5 #include "TGraphErrors.h" 23 void GetKappa(
double &
kappa,
double &error, TString baseline,TString external,TString internal_cut,TString ratio_cut,
sfeats Sample,TString
luminosity);
24 void GetRatio(
double &ratio,
double &error, TString baseline,TString external,TString internal_cut,TString ratio_cut,
sfeats Sample, TString
luminosity);
25 void MakeGraph(TString baseline,vector<TString> external,TString internal_cut, TString ratio_cut, vector<sfeats> samples, vector<TString> binlabels, TString
luminosity);
29 TString folder=
"/cms5r0/ald77/archive/2015_05_21/skim/";
30 TString folder_noskim=
"/cms5r0/ald77/archive/2015_05_21/";
31 vector<TString> s_t1t;
32 s_t1t.push_back(folder+
"*T1tttt*1500_*PU20*");
33 vector<TString> s_t1tc;
34 s_t1tc.push_back(folder+
"*T1tttt*1200_*PU20*");
36 s_tt.push_back(folder+
"*_TTJet*");
37 vector<TString> s_tt_noskim;
38 s_tt_noskim.push_back(folder_noskim+
"*_TTJet*12.root");
39 vector<TString> s_wjets;
40 s_wjets.push_back(folder+
"*WJetsToLNu_HT*");
41 vector<TString> s_singlet;
42 s_singlet.push_back(folder+
"*_T*channel*");
43 vector<TString> s_ttv;
44 s_ttv.push_back(folder+
"*TTW*");
45 s_ttv.push_back(folder+
"*TTZ*");
46 vector<TString> s_other;
47 s_other.push_back(folder+
"*QCD_HT*");
48 s_other.push_back(folder+
"*_ZJet*");
49 s_other.push_back(folder+
"*DY*");
50 s_other.push_back(folder+
"*WH_HToBB*");
53 vector<sfeats> Samples;
64 Samples.push_back(
sfeats(s_tt,
"t#bar{t} 5j", 1, 1,
"njets==5"));
65 Samples.push_back(
sfeats(s_tt,
"t#bar{t} 6j", 2, 1,
"njets==6"));
66 Samples.push_back(
sfeats(s_tt,
"t#bar{t} 7j", 4, 1,
"njets==7"));
67 Samples.push_back(
sfeats(s_tt,
"t#bar{t} 8j", 8, 1,
"njets==8"));
68 Samples.push_back(
sfeats(s_tt,
"t#bar{t} 9+j", 15, 1,
"njets>=9"));
70 Samples.push_back(
sfeats(s_tt,
"t#bar{t}", 15, 1));
83 vector<int> ra4_tt_t1;
84 ra4_tt_t1.push_back(0);
85 ra4_tt_t1.push_back(1);
86 ra4_tt_t1.push_back(2);
89 TString baseline =
"ht>500&&met>200&&nbm>=2&&(nmus+nels)==1";
91 vector<TString> externalvec;
92 externalvec.push_back(
"njets>=6&&njets<=7&&met>200&&met<=400&&nbm==2");
93 externalvec.push_back(
"njets>=6&&njets<=7&&met>200&&met<=400&&nbm>=3");
94 externalvec.push_back(
"njets>=6&&njets<=7&&met>400&&nbm>=2");
95 externalvec.push_back(
"njets>=8&&met>200&&met<=400&&nbm==2");
96 externalvec.push_back(
"njets>=8&&met>200&&met<=400&&nbm>=3");
97 externalvec.push_back(
"njets>=8&&met>400&&nbm>=2");
99 TString internal_cut =
"mj>400";
101 TString ratio_cut =
"mt>140";
103 vector<sfeats> samples_MJ;
104 samples_MJ.push_back(
sfeats(s_tt,
"t#bar{t}", 31, 1));
106 vector<TString> binlabels;
107 binlabels.push_back(
"n_{B}=2, low MET");binlabels.push_back(
"n_{B}=3+, low MET");binlabels.push_back(
"n_{B}=2+, high MET");
108 binlabels.push_back(
"n_{B}=2, low MET");binlabels.push_back(
"n_{B}=3+, low MET");binlabels.push_back(
"n_{B}=2+, high MET");
110 MakeGraph(baseline,externalvec,internal_cut,ratio_cut,samples_MJ,binlabels,luminosity);
113 void MakeGraph(TString baseline,vector<TString> external,TString internal_cut,TString ratio_cut, vector<sfeats> samples, vector<TString> binlabels,TString
luminosity){
115 TString not_internal_cut =
invertcut(internal_cut);
117 int nsamples = samples.size();
118 vector<TGraphErrors*>
graphs;
119 TGraphErrors* kappas;
121 int nR =
static_cast<int>(external.size());
123 vector<double> x_err;
125 for(
int isam = 0; isam<nsamples; isam++){
127 vector<double> R_err;
129 for(
int iR=0;iR<nR;iR++){
133 GetRatio(rholder,r_errholder,baseline,external[iR],internal_cut,ratio_cut,samples.at(isam),
luminosity);
134 R.push_back(rholder);
135 R_err.push_back(r_errholder);
141 TGraphErrors *g1 =
new TGraphErrors(nR,&x[0],&R[0],&x_err[0],&R_err[0]);
142 graphs.push_back(g1);
147 for(
int iR=0;iR<nR;iR++){
151 GetRatio(rholder,r_errholder,baseline,external[iR],not_internal_cut,ratio_cut,samples.at(isam),
luminosity);
152 R.push_back(rholder);
153 R_err.push_back(r_errholder);
159 TGraphErrors *g2 =
new TGraphErrors(nR,&x[0],&R[0],&x_err[0],&R_err[0]);
160 graphs.push_back(g2);
162 for(
int imax = 0;imax<nR;imax++){
163 if(R[imax]>max) max=R[imax];
166 vector<double>
kappa;
167 vector<double> kappa_err;
168 for(
int iR=0;iR<nR;iR++){
172 GetKappa(kholder,k_errholder,baseline,external[iR],internal_cut,ratio_cut,samples.at(0),
luminosity);
173 kappa.push_back(kholder);
174 kappa_err.push_back(k_errholder);
177 kappas =
new TGraphErrors(nR,&x[0],&kappa[0],&x_err[0],&kappa_err[0]);
182 TString plot_tag(
"_lumi"+luminosity+
".eps");
185 TH1F *h =
new TH1F(
"for_axis_label",
cuts2title(baseline),nR,-0.5,nR-0.5);
186 for (
int ih=1;ih<=nR;ih++){ h->GetXaxis()->SetBinLabel(ih,
cuts2title(external[ih-1]));
187 if(external[0].
Contains(
"nbm")) h->GetXaxis()->SetBinLabel(ih,binlabels[ih-1]);
191 h->SetMaximum(1.5*max);
193 if(ratio_cut.Contains(
"mt")){
194 h->GetYaxis()->SetTitle(
"R_{mT}");
196 else {
if(ratio_cut.Contains(
"400")) h->GetYaxis()->SetTitle(
"R_{MJ 400}");
197 if(ratio_cut.Contains(
"500")) h->GetYaxis()->SetTitle(
"R_{MJ 500}");
198 if(ratio_cut.Contains(
"600")) h->GetYaxis()->SetTitle(
"R_{MJ 600}");
200 h->GetXaxis()->SetLabelSize(0.03);
203 double legX = 0.65, legY = 0.89, legSingle = 0.14;
204 double legW = 0.22, legH = legSingle;
205 TLegend
leg(legX, legY-legH, legX+legW, legY);
206 leg.SetTextSize(0.057); leg.SetFillColor(0); leg.SetFillStyle(0); leg.SetBorderSize(0);
207 leg.SetTextFont(132);
209 for(
int ig = 0;ig<nsamples;ig++){
210 graphs.at(0)->SetMarkerStyle(20);
211 graphs.at(0)->SetMarkerColor(31);
212 graphs.at(0)->SetLineColor(31);
213 graphs.at(0)->Draw(
"PZ");
214 leg.AddEntry(graphs.at(0), samples.at(ig).label+
" "+
cuts2title(internal_cut),
"p");
216 graphs.at(1)->SetMarkerStyle(20);
217 graphs.at(1)->SetMarkerColor(46);
218 graphs.at(1)->SetLineColor(46);
219 graphs.at(1)->Draw(
"PZ");
220 leg.AddEntry(graphs.at(1), samples.at(ig).label+
" "+
cuts2title(not_internal_cut),
"p");
225 TLine line; line.SetLineColor(28); line.SetLineWidth(4); line.SetLineStyle(2);
226 if(external[0].
Contains(
"nbm")){ line.DrawLine(2.5, 0, 2.5, 1.5*max);
227 TLatex *text67 =
new TLatex(0.35,0.03,
"n_{jets}= 6-7");
229 text67->SetTextSize(0.03);
230 text67->SetLineWidth(2);
232 TLatex *text8 =
new TLatex(0.7,0.03,
"n_{jets}#geq 8");
234 text8->SetTextSize(0.03);
235 text8->SetLineWidth(2);
240 TString pname1 =
"plots/ratios/ratios_"+
format_tag(ratio_cut+samples.at(0).cut+external[0]+baseline)+
".eps";
243 graphs.at(0)->Delete();
244 graphs.at(1)->Delete();
251 h->GetYaxis()->SetTitle(
"\\kappa");
254 kappas->SetMarkerStyle(20);
255 kappas->SetMarkerColor(kBlack);
256 kappas->SetLineColor(kBlack);
258 line.DrawLine(h->GetBinLowEdge(1), 1, h->GetBinLowEdge(h->GetNbinsX()+1), 1);
260 if(external[0].
Contains(
"nbm")){ line.DrawLine(2.5, 0, 2.5, 1.5*max);
261 TLatex *text67 =
new TLatex(0.35,0.03,
"n_{jets}= 6-7");
263 text67->SetTextSize(0.03);
264 text67->SetLineWidth(2);
266 TLatex *text8 =
new TLatex(0.7,0.03,
"n_{jets}= 8");
268 text8->SetTextSize(0.03);
269 text8->SetLineWidth(2);
273 TString pname2 =
"plots/ratios/kappa_"+
format_tag(ratio_cut+samples.at(0).cut+external[0]+baseline)+
".eps";
278 void GetRatio(
double &ratio,
double &error, TString baseline,TString external,TString internal_cut,TString ratio_cut,
sfeats Sample,TString
luminosity){
280 TChain * chain =
new TChain(
"tree");
281 for(
unsigned insam(0); insam < Sample.
file.size(); insam++)
282 chain->Add(Sample.
file[insam]);
284 TH1D h_numerator(
"num",
"",100, 0, 10000);
286 TH1D h_denominator(
"den",
"",100, 0, 10000);
287 h_denominator.Sumw2();
288 TH1D h_weight(
"weight",
"",2000, 0, 2);
291 TString numCut = luminosity+
"*weight*("+baseline+
"&&"+external+
"&&"+internal_cut+
"&&"+ratio_cut+
"&&"+Sample.
cut+
")";
292 TString denCut = luminosity+
"*weight*("+baseline+
"&&"+external+
"&&"+internal_cut+
"&&!("+ratio_cut+
")&&"+Sample.
cut+
")";
294 chain->Project(
"num",
"met", numCut);
295 chain->Project(
"den",
"met", denCut);
296 chain->Project(
"weight",
"weight*"+luminosity);
298 double weight = h_weight.GetMean();
300 double numerator, denominator,numerator_err, denominator_err;
301 numerator = h_numerator.IntegralAndError(0,101,numerator_err);
302 denominator = h_denominator.IntegralAndError(0,101,denominator_err);
304 if(numerator==0 && denominator==0){
308 else if(numerator==0){
310 numerator_err = weight;
312 else if(denominator==0){
313 denominator = weight*1.;
314 denominator_err = weight;
316 ratio = numerator/denominator;
317 error = sqrt(pow(numerator_err/denominator,2)+pow(numerator/pow(denominator,2)*denominator_err,2));
322 if( !(external.Contains(
">" )&& internal_cut.Contains(
">")) )
323 cout<<
"WARNING: GetKappa needs \"external\" and \"internal_cut\" to use a \">\" sign"<<endl;
325 TChain * chain =
new TChain(
"tree");
326 for(
unsigned insam(0); insam < Sample.
file.size(); insam++)
327 chain->Add(Sample.
file[insam]);
330 TH1D h_yields1(
"yields1",
"",100, 0, 10000);
332 TH1D h_yields2(
"yields2",
"",100, 0, 10000);
334 TH1D h_yields3(
"yields3",
"",100, 0, 10000);
336 TH1D h_yields4(
"yields4",
"",100, 0, 10000);
338 TH1D h_weight(
"weight",
"",2000, 0, 2);
341 TString yields1Cut = luminosity+
"*weight*("+baseline+
"&&"+external+
"&&!("+internal_cut+
")&&!("+ratio_cut+
")&&"+Sample.
cut+
")";
342 TString yields2Cut = luminosity+
"*weight*("+baseline+
"&&"+external+
"&&!("+internal_cut+
")&&"+ratio_cut+
"&&"+Sample.
cut+
")";
343 TString yields3Cut = luminosity+
"*weight*("+baseline+
"&&"+external+
"&&"+internal_cut+
"&&!("+ratio_cut+
")&&"+Sample.
cut+
")";
344 TString yields4Cut = luminosity+
"*weight*("+baseline+
"&&"+external+
"&&"+internal_cut+
"&&"+ratio_cut+
"&&"+Sample.
cut+
")";
346 chain->Project(
"yields1",
"met", yields1Cut);
347 chain->Project(
"yields2",
"met", yields2Cut);
348 chain->Project(
"yields3",
"met", yields3Cut);
349 chain->Project(
"yields4",
"met", yields4Cut);
350 chain->Project(
"weight",
"weight*"+luminosity);
352 double weight = h_weight.GetMean();
354 double n1, n2, n3, n4, n1_err, n2_err, n3_err, n4_err;
355 n1 = h_yields1.IntegralAndError(0,101,n1_err);
356 n2 = h_yields2.IntegralAndError(0,101,n2_err);
357 n3 = h_yields3.IntegralAndError(0,101,n3_err);
358 n4 = h_yields4.IntegralAndError(0,101,n4_err);
386 kappa = (n4*n1)/(n3*n2);
387 error = sqrt(pow((n4/(n2*n3))*n1_err,2)+pow((n1/(n2*n3))*n4_err,2)+pow(((n1*n4)/(pow(n2,2)*n3))*n2_err,2)+pow(((n1*n4)/(n2*pow(n3,2)))*n3_err,2));
void GetRatio(double &ratio, double &error, TString baseline, TString external, TString internal_cut, TString ratio_cut, sfeats Sample, TString luminosity)
bool Contains(const std::string &text, const std::string &pattern)
TString cuts2title(TString title)
void GetKappa(double &kappa, double &error, TString baseline, TString external, TString internal_cut, TString ratio_cut, sfeats Sample, TString luminosity)
TString format_tag(TString tag)
std::vector< TString > file
void MakeGraph(TString baseline, vector< TString > external, TString internal_cut, TString ratio_cut, vector< sfeats > samples, vector< TString > binlabels, TString luminosity)
TString invertcut(TString cut)