CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TrackVertexArbitratration.h
Go to the documentation of this file.
1 #ifndef TrackVertexArbitration_H
2 #define TrackVertexArbitration_H
3 #include <memory>
4 #include <set>
5 
6 
12 
13 
19 
26 
27 
33 
40 
41 //#include "DataFormats/Math/interface/deltaR.h"
42 
43 //#define VTXDEBUG
44 
45 template <class VTX>
47  public:
49 
50 
51  std::vector<VTX> trackVertexArbitrator(
53  const reco::Vertex &pv,
54  std::vector<reco::TransientTrack> & selectedTracks,
55  std::vector<VTX> & secondaryVertices
56  );
57 
58 
59  private:
60  bool trackFilterArbitrator(const reco::TransientTrack &track) const;
61 
66  double dRCut;
67  double distCut;
68  double sigCut;
69  double dLenFraction;
70  double fitterSigmacut; // = 3.0;
71  double fitterTini; // = 256.;
72  double fitterRatio;// = 0.25;
74  double trackMinPt;
76 };
77 
79 template <class VTX>
81  primaryVertexCollection (params.getParameter<edm::InputTag>("primaryVertices")),
82  secondaryVertexCollection (params.getParameter<edm::InputTag>("secondaryVertices")),
83  trackCollection (params.getParameter<edm::InputTag>("tracks")),
84  beamSpotCollection (params.getParameter<edm::InputTag>("beamSpot")),
85  dRCut (params.getParameter<double>("dRCut")),
86  distCut (params.getParameter<double>("distCut")),
87  sigCut (params.getParameter<double>("sigCut")),
88  dLenFraction (params.getParameter<double>("dLenFraction")),
89  fitterSigmacut (params.getParameter<double>("fitterSigmacut")),
90  fitterTini (params.getParameter<double>("fitterTini")),
91  fitterRatio (params.getParameter<double>("fitterRatio")),
92  trackMinLayers (params.getParameter<int32_t>("trackMinLayers")),
93  trackMinPt (params.getParameter<double>("trackMinPt")),
94  trackMinPixels (params.getParameter<int32_t>("trackMinPixels"))
95 {
96  dRCut*=dRCut;
97 }
98 template <class VTX>
100 {
101  if(!track.isValid())
102  return false;
104  return false;
105  if (track.track().pt() < trackMinPt)
106  return false;
108  return false;
109 
110  return true;
111 }
112 
113 float trackWeight(const reco::Vertex & sv, const reco::TransientTrack &track)
114 {
115  return sv.trackWeight(track.trackBaseRef());
116 }
118 {
120  if ( cptt==0 )
121  edm::LogError("DynamicCastingFailed") << "Casting of TransientTrack to CandidatePtrTransientTrack failed!";
122  else
123  {
124  const reco::CandidatePtr & c=cptt->candidate();
125  if(std::find(sv.daughterPtrVector().begin(),sv.daughterPtrVector().end(),c)!= sv.daughterPtrVector().end())
126  return 1.0;
127  else
128  return 0;
129  }
130 return 0;
131 }
132 
133 
134 
135 template <class VTX>
138  const reco::Vertex &pv,
139  std::vector<reco::TransientTrack> & selectedTracks,
140  std::vector<VTX> & secondaryVertices)
141 {
142  using namespace reco;
143 
144  //std::cout << "PV: " << pv.position() << std::endl;
145  VertexDistance3D dist;
146  AdaptiveVertexFitter theAdaptiveFitter(
152 
153 
154 
155  std::vector<VTX> recoVertices;
156  VertexDistance3D vdist;
157  GlobalPoint ppv(pv.position().x(),pv.position().y(),pv.position().z());
158 
159  std::map<unsigned int, Measurement1D> cachedIP;
160  for(typename std::vector<VTX>::const_iterator sv = secondaryVertices.begin();
161  sv != secondaryVertices.end(); ++sv) {
162 
163  GlobalPoint ssv(sv->position().x(),sv->position().y(),sv->position().z());
164  GlobalVector flightDir = ssv-ppv;
165 // std::cout << "Vertex : " << sv-secondaryVertices->begin() << " " << sv->position() << std::endl;
166  Measurement1D dlen= vdist.distance(pv,VertexState(RecoVertex::convertPos(sv->position()),RecoVertex::convertError(sv->error())));
167  std::vector<reco::TransientTrack> selTracks;
168  for(unsigned int itrack = 0; itrack < selectedTracks.size(); itrack++){
169  TransientTrack & tt = (selectedTracks)[itrack];
170  if (!trackFilterArbitrator(tt)) continue;
171  tt.setBeamSpot(*beamSpot);
172  float w = trackWeight(*sv,tt);
173  Measurement1D ipv;
174  if(cachedIP.find(itrack)!=cachedIP.end()) {
175  ipv=cachedIP[itrack];
176  } else {
177  std::pair<bool,Measurement1D> ipvp = IPTools::absoluteImpactParameter3D(tt,pv);
178  cachedIP[itrack]=ipvp.second;
179  ipv=ipvp.second;
180  }
181 
182  AnalyticalImpactPointExtrapolator extrapolator(tt.field());
183  TrajectoryStateOnSurface tsos = extrapolator.extrapolate(tt.impactPointState(), RecoVertex::convertPos(sv->position()));
184  if(! tsos.isValid()) continue;
185  GlobalPoint refPoint = tsos.globalPosition();
186  GlobalError refPointErr = tsos.cartesianError().position();
187  Measurement1D isv = dist.distance(VertexState(RecoVertex::convertPos(sv->position()),RecoVertex::convertError(sv->error())),VertexState(refPoint, refPointErr));
188 
189  float dR = Geom::deltaR2(flightDir,tt.track()); //.eta(), flightDir.phi(), tt.track().eta(), tt.track().phi());
190 
191  if( w > 0 || ( isv.significance() < sigCut && isv.value() < distCut && isv.value() < dlen.value()*dLenFraction ) )
192  {
193 
194  if(( isv.value() < ipv.value() ) && isv.value() < distCut && isv.value() < dlen.value()*dLenFraction
195  && dR < dRCut )
196  {
197 #ifdef VTXDEBUG
198  if(w > 0.5) std::cout << " = ";
199  else std::cout << " + ";
200 #endif
201  selTracks.push_back(tt);
202  } else
203  {
204 #ifdef VTXDEBUG
205  if(w > 0.5 && isv.value() > ipv.value() ) std::cout << " - ";
206  else std::cout << " ";
207 #endif
208  //add also the tracks used in previous fitting that are still closer to Sv than Pv
209  if(w > 0.5 && isv.value() <= ipv.value() && dR < dRCut) {
210  selTracks.push_back(tt);
211 #ifdef VTXDEBUG
212  std::cout << " = ";
213 #endif
214  }
215  if(w > 0.5 && isv.value() <= ipv.value() && dR >= dRCut) {
216 #ifdef VTXDEBUG
217  std::cout << " - ";
218 #endif
219 
220  }
221 
222 
223  }
224 #ifdef VTXDEBUG
225 
226  std::cout << "t : " << itrack << " ref " << ref.key() << " w: " << w
227  << " svip: " << isv.significance() << " " << isv.value()
228  << " pvip: " << ipv.significance() << " " << ipv.value() << " res " << tt.track().residualX(0) << "," << tt.track().residualY(0)
229 // << " tpvip: " << itpv.second.significance() << " " << itpv.second.value() << " dr: " << dR << std::endl;
230 #endif
231 
232  }
233  else
234  {
235 #ifdef VTXDEBUG
236 
237  std::cout << " . t : " << itrack << " ref " << ref.key()<< " w: " << w
238  << " svip: " << isv.second.significance() << " " << isv.second.value()
239  << " pvip: " << ipv.significance() << " " << ipv.value() << " dr: " << dR << std::endl;
240 #endif
241 
242  }
243  }
244 
245  if(selTracks.size() >= 2)
246  {
247  TransientVertex singleFitVertex;
248  singleFitVertex = theAdaptiveFitter.vertex(selTracks,ssv);
249  if(singleFitVertex.isValid()) { recoVertices.push_back(VTX(singleFitVertex));
250 
251 #ifdef VTXDEBUG
252  const VTX & extVertex = recoVertices.back();
253  GlobalVector vtxDir = GlobalVector(extVertex.p4().X(),extVertex.p4().Y(),extVertex.p4().Z());
254 
255 
256  std::cout << " pointing : " << Geom::deltaR(extVertex.position() - pv.position(), vtxDir) << std::endl;
257 #endif
258  }
259  }
260  }
261  return recoVertices;
262 }
263 
264 
265 #endif
reco::Vertex::Point convertPos(const GlobalPoint &p)
const double w
Definition: UKUtility.cc:23
void setBeamSpot(const reco::BeamSpot &beamSpot)
bool isValid() const
Make the ReferenceCountingProxy method to check validity public.
TrackBaseRef trackBaseRef() const
reco::Vertex::Error convertError(const GlobalError &ge)
Definition: ConvertError.h:8
std::pair< bool, Measurement1D > absoluteImpactParameter3D(const reco::TransientTrack &transientTrack, const reco::Vertex &vertex)
Definition: IPTools.cc:37
bool trackFilterArbitrator(const reco::TransientTrack &track) const
const MagneticField * field() const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
int trackerLayersWithMeasurement() const
Definition: HitPattern.cc:527
const Point & position() const
position
Definition: Vertex.h:99
double pt() const
track transverse momentum
Definition: TrackBase.h:616
double residualX(int position) const
Definition: Track.cc:18
virtual CachingVertex< 5 > vertex(const std::vector< reco::TransientTrack > &) const
float trackWeight(const TREF &r) const
returns the weight with which a Track has contributed to the vertex-fit.
Definition: Vertex.h:73
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
const BasicTransientTrack * basicTransientTrack() const
double significance() const
Definition: Measurement1D.h:32
float trackWeight(const reco::Vertex &sv, const reco::TransientTrack &track)
const Track & track() const
const HitPattern & hitPattern() const
Access the hit pattern, indicating in which Tracker layers the track has hits.
Definition: TrackBase.h:445
double value() const
Definition: Measurement1D.h:28
std::vector< VTX > trackVertexArbitrator(edm::Handle< reco::BeamSpot > &beamSpot, const reco::Vertex &pv, std::vector< reco::TransientTrack > &selectedTracks, std::vector< VTX > &secondaryVertices)
T1 deltaR2(T1 eta1, T2 phi1, T3 eta2, T4 phi2)
Definition: deltaR.h:36
double residualY(int position) const
Definition: Track.cc:23
const daughters & daughterPtrVector() const
references to daughtes
TrackVertexArbitration(const edm::ParameterSet &params)
int numberOfValidPixelHits() const
Definition: HitPattern.h:838
tuple cout
Definition: gather_cfg.py:145
TrajectoryStateOnSurface impactPointState() const
bool isValid() const
Global3DVector GlobalVector
Definition: GlobalVector.h:10