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...
 
bool isZSymmetric () const
 
 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
 
std::atomic< MagVolume const * > lastVolume
 
MagBinFinders::GeneralBinFinderInR< double > const * theBarrelBinFinder
 
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

Definition at line 27 of file MagGeometry.h.

Definition at line 26 of file MagGeometry.h.

Constructor & Destructor Documentation

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 23 of file MagGeometry.cc.

26  :
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)) {}
MagGeometry(int geomVersion, const std::vector< MagBLayer * > &, const std::vector< MagESector * > &, const std::vector< MagVolume6Faces * > &, const std::vector< MagVolume6Faces * > &)
Constructor.
Definition: MagGeometry.cc:23
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 30 of file MagGeometry.cc.

References gather_cfg::cout, verbose::debugOut, Geom::pi(), theBarrelBinFinder, theBLayers, theEndcapBinFinder, and theESectors.

33  :
34  lastVolume(nullptr), theBLayers(tbl), theESectors(tes), theBVolumes(tbv), theEVolumes(tev), cacheLastVolume(true), geometryVersion(geomVersion)
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 }
std::atomic< MagVolume const * > lastVolume
Definition: MagGeometry.h:65
std::vector< MagESector const * > theESectors
Definition: MagGeometry.h:68
PeriodicBinFinderInPhi< float > const * theEndcapBinFinder
Definition: MagGeometry.h:75
std::vector< MagBLayer const * > theBLayers
Definition: MagGeometry.h:67
std::vector< MagVolume6Faces const * > theBVolumes
Definition: MagGeometry.h:71
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
MagGeometry::~MagGeometry ( )

Destructor.

Definition at line 61 of file MagGeometry.cc.

References theBarrelBinFinder, theBLayers, theEndcapBinFinder, and theESectors.

61  {
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 }
std::vector< MagESector const * > theESectors
Definition: MagGeometry.h:68
PeriodicBinFinderInPhi< float > const * theEndcapBinFinder
Definition: MagGeometry.h:75
std::vector< MagBLayer const * > theBLayers
Definition: MagGeometry.h:67
MagBinFinders::GeneralBinFinderInR< double > const * theBarrelBinFinder
Definition: MagGeometry.h:74

Member Function Documentation

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

Definition at line 52 of file MagGeometry.h.

References theBVolumes.

52 {return theBVolumes;}
std::vector< MagVolume6Faces const * > theBVolumes
Definition: MagGeometry.h:71
const std::vector<MagVolume6Faces const*>& MagGeometry::endcapVolumes ( ) const
inline

Definition at line 53 of file MagGeometry.h.

References theEVolumes.

53 {return theEVolumes;}
std::vector< MagVolume6Faces const * > theEVolumes
Definition: MagGeometry.h:72
GlobalVector MagGeometry::fieldInTesla ( const GlobalPoint gp) const

Return field vector at the specified global point.

Definition at line 78 of file MagGeometry.cc.

References MagVolume::fieldInTesla(), findVolume(), edm::isNotFinite(), PV3DBase< T, PVType, FrameType >::mag(), and findQualityFiles::v.

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

78  {
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 }
Surface::GlobalVector GlobalVector
Definition: MagGeometry.h:26
constexpr bool isNotFinite(T x)
Definition: isFinite.h:9
MagVolume const * findVolume(const GlobalPoint &gp, double tolerance=0.) const
Find a volume.
Definition: MagGeometry.cc:137
T mag() const
Definition: PV3DBase.h:67
LocalVector fieldInTesla(const LocalPoint &lp) const
Definition: MagVolume.cc:11
MagVolume const * MagGeometry::findVolume ( const GlobalPoint gp,
double  tolerance = 0. 
) const

Find a volume.

Definition at line 137 of file MagGeometry.cc.

References stringResolutionProvider_cfi::bin, PeriodicBinFinderInPhi< T >::binIndex(), MagBinFinders::GeneralBinFinderInR< T >::binIndex(), cacheLastVolume, gather_cfg::cout, verbose::debugOut, inBarrel(), lastVolume, SiStripPI::max, PV3DBase< T, PVType, FrameType >::perp(), phi, PV3DBase< T, PVType, FrameType >::phi(), dttmaxenums::R, mps_fire::result, theBarrelBinFinder, theBLayers, theEndcapBinFinder, and theESectors.

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

137  {
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 }
T perp() const
Definition: PV3DBase.h:72
const double tolerance
std::atomic< MagVolume const * > lastVolume
Definition: MagGeometry.h:65
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
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
std::vector< MagESector const * > theESectors
Definition: MagGeometry.h:68
PeriodicBinFinderInPhi< float > const * theEndcapBinFinder
Definition: MagGeometry.h:75
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.
static constexpr bool debugOut
Definition: MagVerbosity.h:17
MagBinFinders::GeneralBinFinderInR< double > const * theBarrelBinFinder
Definition: MagGeometry.h:74
bool cacheLastVolume
Definition: MagGeometry.h:77
MagVolume const * MagGeometry::findVolume1 ( const GlobalPoint gp,
double  tolerance = 0. 
) const
private

Definition at line 101 of file MagGeometry.cc.

References gather_cfg::cout, runEdmFileComparison::found, inBarrel(), theBVolumes, theEVolumes, and findQualityFiles::v.

101  {
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 }
const double tolerance
bool inBarrel(const GlobalPoint &gp) const
Definition: MagGeometry.cc:186
std::vector< MagVolume6Faces const * > theBVolumes
Definition: MagGeometry.h:71
std::vector< MagVolume6Faces const * > theEVolumes
Definition: MagGeometry.h:72
bool MagGeometry::inBarrel ( const GlobalPoint gp) const
private

Definition at line 186 of file MagGeometry.cc.

References geometryVersion, PV3DBase< T, PVType, FrameType >::perp(), dttmaxenums::R, DOFs::Z, and PV3DBase< T, PVType, FrameType >::z().

Referenced by findVolume(), and findVolume1().

186  {
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 }
T perp() const
Definition: PV3DBase.h:72
T z() const
Definition: PV3DBase.h:64
int geometryVersion
Definition: MagGeometry.h:78
bool MagGeometry::isZSymmetric ( ) const
inline

Definition at line 49 of file MagGeometry.h.

Referenced by VolumeBasedMagneticField::isZSymmetric().

49 {return false;}

Friends And Related Function Documentation

friend class MagGeometryExerciser
friend

Definition at line 57 of file MagGeometry.h.

Member Data Documentation

bool MagGeometry::cacheLastVolume
private

Definition at line 77 of file MagGeometry.h.

Referenced by findVolume().

int MagGeometry::geometryVersion
private

Definition at line 78 of file MagGeometry.h.

Referenced by inBarrel().

std::atomic<MagVolume const*> MagGeometry::lastVolume
mutableprivate

Definition at line 65 of file MagGeometry.h.

Referenced by findVolume().

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

Definition at line 74 of file MagGeometry.h.

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

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

Definition at line 67 of file MagGeometry.h.

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

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

Definition at line 71 of file MagGeometry.h.

Referenced by barrelVolumes(), and findVolume1().

PeriodicBinFinderInPhi<float> const* MagGeometry::theEndcapBinFinder
private

Definition at line 75 of file MagGeometry.h.

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

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

Definition at line 68 of file MagGeometry.h.

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

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

Definition at line 72 of file MagGeometry.h.

Referenced by endcapVolumes(), and findVolume1().