Changes required by Coding Conventions
[u/mrichter/AliRoot.git] / TOF / AliTOFanalyzeDigits.C
CommitLineData
32bd3eb5 1Int_t AliTOFanalyzeDigits(Int_t ndump=15, Int_t iEvNum=0)
ca4508a6 2{
3 //
4 // Analyzes the TOF digits and fills QA-histograms
5 // report problems to pierella@bo.infn.it
6 // iEvNum=0 means all events in the file
7 // Author: F. Pierella (Bologna University)
32bd3eb5 8 // Updated to the new I/O by: A. De Caro, C. Zampolli
ca4508a6 9
32bd3eb5 10 Int_t rc = 0;
ca4508a6 11
ca4508a6 12 // adc and tdc
da3d3acd 13 TH1F *htdc = new TH1F("htdc","TDC [bin]",500,0.,15000.);
14 TH1F *hadc = new TH1F("hadc","ADC [bin]",100,0., 3000.);
ca4508a6 15 // TOF digit 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
22 TH2F *h2tdcVSadc = new TH2F("h2tdcVSadc","TDC [bin] VS ADC [bin]",100,0.,3000.,500,0.,15000.);
23
32bd3eb5 24 // Dynamically link some shared libs
25 if (gClassTable->GetID("AliRun") < 0) {
26 gROOT->LoadMacro("loadlibs.C");
27 loadlibs();
28 }
ca4508a6 29
32bd3eb5 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 << "<AliTOFanalyzeDigits> 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 << "<AliTOFanalyzeDigits> No TOF detector found" << endl;
61 rc = 3;
ca4508a6 62 return rc;
63 }
32bd3eb5 64
65 cout << "First " << ndump << " Digits found in TOF TreeD branch have:" << endl;
66
67 if (iEvNum == 0)
68 {
69 rl->LoadHeader();
70 TTree *TE = rl->TreeE();
71 iEvNum = (Int_t)TE->GetEntries();
72 }
73
74 AliTOFdigit *tofdigit;
75
76 for (Int_t ievent = 0; ievent < iEvNum; ievent++) {
77 printf ("Processing event %d \n", ievent);
78 rl->GetEvent(ievent);
ca4508a6 79
32bd3eb5 80 // Get the pointer Digit tree
81 tofl->LoadDigits();
82 TTree *TD=tofl->TreeD();
83 tof->SetTreeAddress();
84
85 if(!TD)
86 {
87 cout << "<AliTOFanalyzeDigits> No TreeD found" << endl;
ca4508a6 88 rc = 3;
89 return rc;
90 }
ca4508a6 91
32bd3eb5 92 TClonesArray * TOFdigits = new TClonesArray("AliTOFdigit",1000);
93 TOFdigits = tof->Digits();
94 TOFdigits = TD->GetBranch("TOF")->SetAddress(&TOFdigits);
95
96 Int_t nEntries = TD->GetEntries();
97
98 for (Int_t iEntry = 0; iEntry < nEntries; iEntry ++)
99 {
100 tof->ResetDigits();
101 TD->GetEvent(iEntry);
102 Int_t ndig = TOFdigits->GetEntriesFast();
103 cout << "<AliTOFanalyzeDigits> found " << ndig
104 << " TOF digits for event " << ievent << endl;
105
106 for (Int_t k=0; k<ndig; k++) {
107 tofdigit = (AliTOFdigit*) TOFdigits->UncheckedAt(k);
108 Float_t tdc = tofdigit->GetTdc();
109 Float_t adc = tofdigit->GetAdc();
110 htdc->Fill(tdc);
111 hadc->Fill(adc);
112 // TOF digit volumes
da3d3acd 113 Int_t sector = tofdigit->GetSector(); // range [0-17]
114 Int_t plate = tofdigit->GetPlate(); // range [0- 4]
115 Int_t strip = tofdigit->GetStrip(); // range [0-19]
116 Int_t padz = tofdigit->GetPadz(); // range [0- 1]
117 Int_t padx = tofdigit->GetPadx(); // range [0-47]
32bd3eb5 118 // it is QA, then I perform QA!
da3d3acd 119 Bool_t isDigitBad = (sector<0 || sector>17 || plate<0 || plate >4 || padz<0 || padz>1 || padx<0 || padx>47);
32bd3eb5 120
121 if (isDigitBad)
122 {
123 cout << "<AliTOFanalyzeDigits> strange digit 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 " << adc << " [bin] | TDC " << tdc << " [bin]" << endl;
131 cout << "----------------------------------------------------"<< endl;
132 }
133
134 // filling digit 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(adc,tdc);
141
142 }
143 }
144
145 tofl->UnloadDigits();
146 rl->UnloadHeader();
147 rl->UnloadgAlice();
ca4508a6 148
149 } // end loop on events
32bd3eb5 150
ca4508a6 151 TFile *fout = new TFile("TOF_digitsQA.root","RECREATE");
152 htdc->Write();
153 hadc->Write();
154 h2tdcVSadc->Write();
155 hsector->Write();
156 hplate->Write();
157 hstrip->Write();
158 hpadz->Write();
159 hpadx->Write();
160 fout->Close();
161
32bd3eb5 162 delete htdc;
163 delete hadc;
164 delete h2tdcVSadc;
165 delete hsector;
166 delete hplate;
167 delete hstrip;
168 delete hpadz;
169 delete hpadx;
170
171 if (gAlice)
172 {
173 delete gAlice->GetRunLoader();
174 delete gAlice;
175 gAlice = 0x0;
176 }
ca4508a6 177
178 return rc;
179
180}
181