CMS 3D CMS Logo

SimpleNavigationSchool.cc
Go to the documentation of this file.
2 
4 
7 #include "SimpleNavigableLayer.h"
8 #include "SymmetricLayerFinder.h"
9 
13 
16 
18 
19 #include <algorithm>
20 #include <map>
21 #include <cmath>
22 
23 using namespace std;
24 
26 {
27 
28  theAllDetLayersInSystem=&theTracker->allLayers();
29  theAllNavigableLayer.resize(theTracker->allLayers().size(),nullptr);
30 
31 
32  // Get barrel layers
33  for( auto i : theTracker->barrelLayers()) {
34  theBarrelLayers.push_back( i );
35  }
36 
37  // get forward layers
38  for( auto i : theTracker->forwardLayers()) {
39  theForwardLayers.push_back( i );
40  }
41 
42  FDLI middle = find_if( theForwardLayers.begin(), theForwardLayers.end(),
43  [](const GeometricSearchDet* a){ return a->position().z() >= 0.0; });
44  theLeftLayers = FDLC( theForwardLayers.begin(), middle);
45  theRightLayers = FDLC( middle, theForwardLayers.end());
46 
47  SymmetricLayerFinder symFinder( theForwardLayers);
48 
49  // only work on positive Z side; negative by mirror symmetry later
50  linkBarrelLayers( symFinder);
51  linkForwardLayers( symFinder);
52  establishInverseRelations();
53 }
54 
56  // free the memory allocated to the SimpleNavigableLayers
57  for ( vector< SimpleBarrelNavigableLayer*>::const_iterator
58  ib = theBarrelNLC.begin(); ib != theBarrelNLC.end(); ib++) {
59  delete (*ib);
60  }
61  theBarrelNLC.clear();
62  for ( vector< SimpleForwardNavigableLayer*>::const_iterator
63  ifl = theForwardNLC.begin(); ifl != theForwardNLC.end(); ifl++) {
64  delete (*ifl);
65  }
66  theForwardNLC.clear();
67 }
68 
71 {
73  for ( vector< SimpleBarrelNavigableLayer*>::const_iterator
74  ib = theBarrelNLC.begin(); ib != theBarrelNLC.end(); ib++) {
75  result.push_back( *ib);
76  }
77  for ( vector< SimpleForwardNavigableLayer*>::const_iterator
78  ifl = theForwardNLC.begin(); ifl != theForwardNLC.end(); ifl++) {
79  result.push_back( *ifl);
80  }
81  return result;
82 }
83 
86 {
87  // Link barrel layers outwards
88  for ( BDLI i = theBarrelLayers.begin(); i != theBarrelLayers.end(); i++) {
89  BDLC reachableBL;
90  FDLC leftFL;
91  FDLC rightFL;
92 
93  // always add next barrel layer first
94  if ( i+1 != theBarrelLayers.end()) reachableBL.push_back(*(i+1));
95 
96  // Add closest reachable forward layer (except for last BarrelLayer)
97  if (i != theBarrelLayers.end() - 1) {
98  linkNextForwardLayer( *i, rightFL);
99  }
100 
101  // Add next BarrelLayer with length larger than the current BL
102  if ( i+2 < theBarrelLayers.end()) {
103  linkNextLargerLayer( i, theBarrelLayers.end(), reachableBL);
104  }
105 
106  theBarrelNLC.push_back( new
107  SimpleBarrelNavigableLayer( *i, reachableBL,
108  symFinder.mirror(rightFL),
109  rightFL,theField, 5.));
110  }
111 }
112 
114  FDLC& rightFL)
115 {
116  // find first forward layer with larger Z and larger outer radius
117  float length = bl->surface().bounds().length() / 2.;
118  float radius = bl->specificSurface().radius();
119  for ( FDLI fli = theRightLayers.begin();
120  fli != theRightLayers.end(); fli++) {
121  if ( length < (**fli).position().z() &&
122  radius < (**fli).specificSurface().outerRadius()) {
123  //search if there are any sovrapposition between forward layers
124  for ( FDLI fliNext = fli; fliNext != theRightLayers.end(); fliNext++) {
125  if ( (**fliNext).position().z() < (**fli).position().z() && (**fliNext).specificSurface().innerRadius() < (**fli).specificSurface().outerRadius()) {
126  rightFL.push_back( *fliNext);
127  return;
128  }
129  }
130  rightFL.push_back( *fli);
131  return;
132  }
133  }
134 }
135 
137  BDLC& reachableBL)
138 {
139  // compare length of next layer with length of following ones
140  float length = (**(bli+1)).surface().bounds().length();
141  float epsilon = 0.1;
142 
143  for ( BDLI i = bli+2; i < end; i++) {
144  if ( length + epsilon < (**i).surface().bounds().length()) {
145  reachableBL.push_back( *i);
146  return;
147  }
148  }
149 }
150 
153 {
154 
155  // handle right side first, groups are only on the right
156  vector<FDLC> groups = splitForwardLayers();
157 
158  LogDebug("TkNavigation") << "SimpleNavigationSchool, Forward groups size = " << groups.size() ;
159  for (vector<FDLC>::iterator g = groups.begin(); g != groups.end(); g++) {
160  LogDebug("TkNavigation") << "group " << g - groups.begin() << " has "
161  << g->size() << " layers " ;
162  }
163 
164  for ( vector<FDLC>::iterator group = groups.begin();
165  group != groups.end(); group++) {
166 
167  for ( FDLI i = group->begin(); i != group->end(); i++) {
168 
169  BDLC reachableBL;
170  FDLC reachableFL;
171 
172  // Always connect to next barrel layer first, if exists
173  linkNextBarrelLayer( *i, reachableBL);
174 
175  // Then always connect to next forward layer of "same" size,
176  // and layers of larger inner Radius
177  linkNextLayerInGroup( i, *group, reachableFL);
178 
179  // Then connect to next N fw layers of next size
180  if ( group+1 != groups.end()) {
181  linkOuterGroup( *i, *(group+1), reachableFL);
182  }
183 
184  // or connect within the group if outer radius increases
185  linkWithinGroup( i, *group, reachableFL);
186 
187  theForwardNLC.push_back( new SimpleForwardNavigableLayer( *i,reachableBL,
188  reachableFL,
189  theField,
190  5.));
191  theForwardNLC.push_back( new SimpleForwardNavigableLayer( symFinder.mirror(*i),
192  reachableBL,
193  symFinder.mirror(reachableFL),
194  theField,
195  5.));
196 
197  }
198  }
199 
200 // // now the left side by symmetry
201 // for ( FDLI ileft = theLeftLayers.begin();
202 // ileft != theLeftLayers.end(); ileft++) {
203 // ForwardDetLayer* right = symFinder.mirror( *ileft);
204 
205 // theForwardNLC.push_back( new
206 // SimpleForwardNavigableLayer( *ileft , right->nextBarrelLayers(),
207 // symFinder.mirror(right->nextForwardLayers())));
208 // }
209 }
210 
212  BDLC& reachableBL)
213 {
214  if ( fl->position().z() > barrelLength()) return;
215 
216  float outerRadius = fl->specificSurface().outerRadius();
217  float zpos = fl->position().z();
218  for ( BDLI bli = theBarrelLayers.begin(); bli != theBarrelLayers.end(); bli++) {
219  if ( outerRadius < (**bli).specificSurface().radius() &&
220  zpos < (**bli).surface().bounds().length() / 2.) {
221  reachableBL.push_back( *bli);
222  return;
223  }
224  }
225 }
226 
227 
229  const FDLC& group,
230  FDLC& reachableFL)
231 {
232  // Always connect to next forward layer of "same" size, if exists
233  if ( fli+1 != group.end()) {
234  reachableFL.push_back( *(fli+1));
235  // If that layer has an inner radius larger then the current one
236  // also connect ALL next disks of same radius.
237  float innerRThis = (**fli).specificSurface().innerRadius();
238  float innerRNext = (**(fli+1)).specificSurface().innerRadius();
239  const float epsilon = 2.f;
240 
241  if (innerRNext > innerRThis + epsilon) {
242  // next disk is smaller, so it doesn't cover fully subsequent ones
243  // of same radius
244 
245  int i = 2;
246  while ( (fli+i) != group.end()) {
247  if ( (**(fli+i)).specificSurface().innerRadius() <
248  innerRNext + epsilon) {
249  // following disk has not increased in ineer radius
250  reachableFL.push_back( *(fli+i));
251  i++;
252  } else {
253  break;
254  }
255  }
256  }
257  }
258 }
259 
260 
262  const FDLC& group,
263  FDLC& reachableFL)
264 {
265 
266  // insert N layers with Z grater than fl
267 
268  ConstFDLI first = find_if( group.begin(), group.end(),
269  [fl](const GeometricSearchDet* a){ return a->position().z() >= fl->position().z(); });
270  if ( first != group.end()) {
271 
272  // Hard-wired constant!!!!!!
273  ConstFDLI last = min( first + 7, group.end());
274 
275  reachableFL.insert( reachableFL.end(), first, last);
276  }
277 }
278 
280  const FDLC& group,
281  FDLC& reachableFL)
282 {
283  ConstFDLI biggerLayer = outerRadiusIncrease( fl, group);
284  if ( biggerLayer != group.end() && biggerLayer != fl+1) {
285  reachableFL.push_back( *biggerLayer);
286  }
287 }
288 
291 {
292  const float epsilon = 5.f;
293  float outerRadius = (**fl).specificSurface().outerRadius();
294  while ( ++fl != group.end()) {
295  if ( (**fl).specificSurface().outerRadius() > outerRadius + epsilon) {
296  return fl;
297  }
298  }
299  return fl;
300 }
301 
302 vector<SimpleNavigationSchool::FDLC>
304 {
305  // only work on positive Z side; negative by mirror symmetry later
306 
307  FDLC myRightLayers( theRightLayers);
308  FDLI begin = myRightLayers.begin();
309  FDLI end = myRightLayers.end();
310 
311  // sort according to inner radius, but keeping the ordering in z!
312  std::stable_sort ( begin, end, []( const ForwardDetLayer* a, const ForwardDetLayer* b)
313  { return a->specificSurface().innerRadius() < b->specificSurface().innerRadius();});
314 
315  // partition in cylinders
316  vector<FDLC> result;
317  FDLC current;
318  current.push_back( *begin);
319  for ( FDLI i = begin+1; i != end; i++) {
320 
321 #ifdef EDM_ML_DEBUG
322  LogDebug("TkNavigation") << "(**i).specificSurface().innerRadius() = "
323  << (**i).specificSurface().innerRadius() << endl
324  << "(**(i-1)).specificSurface().outerRadius()) = "
325  << (**(i-1)).specificSurface().outerRadius() ;
326  LogDebug("TkNavigation") << "(**i).specificSurface().position().z() = "
327  << (**i).specificSurface().position().z() << endl
328  << "(**(i-1)).specificSurface().position().z() = "
329  << (**(i-1)).specificSurface().position().z() ;
330 #endif
331 
332  // if inner radius of i is larger than outer radius of i-1 then split!
333  // FIXME: The solution found for phase2 is a bit dirty, we can do better.
334  // For phase2 we compare the EXTENDED pixel with the TID to get the assignment right!
335  if ( (**i).specificSurface().innerRadius() > (**(i-1)).specificSurface().outerRadius() ||
336  (theTracker->posPixelForwardLayers().back()->specificSurface().position().z() > theTracker->posTidLayers().front()->specificSurface().position().z() &&
337  (**i).specificSurface().position().z() < (**(i-1)).specificSurface().position().z()) ){
338 
339  LogDebug("TkNavigation") << "found break between groups" ;
340 
341  // sort layers in group along Z
342  std::stable_sort ( current.begin(), current.end(), isDetLessZ);
343 
344  result.push_back(current);
345  current.clear();
346  }
347  current.push_back(*i);
348  }
349  result.push_back(current); // save last one too
350 
351  // now sort subsets in Z
352  for ( vector<FDLC>::iterator ivec = result.begin();
353  ivec != result.end(); ivec++) {
354  std::stable_sort( ivec->begin(), ivec->end(), isDetLessZ);
355  }
356 
357  return result;
358 }
359 
361 {
362  if ( theBarrelLength < 1.) {
363  for (BDLI i=theBarrelLayers.begin(); i!=theBarrelLayers.end(); i++) {
364  theBarrelLength = max( theBarrelLength,
365  (**i).surface().bounds().length() / 2.f);
366  }
367 
368  LogDebug("TkNavigation") << "The barrel length is " << theBarrelLength ;
369  }
370  return theBarrelLength;
371 }
372 
374 
375  // NavigationSetter setter(*this);
376 
377  setState(navigableLayers());
378 
379  // find for each layer which are the barrel and forward
380  // layers that point to it
381  typedef map<const DetLayer*, vector<const BarrelDetLayer*>, less<const DetLayer*> > BarrelMapType;
382  typedef map<const DetLayer*, vector<const ForwardDetLayer*>, less<const DetLayer*> > ForwardMapType;
383 
384 
385  BarrelMapType reachedBarrelLayersMap;
386  ForwardMapType reachedForwardLayersMap;
387 
388 
389  for ( auto bli : theBarrelLayers) {
390  auto reachedLC = nextLayers(*bli, insideOut);
391  for ( auto i : reachedLC) {
392  reachedBarrelLayersMap[i].push_back(bli);
393  }
394  }
395 
396  for ( auto fli : theForwardLayers) {
397  auto reachedLC = nextLayers(*fli, insideOut);
398  for ( auto i : reachedLC) {
399  reachedForwardLayersMap[i].push_back(fli);
400  }
401  }
402 
403  /*
404  vector<DetLayer*> lc = theTracker->allLayers();
405  for ( vector<DetLayer*>::iterator i = lc.begin(); i != lc.end(); i++) {
406  SimpleNavigableLayer* navigableLayer =
407  dynamic_cast<SimpleNavigableLayer*>((**i).navigableLayer());
408  navigableLayer->setInwardLinks( reachedBarrelLayersMap[*i],reachedForwardLayersMap[*i] );
409  }
410  */
411 
412 
413  for(auto nl : theAllNavigableLayer) {
414  if (!nl) continue;
415  auto navigableLayer = static_cast<SimpleNavigableLayer*>(nl);
416  auto dl = nl->detLayer();
417  navigableLayer->setInwardLinks( reachedBarrelLayersMap[dl],reachedForwardLayersMap[dl] );
418  }
419 
420 
421 }
422 
425 
426 
427 #include "NavigationSchoolFactory.h"
430 
#define LogDebug(id)
virtual float length() const =0
std::vector< const BarrelDetLayer * > BDLC
virtual void linkNextBarrelLayer(ForwardDetLayer const *fl, BDLC &)
const Bounds & bounds() const
Definition: Surface.h:120
StateType navigableLayers() override
virtual const BoundCylinder & specificSurface() const final
Extension of the interface.
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
Definition: Activities.doc:4
const ForwardDetLayer * mirror(const ForwardDetLayer *layer)
FDLC::const_iterator ConstFDLI
bool isDetLessZ(const GeometricSearchDet *a, const GeometricSearchDet *b)
Definition: DetLessZ.h:10
virtual void linkNextLayerInGroup(FDLI fli, const FDLC &group, FDLC &reachableFL)
T z() const
Definition: PV3DBase.h:64
std::vector< NavigableLayer * > StateType
#define end
Definition: vmac.h:39
T min(T a, T b)
Definition: MathUtil.h:58
virtual void linkWithinGroup(FDLI fl, const FDLC &group, FDLC &reachableFL)
virtual void linkForwardLayers(SymmetricLayerFinder &symFinder)
virtual void establishInverseRelations()
std::vector< const ForwardDetLayer * > FDLC
virtual void linkBarrelLayers(SymmetricLayerFinder &symFinder)
virtual const BoundDisk & specificSurface() const final
virtual const Surface::PositionType & position() const
Returns position of the surface.
virtual ConstFDLI outerRadiusIncrease(FDLI fl, const FDLC &group)
double b
Definition: hdecay.h:120
virtual std::vector< FDLC > splitForwardLayers()
virtual void linkNextLargerLayer(BDLI, BDLI, BDLC &)
virtual DetLayer const * detLayer() const =0
#define begin
Definition: vmac.h:32
double a
Definition: hdecay.h:121
#define DEFINE_EDM_PLUGIN(factory, type, name)
virtual void linkNextForwardLayer(BarrelDetLayer const *, FDLC &)
const BoundSurface & surface() const final
GeometricSearchDet interface.
virtual void linkOuterGroup(ForwardDetLayer const *fl, const FDLC &group, FDLC &reachableFL)
ib
Definition: cuy.py:662