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

Constructor & Destructor Documentation

◆ SummaryOutputProducer()

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

Definition at line 1142 of file hltDiff.cc.

1143  : json(_json), run(0), storeROOT(_storeROOT), storeCSV(_storeCSV) {}

Member Function Documentation

◆ prepareSummaries()

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

Definition at line 921 of file hltDiff.cc.

921  {
922  this->run = _run;
923  // Initialising the summary objects for trigger/module
924  m_triggerSummary.clear();
925  m_moduleSummary.clear();
926  const size_t nTriggers(json.vars.trigger.size());
927  const size_t nModules(json.vars.label.size());
928  for (size_t i = 0; i < nTriggers; ++i)
929  m_triggerSummary.emplace(i, TriggerSummary(i, json));
930  for (size_t i = 0; i < nModules; ++i)
931  m_moduleSummary.emplace(i, GenericSummary(i, json, json.vars.label));
932 
933  // Add each affected trigger in each event to the trigger/module summary objects
934  for (const JsonOutputProducer::JsonEvent& event : _events) {
935  for (size_t iTrigger = 0; iTrigger < event.triggerStates.size(); ++iTrigger) {
936  const JsonOutputProducer::JsonTriggerEventState& state = event.triggerStates.at(iTrigger);
937  m_triggerSummary.at(state.tr).addEntry(event, iTrigger, json.vars.label);
938  const int moduleId = state.o.s == State::Fail ? state.o.l : state.n.l;
939  m_moduleSummary.at(moduleId).addEntry(event, iTrigger);
940  }
941  }
942  }

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

◆ write()

void SummaryOutputProducer::write ( )
inline

Definition at line 1145 of file hltDiff.cc.

1145  {
1146  std::vector<std::string> filesCreated;
1147  // Processing every run from the JSON producer
1148  if (!json.m_run_events.empty()) {
1149  for (const auto& runEvents : json.m_run_events) {
1150  prepareSummaries(runEvents.first, runEvents.second);
1151  if (storeROOT) {
1152  filesCreated.push_back(writeHistograms());
1153  }
1154  if (storeCSV) {
1155  filesCreated.push_back(writeCSV_trigger());
1156  filesCreated.push_back(writeCSV_module());
1157  }
1158  }
1159  } else {
1160  if (storeROOT) {
1161  filesCreated.push_back(writeHistograms());
1162  }
1163  if (storeCSV) {
1164  filesCreated.push_back(writeCSV_trigger());
1165  filesCreated.push_back(writeCSV_module());
1166  }
1167  }
1168 
1169  if (!filesCreated.empty()) {
1170  std::cout << "Created the following summary files:" << std::endl;
1171  for (const std::string& filename : filesCreated)
1172  std::cout << " " << filename << std::endl;
1173  }
1174  }

References gather_cfg::cout, corrVsCorr::filename, hltMonBTagIPClient_cfi::storeROOT, and AlCaHLTBitMon_QueryRunRegistry::string.

◆ writeCSV_module()

std::string SummaryOutputProducer::writeCSV_module ( ) const
inlineprivate

Definition at line 1117 of file hltDiff.cc.

1117  {
1118  std::string file_name = json.output_filename_base(this->run) += "_module.csv";
1119  FILE* out_file = fopen((file_name).c_str(), "w");
1120 
1121  fprintf(out_file, "Total,Gained,Lost,Changed,module\n");
1122  for (const auto& idSummary : m_moduleSummary) {
1123  const SummaryOutputProducer::GenericSummary& S = idSummary.second;
1124  fprintf(out_file,
1125  "%d,+%.f,-%.f,~%.f,%s\n",
1126  this->json.configuration.events,
1127  S.gained().v,
1128  S.lost().v,
1129  S.changed().v,
1130  S.name.c_str());
1131  }
1132 
1133  fclose(out_file);
1134 
1135  return file_name;
1136  }

References JsonOutputProducer::configuration, JsonOutputProducer::JsonConfiguration::events, contentValuesCheck::file_name, DeadROCCounter::out_file, and AlCaHLTBitMon_QueryRunRegistry::string.

◆ writeCSV_trigger()

std::string SummaryOutputProducer::writeCSV_trigger ( ) const
inlineprivate

Definition at line 1088 of file hltDiff.cc.

1088  {
1089  std::string file_name = json.output_filename_base(this->run) += "_trigger.csv";
1090  FILE* out_file = fopen((file_name).c_str(), "w");
1091 
1092  fprintf(out_file,
1093  "Total,Accepted OLD,Accepted NEW,Gained,Lost,|G|/A_N + "
1094  "|L|/AO,sigma(AN)+sigma(AO),Changed,C/(T-AO),sigma(T-AO),trigger\n");
1095  for (const auto& idSummary : m_triggerSummary) {
1096  const SummaryOutputProducer::TriggerSummary& S = idSummary.second;
1097  fprintf(out_file,
1098  "%d,%d,%d,%+.f,%+.f,%.2f%%,%.2f%%,~%.f,~%.2f%%,%.2f%%,%s\n",
1099  this->json.configuration.events,
1100  S.accepted_o,
1101  S.accepted_n,
1102  S.gained().v,
1103  -1.0 * S.lost().v,
1104  (S.gained(1).v + S.lost(1).v) * 100.0,
1105  (S.gained(1).e + S.lost(1).e) * 100.0,
1106  S.changed().v,
1107  S.changed(1).v * 100.0,
1108  S.changed(1).e * 100.0,
1109  S.name.c_str());
1110  }
1111 
1112  fclose(out_file);
1113 
1114  return file_name;
1115  }

References JsonOutputProducer::configuration, JsonOutputProducer::JsonConfiguration::events, contentValuesCheck::file_name, DeadROCCounter::out_file, and AlCaHLTBitMon_QueryRunRegistry::string.

◆ writeHistograms()

std::string SummaryOutputProducer::writeHistograms ( ) const
inlineprivate

Definition at line 944 of file hltDiff.cc.

944  {
945  std::map<std::string, TH1*> m_histo;
946  // Counting the numbers of bins for different types of histograms
947  // *_c - changed; *_gl - gained or lost
948  int nTriggers(0), nTriggers_c(0), nTriggers_gl(0), nModules_c(0), nModules_gl(0);
949 
950  for (const auto& idSummary : m_triggerSummary) {
951  if (idSummary.second.accepted_o > 0)
952  ++nTriggers;
953  if (idSummary.second.keepForGL())
954  ++nTriggers_gl;
955  if (idSummary.second.keepForC())
956  ++nTriggers_c;
957  }
958  for (const auto& idSummary : m_moduleSummary) {
959  if (idSummary.second.keepForGL())
960  ++nModules_gl;
961  if (idSummary.second.keepForC())
962  ++nModules_c;
963  }
964  // Manually increasing N bins to have histograms with meaningful axis ranges
965  nTriggers = std::max(1, nTriggers);
966  nTriggers_gl = std::max(1, nTriggers_gl);
967  nTriggers_c = std::max(1, nTriggers_c);
968  nModules_c = std::max(1, nModules_c);
969  nModules_gl = std::max(1, nModules_gl);
970 
971  // Initialising overview histograms
972  std::string name = "trigger_accepted";
973  m_histo.emplace(name, new TH1F(name.c_str(), ";;Events accepted^{OLD}", nTriggers, 0, nTriggers));
974  name = "trigger_gained";
975  m_histo.emplace(name, new TH1F(name.c_str(), ";;Events gained", nTriggers_gl, 0, nTriggers_gl));
976  name = "trigger_lost";
977  m_histo.emplace(name, new TH1F(name.c_str(), ";;Events lost", nTriggers_gl, 0, nTriggers_gl));
978  name = "trigger_changed";
979  m_histo.emplace(name, new TH1F(name.c_str(), ";;Events changed", nTriggers_c, 0, nTriggers_c));
980  name = "trigger_gained_frac";
981  m_histo.emplace(name, new TH1F(name.c_str(), ";;#frac{gained}{accepted}", nTriggers_gl, 0, nTriggers_gl));
982  name = "trigger_lost_frac";
983  m_histo.emplace(name, new TH1F(name.c_str(), ";;#frac{lost}{accepted}", nTriggers_gl, 0, nTriggers_gl));
984  name = "trigger_changed_frac";
985  m_histo.emplace(name, new TH1F(name.c_str(), ";;#frac{changed}{all - accepted}", nTriggers_c, 0, nTriggers_c));
986  name = "module_changed";
987  m_histo.emplace(name, new TH1F(name.c_str(), ";;Events changed", nModules_c, 0, nModules_c));
988  name = "module_gained";
989  m_histo.emplace(name, new TH1F(name.c_str(), ";;Events gained", nModules_gl, 0, nModules_gl));
990  name = "module_lost";
991  m_histo.emplace(name, new TH1F(name.c_str(), ";;Events lost", nModules_gl, 0, nModules_gl));
992 
993  // Filling the per-trigger bins in the summary histograms
994  size_t bin(0), bin_c(0), bin_gl(0);
995  for (const auto& idSummary : m_triggerSummary) {
996  const TriggerSummary& summary = idSummary.second;
997  if (summary.accepted_o > 0) {
998  ++bin;
999  // Setting bin contents
1000  m_histo.at("trigger_accepted")->SetBinContent(bin, summary.accepted_o);
1001  // Setting bin labels
1002  m_histo.at("trigger_accepted")->GetXaxis()->SetBinLabel(bin, summary.name.c_str());
1003  }
1004  if (summary.keepForGL()) {
1005  ++bin_gl;
1006  // Setting bin contents
1007  m_histo.at("trigger_gained")->SetBinContent(bin_gl, summary.gained().v);
1008  m_histo.at("trigger_lost")->SetBinContent(bin_gl, -summary.lost().v);
1009  m_histo.at("trigger_gained_frac")->SetBinContent(bin_gl, summary.gained(1).v);
1010  m_histo.at("trigger_lost_frac")->SetBinContent(bin_gl, -summary.lost(1).v);
1011  // Setting bin errors
1012  m_histo.at("trigger_gained_frac")->SetBinError(bin_gl, summary.gained(1).e);
1013  m_histo.at("trigger_lost_frac")->SetBinError(bin_gl, -summary.lost(1).e);
1014  // Setting bin labels
1015  m_histo.at("trigger_gained")->GetXaxis()->SetBinLabel(bin_gl, summary.name.c_str());
1016  m_histo.at("trigger_lost")->GetXaxis()->SetBinLabel(bin_gl, summary.name.c_str());
1017  m_histo.at("trigger_gained_frac")->GetXaxis()->SetBinLabel(bin_gl, summary.name.c_str());
1018  m_histo.at("trigger_lost_frac")->GetXaxis()->SetBinLabel(bin_gl, summary.name.c_str());
1019  }
1020  if (summary.keepForC()) {
1021  ++bin_c;
1022  // Setting bin contents
1023  m_histo.at("trigger_changed")->SetBinContent(bin_c, summary.changed().v);
1024  m_histo.at("trigger_changed_frac")->SetBinContent(bin_c, summary.changed(1).v);
1025  // Setting bin errors
1026  m_histo.at("trigger_changed_frac")->SetBinError(bin_c, summary.changed(1).e);
1027  // Setting bin labels
1028  m_histo.at("trigger_changed")->GetXaxis()->SetBinLabel(bin_c, summary.name.c_str());
1029  m_histo.at("trigger_changed_frac")->GetXaxis()->SetBinLabel(bin_c, summary.name.c_str());
1030  }
1031  }
1032 
1033  // Filling the per-module bins in the summary histograms
1034  bin = 0;
1035  bin_c = 0;
1036  bin_gl = 0;
1037  for (const auto& idSummary : m_moduleSummary) {
1038  ++bin;
1039  const GenericSummary& summary = idSummary.second;
1040  if (summary.keepForGL()) {
1041  ++bin_gl;
1042  // Setting bin contents
1043  m_histo.at("module_gained")->SetBinContent(bin_gl, summary.gained().v);
1044  m_histo.at("module_lost")->SetBinContent(bin_gl, -summary.lost().v);
1045  // Setting bin labels
1046  m_histo.at("module_gained")->GetXaxis()->SetBinLabel(bin_gl, summary.name.c_str());
1047  m_histo.at("module_lost")->GetXaxis()->SetBinLabel(bin_gl, summary.name.c_str());
1048  }
1049  if (summary.keepForC()) {
1050  ++bin_c;
1051  // Setting bin contents
1052  m_histo.at("module_changed")->SetBinContent(bin_c, summary.changed().v);
1053  // Setting bin labels
1054  m_histo.at("module_changed")->GetXaxis()->SetBinLabel(bin_c, summary.name.c_str());
1055  }
1056  }
1057 
1058  // Styling the histograms
1059  for (const auto& nameHisto : m_histo) {
1060  const std::string name = nameHisto.first;
1061  TH1* histo = nameHisto.second;
1062  if (name.find("gained") != std::string::npos || name.find("changed") != std::string::npos) {
1063  if (name.find("frac") != std::string::npos)
1064  histo->GetYaxis()->SetRangeUser(0.0, 1.0);
1065  }
1066  if (name.find("lost") != std::string::npos) {
1067  if (name.find("frac") != std::string::npos)
1068  histo->GetYaxis()->SetRangeUser(-1.0, 0.0);
1069  }
1070  }
1071 
1072  // Storing histograms to a ROOT file
1073  std::string file_name = json.output_filename_base(this->run) += ".root";
1074  auto out_file = new TFile(file_name.c_str(), "RECREATE");
1075  // Storing the histograms in a proper folder according to the DQM convention
1076  char savePath[1000];
1077  sprintf(savePath, "DQMData/Run %d/HLT/Run summary/EventByEvent/", this->run);
1078  out_file->mkdir(savePath);
1079  gDirectory->cd(savePath);
1080  gDirectory->Write();
1081  for (const auto& nameHisto : m_histo)
1082  nameHisto.second->Write(nameHisto.first.c_str());
1083  out_file->Close();
1084 
1085  return file_name;
1086  }

References newFWLiteAna::bin, contentValuesCheck::file_name, timingPdfMaker::histo, SiStripPI::max, Skims_PA_cff::name, DeadROCCounter::out_file, AlCaHLTBitMon_QueryRunRegistry::string, and edmLumisInFiles::summary.

Member Data Documentation

◆ json

const JsonOutputProducer& SummaryOutputProducer::json
private

Definition at line 797 of file hltDiff.cc.

◆ m_moduleSummary

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

Definition at line 919 of file hltDiff.cc.

◆ m_triggerSummary

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

Definition at line 918 of file hltDiff.cc.

◆ run

int SummaryOutputProducer::run
private

◆ storeCSV

bool SummaryOutputProducer::storeCSV

Definition at line 1140 of file hltDiff.cc.

◆ storeROOT

bool SummaryOutputProducer::storeROOT

Definition at line 1139 of file hltDiff.cc.

mps_fire.i
i
Definition: mps_fire.py:355
JsonOutputProducer::JsonTriggerEventState::tr
int tr
Definition: hltDiff.cc:642
SummaryOutputProducer::TriggerSummary
Definition: hltDiff.cc:857
SummaryOutputProducer::writeCSV_trigger
std::string writeCSV_trigger() const
Definition: hltDiff.cc:1088
SummaryOutputProducer::storeROOT
bool storeROOT
Definition: hltDiff.cc:1139
gather_cfg.cout
cout
Definition: gather_cfg.py:144
SummaryOutputProducer::prepareSummaries
void prepareSummaries(const int _run, const std::vector< JsonOutputProducer::JsonEvent > &_events)
Definition: hltDiff.cc:921
SummaryOutputProducer::m_triggerSummary
std::map< int, TriggerSummary > m_triggerSummary
Definition: hltDiff.cc:918
timingPdfMaker.histo
histo
Definition: timingPdfMaker.py:279
JsonOutputProducer::JsonEventState::s
State s
Definition: hltDiff.cc:618
contentValuesCheck.file_name
file_name
Definition: contentValuesCheck.py:38
SummaryOutputProducer::GenericSummary
Definition: hltDiff.cc:817
JsonOutputProducer::JsonTriggerEventState::o
JsonEventState o
Definition: hltDiff.cc:643
corrVsCorr.filename
filename
Definition: corrVsCorr.py:123
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
SummaryOutputProducer::writeCSV_module
std::string writeCSV_module() const
Definition: hltDiff.cc:1117
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
JsonOutputProducer::JsonTriggerEventState
Definition: hltDiff.cc:641
edmLumisInFiles.summary
summary
Definition: edmLumisInFiles.py:39
DeadROCCounter.out_file
out_file
Definition: DeadROCCounter.py:50
SummaryOutputProducer::json
const JsonOutputProducer & json
Definition: hltDiff.cc:797
newFWLiteAna.bin
bin
Definition: newFWLiteAna.py:161
HLTObjectsMonitor_cfi.TriggerSummary
TriggerSummary
Definition: HLTObjectsMonitor_cfi.py:10
SummaryOutputProducer::run
int run
Definition: hltDiff.cc:798
SummaryOutputProducer::storeCSV
bool storeCSV
Definition: hltDiff.cc:1140
JsonOutputProducer::JsonTriggerEventState::n
JsonEventState n
Definition: hltDiff.cc:644
Fail
Definition: hltDiff.cc:245
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
S
Definition: CSCDBL1TPParametersExtended.h:16
SummaryOutputProducer::m_moduleSummary
std::map< int, GenericSummary > m_moduleSummary
Definition: hltDiff.cc:919
event
Definition: event.py:1
JsonOutputProducer::JsonEventState::l
int l
Definition: hltDiff.cc:620
SummaryOutputProducer::writeHistograms
std::string writeHistograms() const
Definition: hltDiff.cc:944
json
nlohmann::json json
Definition: FastTimerService.cc:19
JsonOutputProducer::JsonEvent
Definition: hltDiff.cc:659