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
PuppiProducer Class Reference
Inheritance diagram for PuppiProducer:
edm::stream::EDProducer<>

Public Types

typedef edm::View
< reco::Candidate
CandidateView
 
typedef edm::Association
< reco::VertexCollection
CandToVertex
 
typedef math::XYZTLorentzVector LorentzVector
 
typedef std::vector
< LorentzVector
LorentzVectorCollection
 
typedef std::vector
< pat::PackedCandidate
PackedOutputCollection
 
typedef std::vector
< reco::PFCandidate
PFInputCollection
 
typedef std::vector
< reco::PFCandidate
PFOutputCollection
 
typedef edm::View
< reco::PFCandidate
PFView
 
typedef reco::VertexCollection VertexCollection
 
- 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

 PuppiProducer (const edm::ParameterSet &)
 
 ~PuppiProducer () 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

virtual void beginJob ()
 
virtual void endJob ()
 
void produce (edm::Event &, const edm::EventSetup &) override
 

Private Attributes

bool fClonePackedCands
 
double fDZCut
 
double fDZCutForChargedFromPUVtxs
 
double fEtaMaxCharged
 
double fEtaMaxPhotons
 
double fEtaMinUseDZ
 
uint fNumOfPUVtxsForCharged
 
std::string fPFName
 
double fPtMaxCharged
 
double fPtMaxPhotons
 
std::unique_ptr< PuppiContainerfPuppiContainer
 
bool fPuppiDiagnostics
 
std::string fPuppiName
 
bool fPuppiNoLep
 
std::string fPVName
 
std::vector< RecoObjfRecoObjCollection
 
bool fUseDZ
 
bool fUseExistingWeights
 
bool fUseFromPVLooseTight
 
bool fUsePUProxyValue
 
bool fUseVertexAssociation
 
int fVtxNdofCut
 
double fVtxZCut
 
edm::EDPutTokenT< std::vector
< double > > 
ptokenAlphas_
 
edm::EDPutTokenT< std::vector
< double > > 
ptokenAlphasMed_
 
edm::EDPutTokenT< std::vector
< double > > 
ptokenAlphasRms_
 
edm::EDPutTokenT< double > ptokenNalgos_
 
edm::EDPutTokenT
< edm::ValueMap< LorentzVector > > 
ptokenP4PupOut_
 
edm::EDPutTokenT
< pat::PackedCandidateCollection
ptokenPackedPuppiCandidates_
 
edm::EDPutTokenT
< edm::ValueMap< float > > 
ptokenPupOut_
 
edm::EDPutTokenT
< reco::PFCandidateCollection
ptokenPuppiCandidates_
 
edm::EDPutTokenT< std::vector
< double > > 
ptokenRawAlphas_
 
edm::EDPutTokenT
< edm::ValueMap
< reco::CandidatePtr > > 
ptokenValues_
 
edm::EDGetTokenT< double > puProxyValueToken_
 
edm::EDGetTokenT
< PackedOutputCollection
tokenPackedPuppiCandidates_
 
edm::EDGetTokenT< CandidateViewtokenPFCandidates_
 
edm::EDGetTokenT
< PFOutputCollection
tokenPuppiCandidates_
 
edm::EDGetTokenT< PuppiContainertokenPuppiContainer_
 
edm::EDGetTokenT< CandToVertextokenVertexAssociation_
 
edm::EDGetTokenT
< edm::ValueMap< int > > 
tokenVertexAssociationQuality_
 
edm::EDGetTokenT
< VertexCollection
tokenVertices_
 
int vertexAssociationQuality_
 

Detailed Description

Definition at line 27 of file PuppiProducer.cc.

Member Typedef Documentation

Definition at line 36 of file PuppiProducer.cc.

Definition at line 41 of file PuppiProducer.cc.

Definition at line 33 of file PuppiProducer.cc.

Definition at line 34 of file PuppiProducer.cc.

Definition at line 39 of file PuppiProducer.cc.

Definition at line 37 of file PuppiProducer.cc.

Definition at line 38 of file PuppiProducer.cc.

Definition at line 40 of file PuppiProducer.cc.

Definition at line 35 of file PuppiProducer.cc.

Constructor & Destructor Documentation

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

Definition at line 93 of file PuppiProducer.cc.

References fClonePackedCands, fDZCut, fDZCutForChargedFromPUVtxs, fEtaMaxCharged, fEtaMaxPhotons, fEtaMinUseDZ, fNumOfPUVtxsForCharged, fPtMaxCharged, fPtMaxPhotons, fPuppiContainer, fPuppiDiagnostics, fPuppiNoLep, fUseDZ, fUseExistingWeights, fUseFromPVLooseTight, fUsePUProxyValue, fUseVertexAssociation, fVtxNdofCut, fVtxZCut, edm::ParameterSet::getParameter(), iConfig, ptokenAlphas_, ptokenAlphasMed_, ptokenAlphasRms_, ptokenNalgos_, ptokenP4PupOut_, ptokenPackedPuppiCandidates_, ptokenPupOut_, ptokenPuppiCandidates_, ptokenRawAlphas_, ptokenValues_, puProxyValueToken_, tokenPFCandidates_, tokenVertexAssociation_, tokenVertexAssociationQuality_, tokenVertices_, parallelization::uint(), and vertexAssociationQuality_.

93  {
94  fPuppiDiagnostics = iConfig.getParameter<bool>("puppiDiagnostics");
95  fPuppiNoLep = iConfig.getParameter<bool>("puppiNoLep");
96  fUseFromPVLooseTight = iConfig.getParameter<bool>("UseFromPVLooseTight");
97  fUseDZ = iConfig.getParameter<bool>("UseDeltaZCut");
98  fDZCut = iConfig.getParameter<double>("DeltaZCut");
99  fEtaMinUseDZ = iConfig.getParameter<double>("EtaMinUseDeltaZ");
100  fPtMaxCharged = iConfig.getParameter<double>("PtMaxCharged");
101  fEtaMaxCharged = iConfig.getParameter<double>("EtaMaxCharged");
102  fPtMaxPhotons = iConfig.getParameter<double>("PtMaxPhotons");
103  fEtaMaxPhotons = iConfig.getParameter<double>("EtaMaxPhotons");
104  fNumOfPUVtxsForCharged = iConfig.getParameter<uint>("NumOfPUVtxsForCharged");
105  fDZCutForChargedFromPUVtxs = iConfig.getParameter<double>("DeltaZCutForChargedFromPUVtxs");
106  fUseExistingWeights = iConfig.getParameter<bool>("useExistingWeights");
107  fClonePackedCands = iConfig.getParameter<bool>("clonePackedCands");
108  fVtxNdofCut = iConfig.getParameter<int>("vtxNdofCut");
109  fVtxZCut = iConfig.getParameter<double>("vtxZCut");
110  fPuppiContainer = std::make_unique<PuppiContainer>(iConfig);
111 
112  tokenPFCandidates_ = consumes<CandidateView>(iConfig.getParameter<edm::InputTag>("candName"));
113  tokenVertices_ = consumes<VertexCollection>(iConfig.getParameter<edm::InputTag>("vertexName"));
114  fUseVertexAssociation = iConfig.getParameter<bool>("useVertexAssociation");
115  vertexAssociationQuality_ = iConfig.getParameter<int>("vertexAssociationQuality");
116  if (fUseVertexAssociation) {
117  tokenVertexAssociation_ = consumes<CandToVertex>(iConfig.getParameter<edm::InputTag>("vertexAssociation"));
119  consumes<edm::ValueMap<int>>(iConfig.getParameter<edm::InputTag>("vertexAssociation"));
120  }
121 
122  fUsePUProxyValue = iConfig.getParameter<bool>("usePUProxyValue");
123 
124  if (fUsePUProxyValue) {
125  puProxyValueToken_ = consumes<double>(iConfig.getParameter<edm::InputTag>("PUProxyValue"));
126  }
127 
128  ptokenPupOut_ = produces<edm::ValueMap<float>>();
129  ptokenP4PupOut_ = produces<edm::ValueMap<LorentzVector>>();
130  ptokenValues_ = produces<edm::ValueMap<reco::CandidatePtr>>();
131 
133  ptokenPackedPuppiCandidates_ = produces<pat::PackedCandidateCollection>();
134  else {
135  ptokenPuppiCandidates_ = produces<reco::PFCandidateCollection>();
136  }
137 
138  if (fPuppiDiagnostics) {
139  ptokenNalgos_ = produces<double>("PuppiNAlgos");
140  ptokenRawAlphas_ = produces<std::vector<double>>("PuppiRawAlphas");
141  ptokenAlphas_ = produces<std::vector<double>>("PuppiAlphas");
142  ptokenAlphasMed_ = produces<std::vector<double>>("PuppiAlphasMed");
143  ptokenAlphasRms_ = produces<std::vector<double>>("PuppiAlphasRms");
144  }
145 }
bool fUseFromPVLooseTight
edm::EDPutTokenT< pat::PackedCandidateCollection > ptokenPackedPuppiCandidates_
edm::EDPutTokenT< std::vector< double > > ptokenAlphasMed_
double fDZCutForChargedFromPUVtxs
bool fPuppiDiagnostics
bool fUseVertexAssociation
edm::EDGetTokenT< CandToVertex > tokenVertexAssociation_
edm::EDPutTokenT< reco::PFCandidateCollection > ptokenPuppiCandidates_
edm::EDPutTokenT< double > ptokenNalgos_
double fEtaMaxCharged
std::unique_ptr< PuppiContainer > fPuppiContainer
edm::EDPutTokenT< edm::ValueMap< reco::CandidatePtr > > ptokenValues_
int vertexAssociationQuality_
edm::EDGetTokenT< double > puProxyValueToken_
edm::EDGetTokenT< edm::ValueMap< int > > tokenVertexAssociationQuality_
bool fClonePackedCands
edm::EDGetTokenT< VertexCollection > tokenVertices_
edm::EDPutTokenT< edm::ValueMap< float > > ptokenPupOut_
edm::EDPutTokenT< std::vector< double > > ptokenAlphas_
edm::EDPutTokenT< std::vector< double > > ptokenRawAlphas_
edm::EDGetTokenT< CandidateView > tokenPFCandidates_
double fPtMaxPhotons
double fPtMaxCharged
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
uint fNumOfPUVtxsForCharged
edm::EDPutTokenT< edm::ValueMap< LorentzVector > > ptokenP4PupOut_
bool fUseExistingWeights
edm::EDPutTokenT< std::vector< double > > ptokenAlphasRms_
double fEtaMaxPhotons
double fEtaMinUseDZ
PuppiProducer::~PuppiProducer ( )
override

Definition at line 147 of file PuppiProducer.cc.

147 {}

Member Function Documentation

void PuppiProducer::beginJob ( void  )
privatevirtual

Definition at line 482 of file PuppiProducer.cc.

482 {}
void PuppiProducer::endJob ( void  )
privatevirtual

Definition at line 484 of file PuppiProducer.cc.

Referenced by o2olib.O2ORunMgr::executeJob().

484 {}
void PuppiProducer::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 486 of file PuppiProducer.cc.

References edm::ConfigurationDescriptions::add(), edm::ParameterSetDescription::add(), submitPVResolutionJobs::desc, PuppiAlgo::fillDescriptionsPuppiAlgo(), HLT_FULL_cff::InputTag, and parallelization::uint().

486  {
488  desc.add<bool>("puppiDiagnostics", false);
489  desc.add<bool>("puppiNoLep", false);
490  desc.add<bool>("UseFromPVLooseTight", false);
491  desc.add<bool>("UseDeltaZCut", true);
492  desc.add<double>("DeltaZCut", 0.3);
493  desc.add<double>("EtaMinUseDeltaZ", 0.);
494  desc.add<double>("PtMaxCharged", -1.);
495  desc.add<double>("EtaMaxCharged", 99999.);
496  desc.add<double>("PtMaxPhotons", -1.);
497  desc.add<double>("EtaMaxPhotons", 2.5);
498  desc.add<double>("PtMaxNeutrals", 200.);
499  desc.add<double>("PtMaxNeutralsStartSlope", 0.);
500  desc.add<uint>("NumOfPUVtxsForCharged", 0);
501  desc.add<double>("DeltaZCutForChargedFromPUVtxs", 0.2);
502  desc.add<bool>("useExistingWeights", false);
503  desc.add<bool>("clonePackedCands", false);
504  desc.add<int>("vtxNdofCut", 4);
505  desc.add<double>("vtxZCut", 24);
506  desc.add<edm::InputTag>("candName", edm::InputTag("particleFlow"));
507  desc.add<edm::InputTag>("vertexName", edm::InputTag("offlinePrimaryVertices"));
508  desc.add<bool>("useVertexAssociation", false);
509  desc.add<int>("vertexAssociationQuality", 0);
510  desc.add<edm::InputTag>("vertexAssociation", edm::InputTag(""));
511  desc.add<bool>("applyCHS", true);
512  desc.add<bool>("invertPuppi", false);
513  desc.add<bool>("useExp", false);
514  desc.add<double>("MinPuppiWeight", .01);
515  desc.add<bool>("usePUProxyValue", false);
516  desc.add<edm::InputTag>("PUProxyValue", edm::InputTag(""));
517 
519 
520  descriptions.add("PuppiProducer", desc);
521 }
static void fillDescriptionsPuppiAlgo(edm::ParameterSetDescription &desc)
Definition: PuppiAlgo.cc:218
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void PuppiProducer::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
overrideprivate

Definition at line 149 of file PuppiProducer.cc.

References funct::abs(), RecoObj::charge, RecoObj::d0, pat::PackedCandidate::dxy(), RecoObj::dZ, pat::PackedCandidate::dz(), edm::Event::emplace(), RecoObj::eta, pat::PackedCandidate::eta(), Exception, fClonePackedCands, fDZCut, fDZCutForChargedFromPUVtxs, fEtaMaxCharged, fEtaMaxPhotons, fEtaMinUseDZ, edm::helper::Filler< Map >::fill(), fNumOfPUVtxsForCharged, fPtMaxCharged, fPtMaxPhotons, fPuppiContainer, fPuppiDiagnostics, fPuppiNoLep, fRecoObjCollection, pat::PackedCandidate::fromPV(), fUseDZ, fUseExistingWeights, fUseFromPVLooseTight, fUsePUProxyValue, fUseVertexAssociation, fVtxNdofCut, fVtxZCut, edm::Event::get(), edm::Ref< C, T, F >::get(), edm::Event::getByToken(), reco::PFCandidate::gsfTrackRef(), gpuClustering::id, RecoObj::id, if(), edm::helper::Filler< Map >::insert(), reco::isLepton(), edm::Ref< C, T, F >::isNonnull(), edm::Ref< C, T, F >::key(), edm::errors::LogicError, RecoObj::m, RecoObj::pdgId, pat::PackedCandidate::pdgId(), RecoObj::phi, edm::Handle< T >::product(), RecoObj::pt, pat::PackedCandidate::pt(), ptokenAlphas_, ptokenAlphasMed_, ptokenAlphasRms_, ptokenNalgos_, ptokenP4PupOut_, ptokenPackedPuppiCandidates_, ptokenPupOut_, ptokenPuppiCandidates_, ptokenRawAlphas_, ptokenValues_, pat::PackedCandidate::puppiWeight(), pat::PackedCandidate::puppiWeightNoLep(), puProxyValueToken_, pat::PackedCandidate::PVLoose, pat::PackedCandidate::PVTight, pat::PackedCandidate::PVUsedInFit, quality, RecoObj::rapidity, edm::View< T >::size(), tokenPFCandidates_, tokenVertexAssociation_, tokenVertexAssociationQuality_, tokenVertices_, reco::PFCandidate::trackRef(), reco::PFCandidate::translatePdgIdToType(), parallelization::uint(), makeHLTPrescaleTable::values, vertexAssociationQuality_, and pat::PackedCandidate::vertexRef().

149  {
150  // Get PFCandidate Collection
151  edm::Handle<CandidateView> hPFProduct;
152  iEvent.getByToken(tokenPFCandidates_, hPFProduct);
153  const CandidateView* pfCol = hPFProduct.product();
154 
155  // Get vertex collection w/PV as the first entry?
157  iEvent.getByToken(tokenVertices_, hVertexProduct);
158  const reco::VertexCollection* pvCol = hVertexProduct.product();
159 
161  edm::ValueMap<int> associationQuality;
163  associatedPV = iEvent.get(tokenVertexAssociation_);
164  associationQuality = iEvent.get(tokenVertexAssociationQuality_);
165  }
166 
167  double puProxyValue = 0.;
168  if (fUsePUProxyValue) {
169  puProxyValue = iEvent.get(puProxyValueToken_);
170  } else {
171  for (auto const& vtx : *pvCol) {
172  if (!vtx.isFake() && vtx.ndof() >= fVtxNdofCut && std::abs(vtx.z()) <= fVtxZCut)
173  ++puProxyValue;
174  }
175  }
176 
177  std::vector<double> lWeights;
178  if (!fUseExistingWeights) {
179  //Fill the reco objects
180  fRecoObjCollection.clear();
181  fRecoObjCollection.reserve(pfCol->size());
182  int iCand = 0;
183  for (auto const& aPF : *pfCol) {
184  RecoObj pReco;
185  pReco.pt = aPF.pt();
186  pReco.eta = aPF.eta();
187  pReco.phi = aPF.phi();
188  pReco.m = aPF.mass();
189  pReco.rapidity = aPF.rapidity();
190  pReco.charge = aPF.charge();
191  pReco.pdgId = aPF.pdgId();
192  const reco::Vertex* closestVtx = nullptr;
193  double pDZ = -9999;
194  double pD0 = -9999;
195  uint pVtxId = 0;
196  bool isLepton = ((std::abs(pReco.pdgId) == 11) || (std::abs(pReco.pdgId) == 13));
197  const pat::PackedCandidate* lPack = dynamic_cast<const pat::PackedCandidate*>(&aPF);
198 
199  if (fUseVertexAssociation) {
200  const reco::VertexRef& PVOrig = associatedPV[reco::CandidatePtr(hPFProduct, iCand)];
201  int quality = associationQuality[reco::CandidatePtr(hPFProduct, iCand)];
202  if (PVOrig.isNonnull() && (quality >= vertexAssociationQuality_)) {
203  closestVtx = PVOrig.get();
204  pVtxId = PVOrig.key();
205  }
206  if (std::abs(pReco.charge) == 0)
207  pReco.id = 0;
208  else if (fPuppiNoLep && isLepton)
209  pReco.id = 3;
210  else if (closestVtx != nullptr && pVtxId == 0)
211  pReco.id = 1; // Associated to main vertex
212  else if (closestVtx != nullptr && pVtxId > 0)
213  pReco.id = 2; // Associated to PU
214  else
215  pReco.id = 0; // Unassociated
216  } else if (lPack == nullptr) {
217  const reco::PFCandidate* pPF = dynamic_cast<const reco::PFCandidate*>(&aPF);
218  double curdz = 9999;
219  int closestVtxForUnassociateds = -9999;
220  const reco::TrackRef aTrackRef = pPF->trackRef();
221  bool lFirst = true;
222  for (auto const& aV : *pvCol) {
223  if (lFirst) {
224  if (aTrackRef.isNonnull()) {
225  pDZ = aTrackRef->dz(aV.position());
226  pD0 = aTrackRef->d0();
227  } else if (pPF->gsfTrackRef().isNonnull()) {
228  pDZ = pPF->gsfTrackRef()->dz(aV.position());
229  pD0 = pPF->gsfTrackRef()->d0();
230  }
231  lFirst = false;
232  if (pDZ > -9999)
233  pVtxId = 0;
234  }
235  if (aTrackRef.isNonnull() && aV.trackWeight(pPF->trackRef()) > 0) {
236  closestVtx = &aV;
237  break;
238  }
239  // in case it's unassocciated, keep more info
240  double tmpdz = 99999;
241  if (aTrackRef.isNonnull())
242  tmpdz = aTrackRef->dz(aV.position());
243  else if (pPF->gsfTrackRef().isNonnull())
244  tmpdz = pPF->gsfTrackRef()->dz(aV.position());
245  if (std::abs(tmpdz) < curdz) {
246  curdz = std::abs(tmpdz);
247  closestVtxForUnassociateds = pVtxId;
248  }
249  pVtxId++;
250  }
251  int tmpFromPV = 0;
252  // mocking the miniAOD definitions
253  if (std::abs(pReco.charge) > 0) {
254  if (closestVtx != nullptr && pVtxId > 0)
255  tmpFromPV = 0;
256  if (closestVtx != nullptr && pVtxId == 0)
257  tmpFromPV = 3;
258  if (closestVtx == nullptr && closestVtxForUnassociateds == 0)
259  tmpFromPV = 2;
260  if (closestVtx == nullptr && closestVtxForUnassociateds != 0)
261  tmpFromPV = 1;
262  }
263  pReco.dZ = pDZ;
264  pReco.d0 = pD0;
265  pReco.id = 0;
266  if (std::abs(pReco.charge) == 0) {
267  pReco.id = 0;
268  } else {
269  if (fPuppiNoLep && isLepton)
270  pReco.id = 3;
271  else if (tmpFromPV == 0) {
272  pReco.id = 2;
273  if (fNumOfPUVtxsForCharged > 0 and (pVtxId <= fNumOfPUVtxsForCharged) and
275  pReco.id = 1;
276  } else if (tmpFromPV == 3)
277  pReco.id = 1;
278  else if (tmpFromPV == 1 || tmpFromPV == 2) {
279  pReco.id = 0;
280  if ((fPtMaxCharged > 0) and (pReco.pt > fPtMaxCharged))
281  pReco.id = 1;
282  else if (std::abs(pReco.eta) > fEtaMaxCharged)
283  pReco.id = 1;
284  else if ((fUseDZ) && (std::abs(pReco.eta) >= fEtaMinUseDZ))
285  pReco.id = (std::abs(pDZ) < fDZCut) ? 1 : 2;
286  else if (fUseFromPVLooseTight && tmpFromPV == 1)
287  pReco.id = 2;
288  else if (fUseFromPVLooseTight && tmpFromPV == 2)
289  pReco.id = 1;
290  }
291  }
292  } else if (lPack->vertexRef().isNonnull()) {
293  pDZ = lPack->dz();
294  pD0 = lPack->dxy();
295  pReco.dZ = pDZ;
296  pReco.d0 = pD0;
297 
298  pReco.id = 0;
299  if (std::abs(pReco.charge) == 0) {
300  pReco.id = 0;
301  }
302  if (std::abs(pReco.charge) > 0) {
303  if (fPuppiNoLep && isLepton) {
304  pReco.id = 3;
305  } else if (lPack->fromPV() == 0) {
306  pReco.id = 2;
308  for (size_t puVtx_idx = 1; puVtx_idx <= fNumOfPUVtxsForCharged && puVtx_idx < pvCol->size();
309  ++puVtx_idx) {
310  if (lPack->fromPV(puVtx_idx) >= 2) {
311  pReco.id = 1;
312  break;
313  }
314  }
315  }
316  } else if (lPack->fromPV() == (pat::PackedCandidate::PVUsedInFit)) {
317  pReco.id = 1;
318  } else if (lPack->fromPV() == (pat::PackedCandidate::PVTight) ||
319  lPack->fromPV() == (pat::PackedCandidate::PVLoose)) {
320  pReco.id = 0;
321  if ((fPtMaxCharged > 0) and (pReco.pt > fPtMaxCharged))
322  pReco.id = 1;
323  else if (std::abs(pReco.eta) > fEtaMaxCharged)
324  pReco.id = 1;
325  else if ((fUseDZ) && (std::abs(pReco.eta) >= fEtaMinUseDZ))
326  pReco.id = (std::abs(pDZ) < fDZCut) ? 1 : 2;
328  pReco.id = 2;
330  pReco.id = 1;
331  }
332  }
333  }
334 
335  fRecoObjCollection.push_back(pReco);
336  iCand++;
337  }
338 
339  fPuppiContainer->initialize(fRecoObjCollection);
340  fPuppiContainer->setPUProxy(puProxyValue);
341 
342  //Compute the weights and get the particles
343  lWeights = fPuppiContainer->puppiWeights();
344  } else {
345  //Use the existing weights
346  int lPackCtr = 0;
347  for (auto const& aPF : *pfCol) {
348  const pat::PackedCandidate* lPack = dynamic_cast<const pat::PackedCandidate*>(&aPF);
349  float curpupweight = -1.;
350  if (lPack == nullptr) {
351  // throw error
353  "PuppiProducer: cannot get weights since inputs are not PackedCandidates");
354  } else {
355  if (fPuppiNoLep) {
356  curpupweight = lPack->puppiWeightNoLep();
357  } else {
358  curpupweight = lPack->puppiWeight();
359  }
360  }
361  // Protect high pT photons (important for gamma to hadronic recoil balance)
362  if ((fPtMaxPhotons > 0) && (lPack->pdgId() == 22) && (std::abs(lPack->eta()) < fEtaMaxPhotons) &&
363  (lPack->pt() > fPtMaxPhotons))
364  curpupweight = 1;
365  lWeights.push_back(curpupweight);
366  lPackCtr++;
367  }
368  }
369 
370  //Fill it into the event
371  edm::ValueMap<float> lPupOut;
372  edm::ValueMap<float>::Filler lPupFiller(lPupOut);
373  lPupFiller.insert(hPFProduct, lWeights.begin(), lWeights.end());
374  lPupFiller.fill();
375 
376  // This is a dummy to access the "translate" method which is a
377  // non-static member function even though it doesn't need to be.
378  // Will fix in the future.
379  static const reco::PFCandidate dummySinceTranslateIsNotStatic;
380 
381  // Fill a new PF/Packed Candidate Collection and write out the ValueMap of the new p4s.
382  // Since the size of the ValueMap must be equal to the input collection, we need
383  // to search the "puppi" particles to find a match for each input. If none is found,
384  // the input is set to have a four-vector of 0,0,0,0
385  PFOutputCollection fPuppiCandidates;
386  PackedOutputCollection fPackedPuppiCandidates;
387 
389  LorentzVectorCollection puppiP4s;
390  std::vector<reco::CandidatePtr> values(hPFProduct->size());
391 
392  int iCand = -1;
393  for (auto const& aCand : *hPFProduct) {
394  ++iCand;
395  std::unique_ptr<pat::PackedCandidate> pCand;
396  std::unique_ptr<reco::PFCandidate> pfCand;
397 
399  const pat::PackedCandidate* cand = dynamic_cast<const pat::PackedCandidate*>(&aCand);
400  if (!cand)
401  throw edm::Exception(edm::errors::LogicError, "PuppiProducer: inputs are not PackedCandidates");
402  pCand = std::make_unique<pat::PackedCandidate>(*cand);
403  } else {
404  auto id = dummySinceTranslateIsNotStatic.translatePdgIdToType(aCand.pdgId());
405  const reco::PFCandidate* cand = dynamic_cast<const reco::PFCandidate*>(&aCand);
406  pfCand = std::make_unique<reco::PFCandidate>(cand ? *cand : reco::PFCandidate(aCand.charge(), aCand.p4(), id));
407  }
408 
409  // Here, we are using new weights computed and putting them in the packed candidates.
411  if (fPuppiNoLep)
412  pCand->setPuppiWeight(pCand->puppiWeight(), lWeights[iCand]);
413  else
414  pCand->setPuppiWeight(lWeights[iCand], pCand->puppiWeightNoLep());
415  }
416 
417  puppiP4s.emplace_back(lWeights[iCand] * aCand.px(),
418  lWeights[iCand] * aCand.py(),
419  lWeights[iCand] * aCand.pz(),
420  lWeights[iCand] * aCand.energy());
421 
422  // Here, we are using existing weights, or we're using packed candidates.
423  // That is, whether or not we recomputed the weights, we store the
424  // source candidate appropriately, and set the p4 of the packed candidate.
426  pCand->setP4(puppiP4s.back());
427  pCand->setSourceCandidatePtr(aCand.sourceCandidatePtr(0));
428  fPackedPuppiCandidates.push_back(*pCand);
429  } else {
430  pfCand->setP4(puppiP4s.back());
431  pfCand->setSourceCandidatePtr(aCand.sourceCandidatePtr(0));
432  fPuppiCandidates.push_back(*pfCand);
433  }
434  }
435 
436  //Compute the modified p4s
437  edm::ValueMap<LorentzVector>::Filler p4PupFiller(p4PupOut);
438  p4PupFiller.insert(hPFProduct, puppiP4s.begin(), puppiP4s.end());
439  p4PupFiller.fill();
440 
441  iEvent.emplace(ptokenPupOut_, lPupOut);
442  iEvent.emplace(ptokenP4PupOut_, p4PupOut);
445  iEvent.emplace(ptokenPackedPuppiCandidates_, fPackedPuppiCandidates);
446  for (unsigned int ic = 0, nc = oh->size(); ic < nc; ++ic) {
447  reco::CandidatePtr pkref(oh, ic);
448  values[ic] = pkref;
449  }
450  } else {
452  for (unsigned int ic = 0, nc = oh->size(); ic < nc; ++ic) {
453  reco::CandidatePtr pkref(oh, ic);
454  values[ic] = pkref;
455  }
456  }
459  filler.insert(hPFProduct, values.begin(), values.end());
460  filler.fill();
461  iEvent.emplace(ptokenValues_, pfMap_p);
462 
465  // all the different alphas per particle
466  // THE alpha per particle
467  std::vector<double> theAlphas(fPuppiContainer->puppiAlphas());
468  std::vector<double> theAlphasMed(fPuppiContainer->puppiAlphasMed());
469  std::vector<double> theAlphasRms(fPuppiContainer->puppiAlphasRMS());
470  std::vector<double> alphas(fPuppiContainer->puppiRawAlphas());
471  double nalgos(fPuppiContainer->puppiNAlgos());
472 
473  iEvent.emplace(ptokenRawAlphas_, alphas);
474  iEvent.emplace(ptokenNalgos_, nalgos);
475  iEvent.emplace(ptokenAlphas_, theAlphas);
476  iEvent.emplace(ptokenAlphasMed_, theAlphasMed);
477  iEvent.emplace(ptokenAlphasRms_, theAlphasRms);
478  }
479 }
float puppiWeight() const
virtual float dz(size_t ipv=0) const
dz with respect to the PV[ipv]
bool fUseFromPVLooseTight
edm::EDPutTokenT< pat::PackedCandidateCollection > ptokenPackedPuppiCandidates_
edm::EDPutTokenT< std::vector< double > > ptokenAlphasMed_
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
float puppiWeightNoLep() const
Weight from full PUPPI.
uint16_t *__restrict__ id
float d0
Definition: RecoObj.h:37
double fDZCutForChargedFromPUVtxs
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
uint32_t const *__restrict__ Quality * quality
Definition: RecoObj.h:4
bool fPuppiDiagnostics
bool fUseVertexAssociation
std::vector< RecoObj > fRecoObjCollection
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
bool isLepton(const Candidate &part)
Definition: pdgIdUtils.h:13
edm::EDGetTokenT< CandToVertex > tokenVertexAssociation_
key_type key() const
Accessor for product key.
Definition: Ref.h:250
edm::EDPutTokenT< reco::PFCandidateCollection > ptokenPuppiCandidates_
edm::EDPutTokenT< double > ptokenNalgos_
int pdgId() const override
PDG identifier.
const reco::VertexRef vertexRef() const
double fEtaMaxCharged
std::unique_ptr< PuppiContainer > fPuppiContainer
int charge
Definition: RecoObj.h:38
float dZ
Definition: RecoObj.h:36
edm::EDPutTokenT< edm::ValueMap< reco::CandidatePtr > > ptokenValues_
reco::TrackRef trackRef() const
Definition: PFCandidate.cc:430
float rapidity
Definition: RecoObj.h:26
int vertexAssociationQuality_
edm::EDGetTokenT< double > puProxyValueToken_
float pt
Definition: RecoObj.h:26
double eta() const override
momentum pseudorapidity
int id
Definition: RecoObj.h:27
float phi
Definition: RecoObj.h:26
std::vector< reco::PFCandidate > PFOutputCollection
const PVAssoc fromPV(size_t ipv=0) const
if(conf_.getParameter< bool >("UseStripCablingDB"))
edm::EDGetTokenT< edm::ValueMap< int > > tokenVertexAssociationQuality_
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
bool fClonePackedCands
bool get(ProductID const &oid, Handle< PROD > &result) const
Definition: Event.h:346
edm::View< reco::Candidate > CandidateView
std::vector< pat::PackedCandidate > PackedOutputCollection
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:232
edm::EDGetTokenT< VertexCollection > tokenVertices_
edm::EDPutTokenT< edm::ValueMap< float > > ptokenPupOut_
std::vector< LorentzVector > LorentzVectorCollection
edm::EDPutTokenT< std::vector< double > > ptokenAlphas_
edm::EDPutTokenT< std::vector< double > > ptokenRawAlphas_
edm::EDGetTokenT< CandidateView > tokenPFCandidates_
edm::Ptr< Candidate > CandidatePtr
persistent reference to an object in a collection of Candidate objects
Definition: CandidateFwd.h:25
float m
Definition: RecoObj.h:26
double pt() const override
transverse momentum
T const * product() const
Definition: Handle.h:70
OrphanHandle< PROD > emplace(EDPutTokenT< PROD > token, Args &&...args)
puts a new product
Definition: Event.h:433
double fPtMaxPhotons
double fPtMaxCharged
int pdgId
Definition: RecoObj.h:28
ParticleType translatePdgIdToType(int pdgid) const
Definition: PFCandidate.cc:231
float eta
Definition: RecoObj.h:26
uint fNumOfPUVtxsForCharged
edm::EDPutTokenT< edm::ValueMap< LorentzVector > > ptokenP4PupOut_
bool fUseExistingWeights
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:41
reco::GsfTrackRef gsfTrackRef() const
Definition: PFCandidate.cc:462
edm::EDPutTokenT< std::vector< double > > ptokenAlphasRms_
double fEtaMaxPhotons
virtual float dxy() const
dxy with respect to the PV ref
double fEtaMinUseDZ

Member Data Documentation

bool PuppiProducer::fClonePackedCands
private

Definition at line 84 of file PuppiProducer.cc.

Referenced by produce(), and PuppiProducer().

double PuppiProducer::fDZCut
private

Definition at line 75 of file PuppiProducer.cc.

Referenced by produce(), and PuppiProducer().

double PuppiProducer::fDZCutForChargedFromPUVtxs
private

Definition at line 82 of file PuppiProducer.cc.

Referenced by produce(), and PuppiProducer().

double PuppiProducer::fEtaMaxCharged
private

Definition at line 78 of file PuppiProducer.cc.

Referenced by produce(), and PuppiProducer().

double PuppiProducer::fEtaMaxPhotons
private

Definition at line 80 of file PuppiProducer.cc.

Referenced by produce(), and PuppiProducer().

double PuppiProducer::fEtaMinUseDZ
private

Definition at line 76 of file PuppiProducer.cc.

Referenced by produce(), and PuppiProducer().

uint PuppiProducer::fNumOfPUVtxsForCharged
private

Definition at line 81 of file PuppiProducer.cc.

Referenced by produce(), and PuppiProducer().

std::string PuppiProducer::fPFName
private

Definition at line 67 of file PuppiProducer.cc.

double PuppiProducer::fPtMaxCharged
private

Definition at line 77 of file PuppiProducer.cc.

Referenced by produce(), and PuppiProducer().

double PuppiProducer::fPtMaxPhotons
private

Definition at line 79 of file PuppiProducer.cc.

Referenced by produce(), and PuppiProducer().

std::unique_ptr<PuppiContainer> PuppiProducer::fPuppiContainer
private

Definition at line 88 of file PuppiProducer.cc.

Referenced by produce(), and PuppiProducer().

bool PuppiProducer::fPuppiDiagnostics
private

Definition at line 71 of file PuppiProducer.cc.

Referenced by produce(), and PuppiProducer().

std::string PuppiProducer::fPuppiName
private

Definition at line 66 of file PuppiProducer.cc.

bool PuppiProducer::fPuppiNoLep
private

Definition at line 72 of file PuppiProducer.cc.

Referenced by produce(), and PuppiProducer().

std::string PuppiProducer::fPVName
private

Definition at line 68 of file PuppiProducer.cc.

std::vector<RecoObj> PuppiProducer::fRecoObjCollection
private

Definition at line 89 of file PuppiProducer.cc.

Referenced by produce().

bool PuppiProducer::fUseDZ
private

Definition at line 74 of file PuppiProducer.cc.

Referenced by produce(), and PuppiProducer().

bool PuppiProducer::fUseExistingWeights
private

Definition at line 83 of file PuppiProducer.cc.

Referenced by produce(), and PuppiProducer().

bool PuppiProducer::fUseFromPVLooseTight
private

Definition at line 73 of file PuppiProducer.cc.

Referenced by produce(), and PuppiProducer().

bool PuppiProducer::fUsePUProxyValue
private

Definition at line 87 of file PuppiProducer.cc.

Referenced by produce(), and PuppiProducer().

bool PuppiProducer::fUseVertexAssociation
private

Definition at line 69 of file PuppiProducer.cc.

Referenced by produce(), and PuppiProducer().

int PuppiProducer::fVtxNdofCut
private

Definition at line 85 of file PuppiProducer.cc.

Referenced by produce(), and PuppiProducer().

double PuppiProducer::fVtxZCut
private

Definition at line 86 of file PuppiProducer.cc.

Referenced by produce(), and PuppiProducer().

edm::EDPutTokenT<std::vector<double> > PuppiProducer::ptokenAlphas_
private

Definition at line 63 of file PuppiProducer.cc.

Referenced by produce(), and PuppiProducer().

edm::EDPutTokenT<std::vector<double> > PuppiProducer::ptokenAlphasMed_
private

Definition at line 64 of file PuppiProducer.cc.

Referenced by produce(), and PuppiProducer().

edm::EDPutTokenT<std::vector<double> > PuppiProducer::ptokenAlphasRms_
private

Definition at line 65 of file PuppiProducer.cc.

Referenced by produce(), and PuppiProducer().

edm::EDPutTokenT<double> PuppiProducer::ptokenNalgos_
private

Definition at line 61 of file PuppiProducer.cc.

Referenced by produce(), and PuppiProducer().

edm::EDPutTokenT<edm::ValueMap<LorentzVector> > PuppiProducer::ptokenP4PupOut_
private

Definition at line 57 of file PuppiProducer.cc.

Referenced by produce(), and PuppiProducer().

edm::EDPutTokenT<pat::PackedCandidateCollection> PuppiProducer::ptokenPackedPuppiCandidates_
private

Definition at line 59 of file PuppiProducer.cc.

Referenced by produce(), and PuppiProducer().

edm::EDPutTokenT<edm::ValueMap<float> > PuppiProducer::ptokenPupOut_
private

Definition at line 56 of file PuppiProducer.cc.

Referenced by produce(), and PuppiProducer().

edm::EDPutTokenT<reco::PFCandidateCollection> PuppiProducer::ptokenPuppiCandidates_
private

Definition at line 60 of file PuppiProducer.cc.

Referenced by produce(), and PuppiProducer().

edm::EDPutTokenT<std::vector<double> > PuppiProducer::ptokenRawAlphas_
private

Definition at line 62 of file PuppiProducer.cc.

Referenced by produce(), and PuppiProducer().

edm::EDPutTokenT<edm::ValueMap<reco::CandidatePtr> > PuppiProducer::ptokenValues_
private

Definition at line 58 of file PuppiProducer.cc.

Referenced by produce(), and PuppiProducer().

edm::EDGetTokenT<double> PuppiProducer::puProxyValueToken_
private

Definition at line 55 of file PuppiProducer.cc.

Referenced by produce(), and PuppiProducer().

edm::EDGetTokenT<PackedOutputCollection> PuppiProducer::tokenPackedPuppiCandidates_
private

Definition at line 54 of file PuppiProducer.cc.

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

Definition at line 48 of file PuppiProducer.cc.

Referenced by produce(), and PuppiProducer().

edm::EDGetTokenT<PFOutputCollection> PuppiProducer::tokenPuppiCandidates_
private

Definition at line 53 of file PuppiProducer.cc.

edm::EDGetTokenT<PuppiContainer> PuppiProducer::tokenPuppiContainer_
private

Definition at line 52 of file PuppiProducer.cc.

edm::EDGetTokenT<CandToVertex> PuppiProducer::tokenVertexAssociation_
private

Definition at line 50 of file PuppiProducer.cc.

Referenced by produce(), and PuppiProducer().

edm::EDGetTokenT<edm::ValueMap<int> > PuppiProducer::tokenVertexAssociationQuality_
private

Definition at line 51 of file PuppiProducer.cc.

Referenced by produce(), and PuppiProducer().

edm::EDGetTokenT<VertexCollection> PuppiProducer::tokenVertices_
private

Definition at line 49 of file PuppiProducer.cc.

Referenced by produce(), and PuppiProducer().

int PuppiProducer::vertexAssociationQuality_
private

Definition at line 70 of file PuppiProducer.cc.

Referenced by produce(), and PuppiProducer().