Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-30 02:37:07

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(), hltConfig.prescaleTable());
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(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->filterTag(iF).label());
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       //std::cout << "Run " << iEvent.id().run() << ", LS " << iEvent.id().luminosityBlock() << ": pset " << set << std::endl;
0790       for (unsigned int i = 0, n = names.size(); i < n; ++i) {
0791         auto pvdet = hltPrescaleProvider_.prescaleValuesInDetail(iEvent, iSetup, names.triggerName(i));
0792         //int hltprescale = hltConfig_.prescaleValue(set, names.triggerName(i));
0793         if (pvdet.first.empty()) {
0794           packedPrescalesL1max->addPrescaledTrigger(i, 1);
0795           packedPrescalesL1min->addPrescaledTrigger(i, 1);
0796         } else {
0797           int pmin = -1, pmax = -1;
0798           for (const auto& p : pvdet.first) {
0799             pmax = std::max(pmax, p.second);
0800             if (p.second > 0 && (pmin == -1 || pmin > p.second))
0801               pmin = p.second;
0802           }
0803           packedPrescalesL1max->addPrescaledTrigger(i, pmax);
0804           packedPrescalesL1min->addPrescaledTrigger(i, pmin);
0805           //std::cout << "\tTrigger " << names.triggerName(i) << ", L1 ps " << pmin << "-" << pmax << ", HLT ps " << hltprescale << std::endl;
0806         }
0807         packedPrescales->addPrescaledTrigger(i, pvdet.second);
0808         //assert( hltprescale == pvdet.second );
0809       }
0810       iEvent.put(std::move(packedPrescales));
0811       iEvent.put(std::move(packedPrescalesL1max), "l1max");
0812       iEvent.put(std::move(packedPrescalesL1min), "l1min");
0813     }
0814 
0815   }  // if ( goodHlt )
0816 
0817   // L1 objects
0818   // (needs to be done after HLT objects, since their x-links with filters rely on their collection keys)
0819 
0820   // map for assignments of objects to conditions
0821   std::map<L1GtObject, std::vector<unsigned> > l1ObjectTypeMap;
0822   if (!tagL1ExtraMu_.label().empty()) {
0823     Handle<l1extra::L1MuonParticleCollection> handleL1ExtraMu;
0824     iEvent.getByLabel(tagL1ExtraMu_, handleL1ExtraMu);
0825     if (handleL1ExtraMu.isValid()) {
0826       std::vector<unsigned> muKeys;
0827       for (size_t l1Mu = 0; l1Mu < handleL1ExtraMu->size(); ++l1Mu) {
0828         if (mainBxOnly_ && handleL1ExtraMu->at(l1Mu).bx() != 0)
0829           continue;
0830         TriggerObject triggerObject;
0831         if (saveL1Refs_) {
0832           const reco::CandidateBaseRef leafCandRef(l1extra::L1MuonParticleRef(handleL1ExtraMu, l1Mu));
0833           triggerObject = TriggerObject(leafCandRef);
0834         } else {
0835           const reco::LeafCandidate leafCandidate(*(handleL1ExtraMu->at(l1Mu).reco::LeafCandidate::clone()));
0836           triggerObject = TriggerObject(leafCandidate);
0837         }
0838         triggerObject.setCollection(tagL1ExtraMu_);
0839         triggerObject.addTriggerObjectType(trigger::TriggerL1Mu);
0840         if (!onlyStandAlone_)
0841           triggerObjects->push_back(triggerObject);
0842         TriggerObjectStandAlone triggerObjectStandAlone(triggerObject);
0843         triggerObjectsStandAlone->push_back(triggerObjectStandAlone);
0844         if (handleL1ExtraMu->at(l1Mu).bx() == 0)
0845           muKeys.push_back(triggerObjectsStandAlone->size() - 1);
0846       }
0847       l1ObjectTypeMap.insert(std::make_pair(Mu, muKeys));
0848     } else
0849       LogError("l1ExtraValid") << "l1extra::L1MuonParticleCollection product with InputTag '" << tagL1ExtraMu_.encode()
0850                                << "' not in event";
0851   }
0852   if (!tagL1ExtraNoIsoEG_.label().empty()) {
0853     Handle<l1extra::L1EmParticleCollection> handleL1ExtraNoIsoEG;
0854     iEvent.getByLabel(tagL1ExtraNoIsoEG_, handleL1ExtraNoIsoEG);
0855     if (handleL1ExtraNoIsoEG.isValid()) {
0856       std::vector<unsigned> noIsoEGKeys;
0857       for (size_t l1NoIsoEG = 0; l1NoIsoEG < handleL1ExtraNoIsoEG->size(); ++l1NoIsoEG) {
0858         if (mainBxOnly_ && handleL1ExtraNoIsoEG->at(l1NoIsoEG).bx() != 0)
0859           continue;
0860         TriggerObject triggerObject;
0861         if (saveL1Refs_) {
0862           const reco::CandidateBaseRef leafCandRef(l1extra::L1EmParticleRef(handleL1ExtraNoIsoEG, l1NoIsoEG));
0863           triggerObject = TriggerObject(leafCandRef);
0864         } else {
0865           const reco::LeafCandidate leafCandidate(*(handleL1ExtraNoIsoEG->at(l1NoIsoEG).reco::LeafCandidate::clone()));
0866           triggerObject = TriggerObject(leafCandidate);
0867         }
0868         triggerObject.setCollection(tagL1ExtraNoIsoEG_);
0869         triggerObject.addTriggerObjectType(trigger::TriggerL1NoIsoEG);
0870         if (!onlyStandAlone_)
0871           triggerObjects->push_back(triggerObject);
0872         TriggerObjectStandAlone triggerObjectStandAlone(triggerObject);
0873         triggerObjectsStandAlone->push_back(triggerObjectStandAlone);
0874         if (handleL1ExtraNoIsoEG->at(l1NoIsoEG).bx() == 0)
0875           noIsoEGKeys.push_back(triggerObjectsStandAlone->size() - 1);
0876       }
0877       l1ObjectTypeMap.insert(std::make_pair(NoIsoEG, noIsoEGKeys));
0878     } else
0879       LogError("l1ExtraValid") << "l1extra::L1EmParticleCollection product with InputTag '"
0880                                << tagL1ExtraNoIsoEG_.encode() << "' not in event";
0881   }
0882   if (!tagL1ExtraIsoEG_.label().empty()) {
0883     Handle<l1extra::L1EmParticleCollection> handleL1ExtraIsoEG;
0884     iEvent.getByLabel(tagL1ExtraIsoEG_, handleL1ExtraIsoEG);
0885     if (handleL1ExtraIsoEG.isValid()) {
0886       std::vector<unsigned> isoEGKeys;
0887       for (size_t l1IsoEG = 0; l1IsoEG < handleL1ExtraIsoEG->size(); ++l1IsoEG) {
0888         if (mainBxOnly_ && handleL1ExtraIsoEG->at(l1IsoEG).bx() != 0)
0889           continue;
0890         TriggerObject triggerObject;
0891         if (saveL1Refs_) {
0892           const reco::CandidateBaseRef leafCandRef(l1extra::L1EmParticleRef(handleL1ExtraIsoEG, l1IsoEG));
0893           triggerObject = TriggerObject(leafCandRef);
0894         } else {
0895           const reco::LeafCandidate leafCandidate(*(handleL1ExtraIsoEG->at(l1IsoEG).reco::LeafCandidate::clone()));
0896           triggerObject = TriggerObject(leafCandidate);
0897         }
0898         triggerObject.setCollection(tagL1ExtraIsoEG_);
0899         triggerObject.addTriggerObjectType(trigger::TriggerL1IsoEG);
0900         if (!onlyStandAlone_)
0901           triggerObjects->push_back(triggerObject);
0902         TriggerObjectStandAlone triggerObjectStandAlone(triggerObject);
0903         triggerObjectsStandAlone->push_back(triggerObjectStandAlone);
0904         if (handleL1ExtraIsoEG->at(l1IsoEG).bx() == 0)
0905           isoEGKeys.push_back(triggerObjectsStandAlone->size() - 1);
0906       }
0907       l1ObjectTypeMap.insert(std::make_pair(IsoEG, isoEGKeys));
0908     } else
0909       LogError("l1ExtraValid") << "l1extra::L1EmParticleCollection product with InputTag '" << tagL1ExtraIsoEG_.encode()
0910                                << "' not in event";
0911   }
0912   if (!tagL1ExtraCenJet_.label().empty()) {
0913     Handle<l1extra::L1JetParticleCollection> handleL1ExtraCenJet;
0914     iEvent.getByLabel(tagL1ExtraCenJet_, handleL1ExtraCenJet);
0915     if (handleL1ExtraCenJet.isValid()) {
0916       std::vector<unsigned> cenJetKeys;
0917       for (size_t l1CenJet = 0; l1CenJet < handleL1ExtraCenJet->size(); ++l1CenJet) {
0918         if (mainBxOnly_ && handleL1ExtraCenJet->at(l1CenJet).bx() != 0)
0919           continue;
0920         TriggerObject triggerObject;
0921         if (saveL1Refs_) {
0922           const reco::CandidateBaseRef leafCandRef(l1extra::L1JetParticleRef(handleL1ExtraCenJet, l1CenJet));
0923           triggerObject = TriggerObject(leafCandRef);
0924         } else {
0925           const reco::LeafCandidate leafCandidate(*(handleL1ExtraCenJet->at(l1CenJet).reco::LeafCandidate::clone()));
0926           triggerObject = TriggerObject(leafCandidate);
0927         }
0928         triggerObject.setCollection(tagL1ExtraCenJet_);
0929         triggerObject.addTriggerObjectType(trigger::TriggerL1CenJet);
0930         if (!onlyStandAlone_)
0931           triggerObjects->push_back(triggerObject);
0932         TriggerObjectStandAlone triggerObjectStandAlone(triggerObject);
0933         triggerObjectsStandAlone->push_back(triggerObjectStandAlone);
0934         if (handleL1ExtraCenJet->at(l1CenJet).bx() == 0)
0935           cenJetKeys.push_back(triggerObjectsStandAlone->size() - 1);
0936       }
0937       l1ObjectTypeMap.insert(std::make_pair(CenJet, cenJetKeys));
0938     } else
0939       LogError("l1ExtraValid") << "l1extra::L1JetParticleCollection product with InputTag '"
0940                                << tagL1ExtraCenJet_.encode() << "' not in event";
0941   }
0942   if (!tagL1ExtraForJet_.label().empty()) {
0943     Handle<l1extra::L1JetParticleCollection> handleL1ExtraForJet;
0944     iEvent.getByLabel(tagL1ExtraForJet_, handleL1ExtraForJet);
0945     if (handleL1ExtraForJet.isValid()) {
0946       std::vector<unsigned> forJetKeys;
0947       for (size_t l1ForJet = 0; l1ForJet < handleL1ExtraForJet->size(); ++l1ForJet) {
0948         if (mainBxOnly_ && handleL1ExtraForJet->at(l1ForJet).bx() != 0)
0949           continue;
0950         TriggerObject triggerObject;
0951         if (saveL1Refs_) {
0952           const reco::CandidateBaseRef leafCandRef(l1extra::L1JetParticleRef(handleL1ExtraForJet, l1ForJet));
0953           triggerObject = TriggerObject(leafCandRef);
0954         } else {
0955           const reco::LeafCandidate leafCandidate(*(handleL1ExtraForJet->at(l1ForJet).reco::LeafCandidate::clone()));
0956           triggerObject = TriggerObject(leafCandidate);
0957         }
0958         triggerObject.setCollection(tagL1ExtraForJet_);
0959         triggerObject.addTriggerObjectType(trigger::TriggerL1ForJet);
0960         if (!onlyStandAlone_)
0961           triggerObjects->push_back(triggerObject);
0962         TriggerObjectStandAlone triggerObjectStandAlone(triggerObject);
0963         triggerObjectsStandAlone->push_back(triggerObjectStandAlone);
0964         if (handleL1ExtraForJet->at(l1ForJet).bx() == 0)
0965           forJetKeys.push_back(triggerObjectsStandAlone->size() - 1);
0966       }
0967       l1ObjectTypeMap.insert(std::make_pair(ForJet, forJetKeys));
0968     } else
0969       LogError("l1ExtraValid") << "l1extra::L1JetParticleCollection product with InputTag '"
0970                                << tagL1ExtraForJet_.encode() << "' not in event";
0971   }
0972   if (!tagL1ExtraTauJet_.label().empty()) {
0973     Handle<l1extra::L1JetParticleCollection> handleL1ExtraTauJet;
0974     iEvent.getByLabel(tagL1ExtraTauJet_, handleL1ExtraTauJet);
0975     if (handleL1ExtraTauJet.isValid()) {
0976       std::vector<unsigned> tauJetKeys;
0977       for (size_t l1TauJet = 0; l1TauJet < handleL1ExtraTauJet->size(); ++l1TauJet) {
0978         if (mainBxOnly_ && handleL1ExtraTauJet->at(l1TauJet).bx() != 0)
0979           continue;
0980         TriggerObject triggerObject;
0981         if (saveL1Refs_) {
0982           const reco::CandidateBaseRef leafCandRef(l1extra::L1JetParticleRef(handleL1ExtraTauJet, l1TauJet));
0983           triggerObject = TriggerObject(leafCandRef);
0984         } else {
0985           const reco::LeafCandidate leafCandidate(*(handleL1ExtraTauJet->at(l1TauJet).reco::LeafCandidate::clone()));
0986           triggerObject = TriggerObject(leafCandidate);
0987         }
0988         triggerObject.setCollection(tagL1ExtraTauJet_);
0989         triggerObject.addTriggerObjectType(trigger::TriggerL1TauJet);
0990         if (!onlyStandAlone_)
0991           triggerObjects->push_back(triggerObject);
0992         TriggerObjectStandAlone triggerObjectStandAlone(triggerObject);
0993         triggerObjectsStandAlone->push_back(triggerObjectStandAlone);
0994         if (handleL1ExtraTauJet->at(l1TauJet).bx() == 0)
0995           tauJetKeys.push_back(triggerObjectsStandAlone->size() - 1);
0996       }
0997       l1ObjectTypeMap.insert(std::make_pair(TauJet, tauJetKeys));
0998     } else
0999       LogError("l1ExtraValid") << "l1extra::L1JetParticleCollection product with InputTag '"
1000                                << tagL1ExtraTauJet_.encode() << "' not in event";
1001   }
1002   if (!tagL1ExtraETM_.label().empty()) {
1003     Handle<l1extra::L1EtMissParticleCollection> handleL1ExtraETM;
1004     iEvent.getByLabel(tagL1ExtraETM_, handleL1ExtraETM);
1005     if (handleL1ExtraETM.isValid()) {
1006       std::vector<unsigned> etmKeys;
1007       for (size_t l1ETM = 0; l1ETM < handleL1ExtraETM->size(); ++l1ETM) {
1008         if (mainBxOnly_ && handleL1ExtraETM->at(l1ETM).bx() != 0)
1009           continue;
1010         TriggerObject triggerObject;
1011         if (saveL1Refs_) {
1012           const reco::CandidateBaseRef leafCandRef(l1extra::L1EtMissParticleRef(handleL1ExtraETM, l1ETM));
1013           triggerObject = TriggerObject(leafCandRef);
1014         } else {
1015           const reco::LeafCandidate leafCandidate(*(handleL1ExtraETM->at(l1ETM).reco::LeafCandidate::clone()));
1016           triggerObject = TriggerObject(leafCandidate);
1017         }
1018         triggerObject.setCollection(tagL1ExtraETM_);
1019         triggerObject.addTriggerObjectType(trigger::TriggerL1ETM);
1020         if (!onlyStandAlone_)
1021           triggerObjects->push_back(triggerObject);
1022         TriggerObjectStandAlone triggerObjectStandAlone(triggerObject);
1023         triggerObjectsStandAlone->push_back(triggerObjectStandAlone);
1024         if (handleL1ExtraETM->at(l1ETM).bx() == 0)
1025           etmKeys.push_back(triggerObjectsStandAlone->size() - 1);
1026       }
1027       l1ObjectTypeMap.insert(std::make_pair(ETM, etmKeys));
1028     } else
1029       LogError("l1ExtraValid") << "l1extra::L1EtMissParticleCollection product with InputTag '"
1030                                << tagL1ExtraETM_.encode() << "' not in event";
1031   }
1032   if (!tagL1ExtraHTM_.label().empty()) {
1033     Handle<l1extra::L1EtMissParticleCollection> handleL1ExtraHTM;
1034     iEvent.getByLabel(tagL1ExtraHTM_, handleL1ExtraHTM);
1035     if (handleL1ExtraHTM.isValid()) {
1036       std::vector<unsigned> htmKeys;
1037       for (size_t l1HTM = 0; l1HTM < handleL1ExtraHTM->size(); ++l1HTM) {
1038         if (mainBxOnly_ && handleL1ExtraHTM->at(l1HTM).bx() != 0)
1039           continue;
1040         TriggerObject triggerObject;
1041         if (saveL1Refs_) {
1042           const reco::CandidateBaseRef leafCandRef(l1extra::L1EtMissParticleRef(handleL1ExtraHTM, l1HTM));
1043           triggerObject = TriggerObject(leafCandRef);
1044         } else {
1045           const reco::LeafCandidate leafCandidate(*(handleL1ExtraHTM->at(l1HTM).reco::LeafCandidate::clone()));
1046           triggerObject = TriggerObject(leafCandidate);
1047         }
1048         triggerObject.setCollection(tagL1ExtraHTM_);
1049         triggerObject.addTriggerObjectType(trigger::TriggerL1HTM);
1050         if (!onlyStandAlone_)
1051           triggerObjects->push_back(triggerObject);
1052         TriggerObjectStandAlone triggerObjectStandAlone(triggerObject);
1053         triggerObjectsStandAlone->push_back(triggerObjectStandAlone);
1054         if (handleL1ExtraHTM->at(l1HTM).bx() == 0)
1055           htmKeys.push_back(triggerObjectsStandAlone->size() - 1);
1056       }
1057       l1ObjectTypeMap.insert(std::make_pair(HTM, htmKeys));
1058     } else
1059       LogError("l1ExtraValid") << "l1extra::L1EtMissParticleCollection product with InputTag '"
1060                                << tagL1ExtraHTM_.encode() << "' not in event";
1061   }
1062 
1063   // Put trigger objects to event
1064   if (!onlyStandAlone_)
1065     iEvent.put(std::move(triggerObjects));
1066 
1067   // L1 algorithms
1068   if (!onlyStandAlone_) {
1069     auto triggerAlgos = std::make_unique<TriggerAlgorithmCollection>();
1070     auto triggerConditions = std::make_unique<TriggerConditionCollection>();
1071     if (addL1Algos_) {
1072       // create trigger object types transalation map (yes, it's ugly!)
1073       std::map<L1GtObject, trigger::TriggerObjectType> mapObjectTypes;
1074       mapObjectTypes.insert(std::make_pair(Mu, trigger::TriggerL1Mu));
1075       mapObjectTypes.insert(std::make_pair(NoIsoEG, trigger::TriggerL1NoIsoEG));
1076       mapObjectTypes.insert(std::make_pair(IsoEG, trigger::TriggerL1IsoEG));
1077       mapObjectTypes.insert(std::make_pair(CenJet, trigger::TriggerL1CenJet));
1078       mapObjectTypes.insert(std::make_pair(ForJet, trigger::TriggerL1ForJet));
1079       mapObjectTypes.insert(std::make_pair(TauJet, trigger::TriggerL1TauJet));
1080       mapObjectTypes.insert(std::make_pair(ETM, trigger::TriggerL1ETM));
1081       mapObjectTypes.insert(std::make_pair(HTM, trigger::TriggerL1HTM));
1082       // get and cache L1 menu
1083       L1GtUtils const& l1GtUtils = hltPrescaleProvider_.l1GtUtils();
1084       auto handleL1GtTriggerMenu = iSetup.getHandle(handleL1GtTriggerMenuToken_);
1085       auto const& l1GtAlgorithms = handleL1GtTriggerMenu->gtAlgorithmMap();
1086       auto const& l1GtTechTriggers = handleL1GtTriggerMenu->gtTechnicalTriggerMap();
1087       auto const& l1GtConditionsVector = handleL1GtTriggerMenu->gtConditionMap();
1088       // cache conditions in one single condition map
1089       ConditionMap l1GtConditions;
1090       for (size_t iCv = 0; iCv < l1GtConditionsVector.size(); ++iCv) {
1091         l1GtConditions.insert(l1GtConditionsVector.at(iCv).begin(), l1GtConditionsVector.at(iCv).end());
1092       }
1093       triggerAlgos->reserve(l1GtAlgorithms.size() + l1GtTechTriggers.size());
1094       Handle<L1GlobalTriggerObjectMaps> handleL1GlobalTriggerObjectMaps;
1095       iEvent.getByToken(l1GlobalTriggerObjectMapsToken_, handleL1GlobalTriggerObjectMaps);
1096       if (!handleL1GlobalTriggerObjectMaps.isValid()) {
1097         LogError("l1ObjectMap") << "L1GlobalTriggerObjectMaps product with InputTag '"
1098                                 << tagL1GlobalTriggerObjectMaps_.encode() << "' not in event\n"
1099                                 << "No L1 objects and GTL results available for physics algorithms";
1100       }
1101       handleL1GlobalTriggerObjectMaps->consistencyCheck();
1102       if (firstInRun_) {
1103         l1PSet_ = (ParameterSet*)(pset::Registry::instance()->getMapped(
1104             handleL1GlobalTriggerObjectMaps->namesParameterSetID()));
1105         if (l1PSet_ == nullptr) {
1106           LogError("l1ObjectMap") << "ParameterSet registry not available\n"
1107                                   << "Skipping conditions for all L1 physics algorithm names in this run";
1108         }
1109       } else {
1110         if (l1PSet_ == nullptr) {
1111           LogInfo("l1ObjectMap") << "ParameterSet registry not available\n"
1112                                  << "Skipping conditions for all L1 physics algorithm names in this event";
1113         }
1114       }
1115       // physics algorithms
1116       for (CItAlgo iAlgo = l1GtAlgorithms.begin(); iAlgo != l1GtAlgorithms.end(); ++iAlgo) {
1117         const std::string& algoName(iAlgo->second.algoName());
1118         if (!(iAlgo->second.algoBitNumber() < int(L1GlobalTriggerReadoutSetup::NumberPhysTriggers))) {
1119           LogError("l1Algo") << "L1 physics algorithm '" << algoName << "' has bit number "
1120                              << iAlgo->second.algoBitNumber()
1121                              << " >= " << L1GlobalTriggerReadoutSetup::NumberPhysTriggers << "\n"
1122                              << "Skipping";
1123           continue;
1124         }
1125         L1GtUtils::TriggerCategory category;
1126         int bit;
1127         if (!l1GtUtils.l1AlgoTechTrigBitNumber(algoName, category, bit)) {
1128           LogError("l1Algo") << "L1 physics algorithm '" << algoName << "' not found in the L1 menu\n"
1129                              << "Skipping";
1130           continue;
1131         }
1132         if (category != L1GtUtils::AlgorithmTrigger) {
1133           LogError("l1Algo") << "L1 physics algorithm '" << algoName
1134                              << "' does not have category 'AlgorithmTrigger' from 'L1GtUtils'\n"
1135                              << "Skipping";
1136           continue;
1137         }
1138         bool decisionBeforeMask;
1139         bool decisionAfterMask;
1140         int prescale;
1141         int mask;
1142         int error(l1GtUtils.l1Results(iEvent, algoName, decisionBeforeMask, decisionAfterMask, prescale, mask));
1143         if (error) {
1144           LogError("l1Algo") << "L1 physics algorithm '" << algoName << "' decision has error code " << error
1145                              << " from 'L1GtUtils'\n"
1146                              << "Skipping";
1147           continue;
1148         }
1149         TriggerAlgorithm triggerAlgo(algoName,
1150                                      iAlgo->second.algoAlias(),
1151                                      category == L1GtUtils::TechnicalTrigger,
1152                                      (unsigned)bit,
1153                                      (unsigned)prescale,
1154                                      (bool)mask,
1155                                      decisionBeforeMask,
1156                                      decisionAfterMask);
1157         triggerAlgo.setLogicalExpression(iAlgo->second.algoLogicalExpression());
1158         // GTL result and used conditions in physics algorithm
1159         if (!handleL1GlobalTriggerObjectMaps.isValid()) {
1160           triggerAlgos->push_back(triggerAlgo);
1161           continue;  // LogWarning already earlier (before loop)
1162         }
1163         if (!handleL1GlobalTriggerObjectMaps->algorithmExists(bit)) {
1164           LogError("l1ObjectMap") << "L1 physics algorithm '" << algoName
1165                                   << "' is missing in L1GlobalTriggerObjectMaps\n"
1166                                   << "Skipping conditions and GTL result";
1167           triggerAlgos->push_back(triggerAlgo);
1168           continue;
1169         }
1170         bool algorithmResult = handleL1GlobalTriggerObjectMaps->algorithmResult(bit);
1171         //         if ( ( algorithmResult != decisionBeforeMask ) && ( decisionBeforeMask == true || prescale == 1 ) ) {
1172         if ((algorithmResult != decisionBeforeMask) &&
1173             (decisionBeforeMask == true)) {  // FIXME: understand the difference for un-prescaled algos 118, 119, 123
1174           LogInfo("l1ObjectMap") << "L1 physics algorithm '" << algoName << "' with different decisions in\n"
1175                                  << "L1GlobalTriggerObjectMaps (GTL result)        : " << algorithmResult << "\n"
1176                                  << "L1GlobalTriggerReadoutRecord (decision before mask): " << decisionBeforeMask;
1177         }
1178         triggerAlgo.setGtlResult(algorithmResult);
1179         // conditions in algorithm
1180         L1GlobalTriggerObjectMaps::ConditionsInAlgorithm conditions =
1181             handleL1GlobalTriggerObjectMaps->getConditionsInAlgorithm(bit);
1182         if (l1PSet_ == nullptr) {
1183           triggerAlgos->push_back(triggerAlgo);
1184           continue;
1185         }
1186         if (!l1PSet_->exists(algoName)) {
1187           if (firstInRun_) {
1188             LogError("l1ObjectMap") << "L1 physics algorithm name '" << algoName
1189                                     << "' not available in ParameterSet registry\n"
1190                                     << "Skipping conditions for this algorithm in this run";
1191           } else {
1192             LogInfo("l1ObjectMap") << "L1 physics algorithm name '" << algoName
1193                                    << "' not available in ParameterSet registry\n"
1194                                    << "Skipping conditions for this algorithm in this event";
1195           }
1196           triggerAlgos->push_back(triggerAlgo);
1197           continue;
1198         }
1199         std::vector<std::string> conditionNames(l1PSet_->getParameter<std::vector<std::string> >(algoName));
1200 
1201         for (unsigned iT = 0; iT < conditionNames.size(); ++iT) {
1202           size_t key(triggerConditions->size());
1203           for (size_t iC = 0; iC < triggerConditions->size(); ++iC) {
1204             if (conditionNames.at(iT) == triggerConditions->at(iC).name()) {
1205               key = iC;
1206               break;
1207             }
1208           }
1209           if (key == triggerConditions->size()) {
1210             if (iT >= conditions.nConditions()) {
1211               LogError("l1CondMap") << "More condition names from ParameterSet registry than the "
1212                                     << conditions.nConditions() << " conditions in L1GlobalTriggerObjectMaps\n"
1213                                     << "Skipping condition " << conditionNames.at(iT) << " in algorithm " << algoName;
1214               break;
1215             }
1216             TriggerCondition triggerCond(conditionNames[iT], conditions.getConditionResult(iT));
1217             if (l1GtConditions.find(triggerCond.name()) != l1GtConditions.end()) {
1218               triggerCond.setCategory(l1GtConditions[triggerCond.name()]->condCategory());
1219               triggerCond.setType(l1GtConditions[triggerCond.name()]->condType());
1220               const std::vector<L1GtObject> l1ObjectTypes(l1GtConditions[triggerCond.name()]->objectType());
1221               for (size_t iType = 0; iType < l1ObjectTypes.size(); ++iType) {
1222                 triggerCond.addTriggerObjectType(mapObjectTypes[l1ObjectTypes.at(iType)]);
1223               }
1224               // objects in condition
1225               L1GlobalTriggerObjectMaps::CombinationsInCondition combinations =
1226                   handleL1GlobalTriggerObjectMaps->getCombinationsInCondition(bit, iT);
1227               for (size_t iVV = 0; iVV < combinations.nCombinations(); ++iVV) {
1228                 for (size_t iV = 0; iV < combinations.nObjectsPerCombination(); ++iV) {
1229                   unsigned objectIndex = combinations.getObjectIndex(iVV, iV);
1230                   if (iV >= l1ObjectTypes.size()) {
1231                     LogError("l1CondMap") << "Index " << iV << " in combinations vector overshoots size "
1232                                           << l1ObjectTypes.size() << " of types vector in conditions map\n"
1233                                           << "Skipping object key in condition " << triggerCond.name();
1234                   } else if (l1ObjectTypeMap.find(l1ObjectTypes.at(iV)) != l1ObjectTypeMap.end()) {
1235                     if (objectIndex >= l1ObjectTypeMap[l1ObjectTypes.at(iV)].size()) {
1236                       LogError("l1CondMap")
1237                           << "Index " << objectIndex << " in combination overshoots number "
1238                           << l1ObjectTypeMap[l1ObjectTypes.at(iV)].size() << "of according trigger objects\n"
1239                           << "Skipping object key in condition " << triggerCond.name();
1240                     }
1241                     const unsigned objectKey(l1ObjectTypeMap[l1ObjectTypes.at(iV)].at(objectIndex));
1242                     triggerCond.addObjectKey(objectKey);
1243                     // add current condition and algorithm also to the according stand-alone trigger object
1244                     triggerObjectsStandAlone->at(objectKey).addAlgorithmName(
1245                         triggerAlgo.name(), (triggerAlgo.decision() && triggerCond.wasAccept()));
1246                     triggerObjectsStandAlone->at(objectKey).addConditionName(triggerCond.name());
1247                   }
1248                 }
1249               }
1250             } else {
1251               LogWarning("l1CondMap") << "L1 conditions '" << triggerCond.name() << "' not found in the L1 menu\n"
1252                                       << "Remains incomplete";
1253             }
1254             triggerConditions->push_back(triggerCond);
1255           }
1256           triggerAlgo.addConditionKey(key);
1257         }
1258         triggerAlgos->push_back(triggerAlgo);
1259       }
1260       // technical triggers
1261       for (CItAlgo iAlgo = l1GtTechTriggers.begin(); iAlgo != l1GtTechTriggers.end(); ++iAlgo) {
1262         const std::string& algoName(iAlgo->second.algoName());
1263         if (!(iAlgo->second.algoBitNumber() < int(L1GlobalTriggerReadoutSetup::NumberTechnicalTriggers))) {
1264           LogError("l1Algo") << "L1 technical trigger '" << algoName << "' has bit number "
1265                              << iAlgo->second.algoBitNumber()
1266                              << " >= " << L1GlobalTriggerReadoutSetup::NumberTechnicalTriggers << "\n"
1267                              << "Skipping";
1268           continue;
1269         }
1270         L1GtUtils::TriggerCategory category;
1271         int bit;
1272         if (!l1GtUtils.l1AlgoTechTrigBitNumber(algoName, category, bit)) {
1273           LogError("l1Algo") << "L1 technical trigger '" << algoName << "' not found in the L1 menu\n"
1274                              << "Skipping";
1275           continue;
1276         }
1277         if (category != L1GtUtils::TechnicalTrigger) {
1278           LogError("l1Algo") << "L1 technical trigger '" << algoName
1279                              << "' does not have category 'TechnicalTrigger' from 'L1GtUtils'\n"
1280                              << "Skipping";
1281           continue;
1282         }
1283         bool decisionBeforeMask;
1284         bool decisionAfterMask;
1285         int prescale;
1286         int mask;
1287         int error(l1GtUtils.l1Results(iEvent, algoName, decisionBeforeMask, decisionAfterMask, prescale, mask));
1288         if (error) {
1289           LogError("l1Algo") << "L1 technical trigger '" << algoName << "' decision has error code " << error
1290                              << " from 'L1GtUtils'\n"
1291                              << "Skipping";
1292           continue;
1293         }
1294         TriggerAlgorithm triggerAlgo(algoName,
1295                                      iAlgo->second.algoAlias(),
1296                                      category == L1GtUtils::TechnicalTrigger,
1297                                      (unsigned)bit,
1298                                      (unsigned)prescale,
1299                                      (bool)mask,
1300                                      decisionBeforeMask,
1301                                      decisionAfterMask);
1302         triggerAlgo.setLogicalExpression(iAlgo->second.algoLogicalExpression());
1303         triggerAlgos->push_back(triggerAlgo);
1304       }
1305     }
1306 
1307     // Put L1 algorithms and conditions to event
1308     iEvent.put(std::move(triggerAlgos));
1309     iEvent.put(std::move(triggerConditions));
1310   }
1311 
1312   edm::ProcessConfiguration config;
1313   iEvent.processHistory().getConfigurationForProcess(nameProcess_, config);
1314 
1315   const edm::TriggerNames& names = iEvent.triggerNames(*handleTriggerResults);
1316   for (pat::TriggerObjectStandAlone& obj : *triggerObjectsStandAlone) {
1317     obj.setPSetID(config.parameterSetID());
1318     if (packPathNames_)
1319       obj.packPathNames(names);
1320     if (packLabels_)
1321       obj.packFilterLabels(iEvent, *handleTriggerResults);
1322   }
1323 
1324   // Put (finally) stand-alone trigger objects to event
1325   iEvent.put(std::move(triggerObjectsStandAlone));
1326 
1327   firstInRun_ = false;
1328 }
1329 
1330 void PATTriggerProducer::ModuleLabelToPathAndFlags::init(const HLTConfigProvider& hltConfig) {
1331   clear();
1332   const std::vector<std::string>& pathNames = hltConfig.triggerNames();
1333   unsigned int sizePaths = pathNames.size();
1334   for (unsigned int indexPath = 0; indexPath < sizePaths; ++indexPath) {
1335     const std::string& namePath = pathNames[indexPath];
1336 
1337     const std::vector<std::string>& nameModules = hltConfig.moduleLabels(indexPath);
1338     unsigned int sizeModulesPath = nameModules.size();
1339     bool lastFilter = true;
1340     unsigned int iM = sizeModulesPath;
1341     while (iM > 0) {
1342       const std::string& nameFilter = nameModules[--iM];
1343       if (hltConfig.moduleEDMType(nameFilter) != "EDFilter")
1344         continue;
1345       if (hltConfig.moduleType(nameFilter) == "HLTBool")
1346         continue;
1347       bool saveTags = hltConfig.saveTags(nameFilter);
1348       insert(nameFilter, namePath, indexPath, lastFilter, saveTags);
1349       if (saveTags)
1350         lastFilter = false;  // FIXME: rather always?
1351     }
1352   }
1353 }
1354 
1355 #include "FWCore/Framework/interface/MakerMacros.h"
1356 DEFINE_FWK_MODULE(PATTriggerProducer);