Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:59:08

0001 // -*- C++ -*-
0002 //
0003 // Package:    IsolatedEcalPixelTrackCandidateProducer
0004 // Class:      IsolatedEcalPixelTrackCandidateProducer
0005 //
0006 /**\class IsolatedEcalPixelTrackCandidateProducer IsolatedEcalPixelTrackCandidateProducer.cc Calibration/HcalIsolatedTrackReco/src/IsolatedEcalPixelTrackCandidateProducer.cc
0007 
0008  Description: <one line class summary>
0009 
0010  Implementation:
0011      <Notes on implementation>
0012 */
0013 //
0014 // Original Author:  Ruchi Gupta
0015 //         Created:  Thu Feb 11 17:21:58 MSD 2014
0016 // $Id: IsolatedEcalPixelTrackCandidateProducer.cc,v 1.0 2014/02/11 22:25:52 wmtan Exp $
0017 //
0018 //
0019 
0020 //#define EDM_ML_DEBUG
0021 // system include files
0022 #include <memory>
0023 
0024 // user include files
0025 #include "DataFormats/Common/interface/Ref.h"
0026 #include "DataFormats/DetId/interface/DetId.h"
0027 #include "DataFormats/Math/interface/deltaR.h"
0028 #include "DataFormats/HcalIsolatedTrack/interface/IsolatedPixelTrackCandidate.h"
0029 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
0030 #include "DataFormats/HLTReco/interface/TriggerFilterObjectWithRefs.h"
0031 
0032 #include "FWCore/Framework/interface/Frameworkfwd.h"
0033 #include "FWCore/Framework/interface/global/EDProducer.h"
0034 #include "FWCore/Framework/interface/EventSetup.h"
0035 #include "FWCore/Framework/interface/Event.h"
0036 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0037 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0038 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0039 
0040 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
0041 #include "Geometry/Records/interface/CaloGeometryRecord.h"
0042 
0043 //#define EDM_ML_DEBUG
0044 
0045 //
0046 // class decleration
0047 //
0048 
0049 class IsolatedEcalPixelTrackCandidateProducer : public edm::global::EDProducer<> {
0050 public:
0051   explicit IsolatedEcalPixelTrackCandidateProducer(const edm::ParameterSet&);
0052   ~IsolatedEcalPixelTrackCandidateProducer() override;
0053 
0054   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0055 
0056 private:
0057   void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
0058 
0059   const edm::EDGetTokenT<EcalRecHitCollection> tok_ee;
0060   const edm::EDGetTokenT<EcalRecHitCollection> tok_eb;
0061   const edm::EDGetTokenT<trigger::TriggerFilterObjectWithRefs> tok_trigcand;
0062   const edm::ESGetToken<CaloGeometry, CaloGeometryRecord> tok_geom_;
0063   const double coneSizeEta0_;
0064   const double coneSizeEta1_;
0065   const double hitCountEthrEB_;
0066   const double hitEthrEB_;
0067   const double fachitCountEE_;
0068   const double hitEthrEE0_;
0069   const double hitEthrEE1_;
0070   const double hitEthrEE2_;
0071   const double hitEthrEE3_;
0072 };
0073 
0074 IsolatedEcalPixelTrackCandidateProducer::IsolatedEcalPixelTrackCandidateProducer(const edm::ParameterSet& conf)
0075     : tok_ee(consumes<EcalRecHitCollection>(conf.getParameter<edm::InputTag>("EERecHitSource"))),
0076       tok_eb(consumes<EcalRecHitCollection>(conf.getParameter<edm::InputTag>("EBRecHitSource"))),
0077       tok_trigcand(consumes<trigger::TriggerFilterObjectWithRefs>(conf.getParameter<edm::InputTag>("filterLabel"))),
0078       tok_geom_(esConsumes<CaloGeometry, CaloGeometryRecord>()),
0079       coneSizeEta0_(conf.getParameter<double>("EcalConeSizeEta0")),
0080       coneSizeEta1_(conf.getParameter<double>("EcalConeSizeEta1")),
0081       hitCountEthrEB_(conf.getParameter<double>("EBHitCountEnergyThreshold")),
0082       hitEthrEB_(conf.getParameter<double>("EBHitEnergyThreshold")),
0083       fachitCountEE_(conf.getParameter<double>("EEFacHitCountEnergyThreshold")),
0084       hitEthrEE0_(conf.getParameter<double>("EEHitEnergyThreshold0")),
0085       hitEthrEE1_(conf.getParameter<double>("EEHitEnergyThreshold1")),
0086       hitEthrEE2_(conf.getParameter<double>("EEHitEnergyThreshold2")),
0087       hitEthrEE3_(conf.getParameter<double>("EEHitEnergyThreshold3")) {
0088   // register the products
0089   produces<reco::IsolatedPixelTrackCandidateCollection>();
0090 }
0091 
0092 IsolatedEcalPixelTrackCandidateProducer::~IsolatedEcalPixelTrackCandidateProducer() {}
0093 
0094 void IsolatedEcalPixelTrackCandidateProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0095   edm::ParameterSetDescription desc;
0096   desc.add<edm::InputTag>("filterLabel", edm::InputTag("hltIsolPixelTrackL2Filter"));
0097   desc.add<edm::InputTag>("EBRecHitSource", edm::InputTag("hltEcalRecHit", "EcalRecHitsEB"));
0098   desc.add<edm::InputTag>("EERecHitSource", edm::InputTag("hltEcalRecHit", "EcalRecHitsEE"));
0099   desc.add<double>("EBHitEnergyThreshold", 0.10);
0100   desc.add<double>("EBHitCountEnergyThreshold", 0.5);
0101   desc.add<double>("EEHitEnergyThreshold0", -41.0664);
0102   desc.add<double>("EEHitEnergyThreshold1", 68.7950);
0103   desc.add<double>("EEHitEnergyThreshold2", -38.1483);
0104   desc.add<double>("EEHitEnergyThreshold3", 7.04303);
0105   desc.add<double>("EEFacHitCountEnergyThreshold", 10.0);
0106   desc.add<double>("EcalConeSizeEta0", 0.09);
0107   desc.add<double>("EcalConeSizeEta1", 0.14);
0108   descriptions.add("isolEcalPixelTrackProd", desc);
0109 }
0110 
0111 // ------------ method called to produce the data  ------------
0112 void IsolatedEcalPixelTrackCandidateProducer::produce(edm::StreamID,
0113                                                       edm::Event& iEvent,
0114                                                       const edm::EventSetup& iSetup) const {
0115 #ifdef EDM_ML_DEBUG
0116   edm::LogVerbatim("HcalIsoTrack") << "==============Inside IsolatedEcalPixelTrackCandidateProducer";
0117 #endif
0118   const CaloGeometry* geo = &iSetup.getData(tok_geom_);
0119 
0120   const edm::Handle<EcalRecHitCollection>& ecalEB = iEvent.getHandle(tok_eb);
0121   const edm::Handle<EcalRecHitCollection>& ecalEE = iEvent.getHandle(tok_ee);
0122 #ifdef EDM_ML_DEBUG
0123   edm::LogVerbatim("HcalIsoTrack") << "ecal Collections isValid: " << ecalEB.isValid() << "/" << ecalEE.isValid();
0124 #endif
0125 
0126   const edm::Handle<trigger::TriggerFilterObjectWithRefs>& trigCand = iEvent.getHandle(tok_trigcand);
0127 
0128   std::vector<edm::Ref<reco::IsolatedPixelTrackCandidateCollection> > isoPixTrackRefs;
0129   trigCand->getObjects(trigger::TriggerTrack, isoPixTrackRefs);
0130   int nCand = isoPixTrackRefs.size();
0131 
0132   auto iptcCollection = std::make_unique<reco::IsolatedPixelTrackCandidateCollection>();
0133 #ifdef EDM_ML_DEBUG
0134   edm::LogVerbatim("HcalIsoTrack") << "coneSize_ " << coneSizeEta0_ << "/" << coneSizeEta1_ << " hitCountEthrEB_ "
0135                                    << hitCountEthrEB_ << " hitEthrEB_ " << hitEthrEB_ << " fachitCountEE_ "
0136                                    << fachitCountEE_ << " hitEthrEE " << hitEthrEE0_ << ":" << hitEthrEE1_ << ":"
0137                                    << hitEthrEE2_ << ":" << hitEthrEE3_;
0138 #endif
0139   for (int p = 0; p < nCand; p++) {
0140     int nhitIn(0), nhitOut(0);
0141     double inEnergy(0), outEnergy(0);
0142     std::pair<double, double> etaPhi(isoPixTrackRefs[p]->track()->eta(), isoPixTrackRefs[p]->track()->phi());
0143     if (isoPixTrackRefs[p]->etaPhiEcalValid())
0144       etaPhi = isoPixTrackRefs[p]->etaPhiEcal();
0145     double etaAbs = std::abs(etaPhi.first);
0146     double coneSize_ = (etaAbs > 1.5) ? coneSizeEta1_ : (coneSizeEta0_ * (1.5 - etaAbs) + coneSizeEta1_ * etaAbs) / 1.5;
0147 #ifdef EDM_ML_DEBUG
0148     edm::LogVerbatim("HcalIsoTrack") << "Track: eta/phi " << etaPhi.first << "/" << etaPhi.second
0149                                      << " pt:" << isoPixTrackRefs[p]->track()->pt() << " cone " << coneSize_ << "\n"
0150                                      << "rechit size EB/EE : " << ecalEB->size() << "/" << ecalEE->size()
0151                                      << " coneSize_: " << coneSize_;
0152 #endif
0153     if (etaAbs < 1.7) {
0154       for (auto eItr : *(ecalEB.product())) {
0155         const GlobalPoint& pos = geo->getPosition(eItr.detid());
0156         double R = reco::deltaR(pos.eta(), pos.phi(), etaPhi.first, etaPhi.second);
0157         if (R < coneSize_) {
0158           nhitIn++;
0159           inEnergy += (eItr.energy());
0160           if (eItr.energy() > hitCountEthrEB_)
0161             nhitOut++;
0162           if (eItr.energy() > hitEthrEB_) {
0163             outEnergy += (eItr.energy());
0164           }
0165 #ifdef EDM_ML_DEBUG
0166           edm::LogVerbatim("HcalIsoTrack") << "EBRechit close to the track has E " << eItr.energy()
0167                                            << " eta/phi: " << pos.eta() << "/" << pos.phi() << " deltaR: " << R;
0168 #endif
0169         }
0170       }
0171     }
0172     if (etaAbs > 1.25) {
0173       for (auto eItr : *(ecalEE.product())) {
0174         const GlobalPoint& pos = geo->getPosition(eItr.detid());
0175         double R = reco::deltaR(pos.eta(), pos.phi(), etaPhi.first, etaPhi.second);
0176         if (R < coneSize_) {
0177           double eta = std::abs(pos.eta());
0178           double hitEthr = (((eta * hitEthrEE3_ + hitEthrEE2_) * eta + hitEthrEE1_) * eta + hitEthrEE0_);
0179           if (hitEthr < hitEthrEB_)
0180             hitEthr = hitEthrEB_;
0181           nhitIn++;
0182           inEnergy += (eItr.energy());
0183           if (eItr.energy() > fachitCountEE_ * hitEthr)
0184             nhitOut++;
0185           if (eItr.energy() > hitEthr) {
0186             outEnergy += (eItr.energy());
0187           }
0188 #ifdef EDM_ML_DEBUG
0189           edm::LogVerbatim("HcalIsoTrack") << "EERechit close to the track has E " << eItr.energy()
0190                                            << " eta/phi: " << pos.eta() << "/" << pos.phi() << " deltaR: " << R;
0191 #endif
0192         }
0193       }
0194     }
0195 #ifdef EDM_ML_DEBUG
0196     edm::LogVerbatim("HcalIsoTrack") << "nhitIn:" << nhitIn << " inEnergy:" << inEnergy << " nhitOut:" << nhitOut
0197                                      << " outEnergy:" << outEnergy;
0198 #endif
0199     reco::IsolatedPixelTrackCandidate newca(*isoPixTrackRefs[p]);
0200     newca.setEnergyIn(inEnergy);
0201     newca.setEnergyOut(outEnergy);
0202     newca.setNHitIn(nhitIn);
0203     newca.setNHitOut(nhitOut);
0204     iptcCollection->push_back(newca);
0205   }
0206 #ifdef EDM_ML_DEBUG
0207   edm::LogVerbatim("HcalIsoTrack") << "ncand:" << nCand << " outcollction size:" << iptcCollection->size();
0208 #endif
0209   iEvent.put(std::move(iptcCollection));
0210 }
0211 
0212 #include "FWCore/PluginManager/interface/ModuleDef.h"
0213 #include "FWCore/Framework/interface/MakerMacros.h"
0214 
0215 DEFINE_FWK_MODULE(IsolatedEcalPixelTrackCandidateProducer);