]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWGDQ/dielectron/AliDielectronHFhelper.cxx
update
[u/mrichter/AliRoot.git] / PWGDQ / dielectron / AliDielectronHFhelper.cxx
CommitLineData
5e2cf960 1/*************************************************************************
2* Copyright(c) 1998-2009, 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// Dielectron Histogram framework helper //
18// //
19/*
20
21
22
23
24
25
26
27
28
29*/
30// //
31///////////////////////////////////////////////////////////////////////////
32
33#include <TObjArray.h>
34#include <TKey.h>
35#include <TList.h>
36#include <TClass.h>
37#include <TObject.h>
38#include <TFile.h>
39#include <TString.h>
40#include <TObjString.h>
41#include <TVectorD.h>
42#include <TMath.h>
43#include <TH1.h>
44
45#include <AliLog.h>
46
443a091c 47#include "AliDielectron.h"
5e2cf960 48#include "AliDielectronHFhelper.h"
49#include "AliDielectronHF.h"
50
51//ClassImp(AliDielectronHFhelper)
52
53//const char* AliDielectronHFhelper::fCutVars[AliDielectronHFhelper::kMaxCuts] = {"","","","","","","","","",""};
54
55//________________________________________________________________
56AliDielectronHFhelper::AliDielectronHFhelper(const char* filename) :
57 TNamed(),
58 fArrPairType(0x0),
59 fCutVars(0x0),
60 fCutLowLimits(0),
61 fCutUpLimits(0)
62{
63 //
64 // get HF container(s) from file 'filename'
65 //
66 SetHFArray(filename);
67
68}
69
70//________________________________________________________________
71AliDielectronHFhelper::~AliDielectronHFhelper()
72{
73 //
74 // dtor
75 //
76 if(fArrPairType) delete fArrPairType;
77 if(fCutVars) delete fCutVars;
78
79}
80
81//________________________________________________________________
82void AliDielectronHFhelper::SetHFArray(const char* filename)
83{
84 //
85 // get HF containers from file
86 //
87
88 TFile *f = TFile::Open(filename);
89
90 TList *l=f->GetListOfKeys();
91 TIter nextKey(l);
92 TKey *k=0x0;
93 while ( (k=static_cast<TKey*>(nextKey())) ){
94
95 TObject *o=k->ReadObj();
96 if (o->IsA()==TList::Class()){
97
98 TList *tlist=(TList*)o;
99
100 TIter next(tlist);
101 TObject *obj=0x0;
102 while ((obj = next())) {
103 TString objname(obj->GetName());
104
105 if( objname.Contains("_HF") && obj->IsA()==TObjArray::Class()) {
106 fArrPairType = new TObjArray( *(dynamic_cast<TObjArray*>(obj)) );
107 //fArrPairType->Print();
108 return;
109 }
110 }
111 }
112 }
113
114}
115//________________________________________________________________
116void AliDielectronHFhelper::SetRangeUser(const char *varname, Double_t min, Double_t max, Bool_t leg)
117{
118 //
119 // Set range from variable name
120 //
121 // Int_t size=sizeof(fCutVars)/sizeof(const char*);
122 Int_t size=fCutLowLimits.GetNrows();
123
124 if(size>=kMaxCuts) return;
125
126 // arrays
127 if(!fCutVars) {
128 fCutVars = new TObjArray();
129 fCutVars->SetOwner();
130 }
131 fCutLowLimits.ResizeTo(size+1);
132 fCutUpLimits.ResizeTo(size+1);
133
134 // fill
135 // fCutVars[size]=Form("%s%s",(leg?"Leg":""),varname);
136 TObjString *str = new TObjString(Form("%s%s",(leg?"Leg":""),varname));
137 fCutVars->Add(str);
138 fCutLowLimits(size) = min;
139 fCutUpLimits(size) = max;
140 AliWarning(Form(" %s [%.2f,%.2f]",fCutVars->At(size)->GetName(),fCutLowLimits(size),fCutUpLimits(size)));
141}
142
143//________________________________________________________________
144void AliDielectronHFhelper::SetRangeUser(AliDielectronVarManager::ValueTypes type, Double_t min, Double_t max, Bool_t leg)
145{
146 //
147 // Set range from AliDielectronVarManager
148 //
149 SetRangeUser(AliDielectronVarManager::GetValueName(type), min, max, leg);
150}
151
443a091c 152//________________________________________________________________
153TObjArray* AliDielectronHFhelper::CollectHistos()
154{
155 //
156 // collect histograms for all kind of pair types or sources
157 //
158
159 TObjArray *collection = new TObjArray(AliDielectron::kEv1PMRot+1);
160
161 // loop over max. available pair types
162 for(Int_t i=0; i<AliDielectron::kEv1PMRot+1; i++) {
163
164 collection->AddAt(GetHistogram(AliDielectron::PairClassName(i)),i);
165
166 }
167
168 return collection;
169}
170
5e2cf960 171//________________________________________________________________
172TH1F* AliDielectronHFhelper::GetHistogram(const char *step)
173{
174 //
175 // main function to recive a single histogram
176 //
177
178 TObjArray *histos = (TObjArray*) fArrPairType->FindObject(step);
179 AliInfo(Form(" Step %s selected",step));
180 if(!histos) return 0x0;
181
182 TH1F *hist = FindHistograms(histos);
183 return hist;
184}
185
186//________________________________________________________________
187TH1F* AliDielectronHFhelper::FindHistograms(TObjArray *histos)
188{
189 //
190 // exclude histograms
191 //
192
193 // debug
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()));
197
198 // check for missing cuts
199 CheckCuts(histos);
200
201 // loop over all cuts
202 for(Int_t icut=0; icut<fCutLowLimits.GetNrows(); icut++) {
203
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));
209
210 // loop over all histograms
211 for(Int_t i=0; i<histos->GetEntriesFast(); i++) {
212
213 // continue if already empty
214 if(!histos->At(i)) continue;
215
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()));
220
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()));
225
226 // check for cuts and ranges by the user
227 if(binvar.Contains(cutvar)) {
228 TObjArray *limits = binvar.Tokenize("#");
229
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));
233
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);
238 }
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));
242 }
243 // clean up
244 if(limits) delete limits;
245
246 // do we have found an exact bin
247 if(binmin==min && binmax==max) bFndBin=kTRUE;
248
249 }
250
251 }
252 // clean up
253 if(vars) delete vars;
254
255 }
256
257 }
258
259 // compress the array by removing all empty histos
260 histos->Compress();
261 AliDebug(1,Form(" Compression: %d histograms left",histos->GetEntriesFast()));
262
263 // merge histograms
264 TH1F* hist = MergeHistos(histos);
265 return hist;
266}
267
268//________________________________________________________________
269TH1F* AliDielectronHFhelper::MergeHistos(TObjArray *arr)
270{
271 //
272 // merge histos to one single histogram
273 //
274
275 if(arr->GetEntriesFast()<1) { AliError("[E] No more histosgrams left!"); return 0x0; }
276
277 TH1F *final=(TH1F*) arr->At(0)->Clone();
278 if(!final) return 0x0;
279
280 final->Reset("CE");
281 final->SetTitle(""); //TODO: change in future
282 for(Int_t i=0; i<arr->GetEntriesFast(); i++) {
283 final->Add((TH1F*)arr->At(i));
284 }
285 arr->Clear();
286
287 return final;
288}
289
290//________________________________________________________________
291void AliDielectronHFhelper::CheckCuts(TObjArray *arr)
292{
293 //
294 // Compare histo binning and cut variables. Add necessary cuts (largest limit)
295 //
296
297
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++) {
306
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()));
310
311 switch(ivar%3) {
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;
315 }
316
317 binvarsF->AddAt(0x0,ivar);
318 }
319 binvarsF->Compress();
320
321 // loop over all vars and cuts, check for missing stuff
322 for(Int_t ivar=0; ivar<binvarsF->GetEntriesFast(); ivar++) {
323
324 TString binvar=binvarsF->At(ivar)->GetName();
325 Bool_t selected=kFALSE;
326
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; }
331 // else break;
332 }
333
334 // add missing cut with max limits
335 if(!selected) {
336 AliWarning("Not all bin variables covered. Add additional cut!");
337 SetRangeUser(binvar.Data(),binmin[ivar],binmax[ivar]);
338 }
339
340 }
341
342 // clean up
343 if(binvarsF) delete binvarsF;
344 if(binvarsL) delete binvarsL;
345}
346
347//________________________________________________________________
443a091c 348void AliDielectronHFhelper::Print(const Option_t* /*option*/) const
5e2cf960 349{
350
351 //
352 // Print out object contents
353 //
354
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));
359 }
360
361}
362
363//________________________________________________________________
364void AliDielectronHFhelper::PrintCuts()
365{
366
367 //
368 // Print out object contents
369 //
370
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)));
375
376}
377