CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Attributes
PATRefitVertexProducer Class Reference
Inheritance diagram for PATRefitVertexProducer:
edm::stream::EDProducer<>

Public Member Functions

 PATRefitVertexProducer (const edm::ParameterSet &)
 
void produce (edm::Event &, const edm::EventSetup &) override
 
 ~PATRefitVertexProducer () override
 
- Public Member Functions inherited from edm::stream::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
 
const EDProduceroperator= (const EDProducer &)=delete
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &)
 

Private Attributes

edm::EDGetTokenT< reco::BeamSpotsrcBeamSpot_
 
edm::EDGetTokenT< std::vector< pat::PackedCandidate > > srcCands_
 
edm::EDGetTokenT< std::vector< pat::PackedCandidate > > srcEleKfTracks_
 
edm::EDGetTokenT< std::vector< pat::PackedCandidate > > srcLostTracks_
 
edm::EDGetTokenT< reco::VertexCollectionsrcVertices_
 
edm::ESGetToken< TransientTrackBuilder, TransientTrackRecordtransTrackBuilderToken_
 
bool useBeamSpot_
 
bool useEleKfTracks_
 
bool useLostTracks_
 

Additional Inherited Members

- Public Types inherited from edm::stream::EDProducer<>
using CacheTypes = CacheContexts< T... >
 
using GlobalCache = typename CacheTypes::GlobalCache
 
using HasAbility = AbilityChecker< T... >
 
using InputProcessBlockCache = typename CacheTypes::InputProcessBlockCache
 
using LuminosityBlockCache = typename CacheTypes::LuminosityBlockCache
 
using LuminosityBlockContext = LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCache >
 
using LuminosityBlockSummaryCache = typename CacheTypes::LuminosityBlockSummaryCache
 
using RunCache = typename CacheTypes::RunCache
 
using RunContext = RunContextT< RunCache, GlobalCache >
 
using RunSummaryCache = typename CacheTypes::RunSummaryCache
 

Detailed Description

This producer is intended to take packedCandidates with tracks associated to the PV and refit the PV (applying or not) BeamSpot constraint

Michal Bluj, NCBJ Warsaw (and then others)

Definition at line 29 of file PATRefitVertexProducer.cc.

Constructor & Destructor Documentation

◆ PATRefitVertexProducer()

PATRefitVertexProducer::PATRefitVertexProducer ( const edm::ParameterSet cfg)
explicit

Definition at line 50 of file PATRefitVertexProducer.cc.

51  : srcCands_(consumes<std::vector<pat::PackedCandidate> >(cfg.getParameter<edm::InputTag>("srcCands"))),
52  srcLostTracks_(consumes<std::vector<pat::PackedCandidate> >(cfg.getParameter<edm::InputTag>("srcLostTracks"))),
53  srcEleKfTracks_(consumes<std::vector<pat::PackedCandidate> >(cfg.getParameter<edm::InputTag>("srcEleKfTracks"))),
54  srcVertices_(consumes<reco::VertexCollection>(cfg.getParameter<edm::InputTag>("srcVertices"))),
55  srcBeamSpot_(consumes<reco::BeamSpot>(cfg.getParameter<edm::InputTag>("srcBeamSpot"))),
56  transTrackBuilderToken_(esConsumes(edm::ESInputTag("", "TransientTrackBuilder"))),
57  useBeamSpot_(cfg.getParameter<bool>("useBeamSpot")),
58  useLostTracks_(cfg.getParameter<bool>("useLostTracks")),
59  useEleKfTracks_(cfg.getParameter<bool>("useEleKfTracks")) {
60  produces<reco::VertexCollection>();
61 }
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
edm::EDGetTokenT< reco::BeamSpot > srcBeamSpot_
edm::EDGetTokenT< std::vector< pat::PackedCandidate > > srcLostTracks_
edm::EDGetTokenT< std::vector< pat::PackedCandidate > > srcCands_
edm::EDGetTokenT< reco::VertexCollection > srcVertices_
edm::ESGetToken< TransientTrackBuilder, TransientTrackRecord > transTrackBuilderToken_
edm::EDGetTokenT< std::vector< pat::PackedCandidate > > srcEleKfTracks_

◆ ~PATRefitVertexProducer()

PATRefitVertexProducer::~PATRefitVertexProducer ( )
inlineoverride

Definition at line 32 of file PATRefitVertexProducer.cc.

32 {};

Member Function Documentation

◆ fillDescriptions()

void PATRefitVertexProducer::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 174 of file PATRefitVertexProducer.cc.

References edm::ConfigurationDescriptions::addWithDefaultLabel(), submitPVResolutionJobs::desc, and ProducerED_cfi::InputTag.

174  {
175  // patRefitVertexProducer
177 
178  desc.add<edm::InputTag>("srcVertices", edm::InputTag("offlineSlimmedPrimaryVertices"));
179  desc.add<edm::InputTag>("srcCands", edm::InputTag("packedPFCandidates"));
180  desc.add<edm::InputTag>("srcLostTracks", edm::InputTag("lostTracks"));
181  desc.add<edm::InputTag>("srcEleKfTracks", edm::InputTag("lostTracks:eleTracks"));
182  desc.add<edm::InputTag>("srcBeamSpot", edm::InputTag("offlineBeamSpot"));
183  desc.add<bool>("useBeamSpot", true)->setComment("Refit PV with beam-spot constraint");
184  desc.add<bool>("useLostTracks", true)
185  ->setComment("Use collection of tracks not used by PF-candidates, aka lost-tracks");
186  desc.add<bool>("useEleKfTracks", true)
187  ->setComment("Use collection of electron KF-tracks instead of GSF-tracks of electron PF-candidates");
188 
189  descriptions.addWithDefaultLabel(desc);
190 }
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)

◆ produce()

void PATRefitVertexProducer::produce ( edm::Event evt,
const edm::EventSetup es 
)
override

Definition at line 63 of file PATRefitVertexProducer.cc.

References funct::abs(), pwdgSkimBPark_cfi::beamSpot, TransientTrackBuilder::build(), HLT_2023v12_cff::cands, edm::Event::getByToken(), edm::EventSetup::getData(), TransientVertex::isValid(), submitPVResolutionJobs::key, eostools::move(), TransientVertex::position(), edm::Event::put(), quality, AdaptiveVertexFitter::setWeightThreshold(), srcBeamSpot_, srcCands_, srcEleKfTracks_, srcLostTracks_, srcVertices_, transTrackBuilderToken_, useBeamSpot_, pat::PackedCandidate::UsedInFitLoose, pat::PackedCandidate::UsedInFitTight, useEleKfTracks_, useLostTracks_, AdaptiveVertexFitter::vertex(), AlignmentTracksFromVertexSelector_cfi::vertices, and PV3DBase< T, PVType, FrameType >::z().

63  {
64  // Obtain collections
67 
69  if (useLostTracks_)
70  evt.getByToken(srcLostTracks_, lostTrackCands);
71 
73  if (useEleKfTracks_)
74  evt.getByToken(srcEleKfTracks_, eleKfTrackCands);
75 
78  const reco::Vertex& pv = vertices->front();
79  size_t vtxIdx = 0;
80 
82  if (useBeamSpot_)
84 
85  // Get transient track builder
86  const TransientTrackBuilder& transTrackBuilder = es.getData(transTrackBuilderToken_);
87 
88  // Output collection
89  auto outputVertices = std::make_unique<reco::VertexCollection>();
90  outputVertices->reserve(1);
91 
92  // Create a new track collection for vertex refit
93  std::vector<reco::TransientTrack> transTracks;
94 
95  // loop over the PFCandidates
96  for (const auto& cand : (*cands)) {
97  if (cand.charge() == 0 || cand.vertexRef().isNull())
98  continue;
99  if (cand.bestTrack() == nullptr)
100  continue;
101  auto key = cand.vertexRef().key();
102  auto quality = cand.pvAssociationQuality();
103  if (key != vtxIdx ||
105  continue;
106  if (useEleKfTracks_ && std::abs(cand.pdgId()) == 11)
107  continue;
108  transTracks.push_back(transTrackBuilder.build(cand.bestTrack()));
109  }
110 
111  // loop over the lostTracks
112  if (useLostTracks_) {
113  for (const auto& cand : (*lostTrackCands)) {
114  if (cand.charge() == 0 || cand.vertexRef().isNull())
115  continue;
116  if (cand.bestTrack() == nullptr)
117  continue;
118  auto key = cand.vertexRef().key();
119  auto quality = cand.pvAssociationQuality();
120  if (key != vtxIdx ||
122  continue;
123  transTracks.push_back(transTrackBuilder.build(cand.bestTrack()));
124  }
125  }
126 
127  // loop over the electronKfTracks
128  if (useEleKfTracks_) {
129  for (const auto& cand : (*eleKfTrackCands)) {
130  if (cand.charge() == 0 || cand.vertexRef().isNull())
131  continue;
132  if (cand.bestTrack() == nullptr)
133  continue;
134  auto key = cand.vertexRef().key();
135  auto quality = cand.pvAssociationQuality();
136  if (key != vtxIdx ||
138  continue;
139  transTracks.push_back(transTrackBuilder.build(cand.bestTrack()));
140  }
141  }
142 
143  // Refit the vertex
144  TransientVertex transVtx;
145  reco::Vertex refitPV(pv); // initialized to the original PV
146 
147  bool fitOK = true;
148  if (transTracks.size() >= 3) {
150  avf.setWeightThreshold(0.1); // weight per track, allow almost every fit, else --> exception
151  if (!useBeamSpot_) {
152  transVtx = avf.vertex(transTracks);
153  } else {
154  transVtx = avf.vertex(transTracks, *beamSpot);
155  }
156  if (!transVtx.isValid()) {
157  fitOK = false;
158  } else {
159  //MB: protect against rare cases when transVtx is valid but its postion is ill-defined
160  if (!std::isfinite(transVtx.position().z())) //MB: it is enough to check one coordinate (?)
161  fitOK = false;
162  }
163  } else
164  fitOK = false;
165  if (fitOK) {
166  refitPV = transVtx;
167  }
168 
169  outputVertices->push_back(refitPV);
170 
171  evt.put(std::move(outputVertices));
172 }
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
GlobalPoint position() const
edm::EDGetTokenT< reco::BeamSpot > srcBeamSpot_
T z() const
Definition: PV3DBase.h:61
edm::EDGetTokenT< std::vector< pat::PackedCandidate > > srcLostTracks_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:528
CachingVertex< 5 > vertex(const std::vector< reco::TransientTrack > &) const override
reco::TransientTrack build(const reco::Track *p) const
string quality
bool isValid() const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
key
prepare the HTCondor submission files and eventually submit them
edm::EDGetTokenT< std::vector< pat::PackedCandidate > > srcCands_
edm::EDGetTokenT< reco::VertexCollection > srcVertices_
edm::ESGetToken< TransientTrackBuilder, TransientTrackRecord > transTrackBuilderToken_
edm::EDGetTokenT< std::vector< pat::PackedCandidate > > srcEleKfTracks_
def move(src, dest)
Definition: eostools.py:511

Member Data Documentation

◆ srcBeamSpot_

edm::EDGetTokenT<reco::BeamSpot> PATRefitVertexProducer::srcBeamSpot_
private

Definition at line 43 of file PATRefitVertexProducer.cc.

Referenced by produce().

◆ srcCands_

edm::EDGetTokenT<std::vector<pat::PackedCandidate> > PATRefitVertexProducer::srcCands_
private

Definition at line 41 of file PATRefitVertexProducer.cc.

Referenced by produce().

◆ srcEleKfTracks_

edm::EDGetTokenT<std::vector<pat::PackedCandidate> > PATRefitVertexProducer::srcEleKfTracks_
private

Definition at line 41 of file PATRefitVertexProducer.cc.

Referenced by produce().

◆ srcLostTracks_

edm::EDGetTokenT<std::vector<pat::PackedCandidate> > PATRefitVertexProducer::srcLostTracks_
private

Definition at line 41 of file PATRefitVertexProducer.cc.

Referenced by produce().

◆ srcVertices_

edm::EDGetTokenT<reco::VertexCollection> PATRefitVertexProducer::srcVertices_
private

Definition at line 42 of file PATRefitVertexProducer.cc.

Referenced by produce().

◆ transTrackBuilderToken_

edm::ESGetToken<TransientTrackBuilder, TransientTrackRecord> PATRefitVertexProducer::transTrackBuilderToken_
private

Definition at line 44 of file PATRefitVertexProducer.cc.

Referenced by produce().

◆ useBeamSpot_

bool PATRefitVertexProducer::useBeamSpot_
private

Definition at line 45 of file PATRefitVertexProducer.cc.

Referenced by produce().

◆ useEleKfTracks_

bool PATRefitVertexProducer::useEleKfTracks_
private

Definition at line 47 of file PATRefitVertexProducer.cc.

Referenced by produce().

◆ useLostTracks_

bool PATRefitVertexProducer::useLostTracks_
private

Definition at line 46 of file PATRefitVertexProducer.cc.

Referenced by produce().