]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliQADataMakerRec.cxx
Added QA for digits during reconstruction (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   fDigitsQAList(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   fESDsQAList(qadm.fESDsQAList),
66   fRawsQAList(qadm.fRawsQAList),
67   fDigitsQAList(qadm.fDigitsQAList),
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   if ( AliDebugLevel()  == AliQAv1::GetQADebugLevel() ) 
201     MakeImage(task) ; 
202 }
203
204 //____________________________________________________________________________ 
205 void AliQADataMakerRec::MakeImage(AliQAv1::TASKINDEX_t task)
206 {
207   // create a drawing of detetor defined histograms
208   TObjArray ** list = NULL ;  
209   switch (task) {
210     case AliQAv1::kRAWS:
211       list = fRawsQAList ; 
212       break;
213     case AliQAv1::kHITS:
214       break;
215     case AliQAv1::kSDIGITS:
216       break;  
217     case AliQAv1::kDIGITS:
218       break;  
219     case AliQAv1::kDIGITSR:
220       list = fDigitsQAList ; 
221       break;  
222     case AliQAv1::kRECPOINTS:
223       list = fRecPointsQAList ; 
224       break;
225     case AliQAv1::kTRACKSEGMENTS:
226       break;
227     case AliQAv1::kRECPARTICLES:
228       break;
229     case AliQAv1::kESDS:
230       list = fESDsQAList ; 
231       break;
232     case AliQAv1::kNTASKINDEX:
233       break;
234     default:
235       break;
236   }
237   if ( !list) {
238     AliError("data not initialized, call AliQADataMaker::Init"); 
239     return ; 
240   }
241   TIter next(list[0]) ;  
242   TH1 * hdata = NULL ; 
243   Int_t nImages = 0 ;
244   while ( (hdata=dynamic_cast<TH1 *>(next())) ) {
245     if ( hdata->TestBit(AliQAv1::GetImageBit()) )
246       nImages++; 
247   }
248   if ( nImages == 0 ) {
249     AliWarning(Form("No histogram will be plotted for %s %s\n", GetName(), AliQAv1::GetTaskName(task).Data())) ;  
250   } else {
251     AliDebug(AliQAv1::GetQADebugLevel(), Form("%d histograms will be plotted for %s %s\n", nImages, GetName(), AliQAv1::GetTaskName(task).Data())) ;  
252     Double_t w  = 1000 ;
253     Double_t h  = 1000 ;
254     for (Int_t esIndex = 0 ; esIndex < AliRecoParam::kNSpecies ; esIndex++) {
255       TCanvas * canvasQA = 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       canvasQA->SetWindowSize(w + (w - canvasQA->GetWw()), h + (h - canvasQA->GetWh())) ;
265       Int_t nx = TMath::Sqrt(nImages) ; 
266       Int_t ny = nx  ; 
267       if ( nx < TMath::Sqrt(nImages)) 
268         ny++ ; 
269       canvasQA->Divide(nx, ny) ; 
270       TIter nexthist(list[esIndex]) ; 
271       TH1* hist = NULL ;
272       Int_t npad = 1 ; 
273       canvasQA->cd(npad) ; 
274       while ( (hist=dynamic_cast<TH1*>(nexthist())) ) {
275         if(hist->TestBit(AliQAv1::GetImageBit())) {
276           hist->Draw() ; 
277           canvasQA->cd(++npad) ; 
278         }
279       }
280       canvasQA->Print() ; 
281     }
282   }
283 }
284
285 //____________________________________________________________________________
286 void AliQADataMakerRec::Exec(AliQAv1::TASKINDEX_t task, TObject * data) 
287
288   // creates the quality assurance data for the various tasks (Hits, SDigits, Digits, ESDs)
289         
290         if ( task == AliQAv1::kRAWS ) {
291                 AliDebug(AliQAv1::GetQADebugLevel(), "Processing Raws QA") ; 
292                 AliRawReader * rawReader = dynamic_cast<AliRawReader *>(data) ; 
293                 if (rawReader) 
294                         MakeRaws(rawReader) ;
295                 else
296       AliDebug(AliQAv1::GetQADebugLevel(), "Raw data are not processed") ;     
297         } else if ( task == AliQAv1::kDIGITSR ) {
298                 AliDebug(AliQAv1::GetQADebugLevel(), "Processing Digits QA") ; 
299                 TTree * tree = dynamic_cast<TTree *>(data) ; 
300                 if (tree) {
301                         MakeDigits(tree) ; 
302                 } else {
303                         AliWarning("data are not a TTree") ; 
304                 }
305         } else if ( task == AliQAv1::kRECPOINTS ) {
306                 AliDebug(AliQAv1::GetQADebugLevel(), "Processing RecPoints QA") ; 
307                 TTree * tree = dynamic_cast<TTree *>(data) ; 
308                 if (tree) {
309                         MakeRecPoints(tree) ; 
310                 } else {
311                         AliWarning("data are not a TTree") ; 
312                 }
313         } else if ( task == AliQAv1::kESDS ) {
314                 AliDebug(AliQAv1::GetQADebugLevel(), "Processing ESDs QA") ; 
315                 AliESDEvent * esd = dynamic_cast<AliESDEvent *>(data) ; 
316                 if (esd) 
317                         MakeESDs(esd) ;
318                 else 
319                         AliError("Wrong type of esd container") ; 
320         }  
321 }
322
323 //____________________________________________________________________________ 
324 TObjArray **  AliQADataMakerRec::Init(AliQAv1::TASKINDEX_t task, Int_t cycles)
325 {
326   // general intialisation
327   InitRecoParams() ;
328         TObjArray ** rv = NULL ; 
329   
330         if (cycles > 0)
331                 SetCycle(cycles) ;  
332         
333         if ( task == AliQAv1::kRAWS ) {
334                 if (! fRawsQAList ) { 
335       fRawsQAList = new TObjArray *[AliRecoParam::kNSpecies] ; 
336       for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
337         fRawsQAList[specie] = new TObjArray(100) ;       
338         fRawsQAList[specie]->SetName(Form("%s_%s_%s", GetName(), AliQAv1::GetTaskName(task).Data(), AliRecoParam::GetEventSpecieName(specie))) ;
339       }
340                         InitRaws() ;
341                 }
342                 rv = fRawsQAList ;
343         } else if ( task == AliQAv1::kDIGITSR ) {
344                 if ( ! fDigitsQAList ) {
345       fDigitsQAList = new TObjArray *[AliRecoParam::kNSpecies] ; 
346       for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
347         fDigitsQAList[specie] = new TObjArray(100) ; 
348         fDigitsQAList[specie]->SetName(Form("%s_%s_%s", GetName(), AliQAv1::GetTaskName(task).Data(), AliRecoParam::GetEventSpecieName(specie))) ; 
349       }
350       InitDigits() ;
351                 }
352                 rv = fDigitsQAList ;
353         } else if ( task == AliQAv1::kRECPOINTS ) {
354                 if ( ! fRecPointsQAList ) {
355       fRecPointsQAList = new TObjArray *[AliRecoParam::kNSpecies] ; 
356       for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
357         fRecPointsQAList[specie] = new TObjArray(100) ; 
358         fRecPointsQAList[specie]->SetName(Form("%s_%s_%s", GetName(), AliQAv1::GetTaskName(task).Data(), AliRecoParam::GetEventSpecieName(specie))) ; 
359       }
360       InitRecPoints() ;
361                 }
362                 rv = fRecPointsQAList ;
363         } else if ( task == AliQAv1::kESDS ) {
364                 if ( ! fESDsQAList ) {
365       fESDsQAList = new TObjArray *[AliRecoParam::kNSpecies] ; 
366       for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
367         fESDsQAList[specie] = new TObjArray(100) ;
368         fESDsQAList[specie]->SetName(Form("%s_%s", GetName(), AliQAv1::GetTaskName(task).Data(), AliRecoParam::GetEventSpecieName(specie))) ; 
369       }
370                         InitESDs() ;
371                 }
372                 rv = fESDsQAList ;
373         }
374         return rv ; 
375 }
376
377 //____________________________________________________________________________ 
378 void AliQADataMakerRec::Init(AliQAv1::TASKINDEX_t task, TObjArray ** list, Int_t run, Int_t cycles)
379 {
380   // Intialisation by passing the list of QA data booked elsewhere
381   
382   InitRecoParams() ;
383   fRun = run ;
384         if (cycles > 0)
385                 SetCycle(cycles) ;  
386         
387         if ( task == AliQAv1::kRAWS ) {
388                 fRawsQAList = list ;     
389         } else if ( task == AliQAv1::kDIGITSR ) {
390                 fDigitsQAList = list ; 
391         } else if ( task == AliQAv1::kRECPOINTS ) {
392                 fRecPointsQAList = list ; 
393         } else if ( task == AliQAv1::kESDS ) {
394                 fESDsQAList = list ; 
395         }
396 }
397
398 //____________________________________________________________________________
399 void AliQADataMakerRec::InitRecoParams() 
400 {
401   if (!fRecoParam) {
402     AliDebug(AliQAv1::GetQADebugLevel(), Form("Loading reconstruction parameter objects for detector %s", GetName()));
403     AliCDBPath path(GetName(),"Calib","RecoParam");
404     AliCDBEntry *entry=AliCDBManager::Instance()->Get(path.GetPath());
405     if(!entry) {
406       fRecoParam = NULL ; 
407       AliWarning(Form("Couldn't find RecoParam entry in OCDB for detector %s",GetName()));
408     }
409     else {
410       TObject * recoParamObj = entry->GetObject() ; 
411       if (dynamic_cast<TObjArray*>(recoParamObj)) {
412         // The detector has only one set of reco parameters
413         AliDebug(AliQAv1::GetQADebugLevel(), Form("Array of reconstruction parameters found for detector %s",GetName()));
414         TObjArray *recoParamArray = dynamic_cast<TObjArray*>(recoParamObj) ;
415         for (Int_t iRP=0; iRP<recoParamArray->GetEntriesFast(); iRP++) {
416           fRecoParam = dynamic_cast<AliDetectorRecoParam*>(recoParamArray->At(iRP)) ;
417           if (fRecoParam->IsDefault()) break;
418         }
419       }
420       else if (dynamic_cast<AliDetectorRecoParam*>(recoParamObj)) {
421         // The detector has only onse set of reco parameters
422         // Registering it in AliRecoParam
423         AliDebug(AliQAv1::GetQADebugLevel(), Form("Single set of reconstruction parameters found for detector %s",GetName()));
424         dynamic_cast<AliDetectorRecoParam*>(recoParamObj)->SetAsDefault();
425         fRecoParam = dynamic_cast<AliDetectorRecoParam*>(recoParamObj) ;
426       } else { 
427         AliError(Form("No valid RecoParam object found in the OCDB for detector %s",GetName()));
428       }
429     }
430     AliCDBManager::Instance()->UnloadFromCache(path.GetPath());
431   }
432 }
433
434 //____________________________________________________________________________
435 void AliQADataMakerRec::StartOfCycle(Int_t run) 
436 {
437   // Finishes a cycle of QA for all the tasks
438   Bool_t samecycle = kFALSE ; 
439   StartOfCycle(AliQAv1::kRAWS,      run, samecycle) ;
440   samecycle = kTRUE ; 
441   StartOfCycle(AliQAv1::kDIGITSR,   run, samecycle) ; 
442   StartOfCycle(AliQAv1::kRECPOINTS, run, samecycle) ; 
443   StartOfCycle(AliQAv1::kESDS,      run, samecycle) ; 
444 }
445
446 //____________________________________________________________________________
447 void AliQADataMakerRec::StartOfCycle(AliQAv1::TASKINDEX_t task, Int_t run, const Bool_t sameCycle) 
448
449   // Finishes a cycle of QA data acquistion
450   if ( run > 0 ) 
451     fRun = run ; 
452         if ( !sameCycle || fCurrentCycle == -1) {
453                 ResetCycle() ;
454                 if (fOutput) 
455                         fOutput->Close() ; 
456                 fOutput = AliQAv1::GetQADataFile(GetName(), fRun) ;     
457         }       
458         AliDebug(AliQAv1::GetQADebugLevel(), Form(" Run %d Cycle %d task %s file %s", 
459                                  fRun, fCurrentCycle, AliQAv1::GetTaskName(task).Data(), fOutput->GetName() )) ;
460
461         fDetectorDir = fOutput->GetDirectory(GetDetectorDirName()) ; 
462         if (!fDetectorDir)
463                 fDetectorDir = fOutput->mkdir(GetDetectorDirName()) ; 
464
465         TDirectory * subDir = fDetectorDir->GetDirectory(AliQAv1::GetTaskName(task)) ; 
466         if (!subDir)
467                 subDir = fDetectorDir->mkdir(AliQAv1::GetTaskName(task)) ;  
468   
469   for ( Int_t specie = AliRecoParam::kDefault ; specie < AliRecoParam::kNSpecies ; specie++ ) {
470     TDirectory * eventSpecieDir = subDir->GetDirectory(AliRecoParam::GetEventSpecieName(specie)) ; 
471     if (!eventSpecieDir) 
472       eventSpecieDir = subDir->mkdir(AliRecoParam::GetEventSpecieName(specie)) ; 
473     TDirectory * expertDir = eventSpecieDir->GetDirectory(AliQAv1::GetExpert()) ; 
474     if (!expertDir)
475       expertDir = eventSpecieDir->mkdir(AliQAv1::GetExpert()) ; 
476   } 
477         StartOfDetectorCycle() ; 
478 }