Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:23:54

0001 // -*- C++ -*-
0002 //
0003 // Package:    PatAlgos
0004 // Class:      pat::PATTriggerProducer
0005 //
0006 //
0007 /**
0008   \class    pat::PATTriggerProducer PATTriggerProducer.h "PhysicsTools/PatAlgos/plugins/PATTriggerProducer.h"
0009   \brief    Produces the full or stand-alone PAT trigger information collections
0010 
0011    This producer extracts the trigger information from
0012    - the edm::TriggerResults written by the HLT process,
0013    - the corresponding trigger::TriggerEvent,
0014    - the provenance information,
0015    - the process history,
0016    - the GlobalTrigger information in the event and the event setup and
0017    - the L1 object collections ("l1extra")
0018    re-arranges it and writes it either (full mode) to
0019    - a pat::TriggerObjectCollection,
0020    - a pat::TriggerFilterCollection,
0021    - a pat::TriggerPathCollection,
0022    - a pat::TriggerAlgorithmCollection (optionally filled or empty) and
0023    - a pat::TriggerConditionCollection (optionally filled or empty)
0024    or (stand-alone mode) to
0025    - a pat::TriggerObjectStandAloneCollection
0026 
0027    For me information, s.
0028    https://twiki.cern.ch/twiki/bin/view/CMS/SWGuidePATTrigger
0029 
0030   \author   Volker Adler
0031   \version  $Id: PATTriggerProducer.h,v 1.20 2012/09/11 22:45:29 vadler Exp $
0032 */
0033 
0034 #include "FWCore/Framework/interface/stream/EDProducer.h"
0035 #include "FWCore/Framework/interface/GetterOfProducts.h"
0036 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0037 #include "FWCore/Utilities/interface/InputTag.h"
0038 #include "HLTrigger/HLTcore/interface/HLTPrescaleProvider.h"
0039 #include "HLTrigger/HLTcore/interface/HLTConfigProvider.h"
0040 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerObjectMaps.h"
0041 #include "DataFormats/Common/interface/TriggerResults.h"
0042 #include "DataFormats/HLTReco/interface/TriggerEvent.h"
0043 #include "DataFormats/PatCandidates/interface/TriggerObjectStandAlone.h"
0044 #include "FWCore/Framework/interface/InputTagMatch.h"
0045 #include "CondFormats/L1TObjects/interface/L1GtTriggerMenu.h"
0046 #include "CondFormats/DataRecord/interface/L1GtTriggerMenuRcd.h"
0047 #include "DataFormats/Common/interface/Handle.h"
0048 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutSetup.h"
0049 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutRecord.h"
0050 #include "DataFormats/Provenance/interface/ProcessHistory.h"
0051 #include "FWCore/Framework/interface/Event.h"
0052 #include "FWCore/ParameterSet/interface/Registry.h"
0053 #include "FWCore/Common/interface/TriggerNames.h"
0054 #include "DataFormats/PatCandidates/interface/TriggerAlgorithm.h"
0055 #include "DataFormats/PatCandidates/interface/TriggerCondition.h"
0056 #include "DataFormats/PatCandidates/interface/TriggerPath.h"
0057 #include "DataFormats/PatCandidates/interface/TriggerFilter.h"
0058 #include "DataFormats/PatCandidates/interface/PackedTriggerPrescales.h"
0059 #include "FWCore/Framework/interface/ESHandle.h"
0060 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0061 #include "L1Trigger/GlobalTriggerAnalyzer/interface/L1GtUtils.h"
0062 
0063 #include <cassert>
0064 #include <map>
0065 #include <memory>
0066 #include <string>
0067 #include <utility>
0068 #include <vector>
0069 
0070 namespace pat {
0071 
0072   class PATTriggerProducer : public edm::stream::EDProducer<> {
0073   public:
0074     explicit PATTriggerProducer(const edm::ParameterSet& iConfig);
0075     ~PATTriggerProducer() override{};
0076 
0077   private:
0078     void beginRun(const edm::Run& iRun, const edm::EventSetup& iSetup) override;
0079     void beginLuminosityBlock(const edm::LuminosityBlock& iLuminosityBlock, const edm::EventSetup& iSetup) override;
0080     void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override;
0081 
0082     std::string nameProcess_;  // configuration
0083     bool autoProcessName_;
0084     bool onlyStandAlone_;  // configuration
0085     bool firstInRun_;
0086     // L1
0087     edm::ParameterSet* l1PSet_;
0088     bool addL1Algos_;                             // configuration (optional with default)
0089     edm::InputTag tagL1GlobalTriggerObjectMaps_;  // configuration (optional with default)
0090     edm::EDGetTokenT<L1GlobalTriggerObjectMaps> l1GlobalTriggerObjectMapsToken_;
0091     edm::InputTag tagL1ExtraMu_;  // configuration (optional)
0092     edm::GetterOfProducts<l1extra::L1MuonParticleCollection> l1ExtraMuGetter_;
0093     edm::InputTag tagL1ExtraNoIsoEG_;  // configuration (optional)
0094     edm::GetterOfProducts<l1extra::L1EmParticleCollection> l1ExtraNoIsoEGGetter_;
0095     edm::InputTag tagL1ExtraIsoEG_;  // configuration (optional)
0096     edm::GetterOfProducts<l1extra::L1EmParticleCollection> l1ExtraIsoEGGetter_;
0097     edm::InputTag tagL1ExtraCenJet_;  // configuration (optional)
0098     edm::GetterOfProducts<l1extra::L1JetParticleCollection> l1ExtraCenJetGetter_;
0099     edm::InputTag tagL1ExtraForJet_;  // configuration (optional)
0100     edm::GetterOfProducts<l1extra::L1JetParticleCollection> l1ExtraForJetGetter_;
0101     edm::InputTag tagL1ExtraTauJet_;  // configuration (optional)
0102     edm::GetterOfProducts<l1extra::L1JetParticleCollection> l1ExtraTauJetGetter_;
0103     edm::InputTag tagL1ExtraETM_;  // configuration (optional)
0104     edm::GetterOfProducts<l1extra::L1EtMissParticleCollection> l1ExtraETMGetter_;
0105     edm::InputTag tagL1ExtraHTM_;  // configuration (optional)
0106     edm::GetterOfProducts<l1extra::L1EtMissParticleCollection> l1ExtraHTMGetter_;
0107     bool autoProcessNameL1ExtraMu_;
0108     bool autoProcessNameL1ExtraNoIsoEG_;
0109     bool autoProcessNameL1ExtraIsoEG_;
0110     bool autoProcessNameL1ExtraCenJet_;
0111     bool autoProcessNameL1ExtraForJet_;
0112     bool autoProcessNameL1ExtraTauJet_;
0113     bool autoProcessNameL1ExtraETM_;
0114     bool autoProcessNameL1ExtraHTM_;
0115     bool mainBxOnly_;  // configuration (optional with default)
0116     bool saveL1Refs_;  // configuration (optional with default)
0117     // HLT
0118     HLTPrescaleProvider hltPrescaleProvider_;
0119     bool hltConfigInit_;
0120     edm::InputTag tagTriggerResults_;  // configuration (optional with default)
0121     edm::GetterOfProducts<edm::TriggerResults> triggerResultsGetter_;
0122     edm::InputTag tagTriggerEvent_;  // configuration (optional with default)
0123     edm::GetterOfProducts<trigger::TriggerEvent> triggerEventGetter_;
0124     std::string hltPrescaleLabel_;       // configuration (optional)
0125     std::string labelHltPrescaleTable_;  // configuration (optional)
0126     edm::GetterOfProducts<trigger::HLTPrescaleTable> hltPrescaleTableRunGetter_;
0127     edm::GetterOfProducts<trigger::HLTPrescaleTable> hltPrescaleTableLumiGetter_;
0128     edm::GetterOfProducts<trigger::HLTPrescaleTable> hltPrescaleTableEventGetter_;
0129     trigger::HLTPrescaleTable hltPrescaleTableRun_;
0130     trigger::HLTPrescaleTable hltPrescaleTableLumi_;
0131     bool addPathModuleLabels_;                    // configuration (optional with default)
0132     std::vector<std::string> exludeCollections_;  // configuration (optional)
0133     bool packPathNames_;                          // configuration (optional width default)
0134     bool packLabels_;                             // configuration (optional width default)
0135     bool packPrescales_;                          // configuration (optional width default)
0136     const edm::ESGetToken<L1GtTriggerMenu, L1GtTriggerMenuRcd> handleL1GtTriggerMenuToken_;
0137 
0138     class ModuleLabelToPathAndFlags {
0139     public:
0140       struct PathAndFlags {
0141         PathAndFlags(const std::string& name, unsigned int index, bool last, bool l3)
0142             : pathName(name), pathIndex(index), lastFilter(last), l3Filter(l3) {}
0143         PathAndFlags() {}
0144         std::string pathName;
0145         unsigned int pathIndex;
0146         bool lastFilter;
0147         bool l3Filter;
0148       };
0149       void init(const HLTConfigProvider&);
0150       void clear() { map_.clear(); }
0151       const std::vector<PathAndFlags>& operator[](const std::string& filter) const {
0152         std::map<std::string, std::vector<PathAndFlags> >::const_iterator it = map_.find(filter);
0153         return (it == map_.end() ? empty_ : it->second);
0154       }
0155 
0156     private:
0157       void insert(
0158           const std::string& filter, const std::string& path, unsigned int pathIndex, bool lastFilter, bool l3Filter) {
0159         map_[filter].push_back(PathAndFlags(path, pathIndex, lastFilter, l3Filter));
0160       }
0161       std::map<std::string, std::vector<PathAndFlags> > map_;
0162       const std::vector<PathAndFlags> empty_ = {};
0163     };
0164     ModuleLabelToPathAndFlags moduleLabelToPathAndFlags_;
0165   };
0166 }  // namespace pat
0167 
0168 using namespace pat;
0169 using namespace edm;
0170 
0171 // Constants' definitions
0172 const unsigned L1GlobalTriggerReadoutSetup::NumberPhysTriggers;
0173 const unsigned L1GlobalTriggerReadoutSetup::NumberPhysTriggersExtended;
0174 const unsigned L1GlobalTriggerReadoutSetup::NumberTechnicalTriggers;
0175 
0176 PATTriggerProducer::PATTriggerProducer(const ParameterSet& iConfig)
0177     : nameProcess_(iConfig.getParameter<std::string>("processName")),
0178       autoProcessName_(nameProcess_ == "*"),
0179       onlyStandAlone_(iConfig.getParameter<bool>("onlyStandAlone")),
0180       firstInRun_(true),
0181       // L1 configuration parameters
0182       addL1Algos_(false),
0183       tagL1GlobalTriggerObjectMaps_("l1L1GtObjectMap"),
0184       tagL1ExtraMu_(),
0185       tagL1ExtraNoIsoEG_(),
0186       tagL1ExtraIsoEG_(),
0187       tagL1ExtraCenJet_(),
0188       tagL1ExtraForJet_(),
0189       tagL1ExtraTauJet_(),
0190       tagL1ExtraETM_(),
0191       tagL1ExtraHTM_(),
0192       autoProcessNameL1ExtraMu_(false),
0193       autoProcessNameL1ExtraNoIsoEG_(false),
0194       autoProcessNameL1ExtraIsoEG_(false),
0195       autoProcessNameL1ExtraCenJet_(false),
0196       autoProcessNameL1ExtraForJet_(false),
0197       autoProcessNameL1ExtraTauJet_(false),
0198       autoProcessNameL1ExtraETM_(false),
0199       autoProcessNameL1ExtraHTM_(false),
0200       mainBxOnly_(true),
0201       saveL1Refs_(false),
0202       hltPrescaleProvider_(iConfig, consumesCollector(), *this),
0203       hltConfigInit_(false),
0204       // HLT configuration parameters
0205       tagTriggerResults_("TriggerResults"),
0206       tagTriggerEvent_("hltTriggerSummaryAOD"),
0207       hltPrescaleLabel_(),
0208       labelHltPrescaleTable_(),
0209       hltPrescaleTableRun_(),
0210       hltPrescaleTableLumi_(),
0211       addPathModuleLabels_(false),
0212       packPathNames_(iConfig.existsAs<bool>("packTriggerPathNames") ? iConfig.getParameter<bool>("packTriggerPathNames")
0213                                                                     : false),
0214       packLabels_(iConfig.existsAs<bool>("packTriggerLabels") ? iConfig.getParameter<bool>("packTriggerLabels") : true),
0215       packPrescales_(iConfig.existsAs<bool>("packTriggerPrescales") ? iConfig.getParameter<bool>("packTriggerPrescales")
0216                                                                     : true),
0217       handleL1GtTriggerMenuToken_{esConsumes()} {
0218   // L1 configuration parameters
0219   if (iConfig.exists("addL1Algos"))
0220     addL1Algos_ = iConfig.getParameter<bool>("addL1Algos");
0221   if (iConfig.exists("l1GlobalTriggerObjectMaps"))
0222     tagL1GlobalTriggerObjectMaps_ = iConfig.getParameter<InputTag>("l1GlobalTriggerObjectMaps");
0223   l1GlobalTriggerObjectMapsToken_ = mayConsume<L1GlobalTriggerObjectMaps>(tagL1GlobalTriggerObjectMaps_);
0224   if (iConfig.exists("l1ExtraMu")) {
0225     tagL1ExtraMu_ = iConfig.getParameter<InputTag>("l1ExtraMu");
0226     if (tagL1ExtraMu_.process() == "*") {
0227       if (autoProcessName_)
0228         autoProcessNameL1ExtraMu_ = true;
0229       else
0230         tagL1ExtraMu_ = InputTag(tagL1ExtraMu_.label(), tagL1ExtraMu_.instance(), nameProcess_);
0231     }
0232     l1ExtraMuGetter_ = GetterOfProducts<l1extra::L1MuonParticleCollection>(
0233         InputTagMatch(InputTag(tagL1ExtraMu_.label(), tagL1ExtraMu_.instance())), this);
0234   }
0235   if (iConfig.exists("l1ExtraNoIsoEG")) {
0236     tagL1ExtraNoIsoEG_ = iConfig.getParameter<InputTag>("l1ExtraNoIsoEG");
0237     if (tagL1ExtraNoIsoEG_.process() == "*") {
0238       if (autoProcessName_)
0239         autoProcessNameL1ExtraNoIsoEG_ = true;
0240       else
0241         tagL1ExtraNoIsoEG_ = InputTag(tagL1ExtraNoIsoEG_.label(), tagL1ExtraNoIsoEG_.instance(), nameProcess_);
0242     }
0243     l1ExtraNoIsoEGGetter_ = GetterOfProducts<l1extra::L1EmParticleCollection>(
0244         InputTagMatch(InputTag(tagL1ExtraNoIsoEG_.label(), tagL1ExtraNoIsoEG_.instance())), this);
0245   }
0246   if (iConfig.exists("l1ExtraIsoEG")) {
0247     tagL1ExtraIsoEG_ = iConfig.getParameter<InputTag>("l1ExtraIsoEG");
0248     if (tagL1ExtraIsoEG_.process() == "*") {
0249       if (autoProcessName_)
0250         autoProcessNameL1ExtraIsoEG_ = true;
0251       else
0252         tagL1ExtraIsoEG_ = InputTag(tagL1ExtraIsoEG_.label(), tagL1ExtraIsoEG_.instance(), nameProcess_);
0253     }
0254     l1ExtraIsoEGGetter_ = GetterOfProducts<l1extra::L1EmParticleCollection>(
0255         InputTagMatch(InputTag(tagL1ExtraIsoEG_.label(), tagL1ExtraIsoEG_.instance())), this);
0256   }
0257   if (iConfig.exists("l1ExtraCenJet")) {
0258     tagL1ExtraCenJet_ = iConfig.getParameter<InputTag>("l1ExtraCenJet");
0259     if (tagL1ExtraCenJet_.process() == "*") {
0260       if (autoProcessName_)
0261         autoProcessNameL1ExtraCenJet_ = true;
0262       else
0263         tagL1ExtraCenJet_ = InputTag(tagL1ExtraCenJet_.label(), tagL1ExtraCenJet_.instance(), nameProcess_);
0264     }
0265     l1ExtraCenJetGetter_ = GetterOfProducts<l1extra::L1JetParticleCollection>(
0266         InputTagMatch(InputTag(tagL1ExtraCenJet_.label(), tagL1ExtraCenJet_.instance())), this);
0267   }
0268   if (iConfig.exists("l1ExtraForJet")) {
0269     tagL1ExtraForJet_ = iConfig.getParameter<InputTag>("l1ExtraForJet");
0270     if (tagL1ExtraForJet_.process() == "*") {
0271       if (autoProcessName_)
0272         autoProcessNameL1ExtraForJet_ = true;
0273       else
0274         tagL1ExtraForJet_ = InputTag(tagL1ExtraForJet_.label(), tagL1ExtraForJet_.instance(), nameProcess_);
0275     }
0276     l1ExtraForJetGetter_ = GetterOfProducts<l1extra::L1JetParticleCollection>(
0277         InputTagMatch(InputTag(tagL1ExtraForJet_.label(), tagL1ExtraForJet_.instance())), this);
0278   }
0279   if (iConfig.exists("l1ExtraTauJet")) {
0280     tagL1ExtraTauJet_ = iConfig.getParameter<InputTag>("l1ExtraTauJet");
0281     if (tagL1ExtraTauJet_.process() == "*") {
0282       if (autoProcessName_)
0283         autoProcessNameL1ExtraTauJet_ = true;
0284       else
0285         tagL1ExtraTauJet_ = InputTag(tagL1ExtraTauJet_.label(), tagL1ExtraTauJet_.instance(), nameProcess_);
0286     }
0287     l1ExtraTauJetGetter_ = GetterOfProducts<l1extra::L1JetParticleCollection>(
0288         InputTagMatch(InputTag(tagL1ExtraTauJet_.label(), tagL1ExtraTauJet_.instance())), this);
0289   }
0290   if (iConfig.exists("l1ExtraETM")) {
0291     tagL1ExtraETM_ = iConfig.getParameter<InputTag>("l1ExtraETM");
0292     if (tagL1ExtraETM_.process() == "*") {
0293       if (autoProcessName_)
0294         autoProcessNameL1ExtraETM_ = true;
0295       else
0296         tagL1ExtraETM_ = InputTag(tagL1ExtraETM_.label(), tagL1ExtraETM_.instance(), nameProcess_);
0297     }
0298     l1ExtraETMGetter_ = GetterOfProducts<l1extra::L1EtMissParticleCollection>(
0299         InputTagMatch(InputTag(tagL1ExtraETM_.label(), tagL1ExtraETM_.instance())), this);
0300   }
0301   if (iConfig.exists("l1ExtraHTM")) {
0302     tagL1ExtraHTM_ = iConfig.getParameter<InputTag>("l1ExtraHTM");
0303     if (tagL1ExtraHTM_.process() == "*") {
0304       if (autoProcessName_)
0305         autoProcessNameL1ExtraHTM_ = true;
0306       else
0307         tagL1ExtraHTM_ = InputTag(tagL1ExtraHTM_.label(), tagL1ExtraHTM_.instance(), nameProcess_);
0308     }
0309     l1ExtraHTMGetter_ = GetterOfProducts<l1extra::L1EtMissParticleCollection>(
0310         InputTagMatch(InputTag(tagL1ExtraHTM_.label(), tagL1ExtraHTM_.instance())), this);
0311   }
0312   if (iConfig.exists("mainBxOnly"))
0313     mainBxOnly_ = iConfig.getParameter<bool>("mainBxOnly");
0314   if (iConfig.exists("saveL1Refs"))
0315     saveL1Refs_ = iConfig.getParameter<bool>("saveL1Refs");
0316 
0317   // HLT configuration parameters
0318   if (iConfig.exists("triggerResults"))
0319     tagTriggerResults_ = iConfig.getParameter<InputTag>("triggerResults");
0320   triggerResultsGetter_ =
0321       GetterOfProducts<TriggerResults>(InputTagMatch(InputTag(tagTriggerResults_.label(),
0322                                                               tagTriggerResults_.instance(),
0323                                                               autoProcessName_ ? std::string("") : nameProcess_)),
0324                                        this);
0325   if (iConfig.exists("triggerEvent"))
0326     tagTriggerEvent_ = iConfig.getParameter<InputTag>("triggerEvent");
0327   triggerEventGetter_ = GetterOfProducts<trigger::TriggerEvent>(
0328       InputTagMatch(InputTag(tagTriggerEvent_.label(), tagTriggerEvent_.instance())), this);
0329   if (iConfig.exists("hltPrescaleLabel"))
0330     hltPrescaleLabel_ = iConfig.getParameter<std::string>("hltPrescaleLabel");
0331   if (iConfig.exists("hltPrescaleTable")) {
0332     labelHltPrescaleTable_ = iConfig.getParameter<std::string>("hltPrescaleTable");
0333     hltPrescaleTableRunGetter_ = GetterOfProducts<trigger::HLTPrescaleTable>(
0334         InputTagMatch(InputTag(labelHltPrescaleTable_, "Run")), this, InRun);
0335     hltPrescaleTableLumiGetter_ = GetterOfProducts<trigger::HLTPrescaleTable>(
0336         InputTagMatch(InputTag(labelHltPrescaleTable_, "Lumi")), this, InLumi);
0337     hltPrescaleTableEventGetter_ =
0338         GetterOfProducts<trigger::HLTPrescaleTable>(InputTagMatch(InputTag(labelHltPrescaleTable_, "Event")), this);
0339   }
0340   if (iConfig.exists("addPathModuleLabels"))
0341     addPathModuleLabels_ = iConfig.getParameter<bool>("addPathModuleLabels");
0342   exludeCollections_.clear();
0343   if (iConfig.exists("exludeCollections"))
0344     exludeCollections_ = iConfig.getParameter<std::vector<std::string> >("exludeCollections");
0345 
0346   callWhenNewProductsRegistered([this, &iConfig](BranchDescription const& bd) {
0347     if (iConfig.exists("l1ExtraMu"))
0348       l1ExtraMuGetter_(bd);
0349     if (iConfig.exists("l1ExtraNoIsoEG"))
0350       l1ExtraNoIsoEGGetter_(bd);
0351     if (iConfig.exists("l1ExtraIsoEG"))
0352       l1ExtraIsoEGGetter_(bd);
0353     if (iConfig.exists("l1ExtraCenJet"))
0354       l1ExtraCenJetGetter_(bd);
0355     if (iConfig.exists("l1ExtraForJet"))
0356       l1ExtraForJetGetter_(bd);
0357     if (iConfig.exists("l1ExtraTauJet"))
0358       l1ExtraTauJetGetter_(bd);
0359     if (iConfig.exists("l1ExtraETM"))
0360       l1ExtraETMGetter_(bd);
0361     if (iConfig.exists("l1ExtraHTM"))
0362       l1ExtraHTMGetter_(bd);
0363     if (not(this->autoProcessName_ and bd.processName() == this->moduleDescription().processName())) {
0364       triggerResultsGetter_(bd);
0365     }
0366     triggerEventGetter_(bd);
0367     if (iConfig.exists("hltPrescaleTable")) {
0368       hltPrescaleTableRunGetter_(bd);
0369       hltPrescaleTableLumiGetter_(bd);
0370       hltPrescaleTableEventGetter_(bd);
0371     }
0372   });
0373 
0374   if (!onlyStandAlone_) {
0375     produces<TriggerAlgorithmCollection>();
0376     produces<TriggerConditionCollection>();
0377     produces<TriggerPathCollection>();
0378     produces<TriggerFilterCollection>();
0379     produces<TriggerObjectCollection>();
0380   }
0381   if (packPrescales_) {
0382     produces<PackedTriggerPrescales>();
0383     produces<PackedTriggerPrescales>("l1max");
0384     produces<PackedTriggerPrescales>("l1min");
0385   }
0386   produces<TriggerObjectStandAloneCollection>();
0387 }
0388 
0389 void PATTriggerProducer::beginRun(const Run& iRun, const EventSetup& iSetup) {
0390   // Initialize
0391   firstInRun_ = true;
0392   l1PSet_ = nullptr;
0393   hltConfigInit_ = false;
0394 
0395   // Initialize process name
0396   if (autoProcessName_) {
0397     // reset
0398     nameProcess_ = "*";
0399     // determine process name from last run TriggerSummaryProducerAOD module in process history of input
0400     const ProcessHistory& processHistory(iRun.processHistory());
0401     ProcessConfiguration processConfiguration;
0402     ParameterSet processPSet;
0403     // unbroken loop, which relies on time ordering (accepts the last found entry)
0404     for (ProcessHistory::const_iterator iHist = processHistory.begin(); iHist != processHistory.end(); ++iHist) {
0405       if (processHistory.getConfigurationForProcess(iHist->processName(), processConfiguration) &&
0406           pset::Registry::instance()->getMapped(processConfiguration.parameterSetID(), processPSet) &&
0407           processPSet.exists(tagTriggerEvent_.label())) {
0408         nameProcess_ = iHist->processName();
0409         LogDebug("autoProcessName") << "HLT process name '" << nameProcess_ << "' discovered";
0410       }
0411     }
0412     // terminate, if nothing is found
0413     if (nameProcess_ == "*") {
0414       LogError("autoProcessName") << "trigger::TriggerEvent product with label '" << tagTriggerEvent_.label()
0415                                   << "' not produced according to process history of input data\n"
0416                                   << "No trigger information produced";
0417       return;
0418     }
0419     LogInfo("autoProcessName") << "HLT process name' " << nameProcess_ << "' used for PAT trigger information";
0420   }
0421   // adapt configuration of used input tags
0422   if (tagTriggerResults_.process().empty() || tagTriggerResults_.process() == "*") {
0423     tagTriggerResults_ = InputTag(tagTriggerResults_.label(), tagTriggerResults_.instance(), nameProcess_);
0424   } else if (tagTriggerEvent_.process() != nameProcess_) {
0425     LogWarning("inputTags") << "TriggerResults process name '" << tagTriggerResults_.process()
0426                             << "' differs from HLT process name '" << nameProcess_ << "'";
0427   }
0428   if (tagTriggerEvent_.process().empty() || tagTriggerEvent_.process() == "*") {
0429     tagTriggerEvent_ = InputTag(tagTriggerEvent_.label(), tagTriggerEvent_.instance(), nameProcess_);
0430   } else if (tagTriggerEvent_.process() != nameProcess_) {
0431     LogWarning("inputTags") << "TriggerEvent process name '" << tagTriggerEvent_.process()
0432                             << "' differs from HLT process name '" << nameProcess_ << "'";
0433   }
0434   if (autoProcessNameL1ExtraMu_)
0435     tagL1ExtraMu_ = InputTag(tagL1ExtraMu_.label(), tagL1ExtraMu_.instance(), nameProcess_);
0436   if (autoProcessNameL1ExtraNoIsoEG_)
0437     tagL1ExtraNoIsoEG_ = InputTag(tagL1ExtraNoIsoEG_.label(), tagL1ExtraNoIsoEG_.instance(), nameProcess_);
0438   if (autoProcessNameL1ExtraIsoEG_)
0439     tagL1ExtraIsoEG_ = InputTag(tagL1ExtraIsoEG_.label(), tagL1ExtraIsoEG_.instance(), nameProcess_);
0440   if (autoProcessNameL1ExtraCenJet_)
0441     tagL1ExtraCenJet_ = InputTag(tagL1ExtraCenJet_.label(), tagL1ExtraCenJet_.instance(), nameProcess_);
0442   if (autoProcessNameL1ExtraForJet_)
0443     tagL1ExtraForJet_ = InputTag(tagL1ExtraForJet_.label(), tagL1ExtraForJet_.instance(), nameProcess_);
0444   if (autoProcessNameL1ExtraTauJet_)
0445     tagL1ExtraTauJet_ = InputTag(tagL1ExtraTauJet_.label(), tagL1ExtraTauJet_.instance(), nameProcess_);
0446   if (autoProcessNameL1ExtraETM_)
0447     tagL1ExtraETM_ = InputTag(tagL1ExtraETM_.label(), tagL1ExtraETM_.instance(), nameProcess_);
0448   if (autoProcessNameL1ExtraHTM_)
0449     tagL1ExtraHTM_ = InputTag(tagL1ExtraHTM_.label(), tagL1ExtraHTM_.instance(), nameProcess_);
0450 
0451   // Initialize HLTConfigProvider
0452   HLTConfigProvider const& hltConfig = hltPrescaleProvider_.hltConfigProvider();
0453   bool changed(true);
0454   if (!hltPrescaleProvider_.init(iRun, iSetup, nameProcess_, changed)) {
0455     LogError("hltConfig") << "HLT config extraction error with process name '" << nameProcess_ << "'";
0456   } else if (hltConfig.size() <= 0) {
0457     LogError("hltConfig") << "HLT config size error";
0458   } else
0459     hltConfigInit_ = true;
0460 
0461   // Update mapping from filter names to path names
0462   if (hltConfigInit_ && changed)
0463     moduleLabelToPathAndFlags_.init(hltConfig);
0464 
0465   // Extract pre-scales
0466   if (hltConfigInit_) {
0467     // Start empty
0468     hltPrescaleTableRun_ = trigger::HLTPrescaleTable();
0469     // Try run product, if configured
0470     if (!labelHltPrescaleTable_.empty()) {
0471       Handle<trigger::HLTPrescaleTable> handleHltPrescaleTable;
0472       iRun.getByLabel(InputTag(labelHltPrescaleTable_, "Run", nameProcess_), handleHltPrescaleTable);
0473       if (handleHltPrescaleTable.isValid()) {
0474         hltPrescaleTableRun_ = trigger::HLTPrescaleTable(
0475             handleHltPrescaleTable->set(), handleHltPrescaleTable->labels(), handleHltPrescaleTable->table());
0476       }
0477     }
0478   }
0479 }
0480 
0481 void PATTriggerProducer::beginLuminosityBlock(const LuminosityBlock& iLuminosityBlock, const EventSetup& iSetup) {
0482   // Terminate, if auto process name determination failed
0483   if (nameProcess_ == "*")
0484     return;
0485 
0486   // Extract pre-scales
0487   if (hltConfigInit_) {
0488     // Start from run
0489     hltPrescaleTableLumi_ = trigger::HLTPrescaleTable(
0490         hltPrescaleTableRun_.set(), hltPrescaleTableRun_.labels(), hltPrescaleTableRun_.table());
0491     // Try lumi product, if configured and available
0492     if (!labelHltPrescaleTable_.empty()) {
0493       Handle<trigger::HLTPrescaleTable> handleHltPrescaleTable;
0494       iLuminosityBlock.getByLabel(InputTag(labelHltPrescaleTable_, "Lumi", nameProcess_), handleHltPrescaleTable);
0495       if (handleHltPrescaleTable.isValid()) {
0496         hltPrescaleTableLumi_ = trigger::HLTPrescaleTable(
0497             handleHltPrescaleTable->set(), handleHltPrescaleTable->labels(), handleHltPrescaleTable->table());
0498       }
0499     }
0500   }
0501 }
0502 
0503 void PATTriggerProducer::produce(Event& iEvent, const EventSetup& iSetup) {
0504   // Terminate, if auto process name determination failed
0505   if (nameProcess_ == "*")
0506     return;
0507 
0508   auto triggerObjects = std::make_unique<TriggerObjectCollection>();
0509   auto triggerObjectsStandAlone = std::make_unique<TriggerObjectStandAloneCollection>();
0510   std::unique_ptr<PackedTriggerPrescales> packedPrescales, packedPrescalesL1min, packedPrescalesL1max;
0511 
0512   // HLT
0513   HLTConfigProvider const& hltConfig = hltPrescaleProvider_.hltConfigProvider();
0514 
0515   // Get and check HLT event data
0516   Handle<trigger::TriggerEvent> handleTriggerEvent;
0517   iEvent.getByLabel(tagTriggerEvent_, handleTriggerEvent);
0518   Handle<TriggerResults> handleTriggerResults;
0519   iEvent.getByLabel(tagTriggerResults_, handleTriggerResults);
0520   bool goodHlt(hltConfigInit_);
0521   if (goodHlt) {
0522     if (!handleTriggerResults.isValid()) {
0523       LogError("triggerResultsValid") << "TriggerResults product with InputTag '" << tagTriggerResults_.encode()
0524                                       << "' not in event\n"
0525                                       << "No HLT information produced";
0526       goodHlt = false;
0527     } else if (!handleTriggerEvent.isValid()) {
0528       LogError("triggerEventValid") << "trigger::TriggerEvent product with InputTag '" << tagTriggerEvent_.encode()
0529                                     << "' not in event\n"
0530                                     << "No HLT information produced";
0531       goodHlt = false;
0532     }
0533   }
0534 
0535   // Produce HLT paths and determine status of modules
0536 
0537   if (goodHlt) {
0538     // Extract pre-scales
0539     // Start from lumi
0540     trigger::HLTPrescaleTable hltPrescaleTable(
0541         hltPrescaleTableLumi_.set(), hltPrescaleTableLumi_.labels(), hltPrescaleTableLumi_.table());
0542     // Try event product, if configured and available
0543     if (!labelHltPrescaleTable_.empty()) {
0544       Handle<trigger::HLTPrescaleTable> handleHltPrescaleTable;
0545       iEvent.getByLabel(InputTag(labelHltPrescaleTable_, "Event", nameProcess_), handleHltPrescaleTable);
0546       if (handleHltPrescaleTable.isValid()) {
0547         hltPrescaleTable = trigger::HLTPrescaleTable(
0548             handleHltPrescaleTable->set(), handleHltPrescaleTable->labels(), handleHltPrescaleTable->table());
0549       }
0550     }
0551     // Try event setup, if no product
0552     if (hltPrescaleTable.size() == 0) {
0553       if (!labelHltPrescaleTable_.empty()) {
0554         LogWarning("hltPrescaleInputTag") << "HLTPrescaleTable product with label '" << labelHltPrescaleTable_
0555                                           << "' not found in process" << nameProcess_ << "\n"
0556                                           << "Using default from event setup";
0557       }
0558       if (hltConfig.prescaleSize() > 0) {
0559         if (hltPrescaleProvider_.prescaleSet(iEvent, iSetup) != -1) {
0560           hltPrescaleTable = trigger::HLTPrescaleTable(
0561               hltPrescaleProvider_.prescaleSet(iEvent, iSetup), hltConfig.prescaleLabels(), {});
0562           LogDebug("hltPrescaleTable") << "HLT prescale table found in event setup";
0563         } else {
0564           LogWarning("hltPrescaleSet") << "HLTPrescaleTable from event setup has error";
0565         }
0566       }
0567     }
0568     unsigned set(hltPrescaleTable.set());
0569     if (hltPrescaleTable.size() > 0) {
0570       if (!hltPrescaleLabel_.empty()) {
0571         bool foundPrescaleLabel(false);
0572         for (unsigned iLabel = 0; iLabel < hltPrescaleTable.labels().size(); ++iLabel) {
0573           if (hltPrescaleTable.labels().at(iLabel) == hltPrescaleLabel_) {
0574             set = iLabel;
0575             foundPrescaleLabel = true;
0576             break;
0577           }
0578         }
0579         if (!foundPrescaleLabel) {
0580           LogWarning("hltPrescaleLabel") << "HLT prescale label '" << hltPrescaleLabel_ << "' not in prescale table\n"
0581                                          << "Using default";
0582         }
0583       }
0584     } else if (iEvent.isRealData()) {
0585       if ((labelHltPrescaleTable_.empty() && firstInRun_) || !labelHltPrescaleTable_.empty()) {
0586         LogError("hltPrescaleTable") << "No HLT prescale table found\n"
0587                                      << "Using default empty table with all prescales 1";
0588       }
0589     }
0590 
0591     const unsigned sizePaths(hltConfig.size());
0592     const unsigned sizeFilters(handleTriggerEvent->sizeFilters());
0593     const unsigned sizeObjects(handleTriggerEvent->sizeObjects());
0594 
0595     std::map<std::string, int> moduleStates;
0596 
0597     if (!onlyStandAlone_) {
0598       auto triggerPaths = std::make_unique<TriggerPathCollection>();
0599       triggerPaths->reserve(sizePaths);
0600       const std::vector<std::string>& pathNames = hltConfig.triggerNames();
0601       for (size_t indexPath = 0; indexPath < sizePaths; ++indexPath) {
0602         const std::string& namePath = pathNames.at(indexPath);
0603         unsigned indexLastFilterPathModules(handleTriggerResults->index(indexPath) + 1);
0604         const unsigned sizeModulesPath(hltConfig.size(indexPath));
0605         //protection for paths with zero filters (needed for reco, digi, etc paths)
0606         if (sizeModulesPath != 0) {
0607           while (indexLastFilterPathModules > 0) {
0608             --indexLastFilterPathModules;
0609             const std::string& labelLastFilterPathModules(hltConfig.moduleLabel(indexPath, indexLastFilterPathModules));
0610             unsigned indexLastFilterFilters =
0611                 handleTriggerEvent->filterIndex(InputTag(labelLastFilterPathModules, "", nameProcess_));
0612             if (indexLastFilterFilters < sizeFilters) {
0613               if (hltConfig.moduleType(labelLastFilterPathModules) == "HLTBool")
0614                 continue;
0615               break;
0616             }
0617           }
0618         } else {
0619           indexLastFilterPathModules = 0;
0620         }
0621         TriggerPath triggerPath(namePath,
0622                                 indexPath,
0623                                 hltConfig.prescaleValue<double>(set, namePath),
0624                                 handleTriggerResults->wasrun(indexPath),
0625                                 handleTriggerResults->accept(indexPath),
0626                                 handleTriggerResults->error(indexPath),
0627                                 indexLastFilterPathModules,
0628                                 hltConfig.saveTagsModules(namePath).size());
0629         // add module names to path and states' map
0630 
0631         assert(indexLastFilterPathModules < sizeModulesPath || sizeModulesPath == 0);
0632         std::map<unsigned, std::string> indicesModules;
0633         for (size_t iM = 0; iM < sizeModulesPath; ++iM) {
0634           const std::string& nameModule(hltConfig.moduleLabel(indexPath, iM));
0635           if (addPathModuleLabels_) {
0636             triggerPath.addModule(nameModule);
0637           }
0638           const unsigned indexFilter(handleTriggerEvent->filterIndex(InputTag(nameModule, "", nameProcess_)));
0639           if (indexFilter < sizeFilters) {
0640             triggerPath.addFilterIndex(indexFilter);
0641           }
0642           const unsigned slotModule(hltConfig.moduleIndex(indexPath, nameModule));
0643           indicesModules.insert(std::pair<unsigned, std::string>(slotModule, nameModule));
0644         }
0645         // add L1 seeds
0646         const L1SeedCollection& l1Seeds(hltConfig.hltL1GTSeeds(namePath));
0647         for (L1SeedCollection::const_iterator iSeed = l1Seeds.begin(); iSeed != l1Seeds.end(); ++iSeed) {
0648           triggerPath.addL1Seed(*iSeed);
0649         }
0650         // store path
0651         triggerPaths->push_back(triggerPath);
0652         // cache module states to be used for the filters
0653         for (std::map<unsigned, std::string>::const_iterator iM = indicesModules.begin(); iM != indicesModules.end();
0654              ++iM) {
0655           if (iM->first < indexLastFilterPathModules) {
0656             moduleStates[iM->second] = 1;
0657           } else if (iM->first == indexLastFilterPathModules) {
0658             moduleStates[iM->second] = handleTriggerResults->accept(indexPath);
0659           } else if (moduleStates.find(iM->second) == moduleStates.end()) {
0660             moduleStates[iM->second] = -1;
0661           }
0662         }
0663       }
0664       // Put HLT paths to event
0665       iEvent.put(std::move(triggerPaths));
0666     }
0667 
0668     // Store used trigger objects and their types for HLT filters
0669     // (only active filter(s) available from trigger::TriggerEvent)
0670 
0671     std::multimap<trigger::size_type, int> objectTypes;
0672     std::multimap<trigger::size_type, std::string> filterLabels;
0673 
0674     for (size_t iF = 0; iF < sizeFilters; ++iF) {
0675       const std::string nameFilter(handleTriggerEvent->filterLabel(iF));
0676       const trigger::Keys& keys = handleTriggerEvent->filterKeys(iF);
0677       const trigger::Vids& types = handleTriggerEvent->filterIds(iF);
0678       assert(types.size() == keys.size());
0679       for (size_t iK = 0; iK < keys.size(); ++iK) {
0680         filterLabels.insert(std::pair<trigger::size_type, std::string>(keys[iK], nameFilter));
0681         objectTypes.insert(std::pair<trigger::size_type, int>(keys[iK], types[iK]));
0682       }
0683     }
0684 
0685     // HLT objects
0686 
0687     triggerObjects->reserve(onlyStandAlone_ ? 0 : sizeObjects);
0688     triggerObjectsStandAlone->reserve(sizeObjects);
0689 
0690     const trigger::Keys& collectionKeys(handleTriggerEvent->collectionKeys());
0691     std::map<trigger::size_type, trigger::size_type> newObjectKeys;
0692     for (size_t iO = 0, iC = 0, nC = handleTriggerEvent->sizeCollections(); iO < sizeObjects && iC < nC; ++iO) {
0693       const trigger::TriggerObject tobj = handleTriggerEvent->getObjects().at(iO);
0694       TriggerObject triggerObject(reco::Particle::PolarLorentzVector(tobj.pt(), tobj.eta(), tobj.phi(), tobj.mass()),
0695                                   tobj.id());
0696       // set collection
0697       while (iO >= collectionKeys[iC])
0698         ++iC;  // relies on well ordering of trigger objects with respect to the collections
0699       triggerObject.setCollection(handleTriggerEvent->collectionTagEncoded(iC));
0700       // set filter ID
0701       typedef std::multimap<trigger::size_type, int>::const_iterator it_type;
0702       for (std::pair<it_type, it_type> trange = objectTypes.equal_range(iO); trange.first != trange.second;
0703            ++trange.first) {
0704         triggerObject.addTriggerObjectType(trange.first->second);
0705       }
0706 
0707       // stand-alone trigger object
0708       TriggerObjectStandAlone triggerObjectStandAlone(triggerObject);
0709       // check for excluded collections
0710       bool excluded(false);
0711       for (size_t iE = 0; iE < exludeCollections_.size(); ++iE) {
0712         if (triggerObjectStandAlone.hasCollection(exludeCollections_.at(iE))) {
0713           if (!onlyStandAlone_)
0714             newObjectKeys[iO] = trigger::size_type(sizeObjects);
0715           excluded = true;
0716           break;
0717         }
0718       }
0719       if (excluded)
0720         continue;
0721       typedef std::multimap<trigger::size_type, std::string>::const_iterator it_fl;
0722       for (std::pair<it_fl, it_fl> frange = filterLabels.equal_range(iO); frange.first != frange.second;
0723            ++frange.first) {
0724         triggerObjectStandAlone.addFilterLabel(frange.first->second);
0725         const std::vector<ModuleLabelToPathAndFlags::PathAndFlags>& paths =
0726             moduleLabelToPathAndFlags_[frange.first->second];
0727         for (std::vector<ModuleLabelToPathAndFlags::PathAndFlags>::const_iterator iP = paths.begin(); iP != paths.end();
0728              ++iP) {
0729           bool pathFired = handleTriggerResults->wasrun(iP->pathIndex) && handleTriggerResults->accept(iP->pathIndex);
0730           triggerObjectStandAlone.addPathName(iP->pathName, pathFired && iP->lastFilter, pathFired && iP->l3Filter);
0731         }
0732       }
0733 
0734       triggerObjectsStandAlone->push_back(triggerObjectStandAlone);
0735       if (!onlyStandAlone_) {
0736         triggerObjects->push_back(triggerObject);
0737         newObjectKeys[iO] = trigger::size_type(triggerObjects->size() - 1);
0738       }
0739     }
0740 
0741     // Re-iterate HLT filters and finally produce them in order to account for optionally skipped objects
0742     if (!onlyStandAlone_) {
0743       auto triggerFilters = std::make_unique<TriggerFilterCollection>();
0744       triggerFilters->reserve(sizeFilters);
0745       for (size_t iF = 0; iF < sizeFilters; ++iF) {
0746         const std::string nameFilter(handleTriggerEvent->filterLabel(iF));
0747         const trigger::Keys& keys = handleTriggerEvent->filterKeys(iF);  // not cached
0748         const trigger::Vids& types = handleTriggerEvent->filterIds(iF);  // not cached
0749         TriggerFilter triggerFilter(nameFilter);
0750         // set filter type
0751         const std::string typeFilter(hltConfig.moduleType(nameFilter));
0752         triggerFilter.setType(typeFilter);
0753         triggerFilter.setSaveTags(hltConfig.saveTags(nameFilter));
0754         // set keys and trigger object types of used objects
0755         for (size_t iK = 0; iK < keys.size(); ++iK) {  // identical to types.size()
0756           // check, if current object is excluded
0757           if (newObjectKeys.find(keys.at(iK)) != newObjectKeys.end()) {
0758             if (newObjectKeys[keys.at(iK)] == sizeObjects)
0759               continue;
0760             triggerFilter.addObjectKey(newObjectKeys[keys.at(iK)]);
0761             triggerFilter.addTriggerObjectType(types.at(iK));
0762           } else {
0763             LogWarning("triggerObjectKey") << "TriggerFilter '" << nameFilter
0764                                            << "' requests non-existing TriggerObject key " << keys.at(iK) << "\n"
0765                                            << "Skipping object assignment";
0766           }
0767         }
0768         // set status from path info
0769         std::map<std::string, int>::iterator iS(moduleStates.find(nameFilter));
0770         if (iS != moduleStates.end()) {
0771           if (!triggerFilter.setStatus(iS->second)) {
0772             triggerFilter.setStatus(-1);  // FIXME different code for "unvalid status determined" needed?
0773           }
0774         } else {
0775           triggerFilter.setStatus(-1);  // FIXME different code for "unknown" needed?
0776         }
0777         // store filter
0778         triggerFilters->push_back(triggerFilter);
0779       }
0780       // put HLT filters to event
0781       iEvent.put(std::move(triggerFilters));
0782     }
0783 
0784     if (packPrescales_) {
0785       packedPrescales = std::make_unique<PackedTriggerPrescales>(handleTriggerResults);
0786       packedPrescalesL1min = std::make_unique<PackedTriggerPrescales>(handleTriggerResults);
0787       packedPrescalesL1max = std::make_unique<PackedTriggerPrescales>(handleTriggerResults);
0788       const edm::TriggerNames& names = iEvent.triggerNames(*handleTriggerResults);
0789       for (unsigned int i = 0, n = names.size(); i < n; ++i) {
0790         auto pvdet = hltPrescaleProvider_.prescaleValuesInDetail<double, double>(iEvent, iSetup, names.triggerName(i));
0791         if (pvdet.first.empty()) {
0792           packedPrescalesL1max->addPrescaledTrigger(i, 1);
0793           packedPrescalesL1min->addPrescaledTrigger(i, 1);
0794         } else {
0795           double pmin = -1, pmax = -1;
0796           for (const auto& p : pvdet.first) {
0797             pmax = std::max(pmax, p.second);
0798             if (p.second > 0 && (pmin == -1 || pmin > p.second))
0799               pmin = p.second;
0800           }
0801           packedPrescalesL1max->addPrescaledTrigger(i, pmax);
0802           packedPrescalesL1min->addPrescaledTrigger(i, pmin);
0803         }
0804         packedPrescales->addPrescaledTrigger(i, pvdet.second);
0805       }
0806       iEvent.put(std::move(packedPrescales));
0807       iEvent.put(std::move(packedPrescalesL1max), "l1max");
0808       iEvent.put(std::move(packedPrescalesL1min), "l1min");
0809     }
0810 
0811   }  // if ( goodHlt )
0812 
0813   // L1 objects
0814   // (needs to be done after HLT objects, since their x-links with filters rely on their collection keys)
0815 
0816   // map for assignments of objects to conditions
0817   std::map<L1GtObject, std::vector<unsigned> > l1ObjectTypeMap;
0818   if (!tagL1ExtraMu_.label().empty()) {
0819     Handle<l1extra::L1MuonParticleCollection> handleL1ExtraMu;
0820     iEvent.getByLabel(tagL1ExtraMu_, handleL1ExtraMu);
0821     if (handleL1ExtraMu.isValid()) {
0822       std::vector<unsigned> muKeys;
0823       for (size_t l1Mu = 0; l1Mu < handleL1ExtraMu->size(); ++l1Mu) {
0824         if (mainBxOnly_ && handleL1ExtraMu->at(l1Mu).bx() != 0)
0825           continue;
0826         TriggerObject triggerObject;
0827         if (saveL1Refs_) {
0828           const reco::CandidateBaseRef leafCandRef(l1extra::L1MuonParticleRef(handleL1ExtraMu, l1Mu));
0829           triggerObject = TriggerObject(leafCandRef);
0830         } else {
0831           const reco::LeafCandidate leafCandidate(*(handleL1ExtraMu->at(l1Mu).reco::LeafCandidate::clone()));
0832           triggerObject = TriggerObject(leafCandidate);
0833         }
0834         triggerObject.setCollection(tagL1ExtraMu_);
0835         triggerObject.addTriggerObjectType(trigger::TriggerL1Mu);
0836         if (!onlyStandAlone_)
0837           triggerObjects->push_back(triggerObject);
0838         TriggerObjectStandAlone triggerObjectStandAlone(triggerObject);
0839         triggerObjectsStandAlone->push_back(triggerObjectStandAlone);
0840         if (handleL1ExtraMu->at(l1Mu).bx() == 0)
0841           muKeys.push_back(triggerObjectsStandAlone->size() - 1);
0842       }
0843       l1ObjectTypeMap.insert(std::make_pair(Mu, muKeys));
0844     } else
0845       LogError("l1ExtraValid") << "l1extra::L1MuonParticleCollection product with InputTag '" << tagL1ExtraMu_.encode()
0846                                << "' not in event";
0847   }
0848   if (!tagL1ExtraNoIsoEG_.label().empty()) {
0849     Handle<l1extra::L1EmParticleCollection> handleL1ExtraNoIsoEG;
0850     iEvent.getByLabel(tagL1ExtraNoIsoEG_, handleL1ExtraNoIsoEG);
0851     if (handleL1ExtraNoIsoEG.isValid()) {
0852       std::vector<unsigned> noIsoEGKeys;
0853       for (size_t l1NoIsoEG = 0; l1NoIsoEG < handleL1ExtraNoIsoEG->size(); ++l1NoIsoEG) {
0854         if (mainBxOnly_ && handleL1ExtraNoIsoEG->at(l1NoIsoEG).bx() != 0)
0855           continue;
0856         TriggerObject triggerObject;
0857         if (saveL1Refs_) {
0858           const reco::CandidateBaseRef leafCandRef(l1extra::L1EmParticleRef(handleL1ExtraNoIsoEG, l1NoIsoEG));
0859           triggerObject = TriggerObject(leafCandRef);
0860         } else {
0861           const reco::LeafCandidate leafCandidate(*(handleL1ExtraNoIsoEG->at(l1NoIsoEG).reco::LeafCandidate::clone()));
0862           triggerObject = TriggerObject(leafCandidate);
0863         }
0864         triggerObject.setCollection(tagL1ExtraNoIsoEG_);
0865         triggerObject.addTriggerObjectType(trigger::TriggerL1NoIsoEG);
0866         if (!onlyStandAlone_)
0867           triggerObjects->push_back(triggerObject);
0868         TriggerObjectStandAlone triggerObjectStandAlone(triggerObject);
0869         triggerObjectsStandAlone->push_back(triggerObjectStandAlone);
0870         if (handleL1ExtraNoIsoEG->at(l1NoIsoEG).bx() == 0)
0871           noIsoEGKeys.push_back(triggerObjectsStandAlone->size() - 1);
0872       }
0873       l1ObjectTypeMap.insert(std::make_pair(NoIsoEG, noIsoEGKeys));
0874     } else
0875       LogError("l1ExtraValid") << "l1extra::L1EmParticleCollection product with InputTag '"
0876                                << tagL1ExtraNoIsoEG_.encode() << "' not in event";
0877   }
0878   if (!tagL1ExtraIsoEG_.label().empty()) {
0879     Handle<l1extra::L1EmParticleCollection> handleL1ExtraIsoEG;
0880     iEvent.getByLabel(tagL1ExtraIsoEG_, handleL1ExtraIsoEG);
0881     if (handleL1ExtraIsoEG.isValid()) {
0882       std::vector<unsigned> isoEGKeys;
0883       for (size_t l1IsoEG = 0; l1IsoEG < handleL1ExtraIsoEG->size(); ++l1IsoEG) {
0884         if (mainBxOnly_ && handleL1ExtraIsoEG->at(l1IsoEG).bx() != 0)
0885           continue;
0886         TriggerObject triggerObject;
0887         if (saveL1Refs_) {
0888           const reco::CandidateBaseRef leafCandRef(l1extra::L1EmParticleRef(handleL1ExtraIsoEG, l1IsoEG));
0889           triggerObject = TriggerObject(leafCandRef);
0890         } else {
0891           const reco::LeafCandidate leafCandidate(*(handleL1ExtraIsoEG->at(l1IsoEG).reco::LeafCandidate::clone()));
0892           triggerObject = TriggerObject(leafCandidate);
0893         }
0894         triggerObject.setCollection(tagL1ExtraIsoEG_);
0895         triggerObject.addTriggerObjectType(trigger::TriggerL1IsoEG);
0896         if (!onlyStandAlone_)
0897           triggerObjects->push_back(triggerObject);
0898         TriggerObjectStandAlone triggerObjectStandAlone(triggerObject);
0899         triggerObjectsStandAlone->push_back(triggerObjectStandAlone);
0900         if (handleL1ExtraIsoEG->at(l1IsoEG).bx() == 0)
0901           isoEGKeys.push_back(triggerObjectsStandAlone->size() - 1);
0902       }
0903       l1ObjectTypeMap.insert(std::make_pair(IsoEG, isoEGKeys));
0904     } else
0905       LogError("l1ExtraValid") << "l1extra::L1EmParticleCollection product with InputTag '" << tagL1ExtraIsoEG_.encode()
0906                                << "' not in event";
0907   }
0908   if (!tagL1ExtraCenJet_.label().empty()) {
0909     Handle<l1extra::L1JetParticleCollection> handleL1ExtraCenJet;
0910     iEvent.getByLabel(tagL1ExtraCenJet_, handleL1ExtraCenJet);
0911     if (handleL1ExtraCenJet.isValid()) {
0912       std::vector<unsigned> cenJetKeys;
0913       for (size_t l1CenJet = 0; l1CenJet < handleL1ExtraCenJet->size(); ++l1CenJet) {
0914         if (mainBxOnly_ && handleL1ExtraCenJet->at(l1CenJet).bx() != 0)
0915           continue;
0916         TriggerObject triggerObject;
0917         if (saveL1Refs_) {
0918           const reco::CandidateBaseRef leafCandRef(l1extra::L1JetParticleRef(handleL1ExtraCenJet, l1CenJet));
0919           triggerObject = TriggerObject(leafCandRef);
0920         } else {
0921           const reco::LeafCandidate leafCandidate(*(handleL1ExtraCenJet->at(l1CenJet).reco::LeafCandidate::clone()));
0922           triggerObject = TriggerObject(leafCandidate);
0923         }
0924         triggerObject.setCollection(tagL1ExtraCenJet_);
0925         triggerObject.addTriggerObjectType(trigger::TriggerL1CenJet);
0926         if (!onlyStandAlone_)
0927           triggerObjects->push_back(triggerObject);
0928         TriggerObjectStandAlone triggerObjectStandAlone(triggerObject);
0929         triggerObjectsStandAlone->push_back(triggerObjectStandAlone);
0930         if (handleL1ExtraCenJet->at(l1CenJet).bx() == 0)
0931           cenJetKeys.push_back(triggerObjectsStandAlone->size() - 1);
0932       }
0933       l1ObjectTypeMap.insert(std::make_pair(CenJet, cenJetKeys));
0934     } else
0935       LogError("l1ExtraValid") << "l1extra::L1JetParticleCollection product with InputTag '"
0936                                << tagL1ExtraCenJet_.encode() << "' not in event";
0937   }
0938   if (!tagL1ExtraForJet_.label().empty()) {
0939     Handle<l1extra::L1JetParticleCollection> handleL1ExtraForJet;
0940     iEvent.getByLabel(tagL1ExtraForJet_, handleL1ExtraForJet);
0941     if (handleL1ExtraForJet.isValid()) {
0942       std::vector<unsigned> forJetKeys;
0943       for (size_t l1ForJet = 0; l1ForJet < handleL1ExtraForJet->size(); ++l1ForJet) {
0944         if (mainBxOnly_ && handleL1ExtraForJet->at(l1ForJet).bx() != 0)
0945           continue;
0946         TriggerObject triggerObject;
0947         if (saveL1Refs_) {
0948           const reco::CandidateBaseRef leafCandRef(l1extra::L1JetParticleRef(handleL1ExtraForJet, l1ForJet));
0949           triggerObject = TriggerObject(leafCandRef);
0950         } else {
0951           const reco::LeafCandidate leafCandidate(*(handleL1ExtraForJet->at(l1ForJet).reco::LeafCandidate::clone()));
0952           triggerObject = TriggerObject(leafCandidate);
0953         }
0954         triggerObject.setCollection(tagL1ExtraForJet_);
0955         triggerObject.addTriggerObjectType(trigger::TriggerL1ForJet);
0956         if (!onlyStandAlone_)
0957           triggerObjects->push_back(triggerObject);
0958         TriggerObjectStandAlone triggerObjectStandAlone(triggerObject);
0959         triggerObjectsStandAlone->push_back(triggerObjectStandAlone);
0960         if (handleL1ExtraForJet->at(l1ForJet).bx() == 0)
0961           forJetKeys.push_back(triggerObjectsStandAlone->size() - 1);
0962       }
0963       l1ObjectTypeMap.insert(std::make_pair(ForJet, forJetKeys));
0964     } else
0965       LogError("l1ExtraValid") << "l1extra::L1JetParticleCollection product with InputTag '"
0966                                << tagL1ExtraForJet_.encode() << "' not in event";
0967   }
0968   if (!tagL1ExtraTauJet_.label().empty()) {
0969     Handle<l1extra::L1JetParticleCollection> handleL1ExtraTauJet;
0970     iEvent.getByLabel(tagL1ExtraTauJet_, handleL1ExtraTauJet);
0971     if (handleL1ExtraTauJet.isValid()) {
0972       std::vector<unsigned> tauJetKeys;
0973       for (size_t l1TauJet = 0; l1TauJet < handleL1ExtraTauJet->size(); ++l1TauJet) {
0974         if (mainBxOnly_ && handleL1ExtraTauJet->at(l1TauJet).bx() != 0)
0975           continue;
0976         TriggerObject triggerObject;
0977         if (saveL1Refs_) {
0978           const reco::CandidateBaseRef leafCandRef(l1extra::L1JetParticleRef(handleL1ExtraTauJet, l1TauJet));
0979           triggerObject = TriggerObject(leafCandRef);
0980         } else {
0981           const reco::LeafCandidate leafCandidate(*(handleL1ExtraTauJet->at(l1TauJet).reco::LeafCandidate::clone()));
0982           triggerObject = TriggerObject(leafCandidate);
0983         }
0984         triggerObject.setCollection(tagL1ExtraTauJet_);
0985         triggerObject.addTriggerObjectType(trigger::TriggerL1TauJet);
0986         if (!onlyStandAlone_)
0987           triggerObjects->push_back(triggerObject);
0988         TriggerObjectStandAlone triggerObjectStandAlone(triggerObject);
0989         triggerObjectsStandAlone->push_back(triggerObjectStandAlone);
0990         if (handleL1ExtraTauJet->at(l1TauJet).bx() == 0)
0991           tauJetKeys.push_back(triggerObjectsStandAlone->size() - 1);
0992       }
0993       l1ObjectTypeMap.insert(std::make_pair(TauJet, tauJetKeys));
0994     } else
0995       LogError("l1ExtraValid") << "l1extra::L1JetParticleCollection product with InputTag '"
0996                                << tagL1ExtraTauJet_.encode() << "' not in event";
0997   }
0998   if (!tagL1ExtraETM_.label().empty()) {
0999     Handle<l1extra::L1EtMissParticleCollection> handleL1ExtraETM;
1000     iEvent.getByLabel(tagL1ExtraETM_, handleL1ExtraETM);
1001     if (handleL1ExtraETM.isValid()) {
1002       std::vector<unsigned> etmKeys;
1003       for (size_t l1ETM = 0; l1ETM < handleL1ExtraETM->size(); ++l1ETM) {
1004         if (mainBxOnly_ && handleL1ExtraETM->at(l1ETM).bx() != 0)
1005           continue;
1006         TriggerObject triggerObject;
1007         if (saveL1Refs_) {
1008           const reco::CandidateBaseRef leafCandRef(l1extra::L1EtMissParticleRef(handleL1ExtraETM, l1ETM));
1009           triggerObject = TriggerObject(leafCandRef);
1010         } else {
1011           const reco::LeafCandidate leafCandidate(*(handleL1ExtraETM->at(l1ETM).reco::LeafCandidate::clone()));
1012           triggerObject = TriggerObject(leafCandidate);
1013         }
1014         triggerObject.setCollection(tagL1ExtraETM_);
1015         triggerObject.addTriggerObjectType(trigger::TriggerL1ETM);
1016         if (!onlyStandAlone_)
1017           triggerObjects->push_back(triggerObject);
1018         TriggerObjectStandAlone triggerObjectStandAlone(triggerObject);
1019         triggerObjectsStandAlone->push_back(triggerObjectStandAlone);
1020         if (handleL1ExtraETM->at(l1ETM).bx() == 0)
1021           etmKeys.push_back(triggerObjectsStandAlone->size() - 1);
1022       }
1023       l1ObjectTypeMap.insert(std::make_pair(ETM, etmKeys));
1024     } else
1025       LogError("l1ExtraValid") << "l1extra::L1EtMissParticleCollection product with InputTag '"
1026                                << tagL1ExtraETM_.encode() << "' not in event";
1027   }
1028   if (!tagL1ExtraHTM_.label().empty()) {
1029     Handle<l1extra::L1EtMissParticleCollection> handleL1ExtraHTM;
1030     iEvent.getByLabel(tagL1ExtraHTM_, handleL1ExtraHTM);
1031     if (handleL1ExtraHTM.isValid()) {
1032       std::vector<unsigned> htmKeys;
1033       for (size_t l1HTM = 0; l1HTM < handleL1ExtraHTM->size(); ++l1HTM) {
1034         if (mainBxOnly_ && handleL1ExtraHTM->at(l1HTM).bx() != 0)
1035           continue;
1036         TriggerObject triggerObject;
1037         if (saveL1Refs_) {
1038           const reco::CandidateBaseRef leafCandRef(l1extra::L1EtMissParticleRef(handleL1ExtraHTM, l1HTM));
1039           triggerObject = TriggerObject(leafCandRef);
1040         } else {
1041           const reco::LeafCandidate leafCandidate(*(handleL1ExtraHTM->at(l1HTM).reco::LeafCandidate::clone()));
1042           triggerObject = TriggerObject(leafCandidate);
1043         }
1044         triggerObject.setCollection(tagL1ExtraHTM_);
1045         triggerObject.addTriggerObjectType(trigger::TriggerL1HTM);
1046         if (!onlyStandAlone_)
1047           triggerObjects->push_back(triggerObject);
1048         TriggerObjectStandAlone triggerObjectStandAlone(triggerObject);
1049         triggerObjectsStandAlone->push_back(triggerObjectStandAlone);
1050         if (handleL1ExtraHTM->at(l1HTM).bx() == 0)
1051           htmKeys.push_back(triggerObjectsStandAlone->size() - 1);
1052       }
1053       l1ObjectTypeMap.insert(std::make_pair(HTM, htmKeys));
1054     } else
1055       LogError("l1ExtraValid") << "l1extra::L1EtMissParticleCollection product with InputTag '"
1056                                << tagL1ExtraHTM_.encode() << "' not in event";
1057   }
1058 
1059   // Put trigger objects to event
1060   if (!onlyStandAlone_)
1061     iEvent.put(std::move(triggerObjects));
1062 
1063   // L1 algorithms
1064   if (!onlyStandAlone_) {
1065     auto triggerAlgos = std::make_unique<TriggerAlgorithmCollection>();
1066     auto triggerConditions = std::make_unique<TriggerConditionCollection>();
1067     if (addL1Algos_) {
1068       // create trigger object types transalation map (yes, it's ugly!)
1069       std::map<L1GtObject, trigger::TriggerObjectType> mapObjectTypes;
1070       mapObjectTypes.insert(std::make_pair(Mu, trigger::TriggerL1Mu));
1071       mapObjectTypes.insert(std::make_pair(NoIsoEG, trigger::TriggerL1NoIsoEG));
1072       mapObjectTypes.insert(std::make_pair(IsoEG, trigger::TriggerL1IsoEG));
1073       mapObjectTypes.insert(std::make_pair(CenJet, trigger::TriggerL1CenJet));
1074       mapObjectTypes.insert(std::make_pair(ForJet, trigger::TriggerL1ForJet));
1075       mapObjectTypes.insert(std::make_pair(TauJet, trigger::TriggerL1TauJet));
1076       mapObjectTypes.insert(std::make_pair(ETM, trigger::TriggerL1ETM));
1077       mapObjectTypes.insert(std::make_pair(HTM, trigger::TriggerL1HTM));
1078       // get and cache L1 menu
1079       L1GtUtils const& l1GtUtils = hltPrescaleProvider_.l1GtUtils();
1080       auto handleL1GtTriggerMenu = iSetup.getHandle(handleL1GtTriggerMenuToken_);
1081       auto const& l1GtAlgorithms = handleL1GtTriggerMenu->gtAlgorithmMap();
1082       auto const& l1GtTechTriggers = handleL1GtTriggerMenu->gtTechnicalTriggerMap();
1083       auto const& l1GtConditionsVector = handleL1GtTriggerMenu->gtConditionMap();
1084       // cache conditions in one single condition map
1085       ConditionMap l1GtConditions;
1086       for (size_t iCv = 0; iCv < l1GtConditionsVector.size(); ++iCv) {
1087         l1GtConditions.insert(l1GtConditionsVector.at(iCv).begin(), l1GtConditionsVector.at(iCv).end());
1088       }
1089       triggerAlgos->reserve(l1GtAlgorithms.size() + l1GtTechTriggers.size());
1090       Handle<L1GlobalTriggerObjectMaps> handleL1GlobalTriggerObjectMaps;
1091       iEvent.getByToken(l1GlobalTriggerObjectMapsToken_, handleL1GlobalTriggerObjectMaps);
1092       if (!handleL1GlobalTriggerObjectMaps.isValid()) {
1093         LogError("l1ObjectMap") << "L1GlobalTriggerObjectMaps product with InputTag '"
1094                                 << tagL1GlobalTriggerObjectMaps_.encode() << "' not in event\n"
1095                                 << "No L1 objects and GTL results available for physics algorithms";
1096       }
1097       handleL1GlobalTriggerObjectMaps->consistencyCheck();
1098       if (firstInRun_) {
1099         l1PSet_ = (ParameterSet*)(pset::Registry::instance()->getMapped(
1100             handleL1GlobalTriggerObjectMaps->namesParameterSetID()));
1101         if (l1PSet_ == nullptr) {
1102           LogError("l1ObjectMap") << "ParameterSet registry not available\n"
1103                                   << "Skipping conditions for all L1 physics algorithm names in this run";
1104         }
1105       } else {
1106         if (l1PSet_ == nullptr) {
1107           LogInfo("l1ObjectMap") << "ParameterSet registry not available\n"
1108                                  << "Skipping conditions for all L1 physics algorithm names in this event";
1109         }
1110       }
1111       // physics algorithms
1112       for (CItAlgo iAlgo = l1GtAlgorithms.begin(); iAlgo != l1GtAlgorithms.end(); ++iAlgo) {
1113         const std::string& algoName(iAlgo->second.algoName());
1114         if (!(iAlgo->second.algoBitNumber() < int(L1GlobalTriggerReadoutSetup::NumberPhysTriggers))) {
1115           LogError("l1Algo") << "L1 physics algorithm '" << algoName << "' has bit number "
1116                              << iAlgo->second.algoBitNumber()
1117                              << " >= " << L1GlobalTriggerReadoutSetup::NumberPhysTriggers << "\n"
1118                              << "Skipping";
1119           continue;
1120         }
1121         L1GtUtils::TriggerCategory category;
1122         int bit;
1123         if (!l1GtUtils.l1AlgoTechTrigBitNumber(algoName, category, bit)) {
1124           LogError("l1Algo") << "L1 physics algorithm '" << algoName << "' not found in the L1 menu\n"
1125                              << "Skipping";
1126           continue;
1127         }
1128         if (category != L1GtUtils::AlgorithmTrigger) {
1129           LogError("l1Algo") << "L1 physics algorithm '" << algoName
1130                              << "' does not have category 'AlgorithmTrigger' from 'L1GtUtils'\n"
1131                              << "Skipping";
1132           continue;
1133         }
1134         bool decisionBeforeMask;
1135         bool decisionAfterMask;
1136         int prescale;
1137         int mask;
1138         int error(l1GtUtils.l1Results(iEvent, algoName, decisionBeforeMask, decisionAfterMask, prescale, mask));
1139         if (error) {
1140           LogError("l1Algo") << "L1 physics algorithm '" << algoName << "' decision has error code " << error
1141                              << " from 'L1GtUtils'\n"
1142                              << "Skipping";
1143           continue;
1144         }
1145         TriggerAlgorithm triggerAlgo(algoName,
1146                                      iAlgo->second.algoAlias(),
1147                                      category == L1GtUtils::TechnicalTrigger,
1148                                      (unsigned)bit,
1149                                      (unsigned)prescale,
1150                                      (bool)mask,
1151                                      decisionBeforeMask,
1152                                      decisionAfterMask);
1153         triggerAlgo.setLogicalExpression(iAlgo->second.algoLogicalExpression());
1154         // GTL result and used conditions in physics algorithm
1155         if (!handleL1GlobalTriggerObjectMaps.isValid()) {
1156           triggerAlgos->push_back(triggerAlgo);
1157           continue;  // LogWarning already earlier (before loop)
1158         }
1159         if (!handleL1GlobalTriggerObjectMaps->algorithmExists(bit)) {
1160           LogError("l1ObjectMap") << "L1 physics algorithm '" << algoName
1161                                   << "' is missing in L1GlobalTriggerObjectMaps\n"
1162                                   << "Skipping conditions and GTL result";
1163           triggerAlgos->push_back(triggerAlgo);
1164           continue;
1165         }
1166         bool algorithmResult = handleL1GlobalTriggerObjectMaps->algorithmResult(bit);
1167         //         if ( ( algorithmResult != decisionBeforeMask ) && ( decisionBeforeMask == true || prescale == 1 ) ) {
1168         if ((algorithmResult != decisionBeforeMask) &&
1169             (decisionBeforeMask == true)) {  // FIXME: understand the difference for un-prescaled algos 118, 119, 123
1170           LogInfo("l1ObjectMap") << "L1 physics algorithm '" << algoName << "' with different decisions in\n"
1171                                  << "L1GlobalTriggerObjectMaps (GTL result)        : " << algorithmResult << "\n"
1172                                  << "L1GlobalTriggerReadoutRecord (decision before mask): " << decisionBeforeMask;
1173         }
1174         triggerAlgo.setGtlResult(algorithmResult);
1175         // conditions in algorithm
1176         L1GlobalTriggerObjectMaps::ConditionsInAlgorithm conditions =
1177             handleL1GlobalTriggerObjectMaps->getConditionsInAlgorithm(bit);
1178         if (l1PSet_ == nullptr) {
1179           triggerAlgos->push_back(triggerAlgo);
1180           continue;
1181         }
1182         if (!l1PSet_->exists(algoName)) {
1183           if (firstInRun_) {
1184             LogError("l1ObjectMap") << "L1 physics algorithm name '" << algoName
1185                                     << "' not available in ParameterSet registry\n"
1186                                     << "Skipping conditions for this algorithm in this run";
1187           } else {
1188             LogInfo("l1ObjectMap") << "L1 physics algorithm name '" << algoName
1189                                    << "' not available in ParameterSet registry\n"
1190                                    << "Skipping conditions for this algorithm in this event";
1191           }
1192           triggerAlgos->push_back(triggerAlgo);
1193           continue;
1194         }
1195         std::vector<std::string> conditionNames(l1PSet_->getParameter<std::vector<std::string> >(algoName));
1196 
1197         for (unsigned iT = 0; iT < conditionNames.size(); ++iT) {
1198           size_t key(triggerConditions->size());
1199           for (size_t iC = 0; iC < triggerConditions->size(); ++iC) {
1200             if (conditionNames.at(iT) == triggerConditions->at(iC).name()) {
1201               key = iC;
1202               break;
1203             }
1204           }
1205           if (key == triggerConditions->size()) {
1206             if (iT >= conditions.nConditions()) {
1207               LogError("l1CondMap") << "More condition names from ParameterSet registry than the "
1208                                     << conditions.nConditions() << " conditions in L1GlobalTriggerObjectMaps\n"
1209                                     << "Skipping condition " << conditionNames.at(iT) << " in algorithm " << algoName;
1210               break;
1211             }
1212             TriggerCondition triggerCond(conditionNames[iT], conditions.getConditionResult(iT));
1213             if (l1GtConditions.find(triggerCond.name()) != l1GtConditions.end()) {
1214               triggerCond.setCategory(l1GtConditions[triggerCond.name()]->condCategory());
1215               triggerCond.setType(l1GtConditions[triggerCond.name()]->condType());
1216               const std::vector<L1GtObject> l1ObjectTypes(l1GtConditions[triggerCond.name()]->objectType());
1217               for (size_t iType = 0; iType < l1ObjectTypes.size(); ++iType) {
1218                 triggerCond.addTriggerObjectType(mapObjectTypes[l1ObjectTypes.at(iType)]);
1219               }
1220               // objects in condition
1221               L1GlobalTriggerObjectMaps::CombinationsInCondition combinations =
1222                   handleL1GlobalTriggerObjectMaps->getCombinationsInCondition(bit, iT);
1223               for (size_t iVV = 0; iVV < combinations.nCombinations(); ++iVV) {
1224                 for (size_t iV = 0; iV < combinations.nObjectsPerCombination(); ++iV) {
1225                   unsigned objectIndex = combinations.getObjectIndex(iVV, iV);
1226                   if (iV >= l1ObjectTypes.size()) {
1227                     LogError("l1CondMap") << "Index " << iV << " in combinations vector overshoots size "
1228                                           << l1ObjectTypes.size() << " of types vector in conditions map\n"
1229                                           << "Skipping object key in condition " << triggerCond.name();
1230                   } else if (l1ObjectTypeMap.find(l1ObjectTypes.at(iV)) != l1ObjectTypeMap.end()) {
1231                     if (objectIndex >= l1ObjectTypeMap[l1ObjectTypes.at(iV)].size()) {
1232                       LogError("l1CondMap")
1233                           << "Index " << objectIndex << " in combination overshoots number "
1234                           << l1ObjectTypeMap[l1ObjectTypes.at(iV)].size() << "of according trigger objects\n"
1235                           << "Skipping object key in condition " << triggerCond.name();
1236                     }
1237                     const unsigned objectKey(l1ObjectTypeMap[l1ObjectTypes.at(iV)].at(objectIndex));
1238                     triggerCond.addObjectKey(objectKey);
1239                     // add current condition and algorithm also to the according stand-alone trigger object
1240                     triggerObjectsStandAlone->at(objectKey).addAlgorithmName(
1241                         triggerAlgo.name(), (triggerAlgo.decision() && triggerCond.wasAccept()));
1242                     triggerObjectsStandAlone->at(objectKey).addConditionName(triggerCond.name());
1243                   }
1244                 }
1245               }
1246             } else {
1247               LogWarning("l1CondMap") << "L1 conditions '" << triggerCond.name() << "' not found in the L1 menu\n"
1248                                       << "Remains incomplete";
1249             }
1250             triggerConditions->push_back(triggerCond);
1251           }
1252           triggerAlgo.addConditionKey(key);
1253         }
1254         triggerAlgos->push_back(triggerAlgo);
1255       }
1256       // technical triggers
1257       for (CItAlgo iAlgo = l1GtTechTriggers.begin(); iAlgo != l1GtTechTriggers.end(); ++iAlgo) {
1258         const std::string& algoName(iAlgo->second.algoName());
1259         if (!(iAlgo->second.algoBitNumber() < int(L1GlobalTriggerReadoutSetup::NumberTechnicalTriggers))) {
1260           LogError("l1Algo") << "L1 technical trigger '" << algoName << "' has bit number "
1261                              << iAlgo->second.algoBitNumber()
1262                              << " >= " << L1GlobalTriggerReadoutSetup::NumberTechnicalTriggers << "\n"
1263                              << "Skipping";
1264           continue;
1265         }
1266         L1GtUtils::TriggerCategory category;
1267         int bit;
1268         if (!l1GtUtils.l1AlgoTechTrigBitNumber(algoName, category, bit)) {
1269           LogError("l1Algo") << "L1 technical trigger '" << algoName << "' not found in the L1 menu\n"
1270                              << "Skipping";
1271           continue;
1272         }
1273         if (category != L1GtUtils::TechnicalTrigger) {
1274           LogError("l1Algo") << "L1 technical trigger '" << algoName
1275                              << "' does not have category 'TechnicalTrigger' from 'L1GtUtils'\n"
1276                              << "Skipping";
1277           continue;
1278         }
1279         bool decisionBeforeMask;
1280         bool decisionAfterMask;
1281         int prescale;
1282         int mask;
1283         int error(l1GtUtils.l1Results(iEvent, algoName, decisionBeforeMask, decisionAfterMask, prescale, mask));
1284         if (error) {
1285           LogError("l1Algo") << "L1 technical trigger '" << algoName << "' decision has error code " << error
1286                              << " from 'L1GtUtils'\n"
1287                              << "Skipping";
1288           continue;
1289         }
1290         TriggerAlgorithm triggerAlgo(algoName,
1291                                      iAlgo->second.algoAlias(),
1292                                      category == L1GtUtils::TechnicalTrigger,
1293                                      (unsigned)bit,
1294                                      (unsigned)prescale,
1295                                      (bool)mask,
1296                                      decisionBeforeMask,
1297                                      decisionAfterMask);
1298         triggerAlgo.setLogicalExpression(iAlgo->second.algoLogicalExpression());
1299         triggerAlgos->push_back(triggerAlgo);
1300       }
1301     }
1302 
1303     // Put L1 algorithms and conditions to event
1304     iEvent.put(std::move(triggerAlgos));
1305     iEvent.put(std::move(triggerConditions));
1306   }
1307 
1308   edm::ProcessConfiguration config;
1309   iEvent.processHistory().getConfigurationForProcess(nameProcess_, config);
1310 
1311   const edm::TriggerNames& names = iEvent.triggerNames(*handleTriggerResults);
1312   for (pat::TriggerObjectStandAlone& obj : *triggerObjectsStandAlone) {
1313     obj.setPSetID(config.parameterSetID());
1314     if (packPathNames_)
1315       obj.packPathNames(names);
1316     if (packLabels_)
1317       obj.packFilterLabels(iEvent, *handleTriggerResults);
1318   }
1319 
1320   // Put (finally) stand-alone trigger objects to event
1321   iEvent.put(std::move(triggerObjectsStandAlone));
1322 
1323   firstInRun_ = false;
1324 }
1325 
1326 void PATTriggerProducer::ModuleLabelToPathAndFlags::init(const HLTConfigProvider& hltConfig) {
1327   clear();
1328   const std::vector<std::string>& pathNames = hltConfig.triggerNames();
1329   unsigned int sizePaths = pathNames.size();
1330   for (unsigned int indexPath = 0; indexPath < sizePaths; ++indexPath) {
1331     const std::string& namePath = pathNames[indexPath];
1332 
1333     const std::vector<std::string>& nameModules = hltConfig.moduleLabels(indexPath);
1334     unsigned int sizeModulesPath = nameModules.size();
1335     bool lastFilter = true;
1336     unsigned int iM = sizeModulesPath;
1337     while (iM > 0) {
1338       const std::string& nameFilter = nameModules[--iM];
1339       if (hltConfig.moduleEDMType(nameFilter) != "EDFilter")
1340         continue;
1341       if (hltConfig.moduleType(nameFilter) == "HLTBool")
1342         continue;
1343       bool saveTags = hltConfig.saveTags(nameFilter);
1344       insert(nameFilter, namePath, indexPath, lastFilter, saveTags);
1345       if (saveTags)
1346         lastFilter = false;  // FIXME: rather always?
1347     }
1348   }
1349 }
1350 
1351 #include "FWCore/Framework/interface/MakerMacros.h"
1352 DEFINE_FWK_MODULE(PATTriggerProducer);