CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
List of all members | Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
PuppiPhoton Class Reference
Inheritance diagram for PuppiPhoton:
edm::stream::EDProducer<>

Public Types

typedef edm::View
< reco::Candidate
CandidateView
 
typedef math::XYZTLorentzVector LorentzVector
 
typedef std::vector
< LorentzVector
LorentzVectorCollection
 
typedef std::vector
< reco::PFCandidate
PFOutputCollection
 
typedef edm::View
< reco::PFCandidate
PFView
 
- Public Types inherited from edm::stream::EDProducer<>
using CacheTypes = CacheContexts< T...>
 
using GlobalCache = typename CacheTypes::GlobalCache
 
using HasAbility = AbilityChecker< T...>
 
using InputProcessBlockCache = typename CacheTypes::InputProcessBlockCache
 
using LuminosityBlockCache = typename CacheTypes::LuminosityBlockCache
 
using LuminosityBlockContext = LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCache >
 
using LuminosityBlockSummaryCache = typename CacheTypes::LuminosityBlockSummaryCache
 
using RunCache = typename CacheTypes::RunCache
 
using RunContext = RunContextT< RunCache, GlobalCache >
 
using RunSummaryCache = typename CacheTypes::RunSummaryCache
 

Public Member Functions

 PuppiPhoton (const edm::ParameterSet &)
 
 ~PuppiPhoton () override
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
 EDProducer (const EDProducer &)=delete
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginProcessBlocks () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndProcessBlocks () const final
 
bool hasAbilityToProduceInEndRuns () const final
 
const EDProduceroperator= (const EDProducer &)=delete
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 

Private Member Functions

bool matchPFCandidate (const reco::Candidate *iPF, const reco::Candidate *iPho)
 
void produce (edm::Event &, const edm::EventSetup &) override
 

Private Attributes

std::unique_ptr
< PFOutputCollection
corrCandidates_
 
std::vector< double > dRMatch_
 
double eta_
 
std::vector< int32_t > pdgIds_
 
double pt_
 
edm::EDGetTokenT
< edm::ValueMap< std::vector
< reco::PFCandidateRef > > > 
reco2pf_
 
bool runOnMiniAOD_
 
edm::EDGetTokenT< CandidateViewtokenPFCandidates_
 
edm::EDGetTokenT< CandidateViewtokenPhotonCandidates_
 
edm::EDGetTokenT
< edm::ValueMap< bool > > 
tokenPhotonId_
 
edm::EDGetTokenT< CandidateViewtokenPuppiCandidates_
 
edm::EDGetTokenT
< edm::ValueMap< float > > 
tokenWeights_
 
bool usePFphotons_
 
bool usePFRef_
 
bool usePhotonId_
 
bool useValueMap_
 
double weight_
 

Detailed Description

Definition at line 28 of file PuppiPhoton.cc.

Member Typedef Documentation

Definition at line 36 of file PuppiPhoton.cc.

Definition at line 34 of file PuppiPhoton.cc.

Definition at line 35 of file PuppiPhoton.cc.

Definition at line 37 of file PuppiPhoton.cc.

Definition at line 38 of file PuppiPhoton.cc.

Constructor & Destructor Documentation

PuppiPhoton::PuppiPhoton ( const edm::ParameterSet iConfig)
explicit

Definition at line 63 of file PuppiPhoton.cc.

References dRMatch_, eta_, edm::ParameterSet::getParameter(), pdgIds_, pt_, reco2pf_, runOnMiniAOD_, tokenPFCandidates_, tokenPhotonCandidates_, tokenPhotonId_, tokenPuppiCandidates_, tokenWeights_, usePFphotons_, usePFRef_, usePhotonId_, useValueMap_, and weight_.

63  {
64  tokenPFCandidates_ = consumes<CandidateView>(iConfig.getParameter<edm::InputTag>("candName"));
65  tokenPuppiCandidates_ = consumes<CandidateView>(iConfig.getParameter<edm::InputTag>("puppiCandName"));
66  usePFphotons_ = iConfig.getParameter<bool>("usePFphotons");
67  if (!usePFphotons_)
68  tokenPhotonCandidates_ = consumes<CandidateView>(iConfig.getParameter<edm::InputTag>("photonName"));
69  usePhotonId_ = !(iConfig.getParameter<edm::InputTag>("photonId")).label().empty();
70  if (usePhotonId_)
71  tokenPhotonId_ = consumes<edm::ValueMap<bool>>(iConfig.getParameter<edm::InputTag>("photonId"));
72  runOnMiniAOD_ = iConfig.getParameter<bool>("runOnMiniAOD");
73  if (!runOnMiniAOD_)
74  reco2pf_ =
75  consumes<edm::ValueMap<std::vector<reco::PFCandidateRef>>>(iConfig.getParameter<edm::InputTag>("recoToPFMap"));
76  useValueMap_ = iConfig.getParameter<bool>("useValueMap");
77  if (useValueMap_)
78  tokenWeights_ = consumes<edm::ValueMap<float>>(iConfig.getParameter<edm::InputTag>("weightsName"));
79 
80  pt_ = iConfig.getParameter<double>("pt");
81  eta_ = iConfig.getParameter<double>("eta");
82  dRMatch_ = iConfig.getParameter<std::vector<double>>("dRMatch");
83  pdgIds_ = iConfig.getParameter<std::vector<int32_t>>("pdgids");
84  usePFRef_ = iConfig.getParameter<bool>("useRefs");
85  weight_ = iConfig.getParameter<double>("weight");
86  produces<PFOutputCollection>();
87  produces<edm::ValueMap<reco::CandidatePtr>>();
88 }
std::vector< int32_t > pdgIds_
Definition: PuppiPhoton.cc:56
double pt_
Definition: PuppiPhoton.cc:49
bool runOnMiniAOD_
Definition: PuppiPhoton.cc:53
bool usePFRef_
Definition: PuppiPhoton.cc:51
bool usePFphotons_
Definition: PuppiPhoton.cc:52
edm::EDGetTokenT< edm::ValueMap< float > > tokenWeights_
Definition: PuppiPhoton.cc:47
edm::EDGetTokenT< edm::ValueMap< bool > > tokenPhotonId_
Definition: PuppiPhoton.cc:48
edm::EDGetTokenT< CandidateView > tokenPFCandidates_
Definition: PuppiPhoton.cc:43
bool usePhotonId_
Definition: PuppiPhoton.cc:54
double weight_
Definition: PuppiPhoton.cc:58
double eta_
Definition: PuppiPhoton.cc:50
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::EDGetTokenT< CandidateView > tokenPuppiCandidates_
Definition: PuppiPhoton.cc:44
std::vector< double > dRMatch_
Definition: PuppiPhoton.cc:55
edm::EDGetTokenT< edm::ValueMap< std::vector< reco::PFCandidateRef > > > reco2pf_
Definition: PuppiPhoton.cc:46
bool useValueMap_
Definition: PuppiPhoton.cc:59
edm::EDGetTokenT< CandidateView > tokenPhotonCandidates_
Definition: PuppiPhoton.cc:45
PuppiPhoton::~PuppiPhoton ( )
override

Definition at line 90 of file PuppiPhoton.cc.

90 {}

Member Function Documentation

void PuppiPhoton::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 272 of file PuppiPhoton.cc.

References edm::ConfigurationDescriptions::addDefault(), submitPVResolutionJobs::desc, and edm::ParameterSetDescription::setUnknown().

272  {
273  //The following says we do not know what parameters are allowed so do no validation
274  // Please change this to state exactly what you do use, even if it is no parameters
276  desc.setUnknown();
277  descriptions.addDefault(desc);
278 }
void addDefault(ParameterSetDescription const &psetDescription)
bool PuppiPhoton::matchPFCandidate ( const reco::Candidate iPF,
const reco::Candidate iPho 
)
private

Definition at line 261 of file PuppiPhoton.cc.

References funct::abs(), HLT_FULL_cff::deltaR, dRMatch_, reco::Candidate::eta(), reco::Candidate::pdgId(), pdgIds_, and reco::Candidate::phi().

Referenced by produce().

261  {
262  if (iPF->pdgId() != iPho->pdgId())
263  return false;
264  double lDR = deltaR(iPF->eta(), iPF->phi(), iPho->eta(), iPho->phi());
265  for (unsigned int i0 = 0; i0 < pdgIds_.size(); i0++) {
266  if (std::abs(iPF->pdgId()) == pdgIds_[i0] && lDR < dRMatch_[i0])
267  return true;
268  }
269  return false;
270 }
std::vector< int32_t > pdgIds_
Definition: PuppiPhoton.cc:56
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
virtual int pdgId() const =0
PDG identifier.
std::vector< double > dRMatch_
Definition: PuppiPhoton.cc:55
virtual double phi() const =0
momentum azimuthal angle
virtual double eta() const =0
momentum pseudorapidity
void PuppiPhoton::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
overrideprivate

Definition at line 92 of file PuppiPhoton.cc.

References funct::abs(), pat::Electron::associatedPackedPFCandidates(), pat::Photon::associatedPackedPFCandidates(), edm::View< T >::begin(), RecoTauCleanerPlugins::charge, corrCandidates_, edm::View< T >::end(), relval_parameters_module::energy, eta_, edm::helper::Filler< Map >::fill(), edm::Event::getByToken(), gpuClustering::id, edm::helper::Filler< Map >::insert(), matchPFCandidate(), eostools::move(), edm::Handle< T >::product(), DiDispStaMuonMonitor_cfi::pt, pt_, edm::View< T >::ptrAt(), edm::Event::put(), reco2pf_, edm::View< T >::refAt(), runOnMiniAOD_, reco::LeafCandidate::setP4(), reco::PFCandidate::setSourceCandidatePtr(), edm::View< T >::size(), tokenPFCandidates_, tokenPhotonCandidates_, tokenPhotonId_, tokenPuppiCandidates_, tokenWeights_, reco::PFCandidate::translatePdgIdToType(), usePFphotons_, usePFRef_, usePhotonId_, useValueMap_, makeHLTPrescaleTable::values, and weight_.

92  {
93  int iC = -1;
94  std::vector<const reco::Candidate *> phoCands;
95  std::vector<uint16_t> phoIndx;
96 
98  if (!runOnMiniAOD_)
99  iEvent.getByToken(reco2pf_, reco2pf);
100 
101  // Get PFCandidate Collection
102  edm::Handle<CandidateView> hPFProduct;
103  iEvent.getByToken(tokenPFCandidates_, hPFProduct);
104  const CandidateView *pfCol = hPFProduct.product();
105 
106  edm::Handle<CandidateView> hPuppiProduct;
107  iEvent.getByToken(tokenPuppiCandidates_, hPuppiProduct);
108  const CandidateView *pupCol = hPuppiProduct.product();
109  if (usePFphotons_) {
110  for (const auto &pho : *pfCol) {
111  iC++;
112  if (pho.pt() < pt_)
113  continue;
114  if (std::abs(pho.pdgId()) != 22)
115  continue;
116  if (fabs(pho.eta()) < eta_) {
117  phoIndx.push_back(iC);
118  phoCands.push_back(&pho);
119  }
120  }
121  } else {
122  edm::Handle<CandidateView> hPhoProduct;
123  iEvent.getByToken(tokenPhotonCandidates_, hPhoProduct);
124  const CandidateView *phoCol = hPhoProduct.product();
125 
127  if (usePhotonId_)
128  iEvent.getByToken(tokenPhotonId_, photonId);
129 
130  for (CandidateView::const_iterator itPho = phoCol->begin(); itPho != phoCol->end(); itPho++) {
131  iC++;
132  bool passObject = false;
133  if (itPho->isPhoton() && usePhotonId_)
134  passObject = (*photonId)[phoCol->ptrAt(iC)];
135  if (itPho->pt() < pt_)
136  continue;
137  if (!passObject && usePhotonId_)
138  continue;
139  if (runOnMiniAOD_) {
140  const pat::Photon *pPho = dynamic_cast<const pat::Photon *>(&(*itPho));
141  if (pPho != nullptr) {
143  if (fabs(ref->eta()) < eta_) {
144  phoIndx.push_back(ref.key());
145  phoCands.push_back(&(*(pfCol->ptrAt(ref.key()))));
146  }
147  }
148  continue;
149  }
150  const pat::Electron *pElectron = dynamic_cast<const pat::Electron *>(&(*itPho));
151  if (pElectron != nullptr) {
153  if (fabs(ref->eta()) < eta_) {
154  phoIndx.push_back(ref.key());
155  phoCands.push_back(&(*(pfCol->ptrAt(ref.key()))));
156  }
157  }
158  } else {
159  for (const edm::Ref<std::vector<reco::PFCandidate>> &ref : (*reco2pf)[phoCol->ptrAt(iC)]) {
160  if (fabs(ref->eta()) < eta_) {
161  phoIndx.push_back(ref.key());
162  phoCands.push_back(&(*(pfCol->ptrAt(ref.key()))));
163  }
164  }
165  }
166  }
167  }
168  //Get Weights
170  if (useValueMap_)
171  iEvent.getByToken(tokenWeights_, pupWeights);
172  std::unique_ptr<edm::ValueMap<LorentzVector>> p4PupOut(new edm::ValueMap<LorentzVector>());
173  LorentzVectorCollection puppiP4s;
174  std::vector<reco::CandidatePtr> values(hPFProduct->size());
175  int iPF = 0;
176  std::vector<float> lWeights;
177  static const reco::PFCandidate dummySinceTranslateIsNotStatic;
178  corrCandidates_ = std::make_unique<PFOutputCollection>();
179  std::set<int> foundPhoIndex;
180  for (CandidateView::const_iterator itPF = pupCol->begin(); itPF != pupCol->end(); itPF++) {
181  auto id = dummySinceTranslateIsNotStatic.translatePdgIdToType(itPF->pdgId());
182  const reco::PFCandidate *pPF = dynamic_cast<const reco::PFCandidate *>(&(*itPF));
183  reco::PFCandidate pCand(pPF ? *pPF : reco::PFCandidate(itPF->charge(), itPF->p4(), id));
184  LorentzVector pVec = itPF->p4();
185  float pWeight = 1.;
186  if (useValueMap_)
187  pWeight = (*pupWeights)[pupCol->ptrAt(iPF)];
188  if (!usePFRef_) {
189  int iPho = -1;
190  for (std::vector<const reco::Candidate *>::iterator itPho = phoCands.begin(); itPho != phoCands.end(); itPho++) {
191  iPho++;
192  if ((!matchPFCandidate(&(*itPF), *itPho)) || (foundPhoIndex.count(iPho) != 0))
193  continue;
194  pWeight = weight_;
195  if (!useValueMap_ && itPF->pt() != 0)
196  pWeight = pWeight * (phoCands[iPho]->pt() / itPF->pt());
197  if (!useValueMap_ && itPF->pt() == 0)
198  pVec.SetPxPyPzE(phoCands[iPho]->px() * pWeight,
199  phoCands[iPho]->py() * pWeight,
200  phoCands[iPho]->pz() * pWeight,
201  phoCands[iPho]->energy() * pWeight);
202  foundPhoIndex.insert(iPho);
203  }
204  } else {
205  int iPho = -1;
206  for (std::vector<uint16_t>::const_iterator itPho = phoIndx.begin(); itPho != phoIndx.end(); itPho++) {
207  iPho++;
208  if (pupCol->refAt(iPF).key() != *itPho)
209  continue;
210  pWeight = weight_;
211  if (!useValueMap_ && itPF->pt() != 0)
212  pWeight = pWeight * (phoCands[iPho]->pt() / itPF->pt());
213  if (!useValueMap_ && itPF->pt() == 0)
214  pVec.SetPxPyPzE(phoCands[iPho]->px() * pWeight,
215  phoCands[iPho]->py() * pWeight,
216  phoCands[iPho]->pz() * pWeight,
217  phoCands[iPho]->energy() * pWeight);
218  foundPhoIndex.insert(iPho);
219  }
220  }
221  if (itPF->pt() != 0)
222  pVec.SetPxPyPzE(itPF->px() * pWeight, itPF->py() * pWeight, itPF->pz() * pWeight, itPF->energy() * pWeight);
223 
224  lWeights.push_back(pWeight);
225  pCand.setP4(pVec);
226  puppiP4s.push_back(pVec);
227  pCand.setSourceCandidatePtr(itPF->sourceCandidatePtr(0));
228  corrCandidates_->push_back(pCand);
229  iPF++;
230  }
231  //Add the missing pfcandidates
232  for (unsigned int iPho = 0; iPho < phoCands.size(); iPho++) {
233  if (foundPhoIndex.count(iPho) != 0)
234  continue;
235  auto id = dummySinceTranslateIsNotStatic.translatePdgIdToType(phoCands[iPho]->pdgId());
236  reco::PFCandidate pCand(reco::PFCandidate(phoCands[iPho]->charge(), phoCands[iPho]->p4(), id));
237  pCand.setSourceCandidatePtr(phoCands[iPho]->sourceCandidatePtr(0));
238  LorentzVector pVec = phoCands[iPho]->p4();
239  pVec.SetPxPyPzE(phoCands[iPho]->px() * weight_,
240  phoCands[iPho]->py() * weight_,
241  phoCands[iPho]->pz() * weight_,
242  phoCands[iPho]->energy() * weight_);
243  pCand.setP4(pVec);
244  lWeights.push_back(weight_);
245  puppiP4s.push_back(pVec);
246  corrCandidates_->push_back(pCand);
247  }
248  //Fill it into the event
250  for (unsigned int ic = 0, nc = pupCol->size(); ic < nc; ++ic) {
251  reco::CandidatePtr pkref(oh, ic);
252  values[ic] = pkref;
253  }
254  std::unique_ptr<edm::ValueMap<reco::CandidatePtr>> pfMap_p(new edm::ValueMap<reco::CandidatePtr>());
256  filler.insert(hPFProduct, values.begin(), values.end());
257  filler.fill();
258  iEvent.put(std::move(pfMap_p));
259 }
double pt_
Definition: PuppiPhoton.cc:49
Analysis-level Photon class.
Definition: Photon.h:46
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
uint16_t *__restrict__ id
bool runOnMiniAOD_
Definition: PuppiPhoton.cc:53
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
edm::RefVector< pat::PackedCandidateCollection > associatedPackedPFCandidates() const
References to PFCandidates linked to this object (e.g. for isolation vetos or masking before jet recl...
edm::View< reco::Candidate > CandidateView
Definition: PuppiPhoton.cc:36
bool usePFRef_
Definition: PuppiPhoton.cc:51
bool usePFphotons_
Definition: PuppiPhoton.cc:52
edm::EDGetTokenT< edm::ValueMap< float > > tokenWeights_
Definition: PuppiPhoton.cc:47
def move
Definition: eostools.py:511
edm::EDGetTokenT< edm::ValueMap< bool > > tokenPhotonId_
Definition: PuppiPhoton.cc:48
edm::EDGetTokenT< CandidateView > tokenPFCandidates_
Definition: PuppiPhoton.cc:43
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
math::XYZTLorentzVector LorentzVector
bool matchPFCandidate(const reco::Candidate *iPF, const reco::Candidate *iPho)
Definition: PuppiPhoton.cc:261
bool usePhotonId_
Definition: PuppiPhoton.cc:54
std::vector< LorentzVector > LorentzVectorCollection
double weight_
Definition: PuppiPhoton.cc:58
double eta_
Definition: PuppiPhoton.cc:50
T const * product() const
Definition: Handle.h:70
Analysis-level electron class.
Definition: Electron.h:51
ParticleType translatePdgIdToType(int pdgid) const
Definition: PFCandidate.cc:231
edm::EDGetTokenT< CandidateView > tokenPuppiCandidates_
Definition: PuppiPhoton.cc:44
std::unique_ptr< PFOutputCollection > corrCandidates_
Definition: PuppiPhoton.cc:57
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:41
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
edm::EDGetTokenT< edm::ValueMap< std::vector< reco::PFCandidateRef > > > reco2pf_
Definition: PuppiPhoton.cc:46
edm::RefVector< pat::PackedCandidateCollection > associatedPackedPFCandidates() const
References to PFCandidates linked to this object (e.g. for isolation vetos or masking before jet recl...
bool useValueMap_
Definition: PuppiPhoton.cc:59
edm::EDGetTokenT< CandidateView > tokenPhotonCandidates_
Definition: PuppiPhoton.cc:45

Member Data Documentation

std::unique_ptr<PFOutputCollection> PuppiPhoton::corrCandidates_
private

Definition at line 57 of file PuppiPhoton.cc.

Referenced by produce().

std::vector<double> PuppiPhoton::dRMatch_
private

Definition at line 55 of file PuppiPhoton.cc.

Referenced by matchPFCandidate(), and PuppiPhoton().

double PuppiPhoton::eta_
private

Definition at line 50 of file PuppiPhoton.cc.

Referenced by produce(), and PuppiPhoton().

std::vector<int32_t> PuppiPhoton::pdgIds_
private

Definition at line 56 of file PuppiPhoton.cc.

Referenced by matchPFCandidate(), and PuppiPhoton().

double PuppiPhoton::pt_
private

Definition at line 49 of file PuppiPhoton.cc.

Referenced by produce(), and PuppiPhoton().

edm::EDGetTokenT<edm::ValueMap<std::vector<reco::PFCandidateRef> > > PuppiPhoton::reco2pf_
private

Definition at line 46 of file PuppiPhoton.cc.

Referenced by produce(), and PuppiPhoton().

bool PuppiPhoton::runOnMiniAOD_
private

Definition at line 53 of file PuppiPhoton.cc.

Referenced by produce(), and PuppiPhoton().

edm::EDGetTokenT<CandidateView> PuppiPhoton::tokenPFCandidates_
private

Definition at line 43 of file PuppiPhoton.cc.

Referenced by produce(), and PuppiPhoton().

edm::EDGetTokenT<CandidateView> PuppiPhoton::tokenPhotonCandidates_
private

Definition at line 45 of file PuppiPhoton.cc.

Referenced by produce(), and PuppiPhoton().

edm::EDGetTokenT<edm::ValueMap<bool> > PuppiPhoton::tokenPhotonId_
private

Definition at line 48 of file PuppiPhoton.cc.

Referenced by produce(), and PuppiPhoton().

edm::EDGetTokenT<CandidateView> PuppiPhoton::tokenPuppiCandidates_
private

Definition at line 44 of file PuppiPhoton.cc.

Referenced by produce(), and PuppiPhoton().

edm::EDGetTokenT<edm::ValueMap<float> > PuppiPhoton::tokenWeights_
private

Definition at line 47 of file PuppiPhoton.cc.

Referenced by produce(), and PuppiPhoton().

bool PuppiPhoton::usePFphotons_
private

Definition at line 52 of file PuppiPhoton.cc.

Referenced by produce(), and PuppiPhoton().

bool PuppiPhoton::usePFRef_
private

Definition at line 51 of file PuppiPhoton.cc.

Referenced by produce(), and PuppiPhoton().

bool PuppiPhoton::usePhotonId_
private

Definition at line 54 of file PuppiPhoton.cc.

Referenced by produce(), and PuppiPhoton().

bool PuppiPhoton::useValueMap_
private

Definition at line 59 of file PuppiPhoton.cc.

Referenced by produce(), and PuppiPhoton().

double PuppiPhoton::weight_
private

Definition at line 58 of file PuppiPhoton.cc.

Referenced by produce(), and PuppiPhoton().