Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:49:44

0001 /** \class L1TTkEmFilter
0002  *
0003  * See header file for documentation
0004  *
0005  *
0006  *  \author Martin Grunewald
0007  *  \author Simone Gennai
0008  *  \author Thiago Tomei
0009  *
0010  */
0011 
0012 #include "L1TTkEmFilter.h"
0013 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0014 
0015 #include "DataFormats/Common/interface/Handle.h"
0016 
0017 #include "DataFormats/Common/interface/Ref.h"
0018 #include "DataFormats/HLTReco/interface/TriggerFilterObjectWithRefs.h"
0019 #include "DataFormats/HLTReco/interface/TriggerTypeDefs.h"
0020 
0021 #include "FWCore/Framework/interface/EventSetup.h"
0022 #include "FWCore/Framework/interface/EventSetupRecord.h"
0023 #include "FWCore/Utilities/interface/Exception.h"
0024 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0025 
0026 //
0027 // constructors and destructor
0028 //
0029 
0030 L1TTkEmFilter::L1TTkEmFilter(const edm::ParameterSet& iConfig)
0031     : HLTFilter(iConfig),
0032       l1TkEmTag1_(iConfig.getParameter<edm::InputTag>("inputTag1")),
0033       l1TkEmTag2_(iConfig.getParameter<edm::InputTag>("inputTag2")),
0034       tkEmToken1_(consumes<TkEmCollection>(l1TkEmTag1_)),
0035       tkEmToken2_(consumes<TkEmCollection>(l1TkEmTag2_)) {
0036   min_Pt_ = iConfig.getParameter<double>("MinPt");
0037   min_N_ = iConfig.getParameter<int>("MinN");
0038   min_Eta_ = iConfig.getParameter<double>("MinEta");
0039   max_Eta_ = iConfig.getParameter<double>("MaxEta");
0040   scalings_ = iConfig.getParameter<edm::ParameterSet>("Scalings");
0041   barrelScalings_ = scalings_.getParameter<std::vector<double> >("barrel");
0042   endcapScalings_ = scalings_.getParameter<std::vector<double> >("endcap");
0043   etaBinsForIsolation_ = iConfig.getParameter<std::vector<double> >("EtaBinsForIsolation");
0044   etaBinsForIsolation_ = iConfig.getParameter<std::vector<double> >("EtaBinsForIsolation");
0045   trkIsolation_ = iConfig.getParameter<std::vector<double> >("TrkIsolation");
0046   quality1_ = iConfig.getParameter<int>("Quality1");
0047   quality2_ = iConfig.getParameter<int>("Quality2");
0048   qual1IsMask_ = iConfig.getParameter<bool>("Qual1IsMask");
0049   qual2IsMask_ = iConfig.getParameter<bool>("Qual2IsMask");
0050   applyQual1_ = iConfig.getParameter<bool>("ApplyQual1");
0051   applyQual2_ = iConfig.getParameter<bool>("ApplyQual2");
0052 
0053   if (etaBinsForIsolation_.size() != (trkIsolation_.size() + 1))
0054     throw cms::Exception("ConfigurationError")
0055         << "Vector of isolation values should have same size of vector of eta bins plus one.";
0056 }
0057 
0058 L1TTkEmFilter::~L1TTkEmFilter() = default;
0059 
0060 //
0061 // member functions
0062 //
0063 
0064 void L1TTkEmFilter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0065   edm::ParameterSetDescription desc;
0066   makeHLTFilterDescription(desc);
0067   desc.add<double>("MinPt", -1.0);
0068   desc.add<double>("MinEta", -5.0);
0069   desc.add<double>("MaxEta", 5.0);
0070   desc.add<int>("MinN", 1);
0071   desc.add<edm::InputTag>("inputTag1", edm::InputTag("L1TkEms1"));
0072   desc.add<edm::InputTag>("inputTag2", edm::InputTag("L1TkEms2"));
0073   desc.add<std::vector<double> >("EtaBinsForIsolation", {0.0, 1.479});
0074   desc.add<std::vector<double> >("TrkIsolation",
0075                                  {
0076                                      99999.9,
0077                                  });
0078   desc.add<int>("Quality1", 0);
0079   desc.add<int>("Quality2", 0);
0080   desc.add<bool>("Qual1IsMask", false);
0081   desc.add<bool>("Qual2IsMask", false);
0082   desc.add<bool>("ApplyQual1", false);
0083   desc.add<bool>("ApplyQual2", false);
0084 
0085   edm::ParameterSetDescription descScalings;
0086   descScalings.add<std::vector<double> >("barrel", {0.0, 1.0, 0.0});
0087   descScalings.add<std::vector<double> >("endcap", {0.0, 1.0, 0.0});
0088   desc.add<edm::ParameterSetDescription>("Scalings", descScalings);
0089 
0090   descriptions.add("L1TTkEmFilter", desc);
0091 }
0092 
0093 // ------------ method called to produce the data  ------------
0094 bool L1TTkEmFilter::hltFilter(edm::Event& iEvent,
0095                               const edm::EventSetup& iSetup,
0096                               trigger::TriggerFilterObjectWithRefs& filterproduct) const {
0097   using namespace std;
0098   using namespace edm;
0099   using namespace reco;
0100   using namespace trigger;
0101 
0102   // All HLT filters must create and fill an HLT filter object,
0103   // recording any reconstructed physics objects satisfying (or not)
0104   // this HLT filter, and place it in the Event.
0105 
0106   // The filter object
0107   if (saveTags()) {
0108     filterproduct.addCollectionTag(l1TkEmTag1_);
0109     filterproduct.addCollectionTag(l1TkEmTag2_);
0110   }
0111 
0112   // Specific filter code
0113 
0114   // get hold of products from Event
0115 
0116   /// Barrel collection
0117   Handle<l1t::TkEmCollection> tkEms1;
0118   iEvent.getByToken(tkEmToken1_, tkEms1);
0119 
0120   /// Endcap collection
0121   Handle<l1t::TkEmCollection> tkEms2;
0122   iEvent.getByToken(tkEmToken2_, tkEms2);
0123 
0124   int ntrkEm(0);
0125   // Loop over first collection
0126   auto atrkEms(tkEms1->begin());
0127   auto otrkEms(tkEms1->end());
0128   TkEmCollection::const_iterator itkEm;
0129   for (itkEm = atrkEms; itkEm != otrkEms; itkEm++) {
0130     double offlinePt = this->TkEmOfflineEt(itkEm->pt(), itkEm->eta());
0131     bool passQuality(false);
0132     bool passIsolation(false);
0133 
0134     if (applyQual1_) {
0135       if (qual1IsMask_)
0136         passQuality = (itkEm->EGRef()->hwQual() & quality1_);
0137       else
0138         passQuality = (itkEm->EGRef()->hwQual() == quality1_);
0139     } else
0140       passQuality = true;
0141 
0142     // There has to be a better way to do this.
0143     for (unsigned int etabin = 1; etabin != etaBinsForIsolation_.size(); ++etabin) {
0144       if (std::abs(itkEm->eta()) < etaBinsForIsolation_.at(etabin) and
0145           std::abs(itkEm->eta()) > etaBinsForIsolation_.at(etabin - 1) and
0146           itkEm->trkIsol() < trkIsolation_.at(etabin - 1))
0147         passIsolation = true;
0148     }
0149 
0150     if (offlinePt >= min_Pt_ && itkEm->eta() <= max_Eta_ && itkEm->eta() >= min_Eta_ && passQuality && passIsolation) {
0151       ntrkEm++;
0152       l1t::TkEmRef ref1(l1t::TkEmRef(tkEms1, distance(atrkEms, itkEm)));
0153       filterproduct.addObject(trigger::TriggerObjectType::TriggerL1TkEm, ref1);
0154     }
0155   }
0156 
0157   // Loop over second collection. Notice we don't reset ntrkEm
0158   atrkEms = tkEms2->begin();
0159   otrkEms = tkEms2->end();
0160   for (itkEm = atrkEms; itkEm != otrkEms; itkEm++) {
0161     double offlinePt = this->TkEmOfflineEt(itkEm->pt(), itkEm->eta());
0162     bool passQuality(false);
0163     bool passIsolation(false);
0164 
0165     if (applyQual2_) {
0166       if (qual2IsMask_)
0167         passQuality = (itkEm->EGRef()->hwQual() & quality2_);
0168       else
0169         passQuality = (itkEm->EGRef()->hwQual() == quality2_);
0170     } else
0171       passQuality = true;
0172 
0173     for (unsigned int etabin = 1; etabin != etaBinsForIsolation_.size(); ++etabin) {
0174       if (std::abs(itkEm->eta()) < etaBinsForIsolation_.at(etabin) and
0175           std::abs(itkEm->eta()) > etaBinsForIsolation_.at(etabin - 1) and
0176           itkEm->trkIsol() < trkIsolation_.at(etabin - 1))
0177         passIsolation = true;
0178     }
0179 
0180     if (offlinePt >= min_Pt_ && itkEm->eta() <= max_Eta_ && itkEm->eta() >= min_Eta_ && passQuality && passIsolation) {
0181       ntrkEm++;
0182       l1t::TkEmRef ref2(l1t::TkEmRef(tkEms2, distance(atrkEms, itkEm)));
0183       filterproduct.addObject(trigger::TriggerObjectType::TriggerL1TkEm, ref2);
0184     }
0185   }
0186 
0187   // return with final filter decision
0188   const bool accept(ntrkEm >= min_N_);
0189   return accept;
0190 }
0191 
0192 double L1TTkEmFilter::TkEmOfflineEt(double Et, double Eta) const {
0193   if (std::abs(Eta) < 1.5)
0194     return (barrelScalings_.at(0) + Et * barrelScalings_.at(1) + Et * Et * barrelScalings_.at(2));
0195   else
0196     return (endcapScalings_.at(0) + Et * endcapScalings_.at(1) + Et * Et * endcapScalings_.at(2));
0197 }