9 #include <boost/algorithm/string.hpp>
22 geometryInterface(geo),
23 enabled(iconfig.getParameter<bool>(
"enabled")),
24 perLumiHarvesting(iconfig.getParameter<bool>(
"perLumiHarvesting")),
25 bookUndefined(iconfig.getParameter<bool>(
"bookUndefined")),
26 top_folder_name(iconfig.getParameter<std::
string>(
"topFolderName")),
27 name(iconfig.getParameter<std::
string>(
"name")),
30 ylabel(iconfig.getParameter<std::
string>(
"ylabel")),
31 dimensions(iconfig.getParameter<int>(
"dimensions")),
32 range_x_nbins(iconfig.getParameter<int>(
"range_nbins")),
33 range_x_min(iconfig.getParameter<double>(
"range_min")),
34 range_x_max(iconfig.getParameter<double>(
"range_max")),
35 range_y_nbins(iconfig.getParameter<int>(
"range_y_nbins")),
36 range_y_min(iconfig.getParameter<double>(
"range_y_min")),
37 range_y_max(iconfig.getParameter<double>(
"range_y_max")) {
39 for (
auto spec : spec_configs) {
43 if (!conf.getParameter<
bool>(
"enabled"))
continue;
49 specs.push_back(spec);
71 if (col != this->
iq.
col || row != this->iq.row ||
72 sourceModule != this->iq.sourceModule ||
73 sourceEvent != this->iq.sourceEvent ||
74 sourceModule == 0xFFFFFFFF ||
75 sourceModule ==
DetId(0)
80 int16_t(col), int16_t(row)};
82 for (
unsigned int i = 0;
i <
specs.size();
i++) {
98 <<
"name " <<
tables[
i].begin()->second.th1->GetName() <<
"\n";
99 assert(!
"Histogram not booked! Probably inconsistent geometry description.");
115 fill(x, 0.0, sourceModule, sourceEvent, col, row);
120 fill(0.0, 0.0, sourceModule, sourceEvent, col, row);
125 std::vector<SummationStep>::iterator
first,
126 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) {
138 if (it->arg[0] ==
'1' && n_parameters >= 1) fx =
x;
139 if (it->arg[0] ==
'2' && n_parameters >= 2) fx =
y;
142 if (it->arg[0] ==
'1' && n_parameters >= 1) fy =
x;
143 if (it->arg[0] ==
'2' && n_parameters >= 2) fy =
y;
146 if (it->arg[0] ==
'1' && n_parameters >= 1) fz =
x;
147 if (it->arg[0] ==
'2' && n_parameters >= 2) fz =
y;
160 assert(!
"illegal step in STAGE1!");
164 switch(tot_parameters) {
172 dest.
me->
Fill(fx, fy, fz);
175 edm::LogError(
"HistogramManager") <<
"got " << tot_parameters <<
" dimensions\n"
176 <<
"name " << dest.
th1->GetName() <<
"\n";
177 assert(!
"More than 3 dimensions should never occur.");
186 for (
unsigned int i = 0;
i <
specs.size();
i++) {
192 || !
"Incomplete spec (but this cannot be caught in Python)");
198 auto iq =
e.second.iq_sample;
209 <<
"name " <<
t.begin()->second.th1->GetName() <<
"\n"
211 assert(!
"Histogram not booked! (per-event) Probably inconsistent geometry description.");
224 std::ostringstream
dir(
"");
225 for (
auto e : significantvalues.
values) {
228 if (
e.second == 0) value =
"";
229 if (name ==
"")
continue;
230 if (name ==
"PXDisk" &&
e.second > 0)
231 value =
"_+" + std::to_string(
e.second);
233 std::map<int, std::string> shellname{
234 {11,
"_mI"}, {12,
"_mO"}, {21,
"_pI"}, {22,
"_pO"}};
235 if (name ==
"HalfCylinder" || name ==
"Shell") value = shellname[
e.second];
238 dir << name << value <<
"/";
250 name =
"num_" +
name;
257 name = name +
"_per_" + colname;
283 double range_z_min = 1e12;
284 double range_z_max = -1e12;
287 int range_z_nbins = 0;
289 bool do_profile =
false;
291 std::map<GeometryInterface::Values, MEInfo> toBeBooked;
293 for (
unsigned int i = 0;
i <
specs.size();
i++) {
298 bool bookCounters =
false;
300 auto firststep =
s.steps.begin();
323 for (
auto e : significantvalues.
values)
328 auto histo = toBeBooked.find(significantvalues);
329 if (
histo == toBeBooked.end()) {
333 mei.title = this->
title;
335 mei.title =
"Number of " + mei.title +
" per Event and "
341 int tot_parameters = n_parameters;
342 #define SET_AXIS(to, from) \
343 mei.to##label = from##label; \
344 mei.range_##to##_min = this->range_##from##_min; \
345 mei.range_##to##_max = this->range_##from##_max; \
346 mei.range_##to##_nbins = this->range_##from##_nbins
347 for (
auto it = firststep+1; it !=
s.steps.end(); ++it) {
351 if (it->arg[0] ==
'1' && n_parameters >= 1) {
SET_AXIS(
x,
x); }
352 if (it->arg[0] ==
'2' && n_parameters >= 2) {
SET_AXIS(
x,
y); }
355 if (it->arg[0] ==
'1' && n_parameters >= 1) {
SET_AXIS(
y,
x); }
356 if (it->arg[0] ==
'2' && n_parameters >= 2) {
SET_AXIS(
y,
y); }
359 if (it->arg[0] ==
'1' && n_parameters >= 1) {
SET_AXIS(
z,
x); }
360 if (it->arg[0] ==
'2' && n_parameters >= 2) {
SET_AXIS(
z,
y); }
363 assert(mei.range_x_nbins == 0);
366 mei.title = mei.title +
" by " + mei.xlabel;
376 mei.title = mei.title +
" by " + mei.ylabel;
384 mei.do_profile =
true;
387 assert(!
"illegal step in STAGE1! (booking)");
390 mei.dimensions = tot_parameters;
391 if (mei.do_profile) mei.title =
"Profile of " + mei.title;
392 if (mei.zlabel.size() > 0) mei.title = mei.title +
" (Z: " + mei.zlabel +
")";
398 for (
auto it = firststep+1; it !=
s.steps.end(); ++it) {
404 mei.range_x_min =
std::min(mei.range_x_min, val);
405 mei.range_x_max =
std::max(mei.range_x_max, val);
410 mei.range_y_min =
std::min(mei.range_y_min, val);
411 mei.range_y_max =
std::max(mei.range_y_max, val);
420 for (
auto&
e : toBeBooked) {
423 MEInfo& mei =
e.second;
427 if (mei.range_x_nbins == 0) {
428 mei.range_x_min -= 0.5;
429 mei.range_x_max += 0.5;
430 mei.range_x_nbins = int(mei.range_x_max - mei.range_x_min);
432 if (mei.range_y_nbins == 0) {
433 mei.range_y_min -= 0.5;
434 mei.range_y_max += 0.5;
435 mei.range_y_nbins = int(mei.range_y_max - mei.range_y_min);
438 if (mei.dimensions == 1) {
439 h.
me = iBooker.
book1D(mei.name, (mei.title +
";" + mei.xlabel).c_str(),
440 mei.range_x_nbins, mei.range_x_min, mei.range_x_max);
441 }
else if (mei.dimensions == 2 && !mei.do_profile) {
442 h.
me = iBooker.
book2D(mei.name, (mei.title +
";" + mei.xlabel +
";" + mei.ylabel).c_str(),
443 mei.range_x_nbins, mei.range_x_min, mei.range_x_max,
444 mei.range_y_nbins, mei.range_y_min, mei.range_y_max);
445 }
else if (mei.dimensions == 2 && mei.do_profile) {
446 h.
me = iBooker.
bookProfile(mei.name, (mei.title +
";" + mei.xlabel +
";" + mei.ylabel).c_str(),
447 mei.range_x_nbins, mei.range_x_min, mei.range_x_max, 0.0, 0.0);
448 }
else if (mei.dimensions == 3 && mei.do_profile) {
449 h.
me = iBooker.
bookProfile2D(mei.name, (mei.title +
";" + mei.xlabel +
";" + mei.ylabel).c_str(),
450 mei.range_x_nbins, mei.range_x_min, mei.range_x_max,
451 mei.range_y_nbins, mei.range_y_min, mei.range_y_max,
455 <<
"name " << mei.name <<
"\n"
456 <<
"dim " << mei.dimensions <<
" profile " << mei.do_profile <<
"\n";
457 assert(!
"Illegal Histogram kind.");
487 auto firststep = s.
steps.begin();
495 auto histo = t.find(significantvalues);
496 if (
histo == t.end()) {
502 edm::LogError(
"HistogramManager") <<
"ME " << path <<
" not found\n";
519 TH1* th1 =
e.second.th1;
525 if (dynamic_cast<TH1F*>(th1)) new_histo.
me = iBooker.
book1D(th1->GetName(), (TH1F*) th1);
526 else if (dynamic_cast<TH2F*>(th1)) new_histo.
me = iBooker.
book2D(th1->GetName(), (TH2F*) th1);
527 else if (dynamic_cast<TProfile*>(th1)) new_histo.
me = iBooker.
bookProfile(th1->GetName(), (TProfile*) th1);
528 else if (dynamic_cast<TProfile2D*>(th1)) new_histo.
me = iBooker.
bookProfile2D(th1->GetName(), (TProfile2D*) th1);
529 else assert(!
"No idea how to book this.");
533 new_histo.
th1->Add(th1);
542 std::map<GeometryInterface::Values, int>
nbins;
548 std::map<GeometryInterface::Values, std::string> separators;
556 assert(
e.second.th1 || !
"invalid histogram");
558 int bins = reduce_type !=
"" ? 1 :
e.second.th1->GetXaxis()->GetNbins();
562 for (
auto&
e : separators)
e.second =
"(" +
e.second +
")/";
568 TH1* th1 =
e.second.th1;
577 new_histo =
e.second;
584 auto red = reduce_type;
585 boost::algorithm::to_lower(
red);
587 auto title = eps + th1->GetTitle() +
" per " + colname +
";" +
588 colname + separator +
589 (
red !=
"" ? th1->GetYaxis()->GetTitle() : th1->GetXaxis()->GetTitle()) +
";" +
590 (
red !=
"" ?
red +
" of " + th1->GetXaxis()->GetTitle() : th1->GetYaxis()->GetTitle());
593 if (th1->GetDimension() == 1) {
595 nbins[significantvalues], 0.5, nbins[significantvalues] + 0.5);
597 assert(!
"2D extend not implemented in harvesting.");
606 if (new_histo.
th1->GetDimension() == 1) {
607 if (reduce_type ==
"") {
608 for (
int i = 1;
i <= th1->GetXaxis()->GetNbins();
i++) {
609 new_histo.
th1->SetBinContent(new_histo.
count, th1->GetBinContent(
i));
610 new_histo.
th1->SetBinError(new_histo.
count, th1->GetBinError(
i));
611 new_histo.
count += 1;
613 }
else if (reduce_type ==
"MEAN") {
614 new_histo.
th1->SetBinContent(new_histo.
count, th1->GetMean());
615 new_histo.
th1->SetBinError(new_histo.
count, th1->GetMeanError());
616 new_histo.
count += 1;
618 assert(!
"Reduction type not supported");
621 assert(!
"2D extend not implemented in harvesting.");
633 log <<
"Specs for " <<
name <<
" ";
637 for (
unsigned int i = 0;
i < specs.size();
i++) {
656 reduce_type = step.
arg;
663 assert(!
"EXTEND_Y currently not supported in harvesting.");
669 assert(!
"Operation not supported in harvesting.");
void executeHarvesting(DQMStore::IBooker &iBooker, DQMStore::IGetter &iGetter)
T getParameter(std::string const &) const
GeometryInterface::InterestingQuantities iq_sample
void addSpec(SummationSpecification spec)
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
MonitorElement * bookProfile(Args &&...args)
std::vector< GeometryInterface::Column > columns
void executePerLumiHarvesting(DQMStore::IBooker &iBooker, DQMStore::IGetter &iGetter, edm::LuminosityBlock const &lumiBlock, edm::EventSetup const &iSetup)
MonitorElement * get(const std::string &path)
std::vector< ParameterSet > VParameterSet
void executeExtend(SummationStep &step, Table &t, std::string const &reduction, DQMStore::IBooker &iBooker)
std::string pretty(Column col)
std::vector< SummationSpecification > specs
std::vector< SummationStep > steps
std::string top_folder_name
void fill(DetId sourceModule, const edm::Event *sourceEvent=0, int col=0, int row=0)
std::vector< std::pair< Column, Value > > values
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)
T x() const
Cartesian x coordinate.
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 * bookProfile2D(Args &&...args)
void executeGroupBy(SummationStep &step, Table &t, DQMStore::IBooker &iBooker)
MonitorElement * book1D(Args &&...args)
std::string makeName(SummationSpecification const &s, GeometryInterface::InterestingQuantities const &iq)
static const Value UNDEFINED
std::array< ID, 2 > Column
std::vector< AbstractHistogram * > fastpath
void setCurrentFolder(const std::string &fullpath)
std::vector< GeometryInterface::Values > significantvalues
MonitorElement * book2D(Args &&...args)
std::map< GeometryInterface::Values, AbstractHistogram > Table
std::function< void(SummationStep &step, Table &t, DQMStore::IBooker &iBooker, DQMStore::IGetter &iGetter)> customHandler
HistogramManager(const edm::ParameterSet &iConfig, GeometryInterface &geo)
std::vector< Table > tables
edm::LuminosityBlock const * lumisection
std::pair< Column, Value > extract(Column const &col, InterestingQuantities const &iq)
std::vector< Table > counters
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
std::string makePath(GeometryInterface::Values const &)
#define SET_AXIS(to, from)
GeometryInterface & geometryInterface