CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TrackVertexArbitratration.cc
Go to the documentation of this file.
3 using namespace reco;
4 
6  primaryVertexCollection (params.getParameter<edm::InputTag>("primaryVertices")),
7  secondaryVertexCollection (params.getParameter<edm::InputTag>("secondaryVertices")),
8  trackCollection (params.getParameter<edm::InputTag>("tracks")),
9  beamSpotCollection (params.getParameter<edm::InputTag>("beamSpot")),
10  dRCut (params.getParameter<double>("dRCut")),
11  distCut (params.getParameter<double>("distCut")),
12  sigCut (params.getParameter<double>("sigCut")),
13  dLenFraction (params.getParameter<double>("dLenFraction"))
14 {
15 
16 }
17 
19 {
20  if (track->hitPattern().trackerLayersWithMeasurement() < 4)
21  return false;
22  if (track->pt() < 0.4 )
23  return false;
24  if (track->hitPattern().numberOfValidPixelHits() < 1)
25  return false;
26 
27  return true;
28 }
29 
30 
31 
32 
33 
36  const reco::Vertex &pv,
39  reco::VertexCollection & secondaryVertices)
40 {
41  using namespace reco;
42 
43  //std::cout << "PV: " << pv.position() << std::endl;
44  VertexDistance3D dist;
45 
46  double sigmacut = 3.0;
47  double Tini = 256.;
48  double ratio = 0.25;
49 
50  AdaptiveVertexFitter theAdaptiveFitter(
51  GeometricAnnealing(sigmacut, Tini, ratio),
56 
57 
58 
59  reco::VertexCollection recoVertices;
60 
61  VertexDistance3D vdist;
62 
63 for(std::vector<reco::Vertex>::const_iterator sv = secondaryVertices.begin();
64  sv != secondaryVertices.end(); ++sv) {
65 /* recoVertices->push_back(*sv);
66 
67 
68  for(std::vector<reco::Vertex>::iterator sv = recoVertices->begin();
69  sv != recoVertices->end(); ++sv) {
70 */
71  GlobalPoint ppv(pv.position().x(),pv.position().y(),pv.position().z());
72  GlobalPoint ssv(sv->position().x(),sv->position().y(),sv->position().z());
73  GlobalVector flightDir = ssv-ppv;
74 // std::cout << "Vertex : " << sv-secondaryVertices->begin() << " " << sv->position() << std::endl;
75  Measurement1D dlen= vdist.distance(pv,*sv);
76  std::vector<reco::TransientTrack> selTracks;
77  for(unsigned int itrack = 0; itrack < selectedTracks.size(); itrack++){
78  TrackRef ref = (selectedTracks)[itrack];
79 
80  //for(TrackCollection::const_iterator track = tracks->begin();
81  // track != tracks->end(); ++track) {
82 
83  // TrackRef ref(tracks, track - tracks->begin());
84  if (!trackFilterArbitrator(ref)) continue;
85 
86  TransientTrack tt = trackBuilder->build(ref);
87  tt.setBeamSpot(*beamSpot);
88  float w = sv->trackWeight(ref);
89  std::pair<bool,Measurement1D> ipv = IPTools::absoluteImpactParameter3D(tt,pv);
90  std::pair<bool,Measurement1D> itpv = IPTools::absoluteTransverseImpactParameter(tt,pv);
91  std::pair<bool,Measurement1D> isv = IPTools::absoluteImpactParameter3D(tt,*sv);
92  float dR = Geom::deltaR(flightDir,tt.track()); //.eta(), flightDir.phi(), tt.track().eta(), tt.track().phi());
93 
94  if( w > 0 || ( isv.second.significance() < sigCut && isv.second.value() < distCut && isv.second.value() < dlen.value()*dLenFraction ) )
95  {
96 
97  if(( isv.second.value() < ipv.second.value() ) && isv.second.value() < distCut && isv.second.value() < dlen.value()*dLenFraction
98  && dR < dRCut )
99  {
100 #ifdef VTXDEBUG
101  if(w > 0.5) std::cout << " = ";
102  else std::cout << " + ";
103 #endif
104  selTracks.push_back(tt);
105  } else
106  {
107 #ifdef VTXDEBUG
108  if(w > 0.5 && isv.second.value() > ipv.second.value() ) std::cout << " - ";
109  else std::cout << " ";
110 #endif
111  //add also the tracks used in previous fitting that are still closer to Sv than Pv
112  if(w > 0.5 && isv.second.value() <= ipv.second.value() && dR < dRCut) {
113  selTracks.push_back(tt);
114 #ifdef VTXDEBUG
115  std::cout << " = ";
116 #endif
117  }
118  if(w > 0.5 && isv.second.value() <= ipv.second.value() && dR >= dRCut) {
119 #ifdef VTXDEBUG
120  std::cout << " - ";
121 #endif
122 
123  }
124 
125 
126  }
127 #ifdef VTXDEBUG
128 
129  std::cout << "t : " << itrack << " ref " << ref.key() << " w: " << w
130  << " svip: " << isv.second.significance() << " " << isv.second.value()
131  << " pvip: " << ipv.second.significance() << " " << ipv.second.value() << " res " << tt.track().residualX(0) << "," << tt.track().residualY(0)
132  << " tpvip: " << itpv.second.significance() << " " << itpv.second.value() << " dr: " << dR << std::endl;
133 #endif
134 
135  }
136  else
137  {
138 #ifdef VTXDEBUG
139 
140  std::cout << " . t : " << itrack << " ref " << ref.key()<< " w: " << w
141  << " svip: " << isv.second.significance() << " " << isv.second.value()
142  << " pvip: " << ipv.second.significance() << " " << ipv.second.value() << " dr: " << dR << std::endl;
143 #endif
144 
145  }
146  }
147 
148  if(selTracks.size() >= 2)
149  {
150  TransientVertex singleFitVertex;
151  singleFitVertex = theAdaptiveFitter.vertex(selTracks,ssv);
152  if(singleFitVertex.isValid()) { recoVertices.push_back(reco::Vertex(singleFitVertex));
153 
154 #ifdef VTXDEBUG
155  const reco::Vertex & extVertex = recoVertices.back();
156  GlobalVector vtxDir = GlobalVector(extVertex.p4().X(),extVertex.p4().Y(),extVertex.p4().Z());
157 
158 
159  std::cout << " pointing : " << Geom::deltaR(extVertex.position() - pv.position(), vtxDir) << std::endl;
160 #endif
161  }
162  }
163  }
164  return recoVertices;
165 }
166 
167 
168 
169 
170 
171 
172 
173 
174 
void setBeamSpot(const reco::BeamSpot &beamSpot)
reco::VertexCollection trackVertexArbitrator(edm::Handle< reco::BeamSpot > &beamSpot, const reco::Vertex &pv, edm::ESHandle< TransientTrackBuilder > &trackBuilder, const edm::RefVector< reco::TrackCollection > &selectedTracks, reco::VertexCollection &secondaryVertices)
std::pair< bool, Measurement1D > absoluteImpactParameter3D(const reco::TransientTrack &transientTrack, const reco::Vertex &vertex)
Definition: IPTools.cc:37
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
const Point & position() const
position
Definition: Vertex.h:92
double residualX(int position) const
Definition: Track.cc:14
virtual CachingVertex< 5 > vertex(const std::vector< reco::TransientTrack > &) const
bool trackFilterArbitrator(const reco::TrackRef &track) const
const Track & track() const
math::XYZTLorentzVectorD p4(float mass=0.13957018, float minWeight=0.5) const
Returns the four momentum of the sum of the tracks, assuming the given mass for the decay products...
Definition: Vertex.cc:112
key_type key() const
Accessor for product key.
Definition: Ref.h:266
double value() const
Definition: Measurement1D.h:28
std::pair< bool, Measurement1D > absoluteTransverseImpactParameter(const reco::TransientTrack &transientTrack, const reco::Vertex &vertex)
Definition: IPTools.cc:43
double residualY(int position) const
Definition: Track.cc:19
double deltaR(const Vector1 &v1, const Vector2 &v2)
Definition: VectorUtil.h:84
size_type size() const
Size of the RefVector.
Definition: RefVector.h:89
tuple cout
Definition: gather_cfg.py:121
T w() const
bool isValid() const
TrackVertexArbitration(const edm::ParameterSet &params)
Global3DVector GlobalVector
Definition: GlobalVector.h:10