CMS 3D CMS Logo

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