]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG3/dielectron/AliDielectronCFdraw.cxx
Recover correctly the collision geometry.
[u/mrichter/AliRoot.git] / PWG3 / dielectron / AliDielectronCFdraw.cxx
CommitLineData
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>
39#include <TFile.h>
40#include <TString.h>
41#include <TObjString.h>
42#include <TMath.h>
43#include <TH1.h>
44#include <TH2.h>
45#include <TH3.h>
46#include <TPad.h>
47#include <TCanvas.h>
a655b716 48#include <TLegend.h>
49#include <AliCFEffGrid.h>
6551594b 50
51#include <AliLog.h>
52
53#include "AliDielectronCFdraw.h"
54
55ClassImp(AliDielectronCFdraw)
56
57AliDielectronCFdraw::AliDielectronCFdraw() :
58 TNamed(),
a655b716 59 fCfContainer(0x0),
60 fEffGrid(0x0)
6551594b 61{
62 //
63 // Ctor
64 //
65}
66
67//________________________________________________________________
68AliDielectronCFdraw::AliDielectronCFdraw(const char*name, const char* title) :
69 TNamed(name,title),
a655b716 70 fCfContainer(0x0),
71 fEffGrid(0x0)
6551594b 72{
73 //
74 // Named Ctor
75 //
76
77}
78
a655b716 79//________________________________________________________________
80AliDielectronCFdraw::AliDielectronCFdraw(AliCFContainer *cont) :
81 TNamed(cont->GetName(), cont->GetTitle()),
82 fCfContainer(cont),
83 fEffGrid(new AliCFEffGrid("eff","eff",*cont))
84{
85 //
86 // directly set the CF container
87 //
88
89}
90
91//________________________________________________________________
92AliDielectronCFdraw::AliDielectronCFdraw(const char* filename) :
93 TNamed(),
94 fCfContainer(0x0),
95 fEffGrid(0x0)
96{
97 //
98 // get CF container(s) from file 'filename'
99 //
100 SetCFContainers(filename);
101}
102
6551594b 103//________________________________________________________________
104void AliDielectronCFdraw::SetCFContainers(const TSeqCollection *arr)
105{
106 //
107 // Merge CF Container out of several containers
108 //
109
110 TIter next(arr);
111 TObject *o=0x0;
112
113 Int_t nstep=0;
114 while ( (o=next()) ){
115 AliCFContainer *cf=dynamic_cast<AliCFContainer*>(o);
116 if (!o) continue;
117 nstep+=cf->GetNStep();
118 }
119 Int_t nbins[1]={1};
120 fCfContainer=new AliCFContainer(GetName(), GetTitle(), nstep, 1, nbins);
121
122 //delete unneeded steps
123 for (Int_t istep=0; istep<nstep; ++istep) delete fCfContainer->GetGrid(istep);
124
125 //add step to the new container
126 Int_t istep=0;
127 for (Int_t icf=0; icf<arr->GetEntries(); ++icf){
128 AliCFContainer *cf=dynamic_cast<AliCFContainer*>(arr->At(icf));
129 if (!cf) continue;
130 for (Int_t istepCurr=0; istepCurr<cf->GetNStep(); ++istepCurr){
131 fCfContainer->SetGrid(istep, cf->GetGrid(istepCurr));
132 fCfContainer->SetStepTitle(istep,Form("%s: %s",cf->GetName(),cf->GetStepTitle(istepCurr)));
133 ++istep;
134 }
135 }
a655b716 136 if (fEffGrid) delete fEffGrid;
137 fEffGrid=new AliCFEffGrid("eff","eff",*fCfContainer);
6551594b 138}
139
140//________________________________________________________________
141void AliDielectronCFdraw::SetCFContainers(const char* filename)
142{
143 //
144 // get CF containers from file
145 //
146
147 TFile f(filename);
148 TList *l=f.GetListOfKeys();
149 Int_t entries=l->GetEntries();
150 if (entries==0) return;
151
152 TKey *k=(TKey*)l->At(0);
a655b716 153 if (!k) return;
154 TObject *o=k->ReadObj();
155 if (o->IsA()->InheritsFrom(TSeqCollection::Class())){
156 TSeqCollection *arr=static_cast<TSeqCollection*>(o);
157 SetCFContainers(arr);
158 } else if (o->IsA()==AliCFContainer::Class()){
159 fCfContainer=static_cast<AliCFContainer*>(o);
160 if (fEffGrid) delete fEffGrid;
161 fEffGrid=new AliCFEffGrid("eff","eff",*fCfContainer);
162 }
6551594b 163}
164
165//________________________________________________________________
166void AliDielectronCFdraw::SetRangeUser(Int_t ivar, Double_t min, Double_t max, const char* slices)
167{
168 //
169 // Set range of cut steps defined in slices
170 // Steps may be separated by one the the characteres ,;:
171 //
172 TObjArray *arr=TString(slices).Tokenize(",:;");
173
174 if (arr->GetEntriesFast()==0){
175 // all slices in case of 0 entries
176 for (Int_t istep=0; istep<fCfContainer->GetNStep(); ++istep){
177 fCfContainer->SetRangeUser(ivar,min,max,istep);
178 }
179 } else {
180 TIter next(arr);
181 TObjString *ostr=0x0;
182 while ( (ostr=static_cast<TObjString*>(next())) ) {
183 Int_t istep=ostr->GetString().Atoi();
184 fCfContainer->SetRangeUser(ivar,min,max,istep);
185 }
186 }
187 delete arr;
188}
189
190//________________________________________________________________
191void AliDielectronCFdraw::UnsetRangeUser(Int_t ivar, const char* slices)
192{
193 //
194 // Unset range of cut steps defined in slices
195 // Steps may be separated by one the the characteres ,;:
196 //
197 TObjArray *arr=TString(slices).Tokenize(",:;");
198
199 if (arr->GetEntriesFast()==0){
200 // all slices in case of 0 entries
201 for (Int_t istep=0; istep<fCfContainer->GetNStep(); ++istep){
202 fCfContainer->SetRangeUser(ivar,fCfContainer->GetAxis(ivar,istep)->GetXmin(),
203 fCfContainer->GetAxis(ivar,istep)->GetXmax(),istep);
204 }
205 } else {
206 TIter next(arr);
207 TObjString *ostr=0x0;
208 while ( (ostr=static_cast<TObjString*>(next())) ) {
209 Int_t istep=ostr->GetString().Atoi();
210 fCfContainer->SetRangeUser(ivar,fCfContainer->GetAxis(ivar,istep)->GetXmin(),
211 fCfContainer->GetAxis(ivar,istep)->GetXmax(),istep);
212 }
213 }
214 delete arr;
215}
216
217//________________________________________________________________
218void AliDielectronCFdraw::Draw(const Option_t* varnames, const char* slices, const char* opt)
219{
220 //
221 // Draw 'variables' of 'slices'
222 // for multidimensional draw variables may be separated by a ':'
223 // slice numbers may be separated by any of ,:;
224 //
225 // variables may be called by either their name or number
226 //
227
228 TObjArray *arrVars=TString(varnames).Tokenize(":");
229 Int_t entries=arrVars->GetEntriesFast();
230 if (entries<1||entries>3){
231 AliError("Wrong number of variables, supported are 1 - 3 dimensions");
232 delete arrVars;
233 return;
234 }
235
236 TIter next(arrVars);
237 TObjString *ostr=0x0;
238 Int_t ivar[3]={-1,-1,-1};
239 for (Int_t i=0; i<entries; ++i){
240 ostr=static_cast<TObjString*>(next());
241 if (ostr->GetString().IsDigit()){
242 ivar[i]=ostr->GetString().Atoi();
243 } else {
244 ivar[i]=fCfContainer->GetVar(ostr->GetName());
245 }
246 }
247
248 switch (entries){
249 case 1:
250 Draw(ivar[0],slices,opt);
251 break;
252 case 2:
a655b716 253 Draw(ivar[1],ivar[0],slices,opt);
6551594b 254 break;
255 case 3:
a655b716 256 Draw(ivar[2],ivar[1],ivar[0],slices,opt);
6551594b 257 break;
258 }
259 delete arrVars;
260}
261
262//________________________________________________________________
263void AliDielectronCFdraw::Draw(Int_t var, const char* opt, const char* slices)
264{
265 //
266 // Draw variable var for all slices
267 // slices may be divided by and of ,;:
268 //
269 // if opt contains 'same' all histograms are drawn in the same pad
270 // otherwise the pad will be divided in sub pads and the histograms
271 // are drawn in each sub pad
272 //
273
274 const Int_t ndim=1;
275 Int_t vars[ndim]={var};
a655b716 276 TObjArray *arr=CollectHistosProj(ndim,vars,slices);
6551594b 277 Draw(arr,opt);
278 delete arr;
279}
280
281//________________________________________________________________
282void AliDielectronCFdraw::Draw(Int_t var0, Int_t var1, const char* opt, const char* slices)
283{
284 //
285 // Draw 2D case
286 //
287 const Int_t ndim=2;
288 Int_t vars[ndim]={var0,var1};
a655b716 289 TObjArray *arr=CollectHistosProj(ndim,vars,slices);
6551594b 290 Draw(arr,opt);
291 delete arr;
292}
293
294//________________________________________________________________
295void AliDielectronCFdraw::Draw(Int_t var0, Int_t var1, Int_t var2, const char* opt, const char* slices)
296{
297 //
298 // Draw 3D case
299 //
300 const Int_t ndim=3;
301 Int_t vars[ndim]={var0,var1,var2};
a655b716 302 TObjArray *arr=CollectHistosProj(ndim,vars,slices);
6551594b 303 Draw(arr,opt);
304 delete arr;
305}
306
307//________________________________________________________________
a655b716 308TObjArray* AliDielectronCFdraw::CollectHistosProj(Int_t dim, Int_t *vars, const char* slices)
6551594b 309{
310 //
a655b716 311 // Collect histos with 'dim'ension of the 'slices' separated by one of "':;'"
312 // in a TObjArray and return it
6551594b 313 //
a655b716 314 TObjArray *arr=TString(slices).Tokenize(",:;");
315 TObjArray *arrHists=0x0;
316 if (arr->GetEntriesFast()==0){
317 // all slices in case of 0 entries
318 arrHists=new TObjArray(fCfContainer->GetNStep());
319 for (Int_t istep=0; istep<fCfContainer->GetNStep(); ++istep){
320 TH1 *hproj=Project(dim,vars,istep);
321 hproj->SetName(fCfContainer->GetStepTitle(istep));
322 arrHists->Add(hproj);
323 }
324 } else {
325 arrHists=new TObjArray(arr->GetEntriesFast());
326 TIter next(arr);
327 TObjString *ostr=0x0;
328 while ( (ostr=static_cast<TObjString*>(next())) ) {
329 Int_t istep=ostr->GetString().Atoi();
330 TH1 *hproj=Project(dim,vars,istep);
331 hproj->SetName(fCfContainer->GetStepTitle(istep));
332 arrHists->Add(hproj);
333 }
334 }
335 delete arr;
336
337 return arrHists;
338}
339
340//________________________________________________________________
341TH1* AliDielectronCFdraw::Project(Int_t ndim, Int_t *vars, Int_t slice)
342{
343 //
344 // Do an nim projection
345 //
346 switch (ndim){
347 case 1:
348 return fCfContainer->Project(vars[0],slice);
349 break;
350 case 2:
351 return fCfContainer->Project(vars[0],vars[1],slice);
352 break;
353 case 3:
354 return fCfContainer->Project(vars[0],vars[1],vars[2],slice);
355 break;
356 }
357 return 0x0;
358}
359
360//________________________________________________________________
361void AliDielectronCFdraw::DrawEfficiency(const char* varnames, const char* nominators, Int_t denominator, const char* opt)
362{
363 //
364 // plot efficiencies for variables. Variable may be up to 3 dim, separated by a ':'
365 // you may have several nominators, sparated by one of ',:;'
366 //
367
368 TObjArray *arrVars=TString(varnames).Tokenize(":");
369 Int_t entries=arrVars->GetEntriesFast();
370 if (entries<1||entries>3){
371 AliError("Wrong number of variables, supported are 1 - 3 dimensions");
372 delete arrVars;
373 return;
374 }
375
376 TIter next(arrVars);
377 TObjString *ostr=0x0;
378 Int_t ivar[3]={-1,-1,-1};
379 for (Int_t i=0; i<entries; ++i){
380 ostr=static_cast<TObjString*>(next());
381 if (ostr->GetString().IsDigit()){
382 ivar[i]=ostr->GetString().Atoi();
383 } else {
384 ivar[i]=fCfContainer->GetVar(ostr->GetName());
6551594b 385 }
386 }
a655b716 387
388 switch (entries){
389 case 1:
390 DrawEfficiency(ivar[0],nominators, denominator,opt);
391 break;
392 case 2:
393 DrawEfficiency(ivar[1],ivar[0], nominators, denominator,opt);
394 break;
395 case 3:
396 DrawEfficiency(ivar[2],ivar[1],ivar[0],nominators, denominator,opt);
397 break;
398 }
399 delete arrVars;
400}
401
402//________________________________________________________________
403void AliDielectronCFdraw::DrawEfficiency(Int_t var, const char* nominators, Int_t denominator, const char* opt)
404{
405 //
406 // Draw Efficiencies for all nominators
407 // nominators may be divided by and of ,;:
408 //
409 // if opt contains 'same' all histograms are drawn in the same pad
410 // otherwise the pad will be divided in sub pads and the histograms
411 // are drawn in each sub pad
412 //
413
414 const Int_t ndim=1;
415 Int_t vars[ndim]={var};
416 TObjArray *arr=CollectHistosEff(ndim,vars,nominators,denominator);
417 Draw(arr,opt);
418 delete arr;
419}
420
421//________________________________________________________________
422void AliDielectronCFdraw::DrawEfficiency(Int_t var0, Int_t var1, const char* nominators, Int_t denominator, const char* opt)
423{
424 //
425 // Draw 2D case
426 //
427 const Int_t ndim=2;
428 Int_t vars[ndim]={var0,var1};
429 TObjArray *arr=CollectHistosEff(ndim,vars,nominators,denominator);
430 Draw(arr,opt);
431 delete arr;
432}
433
434//________________________________________________________________
435void AliDielectronCFdraw::DrawEfficiency(Int_t var0, Int_t var1, Int_t var2, const char* nominators, Int_t denominator, const char* opt)
436{
437 //
438 // Draw 3D case
439 //
440 const Int_t ndim=3;
441 Int_t vars[ndim]={var0,var1,var2};
442 TObjArray *arr=CollectHistosEff(ndim,vars,nominators,denominator);
443 Draw(arr,opt);
444 delete arr;
6551594b 445}
446
447//________________________________________________________________
a655b716 448TObjArray* AliDielectronCFdraw::CollectHistosEff(Int_t dim, Int_t *vars, const char* nominators, Int_t denominator)
6551594b 449{
450 //
451 // Collect histos with 'dim'ension of the 'slices' separated by one of "':;'"
452 // in a TObjArray and return it
453 //
a655b716 454 TObjArray *arr=TString(nominators).Tokenize(",:;");
6551594b 455 TObjArray *arrHists=0x0;
456 if (arr->GetEntriesFast()==0){
457 // all slices in case of 0 entries
458 arrHists=new TObjArray(fCfContainer->GetNStep());
459 for (Int_t istep=0; istep<fCfContainer->GetNStep(); ++istep){
a655b716 460 fEffGrid->CalculateEfficiency(istep,denominator);
461 TH1 *hproj=ProjectEff(dim,vars);
462 Float_t eff=fEffGrid->GetAverage();
463 hproj->SetName(Form("%s (%f)",fCfContainer->GetStepTitle(istep),eff));
464 arrHists->Add(hproj);
6551594b 465 }
466 } else {
467 arrHists=new TObjArray(arr->GetEntriesFast());
468 TIter next(arr);
469 TObjString *ostr=0x0;
470 while ( (ostr=static_cast<TObjString*>(next())) ) {
471 Int_t istep=ostr->GetString().Atoi();
a655b716 472 fEffGrid->CalculateEfficiency(istep,denominator);
473 TH1 *hproj=ProjectEff(dim,vars);
474 Float_t eff=fEffGrid->GetAverage();
475 hproj->SetName(Form("%s (%f)",fCfContainer->GetStepTitle(istep),eff));
476 arrHists->Add(hproj);
6551594b 477 }
478 }
479 delete arr;
a655b716 480
6551594b 481 return arrHists;
482}
483
484//________________________________________________________________
a655b716 485TH1* AliDielectronCFdraw::ProjectEff(Int_t ndim, Int_t *vars)
6551594b 486{
487 //
488 // Do an nim projection
489 //
490 switch (ndim){
491 case 1:
a655b716 492 return fEffGrid->Project(vars[0]);
6551594b 493 break;
494 case 2:
a655b716 495 return fEffGrid->Project(vars[0],vars[1]);
6551594b 496 break;
497 case 3:
a655b716 498 return fEffGrid->Project(vars[0],vars[1],vars[2]);
6551594b 499 break;
500 }
501 return 0x0;
502}
503
a655b716 504//________________________________________________________________
505void AliDielectronCFdraw::Draw(const TObjArray *arr, const char* opt)
506{
507 //
508 // draw all objects in arr
509 //
510 TString optStr(opt);
511 optStr.ToLower();
512 Bool_t drawSame=optStr.Contains("same");
513 Bool_t optLeg=optStr.Contains("leg");
514 optStr.ReplaceAll("same","");
515
516 if (!gPad) new TCanvas;
517
518 Int_t nPads = arr->GetEntriesFast();
519 if (nPads==0) return;
520
521 if (nPads==1){
522 arr->UncheckedAt(0)->Draw(optStr.Data());
523 return;
524 }
525
526 TCanvas *c=gPad->GetCanvas();
527 c->Clear();
528
529
530 if (!drawSame){
531 //optimised division
532 Int_t nCols = (Int_t)TMath::Ceil( TMath::Sqrt(nPads) );
533 Int_t nRows = (Int_t)TMath::Ceil( (Double_t)nPads/(Double_t)nCols );
534 c->Divide(nCols,nRows);
535 for (Int_t i=0; i<nPads; ++i){
536 c->cd(i+1);
537 arr->UncheckedAt(i)->Draw(optStr.Data());
538 }
539 } else {
540 TLegend *leg=0;
541 if (optLeg) leg=new TLegend(.8,.3,.99,.9);
542 for (Int_t i=0; i<nPads; ++i){
543 if (i==1) optStr+="same";
544 TH1 *hist=static_cast<TH1*>(arr->UncheckedAt(i));
545 hist->SetLineColor(i+1);
546 hist->SetMarkerColor(i+1);
547 hist->Draw(optStr.Data());
548 if (leg) leg->AddEntry(hist,hist->GetName(),"lp");
549 }
550 if (leg){
551 leg->SetFillColor(10);
552 leg->SetY1(.9-nPads*.05);
553 leg->Draw();
554 }
555 }
556
557}