File indexing completed on 2024-04-06 12:27:28
0001 #include "RecoParticleFlow/PFProducer/interface/BlockElementLinkerBase.h"
0002 #include "DataFormats/ParticleFlowReco/interface/PFCluster.h"
0003 #include "DataFormats/ParticleFlowReco/interface/PFBlockElementCluster.h"
0004 #include "DataFormats/ParticleFlowReco/interface/PFBlockElementSuperCluster.h"
0005 #include "RecoParticleFlow/PFClusterTools/interface/LinkByRecHit.h"
0006 #include "RecoParticleFlow/PFClusterTools/interface/ClusterClusterMapping.h"
0007
0008 class SCAndHGCalLinker : public BlockElementLinkerBase {
0009 public:
0010 SCAndHGCalLinker(const edm::ParameterSet& conf)
0011 : BlockElementLinkerBase(conf),
0012 useKDTree_(conf.getParameter<bool>("useKDTree")),
0013 debug_(conf.getUntrackedParameter<bool>("debug", false)),
0014 superClusterMatchByRef_(conf.getParameter<bool>("SuperClusterMatchByRef")) {}
0015
0016 double testLink(const reco::PFBlockElement*, const reco::PFBlockElement*) const override;
0017
0018 private:
0019 bool useKDTree_, debug_, superClusterMatchByRef_;
0020 };
0021
0022 DEFINE_EDM_PLUGIN(BlockElementLinkerFactory, SCAndHGCalLinker, "SCAndHGCalLinker");
0023
0024 double SCAndHGCalLinker::testLink(const reco::PFBlockElement* elem1, const reco::PFBlockElement* elem2) const {
0025 double dist = -1.0;
0026 const reco::PFBlockElementCluster* ecalelem(nullptr);
0027 const reco::PFBlockElementSuperCluster* scelem(nullptr);
0028 if (elem1->type() > elem2->type()) {
0029 ecalelem = static_cast<const reco::PFBlockElementCluster*>(elem1);
0030 scelem = static_cast<const reco::PFBlockElementSuperCluster*>(elem2);
0031 } else {
0032 ecalelem = static_cast<const reco::PFBlockElementCluster*>(elem2);
0033 scelem = static_cast<const reco::PFBlockElementSuperCluster*>(elem1);
0034 }
0035 const reco::PFClusterRef& clus = ecalelem->clusterRef();
0036 const reco::SuperClusterRef& sclus = scelem->superClusterRef();
0037 if (sclus.isNull()) {
0038 throw cms::Exception("BadRef") << "SuperClusterRef is invalid!";
0039 }
0040
0041 if (superClusterMatchByRef_) {
0042 if (sclus == ecalelem->superClusterRef())
0043 dist = 0.001;
0044 } else {
0045 if (ClusterClusterMapping::overlap(*sclus, *clus)) {
0046 dist = LinkByRecHit::computeDist(
0047 sclus->position().eta(), sclus->position().phi(), clus->positionREP().Eta(), clus->positionREP().Phi());
0048 }
0049 }
0050
0051 return dist;
0052 }