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]),
78 fDetectorDirName = GetName() ;
79 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
80 fParameterList[specie] = NULL ;
81 fImage[specie] = NULL ;
85 //____________________________________________________________________________
86 AliQADataMaker::AliQADataMaker(const AliQADataMaker& qadm) :
87 TNamed(qadm.GetName(), qadm.GetTitle()),
88 fOutput(qadm.fOutput),
89 fDetectorDir(qadm.fDetectorDir),
90 fDetectorDirName(qadm.fDetectorDirName),
91 fCurrentCycle(qadm.fCurrentCycle),
93 fCycleCounter(qadm.fCycleCounter),
94 fWriteExpert(qadm.fWriteExpert),
95 fParameterList(qadm.fParameterList),
97 fEventSpecie(qadm.fEventSpecie),
103 fDetectorDirName = GetName() ;
104 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
105 fParameterList[specie] = qadm.fParameterList[specie] ;
106 fImage[specie] = qadm.fImage[specie] ;
110 //____________________________________________________________________________
111 AliQADataMaker::~AliQADataMaker()
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] ;
120 delete[] fParameterList ;
123 fDigitsArray->Clear() ;
124 delete fDigitsArray ;
128 //____________________________________________________________________________
129 Int_t AliQADataMaker::Add2List(TH1 * hist, const Int_t index, TObjArray ** list, const Bool_t expert, const Bool_t image, const Bool_t saveForCorr)
131 // Set histograms memory resident and add to the list
132 // Maximm allowed is 10000
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())) ;
139 } else if ( index > AliQAv1::GetMaxQAObj() ) {
140 AliError(Form("Max number of authorized QA objects is %d", AliQAv1::GetMaxQAObj())) ;
142 hist->SetDirectory(0) ;
144 hist->SetBit(AliQAv1::GetExpertBit()) ;
146 hist->SetBit(AliQAv1::GetImageBit()) ;
147 const Char_t * name = Form("%s_%s", AliRecoParam::GetEventSpecieName(fEventSpecie), hist->GetName()) ;
148 hist->SetName(name) ;
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) ;
156 list[AliRecoParam::AConvert(fEventSpecie)]->AddAtAndExpand(hist, index) ;
157 rv = list[AliRecoParam::AConvert(fEventSpecie)]->GetLast() ;
162 //____________________________________________________________________________
163 TH1 * AliQADataMaker::CloneMe(TH1 * hist, Int_t specie) const
165 // clones a histogram
166 const Char_t * name = Form("%s_%s", AliRecoParam::GetEventSpecieName(specie), hist->GetName()) ;
167 TH1 * hClone = static_cast<TH1 *>(hist->Clone(name)) ;
168 if ( hist->TestBit(AliQAv1::GetExpertBit()) )
169 hClone->SetBit(AliQAv1::GetExpertBit()) ;
170 if ( hist->TestBit(AliQAv1::GetImageBit()) )
171 hClone->SetBit(AliQAv1::GetImageBit()) ;
175 //____________________________________________________________________________
176 void AliQADataMaker::DefaultEndOfDetectorCycle(AliQAv1::TASKINDEX_t task)
178 // this method must be oveloaded by detectors
179 // sets the QA result to Fatal
180 AliQAv1::Instance(AliQAv1::GetDetIndex(GetName())) ;
181 AliQAv1 * qa = AliQAv1::Instance(task) ;
182 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++)
183 qa->Set(AliQAv1::kFATAL, specie) ;
184 AliQAv1::GetQAResultFile()->cd() ;
185 qa->Write(AliQAv1::GetQAName(), kWriteDelete) ;
186 AliQAv1::GetQAResultFile()->Close() ;
189 //____________________________________________________________________________
190 void AliQADataMaker::Finish() const
192 // write to the output File
197 //____________________________________________________________________________
198 TObject * AliQADataMaker::GetData(TObjArray ** list, const Int_t index)
200 // Returns the QA object at index. Limit is AliQAv1::GetMaxQAObj()
202 AliError("Data list is NULL !!") ;
206 SetEventSpecie(fEventSpecie) ;
207 Int_t esindex = AliRecoParam::AConvert(fEventSpecie) ;
208 TH1 * histClone = NULL ;
209 TObjArray * arr = list[esindex] ;
211 if ( ! arr->GetEntriesFast() ) {
212 // Initializes the histograms
213 TString arrName(arr->GetName()) ;
214 if (arrName.Contains(AliQAv1::GetTaskName(AliQAv1::kRAWS)))
216 else if (arrName.Contains(AliQAv1::GetTaskName(AliQAv1::kHITS)))
218 else if (arrName.Contains(AliQAv1::GetTaskName(AliQAv1::kSDIGITS)))
220 else if (arrName.Contains(AliQAv1::GetTaskName(AliQAv1::kDIGITS)))
222 else if (arrName.Contains(AliQAv1::GetTaskName(AliQAv1::kDIGITSR)))
224 else if (arrName.Contains(AliQAv1::GetTaskName(AliQAv1::kRECPOINTS)))
226 else if (arrName.Contains(AliQAv1::GetTaskName(AliQAv1::kESDS)))
229 if ( index > AliQAv1::GetMaxQAObj() ) {
230 AliError(Form("Max number of authorized QA objects is %d", AliQAv1::GetMaxQAObj())) ;
232 if ( arr->At(index) ) {
233 histClone = static_cast<TH1*>(arr->At(index)) ;
240 //____________________________________________________________________________
241 TObjArray* AliQADataMaker::Init(AliQAv1::TASKINDEX_t task, AliRecoParam::EventSpecie_t es, Int_t cycles)
243 // Initialializes and returns the QAData list for a given event specie
244 TObjArray ** ar = Init(task, cycles) ;
245 return ar[AliRecoParam::AConvert(es)] ;
248 //____________________________________________________________________________
249 Bool_t AliQADataMaker::IsValidEventSpecie(Int_t eventSpecieIndex, TObjArray ** list)
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() )
259 //____________________________________________________________________________
260 void AliQADataMaker::MakeTheImage( TObjArray ** list, AliQAv1::TASKINDEX_t task, const Char_t * mode)
262 // makes the QA image for sim and rec
263 TIter next(list[AliRecoParam::AConvert(fEventSpecie)]) ;
266 while ( (hdata=static_cast<TH1 *>(next())) ) {
267 TString cln(hdata->ClassName()) ;
268 if ( ! cln.Contains("TH1") )
270 if ( hdata->TestBit(AliQAv1::GetImageBit()) )
273 if ( nImages == 0 ) {
274 AliDebug(AliQAv1::GetQADebugLevel(), Form("No histogram will be plotted for %s %s\n", GetName(), AliQAv1::GetTaskName(task).Data())) ;
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)) )
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) ;
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) ;
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) ;
294 if ( nx < TMath::Sqrt(nImages))
296 fImage[esIndex]->Divide(nx, ny) ;
297 TIter nexthist(list[esIndex]) ;
300 fImage[esIndex]->cd(npad) ;
301 while ( (hist=static_cast<TH1*>(nexthist())) ) {
302 TString cln(hist->ClassName()) ;
303 if ( ! cln.Contains("TH1") )
305 if(hist->TestBit(AliQAv1::GetImageBit())) {
307 fImage[esIndex]->cd(++npad) ;
310 fImage[esIndex]->Print(Form("%s%s%d.%s", AliQAv1::GetImageFileName(), mode, fRun, AliQAv1::GetImageFileFormat())) ;