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 (
const 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(
"");
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(
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) {
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;
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;
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.");
521 h.th1 =
h.me->getTH1();
547 auto firststep =
s.steps.begin();
550 auto laststep = std::find_if(
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) {
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.");