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
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,signed char nLoops)
00043 {
00044
00045 std::vector<Trajectory> trajVec;
00046 reco::Track * theTrack;
00047 Trajectory * theTraj;
00048 PropagationDirection seedDir = seed.direction();
00049
00050
00051 if(nLoops>0)
00052 trajVec = theFitter->fit(seed, hits, theTSOS,TrajectoryFitter::looper);
00053 else
00054 trajVec = theFitter->fit(seed, hits, theTSOS,TrajectoryFitter::standard);
00055
00056 LogDebug("TrackProducer") <<" FITTER FOUND "<< trajVec.size() << " TRAJECTORIES" <<"\n";
00057 TrajectoryStateOnSurface innertsos;
00058
00059 if (trajVec.size() != 0){
00060 theTraj = new Trajectory( trajVec.front() );
00061 theTraj->setSeedRef(seedRef);
00062
00063 if (theTraj->direction() == alongMomentum) {
00064 innertsos = theTraj->firstMeasurement().updatedState();
00065 } else {
00066 innertsos = theTraj->lastMeasurement().updatedState();
00067 }
00068
00069 ndof = 0;
00070 TransientTrackingRecHit::RecHitContainer validHits;
00071 theTraj->validRecHits(validHits);
00072 for (TransientTrackingRecHit::RecHitContainer::iterator h=validHits.begin();h!=validHits.end();++h)
00073 ndof = ndof + ((*h)->dimension())*((*h)->weight());
00074 if (theTSOS.magneticField()->inTesla(GlobalPoint(0,0,0)).mag2()<DBL_MIN) ndof = ndof - 4;
00075 else ndof = ndof - 5;
00076
00077 TSCBLBuilderNoMaterial tscblBuilder;
00078
00079 const TrajectoryStateOnSurface & stateForProjectionToBeamLineOnSurface = theTraj->closestMeasurement(GlobalPoint(bs.x0(),bs.y0(),bs.z0())).updatedState();
00080 if (!stateForProjectionToBeamLineOnSurface.isValid()){
00081 edm::LogError("CannotPropagateToBeamLine")<<"the state on the closest measurement isnot valid. skipping track.";
00082 delete theTraj;
00083 return false;
00084 }
00085 const FreeTrajectoryState & stateForProjectionToBeamLine=*stateForProjectionToBeamLineOnSurface.freeState();
00086
00087 LogDebug("TrackProducer") << "stateForProjectionToBeamLine=" << stateForProjectionToBeamLine;
00088
00089 TrajectoryStateClosestToBeamLine tscbl = tscblBuilder(stateForProjectionToBeamLine,bs);
00090
00091 if (tscbl.isValid()==false) {
00092 delete theTraj;
00093 return false;
00094 }
00095
00096 GlobalPoint v = tscbl.trackStateAtPCA().position();
00097 math::XYZPoint pos( v.x(), v.y(), v.z() );
00098 GlobalVector p = tscbl.trackStateAtPCA().momentum();
00099 math::XYZVector mom( p.x(), p.y(), p.z() );
00100
00101 LogDebug("TrackProducer") << "pos=" << v << " mom=" << p << " pt=" << p.perp() << " mag=" << p.mag();
00102
00103 theTrack = new reco::Track(theTraj->chiSquared(),
00104 int(ndof),
00105 pos, mom, tscbl.trackStateAtPCA().charge(),
00106 tscbl.trackStateAtPCA().curvilinearError(),
00107 algo_);
00108
00109 theTrack->setQualityMask(qualityMask);
00110 theTrack->setNLoops(nLoops);
00111
00112 LogDebug("TrackProducer") << "theTrack->pt()=" << theTrack->pt();
00113
00114 LogDebug("TrackProducer") <<"track done\n";
00115
00116 AlgoProduct aProduct(theTraj,std::make_pair(theTrack,seedDir));
00117 algoResults.push_back(aProduct);
00118
00119 return true;
00120 }
00121 else return false;
00122 }
00123
00124 template <> bool
00125 TrackProducerAlgorithm<reco::GsfTrack>::buildTrack (const TrajectoryFitter * theFitter,
00126 const Propagator * thePropagator,
00127 AlgoProductCollection& algoResults,
00128 TransientTrackingRecHit::RecHitContainer& hits,
00129 TrajectoryStateOnSurface& theTSOS,
00130 const TrajectorySeed& seed,
00131 float ndof,
00132 const reco::BeamSpot& bs,
00133 SeedRef seedRef,
00134 int qualityMask,signed char nLoops)
00135 {
00136
00137 std::vector<Trajectory> trajVec;
00138 reco::GsfTrack * theTrack;
00139 Trajectory * theTraj;
00140 PropagationDirection seedDir = seed.direction();
00141
00142
00143 if(nLoops>0)
00144 trajVec = theFitter->fit(seed, hits, theTSOS,TrajectoryFitter::looper);
00145 else
00146 trajVec = theFitter->fit(seed, hits, theTSOS,TrajectoryFitter::standard);
00147
00148
00149
00150 LogDebug("GsfTrackProducer") <<" FITTER FOUND "<< trajVec.size() << " TRAJECTORIES" <<"\n";
00151
00152 TrajectoryStateOnSurface innertsos;
00153 TrajectoryStateOnSurface outertsos;
00154
00155 if (trajVec.size() != 0){
00156
00157 theTraj = new Trajectory( trajVec.front() );
00158 theTraj->setSeedRef(seedRef);
00159
00160 if (theTraj->direction() == alongMomentum) {
00161 innertsos = theTraj->firstMeasurement().updatedState();
00162 outertsos = theTraj->lastMeasurement().updatedState();
00163 } else {
00164 innertsos = theTraj->lastMeasurement().updatedState();
00165 outertsos = theTraj->firstMeasurement().updatedState();
00166 }
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183 ndof = 0;
00184 TransientTrackingRecHit::RecHitContainer validHits;
00185 theTraj->validRecHits(validHits);
00186 for (TransientTrackingRecHit::RecHitContainer::iterator h=validHits.begin();h!=validHits.end();++h)
00187 ndof = ndof + ((*h)->dimension())*((*h)->weight());
00188 if (theTSOS.magneticField()->inTesla(GlobalPoint(0,0,0)).mag2()<DBL_MIN) ndof = ndof - 4;
00189 else ndof = ndof - 5;
00190
00191 TSCBLBuilderNoMaterial tscblBuilder;
00192
00193 const TrajectoryStateOnSurface & stateForProjectionToBeamLineOnSurface = theTraj->closestMeasurement(GlobalPoint(bs.x0(),bs.y0(),bs.z0())).updatedState();
00194 if (!stateForProjectionToBeamLineOnSurface.isValid()){
00195 edm::LogError("CannotPropagateToBeamLine")<<"the state on the closest measurement isnot valid. skipping track.";
00196 delete theTraj;
00197 return false;
00198 } const FreeTrajectoryState & stateForProjectionToBeamLine=*theTraj->closestMeasurement(GlobalPoint(bs.x0(),bs.y0(),bs.z0())).updatedState().freeState();
00199
00200 LogDebug("TrackProducer") << "stateForProjectionToBeamLine=" << stateForProjectionToBeamLine;
00201
00202 TrajectoryStateClosestToBeamLine tscbl = tscblBuilder(stateForProjectionToBeamLine,bs);
00203
00204 if (tscbl.isValid()==false) {
00205 delete theTraj;
00206 return false;
00207 }
00208
00209 GlobalPoint v = tscbl.trackStateAtPCA().position();
00210 math::XYZPoint pos( v.x(), v.y(), v.z() );
00211 GlobalVector p = tscbl.trackStateAtPCA().momentum();
00212 math::XYZVector mom( p.x(), p.y(), p.z() );
00213
00214 LogDebug("TrackProducer") << "pos=" << v << " mom=" << p << " pt=" << p.perp() << " mag=" << p.mag();
00215
00216 theTrack = new reco::GsfTrack(theTraj->chiSquared(),
00217 int(ndof),
00218
00219
00220
00221 pos, mom, tscbl.trackStateAtPCA().charge(), tscbl.trackStateAtPCA().curvilinearError());
00222 theTrack->setAlgorithm(algo_);
00223
00224 LogDebug("GsfTrackProducer") <<"track done\n";
00225
00226 AlgoProduct aProduct(theTraj,std::make_pair(theTrack,seedDir));
00227 LogDebug("GsfTrackProducer") <<"track done1\n";
00228 algoResults.push_back(aProduct);
00229 LogDebug("GsfTrackProducer") <<"track done2\n";
00230
00231 return true;
00232 }
00233 else return false;
00234 }