]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliQADataMakerSim.cxx
Made QA images persistent objects
[u/mrichter/AliRoot.git] / STEER / AliQADataMakerSim.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 notice   *
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. 
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 <TClonesArray.h>
31
32 // --- Standard library ---
33
34 // --- AliRoot header files ---
35 #include "AliLog.h"
36 #include "AliQADataMakerSim.h"
37
38 ClassImp(AliQADataMakerSim)
39              
40 //____________________________________________________________________________ 
41 AliQADataMakerSim::AliQADataMakerSim(const char * name, const char * title) : 
42   AliQADataMaker(name, title), 
43   fDigitsQAList(0x0), 
44   fHitsQAList(0x0),
45   fSDigitsQAList(0x0)
46 {
47         // ctor
48         fDetectorDirName = GetName() ; 
49 }
50
51 //____________________________________________________________________________ 
52 AliQADataMakerSim::AliQADataMakerSim(const AliQADataMakerSim& qadm) :
53   AliQADataMaker(qadm.GetName(), qadm.GetTitle()), 
54   fDigitsQAList(qadm.fDigitsQAList),
55   fHitsQAList(qadm.fHitsQAList),
56   fSDigitsQAList(qadm.fSDigitsQAList) 
57 {
58   //copy ctor
59   fDetectorDirName = GetName() ; 
60 }
61
62 //____________________________________________________________________________ 
63 AliQADataMakerSim::~AliQADataMakerSim()
64 {
65         //dtor: delete the TObjArray and thei content
66         if ( fDigitsQAList ) { 
67     for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
68       if ( fDigitsQAList[specie]->IsOwner() )
69                         fDigitsQAList[specie]->Delete() ;
70     }
71                 delete[] fDigitsQAList ;     
72         }
73         if ( fHitsQAList ) {
74     for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
75       if ( fHitsQAList[specie]->IsOwner() ) 
76                         fHitsQAList[specie]->Delete() ;
77     }
78                 delete[] fHitsQAList ;
79         }
80         if ( fSDigitsQAList ) { 
81     for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
82       if ( fSDigitsQAList[specie]->IsOwner() ) 
83                         fSDigitsQAList[specie]->Delete() ; 
84     }
85                 delete[] fSDigitsQAList ; 
86         }
87 }
88
89 //__________________________________________________________________
90 AliQADataMakerSim& AliQADataMakerSim::operator = (const AliQADataMakerSim& qadm )
91 {
92   // Assignment operator.
93   this->~AliQADataMakerSim();
94   new(this) AliQADataMakerSim(qadm);
95   return *this;
96 }
97
98 //____________________________________________________________________________
99 void AliQADataMakerSim::EndOfCycle() 
100
101   // Finishes a cycle of QA for all tasks
102   EndOfCycle(AliQAv1::kHITS) ; 
103   EndOfCycle(AliQAv1::kSDIGITS) ; 
104   EndOfCycle(AliQAv1::kDIGITS) ;
105   ResetCycle() ; 
106 }
107
108 //____________________________________________________________________________
109 void AliQADataMakerSim::EndOfCycle(AliQAv1::TASKINDEX_t task) 
110
111   // Finishes a cycle of QA data acquistion
112         TObjArray ** list = NULL ; 
113         
114         if ( task == AliQAv1::kHITS ) 
115                 list = fHitsQAList ; 
116         else if ( task == AliQAv1::kSDIGITS )
117                 list = fSDigitsQAList ; 
118         else if ( task == AliQAv1::kDIGITS ) 
119                 list = fDigitsQAList ; 
120   
121   if ( ! list ) 
122     return ; 
123         EndOfDetectorCycle(task, list) ; 
124   TDirectory * subDir = NULL ;
125         if (fDetectorDir) 
126     subDir = fDetectorDir->GetDirectory(AliQAv1::GetTaskName(task)) ; 
127         if (subDir) { 
128                 subDir->cd() ; 
129     for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
130       TDirectory * eventSpecieDir = subDir->GetDirectory(AliRecoParam::GetEventSpecieName(specie)) ;
131       if (eventSpecieDir) {
132         eventSpecieDir->cd() ; 
133         TIter next(list[specie]) ; 
134         TObject * obj ; 
135         while ( (obj = next()) )  {
136           if (!obj->TestBit(AliQAv1::GetExpertBit()))
137             obj->Write() ;
138         }
139         if (WriteExpert()) {
140           TDirectory * expertDir = eventSpecieDir->GetDirectory(AliQAv1::GetExpert()) ; 
141           if ( expertDir ) {
142             expertDir->cd() ;
143             next.Reset() ; 
144             while ( (obj = next()) ) {
145               if (!obj->TestBit(AliQAv1::GetExpertBit()))
146                 continue ; 
147             obj->Write() ;
148             }      
149           }
150         }
151       }
152     }
153     fOutput->Save() ; 
154   }
155   MakeImage(task) ; 
156 }
157  
158 //____________________________________________________________________________
159 void AliQADataMakerSim::Exec(AliQAv1::TASKINDEX_t task, TObject * data) 
160
161   // creates the quality assurance data for the various tasks (Hits, SDigits, Digits, ESDs)
162     
163         if ( task == AliQAv1::kHITS ) {  
164                 AliDebug(AliQAv1::GetQADebugLevel(), "Processing Hits QA") ; 
165                 TClonesArray * arr = dynamic_cast<TClonesArray *>(data) ; 
166                 if (arr) { 
167                         MakeHits(arr) ;
168                 } else {
169                         TTree * tree = dynamic_cast<TTree *>(data) ; 
170                         if (tree) {
171                                 MakeHits(tree) ; 
172                         } else {
173                                 AliWarning("data are neither a TClonesArray nor a TTree") ; 
174                         }
175                 }
176         } else if ( task == AliQAv1::kSDIGITS ) {
177                 AliDebug(AliQAv1::GetQADebugLevel(), "Processing SDigits QA") ; 
178                 TClonesArray * arr = dynamic_cast<TClonesArray *>(data) ; 
179                 if (arr) { 
180                         MakeSDigits(arr) ;
181                 } else {
182                         TTree * tree = dynamic_cast<TTree *>(data) ; 
183                         if (tree) {
184                                 MakeSDigits(tree) ; 
185                         } else {
186                                 AliWarning("data are neither a TClonesArray nor a TTree") ; 
187                         }
188                 }
189         } else if ( task == AliQAv1::kDIGITS ) {
190                 AliDebug(AliQAv1::GetQADebugLevel(), "Processing Digits QA") ; 
191                 TClonesArray * arr = dynamic_cast<TClonesArray *>(data) ; 
192                 if (arr) { 
193                         MakeDigits(arr) ;
194                 } else {
195                         TTree * tree = dynamic_cast<TTree *>(data) ; 
196                         if (tree) {
197                                 MakeDigits(tree) ; 
198                         } else {
199                                 AliWarning("data are neither a TClonesArray nor a TTree") ; 
200                         }
201                 }
202         }
203 }
204
205 //____________________________________________________________________________ 
206 void AliQADataMakerSim::MakeImage(AliQAv1::TASKINDEX_t task)
207 {
208   // create a drawing of detetor defined histograms
209   TObjArray ** list = NULL ;  
210   switch (task) {
211     case AliQAv1::kRAWS:
212       break;
213     case AliQAv1::kHITS:
214       list = fHitsQAList ;
215       break;
216     case AliQAv1::kSDIGITS:
217       list = fSDigitsQAList ;
218       break;  
219     case AliQAv1::kDIGITS:
220       list = fDigitsQAList ;
221       break;  
222     case AliQAv1::kDIGITSR:
223       break;
224     case AliQAv1::kRECPOINTS:
225       break;
226     case AliQAv1::kTRACKSEGMENTS:
227       break;
228     case AliQAv1::kRECPARTICLES:
229       break;
230     case AliQAv1::kESDS:
231       break;
232     case AliQAv1::kNTASKINDEX:
233       break;
234     default:
235     break;
236   }
237   if ( !list) {
238     AliFatal("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       if ( !fImage[esIndex] ) {
256         fImage[esIndex] = new TCanvas(Form("QA_%s_%s_%s", 
257                                            GetName(), 
258                                            AliQAv1::GetTaskName(task).Data(), 
259                                            AliRecoParam::GetEventSpecieName(esIndex)), 
260                                       Form("QA control plots for det=%s task=%s eventspecie=%s", 
261                                            GetName(), 
262                                            AliQAv1::GetTaskName(task).Data(), 
263                                            AliRecoParam::GetEventSpecieName(esIndex)), 
264                                       w, h) ;
265         fImage[esIndex]->SetWindowSize(w + (w - fImage[esIndex]->GetWw()), h + (h - fImage[esIndex]->GetWh())) ;
266         Int_t nx = TMath::Sqrt(nImages) ; 
267         Int_t ny = nx  ; 
268         if ( nx < TMath::Sqrt(nImages)) 
269           ny++ ; 
270         fImage[esIndex]->Divide(nx, ny) ; 
271       }
272       fImage[esIndex]->Clear() ; 
273       TIter nexthist(list[esIndex]) ; 
274       TH1* hist = NULL ;
275       Int_t npad = 1 ; 
276       fImage[esIndex]->cd(npad) ; 
277       while ( (hist=dynamic_cast<TH1*>(nexthist())) ) {
278         if(hist->TestBit(AliQAv1::GetImageBit())) {
279           hist->Draw() ; 
280           fImage[esIndex]->cd(++npad) ; 
281         }
282       }
283       if (fPrintImage) 
284         fImage[esIndex]->Print() ; 
285     }
286   }
287 }
288
289 //____________________________________________________________________________ 
290 TObjArray **  AliQADataMakerSim::Init(AliQAv1::TASKINDEX_t task, Int_t cycles)
291 {
292   // general intialisation
293         
294         if (cycles > 0)
295                 SetCycle(cycles) ;  
296         TObjArray ** rv = NULL ; 
297         if ( task == AliQAv1::kHITS ) {
298                 if ( ! fHitsQAList ) {
299       fHitsQAList = new TObjArray *[AliRecoParam::kNSpecies] ; 
300       for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
301         fHitsQAList[specie] = new TObjArray(100) ;       
302         fHitsQAList[specie]->SetName(Form("%s_%s_%s", GetName(), AliQAv1::GetTaskName(task).Data(), AliRecoParam::GetEventSpecieName(specie))) ;
303       }
304                         InitHits() ;
305                 }
306                 rv = fHitsQAList ;
307         } else if ( task == AliQAv1::kSDIGITS ) {
308                 if ( ! fSDigitsQAList ) {
309       fSDigitsQAList = new TObjArray *[AliRecoParam::kNSpecies] ; 
310       for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
311         fSDigitsQAList[specie] = new TObjArray(100) ; 
312         fSDigitsQAList[specie]->SetName(Form("%s_%s_%s", GetName(), AliQAv1::GetTaskName(task).Data(), AliRecoParam::GetEventSpecieName(specie))) ; 
313       }
314       InitSDigits() ;
315                 }
316                 rv = fSDigitsQAList ;
317    } else if ( task == AliQAv1::kDIGITS ) {
318            if ( ! fDigitsQAList ) {
319        fDigitsQAList = new TObjArray *[AliRecoParam::kNSpecies] ; 
320        for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {    
321          fDigitsQAList[specie] = new TObjArray(100) ;
322          fDigitsQAList[specie]->SetName(Form("%s_%s_%s", GetName(), AliQAv1::GetTaskName(task).Data(), AliRecoParam::GetEventSpecieName(specie))) ;
323        }
324                    InitDigits() ;
325            }
326            rv =  fDigitsQAList ;
327    }
328   
329         return rv ; 
330 }
331
332 //____________________________________________________________________________ 
333 void AliQADataMakerSim::Init(AliQAv1::TASKINDEX_t task, TObjArray ** list, Int_t run, Int_t cycles)
334 {
335   // Intialisation by passing the list of QA data booked elsewhere
336   
337         fRun = run ;
338         if (cycles > 0)
339                 SetCycle(cycles) ;  
340         
341         if ( task == AliQAv1::kHITS ) {
342                 fHitsQAList = list ;     
343         } else if ( task == AliQAv1::kSDIGITS) {
344                 fSDigitsQAList = list ; 
345         } else if ( task == AliQAv1::kDIGITS ) {
346                 fDigitsQAList = list ; 
347         } 
348 }
349
350 //____________________________________________________________________________
351 void AliQADataMakerSim::StartOfCycle(Int_t run) 
352
353   // Finishes a cycle of QA for all tasks
354   Bool_t samecycle = kFALSE ; 
355   StartOfCycle(AliQAv1::kHITS,    run, samecycle) ;
356   samecycle = kTRUE ; 
357   StartOfCycle(AliQAv1::kSDIGITS, run, samecycle) ;
358   StartOfCycle(AliQAv1::kDIGITS,  run, samecycle) ;
359 }
360
361 //____________________________________________________________________________
362 void AliQADataMakerSim::StartOfCycle(AliQAv1::TASKINDEX_t task, Int_t run, const Bool_t sameCycle) 
363
364   // Finishes a cycle of QA data acquistion
365   if ( run > 0 ) 
366     fRun = run ; 
367         if ( !sameCycle || fCurrentCycle == -1) {
368                 ResetCycle() ;
369         if (fOutput) 
370                 fOutput->Close() ; 
371         fOutput = AliQAv1::GetQADataFile(GetName(), fRun) ;     
372         }       
373
374         AliDebug(AliQAv1::GetQADebugLevel(), Form(" Run %d Cycle %d task %s file %s", 
375                                  fRun, fCurrentCycle, AliQAv1::GetTaskName(task).Data(), fOutput->GetName() )) ;
376
377         fDetectorDir = fOutput->GetDirectory(GetDetectorDirName()) ; 
378         if (!fDetectorDir)
379                 fDetectorDir = fOutput->mkdir(GetDetectorDirName()) ; 
380
381         TDirectory * subDir = fDetectorDir->GetDirectory(AliQAv1::GetTaskName(task)) ; 
382         if (!subDir)
383                 subDir = fDetectorDir->mkdir(AliQAv1::GetTaskName(task)) ;  
384   
385   for ( Int_t index = AliRecoParam::kDefault ; index < AliRecoParam::kNSpecies ; index++ ) {
386     TDirectory * eventSpecieDir = subDir->GetDirectory(AliRecoParam::GetEventSpecieName(index)) ; 
387     if (!eventSpecieDir) 
388       eventSpecieDir = subDir->mkdir(AliRecoParam::GetEventSpecieName(index)) ; 
389     TDirectory * expertDir = eventSpecieDir->GetDirectory(AliQAv1::GetExpert()) ; 
390     if (!expertDir) 
391       expertDir = eventSpecieDir->mkdir(AliQAv1::GetExpert()) ; 
392    }   
393         StartOfDetectorCycle() ; 
394 }