Changes required by Coding Conventions
[u/mrichter/AliRoot.git] / TOF / AliTOFanalyzeSDigitsV2.C
CommitLineData
32bd3eb5 1Int_t AliTOFanalyzeSDigitsV2(Int_t ndump=15, Int_t iEvNum=0)
ca4508a6 2{
ca4508a6 3 //
4 // Analyzes the TOF sdigits and fills QA-histograms
5 // report problems to pierella@bo.infn.it
6 // iEvNum=0 means all events in the file
32bd3eb5 7 //
8 // Updated to the new I/O by: A. De Caro, C. Zampolli
ca4508a6 9
32bd3eb5 10 Int_t rc = 0;
ca4508a6 11
12 // adc and tdc
da3d3acd 13 TH1F *htdc = new TH1F("htdc","TDC [bin]",5000,0.,150000.);
14 TH1F *hadc = new TH1F("hadc","ADC [bin]",100,0., 3000.);
ca4508a6 15 // TOF sdigit volumes
da3d3acd 16 TH1F *hsector = new TH1F("hsector","Sector",18,0.,18.);
17 TH1F *hplate = new TH1F("hplate","Plate ", 5,0., 5.);
18 TH1F *hstrip = new TH1F("hstrip","Strip ",20,0.,20.);
19 TH1F *hpadz = new TH1F("hpadz","Pad along z ",2,0.,2.);
20 TH1F *hpadx = new TH1F("hpadx","Pad along x",48,0.,48.);
ca4508a6 21 // ADC-TDC correlation
32bd3eb5 22 TH2F *h2tdcVSadc = new TH2F("h2tdcVSadc","TDC [bin] VS ADC [bin]",500,0.,150000.,100,0.,3000.);
23
24 // Dynamically link some shared libs
25 if (gClassTable->GetID("AliRun") < 0) {
26 gROOT->LoadMacro("loadlibs.C");
27 loadlibs();
28 }
29
30 if (gAlice)
31 {
32 delete gAlice->GetRunLoader();
33 delete gAlice;
34 gAlice = 0x0;
35 }
36
37 AliRunLoader *rl = AliRunLoader::Open("galice.root",AliConfig::fgkDefaultEventFolderName,"read");
38 if (!rl)
39 {
40 cerr<<"Can't load RunLoader from file"<<"!\n";
41 rc = 1;
42 return rc;
43 }
44
45 rl->LoadgAlice();
46 gAlice = rl->GetAliRun();
47
48 if (!gAlice)
49 {
50 cerr << "<AliTOFanalyzeSDigits> AliRun object not found on file\n ";
51 rc = 2;
52 return rc;
53 }
ca4508a6 54
32bd3eb5 55 AliLoader *tofl = rl->GetLoader("TOFLoader");
56 AliTOF *tof = (AliTOF *) rl->GetAliRun()->GetDetector("TOF");
57
58 if (tof==0x0 || tofl==0x0)
59 {
60 cerr << "<AliTOFanalyzeSDigits> no TOF detector found" << endl;
61 rc = 3;
62 return rc;
63 }
64
ca4508a6 65 cout << "First " << ndump << " SDigits found in TOF TreeS branch have:" << endl;
66
32bd3eb5 67 if (iEvNum == 0)
68 {
69 rl->LoadHeader();
70 TTree *TE = rl->TreeE();
71 iEvNum = (Int_t)TE->GetEntries();
72 }
ca4508a6 73
32bd3eb5 74 AliTOFSDigit *tofsdigit;
75
ca4508a6 76 for (Int_t ievent = 0; ievent < iEvNum; ievent++) {
32bd3eb5 77 printf ("Processing event %d \n", ievent);
78 rl->GetEvent(ievent);
ca4508a6 79
32bd3eb5 80 // Get the pointer SDigit tree
81 tofl->LoadSDigits();
82 TTree *TS=tofl->TreeS();
83 tof->SetTreeAddress();
ca4508a6 84
32bd3eb5 85 if(!TS)
86 {
87 cout << "<AliTOFanalyzeSDigits> No TreeS found" << endl;
88 rc = 4;
89 return rc;
90 }
ca4508a6 91
32bd3eb5 92 TClonesArray * TOFsdigits = new TClonesArray("AliTOFSDigit",1000);
93 TOFsdigits = tof->SDigits();
94 TOFsdigits = TS->GetBranch("TOF")->SetAddress(&TOFsdigits);
95
96 Int_t nEntries = TS->GetEntries();
97
98 for (Int_t iEntry = 0; iEntry < nEntries; iEntry ++)
99 {
100 tof->ResetDigits();
101 TS->GetEvent(iEntry);
102 Int_t ndig = TOFsdigits->GetEntriesFast();
103 cout << "<AliTOFanalyzeSDigits> found " << ndig
104 << " TOF sdigits for event " << ievent << endl;
ca4508a6 105
32bd3eb5 106 for (Int_t k=0; k<ndig; k++) {
107 tofsdigit = (AliTOFSDigit*) TOFsdigits->UncheckedAt(k);
108 Float_t firstTDC = tofsdigit->GetTdc(0);
109 Float_t firstADC = tofsdigit->GetAdc(0);
110 htdc->Fill(firstTDC);
111 hadc->Fill(firstADC);
112 // TOF sdigit volumes
da3d3acd 113 Int_t sector = tofsdigit->GetSector(); // range [0-17]
114 Int_t plate = tofsdigit->GetPlate(); // range [0- 4]
115 Int_t strip = tofsdigit->GetStrip(); // range [0-19]
116 Int_t padz = tofsdigit->GetPadz(); // range [0- 1]
117 Int_t padx = tofsdigit->GetPadx(); // range [0-47]
32bd3eb5 118 // it is QA, then I perform QA!
da3d3acd 119 Bool_t isSDigitBad = (sector<0 || sector>17 || plate<0 || plate >4 || padz<0 || padz>1 || padx<0 || padx>47);
32bd3eb5 120
da3d3acd 121
32bd3eb5 122 if (isSDigitBad) {
123 cout << "<AliTOFanalyzeSDigits> strange sdigit found" << endl;
124 rc = 4;
125 return rc;
126 }
127
128 if(k<ndump){
129 cout << k << "-th | " << "Sector " << sector << " | Plate " << plate << " | Strip " << strip << " | PadZ " << padz << " | PadX " << padx << endl;
130 cout << k << "-th | ADC " << firstADC << " [bin] | TDC " << firstTDC << " [bin]" << endl;
131 cout << "----------------------------------------------------"<< endl;
132 }
133
134 // filling sdigit volume histos
135 hsector->Fill(sector);
136 hplate->Fill(plate);
137 hstrip->Fill(strip);
138 hpadx->Fill(padx);
139 hpadz->Fill(padz);
140 h2tdcVSadc->Fill(firstTDC,firstADC);
141
ca4508a6 142 }
32bd3eb5 143 }
ca4508a6 144
32bd3eb5 145 tofl->UnloadSDigits();
ca4508a6 146
32bd3eb5 147 } // end loop on events
148
149 rl->UnloadHeader();
150 rl->UnloadgAlice();
151
ca4508a6 152 TFile *fout = new TFile("TOF_sdigitsQA.root","RECREATE");
153 htdc->Write();
154 hadc->Write();
ca4508a6 155 h2tdcVSadc->Write();
156 hsector->Write();
157 hplate->Write();
158 hstrip->Write();
159 hpadz->Write();
160 hpadx->Write();
32bd3eb5 161 fout->Close();
162
163 delete htdc;
164 delete hadc;
165 delete h2tdcVSadc;
166 delete hsector;
167 delete hplate;
168 delete hstrip;
169 delete hpadz;
170 delete hpadx;
ca4508a6 171
32bd3eb5 172 if (gAlice)
173 {
174 delete gAlice->GetRunLoader();
175 delete gAlice;
176 gAlice = 0x0;
177 }
ca4508a6 178
179 return rc;
180
ca4508a6 181}
32bd3eb5 182