CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Private Member Functions | Private Attributes | Friends
MagGeometry Class Reference

#include <MagGeometry.h>

Public Types

typedef Surface::GlobalPoint GlobalPoint
 
typedef Surface::GlobalVector GlobalVector
 

Public Member Functions

const std::vector< MagVolume6Faces const * > & barrelVolumes () const
 
const std::vector< MagVolume6Faces const * > & endcapVolumes () const
 
GlobalVector fieldInTesla (const GlobalPoint &gp) const
 Return field vector at the specified global point. More...
 
MagVolume const * findVolume (const GlobalPoint &gp, double tolerance=0.) const
 Find a volume. More...
 
 MagGeometry (int geomVersion, const std::vector< MagBLayer * > &, const std::vector< MagESector * > &, const std::vector< MagVolume6Faces * > &, const std::vector< MagVolume6Faces * > &)
 Constructor. More...
 
 MagGeometry (int geomVersion, const std::vector< MagBLayer const * > &, const std::vector< MagESector const * > &, const std::vector< MagVolume6Faces const * > &, const std::vector< MagVolume6Faces const * > &)
 
 ~MagGeometry ()
 Destructor. More...
 

Private Member Functions

MagVolume const * findVolume1 (const GlobalPoint &gp, double tolerance=0.) const
 
bool inBarrel (const GlobalPoint &gp) const
 

Private Attributes

bool cacheLastVolume
 
int geometryVersion
 
const int me_
 
MagBinFinders::GeneralBinFinderInR< double > const * theBarrelBinFinder
 
double theBarrelRsq1
 
double theBarrelRsq2
 
double theBarrelZ0
 
double theBarrelZ1
 
double theBarrelZ2
 
std::vector< MagBLayer const * > theBLayers
 
std::vector< MagVolume6Faces const * > theBVolumes
 
PeriodicBinFinderInPhi< float > const * theEndcapBinFinder
 
std::vector< MagESector const * > theESectors
 
std::vector< MagVolume6Faces const * > theEVolumes
 

Friends

class MagGeometryExerciser
 

Detailed Description

Entry point to the geometry of magnetic volumes.

Author
N. Amapane - INFN Torino

Definition at line 23 of file MagGeometry.h.

Member Typedef Documentation

◆ GlobalPoint

Definition at line 26 of file MagGeometry.h.

◆ GlobalVector

Definition at line 25 of file MagGeometry.h.

Constructor & Destructor Documentation

◆ MagGeometry() [1/2]

MagGeometry::MagGeometry ( int  geomVersion,
const std::vector< MagBLayer * > &  tbl,
const std::vector< MagESector * > &  tes,
const std::vector< MagVolume6Faces * > &  tbv,
const std::vector< MagVolume6Faces * > &  tev 
)

Constructor.

Definition at line 32 of file MagGeometry.cc.

37  : MagGeometry(geomVersion,
38  reinterpret_cast<std::vector<MagBLayer const*> const&>(tbl),
39  reinterpret_cast<std::vector<MagESector const*> const&>(tes),
40  reinterpret_cast<std::vector<MagVolume6Faces const*> const&>(tbv),
41  reinterpret_cast<std::vector<MagVolume6Faces const*> const&>(tev)) {}

◆ MagGeometry() [2/2]

MagGeometry::MagGeometry ( int  geomVersion,
const std::vector< MagBLayer const * > &  tbl,
const std::vector< MagESector const * > &  tes,
const std::vector< MagVolume6Faces const * > &  tbv,
const std::vector< MagVolume6Faces const * > &  tev 
)

Definition at line 43 of file MagGeometry.cc.

48  : me_(++instanceCounter),
49  theBLayers(tbl),
50  theESectors(tes),
51  theBVolumes(tbv),
52  theEVolumes(tev),
53  cacheLastVolume(true),
54  geometryVersion(geomVersion) {
55  vector<double> rBorders;
56 
57  for (vector<MagBLayer const*>::const_iterator ilay = theBLayers.begin(); ilay != theBLayers.end(); ++ilay) {
58  LogTrace("MagGeoBuilder") << " Barrel layer at " << (*ilay)->minR() << endl;
59  //FIXME assume layers are already sorted in minR
60  rBorders.push_back((*ilay)->minR() * (*ilay)->minR());
61  }
62 
64 
65 #ifdef EDM_ML_DEBUG
66  for (vector<MagESector const*>::const_iterator isec = theESectors.begin(); isec != theESectors.end(); ++isec) {
67  LogTrace("MagGeoBuilder") << " Endcap sector at " << (*isec)->minPhi() << endl;
68  }
69 #endif
70 
71  //FIXME assume sectors are already sorted in phi
72  //FIXME: PeriodicBinFinderInPhi gets *center* of first bin
73  int nEBins = theESectors.size();
74  if (nEBins > 0)
75  theEndcapBinFinder = new PeriodicBinFinderInPhi<float>(theESectors.front()->minPhi() + Geom::pi() / nEBins, nEBins);
76 
77  // Compute barrel dimensions based on geometry version
78  // FIXME: it would be nice to derive these from the actual geometry in the builder, possibly adding some specification to the geometry.
79  switch (geomVersion >= 120812 ? 0 : (geomVersion >= 90812 ? 1 : 2)) {
80  case 0: // since 120812
81  theBarrelRsq1 = 172.400 * 172.400;
82  theBarrelRsq2 = 308.735 * 308.735;
83  theBarrelZ0 = 350.000;
84  theBarrelZ1 = 633.290;
85  theBarrelZ2 = 662.010;
86  break;
87  case 1: // version 90812 (no longer in use)
88  theBarrelRsq1 = 172.400 * 172.400;
89  theBarrelRsq2 = 308.755 * 308.755;
90  theBarrelZ0 = 350.000;
91  theBarrelZ1 = 633.890;
92  theBarrelZ2 = 662.010;
93  break;
94  case 2: // versions 71212, 90322
95  theBarrelRsq1 = 172.400 * 172.400;
96  theBarrelRsq2 = 308.755 * 308.755;
97  theBarrelZ0 = 350.000;
98  theBarrelZ1 = 633.290;
99  theBarrelZ2 = 661.010;
100  break;
101  }
102 
103  LogTrace("MagGeometry_cache") << "*** In MagGeometry ctor: me_=" << me_ << " instanceCounter=" << instanceCounter
104  << endl;
105 }

References LogTrace, me_, Geom::pi(), theBarrelBinFinder, theBarrelRsq1, theBarrelRsq2, theBarrelZ0, theBarrelZ1, theBarrelZ2, theBLayers, theEndcapBinFinder, and theESectors.

◆ ~MagGeometry()

MagGeometry::~MagGeometry ( )

Destructor.

Definition at line 107 of file MagGeometry.cc.

107  {
108  if (theBarrelBinFinder != nullptr)
109  delete theBarrelBinFinder;
110  if (theEndcapBinFinder != nullptr)
111  delete theEndcapBinFinder;
112 
113  for (vector<MagBLayer const*>::const_iterator ilay = theBLayers.begin(); ilay != theBLayers.end(); ++ilay) {
114  delete (*ilay);
115  }
116 
117  for (vector<MagESector const*>::const_iterator ilay = theESectors.begin(); ilay != theESectors.end(); ++ilay) {
118  delete (*ilay);
119  }
120 }

References theBarrelBinFinder, theBLayers, theEndcapBinFinder, and theESectors.

Member Function Documentation

◆ barrelVolumes()

const std::vector<MagVolume6Faces const*>& MagGeometry::barrelVolumes ( ) const
inline

Definition at line 50 of file MagGeometry.h.

50 { return theBVolumes; }

References theBVolumes.

◆ endcapVolumes()

const std::vector<MagVolume6Faces const*>& MagGeometry::endcapVolumes ( ) const
inline

Definition at line 51 of file MagGeometry.h.

51 { return theEVolumes; }

References theEVolumes.

◆ fieldInTesla()

GlobalVector MagGeometry::fieldInTesla ( const GlobalPoint gp) const

Return field vector at the specified global point.

Definition at line 123 of file MagGeometry.cc.

123  {
124  MagVolume const* v = nullptr;
125 
126  v = findVolume(gp);
127  if (v != nullptr) {
128  return v->fieldInTesla(gp);
129  }
130 
131  // Fall-back case: no volume found
132 
133  if (edm::isNotFinite(gp.mag())) {
134  LogWarning("MagneticField") << "Input value invalid (not a number): " << gp << endl;
135 
136  } else {
137  LogWarning("MagneticField") << "MagGeometry::fieldInTesla: failed to find volume for " << gp << endl;
138  }
139  return GlobalVector();
140 }

References findVolume(), runTauDisplay::gp, edm::isNotFinite(), and findQualityFiles::v.

Referenced by VolumeBasedMagneticField::inTesla(), and VolumeBasedMagneticField::inTeslaUnchecked().

◆ findVolume()

MagVolume const * MagGeometry::findVolume ( const GlobalPoint gp,
double  tolerance = 0. 
) const

Find a volume.

Definition at line 184 of file MagGeometry.cc.

184  {
185  // Clear volume cache if this is a new instance
186  if (me_ != localInstance) {
187  LogTrace("MagGeometry_cache") << "*** In MagGeometry::findVolume resetting cache: me=" << me_
188  << " localInstance=" << localInstance << endl;
189  localInstance = me_;
190  lastVolume = nullptr;
191  }
192 
193  if (lastVolume != nullptr && lastVolume->inside(gp)) {
194  return lastVolume;
195  }
196 
197  MagVolume const* result = nullptr;
198  if (inBarrel(gp)) { // Barrel
199  double aRsq = gp.perp2();
200  int bin = theBarrelBinFinder->binIndex(aRsq);
201 
202  // Search up to 3 layers inwards. This may happen for very thin layers.
203  for (int bin1 = bin; bin1 >= max(0, bin - 3); --bin1) {
204  LogTrace("MagGeometry") << "Trying layer at R " << theBLayers[bin1]->minR() << " " << sqrt(aRsq) << endl;
205  result = theBLayers[bin1]->findVolume(gp, tolerance);
206  LogTrace("MagGeometry") << "***In blayer " << bin1 - bin << " " << (result == nullptr ? " failed " : " OK ")
207  << endl;
208  if (result != nullptr)
209  break;
210  }
211 
212  } else { // Endcaps
213  Geom::Phi<float> phi = gp.phi();
214  if (theEndcapBinFinder != nullptr && !theESectors.empty()) {
216  LogTrace("MagGeometry") << "Trying endcap sector at phi " << theESectors[bin]->minPhi() << " " << phi << endl;
217  result = theESectors[bin]->findVolume(gp, tolerance);
218  LogTrace("MagGeometry") << "***In guessed esector " << (result == nullptr ? " failed " : " OK ") << endl;
219  } else
220  edm::LogError("MagGeometry") << "Endcap empty";
221  }
222 
223  if (result == nullptr && tolerance < 0.0001) {
224  // If search fails, retry with a 300 micron tolerance.
225  // This is a hack for thin gaps on air-iron boundaries,
226  // which will not be present anymore once surfaces are matched.
227  LogTrace("MagGeometry") << "Increasing the tolerance to 0.03" << endl;
228  result = findVolume(gp, 0.03);
229  }
230 
231  if (cacheLastVolume)
232  lastVolume = result;
233 
234  return result;
235 }

References newFWLiteAna::bin, PeriodicBinFinderInPhi< T >::binIndex(), MagBinFinders::GeneralBinFinderInR< T >::binIndex(), cacheLastVolume, runTauDisplay::gp, inBarrel(), LogTrace, SiStripPI::max, me_, phi, mps_fire::result, mathSSE::sqrt(), theBarrelBinFinder, theBLayers, theEndcapBinFinder, theESectors, and tolerance.

Referenced by fieldInTesla(), and VolumeBasedMagneticField::findVolume().

◆ findVolume1()

MagVolume const * MagGeometry::findVolume1 ( const GlobalPoint gp,
double  tolerance = 0. 
) const
private

Definition at line 143 of file MagGeometry.cc.

143  {
144  MagVolume6Faces const* found = nullptr;
145 
146  int errCnt = 0;
147  if (inBarrel(gp)) { // Barrel
148  for (vector<MagVolume6Faces const*>::const_iterator v = theBVolumes.begin(); v != theBVolumes.end(); ++v) {
149  if ((*v) == nullptr) { //FIXME: remove this check
150  LogError("MagGeometry") << endl << "***ERROR: MagGeometry::findVolume: MagVolume for barrel not set" << endl;
151  ++errCnt;
152  if (errCnt < 3)
153  continue;
154  else
155  break;
156  }
157  if ((*v)->inside(gp, tolerance)) {
158  found = (*v);
159  break;
160  }
161  }
162 
163  } else { // Endcaps
164  for (vector<MagVolume6Faces const*>::const_iterator v = theEVolumes.begin(); v != theEVolumes.end(); ++v) {
165  if ((*v) == nullptr) { //FIXME: remove this check
166  LogError("MagGeometry") << endl << "***ERROR: MagGeometry::findVolume: MagVolume for endcap not set" << endl;
167  ++errCnt;
168  if (errCnt < 3)
169  continue;
170  else
171  break;
172  }
173  if ((*v)->inside(gp, tolerance)) {
174  found = (*v);
175  break;
176  }
177  }
178  }
179 
180  return found;
181 }

References newFWLiteAna::found, runTauDisplay::gp, inBarrel(), theBVolumes, theEVolumes, tolerance, and findQualityFiles::v.

◆ inBarrel()

bool MagGeometry::inBarrel ( const GlobalPoint gp) const
private

Definition at line 237 of file MagGeometry.cc.

237  {
238  double aZ = fabs(gp.z());
239  double aRsq = gp.perp2();
240 
241  return ((aZ < theBarrelZ0) || (aZ < theBarrelZ1 && aRsq > theBarrelRsq1) ||
242  (aZ < theBarrelZ2 && aRsq > theBarrelRsq2));
243 }

References runTauDisplay::gp, theBarrelRsq1, theBarrelRsq2, and theBarrelZ0.

Referenced by findVolume(), and findVolume1().

Friends And Related Function Documentation

◆ MagGeometryExerciser

friend class MagGeometryExerciser
friend

Definition at line 54 of file MagGeometry.h.

Member Data Documentation

◆ cacheLastVolume

bool MagGeometry::cacheLastVolume
private

Definition at line 73 of file MagGeometry.h.

Referenced by findVolume().

◆ geometryVersion

int MagGeometry::geometryVersion
private

Definition at line 74 of file MagGeometry.h.

◆ me_

const int MagGeometry::me_
private

Definition at line 61 of file MagGeometry.h.

Referenced by findVolume(), and MagGeometry().

◆ theBarrelBinFinder

MagBinFinders::GeneralBinFinderInR<double> const* MagGeometry::theBarrelBinFinder
private

Definition at line 70 of file MagGeometry.h.

Referenced by findVolume(), MagGeometry(), and ~MagGeometry().

◆ theBarrelRsq1

double MagGeometry::theBarrelRsq1
private

Definition at line 77 of file MagGeometry.h.

Referenced by inBarrel(), and MagGeometry().

◆ theBarrelRsq2

double MagGeometry::theBarrelRsq2
private

Definition at line 78 of file MagGeometry.h.

Referenced by inBarrel(), and MagGeometry().

◆ theBarrelZ0

double MagGeometry::theBarrelZ0
private

Definition at line 79 of file MagGeometry.h.

Referenced by inBarrel(), and MagGeometry().

◆ theBarrelZ1

double MagGeometry::theBarrelZ1
private

Definition at line 80 of file MagGeometry.h.

Referenced by MagGeometry().

◆ theBarrelZ2

double MagGeometry::theBarrelZ2
private

Definition at line 81 of file MagGeometry.h.

Referenced by MagGeometry().

◆ theBLayers

std::vector<MagBLayer const*> MagGeometry::theBLayers
private

Definition at line 63 of file MagGeometry.h.

Referenced by findVolume(), MagGeometry(), and ~MagGeometry().

◆ theBVolumes

std::vector<MagVolume6Faces const*> MagGeometry::theBVolumes
private

Definition at line 67 of file MagGeometry.h.

Referenced by barrelVolumes(), and findVolume1().

◆ theEndcapBinFinder

PeriodicBinFinderInPhi<float> const* MagGeometry::theEndcapBinFinder
private

Definition at line 71 of file MagGeometry.h.

Referenced by findVolume(), MagGeometry(), and ~MagGeometry().

◆ theESectors

std::vector<MagESector const*> MagGeometry::theESectors
private

Definition at line 64 of file MagGeometry.h.

Referenced by findVolume(), MagGeometry(), and ~MagGeometry().

◆ theEVolumes

std::vector<MagVolume6Faces const*> MagGeometry::theEVolumes
private

Definition at line 68 of file MagGeometry.h.

Referenced by endcapVolumes(), and findVolume1().

MagGeometry::geometryVersion
int geometryVersion
Definition: MagGeometry.h:74
MagGeometry::theEVolumes
std::vector< MagVolume6Faces const * > theEVolumes
Definition: MagGeometry.h:68
MagGeometry::GlobalVector
Surface::GlobalVector GlobalVector
Definition: MagGeometry.h:25
MagGeometry::theBarrelBinFinder
MagBinFinders::GeneralBinFinderInR< double > const * theBarrelBinFinder
Definition: MagGeometry.h:70
edm::isNotFinite
constexpr bool isNotFinite(T x)
Definition: isFinite.h:9
MagGeometry::theBarrelRsq1
double theBarrelRsq1
Definition: MagGeometry.h:77
MagGeometry::theBarrelZ0
double theBarrelZ0
Definition: MagGeometry.h:79
findQualityFiles.v
v
Definition: findQualityFiles.py:179
watchdog.const
const
Definition: watchdog.py:83
newFWLiteAna.found
found
Definition: newFWLiteAna.py:118
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
MagGeometry::theEndcapBinFinder
PeriodicBinFinderInPhi< float > const * theEndcapBinFinder
Definition: MagGeometry.h:71
MagBinFinders::GeneralBinFinderInR::binIndex
int binIndex(T R) const override
Definition: MagBinFinders.h:62
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
MagGeometry::theBarrelZ2
double theBarrelZ2
Definition: MagGeometry.h:81
Geom::pi
constexpr double pi()
Definition: Pi.h:31
MagVolume6Faces
Definition: MagVolume6Faces.h:23
MagGeometry::theESectors
std::vector< MagESector const * > theESectors
Definition: MagGeometry.h:64
runTauDisplay.gp
gp
Definition: runTauDisplay.py:431
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
MagVolume
Definition: MagVolume.h:13
tolerance
const double tolerance
Definition: HGCalGeomParameters.cc:29
Geom::Phi< float >
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
MagGeometry::theBarrelRsq2
double theBarrelRsq2
Definition: MagGeometry.h:78
newFWLiteAna.bin
bin
Definition: newFWLiteAna.py:161
MagGeometry::MagGeometry
MagGeometry(int geomVersion, const std::vector< MagBLayer * > &, const std::vector< MagESector * > &, const std::vector< MagVolume6Faces * > &, const std::vector< MagVolume6Faces * > &)
Constructor.
Definition: MagGeometry.cc:32
DDAxes::phi
MagBinFinders::GeneralBinFinderInR< double >
MagGeometry::theBLayers
std::vector< MagBLayer const * > theBLayers
Definition: MagGeometry.h:63
PeriodicBinFinderInPhi< float >
MagGeometry::theBVolumes
std::vector< MagVolume6Faces const * > theBVolumes
Definition: MagGeometry.h:67
MagGeometry::me_
const int me_
Definition: MagGeometry.h:61
MagGeometry::theBarrelZ1
double theBarrelZ1
Definition: MagGeometry.h:80
PeriodicBinFinderInPhi::binIndex
int binIndex(T phi) const override
returns an index in the valid range for the bin that contains phi
Definition: PeriodicBinFinderInPhi.h:25
mps_fire.result
result
Definition: mps_fire.py:311
LogTrace
#define LogTrace(id)
Definition: MessageLogger.h:234
MagGeometry::findVolume
MagVolume const * findVolume(const GlobalPoint &gp, double tolerance=0.) const
Find a volume.
Definition: MagGeometry.cc:184
MagGeometry::inBarrel
bool inBarrel(const GlobalPoint &gp) const
Definition: MagGeometry.cc:237
MagGeometry::cacheLastVolume
bool cacheLastVolume
Definition: MagGeometry.h:73