CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/Fireworks/Geometry/plugins/MFProducer.cc

Go to the documentation of this file.
00001 #include "FWCore/Framework/interface/Frameworkfwd.h"
00002 #include "FWCore/Framework/interface/EDProducer.h"
00003 #include "FWCore/Framework/interface/ESHandle.h"
00004 #include "FWCore/Framework/interface/MakerMacros.h"
00005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00006 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
00007 #include "DataFormats/GeometryVector/interface/GlobalVector.h"
00008 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
00009 #include "MagneticField/Engine/interface/MagneticField.h"
00010 #include <iostream>
00011 
00012 class MFProducer : public edm::EDProducer
00013 {
00014 public:
00015   explicit MFProducer( const edm::ParameterSet& );
00016   ~MFProducer( void );
00017   
00018 private:
00019   virtual void beginJob( void );
00020   virtual void produce( edm::Event&, const edm::EventSetup& );
00021   virtual void endJob( void );
00022   void          evaluate( const double point[3], double field[3] ) const;
00023   unsigned      m_mapDensityX;
00024   unsigned      m_mapDensityY;
00025   unsigned      m_mapDensityZ;
00026   double        m_minX;
00027   double        m_maxX;
00028   double        m_minY;
00029   double        m_maxY;
00030   double        m_minZ;
00031   double        m_maxZ;
00032   double        m_xBaseDir;
00033   double        m_yBaseDir;
00034   double        m_zBaseDir;
00035   bool          m_valid;
00036   edm::ESHandle<MagneticField> m_mf;
00037 };
00038 
00039 MFProducer::MFProducer( const edm::ParameterSet& iPset )
00040   : m_valid( false )
00041 {
00042   m_mapDensityX = iPset.getUntrackedParameter<unsigned>( "mapDensityX", 10 );
00043   m_mapDensityY = iPset.getUntrackedParameter<unsigned>( "mapDensityY", 10 );
00044   m_mapDensityZ = iPset.getUntrackedParameter<unsigned>( "mapDensityY", 10 );
00045   m_minX = iPset.getUntrackedParameter<double>( "minX", -18.0 );
00046   m_maxX = iPset.getUntrackedParameter<double>( "maxX", 18.0 );
00047   m_minY = iPset.getUntrackedParameter<double>( "minY", -18.0 );
00048   m_maxY = iPset.getUntrackedParameter<double>( "maxY", 18.0 );
00049   m_minZ = iPset.getUntrackedParameter<double>( "minZ", -18.0 );
00050   m_maxZ = iPset.getUntrackedParameter<double>( "maxZ", 18.0 );
00051 
00052   m_xBaseDir = ( m_maxX - m_minX ) / m_mapDensityX;
00053   m_yBaseDir = ( m_maxY - m_minY ) / m_mapDensityY;
00054   m_zBaseDir = ( m_maxZ - m_minZ ) / m_mapDensityZ;
00055 }
00056 
00057 MFProducer::~MFProducer( void )
00058 {}
00059 
00060 void
00061 MFProducer::produce( edm::Event& iEvent, const edm::EventSetup& iSetup )
00062 {
00063   iSetup.get<IdealMagneticFieldRecord>().get( m_mf );
00064   m_mf.isValid() ? m_valid = true : m_valid = false;
00065    
00066   for( unsigned i = 0; i <= m_mapDensityX; ++i )
00067   {
00068     for( unsigned j = 0; j <= m_mapDensityY; ++j )
00069     {                       
00070         // Prepare field position and get value.
00071         double x =  m_minX + m_xBaseDir * i;
00072         double y = m_minY + m_yBaseDir * j;
00073         double z = 0.;
00074         double  pt[3] = { x, y, z };
00075         double  val[3];
00076         evaluate( pt, val );
00077         std::cout << "(" << x << ", " << y << ", " << z << ") " << val[0] << ":" << val[1] << ":" << val[2] << "; ";
00078     }
00079     std::cout << std::endl;
00080   }
00081 }
00082 
00083 void
00084 MFProducer::evaluate (const double point [3], double field [3]) const
00085 {
00086   GlobalVector b = m_mf->inTesla( GlobalPoint( point[0], point[1], point[2] ));
00087   
00088   field [0] = b.x();
00089   field [1] = b.y();
00090   field [2] = b.z();
00091 }
00092 
00093 void 
00094 MFProducer::beginJob( void )
00095 {}
00096 
00097 void 
00098 MFProducer::endJob( void )
00099 {}
00100 
00101 DEFINE_FWK_MODULE( MFProducer );