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 }
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:63
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:214
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
L1TkHTMissProducer_cfi.deltaZ
deltaZ
Definition: L1TkHTMissProducer_cfi.py:13
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