29 #include "TEfficiency.h" 31 #include "TDirectory.h" 41 TString filetype, TString namestyle, TString dir,
bool doRatio,
bool showcuts){
43 TString outfolder(
"plots/"+dir);
44 gSystem->mkdir(outfolder, kTRUE);
47 if(namestyle.Contains(
"_Supplementary")) {
48 CMStype =
"Supplementary";
49 namestyle.ReplaceAll(
"_Supplementary",
"");
51 if(namestyle.Contains(
"_Preliminary")) {
52 CMStype =
"Preliminary";
53 namestyle.ReplaceAll(
"_Preliminary",
"");
56 if (doRatio) namestyle =
"CMSPaper";
58 if(namestyle.Contains(
"CMSPaper")) style.
nDivisions = 706;
70 TPad *pad(NULL), *bpad(NULL);
72 float bpadHeight = 0.3;
73 pad =
new TPad(
"tpad",
"tpad",0.,bpadHeight,1.,1.);
74 pad->SetBottomMargin(0.02);
77 bpad =
new TPad(
"bpad",
"bpad",0.,0.,1.,bpadHeight+0.005);
78 bpad->SetTopMargin(0.);
80 bpad->SetFillStyle(4000);
83 pad =
static_cast<TPad *
>(can.cd());
87 vector<TChain *> chain;
88 for(
unsigned sam(0); sam < Samples.size(); sam++){
89 chain.push_back(
new TChain(
"tree"));
90 for(
unsigned insam(0); insam < Samples[sam].file.size(); insam++){
92 chain[sam]->Add(Samples[sam].
file[insam]);
97 TString lumi_nodot =
luminosity; lumi_nodot.ReplaceAll(
".",
"p");
98 TString plot_tag(
"_lumi"+lumi_nodot+filetype);
99 float minLog = 0.04, fracLeg = 0.36;
102 double legY(1-style.
PadTopMargin-0.027), legSingle = 0.052;
103 if (doRatio) {legY=1-style.
PadTopMargin-0.041; legSingle = 0.06;}
104 double legW = 0.13, legH = legSingle*(vars[0].samples.size()+1)/2;
105 double legX1[] = {legLeft, legLeft+(legRight-legLeft)/2.*1.15};
106 TLegend
leg[2];
int nLegs(2);
107 for(
int ileg(0); ileg<nLegs; ileg++){
108 leg[ileg].SetX1NDC(legX1[ileg]); leg[ileg].SetX2NDC(legX1[ileg]+legW);
109 leg[ileg].SetY1NDC(legY-legH); leg[ileg].SetY2NDC(legY);
110 leg[ileg].SetTextSize(style.
LegendSize); leg[ileg].SetFillColor(0);
111 leg[ileg].SetFillStyle(0); leg[ileg].SetBorderSize(0);
112 leg[ileg].SetTextFont(style.
nFont);
114 TLine line; line.SetLineColor(1); line.SetLineWidth(5); line.SetLineStyle(2);
115 vector< vector<TH1D*> > histo[2];
116 vector<TH1D*> varhisto;
117 vector<float> nentries;
118 TString hname, pname, variable, samVariable, leghisto, totCut, title, ytitle, lumilabel, cmslabel;
119 for(
unsigned var(0); var<vars.size(); var++){
120 bool variableBins = vars[var].minx == -1;
121 if (vars[var].minx == -1) vars[var].minx = vars[var].binning[0];
122 const unsigned Nsam(vars[var].samples.size());
123 legH = (Nsam<=3?legSingle*Nsam:legSingle*(Nsam+1)/2);
126 for(
int ileg(0); ileg<nLegs; ileg++) leg[ileg].SetY1NDC(legY-legH);
127 leg[1].SetX1NDC(legX1[1]+vars[var].moveRLegend); leg[1].SetX2NDC(legX1[1]+legW+vars[var].moveRLegend);
131 bool someBands =
false;
134 if(namestyle.Contains(
"CMSPaper") && !showcuts) title =
"";
135 for(
unsigned his(0); his < 2; his++){
137 for(
unsigned sam(0); sam < Nsam; sam++){
138 if(Samples[vars[var].samples[sam]].doBand) someBands =
true;
139 hname =
"histo"; hname += var; hname += his; hname += sam;
140 delete gROOT->FindObject(hname);
142 vars[var].minx = vars[var].binning[0];
143 varhisto.push_back(
new TH1D(hname, title, vars[var].
nbins, vars[var].binning));
145 varhisto.push_back(
new TH1D(hname, title, vars[var].
nbins, vars[var].minx, vars[var].maxx));
148 histo[his].push_back(varhisto);
150 nentries.resize(Nsam);
151 variable = vars[var].varname;
152 float maxhisto(-999);
154 for(
unsigned sam(Nsam-1); sam < Nsam; sam--){
155 int isam = vars[var].samples[sam];
156 if(!Samples[isam].isSig && !Samples[isam].isData) nbkg++;
157 samVariable = Samples[isam].samVariable;
158 totCut = Samples[isam].factor+
"*"+luminosity+
"*weight*("+vars[var].cuts+
"&&"+Samples[isam].cut+
")";
159 if(Samples[isam].isData) totCut= vars[var].cuts+
"&&"+Samples[isam].cut;
160 if(vars[var].PU_reweight && !Samples[isam].isData) totCut = Samples[isam].factor+
"*"+luminosity+
"*weight*wpu*("+vars[var].cuts+
"&&"+Samples[isam].cut+
")";
163 histo[0][var][sam]->SetBinErrorOption(TH1::kPoisson);
164 if(samVariable==
"noPlot") chain[isam]->Project(histo[0][var][sam]->GetName(), variable, totCut);
165 else chain[isam]->Project(histo[0][var][sam]->GetName(), samVariable, totCut);
166 if(vars[var].addOverflow)
167 histo[0][var][sam]->SetBinContent(vars[var].
nbins,
168 histo[0][var][sam]->GetBinContent(vars[var].nbins)+
169 histo[0][var][sam]->GetBinContent(vars[var].nbins+1));
172 nentries[sam] = histo[0][var][sam]->Integral(1,vars[var].nbins);
173 if(nentries[sam]<0) nentries[sam]=0;
176 if(!namestyle.Contains(
"CMSPaper") || showcuts) {
182 lumilabel = TString::Format(
"#scale[0.8]{13 TeV}");
183 cmslabel =
"#font[62]{CMS} #scale[0.8]{#font[52]{Simulation}}";
184 if(CMStype==
"Supplementary")cmslabel =
"#scale[0.8]{#font[62]{CMS}} #scale[0.6]{#font[52]{Supplementary (Simulation)}}";
185 bool contains_data =
false;
186 for(
unsigned is=0;is<Samples.size();is++){
if(Samples[is].isData){contains_data=
true;
break;} }
188 cmslabel =
"#font[62]{CMS}";
189 cmslabel +=
" #scale[0.8]{#font[52]{"+CMStype+
"}}";
190 lumilabel = TString::Format(
"%1.1f",luminosity.Atof())+
" fb^{-1} (13 TeV)";}
192 if(vars[var].unit!=
"") {
194 float binwidth((vars[var].maxx-vars[var].minx)/static_cast<float>(vars[var].nbins));
195 if(binwidth<1) digits = 1;
196 if (!variableBins) ytitle += (
"/("+
RoundNumber(binwidth,digits) +
" "+vars[var].unit+
")");
198 histo[0][var][sam]->SetYTitle(ytitle);
200 for(
int bin(0); bin<=histo[0][var][sam]->GetNbinsX()+1; bin++){
201 double val(histo[0][var][sam]->GetBinContent(bin));
202 histo[1][var][sam]->SetBinContent(bin, val);
204 histo[1][var][sam]->SetBinError(bin, histo[0][var][sam]->GetBinErrorUp(bin));
208 if(nbkg>0 && (vars[var].whichPlots.Contains(
"0") || vars[var].whichPlots.Contains(
"1")
209 || vars[var].whichPlots.Contains(
"2"))){
212 unsigned int last_hist=9999;
213 float normalization_ratio=1;
214 for(
unsigned sam(Nsam-1); sam < Nsam; sam--){
215 int isam = vars[var].samples[sam];
216 bool noStack = Samples[isam].isSig || Samples[isam].isData;
218 if(sam<last_hist) last_hist=sam;
219 for(
unsigned bsam(sam+1); bsam < Nsam; bsam++){
220 histo[0][var][sam]->Add(histo[0][var][bsam]);
223 histo[0][var][sam]->SetFillStyle(1001);
224 if(Samples[isam].doBand){
225 histo[0][var][sam]->SetFillColor(Samples[isam].color-12);
226 histo[0][var][sam]->SetLineColor(Samples[isam].color);
227 histo[0][var][sam]->SetLineWidth(3);
229 histo[0][var][sam]->SetFillColor(Samples[isam].color);
230 histo[0][var][sam]->SetLineColor(1);
231 histo[0][var][sam]->SetLineWidth(1);
235 histo[0][var][sam]->SetLineColor(Samples[isam].color);
236 if(Samples[isam].isData){
237 histo[0][var][sam]->SetMarkerStyle(20);
238 histo[0][var][sam]->SetMarkerSize(1.2);
239 histo[0][var][sam]->SetLineWidth(2);
241 if(someBands) histo[0][var][sam]->SetLineWidth(3);
242 else histo[0][var][sam]->SetLineWidth(6);
243 histo[0][var][sam]->SetLineStyle(abs(Samples[isam].style));
245 if(Samples[isam].doStack) histo[0][var][sam]->Add(histo[0][var][bkgind]);
250 if(vars[var].normalize || doRatio){
251 double err_num(0), err_den(0);
252 float num = histo[0][var][0]->IntegralAndError(1,histo[0][var][0]->GetNbinsX(),err_num);
253 float den = histo[0][var][last_hist]->IntegralAndError(1,histo[0][var][last_hist]->GetNbinsX(),err_den);
254 normalization_ratio = num/den;
255 double err_tot(den/num*sqrt(pow(err_num/num,2)+pow(err_den/den,2)));
256 err_tot = num/den*sqrt(pow(err_num/num,2)+pow(err_den/den,2));
260 cout<<
"Markers [data] are ("<<
RoundNumber((num/den)*100,1)
261 <<
" +- "<<
RoundNumber(err_tot*100,1)<<
")% the histogram [MC]. Data yield is "<<num<<endl;
264 for(
unsigned sam(Nsam-1); sam < Nsam; sam--){
265 int isam = vars[var].samples[sam];
267 if(sam>=last_hist && vars[var].normalize && !Samples[isam].isSig){
268 histo[0][var][sam]->Scale(normalization_ratio);
269 nentries[sam]*= normalization_ratio;
272 if(Samples[isam].mcerr){ histo[0][var][sam]->SetLineWidth(4); histo[0][var][sam]->SetMarkerStyle(20);
274 histo[0][var][sam]->SetMarkerSize(1.2);
275 histo[0][var][sam]->SetLineStyle(abs(Samples[isam].style));
276 if(Nsam>=3) histo[0][var][2]->SetFillColorAlpha(Samples[2].color, 0.5);
278 double maxval(histo[0][var][sam]->GetMaximum());
279 if(maxhisto < maxval) maxhisto = maxval;
280 maxval += histo[0][var][sam]->GetBinErrorUp(histo[0][var][sam]->GetMaximumBin());
281 if((Samples[isam].isData || Samples[isam].mcerr) && maxhisto < maxval) maxhisto = maxval;
287 for(
int ileg(0); ileg<nLegs; ileg++) leg[ileg].Clear();
288 unsigned legcount(0);
289 int firstplotted(-1);
290 for(
unsigned sam(0); sam < Nsam; sam++){
291 int isam = vars[var].samples[sam];
292 leghisto = Samples[isam].label;
293 if(!namestyle.Contains(
"CMSPaper") || showcuts) leghisto +=
" [N=" +
RoundNumber(nentries[sam],0) +
"]";
295 bool noStack = Samples[isam].isSig || Samples[isam].isData;
296 unsigned ileg = (Nsam<=3?0:legcount>=(Nsam+1)/2);
298 if(Samples[isam].doBand) leg[ileg].AddEntry(histo[0][var][sam], leghisto,
"fl");
299 else leg[ileg].AddEntry(histo[0][var][sam], leghisto,
"f");
301 if(firstplotted < 0) {
302 if(!Samples[isam].mcerr) {
303 if(!Samples[isam].doBand) histo[0][var][sam]->Draw(
"hist");
305 histo[0][var][sam]->Draw(
"E2");
306 TString hcname(
"hclone"); hcname += var;
307 TH1F *hclone =
static_cast<TH1F*
>(histo[0][var][sam]->Clone(hcname));
308 hclone->SetLineColor(Samples[isam].color);
309 hclone->SetLineWidth(3);
310 hclone->SetFillColor(0);
311 hclone->Draw(
"hist same");
313 }
else histo[0][var][sam]->Draw(
"E0LP");
315 style.
setTitles(histo[0][var][sam],vars[var].title, ytitle, cmslabel, lumilabel);
317 if(!Samples[isam].mcerr) histo[0][var][sam]->Draw(
"hist same");
318 else histo[0][var][sam]->Draw(
"E0LP same");
321 if(Samples[isam].isSig) leg[ileg].AddEntry(histo[0][var][sam], leghisto,
"l");
322 else leg[ileg].AddEntry(histo[0][var][sam], leghisto,
"elp");
326 for(
int sam(Nsam-1); sam >= 0; sam--){
327 int isam = vars[var].samples[sam];
328 if(Samples[isam].isSig){
if(!Samples[isam].mcerr) histo[0][var][sam]->Draw(
"hist same");
else histo[0][var][sam]->Draw(
"EP same"); }
329 if(Samples[isam].isData) histo[0][var][sam]->Draw(
"e0 same");
331 for(
int ileg(0); ileg<nLegs; ileg++) leg[ileg].Draw();
334 if(histo[0][var][firstplotted]->GetMinimum() > minLog) histo[0][var][firstplotted]->SetMinimum(minLog);
335 float maxpadLog(maxhisto*exp(fracLeg*log(maxhisto/minLog)/(1-fracLeg)));
336 histo[0][var][firstplotted]->SetMinimum(minLog);
337 histo[0][var][firstplotted]->SetMaximum(maxpadLog);
338 if (!doRatio) style.
moveYAxisLabel(histo[0][var][firstplotted], maxpadLog,
true);
339 histo[0][var][firstplotted]->Draw(
"axis same");
340 if(vars[var].cut>0) line.DrawLine(vars[var].cut, 0, vars[var].cut, maxhisto*1.05);
343 TH1D* hratio_data(NULL);
348 unsigned ndatasam(0);
349 for(
unsigned sam(Nsam-1); sam < Nsam; sam--) {
350 int isam = vars[var].samples[sam];
351 if (Samples[isam].isData || (Samples[isam].mcerr && sam==0)) {
352 if (ndatasam==0) hdata =
static_cast<TH1D*
>(histo[0][var][sam]->Clone());
353 else hdata->Add(histo[0][var][sam]);
358 float maxRatio = 1.9;
359 if(vars[var].maxRatio > 0) maxRatio = vars[var].maxRatio;
360 hratio_data =
static_cast<TH1D*
>(hdata->Clone());
361 hratio_data->SetTitle(
"");
362 hratio_data->Divide(histo[0][var][firstplotted]);
363 hratio_data->GetYaxis()->SetRangeUser(0.1,maxRatio);
364 hratio_data->GetXaxis()->SetLabelOffset(0.025);
365 hratio_data->GetXaxis()->SetLabelSize(style.
LabelSize*2.2);
366 hratio_data->GetYaxis()->SetLabelSize(style.
LabelSize*2.1);
367 hratio_data->GetYaxis()->SetTitle(
"Data / MC ");
369 size_t idata = vars[var].samples[0];
370 if(Samples[idata].label.Contains(
"2l")) hratio_data->GetYaxis()->SetTitle(
"2l / 1l");
371 else hratio_data->GetYaxis()->SetTitle(
"high / low");
373 hratio_data->GetXaxis()->SetTitle(histo[0][var][firstplotted]->GetXaxis()->GetTitle());
374 hratio_data->GetYaxis()->SetTitleSize(style.
TitleSize*3);
375 hratio_data->GetYaxis()->SetTitleOffset(0.5);
376 hratio_data->GetXaxis()->SetTitleSize(style.
TitleSize*3);
377 hratio_data->GetXaxis()->SetTitleOffset(style.
xTitleOffset*0.9);
379 histo[0][var][firstplotted]->GetXaxis()->SetLabelOffset(2.);
382 hratio_data->Draw(
"e0");
388 l1 =
new TLine(histo[0][var][firstplotted]->GetXaxis()->GetXmin(), 1., histo[0][var][firstplotted]->GetXaxis()->GetXmax(), 1.);
392 cerr<<
"ERROR: Ratio plots currently only supported for plots with data."<<endl;
400 if(!namestyle.Contains(
"CMSPaper") || showcuts) {
401 TString lumilbl = TString::Format(
"%1.1f",luminosity.Atof())+
" fb^{-1}, "+norm_s;
404 llbl.SetNDC(); llbl.SetTextAlign(33);
405 llbl.DrawLatex(1-style.
PadRightMargin-0.02,leg[0].GetY1NDC()-0.02,lumilbl);
408 if(vars[var].
tag.Contains(
"results") && vars[var].cuts.Contains(
"nbm")){
410 tla.SetTextSize(0.055);
412 if(vars[var].cuts.Contains(
"nbm==1")) tla.DrawLatexNDC(0.73,0.64,
"#font[62]{N_{b} = 1}");
413 if(vars[var].cuts.Contains(
"nbm>=2")) tla.DrawLatexNDC(0.73,0.64,
"#font[62]{N_{b} #geq 2}");
418 pname = outfolder+
"/log_lumi_"+vars[var].tag+plot_tag;
419 if(vars[var].normalize) pname.ReplaceAll(
"/log_lumi",
"/log_norm");
420 if(!vars[var].skiplog && (vars[var].whichPlots.Contains(
"0") || vars[var].whichPlots.Contains(
"1")))
425 float minhisto(0), maxpad(minhisto + (maxhisto-minhisto)/(1-fracLeg));
426 if(vars[var].maxYaxis > 0) maxpad = vars[var].maxYaxis;
427 histo[0][var][firstplotted]->SetMinimum(minhisto);
428 histo[0][var][firstplotted]->SetMaximum(maxpad);
430 if (!doRatio) style.
moveYAxisLabel(histo[0][var][firstplotted], maxpad,
false);
431 pname = outfolder+
"/lumi_"+vars[var].tag+plot_tag;
432 if(vars[var].normalize) pname.ReplaceAll(
"/lumi",
"/norm");
433 if(vars[var].whichPlots.Contains(
"0") || vars[var].whichPlots.Contains(
"2")) can.SaveAs(pname);
439 for(
int ileg(0); ileg<nLegs; ileg++) leg[ileg].Clear();
440 unsigned legcount = 0;
441 for(
unsigned sam(0); sam < Nsam; sam++){
442 int isam = vars[var].samples[sam];
443 histo[1][var][sam]->SetLineColor(Samples[isam].color);
444 histo[1][var][sam]->SetMarkerColor(Samples[isam].color);
445 histo[1][var][sam]->SetMarkerStyle(20);
446 histo[1][var][sam]->SetLineStyle(abs(Samples[isam].style));
447 histo[1][var][sam]->SetLineWidth(4);
448 if(nentries[sam]) histo[1][var][sam]->Scale(100./nentries[sam]);
449 if(maxhisto < histo[1][var][sam]->GetMaximum()) maxhisto = histo[1][var][sam]->GetMaximum();
450 style.setTitles(histo[1][var][sam],vars[var].title,
"", cmslabel, lumilabel);
452 histo[1][var][sam]->SetXTitle(vars[var].title);
454 if(vars[var].unit!=
"") {
456 float binwidth((vars[var].maxx-vars[var].minx)/static_cast<float>(vars[var].
nbins));
457 if(binwidth<1) digits = 1;
458 if (!variableBins) ytitle += (
"/("+
RoundNumber(binwidth,digits) +
" "+vars[var].unit+
")");
460 histo[1][var][sam]->SetYTitle(ytitle);
461 if(Samples[isam].style>0) histo[1][var][sam]->Draw(
"hist");
462 else histo[1][var][sam]->Draw(
"e0 x0");
464 if(Samples[isam].style>0) histo[1][var][sam]->Draw(
"hist same");
465 else histo[1][var][sam]->Draw(
"e0 x0 same");
467 leghisto = Samples[isam].label;
468 unsigned ileg = (Nsam<=3?0:legcount>=(Nsam+1)/2);
469 if(!namestyle.Contains(
"CMSPaper") || showcuts){
470 if(vars[var].nevents.at(sam)<0){
471 leghisto +=
" [#mu=";
473 if(histo[1][var][sam]->GetMean()<30) digits = 1;
474 leghisto +=
RoundNumber(histo[1][var][sam]->GetMean(),digits) +
"]";
476 leg[ileg].SetX1NDC(0.24); leg[ileg].SetX2NDC(0.7);
477 leg[ileg].SetTextSize(0.75*style.LegendSize);
478 if(vars[var].varname.Contains(
"tks")) leghisto +=
"[N_{tks} = " +
RoundNumber(nentries[sam],1) +
", from N_{events} = " 483 if(Samples[isam].style>0) leg[ileg].AddEntry(histo[1][var][sam], leghisto,
"l");
484 else leg[ileg].AddEntry(histo[1][var][sam], leghisto,
"p");
487 for(
int ileg(0); ileg<nLegs; ileg++) leg[ileg].Draw();
488 if(vars[var].cut>0) line.DrawLine(vars[var].cut, 0, vars[var].cut, maxhisto*1.05);
491 float minhisto(0), maxpad(minhisto + (maxhisto-minhisto)/(1-fracLeg));
492 histo[1][var][0]->SetMinimum(minhisto);
493 histo[1][var][0]->SetMaximum(maxpad);
494 histo[1][var][0]->Draw(
"axis same");
497 if(vars[var].cuts.Contains(
"abs(isr_tru_pt)")){
499 tla.SetTextSize(0.055);
501 if(vars[var].cuts.Contains(
"abs(isr_tru_pt)<10")) tla.DrawLatexNDC(0.63,0.79,
"#font[62]{ISR p_{T} < 10 GeV}");
502 if(vars[var].cuts.Contains(
"abs(isr_tru_pt)>100")) tla.DrawLatexNDC(0.63,0.79,
"#font[62]{ISR p_{T} > 100 GeV}");
504 else if(vars[var].cuts.Contains(
"nleps<1234")){
505 TString
lsp =
"{#lower[-0.1]{#tilde{#chi}}#lower[0.2]{#scale[0.85]{^{0}}}#kern[-1.3]{#scale[0.85]{_{1}}}}";
506 TString t1t_label =
"#scale[0.95]{#tilde{g}#kern[0.2]{#tilde{g}}, #tilde{g}#rightarrowt#kern[0.18]{#bar{t}}#kern[0.18]"+
lsp;
508 tla.SetTextSize(0.045);
510 tla.DrawLatexNDC(0.52,0.70,
"#font[62]{"+t1t_label+
" (1500,100)}}");
511 histo[1][var][0]->SetMaximum(60);
514 pname = outfolder+
"/shapes_"+vars[var].tag+plot_tag;
515 if(vars[var].whichPlots.Contains(
"0") || vars[var].whichPlots.Contains(
"3")) can.SaveAs(pname);
516 float maxpadLog = maxhisto*exp(fracLeg*log(maxhisto/minLog)/(1-fracLeg));
517 histo[1][var][0]->SetMaximum(maxpadLog);
518 histo[1][var][0]->SetMinimum(minLog);
521 pname = outfolder+
"/log_shapes_"+vars[var].tag+plot_tag;
522 if(!vars[var].skiplog && (vars[var].whichPlots.Contains(
"0") || vars[var].whichPlots.Contains(
"4")))
527 for(
unsigned var(0); var<vars.size(); var++){
528 for(
unsigned his(0); his < 2; his++){
529 for(
unsigned sam(0); sam < vars[var].samples.size(); sam++)
530 if(histo[his][var][sam]) {
532 delete histo[his][var][sam];
540 TString filetype, TString namestyle, TString dir){
542 TString lumi_nodot =
luminosity; lumi_nodot.ReplaceAll(
".",
"p");
545 if(namestyle.Contains(
"CMSPaper")) style.
nDivisions = 706;
550 pad =
static_cast<TPad *
>(can.cd());
551 pad->SetRightMargin(0.2);
553 vector<TChain *> chain;
554 for(
unsigned sam(0); sam < Samples.size(); sam++){
555 chain.push_back(
new TChain(
"tree"));
556 for(
unsigned insam(0); insam < Samples[sam].file.size(); insam++){
558 chain[sam]->Add(Samples[sam].
file[insam]);
564 TString hname, title, variable, totCut;
567 for(
unsigned int i=0; i<vars.size(); i++){
568 hname =
"hist"; hname += i;
569 title =
cuts2title(vars[i].cuts); title +=
";"; title += vars[i].titlex; title +=
";"; title += vars[i].titley;
570 variable = vars[i].varnamey+
":"+vars[i].varnamex;
571 totCut = luminosity+
"*weight*("+vars[i].cuts+
")";
576 printf(
"\rSetting up chain %i of %lu for 2D plots...",i+1,vars.size());
578 if(i==vars.size()-1) printf(
"\n");
582 TChain *tempChain =
new TChain(
"tree");
583 for(
unsigned int j=0; j<vars[i].samples.size(); j++){
585 tempChain->Add(chain[vars[i].samples[j]]);
590 hists.push_back(
new TH2D(hname, title, vars[i].nbinsx,vars[i].minx,vars[i].maxx,vars[i].nbinsy,vars[i].miny,vars[i].maxy));
591 tempChain->Project(hname, variable, totCut,
"colz");
592 for(
int iby=1;iby<=vars[i].nbinsy;iby++){
593 hists.back()->SetBinContent(vars[i].nbinsx,iby,hists.back()->GetBinContent(vars[i].nbinsx,iby)+hists.back()->GetBinContent(vars[i].nbinsx+1,iby));
595 for(
int ibx=1;ibx<=vars[i].nbinsx;ibx++){
596 hists.back()->SetBinContent(ibx,vars[i].nbinsy,hists.back()->GetBinContent(ibx,vars[i].nbinsy)+hists.back()->GetBinContent(ibx,vars[i].nbinsy+1));
602 gStyle->SetOptStat(
"emr");
603 gStyle->SetStatX(0.338); gStyle->SetStatW(0.18); gStyle->SetStatY(0.90); gStyle->SetStatH(0.14);
605 cout<<
"Printing 2D plots"<<endl;
606 for(
unsigned int doLogz=0; doLogz<2; doLogz++){
607 for(
unsigned int i=0; i<vars.size(); i++){
608 if(doLogz==0 && vars[i].whichPlots.Contains(
"2"))
continue;
609 if(doLogz==1 && vars[i].whichPlots.Contains(
"1"))
continue;
611 TString plot_tag(
"_lumi"+lumi_nodot+filetype);
612 hists[i]->SetStats(0);
613 hists[i]->Draw(
"colz");
614 pname =
"plots/"+dir+
"/"+vars[i].tag+plot_tag;
615 if(doLogz) pname =
"plots/"+dir+
"/logz_"+vars[i].tag+plot_tag;
618 if(vars[i].cutx>0 || vars[i].cuty>0){
619 TLine line; line.SetLineColor(1); line.SetLineWidth(6); line.SetLineStyle(2);
620 if(vars[i].cutx>0 && vars[i].cuty>0){
621 line.DrawLine(vars[i].cutx,0,vars[i].cutx,vars[i].cuty);
622 line.DrawLine(0,vars[i].cuty,vars[i].cutx,vars[i].cuty);
624 else if(vars[i].cutx>0 && vars[i].cuty<0){
625 line.DrawLine(vars[i].cutx,0,vars[i].cutx,vars[i].maxy);
627 else if(vars[i].cutx<0 && vars[i].cuty>0){
628 line.DrawLine(0,vars[i].cuty,vars[i].maxx,vars[i].cuty);
635 for(
unsigned int i=0; i<vars.size(); i++){
636 if(hists[i]) hists[i]->Delete();
641 if(title==
"1") title =
"";
642 title.ReplaceAll(
"1==1",
"Full Sample");
643 title.ReplaceAll(
"el_tks_chg*lep_charge<0",
"OS");title.ReplaceAll(
"mu_tks_chg*lep_charge<0",
"OS");title.ReplaceAll(
"had_tks_chg*lep_charge<0",
"OS");
644 title.ReplaceAll(
"Sum$(abs(mc_id)==11)",
"n^{true}_{e}");
645 title.ReplaceAll(
"Sum$(abs(mc_id)==13)",
"n^{true}_{#mu}");
646 title.ReplaceAll(
"Sum$(genels_pt>0)",
"n^{true}_{e}");
647 title.ReplaceAll(
"Sum$(genmus_pt>0)",
"n^{true}_{#mu}");
648 title.ReplaceAll(
"Sum$(mus_sigid&&mus_miniso<0.2)",
"n_{#mu}^{10}");
649 title.ReplaceAll(
"Sum$(els_sigid&&els_miniso<0.1)",
"n_{e}^{10}");
650 title.ReplaceAll(
"nvmus==1&&nmus==1&&nvels==0",
"1 #mu");
651 title.ReplaceAll(
"nvmus10==0&&nvels10==0",
"0 leptons");
652 title.ReplaceAll(
"(nmus+nels)",
"n_{lep}");
653 title.ReplaceAll(
"(nels+nmus)",
"n_{lep}");
654 title.ReplaceAll(
"(nvmus+nvels)",
"n^{veto}_{lep}");
655 title.ReplaceAll(
"nvmus==2&&nmus>=1",
"n_{#mu}#geq1, n^{veto}_{#mu}=2");
656 title.ReplaceAll(
"nvels==2&&nels>=1",
"n_{e}#geq1, n^{veto}_{e}=2");
657 title.ReplaceAll(
"(nvmus>=2||nvels>=2)",
"n^{veto}_{lep} #geq 2");
658 title.ReplaceAll(
"(mumu_m*(mumu_m>0)+elel_m*(elel_m>0))>80&&(mumu_m*(mumu_m>0)+elel_m*(elel_m>0))<100",
660 title.ReplaceAll(
"mumuv_m>80&&mumuv_m<100",
662 title.ReplaceAll(
"elelv_m>80&&elelv_m<100",
664 title.ReplaceAll(
"onht>350&&onmet>100&&",
"");
665 title.ReplaceAll(
"jets_islep[0]==0",
"");
666 title.ReplaceAll(
"(nels==0&&nmus==1)",
"n_{#mu}=1");
667 title.ReplaceAll(
"(nels==1&&nmus==0)",
"n_{#font[12]{e}}=1");
668 title.ReplaceAll(
"Max$(abs(els_eta)*(els_sigid&&els_miniso<0.1&&els_pt>20))<1.479",
"barrel #font[12]{e}");
669 title.ReplaceAll(
"Max$(abs(els_eta)*(els_sigid&&els_miniso<0.1&&els_pt>20))>1.479",
"endcap #font[12]{e}");
672 title.ReplaceAll(
"nleps",
"n_{l}");
673 title.ReplaceAll(
"nvleps",
"n_{l}");
674 title.ReplaceAll(
"nmus",
"n_{#mu}");
675 title.ReplaceAll(
"nels",
"n_{e}");
676 title.ReplaceAll(
"nvmus",
"n^{veto}_{#mu}");
677 title.ReplaceAll(
"nvels",
"n^{veto}_{e}");
678 title.ReplaceAll(
"ntruleps",
"n^{true}_{l}");
679 title.ReplaceAll(
"_ra2b",
"^{ra2b}");
680 title.ReplaceAll(
"npv",
"n_{PV}");
681 title.ReplaceAll(
"mumu_pt1",
"p_{T}^{#mu}"); title.ReplaceAll(
"elel_pt1",
"p_{T}^{e}");
683 title.ReplaceAll(
"abs(mc_id)==1000006",
"stop"); title.ReplaceAll(
"abs(mc_id)==1000022",
"LSP");
685 title.ReplaceAll(
"onmet",
"MET^{on}"); title.ReplaceAll(
"onht",
"H_{T}^{on}");
686 title.ReplaceAll(
"njets30",
"n_{jets}^{30}");
687 title.ReplaceAll(
"els_pt",
"p^{e}_{T}"); title.ReplaceAll(
"mus_pt",
"p^{#mu}_{T}");
688 title.ReplaceAll(
"fjets_nconst",
"n_{const}^{fat jet}");
689 title.ReplaceAll(
"fjets_30_m[0]",
"m(J_{1})"); title.ReplaceAll(
"fjets_m[0]",
"m(J_{1})");
690 title.ReplaceAll(
"(fjets_pt*cosh(fjets_eta))",
"p_{fatjet}"); title.ReplaceAll(
"fjets_pt",
"p^{fatjet}_{T}"); title.ReplaceAll(
"jets_pt",
"p^{jet}_{T}");
691 title.ReplaceAll(
"mus_reliso",
"RelIso"); title.ReplaceAll(
"els_reliso",
"RelIso");
692 title.ReplaceAll(
"mus_miniso_tr15",
"MiniIso"); title.ReplaceAll(
"els_miniso_tr15",
"MiniIso");
693 title.ReplaceAll(
"njets",
"n_{jets}");title.ReplaceAll(
"abs(lep_id)==13&&",
"");
694 title.ReplaceAll(
">=",
" #geq "); title.ReplaceAll(
">",
" > ");
695 title.ReplaceAll(
"<=",
" #leq "); title.ReplaceAll(
"<",
" < ");
696 title.ReplaceAll(
"&&",
", "); title.ReplaceAll(
"==",
" = ");
697 title.ReplaceAll(
"met",
"MET"); title.ReplaceAll(
"ht_hlt",
"H_{T}^{HLT}");
698 title.ReplaceAll(
"mht",
"MHT");
699 title.ReplaceAll(
"ht",
"H_{T}"); title.ReplaceAll(
"mt",
"m_{T}");
700 title.ReplaceAll(
"ntks_chg==0",
" ITV");
701 title.ReplaceAll(
"nbm",
"n_{b}");
702 title.ReplaceAll(
"nbl",
"n_{b,l}");
703 title.ReplaceAll(
"mj",
" M_{J}");
705 title.ReplaceAll(
"el_tks_mt",
"Track m_{T}"); title.ReplaceAll(
"mu_tks_mt",
"Track m_{T}"); title.ReplaceAll(
"had_tks_mt",
"Track m_{T}");
706 title.ReplaceAll(
"el_tks_pt",
"Track p_{T}"); title.ReplaceAll(
"mu_tks_pt",
"Track p_{T}"); title.ReplaceAll(
"had_tks_pt",
"Track p_{T}");
707 title.ReplaceAll(
"el_tks_miniso",
"Track miniso"); title.ReplaceAll(
"mu_tks_miniso",
"Track miniso"); title.ReplaceAll(
"had_tks_miniso",
"Track miniso");
708 title.ReplaceAll(
"el_tks_chg_miniso",
"Track charged miniso"); title.ReplaceAll(
"mu_tks_chg_miniso",
"Track charged miniso"); title.ReplaceAll(
"had_tks_chg_miniso",
"Track charged miniso");
713 if (cut.Contains(
"<"))
714 cut.ReplaceAll(
"<",
">=");
715 else if (cut.Contains(
">"))
716 cut.ReplaceAll(
">",
"<=");
717 else if (cut.Contains(
"<="))
718 cut.ReplaceAll(
"<=",
">");
719 else if (cut.Contains(
">="))
720 cut.ReplaceAll(
">=",
"<");
725 pfeats::pfeats(
const vector<int> &isamples,
const TString &icut,
const TString &itagname):
731 hfeats::hfeats(TString ivarname,
int inbins,
float iminx,
float imaxx, vector<int> isamples,
732 TString ititle, TString icuts,
float icut, TString itagname,
bool iskiplog, vector<double> inevents):
747 if(inevents.at(0)<0)
nevents = vector<double>(isamples.size(),-1);
749 if(
nevents.size() !=
samples.size() ) cout<<
"hfeats samples/nevents size mismatch: "<<ititle<<endl;
756 string ctitle(
title.Data());
757 if(!(ctitle.find(
"GeV")==std::string::npos))
unit =
"GeV";
758 if(!(ctitle.find(
"Number")==std::string::npos))
unit =
"";
759 if(!(ctitle.find(
"phi")==std::string::npos))
unit =
"rad";
761 hfeats::hfeats(TString ivarnamex, TString ivarnamey,
int inbinsx,
float iminx,
float imaxx,
int inbinsy,
float iminy,
float imaxy, vector<int> isamples,
762 TString ititlex, TString ititley, TString icuts,
float icutx,
float icuty, TString itagname):
785 string ctitle(
title.Data());
786 if(!(ctitle.find(
"GeV")==std::string::npos))
unit =
"GeV";
787 if(!(ctitle.find(
"Number")==std::string::npos))
unit =
"";
788 if(!(ctitle.find(
"phi")==std::string::npos))
unit =
"rad";
791 hfeats::hfeats(TString ivarname,
int inbins,
float *ibinning, vector<int> isamples,
792 TString ititle, TString icuts,
float icut, TString itagname,
bool iskiplog, vector<double> inevents):
807 if(inevents.at(0)<0)
nevents = vector<double>(isamples.size(),-1);
809 if(
nevents.size() !=
samples.size() ) cout<<
"hfeats samples/nevents size mismatch: "<<ititle<<endl;
813 string ctitle(
title.Data());
814 if(!(ctitle.find(
"GeV")==std::string::npos))
unit =
"GeV";
815 if(!(ctitle.find(
"Number")==std::string::npos))
unit =
"";
816 if(!(ctitle.find(
"phi")==std::string::npos))
unit =
"rad";
825 tag.ReplaceAll(
"1==1",
"full_sample");
826 tag.ReplaceAll(
"el_tks_chg*lep_charge<0",
"OS");
tag.ReplaceAll(
"mu_tks_chg*lep_charge<0",
"OS");
tag.ReplaceAll(
"had_tks_chg*lep_charge<0",
"OS");
827 tag.ReplaceAll(
".",
"");
828 tag.ReplaceAll(
"(",
"");
tag.ReplaceAll(
"$",
"");
tag.ReplaceAll(
")",
"");
829 tag.ReplaceAll(
"[",
"");
tag.ReplaceAll(
"]",
"");
tag.ReplaceAll(
"||",
"_");
830 tag.ReplaceAll(
"/",
"_");
tag.ReplaceAll(
"*",
"");
tag.ReplaceAll(
"&&",
"_");
831 tag.ReplaceAll(
">=",
"ge");
tag.ReplaceAll(
"<=",
"se");
832 tag.ReplaceAll(
">",
"g");
tag.ReplaceAll(
"<",
"s");
tag.ReplaceAll(
"=",
"");
833 tag.ReplaceAll(
"+",
"");
tag.ReplaceAll(
"&",
"");
834 tag.ReplaceAll(
"!",
"not");
835 tag.ReplaceAll(
"#",
"");
tag.ReplaceAll(
"{",
"");
tag.ReplaceAll(
"}",
"");
837 tag.ReplaceAll(
"htg500_metg200_njetsge7_nbmge1_nmusnels1_",
"Baseline1B_");
838 tag.ReplaceAll(
"htg500_metg200_njetsge7_nbmge2_nmusnels1_",
"Baseline_");
840 tag.ReplaceAll(
"tks_idlep_chargeg0_nottks_is_primary_tks_idtks_id121_",
"os_els_");
841 tag.ReplaceAll(
"tks_idlep_chargeg0_nottks_is_primary_tks_idtks_id169_",
"os_mus_");
842 tag.ReplaceAll(
"tks_idlep_charges0_nottks_is_primary_nottks_idtks_id169_tks_idtks_id121_",
"os_had_");
844 tag.ReplaceAll(
"nottks_from_w",
"fakes");
845 tag.ReplaceAll(
"tks_from_w",
"prompt");
847 tag.ReplaceAll(
"tks_ptmintks_mini_netks_mini_ch,tks_r02_netks_r02_ch",
"abs_mini_iso_chgneu");
848 tag.ReplaceAll(
"tks_ptmintks_mini_netks_mini_ch,tks_r05_netks_r05_ch",
"abs_r_05_mini_iso_chgneu");
849 tag.ReplaceAll(
"tks_pttks_mini_netks_mini_ch",
"abs_untruncated_mini_iso_chgneu");
850 tag.ReplaceAll(
"mintks_mini_netks_mini_ch,tks_r02_netks_r02_ch",
"rel_02_mini_iso_chgneu");
851 tag.ReplaceAll(
"mintks_mini_netks_mini_ch,tks_r05_netks_r05_ch",
"rel_05_mini_iso_chgneu");
852 tag.ReplaceAll(
"tks_mini_netks_mini_ch",
"rel_untruncated_mini_iso_chgneu");
854 tag.ReplaceAll(
"tks_ptmintks_mini_ch,tks_r02_ch",
"abs_mini_iso_chg");
855 tag.ReplaceAll(
"tks_ptmintks_mini_ch,tks_r05_ch",
"abs_r05_mini_iso_chg");
856 tag.ReplaceAll(
"tks_pttks_mini_ch",
"abs_untruncated_mini_iso_chg");
857 tag.ReplaceAll(
"mintks_mini_ch,tks_r02_ch",
"rel_02_mini_iso_chg");
858 tag.ReplaceAll(
"mintks_mini_ch,tks_r05_ch",
"rel_05_mini_iso_chg");
859 tag.ReplaceAll(
"tks_mini_ch",
"rel_untruncated_mini_iso_chg");
862 tag.ReplaceAll(
"el_tks_mt",
"Track_mT");
tag.ReplaceAll(
"mu_tks_mt",
"Track_mT");
tag.ReplaceAll(
"had_tks_mt",
"Track_mT");
863 tag.ReplaceAll(
"el_tks_pt",
"Track_pT");
tag.ReplaceAll(
"mu_tks_pt",
"Track_pT");
tag.ReplaceAll(
"had_tks_pt",
"Track_pT");
864 tag.ReplaceAll(
"el_tks_miniso",
"Track_miniso");
tag.ReplaceAll(
"mu_tks_miniso",
"Track_miniso");
tag.ReplaceAll(
"had_tks_miniso",
"Track_miniso");
865 tag.ReplaceAll(
"el_tks_chg_miniso",
"Track_chg_miniso");
tag.ReplaceAll(
"mu_tks_chg_miniso",
"Track_chg_miniso");
tag.ReplaceAll(
"had_tks_chg_miniso",
"Track_chg_miniso");
872 tag.ReplaceAll(
" ",
"");
873 tag.ReplaceAll(
".",
"");tag.ReplaceAll(
",",
"");
874 tag.ReplaceAll(
"(",
""); tag.ReplaceAll(
"$",
""); tag.ReplaceAll(
")",
"");
875 tag.ReplaceAll(
"[",
""); tag.ReplaceAll(
"]",
""); tag.ReplaceAll(
"||",
"_");
876 tag.ReplaceAll(
"/",
"_"); tag.ReplaceAll(
"*",
""); tag.ReplaceAll(
"&&",
"_");
877 tag.ReplaceAll(
">=",
"ge"); tag.ReplaceAll(
"<=",
"se");
878 tag.ReplaceAll(
">",
"g"); tag.ReplaceAll(
"<",
"s"); tag.ReplaceAll(
"=",
"");
879 tag.ReplaceAll(
"+",
""); tag.ReplaceAll(
"&",
"");
880 tag.ReplaceAll(
"!",
"not");
881 tag.ReplaceAll(
"#",
""); tag.ReplaceAll(
"{",
""); tag.ReplaceAll(
"}",
"");
886 sfeats::sfeats(vector<TString> ifile, TString ilabel,
int icolor,
int istyle, TString icut,
887 TString isamVariable){
888 file = ifile; label = ilabel;
cut = icut;
889 color = icolor; style = istyle;
890 isSig = ifile[0].Contains(
"T1tttt");
891 samVariable = isamVariable;
894 tag.ReplaceAll(
"(",
"");
tag.ReplaceAll(
",",
"_");
tag.ReplaceAll(
")",
"");
895 tag.ReplaceAll(
"{",
"");
tag.ReplaceAll(
"#,",
"");
tag.ReplaceAll(
"}",
"");
896 doStack =
false; isData =
false; mcerr=
false; doBand =
false;
911 else {cout<<
"ERROR: bincut out of range"<<endl;
return "";}
915 else {cout<<
"ERROR: weight out of range"<<endl;
return -1.;}
922 void calc_chi2(TH1D *histo,
float &chi2,
int &ndof,
float &pvalue,
float &average){
923 vector<double> vals[2];
924 double sumx_sig2(0), sum_sig2(0);
926 for(
int bin(1); bin<=histo->GetNbinsX(); bin++){
927 if(histo->GetBinError(bin) > 0){
928 vals[0].push_back(histo->GetBinContent(bin));
929 vals[1].push_back(histo->GetBinError(bin));
931 sumx_sig2 += vals[0][ndof]/pow(vals[1][ndof],2);
932 sum_sig2 += 1/pow(vals[1][ndof],2);
936 if(sum_sig2<=0){cout<<
"All errors in histo are zero. Exiting."<<endl;
return;}
937 average = sumx_sig2/sum_sig2;
939 for(
int ival(0); ival <= ndof; ival++){
940 chi2 += pow((vals[0][ival]-average)/vals[1][ival],2);
942 pvalue = TMath::Prob(chi2,ndof);
946 void calc_chi2_diff(TH1D *histo1, TH1D *histo2,
float &chi2,
int &ndof,
float &pvalue,
float *average){
947 TH1D *histos[] = {histo1, histo2};
948 vector<double> vals[2][2];
949 double sumx_sig2[] = {0,0}, sum_sig2[] = {0,0};
951 for(
int his(0); his<2; his++){
952 for(
int bin(1); bin<=histos[his]->GetNbinsX(); bin++){
953 if(histos[his]->GetBinError(bin) > 0){
954 vals[his][0].push_back(histos[his]->GetBinContent(bin));
955 vals[his][1].push_back(histos[his]->GetBinError(bin));
957 sumx_sig2[his] += vals[his][0][ndofs[his]];
962 if(sum_sig2[his]<=0){cout<<
"All errors in histo are zero. Exiting."<<endl;
return;}
963 average[his] = sumx_sig2[his]/sum_sig2[his];
968 if(ndofs[0] != ndofs[1]) {cout<<
"First histo has "<<ndofs[0]<<
" ndof and second "<<ndofs[1]<<endl;
return;}
969 else ndof = ndofs[0];
971 double Raver = average[0]/average[1];
972 for(
int ival(0); ival <= ndof; ival++){
973 double error(sqrt(pow(vals[0][1][ival],2)+pow(vals[1][1][ival]*Raver,2)));
974 chi2 += pow((vals[0][0][ival]-vals[1][0][ival]*Raver)/error,2);
976 pvalue = TMath::Prob(chi2,ndof);
979 long getYieldErr(TChain& tree, TString cut,
double& yield,
double& uncertainty){
980 const TString hist_name(
"temp");
981 TH1D temp(hist_name,
"", 1, -1.0, 1.0);
983 long entries = tree.Project(hist_name,
"0.0", cut);
984 yield = temp.IntegralAndError(0,2,uncertainty);
992 cout<<Form(
"event num: %i",tree.
event())<<endl;
994 cout<<
"print MC doc: "<<endl;
995 for(
unsigned int igen = 0; igen<tree.
mc_pt().size();igen++){
996 cout<<Form(
"%i: ID= %i \tpT=%.1f \teta=%.1f \tphi=%.1f \tmom= %i",igen,tree.
mc_id().at(igen),tree.
mc_pt().at(igen),tree.
mc_eta().at(igen),tree.
mc_phi().at(igen),
static_cast<int>(tree.
mc_mom().at(igen)))<<endl;
999 cout<<
"Dumping Tracks"<<endl;
1000 for(
unsigned int itks = 0; itks<tree.
tks_pt().size();itks++){
1001 cout<<Form(
"%i: ID= %i \tpT=%.1f \teta=%.1f \tphi=%.1f \tisPrimary= %i \tfrom W= %i \ttruID = %i",itks,tree.
tks_id().at(itks),tree.
tks_pt().at(itks),tree.
tks_eta().at(itks),tree.
tks_phi().at(itks),
static_cast<int>(tree.
tks_is_primary().at(itks)),static_cast<int>(tree.
tks_from_w().at(itks)),tree.
tks_tru_id().at(itks))<<endl;
1006 TColor
ucsb_blue(2000, 1/255.,57/255.,166/255.);
1007 TColor
ucsb_gold(2001, 255/255.,200/255.,47/255);
1008 TColor
penn_red(2002, 149/255.,0/255.,26/255.);
1009 TColor
uf_orange(2003, 255/255.,74/255.,0/255.);
1010 TColor
uo_green(2004, 0/255.,79/255.,39/255.);
1011 TColor
tcu_purple(2005, 52/255.,42/255.,123/255.);
1013 TColor
sig_teal(2007, 96/255.,159/255.,128/255.);
1014 TColor
sig_gold(2008, 215/255.,162/255.,50/255.);
1015 TColor
seal_brown(2010, 89/255.,38/255.,11/255.);
1019 TColor
light_blue(2011, 153/255.,220/255.,255/255.);
1020 TColor
med_blue(2012, 1/255.,148/255.,218/255.);
1021 TColor
red(2015, 250/255.,96/255.,1/255.);
1024 TColor
purple(2019, 183/255.,66/255.,176/255.);
1025 TColor
ucsb_gold(2020, 255/255.,200/255.,47/255);
1029 double intGaus(
double mean,
double sigma,
double minX,
double maxX){
1030 return (TMath::Erf((maxX-mean)/sigma/sqrt(2.))-TMath::Erf((minX-mean)/sigma/sqrt(2.)))/2.;
1038 double u = rand.Uniform(1);
1043 double d = a - 1.0 / 3.0;
1044 double c = (1.0 / 3.0) / sqrt (d);
1048 x = rand.Gaus(0, 1.0);
1054 u = rand.Uniform(1);
1056 if (u < 1 - 0.0331 * x * x * x * x)
1059 if (log (u) < 0.5 * x * x + d * (1 - v + log (v)))
1071 vector<float> &powers,
float &mSigma,
float &pSigma,
bool do_data,
1073 TRandom3 rand(1234);
1077 vector<float> fKappas;
1078 double mean(0.), bignum(1e10);
1080 for(
int rep(0), irep(0); rep <
nrep; rep++) {
1081 fKappas.push_back(1.);
1082 bool Denom_is0(
false);
1083 for(
unsigned obs(0); obs < powers.size(); obs++) {
1085 for(
unsigned sam(0); sam < entries[obs].size(); sam++) {
1088 if(do_data) observed += entries[obs][sam]*
weights[obs][sam];
1089 else observed +=
gsl_ran_gamma(entries[obs][sam]+1,1,rand)*weights[obs][sam];
1093 if(observed <= 0 && powers[obs] < 0) Denom_is0 =
true;
1094 else fKappas[irep] *= pow(observed, powers[obs]);
1096 if(Denom_is0 && fKappas[irep]==0) {
1100 if(Denom_is0) fKappas[irep] = bignum;
1101 else mean += fKappas[irep];
1105 int ntot(nrep-nbadk);
1106 mean /=
static_cast<double>(ntot);
1108 sort(fKappas.begin(), fKappas.end());
1109 double gSigma =
intGaus(0,1,0,1);
1110 int iMedian((nrep-nbadk+1)/2-1);
1111 int imSigma(iMedian-static_cast<int>(gSigma*ntot)), ipSigma(iMedian+static_cast<int>(gSigma*ntot));
1112 float median(fKappas[iMedian]);
1113 mSigma = median-fKappas[imSigma]; pSigma = fKappas[ipSigma]-median;
1118 for(
unsigned obs(0); obs < powers.size(); obs++) {
1120 if(verbose) cout<<obs<<
": ";
1121 for(
unsigned sam(0); sam < entries[obs].size(); sam++) {
1122 if(verbose) cout<<
"Yield"<<sam<<
" "<<entries[obs][sam]*
weights[obs][sam]
1123 <<
", N"<<sam<<
" "<<entries[obs][sam]
1124 <<
", avW"<<sam<<
" "<<
weights[obs][sam]<<
". ";
1125 stdyield += entries[obs][sam]*weights[obs][sam];
1127 if(verbose) cout<<
" ==> Total yield "<<stdyield<<endl;
1128 if(stdyield <= 0 && powers[obs] < 0) infStd =
true;
1129 else stdval *= pow(stdyield, powers[obs]);
1131 if(infStd) stdval = median;
1134 for(
int rep(0); rep < ntot; rep++)
1135 if(fKappas[rep]>stdval) {istd = rep;
break;}
1136 imSigma = istd-
static_cast<int>(gSigma*ntot);
1137 ipSigma = istd+
static_cast<int>(gSigma*ntot);
1139 ipSigma += (-imSigma);
1143 imSigma -= (ipSigma-ntot+1);
1146 mSigma = stdval-fKappas[imSigma]; pSigma = fKappas[ipSigma]-stdval;
1150 double minH(stdval-3*mSigma), maxH(stdval+3*pSigma);
1151 if(minH < fKappas[0]) minH = fKappas[0];
1152 if(maxH > fKappas[ntot-1]) maxH = fKappas[ntot-1];
1153 TH1D histo(
"h",
"",nbins, minH, maxH);
1154 for(
int rep(0); rep < ntot; rep++)
1155 histo.Fill(fKappas[rep]);
1158 histo.Scale(1/histo.Integral());
1159 histo.SetMaximum(histo.GetMaximum()*1.2);
1160 histo.SetLineWidth(3);
1162 histo.SetXTitle(
"Expected value");
1163 histo.SetYTitle(
"Probability");
1165 if(do_plot) can.SaveAs(
"test.eps");
1167 double mode(histo.GetBinLowEdge(histo.GetMaximumBin()));
1168 if(verbose) cout<<
"Std kappa = "<<stdval<<
"+"<<pSigma<<
"-"<<mSigma<<
". Mean = "<<mean
1169 <<
". Mode = "<<mode<<
". Median = "<<median<<endl;
1175 if(den<=0){cout<<
"Denominator is "<<den<<
". Exiting"<<endl;
return -1.;}
1177 TH1D hnum(
"hnum",
"",1,0,1);
1178 hnum.SetBinContent(1,num);
1179 TH1D hden(
"hden",
"",1,0,1);
1180 hden.SetBinContent(1,den);
1182 TEfficiency heff(hnum, hden);
1184 errup = heff.GetEfficiencyErrorUp(1);
1185 errdown = heff.GetEfficiencyErrorLow(1);
TColor med_blue(2012, 1/255., 148/255., 218/255.)
std::vector< double > weights
virtual int const & ntruleps() const
TString invertcut(TString cut)
TColor skype_green(2018, 9/255., 186/255., 1/255.)
void calc_chi2_diff(TH1D *histo1, TH1D *histo2, float &chi2, int &ndof, float &pvalue, float *average)
TColor tcu_purple(2005, 52/255., 42/255., 123/255.)
std::vector< double > nevents
double weight(unsigned i)
long getYieldErr(TChain &tree, TString cut, double &yield, double &uncertainty)
virtual std::vector< size_t > const & mc_mom() const
TColor uf_orange(2003, 255/255., 74/255., 0/255.)
virtual std::vector< int > const & tks_tru_id() const
virtual std::vector< bool > const & tks_is_primary() const
virtual int const & ntrutausl() const
TColor tar_heel_blue(2006, 86/255., 160/255., 211/255.)
sfeats(std::vector< TString > ifile, TString ilabel, int icolor=1, int istyle=1, TString icut="1", TString samVariable="noPlot")
void moveYAxisLabel(TH1 *h, float maxi, bool isLog=false)
double gsl_ran_gamma(const double a, const double b, TRandom3 &rand)
TColor ucsb_gold(2020, 255/255., 200/255., 47/255)
virtual std::vector< float > const & tks_pt() const
TString bincut(unsigned i)
int const & event() const
hfeats(TString ivarname, int inbins, float iminx, float imaxx, std::vector< int > isamples, TString ititle="", TString icuts="1", float icut=-1, TString itagname="", bool iskiplog=false, std::vector< double > inevents=std::vector< double >(1,-1.))
TColor ucsb_blue(2000, 1/255., 57/255., 166/255.)
virtual std::vector< float > const & tks_eta() const
TColor light_blue(2011, 153/255., 220/255., 255/255.)
float Efficiency(float num, float den, float &errup, float &errdown)
std::vector< int > samples
double calcKappa(vector< vector< float > > &entries, vector< vector< float > > &weights, vector< float > &powers, float &mSigma, float &pSigma, bool do_data, bool verbose, bool do_plot, int nrep)
void dump_event(small_tree_full &tree, int entry)
double intGaus(double mean, double sigma, double minX, double maxX)
std::vector< int > samples
TString cuts2title(TString title)
TString RoundNumber(double num, int decimals, double denom=1.)
TColor sig_gold(2008, 215/255., 162/255., 50/255.)
virtual std::vector< int > const & mc_id() const
void setTitles(TH1 *h, TString xTitle="", TString yTitle="", TString Left="", TString Right="")
std::vector< TString > bincuts
virtual std::vector< float > const & mc_pt() const
TColor red(2015, 250/255., 96/255., 1/255.)
virtual std::vector< float > const & mc_phi() const
void plot_distributions(vector< sfeats > Samples, vector< hfeats > vars, TString luminosity, TString filetype, TString namestyle, TString dir, bool doRatio, bool showcuts)
virtual int const & ntrutaush() const
void calc_chi2(TH1D *histo, float &chi2, int &ndof, float &pvalue, float &average)
TColor uo_green(2004, 0/255., 79/255., 39/255.)
virtual std::vector< bool > const & tks_from_w() const
TColor penn_red(2002, 149/255., 0/255., 26/255.)
TColor purple(2019, 183/255., 66/255., 176/255.)
void push_back(TString bincut, double weight)
pfeats(const std::vector< int > &isamples, const TString &icut="1", const TString &itagname="")
virtual int const & ntrumus() const
virtual std::vector< int > const & tks_id() const
virtual void GetEntry(const long entry)
virtual std::vector< float > const & tks_phi() const
TColor seal_brown(2010, 89/255., 38/255., 11/255.)
void plot_2D_distributions(vector< sfeats > Samples, vector< hfeats > vars, TString luminosity, TString filetype, TString namestyle, TString dir)
virtual std::vector< float > const & mc_eta() const
TColor sig_teal(2007, 96/255., 159/255., 128/255.)
sysfeats(TString iname, TString ititle)
virtual int const & ntruels() const