00001
00002 #include "DataFormats/GeometrySurface/interface/Line.h"
00003 #include "TrackingTools/PatternTools/interface/TwoTrackMinimumDistance.h"
00004 #include "RecoVertex/VertexTools/interface/VertexDistance3D.h"
00005 #include "RecoVertex/TertiaryTracksVertexFinder/interface/GetLineCovMatrix.h"
00006 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateClosestToPoint.h"
00007 #include "TrackingTools/GeomPropagators/interface/AnalyticalTrajectoryExtrapolatorToLine.h"
00008
00009 #include "RecoVertex/TertiaryTracksVertexFinder/interface/AddTvTrack.h"
00010
00011 using namespace std;
00012 using namespace reco;
00013
00014 AddTvTrack::AddTvTrack( vector<TransientVertex> *PrimaryVertices, vector<TransientVertex> *SecondaryVertices, double maxSigOnDistTrackToB)
00015 {
00016 thePrimaryVertices = PrimaryVertices;
00017 theSecondaryVertices = SecondaryVertices;
00018
00019 MaxSigOnDistTrackToB = maxSigOnDistTrackToB;
00020
00021
00022 MaxSigOnDistTrackToB = 10.0;
00023
00024
00025 theIPSig = 1.5;
00026
00027 }
00028
00029
00030
00031 vector<TransientVertex> AddTvTrack::getSecondaryVertices(const vector<TransientTrack> & unusedTracks ) {
00032
00033 VertexDistance3D theVertexDistance3D;
00034
00035 theTrackInfoVector.clear();
00036
00037
00038
00039
00040
00041
00042
00043 vector<TransientTrack> unusedTrackswithIPSig;
00044 for( vector<TransientTrack>::const_iterator itT = unusedTracks.begin() ;
00045 itT != unusedTracks.end() ; itT++ ) {
00046
00047 GlobalPoint vtxPoint((*thePrimaryVertices)[0].position());
00048
00049 TrajectoryStateClosestToPoint tscp=(*itT).trajectoryStateClosestToPoint(vtxPoint);
00050 double val=tscp.perigeeParameters().transverseImpactParameter();
00051 double error=sqrt((tscp.perigeeError().covarianceMatrix_old())[3][3]);
00052
00053 if (debug) cout <<"[AddTvTrack] tip val,err"<<val<<","<<error<<endl;
00054
00055
00056
00057
00058 double err=sqrt(pow(error,2)+pow(0.0015,2));
00059 if( abs(val/err)>theIPSig ) unusedTrackswithIPSig.push_back(*itT);
00060 }
00061
00062 if (debug) cout<<"[AddTvTrack] tracks surviving IPSig cut: "
00063 <<unusedTrackswithIPSig.size()<<endl;
00064
00065
00066 if( unusedTrackswithIPSig.empty() ) return *theSecondaryVertices;
00067
00068
00069 GlobalPoint PVposition((*thePrimaryVertices)[0].position());
00070 double px = (*theSecondaryVertices)[0].position().x()
00071 - (*thePrimaryVertices)[0].position().x();
00072 double py = (*theSecondaryVertices)[0].position().y()
00073 - (*thePrimaryVertices)[0].position().y();
00074 double pz = (*theSecondaryVertices)[0].position().z()
00075 - (*thePrimaryVertices)[0].position().z();
00076 GlobalVector bVector(px, py, pz);
00077 Line bFlightLine( PVposition , bVector);
00078
00079
00080 GetLineCovMatrix MyLineCovMatrix( PVposition,
00081 (*theSecondaryVertices)[0].position(),
00082 (*thePrimaryVertices)[0].positionError(),
00083 (*theSecondaryVertices)[0].positionError() );
00084
00085
00086 vector<TransientTrack> TracksToAdd;
00087
00088
00089 for( vector<TransientTrack>::const_iterator itT =
00090 unusedTrackswithIPSig.begin() ; itT != unusedTrackswithIPSig.end() ;
00091 itT++ ) {
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104 TransientTrack track = *itT;
00105 AnalyticalTrajectoryExtrapolatorToLine TETL(track.field());
00106 TrajectoryStateOnSurface MyTransientTrackTrajectory;
00107
00108
00109
00110 FreeTrajectoryState fastFts(
00111 track.impactPointState().freeTrajectoryState()->parameters());
00112 TrajectoryStateOnSurface cptl = TETL.extrapolate(fastFts, bFlightLine);
00113
00114 if (cptl.isValid()) {
00115
00116
00117
00118 FreeTrajectoryState fts;
00119 GlobalVector d1 = track.innermostMeasurementState().globalPosition()
00120 -cptl.globalPosition();
00121 GlobalVector d2 = track.outermostMeasurementState().globalPosition()
00122 -cptl.globalPosition();
00123 if (d1.mag()<d2.mag())
00124 fts=*(track.innermostMeasurementState().freeState());
00125 else
00126 fts=*(track.outermostMeasurementState().freeState());
00127 TrajectoryStateOnSurface cptl2 = TETL.extrapolate(fts, bFlightLine);
00128 MyTransientTrackTrajectory=cptl2;
00129 }
00130 else {
00131 MyTransientTrackTrajectory=cptl;
00132 }
00133
00134
00135 GlobalPoint GlobalPoint2 = MyTransientTrackTrajectory.globalPosition();
00136
00137
00138
00139 GlobalVector VecDistTrackbFlightLine=bFlightLine.distance(GlobalPoint2);
00140 double X = GlobalPoint2.x() + VecDistTrackbFlightLine.x();
00141 double Y = GlobalPoint2.y() + VecDistTrackbFlightLine.y();
00142 double Z = GlobalPoint2.z() + VecDistTrackbFlightLine.z();
00143
00144 GlobalPoint GlobalPoint1( X , Y , Z );
00145
00146 pair<GlobalPoint,GlobalPoint> TheTwoPoints(GlobalPoint1, GlobalPoint2);
00147
00148
00149
00150
00151 GlobalError ErrOnBFlightTraj =
00152 MyLineCovMatrix.GetMatrix( TheTwoPoints.first );
00153
00154
00155 vector<TransientTrack> emptyVectorTracks;
00156
00157 VertexState theState1 (TheTwoPoints.first , ErrOnBFlightTraj );
00158 TransientVertex V1(theState1 , emptyVectorTracks , 0.0 ) ;
00159 VertexState theState2 ( TheTwoPoints.second,
00160 MyTransientTrackTrajectory.cartesianError().position() );
00161 TransientVertex V2(theState2 , emptyVectorTracks, 0.0 ) ;
00162
00163
00164
00165 Measurement1D TheMeasurement = theVertexDistance3D.distance( V1, V2 );
00166 double Sig = TheMeasurement.significance();
00167
00168
00169 bool HemisphereOk = false;
00170 if ( abs( (*thePrimaryVertices)[0].position().x()
00171 - (*theSecondaryVertices)[0].position().x() ) >
00172 abs( (*thePrimaryVertices)[0].position().y()
00173 - (*theSecondaryVertices)[0].position().y() ) ) {
00174 if ( (*thePrimaryVertices)[0].position().x()
00175 < (*theSecondaryVertices)[0].position().x() &&
00176 (*thePrimaryVertices)[0].position().x()
00177 < TheTwoPoints.first.x() ) HemisphereOk = true;
00178 if ( (*thePrimaryVertices)[0].position().x()
00179 > (*theSecondaryVertices)[0].position().x() &&
00180 (*thePrimaryVertices)[0].position().x()
00181 > TheTwoPoints.first.x() ) HemisphereOk = true;
00182 }
00183 else {
00184 if ( (*thePrimaryVertices)[0].position().y()
00185 < (*theSecondaryVertices)[0].position().y() &&
00186 (*thePrimaryVertices)[0].position().y()
00187 < TheTwoPoints.first.y() ) HemisphereOk = true;
00188 if ( (*thePrimaryVertices)[0].position().y()
00189 > (*theSecondaryVertices)[0].position().y() &&
00190 (*thePrimaryVertices)[0].position().y()
00191 > TheTwoPoints.first.y() ) HemisphereOk = true;
00192 }
00193
00194 double HemisOK = 0.0;
00195 if( HemisphereOk ) HemisOK = 1.0;
00196
00197
00198
00199
00200
00201
00202
00203 double Dist_X=TheTwoPoints.second.x()
00204 -(*thePrimaryVertices)[0].position().x();
00205 double Dist_Y=TheTwoPoints.second.y()
00206 -(*thePrimaryVertices)[0].position().y();
00207 double Dist_Z=TheTwoPoints.second.z()
00208 -(*thePrimaryVertices)[0].position().z();
00209 double Dist_to_PV = sqrt(Dist_X*Dist_X + Dist_Y*Dist_Y + Dist_Z*Dist_Z);
00210
00211
00212
00213
00214
00215
00216 Dist_X = TheTwoPoints.second.x();
00217 Dist_Y = TheTwoPoints.second.y();
00218 double Dist_to_Beam = sqrt(Dist_X*Dist_X + Dist_Y*Dist_Y);
00219 if( Dist_to_Beam < 0.01 || Dist_to_Beam > 2.5 ) HemisphereOk = false;
00220
00221
00222
00223 if(Sig<MaxSigOnDistTrackToB && HemisphereOk) TracksToAdd.push_back(*itT);
00224
00225
00226
00227
00228
00229
00230 GlobalPoint vtxPoint((*thePrimaryVertices)[0].position());
00231 TrajectoryStateClosestToPoint tscp=(*itT).trajectoryStateClosestToPoint(vtxPoint);
00232 double IP=tscp.perigeeParameters().transverseImpactParameter();
00233 double error=sqrt((tscp.perigeeError().covarianceMatrix_old())[3][3]);
00234 double err=sqrt(pow(error,2)+pow(0.0015,2));
00235 double IPSig = IP/err;
00236
00237 double InfArray[7];
00238 InfArray[0] = Sig;
00239 InfArray[1] = Dist_to_Beam;
00240 InfArray[2] = Dist_to_PV;
00241 InfArray[3] = HemisOK;
00242 InfArray[4] = IP;
00243 InfArray[5] = IPSig;
00244 if (Sig > 10.0) Sig = 10.0 ;
00245 if ( HemisphereOk ) InfArray[6]=Sig;
00246 else InfArray[6]=-Sig;
00247
00248 theTrackInfoVector.push_back(TrackInfo(&*itT,InfArray));
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268 }
00269
00270
00271
00272 if (debug) cout <<"[AddTvTrack] tracks to add: "<<TracksToAdd.size()<<endl;
00273
00274 if( ! TracksToAdd.empty() ) {
00275
00276
00277 vector<TransientVertex> NewSecondaryVertices = *theSecondaryVertices;
00278 vector<TransientTrack> VertexTracks =
00279 NewSecondaryVertices[0].originalTracks();
00280
00281 VertexState theState ( NewSecondaryVertices[0].position(),
00282 NewSecondaryVertices[0].positionError() );
00283
00284
00285 TransientTrackToFloatMap TrackWeightMap;
00286
00287
00288 if( NewSecondaryVertices[0].hasTrackWeight() ) {
00289 TrackWeightMap = NewSecondaryVertices[0].weightMap() ;
00290
00291 TransientTrackToFloatMap::iterator itMapEnd = TrackWeightMap.end();
00292 for(vector<TransientTrack>::const_iterator itT = TracksToAdd.begin();
00293 itT != TracksToAdd.end(); itT++) {
00294
00295
00296 pair< TransientTrack , float > TrackMapPair( (*itT) , 0.0);
00297 itMapEnd = TrackWeightMap.insert( itMapEnd, TrackMapPair );
00298 }
00299 }
00300
00301 else {
00302
00303 TransientTrackToFloatMap::iterator itMapEnd = TrackWeightMap.end();
00304 for(vector<TransientTrack>::const_iterator itT = VertexTracks.begin();
00305 itT != VertexTracks.end(); itT++) {
00306
00307
00308 pair< TransientTrack , float > TrackMapPair( (*itT) , 1.0);
00309 itMapEnd = TrackWeightMap.insert( itMapEnd, TrackMapPair );
00310 }
00311 for(vector<TransientTrack>::const_iterator itT = TracksToAdd.begin();
00312 itT != TracksToAdd.end(); itT++) {
00313
00314
00315 pair< TransientTrack , float > TrackMapPair( (*itT) , 0.0);
00316 itMapEnd = TrackWeightMap.insert( itMapEnd, TrackMapPair );
00317 }
00318 }
00319
00320 for(vector<TransientTrack>::const_iterator itT = TracksToAdd.begin();
00321 itT!=TracksToAdd.end(); itT++)
00322 VertexTracks.push_back(*itT);
00323
00324
00325
00326
00327
00328 TransientVertex NewVertex(theState , VertexTracks,
00329 NewSecondaryVertices[0].totalChiSquared(),
00330 NewSecondaryVertices[0].degreesOfFreedom());
00331 NewVertex.weightMap(TrackWeightMap);
00332
00333
00334
00335 NewSecondaryVertices[0] = NewVertex;
00336 return NewSecondaryVertices;
00337 }
00338
00339 return *theSecondaryVertices;
00340 }