commented define _ClusterTopology_ - to be used only for the special productions
[u/mrichter/AliRoot.git] / ITS / AliITSQASSDDataMakerSim.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 //  SSD QA part: P. Christakoglou - NIKHEF/UU
26
27 // --- ROOT system ---
28 #include <TTree.h>
29 #include <TH1.h>
30 #include <TH2.h>
31 #include <TMath.h>
32 // --- Standard library ---
33
34 // --- AliRoot header files ---
35 #include "AliITS.h"
36 #include "AliITSmodule.h"
37 #include "AliITShit.h"
38 #include "AliITSdigit.h"
39 #include "AliITSpListItem.h"
40 #include "AliRun.h"
41 #include "AliITSQADataMakerSim.h"
42 #include "AliITSQASSDDataMakerSim.h"
43 #include "AliLog.h"
44 #include "AliQAv1.h"
45 #include "AliQAChecker.h"
46 #include "AliRawReader.h"
47
48 ClassImp(AliITSQASSDDataMakerSim)
49
50 //____________________________________________________________________________ 
51 AliITSQASSDDataMakerSim::AliITSQASSDDataMakerSim(AliITSQADataMakerSim *aliITSQADataMakerSim) :
52 TObject(),
53 fAliITSQADataMakerSim(aliITSQADataMakerSim),
54 //fSSDhTask(0),
55 fSSDhHTask(0),
56 fSSDhSTask(0),
57 fSSDhDTask(0),
58 fGenOffsetH(0),
59 fGenOffsetS(0), 
60 fGenOffsetD(0) 
61 {
62   //ctor used to discriminate OnLine-Offline analysis  
63   fGenOffsetH=  new Int_t[AliRecoParam::kNSpecies];                       
64   fGenOffsetS=  new Int_t[AliRecoParam::kNSpecies];                           
65   fGenOffsetD=  new Int_t[AliRecoParam::kNSpecies];
66   for(Int_t i=0; i<AliRecoParam::kNSpecies; i++) 
67     {
68       fGenOffsetH[i]= 0;
69       fGenOffsetS[i]= 0;
70       fGenOffsetD[i]= 0;
71     }  
72 }
73
74 //____________________________________________________________________________ 
75 AliITSQASSDDataMakerSim::AliITSQASSDDataMakerSim(const AliITSQASSDDataMakerSim& qadm) :
76 TObject(),
77 fAliITSQADataMakerSim(qadm.fAliITSQADataMakerSim),
78 //fSSDhTask(qadm.fSSDhTask),
79 fSSDhHTask(qadm.fSSDhHTask),
80 fSSDhSTask(qadm.fSSDhSTask),
81 fSSDhDTask(qadm.fSSDhDTask),
82 fGenOffsetH(qadm.fGenOffsetH), 
83 fGenOffsetS(qadm.fGenOffsetS), 
84 fGenOffsetD(qadm.fGenOffsetD) 
85 {
86   //copy ctor 
87   fAliITSQADataMakerSim->SetName((const char*)qadm.fAliITSQADataMakerSim->GetName()) ; 
88   fAliITSQADataMakerSim->SetTitle((const char*)qadm.fAliITSQADataMakerSim->GetTitle());
89   }
90
91 //__________________________________________________________________
92 AliITSQASSDDataMakerSim& AliITSQASSDDataMakerSim::operator = (const AliITSQASSDDataMakerSim& qac ) {
93   // Equal operator.
94   this->~AliITSQASSDDataMakerSim();
95   new(this) AliITSQASSDDataMakerSim(qac);
96   return *this;
97 }
98
99 //____________________________________________________________________________ 
100 void AliITSQASSDDataMakerSim::StartOfDetectorCycle() {
101   //Detector specific actions at start of cycle
102   AliDebug(AliQAv1::GetQADebugLevel(),"AliITSQADM::Start of SSD Cycle\n");
103 }
104
105 //____________________________________________________________________________ 
106 void AliITSQASSDDataMakerSim::EndOfDetectorCycle(AliQAv1::TASKINDEX_t /*task*/, TObjArray** /*list*/) {
107   // launch the QA checking
108   AliDebug(AliQAv1::GetQADebugLevel(),"AliITSDM instantiates checker with Run(AliQAv1::kITS, task, list)\n"); 
109   
110 //  AliQAChecker::Instance()->Run( AliQAv1::kITS , task, list);
111 }
112
113 //____________________________________________________________________________ 
114 Int_t AliITSQASSDDataMakerSim::InitDigits() { 
115   // Initialization for DIGIT data - SSD -
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
121   // custom code here
122   TH1F *fHistSSDModule = new TH1F("fHistSSDDigitsModule",
123                                   "SSD Digits Module;SSD Module Number;N_{DIGITS}",
124                                   1698,499.5,2197.5);  
125   rv = fAliITSQADataMakerSim->Add2DigitsList(fHistSSDModule,
126                                         fGenOffsetD[fAliITSQADataMakerSim->GetEventSpecie()] + 0, !expert, image);
127   fSSDhDTask += 1;
128   TH2F *fHistSSDModuleStrip = new TH2F("fHistSSDDigitsModuleStrip",
129                                        "SSD Digits Module Strip;N_{Strip};N_{Module}",
130                                        1540,0,1540,1698,499.5,2197.5);  
131   rv = fAliITSQADataMakerSim->Add2DigitsList(fHistSSDModuleStrip,
132                                         fGenOffsetD[fAliITSQADataMakerSim->GetEventSpecie()] + 1, !expert, image);
133   fSSDhDTask += 1;
134
135   AliDebug(AliQAv1::GetQADebugLevel(),Form("%d SSD Digits histograms booked\n",fSSDhDTask));
136   return rv ; 
137 }
138
139 //____________________________________________________________________________
140 Int_t AliITSQASSDDataMakerSim::MakeDigits(TTree *digits) 
141
142   // Fill QA for DIGIT - SSD -
143   Int_t rv = 0 ; 
144
145   AliITS *fITS  = (AliITS*)gAlice->GetModule("ITS");
146   fITS->SetTreeAddress();
147   TClonesArray *iSSDdigits  = fITS->DigitsAddress(2);
148   for(Int_t iModule = 500; iModule < 2198; iModule++) {
149     iSSDdigits->Clear();
150     digits->GetEvent(iModule);    
151     Int_t ndigits = iSSDdigits->GetEntries();
152     fAliITSQADataMakerSim->FillDigitsData(fGenOffsetD[fAliITSQADataMakerSim->GetEventSpecie()] + 0,iModule,ndigits);
153     if(ndigits != 0)
154       AliDebug(AliQAv1::GetQADebugLevel(),Form("Module: %d - Digits: %d",iModule,ndigits));
155  
156     for (Int_t iDigit = 0; iDigit < ndigits; iDigit++) {
157       AliITSdigit *dig = (AliITSdigit*)iSSDdigits->UncheckedAt(iDigit);
158       Int_t fStripNumber = (dig->GetCoord1() == 0) ? dig->GetCoord2() : dig->GetCoord2() + fgkNumberOfPSideStrips;
159       fAliITSQADataMakerSim->FillDigitsData(fGenOffsetD[fAliITSQADataMakerSim->GetEventSpecie()] + 1,fStripNumber,iModule,dig->GetSignal());
160     }//digit loop
161   }//module loop
162   //
163   return rv ; 
164 }
165
166 //____________________________________________________________________________ 
167 Int_t AliITSQASSDDataMakerSim::InitSDigits() { 
168   // Initialization for SDIGIT data - SSD -
169   const Bool_t expert   = kTRUE ; 
170   const Bool_t image    = kTRUE ; 
171   Int_t rv = 0 ; 
172   //fGenOffsetS = (fAliITSQADataMakerSim->fSDigitsQAList[AliRecoParam::kDefault])->GetEntries();
173
174   // custom code here
175   TH1F *fHistSSDModule = new TH1F("fHistSSDSDigitsModule",
176                                   "SSD SDigits Module;SSD Module Number;N_{SDIGITS}",
177                                   1698,499.5,2197.5);  
178   rv = fAliITSQADataMakerSim->Add2SDigitsList(fHistSSDModule,
179                                          fGenOffsetS[fAliITSQADataMakerSim->GetEventSpecie()] + 0, !expert, image);
180   fSSDhSTask += 1;  
181
182   AliDebug(AliQAv1::GetQADebugLevel(),Form("%d SSD SDigits histograms booked\n",fSSDhSTask));
183   //
184   return rv ; 
185 }
186
187 //____________________________________________________________________________
188 Int_t AliITSQASSDDataMakerSim::MakeSDigits(TTree *sdigits) { 
189   // Fill QA for SDIGIT - SSD -
190   Int_t rv = 0 ; 
191  
192   static TClonesArray iSSDEmpty("AliITSpListItem",10000);
193   iSSDEmpty.Clear();
194   TClonesArray *iSSDsdigits = &iSSDEmpty;
195
196   //  AliDebug(AliQAv1::GetQADebugLevel(), Form("Trying to access the sdigits histogram: %d\n",fGenOffsetS));
197
198   TBranch *brchSDigits = sdigits->GetBranch("ITS");
199   brchSDigits->SetAddress(&iSSDsdigits);
200   for(Int_t iModule = 500; iModule < 2198; iModule++) {
201     iSSDsdigits->Clear();
202     sdigits->GetEvent(iModule);    
203     Int_t ndigits = iSSDsdigits->GetEntries();
204     fAliITSQADataMakerSim->FillSDigitsData(fGenOffsetS[fAliITSQADataMakerSim->GetEventSpecie()] + 0,iModule,ndigits);
205     if(ndigits != 0)
206       AliDebug(AliQAv1::GetQADebugLevel(),Form("Module: %d - Digits: %d",iModule,ndigits));
207
208 //     for (Int_t iDigit = 0; iDigit < ndigits; iDigit++) {
209 //       AliITSpListItem *dig=(AliITSpListItem*)iSSDsdigits->At(iDigit);
210 //       dig=0;
211 //     }//digit loop
212   }//module loop
213   //
214   return rv ; 
215 }
216
217 //____________________________________________________________________________ 
218 Int_t AliITSQASSDDataMakerSim::InitHits() { 
219   // Initialization for HITS data - SSD -
220   const Bool_t expert   = kTRUE ; 
221   const Bool_t image    = kTRUE ; 
222   Int_t rv = 0 ; 
223
224   //fGenOffsetH = (fAliITSQADataMakerSim->fHitsQAList[fEventSpecie])->GetEntries();
225
226   // custom code here
227   TH1F *fHistSSDModule = new TH1F("fHistSSDHitsModule",
228                                   "SSD Hits Module;SSD Module Number;N_{HITS}",
229                                   1698,499.5,2197.5); 
230   rv = fAliITSQADataMakerSim->Add2HitsList(fHistSSDModule,
231                                       fGenOffsetH[fAliITSQADataMakerSim->GetEventSpecie()] + 0, !expert, image);
232   fSSDhHTask += 1;
233   TH1F *fHistSSDGlobalX = new TH1F("fHistSSDHitsGlobalX",
234                                    "SSD Hits Global X;x [cm];Entries",
235                                    1000,-50.,50.);
236   rv = fAliITSQADataMakerSim->Add2HitsList(fHistSSDGlobalX,
237                                       fGenOffsetH[fAliITSQADataMakerSim->GetEventSpecie()] + 1, !expert, image);
238   fSSDhHTask += 1;
239   TH1F *fHistSSDGlobalY = new TH1F("fHistSSDHitsGlobalY",
240                                    "SSD Hits Global Y;y [cm];Entries",
241                                    1000,-50.,50.);
242   rv = fAliITSQADataMakerSim->Add2HitsList(fHistSSDGlobalY,
243                                       fGenOffsetH[fAliITSQADataMakerSim->GetEventSpecie()] + 2, !expert, image);
244   fSSDhHTask += 1;
245   TH1F *fHistSSDGlobalZ = new TH1F("fHistSSDHitsGlobalZ",
246                                    "SSD Hits Global Z ;z [cm];Entries",
247                                    1000,-60.,60.);
248   rv = fAliITSQADataMakerSim->Add2HitsList(fHistSSDGlobalZ,
249                                       fGenOffsetH[fAliITSQADataMakerSim->GetEventSpecie()] + 3, !expert, image);
250   fSSDhHTask += 1;
251   TH1F *fHistSSDLocalX = new TH1F("fHistSSDHitsLocalX",
252                                   "SSD Hits Local X;x [cm];Entries",
253                                   1000,-4.,4.);
254   rv = fAliITSQADataMakerSim->Add2HitsList(fHistSSDLocalX,
255                                       fGenOffsetH[fAliITSQADataMakerSim->GetEventSpecie()] + 4, !expert, image);
256   fSSDhHTask += 1;
257   TH1F *fHistSSDLocalY = new TH1F("fHistSSDHitsLocalY",
258                                   "SSD Hits Local Y;y [cm];Entries",
259                                   1000,-0.1,0.1);
260   rv = fAliITSQADataMakerSim->Add2HitsList(fHistSSDLocalY,
261                                       fGenOffsetH[fAliITSQADataMakerSim->GetEventSpecie()] + 5, !expert, image);
262   fSSDhHTask += 1;
263   TH1F *fHistSSDLocalZ = new TH1F("fHistSSDHitsLocalZ",
264                                   "SSD Hits Local Z;z [cm];Entries",
265                                   1000,-4.,4.);
266   rv = fAliITSQADataMakerSim->Add2HitsList(fHistSSDLocalZ,
267                                       fGenOffsetH[fAliITSQADataMakerSim->GetEventSpecie()] + 6, !expert, image);
268   fSSDhHTask += 1;
269   TH1F *fHistSSDIonization = new TH1F("fHistSSDHitsIonization",
270                                       "SSD Hits Ionization;log(dE/dx) [KeV];N_{Hits}",
271                                       100,-7,-2);
272   rv = fAliITSQADataMakerSim->Add2HitsList(fHistSSDIonization,
273                                       fGenOffsetH[fAliITSQADataMakerSim->GetEventSpecie()] + 7, !expert, image);
274   fSSDhHTask += 1;
275   TH2F *fHistSSDGlobalXY = new TH2F("fHistSSDHitsGlobalXY",
276                                     "SSD Hits Global XY;x [cm];y [cm]",
277                                     1000,-50.,50.,
278                                     1000,-50.,50.);
279   rv = fAliITSQADataMakerSim->Add2HitsList(fHistSSDGlobalXY,
280                                       fGenOffsetH[fAliITSQADataMakerSim->GetEventSpecie()] + 8, !expert, image);
281   fSSDhHTask += 1;
282  
283   AliDebug(AliQAv1::GetQADebugLevel(),Form("%d SSD Hits histograms booked\n",fSSDhHTask));
284   return rv ; 
285 }
286
287
288 //____________________________________________________________________________
289 Int_t AliITSQASSDDataMakerSim::MakeHits(TTree *hits) { 
290   // Fill QA for HITS - SSD -
291   Int_t rv = 0 ; 
292  
293   AliITS *fITS  = (AliITS*)gAlice->GetModule("ITS");
294   fITS->SetTreeAddress();
295   Int_t nmodules;
296   fITS->InitModules(-1,nmodules);
297   fITS->FillModules(hits,0);
298   for(Int_t iModule = 500; iModule < 2198; iModule++) {
299     AliITSmodule *module = fITS->GetModule(iModule);
300     TObjArray *arrHits = module->GetHits();
301     Int_t nhits = arrHits->GetEntriesFast();
302     if(nhits != 0)
303       AliDebug(AliQAv1::GetQADebugLevel(),Form("Module: %d - Hits: %d",iModule,nhits));
304     for (Int_t iHit = 0; iHit < nhits; iHit++) {
305       AliITShit *hit = (AliITShit*) arrHits->At(iHit);
306       
307       fAliITSQADataMakerSim->FillHitsData(fGenOffsetH[fAliITSQADataMakerSim->GetEventSpecie()] + 0,iModule);
308       fAliITSQADataMakerSim->FillHitsData(fGenOffsetH[fAliITSQADataMakerSim->GetEventSpecie()] + 1,hit->GetXG());
309       fAliITSQADataMakerSim->FillHitsData(fGenOffsetH[fAliITSQADataMakerSim->GetEventSpecie()] + 2,hit->GetYG());
310       fAliITSQADataMakerSim->FillHitsData(fGenOffsetH[fAliITSQADataMakerSim->GetEventSpecie()] + 3,hit->GetZG());
311       fAliITSQADataMakerSim->FillHitsData(fGenOffsetH[fAliITSQADataMakerSim->GetEventSpecie()] + 4,hit->GetXL());
312       fAliITSQADataMakerSim->FillHitsData(fGenOffsetH[fAliITSQADataMakerSim->GetEventSpecie()] + 5,hit->GetYL());
313       fAliITSQADataMakerSim->FillHitsData(fGenOffsetH[fAliITSQADataMakerSim->GetEventSpecie()] + 6,hit->GetZL());
314       if(hit->GetIonization())
315         fAliITSQADataMakerSim->FillHitsData(fGenOffsetH[fAliITSQADataMakerSim->GetEventSpecie()] + 7,TMath::Log10(hit->GetIonization()));
316       fAliITSQADataMakerSim->FillHitsData(fGenOffsetH[fAliITSQADataMakerSim->GetEventSpecie()] + 8,hit->GetXG(),hit->GetYG());
317     }//hit loop
318   }//module loop  
319   return rv ; 
320 }
321
322 //____________________________________________________________________________ 
323 Int_t AliITSQASSDDataMakerSim::GetOffset(AliQAv1::TASKINDEX_t task,Int_t specie){
324   // Returns histogram offset according to the specified task
325   Int_t offset=0;
326   if( task == AliQAv1::kHITS){
327     offset=fGenOffsetH[specie];  
328   }
329   else if( task == AliQAv1::kSDIGITS) {
330     offset=fGenOffsetS[specie];   
331   }
332   else if( task == AliQAv1::kDIGITS) {
333     offset=fGenOffsetD[specie];   
334   }
335   else {
336     AliInfo("No task has been selected. TaskHisto set to zero.\n");
337   }
338
339   return offset;
340 }
341
342
343 //____________________________________________________________________________ 
344 void AliITSQASSDDataMakerSim::SetOffset(AliQAv1::TASKINDEX_t task, Int_t offset,Int_t specie ){
345   // Returns histogram offset according to the specified task
346   if( task == AliQAv1::kHITS){
347     fGenOffsetH[specie] = offset;  
348   }
349   else if( task == AliQAv1::kSDIGITS) {
350     fGenOffsetS[specie] = offset;   
351   }
352   else if( task == AliQAv1::kDIGITS) {
353     fGenOffsetD[specie] = offset;   
354   }
355   else {
356     AliInfo("No task has been selected. TaskHisto set to zero.\n");
357   }
358 }
359
360 //____________________________________________________________________________ 
361 Int_t AliITSQASSDDataMakerSim::GetTaskHisto(AliQAv1::TASKINDEX_t task) {
362   // Returns the number of booked histograms for the selected task
363   Int_t histotot=0;
364   if( task == AliQAv1::kHITS) {
365     histotot=fSSDhHTask ;  
366   }
367   else if( task == AliQAv1::kSDIGITS) {
368     histotot=fSSDhSTask;   
369   }
370   else if( task == AliQAv1::kDIGITS) {
371     histotot=fSSDhDTask ;   
372   }
373   else {
374     AliInfo("No task has been selected. TaskHisto set to zero.\n");
375   }
376   return histotot;
377
378 }