CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
pat::PATPackedCandidateProducer Class Reference
Inheritance diagram for pat::PATPackedCandidateProducer:
edm::global::EDProducer<> edm::global::EDProducerBase edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

bool candsOrdering (pat::PackedCandidate i, pat::PackedCandidate j) const
 
 PATPackedCandidateProducer (const edm::ParameterSet &)
 
void produce (edm::StreamID, edm::Event &, const edm::EventSetup &) const override
 
template<typename T >
std::vector< size_t > sort_indexes (const std::vector< T > &v) const
 
 ~PATPackedCandidateProducer () override
 
- Public Member Functions inherited from edm::global::EDProducer<>
 EDProducer ()=default
 
bool hasAbilityToProduceInLumis () const final
 
bool hasAbilityToProduceInRuns () const final
 
bool wantsGlobalLuminosityBlocks () const final
 
bool wantsGlobalRuns () const final
 
bool wantsStreamLuminosityBlocks () const final
 
bool wantsStreamRuns () const final
 
- Public Member Functions inherited from edm::global::EDProducerBase
 EDProducerBase ()
 
ModuleDescription const & moduleDescription () const
 
 ~EDProducerBase () override
 
- Public Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
std::vector< edm::ProductResolverIndex > const & indiciesForPutProducts (BranchType iBranchType) const
 
 ProducerBase ()
 
std::vector< edm::ProductResolverIndex > const & putTokenIndexToProductResolverIndex () const
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription const &)> registrationCallback () const
 used by the fwk to register list of products More...
 
void resolvePutIndicies (BranchType iBranchType, ModuleToResolverIndicies const &iIndicies, std::string const &moduleLabel)
 
 ~ProducerBase () noexcept(false) override
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
virtual ~EDConsumerBase () noexcept(false)
 

Private Member Functions

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

Private Attributes

const edm::EDGetTokenT< reco::PFCandidateCollectionCands_
 
const edm::EDGetTokenT< edm::ValueMap< bool > > ChargedHadronIsolation_
 
const std::vector< int > covariancePackingSchemas_
 
const int covarianceVersion_
 
const double minPtForChargedHadronProperties_
 
const double minPtForTrackProperties_
 
const edm::EDGetTokenT< std::vector< reco::PFCandidate > > PuppiCands_
 
const edm::EDGetTokenT< edm::ValueMap< reco::CandidatePtr > > PuppiCandsMap_
 
const edm::EDGetTokenT< std::vector< reco::PFCandidate > > PuppiCandsNoLep_
 
const edm::EDGetTokenT< edm::ValueMap< float > > PuppiWeight_
 
const edm::EDGetTokenT< edm::ValueMap< float > > PuppiWeightNoLep_
 
const edm::EDGetTokenT< edm::Association< reco::VertexCollection > > PVAsso_
 
const edm::EDGetTokenT< edm::ValueMap< int > > PVAssoQuality_
 
const edm::EDGetTokenT< reco::VertexCollectionPVOrigs_
 
const edm::EDGetTokenT< reco::VertexCollectionPVs_
 
const bool storeChargedHadronIsolation_
 
const bool storeTiming_
 
std::vector< edm::EDGetTokenT< edm::View< reco::Candidate > > > SVWhiteLists_
 
const edm::EDGetTokenT< reco::TrackCollectionTKOrigs_
 
const bool usePuppi_
 

Additional Inherited Members

- Public Types inherited from edm::global::EDProducerBase
typedef EDProducerBase ModuleType
 
- Public Types inherited from edm::ProducerBase
using ModuleToResolverIndicies = std::unordered_multimap< std::string, std::tuple< edm::TypeID const *, const char *, edm::ProductResolverIndex >>
 
typedef ProductRegistryHelper::TypeLabelList TypeLabelList
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Public Member Functions inherited from edm::global::EDProducerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- 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 36 of file PATPackedCandidateProducer.cc.

Constructor & Destructor Documentation

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

Definition at line 106 of file PATPackedCandidateProducer.cc.

References edm::EDConsumerBase::consumes(), edm::ParameterSet::getParameter(), and SVWhiteLists_.

106  :
107  usePuppi_(!iConfig.getParameter<edm::InputTag>("PuppiSrc").encode().empty() ||
108  !iConfig.getParameter<edm::InputTag>("PuppiNoLepSrc").encode().empty()),
109  Cands_(consumes<reco::PFCandidateCollection>(iConfig.getParameter<edm::InputTag>("inputCollection"))),
110  PVs_(consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("inputVertices"))),
112  PVAssoQuality_(consumes<edm::ValueMap<int> >(iConfig.getParameter<edm::InputTag>("vertexAssociator"))),
113  PVOrigs_(consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("originalVertices"))),
114  TKOrigs_(consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("originalTracks"))),
115  PuppiWeight_(usePuppi_ ? consumes<edm::ValueMap<float> >(iConfig.getParameter<edm::InputTag>("PuppiSrc")) : edm::EDGetTokenT< edm::ValueMap<float> >()),
116  PuppiWeightNoLep_(usePuppi_ ? consumes<edm::ValueMap<float> >(iConfig.getParameter<edm::InputTag>("PuppiNoLepSrc")) : edm::EDGetTokenT< edm::ValueMap<float> >()),
117  PuppiCandsMap_(usePuppi_ ? consumes<edm::ValueMap<reco::CandidatePtr> >(iConfig.getParameter<edm::InputTag>("PuppiSrc")) : edm::EDGetTokenT<edm::ValueMap<reco::CandidatePtr> >() ),
118  PuppiCands_(usePuppi_ ? consumes<std::vector< reco::PFCandidate > >(iConfig.getParameter<edm::InputTag>("PuppiSrc")) : edm::EDGetTokenT<std::vector< reco::PFCandidate > >() ),
119  PuppiCandsNoLep_(usePuppi_ ? consumes<std::vector< reco::PFCandidate > >(iConfig.getParameter<edm::InputTag>("PuppiNoLepSrc")) : edm::EDGetTokenT<std::vector< reco::PFCandidate > >()),
120  storeChargedHadronIsolation_(!iConfig.getParameter<edm::InputTag>("chargedHadronIsolation").encode().empty()),
121  ChargedHadronIsolation_(consumes<edm::ValueMap<bool> >(iConfig.getParameter<edm::InputTag>("chargedHadronIsolation"))),
122  minPtForChargedHadronProperties_(iConfig.getParameter<double>("minPtForChargedHadronProperties")),
123  minPtForTrackProperties_(iConfig.getParameter<double>("minPtForTrackProperties")),
124  covarianceVersion_(iConfig.getParameter<int >("covarianceVersion")),
125  covariancePackingSchemas_(iConfig.getParameter<std::vector<int> >("covariancePackingSchemas")),
126  storeTiming_(iConfig.getParameter<bool>("storeTiming"))
127 {
128  std::vector<edm::InputTag> sv_tags = iConfig.getParameter<std::vector<edm::InputTag> >("secondaryVerticesForWhiteList");
129  for(auto itag : sv_tags){
130  SVWhiteLists_.push_back(
132  );
133  }
134 
135  produces< std::vector<pat::PackedCandidate> > ();
136  produces< edm::Association<pat::PackedCandidateCollection> > ();
137  produces< edm::Association<reco::PFCandidateCollection> > ();
138 }
T getParameter(std::string const &) const
const edm::EDGetTokenT< edm::ValueMap< float > > PuppiWeight_
const edm::EDGetTokenT< reco::PFCandidateCollection > Cands_
std::string encode() const
Definition: InputTag.cc:166
const edm::EDGetTokenT< edm::ValueMap< int > > PVAssoQuality_
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
const edm::EDGetTokenT< reco::TrackCollection > TKOrigs_
const edm::EDGetTokenT< std::vector< reco::PFCandidate > > PuppiCands_
const edm::EDGetTokenT< edm::ValueMap< reco::CandidatePtr > > PuppiCandsMap_
const edm::EDGetTokenT< edm::ValueMap< float > > PuppiWeightNoLep_
const edm::EDGetTokenT< edm::ValueMap< bool > > ChargedHadronIsolation_
edm::Ptr< Candidate > CandidatePtr
persistent reference to an object in a collection of Candidate objects
Definition: CandidateFwd.h:25
const std::vector< int > covariancePackingSchemas_
const edm::EDGetTokenT< std::vector< reco::PFCandidate > > PuppiCandsNoLep_
def encode(args, files)
const edm::EDGetTokenT< reco::VertexCollection > PVOrigs_
fixed size matrix
HLT enums.
std::vector< edm::EDGetTokenT< edm::View< reco::Candidate > > > SVWhiteLists_
const edm::EDGetTokenT< edm::Association< reco::VertexCollection > > PVAsso_
const edm::EDGetTokenT< reco::VertexCollection > PVs_
pat::PATPackedCandidateProducer::~PATPackedCandidateProducer ( )
override

Definition at line 140 of file PATPackedCandidateProducer.cc.

140 {}

Member Function Documentation

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

Definition at line 97 of file PATPackedCandidateProducer.cc.

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

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

Definition at line 100 of file PATPackedCandidateProducer.cc.

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

100  {
101  return p.Z()-v.Z() - ((p.X()-v.X()) * c.px() + (p.Y()-v.Y())*c.py()) * c.pz()/(c.pt()*c.pt());
102  }
virtual double pz() const =0
z coordinate of momentum vector
virtual double py() const =0
y coordinate of momentum vector
virtual double pt() const =0
transverse momentum
virtual double px() const =0
x coordinate of momentum vector
bool pat::PATPackedCandidateProducer::candsOrdering ( pat::PackedCandidate  i,
pat::PackedCandidate  j 
) const
inline

Definition at line 44 of file PATPackedCandidateProducer.cc.

References funct::abs(), pat::PackedCandidate::charge(), pat::PackedCandidate::covarianceSchema(), pat::PackedCandidate::eta(), pat::PackedCandidate::hasTrackDetails(), edm::Ref< C, T, F >::key(), and pat::PackedCandidate::vertexRef().

Referenced by sort_indexes().

44  {
45  if (std::abs(i.charge()) == std::abs(j.charge())) {
46  if(i.charge()!=0){
47  if(i.hasTrackDetails() and ! j.hasTrackDetails() ) return true;
48  if(! i.hasTrackDetails() and j.hasTrackDetails() ) return false;
49  if(i.covarianceSchema() > j.covarianceSchema() ) return true;
50  if(i.covarianceSchema() < j.covarianceSchema() ) return false;
51 
52  }
53  if(i.vertexRef() == j.vertexRef())
54  return i.eta() > j.eta();
55  else
56  return i.vertexRef().key() < j.vertexRef().key();
57  }
58  return std::abs(i.charge()) > std::abs(j.charge());
59  }
int covarianceSchema() const
key_type key() const
Accessor for product key.
Definition: Ref.h:265
const reco::VertexRef vertexRef() const
int charge() const override
electric charge
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
bool hasTrackDetails() const
Return true if a bestTrack can be extracted from this Candidate.
double eta() const override
momentum pseudorapidity
void pat::PATPackedCandidateProducer::produce ( edm::StreamID  ,
edm::Event iEvent,
const edm::EventSetup iSetup 
) const
override

Definition at line 144 of file PATPackedCandidateProducer.cc.

References funct::abs(), begin, EnergyCorrector::c, egammaForCoreTracking_cff::cands, Cands_, packedPFCandidates_cfi::chargedHadronIsolation, ChargedHadronIsolation_, covariancePackingSchemas_, covarianceVersion_, DEFINE_FWK_MODULE, PVValHelper::dz, reco::TrackBase::dz(), reco::PFCandidate::e, reco::PFCandidate::ecalEnergy(), edm::View< T >::end(), reco::LeafCandidate::energy(), reco::LeafCandidate::eta(), reco::TrackBase::eta(), edm::helper::Filler< Map >::fill(), reco::PFCandidate::gamma, edm::Event::getByToken(), reco::HitPattern::getHitPattern(), reco::PFCandidate::gsfTrackRef(), reco::HitPattern::hasValidHitInPixelLayer(), reco::PFCandidate::hcalEnergy(), reco::TrackBase::highPurity, reco::TrackBase::hitPattern(), mps_fire::i, edm::HandleBase::id(), edm::Ptr< T >::id(), edm::Ref< C, T, F >::id(), cuy::ii, edm::helper::Filler< Map >::insert(), edm::Ref< C, T, F >::isNonnull(), reco::PFCandidate::isTimeValid(), edm::HandleBase::isValid(), crabWrapper::key, edm::Ptr< T >::key(), edm::Ref< C, T, F >::key(), electrons_cff::lostHits, taus_updatedMVAIds_cff::mapping, minPtForChargedHadronProperties_, minPtForTrackProperties_, reco::HitPattern::MISSING_INNER_HITS, pat::PackedCandidate::moreLostInnerHits, eostools::move(), reco::PFCandidate::muonRef(), reco::PFCandidate::mva_nothing_gamma(), pat::PackedCandidate::noLostInnerHits, reco::HitPattern::numberOfLostHits(), reco::HitPattern::numberOfValidPixelHits(), pat::PackedCandidate::oneLostInnerHit, reco::PFCandidate::particleId(), reco::LeafCandidate::pdgId(), reco::LeafCandidate::phi(), reco::TrackBase::phi(), GeomDetEnumerators::PixelBarrel, reco::LeafCandidate::polarP4(), edm::Handle< T >::product(), reco::LeafCandidate::pt(), reco::TrackBase::pt(), PuppiCands_, PuppiCandsMap_, PuppiCandsNoLep_, PuppiWeight_, PuppiWeightNoLep_, edm::Event::put(), nanoDQM_cfi::PV, PVAsso_, PVAssoQuality_, PVOrigs_, PVs_, jets_cff::quality, pat::qualityMap, reco::PFCandidate::rawEcalEnergy(), reco::PFCandidate::rawHcalEnergy(), reco::TrackBase::referencePoint(), edm::View< T >::size(), sort_indexes(), storeChargedHadronIsolation_, storeTiming_, SVWhiteLists_, reco::PFCandidate::time(), reco::PFCandidate::timeError(), TKOrigs_, reco::RecoChargedCandidate::track(), reco::HitPattern::TRACK_HITS, reco::PFCandidate::trackRef(), pat::PackedCandidate::UsedInFitTight, usePuppi_, pat::PackedCandidate::validHitInFirstPixelBarrelLayer, reco::PFCandidate::vertex(), and badGlobalMuonTaggersAOD_cff::vtx.

144  {
145 
147  iEvent.getByToken( Cands_, cands );
148  std::vector<reco::Candidate>::const_iterator cand;
149 
150  edm::Handle<edm::ValueMap<float> > puppiWeight;
153  edm::Handle<edm::ValueMap<float> > puppiWeightNoLep;
155  std::vector<reco::CandidatePtr> puppiCandsNoLepPtrs;
156  if(usePuppi_){
157  iEvent.getByToken( PuppiWeight_, puppiWeight );
158  iEvent.getByToken( PuppiCandsMap_, puppiCandsMap );
159  iEvent.getByToken( PuppiCands_, puppiCands );
160  iEvent.getByToken( PuppiWeightNoLep_, puppiWeightNoLep );
161  iEvent.getByToken( PuppiCandsNoLep_, puppiCandsNoLep );
162  for (auto pup : *puppiCandsNoLep){
163  puppiCandsNoLepPtrs.push_back(pup.sourceCandidatePtr(0));
164  }
165  }
166  std::vector<int> mappingPuppi(usePuppi_ ? puppiCands->size() : 0);
167 
169  iEvent.getByToken( PVOrigs_, PVOrigs );
170 
172  iEvent.getByToken(PVAsso_,assoHandle);
173  edm::Handle<edm::ValueMap<int> > assoQualityHandle;
174  iEvent.getByToken(PVAssoQuality_,assoQualityHandle);
175  const edm::Association<reco::VertexCollection> & associatedPV=*(assoHandle.product());
176  const edm::ValueMap<int> & associationQuality=*(assoQualityHandle.product());
177 
178  edm::Handle<edm::ValueMap<bool> > chargedHadronIsolationHandle;
180  iEvent.getByToken(ChargedHadronIsolation_,chargedHadronIsolationHandle);
181 
182  std::set<unsigned int> whiteList;
183  std::set<reco::TrackRef> whiteListTk;
184  for(auto itoken : SVWhiteLists_) {
185  edm::Handle<edm::View<reco::Candidate > > svWhiteListHandle;
186  iEvent.getByToken(itoken, svWhiteListHandle);
187  const edm::View<reco::Candidate > & svWhiteList=*(svWhiteListHandle.product());
188  for(unsigned int i=0; i<svWhiteList.size();i++) {
189  //Whitelist via Ptrs
190  for(unsigned int j=0; j< svWhiteList[i].numberOfSourceCandidatePtrs(); j++) {
191  const edm::Ptr<reco::Candidate> & c = svWhiteList[i].sourceCandidatePtr(j);
192  if(c.id() == cands.id()) whiteList.insert(c.key());
193 
194  }
195  //Whitelist via RecoCharged
196  for(auto dau = svWhiteList[i].begin(); dau != svWhiteList[i].end() ; dau++){
197  const reco::RecoChargedCandidate * chCand=dynamic_cast<const reco::RecoChargedCandidate *>(&(*dau));
198  if(chCand!=nullptr) {
199  whiteListTk.insert(chCand->track());
200  }
201  }
202  }
203  }
204 
205 
207  iEvent.getByToken( PVs_, PVs );
208  reco::VertexRef PV(PVs.id());
209  reco::VertexRefProd PVRefProd(PVs);
210  math::XYZPoint PVpos;
211 
212 
214  iEvent.getByToken( TKOrigs_, TKOrigs );
215  auto outPtrP = std::make_unique<std::vector<pat::PackedCandidate>>();
216  std::vector<int> mapping(cands->size());
217  std::vector<int> mappingReverse(cands->size());
218  std::vector<int> mappingTk(TKOrigs->size(), -1);
219 
220  for(unsigned int ic=0, nc = cands->size(); ic < nc; ++ic) {
221  const reco::PFCandidate &cand=(*cands)[ic];
222  const reco::Track *ctrack = nullptr;
223  if ((abs(cand.pdgId()) == 11 || cand.pdgId() == 22) && cand.gsfTrackRef().isNonnull()) {
224  ctrack = &*cand.gsfTrackRef();
225  } else if (cand.trackRef().isNonnull()) {
226  ctrack = &*cand.trackRef();
227  }
228  if (ctrack) {
229  float dist=1e99;
230  int pvi=-1;
231  for(size_t ii=0;ii<PVs->size();ii++){
232  float dz=std::abs(ctrack->dz( ((*PVs)[ii]).position()));
233  if(dz<dist) {pvi=ii;dist=dz; }
234  }
235  PV = reco::VertexRef(PVs, pvi);
236  math::XYZPoint vtx = cand.vertex();
238  const reco::VertexRef & PVOrig = associatedPV[reco::CandidatePtr(cands,ic)];
239  if(PVOrig.isNonnull()) PV = reco::VertexRef(PVs, PVOrig.key()); // WARNING: assume the PV slimmer is keeping same order
240  int quality=associationQuality[reco::CandidatePtr(cands,ic)];
241 // if ((size_t)pvi!=PVOrig.key()) std::cout << "not closest in Z" << pvi << " " << PVOrig.key() << " " << cand.pt() << " " << quality << std::endl;
242  // TrajectoryStateOnSurface tsos = extrapolator.extrapolate(trajectoryStateTransform::initialFreeState(*ctrack,&*magneticField), RecoVertex::convertPos(PV->position()));
243  // vtx = tsos.globalPosition();
244  // phiAtVtx = tsos.globalDirection().phi();
245  vtx = ctrack->referencePoint();
246  float ptTrk = ctrack->pt();
247  float etaAtVtx = ctrack->eta();
248  float phiAtVtx = ctrack->phi();
249 
251  if (nlost == 0) {
254  }
255  } else {
257  }
258 
259 
260  outPtrP->push_back( pat::PackedCandidate(cand.polarP4(), vtx, ptTrk, etaAtVtx, phiAtVtx, cand.pdgId(), PVRefProd, PV.key()));
261  outPtrP->back().setAssociationQuality(pat::PackedCandidate::PVAssociationQuality(qualityMap[quality]));
262  outPtrP->back().setCovarianceVersion(covarianceVersion_);
263  if(cand.trackRef().isNonnull() && PVOrig.isNonnull() && PVOrig->trackWeight(cand.trackRef()) > 0.5 && quality == 7) {
264  outPtrP->back().setAssociationQuality(pat::PackedCandidate::UsedInFitTight);
265  }
266  // properties of the best track
267  outPtrP->back().setLostInnerHits( lostHits );
268  if(outPtrP->back().pt() > minPtForTrackProperties_ ||
269  outPtrP->back().ptTrk() > minPtForTrackProperties_ ||
270  whiteList.find(ic)!=whiteList.end() ||
271  (cand.trackRef().isNonnull() && whiteListTk.find(cand.trackRef())!=whiteListTk.end())
272  ) {
273  outPtrP->back().setFirstHit(ctrack->hitPattern().getHitPattern(reco::HitPattern::TRACK_HITS, 0));
274  if(abs(outPtrP->back().pdgId())==22) {
275  outPtrP->back().setTrackProperties(*ctrack,covariancePackingSchemas_[4],covarianceVersion_);
276  } else {
277  if( ctrack->hitPattern().numberOfValidPixelHits() >0) {
278  outPtrP->back().setTrackProperties(*ctrack,covariancePackingSchemas_[0],covarianceVersion_); //high quality
279  } else {
280  outPtrP->back().setTrackProperties(*ctrack,covariancePackingSchemas_[1],covarianceVersion_);
281  }
282  }
283  //outPtrP->back().setTrackProperties(*ctrack,tsos.curvilinearError());
284  } else {
285  if(outPtrP->back().pt() > 0.5 ){
286  if(ctrack->hitPattern().numberOfValidPixelHits() >0) outPtrP->back().setTrackProperties(*ctrack,covariancePackingSchemas_[2],covarianceVersion_); //low quality, with pixels
287  else outPtrP->back().setTrackProperties(*ctrack,covariancePackingSchemas_[3],covarianceVersion_); //low quality, without pixels
288  }
289  }
290 
291  // these things are always for the CKF track
292  outPtrP->back().setTrackHighPurity( cand.trackRef().isNonnull() && cand.trackRef()->quality(reco::Track::highPurity) );
293  if (cand.muonRef().isNonnull()) {
294  outPtrP->back().setMuonID(cand.muonRef()->isStandAloneMuon(), cand.muonRef()->isGlobalMuon());
295  }
296  } else {
297 
298  if (!PVs->empty()) {
299  PV = reco::VertexRef(PVs, 0);
300  PVpos = PV->position();
301  }
302 
303  outPtrP->push_back( pat::PackedCandidate(cand.polarP4(), PVpos, cand.pt(), cand.eta(), cand.phi(), cand.pdgId(), PVRefProd, PV.key()));
305  }
306 
307  // neutrals and isolated charged hadrons
308 
309  bool isIsolatedChargedHadron = false;
311  const edm::ValueMap<bool> & chargedHadronIsolation=*(chargedHadronIsolationHandle.product());
312  isIsolatedChargedHadron=((cand.pt()>minPtForChargedHadronProperties_)&&(chargedHadronIsolation[reco::PFCandidateRef(cands,ic)]));
313  outPtrP->back().setIsIsolatedChargedHadron(isIsolatedChargedHadron);
314  }
315 
316  if(abs(cand.pdgId()) == 1 || abs(cand.pdgId()) == 130) {
317  outPtrP->back().setHcalFraction(cand.hcalEnergy()/(cand.ecalEnergy()+cand.hcalEnergy()));
318  } else if(isIsolatedChargedHadron) {
319  outPtrP->back().setRawCaloFraction((cand.rawEcalEnergy()+cand.rawHcalEnergy())/cand.energy());
320  outPtrP->back().setHcalFraction(cand.rawHcalEnergy()/(cand.rawEcalEnergy()+cand.rawHcalEnergy()));
321  } else {
322  outPtrP->back().setHcalFraction(0);
323  }
324 
325  //specifically this is the PFLinker requirements to apply the e/gamma regression
326  if(cand.particleId() == reco::PFCandidate::e || (cand.particleId() == reco::PFCandidate::gamma && cand.mva_nothing_gamma()>0.)) {
327  outPtrP->back().setGoodEgamma();
328  }
329 
330  if (usePuppi_){
331  reco::PFCandidateRef pkref( cands, ic );
332  // outPtrP->back().setPuppiWeight( (*puppiWeight)[pkref]);
333 
334  float puppiWeightVal = (*puppiWeight)[pkref];
335  float puppiWeightNoLepVal = 0.0;
336  // Check the "no lepton" puppi weights.
337  // If present, then it is not a lepton, use stored weight
338  // If absent, it is a lepton, so set the weight to 1.0
339  if ( puppiWeightNoLep.isValid() ) {
340  // Look for the pointer inside the "no lepton" candidate collection.
341  auto pkrefPtr = pkref->sourceCandidatePtr(0);
342 
343  bool foundNoLep = false;
344  for ( size_t ipcnl = 0; ipcnl < puppiCandsNoLepPtrs.size(); ipcnl++){
345  if (puppiCandsNoLepPtrs[ipcnl] == pkrefPtr){
346  foundNoLep = true;
347  puppiWeightNoLepVal = puppiCandsNoLep->at(ipcnl).pt()/cand.pt(); // a hack for now, should use the value map
348  break;
349  }
350  }
351  if ( !foundNoLep || puppiWeightNoLepVal > 1 ) {
352  puppiWeightNoLepVal = 1.0;
353  }
354  }
355  outPtrP->back().setPuppiWeight( puppiWeightVal, puppiWeightNoLepVal );
356 
357  mappingPuppi[((*puppiCandsMap)[pkref]).key()]=ic;
358  }
359 
360  if (storeTiming_ && cand.isTimeValid()) {
361  outPtrP->back().setTime(cand.time(), cand.timeError());
362  }
363 
364  mapping[ic] = ic; // trivial at the moment!
365  if (cand.trackRef().isNonnull() && cand.trackRef().id() == TKOrigs.id()) {
366  mappingTk[cand.trackRef().key()] = ic;
367  }
368 
369  }
370 
371  auto outPtrPSorted = std::make_unique<std::vector<pat::PackedCandidate>>();
372  std::vector<size_t> order=sort_indexes(*outPtrP);
373  std::vector<size_t> reverseOrder(order.size());
374  for(size_t i=0,nc=cands->size();i<nc;i++) {
375  outPtrPSorted->push_back((*outPtrP)[order[i]]);
376  reverseOrder[order[i]] = i;
377  mappingReverse[order[i]]=i;
378  }
379 
380  // Fix track association for sorted candidates
381  for(size_t i=0,ntk=mappingTk.size();i<ntk;i++){
382  if(mappingTk[i] >= 0)
383  mappingTk[i]=reverseOrder[mappingTk[i]];
384  }
385 
386  for(size_t i=0,ntk=mappingPuppi.size();i<ntk;i++){
387  mappingPuppi[i]=reverseOrder[mappingPuppi[i]];
388  }
389 
391 
392  // now build the two maps
393  auto pf2pc = std::make_unique<edm::Association<pat::PackedCandidateCollection>>(oh);
394  auto pc2pf = std::make_unique<edm::Association<reco::PFCandidateCollection>>(cands);
397  pf2pcFiller.insert(cands, mappingReverse.begin(), mappingReverse.end());
398  pc2pfFiller.insert(oh , order.begin(), order.end());
399  // include also the mapping track -> packed PFCand
400  pf2pcFiller.insert(TKOrigs, mappingTk.begin(), mappingTk.end());
401  if(usePuppi_) pf2pcFiller.insert(puppiCands, mappingPuppi.begin(), mappingPuppi.end());
402 
403  pf2pcFiller.fill();
404  pc2pfFiller.fill();
405  iEvent.put(std::move(pf2pc));
406  iEvent.put(std::move(pc2pf));
407 
408 }
double ecalEnergy() const
return corrected Ecal energy
Definition: PFCandidate.h:222
int pdgId() const final
PDG identifier.
const Point & referencePoint() const
Reference point on the track.
Definition: TrackBase.h:681
const edm::EDGetTokenT< edm::ValueMap< float > > PuppiWeight_
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:137
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:253
double eta() const final
momentum pseudorapidity
const PolarLorentzVector & polarP4() const final
four-momentum Lorentz vector
double rawEcalEnergy() const
return corrected Ecal energy
Definition: PFCandidate.h:225
bool hasValidHitInPixelLayer(enum PixelSubdetector::SubDetector, uint16_t layer) const
Definition: HitPattern.cc:329
key_type key() const
Definition: Ptr.h:185
ProductID id() const
Definition: HandleBase.cc:15
float mva_nothing_gamma() const
mva for gamma detection
Definition: PFCandidate.h:333
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
size_type size() const
double phi() const
azimuthal angle of momentum vector
Definition: TrackBase.h:645
double pt() const final
transverse momentum
float time() const
Definition: PFCandidate.h:421
static const int qualityMap[8]
conversion map from quality flags used in PV association and miniAOD one
const edm::EDGetTokenT< reco::PFCandidateCollection > Cands_
key_type key() const
Accessor for product key.
Definition: Ref.h:265
ProductID id() const
Accessor for product ID.
Definition: Ref.h:259
const edm::EDGetTokenT< edm::ValueMap< int > > PVAssoQuality_
reco::TrackRef trackRef() const
Definition: PFCandidate.cc:442
const Point & vertex() const override
vertex position (overwritten by PF...)
Definition: PFCandidate.cc:656
bool isTimeValid() const
do we have a valid time information
Definition: PFCandidate.h:419
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:651
double pt() const
track transverse momentum
Definition: TrackBase.h:621
double energy() const final
energy
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
reco::TrackRef track() const override
reference to a track
const edm::EDGetTokenT< reco::TrackCollection > TKOrigs_
const edm::EDGetTokenT< std::vector< reco::PFCandidate > > PuppiCands_
std::vector< size_t > sort_indexes(const std::vector< T > &v) const
const edm::EDGetTokenT< edm::ValueMap< reco::CandidatePtr > > PuppiCandsMap_
bool isValid() const
Definition: HandleBase.h:74
const edm::EDGetTokenT< edm::ValueMap< float > > PuppiWeightNoLep_
edm::Ref< VertexCollection > VertexRef
persistent reference to a Vertex
Definition: VertexFwd.h:13
reco::MuonRef muonRef() const
Definition: PFCandidate.cc:459
ii
Definition: cuy.py:589
double dz() const
dz parameter (= dsz/cos(lambda)). This is the track z0 w.r.t (0,0,0) only if the refPoint is close to...
Definition: TrackBase.h:609
LostInnerHits
Enumerator specifying the.
const edm::EDGetTokenT< edm::ValueMap< bool > > ChargedHadronIsolation_
edm::Ptr< Candidate > CandidatePtr
persistent reference to an object in a collection of Candidate objects
Definition: CandidateFwd.h:25
T const * product() const
Definition: Handle.h:81
const HitPattern & hitPattern() const
Access the hit pattern, indicating in which Tracker layers the track has hits.
Definition: TrackBase.h:446
const std::vector< int > covariancePackingSchemas_
const edm::EDGetTokenT< std::vector< reco::PFCandidate > > PuppiCandsNoLep_
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
ProductID id() const
Accessor for product ID.
Definition: Ptr.h:180
const edm::EDGetTokenT< reco::VertexCollection > PVOrigs_
int numberOfLostHits(HitCategory category) const
Definition: HitPattern.h:903
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:40
#define begin
Definition: vmac.h:32
reco::GsfTrackRef gsfTrackRef() const
Definition: PFCandidate.cc:480
std::vector< edm::EDGetTokenT< edm::View< reco::Candidate > > > SVWhiteLists_
double hcalEnergy() const
return corrected Hcal energy
Definition: PFCandidate.h:232
int numberOfValidPixelHits() const
Definition: HitPattern.h:839
const_iterator end() const
const edm::EDGetTokenT< edm::Association< reco::VertexCollection > > PVAsso_
const edm::EDGetTokenT< reco::VertexCollection > PVs_
virtual ParticleType particleId() const
Definition: PFCandidate.h:374
uint16_t getHitPattern(HitCategory category, int position) const
Definition: HitPattern.h:516
double phi() const final
momentum azimuthal angle
float timeError() const
Definition: PFCandidate.h:423
def move(src, dest)
Definition: eostools.py:510
double rawHcalEnergy() const
return raw Hcal energy
Definition: PFCandidate.h:235
template<typename T >
std::vector<size_t> pat::PATPackedCandidateProducer::sort_indexes ( const std::vector< T > &  v) const
inline

Definition at line 61 of file PATPackedCandidateProducer.cc.

References candsOrdering(), mps_fire::i, training_settings::idx, and findQualityFiles::v.

Referenced by produce().

61  {
62  std::vector<size_t> idx(v.size());
63  for (size_t i = 0; i != idx.size(); ++i) idx[i] = i;
64  std::sort(idx.begin(), idx.end(),[&v,this](size_t i1, size_t i2) { return candsOrdering(v[i1],v[i2]);});
65  return idx;
66  }
bool candsOrdering(pat::PackedCandidate i, pat::PackedCandidate j) const

Member Data Documentation

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

Definition at line 74 of file PATPackedCandidateProducer.cc.

Referenced by produce().

const edm::EDGetTokenT<edm::ValueMap<bool> > pat::PATPackedCandidateProducer::ChargedHadronIsolation_
private

Definition at line 87 of file PATPackedCandidateProducer.cc.

Referenced by produce().

const std::vector<int> pat::PATPackedCandidateProducer::covariancePackingSchemas_
private

Definition at line 92 of file PATPackedCandidateProducer.cc.

Referenced by produce().

const int pat::PATPackedCandidateProducer::covarianceVersion_
private

Definition at line 91 of file PATPackedCandidateProducer.cc.

Referenced by produce().

const double pat::PATPackedCandidateProducer::minPtForChargedHadronProperties_
private

Definition at line 89 of file PATPackedCandidateProducer.cc.

Referenced by produce().

const double pat::PATPackedCandidateProducer::minPtForTrackProperties_
private

Definition at line 90 of file PATPackedCandidateProducer.cc.

Referenced by produce().

const edm::EDGetTokenT<std::vector< reco::PFCandidate > > pat::PATPackedCandidateProducer::PuppiCands_
private

Definition at line 83 of file PATPackedCandidateProducer.cc.

Referenced by produce().

const edm::EDGetTokenT<edm::ValueMap<reco::CandidatePtr> > pat::PATPackedCandidateProducer::PuppiCandsMap_
private

Definition at line 82 of file PATPackedCandidateProducer.cc.

Referenced by produce().

const edm::EDGetTokenT<std::vector< reco::PFCandidate > > pat::PATPackedCandidateProducer::PuppiCandsNoLep_
private

Definition at line 84 of file PATPackedCandidateProducer.cc.

Referenced by produce().

const edm::EDGetTokenT< edm::ValueMap<float> > pat::PATPackedCandidateProducer::PuppiWeight_
private

Definition at line 80 of file PATPackedCandidateProducer.cc.

Referenced by produce().

const edm::EDGetTokenT< edm::ValueMap<float> > pat::PATPackedCandidateProducer::PuppiWeightNoLep_
private

Definition at line 81 of file PATPackedCandidateProducer.cc.

Referenced by produce().

const edm::EDGetTokenT<edm::Association<reco::VertexCollection> > pat::PATPackedCandidateProducer::PVAsso_
private

Definition at line 76 of file PATPackedCandidateProducer.cc.

Referenced by produce().

const edm::EDGetTokenT<edm::ValueMap<int> > pat::PATPackedCandidateProducer::PVAssoQuality_
private

Definition at line 77 of file PATPackedCandidateProducer.cc.

Referenced by produce().

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

Definition at line 78 of file PATPackedCandidateProducer.cc.

Referenced by produce().

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

Definition at line 75 of file PATPackedCandidateProducer.cc.

Referenced by produce().

const bool pat::PATPackedCandidateProducer::storeChargedHadronIsolation_
private

Definition at line 86 of file PATPackedCandidateProducer.cc.

Referenced by produce().

const bool pat::PATPackedCandidateProducer::storeTiming_
private

Definition at line 94 of file PATPackedCandidateProducer.cc.

Referenced by produce().

std::vector< edm::EDGetTokenT<edm::View<reco::Candidate> > > pat::PATPackedCandidateProducer::SVWhiteLists_
private

Definition at line 85 of file PATPackedCandidateProducer.cc.

Referenced by PATPackedCandidateProducer(), and produce().

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

Definition at line 79 of file PATPackedCandidateProducer.cc.

Referenced by produce().

const bool pat::PATPackedCandidateProducer::usePuppi_
private

Definition at line 72 of file PATPackedCandidateProducer.cc.

Referenced by produce().