9#include <generators/touschek/TouschekReaderTURTLE.h>
11#include <framework/logging/Logger.h>
12#include <framework/gearbox/Unit.h>
13#include <mdst/dataobjects/MCParticle.h>
15#include <boost/lexical_cast.hpp>
16#include <boost/algorithm/string.hpp>
17#include <boost/tokenizer.hpp>
39 if (!
m_input)
throw(TouschekCouldNotOpenFileError() << filename);
46 B2ERROR(
"The transformation matrix is NULL !");
51 typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
52 boost::char_separator<char> sep(
",; \t");
54 double particlePosTouschek[3] = {0.0, 0.0, 0.0};
55 double particlePosGeant4[3] = {0.0, 0.0, 0.0};
56 double particleMomTouschek[3] = {0.0, 0.0, 0.0};
57 double particleMomGeant4[3] = {0.0, 0.0, 0.0};
63 boost::trim(currLine);
64 if (currLine ==
"")
continue;
66 tokenizer tokens(currLine, sep);
69 for (
const string& tok : tokens) {
72 B2WARNING(
"This Touschek file has more than 7 fields ! Only the first 7 fields were read.");
75 fields[index] = boost::lexical_cast<double>(tok);
77 }
catch (boost::bad_lexical_cast&) {
78 throw (TouschekConvertFieldError() <<
m_lineNum << index << tok);
84 particlePosTouschek[0] = fields[2] *
Unit::m;
85 particlePosTouschek[1] = -fields[3] *
Unit::m;
86 if (
m_pdg == -11) particlePosTouschek[2] = 400.0;
87 else if (
m_pdg == 11) particlePosTouschek[2] = -400.0;
88 else { B2WARNING(
"m_pdg is not 11/-11");
break;}
90 m_transMatrix->LocalToMaster(particlePosTouschek, particlePosGeant4);
94 particleMomTouschek[0] = fields[4];
95 particleMomTouschek[1] = -fields[5];
96 if (
m_pdg == -11) particleMomTouschek[2] = -fields[6];
97 else if (
m_pdg == 11) particleMomTouschek[2] = fields[6];
98 else { B2WARNING(
"m_pdg is not 11/-11");
break;}
100 m_transMatrix->LocalToMasterVect(particleMomTouschek, particleMomGeant4);
102 double totalMom2 = particleMomGeant4[0] * particleMomGeant4[0];
103 totalMom2 += particleMomGeant4[1] * particleMomGeant4[1];
104 totalMom2 += particleMomGeant4[2] * particleMomGeant4[2];
109 particle.setPDG(
m_pdg);
110 particle.setMassFromPDG();
111 particle.setMomentum(ROOT::Math::XYZVector(particleMomGeant4[0], particleMomGeant4[1], particleMomGeant4[2]));
112 particle.setProductionVertex(ROOT::Math::XYZVector(particlePosGeant4[0], particlePosGeant4[1], particlePosGeant4[2]));
113 particle.setEnergy(
sqrt(totalMom2 + particle.getMass()*particle.getMass()));
114 particle.setProductionTime(0.0);
115 particle.setValidVertex(
true);
118 }
while ((!
m_input.eof()) && ((number > -1) && (numParticles < number)));
Class to represent Particle data in graph.
Class to build, validate and sort a particle decay chain.
@ c_PrimaryParticle
bit 0: Particle is primary particle.
TouschekReaderTURTLE(TGeoHMatrix *transMatrix, int pdg)
Constructor of the TouschekReader class.
~TouschekReaderTURTLE()
Destructor.
int m_lineNum
The line number in the ascii file of the last particle which was read.
TGeoHMatrix * m_transMatrix
Transformation matrix from local Touschek to global geant4 space.
int m_pdg
The pdg value of the type of particle that is read (e.g.
void open(const std::string &filename)
Opens an ascii file and prepares it for reading.
std::ifstream m_input
The input stream of the ascii file.
int getParticles(int number, MCParticleGraph &graph)
Reads the specified number of particles from the file and stores the result in the given MCParticle g...
static const double m
[meters]
double sqrt(double a)
sqrt for double
GraphParticle & addParticle()
Add new particle to the graph.
Abstract base class for different kinds of events.