- add protection against invalid sector/stack information in on-line track matching
[u/mrichter/AliRoot.git] / TRD / AliTRDQADataMakerSim.cxx
CommitLineData
04236e67 1/**************************************************************************
2 * Copyright(c) 1998-1999, 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// //
20// Produces the data needed to calculate the quality assurance. //
21// All data must be mergeable objects. //
22// //
23// Author: //
24// Sylwester Radomski (radomski@physi.uni-heidelberg.de) //
25// //
26////////////////////////////////////////////////////////////////////////////
27
28// --- ROOT system ---
29#include <TClonesArray.h>
30#include <TFile.h>
92664bc8 31#include <TH1F.h>
32#include <TH2F.h>
33#include <TH3F.h>
04236e67 34#include <TProfile.h>
35#include <TF1.h>
36#include <TCanvas.h>
37#include <TTree.h>
38
39// --- AliRoot header files ---
40//#include "AliESDEvent.h"
41#include "AliLog.h"
42#include "AliTRDdigit.h"
43#include "AliTRDhit.h"
44//#include "AliTRDcluster.h"
45#include "AliTRDQADataMakerSim.h"
46#include "AliTRDdigitsManager.h"
47#include "AliTRDgeometry.h"
b65e5048 48#include "AliTRDarrayADC.h"
49#include "AliTRDarraySignal.h"
987ba9a3 50//#include "AliTRDrawStream.h"
04236e67 51
52#include "AliQAChecker.h"
53
54ClassImp(AliTRDQADataMakerSim)
55
56//____________________________________________________________________________
57 AliTRDQADataMakerSim::AliTRDQADataMakerSim() :
6252ceeb 58 AliQADataMakerSim(AliQAv1::GetDetName(AliQAv1::kTRD), "TRD Quality Assurance Data Maker"),
59 fTmpHits(NULL)
04236e67 60{
61 //
62 // Default constructor
63}
64
65//____________________________________________________________________________
66AliTRDQADataMakerSim::AliTRDQADataMakerSim(const AliTRDQADataMakerSim& qadm) :
6252ceeb 67 AliQADataMakerSim(),
68 fTmpHits(NULL)
04236e67 69{
70 //
71 // Copy constructor
72 //
73
74 SetName((const char*)qadm.GetName()) ;
75 SetTitle((const char*)qadm.GetTitle());
76
77}
78
79//__________________________________________________________________
80AliTRDQADataMakerSim& AliTRDQADataMakerSim::operator=(const AliTRDQADataMakerSim& qadm)
81{
82 //
83 // Equal operator.
84 //
85
86 this->~AliTRDQADataMakerSim();
87 new(this) AliTRDQADataMakerSim(qadm);
88 return *this;
89
90}
91
92//____________________________________________________________________________
6252ceeb 93AliTRDQADataMakerSim::~AliTRDQADataMakerSim()
94{
95 if (fTmpHits) {
96 fTmpHits->Clear() ;
97 delete fTmpHits ;
98 }
99}
100
101//____________________________________________________________________________
4e25ac79 102void AliTRDQADataMakerSim::EndOfDetectorCycle(AliQAv1::TASKINDEX_t task, TObjArray ** list)
04236e67 103{
104 //
105 // Detector specific actions at end of cycle
106 //
92664bc8 107 ResetEventTrigClasses();
5379c4a3 108 //AliDebug(AliQAv1::GetQADebugLevel(), Form("EndOfCycle", "Fitting RecPoints %d", task));
04236e67 109
110 // call the checker
4e25ac79 111 AliQAChecker::Instance()->Run(AliQAv1::kTRD, task, list) ;
04236e67 112
113
114}
115
116//____________________________________________________________________________
117void AliTRDQADataMakerSim::InitHits()
118{
119 //
120 // Create Hits histograms in Hits subdir
121 //
7d297381 122 const Bool_t expert = kTRUE ;
123 const Bool_t image = kTRUE ;
124
04236e67 125 const Int_t kNhist = 4;
92664bc8 126 TH1F *hist[kNhist];
04236e67 127
92664bc8 128 hist[0] = new TH1F("qaTRD_hits_det", "TRD hits det;Detector Id of the hit;Counts", 540, -0.5, 539.5) ;
04236e67 129
92664bc8 130 hist[1] = new TH1F("qaTRD_hist_Qdrift", "TRD hits Qdrift;Charge from tracks;Counts", 100, 0, 100);
131 hist[2] = new TH1F("qaTRD_hist_Qamp", "TRD hits Qamp;Charge from TRD photon;Counts", 100, 0, 100);
132 hist[3] = new TH1F("qaTRD_hist_Qphoton", "TRD hits Qphoton;Charge from TRD photon;Counts", 100, 0, 100);
04236e67 133
134 for(Int_t i=0; i<kNhist; i++) {
135 //hist[i]->Sumw2();
7d297381 136 Add2HitsList(hist[i], i, !expert, image);
04236e67 137 }
92664bc8 138 //
139 ClonePerTrigClass(AliQAv1::kHITS); // this should be the last line
04236e67 140}
141
142//____________________________________________________________________________
143void AliTRDQADataMakerSim::InitDigits()
144{
145 //
146 // Create Digits histograms in Digits subdir
147 //
7d297381 148 const Bool_t expert = kTRUE ;
149 const Bool_t image = kTRUE ;
150
04236e67 151 const Int_t kNhist = 3;
92664bc8 152 TH1F *hist[kNhist];
04236e67 153
92664bc8 154 hist[0] = new TH1F("qaTRD_digits_det", "TRD digits det;Detector Id of the digit;Counts", 540, -0.5, 539.5);
155 hist[1] = new TH1F("qaTRD_digits_time", "TRDdigits time;Time bin;Counts", 40, -0.5, 39.5);
156 hist[2] = new TH1F("qaTRD_digits_amp", "TRD digits amp;Amplitude;Counts", 100, -5.5, 94.5);
04236e67 157
158 for(Int_t i=0; i<kNhist; i++) {
159 hist[i]->Sumw2();
7d297381 160 Add2DigitsList(hist[i], i, !expert, image);
04236e67 161 }
92664bc8 162 //
163 ClonePerTrigClass(AliQAv1::kDIGITS); // this should be the last line
04236e67 164}
165
166//____________________________________________________________________________
167void AliTRDQADataMakerSim::InitSDigits()
168{
169 //
170 // Create SDigits histograms in SDigits subdir
171 //
7d297381 172 const Bool_t expert = kTRUE ;
173 const Bool_t image = kTRUE ;
174
04236e67 175 const Int_t kNhist = 3;
92664bc8 176 TH1F *hist[kNhist];
04236e67 177
92664bc8 178 hist[0] = new TH1F("qaTRD_sdigits_det", "TRD sdigits det;Detector Id of the digit;Counts", 540, -0.5, 539.5);
179 hist[1] = new TH1F("qaTRD_sdigits_time", "TRD sdigits time;Time bin;Counts", 40, -0.5, 39.5);
180 hist[2] = new TH1F("qaTRD_sdigits_amp", "TRD sdigits amp;Amplitude;Counts", 100, 0, 1e7);
04236e67 181
182 for(Int_t i=0; i<kNhist; i++) {
183 hist[i]->Sumw2();
7d297381 184 Add2SDigitsList(hist[i], i, !expert, image);
04236e67 185 }
92664bc8 186 //
187 ClonePerTrigClass(AliQAv1::kSDIGITS); // this should be the last line
04236e67 188}
189
190//____________________________________________________________________________
6252ceeb 191void AliTRDQADataMakerSim::MakeHits()
04236e67 192{
193 //
194 // Make QA data from Hits
195 //
6252ceeb 196
197 TIter next(fHitsArray);
04236e67 198 AliTRDhit * hit;
199
200 while ( (hit = dynamic_cast<AliTRDhit *>(next())) ) {
92664bc8 201 FillHitsData(0,hit->GetDetector());
04236e67 202 Double_t q = TMath::Abs(hit->GetCharge());
203
92664bc8 204 if (hit->FromDrift()) FillHitsData(1,q);
205 if (hit->FromAmplification()) FillHitsData(2,q);
206 if (hit->FromTRphoton()) FillHitsData(3,q);
04236e67 207 }
04236e67 208}
209
210//____________________________________________________________________________
211void AliTRDQADataMakerSim::MakeHits(TTree * hitTree)
212{
213 //
214 // Make QA data from Hits
215 //
216
217 if (!CheckPointer(hitTree, "TRD hits tree")) return;
218
219 TBranch *branch = hitTree->GetBranch("TRD");
220 if (!CheckPointer(branch, "TRD hits branch")) return;
eca4fa66 221
04236e67 222 Int_t nhits = (Int_t)(hitTree->GetTotBytes()/sizeof(AliTRDhit));
6252ceeb 223 if (fHitsArray)
224 fHitsArray->Clear() ;
225 else
226 fHitsArray = new TClonesArray("AliTRDhit", nhits+1000);
227
bb5265c9 228 //Int_t index = 0;
04236e67 229 Int_t nEntries = (Int_t)branch->GetEntries();
230 for(Int_t i = 0; i < nEntries; i++) {
231 branch->GetEntry(i);
6252ceeb 232 MakeHits();
233 fHitsArray->Clear() ;
04236e67 234 }
92664bc8 235 //
236 IncEvCountCycleHits();
237 IncEvCountTotalHits();
238 //
04236e67 239}
240
241//____________________________________________________________________________
6252ceeb 242void AliTRDQADataMakerSim::MakeDigits()
04236e67 243{
244 //
245 // Makes data from Digits
246 //
247
6252ceeb 248 if (!fDigitsArray)
249 return ;
eca4fa66 250
6252ceeb 251 TIter next(fDigitsArray) ;
04236e67 252 AliTRDdigit * digit ;
3590bda8 253
254 // Info("Make digits", "From the arrya");
255
04236e67 256 while ( (digit = dynamic_cast<AliTRDdigit *>(next())) ) {
3590bda8 257 if (digit->GetAmp() < 1) continue;
92664bc8 258 FillDigitsData(0,digit->GetDetector());
259 FillDigitsData(1,digit->GetTime());
260 FillDigitsData(2,digit->GetAmp());
04236e67 261 }
262
263}
264
265//____________________________________________________________________________
266void AliTRDQADataMakerSim::MakeDigits(TTree * digits)
267{
268 //
269 // Makes data from digits tree
270 //
3590bda8 271 // Info("Make digits", "From a tree");
272
04236e67 273 AliTRDdigitsManager *digitsManager = new AliTRDdigitsManager();
274 digitsManager->CreateArrays();
275 digitsManager->ReadDigits(digits);
92664bc8 276 static TObjArray histDet,histTime,histSignal;
277 //
278 GetMatchingDigitsData(0,&histDet);
279 GetMatchingDigitsData(1,&histTime);
280 GetMatchingDigitsData(2,&histSignal);
3590bda8 281
b65e5048 282 for (Int_t i = 0; i < AliTRDgeometry::kNdet; i++)
283 {
284 AliTRDarrayADC *digitsIn = (AliTRDarrayADC *) digitsManager->GetDigits(i);
285
286 // This is to take care of switched off super modules
287 if (digitsIn->GetNtime() == 0) continue;
288
289 digitsIn->Expand();
290
291 //AliTRDSignalIndex* indexes = digitsManager->GetIndexes(i);
292 //if (indexes->IsAllocated() == kFALSE) digitsManager->BuildIndexes(i);
293
294 Int_t nRows = digitsIn->GetNrow();
295 Int_t nCols = digitsIn->GetNcol();
296 Int_t nTbins = digitsIn->GetNtime();
297
298 for(Int_t row = 0; row < nRows; row++)
eca4fa66 299 for(Int_t col = 0; col < nCols; col++)
300 for(Int_t time = 0; time < nTbins; time++)
301 {
302 Float_t signal = digitsIn->GetData(row,col,time);
303 if (signal < 1) continue;
92664bc8 304 for (int ih=histDet.GetEntriesFast();ih--;) ((TH1*)histDet.UncheckedAt(ih))->Fill(i);
305 for (int ih=histTime.GetEntriesFast();ih--;) ((TH1*)histTime.UncheckedAt(ih))->Fill(time);
306 for (int ih=histSignal.GetEntriesFast();ih--;) ((TH1*)histSignal.UncheckedAt(ih))->Fill(signal);
eca4fa66 307 }
308
309 //delete digitsIn;
310 }
04236e67 311 delete digitsManager;
92664bc8 312 //
313 IncEvCountCycleDigits();
314 IncEvCountTotalDigits();
315 //
04236e67 316}
317
318//____________________________________________________________________________
6252ceeb 319void AliTRDQADataMakerSim::MakeSDigits()
04236e67 320{
321 //
322 // Makes data from Digits
323 //
324
6252ceeb 325 if (!fSDigitsArray)
326 return ;
327
328 TIter next(fSDigitsArray) ;
04236e67 329 AliTRDdigit * digit ;
330 while ( (digit = dynamic_cast<AliTRDdigit *>(next())) ) {
92664bc8 331 FillDigitsData(0,digit->GetDetector());
332 FillDigitsData(1,digit->GetTime());
333 FillDigitsData(2,digit->GetAmp());
04236e67 334 }
335
336}
337
338//____________________________________________________________________________
339void AliTRDQADataMakerSim::MakeSDigits(TTree * digits)
340{
341 //
342 // Makes data from SDigits
343 //
eca4fa66 344 // Check id histograms already created for this Event Specie
345 if ( ! GetSDigitsData(0) )
346 InitSDigits() ;
347
04236e67 348 AliTRDdigitsManager *digitsManager = new AliTRDdigitsManager();
c10bf383 349 digitsManager->SetSDigits(kTRUE);
04236e67 350 digitsManager->CreateArrays();
351 digitsManager->ReadDigits(digits);
352
92664bc8 353 static TObjArray histDet,histTime,histSignal;
354 //
355 GetMatchingSDigitsData(0,&histDet);
356 GetMatchingSDigitsData(1,&histTime);
357 GetMatchingSDigitsData(2,&histSignal);
3590bda8 358
b65e5048 359 for (Int_t i = 0; i < AliTRDgeometry::kNdet; i++)
360 {
361 AliTRDarraySignal *digitsIn = (AliTRDarraySignal *) digitsManager->GetSDigits(i);
362
04236e67 363 // This is to take care of switched off super modules
b65e5048 364 if (digitsIn->GetNtime() == 0) continue;
365
366 digitsIn->Expand();
367
368 //AliTRDSignalIndex* indexes = digitsManager->GetIndexes(i);
369 //if (indexes->IsAllocated() == kFALSE) digitsManager->BuildIndexes(i);
370 Int_t nRows = digitsIn->GetNrow();
371 Int_t nCols = digitsIn->GetNcol();
372 Int_t nTbins = digitsIn->GetNtime();
373
374 for(Int_t row = 0; row < nRows; row++)
375 {
376 for(Int_t col = 0; col < nCols; col++)
377 {
378 for(Int_t time = 0; time < nTbins; time++)
379 {
380 Float_t signal = digitsIn->GetData(row,col,time);
381 if (signal < 1) continue;
92664bc8 382 for (int ih=histDet.GetEntriesFast();ih--;) ((TH1*)histDet.UncheckedAt(ih))->Fill(i);
383 for (int ih=histTime.GetEntriesFast();ih--;) ((TH1*)histTime.UncheckedAt(ih))->Fill(time);
384 for (int ih=histSignal.GetEntriesFast();ih--;) ((TH1*)histSignal.UncheckedAt(ih))->Fill(signal);
b65e5048 385 }
386 }
387 }
388 // delete digitsIn;
389 }
04236e67 390 delete digitsManager;
92664bc8 391 //
392 IncEvCountCycleSDigits();
393 IncEvCountTotalSDigits();
394 //
04236e67 395}
396
397//____________________________________________________________________________
398void AliTRDQADataMakerSim::StartOfDetectorCycle()
399{
400 //
401 // Detector specific actions at start of cycle
402 //
403
404}
405
406//__________________________________________________________________________
407Int_t AliTRDQADataMakerSim::CheckPointer(TObject *obj, const char *name)
408{
409 //
410 // Checks initialization of pointers
411 //
412
413 if (!obj) AliWarning(Form("null pointer: %s", name));
414 return !!obj;
415
416}