Fixes for bug #49914: Compilation breaks in trunk, and bug #48629: Trunk cannot read...
[u/mrichter/AliRoot.git] / ITS / AliITSQADataMakerRec.cxx
1 /**************************************************************************
2  * Copyright(c) 2007-2009, 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 /* $Id$ */
17
18 //  *************************************************************
19 //  Checks the quality assurance 
20 //  by comparing with reference data
21 //  contained in a DB
22 //  -------------------------------------------------------------
23 //  W. Ferrarese + P. Cerello Feb 2008
24 //  INFN Torino
25
26 // --- ROOT system ---
27 #include <TH2.h>
28 #include <TTree.h>
29 // --- Standard library ---
30
31 // --- AliRoot header files ---
32 #include "AliITSQADataMakerRec.h"
33 #include "AliITSQASPDDataMakerRec.h"
34 #include "AliITSQASDDDataMakerRec.h"
35 #include "AliITSQASSDDataMakerRec.h"
36 #include "AliLog.h"
37 #include "AliQAv1.h"
38 #include "AliQAChecker.h"
39 #include "AliITSQAChecker.h"
40 #include "AliRawReader.h"
41 #include "AliESDEvent.h"
42 #include "AliESDtrack.h"
43 #include "AliESDVertex.h"
44 #include "AliMultiplicity.h"
45
46 ClassImp(AliITSQADataMakerRec)
47
48 //____________________________________________________________________________ 
49 AliITSQADataMakerRec::AliITSQADataMakerRec(Bool_t kMode, Short_t subDet, Short_t ldc) :
50 AliQADataMakerRec(AliQAv1::GetDetName(AliQAv1::kITS), "ITS Quality Assurance Data Maker"),
51 fkOnline(kMode),
52 fHLTMode(0),
53 fSubDetector(subDet),
54 fLDC(ldc),
55 fSPDDataMaker(NULL),
56 fSDDDataMaker(NULL),
57 fSSDDataMaker(NULL)
58 {
59   //ctor used to discriminate OnLine-Offline analysis
60   if(fSubDetector < 0 || fSubDetector > 3) {
61         AliError("Error: fSubDetector number out of range; return\n");
62   }
63
64   // Initialization for RAW data 
65   if(fSubDetector == 0 || fSubDetector == 1) {
66     AliDebug(1,"AliITSQADM::Create SPD DataMakerRec\n");
67         fSPDDataMaker = new AliITSQASPDDataMakerRec(this,fkOnline);
68   }
69   if(fSubDetector == 0 || fSubDetector == 2) {
70         AliDebug(1,"AliITSQADM::Create SDD DataMakerRec\n");
71         fSDDDataMaker = new AliITSQASDDDataMakerRec(this,fkOnline);
72         if(fkOnline){SetHLTMode(fSDDDataMaker->GetHLTMode()); }
73   }
74   if(fSubDetector == 0 || fSubDetector == 3) {
75         AliDebug(1,"AliITSQADM::Create SSD DataMakerRec\n");
76         fSSDDataMaker = new AliITSQASSDDataMakerRec(this,fkOnline);
77   }
78 }
79
80 //____________________________________________________________________________ 
81 AliITSQADataMakerRec::~AliITSQADataMakerRec(){
82   // destructor
83   if(fSPDDataMaker)delete fSPDDataMaker;
84   if(fSDDDataMaker)delete fSDDDataMaker;
85   if(fSSDDataMaker)delete fSSDDataMaker;
86 }
87
88 //____________________________________________________________________________ 
89 AliITSQADataMakerRec::AliITSQADataMakerRec(const AliITSQADataMakerRec& qadm) :
90 AliQADataMakerRec(),
91 fkOnline(qadm.fkOnline),
92 fHLTMode(qadm.fHLTMode),
93 fSubDetector(qadm.fSubDetector),
94 fLDC(qadm.fLDC),
95 fSPDDataMaker(NULL),
96 fSDDDataMaker(NULL),
97 fSSDDataMaker(NULL)
98 {
99   //copy ctor 
100   SetName((const char*)qadm.GetName()) ; 
101   SetTitle((const char*)qadm.GetTitle());
102 }
103
104 //__________________________________________________________________
105 AliITSQADataMakerRec& AliITSQADataMakerRec::operator = (const AliITSQADataMakerRec& qac )
106 {
107   // Equal operator.
108   this->~AliITSQADataMakerRec();
109   new(this) AliITSQADataMakerRec(qac);
110   return *this;
111 }
112
113 //____________________________________________________________________________ 
114 void AliITSQADataMakerRec::StartOfDetectorCycle()
115 {
116   //Detector specific actions at start of cycle
117   AliDebug(1,"AliITSQADM::Start of ITS Cycle\n");
118   if(fSubDetector == 0 || fSubDetector == 1) fSPDDataMaker->StartOfDetectorCycle();
119   if(fSubDetector == 0 || fSubDetector == 2) fSDDDataMaker->StartOfDetectorCycle();
120   if(fSubDetector == 0 || fSubDetector == 3) fSSDDataMaker->StartOfDetectorCycle();
121 }
122
123 //____________________________________________________________________________ 
124 void AliITSQADataMakerRec::EndOfDetectorCycle(AliQAv1::TASKINDEX_t task, TObjArray** list)
125 {
126   // launch the QA checking
127
128   for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
129     SetEventSpecie(specie) ; 
130     AliDebug(1,"AliITSDM instantiates checker with Run(AliQAv1::kITS, task, list[specie])\n"); 
131     if(fSubDetector == 0 || fSubDetector == 1) fSPDDataMaker->EndOfDetectorCycle(task, list[specie]);
132     if(fSubDetector == 0 || fSubDetector == 2) fSDDDataMaker->EndOfDetectorCycle(task, list[specie]);
133     if(fSubDetector == 0 || fSubDetector == 3) fSSDDataMaker->EndOfDetectorCycle(task, list[specie]);
134   
135   
136     AliQAChecker *qac = AliQAChecker::Instance();
137     AliITSQAChecker *qacb = (AliITSQAChecker *) qac->GetDetQAChecker(0);
138     Int_t subdet=GetSubDet();
139     qacb->SetSubDet(subdet);
140  
141     if(subdet== 0 ){
142       qacb->SetTaskOffset(fSPDDataMaker->GetOffset(task), fSDDDataMaker->GetOffset(task), fSSDDataMaker->GetOffset(task)); //Setting the offset for the QAChecker list
143     }
144     else
145       if(subdet!=0){
146         Int_t offset=GetDetTaskOffset(subdet, task);
147         qacb->SetDetTaskOffset(subdet,offset);
148       }
149
150     qac->Run( AliQAv1::kITS , task, list); 
151
152   }
153 }
154
155 //____________________________________________________________________________ 
156 void AliITSQADataMakerRec::EndOfDetectorCycle(const char * /*fgDataName*/)
157 {
158   //eventually used for different  AliQAChecker::Instance()->Run
159 }
160
161 //____________________________________________________________________________ 
162 void AliITSQADataMakerRec::InitRaws()
163 {  
164   // Initialization for RAW data 
165         if(fSubDetector == 0 || fSubDetector == 1) {
166           AliDebug(1,"AliITSQADM:: SPD InitRaws\n");
167           fSPDDataMaker->InitRaws();
168         }
169         if(fSubDetector == 0 || fSubDetector == 2) {
170           AliDebug(1,"AliITSQADM:: SDD InitRaws\n");
171           fSDDDataMaker->InitRaws();
172         }
173         if(fSubDetector == 0 || fSubDetector == 3) {
174           AliDebug(1,"AliITSQADM:: SSD InitRaws\n");
175           fSSDDataMaker->InitRaws();
176         }
177 }
178
179 //____________________________________________________________________________
180 void AliITSQADataMakerRec::MakeRaws(AliRawReader* rawReader)
181
182   // Fill QA for RAW   
183   if(fSubDetector == 0 || fSubDetector == 1) fSPDDataMaker->MakeRaws(rawReader);
184   if(fSubDetector == 0 || fSubDetector == 2) fSDDDataMaker->MakeRaws(rawReader);
185   if(fSubDetector == 0 || fSubDetector == 3) fSSDDataMaker->MakeRaws(rawReader);
186 }
187
188 //____________________________________________________________________________ 
189 void AliITSQADataMakerRec::InitRecPoints()
190 {
191   // Initialization for RECPOINTS
192   if(fSubDetector == 0 || fSubDetector == 1) {
193         AliDebug(1,"AliITSQADM:: SPD InitRecPoints\n");
194     fSPDDataMaker->InitRecPoints();
195   }
196   if(fSubDetector == 0 || fSubDetector == 2) {
197         AliDebug(1,"AliITSQADM:: SDD InitRecPoints\n");
198         fSDDDataMaker->InitRecPoints();
199   }
200   if(fSubDetector == 0 || fSubDetector == 3) {
201         AliDebug(1,"AliITSQADM:: SSD InitRecPoints\n");
202         fSSDDataMaker->InitRecPoints();
203   }
204 }
205
206 //____________________________________________________________________________ 
207 void AliITSQADataMakerRec::MakeRecPoints(TTree * clustersTree)
208 {
209   // Fill QA for recpoints
210   if(fSubDetector == 0 || fSubDetector == 1) fSPDDataMaker->MakeRecPoints(clustersTree);
211   if(fSubDetector == 0 || fSubDetector == 2) fSDDDataMaker->MakeRecPoints(clustersTree);
212   if(fSubDetector == 0 || fSubDetector == 3) fSSDDataMaker->MakeRecPoints(clustersTree);
213 }
214
215
216 //____________________________________________________________________________ 
217 void AliITSQADataMakerRec::InitESDs()
218 {
219   // Create ESDs histograms in ESDs subdir
220
221   Bool_t expertHistogram = kTRUE;
222
223   TH1F *hESDClustersMI = 
224     new TH1F("hESDClustersMI", "N ITS clusters per track (MI); N clusters; Counts",
225              7, -0.5, 6.5);
226   hESDClustersMI->Sumw2();
227   hESDClustersMI->SetMinimum(0);
228   Add2ESDsList(hESDClustersMI, 0);
229
230   TH1F *hESDClusterMapMI =
231     new TH1F("hESDClusterMapMI", "N tracks with point Layer (MI); Layer; N tracks",
232              6, -0.5, 5.5);
233   hESDClusterMapMI->Sumw2();
234   hESDClusterMapMI->SetMinimum(0);
235   Add2ESDsList(hESDClusterMapMI, 1, expertHistogram);
236
237   TH1F *hESDClustersSA = 
238     new TH1F("hESDClustersSA", "N ITS clusters per track (SA); N clusters; Counts",
239              7, -0.5, 6.5);
240   hESDClustersSA->Sumw2();
241   hESDClustersSA->SetMinimum(0);
242   Add2ESDsList(hESDClustersSA, 2);
243
244   TH1F *hESDClusterMapSA =
245     new TH1F("hESDClusterMapSA", "N tracks with point Layer (SA); Layer; N tracks",
246              6, -0.5, 5.5);
247   hESDClusterMapSA->Sumw2();
248   hESDClusterMapSA->SetMinimum(0);
249   Add2ESDsList(hESDClusterMapSA, 3, expertHistogram);
250
251   TH1F *hSPDVertexX = 
252     new TH1F("hSPDVertexX","SPD Vertex x; x [cm]; N events",
253              10000,-2,2);
254   hSPDVertexX->Sumw2();
255   Add2ESDsList(hSPDVertexX, 4);
256
257   TH1F *hSPDVertexY = 
258     new TH1F("hSPDVertexY","SPD Vertex y; y [cm]; N events",
259              10000,-2,2);
260   hSPDVertexY->Sumw2();
261   Add2ESDsList(hSPDVertexY, 5);
262
263   TH1F *hSPDVertexZ = 
264     new TH1F("hSPDVertexZ","SPD Vertex Z; z [cm]; N events",
265              10000,-20,20);
266   hSPDVertexZ->Sumw2();
267   Add2ESDsList(hSPDVertexZ, 6);
268
269   TH1F *hSPDVertexContrOverMult =
270     new TH1F("hSPDVertexContrOverMult","SPD Vertex: contributors / multiplicity; N contributors / SPD multiplicity; N events",
271              100,-4,20);
272   hSPDVertexContrOverMult->Sumw2();
273   Add2ESDsList(hSPDVertexContrOverMult, 7, expertHistogram);
274
275   TH1F *hTrkVertexX = 
276     new TH1F("hTrkVertexX","ITS+TPC Trk Vertex x; x [cm]; N events",
277              10000,-2,2);
278   hTrkVertexX->Sumw2();
279   Add2ESDsList(hTrkVertexX, 8, expertHistogram);
280
281   TH1F *hTrkVertexY = 
282     new TH1F("hTrkVertexY","ITS+TPC Trk Vertex y; y [cm]; N events",
283              10000,-2,2);
284   hTrkVertexY->Sumw2();
285   Add2ESDsList(hTrkVertexY, 9, expertHistogram);
286
287   TH1F *hTrkVertexZ = 
288     new TH1F("hTrkVertexZ","ITS+TPC Trk Vertex Z; z [cm]; N events",
289              10000,-20,20);
290   hTrkVertexZ->Sumw2();
291   Add2ESDsList(hTrkVertexZ, 10, expertHistogram);
292
293   TH1F *hTrkVertexContrOverITSrefit5 =
294     new TH1F("hTrkVertexContrOverITSrefit5","ITS+TPC Trk Vertex: contributors / tracks; N contributors / N trks kITSrefit with 5 or 6 clusters; N events",
295              100,-4,2);
296   hTrkVertexContrOverITSrefit5->Sumw2();
297   Add2ESDsList(hTrkVertexContrOverITSrefit5, 11, expertHistogram);
298
299   TH1F *hSPDTrkVertexDeltaX =
300     new TH1F("hSPDTrkVertexDeltaX","Comparison of SPD and Trk vertices: x; xSPD-xTrk [cm]; N events",
301              1000,-1,1);
302   hSPDTrkVertexDeltaX->Sumw2();
303   Add2ESDsList(hSPDTrkVertexDeltaX, 12, expertHistogram);
304     
305   TH1F *hSPDTrkVertexDeltaY =
306     new TH1F("hSPDTrkVertexDeltaY","Comparison of SPD and Trk vertices: y; ySPD-yTrk [cm]; N events",
307              1000,-1,1);
308   hSPDTrkVertexDeltaY->Sumw2();
309   Add2ESDsList(hSPDTrkVertexDeltaY, 13, expertHistogram);
310     
311   TH1F *hSPDTrkVertexDeltaZ =
312     new TH1F("hSPDTrkVertexDeltaZ","Comparison of SPD and Trk vertices: z; zSPD-zTrk [cm]; N events",
313              1000,-1,1);
314   hSPDTrkVertexDeltaZ->Sumw2();
315   Add2ESDsList(hSPDTrkVertexDeltaZ, 14);
316     
317   // SPD Tracklets
318
319   TH1F* hSPDTracklets = 
320     new TH1F("hSPDTracklets","N SPD Tracklets; N tracklets; Counts",300,0.,300.);
321   hSPDTracklets->Sumw2();
322   Add2ESDsList(hSPDTracklets, 15); 
323
324   TH2F* hSPDTrackletsvsFiredChips0 = 
325     new TH2F("hSPDTrackletsvsFiredChips0","N SPD Tracklets vs N FiredChips Layer0",
326               300,0.,300.,300,0.,300.);
327   hSPDTrackletsvsFiredChips0->GetXaxis()->SetTitle("N SPD Tracklets"); 
328   hSPDTrackletsvsFiredChips0->GetYaxis()->SetTitle("N FiredChips Layer0"); 
329   hSPDTrackletsvsFiredChips0->Sumw2();
330   Add2ESDsList(hSPDTrackletsvsFiredChips0, 16, expertHistogram ); 
331
332   TH2F* hSPDTrackletsvsFiredChips1 = 
333     new TH2F("hSPDTrackletsvsFiredChips1","N SPD Tracklets vs N FiredChips Layer1",
334               300,0.,300.,300,0.,300.);
335   hSPDTrackletsvsFiredChips1->GetXaxis()->SetTitle("N SPD Tracklets"); 
336   hSPDTrackletsvsFiredChips1->GetYaxis()->SetTitle("N FiredChips Layer1"); 
337   hSPDTrackletsvsFiredChips1->Sumw2();
338   Add2ESDsList(hSPDTrackletsvsFiredChips1, 17, expertHistogram); 
339     
340   TH1F* hSPDTrackletsDePhi = 
341     new TH1F("hSPDTrackletsDePhi","DeltaPhi SPD Tracklets; DeltaPhi [rad]; N events",200,-0.2,0.2);
342   hSPDTrackletsDePhi->Sumw2();
343   Add2ESDsList(hSPDTrackletsDePhi, 18); 
344     
345   TH1F* hSPDTrackletsPhi = 
346     new TH1F("hSPDTrackletsPhi","Phi SPD Tracklets; Phi [rad]; N events",1000,0.,2*TMath::Pi());
347   hSPDTrackletsPhi->Sumw2();
348   Add2ESDsList(hSPDTrackletsPhi, 19); 
349     
350   TH1F* hSPDTrackletsTheta = 
351     new TH1F("hSPDTrackletsTheta","Theta SPD Tracklets; Theta [rad]; N events",500,0.,TMath::Pi());
352   hSPDTrackletsTheta->Sumw2();
353   Add2ESDsList(hSPDTrackletsTheta, 20); 
354
355   // map of layers skipped by tracking (set in AliITSRecoParam)
356   TH1F *hESDSkippedLayers = 
357     new TH1F("hESDSkippedLayers", "Map of layers skipped by tracking; Layer; Skipped",
358              6, -0.5, 5.5);
359   hESDSkippedLayers->Sumw2();
360   hESDSkippedLayers->SetMinimum(0);
361   Add2ESDsList(hESDSkippedLayers, 21, expertHistogram);
362
363
364   return;
365 }
366
367 //____________________________________________________________________________
368 void AliITSQADataMakerRec::MakeESDs(AliESDEvent *esd)
369 {
370   // Make QA data from ESDs
371   
372   const Int_t nESDTracks = esd->GetNumberOfTracks();
373   Int_t nITSrefit5 = 0; 
374
375   Int_t idet,status;
376   Float_t xloc,zloc;
377
378   // loop on tracks
379   for(Int_t i = 0; i < nESDTracks; i++) {
380     
381     AliESDtrack *track = esd->GetTrack(i);
382     
383     Int_t nclsITS = track->GetNcls(0);
384
385     Bool_t itsrefit=kFALSE,tpcin=kFALSE,itsin=kFALSE;
386     if ((track->GetStatus() & AliESDtrack::kITSrefit)) itsrefit=kTRUE;
387     if ((track->GetStatus() & AliESDtrack::kTPCin)) tpcin=kTRUE;     
388     if ((track->GetStatus() & AliESDtrack::kITSin)) itsin=kTRUE;     
389     if(nclsITS>=5 && itsrefit) nITSrefit5++;
390
391     if(tpcin) {
392       GetESDsData(0)->Fill(nclsITS);
393     }
394     if(itsin && !tpcin){
395       GetESDsData(2)->Fill(nclsITS);
396     }
397
398     for(Int_t layer=0; layer<6; layer++) {
399
400       if(TESTBIT(track->GetITSClusterMap(),layer)) {
401         if(tpcin) {
402           GetESDsData(1)->Fill(layer);
403         } else {
404           GetESDsData(3)->Fill(layer);
405         }
406       }
407       track->GetITSModuleIndexInfo(layer,idet,status,xloc,zloc);
408       if(status==3) GetESDsData(21)->SetBinContent(layer,1);
409     }     
410
411   } // end loop on tracks
412
413   // vertices
414   const AliESDVertex *vtxSPD = esd->GetPrimaryVertexSPD();
415   const AliESDVertex *vtxTrk = esd->GetPrimaryVertex();
416
417   Int_t mult = ((AliMultiplicity*)(esd->GetMultiplicity()))->GetNumberOfTracklets();
418   if(mult>0)
419     GetESDsData(7)->Fill((Float_t)(vtxSPD->GetNContributors())/(Float_t)mult);
420
421   if(nITSrefit5>0)
422     GetESDsData(11)->Fill((Float_t)(vtxTrk->GetNIndices())/(Float_t)nITSrefit5);
423
424   if(vtxSPD->GetNContributors()>0) {
425     GetESDsData(4)->Fill(vtxSPD->GetXv());
426     GetESDsData(5)->Fill(vtxSPD->GetYv());
427     GetESDsData(6)->Fill(vtxSPD->GetZv());
428   }
429
430   if(vtxTrk->GetNContributors()>0) {
431     GetESDsData(8)->Fill(vtxTrk->GetXv());
432     GetESDsData(9)->Fill(vtxTrk->GetYv());
433     GetESDsData(10)->Fill(vtxTrk->GetZv());
434   }
435
436   if(vtxSPD->GetNContributors()>0 && 
437      vtxTrk->GetNContributors()>0) {
438     GetESDsData(12)->Fill(vtxSPD->GetXv()-vtxTrk->GetXv());
439     GetESDsData(13)->Fill(vtxSPD->GetYv()-vtxTrk->GetYv());
440     GetESDsData(14)->Fill(vtxSPD->GetZv()-vtxTrk->GetZv());
441   }
442
443   // SPD Tracklets
444   GetESDsData(15)->Fill(mult);
445
446   Short_t nFiredChips0 = ((AliMultiplicity*)(esd->GetMultiplicity()))->GetNumberOfFiredChips(0);
447   Short_t nFiredChips1 = ((AliMultiplicity*)(esd->GetMultiplicity()))->GetNumberOfFiredChips(1);
448   GetESDsData(16)->Fill(nFiredChips0,mult);
449   GetESDsData(17)->Fill(nFiredChips1,mult);
450
451   // Loop over tracklets
452   for (Int_t itr=0; itr<mult; ++itr) {
453     Float_t dePhiTr = ((AliMultiplicity*)(esd->GetMultiplicity()))->GetDeltaPhi(itr);
454     Float_t phiTr   = ((AliMultiplicity*)(esd->GetMultiplicity()))->GetPhi(itr);
455     Float_t thetaTr = ((AliMultiplicity*)(esd->GetMultiplicity()))->GetTheta(itr);
456     GetESDsData(18)->Fill(dePhiTr);
457     GetESDsData(19)->Fill(phiTr);
458     GetESDsData(20)->Fill(thetaTr);
459   } // end loop on tracklets
460
461   return;
462 }
463
464 //_________________________________________________________________
465 Int_t AliITSQADataMakerRec::GetDetTaskOffset(Int_t subdet,AliQAv1::TASKINDEX_t task)
466 {
467   switch(subdet)
468     {
469
470       Int_t offset;
471     case 1:
472       offset=fSPDDataMaker->GetOffset(task);
473       return offset;
474       break;
475     case 2:
476       offset=fSDDDataMaker->GetOffset(task);
477       return offset;
478       break;
479     case 3:
480       offset=fSSDDataMaker->GetOffset(task);
481       return offset;
482       break;
483     default:
484       AliWarning("No specific subdetector (SPD, SDD, SSD) selected!! Offset set to zero \n");
485       offset=0;
486       return offset;
487       break;
488     }
489   //return offset;
490 }