Belle II Software development
TouschekTURTLEInputModule.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#include <generators/modules/TouschekTURTLEInputModule.h>
10
11#include <framework/datastore/StoreArray.h>
12
13#include <framework/gearbox/Gearbox.h>
14#include <framework/gearbox/GearDir.h>
15#include <framework/gearbox/Unit.h>
16#include <framework/utilities/FileSystem.h>
17
18#include <generators/touschek/TouschekReaderTURTLE.h>
19
20#include <fstream>
21
22using namespace std;
23using namespace Belle2;
24
25//-----------------------------------------------------------------
26// Register the Module
27//-----------------------------------------------------------------
28REG_MODULE(TouschekTURTLEInput);
29
30//-----------------------------------------------------------------
31// Implementation
32//-----------------------------------------------------------------
33
35{
36 //Set module properties
37 setDescription("Reads the Touschek data from a TURTLE file and stores it into the MCParticle collection.");
39
40 //Parameter definition
41 addParam("FilenameHER", m_filenameHER, "The filename of the HER TURTLE input file.");
42 addParam("FilenameLER", m_filenameLER, "The filename of the LER TURTLE input file.");
43 addParam("ReadHER", m_readHER, "Set to false to skip reading the HER data.", true);
44 addParam("ReadLER", m_readLER, "Set to false to skip reading the LER data.", true);
45 addParam("zCoordinate", m_zPos,
46 "Indicates the z-coordinate of the TURTLE particles in the file. (default is 50cm, 400cm is also implemented.)", 50.0);
47 addParam("MaxParticles", m_maxParticles,
48 "The maximum number of particles per event that should be read. -1 means all of the particles are read.", -1);
49
50 //Create and initialize member variables
51 m_herPipePartMatrix = new TGeoHMatrix("TouschekPlaneHER");
52 m_lerPipePartMatrix = new TGeoHMatrix("TouschekPlaneLER");
53 m_readerHER = new TouschekReaderTURTLE(m_herPipePartMatrix, 11); //HER: electrons
54 m_readerLER = new TouschekReaderTURTLE(m_lerPipePartMatrix, -11); //LER: positrons
55}
56
57
59{
60 delete m_readerHER;
61 delete m_readerLER;
62}
63
64
66{
67 //Check if the Gearbox is ready for reading
68 if (!Gearbox::getInstance().isOpen()) {
69 B2FATAL("The Touschek Turtle input module requires a valid Gearbox. Please make sure you have the Gearbox module added to your path.");
70 }
71
72 //Initialize MCParticle collection
73 StoreArray<MCParticle> mcparticle;
74 mcparticle.registerInDataStore();
75
76 //Check parameters
78 B2ERROR("Parameter <FilenameHER>: Could not open the file. The filename " << m_filenameHER << " does not exist !");
80
82 B2ERROR("Parameter <FilenameLER>: Could not open the file. The filename " << m_filenameLER << " does not exist !");
84
85 //Get the transformation from local Touschek plane space to global geant4 space
86 //For the HER
88 double angleher = irDir.getAngle("AngleHER");
89 double angleler = irDir.getAngle("AngleLER");
90 m_herPipePartMatrix->RotateY(angleher / Unit::deg);
91 m_lerPipePartMatrix->RotateY(angleler / Unit::deg);
92}
93
94
96{
97 try {
98 int readHERParticles = 0;
99 int readLERParticles = 0;
100
101 //Read the data
102 MCParticleGraph mpg;
103 if (m_readHER) readHERParticles = m_readerHER->getParticles(m_maxParticles, mpg); //HER: electrons
104 if (m_readLER) readLERParticles = m_readerLER->getParticles(m_maxParticles, mpg); //LER: positrons
105
106 if ((readHERParticles > 0) || (readLERParticles > 0)) {
107 //Generate MCParticle list
109
110 B2INFO("Read " << readHERParticles << " e- particles (HER).");
111 B2INFO("Read " << readLERParticles << " e+ particles (LER).");
112 }
113 } catch (runtime_error& exc) {
114 B2ERROR(exc.what());
115 }
116}
static bool fileExists(const std::string &filename)
Check if the file with given filename exists.
Definition: FileSystem.cc:32
GearDir is the basic class used for accessing the parameter store.
Definition: GearDir.h:31
Class to build, validate and sort a particle decay chain.
@ c_checkCyclic
Check for cyclic dependencies.
@ c_setDecayInfo
Set decay time and vertex.
void generateList(const std::string &name="", int options=c_setNothing)
Generates the MCParticle list and stores it in the StoreArray with the given name.
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
Definition: Module.cc:208
@ c_Input
This module is an input module (reads data).
Definition: Module.h:78
bool registerInDataStore(DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut)
Register the object/array in the DataStore.
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
Class to read Touschek files and store their content in a MCParticle graph.
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 g...
std::string m_filenameHER
The filename of the HER TURTLE Touschek file.
virtual void initialize() override
Checks the validity of the module parameters.
virtual void event() override
Reads the data and stores it into the MCParticle collection.
int m_maxParticles
The maximum number of particles per event that should be read.
TGeoHMatrix * m_herPipePartMatrix
HER transformation matrix from TURTLE space into geant4 space.
TGeoHMatrix * m_lerPipePartMatrix
LER transformation matrix from TURTLE space into geant4 space.
TouschekReaderTURTLE * m_readerLER
The Touschek reader object for the LER data.
bool m_readLER
If set to true reads the LER data and adds it to the MCParticle collection.
std::string m_filenameLER
The filename of the LER TURTLE Touschek file.
double m_zPos
The z Coordinate for all particles in the list in the file.
TouschekReaderTURTLE * m_readerHER
The Touschek reader object for the HER data.
bool m_readHER
If set to true reads the HER data and adds it to the MCParticle collection.
static const double deg
degree to radians
Definition: Unit.h:109
double getAngle(const std::string &path="") const noexcept(false)
Get the parameter path as a double converted to the standard angle unit.
Definition: Interface.h:299
static Gearbox & getInstance()
Return reference to the Gearbox instance.
Definition: Gearbox.cc:81
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition: Module.h:560
GearDir getDetectorComponent(const std::string &component)
Return GearDir representing a given DetectorComponent.
Definition: Gearbox.cc:314
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
Abstract base class for different kinds of events.
STL namespace.