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