fix error in calculating the drift length bin
[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 ---
71f27f1f 27#include <TCanvas.h>
fec0891b 28#include <TPaveText.h>
421ab0fb 29#include <TSystem.h>
30#include <TFile.h>
6c18591a 31#include <TList.h>
d76c31f4 32#include <TTree.h>
d5cf81bd 33#include <TClonesArray.h>
a2b64fbd 34#include <TParameter.h>
57acd2d2 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>
421ab0fb 45
46// --- Standard library ---
47
48// --- AliRoot header files ---
49#include "AliLog.h"
2e42b4d4 50#include "AliQADataMaker.h"
51#include "AliQAChecker.h"
d76c31f4 52#include "AliESDEvent.h"
d5cf81bd 53#include "AliRawReader.h"
5e232cd6 54#include "AliDetectorRecoParam.h"
55
421ab0fb 56
2e42b4d4 57ClassImp(AliQADataMaker)
312e6f8d 58
421ab0fb 59//____________________________________________________________________________
fec0891b 60AliQADataMaker::AliQADataMaker(const Char_t * name, const Char_t * title) :
421ab0fb 61 TNamed(name, title),
62 fOutput(0x0),
6c18591a 63 fDetectorDir(0x0),
312e6f8d 64 fDetectorDirName(""),
930e6e3e 65 fCurrentCycle(0),
5b188f2f 66 fCycle(9999999),
67 fCycleCounter(0),
b1af1125 68 fWriteExpert(kFALSE),
57acd2d2 69 fParameterList(new TList*[AliRecoParam::kNSpecies]),
70 fRun(0),
71f27f1f 71 fEventSpecie(AliRecoParam::kDefault),
72 fImage(new TCanvas*[AliRecoParam::kNSpecies]),
fec0891b 73 fPrintImage(kTRUE)
421ab0fb 74{
75 // ctor
421ab0fb 76 fDetectorDirName = GetName() ;
71f27f1f 77 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
78 fParameterList[specie] = NULL ;
79 fImage[specie] = NULL ;
80 }
421ab0fb 81}
82
83//____________________________________________________________________________
2e42b4d4 84AliQADataMaker::AliQADataMaker(const AliQADataMaker& qadm) :
421ab0fb 85 TNamed(qadm.GetName(), qadm.GetTitle()),
86 fOutput(qadm.fOutput),
6c18591a 87 fDetectorDir(qadm.fDetectorDir),
312e6f8d 88 fDetectorDirName(qadm.fDetectorDirName),
5b188f2f 89 fCurrentCycle(qadm.fCurrentCycle),
90 fCycle(qadm.fCycle),
91 fCycleCounter(qadm.fCycleCounter),
b1af1125 92 fWriteExpert(qadm.fWriteExpert),
a2b64fbd 93 fParameterList(qadm.fParameterList),
57acd2d2 94 fRun(qadm.fRun),
71f27f1f 95 fEventSpecie(qadm.fEventSpecie),
96 fImage(qadm.fImage),
fec0891b 97 fPrintImage(kTRUE)
71f27f1f 98
421ab0fb 99{
100 //copy ctor
101 fDetectorDirName = GetName() ;
102}
103
71f27f1f 104//____________________________________________________________________________
105AliQADataMaker::~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
421ab0fb 117//____________________________________________________________________________
7d297381 118Int_t AliQADataMaker::Add2List(TH1 * hist, const Int_t index, TObjArray ** list, const Bool_t expert, const Bool_t image, const Bool_t saveForCorr)
ba7aca7d 119{
04236e67 120 // Set histograms memory resident and add to the list
ab4351aa 121 // Maximm allowed is 10000
57acd2d2 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 ) {
ab4351aa 129 AliError("Max number of authorized QA objects is 10000") ;
57acd2d2 130 } else {
750730d8 131 if (expert)
7d297381 132 hist->SetBit(AliQAv1::GetExpertBit()) ;
133 if (image)
134 hist->SetBit(AliQAv1::GetImageBit()) ;
135 TH1 * histClone[AliRecoParam::kNSpecies] ;
57acd2d2 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) {
fec0891b 141 const Char_t * name = Form("%s_%s", list[AliRecoParam::AConvert(AliRecoParam::kDefault)]->GetName(), hist->GetName()) ;
57acd2d2 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 }
a2b64fbd 147 }
57acd2d2 148 rv = list[AliRecoParam::kDefault]->GetLast() ;
a2b64fbd 149 }
57acd2d2 150 delete hist ;
151 return rv ;
152}
153
154//____________________________________________________________________________
155TH1 * AliQADataMaker::CloneMe(TH1 * hist, Int_t specie) const
156{
157 // clones a histogram
fec0891b 158 const Char_t * name = Form("%s_%s", AliRecoParam::GetEventSpecieName(specie), hist->GetName()) ;
75373542 159 TH1 * hClone = dynamic_cast<TH1 *>(hist->Clone(name)) ;
4e25ac79 160 if ( hist->TestBit(AliQAv1::GetExpertBit()) )
b2db43c5 161 hClone->SetBit(AliQAv1::GetExpertBit()) ;
162 if ( hist->TestBit(AliQAv1::GetImageBit()) )
163 hClone->SetBit(AliQAv1::GetImageBit()) ;
75373542 164 return hClone ;
421ab0fb 165}
166
96d67a8d 167//____________________________________________________________________________
4e25ac79 168void AliQADataMaker::DefaultEndOfDetectorCycle(AliQAv1::TASKINDEX_t task)
96d67a8d 169{
170 // this method must be oveloaded by detectors
171 // sets the QA result to Fatal
4e25ac79 172 AliQAv1::Instance(AliQAv1::GetDetIndex(GetName())) ;
173 AliQAv1 * qa = AliQAv1::Instance(task) ;
57acd2d2 174 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++)
4e25ac79 175 qa->Set(AliQAv1::kFATAL, specie) ;
176 AliQAv1::GetQAResultFile()->cd() ;
177 qa->Write(AliQAv1::GetQAName(), kWriteDelete) ;
178 AliQAv1::GetQAResultFile()->Close() ;
96d67a8d 179}
180
421ab0fb 181//____________________________________________________________________________
c65c502a 182void AliQADataMaker::Finish() const
421ab0fb 183{
96d67a8d 184 // write to the output File
d9cbd8fd 185 if (fOutput)
186 fOutput->Close() ;
421ab0fb 187}
188
189//____________________________________________________________________________
57acd2d2 190TObject * AliQADataMaker::GetData(TObjArray ** list, const Int_t index)
04236e67 191{
192 // Returns the QA object at index. Limit is 100.
76c42cb4 193 if ( ! list ) {
194 AliError("Data list is NULL !!") ;
195 return NULL ;
196 }
5e232cd6 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 }
57acd2d2 206 if (list[AliRecoParam::AConvert(fEventSpecie)]) {
27773260 207 if ( index > 10000 ) {
208 AliError("Max number of authorized QA objects is 10000") ;
209 return NULL ;
210 } else {
57acd2d2 211 Int_t esindex = AliRecoParam::AConvert(fEventSpecie) ;
212 return list[esindex]->At(index) ;
27773260 213 }
57acd2d2 214 } else {
27773260 215 AliError("Data list is NULL !!") ;
216 return NULL ;
04236e67 217 }
27773260 218}
7d297381 219
fec0891b 220//____________________________________________________________________________
221void 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}