CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/RecoVertex/TertiaryTracksVertexFinder/src/AddTvTrack.cc

Go to the documentation of this file.
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  // why is the argument passed in the ctor overwritten here ???
00022   MaxSigOnDistTrackToB = 10.0;
00023 
00024   // min. transverse impact parameter significance
00025   theIPSig = 1.5; // should this be 2 or 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   // this was commented out in ORCA implementation
00038   // Measurement1D PvSvMeasurement = theVertexDistance3D.distance( (*thePrimaryVertices)[0],  (*theSecondaryVertices)[0] );
00039   // if( PvSvMeasurement.value() < 0.05 ) return *theSecondaryVertices;
00040 
00041   // first, filter tracks on min. IP significance -----------------------------
00042 
00043   vector<TransientTrack> unusedTrackswithIPSig; // filtered Tracks on IPsig
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     //double val= 0.; //(*itT).transverseImpactParameter().value();
00056     //double error= 9999.; //(*itT).transverseImpactParameter().error();
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   // if no tracks survived, we are done already
00066   if( unusedTrackswithIPSig.empty() )  return *theSecondaryVertices;  
00067 
00068   // construct b-flight line (from PV to SV)
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   // and the corresponding cov matrix                  
00080   GetLineCovMatrix MyLineCovMatrix( PVposition, 
00081     (*theSecondaryVertices)[0].position(), 
00082     (*thePrimaryVertices)[0].positionError(), 
00083     (*theSecondaryVertices)[0].positionError() );  
00084 
00085   // the tracks to be added to the SV
00086   vector<TransientTrack> TracksToAdd;
00087 
00088   // main loop over tracks 
00089   for( vector<TransientTrack>::const_iterator itT = 
00090     unusedTrackswithIPSig.begin() ; itT != unusedTrackswithIPSig.end() ; 
00091     itT++ ) {  
00092       // point on track closest to b flight line 
00093 
00094       // ORCA implementation
00095 
00096       // get closest Point to bFlightLine on TransientTrack   
00097       // TrajectoryStateOnSurface MyTransientTrackTrajectory = 
00098       //   (*itT).stateAtLine(bFlightLine); 
00099       // Point on  TransientTrack closest to bFlightLine 
00100       // GlobalPoint GlobalPoint2=MyTransientTrackTrajectory.globalPosition(); 
00101 
00102       // begin lenghy orca translation - - - - - - - - - - - - - - - - - - - - 
00103 
00104       TransientTrack track = *itT;
00105       AnalyticalTrajectoryExtrapolatorToLine TETL(track.field());
00106       TrajectoryStateOnSurface MyTransientTrackTrajectory;
00107 
00108       // approach from impact point first
00109       // create a fts without errors for faster propagation
00110       FreeTrajectoryState fastFts(
00111         track.impactPointState().freeTrajectoryState()->parameters());
00112       TrajectoryStateOnSurface cptl = TETL.extrapolate(fastFts, bFlightLine);
00113       // extrapolate from closest measurement
00114       if (cptl.isValid()) {
00115         // FreeTrajectoryState* fts = 
00116         //   theTrack.closestState(cptl.globalPosition()).freeState();
00117         // transienttrack::closestState() not provided in CMSSW, do by hand
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       // Point on  TransientTrack closest to bFlightLine  
00135       GlobalPoint GlobalPoint2 = MyTransientTrackTrajectory.globalPosition();  
00136 
00137       // end lengthy orca translation - - - - - - - - - - - - - - - - - - - - -
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       // Point on  bFlightLine closest to TransientTrack   
00144       GlobalPoint GlobalPoint1( X , Y , Z );  
00145 
00146       pair<GlobalPoint,GlobalPoint> TheTwoPoints(GlobalPoint1, GlobalPoint2);
00147       // TheTwoPoints.first : Point on b-flight-trajectory
00148       // TheTwoPoints.second: Point on TransientTrack = pseudo tertiary vertex
00149     
00150       // Get Error of  b-flight-trajectory at TheTwoPoints.first
00151       GlobalError ErrOnBFlightTraj = 
00152         MyLineCovMatrix.GetMatrix( TheTwoPoints.first );  
00153 
00154       // used to build pseudo vtx      
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       //VertexDistance3D theVertexDistance3D;   // Distance of the point on the b-flight-trajectory and the point on the TransientTrack                 changed !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1
00164 
00165       Measurement1D TheMeasurement = theVertexDistance3D.distance( V1, V2 );
00166       double Sig = TheMeasurement.significance(); 
00167 
00168       // check if point on b-flight-trajectory is in the correct hemisphere
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       // start Max Dist Cut
00198       //double RDistTheTwoPointsFirst = sqrt( TheTwoPoints.second.x() * TheTwoPoints.second.x() + TheTwoPoints.second.y() * TheTwoPoints.second.y() );   // changed first to second !!!!
00199       //if( RDistTheTwoPointsFirst >= 2.0 ) HemisphereOk = false; 
00200       // end Max Dist Cut
00201 
00202       // distance to PV      
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       //if( Dist_to_PV < 0.2 ) HemisphereOk = false;   !! changed
00212       //if( Dist_to_PV < 0.2  &&   Dist_to_PV >= 2.0 ) HemisphereOk = false; 
00213       //if( Dist_to_PV < 0.01 ) HemisphereOk = false;    
00214 
00215       // distance to beam      
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       // !!!!!!!!!!!!!!!!!!!!! changed !!   0.2 -> 0.01
00221 
00222       // add track      
00223       if(Sig<MaxSigOnDistTrackToB && HemisphereOk) TracksToAdd.push_back(*itT);
00224 
00225       // start TDR INFO -------------------------------------------------------
00226 
00227       //double IP= 0.; //(*itT).transverseImpactParameter().value();
00228       //double error= 999.; //(*itT).transverseImpactParameter().error();
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       //pair<TransientTrack,double* > TrackInfoToPush2( (*itT) , InfArray ); 
00251       //TrackInfo2.push_back( TrackInfoToPush2 );
00252       
00253       //if (Sig > 10.0) Sig = 10.0 ;
00254       
00255       //if ( HemisphereOk ) {
00256       //        pair<TransientTrack,double> TrackInfoToPush( (*itT) , Sig );
00257       //        TrackInfo.push_back( TrackInfoToPush );
00258       //}
00259       //else {
00260       //        pair<TransientTrack,double> TrackInfoToPush( (*itT) , -Sig );
00261       //TrackInfo.push_back( TrackInfoToPush );
00262       //}
00263 
00264 
00265       // end TDR INFO ---------------------------------------------------------
00266    
00267 
00268   } // end  main loop over tracks
00269 
00270   //TracksToAdd.clear();  // for using as PVR  
00271 
00272   if (debug) cout <<"[AddTvTrack] tracks to add: "<<TracksToAdd.size()<<endl;
00273 
00274   if( ! TracksToAdd.empty() ) {
00275 
00276     // build new Vertex, position and CovMatrix are not changed
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     // map<TransientTrack, float, ltrt> TrackWeightMap;
00285     TransientTrackToFloatMap TrackWeightMap;
00286 
00287     // extend old TrackWeightMap
00288     if( NewSecondaryVertices[0].hasTrackWeight() ) {  
00289       TrackWeightMap = NewSecondaryVertices[0].weightMap() ;  
00290       //map<TransientTrack,float,ltrt>::iterator itMapEnd=TrackWeightMap.end();
00291       TransientTrackToFloatMap::iterator itMapEnd = TrackWeightMap.end();
00292       for(vector<TransientTrack>::const_iterator itT = TracksToAdd.begin();
00293           itT != TracksToAdd.end(); itT++) {
00294         // insert weight 0.0 for new Tracks because they are not used 
00295         // for refitting the TransientVertex
00296         pair< TransientTrack , float > TrackMapPair( (*itT) , 0.0);  
00297         itMapEnd = TrackWeightMap.insert( itMapEnd, TrackMapPair ); 
00298       }
00299     }
00300     // build  build TrackWeightMap
00301     else { 
00302       //map<TransientTrack,float,ltrt>::iterator itMapEnd=TrackWeightMap.end();
00303       TransientTrackToFloatMap::iterator itMapEnd = TrackWeightMap.end();
00304       for(vector<TransientTrack>::const_iterator itT = VertexTracks.begin(); 
00305           itT != VertexTracks.end(); itT++) {
00306         // insert weight 1.0 for original Tracks because they are used
00307         // for fitting the TransientVertex
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         // insert weight 0.0 for new Tracks because they are not used 
00314         // for refitting the TransientVertex
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     //TransientVertex NewVertex(theState , VertexTracks, 
00325     //  NewSecondaryVertices[0].totalChiSquared(), 
00326     //  NewSecondaryVertices[0].degreesOfFreedom(), TrackWeightMap) ;
00327 
00328     TransientVertex NewVertex(theState , VertexTracks, 
00329       NewSecondaryVertices[0].totalChiSquared(), 
00330       NewSecondaryVertices[0].degreesOfFreedom()); 
00331     NewVertex.weightMap(TrackWeightMap);
00332 
00333     // end build new Vertex
00334 
00335     NewSecondaryVertices[0] = NewVertex;      
00336     return NewSecondaryVertices;
00337   }
00338   
00339   return *theSecondaryVertices;
00340 }