Debug printout removed.
[u/mrichter/AliRoot.git] / STEER / AliQADataMakerRec.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 *
940d8e5f 10 * copies and that both the copyright notice and this permission notifce *
04236e67 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
17/* $Id$ */
18
202374b1 19//
20// Base Class
21// Produces the data needed to calculate the quality assurance for Reconstruction
22// All data must be mergeable objects.
23// Y. Schutz CERN July 2007
24//
04236e67 25
26// --- ROOT system ---
7d297381 27#include <TCanvas.h>
04236e67 28#include <TFile.h>
04236e67 29#include <TTree.h>
57acd2d2 30#include <TNtupleD.h>
fb6e511e 31#include <TObjArray.h>
04236e67 32
33// --- Standard library ---
34
35// --- AliRoot header files ---
fb6e511e 36#include "AliCDBPath.h"
37#include "AliCDBEntry.h"
38#include "AliDetectorRecoParam.h"
39#include "AliCDBManager.h"
40
04236e67 41#include "AliLog.h"
42#include "AliQADataMakerRec.h"
04236e67 43#include "AliESDEvent.h"
44#include "AliRawReader.h"
45
46ClassImp(AliQADataMakerRec)
47
48//____________________________________________________________________________
49AliQADataMakerRec::AliQADataMakerRec(const char * name, const char * title) :
50 AliQADataMaker(name, title),
a2b64fbd 51 fESDsQAList(NULL),
52 fRawsQAList(NULL),
53 fRecPointsQAList(NULL),
57acd2d2 54 fCorrNt(NULL),
a2b64fbd 55 fRecoParam(NULL)
04236e67 56{
57 // ctor
58 fDetectorDirName = GetName() ;
59}
60
61//____________________________________________________________________________
62AliQADataMakerRec::AliQADataMakerRec(const AliQADataMakerRec& qadm) :
b8bd1ab8 63 AliQADataMaker(qadm.GetName(), qadm.GetTitle()),
64 fESDsQAList(qadm.fESDsQAList),
65 fRawsQAList(qadm.fRawsQAList),
66 fRecPointsQAList(qadm.fRecPointsQAList),
57acd2d2 67 fCorrNt(qadm.fCorrNt),
a2b64fbd 68 fRecoParam(qadm.fRecoParam)
04236e67 69{
70 //copy ctor
71 SetName(qadm.GetName()) ;
72 SetTitle(qadm.GetTitle()) ;
73 fDetectorDirName = GetName() ;
74}
75
63c6f8ae 76//____________________________________________________________________________
77AliQADataMakerRec::~AliQADataMakerRec()
78{
79 //dtor: delete the TObjArray and thei content
7ff8385d 80 if ( fESDsQAList ) {
57acd2d2 81 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
82 if ( fESDsQAList[specie] ) {
83 if ( fESDsQAList[specie]->IsOwner() )
84 fESDsQAList[specie]->Delete() ;
85 }
86 }
87 delete[] fESDsQAList ;
7ff8385d 88 }
89 if ( fRawsQAList ) {
57acd2d2 90 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
91 if ( fRawsQAList[specie] ) {
92 if ( fRawsQAList[specie]->IsOwner() )
93 fRawsQAList[specie]->Delete() ;
94 }
95 }
96 delete[] fRawsQAList ;
97 }
7ff8385d 98 if ( fRecPointsQAList ) {
57acd2d2 99 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
100 if ( fRecPointsQAList[specie] ) {
101 if ( fRecPointsQAList[specie]->IsOwner() )
102 fRecPointsQAList[specie]->Delete() ;
103 }
104 }
105 delete[] fRecPointsQAList ;
7ff8385d 106 }
63c6f8ae 107}
108
04236e67 109//__________________________________________________________________
110AliQADataMakerRec& AliQADataMakerRec::operator = (const AliQADataMakerRec& qadm )
111{
112 // Assignment operator.
113 this->~AliQADataMakerRec();
114 new(this) AliQADataMakerRec(qadm);
115 return *this;
116}
117
118//____________________________________________________________________________
930e6e3e 119void AliQADataMakerRec::EndOfCycle()
120{
121 // Finishes a cycle of QA for all the tasks
4e25ac79 122 EndOfCycle(AliQAv1::kRAWS) ;
123 EndOfCycle(AliQAv1::kRECPOINTS) ;
124 EndOfCycle(AliQAv1::kESDS) ;
930e6e3e 125 ResetCycle() ;
126}
127
128//____________________________________________________________________________
4e25ac79 129void AliQADataMakerRec::EndOfCycle(AliQAv1::TASKINDEX_t task)
04236e67 130{
930e6e3e 131 // Finishes a cycle of QA
04236e67 132
57acd2d2 133 TObjArray ** list = NULL ;
04236e67 134
4e25ac79 135 if ( task == AliQAv1::kRAWS )
04236e67 136 list = fRawsQAList ;
4e25ac79 137 else if ( task == AliQAv1::kRECPOINTS )
04236e67 138 list = fRecPointsQAList ;
4e25ac79 139 else if ( task == AliQAv1::kESDS )
04236e67 140 list = fESDsQAList ;
7c002d48 141
930e6e3e 142
57acd2d2 143 if ( ! list && ! fCorrNt )
930e6e3e 144 return ;
145 //DefaultEndOfDetectorCycle(task) ;
0774e4a4 146 EndOfDetectorCycle(task, list) ;
a2b64fbd 147 TDirectory * subDir = NULL ;
7c002d48 148 if (fDetectorDir)
4e25ac79 149 subDir = fDetectorDir->GetDirectory(AliQAv1::GetTaskName(task)) ;
45c5be2d 150 if ( subDir ) {
eecc22a3 151 subDir->cd() ;
57acd2d2 152 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
153 TDirectory * eventSpecieDir = subDir->GetDirectory(AliRecoParam::GetEventSpecieName(specie)) ;
154 if (eventSpecieDir) {
155 eventSpecieDir->cd() ;
156 if (list[specie]) {
157 TIter next(list[specie]) ;
158 TObject * obj ;
750730d8 159 while( (obj = next()) ) {
4e25ac79 160 if (!obj->TestBit(AliQAv1::GetExpertBit()))
57acd2d2 161 obj->Write() ;
162 }
163 if (WriteExpert()) {
4e25ac79 164 TDirectory * expertDir = eventSpecieDir->GetDirectory(AliQAv1::GetExpert()) ;
57acd2d2 165 if ( expertDir ) { // Write only if requested
166 expertDir->cd() ;
167 next.Reset() ;
168 while( (obj = next()) ) {
4e25ac79 169 if (!obj->TestBit(AliQAv1::GetExpertBit()))
57acd2d2 170 continue ;
171 obj->Write() ;
172 }
173 }
174 }
175 }
176 if ( !fCorrNt )
177 continue ;
4e25ac79 178 if (fCorrNt[specie] && AliQAv1::GetDetIndex(GetName()) == AliQAv1::kCORR) {
57acd2d2 179 eventSpecieDir->cd() ;
180 fCorrNt[specie]->Write() ;
b1af1125 181 }
6e65319c 182 }
183 }
a595ac34 184 fOutput->Save() ;
eecc22a3 185 }
5379c4a3 186 if ( AliDebugLevel() == AliQAv1::GetQADebugLevel() )
187 MakeImage(task) ;
04236e67 188}
7d297381 189
190//____________________________________________________________________________
191void AliQADataMakerRec::MakeImage(AliQAv1::TASKINDEX_t task)
192{
193 // create a drawing of detetor defined histograms
194 TObjArray ** list = NULL ;
195 switch (task) {
196 case AliQAv1::kRAWS:
197 list = fRawsQAList ;
198 break;
199 case AliQAv1::kHITS:
200 break;
201 case AliQAv1::kSDIGITS:
202 break;
203 case AliQAv1::kDIGITS:
204 break;
205 case AliQAv1::kRECPOINTS:
206 list = fRecPointsQAList ;
207 break;
208 case AliQAv1::kTRACKSEGMENTS:
209 break;
210 case AliQAv1::kRECPARTICLES:
211 break;
212 case AliQAv1::kESDS:
213 list = fESDsQAList ;
214 break;
215 case AliQAv1::kNTASKINDEX:
216 break;
217 default:
218 break;
219 }
220 if ( !list) {
221 AliError("data not initialized, call AliQADataMaker::Init");
222 return ;
223 }
224 TIter next(list[0]) ;
225 TH1 * hdata = NULL ;
226 Int_t nImages = 0 ;
227 while ( (hdata=dynamic_cast<TH1 *>(next())) ) {
228 if ( hdata->TestBit(AliQAv1::GetImageBit()) )
229 nImages++;
230 }
231 if ( nImages == 0 ) {
5379c4a3 232 AliWarning(Form("No histogram will be plotted for %s %s\n", GetName(), AliQAv1::GetTaskName(task).Data())) ;
7d297381 233 } else {
5379c4a3 234 AliDebug(AliQAv1::GetQADebugLevel(), Form("%d histograms will be plotted for %s %s\n", nImages, GetName(), AliQAv1::GetTaskName(task).Data())) ;
7d297381 235 Double_t w = 1000 ;
236 Double_t h = 1000 ;
237 for (Int_t esIndex = 0 ; esIndex < AliRecoParam::kNSpecies ; esIndex++) {
238 TCanvas * canvasQA = new TCanvas(Form("QA_%s_%s_%s",
239 GetName(),
240 AliQAv1::GetTaskName(task).Data(),
241 AliRecoParam::GetEventSpecieName(esIndex)),
242 Form("QA control plots for det=%s task=%s eventspecie=%s",
243 GetName(),
244 AliQAv1::GetTaskName(task).Data(),
245 AliRecoParam::GetEventSpecieName(esIndex)),
246 w, h) ;
247 canvasQA->SetWindowSize(w + (w - canvasQA->GetWw()), h + (h - canvasQA->GetWh())) ;
248 Int_t nx = TMath::Sqrt(nImages) ;
249 Int_t ny = nx ;
250 if ( nx < TMath::Sqrt(nImages))
251 ny++ ;
252 canvasQA->Divide(nx, ny) ;
253 TIter nexthist(list[esIndex]) ;
254 TH1* hist = NULL ;
255 Int_t npad = 1 ;
256 canvasQA->cd(npad) ;
257 while ( (hist=dynamic_cast<TH1*>(nexthist())) ) {
258 if(hist->TestBit(AliQAv1::GetImageBit())) {
259 hist->Draw() ;
260 canvasQA->cd(++npad) ;
261 }
262 }
263 canvasQA->Print() ;
264 }
265 }
266}
267
04236e67 268//____________________________________________________________________________
4e25ac79 269void AliQADataMakerRec::Exec(AliQAv1::TASKINDEX_t task, TObject * data)
04236e67 270{
271 // creates the quality assurance data for the various tasks (Hits, SDigits, Digits, ESDs)
272
4e25ac79 273 if ( task == AliQAv1::kRAWS ) {
5379c4a3 274 AliDebug(AliQAv1::GetQADebugLevel(), "Processing Raws QA") ;
04236e67 275 AliRawReader * rawReader = dynamic_cast<AliRawReader *>(data) ;
276 if (rawReader)
277 MakeRaws(rawReader) ;
278 else
5379c4a3 279 AliDebug(AliQAv1::GetQADebugLevel(), "Raw data are not processed") ;
4e25ac79 280 } else if ( task == AliQAv1::kRECPOINTS ) {
5379c4a3 281 AliDebug(AliQAv1::GetQADebugLevel(), "Processing RecPoints QA") ;
04236e67 282 TTree * tree = dynamic_cast<TTree *>(data) ;
283 if (tree) {
284 MakeRecPoints(tree) ;
285 } else {
286 AliWarning("data are not a TTree") ;
287 }
4e25ac79 288 } else if ( task == AliQAv1::kESDS ) {
5379c4a3 289 AliDebug(AliQAv1::GetQADebugLevel(), "Processing ESDs QA") ;
04236e67 290 AliESDEvent * esd = dynamic_cast<AliESDEvent *>(data) ;
291 if (esd)
292 MakeESDs(esd) ;
293 else
294 AliError("Wrong type of esd container") ;
295 }
296}
297
298//____________________________________________________________________________
4e25ac79 299TObjArray ** AliQADataMakerRec::Init(AliQAv1::TASKINDEX_t task, Int_t cycles)
04236e67 300{
301 // general intialisation
fb6e511e 302 InitRecoParams() ;
57acd2d2 303 TObjArray ** rv = NULL ;
04236e67 304
04236e67 305 if (cycles > 0)
306 SetCycle(cycles) ;
307
4e25ac79 308 if ( task == AliQAv1::kRAWS ) {
63c6f8ae 309 if (! fRawsQAList ) {
57acd2d2 310 fRawsQAList = new TObjArray *[AliRecoParam::kNSpecies] ;
311 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
312 fRawsQAList[specie] = new TObjArray(100) ;
4e25ac79 313 fRawsQAList[specie]->SetName(Form("%s_%s_%s", GetName(), AliQAv1::GetTaskName(task).Data(), AliRecoParam::GetEventSpecieName(specie))) ;
57acd2d2 314 }
63c6f8ae 315 InitRaws() ;
316 }
04236e67 317 rv = fRawsQAList ;
4e25ac79 318 } else if ( task == AliQAv1::kRECPOINTS ) {
63c6f8ae 319 if ( ! fRecPointsQAList ) {
57acd2d2 320 fRecPointsQAList = new TObjArray *[AliRecoParam::kNSpecies] ;
321 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
322 fRecPointsQAList[specie] = new TObjArray(100) ;
4e25ac79 323 fRecPointsQAList[specie]->SetName(Form("%s_%s_%s", GetName(), AliQAv1::GetTaskName(task).Data(), AliRecoParam::GetEventSpecieName(specie))) ;
57acd2d2 324 }
325 InitRecPoints() ;
63c6f8ae 326 }
04236e67 327 rv = fRecPointsQAList ;
4e25ac79 328 } else if ( task == AliQAv1::kESDS ) {
63c6f8ae 329 if ( ! fESDsQAList ) {
57acd2d2 330 fESDsQAList = new TObjArray *[AliRecoParam::kNSpecies] ;
331 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
332 fESDsQAList[specie] = new TObjArray(100) ;
4e25ac79 333 fESDsQAList[specie]->SetName(Form("%s_%s", GetName(), AliQAv1::GetTaskName(task).Data(), AliRecoParam::GetEventSpecieName(specie))) ;
57acd2d2 334 }
63c6f8ae 335 InitESDs() ;
336 }
04236e67 337 rv = fESDsQAList ;
338 }
04236e67 339 return rv ;
340}
341
342//____________________________________________________________________________
4e25ac79 343void AliQADataMakerRec::Init(AliQAv1::TASKINDEX_t task, TObjArray ** list, Int_t run, Int_t cycles)
04236e67 344{
345 // Intialisation by passing the list of QA data booked elsewhere
346
fb6e511e 347 InitRecoParams() ;
348 fRun = run ;
04236e67 349 if (cycles > 0)
350 SetCycle(cycles) ;
351
4e25ac79 352 if ( task == AliQAv1::kRAWS ) {
04236e67 353 fRawsQAList = list ;
4e25ac79 354 } else if ( task == AliQAv1::kRECPOINTS ) {
04236e67 355 fRecPointsQAList = list ;
4e25ac79 356 } else if ( task == AliQAv1::kESDS ) {
04236e67 357 fESDsQAList = list ;
358 }
359}
360
361//____________________________________________________________________________
fb6e511e 362void AliQADataMakerRec::InitRecoParams()
363{
364 if (!fRecoParam) {
5379c4a3 365 AliDebug(AliQAv1::GetQADebugLevel(), Form("Loading reconstruction parameter objects for detector %s", GetName()));
fb6e511e 366 AliCDBPath path(GetName(),"Calib","RecoParam");
367 AliCDBEntry *entry=AliCDBManager::Instance()->Get(path.GetPath());
368 if(!entry) {
369 fRecoParam = NULL ;
370 AliWarning(Form("Couldn't find RecoParam entry in OCDB for detector %s",GetName()));
371 }
372 else {
373 TObject * recoParamObj = entry->GetObject() ;
42383dda 374 if (dynamic_cast<TObjArray*>(recoParamObj)) {
375 // The detector has only one set of reco parameters
5379c4a3 376 AliDebug(AliQAv1::GetQADebugLevel(), Form("Array of reconstruction parameters found for detector %s",GetName()));
42383dda 377 TObjArray *recoParamArray = dynamic_cast<TObjArray*>(recoParamObj) ;
378 for (Int_t iRP=0; iRP<recoParamArray->GetEntriesFast(); iRP++) {
379 fRecoParam = dynamic_cast<AliDetectorRecoParam*>(recoParamArray->At(iRP)) ;
380 if (fRecoParam->IsDefault()) break;
381 }
382 }
383 else if (dynamic_cast<AliDetectorRecoParam*>(recoParamObj)) {
fb6e511e 384 // The detector has only onse set of reco parameters
385 // Registering it in AliRecoParam
5379c4a3 386 AliDebug(AliQAv1::GetQADebugLevel(), Form("Single set of reconstruction parameters found for detector %s",GetName()));
fb6e511e 387 dynamic_cast<AliDetectorRecoParam*>(recoParamObj)->SetAsDefault();
388 fRecoParam = dynamic_cast<AliDetectorRecoParam*>(recoParamObj) ;
389 } else {
390 AliError(Form("No valid RecoParam object found in the OCDB for detector %s",GetName()));
391 }
392 }
42383dda 393 AliCDBManager::Instance()->UnloadFromCache(path.GetPath());
fb6e511e 394 }
395}
396
397//____________________________________________________________________________
930e6e3e 398void AliQADataMakerRec::StartOfCycle(Int_t run)
399{
400 // Finishes a cycle of QA for all the tasks
401 Bool_t samecycle = kFALSE ;
4e25ac79 402 StartOfCycle(AliQAv1::kRAWS, run, samecycle) ;
930e6e3e 403 samecycle = kTRUE ;
4e25ac79 404 StartOfCycle(AliQAv1::kRECPOINTS, run, samecycle) ;
405 StartOfCycle(AliQAv1::kESDS, run, samecycle) ;
930e6e3e 406}
407
408//____________________________________________________________________________
4e25ac79 409void AliQADataMakerRec::StartOfCycle(AliQAv1::TASKINDEX_t task, Int_t run, const Bool_t sameCycle)
04236e67 410{
411 // Finishes a cycle of QA data acquistion
930e6e3e 412 if ( run > 0 )
413 fRun = run ;
04236e67 414 if ( !sameCycle || fCurrentCycle == -1) {
415 ResetCycle() ;
416 if (fOutput)
417 fOutput->Close() ;
4e25ac79 418 fOutput = AliQAv1::GetQADataFile(GetName(), fRun) ;
04236e67 419 }
5379c4a3 420 AliDebug(AliQAv1::GetQADebugLevel(), Form(" Run %d Cycle %d task %s file %s",
4e25ac79 421 fRun, fCurrentCycle, AliQAv1::GetTaskName(task).Data(), fOutput->GetName() )) ;
04236e67 422
423 fDetectorDir = fOutput->GetDirectory(GetDetectorDirName()) ;
424 if (!fDetectorDir)
425 fDetectorDir = fOutput->mkdir(GetDetectorDirName()) ;
426
4e25ac79 427 TDirectory * subDir = fDetectorDir->GetDirectory(AliQAv1::GetTaskName(task)) ;
04236e67 428 if (!subDir)
4e25ac79 429 subDir = fDetectorDir->mkdir(AliQAv1::GetTaskName(task)) ;
6e65319c 430
57acd2d2 431 for ( Int_t specie = AliRecoParam::kDefault ; specie < AliRecoParam::kNSpecies ; specie++ ) {
432 TDirectory * eventSpecieDir = subDir->GetDirectory(AliRecoParam::GetEventSpecieName(specie)) ;
433 if (!eventSpecieDir)
434 eventSpecieDir = subDir->mkdir(AliRecoParam::GetEventSpecieName(specie)) ;
4e25ac79 435 TDirectory * expertDir = eventSpecieDir->GetDirectory(AliQAv1::GetExpert()) ;
57acd2d2 436 if (!expertDir)
4e25ac79 437 expertDir = eventSpecieDir->mkdir(AliQAv1::GetExpert()) ;
57acd2d2 438 }
04236e67 439 StartOfDetectorCycle() ;
440}