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