Typo fixed. Cut changed in ESD QA (A. Dainese)
[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 fSubDetector(subDet),
52 fLDC(ldc),
53 fSPDDataMaker(NULL),
54 fSDDDataMaker(NULL),
55 fSSDDataMaker(NULL)
56 {
57   //ctor used to discriminate OnLine-Offline analysis
58   if(fSubDetector < 0 || fSubDetector > 3) {
59         AliError("Error: fSubDetector number out of range; return\n");
60   }
61
62   // Initialization for RAW data 
63   if(fSubDetector == 0 || fSubDetector == 1) {
64     AliDebug(1,"AliITSQADM::Create SPD DataMakerRec\n");
65         fSPDDataMaker = new AliITSQASPDDataMakerRec(this,fkOnline);
66   }
67   if(fSubDetector == 0 || fSubDetector == 2) {
68         AliDebug(1,"AliITSQADM::Create SDD DataMakerRec\n");
69         fSDDDataMaker = new AliITSQASDDDataMakerRec(this,fkOnline);
70   }
71   if(fSubDetector == 0 || fSubDetector == 3) {
72         AliDebug(1,"AliITSQADM::Create SSD DataMakerRec\n");
73         fSSDDataMaker = new AliITSQASSDDataMakerRec(this,fkOnline);
74   }
75 }
76
77 //____________________________________________________________________________ 
78 AliITSQADataMakerRec::~AliITSQADataMakerRec(){
79   // destructor
80   if(fSPDDataMaker)delete fSPDDataMaker;
81   if(fSDDDataMaker)delete fSDDDataMaker;
82   if(fSSDDataMaker)delete fSSDDataMaker;
83 }
84
85 //____________________________________________________________________________ 
86 AliITSQADataMakerRec::AliITSQADataMakerRec(const AliITSQADataMakerRec& qadm) :
87 AliQADataMakerRec(),
88 fkOnline(qadm.fkOnline),
89 fSubDetector(qadm.fSubDetector),
90 fLDC(qadm.fLDC),
91 fSPDDataMaker(NULL),
92 fSDDDataMaker(NULL),
93 fSSDDataMaker(NULL)
94 {
95   //copy ctor 
96   SetName((const char*)qadm.GetName()) ; 
97   SetTitle((const char*)qadm.GetTitle());
98 }
99
100 //__________________________________________________________________
101 AliITSQADataMakerRec& AliITSQADataMakerRec::operator = (const AliITSQADataMakerRec& qac )
102 {
103   // Equal operator.
104   this->~AliITSQADataMakerRec();
105   new(this) AliITSQADataMakerRec(qac);
106   return *this;
107 }
108
109 //____________________________________________________________________________ 
110 void AliITSQADataMakerRec::StartOfDetectorCycle()
111 {
112   //Detector specific actions at start of cycle
113   AliDebug(1,"AliITSQADM::Start of ITS Cycle\n");
114   if(fSubDetector == 0 || fSubDetector == 1) fSPDDataMaker->StartOfDetectorCycle();
115   if(fSubDetector == 0 || fSubDetector == 2) fSDDDataMaker->StartOfDetectorCycle();
116   if(fSubDetector == 0 || fSubDetector == 3) fSSDDataMaker->StartOfDetectorCycle();
117 }
118
119 //____________________________________________________________________________ 
120 void AliITSQADataMakerRec::EndOfDetectorCycle(AliQA::TASKINDEX_t task, TObjArray* list)
121 {
122   // launch the QA checking
123   AliDebug(1,"AliITSDM instantiates checker with Run(AliQA::kITS, task, list)\n"); 
124   if(fSubDetector == 0 || fSubDetector == 1) fSPDDataMaker->EndOfDetectorCycle(task, list);
125   if(fSubDetector == 0 || fSubDetector == 2) fSDDDataMaker->EndOfDetectorCycle(task, list);
126   if(fSubDetector == 0 || fSubDetector == 3) fSSDDataMaker->EndOfDetectorCycle(task, list);
127   
128   AliQAChecker *qac = AliQAChecker::Instance();
129   AliITSQAChecker *qacb = (AliITSQAChecker *) qac->GetDetQAChecker(0);
130   if(fSubDetector == 0 ){
131     qacb->SetTaskOffset(fSPDDataMaker->GetOffset(), fSDDDataMaker->GetOffset(), fSSDDataMaker->GetOffset()); //Setting the offset for the QAChecker list
132   }
133   qac->Run( AliQA::kITS , task, list);  //temporary skipping the checking
134 }
135
136 //____________________________________________________________________________ 
137 void AliITSQADataMakerRec::EndOfDetectorCycle(const char * /*fgDataName*/)
138 {
139   //eventually used for different  AliQAChecker::Instance()->Run
140 }
141
142 //____________________________________________________________________________ 
143 void AliITSQADataMakerRec::InitRaws()
144 {  
145   // Initialization for RAW data 
146         if(fSubDetector == 0 || fSubDetector == 1) {
147           AliDebug(1,"AliITSQADM:: SPD InitRaws\n");
148           fSPDDataMaker->InitRaws();
149         }
150         if(fSubDetector == 0 || fSubDetector == 2) {
151           AliDebug(1,"AliITSQADM:: SDD InitRaws\n");
152           fSDDDataMaker->InitRaws();
153         }
154         if(fSubDetector == 0 || fSubDetector == 3) {
155           AliDebug(1,"AliITSQADM:: SSD InitRaws\n");
156           fSSDDataMaker->InitRaws();
157         }
158 }
159
160 //____________________________________________________________________________
161 void AliITSQADataMakerRec::MakeRaws(AliRawReader* rawReader)
162
163   // Fill QA for RAW   
164   if(fSubDetector == 0 || fSubDetector == 1) fSPDDataMaker->MakeRaws(rawReader);
165   if(fSubDetector == 0 || fSubDetector == 2) fSDDDataMaker->MakeRaws(rawReader);
166   if(fSubDetector == 0 || fSubDetector == 3) fSSDDataMaker->MakeRaws(rawReader);
167 }
168
169 //____________________________________________________________________________ 
170 void AliITSQADataMakerRec::InitRecPoints()
171 {
172   // Initialization for RECPOINTS
173   if(fSubDetector == 0 || fSubDetector == 1) {
174         AliDebug(1,"AliITSQADM:: SPD InitRecPoints\n");
175     fSPDDataMaker->InitRecPoints();
176   }
177   if(fSubDetector == 0 || fSubDetector == 2) {
178         AliDebug(1,"AliITSQADM:: SDD InitRecPoints\n");
179         fSDDDataMaker->InitRecPoints();
180   }
181   if(fSubDetector == 0 || fSubDetector == 3) {
182         AliDebug(1,"AliITSQADM:: SSD InitRecPoints\n");
183         fSSDDataMaker->InitRecPoints();
184   }
185 }
186
187 //____________________________________________________________________________ 
188 void AliITSQADataMakerRec::MakeRecPoints(TTree * clustersTree)
189 {
190   // Fill QA for recpoints
191   if(fSubDetector == 0 || fSubDetector == 1) fSPDDataMaker->MakeRecPoints(clustersTree);
192   if(fSubDetector == 0 || fSubDetector == 2) fSDDDataMaker->MakeRecPoints(clustersTree);
193   if(fSubDetector == 0 || fSubDetector == 3) fSSDDataMaker->MakeRecPoints(clustersTree);
194 }
195
196
197 //____________________________________________________________________________ 
198 void AliITSQADataMakerRec::InitESDs()
199 {
200   // Create ESDs histograms in ESDs subdir
201
202   TH1F *hESDClustersMI = 
203     new TH1F("hESDClustersMI", "N ITS clusters per track (MI); N clusters; Counts",
204              7, -0.5, 6.5);
205   hESDClustersMI->Sumw2();
206   hESDClustersMI->SetMinimum(0);
207   Add2ESDsList(hESDClustersMI, 0);
208
209   TH1F *hESDClusterMapMI =
210     new TH1F("hESDClusterMapMI", "N tracks with point Layer (MI); Layer; N tracks",
211              6, -0.5, 5.5);
212   hESDClusterMapMI->Sumw2();
213   hESDClusterMapMI->SetMinimum(0);
214   Add2ESDsList(hESDClusterMapMI, 1);
215
216   TH1F *hESDClustersSA = 
217     new TH1F("hESDClustersSA", "N ITS clusters per track (SA); N clusters; Counts",
218              7, -0.5, 6.5);
219   hESDClustersSA->Sumw2();
220   hESDClustersSA->SetMinimum(0);
221   Add2ESDsList(hESDClustersSA, 2);
222
223   TH1F *hESDClusterMapSA =
224     new TH1F("hESDClusterMapSA", "N tracks with point Layer (SA); Layer; N tracks",
225              6, -0.5, 5.5);
226   hESDClusterMapSA->Sumw2();
227   hESDClusterMapSA->SetMinimum(0);
228   Add2ESDsList(hESDClusterMapSA, 3);
229
230   TH1F *hSPDVertexX = 
231     new TH1F("hSPDVertexX","SPD Vertex x; x [cm]; N events",
232              10000,-2,2);
233   hSPDVertexX->Sumw2();
234   Add2ESDsList(hSPDVertexX, 4);
235
236   TH1F *hSPDVertexY = 
237     new TH1F("hSPDVertexY","SPD Vertex y; y [cm]; N events",
238              10000,-2,2);
239   hSPDVertexY->Sumw2();
240   Add2ESDsList(hSPDVertexY, 5);
241
242   TH1F *hSPDVertexZ = 
243     new TH1F("hSPDVertexZ","SPD Vertex Z; z [cm]; N events",
244              10000,-20,20);
245   hSPDVertexZ->Sumw2();
246   Add2ESDsList(hSPDVertexZ, 6);
247
248   TH1F *hSPDVertexContrOverMult =
249     new TH1F("hSPDVertexContrOverMult","SPD Vertex: contributors / multiplicity; N contributors / SPD multiplicity; N events",
250              100,-4,20);
251   hSPDVertexContrOverMult->Sumw2();
252   Add2ESDsList(hSPDVertexContrOverMult, 7);
253
254   TH1F *hTrkVertexX = 
255     new TH1F("hTrkVertexX","ITS+TPC Trk Vertex x; x [cm]; N events",
256              10000,-2,2);
257   hTrkVertexX->Sumw2();
258   Add2ESDsList(hTrkVertexX, 8);
259
260   TH1F *hTrkVertexY = 
261     new TH1F("hTrkVertexY","ITS+TPC Trk Vertex y; y [cm]; N events",
262              10000,-2,2);
263   hTrkVertexY->Sumw2();
264   Add2ESDsList(hTrkVertexY, 9);
265
266   TH1F *hTrkVertexZ = 
267     new TH1F("hTrkVertexZ","ITS+TPC Trk Vertex Z; z [cm]; N events",
268              10000,-20,20);
269   hTrkVertexZ->Sumw2();
270   Add2ESDsList(hTrkVertexZ, 10);
271
272   TH1F *hTrkVertexContrOverITSrefit5 =
273     new TH1F("hTrkVertexContrOverITSrefit5","ITS+TPC Trk Vertex: contributors / tracks; N contributors / N trks kITSrefit with 5 or 6 clusters; N events",
274              100,-4,2);
275   hTrkVertexContrOverITSrefit5->Sumw2();
276   Add2ESDsList(hTrkVertexContrOverITSrefit5, 11);
277
278   TH1F *hSPDTrkVertexDeltaX =
279     new TH1F("hSPDTrkVertexDeltaX","Comparison of SPD and Trk vertices: x; xSPD-xTrk [cm]; N events",
280              1000,-1,1);
281   hSPDTrkVertexDeltaX->Sumw2();
282   Add2ESDsList(hSPDTrkVertexDeltaX, 12);
283     
284   TH1F *hSPDTrkVertexDeltaY =
285     new TH1F("hSPDTrkVertexDeltaY","Comparison of SPD and Trk vertices: y; ySPD-yTrk [cm]; N events",
286              1000,-1,1);
287   hSPDTrkVertexDeltaY->Sumw2();
288   Add2ESDsList(hSPDTrkVertexDeltaY, 13);
289     
290   TH1F *hSPDTrkVertexDeltaZ =
291     new TH1F("hSPDTrkVertexDeltaZ","Comparison of SPD and Trk vertices: z; zSPD-zTrk [cm]; N events",
292              1000,-1,1);
293   hSPDTrkVertexDeltaZ->Sumw2();
294   Add2ESDsList(hSPDTrkVertexDeltaZ, 14);
295     
296   return;
297 }
298
299 //____________________________________________________________________________
300 void AliITSQADataMakerRec::MakeESDs(AliESDEvent *esd)
301 {
302   // Make QA data from ESDs
303   
304   const Int_t nESDTracks = esd->GetNumberOfTracks();
305   Int_t nITSrefit5 = 0; 
306
307   // loop on tracks
308   for(Int_t i = 0; i < nESDTracks; i++) {
309     
310     AliESDtrack *track = esd->GetTrack(i);
311     
312     Int_t nclsITS = track->GetNcls(0);
313
314     Bool_t itsrefit=kFALSE,tpcin=kFALSE;
315     if ((track->GetStatus() & AliESDtrack::kITSrefit)) itsrefit=kTRUE;
316     if ((track->GetStatus() & AliESDtrack::kTPCin)) tpcin=kTRUE;     
317     if(nclsITS>=5 && itsrefit) nITSrefit5++;
318
319     if(tpcin) {
320       GetESDsData(0)->Fill(nclsITS);
321     } else {
322       GetESDsData(2)->Fill(nclsITS);
323     }
324
325     for(Int_t layer=0; layer<6; layer++) {
326
327       if(TESTBIT(track->GetITSClusterMap(),layer)) {
328         if(tpcin) {
329           GetESDsData(1)->Fill(layer);
330         } else {
331           GetESDsData(3)->Fill(layer);
332         }
333       }
334
335     }     
336
337   } // end loop on tracks
338
339   // vertices
340   const AliESDVertex *vtxSPD = esd->GetPrimaryVertexSPD();
341   const AliESDVertex *vtxTrk = esd->GetPrimaryVertex();
342
343   Int_t mult = ((AliMultiplicity*)(esd->GetMultiplicity()))->GetNumberOfTracklets();
344   if(mult>0)
345     GetESDsData(7)->Fill((Float_t)(vtxSPD->GetNContributors())/(Float_t)mult);
346
347   if(nITSrefit5>0)
348     GetESDsData(11)->Fill((Float_t)(vtxTrk->GetNIndices())/(Float_t)nITSrefit5);
349
350   if(vtxSPD->GetNContributors()>0) {
351     GetESDsData(4)->Fill(vtxSPD->GetXv());
352     GetESDsData(5)->Fill(vtxSPD->GetYv());
353     GetESDsData(6)->Fill(vtxSPD->GetZv());
354   }
355
356   if(vtxTrk->GetNContributors()>0) {
357     GetESDsData(8)->Fill(vtxTrk->GetXv());
358     GetESDsData(9)->Fill(vtxTrk->GetYv());
359     GetESDsData(10)->Fill(vtxTrk->GetZv());
360   }
361
362   if(vtxSPD->GetNContributors()>0 && 
363      vtxTrk->GetNContributors()>0) {
364     GetESDsData(12)->Fill(vtxSPD->GetXv()-vtxTrk->GetXv());
365     GetESDsData(13)->Fill(vtxSPD->GetYv()-vtxTrk->GetYv());
366     GetESDsData(14)->Fill(vtxSPD->GetZv()-vtxTrk->GetZv());
367   }
368
369   return;
370 }