Warnings corrected.
[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 ;
eca4fa66 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) ;
eca4fa66 161 fDetectorDir = fOutput->GetDirectory(GetDetectorDirName()) ;
162 if (!fDetectorDir)
163 fDetectorDir = fOutput->mkdir(GetDetectorDirName()) ;
164 TDirectory * subDir = fDetectorDir->GetDirectory(AliQAv1::GetTaskName(task)) ;
165 if (!subDir)
166 subDir = fDetectorDir->mkdir(AliQAv1::GetTaskName(task)) ;
167 subDir->cd() ;
168 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
169 if (! AliQAv1::Instance(AliQAv1::GetDetIndex(GetName()))->IsEventSpecieSet(AliRecoParam::ConvertIndex(specie)) )
170 continue ;
171 TDirectory * eventSpecieDir = subDir->GetDirectory(AliRecoParam::GetEventSpecieName(specie)) ;
172 if (!eventSpecieDir)
173 eventSpecieDir = subDir->mkdir(AliRecoParam::GetEventSpecieName(specie)) ;
174 eventSpecieDir->cd() ;
175 if (list[specie]) {
176 TIter next(list[specie]) ;
177 TObject * obj ;
178 while( (obj = next()) ) {
179 if (!obj->TestBit(AliQAv1::GetExpertBit()))
180 obj->Write() ;
6e65319c 181 }
eca4fa66 182 if (WriteExpert()) {
183 TDirectory * expertDir = eventSpecieDir->GetDirectory(AliQAv1::GetExpert()) ;
184 if (!expertDir)
185 expertDir = eventSpecieDir->mkdir(AliQAv1::GetExpert()) ;
186 expertDir->cd() ;
187 next.Reset() ;
188 while( (obj = next()) ) {
189 if (!obj->TestBit(AliQAv1::GetExpertBit()))
190 continue ;
191 obj->Write() ;
192 }
193 }
194 }
195 if ( !fCorrNt )
196 continue ;
197 if (fCorrNt[specie] && AliQAv1::GetDetIndex(GetName()) == AliQAv1::kCORR) {
198 eventSpecieDir->cd() ;
199 fCorrNt[specie]->Write() ;
6e65319c 200 }
a595ac34 201 fOutput->Save() ;
eca4fa66 202 }
203 MakeImage(task) ;
04236e67 204}
7d297381 205
206//____________________________________________________________________________
207void AliQADataMakerRec::MakeImage(AliQAv1::TASKINDEX_t task)
208{
209 // create a drawing of detetor defined histograms
210 TObjArray ** list = NULL ;
211 switch (task) {
212 case AliQAv1::kRAWS:
213 list = fRawsQAList ;
214 break;
215 case AliQAv1::kHITS:
216 break;
217 case AliQAv1::kSDIGITS:
218 break;
219 case AliQAv1::kDIGITS:
220 break;
44ed7a66 221 case AliQAv1::kDIGITSR:
222 list = fDigitsQAList ;
223 break;
7d297381 224 case AliQAv1::kRECPOINTS:
225 list = fRecPointsQAList ;
226 break;
227 case AliQAv1::kTRACKSEGMENTS:
228 break;
229 case AliQAv1::kRECPARTICLES:
230 break;
231 case AliQAv1::kESDS:
232 list = fESDsQAList ;
233 break;
234 case AliQAv1::kNTASKINDEX:
235 break;
236 default:
237 break;
238 }
239 if ( !list) {
240 AliError("data not initialized, call AliQADataMaker::Init");
241 return ;
242 }
fec0891b 243 MakeTheImage(list, task, "Rec") ;
7d297381 244}
245
04236e67 246//____________________________________________________________________________
4e25ac79 247void AliQADataMakerRec::Exec(AliQAv1::TASKINDEX_t task, TObject * data)
04236e67 248{
249 // creates the quality assurance data for the various tasks (Hits, SDigits, Digits, ESDs)
250
4e25ac79 251 if ( task == AliQAv1::kRAWS ) {
5379c4a3 252 AliDebug(AliQAv1::GetQADebugLevel(), "Processing Raws QA") ;
eca4fa66 253 AliRawReader * rawReader = static_cast<AliRawReader *>(data) ;
04236e67 254 if (rawReader)
255 MakeRaws(rawReader) ;
256 else
5379c4a3 257 AliDebug(AliQAv1::GetQADebugLevel(), "Raw data are not processed") ;
44ed7a66 258 } else if ( task == AliQAv1::kDIGITSR ) {
259 AliDebug(AliQAv1::GetQADebugLevel(), "Processing Digits QA") ;
eca4fa66 260 TTree * tree = static_cast<TTree *>(data) ;
261 if (strcmp(tree->ClassName(), "TTree") == 0) {
44ed7a66 262 MakeDigits(tree) ;
263 } else {
264 AliWarning("data are not a TTree") ;
265 }
4e25ac79 266 } else if ( task == AliQAv1::kRECPOINTS ) {
5379c4a3 267 AliDebug(AliQAv1::GetQADebugLevel(), "Processing RecPoints QA") ;
eca4fa66 268 TTree * tree = static_cast<TTree *>(data) ;
269 if (strcmp(tree->ClassName(), "TTree") == 0) {
04236e67 270 MakeRecPoints(tree) ;
271 } else {
272 AliWarning("data are not a TTree") ;
273 }
4e25ac79 274 } else if ( task == AliQAv1::kESDS ) {
5379c4a3 275 AliDebug(AliQAv1::GetQADebugLevel(), "Processing ESDs QA") ;
eca4fa66 276 AliESDEvent * esd = static_cast<AliESDEvent *>(data) ;
277 if (strcmp(esd->ClassName(), "AliESDEvent") == 0)
04236e67 278 MakeESDs(esd) ;
279 else
280 AliError("Wrong type of esd container") ;
281 }
282}
283
284//____________________________________________________________________________
4e25ac79 285TObjArray ** AliQADataMakerRec::Init(AliQAv1::TASKINDEX_t task, Int_t cycles)
04236e67 286{
287 // general intialisation
fb6e511e 288 InitRecoParams() ;
57acd2d2 289 TObjArray ** rv = NULL ;
04236e67 290
04236e67 291 if (cycles > 0)
292 SetCycle(cycles) ;
293
4e25ac79 294 if ( task == AliQAv1::kRAWS ) {
63c6f8ae 295 if (! fRawsQAList ) {
57acd2d2 296 fRawsQAList = new TObjArray *[AliRecoParam::kNSpecies] ;
297 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
eca4fa66 298 fRawsQAList[specie] = new TObjArray(1) ;
4e25ac79 299 fRawsQAList[specie]->SetName(Form("%s_%s_%s", GetName(), AliQAv1::GetTaskName(task).Data(), AliRecoParam::GetEventSpecieName(specie))) ;
57acd2d2 300 }
63c6f8ae 301 }
04236e67 302 rv = fRawsQAList ;
44ed7a66 303 } else if ( task == AliQAv1::kDIGITSR ) {
304 if ( ! fDigitsQAList ) {
305 fDigitsQAList = new TObjArray *[AliRecoParam::kNSpecies] ;
306 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
eca4fa66 307 fDigitsQAList[specie] = new TObjArray(1) ;
44ed7a66 308 fDigitsQAList[specie]->SetName(Form("%s_%s_%s", GetName(), AliQAv1::GetTaskName(task).Data(), AliRecoParam::GetEventSpecieName(specie))) ;
309 }
44ed7a66 310 }
311 rv = fDigitsQAList ;
4e25ac79 312 } else if ( task == AliQAv1::kRECPOINTS ) {
63c6f8ae 313 if ( ! fRecPointsQAList ) {
57acd2d2 314 fRecPointsQAList = new TObjArray *[AliRecoParam::kNSpecies] ;
315 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
eca4fa66 316 fRecPointsQAList[specie] = new TObjArray(1) ;
4e25ac79 317 fRecPointsQAList[specie]->SetName(Form("%s_%s_%s", GetName(), AliQAv1::GetTaskName(task).Data(), AliRecoParam::GetEventSpecieName(specie))) ;
57acd2d2 318 }
eca4fa66 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++) {
eca4fa66 325 fESDsQAList[specie] = new TObjArray(1) ;
4e25ac79 326 fESDsQAList[specie]->SetName(Form("%s_%s", GetName(), AliQAv1::GetTaskName(task).Data(), AliRecoParam::GetEventSpecieName(specie))) ;
57acd2d2 327 }
63c6f8ae 328 }
04236e67 329 rv = fESDsQAList ;
330 }
04236e67 331 return rv ;
332}
333
334//____________________________________________________________________________
4e25ac79 335void AliQADataMakerRec::Init(AliQAv1::TASKINDEX_t task, TObjArray ** list, Int_t run, Int_t cycles)
04236e67 336{
337 // Intialisation by passing the list of QA data booked elsewhere
338
fb6e511e 339 InitRecoParams() ;
340 fRun = run ;
04236e67 341 if (cycles > 0)
342 SetCycle(cycles) ;
343
4e25ac79 344 if ( task == AliQAv1::kRAWS ) {
04236e67 345 fRawsQAList = list ;
44ed7a66 346 } else if ( task == AliQAv1::kDIGITSR ) {
347 fDigitsQAList = list ;
4e25ac79 348 } else if ( task == AliQAv1::kRECPOINTS ) {
04236e67 349 fRecPointsQAList = list ;
4e25ac79 350 } else if ( task == AliQAv1::kESDS ) {
04236e67 351 fESDsQAList = list ;
352 }
353}
354
355//____________________________________________________________________________
fb6e511e 356void AliQADataMakerRec::InitRecoParams()
357{
358 if (!fRecoParam) {
5379c4a3 359 AliDebug(AliQAv1::GetQADebugLevel(), Form("Loading reconstruction parameter objects for detector %s", GetName()));
fb6e511e 360 AliCDBPath path(GetName(),"Calib","RecoParam");
361 AliCDBEntry *entry=AliCDBManager::Instance()->Get(path.GetPath());
362 if(!entry) {
363 fRecoParam = NULL ;
364 AliWarning(Form("Couldn't find RecoParam entry in OCDB for detector %s",GetName()));
365 }
366 else {
367 TObject * recoParamObj = entry->GetObject() ;
eca4fa66 368 if ( strcmp(recoParamObj->ClassName(), "TObjArray") == 0 ) {
42383dda 369 // The detector has only one set of reco parameters
5379c4a3 370 AliDebug(AliQAv1::GetQADebugLevel(), Form("Array of reconstruction parameters found for detector %s",GetName()));
eca4fa66 371 TObjArray *recoParamArray = static_cast<TObjArray*>(recoParamObj) ;
42383dda 372 for (Int_t iRP=0; iRP<recoParamArray->GetEntriesFast(); iRP++) {
eca4fa66 373 fRecoParam = static_cast<AliDetectorRecoParam*>(recoParamArray->At(iRP)) ;
374 if (!fRecoParam)
375 break ;
376 else if (fRecoParam->IsDefault())
377 break ;
42383dda 378 }
379 }
eca4fa66 380 else if (recoParamObj->InheritsFrom("AliDetectorRecoParam")) {
381 // The detector has only one set of reco parameters
fb6e511e 382 // Registering it in AliRecoParam
5379c4a3 383 AliDebug(AliQAv1::GetQADebugLevel(), Form("Single set of reconstruction parameters found for detector %s",GetName()));
eca4fa66 384 fRecoParam = static_cast<AliDetectorRecoParam*>(recoParamObj) ;
385 static_cast<AliDetectorRecoParam*>(recoParamObj)->SetAsDefault();
fb6e511e 386 } else {
387 AliError(Form("No valid RecoParam object found in the OCDB for detector %s",GetName()));
388 }
389 }
42383dda 390 AliCDBManager::Instance()->UnloadFromCache(path.GetPath());
fb6e511e 391 }
392}
393
394//____________________________________________________________________________
930e6e3e 395void AliQADataMakerRec::StartOfCycle(Int_t run)
396{
397 // Finishes a cycle of QA for all the tasks
398 Bool_t samecycle = kFALSE ;
4e25ac79 399 StartOfCycle(AliQAv1::kRAWS, run, samecycle) ;
930e6e3e 400 samecycle = kTRUE ;
44ed7a66 401 StartOfCycle(AliQAv1::kDIGITSR, run, samecycle) ;
4e25ac79 402 StartOfCycle(AliQAv1::kRECPOINTS, run, samecycle) ;
403 StartOfCycle(AliQAv1::kESDS, run, samecycle) ;
930e6e3e 404}
405
406//____________________________________________________________________________
4e25ac79 407void AliQADataMakerRec::StartOfCycle(AliQAv1::TASKINDEX_t task, Int_t run, const Bool_t sameCycle)
04236e67 408{
409 // Finishes a cycle of QA data acquistion
930e6e3e 410 if ( run > 0 )
411 fRun = run ;
04236e67 412 if ( !sameCycle || fCurrentCycle == -1) {
413 ResetCycle() ;
414 if (fOutput)
415 fOutput->Close() ;
4e25ac79 416 fOutput = AliQAv1::GetQADataFile(GetName(), fRun) ;
04236e67 417 }
5379c4a3 418 AliDebug(AliQAv1::GetQADebugLevel(), Form(" Run %d Cycle %d task %s file %s",
4e25ac79 419 fRun, fCurrentCycle, AliQAv1::GetTaskName(task).Data(), fOutput->GetName() )) ;
04236e67 420
eca4fa66 421// fDetectorDir = fOutput->GetDirectory(GetDetectorDirName()) ;
422// if (!fDetectorDir)
423// fDetectorDir = fOutput->mkdir(GetDetectorDirName()) ;
424//
425// TDirectory * subDir = fDetectorDir->GetDirectory(AliQAv1::GetTaskName(task)) ;
426// if (!subDir)
427// subDir = fDetectorDir->mkdir(AliQAv1::GetTaskName(task)) ;
428//
429// for ( Int_t specie = AliRecoParam::kDefault ; specie < AliRecoParam::kNSpecies ; specie++ ) {
430// TDirectory * eventSpecieDir = subDir->GetDirectory(AliRecoParam::GetEventSpecieName(specie)) ;
431// if (!eventSpecieDir)
432// eventSpecieDir = subDir->mkdir(AliRecoParam::GetEventSpecieName(specie)) ;
433// TDirectory * expertDir = eventSpecieDir->GetDirectory(AliQAv1::GetExpert()) ;
434// if (!expertDir)
435// expertDir = eventSpecieDir->mkdir(AliQAv1::GetExpert()) ;
436// }
04236e67 437 StartOfDetectorCycle() ;
438}