]>
Commit | Line | Data |
---|---|---|
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 | //________________________________________________________________ | |
56 | AliDielectronHFhelper::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 | //________________________________________________________________ | |
71 | AliDielectronHFhelper::~AliDielectronHFhelper() | |
72 | { | |
73 | // | |
74 | // dtor | |
75 | // | |
76 | if(fArrPairType) delete fArrPairType; | |
77 | if(fCutVars) delete fCutVars; | |
78 | ||
79 | } | |
80 | ||
81 | //________________________________________________________________ | |
82 | void 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 | //________________________________________________________________ | |
116 | void 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 | //________________________________________________________________ | |
144 | void 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 | ||
4d7704c5 | 152 | //________________________________________________________________ |
153 | void AliDielectronHFhelper::UnsetRangeUser(const char *varname, Bool_t leg) | |
154 | { | |
155 | // | |
156 | // unset range from variable name | |
157 | // | |
158 | Int_t size=fCutLowLimits.GetNrows(); | |
159 | PrintCuts(); | |
160 | TVectorD newlow; | |
161 | TVectorD newup; | |
162 | ||
163 | Int_t ientries = 0; | |
164 | for(Int_t icut=0; icut<size; icut++) { | |
165 | ||
166 | TString cutName = fCutVars->At(icut)->GetName(); | |
167 | if(cutName.Contains(Form("%s%s",(leg?"Leg":""),varname))) { | |
168 | fCutVars->AddAt(0x0,icut); | |
169 | continue; | |
170 | } | |
171 | ||
172 | // fill new vectors | |
173 | newlow.ResizeTo(ientries+1); | |
174 | newup.ResizeTo(ientries+1); | |
175 | newlow(ientries) = fCutLowLimits(icut); | |
176 | newup(ientries) = fCutUpLimits(icut); | |
177 | ||
178 | ientries++; | |
179 | } | |
180 | ||
181 | // adapt new arrays/vectors | |
182 | fCutVars->Compress(); | |
183 | ||
184 | fCutLowLimits.ResizeTo(ientries); | |
185 | fCutUpLimits.ResizeTo(ientries); | |
186 | for(Int_t icut=0; icut<ientries; icut++) { | |
187 | fCutLowLimits(icut) = newlow(icut); | |
188 | fCutUpLimits(icut) = newup(icut); | |
189 | } | |
190 | PrintCuts(); | |
191 | ||
192 | } | |
193 | ||
194 | //________________________________________________________________ | |
195 | void AliDielectronHFhelper::UnsetRangeUser(AliDielectronVarManager::ValueTypes type, Bool_t leg) | |
196 | { | |
197 | // | |
198 | // Unset range from AliDielectronVarManager | |
199 | // | |
200 | UnsetRangeUser(AliDielectronVarManager::GetValueName(type), leg); | |
201 | } | |
202 | ||
443a091c | 203 | //________________________________________________________________ |
204 | TObjArray* AliDielectronHFhelper::CollectHistos() | |
205 | { | |
206 | // | |
207 | // collect histograms for all kind of pair types or sources | |
208 | // | |
209 | ||
210 | TObjArray *collection = new TObjArray(AliDielectron::kEv1PMRot+1); | |
211 | ||
212 | // loop over max. available pair types | |
213 | for(Int_t i=0; i<AliDielectron::kEv1PMRot+1; i++) { | |
214 | ||
215 | collection->AddAt(GetHistogram(AliDielectron::PairClassName(i)),i); | |
216 | ||
217 | } | |
218 | ||
219 | return collection; | |
220 | } | |
221 | ||
5e2cf960 | 222 | //________________________________________________________________ |
223 | TH1F* AliDielectronHFhelper::GetHistogram(const char *step) | |
224 | { | |
225 | // | |
226 | // main function to recive a single histogram | |
227 | // | |
228 | ||
229 | TObjArray *histos = (TObjArray*) fArrPairType->FindObject(step); | |
230 | AliInfo(Form(" Step %s selected",step)); | |
231 | if(!histos) return 0x0; | |
232 | ||
233 | TH1F *hist = FindHistograms(histos); | |
234 | return hist; | |
235 | } | |
236 | ||
237 | //________________________________________________________________ | |
238 | TH1F* AliDielectronHFhelper::FindHistograms(TObjArray *histos) | |
239 | { | |
240 | // | |
241 | // exclude histograms | |
242 | // | |
243 | ||
244 | // debug | |
245 | // TString title = histos->At(0)->GetTitle(); | |
246 | // TObjArray* vars = title.Tokenize(":"); | |
247 | // AliDebug(1,Form(" number of cuts/vars: %d/%d",fCutLowLimits.GetNrows(),vars->GetEntriesFast())); | |
248 | ||
249 | // check for missing cuts | |
250 | CheckCuts(histos); | |
251 | ||
252 | // loop over all cuts | |
253 | for(Int_t icut=0; icut<fCutLowLimits.GetNrows(); icut++) { | |
254 | ||
255 | Bool_t bFndBin = kFALSE; // exact bin found | |
256 | const char *cutvar = fCutVars->At(icut)->GetName(); | |
257 | Double_t min = fCutLowLimits(icut); | |
258 | Double_t max = fCutUpLimits(icut); | |
259 | AliDebug(1,Form(" Cut %d: %s [%.2f,%.2f]",icut,cutvar,min,max)); | |
260 | ||
261 | // loop over all histograms | |
262 | for(Int_t i=0; i<histos->GetEntriesFast(); i++) { | |
263 | ||
264 | // continue if already empty | |
265 | if(!histos->At(i)) continue; | |
266 | ||
267 | // collect binning from histo title | |
268 | TString title = histos->At(i)->GetTitle(); | |
269 | if(title.IsNull()) continue; | |
270 | AliDebug(1,Form(" histo title: %s",title.Data())); | |
271 | ||
272 | TObjArray *vars = title.Tokenize(":"); | |
273 | for(Int_t ivar=0; ivar<vars->GetEntriesFast(); ivar++) { | |
274 | TString binvar = vars->At(ivar)->GetName(); | |
275 | AliDebug(1,Form(" Check ivar %d binvar %s",ivar,binvar.Data())); | |
276 | ||
277 | // check for cuts and ranges by the user | |
278 | if(binvar.Contains(cutvar)) { | |
279 | TObjArray *limits = binvar.Tokenize("#"); | |
280 | ||
281 | Double_t binmin = atof(limits->At(1)->GetName()); | |
282 | Double_t binmax = atof(limits->At(2)->GetName()); | |
283 | AliDebug(1,Form(" bin %s var %s [%.2f,%.2f]",binvar.Data(),limits->At(0)->GetName(),binmin,binmax)); | |
284 | ||
285 | // remove histogram from array | |
286 | if(binmin < min || binmax < min || binmin > max || binmax > max ) { | |
287 | AliDebug(1,Form(" removed, out of range min %.2f,%.2f max %.2f,%.2f",binmin,min,binmax,max)); | |
288 | histos->AddAt(0x0,i); | |
289 | } | |
290 | if(bFndBin && !(binmin == min && binmax == max)) { | |
291 | histos->AddAt(0x0,i); | |
292 | AliDebug(1,Form(" removed, within range min %.2f,%.2f max %.2f,%.2f",binmin,min,binmax,max)); | |
293 | } | |
294 | // clean up | |
295 | if(limits) delete limits; | |
296 | ||
297 | // do we have found an exact bin | |
298 | if(binmin==min && binmax==max) bFndBin=kTRUE; | |
299 | ||
300 | } | |
301 | ||
302 | } | |
303 | // clean up | |
304 | if(vars) delete vars; | |
305 | ||
306 | } | |
307 | ||
308 | } | |
309 | ||
310 | // compress the array by removing all empty histos | |
311 | histos->Compress(); | |
312 | AliDebug(1,Form(" Compression: %d histograms left",histos->GetEntriesFast())); | |
313 | ||
314 | // merge histograms | |
315 | TH1F* hist = MergeHistos(histos); | |
316 | return hist; | |
317 | } | |
318 | ||
319 | //________________________________________________________________ | |
320 | TH1F* AliDielectronHFhelper::MergeHistos(TObjArray *arr) | |
321 | { | |
322 | // | |
323 | // merge histos to one single histogram | |
324 | // | |
325 | ||
326 | if(arr->GetEntriesFast()<1) { AliError("[E] No more histosgrams left!"); return 0x0; } | |
327 | ||
328 | TH1F *final=(TH1F*) arr->At(0)->Clone(); | |
329 | if(!final) return 0x0; | |
330 | ||
331 | final->Reset("CE"); | |
332 | final->SetTitle(""); //TODO: change in future | |
333 | for(Int_t i=0; i<arr->GetEntriesFast(); i++) { | |
334 | final->Add((TH1F*)arr->At(i)); | |
335 | } | |
336 | arr->Clear(); | |
337 | ||
338 | return final; | |
339 | } | |
340 | ||
341 | //________________________________________________________________ | |
342 | void AliDielectronHFhelper::CheckCuts(TObjArray *arr) | |
343 | { | |
344 | // | |
345 | // Compare histo binning and cut variables. Add necessary cuts (largest limit) | |
346 | // | |
347 | ||
348 | ||
349 | // build array with bin variable, minimum and maximum bin values | |
350 | TString titleFIRST = arr->First()->GetTitle(); | |
351 | TString titleLAST = arr->Last()->GetTitle(); | |
352 | TObjArray* binvarsF = titleFIRST.Tokenize(":#"); | |
353 | TObjArray* binvarsL = titleLAST.Tokenize(":#"); | |
354 | Double_t binmin[kMaxCuts]= {0.0}; | |
355 | Double_t binmax[kMaxCuts]= {0.0}; | |
356 | for(Int_t ivar=0; ivar<binvarsF->GetEntriesFast(); ivar++) { | |
357 | ||
358 | TString elementF=binvarsF->At(ivar)->GetName(); | |
359 | TString elementL=binvarsL->At(ivar)->GetName(); | |
360 | AliDebug(1,Form(" binvar %d: %s,%s",ivar,elementF.Data(),elementL.Data())); | |
361 | ||
362 | switch(ivar%3) { | |
363 | case 0: continue; break; | |
364 | case 1: binmin[(int)ivar/3]=atof(elementF.Data()); break; | |
365 | case 2: binmax[(int)ivar/3]=atof(elementL.Data()); break; | |
366 | } | |
367 | ||
368 | binvarsF->AddAt(0x0,ivar); | |
369 | } | |
370 | binvarsF->Compress(); | |
371 | ||
372 | // loop over all vars and cuts, check for missing stuff | |
373 | for(Int_t ivar=0; ivar<binvarsF->GetEntriesFast(); ivar++) { | |
374 | ||
375 | TString binvar=binvarsF->At(ivar)->GetName(); | |
376 | Bool_t selected=kFALSE; | |
377 | ||
378 | AliDebug(1,Form(" check cuts %d %s [%.2f,%.2f]",ivar,binvar.Data(),binmin[ivar],binmax[ivar])); | |
379 | // loop over all cuts and check for missing stuff | |
380 | for(Int_t icut=0; icut<fCutLowLimits.GetNrows(); icut++) { | |
381 | if(binvar.Contains(fCutVars->At(icut)->GetName())) { selected=kTRUE; break; } | |
382 | // else break; | |
383 | } | |
384 | ||
385 | // add missing cut with max limits | |
386 | if(!selected) { | |
387 | AliWarning("Not all bin variables covered. Add additional cut!"); | |
388 | SetRangeUser(binvar.Data(),binmin[ivar],binmax[ivar]); | |
389 | } | |
390 | ||
391 | } | |
392 | ||
393 | // clean up | |
394 | if(binvarsF) delete binvarsF; | |
395 | if(binvarsL) delete binvarsL; | |
396 | } | |
397 | ||
398 | //________________________________________________________________ | |
443a091c | 399 | void AliDielectronHFhelper::Print(const Option_t* /*option*/) const |
5e2cf960 | 400 | { |
401 | ||
402 | // | |
403 | // Print out object contents | |
404 | // | |
405 | ||
406 | // pairtypes, steps and sources | |
407 | AliInfo(Form(" Number of steps: \t %d",fArrPairType->GetEntriesFast())); | |
408 | for(Int_t i=0; i<fArrPairType->GetEntriesFast(); i++) { | |
409 | AliInfo(Form(" Step %d:",0)); | |
410 | } | |
411 | ||
412 | } | |
413 | ||
414 | //________________________________________________________________ | |
415 | void AliDielectronHFhelper::PrintCuts() | |
416 | { | |
417 | ||
418 | // | |
419 | // Print out object contents | |
420 | // | |
421 | ||
422 | // loop over all cuts | |
423 | AliInfo(" Selected cuts:"); | |
424 | for(Int_t icut=0; icut<fCutLowLimits.GetNrows(); icut++) | |
425 | AliInfo(Form(" %d: %s [%.2f,%.2f]",icut,fCutVars->At(icut)->GetName(),fCutLowLimits(icut),fCutUpLimits(icut))); | |
426 | ||
427 | } | |
428 |