CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Private Attributes
SmartSelectionMonitor Class Reference

#include <SmartSelectionMonitor.h>

Public Types

typedef std::unordered_map< std::string, std::map< std::string, TH1 * > * > Monitor_t
 

Public Member Functions

TH1 * addHistogram (TH1 *h, std::string tag)
 
TH1 * addHistogram (TH1 *h)
 
bool fillHisto (std::string name, std::string tag, double valx, double weight, bool useBinWidth=false)
 
bool fillHisto (std::string name, std::string tag, double valx, double valy, double weight, bool useBinWidth=false)
 
bool fillHisto (std::string name, std::vector< std::string > tags, double valx, double weight, bool useBinWidth=false)
 
bool fillHisto (std::string name, std::vector< std::string > tags, double valx, double valy, double weight, bool useBinWidth=false)
 
bool fillHisto (std::string name, std::vector< std::string > tags, double valx, std::vector< double > weights, bool useBinWidth=false)
 
bool fillHisto (std::string name, std::vector< std::string > tags, double valx, double valy, std::vector< double > weights, bool useBinWidth=false)
 
bool fillProfile (std::string name, std::string tag, double valx, double valy, double weight)
 
bool fillProfile (std::string name, std::vector< std::string > tags, double valx, double valy, double weight)
 
bool fillProfile (std::string name, std::vector< std::string > tags, double valx, double valy, std::vector< double > weights)
 
Monitor_tgetAllMonitors ()
 
TH1 * getHisto (std::string histo, std::string tag="all")
 
bool hasBaseHisto (std::string histo)
 
bool hasTag (std::map< std::string, TH1 *> *map, std::string tag)
 
bool hasTag (std::string histo, std::string tag)
 
void initMonitorForStep (std::string tag)
 
void Scale (double w)
 
 SmartSelectionMonitor ()
 
void Write ()
 
 ~SmartSelectionMonitor ()=default
 

Private Attributes

Monitor_t allMonitors_
 

Detailed Description

Definition at line 20 of file SmartSelectionMonitor.h.

Member Typedef Documentation

◆ Monitor_t

typedef std::unordered_map<std::string, std::map<std::string, TH1*>*> SmartSelectionMonitor::Monitor_t

Definition at line 25 of file SmartSelectionMonitor.h.

Constructor & Destructor Documentation

◆ SmartSelectionMonitor()

SmartSelectionMonitor::SmartSelectionMonitor ( )
inline

Definition at line 22 of file SmartSelectionMonitor.h.

22 {}

◆ ~SmartSelectionMonitor()

SmartSelectionMonitor::~SmartSelectionMonitor ( )
default

Member Function Documentation

◆ addHistogram() [1/2]

TH1 * SmartSelectionMonitor::addHistogram ( TH1 *  h,
std::string  tag 
)

Definition at line 4 of file SmartSelectionMonitor.cc.

References allMonitors_, h, hasBaseHisto(), and timingPdfMaker::histo.

Referenced by addHistogram(), and JetHTAnalyzer::beginJob().

4  {
5  if (!h->GetDefaultSumw2())
6  h->Sumw2();
7  if (!hasBaseHisto(histo)) {
8  allMonitors_[histo] = new std::map<std::string, TH1 *>;
9  }
10  (*allMonitors_[histo])["all"] = h;
11  return (*allMonitors_[histo])["all"];
12 }
bool hasBaseHisto(std::string histo)
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4

◆ addHistogram() [2/2]

TH1 * SmartSelectionMonitor::addHistogram ( TH1 *  h)

Definition at line 14 of file SmartSelectionMonitor.cc.

References addHistogram(), and h.

14  {
15  if (h == nullptr)
16  return nullptr;
17  return addHistogram(h, h->GetName());
18 }
TH1 * addHistogram(TH1 *h, std::string tag)
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4

◆ fillHisto() [1/6]

bool SmartSelectionMonitor::fillHisto ( std::string  name,
std::string  tag,
double  valx,
double  weight,
bool  useBinWidth = false 
)

Definition at line 21 of file SmartSelectionMonitor.cc.

References getHisto(), h, Skims_PA_cff::name, makeGlobalPositionRcd_cfg::tag, heppy_batch::val, and ApeEstimator_cff::width.

Referenced by JetHTAnalyzer::analyze(), and fillHisto().

21  {
22  TH1 *h = getHisto(name, tag);
23  if (h == nullptr)
24  return false;
25  if (useBinWidth) {
26  int ibin = h->FindBin(val);
27  double width = h->GetBinWidth(ibin);
28  weight /= width;
29  }
30  h->Fill(val, weight);
31  return true;
32 }
TH1 * getHisto(std::string histo, std::string tag="all")
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

◆ fillHisto() [2/6]

bool SmartSelectionMonitor::fillHisto ( std::string  name,
std::string  tag,
double  valx,
double  valy,
double  weight,
bool  useBinWidth = false 
)

Definition at line 51 of file SmartSelectionMonitor.cc.

References getHisto(), h, Skims_PA_cff::name, makeGlobalPositionRcd_cfg::tag, and ApeEstimator_cff::width.

52  {
53  TH2 *h = (TH2 *)getHisto(name, tag);
54  if (h == nullptr)
55  return false;
56  if (useBinWidth) {
57  int ibin = h->FindBin(valx, valy);
58  double width = h->GetBinWidth(ibin);
59  weight /= width;
60  }
61  h->Fill(valx, valy, weight);
62  return true;
63 }
TH1 * getHisto(std::string histo, std::string tag="all")
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

◆ fillHisto() [3/6]

bool SmartSelectionMonitor::fillHisto ( std::string  name,
std::vector< std::string >  tags,
double  valx,
double  weight,
bool  useBinWidth = false 
)

Definition at line 34 of file SmartSelectionMonitor.cc.

References fillHisto(), mps_fire::i, Skims_PA_cff::name, triggerMatcherToHLTDebug_cfi::tags, and heppy_batch::val.

35  {
36  for (unsigned int i = 0; i < tags.size(); i++) {
37  fillHisto(name, tags[i], val, weight, useBinWidth);
38  }
39  return true;
40 }
bool fillHisto(std::string name, std::string tag, double valx, double weight, bool useBinWidth=false)
Definition: weight.py:1

◆ fillHisto() [4/6]

bool SmartSelectionMonitor::fillHisto ( std::string  name,
std::vector< std::string >  tags,
double  valx,
double  valy,
double  weight,
bool  useBinWidth = false 
)

Definition at line 65 of file SmartSelectionMonitor.cc.

References fillHisto(), mps_fire::i, Skims_PA_cff::name, and triggerMatcherToHLTDebug_cfi::tags.

66  {
67  for (unsigned int i = 0; i < tags.size(); i++) {
68  fillHisto(name, tags[i], valx, valy, weight, useBinWidth);
69  }
70  return true;
71 }
bool fillHisto(std::string name, std::string tag, double valx, double weight, bool useBinWidth=false)
Definition: weight.py:1

◆ fillHisto() [5/6]

bool SmartSelectionMonitor::fillHisto ( std::string  name,
std::vector< std::string >  tags,
double  valx,
std::vector< double >  weights,
bool  useBinWidth = false 
)

Definition at line 42 of file SmartSelectionMonitor.cc.

References fillHisto(), mps_fire::i, Skims_PA_cff::name, triggerMatcherToHLTDebug_cfi::tags, heppy_batch::val, and hltDeepSecondaryVertexTagInfosPFPuppi_cfi::weights.

43  {
44  for (unsigned int i = 0; i < tags.size(); i++) {
45  fillHisto(name, tags[i], val, weights[i], useBinWidth);
46  }
47  return true;
48 }
bool fillHisto(std::string name, std::string tag, double valx, double weight, bool useBinWidth=false)

◆ fillHisto() [6/6]

bool SmartSelectionMonitor::fillHisto ( std::string  name,
std::vector< std::string >  tags,
double  valx,
double  valy,
std::vector< double >  weights,
bool  useBinWidth = false 
)

Definition at line 73 of file SmartSelectionMonitor.cc.

References fillHisto(), mps_fire::i, Skims_PA_cff::name, triggerMatcherToHLTDebug_cfi::tags, and hltDeepSecondaryVertexTagInfosPFPuppi_cfi::weights.

78  {
79  for (unsigned int i = 0; i < tags.size(); i++) {
80  fillHisto(name, tags[i], valx, valy, weights[i], useBinWidth);
81  }
82  return true;
83 }
bool fillHisto(std::string name, std::string tag, double valx, double weight, bool useBinWidth=false)

◆ fillProfile() [1/3]

bool SmartSelectionMonitor::fillProfile ( std::string  name,
std::string  tag,
double  valx,
double  valy,
double  weight 
)

Definition at line 86 of file SmartSelectionMonitor.cc.

References getHisto(), h, Skims_PA_cff::name, and makeGlobalPositionRcd_cfg::tag.

Referenced by JetHTAnalyzer::analyze(), and fillProfile().

86  {
87  TProfile *h = (TProfile *)getHisto(name, tag);
88  if (h == nullptr)
89  return false;
90  h->Fill(valx, valy, weight);
91  return true;
92 }
TH1 * getHisto(std::string histo, std::string tag="all")
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

◆ fillProfile() [2/3]

bool SmartSelectionMonitor::fillProfile ( std::string  name,
std::vector< std::string >  tags,
double  valx,
double  valy,
double  weight 
)

Definition at line 94 of file SmartSelectionMonitor.cc.

References fillProfile(), mps_fire::i, Skims_PA_cff::name, and triggerMatcherToHLTDebug_cfi::tags.

95  {
96  for (unsigned int i = 0; i < tags.size(); i++) {
97  fillProfile(name, tags[i], valx, valy, weight);
98  }
99  return true;
100 }
Definition: weight.py:1
bool fillProfile(std::string name, std::string tag, double valx, double valy, double weight)

◆ fillProfile() [3/3]

bool SmartSelectionMonitor::fillProfile ( std::string  name,
std::vector< std::string >  tags,
double  valx,
double  valy,
std::vector< double >  weights 
)

Definition at line 102 of file SmartSelectionMonitor.cc.

References fillProfile(), mps_fire::i, Skims_PA_cff::name, triggerMatcherToHLTDebug_cfi::tags, and hltDeepSecondaryVertexTagInfosPFPuppi_cfi::weights.

103  {
104  for (unsigned int i = 0; i < tags.size(); i++) {
105  fillProfile(name, tags[i], valx, valy, weights[i]);
106  }
107  return true;
108 }
bool fillProfile(std::string name, std::string tag, double valx, double valy, double weight)

◆ getAllMonitors()

Monitor_t& SmartSelectionMonitor::getAllMonitors ( )
inline

Definition at line 28 of file SmartSelectionMonitor.h.

References allMonitors_.

28 { return allMonitors_; }

◆ getHisto()

TH1* SmartSelectionMonitor::getHisto ( std::string  histo,
std::string  tag = "all" 
)
inline

Definition at line 65 of file SmartSelectionMonitor.h.

References allMonitors_, hasBaseHisto(), hasTag(), timingPdfMaker::histo, genParticles_cff::map, and makeGlobalPositionRcd_cfg::tag.

Referenced by fillHisto(), and fillProfile().

65  {
66  if (!hasBaseHisto(histo))
67  return nullptr;
68  std::map<std::string, TH1*>* map = allMonitors_[histo];
69  if (!hasTag(map, tag))
70  return nullptr;
71  return (*map)[tag];
72  }
bool hasTag(std::map< std::string, TH1 *> *map, std::string tag)
bool hasBaseHisto(std::string histo)

◆ hasBaseHisto()

bool SmartSelectionMonitor::hasBaseHisto ( std::string  histo)
inline

Definition at line 31 of file SmartSelectionMonitor.h.

References allMonitors_, and timingPdfMaker::histo.

Referenced by addHistogram(), getHisto(), and hasTag().

31  {
32  if (allMonitors_.find(histo) == allMonitors_.end())
33  return false;
34  return true;
35  }

◆ hasTag() [1/2]

bool SmartSelectionMonitor::hasTag ( std::map< std::string, TH1 *> *  map,
std::string  tag 
)
inline

Definition at line 38 of file SmartSelectionMonitor.h.

References newFWLiteAna::base, h, genParticles_cff::map, Skims_PA_cff::name, and makeGlobalPositionRcd_cfg::tag.

Referenced by getHisto(), and hasTag().

38  {
39  if (map->find(tag) != map->end())
40  return true;
41  if (map->find("all") == map->end())
42  return false;
43 
44  TH1* base = (*map)["all"];
45  TString allName = base->GetName();
46  TString name = tag + "_" + allName.Data();
47  TH1* h = (TH1*)base->Clone(name);
48  h->SetName(name);
49  h->SetTitle(name);
50  h->Reset("ICE");
51  h->SetDirectory(gROOT);
52  (*map)[tag] = h;
53  return true;
54  }
base
Main Program
Definition: newFWLiteAna.py:92
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4

◆ hasTag() [2/2]

bool SmartSelectionMonitor::hasTag ( std::string  histo,
std::string  tag 
)
inline

Definition at line 57 of file SmartSelectionMonitor.h.

References allMonitors_, hasBaseHisto(), hasTag(), timingPdfMaker::histo, genParticles_cff::map, and makeGlobalPositionRcd_cfg::tag.

57  {
58  if (!hasBaseHisto(histo))
59  return false;
60  std::map<std::string, TH1*>* map = allMonitors_[histo];
61  return hasTag(map, tag);
62  }
bool hasTag(std::map< std::string, TH1 *> *map, std::string tag)
bool hasBaseHisto(std::string histo)

◆ initMonitorForStep()

void SmartSelectionMonitor::initMonitorForStep ( std::string  tag)

◆ Scale()

void SmartSelectionMonitor::Scale ( double  w)
inline

Definition at line 104 of file SmartSelectionMonitor.h.

References allMonitors_, h, genParticles_cff::map, and w().

104  {
105  for (Monitor_t::iterator it = allMonitors_.begin(); it != allMonitors_.end(); it++) {
106  std::map<std::string, TH1*>* map = it->second;
107  for (std::map<std::string, TH1*>::iterator h = map->begin(); h != map->end(); h++) {
108  if (!(h->second)) {
109  continue;
110  }
111  h->second->Scale(w);
112  }
113  }
114  }
T w() const
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4

◆ Write()

void SmartSelectionMonitor::Write ( )
inline

Definition at line 75 of file SmartSelectionMonitor.h.

References allMonitors_, h, and genParticles_cff::map.

Referenced by JetHTAnalyzer::endJob().

75  {
76  for (Monitor_t::iterator it = allMonitors_.begin(); it != allMonitors_.end(); it++) {
77  std::map<std::string, TH1*>* map = it->second;
78  bool neverFilled = true;
79 
80  for (std::map<std::string, TH1*>::iterator h = map->begin(); h != map->end(); h++) {
81  if (!(h->second)) {
82  printf("histo = %30s %15s IS NULL", it->first.c_str(), h->first.c_str());
83  continue;
84  }
85  if (h->second->GetEntries() > 0)
86  neverFilled = false;
87 
88  if (h->first == "all") {
89  h->second->SetName(Form("%s_%s", h->first.c_str(), h->second->GetName()));
90  }
91  h->second->Write();
92  }
93 
94  if (neverFilled) {
95  printf(
96  "SmartSelectionMonitor: histo = '%s' is empty for all categories, you may want to cleanup your project to "
97  "remove this histogram\n",
98  it->first.c_str());
99  }
100  }
101  }
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4

Member Data Documentation

◆ allMonitors_

Monitor_t SmartSelectionMonitor::allMonitors_
private