Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-03-05 03:57:50

0001 /*
0002   Author: Swagata Mukherjee
0003 
0004   Date: Feb 2021
0005 
0006   At the time of writing this new module, it is intended to be used mainly for
0007   phase-2. Before feeding in the L1 e/g collection to
0008   HLTEcalRecHitInAllL1RegionsProducer, it can pass through this module which
0009   will filter the collection based on hardware quality and pT.
0010 
0011   The most generic L1 e/g phase-2 collections are:
0012   TkEm, which is std::vector<l1t::TkEm>
0013   &
0014   StaEG, which is BXVector<l1t::EGamma>
0015 
0016   Despite this technical difference, the objects are almost identical, for all
0017   practical purposes. So any of these two collections could have been used.
0018   Currently, BXVector<l1t::EGamma> is recognised by the next step
0019   HLTEcalRecHitInAllL1RegionsProducer, while std::vector<l1t::TkEm> is not. So
0020   using BXVector<l1t::EGamma> is straightforward. If for some reason one need to
0021   use std::vector<l1t::TkEm>, changes in HLTEcalRecHitInAllL1RegionsProducer
0022   would also be necesary.
0023 */
0024 
0025 #include "DataFormats/L1TCorrelator/interface/TkEm.h"
0026 #include "FWCore/Framework/interface/ESHandle.h"
0027 #include "FWCore/Framework/interface/Event.h"
0028 #include "FWCore/Framework/interface/EventSetup.h"
0029 #include "FWCore/Framework/interface/EventSetupRecord.h"
0030 #include "FWCore/Framework/interface/Frameworkfwd.h"
0031 #include "FWCore/Framework/interface/MakerMacros.h"
0032 #include "FWCore/Framework/interface/global/EDProducer.h"
0033 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0034 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0035 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0036 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0037 
0038 class L1TEGammaFilteredCollectionProducer : public edm::global::EDProducer<> {
0039 public:
0040   explicit L1TEGammaFilteredCollectionProducer(const edm::ParameterSet&);
0041   ~L1TEGammaFilteredCollectionProducer() override;
0042   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0043   void produce(edm::StreamID sid, edm::Event& iEvent, const edm::EventSetup& iSetup) const override;
0044 
0045 private:
0046   edm::InputTag l1EgTag_;
0047   edm::EDGetTokenT<BXVector<l1t::EGamma>> l1EgToken_;
0048   int quality_;
0049   bool qualIsMask_;
0050   bool applyQual_;
0051   int minBX_;
0052   int maxBX_;
0053   double minPt_;
0054   std::vector<double> scalings_;  // pT scaling factors
0055   double getOfflineEt(double et) const;
0056 };
0057 
0058 L1TEGammaFilteredCollectionProducer::L1TEGammaFilteredCollectionProducer(const edm::ParameterSet& iConfig)
0059     : l1EgTag_(iConfig.getParameter<edm::InputTag>("inputTag")), l1EgToken_(consumes<BXVector<l1t::EGamma>>(l1EgTag_)) {
0060   quality_ = iConfig.getParameter<int>("quality");
0061   qualIsMask_ = iConfig.getParameter<bool>("qualIsMask");
0062   applyQual_ = iConfig.getParameter<bool>("applyQual");
0063   minBX_ = iConfig.getParameter<int>("minBX");
0064   maxBX_ = iConfig.getParameter<int>("maxBX");
0065   minPt_ = iConfig.getParameter<double>("minPt");
0066   scalings_ = iConfig.getParameter<std::vector<double>>("scalings");
0067 
0068   produces<BXVector<l1t::EGamma>>();
0069 }
0070 
0071 L1TEGammaFilteredCollectionProducer::~L1TEGammaFilteredCollectionProducer() = default;
0072 
0073 void L1TEGammaFilteredCollectionProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0074   edm::ParameterSetDescription desc;
0075   desc.add<edm::InputTag>("inputTag", edm::InputTag("L1EGammaClusterEmuProducer"));
0076   desc.add<int>("quality", 0x2);
0077   desc.add<bool>("qualIsMask", true);
0078   desc.add<bool>("applyQual", true);
0079   desc.add<int>("minBX", -1);
0080   desc.add<int>("maxBX", 1);
0081   desc.add<double>("minPt", 5.0);
0082   desc.add<std::vector<double>>("scalings", {2.6604, 1.06077, 0.0});
0083   descriptions.add("L1TEGammaFilteredCollectionProducer", desc);
0084 }
0085 
0086 void L1TEGammaFilteredCollectionProducer::produce(edm::StreamID sid,
0087                                                   edm::Event& iEvent,
0088                                                   const edm::EventSetup& iSetup) const {
0089   auto outEgs = std::make_unique<BXVector<l1t::EGamma>>();
0090   auto l1Egs = iEvent.getHandle(l1EgToken_);
0091 
0092   int startBX = std::max((*l1Egs).getFirstBX(), minBX_);
0093   int endBX = std::min((*l1Egs).getLastBX(), maxBX_);
0094 
0095   for (int bx = startBX; bx <= endBX; bx++) {
0096     // Loop over all L1 e/gamma objects
0097     for (BXVector<l1t::EGamma>::const_iterator iEg = (*l1Egs).begin(bx); iEg != (*l1Egs).end(bx); iEg++) {
0098       double offlineEt = this->getOfflineEt((*iEg).pt());
0099       bool passQuality(false);
0100       if (applyQual_) {
0101         if (qualIsMask_)
0102           passQuality = ((*iEg).hwQual() & quality_);
0103         else
0104           passQuality = ((*iEg).hwQual() == quality_);
0105       } else
0106         passQuality = true;
0107 
0108       // if quality is passed, put the object in filtered collection
0109       if (passQuality && (offlineEt > minPt_)) {
0110         outEgs->push_back(bx, *iEg);
0111       }
0112     }  // l1EG loop ends
0113   }    // BX loop ends
0114   iEvent.put(std::move(outEgs));
0115 }
0116 
0117 double L1TEGammaFilteredCollectionProducer::getOfflineEt(double et) const {
0118   return (scalings_.at(0) + et * scalings_.at(1) + et * et * scalings_.at(2));
0119 }
0120 
0121 DEFINE_FWK_MODULE(L1TEGammaFilteredCollectionProducer);