Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:18:29

0001 #ifndef HLTrigger_HLTfilters_L1TEnergySumFilterT_h
0002 #define HLTrigger_HLTfilters_L1TEnergySumFilterT_h
0003 
0004 #include <vector>
0005 #include <iterator>
0006 
0007 #include "DataFormats/Common/interface/Ref.h"
0008 #include "DataFormats/HLTReco/interface/TriggerFilterObjectWithRefs.h"
0009 #include "DataFormats/HLTReco/interface/TriggerTypeDefs.h"
0010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0011 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0012 #include "HLTrigger/HLTcore/interface/HLTFilter.h"
0013 #include "HLTrigger/HLTcore/interface/defaultModuleLabel.h"
0014 
0015 template <typename T>
0016 class L1TEnergySumFilterT : public HLTFilter {
0017 public:
0018   explicit L1TEnergySumFilterT(const edm::ParameterSet&);
0019   ~L1TEnergySumFilterT() override;
0020   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0021   bool hltFilter(edm::Event&,
0022                  edm::EventSetup const&,
0023                  trigger::TriggerFilterObjectWithRefs& filterproduct) const override;
0024 
0025 private:
0026   edm::InputTag const l1tSumTag_;
0027   edm::EDGetTokenT<std::vector<T>> const l1tSumToken_;
0028 
0029   trigger::TriggerObjectType const l1tSumType_;
0030   double const minPt_;
0031 
0032   edm::ParameterSet scalings_;
0033   std::vector<double> theScalings_;
0034 
0035   static trigger::TriggerObjectType typeOfL1TSum(std::string const&);
0036 
0037   double offlineEnergySum(double const Et) const;
0038 };
0039 
0040 template <typename T>
0041 L1TEnergySumFilterT<T>::L1TEnergySumFilterT(const edm::ParameterSet& iConfig)
0042     : HLTFilter(iConfig),
0043       l1tSumTag_(iConfig.getParameter<edm::InputTag>("inputTag")),
0044       l1tSumToken_(consumes<std::vector<T>>(l1tSumTag_)),
0045       l1tSumType_(typeOfL1TSum(iConfig.getParameter<std::string>("TypeOfSum"))),
0046       minPt_(iConfig.getParameter<double>("MinPt")) {
0047   scalings_ = iConfig.getParameter<edm::ParameterSet>("Scalings");
0048   theScalings_ = scalings_.getParameter<std::vector<double>>("theScalings");
0049 }
0050 
0051 template <typename T>
0052 L1TEnergySumFilterT<T>::~L1TEnergySumFilterT() = default;
0053 
0054 template <typename T>
0055 trigger::TriggerObjectType L1TEnergySumFilterT<T>::typeOfL1TSum(std::string const& typeOfSum) {
0056   trigger::TriggerObjectType sumEnum;
0057 
0058   if (typeOfSum == "MET")
0059     sumEnum = trigger::TriggerObjectType::TriggerL1PFMET;
0060   else if (typeOfSum == "ETT")
0061     sumEnum = trigger::TriggerObjectType::TriggerL1PFETT;
0062   else if (typeOfSum == "HT")
0063     sumEnum = trigger::TriggerObjectType::TriggerL1PFHT;
0064   else if (typeOfSum == "MHT")
0065     sumEnum = trigger::TriggerObjectType::TriggerL1PFMHT;
0066   else {
0067     throw cms::Exception("ConfigurationError")
0068         << "Wrong type of energy sum: \"" << typeOfSum << "\" (valid choices are: MET, ETT, HT, MHT)";
0069   }
0070 
0071   return sumEnum;
0072 }
0073 
0074 template <typename T>
0075 void L1TEnergySumFilterT<T>::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0076   edm::ParameterSetDescription desc;
0077   makeHLTFilterDescription(desc);
0078   desc.add<edm::InputTag>("inputTag", edm::InputTag("L1PFEnergySums"));
0079 
0080   edm::ParameterSetDescription descScalings;
0081   descScalings.add<std::vector<double>>("theScalings", {0.0, 1.0, 0.0});
0082   desc.add<edm::ParameterSetDescription>("Scalings", descScalings);
0083 
0084   desc.add<std::string>("TypeOfSum", "HT");
0085   desc.add<double>("MinPt", -1.);
0086   descriptions.add(defaultModuleLabel<L1TEnergySumFilterT<T>>(), desc);
0087 }
0088 
0089 template <typename T>
0090 bool L1TEnergySumFilterT<T>::hltFilter(edm::Event& iEvent,
0091                                        edm::EventSetup const& iSetup,
0092                                        trigger::TriggerFilterObjectWithRefs& filterproduct) const {
0093   // All HLT filters must create and fill an HLT filter object,
0094   // recording any reconstructed physics objects satisfying (or not)
0095   // this HLT filter, and place it in the Event.
0096 
0097   // The filter object
0098   if (saveTags()) {
0099     filterproduct.addCollectionTag(l1tSumTag_);
0100   }
0101 
0102   auto const& l1tSums = iEvent.getHandle(l1tSumToken_);
0103 
0104   /// Thiago: this is now a bit ugly, because the fact that the object is HT or MHT
0105   /// is now encoded on the fact that it is the 0th or 1st element in the vector.
0106   ///
0107   /*
0108   l1t::EtSum HT = l1L1PFPhase1L1JetSums->at(0);
0109   l1t::EtSum MHT = l1L1PFPhase1L1JetSums->at(1);
0110   l1extra_.phase1PuppiHT = HT.pt();
0111   l1extra_.phase1PuppiMHTEt = MHT.pt();
0112   l1t::EtSum met = l1MetPF->at(0);
0113   l1extra_.puppiMETEt = met.et();
0114   */
0115   if (l1tSums->size() < 1) {
0116     throw cms::Exception("BadCollectionSize") << "l1tSums should have size() >= 1";
0117   }
0118 
0119   int nSum(0);
0120   double onlinePt(0.0);
0121   auto iSum = l1tSums->begin();
0122 
0123   // The correct way of doing this would be using the EtSumHelper class.
0124   // However, it doesn't support std::vector<l1t::EtSum>, only the
0125   // older BXVector<l1t::EtSum> collection.
0126   if (l1tSumType_ == trigger::TriggerObjectType::TriggerL1PFMET) {
0127     // MET is index [0], and uses .et() method
0128     onlinePt = iSum->et();
0129   } else if (l1tSumType_ == trigger::TriggerObjectType::TriggerL1PFHT) {
0130     // HT is index [0], and uses .pt() method
0131     onlinePt = iSum->pt();
0132   } else if (l1tSumType_ == trigger::TriggerObjectType::TriggerL1PFMHT) {
0133     // MHT is index [1], and uses .pt() method
0134     if (l1tSums->size() < 2) {
0135       throw cms::Exception("BadCollectionSize")
0136           << "If we want trigger::TriggerObjectType::TriggerL1PFMHT, l1tSums should have size() >= 2";
0137     }
0138     ++iSum;
0139     onlinePt = iSum->pt();
0140   }
0141   if (l1tSumType_ == trigger::TriggerObjectType::TriggerL1PFETT) {
0142     // As of now, L1 doesn't support this object it seems.
0143     throw cms::Exception("UnsupportedType")
0144         << "As of now, L1 doesn't support trigger::TriggerObjectType::TriggerL1PFETT";
0145   }
0146 
0147   // Do the scaling
0148   auto const offlinePt = offlineEnergySum(onlinePt);
0149 
0150   // Add the passing element to the filterproduct.
0151   if (offlinePt >= minPt_) {
0152     ++nSum;
0153     edm::Ref<std::vector<T>> ref(l1tSums, std::distance(l1tSums->begin(), iSum));
0154     filterproduct.addObject(l1tSumType_, ref);
0155   }
0156 
0157   // return final filter decision
0158   return nSum > 0;
0159 }
0160 
0161 template <typename T>
0162 double L1TEnergySumFilterT<T>::offlineEnergySum(double const Et) const {
0163   return (theScalings_.at(0) + Et * theScalings_.at(1) + Et * Et * theScalings_.at(2));
0164 }
0165 
0166 #endif  // HLTrigger_HLTfilters_L1TEnergySumFilterT_h