CMS 3D CMS Logo

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