]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliQADataMaker.cxx
bring back some functionality which was deleted by accident
[u/mrichter/AliRoot.git] / STEER / AliQADataMaker.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 <TROOT.h> 
28 #include <TCanvas.h> 
29 #include <TPaveText.h>
30 #include <TSystem.h> 
31 #include <TFile.h>
32 #include <TList.h> 
33 #include <TTree.h>
34 #include <TClonesArray.h>
35 #include <TParameter.h>
36 #include <TH1K.h>
37 #include <TH2C.h>
38 #include <TH2D.h>
39 #include <TH2F.h>
40 #include <TH2I.h>
41 #include <TH3C.h>
42 #include <TH3D.h>
43 #include <TH3F.h>
44 #include <TH3I.h>
45 #include <TH3S.h>
46
47 // --- Standard library ---
48
49 // --- AliRoot header files ---
50 #include "AliLog.h"
51 #include "AliQADataMaker.h"
52 #include "AliQAChecker.h"
53 #include "AliESDEvent.h"
54 #include "AliRawReader.h"
55 #include "AliDetectorRecoParam.h"
56
57
58 ClassImp(AliQADataMaker)
59              
60 //____________________________________________________________________________ 
61 AliQADataMaker::AliQADataMaker(const Char_t * name, const Char_t * title) : 
62   TNamed(name, title), 
63   fOutput(0x0),
64   fDetectorDir(0x0),
65   fDetectorDirName(""), 
66   fCurrentCycle(0), 
67   fCycle(9999999), 
68   fCycleCounter(0), 
69   fWriteExpert(kFALSE),
70   fParameterList(new TList*[AliRecoParam::kNSpecies]), 
71   fRun(0), 
72   fEventSpecie(AliRecoParam::kDefault), 
73   fImage(new TCanvas*[AliRecoParam::kNSpecies]), 
74   fPrintImage(kTRUE), 
75   fDigitsArray(NULL) 
76 {
77   // ctor
78   fDetectorDirName = GetName() ; 
79     for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
80       fParameterList[specie] = NULL ; 
81       fImage[specie] = NULL ; 
82     }
83 }
84
85 //____________________________________________________________________________ 
86 AliQADataMaker::AliQADataMaker(const AliQADataMaker& qadm) :
87   TNamed(qadm.GetName(), qadm.GetTitle()),
88   fOutput(qadm.fOutput),
89   fDetectorDir(qadm.fDetectorDir),
90   fDetectorDirName(qadm.fDetectorDirName),
91   fCurrentCycle(qadm.fCurrentCycle), 
92   fCycle(qadm.fCycle), 
93   fCycleCounter(qadm.fCycleCounter), 
94   fWriteExpert(qadm.fWriteExpert),
95   fParameterList(qadm.fParameterList),  
96   fRun(qadm.fRun), 
97   fEventSpecie(qadm.fEventSpecie), 
98   fImage(NULL),  
99   fPrintImage(kTRUE),
100   fDigitsArray(NULL) 
101 {
102   //copy ctor
103   fDetectorDirName = GetName() ; 
104   for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
105     fParameterList[specie] = qadm.fParameterList[specie] ; 
106     fImage[specie] = qadm.fImage[specie] ; 
107   }
108 }
109
110 //____________________________________________________________________________ 
111 AliQADataMaker::~AliQADataMaker()
112 {
113   for (Int_t esIndex = 0 ; esIndex < AliRecoParam::kNSpecies ; esIndex++) {
114     if ( fImage[esIndex] ) 
115       delete fImage[esIndex] ;
116     if (fParameterList[esIndex] )
117       delete fParameterList[esIndex] ; 
118   }
119   delete[] fImage ; 
120   delete[] fParameterList ; 
121
122   if (fDigitsArray) {
123     fDigitsArray->Clear() ; 
124     delete fDigitsArray ;
125   }
126 }
127
128 //____________________________________________________________________________
129 Int_t AliQADataMaker::Add2List(TH1 * hist, const Int_t index, TObjArray ** list, const Bool_t expert, const Bool_t image, const Bool_t saveForCorr) 
130
131         // Set histograms memory resident and add to the list
132         // Maximm allowed is 10000
133   
134   Int_t rv = -1 ; 
135   TClass * classType = hist->Class() ;
136   TString className(classType->GetName()) ; 
137   if( ! className.BeginsWith("T") && ! classType->InheritsFrom("TH1") ) {
138     AliError(Form("QA data Object must be a generic ROOT object and derive fom TH1 and not %s", className.Data())) ; 
139         } else if ( index > AliQAv1::GetMaxQAObj() ) {
140                 AliError(Form("Max number of authorized QA objects is %d", AliQAv1::GetMaxQAObj())) ; 
141   } else {
142     hist->SetDirectory(0) ; 
143     if (expert) 
144       hist->SetBit(AliQAv1::GetExpertBit()) ;
145     if (image) 
146       hist->SetBit(AliQAv1::GetImageBit()) ;  
147     const Char_t * name = Form("%s_%s", AliRecoParam::GetEventSpecieName(fEventSpecie), hist->GetName()) ;
148     hist->SetName(name) ; 
149     if(saveForCorr) {  
150       const Char_t * cname = Form("%s_%s", list[AliRecoParam::AConvert(AliRecoParam::kDefault)]->GetName(), hist->GetName()) ;  
151       TParameter<double> * p = new TParameter<double>(cname, 9999.9999) ;
152       if ( fParameterList[AliRecoParam::AConvert(fEventSpecie)] == NULL )
153         fParameterList[AliRecoParam::AConvert(fEventSpecie)] = new TList() ; 
154       fParameterList[AliRecoParam::AConvert(fEventSpecie)]->Add(p) ;
155     }
156     list[AliRecoParam::AConvert(fEventSpecie)]->AddAtAndExpand(hist, index) ; 
157     rv = list[AliRecoParam::AConvert(fEventSpecie)]->GetLast() ;
158   }
159   return rv ; 
160 }
161
162 //____________________________________________________________________________
163 TH1 *  AliQADataMaker::CloneMe(TH1 * hist, Int_t specie) const  
164 {
165   // clones a histogram 
166   const Char_t * name = Form("%s_%s", AliRecoParam::GetEventSpecieName(specie), hist->GetName()) ;
167   TH1 * hClone = static_cast<TH1 *>(hist->Clone(name)) ; 
168   if ( hist->TestBit(AliQAv1::GetExpertBit()) )
169     hClone->SetBit(AliQAv1::GetExpertBit()) ; 
170   if ( hist->TestBit(AliQAv1::GetImageBit()) )
171     hClone->SetBit(AliQAv1::GetImageBit()) ; 
172   return hClone ; 
173 }
174
175 //____________________________________________________________________________
176 void AliQADataMaker::DefaultEndOfDetectorCycle(AliQAv1::TASKINDEX_t task) 
177 {
178         // this method must be oveloaded by detectors
179         // sets the QA result to Fatal
180         AliQAv1::Instance(AliQAv1::GetDetIndex(GetName())) ;
181         AliQAv1 * qa = AliQAv1::Instance(task) ;
182   for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) 
183     qa->Set(AliQAv1::kFATAL, specie) ; 
184         AliQAv1::GetQAResultFile()->cd() ; 
185         qa->Write(AliQAv1::GetQAName(), kWriteDelete) ;   
186         AliQAv1::GetQAResultFile()->Close() ; 
187 }
188
189 //____________________________________________________________________________ 
190 void AliQADataMaker::Finish() const 
191
192         // write to the output File
193         if (fOutput) 
194                 fOutput->Close() ; 
195
196
197 //____________________________________________________________________________ 
198 TObject * AliQADataMaker::GetData(TObjArray ** list, const Int_t index)  
199
200         // Returns the QA object at index. Limit is AliQAv1::GetMaxQAObj() 
201   if ( ! list ) {
202                 AliError("Data list is NULL !!") ; 
203                 return NULL ;           
204         }
205
206   SetEventSpecie(fEventSpecie) ;  
207   Int_t esindex = AliRecoParam::AConvert(fEventSpecie) ; 
208   TH1 * histClone = NULL ; 
209   TObjArray * arr = list[esindex] ; 
210         if (arr) {
211     if ( ! arr->GetEntriesFast() ) {
212       // Initializes the histograms 
213       TString arrName(arr->GetName()) ; 
214       if (arrName.Contains(AliQAv1::GetTaskName(AliQAv1::kRAWS)))
215         InitRaws() ; 
216       else if (arrName.Contains(AliQAv1::GetTaskName(AliQAv1::kHITS)))
217         InitHits() ; 
218       else if (arrName.Contains(AliQAv1::GetTaskName(AliQAv1::kSDIGITS)))
219         InitSDigits() ; 
220       else if (arrName.Contains(AliQAv1::GetTaskName(AliQAv1::kDIGITS)))
221         InitDigits() ; 
222       else if (arrName.Contains(AliQAv1::GetTaskName(AliQAv1::kDIGITSR)))
223         InitSDigits() ; 
224       else if (arrName.Contains(AliQAv1::GetTaskName(AliQAv1::kRECPOINTS)))
225         InitRecPoints() ; 
226       else if (arrName.Contains(AliQAv1::GetTaskName(AliQAv1::kESDS)))
227         InitESDs() ; 
228     }
229                 if ( index > AliQAv1::GetMaxQAObj() ) {
230                         AliError(Form("Max number of authorized QA objects is %d", AliQAv1::GetMaxQAObj())) ; 
231                 } else {
232       if ( arr->At(index) )  {
233         histClone = static_cast<TH1*>(arr->At(index)) ; 
234       }         
235     }
236   }
237   return histClone ;            
238 }
239
240 //____________________________________________________________________________ 
241 TObjArray*  AliQADataMaker::Init(AliQAv1::TASKINDEX_t task, AliRecoParam::EventSpecie_t es, Int_t cycles)
242 {
243   // Initialializes and  returns the QAData list for a given event specie
244   TObjArray ** ar = Init(task, cycles) ; 
245   return ar[AliRecoParam::AConvert(es)] ;  
246 }
247
248 //____________________________________________________________________________ 
249 Bool_t AliQADataMaker::IsValidEventSpecie(Int_t eventSpecieIndex, TObjArray ** list)
250 {
251   // check if event specie was present in current run or 
252   // if histograms of this event specie have been created
253   if (! AliQAv1::Instance(AliQAv1::GetDetIndex(GetName()))->IsEventSpecieSet(AliRecoParam::ConvertIndex(eventSpecieIndex)) || ! list[eventSpecieIndex]->GetEntriesFast() )
254     return kFALSE ;
255   else
256     return kTRUE ;
257 }
258
259 //____________________________________________________________________________ 
260 void AliQADataMaker::MakeTheImage( TObjArray ** list, AliQAv1::TASKINDEX_t task, const Char_t * mode) 
261 {
262   // makes the QA image for sim and rec
263   TIter next(list[AliRecoParam::AConvert(fEventSpecie)]) ;  
264   TH1 * hdata = NULL ; 
265   Int_t nImages = 0 ;
266   while ( (hdata=static_cast<TH1 *>(next())) ) {
267     TString cln(hdata->ClassName()) ; 
268     if ( ! cln.Contains("TH1") )
269       continue ; 
270     if ( hdata->TestBit(AliQAv1::GetImageBit()) )
271       nImages++; 
272   }
273   if ( nImages == 0 ) {
274     AliDebug(AliQAv1::GetQADebugLevel(), Form("No histogram will be plotted for %s %s\n", GetName(), AliQAv1::GetTaskName(task).Data())) ;  
275   } else {
276     AliDebug(AliQAv1::GetQADebugLevel(), Form("%d histograms will be plotted for %s %s\n", nImages, GetName(), AliQAv1::GetTaskName(task).Data())) ;  
277     for (Int_t esIndex = 0 ; esIndex < AliRecoParam::kNSpecies ; esIndex++) {
278       if (! AliQAv1::Instance(AliQAv1::GetDetIndex(GetName()))->IsEventSpecieSet(AliRecoParam::ConvertIndex(esIndex)) ) 
279         continue ;
280       const Char_t * title = Form("QA_%s_%s_%s", GetName(), AliQAv1::GetTaskName(task).Data(), AliRecoParam::GetEventSpecieName(esIndex)) ; 
281       if ( !fImage[esIndex] ) {
282         fImage[esIndex] = new TCanvas(title, title) ;
283       }
284       fImage[esIndex]->Clear() ; 
285       fImage[esIndex]->SetTitle(title) ; 
286       fImage[esIndex]->cd() ; 
287       TPaveText someText(0.015, 0.015, 0.98, 0.98) ;
288       someText.AddText(title) ;
289       someText.Draw() ; 
290       fImage[esIndex]->Print(Form("%s%s%d.%s", AliQAv1::GetImageFileName(), mode, fRun, AliQAv1::GetImageFileFormat())) ; 
291       fImage[esIndex]->Clear() ; 
292       Int_t nx = TMath::Sqrt(nImages) ; 
293       Int_t ny = nx  ; 
294       if ( nx < TMath::Sqrt(nImages)) 
295         ny++ ; 
296       fImage[esIndex]->Divide(nx, ny) ; 
297       TIter nexthist(list[esIndex]) ; 
298       TH1* hist = NULL ;
299       Int_t npad = 1 ; 
300       fImage[esIndex]->cd(npad) ; 
301       while ( (hist=static_cast<TH1*>(nexthist())) ) {
302         TString cln(hist->ClassName()) ; 
303         if ( ! cln.Contains("TH1") )
304           continue ; 
305         if(hist->TestBit(AliQAv1::GetImageBit())) {
306           hist->Draw() ; 
307           fImage[esIndex]->cd(++npad) ; 
308         }
309       }
310       fImage[esIndex]->Print(Form("%s%s%d.%s", AliQAv1::GetImageFileName(), mode, fRun, AliQAv1::GetImageFileFormat())) ; 
311     }
312   }  
313 }