00001
00002
00003
00004
00005
00006
00007 #include "instrument/MCTruth.h"
00008
00009 #include "instrument/DetectorVisitor.h"
00010 #include "instrument/DetectorConverter.h"
00011 #include "instrument/FluxGenerator.h"
00012
00013
00014 MCTruth* MCTruth::s_instance;
00015 const GlastDetector::_PersistKey MCTruth::classPersistKey =
00016 GlastDetector::_PersistKey("MCTruth");
00017
00018 namespace {
00019 bool MCTruthPersistFlag =
00020 GlastDetector::addPersistence(
00021 MCTruth::classPersistKey,
00022 new MCTruth::_Factory);
00023
00024 };
00025
00026
00027 MCTruth::MCTruth (const DOM_Element& elem)
00028 : GlastDetector(elem)
00029 {
00030 s_instance = this;
00031 }
00032
00033
00034 MCTruth::~MCTruth()
00035 {}
00036
00037 void
00038 MCTruth::accept(DetectorVisitor& v) {
00039 v.visit(this);
00040 GlastDetector::accept(v);
00041 }
00042
00043 void
00044 MCTruth::accept(DetectorConverter& c) {
00045 c.backward(*this);
00046 }
00047
00048 void
00049 MCTruth::accept(DetectorConverter& c) const {
00050 c.forward(*this);
00051 }
00053
00054
00055 template< class T>
00056 static inline T read_3_vector(std::istream& in, double f)
00057 {
00058 double x, y, z;
00059 in >> x >> y >> z;
00060 return T(x/f,y/f,z/f);
00061 }
00062
00063
00065
00074 void MCTruth::ParticleData::read (std::istream& in)
00075 {
00076 char name[10];
00077 double x,y,z;
00078 in >> name >> m_energy;
00079 m_name=std::string(name);
00080 #if 1
00081 in >> x >> y >> z;
00082 m_pos=Point(x,y,z);
00083 in >> x >> y >> z;
00084 m_p = 1.e-4*Vector(x,y,z);
00085 #else
00086 double one = 1.0;
00087 m_pos = read_3_vector<Point>( in, one );
00088 m_dir = read_3_vector<Vector>(in, 1.0e6);
00089 in >> m_code;
00090 in >> m_matZ;
00091
00092
00093 delete m_particles;
00094 m_particles = new ParticleData();
00095 m_particles->read (in);
00096 #endif
00097 }
00098
00099 void MCTruth::ParticleData::write ( std::ostream& out) const
00100 {
00101 out << m_name << " " << static_cast<int>(m_energy) << " ";
00102 out << static_cast<int>(m_pos.x()+0.5) << " ";
00103 out << static_cast<int>(m_pos.y()+0.5) << " ";
00104 out << static_cast<int>(m_pos.z()+0.5) << " ";
00105 out << static_cast<int>(m_p.x()*1e4) << " ";
00106 out << static_cast<int>(m_p.y()*1e4) << " ";
00107 out << static_cast<int>(m_p.z()*1e4) << " ";
00108
00109 }
00110
00111
00112 MCTruth::MCTruth(_Particle* p)
00113 : m_particle(p? p : new FluxGenerator), m_id(0)
00114 {
00115 s_instance = this;
00116 }