fixed typo for setting fraction of shared clusters
[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 ---
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) :
50 AliQADataMaker(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
60 fDetectorDirName = GetName() ;
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
75 SetName(qadm.GetName()) ;
76 SetTitle(qadm.GetTitle()) ;
77 fDetectorDirName = GetName() ;
78}
79
63c6f8ae 80//____________________________________________________________________________
81AliQADataMakerRec::~AliQADataMakerRec()
82{
83 //dtor: delete the TObjArray and thei content
7ff8385d 84 if ( fESDsQAList ) {
57acd2d2 85 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
86 if ( fESDsQAList[specie] ) {
57acd2d2 87 fESDsQAList[specie]->Delete() ;
88 }
89 }
90 delete[] fESDsQAList ;
7ff8385d 91 }
92 if ( fRawsQAList ) {
57acd2d2 93 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
94 if ( fRawsQAList[specie] ) {
2f9129dd 95 fRawsQAList[specie]->Delete() ;
57acd2d2 96 }
97 }
98 delete[] fRawsQAList ;
99 }
44ed7a66 100 if ( fDigitsQAList ) {
101 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
102 if ( fDigitsQAList[specie] ) {
2f9129dd 103 fDigitsQAList[specie]->Delete() ;
44ed7a66 104 }
105 }
106 delete[] fDigitsQAList ;
107 }
7ff8385d 108 if ( fRecPointsQAList ) {
57acd2d2 109 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
110 if ( fRecPointsQAList[specie] ) {
2f9129dd 111 fRecPointsQAList[specie]->Delete() ;
57acd2d2 112 }
113 }
114 delete[] fRecPointsQAList ;
eca4fa66 115 }
6252ceeb 116 if (fRecPointsArray) {
117 fRecPointsArray->Clear() ;
118 delete fRecPointsArray ;
119 }
63c6f8ae 120}
121
04236e67 122//__________________________________________________________________
123AliQADataMakerRec& AliQADataMakerRec::operator = (const AliQADataMakerRec& qadm )
124{
125 // Assignment operator.
126 this->~AliQADataMakerRec();
127 new(this) AliQADataMakerRec(qadm);
128 return *this;
129}
130
131//____________________________________________________________________________
930e6e3e 132void AliQADataMakerRec::EndOfCycle()
133{
134 // Finishes a cycle of QA for all the tasks
4e25ac79 135 EndOfCycle(AliQAv1::kRAWS) ;
44ed7a66 136 EndOfCycle(AliQAv1::kDIGITSR) ;
4e25ac79 137 EndOfCycle(AliQAv1::kRECPOINTS) ;
138 EndOfCycle(AliQAv1::kESDS) ;
930e6e3e 139 ResetCycle() ;
140}
141
142//____________________________________________________________________________
4e25ac79 143void AliQADataMakerRec::EndOfCycle(AliQAv1::TASKINDEX_t task)
04236e67 144{
930e6e3e 145 // Finishes a cycle of QA
04236e67 146
ea5df941 147
148 TObjArray ** list = NULL ;
04236e67 149
4e25ac79 150 if ( task == AliQAv1::kRAWS )
04236e67 151 list = fRawsQAList ;
44ed7a66 152 else if ( task == AliQAv1::kDIGITSR )
153 list = fDigitsQAList ;
4e25ac79 154 else if ( task == AliQAv1::kRECPOINTS )
04236e67 155 list = fRecPointsQAList ;
4e25ac79 156 else if ( task == AliQAv1::kESDS )
04236e67 157 list = fESDsQAList ;
7c002d48 158
930e6e3e 159
57acd2d2 160 if ( ! list && ! fCorrNt )
930e6e3e 161 return ;
162 //DefaultEndOfDetectorCycle(task) ;
0774e4a4 163 EndOfDetectorCycle(task, list) ;
50dee02c 164
ea5df941 165 if (! AliQAManager::QAManager(AliQAv1::kRECMODE)->IsSaveData())
166 return ;
167
eca4fa66 168 fDetectorDir = fOutput->GetDirectory(GetDetectorDirName()) ;
169 if (!fDetectorDir)
170 fDetectorDir = fOutput->mkdir(GetDetectorDirName()) ;
171 TDirectory * subDir = fDetectorDir->GetDirectory(AliQAv1::GetTaskName(task)) ;
172 if (!subDir)
173 subDir = fDetectorDir->mkdir(AliQAv1::GetTaskName(task)) ;
174 subDir->cd() ;
6252ceeb 175 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) { // skip Default
176 if (! AliQAv1::Instance(AliQAv1::GetDetIndex(GetName()))->IsEventSpecieSet(AliRecoParam::ConvertIndex(specie)) || AliRecoParam::ConvertIndex(specie) == AliRecoParam::kDefault)
eca4fa66 177 continue ;
7822bb76 178 TDirectory * eventSpecieDir = subDir->GetDirectory(AliRecoParam::GetEventSpecieName(specie)) ;
179 if (!eventSpecieDir)
180 eventSpecieDir = subDir->mkdir(AliRecoParam::GetEventSpecieName(specie)) ;
181 eventSpecieDir->cd() ;
af65f4c8 182 if (list) {
183 if (list[specie]) {
184 TIter next(list[specie]) ;
185 TObject * obj ;
eca4fa66 186 while( (obj = next()) ) {
187 if (!obj->TestBit(AliQAv1::GetExpertBit()))
af65f4c8 188 obj->Write() ;
189 }
190 if (WriteExpert()) {
191 TDirectory * expertDir = eventSpecieDir->GetDirectory(AliQAv1::GetExpert()) ;
192 if (!expertDir)
193 expertDir = eventSpecieDir->mkdir(AliQAv1::GetExpert()) ;
194 expertDir->cd() ;
195 next.Reset() ;
196 while( (obj = next()) ) {
197 if (!obj->TestBit(AliQAv1::GetExpertBit()))
198 continue ;
199 obj->Write() ;
200 }
201 }
eca4fa66 202 }
af65f4c8 203 }
204 else if ( fCorrNt ) {
205 if (fCorrNt[specie] && AliQAv1::GetDetIndex(GetName()) == AliQAv1::kCORR) {
ddfe5350 206 if (fCorrNt[specie]->GetNvar() != 0) {
207 eventSpecieDir->cd() ;
208 fCorrNt[specie]->Write() ;
209 }
af65f4c8 210 }
211 fOutput->Save() ;
7822bb76 212 }
eca4fa66 213 }
7d297381 214}
215
04236e67 216//____________________________________________________________________________
4e25ac79 217void AliQADataMakerRec::Exec(AliQAv1::TASKINDEX_t task, TObject * data)
04236e67 218{
219 // creates the quality assurance data for the various tasks (Hits, SDigits, Digits, ESDs)
220
4e25ac79 221 if ( task == AliQAv1::kRAWS ) {
5379c4a3 222 AliDebug(AliQAv1::GetQADebugLevel(), "Processing Raws QA") ;
eca4fa66 223 AliRawReader * rawReader = static_cast<AliRawReader *>(data) ;
04236e67 224 if (rawReader)
225 MakeRaws(rawReader) ;
226 else
5379c4a3 227 AliDebug(AliQAv1::GetQADebugLevel(), "Raw data are not processed") ;
44ed7a66 228 } else if ( task == AliQAv1::kDIGITSR ) {
229 AliDebug(AliQAv1::GetQADebugLevel(), "Processing Digits QA") ;
eca4fa66 230 TTree * tree = static_cast<TTree *>(data) ;
231 if (strcmp(tree->ClassName(), "TTree") == 0) {
44ed7a66 232 MakeDigits(tree) ;
233 } else {
234 AliWarning("data are not a TTree") ;
235 }
4e25ac79 236 } else if ( task == AliQAv1::kRECPOINTS ) {
5379c4a3 237 AliDebug(AliQAv1::GetQADebugLevel(), "Processing RecPoints QA") ;
eca4fa66 238 TTree * tree = static_cast<TTree *>(data) ;
239 if (strcmp(tree->ClassName(), "TTree") == 0) {
04236e67 240 MakeRecPoints(tree) ;
241 } else {
242 AliWarning("data are not a TTree") ;
243 }
4e25ac79 244 } else if ( task == AliQAv1::kESDS ) {
5379c4a3 245 AliDebug(AliQAv1::GetQADebugLevel(), "Processing ESDs QA") ;
eca4fa66 246 AliESDEvent * esd = static_cast<AliESDEvent *>(data) ;
247 if (strcmp(esd->ClassName(), "AliESDEvent") == 0)
04236e67 248 MakeESDs(esd) ;
249 else
250 AliError("Wrong type of esd container") ;
251 }
252}
253
254//____________________________________________________________________________
4e25ac79 255TObjArray ** AliQADataMakerRec::Init(AliQAv1::TASKINDEX_t task, Int_t cycles)
04236e67 256{
257 // general intialisation
fb6e511e 258 InitRecoParams() ;
57acd2d2 259 TObjArray ** rv = NULL ;
04236e67 260
04236e67 261 if (cycles > 0)
262 SetCycle(cycles) ;
263
4e25ac79 264 if ( task == AliQAv1::kRAWS ) {
63c6f8ae 265 if (! fRawsQAList ) {
57acd2d2 266 fRawsQAList = new TObjArray *[AliRecoParam::kNSpecies] ;
267 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
49466ea2 268 fRawsQAList[specie] = new TObjArray(AliQAv1::GetMaxQAObj()) ;
4e25ac79 269 fRawsQAList[specie]->SetName(Form("%s_%s_%s", GetName(), AliQAv1::GetTaskName(task).Data(), AliRecoParam::GetEventSpecieName(specie))) ;
57acd2d2 270 }
63c6f8ae 271 }
04236e67 272 rv = fRawsQAList ;
44ed7a66 273 } else if ( task == AliQAv1::kDIGITSR ) {
274 if ( ! fDigitsQAList ) {
275 fDigitsQAList = new TObjArray *[AliRecoParam::kNSpecies] ;
276 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
49466ea2 277 fDigitsQAList[specie] = new TObjArray(AliQAv1::GetMaxQAObj()) ;
44ed7a66 278 fDigitsQAList[specie]->SetName(Form("%s_%s_%s", GetName(), AliQAv1::GetTaskName(task).Data(), AliRecoParam::GetEventSpecieName(specie))) ;
279 }
44ed7a66 280 }
281 rv = fDigitsQAList ;
4e25ac79 282 } else if ( task == AliQAv1::kRECPOINTS ) {
63c6f8ae 283 if ( ! fRecPointsQAList ) {
57acd2d2 284 fRecPointsQAList = new TObjArray *[AliRecoParam::kNSpecies] ;
285 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
49466ea2 286 fRecPointsQAList[specie] = new TObjArray(AliQAv1::GetMaxQAObj()) ;
4e25ac79 287 fRecPointsQAList[specie]->SetName(Form("%s_%s_%s", GetName(), AliQAv1::GetTaskName(task).Data(), AliRecoParam::GetEventSpecieName(specie))) ;
57acd2d2 288 }
eca4fa66 289 }
04236e67 290 rv = fRecPointsQAList ;
4e25ac79 291 } else if ( task == AliQAv1::kESDS ) {
63c6f8ae 292 if ( ! fESDsQAList ) {
57acd2d2 293 fESDsQAList = new TObjArray *[AliRecoParam::kNSpecies] ;
294 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
49466ea2 295 fESDsQAList[specie] = new TObjArray(AliQAv1::GetMaxQAObj()) ;
65b25288 296 fESDsQAList[specie]->SetName(Form("%s_%s", GetName(), AliQAv1::GetTaskName(task).Data())); //, AliRecoParam::GetEventSpecieName(specie))) ;
57acd2d2 297 }
63c6f8ae 298 }
04236e67 299 rv = fESDsQAList ;
300 }
04236e67 301 return rv ;
302}
303
304//____________________________________________________________________________
4e25ac79 305void AliQADataMakerRec::Init(AliQAv1::TASKINDEX_t task, TObjArray ** list, Int_t run, Int_t cycles)
04236e67 306{
307 // Intialisation by passing the list of QA data booked elsewhere
308
fb6e511e 309 InitRecoParams() ;
310 fRun = run ;
04236e67 311 if (cycles > 0)
312 SetCycle(cycles) ;
313
4e25ac79 314 if ( task == AliQAv1::kRAWS ) {
04236e67 315 fRawsQAList = list ;
44ed7a66 316 } else if ( task == AliQAv1::kDIGITSR ) {
317 fDigitsQAList = list ;
4e25ac79 318 } else if ( task == AliQAv1::kRECPOINTS ) {
04236e67 319 fRecPointsQAList = list ;
4e25ac79 320 } else if ( task == AliQAv1::kESDS ) {
04236e67 321 fESDsQAList = list ;
322 }
323}
324
325//____________________________________________________________________________
fb6e511e 326void AliQADataMakerRec::InitRecoParams()
327{
f14c8c46 328 // Get the recoparam form the OCDB
fb6e511e 329 if (!fRecoParam) {
5379c4a3 330 AliDebug(AliQAv1::GetQADebugLevel(), Form("Loading reconstruction parameter objects for detector %s", GetName()));
fb6e511e 331 AliCDBPath path(GetName(),"Calib","RecoParam");
332 AliCDBEntry *entry=AliCDBManager::Instance()->Get(path.GetPath());
333 if(!entry) {
334 fRecoParam = NULL ;
55e356ec 335 AliDebug(AliQAv1::GetQADebugLevel(), Form("Couldn't find RecoParam entry in OCDB for detector %s",GetName()));
fb6e511e 336 }
337 else {
338 TObject * recoParamObj = entry->GetObject() ;
eca4fa66 339 if ( strcmp(recoParamObj->ClassName(), "TObjArray") == 0 ) {
42383dda 340 // The detector has only one set of reco parameters
5379c4a3 341 AliDebug(AliQAv1::GetQADebugLevel(), Form("Array of reconstruction parameters found for detector %s",GetName()));
eca4fa66 342 TObjArray *recoParamArray = static_cast<TObjArray*>(recoParamObj) ;
42383dda 343 for (Int_t iRP=0; iRP<recoParamArray->GetEntriesFast(); iRP++) {
eca4fa66 344 fRecoParam = static_cast<AliDetectorRecoParam*>(recoParamArray->At(iRP)) ;
345 if (!fRecoParam)
346 break ;
347 else if (fRecoParam->IsDefault())
348 break ;
42383dda 349 }
350 }
eca4fa66 351 else if (recoParamObj->InheritsFrom("AliDetectorRecoParam")) {
352 // The detector has only one set of reco parameters
fb6e511e 353 // Registering it in AliRecoParam
5379c4a3 354 AliDebug(AliQAv1::GetQADebugLevel(), Form("Single set of reconstruction parameters found for detector %s",GetName()));
eca4fa66 355 fRecoParam = static_cast<AliDetectorRecoParam*>(recoParamObj) ;
356 static_cast<AliDetectorRecoParam*>(recoParamObj)->SetAsDefault();
fb6e511e 357 } else {
358 AliError(Form("No valid RecoParam object found in the OCDB for detector %s",GetName()));
359 }
360 }
361 }
362}
363
9ac91920 364//____________________________________________________________________________
365void AliQADataMakerRec::ResetDetector(AliQAv1::TASKINDEX_t task)
366{
367 // default reset that resets all the QA objects.
368 // to be overloaded by detectors, if necessary
369
370 TObjArray ** list = NULL ;
371 if ( task == AliQAv1::kRAWS ) {
372 list = fRawsQAList ;
373 } else if ( task == AliQAv1::kDIGITSR ) {
374 list = fDigitsQAList ;
375 } else if ( task == AliQAv1::kRECPOINTS ) {
376 list = fRecPointsQAList ;
377 } else if ( task == AliQAv1::kESDS ) {
378 list = fESDsQAList ;
379 }
380 //list was not initialized, skip
381 if (!list)
382 return ;
383
384 for (int spec = 0; spec < AliRecoParam::kNSpecies; spec++) {
385 if (!AliQAv1::Instance()->IsEventSpecieSet(AliRecoParam::ConvertIndex(spec)))
386 continue;
387 TIter next(list[spec]) ;
388 TH1 * histo = NULL ;
389 while ( (histo = dynamic_cast<TH1*> (next())) ) {
3d08fd77 390 histo->Reset("ICE") ;
fc6a0539 391 histo->ResetStats() ;
9ac91920 392 }
393 }
394}
395
fb6e511e 396//____________________________________________________________________________
930e6e3e 397void AliQADataMakerRec::StartOfCycle(Int_t run)
398{
399 // Finishes a cycle of QA for all the tasks
400 Bool_t samecycle = kFALSE ;
4e25ac79 401 StartOfCycle(AliQAv1::kRAWS, run, samecycle) ;
930e6e3e 402 samecycle = kTRUE ;
44ed7a66 403 StartOfCycle(AliQAv1::kDIGITSR, run, samecycle) ;
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() ;
50dee02c 418 if (AliQAManager::QAManager(AliQAv1::kRECMODE)->IsSaveData())
419 fOutput = AliQAv1::GetQADataFile(GetName(), fRun) ;
04236e67 420 }
5379c4a3 421 AliDebug(AliQAv1::GetQADebugLevel(), Form(" Run %d Cycle %d task %s file %s",
4e25ac79 422 fRun, fCurrentCycle, AliQAv1::GetTaskName(task).Data(), fOutput->GetName() )) ;
04236e67 423
eca4fa66 424// fDetectorDir = fOutput->GetDirectory(GetDetectorDirName()) ;
425// if (!fDetectorDir)
426// fDetectorDir = fOutput->mkdir(GetDetectorDirName()) ;
427//
428// TDirectory * subDir = fDetectorDir->GetDirectory(AliQAv1::GetTaskName(task)) ;
429// if (!subDir)
430// subDir = fDetectorDir->mkdir(AliQAv1::GetTaskName(task)) ;
431//
432// for ( Int_t specie = AliRecoParam::kDefault ; specie < AliRecoParam::kNSpecies ; specie++ ) {
433// TDirectory * eventSpecieDir = subDir->GetDirectory(AliRecoParam::GetEventSpecieName(specie)) ;
434// if (!eventSpecieDir)
435// eventSpecieDir = subDir->mkdir(AliRecoParam::GetEventSpecieName(specie)) ;
436// TDirectory * expertDir = eventSpecieDir->GetDirectory(AliQAv1::GetExpert()) ;
437// if (!expertDir)
438// expertDir = eventSpecieDir->mkdir(AliQAv1::GetExpert()) ;
439// }
04236e67 440 StartOfDetectorCycle() ;
441}