CMS 3D CMS Logo

List of all members | Public Member Functions | Static 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

 PATPackedCandidateProducer (const edm::ParameterSet &)
 
void produce (edm::StreamID, edm::Event &, const edm::EventSetup &) const override
 
 ~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
 
ESProxyIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
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)
 
void updateLookup (eventsetup::ESRecordsToProxyIndices const &)
 
virtual ~EDConsumerBase () noexcept(false)
 

Static Public Member Functions

static bool candsOrdering (pat::PackedCandidate const &i, pat::PackedCandidate const &j)
 
template<typename T >
static std::vector< size_t > sort_indexes (const std::vector< T > &v)
 
- Static Public Member Functions inherited from edm::global::EDProducerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 

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 std::vector< int > pfCandidateTypesForHcalDepth_
 
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 storeHcalDepthEndcapOnly_
 
const bool storePfGammaEnFr_
 
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
 
- 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 ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
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 39 of file PATPackedCandidateProducer.cc.

Constructor & Destructor Documentation

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

Definition at line 125 of file PATPackedCandidateProducer.cc.

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

127  : usePuppi_(
128  !iConfig.getParameter<edm::InputTag>("PuppiSrc").encode().empty() ||
129  !iConfig.getParameter<edm::InputTag>("PuppiNoLepSrc")
130  .encode()
131  .empty()),
132  Cands_(consumes<reco::PFCandidateCollection>(
133  iConfig.getParameter<edm::InputTag>("inputCollection"))),
134  PVs_(consumes<reco::VertexCollection>(
135  iConfig.getParameter<edm::InputTag>("inputVertices"))),
137  iConfig.getParameter<edm::InputTag>("vertexAssociator"))),
139  iConfig.getParameter<edm::InputTag>("vertexAssociator"))),
140  PVOrigs_(consumes<reco::VertexCollection>(
141  iConfig.getParameter<edm::InputTag>("originalVertices"))),
142  TKOrigs_(consumes<reco::TrackCollection>(
143  iConfig.getParameter<edm::InputTag>("originalTracks"))),
146  iConfig.getParameter<edm::InputTag>("PuppiSrc"))
147  : edm::EDGetTokenT<edm::ValueMap<float>>()),
149  usePuppi_ ? consumes<edm::ValueMap<float>>(
150  iConfig.getParameter<edm::InputTag>("PuppiNoLepSrc"))
151  : edm::EDGetTokenT<edm::ValueMap<float>>()),
153  usePuppi_ ? consumes<edm::ValueMap<reco::CandidatePtr>>(
154  iConfig.getParameter<edm::InputTag>("PuppiSrc"))
155  : edm::EDGetTokenT<edm::ValueMap<reco::CandidatePtr>>()),
157  ? consumes<std::vector<reco::PFCandidate>>(
158  iConfig.getParameter<edm::InputTag>("PuppiSrc"))
159  : edm::EDGetTokenT<std::vector<reco::PFCandidate>>()),
161  usePuppi_ ? consumes<std::vector<reco::PFCandidate>>(
162  iConfig.getParameter<edm::InputTag>("PuppiNoLepSrc"))
163  : edm::EDGetTokenT<std::vector<reco::PFCandidate>>()),
165  !iConfig.getParameter<edm::InputTag>("chargedHadronIsolation")
166  .encode()
167  .empty()),
169  iConfig.getParameter<edm::InputTag>("chargedHadronIsolation"))),
171  iConfig.getParameter<double>("minPtForChargedHadronProperties")),
173  iConfig.getParameter<double>("minPtForTrackProperties")),
174  covarianceVersion_(iConfig.getParameter<int>("covarianceVersion")),
176  iConfig.getParameter<std::vector<int>>("covariancePackingSchemas")),
177  pfCandidateTypesForHcalDepth_(iConfig.getParameter<std::vector<int>>(
178  "pfCandidateTypesForHcalDepth")),
180  iConfig.getParameter<bool>("storeHcalDepthEndcapOnly")),
181  storeTiming_(iConfig.getParameter<bool>("storeTiming")),
182  storePfGammaEnFr_(iConfig.getParameter<bool>("storePfGammaEnFractions")) {
183  std::vector<edm::InputTag> sv_tags =
184  iConfig.getParameter<std::vector<edm::InputTag>>(
185  "secondaryVerticesForWhiteList");
186  for (const auto &itag : sv_tags) {
188  }
189 
190  produces<std::vector<pat::PackedCandidate>>();
191  produces<edm::Association<pat::PackedCandidateCollection>>();
192  produces<edm::Association<reco::PFCandidateCollection>>();
193 
194  if (not pfCandidateTypesForHcalDepth_.empty())
196  "hcalDepthEnergyFractions");
197 }
BranchAliasSetterT< ProductType > produces()
declare what type of product will make and with which optional label
T getParameter(std::string const &) const
const edm::EDGetTokenT< std::vector< reco::PFCandidate > > PuppiCandsNoLep_
const edm::EDGetTokenT< reco::PFCandidateCollection > Cands_
std::string encode() const
Definition: InputTag.cc:159
const edm::EDGetTokenT< edm::ValueMap< int > > PVAssoQuality_
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
const edm::EDGetTokenT< edm::ValueMap< float > > PuppiWeightNoLep_
const edm::EDGetTokenT< std::vector< reco::PFCandidate > > PuppiCands_
const edm::EDGetTokenT< reco::TrackCollection > TKOrigs_
const edm::EDGetTokenT< edm::ValueMap< reco::CandidatePtr > > PuppiCandsMap_
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_
def encode(args, files)
const edm::EDGetTokenT< edm::ValueMap< float > > PuppiWeight_
const edm::EDGetTokenT< reco::VertexCollection > PVOrigs_
std::vector< edm::EDGetTokenT< edm::View< reco::Candidate > > > SVWhiteLists_
fixed size matrix
HLT enums.
const std::vector< int > pfCandidateTypesForHcalDepth_
const edm::EDGetTokenT< edm::Association< reco::VertexCollection > > PVAsso_
const edm::EDGetTokenT< reco::VertexCollection > PVs_
pat::PATPackedCandidateProducer::~PATPackedCandidateProducer ( )
override

Definition at line 199 of file PATPackedCandidateProducer.cc.

199 {}

Member Function Documentation

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

Definition at line 113 of file PATPackedCandidateProducer.cc.

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

113  {
114  return -dx * std::sin(phi) + dy * std::cos(phi);
115  }
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 116 of file PATPackedCandidateProducer.cc.

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

117  {
118  return p.Z() - v.Z() -
119  ((p.X() - v.X()) * c.px() + (p.Y() - v.Y()) * c.py()) * c.pz() /
120  (c.pt() * c.pt());
121  }
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
static bool pat::PATPackedCandidateProducer::candsOrdering ( pat::PackedCandidate const &  i,
pat::PackedCandidate const &  j 
)
inlinestatic

Definition at line 48 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().

49  {
50  if (std::abs(i.charge()) == std::abs(j.charge())) {
51  if (i.charge() != 0) {
52  if (i.hasTrackDetails() and !j.hasTrackDetails())
53  return true;
54  if (!i.hasTrackDetails() and j.hasTrackDetails())
55  return false;
56  if (i.covarianceSchema() > j.covarianceSchema())
57  return true;
58  if (i.covarianceSchema() < j.covarianceSchema())
59  return false;
60  }
61  if (i.vertexRef() == j.vertexRef())
62  return i.eta() > j.eta();
63  else
64  return i.vertexRef().key() < j.vertexRef().key();
65  }
66  return std::abs(i.charge()) > std::abs(j.charge());
67  }
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void pat::PATPackedCandidateProducer::produce ( edm::StreamID  ,
edm::Event iEvent,
const edm::EventSetup iSetup 
) const
override

Definition at line 201 of file PATPackedCandidateProducer.cc.

References funct::abs(), begin, EnergyCorrector::c, egammaForCoreTracking_cff::cands, Cands_, reco::LeafCandidate::charge(), 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(), spr::find(), reco::PFCandidate::gamma, edm::Event::getByToken(), reco::HitPattern::getHitPattern(), reco::PFCandidate::gsfTrackRef(), reco::HitPattern::hasValidHitInPixelLayer(), reco::PFCandidate::hcalDepthEnergyFractions(), 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(), pfCandidateTypesForHcalDepth_, 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(), pat::HcalDepthEnergyFractions::reset(), edm::View< T >::size(), sort_indexes(), storeChargedHadronIsolation_, storeHcalDepthEndcapOnly_, storePfGammaEnFr_, 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 extraflags_cff::vtx.

202  {
204  iEvent.getByToken(Cands_, cands);
205 
209  edm::Handle<edm::ValueMap<float>> puppiWeightNoLep;
211  std::vector<reco::CandidatePtr> puppiCandsNoLepPtrs;
212  if (usePuppi_) {
213  iEvent.getByToken(PuppiWeight_, puppiWeight);
214  iEvent.getByToken(PuppiCandsMap_, puppiCandsMap);
215  iEvent.getByToken(PuppiCands_, puppiCands);
216  iEvent.getByToken(PuppiWeightNoLep_, puppiWeightNoLep);
217  iEvent.getByToken(PuppiCandsNoLep_, puppiCandsNoLep);
218  for (auto pup : *puppiCandsNoLep) {
219  puppiCandsNoLepPtrs.push_back(pup.sourceCandidatePtr(0));
220  }
221  }
222  std::vector<int> mappingPuppi(usePuppi_ ? puppiCands->size() : 0);
223 
225  iEvent.getByToken(PVOrigs_, PVOrigs);
226 
228  iEvent.getByToken(PVAsso_, assoHandle);
229  edm::Handle<edm::ValueMap<int>> assoQualityHandle;
230  iEvent.getByToken(PVAssoQuality_, assoQualityHandle);
231  const edm::Association<reco::VertexCollection> &associatedPV =
232  *(assoHandle.product());
233  const edm::ValueMap<int> &associationQuality = *(assoQualityHandle.product());
234 
235  edm::Handle<edm::ValueMap<bool>> chargedHadronIsolationHandle;
237  iEvent.getByToken(ChargedHadronIsolation_, chargedHadronIsolationHandle);
238 
239  std::set<unsigned int> whiteList;
240  std::set<reco::TrackRef> whiteListTk;
241  for (auto itoken : SVWhiteLists_) {
242  edm::Handle<edm::View<reco::Candidate>> svWhiteListHandle;
243  iEvent.getByToken(itoken, svWhiteListHandle);
244  const edm::View<reco::Candidate> &svWhiteList =
245  *(svWhiteListHandle.product());
246  for (unsigned int i = 0; i < svWhiteList.size(); i++) {
247  // Whitelist via Ptrs
248  for (unsigned int j = 0; j < svWhiteList[i].numberOfSourceCandidatePtrs();
249  j++) {
251  svWhiteList[i].sourceCandidatePtr(j);
252  if (c.id() == cands.id())
253  whiteList.insert(c.key());
254  }
255  // Whitelist via RecoCharged
256  for (auto dau = svWhiteList[i].begin(); dau != svWhiteList[i].end();
257  dau++) {
258  const reco::RecoChargedCandidate *chCand =
259  dynamic_cast<const reco::RecoChargedCandidate *>(&(*dau));
260  if (chCand != nullptr) {
261  whiteListTk.insert(chCand->track());
262  }
263  }
264  }
265  }
266 
268  iEvent.getByToken(PVs_, PVs);
269  reco::VertexRef PV(PVs.id());
270  reco::VertexRefProd PVRefProd(PVs);
271  math::XYZPoint PVpos;
272 
273  std::vector<pat::HcalDepthEnergyFractions> hcalDepthEnergyFractions;
274  hcalDepthEnergyFractions.reserve(cands->size());
275  std::vector<pat::HcalDepthEnergyFractions> hcalDepthEnergyFractions_Ordered;
276  hcalDepthEnergyFractions_Ordered.reserve(cands->size());
277 
279  iEvent.getByToken(TKOrigs_, TKOrigs);
280  auto outPtrP = std::make_unique<std::vector<pat::PackedCandidate>>();
281  std::vector<int> mapping(cands->size());
282  std::vector<int> mappingReverse(cands->size());
283  std::vector<int> mappingTk(TKOrigs->size(), -1);
284 
285  for (unsigned int ic = 0, nc = cands->size(); ic < nc; ++ic) {
286  const reco::PFCandidate &cand = (*cands)[ic];
287  const reco::Track *ctrack = nullptr;
288  if ((abs(cand.pdgId()) == 11 || cand.pdgId() == 22) &&
289  cand.gsfTrackRef().isNonnull()) {
290  ctrack = &*cand.gsfTrackRef();
291  } else if (cand.trackRef().isNonnull()) {
292  ctrack = &*cand.trackRef();
293  }
294  if (ctrack) {
295  float dist = 1e99;
296  int pvi = -1;
297  for (size_t ii = 0; ii < PVs->size(); ii++) {
298  float dz = std::abs(ctrack->dz(((*PVs)[ii]).position()));
299  if (dz < dist) {
300  pvi = ii;
301  dist = dz;
302  }
303  }
304  PV = reco::VertexRef(PVs, pvi);
305  math::XYZPoint vtx = cand.vertex();
308  const reco::VertexRef &PVOrig =
309  associatedPV[reco::CandidatePtr(cands, ic)];
310  if (PVOrig.isNonnull())
312  PVs,
313  PVOrig
314  .key()); // WARNING: assume the PV slimmer is keeping same order
315  int quality = associationQuality[reco::CandidatePtr(cands, ic)];
316  // if ((size_t)pvi!=PVOrig.key()) std::cout << "not closest in Z"
317  // << pvi << " " << PVOrig.key() << " " << cand.pt() << " " <<
318  // quality << std::endl; TrajectoryStateOnSurface tsos =
319  // extrapolator.extrapolate(trajectoryStateTransform::initialFreeState(*ctrack,&*magneticField),
320  // RecoVertex::convertPos(PV->position()));
321  // vtx = tsos.globalPosition();
322  // phiAtVtx = tsos.globalDirection().phi();
323  vtx = ctrack->referencePoint();
324  float ptTrk = ctrack->pt();
325  float etaAtVtx = ctrack->eta();
326  float phiAtVtx = ctrack->phi();
327 
328  int nlost = ctrack->hitPattern().numberOfLostHits(
330  if (nlost == 0) {
331  if (ctrack->hitPattern().hasValidHitInPixelLayer(
334  }
335  } else {
336  lostHits = (nlost == 1 ? pat::PackedCandidate::oneLostInnerHit
338  }
339 
340  outPtrP->push_back(pat::PackedCandidate(cand.polarP4(), vtx, ptTrk,
341  etaAtVtx, phiAtVtx, cand.pdgId(),
342  PVRefProd, PV.key()));
343  outPtrP->back().setAssociationQuality(
345  outPtrP->back().setCovarianceVersion(covarianceVersion_);
346  if (cand.trackRef().isNonnull() && PVOrig.isNonnull() &&
347  PVOrig->trackWeight(cand.trackRef()) > 0.5 && quality == 7) {
348  outPtrP->back().setAssociationQuality(
350  }
351  // properties of the best track
352  outPtrP->back().setLostInnerHits(lostHits);
353  if (outPtrP->back().pt() > minPtForTrackProperties_ ||
354  outPtrP->back().ptTrk() > minPtForTrackProperties_ ||
355  whiteList.find(ic) != whiteList.end() ||
356  (cand.trackRef().isNonnull() &&
357  whiteListTk.find(cand.trackRef()) != whiteListTk.end())) {
358  outPtrP->back().setFirstHit(ctrack->hitPattern().getHitPattern(
360  if (abs(outPtrP->back().pdgId()) == 22) {
361  outPtrP->back().setTrackProperties(
363  } else {
364  if (ctrack->hitPattern().numberOfValidPixelHits() > 0) {
365  outPtrP->back().setTrackProperties(
366  *ctrack, covariancePackingSchemas_[0],
367  covarianceVersion_); // high quality
368  } else {
369  outPtrP->back().setTrackProperties(
371  }
372  }
373  // outPtrP->back().setTrackProperties(*ctrack,tsos.curvilinearError());
374  } else {
375  if (outPtrP->back().pt() > 0.5) {
376  if (ctrack->hitPattern().numberOfValidPixelHits() > 0)
377  outPtrP->back().setTrackProperties(
378  *ctrack, covariancePackingSchemas_[2],
379  covarianceVersion_); // low quality, with pixels
380  else
381  outPtrP->back().setTrackProperties(
382  *ctrack, covariancePackingSchemas_[3],
383  covarianceVersion_); // low quality, without pixels
384  }
385  }
386 
387  // these things are always for the CKF track
388  outPtrP->back().setTrackHighPurity(
389  cand.trackRef().isNonnull() &&
390  cand.trackRef()->quality(reco::Track::highPurity));
391  if (cand.muonRef().isNonnull()) {
392  outPtrP->back().setMuonID(cand.muonRef()->isStandAloneMuon(),
393  cand.muonRef()->isGlobalMuon());
394  }
395  } else {
396  if (!PVs->empty()) {
397  PV = reco::VertexRef(PVs, 0);
398  PVpos = PV->position();
399  }
400 
401  outPtrP->push_back(
402  pat::PackedCandidate(cand.polarP4(), PVpos, cand.pt(), cand.eta(),
403  cand.phi(), cand.pdgId(), PVRefProd, PV.key()));
404  outPtrP->back().setAssociationQuality(
407  }
408 
409  // neutrals and isolated charged hadrons
410 
411  bool isIsolatedChargedHadron = false;
414  *(chargedHadronIsolationHandle.product());
415  isIsolatedChargedHadron =
416  ((cand.pt() > minPtForChargedHadronProperties_) &&
417  (chargedHadronIsolation[reco::PFCandidateRef(cands, ic)]));
418  outPtrP->back().setIsIsolatedChargedHadron(isIsolatedChargedHadron);
419  }
420 
421  if (abs(cand.pdgId()) == 1 || abs(cand.pdgId()) == 130) {
422  outPtrP->back().setHcalFraction(cand.hcalEnergy() /
423  (cand.ecalEnergy() + cand.hcalEnergy()));
424  } else if ((cand.charge() || (storePfGammaEnFr_ && cand.pdgId() == 22)) && cand.pt() > 0.5) {
425  outPtrP->back().setHcalFraction(cand.hcalEnergy() /
426  (cand.ecalEnergy() + cand.hcalEnergy()));
427  outPtrP->back().setCaloFraction((cand.hcalEnergy() + cand.ecalEnergy()) /
428  cand.energy());
429  } else {
430  outPtrP->back().setHcalFraction(0);
431  outPtrP->back().setCaloFraction(0);
432  }
433 
434  if (isIsolatedChargedHadron) {
435  outPtrP->back().setRawCaloFraction(
436  (cand.rawEcalEnergy() + cand.rawHcalEnergy()) / cand.energy());
437  outPtrP->back().setRawHcalFraction(
438  cand.rawHcalEnergy() / (cand.rawEcalEnergy() + cand.rawHcalEnergy()));
439  } else {
440  outPtrP->back().setRawCaloFraction(0);
441  outPtrP->back().setRawHcalFraction(0);
442  }
443 
444  std::vector<float> dummyVector;
445  dummyVector.clear();
446  pat::HcalDepthEnergyFractions hcalDepthEFrac(dummyVector);
447 
448  // storing HcalDepthEnergyFraction information
451  abs(cand.pdgId())) != pfCandidateTypesForHcalDepth_.end()) {
453  fabs(outPtrP->back().eta()) >
454  1.3) { // storeHcalDepthEndcapOnly_==false -> store all eta of
455  // selected PF types, if true, only |eta|>1.3 of selected
456  // PF types will be stored
457  std::vector<float> hcalDepthEnergyFractionTmp(
458  cand.hcalDepthEnergyFractions().begin(),
459  cand.hcalDepthEnergyFractions().end());
460  hcalDepthEFrac.reset(hcalDepthEnergyFractionTmp);
461  }
462  }
463  hcalDepthEnergyFractions.push_back(hcalDepthEFrac);
464 
465  // specifically this is the PFLinker requirements to apply the e/gamma
466  // regression
467  if (cand.particleId() == reco::PFCandidate::e ||
469  cand.mva_nothing_gamma() > 0.)) {
470  outPtrP->back().setGoodEgamma();
471  }
472 
473  if (usePuppi_) {
474  reco::PFCandidateRef pkref(cands, ic);
475  // outPtrP->back().setPuppiWeight( (*puppiWeight)[pkref]);
476 
477  float puppiWeightVal = (*puppiWeight)[pkref];
478  float puppiWeightNoLepVal = 0.0;
479  // Check the "no lepton" puppi weights.
480  // If present, then it is not a lepton, use stored weight
481  // If absent, it is a lepton, so set the weight to 1.0
482  if (puppiWeightNoLep.isValid()) {
483  // Look for the pointer inside the "no lepton" candidate collection.
484  auto pkrefPtr = pkref->sourceCandidatePtr(0);
485 
486  bool foundNoLep = false;
487  for (size_t ipcnl = 0; ipcnl < puppiCandsNoLepPtrs.size(); ipcnl++) {
488  if (puppiCandsNoLepPtrs[ipcnl] == pkrefPtr) {
489  foundNoLep = true;
490  puppiWeightNoLepVal =
491  puppiCandsNoLep->at(ipcnl).pt() /
492  cand.pt(); // a hack for now, should use the value map
493  break;
494  }
495  }
496  if (!foundNoLep || puppiWeightNoLepVal > 1) {
497  puppiWeightNoLepVal = 1.0;
498  }
499  }
500  outPtrP->back().setPuppiWeight(puppiWeightVal, puppiWeightNoLepVal);
501 
502  mappingPuppi[((*puppiCandsMap)[pkref]).key()] = ic;
503  }
504 
505  if (storeTiming_ && cand.isTimeValid()) {
506  outPtrP->back().setTime(cand.time(), cand.timeError());
507  }
508 
509  mapping[ic] = ic; // trivial at the moment!
510  if (cand.trackRef().isNonnull() && cand.trackRef().id() == TKOrigs.id()) {
511  mappingTk[cand.trackRef().key()] = ic;
512  }
513  }
514 
515  auto outPtrPSorted = std::make_unique<std::vector<pat::PackedCandidate>>();
516  std::vector<size_t> order = sort_indexes(*outPtrP);
517  std::vector<size_t> reverseOrder(order.size());
518  for (size_t i = 0, nc = cands->size(); i < nc; i++) {
519  outPtrPSorted->push_back((*outPtrP)[order[i]]);
520  reverseOrder[order[i]] = i;
521  mappingReverse[order[i]] = i;
522  hcalDepthEnergyFractions_Ordered.push_back(
523  hcalDepthEnergyFractions[order[i]]);
524  }
525 
526  // Fix track association for sorted candidates
527  for (size_t i = 0, ntk = mappingTk.size(); i < ntk; i++) {
528  if (mappingTk[i] >= 0)
529  mappingTk[i] = reverseOrder[mappingTk[i]];
530  }
531 
532  for (size_t i = 0, ntk = mappingPuppi.size(); i < ntk; i++) {
533  mappingPuppi[i] = reverseOrder[mappingPuppi[i]];
534  }
535 
537  iEvent.put(std::move(outPtrPSorted));
538 
539  // now build the two maps
540  auto pf2pc =
541  std::make_unique<edm::Association<pat::PackedCandidateCollection>>(oh);
542  auto pc2pf =
543  std::make_unique<edm::Association<reco::PFCandidateCollection>>(cands);
546  pf2pcFiller.insert(cands, mappingReverse.begin(), mappingReverse.end());
547  pc2pfFiller.insert(oh, order.begin(), order.end());
548  // include also the mapping track -> packed PFCand
549  pf2pcFiller.insert(TKOrigs, mappingTk.begin(), mappingTk.end());
550  if (usePuppi_)
551  pf2pcFiller.insert(puppiCands, mappingPuppi.begin(), mappingPuppi.end());
552 
553  pf2pcFiller.fill();
554  pc2pfFiller.fill();
555  iEvent.put(std::move(pf2pc));
556  iEvent.put(std::move(pc2pf));
557 
558  // HCAL depth energy fraction additions using ValueMap
559  auto hcalDepthEnergyFractionsV =
560  std::make_unique<edm::ValueMap<HcalDepthEnergyFractions>>();
562  fillerHcalDepthEnergyFractions(*hcalDepthEnergyFractionsV);
563  fillerHcalDepthEnergyFractions.insert(
564  cands, hcalDepthEnergyFractions_Ordered.begin(),
565  hcalDepthEnergyFractions_Ordered.end());
566  fillerHcalDepthEnergyFractions.fill();
567 
568  if (not pfCandidateTypesForHcalDepth_.empty())
569  iEvent.put(std::move(hcalDepthEnergyFractionsV),
570  "hcalDepthEnergyFractions");
571 }
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:720
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:251
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:365
key_type key() const
Definition: Ptr.h:185
const edm::EDGetTokenT< std::vector< reco::PFCandidate > > PuppiCandsNoLep_
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:517
const std::array< float, 7 > & hcalDepthEnergyFractions() const
fraction of hcal energy at a given depth (index 0..6 for depth 1..7)
Definition: PFCandidate.h:430
size_type size() const
double phi() const
azimuthal angle of momentum vector
Definition: TrackBase.h:684
double pt() const final
transverse momentum
int charge() const final
electric charge
Definition: LeafCandidate.h:91
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:263
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
ProductID id() const
Accessor for product ID.
Definition: Ref.h:257
const edm::EDGetTokenT< edm::ValueMap< int > > PVAssoQuality_
const edm::EDGetTokenT< edm::ValueMap< float > > PuppiWeightNoLep_
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:690
double pt() const
track transverse momentum
Definition: TrackBase.h:660
double energy() const final
energy
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const edm::EDGetTokenT< std::vector< reco::PFCandidate > > PuppiCands_
reco::TrackRef track() const override
reference to a track
static std::vector< size_t > sort_indexes(const std::vector< T > &v)
const edm::EDGetTokenT< reco::TrackCollection > TKOrigs_
const edm::EDGetTokenT< edm::ValueMap< reco::CandidatePtr > > PuppiCandsMap_
bool isValid() const
Definition: HandleBase.h:74
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:590
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:648
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:74
const HitPattern & hitPattern() const
Access the hit pattern, indicating in which Tracker layers the track has hits.
Definition: TrackBase.h:485
const std::vector< int > covariancePackingSchemas_
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< edm::ValueMap< float > > PuppiWeight_
const edm::EDGetTokenT< reco::VertexCollection > PVOrigs_
int numberOfLostHits(HitCategory category) const
Definition: HitPattern.h:990
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:40
std::vector< edm::EDGetTokenT< edm::View< reco::Candidate > > > SVWhiteLists_
#define begin
Definition: vmac.h:32
reco::GsfTrackRef gsfTrackRef() const
Definition: PFCandidate.cc:480
const std::vector< int > pfCandidateTypesForHcalDepth_
double hcalEnergy() const
return corrected Hcal energy
Definition: PFCandidate.h:232
int numberOfValidPixelHits() const
Definition: HitPattern.h:916
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:553
double phi() const final
momentum azimuthal angle
float timeError() const
Definition: PFCandidate.h:423
def move(src, dest)
Definition: eostools.py:511
double rawHcalEnergy() const
return raw Hcal energy
Definition: PFCandidate.h:235
template<typename T >
static std::vector<size_t> pat::PATPackedCandidateProducer::sort_indexes ( const std::vector< T > &  v)
inlinestatic

Definition at line 70 of file PATPackedCandidateProducer.cc.

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

Referenced by produce().

70  {
71  std::vector<size_t> idx(v.size());
72  for (size_t i = 0; i != idx.size(); ++i)
73  idx[i] = i;
74  std::sort(idx.begin(), idx.end(), [&v](size_t i1, size_t i2) {
75  return candsOrdering(v[i1], v[i2]);
76  });
77  return idx;
78  }
static bool candsOrdering(pat::PackedCandidate const &i, pat::PackedCandidate const &j)

Member Data Documentation

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

Definition at line 86 of file PATPackedCandidateProducer.cc.

Referenced by produce().

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

Definition at line 99 of file PATPackedCandidateProducer.cc.

Referenced by produce().

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

Definition at line 104 of file PATPackedCandidateProducer.cc.

Referenced by produce().

const int pat::PATPackedCandidateProducer::covarianceVersion_
private

Definition at line 103 of file PATPackedCandidateProducer.cc.

Referenced by produce().

const double pat::PATPackedCandidateProducer::minPtForChargedHadronProperties_
private

Definition at line 101 of file PATPackedCandidateProducer.cc.

Referenced by produce().

const double pat::PATPackedCandidateProducer::minPtForTrackProperties_
private

Definition at line 102 of file PATPackedCandidateProducer.cc.

Referenced by produce().

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

Definition at line 106 of file PATPackedCandidateProducer.cc.

Referenced by PATPackedCandidateProducer(), and produce().

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

Definition at line 95 of file PATPackedCandidateProducer.cc.

Referenced by produce().

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

Definition at line 94 of file PATPackedCandidateProducer.cc.

Referenced by produce().

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

Definition at line 96 of file PATPackedCandidateProducer.cc.

Referenced by produce().

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

Definition at line 92 of file PATPackedCandidateProducer.cc.

Referenced by produce().

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

Definition at line 93 of file PATPackedCandidateProducer.cc.

Referenced by produce().

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

Definition at line 88 of file PATPackedCandidateProducer.cc.

Referenced by produce().

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

Definition at line 89 of file PATPackedCandidateProducer.cc.

Referenced by produce().

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

Definition at line 90 of file PATPackedCandidateProducer.cc.

Referenced by produce().

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

Definition at line 87 of file PATPackedCandidateProducer.cc.

Referenced by produce().

const bool pat::PATPackedCandidateProducer::storeChargedHadronIsolation_
private

Definition at line 98 of file PATPackedCandidateProducer.cc.

Referenced by produce().

const bool pat::PATPackedCandidateProducer::storeHcalDepthEndcapOnly_
private

Definition at line 107 of file PATPackedCandidateProducer.cc.

Referenced by produce().

const bool pat::PATPackedCandidateProducer::storePfGammaEnFr_
private

Definition at line 110 of file PATPackedCandidateProducer.cc.

Referenced by produce().

const bool pat::PATPackedCandidateProducer::storeTiming_
private

Definition at line 109 of file PATPackedCandidateProducer.cc.

Referenced by produce().

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

Definition at line 97 of file PATPackedCandidateProducer.cc.

Referenced by PATPackedCandidateProducer(), and produce().

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

Definition at line 91 of file PATPackedCandidateProducer.cc.

Referenced by produce().

const bool pat::PATPackedCandidateProducer::usePuppi_
private

Definition at line 84 of file PATPackedCandidateProducer.cc.

Referenced by produce().