CMS 3D CMS Logo

BeamHaloNavigationSchool.cc
Go to the documentation of this file.
3 
4 #include <vector>
5 
9 public:
10 
12  const MagneticField* field);
14 
15  protected:
16  //addon to SimpleNavigationSchool
17  void linkOtherEndLayers( SymmetricLayerFinder& symFinder);
18  void addInward(const DetLayer * det, const FDLC& news);
19  void addInward(const DetLayer * det, const ForwardDetLayer * newF);
20  void establishInverseRelations() override;
21  FDLC reachableFromHorizontal();
22 };
23 
24 
26 
30 
31 #include "SymmetricLayerFinder.h"
34 #include "SimpleNavigableLayer.h"
35 
36 using namespace std;
37 
39  const MagneticField* field)
40 {
41  edm::LogInfo("BeamHaloNavigationSchool")<<"*********Running BeamHaloNavigationSchool *********";
42  theBarrelLength = 0;theField = field; theTracker = theInputTracker;
43  theAllDetLayersInSystem=&theInputTracker->allLayers();
44  theAllNavigableLayer.resize(theInputTracker->allLayers().size(),nullptr);
45 
46 
47 
48 
49  // Get barrel layers
50  /*sideways does not need barrels*/
51  /* vector<BarrelDetLayer*> blc = theTracker->barrelLayers();
52  for ( vector<BarrelDetLayer*>::iterator i = blc.begin(); i != blc.end(); i++) {
53  theBarrelLayers.push_back( (*i) );
54  }*/
55 
56  // get forward layers
57  for( auto const& l : theTracker->forwardLayers()) {
58  theForwardLayers.push_back(l);
59  }
60 
61  FDLI middle = find_if( theForwardLayers.begin(), theForwardLayers.end(),
62  [](auto const* a){ return a->position().z() >= 0.0; });
63  theLeftLayers = FDLC( theForwardLayers.begin(), middle);
64  theRightLayers = FDLC( middle, theForwardLayers.end());
65 
66  SymmetricLayerFinder symFinder( theForwardLayers);
67 
68  // only work on positive Z side; negative by mirror symmetry later
69  /*sideways does not need barrels*/
70  // linkBarrelLayers( symFinder);
71 
72  linkForwardLayers( symFinder);
73 
74  setState(navigableLayers());
75 
76  LogDebug("BeamHaloNavigationSchool")<<"inverse relation";
77  establishInverseRelations();
78 
79 
80  //add the necessary inward links to end caps
81  LogDebug("BeamHaloNavigationSchool")<<"linkOtherEndLayer";
82 
83  linkOtherEndLayers( symFinder);
84 
85  //set checkCrossing = false to all layers
86  SimpleNavigationSchool::StateType allLayers=navigableLayers();
87  SimpleNavigationSchool::StateType::iterator layerIt=allLayers.begin();
88  SimpleNavigationSchool::StateType::iterator layerIt_end=allLayers.end();
89  for (;layerIt!=layerIt_end;++layerIt)
90  {
91  //convert to SimpleNavigableLayer
92  SimpleNavigableLayer* snl=dynamic_cast<SimpleNavigableLayer*>(*layerIt);
93  if (!snl){
94  edm::LogError("BeamHaloNavigationSchool")<<"navigable layer not casting to simplenavigablelayer.";
95  continue;}
96  snl->setCheckCrossingSide(false);
97  }
98 
99 }
100 
102 
103  // find for each layer which are the barrel and forward
104  // layers that point to it
105  typedef map<const DetLayer*, vector<BarrelDetLayer const*>, less<const DetLayer*> > BarrelMapType;
106  typedef map<const DetLayer*, vector<ForwardDetLayer const*>, less<const DetLayer*> > ForwardMapType;
107 
108 
109  BarrelMapType reachedBarrelLayersMap;
110  ForwardMapType reachedForwardLayersMap;
111 
112  for ( BDLI bli = theBarrelLayers.begin();
113  bli!=theBarrelLayers.end(); bli++) {
114  DLC reachedLC = nextLayers(**bli, insideOut);
115  for ( DLI i = reachedLC.begin(); i != reachedLC.end(); i++) {
116  reachedBarrelLayersMap[*i].push_back( *bli);
117  }
118  }
119 
120  for ( FDLI fli = theForwardLayers.begin();
121  fli!=theForwardLayers.end(); fli++) {
122  DLC reachedLC = nextLayers(**fli, insideOut);
123  for ( DLI i = reachedLC.begin(); i != reachedLC.end(); i++) {
124  reachedForwardLayersMap[*i].push_back( *fli);
125  }
126  }
127 
128 
129  for ( auto const i : theTracker->allLayers()) {
130  SimpleNavigableLayer* navigableLayer =
131  dynamic_cast<SimpleNavigableLayer*>(theAllNavigableLayer[i->seqNum()]);
132  if (!navigableLayer) {edm::LogInfo("BeamHaloNavigationSchool")<<"a detlayer does not have a navigable layer, which is normal in beam halo navigation.";}
133  if (navigableLayer){navigableLayer->setInwardLinks( reachedBarrelLayersMap[i],reachedForwardLayersMap[i], TkLayerLess(outsideIn, i) );}
134  }
135 
136 }
137 
138 
141 
142  LogDebug("BeamHaloNavigationSchool")<<"reachable from horizontal";
143  //generally, on the right side, what are the forward layers reachable from the horizontal
144  FDLC reachableFL= reachableFromHorizontal();
145 
146  //even simpler navigation from end to end.
147  //for each of them
148  for (FDLI fl=reachableFL.begin();fl!=reachableFL.end();fl++)
149  {
150  LogDebug("BeamHaloNavigationSchool")<<"adding inward from right";
151  //link it inward to the mirror reachable from horizontal
152  addInward(static_cast<DetLayer const*>(*fl),symFinder.mirror(*fl));
153 
154  LogDebug("BeamHaloNavigationSchool")<<"adding inward from mirror of right (left?)";
155  addInward(static_cast<DetLayer const*>(symFinder.mirror(*fl)),*fl);
156  }
157 
158 
159 
160 
161 }
162 
164 addInward(const DetLayer * det, const ForwardDetLayer * newF){
165  //get the navigable layer for this DetLayer
166  SimpleNavigableLayer* navigableLayer =
167  dynamic_cast<SimpleNavigableLayer*>(theAllNavigableLayer[(det)->seqNum()]);
168 
169  LogDebug("BeamHaloNavigationSchool")<<"retreive the nextlayer outsidein";
170  //get the inward reachable layers.
171  DLC inwardsLayers(navigableLayer->nextLayers(outsideIn));
172 
173  LogDebug("BeamHaloNavigationSchool")<<"split them barrel/forward";
174  // split barrel and forward layers
175  BDLC inwardsBarrel;
176  FDLC inwardsForward;
177  for ( DLC::iterator dli=inwardsLayers.begin();dli!=inwardsLayers.end();dli++)
178  {
179  if ((**dli).location()==GeomDetEnumerators::barrel)
180  inwardsBarrel.push_back(static_cast<const BarrelDetLayer*>(*dli));
181  else
182  inwardsForward.push_back(static_cast<const ForwardDetLayer*>(*dli));
183  }
184  LogDebug("BeamHaloNavigationSchool")<<"add the new ones";
185  //add the other forward layers provided
186  inwardsForward.push_back(newF);
187 
188  LogDebug("BeamHaloNavigationSchool")<<"no duplicate please";
189  sort(inwardsForward.begin(),inwardsForward.end()); //if you don't sort, unique will not work
190  // FDLI read = inwardsForward.begin();
191  // std::stringstream showMe;
192  // for (;read !=inwardsForward.end();++read) showMe<<" layer p: "<<*read<<"\n";
193  // LogDebug("BeamHaloNavigationSchool")<<"list of layer pointers: \n"<<showMe.str();
194 
195  FDLI new_end =unique(inwardsForward.begin(),inwardsForward.end());
196  // if (new_end!=inwardsForward.end()) LogDebug("BeamHaloNavigationSchool")<<"removing duplicates here";
197  inwardsForward.erase(new_end,inwardsForward.end());
198 
199  LogDebug("BeamHaloNavigationSchool")<<"set back the inward links (no duplicate)";
200  // set them back to the navigable layer
201  navigableLayer->setInwardLinks( inwardsBarrel, inwardsForward, TkLayerLess(outsideIn, det));
202 }
203 
205 addInward(const DetLayer * det, const FDLC& news){
206  //get the navigable layer for this DetLayer
207  SimpleNavigableLayer* navigableLayer =
208  dynamic_cast<SimpleNavigableLayer*>(theAllNavigableLayer[(det)->seqNum()]);
209 
210  LogDebug("BeamHaloNavigationSchool")<<"retreive the nextlayer outsidein";
211  //get the inward reachable layers.
212  DLC inwardsLayers(navigableLayer->nextLayers(outsideIn));
213 
214  LogDebug("BeamHaloNavigationSchool")<<"split them barrel/forward";
215  // split barrel and forward layers
216  BDLC inwardsBarrel;
217  FDLC inwardsForward;
218  for ( DLC::iterator dli=inwardsLayers.begin();dli!=inwardsLayers.end();dli++)
219  {
220  if ((**dli).location()==GeomDetEnumerators::barrel)
221  inwardsBarrel.push_back(static_cast<const BarrelDetLayer*>(*dli));
222  else
223  inwardsForward.push_back(static_cast<const ForwardDetLayer*>(*dli));
224  }
225 
226  LogDebug("BeamHaloNavigationSchool")<<"add the new ones";
227  //add the other forward layers provided
228  inwardsForward.insert( inwardsForward.end(), news.begin(), news.end());
229 
230  LogDebug("BeamHaloNavigationSchool")<<"no duplicate please";
231  FDLI new_end =unique(inwardsForward.begin(),inwardsForward.end());
232  inwardsForward.erase(new_end,inwardsForward.end());
233 
234  LogDebug("BeamHaloNavigationSchool")<<"set back the inward links (no duplicate)";
235  // set them back to the navigable layer
236  navigableLayer->setInwardLinks( inwardsBarrel, inwardsForward, TkLayerLess(outsideIn, det));
237 }
238 
241 {
242  //determine which is the list of forward layers that can be reached from inside-out
243  //at horizontal direction
244 
245  FDLC myRightLayers( theRightLayers);
246  FDLI begin = myRightLayers.begin();
247  FDLI end = myRightLayers.end();
248 
249  //sort along Z to be sure
250  sort(begin, end, isDetLessZ);
251 
252  FDLC reachableFL;
253 
254  begin = myRightLayers.begin();
255  end = myRightLayers.end();
256 
257  //the first one is always reachable
258  reachableFL.push_back(*begin);
259  FDLI current = begin;
260  for (FDLI i = begin+1; i!= end; i++)
261  {
262  //is the previous layer NOT masking this one
263  //inner radius smaller OR outer radius bigger
264  if ((**i).specificSurface().innerRadius() < (**current).specificSurface().innerRadius() ||
265  (**i).specificSurface().outerRadius() > (**current).specificSurface().outerRadius())
266  { //not masked
267  reachableFL.push_back(*i);
268  current=i;
269  }
270  }
271  return reachableFL;
272 }
273 
276 
277 
278 #include "NavigationSchoolFactory.h"
281 
#define LogDebug(id)
std::vector< DetLayer const * > const & allLayers() const
std::vector< const BarrelDetLayer * > BDLC
BeamHaloNavigationSchool(const GeometricSearchTracker *theTracker, const MagneticField *field)
virtual void setInwardLinks(const BDLC &, const FDLC &, TkLayerLess sorter=TkLayerLess(outsideIn))=0
const ForwardDetLayer * mirror(const ForwardDetLayer *layer)
std::vector< const DetLayer * > DLC
bool isDetLessZ(const GeometricSearchDet *a, const GeometricSearchDet *b)
Definition: DetLessZ.h:10
def unique(seq, keepstr=True)
Definition: tier0.py:25
std::vector< NavigableLayer * > StateType
#define end
Definition: vmac.h:39
virtual void establishInverseRelations()
std::vector< const ForwardDetLayer * > FDLC
#define dso_hidden
Definition: Visibility.h:12
virtual std::vector< const DetLayer * > nextLayers(NavigationDirection direction) const =0
void setCheckCrossingSide(bool docheck)
#define begin
Definition: vmac.h:32
double a
Definition: hdecay.h:121
#define DEFINE_EDM_PLUGIN(factory, type, name)
void linkOtherEndLayers(SymmetricLayerFinder &symFinder)
void addInward(const DetLayer *det, const FDLC &news)