CMS 3D CMS Logo

PFTauPrimaryVertexProducerBase.cc
Go to the documentation of this file.
2 
6 
11 
15 
17 
18 #include <memory>
19 
21  : pftauToken_(consumes<std::vector<reco::PFTau>>(iConfig.getParameter<edm::InputTag>("PFTauTag"))),
22  electronToken_(consumes<edm::View<reco::Electron>>(iConfig.getParameter<edm::InputTag>("ElectronTag"))),
23  muonToken_(consumes<edm::View<reco::Muon>>(iConfig.getParameter<edm::InputTag>("MuonTag"))),
24  pvToken_(consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("PVTag"))),
25  beamSpotToken_(consumes<reco::BeamSpot>(iConfig.getParameter<edm::InputTag>("beamSpot"))),
26  algorithm_(iConfig.getParameter<int>("Algorithm")),
27  qualityCutsPSet_(iConfig.getParameter<edm::ParameterSet>("qualityCuts")),
28  useBeamSpot_(iConfig.getParameter<bool>("useBeamSpot")),
29  useSelectedTaus_(iConfig.getParameter<bool>("useSelectedTaus")),
30  removeMuonTracks_(iConfig.getParameter<bool>("RemoveMuonTracks")),
31  removeElectronTracks_(iConfig.getParameter<bool>("RemoveElectronTracks")) {
33  std::vector<edm::ParameterSet> discriminators =
34  iConfig.getParameter<std::vector<edm::ParameterSet>>("discriminators");
35  // Build each of our cuts
36  for (auto const& pset : discriminators) {
37  DiscCutPair* newCut = new DiscCutPair();
38  newCut->inputToken_ = consumes<reco::PFTauDiscriminator>(pset.getParameter<edm::InputTag>("discriminator"));
39 
40  if (pset.existsAs<std::string>("selectionCut"))
41  newCut->cutFormula_ = new TFormula("selectionCut", pset.getParameter<std::string>("selectionCut").data());
42  else
43  newCut->cut_ = pset.getParameter<double>("selectionCut");
44  discriminators_.push_back(newCut);
45  }
46  // Build a string cut if desired
47  if (iConfig.exists("cut"))
48  cut_ = std::make_unique<StringCutObjectSelector<reco::PFTau>>(iConfig.getParameter<std::string>("cut"));
50  produces<edm::AssociationVector<reco::PFTauRefProd, std::vector<reco::VertexRef>>>();
51  produces<reco::VertexCollection>("PFTauPrimaryVertices");
52 
53  vertexAssociator_ = std::make_unique<reco::tau::RecoTauVertexAssociator>(qualityCutsPSet_, consumesCollector());
54 }
55 
57 
58 namespace {
60  const reco::PFCandidate* pfCandPtr = dynamic_cast<const reco::PFCandidate*>(&cand);
61  if (pfCandPtr) {
62  if (pfCandPtr->trackRef().isNonnull())
63  return edm::refToPtr(pfCandPtr->trackRef());
64  else if (pfCandPtr->gsfTrackRef().isNonnull())
65  return edm::refToPtr(pfCandPtr->gsfTrackRef());
66  else
68  }
69  const pat::PackedCandidate* pCand = dynamic_cast<const pat::PackedCandidate*>(&cand);
70  if (pCand && pCand->hasTrackDetails()) {
71  const reco::TrackBase* trkPtr = pCand->bestTrack();
72  return edm::Ptr<reco::TrackBase>(trkPtr, 0);
73  }
75  }
76 } // namespace
77 
79  beginEvent(iEvent, iSetup);
80 
81  // Obtain Collections
82  edm::ESHandle<TransientTrackBuilder> transTrackBuilder;
83  iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder", transTrackBuilder);
84 
86  iEvent.getByToken(pftauToken_, pfTaus);
87 
90  iEvent.getByToken(electronToken_, electrons);
91 
94  iEvent.getByToken(muonToken_, muons);
95 
97  iEvent.getByToken(pvToken_, vertices);
98 
100  if (useBeamSpot_)
101  iEvent.getByToken(beamSpotToken_, beamSpot);
102 
103  // Set Association Map
104  auto avPFTauPV = std::make_unique<edm::AssociationVector<reco::PFTauRefProd, std::vector<reco::VertexRef>>>(
105  reco::PFTauRefProd(pfTaus));
106  auto vertexCollection_out = std::make_unique<reco::VertexCollection>();
107  reco::VertexRefProd vertexRefProd_out = iEvent.getRefBeforePut<reco::VertexCollection>("PFTauPrimaryVertices");
108 
109  // Load each discriminator
110  for (auto& disc : discriminators_) {
112  iEvent.getByToken(disc->inputToken_, discr);
113  disc->discr_ = &(*discr);
114  }
115 
116  // Set event for VerexAssociator if needed
117  if (useInputPV == algorithm_)
118  vertexAssociator_->setEvent(iEvent);
119 
120  // For each Tau Run Algorithim
121  if (pfTaus.isValid()) {
122  for (reco::PFTauCollection::size_type iPFTau = 0; iPFTau < pfTaus->size(); iPFTau++) {
123  reco::PFTauRef tau(pfTaus, iPFTau);
124  reco::VertexRef thePVRef;
125  if (useInputPV == algorithm_) {
126  thePVRef = vertexAssociator_->associatedVertex(*tau);
127  } else if (useFrontPV == algorithm_) {
128  thePVRef = reco::VertexRef(vertices, 0);
129  }
130  reco::Vertex thePV = *thePVRef;
132  // Check if it passed all the discrimiantors
133  bool passed(true);
134  for (auto const& disc : discriminators_) {
135  // Check this discriminator passes
136  bool passedDisc = true;
137  if (disc->cutFormula_)
138  passedDisc = (disc->cutFormula_->Eval((*disc->discr_)[tau]) > 0.5);
139  else
140  passedDisc = ((*disc->discr_)[tau] > disc->cut_);
141  if (!passedDisc) {
142  passed = false;
143  break;
144  }
145  }
146  if (passed && cut_.get()) {
147  passed = (*cut_)(*tau);
148  }
149  if (passed) {
150  std::vector<edm::Ptr<reco::TrackBase>> signalTracks;
151  for (reco::PFTauCollection::size_type jPFTau = 0; jPFTau < pfTaus->size(); jPFTau++) {
152  if (useSelectedTaus_ || iPFTau == jPFTau) {
153  reco::PFTauRef pfTauRef(pfTaus, jPFTau);
155  // Get tracks from PFTau daughters
156  for (const auto& pfcand : pfTauRef->signalChargedHadrCands()) {
157  if (pfcand.isNull())
158  continue;
159  const edm::Ptr<reco::TrackBase>& trackPtr = getTrack(*pfcand);
160  if (trackPtr.isNonnull())
161  signalTracks.push_back(trackPtr);
162  }
163  }
164  }
165  // Get Muon tracks
166  if (removeMuonTracks_) {
167  if (muons.isValid()) {
168  for (const auto& muon : *muons) {
169  if (muon.track().isNonnull())
170  signalTracks.push_back(edm::refToPtr(muon.track()));
171  }
172  }
173  }
174  // Get Electron Tracks
175  if (removeElectronTracks_) {
176  if (electrons.isValid()) {
177  for (const auto& electron : *electrons) {
178  if (electron.track().isNonnull())
179  signalTracks.push_back(edm::refToPtr(electron.track()));
180  if (electron.gsfTrack().isNonnull())
181  signalTracks.push_back(edm::refToPtr(electron.gsfTrack()));
182  }
183  }
184  }
186  // Get Non-Tau tracks
187  std::vector<const reco::Track*> nonTauTracks;
188  nonTauTracksInPV(thePVRef, signalTracks, nonTauTracks);
189 
191  // Refit the vertex
192  TransientVertex transVtx;
193  std::vector<reco::TransientTrack> transTracks;
194  transTracks.reserve(nonTauTracks.size());
195  for (const auto track : nonTauTracks) {
196  transTracks.push_back(transTrackBuilder->build(*track));
197  }
198  bool fitOK(true);
199  if (transTracks.size() >= 2) {
201  avf.setWeightThreshold(0.1); //weight per track. allow almost every fit, else --> exception
202  if (!useBeamSpot_) {
203  transVtx = avf.vertex(transTracks);
204  } else {
205  transVtx = avf.vertex(transTracks, *beamSpot);
206  }
207  if (!transVtx.isValid()) {
208  fitOK = false;
209  } else {
210  //MB: protect against rare cases when transVtx is valid but its position is ill-defined
211  if (!std::isfinite(transVtx.position().z())) //MB: it is enough to check one coordinate (?)
212  fitOK = false;
213  }
214  } else
215  fitOK = false;
216  if (fitOK)
217  thePV = transVtx;
218  }
219  reco::VertexRef vtxRef = reco::VertexRef(vertexRefProd_out, vertexCollection_out->size());
220  vertexCollection_out->push_back(thePV);
221  avPFTauPV->setValue(iPFTau, vtxRef);
222  }
223  }
224  iEvent.put(std::move(vertexCollection_out), "PFTauPrimaryVertices");
225  iEvent.put(std::move(avPFTauPV));
226 }
227 
229  // PFTauPrimaryVertexProducerBase
231 
232  {
234  vpsd1.add<edm::InputTag>("discriminator");
235  vpsd1.add<double>("selectionCut");
236  desc.addVPSet("discriminators", vpsd1);
237  }
238 
239  edm::ParameterSetDescription desc_qualityCuts;
241  desc.add<edm::ParameterSetDescription>("qualityCuts", desc_qualityCuts);
242 
243  desc.add<std::string>("cut", "pt > 18.0 & abs(eta)<2.3");
244  desc.add<int>("Algorithm", 0);
245  desc.add<bool>("RemoveElectronTracks", false);
246  desc.add<bool>("RemoveMuonTracks", false);
247  desc.add<bool>("useBeamSpot", true);
248  desc.add<bool>("useSelectedTaus", false);
249  desc.add<edm::InputTag>("beamSpot", edm::InputTag("offlineBeamSpot"));
250  desc.add<edm::InputTag>("ElectronTag", edm::InputTag("MyElectrons"));
251  desc.add<edm::InputTag>("PFTauTag", edm::InputTag("hpsPFTauProducer"));
252  desc.add<edm::InputTag>("MuonTag", edm::InputTag("MyMuons"));
253  desc.add<edm::InputTag>("PVTag", edm::InputTag("offlinePrimaryVertices"));
254 
255  return desc;
256 }
AdaptiveVertexFitter
Definition: AdaptiveVertexFitter.h:29
reco::PFCandidate::trackRef
reco::TrackRef trackRef() const
Definition: PFCandidate.cc:408
edm::RefProd< VertexCollection >
RefProd.h
PFTauPrimaryVertexProducerBase::cut_
std::unique_ptr< StringCutObjectSelector< reco::PFTau > > cut_
Definition: PFTauPrimaryVertexProducerBase.h:82
pat::PackedCandidate::hasTrackDetails
bool hasTrackDetails() const
Return true if a bestTrack can be extracted from this Candidate.
Definition: PackedCandidate.h:788
PDWG_BPHSkim_cff.muons
muons
Definition: PDWG_BPHSkim_cff.py:47
PFTauPrimaryVertexProducerBase::algorithm_
int algorithm_
Definition: PFTauPrimaryVertexProducerBase.h:75
electrons_cff.bool
bool
Definition: electrons_cff.py:366
edm::ParameterSetDescription::add
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:95
pwdgSkimBPark_cfi.beamSpot
beamSpot
Definition: pwdgSkimBPark_cfi.py:5
PFTauPrimaryVertexProducerBase::removeMuonTracks_
bool removeMuonTracks_
Definition: PFTauPrimaryVertexProducerBase.h:79
HLT_FULL_cff.track
track
Definition: HLT_FULL_cff.py:11713
PFTauPrimaryVertexProducerBase::useInputPV
Definition: PFTauPrimaryVertexProducerBase.h:42
MessageLogger.h
PFTauPrimaryVertexProducerBase::DiscCutPair
Definition: PFTauPrimaryVertexProducerBase.h:44
ESHandle.h
align::BeamSpot
Definition: StructureType.h:95
sistrip::View
View
Definition: ConstantsForView.h:26
metsig::tau
Definition: SignAlgoResolutions.h:49
muon
Definition: MuonCocktails.h:17
TransientVertex::isValid
bool isValid() const
Definition: TransientVertex.h:195
PFTauPrimaryVertexProducerBase::qualityCutsPSet_
edm::ParameterSet qualityCutsPSet_
Definition: PFTauPrimaryVertexProducerBase.h:76
Electron
Definition: Electron.py:1
edm
HLT enums.
Definition: AlignableModifier.h:19
reco::VertexCollection
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
PDWG_TauSkim_cff.discriminators
discriminators
Definition: PDWG_TauSkim_cff.py:6
PFTauPrimaryVertexProducerBase::pftauToken_
edm::EDGetTokenT< std::vector< reco::PFTau > > pftauToken_
Definition: PFTauPrimaryVertexProducerBase.h:70
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89285
reco::PFTauRefProd
edm::RefProd< PFTauCollection > PFTauRefProd
references to PFTau collection
Definition: PFTauFwd.h:15
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
recoTrackAccumulator_cfi.signalTracks
signalTracks
Definition: recoTrackAccumulator_cfi.py:10
TransientVertex::position
GlobalPoint position() const
Definition: TransientVertex.h:169
PFTauPrimaryVertexProducerBase::muonToken_
edm::EDGetTokenT< edm::View< reco::Muon > > muonToken_
Definition: PFTauPrimaryVertexProducerBase.h:72
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
PFTauPrimaryVertexProducerBase::nonTauTracksInPV
virtual void nonTauTracksInPV(const reco::VertexRef &, const std::vector< edm::Ptr< reco::TrackBase > > &, std::vector< const reco::Track * > &)=0
AdaptiveVertexFitter::vertex
CachingVertex< 5 > vertex(const std::vector< reco::TransientTrack > &) const override
Definition: AdaptiveVertexFitter.cc:158
edm::Handle
Definition: AssociativeIterator.h:50
PFTauPrimaryVertexProducerBase::~PFTauPrimaryVertexProducerBase
~PFTauPrimaryVertexProducerBase() override
Definition: PFTauPrimaryVertexProducerBase.cc:56
TtSemiLepEvtBuilder_cfi.disc
disc
Definition: TtSemiLepEvtBuilder_cfi.py:60
Muon
Definition: Muon.py:1
edm::Ref< PFTauCollection >
pfDeepBoostedJetPreprocessParams_cfi.pfcand
pfcand
Definition: pfDeepBoostedJetPreprocessParams_cfi.py:8
PFTauPrimaryVertexProducerBase::beginEvent
virtual void beginEvent(const edm::Event &, const edm::EventSetup &)
Definition: PFTauPrimaryVertexProducerBase.h:61
PFTauPrimaryVertexProducerBase::useSelectedTaus_
bool useSelectedTaus_
Definition: PFTauPrimaryVertexProducerBase.h:78
PV3DBase::z
T z() const
Definition: PV3DBase.h:61
edm::refToPtr
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
PFTauPrimaryVertexProducerBase::useBeamSpot_
bool useBeamSpot_
Definition: PFTauPrimaryVertexProducerBase.h:77
trigger::size_type
uint16_t size_type
Definition: TriggerTypeDefs.h:18
edm::EventSetup::get
T get() const
Definition: EventSetup.h:87
pat::PackedCandidate::bestTrack
const reco::Track * bestTrack() const override
return a pointer to the track if present. otherwise, return a null pointer
Definition: PackedCandidate.h:780
listHistos.discr
discr
Definition: listHistos.py:51
PFTauPrimaryVertexProducerBase::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: PFTauPrimaryVertexProducerBase.cc:78
PFTauPrimaryVertexProducerBase::useFrontPV
Definition: PFTauPrimaryVertexProducerBase.h:42
TransientTrackRecord
Definition: TransientTrackRecord.h:11
PFTauPrimaryVertexProducerBase::PFTauPrimaryVertexProducerBase
PFTauPrimaryVertexProducerBase(const edm::ParameterSet &iConfig)
Definition: PFTauPrimaryVertexProducerBase.cc:20
metsig::electron
Definition: SignAlgoResolutions.h:48
edm::ESHandle< TransientTrackBuilder >
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::ParameterSet::exists
bool exists(std::string const &parameterName) const
checks if a parameter exists
Definition: ParameterSet.cc:681
TransientTrackBuilder.h
edm::ParameterSet
Definition: ParameterSet.h:47
reco::PFCandidate::gsfTrackRef
reco::GsfTrackRef gsfTrackRef() const
Definition: PFCandidate.cc:440
ParameterSet
Definition: Functions.h:16
pat::PackedCandidate
Definition: PackedCandidate.h:22
PackedCandidate.h
edm::Ref::isNonnull
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
reco::VertexRef
edm::Ref< VertexCollection > VertexRef
persistent reference to a Vertex
Definition: VertexFwd.h:13
cand
Definition: decayParser.h:32
createfilelist.int
int
Definition: createfilelist.py:10
iEvent
int iEvent
Definition: GenABIO.cc:224
RefToPtr.h
reco::TrackBase
Definition: TrackBase.h:62
PFTauPrimaryVertexProducerBase::electronToken_
edm::EDGetTokenT< edm::View< reco::Electron > > electronToken_
Definition: PFTauPrimaryVertexProducerBase.h:71
reco::tau::RecoTauQualityCuts::fillDescriptions
static void fillDescriptions(edm::ParameterSetDescription &descriptions)
Declare all parameters read from python config file.
Definition: RecoTauQualityCuts.cc:346
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
AdaptiveVertexFitter::setWeightThreshold
void setWeightThreshold(float w)
Definition: AdaptiveVertexFitter.cc:119
TransientVertex
Definition: TransientVertex.h:18
edm::EventSetup
Definition: EventSetup.h:58
PFTauPrimaryVertexProducerBase::DiscCutPair::cutFormula_
TFormula * cutFormula_
Definition: PFTauPrimaryVertexProducerBase.h:50
TransientTrackRecord.h
get
#define get
edm::Ptr
Definition: AssociationVector.h:31
reco::Candidate
Definition: Candidate.h:27
PFTauPrimaryVertexProducerBase::DiscCutPair::cut_
double cut_
Definition: PFTauPrimaryVertexProducerBase.h:49
getTrack
static const TrackGhostTrackState * getTrack(const BasicGhostTrackState *basic)
Definition: GhostTrackState.cc:49
PFTauPrimaryVertexProducerBase.h
TransientVertex.h
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
pwdgSkimBPark_cfi.electrons
electrons
Definition: pwdgSkimBPark_cfi.py:6
PFTauPrimaryVertexProducerBase::getDescriptionsBase
static edm::ParameterSetDescription getDescriptionsBase()
Definition: PFTauPrimaryVertexProducerBase.cc:228
StringCutObjectSelector< reco::PFTau >
TriggerAnalyzer.passed
passed
Definition: TriggerAnalyzer.py:62
edm::Ptr::isNonnull
bool isNonnull() const
Checks for non-null.
Definition: Ptr.h:146
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
Exception.h
PFTauPrimaryVertexProducerBase::removeElectronTracks_
bool removeElectronTracks_
Definition: PFTauPrimaryVertexProducerBase.h:80
reco::PFCandidate
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:41
RecoPFTauTag_cff.PFTau
PFTau
Definition: RecoPFTauTag_cff.py:121
TransientTrackBuilder::build
reco::TransientTrack build(const reco::Track *p) const
Definition: TransientTrackBuilder.cc:20
AssociationVector.h
PFTauPrimaryVertexProducerBase::discriminators_
DiscCutPairVec discriminators_
Definition: PFTauPrimaryVertexProducerBase.h:81
PFTauPrimaryVertexProducerBase::DiscCutPair::inputToken_
edm::EDGetTokenT< reco::PFTauDiscriminator > inputToken_
Definition: PFTauPrimaryVertexProducerBase.h:48
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
PFTauPrimaryVertexProducerBase::vertexAssociator_
std::unique_ptr< reco::tau::RecoTauVertexAssociator > vertexAssociator_
Definition: PFTauPrimaryVertexProducerBase.h:83
edm::Event
Definition: Event.h:73
AdaptiveVertexFitter.h
edm::InputTag
Definition: InputTag.h:15
reco::Vertex
Definition: Vertex.h:35
PFTauPrimaryVertexProducerBase::pvToken_
edm::EDGetTokenT< reco::VertexCollection > pvToken_
Definition: PFTauPrimaryVertexProducerBase.h:73
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
pwdgSkimBPark_cfi.vertices
vertices
Definition: pwdgSkimBPark_cfi.py:7
PFTauPrimaryVertexProducerBase::beamSpotToken_
edm::EDGetTokenT< reco::BeamSpot > beamSpotToken_
Definition: PFTauPrimaryVertexProducerBase.h:74