1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
21 // Produces the data needed to calculate the quality assurance.
22 // All data must be mergeable objects.
23 // Y. Schutz CERN July 2007
26 // --- ROOT system ---
29 #include <TPaveText.h>
34 #include <TClonesArray.h>
35 #include <TParameter.h>
47 // --- Standard library ---
49 // --- AliRoot header files ---
51 #include "AliQADataMaker.h"
52 #include "AliQAChecker.h"
53 #include "AliESDEvent.h"
54 #include "AliRawReader.h"
55 #include "AliDetectorRecoParam.h"
58 ClassImp(AliQADataMaker)
60 //____________________________________________________________________________
61 AliQADataMaker::AliQADataMaker(const Char_t * name, const Char_t * title) :
70 fParameterList(new TList*[AliRecoParam::kNSpecies]),
72 fEventSpecie(AliRecoParam::kDefault),
73 fImage(new TCanvas*[AliRecoParam::kNSpecies]),
77 fDetectorDirName = GetName() ;
78 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
79 fParameterList[specie] = NULL ;
80 fImage[specie] = NULL ;
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),
92 fCycleCounter(qadm.fCycleCounter),
93 fWriteExpert(qadm.fWriteExpert),
94 fParameterList(qadm.fParameterList),
96 fEventSpecie(qadm.fEventSpecie),
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] ;
109 //____________________________________________________________________________
110 AliQADataMaker::~AliQADataMaker()
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] ;
119 delete[] fParameterList ;
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)
125 // Set histograms memory resident and add to the list
126 // Maximm allowed is 10000
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") ;
136 hist->SetDirectory(0) ;
138 hist->SetBit(AliQAv1::GetExpertBit()) ;
140 hist->SetBit(AliQAv1::GetImageBit()) ;
141 const Char_t * name = Form("%s_%s", AliRecoParam::GetEventSpecieName(fEventSpecie), hist->GetName()) ;
142 hist->SetName(name) ;
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) ;
150 list[AliRecoParam::AConvert(fEventSpecie)]->AddAtAndExpand(hist, index) ;
151 rv = list[AliRecoParam::AConvert(fEventSpecie)]->GetLast() ;
156 //____________________________________________________________________________
157 TH1 * AliQADataMaker::CloneMe(TH1 * hist, Int_t specie) const
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()) ;
169 //____________________________________________________________________________
170 void AliQADataMaker::DefaultEndOfDetectorCycle(AliQAv1::TASKINDEX_t task)
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() ;
183 //____________________________________________________________________________
184 void AliQADataMaker::Finish() const
186 // write to the output File
191 //____________________________________________________________________________
192 TObject * AliQADataMaker::GetData(TObjArray ** list, const Int_t index)
194 // Returns the QA object at index. Limit is 100.
196 AliError("Data list is NULL !!") ;
200 SetEventSpecie(fEventSpecie) ;
201 Int_t esindex = AliRecoParam::AConvert(fEventSpecie) ;
202 TH1 * histClone = NULL ;
204 if ( index > 10000 ) {
205 AliError("Max number of authorized QA objects is 10000") ;
207 if ( list[esindex]->At(index) ) {
208 histClone = static_cast<TH1*>(list[esindex]->At(index)) ;
215 //____________________________________________________________________________
216 TObjArray* AliQADataMaker::Init(AliQAv1::TASKINDEX_t task, AliRecoParam::EventSpecie_t es, Int_t cycles)
218 // Initialializes and returns the QAData list for a given event specie
219 TObjArray ** ar = Init(task, cycles) ;
220 return ar[AliRecoParam::AConvert(es)] ;
223 //____________________________________________________________________________
224 void AliQADataMaker::MakeTheImage( TObjArray ** list, AliQAv1::TASKINDEX_t task, const Char_t * mode)
226 // makes the QA image for sim and rec
227 TIter next(list[AliRecoParam::AConvert(fEventSpecie)]) ;
230 while ( (hdata=static_cast<TH1 *>(next())) ) {
231 TString cln(hdata->ClassName()) ;
232 if ( ! cln.Contains("TH1") )
234 if ( hdata->TestBit(AliQAv1::GetImageBit()) )
237 if ( nImages == 0 ) {
238 AliWarning(Form("No histogram will be plotted for %s %s\n", GetName(), AliQAv1::GetTaskName(task).Data())) ;
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)) )
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) ;
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) ;
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) ;
258 if ( nx < TMath::Sqrt(nImages))
260 fImage[esIndex]->Divide(nx, ny) ;
261 TIter nexthist(list[esIndex]) ;
264 fImage[esIndex]->cd(npad) ;
265 while ( (hist=static_cast<TH1*>(nexthist())) ) {
266 TString cln(hist->ClassName()) ;
267 if ( ! cln.Contains("TH1") )
269 if(hist->TestBit(AliQAv1::GetImageBit())) {
271 fImage[esIndex]->cd(++npad) ;
274 fImage[esIndex]->Print(Form("%s%s%d.%s", AliQAv1::GetImageFileName(), mode, fRun, AliQAv1::GetImageFileFormat())) ;