]>
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 | ||
47 | #include "AliDielectronHFhelper.h" | |
48 | #include "AliDielectronHF.h" | |
49 | ||
50 | //ClassImp(AliDielectronHFhelper) | |
51 | ||
52 | //const char* AliDielectronHFhelper::fCutVars[AliDielectronHFhelper::kMaxCuts] = {"","","","","","","","","",""}; | |
53 | ||
54 | //________________________________________________________________ | |
55 | AliDielectronHFhelper::AliDielectronHFhelper(const char* filename) : | |
56 | TNamed(), | |
57 | fArrPairType(0x0), | |
58 | fCutVars(0x0), | |
59 | fCutLowLimits(0), | |
60 | fCutUpLimits(0) | |
61 | { | |
62 | // | |
63 | // get HF container(s) from file 'filename' | |
64 | // | |
65 | SetHFArray(filename); | |
66 | ||
67 | } | |
68 | ||
69 | //________________________________________________________________ | |
70 | AliDielectronHFhelper::~AliDielectronHFhelper() | |
71 | { | |
72 | // | |
73 | // dtor | |
74 | // | |
75 | if(fArrPairType) delete fArrPairType; | |
76 | if(fCutVars) delete fCutVars; | |
77 | ||
78 | } | |
79 | ||
80 | //________________________________________________________________ | |
81 | void AliDielectronHFhelper::SetHFArray(const char* filename) | |
82 | { | |
83 | // | |
84 | // get HF containers from file | |
85 | // | |
86 | ||
87 | TFile *f = TFile::Open(filename); | |
88 | ||
89 | TList *l=f->GetListOfKeys(); | |
90 | TIter nextKey(l); | |
91 | TKey *k=0x0; | |
92 | while ( (k=static_cast<TKey*>(nextKey())) ){ | |
93 | ||
94 | TObject *o=k->ReadObj(); | |
95 | if (o->IsA()==TList::Class()){ | |
96 | ||
97 | TList *tlist=(TList*)o; | |
98 | ||
99 | TIter next(tlist); | |
100 | TObject *obj=0x0; | |
101 | while ((obj = next())) { | |
102 | TString objname(obj->GetName()); | |
103 | ||
104 | if( objname.Contains("_HF") && obj->IsA()==TObjArray::Class()) { | |
105 | fArrPairType = new TObjArray( *(dynamic_cast<TObjArray*>(obj)) ); | |
106 | //fArrPairType->Print(); | |
107 | return; | |
108 | } | |
109 | } | |
110 | } | |
111 | } | |
112 | ||
113 | } | |
114 | //________________________________________________________________ | |
115 | void AliDielectronHFhelper::SetRangeUser(const char *varname, Double_t min, Double_t max, Bool_t leg) | |
116 | { | |
117 | // | |
118 | // Set range from variable name | |
119 | // | |
120 | // Int_t size=sizeof(fCutVars)/sizeof(const char*); | |
121 | Int_t size=fCutLowLimits.GetNrows(); | |
122 | ||
123 | if(size>=kMaxCuts) return; | |
124 | ||
125 | // arrays | |
126 | if(!fCutVars) { | |
127 | fCutVars = new TObjArray(); | |
128 | fCutVars->SetOwner(); | |
129 | } | |
130 | fCutLowLimits.ResizeTo(size+1); | |
131 | fCutUpLimits.ResizeTo(size+1); | |
132 | ||
133 | // fill | |
134 | // fCutVars[size]=Form("%s%s",(leg?"Leg":""),varname); | |
135 | TObjString *str = new TObjString(Form("%s%s",(leg?"Leg":""),varname)); | |
136 | fCutVars->Add(str); | |
137 | fCutLowLimits(size) = min; | |
138 | fCutUpLimits(size) = max; | |
139 | AliWarning(Form(" %s [%.2f,%.2f]",fCutVars->At(size)->GetName(),fCutLowLimits(size),fCutUpLimits(size))); | |
140 | } | |
141 | ||
142 | //________________________________________________________________ | |
143 | void AliDielectronHFhelper::SetRangeUser(AliDielectronVarManager::ValueTypes type, Double_t min, Double_t max, Bool_t leg) | |
144 | { | |
145 | // | |
146 | // Set range from AliDielectronVarManager | |
147 | // | |
148 | SetRangeUser(AliDielectronVarManager::GetValueName(type), min, max, leg); | |
149 | } | |
150 | ||
151 | //________________________________________________________________ | |
152 | TH1F* AliDielectronHFhelper::GetHistogram(const char *step) | |
153 | { | |
154 | // | |
155 | // main function to recive a single histogram | |
156 | // | |
157 | ||
158 | TObjArray *histos = (TObjArray*) fArrPairType->FindObject(step); | |
159 | AliInfo(Form(" Step %s selected",step)); | |
160 | if(!histos) return 0x0; | |
161 | ||
162 | TH1F *hist = FindHistograms(histos); | |
163 | return hist; | |
164 | } | |
165 | ||
166 | //________________________________________________________________ | |
167 | TH1F* AliDielectronHFhelper::FindHistograms(TObjArray *histos) | |
168 | { | |
169 | // | |
170 | // exclude histograms | |
171 | // | |
172 | ||
173 | // debug | |
174 | // TString title = histos->At(0)->GetTitle(); | |
175 | // TObjArray* vars = title.Tokenize(":"); | |
176 | // AliDebug(1,Form(" number of cuts/vars: %d/%d",fCutLowLimits.GetNrows(),vars->GetEntriesFast())); | |
177 | ||
178 | // check for missing cuts | |
179 | CheckCuts(histos); | |
180 | ||
181 | // loop over all cuts | |
182 | for(Int_t icut=0; icut<fCutLowLimits.GetNrows(); icut++) { | |
183 | ||
184 | Bool_t bFndBin = kFALSE; // exact bin found | |
185 | const char *cutvar = fCutVars->At(icut)->GetName(); | |
186 | Double_t min = fCutLowLimits(icut); | |
187 | Double_t max = fCutUpLimits(icut); | |
188 | AliDebug(1,Form(" Cut %d: %s [%.2f,%.2f]",icut,cutvar,min,max)); | |
189 | ||
190 | // loop over all histograms | |
191 | for(Int_t i=0; i<histos->GetEntriesFast(); i++) { | |
192 | ||
193 | // continue if already empty | |
194 | if(!histos->At(i)) continue; | |
195 | ||
196 | // collect binning from histo title | |
197 | TString title = histos->At(i)->GetTitle(); | |
198 | if(title.IsNull()) continue; | |
199 | AliDebug(1,Form(" histo title: %s",title.Data())); | |
200 | ||
201 | TObjArray *vars = title.Tokenize(":"); | |
202 | for(Int_t ivar=0; ivar<vars->GetEntriesFast(); ivar++) { | |
203 | TString binvar = vars->At(ivar)->GetName(); | |
204 | AliDebug(1,Form(" Check ivar %d binvar %s",ivar,binvar.Data())); | |
205 | ||
206 | // check for cuts and ranges by the user | |
207 | if(binvar.Contains(cutvar)) { | |
208 | TObjArray *limits = binvar.Tokenize("#"); | |
209 | ||
210 | Double_t binmin = atof(limits->At(1)->GetName()); | |
211 | Double_t binmax = atof(limits->At(2)->GetName()); | |
212 | AliDebug(1,Form(" bin %s var %s [%.2f,%.2f]",binvar.Data(),limits->At(0)->GetName(),binmin,binmax)); | |
213 | ||
214 | // remove histogram from array | |
215 | if(binmin < min || binmax < min || binmin > max || binmax > max ) { | |
216 | AliDebug(1,Form(" removed, out of range min %.2f,%.2f max %.2f,%.2f",binmin,min,binmax,max)); | |
217 | histos->AddAt(0x0,i); | |
218 | } | |
219 | if(bFndBin && !(binmin == min && binmax == max)) { | |
220 | histos->AddAt(0x0,i); | |
221 | AliDebug(1,Form(" removed, within range min %.2f,%.2f max %.2f,%.2f",binmin,min,binmax,max)); | |
222 | } | |
223 | // clean up | |
224 | if(limits) delete limits; | |
225 | ||
226 | // do we have found an exact bin | |
227 | if(binmin==min && binmax==max) bFndBin=kTRUE; | |
228 | ||
229 | } | |
230 | ||
231 | } | |
232 | // clean up | |
233 | if(vars) delete vars; | |
234 | ||
235 | } | |
236 | ||
237 | } | |
238 | ||
239 | // compress the array by removing all empty histos | |
240 | histos->Compress(); | |
241 | AliDebug(1,Form(" Compression: %d histograms left",histos->GetEntriesFast())); | |
242 | ||
243 | // merge histograms | |
244 | TH1F* hist = MergeHistos(histos); | |
245 | return hist; | |
246 | } | |
247 | ||
248 | //________________________________________________________________ | |
249 | TH1F* AliDielectronHFhelper::MergeHistos(TObjArray *arr) | |
250 | { | |
251 | // | |
252 | // merge histos to one single histogram | |
253 | // | |
254 | ||
255 | if(arr->GetEntriesFast()<1) { AliError("[E] No more histosgrams left!"); return 0x0; } | |
256 | ||
257 | TH1F *final=(TH1F*) arr->At(0)->Clone(); | |
258 | if(!final) return 0x0; | |
259 | ||
260 | final->Reset("CE"); | |
261 | final->SetTitle(""); //TODO: change in future | |
262 | for(Int_t i=0; i<arr->GetEntriesFast(); i++) { | |
263 | final->Add((TH1F*)arr->At(i)); | |
264 | } | |
265 | arr->Clear(); | |
266 | ||
267 | return final; | |
268 | } | |
269 | ||
270 | //________________________________________________________________ | |
271 | void AliDielectronHFhelper::CheckCuts(TObjArray *arr) | |
272 | { | |
273 | // | |
274 | // Compare histo binning and cut variables. Add necessary cuts (largest limit) | |
275 | // | |
276 | ||
277 | ||
278 | // build array with bin variable, minimum and maximum bin values | |
279 | TString titleFIRST = arr->First()->GetTitle(); | |
280 | TString titleLAST = arr->Last()->GetTitle(); | |
281 | TObjArray* binvarsF = titleFIRST.Tokenize(":#"); | |
282 | TObjArray* binvarsL = titleLAST.Tokenize(":#"); | |
283 | Double_t binmin[kMaxCuts]= {0.0}; | |
284 | Double_t binmax[kMaxCuts]= {0.0}; | |
285 | for(Int_t ivar=0; ivar<binvarsF->GetEntriesFast(); ivar++) { | |
286 | ||
287 | TString elementF=binvarsF->At(ivar)->GetName(); | |
288 | TString elementL=binvarsL->At(ivar)->GetName(); | |
289 | AliDebug(1,Form(" binvar %d: %s,%s",ivar,elementF.Data(),elementL.Data())); | |
290 | ||
291 | switch(ivar%3) { | |
292 | case 0: continue; break; | |
293 | case 1: binmin[(int)ivar/3]=atof(elementF.Data()); break; | |
294 | case 2: binmax[(int)ivar/3]=atof(elementL.Data()); break; | |
295 | } | |
296 | ||
297 | binvarsF->AddAt(0x0,ivar); | |
298 | } | |
299 | binvarsF->Compress(); | |
300 | ||
301 | // loop over all vars and cuts, check for missing stuff | |
302 | for(Int_t ivar=0; ivar<binvarsF->GetEntriesFast(); ivar++) { | |
303 | ||
304 | TString binvar=binvarsF->At(ivar)->GetName(); | |
305 | Bool_t selected=kFALSE; | |
306 | ||
307 | AliDebug(1,Form(" check cuts %d %s [%.2f,%.2f]",ivar,binvar.Data(),binmin[ivar],binmax[ivar])); | |
308 | // loop over all cuts and check for missing stuff | |
309 | for(Int_t icut=0; icut<fCutLowLimits.GetNrows(); icut++) { | |
310 | if(binvar.Contains(fCutVars->At(icut)->GetName())) { selected=kTRUE; break; } | |
311 | // else break; | |
312 | } | |
313 | ||
314 | // add missing cut with max limits | |
315 | if(!selected) { | |
316 | AliWarning("Not all bin variables covered. Add additional cut!"); | |
317 | SetRangeUser(binvar.Data(),binmin[ivar],binmax[ivar]); | |
318 | } | |
319 | ||
320 | } | |
321 | ||
322 | // clean up | |
323 | if(binvarsF) delete binvarsF; | |
324 | if(binvarsL) delete binvarsL; | |
325 | } | |
326 | ||
327 | //________________________________________________________________ | |
328 | void AliDielectronHFhelper::Print() | |
329 | { | |
330 | ||
331 | // | |
332 | // Print out object contents | |
333 | // | |
334 | ||
335 | // pairtypes, steps and sources | |
336 | AliInfo(Form(" Number of steps: \t %d",fArrPairType->GetEntriesFast())); | |
337 | for(Int_t i=0; i<fArrPairType->GetEntriesFast(); i++) { | |
338 | AliInfo(Form(" Step %d:",0)); | |
339 | } | |
340 | ||
341 | } | |
342 | ||
343 | //________________________________________________________________ | |
344 | void AliDielectronHFhelper::PrintCuts() | |
345 | { | |
346 | ||
347 | // | |
348 | // Print out object contents | |
349 | // | |
350 | ||
351 | // loop over all cuts | |
352 | AliInfo(" Selected cuts:"); | |
353 | for(Int_t icut=0; icut<fCutLowLimits.GetNrows(); icut++) | |
354 | AliInfo(Form(" %d: %s [%.2f,%.2f]",icut,fCutVars->At(icut)->GetName(),fCutLowLimits(icut),fCutUpLimits(icut))); | |
355 | ||
356 | } | |
357 |