Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:34:07

0001 /** \class EgammaHLTCaloTowerProducer
0002  *
0003  * Framework module that produces a collection
0004  * of calo towers in the region of interest for Egamma HLT reconnstruction,
0005  * \author M. Sani (UCSD)
0006  *
0007  */
0008 
0009 #include "FWCore/Framework/interface/global/EDProducer.h"
0010 #include "FWCore/Utilities/interface/InputTag.h"
0011 #include "DataFormats/CaloTowers/interface/CaloTowerDefs.h"
0012 #include "DataFormats/L1Trigger/interface/L1EmParticle.h"
0013 #include "DataFormats/L1Trigger/interface/L1EmParticleFwd.h"
0014 #include "DataFormats/RecoCandidate/interface/RecoCaloTowerCandidate.h"
0015 #include "DataFormats/CaloTowers/interface/CaloTower.h"
0016 #include "DataFormats/Common/interface/Handle.h"
0017 #include "FWCore/Framework/interface/Event.h"
0018 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0019 
0020 #include "DataFormats/L1Trigger/interface/L1EmParticle.h"
0021 #include "DataFormats/L1Trigger/interface/L1EmParticleFwd.h"
0022 
0023 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0024 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0025 
0026 #include "Math/GenVector/VectorUtil.h"
0027 
0028 #include <cmath>
0029 #include <string>
0030 
0031 class EgammaHLTCaloTowerProducer : public edm::global::EDProducer<> {
0032 public:
0033   EgammaHLTCaloTowerProducer(const edm::ParameterSet&);
0034   ~EgammaHLTCaloTowerProducer() override{};
0035   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0036   void produce(edm::StreamID, edm::Event&, edm::EventSetup const&) const final;
0037 
0038   const edm::EDGetTokenT<CaloTowerCollection> towers_;
0039   const double cone_;
0040   const edm::EDGetTokenT<edm::View<reco::Candidate>> l1isoseeds_;
0041   const edm::EDGetTokenT<edm::View<reco::Candidate>> l1nonisoseeds_;
0042   const double EtThreshold_;
0043   const double EThreshold_;
0044 };
0045 
0046 using namespace edm;
0047 using namespace reco;
0048 using namespace std;
0049 using namespace l1extra;
0050 
0051 EgammaHLTCaloTowerProducer::EgammaHLTCaloTowerProducer(const ParameterSet& p)
0052     : towers_(consumes<CaloTowerCollection>(p.getParameter<InputTag>("towerCollection"))),
0053       cone_(p.getParameter<double>("useTowersInCone")),
0054       l1isoseeds_(consumes<edm::View<reco::Candidate>>(p.getParameter<edm::InputTag>("L1IsoCand"))),
0055       l1nonisoseeds_(consumes<edm::View<reco::Candidate>>(p.getParameter<edm::InputTag>("L1NonIsoCand"))),
0056       EtThreshold_(p.getParameter<double>("EtMin")),
0057       EThreshold_(p.getParameter<double>("EMin")) {
0058   produces<CaloTowerCollection>();
0059 }
0060 
0061 void EgammaHLTCaloTowerProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0062   edm::ParameterSetDescription desc;
0063 
0064   desc.add<edm::InputTag>(("towerCollection"), edm::InputTag("hltRecoEcalCandidate"));
0065   desc.add<edm::InputTag>(("L1IsoCand"), edm::InputTag("hltTowerMakerForAll"));
0066   desc.add<edm::InputTag>(("L1NonIsoCand"), edm::InputTag("fixedGridRhoFastjetAllCalo"));
0067   desc.add<double>(("useTowersInCone"), 0.8);
0068   desc.add<double>(("EtMin"), 1.0);
0069   desc.add<double>(("EMin"), 1.0);
0070   descriptions.add(("hltCaloTowerForEgamma"), desc);
0071 }
0072 
0073 void EgammaHLTCaloTowerProducer::produce(edm::StreamID, edm::Event& evt, edm::EventSetup const&) const {
0074   edm::Handle<CaloTowerCollection> caloTowers;
0075   evt.getByToken(towers_, caloTowers);
0076 
0077   edm::Handle<edm::View<reco::Candidate>> emIsolColl;
0078   evt.getByToken(l1isoseeds_, emIsolColl);
0079   edm::Handle<edm::View<reco::Candidate>> emNonIsolColl;
0080   evt.getByToken(l1nonisoseeds_, emNonIsolColl);
0081   auto cands = std::make_unique<CaloTowerCollection>();
0082   cands->reserve(caloTowers->size());
0083 
0084   for (unsigned idx = 0; idx < caloTowers->size(); idx++) {
0085     const CaloTower* cal = &((*caloTowers)[idx]);
0086     if (cal->et() >= EtThreshold_ && cal->energy() >= EThreshold_) {
0087       bool fill = false;
0088       math::PtEtaPhiELorentzVector p(cal->et(), cal->eta(), cal->phi(), cal->energy());
0089       for (edm::View<reco::Candidate>::const_iterator emItr = emIsolColl->begin(); emItr != emIsolColl->end();
0090            ++emItr) {
0091         double delta = ROOT::Math::VectorUtil::DeltaR((*emItr).p4().Vect(), p);
0092         if (delta < cone_) {
0093           cands->push_back(*cal);
0094           fill = true;
0095           break;
0096         }
0097       }
0098 
0099       if (!fill) {
0100         for (edm::View<reco::Candidate>::const_iterator emItr = emNonIsolColl->begin(); emItr != emNonIsolColl->end();
0101              ++emItr) {
0102           double delta = ROOT::Math::VectorUtil::DeltaR((*emItr).p4().Vect(), p);
0103           if (delta < cone_) {
0104             cands->push_back(*cal);
0105             break;
0106           }
0107         }
0108       }
0109     }
0110   }
0111 
0112   evt.put(std::move(cands));
0113 }
0114 
0115 #include "FWCore/Framework/interface/MakerMacros.h"
0116 DEFINE_FWK_MODULE(EgammaHLTCaloTowerProducer);