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 
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  areAllReachableLayersSet(false),
32  theDetLayer( detLayer),
33  theOuterBarrelLayers( outerBLC),
34  theOuterLeftForwardLayers( outerLeftFL),
35  theOuterRightForwardLayers( outerRightFL)
36 
37 {
38  // put barrel and forward layers together
39  theNegOuterLayers.reserve( outerBLC.size() + outerLeftFL.size());
40  thePosOuterLayers.reserve( outerBLC.size() + outerRightFL.size());
41 
42  for (ConstBDLI bl=outerBLC.begin(); bl!=outerBLC.end(); bl++)
43  theNegOuterLayers.push_back( *bl);
44  thePosOuterLayers = theNegOuterLayers; // barrel part the same
45 
46  for (ConstFDLI fl=outerLeftFL.begin(); fl!=outerLeftFL.end(); fl++)
47  theNegOuterLayers.push_back( *fl);
48  for (ConstFDLI fl=outerRightFL.begin(); fl!=outerRightFL.end(); fl++)
49  thePosOuterLayers.push_back( *fl);
50 
51  // sort the outer layers
57 }
58 
59 
62  const BDLC& outerBLC,
63  const BDLC& innerBLC,
64  const BDLC& allOuterBLC,
65  const BDLC& allInnerBLC,
66  const FDLC& outerLeftFL,
67  const FDLC& outerRightFL,
68  const FDLC& allOuterLeftFL,
69  const FDLC& allOuterRightFL,
70  const FDLC& innerLeftFL,
71  const FDLC& innerRightFL,
72  const FDLC& allInnerLeftFL,
73  const FDLC& allInnerRightFL,
74  const MagneticField* field,
75  float epsilon,
76  bool checkCrossingSide) :
77  SimpleNavigableLayer(field,epsilon,checkCrossingSide),
78  areAllReachableLayersSet(true),
79  theDetLayer( detLayer),
80  theOuterBarrelLayers( outerBLC),
81  theInnerBarrelLayers( innerBLC),
82  theAllOuterBarrelLayers( allOuterBLC),
83  theAllInnerBarrelLayers( allInnerBLC),
84  theOuterLeftForwardLayers( outerLeftFL),
85  theOuterRightForwardLayers( outerRightFL),
86  theAllOuterLeftForwardLayers( allOuterLeftFL),
87  theAllOuterRightForwardLayers( allOuterRightFL),
88  theInnerLeftForwardLayers( innerLeftFL),
89  theInnerRightForwardLayers( innerRightFL),
90  theAllInnerLeftForwardLayers( allInnerLeftFL),
91  theAllInnerRightForwardLayers( allInnerRightFL)
92 {
93  // put barrel and forward layers together
94  theNegOuterLayers.reserve( outerBLC.size() + outerLeftFL.size());
95  thePosOuterLayers.reserve( outerBLC.size() + outerRightFL.size());
96  theNegInnerLayers.reserve( innerBLC.size() + innerLeftFL.size());
97  thePosInnerLayers.reserve( innerBLC.size() + innerRightFL.size());
98 
99 
100  for (ConstBDLI bl=outerBLC.begin(); bl!=outerBLC.end(); bl++)
101  theNegOuterLayers.push_back( *bl);
102  thePosOuterLayers = theNegOuterLayers; // barrel part the same
103 
104  for (ConstFDLI fl=outerLeftFL.begin(); fl!=outerLeftFL.end(); fl++)
105  theNegOuterLayers.push_back( *fl);
106  for (ConstFDLI fl=outerRightFL.begin(); fl!=outerRightFL.end(); fl++)
107  thePosOuterLayers.push_back( *fl);
108 
109  for (ConstBDLI bl=innerBLC.begin(); bl!=innerBLC.end(); bl++)
110  theNegInnerLayers.push_back( *bl);
111  thePosInnerLayers = theNegInnerLayers; // barrel part the same
112 
113  for (ConstFDLI fl=innerLeftFL.begin(); fl!=innerLeftFL.end(); fl++)
114  theNegInnerLayers.push_back( *fl);
115  for (ConstFDLI fl=innerRightFL.begin(); fl!=innerRightFL.end(); fl++)
116  thePosInnerLayers.push_back( *fl);
117 
118  // sort the outer layers
129 
130 }
131 
132 
133 vector<const DetLayer*>
135 {
136  vector<const DetLayer*> result;
137 
138  // the order is the one in which layers
139  // should be checked for a reasonable trajectory
140 
141  if ( dir == insideOut) {
142  result = theNegOuterLayers;
143  for ( DLC::const_iterator i=thePosOuterLayers.begin();
144  i!=thePosOuterLayers.end(); i++) {
145  // avoid duplication of barrel layers
146  if ((**i).location() == GeomDetEnumerators::endcap) result.push_back(*i);
147  }
148  }
149  else {
150  result = theNegInnerLayers;
151  for ( DLC::const_iterator i=thePosInnerLayers.begin();
152  i!=thePosInnerLayers.end(); i++) {
153  // avoid duplication of barrel layers
154  if ((**i).location() == GeomDetEnumerators::endcap) result.push_back(*i);
155  }
156  }
157  return result;
158 }
159 
160 vector<const DetLayer*>
163 {
164  // This method contains the sequence in which the layers are tested.
165  // The iteration stops as soon as a layer contains the propagated state
166  // within epsilon.
167 
168  vector<const DetLayer*> result;
169 
170  FreeTrajectoryState ftsWithoutErrors = (fts.hasError()) ?
172  fts;
173 
174  //establish whether the tracks is crossing the tracker from outer layers to inner ones
175  //or from inner to outer.
176  GlobalVector transversePosition(fts.position().x(), fts.position().y(), 0);
177  //GlobalVector transverseMomentum(fts.momentum().x(), fts.momentum().y(), 0);
178  //bool isInOutTrack = (fts.position().basicVector().dot(fts.momentum().basicVector())>0) ? 1 : 0;
179  bool isInOutTrackBarrel = (transversePosition.dot(fts.momentum())>0) ? 1 : 0;
180  //cout << "dot: " << transversePosition.dot(fts.momentum()) << endl;
181 
182  float zpos = fts.position().z();
183  bool isInOutTrackFWD = fts.momentum().z()*zpos>0;
184 
185 
186  //establish whether inner or outer layers are crossed after propagation, according
187  //to BOTH propagationDirection AND track momentum
188  bool dirOppositeXORisInOutTrackBarrel = ( !(dir == oppositeToMomentum) && isInOutTrackBarrel) || ((dir == oppositeToMomentum) && !isInOutTrackBarrel);
189  bool dirOppositeXORisInOutTrackFWD = ( !(dir == oppositeToMomentum) && isInOutTrackFWD) || ((dir == oppositeToMomentum) && !isInOutTrackFWD);
190 
191  LogDebug("SimpleBarrelNavigableLayer") << "is alongMomentum? " << (dir == alongMomentum) << endl
192  << "isInOutTrackBarrel: " << isInOutTrackBarrel << endl
193  << "isInOutTrackFWD: " << isInOutTrackFWD << endl
194  << "dirOppositeXORisInOutTrackFWD: " << dirOppositeXORisInOutTrackFWD << endl
195  << "dirOppositeXORisInOutTrackBarrel: "<< dirOppositeXORisInOutTrackBarrel << endl;
196 
197  bool signZmomentumXORdir = (( (fts.momentum().z() > 0) && !(dir == alongMomentum) ) ||
198  (!(fts.momentum().z() > 0) && (dir == alongMomentum) ) );
199 
200 
201  if ( dirOppositeXORisInOutTrackBarrel && dirOppositeXORisInOutTrackFWD) {
202 
203  if ( signZmomentumXORdir ) {
204  wellInside( ftsWithoutErrors, dir, theNegOuterLayers, result);
205  }
206  else {
207  wellInside( ftsWithoutErrors, dir, thePosOuterLayers, result);
208  }
209  } else if (!dirOppositeXORisInOutTrackBarrel && !dirOppositeXORisInOutTrackFWD){
210  if ( signZmomentumXORdir ) {
211  wellInside( ftsWithoutErrors, dir, thePosInnerLayers, result);
212  }
213  else {
214  wellInside( ftsWithoutErrors, dir, theNegInnerLayers, result);
215  }
216  } else if (!dirOppositeXORisInOutTrackBarrel && dirOppositeXORisInOutTrackFWD){
217  wellInside(ftsWithoutErrors, dir, theInnerBarrelLayers.begin(), theInnerBarrelLayers.end(), result);
218 
219  if (signZmomentumXORdir){
220  wellInside(ftsWithoutErrors, dir, theInnerLeftForwardLayers.begin(), theInnerLeftForwardLayers.end(), result);
221  wellInside(ftsWithoutErrors, dir, theOuterLeftForwardLayers.begin(), theOuterLeftForwardLayers.end(), result);
222  } else {
223  wellInside(ftsWithoutErrors, dir, theInnerRightForwardLayers.begin(), theInnerRightForwardLayers.end(), result);
224  wellInside(ftsWithoutErrors, dir, theOuterRightForwardLayers.begin(), theOuterRightForwardLayers.end(), result);
225  }
226  } else {
227  if (signZmomentumXORdir){
228  wellInside(ftsWithoutErrors, dir, theInnerLeftForwardLayers.begin(), theInnerLeftForwardLayers.end(), result);
229  } else {
230  wellInside(ftsWithoutErrors, dir, theInnerRightForwardLayers.begin(), theInnerRightForwardLayers.end(), result);
231  }
232  wellInside(ftsWithoutErrors, dir, theOuterBarrelLayers.begin(), theOuterBarrelLayers.end(), result);
233  }
234 
235  bool goingIntoTheBarrel = (!isInOutTrackBarrel && dir==alongMomentum) || (isInOutTrackBarrel && dir==oppositeToMomentum) ;
236 
237  LogDebug("SimpleBarrelNavigableLayer") << "goingIntoTheBarrel: " << goingIntoTheBarrel;
238 
239 
240  if (theSelfSearch && result.size()==0){
241  if (!goingIntoTheBarrel){ LogDebug("SimpleBarrelNavigableLayer")<<" state is not going toward the center of the barrel. not adding self search.";}
242  else{
243  const BarrelDetLayer * bl = dynamic_cast<const BarrelDetLayer *>(detLayer()); unsigned int before=result.size();
244  LogDebug("SimpleBarrelNavigableLayer")<<" I am trying to added myself as a next layer.";
245  wellInside(ftsWithoutErrors, dir, bl, result);
246  unsigned int after=result.size();
247  if (before!=after)
248  LogDebug("SimpleBarrelNavigableLayer")<<" I have added myself as a next layer.";
249  }
250  }
251 
252  return result;
253 }
254 
255 
256 vector<const DetLayer*>
258 {
260  edm::LogError("TkNavigation") << "ERROR: compatibleLayers() method used without all reachableLayers are set" ;
261  throw DetLayerException("compatibleLayers() method used without all reachableLayers are set");
262  }
263 
264  vector<const DetLayer*> result;
265  if ( dir == insideOut) {
266  for ( BDLC::const_iterator i=theAllOuterBarrelLayers.begin();
267  i!=theAllOuterBarrelLayers.end(); i++) {
268  result.push_back(*i);
269  }
270 // result = theAllOuterBarrelLayers;
271  for ( FDLC::const_iterator i=theAllOuterLeftForwardLayers.begin();
272  i!=theAllOuterLeftForwardLayers.end(); i++) {
273  // avoid duplication of barrel layers
274  result.push_back(*i);
275  }
276  for ( FDLC::const_iterator i=theAllOuterRightForwardLayers.begin();
277  i!=theAllOuterRightForwardLayers.end(); i++) {
278  // avoid duplication of barrel layers
279  result.push_back(*i);
280  }
281  }
282  else {
283  for ( BDLC::const_iterator i=theAllInnerBarrelLayers.begin();
284  i!=theAllInnerBarrelLayers.end(); i++) {
285  result.push_back(*i);
286  }
287  for ( FDLC::const_iterator i=theAllInnerLeftForwardLayers.begin();
288  i!=theAllInnerLeftForwardLayers.end(); i++) {
289  // avoid duplication of barrel layers
290  result.push_back(*i);
291  }
292  for ( FDLC::const_iterator i=theAllInnerRightForwardLayers.begin();
293  i!=theAllInnerRightForwardLayers.end(); i++) {
294  // avoid duplication of barrel layers
295  result.push_back(*i);
296  }
297 
298  }
299 
300  return result;
301 }
302 
303 vector<const DetLayer*>
306 {
308  int counter = 0;
309  return SimpleNavigableLayer::compatibleLayers(fts,dir,counter);
310  // edm::LogError("TkNavigation") << "ERROR: compatibleLayers() method used without all reachableLayers are set" ;
311  // throw DetLayerException("compatibleLayers() method used without all reachableLayers are set");
312  }
313 
314  vector<const DetLayer*> result;
315  FreeTrajectoryState ftsWithoutErrors = (fts.hasError()) ?
316  FreeTrajectoryState( fts.parameters()) : fts;
317 
318  //establish whether the tracks is crossing the tracker from outer layers to inner ones
319  //or from inner to outer.
320  GlobalVector transversePosition(fts.position().x(), fts.position().y(), 0);
321  //GlobalVector transverseMomentum(fts.momentum().x(), fts.momentum().y(), 0);
322  //bool isInOutTrack = (fts.position().basicVector().dot(fts.momentum().basicVector())>0) ? 1 : 0;
323  bool isInOutTrack = (transversePosition.dot(fts.momentum())>0) ? 1 : 0;
324  //establish whether inner or outer layers are crossed after propagation, according
325  //to BOTH propagationDirection AND track momentum
326  bool dirOppositeXORisInOutTrack = ( !(dir == oppositeToMomentum) && isInOutTrack) || ((dir == oppositeToMomentum) && !isInOutTrack);
327 
328  vector<const DetLayer*> temp = dirOppositeXORisInOutTrack ? compatibleLayers(insideOut) : compatibleLayers(outsideIn);
329  wellInside( ftsWithoutErrors, dir, temp, result);
330 
331  return result;
332 
333 }
334 
335 
337 
339  cerr << "Warniong: SimpleBarrelNavigableLayer::setDetLayer called."
340  << endl << "This should never happen!" << endl;
341 }
342 
344  const FDLC& theForwardv,
346 {
347  theInnerBarrelLayers=theBarrelv;
348  // sort the inner layers
350 
351 
352  ConstFDLI middle = find_if( theForwardv.begin(),theForwardv.end(),
353  not1(DetBelowZ(0)));
354  theInnerLeftForwardLayers=FDLC(theForwardv.begin(),middle);
355  theInnerRightForwardLayers=FDLC(middle,theForwardv.end());
356 
357  // sort the inner layers
358  sort(theInnerLeftForwardLayers.begin(), theInnerLeftForwardLayers.end(),sorter);
359  sort(theInnerRightForwardLayers.begin(), theInnerRightForwardLayers.end(),sorter);
360 
361 
362 
363  // put barrel and forward layers together
364  theNegInnerLayers.reserve( theInnerBarrelLayers.size() + theInnerLeftForwardLayers.size());
365  thePosInnerLayers.reserve( theInnerBarrelLayers.size() + theInnerRightForwardLayers.size());
366 
367  for (ConstBDLI bl=theInnerBarrelLayers.begin(); bl!=theInnerBarrelLayers.end(); bl++)
368  theNegInnerLayers.push_back( *bl);
369  thePosInnerLayers = theNegInnerLayers; // barrel part the same
370 
371  for (ConstFDLI fl=theInnerLeftForwardLayers.begin(); fl!=theInnerLeftForwardLayers.end(); fl++)
372  theNegInnerLayers.push_back( *fl);
373  for (ConstFDLI fl=theInnerRightForwardLayers.begin(); fl!=theInnerRightForwardLayers.end(); fl++)
374  thePosInnerLayers.push_back( *fl);
375 
376  // sort the inner layers
380  sort(theInnerLeftForwardLayers.begin(), theInnerLeftForwardLayers.end(),sorter);
381  sort(theInnerRightForwardLayers.begin(), theInnerRightForwardLayers.end(),sorter);
382 
383 }
384 
386  ForwardDetLayer* fadditional = dynamic_cast<ForwardDetLayer*>(additional);
387  BarrelDetLayer* badditional = dynamic_cast<BarrelDetLayer*>(additional);
388  if (badditional){
389  if (direction==insideOut){
390  theAllOuterBarrelLayers.push_back(badditional);
391  theOuterBarrelLayers.push_back(badditional);
392  theNegOuterLayers.push_back(badditional);
393  thePosOuterLayers.push_back(badditional);
394  return;
395  }
396  theAllInnerBarrelLayers.push_back(badditional);
397  theInnerBarrelLayers.push_back(badditional);
398  theNegInnerLayers.push_back(badditional);
399  thePosInnerLayers.push_back(badditional);
400  return;
401  } else if (fadditional){
402  double zpos = fadditional->position().z();
403  if (direction==insideOut){
404  if (zpos>0){
405  theOuterRightForwardLayers.push_back(fadditional);
406  theAllOuterRightForwardLayers.push_back(fadditional);
407  thePosOuterLayers.push_back(fadditional);
408  return;
409  }
410  theOuterLeftForwardLayers.push_back(fadditional);
411  theAllOuterLeftForwardLayers.push_back(fadditional);
412  theNegOuterLayers.push_back(fadditional);
413  return;
414  }
415  if (zpos>0){
416  theInnerRightForwardLayers.push_back(fadditional);
417  theAllInnerRightForwardLayers.push_back(fadditional);
418  thePosInnerLayers.push_back(fadditional);
419  return;
420  }
421  theInnerLeftForwardLayers.push_back(fadditional);
422  theAllInnerLeftForwardLayers.push_back(fadditional);
423  theNegInnerLayers.push_back(fadditional);
424  return;
425  }
426  edm::LogError("TkNavigation") << "trying to add neither a ForwardDetLayer nor a BarrelDetLayer";
427  return;
428 }
#define LogDebug(id)
Common base class.
int i
Definition: DBlmapReader.cc:9
const GlobalTrajectoryParameters & parameters() const
std::vector< BarrelDetLayer * > BDLC
T y() const
Definition: PV3DBase.h:62
PropagationDirection
SimpleBarrelNavigableLayer(BarrelDetLayer *detLayer, const BDLC &outerBLC, const FDLC &outerLeftFL, const FDLC &outerRightFL, const MagneticField *field, float epsilon, bool checkCrossingSide=true)
T z() const
Definition: PV3DBase.h:63
virtual std::vector< const DetLayer * > compatibleLayers(const FreeTrajectoryState &fts, PropagationDirection timeDirection, int &counter) const
tuple result
Definition: query.py:137
FDLC::const_iterator ConstFDLI
GlobalVector momentum() const
GlobalPoint position() const
virtual void setAdditionalLink(DetLayer *, NavigationDirection direction=insideOut)
virtual const Surface::PositionType & position() const
Returns position of the surface.
virtual std::vector< const DetLayer * > compatibleLayers(NavigationDirection direction) const
bool wellInside(const FreeTrajectoryState &fts, PropagationDirection dir, const BarrelDetLayer *bl, DLC &result) const
std::vector< ForwardDetLayer * > FDLC
virtual std::vector< const DetLayer * > nextLayers(NavigationDirection direction) const
dbl *** dir
Definition: mlp_gen.cc:35
const double epsilon
virtual DetLayer * detLayer() const
T x() const
Definition: PV3DBase.h:61
virtual void setInwardLinks(const BDLC &theBarrelv, const FDLC &theForwardv, TkLayerLess sorter=TkLayerLess(outsideIn))
virtual void setDetLayer(DetLayer *dl)
BDLC::const_iterator ConstBDLI