CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/Alignment/ReferenceTrajectories/plugins/BzeroReferenceTrajectoryFactory.cc

Go to the documentation of this file.
00001 #include "Alignment/ReferenceTrajectories/interface/BzeroReferenceTrajectory.h" 
00002 #include "Alignment/ReferenceTrajectories/interface/TrajectoryFactoryPlugin.h"
00003 
00004 #include "FWCore/Framework/interface/ESHandle.h"
00005 #include "FWCore/Framework/interface/EventSetup.h"
00006 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00008 
00009 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h" 
00010 
00011 #include "Alignment/ReferenceTrajectories/interface/TrajectoryFactoryBase.h"
00012 
00015 
00016 
00017 class BzeroReferenceTrajectoryFactory : public TrajectoryFactoryBase
00018 {
00019 public:
00020 
00021   BzeroReferenceTrajectoryFactory(const edm::ParameterSet &config);
00022   virtual ~BzeroReferenceTrajectoryFactory();
00023 
00025   virtual const ReferenceTrajectoryCollection trajectories(const edm::EventSetup &setup,
00026                                                            const ConstTrajTrackPairCollection &tracks,
00027                                                            const reco::BeamSpot &beamSpot) const;
00028 
00029   virtual const ReferenceTrajectoryCollection trajectories(const edm::EventSetup &setup,
00030                                                            const ConstTrajTrackPairCollection &tracks,
00031                                                            const ExternalPredictionCollection &external,
00032                                                            const reco::BeamSpot &beamSpot) const;
00033 
00034   virtual BzeroReferenceTrajectoryFactory* clone() const { return new BzeroReferenceTrajectoryFactory( *this ); }
00035 
00036 private:
00037 
00038   double theMass;
00039   double theMomentumEstimate;
00040 };
00041 
00042 
00046 
00047 BzeroReferenceTrajectoryFactory::BzeroReferenceTrajectoryFactory( const edm::ParameterSet & config ) :
00048   TrajectoryFactoryBase( config )
00049 {
00050   theMass = config.getParameter< double >( "ParticleMass" );
00051   theMomentumEstimate = config.getParameter< double >( "MomentumEstimate" );
00052   theUseBeamSpot = config.getParameter< bool >( "UseBeamSpot" );
00053 }
00054 
00055 
00056 BzeroReferenceTrajectoryFactory::~BzeroReferenceTrajectoryFactory( void ) {}
00057 
00058 
00059 const BzeroReferenceTrajectoryFactory::ReferenceTrajectoryCollection
00060 BzeroReferenceTrajectoryFactory::trajectories(const edm::EventSetup &setup,
00061                                               const ConstTrajTrackPairCollection &tracks,
00062                                               const reco::BeamSpot &beamSpot) const
00063 {
00064   ReferenceTrajectoryCollection trajectories;
00065 
00066   edm::ESHandle< MagneticField > magneticField;
00067   setup.get< IdealMagneticFieldRecord >().get( magneticField );
00068 
00069   ConstTrajTrackPairCollection::const_iterator itTracks = tracks.begin();
00070 
00071   while ( itTracks != tracks.end() )
00072   { 
00073     TrajectoryInput input = this->innermostStateAndRecHits( *itTracks );
00074     // Check input: If all hits were rejected, the TSOS is initialized as invalid.
00075     if ( input.first.isValid() )
00076     {
00077       // set the flag for reversing the RecHits to false, since they are already in the correct order.
00078       trajectories.push_back(ReferenceTrajectoryPtr(new BzeroReferenceTrajectory(input.first, input.second, false,
00079                                                                                  magneticField.product(),
00080                                                                                  materialEffects(),
00081                                                                                  propagationDirection(),
00082                                                                                  theMass, theMomentumEstimate,
00083                                                                                  theUseBeamSpot, beamSpot)));
00084     }
00085 
00086     ++itTracks;
00087   }
00088 
00089   return trajectories;
00090 }
00091 
00092 
00093 const BzeroReferenceTrajectoryFactory::ReferenceTrajectoryCollection
00094 BzeroReferenceTrajectoryFactory::trajectories(const edm::EventSetup &setup,
00095                                               const ConstTrajTrackPairCollection &tracks,
00096                                               const ExternalPredictionCollection &external,
00097                                               const reco::BeamSpot &beamSpot) const
00098 {
00099   ReferenceTrajectoryCollection trajectories;
00100 
00101   if ( tracks.size() != external.size() )
00102   {
00103     edm::LogInfo("ReferenceTrajectories") << "@SUB=BzeroReferenceTrajectoryFactory::trajectories"
00104                                           << "Inconsistent input:\n"
00105                                           << "\tnumber of tracks = " << tracks.size()
00106                                           << "\tnumber of external predictions = " << external.size();
00107     return trajectories;
00108   }
00109 
00110   edm::ESHandle< MagneticField > magneticField;
00111   setup.get< IdealMagneticFieldRecord >().get( magneticField );
00112 
00113   ConstTrajTrackPairCollection::const_iterator itTracks = tracks.begin();
00114   ExternalPredictionCollection::const_iterator itExternal = external.begin();
00115 
00116   while ( itTracks != tracks.end() )
00117   {
00118     TrajectoryInput input = innermostStateAndRecHits( *itTracks );
00119     // Check input: If all hits were rejected, the TSOS is initialized as invalid.
00120     if ( input.first.isValid() )
00121     {
00122       if ( (*itExternal).isValid() && sameSurface( (*itExternal).surface(), input.first.surface() ) )
00123       {
00124         // set the flag for reversing the RecHits to false, since they are already in the correct order.
00125         ReferenceTrajectoryPtr refTraj( new BzeroReferenceTrajectory( *itExternal, input.second, false,
00126                                                                       magneticField.product(), materialEffects(),
00127                                                                       propagationDirection(), theMass,
00128                                                                       theMomentumEstimate, 
00129                                                                       theUseBeamSpot, beamSpot ) );
00130 
00131         AlgebraicSymMatrix externalParamErrors( asHepMatrix<5>( (*itExternal).localError().matrix() ) );
00132         refTraj->setParameterErrors( externalParamErrors.sub( 2, 5 ) );
00133 
00134         trajectories.push_back( refTraj );
00135       }
00136       else
00137       {
00138         trajectories.push_back(ReferenceTrajectoryPtr(new BzeroReferenceTrajectory(input.first, input.second, false,
00139                                                                                    magneticField.product(),
00140                                                                                    materialEffects(),
00141                                                                                    propagationDirection(),
00142                                                                                    theMass, theMomentumEstimate,
00143                                                                                    theUseBeamSpot, beamSpot)));
00144       }
00145     }
00146 
00147     ++itTracks;
00148     ++itExternal;
00149   }
00150 
00151   return trajectories;
00152 }
00153 
00154 
00155 
00156 DEFINE_EDM_PLUGIN( TrajectoryFactoryPlugin, BzeroReferenceTrajectoryFactory, "BzeroReferenceTrajectoryFactory" );