Fixes for Coverity warnings (M. van Leeuwen)
[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->GetDigitsData(0+fGenOffsetD[fAliITSQADataMakerSim->GetEventSpecie()])->Fill(0.5,ndigits);
196       fAliITSQADataMakerSim->GetDigitsData(1+fGenOffsetD[fAliITSQADataMakerSim->GetEventSpecie()])->Fill(imod,ndigits);
197       nDigitsL1+=ndigits;
198     }
199     else {
200       fAliITSQADataMakerSim->GetDigitsData(0+fGenOffsetD[fAliITSQADataMakerSim->GetEventSpecie()])->Fill(1,ndigits);
201       fAliITSQADataMakerSim->GetDigitsData(2+fGenOffsetD[fAliITSQADataMakerSim->GetEventSpecie()])->Fill(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->GetDigitsData(3+fGenOffsetD[fAliITSQADataMakerSim->GetEventSpecie()])->Fill(col);
209       fAliITSQADataMakerSim->GetDigitsData(4+fGenOffsetD[fAliITSQADataMakerSim->GetEventSpecie()])->Fill(row);
210     }
211   }
212   fAliITSQADataMakerSim->GetDigitsData(5+fGenOffsetD[fAliITSQADataMakerSim->GetEventSpecie()])->Fill(nDigitsL1);
213   fAliITSQADataMakerSim->GetDigitsData(6+fGenOffsetD[fAliITSQADataMakerSim->GetEventSpecie()])->Fill(nDigitsL2);
214   fAliITSQADataMakerSim->GetDigitsData(7+fGenOffsetD[fAliITSQADataMakerSim->GetEventSpecie()])->Fill(nDigitsL1,nDigitsL2);
215   return rv ; 
216 }
217
218 //____________________________________________________________________________ 
219 Int_t AliITSQASPDDataMakerSim::InitSDigits()
220
221   // Initialization for SDIGIT data - SPD -
222   const Bool_t expert   = kTRUE ; 
223   const Bool_t image    = kTRUE ;
224   Int_t rv = 0 ; 
225   //fGenOffsetS = (fAliITSQADataMakerSim->fSDigitsQAList[AliRecoParam::kDefault])->GetEntries();
226   //printf("--W-- AliITSQASPDDataMakerSim::InitSDigits()  fGenOffset= %d \n",fGenOffset);
227   //fSPDhSTask must be incremented by one unit every time a histogram is ADDED to the QA List
228   
229   Char_t name[51];
230   Char_t title[51];
231
232   TH1F *hlayer = new TH1F("SPDLayPattern_SPD","Layer map - SPD",6,0.,6.);
233   hlayer->GetXaxis()->SetTitle("Layer number");
234   hlayer->GetYaxis()->SetTitle("Entries");
235   rv = fAliITSQADataMakerSim->Add2SDigitsList(hlayer,fGenOffsetS[fAliITSQADataMakerSim->GetEventSpecie()], expert, !image);
236   fSPDhSTask++;
237
238   TH1F **hmod = new TH1F*[2];
239   for (Int_t iLay=0; iLay<2; ++iLay) {
240     snprintf(name,50,"SPDModPattern_SPD%d",iLay+1);
241     snprintf(title,50,"Module map - SPD Layer %d",iLay+1);
242     hmod[iLay]=new TH1F(name,title,240,0,240);
243     hmod[iLay]->GetXaxis()->SetTitle("Module number");
244     hmod[iLay]->GetYaxis()->SetTitle("Entries");
245     rv = fAliITSQADataMakerSim->Add2SDigitsList(hmod[iLay],1+iLay+fGenOffsetS[fAliITSQADataMakerSim->GetEventSpecie()], !expert, image);
246     fSPDhSTask++;
247   }
248
249   AliDebug(AliQAv1::GetQADebugLevel(),Form("%d SPD SDigits histograms booked\n",fSPDhSTask));
250   delete [] hmod;
251   return rv ; 
252 }
253
254 //____________________________________________________________________________
255 Int_t AliITSQASPDDataMakerSim::MakeSDigits(TTree *sdigits)
256
257   // Fill QA for SDIGIT - SPD -
258   Int_t rv = 0 ; 
259   
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->GetSDigitsData(0+fGenOffsetS[fAliITSQADataMakerSim->GetEventSpecie()])->Fill(0.5,nsdig);
271       fAliITSQADataMakerSim->GetSDigitsData(1+fGenOffsetS[fAliITSQADataMakerSim->GetEventSpecie()])->Fill(imod,nsdig);
272     }
273     else {
274       fAliITSQADataMakerSim->GetSDigitsData(0+fGenOffsetS[fAliITSQADataMakerSim->GetEventSpecie()])->Fill(1,nsdig);
275       fAliITSQADataMakerSim->GetSDigitsData(2+fGenOffsetS[fAliITSQADataMakerSim->GetEventSpecie()])->Fill(imod,nsdig);
276     }
277     sdig->Clear() ;
278   }
279   return rv ; 
280 }
281
282 //____________________________________________________________________________ 
283 Int_t AliITSQASPDDataMakerSim::InitHits()
284
285   // Initialization for HITS data - SPD -
286   const Bool_t expert   = kTRUE ; 
287   const Bool_t image    = kTRUE ;
288   Int_t rv = 0 ; 
289   
290   //fGenOffsetH = (fAliITSQADataMakerSim->fHitsQAList[AliRecoParam::kDefault])->GetEntries();
291   //printf("--W-- AliITSQASPDDataMakerSim::InitHits()  fGenOffset= %d \n",fGenOffset);
292   //fSPDhHTask must be incremented by one unit every time a histogram is ADDED to the QA List
293   Char_t name[50];
294   Char_t title[50];
295
296   TH1F *hlayer = new TH1F("SPDLayPattern_SPD","Layer map - SPD",6,0.,6.);
297   hlayer->GetXaxis()->SetTitle("Layer number");
298   hlayer->GetYaxis()->SetTitle("Entries");
299   rv = fAliITSQADataMakerSim->Add2HitsList(hlayer,fGenOffsetH[fAliITSQADataMakerSim->GetEventSpecie()], expert, !image);
300   fSPDhHTask++;
301
302   TH1F **hmod = new TH1F*[2];
303   for (Int_t iLay=0; iLay<2; ++iLay) {
304     snprintf(name,49,"SPDModPattern_SPD%d",iLay+1);
305     snprintf(title,49,"Module map - SPD Layer %d",iLay+1);
306     hmod[iLay]=new TH1F(name,title,240,0,240);
307     hmod[iLay]->GetXaxis()->SetTitle("Module number");
308     hmod[iLay]->GetYaxis()->SetTitle("Entries");
309     rv = fAliITSQADataMakerSim->Add2HitsList(hmod[iLay],1+iLay+fGenOffsetH[fAliITSQADataMakerSim->GetEventSpecie()], !expert, image);
310     fSPDhHTask++;
311   }
312
313   TH1F *hhitlenght = new TH1F("SPDLenght_SPD","SPD Hit lenght along y_{loc} coord",210,0.,210.);
314   hhitlenght->GetXaxis()->SetTitle("Hit lenght [#mum]");
315   hhitlenght->GetYaxis()->SetTitle("# hits");
316   rv = fAliITSQADataMakerSim->Add2HitsList(hhitlenght,3+fGenOffsetH[fAliITSQADataMakerSim->GetEventSpecie()], !expert, image);
317   fSPDhHTask++;
318
319   TH1F *hEdepos = new TH1F("SPDEnergyDeposit_SPD","SPD Deposited energy distribution (y_{loc}>180 #mum)",150,0.,300.); 
320   hEdepos->GetXaxis()->SetTitle("Deposited energy [keV]"); 
321   hEdepos->GetYaxis()->SetTitle("# hits");
322   rv = fAliITSQADataMakerSim->Add2HitsList(hEdepos,4+fGenOffsetH[fAliITSQADataMakerSim->GetEventSpecie()], !expert, image);
323   fSPDhHTask++;
324
325   AliDebug(AliQAv1::GetQADebugLevel(),Form("%d SPD Hits histograms booked\n",fSPDhHTask));
326   delete [] hmod;
327   return rv ; 
328 }
329
330 //____________________________________________________________________________
331 Int_t AliITSQASPDDataMakerSim::MakeHits(TTree *hits)
332
333   // Fill QA for HITS - SPD -
334   Int_t rv = 0 ; 
335  
336   AliITS *fITS  = (AliITS*)gAlice->GetModule("ITS");
337   fITS->SetTreeAddress();
338   Int_t nmodules;
339   fITS->InitModules(-1,nmodules); //-1->number of modules taken from AliITSgeom class kept in fITSgeom
340                                   //nmodules is set
341
342   fITS->FillModules(hits,0);
343
344   for (Int_t imod=0; imod<240; ++imod){
345     AliITSmodule *module = fITS->GetModule(imod);
346     TObjArray *arrHits = module->GetHits();
347     Int_t nhits = arrHits->GetEntriesFast();
348     if (imod<80) {
349       fAliITSQADataMakerSim->GetHitsData(fGenOffsetH[fAliITSQADataMakerSim->GetEventSpecie()])->Fill(0.5,nhits);
350       fAliITSQADataMakerSim->GetHitsData(1+fGenOffsetH[fAliITSQADataMakerSim->GetEventSpecie()])->Fill(imod,nhits);
351     } else {
352       fAliITSQADataMakerSim->GetHitsData(fGenOffsetH[fAliITSQADataMakerSim->GetEventSpecie()])->Fill(1,nhits);
353       fAliITSQADataMakerSim->GetHitsData(2+fGenOffsetH[fAliITSQADataMakerSim->GetEventSpecie()])->Fill(imod,nhits);
354     }
355     for (Int_t iHit=0; iHit<nhits; ++iHit) {
356       AliITShit *hit = (AliITShit*) arrHits->At(iHit);
357       Double_t xl,yl,zl,xl0,yl0,zl0;
358       Double_t tof,tof0;
359       hit->GetPositionL(xl,yl,zl,tof);
360       hit->GetPositionL0(xl0,yl0,zl0,tof0);
361       Float_t dyloc=TMath::Abs(yl-yl0)*10000.;
362       fAliITSQADataMakerSim->GetHitsData(3+fGenOffsetH[fAliITSQADataMakerSim->GetEventSpecie()])->Fill(dyloc);
363       Float_t edep=hit->GetIonization()*1000000;
364       if(dyloc>180.){
365         fAliITSQADataMakerSim->GetHitsData(4+fGenOffsetH[fAliITSQADataMakerSim->GetEventSpecie()])->Fill(edep);
366       }
367     }
368   }
369   return rv ; 
370 }
371
372
373 //_______________________________________________________________
374
375 Int_t AliITSQASPDDataMakerSim::GetOffset(AliQAv1::TASKINDEX_t task,Int_t specie){
376   // Returns histogram offset according to the specified task
377   Int_t offset=0;
378   if( task == AliQAv1::kHITS){
379     offset=fGenOffsetH[specie];
380   }
381   else if( task == AliQAv1::kSDIGITS) {
382     offset=fGenOffsetS[specie];
383   }
384   else if( task == AliQAv1::kDIGITS) {
385     offset=fGenOffsetD[specie];
386   }
387   else {
388     AliInfo("No task has been selected. TaskHisto set to zero.\n");
389   }
390
391   return offset;
392 }
393
394 //____________________________________________________________________________ 
395 void AliITSQASPDDataMakerSim::SetOffset(AliQAv1::TASKINDEX_t task, Int_t offset,Int_t specie ){
396   // Returns histogram offset according to the specified task
397   if( task == AliQAv1::kHITS){
398     fGenOffsetH[specie] = offset;  
399   }
400   else if( task == AliQAv1::kSDIGITS) {
401     fGenOffsetS[specie] = offset;   
402   }
403   else if( task == AliQAv1::kDIGITS) {
404     fGenOffsetD[specie] = offset;   
405   }
406   else {
407     AliInfo("No task has been selected. TaskHisto set to zero.\n");
408   }
409 }
410
411 //_______________________________________________________________
412
413 Int_t AliITSQASPDDataMakerSim::GetTaskHisto(AliQAv1::TASKINDEX_t task) {
414   // Returns the number of booked histograms for the selected task
415   Int_t histotot=0;
416   if( task == AliQAv1::kHITS) {
417     histotot=fSPDhHTask ;
418   }
419   else if( task == AliQAv1::kSDIGITS) {
420     histotot=fSPDhSTask;
421   }
422   else if( task == AliQAv1::kDIGITS) {
423     histotot=fSPDhDTask ;
424   }
425   else {
426     AliInfo("No task has been selected. TaskHisto set to zero.\n");
427   }
428   return histotot;
429
430 }