Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:57:21

0001 // Local include from plugins directory...:
0002 #include "BzeroReferenceTrajectoryFactory.h"
0003 
0004 #include "Alignment/ReferenceTrajectories/interface/BzeroReferenceTrajectory.h"
0005 #include "Alignment/ReferenceTrajectories/interface/TrajectoryFactoryPlugin.h"
0006 
0007 #include "FWCore/Framework/interface/ESHandle.h"
0008 #include "FWCore/Framework/interface/EventSetup.h"
0009 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0011 
0012 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
0013 
0014 #include "Alignment/ReferenceTrajectories/interface/TrajectoryFactoryBase.h"
0015 
0016 /// A factory that produces instances of class BzeroReferenceTrajectory from a
0017 /// given TrajTrackPairCollection.
0018 
0019 /////////////////////////////////////////////////////////////////////
0020 /////////////////////////////////////////////////////////////////////
0021 /////////////////////////////////////////////////////////////////////
0022 
0023 BzeroReferenceTrajectoryFactory::BzeroReferenceTrajectoryFactory(const edm::ParameterSet &config,
0024                                                                  edm::ConsumesCollector &iC)
0025     : TrajectoryFactoryBase(config, iC),
0026       m_MagFieldToken(iC.esConsumes()),
0027       theMass(config.getParameter<double>("ParticleMass")),
0028       theMomentumEstimate(config.getParameter<double>("MomentumEstimate")) {
0029   edm::LogInfo("Alignment") << "@SUB=BzeroReferenceTrajectoryFactory"
0030                             << "mass: " << theMass << "\nmomentum: " << theMomentumEstimate;
0031 }
0032 
0033 BzeroReferenceTrajectoryFactory::~BzeroReferenceTrajectoryFactory(void) {}
0034 
0035 /////////////////////////////////////////////////////////////////////
0036 const BzeroReferenceTrajectoryFactory::ReferenceTrajectoryCollection BzeroReferenceTrajectoryFactory::trajectories(
0037     const edm::EventSetup &setup, const ConstTrajTrackPairCollection &tracks, const reco::BeamSpot &beamSpot) const {
0038   ReferenceTrajectoryCollection trajectories;
0039 
0040   const MagneticField *magneticField = &setup.getData(m_MagFieldToken);
0041 
0042   ConstTrajTrackPairCollection::const_iterator itTracks = tracks.begin();
0043 
0044   while (itTracks != tracks.end()) {
0045     TrajectoryInput input = this->innermostStateAndRecHits(*itTracks);
0046     // Check input: If all hits were rejected, the TSOS is initialized as invalid.
0047     if (input.first.isValid()) {
0048       ReferenceTrajectoryBase::Config config(materialEffects(), propagationDirection(), theMass, theMomentumEstimate);
0049       config.useBeamSpot = useBeamSpot_;
0050       config.includeAPEs = includeAPEs_;
0051       config.allowZeroMaterial = allowZeroMaterial_;
0052       // set the flag for reversing the RecHits to false, since they are already in the correct order.
0053       config.hitsAreReverse = false;
0054       trajectories.push_back(ReferenceTrajectoryPtr(
0055           new BzeroReferenceTrajectory(input.first, input.second, magneticField, beamSpot, config)));
0056     }
0057 
0058     ++itTracks;
0059   }
0060 
0061   return trajectories;
0062 }
0063 
0064 /////////////////////////////////////////////////////////////////////
0065 const BzeroReferenceTrajectoryFactory::ReferenceTrajectoryCollection BzeroReferenceTrajectoryFactory::trajectories(
0066     const edm::EventSetup &setup,
0067     const ConstTrajTrackPairCollection &tracks,
0068     const ExternalPredictionCollection &external,
0069     const reco::BeamSpot &beamSpot) const {
0070   ReferenceTrajectoryCollection trajectories;
0071 
0072   if (tracks.size() != external.size()) {
0073     edm::LogInfo("ReferenceTrajectories")
0074         << "@SUB=BzeroReferenceTrajectoryFactory::trajectories"
0075         << "Inconsistent input:\n"
0076         << "\tnumber of tracks = " << tracks.size() << "\tnumber of external predictions = " << external.size();
0077     return trajectories;
0078   }
0079 
0080   const MagneticField *magneticField = &setup.getData(m_MagFieldToken);
0081 
0082   ConstTrajTrackPairCollection::const_iterator itTracks = tracks.begin();
0083   ExternalPredictionCollection::const_iterator itExternal = external.begin();
0084 
0085   while (itTracks != tracks.end()) {
0086     TrajectoryInput input = innermostStateAndRecHits(*itTracks);
0087     // Check input: If all hits were rejected, the TSOS is initialized as invalid.
0088     if (input.first.isValid()) {
0089       if ((*itExternal).isValid() && sameSurface((*itExternal).surface(), input.first.surface())) {
0090         ReferenceTrajectoryBase::Config config(materialEffects(), propagationDirection(), theMass, theMomentumEstimate);
0091         config.useBeamSpot = useBeamSpot_;
0092         config.includeAPEs = includeAPEs_;
0093         config.allowZeroMaterial = allowZeroMaterial_;
0094         // set the flag for reversing the RecHits to false, since they are already in the correct order.
0095         config.hitsAreReverse = false;
0096         ReferenceTrajectoryPtr refTraj(
0097             new BzeroReferenceTrajectory(*itExternal, input.second, magneticField, beamSpot, config));
0098 
0099         AlgebraicSymMatrix externalParamErrors(asHepMatrix<5>((*itExternal).localError().matrix()));
0100         refTraj->setParameterErrors(externalParamErrors.sub(2, 5));
0101 
0102         trajectories.push_back(refTraj);
0103       } else {
0104         ReferenceTrajectoryBase::Config config(materialEffects(), propagationDirection(), theMass, theMomentumEstimate);
0105         config.useBeamSpot = useBeamSpot_;
0106         config.includeAPEs = includeAPEs_;
0107         config.allowZeroMaterial = allowZeroMaterial_;
0108         // set the flag for reversing the RecHits to false, since they are already in the correct order.
0109         config.hitsAreReverse = false;
0110         trajectories.push_back(ReferenceTrajectoryPtr(
0111             new BzeroReferenceTrajectory(input.first, input.second, magneticField, beamSpot, config)));
0112       }
0113     }
0114 
0115     ++itTracks;
0116     ++itExternal;
0117   }
0118 
0119   return trajectories;
0120 }
0121 
0122 DEFINE_EDM_PLUGIN(TrajectoryFactoryPlugin, BzeroReferenceTrajectoryFactory, "BzeroReferenceTrajectoryFactory");