CMS 3D CMS Logo

SimpleBarrelNavigableLayer.cc
Go to the documentation of this file.
2 
5 
9 
12 
13 #include <algorithm>
14 #include <map>
15 #include <cmath>
16 
17 using namespace std;
18 
20  const BDLC& outerBLC,
21  const FDLC& outerLeftFL,
22  const FDLC& outerRightFL,
23  const MagneticField* field,
24  float epsilon,
25  bool checkCrossingSide)
26  : SimpleNavigableLayer(field, epsilon, checkCrossingSide),
27  theDetLayer(detLayer),
28  theOuterBarrelLayers(outerBLC),
29  theOuterLeftForwardLayers(outerLeftFL),
30  theOuterRightForwardLayers(outerRightFL)
31 
32 {
33  // put barrel and forward layers together
34  theNegOuterLayers.reserve(outerBLC.size() + outerLeftFL.size());
35  thePosOuterLayers.reserve(outerBLC.size() + outerRightFL.size());
36 
37  for (ConstBDLI bl = outerBLC.begin(); bl != outerBLC.end(); bl++)
38  theNegOuterLayers.push_back(*bl);
39  thePosOuterLayers = theNegOuterLayers; // barrel part the same
40 
41  for (ConstFDLI fl = outerLeftFL.begin(); fl != outerLeftFL.end(); fl++)
42  theNegOuterLayers.push_back(*fl);
43  for (ConstFDLI fl = outerRightFL.begin(); fl != outerRightFL.end(); fl++)
44  thePosOuterLayers.push_back(*fl);
45 
46  // sort the outer layers
47  sort(theNegOuterLayers.begin(), theNegOuterLayers.end(), TkLayerLess());
48  sort(thePosOuterLayers.begin(), thePosOuterLayers.end(), TkLayerLess());
52 }
53 
55  vector<const DetLayer*> result;
56 
57  // the order is the one in which layers
58  // should be checked for a reasonable trajectory
59 
60  if (dir == insideOut) {
61  result = theNegOuterLayers;
62  for (DLC::const_iterator i = thePosOuterLayers.begin(); i != thePosOuterLayers.end(); i++) {
63  // avoid duplication of barrel layers
64  if ((**i).location() == GeomDetEnumerators::endcap)
65  result.push_back(*i);
66  }
67  } else {
68  result = theNegInnerLayers;
69  for (DLC::const_iterator i = thePosInnerLayers.begin(); i != thePosInnerLayers.end(); i++) {
70  // avoid duplication of barrel layers
71  if ((**i).location() == GeomDetEnumerators::endcap)
72  result.push_back(*i);
73  }
74  }
75  return result;
76 }
77 
79  PropagationDirection dir) const {
80  // This method contains the sequence in which the layers are tested.
81  // The iteration stops as soon as a layer contains the propagated state
82  // within epsilon.
83 
84  vector<const DetLayer*> result;
85 
86  FreeTrajectoryState ftsWithoutErrors = (fts.hasError()) ? FreeTrajectoryState(fts.parameters()) : fts;
87 
88  auto const position = fts.position();
89  auto const momentum = fts.momentum();
90 
91  //establish whether the tracks is crossing the tracker from outer layers to inner ones
92  //or from inner to outer.
93  GlobalVector transversePosition(position.x(), position.y(), 0);
94  bool isInOutTrackBarrel = (transversePosition.dot(momentum) > 0);
95 
96  float zpos = position.z();
97  bool isInOutTrackFWD = momentum.z() * zpos > 0;
98 
99  //establish whether inner or outer layers are crossed after propagation, according
100  //to BOTH propagationDirection AND track momentum
101  bool dirOppositeXORisInOutTrackBarrel =
102  (!(dir == oppositeToMomentum) && isInOutTrackBarrel) || ((dir == oppositeToMomentum) && !isInOutTrackBarrel);
103  bool dirOppositeXORisInOutTrackFWD =
104  (!(dir == oppositeToMomentum) && isInOutTrackFWD) || ((dir == oppositeToMomentum) && !isInOutTrackFWD);
105 
106  LogDebug("SimpleBarrelNavigableLayer") << "is alongMomentum? " << (dir == alongMomentum) << endl
107  << "isInOutTrackBarrel: " << isInOutTrackBarrel << endl
108  << "isInOutTrackFWD: " << isInOutTrackFWD << endl
109  << "dirOppositeXORisInOutTrackFWD: " << dirOppositeXORisInOutTrackFWD << endl
110  << "dirOppositeXORisInOutTrackBarrel: " << dirOppositeXORisInOutTrackBarrel
111  << endl;
112 
113  bool signZmomentumXORdir =
114  (((momentum.z() > 0) && !(dir == alongMomentum)) || (!(momentum.z() > 0) && (dir == alongMomentum)));
115 
116  if
117  LIKELY(dirOppositeXORisInOutTrackBarrel && dirOppositeXORisInOutTrackFWD) {
118  if (signZmomentumXORdir) {
119  wellInside(ftsWithoutErrors, dir, theNegOuterLayers, result);
120  } else {
121  wellInside(ftsWithoutErrors, dir, thePosOuterLayers, result);
122  }
123  }
124  else if (!dirOppositeXORisInOutTrackBarrel && !dirOppositeXORisInOutTrackFWD) {
125  if (signZmomentumXORdir) {
126  wellInside(ftsWithoutErrors, dir, thePosInnerLayers, result);
127  } else {
128  wellInside(ftsWithoutErrors, dir, theNegInnerLayers, result);
129  }
130  } else if (!dirOppositeXORisInOutTrackBarrel && dirOppositeXORisInOutTrackFWD) {
131  wellInside(ftsWithoutErrors, dir, theInnerBarrelLayers.begin(), theInnerBarrelLayers.end(), result);
132 
133  if (signZmomentumXORdir) {
134  wellInside(ftsWithoutErrors, dir, theInnerLeftForwardLayers.begin(), theInnerLeftForwardLayers.end(), result);
135  wellInside(ftsWithoutErrors, dir, theOuterLeftForwardLayers.begin(), theOuterLeftForwardLayers.end(), result);
136  } else {
137  wellInside(ftsWithoutErrors, dir, theInnerRightForwardLayers.begin(), theInnerRightForwardLayers.end(), result);
138  wellInside(ftsWithoutErrors, dir, theOuterRightForwardLayers.begin(), theOuterRightForwardLayers.end(), result);
139  }
140  } else {
141  if (signZmomentumXORdir) {
142  wellInside(ftsWithoutErrors, dir, theInnerLeftForwardLayers.begin(), theInnerLeftForwardLayers.end(), result);
143  } else {
144  wellInside(ftsWithoutErrors, dir, theInnerRightForwardLayers.begin(), theInnerRightForwardLayers.end(), result);
145  }
146  wellInside(ftsWithoutErrors, dir, theOuterBarrelLayers.begin(), theOuterBarrelLayers.end(), result);
147  }
148 
149  bool goingIntoTheBarrel =
150  (!isInOutTrackBarrel && dir == alongMomentum) || (isInOutTrackBarrel && dir == oppositeToMomentum);
151 
152  LogDebug("SimpleBarrelNavigableLayer") << "goingIntoTheBarrel: " << goingIntoTheBarrel;
153 
154  if
155  UNLIKELY(theSelfSearch && result.empty()) {
156  if (!goingIntoTheBarrel) {
157  LogDebug("SimpleBarrelNavigableLayer")
158  << " state is not going toward the center of the barrel. not adding self search.";
159  } else {
160  const BarrelDetLayer* bl = reinterpret_cast<const BarrelDetLayer*>(detLayer());
161  unsigned int before = result.size();
162  LogDebug("SimpleBarrelNavigableLayer") << " I am trying to added myself as a next layer.";
163  wellInside(ftsWithoutErrors, dir, bl, result);
164  unsigned int after = result.size();
165  if (before != after)
166  LogDebug("SimpleBarrelNavigableLayer") << " I have added myself as a next layer.";
167  }
168  }
169 
170  return result;
171 }
172 
174  edm::LogError("TkNavigation") << "ERROR: compatibleLayers() method used without all reachableLayers are set";
175  throw DetLayerException("compatibleLayers() method used without all reachableLayers are set");
176  return vector<const DetLayer*>();
177 }
178 
180  cerr << "Warniong: SimpleBarrelNavigableLayer::setDetLayer called." << endl << "This should never happen!" << endl;
181 }
182 
183 void SimpleBarrelNavigableLayer::setInwardLinks(const BDLC& theBarrelv, const FDLC& theForwardv, TkLayerLess sorter) {
184  theInnerBarrelLayers = theBarrelv;
185  // sort the inner layers
186  sort(theInnerBarrelLayers.begin(), theInnerBarrelLayers.end(), sorter);
187 
188  ConstFDLI middle = find_if(
189  theForwardv.begin(), theForwardv.end(), [](const GeometricSearchDet* a) { return a->position().z() >= 0.0; });
190  theInnerLeftForwardLayers = FDLC(theForwardv.begin(), middle);
191  theInnerRightForwardLayers = FDLC(middle, theForwardv.end());
192 
193  // sort the inner layers
194  sort(theInnerLeftForwardLayers.begin(), theInnerLeftForwardLayers.end(), sorter);
195  sort(theInnerRightForwardLayers.begin(), theInnerRightForwardLayers.end(), sorter);
196 
197  // put barrel and forward layers together
198  theNegInnerLayers.reserve(theInnerBarrelLayers.size() + theInnerLeftForwardLayers.size());
199  thePosInnerLayers.reserve(theInnerBarrelLayers.size() + theInnerRightForwardLayers.size());
200 
201  for (ConstBDLI bl = theInnerBarrelLayers.begin(); bl != theInnerBarrelLayers.end(); bl++)
202  theNegInnerLayers.push_back(*bl);
203  thePosInnerLayers = theNegInnerLayers; // barrel part the same
204 
205  for (ConstFDLI fl = theInnerLeftForwardLayers.begin(); fl != theInnerLeftForwardLayers.end(); fl++)
206  theNegInnerLayers.push_back(*fl);
207  for (ConstFDLI fl = theInnerRightForwardLayers.begin(); fl != theInnerRightForwardLayers.end(); fl++)
208  thePosInnerLayers.push_back(*fl);
209 
210  // sort the inner layers
211  sort(theNegInnerLayers.begin(), theNegInnerLayers.end(), sorter);
212  sort(thePosInnerLayers.begin(), thePosInnerLayers.end(), sorter);
213  sort(theInnerBarrelLayers.begin(), theInnerBarrelLayers.end(), sorter);
214  sort(theInnerLeftForwardLayers.begin(), theInnerLeftForwardLayers.end(), sorter);
215  sort(theInnerRightForwardLayers.begin(), theInnerRightForwardLayers.end(), sorter);
216 }
217 
219  const ForwardDetLayer* fadditional = dynamic_cast<const ForwardDetLayer*>(additional);
220  const BarrelDetLayer* badditional = dynamic_cast<const BarrelDetLayer*>(additional);
221  if (badditional) {
222  if (direction == insideOut) {
223  theOuterBarrelLayers.push_back(badditional);
224  theNegOuterLayers.push_back(badditional);
225  thePosOuterLayers.push_back(badditional);
226  return;
227  }
228  theInnerBarrelLayers.push_back(badditional);
229  theNegInnerLayers.push_back(badditional);
230  thePosInnerLayers.push_back(badditional);
231  return;
232  } else if (fadditional) {
233  double zpos = fadditional->position().z();
234  if (direction == insideOut) {
235  if (zpos > 0) {
236  theOuterRightForwardLayers.push_back(fadditional);
237  thePosOuterLayers.push_back(fadditional);
238  return;
239  }
240  theOuterLeftForwardLayers.push_back(fadditional);
241  theNegOuterLayers.push_back(fadditional);
242  return;
243  }
244  if (zpos > 0) {
245  theInnerRightForwardLayers.push_back(fadditional);
246  thePosInnerLayers.push_back(fadditional);
247  return;
248  }
249  theInnerLeftForwardLayers.push_back(fadditional);
250  theNegInnerLayers.push_back(fadditional);
251  return;
252  }
253  edm::LogError("TkNavigation") << "trying to add neither a ForwardDetLayer nor a BarrelDetLayer";
254  return;
255 }
#define LogDebug(id)
std::vector< const DetLayer * > nextLayers(NavigationDirection direction) const override
Common base class.
void setInwardLinks(const BDLC &theBarrelv, const FDLC &theForwardv, TkLayerLess sorter=TkLayerLess(outsideIn)) override
SimpleBarrelNavigableLayer(BarrelDetLayer const *detLayer, const BDLC &outerBLC, const FDLC &outerLeftFL, const FDLC &outerRightFL, const MagneticField *field, float epsilon, bool checkCrossingSide=true)
const GlobalTrajectoryParameters & parameters() const
std::vector< const DetLayer * > compatibleLayers(NavigationDirection direction) const override
#define LIKELY(x)
Definition: Likely.h:20
PropagationDirection
std::vector< const ForwardDetLayer * > FDLC
T z() const
Definition: PV3DBase.h:61
FDLC::const_iterator ConstFDLI
const DetLayer * detLayer() const override
GlobalVector momentum() const
GlobalPoint position() const
virtual const Surface::PositionType & position() const
Returns position of the surface.
bool wellInside(const FreeTrajectoryState &fts, PropagationDirection dir, const BarrelDetLayer *bl, DLC &result) const
double a
Definition: hdecay.h:119
static int position[264][3]
Definition: ReadPGInfo.cc:289
void setAdditionalLink(const DetLayer *, NavigationDirection direction=insideOut) override
#define UNLIKELY(x)
Definition: Likely.h:21
void setDetLayer(const DetLayer *dl) override
BDLC::const_iterator ConstBDLI
std::vector< const BarrelDetLayer * > BDLC