3 extern TRandom *gRandom;
4 extern TBenchmark *gBenchmark;
5 extern TSystem *gSystem;
7 void testCFContainers(){
9 // simple example macros for usage of a N-dim container (AliCFContainer)
10 // handling a set of grids to accumulate data at different
11 // selection steps, & derive efficiency (this is stored in AliCFEffGrid)
12 // book, fill and draw some histos
13 // The efficiency is then used to correct the data (trivially self-correct,
16 gROOT->SetStyle("Plain");
17 gStyle->SetPalette(1);
18 gStyle->SetOptStat(111110);
19 gStyle->SetPalette(1);
20 gStyle->SetCanvasColor(0);
21 gStyle->SetFrameFillColor(0);
23 gSystem->SetIncludePath("-I. -I$ALICE_ROOT/include -I$ROOTSYS/include");
24 gSystem->Load("libANALYSIS.so");
25 gSystem->Load("$ALICE_ROOT/CORRFW/libCORRFW.so") ;
27 //Setting up the container grid...
29 const Int_t nstep=2; //number of selection steps (just 2 in this ex)
31 const Int_t nvar=4; //number of variables on the grid:pt,vtx
33 const Int_t nbin1=6; //bins in pt
34 const Int_t nbin2=10; //bins in eta
35 const Int_t nbin3=18; //bins in phi
36 const Int_t nbin4=10; //bins in vertex
39 //Flag the sel steps. In this example, we have two, may be any nstep
43 //the sensitive variables, their indeces
49 //arrays for the number of bins in each dimension
50 const Int_t iBin[nvar] ={nbin1,nbin2,nbin3,nbin4};
52 //arrays for bin limits
53 Double_t binLim1[nbin1+1];
54 Double_t binLim2[nbin2+1];
55 Double_t binLim3[nbin3+1];
56 Double_t binLim4[nbin4+1];
58 for(Int_t i=0;i<=nbin1;i++){
63 for(Int_t i=0;i<=nbin2;i++){
67 for(Int_t i=0;i<=nbin3;i++){
71 for(Int_t i=0;i<=nbin4;i++){
77 //the nstep grids "container"
78 AliCFContainer *cont = new AliCFContainer("cont","example of container",nstep,nvar,iBin);
80 //setting the bin limits
81 cont->SetBinLimits(ipt,binLim1);
82 cont->SetBinLimits(ieta,binLim2);
83 cont->SetBinLimits(iphi,binLim3);
84 cont->SetBinLimits(ivtx,binLim4);
86 //Start filling the mc and the data
88 //data sample (1M tracks)
91 gRandom->SetSeed(seed);
93 for(Int_t iev =0;iev<nev;iev++){
94 Float_t y=gRandom->Rndm();
95 Float_t pt=-TMath::Log(y)/0.5; //pt, exponential
96 Double_t eta=2.*gRandom->Rndm()-1.;//flat in eta
97 Double_t phi=360.*gRandom->Rndm(); //flat in phi
98 Float_t vtx=gRandom->Gaus( 0,5.);//gaussian in vertex
103 cont->Fill(Value, stepGen); //fill the efficiency denominator, sel step=0
104 Float_t rndm=gRandom->Rndm();
105 //simulate 80% constant efficiency everywhere
107 cont->Fill(Value,stepRec); //fill the efficiency denominator, sel step =1
112 cont->Save("container.root");
116 // Read the container from file
117 TFile *file = new TFile("container.root");
118 AliCFContainer *data = (AliCFContainer*) (file->Get("cont"));
120 // Make some 1 & 2-D projections..
121 // pt and vertex, generator and reconstructed level
122 TCanvas *cmc =new TCanvas("cmc","The distributions",0,300,900,900);
125 TH1D *hpt1a = data->ShowProjection(ipt, stepGen);
126 hpt1a->SetMinimum(0.01);
129 TH1D *hpt1b = data->ShowProjection(ipt, stepRec);
130 hpt1b->SetMinimum(0.01);
133 TH2D *hptvtx1a = data->ShowProjection(ipt,ivtx, stepGen);
134 hptvtx1a->SetMinimum(0.01);
135 hptvtx1a->Draw("lego");
137 TH2D *hptvtx1b = data->ShowProjection(ipt,ivtx, stepRec);
138 hptvtx1b->SetMinimum(0.01);
139 hptvtx1b->Draw("lego");
140 cmc->Print("data.gif");
143 //construct the efficiency grid from the data container
144 AliCFEffGrid *eff = new AliCFEffGrid("eff"," The efficiency",*data);
145 eff->CalculateEfficiency(stepRec,stepGen); //eff= step1/step0
147 //The efficiency along pt and vertex, and 2-D projection
148 TCanvas *ceff =new TCanvas("ceff"," Efficiency",0,300,900,300);
151 TH1D *hpt2a = eff->Project(ipt); //the efficiency vs pt
152 hpt2a->SetMinimum(0.01);
155 TH1D *hvtx2a = eff->Project(ivtx); //the efficiency vs vtx
156 hvtx2a->SetMinimum(0.01);
159 TH2D *hptvtx2a = eff->Project(ipt,ivtx); //look at the numerator
160 hptvtx2a->SetMinimum(0.01);
161 hptvtx2a->SetMinimum(0.01);
162 hptvtx2a->Draw("lego");
164 ceff->Print("eff.gif");
166 //get the corrected data grid
167 AliCFDataGrid *corrdata = new AliCFDataGrid("corrdata","corrected data",*data);
168 //correct selection step "reconstructed"
169 corrdata->SetMeasured(stepRec); //set data to be corrected
170 corrdata->ApplyEffCorrection(*eff);//apply the correction for efficiency
172 //The observed data, the corrected ones and the "MC truth" distributions
174 TCanvas *ccorrdata =new TCanvas("ccorrdata"," corrected data",0,300,900,900);
175 ccorrdata->Divide(2,2);
177 TH1D *hpt3a = corrdata->GetData()->Project(ipt); //uncorrected data
178 hpt3a->SetMinimum(0.01);
181 TH1D *hpt3b = corrdata->Project(ipt); //corrected data
182 hpt3b->SetMinimum(0.01);
185 TH1D *hvtx3a = corrdata->GetData()->Project(ivtx); //uncorrected data
186 hvtx3a->SetMinimum(0.01);
189 TH1D *hvtx3b = corrdata->Project(ivtx); //corrected data
190 hvtx3b->SetMinimum(0.01);
192 ccorrdata->Print("corrdata.gif");