CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_1/src/Alignment/ReferenceTrajectories/src/TrajectoryFactoryBase.cc

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