CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
PuppiProducer Class Reference

#include <PuppiProducer.h>

Inheritance diagram for PuppiProducer:
edm::stream::EDProducer<> edm::stream::EDProducerBase edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Types

typedef edm::View
< reco::Candidate
CandidateView
 
typedef math::XYZTLorentzVector LorentzVector
 
typedef std::vector
< LorentzVector
LorentzVectorCollection
 
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<>
typedef CacheContexts< T...> CacheTypes
 
typedef CacheTypes::GlobalCache GlobalCache
 
typedef AbilityChecker< T...> HasAbility
 
typedef
CacheTypes::LuminosityBlockCache 
LuminosityBlockCache
 
typedef
LuminosityBlockContextT
< LuminosityBlockCache,
RunCache, GlobalCache
LuminosityBlockContext
 
typedef
CacheTypes::LuminosityBlockSummaryCache 
LuminosityBlockSummaryCache
 
typedef CacheTypes::RunCache RunCache
 
typedef RunContextT< RunCache,
GlobalCache
RunContext
 
typedef CacheTypes::RunSummaryCache RunSummaryCache
 
- Public Types inherited from edm::stream::EDProducerBase
typedef EDProducerAdaptorBase ModuleType
 
- Public Types inherited from edm::ProducerBase
typedef
ProductRegistryHelper::TypeLabelList 
TypeLabelList
 

Public Member Functions

 PuppiProducer (const edm::ParameterSet &)
 
 ~PuppiProducer ()
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
- Public Member Functions inherited from edm::stream::EDProducerBase
 EDProducerBase ()
 
ModuleDescription const & moduleDescription () const
 
virtual ~EDProducerBase ()
 
- Public Member Functions inherited from edm::ProducerBase
 ProducerBase ()
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription
const &)> 
registrationCallback () const
 used by the fwk to register list of products More...
 
virtual ~ProducerBase ()
 
- Public Member Functions inherited from edm::EDConsumerBase
 EDConsumerBase ()
 
ProductHolderIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
std::vector
< ProductHolderIndexAndSkipBit >
const & 
itemsToGetFromEvent () const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesDependentUpon (const std::string &iProcessName, std::vector< const char * > &oModuleLabels) const
 
bool registeredToConsume (ProductHolderIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 
- Static Public Member Functions inherited from edm::stream::EDProducerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 

Private Member Functions

virtual void beginJob ()
 
virtual void beginLuminosityBlock (edm::LuminosityBlock &, edm::EventSetup const &)
 
virtual void beginRun (edm::Run &, edm::EventSetup const &)
 
virtual void endJob ()
 
virtual void endLuminosityBlock (edm::LuminosityBlock &, edm::EventSetup const &)
 
virtual void endRun (edm::Run &, edm::EventSetup const &)
 
virtual void produce (edm::Event &, const edm::EventSetup &)
 

Private Attributes

float fDZCut
 
std::string fPFName
 
std::auto_ptr< PFOutputCollectionfPuppiCandidates
 
std::unique_ptr< PuppiContainerfPuppiContainer
 
std::string fPuppiName
 
std::string fPVName
 
std::vector< RecoObjfRecoObjCollection
 
bool fUseDZ
 
edm::EDGetTokenT< CandidateViewtokenPFCandidates_
 
edm::EDGetTokenT
< VertexCollection
tokenVertices_
 

Additional Inherited Members

- Protected Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

Definition at line 19 of file PuppiProducer.h.

Member Typedef Documentation

Definition at line 29 of file PuppiProducer.h.

Definition at line 26 of file PuppiProducer.h.

Definition at line 27 of file PuppiProducer.h.

Definition at line 30 of file PuppiProducer.h.

Definition at line 31 of file PuppiProducer.h.

Definition at line 32 of file PuppiProducer.h.

Definition at line 28 of file PuppiProducer.h.

Constructor & Destructor Documentation

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

Definition at line 28 of file PuppiProducer.cc.

References fDZCut, fPuppiContainer, fUseDZ, edm::ParameterSet::getParameter(), tokenPFCandidates_, and tokenVertices_.

28  {
29  fUseDZ = iConfig.getParameter<bool>("UseDeltaZCut");
30  fDZCut = iConfig.getParameter<double>("DeltaZCut");
31  fPuppiContainer = std::unique_ptr<PuppiContainer> ( new PuppiContainer(iConfig) );
32 
34  = consumes<CandidateView>(iConfig.getParameter<edm::InputTag>("candName"));
36  = consumes<VertexCollection>(iConfig.getParameter<edm::InputTag>("vertexName"));
37 
38 
39  produces<edm::ValueMap<float> > ("PuppiWeights");
40  produces<edm::ValueMap<LorentzVector> > ("PuppiP4s");
41  produces<PFOutputCollection>();
42 
43 
44 }
T getParameter(std::string const &) const
std::unique_ptr< PuppiContainer > fPuppiContainer
Definition: PuppiProducer.h:51
edm::EDGetTokenT< VertexCollection > tokenVertices_
Definition: PuppiProducer.h:45
edm::EDGetTokenT< CandidateView > tokenPFCandidates_
Definition: PuppiProducer.h:44
PuppiProducer::~PuppiProducer ( )

Definition at line 46 of file PuppiProducer.cc.

46  {
47 }

Member Function Documentation

void PuppiProducer::beginJob ( void  )
privatevirtual

Definition at line 179 of file PuppiProducer.cc.

179  {
180 }
void PuppiProducer::beginLuminosityBlock ( edm::LuminosityBlock ,
edm::EventSetup const &   
)
privatevirtual

Definition at line 191 of file PuppiProducer.cc.

191  {
192 }
void PuppiProducer::beginRun ( edm::Run ,
edm::EventSetup const &   
)
privatevirtual

Definition at line 185 of file PuppiProducer.cc.

185  {
186 }
void PuppiProducer::endJob ( void  )
privatevirtual

Definition at line 182 of file PuppiProducer.cc.

182  {
183 }
void PuppiProducer::endLuminosityBlock ( edm::LuminosityBlock ,
edm::EventSetup const &   
)
privatevirtual

Definition at line 194 of file PuppiProducer.cc.

194  {
195 }
void PuppiProducer::endRun ( edm::Run ,
edm::EventSetup const &   
)
privatevirtual

Definition at line 188 of file PuppiProducer.cc.

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

Definition at line 197 of file PuppiProducer.cc.

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

197  {
198  //The following says we do not know what parameters are allowed so do no validation
199  // Please change this to state exactly what you do use, even if it is no parameters
201  desc.setUnknown();
202  descriptions.addDefault(desc);
203 }
void addDefault(ParameterSetDescription const &psetDescription)
void PuppiProducer::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
privatevirtual

Implements edm::stream::EDProducerBase.

Definition at line 49 of file PuppiProducer.cc.

References edm::View< T >::begin(), RecoObj::charge, RecoObj::d0, pat::PackedCandidate::dxy(), RecoObj::dZ, pat::PackedCandidate::dz(), edm::View< T >::end(), RecoObj::eta, fDZCut, edm::helper::Filler< Map >::fill(), fPuppiCandidates, fPuppiContainer, fRecoObjCollection, pat::PackedCandidate::fromPV(), fUseDZ, edm::Event::getByToken(), reco::PFCandidate::gsfTrackRef(), i, RecoObj::id, edm::helper::Filler< Map >::insert(), edm::Ref< C, T, F >::isNonnull(), RecoObj::m, reco::LeafCandidate::p4(), RecoObj::phi, edm::Handle< T >::product(), RecoObj::pt, edm::Event::put(), pat::PackedCandidate::PVLoose, pat::PackedCandidate::PVTight, pat::PackedCandidate::PVUsedInFit, tokenPFCandidates_, tokenVertices_, reco::PFCandidate::trackRef(), reco::PFCandidate::translatePdgIdToType(), pat::PackedCandidate::vertexRef(), and RecoObj::vtxId.

Referenced by JSONExport.JsonExport::export(), HTMLExport.HTMLExport::export(), and HTMLExport.HTMLExportStatic::export().

49  {
50 
51  // Get PFCandidate Collection
52  edm::Handle<CandidateView> hPFProduct;
53  iEvent.getByToken(tokenPFCandidates_,hPFProduct);
54  const CandidateView *pfCol = hPFProduct.product();
55 
56  // Get vertex collection w/PV as the first entry?
58  iEvent.getByToken(tokenVertices_,hVertexProduct);
59  const reco::VertexCollection *pvCol = hVertexProduct.product();
60 
61  //Fill the reco objects
62  fRecoObjCollection.clear();
63  for(CandidateView::const_iterator itPF = pfCol->begin(); itPF!=pfCol->end(); itPF++) {
64  RecoObj pReco;
65  pReco.pt = itPF->pt();
66  pReco.eta = itPF->eta();
67  pReco.phi = itPF->phi();
68  pReco.m = itPF->mass();
69  pReco.charge = itPF->charge();
70  const reco::Vertex *closestVtx = 0;
71  double pDZ = -9999;
72  double pD0 = -9999;
73  int pVtxId = -9999;
74  bool lFirst = true;
75  const pat::PackedCandidate *lPack = dynamic_cast<const pat::PackedCandidate*>(&(*itPF));
76  if(lPack == 0 ) {
77  const reco::PFCandidate *pPF = dynamic_cast<const reco::PFCandidate*>(&(*itPF));
78  for(reco::VertexCollection::const_iterator iV = pvCol->begin(); iV!=pvCol->end(); ++iV) {
79  if(lFirst) {
80  if ( pPF->trackRef().isNonnull() ) pDZ = pPF->trackRef() ->dz(iV->position());
81  else if ( pPF->gsfTrackRef().isNonnull() ) pDZ = pPF->gsfTrackRef()->dz(iV->position());
82  if ( pPF->trackRef().isNonnull() ) pD0 = pPF->trackRef() ->d0();
83  else if ( pPF->gsfTrackRef().isNonnull() ) pD0 = pPF->gsfTrackRef()->d0();
84  lFirst = false;
85  if(pDZ > -9999) pVtxId = 0;
86  }
87  if(iV->trackWeight(pPF->trackRef())>0) {
88  closestVtx = &(*iV);
89  break;
90  }
91  pVtxId++;
92  }
93  } else if(lPack->vertexRef().isNonnull() ) {
94  pDZ = lPack->dz();
95  pD0 = lPack->dxy();
96  closestVtx = &(*(lPack->vertexRef()));
97  pVtxId = (lPack->fromPV() != (pat::PackedCandidate::PVUsedInFit));
98  if( (lPack->fromPV() == pat::PackedCandidate::PVLoose) ||
99  (lPack->fromPV() == pat::PackedCandidate::PVTight) )
100  closestVtx = 0;
101  }
102  pReco.dZ = pDZ;
103  pReco.d0 = pD0;
104 
105  if(closestVtx == 0) pReco.vtxId = -1;
106  if(closestVtx != 0) pReco.vtxId = pVtxId;
107  //if(closestVtx != 0) pReco.vtxChi2 = closestVtx->trackWeight(itPF->trackRef());
108  //Set the id for Puppi Algo: 0 is neutral pfCandidate, id = 1 for particles coming from PV and id = 2 for charged particles from non-leading vertex
109  pReco.id = 0;
110 
111  if(closestVtx != 0 && pVtxId == 0 && fabs(pReco.charge) > 0) pReco.id = 1;
112  if(closestVtx != 0 && pVtxId > 0 && fabs(pReco.charge) > 0) pReco.id = 2;
113  //Add a dZ cut if wanted (this helps)
114  if(fUseDZ && pDZ > -9999 && closestVtx == 0 && (fabs(pDZ) < fDZCut) && fabs(pReco.charge) > 0) pReco.id = 1;
115  if(fUseDZ && pDZ > -9999 && closestVtx == 0 && (fabs(pDZ) > fDZCut) && fabs(pReco.charge) > 0) pReco.id = 2;
116 
117  //std::cout << "pVtxId = " << pVtxId << ", and charge = " << itPF->charge() << ", and closestVtx = " << closestVtx << ", and id = " << pReco.id << std::endl;
118 
119  fRecoObjCollection.push_back(pReco);
120  }
121  fPuppiContainer->initialize(fRecoObjCollection);
122 
123  //Compute the weights
124  const std::vector<double> lWeights = fPuppiContainer->puppiWeights();
125  //Fill it into the event
126  std::auto_ptr<edm::ValueMap<float> > lPupOut(new edm::ValueMap<float>());
127  edm::ValueMap<float>::Filler lPupFiller(*lPupOut);
128  lPupFiller.insert(hPFProduct,lWeights.begin(),lWeights.end());
129  lPupFiller.fill();
130 
131  // This is a dummy to access the "translate" method which is a
132  // non-static member function even though it doesn't need to be.
133  // Will fix in the future.
134  static const reco::PFCandidate dummySinceTranslateIsNotStatic;
135 
136  //Fill a new PF Candidate Collection and write out the ValueMap of the new p4s.
137  // Since the size of the ValueMap must be equal to the input collection, we need
138  // to search the "puppi" particles to find a match for each input. If none is found,
139  // the input is set to have a four-vector of 0,0,0,0
140  const std::vector<fastjet::PseudoJet> lCandidates = fPuppiContainer->puppiParticles();
142  std::auto_ptr<edm::ValueMap<LorentzVector> > p4PupOut(new edm::ValueMap<LorentzVector>());
143  LorentzVectorCollection puppiP4s;
144  for ( auto i0 = hPFProduct->begin(),
145  i0begin = hPFProduct->begin(),
146  i0end = hPFProduct->end(); i0 != i0end; ++i0 ) {
147  //for(unsigned int i0 = 0; i0 < lCandidates.size(); i0++) {
148  //reco::PFCandidate pCand;
149  auto id = dummySinceTranslateIsNotStatic.translatePdgIdToType(i0->pdgId());
150  reco::PFCandidate pCand( i0->charge(),
151  i0->p4(),
152  id );
153  LorentzVector pVec = i0->p4();
154  int val = i0 - i0begin;
155 
156  // Find the Puppi particle matched to the input collection using the "user_index" of the object.
157  auto puppiMatched = find_if( lCandidates.begin(), lCandidates.end(), [&val]( fastjet::PseudoJet const & i ){ return i.user_index() == val; } );
158  if ( puppiMatched != lCandidates.end() ) {
159  pVec.SetPxPyPzE(puppiMatched->px(),puppiMatched->py(),puppiMatched->pz(),puppiMatched->E());
160  } else {
161  pVec.SetPxPyPzE( 0, 0, 0, 0);
162  }
163  pCand.setP4(pVec);
164  puppiP4s.push_back( pVec );
165  fPuppiCandidates->push_back(pCand);
166  }
167 
168  //Compute the modified p4s
169  edm::ValueMap<LorentzVector>::Filler p4PupFiller(*p4PupOut);
170  p4PupFiller.insert(hPFProduct,puppiP4s.begin(), puppiP4s.end() );
171  p4PupFiller.fill();
172 
173  iEvent.put(lPupOut,"PuppiWeights");
174  iEvent.put(p4PupOut,"PuppiP4s");
175  iEvent.put(fPuppiCandidates);
176 }
int i
Definition: DBlmapReader.cc:9
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:250
float d0
Definition: RecoObj.h:28
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:446
std::vector< reco::PFCandidate > PFOutputCollection
Definition: PuppiProducer.h:31
Definition: RecoObj.h:4
std::vector< RecoObj > fRecoObjCollection
Definition: PuppiProducer.h:52
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
const reco::VertexRef vertexRef() const
std::unique_ptr< PuppiContainer > fPuppiContainer
Definition: PuppiProducer.h:51
int charge
Definition: RecoObj.h:29
edm::EDGetTokenT< VertexCollection > tokenVertices_
Definition: PuppiProducer.h:45
float dZ
Definition: RecoObj.h:27
reco::TrackRef trackRef() const
Definition: PFCandidate.cc:433
float pt
Definition: RecoObj.h:17
const_iterator begin() const
int id
Definition: RecoObj.h:18
float phi
Definition: RecoObj.h:17
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
std::vector< LorentzVector > LorentzVectorCollection
float m
Definition: RecoObj.h:17
T const * product() const
Definition: Handle.h:81
ParticleType translatePdgIdToType(int pdgid) const
Definition: PFCandidate.cc:224
float eta
Definition: RecoObj.h:17
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< float > > LorentzVector
Definition: analysisEnums.h:9
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:39
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81
reco::GsfTrackRef gsfTrackRef() const
Definition: PFCandidate.cc:471
edm::EDGetTokenT< CandidateView > tokenPFCandidates_
Definition: PuppiProducer.h:44
std::auto_ptr< PFOutputCollection > fPuppiCandidates
Definition: PuppiProducer.h:53
const_iterator end() const
virtual float dxy() const
dxy with respect to the PV ref
const PVAssoc fromPV() const
virtual const LorentzVector & p4() const
four-momentum Lorentz vector
int vtxId
Definition: RecoObj.h:20
virtual float dz() const
dz with respect to the PV ref

Member Data Documentation

float PuppiProducer::fDZCut
private

Definition at line 50 of file PuppiProducer.h.

Referenced by produce(), and PuppiProducer().

std::string PuppiProducer::fPFName
private

Definition at line 47 of file PuppiProducer.h.

std::auto_ptr< PFOutputCollection > PuppiProducer::fPuppiCandidates
private

Definition at line 53 of file PuppiProducer.h.

Referenced by produce().

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

Definition at line 51 of file PuppiProducer.h.

Referenced by produce(), and PuppiProducer().

std::string PuppiProducer::fPuppiName
private

Definition at line 46 of file PuppiProducer.h.

std::string PuppiProducer::fPVName
private

Definition at line 48 of file PuppiProducer.h.

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

Definition at line 52 of file PuppiProducer.h.

Referenced by produce().

bool PuppiProducer::fUseDZ
private

Definition at line 49 of file PuppiProducer.h.

Referenced by produce(), and PuppiProducer().

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

Definition at line 44 of file PuppiProducer.h.

Referenced by produce(), and PuppiProducer().

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

Definition at line 45 of file PuppiProducer.h.

Referenced by produce(), and PuppiProducer().