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