CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
pat::PATPackedCandidateProducer Class Reference
Inheritance diagram for pat::PATPackedCandidateProducer:
edm::EDProducer edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

 PATPackedCandidateProducer (const edm::ParameterSet &)
 
virtual void produce (edm::Event &, const edm::EventSetup &)
 
 ~PATPackedCandidateProducer ()
 
- Public Member Functions inherited from edm::EDProducer
 EDProducer ()
 
ModuleDescription const & moduleDescription () const
 
virtual ~EDProducer ()
 
- 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 ()
 

Private Member Functions

float calcDxy (float dx, float dy, float phi)
 
float calcDz (reco::Candidate::Point p, reco::Candidate::Point v, const reco::Candidate &c)
 

Private Attributes

edm::EDGetTokenT
< reco::PFCandidateCollection
Cands_
 
edm::EDGetTokenT
< reco::PFCandidateFwdPtrVector
CandsFromPVLoose_
 
edm::EDGetTokenT
< reco::PFCandidateFwdPtrVector
CandsFromPVTight_
 
double minPtForTrackProperties_
 
edm::EDGetTokenT
< reco::VertexCollection
PVOrigs_
 
edm::EDGetTokenT
< reco::VertexCollection
PVs_
 
edm::EDGetTokenT
< reco::TrackCollection
TKOrigs_
 

Additional Inherited Members

- Public Types inherited from edm::EDProducer
typedef EDProducer ModuleType
 
- Public Types inherited from edm::ProducerBase
typedef
ProductRegistryHelper::TypeLabelList 
TypeLabelList
 
- Static Public Member Functions inherited from edm::EDProducer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- 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 33 of file PATPackedCandidateProducer.cc.

Constructor & Destructor Documentation

pat::PATPackedCandidateProducer::PATPackedCandidateProducer ( const edm::ParameterSet iConfig)
explicit

Definition at line 58 of file PATPackedCandidateProducer.cc.

58  :
59  Cands_(consumes<reco::PFCandidateCollection>(iConfig.getParameter<edm::InputTag>("inputCollection"))),
60  CandsFromPVLoose_(consumes<reco::PFCandidateFwdPtrVector>(iConfig.getParameter<edm::InputTag>("inputCollectionFromPVLoose"))),
61  CandsFromPVTight_(consumes<reco::PFCandidateFwdPtrVector>(iConfig.getParameter<edm::InputTag>("inputCollectionFromPVTight"))),
62  PVs_(consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("inputVertices"))),
63  PVOrigs_(consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("originalVertices"))),
64  TKOrigs_(consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("originalTracks"))),
65  minPtForTrackProperties_(iConfig.getParameter<double>("minPtForTrackProperties"))
66 {
67  produces< std::vector<pat::PackedCandidate> > ();
68  produces< edm::Association<pat::PackedCandidateCollection> > ();
69  produces< edm::Association<reco::PFCandidateCollection> > ();
70 }
T getParameter(std::string const &) const
edm::EDGetTokenT< reco::PFCandidateFwdPtrVector > CandsFromPVLoose_
edm::EDGetTokenT< reco::TrackCollection > TKOrigs_
edm::EDGetTokenT< reco::PFCandidateCollection > Cands_
edm::EDGetTokenT< reco::VertexCollection > PVs_
edm::EDGetTokenT< reco::PFCandidateFwdPtrVector > CandsFromPVTight_
edm::EDGetTokenT< reco::VertexCollection > PVOrigs_
pat::PATPackedCandidateProducer::~PATPackedCandidateProducer ( )

Definition at line 72 of file PATPackedCandidateProducer.cc.

72 {}

Member Function Documentation

float pat::PATPackedCandidateProducer::calcDxy ( float  dx,
float  dy,
float  phi 
)
inlineprivate

Definition at line 49 of file PATPackedCandidateProducer.cc.

References funct::cos(), and funct::sin().

49  {
50  return - dx * std::sin(phi) + dy * std::cos(phi);
51  }
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Definition: DDAxes.h:10
float pat::PATPackedCandidateProducer::calcDz ( reco::Candidate::Point  p,
reco::Candidate::Point  v,
const reco::Candidate c 
)
inlineprivate

Definition at line 52 of file PATPackedCandidateProducer.cc.

References reco::Candidate::pt(), reco::Candidate::px(), reco::Candidate::py(), and reco::Candidate::pz().

52  {
53  return p.Z()-v.Z() - ((p.X()-v.X()) * c.px() + (p.Y()-v.Y())*c.py()) * c.pz()/(c.pt()*c.pt());
54  }
virtual double pz() const =0
z coordinate of momentum vector
virtual float pt() const =0
transverse momentum
virtual double py() const =0
y coordinate of momentum vector
virtual double px() const =0
x coordinate of momentum vector
void pat::PATPackedCandidateProducer::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
virtual

Implements edm::EDProducer.

Definition at line 74 of file PATPackedCandidateProducer.cc.

References funct::abs(), reco::CompositePtrCandidate::daughterPtrVector(), edm::hlt::Exception, edm::helper::Filler< Map >::fill(), edm::Event::getByLabel(), edm::Event::getByToken(), reco::PFCandidate::gsfTrackRef(), reco::HitPattern::hasValidHitInFirstPixelBarrel(), reco::TrackBase::highPurity, reco::TrackBase::hitPattern(), i, edm::HandleBase::id(), edm::Ref< C, T, F >::id(), edm::helper::Filler< Map >::insert(), edm::Ref< C, T, F >::isNonnull(), metsig::jet, fwrapper::jets, combine::key, edm::Ref< C, T, F >::key(), pat::PackedCandidate::moreLostInnerHits, reco::PFCandidate::muonRef(), pat::PackedCandidate::noLostInnerHits, pat::PackedCandidate::NoPV, reco::HitPattern::numberOfLostHits(), pat::PackedCandidate::oneLostInnerHit, reco::LeafCandidate::pdgId(), reco::TrackBase::phi(), reco::LeafCandidate::phi(), reco::LeafCandidate::polarP4(), RecoTauCleanerPlugins::pt, edm::Event::put(), pat::PackedCandidate::PVLoose, pat::PackedCandidate::PVTight, pat::PackedCandidate::PVUsedInFit, reco::TrackBase::referencePoint(), reco::TrackBase::trackerExpectedHitsInner(), reco::PFCandidate::trackRef(), reco::Vertex::trackWeight(), pat::PackedCandidate::validHitInFirstPixelBarrelLayer, and reco::PFCandidate::vertex().

74  {
75 
76 #ifdef CRAZYSORT
78  iEvent.getByLabel("selectedPatJets", jets);
79 #endif
80 
81 /* edm::ESHandle<MagneticField> magneticField;
82  iSetup.get<IdealMagneticFieldRecord>().get(magneticField);
83  AnalyticalImpactPointExtrapolator extrapolator(&*magneticField);
84 */
86  iEvent.getByToken( Cands_, cands );
87  std::vector<reco::Candidate>::const_iterator cand;
88 
90  iEvent.getByToken( CandsFromPVLoose_, candsFromPVLoose );
92  iEvent.getByToken( CandsFromPVTight_, candsFromPVTight );
93 
94  std::vector<pat::PackedCandidate::PVAssoc> fromPV(cands->size(), pat::PackedCandidate::NoPV);
95  for (const reco::PFCandidateFwdPtr &ptr : *candsFromPVLoose) {
96  if (ptr.ptr().id() == cands.id()) {
97  fromPV[ptr.ptr().key()] = pat::PackedCandidate::PVLoose;
98  } else if (ptr.backPtr().id() == cands.id()) {
99  fromPV[ptr.backPtr().key()] = pat::PackedCandidate::PVLoose;
100  } else {
101  throw cms::Exception("Configuration", "The elements from 'inputCollectionFromPVLoose' don't point to 'inputCollection'\n");
102  }
103  }
104  for (const reco::PFCandidateFwdPtr &ptr : *candsFromPVTight) {
105  if (ptr.ptr().id() == cands.id()) {
106  fromPV[ptr.ptr().key()] = pat::PackedCandidate::PVTight;
107  } else if (ptr.backPtr().id() == cands.id()) {
108  fromPV[ptr.backPtr().key()] = pat::PackedCandidate::PVTight;
109  } else {
110  throw cms::Exception("Configuration", "The elements from 'inputCollectionFromPVTight' don't point to 'inputCollection'\n");
111  }
112  }
113 
115  iEvent.getByToken( PVOrigs_, PVOrigs );
116  const reco::Vertex & PVOrig = (*PVOrigs)[0];
118  iEvent.getByToken( PVs_, PVs );
119  reco::VertexRef PV(PVs.id());
120  math::XYZPoint PVpos;
121  if (!PVs->empty()) {
122  PV = reco::VertexRef(PVs, 0);
123  PVpos = PV->position();
124  }
125 
127  iEvent.getByToken( TKOrigs_, TKOrigs );
128 
129  std::auto_ptr< std::vector<pat::PackedCandidate> > outPtrP( new std::vector<pat::PackedCandidate> );
130  std::vector<int> mapping(cands->size());
131  std::vector<int> mappingTk(TKOrigs->size(), -1);
132 #ifdef CRAZYSORT
133  std::vector<int> jetOrder;
134  std::vector<int> jetOrderReverse;
135  for(unsigned int i=0;i<cands->size();i++) jetOrderReverse.push_back(-1);
136  for (edm::View<pat::Jet>::const_iterator it = jets->begin(), ed = jets->end(); it != ed; ++it) {
137  const pat::Jet & jet = *it;
139  for(unsigned int i=0;i<dau.size();i++)
140  {
141  if((*cands)[dau[i].key()].trackRef().isNonnull() && (*cands)[dau[i].key()].pt() > minPtForTrackProperties_){
142  jetOrder.push_back(dau[i].key());
143  jetOrderReverse[jetOrder.back()]=jetOrder.size()-1;
144  }
145  }
146  for(unsigned int i=0;i<dau.size();i++)
147  {
148  if(!((*cands)[dau[i].key()].trackRef().isNonnull() && (*cands)[dau[i].key()].pt() > minPtForTrackProperties_)){
149  jetOrder.push_back(dau[i].key());
150  jetOrderReverse[jetOrder.back()]=jetOrder.size()-1;
151  }
152  }
153 
154  }
155  for(unsigned int ic=0, nc = cands->size(); ic < nc; ++ic) {
156  if(jetOrderReverse[ic]==-1 && (*cands)[ic].trackRef().isNonnull() && (*cands)[ic].pt() > minPtForTrackProperties_)
157  {
158  jetOrder.push_back(ic);
159  jetOrderReverse[jetOrder.back()]=jetOrder.size()-1;
160  }
161 
162  }
163  //all what's left
164  for(unsigned int ic=0, nc = cands->size(); ic < nc; ++ic) {
165  if(jetOrderReverse[ic]==-1)
166  {
167  jetOrder.push_back(ic);
168  jetOrderReverse[jetOrder.back()]=jetOrder.size()-1;
169  }
170 
171  }
172 #endif //CRAZYSORT
173 
174 
175  for(unsigned int ic=0, nc = cands->size(); ic < nc; ++ic) {
176 #ifdef CRAZYSORT
177  const reco::PFCandidate &cand=(*cands)[jetOrder[ic]];
178 #else
179  const reco::PFCandidate &cand=(*cands)[ic];
180 #endif
181  float phiAtVtx = cand.phi();
182  const reco::Track *ctrack = 0;
183  if ((abs(cand.pdgId()) == 11 || cand.pdgId() == 22) && cand.gsfTrackRef().isNonnull()) {
184  ctrack = &*cand.gsfTrackRef();
185  } else if (cand.trackRef().isNonnull()) {
186  ctrack = &*cand.trackRef();
187  }
188  if (ctrack) {
189  math::XYZPoint vtx = cand.vertex();
191 
192 // TrajectoryStateOnSurface tsos = extrapolator.extrapolate(trajectoryStateTransform::initialFreeState(*ctrack,&*magneticField), RecoVertex::convertPos(PV->position()));
193 // vtx = tsos.globalPosition();
194 // phiAtVtx = tsos.globalDirection().phi();
195  vtx = ctrack->referencePoint();
196  phiAtVtx = ctrack->phi();
197  int nlost = ctrack->trackerExpectedHitsInner().numberOfLostHits();
198  if (nlost == 0) {
199  if ( ctrack->hitPattern().hasValidHitInFirstPixelBarrel()) {
201  }
202  } else {
204  }
205 
206 
207  outPtrP->push_back( pat::PackedCandidate(cand.polarP4(), vtx, phiAtVtx, cand.pdgId(), PV));
208 
209  // properties of the best track
210  outPtrP->back().setLostInnerHits( lostHits );
211  if(outPtrP->back().pt() > minPtForTrackProperties_) {
212  outPtrP->back().setTrackProperties(*ctrack);
213  //outPtrP->back().setTrackProperties(*ctrack,tsos.curvilinearError());
214  }
215 
216  // these things are always for the CKF track
217  if(cand.trackRef().isNonnull() && PVOrig.trackWeight(cand.trackRef()) > 0.5) {
218  outPtrP->back().setFromPV(pat::PackedCandidate::PVUsedInFit);
219  } else {
220  outPtrP->back().setFromPV( fromPV[ic] );
221  }
222  outPtrP->back().setTrackHighPurity( cand.trackRef().isNonnull() && cand.trackRef()->quality(reco::Track::highPurity) );
223  if (cand.muonRef().isNonnull()) {
224  outPtrP->back().setMuonID(cand.muonRef()->isStandAloneMuon(), cand.muonRef()->isGlobalMuon());
225  }
226  } else {
227  outPtrP->push_back( pat::PackedCandidate(cand.polarP4(), PVpos, cand.phi(), cand.pdgId(), PV));
228  outPtrP->back().setFromPV( fromPV[ic] );
229  }
230 
231  mapping[ic] = ic; // trivial at the moment!
232  if (cand.trackRef().isNonnull() && cand.trackRef().id() == TKOrigs.id()) {
233  mappingTk[cand.trackRef().key()] = ic;
234  }
235 
236  }
237 
238 
240 
241  // now build the two maps
242  std::auto_ptr<edm::Association<pat::PackedCandidateCollection> > pf2pc(new edm::Association<pat::PackedCandidateCollection>(oh ));
243  std::auto_ptr<edm::Association<reco::PFCandidateCollection > > pc2pf(new edm::Association<reco::PFCandidateCollection >(cands));
246 #ifdef CRAZYSORT
247  pf2pcFiller.insert(cands, jetOrderReverse.begin(), jetOrderReverse.end());
248  pc2pfFiller.insert(oh , jetOrder.begin(), jetOrder.end());
249 #else
250  pf2pcFiller.insert(cands, mapping.begin(), mapping.end());
251  pc2pfFiller.insert(oh , mapping.begin(), mapping.end());
252 #endif
253  // include also the mapping track -> packed PFCand
254  pf2pcFiller.insert(TKOrigs, mappingTk.begin(), mappingTk.end());
255 
256  pf2pcFiller.fill();
257  pc2pfFiller.fill();
258  iEvent.put(pf2pc);
259  iEvent.put(pc2pf);
260 
261 }
int i
Definition: DBlmapReader.cc:9
virtual int pdgId() const
PDG identifier.
edm::EDGetTokenT< reco::PFCandidateFwdPtrVector > CandsFromPVLoose_
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81
ProductID id() const
Definition: HandleBase.cc:15
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
virtual float phi() const
momentum azimuthal angle
int numberOfLostHits() const
Definition: HitPattern.h:646
double phi() const
azimuthal angle of momentum vector
Definition: TrackBase.h:137
const Point & referencePoint() const
Reference point on the track.
Definition: TrackBase.h:151
edm::EDGetTokenT< reco::TrackCollection > TKOrigs_
reco::TrackRef trackRef() const
Definition: PFCandidate.cc:429
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:250
edm::EDGetTokenT< reco::PFCandidateCollection > Cands_
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
float trackWeight(const TrackBaseRef &r) const
returns the weight with which a Track has contributed to the vertex-fit.
vector< PseudoJet > jets
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
virtual const Point & vertex() const
vertex position (overwritten by PF...)
Definition: PFCandidate.cc:643
const HitPattern & trackerExpectedHitsInner() const
Access the hit pattern counting (in the Tracker) the number of expected crossed layers before the fir...
Definition: TrackBase.h:223
edm::EDGetTokenT< reco::VertexCollection > PVs_
edm::EDGetTokenT< reco::PFCandidateFwdPtrVector > CandsFromPVTight_
const HitPattern & hitPattern() const
Access the hit pattern, indicating in which Tracker layers the track has hits.
Definition: TrackBase.h:221
edm::Ref< VertexCollection > VertexRef
persistent reference to a Vertex
Definition: VertexFwd.h:13
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:390
reco::MuonRef muonRef() const
Definition: PFCandidate.cc:446
LostInnerHits
Enumerator specifying the.
std::vector< CandidatePtr > daughters
collection of references to daughters
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
key_type key() const
Accessor for product key.
Definition: Ref.h:266
Analysis-level calorimeter jet class.
Definition: Jet.h:73
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:38
virtual const PolarLorentzVector & polarP4() const
four-momentum Lorentz vector
list key
Definition: combine.py:13
reco::GsfTrackRef gsfTrackRef() const
Definition: PFCandidate.cc:467
const daughters & daughterPtrVector() const
references to daughtes
ProductID id() const
Accessor for product ID.
Definition: Ref.h:256
bool hasValidHitInFirstPixelBarrel() const
Definition: HitPattern.cc:181
edm::EDGetTokenT< reco::VertexCollection > PVOrigs_

Member Data Documentation

edm::EDGetTokenT<reco::PFCandidateCollection> pat::PATPackedCandidateProducer::Cands_
private

Definition at line 41 of file PATPackedCandidateProducer.cc.

edm::EDGetTokenT<reco::PFCandidateFwdPtrVector> pat::PATPackedCandidateProducer::CandsFromPVLoose_
private

Definition at line 42 of file PATPackedCandidateProducer.cc.

edm::EDGetTokenT<reco::PFCandidateFwdPtrVector> pat::PATPackedCandidateProducer::CandsFromPVTight_
private

Definition at line 43 of file PATPackedCandidateProducer.cc.

double pat::PATPackedCandidateProducer::minPtForTrackProperties_
private

Definition at line 47 of file PATPackedCandidateProducer.cc.

edm::EDGetTokenT<reco::VertexCollection> pat::PATPackedCandidateProducer::PVOrigs_
private

Definition at line 45 of file PATPackedCandidateProducer.cc.

edm::EDGetTokenT<reco::VertexCollection> pat::PATPackedCandidateProducer::PVs_
private

Definition at line 44 of file PATPackedCandidateProducer.cc.

edm::EDGetTokenT<reco::TrackCollection> pat::PATPackedCandidateProducer::TKOrigs_
private

Definition at line 46 of file PATPackedCandidateProducer.cc.