]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliQADataMakerRec.cxx
Made QA images persistent objects
[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 <TCanvas.h>
28 #include <TFile.h>
29 #include <TTree.h>
30 #include <TNtupleD.h>
31 #include <TObjArray.h>
32
33 // --- Standard library ---
34
35 // --- AliRoot header files ---
36 #include "AliCDBPath.h"
37 #include "AliCDBEntry.h"
38 #include "AliDetectorRecoParam.h"
39 #include "AliCDBManager.h"
40
41 #include "AliLog.h"
42 #include "AliQADataMakerRec.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 {
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 {
72   //copy ctor
73         SetName(qadm.GetName()) ; 
74         SetTitle(qadm.GetTitle()) ; 
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         if ( fESDsQAList[specie]->IsOwner() ) 
86           fESDsQAList[specie]->Delete() ;     
87       }
88     }
89     delete[] fESDsQAList ;
90         }
91         if ( fRawsQAList ) {
92     for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
93       if ( fRawsQAList[specie] ) {
94         if ( fRawsQAList[specie]->IsOwner() ) 
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         if ( fDigitsQAList[specie]->IsOwner() ) 
104           fDigitsQAList[specie]->Delete() ;
105       }
106     }
107                 delete[] fDigitsQAList ; 
108   }
109         if ( fRecPointsQAList ) {
110     for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
111       if ( fRecPointsQAList[specie] ) {
112         if ( fRecPointsQAList[specie]->IsOwner() ) 
113           fRecPointsQAList[specie]->Delete() ;
114       }
115     }
116                 delete[] fRecPointsQAList ; 
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         TObjArray ** list = NULL ; 
146         
147         if ( task == AliQAv1::kRAWS )     
148                 list = fRawsQAList ; 
149         else if ( task == AliQAv1::kDIGITSR ) 
150                 list = fDigitsQAList ; 
151         else if ( task == AliQAv1::kRECPOINTS ) 
152                 list = fRecPointsQAList ; 
153         else if ( task == AliQAv1::kESDS )
154                 list = fESDsQAList ; 
155
156  
157         if ( ! list && ! fCorrNt ) 
158     return ; 
159   //DefaultEndOfDetectorCycle(task) ;
160         EndOfDetectorCycle(task, list) ;
161         TDirectory * subDir = NULL ;
162         if (fDetectorDir) 
163                 subDir = fDetectorDir->GetDirectory(AliQAv1::GetTaskName(task)) ; 
164         if ( subDir ) {
165                 subDir->cd() ; 
166     for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
167       TDirectory * eventSpecieDir = subDir->GetDirectory(AliRecoParam::GetEventSpecieName(specie)) ;
168       if (eventSpecieDir) {
169         eventSpecieDir->cd() ;    
170         if (list[specie]) {
171           TIter next(list[specie]) ; 
172           TObject * obj ; 
173           while( (obj = next()) ) {
174             if (!obj->TestBit(AliQAv1::GetExpertBit()))
175               obj->Write() ;
176           }
177           if (WriteExpert()) {
178             TDirectory * expertDir = eventSpecieDir->GetDirectory(AliQAv1::GetExpert()) ; 
179             if ( expertDir ) { // Write only if requested
180               expertDir->cd() ;
181               next.Reset() ; 
182               while( (obj = next()) ) {
183                 if (!obj->TestBit(AliQAv1::GetExpertBit()))
184                   continue ; 
185                 obj->Write() ;
186               }      
187             }
188           }
189         }
190         if ( !fCorrNt )
191           continue ; 
192         if (fCorrNt[specie] && AliQAv1::GetDetIndex(GetName()) == AliQAv1::kCORR) {
193           eventSpecieDir->cd() ; 
194           fCorrNt[specie]->Write() ; 
195         }
196       }
197     }
198     fOutput->Save() ; 
199         }
200     MakeImage(task) ; 
201 }
202
203 //____________________________________________________________________________ 
204 void AliQADataMakerRec::MakeImage(AliQAv1::TASKINDEX_t task)
205 {
206   // create a drawing of detetor defined histograms
207   TObjArray ** list = NULL ;  
208   switch (task) {
209     case AliQAv1::kRAWS:
210       list = fRawsQAList ; 
211       break;
212     case AliQAv1::kHITS:
213       break;
214     case AliQAv1::kSDIGITS:
215       break;  
216     case AliQAv1::kDIGITS:
217       break;  
218     case AliQAv1::kDIGITSR:
219       list = fDigitsQAList ; 
220       break;  
221     case AliQAv1::kRECPOINTS:
222       list = fRecPointsQAList ; 
223       break;
224     case AliQAv1::kTRACKSEGMENTS:
225       break;
226     case AliQAv1::kRECPARTICLES:
227       break;
228     case AliQAv1::kESDS:
229       list = fESDsQAList ; 
230       break;
231     case AliQAv1::kNTASKINDEX:
232       break;
233     default:
234       break;
235   }
236   if ( !list) {
237     AliError("data not initialized, call AliQADataMaker::Init"); 
238     return ; 
239   }
240   TIter next(list[0]) ;  
241   TH1 * hdata = NULL ; 
242   Int_t nImages = 0 ;
243   while ( (hdata=dynamic_cast<TH1 *>(next())) ) {
244     if ( hdata->TestBit(AliQAv1::GetImageBit()) )
245       nImages++; 
246   }
247   if ( nImages == 0 ) {
248     AliWarning(Form("No histogram will be plotted for %s %s\n", GetName(), AliQAv1::GetTaskName(task).Data())) ;  
249   } else {
250     AliDebug(AliQAv1::GetQADebugLevel(), Form("%d histograms will be plotted for %s %s\n", nImages, GetName(), AliQAv1::GetTaskName(task).Data())) ;  
251     Double_t w  = 1000 ;
252     Double_t h  = 1000 ;
253     for (Int_t esIndex = 0 ; esIndex < AliRecoParam::kNSpecies ; esIndex++) {
254       if ( !fImage[esIndex] ) {
255         fImage[esIndex] = new TCanvas(Form("QA_%s_%s_%s", 
256                                            GetName(), 
257                                            AliQAv1::GetTaskName(task).Data(), 
258                                            AliRecoParam::GetEventSpecieName(esIndex)), 
259                                       Form("QA control plots for det=%s task=%s eventspecie=%s", 
260                                            GetName(), 
261                                            AliQAv1::GetTaskName(task).Data(), 
262                                            AliRecoParam::GetEventSpecieName(esIndex)), 
263                                       w, h) ;
264       }
265       fImage[esIndex]->Clear() ; 
266       fImage[esIndex]->SetWindowSize(w + (w - fImage[esIndex]->GetWw()), h + (h - fImage[esIndex]->GetWh())) ;
267       Int_t nx = TMath::Sqrt(nImages) ; 
268       Int_t ny = nx  ; 
269       if ( nx < TMath::Sqrt(nImages)) 
270         ny++ ; 
271       fImage[esIndex]->Divide(nx, ny) ; 
272       TIter nexthist(list[esIndex]) ; 
273       TH1* hist = NULL ;
274       Int_t npad = 1 ; 
275       fImage[esIndex]->cd(npad) ; 
276       while ( (hist=dynamic_cast<TH1*>(nexthist())) ) {
277         if(hist->TestBit(AliQAv1::GetImageBit())) {
278           hist->Draw() ; 
279           fImage[esIndex]->cd(++npad) ; 
280         }
281       }
282       if (fPrintImage) 
283         fImage[esIndex]->Print() ; 
284     }
285   }
286 }
287
288 //____________________________________________________________________________
289 void AliQADataMakerRec::Exec(AliQAv1::TASKINDEX_t task, TObject * data) 
290
291   // creates the quality assurance data for the various tasks (Hits, SDigits, Digits, ESDs)
292         
293         if ( task == AliQAv1::kRAWS ) {
294                 AliDebug(AliQAv1::GetQADebugLevel(), "Processing Raws QA") ; 
295                 AliRawReader * rawReader = dynamic_cast<AliRawReader *>(data) ; 
296                 if (rawReader) 
297                         MakeRaws(rawReader) ;
298                 else
299       AliDebug(AliQAv1::GetQADebugLevel(), "Raw data are not processed") ;     
300         } else if ( task == AliQAv1::kDIGITSR ) {
301                 AliDebug(AliQAv1::GetQADebugLevel(), "Processing Digits QA") ; 
302                 TTree * tree = dynamic_cast<TTree *>(data) ; 
303                 if (tree) {
304                         MakeDigits(tree) ; 
305                 } else {
306                         AliWarning("data are not a TTree") ; 
307                 }
308         } else if ( task == AliQAv1::kRECPOINTS ) {
309                 AliDebug(AliQAv1::GetQADebugLevel(), "Processing RecPoints QA") ; 
310                 TTree * tree = dynamic_cast<TTree *>(data) ; 
311                 if (tree) {
312                         MakeRecPoints(tree) ; 
313                 } else {
314                         AliWarning("data are not a TTree") ; 
315                 }
316         } else if ( task == AliQAv1::kESDS ) {
317                 AliDebug(AliQAv1::GetQADebugLevel(), "Processing ESDs QA") ; 
318                 AliESDEvent * esd = dynamic_cast<AliESDEvent *>(data) ; 
319                 if (esd) 
320                         MakeESDs(esd) ;
321                 else 
322                         AliError("Wrong type of esd container") ; 
323         }  
324 }
325
326 //____________________________________________________________________________ 
327 TObjArray **  AliQADataMakerRec::Init(AliQAv1::TASKINDEX_t task, Int_t cycles)
328 {
329   // general intialisation
330   InitRecoParams() ;
331         TObjArray ** rv = NULL ; 
332   
333         if (cycles > 0)
334                 SetCycle(cycles) ;  
335         
336         if ( task == AliQAv1::kRAWS ) {
337                 if (! fRawsQAList ) { 
338       fRawsQAList = new TObjArray *[AliRecoParam::kNSpecies] ; 
339       for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
340         fRawsQAList[specie] = new TObjArray(100) ;       
341         fRawsQAList[specie]->SetName(Form("%s_%s_%s", GetName(), AliQAv1::GetTaskName(task).Data(), AliRecoParam::GetEventSpecieName(specie))) ;
342       }
343                         InitRaws() ;
344                 }
345                 rv = fRawsQAList ;
346         } else if ( task == AliQAv1::kDIGITSR ) {
347                 if ( ! fDigitsQAList ) {
348       fDigitsQAList = new TObjArray *[AliRecoParam::kNSpecies] ; 
349       for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
350         fDigitsQAList[specie] = new TObjArray(100) ; 
351         fDigitsQAList[specie]->SetName(Form("%s_%s_%s", GetName(), AliQAv1::GetTaskName(task).Data(), AliRecoParam::GetEventSpecieName(specie))) ; 
352       }
353       InitDigits() ;
354                 }
355                 rv = fDigitsQAList ;
356         } else if ( task == AliQAv1::kRECPOINTS ) {
357                 if ( ! fRecPointsQAList ) {
358       fRecPointsQAList = new TObjArray *[AliRecoParam::kNSpecies] ; 
359       for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
360         fRecPointsQAList[specie] = new TObjArray(100) ; 
361         fRecPointsQAList[specie]->SetName(Form("%s_%s_%s", GetName(), AliQAv1::GetTaskName(task).Data(), AliRecoParam::GetEventSpecieName(specie))) ; 
362       }
363       InitRecPoints() ;
364                 }
365                 rv = fRecPointsQAList ;
366         } else if ( task == AliQAv1::kESDS ) {
367                 if ( ! fESDsQAList ) {
368       fESDsQAList = new TObjArray *[AliRecoParam::kNSpecies] ; 
369       for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
370         fESDsQAList[specie] = new TObjArray(100) ;
371         fESDsQAList[specie]->SetName(Form("%s_%s", GetName(), AliQAv1::GetTaskName(task).Data(), AliRecoParam::GetEventSpecieName(specie))) ; 
372       }
373                         InitESDs() ;
374                 }
375                 rv = fESDsQAList ;
376         }
377         return rv ; 
378 }
379
380 //____________________________________________________________________________ 
381 void AliQADataMakerRec::Init(AliQAv1::TASKINDEX_t task, TObjArray ** list, Int_t run, Int_t cycles)
382 {
383   // Intialisation by passing the list of QA data booked elsewhere
384   
385   InitRecoParams() ;
386   fRun = run ;
387         if (cycles > 0)
388                 SetCycle(cycles) ;  
389         
390         if ( task == AliQAv1::kRAWS ) {
391                 fRawsQAList = list ;     
392         } else if ( task == AliQAv1::kDIGITSR ) {
393                 fDigitsQAList = list ; 
394         } else if ( task == AliQAv1::kRECPOINTS ) {
395                 fRecPointsQAList = list ; 
396         } else if ( task == AliQAv1::kESDS ) {
397                 fESDsQAList = list ; 
398         }
399 }
400
401 //____________________________________________________________________________
402 void AliQADataMakerRec::InitRecoParams() 
403 {
404   if (!fRecoParam) {
405     AliDebug(AliQAv1::GetQADebugLevel(), Form("Loading reconstruction parameter objects for detector %s", GetName()));
406     AliCDBPath path(GetName(),"Calib","RecoParam");
407     AliCDBEntry *entry=AliCDBManager::Instance()->Get(path.GetPath());
408     if(!entry) {
409       fRecoParam = NULL ; 
410       AliWarning(Form("Couldn't find RecoParam entry in OCDB for detector %s",GetName()));
411     }
412     else {
413       TObject * recoParamObj = entry->GetObject() ; 
414       if (dynamic_cast<TObjArray*>(recoParamObj)) {
415         // The detector has only one set of reco parameters
416         AliDebug(AliQAv1::GetQADebugLevel(), Form("Array of reconstruction parameters found for detector %s",GetName()));
417         TObjArray *recoParamArray = dynamic_cast<TObjArray*>(recoParamObj) ;
418         for (Int_t iRP=0; iRP<recoParamArray->GetEntriesFast(); iRP++) {
419           fRecoParam = dynamic_cast<AliDetectorRecoParam*>(recoParamArray->At(iRP)) ;
420           if (fRecoParam->IsDefault()) break;
421         }
422       }
423       else if (dynamic_cast<AliDetectorRecoParam*>(recoParamObj)) {
424         // The detector has only onse set of reco parameters
425         // Registering it in AliRecoParam
426         AliDebug(AliQAv1::GetQADebugLevel(), Form("Single set of reconstruction parameters found for detector %s",GetName()));
427         dynamic_cast<AliDetectorRecoParam*>(recoParamObj)->SetAsDefault();
428         fRecoParam = dynamic_cast<AliDetectorRecoParam*>(recoParamObj) ;
429       } else { 
430         AliError(Form("No valid RecoParam object found in the OCDB for detector %s",GetName()));
431       }
432     }
433     AliCDBManager::Instance()->UnloadFromCache(path.GetPath());
434   }
435 }
436
437 //____________________________________________________________________________
438 void AliQADataMakerRec::StartOfCycle(Int_t run) 
439 {
440   // Finishes a cycle of QA for all the tasks
441   Bool_t samecycle = kFALSE ; 
442   StartOfCycle(AliQAv1::kRAWS,      run, samecycle) ;
443   samecycle = kTRUE ; 
444   StartOfCycle(AliQAv1::kDIGITSR,   run, samecycle) ; 
445   StartOfCycle(AliQAv1::kRECPOINTS, run, samecycle) ; 
446   StartOfCycle(AliQAv1::kESDS,      run, samecycle) ; 
447 }
448
449 //____________________________________________________________________________
450 void AliQADataMakerRec::StartOfCycle(AliQAv1::TASKINDEX_t task, Int_t run, const Bool_t sameCycle) 
451
452   // Finishes a cycle of QA data acquistion
453   if ( run > 0 ) 
454     fRun = run ; 
455         if ( !sameCycle || fCurrentCycle == -1) {
456                 ResetCycle() ;
457                 if (fOutput) 
458                         fOutput->Close() ; 
459                 fOutput = AliQAv1::GetQADataFile(GetName(), fRun) ;     
460         }       
461         AliDebug(AliQAv1::GetQADebugLevel(), Form(" Run %d Cycle %d task %s file %s", 
462                                  fRun, fCurrentCycle, AliQAv1::GetTaskName(task).Data(), fOutput->GetName() )) ;
463
464         fDetectorDir = fOutput->GetDirectory(GetDetectorDirName()) ; 
465         if (!fDetectorDir)
466                 fDetectorDir = fOutput->mkdir(GetDetectorDirName()) ; 
467
468         TDirectory * subDir = fDetectorDir->GetDirectory(AliQAv1::GetTaskName(task)) ; 
469         if (!subDir)
470                 subDir = fDetectorDir->mkdir(AliQAv1::GetTaskName(task)) ;  
471   
472   for ( Int_t specie = AliRecoParam::kDefault ; specie < AliRecoParam::kNSpecies ; specie++ ) {
473     TDirectory * eventSpecieDir = subDir->GetDirectory(AliRecoParam::GetEventSpecieName(specie)) ; 
474     if (!eventSpecieDir) 
475       eventSpecieDir = subDir->mkdir(AliRecoParam::GetEventSpecieName(specie)) ; 
476     TDirectory * expertDir = eventSpecieDir->GetDirectory(AliQAv1::GetExpert()) ; 
477     if (!expertDir)
478       expertDir = eventSpecieDir->mkdir(AliQAv1::GetExpert()) ; 
479   } 
480         StartOfDetectorCycle() ; 
481 }