CMS 3D CMS Logo

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