CMS 3D CMS Logo

PFClusterMatchedToPhotonsSelector.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: CommonTools/RecoAlgos
4 // Class: PFClusterMatchedToPhotonsSelector
5 //
13 //
14 // Original Author: RCLSA
15 // Created: Wed, 22 Mar 2017 18:01:40 GMT
16 //
17 //
18 
19 // system include files
20 #include <memory>
21 #include <iostream>
22 
23 // user include files
29 
41 
43 bool sortByKey(const EEPSPair& a, const EEPSPair& b) { return a.first < b.first; }
44 
46 public:
49 
50 private:
51  void produce(edm::Event&, const edm::EventSetup&) override;
52 
59 
61 
62  double matchMaxDR2_;
64 
65  double volumeZ_EB_;
67  double volumeZ_EE_;
68 };
69 
71  : ecalClusterToolsESGetTokens_{consumesCollector()} {
72  //now do what ever initialization is needed
73  particleFlowClusterECALToken_ =
74  consumes<reco::PFClusterCollection>(iConfig.getParameter<edm::InputTag>("pfClustersTag"));
75  associationToken_ =
76  consumes<reco::PFCluster::EEtoPSAssociation>(iConfig.getParameter<edm::InputTag>("pfClustersTag"));
77  trackingParticleToken_ =
78  consumes<TrackingParticleCollection>(iConfig.getParameter<edm::InputTag>("trackingParticleTag"));
79  genParticleToken_ = consumes<reco::GenParticleCollection>(iConfig.getParameter<edm::InputTag>("genParticleTag"));
80  recHitsEB_ = consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("recHitsEBLabel"));
81  recHitsEE_ = consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("recHitsEELabel"));
82 
83  matchMaxDR2_ = iConfig.getParameter<double>("maxDR2");
84  matchMaxDEDR2_ = iConfig.getParameter<double>("maxDEDR2");
85  volumeZ_EB_ = iConfig.getParameter<double>("volumeZ_EB");
86  volumeRadius_EB_ = iConfig.getParameter<double>("volumeRadius_EB");
87  volumeZ_EE_ = iConfig.getParameter<double>("volumeZ_EE");
88 
89  produces<reco::PFClusterCollection>();
90  produces<edm::ValueMap<reco::GenParticleRef> >();
91  produces<edm::ValueMap<int> >();
92  produces<edm::ValueMap<float> >("PS1");
93  produces<edm::ValueMap<float> >("PS2");
94 }
95 
98  desc.add<edm::InputTag>("pfClustersTag", edm::InputTag("particleFlowClusterECAL"));
99  desc.add<edm::InputTag>("trackingParticleTag", edm::InputTag("mix", "MergedTrackTruth"));
100  desc.add<edm::InputTag>("genParticleTag", edm::InputTag("genParticles"));
101  desc.add<edm::InputTag>("recHitsEBLabel", edm::InputTag("ecalRecHit", "EcalRecHitsEB"));
102  desc.add<edm::InputTag>("recHitsEELabel", edm::InputTag("ecalRecHit", "EcalRecHitsEE"));
103  desc.add<double>("maxDR2", 0.1 * 0.1);
104  desc.add<double>("maxDEDR2", 0.5 * 0.5);
105  desc.add<double>("volumeZ_EB", 304.5);
106  desc.add<double>("volumeRadius_EB", 123.8);
107  desc.add<double>("volumeZ_EE", 317.0);
108  descriptions.add("pfClusterMatchedToPhotonsSelector", desc);
109 }
110 
112  edm::Handle<reco::PFClusterCollection> particleFlowClusterECALHandle_;
114  edm::Handle<TrackingParticleCollection> trackingParticleHandle_;
115  edm::Handle<reco::GenParticleCollection> genParticleHandle_;
116 
117  iEvent.getByToken(particleFlowClusterECALToken_, particleFlowClusterECALHandle_);
118  iEvent.getByToken(trackingParticleToken_, trackingParticleHandle_);
119  iEvent.getByToken(genParticleToken_, genParticleHandle_);
120  iEvent.getByToken(associationToken_, associationHandle_);
121 
122  std::unique_ptr<reco::PFClusterCollection> out = std::make_unique<reco::PFClusterCollection>();
123  std::unique_ptr<edm::ValueMap<reco::GenParticleRef> > genmatching_out =
124  std::make_unique<edm::ValueMap<reco::GenParticleRef> >();
125  std::unique_ptr<edm::ValueMap<int> > clustersize_out = std::make_unique<edm::ValueMap<int> >();
126  std::unique_ptr<edm::ValueMap<float> > energyPS1_out = std::make_unique<edm::ValueMap<float> >();
127  std::unique_ptr<edm::ValueMap<float> > energyPS2_out = std::make_unique<edm::ValueMap<float> >();
128 
129  std::vector<reco::GenParticleRef> genmatching;
130  std::vector<int> clustersize;
131  std::vector<float> energyPS1;
132  std::vector<float> energyPS2;
133 
135 
136  for (size_t iP = 0; iP < particleFlowClusterECALHandle_->size(); iP++) {
137  auto&& pfCluster = particleFlowClusterECALHandle_->at(iP);
138  bool isMatched = false;
140 
141  // Preselect PFclusters
142  if (pfCluster.energy() <= 0) {
143  continue;
144  }
145 
146  for (auto&& trackingParticle : *trackingParticleHandle_) {
147  if (trackingParticle.pdgId() != 22)
148  continue;
149  if (trackingParticle.status() != 1)
150  continue;
151  matchedKey = trackingParticle.genParticles().at(0).key();
152 
153  float dR2 = reco::deltaR2(trackingParticle, pfCluster.position());
154  if (dR2 > matchMaxDR2_)
155  continue;
156  float dE = 1. - trackingParticle.genParticles().at(0)->energy() / pfCluster.energy();
157  if ((dR2 + dE * dE) > matchMaxDEDR2_)
158  continue;
159 
160  bool isConversion = false;
161  for (auto&& vertRef : trackingParticle.decayVertices()) {
162  if (vertRef->position().rho() > volumeRadius_EB_ && std::abs(vertRef->position().z()) < volumeZ_EB_)
163  continue;
164  if (std::abs(vertRef->position().z()) > volumeZ_EE_)
165  continue;
166 
167  for (auto&& tpRef : vertRef->daughterTracks()) {
168  if (std::abs(tpRef->pdgId()) == 11)
169  isConversion = true;
170  break;
171  }
172  if (isConversion)
173  break;
174  }
175  if (isConversion)
176  continue;
177 
178  isMatched = true;
179  break;
180  }
181 
182  if (isMatched) {
183  out->push_back(pfCluster);
184  double ePS1 = 0, ePS2 = 0;
185  if (!(pfCluster.layer() == PFLayer::ECAL_BARREL)) {
186  auto ee_key_val = std::make_pair(iP, edm::Ptr<reco::PFCluster>());
187  const auto clustops = std::equal_range(
188  associationHandle_.product()->begin(), associationHandle_.product()->end(), ee_key_val, sortByKey);
189  for (auto i_ps = clustops.first; i_ps != clustops.second; ++i_ps) {
190  edm::Ptr<reco::PFCluster> psclus(i_ps->second);
191  switch (psclus->layer()) {
192  case PFLayer::PS1:
193  ePS1 += psclus->energy();
194  break;
195  case PFLayer::PS2:
196  ePS2 += psclus->energy();
197  break;
198  default:
199  break;
200  }
201  }
202  }
203 
204  genmatching.push_back(edm::Ref<reco::GenParticleCollection>(genParticleHandle_, matchedKey));
205  clustersize.push_back(lazyTool.n5x5(pfCluster));
206  energyPS1.push_back(ePS1);
207  energyPS2.push_back(ePS2);
208  }
209  }
210 
212 
213  edm::ValueMap<reco::GenParticleRef>::Filler mapFiller(*genmatching_out);
214  mapFiller.insert(pfClusterHandle, genmatching.begin(), genmatching.end());
215  mapFiller.fill();
216  iEvent.put(std::move(genmatching_out));
217 
218  edm::ValueMap<int>::Filler mapFiller_int(*clustersize_out);
219  mapFiller_int.insert(pfClusterHandle, clustersize.begin(), clustersize.end());
220  mapFiller_int.fill();
221  iEvent.put(std::move(clustersize_out));
222 
223  edm::ValueMap<float>::Filler mapFiller_energyPS1(*energyPS1_out);
224  mapFiller_energyPS1.insert(pfClusterHandle, energyPS1.begin(), energyPS1.end());
225  mapFiller_energyPS1.fill();
226  iEvent.put(std::move(energyPS1_out), "PS1");
227 
228  edm::ValueMap<float>::Filler mapFiller_energyPS2(*energyPS2_out);
229  mapFiller_energyPS2.insert(pfClusterHandle, energyPS2.begin(), energyPS2.end());
230  mapFiller_energyPS2.fill();
231  iEvent.put(std::move(energyPS2_out), "PS2");
232 }
233 
234 //define this as a plug-in
std::remove_cv< typename std::remove_reference< argument_type >::type >::type key_type
Definition: Ref.h:164
edm::EDGetTokenT< reco::GenParticleCollection > genParticleToken_
T const * product() const
Definition: Handle.h:70
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:53
PFLayer::Layer layer() const
cluster layer, see PFLayer.h in this directory
Definition: PFCluster.cc:56
ESData get(edm::EventSetup const &eventSetup) const
edm::EDGetTokenT< EcalRecHitCollection > recHitsEB_
int iEvent
Definition: GenABIO.cc:224
const EcalClusterLazyTools::ESGetTokens ecalClusterToolsESGetTokens_
edm::EDGetTokenT< EcalRecHitCollection > recHitsEE_
double energy() const
cluster energy
Definition: PFCluster.h:74
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
edm::EDGetTokenT< TrackingParticleCollection > trackingParticleToken_
bool isMatched(TrackingRecHit const &hit)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::EDGetTokenT< reco::PFClusterCollection > particleFlowClusterECALToken_
static void fillDescriptions(edm::ConfigurationDescriptions &)
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
reco::PFCluster::EEtoPSAssociation::value_type EEPSPair
bool sortByKey(const EEPSPair &a, const EEPSPair &b)
double b
Definition: hdecay.h:120
void add(std::string const &label, ParameterSetDescription const &psetDescription)
double a
Definition: hdecay.h:121
void produce(edm::Event &, const edm::EventSetup &) override
edm::EDGetTokenT< reco::PFCluster::EEtoPSAssociation > associationToken_
PFClusterMatchedToPhotonsSelector(const edm::ParameterSet &)
def move(src, dest)
Definition: eostools.py:511