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
std::vector< ConsumesInfoconsumesInfo () const
 
 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
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) 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 31 of file PuppiProducer.cc.

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

31  {
32  fUseDZ = iConfig.getParameter<bool>("UseDeltaZCut");
33  fDZCut = iConfig.getParameter<double>("DeltaZCut");
34  fPuppiContainer = std::unique_ptr<PuppiContainer> ( new PuppiContainer(iConfig) );
35 
37  = consumes<CandidateView>(iConfig.getParameter<edm::InputTag>("candName"));
39  = consumes<VertexCollection>(iConfig.getParameter<edm::InputTag>("vertexName"));
40 
41 
42  produces<edm::ValueMap<float> > ();
43  produces<edm::ValueMap<LorentzVector> > ();
44  produces< edm::ValueMap<reco::CandidatePtr> >();
45 
46  produces<PFOutputCollection>();
47 
48 
49 }
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 51 of file PuppiProducer.cc.

51  {
52 }

Member Function Documentation

void PuppiProducer::beginJob ( void  )
privatevirtual

Definition at line 198 of file PuppiProducer.cc.

198  {
199 }
void PuppiProducer::beginLuminosityBlock ( edm::LuminosityBlock ,
edm::EventSetup const &   
)
privatevirtual

Definition at line 210 of file PuppiProducer.cc.

210  {
211 }
void PuppiProducer::beginRun ( edm::Run ,
edm::EventSetup const &   
)
privatevirtual

Definition at line 204 of file PuppiProducer.cc.

204  {
205 }
void PuppiProducer::endJob ( void  )
privatevirtual

Definition at line 201 of file PuppiProducer.cc.

201  {
202 }
void PuppiProducer::endLuminosityBlock ( edm::LuminosityBlock ,
edm::EventSetup const &   
)
privatevirtual

Definition at line 213 of file PuppiProducer.cc.

213  {
214 }
void PuppiProducer::endRun ( edm::Run ,
edm::EventSetup const &   
)
privatevirtual

Definition at line 207 of file PuppiProducer.cc.

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

Definition at line 216 of file PuppiProducer.cc.

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

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

Implements edm::stream::EDProducerBase.

Definition at line 54 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, RecoObj::phi, edm::Handle< T >::product(), RecoObj::pt, edm::Event::put(), pat::PackedCandidate::PVLoose, pat::PackedCandidate::PVTight, pat::PackedCandidate::PVUsedInFit, reco::LeafCandidate::setP4(), tokenPFCandidates_, tokenVertices_, reco::PFCandidate::trackRef(), reco::PFCandidate::translatePdgIdToType(), makeHLTPrescaleTable::values, pat::PackedCandidate::vertexRef(), and RecoObj::vtxId.

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

54  {
55 
56  // Get PFCandidate Collection
57  edm::Handle<CandidateView> hPFProduct;
58  iEvent.getByToken(tokenPFCandidates_,hPFProduct);
59  const CandidateView *pfCol = hPFProduct.product();
60 
61  // Get vertex collection w/PV as the first entry?
63  iEvent.getByToken(tokenVertices_,hVertexProduct);
64  const reco::VertexCollection *pvCol = hVertexProduct.product();
65 
66  //Fill the reco objects
67  fRecoObjCollection.clear();
68  for(CandidateView::const_iterator itPF = pfCol->begin(); itPF!=pfCol->end(); itPF++) {
69  RecoObj pReco;
70  pReco.pt = itPF->pt();
71  pReco.eta = itPF->eta();
72  pReco.phi = itPF->phi();
73  pReco.m = itPF->mass();
74  pReco.charge = itPF->charge();
75  const reco::Vertex *closestVtx = 0;
76  double pDZ = -9999;
77  double pD0 = -9999;
78  int pVtxId = -9999;
79  bool lFirst = true;
80  const pat::PackedCandidate *lPack = dynamic_cast<const pat::PackedCandidate*>(&(*itPF));
81  if(lPack == 0 ) {
82  const reco::PFCandidate *pPF = dynamic_cast<const reco::PFCandidate*>(&(*itPF));
83  for(reco::VertexCollection::const_iterator iV = pvCol->begin(); iV!=pvCol->end(); ++iV) {
84  if(lFirst) {
85  if ( pPF->trackRef().isNonnull() ) pDZ = pPF->trackRef() ->dz(iV->position());
86  else if ( pPF->gsfTrackRef().isNonnull() ) pDZ = pPF->gsfTrackRef()->dz(iV->position());
87  if ( pPF->trackRef().isNonnull() ) pD0 = pPF->trackRef() ->d0();
88  else if ( pPF->gsfTrackRef().isNonnull() ) pD0 = pPF->gsfTrackRef()->d0();
89  lFirst = false;
90  if(pDZ > -9999) pVtxId = 0;
91  }
92  if(iV->trackWeight(pPF->trackRef())>0) {
93  closestVtx = &(*iV);
94  break;
95  }
96  pVtxId++;
97  }
98  } else if(lPack->vertexRef().isNonnull() ) {
99  pDZ = lPack->dz();
100  pD0 = lPack->dxy();
101  closestVtx = &(*(lPack->vertexRef()));
102  pVtxId = (lPack->fromPV() != (pat::PackedCandidate::PVUsedInFit));
103  if( (lPack->fromPV() == pat::PackedCandidate::PVLoose) ||
104  (lPack->fromPV() == pat::PackedCandidate::PVTight) )
105  closestVtx = 0;
106  }
107  pReco.dZ = pDZ;
108  pReco.d0 = pD0;
109 
110  if(closestVtx == 0) pReco.vtxId = -1;
111  if(closestVtx != 0) pReco.vtxId = pVtxId;
112  //if(closestVtx != 0) pReco.vtxChi2 = closestVtx->trackWeight(itPF->trackRef());
113  //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
114  pReco.id = 0;
115 
116  if(closestVtx != 0 && pVtxId == 0 && fabs(pReco.charge) > 0) pReco.id = 1;
117  if(closestVtx != 0 && pVtxId > 0 && fabs(pReco.charge) > 0) pReco.id = 2;
118  //Add a dZ cut if wanted (this helps)
119  if(fUseDZ && pDZ > -9999 && closestVtx == 0 && (fabs(pDZ) < fDZCut) && fabs(pReco.charge) > 0) pReco.id = 1;
120  if(fUseDZ && pDZ > -9999 && closestVtx == 0 && (fabs(pDZ) > fDZCut) && fabs(pReco.charge) > 0) pReco.id = 2;
121 
122  //std::cout << "pVtxId = " << pVtxId << ", and charge = " << itPF->charge() << ", and closestVtx = " << closestVtx << ", and id = " << pReco.id << std::endl;
123 
124  fRecoObjCollection.push_back(pReco);
125  }
126  fPuppiContainer->initialize(fRecoObjCollection);
127 
128  //Compute the weights
129  const std::vector<double> lWeights = fPuppiContainer->puppiWeights();
130  //Fill it into the event
131  std::auto_ptr<edm::ValueMap<float> > lPupOut(new edm::ValueMap<float>());
132  edm::ValueMap<float>::Filler lPupFiller(*lPupOut);
133  lPupFiller.insert(hPFProduct,lWeights.begin(),lWeights.end());
134  lPupFiller.fill();
135 
136 
137  // This is a dummy to access the "translate" method which is a
138  // non-static member function even though it doesn't need to be.
139  // Will fix in the future.
140  static const reco::PFCandidate dummySinceTranslateIsNotStatic;
141 
142  //Fill a new PF Candidate Collection and write out the ValueMap of the new p4s.
143  // Since the size of the ValueMap must be equal to the input collection, we need
144  // to search the "puppi" particles to find a match for each input. If none is found,
145  // the input is set to have a four-vector of 0,0,0,0
146  const std::vector<fastjet::PseudoJet> lCandidates = fPuppiContainer->puppiParticles();
148  std::auto_ptr<edm::ValueMap<LorentzVector> > p4PupOut(new edm::ValueMap<LorentzVector>());
149  LorentzVectorCollection puppiP4s;
150  std::vector<reco::CandidatePtr> values(hPFProduct->size());
151  //std::vector<int> values(hPFProduct->size());
152 
153  for ( auto i0 = hPFProduct->begin(),
154  i0begin = hPFProduct->begin(),
155  i0end = hPFProduct->end(); i0 != i0end; ++i0 ) {
156  //for(unsigned int i0 = 0; i0 < lCandidates.size(); i0++) {
157  //reco::PFCandidate pCand;
158  auto id = dummySinceTranslateIsNotStatic.translatePdgIdToType(i0->pdgId());
159  const reco::PFCandidate *pPF = dynamic_cast<const reco::PFCandidate*>(&(*i0));
160  reco::PFCandidate pCand( pPF ? *pPF : reco::PFCandidate(i0->charge(), i0->p4(), id) );
161  LorentzVector pVec = i0->p4();
162  int val = i0 - i0begin;
163 
164  // Find the Puppi particle matched to the input collection using the "user_index" of the object.
165  auto puppiMatched = find_if( lCandidates.begin(), lCandidates.end(), [&val]( fastjet::PseudoJet const & i ){ return i.user_index() == val; } );
166  if ( puppiMatched != lCandidates.end() ) {
167  pVec.SetPxPyPzE(puppiMatched->px(),puppiMatched->py(),puppiMatched->pz(),puppiMatched->E());
168  } else {
169  pVec.SetPxPyPzE( 0, 0, 0, 0);
170  }
171  pCand.setP4(pVec);
172  puppiP4s.push_back( pVec );
173  fPuppiCandidates->push_back(pCand);
174  }
175 
176  //Compute the modified p4s
177  edm::ValueMap<LorentzVector>::Filler p4PupFiller(*p4PupOut);
178  p4PupFiller.insert(hPFProduct,puppiP4s.begin(), puppiP4s.end() );
179  p4PupFiller.fill();
180 
181  iEvent.put(lPupOut);
182  iEvent.put(p4PupOut);
184  for(unsigned int ic=0, nc = oh->size(); ic < nc; ++ic) {
185  reco::CandidatePtr pkref( oh, ic );
186  values[ic] = pkref;
187 
188  }
189  std::auto_ptr<edm::ValueMap<reco::CandidatePtr> > pfMap_p(new edm::ValueMap<reco::CandidatePtr>());
191  filler.insert(hPFProduct, values.begin(), values.end());
192  filler.fill();
193  iEvent.put(pfMap_p);
194 
195 }
virtual float dz(size_t ipv=0) const
dz with respect to the PV[ipv]
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:449
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
const PVAssoc fromPV(size_t ipv=0) const
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
int vtxId
Definition: RecoObj.h:20

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().