CMS 3D CMS Logo

RecoTauDiscriminationByFlight.cc
Go to the documentation of this file.
4 
12 
14  public:
17  void beginEvent(const edm::Event& evt, const edm::EventSetup& es) override;
18  double discriminate(const reco::PFTauRef&) const override;
19  private:
25  double oneProngSig_;
27  bool refitPV_;
28 };
29 
32  vertexSource_ = pset.getParameter<edm::InputTag>("vertexSource");
33  oneProngSig_ = pset.exists("oneProngSigCut") ?
34  pset.getParameter<double>("oneProngSigCut") : -1.;
35  threeProngSig_ = pset.exists("threeProngSigCut") ?
36  pset.getParameter<double>("threeProngSigCut") : -1.;
37  refitPV_ = pset.getParameter<bool>("refitPV");
38  if (refitPV_)
39  bsSource_ = pset.getParameter<edm::InputTag>("beamspot");
40 }
41 
43  const edm::Event& evt, const edm::EventSetup& es) {
45  if (refitPV_)
47  edm::ESHandle<TransientTrackBuilder> transTrackBuilder;
48  es.get<TransientTrackRecord>().get("TransientTrackBuilder",transTrackBuilder);
49  builder_ = transTrackBuilder.product();
50 }
51 
53  const reco::PFTauRef& tau) const {
54 
55  KalmanVertexFitter kvf(true);
56  const std::vector<reco::PFCandidatePtr>& signalTracks =
57  tau->signalPFChargedHadrCands();
58  std::vector<reco::TransientTrack> signalTransTracks;
59  std::vector<reco::TrackRef> signalTrackPtrs;
60  for(auto const& pftrack : signalTracks) {
61  if (pftrack->trackRef().isNonnull()) {
62  signalTransTracks.push_back(
63  builder_->build(pftrack->trackRef()));
64  signalTrackPtrs.push_back(pftrack->trackRef());
65  }
66  }
67 
68  reco::Vertex pv = (*vertices_)[0];
69 
70  if (refitPV_) {
71  std::vector<reco::TrackRef> pvTrackRefs;
73  pvTrack != pv.tracks_end(); ++pvTrack ) {
74  pvTrackRefs.push_back(pvTrack->castTo<reco::TrackRef>());
75  }
76  // Get PV tracks not associated to the tau
77  std::sort(signalTrackPtrs.begin(), signalTrackPtrs.end());
78  std::sort(pvTrackRefs.begin(), pvTrackRefs.end());
79  std::vector<reco::TrackRef> uniquePVTracks;
80  uniquePVTracks.reserve(pvTrackRefs.size());
81  std::set_difference(pvTrackRefs.begin(), pvTrackRefs.end(),
82  signalTrackPtrs.begin(), signalTrackPtrs.end(),
83  std::back_inserter(uniquePVTracks));
84  // Check if we need to refit
85  if (uniquePVTracks.size() != pvTrackRefs.size()) {
86  std::vector<reco::TransientTrack> pvTransTracks;
87  // Build all our unique transient tracks in the PV
88  for(auto const& track : pvTrackRefs) {
89  pvTransTracks.push_back(builder_->build(track));
90  }
91  // Refit our PV
92  TransientVertex newPV = kvf.vertex(pvTransTracks, *beamspot_);
93  pv = newPV;
94  }
95  }
96 
97  // The tau direction, to determine the sign of the IP.
98  // In the case that it is a one prong, take the jet direction.
99  // This may give better result due to out-of-cone stuff.
100  GlobalVector direction = (tau->signalPFCands().size() == 1 ?
101  GlobalVector(
102  tau->jetRef()->px(), tau->jetRef()->py(), tau->jetRef()->pz()) :
103  GlobalVector(tau->px(), tau->py(), tau->pz()));
104 
105  // Now figure out of we are doing a SV fit or an IP significance
106  if (signalTransTracks.size() == 1) {
107  reco::TransientTrack track = signalTransTracks.front();
108  std::pair<bool,Measurement1D> ipsig =
109  IPTools::signedTransverseImpactParameter(track, direction, pv);
110  if (ipsig.first)
111  return ipsig.second.significance();
112  else
114  } else if (signalTransTracks.size() == 3) {
115  // Fit the decay vertex of the three prong
116  TransientVertex sv = kvf.vertex(signalTransTracks);
117  // the true parameter indicates include PV errors
119  pv, sv, direction, true);
120  double significance = svDist.significance();
121  // Make sure it is a sane value
122  if (significance > 40)
123  significance = 40;
124  if (significance < -20)
125  significance = -20;
126  return significance;
127  } else {
128  // Weird two prong or something
130  }
131 }
132 
T getParameter(std::string const &) const
edm::Handle< reco::VertexCollection > vertices_
PFRecoTauDiscriminationByFlight(const edm::ParameterSet &pset)
trackRef_iterator tracks_end() const
last iterator over tracks
Definition: Vertex.cc:81
void beginEvent(const edm::Event &evt, const edm::EventSetup &es) override
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::pair< bool, Measurement1D > signedTransverseImpactParameter(const reco::TransientTrack &track, const GlobalVector &direction, const reco::Vertex &vertex)
Definition: IPTools.cc:50
reco::TransientTrack build(const reco::Track *p) const
bool exists(std::string const &parameterName) const
checks if a parameter exists
static Measurement1D computeDist2d(const reco::Vertex &pv, const SV &sv, const GlobalVector &direction, bool withPVError)
def pv(vc)
Definition: MetAnalyzer.py:7
CachingVertex< 5 > vertex(const std::vector< reco::TransientTrack > &tracks) const override
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:535
double significance() const
Definition: Measurement1D.h:32
double discriminate(const reco::PFTauRef &) const override
significance
Definition: met_cff.py:30
T get() const
Definition: EventSetup.h:68
std::vector< TrackBaseRef >::const_iterator trackRef_iterator
The iteratator for the vector<TrackRef>
Definition: Vertex.h:37
trackRef_iterator tracks_begin() const
first iterator over tracks
Definition: Vertex.cc:76
T const * product() const
Definition: ESHandle.h:84
Global3DVector GlobalVector
Definition: GlobalVector.h:10