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