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.
2 
4 
9 
14 
16 
17 using namespace std;
18 
20  const MagneticField* field)
21 {
22  edm::LogInfo("BeamHaloNavigationSchool")<<"*********Running BeamHaloNavigationSchool *********";
23  theBarrelLength = 0;theField = field; theTracker = theInputTracker;
24  theAllDetLayersInSystem=&theInputTracker->allLayers();
25  // Get barrel layers
26  /*sideways does not need barrels*/
27  /* vector<BarrelDetLayer*> blc = theTracker->barrelLayers();
28  for ( vector<BarrelDetLayer*>::iterator i = blc.begin(); i != blc.end(); i++) {
29  theBarrelLayers.push_back( (*i) );
30  }*/
31 
32  // get forward layers
33  vector<ForwardDetLayer*> flc = theTracker->forwardLayers();
34  for ( vector<ForwardDetLayer*>::iterator i = flc.begin(); i != flc.end(); i++) {
35  theForwardLayers.push_back( (*i) );
36  }
37 
38  FDLI middle = find_if( theForwardLayers.begin(), theForwardLayers.end(),
39  not1(DetBelowZ(0)));
40  theLeftLayers = FDLC( theForwardLayers.begin(), middle);
41  theRightLayers = FDLC( middle, theForwardLayers.end());
42 
43  SymmetricLayerFinder symFinder( theForwardLayers);
44 
45  // only work on positive Z side; negative by mirror symmetry later
46  /*sideways does not need barrels*/
47  // linkBarrelLayers( symFinder);
48 
49  linkForwardLayers( symFinder);
50  LogDebug("BeamHaloNavigationSchool")<<"inverse relation";
51  establishInverseRelations();
52 
53 
54  //add the necessary inward links to end caps
55  LogDebug("BeamHaloNavigationSchool")<<"linkOtherEndLayer";
56  linkOtherEndLayers( symFinder);
57 
58  //set checkCrossing = false to all layers
59  SimpleNavigationSchool::StateType allLayers=navigableLayers();
60  SimpleNavigationSchool::StateType::iterator layerIt=allLayers.begin();
61  SimpleNavigationSchool::StateType::iterator layerIt_end=allLayers.end();
62  for (;layerIt!=layerIt_end;++layerIt)
63  {
64  //convert to SimpleNavigableLayer
65  SimpleNavigableLayer* snl=dynamic_cast<SimpleNavigableLayer*>(*layerIt);
66  if (!snl){
67  edm::LogError("BeamHaloNavigationSchool")<<"navigable layer not casting to simplenavigablelayer.";
68  continue;}
69  snl->setCheckCrossingSide(false);
70  }
71 
72 }
73 
75  NavigationSetter setter(*this);
76 
77  // find for each layer which are the barrel and forward
78  // layers that point to it
79  typedef map<const DetLayer*, vector<BarrelDetLayer*>, less<const DetLayer*> > BarrelMapType;
80  typedef map<const DetLayer*, vector<ForwardDetLayer*>, less<const DetLayer*> > ForwardMapType;
81 
82 
83  BarrelMapType reachedBarrelLayersMap;
84  ForwardMapType reachedForwardLayersMap;
85 
86  for ( BDLI bli = theBarrelLayers.begin();
87  bli!=theBarrelLayers.end(); bli++) {
88  DLC reachedLC = (**bli).nextLayers( insideOut);
89  for ( DLI i = reachedLC.begin(); i != reachedLC.end(); i++) {
90  reachedBarrelLayersMap[*i].push_back( *bli);
91  }
92  }
93 
94  for ( FDLI fli = theForwardLayers.begin();
95  fli!=theForwardLayers.end(); fli++) {
96  DLC reachedLC = (**fli).nextLayers( insideOut);
97  for ( DLI i = reachedLC.begin(); i != reachedLC.end(); i++) {
98  reachedForwardLayersMap[*i].push_back( *fli);
99  }
100  }
101 
102 
103  vector<DetLayer*> lc = theTracker->allLayers();
104  for ( vector<DetLayer*>::iterator i = lc.begin(); i != lc.end(); i++) {
105  SimpleNavigableLayer* navigableLayer =
106  dynamic_cast<SimpleNavigableLayer*>((**i).navigableLayer());
107  if (!navigableLayer) {edm::LogInfo("BeamHaloNavigationSchool")<<"a detlayer does not have a navigable layer, which is normal in beam halo navigation.";}
108  if (navigableLayer){navigableLayer->setInwardLinks( reachedBarrelLayersMap[*i],reachedForwardLayersMap[*i], TkLayerLess(outsideIn, (*i)) );}
109  }
110 
111 }
112 
113 
116  NavigationSetter setter(*this);
117 
118  LogDebug("BeamHaloNavigationSchool")<<"reachable from horizontal";
119  //generally, on the right side, what are the forward layers reachable from the horizontal
120  FDLC reachableFL= reachableFromHorizontal();
121 
122  //even simpler navigation from end to end.
123  //for each of them
124  for (FDLI fl=reachableFL.begin();fl!=reachableFL.end();fl++)
125  {
126  LogDebug("BeamHaloNavigationSchool")<<"adding inward from right";
127  //link it inward to the mirror reachable from horizontal
128  addInward((DetLayer*)*fl,symFinder.mirror(*fl));
129 
130  LogDebug("BeamHaloNavigationSchool")<<"adding inward from mirror of right (left?)";
131  addInward((DetLayer*)symFinder.mirror(*fl),*fl);
132  }
133 
134  /* this is not enough to set reachable from each of them: too few links
135  //this is enough in the end
136  //for each of them
137  for (FDLI fl=reachableFL.begin();fl!=reachableFL.end();fl++)
138  {
139  LogDebug("BeamHaloNavigationSchool")<<"adding inward from right";
140  //link it inward to the mirror reachable from horizontal
141  addInward((DetLayer*)*fl,symFinder.mirror(reachableFL));
142 
143  LogDebug("BeamHaloNavigationSchool")<<"adding inward from mirror of right (left?)";
144  //do the same from the the mirrored layer to the reachable from horizontal
145  addInward((DetLayer*)symFinder.mirror(*fl),reachableFL);
146  }
147  */
148 
149 
150  /* what about linking every not masked layer in each group.
151  except for within the same group
152 
153  vector<FDLC> groups splitForwardLayers();
154  FDLC reachable;
155 
156  for ( vector<FDLC>::iterator group = groups.begin();
157  group != groups.end(); group++) {
158  //for each group
159 
160  for ( FDLI i = group->begin(); i != group->end(); i++) {
161 
162  for ( vector<FDLC>::iterator other_group = groups.begin();
163  other_group != groups.end(); other_group++) {
164  //for each other group
165 
166  if (other_group==group && i==group->begin()){
167  //other_group is the same as group and dealing with the first layer of the group
168  //link the first of each group
169  reachable.push_back(other_group.front());
170  continue;}
171 
172  //now dealing as if other_group is different than group
173  for ( FDLI other_i = other_group->begin(); other_i != other_group->end(); other_i++) {
174  //for each of other group
175  //is the layer in the other group "masking" this one
176  //inner radius smaller OR outer radius bigger
177  if ((**other_i).specificSurface().innerRadius() < (**i).specificSurface().innerRadius() ||
178  (**other_i).specificSurface().outerRadius() > (**i).specificSurface().outerRadius())
179  { //not masked
180  reachableFL.push_back(*other_i);
181  }
182  }
183  //do something special with the first of each group
184  //do somethign special with layers in its own group
185  }
186  }
187  }
188  */
189 
190 
191 
192  /* this is too much links between layers
193  FDLC myRightLayers( theRightLayers);
194  FDLI begin = myRightLayers.begin();
195  FDLI end = myRightLayers.end();
196 
197  // for each of the right layers
198  for (FDLI fl = begin;fl!=end;++fl)
199  {
200  //get the navigable layer for this DetLayer
201  SimpleNavigableLayer* navigableLayer =
202  dynamic_cast<SimpleNavigableLayer*>((*fl)->navigableLayer());
203 
204  LogDebug("BeamHaloNavigationSchool")<<"retreive the next layers outsidein";
205  //get the OUTward reachable layers.
206  DLC inwardsLayers(navigableLayer->nextLayers(insideOut));
207 
208  //what is reachable horizontaly
209  FDLC thisReachableFL (reachableFL);
210 
211  LogDebug("BeamHaloNavigationSchool")<<"combine";
212  //combine the two vector with a conversion to forward layer
213  for (DLI i=inwardsLayers.begin();i!=inwardsLayers.end();++i)
214  {
215  ForwardDetLayer* fd=dynamic_cast<ForwardDetLayer*>(const_cast<DetLayer*>(*i));
216  // ForwardDetLayer* fd=const_cast<ForwardDetLayer*>(*i);
217  if (fd){
218  // if (thisReachableFL.find(fd)==thisReachableFL.end())
219  // {//no duplicate. insert it
220  thisReachableFL.push_back(fd);
221  //}
222  }
223  LogDebug("BeamHaloNavigationSchool")<<"investigate";
224  }
225 
226  //please no duplicate !!!
227  LogDebug("BeamHaloNavigationSchool")<<"no duplicate";
228  FDLI new_end =unique(thisReachableFL.begin(),thisReachableFL.end());
229  thisReachableFL.erase(new_end,thisReachableFL.end());
230 
231  //then set the inwards links
232  LogDebug("BeamHaloNavigationSchool")<<"adding inward from right";
233  //link it inward to the mirror reachable from horizontal
234  addInward((DetLayer*)*fl,symFinder.mirror(thisReachableFL));
235 
236  LogDebug("BeamHaloNavigationSchool")<<"adding inward from mirror of right (left?)";
237  //do the same from the the mirrored layer to the reachable from horizontal
238  addInward((DetLayer*)symFinder.mirror(*fl),thisReachableFL);
239  }
240  */
241 
242 
243 }
244 
247  //get the navigable layer for this DetLayer
248  SimpleNavigableLayer* navigableLayer =
249  dynamic_cast<SimpleNavigableLayer*>((*det).navigableLayer());
250 
251  LogDebug("BeamHaloNavigationSchool")<<"retreive the nextlayer outsidein";
252  //get the inward reachable layers.
253  DLC inwardsLayers(navigableLayer->nextLayers(outsideIn));
254 
255  LogDebug("BeamHaloNavigationSchool")<<"split them barrel/forward";
256  // split barrel and forward layers
257  BDLC inwardsBarrel;
258  FDLC inwardsForward;
259  for ( DLC::iterator dli=inwardsLayers.begin();dli!=inwardsLayers.end();dli++)
260  {
261  if ((**dli).location()==GeomDetEnumerators::barrel)
262  inwardsBarrel.push_back((BarrelDetLayer*)*dli);
263  else
264  inwardsForward.push_back((ForwardDetLayer*)*dli);
265  }
266  LogDebug("BeamHaloNavigationSchool")<<"add the new ones";
267  //add the other forward layers provided
268  inwardsForward.push_back(newF);
269 
270  LogDebug("BeamHaloNavigationSchool")<<"no duplicate please";
271  sort(inwardsForward.begin(),inwardsForward.end()); //if you don't sort, unique will not work
272  // FDLI read = inwardsForward.begin();
273  // std::stringstream showMe;
274  // for (;read !=inwardsForward.end();++read) showMe<<" layer p: "<<*read<<"\n";
275  // LogDebug("BeamHaloNavigationSchool")<<"list of layer pointers: \n"<<showMe.str();
276 
277  FDLI new_end =unique(inwardsForward.begin(),inwardsForward.end());
278  // if (new_end!=inwardsForward.end()) LogDebug("BeamHaloNavigationSchool")<<"removing duplicates here";
279  inwardsForward.erase(new_end,inwardsForward.end());
280 
281  LogDebug("BeamHaloNavigationSchool")<<"set back the inward links (no duplicate)";
282  // set them back to the navigable layer
283  navigableLayer->setInwardLinks( inwardsBarrel, inwardsForward, TkLayerLess(outsideIn, det));
284 }
285 
287 addInward(DetLayer * det, FDLC news){
288  //get the navigable layer for this DetLayer
289  SimpleNavigableLayer* navigableLayer =
290  dynamic_cast<SimpleNavigableLayer*>((*det).navigableLayer());
291 
292  LogDebug("BeamHaloNavigationSchool")<<"retreive the nextlayer outsidein";
293  //get the inward reachable layers.
294  DLC inwardsLayers(navigableLayer->nextLayers(outsideIn));
295 
296  LogDebug("BeamHaloNavigationSchool")<<"split them barrel/forward";
297  // split barrel and forward layers
298  BDLC inwardsBarrel;
299  FDLC inwardsForward;
300  for ( DLC::iterator dli=inwardsLayers.begin();dli!=inwardsLayers.end();dli++)
301  {
302  if ((**dli).location()==GeomDetEnumerators::barrel)
303  inwardsBarrel.push_back((BarrelDetLayer*)*dli);
304  else
305  inwardsForward.push_back((ForwardDetLayer*)*dli);
306  }
307 
308  LogDebug("BeamHaloNavigationSchool")<<"add the new ones";
309  //add the other forward layers provided
310  inwardsForward.insert( inwardsForward.end(), news.begin(), news.end());
311 
312  LogDebug("BeamHaloNavigationSchool")<<"no duplicate please";
313  FDLI new_end =unique(inwardsForward.begin(),inwardsForward.end());
314  inwardsForward.erase(new_end,inwardsForward.end());
315 
316  LogDebug("BeamHaloNavigationSchool")<<"set back the inward links (no duplicate)";
317  // set them back to the navigable layer
318  navigableLayer->setInwardLinks( inwardsBarrel, inwardsForward, TkLayerLess(outsideIn, det));
319 }
320 
323 {
324  //determine which is the list of forward layers that can be reached from inside-out
325  //at horizontal direction
326 
327  FDLC myRightLayers( theRightLayers);
328  FDLI begin = myRightLayers.begin();
329  FDLI end = myRightLayers.end();
330 
331  //sort along Z to be sure
332  sort(begin, end, DetLessZ());
333 
334  FDLC reachableFL;
335 
336  begin = myRightLayers.begin();
337  end = myRightLayers.end();
338 
339  //the first one is always reachable
340  reachableFL.push_back(*begin);
341  FDLI current = begin;
342  for (FDLI i = begin+1; i!= end; i++)
343  {
344  //is the previous layer NOT masking this one
345  //inner radius smaller OR outer radius bigger
346  if ((**i).specificSurface().innerRadius() < (**current).specificSurface().innerRadius() ||
347  (**i).specificSurface().outerRadius() > (**current).specificSurface().outerRadius())
348  { //not masked
349  reachableFL.push_back(*i);
350  current=i;
351  }
352  }
353  return reachableFL;
354 }
#define LogDebug(id)
void addInward(DetLayer *det, FDLC news)
int i
Definition: DBlmapReader.cc:9
BeamHaloNavigationSchool(const GeometricSearchTracker *theTracker, const MagneticField *field)
virtual void setInwardLinks(const BDLC &, const FDLC &, TkLayerLess sorter=TkLayerLess(outsideIn))=0
std::vector< ForwardDetLayer * > FDLC
std::vector< const DetLayer * > DLC
std::vector< NavigableLayer * > StateType
#define end
Definition: vmac.h:38
std::vector< DetLayer * > const & allLayers() const
void setCheckCrossingSide(bool docheck)
#define begin
Definition: vmac.h:31
virtual std::vector< const DetLayer * > nextLayers(NavigationDirection direction) const =0
void linkOtherEndLayers(SymmetricLayerFinder &symFinder)
std::vector< BarrelDetLayer * > BDLC
ForwardDetLayer * mirror(const ForwardDetLayer *layer)