7 added files
trf++/src/mag_field
diff -N MagFieldMgr.cpp
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ MagFieldMgr.cpp 29 Jul 2011 00:06:58 -0000 1.1
@@ -0,0 +1,58 @@
+#include "mag_field/MagFieldMgr.hpp"
+
+#include <iostream>
+#include <cassert>
+
+MagFieldMgr* MagFieldMgr::_instance=0;
+
+
+//***************************************************************
+
+MagFieldMgr::MagFieldMgr() : _pfield(0) , _id(1), _counter(0) {
+}
+
+//***************************************************************
+
+MagFieldMgr::MagFieldMgr(const MagFieldMgr& mgr) {
+ assert(false);
+}
+
+//***************************************************************
+
+MagFieldMgr::~MagFieldMgr() {
+ delete _pfield;
+}
+
+//***************************************************************
+
+void MagFieldMgr::reset_field(AbstractMagneticField* pfield) {
+ // delete _pfield;
+ _pfield=pfield;
+ // _cache.refresh_handle(_id,_pfield);
+ _counter++;
+}
+
+//***************************************************************
+
+MagFieldMgr* MagFieldMgr::get_instance() {
+ if( !_instance )
+ _instance = new MagFieldMgr;
+ return _instance;
+}
+
+//***************************************************************
+
+AbstractMagneticField** MagFieldMgr::get_field() {
+
+ if( !isFieldValid() ) {
+ std::cerr<<"Instantiate the MagField first\n";
+ assert(false);
+ }
+
+ return &_pfield;
+
+ // return _cache.create_handle(_id,_pfield);
+
+}
+
+//***************************************************************
trf++/src/mag_field
diff -N ConstantMagneticField.cpp
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ConstantMagneticField.cpp 29 Jul 2011 00:06:58 -0000 1.1
@@ -0,0 +1,115 @@
+//
+// $Id: ConstantMagneticField.cpp,v 1.1 2011/07/29 00:06:58 ngraf Exp $
+//
+// File: ConstantMagneticField.cc
+// Purpose:
+// Created: 17-Dec-1997 Heidi Schellman
+//
+// $Revision: 1.1 $
+// H. Schellman 1998-06-14
+// Modify to run standalone in VC++
+//
+//
+//
+
+// Include files
+#include "mag_field/ConstantMagneticField.hpp"
+
+#include <iostream>
+using namespace std;
+
+/// set the magnitude
+ConstantMagneticField::ConstantMagneticField(const double magnitude) {
+ m_magnitude = magnitude;
+ SpacePoint origin;
+ m_constantfield = CartesianPointVector(origin,0.,0.,magnitude);
+}
+ConstantMagneticField::ConstantMagneticField() {
+ ConstantMagneticField(0.0);
+}
+
+
+ConstantMagneticField::ConstantMagneticField(const SpacePointVector& axis,
+ const double magnitude) {
+ m_magnitude = magnitude;
+ // just in case used screwed up
+ //||||||||| v_rxyz() is vector's r component ||||||||||||||||||||||
+ //double rescale = magnitude/axis.v_rxyz();
+ double rescale = magnitude/axis.magnitude();
+ //|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+ SpacePoint origin;
+ m_constantfield = CartesianPointVector(origin,
+ axis.v_x()*rescale,
+ axis.v_y()*rescale,
+ axis.v_z()*rescale);
+ }
+
+ConstantMagneticField::ConstantMagneticField(const SpacePointVector& axis) {
+ // same as above ||||||||||||||||||||||
+ //m_magnitude = axis.v_rxyz();
+ m_magnitude = axis.magnitude();
+ // ||||||||||||||||||||||||||||||||||||
+ m_constantfield = axis;
+ }
+
+bool ConstantMagneticField::set_magnitude(const double magnitude){
+ double rescale = magnitude/m_magnitude;
+ m_magnitude = magnitude;
+ SpacePoint origin;
+ m_constantfield = CartesianPointVector(origin,
+ m_constantfield.v_x()*rescale,
+ m_constantfield.v_y()*rescale,
+ m_constantfield.v_z()*rescale);
+ return 1;
+}
+
+
+SpacePointVector ConstantMagneticField::field(const SpacePoint& x,
+ SpacePointTensor* g) const {
+ // Purpose: return the magnetic field in local coordinates
+
+ // Set gradient to zero.
+
+ if(g != 0)
+ *g = SpacePointTensor(x);
+
+ // Return field.
+
+ return CartesianPointVector(x,m_constantfield.v_x(),
+ m_constantfield.v_y(),
+ m_constantfield.v_z());
+}
+
+SpacePointVector ConstantMagneticField::fieldgradient(const SpacePoint&) const {
+ // Purpose: return the scale over which field varies
+
+ SpacePointVector v;
+ return v;
+}
+
+bool ConstantMagneticField::fieldvalid(const SpacePoint&) const {
+ // am i ok?
+ return 1;
+}
+
+
+ostream& operator <<(ostream& os, const ConstantMagneticField& me){
+//
+// Purpose: Dump the definition of the ConstantMagneticField
+//
+//======= a dead loop ===================================
+//os << "ConstantMagneticField = " << me ;
+ os << "ConstantmagneticField magnitude = "<<me.get_magnitude();
+// ======================================================
+ return os;
+}
+
+
+
+
+
+
+
+
+
+
trf++/src/mag_field
diff -N AbstractMagneticField.cpp
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ AbstractMagneticField.cpp 29 Jul 2011 00:06:58 -0000 1.1
@@ -0,0 +1,84 @@
+//
+// $Id: AbstractMagneticField.cpp,v 1.1 2011/07/29 00:06:58 ngraf Exp $
+//
+// File: AbstractMagneticField.cpp
+// Purpose: Common interface for magnetic field.
+// Created: 17-Dec-1997 Heidi Schellman
+//
+// $Revision: 1.1 $
+//
+// H. Schellman 1998-06-14
+// Modify to run standalone in VC++
+//
+
+// Include files
+#include "mag_field/AbstractMagneticField.hpp"
+
+#include <iostream>
+using namespace std;
+
+AbstractMagneticField::AbstractMagneticField(const double magnitude): m_magnitude(magnitude){;}
+
+AbstractMagneticField::AbstractMagneticField(){;}
+
+
+AbstractMagneticField::~AbstractMagneticField(){;}
+
+
+ double AbstractMagneticField::get_magnitude() const {
+ return m_magnitude; }
+
+ bool AbstractMagneticField::set_magnitude(const double dmagnitude)
+ {
+ m_magnitude = dmagnitude;
+ return true;
+ }
+
+
+
+
+ostream& operator <<(ostream& os, const AbstractMagneticField& me)
+//
+// Purpose: Dump the definition of the AbstractMagneticField
+// States:
+//
+{
+ os << "AbstractMagneticField constant = " << me.m_magnitude << endl ;
+ return os;
+}
+
+
+
+// Calculate field and make a numerical calculation of the gradient by
+// differences.
+
+void AbstractMagneticField::gradient_numeric(const SpacePoint& p,
+ SpacePointTensor& g) const
+{
+ double x = p.x();
+ double y = p.y();
+ double z = p.z();
+ double dx = 0.1;
+ double dy = 0.1;
+ double dz = 1.0;
+ SpacePointVector bfx2(field(CartesianPoint(x + 0.5*dx, y, z)));
+ SpacePointVector bfx1(field(CartesianPoint(x - 0.5*dx, y, z)));
+ SpacePointVector bfy2(field(CartesianPoint(x, y + 0.5*dy, z)));
+ SpacePointVector bfy1(field(CartesianPoint(x, y - 0.5*dy, z)));
+ SpacePointVector bfz2(field(CartesianPoint(x, y, z + 0.5*dz)));
+ SpacePointVector bfz1(field(CartesianPoint(x, y, z - 0.5*dz)));
+ double dbxdx = (bfx2.v_x() - bfx1.v_x())/dx;
+ double dbxdy = (bfy2.v_x() - bfy1.v_x())/dy;
+ double dbxdz = (bfz2.v_x() - bfz1.v_x())/dz;
+ double dbydx = (bfx2.v_y() - bfx1.v_y())/dx;
+ double dbydy = (bfy2.v_y() - bfy1.v_y())/dy;
+ double dbydz = (bfz2.v_y() - bfz1.v_y())/dz;
+ double dbzdx = (bfx2.v_z() - bfx1.v_z())/dx;
+ double dbzdy = (bfy2.v_z() - bfy1.v_z())/dy;
+ double dbzdz = (bfz2.v_z() - bfz1.v_z())/dz;
+ g = CartesianPointTensor(x, y, z,
+ dbxdx, dbxdy, dbxdz,
+ dbydx, dbydy, dbydz,
+ dbzdx, dbzdy, dbzdz);
+ return;
+}
trf++/include/mag_field
diff -N MagFieldMgr.hpp
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ MagFieldMgr.hpp 29 Jul 2011 00:06:59 -0000 1.1
@@ -0,0 +1,83 @@
+#ifndef MagFieldManager_HPP
+#define MagFieldManager_HPP
+
+// MagFieldMgr is a singleton holding a pointer to a Magnetic Field Map
+// The users are expected to utilize it in the pattern
+//
+// MagFieldMgr* mgr = MagFieldManager::get_instance();
+// AbstractMagneticField** pfieldPtr;
+// if( mgr.isFieldValid() )
+// pfieldPtr = mgr->get_field();
+// SpacePoint x;
+// SpacePointVector bf = (*pfieldPtr)->field(x);
+//
+// MagFieldMgr returns a pointer to a pointer so the user will get
+// updates whenever some external agent detects a need for a new
+// field map ( new run or anything like that) and the user doesn't need
+// to call mgr->get_bfield() again.
+//
+
+
+#include "mag_field/AbstractMagneticField.hpp"
+//#include "geometry_system/management/HandleSystem.hpp"
+//
+//namespace mgf {
+// typedef dgs::Handle<const AbstractMagneticField> MagFieldPtr;
+//}
+
+//class AbstractMagneticField;
+
+class MagFieldMgr {
+
+public:
+
+// return instance of MagFieldMgr
+
+ static MagFieldMgr* get_instance();
+
+// return a smart pointer to a field
+
+// mgf::MagFieldPtr get_field();
+
+ AbstractMagneticField** get_field();
+// is Manager holding a field at the moment?
+
+ bool isFieldValid() const { return _pfield!=0; }
+
+
+// internal counter. It starts at 0 when Manager instantiated
+// and gets incremented every time reset_field() method is called
+// User can remember the value of the counter after calling
+// get_field method and check againts it every time the wish
+// to decect is field has changed
+
+ unsigned int counter() { return _counter; }
+
+private:
+
+ MagFieldMgr() ;
+ MagFieldMgr(const MagFieldMgr&) ;
+~MagFieldMgr() ;
+
+public:
+
+ // set the field and give up object management to MagFieldMgr
+ void reset_field(AbstractMagneticField*);
+
+protected:
+ // typedef dgs::HandleCache<const AbstractMagneticField> Cache;
+
+ // Cache _cache;
+
+ static MagFieldMgr* _instance;
+
+ AbstractMagneticField* _pfield;
+
+ int _id;
+
+ unsigned int _counter;
+
+};
+
+#endif
+
trf++/include/mag_field
diff -N ConstantMagneticField.hpp
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ConstantMagneticField.hpp 29 Jul 2011 00:06:59 -0000 1.1
@@ -0,0 +1,80 @@
+#ifndef INC_ConstantMagneticField_HH
+#define INC_ConstantMagneticField_HH
+//
+// $Id: ConstantMagneticField.hpp,v 1.1 2011/07/29 00:06:59 ngraf Exp $
+//
+// File: ConstantMagneticField.hh
+// Purpose: Return a constant magnetic field with direction and magnitude
+// set by the user.
+// Created: 5-MAR-1998 Heidi Schellman
+//
+/** ConstantMagneticField is a constant Magnetic field which covers all
+space and defaults to lying on the z-axis.
+**/
+//
+// $Revision: 1.1 $
+// H. Schellman 1998-06-14
+// Modify to run standalone in VC++
+//
+//
+
+
+// Include files
+
+
+#include "mag_field/AbstractMagneticField.hpp"
+
+
+// Class definitions
+class ConstantMagneticField: public AbstractMagneticField
+{
+ /// Purpose: Set up and return a Constant Magnetic Field
+
+public:
+
+ // The public constructor must have initialization.
+
+ /// make magnetic field along z with magnitude magnitude
+ ConstantMagneticField(const double magnitude);
+
+ /// make magnetic field pointing along (unit) vector axis with magnitude magnitude
+ConstantMagneticField(const SpacePointVector& axis, const double magnitude);
+ // axis is made into a unit vector before use.
+
+ /// Make a constant magnetic field out of SpacePointVector BVector
+ ConstantMagneticField(const SpacePointVector& Bvector);
+ // the magnitude is set to the length of Bvector.
+
+ /// Default constructor
+ ConstantMagneticField();
+
+ /// set the magnitude of the magnetic field
+ bool set_magnitude(const double magnitude);
+
+ /// return the magnetic field at space point x
+ SpacePointVector field(const SpacePoint& x, SpacePointTensor* g = 0)const;
+
+ /// return the scale length over which field is varying at x
+ SpacePointVector fieldgradient(const SpacePoint&)const;
+
+ /// is the field valid at x
+ bool fieldvalid(const SpacePoint&)const;
+
+ /// tells us more about yourself ...
+ friend std::ostream& operator<<(std::ostream& os, const ConstantMagneticField& me);
+
+
+private:
+
+
+ /// not much in here is there?
+ SpacePointVector m_constantfield; // the field value
+
+
+
+public:
+
+ // D0_OBJECT_SETUP(ConstantMagneticField);
+
+};
+#endif //INC_ConstantMagneticField_HH
trf++/include/mag_field
diff -N AbstractMagneticField.hpp
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ AbstractMagneticField.hpp 29 Jul 2011 00:06:59 -0000 1.1
@@ -0,0 +1,148 @@
+#ifndef INC_AbstractMagneticField_HH
+#define INC_AbstractMagneticField_HH
+//
+// $Id: AbstractMagneticField.hpp,v 1.1 2011/07/29 00:06:59 ngraf Exp $
+//
+// File: AbstractMagneticField.hpp
+// Purpose: Common interface for magnetic fields in D0
+// Created: 5-MAR-1998 Heidi Schellman
+//
+
+/// transformation interface self_xform() and set_xform() added
+/// by zhong yu @ Nov 23, 1998.
+
+/** AbstractMagneticField is a general magnetic field class which returns
+values interesting for tracking code. A magnetic field
+will generally have an internal representation optimized for speed which
+will need to be updated whenever the field is moved or rescaled. Important
+methods are:
+
+
+SpacePointVector field(const SpacePoint& x, SpacePointTensor* g = 0);
+returns the field at x and optionally calculates the gradient tensor.
+The returned field and the gradient are in the form of a value at the point x.
+
+bool fieldvalid(const SpacePoint& x); returns TRUE/FALSE if x is in the valid
+field region.
+
+void gradient_numeric(SpacePointTensor&); calculates the gradient tensor
+numerically by differences. It is supplied for convenience to concrete
+field classes that don't include an internal gradient calculation,
+and for testing internal gradient calculations.
+
+SpacePointVector fieldgradient(SpacePoint& x); is the old gradient method.
+This method is not very useful, since it can not calculate the full gradient
+tensor, and no concrete field provides a nontrivial implementation of it.
+
+
+Note regarding gradient tensor:
+
+The gradient tensor is a matrix of covariant derivates, which can be defined,
+or its components extracted, in any standard coordinate system (namely,
+Cartesian, cylindrical, spherical).
+
+In Cartesian coordinates, covariant derivatives is the same as ordinary
+partial derivatives:
+
+Bi;j = Bi,j (i,j = x,y,z)
+
+In Cylindrical coordinates, the physical components of the covariant
+gradient tensor are as follows:
+
+Br;r = Br,r
+Br;phi = (1/r)Br,phi - Bphi/r
+Br:z = Br,z
+Bphi;r = Bphi,r
+Bphi;phi = (1/r)Bphi,phi + Br/r
+Bphi;z = Bphi,z
+Bz;r = Bz,r
+Bz;phi = (1/r)Bz,phi
+Bz;z = Bz,phi
+
+
+**/
+//
+//
+// $Revision: 1.1 $
+//
+//
+
+
+// Include files
+#include "spacegeom/SpacePointVector.h"
+#include "spacegeom/SpacePointTensor.h"
+#include <iostream>
+
+namespace dgs{
+ class GeometryXform;
+ }
+
+// Class definitions
+class AbstractMagneticField
+{
+ //Purpose: Common interface for D0 magnetic fields
+
+public:
+
+ // The public constructor must have initialization.
+ /// Make a field.
+ AbstractMagneticField(const double magnitude);
+ AbstractMagneticField();
+ virtual ~AbstractMagneticField();
+
+
+
+ // Accessors and I/O
+ /// return the overall scale for the field map
+ double get_magnitude() const;
+
+ /// set the overall scale for the field map
+ virtual bool set_magnitude(const double dmagnitude);
+
+
+ /// given a space position, return a field object and optionally calculate
+ /// the covarient gradient.
+ virtual SpacePointVector field(const SpacePoint&,
+ SpacePointTensor* g = 0)const = 0;
+
+ /// given a space position, return the field gradient
+ virtual SpacePointVector fieldgradient(const SpacePoint&)const = 0;
+
+ /// given a space position, tell me if the map is valid here
+ virtual bool fieldvalid(const SpacePoint&) const = 0;
+
+ /// Calculate gradient tensor by differences.
+ void gradient_numeric(const SpacePoint&, SpacePointTensor&) const;
+
+ /// Print out the B field (not its value at a particular place)
+ friend std::ostream& operator<<(std::ostream& os, const AbstractMagneticField& me);
+
+ /// transformation interfaces:
+ virtual bool self_xform() const{return false;} // default: can't
+ virtual bool set_xform(const dgs::GeometryXform& origin){return false;}
+
+protected:
+
+ double m_magnitude; // the scale of the field so it is easy to rescale from
+ // hall probe readout
+
+
+public:
+
+ // D0_OBJECT_SETUP(AbstractMagneticField);
+
+};
+
+
+std::ostream& operator<<(std::ostream& os, const AbstractMagneticField& me);
+
+#endif //INC_AbstractMagneticField_HH
+
+
+
+
+
+
+
+
+
trf++/include/mag_field
diff -N MCField.hpp
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ MCField.hpp 29 Jul 2011 00:06:59 -0000 1.1
@@ -0,0 +1,70 @@
+//
+// Name: MCField.hpp
+//
+// Purpose: Magnetic field class provides C++ interface to d0gstar magnetic
+// field map d0gstar/d0db/detc/fmap.tz. The algorithm is based
+// on a hand transltion of the d0gstar fortran magnetic field
+// subroutine d0gstar/src/util/d0field/gufld.F.
+//
+// Created: 27-Nov-2000 H. Greenlee
+//
+
+#ifndef MCFIELD_HPP
+#define MCFIELD_HPP
+
+#include <vector>
+#include "mag_field/AbstractMagneticField.hpp"
+
+class MCField : public AbstractMagneticField
+{
+public:
+
+ // Constructor/destructor
+
+ MCField(double solenoid_scale=1., double toroid_scale=1.);
+ ~MCField();
+
+ // Required overrides.
+
+ SpacePointVector field(const SpacePoint& point,
+ SpacePointTensor* g = 0)const;
+ SpacePointVector fieldgradient(const SpacePoint& point)const;
+ bool fieldvalid(const SpacePoint& point) const {return true;}
+
+private:
+
+ // Attributes
+
+ double _solenoid_scale; // Solenoid scale factor.
+ double _toroid_scale; // Toroid scale factor.
+
+ // Field maps.
+
+ // Solenoid Central 2D.
+ int _central_nr; // Number of r grid points.
+ int _central_nz; // Number of z grid points.
+ float _central_dr; // R grid spacing.
+ float _central_dz; // Z grid spacing.
+ float _central_rmin, _central_rmax; // R grid limits.
+ float _central_zmin, _central_zmax; // Z grid limits.
+ std::vector<float> _central_br; // BR map.
+ std::vector<float> _central_bz; // BZ map.
+
+ // Solenoid Fringe 3D.
+ std::vector<float> _fringe_grid_x; // X grid points.
+ std::vector<float> _fringe_grid_y; // Y grid points.
+ std::vector<float> _fringe_grid_z; // Z grid points.
+ std::vector<float> _fringe_bx; // BX map.
+ std::vector<float> _fringe_by; // BY map.
+ std::vector<float> _fringe_bz; // BZ map.
+
+ // Toroid 3D.
+ std::vector<float> _toroid_grid_x; // X grid points.
+ std::vector<float> _toroid_grid_y; // Y grid points.
+ std::vector<float> _toroid_grid_z; // Z grid points.
+ std::vector<float> _toroid_bx; // BX map.
+ std::vector<float> _toroid_by; // BY map.
+ std::vector<float> _toroid_bz; // BZ map.
+};
+
+#endif
CVSspam 0.2.8