File indexing completed on 2024-04-06 11:57:22
0001 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0002 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0003 #include "FWCore/Utilities/interface/Exception.h"
0004
0005 #include "RecoTracker/TransientTrackingRecHit/interface/ProjectedRecHit2D.h"
0006
0007 #include "Alignment/ReferenceTrajectories/interface/TrajectoryFactoryBase.h"
0008
0009 TrajectoryFactoryBase::TrajectoryFactoryBase(const edm::ParameterSet& config, const edm::ConsumesCollector& iC)
0010 : TrajectoryFactoryBase(config, 1, iC) {}
0011
0012 TrajectoryFactoryBase::TrajectoryFactoryBase(const edm::ParameterSet& config,
0013 unsigned int tracksPerTrajectory,
0014 const edm::ConsumesCollector& iC)
0015 : cfg_(config),
0016 tracksPerTrajectory_(tracksPerTrajectory),
0017 materialEffects_(materialEffects(config.getParameter<std::string>("MaterialEffects"))),
0018 propDir_(propagationDirection(config.getParameter<std::string>("PropagationDirection"))),
0019 useWithoutDet_(config.getParameter<bool>("UseHitWithoutDet")),
0020 useInvalidHits_(config.getParameter<bool>("UseInvalidHits")),
0021 useProjectedHits_(config.getParameter<bool>("UseProjectedHits")),
0022 useBeamSpot_(config.getParameter<bool>("UseBeamSpot")),
0023 includeAPEs_(config.getParameter<bool>("IncludeAPEs")),
0024 allowZeroMaterial_(config.getParameter<bool>("AllowZeroMaterial")) {
0025 edm::LogInfo("Alignment") << "@SUB=TrajectoryFactoryBase"
0026 << "TrajectoryFactory '" << cfg_.getParameter<std::string>("TrajectoryFactoryName")
0027 << "' with following settings:"
0028 << "\nmaterial effects: " << cfg_.getParameter<std::string>("MaterialEffects")
0029 << "\npropagation: " << cfg_.getParameter<std::string>("PropagationDirection")
0030 << "\nuse hits without det: " << (useWithoutDet_ ? "yes" : "no")
0031 << "\nuse invalid hits: " << (useInvalidHits_ ? "yes" : "no")
0032 << "\nuse projected hits: " << (useProjectedHits_ ? "yes" : "no")
0033 << "\nuse beamspot: " << (useBeamSpot_ ? "yes" : "no")
0034 << "\ninclude APEs: " << (includeAPEs_ ? "yes" : "no")
0035 << "\nallow zero material: " << (allowZeroMaterial_ ? "yes" : "no");
0036 }
0037
0038 TrajectoryFactoryBase::~TrajectoryFactoryBase(void) {}
0039
0040 const TrajectoryFactoryBase::TrajectoryInput TrajectoryFactoryBase::innermostStateAndRecHits(
0041 const ConstTrajTrackPair& track) const {
0042 TrajectoryInput result;
0043
0044
0045 Trajectory::DataContainer trajectoryMeasurements = this->orderedTrajectoryMeasurements(*track.first);
0046 Trajectory::DataContainer::iterator itM = trajectoryMeasurements.begin();
0047
0048
0049 while (itM != trajectoryMeasurements.end()) {
0050 if ((*itM).updatedState().isValid() && useRecHit((*itM).recHit()))
0051 break;
0052 ++itM;
0053 }
0054 if (itM != trajectoryMeasurements.end())
0055 result.first = (*itM).updatedState();
0056
0057
0058 while (itM != trajectoryMeasurements.end()) {
0059 TransientTrackingRecHit::ConstRecHitPointer aRecHit = (*itM).recHit();
0060 if (useRecHit(aRecHit))
0061 result.second.push_back(aRecHit);
0062 ++itM;
0063 }
0064
0065 return result;
0066 }
0067
0068 const Trajectory::DataContainer TrajectoryFactoryBase::orderedTrajectoryMeasurements(
0069 const Trajectory& trajectory) const {
0070 const PropagationDirection dir = trajectory.direction();
0071 const bool hitsAreReverse = ((dir == propDir_ || propDir_ == anyDirection) ? false : true);
0072
0073 const Trajectory::DataContainer& original = trajectory.measurements();
0074
0075 if (hitsAreReverse) {
0076
0077
0078 Trajectory::DataContainer reordered;
0079 reordered.reserve(original.size());
0080
0081 Trajectory::DataContainer::const_reverse_iterator itM;
0082 for (itM = original.rbegin(); itM != original.rend(); ++itM) {
0083 reordered.push_back(*itM);
0084 }
0085 return reordered;
0086 }
0087
0088 return original;
0089 }
0090
0091 bool TrajectoryFactoryBase::sameSurface(const Surface& s1, const Surface& s2) const {
0092
0093
0094 return (s1.eta() == s2.eta()) && (s1.phi() == s2.phi()) && (s1.position().perp() == s2.position().perp());
0095 }
0096
0097 bool TrajectoryFactoryBase::useRecHit(const TransientTrackingRecHit::ConstRecHitPointer& hitPtr) const {
0098 const GeomDet* det = hitPtr->det();
0099 if (!det && !useWithoutDet_)
0100 return false;
0101
0102 if (!(useInvalidHits_ || hitPtr->isValid()))
0103 return false;
0104
0105 if (!useProjectedHits_) {
0106 if (trackerHitRTTI::isProjected(*hitPtr))
0107 return false;
0108 }
0109
0110 return true;
0111 }
0112
0113 TrajectoryFactoryBase::MaterialEffects TrajectoryFactoryBase::materialEffects(const std::string& strME) const {
0114 if (strME == "MultipleScattering")
0115 return ReferenceTrajectoryBase::multipleScattering;
0116 if (strME == "EnergyLoss")
0117 return ReferenceTrajectoryBase::energyLoss;
0118 if (strME == "Combined")
0119 return ReferenceTrajectoryBase::combined;
0120 if (strME == "None")
0121 return ReferenceTrajectoryBase::none;
0122 if (strME == "BreakPoints")
0123 return ReferenceTrajectoryBase::breakPoints;
0124 if (strME == "BrokenLines")
0125 return ReferenceTrajectoryBase::brokenLinesCoarse;
0126 if (strME == "BrokenLinesCoarse")
0127 return ReferenceTrajectoryBase::brokenLinesCoarse;
0128 if (strME == "BrokenLinesFine")
0129 return ReferenceTrajectoryBase::brokenLinesFine;
0130 if (strME == "LocalGBL")
0131 return ReferenceTrajectoryBase::localGBL;
0132 if (strME == "CurvlinGBL")
0133 return ReferenceTrajectoryBase::curvlinGBL;
0134
0135 throw cms::Exception("BadConfig") << "[TrajectoryFactoryBase::materialEffects] Unknown parameter: " << strME;
0136 }
0137
0138 PropagationDirection TrajectoryFactoryBase::propagationDirection(const std::string& strPD) const {
0139 if (strPD == "oppositeToMomentum")
0140 return oppositeToMomentum;
0141 if (strPD == "alongMomentum")
0142 return alongMomentum;
0143 if (strPD == "anyDirection")
0144 return anyDirection;
0145
0146 throw cms::Exception("BadConfig") << "[TrajectoryFactoryBase::propagationDirection] Unknown parameter: " << strPD;
0147 }