Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:24:54

0001 //*****************************************************************************
0002 // File:      EgammaEcalExtractor.cc
0003 // ----------------------------------------------------------------------------
0004 // Type:      Class implementation header
0005 // Package:   EgammaIsolationAlgos/EgammaIsolationAlgos
0006 // Class:     EgammaEcalExtractor
0007 // Language:  Standard C++
0008 // Project:   CMS
0009 // OrigAuth:  Gilles De Lentdecker
0010 // Institute: IIHE-ULB
0011 //=============================================================================
0012 //*****************************************************************************
0013 
0014 #include "DataFormats/Candidate/interface/Candidate.h"
0015 #include "DataFormats/EgammaReco/interface/BasicCluster.h"
0016 #include "DataFormats/EgammaReco/interface/BasicClusterFwd.h"
0017 #include "DataFormats/EgammaReco/interface/SuperCluster.h"
0018 #include "DataFormats/RecoCandidate/interface/IsoDeposit.h"
0019 #include "DataFormats/RecoCandidate/interface/RecoCandidate.h"
0020 #include "DataFormats/TrackReco/interface/Track.h"
0021 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0022 #include "FWCore/Framework/interface/ConsumesCollector.h"
0023 #include "FWCore/Framework/interface/Event.h"
0024 #include "FWCore/Framework/interface/EventSetup.h"
0025 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0026 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0027 #include "FWCore/Utilities/interface/InputTag.h"
0028 #include "PhysicsTools/IsolationAlgos/interface/IsoDepositExtractor.h"
0029 
0030 #include <Math/VectorUtil.h>
0031 
0032 #include <functional>
0033 #include <vector>
0034 
0035 namespace egammaisolation {
0036 
0037   class EgammaEcalExtractor : public reco::isodeposit::IsoDepositExtractor {
0038   public:
0039     EgammaEcalExtractor(const edm::ParameterSet& par, edm::ConsumesCollector&& iC) : EgammaEcalExtractor(par, iC) {}
0040     EgammaEcalExtractor(const edm::ParameterSet& par, edm::ConsumesCollector& iC)
0041         : etMin_(par.getParameter<double>("etMin")),
0042           conesize_(par.getParameter<double>("extRadius")),
0043           scmatch_(par.getParameter<bool>("superClusterMatch")),
0044           basicClusterToken_(
0045               iC.consumes<reco::BasicClusterCollection>(par.getParameter<edm::InputTag>("basicClusters"))),
0046           superClusterToken_(
0047               iC.consumes<reco::SuperClusterCollection>(par.getParameter<edm::InputTag>("superClusters"))) {}
0048 
0049     ~EgammaEcalExtractor() override;
0050 
0051     void fillVetos(const edm::Event& ev, const edm::EventSetup& evSetup, const reco::TrackCollection& tracks) override {
0052     }
0053     reco::IsoDeposit deposit(const edm::Event& ev,
0054                              const edm::EventSetup& evSetup,
0055                              const reco::Track& track) const override {
0056       throw cms::Exception("Configuration Error")
0057           << "This extractor " << (typeid(this).name()) << " is not made for tracks";
0058     }
0059     reco::IsoDeposit deposit(const edm::Event& ev,
0060                              const edm::EventSetup& evSetup,
0061                              const reco::Candidate& c) const override;
0062 
0063   private:
0064     // ---------- member data --------------------------------
0065 
0066     // Parameters of isolation cone geometry.
0067     // Photon case
0068     double etMin_;
0069     double conesize_;
0070     bool scmatch_;  // true-> reject basic clusters matched to the superclsuter
0071                     // false-> fill all basic clusters
0072     edm::EDGetTokenT<reco::BasicClusterCollection> basicClusterToken_;
0073     edm::EDGetTokenT<reco::SuperClusterCollection> superClusterToken_;
0074   };
0075 
0076 }  // namespace egammaisolation
0077 
0078 #include "FWCore/Framework/interface/MakerMacros.h"
0079 #include "PhysicsTools/IsolationAlgos/interface/IsoDepositExtractorFactory.h"
0080 DEFINE_EDM_PLUGIN(IsoDepositExtractorFactory, egammaisolation::EgammaEcalExtractor, "EgammaEcalExtractor");
0081 
0082 using namespace egammaisolation;
0083 using namespace reco::isodeposit;
0084 
0085 EgammaEcalExtractor::~EgammaEcalExtractor() {}
0086 
0087 reco::IsoDeposit EgammaEcalExtractor::deposit(const edm::Event& ev,
0088                                               const edm::EventSetup& evSetup,
0089                                               const reco::Candidate& candidate) const {
0090   reco::SuperClusterRef sc = candidate.get<reco::SuperClusterRef>();
0091   math::XYZPoint position = sc->position();
0092   // match the photon hybrid supercluster with those with Algo==0 (island)
0093   double delta1 = 1000.;
0094   double deltacur = 1000.;
0095   const reco::SuperCluster* matchedsupercluster = nullptr;
0096   bool MATCHEDSC = false;
0097 
0098   Direction candDir(position.eta(), position.phi());
0099   reco::IsoDeposit deposit(candDir);
0100   deposit.setVeto(reco::IsoDeposit::Veto(candDir, 0));  // no veto is needed for this deposit
0101   deposit.addCandEnergy(sc->energy() * sin(2 * atan(exp(-sc->eta()))));
0102 
0103   for (auto const& scItr : ev.get(superClusterToken_)) {
0104     const reco::SuperCluster* supercluster = &scItr;
0105 
0106     if (supercluster->seed()->algo() == 0) {
0107       deltacur = ROOT::Math::VectorUtil::DeltaR(supercluster->position(), position);
0108       if (deltacur < delta1) {
0109         delta1 = deltacur;
0110         matchedsupercluster = supercluster;
0111         MATCHEDSC = true;
0112       }
0113     }
0114   }
0115 
0116   const reco::BasicCluster* cluster = nullptr;
0117 
0118   //loop over basic clusters
0119   for (auto const& cItr : ev.get(basicClusterToken_)) {
0120     cluster = &cItr;
0121     //    double ebc_bcchi2 = cluster->chi2();
0122     int ebc_bcalgo = cluster->algo();
0123     double ebc_bce = cluster->energy();
0124     double ebc_bceta = cluster->eta();
0125     double ebc_bcet = ebc_bce * sin(2 * atan(exp(ebc_bceta)));
0126     double newDelta = 0.;
0127 
0128     if (ebc_bcet > etMin_ && ebc_bcalgo == 0) {
0129       //      if (ebc_bcchi2 < 30.) {
0130 
0131       if (MATCHEDSC || !scmatch_) {  //skip selection if user wants to fill all superclusters
0132         bool inSuperCluster = false;
0133 
0134         if (scmatch_) {  // only try the matching if needed
0135           reco::CaloCluster_iterator theEclust = matchedsupercluster->clustersBegin();
0136           // loop over the basic clusters of the matched supercluster
0137           for (; theEclust != matchedsupercluster->clustersEnd(); ++theEclust) {
0138             if ((**theEclust) == (*cluster))
0139               inSuperCluster = true;
0140           }
0141         }
0142         if (!inSuperCluster || !scmatch_) {  //skip selection if user wants to fill all superclusters
0143           newDelta = ROOT::Math::VectorUtil::DeltaR(cluster->position(), position);
0144           if (newDelta < conesize_) {
0145             deposit.addDeposit(Direction(cluster->eta(), cluster->phi()), ebc_bcet);
0146           }
0147         }
0148       }
0149       //      } // matches ebc_bcchi2
0150     }  // matches ebc_bcet && ebc_bcalgo
0151   }
0152 
0153   //  std::cout << "Will return ecalIsol = " << ecalIsol << std::endl;
0154   return deposit;
0155 }