Belle II Software  release-06-02-00
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 
22 using namespace std;
23 using namespace Belle2;
24 
25 //-----------------------------------------------------------------
26 // Register the Module
27 //-----------------------------------------------------------------
28 REG_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.");
38  setPropertyFlags(c_Input);
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 
58 TouschekTURTLEInputModule::~TouschekTURTLEInputModule()
59 {
60  delete m_readerHER;
61  delete m_readerLER;
62 }
63 
64 
65 void TouschekTURTLEInputModule::initialize()
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
77  if ((m_readHER) && (!FileSystem::fileExists(m_filenameHER))) {
78  B2ERROR("Parameter <FilenameHER>: Could not open the file. The filename " << m_filenameHER << " does not exist !");
79  } else m_readerHER->open(m_filenameHER);
80 
81  if ((m_readLER) && (!FileSystem::fileExists(m_filenameLER))) {
82  B2ERROR("Parameter <FilenameLER>: Could not open the file. The filename " << m_filenameLER << " does not exist !");
83  } else m_readerLER->open(m_filenameLER);
84 
85  //Get the transformation from local Touschek plane space to global geant4 space
86  //For the HER
87  GearDir irDir = Gearbox::getInstance().getDetectorComponent("Cryostat");
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 
95 void TouschekTURTLEInputModule::event()
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
108  mpg.generateList("", MCParticleGraph::c_setDecayInfo | MCParticleGraph::c_checkCyclic);
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 }
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.
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
bool registerInDataStore(DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut)
Register the object/array in the DataStore.
Class to read Touschek files and store their content in a MCParticle graph.
The TouschekTURTLE Input module.
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
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
@ c_Input
Input Process.
Abstract base class for different kinds of events.