Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-02-28 01:32:07

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       int nin(0), nout(0);
0155       for (auto eItr : *(ecalEB.product())) {
0156         const GlobalPoint& pos = geo->getPosition(eItr.detid());
0157         double R = reco::deltaR(pos.eta(), pos.phi(), etaPhi.first, etaPhi.second);
0158         if (R < coneSize_) {
0159           nhitIn++;
0160           inEnergy += (eItr.energy());
0161           ++nin;
0162           if (eItr.energy() > hitCountEthrEB_)
0163             nhitOut++;
0164           if (eItr.energy() > hitEthrEB_) {
0165             outEnergy += (eItr.energy());
0166             ++nout;
0167           }
0168 #ifdef EDM_ML_DEBUG
0169           edm::LogVerbatim("HcalIsoTrack") << "EBRechit close to the track has E " << eItr.energy()
0170                                            << " eta/phi: " << pos.eta() << "/" << pos.phi() << " deltaR: " << R;
0171 #endif
0172         }
0173       }
0174     }
0175     if (etaAbs > 1.25) {
0176       int nin(0), nout(0);
0177       for (auto eItr : *(ecalEE.product())) {
0178         const GlobalPoint& pos = geo->getPosition(eItr.detid());
0179         double R = reco::deltaR(pos.eta(), pos.phi(), etaPhi.first, etaPhi.second);
0180         if (R < coneSize_) {
0181           double eta = std::abs(pos.eta());
0182           double hitEthr = (((eta * hitEthrEE3_ + hitEthrEE2_) * eta + hitEthrEE1_) * eta + hitEthrEE0_);
0183           if (hitEthr < hitEthrEB_)
0184             hitEthr = hitEthrEB_;
0185           nhitIn++;
0186           inEnergy += (eItr.energy());
0187           ++nin;
0188           if (eItr.energy() > fachitCountEE_ * hitEthr)
0189             nhitOut++;
0190           if (eItr.energy() > hitEthr) {
0191             outEnergy += (eItr.energy());
0192             ++nout;
0193           }
0194 #ifdef EDM_ML_DEBUG
0195           edm::LogVerbatim("HcalIsoTrack") << "EERechit close to the track has E " << eItr.energy()
0196                                            << " eta/phi: " << pos.eta() << "/" << pos.phi() << " deltaR: " << R;
0197 #endif
0198         }
0199       }
0200     }
0201 #ifdef EDM_ML_DEBUG
0202     edm::LogVerbatim("HcalIsoTrack") << "nhitIn:" << nhitIn << " inEnergy:" << inEnergy << " nhitOut:" << nhitOut
0203                                      << " outEnergy:" << outEnergy;
0204 #endif
0205     reco::IsolatedPixelTrackCandidate newca(*isoPixTrackRefs[p]);
0206     newca.setEnergyIn(inEnergy);
0207     newca.setEnergyOut(outEnergy);
0208     newca.setNHitIn(nhitIn);
0209     newca.setNHitOut(nhitOut);
0210     iptcCollection->push_back(newca);
0211   }
0212 #ifdef EDM_ML_DEBUG
0213   edm::LogVerbatim("HcalIsoTrack") << "ncand:" << nCand << " outcollction size:" << iptcCollection->size();
0214 #endif
0215   iEvent.put(std::move(iptcCollection));
0216 }
0217 
0218 #include "FWCore/PluginManager/interface/ModuleDef.h"
0219 #include "FWCore/Framework/interface/MakerMacros.h"
0220 
0221 DEFINE_FWK_MODULE(IsolatedEcalPixelTrackCandidateProducer);