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