9 #include <boost/algorithm/string.hpp> 21 geometryInterface(geo),
25 top_folder_name(iconfig.getParameter<
std::
string>(
"topFolderName")),
31 range_x_nbins(iconfig.getParameter<
int>(
"range_nbins")),
32 range_x_min(iconfig.getParameter<double>(
"range_min")),
33 range_x_max(iconfig.getParameter<double>(
"range_max")),
35 range_y_min(iconfig.getParameter<double>(
"range_y_min")),
36 range_y_max(iconfig.getParameter<double>(
"range_y_max")) {
38 for (
auto spec : spec_configs) {
42 if (!conf.getParameter<
bool>(
"enabled"))
49 specs.push_back(spec);
80 if (sourceModule == this->
iq.
sourceModule && sourceEvent == this->iq.sourceEvent) {
84 for (
unsigned int i = 0;
i <
specs.size();
i++) {
94 <<
"name " <<
tables[
i].begin()->second.th1->GetName() <<
"\n";
95 assert(!
"Histogram not booked! Probably inconsistent geometry description.");
115 fill(x, 0.0, sourceModule, sourceEvent, col, row);
119 fill(0.0, 0.0, sourceModule, sourceEvent, col, row);
126 std::vector<SummationStep>::iterator
first,
127 std::vector<SummationStep>::iterator
last,
129 double fx = 0,
fy = 0, fz = 0;
130 int tot_parameters = n_parameters;
131 for (
auto it = first; it !=
last; ++it) {
139 if (it->arg[0] ==
'1' && n_parameters >= 1)
141 if (it->arg[0] ==
'2' && n_parameters >= 2)
145 if (it->arg[0] ==
'1' && n_parameters >= 1)
147 if (it->arg[0] ==
'2' && n_parameters >= 2)
151 if (it->arg[0] ==
'1' && n_parameters >= 1)
153 if (it->arg[0] ==
'2' && n_parameters >= 2)
167 assert(!
"illegal step in STAGE1!");
171 switch (tot_parameters) {
182 edm::LogError(
"HistogramManager") <<
"got " << tot_parameters <<
" dimensions\n" 183 <<
"name " << dest.
th1->GetName() <<
"\n";
184 assert(!
"More than 3 dimensions should never occur.");
193 for (
unsigned int i = 0;
i <
specs.size();
i++) {
200 !
"Incomplete spec (but this cannot be caught in Python)");
206 auto iq =
e.second.iq_sample;
216 <<
"name " <<
t.begin()->second.th1->GetName() <<
"\n" 219 assert(!
"Histogram not booked! (per-event) Probably inconsistent geometry description.");
230 std::ostringstream
dir(
"");
234 if (!significantvalues.empty()) {
235 for (
auto it = significantvalues.begin(); it != (significantvalues.end() - 1); ++it) {
241 auto e = significantvalues[significantvalues.size() - 1];
252 name =
"num_" +
name;
260 name = name +
"_per_" + colname;
265 boost::algorithm::to_lower(
red);
290 double range_z_min = 1e12;
291 double range_z_max = -1e12;
294 int range_z_nbins = 0;
298 bool do_profile =
false;
300 std::map<GeometryInterface::Values, MEInfo> toBeBooked;
302 for (
unsigned int i = 0;
i <
specs.size();
i++) {
307 bool bookCounters =
false;
309 auto firststep =
s.steps.begin();
318 auto laststep = std::find_if(
334 for (
auto e : significantvalues)
341 auto histo = toBeBooked.find(significantvalues);
342 if (
histo == toBeBooked.end()) {
345 mei.title = this->
title;
353 int tot_parameters = n_parameters;
355 #define SET_AXIS(to, from) \ 356 mei.to##label = from##label; \ 357 mei.range_##to##_min = ((it->nbins == -1) ? this->range_##from##_min : it->xmin); \ 358 mei.range_##to##_max = ((it->nbins == -1) ? this->range_##from##_max : it->xmax); \ 359 mei.range_##to##_nbins = ((it->nbins == -1) ? this->range_##from##_nbins : it->nbins) 361 for (
auto it = firststep + 1; it != laststep; ++it) {
364 if (it->arg[0] ==
'1' && n_parameters >= 1) {
367 if (it->arg[0] ==
'2' && n_parameters >= 2) {
372 if (it->arg[0] ==
'1' && n_parameters >= 1) {
375 if (it->arg[0] ==
'2' && n_parameters >= 2) {
380 if (it->arg[0] ==
'1' && n_parameters >= 1) {
383 if (it->arg[0] ==
'2' && n_parameters >= 2) {
388 assert(mei.range_x_nbins == 0);
389 auto col = it->columns[0];
391 mei.title = mei.title +
" by " + mei.xlabel;
400 auto col = it->columns[0];
402 mei.title = mei.title +
" by " + mei.ylabel;
411 mei.do_profile =
true;
414 assert(!
"illegal step in STAGE1! (booking)");
417 mei.dimensions = tot_parameters;
419 mei.title =
"Profile of " + mei.title;
420 if (!mei.zlabel.empty())
421 mei.title = mei.title +
" (Z: " + mei.zlabel +
")";
427 for (
auto it = firststep + 1; it != laststep; ++it) {
433 mei.range_x_min =
std::min(mei.range_x_min, val);
434 mei.range_x_max =
std::max(mei.range_x_max, val);
440 mei.range_y_min =
std::min(mei.range_y_min, val);
441 mei.range_y_max =
std::max(mei.range_y_max, val);
450 for (
auto&
e : toBeBooked) {
452 MEInfo& mei =
e.second;
460 if (mei.binwidth_x != 0) {
461 double range = (mei.range_x_max - mei.range_x_min) / mei.binwidth_x;
462 if ((range -
int(range)) == 0.0) {
463 mei.range_x_min -= mei.binwidth_x / 2;
464 mei.range_x_max += mei.binwidth_x / 2;
466 mei.range_x_min = std::floor(mei.range_x_min / mei.binwidth_x) * mei.binwidth_x;
467 mei.range_x_max =
std::ceil(mei.range_x_max / mei.binwidth_x) * mei.binwidth_x;
469 mei.range_x_nbins =
int((mei.range_x_max - mei.range_x_min) / mei.binwidth_x);
471 if (mei.binwidth_y != 0) {
472 double range = (mei.range_y_max - mei.range_y_min) / mei.binwidth_y;
473 if ((range -
int(range)) == 0.0) {
474 mei.range_y_min -= mei.binwidth_y / 2;
475 mei.range_y_max += mei.binwidth_y / 2;
477 mei.range_y_min = std::floor(mei.range_y_min / mei.binwidth_y) * mei.binwidth_y;
478 mei.range_y_max =
std::ceil(mei.range_y_max / mei.binwidth_y) * mei.binwidth_y;
480 mei.range_y_nbins =
int((mei.range_y_max - mei.range_y_min) / mei.binwidth_y);
483 if (mei.dimensions == 1) {
485 name.second, (mei.title +
";" + mei.xlabel).c_str(), mei.range_x_nbins, mei.range_x_min, mei.range_x_max);
486 }
else if (mei.dimensions == 2 && !mei.do_profile) {
488 (mei.title +
";" + mei.xlabel +
";" + mei.ylabel).c_str(),
495 }
else if (mei.dimensions == 2 && mei.do_profile) {
497 (mei.title +
";" + mei.xlabel +
";" + mei.ylabel).c_str(),
504 }
else if (mei.dimensions == 3 && mei.do_profile) {
506 (mei.title +
";" + mei.xlabel +
";" + mei.ylabel).c_str(),
517 <<
"name " <<
name.second <<
"\n" 518 <<
"dim " << mei.dimensions <<
" profile " << mei.do_profile <<
"\n";
519 assert(!
"Illegal Histogram kind.");
547 auto firststep = s.
steps.begin();
550 auto laststep = std::find_if(
556 auto histo = t.find(significantvalues);
557 if (
histo == t.end()) {
563 edm::LogError(
"HistogramManager") <<
"ME " << path <<
" not found\n";
583 TH1* th1 =
e.second.th1;
589 if (dynamic_cast<TH1F*>(th1))
591 else if (dynamic_cast<TH2F*>(th1))
593 else if (dynamic_cast<TProfile*>(th1))
595 else if (dynamic_cast<TProfile2D*>(th1))
598 assert(!
"No idea how to book this.");
602 new_histo.
th1->Add(th1);
615 std::map<GeometryInterface::Values, int>
nbins;
621 std::map<GeometryInterface::Values, std::string> separators;
628 assert(
e.second.th1 || !
"invalid histogram");
630 int bins = !reduce_type.empty() ? 1 :
e.second.th1->GetXaxis()->GetNbins();
635 for (
auto&
e : separators)
636 e.second =
"(" +
e.second +
")/";
641 TH1* th1 =
e.second.th1;
654 (!reduce_type.empty() ? th1->GetYaxis()->GetTitle() : th1->GetXaxis()->GetTitle()) +
";" +
655 (!reduce_type.empty() ? reduce_type +
" of " + th1->GetXaxis()->GetTitle() : th1->GetYaxis()->GetTitle());
658 if (th1->GetDimension() == 1) {
660 iBooker.
book1D(
name.second,
title, nbins[significantvalues], 0.5, nbins[significantvalues] + 0.5);
662 assert(!
"2D extend not implemented in harvesting.");
671 if (new_histo.
th1->GetDimension() == 1) {
672 if (reduce_type.empty()) {
673 for (
int i = 1;
i <= th1->GetXaxis()->GetNbins();
i++) {
674 new_histo.
th1->SetBinContent(new_histo.
count, th1->GetBinContent(
i));
675 new_histo.
th1->SetBinError(new_histo.
count, th1->GetBinError(
i));
676 new_histo.
count += 1;
678 }
else if (reduce_type ==
"MEAN") {
679 new_histo.
th1->SetBinContent(new_histo.
count, th1->GetMean());
680 new_histo.
th1->SetBinError(new_histo.
count, th1->GetMeanError());
681 new_histo.
count += 1;
683 assert(!
"Reduction type not supported");
686 assert(!
"2D extend not implemented in harvesting.");
698 log <<
"Specs for " <<
name <<
" ";
702 for (
unsigned int i = 0;
i < specs.size();
i++) {
721 reduce_type = step.
arg;
728 assert(!
"EXTEND_Y currently not supported in harvesting.");
731 assert(!
"Operation not supported in harvesting.");
void executeHarvesting(DQMStore::IBooker &iBooker, DQMStore::IGetter &iGetter)
#define SET_AXIS(to, from)
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX)
T getParameter(std::string const &) const
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
GeometryInterface::InterestingQuantities iq_sample
void addSpec(SummationSpecification spec)
std::vector< GeometryInterface::Column > columns
void executePerLumiHarvesting(DQMStore::IBooker &iBooker, DQMStore::IGetter &iGetter, edm::LuminosityBlock const &lumiBlock, edm::EventSetup const &iSetup)
void setCurrentFolder(std::string const &fullpath)
std::vector< ParameterSet > VParameterSet
std::string pretty(Column col)
void executeGroupBy(SummationStep const &step, Table &t, DQMStore::IBooker &iBooker, SummationSpecification const &s)
std::string formatValue(Column, Value)
std::vector< SummationSpecification > specs
std::pair< std::string, std::string > makePathName(SummationSpecification const &s, GeometryInterface::Values const &, SummationStep const *upto)
std::vector< SummationStep > steps
constexpr int32_t ceil(float num)
std::string top_folder_name
void fill(DetId sourceModule, const edm::Event *sourceEvent=0, int col=0, int row=0)
void fillInternal(double x, double y, int n_parameters, GeometryInterface::InterestingQuantities const &iq, std::vector< SummationStep >::iterator first, std::vector< SummationStep >::iterator last, AbstractHistogram &dest)
void executeExtend(SummationStep const &step, Table &t, std::string const &reduction, DQMStore::IBooker &iBooker, SummationSpecification const &s)
void loadFromDQMStore(SummationSpecification &s, Table &t, DQMStore::IGetter &iGetter)
void load(edm::EventSetup const &iSetup)
void extractColumns(std::vector< Column > const &names, InterestingQuantities const &iq, Values &out)
MonitorElement * bookProfile(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, char const *option="s")
MonitorElement * bookProfile2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, double lowZ, double highZ, char const *option="s")
static const Value UNDEFINED
std::vector< std::pair< Column, Value > > Values
std::vector< AbstractHistogram * > fastpath
std::vector< GeometryInterface::Values > significantvalues
std::map< GeometryInterface::Values, AbstractHistogram > Table
HistogramManager(const edm::ParameterSet &iConfig, GeometryInterface &geo)
std::vector< Table > tables
edm::LuminosityBlock const * lumisection
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
std::pair< Column, Value > extract(Column const &col, InterestingQuantities const &iq)
std::vector< Table > counters
dqm::legacy::MonitorElement * me
std::vector< InterestingQuantities > const & allModules()
const edm::Event * sourceEvent
void executePerEventHarvesting(edm::Event const *ev)
void book(DQMStore::IBooker &iBooker, edm::EventSetup const &iSetup)
GeometryInterface::InterestingQuantities iq
MonitorElement * get(std::string const &path)
virtual TH1 * getTH1() const
GeometryInterface & geometryInterface