ra4_macros  bede988c286599a3a84b77a4d788ac0a971e89f9
kappa_variations.cxx
Go to the documentation of this file.
1 #include <iostream>
2 #include <fstream>
3 #include <vector>
4 #include <ctime>
5 
6 #include "TMath.h"
7 #include "TChain.h"
8 #include "TRandom3.h"
9 #include "TH1D.h"
10 #include "TCanvas.h"
11 #include "TLegend.h"
12 #include "TLine.h"
13 #include "TString.h"
14 #include "TLatex.h"
15 #include "TGraphAsymmErrors.h"
16 
17 #include "styles.hpp"
18 #include "utilities.hpp"
19 #include "utilities_macros.hpp"
20 
21 namespace {
22  TString ntuple_date("2015_05_25");
23  TString lumi("10");
24  int method(1);
25  int nrep = 10000; // Fluctuations of Gamma distribution
26  bool do_1ltt(false); // Kappa just for 1l ttbar
27  bool do_2ltt(false); // Kappa just for 2l ttbar
28  bool do_ttbar(true); // Include ttbar in kappa
29  bool do_other(false); // Include other in kappa
30 }
31 
32 using namespace std;
33 
34 // yields[Nobs][Nsam] has the entries for each sample for each observable going into kappa
35 // weights[Nobs][Nsam] has the average weight of each observable for each sample
36 // powers[Nobs] defines kappa = Product_obs{ Sum_sam{yields[sam][obs]*weights[sam][obs]}^powers[obs] }
37 double calcKappaRelUnc(vector<vector<vector<int> > > &entries, vector<vector<vector<float> > > &weights, vector<float> &powers,
38  float &mSigma, float &pSigma, TString label);
39 
40 double getSysWeight();
41 
42 int main(){
43  styles style("RA4"); style.LabelSize = 0.05;
44  style.setDefaultStyle();
45  // TString folder="/cms5r0/ald77/archive/"+ntuple_date+"/skim100/";
46  // TString folder_ns="/cms5r0/ald77/archive/"+ntuple_date+"/";
47  // TString folder="/net/cms2/cms2r0/manuelf/root/archive/15-06-01/skim/";
48  TString folder="/cms5r0/aovcharova/archive/2015_06_05/skim/";
49 
50 
51  vector<TString> s_tt;
52  s_tt.push_back(folder+"*_TTJet*");
53  vector<TString> s_singlet;
54  s_singlet.push_back(folder+"*_T*channel*");
55  vector<TString> s_other;
56  s_other.push_back(folder+"*QCD_HT*");
57  s_other.push_back(folder+"*_ZJet*");
58  s_other.push_back(folder+"*DY*");
59  s_other.push_back(folder+"*WH_HToBB*");
60  s_other.push_back(folder+"*TTW*");
61  s_other.push_back(folder+"*TTZ*");
62  s_other.push_back(folder+"*WJets*");
63 
64  // Reading ntuples
65  vector<sfeats> Samples;
66  if(do_1ltt) Samples.push_back(sfeats(s_tt, "t#bar{t}, 1 l", ra4::c_tt_1l, 1,"ntruleps==1"));
67  else {
68  if(do_2ltt) Samples.push_back(sfeats(s_tt, "t#bar{t}, 2 l", ra4::c_tt_2l,1,"ntruleps>=2"));
69  else {
70  if(do_ttbar) Samples.push_back(sfeats(s_tt, "t#bar{t}, 2 l", ra4::c_tt_2l,1));
71  if(do_other){
72  Samples.push_back(sfeats(s_singlet, "Single t", ra4::c_singlet));
73  Samples.push_back(sfeats(s_other, "Other", ra4::c_other, 1));
74  }
75  }
76  }
77  // Adding non-skimmed samples
78  vector<int> ra4_sam, ra4_sam_ns;
79  unsigned nsam(Samples.size());
80  for(unsigned sam(0); sam < nsam; sam++){
81  ra4_sam.push_back(sam);
82  // ra4_sam_ns.push_back(nsam+sam);
83  // vector<TString> sam_files = Samples[sam].file;
84  // for(unsigned ifile(0); ifile < sam_files.size(); ifile++)
85  // sam_files[ifile].ReplaceAll(folder, folder_ns);
86  // Samples.push_back(sfeats(sam_files, Samples[sam].label, Samples[sam].color, Samples[sam].style,
87  // Samples[sam].cut));
88  } // Loop over samples
89 
90  // Reading ntuples
91  vector<TChain *> chain;
92  for(unsigned sam(0); sam < Samples.size(); sam++){
93  chain.push_back(new TChain("tree"));
94  for(unsigned insam(0); insam < Samples[sam].file.size(); insam++)
95  chain[sam]->Add(Samples[sam].file[insam]);
96  }
97 
98 
99  time_t begtime, endtime;
100  time(&begtime);
101 
102  TString mjthresh("400");
103  if(method==1) mjthresh = "600";
104  float mSigma, pSigma;
105  vector<float> powers;
106  vector<TString> cuts;
107  powers.push_back(1); cuts.push_back("mt<=140&&mj<="+mjthresh); // R1
108  powers.push_back(-1); cuts.push_back("mt<=140&&mj>"+mjthresh); // R2
109  powers.push_back(-1); cuts.push_back("mt>140&&mj<="+mjthresh); // R3
110  powers.push_back(1); cuts.push_back("mt>140&&mj>"+mjthresh); // R4
111 
112  TString baseline("(nmus+nels)==1&&ht>500&&met>100&&njets>=7&&nbm>=1");
113  vector<TString> metcuts, njcuts, nbcuts, metnames;
114  metcuts.push_back("met>200&&met<=400");
115  metcuts.push_back("met>400");
116  njcuts.push_back("njets<=8");
117  njcuts.push_back("njets>=9");
118  // nbcuts.push_back("nbm==1");
119  if(method==1 || method==2) nbcuts.push_back("nbm>=1");
120  else {
121  nbcuts.push_back("nbm==2");
122  nbcuts.push_back("nbm>=3");
123  }
124  for(unsigned imet(0); imet<metcuts.size(); imet++){
125  metnames.push_back(metcuts[imet]);
126  metnames[imet].ReplaceAll("met>","");
127  metnames[imet].ReplaceAll("met<=","");
128  metnames[imet].ReplaceAll("&&","-");
129  if(!metnames[imet].Contains("-")) metnames[imet] += "+";
130  metnames[imet] = "#splitline{MET}{"+metnames[imet]+"}";
131  }
132 
133  vector<sysfeats> syst;
134  syst.push_back(sysfeats("nisr","ME ISR multiplicity"));
135  syst.back().push_back("n_isr_me==0", 0.75);
136  syst.back().push_back("n_isr_me==1", 1.);
137  syst.back().push_back("n_isr_me==2", 1.25);
138  syst.back().push_back("n_isr_me==3", 1.5);
139 
140  syst.push_back(sysfeats("pt_isr","ISR pT"));
141  syst.back().push_back("tru_tt_pt<=120", 1.);
142  syst.back().push_back("120<tru_tt_pt&&tru_tt_pt<=200", 0.95);
143  syst.back().push_back("200<tru_tt_pt&&tru_tt_pt<=300", 0.9);
144  syst.back().push_back("300<tru_tt_pt&&tru_tt_pt<=500", 0.8);
145  syst.back().push_back("500<tru_tt_pt&&tru_tt_pt<=650", 0.6);
146  syst.back().push_back("650<tru_tt_pt&&tru_tt_pt<=800", 0.4);
147  syst.back().push_back("800<tru_tt_pt&&tru_tt_pt", 0.2);
148 
149  // syst.push_back(sysfeats("top_pt","top $p_T$"));
150  // syst.back().push_back("(trutop1_pt+trutop2_pt)<=300", exp(0.156-0.000685*200.));
151  // syst.back().push_back("300<(trutop1_pt+trutop2_pt)&&(trutop1_pt+trutop2_pt)<=500", exp(0.156-0.000685*400.));
152  // syst.back().push_back("500<(trutop1_pt+trutop2_pt)&&(trutop1_pt+trutop2_pt)<=700", exp(0.156-0.000685*600.));
153  // syst.back().push_back("700<(trutop1_pt+trutop2_pt)&&(trutop1_pt+trutop2_pt)<=900", exp(0.156-0.000685*800.));
154  // syst.back().push_back("900<(trutop1_pt+trutop2_pt)&&(trutop1_pt+trutop2_pt)<=1100", exp(0.156-0.000685*1000.));
155  // syst.back().push_back("1100<(trutop1_pt+trutop2_pt)&&(trutop1_pt+trutop2_pt)<=1300", exp(0.156-0.000685*1200.));
156  // syst.back().push_back("1300<(trutop1_pt+trutop2_pt)&&(trutop1_pt+trutop2_pt)<=1500", exp(0.156-0.000685*1400.));
157  // syst.back().push_back("1500<(trutop1_pt+trutop2_pt)", exp(0.156-0.000685*1500.));
158 
159 
160  syst.push_back(sysfeats("dilep","2 $\\times$ dilep."));
161  syst.back().push_back("((ntruleps==1&&mt<=140.)||ntruleps==2)", 1.);
162  syst.back().push_back("ntruleps==1&&mt>140", 2.);
163 
164  float minh(0), maxh(10), wtot(maxh-minh), max_axis(2.), max_krelunc(0.);
165  float wnj(wtot/static_cast<float>(njcuts.size()));
166  float wmet(wnj/static_cast<float>(metcuts.size()));
167  float wnb(wmet/static_cast<float>(nbcuts.size()+4));
168  vector<vector<double> > vx, vy, vexl, vexh, veyl, veyh;
169  for(unsigned inb(0); inb<nbcuts.size(); inb++){
170  vx.push_back (vector<double>());
171  vy.push_back (vector<double>());
172  vexl.push_back(vector<double>());
173  vexh.push_back(vector<double>());
174  veyl.push_back(vector<double>());
175  veyh.push_back(vector<double>());
176  }
177 
178  TString totcut("");
179  for(unsigned isys(0); isys<syst.size(); isys++){
180  for(unsigned inj(0); inj<njcuts.size(); inj++){
181  for(unsigned imet(0); imet<metcuts.size(); imet++){
182  for(unsigned inb(0); inb<nbcuts.size(); inb++){
183  vector<vector<vector<int> > > entries;
184  vector<vector<vector<float> > > weights;
185  for(unsigned obs(0); obs < powers.size(); obs++) {
186  entries.push_back(vector<vector<int> >());
187  weights.push_back(vector<vector<float> >());
188  // totcut = lumi+"*weight*("+baseline+"&&"+nbcuts[inb]+"&&"+metcuts[imet]+"&&"+cuts[obs];
189  // if(method==1 || obs%2==1) totcut += "&&"+njcuts[inj];
190  // totcut += ")";
191  // cout << totcut<<endl;
192  for(unsigned sam(0); sam < ra4_sam.size(); sam++) {
193  for(unsigned isbin(0); isbin < syst[isys].size(); isbin++) {
194  entries[obs].push_back(vector<int>());
195  weights[obs].push_back(vector<float>());
196  totcut = (lumi+"*weight*("+baseline+"&&"+nbcuts[inb]+"&&"+metcuts[imet]+"&&"+cuts[obs]+
197  "&&"+Samples[ra4_sam[sam]].cut+"&&"+syst[isys].bincut(isbin));
198  if(method==1 || obs%2==1) totcut += "&&"+njcuts[inj];
199  totcut += ")";
200  //cout << totcut<<endl;
201 
202  double yield(0.), sigma(0.), avWeight(1.);
203  int Nentries(0);
204  Nentries = getYieldErr(*chain[ra4_sam[sam]], totcut, yield, sigma);
205  entries[obs][sam].push_back(Nentries);
206  if(Nentries==0){ // If no entries, find average weight in signal bin
207  totcut = (lumi+"*weight*("+baseline+"&&"+cuts[obs]+")");
208  Nentries = getYieldErr(*chain[ra4_sam[sam]], totcut, yield, sigma);
209  // If no entries, find averate weight in baseline region
210  if(Nentries==0){
211  totcut = (lumi+"*weight*("+baseline+")");
212  Nentries = getYieldErr(*chain[ra4_sam[sam]], totcut, yield, sigma);
213  }
214  }
215  avWeight = fabs(yield/static_cast<double>(Nentries));
216  if (isbin == 0) weights[obs][sam].push_back(avWeight);
217  weights[obs][sam].push_back(syst[isys].weight(isbin));
218  }
219  //cout<<obs<<","<<sam<<": entries "<<entries[obs][sam]<<", weight "<<avWeight<<", yield "<<yield<<endl;
220  } // Loop over samples
221  } // Loop over number of observables going into kappa
222 
223  cout<<"----- Calc kappa for: "<<njcuts[inj]<<", "<<metcuts[imet]<<", "<<nbcuts[inb]<<endl;
224  double krelunc = calcKappaRelUnc(entries, weights, powers, mSigma, pSigma, Form("nj%i_imet%i_isys%i",inj,imet,isys));
225  if(krelunc > max_krelunc) max_krelunc = krelunc;
226  float xpoint = inj*wnj+imet*wmet+(inb+2)*wnb;
227  if(krelunc > max_axis && krelunc-mSigma < max_axis) {
228  mSigma = max_axis-(krelunc-mSigma);
229  krelunc = max_axis;
230  }
231  vx[inb].push_back(xpoint);
232  vy[inb].push_back(krelunc);
233  vexl[inb].push_back(0);
234  vexh[inb].push_back(0);
235  veyl[inb].push_back(mSigma);
236  veyh[inb].push_back(pSigma);
237 
238  } // Loop over nb cuts
239  } // Loop over met cuts
240  } // Loop over nj cuts
241  } // Loop over systematics
242 
243  int digits(1);
244  vector<unsigned> ind(nbcuts.size(),0);
245  TString pname = "txt/kappa_method", cutname; pname += method;
246  if(do_1ltt) pname += "_1ltt";
247  else {
248  if(do_2ltt) pname += "_2ltt";
249  else {
250  if(do_ttbar) pname += "_tt";
251  if(do_other) pname += "_other";
252  }
253  }
254  pname += ".tex";
255  // ifstream header("txt/header.tex");
256  // ifstream footer("txt/footer.tex");
257  ofstream file(pname);
258  // file<<header.rdbuf();
260  file << "\\renewcommand{\\arraystretch}{1.4}"<<endl;
261  file << "\\begin{tabular}[tbp!]{ l | cccc}\\hline\\hline\n";
262  file << "& $n_{jets} \\leq 8$ & $n_{jets} \\leq 8$ & $n_{jets} > 8$ & $n_{jets} > 8$ \\\\"<<endl;
263  file << "& MET $\\leq 400$ & MET $> 400$ & MET $\\leq 400$ & MET $> 400$ \\\\"<<endl;
264  file << "\\hline\n";
265 
266  // file << " \\multicolumn{1}{c|}{${\\cal L} = "<<lumi<<"$ fb$^{-1}$} ";
267  // file << " & $N_{\\rm R2}\\frac{N_{\\rm R3}}{N_{\\rm R1}}$ & Data stat. [\\%] \n";
268  // file << "& $\\kappa^{\\rm MC}$ & MC stat. [\\%] & \\multicolumn{1}{c}{$\\hat{N}_{\\rm R4}$} \\\\ \\hline\n";
269  for(unsigned isys(0); isys<syst.size(); isys++){
270  file << syst[isys].title;
271  for(unsigned inj(0); inj<njcuts.size(); inj++){
272  for(unsigned imet(0); imet<metcuts.size(); imet++){
273  for(unsigned inb(0); inb<nbcuts.size(); inb++){
274  float Kappa(vy[inb][ind[inb]]);
275  float epKappa(veyh[inb][ind[inb]]), emKappa(veyl[inb][ind[inb]]);
276  file << " \t& $" <<RoundNumber(Kappa,digits+1)<<"^{+"<<RoundNumber(epKappa,digits+1)
277  <<"}_{-"<<RoundNumber(emKappa,digits+1)<<"}$";
278  ind[inb]++;
279  } // Loop over nb cuts
280  } // Loop over met cuts
281  } // Loop over nj cuts
282  file << "\\\\"<<endl;
283  } // Loop over systematics
284 
285  file<< "\\hline\\hline\n\\end{tabular}"<<endl<<endl;
286  // file<<footer.rdbuf();
287  file.close();
288  cout<<endl<<"Written "<<pname<<endl;
289 
290  // TCanvas can;
291  // TLine line; line.SetLineColor(28); line.SetLineWidth(4); line.SetLineStyle(2);
292  // TH1D histo("histo",cuts2title(baseline),njcuts.size()*metcuts.size(), minh, maxh);
293  // histo.Draw();
294  // TString ytitle("#kappa rel. unc. for method "); ytitle += method;
295  // histo.SetYTitle(ytitle);
296  // histo.SetMaximum(max_axis);
297  // style.moveYAxisLabel(&histo, max_axis, false);
298  // line.SetLineColor(1); line.SetLineWidth(2);
299  // line.DrawLine(minh+wtot/2., 0, minh+wtot/2, max_axis);
300  // for(unsigned inj(0); inj<njcuts.size(); inj++)
301  // for(unsigned imet(0); imet<metcuts.size(); imet++)
302  // histo.GetXaxis()->SetBinLabel(1+imet+inj*metcuts.size(), metnames[imet]);
303 
304  // double legX(style.PadLeftMargin+0.03), legY(0.902), legSingle = 0.052;
305  // double legW = 0.13, legH = legSingle*nbcuts.size();
306  // TLegend leg(legX, legY-legH, legX+legW, legY);
307  // leg.SetTextSize(style.LegendSize); leg.SetFillColor(0);
308  // leg.SetFillStyle(0); leg.SetBorderSize(0);
309  // leg.SetTextFont(style.nFont);
310  // TGraphAsymmErrors graph[20];
311  // int colors[] = {2,4,kMagenta+2}, styles[] = {20, 21, 22};
312  // for(unsigned isys(0); isys<syst.size(); isys++){
313  // graph[isys] = TGraphAsymmErrors(vx[isys].size(), &(vx[isys][0]), &(vy[isys][0]),
314  // &(vexl[isys][0]), &(vexh[isys][0]), &(veyl[isys][0]), &(veyh[isys][0]));
315  // graph[isys].SetMarkerStyle(styles[isys]); graph[isys].SetMarkerSize(1.4);
316  // graph[isys].SetMarkerColor(colors[isys]); graph[isys].SetLineColor(colors[isys]);
317  // graph[isys].Draw("p same");
318  // leg.AddEntry(&graph[isys], syst[isys].title, "p");
319  // }
320  // leg.Draw();
321  // TLatex label; label.SetNDC(kTRUE);label.SetTextAlign(22);
322  // label.DrawLatex(0.37,0.03,"7 #leq n_{j} #leq 8");
323  // label.DrawLatex(0.73,0.03,"n_{j} #geq 9");
324 
325  // TString pname = "plots/relunc_method"; pname += method;
326  // if(do_1ltt) pname += "_1ltt";
327  // else {
328  // if(do_2ltt) pname += "_2ltt";
329  // else {
330  // if(do_ttbar) pname += "_tt";
331  // if(do_other) pname += "_other";
332  // }
333  // }
334  // pname += "_mc";
335  // pname += ".pdf";
336  // can.SaveAs(pname);
337 
338  time(&endtime);
339  cout<<endl<<"Calculation took "<<difftime(endtime, begtime)<<" seconds"<<endl<<endl;
340 }
341 
342 double calcKappaRelUnc(vector<vector<vector<int> > > &entries, vector<vector<vector<float> > > &weights, vector<float> &powers,
343  float &mSigma, float &pSigma, TString label){
344  TRandom3 rand(1234);
345  int nbadk(0);
346  TCanvas can;
347  vector<float> fKappaRelShift;
348  double mean(0.), bignum(1e10);
349  // Doing kappa variations
350  for(int rep(0), irep(0); rep < nrep; rep++) {
351  fKappaRelShift.push_back(1.);
352  bool Denom_is0(false);
353  for(unsigned obs(0); obs < powers.size(); obs++) {
354  float observed(0.), observed_sys(0.);
355  for(unsigned sam(0); sam < entries[obs].size(); sam++) {
356  for(unsigned sysbin(0); sysbin < entries[obs][sam].size(); sysbin++) {
357  // Using a flat prior, the expected average of the Poisson with N observed is Gamma(N+1,1)
358  // double grnd = gsl_ran_gamma(entries[obs][sam][sysbin]+1,1,rand);
359  double grnd = gsl_ran_gamma(entries[obs][sam][sysbin]+1,1,rand);
360  observed += grnd*weights[obs][sam][0]; //store the nominal weight at 0
361  observed_sys += grnd*weights[obs][sam][0]*weights[obs][sam][sysbin+1];
362  // if (irep==0)
363  // cout<<"obs: "<<obs<<"sam: "<<sam<<"sbin: "<<sysbin<<
364  // "entr: "<<entries[obs][sam][sysbin]<<
365  // " rnd "<<grnd<<" w"<<weights[obs][sam][0]<<
366  // " wsys"<<weights[obs][sam][sysbin+1]<<endl;
367  } // Loop over systematic bin
368  } // Loop over samples
369  // cout<<obs<<": observed "<<observed<<" sys "<<observed_sys<<endl;
370  if( (observed <= 0 && powers[obs]*(-1) < 0) || (observed_sys <= 0 && powers[obs] < 0) ) Denom_is0 = true;
371  else {
372  // cout<<obs<<": pow observed "<<pow(observed, powers[obs]*(-1))<<" powsys "<<pow(observed_sys, powers[obs])<<endl;
373  // cout<<"before "<<fKappaRelShift[irep]<<endl;
374  // cout<<"mult fact: "<<(pow(observed, powers[obs]*(-1))*pow(observed_sys, powers[obs]))<<endl;
375  fKappaRelShift[irep] *= (pow(observed, powers[obs]*(-1))*pow(observed_sys, powers[obs]));
376  // cout<<"after "<<fKappaRelShift[irep]<<endl;
377  }
378  // cout<<"fKappaRelShift "<<fKappaRelShift[irep]<<endl;
379  } // Loop over number of observables going into kappa
380  fKappaRelShift[irep] -=1.;
381  if(Denom_is0 && fKappaRelShift[irep]==0) {
382  fKappaRelShift.pop_back();
383  nbadk++;
384  } else {
385  if(Denom_is0) fKappaRelShift[irep] = bignum;
386  else mean += fKappaRelShift[irep];
387  irep++;
388  }
389  // cout<<"fKappaRelShift "<<fKappaRelShift[irep]<<endl;
390  } // Loop over fluctuations of kappa (repetitions)
391  int ntot(nrep-nbadk);
392  mean /= static_cast<double>(ntot);
393 
394  sort(fKappaRelShift.begin(), fKappaRelShift.end());
395  double gSigma = intGaus(0,1,0,1);
396  int iMedian((nrep-nbadk+1)/2-1);
397  int imSigma(iMedian-static_cast<int>(gSigma*ntot)), ipSigma(iMedian+static_cast<int>(gSigma*ntot));
398  float median(fKappaRelShift[iMedian]);
399  mSigma = median-fKappaRelShift[imSigma]; pSigma = fKappaRelShift[ipSigma]-median;
400 
401  // Finding standard value
402  float stdRelShift(1.);
403  bool infStd(false);
404  for(unsigned obs(0); obs < powers.size(); obs++) {
405  float observed(0.), observed_sys(0.);
406  for(unsigned sam(0); sam < entries[obs].size(); sam++) {
407  for(unsigned sysbin(0); sysbin < entries[obs][sam].size(); sysbin++) {
408  observed += entries[obs][sam][sysbin]*weights[obs][sam][0];
409  observed_sys += entries[obs][sam][sysbin]*weights[obs][sam][0]*weights[obs][sam][sysbin+1];
410  }
411  }
412  if( (observed <= 0 && powers[obs]*(-1) < 0) || (observed_sys <= 0 && powers[obs] < 0) ) infStd = true;
413  else stdRelShift *= pow(observed, powers[obs]*(-1))*pow(observed_sys, powers[obs]);
414  } // Loop over number of observables going into kappa
415  stdRelShift -=1.;
416  //if I want to pick up the mean instead:
417  stdRelShift = median;
418  cout<<"Standard rel. shift = "<<stdRelShift<<" median = "<<median<<endl;
419  if(infStd) stdRelShift = median;
420  else {
421  int istd(0);
422  for(int rep(0); rep < ntot; rep++) {
423  if(fKappaRelShift[rep]>stdRelShift) {istd = rep; break;}
424  }
425  imSigma = istd-static_cast<int>(gSigma*ntot);
426  ipSigma = istd+static_cast<int>(gSigma*ntot);
427  if(imSigma<0){ // Adjusting the length of the interval in case imSigma has less than 1sigma
428  ipSigma += (-imSigma);
429  imSigma = 0;
430  }
431  if(ipSigma>=ntot){ // Adjusting the length of the interval in case ipSigma has less than 1sigma
432  imSigma -= (ipSigma-ntot+1);
433  ipSigma = ntot-1;
434  }
435  mSigma = stdRelShift-fKappaRelShift[imSigma];
436  pSigma = fKappaRelShift[ipSigma]-stdRelShift;
437  }
438 
439  int nbins(100);
440  double minH(stdRelShift-3*mSigma), maxH(stdRelShift+3*pSigma);
441  if(minH < fKappaRelShift[0]) minH = fKappaRelShift[0];
442  if(maxH > fKappaRelShift[ntot-1]) maxH = fKappaRelShift[ntot-1];
443  TH1D histo("h","",nbins, minH, maxH);
444  for(int rep(0); rep < ntot; rep++)
445  histo.Fill(fKappaRelShift[rep]);
446  histo.SetBinContent(1, histo.GetBinContent(1)+nbadk);
447  histo.SetBinContent(nbins, histo.GetBinContent(nbins)+histo.GetBinContent(nbins+1));
448  histo.SetMaximum(histo.GetMaximum()*1.2);
449  histo.Draw();
450  can.SaveAs("plots/test_"+label+".pdf");
451 
452  double mode(histo.GetBinLowEdge(histo.GetMaximumBin()));
453  cout<<"Std kappa = "<<stdRelShift<<"+"<<pSigma<<"-"<<mSigma<<". Mean = "<<mean
454  <<". Mode = "<<mode<<". Median = "<<median<<endl;
455 
456  return stdRelShift;
457 }
458 
459 
double getSysWeight()
long getYieldErr(TChain &tree, TString cut, double &yield, double &uncertainty)
void setDefaultStyle()
Definition: styles.cpp:36
bool Contains(const std::string &text, const std::string &pattern)
float LabelSize
Definition: styles.hpp:35
STL namespace.
double intGaus(double mean, double sigma, double minX, double maxX)
double calcKappaRelUnc(vector< vector< vector< int > > > &entries, vector< vector< vector< float > > > &weights, vector< float > &powers, float &mSigma, float &pSigma, TString label)
TString RoundNumber(double num, int decimals, double denom=1.)
Definition: utilities.cpp:191
tuple file
Definition: parse_card.py:238
int main()
double gsl_ran_gamma(const double a, const double b, TRandom3 &rand)