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