8 #include "RooStats/NumberCountingUtils.h" 23 auto pos_1 = x.find(
"\\");
24 auto pos_2 = x.find(
"_");
25 auto pos_3 = x.find(
"^");
26 auto pos_4 = x.find(
"{");
27 auto pos_5 = x.find(
"}");
28 if(pos_1 != string::npos
29 || pos_2 != string::npos
30 || pos_3 != string::npos
31 || pos_4 != string::npos
32 || pos_5 != string::npos){
40 const shared_ptr<Process> &process):
41 FigureComponent(table, process),
42 sumw_(table.
rows_.size(), 0.),
43 sumw2_(table.
rows_.size(), 0.),
44 proc_and_table_cut_(table.
rows_.size(), process->cut_),
48 for(
size_t irow = 0; irow < table.
rows_.size(); ++irow){
49 proc_and_table_cut_.at(irow) = table.
rows_.at(irow).cut_ && process->cut_;
54 const Table& table =
static_cast<const Table&
>(figure_);
58 for(
size_t irow = 0; irow < table.
rows_.size(); ++irow){
64 const NamedFunc &cut = proc_and_table_cut_.at(irow);
72 if(!have_vector || cut_vector_.size() < min_vec_size){
74 min_vec_size = cut_vector_.size();
83 if(!have_vector || wgt_vector_.size() < min_vec_size){
85 min_vec_size = wgt_vector_.size();
90 sumw_.at(irow) += wgt_scalar;
91 sumw2_.at(irow) += wgt_scalar*wgt_scalar;
93 for(
size_t iobject = 0; iobject < min_vec_size; ++iobject){
95 if(!this_cut)
continue;
97 sumw_.at(irow) += this_wgt;
98 sumw2_.at(irow) += this_wgt*this_wgt;
105 const vector<TableRow> &rows,
106 const vector<shared_ptr<Process> > &processes,
114 print_table_(print_table),
115 print_pie_(print_pie),
116 plot_options_({
PlotOpt(
"txt/plot_styles.txt",
"Pie")}),
120 for(
const auto &process: processes){
121 switch(process->type_){
123 datas_.emplace_back(
new TableColumn(*
this, process));
126 backgrounds_.emplace_back(
new TableColumn(*
this, process));
129 signals_.emplace_back(
new TableColumn(*
this, process));
140 const string &subdir){
141 if(!print_table_)
return;
142 if(subdir !=
"") mkdir((
"tables/"+subdir).c_str(), 0777);
143 string file_name = subdir !=
"" 144 ?
"tables/"+subdir+
"/"+name_+
"_lumi_"+
ToString(luminosity)+
".tex" 145 :
"tables/"+name_+
"_lumi_"+
ToString(luminosity)+
".tex";
146 std::ofstream file(file_name);
147 file << fixed << setprecision(1);
149 for(
size_t i = 0; i < rows_.size(); ++i){
150 PrintRow(file, i, luminosity);
155 cout <<
"pdflatex " << file_name <<
" &> /dev/null; #./python/texify.py tables" << endl;
160 const auto &component_list = GetComponentList(process);
162 for(
const auto &component: component_list){
163 if(component->process_.get() == process){
164 col =
static_cast<const TableColumn *
>(component.get());
167 if(col ==
nullptr)
return vector<GammaParams>();
168 vector<GammaParams> yields(rows_.size());
169 for(
size_t i = 0; i < yields.size(); ++i){
170 yields.at(i).SetYieldAndUncertainty(luminosity*col->
sumw_.at(i), luminosity*sqrt(col->
sumw2_.at(i)));
176 vector<GammaParams> yields(rows_.size());
177 auto procs = GetProcesses();
178 for(
const auto &proc: procs){
180 vector<GammaParams> proc_yields = Yield(proc, luminosity);
181 for(
size_t i = 0; i < proc_yields.size(); ++i){
182 yields.at(i) += proc_yields.at(i);
189 vector<GammaParams> yields(rows_.size());
190 auto procs = GetProcesses();
191 for(
const auto &proc: procs){
193 vector<GammaParams> proc_yields = Yield(proc, 1.);
194 for(
size_t i = 0; i < proc_yields.size(); ++i){
195 yields.at(i) += proc_yields.at(i);
202 set<const Process*> processes;
203 for(
const auto &proc: backgrounds_){
204 processes.insert(proc->process_.get());
206 for(
const auto &proc: signals_){
207 processes.insert(proc->process_.get());
209 for(
const auto &proc: datas_){
210 processes.insert(proc->process_.get());
216 const auto &component_list = GetComponentList(process);
217 for(
const auto &component: component_list){
218 if(component->process_.get() == process){
219 return component.get();
222 DBG(
"Could not find histogram for process "+process->
name_+
".");
227 switch(process->
type_){
235 ERROR(
"Did not understand process type "+to_string(static_cast<long>(process->
type_))+
".");
240 file <<
"\\documentclass[10pt,oneside]{report}\n";
241 file <<
"\\usepackage{graphicx,xspace,amssymb,amsmath,colordvi,colortbl,verbatim,multicol}\n";
242 file <<
"\\usepackage{multirow, rotating}\n\n";
244 file <<
"\\begin{document}\n";
245 file <<
"\\begin{sidewaystable}[tbp!]\n";
246 file <<
" \\centering\n";
247 file <<
" \\begin{tabular}{ l";
249 if(backgrounds_.size() > 1){
251 for(
size_t i = 0; i < backgrounds_.size(); ++i){
255 }
else if(backgrounds_.size() == 1){
259 if(datas_.size() > 1){
261 for(
size_t i = 0; i < datas_.size(); ++i){
265 }
else if(datas_.size() == 1){
269 for(
size_t i = 0; i < signals_.size(); ++i){
270 if(do_zbi_) file <<
" | rr";
275 file <<
" \\hline\\hline\n";
278 if(backgrounds_.size() > 1){
279 for(
size_t i = 0; i < backgrounds_.size(); ++i){
280 file <<
" & " <<
ToLatex(backgrounds_.at(i)->process_->name_);
282 file <<
" & SM Bkg.";
283 }
else if(backgrounds_.size() == 1){
284 file <<
" & " <<
ToLatex(backgrounds_.front()->process_->name_);
287 if(datas_.size() > 1){
289 for(
size_t i = 0; i < datas_.size(); ++i){
290 file <<
" & " <<
ToLatex(datas_.at(i)->process_->name_);
292 file <<
" & Data Tot.";
293 }
else if(datas_.size() == 1){
294 file <<
" & " <<
ToLatex(datas_.front()->process_->name_);
297 for(
size_t i = 0; i < signals_.size(); ++i){
298 file <<
" & " <<
ToLatex(signals_.at(i)->process_->name_);
300 file <<
" & $Z_{\\text{Bi}}$";
307 const TableRow& row = rows_.at(irow);
317 file <<
" " << row.
label_;
318 if(backgrounds_.size() > 1){
319 for(
size_t i = 0; i < backgrounds_.size(); ++i){
320 file <<
" & " << luminosity*backgrounds_.at(i)->sumw_.at(irow);
322 file <<
" & " << luminosity*GetYield(backgrounds_, irow) <<
"$\\pm$" << luminosity*GetError(backgrounds_, irow);
323 }
else if(backgrounds_.size() == 1){
324 file <<
" & " << luminosity*GetYield(backgrounds_, irow) <<
"$\\pm$" << luminosity*GetError(backgrounds_, irow);
327 if(datas_.size() > 1){
328 for(
size_t i = 0; i < datas_.size(); ++i){
329 file <<
" & " << datas_.at(i)->sumw_.at(irow);
331 file <<
" & " << GetYield(datas_, irow);
332 }
else if(datas_.size() == 1){
333 file <<
" & " << GetYield(datas_, irow);
336 for(
size_t i = 0; i < signals_.size(); ++i){
337 file <<
" & " << luminosity*signals_.at(i)->sumw_.at(irow);
339 file <<
" & " << RooStats::NumberCountingUtils::BinomialExpZ(luminosity*signals_.at(i)->sumw_.at(irow),
340 luminosity*GetYield(backgrounds_, irow),
341 hypot(GetError(backgrounds_, irow)/GetYield(backgrounds_, irow), 0.3));
345 file <<
" \\multicolumn{" << NumColumns() <<
"}{c}{" << row.
label_ <<
"}";
358 if(print_pie_) PrintPie(irow, luminosity);
362 size_t Nbkg = backgrounds_.size();
363 float Yield_tt = 0, Yield_tot = luminosity*GetYield(backgrounds_, irow);
364 vector<double> counts(Nbkg);
365 vector<int> colors(Nbkg);
366 vector<const char*> labels(Nbkg);
367 vector<TH1D> histos(Nbkg, TH1D(
"",
"",1,-1.,1.));
368 TLegend leg(0., 0., 1., 1.);
369 for(
size_t ind = 0; ind < Nbkg; ++ind){
370 counts[ind] = luminosity*backgrounds_.at(ind)->sumw_.at(irow);
371 histos[ind].SetFillColor(backgrounds_.at(ind)->process_->GetFillColor());
372 colors.at(ind) = backgrounds_.at(ind)->process_->GetFillColor();
373 string label = backgrounds_.at(ind)->process_->name_;
374 leg.AddEntry(&histos[ind], label.c_str(),
"f");
375 labels.at(ind) = label.c_str();
376 if(
Contains(label,
"t#bar{t}") && !
Contains(label,
"t#bar{t}V")) Yield_tt += counts[ind];
381 gStyle->SetTitleW(0.95);
382 TCanvas can(
"",
"", plot_options_[0].CanvasWidth(), plot_options_[0].CanvasHeight());
383 can.SetFillColorAlpha(0, 0.);
384 can.SetFillStyle(4000);
390 plot_name =
"plots/pie_"+name_+
"_legend_lumi"+
RoundNumber(luminosity,0)+
".pdf";
391 can.SaveAs(plot_name.c_str());
392 cout<<
" open "<<plot_name<<endl;
396 TPie pie(
"",
"", Nbkg, &counts.at(0), &colors.at(0), &labels.at(0));
397 pie.SetCircle(0.5, 0.48, 0.35);
399 +
", t#bar{t}="+
RoundNumber(Yield_tt*100,1,Yield_tot).Data()+
"%)").c_str());
402 pie.SetLabelFormat(
"%perc");
405 plot_name =
CodeToPlainText(
"plots/pie_"+name_+
"_"+(rows_.at(irow).cut_.Name())+
"_perc_lumi"+
RoundNumber(luminosity,0).Data()+
".pdf");
407 plot_name =
"plots/pie_"+name_+
"_"+
CodeToPlainText(rows_.at(irow).cut_.Name())+
"_perc_lumi"+
RoundNumber(luminosity,0).Data()+
".pdf";
408 >>>>>>> b1f888b55e7125d5a772cc4a7067bd650781e35f
409 can.SaveAs(plot_name.c_str());
410 cout<<
" open "<<plot_name<<endl;
416 file <<
" \\hline\n";
419 if(backgrounds_.size() > 1){
420 for(
size_t i = 0; i < backgrounds_.size(); ++i){
421 file <<
" & " <<
ToLatex(backgrounds_.at(i)->process_->name_);
423 file <<
" & SM Bkg.";
424 }
else if(backgrounds_.size() == 1){
425 file <<
" & " <<
ToLatex(backgrounds_.front()->process_->name_);
428 if(datas_.size() > 1){
430 for(
size_t i = 0; i < datas_.size(); ++i){
431 file <<
" & " <<
ToLatex(datas_.at(i)->process_->name_);
433 file <<
" & Data Tot.";
434 }
else if(datas_.size() == 1){
435 file <<
" & " <<
ToLatex(datas_.front()->process_->name_);
438 for(
size_t i = 0; i < signals_.size(); ++i){
439 file <<
" & " <<
ToLatex(signals_.at(i)->process_->name_);
441 file <<
" & $Z_{\\text{Bi}}$";
445 file <<
" \\hline\\hline\n";
446 file <<
" \\end{tabular}\n";
447 file <<
"\\end{sidewaystable}\n";
448 file <<
"\\end{document}\n";
453 + (backgrounds_.size() <= 1 ? backgrounds_.size() : backgrounds_.size()+1)
454 + (datas_.size() <= 1 ? datas_.size() : datas_.size()+1)
455 + (do_zbi_ ? 2 : 1)*signals_.size();
461 for(
const auto &column: columns){
462 yield += column->sumw_.at(irow);
470 for(
const auto &column: columns){
471 error += column->sumw2_.at(irow);
void PrintRow(std::ofstream &file, std::size_t irow, double luminosity) const
std::string ToLatex(std::string x)
std::vector< GammaParams > Yield(const Process *process, double luminosity) const
std::set< const Process * > GetProcesses() const final
std::string CodeToPlainText(std::string code)
std::vector< double > sumw2_
Abstract base class for access to ntuple variables.
void ReplaceAll(std::string &str, const std::string &orig, const std::string &rep)
ScalarType GetScalar(const Baby &b) const
Evaluate scalar function with b as argument.
Combines a callable function taking a Baby and returning a scalar or vector with its string represent...
bool Contains(const std::string &str, const std::string &pat)
std::size_t NumColumns() const
void PrintPie(std::size_t irow, double luminosity) const
bool IsScalar() const
Check if scalar function is valid.
std::vector< GammaParams > BackgroundYield(double luminosity) const
std::string CodeToRootTex(std::string code)
FigureComponent * GetComponent(const Process *process) final
VectorType GetVector(const Baby &b) const
Evaluate vector function with b as argument.
const std::vector< std::unique_ptr< TableColumn > > & GetComponentList(const Process *process) const
TString RoundNumber(double num, int decimals, double denom=1.)
void PrintFooter(std::ofstream &file) const
std::vector< TableRow > rows_
std::vector< GammaParams > DataYield() const
static double GetYield(const std::vector< std::unique_ptr< TableColumn > > &columns, std::size_t irow)
void PrintHeader(std::ofstream &file) const
std::vector< double > sumw_
std::size_t lines_before_
void Print(double luminosity, const std::string &subdir) final
void RecordEvent(const Baby &baby) final
static double GetError(const std::vector< std::unique_ptr< TableColumn > > &columns, std::size_t irow)
std::string ToString(const T &x)