Update master to aliroot
[u/mrichter/AliRoot.git] / STEER / 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 ---
04236e67 27#include <TFile.h>
04236e67 28#include <TTree.h>
57acd2d2 29#include <TNtupleD.h>
fb6e511e 30#include <TObjArray.h>
04236e67 31
32// --- Standard library ---
33
34// --- AliRoot header files ---
fb6e511e 35#include "AliCDBPath.h"
36#include "AliCDBEntry.h"
37#include "AliDetectorRecoParam.h"
38#include "AliCDBManager.h"
39
04236e67 40#include "AliLog.h"
41#include "AliQADataMakerRec.h"
50dee02c 42#include "AliQAManager.h"
04236e67 43#include "AliESDEvent.h"
44#include "AliRawReader.h"
45
46ClassImp(AliQADataMakerRec)
47
48//____________________________________________________________________________
49AliQADataMakerRec::AliQADataMakerRec(const char * name, const char * title) :
92664bc8 50AliQADataMaker(name, title),
71f27f1f 51 fDigitsQAList(NULL),
a2b64fbd 52 fESDsQAList(NULL),
53 fRawsQAList(NULL),
54 fRecPointsQAList(NULL),
57acd2d2 55 fCorrNt(NULL),
6252ceeb 56 fRecoParam(NULL),
57 fRecPointsArray(NULL)
04236e67 58{
59 // ctor
92664bc8 60 fDetectorDirName = GetName() ;
04236e67 61}
62
63//____________________________________________________________________________
64AliQADataMakerRec::AliQADataMakerRec(const AliQADataMakerRec& qadm) :
b8bd1ab8 65 AliQADataMaker(qadm.GetName(), qadm.GetTitle()),
71f27f1f 66 fDigitsQAList(qadm.fDigitsQAList),
b8bd1ab8 67 fESDsQAList(qadm.fESDsQAList),
68 fRawsQAList(qadm.fRawsQAList),
69 fRecPointsQAList(qadm.fRecPointsQAList),
57acd2d2 70 fCorrNt(qadm.fCorrNt),
6252ceeb 71 fRecoParam(qadm.fRecoParam),
72 fRecPointsArray(NULL)
04236e67 73{
74 //copy ctor
92664bc8 75 fDetectorDirName = GetName() ;
04236e67 76}
77
63c6f8ae 78//____________________________________________________________________________
79AliQADataMakerRec::~AliQADataMakerRec()
80{
92664bc8 81 //dtor: delete the TObjArray and thei content
82 if ( fESDsQAList ) {
57acd2d2 83 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
84 if ( fESDsQAList[specie] ) {
92664bc8 85 fESDsQAList[specie]->Delete() ;
57acd2d2 86 }
87 }
88 delete[] fESDsQAList ;
92664bc8 89 }
90 if ( fRawsQAList ) {
57acd2d2 91 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
92 if ( fRawsQAList[specie] ) {
2f9129dd 93 fRawsQAList[specie]->Delete() ;
57acd2d2 94 }
95 }
96 delete[] fRawsQAList ;
97 }
92664bc8 98 if ( fDigitsQAList ) {
44ed7a66 99 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
100 if ( fDigitsQAList[specie] ) {
2f9129dd 101 fDigitsQAList[specie]->Delete() ;
44ed7a66 102 }
103 }
92664bc8 104 delete[] fDigitsQAList ;
44ed7a66 105 }
92664bc8 106 if ( fRecPointsQAList ) {
57acd2d2 107 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
108 if ( fRecPointsQAList[specie] ) {
2f9129dd 109 fRecPointsQAList[specie]->Delete() ;
57acd2d2 110 }
111 }
92664bc8 112 delete[] fRecPointsQAList ;
eca4fa66 113 }
6252ceeb 114 if (fRecPointsArray) {
115 fRecPointsArray->Clear() ;
116 delete fRecPointsArray ;
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{
92664bc8 143 // Finishes a cycle of QA
04236e67 144
ea5df941 145
146 TObjArray ** list = NULL ;
04236e67 147
92664bc8 148 if ( task == AliQAv1::kRAWS )
149 list = fRawsQAList ;
150 else if ( task == AliQAv1::kDIGITSR )
151 list = fDigitsQAList ;
152 else if ( task == AliQAv1::kRECPOINTS )
153 list = fRecPointsQAList ;
154 else if ( task == AliQAv1::kESDS )
155 list = fESDsQAList ;
7c002d48 156
930e6e3e 157
92664bc8 158 if ( ! list && ! fCorrNt )
930e6e3e 159 return ;
160 //DefaultEndOfDetectorCycle(task) ;
92664bc8 161 EndOfDetectorCycle(task, list) ;
50dee02c 162
92664bc8 163 if (! AliQAManager::QAManager(AliQAv1::kRECMODE)->IsSaveData()) return;
ea5df941 164
eca4fa66 165 fDetectorDir = fOutput->GetDirectory(GetDetectorDirName()) ;
92664bc8 166 if (!fDetectorDir) fDetectorDir = fOutput->mkdir(GetDetectorDirName()) ;
eca4fa66 167 TDirectory * subDir = fDetectorDir->GetDirectory(AliQAv1::GetTaskName(task)) ;
92664bc8 168 if (!subDir) subDir = fDetectorDir->mkdir(AliQAv1::GetTaskName(task)) ;
169 subDir->cd();
170 //
6252ceeb 171 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) { // skip Default
92664bc8 172 if (! AliQAv1::Instance(AliQAv1::GetDetIndex(GetName()))->IsEventSpecieSet(AliRecoParam::ConvertIndex(specie)) || AliRecoParam::ConvertIndex(specie) == AliRecoParam::kDefault) continue ;
7822bb76 173 TDirectory * eventSpecieDir = subDir->GetDirectory(AliRecoParam::GetEventSpecieName(specie)) ;
92664bc8 174 if (!eventSpecieDir) eventSpecieDir = subDir->mkdir(AliRecoParam::GetEventSpecieName(specie)) ;
175 eventSpecieDir->cd();
af65f4c8 176 if (list) {
177 if (list[specie]) {
178 TIter next(list[specie]) ;
179 TObject * obj ;
eca4fa66 180 while( (obj = next()) ) {
92664bc8 181 if (!obj->TestBit(AliQAv1::GetExpertBit())) obj->Write(); // RS: Note, this can be also TObjArray of clones
af65f4c8 182 }
183 if (WriteExpert()) {
184 TDirectory * expertDir = eventSpecieDir->GetDirectory(AliQAv1::GetExpert()) ;
185 if (!expertDir)
186 expertDir = eventSpecieDir->mkdir(AliQAv1::GetExpert()) ;
187 expertDir->cd() ;
188 next.Reset() ;
189 while( (obj = next()) ) {
92664bc8 190 if (!obj->TestBit(AliQAv1::GetExpertBit())) continue;
191 obj->Write(); // RS: Note, this can be also TObjArray of clones
af65f4c8 192 }
193 }
eca4fa66 194 }
af65f4c8 195 }
196 else if ( fCorrNt ) {
197 if (fCorrNt[specie] && AliQAv1::GetDetIndex(GetName()) == AliQAv1::kCORR) {
ddfe5350 198 if (fCorrNt[specie]->GetNvar() != 0) {
199 eventSpecieDir->cd() ;
200 fCorrNt[specie]->Write() ;
201 }
af65f4c8 202 }
203 fOutput->Save() ;
7822bb76 204 }
eca4fa66 205 }
7d297381 206}
207
04236e67 208//____________________________________________________________________________
4e25ac79 209void AliQADataMakerRec::Exec(AliQAv1::TASKINDEX_t task, TObject * data)
04236e67 210{
211 // creates the quality assurance data for the various tasks (Hits, SDigits, Digits, ESDs)
212
92664bc8 213 if ( task == AliQAv1::kRAWS ) {
214 AliDebug(AliQAv1::GetQADebugLevel(), "Processing Raws QA") ;
215 AliRawReader * rawReader = static_cast<AliRawReader *>(data) ;
216 if (rawReader)
217 MakeRaws(rawReader) ;
218 else
5379c4a3 219 AliDebug(AliQAv1::GetQADebugLevel(), "Raw data are not processed") ;
92664bc8 220 } else if ( task == AliQAv1::kDIGITSR ) {
221 AliDebug(AliQAv1::GetQADebugLevel(), "Processing Digits QA") ;
222 TTree * tree = static_cast<TTree *>(data) ;
223 if (strcmp(tree->ClassName(), "TTree") == 0) {
224 MakeDigits(tree) ;
225 } else {
226 AliWarning("data are not a TTree") ;
227 }
228 } else if ( task == AliQAv1::kRECPOINTS ) {
229 AliDebug(AliQAv1::GetQADebugLevel(), "Processing RecPoints QA") ;
230 TTree * tree = static_cast<TTree *>(data) ;
231 if (strcmp(tree->ClassName(), "TTree") == 0) {
232 MakeRecPoints(tree) ;
233 } else {
234 AliWarning("data are not a TTree") ;
235 }
236 } else if ( task == AliQAv1::kESDS ) {
237 AliDebug(AliQAv1::GetQADebugLevel(), "Processing ESDs QA") ;
238 AliESDEvent * esd = static_cast<AliESDEvent *>(data) ;
239 if (strcmp(esd->ClassName(), "AliESDEvent") == 0)
240 MakeESDs(esd) ;
241 else
242 AliError("Wrong type of esd container") ;
243 }
04236e67 244}
245
246//____________________________________________________________________________
4e25ac79 247TObjArray ** AliQADataMakerRec::Init(AliQAv1::TASKINDEX_t task, Int_t cycles)
04236e67 248{
249 // general intialisation
fb6e511e 250 InitRecoParams() ;
92664bc8 251 TObjArray ** rv = NULL ;
04236e67 252
92664bc8 253 if (cycles > 0)
254 SetCycle(cycles) ;
04236e67 255
92664bc8 256 if ( task == AliQAv1::kRAWS ) {
257 if (! fRawsQAList ) {
57acd2d2 258 fRawsQAList = new TObjArray *[AliRecoParam::kNSpecies] ;
259 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
49466ea2 260 fRawsQAList[specie] = new TObjArray(AliQAv1::GetMaxQAObj()) ;
4e25ac79 261 fRawsQAList[specie]->SetName(Form("%s_%s_%s", GetName(), AliQAv1::GetTaskName(task).Data(), AliRecoParam::GetEventSpecieName(specie))) ;
57acd2d2 262 }
92664bc8 263 }
264 rv = fRawsQAList ;
265 } else if ( task == AliQAv1::kDIGITSR ) {
266 if ( ! fDigitsQAList ) {
44ed7a66 267 fDigitsQAList = new TObjArray *[AliRecoParam::kNSpecies] ;
268 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
49466ea2 269 fDigitsQAList[specie] = new TObjArray(AliQAv1::GetMaxQAObj()) ;
44ed7a66 270 fDigitsQAList[specie]->SetName(Form("%s_%s_%s", GetName(), AliQAv1::GetTaskName(task).Data(), AliRecoParam::GetEventSpecieName(specie))) ;
271 }
92664bc8 272 }
273 rv = fDigitsQAList ;
274 } else if ( task == AliQAv1::kRECPOINTS ) {
275 if ( ! fRecPointsQAList ) {
57acd2d2 276 fRecPointsQAList = new TObjArray *[AliRecoParam::kNSpecies] ;
277 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
49466ea2 278 fRecPointsQAList[specie] = new TObjArray(AliQAv1::GetMaxQAObj()) ;
4e25ac79 279 fRecPointsQAList[specie]->SetName(Form("%s_%s_%s", GetName(), AliQAv1::GetTaskName(task).Data(), AliRecoParam::GetEventSpecieName(specie))) ;
57acd2d2 280 }
eca4fa66 281 }
92664bc8 282 rv = fRecPointsQAList ;
283 } else if ( task == AliQAv1::kESDS ) {
284 if ( ! fESDsQAList ) {
57acd2d2 285 fESDsQAList = new TObjArray *[AliRecoParam::kNSpecies] ;
286 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
49466ea2 287 fESDsQAList[specie] = new TObjArray(AliQAv1::GetMaxQAObj()) ;
65b25288 288 fESDsQAList[specie]->SetName(Form("%s_%s", GetName(), AliQAv1::GetTaskName(task).Data())); //, AliRecoParam::GetEventSpecieName(specie))) ;
57acd2d2 289 }
92664bc8 290 }
291 rv = fESDsQAList ;
292 }
293 return rv ;
04236e67 294}
295
296//____________________________________________________________________________
4e25ac79 297void AliQADataMakerRec::Init(AliQAv1::TASKINDEX_t task, TObjArray ** list, Int_t run, Int_t cycles)
04236e67 298{
299 // Intialisation by passing the list of QA data booked elsewhere
300
fb6e511e 301 InitRecoParams() ;
302 fRun = run ;
92664bc8 303 if (cycles > 0)
304 SetCycle(cycles) ;
04236e67 305
92664bc8 306 if ( task == AliQAv1::kRAWS ) {
307 fRawsQAList = list ;
308 } else if ( task == AliQAv1::kDIGITSR ) {
309 fDigitsQAList = list ;
310 } else if ( task == AliQAv1::kRECPOINTS ) {
311 fRecPointsQAList = list ;
312 } else if ( task == AliQAv1::kESDS ) {
313 fESDsQAList = list ;
314 }
04236e67 315}
316
317//____________________________________________________________________________
fb6e511e 318void AliQADataMakerRec::InitRecoParams()
319{
f14c8c46 320 // Get the recoparam form the OCDB
fb6e511e 321 if (!fRecoParam) {
5379c4a3 322 AliDebug(AliQAv1::GetQADebugLevel(), Form("Loading reconstruction parameter objects for detector %s", GetName()));
fb6e511e 323 AliCDBPath path(GetName(),"Calib","RecoParam");
fcab16e6 324 AliCDBEntry *entry=AliCDBManager::Instance()->Get(path.GetPath());
fb6e511e 325 if(!entry) {
326 fRecoParam = NULL ;
55e356ec 327 AliDebug(AliQAv1::GetQADebugLevel(), Form("Couldn't find RecoParam entry in OCDB for detector %s",GetName()));
fb6e511e 328 }
329 else {
a5ef5a9a 330 // entry->SetOwner(kTRUE);
fb6e511e 331 TObject * recoParamObj = entry->GetObject() ;
eca4fa66 332 if ( strcmp(recoParamObj->ClassName(), "TObjArray") == 0 ) {
42383dda 333 // The detector has only one set of reco parameters
5379c4a3 334 AliDebug(AliQAv1::GetQADebugLevel(), Form("Array of reconstruction parameters found for detector %s",GetName()));
eca4fa66 335 TObjArray *recoParamArray = static_cast<TObjArray*>(recoParamObj) ;
a5ef5a9a 336 // recoParamArray->SetOwner(kTRUE);
42383dda 337 for (Int_t iRP=0; iRP<recoParamArray->GetEntriesFast(); iRP++) {
eca4fa66 338 fRecoParam = static_cast<AliDetectorRecoParam*>(recoParamArray->At(iRP)) ;
339 if (!fRecoParam)
340 break ;
341 else if (fRecoParam->IsDefault())
342 break ;
42383dda 343 }
344 }
eca4fa66 345 else if (recoParamObj->InheritsFrom("AliDetectorRecoParam")) {
346 // The detector has only one set of reco parameters
fb6e511e 347 // Registering it in AliRecoParam
5379c4a3 348 AliDebug(AliQAv1::GetQADebugLevel(), Form("Single set of reconstruction parameters found for detector %s",GetName()));
eca4fa66 349 fRecoParam = static_cast<AliDetectorRecoParam*>(recoParamObj) ;
350 static_cast<AliDetectorRecoParam*>(recoParamObj)->SetAsDefault();
fb6e511e 351 } else {
352 AliError(Form("No valid RecoParam object found in the OCDB for detector %s",GetName()));
353 }
354 }
355 }
356}
357
9ac91920 358//____________________________________________________________________________
359void AliQADataMakerRec::ResetDetector(AliQAv1::TASKINDEX_t task)
360{
92664bc8 361 // default reset that resets all the QA objects.
362 // to be overloaded by detectors, if necessary
9ac91920 363
364 TObjArray ** list = NULL ;
365 if ( task == AliQAv1::kRAWS ) {
92664bc8 366 list = fRawsQAList ;
367 } else if ( task == AliQAv1::kDIGITSR ) {
368 list = fDigitsQAList ;
369 } else if ( task == AliQAv1::kRECPOINTS ) {
370 list = fRecPointsQAList ;
371 } else if ( task == AliQAv1::kESDS ) {
372 list = fESDsQAList ;
373 }
374 //list was not initialized, skip
b68870b9 375 if (!list) return;
9ac91920 376
377 for (int spec = 0; spec < AliRecoParam::kNSpecies; spec++) {
92664bc8 378 if (!AliQAv1::Instance()->IsEventSpecieSet(AliRecoParam::ConvertIndex(spec))) continue;
9ac91920 379 TIter next(list[spec]) ;
92664bc8 380 TObject *obj = NULL;
381 while ( (obj = next()) ) {
382 if (obj->TestBit(AliQAv1::GetClonedBit())) { // this is array of cloned histos
383 TObjArray* arr = (TObjArray*)obj;
384 for (int ih=arr->GetEntriesFast();ih--;) {
385 TH1* histo = (TH1*)arr->At(ih);
b68870b9 386 if (!histo) continue;
92664bc8 387 histo->Reset("ICE");
388 histo->ResetStats();
389 }
390 }
391 else {
392 ((TH1*)obj)->Reset("ICE");
393 ((TH1*)obj)->ResetStats();
394 }
9ac91920 395 }
92664bc8 396 ResetEvCountCycle(AliRecoParam::ConvertIndex(spec));
397 ResetEvCountTotal(AliRecoParam::ConvertIndex(spec));
9ac91920 398 }
399}
400
fb6e511e 401//____________________________________________________________________________
930e6e3e 402void AliQADataMakerRec::StartOfCycle(Int_t run)
403{
404 // Finishes a cycle of QA for all the tasks
405 Bool_t samecycle = kFALSE ;
4e25ac79 406 StartOfCycle(AliQAv1::kRAWS, run, samecycle) ;
930e6e3e 407 samecycle = kTRUE ;
44ed7a66 408 StartOfCycle(AliQAv1::kDIGITSR, run, samecycle) ;
4e25ac79 409 StartOfCycle(AliQAv1::kRECPOINTS, run, samecycle) ;
92664bc8 410 StartOfCycle(AliQAv1::kESDS, run, samecycle) ;
930e6e3e 411}
412
413//____________________________________________________________________________
4e25ac79 414void AliQADataMakerRec::StartOfCycle(AliQAv1::TASKINDEX_t task, Int_t run, const Bool_t sameCycle)
04236e67 415{
416 // Finishes a cycle of QA data acquistion
92664bc8 417 if ( run > 0 ) fRun = run ;
418 if ( !sameCycle || fCurrentCycle == -1) {
419 ResetCycle() ;
420 if (fOutput)
421 fOutput->Close() ;
422 if (AliQAManager::QAManager(AliQAv1::kRECMODE)->IsSaveData())
50dee02c 423 fOutput = AliQAv1::GetQADataFile(GetName(), fRun) ;
92664bc8 424 }
2ad98fc5 425 if (AliQAManager::QAManager(AliQAv1::kRECMODE)->IsSaveData())
426 AliDebug(AliQAv1::GetQADebugLevel(), Form(" Run %d Cycle %d task %s file %s",
92664bc8 427 fRun, fCurrentCycle, AliQAv1::GetTaskName(task).Data(), fOutput->GetName() )) ;
2ad98fc5 428 else
429 AliDebug(AliQAv1::GetQADebugLevel(), Form(" Run %d Cycle %d task %s not saved",
430 fRun, fCurrentCycle, AliQAv1::GetTaskName(task).Data() )) ;
92664bc8 431
432 // fDetectorDir = fOutput->GetDirectory(GetDetectorDirName()) ;
433 // if (!fDetectorDir)
434 // fDetectorDir = fOutput->mkdir(GetDetectorDirName()) ;
435 //
436 // TDirectory * subDir = fDetectorDir->GetDirectory(AliQAv1::GetTaskName(task)) ;
437 // if (!subDir)
438 // subDir = fDetectorDir->mkdir(AliQAv1::GetTaskName(task)) ;
439 //
440 // for ( Int_t specie = AliRecoParam::kDefault ; specie < AliRecoParam::kNSpecies ; specie++ ) {
441 // TDirectory * eventSpecieDir = subDir->GetDirectory(AliRecoParam::GetEventSpecieName(specie)) ;
442 // if (!eventSpecieDir)
443 // eventSpecieDir = subDir->mkdir(AliRecoParam::GetEventSpecieName(specie)) ;
444 // TDirectory * expertDir = eventSpecieDir->GetDirectory(AliQAv1::GetExpert()) ;
445 // if (!expertDir)
446 // expertDir = eventSpecieDir->mkdir(AliQAv1::GetExpert()) ;
447 // }
448 StartOfDetectorCycle();
449 ResetEvCountCycle();
450}
04236e67 451
92664bc8 452//____________________________________________________________________________
453void AliQADataMakerRec::ClonePerTrigClass(AliQAv1::TASKINDEX_t task)
454{
455 // clone the histos of the array corresponding to task
456 switch (task)
457 {
458 case AliQAv1::kRAWS : ClonePerTrigClassL(fRawsQAList, task); break;
459 case AliQAv1::kDIGITS : ClonePerTrigClassL(fDigitsQAList, task); break;
460 case AliQAv1::kRECPOINTS : ClonePerTrigClassL(fRecPointsQAList, task); break;
461 case AliQAv1::kESDS : ClonePerTrigClassL(fESDsQAList, task); break;
462 default : AliError(Form("Task %s is invalid in this context", AliQAv1::GetTaskName(task).Data() )); break;
463 }
464 //
04236e67 465}