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