]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliQADataMakerRec.cxx
adding Mihaela's macros to be used for the analysis train...
[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 "AliESDEvent.h"
43 #include "AliRawReader.h"
44
45 ClassImp(AliQADataMakerRec)
46              
47 //____________________________________________________________________________ 
48 AliQADataMakerRec::AliQADataMakerRec(const char * name, const char * title) : 
49   AliQADataMaker(name, title), 
50   fESDsQAList(NULL), 
51   fRawsQAList(NULL), 
52   fRecPointsQAList(NULL),
53   fCorrNt(NULL), 
54   fRecoParam(NULL) 
55 {
56   // ctor
57         fDetectorDirName = GetName() ; 
58 }
59
60 //____________________________________________________________________________ 
61 AliQADataMakerRec::AliQADataMakerRec(const AliQADataMakerRec& qadm) :
62   AliQADataMaker(qadm.GetName(), qadm.GetTitle()), 
63   fESDsQAList(qadm.fESDsQAList),
64   fRawsQAList(qadm.fRawsQAList),
65   fRecPointsQAList(qadm.fRecPointsQAList),
66   fCorrNt(qadm.fCorrNt),  
67   fRecoParam(qadm.fRecoParam) 
68 {
69   //copy ctor
70         SetName(qadm.GetName()) ; 
71         SetTitle(qadm.GetTitle()) ; 
72         fDetectorDirName = GetName() ; 
73 }
74
75 //____________________________________________________________________________ 
76 AliQADataMakerRec::~AliQADataMakerRec()
77 {
78         //dtor: delete the TObjArray and thei content
79         if ( fESDsQAList ) {
80     for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
81       if ( fESDsQAList[specie] ) {
82         if ( fESDsQAList[specie]->IsOwner() ) 
83           fESDsQAList[specie]->Delete() ;     
84       }
85     }
86     delete[] fESDsQAList ;
87         }
88         if ( fRawsQAList ) {
89     for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
90       if ( fRawsQAList[specie] ) {
91         if ( fRawsQAList[specie]->IsOwner() ) 
92           fRawsQAList[specie]->Delete() ;
93       }
94     }
95     delete[] fRawsQAList ;
96   }
97         if ( fRecPointsQAList ) {
98     for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
99       if ( fRecPointsQAList[specie] ) {
100         if ( fRecPointsQAList[specie]->IsOwner() ) 
101           fRecPointsQAList[specie]->Delete() ;
102       }
103     }
104                 delete[] fRecPointsQAList ; 
105         }
106 }
107
108 //__________________________________________________________________
109 AliQADataMakerRec& AliQADataMakerRec::operator = (const AliQADataMakerRec& qadm )
110 {
111   // Assignment operator.
112   this->~AliQADataMakerRec();
113   new(this) AliQADataMakerRec(qadm);
114   return *this;
115 }
116
117 //____________________________________________________________________________
118 void AliQADataMakerRec::EndOfCycle() 
119 {
120   // Finishes a cycle of QA for all the tasks
121   EndOfCycle(AliQA::kRAWS) ; 
122   EndOfCycle(AliQA::kRECPOINTS) ; 
123   EndOfCycle(AliQA::kESDS) ; 
124   ResetCycle() ; 
125 }
126
127 //____________________________________________________________________________
128 void AliQADataMakerRec::EndOfCycle(AliQA::TASKINDEX_t task) 
129 {
130         // Finishes a cycle of QA 
131         
132         TObjArray ** list = NULL ; 
133         
134         if ( task == AliQA::kRAWS )     
135                 list = fRawsQAList ; 
136         else if ( task == AliQA::kRECPOINTS ) 
137                 list = fRecPointsQAList ; 
138         else if ( task == AliQA::kESDS )
139                 list = fESDsQAList ; 
140
141  
142         if ( ! list && ! fCorrNt ) 
143     return ; 
144   //DefaultEndOfDetectorCycle(task) ;
145         EndOfDetectorCycle(task, list) ;
146         TDirectory * subDir = NULL ;
147         if (fDetectorDir) 
148                 subDir = fDetectorDir->GetDirectory(AliQA::GetTaskName(task)) ; 
149         if ( subDir ) {
150                 subDir->cd() ; 
151     for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
152       TDirectory * eventSpecieDir = subDir->GetDirectory(AliRecoParam::GetEventSpecieName(specie)) ;
153       if (eventSpecieDir) {
154         eventSpecieDir->cd() ;    
155         if (list[specie]) {
156           TIter next(list[specie]) ; 
157           TObject * obj ; 
158           while( (obj = next()) ) {
159             if (!obj->TestBit(AliQA::GetExpertBit()))
160               obj->Write() ;
161           }
162           if (WriteExpert()) {
163             TDirectory * expertDir = eventSpecieDir->GetDirectory(AliQA::GetExpert()) ; 
164             if ( expertDir ) { // Write only if requested
165               expertDir->cd() ;
166               next.Reset() ; 
167               while( (obj = next()) ) {
168                 if (!obj->TestBit(AliQA::GetExpertBit()))
169                   continue ; 
170                 obj->Write() ;
171               }      
172             }
173           }
174         }
175         if ( !fCorrNt )
176           continue ; 
177         if (fCorrNt[specie] && AliQA::GetDetIndex(GetName()) == AliQA::kCORR) {
178           eventSpecieDir->cd() ; 
179           fCorrNt[specie]->Write() ; 
180         }
181       }
182     }
183     fOutput->Save() ; 
184         }
185 }
186  
187 //____________________________________________________________________________
188 void AliQADataMakerRec::Exec(AliQA::TASKINDEX_t task, TObject * data) 
189
190   // creates the quality assurance data for the various tasks (Hits, SDigits, Digits, ESDs)
191         
192         if ( task == AliQA::kRAWS ) {
193                 AliDebug(1, "Processing Raws QA") ; 
194                 AliRawReader * rawReader = dynamic_cast<AliRawReader *>(data) ; 
195                 if (rawReader) 
196                         MakeRaws(rawReader) ;
197                 else
198                 AliInfo("Raw data are not processed") ;     
199         } else if ( task == AliQA::kRECPOINTS ) {
200                 AliDebug(1, "Processing RecPoints QA") ; 
201                 TTree * tree = dynamic_cast<TTree *>(data) ; 
202                 if (tree) {
203                         MakeRecPoints(tree) ; 
204                 } else {
205                         AliWarning("data are not a TTree") ; 
206                 }
207         } else if ( task == AliQA::kESDS ) {
208                 AliDebug(1, "Processing ESDs QA") ; 
209                 AliESDEvent * esd = dynamic_cast<AliESDEvent *>(data) ; 
210                 if (esd) 
211                         MakeESDs(esd) ;
212                 else 
213                         AliError("Wrong type of esd container") ; 
214         }  
215 }
216
217 //____________________________________________________________________________ 
218 TObjArray **  AliQADataMakerRec::Init(AliQA::TASKINDEX_t task, Int_t cycles)
219 {
220   // general intialisation
221   InitRecoParams() ;
222         TObjArray ** rv = NULL ; 
223   
224         if (cycles > 0)
225                 SetCycle(cycles) ;  
226         
227         if ( task == AliQA::kRAWS ) {
228                 if (! fRawsQAList ) { 
229       fRawsQAList = new TObjArray *[AliRecoParam::kNSpecies] ; 
230       for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
231         fRawsQAList[specie] = new TObjArray(100) ;       
232         fRawsQAList[specie]->SetName(Form("%s_%s_%s", GetName(), AliQA::GetTaskName(task).Data(), AliRecoParam::GetEventSpecieName(specie))) ;
233       }
234                         InitRaws() ;
235                 }
236                 rv = fRawsQAList ;
237         } else if ( task == AliQA::kRECPOINTS ) {
238                 if ( ! fRecPointsQAList ) {
239       fRecPointsQAList = new TObjArray *[AliRecoParam::kNSpecies] ; 
240       for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
241         fRecPointsQAList[specie] = new TObjArray(100) ; 
242         fRecPointsQAList[specie]->SetName(Form("%s_%s_%s", GetName(), AliQA::GetTaskName(task).Data(), AliRecoParam::GetEventSpecieName(specie))) ; 
243       }
244       InitRecPoints() ;
245                 }
246                 rv = fRecPointsQAList ;
247         } else if ( task == AliQA::kESDS ) {
248                 if ( ! fESDsQAList ) {
249       fESDsQAList = new TObjArray *[AliRecoParam::kNSpecies] ; 
250       for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
251         fESDsQAList[specie] = new TObjArray(100) ;
252         fESDsQAList[specie]->SetName(Form("%s_%s", GetName(), AliQA::GetTaskName(task).Data(), AliRecoParam::GetEventSpecieName(specie))) ; 
253       }
254                         InitESDs() ;
255                 }
256                 rv = fESDsQAList ;
257         }
258         return rv ; 
259 }
260
261 //____________________________________________________________________________ 
262 void AliQADataMakerRec::Init(AliQA::TASKINDEX_t task, TObjArray ** list, Int_t run, Int_t cycles)
263 {
264   // Intialisation by passing the list of QA data booked elsewhere
265   
266   InitRecoParams() ;
267   fRun = run ;
268         if (cycles > 0)
269                 SetCycle(cycles) ;  
270         
271         if ( task == AliQA::kRAWS ) {
272                 fRawsQAList = list ;     
273         } else if ( task == AliQA::kRECPOINTS ) {
274                 fRecPointsQAList = list ; 
275         } else if ( task == AliQA::kESDS ) {
276                 fESDsQAList = list ; 
277         }
278 }
279
280 //____________________________________________________________________________
281 void AliQADataMakerRec::InitRecoParams() 
282 {
283   if (!fRecoParam) {
284     AliInfo(Form("Loading reconstruction parameter objects for detector %s", GetName()));
285     AliCDBPath path(GetName(),"Calib","RecoParam");
286     AliCDBEntry *entry=AliCDBManager::Instance()->Get(path.GetPath());
287     if(!entry) {
288       fRecoParam = NULL ; 
289       AliWarning(Form("Couldn't find RecoParam entry in OCDB for detector %s",GetName()));
290     }
291     else {
292       TObject * recoParamObj = entry->GetObject() ; 
293       if (dynamic_cast<TObjArray*>(recoParamObj)) {
294         // The detector has only one set of reco parameters
295         AliInfo(Form("Array of reconstruction parameters found for detector %s",GetName()));
296         TObjArray *recoParamArray = dynamic_cast<TObjArray*>(recoParamObj) ;
297         for (Int_t iRP=0; iRP<recoParamArray->GetEntriesFast(); iRP++) {
298           fRecoParam = dynamic_cast<AliDetectorRecoParam*>(recoParamArray->At(iRP)) ;
299           if (fRecoParam->IsDefault()) break;
300         }
301       }
302       else if (dynamic_cast<AliDetectorRecoParam*>(recoParamObj)) {
303         // The detector has only onse set of reco parameters
304         // Registering it in AliRecoParam
305         AliInfo(Form("Single set of reconstruction parameters found for detector %s",GetName()));
306         dynamic_cast<AliDetectorRecoParam*>(recoParamObj)->SetAsDefault();
307         fRecoParam = dynamic_cast<AliDetectorRecoParam*>(recoParamObj) ;
308       } else { 
309         AliError(Form("No valid RecoParam object found in the OCDB for detector %s",GetName()));
310       }
311     }
312     AliCDBManager::Instance()->UnloadFromCache(path.GetPath());
313   }
314 }
315
316 //____________________________________________________________________________
317 void AliQADataMakerRec::StartOfCycle(Int_t run) 
318 {
319   // Finishes a cycle of QA for all the tasks
320   Bool_t samecycle = kFALSE ; 
321   StartOfCycle(AliQA::kRAWS,      run, samecycle) ;
322   samecycle = kTRUE ; 
323   StartOfCycle(AliQA::kRECPOINTS, run, samecycle) ; 
324   StartOfCycle(AliQA::kESDS,      run, samecycle) ; 
325 }
326
327 //____________________________________________________________________________
328 void AliQADataMakerRec::StartOfCycle(AliQA::TASKINDEX_t task, Int_t run, const Bool_t sameCycle) 
329
330   // Finishes a cycle of QA data acquistion
331   if ( run > 0 ) 
332     fRun = run ; 
333         if ( !sameCycle || fCurrentCycle == -1) {
334                 ResetCycle() ;
335                 if (fOutput) 
336                         fOutput->Close() ; 
337                 fOutput = AliQA::GetQADataFile(GetName(), fRun) ;       
338         }       
339         AliInfo(Form(" Run %d Cycle %d task %s file %s", 
340                                  fRun, fCurrentCycle, AliQA::GetTaskName(task).Data(), fOutput->GetName() )) ;
341
342         fDetectorDir = fOutput->GetDirectory(GetDetectorDirName()) ; 
343         if (!fDetectorDir)
344                 fDetectorDir = fOutput->mkdir(GetDetectorDirName()) ; 
345
346         TDirectory * subDir = fDetectorDir->GetDirectory(AliQA::GetTaskName(task)) ; 
347         if (!subDir)
348                 subDir = fDetectorDir->mkdir(AliQA::GetTaskName(task)) ;  
349   
350   for ( Int_t specie = AliRecoParam::kDefault ; specie < AliRecoParam::kNSpecies ; specie++ ) {
351     TDirectory * eventSpecieDir = subDir->GetDirectory(AliRecoParam::GetEventSpecieName(specie)) ; 
352     if (!eventSpecieDir) 
353       eventSpecieDir = subDir->mkdir(AliRecoParam::GetEventSpecieName(specie)) ; 
354     TDirectory * expertDir = eventSpecieDir->GetDirectory(AliQA::GetExpert()) ; 
355     if (!expertDir)
356       expertDir = eventSpecieDir->mkdir(AliQA::GetExpert()) ; 
357   } 
358         StartOfDetectorCycle() ; 
359 }