CMS 3D CMS Logo

MagneticFieldMap.cc
Go to the documentation of this file.
4 
5 #include <iostream>
6 
8  : pMF_(pMF),
9  geometry_(myGeo),
10  bins(101),
11  fieldBarrelHistos(200, static_cast<std::vector<double> >(std::vector<double>(bins, static_cast<double>(0.)))),
12  fieldEndcapHistos(200, static_cast<std::vector<double> >(std::vector<double>(bins, static_cast<double>(0.)))),
13  fieldBarrelBinWidth(200, static_cast<double>(0.)),
14  fieldBarrelZMin(200, static_cast<double>(0.)),
15  fieldEndcapBinWidth(200, static_cast<double>(0.)),
16  fieldEndcapRMin(200, static_cast<double>(0.))
17 
18 {
19  std::list<TrackerLayer>::const_iterator cyliter;
20  std::list<TrackerLayer>::const_iterator cylitBeg = geometry_->cylinderBegin();
21  std::list<TrackerLayer>::const_iterator cylitEnd = geometry_->cylinderEnd();
22 
23  // Prepare the histograms
24  // std::cout << "Prepare magnetic field local database for FAMOS speed-up" << std::endl;
25  for (cyliter = cylitBeg; cyliter != cylitEnd; ++cyliter) {
26  int layer = cyliter->layerNumber();
27  // cout << " Fill Histogram " << hist << endl;
28 
29  // Cylinder bounds
30  double zmin = 0.;
31  double zmax;
32  double rmin = 0.;
33  double rmax;
34  if (cyliter->forward()) {
35  zmax = cyliter->disk()->position().z();
36  rmax = cyliter->disk()->outerRadius();
37  } else {
38  zmax = cyliter->cylinder()->bounds().length() / 2.;
39  rmax = cyliter->cylinder()->bounds().width() / 2. - cyliter->cylinder()->bounds().thickness() / 2.;
40  }
41 
42  // Histograms
43  double step;
44 
45  // Disk histogram characteristics
46  step = (rmax - rmin) / (bins - 1);
48  fieldEndcapRMin[layer] = rmin;
49 
50  // Fill the histo
51  int endcapBin = 0;
52  for (double radius = rmin + step / 2.; radius < rmax + step; radius += step) {
53  double field = inTeslaZ(GlobalPoint(radius, 0., zmax));
54  fieldEndcapHistos[layer][endcapBin++] = field;
55  }
56 
57  // Barrel Histogram characteritics
58  step = (zmax - zmin) / (bins - 1);
61 
62  // Fill the histo
63  int barrelBin = 0;
64  for (double zed = zmin + step / 2.; zed < zmax + step; zed += step) {
65  double field = inTeslaZ(GlobalPoint(rmax, 0., zed));
66  fieldBarrelHistos[layer][barrelBin++] = field;
67  }
68  }
69 }
70 
72  if (!pMF_) {
73  return GlobalVector(0., 0., 4.);
74  } else {
75  return pMF_->inTesla(gp);
76  }
77 }
78 
79 const GlobalVector MagneticFieldMap::inTesla(const TrackerLayer& aLayer, double coord, int success) const {
80  if (!pMF_) {
81  return GlobalVector(0., 0., 4.);
82  } else {
83  return GlobalVector(0., 0., inTeslaZ(aLayer, coord, success));
84  }
85 }
86 
87 const GlobalVector MagneticFieldMap::inKGauss(const GlobalPoint& gp) const { return inTesla(gp) * 10.; }
88 
89 const GlobalVector MagneticFieldMap::inInverseGeV(const GlobalPoint& gp) const { return inKGauss(gp) * 2.99792458e-4; }
90 
91 double MagneticFieldMap::inTeslaZ(const GlobalPoint& gp) const { return pMF_ ? pMF_->inTesla(gp).z() : 4.0; }
92 
93 double MagneticFieldMap::inTeslaZ(const TrackerLayer& aLayer, double coord, int success) const {
94  if (!pMF_) {
95  return 4.;
96  } else {
97  // Find the relevant histo
98  double theBinWidth;
99  double theXMin;
100  unsigned layer = aLayer.layerNumber();
101  const std::vector<double>* theHisto;
102 
103  if (success == 1) {
104  theHisto = theFieldBarrelHisto(layer);
105  theBinWidth = fieldBarrelBinWidth[layer];
106  theXMin = fieldBarrelZMin[layer];
107  } else {
108  theHisto = theFieldEndcapHisto(layer);
109  theBinWidth = fieldEndcapBinWidth[layer];
110  theXMin = fieldEndcapRMin[layer];
111  }
112 
113  // Find the relevant bin
114  double x = fabs(coord);
115  unsigned bin = (unsigned)((x - theXMin) / theBinWidth);
116  if (bin + 1 == (unsigned)bins)
117  bin -= 1; // Add a protection against coordinates near the layer edge
118  double x1 = theXMin + (bin - 0.5) * theBinWidth;
119  double x2 = x1 + theBinWidth;
120 
121  // Determine the field
122  double field1 = (*theHisto)[bin];
123  double field2 = (*theHisto)[bin + 1];
124 
125  return field1 + (field2 - field1) * (x - x1) / (x2 - x1);
126  }
127 }
128 
129 double MagneticFieldMap::inKGaussZ(const GlobalPoint& gp) const { return inTeslaZ(gp) / 10.; }
130 
131 double MagneticFieldMap::inInverseGeVZ(const GlobalPoint& gp) const { return inKGaussZ(gp) * 2.99792458e-4; }
Vector3DBase
Definition: Vector3DBase.h:8
MagneticField::inTesla
virtual GlobalVector inTesla(const GlobalPoint &gp) const =0
Field value ad specified global point, in Tesla.
MagneticFieldMap::theFieldBarrelHisto
const std::vector< double > * theFieldBarrelHisto(unsigned layer) const
Definition: MagneticFieldMap.h:39
MagneticFieldMap::inInverseGeV
const GlobalVector inInverseGeV(const GlobalPoint &) const
Definition: MagneticFieldMap.cc:89
step
step
Definition: StallMonitor.cc:94
TrackerInteractionGeometry::cylinderEnd
std::list< TrackerLayer >::const_iterator cylinderEnd() const
Returns the last pointer in the cylinder list.
Definition: TrackerInteractionGeometry.h:40
testProducerWithPsetDescEmpty_cfi.x2
x2
Definition: testProducerWithPsetDescEmpty_cfi.py:28
MagneticFieldMap::inTeslaZ
double inTeslaZ(const GlobalPoint &) const
Definition: MagneticFieldMap.cc:91
DDAxes::x
GlobalVector
Global3DVector GlobalVector
Definition: GlobalVector.h:10
SiStripMonitorCluster_cfi.zmin
zmin
Definition: SiStripMonitorCluster_cfi.py:200
MagneticFieldMap::fieldBarrelHistos
std::vector< std::vector< double > > fieldBarrelHistos
Definition: MagneticFieldMap.h:44
MagneticFieldMap::fieldEndcapBinWidth
std::vector< double > fieldEndcapBinWidth
Definition: MagneticFieldMap.h:48
PV3DBase::z
T z() const
Definition: PV3DBase.h:61
testProducerWithPsetDescEmpty_cfi.x1
x1
Definition: testProducerWithPsetDescEmpty_cfi.py:33
MagneticFieldMap::fieldBarrelBinWidth
std::vector< double > fieldBarrelBinWidth
Definition: MagneticFieldMap.h:46
SiStripMonitorCluster_cfi.zmax
zmax
Definition: SiStripMonitorCluster_cfi.py:201
TrackerInteractionGeometry.h
summarizeEdmComparisonLogfiles.success
success
Definition: summarizeEdmComparisonLogfiles.py:114
MagneticFieldMap::fieldBarrelZMin
std::vector< double > fieldBarrelZMin
Definition: MagneticFieldMap.h:47
GlobalPoint
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
MagneticFieldMap::inInverseGeVZ
double inInverseGeVZ(const GlobalPoint &) const
Definition: MagneticFieldMap.cc:131
Point3DBase< float, GlobalTag >
TrackerInteractionGeometry
Definition: TrackerInteractionGeometry.h:23
MagneticFieldMap::fieldEndcapHistos
std::vector< std::vector< double > > fieldEndcapHistos
Definition: MagneticFieldMap.h:45
phase1PixelTopology::layer
constexpr std::array< uint8_t, layerIndexSize > layer
Definition: phase1PixelTopology.h:99
runTauDisplay.gp
gp
Definition: runTauDisplay.py:431
MagneticFieldMap.h
TrackerLayer
Definition: TrackerLayer.h:13
TrackerInteractionGeometry::cylinderBegin
std::list< TrackerLayer >::const_iterator cylinderBegin() const
Returns the first pointer in the cylinder list.
Definition: TrackerInteractionGeometry.h:37
TrackerLayer::layerNumber
unsigned int layerNumber() const
Returns the layer number.
Definition: TrackerLayer.h:78
MagneticFieldMap::inKGauss
const GlobalVector inKGauss(const GlobalPoint &) const
Definition: MagneticFieldMap.cc:87
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
MagneticFieldMap::pMF_
const MagneticField * pMF_
Definition: MagneticFieldMap.h:41
MagneticField.h
MagneticFieldMap::MagneticFieldMap
MagneticFieldMap(const MagneticField *pmF, const TrackerInteractionGeometry *myGeo)
Definition: MagneticFieldMap.cc:7
newFWLiteAna.bin
bin
Definition: newFWLiteAna.py:161
MagneticFieldMap::fieldEndcapRMin
std::vector< double > fieldEndcapRMin
Definition: MagneticFieldMap.h:49
std
Definition: JetResolutionObject.h:76
CosmicsPD_Skims.radius
radius
Definition: CosmicsPD_Skims.py:135
MagneticFieldMap::geometry_
const TrackerInteractionGeometry * geometry_
Definition: MagneticFieldMap.h:42
MagneticFieldMap::inTesla
const GlobalVector inTesla(const GlobalPoint &) const
Definition: MagneticFieldMap.cc:71
MagneticFieldMap::inKGaussZ
double inKGaussZ(const GlobalPoint &) const
Definition: MagneticFieldMap.cc:129
trigObjTnPSource_cfi.bins
bins
Definition: trigObjTnPSource_cfi.py:20
MagneticFieldMap::theFieldEndcapHisto
const std::vector< double > * theFieldEndcapHisto(unsigned layer) const
Definition: MagneticFieldMap.h:37
MagneticFieldMap::bins
unsigned bins
Definition: MagneticFieldMap.h:43
MagneticField
Definition: MagneticField.h:19