1 /*************************************************************************
2 * Copyright(c) 1998-2009, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
16 ///////////////////////////////////////////////////////////////////////////
17 // Dielectron Correction framework draw helper //
31 ///////////////////////////////////////////////////////////////////////////
33 #include <TSeqCollection.h>
34 #include <TObjArray.h>
39 #include <TVirtualPS.h>
42 #include <TObjString.h>
51 #include <AliCFEffGrid.h>
55 #include "AliDielectronCFdraw.h"
57 ClassImp(AliDielectronCFdraw)
59 AliDielectronCFdraw::AliDielectronCFdraw() :
70 //________________________________________________________________
71 AliDielectronCFdraw::AliDielectronCFdraw(const char*name, const char* title) :
83 //________________________________________________________________
84 AliDielectronCFdraw::AliDielectronCFdraw(AliCFContainer *cont) :
85 TNamed(cont->GetName(), cont->GetTitle()),
87 fEffGrid(new AliCFEffGrid("eff","eff",*cont)),
91 // directly set the CF container
96 //________________________________________________________________
97 AliDielectronCFdraw::AliDielectronCFdraw(const char* filename) :
104 // get CF container(s) from file 'filename'
106 SetCFContainers(filename);
109 //________________________________________________________________
110 void AliDielectronCFdraw::SetCFContainers(const TSeqCollection *arr)
113 // Merge CF Container out of several containers
120 while ( (o=next()) ){
121 AliCFContainer *cf=dynamic_cast<AliCFContainer*>(o);
123 nstep+=cf->GetNStep();
126 fCfContainer=new AliCFContainer(GetName(), GetTitle(), nstep, 1, nbins);
128 //delete unneeded steps
129 // for (Int_t istep=0; istep<nstep; ++istep) delete fCfContainer->GetGrid(istep);
131 //add step to the new container
133 for (Int_t icf=0; icf<arr->GetEntries(); ++icf){
134 AliCFContainer *cf=dynamic_cast<AliCFContainer*>(arr->At(icf));
136 for (Int_t istepCurr=0; istepCurr<cf->GetNStep(); ++istepCurr){
137 fCfContainer->SetGrid(istep, cf->GetGrid(istepCurr));
138 fCfContainer->SetStepTitle(istep,Form("%s, Pair: %s",cf->GetTitle(),cf->GetStepTitle(istepCurr)));
142 if (fEffGrid) delete fEffGrid;
143 fEffGrid=new AliCFEffGrid("eff","eff",*fCfContainer);
146 //________________________________________________________________
147 void AliDielectronCFdraw::SetCFContainers(const char* filename)
150 // get CF containers from file
154 TList *l=f.GetListOfKeys();
155 Int_t entries=l->GetEntries();
156 if (entries==0) return;
158 TKey *k=(TKey*)l->At(0);
160 TObject *o=k->ReadObj();
161 if (o->IsA()->InheritsFrom(TSeqCollection::Class())){
162 TSeqCollection *arr=static_cast<TSeqCollection*>(o);
163 SetCFContainers(arr);
164 } else if (o->IsA()==AliCFContainer::Class()){
165 fCfContainer=static_cast<AliCFContainer*>(o);
166 if (fEffGrid) delete fEffGrid;
167 fEffGrid=new AliCFEffGrid("eff","eff",*fCfContainer);
171 //________________________________________________________________
172 void AliDielectronCFdraw::SetRangeUser(Int_t ivar, Double_t min, Double_t max, const char* slices)
175 // Set range of cut steps defined in slices
176 // Steps may be separated by one the the characteres ,;:
178 TObjArray *arr=TString(slices).Tokenize(",:;");
180 if (arr->GetEntriesFast()==0){
181 // all slices in case of 0 entries
182 for (Int_t istep=0; istep<fCfContainer->GetNStep(); ++istep){
183 fCfContainer->SetRangeUser(ivar,min,max,istep);
187 TObjString *ostr=0x0;
188 while ( (ostr=static_cast<TObjString*>(next())) ) {
189 Int_t istep=ostr->GetString().Atoi();
190 fCfContainer->SetRangeUser(ivar,min,max,istep);
196 //________________________________________________________________
197 void AliDielectronCFdraw::UnsetRangeUser(Int_t ivar, const char* slices)
200 // Unset range of cut steps defined in slices
201 // Steps may be separated by one the the characteres ,;:
203 TObjArray *arr=TString(slices).Tokenize(",:;");
205 if (arr->GetEntriesFast()==0){
206 // all slices in case of 0 entries
207 for (Int_t istep=0; istep<fCfContainer->GetNStep(); ++istep){
208 fCfContainer->GetAxis(ivar,istep)->SetRange(0,0);
212 TObjString *ostr=0x0;
213 while ( (ostr=static_cast<TObjString*>(next())) ) {
214 Int_t istep=ostr->GetString().Atoi();
215 fCfContainer->GetAxis(ivar,istep)->SetRange(0,0);
221 //________________________________________________________________
222 void AliDielectronCFdraw::Draw(const Option_t* varnames, const char* opt, const char* slices)
225 // Draw 'variables' of 'slices'
226 // for multidimensional draw variables may be separated by a ':'
227 // slice numbers may be separated by any of ,:;
229 // variables may be called by either their name or number
232 TObjArray *arrVars=TString(varnames).Tokenize(":");
233 Int_t entries=arrVars->GetEntriesFast();
234 if (entries<1||entries>3){
235 AliError("Wrong number of variables, supported are 1 - 3 dimensions");
241 TObjString *ostr=0x0;
242 Int_t ivar[3]={-1,-1,-1};
243 for (Int_t i=0; i<entries; ++i){
244 ostr=static_cast<TObjString*>(next());
245 if (ostr->GetString().IsDigit()){
246 ivar[i]=ostr->GetString().Atoi();
248 ivar[i]=fCfContainer->GetVar(ostr->GetName());
254 Draw(ivar[0],opt,slices);
257 Draw(ivar[1],ivar[0],opt,slices);
260 Draw(ivar[2],ivar[1],ivar[0],opt,slices);
266 //________________________________________________________________
267 void AliDielectronCFdraw::Draw(Int_t var, const char* opt, const char* slices)
270 // Draw variable var for all slices
271 // slices may be divided by and of ,;:
273 // if opt contains 'same' all histograms are drawn in the same pad
274 // otherwise the pad will be divided in sub pads and the histograms
275 // are drawn in each sub pad
279 Int_t vars[ndim]={var};
280 TObjArray *arr=CollectHistosProj(ndim,vars,slices);
285 //________________________________________________________________
286 void AliDielectronCFdraw::Draw(Int_t var0, Int_t var1, const char* opt, const char* slices)
292 Int_t vars[ndim]={var0,var1};
293 TObjArray *arr=CollectHistosProj(ndim,vars,slices);
298 //________________________________________________________________
299 void AliDielectronCFdraw::Draw(Int_t var0, Int_t var1, Int_t var2, const char* opt, const char* slices)
305 Int_t vars[ndim]={var0,var1,var2};
306 TObjArray *arr=CollectHistosProj(ndim,vars,slices);
311 //________________________________________________________________
312 TObjArray* AliDielectronCFdraw::CollectHistosProj(Int_t dim, Int_t *vars, const char* slices)
315 // Collect histos with 'dim'ension of the 'slices' separated by one of "':;'"
316 // in a TObjArray and return it
318 TObjArray *arr=TString(slices).Tokenize(",:;");
319 TObjArray *arrHists=0x0;
320 if (arr->GetEntriesFast()==0){
321 // all slices in case of 0 entries
322 arrHists=new TObjArray(fCfContainer->GetNStep());
323 for (Int_t istep=0; istep<fCfContainer->GetNStep(); ++istep){
324 TH1 *hproj=Project(dim,vars,istep);
325 if (!hproj) continue;
326 hproj->SetName(Form("proj_%02d",istep));
327 hproj->SetTitle(fCfContainer->GetStepTitle(istep));
328 arrHists->Add(hproj);
331 arrHists=new TObjArray(arr->GetEntriesFast());
333 TObjString *ostr=0x0;
334 while ( (ostr=static_cast<TObjString*>(next())) ) {
335 Int_t istep=ostr->GetString().Atoi();
336 TH1 *hproj=Project(dim,vars,istep);
337 if (!hproj) continue;
338 hproj->SetName(Form("proj_%02d",istep));
339 hproj->SetTitle(fCfContainer->GetStepTitle(istep));
340 arrHists->Add(hproj);
348 //________________________________________________________________
349 TH1* AliDielectronCFdraw::Project(Int_t ndim, Int_t *vars, Int_t slice)
352 // Do an nim projection
356 return fCfContainer->Project(vars[0],slice);
359 return fCfContainer->Project(vars[0],vars[1],slice);
362 return fCfContainer->Project(vars[0],vars[1],vars[2],slice);
368 //________________________________________________________________
369 void AliDielectronCFdraw::DrawEfficiency(const char* varnames, const char* nominators, Int_t denominator, const char* opt)
372 // plot efficiencies for variables. Variable may be up to 3 dim, separated by a ':'
373 // you may have several nominators, sparated by one of ',:;'
376 TObjArray *arrVars=TString(varnames).Tokenize(":");
377 Int_t entries=arrVars->GetEntriesFast();
378 if (entries<1||entries>3){
379 AliError("Wrong number of variables, supported are 1 - 3 dimensions");
385 TObjString *ostr=0x0;
386 Int_t ivar[3]={-1,-1,-1};
387 for (Int_t i=0; i<entries; ++i){
388 ostr=static_cast<TObjString*>(next());
389 if (ostr->GetString().IsDigit()){
390 ivar[i]=ostr->GetString().Atoi();
392 ivar[i]=fCfContainer->GetVar(ostr->GetName());
398 if (optStr.Contains("2")) type=1;
402 DrawEfficiency(ivar[0],nominators, denominator,opt,type);
405 DrawEfficiency(ivar[1],ivar[0], nominators, denominator,opt,type);
408 DrawEfficiency(ivar[2],ivar[1],ivar[0],nominators, denominator,opt,type);
414 //________________________________________________________________
415 void AliDielectronCFdraw::DrawEfficiency(Int_t var, const char* nominators, Int_t denominator, const char* opt, Int_t type)
418 // Draw Efficiencies for all nominators
419 // nominators may be divided by and of ,;:
421 // if opt contains 'same' all histograms are drawn in the same pad
422 // otherwise the pad will be divided in sub pads and the histograms
423 // are drawn in each sub pad
427 Int_t vars[ndim]={var};
428 TObjArray *arr=CollectHistosEff(ndim,vars,nominators,denominator,type);
435 //________________________________________________________________
436 void AliDielectronCFdraw::DrawEfficiency(Int_t var0, Int_t var1, const char* nominators, Int_t denominator, const char* opt, Int_t type)
442 Int_t vars[ndim]={var0,var1};
443 TObjArray *arr=CollectHistosEff(ndim,vars,nominators,denominator,type);
450 //________________________________________________________________
451 void AliDielectronCFdraw::DrawEfficiency(Int_t var0, Int_t var1, Int_t var2, const char* nominators, Int_t denominator, const char* opt, Int_t type)
457 Int_t vars[ndim]={var0,var1,var2};
458 TObjArray *arr=CollectHistosEff(ndim,vars,nominators,denominator,type);
465 //________________________________________________________________
466 TObjArray* AliDielectronCFdraw::CollectHistosEff(Int_t dim, Int_t *vars, const char* nominators, Int_t denominator, Int_t type)
469 // Collect histos with 'dim'ension of the 'slices' separated by one of "':;'"
470 // in a TObjArray and return it
472 TObjArray *arr=TString(nominators).Tokenize(",:;");
473 TObjArray *arrHists=0x0;
476 if (arr->GetEntriesFast()==0){
477 // all slices in case of 0 entries
478 arrHists=new TObjArray(fCfContainer->GetNStep());
479 fVdata.ResizeTo(arrHists->GetSize());
480 for (Int_t istep=0; istep<fCfContainer->GetNStep(); ++istep){
481 fEffGrid->CalculateEfficiency(istep,denominator);
482 TH1 *hproj=ProjectEff(dim,vars);
483 if (!hproj) continue;
484 Float_t eff=fEffGrid->GetAverage();
486 hproj->SetName(Form("eff_%02d/%02d",istep,denominator));
487 hproj->SetTitle(Form("%s (%.3f)",fCfContainer->GetStepTitle(istep),eff));
488 arrHists->Add(hproj);
491 arrHists=new TObjArray(arr->GetEntriesFast());
493 TObjString *ostr=0x0;
494 fVdata.ResizeTo(arrHists->GetSize());
496 while ( (ostr=static_cast<TObjString*>(next())) ) {
497 Int_t istep=ostr->GetString().Atoi();
498 fEffGrid->CalculateEfficiency(istep,denominator);
499 TH1 *hproj=ProjectEff(dim,vars);
500 if (!hproj) continue;
501 Float_t eff=fEffGrid->GetAverage();
503 hproj->SetName(Form("eff_%02d/%02d",istep,denominator));
504 hproj->SetTitle(Form("%s (%.3f)",fCfContainer->GetStepTitle(istep),eff));
505 arrHists->Add(hproj);
512 TH1 *hDen=Project(dim,vars,denominator);
513 Double_t entriesDen=hDen->GetEffectiveEntries();
514 if (arr->GetEntriesFast()==0){
515 // all slices in case of 0 entries
516 arrHists=new TObjArray(fCfContainer->GetNStep());
517 fVdata.ResizeTo(arrHists->GetSize());
518 for (Int_t istep=0; istep<fCfContainer->GetNStep(); ++istep){
519 TH1 *hproj=Project(dim,vars,istep);
520 if (!hproj) continue;
522 if (entriesDen>0) eff=hproj->GetEffectiveEntries()/entriesDen;
525 hproj->SetName(Form("eff_%02d/%02d",istep,denominator));
526 hproj->SetTitle(Form("%s (%.3f)",fCfContainer->GetStepTitle(istep),eff));
527 arrHists->Add(hproj);
530 arrHists=new TObjArray(arr->GetEntriesFast());
531 fVdata.ResizeTo(arrHists->GetSize());
533 TObjString *ostr=0x0;
535 while ( (ostr=static_cast<TObjString*>(next())) ) {
536 Int_t istep=ostr->GetString().Atoi();
537 TH1 *hproj=Project(dim,vars,istep);
538 if (!hproj) continue;
540 if (entriesDen>0) eff=hproj->GetEffectiveEntries()/entriesDen;
543 hproj->SetName(Form("eff_%02d/%02d",istep,denominator));
544 hproj->SetTitle(Form("%s (%.3f)",fCfContainer->GetStepTitle(istep),eff));
545 arrHists->Add(hproj);
556 //________________________________________________________________
557 TH1* AliDielectronCFdraw::ProjectEff(Int_t ndim, Int_t *vars)
560 // Do an nim projection
564 return fEffGrid->Project(vars[0]);
567 return fEffGrid->Project(vars[0],vars[1]);
570 return fEffGrid->Project(vars[0],vars[1],vars[2]);
576 //________________________________________________________________
577 void AliDielectronCFdraw::Draw(const TObjArray *arr, const char* opt)
580 // draw all objects in arr
584 Bool_t drawSame = optStr.Contains("same");
585 Bool_t drawSamePlus = optStr.Contains("same+");
586 Bool_t drawEff = optStr.Contains("eff");
587 Bool_t optLeg = optStr.Contains("leg");
588 Bool_t optScaleMax = optStr.Contains("max");
590 if (!drawSamePlus) optStr.ReplaceAll("same","");
592 optStr.ReplaceAll("+","");
593 optStr.ReplaceAll("eff","");
594 optStr.ReplaceAll("leg","");
595 optStr.ReplaceAll("max","");
597 if (!gPad) new TCanvas;
599 Int_t nPads = arr->GetEntriesFast();
600 if (nPads==0) return;
603 // arr->UncheckedAt(0)->Draw(optStr.Data());
607 TCanvas *c=gPad->GetCanvas();
608 if (!gVirtualPS&&!drawSamePlus) c->Clear();
613 Int_t nCols = (Int_t)TMath::Ceil( TMath::Sqrt(nPads) );
614 Int_t nRows = (Int_t)TMath::Ceil( (Double_t)nPads/(Double_t)nCols );
615 c->Divide(nCols,nRows);
616 for (Int_t i=0; i<nPads; ++i){
618 arr->UncheckedAt(i)->Draw(optStr.Data());
623 //find already existing legend to attach entries to it
624 TIter nextPrimitive(gPad->GetListOfPrimitives());
626 while ((o=nextPrimitive())) if (o->IsA()==TLegend::Class()) leg=(TLegend*)o;
629 if (optLeg&&!leg) leg=new TLegend(.2,.3,.99,.9);
631 if (leg) addColor=leg->GetNRows();
633 if (nPads<7) offset=24;
634 for (Int_t i=0; i<nPads; ++i){
635 if (i==1&&!drawSamePlus) optStr+="same";
636 TH1 *hist=static_cast<TH1*>(arr->UncheckedAt(i));
637 hist->SetLineColor(i+1+addColor);
638 hist->SetLineWidth(2);
639 hist->SetMarkerColor(i+1+addColor);
640 hist->SetMarkerStyle(offset+i+addColor);
641 hist->Draw(optStr.Data());
643 if (drawEff&&i==0&&!drawSamePlus) {
644 hist->GetYaxis()->SetRangeUser(0,2);
645 hist->SetYTitle("Rec. Signal / Gen. Signal");
648 if (leg) leg->AddEntry(hist,hist->GetTitle(),"lp");
651 leg->SetFillColor(10);
652 leg->SetY1(.9-leg->GetNRows()*.05);
653 leg->SetY1NDC(.9-leg->GetNRows()*.05);
655 if (!drawSamePlus) leg->Draw();
658 TIter nextPrimitive(gPad->GetListOfPrimitives());
662 while ((o=nextPrimitive())) if (o->InheritsFrom(TH1::Class())){
664 if (!hfirst) hfirst=h;
665 if (h->GetMaximum()>max) max=h->GetMaximum();
668 hfirst->SetMaximum(max);