00001 #include "FWCore/MessageLogger/interface/MessageLogger.h" 00002 #include "FWCore/ParameterSet/interface/ParameterSet.h" 00003 #include "FWCore/Utilities/interface/Exception.h" 00004 00005 #include "RecoTracker/TransientTrackingRecHit/interface/ProjectedRecHit2D.h" 00006 00007 #include "Alignment/ReferenceTrajectories/interface/TrajectoryFactoryBase.h" 00008 00009 00010 TrajectoryFactoryBase::TrajectoryFactoryBase( const edm::ParameterSet & config ) 00011 { 00012 const std::string strMaterialEffects = config.getParameter< std::string >( "MaterialEffects" ); 00013 theMaterialEffects = this->materialEffects( strMaterialEffects ); 00014 00015 const std::string strPropagationDirection = config.getParameter< std::string >( "PropagationDirection" ); 00016 thePropDir = this->propagationDirection( strPropagationDirection ); 00017 00018 theUseWithoutDet = config.getParameter< bool >( "UseHitWithoutDet" ); 00019 theUseInvalidHits = config.getParameter< bool >( "UseInvalidHits" ); 00020 theUseProjectedHits = config.getParameter< bool >( "UseProjectedHits" ); 00021 } 00022 00023 00024 TrajectoryFactoryBase::~TrajectoryFactoryBase( void ) {} 00025 00026 00027 const TrajectoryFactoryBase::TrajectoryInput 00028 TrajectoryFactoryBase::innermostStateAndRecHits( const ConstTrajTrackPair & track ) const 00029 { 00030 TrajectoryInput result; 00031 00032 // get the trajectory measurements in the correct order, i.e. reverse if needed 00033 Trajectory::DataContainer trajectoryMeasurements 00034 = this->orderedTrajectoryMeasurements( *track.first ); 00035 Trajectory::DataContainer::iterator itM = trajectoryMeasurements.begin(); 00036 00037 // get the innermost valid trajectory state - the corresponding hit must be o.k. as well 00038 while ( itM != trajectoryMeasurements.end() ) 00039 { 00040 if ( ( *itM ).updatedState().isValid() && useRecHit( ( *itM ).recHit() ) ) break; 00041 ++itM; 00042 } 00043 if ( itM != trajectoryMeasurements.end() ) result.first = ( *itM ).updatedState(); 00044 00045 // get the valid RecHits 00046 while ( itM != trajectoryMeasurements.end() ) 00047 { 00048 TransientTrackingRecHit::ConstRecHitPointer aRecHit = ( *itM ).recHit(); 00049 if ( useRecHit( aRecHit ) ) result.second.push_back( aRecHit ); 00050 ++itM; 00051 } 00052 00053 return result; 00054 } 00055 00056 00057 const Trajectory::DataContainer 00058 TrajectoryFactoryBase::orderedTrajectoryMeasurements( const Trajectory & trajectory ) const 00059 { 00060 const PropagationDirection dir = trajectory.direction(); 00061 const bool hitsAreReverse = ( ( dir == thePropDir || thePropDir == anyDirection ) ? false : true ); 00062 00063 const Trajectory::DataContainer & original = trajectory.measurements(); 00064 00065 if ( hitsAreReverse ) 00066 { 00067 // Simply use this line instead of the copying by hand? 00068 // const Trajectory::DataContainer reordered(original.rbegin(), original.rend()); 00069 Trajectory::DataContainer reordered; 00070 reordered.reserve( original.size() ); 00071 00072 Trajectory::DataContainer::const_reverse_iterator itM; 00073 for ( itM = original.rbegin(); itM != original.rend(); ++itM ) 00074 { 00075 reordered.push_back( *itM ); 00076 } 00077 return reordered; 00078 } 00079 00080 return original; 00081 } 00082 00083 00084 bool TrajectoryFactoryBase::sameSurface( const Surface& s1, const Surface& s2 ) const 00085 { 00086 // - Should use perp2() instead of perp() 00087 // - Should not rely on floating point equality, but make a minimal range, e.g. 1.e-6 ? 00088 return ( s1.eta() == s2.eta() ) && ( s1.phi() == s2.phi() ) && ( s1.position().perp() == s2.position().perp() ); 00089 } 00090 00091 00092 bool 00093 TrajectoryFactoryBase::useRecHit( const TransientTrackingRecHit::ConstRecHitPointer& hitPtr ) const 00094 { 00095 const GeomDet* det = hitPtr->det(); 00096 if ( !det && !theUseWithoutDet ) return false; 00097 00098 if ( !( theUseInvalidHits || hitPtr->isValid() ) ) return false; 00099 00100 if ( !theUseProjectedHits ) 00101 { 00102 const ProjectedRecHit2D* projectedHit = dynamic_cast< const ProjectedRecHit2D* >( hitPtr.get() ); 00103 if ( projectedHit != 0 ) return false; 00104 } 00105 00106 return true; 00107 } 00108 00109 00110 const TrajectoryFactoryBase::MaterialEffects 00111 TrajectoryFactoryBase::materialEffects( const std::string & strME ) const 00112 { 00113 if ( strME == "MultipleScattering" ) return ReferenceTrajectoryBase::multipleScattering; 00114 if ( strME == "EnergyLoss" ) return ReferenceTrajectoryBase::energyLoss; 00115 if ( strME == "Combined" ) return ReferenceTrajectoryBase::combined; 00116 if ( strME == "None" ) return ReferenceTrajectoryBase::none; 00117 00118 throw cms::Exception("BadConfig") 00119 << "[TrajectoryFactoryBase::materialEffects] Unknown parameter: " << strME; 00120 } 00121 00122 00123 const PropagationDirection 00124 TrajectoryFactoryBase::propagationDirection( const std::string & strPD ) const 00125 { 00126 if ( strPD == "oppositeToMomentum" ) return oppositeToMomentum; 00127 if ( strPD == "alongMomentum" ) return alongMomentum; 00128 if ( strPD == "anyDirection" ) return anyDirection; 00129 00130 throw cms::Exception("BadConfig") 00131 << "[TrajectoryFactoryBase::propagationDirection] Unknown parameter: " << strPD; 00132 }