CMS 3D CMS Logo

SimpleNavigableLayer.cc
Go to the documentation of this file.
1 #include "SimpleNavigableLayer.h"
3 
5 
10 
11 #include <set>
12 
13 using namespace std;
14 
16  PropagationDirection dir) const {
17  //self propagating. step one: go close to the center
18  GlobalPoint initialPoint = fts.position();
20  GlobalPoint center(0, 0, 0);
21  TSOS propState = middle.extrapolate(fts, center, propagator(dir));
22  if (!propState.isValid())
23  return TrajectoryStateOnSurface();
24 
25  FreeTrajectoryState const& dest = *propState.freeState();
26  GlobalPoint middlePoint = dest.position();
27  const float toCloseToEachOther2 = 1e-4 * 1e-4;
28  if
29  UNLIKELY((middlePoint - initialPoint).mag2() < toCloseToEachOther2) {
30  LogDebug("SimpleNavigableLayer")
31  << "initial state and PCA are identical. Things are bound to fail. Do not add the link.";
32  return TrajectoryStateOnSurface();
33  }
34 
35  /*
36  std::string dirS;
37  if (dir==alongMomentum) dirS = "alongMomentum";
38  else if (dir==oppositeToMomentum) dirS = "oppositeToMomentum";
39  else dirS = "anyDirection";
40  */
41 
42  LogDebug("SimpleNavigableLayer") << "self propagating(" << dir << ") from:\n"
43  << fts << "\n"
44  << dest << "\n"
45  << " and the direction is: " << dir;
46 
47  //second propagation to go on the other side of the barrel
48  //propState = propagator(dir).propagate( dest, detLayer()->specificSurface());
49  propState = propagator(dir).propagate(dest, detLayer()->surface());
50  if (!propState.isValid())
51  return TrajectoryStateOnSurface();
52 
53  const FreeTrajectoryState& dest2 = *propState.freeState();
54  GlobalPoint finalPoint = dest2.position();
55  LogDebug("SimpleNavigableLayer") << "second propagation(" << dir << ") to: \n" << dest2;
56  double finalDot = (middlePoint - initialPoint).basicVector().dot((finalPoint - middlePoint).basicVector());
57  if
58  UNLIKELY(finalDot < 0) { // check that before and after are in different side.
59  LogDebug("SimpleNavigableLayer") << "switch side back: ABORT.";
60  return TrajectoryStateOnSurface();
61  }
62  return propState;
63 }
64 
67  const BarrelDetLayer* bl,
68  DLC& result) const {
69  TSOS propState = (bl == detLayer()) ? crossingState(fts, dir) : propagator(dir).propagate(fts, bl->specificSurface());
70 
71  if (!propState.isValid())
72  return false;
73 
74  //if requested check that the layer is crossed on the right side
75  if (theCheckCrossingSide) {
76  bool backTobackTransverse =
77  (fts.position().x() * propState.globalPosition().x() + fts.position().y() * propState.globalPosition().y()) < 0;
78  bool backToback = propState.globalPosition().basicVector().dot(fts.position().basicVector()) < 0;
79 
80  if (backTobackTransverse || backToback) {
81  LogTrace("TkNavigation") << "Crossing over prevented!\nStaring from (x,y,z,r) (" << fts.position().x() << ","
82  << fts.position().y() << "," << fts.position().z() << "," << fts.position().perp()
83  << ") going to TSOS (x,y,z,r)" << propState.globalPosition().x() << ","
84  << propState.globalPosition().y() << "," << propState.globalPosition().z() << ","
85  << propState.globalPosition().perp() << ")";
86  return false;
87 
88  /*
89  //we have to check the crossing side only if we are going to something smaller
90  if (fts.position().perp()>bl->specificSurface().radius() ||
91  fabs(fts.position().z())>bl->surface().bounds().length()/2. ){
92  if (propState.globalPosition().basicVector().dot(fts.position().basicVector())<0){
93  LogTrace("TkNavigation") << "Crossing over prevented!\nStaring from (x,y,z,r) ("
94  << fts.position().x()<<","<< fts.position().y()<<","<< fts.position().z()<<","<<fts.position().perp()
95  << ") going to TSOS (x,y,z,r)"
96  << propState.globalPosition().x()<<","<< propState.globalPosition().y()<<","<< propState.globalPosition().z()<<","<<propState.globalPosition().perp()<<")";;
97  return false;
98  }
99  }
100  */
101  }
102  }
103 
104  const Bounds& bounds(bl->specificSurface().bounds());
105  float length = bounds.length() * 0.5f;
106 
107  // take into account the thickness of the layer
108  float deltaZ =
109  0.5f * bounds.thickness() * std::abs(propState.globalDirection().z()) / propState.globalDirection().perp();
110 
111  // take into account the error on the predicted state
112  const float nSigma = theEpsilon; // temporary reuse of epsilon
113  if (propState.hasError()) {
114  deltaZ += nSigma * sqrt(fts.cartesianError().position().czz());
115  }
116 
117  // cout << "SimpleNavigableLayer BarrelDetLayer deltaZ = " << deltaZ << endl;
118 
119  float zpos = propState.globalPosition().z();
120  if (std::abs(zpos) < length + deltaZ)
121  result.push_back(bl);
122 
123  return std::abs(zpos) < length - deltaZ;
124 }
125 
128  const ForwardDetLayer* fl,
129  DLC& result) const {
130  TSOS propState = propagator(dir).propagate(fts, fl->specificSurface());
131  if (!propState.isValid())
132  return false;
133 
134  if (fl == detLayer()) {
135  LogDebug("SimpleNavigableLayer") << "self propagating from:\n" << fts << "\n to \n" << *propState.freeState();
136  }
137 
138  //if requested avoids crossing over the tracker
139  if (theCheckCrossingSide) {
140  bool backTobackTransverse =
141  (fts.position().x() * propState.globalPosition().x() + fts.position().y() * propState.globalPosition().y()) < 0;
142  bool backToback = propState.globalPosition().basicVector().dot(fts.position().basicVector()) < 0;
143 
144  if (backTobackTransverse || backToback) {
145  LogTrace("TkNavigation") << "Crossing over prevented!\nStaring from (x,y,z,r) (" << fts.position().x() << ","
146  << fts.position().y() << "," << fts.position().z() << "," << fts.position().perp()
147  << ") going to TSOS (x,y,z,r)" << propState.globalPosition().x() << ","
148  << propState.globalPosition().y() << "," << propState.globalPosition().z() << ","
149  << propState.globalPosition().perp() << ")";
150  ;
151  return false;
152 
153  // if (fts.position().z()*propState.globalPosition().z() < 0) return false;
154  }
155  }
156 
157  float rpos = propState.globalPosition().perp();
158  float innerR = fl->specificSurface().innerRadius();
159  float outerR = fl->specificSurface().outerRadius();
160 
161  // take into account the thickness of the layer
162  float deltaR = 0.5f * fl->surface().bounds().thickness() * propState.localDirection().perp() /
163  std::abs(propState.localDirection().z());
164 
165  // take into account the error on the predicted state
166  const float nSigma = theEpsilon;
167  if (propState.hasError()) {
168  LocalError err = propState.localError().positionError();
169  // ignore correlation for the moment...
170  deltaR += nSigma * sqrt(err.xx() + err.yy());
171  }
172 
173  // cout << "SimpleNavigableLayer BarrelDetLayer deltaR = " << deltaR << endl;
174 
175  if (innerR - deltaR < rpos && rpos < outerR + deltaR)
176  result.push_back(fl);
177  return (innerR + deltaR < rpos && rpos < outerR - deltaR);
178 }
179 
182  const DLC& layers,
183  DLC& result) const {
184  for (auto l : layers) {
185  if (l->isBarrel()) {
186  const BarrelDetLayer* bl = reinterpret_cast<const BarrelDetLayer*>(l);
187  if (wellInside(fts, dir, bl, result))
188  return true;
189  } else {
190  const ForwardDetLayer* fl = reinterpret_cast<const ForwardDetLayer*>(l);
191  if (wellInside(fts, dir, fl, result))
192  return true;
193  }
194  }
195  return false;
196 }
197 
200  for (ConstBDLI i = begin; i < end; i++) {
201  if (wellInside(fts, dir, *i, result))
202  return true;
203  }
204  return false;
205 }
206 
209  for (ConstFDLI i = begin; i < end; i++) {
210  if (wellInside(fts, dir, *i, result))
211  return true;
212  }
213  return false;
214 }
215 
216 std::vector<const DetLayer*> SimpleNavigableLayer::compatibleLayers(const FreeTrajectoryState& fts,
217  PropagationDirection timeDirection,
218  int& counter) const {
219  typedef std::vector<const DetLayer*> Lvect;
220  typedef std::set<const DetLayer*> Lset;
221 
222  //initiate the first iteration
223  const Lvect& someLayers = nextLayers(fts, timeDirection);
224  if (someLayers.empty()) {
225  LogDebug("SimpleNavigableLayer") << "Number of compatible layers: " << 0;
226  return someLayers;
227  }
228 
229  Lset collect; //a container of unique instances. to avoid duplicates
230  Lset layerToTry, nextLayerToTry; //set used for iterations
231  layerToTry.insert(someLayers.begin(), someLayers.end());
232 
233  while (!layerToTry.empty() && (counter++) <= 150) {
234  LogDebug("SimpleNavigableLayer") << counter << "] going to check on : " << layerToTry.size() << " next layers.";
235  //clear this set first, it will be swaped with layerToTry
236  nextLayerToTry.clear();
237  for (auto toTry : layerToTry) {
238  //add the layer you tried.
239  LogDebug("SimpleNavigableLayer") << counter << "] adding layer with pointer: " << (toTry)
240  << " first detid: " << (toTry)->basicComponents().front()->geographicalId();
241  if (!collect.insert(toTry).second)
242  continue;
243 
244  //find the next layers from it
245  Lvect&& nextLayers = school->nextLayers(*toTry, fts, timeDirection);
246  LogDebug("SimpleNavigableLayer") << counter << "] this layer has : " << nextLayers.size() << " next layers.";
247  nextLayerToTry.insert(nextLayers.begin(), nextLayers.end());
248  } // layerToTry
249  //swap now that you where to go next.
250  layerToTry.swap(nextLayerToTry);
251  }
252  if (counter >= 150) {
253  edm::LogWarning("SimpleNavigableLayer") << "WARNING: compatibleLayers() more than 150 iterations!!! Bailing out..";
254  counter = -1;
255  return Lvect();
256  }
257 
258  LogDebug("SimpleNavigableLayer") << "Number of compatible layers: " << collect.size();
259 
260  return Lvect(collect.begin(), collect.end());
261 }
Likely.h
TrajectoryStateOnSurface::globalDirection
GlobalVector globalDirection() const
Definition: TrajectoryStateOnSurface.h:67
counter
Definition: counter.py:1
mps_fire.i
i
Definition: mps_fire.py:428
SimpleNavigableLayer::DLC
std::vector< const DetLayer * > DLC
Definition: SimpleNavigableLayer.h:22
MessageLogger.h
SimpleNavigableLayer.h
LocalTrajectoryError::positionError
LocalError positionError() const
Definition: LocalTrajectoryError.h:81
PV3DBase::x
T x() const
Definition: PV3DBase.h:59
BoundDisk.h
ForwardDetLayer::surface
const BoundSurface & surface() const final
The surface of the GeometricSearchDet.
Definition: ForwardDetLayer.h:29
TrajectoryStateOnSurface::globalPosition
GlobalPoint globalPosition() const
Definition: TrajectoryStateOnSurface.h:65
Bounds
Definition: Bounds.h:18
BoundCylinder.h
TransverseImpactPointExtrapolator
Definition: TransverseImpactPointExtrapolator.h:26
FreeTrajectoryState::position
GlobalPoint position() const
Definition: FreeTrajectoryState.h:67
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
Bounds::length
virtual float length() const =0
PV3DBase::z
T z() const
Definition: PV3DBase.h:61
SimpleNavigableLayer::wellInside
bool wellInside(const FreeTrajectoryState &fts, PropagationDirection dir, const BarrelDetLayer *bl, DLC &result) const
Definition: SimpleNavigableLayer.cc:65
UNLIKELY
#define UNLIKELY(x)
Definition: Likely.h:21
TrajectoryStateOnSurface
Definition: TrajectoryStateOnSurface.h:16
TrajectoryStateOnSurface::freeState
FreeTrajectoryState const * freeState(bool withErrors=true) const
Definition: TrajectoryStateOnSurface.h:58
FreeTrajectoryState::cartesianError
CartesianTrajectoryError cartesianError() const
Definition: FreeTrajectoryState.h:81
TrackCandidateProducer_cfi.propagator
propagator
Definition: TrackCandidateProducer_cfi.py:17
TrajectoryStateOnSurface::localDirection
LocalVector localDirection() const
Definition: TrajectoryStateOnSurface.h:76
TrajectoryStateOnSurface::hasError
bool hasError() const
Definition: TrajectoryStateOnSurface.h:56
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
Surface::bounds
const Bounds & bounds() const
Definition: Surface.h:87
mps_fire.end
end
Definition: mps_fire.py:242
Basic3DVector::dot
T dot(const Basic3DVector &rh) const
Scalar product, or "dot" product, with a vector of same type.
Definition: extBasic3DVector.h:189
Point3DBase< float, GlobalTag >
PbPb_ZMuSkimMuonDPG_cff.deltaR
deltaR
Definition: PbPb_ZMuSkimMuonDPG_cff.py:63
SimpleNavigableLayer::crossingState
TSOS crossingState(const FreeTrajectoryState &fts, PropagationDirection dir) const
Definition: SimpleNavigableLayer.cc:15
Bounds::thickness
virtual float thickness() const =0
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
LocalError
Definition: LocalError.h:12
SimpleNavigableLayer::compatibleLayers
std::vector< const DetLayer * > compatibleLayers(const FreeTrajectoryState &fts, PropagationDirection timeDirection, int &counter) const final
Definition: SimpleNavigableLayer.cc:216
PV3DBase::y
T y() const
Definition: PV3DBase.h:60
mag2
T mag2() const
The vector magnitude squared. Equivalent to vec.dot(vec)
Definition: Basic3DVectorLD.h:124
submitPVResolutionJobs.err
err
Definition: submitPVResolutionJobs.py:85
SimpleNavigableLayer::ConstFDLI
FDLC::const_iterator ConstFDLI
Definition: SimpleNavigableLayer.h:52
BarrelDetLayer
Definition: BarrelDetLayer.h:22
cmsLHEtoEOSManager.l
l
Definition: cmsLHEtoEOSManager.py:204
PV3DBase::basicVector
const BasicVectorType & basicVector() const
Definition: PV3DBase.h:53
std
Definition: JetResolutionObject.h:76
ForwardDetLayer
Definition: ForwardDetLayer.h:22
FreeTrajectoryState
Definition: FreeTrajectoryState.h:27
PropagationDirection
PropagationDirection
Definition: PropagationDirection.h:4
TransverseImpactPointExtrapolator.h
TransverseImpactPointExtrapolator::extrapolate
TrajectoryStateOnSurface extrapolate(const FreeTrajectoryState &fts, const GlobalPoint &vtx) const
extrapolation with default (=geometrical) propagator
Definition: TransverseImpactPointExtrapolator.cc:23
GlobalErrorBase::czz
T czz() const
Definition: GlobalErrorBase.h:107
mps_fire.result
result
Definition: mps_fire.py:311
SimpleNavigableLayer::ConstBDLI
BDLC::const_iterator ConstBDLI
Definition: SimpleNavigableLayer.h:51
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
LogTrace
#define LogTrace(id)
Definition: MessageLogger.h:234
NavigationSchool.h
TrajectoryStateOnSurface::localError
const LocalTrajectoryError & localError() const
Definition: TrajectoryStateOnSurface.h:77
BarrelDetLayer::specificSurface
virtual const BoundCylinder & specificSurface() const final
Extension of the interface.
Definition: BarrelDetLayer.h:39
PV3DBase::perp
T perp() const
Definition: PV3DBase.h:69
CartesianTrajectoryError::position
const GlobalError position() const
Position error submatrix.
Definition: CartesianTrajectoryError.h:41
HLTSiStripMonitoring_cff.nSigma
nSigma
Definition: HLTSiStripMonitoring_cff.py:151
hgcalTopologyTester_cfi.layers
layers
Definition: hgcalTopologyTester_cfi.py:8
TrajectoryStateOnSurface::isValid
bool isValid() const
Definition: TrajectoryStateOnSurface.h:54
mps_fire.dest
dest
Definition: mps_fire.py:179
ForwardDetLayer::specificSurface
virtual const BoundDisk & specificSurface() const final
Definition: ForwardDetLayer.h:39
DeadROC_duringRun.dir
dir
Definition: DeadROC_duringRun.py:23
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37