]>
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 | //________________________________________________________________ | |
e0f6eeb2 | 56 | AliDielectronHFhelper::AliDielectronHFhelper(const char* filename, const char* container) : |
5e2cf960 | 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 | // | |
e0f6eeb2 | 66 | SetHFArray(filename, container); |
187de573 | 67 | |
5e2cf960 | 68 | } |
69 | ||
70 | //________________________________________________________________ | |
71 | AliDielectronHFhelper::~AliDielectronHFhelper() | |
72 | { | |
73 | // | |
74 | // dtor | |
75 | // | |
76 | if(fArrPairType) delete fArrPairType; | |
77 | if(fCutVars) delete fCutVars; | |
187de573 | 78 | |
5e2cf960 | 79 | } |
80 | ||
81 | //________________________________________________________________ | |
e0f6eeb2 | 82 | void AliDielectronHFhelper::SetHFArray(const char* filename, const char* container) |
5e2cf960 | 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())) ){ | |
187de573 | 94 | |
5e2cf960 | 95 | TObject *o=k->ReadObj(); |
96 | if (o->IsA()==TList::Class()){ | |
187de573 | 97 | |
5e2cf960 | 98 | TList *tlist=(TList*)o; |
187de573 | 99 | |
5e2cf960 | 100 | TIter next(tlist); |
101 | TObject *obj=0x0; | |
102 | while ((obj = next())) { | |
103 | TString objname(obj->GetName()); | |
104 | ||
e0f6eeb2 | 105 | if( objname.Contains(Form("%s_HF",container)) && obj->IsA()==TObjArray::Class()) { |
5e2cf960 | 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*); | |
187de573 | 122 | |
5e2cf960 | 123 | Int_t size=fCutLowLimits.GetNrows(); |
124 | ||
187de573 | 125 | // check if cut is already set |
126 | for(Int_t icut=0; icut<size; icut++) { | |
127 | TString cutName = fCutVars->At(icut)->GetName(); | |
128 | if(!cutName.CompareTo(Form("%s%s",(leg?"Leg":""),varname))) { | |
129 | UnsetRangeUser(varname,leg); | |
130 | SetRangeUser(varname, min, max, leg); | |
131 | return; | |
132 | } | |
133 | } | |
134 | ||
5e2cf960 | 135 | if(size>=kMaxCuts) return; |
136 | ||
137 | // arrays | |
138 | if(!fCutVars) { | |
139 | fCutVars = new TObjArray(); | |
140 | fCutVars->SetOwner(); | |
141 | } | |
142 | fCutLowLimits.ResizeTo(size+1); | |
143 | fCutUpLimits.ResizeTo(size+1); | |
144 | ||
145 | // fill | |
5e2cf960 | 146 | TObjString *str = new TObjString(Form("%s%s",(leg?"Leg":""),varname)); |
147 | fCutVars->Add(str); | |
148 | fCutLowLimits(size) = min; | |
149 | fCutUpLimits(size) = max; | |
150 | AliWarning(Form(" %s [%.2f,%.2f]",fCutVars->At(size)->GetName(),fCutLowLimits(size),fCutUpLimits(size))); | |
151 | } | |
152 | ||
153 | //________________________________________________________________ | |
154 | void AliDielectronHFhelper::SetRangeUser(AliDielectronVarManager::ValueTypes type, Double_t min, Double_t max, Bool_t leg) | |
155 | { | |
156 | // | |
187de573 | 157 | // Set range from AliDielectronVarManager |
5e2cf960 | 158 | // |
159 | SetRangeUser(AliDielectronVarManager::GetValueName(type), min, max, leg); | |
160 | } | |
161 | ||
4d7704c5 | 162 | //________________________________________________________________ |
163 | void AliDielectronHFhelper::UnsetRangeUser(const char *varname, Bool_t leg) | |
164 | { | |
165 | // | |
166 | // unset range from variable name | |
167 | // | |
168 | Int_t size=fCutLowLimits.GetNrows(); | |
187de573 | 169 | // PrintCuts(); |
4d7704c5 | 170 | TVectorD newlow; |
171 | TVectorD newup; | |
172 | ||
187de573 | 173 | // find cut and build new vectors w/o it |
4d7704c5 | 174 | Int_t ientries = 0; |
175 | for(Int_t icut=0; icut<size; icut++) { | |
176 | ||
177 | TString cutName = fCutVars->At(icut)->GetName(); | |
187de573 | 178 | if(!cutName.CompareTo(Form("%s%s",(leg?"Leg":""),varname))) { |
4d7704c5 | 179 | fCutVars->AddAt(0x0,icut); |
180 | continue; | |
181 | } | |
187de573 | 182 | |
4d7704c5 | 183 | // fill new vectors |
184 | newlow.ResizeTo(ientries+1); | |
185 | newup.ResizeTo(ientries+1); | |
186 | newlow(ientries) = fCutLowLimits(icut); | |
187 | newup(ientries) = fCutUpLimits(icut); | |
187de573 | 188 | |
4d7704c5 | 189 | ientries++; |
190 | } | |
187de573 | 191 | |
4d7704c5 | 192 | // adapt new arrays/vectors |
193 | fCutVars->Compress(); | |
194 | ||
195 | fCutLowLimits.ResizeTo(ientries); | |
196 | fCutUpLimits.ResizeTo(ientries); | |
197 | for(Int_t icut=0; icut<ientries; icut++) { | |
198 | fCutLowLimits(icut) = newlow(icut); | |
199 | fCutUpLimits(icut) = newup(icut); | |
200 | } | |
187de573 | 201 | // PrintCuts(); |
202 | ||
4d7704c5 | 203 | } |
204 | ||
205 | //________________________________________________________________ | |
206 | void AliDielectronHFhelper::UnsetRangeUser(AliDielectronVarManager::ValueTypes type, Bool_t leg) | |
207 | { | |
208 | // | |
187de573 | 209 | // Unset range from AliDielectronVarManager |
4d7704c5 | 210 | // |
211 | UnsetRangeUser(AliDielectronVarManager::GetValueName(type), leg); | |
212 | } | |
213 | ||
443a091c | 214 | //________________________________________________________________ |
187de573 | 215 | TObjArray* AliDielectronHFhelper::CollectHistos() |
443a091c | 216 | { |
217 | // | |
218 | // collect histograms for all kind of pair types or sources | |
219 | // | |
187de573 | 220 | |
443a091c | 221 | TObjArray *collection = new TObjArray(AliDielectron::kEv1PMRot+1); |
222 | ||
187de573 | 223 | TObjArray *histArr = (TObjArray*) fArrPairType->Clone("tmpArr"); |
1ae2dca4 | 224 | if(!histArr) return 0x0; |
187de573 | 225 | histArr->SetOwner(kTRUE); |
226 | ||
443a091c | 227 | // loop over max. available pair types |
228 | for(Int_t i=0; i<AliDielectron::kEv1PMRot+1; i++) { | |
229 | ||
187de573 | 230 | collection->AddAt(GetHistogram(AliDielectron::PairClassName(i),histArr), i); |
231 | ||
232 | } | |
233 | ||
234 | // clean up the clone | |
235 | if(histArr) { | |
236 | delete histArr; | |
237 | histArr=0; | |
443a091c | 238 | } |
239 | ||
240 | return collection; | |
241 | } | |
242 | ||
5e2cf960 | 243 | //________________________________________________________________ |
35363fb9 | 244 | TH1* AliDielectronHFhelper::GetHistogram(const char *step, TObjArray *histArr) |
5e2cf960 | 245 | { |
246 | // | |
187de573 | 247 | // main function to recieve a single histogram |
248 | // TODO: check memory | |
249 | ||
250 | AliDebug(1,Form(" Step %s selected",step)); | |
251 | ||
252 | TObjArray *histos= 0x0; | |
35363fb9 | 253 | TH1 *hist = 0x0; |
187de573 | 254 | if(!histArr) { |
255 | histos = (TObjArray*) fArrPairType->FindObject(step)->Clone("tmpArr"); | |
256 | } | |
257 | else { | |
258 | histos = (TObjArray*) histArr->FindObject(step); | |
259 | } | |
5e2cf960 | 260 | |
187de573 | 261 | if(histos) hist = FindHistograms(histos); |
5e2cf960 | 262 | return hist; |
187de573 | 263 | |
5e2cf960 | 264 | } |
265 | ||
266 | //________________________________________________________________ | |
35363fb9 | 267 | TH1* AliDielectronHFhelper::FindHistograms(TObjArray *histos) |
5e2cf960 | 268 | { |
269 | // | |
270 | // exclude histograms | |
271 | // | |
187de573 | 272 | |
5e2cf960 | 273 | // debug |
274 | // TString title = histos->At(0)->GetTitle(); | |
275 | // TObjArray* vars = title.Tokenize(":"); | |
187de573 | 276 | // AliDebug(1,Form(" number of cuts/vars: %d/%d",fCutLowLimits.GetNrows(),vars->GetEntriesFast())); |
277 | ||
5e2cf960 | 278 | // check for missing cuts |
279 | CheckCuts(histos); | |
187de573 | 280 | |
5e2cf960 | 281 | // loop over all cuts |
282 | for(Int_t icut=0; icut<fCutLowLimits.GetNrows(); icut++) { | |
283 | ||
284 | Bool_t bFndBin = kFALSE; // exact bin found | |
285 | const char *cutvar = fCutVars->At(icut)->GetName(); | |
286 | Double_t min = fCutLowLimits(icut); | |
287 | Double_t max = fCutUpLimits(icut); | |
187de573 | 288 | AliDebug(5,Form(" Cut %d: %s [%.2f,%.2f]",icut,cutvar,min,max)); |
5e2cf960 | 289 | |
290 | // loop over all histograms | |
291 | for(Int_t i=0; i<histos->GetEntriesFast(); i++) { | |
292 | ||
293 | // continue if already empty | |
294 | if(!histos->At(i)) continue; | |
295 | ||
296 | // collect binning from histo title | |
35363fb9 | 297 | TString title = histos->At(i)->GetName(); |
5e2cf960 | 298 | if(title.IsNull()) continue; |
187de573 | 299 | AliDebug(10,Form(" histo title: %s",title.Data())); |
5e2cf960 | 300 | |
301 | TObjArray *vars = title.Tokenize(":"); | |
302 | for(Int_t ivar=0; ivar<vars->GetEntriesFast(); ivar++) { | |
303 | TString binvar = vars->At(ivar)->GetName(); | |
187de573 | 304 | AliDebug(10,Form(" Check ivar %d binvar %s",ivar,binvar.Data())); |
305 | ||
5e2cf960 | 306 | // check for cuts and ranges by the user |
307 | if(binvar.Contains(cutvar)) { | |
308 | TObjArray *limits = binvar.Tokenize("#"); | |
187de573 | 309 | |
5e2cf960 | 310 | Double_t binmin = atof(limits->At(1)->GetName()); |
311 | Double_t binmax = atof(limits->At(2)->GetName()); | |
187de573 | 312 | AliDebug(10,Form(" bin %s var %s [%.2f,%.2f]",binvar.Data(),limits->At(0)->GetName(),binmin,binmax)); |
313 | ||
5e2cf960 | 314 | // remove histogram from array |
315 | if(binmin < min || binmax < min || binmin > max || binmax > max ) { | |
187de573 | 316 | AliDebug(10,Form(" removed, out of range min %.2f,%.2f max %.2f,%.2f",binmin,min,binmax,max)); |
5e2cf960 | 317 | histos->AddAt(0x0,i); |
318 | } | |
319 | if(bFndBin && !(binmin == min && binmax == max)) { | |
8d42b5b9 | 320 | histos->AddAt(0x0,i); |
321 | AliDebug(10,Form(" removed, within range min %.2f,%.2f max %.2f,%.2f",binmin,min,binmax,max)); | |
322 | } | |
5e2cf960 | 323 | // clean up |
324 | if(limits) delete limits; | |
325 | ||
326 | // do we have found an exact bin | |
327 | if(binmin==min && binmax==max) bFndBin=kTRUE; | |
328 | ||
329 | } | |
330 | ||
331 | } | |
332 | // clean up | |
333 | if(vars) delete vars; | |
187de573 | 334 | |
5e2cf960 | 335 | } |
187de573 | 336 | |
5e2cf960 | 337 | } |
187de573 | 338 | |
5e2cf960 | 339 | // compress the array by removing all empty histos |
187de573 | 340 | histos->Compress(); |
5e2cf960 | 341 | AliDebug(1,Form(" Compression: %d histograms left",histos->GetEntriesFast())); |
342 | ||
343 | // merge histograms | |
35363fb9 | 344 | TH1* hist = MergeHistos(histos); |
e0f6eeb2 | 345 | if(hist) AliDebug(1,Form(" Merging: %e histogram entries",hist->GetEntries())); |
5e2cf960 | 346 | return hist; |
347 | } | |
348 | ||
349 | //________________________________________________________________ | |
35363fb9 | 350 | TH1* AliDielectronHFhelper::MergeHistos(TObjArray *arr) |
5e2cf960 | 351 | { |
352 | // | |
353 | // merge histos to one single histogram | |
354 | // | |
5e2cf960 | 355 | |
187de573 | 356 | if(arr->GetEntriesFast()<1) { AliError(" No more histosgrams left!"); return 0x0; } |
357 | ||
35363fb9 | 358 | TObject *final=arr->At(0)->Clone(); |
5e2cf960 | 359 | if(!final) return 0x0; |
187de573 | 360 | |
35363fb9 | 361 | TList listH; |
362 | TString listHargs; | |
363 | listHargs.Form("((TCollection*)0x%lx)", (ULong_t)&listH); | |
364 | Int_t error = 0; | |
365 | ||
366 | // final->Reset("CE"); | |
367 | // final->SetTitle(""); //TODO: change in future | |
368 | for(Int_t i=1; i<arr->GetEntriesFast(); i++) { | |
369 | listH.Add(arr->At(i)); | |
370 | // final->Add((TH1*)arr->At(i)); | |
5e2cf960 | 371 | } |
35363fb9 | 372 | // arr->Clear(); |
5e2cf960 | 373 | |
35363fb9 | 374 | final->Execute("Merge", listHargs.Data(), &error); |
375 | return (TH1*)final; | |
5e2cf960 | 376 | } |
377 | ||
378 | //________________________________________________________________ | |
379 | void AliDielectronHFhelper::CheckCuts(TObjArray *arr) | |
380 | { | |
381 | // | |
779267ed | 382 | // Compare histo binning and cut variables. Add necessary cuts (largest limits) |
5e2cf960 | 383 | // |
384 | ||
385 | ||
386 | // build array with bin variable, minimum and maximum bin values | |
35363fb9 | 387 | TString titleFIRST = arr->First()->GetName(); |
388 | TString titleLAST = arr->Last()->GetName(); | |
5e2cf960 | 389 | TObjArray* binvarsF = titleFIRST.Tokenize(":#"); |
390 | TObjArray* binvarsL = titleLAST.Tokenize(":#"); | |
391 | Double_t binmin[kMaxCuts]= {0.0}; | |
392 | Double_t binmax[kMaxCuts]= {0.0}; | |
393 | for(Int_t ivar=0; ivar<binvarsF->GetEntriesFast(); ivar++) { | |
394 | ||
395 | TString elementF=binvarsF->At(ivar)->GetName(); | |
396 | TString elementL=binvarsL->At(ivar)->GetName(); | |
397 | AliDebug(1,Form(" binvar %d: %s,%s",ivar,elementF.Data(),elementL.Data())); | |
187de573 | 398 | |
5e2cf960 | 399 | switch(ivar%3) { |
400 | case 0: continue; break; | |
401 | case 1: binmin[(int)ivar/3]=atof(elementF.Data()); break; | |
402 | case 2: binmax[(int)ivar/3]=atof(elementL.Data()); break; | |
403 | } | |
187de573 | 404 | |
5e2cf960 | 405 | binvarsF->AddAt(0x0,ivar); |
406 | } | |
407 | binvarsF->Compress(); | |
187de573 | 408 | |
5e2cf960 | 409 | // loop over all vars and cuts, check for missing stuff |
410 | for(Int_t ivar=0; ivar<binvarsF->GetEntriesFast(); ivar++) { | |
187de573 | 411 | |
5e2cf960 | 412 | TString binvar=binvarsF->At(ivar)->GetName(); |
413 | Bool_t selected=kFALSE; | |
414 | ||
415 | AliDebug(1,Form(" check cuts %d %s [%.2f,%.2f]",ivar,binvar.Data(),binmin[ivar],binmax[ivar])); | |
416 | // loop over all cuts and check for missing stuff | |
417 | for(Int_t icut=0; icut<fCutLowLimits.GetNrows(); icut++) { | |
418 | if(binvar.Contains(fCutVars->At(icut)->GetName())) { selected=kTRUE; break; } | |
419 | // else break; | |
420 | } | |
187de573 | 421 | |
5e2cf960 | 422 | // add missing cut with max limits |
423 | if(!selected) { | |
187de573 | 424 | AliWarning(Form(" Bin variable %s not covered. Add cut!",binvar.Data())); |
425 | Bool_t leg = binvar.BeginsWith("Leg"); | |
426 | if(leg) binvar.Remove(0,3); | |
427 | SetRangeUser(binvar.Data(),binmin[ivar],binmax[ivar], leg); | |
5e2cf960 | 428 | } |
187de573 | 429 | |
5e2cf960 | 430 | } |
187de573 | 431 | |
432 | // clean up | |
5e2cf960 | 433 | if(binvarsF) delete binvarsF; |
434 | if(binvarsL) delete binvarsL; | |
435 | } | |
436 | ||
437 | //________________________________________________________________ | |
443a091c | 438 | void AliDielectronHFhelper::Print(const Option_t* /*option*/) const |
5e2cf960 | 439 | { |
440 | ||
441 | // | |
442 | // Print out object contents | |
443 | // | |
e0f6eeb2 | 444 | AliInfo(Form(" Container: %s",fArrPairType->GetName())); |
5e2cf960 | 445 | |
446 | // pairtypes, steps and sources | |
187de573 | 447 | AliInfo(Form(" Number of filled steps: %d",fArrPairType->GetEntries())); |
448 | for(Int_t istep=0; istep<fArrPairType->GetEntriesFast(); istep++) { | |
449 | if(fArrPairType->At(istep)) | |
450 | AliInfo(Form(" step %d: %s",istep,fArrPairType->At(istep)->GetName())); | |
451 | } | |
452 | ||
453 | AliInfo(Form(" Number of histograms: %d",((TObjArray*)fArrPairType->At(0))->GetEntriesFast())); | |
454 | ||
455 | TString title = ((TObjArray*)fArrPairType->At(0))->First()->GetTitle(); | |
456 | TObjArray* binvars = title.Tokenize(":"); | |
457 | AliInfo(Form(" Number of variables: %d",binvars->GetEntriesFast())); | |
09d5920f | 458 | delete binvars; |
187de573 | 459 | |
460 | TObjArray* binvars2 = title.Tokenize(":#"); | |
461 | for(Int_t ivar=0; ivar<binvars2->GetEntriesFast(); ivar++) { | |
462 | if(ivar%3) continue; | |
463 | AliInfo(Form(" variable %.0f: %s",((Double_t)ivar)/3+1,binvars2->At(ivar)->GetName())); | |
5e2cf960 | 464 | } |
09d5920f | 465 | delete binvars2; |
5e2cf960 | 466 | |
467 | } | |
468 | ||
469 | //________________________________________________________________ | |
470 | void AliDielectronHFhelper::PrintCuts() | |
471 | { | |
472 | ||
473 | // | |
474 | // Print out object contents | |
475 | // | |
476 | ||
477 | // loop over all cuts | |
478 | AliInfo(" Selected cuts:"); | |
479 | for(Int_t icut=0; icut<fCutLowLimits.GetNrows(); icut++) | |
480 | AliInfo(Form(" %d: %s [%.2f,%.2f]",icut,fCutVars->At(icut)->GetName(),fCutLowLimits(icut),fCutUpLimits(icut))); | |
187de573 | 481 | |
5e2cf960 | 482 | } |
483 |