]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliQADataMaker.cxx
increment the event counter only in even loop and not in task loop
[u/mrichter/AliRoot.git] / STEER / AliQADataMaker.cxx
CommitLineData
421ab0fb 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
202374b1 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//
421ab0fb 25
26// --- ROOT system ---
eca4fa66 27#include <TROOT.h>
71f27f1f 28#include <TCanvas.h>
fec0891b 29#include <TPaveText.h>
421ab0fb 30#include <TSystem.h>
31#include <TFile.h>
6c18591a 32#include <TList.h>
d76c31f4 33#include <TTree.h>
d5cf81bd 34#include <TClonesArray.h>
a2b64fbd 35#include <TParameter.h>
57acd2d2 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>
421ab0fb 46
47// --- Standard library ---
48
49// --- AliRoot header files ---
50#include "AliLog.h"
2e42b4d4 51#include "AliQADataMaker.h"
52#include "AliQAChecker.h"
d76c31f4 53#include "AliESDEvent.h"
d5cf81bd 54#include "AliRawReader.h"
5e232cd6 55#include "AliDetectorRecoParam.h"
56
421ab0fb 57
2e42b4d4 58ClassImp(AliQADataMaker)
312e6f8d 59
421ab0fb 60//____________________________________________________________________________
fec0891b 61AliQADataMaker::AliQADataMaker(const Char_t * name, const Char_t * title) :
421ab0fb 62 TNamed(name, title),
63 fOutput(0x0),
6c18591a 64 fDetectorDir(0x0),
312e6f8d 65 fDetectorDirName(""),
930e6e3e 66 fCurrentCycle(0),
5b188f2f 67 fCycle(9999999),
68 fCycleCounter(0),
b1af1125 69 fWriteExpert(kFALSE),
57acd2d2 70 fParameterList(new TList*[AliRecoParam::kNSpecies]),
71 fRun(0),
71f27f1f 72 fEventSpecie(AliRecoParam::kDefault),
73 fImage(new TCanvas*[AliRecoParam::kNSpecies]),
6252ceeb 74 fPrintImage(kTRUE),
75 fDigitsArray(NULL)
421ab0fb 76{
77 // ctor
421ab0fb 78 fDetectorDirName = GetName() ;
71f27f1f 79 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
80 fParameterList[specie] = NULL ;
81 fImage[specie] = NULL ;
82 }
421ab0fb 83}
84
85//____________________________________________________________________________
2e42b4d4 86AliQADataMaker::AliQADataMaker(const AliQADataMaker& qadm) :
421ab0fb 87 TNamed(qadm.GetName(), qadm.GetTitle()),
88 fOutput(qadm.fOutput),
6c18591a 89 fDetectorDir(qadm.fDetectorDir),
312e6f8d 90 fDetectorDirName(qadm.fDetectorDirName),
5b188f2f 91 fCurrentCycle(qadm.fCurrentCycle),
92 fCycle(qadm.fCycle),
93 fCycleCounter(qadm.fCycleCounter),
b1af1125 94 fWriteExpert(qadm.fWriteExpert),
a2b64fbd 95 fParameterList(qadm.fParameterList),
57acd2d2 96 fRun(qadm.fRun),
71f27f1f 97 fEventSpecie(qadm.fEventSpecie),
99737f39 98 fImage(NULL),
6252ceeb 99 fPrintImage(kTRUE),
100 fDigitsArray(NULL)
421ab0fb 101{
102 //copy ctor
103 fDetectorDirName = GetName() ;
eca4fa66 104 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
105 fParameterList[specie] = qadm.fParameterList[specie] ;
106 fImage[specie] = qadm.fImage[specie] ;
107 }
421ab0fb 108}
109
71f27f1f 110//____________________________________________________________________________
111AliQADataMaker::~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 ;
6252ceeb 121
122 if (fDigitsArray) {
123 fDigitsArray->Clear() ;
124 delete fDigitsArray ;
125 }
71f27f1f 126}
127
ba7aca7d 128//____________________________________________________________________________
7d297381 129Int_t AliQADataMaker::Add2List(TH1 * hist, const Int_t index, TObjArray ** list, const Bool_t expert, const Bool_t image, const Bool_t saveForCorr)
ba7aca7d 130{
04236e67 131 // Set histograms memory resident and add to the list
ab4351aa 132 // Maximm allowed is 10000
57acd2d2 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())) ;
49466ea2 139 } else if ( index > AliQAv1::GetMaxQAObj() ) {
140 AliError(Form("Max number of authorized QA objects is %d", AliQAv1::GetMaxQAObj())) ;
eca4fa66 141 } else {
142 hist->SetDirectory(0) ;
750730d8 143 if (expert)
7d297381 144 hist->SetBit(AliQAv1::GetExpertBit()) ;
145 if (image)
146 hist->SetBit(AliQAv1::GetImageBit()) ;
eca4fa66 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) ;
a2b64fbd 155 }
eca4fa66 156 list[AliRecoParam::AConvert(fEventSpecie)]->AddAtAndExpand(hist, index) ;
157 rv = list[AliRecoParam::AConvert(fEventSpecie)]->GetLast() ;
a2b64fbd 158 }
57acd2d2 159 return rv ;
160}
161
162//____________________________________________________________________________
163TH1 * AliQADataMaker::CloneMe(TH1 * hist, Int_t specie) const
164{
165 // clones a histogram
fec0891b 166 const Char_t * name = Form("%s_%s", AliRecoParam::GetEventSpecieName(specie), hist->GetName()) ;
eca4fa66 167 TH1 * hClone = static_cast<TH1 *>(hist->Clone(name)) ;
4e25ac79 168 if ( hist->TestBit(AliQAv1::GetExpertBit()) )
b2db43c5 169 hClone->SetBit(AliQAv1::GetExpertBit()) ;
170 if ( hist->TestBit(AliQAv1::GetImageBit()) )
171 hClone->SetBit(AliQAv1::GetImageBit()) ;
75373542 172 return hClone ;
421ab0fb 173}
174
96d67a8d 175//____________________________________________________________________________
4e25ac79 176void AliQADataMaker::DefaultEndOfDetectorCycle(AliQAv1::TASKINDEX_t task)
96d67a8d 177{
178 // this method must be oveloaded by detectors
179 // sets the QA result to Fatal
4e25ac79 180 AliQAv1::Instance(AliQAv1::GetDetIndex(GetName())) ;
181 AliQAv1 * qa = AliQAv1::Instance(task) ;
57acd2d2 182 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++)
4e25ac79 183 qa->Set(AliQAv1::kFATAL, specie) ;
184 AliQAv1::GetQAResultFile()->cd() ;
185 qa->Write(AliQAv1::GetQAName(), kWriteDelete) ;
186 AliQAv1::GetQAResultFile()->Close() ;
96d67a8d 187}
188
421ab0fb 189//____________________________________________________________________________
c65c502a 190void AliQADataMaker::Finish() const
421ab0fb 191{
96d67a8d 192 // write to the output File
d9cbd8fd 193 if (fOutput)
194 fOutput->Close() ;
421ab0fb 195}
196
197//____________________________________________________________________________
57acd2d2 198TObject * AliQADataMaker::GetData(TObjArray ** list, const Int_t index)
04236e67 199{
49466ea2 200 // Returns the QA object at index. Limit is AliQAv1::GetMaxQAObj()
76c42cb4 201 if ( ! list ) {
202 AliError("Data list is NULL !!") ;
203 return NULL ;
204 }
5e232cd6 205
206 SetEventSpecie(fEventSpecie) ;
eca4fa66 207 Int_t esindex = AliRecoParam::AConvert(fEventSpecie) ;
208 TH1 * histClone = NULL ;
49466ea2 209 TObjArray * arr = list[esindex] ;
210 if (arr) {
6252ceeb 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 }
49466ea2 229 if ( index > AliQAv1::GetMaxQAObj() ) {
230 AliError(Form("Max number of authorized QA objects is %d", AliQAv1::GetMaxQAObj())) ;
27773260 231 } else {
49466ea2 232 if ( arr->At(index) ) {
233 histClone = static_cast<TH1*>(arr->At(index)) ;
eca4fa66 234 }
235 }
236 }
237 return histClone ;
27773260 238}
7d297381 239
211a7313 240//____________________________________________________________________________
241TObjArray* 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
6252ceeb 248//____________________________________________________________________________
249Bool_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
fec0891b 259//____________________________________________________________________________
eca4fa66 260void AliQADataMaker::MakeTheImage( TObjArray ** list, AliQAv1::TASKINDEX_t task, const Char_t * mode)
fec0891b 261{
262 // makes the QA image for sim and rec
eca4fa66 263 TIter next(list[AliRecoParam::AConvert(fEventSpecie)]) ;
fec0891b 264 TH1 * hdata = NULL ;
265 Int_t nImages = 0 ;
eca4fa66 266 while ( (hdata=static_cast<TH1 *>(next())) ) {
267 TString cln(hdata->ClassName()) ;
268 if ( ! cln.Contains("TH1") )
269 continue ;
fec0891b 270 if ( hdata->TestBit(AliQAv1::GetImageBit()) )
271 nImages++;
272 }
273 if ( nImages == 0 ) {
6252ceeb 274 AliDebug(AliQAv1::GetQADebugLevel(), Form("No histogram will be plotted for %s %s\n", GetName(), AliQAv1::GetTaskName(task).Data())) ;
fec0891b 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) ;
eca4fa66 301 while ( (hist=static_cast<TH1*>(nexthist())) ) {
302 TString cln(hist->ClassName()) ;
303 if ( ! cln.Contains("TH1") )
304 continue ;
fec0891b 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}