CMS 3D CMS Logo

List of all members | Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Attributes
PFTauPrimaryVertexProducerBase Class Referenceabstract

#include <PFTauPrimaryVertexProducerBase.h>

Inheritance diagram for PFTauPrimaryVertexProducerBase:
edm::stream::EDProducer<> PFTauMiniAODPrimaryVertexProducer PFTauPrimaryVertexProducer

Classes

struct  DiscCutPair
 

Public Types

enum  Alg { useInputPV = 0, useFrontPV }
 
typedef std::vector< DiscCutPair * > DiscCutPairVec
 
- 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
 

Public Member Functions

virtual void beginEvent (const edm::Event &, const edm::EventSetup &)
 
 PFTauPrimaryVertexProducerBase (const edm::ParameterSet &iConfig)
 
void produce (edm::Event &, const edm::EventSetup &) override
 
 ~PFTauPrimaryVertexProducerBase () 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 edm::ParameterSetDescription getDescriptionsBase ()
 

Protected Member Functions

virtual void nonTauTracksInPV (const reco::VertexRef &, const std::vector< edm::Ptr< reco::TrackBase > > &, std::vector< const reco::Track *> &)=0
 

Private Attributes

int algorithm_
 
edm::EDGetTokenT< reco::BeamSpotbeamSpotToken_
 
std::unique_ptr< StringCutObjectSelector< reco::PFTau > > cut_
 
DiscCutPairVec discriminators_
 
edm::EDGetTokenT< edm::View< reco::Electron > > electronToken_
 
edm::EDGetTokenT< edm::View< reco::Muon > > muonToken_
 
edm::EDGetTokenT< std::vector< reco::PFTau > > pftauToken_
 
edm::EDGetTokenT< reco::VertexCollectionpvToken_
 
edm::ParameterSet qualityCutsPSet_
 
bool removeElectronTracks_
 
bool removeMuonTracks_
 
edm::ESGetToken< TransientTrackBuilder, TransientTrackRecordtransTrackBuilderToken_
 
bool useBeamSpot_
 
bool useSelectedTaus_
 
std::unique_ptr< reco::tau::RecoTauVertexAssociatorvertexAssociator_
 

Detailed Description

Definition at line 43 of file PFTauPrimaryVertexProducerBase.h.

Member Typedef Documentation

◆ DiscCutPairVec

Definition at line 55 of file PFTauPrimaryVertexProducerBase.h.

Member Enumeration Documentation

◆ Alg

Constructor & Destructor Documentation

◆ PFTauPrimaryVertexProducerBase()

PFTauPrimaryVertexProducerBase::PFTauPrimaryVertexProducerBase ( const edm::ParameterSet iConfig)
explicit

Definition at line 17 of file PFTauPrimaryVertexProducerBase.cc.

References PFTauPrimaryVertexProducerBase::DiscCutPair::cut_, cut_, PFTauPrimaryVertexProducerBase::DiscCutPair::cutFormula_, PDWG_TauSkim_cff::discriminators, discriminators_, edm::ParameterSet::exists(), edm::ParameterSet::getParameter(), PFTauPrimaryVertexProducerBase::DiscCutPair::inputToken_, muonDTDigis_cfi::pset, qualityCutsPSet_, AlCaHLTBitMon_QueryRunRegistry::string, and vertexAssociator_.

18  : pftauToken_(consumes<std::vector<reco::PFTau>>(iConfig.getParameter<edm::InputTag>("PFTauTag"))),
19  electronToken_(consumes<edm::View<reco::Electron>>(iConfig.getParameter<edm::InputTag>("ElectronTag"))),
20  muonToken_(consumes<edm::View<reco::Muon>>(iConfig.getParameter<edm::InputTag>("MuonTag"))),
21  pvToken_(consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("PVTag"))),
22  beamSpotToken_(consumes<reco::BeamSpot>(iConfig.getParameter<edm::InputTag>("beamSpot"))),
23  transTrackBuilderToken_(esConsumes(edm::ESInputTag("", "TransientTrackBuilder"))),
24  algorithm_(iConfig.getParameter<int>("Algorithm")),
25  qualityCutsPSet_(iConfig.getParameter<edm::ParameterSet>("qualityCuts")),
26  useBeamSpot_(iConfig.getParameter<bool>("useBeamSpot")),
27  useSelectedTaus_(iConfig.getParameter<bool>("useSelectedTaus")),
28  removeMuonTracks_(iConfig.getParameter<bool>("RemoveMuonTracks")),
29  removeElectronTracks_(iConfig.getParameter<bool>("RemoveElectronTracks")) {
31  std::vector<edm::ParameterSet> discriminators =
32  iConfig.getParameter<std::vector<edm::ParameterSet>>("discriminators");
33  // Build each of our cuts
34  for (auto const& pset : discriminators) {
35  DiscCutPair* newCut = new DiscCutPair();
36  newCut->inputToken_ = consumes<reco::PFTauDiscriminator>(pset.getParameter<edm::InputTag>("discriminator"));
37 
38  if (pset.existsAs<std::string>("selectionCut"))
39  newCut->cutFormula_ = new TFormula("selectionCut", pset.getParameter<std::string>("selectionCut").data());
40  else
41  newCut->cut_ = pset.getParameter<double>("selectionCut");
42  discriminators_.push_back(newCut);
43  }
44  // Build a string cut if desired
45  if (iConfig.exists("cut"))
46  cut_ = std::make_unique<StringCutObjectSelector<reco::PFTau>>(iConfig.getParameter<std::string>("cut"));
48  produces<edm::AssociationVector<reco::PFTauRefProd, std::vector<reco::VertexRef>>>();
49  produces<reco::VertexCollection>("PFTauPrimaryVertices");
50 
51  vertexAssociator_ = std::make_unique<reco::tau::RecoTauVertexAssociator>(qualityCutsPSet_, consumesCollector());
52 }
edm::EDGetTokenT< reco::BeamSpot > beamSpotToken_
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::EDGetTokenT< edm::View< reco::Muon > > muonToken_
bool exists(std::string const &parameterName) const
checks if a parameter exists
edm::EDGetTokenT< reco::VertexCollection > pvToken_
edm::ESGetToken< TransientTrackBuilder, TransientTrackRecord > transTrackBuilderToken_
edm::EDGetTokenT< std::vector< reco::PFTau > > pftauToken_
std::unique_ptr< reco::tau::RecoTauVertexAssociator > vertexAssociator_
std::unique_ptr< StringCutObjectSelector< reco::PFTau > > cut_
edm::EDGetTokenT< edm::View< reco::Electron > > electronToken_

◆ ~PFTauPrimaryVertexProducerBase()

PFTauPrimaryVertexProducerBase::~PFTauPrimaryVertexProducerBase ( )
override

Definition at line 54 of file PFTauPrimaryVertexProducerBase.cc.

54 {}

Member Function Documentation

◆ beginEvent()

virtual void PFTauPrimaryVertexProducerBase::beginEvent ( const edm::Event ,
const edm::EventSetup  
)
inlinevirtual

Reimplemented in PFTauMiniAODPrimaryVertexProducer.

Definition at line 64 of file PFTauPrimaryVertexProducerBase.h.

Referenced by produce().

64 {}

◆ getDescriptionsBase()

edm::ParameterSetDescription PFTauPrimaryVertexProducerBase::getDescriptionsBase ( )
static

Definition at line 225 of file PFTauPrimaryVertexProducerBase.cc.

References edm::ParameterSetDescription::add(), submitPVResolutionJobs::desc, reco::tau::RecoTauQualityCuts::fillDescriptions(), HLT_2022v15_cff::InputTag, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by PFTauPrimaryVertexProducer::fillDescriptions(), and PFTauMiniAODPrimaryVertexProducer::fillDescriptions().

225  {
226  // PFTauPrimaryVertexProducerBase
228 
229  {
231  vpsd1.add<edm::InputTag>("discriminator");
232  vpsd1.add<double>("selectionCut");
233  desc.addVPSet("discriminators", vpsd1);
234  }
235 
236  edm::ParameterSetDescription desc_qualityCuts;
238  desc.add<edm::ParameterSetDescription>("qualityCuts", desc_qualityCuts);
239 
240  desc.add<std::string>("cut", "pt > 18.0 & abs(eta)<2.3");
241  desc.add<int>("Algorithm", 0);
242  desc.add<bool>("RemoveElectronTracks", false);
243  desc.add<bool>("RemoveMuonTracks", false);
244  desc.add<bool>("useBeamSpot", true);
245  desc.add<bool>("useSelectedTaus", false);
246  desc.add<edm::InputTag>("beamSpot", edm::InputTag("offlineBeamSpot"));
247  desc.add<edm::InputTag>("ElectronTag", edm::InputTag("MyElectrons"));
248  desc.add<edm::InputTag>("PFTauTag", edm::InputTag("hpsPFTauProducer"));
249  desc.add<edm::InputTag>("MuonTag", edm::InputTag("MyMuons"));
250  desc.add<edm::InputTag>("PVTag", edm::InputTag("offlinePrimaryVertices"));
251 
252  return desc;
253 }
static void fillDescriptions(edm::ParameterSetDescription &descriptions)
Declare all parameters read from python config file.
ParameterDescriptionBase * add(U const &iLabel, T const &value)

◆ nonTauTracksInPV()

virtual void PFTauPrimaryVertexProducerBase::nonTauTracksInPV ( const reco::VertexRef ,
const std::vector< edm::Ptr< reco::TrackBase > > &  ,
std::vector< const reco::Track *> &   
)
protectedpure virtual

◆ produce()

void PFTauPrimaryVertexProducerBase::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
override

Definition at line 76 of file PFTauPrimaryVertexProducerBase.cc.

References algorithm_, pwdgSkimBPark_cfi::beamSpot, beamSpotToken_, beginEvent(), cut_, TtSemiLepEvtBuilder_cfi::disc, listHistos::discr, discriminators_, HPSPFTauProducerPuppi_cfi::electron, pwdgSkimBPark_cfi::electrons, electronToken_, edm::EventSetup::getData(), getTrack(), iEvent, edm::Ptr< T >::isNonnull(), edm::HandleBase::isValid(), TransientVertex::isValid(), eostools::move(), PDWG_BPHSkim_cff::muons, muonToken_, nonTauTracksInPV(), TriggerAnalyzer::passed, pfDeepBoostedJetPreprocessParams_cfi::pfcand, pftauToken_, TransientVertex::position(), pvToken_, edm::refToPtr(), removeElectronTracks_, removeMuonTracks_, AdaptiveVertexFitter::setWeightThreshold(), recoTrackAccumulator_cfi::signalTracks, metsig::tau, HLT_2022v15_cff::track, transTrackBuilderToken_, useBeamSpot_, useFrontPV, useInputPV, useSelectedTaus_, AdaptiveVertexFitter::vertex(), vertexAssociator_, AlignmentTracksFromVertexSelector_cfi::vertices, and PV3DBase< T, PVType, FrameType >::z().

76  {
77  beginEvent(iEvent, iSetup);
78 
79  // Obtain Collections
80  auto const& transTrackBuilder = iSetup.getData(transTrackBuilderToken_);
81 
83  iEvent.getByToken(pftauToken_, pfTaus);
84 
87  iEvent.getByToken(electronToken_, electrons);
88 
91  iEvent.getByToken(muonToken_, muons);
92 
94  iEvent.getByToken(pvToken_, vertices);
95 
97  if (useBeamSpot_)
98  iEvent.getByToken(beamSpotToken_, beamSpot);
99 
100  // Set Association Map
101  auto avPFTauPV = std::make_unique<edm::AssociationVector<reco::PFTauRefProd, std::vector<reco::VertexRef>>>(
102  reco::PFTauRefProd(pfTaus));
103  auto vertexCollection_out = std::make_unique<reco::VertexCollection>();
104  reco::VertexRefProd vertexRefProd_out = iEvent.getRefBeforePut<reco::VertexCollection>("PFTauPrimaryVertices");
105 
106  // Load each discriminator
107  for (auto& disc : discriminators_) {
109  iEvent.getByToken(disc->inputToken_, discr);
110  disc->discr_ = &(*discr);
111  }
112 
113  // Set event for VerexAssociator if needed
114  if (useInputPV == algorithm_)
115  vertexAssociator_->setEvent(iEvent);
116 
117  // For each Tau Run Algorithim
118  if (pfTaus.isValid()) {
119  for (reco::PFTauCollection::size_type iPFTau = 0; iPFTau < pfTaus->size(); iPFTau++) {
120  reco::PFTauRef tau(pfTaus, iPFTau);
121  reco::VertexRef thePVRef;
122  if (useInputPV == algorithm_) {
123  thePVRef = vertexAssociator_->associatedVertex(*tau);
124  } else if (useFrontPV == algorithm_) {
125  thePVRef = reco::VertexRef(vertices, 0);
126  }
127  reco::Vertex thePV = *thePVRef;
129  // Check if it passed all the discrimiantors
130  bool passed(true);
131  for (auto const& disc : discriminators_) {
132  // Check this discriminator passes
133  bool passedDisc = true;
134  if (disc->cutFormula_)
135  passedDisc = (disc->cutFormula_->Eval((*disc->discr_)[tau]) > 0.5);
136  else
137  passedDisc = ((*disc->discr_)[tau] > disc->cut_);
138  if (!passedDisc) {
139  passed = false;
140  break;
141  }
142  }
143  if (passed && cut_.get()) {
144  passed = (*cut_)(*tau);
145  }
146  if (passed) {
147  std::vector<edm::Ptr<reco::TrackBase>> signalTracks;
148  for (reco::PFTauCollection::size_type jPFTau = 0; jPFTau < pfTaus->size(); jPFTau++) {
149  if (useSelectedTaus_ || iPFTau == jPFTau) {
150  reco::PFTauRef pfTauRef(pfTaus, jPFTau);
152  // Get tracks from PFTau daughters
153  for (const auto& pfcand : pfTauRef->signalChargedHadrCands()) {
154  if (pfcand.isNull())
155  continue;
156  const edm::Ptr<reco::TrackBase>& trackPtr = getTrack(*pfcand);
157  if (trackPtr.isNonnull())
158  signalTracks.push_back(trackPtr);
159  }
160  }
161  }
162  // Get Muon tracks
163  if (removeMuonTracks_) {
164  if (muons.isValid()) {
165  for (const auto& muon : *muons) {
166  if (muon.track().isNonnull())
167  signalTracks.push_back(edm::refToPtr(muon.track()));
168  }
169  }
170  }
171  // Get Electron Tracks
172  if (removeElectronTracks_) {
173  if (electrons.isValid()) {
174  for (const auto& electron : *electrons) {
175  if (electron.track().isNonnull())
176  signalTracks.push_back(edm::refToPtr(electron.track()));
177  if (electron.gsfTrack().isNonnull())
178  signalTracks.push_back(edm::refToPtr(electron.gsfTrack()));
179  }
180  }
181  }
183  // Get Non-Tau tracks
184  std::vector<const reco::Track*> nonTauTracks;
185  nonTauTracksInPV(thePVRef, signalTracks, nonTauTracks);
186 
188  // Refit the vertex
189  TransientVertex transVtx;
190  std::vector<reco::TransientTrack> transTracks;
191  transTracks.reserve(nonTauTracks.size());
192  for (const auto track : nonTauTracks) {
193  transTracks.push_back(transTrackBuilder.build(*track));
194  }
195  bool fitOK(true);
196  if (transTracks.size() >= 2) {
198  avf.setWeightThreshold(0.1); //weight per track. allow almost every fit, else --> exception
199  if (!useBeamSpot_) {
200  transVtx = avf.vertex(transTracks);
201  } else {
202  transVtx = avf.vertex(transTracks, *beamSpot);
203  }
204  if (!transVtx.isValid()) {
205  fitOK = false;
206  } else {
207  //MB: protect against rare cases when transVtx is valid but its position is ill-defined
208  if (!std::isfinite(transVtx.position().z())) //MB: it is enough to check one coordinate (?)
209  fitOK = false;
210  }
211  } else
212  fitOK = false;
213  if (fitOK)
214  thePV = transVtx;
215  }
216  reco::VertexRef vtxRef = reco::VertexRef(vertexRefProd_out, vertexCollection_out->size());
217  vertexCollection_out->push_back(thePV);
218  avPFTauPV->setValue(iPFTau, vtxRef);
219  }
220  }
221  iEvent.put(std::move(vertexCollection_out), "PFTauPrimaryVertices");
222  iEvent.put(std::move(avPFTauPV));
223 }
edm::EDGetTokenT< reco::BeamSpot > beamSpotToken_
Ptr< typename C::value_type > refToPtr(Ref< C, typename C::value_type, refhelper::FindUsingAdvance< C, typename C::value_type > > const &ref)
Definition: RefToPtr.h:18
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
GlobalPoint position() const
edm::EDGetTokenT< edm::View< reco::Muon > > muonToken_
T z() const
Definition: PV3DBase.h:61
edm::EDGetTokenT< reco::VertexCollection > pvToken_
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
CachingVertex< 5 > vertex(const std::vector< reco::TransientTrack > &) const override
edm::RefProd< PFTauCollection > PFTauRefProd
references to PFTau collection
Definition: PFTauFwd.h:15
uint16_t size_type
virtual void beginEvent(const edm::Event &, const edm::EventSetup &)
edm::ESGetToken< TransientTrackBuilder, TransientTrackRecord > transTrackBuilderToken_
int iEvent
Definition: GenABIO.cc:224
bool isValid() const
bool isNonnull() const
Checks for non-null.
Definition: Ptr.h:146
edm::EDGetTokenT< std::vector< reco::PFTau > > pftauToken_
edm::Ref< VertexCollection > VertexRef
persistent reference to a Vertex
Definition: VertexFwd.h:13
static const TrackGhostTrackState * getTrack(const BasicGhostTrackState *basic)
std::unique_ptr< reco::tau::RecoTauVertexAssociator > vertexAssociator_
virtual void nonTauTracksInPV(const reco::VertexRef &, const std::vector< edm::Ptr< reco::TrackBase > > &, std::vector< const reco::Track *> &)=0
bool isValid() const
Definition: HandleBase.h:70
std::unique_ptr< StringCutObjectSelector< reco::PFTau > > cut_
edm::EDGetTokenT< edm::View< reco::Electron > > electronToken_
def move(src, dest)
Definition: eostools.py:511

Member Data Documentation

◆ algorithm_

int PFTauPrimaryVertexProducerBase::algorithm_
private

Definition at line 79 of file PFTauPrimaryVertexProducerBase.h.

Referenced by produce().

◆ beamSpotToken_

edm::EDGetTokenT<reco::BeamSpot> PFTauPrimaryVertexProducerBase::beamSpotToken_
private

Definition at line 77 of file PFTauPrimaryVertexProducerBase.h.

Referenced by produce().

◆ cut_

std::unique_ptr<StringCutObjectSelector<reco::PFTau> > PFTauPrimaryVertexProducerBase::cut_
private

Definition at line 86 of file PFTauPrimaryVertexProducerBase.h.

Referenced by PFTauPrimaryVertexProducerBase(), and produce().

◆ discriminators_

DiscCutPairVec PFTauPrimaryVertexProducerBase::discriminators_
private

Definition at line 85 of file PFTauPrimaryVertexProducerBase.h.

Referenced by PFTauPrimaryVertexProducerBase(), and produce().

◆ electronToken_

edm::EDGetTokenT<edm::View<reco::Electron> > PFTauPrimaryVertexProducerBase::electronToken_
private

Definition at line 74 of file PFTauPrimaryVertexProducerBase.h.

Referenced by produce().

◆ muonToken_

edm::EDGetTokenT<edm::View<reco::Muon> > PFTauPrimaryVertexProducerBase::muonToken_
private

Definition at line 75 of file PFTauPrimaryVertexProducerBase.h.

Referenced by produce().

◆ pftauToken_

edm::EDGetTokenT<std::vector<reco::PFTau> > PFTauPrimaryVertexProducerBase::pftauToken_
private

Definition at line 73 of file PFTauPrimaryVertexProducerBase.h.

Referenced by produce().

◆ pvToken_

edm::EDGetTokenT<reco::VertexCollection> PFTauPrimaryVertexProducerBase::pvToken_
private

Definition at line 76 of file PFTauPrimaryVertexProducerBase.h.

Referenced by produce().

◆ qualityCutsPSet_

edm::ParameterSet PFTauPrimaryVertexProducerBase::qualityCutsPSet_
private

Definition at line 80 of file PFTauPrimaryVertexProducerBase.h.

Referenced by PFTauPrimaryVertexProducerBase().

◆ removeElectronTracks_

bool PFTauPrimaryVertexProducerBase::removeElectronTracks_
private

Definition at line 84 of file PFTauPrimaryVertexProducerBase.h.

Referenced by produce().

◆ removeMuonTracks_

bool PFTauPrimaryVertexProducerBase::removeMuonTracks_
private

Definition at line 83 of file PFTauPrimaryVertexProducerBase.h.

Referenced by produce().

◆ transTrackBuilderToken_

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

Definition at line 78 of file PFTauPrimaryVertexProducerBase.h.

Referenced by produce().

◆ useBeamSpot_

bool PFTauPrimaryVertexProducerBase::useBeamSpot_
private

Definition at line 81 of file PFTauPrimaryVertexProducerBase.h.

Referenced by produce().

◆ useSelectedTaus_

bool PFTauPrimaryVertexProducerBase::useSelectedTaus_
private

Definition at line 82 of file PFTauPrimaryVertexProducerBase.h.

Referenced by produce().

◆ vertexAssociator_

std::unique_ptr<reco::tau::RecoTauVertexAssociator> PFTauPrimaryVertexProducerBase::vertexAssociator_
private

Definition at line 87 of file PFTauPrimaryVertexProducerBase.h.

Referenced by PFTauPrimaryVertexProducerBase(), and produce().