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 hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndRuns () 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 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::ProducerBase
ProducesCollector producesCollector ()
 
- 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 115 of file PATPackedCandidateProducer.cc.

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

116  : usePuppi_(!iConfig.getParameter<edm::InputTag>("PuppiSrc").encode().empty() ||
117  !iConfig.getParameter<edm::InputTag>("PuppiNoLepSrc").encode().empty()),
118  Cands_(consumes<reco::PFCandidateCollection>(iConfig.getParameter<edm::InputTag>("inputCollection"))),
119  PVs_(consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("inputVertices"))),
120  PVAsso_(
122  PVAssoQuality_(consumes<edm::ValueMap<int>>(iConfig.getParameter<edm::InputTag>("vertexAssociator"))),
123  PVOrigs_(consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("originalVertices"))),
124  TKOrigs_(consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("originalTracks"))),
126  : edm::EDGetTokenT<edm::ValueMap<float>>()),
127  PuppiWeightNoLep_(usePuppi_ ? consumes<edm::ValueMap<float>>(iConfig.getParameter<edm::InputTag>("PuppiNoLepSrc"))
128  : edm::EDGetTokenT<edm::ValueMap<float>>()),
130  ? consumes<edm::ValueMap<reco::CandidatePtr>>(iConfig.getParameter<edm::InputTag>("PuppiSrc"))
131  : edm::EDGetTokenT<edm::ValueMap<reco::CandidatePtr>>()),
132  PuppiCands_(usePuppi_ ? consumes<std::vector<reco::PFCandidate>>(iConfig.getParameter<edm::InputTag>("PuppiSrc"))
133  : edm::EDGetTokenT<std::vector<reco::PFCandidate>>()),
135  usePuppi_ ? consumes<std::vector<reco::PFCandidate>>(iConfig.getParameter<edm::InputTag>("PuppiNoLepSrc"))
136  : edm::EDGetTokenT<std::vector<reco::PFCandidate>>()),
137  storeChargedHadronIsolation_(!iConfig.getParameter<edm::InputTag>("chargedHadronIsolation").encode().empty()),
139  consumes<edm::ValueMap<bool>>(iConfig.getParameter<edm::InputTag>("chargedHadronIsolation"))),
140  minPtForChargedHadronProperties_(iConfig.getParameter<double>("minPtForChargedHadronProperties")),
141  minPtForTrackProperties_(iConfig.getParameter<double>("minPtForTrackProperties")),
142  covarianceVersion_(iConfig.getParameter<int>("covarianceVersion")),
143  covariancePackingSchemas_(iConfig.getParameter<std::vector<int>>("covariancePackingSchemas")),
144  pfCandidateTypesForHcalDepth_(iConfig.getParameter<std::vector<int>>("pfCandidateTypesForHcalDepth")),
145  storeHcalDepthEndcapOnly_(iConfig.getParameter<bool>("storeHcalDepthEndcapOnly")),
146  storeTiming_(iConfig.getParameter<bool>("storeTiming")) {
147  std::vector<edm::InputTag> sv_tags =
148  iConfig.getParameter<std::vector<edm::InputTag>>("secondaryVerticesForWhiteList");
149  for (auto itag : sv_tags) {
151  }
152 
153  produces<std::vector<pat::PackedCandidate>>();
154  produces<edm::Association<pat::PackedCandidateCollection>>();
155  produces<edm::Association<reco::PFCandidateCollection>>();
156 
157  if (not pfCandidateTypesForHcalDepth_.empty())
158  produces<edm::ValueMap<pat::HcalDepthEnergyFractions>>("hcalDepthEnergyFractions");
159 }
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 161 of file PATPackedCandidateProducer.cc.

161 {}

Member Function Documentation

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

Definition at line 108 of file PATPackedCandidateProducer.cc.

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

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

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

109  {
110  return p.Z() - v.Z() - ((p.X() - v.X()) * c.px() + (p.Y() - v.Y()) * c.py()) * c.pz() / (c.pt() * c.pt());
111  }
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 47 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().

47  {
48  if (std::abs(i.charge()) == std::abs(j.charge())) {
49  if (i.charge() != 0) {
50  if (i.hasTrackDetails() and !j.hasTrackDetails())
51  return true;
52  if (!i.hasTrackDetails() and j.hasTrackDetails())
53  return false;
54  if (i.covarianceSchema() > j.covarianceSchema())
55  return true;
56  if (i.covarianceSchema() < j.covarianceSchema())
57  return false;
58  }
59  if (i.vertexRef() == j.vertexRef())
60  return i.eta() > j.eta();
61  else
62  return i.vertexRef().key() < j.vertexRef().key();
63  }
64  return std::abs(i.charge()) > std::abs(j.charge());
65  }
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 163 of file PATPackedCandidateProducer.cc.

References funct::abs(), begin, HltBtagPostValidation_cff::c, HLT_2018_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(), dqmiolumiharvest::j, 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, eventshapeDQM_cfi::order, 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_, qcdUeDQM_cfi::quality, pat::qualityMap, reco::PFCandidate::rawEcalEnergy(), reco::PFCandidate::rawHcalEnergy(), reco::TrackBase::referencePoint(), pat::HcalDepthEnergyFractions::reset(), edm::View< T >::size(), sort_indexes(), storeChargedHadronIsolation_, storeHcalDepthEndcapOnly_, 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.

163  {
165  iEvent.getByToken(Cands_, cands);
166 
170  edm::Handle<edm::ValueMap<float>> puppiWeightNoLep;
172  std::vector<reco::CandidatePtr> puppiCandsNoLepPtrs;
173  if (usePuppi_) {
174  iEvent.getByToken(PuppiWeight_, puppiWeight);
175  iEvent.getByToken(PuppiCandsMap_, puppiCandsMap);
176  iEvent.getByToken(PuppiCands_, puppiCands);
177  iEvent.getByToken(PuppiWeightNoLep_, puppiWeightNoLep);
178  iEvent.getByToken(PuppiCandsNoLep_, puppiCandsNoLep);
179  for (auto pup : *puppiCandsNoLep) {
180  puppiCandsNoLepPtrs.push_back(pup.sourceCandidatePtr(0));
181  }
182  }
183  std::vector<int> mappingPuppi(usePuppi_ ? puppiCands->size() : 0);
184 
186  iEvent.getByToken(PVOrigs_, PVOrigs);
187 
189  iEvent.getByToken(PVAsso_, assoHandle);
190  edm::Handle<edm::ValueMap<int>> assoQualityHandle;
191  iEvent.getByToken(PVAssoQuality_, assoQualityHandle);
192  const edm::Association<reco::VertexCollection> &associatedPV = *(assoHandle.product());
193  const edm::ValueMap<int> &associationQuality = *(assoQualityHandle.product());
194 
195  edm::Handle<edm::ValueMap<bool>> chargedHadronIsolationHandle;
197  iEvent.getByToken(ChargedHadronIsolation_, chargedHadronIsolationHandle);
198 
199  std::set<unsigned int> whiteList;
200  std::set<reco::TrackRef> whiteListTk;
201  for (auto itoken : SVWhiteLists_) {
202  edm::Handle<edm::View<reco::Candidate>> svWhiteListHandle;
203  iEvent.getByToken(itoken, svWhiteListHandle);
204  const edm::View<reco::Candidate> &svWhiteList = *(svWhiteListHandle.product());
205  for (unsigned int i = 0; i < svWhiteList.size(); i++) {
206  // Whitelist via Ptrs
207  for (unsigned int j = 0; j < svWhiteList[i].numberOfSourceCandidatePtrs(); j++) {
208  const edm::Ptr<reco::Candidate> &c = svWhiteList[i].sourceCandidatePtr(j);
209  if (c.id() == cands.id())
210  whiteList.insert(c.key());
211  }
212  // Whitelist via RecoCharged
213  for (auto dau = svWhiteList[i].begin(); dau != svWhiteList[i].end(); dau++) {
214  const reco::RecoChargedCandidate *chCand = dynamic_cast<const reco::RecoChargedCandidate *>(&(*dau));
215  if (chCand != nullptr) {
216  whiteListTk.insert(chCand->track());
217  }
218  }
219  }
220  }
221 
223  iEvent.getByToken(PVs_, PVs);
224  reco::VertexRef PV(PVs.id());
225  reco::VertexRefProd PVRefProd(PVs);
226  math::XYZPoint PVpos;
227 
228  std::vector<pat::HcalDepthEnergyFractions> hcalDepthEnergyFractions;
229  hcalDepthEnergyFractions.reserve(cands->size());
230  std::vector<pat::HcalDepthEnergyFractions> hcalDepthEnergyFractions_Ordered;
231  hcalDepthEnergyFractions_Ordered.reserve(cands->size());
232 
234  iEvent.getByToken(TKOrigs_, TKOrigs);
235  auto outPtrP = std::make_unique<std::vector<pat::PackedCandidate>>();
236  std::vector<int> mapping(cands->size());
237  std::vector<int> mappingReverse(cands->size());
238  std::vector<int> mappingTk(TKOrigs->size(), -1);
239 
240  for (unsigned int ic = 0, nc = cands->size(); ic < nc; ++ic) {
241  const reco::PFCandidate &cand = (*cands)[ic];
242  const reco::Track *ctrack = nullptr;
243  if ((abs(cand.pdgId()) == 11 || cand.pdgId() == 22) && cand.gsfTrackRef().isNonnull()) {
244  ctrack = &*cand.gsfTrackRef();
245  } else if (cand.trackRef().isNonnull()) {
246  ctrack = &*cand.trackRef();
247  }
248  if (ctrack) {
249  float dist = 1e99;
250  int pvi = -1;
251  for (size_t ii = 0; ii < PVs->size(); ii++) {
252  float dz = std::abs(ctrack->dz(((*PVs)[ii]).position()));
253  if (dz < dist) {
254  pvi = ii;
255  dist = dz;
256  }
257  }
258  PV = reco::VertexRef(PVs, pvi);
259  math::XYZPoint vtx = cand.vertex();
261  const reco::VertexRef &PVOrig = associatedPV[reco::CandidatePtr(cands, ic)];
262  if (PVOrig.isNonnull())
263  PV = reco::VertexRef(PVs,
264  PVOrig.key()); // WARNING: assume the PV slimmer is keeping same order
265  int quality = associationQuality[reco::CandidatePtr(cands, ic)];
266  // if ((size_t)pvi!=PVOrig.key()) std::cout << "not closest in Z"
267  // << pvi << " " << PVOrig.key() << " " << cand.pt() << " " <<
268  // quality << std::endl; TrajectoryStateOnSurface tsos =
269  // extrapolator.extrapolate(trajectoryStateTransform::initialFreeState(*ctrack,&*magneticField),
270  // RecoVertex::convertPos(PV->position()));
271  // vtx = tsos.globalPosition();
272  // phiAtVtx = tsos.globalDirection().phi();
273  vtx = ctrack->referencePoint();
274  float ptTrk = ctrack->pt();
275  float etaAtVtx = ctrack->eta();
276  float phiAtVtx = ctrack->phi();
277 
279  if (nlost == 0) {
282  }
283  } else {
285  }
286 
287  outPtrP->push_back(
288  pat::PackedCandidate(cand.polarP4(), vtx, ptTrk, etaAtVtx, phiAtVtx, cand.pdgId(), PVRefProd, PV.key()));
289  outPtrP->back().setAssociationQuality(pat::PackedCandidate::PVAssociationQuality(qualityMap[quality]));
290  outPtrP->back().setCovarianceVersion(covarianceVersion_);
291  if (cand.trackRef().isNonnull() && PVOrig.isNonnull() && PVOrig->trackWeight(cand.trackRef()) > 0.5 &&
292  quality == 7) {
293  outPtrP->back().setAssociationQuality(pat::PackedCandidate::UsedInFitTight);
294  }
295  // properties of the best track
296  outPtrP->back().setLostInnerHits(lostHits);
297  if (outPtrP->back().pt() > minPtForTrackProperties_ || outPtrP->back().ptTrk() > minPtForTrackProperties_ ||
298  whiteList.find(ic) != whiteList.end() ||
299  (cand.trackRef().isNonnull() && whiteListTk.find(cand.trackRef()) != whiteListTk.end())) {
300  outPtrP->back().setFirstHit(ctrack->hitPattern().getHitPattern(reco::HitPattern::TRACK_HITS, 0));
301  if (abs(outPtrP->back().pdgId()) == 22) {
302  outPtrP->back().setTrackProperties(*ctrack, covariancePackingSchemas_[4], covarianceVersion_);
303  } else {
304  if (ctrack->hitPattern().numberOfValidPixelHits() > 0) {
305  outPtrP->back().setTrackProperties(*ctrack,
307  covarianceVersion_); // high quality
308  } else {
309  outPtrP->back().setTrackProperties(*ctrack, covariancePackingSchemas_[1], covarianceVersion_);
310  }
311  }
312  // outPtrP->back().setTrackProperties(*ctrack,tsos.curvilinearError());
313  } else {
314  if (outPtrP->back().pt() > 0.5) {
315  if (ctrack->hitPattern().numberOfValidPixelHits() > 0)
316  outPtrP->back().setTrackProperties(*ctrack,
318  covarianceVersion_); // low quality, with pixels
319  else
320  outPtrP->back().setTrackProperties(*ctrack,
322  covarianceVersion_); // low quality, without pixels
323  }
324  }
325 
326  // these things are always for the CKF track
327  outPtrP->back().setTrackHighPurity(cand.trackRef().isNonnull() &&
328  cand.trackRef()->quality(reco::Track::highPurity));
329  if (cand.muonRef().isNonnull()) {
330  outPtrP->back().setMuonID(cand.muonRef()->isStandAloneMuon(), cand.muonRef()->isGlobalMuon());
331  }
332  } else {
333  if (!PVs->empty()) {
334  PV = reco::VertexRef(PVs, 0);
335  PVpos = PV->position();
336  }
337 
338  outPtrP->push_back(pat::PackedCandidate(
339  cand.polarP4(), PVpos, cand.pt(), cand.eta(), cand.phi(), cand.pdgId(), PVRefProd, PV.key()));
340  outPtrP->back().setAssociationQuality(
342  }
343 
344  // neutrals and isolated charged hadrons
345 
346  bool isIsolatedChargedHadron = false;
348  const edm::ValueMap<bool> &chargedHadronIsolation = *(chargedHadronIsolationHandle.product());
349  isIsolatedChargedHadron =
350  ((cand.pt() > minPtForChargedHadronProperties_) && (chargedHadronIsolation[reco::PFCandidateRef(cands, ic)]));
351  outPtrP->back().setIsIsolatedChargedHadron(isIsolatedChargedHadron);
352  }
353 
354  if (abs(cand.pdgId()) == 1 || abs(cand.pdgId()) == 130) {
355  outPtrP->back().setHcalFraction(cand.hcalEnergy() / (cand.ecalEnergy() + cand.hcalEnergy()));
356  } else if (cand.charge() && cand.pt() > 0.5) {
357  outPtrP->back().setHcalFraction(cand.hcalEnergy() / (cand.ecalEnergy() + cand.hcalEnergy()));
358  outPtrP->back().setCaloFraction((cand.hcalEnergy() + cand.ecalEnergy()) / cand.energy());
359  } else {
360  outPtrP->back().setHcalFraction(0);
361  outPtrP->back().setCaloFraction(0);
362  }
363 
364  if (isIsolatedChargedHadron) {
365  outPtrP->back().setRawCaloFraction((cand.rawEcalEnergy() + cand.rawHcalEnergy()) / cand.energy());
366  outPtrP->back().setRawHcalFraction(cand.rawHcalEnergy() / (cand.rawEcalEnergy() + cand.rawHcalEnergy()));
367  } else {
368  outPtrP->back().setRawCaloFraction(0);
369  outPtrP->back().setRawHcalFraction(0);
370  }
371 
372  std::vector<float> dummyVector;
373  dummyVector.clear();
374  pat::HcalDepthEnergyFractions hcalDepthEFrac(dummyVector);
375 
376  // storing HcalDepthEnergyFraction information
380  fabs(outPtrP->back().eta()) > 1.3) { // storeHcalDepthEndcapOnly_==false -> store all eta of
381  // selected PF types, if true, only |eta|>1.3 of selected
382  // PF types will be stored
383  std::vector<float> hcalDepthEnergyFractionTmp(cand.hcalDepthEnergyFractions().begin(),
384  cand.hcalDepthEnergyFractions().end());
385  hcalDepthEFrac.reset(hcalDepthEnergyFractionTmp);
386  }
387  }
388  hcalDepthEnergyFractions.push_back(hcalDepthEFrac);
389 
390  // specifically this is the PFLinker requirements to apply the e/gamma
391  // regression
392  if (cand.particleId() == reco::PFCandidate::e ||
393  (cand.particleId() == reco::PFCandidate::gamma && cand.mva_nothing_gamma() > 0.)) {
394  outPtrP->back().setGoodEgamma();
395  }
396 
397  if (usePuppi_) {
398  reco::PFCandidateRef pkref(cands, ic);
399  // outPtrP->back().setPuppiWeight( (*puppiWeight)[pkref]);
400 
401  float puppiWeightVal = (*puppiWeight)[pkref];
402  float puppiWeightNoLepVal = 0.0;
403  // Check the "no lepton" puppi weights.
404  // If present, then it is not a lepton, use stored weight
405  // If absent, it is a lepton, so set the weight to 1.0
406  if (puppiWeightNoLep.isValid()) {
407  // Look for the pointer inside the "no lepton" candidate collection.
408  auto pkrefPtr = pkref->sourceCandidatePtr(0);
409 
410  bool foundNoLep = false;
411  for (size_t ipcnl = 0; ipcnl < puppiCandsNoLepPtrs.size(); ipcnl++) {
412  if (puppiCandsNoLepPtrs[ipcnl] == pkrefPtr) {
413  foundNoLep = true;
414  puppiWeightNoLepVal =
415  puppiCandsNoLep->at(ipcnl).pt() / cand.pt(); // a hack for now, should use the value map
416  break;
417  }
418  }
419  if (!foundNoLep || puppiWeightNoLepVal > 1) {
420  puppiWeightNoLepVal = 1.0;
421  }
422  }
423  outPtrP->back().setPuppiWeight(puppiWeightVal, puppiWeightNoLepVal);
424 
425  mappingPuppi[((*puppiCandsMap)[pkref]).key()] = ic;
426  }
427 
428  if (storeTiming_ && cand.isTimeValid()) {
429  outPtrP->back().setTime(cand.time(), cand.timeError());
430  }
431 
432  mapping[ic] = ic; // trivial at the moment!
433  if (cand.trackRef().isNonnull() && cand.trackRef().id() == TKOrigs.id()) {
434  mappingTk[cand.trackRef().key()] = ic;
435  }
436  }
437 
438  auto outPtrPSorted = std::make_unique<std::vector<pat::PackedCandidate>>();
439  std::vector<size_t> order = sort_indexes(*outPtrP);
440  std::vector<size_t> reverseOrder(order.size());
441  for (size_t i = 0, nc = cands->size(); i < nc; i++) {
442  outPtrPSorted->push_back((*outPtrP)[order[i]]);
443  reverseOrder[order[i]] = i;
444  mappingReverse[order[i]] = i;
445  hcalDepthEnergyFractions_Ordered.push_back(hcalDepthEnergyFractions[order[i]]);
446  }
447 
448  // Fix track association for sorted candidates
449  for (size_t i = 0, ntk = mappingTk.size(); i < ntk; i++) {
450  if (mappingTk[i] >= 0)
451  mappingTk[i] = reverseOrder[mappingTk[i]];
452  }
453 
454  for (size_t i = 0, ntk = mappingPuppi.size(); i < ntk; i++) {
455  mappingPuppi[i] = reverseOrder[mappingPuppi[i]];
456  }
457 
459 
460  // now build the two maps
461  auto pf2pc = std::make_unique<edm::Association<pat::PackedCandidateCollection>>(oh);
462  auto pc2pf = std::make_unique<edm::Association<reco::PFCandidateCollection>>(cands);
465  pf2pcFiller.insert(cands, mappingReverse.begin(), mappingReverse.end());
466  pc2pfFiller.insert(oh, order.begin(), order.end());
467  // include also the mapping track -> packed PFCand
468  pf2pcFiller.insert(TKOrigs, mappingTk.begin(), mappingTk.end());
469  if (usePuppi_)
470  pf2pcFiller.insert(puppiCands, mappingPuppi.begin(), mappingPuppi.end());
471 
472  pf2pcFiller.fill();
473  pc2pfFiller.fill();
474  iEvent.put(std::move(pf2pc));
475  iEvent.put(std::move(pc2pf));
476 
477  // HCAL depth energy fraction additions using ValueMap
478  auto hcalDepthEnergyFractionsV = std::make_unique<edm::ValueMap<HcalDepthEnergyFractions>>();
479  edm::ValueMap<HcalDepthEnergyFractions>::Filler fillerHcalDepthEnergyFractions(*hcalDepthEnergyFractionsV);
480  fillerHcalDepthEnergyFractions.insert(
481  cands, hcalDepthEnergyFractions_Ordered.begin(), hcalDepthEnergyFractions_Ordered.end());
482  fillerHcalDepthEnergyFractions.fill();
483 
484  if (not pfCandidateTypesForHcalDepth_.empty())
485  iEvent.put(std::move(hcalDepthEnergyFractionsV), "hcalDepthEnergyFractions");
486 }
double ecalEnergy() const
return corrected Ecal energy
Definition: PFCandidate.h:220
int pdgId() const final
PDG identifier.
const Point & referencePoint() const
Reference point on the track.
Definition: TrackBase.h:632
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
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:223
bool hasValidHitInPixelLayer(enum PixelSubdetector::SubDetector, uint16_t layer) const
Definition: HitPattern.cc:337
key_type key() const
Definition: Ptr.h:163
const edm::EDGetTokenT< std::vector< reco::PFCandidate > > PuppiCandsNoLep_
ProductID id() const
Definition: HandleBase.cc:13
float mva_nothing_gamma() const
mva for gamma detection
Definition: PFCandidate.h:334
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
size_type size() const
double phi() const
azimuthal angle of momentum vector
Definition: TrackBase.h:614
double pt() const final
transverse momentum
int charge() const final
electric charge
float time() const
Definition: PFCandidate.h:416
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:250
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
ProductID id() const
Accessor for product ID.
Definition: Ref.h:244
const edm::EDGetTokenT< edm::ValueMap< int > > PVAssoQuality_
const edm::EDGetTokenT< edm::ValueMap< float > > PuppiWeightNoLep_
reco::TrackRef trackRef() const
Definition: PFCandidate.cc:408
const Point & vertex() const override
vertex position (overwritten by PF...)
Definition: PFCandidate.cc:602
bool isTimeValid() const
do we have a valid time information
Definition: PFCandidate.h:414
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:617
double pt() const
track transverse momentum
Definition: TrackBase.h:602
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:70
edm::Ref< VertexCollection > VertexRef
persistent reference to a Vertex
Definition: VertexFwd.h:13
reco::MuonRef muonRef() const
Definition: PFCandidate.cc:421
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:596
LostInnerHits
Enumerator specifying the.
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:428
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:69
const HitPattern & hitPattern() const
Access the hit pattern, indicating in which Tracker layers the track has hits.
Definition: TrackBase.h:483
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:158
const edm::EDGetTokenT< edm::ValueMap< float > > PuppiWeight_
const edm::EDGetTokenT< reco::VertexCollection > PVOrigs_
int numberOfLostHits(HitCategory category) const
Definition: HitPattern.h:861
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:440
const std::vector< int > pfCandidateTypesForHcalDepth_
double hcalEnergy() const
return corrected Hcal energy
Definition: PFCandidate.h:232
int numberOfValidPixelHits() const
Definition: HitPattern.h:801
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:366
uint16_t getHitPattern(HitCategory category, int position) const
Definition: HitPattern.h:531
double phi() const final
momentum azimuthal angle
float timeError() const
Definition: PFCandidate.h:418
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 68 of file PATPackedCandidateProducer.cc.

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

Referenced by produce().

68  {
69  std::vector<size_t> idx(v.size());
70  for (size_t i = 0; i != idx.size(); ++i)
71  idx[i] = i;
72  std::sort(idx.begin(), idx.end(), [&v](size_t i1, size_t i2) { return candsOrdering(v[i1], v[i2]); });
73  return idx;
74  }
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 82 of file PATPackedCandidateProducer.cc.

Referenced by produce().

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

Definition at line 95 of file PATPackedCandidateProducer.cc.

Referenced by produce().

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

Definition at line 100 of file PATPackedCandidateProducer.cc.

Referenced by produce().

const int pat::PATPackedCandidateProducer::covarianceVersion_
private

Definition at line 99 of file PATPackedCandidateProducer.cc.

Referenced by produce().

const double pat::PATPackedCandidateProducer::minPtForChargedHadronProperties_
private

Definition at line 97 of file PATPackedCandidateProducer.cc.

Referenced by produce().

const double pat::PATPackedCandidateProducer::minPtForTrackProperties_
private

Definition at line 98 of file PATPackedCandidateProducer.cc.

Referenced by produce().

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

Definition at line 102 of file PATPackedCandidateProducer.cc.

Referenced by PATPackedCandidateProducer(), and produce().

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

Definition at line 91 of file PATPackedCandidateProducer.cc.

Referenced by produce().

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

Definition at line 90 of file PATPackedCandidateProducer.cc.

Referenced by produce().

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

Definition at line 92 of file PATPackedCandidateProducer.cc.

Referenced by produce().

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

Definition at line 88 of file PATPackedCandidateProducer.cc.

Referenced by produce().

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

Definition at line 89 of file PATPackedCandidateProducer.cc.

Referenced by produce().

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

Definition at line 84 of file PATPackedCandidateProducer.cc.

Referenced by produce().

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

Definition at line 85 of file PATPackedCandidateProducer.cc.

Referenced by produce().

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

Definition at line 86 of file PATPackedCandidateProducer.cc.

Referenced by produce().

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

Definition at line 83 of file PATPackedCandidateProducer.cc.

Referenced by produce().

const bool pat::PATPackedCandidateProducer::storeChargedHadronIsolation_
private

Definition at line 94 of file PATPackedCandidateProducer.cc.

Referenced by produce().

const bool pat::PATPackedCandidateProducer::storeHcalDepthEndcapOnly_
private

Definition at line 103 of file PATPackedCandidateProducer.cc.

Referenced by produce().

const bool pat::PATPackedCandidateProducer::storeTiming_
private

Definition at line 105 of file PATPackedCandidateProducer.cc.

Referenced by produce().

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

Definition at line 93 of file PATPackedCandidateProducer.cc.

Referenced by PATPackedCandidateProducer(), and produce().

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

Definition at line 87 of file PATPackedCandidateProducer.cc.

Referenced by produce().

const bool pat::PATPackedCandidateProducer::usePuppi_
private

Definition at line 80 of file PATPackedCandidateProducer.cc.

Referenced by produce().