]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG0/multVScentPbPb/CorrectSpectraMulti.C
Macro for trend of SDD calibration updated to skip obselete OCDB files from LE run
[u/mrichter/AliRoot.git] / PWG0 / multVScentPbPb / CorrectSpectraMulti.C
CommitLineData
a9a39f46 1#if !defined(__CINT__) || defined(__MAKECINT__)
2#include "TList.h"
3#include "TFile.h"
4#include "TStyle.h"
5#include "TH1F.h"
6#include "TH2F.h"
7#include "THnSparse.h"
8#include "TLegend.h"
9#include "TSystem.h"
10#include "TMath.h"
11#include "TCanvas.h"
12#include "TLegend.h"
13#include "TLatex.h"
14#include "TF1.h"
15#include "TLine.h"
16#include "TPaletteAxis.h"
17#include "TArrayD.h"
18#include "TGraphErrors.h"
19//
20//
21#endif
22#include "/home/shahoian/ALICE/mymacros/SaveCanvas.h"
23
24
25
26const char kHStatName[]="hStat";
27double kEps = 1e-6;
28//
29double kdPhiBgTailMin = 0.1; // lower limit of dphi tail to use for bg normalization
30double kdPhiBgTailMax = 0.3; // upper limit of dphi tail to use for bg normalization
31//
32double kWDistBgTailMin = 5.; // lower limit of wgh.distance tail to use for bg normalization
33double kWDistBgTailMax = 25.; // upper limit of wgh.distance tail to use for bg normalization
34
35double kdPhiSgCut=-1; // cut in dphi-bent used to extract the signal, extracted from stat histo
36double kWDistSgCut=-1; // cut in w.distance used to extract the signal, extracted from stat histo
37//
38enum { kNormShapeDist, // normalize bg tails usig weighted distance shape
39 kNormShapeDPhi, // normalize bg tails usig dPhi-bend shape
40 kNormShapes};
41
42enum { kSclWghMean, // normalize bg tails to data using weighted mean of bin-by-bin ratios
43 kSclIntegral, // normalize bg tails to data using integral
44 kSclTypes};
45
46
47const char* figDir = "figMult";
48TString useBgType = "Inj";
49Int_t useShapeType = kNormShapeDist; // which distribution to use for bg normalization
6c56e693 50Bool_t useMCLB = 0;//kFALSE; // use Comb MC Labels as a template for Bg.
a9a39f46 51Int_t useScaleType = kSclIntegral;//kSclWghMean; // which type of tails normalization to use
52const double kEtaFitRange = 0.5;
53
54enum {kBitNormPerEvent=BIT(14)};
55 // bins for saved parameters in the hStat histo
6c56e693 56 enum {kDummyBin,
57 kEvTot0, // events read
58 kEvTot, // events read after vertex quality selection
59 kOneUnit, // just 1 to track primate merges
60 kNWorkers, // n workers
61 //
62 kCentVar, // cetrality var. used
63 kDPhi, // dphi window
64 kDTht, // dtheta window
65 kNStd, // N.standard deviations to keep
66 kPhiShift, // bending shift
67 kThtS2, // is dtheta scaled by 1/sin^2
68 kThtCW, // on top of w.dist cut cut also on 1 sigma dThetaX
69 kPhiOvl, // overlap params
70 kZEtaOvl, // overlap params
71 kNoOvl, // flag that overlap are suppressed
72 //
73 kPhiRot, // rotation phi
74 kInjScl, // injection scaling
75 kEtaMin, // eta cut
76 kEtaMax, // eta cut
77 kZVMin, // min ZVertex to process
78 kZVMax, // max ZVertex to process
79 //
80 kDPiSCut, // cut on dphi used to extract signal (when WDist is used in analysis, put it equal to kDPhi
81 kNStdCut, // cut on weighted distance (~1) used to extract signal
82 //
83 kMCV0Scale, // scaling value for V0 in MC
84 //
85 // here we put entries for each mult.bin
86 kBinEntries = 50,
87 kEvProcData, // events with data mult.object (ESD or reco)
88 kEvProcInj, // events Injected, total
89 kEvProcRot, // events Rotated
90 kEvProcMix, // events Mixed
91 kEntriesPerBin
92 };
a9a39f46 93
94
95enum {kSigCorr,kMCPrim,kRawDtCut,kSignalEst,kSignalEstMC,kBgEst,k1MBeta,k1MBetaMC,kAlpha,kAlphaMC,kBgMC,kBgRescFc,kDataDist,kBgDist,kBgMCDist, kMCShift=20, kNHistos=kMCShift+kMCShift};
96
97void CorrectSpectraMulti(const char* flNameData, const char* flNameMC,const char* unique="");
98Bool_t PrepareHistos(int bin, TList* lst, Bool_t isMC);
99void ProcessHistos(int bin);
100TH1* NormalizeBg(TH1* dataH, TH1* bgH, double &scl, double &scle);
101TObject* FindObject(int bin, const char* nameH, const TList* lst, Bool_t normPerEvent=kTRUE);
102TList* LoadList(const char* flName, const char* addPref, const char* nameL="clist");
103void GetRatE(double x,double xe, double y,double ye, double &rat, double &rate);
104Int_t CheckStat(const TList* lst,const char* dtType);
105void Integrate(TH1* hist, double xmn,double xmx, double &val, double& err);
106void CropHisto(TH1* histo, int b00, int b01, int b10=-1, int b11=-1);
107void CropHisto(TH1* histo, double b00, double b01, double b10=-1, double b11=-1);
108void GetRealMinMax(TH1* h, double &vmn, double &vmx);
109const char* HName(const char* prefix,const char* htype);
110
111void PlotResults();
112void PlotDNDEta(int bin);
113void PlotAlphaBeta(int bin);
114void PlotSpecies();
115
116Float_t myMergeFactor = -1; // if the files were manually merged, scale everything except statistics by 1/myMergeFactor
117Int_t nCentBins = -1;
118TList *listDt=0, *listMC=0;
119TObjArray resArr;
120char outStr[1000];
121char outTitle[1000];
122TString uniqueName="";
123//
124TArrayD dNdEta,dNdEtaErr;
125TCanvas *canvFin=0;
126//
127Bool_t creatDnDEtaCMacro = kFALSE;
128Bool_t creatAlphaBetaCMacro = kFALSE;
129Bool_t creatSpeciesCMacro = kFALSE;
130
131void CorrectSpectraMulti(const char* flNameData, const char* flNameMC, const char* uniqueNm)
132{
133 //
134 uniqueName = uniqueNm;
135 listDt = LoadList(flNameData,"dt_");
136 listMC = LoadList(flNameMC,"mc_");
137 //
138 resArr.Clear();
139 //
140 TH1* hstat = (TH1*)FindObject(-1,kHStatName,listDt,kFALSE);
141 //
142 int nbstat = hstat->GetNbinsX();
143 nCentBins = (nbstat - kBinEntries)/kEntriesPerBin;
144 printf("%d bins will be processed\n",nCentBins);
145 if (nCentBins<1) return;
146 myMergeFactor = hstat->GetBinContent(kOneUnit);
147 printf("Detected %f mergings\n",myMergeFactor);
148 //
149 dNdEta.Set(nCentBins);
150 dNdEtaErr.Set(nCentBins);
151 //
152 kdPhiSgCut = hstat->GetBinContent(kDPiSCut)/myMergeFactor;
153 kWDistSgCut = hstat->GetBinContent(kNStdCut)/myMergeFactor;
154 printf("Signal cuts used: dPhiS: %f WDist:%f\n",kdPhiSgCut,kWDistSgCut);
155 //
156 for (int ib=0;ib<nCentBins;ib++) {
157 if (!PrepareHistos(ib,listMC,kTRUE)) return;
158 if (!PrepareHistos(ib,listDt,kFALSE)) return;
159 ProcessHistos(ib);
160 //
161 }
162 //
6c56e693 163 sprintf(outStr,"CutEta%.1f_%.1f_Zv%.1f_%.1f_bg%s_Shape_%s_mcLB%d_cutSig%.1f_cutBg%.1f",
164 hstat->GetBinContent(kEtaMin)/myMergeFactor,
165 hstat->GetBinContent(kEtaMax)/myMergeFactor,
a9a39f46 166 hstat->GetBinContent(kZVMin)/myMergeFactor,
167 hstat->GetBinContent(kZVMax)/myMergeFactor,
168 useBgType.Data(),
169 useShapeType==kNormShapeDist ? "wdst":"dphi",
170 useMCLB,
171 useShapeType==kNormShapeDist ? kWDistSgCut:kdPhiSgCut,
172 useShapeType==kNormShapeDist ? kWDistBgTailMin:kdPhiBgTailMin);
173 //
174 PlotResults();
175 //
176 printf("Final Results:\n");
177 printf("dNdEta: ");
178 for (int i=nCentBins;i--;) printf("%.2f,",dNdEta[i]); printf("\n");
179 printf("dNdEtaErr: ");
180 for (int i=nCentBins;i--;) printf("%.2f,",dNdEtaErr[i]); printf("\n");
181
182}
183
184//_____________________________________________________________________
185Bool_t PrepareHistos(int bin, TList* lst, Bool_t isMC)
186{
187 // fill standard histos for given bin
188 //
189 char buffn[500];
190 char bufft[500];
191 //
192 double cutBgMin,cutBgMax;
193 double cutSgMin,cutSgMax;
194 //
195 if (useShapeType==kNormShapeDist) {
196 cutBgMin = kWDistBgTailMin;
197 cutBgMax = kWDistBgTailMax;
198 //
199 cutSgMin = 0;
200 cutSgMax = kWDistSgCut;
201 }
202 else {
203 cutBgMin = kdPhiBgTailMin;
204 cutBgMax = kdPhiBgTailMax;
205 //
206 cutSgMin = 0;
207 cutSgMax = kdPhiSgCut;
208 }
209 //
210 const char* zeCut = "ZvEtaCutT";
211 TObjArray* res = &resArr;
212 int shift = bin*kNHistos + (isMC ? kMCShift : 0);
213 //
214 // histo for "data" Z vs Eta with default signal cut
215 TH2* hRawDtCut = (TH2*) FindObject(bin,HName("Data",zeCut),lst);
216 if (!hRawDtCut) return kFALSE;
217 sprintf(buffn,"bin%d_%s_RawWithCut",bin,isMC ? "mc":"dt");
218 sprintf(bufft,"bin%d %s Raw Data with cut on tracklets",bin,isMC ? "mc":"dt");
219 hRawDtCut = (TH2*)hRawDtCut->Clone(buffn);
220 hRawDtCut->SetTitle(bufft);
221 res->AddAtAndExpand(hRawDtCut, kRawDtCut+shift);
222 //
223 int nbEta = hRawDtCut->GetXaxis()->GetNbins();
224 int nbZV = hRawDtCut->GetYaxis()->GetNbins();
225 //
226 // "Data - Est.Bg" histo with cut on tails where we look for signal
227 sprintf(buffn,"bin%d_%s_SignalWithCut",bin,isMC ? "mc":"dt");
228 sprintf(bufft,"bin%d %s Signal (raw-bg) with cut on tracklets",bin,isMC ? "mc":"dt");
229 TH2* hSignalEst = (TH2F*)hRawDtCut->Clone(buffn);
230 hSignalEst->SetTitle(bufft);
231 res->AddAtAndExpand(hSignalEst, kSignalEst+shift);
232 //
233 // "Data - MC.Bg" histo with cut on tails where we look for signal
234 TH2* hSignalEstMC = 0;
235 if (isMC) {
236 sprintf(buffn,"bin%d_%s_SignalWithCut_bgMCLabels",bin,isMC ? "mc":"dt");
237 sprintf(bufft,"bin%d %s Signal (raw-bg_MCLabels) with cut on tracklets",bin,isMC ? "mc":"dt");
238 hSignalEstMC = (TH2F*)hRawDtCut->Clone(buffn);
239 hSignalEstMC->SetTitle(bufft);
240 res->AddAtAndExpand(hSignalEstMC, kSignalEstMC+shift);
241 }
242 //
243 // Estimated background in the cut range
244 sprintf(buffn,"bin%d_%s_BgEst",bin,isMC ? "mc":"dt");
245 sprintf(bufft,"bin%d %s Estimated Bg",bin,isMC ? "mc":"dt");
246 TH2* hBgEst = (TH2*) FindObject(bin,HName(useBgType.Data(),zeCut),lst);
247 if (!hBgEst) return kFALSE;
248 hBgEst = (TH2*)hBgEst->Clone(buffn);
249 hBgEst->SetTitle(bufft);
250 res->AddAtAndExpand(hBgEst,kBgEst +shift);
251 //
252 // special feature: use MC Labels bg as a shape instead of generated bg
6c56e693 253 if (useMCLB/* && !isMC*/) {
a9a39f46 254 TString nm = hBgEst->GetName(); nm += "_MCLB";
255 TString tit = hBgEst->GetTitle(); tit += "_MCLB";
256 TH2* hBMCLB = (TH2*) FindObject(bin,HName("Comb",zeCut),listMC);
257 if (!hBMCLB) return kFALSE;
258 hBMCLB = (TH2F*)hBMCLB->Clone(nm.Data());
259 hBMCLB->SetTitle(tit.Data());
260 delete hBgEst;
261 hBgEst = hBMCLB;
262 res->AddAtAndExpand(hBgEst,kBgEst +shift);
263 }
a9a39f46 264 //
265 // 1-beta for "data" = (Data_cut - Bg_cut) / Data_cut
266 sprintf(buffn,"bin%d_%s_1mBeta",bin,isMC ? "mc":"dt");
267 sprintf(bufft,"bin%d %s 1-#beta with estimated bg",bin,isMC ? "mc":"dt");
268 TH2* h1mBeta = (TH2*)hBgEst->Clone(buffn);
269 h1mBeta->SetTitle(bufft);
270 h1mBeta->Reset();
271 res->AddAtAndExpand(h1mBeta, k1MBeta+shift);
272 //
273 // If MC labels info is provided, prepare 1-beta with MC bg
274 TH2* h1mBetaMC = 0; // 1-beta for MC with bg from labels
275 TH2* hBgMC = 0; // bg from MC labels
276 if (isMC) {
277 sprintf(buffn,"bin%d_%s_BgMC",bin,isMC ? "mc":"dt");
278 sprintf(bufft,"bin%d %s Bg from MC labels",bin,isMC ? "mc":"dt");
279 hBgMC = (TH2*) FindObject(bin,HName("Comb",zeCut),listMC);
280 if (!hBgMC) return kFALSE;
281 hBgMC = (TH2F*)hBgMC->Clone(buffn);
282 hBgMC->SetTitle(bufft);
283 res->AddAtAndExpand(hBgMC, kBgMC+shift);
284 //
285 sprintf(buffn,"bin%d_%s_h1mBetaMC",bin,isMC ? "mc":"dt");
286 sprintf(bufft,"bin%d %s 1-#beta with bg. from MC labels",bin,isMC ? "mc":"dt");
287 h1mBetaMC = (TH2F*) hBgMC->Clone(buffn);
288 h1mBetaMC->SetTitle(bufft);
289 res->AddAtAndExpand(h1mBetaMC, k1MBetaMC+shift);
290 h1mBetaMC->Divide(hRawDtCut);
291 for (int ib0=1;ib0<=nbEta;ib0++)
292 for (int ib1=1;ib1<=nbZV;ib1++)
293 h1mBetaMC->SetBinContent(ib0,ib1, 1.- h1mBetaMC->GetBinContent(ib0,ib1));
294 //
295 hSignalEstMC->Add(hBgMC,-1);
296 }
297 //
298 // uncut w.distance or dphi distribution for data
299 TH1* hDstDt = (TH1*) FindObject(bin,HName("Data",useShapeType==kNormShapeDist ? "WDist":"DPhiS"),lst);
300 if (!hDstDt) return kFALSE;
301 sprintf(buffn,"bin%d_%s_DistRawData",bin,isMC ? "mc":"dt");
302 sprintf(bufft,"bin%d %s Raw Distance for Data",bin,isMC ? "mc":"dt");
303 hDstDt = (TH1*) hDstDt->Clone(buffn);
304 hDstDt->SetTitle(bufft);
305 double nrmDst,dumErr = 0;
306 Integrate(hDstDt, cutBgMin,cutBgMax, nrmDst, dumErr);
307 hDstDt->Scale(1./nrmDst);
308 res->AddAtAndExpand(hDstDt, kDataDist+shift);
309 //
310 // uncut w.distance or dphi distribution for generated bg
311 TH1* hDstBg = (TH1*) FindObject(bin,HName(useBgType.Data(),useShapeType==kNormShapeDist ? "WDist":"DPhiS"),lst);
312 if (!hDstBg) return kFALSE;
313 sprintf(buffn,"bin%d_%s_DistRawGenBgNorm",bin,isMC ? "mc":"dt");
314 sprintf(bufft,"bin%d %s Raw Distance for Gen.Bg. Normalized to data",bin,isMC ? "mc":"dt");
315 hDstBg = (TH1*) hDstBg->Clone(buffn);
316 hDstBg->SetTitle(bufft);
317 hDstBg->Scale(1./nrmDst);
318 // res->AddAtAndExpand(hDstBg, kBgDist+shift);
319 //
a9a39f46 320 // uncut w.distance or dphi distribution for comb. MC labels
321 TH1* hDstBgMC = 0;
322 if (isMC) {
323 hDstBgMC = (TH1*) FindObject(bin,HName("Comb",useShapeType==kNormShapeDist ? "WDist":"DPhiS"),lst);
324 if (!hDstBgMC) return kFALSE;
325 sprintf(buffn,"bin%d_%s_DistBgMC",bin,isMC ? "mc":"dt");
326 sprintf(bufft,"bin%d %s Bg. Distance from MC labels",bin,isMC ? "mc":"dt");
327 hDstBgMC = (TH1*) hDstBgMC->Clone(buffn);
328 hDstBgMC->SetTitle(bufft);
329 hDstBgMC->Scale(1./nrmDst);
330 res->AddAtAndExpand(hDstBgMC, kBgMCDist+shift);
331 }
332 //
333 // fill 1-beta matrix
334 double scl,sclE;
335 hDstBg = NormalizeBg(hDstDt,hDstBg,scl,sclE); // get rescaling factor for bg. from tails comparison
336 res->AddAtAndExpand(hDstBg, kBgDist+shift);
337 double bgVal,bgErr;
338 double dtVal,dtErr;
339 // integral in the range where we look for signal
340 Integrate(hDstBg, cutSgMin, cutSgMax, bgVal, bgErr);
341 Integrate(hDstDt, cutSgMin, cutSgMax, dtVal, dtErr);
342 double sclb,sclbErr;
343 GetRatE(bgVal,bgErr, dtVal, dtErr,sclb,sclbErr);
344 // hDstBg->Scale(1./nrmDst);
345 //
346 // finalize estimated bg and signal matrices
347 hBgEst->Scale(scl);
348 //
349 hSignalEst->Add(hBgEst,-1);
350 //
351 // finalize 1-beta
352 for (int ib0=1;ib0<=nbEta;ib0++) { // eta
353 for (int ib1=1;ib1<=nbZV;ib1++) { // zv
354 // printf("Bin %d %d\n",ib0,ib1);
355 double bg = hBgEst->GetBinContent(ib0,ib1);
356 double bgE = hBgEst->GetBinError(ib0,ib1);
357 double dt = hRawDtCut->GetBinContent(ib0,ib1);
358 double dtE = hRawDtCut->GetBinError(ib0,ib1);
359 double beta,betaE;
360 GetRatE(bg,bgE,dt,dtE, beta,betaE );
361 h1mBeta->SetBinContent(ib0,ib1,1.-beta);
362 h1mBeta->SetBinError(ib0,ib1,betaE);
363 //
364 }
365 }
366 //
367 if (isMC) {
368 // prepare MC primary signal histo
369 sprintf(buffn,"bin%d_zvEtaPrimMC",bin);
370 sprintf(bufft,"bin%d MC True signal Zv vs Eta",bin);
371 TH2F* mcPrim = (TH2F*)FindObject(bin,"zvEtaPrimMC", lst );
372 mcPrim = (TH2F*) mcPrim->Clone(buffn);
373 mcPrim->SetTitle(bufft);
374 res->AddAtAndExpand(mcPrim, kMCPrim + shift);
375 }
376 //
377 return kTRUE;
378}
379
380//_____________________________________________________________________
381void ProcessHistos(int bin)
382{
383 //
384 int shift = bin*kNHistos;
385 //
386 TString prefN = "bin"; prefN += bin; prefN+="_";
387 TString prefT = "bin"; prefT += bin; prefT+=" ";
388 TObjArray* res = &resArr;
389 // build alpha matrix
390 TH2* halp = (TH2*)res->At(shift + kMCShift + kMCPrim);
391 halp = (TH2*) halp->Clone(prefN+"Alpha");
392 halp->SetTitle(prefN+"#alpha");
393 halp->Divide( (TH2*)res->At(shift + kMCShift + k1MBeta) );
394 halp->Divide( (TH2*)res->At(shift + kMCShift + kRawDtCut) );
395 res->AddAtAndExpand(halp, shift + kAlpha);
396 //
397 // build alpha matrix with MC labels bg
398 TH2* halpMC = (TH2*)res->At(shift + kMCShift + kMCPrim);
399 halpMC = (TH2*) halpMC->Clone(prefN + "AlphaMC");
400 halpMC->SetTitle(prefT + "#alpha MC labels");
401 halpMC->Divide( (TH2*)res->At(shift + kMCShift + k1MBetaMC) );
402 halpMC->Divide( (TH2*)res->At(shift + kMCShift + kRawDtCut) );
403 res->AddAtAndExpand(halpMC, shift + kAlphaMC);
404 //
405 // build corrected signal
406 TH2* hsigCorr = (TH2*)res->At(shift + kSignalEst);
407 hsigCorr = (TH2*) hsigCorr->Clone(prefN + "SignalEstCorr");
408 hsigCorr->SetTitle(prefT + "Corrected Signal");
409 hsigCorr->Multiply( halp );
410 res->AddAtAndExpand(hsigCorr, shift + kSigCorr);
411 //
412 TH1* hsigCorrX = hsigCorr->ProjectionX("DataCorrSignalX");
413 hsigCorrX->Scale(1./hsigCorr->GetBinWidth(1));
414 TF1* pl0 = new TF1("pl0","pol0");
415 pl0->SetParameter(0,hsigCorr->GetMinimum());
416 hsigCorrX->Fit(pl0,"q0","",-kEtaFitRange,kEtaFitRange);
417 double fval = pl0->GetParameter(0);
418 double ferr = pl0->GetParError(0);
419 delete hsigCorrX;
420 dNdEta[bin] = fval;
421 dNdEtaErr[bin] = ferr;
422 printf("Bin %d: dN/d#eta_{|#eta|<0.5} = %.2f %.2f\n",bin, fval,ferr);
423 //
424}
425
426void PlotResults()
427{
428 TString psnm1 = figDir; psnm1 += "/"; psnm1 += uniqueName;
429 psnm1 += "_"; psnm1 += nCentBins; psnm1+= "bins_";
430 psnm1 += outStr; psnm1 += ".ps";
431 TString psnm0 = psnm1.Data();
432 psnm0 += "[";
433 TString psnm2 = psnm1.Data();
434 psnm2 += "]";
435 //
436 TH1* hstat = (TH1*)FindObject(-1,kHStatName,listDt,kFALSE);
437 //
438 TH1* hbins = (TH1*)FindObject(-1,"EvCentr",listDt,kFALSE);
439 //
440 if (!canvFin) canvFin = new TCanvas("canvFin", "canvFin",0,50,700,1000);
441 canvFin->Clear();
442 //
443 canvFin->Print(psnm0.Data());
444 //
445 canvFin->Divide(1,2);
446 canvFin->cd(1);
447 gPad->SetLeftMargin(0.15);
448 TGraphErrors* grp = new TGraphErrors(nCentBins);
449 for (int i=0;i<nCentBins;i++) {
450 grp->SetPoint(i,hbins->GetBinCenter(i+1),dNdEta[i]);
451 grp->SetPointError(i,hbins->GetBinWidth(i+1)/2,dNdEtaErr[i]);
452 }
453 grp->SetMarkerStyle(20);
454 grp->SetMarkerColor(kRed);
455 grp->SetLineColor(kRed);
456 grp->SetMinimum(1e-6);
457 grp->Draw("ap");
458 grp->GetXaxis()->SetTitle("Centrality Variable");
459 grp->GetYaxis()->SetTitle("dN/d#eta_{|#eta|<0.5}");
460 grp->GetYaxis()->SetTitleOffset(1.8);
461 gPad->SetGrid(1,1);
462 //
463 canvFin->cd(2);
464 gPad->SetLeftMargin(0.15);
465 hbins->Draw();
466 hbins->SetMinimum(1e-6);
467 hbins->SetMarkerStyle(20);
468 hbins->SetMarkerColor(kRed);
469 hbins->SetLineColor(kRed);
470 hbins->GetYaxis()->SetTitle("accepted events");
471 hbins->GetYaxis()->SetTitleOffset(1.8);
472 gPad->SetGrid(1,1);
473 //
474 canvFin->cd(0);
475 canvFin->Print(psnm1.Data());
476 //
477 const TArrayD &binArr = *hbins->GetXaxis()->GetXbins();
478 //
479 for (int i=0;i<nCentBins;i++) {
480 //
6c56e693 481 sprintf(outTitle,"%s, %d<C_%s<%d, %.1f<#eta<%.1f, %.1f<Z_{V}<%.1f, Bg.:%s, UseMCLB=%d, CutVar:%s, |sig|<%.2f, %.2f<|bg.nrm|<%.2f",
a9a39f46 482 uniqueName.Data(),
6c56e693 483 (int)binArr[i],
484 hstat->GetXaxis()->GetBinLabel(kCentVar),
485 (int)binArr[i+1],
486 hstat->GetBinContent(kEtaMin)/myMergeFactor,
487 hstat->GetBinContent(kEtaMax)/myMergeFactor,
a9a39f46 488 hstat->GetBinContent(kZVMin)/myMergeFactor,
489 hstat->GetBinContent(kZVMax)/myMergeFactor,
490 useBgType.Data(),
491 useMCLB,
492 useShapeType==kNormShapeDist ? "#Delta":"#Delta#varphi-#delta_{#varphi}",
493 useShapeType==kNormShapeDist ? kWDistSgCut:kdPhiSgCut,
494 useShapeType==kNormShapeDist ? kWDistBgTailMin : kdPhiBgTailMin,
495 useShapeType==kNormShapeDist ? kWDistBgTailMax : kdPhiBgTailMax
496 );
497 //
498 PlotDNDEta(i);
499 canvFin->Print(psnm1.Data());
500 PlotAlphaBeta(i);
501 canvFin->Print(psnm1.Data());
502 }
503 PlotSpecies();
504 canvFin->Print(psnm1.Data());
505 //
506 canvFin->Print(psnm2.Data());
507}
508
509void PlotDNDEta(int bin)
510{
511 //
512 TObjArray *res = &resArr;
513 TString prefN = "bin"; prefN += bin; prefN+="_";
514 int shift = bin*kNHistos;
515 //
516 char buff[1000];
517 // eta range
518 gStyle->SetOptFit(0);
519 gStyle->SetOptStat(0);
520 gStyle->SetOptTitle(0);
521 double mn = 1e6,mx = -1e6;
522 if (!canvFin) canvFin = new TCanvas("canvFin", "canvFin",0,50,700,1000);
523 canvFin->Clear();
524 canvFin->Divide(1,2);
525 canvFin->cd(1);
526 gPad->SetLeftMargin(0.15);
527 //
528 // corrected data
529 TH1* hsigCorr = ((TH2F*)res->At(shift + kSigCorr))->ProjectionX(prefN+"DataCorrSignal");
530 SetHStyle(hsigCorr,kRed,20,1.0);
531 hsigCorr->Scale(1./hsigCorr->GetBinWidth(1));
532 hsigCorr->Draw();
533 mx = TMath::Max(mx, hsigCorr->GetMaximum());
534 mn = TMath::Min(mn, hsigCorr->GetMinimum());
535 char ftres[1000];
536 sprintf(ftres,"dN/d#eta_{|#eta|<%.1f} = %.1f #pm %.1f",kEtaFitRange,dNdEta[bin],dNdEtaErr[bin]);
537 TLatex *txfit = new TLatex(-0.2,hsigCorr->GetMinimum()*0.9, ftres);
538 txfit->SetTextSize(0.04);
539 txfit->Draw();
540 //
541 // raw data
542 TH1* hraw = ((TH2F*)res->At(shift+kRawDtCut))->ProjectionX(prefN+"DataRaw");
543 SetHStyle(hraw,kRed,21,1.0);
544 hraw->Scale(1./hraw->GetBinWidth(1));
545 hraw->Draw("same");
546 mn = TMath::Min(mn, hraw->GetMinimum());
547 mx = TMath::Max(mx, hraw->GetMaximum());
548 //
549 // raw data bg sub
550 TH1* hraws = ((TH2F*)res->At(shift+kSignalEst))->ProjectionX(prefN+"DataRawSub");
551 SetHStyle(hraws,kRed,23,1.0);
552 hraws->Scale(1./hraw->GetBinWidth(1));
553 hraws->Draw("same");
554 mn = TMath::Min(mn, hraw->GetMinimum());
555 mx = TMath::Max(mx, hraw->GetMaximum());
556 //
557 // bg
558 TH1* hbg = ((TH2F*)res->At(shift+kBgEst))->ProjectionX(prefN+"BgEst");
559 SetHStyle(hbg,kMagenta,22,1.0);
560 hbg->Scale(1./hbg->GetBinWidth(1));
561 hbg->Draw("same");
562 mn = TMath::Min(mn, hbg->GetMinimum());
563 mx = TMath::Max(mx, hbg->GetMaximum());
564 //
565 // mc part ----------------------------
566 // raw data
567 TH1* hrawMC = ((TH2F*)res->At(shift+kRawDtCut+kMCShift))->ProjectionX(prefN+"DataRawMC");
568 SetHStyle(hrawMC,kBlue,24,1.0);
569 hrawMC->Scale(1./hrawMC->GetBinWidth(1));
570 hrawMC->Draw("same");
571 mn = TMath::Min(mn, hrawMC->GetMinimum());
572 mx = TMath::Max(mx, hrawMC->GetMaximum());
573 //
574 // raw data bg sub
575 TH1* hrawsMC = ((TH2F*)res->At(shift+kSignalEst+kMCShift))->ProjectionX(prefN+"DataRawSubMC");
576 SetHStyle(hrawsMC,kBlue,26,1.0);
577 hrawsMC->Scale(1./hrawMC->GetBinWidth(1));
578 hrawsMC->Draw("same");
579 mn = TMath::Min(mn, hrawMC->GetMinimum());
580 mx = TMath::Max(mx, hrawMC->GetMaximum());
581 //
582 // raw data bgMClabels sub
583 TH1* hrawsMCLB = ((TH2F*)res->At(shift+kSignalEstMC+kMCShift))->ProjectionX(prefN+"DataRawSubMCLB");
584 SetHStyle(hrawsMCLB,kGreen+2,30,1.0);
585 hrawsMCLB->Scale(1./hrawsMCLB->GetBinWidth(1));
586 hrawsMCLB->Draw("same");
587 mn = TMath::Min(mn, hrawsMCLB->GetMinimum());
588 mx = TMath::Max(mx, hrawsMCLB->GetMaximum());
589 //
590 // bg est
591 TH1* hbgMCEst = ((TH2F*)res->At(shift+kBgEst+kMCShift))->ProjectionX(prefN+"BgEstMC");
592 SetHStyle(hbgMCEst,kBlue,26,1.0);
593 hbgMCEst->Scale(1./hbgMCEst->GetBinWidth(1));
594 hbgMCEst->Draw("same");
595 mn = TMath::Min(mn, hbgMCEst->GetMinimum());
596 mx = TMath::Max(mx, hbgMCEst->GetMaximum());
597 //
598 // bg MC
599 TH1* hbgMC = ((TH2F*)res->At(shift+kBgMC+kMCShift))->ProjectionX(prefN+"BgMC");
600 SetHStyle(hbgMC,kGreen+2,25,1.0);
601 hbgMC->Scale(1./hbgMC->GetBinWidth(1));
602 hbgMC->Draw("same");
603 mn = TMath::Min(mn, hbgMC->GetMinimum());
604 mx = TMath::Max(mx, hbgMC->GetMaximum());
605 //
606 mn = 0;
607 hsigCorr->SetMinimum(mn);
608 hsigCorr->SetMaximum(mx + 0.4*(mx-mn));
609 gPad->Modified();
610 //
611 TLegend *legDnDeta = new TLegend(0.15,0.75, 0.45,0.95);
612 legDnDeta->SetFillColor(kWhite);
613 legDnDeta->SetHeader("Data");
614 legDnDeta->AddEntry(hsigCorr,"Corrected","pl");
615 legDnDeta->AddEntry(hraw, "Reconstructed","pl");
616 sprintf(buff,"Reconstructed - Bckg.%s.",useBgType.Data());
617 legDnDeta->AddEntry(hraws, buff,"pl");
618 sprintf(buff,"Background %s.",useBgType.Data());
619 legDnDeta->AddEntry(hbg, buff,"pl");
620 legDnDeta->Draw();
621 //
622 TLegend *legDnDetaMC = new TLegend(0.60,0.72, 0.95,0.95);
623 legDnDetaMC->SetFillColor(kWhite);
624 legDnDetaMC->SetHeader("MC");
625 legDnDetaMC->AddEntry(hrawMC, "Reconstructed","pl");
626 sprintf(buff,"Reconstructed - Bckg.%s.",useBgType.Data());
627 legDnDetaMC->AddEntry(hrawsMC, buff,"pl");
628 sprintf(buff,"Reconstructed - Bckg.%s.","MC.Labels");
629 legDnDetaMC->AddEntry(hrawsMCLB, buff,"pl");
630 sprintf(buff,"Background %s.",useBgType.Data());
631 legDnDetaMC->AddEntry(hbgMCEst, buff,"pl");
632 sprintf(buff,"Background %s.","MC Labels");
633 legDnDetaMC->AddEntry(hbgMC, buff,"pl");
634 //
635 legDnDetaMC->Draw();
636 //
637 gPad->SetGrid(1.1);
638 gPad->Modified();
6c56e693 639 AddLabel(outTitle,0.1,0.97, kBlack,0.02);
a9a39f46 640 //
641 canvFin->cd();
642 //
643 //---------------- dsitributions
644 canvFin->cd(2);
645 //
646 TH1* mcdst = (TH1*)res->At(shift+kDataDist+kMCShift);
647 TH1* mcdstbg = (TH1*)res->At(shift+kBgDist+kMCShift);
648 TH1* mcdstbgLB = (TH1*)res->At(shift+kBgMCDist+kMCShift);
649 TH1* dtdst = (TH1*)res->At(shift+kDataDist);
650 TH1* dtdstbg = (TH1*)res->At(shift+kBgDist);
651 //
652 TH1* mcDstN = (TH1*)FindObject(bin,HName("Data", useShapeType==kNormShapeDist ? "WDist":"DPhiS"), listMC );
653 TH1* mcDstSec = (TH1*)FindObject(bin,HName("Sec", useShapeType==kNormShapeDist ? "WDist":"DPhiS"), listMC );
654 TH1* mcDstCombU = (TH1*)FindObject(bin,HName("CombU",useShapeType==kNormShapeDist ? "WDist":"DPhiS"), listMC );
655 TH1* mcDstCombC = (TH1*)FindObject(bin,HName("Comb", useShapeType==kNormShapeDist ? "WDist":"DPhiS"), listMC );
656 //
657 double scl,sclE;
658 mcDstN = NormalizeBg(mcdst,mcDstN,scl,sclE);
659 mcDstSec->Scale(scl);
660 mcDstCombU->Scale(scl);
661 mcDstCombC->Scale(scl);
662 mcDstCombC->Add(mcDstCombU,-1);
663
664 dtdst->Draw("");
665 gPad->Modified();
666 dtdst->GetXaxis()->SetLabelSize(0.03);
667 dtdst->GetXaxis()->SetTitleSize(0.03);
668 dtdst->GetXaxis()->SetTitleOffset(2);
669 dtdstbg->Draw("same");
670 //
671 mcdst->Draw("same");
672 mcDstSec->Draw("same");
673 mcdstbgLB->Draw("same");
674 mcdstbg->Draw("same");
675 mcDstCombC->Draw("same");
676 //
677
678 SetHStyle(mcdst,kBlue, 25,0.7);
679 SetHStyle(mcdstbgLB,kGreen, 7/*32*/,0.5);
680 SetHStyle(mcdstbg,kCyan, 7/*26*/,0.5);
681 SetHStyle(mcDstCombC,kGreen+2, 21,0.7);
682 SetHStyle(mcDstSec,kBlue+2, 22,0.7);
683 //
684 SetHStyle(dtdst,kRed, 20,0.7);
685 SetHStyle(dtdstbg,kBlue, 34,0.7);
686 //
687 double vmcTot,vmcTotE;
688 double vmcSec,vmcSecE, ratSec,ratSecE;
689 double vmcCmbEst,vmcCmbEstE, ratCmbEst,ratCmbEstE;
690 double vmcCmb,vmcCmbE, ratCmb,ratCmbE;
691 double vmcCmbC,vmcCmbCE, ratCmbC,ratCmbCE;
692 double cutSgMin,cutSgMax;
693 double cutBgMin,cutBgMax;
694 if (useShapeType==kNormShapeDist) {
695 cutSgMin = 0;
696 cutSgMax = kWDistSgCut;
697 cutBgMin = kWDistBgTailMin;
698 cutBgMax = kWDistBgTailMax;
699 }
700 else {
701 cutSgMin = 0;
702 cutSgMax = kdPhiSgCut;
703 cutBgMin = kdPhiBgTailMin;
704 cutBgMax = kdPhiBgTailMax;
705 }
706 Integrate(mcdst, cutSgMin,cutSgMax, vmcTot,vmcTotE);
707 Integrate(mcDstSec, cutSgMin,cutSgMax, vmcSec,vmcSecE);
708 GetRatE(vmcSec,vmcSecE, vmcTot,vmcTotE, ratSec,ratSecE);
709 //
710 Integrate(mcdstbgLB, cutSgMin,cutSgMax, vmcCmb,vmcCmbE);
711 GetRatE(vmcCmb,vmcCmbE, vmcTot,vmcTotE, ratCmb,ratCmbE);
712 //
713 Integrate(mcdstbg, cutSgMin,cutSgMax, vmcCmbEst,vmcCmbEstE);
714 GetRatE(vmcCmbEst,vmcCmbEstE, vmcTot,vmcTotE, ratCmbEst,ratCmbEstE);
715 //
716 Integrate(mcDstCombC, cutSgMin,cutSgMax, vmcCmbC,vmcCmbCE);
717 GetRatE(vmcCmbC,vmcCmbCE, vmcTot,vmcTotE, ratCmbC,ratCmbCE);
718 //
719 double vdtTot,vdtTotE;
720 double vdtBg,vdtBgE, ratdtBg,ratdtBgE;
721 //
722 Integrate(dtdst, cutSgMin,cutSgMax, vdtTot,vdtTotE);
723 Integrate(dtdstbg, cutSgMin,cutSgMax, vdtBg,vdtBgE);
724 GetRatE( vdtBg,vdtBgE, vdtTot,vdtTotE, ratdtBg,ratdtBgE);
725 //
726 //
727 double dmn = mcdst->GetMinimum();
728 double dmx = mcdst->GetMaximum();
729 TLine *ln = new TLine(cutSgMax, dmn, cutSgMax, dmx);
730 ln->SetLineColor(kBlack);
731 ln->Draw();
732 TLine *lnc = new TLine(cutBgMin, dmn, cutBgMin, dmx);
733 lnc->SetLineColor(kRed);
734 lnc->Draw();
735 if (useShapeType==kNormShapeDPhi) {
736 ln = new TLine(-cutSgMax, dmn, -cutSgMax, dmx);
737 ln->SetLineColor(kBlack);
738 ln->Draw();
739 //
740 lnc = new TLine(-cutBgMin, dmn, -cutBgMin, dmx);
741 lnc->SetLineColor(kRed);
742 lnc->Draw();
743 }
744 //
745 TLegend *legDstMC1 = new TLegend(0.60,0.72, 0.95,0.95);
746 legDstMC1->SetFillColor(kWhite);
747
748 //
749 legDstMC1->AddEntry(dtdst, "Data raw","pl");
750 sprintf(buff,"Data Comb. %s. : %.1f%%",useBgType.Data(),ratdtBg*100);
751 legDstMC1->AddEntry(dtdstbg, buff,"pl");
752 //
753
754
755 legDstMC1->AddEntry(mcdst, "MC raw","pl");
756 sprintf(buff,"MC Comb. %s. : %.1f%%",useBgType.Data(),ratCmbEst*100);
757 legDstMC1->AddEntry(mcdstbg, buff,"pl");
758 //
759 sprintf(buff,"MC Comb. %s. : %.1f%%","MC Lbl.",ratCmb*100);
760 legDstMC1->AddEntry(mcdstbgLB, buff,"pl");
761
762 sprintf(buff,"MC Comb.Uncorr %s. : %.1f%%","MC Lbl.",ratCmbC*100);
763 legDstMC1->AddEntry(mcDstCombC, buff,"pl");
764
765 sprintf(buff,"MC Sec. : %.1f%%",ratSec*100);
766 legDstMC1->AddEntry(mcDstSec, buff,"pl");
767
768 legDstMC1->Draw();
769
770 if (useShapeType==kNormShapeDist) gPad->SetLogx();
771 gPad->SetLogy();
772 gPad->SetGrid(1,1);
773 gPad->Modified();
774 //
775 canvFin->cd();
776 //
777 if (creatDnDEtaCMacro) {
778 sprintf(buff,"%s/%s_b%d_dNdEta_%s",figDir,uniqueName.Data(),bin,outStr);
779 SaveCanvas(canvFin,buff,"cg");
780 }
781 //
782}
783//
784void PlotAlphaBeta(int bin)
785{
786 char buff[1000];
787 int shift = bin*kNHistos;
788 gStyle->SetOptFit(0);
789 gStyle->SetOptStat(0);
790 gStyle->SetOptTitle(0);
791 TObjArray* res = &resArr;
792 //------------------------------------------------------
793 if (!canvFin) canvFin = new TCanvas("canvFin","canvFin",10,10,700,1000);
794 canvFin->Clear();
795 canvFin->Divide(2,3,0.01,0.01);
796 canvFin->cd(1);
797 TH1* dtBet = (TH1*)res->At(shift + k1MBeta);
798 TH1* mcBet = (TH1*)res->At(shift + k1MBeta+kMCShift);
799 TH1* mcBetLB = (TH1*)res->At(shift + k1MBetaMC+kMCShift);
800 double mn,mx,mnt,mxt;
801 GetRealMinMax(dtBet,mn,mx);
802 GetRealMinMax(mcBet,mnt,mxt);
803 if (mnt<mn) mn = mnt;
804 if (mxt>mx) mx = mxt;
805 GetRealMinMax(mcBetLB,mnt,mxt);
806 if (mnt<mn) mn = mnt;
807 if (mxt>mx) mx = mxt;
808 //
809 dtBet->SetMinimum(mn - 0.05*(mx-mn));
810 dtBet->SetMaximum(mx + 0.05*(mx-mn));
811 mcBet->SetMinimum(mn - 0.05*(mx-mn));
812 mcBet->SetMaximum(mx + 0.05*(mx-mn));
813 mcBetLB->SetMinimum(mn - 0.05*(mx-mn));
814 mcBetLB->SetMaximum(mx + 0.05*(mx-mn));
815 //
816 canvFin->cd(1);
817 gPad->SetRightMargin(0.15);
818 dtBet->Draw("colz");
6c56e693 819 AddLabel("#beta Data",0.2,0.95,kBlack,0.04);
a9a39f46 820 gPad->Modified();
821 dtBet->GetYaxis()->SetTitleOffset(1.4);
822 TPaletteAxis *p = (TPaletteAxis*)dtBet->FindObject("palette");
823 if (p) p->SetX1NDC(0.85);
824 canvFin->cd(2);
825 gPad->SetRightMargin(0.15);
826 mcBet->Draw("colz");
6c56e693 827 AddLabel("#beta MC (bckg.estimated)",0.2,0.95,kBlack,0.04);
a9a39f46 828 gPad->Modified();
829 mcBet->GetYaxis()->SetTitleOffset(1.4);
830 p = (TPaletteAxis*)mcBet->FindObject("palette");
831 if (p) p->SetX1NDC(0.85);
832 canvFin->cd(3);
833 gPad->SetRightMargin(0.15);
834 mcBetLB->Draw("colz");
6c56e693 835 AddLabel("#beta MC (bckg.from MC labels)",0.2,0.95,kBlack,0.04);
a9a39f46 836 gPad->Modified();
837 mcBetLB->GetYaxis()->SetTitleOffset(1.4);
838 p = (TPaletteAxis*)mcBetLB->FindObject("palette");
839 if (p) p->SetX1NDC(0.85);
840 //
841 //------------------------------------------------------
842 TH1* dtAlp = (TH1*)res->At(shift + kAlpha);
843 TH1* mcAlp = (TH1*)res->At(shift + kAlphaMC);
844 GetRealMinMax(dtAlp,mn,mx);
845 GetRealMinMax(mcAlp,mnt,mxt);
846 if (mnt<mn) mn = mnt;
847 if (mxt>mx) mx = mxt;
848 dtAlp->SetMinimum(mn - 0.05*(mx-mn));
849 dtAlp->SetMaximum(mx + 0.05*(mx-mn));
850 mcAlp->SetMinimum(mn - 0.05*(mx-mn));
851 mcAlp->SetMaximum(mx + 0.05*(mx-mn));
852 //
853 canvFin->cd(4);
854 gPad->SetRightMargin(0.15);
855 dtAlp->Draw("colz");
6c56e693 856 AddLabel("#alpha (bckg.estimated)",0.2,0.95,kBlack,0.04);
a9a39f46 857 gPad->Modified();
858 dtAlp->GetYaxis()->SetTitleOffset(1.4);
859 TPaletteAxis *pa = (TPaletteAxis*)dtBet->FindObject("palette");
860 if (pa) pa->SetX1NDC(0.85);
861 canvFin->cd(5);
862 gPad->SetRightMargin(0.15);
863 mcAlp->Draw("colz");
6c56e693 864 AddLabel("#alpha (bckg.from MC labels)",0.2,0.95,kBlack,0.04);
a9a39f46 865 gPad->Modified();
866 mcAlp->GetYaxis()->SetTitleOffset(1.4);
867 pa = (TPaletteAxis*)mcBet->FindObject("palette");
868 if (pa) pa->SetX1NDC(0.85);
869 gPad->Modified();
870 canvFin->cd(6);
6c56e693 871 AddLabel(outTitle,0.1,0.5, kBlack, 0.02);
a9a39f46 872 //
873 if (creatAlphaBetaCMacro) {
874 sprintf(buff,"%s/%sAlphaBeta_%s",figDir,uniqueName.Data(),outStr);
875 SaveCanvas(canvFin,buff,"cg");
876 }
877 //
878}
879
880void PlotSpecies()
881{
882 char buff[1000];
883 gStyle->SetOptFit(0);
884 gStyle->SetOptStat(0);
885 gStyle->SetOptTitle(0);
886 //------------------------------------------------------
887 TH2F* hSpecPrim = (TH2F*)FindObject(-1, "pdgPrim", listMC,kFALSE);
888 TH2F* hSpecSec = (TH2F*)FindObject(-1, "pdgSec", listMC,kFALSE);
889 TH2F* hSpecPrimP = (TH2F*)FindObject(-1, "pdgPrimPar", listMC,kFALSE);
890 TH2F* hSpecSecP = (TH2F*)FindObject(-1, "pdgSecPar", listMC,kFALSE);
891 int nbd = hSpecPrim->GetXaxis()->GetNbins();
892 //
893 TH1* hSpecPrimAll = hSpecPrim->ProjectionX("specPrimAll",1,nbd+1,"e");
894 hSpecPrimAll->Scale(100./hSpecPrimAll->Integral());
895 hSpecPrimAll->GetYaxis()->SetTitle("Fraction,%");
896 hSpecPrimAll->GetXaxis()->SetLabelSize(0.06);
897 hSpecPrimAll->GetXaxis()->LabelsOption("v");
898 //
899 TH1* hSpecSecAll = hSpecSec->ProjectionX("specSecAll",1,nbd+1,"e");
900 hSpecSecAll->Scale(100./hSpecSecAll->Integral());
901 hSpecSecAll->GetYaxis()->SetTitle("Fraction,%");
902 hSpecSecAll->GetXaxis()->SetLabelSize(0.05);
903 //
904 TH1* hSpecPrimPAll = hSpecPrimP->ProjectionX("specPrimPAll",1,nbd+1,"e");
905 hSpecPrimPAll->Scale(100./hSpecPrimPAll->Integral());
906 hSpecPrimPAll->GetYaxis()->SetTitle("Fraction,%");
907 hSpecPrimPAll->GetXaxis()->SetLabelSize(0.06);
908 hSpecPrimPAll->GetXaxis()->LabelsOption("v");
909
910 //
911 TH1* hSpecSecPAll = hSpecSecP->ProjectionX("specSecPAll",1,nbd+1,"e");
912 hSpecSecPAll->Scale(100./hSpecSecPAll->Integral());
913 hSpecSecPAll->GetYaxis()->SetTitle("Fraction,%");
914 hSpecSecPAll->GetXaxis()->SetLabelSize(0.05);
915 //
916 int binCut = hSpecPrim->GetXaxis()->FindBin(kWDistSgCut-kEps);
917 TH1* hSpecPrimSel = hSpecPrim->ProjectionX("specPrimSel",1,binCut,"e");
918 hSpecPrimSel->Scale(100./hSpecPrimSel->Integral());
919 hSpecPrimSel->GetYaxis()->SetTitle("Fraction,%");
920 hSpecPrimSel->GetXaxis()->SetLabelSize(0.05);
921 //
922 TH1* hSpecSecSel = hSpecSec->ProjectionX("specSecSel",1,binCut,"e");
923 hSpecSecSel->Scale(100./hSpecSecSel->Integral());
924 hSpecSecSel->GetYaxis()->SetTitle("Fraction,%");
925 hSpecSecSel->GetXaxis()->SetLabelSize(0.05);
926 //
927 TH1* hSpecPrimPSel = hSpecPrimP->ProjectionX("specPrimPSel",1,binCut,"e");
928 hSpecPrimPSel->Scale(100./hSpecPrimPSel->Integral());
929 hSpecPrimPSel->GetYaxis()->SetTitle("Fraction,%");
930 hSpecPrimPSel->GetXaxis()->SetLabelSize(0.05);
931 //
932 TH1* hSpecSecPSel = hSpecSecP->ProjectionX("specSecPSel",1,binCut,"e");
933 hSpecSecPSel->Scale(100./hSpecSecPSel->Integral());
934 hSpecSecPSel->GetYaxis()->SetTitle("Fraction,%");
935 hSpecSecPSel->GetXaxis()->SetLabelSize(0.05);
936 //
937 if (!canvFin) canvFin = new TCanvas("canvFin","canvFin",10,10,1100,800);
938 canvFin->Clear();
939 canvFin->Divide(1,2,0.01,0.01);
940 canvFin->cd(1);
941 hSpecPrimAll->Draw();
942 SetHStyle(hSpecPrimAll,kBlue,25,1.1);
943 hSpecPrimSel->Draw("same");
944 SetHStyle(hSpecPrimSel,kRed,20,1);
945 //
946 hSpecSecAll->Draw("same");
947 SetHStyle(hSpecSecAll,kGreen,32,1.1);
948 hSpecSecSel->Draw("same");
949 SetHStyle(hSpecSecSel,kBlack,22,1);
950 //
951 TLegend *legPart = new TLegend(0.8,0.72, 0.999,0.999);
952 legPart->SetFillColor(kWhite);
953 legPart->SetHeader("Tracklet PDG");
954 //
955 legPart->AddEntry(hSpecPrimAll, "Prim., before #Delta cut","pl");
956 legPart->AddEntry(hSpecPrimSel, "Prim., after #Delta cut","pl");
957 legPart->AddEntry(hSpecSecAll, "Sec., before #Delta cut","pl");
958 legPart->AddEntry(hSpecSecSel, "Sec., after #Delta cut","pl");
959 //
960 legPart->Draw();
961 gPad->SetLogy();
962 gPad->SetGrid(1,1);
963 gPad->Modified();
964 //
965 canvFin->cd(2);
966 hSpecPrimPAll->Draw();
967 SetHStyle(hSpecPrimPAll,kBlue,25,1.1);
968 hSpecPrimPSel->Draw("same");
969 SetHStyle(hSpecPrimPSel,kRed,20,1);
970 //
971 hSpecSecPAll->Draw("same");
972 SetHStyle(hSpecSecPAll,kGreen,32,1.1);
973 hSpecSecPSel->Draw("same");
974 SetHStyle(hSpecSecPSel,kBlack,22,1);
975 //
976 TLegend *legPartP = new TLegend(0.8,0.72, 0.999,0.999);
977 legPartP->SetFillColor(kWhite);
978 legPartP->SetHeader("Tracklet Parents PDG");
979 //
980 legPartP->AddEntry(hSpecPrimPAll, "Prim., before #Delta cut","pl");
981 legPartP->AddEntry(hSpecPrimPSel, "Prim., after #Delta cut","pl");
982 legPartP->AddEntry(hSpecSecPAll, "Sec., before #Delta cut","pl");
983 legPartP->AddEntry(hSpecSecPSel, "Sec., after #Delta cut","pl");
984 //
985 legPartP->Draw();
986 gPad->SetLogy();
987 gPad->SetGrid(1,1);
988 gPad->Modified();
989 //
990 canvFin->cd(1);
6c56e693 991 // AddLabel(outTitle,0.1,0.97, kBlack, 0.02);
a9a39f46 992 canvFin->cd();
993 //
994 if (creatSpeciesCMacro) {
995 sprintf(buff,"%s/%sSpecies_%s",figDir,uniqueName.Data(),outStr);
996 SaveCanvas(canvFin,buff,"cg");
997 }
998}
999
1000//______________________________________________________________________
1001void CropHisto(TH1* histo, int bx0, int bx1, int by0, int by1)
1002{
1003 // fill 0 to all bins outside defined range
1004 TAxis *xax = histo->GetXaxis();
1005 int nbx = xax->GetNbins();
1006 double vmn=1e16,vmx=-1e16;
1007 if (histo->InheritsFrom(TH2::Class())) {
1008 TAxis *yax = histo->GetYaxis();
1009 int nby = yax->GetNbins();
1010 for (int ix=nbx+2;ix--;) {
1011 for (int iy=nby+2;iy--;) {
1012 if ((ix<bx0||ix>bx1)||(iy<by0||iy>by1)) {
1013 histo->SetBinContent(ix,iy,0);
1014 histo->SetBinError(ix,iy,0);
1015 }
1016 else {
1017 double vl = histo->GetBinContent(ix,iy);
1018 if (vl<vmn) vmn = vl;
1019 if (vl>vmx) vmx = vl;
1020 }
1021 }
1022 }
1023 }
1024 else {
1025 for (int ix=nbx+2;ix--;) {
1026 if ((ix<bx0||ix>bx1)) {
1027 histo->SetBinContent(ix,0);
1028 histo->SetBinError(ix,0);
1029 }
1030 else {
1031 double vl = histo->GetBinContent(ix);
1032 if (vl<vmn) vmn = vl;
1033 if (vl>vmx) vmx = vl;
1034 }
1035 }
1036 }
1037 //
1038 if (vmn==vmx) {
1039 vmn = 0.95*vmn;
1040 vmx = 1.05*vmx;
1041 }
1042 histo->SetMaximum(vmx);
1043 histo->SetMinimum(vmn);
1044}
1045
1046//______________________________________________________________________
1047void CropHisto(TH1* histo, double vx0, double vx1, double vy0, double vy1)
1048{
1049 // fill 0 to all bins outside defined range
1050 TAxis *xax = histo->GetXaxis();
1051 int bx0,bx1,by0=-1,by1=-1;
1052 bx0 = xax->FindBin(vx0+kEps);
1053 bx1 = xax->FindBin(vx1-kEps);
1054 if (histo->InheritsFrom(TH2::Class())) {
1055 TAxis *yax = histo->GetYaxis();
1056 by0 = yax->FindBin(vy0+kEps);
1057 by1 = yax->FindBin(vy1-kEps);
1058 }
1059 CropHisto(histo,bx0,bx1,by0,by1);
1060}
1061
1062//______________________________________________________________________
1063TH1* NormalizeBg(TH1* dataH, TH1* bgH, double &scl, double &sclE)
1064{
1065 // match generated bg and data tails, calculate normalization, return normalized bg copy
1066 //
1067 TAxis* xax = dataH->GetXaxis();
1068 int nbtot = xax->GetNbins();
1069 int bgBins[2][2] = {{0}}; // limiting bins for tails integration
1070 Int_t ntails; // 0 for dphi plot, 1 for weighted dist plot
1071 if (useShapeType == kNormShapeDist) { // only positive tail
1072 bgBins[0][0] = xax->FindBin(kWDistBgTailMin+kEps); // positive tail min bin
1073 bgBins[0][1] = xax->FindBin(kWDistBgTailMax-kEps); // positive tail max bin
1074 ntails = 1;
1075 }
1076 else if (useShapeType == kNormShapeDPhi) { // both tails
1077 bgBins[0][0] = xax->FindBin( kdPhiBgTailMin+kEps); // positive tail min bin
1078 bgBins[0][1] = xax->FindBin( kdPhiBgTailMax-kEps); // positive tail max bin
1079 bgBins[1][0] = xax->FindBin(-kdPhiBgTailMax+kEps); // negative tail min bin
1080 bgBins[1][1] = xax->FindBin(-kdPhiBgTailMin-kEps); // positive tail max bin
1081 ntails = 2;
1082 }
1083 else {printf("NormalizeBg: unknown shape type %d\n",useShapeType);exit(1);}
1084 printf("NormalizeBg: bins for tails: right: %d:%d / left: %d:%d\n",bgBins[0][0],bgBins[0][1],bgBins[1][0],bgBins[1][1]);
1085 //
1086 double meanR=0,meanRE=0,meanRE2=0;
1087 double meanD=0,meanDE2=0;
1088 double meanB=0,meanBE2=0;
1089 double meanRI=0,meanRIE=0;
1090 for (int itp=0;itp<=ntails;itp++) {
1091 for (int ib=bgBins[itp][0];ib<=bgBins[itp][1];ib++) {
1092 if (ib<1||ib>nbtot) continue;
1093 double vD = dataH->GetBinContent(ib);
1094 double vB = bgH->GetBinContent(ib);
1095 double eD = dataH->GetBinError(ib);
1096 double eB = bgH->GetBinError(ib);
1097 meanD += vD; meanDE2 += eD*eD;
1098 meanB += vB; meanBE2 += eB*eB;
1099 if (vD<=0 || vB<=0 || eD<=0 || eB<=0) continue;
1100 double rat = vD/vB;
1101 double ratE2 = rat*rat*(eD*eD/vD/vD + eB*eB/vB/vB);
1102 meanR += rat/ratE2; meanRE2 += 1.0/ratE2;
1103 }
1104 }
1105 //
1106 if (meanRE2>0) {
1107 meanR /= meanRE2;
1108 meanRE2 = 1./meanRE2;
1109 meanRE = TMath::Sqrt(meanRE2);
1110 }
1111 if (meanDE2>0 && meanBE2>0) {
1112 meanRI = meanD/meanB;
1113 meanRIE = meanRI*TMath::Sqrt(meanDE2/meanD/meanD + meanBE2/meanB/meanB);
1114 }
1115 printf("NormalizeBg: Tails scaling %s wrt %s: Wgh.Mean:%.4f(%.4f) / Integral:%.4f(%.4f)\n",
1116 bgH->GetName(),dataH->GetName(), meanR,meanRE, meanRI,meanRIE);
1117 printf("NormalizeBg: Select scaling type %s\n",useScaleType==kSclWghMean ? "Wgh.Mean":"Integral");
1118 //
1119 scl = useScaleType==kSclWghMean ? meanR : meanRI;
1120 sclE = useScaleType==kSclWghMean ? meanRE : meanRIE;
1121 //
1122 // rescaled bg
1123 char buff[1000];
1124 sprintf(buff,"%s_bgNorm",bgH->GetName());
1125 bgH = (TH1*)bgH->Clone(buff);
1126 sprintf(buff,"%s bgNorm%d %.4f+-%.4f",bgH->GetName(),useScaleType,scl,sclE);
1127 TH1* dumH = (TH1*)bgH->Clone("dummySCL$"); dumH->Reset();
1128 for (int i=1;i<=nbtot;i++) {
1129 dumH->SetBinContent(i,scl);
1130 dumH->SetBinError(i,sclE);
1131 }
1132 bgH->Multiply(dumH);
1133 delete dumH;
1134 return bgH;
1135}
1136
1137//______________________________________________________________________
1138TObject* FindObject(int bin, const char* nameH, const TList* lst, Bool_t normPerEvent)
1139{
1140 // get histo, optionally normalizing it per processed event
1141 if (!lst) {printf("FindObject %s: No list provided\n",nameH); exit(1);}
1142 int nent = lst->GetEntries();
1143 //
1144 char buff[200];
1145 if (bin>=0) sprintf(buff,"b%d_%s",bin,nameH);
1146 else sprintf(buff,"%s",nameH);
1147 TString nm;
1148 TObject *hst = 0;
1149 for (int i=nent;i--;) {
1150 nm = lst->At(i)->GetName();
1151 if (nm.EndsWith(buff)) {hst = lst->At(i); break;}
1152 }
1153 if (!hst) {printf("FindObject: No bin %d %s histo in list %s\n",bin,nameH,lst->GetName()); exit(1);}
1154 if (!normPerEvent || hst->TestBit(kBitNormPerEvent)) return hst; // already normalized
1155 TString nameHS = nameH;
1156 if (nameHS==kHStatName) return hst; // never scale stat. histo
1157 //
1158 TH1* hstat = (TH1*)FindObject(-1,kHStatName,lst,kFALSE);
1159 double nrm = hstat->GetBinContent(kBinEntries + kEvProcInj+bin*kEntriesPerBin);
1160 // double nrm = hstat->GetBinContent(kBinEntries + kEvProcData+bin*kEntriesPerBin); // HACK
1161 if (nrm<1) {printf("FindObject %s: Anomaluous %d number of events processed in bin %d of list %p\n",
1162 buff,int(nrm),bin,lst); return 0;}
1163 //
1164 if (hst->InheritsFrom(TH1::Class())) ((TH1*)hst)->Scale(1./nrm);
1165 else if (hst->InheritsFrom(THnSparse::Class())) {
1166 THnSparse* spr = (THnSparse*) hst;
1167 spr->Sumw2();
1168 int coord[3] = {0,0,0};
1169 for (Long64_t i = 0; i < spr->GetNbins(); ++i) {
1170 // Get the content of the bin from the current histogram
1171 Double_t v = spr->GetBinContent(i, coord);
1172 spr->SetBinContent(coord, v/nrm);
1173 spr->SetBinError(coord,TMath::Sqrt(v)/nrm);
1174 }
1175 }
1176 //
1177 hst->SetBit(kBitNormPerEvent);
1178 return hst;
1179}
1180
1181//______________________________________________________________________
1182TList* LoadList(const char* flName, const char* addPref, const char* nameL)
1183{
1184 // load list with histos
1185 TString nms = flName;
1186 gSystem->ExpandPathName(nms);
1187 TFile* fl = TFile::Open(nms.Data());
1188 if (!fl) {printf("LoadList: No file %s\n",nms.Data()); exit(1);}
1189 TList* lst = (TList*)fl->Get(nameL);
1190 if (!lst) {printf("LoadList: No list %s in file %s\n",nameL,nms.Data()); exit(1);}
1191 lst->SetName(flName);
1192 //
1193 int nEnt = lst->GetSize();
1194 TString nm;
1195 for (int i=0;i<nEnt;i++) {
1196 TNamed* ob = (TNamed*)lst->At(i);
1197 nm = addPref;
1198 nm += ob->GetName();
1199 ob->SetName(nm.Data());
1200 }
1201 //
1202 return lst;
1203}
1204
1205//____________________________________________________________________________
1206void GetRatE(double x,double xe, double y,double ye, double &rat, double &rate)
1207{
1208 rat = 0; rate = 0;
1209 if (TMath::Abs(y)<1e-16 || TMath::Abs(x)<1e-16) return;
1210 rat = x/y;
1211 rate = rat*TMath::Sqrt( xe*xe/(x*x) + ye*ye/(y*y));
1212}
1213
1214//____________________________________________________________________________
1215void Integrate(TH1* hist, double xmn,double xmx, double &val, double& err)
1216{
1217 // integrate 1d histo within given limits
1218 TAxis* xax = hist->GetXaxis();
1219 int bmn = xax->FindBin(xmn+kEps); if (bmn<1) bmn = 0; // include
1220 int bmx = xax->FindBin(xmx-kEps);
1221 val = hist->IntegralAndError(bmn,bmx,err);
1222 // is this histo with symmetric axis ? then integrate also negative half axis
1223 if (TMath::Abs( xax->GetXmin() + xax->GetXmax() )<1e-6) {
1224 bmn = xax->FindBin(-xmx+kEps);
1225 bmx = xax->FindBin(-xmn-kEps);
1226 double errn;
1227 val += hist->IntegralAndError(bmn,bmx,errn);
1228 err = TMath::Sqrt(err*err + errn*errn);
1229 }
1230}
1231
1232
1233//____________________________________________________________________________
1234const char* HName(const char* prefix,const char* htype)
1235{
1236 // compose the name of histo in the clist
1237 static TString strh;
1238 strh = "Tr"; strh += prefix; strh += "_"; strh += htype;
1239 return strh.Data();
1240}
1241
1242//____________________________________________________________________________
1243Int_t CheckStat(const TList* lst, const char* dtType)
1244{
1245 // check if needed bg was generated
1246 TH1* hstat = (TH1*)FindObject(-1,kHStatName,lst);
1247 TString dts = dtType;
1248 if (dts=="Data") return int( hstat->GetBinContent(kEvProcData) );
1249 if (dts=="Mix") return int( hstat->GetBinContent(kEvProcMix) );
1250 if (dts=="Inj") return int( hstat->GetBinContent(kEvProcInj) );
1251 if (dts=="Rot") return int( hstat->GetBinContent(kEvProcRot) );
1252 printf("Unknown process %s statistics is checked. Alowed: Data,Mix,Inj,Rot",dtType);
1253 return 0;
1254}
1255
1256
1257void GetRealMinMax(TH1* histo, double &vmn, double &vmx)
1258{
1259 TAxis *xax = histo->GetXaxis();
1260 int nbx = xax->GetNbins();
1261 vmn=1e6, vmx=-1e6;
1262 if (histo->InheritsFrom(TH2::Class())) {
1263 TAxis *yax = histo->GetYaxis();
1264 int nby = yax->GetNbins();
1265 for (int ix=nbx+2;ix--;) {
1266 for (int iy=nby+2;iy--;) {
1267 double vl = histo->GetBinContent(ix,iy);
1268 if (vl<kEps) continue;
1269 if (vl<vmn) vmn = vl;
1270 if (vl>vmx) vmx = vl;
1271 }
1272 }
1273 }
1274 //
1275 else {
1276 for (int ix=nbx+2;ix--;) {
1277 double vl = histo->GetBinContent(ix);
1278 if (vl<vmn) vmn = vl;
1279 if (vl>vmx) vmx = vl;
1280 }
1281 }
1282 //
1283}