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