]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliQADataMaker.cxx
Warnings corrected.
[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 {
76   // ctor
77   fDetectorDirName = GetName() ; 
78     for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
79       fParameterList[specie] = NULL ; 
80       fImage[specie] = NULL ; 
81     }
82 }
83
84 //____________________________________________________________________________ 
85 AliQADataMaker::AliQADataMaker(const AliQADataMaker& qadm) :
86   TNamed(qadm.GetName(), qadm.GetTitle()),
87   fOutput(qadm.fOutput),
88   fDetectorDir(qadm.fDetectorDir),
89   fDetectorDirName(qadm.fDetectorDirName),
90   fCurrentCycle(qadm.fCurrentCycle), 
91   fCycle(qadm.fCycle), 
92   fCycleCounter(qadm.fCycleCounter), 
93   fWriteExpert(qadm.fWriteExpert),
94   fParameterList(qadm.fParameterList),  
95   fRun(qadm.fRun), 
96   fEventSpecie(qadm.fEventSpecie), 
97   fImage(qadm.fImage),  
98   fPrintImage(kTRUE)
99
100 {
101   //copy ctor
102   fDetectorDirName = GetName() ; 
103   for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
104     fParameterList[specie] = qadm.fParameterList[specie] ; 
105     fImage[specie] = qadm.fImage[specie] ; 
106   }
107 }
108
109 //____________________________________________________________________________ 
110 AliQADataMaker::~AliQADataMaker()
111 {
112   for (Int_t esIndex = 0 ; esIndex < AliRecoParam::kNSpecies ; esIndex++) {
113     if ( fImage[esIndex] ) 
114       delete fImage[esIndex] ;
115     if (fParameterList[esIndex] )
116       delete fParameterList[esIndex] ; 
117   }
118   delete[] fImage ; 
119   delete[] fParameterList ; 
120 }
121
122 //____________________________________________________________________________
123 Int_t AliQADataMaker::Add2List(TH1 * hist, const Int_t index, TObjArray ** list, const Bool_t expert, const Bool_t image, const Bool_t saveForCorr) 
124
125         // Set histograms memory resident and add to the list
126         // Maximm allowed is 10000
127   
128   Int_t rv = -1 ; 
129   TClass * classType = hist->Class() ;
130   TString className(classType->GetName()) ; 
131   if( ! className.BeginsWith("T") && ! classType->InheritsFrom("TH1") ) {
132     AliError(Form("QA data Object must be a generic ROOT object and derive fom TH1 and not %s", className.Data())) ; 
133         } else if ( index > 10000 ) {
134                 AliError("Max number of authorized QA objects is 10000") ; 
135   } else {
136     hist->SetDirectory(0) ; 
137     if (expert) 
138       hist->SetBit(AliQAv1::GetExpertBit()) ;
139     if (image) 
140       hist->SetBit(AliQAv1::GetImageBit()) ;  
141     const Char_t * name = Form("%s_%s", AliRecoParam::GetEventSpecieName(fEventSpecie), hist->GetName()) ;
142     hist->SetName(name) ; 
143     if(saveForCorr) {  
144       const Char_t * cname = Form("%s_%s", list[AliRecoParam::AConvert(AliRecoParam::kDefault)]->GetName(), hist->GetName()) ;  
145       TParameter<double> * p = new TParameter<double>(cname, 9999.9999) ;
146       if ( fParameterList[AliRecoParam::AConvert(fEventSpecie)] == NULL )
147         fParameterList[AliRecoParam::AConvert(fEventSpecie)] = new TList() ; 
148       fParameterList[AliRecoParam::AConvert(fEventSpecie)]->Add(p) ;
149     }
150     list[AliRecoParam::AConvert(fEventSpecie)]->AddAtAndExpand(hist, index) ; 
151     rv = list[AliRecoParam::AConvert(fEventSpecie)]->GetLast() ;
152   }
153   return rv ; 
154 }
155
156 //____________________________________________________________________________
157 TH1 *  AliQADataMaker::CloneMe(TH1 * hist, Int_t specie) const  
158 {
159   // clones a histogram 
160   const Char_t * name = Form("%s_%s", AliRecoParam::GetEventSpecieName(specie), hist->GetName()) ;
161   TH1 * hClone = static_cast<TH1 *>(hist->Clone(name)) ; 
162   if ( hist->TestBit(AliQAv1::GetExpertBit()) )
163     hClone->SetBit(AliQAv1::GetExpertBit()) ; 
164   if ( hist->TestBit(AliQAv1::GetImageBit()) )
165     hClone->SetBit(AliQAv1::GetImageBit()) ; 
166   return hClone ; 
167 }
168
169 //____________________________________________________________________________
170 void AliQADataMaker::DefaultEndOfDetectorCycle(AliQAv1::TASKINDEX_t task) 
171 {
172         // this method must be oveloaded by detectors
173         // sets the QA result to Fatal
174         AliQAv1::Instance(AliQAv1::GetDetIndex(GetName())) ;
175         AliQAv1 * qa = AliQAv1::Instance(task) ;
176   for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) 
177     qa->Set(AliQAv1::kFATAL, specie) ; 
178         AliQAv1::GetQAResultFile()->cd() ; 
179         qa->Write(AliQAv1::GetQAName(), kWriteDelete) ;   
180         AliQAv1::GetQAResultFile()->Close() ; 
181 }
182
183 //____________________________________________________________________________ 
184 void AliQADataMaker::Finish() const 
185
186         // write to the output File
187         if (fOutput) 
188                 fOutput->Close() ; 
189
190
191 //____________________________________________________________________________ 
192 TObject * AliQADataMaker::GetData(TObjArray ** list, const Int_t index)  
193
194         // Returns the QA object at index. Limit is 100. 
195   if ( ! list ) {
196                 AliError("Data list is NULL !!") ; 
197                 return NULL ;           
198         }
199
200   SetEventSpecie(fEventSpecie) ;  
201   Int_t esindex = AliRecoParam::AConvert(fEventSpecie) ; 
202   TH1 * histClone = NULL ; 
203         if (list[esindex]) {
204                 if ( index > 10000 ) {
205                         AliError("Max number of authorized QA objects is 10000") ; 
206                 } else {
207       if ( list[esindex]->At(index) )  {
208         histClone = static_cast<TH1*>(list[esindex]->At(index)) ; 
209       }         
210     }
211   }
212   return histClone ;            
213 }
214
215 //____________________________________________________________________________ 
216 TObjArray*  AliQADataMaker::Init(AliQAv1::TASKINDEX_t task, AliRecoParam::EventSpecie_t es, Int_t cycles)
217 {
218   // Initialializes and  returns the QAData list for a given event specie
219   TObjArray ** ar = Init(task, cycles) ; 
220   return ar[AliRecoParam::AConvert(es)] ;  
221 }
222
223 //____________________________________________________________________________ 
224 void AliQADataMaker::MakeTheImage( TObjArray ** list, AliQAv1::TASKINDEX_t task, const Char_t * mode) 
225 {
226   // makes the QA image for sim and rec
227   TIter next(list[AliRecoParam::AConvert(fEventSpecie)]) ;  
228   TH1 * hdata = NULL ; 
229   Int_t nImages = 0 ;
230   while ( (hdata=static_cast<TH1 *>(next())) ) {
231     TString cln(hdata->ClassName()) ; 
232     if ( ! cln.Contains("TH1") )
233       continue ; 
234     if ( hdata->TestBit(AliQAv1::GetImageBit()) )
235       nImages++; 
236   }
237   if ( nImages == 0 ) {
238     AliWarning(Form("No histogram will be plotted for %s %s\n", GetName(), AliQAv1::GetTaskName(task).Data())) ;  
239   } else {
240     AliDebug(AliQAv1::GetQADebugLevel(), Form("%d histograms will be plotted for %s %s\n", nImages, GetName(), AliQAv1::GetTaskName(task).Data())) ;  
241     for (Int_t esIndex = 0 ; esIndex < AliRecoParam::kNSpecies ; esIndex++) {
242       if (! AliQAv1::Instance(AliQAv1::GetDetIndex(GetName()))->IsEventSpecieSet(AliRecoParam::ConvertIndex(esIndex)) ) 
243         continue ;
244       const Char_t * title = Form("QA_%s_%s_%s", GetName(), AliQAv1::GetTaskName(task).Data(), AliRecoParam::GetEventSpecieName(esIndex)) ; 
245       if ( !fImage[esIndex] ) {
246         fImage[esIndex] = new TCanvas(title, title) ;
247       }
248       fImage[esIndex]->Clear() ; 
249       fImage[esIndex]->SetTitle(title) ; 
250       fImage[esIndex]->cd() ; 
251       TPaveText someText(0.015, 0.015, 0.98, 0.98) ;
252       someText.AddText(title) ;
253       someText.Draw() ; 
254       fImage[esIndex]->Print(Form("%s%s%d.%s", AliQAv1::GetImageFileName(), mode, fRun, AliQAv1::GetImageFileFormat())) ; 
255       fImage[esIndex]->Clear() ; 
256       Int_t nx = TMath::Sqrt(nImages) ; 
257       Int_t ny = nx  ; 
258       if ( nx < TMath::Sqrt(nImages)) 
259         ny++ ; 
260       fImage[esIndex]->Divide(nx, ny) ; 
261       TIter nexthist(list[esIndex]) ; 
262       TH1* hist = NULL ;
263       Int_t npad = 1 ; 
264       fImage[esIndex]->cd(npad) ; 
265       while ( (hist=static_cast<TH1*>(nexthist())) ) {
266         TString cln(hist->ClassName()) ; 
267         if ( ! cln.Contains("TH1") )
268           continue ; 
269         if(hist->TestBit(AliQAv1::GetImageBit())) {
270           hist->Draw() ; 
271           fImage[esIndex]->cd(++npad) ; 
272         }
273       }
274       fImage[esIndex]->Print(Form("%s%s%d.%s", AliQAv1::GetImageFileName(), mode, fRun, AliQAv1::GetImageFileFormat())) ; 
275     }
276   }  
277 }