Introducing event specie in QA (Yves)
[u/mrichter/AliRoot.git] / ITS / AliITSQASPDDataMakerSim.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 //  Checks the quality assurance 
19 //  by comparing with reference data
20 //  contained in a DB
21 //  -------------------------------------------------------------
22 //  W. Ferrarese + P. Cerello INFN Torino Feb 2008
23 //  M. Nicassio D. Elia INFN Bari April 2008
24 //  maria.nicassio@ba.infn.it
25
26 // --- ROOT system ---
27 #include <TTree.h>
28 #include <TH2.h>
29 #include <TH1.h>
30 // --- Standard library ---
31
32 // --- AliRoot header files ---
33 #include "AliRun.h"
34 #include "AliITSQADataMakerSim.h"
35 #include "AliITSQASPDDataMakerSim.h"
36 #include "AliQA.h"
37 #include "AliQAChecker.h"
38 #include "AliITSdigit.h"   
39 #include "AliITSdigitSPD.h"
40 #include "AliITS.h"
41 #include "AliITSmodule.h"
42 #include "AliITShit.h"
43 #include "AliITSLoader.h"
44 #include "AliRunLoader.h"
45
46 ClassImp(AliITSQASPDDataMakerSim)
47
48 //____________________________________________________________________________ 
49 AliITSQASPDDataMakerSim::AliITSQASPDDataMakerSim(AliITSQADataMakerSim *aliITSQADataMakerSim) :
50 TObject(),
51 fAliITSQADataMakerSim(aliITSQADataMakerSim),
52 fSPDhHTask(0),
53 fSPDhSTask(0),
54 fSPDhDTask(0),
55 fGenOffsetH(0),
56 fGenOffsetS(0),
57 fGenOffsetD(0)
58 {
59   //ctor used to discriminate OnLine-Offline analysis   
60 }
61
62 //____________________________________________________________________________ 
63 AliITSQASPDDataMakerSim::AliITSQASPDDataMakerSim(const AliITSQASPDDataMakerSim& qadm) :
64 TObject(),
65 fAliITSQADataMakerSim(qadm.fAliITSQADataMakerSim),
66 fSPDhHTask(qadm.fSPDhHTask),
67 fSPDhSTask(qadm.fSPDhSTask),
68 fSPDhDTask(qadm.fSPDhDTask),
69 fGenOffsetH(qadm.fGenOffsetH),
70 fGenOffsetS(qadm.fGenOffsetS),
71 fGenOffsetD(qadm.fGenOffsetD)
72 {
73   //copy ctor 
74   fAliITSQADataMakerSim->SetName((const char*)qadm.fAliITSQADataMakerSim->GetName()) ; 
75   fAliITSQADataMakerSim->SetTitle((const char*)qadm.fAliITSQADataMakerSim->GetTitle());
76   }
77
78 //__________________________________________________________________
79 AliITSQASPDDataMakerSim& AliITSQASPDDataMakerSim::operator = (const AliITSQASPDDataMakerSim& qac )
80 {
81   // Equal operator.
82   this->~AliITSQASPDDataMakerSim();
83   new(this) AliITSQASPDDataMakerSim(qac);
84   return *this;
85 }
86
87 //____________________________________________________________________________ 
88 void AliITSQASPDDataMakerSim::StartOfDetectorCycle()
89 {
90   //Detector specific actions at start of cycle
91   AliDebug(1,"AliITSQADM::Start of SPD Cycle\n");
92 }
93
94 //____________________________________________________________________________ 
95 void AliITSQASPDDataMakerSim::EndOfDetectorCycle(AliQA::TASKINDEX_t /*task*/, TObjArray* /*list*/)
96 {
97   // launch the QA checking
98   AliDebug(1,"AliITSDM instantiates checker with Run(AliQA::kITS, task, list)\n"); 
99   
100   //AliQAChecker::Instance()->Run( AliQA::kITS , task, list);
101 }
102
103 //____________________________________________________________________________ 
104 void AliITSQASPDDataMakerSim::InitDigits()
105
106   // Initialization for DIGIT data - SPD -
107   fGenOffsetD = (fAliITSQADataMakerSim->fDigitsQAList[AliRecoParam::kDefault])->GetEntries();
108   //fSPDhDTask must be incremented by one unit every time a histogram is ADDED to the QA List
109
110   Char_t name[50];
111   Char_t title[50];
112
113   TH1F *hlayer = new TH1F("SPDLayPattern_SPD","Layer map - SPD",6,0.,6.);
114   hlayer->GetXaxis()->SetTitle("Layer number");
115   hlayer->GetYaxis()->SetTitle("Entries");
116   fAliITSQADataMakerSim->Add2DigitsList(hlayer,fGenOffsetD,kTRUE);
117   fSPDhDTask++;
118   
119   TH1F **hmod = new TH1F*[2];
120   for (Int_t iLay=0; iLay<2; iLay++) {
121     sprintf(name,"SPDModPattern_SPD%d",iLay+1);
122     sprintf(title,"Module map - SPD Layer %d",iLay+1);
123     hmod[iLay]=new TH1F(name,title,240,0,240);
124     hmod[iLay]->GetXaxis()->SetTitle("Module number");
125     hmod[iLay]->GetYaxis()->SetTitle("Entries");
126     fAliITSQADataMakerSim->Add2DigitsList(hmod[iLay],1+iLay+fGenOffsetD);
127     fSPDhDTask++;
128   }
129   
130   TH1F *hcolumns = new TH1F("SPDColumns_SPD","Columns - SPD",160,0.,160.);
131   hcolumns->GetXaxis()->SetTitle("Column number");
132   hcolumns->GetYaxis()->SetTitle("Entries");
133   fAliITSQADataMakerSim->Add2DigitsList(hcolumns,3+fGenOffsetD,kTRUE);
134   fSPDhDTask++;
135
136   TH1F *hrows = new TH1F("SPDRows_SPD","Rows - SPD",256,0.,256.);
137   hrows->GetXaxis()->SetTitle("Row number");
138   hrows->GetYaxis()->SetTitle("Entries");
139   fAliITSQADataMakerSim->Add2DigitsList(hrows,4+fGenOffsetD,kTRUE);
140   fSPDhDTask++;
141
142   TH1F** hMultSPDdigits = new TH1F*[2];
143   for (Int_t iLay=0; iLay<2; ++iLay) {
144     sprintf(name,"SPDDigitMultiplicity_SPD%d",iLay+1);
145     sprintf(title,"Digit multiplicity - SPD Layer %d",iLay+1);
146     hMultSPDdigits[iLay]=new TH1F(name,title,200,0.,200.);
147     hMultSPDdigits[iLay]->GetXaxis()->SetTitle("Digit multiplicity");
148     hMultSPDdigits[iLay]->GetYaxis()->SetTitle("Entries");
149     fAliITSQADataMakerSim->Add2DigitsList(hMultSPDdigits[iLay], 5+iLay+fGenOffsetD);
150     fSPDhDTask++;
151   }
152
153   TH2F *hMultSPDdig2MultSPDdig1 
154        = new TH2F("SPDDigitMultCorrelation_SPD","Digit multiplicity correlation - SPD",200,0.,200.,200,0.,200.);
155   hMultSPDdig2MultSPDdig1->GetXaxis()->SetTitle("Digit multiplicity (Layer 1)");
156   hMultSPDdig2MultSPDdig1->GetYaxis()->SetTitle("Digit multiplicity (Layer 2)");
157   fAliITSQADataMakerSim->Add2DigitsList(hMultSPDdig2MultSPDdig1,7+fGenOffsetD);
158   fSPDhDTask++;
159
160   AliDebug(1,Form("%d SPD Digits histograms booked\n",fSPDhDTask));
161
162 }
163
164 //____________________________________________________________________________
165 void AliITSQASPDDataMakerSim::MakeDigits(TTree *digits)
166
167   // Fill QA for DIGIT - SPD -
168   AliITS *fITS  = (AliITS*)gAlice->GetModule("ITS");
169   fITS->SetTreeAddress();
170   TClonesArray *iITSdigits  = fITS->DigitsAddress(0);  // 0->SPD
171
172   Int_t nDigitsL1=0;
173   Int_t nDigitsL2=0;
174
175   for (Int_t imod=0; imod<240; ++imod){
176     digits->GetEvent(imod);
177     Int_t ndigits = iITSdigits->GetEntries();
178     if (imod<80) {
179       fAliITSQADataMakerSim->GetDigitsData(0+fGenOffsetD)->Fill(0.5,ndigits);
180       fAliITSQADataMakerSim->GetDigitsData(1+fGenOffsetD)->Fill(imod,ndigits);
181       nDigitsL1+=ndigits;
182     }
183     else {
184       fAliITSQADataMakerSim->GetDigitsData(0+fGenOffsetD)->Fill(1,ndigits);
185       fAliITSQADataMakerSim->GetDigitsData(2+fGenOffsetD)->Fill(imod,ndigits);
186       nDigitsL2+=ndigits;
187     }
188     for (Int_t idig=0; idig<ndigits; ++idig) {
189       AliITSdigit *dig=(AliITSdigit*)iITSdigits->UncheckedAt(idig);
190       Int_t col=dig->GetCoord1();  // cell number z
191       Int_t row=dig->GetCoord2();  // cell number x
192       fAliITSQADataMakerSim->GetDigitsData(3+fGenOffsetD)->Fill(col);
193       fAliITSQADataMakerSim->GetDigitsData(4+fGenOffsetD)->Fill(row);
194     }
195   }
196   fAliITSQADataMakerSim->GetDigitsData(5+fGenOffsetD)->Fill(nDigitsL1);
197   fAliITSQADataMakerSim->GetDigitsData(6+fGenOffsetD)->Fill(nDigitsL2);
198   fAliITSQADataMakerSim->GetDigitsData(7+fGenOffsetD)->Fill(nDigitsL1,nDigitsL2);
199 }
200
201 //____________________________________________________________________________ 
202 void AliITSQASPDDataMakerSim::InitSDigits()
203
204   // Initialization for SDIGIT data - SPD -
205   fGenOffsetS = (fAliITSQADataMakerSim->fSDigitsQAList[AliRecoParam::kDefault])->GetEntries();
206   //printf("--W-- AliITSQASPDDataMakerSim::InitSDigits()  fGenOffset= %d \n",fGenOffset);
207   //fSPDhSTask must be incremented by one unit every time a histogram is ADDED to the QA List
208   
209   Char_t name[50];
210   Char_t title[50];
211
212   TH1F *hlayer = new TH1F("SPDLayPattern_SPD","Layer map - SPD",6,0.,6.);
213   hlayer->GetXaxis()->SetTitle("Layer number");
214   hlayer->GetYaxis()->SetTitle("Entries");
215   fAliITSQADataMakerSim->Add2SDigitsList(hlayer,fGenOffsetS,kTRUE);
216   fSPDhSTask++;
217
218   TH1F **hmod = new TH1F*[2];
219   for (Int_t iLay=0; iLay<2; ++iLay) {
220     sprintf(name,"SPDModPattern_SPD%d",iLay+1);
221     sprintf(title,"Module map - SPD Layer %d",iLay+1);
222     hmod[iLay]=new TH1F(name,title,240,0,240);
223     hmod[iLay]->GetXaxis()->SetTitle("Module number");
224     hmod[iLay]->GetYaxis()->SetTitle("Entries");
225     fAliITSQADataMakerSim->Add2SDigitsList(hmod[iLay],1+iLay+fGenOffsetS);
226     fSPDhSTask++;
227   }
228
229   AliDebug(1,Form("%d SPD SDigits histograms booked\n",fSPDhSTask));
230
231 }
232
233 //____________________________________________________________________________
234 void AliITSQASPDDataMakerSim::MakeSDigits(TTree *sdigits)
235
236   // Fill QA for SDIGIT - SPD -
237   TBranch *brchSDigits = sdigits->GetBranch("ITS");
238   for (Int_t imod=0; imod<240; ++imod){
239     TClonesArray * sdig = new TClonesArray( "AliITSpListItem",1000 );
240     brchSDigits->SetAddress( &sdig );
241     brchSDigits->GetEvent(imod);
242     Int_t nsdig=sdig->GetEntries();
243     if (imod<80) {
244       fAliITSQADataMakerSim->GetSDigitsData(0+fGenOffsetS)->Fill(0.5,nsdig);
245       fAliITSQADataMakerSim->GetSDigitsData(1+fGenOffsetS)->Fill(imod,nsdig);
246     }
247     else {
248       fAliITSQADataMakerSim->GetSDigitsData(0+fGenOffsetS)->Fill(1,nsdig);
249       fAliITSQADataMakerSim->GetSDigitsData(2+fGenOffsetS)->Fill(imod,nsdig);
250     }
251     delete sdig;
252   }
253
254 }
255
256 //____________________________________________________________________________ 
257 void AliITSQASPDDataMakerSim::InitHits()
258
259   // Initialization for HITS data - SPD -
260   fGenOffsetH = (fAliITSQADataMakerSim->fHitsQAList[AliRecoParam::kDefault])->GetEntries();
261   //printf("--W-- AliITSQASPDDataMakerSim::InitHits()  fGenOffset= %d \n",fGenOffset);
262   //fSPDhHTask must be incremented by one unit every time a histogram is ADDED to the QA List
263   Char_t name[50];
264   Char_t title[50];
265
266   TH1F *hlayer = new TH1F("SPDLayPattern_SPD","Layer map - SPD",6,0.,6.);
267   hlayer->GetXaxis()->SetTitle("Layer number");
268   hlayer->GetYaxis()->SetTitle("Entries");
269   fAliITSQADataMakerSim->Add2HitsList(hlayer,fGenOffsetH,kTRUE);
270   fSPDhHTask++;
271
272   TH1F **hmod = new TH1F*[2];
273   for (Int_t iLay=0; iLay<2; ++iLay) {
274     sprintf(name,"SPDModPattern_SPD%d",iLay+1);
275     sprintf(title,"Module map - SPD Layer %d",iLay+1);
276     hmod[iLay]=new TH1F(name,title,240,0,240);
277     hmod[iLay]->GetXaxis()->SetTitle("Module number");
278     hmod[iLay]->GetYaxis()->SetTitle("Entries");
279     fAliITSQADataMakerSim->Add2HitsList(hmod[iLay],1+iLay+fGenOffsetH);
280     fSPDhHTask++;
281   }
282
283   TH1F *hhitlenght = new TH1F("SPDLenght_SPD","Hit lenght along y_{loc} coord",210,0.,210.);
284   hhitlenght->GetXaxis()->SetTitle("Hit lenght [#mum]");
285   hhitlenght->GetYaxis()->SetTitle("# hits");
286   fAliITSQADataMakerSim->Add2HitsList(hhitlenght,3+fGenOffsetH);
287   fSPDhHTask++;
288
289   TH1F *hEdepos = new TH1F("SPDEnergyDeposit_SPD","Deposited energy distribution (y_{loc}>180 #mum)",150,0.,300.); 
290   hEdepos->GetXaxis()->SetTitle("Deposited energy [keV]"); 
291   hEdepos->GetYaxis()->SetTitle("# hits");
292   fAliITSQADataMakerSim->Add2HitsList(hEdepos,4+fGenOffsetH);
293   fSPDhHTask++;
294
295   AliDebug(1,Form("%d SPD Hits histograms booked\n",fSPDhHTask));
296
297 }
298
299 //____________________________________________________________________________
300 void AliITSQASPDDataMakerSim::MakeHits(TTree *hits)
301
302   // Fill QA for HITS - SPD -
303   AliITS *fITS  = (AliITS*)gAlice->GetModule("ITS");
304   fITS->SetTreeAddress();
305   Int_t nmodules;
306   fITS->InitModules(-1,nmodules); //-1->number of modules taken from AliITSgeom class kept in fITSgeom
307                                   //nmodules is set
308
309   fITS->FillModules(hits,0);
310
311   for (Int_t imod=0; imod<240; ++imod){
312     AliITSmodule *module = fITS->GetModule(imod);
313     TObjArray *arrHits = module->GetHits();
314     Int_t nhits = arrHits->GetEntriesFast();
315     if (imod<80) {
316       fAliITSQADataMakerSim->GetHitsData(fGenOffsetH)->Fill(0.5,nhits);
317       fAliITSQADataMakerSim->GetHitsData(1+fGenOffsetH)->Fill(imod,nhits);
318     } else {
319       fAliITSQADataMakerSim->GetHitsData(fGenOffsetH)->Fill(1,nhits);
320       fAliITSQADataMakerSim->GetHitsData(2+fGenOffsetH)->Fill(imod,nhits);
321     }
322     for (Int_t iHit=0; iHit<nhits; ++iHit) {
323       AliITShit *hit = (AliITShit*) arrHits->At(iHit);
324       Double_t xl,yl,zl,xl0,yl0,zl0;
325       Double_t tof,tof0;
326       hit->GetPositionL(xl,yl,zl,tof);
327       hit->GetPositionL0(xl0,yl0,zl0,tof0);
328       Float_t dyloc=TMath::Abs(yl-yl0)*10000.;
329       fAliITSQADataMakerSim->GetHitsData(3+fGenOffsetH)->Fill(dyloc);
330       Float_t edep=hit->GetIonization()*1000000;
331       if(dyloc>180.){
332         fAliITSQADataMakerSim->GetHitsData(4+fGenOffsetH)->Fill(edep);
333       }
334     }
335   }
336 }
337
338
339 //_______________________________________________________________
340
341 Int_t AliITSQASPDDataMakerSim::GetOffset(AliQA::TASKINDEX_t task){
342   // Returns histogram offset according to the specified task
343   Int_t offset=0;
344   if( task == AliQA::kHITS){
345     offset=fGenOffsetH;
346   }
347   else if( task == AliQA::kSDIGITS) {
348     offset=fGenOffsetS;
349   }
350   else if( task == AliQA::kDIGITS) {
351     offset=fGenOffsetD;
352   }
353   else {
354     AliInfo("No task has been selected. TaskHisto set to zero.\n");
355   }
356
357   return offset;
358 }
359
360
361 //_______________________________________________________________
362
363 Int_t AliITSQASPDDataMakerSim::GetTaskHisto(AliQA::TASKINDEX_t task) {
364   // Returns the number of booked histograms for the selected task
365   Int_t histotot=0;
366   if( task == AliQA::kHITS) {
367     histotot=fSPDhHTask ;
368   }
369   else if( task == AliQA::kSDIGITS) {
370     histotot=fSPDhSTask;
371   }
372   else if( task == AliQA::kDIGITS) {
373     histotot=fSPDhDTask ;
374   }
375   else {
376     AliInfo("No task has been selected. TaskHisto set to zero.\n");
377   }
378   return histotot;
379
380 }