]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/STEER/AliQADataMakerRec.cxx
d2acbfbd6d089898418fa331f1e2d52466cf852d
[u/mrichter/AliRoot.git] / STEER / STEER / AliQADataMakerRec.cxx
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   *
10  * copies and that both the copyright notice and this permission notifce   *
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
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 //
25
26 // --- ROOT system ---
27 #include <TFile.h>
28 #include <TTree.h>
29 #include <TNtupleD.h>
30 #include <TObjArray.h>
31
32 // --- Standard library ---
33
34 // --- AliRoot header files ---
35 #include "AliCDBPath.h"
36 #include "AliCDBEntry.h"
37 #include "AliDetectorRecoParam.h"
38 #include "AliCDBManager.h"
39
40 #include "AliLog.h"
41 #include "AliQADataMakerRec.h"
42 #include "AliQAManager.h"
43 #include "AliESDEvent.h"
44 #include "AliRawReader.h"
45
46 ClassImp(AliQADataMakerRec)
47              
48 //____________________________________________________________________________ 
49 AliQADataMakerRec::AliQADataMakerRec(const char * name, const char * title) : 
50 AliQADataMaker(name, title), 
51   fDigitsQAList(NULL),
52   fESDsQAList(NULL), 
53   fRawsQAList(NULL), 
54   fRecPointsQAList(NULL),
55   fCorrNt(NULL), 
56   fRecoParam(NULL),
57   fRecPointsArray(NULL)
58 {
59   // ctor
60   fDetectorDirName = GetName() ; 
61 }
62
63 //____________________________________________________________________________ 
64 AliQADataMakerRec::AliQADataMakerRec(const AliQADataMakerRec& qadm) :
65   AliQADataMaker(qadm.GetName(), qadm.GetTitle()), 
66   fDigitsQAList(qadm.fDigitsQAList),
67   fESDsQAList(qadm.fESDsQAList),
68   fRawsQAList(qadm.fRawsQAList),
69   fRecPointsQAList(qadm.fRecPointsQAList),
70   fCorrNt(qadm.fCorrNt),  
71   fRecoParam(qadm.fRecoParam),
72   fRecPointsArray(NULL)
73 {
74   //copy ctor
75   fDetectorDirName = GetName() ; 
76 }
77
78 //____________________________________________________________________________ 
79 AliQADataMakerRec::~AliQADataMakerRec()
80 {
81   //dtor: delete the TObjArray and thei content
82   if ( fESDsQAList ) {
83     for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
84       if ( fESDsQAList[specie] ) {
85         fESDsQAList[specie]->Delete() ;     
86       }
87     }
88     delete[] fESDsQAList ;
89   }
90   if ( fRawsQAList ) {
91     for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
92       if ( fRawsQAList[specie] ) {
93         fRawsQAList[specie]->Delete() ;
94       }
95     }
96     delete[] fRawsQAList ;
97   }
98   if ( fDigitsQAList ) {
99     for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
100       if ( fDigitsQAList[specie] ) {
101         fDigitsQAList[specie]->Delete() ;
102       }
103     }
104     delete[] fDigitsQAList ; 
105   }
106   if ( fRecPointsQAList ) {
107     for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
108       if ( fRecPointsQAList[specie] ) {
109         fRecPointsQAList[specie]->Delete() ;
110       }
111     }
112     delete[] fRecPointsQAList ; 
113   }
114   if (fRecPointsArray) {
115     fRecPointsArray->Clear() ; 
116     delete fRecPointsArray ; 
117   }
118 }
119
120 //__________________________________________________________________
121 AliQADataMakerRec& AliQADataMakerRec::operator = (const AliQADataMakerRec& qadm )
122 {
123   // Assignment operator.
124   this->~AliQADataMakerRec();
125   new(this) AliQADataMakerRec(qadm);
126   return *this;
127 }
128
129 //____________________________________________________________________________
130 void AliQADataMakerRec::EndOfCycle() 
131 {
132   // Finishes a cycle of QA for all the tasks
133   EndOfCycle(AliQAv1::kRAWS) ; 
134   EndOfCycle(AliQAv1::kDIGITSR) ; 
135   EndOfCycle(AliQAv1::kRECPOINTS) ; 
136   EndOfCycle(AliQAv1::kESDS) ; 
137   ResetCycle() ; 
138 }
139
140 //____________________________________________________________________________
141 void AliQADataMakerRec::EndOfCycle(AliQAv1::TASKINDEX_t task) 
142 {
143   // Finishes a cycle of QA 
144         
145     
146   TObjArray ** list = NULL ; 
147         
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 ; 
156
157  
158   if ( ! list && ! fCorrNt ) 
159     return ; 
160   //DefaultEndOfDetectorCycle(task) ;
161   EndOfDetectorCycle(task, list) ;
162   
163   if (! AliQAManager::QAManager(AliQAv1::kRECMODE)->IsSaveData()) return; 
164
165   fDetectorDir = fOutput->GetDirectory(GetDetectorDirName()) ; 
166   if (!fDetectorDir) fDetectorDir = fOutput->mkdir(GetDetectorDirName()) ; 
167   TDirectory * subDir = fDetectorDir->GetDirectory(AliQAv1::GetTaskName(task)) ; 
168   if (!subDir) subDir = fDetectorDir->mkdir(AliQAv1::GetTaskName(task)) ;  
169   subDir->cd();
170   // 
171   for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) { // skip Default
172     if (! AliQAv1::Instance(AliQAv1::GetDetIndex(GetName()))->IsEventSpecieSet(AliRecoParam::ConvertIndex(specie)) || AliRecoParam::ConvertIndex(specie) == AliRecoParam::kDefault) continue ; 
173     TDirectory * eventSpecieDir = subDir->GetDirectory(AliRecoParam::GetEventSpecieName(specie)) ;
174     if (!eventSpecieDir) eventSpecieDir = subDir->mkdir(AliRecoParam::GetEventSpecieName(specie)) ; 
175     eventSpecieDir->cd();    
176     if (list) {
177       if (list[specie]) {
178         TIter next(list[specie]) ; 
179         TObject * obj ; 
180         while( (obj = next()) ) {
181           if (!obj->TestBit(AliQAv1::GetExpertBit())) obj->Write(); // RS: Note, this can be also TObjArray of clones
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()) ) {
190             if (!obj->TestBit(AliQAv1::GetExpertBit())) continue; 
191             obj->Write();  // RS: Note, this can be also TObjArray of clones
192           }      
193         }
194       }
195     } 
196     else if ( fCorrNt ) {
197       if (fCorrNt[specie] && AliQAv1::GetDetIndex(GetName()) == AliQAv1::kCORR) {
198         if (fCorrNt[specie]->GetNvar() != 0) {
199           eventSpecieDir->cd() ; 
200           fCorrNt[specie]->Write() ; 
201         }
202       }
203       fOutput->Save() ; 
204     }
205   }
206 }
207
208 //____________________________________________________________________________
209 void AliQADataMakerRec::Exec(AliQAv1::TASKINDEX_t task, TObject * data) 
210
211   // creates the quality assurance data for the various tasks (Hits, SDigits, Digits, ESDs)
212         
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
219       AliDebug(AliQAv1::GetQADebugLevel(), "Raw data are not processed") ;     
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   }  
244 }
245
246 //____________________________________________________________________________ 
247 TObjArray **  AliQADataMakerRec::Init(AliQAv1::TASKINDEX_t task, Int_t cycles)
248 {
249   // general intialisation
250   InitRecoParams() ;
251   TObjArray ** rv = NULL ; 
252   
253   if (cycles > 0)
254     SetCycle(cycles) ;  
255         
256   if ( task == AliQAv1::kRAWS ) {
257     if (! fRawsQAList ) { 
258       fRawsQAList = new TObjArray *[AliRecoParam::kNSpecies] ; 
259       for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
260         fRawsQAList[specie] = new TObjArray(AliQAv1::GetMaxQAObj()) ;    
261         fRawsQAList[specie]->SetName(Form("%s_%s_%s", GetName(), AliQAv1::GetTaskName(task).Data(), AliRecoParam::GetEventSpecieName(specie))) ;
262       }
263     }
264     rv = fRawsQAList ;
265   } else if ( task == AliQAv1::kDIGITSR ) {
266     if ( ! fDigitsQAList ) {
267       fDigitsQAList = new TObjArray *[AliRecoParam::kNSpecies] ; 
268       for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
269         fDigitsQAList[specie] = new TObjArray(AliQAv1::GetMaxQAObj()) ; 
270         fDigitsQAList[specie]->SetName(Form("%s_%s_%s", GetName(), AliQAv1::GetTaskName(task).Data(), AliRecoParam::GetEventSpecieName(specie))) ; 
271       }
272     }
273     rv = fDigitsQAList ;
274   } else if ( task == AliQAv1::kRECPOINTS ) {
275     if ( ! fRecPointsQAList ) {
276       fRecPointsQAList = new TObjArray *[AliRecoParam::kNSpecies] ; 
277       for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
278         fRecPointsQAList[specie] = new TObjArray(AliQAv1::GetMaxQAObj()) ; 
279         fRecPointsQAList[specie]->SetName(Form("%s_%s_%s", GetName(), AliQAv1::GetTaskName(task).Data(), AliRecoParam::GetEventSpecieName(specie))) ; 
280       }
281     }
282     rv = fRecPointsQAList ;
283   } else if ( task == AliQAv1::kESDS ) {
284     if ( ! fESDsQAList ) {
285       fESDsQAList = new TObjArray *[AliRecoParam::kNSpecies] ; 
286       for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
287         fESDsQAList[specie] = new TObjArray(AliQAv1::GetMaxQAObj()) ;
288         fESDsQAList[specie]->SetName(Form("%s_%s", GetName(), AliQAv1::GetTaskName(task).Data())); //, AliRecoParam::GetEventSpecieName(specie))) ; 
289       }
290     }
291     rv = fESDsQAList ;
292   }
293   return rv ; 
294 }
295
296 //____________________________________________________________________________ 
297 void AliQADataMakerRec::Init(AliQAv1::TASKINDEX_t task, TObjArray ** list, Int_t run, Int_t cycles)
298 {
299   // Intialisation by passing the list of QA data booked elsewhere
300   
301   InitRecoParams() ;
302   fRun = run ;
303   if (cycles > 0)
304     SetCycle(cycles) ;  
305         
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   }
315 }
316
317 //____________________________________________________________________________
318 void AliQADataMakerRec::InitRecoParams() 
319 {
320   // Get the recoparam form the OCDB 
321   if (!fRecoParam) {
322     AliDebug(AliQAv1::GetQADebugLevel(), Form("Loading reconstruction parameter objects for detector %s", GetName()));
323     AliCDBPath path(GetName(),"Calib","RecoParam");
324     AliCDBEntry *entry=AliCDBManager::Instance()->Get(path.GetPath());    
325     if(!entry) {
326       fRecoParam = NULL ; 
327       AliDebug(AliQAv1::GetQADebugLevel(), Form("Couldn't find RecoParam entry in OCDB for detector %s",GetName()));
328     }
329     else {
330       //      entry->SetOwner(kTRUE);
331       TObject * recoParamObj = entry->GetObject() ; 
332       if ( strcmp(recoParamObj->ClassName(), "TObjArray") == 0 ) {
333         // The detector has only one set of reco parameters
334         AliDebug(AliQAv1::GetQADebugLevel(), Form("Array of reconstruction parameters found for detector %s",GetName()));
335         TObjArray *recoParamArray = static_cast<TObjArray*>(recoParamObj) ;
336         //        recoParamArray->SetOwner(kTRUE);
337         for (Int_t iRP=0; iRP<recoParamArray->GetEntriesFast(); iRP++) {
338           fRecoParam = static_cast<AliDetectorRecoParam*>(recoParamArray->At(iRP)) ;
339           if (!fRecoParam) 
340             break ; 
341           else if (fRecoParam->IsDefault()) 
342             break ; 
343         }
344       }
345       else if (recoParamObj->InheritsFrom("AliDetectorRecoParam")) {
346         // The detector has only one set of reco parameters
347         // Registering it in AliRecoParam
348         AliDebug(AliQAv1::GetQADebugLevel(), Form("Single set of reconstruction parameters found for detector %s",GetName()));
349         fRecoParam = static_cast<AliDetectorRecoParam*>(recoParamObj) ;
350         static_cast<AliDetectorRecoParam*>(recoParamObj)->SetAsDefault();
351       } else { 
352         AliError(Form("No valid RecoParam object found in the OCDB for detector %s",GetName()));
353       }
354     }
355   }
356 }
357
358 //____________________________________________________________________________ 
359 void AliQADataMakerRec::ResetDetector(AliQAv1::TASKINDEX_t task)
360 {
361   // default reset that resets all the QA objects.
362   // to be overloaded by detectors, if necessary
363
364   TObjArray ** list = NULL ; 
365   if ( task == AliQAv1::kRAWS ) {
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
375   if (!list) return; 
376   
377   for (int spec = 0; spec < AliRecoParam::kNSpecies; spec++) {
378     if (!AliQAv1::Instance()->IsEventSpecieSet(AliRecoParam::ConvertIndex(spec))) continue;
379     TIter next(list[spec]) ; 
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); 
386           if (!histo) continue;
387           histo->Reset("ICE");
388           histo->ResetStats();
389         }
390       }
391       else {
392         ((TH1*)obj)->Reset("ICE");
393         ((TH1*)obj)->ResetStats();
394       }
395     }
396     ResetEvCountCycle(AliRecoParam::ConvertIndex(spec));
397     ResetEvCountTotal(AliRecoParam::ConvertIndex(spec));
398   }
399 }
400
401 //____________________________________________________________________________
402 void AliQADataMakerRec::StartOfCycle(Int_t run) 
403 {
404   // Finishes a cycle of QA for all the tasks
405   Bool_t samecycle = kFALSE ; 
406   StartOfCycle(AliQAv1::kRAWS,      run, samecycle) ;
407   samecycle = kTRUE ; 
408   StartOfCycle(AliQAv1::kDIGITSR,   run, samecycle) ; 
409   StartOfCycle(AliQAv1::kRECPOINTS, run, samecycle) ; 
410   StartOfCycle(AliQAv1::kESDS,      run, samecycle) ;
411 }
412
413 //____________________________________________________________________________
414 void AliQADataMakerRec::StartOfCycle(AliQAv1::TASKINDEX_t task, Int_t run, const Bool_t sameCycle) 
415
416   // Finishes a cycle of QA data acquistion
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())
423       fOutput = AliQAv1::GetQADataFile(GetName(), fRun) ;       
424   }     
425   if (AliQAManager::QAManager(AliQAv1::kRECMODE)->IsSaveData())
426     AliDebug(AliQAv1::GetQADebugLevel(), Form(" Run %d Cycle %d task %s file %s", 
427                                             fRun, fCurrentCycle, AliQAv1::GetTaskName(task).Data(), fOutput->GetName() )) ;
428   else
429     AliDebug(AliQAv1::GetQADebugLevel(), Form(" Run %d Cycle %d task %s not saved", 
430                                               fRun, fCurrentCycle, AliQAv1::GetTaskName(task).Data() )) ;    
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 }
451
452 //____________________________________________________________________________
453 void 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   //
465 }