9 #include <boost/algorithm/string.hpp>
20 geometryInterface(geo),
24 top_folder_name(iconfig.getParameter<
std::
string>(
"topFolderName")),
30 range_x_nbins(iconfig.getParameter<
int>(
"range_nbins")),
31 range_x_min(iconfig.getParameter<double>(
"range_min")),
32 range_x_max(iconfig.getParameter<double>(
"range_max")),
34 range_y_min(iconfig.getParameter<double>(
"range_y_min")),
35 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(
"");
290 double range_z_min = 1e12;
291 double range_z_max = -1e12;
294 int range_z_nbins = 0;
298 bool do_profile =
false;
302 std::map<GeometryInterface::Values, MEInfo> toBeBooked;
304 for (
unsigned int i = 0;
i <
specs.size();
i++) {
309 bool bookCounters =
false;
311 auto firststep =
s.steps.begin();
320 auto laststep = std::find_if(
344 if (
histo == toBeBooked.end()) {
347 mei.title = this->
title;
356 int tot_parameters = n_parameters;
358 #define SET_AXIS(to, from) \
359 mei.to##label = from##label; \
360 mei.range_##to##_min = ((it->nbins == -1) ? this->range_##from##_min : it->xmin); \
361 mei.range_##to##_max = ((it->nbins == -1) ? this->range_##from##_max : it->xmax); \
362 mei.range_##to##_nbins = ((it->nbins == -1) ? this->range_##from##_nbins : it->nbins)
364 for (
auto it = firststep + 1; it != laststep; ++it) {
367 if (it->arg[0] ==
'1' && n_parameters >= 1) {
370 if (it->arg[0] ==
'2' && n_parameters >= 2) {
375 if (it->arg[0] ==
'1' && n_parameters >= 1) {
378 if (it->arg[0] ==
'2' && n_parameters >= 2) {
383 if (it->arg[0] ==
'1' && n_parameters >= 1) {
386 if (it->arg[0] ==
'2' && n_parameters >= 2) {
391 assert(mei.range_x_nbins == 0);
392 auto col = it->columns[0];
394 mei.title = mei.title +
" by " + mei.xlabel;
403 auto col = it->columns[0];
405 mei.title = mei.title +
" by " + mei.ylabel;
414 mei.do_profile =
true;
417 assert(!
"illegal step in STAGE1! (booking)");
420 mei.dimensions = tot_parameters;
422 mei.title =
"Profile of " + mei.title;
423 if (!mei.zlabel.empty())
424 mei.title = mei.title +
" (Z: " + mei.zlabel +
")";
430 for (
auto it = firststep + 1; it != laststep; ++it) {
453 for (
auto&
e : toBeBooked) {
455 MEInfo& mei =
e.second;
463 if (mei.binwidth_x != 0) {
464 double range = (mei.range_x_max - mei.range_x_min) / mei.binwidth_x;
466 mei.range_x_min -= mei.binwidth_x / 2;
467 mei.range_x_max += mei.binwidth_x / 2;
469 mei.range_x_min = std::floor(mei.range_x_min / mei.binwidth_x) * mei.binwidth_x;
470 mei.range_x_max =
std::ceil(mei.range_x_max / mei.binwidth_x) * mei.binwidth_x;
472 mei.range_x_nbins =
int((mei.range_x_max - mei.range_x_min) / mei.binwidth_x);
474 if (mei.binwidth_y != 0) {
475 double range = (mei.range_y_max - mei.range_y_min) / mei.binwidth_y;
477 mei.range_y_min -= mei.binwidth_y / 2;
478 mei.range_y_max += mei.binwidth_y / 2;
480 mei.range_y_min = std::floor(mei.range_y_min / mei.binwidth_y) * mei.binwidth_y;
481 mei.range_y_max =
std::ceil(mei.range_y_max / mei.binwidth_y) * mei.binwidth_y;
483 mei.range_y_nbins =
int((mei.range_y_max - mei.range_y_min) / mei.binwidth_y);
486 if (mei.dimensions == 1) {
488 name.second, (mei.title +
";" + mei.xlabel).c_str(), mei.range_x_nbins, mei.range_x_min, mei.range_x_max);
489 }
else if (mei.dimensions == 2 && !mei.do_profile) {
491 (mei.title +
";" + mei.xlabel +
";" + mei.ylabel).c_str(),
498 }
else if (mei.dimensions == 2 && mei.do_profile) {
500 (mei.title +
";" + mei.xlabel +
";" + mei.ylabel).c_str(),
507 }
else if (mei.dimensions == 3 && mei.do_profile) {
509 (mei.title +
";" + mei.xlabel +
";" + mei.ylabel).c_str(),
520 <<
"name " <<
name.second <<
"\n"
521 <<
"dim " << mei.dimensions <<
" profile " << mei.do_profile <<
"\n";
522 assert(!
"Illegal Histogram kind.");
524 h.th1 =
h.me->getTH1();
525 h.me->setStatOverflows(mei.statsOverflows);
551 auto firststep =
s.steps.begin();
554 auto laststep = std::find_if(
587 TH1* th1 =
e.second.th1;
593 if (dynamic_cast<TH1F*>(th1))
595 else if (dynamic_cast<TH2F*>(th1))
597 else if (dynamic_cast<TProfile*>(th1))
599 else if (dynamic_cast<TProfile2D*>(th1))
602 assert(!
"No idea how to book this.");
606 new_histo.
th1->Add(th1);
620 std::map<GeometryInterface::Values, int>
nbins;
626 std::map<GeometryInterface::Values, std::string> separators;
633 assert(
e.second.th1 || !
"invalid histogram");
635 int bins = !reduce_type.empty() ? 1 :
e.second.th1->GetXaxis()->GetNbins();
640 for (
auto&
e : separators)
641 e.second =
"(" +
e.second +
")/";
646 TH1* th1 =
e.second.th1;
659 (!reduce_type.empty() ? th1->GetYaxis()->GetTitle() : th1->GetXaxis()->GetTitle()) +
";" +
660 (!reduce_type.empty() ? reduce_type +
" of " + th1->GetXaxis()->GetTitle() : th1->GetYaxis()->GetTitle());
663 if (th1->GetDimension() == 1) {
667 assert(!
"2D extend not implemented in harvesting.");
676 if (new_histo.
th1->GetDimension() == 1) {
677 if (reduce_type.empty()) {
678 for (
int i = 1;
i <= th1->GetXaxis()->GetNbins();
i++) {
679 new_histo.
th1->SetBinContent(new_histo.
count, th1->GetBinContent(
i));
680 new_histo.
th1->SetBinError(new_histo.
count, th1->GetBinError(
i));
681 new_histo.
count += 1;
683 }
else if (reduce_type ==
"MEAN") {
684 new_histo.
th1->SetBinContent(new_histo.
count, th1->GetMean());
685 new_histo.
th1->SetBinError(new_histo.
count, th1->GetMeanError());
686 new_histo.
count += 1;
688 assert(!
"Reduction type not supported");
692 assert(!
"2D extend not implemented in harvesting.");
704 log <<
"Specs for " <<
name <<
" ";
708 for (
unsigned int i = 0;
i <
specs.size();
i++) {
727 reduce_type =
step.arg;
734 assert(!
"EXTEND_Y currently not supported in harvesting.");
737 assert(!
"Operation not supported in harvesting.");