ROOT logo
/**************************************************************************
 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
 *                                                                        *
 * Author: The ALICE Off-line Project.                                    *
 * Contributors are mentioned in the code where appropriate.              *
 *                                                                        *
 * Permission to use, copy, modify and distribute this software and its   *
 * documentation strictly for non-commercial purposes is hereby granted   *
 * without fee, provided that the above copyright notice appears in all   *
 * copies and that both the copyright notice and this permission notice   *
 * appear in the supporting documentation. The authors make no claims     *
 * about the suitability of this software for any purpose. It is          *
 * provided "as is" without express or implied warranty.                  *
 **************************************************************************/

// $Id$

// Macro to generate histograms from digits
// By E. Sicking, CERN

TDirectoryFile* GetDirectory(Int_t ievent, const TString& detName, Int_t nfiles) 
{
  for (Int_t file =0; file<nfiles; file++) {
    TString filename(detName);
    if ( file == 0 ) {
      filename += ".Digits.root";
    }  
    else { 
      filename += TString(Form(".Digits%d.root",file));
    }

    TFile* file0 = TFile::Open(filename.Data());

    TDirectoryFile* dir = (TDirectoryFile*)file0->Get(Form("Event%d",ievent));
    if (dir)  return dir;
  }
  return 0;
}  
    
void digitsTPC(Int_t nevents, Int_t nfiles)
{

  TH1F * hadclog = new TH1F ("hadclog", "hadclog",100, -1,3.5 );
  TH1F * hadc = new TH1F ("hadc", "hadc",200, -100,1100 );

  TH1F * hRow = new TH1F ("hRow", "hRow",120, -100, 1100);
  TH1F * hCol = new TH1F ("hCol", "hCol",100, -5, 194);
  TH1F * hndig = new TH1F ("hndig", "hndig",120, -100000, 100000);
  TH1F * hSize = new TH1F ("hSize", "hSize",100, 1000, 5000);


  TDirectoryFile *tdf[100];     
  TDirectoryFile *tdfKine[100] ;

  TTree *ttree[100];      
  TTree *ttreeKine[100];  

  AliSimDigits *digits= NULL;  


  Int_t numberhits=0;


  //Run loader------------
  TString name;
  name = "galice.root";
  AliRunLoader* rlSig = AliRunLoader::Open(name.Data());

  // gAlice
  rlSig->LoadgAlice();
  gAlice = rlSig->GetAliRun();

  // Now load kinematics and event header
  rlSig->LoadKinematics();
  rlSig->LoadHeader();
  cout <<  rlSig->GetNumberOfEvents()<< endl;
  //----------------------

    //loop over events in the files
    for(Int_t event=0; event<nevents; event++){
      printf("###event= %d\n", event);

    tdf[event] = GetDirectory(event, "TPC", nfiles);
    if ( ! tdf[event] ) {
      cerr << "Event directory not found in " << nfiles <<  " files" << endl;
      exit(1);
    }      

      ttree[event] = (TTree*)tdf[event]->Get("TreeD");
          
      digits = NULL;
      ttree[event]->SetBranchAddress("Segment", &digits);

      // Runloader -> gives particle Stack
      rlSig->GetEvent(event);
      AliStack * stack = rlSig->Stack(); 
      //stack->DumpPStack();

      Short_t digitValue=0;
      Int_t iRow=0;
      Int_t iColumn=0;
      Short_t ndig =0;
      Int_t digSize =0;

      // loop over tracks
      for(Int_t iev=0; iev<ttree[event]->GetEntries(); iev++){
	ttree[event]->GetEntry(iev);
	digits->First();    
	
	iRow=digits->CurrentRow();
	digitValue = digits->CurrentDigit();
	iColumn=digits->CurrentColumn();
	ndig=digits->GetDigits();
	digSize=digits->GetDigitSize();

	if(digitValue>0.)hadclog->Fill(TMath::Log10(digitValue));
	hadc->Fill(digitValue);
	hRow->Fill(iRow);
	hCol->Fill(iColumn);
	hndig->Fill(ndig);
	hSize->Fill(digSize);

	while (digits->Next()){

	  digitValue = digits->CurrentDigit();
	  iRow=digits->CurrentRow();
	  iColumn=digits->CurrentColumn();
	  ndig=digits->GetDigits();
	  digSize=digits->GetDigitSize();
	  
	  if(digitValue>0.)hadclog->Fill(TMath::Log10(digitValue));
	  hadc->Fill(digitValue);
	  hRow->Fill(iRow);
	  hCol->Fill(iColumn);
	  hndig->Fill(ndig);
	  hSize->Fill(digSize);
	  //cout << digSize << endl;
	}
      }
    }
  
   TFile fc("digits.TPC.root","RECREATE");
   fc.cd();

   hadclog->Write();
   hadc->Write();
   hRow->Write();
   hCol->Write();
   hndig->Write();
   hSize->Write();

   fc.Close();

}
 digitsTPC.C:1
 digitsTPC.C:2
 digitsTPC.C:3
 digitsTPC.C:4
 digitsTPC.C:5
 digitsTPC.C:6
 digitsTPC.C:7
 digitsTPC.C:8
 digitsTPC.C:9
 digitsTPC.C:10
 digitsTPC.C:11
 digitsTPC.C:12
 digitsTPC.C:13
 digitsTPC.C:14
 digitsTPC.C:15
 digitsTPC.C:16
 digitsTPC.C:17
 digitsTPC.C:18
 digitsTPC.C:19
 digitsTPC.C:20
 digitsTPC.C:21
 digitsTPC.C:22
 digitsTPC.C:23
 digitsTPC.C:24
 digitsTPC.C:25
 digitsTPC.C:26
 digitsTPC.C:27
 digitsTPC.C:28
 digitsTPC.C:29
 digitsTPC.C:30
 digitsTPC.C:31
 digitsTPC.C:32
 digitsTPC.C:33
 digitsTPC.C:34
 digitsTPC.C:35
 digitsTPC.C:36
 digitsTPC.C:37
 digitsTPC.C:38
 digitsTPC.C:39
 digitsTPC.C:40
 digitsTPC.C:41
 digitsTPC.C:42
 digitsTPC.C:43
 digitsTPC.C:44
 digitsTPC.C:45
 digitsTPC.C:46
 digitsTPC.C:47
 digitsTPC.C:48
 digitsTPC.C:49
 digitsTPC.C:50
 digitsTPC.C:51
 digitsTPC.C:52
 digitsTPC.C:53
 digitsTPC.C:54
 digitsTPC.C:55
 digitsTPC.C:56
 digitsTPC.C:57
 digitsTPC.C:58
 digitsTPC.C:59
 digitsTPC.C:60
 digitsTPC.C:61
 digitsTPC.C:62
 digitsTPC.C:63
 digitsTPC.C:64
 digitsTPC.C:65
 digitsTPC.C:66
 digitsTPC.C:67
 digitsTPC.C:68
 digitsTPC.C:69
 digitsTPC.C:70
 digitsTPC.C:71
 digitsTPC.C:72
 digitsTPC.C:73
 digitsTPC.C:74
 digitsTPC.C:75
 digitsTPC.C:76
 digitsTPC.C:77
 digitsTPC.C:78
 digitsTPC.C:79
 digitsTPC.C:80
 digitsTPC.C:81
 digitsTPC.C:82
 digitsTPC.C:83
 digitsTPC.C:84
 digitsTPC.C:85
 digitsTPC.C:86
 digitsTPC.C:87
 digitsTPC.C:88
 digitsTPC.C:89
 digitsTPC.C:90
 digitsTPC.C:91
 digitsTPC.C:92
 digitsTPC.C:93
 digitsTPC.C:94
 digitsTPC.C:95
 digitsTPC.C:96
 digitsTPC.C:97
 digitsTPC.C:98
 digitsTPC.C:99
 digitsTPC.C:100
 digitsTPC.C:101
 digitsTPC.C:102
 digitsTPC.C:103
 digitsTPC.C:104
 digitsTPC.C:105
 digitsTPC.C:106
 digitsTPC.C:107
 digitsTPC.C:108
 digitsTPC.C:109
 digitsTPC.C:110
 digitsTPC.C:111
 digitsTPC.C:112
 digitsTPC.C:113
 digitsTPC.C:114
 digitsTPC.C:115
 digitsTPC.C:116
 digitsTPC.C:117
 digitsTPC.C:118
 digitsTPC.C:119
 digitsTPC.C:120
 digitsTPC.C:121
 digitsTPC.C:122
 digitsTPC.C:123
 digitsTPC.C:124
 digitsTPC.C:125
 digitsTPC.C:126
 digitsTPC.C:127
 digitsTPC.C:128
 digitsTPC.C:129
 digitsTPC.C:130
 digitsTPC.C:131
 digitsTPC.C:132
 digitsTPC.C:133
 digitsTPC.C:134
 digitsTPC.C:135
 digitsTPC.C:136
 digitsTPC.C:137
 digitsTPC.C:138
 digitsTPC.C:139
 digitsTPC.C:140
 digitsTPC.C:141
 digitsTPC.C:142
 digitsTPC.C:143
 digitsTPC.C:144
 digitsTPC.C:145
 digitsTPC.C:146
 digitsTPC.C:147
 digitsTPC.C:148
 digitsTPC.C:149
 digitsTPC.C:150
 digitsTPC.C:151
 digitsTPC.C:152
 digitsTPC.C:153
 digitsTPC.C:154
 digitsTPC.C:155