CMS 3D CMS Logo

EgammaIsoESDetIdCollectionProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: EgammaIsoESDetIdCollectionProducer
4 // Class: EgammaIsoESDetIdCollectionProducer
5 //
30 
32 public:
36  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
37 
38 private:
39  void addDetIds(const reco::SuperCluster& superClus,
41  const reco::PFCluster::EEtoPSAssociation& eeClusToESMap,
42  std::vector<DetId>& detIdsToStore) const;
43 
44  // ----------member data ---------------------------
50 
52 
53  float minSCEt_;
54  float minEleEt_;
55  float minPhoEt_;
56 
57  float maxDR_;
58 };
59 
62 
64  : eeClusToESMapToken_{consumes(iConfig.getParameter<edm::InputTag>("eeClusToESMapLabel"))},
65  ecalPFClustersToken_{consumes(iConfig.getParameter<edm::InputTag>("ecalPFClustersLabel"))},
66  superClustersToken_{consumes(iConfig.getParameter<edm::InputTag>("superClustersLabel"))},
67  elesToken_{consumes(iConfig.getParameter<edm::InputTag>("elesLabel"))},
68  phosToken_{consumes(iConfig.getParameter<edm::InputTag>("phosLabel"))} {
69  minSCEt_ = iConfig.getParameter<double>("minSCEt");
70  minEleEt_ = iConfig.getParameter<double>("minEleEt");
71  minPhoEt_ = iConfig.getParameter<double>("minPhoEt");
72 
73  interestingDetIdCollection_ = iConfig.getParameter<std::string>("interestingDetIdCollection");
74 
75  maxDR_ = iConfig.getParameter<double>("maxDR");
76 
77  //register your products
78  produces<DetIdCollection>(interestingDetIdCollection_);
79 }
80 
81 // ------------ method called to produce the data ------------
83  auto superClusters = iEvent.getHandle(superClustersToken_);
84  auto eles = iEvent.getHandle(elesToken_);
85  auto phos = iEvent.getHandle(phosToken_);
86  auto eeClusToESMap = iEvent.getHandle(eeClusToESMapToken_);
87  auto ecalPFClusters = iEvent.getHandle(ecalPFClustersToken_);
88 
89  //Create empty output collections
90  std::vector<DetId> indexToStore;
91  indexToStore.reserve(100);
92 
93  if (eles.isValid() && eeClusToESMap.isValid() && ecalPFClusters.isValid()) {
94  for (auto& ele : *eles) {
95  float scEt = ele.superCluster()->energy() * std::sin(ele.superCluster()->position().theta());
96  if (scEt > minEleEt_ || ele.et() > minEleEt_)
97  addDetIds(*ele.superCluster(), *ecalPFClusters, *eeClusToESMap, indexToStore);
98  }
99  }
100  if (phos.isValid() && eeClusToESMap.isValid() && ecalPFClusters.isValid()) {
101  for (auto& pho : *phos) {
102  float scEt = pho.superCluster()->energy() * std::sin(pho.superCluster()->position().theta());
103  if (scEt > minPhoEt_ || pho.et() > minPhoEt_)
104  addDetIds(*pho.superCluster(), *ecalPFClusters, *eeClusToESMap, indexToStore);
105  }
106  }
107  if (superClusters.isValid() && eeClusToESMap.isValid() && ecalPFClusters.isValid()) {
108  for (auto& sc : *superClusters) {
109  float scEt = sc.energy() * std::sin(sc.position().theta());
110  if (scEt > minSCEt_)
111  addDetIds(sc, *ecalPFClusters, *eeClusToESMap, indexToStore);
112  }
113  }
114 
115  //unify the vector
116  std::sort(indexToStore.begin(), indexToStore.end());
117  std::unique(indexToStore.begin(), indexToStore.end());
118 
119  auto detIdCollection = std::make_unique<DetIdCollection>(indexToStore);
120 
121  iEvent.put(std::move(detIdCollection), interestingDetIdCollection_);
122 }
123 
124 //find all clusters within dR2<maxDR2_ of supercluster and then save det id's of hits of all es clusters matched to said ecal clusters
127  const reco::PFCluster::EEtoPSAssociation& eeClusToESMap,
128  std::vector<DetId>& detIdsToStore) const {
129  const float scEta = superClus.eta();
130  // if(std::abs(scEta)+maxDR_<1.5) return; //not possible to have a endcap cluster, let alone one with preshower (eta>1.65) so exit without checking further
131  const float scPhi = superClus.phi();
132 
133  const float maxDR2 = maxDR_ * maxDR_;
134 
135  for (size_t clusNr = 0; clusNr < clusters.size(); clusNr++) {
136  const reco::PFCluster& clus = clusters[clusNr];
137  if (clus.layer() == PFLayer::ECAL_ENDCAP && reco::deltaR2(scEta, scPhi, clus.eta(), clus.phi()) < maxDR2) {
138  auto keyVal = std::make_pair(clusNr, edm::Ptr<reco::PFCluster>());
139  const auto esClusters = std::equal_range(
140  eeClusToESMap.begin(),
141  eeClusToESMap.end(),
142  keyVal,
143  [](const reco::PFCluster::EEtoPSAssociation::value_type& rhs, //roll on c++14, auto & lambda 4 evar!
144  const reco::PFCluster::EEtoPSAssociation::value_type& lhs) -> bool { return rhs.first < lhs.first; });
145  // std::cout <<"cluster "<<clus.eta()<<" had "<<std::distance(esClusters.first,esClusters.second)<<" es clusters"<<std::endl;
146  for (auto esIt = esClusters.first; esIt != esClusters.second; ++esIt) {
147  // std::cout <<"es clus "<<esIt->second->hitsAndFractions().size()<<std::endl;
148  for (const auto& hitAndFrac : esIt->second->hitsAndFractions()) {
149  detIdsToStore.push_back(hitAndFrac.first);
150  }
151  }
152 
153  } //end of endcap & dR check
154  } //end of cluster loop
155 }
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
producer
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
Particle flow cluster, see clustering algorithm in PFClusterAlgo.
Definition: PFCluster.h:42
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
edm::EDGetTokenT< reco::GsfElectronCollection > elesToken_
PFLayer::Layer layer() const
cluster layer, see PFLayer.h in this directory
Definition: PFCluster.cc:56
double phi() const
azimuthal angle of cluster centroid
Definition: CaloCluster.h:184
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
edm::EDGetTokenT< reco::PFCluster::EEtoPSAssociation > eeClusToESMapToken_
int iEvent
Definition: GenABIO.cc:224
edm::EDGetTokenT< reco::PFClusterCollection > ecalPFClustersToken_
def unique(seq, keepstr=True)
Definition: tier0.py:24
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
std::vector< std::pair< CaloClusterPtr::key_type, edm::Ptr< PFCluster > > > EEtoPSAssociation
Definition: PFCluster.h:44
edm::EDGetTokenT< reco::PhotonCollection > phosToken_
void addDetIds(const reco::SuperCluster &superClus, reco::PFClusterCollection clusters, const reco::PFCluster::EEtoPSAssociation &eeClusToESMap, std::vector< DetId > &detIdsToStore) const
std::vector< PFCluster > PFClusterCollection
collection of PFCluster objects
Definition: PFClusterFwd.h:9
edm::EDGetTokenT< reco::SuperClusterCollection > superClustersToken_
double eta() const
pseudorapidity of cluster centroid
Definition: CaloCluster.h:181
def move(src, dest)
Definition: eostools.py:511
EgammaIsoESDetIdCollectionProducer(const edm::ParameterSet &)
ctor