]>
Commit | Line | Data |
---|---|---|
6551594b | 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 Correction framework draw helper // | |
18 | // // | |
19 | /* | |
20 | ||
21 | ||
22 | ||
23 | ||
24 | ||
25 | ||
26 | ||
27 | ||
28 | ||
29 | */ | |
30 | // // | |
31 | /////////////////////////////////////////////////////////////////////////// | |
32 | ||
33 | #include <TSeqCollection.h> | |
34 | #include <TObjArray.h> | |
35 | #include <TKey.h> | |
36 | #include <TList.h> | |
a655b716 | 37 | #include <TClass.h> |
6551594b | 38 | #include <TObject.h> |
572b0139 | 39 | #include <TVirtualPS.h> |
6551594b | 40 | #include <TFile.h> |
41 | #include <TString.h> | |
42 | #include <TObjString.h> | |
572b0139 | 43 | #include <TVectorD.h> |
6551594b | 44 | #include <TMath.h> |
45 | #include <TH1.h> | |
46 | #include <TH2.h> | |
47 | #include <TH3.h> | |
48 | #include <TPad.h> | |
49 | #include <TCanvas.h> | |
a655b716 | 50 | #include <TLegend.h> |
51 | #include <AliCFEffGrid.h> | |
6551594b | 52 | |
53 | #include <AliLog.h> | |
54 | ||
55 | #include "AliDielectronCFdraw.h" | |
56 | ||
57 | ClassImp(AliDielectronCFdraw) | |
58 | ||
59 | AliDielectronCFdraw::AliDielectronCFdraw() : | |
60 | TNamed(), | |
a655b716 | 61 | fCfContainer(0x0), |
572b0139 | 62 | fEffGrid(0x0), |
63 | fVdata(0) | |
6551594b | 64 | { |
65 | // | |
66 | // Ctor | |
67 | // | |
68 | } | |
69 | ||
70 | //________________________________________________________________ | |
71 | AliDielectronCFdraw::AliDielectronCFdraw(const char*name, const char* title) : | |
72 | TNamed(name,title), | |
a655b716 | 73 | fCfContainer(0x0), |
572b0139 | 74 | fEffGrid(0x0), |
75 | fVdata(0) | |
6551594b | 76 | { |
77 | // | |
78 | // Named Ctor | |
79 | // | |
80 | ||
81 | } | |
82 | ||
a655b716 | 83 | //________________________________________________________________ |
84 | AliDielectronCFdraw::AliDielectronCFdraw(AliCFContainer *cont) : | |
85 | TNamed(cont->GetName(), cont->GetTitle()), | |
86 | fCfContainer(cont), | |
572b0139 | 87 | fEffGrid(new AliCFEffGrid("eff","eff",*cont)), |
88 | fVdata(0) | |
a655b716 | 89 | { |
90 | // | |
91 | // directly set the CF container | |
92 | // | |
93 | ||
94 | } | |
95 | ||
96 | //________________________________________________________________ | |
97 | AliDielectronCFdraw::AliDielectronCFdraw(const char* filename) : | |
98 | TNamed(), | |
99 | fCfContainer(0x0), | |
572b0139 | 100 | fEffGrid(0x0), |
101 | fVdata(0) | |
a655b716 | 102 | { |
103 | // | |
104 | // get CF container(s) from file 'filename' | |
105 | // | |
106 | SetCFContainers(filename); | |
107 | } | |
108 | ||
6551594b | 109 | //________________________________________________________________ |
110 | void AliDielectronCFdraw::SetCFContainers(const TSeqCollection *arr) | |
111 | { | |
112 | // | |
113 | // Merge CF Container out of several containers | |
114 | // | |
115 | ||
116 | TIter next(arr); | |
117 | TObject *o=0x0; | |
118 | ||
119 | Int_t nstep=0; | |
120 | while ( (o=next()) ){ | |
121 | AliCFContainer *cf=dynamic_cast<AliCFContainer*>(o); | |
61d106d3 | 122 | if (!cf) continue; |
6551594b | 123 | nstep+=cf->GetNStep(); |
124 | } | |
61d106d3 | 125 | if (nstep==0) return; |
6551594b | 126 | Int_t nbins[1]={1}; |
127 | fCfContainer=new AliCFContainer(GetName(), GetTitle(), nstep, 1, nbins); | |
128 | ||
129 | //delete unneeded steps | |
572b0139 | 130 | // for (Int_t istep=0; istep<nstep; ++istep) delete fCfContainer->GetGrid(istep); |
6551594b | 131 | |
132 | //add step to the new container | |
133 | Int_t istep=0; | |
134 | for (Int_t icf=0; icf<arr->GetEntries(); ++icf){ | |
135 | AliCFContainer *cf=dynamic_cast<AliCFContainer*>(arr->At(icf)); | |
136 | if (!cf) continue; | |
137 | for (Int_t istepCurr=0; istepCurr<cf->GetNStep(); ++istepCurr){ | |
138 | fCfContainer->SetGrid(istep, cf->GetGrid(istepCurr)); | |
66b2c564 | 139 | fCfContainer->SetStepTitle(istep,Form("%s, Pair: %s",cf->GetTitle(),cf->GetStepTitle(istepCurr))); |
6551594b | 140 | ++istep; |
141 | } | |
142 | } | |
a655b716 | 143 | if (fEffGrid) delete fEffGrid; |
144 | fEffGrid=new AliCFEffGrid("eff","eff",*fCfContainer); | |
6551594b | 145 | } |
146 | ||
147 | //________________________________________________________________ | |
148 | void AliDielectronCFdraw::SetCFContainers(const char* filename) | |
149 | { | |
150 | // | |
151 | // get CF containers from file | |
152 | // | |
153 | ||
154 | TFile f(filename); | |
155 | TList *l=f.GetListOfKeys(); | |
61d106d3 | 156 | TIter nextKey(l); |
157 | TKey *k=0x0; | |
158 | while ( (k=static_cast<TKey*>(nextKey())) ){ | |
159 | TObject *o=k->ReadObj(); | |
160 | if (o->IsA()->InheritsFrom(TSeqCollection::Class())){ | |
161 | TSeqCollection *arr=static_cast<TSeqCollection*>(o); | |
162 | SetCFContainers(arr); | |
163 | } else if (o->IsA()==AliCFContainer::Class()){ | |
164 | fCfContainer=static_cast<AliCFContainer*>(o); | |
165 | if (fEffGrid) delete fEffGrid; | |
166 | fEffGrid=new AliCFEffGrid("eff","eff",*fCfContainer); | |
167 | } | |
a655b716 | 168 | } |
6551594b | 169 | } |
170 | ||
171 | //________________________________________________________________ | |
172 | void AliDielectronCFdraw::SetRangeUser(Int_t ivar, Double_t min, Double_t max, const char* slices) | |
173 | { | |
174 | // | |
175 | // Set range of cut steps defined in slices | |
176 | // Steps may be separated by one the the characteres ,;: | |
177 | // | |
ba15fdfb | 178 | if (ivar==-1) return; |
6551594b | 179 | TObjArray *arr=TString(slices).Tokenize(",:;"); |
180 | ||
181 | if (arr->GetEntriesFast()==0){ | |
182 | // all slices in case of 0 entries | |
183 | for (Int_t istep=0; istep<fCfContainer->GetNStep(); ++istep){ | |
ffbede40 | 184 | fCfContainer->GetGrid(istep)->SetRangeUser(ivar,min,max); |
ba15fdfb | 185 | fCfContainer->GetAxis(ivar,istep)->SetBit(TAxis::kAxisRange,1); |
6551594b | 186 | } |
187 | } else { | |
188 | TIter next(arr); | |
189 | TObjString *ostr=0x0; | |
190 | while ( (ostr=static_cast<TObjString*>(next())) ) { | |
191 | Int_t istep=ostr->GetString().Atoi(); | |
ffbede40 | 192 | fCfContainer->GetGrid(istep)->SetRangeUser(ivar,min,max); |
ba15fdfb | 193 | fCfContainer->GetAxis(ivar,istep)->SetBit(TAxis::kAxisRange,1); |
6551594b | 194 | } |
195 | } | |
196 | delete arr; | |
197 | } | |
198 | ||
199 | //________________________________________________________________ | |
200 | void AliDielectronCFdraw::UnsetRangeUser(Int_t ivar, const char* slices) | |
201 | { | |
202 | // | |
203 | // Unset range of cut steps defined in slices | |
204 | // Steps may be separated by one the the characteres ,;: | |
205 | // | |
ba15fdfb | 206 | if (ivar==-1) return; |
6551594b | 207 | TObjArray *arr=TString(slices).Tokenize(",:;"); |
208 | ||
209 | if (arr->GetEntriesFast()==0){ | |
210 | // all slices in case of 0 entries | |
211 | for (Int_t istep=0; istep<fCfContainer->GetNStep(); ++istep){ | |
572b0139 | 212 | fCfContainer->GetAxis(ivar,istep)->SetRange(0,0); |
5cc8c825 | 213 | fCfContainer->GetAxis(ivar,istep)->SetBit(TAxis::kAxisRange,0); |
6551594b | 214 | } |
215 | } else { | |
216 | TIter next(arr); | |
217 | TObjString *ostr=0x0; | |
218 | while ( (ostr=static_cast<TObjString*>(next())) ) { | |
219 | Int_t istep=ostr->GetString().Atoi(); | |
572b0139 | 220 | fCfContainer->GetAxis(ivar,istep)->SetRange(0,0); |
5cc8c825 | 221 | fCfContainer->GetAxis(ivar,istep)->SetBit(TAxis::kAxisRange,0); |
6551594b | 222 | } |
223 | } | |
224 | delete arr; | |
225 | } | |
226 | ||
227 | //________________________________________________________________ | |
572b0139 | 228 | void AliDielectronCFdraw::Draw(const Option_t* varnames, const char* opt, const char* slices) |
6551594b | 229 | { |
230 | // | |
231 | // Draw 'variables' of 'slices' | |
232 | // for multidimensional draw variables may be separated by a ':' | |
233 | // slice numbers may be separated by any of ,:; | |
234 | // | |
235 | // variables may be called by either their name or number | |
236 | // | |
237 | ||
238 | TObjArray *arrVars=TString(varnames).Tokenize(":"); | |
239 | Int_t entries=arrVars->GetEntriesFast(); | |
240 | if (entries<1||entries>3){ | |
241 | AliError("Wrong number of variables, supported are 1 - 3 dimensions"); | |
242 | delete arrVars; | |
243 | return; | |
244 | } | |
245 | ||
246 | TIter next(arrVars); | |
247 | TObjString *ostr=0x0; | |
248 | Int_t ivar[3]={-1,-1,-1}; | |
ffbede40 | 249 | for (Int_t i=entries-1; i>=0; --i){ |
6551594b | 250 | ostr=static_cast<TObjString*>(next()); |
251 | if (ostr->GetString().IsDigit()){ | |
252 | ivar[i]=ostr->GetString().Atoi(); | |
253 | } else { | |
254 | ivar[i]=fCfContainer->GetVar(ostr->GetName()); | |
255 | } | |
256 | } | |
257 | ||
ffbede40 | 258 | Draw(ivar[0],ivar[1],ivar[2],opt,slices); |
6551594b | 259 | delete arrVars; |
260 | } | |
261 | ||
ba15fdfb | 262 | //________________________________________________________________ |
263 | TObjArray* AliDielectronCFdraw::CollectHistosProj(const Option_t* varnames, const char* slices) | |
264 | { | |
265 | // | |
266 | // Collect histos with 'variables' of 'slices' | |
267 | // for multidimensional histograms, variables may be separated by a ':' | |
268 | // slice numbers may be separated by any of ,:; | |
269 | // | |
270 | // variables may be called by either their name or number | |
271 | // | |
272 | ||
273 | TObjArray *arrVars=TString(varnames).Tokenize(":"); | |
274 | Int_t entries=arrVars->GetEntriesFast(); | |
275 | if (entries<1||entries>3){ | |
276 | AliError("Wrong number of variables, supported are 1 - 3 dimensions"); | |
277 | delete arrVars; | |
278 | return 0x0; | |
279 | } | |
280 | ||
281 | TIter next(arrVars); | |
282 | TObjString *ostr=0x0; | |
283 | Int_t ivar[3]={-1,-1,-1}; | |
284 | for (Int_t i=entries-1; i>=0; --i){ | |
285 | ostr=static_cast<TObjString*>(next()); | |
286 | if (ostr->GetString().IsDigit()){ | |
287 | ivar[i]=ostr->GetString().Atoi(); | |
288 | } else { | |
289 | ivar[i]=fCfContainer->GetVar(ostr->GetName()); | |
290 | } | |
291 | } | |
292 | delete arrVars; | |
293 | ||
294 | return CollectHistosProj(ivar,slices); | |
295 | } | |
296 | ||
6551594b | 297 | //________________________________________________________________ |
298 | void AliDielectronCFdraw::Draw(Int_t var, const char* opt, const char* slices) | |
299 | { | |
300 | // | |
301 | // Draw variable var for all slices | |
302 | // slices may be divided by and of ,;: | |
303 | // | |
304 | // if opt contains 'same' all histograms are drawn in the same pad | |
305 | // otherwise the pad will be divided in sub pads and the histograms | |
306 | // are drawn in each sub pad | |
307 | // | |
308 | ||
ffbede40 | 309 | Int_t vars[3]={var,-1,-1}; |
310 | TObjArray *arr=CollectHistosProj(vars,slices); | |
6551594b | 311 | Draw(arr,opt); |
312 | delete arr; | |
313 | } | |
314 | ||
315 | //________________________________________________________________ | |
316 | void AliDielectronCFdraw::Draw(Int_t var0, Int_t var1, const char* opt, const char* slices) | |
317 | { | |
318 | // | |
319 | // Draw 2D case | |
320 | // | |
ffbede40 | 321 | Int_t vars[3]={var0,var1,-1}; |
322 | TObjArray *arr=CollectHistosProj(vars,slices); | |
6551594b | 323 | Draw(arr,opt); |
324 | delete arr; | |
325 | } | |
326 | ||
327 | //________________________________________________________________ | |
328 | void AliDielectronCFdraw::Draw(Int_t var0, Int_t var1, Int_t var2, const char* opt, const char* slices) | |
329 | { | |
330 | // | |
331 | // Draw 3D case | |
332 | // | |
ffbede40 | 333 | Int_t vars[3]={var0,var1,var2}; |
334 | TObjArray *arr=CollectHistosProj(vars,slices); | |
6551594b | 335 | Draw(arr,opt); |
336 | delete arr; | |
337 | } | |
338 | ||
339 | //________________________________________________________________ | |
ffbede40 | 340 | TObjArray* AliDielectronCFdraw::CollectHistosProj(const Int_t vars[3], const char* slices) |
6551594b | 341 | { |
342 | // | |
ffbede40 | 343 | // Collect histos with up to 3 dimension of the 'slices' separated by one of "':;'" |
a655b716 | 344 | // in a TObjArray and return it |
ffbede40 | 345 | // if a dimension is not used it must be set to -1 |
6551594b | 346 | // |
a655b716 | 347 | TObjArray *arr=TString(slices).Tokenize(",:;"); |
348 | TObjArray *arrHists=0x0; | |
349 | if (arr->GetEntriesFast()==0){ | |
350 | // all slices in case of 0 entries | |
351 | arrHists=new TObjArray(fCfContainer->GetNStep()); | |
352 | for (Int_t istep=0; istep<fCfContainer->GetNStep(); ++istep){ | |
ffbede40 | 353 | TH1 *hproj=Project(vars,istep); |
572b0139 | 354 | if (!hproj) continue; |
66b2c564 | 355 | hproj->SetName(Form("proj_%02d",istep)); |
356 | hproj->SetTitle(fCfContainer->GetStepTitle(istep)); | |
a655b716 | 357 | arrHists->Add(hproj); |
358 | } | |
359 | } else { | |
360 | arrHists=new TObjArray(arr->GetEntriesFast()); | |
361 | TIter next(arr); | |
362 | TObjString *ostr=0x0; | |
363 | while ( (ostr=static_cast<TObjString*>(next())) ) { | |
364 | Int_t istep=ostr->GetString().Atoi(); | |
ffbede40 | 365 | TH1 *hproj=Project(vars,istep); |
572b0139 | 366 | if (!hproj) continue; |
66b2c564 | 367 | hproj->SetName(Form("proj_%02d",istep)); |
368 | hproj->SetTitle(fCfContainer->GetStepTitle(istep)); | |
a655b716 | 369 | arrHists->Add(hproj); |
370 | } | |
371 | } | |
372 | delete arr; | |
373 | ||
374 | return arrHists; | |
375 | } | |
376 | ||
377 | //________________________________________________________________ | |
ffbede40 | 378 | TH1* AliDielectronCFdraw::Project(const Int_t *vars, Int_t slice) |
a655b716 | 379 | { |
380 | // | |
2a14a7b1 | 381 | // Do an ndim projection |
a655b716 | 382 | // |
ffbede40 | 383 | return fCfContainer->Project(slice,vars[0],vars[1],vars[2]); |
a655b716 | 384 | } |
385 | ||
2a14a7b1 | 386 | //________________________________________________________________ |
387 | TH1* AliDielectronCFdraw::Project(const Option_t* var, Int_t slice) | |
388 | { | |
389 | // | |
390 | // translate variable names and do projection | |
391 | // | |
392 | TObjArray *arrVars=TString(var).Tokenize(":"); | |
393 | Int_t entries=arrVars->GetEntriesFast(); | |
394 | if (entries<1||entries>3){ | |
395 | AliError("Wrong number of variables, supported are 1 - 3 dimensions"); | |
396 | delete arrVars; | |
397 | return 0x0; | |
398 | } | |
5720c765 | 399 | |
400 | TIter next(arrVars); | |
2a14a7b1 | 401 | TObjString *ostr=0x0; |
402 | Int_t ivar[3]={-1,-1,-1}; | |
ffbede40 | 403 | for (Int_t i=entries-1; i>=0; --i){ |
5720c765 | 404 | ostr=static_cast<TObjString*>(next()); |
2a14a7b1 | 405 | if (ostr->GetString().IsDigit()){ |
406 | ivar[i]=ostr->GetString().Atoi(); | |
407 | } else { | |
408 | ivar[i]=fCfContainer->GetVar(ostr->GetName()); | |
409 | } | |
410 | } | |
ffbede40 | 411 | if (ivar[0]==-1) return 0x0; |
2a14a7b1 | 412 | delete arrVars; |
ffbede40 | 413 | return fCfContainer->Project(slice,ivar[0],ivar[1],ivar[2]); |
2a14a7b1 | 414 | } |
415 | ||
a655b716 | 416 | //________________________________________________________________ |
554e40f8 | 417 | void AliDielectronCFdraw::DrawEfficiency(const char* varnames, const char* numerators, Int_t denominator, const char* opt) |
a655b716 | 418 | { |
419 | // | |
420 | // plot efficiencies for variables. Variable may be up to 3 dim, separated by a ':' | |
554e40f8 | 421 | // you may have several numerators, sparated by one of ',:;' |
a655b716 | 422 | // |
423 | ||
424 | TObjArray *arrVars=TString(varnames).Tokenize(":"); | |
425 | Int_t entries=arrVars->GetEntriesFast(); | |
426 | if (entries<1||entries>3){ | |
427 | AliError("Wrong number of variables, supported are 1 - 3 dimensions"); | |
428 | delete arrVars; | |
429 | return; | |
430 | } | |
431 | ||
432 | TIter next(arrVars); | |
433 | TObjString *ostr=0x0; | |
434 | Int_t ivar[3]={-1,-1,-1}; | |
5720c765 | 435 | for (Int_t i=entries-1; i>=0; --i){ |
a655b716 | 436 | ostr=static_cast<TObjString*>(next()); |
437 | if (ostr->GetString().IsDigit()){ | |
438 | ivar[i]=ostr->GetString().Atoi(); | |
439 | } else { | |
440 | ivar[i]=fCfContainer->GetVar(ostr->GetName()); | |
6551594b | 441 | } |
442 | } | |
66b2c564 | 443 | |
444 | Int_t type=0; | |
445 | TString optStr(opt); | |
446 | if (optStr.Contains("2")) type=1; | |
a655b716 | 447 | |
5720c765 | 448 | DrawEfficiency(ivar[0],ivar[1],ivar[2],numerators, denominator,opt,type); |
a655b716 | 449 | delete arrVars; |
450 | } | |
451 | ||
452 | //________________________________________________________________ | |
554e40f8 | 453 | void AliDielectronCFdraw::DrawEfficiency(Int_t var, const char* numerators, Int_t denominator, const char* opt, Int_t type) |
a655b716 | 454 | { |
455 | // | |
554e40f8 | 456 | // Draw Efficiencies for all numerators |
457 | // numerators may be divided by and of ,;: | |
a655b716 | 458 | // |
459 | // if opt contains 'same' all histograms are drawn in the same pad | |
460 | // otherwise the pad will be divided in sub pads and the histograms | |
461 | // are drawn in each sub pad | |
462 | // | |
463 | ||
ffbede40 | 464 | Int_t vars[3]={var,-1,-1}; |
465 | TObjArray *arr=CollectHistosEff(vars,numerators,denominator,type); | |
572b0139 | 466 | TString drawOpt=opt; |
467 | drawOpt+="eff"; | |
468 | Draw(arr,drawOpt); | |
a655b716 | 469 | delete arr; |
470 | } | |
471 | ||
472 | //________________________________________________________________ | |
554e40f8 | 473 | void AliDielectronCFdraw::DrawEfficiency(Int_t var0, Int_t var1, const char* numerators, Int_t denominator, const char* opt, Int_t type) |
a655b716 | 474 | { |
475 | // | |
476 | // Draw 2D case | |
477 | // | |
ffbede40 | 478 | Int_t vars[3]={var0,var1,-1}; |
479 | TObjArray *arr=CollectHistosEff(vars,numerators,denominator,type); | |
572b0139 | 480 | TString drawOpt=opt; |
481 | drawOpt+="eff"; | |
482 | Draw(arr,drawOpt); | |
a655b716 | 483 | delete arr; |
484 | } | |
485 | ||
486 | //________________________________________________________________ | |
554e40f8 | 487 | void AliDielectronCFdraw::DrawEfficiency(Int_t var0, Int_t var1, Int_t var2, const char* numerators, Int_t denominator, const char* opt, Int_t type) |
a655b716 | 488 | { |
489 | // | |
490 | // Draw 3D case | |
491 | // | |
ffbede40 | 492 | Int_t vars[3]={var0,var1,var2}; |
493 | TObjArray *arr=CollectHistosEff(vars,numerators,denominator,type); | |
572b0139 | 494 | TString drawOpt=opt; |
495 | drawOpt+="eff"; | |
496 | Draw(arr,drawOpt); | |
a655b716 | 497 | delete arr; |
6551594b | 498 | } |
499 | ||
500 | //________________________________________________________________ | |
ffbede40 | 501 | TObjArray* AliDielectronCFdraw::CollectHistosEff(const Int_t vars[3], const char* numerators, Int_t denominator, Int_t type) |
6551594b | 502 | { |
503 | // | |
504 | // Collect histos with 'dim'ension of the 'slices' separated by one of "':;'" | |
505 | // in a TObjArray and return it | |
506 | // | |
554e40f8 | 507 | TObjArray *arr=TString(numerators).Tokenize(",:;"); |
6551594b | 508 | TObjArray *arrHists=0x0; |
66b2c564 | 509 | |
510 | if (type==0){ | |
511 | if (arr->GetEntriesFast()==0){ | |
6551594b | 512 | // all slices in case of 0 entries |
66b2c564 | 513 | arrHists=new TObjArray(fCfContainer->GetNStep()); |
572b0139 | 514 | fVdata.ResizeTo(arrHists->GetSize()); |
66b2c564 | 515 | for (Int_t istep=0; istep<fCfContainer->GetNStep(); ++istep){ |
516 | fEffGrid->CalculateEfficiency(istep,denominator); | |
ffbede40 | 517 | TH1 *hproj=ProjectEff(vars); |
572b0139 | 518 | if (!hproj) continue; |
66b2c564 | 519 | Float_t eff=fEffGrid->GetAverage(); |
572b0139 | 520 | fVdata(istep)=eff; |
66b2c564 | 521 | hproj->SetName(Form("eff_%02d/%02d",istep,denominator)); |
572b0139 | 522 | hproj->SetTitle(Form("%s (%.3f)",fCfContainer->GetStepTitle(istep),eff)); |
66b2c564 | 523 | arrHists->Add(hproj); |
524 | } | |
525 | } else { | |
526 | arrHists=new TObjArray(arr->GetEntriesFast()); | |
527 | TIter next(arr); | |
528 | TObjString *ostr=0x0; | |
572b0139 | 529 | fVdata.ResizeTo(arrHists->GetSize()); |
530 | Int_t count=0; | |
66b2c564 | 531 | while ( (ostr=static_cast<TObjString*>(next())) ) { |
532 | Int_t istep=ostr->GetString().Atoi(); | |
533 | fEffGrid->CalculateEfficiency(istep,denominator); | |
ffbede40 | 534 | TH1 *hproj=ProjectEff(vars); |
572b0139 | 535 | if (!hproj) continue; |
66b2c564 | 536 | Float_t eff=fEffGrid->GetAverage(); |
572b0139 | 537 | fVdata(count++)=eff; |
66b2c564 | 538 | hproj->SetName(Form("eff_%02d/%02d",istep,denominator)); |
572b0139 | 539 | hproj->SetTitle(Form("%s (%.3f)",fCfContainer->GetStepTitle(istep),eff)); |
66b2c564 | 540 | arrHists->Add(hproj); |
541 | } | |
6551594b | 542 | } |
66b2c564 | 543 | } |
544 | ||
545 | //second approach | |
546 | if (type==1){ | |
ffbede40 | 547 | TH1 *hDen=Project(vars,denominator); |
66b2c564 | 548 | Double_t entriesDen=hDen->GetEffectiveEntries(); |
549 | if (arr->GetEntriesFast()==0){ | |
550 | // all slices in case of 0 entries | |
551 | arrHists=new TObjArray(fCfContainer->GetNStep()); | |
572b0139 | 552 | fVdata.ResizeTo(arrHists->GetSize()); |
66b2c564 | 553 | for (Int_t istep=0; istep<fCfContainer->GetNStep(); ++istep){ |
ffbede40 | 554 | TH1 *hproj=Project(vars,istep); |
572b0139 | 555 | if (!hproj) continue; |
66b2c564 | 556 | Float_t eff=0; |
557 | if (entriesDen>0) eff=hproj->GetEffectiveEntries()/entriesDen; | |
572b0139 | 558 | fVdata(istep)=eff; |
48609e3d | 559 | hproj->Divide(hproj,hDen,1,1,"B"); |
66b2c564 | 560 | hproj->SetName(Form("eff_%02d/%02d",istep,denominator)); |
572b0139 | 561 | hproj->SetTitle(Form("%s (%.3f)",fCfContainer->GetStepTitle(istep),eff)); |
66b2c564 | 562 | arrHists->Add(hproj); |
563 | } | |
564 | } else { | |
565 | arrHists=new TObjArray(arr->GetEntriesFast()); | |
572b0139 | 566 | fVdata.ResizeTo(arrHists->GetSize()); |
66b2c564 | 567 | TIter next(arr); |
568 | TObjString *ostr=0x0; | |
572b0139 | 569 | Int_t count=0; |
66b2c564 | 570 | while ( (ostr=static_cast<TObjString*>(next())) ) { |
571 | Int_t istep=ostr->GetString().Atoi(); | |
ffbede40 | 572 | TH1 *hproj=Project(vars,istep); |
572b0139 | 573 | if (!hproj) continue; |
66b2c564 | 574 | Float_t eff=0; |
575 | if (entriesDen>0) eff=hproj->GetEffectiveEntries()/entriesDen; | |
572b0139 | 576 | fVdata(count++)=eff; |
48609e3d | 577 | hproj->Divide(hproj,hDen,1,1,"B"); |
66b2c564 | 578 | hproj->SetName(Form("eff_%02d/%02d",istep,denominator)); |
572b0139 | 579 | hproj->SetTitle(Form("%s (%.3f)",fCfContainer->GetStepTitle(istep),eff)); |
66b2c564 | 580 | arrHists->Add(hproj); |
581 | } | |
6551594b | 582 | } |
66b2c564 | 583 | delete hDen; |
6551594b | 584 | } |
a655b716 | 585 | |
66b2c564 | 586 | |
587 | delete arr; | |
6551594b | 588 | return arrHists; |
589 | } | |
590 | ||
591 | //________________________________________________________________ | |
ffbede40 | 592 | TH1* AliDielectronCFdraw::ProjectEff(const Int_t vars[3]) |
6551594b | 593 | { |
594 | // | |
595 | // Do an nim projection | |
596 | // | |
ffbede40 | 597 | return fEffGrid->Project(vars[0],vars[1],vars[2]); |
6551594b | 598 | } |
599 | ||
a655b716 | 600 | //________________________________________________________________ |
601 | void AliDielectronCFdraw::Draw(const TObjArray *arr, const char* opt) | |
602 | { | |
603 | // | |
604 | // draw all objects in arr | |
605 | // | |
606 | TString optStr(opt); | |
607 | optStr.ToLower(); | |
572b0139 | 608 | Bool_t drawSame = optStr.Contains("same"); |
609 | Bool_t drawSamePlus = optStr.Contains("same+"); | |
610 | Bool_t drawEff = optStr.Contains("eff"); | |
611 | Bool_t optLeg = optStr.Contains("leg"); | |
612 | Bool_t optScaleMax = optStr.Contains("max"); | |
613 | ||
614 | if (!drawSamePlus) optStr.ReplaceAll("same",""); | |
615 | ||
616 | optStr.ReplaceAll("+",""); | |
617 | optStr.ReplaceAll("eff",""); | |
618 | optStr.ReplaceAll("leg",""); | |
619 | optStr.ReplaceAll("max",""); | |
a655b716 | 620 | |
621 | if (!gPad) new TCanvas; | |
622 | ||
623 | Int_t nPads = arr->GetEntriesFast(); | |
624 | if (nPads==0) return; | |
625 | ||
572b0139 | 626 | // if (nPads==1){ |
627 | // arr->UncheckedAt(0)->Draw(optStr.Data()); | |
628 | // return; | |
629 | // } | |
a655b716 | 630 | |
631 | TCanvas *c=gPad->GetCanvas(); | |
8df8e382 | 632 | if (!gVirtualPS&&!drawSamePlus&&!drawSame&&nPads>1) c->Clear(); |
a655b716 | 633 | |
8df8e382 | 634 | if (!drawSame&&nPads>1){ |
a655b716 | 635 | //optimised division |
636 | Int_t nCols = (Int_t)TMath::Ceil( TMath::Sqrt(nPads) ); | |
637 | Int_t nRows = (Int_t)TMath::Ceil( (Double_t)nPads/(Double_t)nCols ); | |
638 | c->Divide(nCols,nRows); | |
639 | for (Int_t i=0; i<nPads; ++i){ | |
640 | c->cd(i+1); | |
641 | arr->UncheckedAt(i)->Draw(optStr.Data()); | |
642 | } | |
643 | } else { | |
644 | TLegend *leg=0; | |
572b0139 | 645 | if (drawSamePlus){ |
646 | //find already existing legend to attach entries to it | |
647 | TIter nextPrimitive(gPad->GetListOfPrimitives()); | |
648 | TObject *o=0x0; | |
649 | while ((o=nextPrimitive())) if (o->IsA()==TLegend::Class()) leg=(TLegend*)o; | |
650 | } | |
651 | ||
652 | if (optLeg&&!leg) leg=new TLegend(.2,.3,.99,.9); | |
653 | Int_t addColor=0; | |
654 | if (leg) addColor=leg->GetNRows(); | |
66b2c564 | 655 | Int_t offset=20; |
656 | if (nPads<7) offset=24; | |
a655b716 | 657 | for (Int_t i=0; i<nPads; ++i){ |
572b0139 | 658 | if (i==1&&!drawSamePlus) optStr+="same"; |
a655b716 | 659 | TH1 *hist=static_cast<TH1*>(arr->UncheckedAt(i)); |
572b0139 | 660 | hist->SetLineColor(i+1+addColor); |
66b2c564 | 661 | hist->SetLineWidth(2); |
572b0139 | 662 | hist->SetMarkerColor(i+1+addColor); |
663 | hist->SetMarkerStyle(offset+i+addColor); | |
a655b716 | 664 | hist->Draw(optStr.Data()); |
572b0139 | 665 | |
666 | if (drawEff&&i==0&&!drawSamePlus) { | |
667 | hist->GetYaxis()->SetRangeUser(0,2); | |
668 | hist->SetYTitle("Rec. Signal / Gen. Signal"); | |
669 | } | |
670 | ||
66b2c564 | 671 | if (leg) leg->AddEntry(hist,hist->GetTitle(),"lp"); |
a655b716 | 672 | } |
673 | if (leg){ | |
674 | leg->SetFillColor(10); | |
572b0139 | 675 | leg->SetY1(.9-leg->GetNRows()*.05); |
676 | leg->SetY1NDC(.9-leg->GetNRows()*.05); | |
66b2c564 | 677 | leg->SetMargin(.1); |
572b0139 | 678 | if (!drawSamePlus) leg->Draw(); |
679 | } | |
680 | if (optScaleMax){ | |
681 | TIter nextPrimitive(gPad->GetListOfPrimitives()); | |
682 | TObject *o=0x0; | |
683 | TH1 *hfirst=0x0; | |
684 | Float_t max=0; | |
685 | while ((o=nextPrimitive())) if (o->InheritsFrom(TH1::Class())){ | |
686 | TH1 *h=(TH1*)o; | |
687 | if (!hfirst) hfirst=h; | |
688 | if (h->GetMaximum()>max) max=h->GetMaximum(); | |
689 | } | |
690 | max*=1.1; | |
691 | hfirst->SetMaximum(max); | |
a655b716 | 692 | } |
693 | } | |
694 | ||
695 | } | |
554e40f8 | 696 | |
697 | //________________________________________________________________ | |
698 | Double_t AliDielectronCFdraw::GetAverageEfficiency(Int_t numerator, Int_t denominator, Double_t &effErr) | |
699 | { | |
700 | // | |
701 | // Extract the mean efficiency of the numerator and denominator | |
702 | // | |
703 | ||
704 | //use variable 0 as default, since for the average it doesn't matter | |
ffbede40 | 705 | TH1 *hDen=fCfContainer->Project(denominator,0); |
554e40f8 | 706 | Double_t entriesDen=hDen->GetEffectiveEntries(); |
ffbede40 | 707 | TH1 *hproj=fCfContainer->Project(numerator,0); |
554e40f8 | 708 | if (!hproj) return -1.; |
709 | Double_t entriesNum=hproj->GetEffectiveEntries(); | |
710 | if (entriesDen<1||entriesNum<1) return -1; | |
711 | ||
712 | Double_t eff=-1.; | |
713 | if (entriesDen>0) eff=entriesNum/entriesDen; | |
714 | effErr=TMath::Sqrt(1./entriesNum+1./entriesDen)*eff; | |
715 | delete hDen; | |
716 | delete hproj; | |
717 | return eff; | |
718 | } |