Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:01:06

0001 #include "PFCandWithSuperClusterExtractor.h"
0002 
0003 #include "DataFormats/RecoCandidate/interface/IsoDepositDirection.h"
0004 #include "DataFormats/Common/interface/Handle.h"
0005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0006 #include "DataFormats/Math/interface/deltaR.h"
0007 #include "DataFormats/GsfTrackReco/interface/GsfTrack.h"
0008 
0009 using namespace edm;
0010 using namespace reco;
0011 
0012 PFCandWithSuperClusterExtractor::PFCandWithSuperClusterExtractor(const ParameterSet& par, edm::ConsumesCollector&& iC)
0013     : thePFCandToken(iC.consumes<PFCandidateCollection>(par.getParameter<edm::InputTag>("inputCandView"))),
0014       theDepositLabel(par.getUntrackedParameter<std::string>("DepositLabel")),
0015       theVetoSuperClusterMatch(par.getParameter<bool>("SCMatch_Veto")),
0016       theMissHitVetoSuperClusterMatch(par.getParameter<bool>("MissHitSCMatch_Veto")),
0017       theDiff_r(par.getParameter<double>("Diff_r")),
0018       theDiff_z(par.getParameter<double>("Diff_z")),
0019       theDR_Max(par.getParameter<double>("DR_Max")),
0020       theDR_Veto(par.getParameter<double>("DR_Veto")) {
0021   //  std::cout << " Loading PFCandWithSuperClusterExtractor "  << std::endl;
0022 }
0023 /*
0024 reco::IsoDeposit::Vetos PFCandWithSuperClusterExtractor::vetos(const edm::Event & ev,
0025       const edm::EventSetup & evSetup, const reco::Candidate & cand) const
0026 {
0027   reco::isodeposit::Direction dir(cand.eta(),cand.phi());
0028   return reco::IsoDeposit::Vetos(1,veto(dir));
0029 }
0030 */
0031 
0032 reco::IsoDeposit::Veto PFCandWithSuperClusterExtractor::veto(const reco::IsoDeposit::Direction& dir) const {
0033   reco::IsoDeposit::Veto result;
0034   result.vetoDir = dir;
0035   result.dR = theDR_Veto;
0036   return result;
0037 }
0038 
0039 IsoDeposit PFCandWithSuperClusterExtractor::depositFromObject(const Event& event,
0040                                                               const EventSetup& eventSetup,
0041                                                               const Photon& cand) const {
0042   reco::isodeposit::Direction candDir(cand.eta(), cand.phi());
0043   IsoDeposit deposit(candDir);
0044   deposit.setVeto(veto(candDir));
0045   deposit.addCandEnergy(cand.pt());
0046 
0047   Handle<PFCandidateCollection> PFCandH;
0048   event.getByToken(thePFCandToken, PFCandH);
0049 
0050   double eta = cand.eta(), phi = cand.phi();
0051   const reco::Particle::Point& vtx = cand.vertex();
0052   for (PFCandidateCollection::const_iterator it = PFCandH->begin(), ed = PFCandH->end(); it != ed; ++it) {
0053     double dR = deltaR(it->eta(), it->phi(), eta, phi);
0054     // veto SC
0055     if (theVetoSuperClusterMatch && cand.superCluster().isNonnull() && it->superClusterRef().isNonnull() &&
0056         cand.superCluster() == it->superClusterRef())
0057       continue;
0058     if ((dR < theDR_Max) && (dR > theDR_Veto) && (std::abs(it->vz() - cand.vz()) < theDiff_z) &&
0059         ((it->vertex() - vtx).Rho() < theDiff_r)) {
0060       // ok
0061       reco::isodeposit::Direction dirTrk(it->eta(), it->phi());
0062       deposit.addDeposit(dirTrk, it->pt());
0063     }
0064   }
0065 
0066   return deposit;
0067 }
0068 
0069 IsoDeposit PFCandWithSuperClusterExtractor::depositFromObject(const Event& event,
0070                                                               const EventSetup& eventSetup,
0071                                                               const GsfElectron& cand) const {
0072   reco::isodeposit::Direction candDir(cand.eta(), cand.phi());
0073   IsoDeposit deposit(candDir);
0074   deposit.setVeto(veto(candDir));
0075   deposit.addCandEnergy(cand.pt());
0076 
0077   Handle<PFCandidateCollection> PFCandH;
0078   event.getByToken(thePFCandToken, PFCandH);
0079 
0080   double eta = cand.eta(), phi = cand.phi();
0081   const reco::Particle::Point& vtx = cand.vertex();
0082   for (PFCandidateCollection::const_iterator it = PFCandH->begin(), ed = PFCandH->end(); it != ed; ++it) {
0083     double dR = deltaR(it->eta(), it->phi(), eta, phi);
0084     // If MissHits>0 (possibly reconstructed as a photon in the PF in this case, kill the the photon if sharing the same SC)
0085     if (cand.gsfTrack()->hitPattern().numberOfLostHits(reco::HitPattern::MISSING_INNER_HITS) > 0 &&
0086         theMissHitVetoSuperClusterMatch && it->mva_nothing_gamma() > 0.99 && cand.superCluster().isNonnull() &&
0087         it->superClusterRef().isNonnull() && cand.superCluster() == it->superClusterRef()) {
0088       continue;
0089     }
0090     if ((dR < theDR_Max) && (dR > theDR_Veto) && (std::abs(it->vz() - cand.vz()) < theDiff_z) &&
0091         ((it->vertex() - vtx).Rho() < theDiff_r)) {
0092       // ok
0093       reco::isodeposit::Direction dirTrk(it->eta(), it->phi());
0094       deposit.addDeposit(dirTrk, it->pt());
0095     }
0096   }
0097 
0098   return deposit;
0099 }
0100 
0101 IsoDeposit PFCandWithSuperClusterExtractor::depositFromObject(const Event& event,
0102                                                               const EventSetup& eventSetup,
0103                                                               const Track& cand) const {
0104   reco::isodeposit::Direction candDir(cand.eta(), cand.phi());
0105   IsoDeposit deposit(candDir);
0106   deposit.setVeto(veto(candDir));
0107   deposit.addCandEnergy(cand.pt());
0108   Handle<PFCandidateCollection> PFCandH;
0109   event.getByToken(thePFCandToken, PFCandH);
0110 
0111   double eta = cand.eta(), phi = cand.phi();
0112   const reco::Particle::Point& vtx = cand.vertex();
0113   for (PFCandidateCollection::const_iterator it = PFCandH->begin(), ed = PFCandH->end(); it != ed; ++it) {
0114     double dR = deltaR(it->eta(), it->phi(), eta, phi);
0115 
0116     if ((dR < theDR_Max) && (dR > theDR_Veto) && (std::abs(it->vz() - cand.vz()) < theDiff_z) &&
0117         ((it->vertex() - vtx).Rho() < theDiff_r)) {
0118       // ok
0119       reco::isodeposit::Direction dirTrk(it->eta(), it->phi());
0120       deposit.addDeposit(dirTrk, it->pt());
0121     }
0122   }
0123 
0124   return deposit;
0125 }
0126 
0127 IsoDeposit PFCandWithSuperClusterExtractor::depositFromObject(const Event& event,
0128                                                               const EventSetup& eventSetup,
0129                                                               const PFCandidate& cand) const {
0130   reco::isodeposit::Direction candDir(cand.eta(), cand.phi());
0131   IsoDeposit deposit(candDir);
0132   deposit.setVeto(veto(candDir));
0133   deposit.addCandEnergy(cand.pt());
0134   Handle<PFCandidateCollection> PFCandH;
0135   event.getByToken(thePFCandToken, PFCandH);
0136 
0137   double eta = cand.eta(), phi = cand.phi();
0138   const reco::Particle::Point& vtx = cand.vertex();
0139   for (PFCandidateCollection::const_iterator it = PFCandH->begin(), ed = PFCandH->end(); it != ed; ++it) {
0140     // veto SC
0141     if (theVetoSuperClusterMatch && cand.superClusterRef().isNonnull() && it->superClusterRef().isNonnull() &&
0142         cand.superClusterRef() == it->superClusterRef())
0143       continue;
0144     double dR = deltaR(it->eta(), it->phi(), eta, phi);
0145 
0146     if ((dR < theDR_Max) && (dR > theDR_Veto) && (std::abs(it->vz() - cand.vz()) < theDiff_z) &&
0147         ((it->vertex() - vtx).Rho() < theDiff_r)) {
0148       // ok
0149       reco::isodeposit::Direction dirTrk(it->eta(), it->phi());
0150       deposit.addDeposit(dirTrk, it->pt());
0151     }
0152   }
0153 
0154   return deposit;
0155 }
0156 
0157 #include "FWCore/PluginManager/interface/ModuleDef.h"
0158 #include "FWCore/Framework/interface/MakerMacros.h"
0159 
0160 #include "PhysicsTools/IsolationAlgos/interface/IsoDepositExtractor.h"
0161 #include "PhysicsTools/IsolationAlgos/interface/IsoDepositExtractorFactory.h"
0162 #include "PFCandWithSuperClusterExtractor.h"
0163 DEFINE_EDM_PLUGIN(IsoDepositExtractorFactory, PFCandWithSuperClusterExtractor, "PFCandWithSuperClusterExtractor");