CMS 3D CMS Logo

MTDNavigationSchool.cc
Go to the documentation of this file.
1 
16 
17 /* Collaborating Class Header */
28 
29 #include <algorithm>
30 #include <iostream>
31 using namespace std;
32 
34 MTDNavigationSchool::MTDNavigationSchool(const MTDDetLayerGeometry * mtdLayout, bool enableBTL, bool enableETL ) : theMTDDetLayerGeometry(mtdLayout) {
35 
36  theAllDetLayersInSystem=&mtdLayout->allLayers();
37  theAllNavigableLayer.resize(mtdLayout->allLayers().size(),nullptr);
38 
39 
40 
41  // get all barrel DetLayers (BTL)
42  vector<const DetLayer*> barrel;
43  if ( enableBTL ) barrel = mtdLayout->allBarrelLayers();
44  else barrel = mtdLayout->allBarrelLayers();
45 
46  for ( auto i = barrel.begin(); i != barrel.end(); i++ ) {
47  const BarrelDetLayer* mbp = dynamic_cast<const BarrelDetLayer*>(*i);
48  if ( mbp == nullptr ) throw cms::Exception("MTDNavigationSchool", "Bad BarrelDetLayer");
49  addBarrelLayer(mbp);
50  }
51 
52 
53  // get all endcap DetLayers (ETL)
54  vector<const DetLayer*> endcap;
55  if ( enableETL ) endcap = mtdLayout->allEndcapLayers();
56  else endcap = mtdLayout->allEndcapLayers();
57 
58  for ( auto i = endcap.begin(); i != endcap.end(); i++ ) {
59  const ForwardDetLayer* mep = dynamic_cast<const ForwardDetLayer*>(*i);
60  if ( mep == nullptr ) throw cms::Exception("MTDNavigationSchool", "Bad ForwardDetLayer");
61  addEndcapLayer(mep);
62  }
63 
64  // create outward links for all DetLayers
68 
69  // create inverse links
71 
72 }
73 
74 
77 
78  for_each(theBarrelNLC.begin(),theBarrelNLC.end(), delete_layer());
79  for_each(theForwardNLC.begin(),theForwardNLC.end(), delete_layer());
80  for_each(theBackwardNLC.begin(),theBackwardNLC.end(), delete_layer());
81 
82 }
83 
84 
88 
90 
91  vector<BTLNavigableLayer*>::const_iterator ib;
92  vector<ETLNavigableLayer*>::const_iterator ie;
93 
94  for ( ib = theBarrelNLC.begin(); ib != theBarrelNLC.end(); ib++ ) {
95  result.push_back(*ib);
96  }
97 
98  for ( ie = theForwardNLC.begin(); ie != theForwardNLC.end(); ie++ ) {
99  result.push_back(*ie);
100  }
101 
102  for ( ie = theBackwardNLC.begin(); ie != theBackwardNLC.end(); ie++ ) {
103  result.push_back(*ie);
104  }
105 
106  return result;
107 
108 }
109 
110 
113 
114  const BoundCylinder& bc = mbp->specificSurface();
115  float radius = bc.radius();
116  float length = bc.bounds().length()/2.;
117 
118  float eta_max = calculateEta(radius, length);
119  float eta_min = -eta_max;
120 
121  theBarrelLayers[mbp] = MTDEtaRange(eta_max, eta_min);
122 
123 }
124 
125 
128 
129  const BoundDisk& bd = mep->specificSurface();
130  float outRadius = bd.outerRadius();
131  float inRadius = bd.innerRadius();
132  float thick = bd.bounds().length()/2.;
133  float z = bd.position().z();
134 
135  if ( z > 0. ) {
136  float eta_min = calculateEta(outRadius, z-thick);
137  float eta_max = calculateEta(inRadius, z+thick);
138  theForwardLayers[mep] = MTDEtaRange(eta_max, eta_min);
139  } else {
140  float eta_max = calculateEta(outRadius, z+thick);
141  float eta_min = calculateEta(inRadius, z-thick);
142  theBackwardLayers[mep] = MTDEtaRange(eta_max, eta_min);
143  }
144 
145 }
146 
147 
149 float MTDNavigationSchool::calculateEta(const float& r, const float& z) const {
150 
151  if ( z > 0 ) return -log((tan(atan(r/z)/2.)));
152  return log(-(tan(atan(r/z)/2.)));
153 
154 }
155 
158 
159  for (MapBI bl = theBarrelLayers.begin();
160  bl != theBarrelLayers.end(); bl++) {
161 
162  MTDEtaRange range = (*bl).second;
163 
164  // first add next barrel layer
165  MapBI plusOne(bl);
166  plusOne++;
167  MapB outerBarrel;
168  MapB allOuterBarrel;
169  if ( plusOne != theBarrelLayers.end() ) { outerBarrel.insert(*plusOne);}
170  // add all outer barrel layers
171  for ( MapBI iMBI = plusOne; iMBI!= theBarrelLayers.end(); iMBI++){
172  allOuterBarrel.insert(*iMBI);
173  }
174  // then add all compatible backward layers with an eta criteria
175  MapE allOuterBackward;
176  for (MapEI el = theBackwardLayers.begin();
177  el != theBackwardLayers.end(); el++) {
178  if ( (*el).second.isCompatible(range) ) {
179  allOuterBackward.insert(*el);
180  }
181  }
182  //add the backward next layer with an eta criteria
183  MapE outerBackward;
184  for (MapEI el = theBackwardLayers.begin();
185  el != theBackwardLayers.end(); el++) {
186  if ( (*el).second.isCompatible(range) ) {
187  outerBackward.insert(*el);
188  break;
189  }
190  }
191 
192  // then add all compatible forward layers with an eta criteria
193  MapE allOuterForward;
194  for (MapEI el = theForwardLayers.begin();
195  el != theForwardLayers.end(); el++) {
196  if ( (*el).second.isCompatible(range) ) {
197  allOuterForward.insert(*el);
198  }
199  }
200 
201  // then add forward next layer with an eta criteria
202  MapE outerForward;
203  for (MapEI el = theForwardLayers.begin();
204  el != theForwardLayers.end(); el++) {
205  if ( (*el).second.isCompatible(range) ) {
206  outerForward.insert(*el);
207  break;
208  }
209  }
210 
211  theBarrelNLC.push_back(new BTLNavigableLayer(
212  (*bl).first,outerBarrel, outerBackward, outerForward,
213  allOuterBarrel,allOuterBackward,allOuterForward));
214 
215  }
216 
217 }
220  vector<ETLNavigableLayer*>& result) {
221 
222  for (MapEI el = layers.begin(); el != layers.end(); el++) {
223 
224  MTDEtaRange range = (*el).second;
225  // first add next endcap layer (if compatible)
226  MapEI plusOne(el);
227  plusOne++;
228  MapE outerLayers;
229  if ( plusOne != layers.end() && (*plusOne).second.isCompatible(range) ) {
230  outerLayers.insert(*plusOne);
231  if ( !range.isInside((*plusOne).second) ) {
232  // then look if the next layer has a wider eta range, if so add it
233  MapEI tmpel(plusOne);
234  tmpel++;
235  MTDEtaRange max((*plusOne).second);
236  for ( MapEI l = tmpel; l != layers.end(); l++ ) {
237  MTDEtaRange next = (*l).second;
238  if ( next.isCompatible(max) && !range.isInside(next) &&
239  !next.isInside(max) && next.subtract(max).isInside(range) ) {
240  max = max.add(next);
241  outerLayers.insert(*l);
242  }
243  }
244  }
245  }
246 
247  MapE allOuterLayers;
248  for (MapEI iMEI = plusOne; iMEI!=layers.end(); iMEI++){
249  if ((*iMEI).second.isCompatible(range)) allOuterLayers.insert(*iMEI);
250  }
251 
252  result.push_back(new ETLNavigableLayer(
253  (*el).first,outerLayers, allOuterLayers));
254  }
255 
256 }
257 
258 
261 
262  // set outward link
263  // NavigationSetter setter(*this);
264 
266 
267 
268  // find for each layer which are the layers pointing to it
269  typedef map<const DetLayer*, MapB, less<const DetLayer*> > BarrelMapType;
270  typedef map<const DetLayer*, MapE, less<const DetLayer*> > ForwardMapType;
271 
272  // map of all DetLayers which can reach a specific DetLayer
273  BarrelMapType reachedBarrelLayersMap;
274  ForwardMapType reachedForwardLayersMap;
275 
276  // map of all DetLayers which is compatible with a specific DetLayer
277  BarrelMapType compatibleBarrelLayersMap;
278  ForwardMapType compatibleForwardLayersMap;
279 
280  // collect all reacheable layers starting from a barrel layer
281  for ( MapBI bli = theBarrelLayers.begin();
282  bli != theBarrelLayers.end(); bli++ ) {
283  // barrel
284  BTLNavigableLayer* mbnl =
285  dynamic_cast<BTLNavigableLayer*>(theAllNavigableLayer[((*bli).first)->seqNum()]);
286  MapB reacheableB = mbnl->getOuterBarrelLayers();
287  for (MapBI i = reacheableB.begin(); i != reacheableB.end(); i++ ) {
288  reachedBarrelLayersMap[(*i).first].insert(*bli);
289  }
290  MapB compatibleB = mbnl->getAllOuterBarrelLayers();
291  for (MapBI i = compatibleB.begin(); i != compatibleB.end(); i++ ) {
292  compatibleBarrelLayersMap[(*i).first].insert(*bli);
293  }
294  MapE reacheableE = mbnl->getOuterBackwardLayers();
295  for (MapEI i = reacheableE.begin(); i != reacheableE.end(); i++ ) {
296  reachedBarrelLayersMap[(*i).first].insert(*bli);
297  }
298  reacheableE = mbnl->getOuterForwardLayers();
299  for (MapEI i = reacheableE.begin(); i != reacheableE.end(); i++ ) {
300  reachedBarrelLayersMap[(*i).first].insert(*bli);
301  }
302  MapE compatibleE = mbnl->getAllOuterBackwardLayers();
303  for (MapEI i = compatibleE.begin(); i != compatibleE.end(); i++ ) {
304  compatibleBarrelLayersMap[(*i).first].insert(*bli);
305  }
306  compatibleE = mbnl->getAllOuterForwardLayers();
307  for (MapEI i = compatibleE.begin(); i != compatibleE.end(); i++ ) {
308  compatibleBarrelLayersMap[(*i).first].insert(*bli);
309  }
310 
311  }
312 
313  // collect all reacheable layer starting from a backward layer
314  for ( MapEI eli = theBackwardLayers.begin();
315  eli != theBackwardLayers.end(); eli++ ) {
316  MapE reacheableE =
317  dynamic_cast<ETLNavigableLayer*>(theAllNavigableLayer[((*eli).first)->seqNum()])->getOuterEndcapLayers();
318  for (MapEI i = reacheableE.begin(); i != reacheableE.end(); i++ ) {
319  reachedForwardLayersMap[(*i).first].insert(*eli);
320  }
321  // collect all compatible layer starting from a backward layer
322  MapE compatibleE =
323  dynamic_cast<ETLNavigableLayer*>(theAllNavigableLayer[((*eli).first)->seqNum()])->getAllOuterEndcapLayers();
324  for (MapEI i = compatibleE.begin(); i != compatibleE.end(); i++ ) {
325  compatibleForwardLayersMap[(*i).first].insert(*eli);
326  }
327  }
328 
329  for ( MapEI eli = theForwardLayers.begin();
330  eli != theForwardLayers.end(); eli++ ) {
331  // collect all reacheable layer starting from a forward layer
332  MapE reacheableE =
333  dynamic_cast<ETLNavigableLayer*>(theAllNavigableLayer[((*eli).first)->seqNum()])->getOuterEndcapLayers();
334  for (MapEI i = reacheableE.begin(); i != reacheableE.end(); i++ ) {
335  reachedForwardLayersMap[(*i).first].insert(*eli);
336  }
337  // collect all compatible layer starting from a forward layer
338  MapE compatibleE =
339  dynamic_cast<ETLNavigableLayer*>(theAllNavigableLayer[((*eli).first)->seqNum()])->getAllOuterEndcapLayers();
340  for (MapEI i = compatibleE.begin(); i != compatibleE.end(); i++ ) {
341  compatibleForwardLayersMap[(*i).first].insert(*eli);
342  }
343  }
344 
345  // now set inverse link for barrel layers
346  for ( MapBI bli = theBarrelLayers.begin();
347  bli != theBarrelLayers.end(); bli++ ) {
348  BTLNavigableLayer* mbnl =
349  dynamic_cast<BTLNavigableLayer*>(theAllNavigableLayer[((*bli).first)->seqNum()]);
350  mbnl->setInwardLinks(reachedBarrelLayersMap[(*bli).first]);
351  mbnl->setInwardCompatibleLinks(compatibleBarrelLayersMap[(*bli).first]);
352 
353  }
354  //BACKWARD
355  for ( MapEI eli = theBackwardLayers.begin();
356  eli != theBackwardLayers.end(); eli++ ) {
357  ETLNavigableLayer* mfnl =
358  dynamic_cast<ETLNavigableLayer*>(theAllNavigableLayer[((*eli).first)->seqNum()]);
359  // for backward next layers
360  mfnl->setInwardLinks(reachedBarrelLayersMap[(*eli).first],
361  reachedForwardLayersMap[(*eli).first]);
362  // for backward compatible layers
363  mfnl->setInwardCompatibleLinks(compatibleBarrelLayersMap[(*eli).first],
364  compatibleForwardLayersMap[(*eli).first]);
365  }
366  //FORWARD
367  for ( MapEI eli = theForwardLayers.begin();
368  eli != theForwardLayers.end(); eli++ ) {
369  ETLNavigableLayer* mfnl =
370  dynamic_cast<ETLNavigableLayer*>(theAllNavigableLayer[((*eli).first)->seqNum()]);
371  // and for forward next layers
372  mfnl->setInwardLinks(reachedBarrelLayersMap[(*eli).first],
373  reachedForwardLayersMap[(*eli).first]);
374  // and for forward compatible layers
375  mfnl->setInwardCompatibleLinks(compatibleBarrelLayersMap[(*eli).first],
376  compatibleForwardLayersMap[(*eli).first]);
377  }
378 
379 }
const std::vector< const DetLayer * > & allLayers() const
return all DetLayers (barrel + endcap), -Z to +Z
std::vector< BTLNavigableLayer * > theBarrelNLC
-z endcap
MapB::const_iterator MapBI
std::vector< LayerSetAndLayers > layers(const SeedingLayerSetsHits &sets)
Definition: LayerTriplets.cc:4
StateType navigableLayers() override
return navigable layers, from base class
std::map< const BarrelDetLayer *, MTDEtaRange, MTDDetLayerComp > MapB
const std::vector< const DetLayer * > & allEndcapLayers() const
return all endcap layers
std::vector< ETLNavigableLayer * > theBackwardNLC
MapB getOuterBarrelLayers() const
void linkBarrelLayers()
link barrel layers
MapE getOuterForwardLayers() const
virtual const BoundCylinder & specificSurface() const final
Extension of the interface.
void linkEndcapLayers(const MapE &, std::vector< ETLNavigableLayer * > &)
link endcap layers
~MTDNavigationSchool() override
Destructor.
std::vector< ETLNavigableLayer * > theForwardNLC
MapE getAllOuterForwardLayers() const
MTDEtaRange add(const MTDEtaRange &) const
create maximum of ranges
Definition: MTDEtaRange.cc:59
MapE getOuterBackwardLayers() const
MTDNavigationSchool(const MTDDetLayerGeometry *, bool enableBTL=true, bool enableETL=true)
Constructor.
StateType theAllNavigableLayer
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
void createInverseLinks()
establish inward links
std::vector< NavigableLayer * > StateType
float calculateEta(const float &, const float &) const
calculate pseudorapidity from r and z
const std::vector< const DetLayer * > * theAllDetLayersInSystem
MapE theBackwardLayers
+z endcap
MapE getAllOuterBackwardLayers() const
virtual const BoundDisk & specificSurface() const final
bool isInside(float eta, float error=0.) const
Definition: MTDEtaRange.cc:43
void setInwardCompatibleLinks(const MapB &, const MapE &)
const std::vector< const DetLayer * > & allBarrelLayers() const
return all barrel layers
void addEndcapLayer(const ForwardDetLayer *)
add endcap layer (backward and forward)
MTDEtaRange subtract(const MTDEtaRange &) const
create new range of size this minus range
Definition: MTDEtaRange.cc:65
MapE::const_iterator MapEI
void addBarrelLayer(const BarrelDetLayer *)
add barrel layer
MapB getAllOuterBarrelLayers() const
void setInwardLinks(const MapB &)
set inward links
void setState(const StateType &state)
void setInwardCompatibleLinks(const MapB &)
bool isCompatible(const MTDEtaRange &range) const
true if this overlaps with range
Definition: MTDEtaRange.cc:54
ib
Definition: cuy.py:662
void setInwardLinks(const MapB &, const MapE &)
set inward links
std::map< const ForwardDetLayer *, MTDEtaRange, MTDDetLayerComp > MapE