]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliQADataMakerRec.cxx
Bug fix in the order of the Ds cuts (Sadhana, Francesco)
[u/mrichter/AliRoot.git] / 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         SetName(qadm.GetName()) ; 
76         SetTitle(qadm.GetTitle()) ; 
77         fDetectorDirName = GetName() ; 
78 }
79
80 //____________________________________________________________________________ 
81 AliQADataMakerRec::~AliQADataMakerRec()
82 {
83         //dtor: delete the TObjArray and thei content
84         if ( fESDsQAList ) {
85     for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
86       if ( fESDsQAList[specie] ) {
87           fESDsQAList[specie]->Delete() ;     
88       }
89     }
90     delete[] fESDsQAList ;
91         }
92         if ( fRawsQAList ) {
93     for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
94       if ( fRawsQAList[specie] ) {
95         fRawsQAList[specie]->Delete() ;
96       }
97     }
98     delete[] fRawsQAList ;
99   }
100         if ( fDigitsQAList ) {
101     for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
102       if ( fDigitsQAList[specie] ) {
103         fDigitsQAList[specie]->Delete() ;
104       }
105     }
106                 delete[] fDigitsQAList ; 
107   }
108         if ( fRecPointsQAList ) {
109     for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
110       if ( fRecPointsQAList[specie] ) {
111         fRecPointsQAList[specie]->Delete() ;
112       }
113     }
114                 delete[] fRecPointsQAList ; 
115   }
116   if (fRecPointsArray) {
117     fRecPointsArray->Clear() ; 
118     delete fRecPointsArray ; 
119   }
120 }
121
122 //__________________________________________________________________
123 AliQADataMakerRec& AliQADataMakerRec::operator = (const AliQADataMakerRec& qadm )
124 {
125   // Assignment operator.
126   this->~AliQADataMakerRec();
127   new(this) AliQADataMakerRec(qadm);
128   return *this;
129 }
130
131 //____________________________________________________________________________
132 void AliQADataMakerRec::EndOfCycle() 
133 {
134   // Finishes a cycle of QA for all the tasks
135   EndOfCycle(AliQAv1::kRAWS) ; 
136   EndOfCycle(AliQAv1::kDIGITSR) ; 
137   EndOfCycle(AliQAv1::kRECPOINTS) ; 
138   EndOfCycle(AliQAv1::kESDS) ; 
139   ResetCycle() ; 
140 }
141
142 //____________________________________________________________________________
143 void AliQADataMakerRec::EndOfCycle(AliQAv1::TASKINDEX_t task) 
144 {
145         // Finishes a cycle of QA 
146         
147     
148   TObjArray ** list = NULL ; 
149         
150         if ( task == AliQAv1::kRAWS )     
151                 list = fRawsQAList ; 
152         else if ( task == AliQAv1::kDIGITSR ) 
153                 list = fDigitsQAList ; 
154         else if ( task == AliQAv1::kRECPOINTS ) 
155                 list = fRecPointsQAList ; 
156         else if ( task == AliQAv1::kESDS )
157                 list = fESDsQAList ; 
158
159  
160         if ( ! list && ! fCorrNt ) 
161     return ; 
162   //DefaultEndOfDetectorCycle(task) ;
163         EndOfDetectorCycle(task, list) ;
164   
165   if (! AliQAManager::QAManager(AliQAv1::kRECMODE)->IsSaveData())
166     return ; 
167
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() ; 
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) 
177       continue ; 
178     TDirectory * eventSpecieDir = subDir->GetDirectory(AliRecoParam::GetEventSpecieName(specie)) ;
179     if (!eventSpecieDir) 
180       eventSpecieDir = subDir->mkdir(AliRecoParam::GetEventSpecieName(specie)) ; 
181     eventSpecieDir->cd() ;    
182     if (list) {
183       if (list[specie]) {
184         TIter next(list[specie]) ; 
185         TObject * obj ; 
186         while( (obj = next()) ) {
187           if (!obj->TestBit(AliQAv1::GetExpertBit()))
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         }
202       }
203     } 
204     else if ( fCorrNt ) {
205       if (fCorrNt[specie] && AliQAv1::GetDetIndex(GetName()) == AliQAv1::kCORR) {
206         eventSpecieDir->cd() ; 
207         fCorrNt[specie]->Write() ; 
208       }
209       fOutput->Save() ; 
210     }
211   }
212 }
213
214 //____________________________________________________________________________
215 void AliQADataMakerRec::Exec(AliQAv1::TASKINDEX_t task, TObject * data) 
216
217   // creates the quality assurance data for the various tasks (Hits, SDigits, Digits, ESDs)
218         
219         if ( task == AliQAv1::kRAWS ) {
220                 AliDebug(AliQAv1::GetQADebugLevel(), "Processing Raws QA") ; 
221                 AliRawReader * rawReader = static_cast<AliRawReader *>(data) ; 
222                 if (rawReader) 
223                         MakeRaws(rawReader) ;
224                 else
225       AliDebug(AliQAv1::GetQADebugLevel(), "Raw data are not processed") ;     
226         } else if ( task == AliQAv1::kDIGITSR ) {
227                 AliDebug(AliQAv1::GetQADebugLevel(), "Processing Digits QA") ; 
228                 TTree * tree = static_cast<TTree *>(data) ; 
229                 if (strcmp(tree->ClassName(), "TTree") == 0) {
230                         MakeDigits(tree) ; 
231                 } else {
232                         AliWarning("data are not a TTree") ; 
233                 }
234         } else if ( task == AliQAv1::kRECPOINTS ) {
235                 AliDebug(AliQAv1::GetQADebugLevel(), "Processing RecPoints QA") ; 
236                 TTree * tree = static_cast<TTree *>(data) ; 
237                 if (strcmp(tree->ClassName(), "TTree") == 0) {
238                         MakeRecPoints(tree) ; 
239                 } else {
240                         AliWarning("data are not a TTree") ; 
241                 }
242         } else if ( task == AliQAv1::kESDS ) {
243                 AliDebug(AliQAv1::GetQADebugLevel(), "Processing ESDs QA") ; 
244                 AliESDEvent * esd = static_cast<AliESDEvent *>(data) ; 
245                 if (strcmp(esd->ClassName(), "AliESDEvent") == 0) 
246                         MakeESDs(esd) ;
247                 else 
248                         AliError("Wrong type of esd container") ; 
249         }  
250 }
251
252 //____________________________________________________________________________ 
253 TObjArray **  AliQADataMakerRec::Init(AliQAv1::TASKINDEX_t task, Int_t cycles)
254 {
255   // general intialisation
256   InitRecoParams() ;
257         TObjArray ** rv = NULL ; 
258   
259         if (cycles > 0)
260                 SetCycle(cycles) ;  
261         
262         if ( task == AliQAv1::kRAWS ) {
263                 if (! fRawsQAList ) { 
264       fRawsQAList = new TObjArray *[AliRecoParam::kNSpecies] ; 
265       for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
266         fRawsQAList[specie] = new TObjArray(AliQAv1::GetMaxQAObj()) ;    
267         fRawsQAList[specie]->SetName(Form("%s_%s_%s", GetName(), AliQAv1::GetTaskName(task).Data(), AliRecoParam::GetEventSpecieName(specie))) ;
268       }
269                 }
270                 rv = fRawsQAList ;
271         } else if ( task == AliQAv1::kDIGITSR ) {
272                 if ( ! fDigitsQAList ) {
273       fDigitsQAList = new TObjArray *[AliRecoParam::kNSpecies] ; 
274       for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
275         fDigitsQAList[specie] = new TObjArray(AliQAv1::GetMaxQAObj()) ; 
276         fDigitsQAList[specie]->SetName(Form("%s_%s_%s", GetName(), AliQAv1::GetTaskName(task).Data(), AliRecoParam::GetEventSpecieName(specie))) ; 
277       }
278                 }
279                 rv = fDigitsQAList ;
280         } else if ( task == AliQAv1::kRECPOINTS ) {
281                 if ( ! fRecPointsQAList ) {
282       fRecPointsQAList = new TObjArray *[AliRecoParam::kNSpecies] ; 
283       for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
284         fRecPointsQAList[specie] = new TObjArray(AliQAv1::GetMaxQAObj()) ; 
285         fRecPointsQAList[specie]->SetName(Form("%s_%s_%s", GetName(), AliQAv1::GetTaskName(task).Data(), AliRecoParam::GetEventSpecieName(specie))) ; 
286       }
287     }
288                 rv = fRecPointsQAList ;
289         } else if ( task == AliQAv1::kESDS ) {
290                 if ( ! fESDsQAList ) {
291       fESDsQAList = new TObjArray *[AliRecoParam::kNSpecies] ; 
292       for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
293         fESDsQAList[specie] = new TObjArray(AliQAv1::GetMaxQAObj()) ;
294         fESDsQAList[specie]->SetName(Form("%s_%s", GetName(), AliQAv1::GetTaskName(task).Data(), AliRecoParam::GetEventSpecieName(specie))) ; 
295       }
296                 }
297                 rv = fESDsQAList ;
298         }
299         return rv ; 
300 }
301
302 //____________________________________________________________________________ 
303 void AliQADataMakerRec::Init(AliQAv1::TASKINDEX_t task, TObjArray ** list, Int_t run, Int_t cycles)
304 {
305   // Intialisation by passing the list of QA data booked elsewhere
306   
307   InitRecoParams() ;
308   fRun = run ;
309         if (cycles > 0)
310                 SetCycle(cycles) ;  
311         
312         if ( task == AliQAv1::kRAWS ) {
313                 fRawsQAList = list ;     
314         } else if ( task == AliQAv1::kDIGITSR ) {
315                 fDigitsQAList = list ; 
316         } else if ( task == AliQAv1::kRECPOINTS ) {
317                 fRecPointsQAList = list ; 
318         } else if ( task == AliQAv1::kESDS ) {
319                 fESDsQAList = list ; 
320         }
321 }
322
323 //____________________________________________________________________________
324 void AliQADataMakerRec::InitRecoParams() 
325 {
326   // Get the recoparam form the OCDB 
327   if (!fRecoParam) {
328     AliDebug(AliQAv1::GetQADebugLevel(), Form("Loading reconstruction parameter objects for detector %s", GetName()));
329     AliCDBPath path(GetName(),"Calib","RecoParam");
330     AliCDBEntry *entry=AliCDBManager::Instance()->Get(path.GetPath());
331     if(!entry) {
332       fRecoParam = NULL ; 
333       AliDebug(AliQAv1::GetQADebugLevel(), Form("Couldn't find RecoParam entry in OCDB for detector %s",GetName()));
334     }
335     else {
336       TObject * recoParamObj = entry->GetObject() ; 
337       if ( strcmp(recoParamObj->ClassName(), "TObjArray") == 0 ) {
338         // The detector has only one set of reco parameters
339         AliDebug(AliQAv1::GetQADebugLevel(), Form("Array of reconstruction parameters found for detector %s",GetName()));
340         TObjArray *recoParamArray = static_cast<TObjArray*>(recoParamObj) ;
341         for (Int_t iRP=0; iRP<recoParamArray->GetEntriesFast(); iRP++) {
342           fRecoParam = static_cast<AliDetectorRecoParam*>(recoParamArray->At(iRP)) ;
343           if (!fRecoParam) 
344             break ; 
345           else if (fRecoParam->IsDefault()) 
346             break ; 
347         }
348       }
349       else if (recoParamObj->InheritsFrom("AliDetectorRecoParam")) {
350         // The detector has only one set of reco parameters
351         // Registering it in AliRecoParam
352         AliDebug(AliQAv1::GetQADebugLevel(), Form("Single set of reconstruction parameters found for detector %s",GetName()));
353         fRecoParam = static_cast<AliDetectorRecoParam*>(recoParamObj) ;
354         static_cast<AliDetectorRecoParam*>(recoParamObj)->SetAsDefault();
355       } else { 
356         AliError(Form("No valid RecoParam object found in the OCDB for detector %s",GetName()));
357       }
358     }
359   }
360 }
361
362 //____________________________________________________________________________ 
363 void AliQADataMakerRec::ResetDetector(AliQAv1::TASKINDEX_t task)
364 {
365     // default reset that resets all the QA objects.
366     // to be overloaded by detectors, if necessary
367
368   TObjArray ** list = NULL ; 
369   if ( task == AliQAv1::kRAWS ) {
370                 list = fRawsQAList ;     
371         } else if ( task == AliQAv1::kDIGITSR ) {
372                 list = fDigitsQAList ; 
373         } else if ( task == AliQAv1::kRECPOINTS ) {
374                 list = fRecPointsQAList ; 
375         } else if ( task == AliQAv1::kESDS ) {
376                 list = fESDsQAList ; 
377         }
378     //list was not initialized, skip
379   if (!list) 
380     return ; 
381   
382   for (int spec = 0; spec < AliRecoParam::kNSpecies; spec++) {
383     if (!AliQAv1::Instance()->IsEventSpecieSet(AliRecoParam::ConvertIndex(spec)))
384       continue;
385     TIter next(list[spec]) ; 
386     TH1 * histo = NULL ; 
387     while ( (histo = dynamic_cast<TH1*> (next())) ) {
388       histo->Reset("ICE") ;
389     }
390   }
391 }
392
393 //____________________________________________________________________________
394 void AliQADataMakerRec::StartOfCycle(Int_t run) 
395 {
396   // Finishes a cycle of QA for all the tasks
397   Bool_t samecycle = kFALSE ; 
398   StartOfCycle(AliQAv1::kRAWS,      run, samecycle) ;
399   samecycle = kTRUE ; 
400   StartOfCycle(AliQAv1::kDIGITSR,   run, samecycle) ; 
401   StartOfCycle(AliQAv1::kRECPOINTS, run, samecycle) ; 
402   StartOfCycle(AliQAv1::kESDS,      run, samecycle) ; 
403 }
404
405 //____________________________________________________________________________
406 void AliQADataMakerRec::StartOfCycle(AliQAv1::TASKINDEX_t task, Int_t run, const Bool_t sameCycle) 
407
408   // Finishes a cycle of QA data acquistion
409   if ( run > 0 ) 
410     fRun = run ; 
411         if ( !sameCycle || fCurrentCycle == -1) {
412                 ResetCycle() ;
413                 if (fOutput) 
414                         fOutput->Close() ; 
415                 if (AliQAManager::QAManager(AliQAv1::kRECMODE)->IsSaveData())
416       fOutput = AliQAv1::GetQADataFile(GetName(), fRun) ;       
417         }       
418         AliDebug(AliQAv1::GetQADebugLevel(), Form(" Run %d Cycle %d task %s file %s", 
419                                  fRun, fCurrentCycle, AliQAv1::GetTaskName(task).Data(), fOutput->GetName() )) ;
420
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 //  } 
437         StartOfDetectorCycle() ; 
438 }