File indexing completed on 2024-04-06 12:28:52
0001 #include "SimpleNavigableLayer.h"
0002 #include "TrackingTools/DetLayers/interface/NavigationSchool.h"
0003
0004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0005
0006 #include "DataFormats/GeometrySurface/interface/BoundCylinder.h"
0007 #include "DataFormats/GeometrySurface/interface/BoundDisk.h"
0008 #include "TrackingTools/PatternTools/interface/TransverseImpactPointExtrapolator.h"
0009 #include "FWCore/Utilities/interface/Likely.h"
0010
0011 #include <set>
0012
0013 using namespace std;
0014
0015 TrajectoryStateOnSurface SimpleNavigableLayer::crossingState(const FreeTrajectoryState& fts,
0016 PropagationDirection dir) const {
0017
0018 GlobalPoint initialPoint = fts.position();
0019 TransverseImpactPointExtrapolator middle;
0020 GlobalPoint center(0, 0, 0);
0021 TSOS propState = middle.extrapolate(fts, center, propagator(dir));
0022 if (!propState.isValid())
0023 return TrajectoryStateOnSurface();
0024
0025 FreeTrajectoryState const& dest = *propState.freeState();
0026 GlobalPoint middlePoint = dest.position();
0027 const float toCloseToEachOther2 = 1e-4 * 1e-4;
0028 if UNLIKELY ((middlePoint - initialPoint).mag2() < toCloseToEachOther2) {
0029 LogDebug("SimpleNavigableLayer")
0030 << "initial state and PCA are identical. Things are bound to fail. Do not add the link.";
0031 return TrajectoryStateOnSurface();
0032 }
0033
0034
0035
0036
0037
0038
0039
0040
0041 LogDebug("SimpleNavigableLayer") << "self propagating(" << dir << ") from:\n"
0042 << fts << "\n"
0043 << dest << "\n"
0044 << " and the direction is: " << dir;
0045
0046
0047
0048 propState = propagator(dir).propagate(dest, detLayer()->surface());
0049 if (!propState.isValid())
0050 return TrajectoryStateOnSurface();
0051
0052 const FreeTrajectoryState& dest2 = *propState.freeState();
0053 GlobalPoint finalPoint = dest2.position();
0054 LogDebug("SimpleNavigableLayer") << "second propagation(" << dir << ") to: \n" << dest2;
0055 double finalDot = (middlePoint - initialPoint).basicVector().dot((finalPoint - middlePoint).basicVector());
0056 if UNLIKELY (finalDot < 0) {
0057 LogDebug("SimpleNavigableLayer") << "switch side back: ABORT.";
0058 return TrajectoryStateOnSurface();
0059 }
0060 return propState;
0061 }
0062
0063 bool SimpleNavigableLayer::wellInside(const FreeTrajectoryState& fts,
0064 PropagationDirection dir,
0065 const BarrelDetLayer* bl,
0066 DLC& result) const {
0067 TSOS propState = (bl == detLayer()) ? crossingState(fts, dir) : propagator(dir).propagate(fts, bl->specificSurface());
0068
0069 if (!propState.isValid())
0070 return false;
0071
0072
0073 if (theCheckCrossingSide) {
0074 bool backTobackTransverse =
0075 (fts.position().x() * propState.globalPosition().x() + fts.position().y() * propState.globalPosition().y()) < 0;
0076 bool backToback = propState.globalPosition().basicVector().dot(fts.position().basicVector()) < 0;
0077
0078 if (backTobackTransverse || backToback) {
0079 LogTrace("TkNavigation") << "Crossing over prevented!\nStaring from (x,y,z,r) (" << fts.position().x() << ","
0080 << fts.position().y() << "," << fts.position().z() << "," << fts.position().perp()
0081 << ") going to TSOS (x,y,z,r)" << propState.globalPosition().x() << ","
0082 << propState.globalPosition().y() << "," << propState.globalPosition().z() << ","
0083 << propState.globalPosition().perp() << ")";
0084 return false;
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099 }
0100 }
0101
0102 const Bounds& bounds(bl->specificSurface().bounds());
0103 float length = bounds.length() * 0.5f;
0104
0105
0106 float deltaZ =
0107 0.5f * bounds.thickness() * std::abs(propState.globalDirection().z()) / propState.globalDirection().perp();
0108
0109
0110 const float nSigma = theEpsilon;
0111 if (propState.hasError()) {
0112 deltaZ += nSigma * sqrt(fts.cartesianError().position().czz());
0113 }
0114
0115
0116
0117 float zpos = propState.globalPosition().z();
0118 if (std::abs(zpos) < length + deltaZ)
0119 result.push_back(bl);
0120
0121 return std::abs(zpos) < length - deltaZ;
0122 }
0123
0124 bool SimpleNavigableLayer::wellInside(const FreeTrajectoryState& fts,
0125 PropagationDirection dir,
0126 const ForwardDetLayer* fl,
0127 DLC& result) const {
0128 TSOS propState = propagator(dir).propagate(fts, fl->specificSurface());
0129 if (!propState.isValid())
0130 return false;
0131
0132 if (fl == detLayer()) {
0133 LogDebug("SimpleNavigableLayer") << "self propagating from:\n" << fts << "\n to \n" << *propState.freeState();
0134 }
0135
0136
0137 if (theCheckCrossingSide) {
0138 bool backTobackTransverse =
0139 (fts.position().x() * propState.globalPosition().x() + fts.position().y() * propState.globalPosition().y()) < 0;
0140 bool backToback = propState.globalPosition().basicVector().dot(fts.position().basicVector()) < 0;
0141
0142 if (backTobackTransverse || backToback) {
0143 LogTrace("TkNavigation") << "Crossing over prevented!\nStaring from (x,y,z,r) (" << fts.position().x() << ","
0144 << fts.position().y() << "," << fts.position().z() << "," << fts.position().perp()
0145 << ") going to TSOS (x,y,z,r)" << propState.globalPosition().x() << ","
0146 << propState.globalPosition().y() << "," << propState.globalPosition().z() << ","
0147 << propState.globalPosition().perp() << ")";
0148 ;
0149 return false;
0150
0151
0152 }
0153 }
0154
0155 float rpos = propState.globalPosition().perp();
0156 float innerR = fl->specificSurface().innerRadius();
0157 float outerR = fl->specificSurface().outerRadius();
0158
0159
0160 float deltaR = 0.5f * fl->surface().bounds().thickness() * propState.localDirection().perp() /
0161 std::abs(propState.localDirection().z());
0162
0163
0164 const float nSigma = theEpsilon;
0165 if (propState.hasError()) {
0166 LocalError err = propState.localError().positionError();
0167
0168 deltaR += nSigma * sqrt(err.xx() + err.yy());
0169 }
0170
0171
0172
0173 if (innerR - deltaR < rpos && rpos < outerR + deltaR)
0174 result.push_back(fl);
0175 return (innerR + deltaR < rpos && rpos < outerR - deltaR);
0176 }
0177
0178 bool SimpleNavigableLayer::wellInside(const FreeTrajectoryState& fts,
0179 PropagationDirection dir,
0180 const DLC& layers,
0181 DLC& result) const {
0182 for (auto l : layers) {
0183 if (l->isBarrel()) {
0184 const BarrelDetLayer* bl = reinterpret_cast<const BarrelDetLayer*>(l);
0185 if (wellInside(fts, dir, bl, result))
0186 return true;
0187 } else {
0188 const ForwardDetLayer* fl = reinterpret_cast<const ForwardDetLayer*>(l);
0189 if (wellInside(fts, dir, fl, result))
0190 return true;
0191 }
0192 }
0193 return false;
0194 }
0195
0196 bool SimpleNavigableLayer::wellInside(
0197 const FreeTrajectoryState& fts, PropagationDirection dir, ConstBDLI begin, ConstBDLI end, DLC& result) const {
0198 for (ConstBDLI i = begin; i < end; i++) {
0199 if (wellInside(fts, dir, *i, result))
0200 return true;
0201 }
0202 return false;
0203 }
0204
0205 bool SimpleNavigableLayer::wellInside(
0206 const FreeTrajectoryState& fts, PropagationDirection dir, ConstFDLI begin, ConstFDLI end, DLC& result) const {
0207 for (ConstFDLI i = begin; i < end; i++) {
0208 if (wellInside(fts, dir, *i, result))
0209 return true;
0210 }
0211 return false;
0212 }
0213
0214 std::vector<const DetLayer*> SimpleNavigableLayer::compatibleLayers(const FreeTrajectoryState& fts,
0215 PropagationDirection timeDirection,
0216 int& counter) const {
0217 typedef std::vector<const DetLayer*> Lvect;
0218 typedef std::set<const DetLayer*> Lset;
0219
0220
0221 const Lvect& someLayers = nextLayers(fts, timeDirection);
0222 if (someLayers.empty()) {
0223 LogDebug("SimpleNavigableLayer") << "Number of compatible layers: " << 0;
0224 return someLayers;
0225 }
0226
0227 Lset collect;
0228 Lset layerToTry, nextLayerToTry;
0229 layerToTry.insert(someLayers.begin(), someLayers.end());
0230
0231 while (!layerToTry.empty() && (counter++) <= 150) {
0232 LogDebug("SimpleNavigableLayer") << counter << "] going to check on : " << layerToTry.size() << " next layers.";
0233
0234 nextLayerToTry.clear();
0235 for (auto toTry : layerToTry) {
0236
0237 LogDebug("SimpleNavigableLayer") << counter << "] adding layer with pointer: " << (toTry)
0238 << " first detid: " << (toTry)->basicComponents().front()->geographicalId();
0239 if (!collect.insert(toTry).second)
0240 continue;
0241
0242
0243 Lvect&& nextLayers = school->nextLayers(*toTry, fts, timeDirection);
0244 LogDebug("SimpleNavigableLayer") << counter << "] this layer has : " << nextLayers.size() << " next layers.";
0245 nextLayerToTry.insert(nextLayers.begin(), nextLayers.end());
0246 }
0247
0248 layerToTry.swap(nextLayerToTry);
0249 }
0250 if (counter >= 150) {
0251 edm::LogWarning("SimpleNavigableLayer") << "WARNING: compatibleLayers() more than 150 iterations!!! Bailing out..";
0252 counter = -1;
0253 return Lvect();
0254 }
0255
0256 LogDebug("SimpleNavigableLayer") << "Number of compatible layers: " << collect.size();
0257
0258 return Lvect(collect.begin(), collect.end());
0259 }