Another round of fixes in order to use the event specie in the QA. The procedure...
[u/mrichter/AliRoot.git] / T0 / AliT0QADataMakerRec.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 /* $Id$ */
18
19 //---
20 //  Produces the data needed to calculate the quality assurance. 
21 //  Alla.Maevskaya@cern.ch
22 //---
23
24 // --- ROOT system ---
25 #include <TClonesArray.h>
26 #include <TFile.h> 
27 #include <TH1F.h> 
28 #include <TH2F.h> 
29 #include <TDirectory.h>
30 // --- Standard library ---
31
32 // --- AliRoot header files ---
33 #include "AliESDEvent.h"
34 #include "AliLog.h"
35 #include "AliT0digit.h" 
36 #include "AliT0hit.h"
37 #include "AliT0RecPoint.h"
38 #include "AliT0QADataMakerRec.h"
39 #include "AliQAChecker.h"
40 #include "AliT0RawReader.h"
41
42 #include "Riostream.h"
43 ClassImp(AliT0QADataMakerRec)
44            
45 //____________________________________________________________________________ 
46   AliT0QADataMakerRec::AliT0QADataMakerRec() : 
47 AliQADataMakerRec(AliQAv1::GetDetName(AliQAv1::kT0), 
48                   "T0 Quality Assurance Data Maker"),
49   fnEvent(0)
50
51 {
52   // ctor
53   for (Int_t i=0; i<6; i++) {
54     fNumTriggers[i]=0;
55     fNumTriggersCal[i]=0;
56   }
57   for (Int_t i=0; i<24; i++)
58     {
59       feffC[i]=0;
60       feffA[i]=0;
61     }
62 }
63
64 //____________________________________________________________________________ 
65 AliT0QADataMakerRec::AliT0QADataMakerRec(const AliT0QADataMakerRec& qadm) :
66   AliQADataMakerRec(),
67   fnEvent(0)
68   
69 {
70   //copy ctor 
71  SetName((const char*)qadm.GetName()) ; 
72   SetTitle((const char*)qadm.GetTitle()); 
73 }
74
75 //__________________________________________________________________
76 AliT0QADataMakerRec& AliT0QADataMakerRec::operator = (const AliT0QADataMakerRec& qadm )
77 {
78   // Equal operator.
79   this->~AliT0QADataMakerRec();
80   new(this) AliT0QADataMakerRec(qadm);
81   return *this;
82 }
83 //____________________________________________________________________________
84 void AliT0QADataMakerRec::EndOfDetectorCycle(AliQAv1::TASKINDEX_t task, TObjArray ** list)
85 {
86   //Detector specific actions at end of cycle
87   // do the QA checking
88   AliQAChecker::Instance()->Run(AliQAv1::kT0, task, list) ;
89   for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
90     SetEventSpecie(AliRecoParam::ConvertIndex(specie)) ; 
91     if ( task == AliQAv1::kRAWS ) {
92       const Char_t *triggers[6] = {"mean", "vertex","ORA","ORC","central","semi-central"};
93       for (Int_t itr=0; itr<6; itr++) {
94         GetRawsData(197)->Fill(triggers[itr], fNumTriggersCal[itr]);
95         GetRawsData(197)->SetBinContent(itr+1, fNumTriggersCal[itr]);
96       }  
97       GetRawsData(205)->SetOption("COLZ");
98       GetRawsData(206)->SetOption("COLZ");
99       GetRawsData(207)->SetOption("COLZ");
100       GetRawsData(205)->GetXaxis()->SetTitle("#PMT");
101       GetRawsData(206)->GetXaxis()->SetTitle("#PMT");
102       GetRawsData(205)->GetYaxis()->SetTitle("NeventsReg/Nevents");
103       GetRawsData(206)->GetYaxis()->SetTitle("NeventsReg/Nevents");
104       GetRawsData(207)->GetXaxis()->SetTitle("#PMT");
105       GetRawsData(207)->GetYaxis()->SetTitle("Charge, #channels");
106     }
107     if ( task == AliQAv1::kRECPOINTS) {
108       GetRecPointsData(0)->SetOption("COLZ");
109       GetRecPointsData(1)->SetOption("COLZ");
110       GetRecPointsData(0)->GetXaxis()->SetTitle("#PMT");
111       GetRecPointsData(1)->GetXaxis()->SetTitle("#PMT");
112       GetRecPointsData(0)->GetYaxis()->SetTitle("CFD time");
113       GetRecPointsData(1)->GetYaxis()->SetTitle("Charge, #channels");
114     }
115   }
116 }
117
118 //____________________________________________________________________________
119 void AliT0QADataMakerRec::StartOfDetectorCycle()
120 {
121   //Detector specific actions at start of cycle
122   fnEvent=0;
123
124 }
125  
126 //____________________________________________________________________________ 
127 void AliT0QADataMakerRec::InitRaws()
128 {
129   // create Raw histograms in Raw subdir
130   const Bool_t expert   = kTRUE ; 
131   const Bool_t saveCorr = kTRUE ; 
132   const Bool_t image    = kTRUE ; 
133   
134   TString timename, ampname, qtcname, ledname;
135   TString timeCalname, ampCalname, ledCalname, qtcCalname;
136
137   TH1F* fhRefPoint = new TH1F("hRefPoint","Ref Point", 10,1252170, 1252180);
138   Add2RawsList( fhRefPoint,0, !expert, image, !saveCorr);
139    
140   TH1F *fhRawCFD[24]; TH1F * fhRawLEDamp[24];
141   TH1F *fhRawQTC[24]; TH1F * fhRawLED[24];
142   TH1F *fhRawCFDcal[24]; TH1F * fhRawLEDampcal[24]; 
143   TH1F *fhRawQTCcal[24];  TH1F * fhRawLEDcal[24];
144   
145   for (Int_t i=0; i<24; i++)
146     {
147       timename ="hRawCFD";
148       ledname = "hRawLED";
149       qtcname = "hRawQTC";
150       ampname = "hRawLEDminCFD";
151       timename += i;
152       ampname += i;
153       qtcname += i;
154       ledname += i;
155       fhRawCFD[i] = new TH1F(timename.Data(), timename.Data(),500,-250,250);
156       Add2RawsList( fhRawCFD[i],i+1, !expert, image, !saveCorr);
157       fhRawLED[i] = new TH1F(ledname.Data(), ledname.Data(),2000,-1000,1000);
158       Add2RawsList( fhRawLED[i],i+24+1, !expert, image, !saveCorr);
159       fhRawLEDamp[i] = new TH1F(ampname.Data(), ampname.Data(),100,300,600);
160       Add2RawsList( fhRawLEDamp[i],i+48+1, !expert, image, !saveCorr);
161       fhRawQTC[i] = new TH1F(qtcname.Data(), qtcname.Data(),1500,1000,7000);
162       Add2RawsList( fhRawQTC[i],i+72+1, !expert, image, !saveCorr);
163      }
164   TH1F* fhRawTrigger = new TH1F("hRawTrigger"," phys triggers",5,0,5);
165   Add2RawsList(fhRawTrigger ,97, !expert, image, !saveCorr);
166   
167   TH1F* fhRawMean = new TH1F("hRawMean","online mean signal", 100,2400,2500);
168   Add2RawsList( fhRawMean,98, !expert, image, !saveCorr);
169   TH1F* fhRawVertex = new TH1F("hRawVertex","online vertex signal", 100,0,600);
170   Add2RawsList( fhRawVertex,99, !expert, image, !saveCorr);
171   TH1F* fhRawORA = new TH1F("hRawORA","online OR A", 100,2500,2800);
172   Add2RawsList( fhRawORA,100, !expert, image, !saveCorr);
173   TH1F* fhRawORC = new TH1F("hRawORC","online OR C", 100,2000,2300);
174   Add2RawsList( fhRawORC,101, !expert, image, !saveCorr);
175   
176   for (Int_t i=0; i<24; i++)
177     {
178       // for events with trigger CALIBRATION_EVENT
179       timeCalname ="hRawCFDcal";
180       ledCalname = "hRawLEDcal";
181       ampCalname = "hRawLEDminCFDcal";
182       qtcCalname = "hRawQTCcal";
183       timeCalname += i;
184       ledCalname += i;
185       ampCalname += i;
186       qtcCalname += i;
187       fhRawCFDcal[i] = new TH1F(timeCalname.Data(), timeCalname.Data(),2000,-1000,1000);
188       Add2RawsList( fhRawCFDcal[i],101+i+1, !expert, image, !saveCorr);
189       fhRawLEDcal[i] = new TH1F(ledCalname.Data(), ledCalname.Data(),2000,-1000,1000);
190       Add2RawsList( fhRawLEDcal[i],101+i+24+1, !expert, image, !saveCorr);
191       fhRawLEDampcal[i] = new TH1F(ampCalname.Data(), ampCalname.Data(),300,300,600);
192       Add2RawsList( fhRawLEDampcal[i],101+i+48+1, !expert, image, !saveCorr);
193       fhRawQTCcal[i] = new TH1F(qtcCalname.Data(), qtcCalname.Data(),1000,0,7000);
194       Add2RawsList( fhRawQTCcal[i],101+i+72+1, !expert, image, !saveCorr);
195     }
196
197   TH1F* fhRawTriggerCal = new TH1F("hRawTriggerCal"," laser triggers",6,0,6);
198   Add2RawsList(fhRawTriggerCal ,197 , !expert, !image, saveCorr);
199
200   TH1F* fhRawMeanCal = new TH1F("hRawMeanCal","online mean signal, calibration event",
201                                 10000,0,10000);
202   Add2RawsList( fhRawMeanCal,198);
203   TH1F* fhRawVertexCal = new TH1F("hRawVertexCal","online vertex signal, calibration even ",
204                                   10000,0,10000);
205   Add2RawsList( fhRawVertexCal,199, !expert, image, !saveCorr);
206   TH1F* fhRawORAcal = new TH1F("hRawORAcal","online OR A", 10000,0,10000);
207   Add2RawsList( fhRawORAcal,200, !expert, image, !saveCorr );
208   TH1F* fhRawORCcal = new TH1F("hRawORCcal","online OR C", 10000,0,10000);
209   Add2RawsList( fhRawORCcal,201, !expert, image, !saveCorr);
210   TH1F* fhMultcal = new TH1F("hMultcal","full mulltiplicity", 10000,0,10000);
211   Add2RawsList( fhMultcal,202, !expert, image, !saveCorr );
212   TH1F* fhMultScal = new TH1F("hMultScal","full multiplicity with semi-central trigger",
213                               10000,0,10000);
214   Add2RawsList( fhMultScal,203, !expert, image, !saveCorr);
215   TH1F* fhMultCcal = new TH1F("hMultCcal","full multiplicity with central trigger", 
216                               1000,0,10000);
217   Add2RawsList( fhMultCcal,204, !expert, image, !saveCorr);
218
219   //  TH2F* fhEffCFD = new TH2F("hEffCFD"," CFD time",24, 0 ,24, 
220   //                  100,-500,500);
221   TH2F* fhEffCFD = new TH2F("hEffCFD"," CFD time",24, 0 ,24, 50, 0,5); 
222
223   Add2RawsList( fhEffCFD,205, !expert, !image, saveCorr);
224   TH2F* fhEffLED = new TH2F("hEffLED","LED time",24, 0 ,24, 
225                             100, 0, 5); 
226   //100,-500,500);
227
228   Add2RawsList( fhEffLED,206, !expert, !image, saveCorr);
229   TH2F* fhEffQTC = new TH2F("hEffQTC","QTC amplitude",24, 0 ,24, 
230                               100,0,7000);
231   Add2RawsList( fhEffQTC,207, !expert, !image, saveCorr);
232   //yeys guide line
233   //  TH2F* fhLineQTC = new TH2F("hLineQTC","QTC amplitude boeder",24, 0 ,24, 
234   //                          100,0,7000);
235 //  Add2RawsList( fhLineQTC,208, !expert, !image, saveCorr);
236 }
237
238 //____________________________________________________________________________ 
239
240 void AliT0QADataMakerRec::InitRecPoints()
241 {
242   // create cluster histograms in RecPoint subdir
243   const Bool_t expert   = kTRUE ; 
244   const Bool_t image    = kTRUE ; 
245
246   TH2F* fhRecCFD = new TH2F("hRecCFD"," CFD time",24, 0 ,24, 
247                               100,-50,50);
248   Add2RecPointsList ( fhRecCFD,0, !expert, image);
249
250   TH2F* fhRecAmpDiff = new TH2F("hRecAmpDiff"," LED-CFD  min QTC amplitude",
251                                 24, 0 ,24, 200,-10,10);
252   Add2RecPointsList (fhRecAmpDiff, 1, !expert, image);
253   
254   TH1F *fhMean = new TH1F("hMean","online - rec mean",1000, -5000, 5000);
255   Add2RecPointsList ( fhMean,2, !expert, image);
256  }
257
258 //____________________________________________________________________________
259 void AliT0QADataMakerRec::InitESDs()
260 {
261   //create ESDs histograms in ESDs subdir
262   const Bool_t expert   = kTRUE ; 
263   const Bool_t image    = kTRUE ; 
264   
265   TH1F *fhESDMean = new TH1F("hESDmean"," ESD mean",100,2400,2500);
266   Add2ESDsList(fhESDMean, 0, !expert, image) ;
267   TH1F * fhESDVertex = new TH1F("hESDvertex","ESD vertex",82,-30,30);
268   Add2ESDsList(fhESDVertex, 1, !expert, image) ;
269   
270
271 }
272
273 //____________________________________________________________________________
274 void AliT0QADataMakerRec::MakeRaws( AliRawReader* rawReader)
275 {
276         rawReader->Reset() ; 
277   //fills QA histos for RAW
278   Int_t shift=0;
279   Float_t effic ;
280
281   AliT0RawReader *start = new AliT0RawReader(rawReader);
282   //  start->Next();
283   if (! start->Next())
284     AliDebug(AliQAv1::GetQADebugLevel(),Form(" no raw data found!!"));
285   else
286     {  
287       fnEvent++;
288
289       UInt_t type =rawReader->GetType();
290       //     cout<<" !!!!! new event type = "<<type<<endl;
291       Int_t allData[110][5];
292       for (Int_t i0=0; i0<105; i0++)
293         {
294           for (Int_t j0=0; j0<5; j0++) allData[i0][j0]=0;
295         }
296       for (Int_t i=0; i<105; i++) 
297         for (Int_t iHit=0; iHit<5; iHit++)
298           allData[i][iHit]= start->GetData(i,iHit);
299       
300       if (allData[0][0]>0)    GetRawsData(0) -> Fill( allData[0][0]);
301       //  allData[0][0] = allData[0][0] - 7000; 
302       if (type == 8) shift=101;
303       if (type == 7) shift=0;
304       
305       for (Int_t ik = 0; ik<12; ik++){
306         for (Int_t iHt=0; iHt<5; iHt++){
307           //cfd
308           if(allData[ik+1][iHt]>0)
309             GetRawsData(shift+ik+1) -> 
310               Fill(allData[ik+1][iHt]-allData[1][0]);
311           //led
312           if(allData[ik+13][iHt] > 0 && allData[13][iHt]>0) 
313             GetRawsData(shift+ik+24+1)->
314               Fill(allData[ik+13][iHt]-allData[13][iHt]);
315           //led -cfd
316
317           if(allData[ik+13][iHt] > 0 && allData[ik+1][iHt] >0 )
318             GetRawsData(shift+ik+48+1)->
319               Fill(allData[ik+13][iHt]-allData[ik+1][iHt]);
320           //qtc
321           if(allData[2*ik+25][iHt] > 0 && allData[2*ik+26][iHt] > 0)
322             GetRawsData(shift+ik+72+1)->
323               Fill(allData[2*ik+25][iHt]-allData[2*ik+26][iHt]);
324           
325           
326           if(type == 8 && allData[ik+1][iHt]>0 ) feffC[ik]++; 
327           if(type == 8 && allData[ik+13][iHt]>0 ) feffA[ik]++; 
328           // GetRawsData(206)->Fill(ik,allData[ik+13][iHt]-allData[13][0]);
329           if(type == 8 && (allData[2*ik+25][iHt]>0 && allData[2*ik+26][iHt]>0) ) 
330             GetRawsData(207)->Fill(ik,allData[2*ik+25][iHt]-allData[2*ik+26][iHt]);
331         }
332         effic = Float_t(feffC[ik])/Float_t(fnEvent);
333         GetRawsData(205)->Fill(ik,effic );
334         effic = Float_t(feffA[ik])/Float_t(fnEvent);
335         GetRawsData(206)->Fill(ik,effic );
336         //      printf("CFD  efficiency for PMT %i = %f \n", ik, effic); 
337       }
338       for (Int_t ik = 12; ik<24; ik++) {
339         for (Int_t iHt=0; iHt<5; iHt++) {
340           if(allData[ik+45][iHt]>0) 
341             //cfd
342             GetRawsData(shift+ik+1)->
343               Fill(allData[ik+45][iHt]-allData[57][0]);
344             //qtc         
345           if(allData[2*ik+57][iHt]>0 && allData[2*ik+58][iHt]>0)
346             GetRawsData(shift+ik+72+1)->
347               Fill(allData[2*ik+57][iHt]-allData[2*ik+58][iHt]);
348           //led
349           if(allData[ik+57][iHt] > 0 )
350             GetRawsData(shift+ik+24+1)->
351               Fill(allData[ik+57][iHt]-allData[69][iHt]);
352             //led-cfd
353           if(allData[ik+57][iHt] > 0 &&allData[ik+45][iHt]>0)
354             GetRawsData(shift+ik+48+1)->
355               Fill(allData[ik+57][iHt]-allData[ik+45][iHt]);
356           
357           if(type == 8 && allData[ik+45][iHt]>0 )  feffC[ik]++; 
358
359           if(type == 8 && allData[ik+57][iHt]>0 )  feffA[ik]++; 
360           // GetRawsData(206)->Fill(ik,allData[ik+57][iHt]-allData[69][0]);
361           if(type == 8 && (allData[2*ik+57][iHt]>0 && allData[2*ik+58][iHt]>0) )
362             GetRawsData(207)->Fill(ik,allData[2*ik+57][iHt]-allData[2*ik+58][iHt]);               
363         }
364         effic = Float_t(feffC[ik])/Float_t(fnEvent);
365         GetRawsData(205)->Fill(ik,effic );
366         effic = Float_t(feffA[ik])/Float_t(fnEvent);
367         GetRawsData(206)->Fill(ik,effic );
368         //   printf("CFD  efficiency for PMT %i = %f \n", ik, effic);       }
369       }
370         
371       Int_t trChannel[6] = {49,50,51,52,55,56};  
372       if(type == 7)
373         {
374           for (Int_t iHt=0; iHt<6; iHt++) {
375             for (Int_t itr=0; itr<6; itr++) {
376               if(allData[trChannel[itr]][iHt]>0) fNumTriggers[itr]++;
377             }
378           }
379         }
380       if(type == 8)
381         {
382           for (Int_t iHt=0; iHt<5; iHt++) {
383             for (Int_t itr=0; itr<6; itr++) {
384               if(allData[trChannel[itr]][iHt]>0)
385                 {
386                   
387                   GetRawsData(198+itr)->Fill(allData[trChannel[itr]][iHt]-allData[1][0]);
388                   
389                   fNumTriggersCal[itr]++;
390                 }
391             }
392             if(allData[53][iHt]>0 && allData[54][iHt]>0) 
393               GetRawsData(204)->Fill(allData[53][iHt]-allData[54][iHt]);
394           }
395         } 
396
397       
398       
399       delete start;
400       }
401     }
402   
403
404
405 //____________________________________________________________________________
406 void AliT0QADataMakerRec::MakeRecPoints(TTree * clustersTree)
407 {
408   //fills QA histos for clusters
409
410   AliT0RecPoint* frecpoints= new AliT0RecPoint ();
411     if (!frecpoints) {
412     AliError("Reconstruct Fill ESD >> no recpoints found");
413     return;
414   }
415   TBranch *brRec =clustersTree ->GetBranch("T0");
416   if (brRec) {
417     brRec->SetAddress(&frecpoints);
418   }else{
419       AliError(Form("EXEC Branch T0 rec not found "));
420       return;
421   } 
422     
423   brRec->GetEntry(0);
424     
425   for ( Int_t i=0; i<24; i++) {
426     if(i<12)
427       GetRecPointsData(0) -> Fill(i, frecpoints -> GetTime(i) - frecpoints -> GetTime(0)); 
428     if(i>11)
429       GetRecPointsData(0) -> Fill(i,  frecpoints -> GetTime(i) - frecpoints -> GetTime(12)); 
430     GetRecPointsData(1) -> Fill( i, frecpoints -> GetAmp(i) - frecpoints->AmpLED(i));
431   }
432   Double_t mmm=frecpoints->GetOnlineMean()- frecpoints->GetMeanTime();
433    GetRecPointsData(2) ->Fill(mmm);
434    // printf(" AliT0QADataMakerRec: diff mean  %f \n",mmm ); 
435    // GetRecPointsData(73) ->Fill(frecpoints->GetMeanTime());
436   
437
438
439 }
440
441 //____________________________________________________________________________
442 void AliT0QADataMakerRec::MakeESDs(AliESDEvent * esd)
443 {
444   //fills QA histos for ESD
445
446   GetESDsData(0) -> Fill(esd->GetT0());
447   GetESDsData(1)-> Fill(esd->GetT0zVertex());
448
449 }