| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

MagFieldReader.cpp

Go to the documentation of this file.
00001 // $Id: MagFieldReader.cpp,v 1.16 2009/01/27 16:13:40 cattanem Exp $
00002 // Include files 
00003 #include "Riostream.h"
00004 // from Gaudi
00005 #include "GaudiKernel/AlgFactory.h"
00006 #include "GaudiKernel/IMagneticFieldSvc.h"
00007 #include "GaudiKernel/IChronoStatSvc.h"
00008 #include "GaudiKernel/SystemOfUnits.h"
00009 #include "GaudiKernel/RndmGenerators.h"
00010 
00011 // from LHCbKernel
00012 #include "Kernel/IBIntegrator.h"
00013 
00014 // Math Definitions
00015 #include "GaudiKernel/Vector3DTypes.h"
00016 #include "GaudiKernel/Point3DTypes.h"
00017 
00018 // local
00019 #include "MagFieldReader.h"
00020 
00021 
00022 //-----------------------------------------------------------------------------
00023 // Implementation file for class : MagFieldReader
00024 //
00025 // 08/05/2002 : Edgar De Oliveira
00026 // 16/03/2004 : Gloria Corti, modified to fill ntuple
00027 // 05/2007: Adlene Hicheur, modified to enable tests of different mappings
00028 // 07/2007: Adlene Hicheur, added B field integral testing Ntuple
00029 //-----------------------------------------------------------------------------
00030 
00031 DECLARE_ALGORITHM_FACTORY( MagFieldReader );
00032 
00033 //=============================================================================
00034 // Standard constructor, initializes variables
00035 //=============================================================================
00036 MagFieldReader::MagFieldReader( const std::string& name,
00037                     ISvcLocator* pSvcLocator)
00038   : GaudiTupleAlg ( name , pSvcLocator )
00039   , m_pIMF(0) 
00040 {
00041   declareProperty("Zmin", m_zMin =  -500.0*Gaudi::Units::mm);
00042   declareProperty("Zmax", m_zMax = 14000.0*Gaudi::Units::mm);  
00043   declareProperty("Step", m_step =   100.0*Gaudi::Units::mm);  
00044   declareProperty("Xmin", m_xMin =     0.0*Gaudi::Units::mm);  
00045   declareProperty("Xmax", m_xMax =  4000.0*Gaudi::Units::mm);
00046   declareProperty("Ymin", m_yMin =     0.0*Gaudi::Units::mm);  
00047   declareProperty("Ymax", m_yMax =  4000.0*Gaudi::Units::mm);
00048   declareProperty("FieldSvcName",m_FieldServiceName="MagneticFieldSvc");
00049   declareProperty("TestFieldInt",m_testbdl=false);
00050   declareProperty("NInt",m_nInt=1000);
00051   
00052 }
00053 
00054 //=============================================================================
00055 // Initialisation. Check parameters
00056 //=============================================================================
00057 StatusCode MagFieldReader::initialize() {
00058 
00059   StatusCode sc = GaudiTupleAlg::initialize(); // must be executed first
00060   if ( sc.isFailure() ) return sc;  // error printed already by GaudiAlgorithm
00061   
00062   debug() << "FieldReader intialize() has been called" << endmsg;
00063   
00064   m_pIMF = svc<IMagneticFieldSvc>( m_FieldServiceName, true );
00065   // m_pIAF = svc<IMagneticFieldSvc>( "AnalyticFieldSvc", true );
00066 
00067   info() << "MagFieldReader initialized with service ==> " <<  m_FieldServiceName << endmsg;
00068   return StatusCode::SUCCESS;
00069 };
00070 
00071 //=============================================================================
00072 // Main execution
00073 //=============================================================================
00074 StatusCode MagFieldReader::execute() {
00075 
00076   if (m_testbdl) TestBdl();
00077   
00078   // Print out info messages with the field value at different locations.
00079 
00080   debug() << "m_pIMF = " << m_pIMF << endreq;
00081 
00082   Tuple nt1 = nTuple( 10, "Field", CLID_ColumnWiseTuple );
00083 
00084   Gaudi::XYZVector B(0.0,0.0,0.0);
00085 
00086 
00087 
00088   for ( double z = m_zMin; z <= m_zMax; z += m_step ) {
00089     for( double y = m_yMin; y <= m_yMax; y += m_step ) {
00090       for( double x = m_xMin; x <= m_xMax; x += m_step ) {
00091         Gaudi::XYZPoint P( x, y, z );
00092         
00093 
00094           m_pIMF->fieldVector( P, B );
00095 
00096         
00097         
00098         
00099         // fill ntuple
00100         nt1->column( "x", P.x()/Gaudi::Units::cm );
00101         nt1->column( "y", P.y()/Gaudi::Units::cm );
00102         nt1->column( "z", P.z()/Gaudi::Units::cm );
00103         nt1->column( "Bx", B.x()/Gaudi::Units::tesla );
00104         nt1->column( "By", B.y()/Gaudi::Units::tesla );
00105         nt1->column( "Bz", B.z()/Gaudi::Units::tesla );
00106  
00107         nt1->write();
00108       }
00109     }
00110 
00111      Gaudi::XYZPoint P0( 0.0, 0.0, z);
00112      Gaudi::XYZPoint P02( 0.0, 0.0, z);
00113       m_pIMF->fieldVector( P0, B );
00114   
00115 
00116       debug() << "Magnetic Field at ("
00117               << P0.x() << ", " << P0.y() << ", " << P0.z() << " ) = "
00118               << (B.x())/Gaudi::Units::tesla << ", "
00119               << (B.y())/Gaudi::Units::tesla << ", "
00120               << (B.z())/Gaudi::Units::tesla << " Tesla " 
00121               << endmsg;
00122 
00123 
00124   }
00125 
00126 
00127 
00128   // Return status code.
00129   return StatusCode::SUCCESS;
00130 }
00131 
00132 
00133 StatusCode MagFieldReader::finalize() {
00134 
00135   StatusCode sc = GaudiTupleAlg::finalize(); // must be executed first
00136   if ( sc.isFailure() ) return sc;  // error printed already by GaudiAlgorithm
00137 if ( sc.isSuccess() )
00138     info() << "Service finalized successfully" << endmsg;
00139   return StatusCode::SUCCESS;
00140 };
00141 
00142 
00143 void MagFieldReader::TestBdl() 
00144 {
00145   
00146 Tuple nt2 = nTuple( 20, "Field Integral", CLID_ColumnWiseTuple );
00147 
00148   IBIntegrator* bIntegrator = tool<IBIntegrator>("BIntegrator");
00149 
00150   Gaudi::XYZPoint start(0,0,0);
00151   Gaudi::XYZPoint stop(0,0,9000/Gaudi::Units::mm); // start and end points
00152   double sigtx(0.3);
00153   double sigty(0.25); // slopes at start
00154   double zC; // z centre of field returned by tool
00155   Gaudi::XYZVector bdl;
00156 
00157   // random number generation
00158   Rndm::Numbers gausstx(randSvc(),Rndm::Gauss(0.,sigtx/2));
00159   Rndm::Numbers gaussty(randSvc(),Rndm::Gauss(0.,sigty/2));
00160   
00161   for (int i=0;i<m_nInt;i++) {
00162     double tx = gausstx();
00163     double ty = gaussty();
00164     if (fabs(tx) < sigtx && fabs(ty) < sigty) {
00165       
00166       bIntegrator->calculateBdlAndCenter(start, stop, tx, ty, zC, bdl);
00167   
00168       nt2->column( "tx", tx);
00169       nt2->column( "ty", ty);
00170       nt2->column( "Bdlx", bdl.x());
00171       nt2->column( "Bdly", bdl.y());
00172       nt2->column( "Bdlz", bdl.z());
00173       nt2->column( "zCenter", zC);
00174       nt2->write();
00175     }
00176   }
00177   
00178   releaseTool(bIntegrator).ignore(); 
00179   
00180 }
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 20:04:54 2011 for Magnet by doxygen 1.4.7