CMS 3D CMS Logo

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

#include <ConfigurableHisto.h>

Inheritance diagram for SplittingConfigurableHisto:
ConfigurableHisto

Public Member Functions

void book (TFileDirectory *dir) override
 
ConfigurableHistoclone () const override
 
void complete ()
 
void fill (const edm::Event &e) override
 
 SplittingConfigurableHisto (HType t, std::string name, edm::ParameterSet &pset)
 
- Public Member Functions inherited from ConfigurableHisto
void complete ()
 
 ConfigurableHisto (HType t, std::string name, edm::ParameterSet &iConfig)
 
TH1 * h ()
 
const HTypetype ()
 
virtual ~ConfigurableHisto ()
 

Private Types

typedef std::map< const Splitter *, std::vector< ConfigurableHisto * > > SubHistoMap
 
typedef std::map< const Splitter *, THStack * > SubHistoStacks
 

Private Member Functions

 SplittingConfigurableHisto (const SplittingConfigurableHisto &master)
 

Private Attributes

const Splittersplitter_
 
THStack * stack_
 
SubHistoMap subHistoMap_
 
std::vector< ConfigurableHisto * > subHistos_
 
SubHistoStacks subHistoStacks_
 

Additional Inherited Members

- Public Types inherited from ConfigurableHisto
enum  HType { h1, h2, prof }
 
- Protected Member Functions inherited from ConfigurableHisto
 ConfigurableHisto (const ConfigurableHisto &master)
 
- Protected Attributes inherited from ConfigurableHisto
edm::ParameterSet conf_
 
TH1 * h_
 
std::string name_
 
HType type_
 
const CachingVariablew_
 
const CachingVariablex_
 
const CachingVariabley_
 
const CachingVariablez_
 

Detailed Description

Definition at line 241 of file ConfigurableHisto.h.

Member Typedef Documentation

typedef std::map<const Splitter*, std::vector<ConfigurableHisto*> > SplittingConfigurableHisto::SubHistoMap
private

Definition at line 410 of file ConfigurableHisto.h.

typedef std::map<const Splitter*, THStack*> SplittingConfigurableHisto::SubHistoStacks
private

Definition at line 411 of file ConfigurableHisto.h.

Constructor & Destructor Documentation

SplittingConfigurableHisto::SplittingConfigurableHisto ( HType  t,
std::string  name,
edm::ParameterSet pset 
)
inline

Definition at line 243 of file ConfigurableHisto.h.

References MillePedeFileConverter_cfg::e, edm::ParameterSet::exists(), edm::ParameterSet::getParameter(), mps_fire::i, edm::ParameterSet::insert(), label, Splitter::label(), Splitter::maxSlots(), CachingVariable::name(), muonDTDigis_cfi::pset, alignCSCRings::s, Splitter::shortLabel(), confdb::splitter(), AlCaHLTBitMon_QueryRunRegistry::string, overlapproblemtsosanalyzer_cfi::title, and findQualityFiles::v.

244  : ConfigurableHisto(t, name, pset), splitter_(nullptr) {
245  std::string title = pset.getParameter<std::string>("title");
246 
247  //allow for many splitters ...
248  if (pset.exists("splitters")) {
249  //you want more than one splitter
250  std::vector<std::string> splitters = pset.getParameter<std::vector<std::string> >("splitters");
251  for (unsigned int s = 0; s != splitters.size(); ++s) {
252  const CachingVariable* v = edm::Service<VariableHelperService>()->get().variable(splitters[s]);
253  const Splitter* splitter = dynamic_cast<const Splitter*>(v);
254  if (!splitter) {
255  edm::LogError("SplittingConfigurableHisto")
256  << "for: " << name_ << " the splitting variable: " << splitters[s] << " is not a Splitter";
257  continue;
258  }
259 
260  //insert in the map
261  std::vector<ConfigurableHisto*>& insertedHisto = subHistoMap_[splitter];
262  //now configure the histograms
263  unsigned int mSlots = splitter->maxSlots();
264  for (unsigned int i = 0; i != mSlots; ++i) {
265  //--- std::cout<<" slot: "<<i<<std::endl;
266  const std::string& slabel = splitter->shortLabel(i);
267  const std::string& label = splitter->label(i);
268  edm::ParameterSet mPset = pset;
269  edm::Entry e("string", title + " for " + label, true);
270  mPset.insert(true, "title", e);
271  insertedHisto.push_back(new ConfigurableHisto(t, name + slabel, mPset));
272  } //loop on slots
273  } //loop on splitters
274 
275  } //if splitters exists
276  else {
277  //single splitter
278  //get the splitting variable
279  const CachingVariable* v =
280  edm::Service<VariableHelperService>()->get().variable(pset.getParameter<std::string>("splitter"));
281  splitter_ = dynamic_cast<const Splitter*>(v);
282  if (!splitter_) {
283  edm::LogError("SplittingConfigurableHisto")
284  << "for: " << name_ << " the splitting variable: " << v->name() << " is not a Splitter";
285  } else {
286  //configure the splitted plots
287  unsigned int mSlots = splitter_->maxSlots();
288  for (unsigned int i = 0; i != mSlots; i++) {
289  const std::string& slabel = splitter_->shortLabel(i);
290  const std::string& label = splitter_->label(i);
291  edm::ParameterSet mPset = pset;
292  edm::Entry e("string", title + " for " + label, true);
293  mPset.insert(true, "title", e);
294  subHistos_.push_back(new ConfigurableHisto(t, name + slabel, mPset));
295  }
296  }
297  }
298  } //end of ctor
T getParameter(std::string const &) const
def splitter(iterator, n)
Definition: confdb.py:13
bool exists(std::string const &parameterName) const
checks if a parameter exists
void insert(bool ok_to_replace, char const *, Entry const &)
std::vector< ConfigurableHisto * > subHistos_
char const * label
ConfigurableHisto(HType t, std::string name, edm::ParameterSet &iConfig)
const std::string shortLabel(unsigned int i) const
virtual unsigned int maxSlots() const
const std::string & label(unsigned int i) const
const std::string & name() const
SplittingConfigurableHisto::SplittingConfigurableHisto ( const SplittingConfigurableHisto master)
inlineprivate

Definition at line 391 of file ConfigurableHisto.h.

References clone(), mps_fire::i, splitter_, subHistoMap_, and subHistos_.

391  : ConfigurableHisto(master) {
392  splitter_ = master.splitter_;
393  if (!master.subHistoMap_.empty()) {
394  SubHistoMap::const_iterator i = master.subHistoMap_.begin();
395  SubHistoMap::const_iterator i_end = master.subHistoMap_.end();
396  for (; i != i_end; ++i) {
397  const std::vector<ConfigurableHisto*>& masterHistos = i->second;
398  std::vector<ConfigurableHisto*>& clonedHistos = subHistoMap_[i->first];
399  for (unsigned int i = 0; i != masterHistos.size(); i++) {
400  clonedHistos.push_back(masterHistos[i]->clone());
401  }
402  }
403  } else {
404  for (unsigned int i = 0; i != master.subHistos_.size(); i++) {
405  subHistos_.push_back(master.subHistos_[i]->clone());
406  }
407  }
408  }
std::vector< ConfigurableHisto * > subHistos_
ConfigurableHisto(HType t, std::string name, edm::ParameterSet &iConfig)
ConfigurableHisto * clone() const override

Member Function Documentation

void SplittingConfigurableHisto::book ( TFileDirectory dir)
inlineoverridevirtual

Reimplemented from ConfigurableHisto.

Definition at line 300 of file ConfigurableHisto.h.

References ConfigurableHisto::book(), h, mps_fire::i, TFileDirectory::make(), and AlCaHLTBitMon_QueryRunRegistry::string.

300  {
301  //book the base histogram
303 
304  if (!subHistoMap_.empty()) {
305  SubHistoMap::iterator i = subHistoMap_.begin();
306  SubHistoMap::iterator i_end = subHistoMap_.end();
307  for (; i != i_end; ++i) {
308  for (unsigned int h = 0; h != i->second.size(); ++h) {
309  i->second[h]->book(dir);
310  }
311  //book the THStack
312  std::string sName = name_ + "_" + i->first->name();
313  std::string sTitle = "Stack histogram of " + name_ + " for splitter " + i->first->name();
314  subHistoStacks_[i->first] = dir->make<THStack>(sName.c_str(), sTitle.c_str());
315  }
316  } else {
317  for (unsigned int h = 0; h != subHistos_.size(); h++) {
318  subHistos_[h]->book(dir);
319  }
320  //book a THStack
321  std::string sName = name_ + "_" + splitter_->name();
322  std::string sTitle = "Stack histogram of " + name_ + " for splitter " + splitter_->name();
323  stack_ = dir->make<THStack>(sName.c_str(), sTitle.c_str());
324  }
325  }
std::vector< ConfigurableHisto * > subHistos_
T * make(const Args &...args) const
make new ROOT object
virtual void book(TFileDirectory *dir)
const std::string & name() const
ConfigurableHisto* SplittingConfigurableHisto::clone ( void  ) const
inlineoverridevirtual

Reimplemented from ConfigurableHisto.

Definition at line 327 of file ConfigurableHisto.h.

327 { return new SplittingConfigurableHisto(*this); }
SplittingConfigurableHisto(HType t, std::string name, edm::ParameterSet &pset)
void SplittingConfigurableHisto::complete ( )
inline

Definition at line 370 of file ConfigurableHisto.h.

References h, and mps_fire::i.

370  {
371  if (!subHistoMap_.empty()) {
372  //fill up the stacks
373  SubHistoMap::iterator i = subHistoMap_.begin();
374  SubHistoMap::iterator i_end = subHistoMap_.end();
375  for (; i != i_end; ++i) {
376  for (unsigned int h = 0; h != i->second.size(); h++) {
377  // if (i->second[h]->h()->Integral==0) continue;// do not add empty histograms. NO, because it will be tough to merge two THStack
378  subHistoStacks_[i->first]->Add(i->second[h]->h(), i->first->label(h).c_str());
379  }
380  }
381 
382  } else {
383  //fill up the only stack
384  for (unsigned int i = 0; i != subHistos_.size(); i++) {
385  stack_->Add(subHistos_[i]->h(), splitter_->label(i).c_str());
386  }
387  }
388  }
std::vector< ConfigurableHisto * > subHistos_
const std::string & label(unsigned int i) const
void SplittingConfigurableHisto::fill ( const edm::Event e)
inlineoverridevirtual

Reimplemented from ConfigurableHisto.

Definition at line 329 of file ConfigurableHisto.h.

References CachingVariable::compute(), MillePedeFileConverter_cfg::e, ConfigurableHisto::fill(), mps_fire::i, and createfilelist::int.

329  {
330  //fill the base histogram
332 
333  if (!subHistoMap_.empty()) {
334  SubHistoMap::iterator i = subHistoMap_.begin();
335  SubHistoMap::iterator i_end = subHistoMap_.end();
336  for (; i != i_end; ++i) {
337  const Splitter* splitter = i->first;
338  if (!splitter)
339  continue;
340  if (!splitter->compute(e))
341  continue;
342  unsigned int slot = (unsigned int)(*splitter)(e);
343  if (slot >= i->second.size()) {
344  edm::LogError("SplittingConfigurableHisto")
345  << "slot index: " << slot << " is bigger than slots size: " << i->second.size()
346  << " from variable value: " << (*splitter)(e);
347  continue;
348  }
349  //fill in the proper slot
350  i->second[slot]->fill(e);
351  }
352  } else {
353  //fill the component histograms
354  if (!splitter_)
355  return;
356  if (!splitter_->compute(e)) {
357  return;
358  }
359  unsigned int slot = (unsigned int)(*splitter_)(e);
360  if (slot >= subHistos_.size()) {
361  edm::LogError("SplittingConfigurableHisto")
362  << "slot index: " << slot << " is bigger than slots size: " << subHistos_.size()
363  << " from variable value: " << (*splitter_)(e);
364  return;
365  }
366  subHistos_[slot]->fill(e);
367  }
368  }
std::vector< ConfigurableHisto * > subHistos_
virtual void fill(const edm::Event &iEvent)
bool compute(const edm::Event &iEvent) const

Member Data Documentation

const Splitter* SplittingConfigurableHisto::splitter_
private

Definition at line 415 of file ConfigurableHisto.h.

Referenced by SplittingConfigurableHisto().

THStack* SplittingConfigurableHisto::stack_
private

Definition at line 418 of file ConfigurableHisto.h.

SubHistoMap SplittingConfigurableHisto::subHistoMap_
private

Definition at line 413 of file ConfigurableHisto.h.

Referenced by SplittingConfigurableHisto().

std::vector<ConfigurableHisto*> SplittingConfigurableHisto::subHistos_
private

Definition at line 416 of file ConfigurableHisto.h.

Referenced by SplittingConfigurableHisto().

SubHistoStacks SplittingConfigurableHisto::subHistoStacks_
private

Definition at line 412 of file ConfigurableHisto.h.