]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TOF/AliTOFQADataMaker.cxx
3b2a4b94a3ab5ac0a0ad5ec07deb6f0e49da632a
[u/mrichter/AliRoot.git] / TOF / AliTOFQADataMaker.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15 /*
16   Produces the data needed to calculate the TOF quality assurance. 
17   QA objects are 1 & 2 Dimensional histograms.
18   author: S.Arcelli
19 */
20
21 #include <TClonesArray.h>
22 #include <TFile.h> 
23 #include <TH1I.h> 
24 #include <TH1F.h> 
25 #include <TH2F.h> 
26 #include "AliESDEvent.h"
27 #include "AliESDtrack.h"
28 #include "AliTOFcluster.h"
29 #include "AliTOFdigit.h"
30 #include "AliTOFSDigit.h"
31 #include "AliTOFhitT0.h"
32 #include "AliTOFQADataMaker.h"
33 #include "AliRawReader.h"
34 #include "AliTOFRawStream.h"
35 #include "AliTOFrawData.h"
36 #include "AliLog.h"
37
38 ClassImp(AliTOFQADataMaker)
39            
40 //____________________________________________________________________________ 
41   AliTOFQADataMaker::AliTOFQADataMaker() : 
42   AliQADataMaker(AliQA::GetDetName(AliQA::kTOF), "TOF Quality Assurance Data Maker")
43 {
44   //
45   // ctor
46   //
47 }
48
49 //____________________________________________________________________________ 
50 AliTOFQADataMaker::AliTOFQADataMaker(const AliTOFQADataMaker& qadm) :
51   AliQADataMaker()
52 {
53   //
54   //copy ctor 
55   //
56   SetName((const char*)qadm.GetName()) ; 
57   SetTitle((const char*)qadm.GetTitle()); 
58 }
59
60 //__________________________________________________________________
61 AliTOFQADataMaker& AliTOFQADataMaker::operator = (const AliTOFQADataMaker& qadm )
62 {
63   //
64   // assignment operator.
65   //
66   this->~AliTOFQADataMaker();
67   new(this) AliTOFQADataMaker(qadm);
68   return *this;
69 }
70  
71 //____________________________________________________________________________ 
72 void AliTOFQADataMaker::InitHits()
73 {
74   //
75   // create Hits histograms in Hits subdir
76   //
77   TH1F * h0 = new TH1F("hTOFHits",    "Number of TOF Hits ",301, -1.02, 5.) ; 
78   h0->Sumw2() ;
79   Add2HitsList(h0, 0) ;
80
81   TH1F * h1  = new TH1F("hTOFHitsTime", "Hits Time Spectrum in TOF (ns)", 2000, 0., 200) ; 
82   h1->Sumw2() ;
83   Add2HitsList(h1, 1) ;
84
85   TH1F * h2  = new TH1F("hTOFHitsLength", "Length Spectrum in TOF (cm)", 500, 0., 500) ; 
86   h2->Sumw2() ;
87   Add2HitsList(h2, 2) ;
88
89   TH2F * h3  = new TH2F("hTOFHitsClusMap","Hits vs TOF eta-phi",183, -0.5, 182.5,865,-0.5,864.5) ; 
90   h3->Sumw2() ;
91   Add2HitsList(h3, 3) ;
92 }
93
94 //____________________________________________________________________________ 
95 void AliTOFQADataMaker::InitDigits()
96 {
97   //
98   // create Digits histograms in Digits subdir
99   //
100   TH1F * h0 = new TH1F("hTOFDigits",    "Number of TOF Digits ",301, -1.02, 5.) ;   h0->Sumw2() ;
101   Add2DigitsList(h0, 0) ;
102
103   TH1F * h1  = new TH1F("hTOFDigitsTime", "Digits Time Spectrum in TOF (ns)", 2000, 0., 200) ; 
104   h1->Sumw2() ;
105   Add2DigitsList(h1, 1) ;
106
107   TH1F * h2  = new TH1F("hTOFDigitsToT", "Digits ToT Spectrum in TOF (ns)", 500, 0., 50) ; 
108   h2->Sumw2() ;
109   Add2DigitsList(h2, 2) ;
110
111   TH2F * h3  = new TH2F("hTOFDigitsClusMap","Digits vs TOF eta-phi",183, -0.5, 182.5,865,-0.5,864.5) ; 
112   h3->Sumw2() ;
113   Add2DigitsList(h3, 3) ;
114
115 }
116
117 //____________________________________________________________________________ 
118 void AliTOFQADataMaker::InitSDigits()
119 {
120   //
121   // create SDigits histograms in SDigits subdir
122   //
123   TH1F * h0 = new TH1F("hTOFSDigits",    "Number of TOF SDigits ",301, -1.02, 5.) ;   h0->Sumw2() ;
124   Add2SDigitsList(h0, 0) ;
125
126   TH1F * h1  = new TH1F("hTOFSDigitsTime", "SDigits Time Spectrum in TOF (ns)", 2000, 0., 200) ; 
127   h1->Sumw2() ;
128   Add2SDigitsList(h1, 1) ;
129
130   TH2F * h2  = new TH2F("hTOFSDigitsClusMap","SDigits vs TOF eta-phi",183, -0.5, 182.5,865,-0.5,864.5) ; 
131   h2->Sumw2() ;
132   Add2SDigitsList(h2, 2) ;
133
134 }
135
136 //____________________________________________________________________________ 
137 void AliTOFQADataMaker::InitRaws()
138 {
139   //
140   // create Raws histograms in Raws subdir
141   //
142   TH1F * h0 = new TH1F("hTOFRaws",    "Number of TOF Raws ",301, -1.02, 5.) ;   h0->Sumw2() ;
143   Add2RawsList(h0, 0) ;
144
145   TH1F * h1  = new TH1F("hTOFRawsTime", "Raws Time Spectrum in TOF (ns)", 2000, 0., 200) ; 
146   h1->Sumw2() ;
147   Add2RawsList(h1, 1) ;
148
149   TH1F * h2  = new TH1F("hTOFRawsToT", "Raws ToT Spectrum in TOF (ns)", 500, 0., 50) ; 
150   h2->Sumw2() ;
151   Add2RawsList(h2, 2) ;
152
153   TH2F * h3  = new TH2F("hTOFRawsClusMap","Raws vs TOF eta-phi",183, -0.5, 182.5,865,-0.5,864.5) ; 
154   h3->Sumw2() ;
155   Add2RawsList(h3, 3) ;
156
157 }
158
159 //____________________________________________________________________________ 
160 void AliTOFQADataMaker::InitRecPoints()
161 {
162   //
163   // create RecPoints histograms in RecPoints subdir
164   //
165   TH1F * h0 = new TH1F("hTOFRecPoints",    "Number of TOF RecPoints ",301, -1.02, 5.) ;   h0->Sumw2() ;
166   Add2RecPointsList(h0, 0) ;
167
168   TH1F * h1  = new TH1F("hTOFRecPointsTime", "RecPoints Time Spectrum in TOF (ns)", 2000, 0., 200) ; 
169   h1->Sumw2() ;
170   Add2RecPointsList(h1, 1) ;
171
172   TH1F * h2  = new TH1F("hTOFRecPointsRawTime", "RecPoints raw Time Spectrum in TOF (ns)", 2000, 0., 200) ; 
173   h2->Sumw2() ;
174   Add2RecPointsList(h2, 2) ;
175
176   TH1F * h3  = new TH1F("hTOFRecPointsToT", "RecPoints ToT Spectrum in TOF (ns)", 500, 0., 50) ; 
177   h3->Sumw2() ;
178   Add2RecPointsList(h3, 3) ;
179
180   TH2F * h4  = new TH2F("hTOFRecPointsClusMap","RecPoints vs TOF eta-phi",183, -0.5, 182.5,865,-0.5,864.5) ; 
181   h4->Sumw2() ;
182   Add2RecPointsList(h4, 4) ;
183
184 }
185
186 //____________________________________________________________________________ 
187 void AliTOFQADataMaker::InitESDs()
188 {
189   //
190   //create ESDs histograms in ESDs subdir
191   //
192   TH1F * h0 = new TH1F("hTOFESDs",    "Number of matched TOF tracks over ESDs",       250, -1., 4.) ;  
193   h0->Sumw2() ; 
194   Add2ESDsList(h0, 0) ;
195
196   TH1F * h1  = new TH1F("hTOFESDsTime", "Time Spectrum in TOF (ns)", 2000, 0., 200) ; 
197   h1->Sumw2() ;
198   Add2ESDsList(h1, 1) ;
199
200   TH1F * h2  = new TH1F("hTOFESDsRawTime", "raw Time Spectrum in TOF (ns)", 2000, 0., 200) ; 
201   h2->Sumw2() ;
202   Add2ESDsList(h2, 2) ;
203
204   TH1F * h3  = new TH1F("hTOFESDsToT", "ToT Spectrum in TOF (ns)", 500, 0., 50) ; 
205   h3->Sumw2() ;
206   Add2ESDsList(h3, 3) ;
207
208   TH1F * h4 = new TH1F("hTOFESDsPID",    "Fraction of matched TOF tracks with good PID glag", 100, 0., 1.) ;  
209   h4->Sumw2() ; 
210   Add2ESDsList(h4, 4) ;
211 }
212
213
214 //____________________________________________________________________________
215 void AliTOFQADataMaker::MakeHits(TClonesArray * hits)
216 {
217   //
218   //make QA data from Hits
219   //
220
221   Int_t in[5];
222   Int_t out[5];
223
224   Int_t nentries=hits->GetEntriesFast();
225   if(nentries==0)nentries=-1;
226   GetHitsData(0)->Fill(TMath::Log10(nentries)) ; 
227
228   TIter next(hits) ; 
229   AliTOFhitT0 * hit ; 
230   while ( (hit = dynamic_cast<AliTOFhitT0 *>(next())) ) {
231
232     GetHitsData(1)->Fill( hit->GetTof()*1.E9) ;//in ns
233     GetHitsData(2)->Fill( hit->GetLen()) ;//in cm
234   
235     in[0] = hit->GetSector();
236     in[1] = hit->GetPlate();
237     in[2]= hit->GetStrip();
238     in[3]= hit->GetPadx();
239     in[4]= hit->GetPadz();
240     GetMapIndeces(in,out);
241     GetHitsData(3)->Fill( out[0],out[1]) ;//hit map
242   }
243
244 }
245
246
247 //____________________________________________________________________________
248 void AliTOFQADataMaker::MakeHits(TTree * hitTree)
249 {
250   //
251   // make QA data from Hit Tree
252   //
253   if(!hitTree){
254     AliError("can't get the tree with TOF hits !");
255     return;
256   }     
257
258   TBranch * branch = hitTree->GetBranch("TOF") ;
259
260   if (!branch ) {
261     AliError("TOF branch in Hit Tree not found") ; 
262     return;
263   }
264
265   TClonesArray * hits = new TClonesArray("AliTOFhitT0", 1000);
266   TClonesArray * dummy = new TClonesArray("AliTOFhitT0", 1000);
267   branch->SetAddress(&dummy);
268   Int_t index = 0 ;  
269   for (Int_t ientry = 0 ; ientry < branch->GetEntries() ; ientry++) {
270     branch->GetEntry(ientry) ; 
271     for (Int_t ihit = 0 ; ihit < dummy->GetEntries() ; ihit++) {
272       AliTOFhitT0 * hit = dynamic_cast<AliTOFhitT0 *> (dummy->At(ihit)) ; 
273       new((*hits)[index]) AliTOFhitT0(*hit) ; 
274       index++ ;
275     } 
276   }     
277
278   dummy->Delete();
279   delete dummy;
280   MakeHits(hits) ; 
281
282 }
283
284 //____________________________________________________________________________
285 void AliTOFQADataMaker::MakeDigits(TClonesArray * digits)
286 {
287   //
288   // makes data from Digits
289   //
290   Double_t tdc2ns=AliTOFGeometry::TdcBinWidth()*1E-3;
291   Double_t tot2ns=AliTOFGeometry::ToTBinWidth()*1E-3;
292   Int_t in[5];
293   Int_t out[5];
294
295   Int_t nentries=digits->GetEntriesFast();
296   if(nentries==0)nentries=-1;
297   GetDigitsData(0)->Fill(TMath::Log10(nentries)) ; 
298   TIter next(digits) ; 
299   AliTOFdigit * digit ; 
300   while ( (digit = dynamic_cast<AliTOFdigit *>(next())) ) {
301     
302     GetDigitsData(1)->Fill( digit->GetTdc()*tdc2ns) ;//in ns
303     GetDigitsData(2)->Fill( digit->GetToT()*tot2ns) ;//in ns
304
305     in[0] = digit->GetSector();
306     in[1] = digit->GetPlate();
307     in[2] = digit->GetStrip();
308     in[3] = digit->GetPadx();
309     in[4]= digit->GetPadz();
310     GetMapIndeces(in,out);
311     GetDigitsData(3)->Fill( out[0],out[1]) ;//digit map
312   }
313
314 }
315
316
317 //____________________________________________________________________________
318 void AliTOFQADataMaker::MakeDigits(TTree * digitTree)
319 {
320   //
321   // makes data from Digit Tree
322   //
323   TClonesArray * digits = new TClonesArray("AliTOFdigit", 1000) ; 
324   
325   TBranch * branch = digitTree->GetBranch("TOF") ;
326   if ( ! branch ) {
327     AliError("TOF branch in Digit Tree not found") ; 
328     return;
329   }
330   branch->SetAddress(&digits) ;
331   branch->GetEntry(0) ; 
332   MakeDigits(digits) ; 
333 }
334
335 //____________________________________________________________________________
336 void AliTOFQADataMaker::MakeSDigits(TClonesArray * sdigits)
337 {
338   //
339   // makes data from SDigits
340   //
341
342   Double_t tdc2ns=AliTOFGeometry::TdcBinWidth()*1E-3;
343   Int_t in[5];
344   Int_t out[5];
345
346   Int_t nentries=sdigits->GetEntriesFast();
347   if(nentries==0)nentries=-1;
348   GetSDigitsData(0)->Fill(TMath::Log10(nentries)) ; 
349
350   TIter next(sdigits) ; 
351   AliTOFSDigit * sdigit ; 
352   while ( (sdigit = dynamic_cast<AliTOFSDigit *>(next())) ) {
353     
354     for(Int_t i=0;i<sdigit->GetNDigits();i++){
355       GetSDigitsData(1)->Fill( sdigit->GetTdc(i)*tdc2ns) ;//in ns
356     }
357
358     in[0] = sdigit->GetSector();
359     in[1] = sdigit->GetPlate();
360     in[2] = sdigit->GetStrip();
361     in[3] = sdigit->GetPadx();
362     in[4]= sdigit->GetPadz();
363     GetMapIndeces(in,out);
364     GetSDigitsData(2)->Fill( out[0],out[1]) ;//sdigit map
365   }
366 }
367
368 //____________________________________________________________________________
369 void AliTOFQADataMaker::MakeSDigits(TTree * sdigitTree)
370 {
371   //
372   // makes data from SDigit Tree
373   //
374   TClonesArray * sdigits = new TClonesArray("AliTOFSDigit", 1000) ; 
375   
376   TBranch * branch = sdigitTree->GetBranch("TOF") ;
377   if ( ! branch ) {
378     AliError("TOF branch in SDigit Tree not found") ; 
379     return;
380   }
381   branch->SetAddress(&sdigits) ;
382   branch->GetEntry(0) ; 
383   MakeSDigits(sdigits) ; 
384 }
385
386 //____________________________________________________________________________
387 void AliTOFQADataMaker::MakeRaws(AliRawReader* rawReader)
388 {
389   //
390   // makes data from Raws
391   //
392
393   Double_t tdc2ns=AliTOFGeometry::TdcBinWidth()*1E-3;
394   Double_t tot2ns=AliTOFGeometry::ToTBinWidth()*1E-3;
395
396
397   Int_t ntof = 0 ; 
398   Int_t in[5];
399   Int_t out[5];
400
401   TClonesArray * clonesRawData;
402   AliTOFRawStream tofInput(rawReader);
403   for (Int_t iDDL = 0; iDDL < AliTOFGeometry::NDDL()*AliTOFGeometry::NSectors(); iDDL++){
404     rawReader->Reset();
405     tofInput.LoadRawData(iDDL);
406     clonesRawData = (TClonesArray*)tofInput.GetRawData();
407     for (Int_t iRawData = 0; iRawData<clonesRawData->GetEntriesFast(); iRawData++) {
408       AliTOFrawData *tofRawDatum = (AliTOFrawData*)clonesRawData->UncheckedAt(iRawData);
409       if (!tofRawDatum->GetTOT() || !tofRawDatum->GetTOF()) continue;
410       ntof++;
411       GetRawsData(1)->Fill( tofRawDatum->GetTOF()*tdc2ns) ;//in ns
412       GetRawsData(2)->Fill( tofRawDatum->GetTOT()*tot2ns) ;//in ns
413
414       tofInput.EquipmentId2VolumeId(iDDL, 
415                                     tofRawDatum->GetTRM(), 
416                                     tofRawDatum->GetTRMchain(),
417                                     tofRawDatum->GetTDC(), 
418                                     tofRawDatum->GetTDCchannel(), 
419                                     in);
420     
421       GetMapIndeces(in,out);
422       GetRawsData(3)->Fill( out[0],out[1]) ;//raw map
423       
424     } // while loop
425     
426     clonesRawData->Clear();
427     
428   } // DDL Loop
429   
430   Int_t nentries=ntof;
431   if(nentries==0)nentries=-1;
432   GetRawsData(0)->Fill(TMath::Log10(nentries)) ; 
433
434 }
435
436 //____________________________________________________________________________
437 void AliTOFQADataMaker::MakeRecPoints(TTree * clustersTree)
438 {
439   //
440   // Make data from Clusters
441   //
442
443   Double_t tdc2ns=AliTOFGeometry::TdcBinWidth()*1E-3;
444   Double_t tot2ns=AliTOFGeometry::ToTBinWidth()*1E-3;
445
446   Int_t in[5];
447   Int_t out[5];
448
449   TBranch *branch=clustersTree->GetBranch("TOF");
450   if (!branch) { 
451     AliError("can't get the branch with the TOF clusters !");
452     return;
453   }
454
455   TObjArray * clusters = new TObjArray(100) ;
456   branch->SetAddress(&clusters);
457   clustersTree->GetEvent(0);
458
459   Int_t nentries=clusters->GetEntriesFast();
460   if(nentries==0)nentries=-1;
461   GetRecPointsData(0)->Fill(TMath::Log10(nentries)) ; 
462
463   TIter next(clusters) ; 
464   AliTOFcluster * c ; 
465   while ( (c = dynamic_cast<AliTOFcluster *>(next())) ) {
466     GetRecPointsData(1)->Fill(c->GetTDC()*tdc2ns);
467     GetRecPointsData(2)->Fill(c->GetTDCRAW()*tdc2ns);
468     GetRecPointsData(3)->Fill(c->GetToT()*tot2ns);
469
470     in[0] = c->GetDetInd(0);
471     in[1] = c->GetDetInd(1);
472     in[2] = c->GetDetInd(2);
473     in[3] = c->GetDetInd(4); //X and Z indeces inverted in RecPoints
474     in[4] = c->GetDetInd(3); //X and Z indeces inverted in RecPoints
475
476     GetMapIndeces(in,out);
477     GetRecPointsData(4)->Fill(out[0],out[1]);
478
479   }
480   clusters->Delete();
481   delete clusters;
482 }
483
484 //____________________________________________________________________________
485 void AliTOFQADataMaker::MakeESDs(AliESDEvent * esd)
486 {
487   //
488   // make QA data from ESDs
489   //  
490   Int_t ntrk = esd->GetNumberOfTracks() ; 
491   Int_t ntof=0;
492   Int_t ntofpid=0;
493   while (ntrk--) {
494     AliESDtrack *track=esd->GetTrack(ntrk);
495     Double_t tofTime=track->GetTOFsignal()*1E-3;//in ns
496     Double_t tofTimeRaw=track->GetTOFsignalRaw()*1E-3;//in ns
497     Double_t tofToT=track->GetTOFsignalToT(); //in ns
498     if(!(tofTime>0))continue;
499     ntof++;
500     GetESDsData(1)->Fill(tofTime);
501     GetESDsData(2)->Fill(tofTimeRaw); 
502     GetESDsData(3)->Fill(tofToT);
503     //check how many tracks where ESD PID is ok 
504     UInt_t status=track->GetStatus();
505     if (((status&AliESDtrack::kESDpid)==0) || 
506         ((status&AliESDtrack::kTOFpid)==0)) continue;
507     ntofpid++;
508   }
509   
510   Int_t nentries=ntof;
511   if(nentries==0)nentries=-1;
512   GetESDsData(0)->Fill(TMath::Log10(nentries)) ;
513   if(ntof>0)GetESDsData(4)->Fill(ntofpid/ntof) ;
514
515 }
516
517 //____________________________________________________________________________ 
518 void AliTOFQADataMaker::StartOfDetectorCycle()
519 {
520   //
521   //Detector specific actions at start of cycle
522   //to be implemented  
523 }
524
525 //____________________________________________________________________________
526 void AliTOFQADataMaker::GetMapIndeces(Int_t* in , Int_t* out)
527 {
528   //
529   //return appropriate indeces for the theta-phi map
530   //
531
532   Int_t npadX = AliTOFGeometry::NpadX();
533   Int_t npadZ = AliTOFGeometry::NpadZ();
534   Int_t nStripA = AliTOFGeometry::NStripA();
535   Int_t nStripB = AliTOFGeometry::NStripB();
536   Int_t nStripC = AliTOFGeometry::NStripC();
537
538   Int_t isector = in[0];
539   Int_t iplate = in[1];
540   Int_t istrip = in[2];
541   Int_t ipadX = in[3]; 
542   Int_t ipadZ = in[4]; 
543   
544   Int_t stripOffset = 0;
545   switch (iplate) {
546   case 0:
547     stripOffset = 0;
548       break;
549   case 1:
550     stripOffset = nStripC;
551     break;
552   case 2:
553     stripOffset = nStripC+nStripB;
554     break;
555   case 3:
556     stripOffset = nStripC+nStripB+nStripA;
557     break;
558   case 4:
559     stripOffset = nStripC+nStripB+nStripA+nStripB;
560     break;
561   default:
562     AliError(Form("Wrong plate number in TOF (%d) !",iplate));
563     break;
564   };
565   Int_t zindex=npadZ*(istrip+stripOffset)+(ipadZ+1);
566   Int_t phiindex=npadX*isector+ipadX+1;
567   out[0]=zindex;  
568   out[1]=phiindex;  
569   
570 }