Merge branch 'master' of https://git.cern.ch/reps/AliRoot
[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 "AliQAv1.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   fGenOffsetH=  new Int_t[AliRecoParam::kNSpecies];                       
61   fGenOffsetS=  new Int_t[AliRecoParam::kNSpecies];                           
62   fGenOffsetD=  new Int_t[AliRecoParam::kNSpecies];
63   for(Int_t i=0; i<AliRecoParam::kNSpecies; i++) {
64     fGenOffsetH[i]= 0;
65     fGenOffsetS[i]= 0;
66     fGenOffsetD[i]= 0;
67   }             
68 }
69
70 //____________________________________________________________________________ 
71 AliITSQASPDDataMakerSim::AliITSQASPDDataMakerSim(const AliITSQASPDDataMakerSim& qadm) :
72 TObject(),
73 fAliITSQADataMakerSim(qadm.fAliITSQADataMakerSim),
74 fSPDhHTask(qadm.fSPDhHTask),
75 fSPDhSTask(qadm.fSPDhSTask),
76 fSPDhDTask(qadm.fSPDhDTask),
77 fGenOffsetH(qadm.fGenOffsetH),
78 fGenOffsetS(qadm.fGenOffsetS),
79 fGenOffsetD(qadm.fGenOffsetD)
80 {
81   //copy ctor 
82   fAliITSQADataMakerSim->SetName((const char*)qadm.fAliITSQADataMakerSim->GetName()) ; 
83   fAliITSQADataMakerSim->SetTitle((const char*)qadm.fAliITSQADataMakerSim->GetTitle());
84
85 }
86
87 //__________________________________________________________________
88 AliITSQASPDDataMakerSim& AliITSQASPDDataMakerSim::operator = (const AliITSQASPDDataMakerSim& qac )
89 {
90   // Equal operator.
91   this->~AliITSQASPDDataMakerSim();
92   new(this) AliITSQASPDDataMakerSim(qac);
93   return *this;
94 }
95
96 //____________________________________________________________________________ 
97 void AliITSQASPDDataMakerSim::StartOfDetectorCycle()
98 {
99   //Detector specific actions at start of cycle
100   AliDebug(AliQAv1::GetQADebugLevel(),"AliITSQADM::Start of SPD Cycle\n");
101 }
102
103 //____________________________________________________________________________ 
104 void AliITSQASPDDataMakerSim::EndOfDetectorCycle(AliQAv1::TASKINDEX_t /*task*/, TObjArray** /*list*/)
105 {
106   // launch the QA checking
107   AliDebug(AliQAv1::GetQADebugLevel(),"AliITSDM instantiates checker with Run(AliQAv1::kITS, task, list)\n"); 
108   
109   //AliQAChecker::Instance()->Run( AliQAv1::kITS , task, list);
110 }
111
112 //____________________________________________________________________________ 
113 Int_t AliITSQASPDDataMakerSim::InitDigits()
114
115   // Initialization for DIGIT data - SPD -
116   const Bool_t expert   = kTRUE ; 
117   const Bool_t image    = kTRUE ;
118   Int_t rv = 0 ; 
119   //fGenOffsetD = (fAliITSQADataMakerSim->fDigitsQAList[AliRecoParam::kDefault])->GetEntries();
120   //fSPDhDTask must be incremented by one unit every time a histogram is ADDED to the QA List
121
122   Char_t name[51];
123   Char_t title[51];
124
125   TH1F *hlayer = new TH1F("SPDLayPattern_SPD","Layer map - SPD",6,0.,6.);
126   hlayer->GetXaxis()->SetTitle("Layer number");
127   hlayer->GetYaxis()->SetTitle("Entries");
128   rv = fAliITSQADataMakerSim->Add2DigitsList(hlayer,fGenOffsetD[fAliITSQADataMakerSim->GetEventSpecie()], expert, !image);
129   fSPDhDTask++;
130   
131   TH1F **hmod = new TH1F*[2];
132   for (Int_t iLay=0; iLay<2; iLay++) {
133     snprintf(name,50,"SPDModPattern_SPD%d",iLay+1);
134     snprintf(title,50,"Module map - SPD Layer %d",iLay+1);
135     hmod[iLay]=new TH1F(name,title,240,0,240);
136     hmod[iLay]->GetXaxis()->SetTitle("Module number");
137     hmod[iLay]->GetYaxis()->SetTitle("Entries");
138     rv = fAliITSQADataMakerSim->Add2DigitsList(hmod[iLay],1+iLay+fGenOffsetD[fAliITSQADataMakerSim->GetEventSpecie()], !expert, image);
139     fSPDhDTask++;
140   }
141   
142   TH1F *hcolumns = new TH1F("SPDColumns_SPD","Columns - SPD",160,0.,160.);
143   hcolumns->GetXaxis()->SetTitle("Column number");
144   hcolumns->GetYaxis()->SetTitle("Entries");
145   fAliITSQADataMakerSim->Add2DigitsList(hcolumns,3+fGenOffsetD[fAliITSQADataMakerSim->GetEventSpecie()], expert, !image);
146   fSPDhDTask++;
147
148   TH1F *hrows = new TH1F("SPDRows_SPD","Rows - SPD",256,0.,256.);
149   hrows->GetXaxis()->SetTitle("Row number");
150   hrows->GetYaxis()->SetTitle("Entries");
151   rv = fAliITSQADataMakerSim->Add2DigitsList(hrows,4+fGenOffsetD[fAliITSQADataMakerSim->GetEventSpecie()], expert, !image);
152   fSPDhDTask++;
153
154   TH1F** hMultSPDdigits = new TH1F*[2];
155   for (Int_t iLay=0; iLay<2; ++iLay) {
156     snprintf(name,50,"SPDDigitMultiplicity_SPD%d",iLay+1);
157     snprintf(title,50,"Digit multiplicity - SPD Layer %d",iLay+1);
158     hMultSPDdigits[iLay]=new TH1F(name,title,200,0.,200.);
159     hMultSPDdigits[iLay]->GetXaxis()->SetTitle("Digit multiplicity");
160     hMultSPDdigits[iLay]->GetYaxis()->SetTitle("Entries");
161     rv = fAliITSQADataMakerSim->Add2DigitsList(hMultSPDdigits[iLay], 5+iLay+fGenOffsetD[fAliITSQADataMakerSim->GetEventSpecie()], !expert, image);
162     fSPDhDTask++;
163   }
164
165   TH2F *hMultSPDdig2MultSPDdig1 
166        = new TH2F("SPDDigitMultCorrelation_SPD","Digit multiplicity correlation - SPD",200,0.,200.,200,0.,200.);
167   hMultSPDdig2MultSPDdig1->GetXaxis()->SetTitle("Digit multiplicity (Layer 1)");
168   hMultSPDdig2MultSPDdig1->GetYaxis()->SetTitle("Digit multiplicity (Layer 2)");
169   rv = fAliITSQADataMakerSim->Add2DigitsList(hMultSPDdig2MultSPDdig1,7+fGenOffsetD[fAliITSQADataMakerSim->GetEventSpecie()], !expert, image);
170   fSPDhDTask++;
171
172   AliDebug(AliQAv1::GetQADebugLevel(),Form("%d SPD Digits histograms booked\n",fSPDhDTask));
173   delete [] hmod;
174   delete [] hMultSPDdigits;
175   return rv ; 
176 }
177
178 //____________________________________________________________________________
179 Int_t AliITSQASPDDataMakerSim::MakeDigits(TTree *digits)
180
181   // Fill QA for DIGIT - SPD -
182   Int_t rv = 0 ; 
183  
184   AliITS *fITS  = (AliITS*)gAlice->GetModule("ITS");
185   fITS->SetTreeAddress();
186   TClonesArray *iITSdigits  = fITS->DigitsAddress(0);  // 0->SPD
187
188   Int_t nDigitsL1=0;
189   Int_t nDigitsL2=0;
190
191   for (Int_t imod=0; imod<240; ++imod){
192     digits->GetEvent(imod);
193     Int_t ndigits = iITSdigits->GetEntries();
194     if (imod<80) {
195       fAliITSQADataMakerSim->FillDigitsData(0+fGenOffsetD[fAliITSQADataMakerSim->GetEventSpecie()],0.5,ndigits);
196       fAliITSQADataMakerSim->FillDigitsData(1+fGenOffsetD[fAliITSQADataMakerSim->GetEventSpecie()],imod,ndigits);
197       nDigitsL1+=ndigits;
198     }
199     else {
200       fAliITSQADataMakerSim->FillDigitsData(0+fGenOffsetD[fAliITSQADataMakerSim->GetEventSpecie()],1,ndigits);
201       fAliITSQADataMakerSim->FillDigitsData(2+fGenOffsetD[fAliITSQADataMakerSim->GetEventSpecie()],imod,ndigits);
202       nDigitsL2+=ndigits;
203     }
204     for (Int_t idig=0; idig<ndigits; ++idig) {
205       AliITSdigit *dig=(AliITSdigit*)iITSdigits->UncheckedAt(idig);
206       Int_t col=dig->GetCoord1();  // cell number z
207       Int_t row=dig->GetCoord2();  // cell number x
208       fAliITSQADataMakerSim->FillDigitsData(3+fGenOffsetD[fAliITSQADataMakerSim->GetEventSpecie()],col);
209       fAliITSQADataMakerSim->FillDigitsData(4+fGenOffsetD[fAliITSQADataMakerSim->GetEventSpecie()],row);
210     }
211   }
212   fAliITSQADataMakerSim->FillDigitsData(5+fGenOffsetD[fAliITSQADataMakerSim->GetEventSpecie()],nDigitsL1);
213   fAliITSQADataMakerSim->FillDigitsData(6+fGenOffsetD[fAliITSQADataMakerSim->GetEventSpecie()],nDigitsL2);
214   fAliITSQADataMakerSim->FillDigitsData(7+fGenOffsetD[fAliITSQADataMakerSim->GetEventSpecie()],nDigitsL1,nDigitsL2);
215   //
216   return rv ; 
217 }
218
219 //____________________________________________________________________________ 
220 Int_t AliITSQASPDDataMakerSim::InitSDigits()
221
222   // Initialization for SDIGIT data - SPD -
223   const Bool_t expert   = kTRUE ; 
224   const Bool_t image    = kTRUE ;
225   Int_t rv = 0 ; 
226   //fGenOffsetS = (fAliITSQADataMakerSim->fSDigitsQAList[AliRecoParam::kDefault])->GetEntries();
227   //printf("--W-- AliITSQASPDDataMakerSim::InitSDigits()  fGenOffset= %d \n",fGenOffset);
228   //fSPDhSTask must be incremented by one unit every time a histogram is ADDED to the QA List
229   
230   Char_t name[51];
231   Char_t title[51];
232
233   TH1F *hlayer = new TH1F("SPDLayPattern_SPD","Layer map - SPD",6,0.,6.);
234   hlayer->GetXaxis()->SetTitle("Layer number");
235   hlayer->GetYaxis()->SetTitle("Entries");
236   rv = fAliITSQADataMakerSim->Add2SDigitsList(hlayer,fGenOffsetS[fAliITSQADataMakerSim->GetEventSpecie()], expert, !image);
237   fSPDhSTask++;
238
239   TH1F **hmod = new TH1F*[2];
240   for (Int_t iLay=0; iLay<2; ++iLay) {
241     snprintf(name,50,"SPDModPattern_SPD%d",iLay+1);
242     snprintf(title,50,"Module map - SPD Layer %d",iLay+1);
243     hmod[iLay]=new TH1F(name,title,240,0,240);
244     hmod[iLay]->GetXaxis()->SetTitle("Module number");
245     hmod[iLay]->GetYaxis()->SetTitle("Entries");
246     rv = fAliITSQADataMakerSim->Add2SDigitsList(hmod[iLay],1+iLay+fGenOffsetS[fAliITSQADataMakerSim->GetEventSpecie()], !expert, image);
247     fSPDhSTask++;
248   }
249
250   AliDebug(AliQAv1::GetQADebugLevel(),Form("%d SPD SDigits histograms booked\n",fSPDhSTask));
251   delete [] hmod;
252   return rv ; 
253 }
254
255 //____________________________________________________________________________
256 Int_t AliITSQASPDDataMakerSim::MakeSDigits(TTree *sdigits)
257
258   // Fill QA for SDIGIT - SPD -
259   Int_t rv = 0 ; 
260   static TClonesArray * sdig ; 
261   if (! sdig )
262     sdig = new TClonesArray( "AliITSpListItem",1000 );
263   
264   TBranch *brchSDigits = sdigits->GetBranch("ITS");
265   for (Int_t imod=0; imod<240; ++imod){
266     brchSDigits->SetAddress( &sdig );
267     brchSDigits->GetEvent(imod);
268     Int_t nsdig=sdig->GetEntries();
269     if (imod<80) {
270       fAliITSQADataMakerSim->FillSDigitsData(0+fGenOffsetS[fAliITSQADataMakerSim->GetEventSpecie()],0.5,nsdig);
271       fAliITSQADataMakerSim->FillSDigitsData(1+fGenOffsetS[fAliITSQADataMakerSim->GetEventSpecie()],imod,nsdig);
272     }
273     else {
274       fAliITSQADataMakerSim->FillSDigitsData(0+fGenOffsetS[fAliITSQADataMakerSim->GetEventSpecie()],1,nsdig);
275       fAliITSQADataMakerSim->FillSDigitsData(2+fGenOffsetS[fAliITSQADataMakerSim->GetEventSpecie()],imod,nsdig);
276     }
277     sdig->Clear() ;
278   }
279   //
280   return rv ; 
281 }
282
283 //____________________________________________________________________________ 
284 Int_t AliITSQASPDDataMakerSim::InitHits()
285
286   // Initialization for HITS data - SPD -
287   const Bool_t expert   = kTRUE ; 
288   const Bool_t image    = kTRUE ;
289   Int_t rv = 0 ; 
290   
291   //fGenOffsetH = (fAliITSQADataMakerSim->fHitsQAList[AliRecoParam::kDefault])->GetEntries();
292   //printf("--W-- AliITSQASPDDataMakerSim::InitHits()  fGenOffset= %d \n",fGenOffset);
293   //fSPDhHTask must be incremented by one unit every time a histogram is ADDED to the QA List
294   Char_t name[50];
295   Char_t title[50];
296
297   TH1F *hlayer = new TH1F("SPDLayPattern_SPD","Layer map - SPD",6,0.,6.);
298   hlayer->GetXaxis()->SetTitle("Layer number");
299   hlayer->GetYaxis()->SetTitle("Entries");
300   rv = fAliITSQADataMakerSim->Add2HitsList(hlayer,fGenOffsetH[fAliITSQADataMakerSim->GetEventSpecie()], expert, !image);
301   fSPDhHTask++;
302
303   TH1F **hmod = new TH1F*[2];
304   for (Int_t iLay=0; iLay<2; ++iLay) {
305     snprintf(name,49,"SPDModPattern_SPD%d",iLay+1);
306     snprintf(title,49,"Module map - SPD Layer %d",iLay+1);
307     hmod[iLay]=new TH1F(name,title,240,0,240);
308     hmod[iLay]->GetXaxis()->SetTitle("Module number");
309     hmod[iLay]->GetYaxis()->SetTitle("Entries");
310     rv = fAliITSQADataMakerSim->Add2HitsList(hmod[iLay],1+iLay+fGenOffsetH[fAliITSQADataMakerSim->GetEventSpecie()], !expert, image);
311     fSPDhHTask++;
312   }
313
314   TH1F *hhitlenght = new TH1F("SPDLenght_SPD","SPD Hit lenght along y_{loc} coord",210,0.,210.);
315   hhitlenght->GetXaxis()->SetTitle("Hit lenght [#mum]");
316   hhitlenght->GetYaxis()->SetTitle("# hits");
317   rv = fAliITSQADataMakerSim->Add2HitsList(hhitlenght,3+fGenOffsetH[fAliITSQADataMakerSim->GetEventSpecie()], !expert, image);
318   fSPDhHTask++;
319
320   TH1F *hEdepos = new TH1F("SPDEnergyDeposit_SPD","SPD Deposited energy distribution (y_{loc}>180 #mum)",150,0.,300.); 
321   hEdepos->GetXaxis()->SetTitle("Deposited energy [keV]"); 
322   hEdepos->GetYaxis()->SetTitle("# hits");
323   rv = fAliITSQADataMakerSim->Add2HitsList(hEdepos,4+fGenOffsetH[fAliITSQADataMakerSim->GetEventSpecie()], !expert, image);
324   fSPDhHTask++;
325
326   AliDebug(AliQAv1::GetQADebugLevel(),Form("%d SPD Hits histograms booked\n",fSPDhHTask));
327   delete [] hmod;
328   return rv ; 
329 }
330
331 //____________________________________________________________________________
332 Int_t AliITSQASPDDataMakerSim::MakeHits(TTree *hits)
333
334   // Fill QA for HITS - SPD -
335   Int_t rv = 0 ; 
336  
337   AliITS *fITS  = (AliITS*)gAlice->GetModule("ITS");
338   fITS->SetTreeAddress();
339   Int_t nmodules;
340   fITS->InitModules(-1,nmodules); //-1->number of modules taken from AliITSgeom class kept in fITSgeom
341                                   //nmodules is set
342
343   fITS->FillModules(hits,0);
344
345   for (Int_t imod=0; imod<240; ++imod){
346     AliITSmodule *module = fITS->GetModule(imod);
347     TObjArray *arrHits = module->GetHits();
348     Int_t nhits = arrHits->GetEntriesFast();
349     if (imod<80) {
350       fAliITSQADataMakerSim->FillHitsData(fGenOffsetH[fAliITSQADataMakerSim->GetEventSpecie()],0.5,nhits);
351       fAliITSQADataMakerSim->FillHitsData(1+fGenOffsetH[fAliITSQADataMakerSim->GetEventSpecie()],imod,nhits);
352     } else {
353       fAliITSQADataMakerSim->FillHitsData(fGenOffsetH[fAliITSQADataMakerSim->GetEventSpecie()],1,nhits);
354       fAliITSQADataMakerSim->FillHitsData(2+fGenOffsetH[fAliITSQADataMakerSim->GetEventSpecie()],imod,nhits);
355     }
356     for (Int_t iHit=0; iHit<nhits; ++iHit) {
357       AliITShit *hit = (AliITShit*) arrHits->At(iHit);
358       Double_t xl,yl,zl,xl0,yl0,zl0;
359       Double_t tof,tof0;
360       hit->GetPositionL(xl,yl,zl,tof);
361       hit->GetPositionL0(xl0,yl0,zl0,tof0);
362       Float_t dyloc=TMath::Abs(yl-yl0)*10000.;
363       fAliITSQADataMakerSim->FillHitsData(3+fGenOffsetH[fAliITSQADataMakerSim->GetEventSpecie()],dyloc);
364       Float_t edep=hit->GetIonization()*1000000;
365       if(dyloc>180.){
366         fAliITSQADataMakerSim->FillHitsData(4+fGenOffsetH[fAliITSQADataMakerSim->GetEventSpecie()],edep);
367       }
368     }
369   }
370   //
371   return rv ; 
372 }
373
374
375 //_______________________________________________________________
376
377 Int_t AliITSQASPDDataMakerSim::GetOffset(AliQAv1::TASKINDEX_t task,Int_t specie){
378   // Returns histogram offset according to the specified task
379   Int_t offset=0;
380   if( task == AliQAv1::kHITS){
381     offset=fGenOffsetH[specie];
382   }
383   else if( task == AliQAv1::kSDIGITS) {
384     offset=fGenOffsetS[specie];
385   }
386   else if( task == AliQAv1::kDIGITS) {
387     offset=fGenOffsetD[specie];
388   }
389   else {
390     AliInfo("No task has been selected. TaskHisto set to zero.\n");
391   }
392
393   return offset;
394 }
395
396 //____________________________________________________________________________ 
397 void AliITSQASPDDataMakerSim::SetOffset(AliQAv1::TASKINDEX_t task, Int_t offset,Int_t specie ){
398   // Returns histogram offset according to the specified task
399   if( task == AliQAv1::kHITS){
400     fGenOffsetH[specie] = offset;  
401   }
402   else if( task == AliQAv1::kSDIGITS) {
403     fGenOffsetS[specie] = offset;   
404   }
405   else if( task == AliQAv1::kDIGITS) {
406     fGenOffsetD[specie] = offset;   
407   }
408   else {
409     AliInfo("No task has been selected. TaskHisto set to zero.\n");
410   }
411 }
412
413 //_______________________________________________________________
414
415 Int_t AliITSQASPDDataMakerSim::GetTaskHisto(AliQAv1::TASKINDEX_t task) {
416   // Returns the number of booked histograms for the selected task
417   Int_t histotot=0;
418   if( task == AliQAv1::kHITS) {
419     histotot=fSPDhHTask ;
420   }
421   else if( task == AliQAv1::kSDIGITS) {
422     histotot=fSPDhSTask;
423   }
424   else if( task == AliQAv1::kDIGITS) {
425     histotot=fSPDhDTask ;
426   }
427   else {
428     AliInfo("No task has been selected. TaskHisto set to zero.\n");
429   }
430   return histotot;
431
432 }