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 840 of file hltDiff.cc.

Constructor & Destructor Documentation

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

Definition at line 1169 of file hltDiff.cc.

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

Member Function Documentation

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

Definition at line 971 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.

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

Definition at line 1175 of file hltDiff.cc.

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

Referenced by HltDiff::compare().

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

Definition at line 1149 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.

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

Definition at line 1133 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.

1133  {
1134  std::string file_name = json.output_filename_base(this->run)+="_trigger.csv";
1135  FILE* out_file = fopen((file_name).c_str(), "w");
1136 
1137  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");
1138  for (const auto& idSummary : m_triggerSummary) {
1139  const SummaryOutputProducer::TriggerSummary& S = idSummary.second;
1140  fprintf(out_file, "%d,%d,%d,%+.f,%+.f,%.2f%%,%.2f%%,~%.f,~%.2f%%,%.2f%%,%s\n",
1141  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());
1142  }
1143 
1144  fclose(out_file);
1145 
1146  return file_name;
1147  }
Pair gained(int type=0) const
Definition: hltDiff.cc:936
const JsonOutputProducer & json
Definition: hltDiff.cc:843
Pair changed(int type=0) const
Definition: hltDiff.cc:956
std::string output_filename_base(int _run) const
Definition: hltDiff.cc:773
std::map< int, TriggerSummary > m_triggerSummary
Definition: hltDiff.cc:968
double S(const TLorentzVector &, const TLorentzVector &)
Definition: Particle.cc:99
Pair lost(int type=0) const
Definition: hltDiff.cc:946
JsonConfiguration configuration
Definition: hltDiff.cc:646
std::string SummaryOutputProducer::writeHistograms ( ) const
inlineprivate

Definition at line 994 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.

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

Member Data Documentation

const JsonOutputProducer& SummaryOutputProducer::json
private

Definition at line 843 of file hltDiff.cc.

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

Definition at line 969 of file hltDiff.cc.

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

Definition at line 968 of file hltDiff.cc.

int SummaryOutputProducer::run
private
bool SummaryOutputProducer::storeCSV

Definition at line 1167 of file hltDiff.cc.

bool SummaryOutputProducer::storeROOT

Definition at line 1166 of file hltDiff.cc.