test
CMS 3D CMS Logo

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