8 added files
lcdd/include
diff -N DipoleCoeffType.hh
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ DipoleCoeffType.hh 21 Apr 2006 23:50:52 -0000 1.1
@@ -0,0 +1,36 @@
+// $Header: /cvs/lcd/lcdd/include/DipoleCoeffType.hh,v 1.1 2006/04/21 23:50:52 jeremy Exp $
+#ifndef DipoleCoeffType_hh
+#define DipoleCoeffType_hh
+
+#include <string>
+
+/**
+ * @class DipoleCoeffType
+ * @brief The DipoleCoeffType from the lcdd_fields.xsd schema.
+ */
+class DipoleCoeffType
+{
+public:
+ DipoleCoeffType()
+ {}
+
+ virtual ~DipoleCoeffType()
+ {}
+
+public:
+
+ void set_value(const std::string& s)
+ {
+ m_value = s;
+ }
+
+ const std::string& get_value()
+ {
+ return m_value;
+ }
+
+private:
+ std::string m_value;
+};
+
+#endif
lcdd/include
diff -N DipoleType.hh
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ DipoleType.hh 21 Apr 2006 23:50:52 -0000 1.1
@@ -0,0 +1,71 @@
+#ifndef DipoleType_hh
+#define DipoleType_hh 1
+
+// parent class
+#include "FieldType.hh"
+
+// gdml
+#include "Schema/ContentGroup.h"
+
+// std
+#include <string>
+
+/**
+ * @class DipoleType
+ * @brief DipoleType from lcdd_fields.xsd schema.
+ */
+class DipoleType : public FieldType
+{
+public:
+
+ DipoleType()
+ {}
+
+ virtual ~DipoleType()
+ {}
+
+public:
+
+ void set_zmax(const std::string& s)
+ {
+ m_zmax = s;
+ }
+
+ void set_zmin(const std::string& s)
+ {
+ m_zmin = s;
+ }
+
+ const std::string& get_zmin() const
+ {
+ return m_zmin;
+ }
+
+ const std::string& get_zmax() const
+ {
+ return m_zmax;
+ }
+
+ void add_dipole_coeff()
+ {}
+
+ void add_content(const std::string& tag, SAXObject* so)
+ {
+ ContentGroup::ContentItem ci = {tag, so };
+ m_sequence.add_content(ci);
+ }
+
+ const ContentSequence* get_content() const
+ {
+ return &m_sequence;
+ }
+
+private:
+
+ std::string m_zmax;
+ std::string m_zmin;
+
+ ContentSequence m_sequence;
+};
+
+#endif
lcdd/include
diff -N G4Dipole.hh
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ G4Dipole.hh 21 Apr 2006 23:50:52 -0000 1.1
@@ -0,0 +1,38 @@
+// $Header: /cvs/lcd/lcdd/include/G4Dipole.hh,v 1.1 2006/04/21 23:50:52 jeremy Exp $
+
+#ifndef G4Dipole_hh
+#define G4Dipole_hh 1
+
+#include "G4MagneticField.hh"
+
+#include <vector>
+
+/**
+ * @class G4Dipole
+ * @brief The Geant4 binding for the dipole element.
+ */
+class G4Dipole : public G4MagneticField
+{
+public:
+ G4Dipole() {}
+ virtual ~G4Dipole() {}
+
+public:
+ void GetFieldValue( const double Point[3], double *Bfield ) const;
+
+ void setZMax(double zmax);
+ double getZMax();
+
+ void setZMin(double zmin);
+ double getZMin();
+
+ void addCoeff(double coeff);
+ const std::vector<double>& getCoeffs();
+
+private:
+ double m_zmin;
+ double m_zmax;
+ std::vector<double> m_coeffs;
+};
+
+#endif
lcdd/include
diff -N dipole.hh
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ dipole.hh 21 Apr 2006 23:50:52 -0000 1.1
@@ -0,0 +1,28 @@
+// $Header: /cvs/lcd/lcdd/include/dipole.hh,v 1.1 2006/04/21 23:50:52 jeremy Exp $
+#ifndef dipole_hh
+#define dipole_hh
+
+#include "Saxana/SAXObject.h"
+
+#include "DipoleType.hh"
+
+/**
+ * @class dipole
+ * @class The dipole element from the lcdd_fields.xsd schema.
+ */
+class dipole : public SAXObject, public DipoleType
+{
+public:
+ dipole()
+ {}
+
+ virtual ~dipole()
+ {}
+
+ virtual SAXObject::Type type()
+ {
+ return SAXObject::element;
+ }
+};
+
+#endif
lcdd/include
diff -N dipole_coeff.hh
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ dipole_coeff.hh 21 Apr 2006 23:50:52 -0000 1.1
@@ -0,0 +1,26 @@
+// $Header: /cvs/lcd/lcdd/include/dipole_coeff.hh,v 1.1 2006/04/21 23:50:52 jeremy Exp $
+#ifndef dipole_coeff_hh
+#define dipole_coeff_hh 1
+
+#include "DipoleCoeffType.hh"
+
+/**
+ * @class dipole_coeff
+ * @brief The dipole_coeff element from the lcdd_fields.xsd schema.
+ */
+class dipole_coeff : public SAXObject, public DipoleCoeffType
+{
+public:
+ dipole_coeff()
+ {}
+
+ virtual ~dipole_coeff()
+ {}
+
+ virtual SAXObject::Type type()
+ {
+ return SAXObject::element;
+ }
+};
+
+#endif
lcdd/src
diff -N G4Dipole.cc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ G4Dipole.cc 21 Apr 2006 23:50:53 -0000 1.1
@@ -0,0 +1,59 @@
+// $Header: /cvs/lcd/lcdd/src/G4Dipole.cc,v 1.1 2006/04/21 23:50:53 jeremy Exp $
+
+#include "G4Dipole.hh"
+
+#include <iostream>
+
+/**
+ * Apply polynomial fit of dipole field, with variable number of coefficients
+ * read from the input XML file.
+ */
+void G4Dipole::GetFieldValue( const double Point[3], double* Bfield ) const
+{
+ double bx = 0;
+ double z = Point[2];
+
+ // Check if z coordinate is within dipole z bounds.
+ if (z > m_zmin && z < m_zmax) {
+
+ // Apply all coefficients to this z coordinate.
+ for (size_t i=0; i<m_coeffs.size(); ++i) {
+ bx += m_coeffs[i] * pow(z,i);
+ }
+
+ // Apply Bx to input array.
+ Bfield[0] += bx;
+ }
+
+ return;
+}
+
+void G4Dipole::setZMax(double zmax)
+{
+ m_zmax = zmax;
+}
+
+double G4Dipole::getZMax()
+{
+ return m_zmax;
+}
+
+void G4Dipole::setZMin(double zmin)
+{
+ m_zmin = zmin;
+}
+
+double G4Dipole::getZMin()
+{
+ return m_zmin;
+}
+
+void G4Dipole::addCoeff(double coeff)
+{
+ m_coeffs.push_back(coeff);
+}
+
+const std::vector<double>& G4Dipole::getCoeffs()
+{
+ return m_coeffs;
+}
lcdd/src
diff -N dipoleProcess.cc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ dipoleProcess.cc 21 Apr 2006 23:50:53 -0000 1.1
@@ -0,0 +1,77 @@
+// $Header: /cvs/lcd/lcdd/src/dipoleProcess.cc,v 1.1 2006/04/21 23:50:53 jeremy Exp $
+#ifndef dipoleProcess_hh
+#define dipoleProcess_hh 1
+
+// gdml
+#include "Saxana/ProcessingConfigurator.h"
+#include "Saxana/ProcessingContext.h"
+#include "Saxana/SAXProcessor.h"
+#include "Saxana/StateStack.h"
+#include "Saxana/SAXProcessingState.h"
+#include "Saxana/SAXStateProcess.h"
+#include "Saxana/SAXComponentFactory.h"
+
+#include "dipole.hh"
+
+/**
+ * @class dipoleProcess
+ * @brief SAX process for the dipole element.
+ */
+class dipoleProcess : public SAXStateProcess
+{
+public:
+
+ dipoleProcess(const ProcessingContext* context = 0)
+ : SAXStateProcess(context),
+ m_obj(0)
+ {}
+
+ virtual ~dipoleProcess()
+ {}
+
+ virtual const SAXComponentObject* Build() const
+ {
+ return this;
+ }
+
+ virtual void StartElement(const std::string&, const ASCIIAttributeList& attrs)
+ {
+ SAXObject** obj = Context()->GetTopObject();
+
+ dipole* d = new dipole;
+ d->set_name(attrs.getValue("name"));
+ d->set_lunit(attrs.getValue("lunit"));
+ d->set_funit(attrs.getValue("funit"));
+ d->set_zmax(attrs.getValue("zmax"));
+ d->set_zmin(attrs.getValue("zmin"));
+
+ m_obj = d;
+ *obj = d;
+ }
+
+ virtual void EndElement(const std::string&)
+ {}
+
+ virtual void Characters(const std::string&)
+ {}
+
+ virtual void StackPopNotify(const std::string& name)
+ {
+ SAXObject** so = Context()->GetTopObject();
+ dipole* d = dynamic_cast<dipole*>(m_obj);
+ d->add_content(name,*so);
+ }
+
+ virtual const std::string& State() const
+ {
+ static std::string tag = "dipole";
+ return tag;
+ }
+
+private:
+ SAXObject* m_obj;
+};
+
+DECLARE_PROCESS_FACTORY(dipoleProcess);
+
+#endif
lcdd/src
diff -N dipoleSubscriber.cc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ dipoleSubscriber.cc 21 Apr 2006 23:50:53 -0000 1.1
@@ -0,0 +1,97 @@
+// $Header: /cvs/lcd/lcdd/src/dipoleSubscriber.cc,v 1.1 2006/04/21 23:50:53 jeremy Exp $
+#include "Saxana/SAXSubscriber.h"
+#include "Saxana/SAXComponentFactory.h"
+
+#include "G4Processor/GDMLProcessor.h"
+#include "G4Evaluator/GDMLExpressionEvaluator.h"
+
+// processor
+#include "LCDDProcessor.hh"
+
+// element
+#include "dipole.hh"
+#include "dipole_coeff.hh"
+
+// Geant4
+#include "G4Dipole.hh"
+
+/**
+ * @class dipoleSubscriber
+ * @brief Creates G4Dipole objects from dipole elements.
+ */
+class dipoleSubscriber : virtual public SAXSubscriber
+{
+
+public:
+ virtual const SAXComponentObject* Build() const
+ {
+ return this;
+ }
+
+public:
+ dipoleSubscriber()
+ {
+ Subscribe("dipole");
+ }
+
+ virtual ~dipoleSubscriber()
+ {}
+
+ virtual void Activate(const SAXObject* object)
+ {
+ GDMLExpressionEvaluator* calc = GDMLProcessor::GetInstance()->GetEvaluator();
+
+ if (object) {
+ const dipole* d = dynamic_cast<const dipole*>(object);
+
+ if (d) {
+ double zmin, zmax;
+
+ std::string lunit = d->get_lunit();
+ std::string funit = d->get_funit();
+
+ // Evaluate zmin with lunit.
+ std::string sval = d->get_zmin();
+ sval += "*" + lunit;
+ zmin = calc->Eval(sval);
+
+ // Evalute zmax with lunit.
+ sval = d->get_zmax();
+ sval += "*" + lunit;
+ zmax = calc->Eval(sval);
+
+ // Create the Geant4 dipole object.
+ G4Dipole* g4d = new G4Dipole();
+
+ // Set zmin and zmax.
+ g4d->setZMax(zmax);
+ g4d->setZMin(zmin);
+
+ // Add the dipole coefficients.
+ ContentSequence* seq = const_cast<ContentSequence*> (d->get_content());
+ size_t count = seq->size();
+ for(size_t i=0; i<count; i++) {
+ const ContentGroup::ContentItem& elem = seq->content(i);
+ if (elem.tag == "dipole_coeff") {
+ dipole_coeff* coeff = dynamic_cast<dipole_coeff*>(elem.object);
+
+ // Coefficients are unitless, so don't * with funit. (f/ N. Graf)
+ g4d->addCoeff(calc->Eval(coeff->get_value()));
+ }
+ else {
+ std::cerr << "dipoleSubscriber :: Activate - The element " << elem.tag << " is not a dipole_coeff!" << std::endl;
+ }
+ }
+
+ // Add the G4Dipole to the magnetic field store.
+ std::string field_name = d->get_name();
+ LCDDProcessor::instance()->addMagneticField(field_name, g4d);
+ }
+ else {
+ std::cerr << "dipoleSubscriber :: Activate - Failed cast to dipole!" << std::endl;
+ }
+ }
+ };
+};
+
+DECLARE_SUBSCRIBER_FACTORY(dipoleSubscriber);
CVSspam 0.2.8