6 #include "boost/format.hpp"
7 #include "FWCore/Framework/interface/Event.h"
8 #include "FWCore/Framework/interface/EventSetup.h"
9 #include "FWCore/Framework/interface/MakerMacros.h"
10 #include "FWCore/ParameterSet/interface/ParameterSet.h"
11 #include "FWCore/Utilities/interface/InputTag.h"
12 #include "DataFormats/Common/interface/Handle.h"
13 #include "FWCore/Common/interface/TriggerNames.h"
14 #include "DataFormats/Common/interface/TriggerResults.h"
15 #include "DataFormats/PatCandidates/interface/TriggerEvent.h"
16 #include "DataFormats/PatCandidates/interface/TriggerObjectStandAlone.h"
17 #include "PhysicsTools/PatUtils/interface/TriggerHelper.h"
18 #include "HLTrigger/HLTcore/interface/HLTConfigProvider.h"
27 const edm::ParameterSet& config)
28 : input_(config.getParameter<
edm::InputTag>(
"input")),
29 input_trigres_(config.getParameter<
edm::InputTag>(
"inputTriggerResults")),
30 branch_(config.getParameter<
std::string>(
"branch")),
31 hlt_path_(config.getParameter<
std::string>(
"hltPath")),
32 store_only_if_fired_(config.getParameter<bool>(
"storeOnlyIfFired")),
33 input_is_standalone_(config.getParameter<bool>(
"inputIsStandAlone")) {
34 if(!input_is_standalone_){
35 consumes<pat::TriggerEvent>(input_);
37 consumes<pat::TriggerObjectStandAloneCollection>(input_);
39 consumes<edm::TriggerResults>(input_trigres_);
40 objects_ =
new std::vector<ic::TriggerObject>();
42 std::cout << boost::format(
"%-15s : %-60s\n") %
"Path" % hlt_path_;
49 void ICTriggerObjectProducer::produce(edm::Event& event,
50 const edm::EventSetup& setup) {
53 if (!input_is_standalone_) {
54 edm::Handle<pat::TriggerEvent> trig_handle;
55 event.getByLabel(input_, trig_handle);
59 std::vector<pat::TriggerPath>
const* paths = trig_handle->paths();
63 bool path_found =
false;
64 std::string full_name;
65 for (
unsigned i = 0; i < paths->size(); ++i) {
66 std::string
const& name = paths->at(i).name();
67 if (name.find(hlt_path_) != name.npos) {
70 if (store_only_if_fired_ && !(paths->at(i).wasAccept())) fired =
false;
74 if (!fired || !path_found)
return;
77 pat::TriggerObjectRefVector objects =
78 trig_handle->pathObjects(full_name,
false);
80 for (
unsigned i = 0; i < objects.size(); ++i) {
81 pat::TriggerObject
const& src = *(objects.at(i));
88 std::vector<std::size_t> filter_labels;
91 pat::TriggerFilterRefVector filters =
92 trig_handle->objectFilters((objects)[i],
false);
93 for (
unsigned k = 0; k < filters.size(); ++k) {
95 if (!trig_handle->filterInPath(filters[k], full_name,
false))
continue;
96 filter_labels.push_back(
CityHash64(filters[k]->label()));
97 observed_filters_[filters[k]->label()] =
CityHash64(filters[k]->label());
107 unsigned n_types = std::min(std::size_t(4), src.triggerObjectTypes().size());
108 for (
unsigned t = 0; t < n_types; ++t) {
109 packed_type.four[t] = src.triggerObjectTypes()[t];
111 dest.
set_id(packed_type.one);
120 edm::Handle<edm::TriggerResults> trigres_handle;
121 event.getByLabel(input_trigres_, trigres_handle);
122 edm::TriggerNames
const& names =
event.triggerNames(*trigres_handle);
125 bool path_found =
false;
126 std::string full_name;
128 for (
unsigned int i = 0, n = trigres_handle->size(); i < n; ++i) {
129 std::string
const& name = names.triggerName(i);
131 if (name.find(hlt_path_) != name.npos) {
134 if (store_only_if_fired_ && !(trigres_handle->accept(i))) fired =
false;
138 if (!fired || !path_found)
return;
142 std::set<std::string> path_filters;
143 std::vector<std::string>
const& filt_vec =
144 hlt_config_.saveTagsModules(full_name);
145 for (
unsigned i = 0; i < filt_vec.size(); ++i)
146 path_filters.insert(filt_vec[i]);
148 edm::Handle<pat::TriggerObjectStandAloneCollection> trigobj_handle;
149 event.getByLabel(input_, trigobj_handle);
150 for (
unsigned i = 0; i < trigobj_handle->size(); ++i) {
151 pat::TriggerObjectStandAlone src = trigobj_handle->at(i);
152 #if CMSSW_MAJOR_VERSION >= 7
155 src.unpackPathNames(names);
157 std::vector<std::string>
const& pathnames = src.pathNames(
false,
false);
158 bool obj_in_path =
false;
159 for (
unsigned j = 0; j < pathnames.size(); ++j) {
160 if (full_name == pathnames[j]) {
165 if (!obj_in_path)
continue;
178 std::vector<std::string>
const& filters = src.filterLabels();
179 std::vector<std::size_t> filter_labels;
180 for (
unsigned k = 0; k < filters.size(); ++k) {
183 if (!path_filters.count(filters[k]))
continue;
184 filter_labels.push_back(
CityHash64(filters[k]));
185 observed_filters_[filters[k]] =
CityHash64(filters[k]);
195 unsigned n_types = std::min(std::size_t(4), src.triggerObjectTypes().size());
196 for (
unsigned t = 0; t < n_types; ++t) {
197 packed_type.four[t] = src.triggerObjectTypes()[t];
199 dest.
set_id(packed_type.one);
204 void ICTriggerObjectProducer::beginRun(edm::Run
const& run,
205 edm::EventSetup
const& es) {
206 if (input_is_standalone_) {
208 input_trigres_.process() !=
"" ? input_trigres_.process() :
"HLT";
210 bool res = hlt_config_.init(run, es, proc, changed);
212 throw std::runtime_error(
213 "HLTConfigProvider did not initialise correctly");
218 void ICTriggerObjectProducer::beginJob() {
222 void ICTriggerObjectProducer::endJob() {
223 std::cout << std::string(78,
'-') <<
"\n";
224 std::cout << boost::format(
"Path: %-50s %20s\n")
225 % hlt_path_ % std::string(
"Hash Summmary");
226 std::map<std::string, std::size_t>::const_iterator iter;
227 for (iter = observed_filters_.begin(); iter != observed_filters_.end();
230 std::cout << boost::format(
"%-56s| %020i\n") % iter->first % iter->second;
~ICTriggerObjectProducer()
uint64 CityHash64(const char *buf, size_t len)
ICTriggerObjectProducer(const edm::ParameterSet &)
void set_filters(std::vector< std::size_t > const &filters)
The list of filter label hashes this object was accepted by, typically restricted to the modules in s...
void set_phi(double const &phi)
Direct access to .
void set_id(std::size_t const &id)
Unique identifier.
void set_charge(int const &charge)
Electric charge.
void set_energy(double const &energy)
Direct access to the energy.
Stores the four-momentum of a trigger object as well as a list of the (hashed) filter labels the obje...
void set_pt(double const &pt)
Direct access to the .
void set_eta(double const &eta)
Direct access to .
DEFINE_FWK_MODULE(ICTriggerObjectProducer)
static void Add(std::size_t const &id, std::string const &str)