21 #include "TGraphAsymmErrors.h" 44 void plotKappa(vector<vector<double> > &vx, vector<vector<double> > &vy, vector<vector<double> > &vexl,
45 vector<vector<double> > &vexh, vector<vector<double> > &veyl, vector<vector<double> > &veyh,
46 unsigned idata, TH1D &histo, vector<TString> &nbcuts);
47 int main(
int argc,
char *argv[]){
48 float time_setup(0.), time_ntu(0.), time_gen(0.);
49 time_t begtime, endtime;
53 while((c=getopt(argc, argv,
"m:n:to12j"))!=-1){
81 TString folder=
"/cms5r0/rohan/archive/"+
ntuple_date+
"/skim/";
82 TString folder_1l=
"/cms5r0/rohan/archive/"+
ntuple_date+
"/skim_1l/";
83 TString folder_2l=
"/cms5r0/rohan/archive/"+
ntuple_date+
"/skim_2l/";
84 TString folder_genht=
"/cms5r0/rohan/archive/"+
ntuple_date+
"/skim_genht/";
88 s_tt.push_back(folder_genht+
"*_TTJets*SingleLept*");
89 s_tt.push_back(folder_1l+
"*_TTJets*HT*");
92 s_tt.push_back(folder_genht+
"*_TTJets*DiLept*");
93 s_tt.push_back(folder_2l+
"*_TTJets*HT*");
96 s_tt.push_back(folder_genht+
"*_TTJets*Lept*");
97 s_tt.push_back(folder+
"*_TTJets*HT*");
100 vector<sfeats> Samples;
101 Samples.push_back(
sfeats(s_tt,
"t#bar{t}", 46,1));
104 vector<int> ra4_sam, ra4_sam_ns;
105 unsigned nsam(Samples.size());
106 for(
unsigned sam(0); sam < nsam; sam++){
107 ra4_sam.push_back(sam);
111 vector<TChain *> chain;
112 for(
unsigned sam(0); sam < Samples.size(); sam++){
113 chain.push_back(
new TChain(
"tree"));
114 for(
unsigned insam(0); insam < Samples[sam].file.size(); insam++)
115 chain[sam]->Add(Samples[sam].
file[insam]);
118 float mSigma, pSigma;
119 vector<float> powersk;
120 vector<TString> cuts;
122 powersk.push_back(-1); cuts.push_back(
"mt<=140");
123 powersk.push_back(1); cuts.push_back(
"mt>140");
125 powersk.push_back(-1); cuts.push_back(
"mj<="+
mjthresh);
126 powersk.push_back(1); cuts.push_back(
"mj>"+
mjthresh);
129 TString baseline(
"ht>500&&met>200&&(nmus+nels)==1");
130 if(
do_mj200) baseline +=
"&&mj>200";
131 if(
do_2l) baseline =
"(nmus+nels)==2&&ht>500&&met>200&&njets>=6&&nbm>=1";
132 vector<TString> mjcuts, njcuts, nbcuts, mjnames, njnames;
136 njcuts.push_back(
"njets==4");
137 njcuts.push_back(
"njets==5");
138 njcuts.push_back(
"njets==6");
139 njcuts.push_back(
"njets==7");
140 njcuts.push_back(
"njets==8");
141 njcuts.push_back(
"njets==9");
142 njcuts.push_back(
"njets==10");
143 njcuts.push_back(
"njets>=11");
147 njcuts.push_back(
"njets<=7");
148 njcuts.push_back(
"njets>=8");
150 if(
do_2l) nbcuts.push_back(
"nbm<=2");
152 nbcuts.push_back(
"nbm==1");
153 nbcuts.push_back(
"nbm>=2");
157 for(
unsigned imj(0); imj<mjcuts.size(); imj++){
158 mjnames.push_back(mjcuts[imj]);
159 mjnames[imj].ReplaceAll(
"mj",
"M_{J}");
160 mjnames[imj].ReplaceAll(
"<=",
" #leq ");
161 mjnames[imj].ReplaceAll(
"==",
" = ");
162 mjnames[imj].ReplaceAll(
">",
" > ");
165 for(
unsigned inj(0); inj<njcuts.size(); inj++){
166 njnames.push_back(njcuts[inj]);
167 njnames[inj].ReplaceAll(
"njets",
"n_{j}");
168 njnames[inj].ReplaceAll(
">=",
" #geq ");
169 njnames[inj].ReplaceAll(
"==",
" = ");
172 float minh(0), maxh(mjcuts.size()*njcuts.size()), wtot(maxh-minh);
173 float wmj(wtot/static_cast<float>(mjcuts.size()));
174 float wnj(wmj/static_cast<float>(njcuts.size()));
175 float wnb(wnj/static_cast<float>(nbcuts.size()+4));
178 vector<vector<vector<double> > > vx, vy, vexl, vexh, veyl, veyh;
179 for(
unsigned idata(0); idata<4; idata++){
180 vx.push_back (vector<vector<double> >());
181 vy.push_back (vector<vector<double> >());
182 vexl.push_back(vector<vector<double> >());
183 vexh.push_back(vector<vector<double> >());
184 veyl.push_back(vector<vector<double> >());
185 veyh.push_back(vector<vector<double> >());
186 for(
unsigned inb(0); inb<nbcuts.size(); inb++){
187 vx[idata].push_back (vector<double>());
188 vy[idata].push_back (vector<double>());
189 vexl[idata].push_back(vector<double>());
190 vexh[idata].push_back(vector<double>());
191 veyl[idata].push_back(vector<double>());
192 veyh[idata].push_back(vector<double>());
196 time(&endtime); time_setup = difftime(endtime, begtime);
200 for(
unsigned imj(0); imj<mjcuts.size(); imj++){
201 for(
unsigned inj(0); inj<njcuts.size(); inj++){
202 for(
unsigned inb(0); inb<nbcuts.size(); inb++){
203 vector<vector<float> > entries;
204 vector<vector<float> > weights;
205 for(
unsigned obs(0); obs < powersk.size(); obs++) {
206 entries.push_back(vector<float>());
207 weights.push_back(vector<float>());
208 float yield_singlet(0);
209 for(
unsigned sam(0); sam < ra4_sam.size(); sam++) {
210 totcut = (
lumi+
"*weight*("+baseline+
"&&"+nbcuts[inb]+
"&&"+mjcuts[imj]+
"&&"+cuts[obs]+
211 "&&"+Samples[ra4_sam[sam]].cut);
212 totcut +=
"&&"+njcuts[inj]+
")";
213 cout << totcut<<endl;
214 double yield(0.), sigma(0.), avWeight(1.);
216 Nentries =
getYieldErr(*chain[ra4_sam[sam]], totcut, yield, sigma);
218 if(Samples[ra4_sam[sam]].label==
"Single t"){
219 if(yield>0) yield_singlet = yield;
222 if(Samples[ra4_sam[sam]].label==
"Other") yield += yield_singlet;
223 if(yield<=0) entries[obs].push_back(0);
226 else entries[obs].push_back(Nentries);
229 totcut = (
lumi+
"*weight*("+baseline+
"&&"+cuts[obs]+
")");
230 Nentries =
getYieldErr(*chain[ra4_sam[sam]], totcut, yield, sigma);
233 totcut = (
lumi+
"*weight*("+baseline+
")");
234 Nentries =
getYieldErr(*chain[ra4_sam[sam]], totcut, yield, sigma);
238 else avWeight = fabs(yield/static_cast<double>(Nentries));
239 weights[obs].push_back(avWeight);
244 time(&endtime); time_ntu += difftime(endtime, begtime);
246 for(
unsigned idata(0); idata<1; idata++){
247 if(
do_2l && idata>=2)
continue;
249 kappa =
calcKappa(entries, weights, powersk, mSigma, pSigma, (idata%2)==1,
false);
250 float xpoint = inj*wnj+imj*wmj+(inb+2)*wnb;
251 vx[idata][inb].push_back(xpoint);
252 vy[idata][inb].push_back(kappa);
253 vexl[idata][inb].push_back(0);
254 vexh[idata][inb].push_back(0);
255 veyl[idata][inb].push_back(mSigma);
256 veyh[idata][inb].push_back(pSigma);
258 time(&endtime); time_gen += difftime(endtime, begtime);
264 vector<unsigned> ind(nbcuts.size(),0);
266 for(
unsigned imj(0); imj<mjcuts.size(); imj++){
267 for(
unsigned inj(0); inj<njcuts.size(); inj++){
269 float MC(vy[0][inb][ind[inb]]), Data(vy[1][inb][ind[inb]]);
270 float epMC(veyh[0][inb][ind[inb]]), emMC(veyl[0][inb][ind[inb]]);
271 float epData(veyh[1][inb][ind[inb]]), emData(veyl[1][inb][ind[inb]]);
272 float epTotal(sqrt(pow(epMC/MC,2)+pow(epData/Data,2))), emTotal(sqrt(pow(emMC/MC,2)+pow(emData/Data,2)));
274 mjcuts[imj].ReplaceAll(
"mj>200&&",
"");
275 TString cutname = njcuts[inj]+
", "+mjcuts[imj];
286 TH1D histo(
"histo",
cuts2title(baseline),njcuts.size()*mjcuts.size(), minh, maxh);
287 for(
unsigned imj(0); imj<mjcuts.size(); imj++)
288 for(
unsigned inj(0); inj<njcuts.size(); inj++)
289 histo.GetXaxis()->SetBinLabel(1+inj+imj*njcuts.size(), njnames[inj]);
290 for(
unsigned idata(0); idata<1; idata++)
291 plotKappa(vx[idata], vy[idata], vexl[idata], vexh[idata], veyl[idata], veyh[idata], idata, histo, nbcuts);
294 time(&endtime); time_setup += difftime(endtime, begtime);
296 cout<<endl<<
"Total time: set up "<<time_setup<<
" s, finding yields "<<time_ntu
297 <<
" s, toys "<<time_gen<<
" s"<<endl<<endl;
300 void plotKappa(vector<vector<double> > &vx, vector<vector<double> > &vy, vector<vector<double> > &vexl,
301 vector<vector<double> > &vexh, vector<vector<double> > &veyl, vector<vector<double> > &veyh,
302 unsigned idata, TH1D &histo, vector<TString> &nbcuts){
304 bool do_data((idata%2)==1), do_pred(
true);
307 float max_axis(3.2), max_kappa(0.);
308 unsigned nbsize(vx.size());
309 float minh(histo.GetBinLowEdge(1)), maxh(histo.GetBinLowEdge(histo.GetNbinsX()+1));
310 float wtot(maxh-minh);
311 for(
unsigned inb(0); inb<nbsize; inb++){
312 for(
unsigned ik(0); ik<vy[inb].size(); ik++){
313 if((vy[inb][ik]+veyh[inb][ik]) > max_kappa) max_kappa = vy[inb][ik]+veyh[inb][ik];
316 max_axis = max_kappa*1.1;
318 TLine line; line.SetLineColor(28); line.SetLineWidth(4); line.SetLineStyle(3);
320 TString ytitle(
"#kappa^{MC}");
321 if(do_pred) ytitle =
"R_{m_{T}}";
322 histo.SetYTitle(ytitle);
323 histo.SetMaximum(max_axis);
325 if(!do_pred) line.DrawLine(minh, 1, maxh, 1);
326 line.SetLineColor(1); line.SetLineWidth(2);
327 line.DrawLine(minh+wtot/2., 0, minh+wtot/2, max_axis);
329 int acolor(kGreen+3);
330 float alength((maxh-minh)/8.), yarrow(max_axis/15.), llength(max_axis/1.5);
331 TArrow arrow; arrow.SetLineColor(acolor); arrow.SetLineWidth(1); arrow.SetArrowSize(0.02);
332 TLatex label; label.SetNDC(kFALSE);label.SetTextAlign(11); label.SetTextColor(acolor);
333 float binw(histo.GetBinWidth(1));
334 line.SetLineColor(acolor); line.SetLineWidth(1); line.SetLineStyle(2);
335 float xarrow(minh+binw*3);
336 line.DrawLine(xarrow, 0, xarrow, llength);
337 arrow.DrawArrow(xarrow, yarrow, xarrow+alength, yarrow);
338 label.DrawLatex(xarrow+0.1, yarrow+max_axis/80.,
"Baseline");
340 xarrow = minh+wtot/2+binw*3;
341 line.DrawLine(xarrow, 0, xarrow, llength);
342 arrow.DrawArrow(xarrow, yarrow, xarrow+alength, yarrow);
343 label.DrawLatex(xarrow+0.1, yarrow+max_axis/80.,
"Baseline");
345 double legX(style.
PadLeftMargin+0.0), legY(0.88), legSingle = 0.052;
347 double legW = 0.29, legH = legSingle*nbsize;
348 if(nbsize>3) legH = legSingle*((nbsize+1)/2);
349 TLegend
leg(legX, legY-legH, legX+legW, legY);
350 leg.SetTextSize(style.
LegendSize); leg.SetFillColor(0);
351 leg.SetFillStyle(0); leg.SetBorderSize(0);
352 leg.SetTextFont(style.
nFont);
353 if(nbsize>3) leg.SetNColumns(2);
354 TGraphAsymmErrors
graph[20];
355 int colors[] = {2,4,kMagenta+2, kGreen+3},
styles[] = {20, 21, 22, 23};
356 for(
unsigned inb(0); inb<nbsize; inb++){
357 graph[inb] = TGraphAsymmErrors(vx[inb].size(), &(vx[inb][0]), &(vy[inb][0]),
358 &(vexl[inb][0]), &(vexh[inb][0]), &(veyl[inb][0]), &(veyh[inb][0]));
359 graph[inb].SetMarkerStyle(styles[inb]); graph[inb].SetMarkerSize(1.4);
360 graph[inb].SetMarkerColor(colors[inb]); graph[inb].SetLineColor(colors[inb]);
361 graph[inb].Draw(
"p same");
362 nbcuts[inb].ReplaceAll(
"nbm",
"n_{b}");
363 nbcuts[inb].ReplaceAll(
"==",
" = ");
364 nbcuts[inb].ReplaceAll(
">=",
" #geq ");
365 leg.AddEntry(&graph[inb], nbcuts[inb],
"p");
368 label.SetNDC(kTRUE); label.SetTextAlign(22); label.SetTextColor(1);
370 label.DrawLatex(0.37,0.03,
"M_{J} #leq "+
mjthresh);
371 label.DrawLatex(0.73,0.03,
"M_{J} > "+
mjthresh);
373 TString pname =
"plots/ratio_mt";
382 if(do_data) pname +=
"_data";
385 if(do_pred) pname.ReplaceAll(
"kappa",
"npred");
long getYieldErr(TChain &tree, TString cut, double &yield, double &uncertainty)
int main(int argc, char *argv[])
TString cuts2title(TString title)
void moveYAxisLabel(TH1 *h, float maxi, bool isLog=false)
void plotKappa(vector< vector< double > > &vx, vector< vector< double > > &vy, vector< vector< double > > &vexl, vector< vector< double > > &vexh, vector< vector< double > > &veyl, vector< vector< double > > &veyh, unsigned idata, TH1D &histo, vector< TString > &nbcuts)
TString ntuple_date("2015_09_14")
TString RoundNumber(double num, int decimals, double denom=1.)
bool do_sigma_avError(true)
double calcKappa(std::vector< std::vector< float > > &entries, std::vector< std::vector< float > > &weights, std::vector< float > &powers, float &mSigma, float &pSigma, bool do_data=false, bool verbose=false, bool do_plot=false, int nrep=100000)