CMS 3D CMS Logo

MagGeometry.cc
Go to the documentation of this file.
1 /*
2  * See header file for a description of this class.
3  *
4  * \author N. Amapane - INFN Torino
5  */
6 
12 
14 
16 
19 
20 using namespace std;
21 using namespace edm;
22 
23 MagGeometry::MagGeometry(int geomVersion, const std::vector<MagBLayer *>& tbl,
24  const std::vector<MagESector *>& tes,
25  const std::vector<MagVolume6Faces*>& tbv,
26  const std::vector<MagVolume6Faces*>& tev) :
27  MagGeometry(geomVersion, reinterpret_cast<std::vector<MagBLayer const*> const&>(tbl), reinterpret_cast<std::vector<MagESector const*> const&>(tes),
28  reinterpret_cast<std::vector<MagVolume6Faces const*> const&>(tbv), reinterpret_cast<std::vector<MagVolume6Faces const*> const&>(tev)) {}
29 
30 MagGeometry::MagGeometry(int geomVersion, const std::vector<MagBLayer const*>& tbl,
31  const std::vector<MagESector const*>& tes,
32  const std::vector<MagVolume6Faces const*>& tbv,
33  const std::vector<MagVolume6Faces const*>& tev) :
35 {
36  vector<double> rBorders;
37 
38  for (vector<MagBLayer const*>::const_iterator ilay = theBLayers.begin();
39  ilay != theBLayers.end(); ++ilay) {
40  if (verbose::debugOut) cout << " Barrel layer at " << (*ilay)->minR() <<endl;
41  //FIXME assume layers are already sorted in minR
42  rBorders.push_back((*ilay)->minR());
43  }
44 
46 
47  if (verbose::debugOut) {
48  for (vector<MagESector const*>::const_iterator isec = theESectors.begin();
49  isec != theESectors.end(); ++isec) {
50  cout << " Endcap sector at " << (*isec)->minPhi() << endl;
51  }
52  }
53 
54  //FIXME assume sectors are already sorted in phi
55  //FIXME: PeriodicBinFinderInPhi gets *center* of first bin
56  int nEBins = theESectors.size();
57  theEndcapBinFinder = new PeriodicBinFinderInPhi<float>(theESectors.front()->minPhi()+Geom::pi()/nEBins, nEBins);
58 
59 }
60 
62  delete theBarrelBinFinder;
63  delete theEndcapBinFinder;
64 
65  for (vector<MagBLayer const*>::const_iterator ilay = theBLayers.begin();
66  ilay != theBLayers.end(); ++ilay) {
67  delete (*ilay);
68  }
69 
70  for (vector<MagESector const*>::const_iterator ilay = theESectors.begin();
71  ilay != theESectors.end(); ++ilay) {
72  delete (*ilay);
73  }
74 }
75 
76 
77 // Return field vector at the specified global point
79  MagVolume const * v = nullptr;
80 
81 
82  v = findVolume(gp);
83  if (v!=nullptr) {
84  return v->fieldInTesla(gp);
85  }
86 
87  // Fall-back case: no volume found
88 
89  if (edm::isNotFinite(gp.mag())) {
90  LogWarning("InvalidInput") << "Input value invalid (not a number): " << gp << endl;
91 
92  } else {
93  LogWarning("MagneticField") << "MagGeometry::fieldInTesla: failed to find volume for " << gp << endl;
94  }
95  return GlobalVector();
96 }
97 
98 
99 // Linear search implementation (just for testing)
100 MagVolume const*
102 
103  MagVolume6Faces const* found = nullptr;
104 
105  if (inBarrel(gp)) { // Barrel
106  for (vector<MagVolume6Faces const*>::const_iterator v = theBVolumes.begin();
107  v!=theBVolumes.end(); ++v){
108  if ((*v)==nullptr) { //FIXME: remove this check
109  cout << endl << "***ERROR: MagGeometry::findVolume: MagVolume not set" << endl;
110  continue;
111  }
112  if ((*v)->inside(gp,tolerance)) {
113  found = (*v);
114  break;
115  }
116  }
117 
118  } else { // Endcaps
119  for (vector<MagVolume6Faces const*>::const_iterator v = theEVolumes.begin();
120  v!=theEVolumes.end(); ++v){
121  if ((*v)==nullptr) { //FIXME: remove this check
122  cout << endl << "***ERROR: MagGeometry::findVolume: MagVolume not set" << endl;
123  continue;
124  }
125  if ((*v)->inside(gp,tolerance)) {
126  found = (*v);
127  break;
128  }
129  }
130  }
131 
132  return found;
133 }
134 
135 // Use hierarchical structure for fast lookup.
136 MagVolume const*
138  // Check volume cache
139  auto lastVolumeCheck = lastVolume.load(std::memory_order_acquire);
140  if (lastVolumeCheck!=nullptr && lastVolumeCheck->inside(gp)){
141  return lastVolumeCheck;
142  }
143 
144  MagVolume const* result=nullptr;
145  if (inBarrel(gp)) { // Barrel
146  double R = gp.perp();
147  int bin = theBarrelBinFinder->binIndex(R);
148 
149  // Search up to 3 layers inwards. This may happen for very thin layers.
150  for (int bin1 = bin; bin1 >= max(0,bin-3); --bin1) {
151  if (verbose::debugOut) cout << "Trying layer at R " << theBLayers[bin1]->minR()
152  << " " << R << endl ;
153  result = theBLayers[bin1]->findVolume(gp, tolerance);
154  if (verbose::debugOut) cout << "***In blayer " << bin1-bin << " "
155  << (result==nullptr? " failed " : " OK ") <<endl;
156  if (result != nullptr) break;
157  }
158 
159  } else { // Endcaps
160  Geom::Phi<float> phi = gp.phi();
161  int bin = theEndcapBinFinder->binIndex(phi);
162  if (verbose::debugOut) cout << "Trying endcap sector at phi "
163  << theESectors[bin]->minPhi() << " " << phi << endl ;
164  result = theESectors[bin]->findVolume(gp, tolerance);
165  if (verbose::debugOut) cout << "***In guessed esector "
166  << (result==nullptr? " failed " : " OK ") <<endl;
167  }
168 
169 
170  if (result==nullptr && tolerance < 0.0001) {
171  // If search fails, retry with a 300 micron tolerance.
172  // This is a hack for thin gaps on air-iron boundaries,
173  // which will not be present anymore once surfaces are matched.
174  if (verbose::debugOut) cout << "Increasing the tolerance to 0.03" <<endl;
175  result = findVolume(gp, 0.03);
176  }
177 
178  if (cacheLastVolume) lastVolume.store(result,std::memory_order_release);
179 
180  return result;
181 }
182 
183 
184 
185 
187  float Z = fabs(gp.z());
188  float R = gp.perp();
189 
190  // FIXME: Get these dimensions from the builder.
191  if (geometryVersion>=120812) {
192  return (Z<350. ||
193  (R>172.4 && Z<633.29) ||
194  (R>308.735 && Z<662.01));
195  } else if (geometryVersion>=90812) { // FIXME no longer supported
196  return (Z<350. ||
197  (R>172.4 && Z<633.89) ||
198  (R>308.755 && Z<662.01));
199  } else { // versions 71212, 90322
200  return (Z<350. ||
201  (R>172.4 && Z<633.29) ||
202  (R>308.755 && Z<661.01));
203  }
204 }
205 
Surface::GlobalVector GlobalVector
Definition: MagGeometry.h:26
T perp() const
Definition: PV3DBase.h:72
constexpr bool isNotFinite(T x)
Definition: isFinite.h:9
const double tolerance
std::atomic< MagVolume const * > lastVolume
Definition: MagGeometry.h:65
#define nullptr
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
int binIndex(T phi) const override
returns an index in the valid range for the bin that contains phi
~MagGeometry()
Destructor.
Definition: MagGeometry.cc:61
bool inBarrel(const GlobalPoint &gp) const
Definition: MagGeometry.cc:186
MagVolume const * findVolume(const GlobalPoint &gp, double tolerance=0.) const
Find a volume.
Definition: MagGeometry.cc:137
T mag() const
Definition: PV3DBase.h:67
std::vector< MagESector const * > theESectors
Definition: MagGeometry.h:68
PeriodicBinFinderInPhi< float > const * theEndcapBinFinder
Definition: MagGeometry.h:75
T z() const
Definition: PV3DBase.h:64
MagVolume const * findVolume1(const GlobalPoint &gp, double tolerance=0.) const
Definition: MagGeometry.cc:101
int binIndex(T R) const override
Definition: MagBinFinders.h:66
std::vector< MagBLayer const * > theBLayers
Definition: MagGeometry.h:67
bin
set the eta bin as selection string.
std::vector< MagVolume6Faces const * > theBVolumes
Definition: MagGeometry.h:71
LocalVector fieldInTesla(const LocalPoint &lp) const
Definition: MagVolume.cc:11
HLT enums.
GlobalVector fieldInTesla(const GlobalPoint &gp) const
Return field vector at the specified global point.
Definition: MagGeometry.cc:78
MagGeometry(int geomVersion, const std::vector< MagBLayer * > &, const std::vector< MagESector * > &, const std::vector< MagVolume6Faces * > &, const std::vector< MagVolume6Faces * > &)
Constructor.
Definition: MagGeometry.cc:23
std::vector< MagVolume6Faces const * > theEVolumes
Definition: MagGeometry.h:72
static constexpr bool debugOut
Definition: MagVerbosity.h:17
constexpr double pi()
Definition: Pi.h:31
MagBinFinders::GeneralBinFinderInR< double > const * theBarrelBinFinder
Definition: MagGeometry.h:74
bool cacheLastVolume
Definition: MagGeometry.h:77
int geometryVersion
Definition: MagGeometry.h:78