File indexing completed on 2024-04-06 12:11:47
0001 #include "FWCore/Framework/interface/Frameworkfwd.h"
0002 #include "FWCore/Framework/interface/one/EDProducer.h"
0003 #include "FWCore/Framework/interface/ESHandle.h"
0004 #include "FWCore/Framework/interface/MakerMacros.h"
0005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0006 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
0007 #include "DataFormats/GeometryVector/interface/GlobalVector.h"
0008 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
0009 #include "MagneticField/Engine/interface/MagneticField.h"
0010 #include <iostream>
0011
0012 class MFProducer : public edm::one::EDProducer<> {
0013 public:
0014 explicit MFProducer(const edm::ParameterSet&);
0015 ~MFProducer(void) override;
0016
0017 private:
0018 void beginJob(void) override;
0019 void produce(edm::Event&, const edm::EventSetup&) override;
0020 void endJob(void) override;
0021 void evaluate(const double point[3], double field[3]) const;
0022 unsigned m_mapDensityX;
0023 unsigned m_mapDensityY;
0024 unsigned m_mapDensityZ;
0025 double m_minX;
0026 double m_maxX;
0027 double m_minY;
0028 double m_maxY;
0029 double m_minZ;
0030 double m_maxZ;
0031 double m_xBaseDir;
0032 double m_yBaseDir;
0033 double m_zBaseDir;
0034 bool m_valid;
0035 const edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> m_mfToken;
0036 edm::ESHandle<MagneticField> m_mf;
0037 };
0038
0039 MFProducer::MFProducer(const edm::ParameterSet& iPset) : m_valid(false), m_mfToken(esConsumes()) {
0040 m_mapDensityX = iPset.getUntrackedParameter<unsigned>("mapDensityX", 10);
0041 m_mapDensityY = iPset.getUntrackedParameter<unsigned>("mapDensityY", 10);
0042 m_mapDensityZ = iPset.getUntrackedParameter<unsigned>("mapDensityY", 10);
0043 m_minX = iPset.getUntrackedParameter<double>("minX", -18.0);
0044 m_maxX = iPset.getUntrackedParameter<double>("maxX", 18.0);
0045 m_minY = iPset.getUntrackedParameter<double>("minY", -18.0);
0046 m_maxY = iPset.getUntrackedParameter<double>("maxY", 18.0);
0047 m_minZ = iPset.getUntrackedParameter<double>("minZ", -18.0);
0048 m_maxZ = iPset.getUntrackedParameter<double>("maxZ", 18.0);
0049
0050 m_xBaseDir = (m_maxX - m_minX) / m_mapDensityX;
0051 m_yBaseDir = (m_maxY - m_minY) / m_mapDensityY;
0052 m_zBaseDir = (m_maxZ - m_minZ) / m_mapDensityZ;
0053 }
0054
0055 MFProducer::~MFProducer(void) {}
0056
0057 void MFProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0058 m_mf = iSetup.getHandle(m_mfToken);
0059 m_mf.isValid() ? m_valid = true : m_valid = false;
0060
0061 for (unsigned i = 0; i <= m_mapDensityX; ++i) {
0062 for (unsigned j = 0; j <= m_mapDensityY; ++j) {
0063
0064 double x = m_minX + m_xBaseDir * i;
0065 double y = m_minY + m_yBaseDir * j;
0066 double z = 0.;
0067 double pt[3] = {x, y, z};
0068 double val[3];
0069 evaluate(pt, val);
0070 std::cout << "(" << x << ", " << y << ", " << z << ") " << val[0] << ":" << val[1] << ":" << val[2] << "; ";
0071 }
0072 std::cout << std::endl;
0073 }
0074 }
0075
0076 void MFProducer::evaluate(const double point[3], double field[3]) const {
0077 GlobalVector b = m_mf->inTesla(GlobalPoint(point[0], point[1], point[2]));
0078
0079 field[0] = b.x();
0080 field[1] = b.y();
0081 field[2] = b.z();
0082 }
0083
0084 void MFProducer::beginJob(void) {}
0085
0086 void MFProducer::endJob(void) {}
0087
0088 DEFINE_FWK_MODULE(MFProducer);