Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:33:15

0001 #include "PhysicsTools/UtilAlgos/interface/CachingVariable.h"
0002 
0003 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutRecord.h"
0004 
0005 class L1BitComputer : public VariableComputer {
0006 public:
0007   L1BitComputer(CachingVariable::CachingVariableFactoryArg arg, edm::ConsumesCollector& iC)
0008       : VariableComputer(arg, iC) {
0009     src_ = iC.consumes<L1GlobalTriggerReadoutRecord>(
0010         edm::Service<InputTagDistributorService>()->retrieve("src", arg.iConfig));
0011     for (int i = 0; i != 128; i++) {
0012       std::stringstream ss;
0013       ss << i;
0014       declare(ss.str(), iC);
0015     }
0016 
0017     for (int i = 0; i != 64; i++) {
0018       std::stringstream ss;
0019       ss << "TechTrig_";
0020       ss << i;
0021       declare(ss.str(), iC);
0022     }
0023   }
0024   ~L1BitComputer() override{};
0025 
0026   void compute(const edm::Event& iEvent) const override {
0027     edm::Handle<L1GlobalTriggerReadoutRecord> l1Handle;
0028     iEvent.getByToken(src_, l1Handle);
0029     if (l1Handle.failedToGet())
0030       doesNotCompute();
0031     const DecisionWord& dWord = l1Handle->decisionWord();
0032     for (int i = 0; i != 128; i++) {
0033       std::stringstream ss;
0034       ss << i;
0035       double r = dWord.at(i);
0036       assign(ss.str(), r);
0037     }
0038 
0039     const TechnicalTriggerWord& tTWord = l1Handle->technicalTriggerWord();
0040     for (int i = 0; i != 64; i++) {
0041       std::stringstream ss;
0042       ss << "TechTrig_";
0043       ss << i;
0044       double r = tTWord.at(i);
0045       assign(ss.str(), r);
0046     }
0047   }
0048 
0049 private:
0050   edm::EDGetTokenT<L1GlobalTriggerReadoutRecord> src_;
0051 };
0052 
0053 #include "DataFormats/Common/interface/TriggerResults.h"
0054 #include "FWCore/Common/interface/TriggerNames.h"
0055 #include "HLTrigger/HLTcore/interface/HLTConfigProvider.h"
0056 
0057 class HLTBitComputer : public VariableComputer {
0058 public:
0059   HLTBitComputer(CachingVariable::CachingVariableFactoryArg arg, edm::ConsumesCollector& iC)
0060       : VariableComputer(arg, iC) {
0061     src_ = iC.consumes<edm::TriggerResults>(edm::Service<InputTagDistributorService>()->retrieve("src", arg.iConfig));
0062     HLTConfigProvider provider;
0063     //the function will not work anymore until a major redesign is performed. so long for HLT variables.
0064     //provider.init(src_.process());
0065     validTriggerNames_ = provider.triggerNames();
0066     for (unsigned int iT = 0; iT != validTriggerNames_.size(); ++iT) {
0067       TString tname(validTriggerNames_[iT]);
0068       tname.ReplaceAll("HLT_", "");  //remove the "HLT_" prefix
0069       declare(std::string(static_cast<const char*>(tname)), iC);
0070     }
0071   }
0072   ~HLTBitComputer() override {}
0073   void compute(const edm::Event& iEvent) const override {
0074     edm::Handle<edm::TriggerResults> trh;
0075     iEvent.getByToken(src_, trh);
0076     if (!trh.isValid())
0077       doesNotCompute();
0078     const edm::TriggerNames& triggerNames = iEvent.triggerNames(*trh);
0079     for (unsigned int iT = 0; iT != validTriggerNames_.size(); ++iT) {
0080       TString tname(validTriggerNames_[iT]);
0081       tname.ReplaceAll("HLT_", "");
0082       double r = trh->accept(triggerNames.triggerIndex(validTriggerNames_[iT]));
0083       assign(std::string(static_cast<const char*>(tname)), r);
0084     }
0085   }
0086 
0087 private:
0088   edm::EDGetTokenT<edm::TriggerResults> src_;
0089   std::vector<std::string> validTriggerNames_;
0090 };
0091 
0092 class HLTBitVariable : public CachingVariable {
0093 public:
0094   HLTBitVariable(CachingVariableFactoryArg arg, edm::ConsumesCollector& iC)
0095       : CachingVariable("HLTBitVariable", arg.n, arg.iConfig, iC),
0096         src_(
0097             iC.consumes<edm::TriggerResults>(edm::Service<InputTagDistributorService>()->retrieve("src", arg.iConfig))),
0098         bitName_(arg.n) {
0099     arg.m[arg.n] = this;
0100   }
0101   CachingVariable::evalType eval(const edm::Event& iEvent) const override {
0102     edm::Handle<edm::TriggerResults> hltHandle;
0103     iEvent.getByToken(src_, hltHandle);
0104     if (hltHandle.failedToGet())
0105       return std::make_pair(false, 0);
0106     const edm::TriggerNames& trgNames = iEvent.triggerNames(*hltHandle);
0107     unsigned int index = trgNames.triggerIndex(bitName_);
0108     if (index == trgNames.size())
0109       return std::make_pair(false, 0);
0110     else
0111       return std::make_pair(true, hltHandle->accept(index));
0112   }
0113 
0114 private:
0115   edm::EDGetTokenT<edm::TriggerResults> src_;
0116   std::string bitName_;
0117 };