CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Public Attributes | Private Member Functions | Private Attributes
SummaryOutputProducer Class Reference

Classes

struct  Event
 
struct  GenericSummary
 
struct  Pair
 
struct  TriggerSummary
 

Public Member Functions

 SummaryOutputProducer (const JsonOutputProducer &_json, bool _storeROOT, bool _storeCSV)
 
void write ()
 

Public Attributes

bool storeCSV
 
bool storeROOT
 

Private Member Functions

void prepareSummaries (const int _run, const std::vector< JsonOutputProducer::JsonEvent > &_events)
 
std::string writeCSV_module () const
 
std::string writeCSV_trigger () const
 
std::string writeHistograms () const
 

Private Attributes

const JsonOutputProducerjson
 
std::map< int, GenericSummarym_moduleSummary
 
std::map< int, TriggerSummarym_triggerSummary
 
int run
 

Detailed Description

Definition at line 841 of file hltDiff.cc.

Constructor & Destructor Documentation

SummaryOutputProducer::SummaryOutputProducer ( const JsonOutputProducer _json,
bool  _storeROOT,
bool  _storeCSV 
)
inline

Definition at line 1170 of file hltDiff.cc.

1170  :
1171  json(_json),
1172  run(0),
1173  storeROOT(_storeROOT),
1174  storeCSV(_storeCSV) {}
const JsonOutputProducer & json
Definition: hltDiff.cc:844

Member Function Documentation

void SummaryOutputProducer::prepareSummaries ( const int  _run,
const std::vector< JsonOutputProducer::JsonEvent > &  _events 
)
inlineprivate

Definition at line 972 of file hltDiff.cc.

References Fail, mps_fire::i, JsonOutputProducer::JsonEventState::l, JsonOutputProducer::JsonVars::label, JsonOutputProducer::JsonTriggerEventState::n, JsonOutputProducer::JsonTriggerEventState::o, JsonOutputProducer::JsonEventState::s, JsonOutputProducer::JsonTriggerEventState::tr, JsonOutputProducer::JsonVars::trigger, and JsonOutputProducer::vars.

972  {
973  this->run = _run;
974  // Initialising the summary objects for trigger/module
975  m_triggerSummary.clear();
976  m_moduleSummary.clear();
977  const size_t nTriggers( json.vars.trigger.size() );
978  const size_t nModules( json.vars.label.size() );
979  for (size_t i=0; i<nTriggers; ++i)
980  m_triggerSummary.emplace(i, TriggerSummary(i, json) );
981  for (size_t i=0; i<nModules; ++i)
982  m_moduleSummary.emplace(i, GenericSummary(i, json, json.vars.label) );
983 
984  // Add each affected trigger in each event to the trigger/module summary objects
985  for (const JsonOutputProducer::JsonEvent& event : _events) {
986  for (size_t iTrigger = 0; iTrigger < event.triggerStates.size(); ++iTrigger) {
987  const JsonOutputProducer::JsonTriggerEventState& state = event.triggerStates.at(iTrigger);
988  m_triggerSummary.at(state.tr).addEntry(event, iTrigger, json.vars.label);
989  const int moduleId = state.o.s == State::Fail ? state.o.l : state.n.l;
990  m_moduleSummary.at(moduleId).addEntry(event, iTrigger);
991  }
992  }
993  }
const JsonOutputProducer & json
Definition: hltDiff.cc:844
std::vector< std::string > label
Definition: hltDiff.cc:621
std::map< int, GenericSummary > m_moduleSummary
Definition: hltDiff.cc:970
std::map< int, TriggerSummary > m_triggerSummary
Definition: hltDiff.cc:969
std::vector< std::string > trigger
Definition: hltDiff.cc:619
Definition: hltDiff.cc:291
Definition: event.py:1
void SummaryOutputProducer::write ( )
inline

Definition at line 1176 of file hltDiff.cc.

References gather_cfg::cout, corrVsCorr::filename, JsonOutputProducer::m_run_events, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by HltDiff::compare().

1176  {
1177  std::vector<std::string> filesCreated;
1178  // Processing every run from the JSON producer
1179  if (json.m_run_events.size() > 0) {
1180  for (const auto& runEvents : json.m_run_events) {
1181  prepareSummaries(runEvents.first, runEvents.second);
1182  if (storeROOT) {
1183  filesCreated.push_back(writeHistograms());
1184  }
1185  if (storeCSV) {
1186  filesCreated.push_back(writeCSV_trigger());
1187  filesCreated.push_back(writeCSV_module());
1188  }
1189  }
1190  } else {
1191  if (storeROOT) {
1192  filesCreated.push_back(writeHistograms());
1193  }
1194  if (storeCSV) {
1195  filesCreated.push_back(writeCSV_trigger());
1196  filesCreated.push_back(writeCSV_module());
1197  }
1198  }
1199 
1200  if (filesCreated.size() > 0) {
1201  std::cout << "Created the following summary files:" << std::endl;
1202  for (const std::string& filename : filesCreated)
1203  std::cout << " " << filename << std::endl;
1204  }
1205  }
std::map< int, std::vector< JsonEvent > > m_run_events
Definition: hltDiff.cc:746
const JsonOutputProducer & json
Definition: hltDiff.cc:844
std::string writeCSV_module() const
Definition: hltDiff.cc:1150
void prepareSummaries(const int _run, const std::vector< JsonOutputProducer::JsonEvent > &_events)
Definition: hltDiff.cc:972
std::string writeHistograms() const
Definition: hltDiff.cc:995
std::string writeCSV_trigger() const
Definition: hltDiff.cc:1134
std::string SummaryOutputProducer::writeCSV_module ( ) const
inlineprivate

Definition at line 1150 of file hltDiff.cc.

References SummaryOutputProducer::GenericSummary::changed(), JsonOutputProducer::configuration, JsonOutputProducer::JsonConfiguration::events, cmsPerfSuiteHarvest::file_name, SummaryOutputProducer::GenericSummary::gained(), SummaryOutputProducer::GenericSummary::lost(), SummaryOutputProducer::GenericSummary::name, JsonOutputProducer::output_filename_base(), S(), AlCaHLTBitMon_QueryRunRegistry::string, and SummaryOutputProducer::Pair::v.

1150  {
1151  std::string file_name = json.output_filename_base(this->run)+="_module.csv";
1152  FILE* out_file = fopen((file_name).c_str(), "w");
1153 
1154  fprintf(out_file,"Total,Gained,Lost,Changed,module\n");
1155  for (const auto& idSummary : m_moduleSummary) {
1156  const SummaryOutputProducer::GenericSummary& S = idSummary.second;
1157  fprintf(out_file, "%d,+%.f,-%.f,~%.f,%s\n",
1158  this->json.configuration.events, S.gained().v, S.lost().v, S.changed().v, S.name.c_str());
1159  }
1160 
1161  fclose(out_file);
1162 
1163  return file_name;
1164  }
const JsonOutputProducer & json
Definition: hltDiff.cc:844
std::map< int, GenericSummary > m_moduleSummary
Definition: hltDiff.cc:970
std::string output_filename_base(int _run) const
Definition: hltDiff.cc:774
double S(const TLorentzVector &, const TLorentzVector &)
Definition: Particle.cc:99
JsonConfiguration configuration
Definition: hltDiff.cc:647
std::string SummaryOutputProducer::writeCSV_trigger ( ) const
inlineprivate

Definition at line 1134 of file hltDiff.cc.

References SummaryOutputProducer::TriggerSummary::accepted_n, SummaryOutputProducer::TriggerSummary::accepted_o, SummaryOutputProducer::TriggerSummary::changed(), JsonOutputProducer::configuration, SummaryOutputProducer::Pair::e, JsonOutputProducer::JsonConfiguration::events, cmsPerfSuiteHarvest::file_name, SummaryOutputProducer::TriggerSummary::gained(), SummaryOutputProducer::TriggerSummary::lost(), SummaryOutputProducer::GenericSummary::name, JsonOutputProducer::output_filename_base(), S(), AlCaHLTBitMon_QueryRunRegistry::string, and SummaryOutputProducer::Pair::v.

1134  {
1135  std::string file_name = json.output_filename_base(this->run)+="_trigger.csv";
1136  FILE* out_file = fopen((file_name).c_str(), "w");
1137 
1138  fprintf(out_file,"Total,Accepted OLD,Accepted NEW,Gained,Lost,|G|/A_N + |L|/AO,sigma(AN)+sigma(AO),Changed,C/(T-AO),sigma(T-AO),trigger\n");
1139  for (const auto& idSummary : m_triggerSummary) {
1140  const SummaryOutputProducer::TriggerSummary& S = idSummary.second;
1141  fprintf(out_file, "%d,%d,%d,%+.f,%+.f,%.2f%%,%.2f%%,~%.f,~%.2f%%,%.2f%%,%s\n",
1142  this->json.configuration.events, S.accepted_o, S.accepted_n, S.gained().v, -1.0*S.lost().v, (S.gained(1).v+S.lost(1).v)*100.0, (S.gained(1).e+S.lost(1).e)*100.0, S.changed().v, S.changed(1).v*100.0, S.changed(1).e*100.0, S.name.c_str());
1143  }
1144 
1145  fclose(out_file);
1146 
1147  return file_name;
1148  }
Pair gained(int type=0) const
Definition: hltDiff.cc:937
const JsonOutputProducer & json
Definition: hltDiff.cc:844
Pair changed(int type=0) const
Definition: hltDiff.cc:957
std::string output_filename_base(int _run) const
Definition: hltDiff.cc:774
std::map< int, TriggerSummary > m_triggerSummary
Definition: hltDiff.cc:969
double S(const TLorentzVector &, const TLorentzVector &)
Definition: Particle.cc:99
Pair lost(int type=0) const
Definition: hltDiff.cc:947
JsonConfiguration configuration
Definition: hltDiff.cc:647
std::string SummaryOutputProducer::writeHistograms ( ) const
inlineprivate

Definition at line 995 of file hltDiff.cc.

References SummaryOutputProducer::TriggerSummary::accepted_o, stringResolutionProvider_cfi::bin, SummaryOutputProducer::GenericSummary::changed(), SummaryOutputProducer::TriggerSummary::changed(), SummaryOutputProducer::Pair::e, cmsPerfSuiteHarvest::file_name, SummaryOutputProducer::GenericSummary::gained(), SummaryOutputProducer::TriggerSummary::gained(), trackerHits::histo, SummaryOutputProducer::GenericSummary::keepForC(), SummaryOutputProducer::GenericSummary::keepForGL(), SummaryOutputProducer::GenericSummary::lost(), SummaryOutputProducer::TriggerSummary::lost(), hpstanc_transforms::max, dataset::name, SummaryOutputProducer::GenericSummary::name, JsonOutputProducer::output_filename_base(), AlCaHLTBitMon_QueryRunRegistry::string, heppy_report::summary, and SummaryOutputProducer::Pair::v.

995  {
996  std::map<std::string, TH1*> m_histo;
997  // Counting the numbers of bins for different types of histograms
998  // *_c - changed; *_gl - gained or lost
999  int nTriggers(0), nTriggers_c(0), nTriggers_gl(0), nModules_c(0), nModules_gl(0);
1000 
1001  for (const auto& idSummary : m_triggerSummary) {
1002  if (idSummary.second.accepted_o > 0) ++nTriggers;
1003  if (idSummary.second.keepForGL()) ++nTriggers_gl;
1004  if (idSummary.second.keepForC()) ++nTriggers_c;
1005  }
1006  for (const auto& idSummary : m_moduleSummary) {
1007  if (idSummary.second.keepForGL()) ++nModules_gl;
1008  if (idSummary.second.keepForC()) ++nModules_c;
1009  }
1010  // Manually increasing N bins to have histograms with meaningful axis ranges
1011  nTriggers = std::max(1, nTriggers);
1012  nTriggers_gl = std::max(1, nTriggers_gl);
1013  nTriggers_c = std::max(1, nTriggers_c);
1014  nModules_c = std::max(1, nModules_c);
1015  nModules_gl = std::max(1, nModules_gl);
1016 
1017  // Initialising overview histograms
1018  std::string name = "trigger_accepted";
1019  m_histo.emplace(name, new TH1F(name.c_str(), ";;Events accepted^{OLD}", nTriggers, 0, nTriggers));
1020  name = "trigger_gained";
1021  m_histo.emplace(name, new TH1F(name.c_str(), ";;Events gained", nTriggers_gl, 0, nTriggers_gl));
1022  name = "trigger_lost";
1023  m_histo.emplace(name, new TH1F(name.c_str(), ";;Events lost", nTriggers_gl, 0, nTriggers_gl));
1024  name = "trigger_changed";
1025  m_histo.emplace(name, new TH1F(name.c_str(), ";;Events changed", nTriggers_c, 0, nTriggers_c));
1026  name = "trigger_gained_frac";
1027  m_histo.emplace(name, new TH1F(name.c_str(), ";;#frac{gained}{accepted}", nTriggers_gl, 0, nTriggers_gl));
1028  name = "trigger_lost_frac";
1029  m_histo.emplace(name, new TH1F(name.c_str(), ";;#frac{lost}{accepted}", nTriggers_gl, 0, nTriggers_gl));
1030  name = "trigger_changed_frac";
1031  m_histo.emplace(name, new TH1F(name.c_str(), ";;#frac{changed}{all - accepted}", nTriggers_c, 0, nTriggers_c));
1032  name = "module_changed";
1033  m_histo.emplace(name, new TH1F(name.c_str(), ";;Events changed", nModules_c, 0, nModules_c));
1034  name = "module_gained";
1035  m_histo.emplace(name, new TH1F(name.c_str(), ";;Events gained", nModules_gl, 0, nModules_gl));
1036  name = "module_lost";
1037  m_histo.emplace(name, new TH1F(name.c_str(), ";;Events lost", nModules_gl, 0, nModules_gl));
1038 
1039  // Filling the per-trigger bins in the summary histograms
1040  size_t bin(0), bin_c(0), bin_gl(0);
1041  for (const auto& idSummary : m_triggerSummary) {
1042  const TriggerSummary& summary = idSummary.second;
1043  if (summary.accepted_o > 0) {
1044  ++bin;
1045  // Setting bin contents
1046  m_histo.at("trigger_accepted")->SetBinContent(bin, summary.accepted_o);
1047  // Setting bin labels
1048  m_histo.at("trigger_accepted")->GetXaxis()->SetBinLabel(bin, summary.name.c_str());
1049  }
1050  if (summary.keepForGL()) {
1051  ++bin_gl;
1052  // Setting bin contents
1053  m_histo.at("trigger_gained")->SetBinContent(bin_gl, summary.gained().v);
1054  m_histo.at("trigger_lost")->SetBinContent(bin_gl, -summary.lost().v);
1055  m_histo.at("trigger_gained_frac")->SetBinContent(bin_gl, summary.gained(1).v);
1056  m_histo.at("trigger_lost_frac")->SetBinContent(bin_gl, -summary.lost(1).v);
1057  // Setting bin errors
1058  m_histo.at("trigger_gained_frac")->SetBinError(bin_gl, summary.gained(1).e);
1059  m_histo.at("trigger_lost_frac")->SetBinError(bin_gl, -summary.lost(1).e);
1060  // Setting bin labels
1061  m_histo.at("trigger_gained")->GetXaxis()->SetBinLabel(bin_gl, summary.name.c_str());
1062  m_histo.at("trigger_lost")->GetXaxis()->SetBinLabel(bin_gl, summary.name.c_str());
1063  m_histo.at("trigger_gained_frac")->GetXaxis()->SetBinLabel(bin_gl, summary.name.c_str());
1064  m_histo.at("trigger_lost_frac")->GetXaxis()->SetBinLabel(bin_gl, summary.name.c_str());
1065  }
1066  if (summary.keepForC()) {
1067  ++bin_c;
1068  // Setting bin contents
1069  m_histo.at("trigger_changed")->SetBinContent(bin_c, summary.changed().v);
1070  m_histo.at("trigger_changed_frac")->SetBinContent(bin_c, summary.changed(1).v);
1071  // Setting bin errors
1072  m_histo.at("trigger_changed_frac")->SetBinError(bin_c, summary.changed(1).e);
1073  // Setting bin labels
1074  m_histo.at("trigger_changed")->GetXaxis()->SetBinLabel(bin_c, summary.name.c_str());
1075  m_histo.at("trigger_changed_frac")->GetXaxis()->SetBinLabel(bin_c, summary.name.c_str());
1076  }
1077  }
1078 
1079  // Filling the per-module bins in the summary histograms
1080  bin = 0;
1081  bin_c = 0;
1082  bin_gl = 0;
1083  for (const auto& idSummary : m_moduleSummary) {
1084  ++bin;
1085  const GenericSummary& summary = idSummary.second;
1086  if (summary.keepForGL()) {
1087  ++bin_gl;
1088  // Setting bin contents
1089  m_histo.at("module_gained")->SetBinContent(bin_gl, summary.gained().v);
1090  m_histo.at("module_lost")->SetBinContent(bin_gl, -summary.lost().v);
1091  // Setting bin labels
1092  m_histo.at("module_gained")->GetXaxis()->SetBinLabel(bin_gl, summary.name.c_str());
1093  m_histo.at("module_lost")->GetXaxis()->SetBinLabel(bin_gl, summary.name.c_str());
1094  }
1095  if (summary.keepForC()) {
1096  ++bin_c;
1097  // Setting bin contents
1098  m_histo.at("module_changed")->SetBinContent(bin_c, summary.changed().v);
1099  // Setting bin labels
1100  m_histo.at("module_changed")->GetXaxis()->SetBinLabel(bin_c, summary.name.c_str());
1101  }
1102  }
1103 
1104  // Styling the histograms
1105  for (const auto& nameHisto : m_histo) {
1106  const std::string name = nameHisto.first;
1107  TH1* histo = nameHisto.second;
1108  if (name.find("gained") != std::string::npos || name.find("changed") != std::string::npos) {
1109  if (name.find("frac") != std::string::npos)
1110  histo->GetYaxis()->SetRangeUser(0.0, 1.0);
1111  }
1112  if (name.find("lost") != std::string::npos) {
1113  if (name.find("frac") != std::string::npos)
1114  histo->GetYaxis()->SetRangeUser(-1.0, 0.0);
1115  }
1116  }
1117 
1118  // Storing histograms to a ROOT file
1120  auto out_file = new TFile(file_name.c_str(), "RECREATE");
1121  // Storing the histograms in a proper folder according to the DQM convention
1122  char savePath[1000];
1123  sprintf(savePath, "DQMData/Run %d/HLT/Run summary/EventByEvent/", this->run);
1124  out_file->mkdir(savePath);
1125  gDirectory->cd(savePath);
1126  gDirectory->Write();
1127  for (const auto& nameHisto : m_histo)
1128  nameHisto.second->Write(nameHisto.first.c_str());
1129  out_file->Close();
1130 
1131  return file_name;
1132  }
const JsonOutputProducer & json
Definition: hltDiff.cc:844
std::map< int, GenericSummary > m_moduleSummary
Definition: hltDiff.cc:970
std::string output_filename_base(int _run) const
Definition: hltDiff.cc:774
std::map< int, TriggerSummary > m_triggerSummary
Definition: hltDiff.cc:969
bin
set the eta bin as selection string.

Member Data Documentation

const JsonOutputProducer& SummaryOutputProducer::json
private

Definition at line 844 of file hltDiff.cc.

std::map<int, GenericSummary> SummaryOutputProducer::m_moduleSummary
private

Definition at line 970 of file hltDiff.cc.

std::map<int, TriggerSummary> SummaryOutputProducer::m_triggerSummary
private

Definition at line 969 of file hltDiff.cc.

int SummaryOutputProducer::run
private
bool SummaryOutputProducer::storeCSV

Definition at line 1168 of file hltDiff.cc.

bool SummaryOutputProducer::storeROOT

Definition at line 1167 of file hltDiff.cc.