CMS 3D CMS Logo

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