CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HICSimpleNavigationSchool.cc
Go to the documentation of this file.
2 
4 
10 
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 // vector<DetLayer*> theDetLayers;
36  // Get barrel layers
37  vector<BarrelDetLayer*> blc = theTracker->barrelLayers();
38 // int kk=-1;
39  for ( vector<BarrelDetLayer*>::iterator i = blc.begin(); i != blc.end(); i++) {
40  if((*i)->specificSurface().radius()<20. || (*i)->specificSurface().radius()>65.) {
41 // cout<<"Barrel surface "<<(*i)->specificSurface().radius()<<endl;
42 // kk++;
43 // if(kk==excludedBarrelLayer) continue;
44  theBarrelLayers.push_back( (*i) );
45  theDetLayers.push_back( (*i) );
46  }
47  }
48 
49  // get forward layers
50 
51  vector<ForwardDetLayer*> flc = theTracker->forwardLayers();
52  for ( vector<ForwardDetLayer*>::iterator i = flc.begin(); i != flc.end(); i++) {
53  if(((*i)->specificSurface().outerRadius()>60.&& (*i)->specificSurface().innerRadius()>20.)|| (*i)->specificSurface().innerRadius()<10.) {
54  // cout<<" Endcap surface "<<(*i)->specificSurface().outerRadius()<<" "<<(*i)->specificSurface().innerRadius()<<endl;
55  theForwardLayers.push_back( (*i) );
56  theDetLayers.push_back( (*i) );
57  }
58  }
59 
60 // cout<<" Number of detectors"<< theDetLayers.size()<<endl;
61 
62  FDLI middle = find_if( theForwardLayers.begin(), theForwardLayers.end(),
63  not1(DetBelowZ(0)));
64  // cout<<" Point 0 "<<endl;
65  theLeftLayers = FDLC( theForwardLayers.begin(), middle);
66  // cout<<" Point 1 "<<endl;
67  theRightLayers = FDLC( middle, theForwardLayers.end());
68  // cout<<" Point 2 "<<endl;
70  // cout<<" Point 3 "<<endl;
71  // only work on positive Z side; negative by mirror symmetry later
72  linkBarrelLayers( symFinder);
73  // cout<<" Point 4 "<<endl;
74  linkForwardLayers( symFinder);
75  // cout<<" Point 5 "<<endl;
77  // cout<<" Point 6 "<<endl;
78 }
79 
81  const MagneticField* field, int ll, int nn) :
82  theBarrelLength(0),theField(field), theTracker(theInputTracker)
83 {
84 
87 
88  theAllDetLayersInSystem=&theInputTracker->allLayers();
89 // vector<DetLayer*> theDetLayers;
90  // Get barrel layers
91  vector<BarrelDetLayer*> blc = theTracker->barrelLayers();
92  int kk = 0;
93 
94  //cout<<" kk= "<<kk<<" excludedBarrel "<<excludedBarrelLayer<<" excludedForward "<<excludedForwardLayer<<endl;
95 
96  for ( vector<BarrelDetLayer*>::iterator i = blc.begin(); i != blc.end(); i++) {
97  if((*i)->specificSurface().radius()<20. || (*i)->specificSurface().radius()>65.) {
98 // cout<<"Barrel surface "<<kk<<" "<<(*i)->specificSurface().radius()<<" "<<excludedBarrelLayer<<endl;
99  if(kk != excludedBarrelLayer ) {
100  //cout<<"Included layer "<<endl;
101  theBarrelLayers.push_back( (*i) );
102  theDetLayers.push_back( (*i) );
103  }
104  else {
105  // cout<<"Excluded layer "<<endl;
106  }
107  }
108  kk++;
109  }
110 
111  // get forward layers
112  if( excludedForwardLayer > -1 ) {
113  kk=0;
114  vector<ForwardDetLayer*> flc = theTracker->forwardLayers();
115  for ( vector<ForwardDetLayer*>::iterator i = flc.begin(); i != flc.end(); i++)
116  {
117  if(((*i)->specificSurface().outerRadius()>60.&&
118  (*i)->specificSurface().innerRadius()>20.)|| (*i)->specificSurface().innerRadius()<10.)
119  {
120 // cout<<" Endcap surface "<<kk<<" "<<(*i)->specificSurface().position().z()<<endl;
121  if(kk != excludedForwardLayer && kk != excludedForwardLayer + 14)
122  {
123  //cout<<"Excluded layer "<<endl;
124  theForwardLayers.push_back( (*i) );
125  theDetLayers.push_back( (*i) );
126  } else {
127  // cout<<"Excluded layer "<<endl;
128  }
129  } // radius
130  kk++;
131  } // forward layers
132  } else {
133  vector<ForwardDetLayer*> flc = theTracker->forwardLayers();
134  for ( vector<ForwardDetLayer*>::iterator i = flc.begin(); i != flc.end(); i++)
135  {
136  if(((*i)->specificSurface().outerRadius()>60.&&
137  (*i)->specificSurface().innerRadius()>20.)|| (*i)->specificSurface().innerRadius()<10.)
138  {
139 // cout<<" Endcap surface "<<kk<<" "<<(*i)->specificSurface().position().z()<<endl;
140  //cout<<"Excluded layer "<<endl;
141  theForwardLayers.push_back( (*i) );
142  theDetLayers.push_back( (*i) );
143  } // radius
144  kk++;
145  } // forward layers
146  } // No Excluded layer
147 
148 // cout<<" Number of detectors"<< theDetLayers.size()<<endl;
149 
150  FDLI middle = find_if( theForwardLayers.begin(), theForwardLayers.end(),
151  not1(DetBelowZ(0)));
152  //cout<<" Point 0 "<<endl;
153  theLeftLayers = FDLC( theForwardLayers.begin(), middle);
154  // cout<<" Point 1 "<<endl;
155  theRightLayers = FDLC( middle, theForwardLayers.end());
156  // cout<<" Point 2 "<<endl;
158  // cout<<" Point 3 "<<endl;
159  // only work on positive Z side; negative by mirror symmetry later
160  linkBarrelLayers( symFinder);
161  // cout<<" Point 4 "<<endl;
162  linkForwardLayers( symFinder);
163  // cout<<" Point 5 "<<endl;
165  // cout<<" Point 6 "<<endl;
166 }
167 
170 {
172  for ( vector< SimpleBarrelNavigableLayer*>::const_iterator
173  ib = theBarrelNLC.begin(); ib != theBarrelNLC.end(); ib++) {
174  result.push_back( *ib);
175  }
176  for ( vector< SimpleForwardNavigableLayer*>::const_iterator
177  ifl = theForwardNLC.begin(); ifl != theForwardNLC.end(); ifl++) {
178  result.push_back( *ifl);
179  }
180  return result;
181 }
182 
185 {
186  // Link barrel layers outwards
187  for ( BDLI i = theBarrelLayers.begin(); i != theBarrelLayers.end(); i++) {
188  BDLC reachableBL;
189  FDLC leftFL;
190  FDLC rightFL;
191 
192  // always add next barrel layer first
193  if ( i+1 != theBarrelLayers.end()) reachableBL.push_back(*(i+1));
194 
195  // Add closest reachable forward layer (except for last BarrelLayer)
196  if (i != theBarrelLayers.end() - 1) {
197  linkNextForwardLayer( *i, rightFL);
198  }
199 
200  // Add next BarrelLayer with length larger than the current BL
201  if ( i+2 < theBarrelLayers.end()) {
202  linkNextLargerLayer( i, theBarrelLayers.end(), reachableBL);
203  }
204 
205  theBarrelNLC.push_back( new
206  SimpleBarrelNavigableLayer( *i, reachableBL,
207  symFinder.mirror(rightFL),
208  rightFL,theField, 5.));
209  }
210 }
211 
213  FDLC& rightFL)
214 {
215  // find first forward layer with larger Z and larger outer radius
216  // float length = bl->surface().bounds().length() / 2.;
217 // float radius = bl->specificSurface().radius();
218  for ( FDLI fli = theRightLayers.begin();
219  fli != theRightLayers.end(); fli++) {
220  // if ( length < (**fli).position().z() &&
221  // radius < (**fli).specificSurface().outerRadius())
222  if(fabs((**fli).position().z())>130. && fabs((**fli).position().z())<132.)
223  {
224 #ifdef DEBUG
225 // cout<<" Add to barrel layer "<<radius<<" Forward layer "<<(**fli).position().z()<<endl;
226 #endif
227  rightFL.push_back( *fli);
228  return;
229  }
230  }
231 }
232 
234  BDLC& reachableBL)
235 {
236  // compare length of next layer with length of following ones
237  float length = (**(bli+1)).surface().bounds().length();
238  float epsilon = 0.1;
239 
240  for ( BDLI i = bli+2; i < end; i++) {
241  if ( length + epsilon < (**i).surface().bounds().length()) {
242  reachableBL.push_back( *i);
243  return;
244  }
245  }
246 }
247 
250 {
251 
252  // handle right side first, groups are only on the right
253  vector<FDLC> groups = splitForwardLayers();
254 
255  LogDebug("TkNavigation") << "SimpleNavigationSchool, Forward groups size = " << groups.size() ;
256  for (vector<FDLC>::iterator g = groups.begin(); g != groups.end(); g++) {
257  LogDebug("TkNavigation") << "group " << g - groups.begin() << " has "
258  << g->size() << " layers " ;
259  }
260 
261  for ( vector<FDLC>::iterator group = groups.begin();
262  group != groups.end(); group++) {
263 
264  for ( FDLI i = group->begin(); i != group->end(); i++) {
265 
266  BDLC reachableBL;
267  FDLC reachableFL;
268 
269  // Always connect to next barrel layer first, if exists
270  linkNextBarrelLayer( *i, reachableBL);
271 
272  // Then always connect to next forward layer of "same" size,
273  // and layers of larger inner Radius
274  linkNextLayerInGroup( i, *group, reachableFL);
275 
276  // Then connect to next N fw layers of next size
277  if ( group+1 != groups.end()) {
278  linkOuterGroup( *i, *(group+1), reachableFL);
279  }
280 
281  // or connect within the group if outer radius increases
282  linkWithinGroup( i, *group, reachableFL);
283 
284  theForwardNLC.push_back( new SimpleForwardNavigableLayer( *i,reachableBL,
285  reachableFL,
286  theField,
287  5.));
288  theForwardNLC.push_back( new SimpleForwardNavigableLayer( symFinder.mirror(*i),
289  reachableBL,
290  symFinder.mirror(reachableFL),
291  theField,
292  5.));
293 
294  }
295  }
296 
297 // // now the left side by symmetry
298 // for ( FDLI ileft = theLeftLayers.begin();
299 // ileft != theLeftLayers.end(); ileft++) {
300 // ForwardDetLayer* right = symFinder.mirror( *ileft);
301 
302 // theForwardNLC.push_back( new
303 // SimpleForwardNavigableLayer( *ileft , right->nextBarrelLayers(),
304 // symFinder.mirror(right->nextForwardLayers())));
305 // }
306 }
307 
309  BDLC& reachableBL)
310 {
311  if ( fl->position().z() > barrelLength()) return;
312 
313  // float outerRadius = fl->specificSurface().outerRadius();
314  float zpos = fl->position().z();
315  for ( BDLI bli = theBarrelLayers.begin(); bli != theBarrelLayers.end(); bli++) {
316 // if ( outerRadius < (**bli).specificSurface().radius() &&
317 // zpos < (**bli).surface().bounds().length() / 2.)
318  if( fabs(zpos) > 130. && fabs(zpos) < 132. )
319  {
320  //cout<<" Forward layer "<<fl->position().z()<<" to Barrel layer "<<(**bli).specificSurface().radius()<<endl;
321  reachableBL.push_back( *bli);
322  return;
323  }
324  }
325 }
326 
327 
329  const FDLC& group,
330  FDLC& reachableFL)
331 {
332  // Always connect to next forward layer of "same" size, if exists
333  if ( fli+1 != group.end()) {
334  reachableFL.push_back( *(fli+1));
335  // If that layer has an inner radius larger then the current one
336  // also connect ALL next disks of same radius.
337  float innerRThis = (**fli).specificSurface().innerRadius();
338  float innerRNext = (**(fli+1)).specificSurface().innerRadius();
339  const float epsilon = 2.f;
340 
341  if (innerRNext > innerRThis + epsilon) {
342  // next disk is smaller, so it doesn't cover fully subsequent ones
343  // of same radius
344 
345  int i = 2;
346  while ( (fli+i) != group.end()) {
347  if ( (**(fli+i)).specificSurface().innerRadius() <
348  innerRNext + epsilon) {
349  // following disk has not increased in ineer radius
350  reachableFL.push_back( *(fli+i));
351  i++;
352  } else {
353  break;
354  }
355  }
356  }
357  }
358 }
359 
360 
362  const FDLC& group,
363  FDLC& reachableFL)
364 {
365 
366  // insert N layers with Z grater than fl
367 
368  ConstFDLI first = find_if( group.begin(), group.end(),
369  not1( DetBelowZ( fl->position().z())));
370  if ( first != group.end()) {
371 
372  // Hard-wired constant!!!!!!
373  ConstFDLI last = min( first + 7, group.end());
374 
375  reachableFL.insert( reachableFL.end(), first, last);
376  }
377 }
378 
380  const FDLC& group,
381  FDLC& reachableFL)
382 {
383  ConstFDLI biggerLayer = outerRadiusIncrease( fl, group);
384  if ( biggerLayer != group.end() && biggerLayer != fl+1) {
385  reachableFL.push_back( *biggerLayer);
386  }
387 }
388 
391 {
392  const float epsilon = 5.f;
393  float outerRadius = (**fl).specificSurface().outerRadius();
394  while ( ++fl != group.end()) {
395  if ( (**fl).specificSurface().outerRadius() > outerRadius + epsilon) {
396  return fl;
397  }
398  }
399  return fl;
400 }
401 
402 vector<HICSimpleNavigationSchool::FDLC>
404 {
405  // only work on positive Z side; negative by mirror symmetry later
406 
407  FDLC myRightLayers( theRightLayers);
408  FDLI begin = myRightLayers.begin();
409  FDLI end = myRightLayers.end();
410 
411  // sort according to inner radius
412  sort ( begin, end, DiskLessInnerRadius());
413 
414  // partition in cylinders
415  vector<FDLC> result;
416  FDLC current;
417  current.push_back( *begin);
418  for ( FDLI i = begin+1; i != end; i++) {
419 
420  LogDebug("TkNavigation") << "(**i).specificSurface().innerRadius() = "
421  << (**i).specificSurface().innerRadius() << endl
422  << "(**(i-1)).specificSurface().outerRadius()) = "
423  << (**(i-1)).specificSurface().outerRadius() ;
424 
425  // if inner radius of i is larger than outer radius of i-1 then split!
426  if ( (**i).specificSurface().innerRadius() >
427  (**(i-1)).specificSurface().outerRadius()) {
428 
429  LogDebug("TkNavigation") << "found break between groups" ;
430 
431  // sort layers in group along Z
432  sort ( current.begin(), current.end(), DetLessZ());
433 
434  result.push_back(current);
435  current.clear();
436  }
437  current.push_back(*i);
438  }
439  result.push_back(current); // save last one too
440 
441  // now sort subsets in Z
442  for ( vector<FDLC>::iterator ivec = result.begin();
443  ivec != result.end(); ivec++) {
444  sort( ivec->begin(), ivec->end(), DetLessZ());
445  }
446 
447  return result;
448 }
449 
451 {
452  if ( theBarrelLength < 1.) {
453  for (BDLI i=theBarrelLayers.begin(); i!=theBarrelLayers.end(); i++) {
455  (**i).surface().bounds().length() / 2.f);
456  }
457 
458  LogDebug("TkNavigation") << "The barrel length is " << theBarrelLength ;
459  }
460  return theBarrelLength;
461 }
462 
464 
465  NavigationSetter setter(*this);
466 
467  // find for each layer which are the barrel and forward
468  // layers that point to it
469  typedef map<const DetLayer*, vector<BarrelDetLayer*>, less<const DetLayer*> > BarrelMapType;
470  typedef map<const DetLayer*, vector<ForwardDetLayer*>, less<const DetLayer*> > ForwardMapType;
471 
472  // cout<<"SimpleNavigationSchool::establishInverseRelations::point 0 "<<endl;
473  BarrelMapType reachedBarrelLayersMap;
474  ForwardMapType reachedForwardLayersMap;
475 
476 
477  for ( BDLI bli = theBarrelLayers.begin();
478  bli!=theBarrelLayers.end(); bli++) {
479  DLC reachedLC = (**bli).nextLayers( insideOut);
480  for ( DLI i = reachedLC.begin(); i != reachedLC.end(); i++) {
481  reachedBarrelLayersMap[*i].push_back( *bli);
482  }
483  }
484  // cout<<"SimpleNavigationSchool::establishInverseRelations::point 1 "<<endl;
485  for ( FDLI fli = theForwardLayers.begin();
486  fli!=theForwardLayers.end(); fli++) {
487  DLC reachedLC = (**fli).nextLayers( insideOut);
488  for ( DLI i = reachedLC.begin(); i != reachedLC.end(); i++) {
489  reachedForwardLayersMap[*i].push_back( *fli);
490  }
491  }
492 
493  // cout<<"SimpleNavigationSchool::establishInverseRelations::point 2:: size od detlayers "<<theDetLayers.size()<<endl;
494 // vector<DetLayer*> lc = theTracker->allLayers();
495  for ( vector<DetLayer*>::iterator i = theDetLayers.begin(); i != theDetLayers.end(); i++) {
496  SimpleNavigableLayer* navigableLayer =
497  dynamic_cast<SimpleNavigableLayer*>((**i).navigableLayer());
498  navigableLayer->setInwardLinks( reachedBarrelLayersMap[*i],reachedForwardLayersMap[*i] );
499  }
500  // cout<<"SimpleNavigationSchool::establishInverseRelations::point 3 "<<endl;
501 }
502 
#define LogDebug(id)
int i
Definition: DBlmapReader.cc:9
std::vector< BarrelDetLayer * > BDLC
std::vector< ForwardDetLayer * > FDLC
virtual void linkBarrelLayers(SymmetricLayerFinder &symFinder)
virtual void linkNextLayerInGroup(FDLI fli, const FDLC &group, FDLC &reachableFL)
#define min(a, b)
Definition: mlp_lapack.h:161
virtual std::vector< FDLC > splitForwardLayers()
virtual void setInwardLinks(const BDLC &, const FDLC &, TkLayerLess sorter=TkLayerLess(outsideIn))=0
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
std::vector< DetLayer * > theDetLayers
std::vector< BarrelDetLayer * > const & barrelLayers() const
virtual StateType navigableLayers() const
const T & max(const T &a, const T &b)
T z() const
Definition: PV3DBase.h:58
tuple result
Definition: query.py:137
std::vector< const DetLayer * > DLC
std::vector< NavigableLayer * > StateType
#define end
Definition: vmac.h:38
bool first
Definition: L1TdeRCT.cc:79
std::vector< DetLayer * > const & allLayers() const
virtual void linkNextBarrelLayer(ForwardDetLayer *fl, BDLC &)
virtual void linkNextLargerLayer(BDLI, BDLI, BDLC &)
virtual const Surface::PositionType & position() const
Returns position of the surface.
virtual void linkOuterGroup(ForwardDetLayer *fl, const FDLC &group, FDLC &reachableFL)
virtual void linkForwardLayers(SymmetricLayerFinder &symFinder)
#define begin
Definition: vmac.h:31
const GeometricSearchTracker * theTracker
virtual ConstFDLI outerRadiusIncrease(FDLI fl, const FDLC &group)
const double epsilon
const std::vector< DetLayer * > * theAllDetLayersInSystem
std::vector< ForwardDetLayer * > const & forwardLayers() const
virtual void linkWithinGroup(FDLI fl, const FDLC &group, FDLC &reachableFL)
virtual void linkNextForwardLayer(BarrelDetLayer *, FDLC &)
ForwardDetLayer * mirror(const ForwardDetLayer *layer)