CMS 3D CMS Logo

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