CMS 3D CMS Logo

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