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
 
 EDProducer (const EDProducer &)=delete
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginProcessBlocks () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndProcessBlocks () const final
 
bool hasAbilityToProduceInEndRuns () const final
 
EDProduceroperator= (const EDProducer &)=delete
 
bool wantsGlobalLuminosityBlocks () const noexcept final
 
bool wantsGlobalRuns () const noexcept final
 
bool wantsInputProcessBlocks () const noexcept final
 
bool wantsProcessBlocks () const noexcept final
 
bool wantsStreamLuminosityBlocks () const noexcept final
 
bool wantsStreamRuns () const noexcept 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
 
std::vector< bool > const & recordProvenanceList () 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)
 
TypeLabelList const & typeLabelList () const
 used by the fwk to register the list of products of this module More...
 
 ~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
 
ESResolverIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
std::vector< ESResolverIndex > const & esGetTokenIndicesVector (edm::Transition iTrans) const
 
std::vector< ESRecordIndex > const & esGetTokenRecordIndicesVector (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::array< std::vector< ModuleDescription const *> *, NumBranchTypes > &modulesAll, std::vector< ModuleProcessName > &modulesInPreviousProcesses, 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
 
void selectInputProcessBlocks (ProductRegistry const &productRegistry, ProcessBlockHelperBase const &processBlockHelperBase)
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProductResolverIndices 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 minPtForLowQualityTrackProperties_
 
const double minPtForTrackProperties_
 
const std::vector< int > pfCandidateTypesForHcalDepth_
 
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< edm::ValueMap< float > > t0ErrMap_
 
const edm::EDGetTokenT< edm::ValueMap< float > > t0Map_
 
const bool timeFromValueMap_
 
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
template<typename T >
using BranchAliasSetterT = ProductRegistryHelper::BranchAliasSetterT< T >
 
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
template<Transition Tr = Transition::Event>
auto produces (std::string instanceName) noexcept
 declare what type of product will make and with which optional label More...
 
template<Transition B>
BranchAliasSetter produces (const TypeID &id, std::string instanceName=std::string(), bool recordProvenance=true)
 
template<BranchType B>
BranchAliasSetter produces (const TypeID &id, std::string instanceName=std::string(), bool recordProvenance=true)
 
BranchAliasSetter produces (const TypeID &id, std::string instanceName=std::string(), bool recordProvenance=true)
 
template<typename ProductType , Transition B>
BranchAliasSetterT< ProductType > produces (std::string instanceName)
 
template<class ProductType >
BranchAliasSetterT< ProductType > produces ()
 
template<typename ProductType , BranchType B>
BranchAliasSetterT< ProductType > produces (std::string instanceName)
 
template<typename ProductType , BranchType B>
BranchAliasSetterT< ProductType > produces ()
 
template<class ProductType >
BranchAliasSetterT< ProductType > produces (std::string instanceName)
 
template<typename ProductType , Transition B>
BranchAliasSetterT< ProductType > produces ()
 
template<Transition Tr = Transition::Event>
auto produces () noexcept
 
ProducesCollector producesCollector ()
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
template<BranchType B = InEvent>
EDConsumerBaseAdaptor< Bconsumes (edm::InputTag tag) noexcept
 
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 ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
template<Transition Tr = Transition::Event>
constexpr auto esConsumes ()
 
template<Transition Tr = Transition::Event>
auto esConsumes (ESInputTag tag)
 
template<Transition Tr = Transition::Event>
ESGetTokenGeneric esConsumes (eventsetup::EventSetupRecordKey const &iRecord, eventsetup::DataKey const &iKey)
 Used with EventSetupRecord::doGet. More...
 
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)
 
void resetItemsToGetFrom (BranchType iType)
 

Detailed Description

Definition at line 39 of file PATPackedCandidateProducer.cc.

Constructor & Destructor Documentation

◆ PATPackedCandidateProducer()

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

Definition at line 116 of file PATPackedCandidateProducer.cc.

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

117  : usePuppi_(!iConfig.getParameter<edm::InputTag>("PuppiSrc").encode().empty() ||
118  !iConfig.getParameter<edm::InputTag>("PuppiNoLepSrc").encode().empty()),
119  Cands_(consumes<reco::PFCandidateCollection>(iConfig.getParameter<edm::InputTag>("inputCollection"))),
120  PVs_(consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("inputVertices"))),
121  PVAsso_(
123  PVAssoQuality_(consumes<edm::ValueMap<int>>(iConfig.getParameter<edm::InputTag>("vertexAssociator"))),
124  PVOrigs_(consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("originalVertices"))),
125  TKOrigs_(consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("originalTracks"))),
127  : edm::EDGetTokenT<edm::ValueMap<float>>()),
128  PuppiWeightNoLep_(usePuppi_ ? consumes<edm::ValueMap<float>>(iConfig.getParameter<edm::InputTag>("PuppiNoLepSrc"))
129  : edm::EDGetTokenT<edm::ValueMap<float>>()),
130  storeChargedHadronIsolation_(!iConfig.getParameter<edm::InputTag>("chargedHadronIsolation").encode().empty()),
132  consumes<edm::ValueMap<bool>>(iConfig.getParameter<edm::InputTag>("chargedHadronIsolation"))),
133  minPtForChargedHadronProperties_(iConfig.getParameter<double>("minPtForChargedHadronProperties")),
134  minPtForTrackProperties_(iConfig.getParameter<double>("minPtForTrackProperties")),
135  minPtForLowQualityTrackProperties_(iConfig.getParameter<double>("minPtForLowQualityTrackProperties")),
136  covarianceVersion_(iConfig.getParameter<int>("covarianceVersion")),
137  covariancePackingSchemas_(iConfig.getParameter<std::vector<int>>("covariancePackingSchemas")),
138  pfCandidateTypesForHcalDepth_(iConfig.getParameter<std::vector<int>>("pfCandidateTypesForHcalDepth")),
139  storeHcalDepthEndcapOnly_(iConfig.getParameter<bool>("storeHcalDepthEndcapOnly")),
140  storeTiming_(iConfig.getParameter<bool>("storeTiming")),
141  timeFromValueMap_(!iConfig.getParameter<edm::InputTag>("timeMap").encode().empty() &&
142  !iConfig.getParameter<edm::InputTag>("timeMapErr").encode().empty()),
143  t0Map_(timeFromValueMap_ ? consumes<edm::ValueMap<float>>(iConfig.getParameter<edm::InputTag>("timeMap"))
144  : edm::EDGetTokenT<edm::ValueMap<float>>()),
145  t0ErrMap_(timeFromValueMap_ ? consumes<edm::ValueMap<float>>(iConfig.getParameter<edm::InputTag>("timeMapErr"))
146  : edm::EDGetTokenT<edm::ValueMap<float>>()) {
147  std::vector<edm::InputTag> sv_tags =
148  iConfig.getParameter<std::vector<edm::InputTag>>("secondaryVerticesForWhiteList");
149  for (const 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 }
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
std::string encode() const
Definition: InputTag.cc:159
const edm::EDGetTokenT< reco::PFCandidateCollection > Cands_
const edm::EDGetTokenT< edm::ValueMap< int > > PVAssoQuality_
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
const edm::EDGetTokenT< edm::ValueMap< float > > PuppiWeightNoLep_
const edm::EDGetTokenT< edm::ValueMap< float > > t0ErrMap_
const edm::EDGetTokenT< reco::TrackCollection > TKOrigs_
const edm::EDGetTokenT< edm::ValueMap< bool > > ChargedHadronIsolation_
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_
HLT enums.
const std::vector< int > pfCandidateTypesForHcalDepth_
const edm::EDGetTokenT< edm::Association< reco::VertexCollection > > PVAsso_
const edm::EDGetTokenT< reco::VertexCollection > PVs_
const edm::EDGetTokenT< edm::ValueMap< float > > t0Map_

◆ ~PATPackedCandidateProducer()

pat::PATPackedCandidateProducer::~PATPackedCandidateProducer ( )
override

Definition at line 161 of file PATPackedCandidateProducer.cc.

161 {}

Member Function Documentation

◆ calcDxy()

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

Definition at line 109 of file PATPackedCandidateProducer.cc.

References funct::cos(), PVValHelper::dx, PVValHelper::dy, and funct::sin().

109 { 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

◆ calcDz()

float pat::PATPackedCandidateProducer::calcDz ( reco::Candidate::Point  p,
reco::Candidate::Point  v,
const reco::Candidate c 
) const
inlineprivate

Definition at line 110 of file PATPackedCandidateProducer.cc.

References DummyCfis::c, AlCaHLTBitMon_ParallelJobs::p, and findQualityFiles::v.

110  {
111  return p.Z() - v.Z() - ((p.X() - v.X()) * c.px() + (p.Y() - v.Y()) * c.py()) * c.pz() / (c.pt() * c.pt());
112  }

◆ candsOrdering()

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(), mps_fire::i, and dqmiolumiharvest::j.

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

◆ produce()

void pat::PATPackedCandidateProducer::produce ( edm::StreamID  ,
edm::Event iEvent,
const edm::EventSetup iSetup 
) const
overridevirtual

Implements edm::global::EDProducerBase.

Definition at line 163 of file PATPackedCandidateProducer.cc.

References funct::abs(), reco::TrackBase::algo(), DummyCfis::c, HLT_2024v14_cff::cands, packedPFCandidates_cfi::chargedHadronIsolation, PVValHelper::dz, reco::TrackBase::dz(), reco::PFCandidate::e, edm::View< T >::end(), reco::TrackBase::eta(), l1trig_cff::etaAtVtx, edm::helper::Filler< Map >::fill(), spr::find(), reco::PFCandidate::gamma, reco::HitPattern::getHitPattern(), reco::HitPattern::hasValidHitInPixelLayer(), reco::TrackBase::highPurity, reco::TrackBase::hitPattern(), mps_fire::i, edm::HandleBase::id(), iEvent, cuy::ii, edm::helper::Filler< Map >::insert(), edm::Ref< C, T, F >::isNonnull(), dqmiolumiharvest::j, edm::Ref< C, T, F >::key(), electrons_cff::lostHits, HPSPFTaus_cff::mapping, reco::HitPattern::MISSING_INNER_HITS, pat::PackedCandidate::moreLostInnerHits, eostools::move(), pat::PackedCandidate::noLostInnerHits, reco::HitPattern::numberOfLostHits(), reco::HitPattern::numberOfValidPixelHits(), pat::PackedCandidate::oneLostInnerHit, eventshapeDQM_cfi::order, reco::TrackBase::originalAlgo(), reco::TrackBase::phi(), l1trig_cff::phiAtVtx, GeomDetEnumerators::PixelBarrel, edm::Handle< T >::product(), reco::TrackBase::pt(), nanoDQM_cfi::PV, quality, pat::qualityMap, reco::TrackBase::referencePoint(), pat::HcalDepthEnergyFractions::reset(), edm::View< T >::size(), FrontierCondition_GT_autoExpress_cfi::t0, reco::RecoChargedCandidate::track(), reco::HitPattern::TRACK_HITS, pat::PackedCandidate::UsedInFitTight, pat::PackedCandidate::validHitInFirstPixelBarrelLayer, and L1BJetProducer_cff::vtx.

163  {
165  iEvent.getByToken(Cands_, cands);
166 
168  edm::Handle<edm::ValueMap<float>> puppiWeightNoLep;
169  if (usePuppi_) {
170  iEvent.getByToken(PuppiWeight_, puppiWeight);
171  iEvent.getByToken(PuppiWeightNoLep_, puppiWeightNoLep);
172  }
173 
175  iEvent.getByToken(PVOrigs_, PVOrigs);
176 
178  iEvent.getByToken(PVAsso_, assoHandle);
179  edm::Handle<edm::ValueMap<int>> assoQualityHandle;
180  iEvent.getByToken(PVAssoQuality_, assoQualityHandle);
181  const edm::Association<reco::VertexCollection> &associatedPV = *(assoHandle.product());
182  const edm::ValueMap<int> &associationQuality = *(assoQualityHandle.product());
183 
184  edm::Handle<edm::ValueMap<bool>> chargedHadronIsolationHandle;
186  iEvent.getByToken(ChargedHadronIsolation_, chargedHadronIsolationHandle);
187 
188  std::set<unsigned int> whiteList;
189  std::set<reco::TrackRef> whiteListTk;
190  for (auto itoken : SVWhiteLists_) {
191  edm::Handle<edm::View<reco::Candidate>> svWhiteListHandle;
192  iEvent.getByToken(itoken, svWhiteListHandle);
193  const edm::View<reco::Candidate> &svWhiteList = *(svWhiteListHandle.product());
194  for (unsigned int i = 0; i < svWhiteList.size(); i++) {
195  // Whitelist via Ptrs
196  for (unsigned int j = 0; j < svWhiteList[i].numberOfSourceCandidatePtrs(); j++) {
197  const edm::Ptr<reco::Candidate> &c = svWhiteList[i].sourceCandidatePtr(j);
198  if (c.id() == cands.id())
199  whiteList.insert(c.key());
200  }
201  // Whitelist via RecoCharged
202  for (auto dau = svWhiteList[i].begin(); dau != svWhiteList[i].end(); dau++) {
203  const reco::RecoChargedCandidate *chCand = dynamic_cast<const reco::RecoChargedCandidate *>(&(*dau));
204  if (chCand != nullptr) {
205  whiteListTk.insert(chCand->track());
206  }
207  }
208  }
209  }
210 
213  if (timeFromValueMap_) {
214  iEvent.getByToken(t0Map_, t0Map);
215  iEvent.getByToken(t0ErrMap_, t0ErrMap);
216  }
217 
219  iEvent.getByToken(PVs_, PVs);
220  reco::VertexRef PV(PVs.id());
221  reco::VertexRefProd PVRefProd(PVs);
222  math::XYZPoint PVpos;
223 
224  std::vector<pat::HcalDepthEnergyFractions> hcalDepthEnergyFractions;
225  hcalDepthEnergyFractions.reserve(cands->size());
226  std::vector<pat::HcalDepthEnergyFractions> hcalDepthEnergyFractions_Ordered;
227  hcalDepthEnergyFractions_Ordered.reserve(cands->size());
228 
230  iEvent.getByToken(TKOrigs_, TKOrigs);
231  auto outPtrP = std::make_unique<std::vector<pat::PackedCandidate>>();
232  std::vector<int> mapping(cands->size());
233  std::vector<int> mappingReverse(cands->size());
234  std::vector<int> mappingTk(TKOrigs->size(), -1);
235 
236  for (unsigned int ic = 0, nc = cands->size(); ic < nc; ++ic) {
237  const reco::PFCandidate &cand = (*cands)[ic];
238  const reco::Track *ctrack = nullptr;
239  if ((abs(cand.pdgId()) == 11 || cand.pdgId() == 22) && cand.gsfTrackRef().isNonnull()) {
240  ctrack = &*cand.gsfTrackRef();
241  } else if (cand.trackRef().isNonnull()) {
242  ctrack = &*cand.trackRef();
243  }
244  if (ctrack) {
245  float dist = 1e99;
246  int pvi = -1;
247  for (size_t ii = 0; ii < PVs->size(); ii++) {
248  float dz = std::abs(ctrack->dz(((*PVs)[ii]).position()));
249  if (dz < dist) {
250  pvi = ii;
251  dist = dz;
252  }
253  }
254  PV = reco::VertexRef(PVs, pvi);
255  math::XYZPoint vtx = cand.vertex();
257  const reco::VertexRef &PVOrig = associatedPV[reco::CandidatePtr(cands, ic)];
258  if (PVOrig.isNonnull())
259  PV = reco::VertexRef(PVs,
260  PVOrig.key()); // WARNING: assume the PV slimmer is keeping same order
261  int quality = associationQuality[reco::CandidatePtr(cands, ic)];
262  // if ((size_t)pvi!=PVOrig.key()) std::cout << "not closest in Z"
263  // << pvi << " " << PVOrig.key() << " " << cand.pt() << " " <<
264  // quality << std::endl; TrajectoryStateOnSurface tsos =
265  // extrapolator.extrapolate(trajectoryStateTransform::initialFreeState(*ctrack,&*magneticField),
266  // RecoVertex::convertPos(PV->position()));
267  // vtx = tsos.globalPosition();
268  // phiAtVtx = tsos.globalDirection().phi();
269  vtx = ctrack->referencePoint();
270  float ptTrk = ctrack->pt();
271  float etaAtVtx = ctrack->eta();
272  float phiAtVtx = ctrack->phi();
273 
275  if (nlost == 0) {
278  }
279  } else {
281  }
282 
283  outPtrP->push_back(
284  pat::PackedCandidate(cand.polarP4(), vtx, ptTrk, etaAtVtx, phiAtVtx, cand.pdgId(), PVRefProd, PV.key()));
285  outPtrP->back().setAssociationQuality(pat::PackedCandidate::PVAssociationQuality(qualityMap[quality]));
286  outPtrP->back().setCovarianceVersion(covarianceVersion_);
287  if (cand.trackRef().isNonnull() && PVOrig.isNonnull() && PVOrig->trackWeight(cand.trackRef()) > 0.5 &&
288  quality == 7) {
289  outPtrP->back().setAssociationQuality(pat::PackedCandidate::UsedInFitTight);
290  }
291  // properties of the best track
292  outPtrP->back().setLostInnerHits(lostHits);
293  if (outPtrP->back().pt() > minPtForTrackProperties_ || outPtrP->back().ptTrk() > minPtForTrackProperties_ ||
294  whiteList.find(ic) != whiteList.end() ||
295  (cand.trackRef().isNonnull() && whiteListTk.find(cand.trackRef()) != whiteListTk.end())) {
296  outPtrP->back().setTrkAlgo(static_cast<uint8_t>(ctrack->algo()), static_cast<uint8_t>(ctrack->originalAlgo()));
297  outPtrP->back().setFirstHit(ctrack->hitPattern().getHitPattern(reco::HitPattern::TRACK_HITS, 0));
298  if (abs(outPtrP->back().pdgId()) == 22) {
299  outPtrP->back().setTrackProperties(*ctrack, covariancePackingSchemas_[4], covarianceVersion_);
300  } else {
301  if (ctrack->hitPattern().numberOfValidPixelHits() > 0) {
302  outPtrP->back().setTrackProperties(*ctrack,
304  covarianceVersion_); // high quality
305  } else {
306  outPtrP->back().setTrackProperties(*ctrack, covariancePackingSchemas_[1], covarianceVersion_);
307  }
308  }
309  // outPtrP->back().setTrackProperties(*ctrack,tsos.curvilinearError());
310  } else {
311  if (outPtrP->back().pt() > minPtForLowQualityTrackProperties_) {
312  if (ctrack->hitPattern().numberOfValidPixelHits() > 0)
313  outPtrP->back().setTrackProperties(*ctrack,
315  covarianceVersion_); // low quality, with pixels
316  else
317  outPtrP->back().setTrackProperties(*ctrack,
319  covarianceVersion_); // low quality, without pixels
320  }
321  }
322 
323  // these things are always for the CKF track
324  outPtrP->back().setTrackHighPurity(cand.trackRef().isNonnull() &&
325  cand.trackRef()->quality(reco::Track::highPurity));
326  } else {
327  if (!PVs->empty()) {
328  PV = reco::VertexRef(PVs, 0);
329  PVpos = PV->position();
330  }
331 
332  outPtrP->push_back(pat::PackedCandidate(
333  cand.polarP4(), PVpos, cand.pt(), cand.eta(), cand.phi(), cand.pdgId(), PVRefProd, PV.key()));
334  outPtrP->back().setAssociationQuality(
336  }
337 
338  // Set Muon ID flags
339 
340  if (cand.muonRef().isNonnull()) {
341  outPtrP->back().setMuonID(cand.muonRef()->isStandAloneMuon(), cand.muonRef()->isGlobalMuon());
342  }
343 
344  // neutrals and isolated charged hadrons
345 
346  bool isIsolatedChargedHadron = false;
348  const edm::ValueMap<bool> &chargedHadronIsolation = *(chargedHadronIsolationHandle.product());
349  isIsolatedChargedHadron =
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() || abs(cand.pdgId()) == 22) && 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 
400  float puppiWeightVal = (*puppiWeight)[pkref];
401  float puppiWeightNoLepVal = (*puppiWeightNoLep)[pkref];
402  outPtrP->back().setPuppiWeight(puppiWeightVal, puppiWeightNoLepVal);
403  }
404 
405  if (storeTiming_) {
406  if (timeFromValueMap_) {
407  if (cand.trackRef().isNonnull()) {
408  auto t0 = (*t0Map)[cand.trackRef()];
409  auto t0Err = (*t0ErrMap)[cand.trackRef()];
410  outPtrP->back().setTime(t0, t0Err);
411  }
412  } else {
413  if (cand.isTimeValid()) {
414  outPtrP->back().setTime(cand.time(), cand.timeError());
415  }
416  }
417  }
418 
419  mapping[ic] = ic; // trivial at the moment!
420  if (cand.trackRef().isNonnull() && cand.trackRef().id() == TKOrigs.id()) {
421  mappingTk[cand.trackRef().key()] = ic;
422  }
423  }
424 
425  auto outPtrPSorted = std::make_unique<std::vector<pat::PackedCandidate>>();
426  std::vector<size_t> order = sort_indexes(*outPtrP);
427  std::vector<size_t> reverseOrder(order.size());
428  for (size_t i = 0, nc = cands->size(); i < nc; i++) {
429  outPtrPSorted->push_back((*outPtrP)[order[i]]);
430  reverseOrder[order[i]] = i;
431  mappingReverse[order[i]] = i;
432  hcalDepthEnergyFractions_Ordered.push_back(hcalDepthEnergyFractions[order[i]]);
433  }
434 
435  // Fix track association for sorted candidates
436  for (size_t i = 0, ntk = mappingTk.size(); i < ntk; i++) {
437  if (mappingTk[i] >= 0)
438  mappingTk[i] = reverseOrder[mappingTk[i]];
439  }
440 
442 
443  // now build the two maps
444  auto pf2pc = std::make_unique<edm::Association<pat::PackedCandidateCollection>>(oh);
445  auto pc2pf = std::make_unique<edm::Association<reco::PFCandidateCollection>>(cands);
448  pf2pcFiller.insert(cands, mappingReverse.begin(), mappingReverse.end());
449  pc2pfFiller.insert(oh, order.begin(), order.end());
450  // include also the mapping track -> packed PFCand
451  pf2pcFiller.insert(TKOrigs, mappingTk.begin(), mappingTk.end());
452 
453  pf2pcFiller.fill();
454  pc2pfFiller.fill();
455  iEvent.put(std::move(pf2pc));
456  iEvent.put(std::move(pc2pf));
457 
458  // HCAL depth energy fraction additions using ValueMap
459  auto hcalDepthEnergyFractionsV = std::make_unique<edm::ValueMap<HcalDepthEnergyFractions>>();
460  edm::ValueMap<HcalDepthEnergyFractions>::Filler fillerHcalDepthEnergyFractions(*hcalDepthEnergyFractionsV);
461  fillerHcalDepthEnergyFractions.insert(
462  cands, hcalDepthEnergyFractions_Ordered.begin(), hcalDepthEnergyFractions_Ordered.end());
463  fillerHcalDepthEnergyFractions.fill();
464 
465  if (not pfCandidateTypesForHcalDepth_.empty())
466  iEvent.put(std::move(hcalDepthEnergyFractionsV), "hcalDepthEnergyFractions");
467 }
int numberOfValidPixelHits() const
Definition: HitPattern.h:831
int numberOfLostHits(HitCategory category) const
Definition: HitPattern.h:891
ProductID id() const
Definition: HandleBase.cc:29
T const * product() const
Definition: Handle.h:70
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
static const int qualityMap[8]
conversion map from quality flags used in PV association and miniAOD one
const Point & referencePoint() const
Reference point on the track.
Definition: TrackBase.h:667
const edm::EDGetTokenT< reco::PFCandidateCollection > Cands_
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
key_type key() const
Accessor for product key.
Definition: Ref.h:250
const edm::EDGetTokenT< edm::ValueMap< int > > PVAssoQuality_
size_type size() const
const edm::EDGetTokenT< edm::ValueMap< float > > PuppiWeightNoLep_
double pt() const
track transverse momentum
Definition: TrackBase.h:637
string quality
TrackAlgorithm originalAlgo() const
Definition: TrackBase.h:548
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:622
int iEvent
Definition: GenABIO.cc:224
const edm::EDGetTokenT< edm::ValueMap< float > > t0ErrMap_
reco::TrackRef track() const override
reference to a track
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double phi() const
azimuthal angle of momentum vector
Definition: TrackBase.h:649
static std::vector< size_t > sort_indexes(const std::vector< T > &v)
const edm::EDGetTokenT< reco::TrackCollection > TKOrigs_
edm::Ref< VertexCollection > VertexRef
persistent reference to a Vertex
Definition: VertexFwd.h:13
uint16_t getHitPattern(HitCategory category, int position) const
Definition: HitPattern.h:537
ii
Definition: cuy.py:589
LostInnerHits
Enumerator specifying the.
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:652
const edm::EDGetTokenT< edm::ValueMap< bool > > ChargedHadronIsolation_
TrackAlgorithm algo() const
Definition: TrackBase.h:547
edm::Ptr< Candidate > CandidatePtr
persistent reference to an object in a collection of Candidate objects
Definition: CandidateFwd.h:25
const HitPattern & hitPattern() const
Access the hit pattern, indicating in which Tracker layers the track has hits.
Definition: TrackBase.h:504
const std::vector< int > covariancePackingSchemas_
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
const edm::EDGetTokenT< edm::ValueMap< float > > PuppiWeight_
const edm::EDGetTokenT< reco::VertexCollection > PVOrigs_
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:41
std::vector< edm::EDGetTokenT< edm::View< reco::Candidate > > > SVWhiteLists_
const std::vector< int > pfCandidateTypesForHcalDepth_
const edm::EDGetTokenT< edm::Association< reco::VertexCollection > > PVAsso_
const edm::EDGetTokenT< reco::VertexCollection > PVs_
const edm::EDGetTokenT< edm::ValueMap< float > > t0Map_
Definition: PV.py:1
const_iterator end() const
def move(src, dest)
Definition: eostools.py:511
bool hasValidHitInPixelLayer(enum PixelSubdetector::SubDetector, uint16_t layer) const
Definition: HitPattern.cc:359

◆ sort_indexes()

template<typename T >
static std::vector<size_t> pat::PATPackedCandidateProducer::sort_indexes ( const std::vector< T > &  v)
inlinestatic

Member Data Documentation

◆ Cands_

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

Definition at line 82 of file PATPackedCandidateProducer.cc.

◆ ChargedHadronIsolation_

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

Definition at line 92 of file PATPackedCandidateProducer.cc.

◆ covariancePackingSchemas_

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

Definition at line 98 of file PATPackedCandidateProducer.cc.

◆ covarianceVersion_

const int pat::PATPackedCandidateProducer::covarianceVersion_
private

Definition at line 97 of file PATPackedCandidateProducer.cc.

◆ minPtForChargedHadronProperties_

const double pat::PATPackedCandidateProducer::minPtForChargedHadronProperties_
private

Definition at line 94 of file PATPackedCandidateProducer.cc.

◆ minPtForLowQualityTrackProperties_

const double pat::PATPackedCandidateProducer::minPtForLowQualityTrackProperties_
private

Definition at line 96 of file PATPackedCandidateProducer.cc.

◆ minPtForTrackProperties_

const double pat::PATPackedCandidateProducer::minPtForTrackProperties_
private

Definition at line 95 of file PATPackedCandidateProducer.cc.

◆ pfCandidateTypesForHcalDepth_

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

Definition at line 100 of file PATPackedCandidateProducer.cc.

Referenced by PATPackedCandidateProducer().

◆ PuppiWeight_

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

Definition at line 88 of file PATPackedCandidateProducer.cc.

◆ PuppiWeightNoLep_

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

Definition at line 89 of file PATPackedCandidateProducer.cc.

◆ PVAsso_

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

Definition at line 84 of file PATPackedCandidateProducer.cc.

◆ PVAssoQuality_

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

Definition at line 85 of file PATPackedCandidateProducer.cc.

◆ PVOrigs_

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

Definition at line 86 of file PATPackedCandidateProducer.cc.

◆ PVs_

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

Definition at line 83 of file PATPackedCandidateProducer.cc.

◆ storeChargedHadronIsolation_

const bool pat::PATPackedCandidateProducer::storeChargedHadronIsolation_
private

Definition at line 91 of file PATPackedCandidateProducer.cc.

◆ storeHcalDepthEndcapOnly_

const bool pat::PATPackedCandidateProducer::storeHcalDepthEndcapOnly_
private

Definition at line 101 of file PATPackedCandidateProducer.cc.

◆ storeTiming_

const bool pat::PATPackedCandidateProducer::storeTiming_
private

Definition at line 103 of file PATPackedCandidateProducer.cc.

◆ SVWhiteLists_

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

Definition at line 90 of file PATPackedCandidateProducer.cc.

Referenced by PATPackedCandidateProducer().

◆ t0ErrMap_

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

Definition at line 106 of file PATPackedCandidateProducer.cc.

◆ t0Map_

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

Definition at line 105 of file PATPackedCandidateProducer.cc.

◆ timeFromValueMap_

const bool pat::PATPackedCandidateProducer::timeFromValueMap_
private

Definition at line 104 of file PATPackedCandidateProducer.cc.

◆ TKOrigs_

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

Definition at line 87 of file PATPackedCandidateProducer.cc.

◆ usePuppi_

const bool pat::PATPackedCandidateProducer::usePuppi_
private

Definition at line 80 of file PATPackedCandidateProducer.cc.