55492cc8ccbbbeacb69cbbea51cc3d3b3e3c6b30
[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   Bool_t expertHistogram = kTRUE;
203
204   TH1F *hESDClustersMI = 
205     new TH1F("hESDClustersMI", "N ITS clusters per track (MI); N clusters; Counts",
206              7, -0.5, 6.5);
207   hESDClustersMI->Sumw2();
208   hESDClustersMI->SetMinimum(0);
209   Add2ESDsList(hESDClustersMI, 0);
210
211   TH1F *hESDClusterMapMI =
212     new TH1F("hESDClusterMapMI", "N tracks with point Layer (MI); Layer; N tracks",
213              6, -0.5, 5.5);
214   hESDClusterMapMI->Sumw2();
215   hESDClusterMapMI->SetMinimum(0);
216   Add2ESDsList(hESDClusterMapMI, 1, expertHistogram);
217
218   TH1F *hESDClustersSA = 
219     new TH1F("hESDClustersSA", "N ITS clusters per track (SA); N clusters; Counts",
220              7, -0.5, 6.5);
221   hESDClustersSA->Sumw2();
222   hESDClustersSA->SetMinimum(0);
223   Add2ESDsList(hESDClustersSA, 2);
224
225   TH1F *hESDClusterMapSA =
226     new TH1F("hESDClusterMapSA", "N tracks with point Layer (SA); Layer; N tracks",
227              6, -0.5, 5.5);
228   hESDClusterMapSA->Sumw2();
229   hESDClusterMapSA->SetMinimum(0);
230   Add2ESDsList(hESDClusterMapSA, 3, expertHistogram);
231
232   TH1F *hSPDVertexX = 
233     new TH1F("hSPDVertexX","SPD Vertex x; x [cm]; N events",
234              10000,-2,2);
235   hSPDVertexX->Sumw2();
236   Add2ESDsList(hSPDVertexX, 4);
237
238   TH1F *hSPDVertexY = 
239     new TH1F("hSPDVertexY","SPD Vertex y; y [cm]; N events",
240              10000,-2,2);
241   hSPDVertexY->Sumw2();
242   Add2ESDsList(hSPDVertexY, 5);
243
244   TH1F *hSPDVertexZ = 
245     new TH1F("hSPDVertexZ","SPD Vertex Z; z [cm]; N events",
246              10000,-20,20);
247   hSPDVertexZ->Sumw2();
248   Add2ESDsList(hSPDVertexZ, 6);
249
250   TH1F *hSPDVertexContrOverMult =
251     new TH1F("hSPDVertexContrOverMult","SPD Vertex: contributors / multiplicity; N contributors / SPD multiplicity; N events",
252              100,-4,20);
253   hSPDVertexContrOverMult->Sumw2();
254   Add2ESDsList(hSPDVertexContrOverMult, 7, expertHistogram);
255
256   TH1F *hTrkVertexX = 
257     new TH1F("hTrkVertexX","ITS+TPC Trk Vertex x; x [cm]; N events",
258              10000,-2,2);
259   hTrkVertexX->Sumw2();
260   Add2ESDsList(hTrkVertexX, 8, expertHistogram);
261
262   TH1F *hTrkVertexY = 
263     new TH1F("hTrkVertexY","ITS+TPC Trk Vertex y; y [cm]; N events",
264              10000,-2,2);
265   hTrkVertexY->Sumw2();
266   Add2ESDsList(hTrkVertexY, 9, expertHistogram);
267
268   TH1F *hTrkVertexZ = 
269     new TH1F("hTrkVertexZ","ITS+TPC Trk Vertex Z; z [cm]; N events",
270              10000,-20,20);
271   hTrkVertexZ->Sumw2();
272   Add2ESDsList(hTrkVertexZ, 10, expertHistogram);
273
274   TH1F *hTrkVertexContrOverITSrefit5 =
275     new TH1F("hTrkVertexContrOverITSrefit5","ITS+TPC Trk Vertex: contributors / tracks; N contributors / N trks kITSrefit with 5 or 6 clusters; N events",
276              100,-4,2);
277   hTrkVertexContrOverITSrefit5->Sumw2();
278   Add2ESDsList(hTrkVertexContrOverITSrefit5, 11, expertHistogram);
279
280   TH1F *hSPDTrkVertexDeltaX =
281     new TH1F("hSPDTrkVertexDeltaX","Comparison of SPD and Trk vertices: x; xSPD-xTrk [cm]; N events",
282              1000,-1,1);
283   hSPDTrkVertexDeltaX->Sumw2();
284   Add2ESDsList(hSPDTrkVertexDeltaX, 12, expertHistogram);
285     
286   TH1F *hSPDTrkVertexDeltaY =
287     new TH1F("hSPDTrkVertexDeltaY","Comparison of SPD and Trk vertices: y; ySPD-yTrk [cm]; N events",
288              1000,-1,1);
289   hSPDTrkVertexDeltaY->Sumw2();
290   Add2ESDsList(hSPDTrkVertexDeltaY, 13, expertHistogram);
291     
292   TH1F *hSPDTrkVertexDeltaZ =
293     new TH1F("hSPDTrkVertexDeltaZ","Comparison of SPD and Trk vertices: z; zSPD-zTrk [cm]; N events",
294              1000,-1,1);
295   hSPDTrkVertexDeltaZ->Sumw2();
296   Add2ESDsList(hSPDTrkVertexDeltaZ, 14);
297     
298   // SPD Tracklets
299
300   TH1F* hSPDTracklets = 
301     new TH1F("hSPDTracklets","N SPD Tracklets; N tracklets; Counts",300,0.,300.);
302   hSPDTracklets->Sumw2();
303   Add2ESDsList(hSPDTracklets, 15); 
304     
305   TH1F* hSPDTrackletsDePhi = 
306     new TH1F("hSPDTrackletsDePhi","DeltaPhi SPD Tracklets; DeltaPhi [rad]; N events",200,-0.2,0.2);
307   hSPDTrackletsDePhi->Sumw2();
308   Add2ESDsList(hSPDTrackletsDePhi, 16); 
309     
310   TH1F* hSPDTrackletsPhi = 
311     new TH1F("hSPDTrackletsPhi","Phi SPD Tracklets; Phi [rad]; N events",1000,0.,2*TMath::Pi());
312   hSPDTrackletsPhi->Sumw2();
313   Add2ESDsList(hSPDTrackletsPhi, 17); 
314     
315   TH1F* hSPDTrackletsTheta = 
316     new TH1F("hSPDTrackletsTheta","Theta SPD Tracklets; Theta [rad]; N events",500,0.,TMath::Pi());
317   hSPDTrackletsTheta->Sumw2();
318   Add2ESDsList(hSPDTrackletsTheta, 18); 
319
320   return;
321 }
322
323 //____________________________________________________________________________
324 void AliITSQADataMakerRec::MakeESDs(AliESDEvent *esd)
325 {
326   // Make QA data from ESDs
327   
328   const Int_t nESDTracks = esd->GetNumberOfTracks();
329   Int_t nITSrefit5 = 0; 
330
331   // loop on tracks
332   for(Int_t i = 0; i < nESDTracks; i++) {
333     
334     AliESDtrack *track = esd->GetTrack(i);
335     
336     Int_t nclsITS = track->GetNcls(0);
337
338     Bool_t itsrefit=kFALSE,tpcin=kFALSE;
339     if ((track->GetStatus() & AliESDtrack::kITSrefit)) itsrefit=kTRUE;
340     if ((track->GetStatus() & AliESDtrack::kTPCin)) tpcin=kTRUE;     
341     if(nclsITS>=5 && itsrefit) nITSrefit5++;
342
343     if(tpcin) {
344       GetESDsData(0)->Fill(nclsITS);
345     } else {
346       GetESDsData(2)->Fill(nclsITS);
347     }
348
349     for(Int_t layer=0; layer<6; layer++) {
350
351       if(TESTBIT(track->GetITSClusterMap(),layer)) {
352         if(tpcin) {
353           GetESDsData(1)->Fill(layer);
354         } else {
355           GetESDsData(3)->Fill(layer);
356         }
357       }
358
359     }     
360
361   } // end loop on tracks
362
363   // vertices
364   const AliESDVertex *vtxSPD = esd->GetPrimaryVertexSPD();
365   const AliESDVertex *vtxTrk = esd->GetPrimaryVertex();
366
367   Int_t mult = ((AliMultiplicity*)(esd->GetMultiplicity()))->GetNumberOfTracklets();
368   if(mult>0)
369     GetESDsData(7)->Fill((Float_t)(vtxSPD->GetNContributors())/(Float_t)mult);
370
371   if(nITSrefit5>0)
372     GetESDsData(11)->Fill((Float_t)(vtxTrk->GetNIndices())/(Float_t)nITSrefit5);
373
374   if(vtxSPD->GetNContributors()>0) {
375     GetESDsData(4)->Fill(vtxSPD->GetXv());
376     GetESDsData(5)->Fill(vtxSPD->GetYv());
377     GetESDsData(6)->Fill(vtxSPD->GetZv());
378   }
379
380   if(vtxTrk->GetNContributors()>0) {
381     GetESDsData(8)->Fill(vtxTrk->GetXv());
382     GetESDsData(9)->Fill(vtxTrk->GetYv());
383     GetESDsData(10)->Fill(vtxTrk->GetZv());
384   }
385
386   if(vtxSPD->GetNContributors()>0 && 
387      vtxTrk->GetNContributors()>0) {
388     GetESDsData(12)->Fill(vtxSPD->GetXv()-vtxTrk->GetXv());
389     GetESDsData(13)->Fill(vtxSPD->GetYv()-vtxTrk->GetYv());
390     GetESDsData(14)->Fill(vtxSPD->GetZv()-vtxTrk->GetZv());
391   }
392
393   // SPD Tracklets
394
395   // Loop over tracklets
396   GetESDsData(15)->Fill(mult);
397   for (Int_t itr=0; itr<mult; ++itr) {
398     Float_t dePhiTr = ((AliMultiplicity*)(esd->GetMultiplicity()))->GetDeltaPhi(itr);
399     Float_t phiTr   = ((AliMultiplicity*)(esd->GetMultiplicity()))->GetPhi(itr);
400     Float_t thetaTr = ((AliMultiplicity*)(esd->GetMultiplicity()))->GetTheta(itr);
401     GetESDsData(16)->Fill(dePhiTr);
402     GetESDsData(17)->Fill(phiTr);
403     GetESDsData(18)->Fill(thetaTr);
404   } // end loop on tracklets
405
406   return;
407 }