CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/RecoTracker/TrackProducer/src/TrackProducerAlgorithm.cc

Go to the documentation of this file.
00001 #include "RecoTracker/TrackProducer/interface/TrackProducerAlgorithm.h"
00002 
00003 #include "DataFormats/Common/interface/OrphanHandle.h"
00004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00005 
00006 #include "MagneticField/Engine/interface/MagneticField.h"
00007 #include "Geometry/CommonDetUnit/interface/TrackingGeometry.h"
00008 
00009 #include "DataFormats/TrajectorySeed/interface/TrajectorySeed.h"
00010 #include "DataFormats/TrackCandidate/interface/TrackCandidate.h"
00011 #include "DataFormats/TrackingRecHit/interface/TrackingRecHitFwd.h"
00012 
00013 #include "TrackingTools/TrackFitters/interface/TrajectoryFitter.h"
00014 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateOnSurface.h"
00015 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateTransform.h"
00016 #include "TrackingTools/TransientTrackingRecHit/interface/TransientTrackingRecHitBuilder.h"
00017 #include "RecoTracker/TransientTrackingRecHit/interface/TkTransientTrackingRecHitBuilder.h"
00018 #include "TrackingTools/PatternTools/interface/TransverseImpactPointExtrapolator.h"
00019 #include "TrackingTools/TransientTrack/interface/TransientTrack.h"
00020 #include "RecoTracker/TrackProducer/interface/TrackingRecHitLessFromGlobalPosition.h"
00021 
00022 #include "TrackingTools/PatternTools/interface/TSCBLBuilderNoMaterial.h"
00023 #include "Utilities/General/interface/CMSexception.h"
00024 
00025 #include "RecoTracker/TransientTrackingRecHit/interface/TRecHit2DPosConstraint.h"
00026 #include "RecoTracker/TransientTrackingRecHit/interface/TRecHit1DMomConstraint.h"
00027 #include "TrackingTools/MaterialEffects/interface/PropagatorWithMaterial.h"
00028 #include "DataFormats/GeometryCommonDetAlgo/interface/ErrorFrameTransformer.h"
00029 #include "TrackingTools/TrackFitters/interface/RecHitSorter.h"
00030 #include "DataFormats/TrackReco/interface/TrackBase.h"
00031 
00032 template <> bool
00033 TrackProducerAlgorithm<reco::Track>::buildTrack (const TrajectoryFitter * theFitter,
00034                                                  const Propagator * thePropagator,
00035                                                  AlgoProductCollection& algoResults,
00036                                                  TransientTrackingRecHit::RecHitContainer& hits,
00037                                                  TrajectoryStateOnSurface& theTSOS,
00038                                                  const TrajectorySeed& seed,
00039                                                  float ndof,
00040                                                  const reco::BeamSpot& bs,
00041                                                  SeedRef seedRef,
00042                                                  int qualityMask)                                                
00043 {
00044   //variable declarations
00045   std::vector<Trajectory> trajVec;
00046   reco::Track * theTrack;
00047   Trajectory * theTraj; 
00048   PropagationDirection seedDir = seed.direction();
00049       
00050   //perform the fit: the result's size is 1 if it succeded, 0 if fails
00051   trajVec = theFitter->fit(seed, hits, theTSOS);
00052   
00053   LogDebug("TrackProducer") <<" FITTER FOUND "<< trajVec.size() << " TRAJECTORIES" <<"\n";
00054   TrajectoryStateOnSurface innertsos;
00055   
00056   if (trajVec.size() != 0){
00057 
00058     theTraj = new Trajectory( trajVec.front() );
00059     theTraj->setSeedRef(seedRef);
00060     
00061     if (theTraj->direction() == alongMomentum) {
00062       innertsos = theTraj->firstMeasurement().updatedState();
00063     } else { 
00064       innertsos = theTraj->lastMeasurement().updatedState();
00065     }
00066     
00067     ndof = 0;
00068     TransientTrackingRecHit::RecHitContainer validHits;
00069     theTraj->validRecHits(validHits);
00070     for (TransientTrackingRecHit::RecHitContainer::iterator h=validHits.begin();h!=validHits.end();++h)
00071       ndof = ndof + ((*h)->dimension())*((*h)->weight());
00072     if (theTSOS.magneticField()->inTesla(GlobalPoint(0,0,0)).mag2()<DBL_MIN) ndof = ndof - 4;
00073     else ndof = ndof - 5;
00074     
00075     TSCBLBuilderNoMaterial tscblBuilder;
00076     //    const FreeTrajectoryState & stateForProjectionToBeamLine=*innertsos.freeState();
00077     const TrajectoryStateOnSurface & stateForProjectionToBeamLineOnSurface = theTraj->closestMeasurement(GlobalPoint(bs.x0(),bs.y0(),bs.z0())).updatedState();
00078     if (!stateForProjectionToBeamLineOnSurface.isValid()){
00079       edm::LogError("CannotPropagateToBeamLine")<<"the state on the closest measurement isnot valid. skipping track.";
00080       delete theTraj;
00081       return false;
00082     }
00083     const FreeTrajectoryState & stateForProjectionToBeamLine=*stateForProjectionToBeamLineOnSurface.freeState();
00084 
00085     LogDebug("TrackProducer") << "stateForProjectionToBeamLine=" << stateForProjectionToBeamLine;
00086 
00087     TrajectoryStateClosestToBeamLine tscbl = tscblBuilder(stateForProjectionToBeamLine,bs);
00088 
00089     if (tscbl.isValid()==false) {
00090         delete theTraj;
00091         return false;
00092     }
00093 
00094     GlobalPoint v = tscbl.trackStateAtPCA().position();
00095     math::XYZPoint  pos( v.x(), v.y(), v.z() );
00096     GlobalVector p = tscbl.trackStateAtPCA().momentum();
00097     math::XYZVector mom( p.x(), p.y(), p.z() );
00098 
00099     LogDebug("TrackProducer") << "pos=" << v << " mom=" << p << " pt=" << p.perp() << " mag=" << p.mag();
00100 
00101     theTrack = new reco::Track(theTraj->chiSquared(),
00102                                int(ndof),//FIXME fix weight() in TrackingRecHit
00103                                pos, mom, tscbl.trackStateAtPCA().charge(), 
00104                                tscbl.trackStateAtPCA().curvilinearError(),
00105                                algo_);
00106    
00107     theTrack->setQualityMask(qualityMask);
00108     
00109     LogDebug("TrackProducer") << "theTrack->pt()=" << theTrack->pt();
00110 
00111     LogDebug("TrackProducer") <<"track done\n";
00112 
00113     AlgoProduct aProduct(theTraj,std::make_pair(theTrack,seedDir));
00114     algoResults.push_back(aProduct);
00115     
00116     return true;
00117   } 
00118   else  return false;
00119 }
00120 
00121 template <> bool
00122 TrackProducerAlgorithm<reco::GsfTrack>::buildTrack (const TrajectoryFitter * theFitter,
00123                                                     const Propagator * thePropagator,
00124                                                     AlgoProductCollection& algoResults,
00125                                                     TransientTrackingRecHit::RecHitContainer& hits,
00126                                                     TrajectoryStateOnSurface& theTSOS,
00127                                                     const TrajectorySeed& seed,
00128                                                     float ndof,
00129                                                     const reco::BeamSpot& bs,
00130                                                     SeedRef seedRef,
00131                                                     int qualityMask)
00132 {
00133   //variable declarations
00134   std::vector<Trajectory> trajVec;
00135   reco::GsfTrack * theTrack;
00136   Trajectory * theTraj; 
00137   PropagationDirection seedDir = seed.direction();
00138       
00139   //perform the fit: the result's size is 1 if it succeded, 0 if fails
00140   trajVec = theFitter->fit(seed, hits, theTSOS);
00141   
00142   LogDebug("GsfTrackProducer") <<" FITTER FOUND "<< trajVec.size() << " TRAJECTORIES" <<"\n";
00143   
00144   TrajectoryStateOnSurface innertsos;
00145   TrajectoryStateOnSurface outertsos;
00146   
00147   if (trajVec.size() != 0){
00148 
00149     theTraj = new Trajectory( trajVec.front() );
00150     theTraj->setSeedRef(seedRef);
00151     
00152     if (theTraj->direction() == alongMomentum) {
00153       innertsos = theTraj->firstMeasurement().updatedState();
00154       outertsos = theTraj->lastMeasurement().updatedState();
00155     } else { 
00156       innertsos = theTraj->lastMeasurement().updatedState();
00157       outertsos = theTraj->firstMeasurement().updatedState();
00158     }
00159 //     std::cout
00160 //       << "Nr. of first / last states = "
00161 //       << innertsos.components().size() << " "
00162 //       << outertsos.components().size() << std::endl;
00163 //     std::vector<TrajectoryStateOnSurface> components = 
00164 //       innertsos.components();
00165 //     double sinTheta = 
00166 //       sin(innertsos.globalMomentum().theta());
00167 //     for ( std::vector<TrajectoryStateOnSurface>::const_iterator ic=components.begin();
00168 //        ic!=components.end(); ic++ ) {
00169 //       std::cout << " comp " << ic-components.begin() << " "
00170 //              << (*ic).weight() << " "
00171 //              << (*ic).localParameters().vector()[0]/sinTheta << " "
00172 //              << sqrt((*ic).localError().matrix()[0][0])/sinTheta << std::endl;
00173 //     }
00174     
00175     ndof = 0;
00176     TransientTrackingRecHit::RecHitContainer validHits;
00177     theTraj->validRecHits(validHits);
00178     for (TransientTrackingRecHit::RecHitContainer::iterator h=validHits.begin();h!=validHits.end();++h)
00179       ndof = ndof + ((*h)->dimension())*((*h)->weight());
00180     if (theTSOS.magneticField()->inTesla(GlobalPoint(0,0,0)).mag2()<DBL_MIN) ndof = ndof - 4;
00181     else ndof = ndof - 5;
00182    
00183     TSCBLBuilderNoMaterial tscblBuilder;
00184     //    const FreeTrajectoryState & stateForProjectionToBeamLine=*innertsos.freeState();
00185     const TrajectoryStateOnSurface & stateForProjectionToBeamLineOnSurface = theTraj->closestMeasurement(GlobalPoint(bs.x0(),bs.y0(),bs.z0())).updatedState();
00186     if (!stateForProjectionToBeamLineOnSurface.isValid()){
00187       edm::LogError("CannotPropagateToBeamLine")<<"the state on the closest measurement isnot valid. skipping track.";
00188       delete theTraj;
00189       return false;
00190     }    const FreeTrajectoryState & stateForProjectionToBeamLine=*theTraj->closestMeasurement(GlobalPoint(bs.x0(),bs.y0(),bs.z0())).updatedState().freeState();
00191 
00192     LogDebug("TrackProducer") << "stateForProjectionToBeamLine=" << stateForProjectionToBeamLine;
00193 
00194     TrajectoryStateClosestToBeamLine tscbl = tscblBuilder(stateForProjectionToBeamLine,bs);
00195 
00196     if (tscbl.isValid()==false) {
00197         delete theTraj;
00198         return false;
00199     }
00200 
00201     GlobalPoint v = tscbl.trackStateAtPCA().position();
00202     math::XYZPoint  pos( v.x(), v.y(), v.z() );
00203     GlobalVector p = tscbl.trackStateAtPCA().momentum();
00204     math::XYZVector mom( p.x(), p.y(), p.z() );
00205 
00206     LogDebug("TrackProducer") << "pos=" << v << " mom=" << p << " pt=" << p.perp() << " mag=" << p.mag();
00207 
00208     theTrack = new reco::GsfTrack(theTraj->chiSquared(),
00209                                   int(ndof),//FIXME fix weight() in TrackingRecHit
00210                                   //                           theTraj->foundHits(),//FIXME to be fixed in Trajectory.h
00211                                   //                           0, //FIXME no corresponding method in trajectory.h
00212                                   //                           theTraj->lostHits(),//FIXME to be fixed in Trajectory.h
00213                                   pos, mom, tscbl.trackStateAtPCA().charge(), tscbl.trackStateAtPCA().curvilinearError());    
00214     theTrack->setAlgorithm(algo_);
00215 
00216     LogDebug("GsfTrackProducer") <<"track done\n";
00217 
00218     AlgoProduct aProduct(theTraj,std::make_pair(theTrack,seedDir));
00219     LogDebug("GsfTrackProducer") <<"track done1\n";
00220     algoResults.push_back(aProduct);
00221     LogDebug("GsfTrackProducer") <<"track done2\n";
00222     
00223     return true;
00224   } 
00225   else  return false;
00226 }