Belle II Software development
TouschekReaderTURTLE Class Reference

Class to read Touschek files and store their content in a MCParticle graph. More...

#include <TouschekReaderTURTLE.h>

Public Member Functions

 BELLE2_DEFINE_EXCEPTION (TouschekCouldNotOpenFileError, "Could not open file %1% !")
 Exception is thrown if the Touschek file could not be opened.
 
 BELLE2_DEFINE_EXCEPTION (TouschekConvertFieldError, "Line %1%: Could not convert field %2%: %3%")
 Exception is thrown if a field in the Touschek file could not be converted to a number.
 
 TouschekReaderTURTLE (TGeoHMatrix *transMatrix, int pdg)
 Constructor of the TouschekReader class.
 
 ~TouschekReaderTURTLE ()
 Destructor.
 
void open (const std::string &filename)
 Opens an ascii file and prepares it for reading.
 
int getParticles (int number, MCParticleGraph &graph)
 Reads the specified number of particles from the file and stores the result in the given MCParticle graph.
 

Protected Attributes

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.
 
std::ifstream m_input
 The input stream of the ascii file.
 
int m_lineNum
 The line number in the ascii file of the last particle which was read.
 

Detailed Description

Class to read Touschek files and store their content in a MCParticle graph.

The reader supports retrieving the Touschek information from an ascii text file.

The file contains just a list of particles, defined at plane +-50cm from the IP. The reader reads either a specified number of particles from the file, or all particles.

Definition at line 34 of file TouschekReaderTURTLE.h.

Constructor & Destructor Documentation

◆ TouschekReaderTURTLE()

TouschekReaderTURTLE ( TGeoHMatrix *  transMatrix,
int  pdg 
)

Constructor of the TouschekReader class.

Parameters
transMatrixPointer to the matrix which transforms the particles from the local Touschek to the global geant4 coordinate system.
pdgThe pdg value of the type of particle that is read (e.g. 11 for e-, -11 for e+).

Definition at line 23 of file TouschekReaderTURTLE.cc.

23 : m_transMatrix(transMatrix), m_pdg(pdg),
24 m_lineNum(0)
25{
26}
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.

◆ ~TouschekReaderTURTLE()

Destructor.

Definition at line 29 of file TouschekReaderTURTLE.cc.

30{
31 if (m_input) m_input.close();
32}
std::ifstream m_input
The input stream of the ascii file.

Member Function Documentation

◆ getParticles()

int getParticles ( int  number,
MCParticleGraph graph 
)

Reads the specified number of particles from the file and stores the result in the given MCParticle graph.

The number of the last particle which was read is saved. So the next time this method is called the reading continues at the position where the last particle which was read.

Parameters
numberThe number of particles that should be read from the file. Set it to -1 to read all particles.
graphReference to the graph which should be filled with the information from the Touschek file.
Returns
The number of particles which were read.

Definition at line 43 of file TouschekReaderTURTLE.cc.

44{
45 if (m_transMatrix == NULL) {
46 B2ERROR("The transformation matrix is NULL !");
47 }
48
49 int numParticles = 0;
50 string currLine;
51 typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
52 boost::char_separator<char> sep(",; \t");
53 double fields[7];
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};
58
59 do {
60 getline(m_input, currLine);
61 m_lineNum++;
62
63 boost::trim(currLine);
64 if (currLine == "") continue;
65
66 tokenizer tokens(currLine, sep);
67
68 int index = 0;
69 for (const string& tok : tokens) {
70 try {
71 if (index >= 7) {
72 B2WARNING("This Touschek file has more than 7 fields ! Only the first 7 fields were read.");
73 break;
74 }
75 fields[index] = boost::lexical_cast<double>(tok);
76 index++;
77 } catch (boost::bad_lexical_cast&) {
78 throw (TouschekConvertFieldError() << m_lineNum << index << tok);
79 }
80 }
81
82 //Convert the position of the particle from local Touschek plane space to global geant4 space.
83 //Flip the sign for the y and z component to go from the accelerator to the detector coordinate system
84 particlePosTouschek[0] = fields[2] * Unit::m;
85 particlePosTouschek[1] = -fields[3] * Unit::m;
86 if (m_pdg == -11) particlePosTouschek[2] = 400.0; //forLER
87 else if (m_pdg == 11) particlePosTouschek[2] = -400.0; //forHER
88 else { B2WARNING("m_pdg is not 11/-11"); break;}
89
90 m_transMatrix->LocalToMaster(particlePosTouschek, particlePosGeant4);
91
92 //Convert the momentum of the particle from local Touschek plane space to global geant4 space.
93 //Flip the sign for the y and z component to go from the accelerator to the detector coordinate system
94 particleMomTouschek[0] = fields[4];
95 particleMomTouschek[1] = -fields[5];
96 if (m_pdg == -11) particleMomTouschek[2] = -fields[6]; //forLER
97 else if (m_pdg == 11) particleMomTouschek[2] = fields[6]; //forHER
98 else { B2WARNING("m_pdg is not 11/-11"); break;}
99
100 m_transMatrix->LocalToMasterVect(particleMomTouschek, particleMomGeant4);
101
102 double totalMom2 = particleMomGeant4[0] * particleMomGeant4[0];
103 totalMom2 += particleMomGeant4[1] * particleMomGeant4[1];
104 totalMom2 += particleMomGeant4[2] * particleMomGeant4[2];
105
106 //Add particles to MCParticle collection
108 particle.setStatus(MCParticle::c_PrimaryParticle);
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);
116
117 numParticles++;
118 } while ((!m_input.eof()) && ((number > -1) && (numParticles < number)));
119
120 return numParticles;
121}
Class to represent Particle data in graph.
@ c_PrimaryParticle
bit 0: Particle is primary particle.
Definition: MCParticle.h:47
static const double m
[meters]
Definition: Unit.h:69
double sqrt(double a)
sqrt for double
Definition: beamHelpers.h:28
GraphParticle & addParticle()
Add new particle to the graph.

◆ open()

void open ( const std::string &  filename)

Opens an ascii file and prepares it for reading.

Parameters
filenameThe filename of the Touschek ascii file which should be read.

Definition at line 35 of file TouschekReaderTURTLE.cc.

36{
37 m_lineNum = 0;
38 m_input.open(filename.c_str());
39 if (!m_input) throw(TouschekCouldNotOpenFileError() << filename);
40}

Member Data Documentation

◆ m_input

std::ifstream m_input
protected

The input stream of the ascii file.

Definition at line 78 of file TouschekReaderTURTLE.h.

◆ m_lineNum

int m_lineNum
protected

The line number in the ascii file of the last particle which was read.

Definition at line 79 of file TouschekReaderTURTLE.h.

◆ m_pdg

int m_pdg
protected

The pdg value of the type of particle that is read (e.g.

11 for e-, -11 for e+).

Definition at line 77 of file TouschekReaderTURTLE.h.

◆ m_transMatrix

TGeoHMatrix* m_transMatrix
protected

Transformation matrix from local Touschek to global geant4 space.

Definition at line 76 of file TouschekReaderTURTLE.h.


The documentation for this class was generated from the following files: