CMS 3D CMS Logo

List of all members | Public Member Functions | Public Attributes
RooUtil::Cutflow Class Reference

#include <anautil.h>

Public Member Functions

void addCut (TString n, std::function< bool()> pass, std::function< float()> weight)
 
void addCutSyst (TString syst, std::vector< TString > pattern, std::vector< TString > vetopattern=std::vector< TString >())
 
void addCutToLastActiveCut (TString n, std::function< bool()> pass, std::function< float()> weight)
 
void addCutToSkipCutflowList (TString n)
 
void addToCutTreeMap (TString n)
 
void addWgtSyst (TString syst, std::function< float()>)
 
void book2DHistogram (TString, std::pair< std::pair< TString, TString >, std::tuple< unsigned, float, float, unsigned, float, float, std::function< float()>, std::function< float()>>>, TString="")
 
void book2DVecHistogram (TString, std::pair< std::pair< TString, TString >, std::tuple< unsigned, float, float, unsigned, float, float, std::function< std::vector< float >()>, std::function< std::vector< float >()>, std::function< std::vector< float >()>>>, TString="")
 
void book2DVecHistogram (TString, std::pair< std::pair< TString, TString >, std::tuple< std::vector< float >, unsigned, float, float, std::function< std::vector< float >()>, std::function< std::vector< float >()>, std::function< std::vector< float >()>>>, TString="")
 
void bookCutflowHistograms ()
 
void bookCutflowHistograms_v1 ()
 
void bookCutflowHistograms_v2 ()
 
void bookCutflows ()
 
void bookCutflowsForRegions (std::vector< TString > regions)
 
void bookCutflowTree ()
 
void bookEventLists ()
 
void bookHistogram (TString, std::pair< TString, std::tuple< unsigned, float, float, std::function< float()>>>, TString="")
 
void bookHistogram (TString, std::pair< TString, std::tuple< std::vector< float >, std::function< float()>>>, TString="")
 
void bookHistograms (Histograms &histograms)
 
void bookHistograms (Histograms &histograms, std::vector< TString > cutlist)
 
void bookHistogramsForCut (Histograms &histograms, TString)
 
void bookHistogramsForCutAndAbove (Histograms &histograms, TString)
 
void bookHistogramsForCutAndBelow (Histograms &histograms, TString)
 
void bookHistogramsForEndCuts (Histograms &histograms)
 
void bookVecHistogram (TString, std::pair< TString, std::tuple< unsigned, float, float, std::function< std::vector< float >()>, std::function< std::vector< float >()>>>, TString="")
 
void bookVecHistogram (TString, std::pair< TString, std::tuple< std::vector< float >, std::function< std::vector< float >()>, std::function< std::vector< float >()>>>, TString="")
 
void copyAndEditCuts (TString, std::map< TString, TString >)
 
void createWgtSystBranches ()
 
 Cutflow ()
 
 Cutflow (TFile *o)
 
void fill ()
 
void fillCutflow (std::vector< TString > &cutlist, TH1D *h, TH1D *hraw, float wgtsyst=1)
 
void fillCutflow_v2 (std::vector< CutTree *> &cutlist, TH1D *h, TH1D *hraw, float wgtsyst=1)
 
void fillCutflows (TString syst="", bool iswgtsyst=true)
 
void fillCutflows_v1 (TString syst="", bool iswgtsyst=true)
 
void fillCutflows_v2 (TString syst="", bool iswgtsyst=true)
 
void fillHistograms (TString syst="", bool iswgtsyst=true)
 
void filterCuts (std::vector< TString > ns)
 
CutTreegetCut (TString n)
 
void printCuts ()
 
void printSetFunctionError (TString msg)
 
void removeCut (TString n)
 
void saveCutflows ()
 
void saveHistograms ()
 
void saveOutput ()
 
void saveTTreeX ()
 
void setCut (TString cutname, std::function< bool()> pass, std::function< float()> weight)
 
void setCutLists (std::vector< TString > regions)
 
void setCutSyst (TString cutname, TString syst, std::function< bool()> pass, std::function< float()> weight)
 
void setEventID (int, int, unsigned long long)
 
void setHistsAxesExtendable ()
 
void setLastActiveCut (TString n)
 
void setSaveTTreeX (bool=true)
 
void setSkipSystematicHistograms (bool=true)
 
void setTFile (TFile *o)
 
void setVariable (TString varname, float)
 
void setWgtSyst (TString syst, float weight)
 
 ~Cutflow ()
 

Public Attributes

std::map< std::tuple< std::string, std::string, std::string, std::string >, TH2F * > booked_2dhistograms
 
std::vector< std::tuple< std::string, std::string, std::string, std::string > > booked_2dhistograms_nominal_keys
 
std::map< std::tuple< std::string, std::string, std::string >, TH1D * > booked_histograms
 
std::vector< std::tuple< std::string, std::string, std::string > > booked_histograms_nominal_keys
 
bool cutflow_booked
 
std::map< TString, TH1D * > cutflow_histograms
 
std::vector< std::tuple< TH1D *, std::vector< int * >, std::vector< float * >, std::function< float()> > > cutflow_histograms_v2
 
std::vector< TString > cutflow_nofill_cut_list
 
std::map< TString, std::vector< TString > > cutlists
 
std::vector< TString > cutsysts
 
CutTree cuttree
 
std::map< TString, std::vector< CutTree * > > cuttreelists
 
std::map< std::string, CutTree * > cuttreemap
 
bool dosavettreex
 
bool doskipsysthist
 
bool iseventlistbooked
 
CutTreelast_active_cut
 
TFile * ofile
 
std::map< TString, TH1D * > rawcutflow_histograms
 
std::vector< std::tuple< TH1D *, std::vector< int * > > > rawcutflow_histograms_v2
 
int seterrorcount
 
std::vector< TString > systs
 
std::map< TString, std::function< float()> > systs_funcs
 
TTree * t
 
TTreeXtx
 

Detailed Description

Definition at line 113 of file anautil.h.

Constructor & Destructor Documentation

◆ Cutflow() [1/2]

RooUtil::Cutflow::Cutflow ( )

Definition at line 7 of file anautil.cc.

References cuttree, and cuttreemap.

8  : cuttree("Root"),
10  ofile(0),
11  t(0),
12  tx(0),
13  iseventlistbooked(false),
14  seterrorcount(0),
15  doskipsysthist(0),
16  dosavettreex(0),
17  cutflow_booked(false) {
18  cuttreemap["Root"] = &cuttree;
19 }
bool iseventlistbooked
Definition: anautil.h:140
bool doskipsysthist
Definition: anautil.h:142
TFile * ofile
Definition: anautil.h:132
TTreeX * tx
Definition: anautil.h:134
CutTree * last_active_cut
Definition: anautil.h:116
bool cutflow_booked
Definition: anautil.h:144
CutTree cuttree
Definition: anautil.h:115
bool dosavettreex
Definition: anautil.h:143
std::map< std::string, CutTree * > cuttreemap
Definition: anautil.h:117

◆ Cutflow() [2/2]

RooUtil::Cutflow::Cutflow ( TFile *  o)

Definition at line 22 of file anautil.cc.

References cuttree, and cuttreemap.

23  : cuttree("Root"),
24  last_active_cut(0),
25  ofile(o),
26  t(0),
27  tx(0),
28  iseventlistbooked(false),
29  seterrorcount(0),
30  doskipsysthist(0),
31  dosavettreex(0),
32  cutflow_booked(false) {
33  cuttreemap["Root"] = &cuttree;
34 }
bool iseventlistbooked
Definition: anautil.h:140
bool doskipsysthist
Definition: anautil.h:142
TFile * ofile
Definition: anautil.h:132
TTreeX * tx
Definition: anautil.h:134
CutTree * last_active_cut
Definition: anautil.h:116
bool cutflow_booked
Definition: anautil.h:144
CutTree cuttree
Definition: anautil.h:115
bool dosavettreex
Definition: anautil.h:143
std::map< std::string, CutTree * > cuttreemap
Definition: anautil.h:117

◆ ~Cutflow()

RooUtil::Cutflow::~Cutflow ( )

Definition at line 37 of file anautil.cc.

References isotrackApplyRegressor::k, and findQualityFiles::v.

37  {
38  if (booked_histograms.size() > 0) {
39  for (auto& [k, v] : booked_histograms) {
40  delete v;
41  }
42  }
43  if (booked_2dhistograms.size() > 0) {
44  for (auto& [k, v] : booked_2dhistograms) {
45  delete v;
46  }
47  }
48 }
std::map< std::tuple< std::string, std::string, std::string, std::string >, TH2F * > booked_2dhistograms
Definition: anautil.h:123
std::map< std::tuple< std::string, std::string, std::string >, TH1D * > booked_histograms
Definition: anautil.h:121

Member Function Documentation

◆ addCut()

void RooUtil::Cutflow::addCut ( TString  n,
std::function< bool()>  pass,
std::function< float()>  weight 
)

Definition at line 73 of file anautil.cc.

References DMR_cfg::cut, and create_idmaps::n.

73  {
74  cuttree.addCut(n);
77  setCut(n, cut, weight);
78 }
void setCut(TString cutname, std::function< bool()> pass, std::function< float()> weight)
Definition: anautil.cc:343
void addToCutTreeMap(TString n)
Definition: anautil.cc:51
void setLastActiveCut(TString n)
Definition: anautil.cc:59
Definition: weight.py:1
void addCut(TString n)
Definition: cutflowutil.h:181
CutTree cuttree
Definition: anautil.h:115

◆ addCutSyst()

void RooUtil::Cutflow::addCutSyst ( TString  syst,
std::vector< TString >  pattern,
std::vector< TString >  vetopattern = std::vector<TString>() 
)

Definition at line 412 of file anautil.cc.

References topSingleLeptonDQM_PU_cfi::pattern.

412  {
413  cutsysts.push_back(syst);
414  cuttree.addSyst(syst, pattern, vetopattern);
415 }
std::vector< TString > cutsysts
Definition: anautil.h:135
void addSyst(TString syst)
Definition: cutflowutil.h:187
CutTree cuttree
Definition: anautil.h:115

◆ addCutToLastActiveCut()

void RooUtil::Cutflow::addCutToLastActiveCut ( TString  n,
std::function< bool()>  pass,
std::function< float()>  weight 
)

Definition at line 81 of file anautil.cc.

References DMR_cfg::cut, and create_idmaps::n.

81  {
85  setCut(n, cut, weight);
86 }
void setCut(TString cutname, std::function< bool()> pass, std::function< float()> weight)
Definition: anautil.cc:343
void addToCutTreeMap(TString n)
Definition: anautil.cc:51
void setLastActiveCut(TString n)
Definition: anautil.cc:59
Definition: weight.py:1
void addCut(TString n)
Definition: cutflowutil.h:181
CutTree * last_active_cut
Definition: anautil.h:116

◆ addCutToSkipCutflowList()

void RooUtil::Cutflow::addCutToSkipCutflowList ( TString  n)

Definition at line 159 of file anautil.cc.

References spr::find(), and create_idmaps::n.

159  {
161  cutflow_nofill_cut_list.push_back(n);
162 }
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
std::vector< TString > cutflow_nofill_cut_list
Definition: anautil.h:131

◆ addToCutTreeMap()

void RooUtil::Cutflow::addToCutTreeMap ( TString  n)

Definition at line 51 of file anautil.cc.

References RooUtil::error(), and create_idmaps::n.

51  {
52  if (cuttreemap.find(n.Data()) == cuttreemap.end())
53  cuttreemap[n.Data()] = cuttree.getCutPointer(n);
54  else
55  error(TString::Format("Cut %s already exists! no duplicate cut names allowed!", n.Data()));
56 }
void error(TString msg, const char *fname="", int is_error=1)
Definition: printutil.cc:44
CutTree cuttree
Definition: anautil.h:115
CutTree * getCutPointer(TString n)
Definition: cutflowutil.h:248
std::map< std::string, CutTree * > cuttreemap
Definition: anautil.h:117

◆ addWgtSyst()

void RooUtil::Cutflow::addWgtSyst ( TString  syst,
std::function< float()>  weight 
)

Definition at line 419 of file anautil.cc.

References mps_merge::weight.

419  {
420  systs.push_back(syst);
421  systs_funcs[syst] = weight;
422 }
std::map< TString, std::function< float()> > systs_funcs
Definition: anautil.h:137
std::vector< TString > systs
Definition: anautil.h:136

◆ book2DHistogram()

void RooUtil::Cutflow::book2DHistogram ( TString  cut,
std::pair< std::pair< TString, TString >, std::tuple< unsigned, float, float, unsigned, float, float, std::function< float()>, std::function< float()>>>  key,
TString  syst = "" 
)

Definition at line 786 of file anautil.cc.

References DMR_cfg::cut, submitPVResolutionJobs::key, WZElectronSkims53X_cff::max, and SiStripPI::min.

791  {
792  TString varname = key.first.first;
793  TString varnamey = key.first.second;
794  unsigned int nbin = std::get<0>(key.second);
795  float min = std::get<1>(key.second);
796  float max = std::get<2>(key.second);
797  unsigned int nbiny = std::get<3>(key.second);
798  float miny = std::get<4>(key.second);
799  float maxy = std::get<5>(key.second);
800  std::function<float()> varxdef = std::get<6>(key.second);
801  std::function<float()> varydef = std::get<7>(key.second);
802  TString histname = cut + syst + "__" + varname + "_v_" + varnamey;
803  if (booked_2dhistograms.find(std::make_tuple(cut.Data(), syst.Data(), varname.Data(), varnamey.Data())) ==
804  booked_2dhistograms.end()) {
805  booked_2dhistograms[std::make_tuple(cut.Data(), syst.Data(), varname.Data(), varnamey.Data())] =
806  new TH2F(histname, "", nbin, min, max, nbiny, miny, maxy);
807  booked_2dhistograms[std::make_tuple(cut.Data(), syst.Data(), varname.Data(), varnamey.Data())]->SetDirectory(0);
808  booked_2dhistograms[std::make_tuple(cut.Data(), syst.Data(), varname.Data(), varnamey.Data())]->Sumw2();
809  if (syst.IsNull()) {
811  std::make_tuple(cut.Data(), syst.Data(), varname.Data(), varnamey.Data()));
812  }
813  cuttreemap[cut.Data()]->addHist2D(
814  booked_2dhistograms[std::make_tuple(cut.Data(), syst.Data(), varname.Data(), varnamey.Data())],
815  varxdef,
816  varydef,
817  syst);
818  }
819 }
std::map< std::tuple< std::string, std::string, std::string, std::string >, TH2F * > booked_2dhistograms
Definition: anautil.h:123
std::vector< std::tuple< std::string, std::string, std::string, std::string > > booked_2dhistograms_nominal_keys
Definition: anautil.h:127
key
prepare the HTCondor submission files and eventually submit them
std::map< std::string, CutTree * > cuttreemap
Definition: anautil.h:117

◆ book2DVecHistogram() [1/2]

void RooUtil::Cutflow::book2DVecHistogram ( TString  cut,
std::pair< std::pair< TString, TString >, std::tuple< unsigned, float, float, unsigned, float, float, std::function< std::vector< float >()>, std::function< std::vector< float >()>, std::function< std::vector< float >()>>>  key,
TString  syst = "" 
)

Definition at line 822 of file anautil.cc.

References DMR_cfg::cut, submitPVResolutionJobs::key, WZElectronSkims53X_cff::max, and SiStripPI::min.

833  {
834  TString varname = key.first.first;
835  TString varnamey = key.first.second;
836  unsigned int nbin = std::get<0>(key.second);
837  float min = std::get<1>(key.second);
838  float max = std::get<2>(key.second);
839  unsigned int nbiny = std::get<3>(key.second);
840  float miny = std::get<4>(key.second);
841  float maxy = std::get<5>(key.second);
842  std::function<std::vector<float>()> varxdef = std::get<6>(key.second);
843  std::function<std::vector<float>()> varydef = std::get<7>(key.second);
844  std::function<std::vector<float>()> elemwgt = std::get<8>(key.second);
845  TString histname = cut + syst + "__" + varname + "_v_" + varnamey;
846  if (booked_2dhistograms.find(std::make_tuple(cut.Data(), syst.Data(), varname.Data(), varnamey.Data())) ==
847  booked_2dhistograms.end()) {
848  booked_2dhistograms[std::make_tuple(cut.Data(), syst.Data(), varname.Data(), varnamey.Data())] =
849  new TH2F(histname, "", nbin, min, max, nbiny, miny, maxy);
850  booked_2dhistograms[std::make_tuple(cut.Data(), syst.Data(), varname.Data(), varnamey.Data())]->SetDirectory(0);
851  booked_2dhistograms[std::make_tuple(cut.Data(), syst.Data(), varname.Data(), varnamey.Data())]->Sumw2();
852  if (syst.IsNull()) {
854  std::make_tuple(cut.Data(), syst.Data(), varname.Data(), varnamey.Data()));
855  }
856  cuttreemap[cut.Data()]->addHist2DVec(
857  booked_2dhistograms[std::make_tuple(cut.Data(), syst.Data(), varname.Data(), varnamey.Data())],
858  varxdef,
859  varydef,
860  elemwgt,
861  syst);
862  }
863 }
std::map< std::tuple< std::string, std::string, std::string, std::string >, TH2F * > booked_2dhistograms
Definition: anautil.h:123
std::vector< std::tuple< std::string, std::string, std::string, std::string > > booked_2dhistograms_nominal_keys
Definition: anautil.h:127
key
prepare the HTCondor submission files and eventually submit them
std::map< std::string, CutTree * > cuttreemap
Definition: anautil.h:117

◆ book2DVecHistogram() [2/2]

void RooUtil::Cutflow::book2DVecHistogram ( TString  cut,
std::pair< std::pair< TString, TString >, std::tuple< std::vector< float >, unsigned, float, float, std::function< std::vector< float >()>, std::function< std::vector< float >()>, std::function< std::vector< float >()>>>  key,
TString  syst = "" 
)

Definition at line 865 of file anautil.cc.

References DMR_cfg::cut, mps_fire::i, and submitPVResolutionJobs::key.

874  {
875  TString varname = key.first.first;
876  TString varnamey = key.first.second;
877  std::vector<float> xboundaries = std::get<0>(key.second);
878  unsigned int nbiny = std::get<1>(key.second);
879  float miny = std::get<2>(key.second);
880  float maxy = std::get<3>(key.second);
881  std::function<std::vector<float>()> varxdef = std::get<4>(key.second);
882  std::function<std::vector<float>()> varydef = std::get<5>(key.second);
883  std::function<std::vector<float>()> elemwgt = std::get<6>(key.second);
884  TString histname = cut + syst + "__" + varname + "_v_" + varnamey;
885  if (booked_2dhistograms.find(std::make_tuple(cut.Data(), syst.Data(), varname.Data(), varnamey.Data())) ==
886  booked_2dhistograms.end()) {
887  Double_t xbounds[xboundaries.size()];
888  for (unsigned int i = 0; i < xboundaries.size(); ++i)
889  xbounds[i] = xboundaries[i];
890  booked_2dhistograms[std::make_tuple(cut.Data(), syst.Data(), varname.Data(), varnamey.Data())] =
891  new TH2F(histname, "", xboundaries.size() - 1, xbounds, nbiny, miny, maxy);
892  booked_2dhistograms[std::make_tuple(cut.Data(), syst.Data(), varname.Data(), varnamey.Data())]->SetDirectory(0);
893  booked_2dhistograms[std::make_tuple(cut.Data(), syst.Data(), varname.Data(), varnamey.Data())]->Sumw2();
894  if (syst.IsNull()) {
896  std::make_tuple(cut.Data(), syst.Data(), varname.Data(), varnamey.Data()));
897  }
898  cuttreemap[cut.Data()]->addHist2DVec(
899  booked_2dhistograms[std::make_tuple(cut.Data(), syst.Data(), varname.Data(), varnamey.Data())],
900  varxdef,
901  varydef,
902  elemwgt,
903  syst);
904  }
905 }
std::map< std::tuple< std::string, std::string, std::string, std::string >, TH2F * > booked_2dhistograms
Definition: anautil.h:123
std::vector< std::tuple< std::string, std::string, std::string, std::string > > booked_2dhistograms_nominal_keys
Definition: anautil.h:127
key
prepare the HTCondor submission files and eventually submit them
std::map< std::string, CutTree * > cuttreemap
Definition: anautil.h:117

◆ bookCutflowHistograms()

void RooUtil::Cutflow::bookCutflowHistograms ( )

Definition at line 181 of file anautil.cc.

References RooUtil::error().

181  {
182  if (cutflow_booked) {
183  error("bookCutflowHistograms():: cutflows already booked! yet you called again to book it! Check your user code!");
184  }
185  cutflow_booked = true;
187 }
void bookCutflowHistograms_v1()
Definition: anautil.cc:259
void error(TString msg, const char *fname="", int is_error=1)
Definition: printutil.cc:44
bool cutflow_booked
Definition: anautil.h:144

◆ bookCutflowHistograms_v1()

void RooUtil::Cutflow::bookCutflowHistograms_v1 ( )

Definition at line 259 of file anautil.cc.

References RooUtil::CutflowUtil::createCutflowHistograms(), mps_check::msg, and RooUtil::print().

259  {
260  ofile->cd();
261 
263 
264  for (auto& syst : systs) {
265  std::map<CUTFLOWMAPSTRING, THist*> cutflow_histograms_tmp;
266  std::map<CUTFLOWMAPSTRING, THist*> rawcutflow_histograms_tmp;
267  std::tie(cutflow_histograms_tmp, rawcutflow_histograms_tmp) =
269  cutflow_histograms.insert(cutflow_histograms_tmp.begin(), cutflow_histograms_tmp.end());
270  rawcutflow_histograms.insert(rawcutflow_histograms_tmp.begin(), rawcutflow_histograms_tmp.end());
271  }
272 
273  for (auto& cutsyst : cutsysts) {
274  std::map<CUTFLOWMAPSTRING, THist*> cutflow_histograms_tmp;
275  std::map<CUTFLOWMAPSTRING, THist*> rawcutflow_histograms_tmp;
276  std::tie(cutflow_histograms_tmp, rawcutflow_histograms_tmp) =
278  cutflow_histograms.insert(cutflow_histograms_tmp.begin(), cutflow_histograms_tmp.end());
279  rawcutflow_histograms.insert(rawcutflow_histograms_tmp.begin(), rawcutflow_histograms_tmp.end());
280  }
281 
282  for (auto& cutflow_histogram : cutflow_histograms) {
283  TString msg = "Booked cutflow histogram for cut = " + cutflow_histogram.first;
284  print(msg);
285  }
286  for (auto& rawcutflow_histogram : rawcutflow_histograms) {
287  TString msg = "Booked rawcutflow histogram for cut = " + rawcutflow_histogram.first;
288  print(msg);
289  }
290 }
std::tuple< std::map< TString, TH1D * >, std::map< TString, TH1D * > > createCutflowHistograms(CutNameListMap &cutlists, TString syst="")
Definition: cutflowutil.cc:78
void print(TString msg="", const char *fname="", int flush_before=0, int flush_after=0)
Definition: printutil.cc:23
std::vector< TString > systs
Definition: anautil.h:136
std::vector< TString > cutsysts
Definition: anautil.h:135
std::map< TString, std::vector< TString > > cutlists
Definition: anautil.h:138
std::map< TString, TH1D * > rawcutflow_histograms
Definition: anautil.h:119
TFile * ofile
Definition: anautil.h:132
tuple msg
Definition: mps_check.py:286
std::map< TString, TH1D * > cutflow_histograms
Definition: anautil.h:118

◆ bookCutflowHistograms_v2()

void RooUtil::Cutflow::bookCutflowHistograms_v2 ( )

Definition at line 190 of file anautil.cc.

References hgcalPlots::ct, h, mps_fire::i, THist, UNITY(), and hltDeepSecondaryVertexTagInfosPFPuppi_cfi::weights.

190  {
191  ofile->cd();
192 
193  // Nominal
194  for (auto& cuttreelist : cuttreelists) {
195  THist* h = new THist(cuttreelist.first + "_cutflow", "", cuttreelist.second.size(), 0, cuttreelist.second.size());
196  THist* h_raw =
197  new THist(cuttreelist.first + "_rawcutflow", "", cuttreelist.second.size(), 0, cuttreelist.second.size());
198  h->Sumw2();
199  h_raw->Sumw2();
200  h->SetDirectory(0);
201  h_raw->SetDirectory(0);
202  std::vector<int*> passes;
203  std::vector<float*> weights;
204  for (auto& ct : cuttreelist.second) {
205  passes.push_back(&(ct->pass));
206  weights.push_back(&(ct->weight));
207  }
208  cutflow_histograms_v2.push_back(std::make_tuple(h, passes, weights, UNITY));
209  rawcutflow_histograms_v2.push_back(std::make_tuple(h_raw, passes));
210  }
211 
212  // Wgt varying systematic cutflow
213  for (auto& syst : systs) {
214  for (auto& cuttreelist : cuttreelists) {
215  THist* h =
216  new THist(cuttreelist.first + syst + "_cutflow", "", cuttreelist.second.size(), 0, cuttreelist.second.size());
217  THist* h_raw = new THist(
218  cuttreelist.first + syst + "_rawcutflow", "", cuttreelist.second.size(), 0, cuttreelist.second.size());
219  h->Sumw2();
220  h_raw->Sumw2();
221  h->SetDirectory(0);
222  h_raw->SetDirectory(0);
223  std::vector<int*> passes;
224  std::vector<float*> weights;
225  for (auto& ct : cuttreelist.second) {
226  passes.push_back(&(ct->pass));
227  weights.push_back(&(ct->weight));
228  }
229  cutflow_histograms_v2.push_back(std::make_tuple(h, passes, weights, systs_funcs[syst]));
230  rawcutflow_histograms_v2.push_back(std::make_tuple(h_raw, passes));
231  }
232  }
233 
234  // Nominal
235  for (unsigned int i = 0; i < cutsysts.size(); ++i) {
236  TString cutsyst = cutsysts[i];
237  for (auto& cuttreelist : cuttreelists) {
238  THist* h = new THist(
239  cuttreelist.first + cutsyst + "_cutflow", "", cuttreelist.second.size(), 0, cuttreelist.second.size());
240  THist* h_raw = new THist(
241  cuttreelist.first + cutsyst + "_rawcutflow", "", cuttreelist.second.size(), 0, cuttreelist.second.size());
242  h->Sumw2();
243  h_raw->Sumw2();
244  h->SetDirectory(0);
245  h_raw->SetDirectory(0);
246  std::vector<int*> passes;
247  std::vector<float*> weights;
248  for (auto& ct : cuttreelist.second) {
249  passes.push_back(&(ct->systpasses[i]));
250  weights.push_back(&(ct->systweights[i]));
251  }
252  cutflow_histograms_v2.push_back(std::make_tuple(h, passes, weights, UNITY));
253  rawcutflow_histograms_v2.push_back(std::make_tuple(h_raw, passes));
254  }
255  }
256 }
std::map< TString, std::function< float()> > systs_funcs
Definition: anautil.h:137
float UNITY()
Definition: anautil.cc:4
std::vector< TString > systs
Definition: anautil.h:136
std::map< TString, std::vector< CutTree * > > cuttreelists
Definition: anautil.h:139
std::vector< std::tuple< TH1D *, std::vector< int * >, std::vector< float * >, std::function< float()> > > cutflow_histograms_v2
Definition: anautil.h:129
std::vector< TString > cutsysts
Definition: anautil.h:135
#define THist
Definition: cutflowutil.h:21
TFile * ofile
Definition: anautil.h:132
std::vector< std::tuple< TH1D *, std::vector< int * > > > rawcutflow_histograms_v2
Definition: anautil.h:130
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4

◆ bookCutflows()

void RooUtil::Cutflow::bookCutflows ( )

Definition at line 300 of file anautil.cc.

300  {
301  std::vector<TString> regions = cuttree.getEndCuts();
303  bookCutflowTree();
305 }
void bookCutflowHistograms()
Definition: anautil.cc:181
void setCutLists(std::vector< TString > regions)
Definition: anautil.cc:144
void bookCutflowTree()
Definition: anautil.cc:165
CutTree cuttree
Definition: anautil.h:115
std::vector< TString > getEndCuts(std::vector< TString > endcuts=std::vector< TString >())
Definition: cutflowutil.h:294

◆ bookCutflowsForRegions()

void RooUtil::Cutflow::bookCutflowsForRegions ( std::vector< TString >  regions)

Definition at line 293 of file anautil.cc.

293  {
295  bookCutflowTree();
297 }
void bookCutflowHistograms()
Definition: anautil.cc:181
void setCutLists(std::vector< TString > regions)
Definition: anautil.cc:144
void bookCutflowTree()
Definition: anautil.cc:165

◆ bookCutflowTree()

void RooUtil::Cutflow::bookCutflowTree ( )

Definition at line 165 of file anautil.cc.

References RooUtil::CutflowUtil::createCutflowBranches(), and submitPVValidationJobs::t.

165  {
166  if (!t) {
167  ofile->cd();
168  t = new TTree("cut_tree", "cut_tree");
169  t->SetDirectory(0);
170  }
171  if (!tx) {
172  ofile->cd();
173  tx = new TTreeX(t);
174  }
177  // t->Print();
178 }
std::map< TString, std::vector< TString > > cutlists
Definition: anautil.h:138
void createWgtSystBranches()
Definition: anautil.cc:429
void createCutflowBranches(CutNameListMap &cutlists, RooUtil::TTreeX &tx)
Definition: cutflowutil.cc:18
TFile * ofile
Definition: anautil.h:132
TTreeX * tx
Definition: anautil.h:134

◆ bookEventLists()

void RooUtil::Cutflow::bookEventLists ( )

Definition at line 459 of file anautil.cc.

References RooUtil::error().

459  {
460  if (!tx)
461  error("bookEventLists():: No TTreeX has been set. Forgot to call bookCutflows()?");
462  if (!tx->hasBranch<int>("run"))
463  tx->createBranch<int>("run");
464  if (!tx->hasBranch<int>("lumi"))
465  tx->createBranch<int>("lumi");
466  if (!tx->hasBranch<unsigned long long>("evt"))
467  tx->createBranch<unsigned long long>("evt");
468  iseventlistbooked = true;
469 }
void error(TString msg, const char *fname="", int is_error=1)
Definition: printutil.cc:44
bool iseventlistbooked
Definition: anautil.h:140
void createBranch(TString, bool=true)
bool hasBranch(TString)
TTreeX * tx
Definition: anautil.h:134

◆ bookHistogram() [1/2]

void RooUtil::Cutflow::bookHistogram ( TString  cut,
std::pair< TString, std::tuple< unsigned, float, float, std::function< float()>>>  key,
TString  syst = "" 
)

Definition at line 683 of file anautil.cc.

References DMR_cfg::cut, submitPVResolutionJobs::key, WZElectronSkims53X_cff::max, SiStripPI::min, and THist.

685  {
686  TString varname = key.first;
687  unsigned int nbin = std::get<0>(key.second);
688  float min = std::get<1>(key.second);
689  float max = std::get<2>(key.second);
690  std::function<float()> vardef = std::get<3>(key.second);
691  TString histname = cut + syst + "__" + varname;
692  if (booked_histograms.find(std::make_tuple(cut.Data(), syst.Data(), varname.Data())) == booked_histograms.end()) {
693  booked_histograms[std::make_tuple(cut.Data(), syst.Data(), varname.Data())] =
694  new THist(histname, "", nbin, min, max);
695  booked_histograms[std::make_tuple(cut.Data(), syst.Data(), varname.Data())]->SetDirectory(0);
696  booked_histograms[std::make_tuple(cut.Data(), syst.Data(), varname.Data())]->Sumw2();
697  if (syst.IsNull()) {
698  booked_histograms_nominal_keys.push_back(std::make_tuple(cut.Data(), syst.Data(), varname.Data()));
699  }
700  cuttreemap[cut.Data()]->addHist1D(
701  booked_histograms[std::make_tuple(cut.Data(), syst.Data(), varname.Data())], vardef, syst);
702  }
703 }
key
prepare the HTCondor submission files and eventually submit them
#define THist
Definition: cutflowutil.h:21
std::map< std::tuple< std::string, std::string, std::string >, TH1D * > booked_histograms
Definition: anautil.h:121
std::vector< std::tuple< std::string, std::string, std::string > > booked_histograms_nominal_keys
Definition: anautil.h:125
std::map< std::string, CutTree * > cuttreemap
Definition: anautil.h:117

◆ bookHistogram() [2/2]

void RooUtil::Cutflow::bookHistogram ( TString  cut,
std::pair< TString, std::tuple< std::vector< float >, std::function< float()>>>  key,
TString  syst = "" 
)

Definition at line 734 of file anautil.cc.

References DMR_cfg::cut, mps_fire::i, submitPVResolutionJobs::key, and THist.

736  {
737  TString varname = key.first;
738  std::vector<float> boundaries = std::get<0>(key.second);
739  std::function<float()> vardef = std::get<1>(key.second);
740  TString histname = cut + syst + "__" + varname;
741  if (booked_histograms.find(std::make_tuple(cut.Data(), syst.Data(), varname.Data())) == booked_histograms.end()) {
742  Float_t bounds[boundaries.size()];
743  for (unsigned int i = 0; i < boundaries.size(); ++i)
744  bounds[i] = boundaries[i];
745  booked_histograms[std::make_tuple(cut.Data(), syst.Data(), varname.Data())] =
746  new THist(histname, "", boundaries.size() - 1, bounds);
747  booked_histograms[std::make_tuple(cut.Data(), syst.Data(), varname.Data())]->SetDirectory(0);
748  booked_histograms[std::make_tuple(cut.Data(), syst.Data(), varname.Data())]->Sumw2();
749  if (syst.IsNull()) {
750  booked_histograms_nominal_keys.push_back(std::make_tuple(cut.Data(), syst.Data(), varname.Data()));
751  }
752  cuttreemap[cut.Data()]->addHist1D(
753  booked_histograms[std::make_tuple(cut.Data(), syst.Data(), varname.Data())], vardef, syst);
754  }
755 }
key
prepare the HTCondor submission files and eventually submit them
#define THist
Definition: cutflowutil.h:21
std::map< std::tuple< std::string, std::string, std::string >, TH1D * > booked_histograms
Definition: anautil.h:121
std::vector< std::tuple< std::string, std::string, std::string > > booked_histograms_nominal_keys
Definition: anautil.h:125
std::map< std::string, CutTree * > cuttreemap
Definition: anautil.h:117

◆ bookHistograms() [1/2]

void RooUtil::Cutflow::bookHistograms ( Histograms histograms)

Definition at line 666 of file anautil.cc.

References bookHistograms(), SimL1EmulatorRepack_CalouGT_cff::cutlist, and nano_mu_digi_cff::region.

Referenced by main().

666  {
667  std::vector<TString> regions = cuttree.getEndCuts();
668  for (auto& region : regions) {
669  std::vector<TString> cutlist = cuttree.getCutList(region);
671  }
672 }
std::vector< TString > getCutList(TString n, std::vector< TString > cut_list=std::vector< TString >())
Definition: cutflowutil.h:272
CutTree cuttree
Definition: anautil.h:115
void bookHistograms(Histograms &histograms)
Definition: anautil.cc:666
std::vector< TString > getEndCuts(std::vector< TString > endcuts=std::vector< TString >())
Definition: cutflowutil.h:294

◆ bookHistograms() [2/2]

void RooUtil::Cutflow::bookHistograms ( Histograms histograms,
std::vector< TString >  cutlist 
)

Definition at line 675 of file anautil.cc.

References DMR_cfg::cut, and SimL1EmulatorRepack_CalouGT_cff::cutlist.

675  {
676  for (auto& cut : cutlist) {
678  }
679 }
void bookHistogramsForCut(Histograms &histograms, TString)
Definition: anautil.cc:998

◆ bookHistogramsForCut()

void RooUtil::Cutflow::bookHistogramsForCut ( Histograms histograms,
TString  cut 
)

Definition at line 998 of file anautil.cc.

References DMR_cfg::cut, and submitPVResolutionJobs::key.

998  {
999  for (auto& key : histograms.th1fs)
1000  bookHistogram(cut, key);
1001  for (auto& key : histograms.th1fs_varbin)
1002  bookHistogram(cut, key);
1003  for (auto& key : histograms.th1vecfs)
1005  for (auto& key : histograms.th1vecfs_varbin)
1007  for (auto& key : histograms.th2fs)
1009  for (auto& key : histograms.th2vecfs)
1011  for (auto& key : histograms.th2vecfs_xvarbin)
1013  if (not doskipsysthist) {
1014  for (auto& syst : systs) {
1015  for (auto& key : histograms.th1fs)
1016  bookHistogram(cut, key, syst);
1017  for (auto& key : histograms.th1fs_varbin)
1018  bookHistogram(cut, key, syst);
1019  for (auto& key : histograms.th1vecfs)
1020  bookVecHistogram(cut, key, syst);
1021  for (auto& key : histograms.th1vecfs_varbin)
1022  bookVecHistogram(cut, key, syst);
1023  for (auto& key : histograms.th2fs)
1024  book2DHistogram(cut, key, syst);
1025  for (auto& key : histograms.th2vecfs)
1026  book2DVecHistogram(cut, key, syst);
1027  for (auto& key : histograms.th2vecfs_xvarbin)
1028  book2DVecHistogram(cut, key, syst);
1029  }
1030  for (auto& cutsyst : cutsysts) {
1031  for (auto& key : histograms.th1fs)
1032  bookHistogram(cut, key, cutsyst);
1033  for (auto& key : histograms.th1fs_varbin)
1034  bookHistogram(cut, key, cutsyst);
1035  for (auto& key : histograms.th1vecfs)
1036  bookVecHistogram(cut, key, cutsyst);
1037  for (auto& key : histograms.th1vecfs_varbin)
1038  bookVecHistogram(cut, key, cutsyst);
1039  for (auto& key : histograms.th2fs)
1040  book2DHistogram(cut, key, cutsyst);
1041  for (auto& key : histograms.th2vecfs)
1042  book2DVecHistogram(cut, key, cutsyst);
1043  for (auto& key : histograms.th2vecfs_xvarbin)
1044  book2DVecHistogram(cut, key, cutsyst);
1045  }
1046  }
1047 }
std::vector< TString > systs
Definition: anautil.h:136
void book2DVecHistogram(TString, std::pair< std::pair< TString, TString >, std::tuple< unsigned, float, float, unsigned, float, float, std::function< std::vector< float >()>, std::function< std::vector< float >()>, std::function< std::vector< float >()>>>, TString="")
Definition: anautil.cc:822
bool doskipsysthist
Definition: anautil.h:142
std::vector< TString > cutsysts
Definition: anautil.h:135
key
prepare the HTCondor submission files and eventually submit them
void bookHistogram(TString, std::pair< TString, std::tuple< unsigned, float, float, std::function< float()>>>, TString="")
Definition: anautil.cc:683
void bookVecHistogram(TString, std::pair< TString, std::tuple< unsigned, float, float, std::function< std::vector< float >()>, std::function< std::vector< float >()>>>, TString="")
Definition: anautil.cc:706
void book2DHistogram(TString, std::pair< std::pair< TString, TString >, std::tuple< unsigned, float, float, unsigned, float, float, std::function< float()>, std::function< float()>>>, TString="")
Definition: anautil.cc:786

◆ bookHistogramsForCutAndAbove()

void RooUtil::Cutflow::bookHistogramsForCutAndAbove ( Histograms histograms,
TString  cut 
)

Definition at line 1058 of file anautil.cc.

References RooUtil::error().

1058  {
1059  error("bookHistogramsForCutAndAbove not yet implemented");
1060 }
void error(TString msg, const char *fname="", int is_error=1)
Definition: printutil.cc:44

◆ bookHistogramsForCutAndBelow()

void RooUtil::Cutflow::bookHistogramsForCutAndBelow ( Histograms histograms,
TString  cut 
)

Definition at line 1050 of file anautil.cc.

References DummyCfis::c, DMR_cfg::cut, and SimL1EmulatorRepack_CalouGT_cff::cutlist.

1050  {
1051  std::vector<TString> cutlist = cuttree.getCutListBelow(cut);
1052  for (auto& c : cutlist) {
1054  }
1055 }
std::vector< TString > getCutListBelow(TString n, std::vector< TString > cut_list=std::vector< TString >())
Definition: cutflowutil.h:303
void bookHistogramsForCut(Histograms &histograms, TString)
Definition: anautil.cc:998
CutTree cuttree
Definition: anautil.h:115

◆ bookHistogramsForEndCuts()

void RooUtil::Cutflow::bookHistogramsForEndCuts ( Histograms histograms)

Definition at line 1063 of file anautil.cc.

References nano_mu_digi_cff::region.

1063  {
1064  std::vector<TString> regions = cuttree.getEndCuts();
1065  for (auto& region : regions) {
1067  }
1068 }
void bookHistogramsForCut(Histograms &histograms, TString)
Definition: anautil.cc:998
CutTree cuttree
Definition: anautil.h:115
std::vector< TString > getEndCuts(std::vector< TString > endcuts=std::vector< TString >())
Definition: cutflowutil.h:294

◆ bookVecHistogram() [1/2]

void RooUtil::Cutflow::bookVecHistogram ( TString  cut,
std::pair< TString, std::tuple< unsigned, float, float, std::function< std::vector< float >()>, std::function< std::vector< float >()>>>  key,
TString  syst = "" 
)

Definition at line 706 of file anautil.cc.

References DMR_cfg::cut, submitPVResolutionJobs::key, WZElectronSkims53X_cff::max, SiStripPI::min, and THist.

712  {
713  TString varname = key.first;
714  unsigned int nbin = std::get<0>(key.second);
715  float min = std::get<1>(key.second);
716  float max = std::get<2>(key.second);
717  std::function<std::vector<float>()> vardef = std::get<3>(key.second);
718  std::function<std::vector<float>()> wgtdef = std::get<4>(key.second);
719  TString histname = cut + syst + "__" + varname;
720  if (booked_histograms.find(std::make_tuple(cut.Data(), syst.Data(), varname.Data())) == booked_histograms.end()) {
721  booked_histograms[std::make_tuple(cut.Data(), syst.Data(), varname.Data())] =
722  new THist(histname, "", nbin, min, max);
723  booked_histograms[std::make_tuple(cut.Data(), syst.Data(), varname.Data())]->SetDirectory(0);
724  booked_histograms[std::make_tuple(cut.Data(), syst.Data(), varname.Data())]->Sumw2();
725  if (syst.IsNull()) {
726  booked_histograms_nominal_keys.push_back(std::make_tuple(cut.Data(), syst.Data(), varname.Data()));
727  }
728  cuttreemap[cut.Data()]->addHist1DVec(
729  booked_histograms[std::make_tuple(cut.Data(), syst.Data(), varname.Data())], vardef, wgtdef, syst);
730  }
731 }
key
prepare the HTCondor submission files and eventually submit them
#define THist
Definition: cutflowutil.h:21
std::map< std::tuple< std::string, std::string, std::string >, TH1D * > booked_histograms
Definition: anautil.h:121
std::vector< std::tuple< std::string, std::string, std::string > > booked_histograms_nominal_keys
Definition: anautil.h:125
std::map< std::string, CutTree * > cuttreemap
Definition: anautil.h:117

◆ bookVecHistogram() [2/2]

void RooUtil::Cutflow::bookVecHistogram ( TString  cut,
std::pair< TString, std::tuple< std::vector< float >, std::function< std::vector< float >()>, std::function< std::vector< float >()>>>  key,
TString  syst = "" 
)

Definition at line 758 of file anautil.cc.

References DMR_cfg::cut, mps_fire::i, submitPVResolutionJobs::key, and THist.

763  {
764  TString varname = key.first;
765  std::vector<float> boundaries = std::get<0>(key.second);
766  std::function<std::vector<float>()> vardef = std::get<1>(key.second);
767  std::function<std::vector<float>()> wgtdef = std::get<2>(key.second);
768  TString histname = cut + syst + "__" + varname;
769  if (booked_histograms.find(std::make_tuple(cut.Data(), syst.Data(), varname.Data())) == booked_histograms.end()) {
770  Float_t bounds[boundaries.size()];
771  for (unsigned int i = 0; i < boundaries.size(); ++i)
772  bounds[i] = boundaries[i];
773  booked_histograms[std::make_tuple(cut.Data(), syst.Data(), varname.Data())] =
774  new THist(histname, "", boundaries.size() - 1, bounds);
775  booked_histograms[std::make_tuple(cut.Data(), syst.Data(), varname.Data())]->SetDirectory(0);
776  booked_histograms[std::make_tuple(cut.Data(), syst.Data(), varname.Data())]->Sumw2();
777  if (syst.IsNull()) {
778  booked_histograms_nominal_keys.push_back(std::make_tuple(cut.Data(), syst.Data(), varname.Data()));
779  }
780  cuttreemap[cut.Data()]->addHist1DVec(
781  booked_histograms[std::make_tuple(cut.Data(), syst.Data(), varname.Data())], vardef, wgtdef, syst);
782  }
783 }
key
prepare the HTCondor submission files and eventually submit them
#define THist
Definition: cutflowutil.h:21
std::map< std::tuple< std::string, std::string, std::string >, TH1D * > booked_histograms
Definition: anautil.h:121
std::vector< std::tuple< std::string, std::string, std::string > > booked_histograms_nominal_keys
Definition: anautil.h:125
std::map< std::string, CutTree * > cuttreemap
Definition: anautil.h:117

◆ copyAndEditCuts()

void RooUtil::Cutflow::copyAndEditCuts ( TString  ,
std::map< TString, TString >   
)

◆ createWgtSystBranches()

void RooUtil::Cutflow::createWgtSystBranches ( )

Definition at line 429 of file anautil.cc.

429  {
430  for (auto& syst : systs) {
431  if (!tx->hasBranch<float>(syst))
432  tx->createBranch<float>(syst);
433  }
434 }
std::vector< TString > systs
Definition: anautil.h:136
void createBranch(TString, bool=true)
bool hasBranch(TString)
TTreeX * tx
Definition: anautil.h:134

◆ fill()

void RooUtil::Cutflow::fill ( void  )

Definition at line 472 of file anautil.cc.

References RPCNoise_cfi::fillHistograms, and mps_check::msg.

Referenced by main().

472  {
473 #ifdef USE_TTREEX
474  if (!tx) {
475  TString msg = "No TTreeX object set, fill()";
477  return;
478  }
479  tx->setBranch<bool>("Root", 1); // Root is internally set
480  tx->setBranch<float>("Root_weight", 1); // Root is internally set
481 #else
482  cuttreemap["Root"]->pass_this_cut = 1;
483  cuttreemap["Root"]->weight_this_cut = 1;
484 #endif
485 
486  // Evaluate nominal selection cutflows (the non cut varying selections)
488 
489  // Nominal cutflow
490  fillCutflows();
491 
492  // Wgt systematic variations
493  for (auto& syst : systs)
494  fillCutflows(syst);
495 
496  // Fill nominal histograms
497  fillHistograms();
498 
499  if (not doskipsysthist) {
500  // Wgt systematic variations
501  for (auto& syst : systs)
502  fillHistograms(syst);
503  }
504 
505  for (auto& cutsyst : cutsysts) {
506  cuttree.evaluate(*tx, cutsyst, iseventlistbooked);
507  fillCutflows(cutsyst, false);
508  if (not doskipsysthist)
509  fillHistograms(cutsyst, false);
510  }
511 
512  if (tx) {
513  if (dosavettreex)
514  tx->fill();
515 
516  tx->clear();
517  }
518 }
void evaluate(RooUtil::TTreeX &tx, TString cutsystname="", bool doeventlist=false, bool aggregated_pass=true, float aggregated_weight=1)
Definition: cutflowutil.h:350
std::vector< TString > systs
Definition: anautil.h:136
bool iseventlistbooked
Definition: anautil.h:140
bool doskipsysthist
Definition: anautil.h:142
void printSetFunctionError(TString msg)
Definition: anautil.cc:1077
std::vector< TString > cutsysts
Definition: anautil.h:135
void setBranch(TString, T, bool=false, bool=false)
tuple msg
Definition: mps_check.py:286
TTreeX * tx
Definition: anautil.h:134
void fillHistograms(TString syst="", bool iswgtsyst=true)
Definition: anautil.cc:599
CutTree cuttree
Definition: anautil.h:115
void fillCutflows(TString syst="", bool iswgtsyst=true)
Definition: anautil.cc:522
bool dosavettreex
Definition: anautil.h:143
std::map< std::string, CutTree * > cuttreemap
Definition: anautil.h:117
void fill()
Definition: ttreex.h:122
void clear()
Definition: ttreex.cc:40

◆ fillCutflow()

void RooUtil::Cutflow::fillCutflow ( std::vector< TString > &  cutlist,
TH1D *  h,
TH1D *  hraw,
float  wgtsyst = 1 
)

Definition at line 565 of file anautil.cc.

References SimL1EmulatorRepack_CalouGT_cff::cutlist, h, and mps_fire::i.

565  {
566  for (unsigned int i = 0; i < cutlist.size(); ++i) {
567  int& pass = cuttreemap[cutlist[i].Data()]->pass;
568  if (pass) {
569  float& weight = cuttreemap[cutlist[i].Data()]->weight;
570  h->Fill(i, weight * wgtsyst);
571  hraw->Fill(i, 1);
572  } else {
573  return;
574  }
575  }
576 }
Definition: weight.py:1
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
std::map< std::string, CutTree * > cuttreemap
Definition: anautil.h:117

◆ fillCutflow_v2()

void RooUtil::Cutflow::fillCutflow_v2 ( std::vector< CutTree *> &  cutlist,
TH1D *  h,
TH1D *  hraw,
float  wgtsyst = 1 
)

Definition at line 579 of file anautil.cc.

References hgcalPlots::ct, h, and mps_fire::i.

582  {
583  for (unsigned int i = 0; i < cuttreelist.size(); ++i) {
584  RooUtil::CutTree* ct = cuttreelist[i];
585  // if (std::find(cutflow_nofill_cut_list.begin(), cutflow_nofill_cut_list.end(), ct->name) != cutflow_nofill_cut_list.end())
586  // continue;
587  int& pass = ct->pass;
588  if (pass) {
589  float& weight = ct->weight;
590  h->Fill(i, weight * wgtsyst);
591  hraw->Fill(i, 1);
592  } else {
593  return;
594  }
595  }
596 }
Definition: weight.py:1
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4

◆ fillCutflows()

void RooUtil::Cutflow::fillCutflows ( TString  syst = "",
bool  iswgtsyst = true 
)

Definition at line 522 of file anautil.cc.

522 { fillCutflows_v2(syst, iswgtsyst); }
void fillCutflows_v2(TString syst="", bool iswgtsyst=true)
Definition: anautil.cc:538

◆ fillCutflows_v1()

void RooUtil::Cutflow::fillCutflows_v1 ( TString  syst = "",
bool  iswgtsyst = true 
)

Definition at line 525 of file anautil.cc.

References SimL1EmulatorRepack_CalouGT_cff::cutlist, and RooUtil::CutflowUtil::fillCutflow().

525  {
526  for (auto& pair : cutlists) {
527  const TString& region_name = pair.first;
528  std::vector<TString>& cutlist = pair.second;
529  float wgtsyst = (!syst.IsNull() and iswgtsyst) ? systs_funcs[syst]() : 1;
531  cutflow_histograms[(region_name + syst).Data()],
532  rawcutflow_histograms[(region_name + syst).Data()],
533  wgtsyst);
534  }
535 }
std::map< TString, std::function< float()> > systs_funcs
Definition: anautil.h:137
void fillCutflow(std::vector< TString > &cutlist, TH1D *h, TH1D *hraw, float wgtsyst=1)
Definition: anautil.cc:565
std::map< TString, std::vector< TString > > cutlists
Definition: anautil.h:138
std::map< TString, TH1D * > rawcutflow_histograms
Definition: anautil.h:119
std::map< TString, TH1D * > cutflow_histograms
Definition: anautil.h:118

◆ fillCutflows_v2()

void RooUtil::Cutflow::fillCutflows_v2 ( TString  syst = "",
bool  iswgtsyst = true 
)

Definition at line 538 of file anautil.cc.

538  {
539  for (auto& pair : cuttreelists) {
540  const TString& region_name = pair.first;
541  std::vector<RooUtil::CutTree*>& cuttreelist = pair.second;
542  float wgtsyst = (!syst.IsNull() and iswgtsyst) ? systs_funcs[syst]() : 1;
543  fillCutflow_v2(cuttreelist,
544  cutflow_histograms[(region_name + syst).Data()],
545  rawcutflow_histograms[(region_name + syst).Data()],
546  wgtsyst);
547  }
548 }
std::map< TString, std::function< float()> > systs_funcs
Definition: anautil.h:137
std::map< TString, std::vector< CutTree * > > cuttreelists
Definition: anautil.h:139
void fillCutflow_v2(std::vector< CutTree *> &cutlist, TH1D *h, TH1D *hraw, float wgtsyst=1)
Definition: anautil.cc:579
std::map< TString, TH1D * > rawcutflow_histograms
Definition: anautil.h:119
std::map< TString, TH1D * > cutflow_histograms
Definition: anautil.h:118

◆ fillHistograms()

void RooUtil::Cutflow::fillHistograms ( TString  syst = "",
bool  iswgtsyst = true 
)

Definition at line 599 of file anautil.cc.

599  {
600 #ifdef USE_CUTLAMBDA
601  float wgtsyst = (!syst.IsNull() and iswgtsyst) ? systs_funcs[syst]() : 1;
602  cuttree.fillHistograms(syst, wgtsyst);
603 #else
604  float wgtsyst = (!syst.IsNull() and iswgtsyst) ? tx->getBranch<float>(syst) : 1.;
605  cuttree.fillHistograms(*tx, syst, wgtsyst);
606 #endif
607 
608  // for (auto& key1d : booked_histograms_nominal_keys)
609  // {
610  // TString cutname = std::get<0>(key1d);
611  // std::get<1>(key1d) = syst;
612  // TString varname = std::get<2>(key1d);
613  // bool& passed = cuttreemap[cutname.Data()]->pass;
614  // if (!passed)
615  // continue;
616  // float& weight = cuttreemap[cutname.Data()]->weight;
617  // float wgtsyst = (!syst.IsNull() and iswgtsyst)? tx->getBranch<float>(syst) : 1.;
618  // THist* h = booked_histograms[key1d];
619  // h->Fill(tx->getBranch<float>(varname), weight * wgtsyst);
620  // }
621  //
622  // for (auto& key2d : booked_2dhistograms_nominal_keys)
623  // {
624  // TString cutname = std::get<0>(key2d);
625  // std::get<1>(key2d) = syst;
626  // TString varname = std::get<2>(key2d);
627  // TString varnamey = std::get<3>(key2d);
628  // bool& passed = cuttreemap[cutname.Data()]->pass;
629  // if (!passed)
630  // continue;
631  // float& weight = cuttreemap[cutname.Data()]->weight;
632  // float wgtsyst = (!syst.IsNull() and iswgtsyst)? tx->getBranch<float>(syst) : 1.;
633  // TH2F* h = booked_2dhistograms[key2d];
634  // h->Fill(tx->getBranch<float>(varname), tx->getBranch<float>(varnamey), weight * wgtsyst);
635  // }
636 
637  // for (auto& pair : booked_histograms)
638  // {
639  // TString cutname = std::get<0>(pair.first);
640  // TString sysname = std::get<1>(pair.first);
641  // TString varname = std::get<2>(pair.first);
642  // THist* h = pair.second;
643  // bool& passed = cuttreemap[cutname.DATA()]->pass;
644  // float& weight = cuttreemap[cutname.DATA()]->weight;
645  // float wgtsyst = sysname.IsNull() ? 1. : tx->getBranch<float>(sysname);
646  // if (passed)
647  // h->Fill(tx->getBranch<float>(varname), weight * wgtsyst);
648  // }
649  //
650  // for (auto& pair : booked_2dhistograms)
651  // {
652  // TString cutname = std::get<0>(pair.first);
653  // TString sysname = std::get<1>(pair.first);
654  // TString varname = std::get<2>(pair.first);
655  // TString varnamey = std::get<3>(pair.first);
656  // TH2F* h = pair.second;
657  // bool& passed = cuttreemap[cutname.DATA()]->pass;
658  // float& weight = cuttreemap[cutname.DATA()]->weight;
659  // float wgtsyst = sysname.IsNull() ? 1. : tx->getBranch<float>(sysname);
660  // if (passed)
661  // h->Fill(tx->getBranch<float>(varname), tx->getBranch<float>(varnamey), weight * wgtsyst);
662  // }
663 }
std::map< TString, std::function< float()> > systs_funcs
Definition: anautil.h:137
void fillHistograms(TString syst, float extrawgt)
Definition: cutflowutil.h:520
const T & getBranch(TString, bool=true)
TTreeX * tx
Definition: anautil.h:134
CutTree cuttree
Definition: anautil.h:115

◆ filterCuts()

void RooUtil::Cutflow::filterCuts ( std::vector< TString >  ns)

Definition at line 114 of file anautil.cc.

References submitPVValidationJobs::child, DMR_cfg::cut, SimL1EmulatorRepack_CalouGT_cff::cutlist, spr::find(), mps_fire::i, and create_idmaps::n.

114  {
115  //
116  std::vector<TString> to_not_remove;
117  for (auto& n : ns) {
118  std::vector<TString> cutlist = cuttree.getCutList(n);
119  for (auto& cut : cutlist) {
120  to_not_remove.push_back(cut);
121  }
122  }
123 
124  for (auto& n : ns) {
125  std::vector<TString> cutlist = cuttree.getCutList(n);
126  for (unsigned int i = 0; i < cutlist.size() - 1; ++i) {
128  std::vector<RooUtil::CutTree*> toremove;
129  for (auto& child : cut->children) {
130  if (not child->name.EqualTo(cutlist[i + 1])) {
131  if (std::find(to_not_remove.begin(), to_not_remove.end(), child->name) == to_not_remove.end())
132  toremove.push_back(child);
133  }
134  }
135  for (auto& child : toremove) {
136  cut->children.erase(std::find(cut->children.begin(), cut->children.end(), child));
137  cuttreemap.erase(cuttreemap.find(child->name.Data()));
138  }
139  }
140  }
141 }
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
std::vector< TString > getCutList(TString n, std::vector< TString > cut_list=std::vector< TString >())
Definition: cutflowutil.h:272
CutTree cuttree
Definition: anautil.h:115
CutTree * getCutPointer(TString n)
Definition: cutflowutil.h:248
std::map< std::string, CutTree * > cuttreemap
Definition: anautil.h:117

◆ getCut()

RooUtil::CutTree & RooUtil::Cutflow::getCut ( TString  n)

Definition at line 65 of file anautil.cc.

References DummyCfis::c, and create_idmaps::n.

65  {
68  return c;
69 }
CutTree & getCut(TString n)
Definition: cutflowutil.h:263
void setLastActiveCut(TString n)
Definition: anautil.cc:59
CutTree cuttree
Definition: anautil.h:115

◆ printCuts()

void RooUtil::Cutflow::printCuts ( )

Definition at line 62 of file anautil.cc.

62 { cuttree.printCuts(); }
void printCuts(int indent=0, std::vector< int > multichild=std::vector< int >())
Definition: cutflowutil.h:119
CutTree cuttree
Definition: anautil.h:115

◆ printSetFunctionError()

void RooUtil::Cutflow::printSetFunctionError ( TString  msg)

Definition at line 1077 of file anautil.cc.

References mps_check::msg, and RooUtil::print().

1077  {
1078  if (seterrorcount < 100) {
1079  print(msg);
1080  seterrorcount++;
1081  } else if (seterrorcount == 100) {
1082  print(msg);
1083  print("Suppressing Cutflow::set\"Func\"() errors ... ");
1084  seterrorcount++;
1085  } else {
1086  return;
1087  }
1088 }
void print(TString msg="", const char *fname="", int flush_before=0, int flush_after=0)
Definition: printutil.cc:23
tuple msg
Definition: mps_check.py:286

◆ removeCut()

void RooUtil::Cutflow::removeCut ( TString  n)

Definition at line 107 of file anautil.cc.

References DummyCfis::c, spr::find(), and create_idmaps::n.

107  {
109  c->parent->children.erase(std::find(c->parent->children.begin(), c->parent->children.end(), c));
110  cuttreemap.erase(cuttreemap.find(n.Data()));
111 }
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
CutTree cuttree
Definition: anautil.h:115
CutTree * getCutPointer(TString n)
Definition: cutflowutil.h:248
std::map< std::string, CutTree * > cuttreemap
Definition: anautil.h:117

◆ saveCutflows()

void RooUtil::Cutflow::saveCutflows ( )

Definition at line 318 of file anautil.cc.

References RooUtil::CutflowUtil::saveCutflowHistograms().

318  {
319  // Save cutflow histograms
320  ofile->cd();
322 }
void saveCutflowHistograms(std::map< TString, TH1D *> &cutflows, std::map< TString, TH1D *> &rawcutflows)
Definition: cutflowutil.cc:123
std::map< TString, TH1D * > rawcutflow_histograms
Definition: anautil.h:119
TFile * ofile
Definition: anautil.h:132
std::map< TString, TH1D * > cutflow_histograms
Definition: anautil.h:118

◆ saveHistograms()

void RooUtil::Cutflow::saveHistograms ( )

Definition at line 325 of file anautil.cc.

325  {
326  ofile->cd();
327  for (auto& pair : booked_histograms)
328  pair.second->Write();
329  for (auto& pair : booked_2dhistograms)
330  pair.second->Write();
331 }
std::map< std::tuple< std::string, std::string, std::string, std::string >, TH2F * > booked_2dhistograms
Definition: anautil.h:123
TFile * ofile
Definition: anautil.h:132
std::map< std::tuple< std::string, std::string, std::string >, TH1D * > booked_histograms
Definition: anautil.h:121

◆ saveOutput()

void RooUtil::Cutflow::saveOutput ( )

Definition at line 308 of file anautil.cc.

References corrVsCorr::filename, mps_check::msg, RooUtil::print(), and ntuplePlotting::saveHistograms().

Referenced by main(), and run_lst().

308  {
309  saveCutflows();
310  saveHistograms();
311  saveTTreeX();
312  TString filename = ofile->GetName();
313  TString msg = "Wrote output to " + filename;
314  print(msg);
315 }
void print(TString msg="", const char *fname="", int flush_before=0, int flush_after=0)
Definition: printutil.cc:23
void saveTTreeX()
Definition: anautil.cc:334
void saveCutflows()
Definition: anautil.cc:318
TFile * ofile
Definition: anautil.h:132
tuple msg
Definition: mps_check.py:286
void saveHistograms()
Definition: anautil.cc:325

◆ saveTTreeX()

void RooUtil::Cutflow::saveTTreeX ( )

Definition at line 334 of file anautil.cc.

334  {
335  if (dosavettreex) {
336  ofile->cd();
337  tx->save(ofile);
338  }
339 }
void save(TFile *)
Definition: ttreex.cc:78
TFile * ofile
Definition: anautil.h:132
TTreeX * tx
Definition: anautil.h:134
bool dosavettreex
Definition: anautil.h:143

◆ setCut()

void RooUtil::Cutflow::setCut ( TString  cutname,
std::function< bool()>  pass,
std::function< float()>  weight 
)

Definition at line 343 of file anautil.cc.

References mps_merge::weight.

343  {
344  cuttreemap[cutname.Data()]->pass_this_cut_func = pass;
345  cuttreemap[cutname.Data()]->weight_this_cut_func = weight;
346 }
std::map< std::string, CutTree * > cuttreemap
Definition: anautil.h:117

◆ setCutLists()

void RooUtil::Cutflow::setCutLists ( std::vector< TString >  regions)

Definition at line 144 of file anautil.cc.

References nano_mu_digi_cff::region.

144  {
145  for (auto& region : regions) {
147  // std::cout << region << std::endl;
148  // for (auto& cutname : cutlists[region])
149  // std::cout << cutname << std::endl;
150  }
151  for (auto& region : regions) {
152  for (auto& cutname : cutlists[region]) {
153  cuttreelists[region].push_back(cuttreemap[cutname.Data()]);
154  }
155  }
156 }
std::map< TString, std::vector< CutTree * > > cuttreelists
Definition: anautil.h:139
std::map< TString, std::vector< TString > > cutlists
Definition: anautil.h:138
std::vector< TString > getCutList(TString n, std::vector< TString > cut_list=std::vector< TString >())
Definition: cutflowutil.h:272
CutTree cuttree
Definition: anautil.h:115
std::map< std::string, CutTree * > cuttreemap
Definition: anautil.h:117

◆ setCutSyst()

void RooUtil::Cutflow::setCutSyst ( TString  cutname,
TString  syst,
std::function< bool()>  pass,
std::function< float()>  weight 
)

Definition at line 349 of file anautil.cc.

References RooUtil::error(), and mps_merge::weight.

352  {
353  if (cuttreemap[cutname.Data()]->systs.find(syst) == cuttreemap[cutname.Data()]->systs.end()) {
354  error(
355  TString::Format("setCutSyst():: Did not find syst=%s from the cut=%s! Did you actually book this syst for the "
356  "cut properly using addCutSyst() ?",
357  syst.Data(),
358  cutname.Data()));
359  }
360  cuttreemap[cutname.Data()]->systs[syst]->pass_this_cut_func = pass;
361  cuttreemap[cutname.Data()]->systs[syst]->weight_this_cut_func = weight;
362 }
void error(TString msg, const char *fname="", int is_error=1)
Definition: printutil.cc:44
std::map< std::string, CutTree * > cuttreemap
Definition: anautil.h:117

◆ setEventID()

void RooUtil::Cutflow::setEventID ( int  run,
int  lumi,
unsigned long long  evt 
)

Definition at line 447 of file anautil.cc.

References BXlumiParameters_cfi::lumi, mps_check::msg, and writedatasetfile::run.

447  {
448  if (!tx) {
449  TString msg = "No TTreeX object set, setEventID()";
451  return;
452  }
453  tx->setBranch<int>("run", run, false, true);
454  tx->setBranch<int>("lumi", lumi, false, true);
455  tx->setBranch<unsigned long long>("evt", evt, false, true);
456 }
void printSetFunctionError(TString msg)
Definition: anautil.cc:1077
void setBranch(TString, T, bool=false, bool=false)
tuple msg
Definition: mps_check.py:286
TTreeX * tx
Definition: anautil.h:134

◆ setHistsAxesExtendable()

void RooUtil::Cutflow::setHistsAxesExtendable ( )

Definition at line 1091 of file anautil.cc.

1091  {
1092  for (auto& pair : booked_histograms)
1093  pair.second->SetCanExtend(TH1::kAllAxes);
1094 }
std::map< std::tuple< std::string, std::string, std::string >, TH1D * > booked_histograms
Definition: anautil.h:121

◆ setLastActiveCut()

void RooUtil::Cutflow::setLastActiveCut ( TString  n)

Definition at line 59 of file anautil.cc.

References create_idmaps::n.

CutTree * last_active_cut
Definition: anautil.h:116
CutTree cuttree
Definition: anautil.h:115
CutTree * getCutPointer(TString n)
Definition: cutflowutil.h:248

◆ setSaveTTreeX()

void RooUtil::Cutflow::setSaveTTreeX ( bool  v = true)

Definition at line 1074 of file anautil.cc.

References findQualityFiles::v.

◆ setSkipSystematicHistograms()

void RooUtil::Cutflow::setSkipSystematicHistograms ( bool  v = true)

Definition at line 1071 of file anautil.cc.

References findQualityFiles::v.

◆ setTFile()

void RooUtil::Cutflow::setTFile ( TFile *  o)
inline

Definition at line 148 of file anautil.h.

References EcalTangentSkim_cfg::o, and ofile.

Referenced by initializeInputsAndOutputs(), and main().

◆ setVariable()

void RooUtil::Cutflow::setVariable ( TString  varname,
float  val 
)

Definition at line 437 of file anautil.cc.

References mps_check::msg, and heppy_batch::val.

437  {
438  if (!tx) {
439  TString msg = "No TTreeX object set, setVariable() for " + varname;
441  return;
442  }
443  tx->setBranch<float>(varname, val, false, true);
444 }
void printSetFunctionError(TString msg)
Definition: anautil.cc:1077
void setBranch(TString, T, bool=false, bool=false)
tuple msg
Definition: mps_check.py:286
TTreeX * tx
Definition: anautil.h:134

◆ setWgtSyst()

void RooUtil::Cutflow::setWgtSyst ( TString  syst,
float  weight 
)

Definition at line 402 of file anautil.cc.

References mps_check::msg, and mps_merge::weight.

402  {
403  if (!tx) {
404  TString msg = "No TTreeX object set, setWgtSyst() for " + syst;
406  return;
407  }
408  tx->setBranch<float>(syst, weight, false, true);
409 }
void printSetFunctionError(TString msg)
Definition: anautil.cc:1077
void setBranch(TString, T, bool=false, bool=false)
tuple msg
Definition: mps_check.py:286
TTreeX * tx
Definition: anautil.h:134

Member Data Documentation

◆ booked_2dhistograms

std::map<std::tuple< std::string , std::string , std::string , std::string >, TH2F*> RooUtil::Cutflow::booked_2dhistograms

Definition at line 123 of file anautil.h.

◆ booked_2dhistograms_nominal_keys

std::vector<std::tuple< std::string , std::string , std::string , std::string > > RooUtil::Cutflow::booked_2dhistograms_nominal_keys

Definition at line 127 of file anautil.h.

◆ booked_histograms

std::map<std::tuple< std::string , std::string , std::string >, TH1D *> RooUtil::Cutflow::booked_histograms

Definition at line 121 of file anautil.h.

◆ booked_histograms_nominal_keys

std::vector<std::tuple< std::string , std::string , std::string > > RooUtil::Cutflow::booked_histograms_nominal_keys

Definition at line 125 of file anautil.h.

◆ cutflow_booked

bool RooUtil::Cutflow::cutflow_booked

Definition at line 144 of file anautil.h.

◆ cutflow_histograms

std::map< TString , TH1D *> RooUtil::Cutflow::cutflow_histograms

Definition at line 118 of file anautil.h.

◆ cutflow_histograms_v2

std::vector<std::tuple< TH1D *, std::vector<int*>, std::vector<float*>, std::function<float()> > > RooUtil::Cutflow::cutflow_histograms_v2

Definition at line 129 of file anautil.h.

◆ cutflow_nofill_cut_list

std::vector<TString> RooUtil::Cutflow::cutflow_nofill_cut_list

Definition at line 131 of file anautil.h.

◆ cutlists

std::map<TString, std::vector<TString> > RooUtil::Cutflow::cutlists

Definition at line 138 of file anautil.h.

◆ cutsysts

std::vector<TString> RooUtil::Cutflow::cutsysts

Definition at line 135 of file anautil.h.

◆ cuttree

CutTree RooUtil::Cutflow::cuttree

Definition at line 115 of file anautil.h.

Referenced by Cutflow().

◆ cuttreelists

std::map<TString, std::vector<CutTree*> > RooUtil::Cutflow::cuttreelists

Definition at line 139 of file anautil.h.

◆ cuttreemap

std::map< std::string , CutTree*> RooUtil::Cutflow::cuttreemap

Definition at line 117 of file anautil.h.

Referenced by Cutflow().

◆ dosavettreex

bool RooUtil::Cutflow::dosavettreex

Definition at line 143 of file anautil.h.

◆ doskipsysthist

bool RooUtil::Cutflow::doskipsysthist

Definition at line 142 of file anautil.h.

◆ iseventlistbooked

bool RooUtil::Cutflow::iseventlistbooked

Definition at line 140 of file anautil.h.

◆ last_active_cut

CutTree* RooUtil::Cutflow::last_active_cut

Definition at line 116 of file anautil.h.

◆ ofile

TFile* RooUtil::Cutflow::ofile

Definition at line 132 of file anautil.h.

Referenced by setTFile().

◆ rawcutflow_histograms

std::map< TString , TH1D *> RooUtil::Cutflow::rawcutflow_histograms

Definition at line 119 of file anautil.h.

◆ rawcutflow_histograms_v2

std::vector<std::tuple< TH1D *, std::vector<int*> > > RooUtil::Cutflow::rawcutflow_histograms_v2

Definition at line 130 of file anautil.h.

◆ seterrorcount

int RooUtil::Cutflow::seterrorcount

Definition at line 141 of file anautil.h.

◆ systs

std::vector<TString> RooUtil::Cutflow::systs

Definition at line 136 of file anautil.h.

◆ systs_funcs

std::map<TString, std::function<float()> > RooUtil::Cutflow::systs_funcs

Definition at line 137 of file anautil.h.

◆ t

TTree* RooUtil::Cutflow::t

Definition at line 133 of file anautil.h.

◆ tx

TTreeX* RooUtil::Cutflow::tx

Definition at line 134 of file anautil.h.