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