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->Load("libANALYSIS.so");
24 gSystem->Load("libCORRFW.so") ;
26 //Setting up the container grid...
28 const Int_t nstep=2; //number of selection steps (just 2 in this ex)
30 const Int_t nvar=4; //number of variables on the grid:pt,vtx
32 const Int_t nbin1=6; //bins in pt
33 const Int_t nbin2=10; //bins in eta
34 const Int_t nbin3=18; //bins in phi
35 const Int_t nbin4=10; //bins in vertex
38 //Flag the sel steps. In this example, we have two, may be any nstep
42 //the sensitive variables, their indeces
48 //arrays for the number of bins in each dimension
49 const Int_t iBin[nvar] ={nbin1,nbin2,nbin3,nbin4};
51 //arrays for bin limits
52 Double_t binLim1[nbin1+1];
53 Double_t binLim2[nbin2+1];
54 Double_t binLim3[nbin3+1];
55 Double_t binLim4[nbin4+1];
57 for(Int_t i=0;i<=nbin1;i++){
62 for(Int_t i=0;i<=nbin2;i++){
66 for(Int_t i=0;i<=nbin3;i++){
70 for(Int_t i=0;i<=nbin4;i++){
76 //the nstep grids "container"
77 AliCFContainer *cont = new AliCFContainer("cont","example of container",nstep,nvar,iBin);
79 //setting the bin limits
80 cont->SetBinLimits(ipt,binLim1);
81 cont->SetBinLimits(ieta,binLim2);
82 cont->SetBinLimits(iphi,binLim3);
83 cont->SetBinLimits(ivtx,binLim4);
85 //Start filling the mc and the data
87 //data sample (1M tracks)
90 gRandom->SetSeed(seed);
92 for(Int_t iev =0;iev<nev;iev++){
93 Float_t y=gRandom->Rndm();
94 Float_t pt=-TMath::Log(y)/0.5; //pt, exponential
95 Double_t eta=2.*gRandom->Rndm()-1.;//flat in eta
96 Double_t phi=360.*gRandom->Rndm(); //flat in phi
97 Float_t vtx=gRandom->Gaus( 0,5.);//gaussian in vertex
102 cont->Fill(Value, stepGen); //fill the efficiency denominator, sel step=0
103 Float_t rndm=gRandom->Rndm();
104 //simulate 80% constant efficiency everywhere
106 cont->Fill(Value,stepRec); //fill the efficiency denominator, sel step =1
111 cont->Save("container.root");
115 // Read the container from file
116 TFile *file = new TFile("container.root");
117 AliCFContainer *data = (AliCFContainer*) (file->Get("cont"));
119 // Make some 1 & 2-D projections..
120 // pt and vertex, generator and reconstructed level
121 // TCanvas *cmc =new TCanvas("cmc","The distributions",0,300,900,900);
124 // TH1D *hpt1a = data->ShowProjection(ipt, stepGen);
125 // hpt1a->SetMinimum(0.01);
128 // TH1D *hpt1b = data->ShowProjection(ipt, stepRec);
129 // hpt1b->SetMinimum(0.01);
132 // TH2D *hptvtx1a = data->ShowProjection(ipt,ivtx, stepGen);
133 // hptvtx1a->SetMinimum(0.01);
134 // hptvtx1a->Draw("lego");
136 // TH2D *hptvtx1b = data->ShowProjection(ipt,ivtx, stepRec);
137 // hptvtx1b->SetMinimum(0.01);
138 // hptvtx1b->Draw("lego");
139 // cmc->Print("data.gif");
142 //construct the efficiency grid from the data container
143 AliCFEffGrid *eff = new AliCFEffGrid("eff"," The efficiency",*data);
144 eff->CalculateEfficiency(stepRec,stepGen); //eff= step1/step0
146 //The efficiency along pt and vertex, and 2-D projection
147 TCanvas *ceff =new TCanvas("ceff"," Efficiency",0,300,900,300);
150 TH1D *hpt2a = eff->Project(ipt); //the efficiency vs pt
151 hpt2a->SetMinimum(0.01);
154 TH1D *hvtx2a = eff->Project(ivtx); //the efficiency vs vtx
155 hvtx2a->SetMinimum(0.01);
158 TH2D *hptvtx2a = eff->Project(ipt,ivtx); //look at the numerator
159 hptvtx2a->SetMinimum(0.01);
160 hptvtx2a->SetMinimum(0.01);
161 hptvtx2a->Draw("lego");
163 ceff->Print("eff.gif");
165 //get the corrected data grid
166 AliCFDataGrid *corrdata = new AliCFDataGrid("corrdata","corrected data",*data);
167 //correct selection step "reconstructed"
168 corrdata->SetMeasured(stepRec); //set data to be corrected
169 corrdata->ApplyEffCorrection(*eff);//apply the correction for efficiency
171 //The observed data, the corrected ones and the "MC truth" distributions
173 TCanvas *ccorrdata =new TCanvas("ccorrdata"," corrected data",0,300,900,900);
174 ccorrdata->Divide(2,2);
176 TH1D *hpt3a = corrdata->GetData()->Project(ipt); //uncorrected data
177 hpt3a->SetMinimum(0.01);
180 TH1D *hpt3b = corrdata->Project(ipt); //corrected data
181 hpt3b->SetMinimum(0.01);
184 TH1D *hvtx3a = corrdata->GetData()->Project(ivtx); //uncorrected data
185 hvtx3a->SetMinimum(0.01);
188 TH1D *hvtx3b = corrdata->Project(ivtx); //corrected data
189 hvtx3b->SetMinimum(0.01);
191 ccorrdata->Print("corrdata.gif");