65 #include "boost/algorithm/string.hpp"
68 std::vector<std::regex> convertToRegex(std::vector<std::string>
const& iPatterns) {
69 std::vector<std::regex>
result;
71 for (
auto const& pattern : iPatterns) {
72 auto regexPattern = pattern;
73 boost::replace_all(regexPattern,
"*",
".*");
74 boost::replace_all(regexPattern,
"?",
".");
76 result.emplace_back(regexPattern);
86 : throw_(ps.getParameter<bool>(
"throw")),
87 pn_(ps.getParameter<std::
string>(
"processName")),
88 moduleLabelPatternsToMatch_(
89 convertToRegex(ps.getParameter<std::
vector<std::
string>>(
"moduleLabelPatternsToMatch"))),
90 moduleLabelPatternsToSkip_(
91 convertToRegex(ps.getParameter<std::
vector<std::
string>>(
"moduleLabelPatternsToSkip"))) {
97 edm::LogError(
"TriggerSummaryProducerAOD") <<
"HLT Error: TriggerNamesService not available!";
101 LogDebug(
"TriggerSummaryProducerAOD") <<
"Using process name: '" <<
pn_ <<
"'";
103 produces<trigger::TriggerEvent>();
105 auto const* pProcessName = &
pn_;
110 if (iBranch.processName() == *pProcessName || *pProcessName ==
"*") {
111 auto const&
label = iBranch.moduleLabel();
115 for (
auto&
reject : moduleLabelPatternsToSkip) {
203 const char token(
':');
208 if (i1 == string::npos) {
212 instance = label.substr(i1 + 1);
215 if (i2 == string::npos) {
218 process = instance.substr(i2 + 1);
227 desc.
add<
bool>(
"throw",
false)->setComment(
"Throw exception or LogError");
230 "Process name to use when getting data. The value of '@' is used to denote the current process name.");
231 desc.
add<std::vector<std::string>>(
"moduleLabelPatternsToMatch", std::vector<std::string>(1,
"hlt*"))
232 ->
setComment(
"glob patterns for module labels to get data.");
233 desc.
add<std::vector<std::string>>(
"moduleLabelPatternsToSkip", std::vector<std::string>())
234 ->
setComment(
"module labels for data products which should not be gotten.");
235 descriptions.
add(
"triggerSummaryProducerAOD", desc);
242 using namespace reco;
243 using namespace l1extra;
244 using namespace trigger;
247 std::vector<edm::Handle<trigger::TriggerFilterObjectWithRefs>> fobs;
250 const unsigned int nfob(fobs.size());
251 LogTrace(
"TriggerSummaryProducerAOD") <<
"Number of filter objects found: " << nfob;
253 string tagLabel, tagInstance, tagProcess;
260 std::vector<bool> maskFilters;
261 maskFilters.resize(nfob);
266 for (
unsigned int ifob = 0; ifob != nfob; ++ifob) {
267 maskFilters[ifob] =
false;
268 const vector<string>& collectionTags_(fobs[ifob]->getCollectionTagsAsStrings());
269 const unsigned int ncol(collectionTags_.size());
272 maskFilters[ifob] =
true;
273 const string&
label(fobs[ifob].provenance()->moduleLabel());
274 const string&
instance(fobs[ifob].provenance()->productInstanceName());
276 filterTagsEvent.insert(
InputTag(label, instance, process));
277 for (
unsigned int icol = 0; icol != ncol; ++icol) {
279 tokenizeTag(collectionTags_[icol], tagLabel, tagInstance, tagProcess);
280 collectionTagsEvent.insert(
InputTag(tagLabel, tagInstance,
pn_));
285 if (filterTagsEvent.size() != nf) {
286 LogError(
"TriggerSummaryProducerAOD")
287 <<
"Mismatch in number of filter tags: " << filterTagsEvent.size() <<
"!=" << nf;
297 const unsigned int nc(collectionTagsEvent.size());
298 LogTrace(
"TriggerSummaryProducerAOD") <<
"Number of unique collections requested " << nc;
299 const InputTagSet::const_iterator cb(collectionTagsEvent.begin());
300 const InputTagSet::const_iterator ce(collectionTagsEvent.end());
301 for (InputTagSet::const_iterator ci = cb; ci != ce; ++ci) {
302 LogTrace(
"TriggerSummaryProducerAOD") <<
distance(cb, ci) <<
" " << ci->encode();
304 const unsigned int nf(filterTagsEvent.size());
305 LogTrace(
"TriggerSummaryProducerAOD") <<
"Number of unique filters requested " << nf;
306 const InputTagSet::const_iterator fb(filterTagsEvent.begin());
307 const InputTagSet::const_iterator fe(filterTagsEvent.end());
308 for (InputTagSet::const_iterator fi = fb; fi != fe; ++fi) {
309 LogTrace(
"TriggerSummaryProducerAOD") <<
distance(fb, fi) <<
" " << fi->encode();
320 std::vector<std::string>
tags;
322 std::map<edm::ProductID, unsigned int>
offset;
324 fillTriggerObjectCollections<RecoEcalCandidateCollection>(
326 fillTriggerObjectCollections<ElectronCollection>(
328 fillTriggerObjectCollections<RecoChargedCandidateCollection>(
330 fillTriggerObjectCollections<CaloJetCollection>(
332 fillTriggerObjectCollections<CompositeCandidateCollection>(
335 fillTriggerObjectCollections<CaloMETCollection>(
337 fillTriggerObjectCollections<IsolatedPixelTrackCandidateCollection>(
340 fillTriggerObjectCollections<L1EmParticleCollection>(
342 fillTriggerObjectCollections<L1MuonParticleCollection>(
344 fillTriggerObjectCollections<L1JetParticleCollection>(
346 fillTriggerObjectCollections<L1EtMissParticleCollection>(
348 fillTriggerObjectCollections<L1HFRingsCollection>(
350 fillTriggerObjectCollections<MuonBxCollection>(
352 fillTriggerObjectCollections<EGammaBxCollection>(
354 fillTriggerObjectCollections<JetBxCollection>(
356 fillTriggerObjectCollections<TauBxCollection>(
358 fillTriggerObjectCollections<EtSumBxCollection>(
361 fillTriggerObjectCollections<l1t::TkMuonCollection>(
363 fillTriggerObjectCollections<l1t::TkElectronCollection>(
365 fillTriggerObjectCollections<l1t::TkEmCollection>(
367 fillTriggerObjectCollections<l1t::PFJetCollection>(
369 fillTriggerObjectCollections<l1t::PFTauCollection>(
371 fillTriggerObjectCollections<l1t::HPSPFTauCollection>(
373 fillTriggerObjectCollections<l1t::PFTrackCollection>(
376 fillTriggerObjectCollections<reco::PFJetCollection>(
378 fillTriggerObjectCollections<reco::PFTauCollection>(
380 fillTriggerObjectCollections<reco::PFMETCollection>(
383 const unsigned int nk(
tags.size());
384 LogDebug(
"TriggerSummaryProducerAOD") <<
"Number of collections found: " << nk;
385 const unsigned int no(toc.size());
386 LogDebug(
"TriggerSummaryProducerAOD") <<
"Number of physics objects found: " << no;
393 product->addCollections(
tags,
keys);
394 product->addObjects(toc);
398 for (
unsigned int ifob = 0; ifob != nfob; ++ifob) {
399 if (maskFilters[ifob]) {
400 const string&
label(fobs[ifob].provenance()->moduleLabel());
401 const string&
instance(fobs[ifob].provenance()->productInstanceName());
408 iEvent, filterTag, fobs[ifob]->electronIds(), fobs[ifob]->electronRefs(),
offset,
keys, ids);
412 iEvent, filterTag, fobs[ifob]->compositeIds(), fobs[ifob]->compositeRefs(),
offset,
keys, ids);
414 iEvent, filterTag, fobs[ifob]->basemetIds(), fobs[ifob]->basemetRefs(),
offset,
keys, ids);
416 iEvent, filterTag, fobs[ifob]->calometIds(), fobs[ifob]->calometRefs(),
offset,
keys, ids);
418 iEvent, filterTag, fobs[ifob]->pixtrackIds(), fobs[ifob]->pixtrackRefs(),
offset,
keys, ids);
423 iEvent, filterTag, fobs[ifob]->l1etmissIds(), fobs[ifob]->l1etmissRefs(),
offset,
keys, ids);
425 iEvent, filterTag, fobs[ifob]->l1hfringsIds(), fobs[ifob]->l1hfringsRefs(),
offset,
keys, ids);
427 iEvent, filterTag, fobs[ifob]->l1tmuonIds(), fobs[ifob]->l1tmuonRefs(),
offset,
keys, ids);
429 iEvent, filterTag, fobs[ifob]->l1tegammaIds(), fobs[ifob]->l1tegammaRefs(),
offset,
keys, ids);
433 iEvent, filterTag, fobs[ifob]->l1tetsumIds(), fobs[ifob]->l1tetsumRefs(),
offset,
keys, ids);
436 iEvent, filterTag, fobs[ifob]->l1ttkmuonIds(), fobs[ifob]->l1ttkmuonRefs(),
offset,
keys, ids);
438 iEvent, filterTag, fobs[ifob]->l1ttkeleIds(), fobs[ifob]->l1ttkeleRefs(),
offset,
keys, ids);
440 iEvent, filterTag, fobs[ifob]->l1ttkemIds(), fobs[ifob]->l1ttkemRefs(),
offset,
keys, ids);
442 iEvent, filterTag, fobs[ifob]->l1tpfjetIds(), fobs[ifob]->l1tpfjetRefs(),
offset,
keys, ids);
444 iEvent, filterTag, fobs[ifob]->l1tpftauIds(), fobs[ifob]->l1tpftauRefs(),
offset,
keys, ids);
446 iEvent, filterTag, fobs[ifob]->l1thpspftauIds(), fobs[ifob]->l1thpspftauRefs(),
offset,
keys, ids);
448 iEvent, filterTag, fobs[ifob]->l1tpftrackIds(), fobs[ifob]->l1tpftrackRefs(),
offset,
keys, ids);
453 product->addFilter(filterTag, ids,
keys);
458 LogTrace(
"TriggerSummaryProducerAOD") <<
"Number of physics objects packed: " << ref->sizeObjects();
459 LogTrace(
"TriggerSummaryProducerAOD") <<
"Number of filter objects packed: " << ref->sizeFilters();
462 template <
typename C>
465 std::vector<std::string>&
tags,
476 using namespace reco;
477 using namespace l1extra;
478 using namespace trigger;
481 vector<Handle<C>> collections;
483 const unsigned int nc(collections.size());
485 for (
unsigned int ic = 0; ic != nc; ++ic) {
486 const Provenance& provenance(*(collections[ic].provenance()));
490 const InputTag collectionTag(label, instance, process);
492 if (collectionTagsEvent.find(collectionTag) != collectionTagsEvent.end()) {
493 const ProductID pid(collections[ic].provenance()->productID());
494 if (offset.find(pid) != offset.end()) {
495 LogError(
"TriggerSummaryProducerAOD") <<
"Duplicate pid: " << pid;
497 offset[pid] = toc.size();
498 const unsigned int n(collections[ic]->
size());
499 for (
unsigned int i = 0;
i !=
n; ++
i) {
502 tags.push_back(collectionTag.encode());
503 keys.push_back(toc.size());
509 template <
typename T>
511 using namespace trigger;
512 toc.emplace_back(
object);
519 using namespace l1extra;
520 using namespace trigger;
523 object.hfEtSum(L1HFRings::kRing1PosEta),
524 object.hfEtSum(L1HFRings::kRing1NegEta),
525 object.hfEtSum(L1HFRings::kRing2PosEta),
526 object.hfEtSum(L1HFRings::kRing2NegEta));
528 object.hfBitCount(L1HFRings::kRing1PosEta),
529 object.hfBitCount(L1HFRings::kRing1NegEta),
530 object.hfBitCount(L1HFRings::kRing2PosEta),
531 object.hfBitCount(L1HFRings::kRing2NegEta));
538 using namespace l1extra;
539 using namespace trigger;
541 toc.emplace_back(
object);
542 if (
object.
type() == L1EtMissParticle::kMET) {
543 toc.emplace_back(
TriggerL1ETT,
object.etTotal(), 0.0, 0.0, 0.0);
544 }
else if (
object.
type() == L1EtMissParticle::kMHT) {
545 toc.emplace_back(
TriggerL1HTT,
object.etTotal(), 0.0, 0.0, 0.0);
547 toc.emplace_back(0,
object.etTotal(), 0.0, 0.0, 0.0);
555 using namespace reco;
556 using namespace trigger;
558 toc.emplace_back(
object);
559 toc.emplace_back(
TriggerTET,
object.sumEt(), 0.0, 0.0, 0.0);
560 toc.emplace_back(
TriggerMETSig,
object.mEtSig(), 0.0, 0.0, 0.0);
561 toc.emplace_back(
TriggerELongit,
object.e_longitudinal(), 0.0, 0.0, 0.0);
568 using namespace reco;
569 using namespace trigger;
571 toc.emplace_back(
object);
572 toc.emplace_back(
TriggerTET,
object.sumEt(), 0.0, 0.0, 0.0);
573 toc.emplace_back(
TriggerMETSig,
object.mEtSig(), 0.0, 0.0, 0.0);
574 toc.emplace_back(
TriggerELongit,
object.e_longitudinal(), 0.0, 0.0, 0.0);
581 using namespace reco;
582 using namespace trigger;
584 toc.emplace_back(
object);
585 toc.emplace_back(
TriggerTHT,
object.sumEt(), 0.0, 0.0, 0.0);
586 toc.emplace_back(
TriggerMHTSig,
object.mEtSig(), 0.0, 0.0, 0.0);
587 toc.emplace_back(
TriggerHLongit,
object.e_longitudinal(), 0.0, 0.0, 0.0);
592 template <
typename C>
606 using namespace reco;
607 using namespace l1extra;
608 using namespace trigger;
610 if (ids.size() != refs.size()) {
611 LogError(
"TriggerSummaryProducerAOD") <<
"Vector length is different: " << ids.size() <<
" " << refs.size();
614 const unsigned int n(
min(ids.size(), refs.size()));
615 for (
unsigned int i = 0;
i !=
n; ++
i) {
618 std::ostringstream ost;
619 ost <<
"Iinvalid pid: " << pid <<
" FilterTag / Key: " << tag.
encode() <<
" / " <<
i <<
"of" << n
620 <<
" CollectionTag / Key: "
621 <<
" <Unrecoverable>"
622 <<
" / " << refs[
i].key() <<
" CollectionType: " <<
typeid(
C).
name();
626 LogError(
"TriggerSummaryProducerAOD") << ost.str();
629 auto itOffset = offset.find(pid);
630 if (itOffset == offset.end()) {
632 const string&
label(prov.moduleLabel());
633 const string&
instance(prov.productInstanceName());
634 const string&
process(prov.processName());
635 std::ostringstream ost;
636 ost <<
"Uunknown pid: " << pid <<
" FilterTag / Key: " << tag.
encode() <<
" / " <<
i <<
"of" << n
637 <<
" CollectionTag / Key: " <<
InputTag(label, instance, process).encode() <<
" / " << refs[
i].key()
638 <<
" CollectionType: " <<
typeid(
C).
name();
642 LogError(
"TriggerSummaryProducerAOD") << ost.str();
652 template <
typename C>
655 keys.push_back(offset + ref.
key());
666 using namespace trigger;
669 keys.push_back(offset + 2 * ref.
key() + 1);
671 keys.push_back(offset + 2 * ref.
key() + 0);
683 using namespace trigger;
686 keys.push_back(offset + 2 * ref.
key() + 1);
688 keys.push_back(offset + 2 * ref.
key() + 0);
700 using namespace trigger;
703 keys.push_back(offset + 4 * ref.
key() + 1);
705 keys.push_back(offset + 4 * ref.
key() + 2);
707 keys.push_back(offset + 4 * ref.
key() + 3);
709 keys.push_back(offset + 4 * ref.
key() + 0);
721 using namespace trigger;
724 keys.push_back(offset + 4 * ref.
key() + 1);
726 keys.push_back(offset + 4 * ref.
key() + 2);
728 keys.push_back(offset + 4 * ref.
key() + 3);
730 keys.push_back(offset + 4 * ref.
key() + 0);
742 using namespace trigger;
745 keys.push_back(offset + 4 * ref.
key() + 1);
747 keys.push_back(offset + 4 * ref.
key() + 2);
749 keys.push_back(offset + 4 * ref.
key() + 3);
751 keys.push_back(offset + 4 * ref.
key() + 0);
761 using namespace trigger;
764 LogVerbatim(
"TriggerSummaryProducerAOD") <<
"TriggerSummaryProducerAOD::globalEndJob - accumulated tags:" << endl;
772 const unsigned int nc(collectionTags.size());
773 const unsigned int nf(filterTags.size());
774 LogVerbatim(
"TriggerSummaryProducerAOD") <<
" Overall number of Collections/Filters: " << nc <<
"/" << nf << endl;
776 LogVerbatim(
"TriggerSummaryProducerAOD") <<
" The collections: " << nc << endl;
777 const InputTagSet::const_iterator cb(collectionTags.begin());
778 const InputTagSet::const_iterator ce(collectionTags.end());
779 for (InputTagSet::const_iterator ci = cb; ci != ce; ++ci) {
780 LogVerbatim(
"TriggerSummaryProducerAOD") <<
" " <<
distance(cb, ci) <<
" " << ci->encode() << endl;
783 LogVerbatim(
"TriggerSummaryProducerAOD") <<
" The filters:" << nf << endl;
784 const InputTagSet::const_iterator fb(filterTags.begin());
785 const InputTagSet::const_iterator fe(filterTags.end());
786 for (InputTagSet::const_iterator fi = fb; fi != fe; ++fi) {
787 LogVerbatim(
"TriggerSummaryProducerAOD") <<
" " <<
distance(fb, fi) <<
" " << fi->encode() << endl;
790 LogVerbatim(
"TriggerSummaryProducerAOD") <<
"TriggerSummaryProducerAOD::endJob." << endl;
~TriggerSummaryProducerAOD() override
Log< level::Info, true > LogVerbatim
void callWhenNewProductsRegistered(std::function< void(BranchDescription const &)> const &func)
void setComment(std::string const &value)
edm::GetterOfProducts< l1t::TauBxCollection > getL1TTauParticleCollection_
std::vector< std::regex > moduleLabelPatternsToSkip_
pathNames_ & tns()), endPathNames_(&tns.getEndPaths()), wantSummary_(tns.wantSummary()
edm::GetterOfProducts< l1extra::L1JetParticleCollection > getL1JetParticleCollection_
edm::GetterOfProducts< reco::IsolatedPixelTrackCandidateCollection > getIsolatedPixelTrackCandidateCollection_
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
edm::GetterOfProducts< reco::RecoEcalCandidateCollection > getRecoEcalCandidateCollection_
std::string const & getProcessName() const
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
edm::GetterOfProducts< l1t::PFTrackCollection > getL1TPFTrackCollection_
edm::GetterOfProducts< l1extra::L1MuonParticleCollection > getL1MuonParticleCollection_
The single EDProduct to be saved for each event (AOD case)
edm::GetterOfProducts< reco::PFTauCollection > getPFTauCollection_
void fillTriggerObject(trigger::TriggerObjectCollection &, const T &) const
static PFTauRenderPlugin instance
edm::GetterOfProducts< reco::METCollection > getMETCollection_
edm::GetterOfProducts< l1t::JetBxCollection > getL1TJetParticleCollection_
edm::GetterOfProducts< l1t::TkElectronCollection > getL1TTkElectronCollection_
void fillHandles(edm::Event const &event, std::vector< edm::Handle< T >> &handles) const
tbb::concurrent_unordered_set< edm::InputTag, InputTagHash > filterTagsGlobal_
list of L3 filter tags
tbb::concurrent_unordered_set< edm::InputTag, InputTagHash > collectionTagsGlobal_
list of L3 collection tags
edm::GetterOfProducts< reco::CaloJetCollection > getCaloJetCollection_
edm::GetterOfProducts< l1extra::L1EtMissParticleCollection > getL1EtMissParticleCollection_
key_type key() const
Accessor for product key.
tuple moduleLabelPatternsToMatch
Log< level::Error, false > LogError
std::string const & processName() const
edm::GetterOfProducts< reco::PFJetCollection > getPFJetCollection_
const bool throw_
throw on error
std::set< edm::InputTag, OrderInputTag > InputTagSet
edm::GetterOfProducts< l1t::TkEmCollection > getL1TTkEmCollection_
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
edm::GetterOfProducts< reco::RecoChargedCandidateCollection > getRecoChargedCandidateCollection_
TriggerSummaryProducerAOD(const edm::ParameterSet &)
edm::GetterOfProducts< l1extra::L1HFRingsCollection > getL1HFRingsCollection_
edm::GetterOfProducts< l1t::TkMuonCollection > getL1TTkMuonCollection_
std::vector< std::regex > moduleLabelPatternsToMatch_
module labels which should be avoided
edm::GetterOfProducts< l1t::PFTauCollection > getL1TPFTauCollection_
ParameterDescriptionBase * add(U const &iLabel, T const &value)
edm::GetterOfProducts< l1t::MuonBxCollection > getL1TMuonParticleCollection_
edm::GetterOfProducts< l1t::HPSPFTauCollection > getL1THPSPFTauCollection_
void fillFilterObjectMembers(const edm::Event &, const edm::InputTag &tag, const trigger::Vids &, const std::vector< edm::Ref< C >> &, const ProductIDtoIndex &, trigger::Keys &keys, trigger::Vids &oIds) const
std::vector< TriggerObject > TriggerObjectCollection
collection of trigger physics objects (e.g., all isolated muons)
void fillTriggerObjectCollections(trigger::TriggerObjectCollection &, ProductIDtoIndex &, std::vector< std::string > &, trigger::Keys &, const edm::Event &, const edm::GetterOfProducts< C > &, const InputTagSet &) const
std::vector< size_type > Keys
void add(std::string const &label, ParameterSetDescription const &psetDescription)
std::string const & moduleLabel() const
edm::GetterOfProducts< reco::CaloMETCollection > getCaloMETCollection_
edm::GetterOfProducts< reco::ElectronCollection > getElectronCollection_
std::map< edm::ProductID, unsigned int > ProductIDtoIndex
void fillFilterObjectMember(trigger::Keys &keys, trigger::Vids &ids, const int &, const int &, const edm::Ref< C > &) const
tuple moduleLabelPatternsToSkip
edm::GetterOfProducts< reco::CompositeCandidateCollection > getCompositeCandidateCollection_
edm::GetterOfProducts< trigger::TriggerFilterObjectWithRefs > getTriggerFilterObjectWithRefs_
trigger object collection
std::string pn_
process name
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
edm::GetterOfProducts< reco::PFMETCollection > getPFMETCollection_
edm::GetterOfProducts< l1t::PFJetCollection > getL1TPFJetCollection_
std::string const & productInstanceName() const
StableProvenance const & getStableProvenance(BranchID const &theID) const
edm::GetterOfProducts< l1t::EtSumBxCollection > getL1TEtSumParticleCollection_
tuple size
Write out results.
edm::GetterOfProducts< l1extra::L1EmParticleCollection > getL1EmParticleCollection_
edm::GetterOfProducts< l1t::EGammaBxCollection > getL1TEGammaParticleCollection_