CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
AddTvTrack.cc
Go to the documentation of this file.
1 
8 
10 
11 using namespace std;
12 using namespace reco;
13 
14 AddTvTrack::AddTvTrack( vector<TransientVertex> *PrimaryVertices, vector<TransientVertex> *SecondaryVertices, double maxSigOnDistTrackToB)
15 {
16  thePrimaryVertices = PrimaryVertices;
17  theSecondaryVertices = SecondaryVertices;
18 
19  MaxSigOnDistTrackToB = maxSigOnDistTrackToB;
20 
21  // why is the argument passed in the ctor overwritten here ???
22  MaxSigOnDistTrackToB = 10.0;
23 
24  // min. transverse impact parameter significance
25  theIPSig = 1.5; // should this be 2 or 1.5 ???
26 
27 }
28 
29 //-----------------------------------------------------------------------------
30 
31 vector<TransientVertex> AddTvTrack::getSecondaryVertices(const vector<TransientTrack> & unusedTracks ) {
32 
33  VertexDistance3D theVertexDistance3D;
34 
35  theTrackInfoVector.clear();
36 
37  // this was commented out in ORCA implementation
38  // Measurement1D PvSvMeasurement = theVertexDistance3D.distance( (*thePrimaryVertices)[0], (*theSecondaryVertices)[0] );
39  // if( PvSvMeasurement.value() < 0.05 ) return *theSecondaryVertices;
40 
41  // first, filter tracks on min. IP significance -----------------------------
42 
43  vector<TransientTrack> unusedTrackswithIPSig; // filtered Tracks on IPsig
44  for( vector<TransientTrack>::const_iterator itT = unusedTracks.begin() ;
45  itT != unusedTracks.end() ; itT++ ) {
46 
47  GlobalPoint vtxPoint((*thePrimaryVertices)[0].position());
48 
49  TrajectoryStateClosestToPoint tscp=(*itT).trajectoryStateClosestToPoint(vtxPoint);
50  double val=tscp.perigeeParameters().transverseImpactParameter();
51  double error=sqrt(tscp.perigeeError().covarianceMatrix()(3,3));
52 
53  if (debug) cout <<"[AddTvTrack] tip val,err"<<val<<","<<error<<endl;
54 
55  //double val= 0.; //(*itT).transverseImpactParameter().value();
56  //double error= 9999.; //(*itT).transverseImpactParameter().error();
57 
58  double err=sqrt(pow(error,2)+pow(0.0015,2));
59  if( abs(val/err)>theIPSig ) unusedTrackswithIPSig.push_back(*itT);
60  }
61 
62  if (debug) cout<<"[AddTvTrack] tracks surviving IPSig cut: "
63  <<unusedTrackswithIPSig.size()<<endl;
64 
65  // if no tracks survived, we are done already
66  if( unusedTrackswithIPSig.empty() ) return *theSecondaryVertices;
67 
68  // construct b-flight line (from PV to SV)
69  GlobalPoint PVposition((*thePrimaryVertices)[0].position());
70  double px = (*theSecondaryVertices)[0].position().x()
71  - (*thePrimaryVertices)[0].position().x();
72  double py = (*theSecondaryVertices)[0].position().y()
73  - (*thePrimaryVertices)[0].position().y();
74  double pz = (*theSecondaryVertices)[0].position().z()
75  - (*thePrimaryVertices)[0].position().z();
76  GlobalVector bVector(px, py, pz);
77  Line bFlightLine( PVposition , bVector);
78 
79  // and the corresponding cov matrix
80  GetLineCovMatrix MyLineCovMatrix( PVposition,
81  (*theSecondaryVertices)[0].position(),
82  (*thePrimaryVertices)[0].positionError(),
83  (*theSecondaryVertices)[0].positionError() );
84 
85  // the tracks to be added to the SV
86  vector<TransientTrack> TracksToAdd;
87 
88  // main loop over tracks
89  for( vector<TransientTrack>::const_iterator itT =
90  unusedTrackswithIPSig.begin() ; itT != unusedTrackswithIPSig.end() ;
91  itT++ ) {
92  // point on track closest to b flight line
93 
94  // ORCA implementation
95 
96  // get closest Point to bFlightLine on TransientTrack
97  // TrajectoryStateOnSurface MyTransientTrackTrajectory =
98  // (*itT).stateAtLine(bFlightLine);
99  // Point on TransientTrack closest to bFlightLine
100  // GlobalPoint GlobalPoint2=MyTransientTrackTrajectory.globalPosition();
101 
102  // begin lenghy orca translation - - - - - - - - - - - - - - - - - - - -
103 
104  TransientTrack track = *itT;
106  TrajectoryStateOnSurface MyTransientTrackTrajectory;
107 
108  // approach from impact point first
109  // create a fts without errors for faster propagation
110  FreeTrajectoryState fastFts(
112  TrajectoryStateOnSurface cptl = TETL.extrapolate(fastFts, bFlightLine);
113  // extrapolate from closest measurement
114  if (cptl.isValid()) {
115  // FreeTrajectoryState* fts =
116  // theTrack.closestState(cptl.globalPosition()).freeState();
117  // transienttrack::closestState() not provided in CMSSW, do by hand
120  -cptl.globalPosition();
122  -cptl.globalPosition();
123  if (d1.mag()<d2.mag())
124  fts=*(track.innermostMeasurementState().freeState());
125  else
126  fts=*(track.outermostMeasurementState().freeState());
127  TrajectoryStateOnSurface cptl2 = TETL.extrapolate(fts, bFlightLine);
128  MyTransientTrackTrajectory=cptl2;
129  }
130  else {
131  MyTransientTrackTrajectory=cptl;
132  }
133 
134  // Point on TransientTrack closest to bFlightLine
135  GlobalPoint GlobalPoint2 = MyTransientTrackTrajectory.globalPosition();
136 
137  // end lengthy orca translation - - - - - - - - - - - - - - - - - - - - -
138 
139  GlobalVector VecDistTrackbFlightLine=bFlightLine.distance(GlobalPoint2);
140  double X = GlobalPoint2.x() + VecDistTrackbFlightLine.x();
141  double Y = GlobalPoint2.y() + VecDistTrackbFlightLine.y();
142  double Z = GlobalPoint2.z() + VecDistTrackbFlightLine.z();
143  // Point on bFlightLine closest to TransientTrack
144  GlobalPoint GlobalPoint1( X , Y , Z );
145 
146  pair<GlobalPoint,GlobalPoint> TheTwoPoints(GlobalPoint1, GlobalPoint2);
147  // TheTwoPoints.first : Point on b-flight-trajectory
148  // TheTwoPoints.second: Point on TransientTrack = pseudo tertiary vertex
149 
150  // Get Error of b-flight-trajectory at TheTwoPoints.first
151  GlobalError ErrOnBFlightTraj =
152  MyLineCovMatrix.GetMatrix( TheTwoPoints.first );
153 
154  // used to build pseudo vtx
155  vector<TransientTrack> emptyVectorTracks;
156 
157  VertexState theState1 (TheTwoPoints.first , ErrOnBFlightTraj );
158  TransientVertex V1(theState1 , emptyVectorTracks , 0.0 ) ;
159  VertexState theState2 ( TheTwoPoints.second,
160  MyTransientTrackTrajectory.cartesianError().position() );
161  TransientVertex V2(theState2 , emptyVectorTracks, 0.0 ) ;
162 
163  //VertexDistance3D theVertexDistance3D; // Distance of the point on the b-flight-trajectory and the point on the TransientTrack changed !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1
164 
165  Measurement1D TheMeasurement = theVertexDistance3D.distance( V1, V2 );
166  double Sig = TheMeasurement.significance();
167 
168  // check if point on b-flight-trajectory is in the correct hemisphere
169  bool HemisphereOk = false;
170  if ( abs( (*thePrimaryVertices)[0].position().x()
171  - (*theSecondaryVertices)[0].position().x() ) >
172  abs( (*thePrimaryVertices)[0].position().y()
173  - (*theSecondaryVertices)[0].position().y() ) ) {
174  if ( (*thePrimaryVertices)[0].position().x()
175  < (*theSecondaryVertices)[0].position().x() &&
176  (*thePrimaryVertices)[0].position().x()
177  < TheTwoPoints.first.x() ) HemisphereOk = true;
178  if ( (*thePrimaryVertices)[0].position().x()
179  > (*theSecondaryVertices)[0].position().x() &&
180  (*thePrimaryVertices)[0].position().x()
181  > TheTwoPoints.first.x() ) HemisphereOk = true;
182  }
183  else {
184  if ( (*thePrimaryVertices)[0].position().y()
185  < (*theSecondaryVertices)[0].position().y() &&
186  (*thePrimaryVertices)[0].position().y()
187  < TheTwoPoints.first.y() ) HemisphereOk = true;
188  if ( (*thePrimaryVertices)[0].position().y()
189  > (*theSecondaryVertices)[0].position().y() &&
190  (*thePrimaryVertices)[0].position().y()
191  > TheTwoPoints.first.y() ) HemisphereOk = true;
192  }
193 
194  double HemisOK = 0.0;
195  if( HemisphereOk ) HemisOK = 1.0;
196 
197  // start Max Dist Cut
198  //double RDistTheTwoPointsFirst = sqrt( TheTwoPoints.second.x() * TheTwoPoints.second.x() + TheTwoPoints.second.y() * TheTwoPoints.second.y() ); // changed first to second !!!!
199  //if( RDistTheTwoPointsFirst >= 2.0 ) HemisphereOk = false;
200  // end Max Dist Cut
201 
202  // distance to PV
203  double Dist_X=TheTwoPoints.second.x()
204  -(*thePrimaryVertices)[0].position().x();
205  double Dist_Y=TheTwoPoints.second.y()
206  -(*thePrimaryVertices)[0].position().y();
207  double Dist_Z=TheTwoPoints.second.z()
208  -(*thePrimaryVertices)[0].position().z();
209  double Dist_to_PV = sqrt(Dist_X*Dist_X + Dist_Y*Dist_Y + Dist_Z*Dist_Z);
210 
211  //if( Dist_to_PV < 0.2 ) HemisphereOk = false; !! changed
212  //if( Dist_to_PV < 0.2 && Dist_to_PV >= 2.0 ) HemisphereOk = false;
213  //if( Dist_to_PV < 0.01 ) HemisphereOk = false;
214 
215  // distance to beam
216  Dist_X = TheTwoPoints.second.x();
217  Dist_Y = TheTwoPoints.second.y();
218  double Dist_to_Beam = sqrt(Dist_X*Dist_X + Dist_Y*Dist_Y);
219  if( Dist_to_Beam < 0.01 || Dist_to_Beam > 2.5 ) HemisphereOk = false;
220  // !!!!!!!!!!!!!!!!!!!!! changed !! 0.2 -> 0.01
221 
222  // add track
223  if(Sig<MaxSigOnDistTrackToB && HemisphereOk) TracksToAdd.push_back(*itT);
224 
225  // start TDR INFO -------------------------------------------------------
226 
227  //double IP= 0.; //(*itT).transverseImpactParameter().value();
228  //double error= 999.; //(*itT).transverseImpactParameter().error();
229 
230  GlobalPoint vtxPoint((*thePrimaryVertices)[0].position());
231  TrajectoryStateClosestToPoint tscp=(*itT).trajectoryStateClosestToPoint(vtxPoint);
232  double IP=tscp.perigeeParameters().transverseImpactParameter();
233  double error=sqrt(tscp.perigeeError().covarianceMatrix()(3,3));
234  double err=sqrt(pow(error,2)+pow(0.0015,2));
235  double IPSig = IP/err;
236 
237  double InfArray[7];
238  InfArray[0] = Sig;
239  InfArray[1] = Dist_to_Beam;
240  InfArray[2] = Dist_to_PV;
241  InfArray[3] = HemisOK;
242  InfArray[4] = IP;
243  InfArray[5] = IPSig;
244  if (Sig > 10.0) Sig = 10.0 ;
245  if ( HemisphereOk ) InfArray[6]=Sig;
246  else InfArray[6]=-Sig;
247 
248  theTrackInfoVector.push_back(TrackInfo(&*itT,InfArray));
249 
250  //pair<TransientTrack,double* > TrackInfoToPush2( (*itT) , InfArray );
251  //TrackInfo2.push_back( TrackInfoToPush2 );
252 
253  //if (Sig > 10.0) Sig = 10.0 ;
254 
255  //if ( HemisphereOk ) {
256  // pair<TransientTrack,double> TrackInfoToPush( (*itT) , Sig );
257  // TrackInfo.push_back( TrackInfoToPush );
258  //}
259  //else {
260  // pair<TransientTrack,double> TrackInfoToPush( (*itT) , -Sig );
261  //TrackInfo.push_back( TrackInfoToPush );
262  //}
263 
264 
265  // end TDR INFO ---------------------------------------------------------
266 
267 
268  } // end main loop over tracks
269 
270  //TracksToAdd.clear(); // for using as PVR
271 
272  if (debug) cout <<"[AddTvTrack] tracks to add: "<<TracksToAdd.size()<<endl;
273 
274  if( ! TracksToAdd.empty() ) {
275 
276  // build new Vertex, position and CovMatrix are not changed
277  vector<TransientVertex> NewSecondaryVertices = *theSecondaryVertices;
278  vector<TransientTrack> VertexTracks =
279  NewSecondaryVertices[0].originalTracks();
280 
281  VertexState theState ( NewSecondaryVertices[0].position(),
282  NewSecondaryVertices[0].positionError() );
283 
284  // map<TransientTrack, float, ltrt> TrackWeightMap;
285  TransientTrackToFloatMap TrackWeightMap;
286 
287  // extend old TrackWeightMap
288  if( NewSecondaryVertices[0].hasTrackWeight() ) {
289  TrackWeightMap = NewSecondaryVertices[0].weightMap() ;
290  //map<TransientTrack,float,ltrt>::iterator itMapEnd=TrackWeightMap.end();
291  TransientTrackToFloatMap::iterator itMapEnd = TrackWeightMap.end();
292  for(vector<TransientTrack>::const_iterator itT = TracksToAdd.begin();
293  itT != TracksToAdd.end(); itT++) {
294  // insert weight 0.0 for new Tracks because they are not used
295  // for refitting the TransientVertex
296  pair< TransientTrack , float > TrackMapPair( (*itT) , 0.0);
297  itMapEnd = TrackWeightMap.insert( itMapEnd, TrackMapPair );
298  }
299  }
300  // build build TrackWeightMap
301  else {
302  //map<TransientTrack,float,ltrt>::iterator itMapEnd=TrackWeightMap.end();
303  TransientTrackToFloatMap::iterator itMapEnd = TrackWeightMap.end();
304  for(vector<TransientTrack>::const_iterator itT = VertexTracks.begin();
305  itT != VertexTracks.end(); itT++) {
306  // insert weight 1.0 for original Tracks because they are used
307  // for fitting the TransientVertex
308  pair< TransientTrack , float > TrackMapPair( (*itT) , 1.0);
309  itMapEnd = TrackWeightMap.insert( itMapEnd, TrackMapPair );
310  }
311  for(vector<TransientTrack>::const_iterator itT = TracksToAdd.begin();
312  itT != TracksToAdd.end(); itT++) {
313  // insert weight 0.0 for new Tracks because they are not used
314  // for refitting the TransientVertex
315  pair< TransientTrack , float > TrackMapPair( (*itT) , 0.0);
316  itMapEnd = TrackWeightMap.insert( itMapEnd, TrackMapPair );
317  }
318  }
319 
320  for(vector<TransientTrack>::const_iterator itT = TracksToAdd.begin();
321  itT!=TracksToAdd.end(); itT++)
322  VertexTracks.push_back(*itT);
323 
324  //TransientVertex NewVertex(theState , VertexTracks,
325  // NewSecondaryVertices[0].totalChiSquared(),
326  // NewSecondaryVertices[0].degreesOfFreedom(), TrackWeightMap) ;
327 
328  TransientVertex NewVertex(theState , VertexTracks,
329  NewSecondaryVertices[0].totalChiSquared(),
330  NewSecondaryVertices[0].degreesOfFreedom());
331  NewVertex.weightMap(TrackWeightMap);
332 
333  // end build new Vertex
334 
335  NewSecondaryVertices[0] = NewVertex;
336  return NewSecondaryVertices;
337  }
338 
339  return *theSecondaryVertices;
340 }
const double Z[kNumberCalorimeter]
virtual Measurement1D distance(const GlobalPoint &vtx1Position, const GlobalError &vtx1PositionError, const GlobalPoint &vtx2Position, const GlobalError &vtx2PositionError) const
const PerigeeTrajectoryError & perigeeError() const
const GlobalTrajectoryParameters & parameters() const
Definition: Line.h:10
FreeTrajectoryState * freeTrajectoryState(bool withErrors=true) const
std::map< reco::TransientTrack, float > TransientTrackToFloatMap
Definition: AddTvTrack.h:76
T y() const
Definition: PV3DBase.h:62
#define X(str)
Definition: MuonsGrabber.cc:49
#define abs(x)
Definition: mlp_lapack.h:159
GlobalPoint globalPosition() const
const MagneticField * field() const
static int position[TOTALCHAMBERS][3]
Definition: ReadPGInfo.cc:509
GlobalVector distance(const Line &aLine) const
Definition: Line.h:38
std::vector< TransientVertex > * getSecondaryVertices() const
Definition: AddTvTrack.h:32
TrajectoryStateOnSurface innermostMeasurementState() const
T mag() const
Definition: PV3DBase.h:66
const PerigeeTrajectoryParameters & perigeeParameters() const
FreeTrajectoryState * freeState(bool withErrors=true) const
T sqrt(T t)
Definition: SSEVec.h:46
T z() const
Definition: PV3DBase.h:63
TrajectoryStateOnSurface outermostMeasurementState() const
const AlgebraicSymMatrix55 & covarianceMatrix() const
AddTvTrack(std::vector< TransientVertex > *, std::vector< TransientVertex > *, double)
Definition: AddTvTrack.cc:14
double significance() const
Definition: Measurement1D.h:32
GlobalError GetMatrix(GlobalPoint)
tuple cout
Definition: gather_cfg.py:121
TrajectoryStateOnSurface impactPointState() const
Definition: DDAxes.h:10
#define debug
Definition: MEtoEDMFormat.h:34
T x() const
Definition: PV3DBase.h:61
TransientTrackToFloatMap weightMap() const
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40