56 #include "boost/algorithm/string.hpp"
59 std::vector<std::regex> convertToRegex(std::vector<std::string>
const& iPatterns) {
60 std::vector<std::regex>
result;
62 for (
auto const&
pattern : iPatterns) {
64 boost::replace_all(regexPattern,
"*",
".*");
65 boost::replace_all(regexPattern,
"?",
".");
67 result.emplace_back(regexPattern);
77 : throw_(ps.getParameter<
bool>(
"throw")),
78 pn_(ps.getParameter<
std::
string>(
"processName")),
79 moduleLabelPatternsToMatch_(
80 convertToRegex(ps.getParameter<
std::
vector<
std::
string>>(
"moduleLabelPatternsToMatch"))),
81 moduleLabelPatternsToSkip_(
82 convertToRegex(ps.getParameter<
std::
vector<
std::
string>>(
"moduleLabelPatternsToSkip"))) {
88 edm::LogError(
"TriggerSummaryProducerAOD") <<
"HLT Error: TriggerNamesService not available!";
92 LogDebug(
"TriggerSummaryProducerAOD") <<
"Using process name: '" <<
pn_ <<
"'";
94 produces<trigger::TriggerEvent>();
96 auto const* pProcessName = &
pn_;
101 if (iBranch.processName() == *pProcessName || *pProcessName ==
"*") {
102 auto const&
label = iBranch.moduleLabel();
107 if (std::regex_match(
label, reject)) {
178 const char token(
':');
183 if (
i1 == string::npos) {
190 if (
i2 == string::npos) {
202 desc.add<
bool>(
"throw",
false)->setComment(
"Throw exception or LogError");
205 "Process name to use when getting data. The value of '@' is used to denote the current process name.");
206 desc.add<std::vector<std::string>>(
"moduleLabelPatternsToMatch", std::vector<std::string>(1,
"hlt*"))
207 ->setComment(
"glob patterns for module labels to get data.");
208 desc.add<std::vector<std::string>>(
"moduleLabelPatternsToSkip", std::vector<std::string>())
209 ->setComment(
"module labels for data products which should not be gotten.");
210 descriptions.
add(
"triggerSummaryProducerAOD",
desc);
217 using namespace reco;
222 std::vector<edm::Handle<trigger::TriggerFilterObjectWithRefs>> fobs;
225 const unsigned int nfob(fobs.size());
226 LogTrace(
"TriggerSummaryProducerAOD") <<
"Number of filter objects found: " << nfob;
228 string tagLabel, tagInstance, tagProcess;
235 std::vector<bool> maskFilters;
236 maskFilters.resize(nfob);
241 for (
unsigned int ifob = 0; ifob != nfob; ++ifob) {
242 maskFilters[ifob] =
false;
243 const vector<string>& collectionTags_(fobs[ifob]->getCollectionTagsAsStrings());
244 const unsigned int ncol(collectionTags_.size());
247 maskFilters[ifob] =
true;
249 const string&
instance(fobs[ifob].provenance()->productInstanceName());
252 for (
unsigned int icol = 0; icol != ncol; ++icol) {
254 tokenizeTag(collectionTags_[icol], tagLabel, tagInstance, tagProcess);
255 collectionTagsEvent.insert(
InputTag(tagLabel, tagInstance,
pn_));
260 if (filterTagsEvent.size() != nf) {
261 LogError(
"TriggerSummaryProducerAOD")
262 <<
"Mismatch in number of filter tags: " << filterTagsEvent.size() <<
"!=" << nf;
272 const unsigned int nc(collectionTagsEvent.size());
273 LogTrace(
"TriggerSummaryProducerAOD") <<
"Number of unique collections requested " << nc;
274 const InputTagSet::const_iterator cb(collectionTagsEvent.begin());
275 const InputTagSet::const_iterator ce(collectionTagsEvent.end());
276 for (InputTagSet::const_iterator ci = cb; ci != ce; ++ci) {
277 LogTrace(
"TriggerSummaryProducerAOD") <<
distance(cb, ci) <<
" " << ci->encode();
279 const unsigned int nf(filterTagsEvent.size());
280 LogTrace(
"TriggerSummaryProducerAOD") <<
"Number of unique filters requested " << nf;
281 const InputTagSet::const_iterator
fb(filterTagsEvent.begin());
282 const InputTagSet::const_iterator fe(filterTagsEvent.end());
283 for (InputTagSet::const_iterator fi =
fb; fi != fe; ++fi) {
295 std::vector<std::string>
tags;
297 std::map<edm::ProductID, unsigned int>
offset;
299 fillTriggerObjectCollections<RecoEcalCandidateCollection>(
301 fillTriggerObjectCollections<ElectronCollection>(
303 fillTriggerObjectCollections<RecoChargedCandidateCollection>(
305 fillTriggerObjectCollections<CaloJetCollection>(
307 fillTriggerObjectCollections<CompositeCandidateCollection>(
310 fillTriggerObjectCollections<CaloMETCollection>(
312 fillTriggerObjectCollections<IsolatedPixelTrackCandidateCollection>(
315 fillTriggerObjectCollections<L1EmParticleCollection>(
317 fillTriggerObjectCollections<L1MuonParticleCollection>(
319 fillTriggerObjectCollections<L1JetParticleCollection>(
321 fillTriggerObjectCollections<L1EtMissParticleCollection>(
323 fillTriggerObjectCollections<L1HFRingsCollection>(
325 fillTriggerObjectCollections<MuonBxCollection>(
327 fillTriggerObjectCollections<EGammaBxCollection>(
329 fillTriggerObjectCollections<JetBxCollection>(
331 fillTriggerObjectCollections<TauBxCollection>(
333 fillTriggerObjectCollections<EtSumBxCollection>(
336 fillTriggerObjectCollections<PFJetCollection>(
338 fillTriggerObjectCollections<PFTauCollection>(
340 fillTriggerObjectCollections<PFMETCollection>(
343 const unsigned int nk(
tags.size());
344 LogDebug(
"TriggerSummaryProducerAOD") <<
"Number of collections found: " << nk;
345 const unsigned int no(toc.size());
346 LogDebug(
"TriggerSummaryProducerAOD") <<
"Number of physics objects found: " << no;
353 product->addCollections(
tags,
keys);
354 product->addObjects(toc);
358 for (
unsigned int ifob = 0; ifob != nfob; ++ifob) {
359 if (maskFilters[ifob]) {
361 const string&
instance(fobs[ifob].provenance()->productInstanceName());
368 iEvent, filterTag, fobs[ifob]->electronIds(), fobs[ifob]->electronRefs(),
offset,
keys, ids);
372 iEvent, filterTag, fobs[ifob]->compositeIds(), fobs[ifob]->compositeRefs(),
offset,
keys, ids);
374 iEvent, filterTag, fobs[ifob]->basemetIds(), fobs[ifob]->basemetRefs(),
offset,
keys, ids);
376 iEvent, filterTag, fobs[ifob]->calometIds(), fobs[ifob]->calometRefs(),
offset,
keys, ids);
378 iEvent, filterTag, fobs[ifob]->pixtrackIds(), fobs[ifob]->pixtrackRefs(),
offset,
keys, ids);
383 iEvent, filterTag, fobs[ifob]->l1etmissIds(), fobs[ifob]->l1etmissRefs(),
offset,
keys, ids);
385 iEvent, filterTag, fobs[ifob]->l1hfringsIds(), fobs[ifob]->l1hfringsRefs(),
offset,
keys, ids);
387 iEvent, filterTag, fobs[ifob]->l1tmuonIds(), fobs[ifob]->l1tmuonRefs(),
offset,
keys, ids);
389 iEvent, filterTag, fobs[ifob]->l1tegammaIds(), fobs[ifob]->l1tegammaRefs(),
offset,
keys, ids);
393 iEvent, filterTag, fobs[ifob]->l1tetsumIds(), fobs[ifob]->l1tetsumRefs(),
offset,
keys, ids);
397 product->addFilter(filterTag, ids,
keys);
402 LogTrace(
"TriggerSummaryProducerAOD") <<
"Number of physics objects packed: " << ref->
sizeObjects();
403 LogTrace(
"TriggerSummaryProducerAOD") <<
"Number of filter objects packed: " << ref->
sizeFilters();
406 template <
typename C>
409 std::vector<std::string>&
tags,
420 using namespace reco;
429 for (
unsigned int ic = 0; ic != nc; ++ic) {
436 if (collectionTagsEvent.find(collectionTag) != collectionTagsEvent.end()) {
439 LogError(
"TriggerSummaryProducerAOD") <<
"Duplicate pid: " << pid;
443 for (
unsigned int i = 0;
i !=
n; ++
i) {
446 tags.push_back(collectionTag.encode());
447 keys.push_back(toc.size());
453 template <
typename T>
456 toc.emplace_back(
object);
467 object.hfEtSum(L1HFRings::kRing1PosEta),
468 object.hfEtSum(L1HFRings::kRing1NegEta),
469 object.hfEtSum(L1HFRings::kRing2PosEta),
470 object.hfEtSum(L1HFRings::kRing2NegEta));
472 object.hfBitCount(L1HFRings::kRing1PosEta),
473 object.hfBitCount(L1HFRings::kRing1NegEta),
474 object.hfBitCount(L1HFRings::kRing2PosEta),
475 object.hfBitCount(L1HFRings::kRing2NegEta));
485 toc.emplace_back(
object);
486 if (
object.
type() == L1EtMissParticle::kMET) {
487 toc.emplace_back(
TriggerL1ETT,
object.etTotal(), 0.0, 0.0, 0.0);
488 }
else if (
object.
type() == L1EtMissParticle::kMHT) {
489 toc.emplace_back(
TriggerL1HTT,
object.etTotal(), 0.0, 0.0, 0.0);
491 toc.emplace_back(0,
object.etTotal(), 0.0, 0.0, 0.0);
499 using namespace reco;
502 toc.emplace_back(
object);
504 toc.emplace_back(
TriggerMETSig,
object.mEtSig(), 0.0, 0.0, 0.0);
505 toc.emplace_back(
TriggerELongit,
object.e_longitudinal(), 0.0, 0.0, 0.0);
512 using namespace reco;
515 toc.emplace_back(
object);
517 toc.emplace_back(
TriggerMETSig,
object.mEtSig(), 0.0, 0.0, 0.0);
518 toc.emplace_back(
TriggerELongit,
object.e_longitudinal(), 0.0, 0.0, 0.0);
525 using namespace reco;
528 toc.emplace_back(
object);
530 toc.emplace_back(
TriggerMHTSig,
object.mEtSig(), 0.0, 0.0, 0.0);
531 toc.emplace_back(
TriggerHLongit,
object.e_longitudinal(), 0.0, 0.0, 0.0);
536 template <
typename C>
550 using namespace reco;
554 if (ids.size() != refs.size()) {
555 LogError(
"TriggerSummaryProducerAOD") <<
"Vector length is different: " << ids.size() <<
" " << refs.size();
558 const unsigned int n(
min(ids.size(), refs.size()));
559 for (
unsigned int i = 0;
i !=
n; ++
i) {
562 std::ostringstream ost;
563 ost <<
"Iinvalid pid: " << pid <<
" FilterTag / Key: " <<
tag.encode() <<
" / " <<
i <<
"of" <<
n
564 <<
" CollectionTag / Key: "
565 <<
" <Unrecoverable>"
566 <<
" / " << refs[
i].key() <<
" CollectionType: " <<
typeid(
C).
name();
570 LogError(
"TriggerSummaryProducerAOD") << ost.str();
573 auto itOffset =
offset.find(pid);
574 if (itOffset ==
offset.end()) {
575 const string&
label(
iEvent.getProvenance(pid).moduleLabel());
576 const string&
instance(
iEvent.getProvenance(pid).productInstanceName());
577 const string&
process(
iEvent.getProvenance(pid).processName());
578 std::ostringstream ost;
579 ost <<
"Uunknown pid: " << pid <<
" FilterTag / Key: " <<
tag.encode() <<
" / " <<
i <<
"of" <<
n
581 <<
" CollectionType: " <<
typeid(
C).
name();
585 LogError(
"TriggerSummaryProducerAOD") << ost.str();
595 template <
typename C>
707 LogVerbatim(
"TriggerSummaryProducerAOD") <<
"TriggerSummaryProducerAOD::globalEndJob - accumulated tags:" << endl;
716 const unsigned int nf(filterTags.size());
717 LogVerbatim(
"TriggerSummaryProducerAOD") <<
" Overall number of Collections/Filters: " << nc <<
"/" << nf << endl;
719 LogVerbatim(
"TriggerSummaryProducerAOD") <<
" The collections: " << nc << endl;
722 for (InputTagSet::const_iterator ci = cb; ci != ce; ++ci) {
723 LogVerbatim(
"TriggerSummaryProducerAOD") <<
" " <<
distance(cb, ci) <<
" " << ci->encode() << endl;
726 LogVerbatim(
"TriggerSummaryProducerAOD") <<
" The filters:" << nf << endl;
727 const InputTagSet::const_iterator
fb(filterTags.begin());
728 const InputTagSet::const_iterator fe(filterTags.end());
729 for (InputTagSet::const_iterator fi =
fb; fi != fe; ++fi) {
733 LogVerbatim(
"TriggerSummaryProducerAOD") <<
"TriggerSummaryProducerAOD::endJob." << endl;