CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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  const MagneticField* field) :
31  theBarrelLength(0),theField(field), theTracker(theInputTracker)
32 {
33 
34  theAllDetLayersInSystem=&theInputTracker->allLayers();
35  theAllNavigableLayer.resize(theInputTracker->allLayers().size(),nullptr);
36 
37 
38  // Get barrel layers
39  for( auto i : theTracker->barrelLayers()) {
40  theBarrelLayers.push_back( i );
41  }
42 
43  // get forward layers
44  for( auto i : theTracker->forwardLayers()) {
45  theForwardLayers.push_back( i );
46  }
47 
48  FDLI middle = find_if( theForwardLayers.begin(), theForwardLayers.end(),
49  not1(DetBelowZ(0)));
50  theLeftLayers = FDLC( theForwardLayers.begin(), middle);
51  theRightLayers = FDLC( middle, theForwardLayers.end());
52 
54 
55  // only work on positive Z side; negative by mirror symmetry later
56  linkBarrelLayers( symFinder);
57  linkForwardLayers( symFinder);
59 }
60 
62  // free the memory allocated to the SimpleNavigableLayers
63  for ( vector< SimpleBarrelNavigableLayer*>::const_iterator
64  ib = theBarrelNLC.begin(); ib != theBarrelNLC.end(); ib++) {
65  delete (*ib);
66  }
67  theBarrelNLC.clear();
68  for ( vector< SimpleForwardNavigableLayer*>::const_iterator
69  ifl = theForwardNLC.begin(); ifl != theForwardNLC.end(); ifl++) {
70  delete (*ifl);
71  }
72  theForwardNLC.clear();
73 }
74 
77 {
79  for ( vector< SimpleBarrelNavigableLayer*>::const_iterator
80  ib = theBarrelNLC.begin(); ib != theBarrelNLC.end(); ib++) {
81  result.push_back( *ib);
82  }
83  for ( vector< SimpleForwardNavigableLayer*>::const_iterator
84  ifl = theForwardNLC.begin(); ifl != theForwardNLC.end(); ifl++) {
85  result.push_back( *ifl);
86  }
87  return result;
88 }
89 
92 {
93  // Link barrel layers outwards
94  for ( BDLI i = theBarrelLayers.begin(); i != theBarrelLayers.end(); i++) {
95  BDLC reachableBL;
96  FDLC leftFL;
97  FDLC rightFL;
98 
99  // always add next barrel layer first
100  if ( i+1 != theBarrelLayers.end()) reachableBL.push_back(*(i+1));
101 
102  // Add closest reachable forward layer (except for last BarrelLayer)
103  if (i != theBarrelLayers.end() - 1) {
104  linkNextForwardLayer( *i, rightFL);
105  }
106 
107  // Add next BarrelLayer with length larger than the current BL
108  if ( i+2 < theBarrelLayers.end()) {
109  linkNextLargerLayer( i, theBarrelLayers.end(), reachableBL);
110  }
111 
112  theBarrelNLC.push_back( new
113  SimpleBarrelNavigableLayer( *i, reachableBL,
114  symFinder.mirror(rightFL),
115  rightFL,theField, 5.));
116  }
117 }
118 
120  FDLC& rightFL)
121 {
122  // find first forward layer with larger Z and larger outer radius
123  float length = bl->surface().bounds().length() / 2.;
124  float radius = bl->specificSurface().radius();
125  for ( FDLI fli = theRightLayers.begin();
126  fli != theRightLayers.end(); fli++) {
127  if ( length < (**fli).position().z() &&
128  radius < (**fli).specificSurface().outerRadius()) {
129  rightFL.push_back( *fli);
130  return;
131  }
132  }
133 }
134 
136  BDLC& reachableBL)
137 {
138  // compare length of next layer with length of following ones
139  float length = (**(bli+1)).surface().bounds().length();
140  float epsilon = 0.1;
141 
142  for ( BDLI i = bli+2; i < end; i++) {
143  if ( length + epsilon < (**i).surface().bounds().length()) {
144  reachableBL.push_back( *i);
145  return;
146  }
147  }
148 }
149 
152 {
153 
154  // handle right side first, groups are only on the right
155  vector<FDLC> groups = splitForwardLayers();
156 
157  LogDebug("TkNavigation") << "SimpleNavigationSchool, Forward groups size = " << groups.size() ;
158  for (vector<FDLC>::iterator g = groups.begin(); g != groups.end(); g++) {
159  LogDebug("TkNavigation") << "group " << g - groups.begin() << " has "
160  << g->size() << " layers " ;
161  }
162 
163  for ( vector<FDLC>::iterator group = groups.begin();
164  group != groups.end(); group++) {
165 
166  for ( FDLI i = group->begin(); i != group->end(); i++) {
167 
168  BDLC reachableBL;
169  FDLC reachableFL;
170 
171  // Always connect to next barrel layer first, if exists
172  linkNextBarrelLayer( *i, reachableBL);
173 
174  // Then always connect to next forward layer of "same" size,
175  // and layers of larger inner Radius
176  linkNextLayerInGroup( i, *group, reachableFL);
177 
178  // Then connect to next N fw layers of next size
179  if ( group+1 != groups.end()) {
180  linkOuterGroup( *i, *(group+1), reachableFL);
181  }
182 
183  // or connect within the group if outer radius increases
184  linkWithinGroup( i, *group, reachableFL);
185 
186  theForwardNLC.push_back( new SimpleForwardNavigableLayer( *i,reachableBL,
187  reachableFL,
188  theField,
189  5.));
190  theForwardNLC.push_back( new SimpleForwardNavigableLayer( symFinder.mirror(*i),
191  reachableBL,
192  symFinder.mirror(reachableFL),
193  theField,
194  5.));
195 
196  }
197  }
198 
199 // // now the left side by symmetry
200 // for ( FDLI ileft = theLeftLayers.begin();
201 // ileft != theLeftLayers.end(); ileft++) {
202 // ForwardDetLayer* right = symFinder.mirror( *ileft);
203 
204 // theForwardNLC.push_back( new
205 // SimpleForwardNavigableLayer( *ileft , right->nextBarrelLayers(),
206 // symFinder.mirror(right->nextForwardLayers())));
207 // }
208 }
209 
211  BDLC& reachableBL)
212 {
213  if ( fl->position().z() > barrelLength()) return;
214 
215  float outerRadius = fl->specificSurface().outerRadius();
216  float zpos = fl->position().z();
217  for ( BDLI bli = theBarrelLayers.begin(); bli != theBarrelLayers.end(); bli++) {
218  if ( outerRadius < (**bli).specificSurface().radius() &&
219  zpos < (**bli).surface().bounds().length() / 2.) {
220  reachableBL.push_back( *bli);
221  return;
222  }
223  }
224 }
225 
226 
228  const FDLC& group,
229  FDLC& reachableFL)
230 {
231  // Always connect to next forward layer of "same" size, if exists
232  if ( fli+1 != group.end()) {
233  reachableFL.push_back( *(fli+1));
234  // If that layer has an inner radius larger then the current one
235  // also connect ALL next disks of same radius.
236  float innerRThis = (**fli).specificSurface().innerRadius();
237  float innerRNext = (**(fli+1)).specificSurface().innerRadius();
238  const float epsilon = 2.f;
239 
240  if (innerRNext > innerRThis + epsilon) {
241  // next disk is smaller, so it doesn't cover fully subsequent ones
242  // of same radius
243 
244  int i = 2;
245  while ( (fli+i) != group.end()) {
246  if ( (**(fli+i)).specificSurface().innerRadius() <
247  innerRNext + epsilon) {
248  // following disk has not increased in ineer radius
249  reachableFL.push_back( *(fli+i));
250  i++;
251  } else {
252  break;
253  }
254  }
255  }
256  }
257 }
258 
259 
261  const FDLC& group,
262  FDLC& reachableFL)
263 {
264 
265  // insert N layers with Z grater than fl
266 
267  ConstFDLI first = find_if( group.begin(), group.end(),
268  not1( DetBelowZ( fl->position().z())));
269  if ( first != group.end()) {
270 
271  // Hard-wired constant!!!!!!
272  ConstFDLI last = min( first + 7, group.end());
273 
274  reachableFL.insert( reachableFL.end(), first, last);
275  }
276 }
277 
279  const FDLC& group,
280  FDLC& reachableFL)
281 {
282  ConstFDLI biggerLayer = outerRadiusIncrease( fl, group);
283  if ( biggerLayer != group.end() && biggerLayer != fl+1) {
284  reachableFL.push_back( *biggerLayer);
285  }
286 }
287 
290 {
291  const float epsilon = 5.f;
292  float outerRadius = (**fl).specificSurface().outerRadius();
293  while ( ++fl != group.end()) {
294  if ( (**fl).specificSurface().outerRadius() > outerRadius + epsilon) {
295  return fl;
296  }
297  }
298  return fl;
299 }
300 
301 vector<SimpleNavigationSchool::FDLC>
303 {
304  // only work on positive Z side; negative by mirror symmetry later
305 
306  FDLC myRightLayers( theRightLayers);
307  FDLI begin = myRightLayers.begin();
308  FDLI end = myRightLayers.end();
309 
310  // sort according to inner radius
311  sort ( begin, end, DiskLessInnerRadius());
312 
313  // partition in cylinders
314  vector<FDLC> result;
315  FDLC current;
316  current.push_back( *begin);
317  for ( FDLI i = begin+1; i != end; i++) {
318 
319  LogDebug("TkNavigation") << "(**i).specificSurface().innerRadius() = "
320  << (**i).specificSurface().innerRadius() << endl
321  << "(**(i-1)).specificSurface().outerRadius()) = "
322  << (**(i-1)).specificSurface().outerRadius() ;
323 
324  // if inner radius of i is larger than outer radius of i-1 then split!
325  if ( (**i).specificSurface().innerRadius() >
326  (**(i-1)).specificSurface().outerRadius()) {
327 
328  LogDebug("TkNavigation") << "found break between groups" ;
329 
330  // sort layers in group along Z
331  sort ( current.begin(), current.end(), DetLessZ());
332 
333  result.push_back(current);
334  current.clear();
335  }
336  current.push_back(*i);
337  }
338  result.push_back(current); // save last one too
339 
340  // now sort subsets in Z
341  for ( vector<FDLC>::iterator ivec = result.begin();
342  ivec != result.end(); ivec++) {
343  sort( ivec->begin(), ivec->end(), DetLessZ());
344  }
345 
346  return result;
347 }
348 
350 {
351  if ( theBarrelLength < 1.) {
352  for (BDLI i=theBarrelLayers.begin(); i!=theBarrelLayers.end(); i++) {
354  (**i).surface().bounds().length() / 2.f);
355  }
356 
357  LogDebug("TkNavigation") << "The barrel length is " << theBarrelLength ;
358  }
359  return theBarrelLength;
360 }
361 
363 
364  // NavigationSetter setter(*this);
365 
367 
368  // find for each layer which are the barrel and forward
369  // layers that point to it
370  typedef map<const DetLayer*, vector<const BarrelDetLayer*>, less<const DetLayer*> > BarrelMapType;
371  typedef map<const DetLayer*, vector<const ForwardDetLayer*>, less<const DetLayer*> > ForwardMapType;
372 
373 
374  BarrelMapType reachedBarrelLayersMap;
375  ForwardMapType reachedForwardLayersMap;
376 
377 
378  for ( auto bli : theBarrelLayers) {
379  auto reachedLC = nextLayers(*bli, insideOut);
380  for ( auto i : reachedLC) {
381  reachedBarrelLayersMap[i].push_back(bli);
382  }
383  }
384 
385  for ( auto fli : theForwardLayers) {
386  auto reachedLC = nextLayers(*fli, insideOut);
387  for ( auto i : reachedLC) {
388  reachedForwardLayersMap[i].push_back(fli);
389  }
390  }
391 
392  /*
393  vector<DetLayer*> lc = theTracker->allLayers();
394  for ( vector<DetLayer*>::iterator i = lc.begin(); i != lc.end(); i++) {
395  SimpleNavigableLayer* navigableLayer =
396  dynamic_cast<SimpleNavigableLayer*>((**i).navigableLayer());
397  navigableLayer->setInwardLinks( reachedBarrelLayersMap[*i],reachedForwardLayersMap[*i] );
398  }
399  */
400 
401 
402  for(auto nl : theAllNavigableLayer) {
403  if (!nl) continue;
404  auto navigableLayer = static_cast<SimpleNavigableLayer*>(nl);
405  auto dl = nl->detLayer();
406  navigableLayer->setInwardLinks( reachedBarrelLayersMap[dl],reachedForwardLayersMap[dl] );
407  }
408 
409 
410 }
411 
414 
415 
416 #include "NavigationSchoolFactory.h"
419 
#define LogDebug(id)
int i
Definition: DBlmapReader.cc:9
int ib
Definition: cuy.py:660
virtual float length() const =0
std::vector< DetLayer const * > const & allLayers() const
std::vector< const BarrelDetLayer * > BDLC
virtual void linkNextBarrelLayer(ForwardDetLayer const *fl, BDLC &)
virtual const BoundSurface & surface() const final
GeometricSearchDet interface.
virtual DetLayer const * detLayer() const =0
std::vector< ForwardDetLayer const * > const & forwardLayers() const
const Bounds & bounds() const
Definition: Surface.h:120
virtual StateType navigableLayers() override
const GeometricSearchTracker * theTracker
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)
tuple result
Definition: mps_fire.py:83
FDLC::const_iterator ConstFDLI
virtual void linkNextLayerInGroup(FDLI fli, const FDLC &group, FDLC &reachableFL)
T z() const
Definition: PV3DBase.h:64
StateType theAllNavigableLayer
std::vector< NavigableLayer * > StateType
#define end
Definition: vmac.h:37
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
const std::vector< const DetLayer * > * theAllDetLayersInSystem
const MagneticField * theField
tuple group
Definition: watchdog.py:82
virtual void linkBarrelLayers(SymmetricLayerFinder &symFinder)
virtual const Surface::PositionType & position() const
Returns position of the surface.
virtual ConstFDLI outerRadiusIncrease(FDLI fl, const FDLC &group)
std::vector< const DetLayer * > nextLayers(const DetLayer &detLayer, Args &&...args) const
NavigationDirection.
virtual const BoundCylinder & specificSurface() const final
Extension of the interface.
virtual std::vector< FDLC > splitForwardLayers()
virtual void linkNextLargerLayer(BDLI, BDLI, BDLC &)
#define begin
Definition: vmac.h:30
virtual const BoundDisk & specificSurface() const final
#define DEFINE_EDM_PLUGIN(factory, type, name)
virtual void linkNextForwardLayer(BarrelDetLayer const *, FDLC &)
void setState(const StateType &state)
virtual void linkOuterGroup(ForwardDetLayer const *fl, const FDLC &group, FDLC &reachableFL)
std::vector< BarrelDetLayer const * > const & barrelLayers() const