]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliQADataMaker.cxx
Warnings corrected.
[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]),
fec0891b 74 fPrintImage(kTRUE)
421ab0fb 75{
76 // ctor
421ab0fb 77 fDetectorDirName = GetName() ;
71f27f1f 78 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
79 fParameterList[specie] = NULL ;
80 fImage[specie] = NULL ;
81 }
421ab0fb 82}
83
84//____________________________________________________________________________
2e42b4d4 85AliQADataMaker::AliQADataMaker(const AliQADataMaker& qadm) :
421ab0fb 86 TNamed(qadm.GetName(), qadm.GetTitle()),
87 fOutput(qadm.fOutput),
6c18591a 88 fDetectorDir(qadm.fDetectorDir),
312e6f8d 89 fDetectorDirName(qadm.fDetectorDirName),
5b188f2f 90 fCurrentCycle(qadm.fCurrentCycle),
91 fCycle(qadm.fCycle),
92 fCycleCounter(qadm.fCycleCounter),
b1af1125 93 fWriteExpert(qadm.fWriteExpert),
a2b64fbd 94 fParameterList(qadm.fParameterList),
57acd2d2 95 fRun(qadm.fRun),
71f27f1f 96 fEventSpecie(qadm.fEventSpecie),
97 fImage(qadm.fImage),
fec0891b 98 fPrintImage(kTRUE)
71f27f1f 99
421ab0fb 100{
101 //copy ctor
102 fDetectorDirName = GetName() ;
eca4fa66 103 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
104 fParameterList[specie] = qadm.fParameterList[specie] ;
105 fImage[specie] = qadm.fImage[specie] ;
106 }
421ab0fb 107}
108
71f27f1f 109//____________________________________________________________________________
110AliQADataMaker::~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
ba7aca7d 122//____________________________________________________________________________
7d297381 123Int_t AliQADataMaker::Add2List(TH1 * hist, const Int_t index, TObjArray ** list, const Bool_t expert, const Bool_t image, const Bool_t saveForCorr)
ba7aca7d 124{
04236e67 125 // Set histograms memory resident and add to the list
ab4351aa 126 // Maximm allowed is 10000
57acd2d2 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 ) {
ab4351aa 134 AliError("Max number of authorized QA objects is 10000") ;
eca4fa66 135 } else {
136 hist->SetDirectory(0) ;
750730d8 137 if (expert)
7d297381 138 hist->SetBit(AliQAv1::GetExpertBit()) ;
139 if (image)
140 hist->SetBit(AliQAv1::GetImageBit()) ;
eca4fa66 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) ;
a2b64fbd 149 }
eca4fa66 150 list[AliRecoParam::AConvert(fEventSpecie)]->AddAtAndExpand(hist, index) ;
151 rv = list[AliRecoParam::AConvert(fEventSpecie)]->GetLast() ;
a2b64fbd 152 }
57acd2d2 153 return rv ;
154}
155
156//____________________________________________________________________________
157TH1 * AliQADataMaker::CloneMe(TH1 * hist, Int_t specie) const
158{
159 // clones a histogram
fec0891b 160 const Char_t * name = Form("%s_%s", AliRecoParam::GetEventSpecieName(specie), hist->GetName()) ;
eca4fa66 161 TH1 * hClone = static_cast<TH1 *>(hist->Clone(name)) ;
4e25ac79 162 if ( hist->TestBit(AliQAv1::GetExpertBit()) )
b2db43c5 163 hClone->SetBit(AliQAv1::GetExpertBit()) ;
164 if ( hist->TestBit(AliQAv1::GetImageBit()) )
165 hClone->SetBit(AliQAv1::GetImageBit()) ;
75373542 166 return hClone ;
421ab0fb 167}
168
96d67a8d 169//____________________________________________________________________________
4e25ac79 170void AliQADataMaker::DefaultEndOfDetectorCycle(AliQAv1::TASKINDEX_t task)
96d67a8d 171{
172 // this method must be oveloaded by detectors
173 // sets the QA result to Fatal
4e25ac79 174 AliQAv1::Instance(AliQAv1::GetDetIndex(GetName())) ;
175 AliQAv1 * qa = AliQAv1::Instance(task) ;
57acd2d2 176 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++)
4e25ac79 177 qa->Set(AliQAv1::kFATAL, specie) ;
178 AliQAv1::GetQAResultFile()->cd() ;
179 qa->Write(AliQAv1::GetQAName(), kWriteDelete) ;
180 AliQAv1::GetQAResultFile()->Close() ;
96d67a8d 181}
182
421ab0fb 183//____________________________________________________________________________
c65c502a 184void AliQADataMaker::Finish() const
421ab0fb 185{
96d67a8d 186 // write to the output File
d9cbd8fd 187 if (fOutput)
188 fOutput->Close() ;
421ab0fb 189}
190
191//____________________________________________________________________________
57acd2d2 192TObject * AliQADataMaker::GetData(TObjArray ** list, const Int_t index)
04236e67 193{
194 // Returns the QA object at index. Limit is 100.
76c42cb4 195 if ( ! list ) {
196 AliError("Data list is NULL !!") ;
197 return NULL ;
198 }
5e232cd6 199
200 SetEventSpecie(fEventSpecie) ;
eca4fa66 201 Int_t esindex = AliRecoParam::AConvert(fEventSpecie) ;
202 TH1 * histClone = NULL ;
203 if (list[esindex]) {
27773260 204 if ( index > 10000 ) {
205 AliError("Max number of authorized QA objects is 10000") ;
27773260 206 } else {
eca4fa66 207 if ( list[esindex]->At(index) ) {
208 histClone = static_cast<TH1*>(list[esindex]->At(index)) ;
209 }
210 }
211 }
212 return histClone ;
27773260 213}
7d297381 214
211a7313 215//____________________________________________________________________________
216TObjArray* 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
fec0891b 223//____________________________________________________________________________
eca4fa66 224void AliQADataMaker::MakeTheImage( TObjArray ** list, AliQAv1::TASKINDEX_t task, const Char_t * mode)
fec0891b 225{
226 // makes the QA image for sim and rec
eca4fa66 227 TIter next(list[AliRecoParam::AConvert(fEventSpecie)]) ;
fec0891b 228 TH1 * hdata = NULL ;
229 Int_t nImages = 0 ;
eca4fa66 230 while ( (hdata=static_cast<TH1 *>(next())) ) {
231 TString cln(hdata->ClassName()) ;
232 if ( ! cln.Contains("TH1") )
233 continue ;
fec0891b 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) ;
eca4fa66 265 while ( (hist=static_cast<TH1*>(nexthist())) ) {
266 TString cln(hist->ClassName()) ;
267 if ( ! cln.Contains("TH1") )
268 continue ;
fec0891b 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}