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