9 #include <boost/algorithm/string.hpp> 22 geometryInterface(geo),
24 perLumiHarvesting(iconfig.getParameter<
bool>(
"perLumiHarvesting")),
25 bookUndefined(iconfig.getParameter<
bool>(
"bookUndefined")),
26 top_folder_name(iconfig.getParameter<
std::
string>(
"topFolderName")),
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")),
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);
81 && sourceEvent == this->iq.sourceEvent) {
85 int16_t(col), int16_t(row)};
86 for (
unsigned int i = 0;
i <
specs.size();
i++) {
97 <<
"name " <<
tables[
i].begin()->second.th1->GetName() <<
"\n";
98 assert(!
"Histogram not booked! Probably inconsistent geometry description.");
119 fill(x, 0.0, sourceModule, sourceEvent, col, row);
124 fill(0.0, 0.0, sourceModule, sourceEvent, col, row);
129 std::vector<SummationStep>::iterator
first,
130 std::vector<SummationStep>::iterator
last,
133 double fx = 0, fy = 0, fz = 0;
134 int tot_parameters = n_parameters;
135 for (
auto it = first; it !=
last; ++it) {
142 if (it->arg[0] ==
'1' && n_parameters >= 1) fx =
x;
143 if (it->arg[0] ==
'2' && n_parameters >= 2) fx =
y;
146 if (it->arg[0] ==
'1' && n_parameters >= 1) fy =
x;
147 if (it->arg[0] ==
'2' && n_parameters >= 2) fy =
y;
150 if (it->arg[0] ==
'1' && n_parameters >= 1) fz =
x;
151 if (it->arg[0] ==
'2' && n_parameters >= 2) fz =
y;
164 assert(!
"illegal step in STAGE1!");
168 switch(tot_parameters) {
176 dest.
me->
Fill(fx, fy, fz);
179 edm::LogError(
"HistogramManager") <<
"got " << tot_parameters <<
" dimensions\n" 180 <<
"name " << dest.
th1->GetName() <<
"\n";
181 assert(!
"More than 3 dimensions should never occur.");
190 for (
unsigned int i = 0;
i <
specs.size();
i++) {
196 || !
"Incomplete spec (but this cannot be caught in Python)");
202 auto iq =
e.second.iq_sample;
212 <<
"name " <<
t.begin()->second.th1->GetName() <<
"\n" 214 assert(!
"Histogram not booked! (per-event) Probably inconsistent geometry description.");
222 std::pair<std::string, std::string>
226 std::ostringstream
dir(
"");
230 if (!significantvalues.empty()) {
231 for (
auto it = significantvalues.begin();
232 it != (significantvalues.end()-1); ++it) {
234 if (
name ==
"")
continue;
237 auto e = significantvalues[significantvalues.size()-1];
244 if (&step == upto)
break;
247 name =
"num_" +
name;
254 name = name +
"_per_" + colname;
258 boost::algorithm::to_lower(
red);
283 double range_z_min = 1e12;
284 double range_z_max = -1e12;
287 int range_z_nbins = 0;
291 bool do_profile =
false;
293 std::map<GeometryInterface::Values, MEInfo> toBeBooked;
295 for (
unsigned int i = 0;
i <
specs.size();
i++) {
300 bool bookCounters =
false;
302 auto firststep =
s.steps.begin();
311 auto laststep = std::find_if(
s.steps.begin(),
s.steps.end(),
330 for (
auto e : significantvalues)
335 auto histo = toBeBooked.find(significantvalues);
336 if (
histo == toBeBooked.end()) {
339 mei.title = this->
title;
341 mei.title =
"Number of " + mei.title +
" per Event and " 347 int tot_parameters = n_parameters;
349 #define SET_AXIS(to, from) \ 350 mei.to##label = from##label; \ 351 mei.range_##to##_min = ((it->nbins == -1) ? this->range_##from##_min : it->xmin); \ 352 mei.range_##to##_max = ((it->nbins == -1) ? this->range_##from##_max : it->xmax); \ 353 mei.range_##to##_nbins = ((it->nbins == -1) ? this->range_##from##_nbins : it->nbins) 356 for (
auto it = firststep+1; it != laststep; ++it) {
359 if (it->arg[0] ==
'1' && n_parameters >= 1) {
SET_AXIS(
x,
x); }
360 if (it->arg[0] ==
'2' && n_parameters >= 2) {
SET_AXIS(
x,
y); }
363 if (it->arg[0] ==
'1' && n_parameters >= 1) {
SET_AXIS(
y,
x); }
364 if (it->arg[0] ==
'2' && n_parameters >= 2) {
SET_AXIS(
y,
y); }
367 if (it->arg[0] ==
'1' && n_parameters >= 1) {
SET_AXIS(
z,
x); }
368 if (it->arg[0] ==
'2' && n_parameters >= 2) {
SET_AXIS(
z,
y); }
371 assert(mei.range_x_nbins == 0);
372 auto col = it->columns[0];
374 mei.title = mei.title +
" by " + mei.xlabel;
383 auto col = it->columns[0];
385 mei.title = mei.title +
" by " + mei.ylabel;
394 mei.do_profile =
true;
397 assert(!
"illegal step in STAGE1! (booking)");
400 mei.dimensions = tot_parameters;
401 if (mei.do_profile) mei.title =
"Profile of " + mei.title;
402 if (!mei.zlabel.empty()) mei.title = mei.title +
" (Z: " + mei.zlabel +
")";
408 for (
auto it = firststep+1; it != laststep; ++it) {
413 mei.range_x_min =
std::min(mei.range_x_min, val);
414 mei.range_x_max =
std::max(mei.range_x_max, val);
419 mei.range_y_min =
std::min(mei.range_y_min, val);
420 mei.range_y_max =
std::max(mei.range_y_max, val);
429 for (
auto&
e : toBeBooked) {
431 MEInfo& mei =
e.second;
439 if (mei.binwidth_x != 0) {
440 double range = (mei.range_x_max - mei.range_x_min)/mei.binwidth_x;
441 if ((range -
int(range)) == 0.0) {
442 mei.range_x_min -= mei.binwidth_x/2;
443 mei.range_x_max += mei.binwidth_x/2;
445 mei.range_x_min = std::floor(mei.range_x_min/mei.binwidth_x)*mei.binwidth_x;
446 mei.range_x_max = std::ceil(mei.range_x_max/mei.binwidth_x)*mei.binwidth_x;
448 mei.range_x_nbins =
int((mei.range_x_max - mei.range_x_min)/mei.binwidth_x);
450 if (mei.binwidth_y != 0) {
451 double range = (mei.range_y_max - mei.range_y_min)/mei.binwidth_y;
452 if ((range -
int(range)) == 0.0) {
453 mei.range_y_min -= mei.binwidth_y/2;
454 mei.range_y_max += mei.binwidth_y/2;
456 mei.range_y_min = std::floor(mei.range_y_min/mei.binwidth_y)*mei.binwidth_y;
457 mei.range_y_max = std::ceil(mei.range_y_max/mei.binwidth_y)*mei.binwidth_y;
459 mei.range_y_nbins =
int((mei.range_y_max - mei.range_y_min)/mei.binwidth_y);
462 if (mei.dimensions == 1) {
463 h.
me = iBooker.
book1D(
name.second, (mei.title +
";" + mei.xlabel).c_str(),
464 mei.range_x_nbins, mei.range_x_min, mei.range_x_max);
465 }
else if (mei.dimensions == 2 && !mei.do_profile) {
466 h.
me = iBooker.
book2D(
name.second, (mei.title +
";" + mei.xlabel +
";" + mei.ylabel).c_str(),
467 mei.range_x_nbins, mei.range_x_min, mei.range_x_max,
468 mei.range_y_nbins, mei.range_y_min, mei.range_y_max);
469 }
else if (mei.dimensions == 2 && mei.do_profile) {
470 h.
me = iBooker.
bookProfile(
name.second, (mei.title +
";" + mei.xlabel +
";" + mei.ylabel).c_str(),
471 mei.range_x_nbins, mei.range_x_min, mei.range_x_max, 0.0, 0.0,
"");
472 }
else if (mei.dimensions == 3 && mei.do_profile) {
473 h.
me = iBooker.
bookProfile2D(
name.second, (mei.title +
";" + mei.xlabel +
";" + mei.ylabel).c_str(),
474 mei.range_x_nbins, mei.range_x_min, mei.range_x_max,
475 mei.range_y_nbins, mei.range_y_min, mei.range_y_max,
479 <<
"name " <<
name.second <<
"\n" 480 <<
"dim " << mei.dimensions <<
" profile " << mei.do_profile <<
"\n";
481 assert(!
"Illegal Histogram kind.");
511 auto firststep = s.
steps.begin();
513 auto laststep = std::find_if(s.
steps.begin(), s.
steps.end(),
521 auto histo = t.find(significantvalues);
522 if (
histo == t.end()) {
528 edm::LogError(
"HistogramManager") <<
"ME " << path <<
" not found\n";
546 TH1* th1 =
e.second.th1;
553 if (dynamic_cast<TH1F*>(th1)) new_histo.
me = iBooker.
book1D(
name.second, (TH1F*) th1);
554 else if (dynamic_cast<TH2F*>(th1)) new_histo.
me = iBooker.
book2D(
name.second, (TH2F*) th1);
555 else if (dynamic_cast<TProfile*>(th1)) new_histo.
me = iBooker.
bookProfile(
name.second, (TProfile*) th1);
556 else if (dynamic_cast<TProfile2D*>(th1)) new_histo.
me = iBooker.
bookProfile2D(
name.second, (TProfile2D*) th1);
557 else assert(!
"No idea how to book this.");
561 new_histo.
th1->Add(th1);
571 std::map<GeometryInterface::Values, int>
nbins;
577 std::map<GeometryInterface::Values, std::string> separators;
585 assert(
e.second.th1 || !
"invalid histogram");
587 int bins = reduce_type !=
"" ? 1 :
e.second.th1->GetXaxis()->GetNbins();
591 for (
auto&
e : separators)
e.second =
"(" +
e.second +
")/";
597 TH1* th1 =
e.second.th1;
610 (reduce_type !=
"" ? th1->GetYaxis()->GetTitle() : th1->GetXaxis()->GetTitle()) +
";" +
611 (reduce_type !=
"" ? reduce_type +
" of " + th1->GetXaxis()->GetTitle() : th1->GetYaxis()->GetTitle());
614 if (th1->GetDimension() == 1) {
616 nbins[significantvalues], 0.5, nbins[significantvalues] + 0.5);
618 assert(!
"2D extend not implemented in harvesting.");
627 if (new_histo.
th1->GetDimension() == 1) {
628 if (reduce_type ==
"") {
629 for (
int i = 1;
i <= th1->GetXaxis()->GetNbins();
i++) {
630 new_histo.
th1->SetBinContent(new_histo.
count, th1->GetBinContent(
i));
631 new_histo.
th1->SetBinError(new_histo.
count, th1->GetBinError(
i));
632 new_histo.
count += 1;
634 }
else if (reduce_type ==
"MEAN") {
635 new_histo.
th1->SetBinContent(new_histo.
count, th1->GetMean());
636 new_histo.
th1->SetBinError(new_histo.
count, th1->GetMeanError());
637 new_histo.
count += 1;
639 assert(!
"Reduction type not supported");
642 assert(!
"2D extend not implemented in harvesting.");
654 log <<
"Specs for " <<
name <<
" ";
658 for (
unsigned int i = 0;
i < specs.size();
i++) {
677 reduce_type = step.
arg;
684 assert(!
"EXTEND_Y currently not supported in harvesting.");
687 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
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
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 * bookProfile2D(Args &&...args)
MonitorElement * book1D(Args &&...args)
static const Value UNDEFINED
std::vector< std::pair< Column, Value > > Values
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
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
#define SET_AXIS(to, from)
GeometryInterface & geometryInterface