1 /*************************************************************************
2 * Copyright(c) 1998-2009, 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 **************************************************************************/
16 ///////////////////////////////////////////////////////////////////////////
17 // Dielectron Histogram framework helper //
31 ///////////////////////////////////////////////////////////////////////////
33 #include <TObjArray.h>
40 #include <TObjString.h>
47 #include "AliDielectron.h"
48 #include "AliDielectronHFhelper.h"
49 #include "AliDielectronHF.h"
51 //ClassImp(AliDielectronHFhelper)
53 //const char* AliDielectronHFhelper::fCutVars[AliDielectronHFhelper::kMaxCuts] = {"","","","","","","","","",""};
55 //________________________________________________________________
56 AliDielectronHFhelper::AliDielectronHFhelper(const char* filename) :
64 // get HF container(s) from file 'filename'
70 //________________________________________________________________
71 AliDielectronHFhelper::~AliDielectronHFhelper()
76 if(fArrPairType) delete fArrPairType;
77 if(fCutVars) delete fCutVars;
81 //________________________________________________________________
82 void AliDielectronHFhelper::SetHFArray(const char* filename)
85 // get HF containers from file
88 TFile *f = TFile::Open(filename);
90 TList *l=f->GetListOfKeys();
93 while ( (k=static_cast<TKey*>(nextKey())) ){
95 TObject *o=k->ReadObj();
96 if (o->IsA()==TList::Class()){
98 TList *tlist=(TList*)o;
102 while ((obj = next())) {
103 TString objname(obj->GetName());
105 if( objname.Contains("_HF") && obj->IsA()==TObjArray::Class()) {
106 fArrPairType = new TObjArray( *(dynamic_cast<TObjArray*>(obj)) );
107 //fArrPairType->Print();
115 //________________________________________________________________
116 void AliDielectronHFhelper::SetRangeUser(const char *varname, Double_t min, Double_t max, Bool_t leg)
119 // Set range from variable name
121 // Int_t size=sizeof(fCutVars)/sizeof(const char*);
122 Int_t size=fCutLowLimits.GetNrows();
124 if(size>=kMaxCuts) return;
128 fCutVars = new TObjArray();
129 fCutVars->SetOwner();
131 fCutLowLimits.ResizeTo(size+1);
132 fCutUpLimits.ResizeTo(size+1);
135 // fCutVars[size]=Form("%s%s",(leg?"Leg":""),varname);
136 TObjString *str = new TObjString(Form("%s%s",(leg?"Leg":""),varname));
138 fCutLowLimits(size) = min;
139 fCutUpLimits(size) = max;
140 AliWarning(Form(" %s [%.2f,%.2f]",fCutVars->At(size)->GetName(),fCutLowLimits(size),fCutUpLimits(size)));
143 //________________________________________________________________
144 void AliDielectronHFhelper::SetRangeUser(AliDielectronVarManager::ValueTypes type, Double_t min, Double_t max, Bool_t leg)
147 // Set range from AliDielectronVarManager
149 SetRangeUser(AliDielectronVarManager::GetValueName(type), min, max, leg);
152 //________________________________________________________________
153 TObjArray* AliDielectronHFhelper::CollectHistos()
156 // collect histograms for all kind of pair types or sources
159 TObjArray *collection = new TObjArray(AliDielectron::kEv1PMRot+1);
161 // loop over max. available pair types
162 for(Int_t i=0; i<AliDielectron::kEv1PMRot+1; i++) {
164 collection->AddAt(GetHistogram(AliDielectron::PairClassName(i)),i);
171 //________________________________________________________________
172 TH1F* AliDielectronHFhelper::GetHistogram(const char *step)
175 // main function to recive a single histogram
178 TObjArray *histos = (TObjArray*) fArrPairType->FindObject(step);
179 AliInfo(Form(" Step %s selected",step));
180 if(!histos) return 0x0;
182 TH1F *hist = FindHistograms(histos);
186 //________________________________________________________________
187 TH1F* AliDielectronHFhelper::FindHistograms(TObjArray *histos)
190 // exclude histograms
194 // TString title = histos->At(0)->GetTitle();
195 // TObjArray* vars = title.Tokenize(":");
196 // AliDebug(1,Form(" number of cuts/vars: %d/%d",fCutLowLimits.GetNrows(),vars->GetEntriesFast()));
198 // check for missing cuts
201 // loop over all cuts
202 for(Int_t icut=0; icut<fCutLowLimits.GetNrows(); icut++) {
204 Bool_t bFndBin = kFALSE; // exact bin found
205 const char *cutvar = fCutVars->At(icut)->GetName();
206 Double_t min = fCutLowLimits(icut);
207 Double_t max = fCutUpLimits(icut);
208 AliDebug(1,Form(" Cut %d: %s [%.2f,%.2f]",icut,cutvar,min,max));
210 // loop over all histograms
211 for(Int_t i=0; i<histos->GetEntriesFast(); i++) {
213 // continue if already empty
214 if(!histos->At(i)) continue;
216 // collect binning from histo title
217 TString title = histos->At(i)->GetTitle();
218 if(title.IsNull()) continue;
219 AliDebug(1,Form(" histo title: %s",title.Data()));
221 TObjArray *vars = title.Tokenize(":");
222 for(Int_t ivar=0; ivar<vars->GetEntriesFast(); ivar++) {
223 TString binvar = vars->At(ivar)->GetName();
224 AliDebug(1,Form(" Check ivar %d binvar %s",ivar,binvar.Data()));
226 // check for cuts and ranges by the user
227 if(binvar.Contains(cutvar)) {
228 TObjArray *limits = binvar.Tokenize("#");
230 Double_t binmin = atof(limits->At(1)->GetName());
231 Double_t binmax = atof(limits->At(2)->GetName());
232 AliDebug(1,Form(" bin %s var %s [%.2f,%.2f]",binvar.Data(),limits->At(0)->GetName(),binmin,binmax));
234 // remove histogram from array
235 if(binmin < min || binmax < min || binmin > max || binmax > max ) {
236 AliDebug(1,Form(" removed, out of range min %.2f,%.2f max %.2f,%.2f",binmin,min,binmax,max));
237 histos->AddAt(0x0,i);
239 if(bFndBin && !(binmin == min && binmax == max)) {
240 histos->AddAt(0x0,i);
241 AliDebug(1,Form(" removed, within range min %.2f,%.2f max %.2f,%.2f",binmin,min,binmax,max));
244 if(limits) delete limits;
246 // do we have found an exact bin
247 if(binmin==min && binmax==max) bFndBin=kTRUE;
253 if(vars) delete vars;
259 // compress the array by removing all empty histos
261 AliDebug(1,Form(" Compression: %d histograms left",histos->GetEntriesFast()));
264 TH1F* hist = MergeHistos(histos);
268 //________________________________________________________________
269 TH1F* AliDielectronHFhelper::MergeHistos(TObjArray *arr)
272 // merge histos to one single histogram
275 if(arr->GetEntriesFast()<1) { AliError("[E] No more histosgrams left!"); return 0x0; }
277 TH1F *final=(TH1F*) arr->At(0)->Clone();
278 if(!final) return 0x0;
281 final->SetTitle(""); //TODO: change in future
282 for(Int_t i=0; i<arr->GetEntriesFast(); i++) {
283 final->Add((TH1F*)arr->At(i));
290 //________________________________________________________________
291 void AliDielectronHFhelper::CheckCuts(TObjArray *arr)
294 // Compare histo binning and cut variables. Add necessary cuts (largest limit)
298 // build array with bin variable, minimum and maximum bin values
299 TString titleFIRST = arr->First()->GetTitle();
300 TString titleLAST = arr->Last()->GetTitle();
301 TObjArray* binvarsF = titleFIRST.Tokenize(":#");
302 TObjArray* binvarsL = titleLAST.Tokenize(":#");
303 Double_t binmin[kMaxCuts]= {0.0};
304 Double_t binmax[kMaxCuts]= {0.0};
305 for(Int_t ivar=0; ivar<binvarsF->GetEntriesFast(); ivar++) {
307 TString elementF=binvarsF->At(ivar)->GetName();
308 TString elementL=binvarsL->At(ivar)->GetName();
309 AliDebug(1,Form(" binvar %d: %s,%s",ivar,elementF.Data(),elementL.Data()));
312 case 0: continue; break;
313 case 1: binmin[(int)ivar/3]=atof(elementF.Data()); break;
314 case 2: binmax[(int)ivar/3]=atof(elementL.Data()); break;
317 binvarsF->AddAt(0x0,ivar);
319 binvarsF->Compress();
321 // loop over all vars and cuts, check for missing stuff
322 for(Int_t ivar=0; ivar<binvarsF->GetEntriesFast(); ivar++) {
324 TString binvar=binvarsF->At(ivar)->GetName();
325 Bool_t selected=kFALSE;
327 AliDebug(1,Form(" check cuts %d %s [%.2f,%.2f]",ivar,binvar.Data(),binmin[ivar],binmax[ivar]));
328 // loop over all cuts and check for missing stuff
329 for(Int_t icut=0; icut<fCutLowLimits.GetNrows(); icut++) {
330 if(binvar.Contains(fCutVars->At(icut)->GetName())) { selected=kTRUE; break; }
334 // add missing cut with max limits
336 AliWarning("Not all bin variables covered. Add additional cut!");
337 SetRangeUser(binvar.Data(),binmin[ivar],binmax[ivar]);
343 if(binvarsF) delete binvarsF;
344 if(binvarsL) delete binvarsL;
347 //________________________________________________________________
348 void AliDielectronHFhelper::Print(const Option_t* /*option*/) const
352 // Print out object contents
355 // pairtypes, steps and sources
356 AliInfo(Form(" Number of steps: \t %d",fArrPairType->GetEntriesFast()));
357 for(Int_t i=0; i<fArrPairType->GetEntriesFast(); i++) {
358 AliInfo(Form(" Step %d:",0));
363 //________________________________________________________________
364 void AliDielectronHFhelper::PrintCuts()
368 // Print out object contents
371 // loop over all cuts
372 AliInfo(" Selected cuts:");
373 for(Int_t icut=0; icut<fCutLowLimits.GetNrows(); icut++)
374 AliInfo(Form(" %d: %s [%.2f,%.2f]",icut,fCutVars->At(icut)->GetName(),fCutLowLimits(icut),fCutUpLimits(icut)));