CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes
ConfigurableHisto Class Reference

#include <ConfigurableHisto.h>

Inheritance diagram for ConfigurableHisto:
SplittingConfigurableHisto

Public Types

enum  HType { h1, h2, prof }
 

Public Member Functions

virtual void book (TFileDirectory *dir)
 
virtual ConfigurableHistoclone () const
 
void complete ()
 
 ConfigurableHisto (HType t, std::string name, edm::ParameterSet &iConfig)
 
virtual void fill (const edm::Event &iEvent)
 
TH1 * h ()
 
const HTypetype ()
 
virtual ~ConfigurableHisto ()
 

Protected Member Functions

 ConfigurableHisto (const ConfigurableHisto &master)
 

Protected Attributes

edm::ParameterSet conf_
 
TH1 * h_
 
std::string name_
 
HType type_
 
const CachingVariablew_
 
const CachingVariablex_
 
const CachingVariabley_
 
const CachingVariablez_
 

Detailed Description

Definition at line 70 of file ConfigurableHisto.h.

Member Enumeration Documentation

◆ HType

Enumerator
h1 
h2 
prof 

Definition at line 72 of file ConfigurableHisto.h.

Constructor & Destructor Documentation

◆ ConfigurableHisto() [1/2]

ConfigurableHisto::ConfigurableHisto ( HType  t,
std::string  name,
edm::ParameterSet iConfig 
)
inline

Definition at line 73 of file ConfigurableHisto.h.

Referenced by clone(), and SplittingConfigurableHisto::SplittingConfigurableHisto().

74  : type_(t), h_(nullptr), name_(name), conf_(iConfig), x_(nullptr), y_(nullptr), z_(nullptr), w_(nullptr) {}
const CachingVariable * y_
const CachingVariable * x_
const CachingVariable * w_
edm::ParameterSet conf_
const CachingVariable * z_

◆ ~ConfigurableHisto()

virtual ConfigurableHisto::~ConfigurableHisto ( )
inlinevirtual

Definition at line 76 of file ConfigurableHisto.h.

76 {}

◆ ConfigurableHisto() [2/2]

ConfigurableHisto::ConfigurableHisto ( const ConfigurableHisto master)
inlineprotected

Definition at line 220 of file ConfigurableHisto.h.

References conf_, h_, volumeBasedMagneticField_160812_cfi::master, name_, type_, w_, x_, y_, and z_.

220  {
221  type_ = master.type_;
222  h_ = nullptr; //no histogram attached in copy constructor
223  name_ = master.name_;
224  conf_ = master.conf_;
225  x_ = master.x_;
226  y_ = master.y_;
227  z_ = master.z_;
228  w_ = master.w_;
229  }
const CachingVariable * y_
const CachingVariable * x_
const CachingVariable * w_
edm::ParameterSet conf_
const CachingVariable * z_

Member Function Documentation

◆ book()

virtual void ConfigurableHisto::book ( TFileDirectory dir)
inlinevirtual

Reimplemented in SplittingConfigurableHisto.

Definition at line 80 of file ConfigurableHisto.h.

References conf_, DeadROC_duringRun::dir, edm::ParameterSet::dump(), edm::ParameterSet::exists(), edm::ParameterSet::getParameter(), h1, h2, h_, name_, prof, AlCaHLTBitMon_QueryRunRegistry::string, runGCPTkAlMap::title, type(), w_, x_, HLT_2022v12_cff::xAxis, y_, and HLT_2022v12_cff::yAxis.

Referenced by SplittingConfigurableHisto::book().

80  {
83  ConfigurableAxis xAxis(xAxisPSet);
84  x_ = edm::Service<VariableHelperService>()->get().variable(xAxisPSet.getParameter<std::string>("var"));
85 
86  std::string yLabel = "";
87  bool yVBin = false;
89  if (conf_.exists("yAxis")) {
91  yAxis = ConfigurableAxis(yAxisPSet);
92  yLabel = yAxis.Label();
93  //at least TH2 or TProfile
94  if (yAxisPSet.exists("var"))
95  y_ = edm::Service<VariableHelperService>()->get().variable(yAxisPSet.getParameter<std::string>("var"));
96  yVBin = yAxis.variableSize();
97  }
98 
99  if (conf_.exists("zAxis")) {
100  throw;
101  }
102 
103  bool xVBin = xAxis.variableSize();
104 
105  if (type() == h1) {
106  //make TH1F
107  if (xVBin)
108  h_ = dir->make<TH1F>(name_.c_str(), title.c_str(), xAxis.nBin(), xAxis.xBins());
109  else
110  h_ = dir->make<TH1F>(name_.c_str(), title.c_str(), xAxis.nBin(), xAxis.Min(), xAxis.Max());
111  } else if (type() == h2) {
112  //make TH2F
113  if (xVBin) {
114  if (yVBin)
115  h_ = dir->make<TH2F>(name_.c_str(), title.c_str(), xAxis.nBin(), xAxis.xBins(), yAxis.nBin(), yAxis.xBins());
116  else
117  h_ = dir->make<TH2F>(
118  name_.c_str(), title.c_str(), xAxis.nBin(), xAxis.xBins(), yAxis.nBin(), yAxis.Min(), yAxis.Max());
119  } else {
120  if (yVBin)
121  h_ = dir->make<TH2F>(
122  name_.c_str(), title.c_str(), xAxis.nBin(), xAxis.Min(), xAxis.Max(), yAxis.nBin(), yAxis.xBins());
123  else
124  h_ = dir->make<TH2F>(name_.c_str(),
125  title.c_str(),
126  xAxis.nBin(),
127  xAxis.Min(),
128  xAxis.Max(),
129  yAxis.nBin(),
130  yAxis.Min(),
131  yAxis.Max());
132  }
133  } else if (type() == prof) {
134  //make TProfile
135  std::string pFopt = "";
136  if (conf_.exists("Option"))
137  pFopt = conf_.getParameter<std::string>("Option");
138 
139  if (xVBin)
140  h_ = dir->make<TProfile>(
141  name_.c_str(), title.c_str(), xAxis.nBin(), xAxis.xBins(), yAxis.Min(), yAxis.Max(), pFopt.c_str());
142  else
143  h_ = dir->make<TProfile>(name_.c_str(),
144  title.c_str(),
145  xAxis.nBin(),
146  xAxis.Min(),
147  xAxis.Max(),
148  yAxis.Min(),
149  yAxis.Max(),
150  pFopt.c_str());
151 
152  } else {
153  edm::LogError("ConfigurableHisto") << "cannot book: " << name_ << "\n" << conf_.dump();
154  throw;
155  }
156 
157  //cosmetics
158  h_->GetXaxis()->SetTitle(xAxis.Label().c_str());
159  h_->SetYTitle(yLabel.c_str());
160 
161  if (conf_.exists("weight")) {
162  w_ = edm::Service<VariableHelperService>()->get().variable(conf_.getParameter<std::string>("weight"));
163  }
164  }
const HType & type()
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
bool exists(std::string const &parameterName) const
checks if a parameter exists
Log< level::Error, false > LogError
const CachingVariable * y_
const CachingVariable * x_
const CachingVariable * w_
std::string dump(unsigned int indent=0) const
edm::ParameterSet conf_

◆ clone()

virtual ConfigurableHisto* ConfigurableHisto::clone ( void  ) const
inlinevirtual

Reimplemented in SplittingConfigurableHisto.

Definition at line 78 of file ConfigurableHisto.h.

References ConfigurableHisto().

78 { return new ConfigurableHisto(*this); }
ConfigurableHisto(HType t, std::string name, edm::ParameterSet &iConfig)

◆ complete()

void ConfigurableHisto::complete ( )
inline

Definition at line 216 of file ConfigurableHisto.h.

216 {}

◆ fill()

virtual void ConfigurableHisto::fill ( const edm::Event iEvent)
inlinevirtual

Reimplemented in SplittingConfigurableHisto.

Definition at line 166 of file ConfigurableHisto.h.

References CachingVariable::compute(), conf_, edm::ParameterSet::dump(), h1, h2, h_, iEvent, name_, prof, type_, w_, x_, and y_.

Referenced by SplittingConfigurableHisto::fill().

166  {
167  if (!h_)
168  return;
169 
170  double weight = 1.0;
171  if (w_) {
172  if (w_->compute(iEvent))
173  weight = (*w_)(iEvent);
174  else {
175  edm::LogInfo("ConfigurableHisto") << "could not compute the weight for: " << name_ << " with config:\n"
176  << conf_.dump() << " default to 1.0";
177  }
178  }
179 
180  TProfile* pcast(nullptr);
181  TH2* h2cast(nullptr);
182  switch (type_) {
183  case h1:
184  if (!h_)
185  throw;
186  if (x_->compute(iEvent))
187  h_->Fill((*x_)(iEvent), weight);
188  else {
189  edm::LogInfo("ConfigurableHisto") << "could not fill: " << name_ << " with config:\n" << conf_.dump();
190  }
191  break;
192  case prof:
193  pcast = dynamic_cast<TProfile*>(h_);
194  if (!pcast)
195  throw;
196  if (x_->compute(iEvent) && y_->compute(iEvent))
197  pcast->Fill((*x_)(iEvent), (*y_)(iEvent), weight);
198  else {
199  edm::LogInfo("ConfigurableHisto") << "could not fill: " << name_ << " with config:\n" << conf_.dump();
200  }
201  break;
202  case h2:
203  h2cast = dynamic_cast<TH2*>(h_);
204  if (!h2cast)
205  throw;
206  if (x_->compute(iEvent) && y_->compute(iEvent))
207  h2cast->Fill((*x_)(iEvent), (*y_)(iEvent), weight);
208  else {
209  edm::LogInfo("ConfigurableHisto") << "could not fill: " << name_ << " with config:\n" << conf_.dump();
210  }
211  break;
212  }
213  }
Definition: weight.py:1
const CachingVariable * y_
int iEvent
Definition: GenABIO.cc:224
const CachingVariable * x_
Log< level::Info, false > LogInfo
const CachingVariable * w_
std::string dump(unsigned int indent=0) const
bool compute(const edm::Event &iEvent) const
edm::ParameterSet conf_

◆ h()

TH1* ConfigurableHisto::h ( )
inline

Definition at line 217 of file ConfigurableHisto.h.

References h_.

Referenced by SplittingConfigurableHisto::book(), and SplittingConfigurableHisto::complete().

217 { return h_; }

◆ type()

const HType& ConfigurableHisto::type ( )
inline

Definition at line 214 of file ConfigurableHisto.h.

References type_.

Referenced by book().

214 { return type_; }

Member Data Documentation

◆ conf_

edm::ParameterSet ConfigurableHisto::conf_
protected

Definition at line 233 of file ConfigurableHisto.h.

Referenced by book(), ConfigurableHisto(), and fill().

◆ h_

TH1* ConfigurableHisto::h_
protected

Definition at line 231 of file ConfigurableHisto.h.

Referenced by book(), ConfigurableHisto(), fill(), and h().

◆ name_

std::string ConfigurableHisto::name_
protected

◆ type_

HType ConfigurableHisto::type_
protected

◆ w_

const CachingVariable* ConfigurableHisto::w_
protected

Definition at line 238 of file ConfigurableHisto.h.

Referenced by book(), ConfigurableHisto(), and fill().

◆ x_

const CachingVariable* ConfigurableHisto::x_
protected

Definition at line 235 of file ConfigurableHisto.h.

Referenced by book(), ConfigurableHisto(), and fill().

◆ y_

const CachingVariable* ConfigurableHisto::y_
protected

Definition at line 236 of file ConfigurableHisto.h.

Referenced by book(), ConfigurableHisto(), and fill().

◆ z_

const CachingVariable* ConfigurableHisto::z_
protected

Definition at line 237 of file ConfigurableHisto.h.

Referenced by ConfigurableHisto().