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 
39 
41 bool sortByKey(const EEPSPair& a, const EEPSPair& b) { return a.first < b.first; }
42 
44 public:
47 
48 private:
49  void produce(edm::Event&, const edm::EventSetup&) override;
50 
55  double matchMaxDR2_;
57 
58  double volumeZ_EB_;
60  double volumeZ_EE_;
61 };
62 
64  //now do what ever initialization is needed
66  consumes<reco::PFClusterCollection>(iConfig.getParameter<edm::InputTag>("pfClustersTag"));
68  consumes<reco::PFCluster::EEtoPSAssociation>(iConfig.getParameter<edm::InputTag>("pfClustersTag"));
70  consumes<TrackingParticleCollection>(iConfig.getParameter<edm::InputTag>("trackingParticleTag"));
71  genParticleToken_ = consumes<reco::GenParticleCollection>(iConfig.getParameter<edm::InputTag>("genParticleTag"));
72 
73  matchMaxDR2_ = iConfig.getParameter<double>("maxDR2");
74  matchMaxDEDR2_ = iConfig.getParameter<double>("maxDEDR2");
75  volumeZ_EB_ = iConfig.getParameter<double>("volumeZ_EB");
76  volumeRadius_EB_ = iConfig.getParameter<double>("volumeRadius_EB");
77  volumeZ_EE_ = iConfig.getParameter<double>("volumeZ_EE");
78 
79  produces<reco::PFClusterCollection>();
80  produces<reco::PFCluster::EEtoPSAssociation>();
81  produces<edm::ValueMap<reco::GenParticleRef> >();
82 }
83 
86  desc.add<edm::InputTag>("pfClustersTag", edm::InputTag("particleFlowClusterECAL"));
87  desc.add<edm::InputTag>("trackingParticleTag", edm::InputTag("mix", "MergedTrackTruth"));
88  desc.add<edm::InputTag>("genParticleTag", edm::InputTag("genParticles"));
89  desc.add<double>("maxDR2", 0.1 * 0.1);
90  desc.add<double>("maxDEDR2", 0.5 * 0.5);
91  desc.add<double>("volumeZ_EB", 304.5);
92  desc.add<double>("volumeRadius_EB", 123.8);
93  desc.add<double>("volumeZ_EE", 317.0);
94  descriptions.add("pfClusterMatchedToPhotonsSelector", desc);
95 }
96 
98  edm::Handle<reco::PFClusterCollection> particleFlowClusterECALHandle_;
100  edm::Handle<TrackingParticleCollection> trackingParticleHandle_;
101  edm::Handle<reco::GenParticleCollection> genParticleHandle_;
102  iEvent.getByToken(particleFlowClusterECALToken_, particleFlowClusterECALHandle_);
103  iEvent.getByToken(trackingParticleToken_, trackingParticleHandle_);
104  iEvent.getByToken(genParticleToken_, genParticleHandle_);
105  iEvent.getByToken(associationToken_, associationHandle_);
106 
107  std::unique_ptr<reco::PFClusterCollection> out = std::make_unique<reco::PFClusterCollection>();
108  std::unique_ptr<reco::PFCluster::EEtoPSAssociation> association_out =
109  std::make_unique<reco::PFCluster::EEtoPSAssociation>();
110  std::unique_ptr<edm::ValueMap<reco::GenParticleRef> > genmatching_out =
111  std::make_unique<edm::ValueMap<reco::GenParticleRef> >();
112 
113  std::vector<reco::GenParticleRef> genmatching;
114 
115  size_t iN(0);
116  for (size_t iP = 0; iP < particleFlowClusterECALHandle_->size(); iP++) {
117  auto&& pfCluster = particleFlowClusterECALHandle_->at(iP);
118  bool isMatched = false;
120 
121  // Preselect PFclusters
122  if (pfCluster.energy() <= 0) {
123  continue;
124  }
125 
126  for (auto&& trackingParticle : *trackingParticleHandle_) {
127  if (trackingParticle.pdgId() != 22)
128  continue;
129  if (trackingParticle.status() != 1)
130  continue;
131  matchedKey = trackingParticle.genParticles().at(0).key();
132  float dR2 = reco::deltaR2(trackingParticle, pfCluster.position());
133  if (dR2 > matchMaxDR2_)
134  continue;
135  float dE = 1. - trackingParticle.genParticles().at(0)->energy() / pfCluster.energy();
136  if ((dR2 + dE * dE) > matchMaxDEDR2_)
137  continue;
138 
139  bool isConversion = false;
140  for (auto&& vertRef : trackingParticle.decayVertices()) {
141  if (vertRef->position().rho() > volumeRadius_EB_ && std::abs(vertRef->position().z()) < volumeZ_EB_)
142  continue;
143  if (std::abs(vertRef->position().z()) > volumeZ_EE_)
144  continue;
145 
146  for (auto&& tpRef : vertRef->daughterTracks()) {
147  if (std::abs(tpRef->pdgId()) == 11)
148  isConversion = true;
149  break;
150  }
151  if (isConversion)
152  break;
153  }
154  if (isConversion)
155  continue;
156 
157  isMatched = true;
158  break;
159  }
160 
161  if (isMatched) {
162  out->push_back(pfCluster);
163  for (size_t i = 0; i < associationHandle_.product()->size(); i++) {
164  if (associationHandle_.product()->at(i).first == iP) {
165  association_out->push_back(std::make_pair(iN, associationHandle_.product()->at(i).second));
166  }
167  }
168  genmatching.push_back(edm::Ref<reco::GenParticleCollection>(genParticleHandle_, matchedKey));
169  }
170  }
171 
172  std::sort(association_out->begin(), association_out->end(), sortByKey);
174  iEvent.put(std::move(association_out));
175 
176  edm::ValueMap<reco::GenParticleRef>::Filler mapFiller(*genmatching_out);
177  mapFiller.insert(pfClusterHandle, genmatching.begin(), genmatching.end());
178  mapFiller.fill();
179  iEvent.put(std::move(genmatching_out));
180 }
181 
182 //define this as a plug-in
PFClusterMatchedToPhotonsSelector::matchMaxDEDR2_
double matchMaxDEDR2_
Definition: PFClusterMatchedToPhotonsSelector.cc:56
PFClusterMatchedToPhotonsSelector::particleFlowClusterECALToken_
edm::EDGetTokenT< reco::PFClusterCollection > particleFlowClusterECALToken_
Definition: PFClusterMatchedToPhotonsSelector.cc:52
edm::helper::Filler::insert
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:53
mps_fire.i
i
Definition: mps_fire.py:428
edm::Handle::product
T const * product() const
Definition: Handle.h:70
PFClusterMatchedToPhotonsSelector::PFClusterMatchedToPhotonsSelector
PFClusterMatchedToPhotonsSelector(const edm::ParameterSet &)
Definition: PFClusterMatchedToPhotonsSelector.cc:63
edm::EDGetTokenT< reco::GenParticleCollection >
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89287
edm::helper::Filler::fill
void fill()
Definition: ValueMap.h:65
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
EDProducer.h
edm::Handle
Definition: AssociativeIterator.h:50
PFClusterMatchedToPhotonsSelector::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &)
Definition: PFClusterMatchedToPhotonsSelector.cc:84
edm::Ref
Definition: AssociativeIterator.h:58
GenParticle.h
MakerMacros.h
PFClusterMatchedToPhotonsSelector::associationToken_
edm::EDGetTokenT< reco::PFCluster::EEtoPSAssociation > associationToken_
Definition: PFClusterMatchedToPhotonsSelector.cc:53
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
GenParticleFwd.h
PFCluster.h
PFClusterMatchedToPhotonsSelector
Definition: PFClusterMatchedToPhotonsSelector.cc:43
b
double b
Definition: hdecay.h:118
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
PFClusterMatchedToPhotonsSelector::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: PFClusterMatchedToPhotonsSelector.cc:97
trackerHitRTTI::isMatched
bool isMatched(TrackingRecHit const &hit)
Definition: trackerHitRTTI.h:33
edm::ParameterSet
Definition: ParameterSet.h:47
a
double a
Definition: hdecay.h:119
Event.h
deltaR.h
reco::deltaR2
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
iEvent
int iEvent
Definition: GenABIO.cc:224
PFClusterFwd.h
edm::stream::EDProducer
Definition: EDProducer.h:38
edm::EventSetup
Definition: EventSetup.h:57
reco::JetExtendedAssociation::value_type
Container::value_type value_type
Definition: JetExtendedAssociation.h:30
edm::Ref< GenParticleCollection >::key_type
std::remove_cv< typename std::remove_reference< argument_type >::type >::type key_type
Definition: Ref.h:164
PFClusterMatchedToPhotonsSelector::volumeZ_EB_
double volumeZ_EB_
Definition: PFClusterMatchedToPhotonsSelector.cc:58
ValueMap.h
TrackingParticle.h
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
eostools.move
def move(src, dest)
Definition: eostools.py:511
Ref.h
edm::OrphanHandle
Definition: EDProductfwd.h:39
TrackingParticleFwd.h
Frameworkfwd.h
PFClusterMatchedToPhotonsSelector::volumeRadius_EB_
double volumeRadius_EB_
Definition: PFClusterMatchedToPhotonsSelector.cc:59
EEPSPair
reco::PFCluster::EEtoPSAssociation::value_type EEPSPair
Definition: PFClusterMatchedToPhotonsSelector.cc:40
PFClusterMatchedToPhotonsSelector::trackingParticleToken_
edm::EDGetTokenT< TrackingParticleCollection > trackingParticleToken_
Definition: PFClusterMatchedToPhotonsSelector.cc:54
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
sortByKey
bool sortByKey(const EEPSPair &a, const EEPSPair &b)
Definition: PFClusterMatchedToPhotonsSelector.cc:41
PFClusterMatchedToPhotonsSelector::matchMaxDR2_
double matchMaxDR2_
Definition: PFClusterMatchedToPhotonsSelector.cc:55
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
edm::helper::Filler
Definition: ValueMap.h:22
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
ParameterSet.h
PFClusterMatchedToPhotonsSelector::genParticleToken_
edm::EDGetTokenT< reco::GenParticleCollection > genParticleToken_
Definition: PFClusterMatchedToPhotonsSelector.cc:51
PFClusterMatchedToPhotonsSelector::volumeZ_EE_
double volumeZ_EE_
Definition: PFClusterMatchedToPhotonsSelector.cc:60
edm::Event
Definition: Event.h:73
edm::InputTag
Definition: InputTag.h:15