24 #include <boost/algorithm/string.hpp> 25 #include <boost/filesystem.hpp> 31 #include <TGraphAsymmErrors.h> 46 out <<
"Try 'hltDiff --help' for more information" << std::endl;
50 out << message << std::endl;
55 out << message << std::endl;
63 virtual unsigned int size()
const = 0;
64 virtual unsigned int size(
unsigned int trigger)
const = 0;
66 virtual unsigned int triggerIndex(
unsigned int trigger)
const = 0;
69 virtual bool prescaler(
unsigned int trigger,
unsigned int module)
const = 0;
80 for (
unsigned int t = 0;
t < data_.size(); ++
t) {
81 prescalers_[
t].resize(
size(
t));
82 moduleTypes_[
t].resize(
size(
t));
83 for (
unsigned int m = 0;
m < data_.size(
t); ++
m) {
85 prescalers_[
t][
m] = (type ==
"HLTPrescaler");
86 moduleTypes_[
t][
m] = &* moduleTypeSet_.insert(
std::move(type)).first;
92 return data_.processName();
95 unsigned int size()
const override {
100 return data_.size(trigger);
104 return data_.triggerNames();
108 return data_.triggerName(trigger);
116 return data_.moduleLabel(trigger, module);
120 return * moduleTypes_.at(trigger).at(module);
124 return prescalers_.at(trigger).at(module);
136 return state ?
"accepted" :
"rejected";
155 unsigned int size()
const override;
156 unsigned int size(
unsigned int trigger)
const override;
158 unsigned int triggerIndex(
unsigned int trigger)
const override;
161 bool prescaler(
unsigned int trigger,
unsigned int module)
const override;
172 firstView_(*this,
Index::First),
173 secondView_(*this,
Index::Second)
175 for (
unsigned int f = 0;
f < first.
size(); ++
f)
176 for (
unsigned int s = 0;
s < second.
size(); ++
s)
178 triggerIndices_.push_back(std::make_pair(
f,
s));
184 if (index == Index::First)
191 if (index == Index::First)
192 return first_.processName();
194 return second_.processName();
198 return triggerIndices_.size();
202 if (index == Index::First)
203 return first_.size(trigger);
205 return second_.size(trigger);
209 if (index == Index::First)
210 return first_.triggerName(triggerIndices_.at(trigger).first);
212 return second_.triggerName(triggerIndices_.at(trigger).second);
216 if (index == Index::First)
217 return triggerIndices_.at(trigger).first;
219 return triggerIndices_.at(trigger).second;
223 if (index == Index::First)
224 return first_.moduleLabel(triggerIndices_.at(trigger).first,
module);
226 return second_.moduleLabel(triggerIndices_.at(trigger).second,
module);
230 if (index == Index::First)
231 return first_.moduleType(triggerIndices_.at(trigger).first,
module);
233 return second_.moduleType(triggerIndices_.at(trigger).second,
module);
237 if (index == Index::First)
238 return first_.prescaler(triggerIndices_.at(trigger).first,
module);
240 return second_.prescaler(triggerIndices_.at(trigger).second,
module);
255 return config_.processName(index_);
259 return config_.size(index_);
263 return config_.size(index_, trigger);
267 return config_.triggerName(index_, trigger);
271 return config_.triggerIndex(index_, trigger);
275 return config_.moduleLabel(index_, trigger, module);
279 return config_.moduleType(index_, trigger, module);
283 return config_.prescaler(index_, trigger, module);
297 static const char *
message[] = {
"not run",
"accepted",
"rejected",
"exception",
"prescaled",
"invalid" };
299 if (state > 0 and state <
Invalid)
300 return message[state];
309 return (
State) state;
320 if (
std::count(s.begin(), s.end(),
':') == 2) {
322 size_t end = s.find_last_of(
':');
323 if (end > 0 and s.at(end-1) ==
':')
326 return s.substr(0, end);
340 out <<
" by module " << module <<
" '" <<
label <<
"' [" <<
type <<
"]";
342 out <<
" at module " << module <<
" '" <<
label <<
"' [" << type <<
"]";
351 out <<
" not found\n";
361 for (
unsigned int i = 0;
i < summary.
filterKeys(index).size(); ++
i) {
366 <<
"filter id: " <<
id <<
", " 367 <<
"object id: " << candidate.
id() <<
", " 368 <<
"pT: " << candidate.
pt() <<
", " 369 <<
"eta: " << candidate.
eta() <<
", " 370 <<
"phi: " << candidate.
phi() <<
", " 371 <<
"mass: " << candidate.
mass() <<
"\n";
379 out <<
" not found\n";
396 <<
"object id: " << candidate.
id() <<
", " 397 <<
"pT: " << candidate.
pt() <<
", " 398 <<
"eta: " << candidate.
eta() <<
", " 399 <<
"phi: " << candidate.
phi() <<
", " 400 <<
"mass: " << candidate.
mass() <<
"\n";
406 std::vector<boost::iterator_range<std::string::const_iterator>> tokens;
407 boost::split(tokens, branch, boost::is_any_of(
"_."), boost::token_compress_off);
408 return boost::copy_range<std::string>(tokens[3]);
412 auto const & history =
event.processHistory();
413 if (process.empty()) {
420 if (not history.getConfigurationForProcess(process, config)) {
421 std::cerr <<
"error: the process " << process <<
" is not in the Process History" << std::endl;
425 if (pset ==
nullptr) {
426 std::cerr <<
"error: the configuration for the process " << process <<
" is not available in the Provenance" << std::endl;
429 return std::make_unique<HLTConfigDataEx>(
HLTConfigData(pset));
439 unsigned int internal;
447 memset(buffer, 0, 12);
449 unsigned int digit = 10;
451 buffer[digit] = value % 10 + 48;
455 buffer[digit] =
sign;
461 return this->gained + this->lost + this->
internal;
466 out << std::setw(12) << diff.
count 483 int nSpaces = tab_spaces;
512 str.append(std::to_string(_int));
519 str.insert(1, _string);
527 for (
auto it = _values.begin(); it != _values.end(); ++it) {
532 if (it != --_values.end()) str.push_back(
',');
552 std::ostringstream
json;
554 json << key_string(
"file_base", file_base) <<
',';
556 json <<
key(
"files") << list_string(files) <<
',';
558 json << key_string(
"process", process) <<
',';
560 json <<
key(
"skipped_triggers") << list_string(skipped_triggers);
568 for (
size_t i = 0;
i < file0.length(); ++
i) {
569 bool identicalInAll =
true;
570 char character = file0.at(
i);
572 if (
file.at(
i) == character)
continue;
573 identicalInAll =
false;
576 if (!identicalInAll)
break;
577 file_base.push_back(character);
579 const unsigned int file_base_len = file_base.length();
580 if (file_base_len < 1)
return;
583 file.erase(0, file_base_len);
597 std::ostringstream
json;
598 json <<
indent(_indent) <<
key(
"configuration") <<
'{';
599 json <<
indent(_indent+1) <<
key(
"o") <<
'{';
601 json <<
indent(_indent+1) <<
"},";
602 json <<
indent(_indent+1) <<
key(
"n") <<
'{';
604 json <<
indent(_indent+1) <<
"},";
605 std::string prescales_str = prescales ?
"true" :
"false";
606 json <<
indent(_indent+1) <<
key(
"prescales") << prescales_str <<
',';
608 json <<
indent(_indent) <<
"}";
624 std::ostringstream
json;
625 json <<
indent(_indent) <<
key(
"vars") <<
'{';
626 json <<
indent(_indent+1) <<
key(
"state") << list_string(state) <<
',';
627 json <<
indent(_indent+1) <<
key(
"trigger") << list_string(trigger) <<
',';
628 json <<
indent(_indent+1) <<
key(
"trigger_passed_count") <<
'[';
629 for (
auto it = trigger_passed_count.begin(); it != trigger_passed_count.end(); ++it) {
630 json <<
'{' <<
key(
"o") << (*it).first <<
',' <<
key(
"n") << (*it).second <<
'}';
631 if (it != trigger_passed_count.end()-1)
635 json <<
indent(_indent+1) <<
key(
"label") << list_string(label) <<
',';
636 json <<
indent(_indent+1) <<
key(
"type") << list_string(type);
637 json <<
indent(_indent) <<
'}';
642 JsonVars() : state(0), trigger(0), trigger_passed_count(0), label(0), type(0) {}
652 if (
id < vars.
label.size())
654 vars.
label.push_back(labelName);
655 return vars.
label.size()-1;
660 if (
id < vars.
type.size())
662 vars.
type.push_back(typeName);
663 return vars.
type.size()-1;
674 std::ostringstream
json;
675 json << key_int(
"s",
int(s));
679 json << key_int(
"m", m) <<
',';
680 json << key_int(
"l", l) <<
',';
681 json << key_int(
"t", t);
696 std::ostringstream
json;
697 json <<
indent(_indent) << key_int(
"t", tr) <<
',';
715 std::ostringstream
json;
716 json <<
indent(_indent) <<
'{' <<
"\"r\"" <<
':' << run <<
",\"l\":" << lumi <<
",\"e\":" <<
event <<
",\"t\":[";
717 for (
auto it = triggerStates.begin(); it != triggerStates.end(); ++it) {
719 json << (*it).serialise(_indent+2);
720 json <<
indent(_indent+1) <<
'}';
721 if (it != --triggerStates.end()) json <<
',';
723 json <<
indent(_indent) <<
']' <<
'}';
729 run(_run), lumi(_lumi), event(_event), triggerStates(0) { }
733 if (triggerStates.size() > 0) {
735 if (lastTrigger.
tr == _tr)
739 return triggerStates.back();
749 writeJson(_writeJson),
750 out_filename_base(
std::
move(_file_name)) {
751 useSingleOutFile = out_filename_base.length() > 0;
756 if ( (m_run_events.count(_run) == 0 && !useSingleOutFile) || m_run_events.size() == 0 )
757 m_run_events.emplace(_run, std::vector<JsonEvent>());
758 std::vector<JsonEvent>& v_events = useSingleOutFile ? m_run_events.begin()->second : m_run_events.at(_run);
760 if (v_events.size() > 0) {
762 if (lastEvent.
run == _run && lastEvent.
lumi == _lumi && lastEvent.
event == _event)
765 v_events.push_back(
JsonEvent(_run, _lumi, _event));
766 return v_events.back();
770 return JsonEventState(_s, _m, this->labelId(_l), this->typeId(_t));
774 if (useSingleOutFile)
775 return out_filename_base;
778 sprintf(name,
"DQM_V0001_R%.9d__OLD_%s__NEW_%s_DQM", _run, configuration.
o.
process.c_str(), configuration.
n.
process.c_str());
784 if (!writeJson)
return;
785 std::set<std::string> filesCreated;
786 std::ofstream out_file;
787 if (m_run_events.size() > 0) {
789 for (
const auto& runEvents : m_run_events) {
790 const int run = runEvents.first;
791 const std::vector<JsonEvent>& v_events = runEvents.second;
793 std::string output_name = output_filename_base(run)+=
".json";
796 out_file << configuration.
serialise(1) <<
',';
799 out_file <<
indent(1) <<
key(
"events") <<
'[';
800 for (
auto it = v_events.begin(); it != v_events.end(); ++it) {
801 out_file << (*it).serialise(2);
802 if (it != --v_events.end()) out_file <<
',';
804 out_file <<
indent(1) <<
']';
805 out_file <<
indent(0) <<
"}";
808 filesCreated.insert(output_name);
812 std::string output_name = output_filename_base(0)+=
".json";
815 out_file << configuration.
serialise(1) <<
',';
818 out_file <<
indent(1) <<
key(
"events") <<
'[';
823 out_file <<
indent(1) <<
']';
824 out_file <<
indent(0) <<
"}";
827 filesCreated.insert(output_name);
830 if (filesCreated.size() > 0) {
831 std::cout <<
"Created the following JSON files:" << std::endl;
850 Pair(
double _v,
double _e) : v(_v), e(_e) {};
851 Pair(
int _v,
int _e) : v(_v), e(_e) {};
859 Event(
int _run,
int _lumi,
int _event) : run(_run), lumi(_lumi), event(_event) {};
861 return std::tie(run, lumi, event) < std::tie(b.
run, b.
lumi, b.
event);
876 name = _names.at(
id);
882 int moduleId = state.
o.
l;
884 moduleId = state.
n.
l;
885 v_lost.insert(
event);
888 v_gained.insert(
event);
891 v_changed.insert(
event);
898 return Pair(
double(v_gained.size()),
sqrt(
double(v_gained.size()) ) );
902 return Pair(
double(v_lost.size()),
sqrt(
double(v_lost.size()) ) );
906 return Pair(
double(v_changed.size()),
sqrt(
double(v_changed.size()) ) );
910 return v_changed.size() > 0;
914 return v_gained.size() > 0 || v_lost.size() > 0;
925 accepted_o(_json.vars.trigger_passed_count.at(
id).
first),
926 accepted_n(_json.vars.trigger_passed_count.at(
id).
second) {}
931 if (m_modules.count(moduleLabelId) == 0)
932 m_modules.emplace(moduleLabelId,
GenericSummary(moduleLabelId, json, _moduleNames));
933 m_modules.at(moduleLabelId).addEntry(_event, _triggerIndex);
937 Pair gained( GenericSummary::gained() );
938 if (
type == 0)
return gained;
939 double all( accepted_n );
943 return Pair( fraction.
v / (fraction.
e + 1
e-10), 0.0 );
947 Pair lost( GenericSummary::lost() );
948 if (
type == 0)
return lost;
949 double all( accepted_o );
953 return Pair( fraction.
v / (fraction.
e + 1
e-10), 0.0 );
957 Pair changed( GenericSummary::changed() );
958 if (
type == 0)
return changed;
963 return Pair( fraction.
v / (fraction.
e + 1
e-10), 0.0 );
971 void prepareSummaries(
const int _run,
const std::vector<JsonOutputProducer::JsonEvent>& _events) {
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)
980 for (
size_t i=0;
i<nModules; ++
i)
985 for (
size_t iTrigger = 0; iTrigger <
event.triggerStates.size(); ++iTrigger) {
989 m_moduleSummary.at(moduleId).addEntry(
event, iTrigger);
995 std::map<std::string, TH1*> m_histo;
998 int nTriggers(0), nTriggers_c(0), nTriggers_gl(0), nModules_c(0), nModules_gl(0);
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;
1005 for (
const auto& idSummary : m_moduleSummary) {
1006 if (idSummary.second.keepForGL()) ++nModules_gl;
1007 if (idSummary.second.keepForC()) ++nModules_c;
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);
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));
1039 size_t bin(0), bin_c(0), bin_gl(0);
1040 for (
const auto& idSummary : m_triggerSummary) {
1045 m_histo.at(
"trigger_accepted")->SetBinContent(
bin, summary.
accepted_o);
1047 m_histo.at(
"trigger_accepted")->GetXaxis()->SetBinLabel(
bin, summary.
name.c_str());
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);
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);
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());
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);
1071 m_histo.at(
"trigger_changed_frac")->SetBinError(bin_c, summary.
changed(1).
e);
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());
1082 for (
const auto& idSummary : m_moduleSummary) {
1088 m_histo.at(
"module_gained")->SetBinContent(bin_gl, summary.
gained().
v);
1089 m_histo.at(
"module_lost")->SetBinContent(bin_gl, -summary.
lost().
v);
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());
1097 m_histo.at(
"module_changed")->SetBinContent(bin_c, summary.
changed().
v);
1099 m_histo.at(
"module_changed")->GetXaxis()->SetBinLabel(bin_c, summary.
name.c_str());
1104 for (
const auto& nameHisto : m_histo) {
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);
1111 if (name.find(
"lost") != std::string::npos) {
1112 if (name.find(
"frac") != std::string::npos)
1113 histo->GetYaxis()->SetRangeUser(-1.0, 0.0);
1119 auto out_file =
new TFile(file_name.c_str(),
"RECREATE");
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());
1135 FILE* out_file = fopen((file_name).c_str(),
"w");
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) {
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());
1151 FILE* out_file = fopen((file_name).c_str(),
"w");
1153 fprintf(out_file,
"Total,Gained,Lost,Changed,module\n");
1154 for (
const auto& idSummary : m_moduleSummary) {
1156 fprintf(out_file,
"%d,+%.f,-%.f,~%.f,%s\n",
1172 storeROOT(_storeROOT),
1173 storeCSV(_storeCSV) {}
1176 std::vector<std::string> filesCreated;
1180 prepareSummaries(runEvents.first, runEvents.second);
1182 filesCreated.push_back(writeHistograms());
1185 filesCreated.push_back(writeCSV_trigger());
1186 filesCreated.push_back(writeCSV_module());
1191 filesCreated.push_back(writeHistograms());
1194 filesCreated.push_back(writeCSV_trigger());
1195 filesCreated.push_back(writeCSV_module());
1199 if (filesCreated.size() > 0) {
1200 std::cout <<
"Created the following summary files:" << std::endl;
1210 std::unique_ptr<TFile>
f(TFile::Open(file.c_str()));
1211 return (f and not f->IsZombie());
1217 for (
auto const &
file: files)
1220 std::cerr <<
"hltDiff: error: file " <<
file <<
" does not exist, or is not a regular file." << std::endl;
1250 ignore_prescales(
true),
1261 std::shared_ptr<fwlite::ChainEvent> old_events;
1262 std::shared_ptr<fwlite::ChainEvent> new_events;
1265 old_events = std::make_shared<fwlite::ChainEvent>(old_files);
1269 if (new_files.size() == 1 and new_files[0] ==
"-")
1270 new_events = old_events;
1272 new_events = std::make_shared<fwlite::ChainEvent>(new_files);
1290 std::unique_ptr<HLTConfigDataEx> old_config_data;
1291 std::unique_ptr<HLTConfigDataEx> new_config_data;
1292 std::unique_ptr<HLTCommonConfig> common_config;
1298 unsigned int affected = 0;
1299 bool new_run =
true;
1300 std::vector<TriggerDiff> differences;
1304 const unsigned int counter_denominator =
std::max(1,
int(nEvents/10));
1305 for (old_events->toBegin(); not old_events->atEnd(); ++(*old_events)) {
1307 if (counter%(counter_denominator) == 0) {
1308 std::cout <<
"Processed events: " << counter <<
" out of " << nEvents
1309 <<
" (" << 10*counter/(counter_denominator) <<
"%)" << std::endl;
1314 if (new_events != old_events and not new_events->to(
id)) {
1316 std::cerr <<
"run " <<
id.run() <<
", lumi " <<
id.luminosityBlock() <<
", event " <<
id.event() <<
": not found in the 'new' files, skipping." << std::endl;
1326 old_results = old_results_h.
product();
1329 std::cerr <<
"run " <<
id.run() <<
", lumi " <<
id.luminosityBlock() <<
", event " <<
id.event() <<
": 'old' TriggerResults not found, skipping." << std::endl;
1335 old_summary_h.
getByLabel<
fwlite::Event>(* old_events->event(),
"hltTriggerSummaryAOD",
"", old_process.c_str());
1337 old_summary = old_summary_h.
product();
1343 new_results = new_results_h.
product();
1346 std::cerr <<
"run " <<
id.run() <<
", lumi " <<
id.luminosityBlock() <<
", event " <<
id.event() <<
": 'new' TriggerResults not found, skipping." << std::endl;
1352 new_summary_h.
getByLabel<
fwlite::Event>(* new_events->event(),
"hltTriggerSummaryAOD",
"", new_process.c_str());
1354 new_summary = new_summary_h.
product();
1359 old_events->fillParameterSetRegistry();
1360 new_events->fillParameterSetRegistry();
1364 if (new_config_data->triggerNames() == old_config_data->triggerNames()) {
1365 old_config = old_config_data.get();
1366 new_config = new_config_data.get();
1368 common_config = std::make_unique<HLTCommonConfig>(*old_config_data, *new_config_data);
1371 std::cout <<
"Warning: old and new TriggerResults come from different HLT menus. Only the common " << old_config->size() <<
" triggers are compared.\n" << std::endl;
1374 differences.clear();
1375 differences.resize(old_config->
size());
1378 std::vector<std::string> states_str;
1382 for (
size_t triggerId = 0; triggerId < old_config->
size(); ++triggerId) {
1387 for (
auto const & it : old_config_data->triggerNames()) {
1392 for (
auto const & it : new_config_data->triggerNames()) {
1399 bool needs_header =
true;
1400 bool event_affected =
false;
1401 for (
unsigned int p = 0;
p < old_config->
size(); ++
p) {
1408 if (old_state ==
Pass) {
1409 ++differences.at(
p).count;
1411 if (old_state ==
Pass)
1413 if (new_state ==
Pass)
1416 bool trigger_affected =
false;
1418 if (old_state ==
Pass and new_state !=
Pass) {
1419 ++differences.at(
p).lost;
1420 trigger_affected =
true;
1421 }
else if (old_state !=
Pass and new_state ==
Pass) {
1422 ++differences.at(
p).gained;
1423 trigger_affected =
true;
1424 }
else if (old_results->
index(old_index) != new_results->
index(new_index)) {
1425 ++differences.at(
p).internal;
1426 trigger_affected =
true;
1430 if (not trigger_affected)
continue;
1432 event_affected =
true;
1433 const unsigned int old_moduleIndex = old_results->
index(old_index);
1434 const unsigned int new_moduleIndex = new_results->
index(new_index);
1443 needs_header =
false;
1444 std::cout <<
"run " <<
id.run() <<
", lumi " <<
id.luminosityBlock() <<
", event " <<
id.event() <<
": " 1451 <<
" old state is ";
1454 <<
" new state is ";
1458 if (verbose > 1 and old_summary and new_summary) {
1460 unsigned int module =
std::min(old_moduleIndex, new_moduleIndex);
1462 std::cout <<
" old trigger candidates:\n";
1464 std::cout <<
" new trigger candidates:\n";
1474 if (event_affected and verbose > 2 and old_summary and new_summary) {
1475 std::map<std::string, std::pair<std::string, std::string>> collections;
1478 for (
auto const & new_collection: new_summary->collectionTags())
1483 std::cout <<
" old trigger candidates:\n";
1485 std::cout <<
" new trigger candidates:\n";
1492 if (nEvents and counter >= nEvents)
1499 std::cout <<
"There are no common events between the old and new files";
1501 std::cout <<
", " << skipped <<
" events were skipped";
1504 std::cout <<
"Found " << counter <<
" matching events, out of which " << affected <<
" have different HLT results";
1506 std::cout <<
", " << skipped <<
" events were skipped";
1511 bool summaryHeaderPrinted =
false;
1512 for (
size_t p = 0;
p < old_config->
size(); ++
p) {
1513 if (differences.at(
p).total() < 1)
continue;
1514 if (!summaryHeaderPrinted)
1515 std::cout << std::setw(12) <<
"Events" << std::setw(12) <<
"Accepted" << std::setw(12) <<
"Gained" << std::setw(12) <<
"Lost" << std::setw(12) <<
"Other" <<
" " <<
"Trigger" << std::endl;
1516 std::cout << std::setw(12) << counter << differences.at(
p) <<
" " << old_config->
triggerName(
p) << std::endl;
1517 summaryHeaderPrinted =
true;
1529 usage: hltDiff -o|--old-files FILE1.ROOT [FILE2.ROOT ...] [-O|--old-process LABEL[:INSTANCE[:PROCESS]]]\n\ 1530 -n|--new-files FILE1.ROOT [FILE2.ROOT ...] [-N|--new-process LABEL[:INSTANCE[:PROCESS]]]\n\ 1531 [-m|--max-events MAXEVENTS] [-p|--prescales] [-c|--csv-output] [-j|--json-output]\n\ 1532 [-r|--root-output] [-f|--file-check] [-d|--debug] [-q|--quiet] [-v|--verbose]\n\ 1533 [-h|--help] [-F|--output-file] FILE_NAME\n\ 1535 -o|--old-files FILE1.ROOT [FILE2.ROOT ...]\n\ 1536 input file(s) with the old (reference) trigger results\n\ 1538 -O|--old-process PROCESS\n\ 1539 process name of the collection with the old (reference) trigger results\n\ 1540 default: take the 'TriggerResults' from the last process\n\ 1542 -n|--new-files FILE1.ROOT [FILE2.ROOT ...]\n\ 1543 input file(s) with the new trigger results to be compared with the reference\n\ 1544 to read these from a different collection in the same files as\n\ 1545 the reference, use '-n -' and specify the collection with -N (see below)\n\ 1547 -N|--new-process PROCESS\n\ 1548 process name of the collection with the new (reference) trigger results\n\ 1549 default: take the 'TriggerResults' from the last process\n\ 1551 -m|--max-events MAXEVENTS\n\ 1552 compare only the first MAXEVENTS events\n\ 1553 default: compare all the events in the original (reference) files\n\ 1556 do not ignore differences caused by HLTPrescaler modules\n\ 1559 produce comparison results in a CSV format\n\ 1562 produce comparison results in a JSON format\n\ 1565 produce comparison results as histograms in a ROOT file\n\ 1567 -F|--output-file FILE_NAME\n\ 1568 combine all RUNs to files with the specified custom name: FILE_NAME.json, FILE_NAME.root\n\ 1569 default: a separate output file will be produced for each RUN with names suitable for the DQM GUI\n\ 1572 check existence of every old and new file before running the comparison\n\ 1573 safer if files are run for the first time, but can cause a substantial delay\n\ 1576 display messages about missing events and collectiions\n\ 1579 don't display summary printout with the list of affected trigger paths\n\ 1581 -v|--verbose LEVEL\n\ 1582 set verbosity level:\n\ 1583 1: event-by-event comparison results\n\ 1584 2: + print the trigger candidates of the affected filters\n\ 1585 3: + print all the trigger candidates for the affected events\n\ 1589 print this help message, and exit" << std::endl;
1597 const char optstring[] =
"dfo:O:n:N:m:pcjrF:v::hq";
1598 const option longopts[] = {
1599 option{
"debug", no_argument,
nullptr,
'd' },
1600 option{
"file-check", no_argument,
nullptr,
'f' },
1601 option{
"old-files", required_argument,
nullptr,
'o' },
1602 option{
"old-process", required_argument,
nullptr,
'O' },
1603 option{
"new-files", required_argument,
nullptr,
'n' },
1604 option{
"new-process", required_argument,
nullptr,
'N' },
1605 option{
"max-events", required_argument,
nullptr,
'm' },
1606 option{
"prescales", no_argument,
nullptr,
'p' },
1607 option{
"csv-output", optional_argument,
nullptr,
'c' },
1608 option{
"json-output", optional_argument,
nullptr,
'j' },
1609 option{
"root-output", optional_argument,
nullptr,
'r' },
1610 option{
"output-file", optional_argument,
nullptr,
'F' },
1611 option{
"verbose", optional_argument,
nullptr,
'v' },
1612 option{
"help", no_argument,
nullptr,
'h' },
1613 option{
"quiet", no_argument,
nullptr,
'q' },
1621 while ((c = getopt_long(argc, argv, optstring, longopts,
nullptr)) != -1) {
1628 hlt->file_check =
true;
1632 hlt->old_files.emplace_back(optarg);
1633 while (optind < argc) {
1634 if (argv[optind][0] ==
'-')
1636 hlt->old_files.emplace_back(argv[optind]);
1642 hlt->old_process = optarg;
1646 hlt->new_files.emplace_back(optarg);
1647 while (optind < argc) {
1648 if (argv[optind][0] ==
'-')
1650 hlt->new_files.emplace_back(argv[optind]);
1656 hlt->new_process = optarg;
1660 hlt->max_events = atoi(optarg);
1664 hlt->ignore_prescales =
false;
1668 hlt->csv_out =
true;
1672 hlt->json_out =
true;
1676 hlt->root_out =
true;
1680 hlt->output_file = optarg;
1687 }
else if (!optarg &&
nullptr != argv[optind] &&
'-' != argv[optind][0]) {
1689 const char *tmp_optarg = argv[optind++];
1710 if (
hlt->old_files.empty()) {
1714 if (
hlt->new_files.empty()) {
unsigned int typeId(std::string typeName)
std::string const & processName() const override
unsigned int total() const
JsonEvent & pushEvent(int _run, int _lumi, int _event)
std::string const & processName() const override
static std::string indent(size_t _nTabs)
virtual unsigned int triggerIndex(unsigned int trigger) const =0
std::set< std::string > moduleTypeSet_
std::vector< std::pair< unsigned int, unsigned int > > triggerIndices_
std::string const & moduleLabel(Index index, unsigned int trigger, unsigned int module) const
std::map< int, GenericSummary > m_modules
std::map< int, std::vector< JsonEvent > > m_run_events
unsigned int labelId(std::string labelName)
bool check_files(std::vector< std::string > const &files)
const std::vector< std::string > & collectionTags() const
The single EDProduct to be saved for each event (AOD case)
trigger::size_type sizeFilters() const
std::string const & moduleLabel(unsigned int trigger, unsigned int module) const override
virtual std::string const & processName() const =0
void print_trigger_candidates(std::ostream &out, trigger::TriggerEvent const &summary, edm::InputTag const &filter)
virtual std::string const & moduleLabel(unsigned int trigger, unsigned int module) const =0
std::string const & moduleType(unsigned int trigger, unsigned int module) const override
unsigned int size(Index index, unsigned int trigger) const
trigger::size_type collectionKey(trigger::size_type index) const
std::string const & triggerName(unsigned int trigger) const override
std::vector< std::string > skipped_triggers
std::string serialise(size_t _indent=0) const
std::vector< std::vector< std::string const * > > moduleTypes_
Pair gained(int type=0) const
const JsonOutputProducer & json
bool accept() const
Has at least one path accepted the event?
std::string writeCSV_module() const
const Keys & filterKeys(trigger::size_type index) const
View(HLTCommonConfig const &config, HLTCommonConfig::Index index)
std::string const & moduleLabel(unsigned int trigger, unsigned int module) const override
trigger::size_type filterIndex(const edm::InputTag &filterTag) const
find index of filter in data-member vector from filter tag
Pair changed(int type=0) const
JsonOutputProducer(bool _writeJson, std::string _file_name)
TriggerSummary(int _id, const JsonOutputProducer &_json)
void print_detailed_path_state(std::ostream &out, State state, int path, int module, HLTConfigInterface const &config)
std::vector< std::pair< int, int > > trigger_passed_count
std::string serialise(size_t _indent=0) const
GenericSummary(int _id, const JsonOutputProducer &_json, const std::vector< std::string > &_names)
const char * event_state(bool state)
void prepareSummaries(const int _run, const std::vector< JsonOutputProducer::JsonEvent > &_events)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
JsonTriggerEventState & pushTrigger(int _tr)
std::vector< JsonTriggerEventState > triggerStates
std::vector< std::string > label
HLTCommonConfig(HLTConfigDataEx const &first, HLTConfigDataEx const &second)
virtual std::vector< std::string > const & triggerNames() const
Single trigger physics object (e.g., an isolated muon)
U second(std::pair< T, U > const &p)
static std::string format(unsigned int value, char sign= '+')
void getByLabel(const P &iP, const char *iModuleLabel, const char *iProductInstanceLabel=0, const char *iProcessLabel=0)
std::map< int, GenericSummary > m_moduleSummary
std::vector< std::string > old_files
static std::string string(const std::string &_string, const std::string &_delim="")
bool prescaler(unsigned int trigger, unsigned int module) const override
JsonEventState eventState(State _s, int _m, const std::string &_l, const std::string &_t)
State prescaled_state(int state, int path, int module, HLTConfigInterface const &config)
const JsonOutputProducer & json
const Vids & filterIds(trigger::size_type index) const
def addEntry(schema, datatableName, entryinfo, branchinfo)
ParameterSetID const & parameterSetID() const
bool operator<(const FedChannelConnection &, const FedChannelConnection &)
std::string output_filename_base(int _run) const
Pair(double _v, double _e)
int addEntry(const JsonOutputProducer::JsonEvent &_event, const int _triggerIndex)
HLTConfigDataEx const & second_
std::unique_ptr< HLTConfigDataEx > getHLTConfigData(fwlite::EventBase const &event, std::string process)
std::string const & moduleType(unsigned int trigger, unsigned int module) const override
const TriggerObjectCollection & getObjects() const
JsonEvent(int _run, int _lumi, int _event)
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Event(int _run, int _lumi, int _event)
unsigned int index(const unsigned int i) const
Get index (slot position) of module giving the decision of the ith path.
std::vector< std::string > new_files
std::string serialise(size_t _indent=0) const
virtual std::string const & moduleType(unsigned int trigger, unsigned int module) const =0
static std::string key_int(const std::string &_key, int _int, const std::string &_delim="")
std::map< int, TriggerSummary > m_triggerSummary
std::string getProcessNameFromBranch(std::string const &branch)
HLTCommonConfig const & config_
std::set< Event > v_changed
std::vector< std::string > trigger
bool getMapped(key_type const &k, value_type &result) const
std::string out_filename_base
std::string strip_process_name(std::string const &s)
std::string serialise(size_t _indent=0) const
unsigned int size(Index index) const
static std::string list_string(const std::vector< std::string > &_values, const std::string &_delim="")
void addEntry(const JsonOutputProducer::JsonEvent &_event, const int _triggerIndex, const std::vector< std::string > &_moduleNames)
unsigned int size() const override
std::string const & triggerName(unsigned int trigger) const override
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
void error(std::ostream &out)
void print_trigger_collection(std::ostream &out, trigger::TriggerEvent const &summary, std::string const &tag)
bool prescaler(unsigned int trigger, unsigned int module) const override
unsigned int triggerIndex(unsigned int trigger) const override
HLTConfigDataEx(HLTConfigData data)
int main(int argc, char **argv)
bin
set the eta bin as selection string.
unsigned int triggerIndex(Index index, unsigned int trigger) const
unsigned int triggerIndex(unsigned int trigger) const override
std::vector< std::string > state
std::vector< std::string > files
std::ostream & operator<<(std::ostream &out, TriggerDiff diff)
std::string serialise(size_t _indent=0) const
std::string writeHistograms() const
SummaryOutputProducer(const JsonOutputProducer &_json, bool _storeROOT, bool _storeCSV)
double S(const TLorentzVector &, const TLorentzVector &)
std::set< Event > v_gained
const char * path_state(State state)
unsigned int size(unsigned int trigger) const override
HLTConfigDataEx const & first_
bool check_file(std::string const &file)
virtual unsigned int size() const =0
char data[epos_bytes_allocation]
std::string serialise(size_t _indent=0) const
static std::atomic< unsigned int > counter
virtual std::string const & triggerName(unsigned int trigger) const =0
std::vector< std::string > type
std::string const & moduleType(Index index, unsigned int trigger, unsigned int module) const
bool prescaler(Index index, unsigned int trigger, unsigned int module) const
std::string const & processName(Index index) const
T const * product() const
View const & getView(Index index) const
std::vector< std::vector< bool > > prescalers_
std::string const & triggerName(Index index, unsigned int trigger) const
virtual bool prescaler(unsigned int trigger, unsigned int module) const =0
Pair lost(int type=0) const
JsonConfiguration configuration
unsigned int size() const override
JsonTriggerEventState(int _tr)
JsonEventState(State _s, int _m, int _l, int _t)
static Registry * instance()
hlt::HLTState state(const unsigned int i) const
Get status of ith path.
static std::string key(const std::string &_key, const std::string &_delim="")
std::string writeCSV_trigger() const
static std::string key_string(const std::string &_key, const std::string &_string, const std::string &_delim="")
void usage(std::ostream &out) const