13 #include <sys/ioctl.h> 18 #define TREEMAPSTRING std::string 19 #define CUTFLOWMAPSTRING TString 24 namespace CutflowUtil {
47 std::cout <<
"CutNameList - " <<
cl.first << std::endl;
52 std::map<TString, std::vector<TString>> obj_cutlists;
54 obj_cutlists[
cl.first] =
cl.second.cutlist;
66 CutNameListMap& cutlists, TString syst =
"");
68 std::map<TString, std::vector<TString>>& cutlists, TString syst =
"");
70 std::map<CUTFLOWMAPSTRING, THist*>& rawcutflows);
84 std::map<TString, CutTree*>
systs;
96 std::map<TString, std::vector<std::tuple<THist*, std::function<float()>>>>
hists1d;
98 std::vector<std::tuple<THist*, std::function<std::vector<float>()>,
std::function<std::vector<float>()>>>>
100 std::map<TString, std::vector<std::tuple<TH2F*, std::function<float()>, std::function<float()>>>>
hists2d;
103 std::function<std::vector<float>()>,
105 std::function<std::vector<float>()>>>>
108 std::map<TString, std::vector<std::tuple<THist*, TString>>>
hists1d;
109 std::map<TString, std::vector<std::tuple<TH2F*, TString, TString>>>
hists2d;
111 std::vector<std::tuple<int, int, unsigned long long>>
eventlist;
121 ioctl(STDOUT_FILENO, TIOCGWINSZ, &
w);
122 int colsize =
std::min(
w.ws_col - 100, 600);
124 TString
header =
"Cut name";
125 int extra = colsize -
header.Length();
126 for (
int i = 0;
i < extra; ++
i)
128 header +=
"|pass|weight|systs";
131 for (
int i = 0;
i <
w.ws_col - 10; ++
i)
137 if (
std::find(multichild.begin(), multichild.end(),
i + 1) != multichild.end()) {
146 int extrapad = colsize -
msg.Length() > 0 ? colsize -
msg.Length() : 0;
147 for (
int i = 0;
i < extrapad; ++
i)
156 multichild.push_back(
indent + 1);
158 (*child).printCuts(
indent + 1, multichild);
162 print(TString::Format(
"Print event list for the cut = %s",
name.Data()));
164 int run = std::get<0>(eventid);
165 int lumi = std::get<1>(eventid);
166 unsigned long long evt = std::get<2>(eventid);
167 TString
msg = TString::Format(
"%d:%d:%llu",
run,
lumi, evt);
172 std::ofstream
outFile(ofilename);
176 unsigned long long evt = std::get<2>(
tuple);
184 obj->parents.push_back(
this);
222 hists2d[syst].push_back(std::make_tuple(
h, varx, vary));
232 hists2dvec[syst].push_back(std::make_tuple(
h, varx, vary, elemwgt));
241 void addHist2D(TH2F*
h, TString varx, TString vary, TString syst) {
245 hists2d[syst].push_back(std::make_tuple(
h, varx, vary));
250 if (
name.EqualTo(
n)) {
268 RooUtil::error(TString::Format(
"Asked for %s cut, but did not find the cut",
n.Data()));
272 std::vector<TString>
getCutList(TString
n, std::vector<TString> cut_list = std::vector<TString>()) {
280 if (cut_list.size() == 0) {
282 cut_list.push_back(
c->name);
285 cut_list.push_back(
n);
288 return (
c->parent)->getCutList((
c->parent)->name, cut_list);
294 std::vector<TString>
getEndCuts(std::vector<TString> endcuts = std::vector<TString>()) {
296 endcuts.push_back(
name);
300 endcuts =
child->getEndCuts(endcuts);
303 std::vector<TString>
getCutListBelow(TString
n, std::vector<TString> cut_list = std::vector<TString>()) {
306 if (cut_list.size() == 0) {
308 cut_list.push_back(
c->name);
311 cut_list.push_back(
n);
314 for (
auto&
child :
c->children) {
315 cut_list =
child->getCutListBelow(
child->name, cut_list);
329 std::vector<TString> patterns,
330 std::vector<TString> vetopatterns = std::vector<TString>()) {
334 for (
auto& vetopattern : vetopatterns) {
335 if (
name.Contains(vetopattern))
342 child->addSyst(syst, patterns, vetopatterns);
348 child->clear_passbits();
351 TString cutsystname =
"",
352 bool doeventlist =
false,
353 bool aggregated_pass =
true,
354 float aggregated_weight = 1) {
366 TString cutsystname =
"",
367 bool doeventlist =
false,
368 bool aggregated_pass =
true,
369 float aggregated_weight = 1) {
375 if (cutsystname.IsNull()) {
382 TString
msg =
"cowardly passing the event because cut and weight func not set! cut name = " +
name;
384 pass = aggregated_pass;
385 weight = aggregated_weight;
395 TString
msg =
"cowardly passing the event because cut and weight func not set! cut name = " +
name;
397 pass = aggregated_pass;
398 weight = aggregated_weight;
402 pass =
systs[cutsystname]->pass_this_cut_func() && aggregated_pass;
403 weight =
systs[cutsystname]->weight_this_cut_func() * aggregated_weight;
407 TString
msg =
"cowardly passing the event because cut and weight func not set! cut name = " +
name +
408 " syst name = " + cutsystname;
410 pass = aggregated_pass;
411 weight = aggregated_weight;
416 if (doeventlist and
pass and cutsystname.IsNull()) {
423 child->evaluate_use_lambda(tx, cutsystname, doeventlist,
pass,
weight);
426 TString cutsystname =
"",
427 bool doeventlist =
false,
428 bool aggregated_pass =
true,
429 float aggregated_weight = 1) {
435 if (cutsystname.IsNull()) {
447 pass =
systs[cutsystname]->pass_this_cut && aggregated_pass;
448 weight =
systs[cutsystname]->weight_this_cut * aggregated_weight;
454 if (doeventlist and
pass and cutsystname.IsNull()) {
461 child->evaluate_use_internal_variable(tx, cutsystname, doeventlist,
pass,
weight);
464 TString cutsystname =
"",
465 bool doeventlist =
false,
466 bool aggregated_pass =
true,
467 float aggregated_weight = 1) {
472 if (cutsystname.IsNull()) {
491 if (doeventlist and
pass and cutsystname.IsNull()) {
498 child->evaluate_use_ttreex(tx, cutsystname, doeventlist,
pass,
weight);
504 [](
const std::tuple<int, int, unsigned long long>&
a,
const std::tuple<int, int, unsigned long long>&
b) {
505 if (std::get<0>(
a) != std::get<0>(
b))
506 return std::get<0>(
a) < std::get<0>(
b);
507 else if (std::get<1>(
a) != std::get<1>(
b))
508 return std::get<1>(
a) < std::get<1>(
b);
509 else if (std::get<2>(
a) != std::get<2>(
b))
510 return std::get<2>(
a) < std::get<2>(
b);
526 TString systkey = syst.IsNull() ?
"Nominal" : syst;
529 std::function<float()> vardef = std::get<1>(
tuple);
530 h->Fill(vardef(),
weight * extrawgt);
533 TH2F*
h = std::get<0>(
tuple);
534 std::function<float()> varxdef = std::get<1>(
tuple);
535 std::function<float()> varydef = std::get<2>(
tuple);
536 h->Fill(varxdef(), varydef(),
weight * extrawgt);
540 std::function<std::vector<float>()> vardef = std::get<1>(
tuple);
541 std::function<std::vector<float>()> wgtdef = std::get<2>(
tuple);
542 std::vector<float> varx = vardef();
543 std::vector<float> elemwgts;
546 for (
unsigned int i = 0;
i < varx.size(); ++
i) {
548 h->Fill(varx[
i],
weight * extrawgt * elemwgts[
i]);
550 h->Fill(varx[
i],
weight * extrawgt);
554 TH2F*
h = std::get<0>(
tuple);
555 std::function<std::vector<float>()> varxdef = std::get<1>(
tuple);
556 std::function<std::vector<float>()> varydef = std::get<2>(
tuple);
557 std::function<std::vector<float>()> wgtdef = std::get<3>(
tuple);
558 std::vector<float> varx = varxdef();
559 std::vector<float> vary = varydef();
560 if (varx.size() != vary.size()) {
562 "the vector input to be looped over do not have same length for x and y! check the variable definition " 567 std::vector<float> elemwgts;
570 for (
unsigned int i = 0;
i < varx.size(); ++
i) {
572 h->Fill(varx[
i], vary[
i],
weight * extrawgt * elemwgts[
i]);
574 h->Fill(varx[
i], vary[
i],
weight * extrawgt);
579 child->fillHistograms(syst, extrawgt);
588 TString systkey = syst.IsNull() ?
"Nominal" : syst;
591 TString varname = std::get<1>(
tuple);
595 TH2F*
h = std::get<0>(
tuple);
596 TString varname = std::get<1>(
tuple);
597 TString varnamey = std::get<2>(
tuple);
602 child->fillHistograms(tx, syst, extrawgt);
CutNameList & operator[](TString name)
void fillHistograms(TString syst, float extrawgt)
void addHist2D(TH2F *h, std::function< float()> varx, std::function< float()> vary, TString syst)
std::map< TString, std::vector< std::tuple< TH1D *, std::function< float()> > > > hists1d
void fillCutflow(std::vector< TString > cutlist, RooUtil::TTreeX &tx, TH1D *h)
std::tuple< std::map< TString, TH1D * >, std::map< TString, TH1D * > > createCutflowHistograms(CutNameListMap &cutlists, TString syst="")
std::vector< int > systpasses
CutTree & getCut(TString n)
void evaluate(RooUtil::TTreeX &tx, TString cutsystname="", bool doeventlist=false, bool aggregated_pass=true, float aggregated_weight=1)
std::vector< TString > getCutListBelow(TString n, std::vector< TString > cut_list=std::vector< TString >())
void evaluate_use_lambda(RooUtil::TTreeX &tx, TString cutsystname="", bool doeventlist=false, bool aggregated_pass=true, float aggregated_weight=1)
void warning(TString msg, const char *fname="")
void print(TString msg="", const char *fname="", int flush_before=0, int flush_after=0)
void fillRawCutflow(std::vector< TString > cutlist, RooUtil::TTreeX &tx, TH1D *h)
std::vector< TString > systcutnames
void printCuts(int indent=0, std::vector< int > multichild=std::vector< int >())
const T & getBranch(TString, bool=true)
void saveCutflowHistograms(std::map< TString, TH1D *> &cutflows, std::map< TString, TH1D *> &rawcutflows)
CutNameList(const CutNameList &cutnamelist)
void addHist1DVec(TH1D *h, std::function< std::vector< float >()> var, std::function< std::vector< float >()> wgt, TString syst)
std::map< TString, std::vector< std::tuple< TH2F *, std::function< float()>, std::function< float()> > > > hists2d
void addEventList(int run, int lumi, unsigned long long evt)
void error(TString msg, const char *fname="", int is_error=1)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
void addSyst(TString syst, std::vector< TString > patterns, std::vector< TString > vetopatterns=std::vector< TString >())
std::vector< TString > cutlist
std::map< TString, CutNameList > cutlists
std::map< TString, std::vector< std::tuple< TH2F *, std::function< std::vector< float >)>, std::function< std::vector< float >)>, std::function< std::vector< float >)> > > > hists2dvec
std::function< float()> weight_this_cut_func
std::vector< float > systweights
std::map< TString, std::vector< std::tuple< TH1D *, std::function< std::vector< float >)>, std::function< std::vector< float >)> > > > hists1dvec
std::vector< CutTree * > parents
std::tuple< std::vector< bool >, std::vector< float > > getCutflow(std::vector< TString > cutlist, RooUtil::TTreeX &tx)
std::vector< std::tuple< int, int, unsigned long long > > eventlist
std::vector< CutTree * > children
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
void addSyst(TString syst)
key
prepare the HTCondor submission files and eventually submit them
std::function< bool()> pass_this_cut_func
void evaluate_use_ttreex(RooUtil::TTreeX &tx, TString cutsystname="", bool doeventlist=false, bool aggregated_pass=true, float aggregated_weight=1)
void addCutName(TString cutname)
std::map< TString, CutTree * > systs
void createCutflowBranches(CutNameListMap &cutlists, RooUtil::TTreeX &tx)
void addHist1D(TH1D *h, std::function< float()> var, TString syst)
std::vector< TString > cutlist
std::vector< TString > getCutList(TString n, std::vector< TString > cut_list=std::vector< TString >())
deadvectors [0] push_back({0.0175431, 0.538005, 6.80997, 13.29})
void addHist2DVec(TH2F *h, std::function< std::vector< float >()> varx, std::function< std::vector< float >()> vary, std::function< std::vector< float >()> elemwgt, TString syst)
std::vector< CutTree * > systcuts
std::map< TString, std::vector< TString > > getStdVersion()
std::vector< TString > getEndCuts(std::vector< TString > endcuts=std::vector< TString >())
std::pair< bool, float > passCuts(std::vector< TString > cutlist, RooUtil::TTreeX &tx)
void evaluate_use_internal_variable(RooUtil::TTreeX &tx, TString cutsystname="", bool doeventlist=false, bool aggregated_pass=true, float aggregated_weight=1)
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
CutTree * getCutPointer(TString n)
void writeEventList(TString ofilename)