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