Fixed a bug in the Digit reader, moved clusterfinder to initialize from OCDB, Added...
[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 //  Melinda Siciliano Aug 2008
26
27
28 // --- ROOT system ---
29 #include <TH2.h>
30 #include <TTree.h>
31 // --- Standard library ---
32
33 // --- AliRoot header files ---
34 #include "AliITSQADataMakerRec.h"
35 #include "AliITSQASPDDataMakerRec.h"
36 #include "AliITSQASDDDataMakerRec.h"
37 #include "AliITSQASSDDataMakerRec.h"
38 #include "AliLog.h"
39 #include "AliQAv1.h"
40 #include "AliQAChecker.h"
41 #include "AliITSQAChecker.h"
42 #include "AliITSRecPoint.h"
43 #include "AliRawReader.h"
44 #include "AliESDEvent.h"
45 #include "AliESDtrack.h"
46 #include "AliESDVertex.h"
47 #include "AliMultiplicity.h"
48 #include "AliITSgeomTGeo.h"
49
50 ClassImp(AliITSQADataMakerRec)
51
52 //____________________________________________________________________________ 
53 AliITSQADataMakerRec::AliITSQADataMakerRec(Bool_t kMode, Short_t subDet, Short_t ldc) :
54 AliQADataMakerRec(AliQAv1::GetDetName(AliQAv1::kITS), "ITS Quality Assurance Data Maker"),
55 fkOnline(kMode),
56 fSubDetector(subDet),
57 fLDC(ldc),
58 fRunNumber(0),
59 fSPDDataMaker(NULL),
60 fSDDDataMaker(NULL),
61 fSSDDataMaker(NULL)
62
63 {
64   //ctor used to discriminate OnLine-Offline analysis
65   if(fSubDetector < 0 || fSubDetector > 3) {
66         AliError("Error: fSubDetector number out of range; return\n");
67   }
68
69   // Initialization for RAW data 
70   if(fSubDetector == 0 || fSubDetector == 1) {
71     AliDebug(AliQAv1::GetQADebugLevel(),"AliITSQADM::Create SPD DataMakerRec\n");
72         fSPDDataMaker = new AliITSQASPDDataMakerRec(this,fkOnline);
73   }
74   if(fSubDetector == 0 || fSubDetector == 2) {
75     AliDebug(AliQAv1::GetQADebugLevel(),"AliITSQADM::Create SDD DataMakerRec\n");
76         fSDDDataMaker = new AliITSQASDDDataMakerRec(this,fkOnline);
77   }
78   if(fSubDetector == 0 || fSubDetector == 3) {
79     AliDebug(AliQAv1::GetQADebugLevel(),"AliITSQADM::Create SSD DataMakerRec\n");
80         fSSDDataMaker = new AliITSQASSDDataMakerRec(this,fkOnline);
81   }
82 }
83
84 //____________________________________________________________________________ 
85 AliITSQADataMakerRec::~AliITSQADataMakerRec(){
86   // destructor
87   if(fSPDDataMaker)delete fSPDDataMaker;
88   if(fSDDDataMaker)delete fSDDDataMaker;
89   if(fSSDDataMaker)delete fSSDDataMaker;
90 }
91
92 //____________________________________________________________________________ 
93 AliITSQADataMakerRec::AliITSQADataMakerRec(const AliITSQADataMakerRec& qadm) :
94 AliQADataMakerRec(),
95 fkOnline(qadm.fkOnline),
96 fSubDetector(qadm.fSubDetector),
97 fLDC(qadm.fLDC),
98 fRunNumber(0),
99 fSPDDataMaker(NULL),
100 fSDDDataMaker(NULL),
101 fSSDDataMaker(NULL)
102
103 {
104   //copy ctor 
105   SetName((const char*)qadm.GetName()) ; 
106   SetTitle((const char*)qadm.GetTitle());
107 }
108
109 //__________________________________________________________________
110 AliITSQADataMakerRec& AliITSQADataMakerRec::operator = (const AliITSQADataMakerRec& qac )
111 {
112   // Equal operator.
113   this->~AliITSQADataMakerRec();
114   new(this) AliITSQADataMakerRec(qac);
115   return *this;
116 }
117
118 //____________________________________________________________________________ 
119 void AliITSQADataMakerRec::StartOfDetectorCycle()
120 {
121   //Detector specific actions at start of cycle
122   AliDebug(AliQAv1::GetQADebugLevel(),"AliITSQADM::Start of ITS Cycle\n");
123   if(fSubDetector == 0 || fSubDetector == 1) fSPDDataMaker->StartOfDetectorCycle();
124   if(fSubDetector == 0 || fSubDetector == 2) fSDDDataMaker->StartOfDetectorCycle();
125   if(fSubDetector == 0 || fSubDetector == 3) fSSDDataMaker->StartOfDetectorCycle();
126 }
127
128 //____________________________________________________________________________ 
129 void AliITSQADataMakerRec::EndOfDetectorCycle(AliQAv1::TASKINDEX_t task, TObjArray** list)
130 {
131   // launch the QA checking
132
133   for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
134     //SetEventSpecie(specie) ; 
135     //AliQAv1::Instance()->SetEventSpecie(specie);
136     if(AliQAv1::Instance()->IsEventSpecieSet(specie)){
137     AliDebug(AliQAv1::GetQADebugLevel(),"AliITSDM instantiates checker with Run(AliQAv1::kITS, task, list[specie])\n"); 
138     if(fSubDetector == 0 || fSubDetector == 1) fSPDDataMaker->EndOfDetectorCycle(task, list[/*GetEventSpecie()*/specie]);
139     if(fSubDetector == 0 || fSubDetector == 2) fSDDDataMaker->EndOfDetectorCycle(task, list[/*GetEventSpecie()*/specie]);
140     if(fSubDetector == 0 || fSubDetector == 3) fSSDDataMaker->EndOfDetectorCycle(task, list[/*GetEventSpecie()*/specie]);
141   
142   
143     AliQAChecker *qac = AliQAChecker::Instance();
144     qac->SetRunNumber(GetRunNumber());
145     AliITSQAChecker *qacb = (AliITSQAChecker *) qac->GetDetQAChecker(0);
146     Int_t subdet=GetSubDet();
147     qacb->SetSubDet(subdet);
148  
149     if(subdet== 0 ){
150       qacb->SetTaskOffset(fSPDDataMaker->GetOffset(task), fSDDDataMaker->GetOffset(task), fSSDDataMaker->GetOffset(task)); //Setting the offset for the QAChecker list
151     }
152     else
153       if(subdet!=0){
154         Int_t offset=GetDetTaskOffset(subdet, task);
155         qacb->SetDetTaskOffset(subdet,offset);
156       }
157
158     qac->Run( AliQAv1::kITS , task, list);
159  
160     }
161     
162   }
163 }
164
165 //____________________________________________________________________________ 
166 void AliITSQADataMakerRec::EndOfDetectorCycle(const char * /*fgDataName*/)
167 {
168   //eventually used for different  AliQAChecker::Instance()->Run
169 }
170
171 //____________________________________________________________________________ 
172 void AliITSQADataMakerRec::InitRaws()
173 {  
174
175   //if(fRawsQAList[AliRecoParam::AConvert(fEventSpecie)]->GetEntries()) return;
176         
177
178   if(fSubDetector == 0 || fSubDetector == 1) {
179     AliDebug(AliQAv1::GetQADebugLevel(),"AliITSQADM:: SPD InitRaws\n");
180     fSPDDataMaker->InitRaws();
181   }
182   if(fSubDetector == 0 || fSubDetector == 2) {
183     AliDebug(AliQAv1::GetQADebugLevel(),"AliITSQADM:: SDD InitRaws\n");
184     
185     fSDDDataMaker->SetOffset(AliQAv1::kRAWS, fRawsQAList[AliRecoParam::AConvert(fEventSpecie)]->GetEntries(),AliRecoParam::AConvert(fEventSpecie));
186     fSDDDataMaker->InitRaws();
187   }
188   if(fSubDetector == 0 || fSubDetector == 3) {
189     AliDebug(AliQAv1::GetQADebugLevel(),"AliITSQADM:: SSD InitRaws\n");
190     
191     fSSDDataMaker->SetOffset(AliQAv1::kRAWS, fRawsQAList[AliRecoParam::AConvert(fEventSpecie)]->GetEntries(),AliRecoParam::AConvert(fEventSpecie));
192     fSSDDataMaker->InitRaws();
193   }
194 }
195
196 //____________________________________________________________________________
197 void AliITSQADataMakerRec::MakeRaws(AliRawReader* rawReader)
198
199   // Fill QA for RAW   
200   //return ; 
201
202   SetRunNumber(rawReader->GetRunNumber());
203
204   if(fSubDetector == 0 || fSubDetector == 1)  {
205     fSPDDataMaker->MakeRaws(rawReader) ; 
206   }
207   
208   if(fSubDetector == 0 || fSubDetector == 2) {
209     fSDDDataMaker->MakeRaws(rawReader) ; 
210   }
211
212   if(fSubDetector == 0 || fSubDetector == 3) fSSDDataMaker->MakeRaws(rawReader);
213
214 }
215
216 //____________________________________________________________________________ 
217 void AliITSQADataMakerRec::InitDigits()
218 {
219   
220   // Initialization for DIGITS
221   if(fSubDetector == 0 || fSubDetector == 1) {
222     AliDebug(AliQAv1::GetQADebugLevel(),"AliITSQADM:: SPD InitDigitss\n");
223
224     fSPDDataMaker->InitDigits();
225   }
226   if(fSubDetector == 0 || fSubDetector == 2) {
227     AliDebug(AliQAv1::GetQADebugLevel(),"AliITSQADM:: SDD InitDigits\n");
228     fSDDDataMaker->SetOffset(AliQAv1::kDIGITSR, fDigitsQAList[AliRecoParam::AConvert(fEventSpecie)]->GetEntries(),AliRecoParam::AConvert(fEventSpecie));
229
230     fSDDDataMaker->InitDigits();
231   }
232   if(fSubDetector == 0 || fSubDetector == 3) {
233     AliDebug(AliQAv1::GetQADebugLevel(),"AliITSQADM:: SSD InitDigits\n");
234     fSSDDataMaker->SetOffset(AliQAv1::kDIGITSR, fDigitsQAList[AliRecoParam::AConvert(fEventSpecie)]->GetEntries(),AliRecoParam::AConvert(fEventSpecie));
235
236     fSSDDataMaker->InitDigits();
237   }
238 }
239
240 //____________________________________________________________________________ 
241 void AliITSQADataMakerRec::MakeDigits(TTree * digitsTree)
242 {
243
244   
245   // Fill QA for recpoints
246   if(fSubDetector == 0 || fSubDetector == 1) {
247     fSPDDataMaker->MakeDigits(digitsTree) ; 
248   }
249   
250   if(fSubDetector == 0 || fSubDetector == 2) {
251     fSDDDataMaker->MakeDigits(digitsTree) ; 
252     
253   }
254   
255   if(fSubDetector == 0 || fSubDetector == 3) fSSDDataMaker->MakeDigits(digitsTree);
256 }
257
258 //____________________________________________________________________________ 
259 void AliITSQADataMakerRec::InitRecPoints()
260 {
261
262   // Initialization for RECPOINTS
263
264
265   //if(fRecPointsQAList[AliRecoParam::AConvert(fEventSpecie)]->GetEntries()) return;
266         if(fSubDetector == 0 || fSubDetector == 1) {
267                 AliDebug(AliQAv1::GetQADebugLevel(),"AliITSQADM:: SPD InitRecPoints\n");
268                 fSPDDataMaker->InitRecPoints();
269         }
270         if(fSubDetector == 0 || fSubDetector == 2) {
271                 AliDebug(AliQAv1::GetQADebugLevel(),"AliITSQADM:: SDD InitRecPoints\n");
272                 fSDDDataMaker->SetOffset(AliQAv1::kRECPOINTS, fRecPointsQAList[AliRecoParam::AConvert(fEventSpecie)]->GetEntries(), AliRecoParam::AConvert(fEventSpecie));
273                 fSDDDataMaker->InitRecPoints();
274         }
275         if(fSubDetector == 0 || fSubDetector == 3) {
276                 AliDebug(AliQAv1::GetQADebugLevel(),"AliITSQADM:: SSD InitRecPoints\n");
277                 fSSDDataMaker->SetOffset(AliQAv1::kRECPOINTS, fRecPointsQAList[AliRecoParam::AConvert(fEventSpecie)]->GetEntries(),AliRecoParam::AConvert(fEventSpecie));
278                 fSSDDataMaker->InitRecPoints();
279         }
280
281
282         if(fSubDetector == 0){
283           Int_t offset = fRecPointsQAList [AliRecoParam::AConvert(fEventSpecie)]->GetEntries();
284           const Bool_t expert   = kTRUE ; 
285           const Bool_t image    = kTRUE ; 
286           Char_t name[50];
287           Char_t title[50];
288           TH2F**hPhiEta = new TH2F*[6];
289           for (Int_t iLay=0;iLay<6;iLay++) {
290             sprintf(name,"Phi_vs_Eta_ITS_Layer%d",iLay+1);
291             sprintf(title,"Phi vs Eta - ITS Layer %d",iLay+1);
292             hPhiEta[iLay]=new TH2F(name,title,30,-1.5,1.5,200,0.,2*TMath::Pi());
293             hPhiEta[iLay]->GetXaxis()->SetTitle("Pseudorapidity");
294             hPhiEta[iLay]->GetYaxis()->SetTitle("#varphi [rad]");
295             Add2RecPointsList((new TH2F(*hPhiEta[iLay])), iLay + offset, !expert, image);
296             
297             delete hPhiEta[iLay];
298           }
299           
300         }
301         
302 }
303
304 //____________________________________________________________________________ 
305 void AliITSQADataMakerRec::MakeRecPoints(TTree * clustersTree)
306 {
307  
308   // Fill QA for recpoints
309   if(fSubDetector == 0 || fSubDetector == 1) {
310     fSPDDataMaker->MakeRecPoints(clustersTree) ; 
311   }
312     
313   if(fSubDetector == 0 || fSubDetector == 2) {
314     fSDDDataMaker->MakeRecPoints(clustersTree) ; 
315   }
316   
317   if(fSubDetector == 0 || fSubDetector == 3) fSSDDataMaker->MakeRecPoints(clustersTree);
318
319
320
321   if(fSubDetector == 0){
322     // Check id histograms already created for this Event Specie
323     TBranch *branchRecP = clustersTree->GetBranch("ITSRecPoints");
324     if (!branchRecP) {
325       AliError("can't get the branch with the ITS clusters !");
326       return;
327     }
328     
329     Int_t offset = fRecPointsQAList [AliRecoParam::AConvert(fEventSpecie)]->GetEntries();
330     Float_t cluGlo[3] = {0.,0.,0.};
331     Int_t lay, lad, det; 
332     static TClonesArray statRecpoints("AliITSRecPoint") ;
333     TClonesArray *recpoints = &statRecpoints;
334     branchRecP->SetAddress(&recpoints);
335     // Fill QA for recpoints
336     for(Int_t module=0; module<clustersTree->GetEntries();module++){
337       //  AliInfo(Form("Module %d\n",module));
338       branchRecP->GetEvent(module);
339       AliITSgeomTGeo::GetModuleId(module, lay, lad, det);
340       for(Int_t j=0;j<recpoints->GetEntries();j++){
341         AliITSRecPoint *rcp = (AliITSRecPoint*)recpoints->At(j);    
342         //Check id histograms already created for this Event Specie
343         rcp->GetGlobalXYZ(cluGlo);
344         Double_t rad=TMath::Sqrt(cluGlo[0]*cluGlo[0]+cluGlo[1]*cluGlo[1]+cluGlo[2]*cluGlo[2]);
345         Double_t phi= TMath::Pi() + TMath::ATan2(-cluGlo[1],-cluGlo[0]);
346         Double_t theta = TMath::ACos(cluGlo[2]/rad);
347         Double_t eta = 100.;
348         if(AreEqual(rad,0.) == kFALSE) {
349           if(theta<=1.e-14){ eta=30.; }
350           else { eta = -TMath::Log(TMath::Tan(theta/2.));}
351         }
352         //      printf("=========================>hlt   rcp->GetLayer() = %d \n",rcp->GetLayer());
353         (GetRecPointsData( rcp->GetLayer() + offset - 6))->Fill(eta,phi);
354       }
355     }
356   }
357   
358 }
359
360 //____________________________________________________________________________ 
361 void AliITSQADataMakerRec::FillRecPoint(AliITSRecPoint rcp)
362 {
363
364         // Fill QA for recpoints
365         Float_t cluGlo[3] = {0.,0.,0.};
366         Int_t offset = fRecPointsQAList [AliRecoParam::AConvert(fEventSpecie)]->GetEntries();
367   // Check id histograms already created for this Event Specie
368         rcp.GetGlobalXYZ(cluGlo);
369         Double_t rad=TMath::Sqrt(cluGlo[0]*cluGlo[0]+cluGlo[1]*cluGlo[1]+cluGlo[2]*cluGlo[2]);
370         Double_t phi= TMath::Pi() + TMath::ATan2(-cluGlo[1],-cluGlo[0]);
371         Double_t theta = TMath::ACos(cluGlo[2]/rad);
372         Double_t eta = 100.;
373         if(AreEqual(rad,0.)==kFALSE) {
374           if(theta<=1.e-14){eta=30.;}
375           else    {eta = -TMath::Log(TMath::Tan(theta/2.));}
376         }
377         (GetRecPointsData( rcp.GetLayer() + offset - 6))->Fill(eta,phi);        
378
379 }
380
381 //____________________________________________________________________________ 
382 TH2F *AliITSQADataMakerRec::GetITSGlobalHisto(Int_t layer)
383 {
384
385         Int_t offset = fRecPointsQAList [AliRecoParam::AConvert(fEventSpecie)]->GetEntries();
386         return ((TH2F *) GetRecPointsData( layer + offset - 6));//local distribution
387 }
388
389 //____________________________________________________________________________ 
390 void AliITSQADataMakerRec::InitESDs()
391 {
392
393   // Create ESDs histograms in ESDs subdir
394
395   Bool_t expertHistogram = kTRUE;
396
397   TH1F *hESDClustersMI = 
398     new TH1F("hESDClustersMI", "N ITS clusters per track (MI); N clusters; Counts",
399              7, -0.5, 6.5);
400   hESDClustersMI->Sumw2();
401   hESDClustersMI->SetMinimum(0);
402   Add2ESDsList(hESDClustersMI, 0);
403
404   TH1F *hESDClusterMapMI =
405     new TH1F("hESDClusterMapMI", "N tracks with point Layer (MI); Layer; N tracks",
406              6, -0.5, 5.5);
407   hESDClusterMapMI->Sumw2();
408   hESDClusterMapMI->SetMinimum(0);
409   Add2ESDsList(hESDClusterMapMI, 1, expertHistogram);
410
411   TH1F *hESDClustersSA = 
412     new TH1F("hESDClustersSA", "N ITS clusters per track (SA); N clusters; Counts",
413              7, -0.5, 6.5);
414   hESDClustersSA->Sumw2();
415   hESDClustersSA->SetMinimum(0);
416   Add2ESDsList(hESDClustersSA, 2);
417
418   TH1F *hESDClusterMapSA =
419     new TH1F("hESDClusterMapSA", "N tracks with point Layer (SA); Layer; N tracks",
420              6, -0.5, 5.5);
421   hESDClusterMapSA->Sumw2();
422   hESDClusterMapSA->SetMinimum(0);
423   Add2ESDsList(hESDClusterMapSA, 3, expertHistogram);
424
425   TH1F *hSPDVertexX = 
426     new TH1F("hSPDVertexX","SPD Vertex x; x [cm]; N events",
427              10000,-2,2);
428   hSPDVertexX->Sumw2();
429   Add2ESDsList(hSPDVertexX, 4);
430
431   TH1F *hSPDVertexY = 
432     new TH1F("hSPDVertexY","SPD Vertex y; y [cm]; N events",
433              10000,-2,2);
434   hSPDVertexY->Sumw2();
435   Add2ESDsList(hSPDVertexY, 5);
436
437   TH1F *hSPDVertexZ = 
438     new TH1F("hSPDVertexZ","SPD Vertex Z; z [cm]; N events",
439              10000,-20,20);
440   hSPDVertexZ->Sumw2();
441   Add2ESDsList(hSPDVertexZ, 6);
442
443   TH1F *hSPDVertexContrOverMult =
444     new TH1F("hSPDVertexContrOverMult","SPD Vertex: contributors / multiplicity; N contributors / SPD multiplicity; N events",
445              100,-4,20);
446   hSPDVertexContrOverMult->Sumw2();
447   Add2ESDsList(hSPDVertexContrOverMult, 7, expertHistogram);
448
449   TH1F *hTrkVertexX = 
450     new TH1F("hTrkVertexX","ITS+TPC Trk Vertex x; x [cm]; N events",
451              10000,-2,2);
452   hTrkVertexX->Sumw2();
453   Add2ESDsList(hTrkVertexX, 8, expertHistogram);
454
455   TH1F *hTrkVertexY = 
456     new TH1F("hTrkVertexY","ITS+TPC Trk Vertex y; y [cm]; N events",
457              10000,-2,2);
458   hTrkVertexY->Sumw2();
459   Add2ESDsList(hTrkVertexY, 9, expertHistogram);
460
461   TH1F *hTrkVertexZ = 
462     new TH1F("hTrkVertexZ","ITS+TPC Trk Vertex Z; z [cm]; N events",
463              10000,-20,20);
464   hTrkVertexZ->Sumw2();
465   Add2ESDsList(hTrkVertexZ, 10, expertHistogram);
466
467   TH1F *hTrkVertexContrOverITSrefit5 =
468     new TH1F("hTrkVertexContrOverITSrefit5","ITS+TPC Trk Vertex: contributors / tracks; N contributors / N trks kITSrefit with 5 or 6 clusters; N events",
469              100,-4,2);
470   hTrkVertexContrOverITSrefit5->Sumw2();
471   Add2ESDsList(hTrkVertexContrOverITSrefit5, 11, expertHistogram);
472
473   TH1F *hSPDTrkVertexDeltaX =
474     new TH1F("hSPDTrkVertexDeltaX","Comparison of SPD and Trk vertices: x; xSPD-xTrk [cm]; N events",
475              1000,-1,1);
476   hSPDTrkVertexDeltaX->Sumw2();
477   Add2ESDsList(hSPDTrkVertexDeltaX, 12, expertHistogram);
478     
479   TH1F *hSPDTrkVertexDeltaY =
480     new TH1F("hSPDTrkVertexDeltaY","Comparison of SPD and Trk vertices: y; ySPD-yTrk [cm]; N events",
481              1000,-1,1);
482   hSPDTrkVertexDeltaY->Sumw2();
483   Add2ESDsList(hSPDTrkVertexDeltaY, 13, expertHistogram);
484     
485   TH1F *hSPDTrkVertexDeltaZ =
486     new TH1F("hSPDTrkVertexDeltaZ","Comparison of SPD and Trk vertices: z; zSPD-zTrk [cm]; N events",
487              1000,-1,1);
488   hSPDTrkVertexDeltaZ->Sumw2();
489   Add2ESDsList(hSPDTrkVertexDeltaZ, 14);
490     
491   // SPD Tracklets
492
493   TH1F* hSPDTracklets = 
494     new TH1F("hSPDTracklets","N SPD Tracklets; N tracklets; Counts",300,0.,300.);
495   hSPDTracklets->Sumw2();
496   Add2ESDsList(hSPDTracklets, 15); 
497
498   TH2F* hSPDTrackletsvsFiredChips0 = 
499     new TH2F("hSPDTrackletsvsFiredChips0","N SPD Tracklets vs N FiredChips Layer0",
500               300,0.,300.,300,0.,300.);
501   hSPDTrackletsvsFiredChips0->GetXaxis()->SetTitle("N FiredChips Layer0"); 
502   hSPDTrackletsvsFiredChips0->GetYaxis()->SetTitle("N SPD Tracklets"); 
503   hSPDTrackletsvsFiredChips0->Sumw2();
504   Add2ESDsList(hSPDTrackletsvsFiredChips0, 16, expertHistogram ); 
505
506   TH2F* hSPDTrackletsvsFiredChips1 = 
507     new TH2F("hSPDTrackletsvsFiredChips1","N SPD Tracklets vs N FiredChips Layer1",
508               300,0.,300.,300,0.,300.);
509   hSPDTrackletsvsFiredChips1->GetXaxis()->SetTitle("N FiredChips Layer1"); 
510   hSPDTrackletsvsFiredChips1->GetYaxis()->SetTitle("N SPD Tracklets"); 
511   hSPDTrackletsvsFiredChips1->Sumw2();
512   Add2ESDsList(hSPDTrackletsvsFiredChips1, 17, expertHistogram); 
513
514   TH2F* hSPDFiredChips1vsFiredChips0 = 
515     new TH2F("hSPDFiredChips1vsFiredChips0","N FiredChips Layer1 vs N FiredChips Layer0",
516               300,0.,300.,300,0.,300.);
517   hSPDFiredChips1vsFiredChips0->GetXaxis()->SetTitle("N FiredChips Layer0"); 
518   hSPDFiredChips1vsFiredChips0->GetYaxis()->SetTitle("N FiredChips Layer1"); 
519   hSPDFiredChips1vsFiredChips0->Sumw2();
520   Add2ESDsList(hSPDFiredChips1vsFiredChips0, 18, expertHistogram ); 
521     
522   TH1F* hSPDTrackletsDePhi = 
523     new TH1F("hSPDTrackletsDePhi","DeltaPhi SPD Tracklets; DeltaPhi [rad]; N events",200,-0.2,0.2);
524   hSPDTrackletsDePhi->Sumw2();
525   Add2ESDsList(hSPDTrackletsDePhi, 19); 
526     
527   TH1F* hSPDTrackletsPhi = 
528     new TH1F("hSPDTrackletsPhi","Phi SPD Tracklets; Phi [rad]; N events",1000,0.,2*TMath::Pi());
529   hSPDTrackletsPhi->Sumw2();
530   Add2ESDsList(hSPDTrackletsPhi, 20); 
531     
532   TH1F* hSPDTrackletsDeTheta = 
533     new TH1F("hSPDTrackletsDeTheta","DeltaTheta SPD Tracklets; DeltaTheta [rad]; N events",200,-0.2,0.2);
534   hSPDTrackletsDeTheta->Sumw2();
535   Add2ESDsList(hSPDTrackletsDeTheta, 21); 
536
537   TH1F* hSPDTrackletsTheta = 
538     new TH1F("hSPDTrackletsTheta","Theta SPD Tracklets; Theta [rad]; N events",500,0.,TMath::Pi());
539   hSPDTrackletsTheta->Sumw2();
540   Add2ESDsList(hSPDTrackletsTheta, 22); 
541
542   // map of layers skipped by tracking (set in AliITSRecoParam)
543   TH1F *hESDSkippedLayers = 
544     new TH1F("hESDSkippedLayers", "Map of layers skipped by tracking; Layer; Skipped",
545              6, -0.5, 5.5);
546   hESDSkippedLayers->Sumw2();
547   hESDSkippedLayers->SetMinimum(0);
548   Add2ESDsList(hESDSkippedLayers, 23, expertHistogram);
549
550
551   return;
552 }
553
554 //____________________________________________________________________________
555 void AliITSQADataMakerRec::MakeESDs(AliESDEvent *esd)
556 {
557   // Make QA data from ESDs
558
559   // Check id histograms already created for this Event Specie
560 //  if ( ! GetESDsData(0) )
561 //    InitESDs() ;
562   
563   const Int_t nESDTracks = esd->GetNumberOfTracks();
564   Int_t nITSrefit5 = 0; 
565
566   Int_t idet,status;
567   Float_t xloc,zloc;
568
569   // loop on tracks
570   for(Int_t i = 0; i < nESDTracks; i++) {
571     
572     AliESDtrack *track = esd->GetTrack(i);
573     
574     Int_t nclsITS = track->GetNcls(0);
575
576     Bool_t itsrefit=kFALSE,tpcin=kFALSE,itsin=kFALSE;
577     if ((track->GetStatus() & AliESDtrack::kITSrefit)) itsrefit=kTRUE;
578     if ((track->GetStatus() & AliESDtrack::kTPCin)) tpcin=kTRUE;     
579     if ((track->GetStatus() & AliESDtrack::kITSin)) itsin=kTRUE;     
580     if(nclsITS>=5 && itsrefit) nITSrefit5++;
581
582     if(tpcin) {
583       GetESDsData(0)->Fill(nclsITS);
584     }
585     if(itsin && !tpcin){
586       GetESDsData(2)->Fill(nclsITS);
587     }
588
589     for(Int_t layer=0; layer<6; layer++) {
590
591       if(TESTBIT(track->GetITSClusterMap(),layer)) {
592         if(tpcin) {
593           GetESDsData(1)->Fill(layer);
594         } else {
595           GetESDsData(3)->Fill(layer);
596         }
597       }
598       track->GetITSModuleIndexInfo(layer,idet,status,xloc,zloc);
599       if(status==3) GetESDsData(23)->SetBinContent(layer,1);
600     }     
601
602   } // end loop on tracks
603
604   // vertices
605   const AliESDVertex *vtxSPD = esd->GetPrimaryVertexSPD();
606   const AliESDVertex *vtxTrk = esd->GetPrimaryVertexTracks();
607
608   Int_t mult = ((AliMultiplicity*)(esd->GetMultiplicity()))->GetNumberOfTracklets();
609   if(mult>0)
610     GetESDsData(7)->Fill((Float_t)(vtxSPD->GetNContributors())/(Float_t)mult);
611
612   if(nITSrefit5>0)
613     GetESDsData(11)->Fill((Float_t)(vtxTrk->GetNIndices())/(Float_t)nITSrefit5);
614
615   if(vtxSPD->GetNContributors()>0) {
616     GetESDsData(4)->Fill(vtxSPD->GetXv());
617     GetESDsData(5)->Fill(vtxSPD->GetYv());
618     GetESDsData(6)->Fill(vtxSPD->GetZv());
619   }
620
621   if(vtxTrk->GetNContributors()>0) {
622     GetESDsData(8)->Fill(vtxTrk->GetXv());
623     GetESDsData(9)->Fill(vtxTrk->GetYv());
624     GetESDsData(10)->Fill(vtxTrk->GetZv());
625   }
626
627   if(vtxSPD->GetNContributors()>0 && 
628      vtxTrk->GetNContributors()>0) {
629     GetESDsData(12)->Fill(vtxSPD->GetXv()-vtxTrk->GetXv());
630     GetESDsData(13)->Fill(vtxSPD->GetYv()-vtxTrk->GetYv());
631     GetESDsData(14)->Fill(vtxSPD->GetZv()-vtxTrk->GetZv());
632   }
633
634   // SPD Tracklets
635   GetESDsData(15)->Fill(mult);
636
637   Short_t nFiredChips0 = ((AliMultiplicity*)(esd->GetMultiplicity()))->GetNumberOfFiredChips(0);
638   Short_t nFiredChips1 = ((AliMultiplicity*)(esd->GetMultiplicity()))->GetNumberOfFiredChips(1);
639   GetESDsData(16)->Fill(nFiredChips0,mult);
640   GetESDsData(17)->Fill(nFiredChips1,mult);
641   GetESDsData(18)->Fill(nFiredChips0,nFiredChips1);
642
643   // Loop over tracklets
644   for (Int_t itr=0; itr<mult; ++itr) {
645     Float_t dePhiTr   = ((AliMultiplicity*)(esd->GetMultiplicity()))->GetDeltaPhi(itr);
646     Float_t deThetaTr = ((AliMultiplicity*)(esd->GetMultiplicity()))->GetDeltaTheta(itr);
647     Float_t phiTr   = ((AliMultiplicity*)(esd->GetMultiplicity()))->GetPhi(itr);
648     Float_t thetaTr = ((AliMultiplicity*)(esd->GetMultiplicity()))->GetTheta(itr);
649     GetESDsData(19)->Fill(dePhiTr);
650     GetESDsData(20)->Fill(phiTr);
651     GetESDsData(21)->Fill(deThetaTr);
652     GetESDsData(22)->Fill(thetaTr);
653   } // end loop on tracklets
654
655   return;
656 }
657
658 //_________________________________________________________________
659 Int_t AliITSQADataMakerRec::GetDetTaskOffset(Int_t subdet,AliQAv1::TASKINDEX_t task)
660 {
661   switch(subdet)
662     {
663
664       Int_t offset;
665     case 1:
666       offset=fSPDDataMaker->GetOffset(task);
667       return offset;
668       break;
669     case 2:
670       offset=fSDDDataMaker->GetOffset(task);
671       return offset;
672       break;
673     case 3:
674       offset=fSSDDataMaker->GetOffset(task);
675       return offset;
676       break;
677     default:
678       AliWarning("No specific subdetector (SPD, SDD, SSD) selected!! Offset set to zero \n");
679       offset=0;
680       return offset;
681       break;
682     }
683   //return offset;
684 }
685
686 //____________________________________________________________________
687
688 Bool_t AliITSQADataMakerRec::AreEqual(Double_t a1,Double_t a2)
689 {
690   const Double_t kEpsilon= 1.e-14;
691   return TMath::Abs(a1-a2)<=kEpsilon*TMath::Abs(a1);      
692 }
693