Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

BIntegrator.cpp

Go to the documentation of this file.
00001 // $Id: BIntegrator.cpp,v 1.2 2005/05/25 14:31:35 cattanem Exp $
00002 // Include files 
00003 // -------------
00004 
00005 // from Gaudi
00006 #include "GaudiKernel/ToolFactory.h" 
00007 
00008 // from TrackEvent
00009 #include "Event/State.h"
00010 #include "Event/TrackParameters.h"
00011 
00012 // from CLHEP
00013 #include "CLHEP/Units/PhysicalConstants.h"
00014 
00015 // local
00016 #include "BIntegrator.h"
00017 
00018 //-----------------------------------------------------------------------------
00019 // Implementation file for class : BIntegrator
00020 //
00021 // 2000-08-16 : M. Needham
00022 // 2005-05-12 : Eduardo Rodrigues (adaptations to new track event model)
00023 //-----------------------------------------------------------------------------
00024 
00025 // Declaration of the Tool Factory
00026 static const  ToolFactory<BIntegrator>          s_factory ;
00027 const        IToolFactory& BIntegratorFactory = s_factory ; 
00028 
00029 
00030 //=============================================================================
00031 // Standard constructor, initializes variables
00032 //=============================================================================
00033 BIntegrator::BIntegrator( const std::string& type,
00034                           const std::string& name,
00035                           const IInterface* parent )
00036   : GaudiTool ( type, name , parent )
00037 {
00038   declareInterface<IBIntegrator>(this);
00039 
00040   declareProperty( "NSteps", m_nSteps = 501 ); 
00041   declareProperty( "FirstZ", m_firstZ = 0.1*mm );
00042   declareProperty( "LastZ",  m_lastZ = 9400.*mm );
00043 }
00044 //=============================================================================
00045 // Destructor
00046 //=============================================================================
00047 BIntegrator::~BIntegrator() {}; 
00048 
00049 //=============================================================================
00050 // Initialization
00051 //=============================================================================
00052 StatusCode BIntegrator::initialize()
00053 {
00054   StatusCode sc = GaudiTool::initialize();
00055   if (sc.isFailure()) return sc;  // error already reported by base class
00056 
00057   // Retrieve a pointer to the magnetic field service
00058   m_pIMF = svc<IMagneticFieldSvc>( "MagneticFieldSvc", true );
00059  
00060   calculateBdlCenter();
00061   info() << "Center of the field is at the z positions "
00062          << m_centerZ << endreq;
00063   
00064   return sc;
00065 }
00066 
00067 //=============================================================================
00068 // Get the z of center and the total Bdl
00069 //=============================================================================
00070 StatusCode BIntegrator::calculateBdlAndCenter( const HepPoint3D& beginPoint, 
00071                                                const HepPoint3D& endPoint,
00072                                                const double tX,
00073                                                const double tY, 
00074                                                double& zCenter, 
00075                                                HepVector3D& Bdl ) const
00076 {
00077   // Point where field should be calculated
00078   HepPoint3D  point(0.001,0.001,0.0001);
00079   HepVector3D bField;      // returned field
00080   Bdl.setX(0.);
00081   Bdl.setY(0.);
00082   Bdl.setZ(0.);
00083 
00084   //First get the Center by walking in two rays..
00085   double zCen = m_centerZ.x();  // the Bdlx is the important component
00086   double xCen = endPoint.x() + tX*(zCen-endPoint.z());
00087   double yCen = endPoint.y() + tY*(zCen-endPoint.z());
00088   if (xCen/zCen>0.3) { 
00089     xCen = 0.3*zCen;
00090   }
00091   else if (xCen/zCen< -0.3) {
00092     xCen = -0.3*zCen;
00093   }
00094   if( yCen/zCen>0.25) {
00095     yCen = 0.25*zCen;
00096   }
00097   else if (yCen/zCen< -0.25){ 
00098     yCen = -0.25*zCen;
00099   }
00100 
00101   double angleX = xCen/zCen;
00102   double angleY = yCen/zCen;
00103   double stepSize = (endPoint.z()-beginPoint.z())/(double)m_nSteps;
00104   int iStep;
00105   for(iStep=0;iStep<m_nSteps;iStep++)    {
00106 
00107     if(point.z()>zCen)      {
00108       angleX = tX;
00109       angleY = tY;
00110     }
00111     double dX = angleX*stepSize;
00112     double dY = angleY*stepSize;
00113     double dZ = stepSize;
00114     point.setX( point.x()+ dX);
00115     point.setY( point.y()+ dY);
00116     point.setZ( point.z()+ dZ);
00117     m_pIMF->fieldVector(point,bField);
00118 
00119     //Cacluate the Bdl 
00120     Bdl.setX( Bdl.x() + dY* bField.z()- dZ*bField.y() );
00121     Bdl.setY( Bdl.y() + dZ*bField.x() -dX*bField.z());
00122     Bdl.setZ( Bdl.z() + dX*bField.y() -dY*bField.x());
00123     
00124   } // iStep
00125 
00127 
00128   double Bdlx_half =0.5*Bdl.x();
00129   double Bdly_half =0.5*Bdl.y();
00130   double Bdlz_half =0.5*Bdl.z();
00131   
00132   Bdl.setX( 0.);
00133   Bdl.setY( 0.);
00134   Bdl.setZ( 0.);
00135   
00136   double min_Bdlx =10000.;
00137   double min_Bdly =10000.;
00138   double min_Bdlz =10000.;
00139   HepPoint3D centerZ(0.,0.,0.);
00140   //reset al the variables used
00141   angleX = xCen/zCen;
00142   angleY = yCen/zCen;
00143   point.setX(0.);
00144   point.setY(0.);
00145   point.setZ(0.);
00146   for(iStep=0;iStep<m_nSteps;iStep++)    {
00147 
00148     if(point.z()>zCen)      {
00149       angleX = tX;
00150       angleY = tY;
00151     }
00152     double dX = angleX*stepSize;
00153     double dY = angleY*stepSize;
00154     double dZ = stepSize;
00155     point.setX( point.x()+ dX);
00156     point.setY( point.y()+ dY);
00157     point.setZ( point.z()+ dZ);
00158     m_pIMF->fieldVector(point,bField);
00159 
00160     //Cacluate the Bdl 
00161     Bdl.setX( Bdl.x() + dY* bField.z()- dZ*bField.y() );
00162     Bdl.setY( Bdl.y() + dZ*bField.x() -dX*bField.z());
00163     Bdl.setZ( Bdl.z() + dX*bField.y() -dY*bField.x());
00164 
00165     if(fabs(Bdl.x()-Bdlx_half)< min_Bdlx){
00166       min_Bdlx=fabs(Bdl.x()-Bdlx_half);
00167       centerZ.setX(point.z());
00168     }
00169     if(fabs(Bdl.y()-Bdly_half)< min_Bdly){
00170       min_Bdly=fabs(Bdl.y()-Bdly_half);
00171       centerZ.setY(point.z());
00172     }
00173     if(fabs(Bdl.z()-Bdlz_half)< min_Bdlz){
00174       min_Bdlz=fabs(Bdl.z()-Bdlz_half);
00175       centerZ.setZ(point.z());
00176     }
00177 
00178   }
00179 
00180   //take the x component of the zcenter.....
00181   zCenter = centerZ.x();
00182 
00183   return StatusCode::SUCCESS;
00184 }
00185 
00186 //=============================================================================
00187 // 
00188 //=============================================================================
00189 StatusCode BIntegrator::calculateBdlCenter()
00190 {
00191   // Centre of the field
00192   HepVector3D bField;
00193 
00194   HepVector3D BdlTotal(0.,0.,0.);
00195   HepPoint3D  position = HepPoint3D(0.0,0.0,0.);
00196 
00197   double stepSize = (m_lastZ-m_firstZ) / (double)m_nSteps;
00198 
00199   // Get the integral field
00200   int iStep;
00201   for( iStep=0;iStep < m_nSteps;iStep++) {
00202     position.setX(0.1);
00203     position.setY(0.1);
00204     position.setZ( m_firstZ+((double)iStep+0.5)*stepSize );
00205     m_pIMF -> fieldVector( position,bField );
00206 
00207     //Calculate the Bdl 
00208     BdlTotal.setX( BdlTotal.x() - stepSize*bField.y() );
00209     BdlTotal.setY( BdlTotal.y() + stepSize*bField.x() );
00210     BdlTotal.setZ( BdlTotal.z() + 0.);
00211   } // iStep
00212 
00213   double Bdlx_half = 0.5*BdlTotal.x();
00214   double Bdly_half = 0.5*BdlTotal.y();
00215   double Bdlz_half = 0.5*BdlTotal.z();
00216   
00217   BdlTotal.setX( 0.);
00218   BdlTotal.setY( 0.);
00219   BdlTotal.setZ( 0.);
00220   
00221   double min_Bdlx = 10000.;
00222   double min_Bdly = 10000.;
00223   double min_Bdlz = 10000.;
00224 
00225   //Loop again and find the middle of each of the components
00226   for ( iStep=0; iStep < m_nSteps; iStep++ ) {
00227     double z = m_firstZ+ (iStep+0.5)*stepSize;
00228     position.setX(0.1);
00229     position.setY(0.1);
00230     position.setZ(z);
00231     m_pIMF -> fieldVector( position,bField );
00232     //Cacluate the Bdl 
00233     BdlTotal.setX( BdlTotal.x() - stepSize*bField.y() );
00234     BdlTotal.setY( BdlTotal.y() + stepSize*bField.x() );
00235     BdlTotal.setZ( BdlTotal.z() + 0.);
00236     if ( fabs(BdlTotal.x()-Bdlx_half) < min_Bdlx ) {
00237       min_Bdlx = fabs( BdlTotal.x()-Bdlx_half );
00238       m_centerZ.setX(z);
00239     }
00240     if ( fabs(BdlTotal.y()-Bdly_half)< min_Bdly ) {
00241       min_Bdly = fabs( BdlTotal.y()-Bdly_half );
00242       m_centerZ.setY(z);
00243     }
00244     if ( fabs(BdlTotal.z()-Bdlz_half)< min_Bdlz ) {
00245       min_Bdlz = fabs( BdlTotal.z()-Bdlz_half );
00246       m_centerZ.setZ(z);
00247     }
00248   }
00249   
00250   return StatusCode::SUCCESS;
00251 }
00252 
00253 //=============================================================================

Generated on Fri May 27 13:59:37 2005 for New Track Event Model by doxygen 1.4.1