Belle II Software  release-05-01-25
TouschekTURTLEInputModule.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010-2011 Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Andreas Moll *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <generators/modules/TouschekTURTLEInputModule.h>
12 
13 #include <framework/datastore/StoreArray.h>
14 
15 #include <framework/gearbox/Gearbox.h>
16 #include <framework/gearbox/GearDir.h>
17 #include <framework/gearbox/Unit.h>
18 #include <framework/utilities/FileSystem.h>
19 
20 #include <generators/touschek/TouschekReaderTURTLE.h>
21 
22 #include <fstream>
23 
24 using namespace std;
25 using namespace Belle2;
26 
27 //-----------------------------------------------------------------
28 // Register the Module
29 //-----------------------------------------------------------------
30 REG_MODULE(TouschekTURTLEInput)
31 
32 //-----------------------------------------------------------------
33 // Implementation
34 //-----------------------------------------------------------------
35 
37 {
38  //Set module properties
39  setDescription("Reads the Touschek data from a TURTLE file and stores it into the MCParticle collection.");
40  setPropertyFlags(c_Input);
41 
42  //Parameter definition
43  addParam("FilenameHER", m_filenameHER, "The filename of the HER TURTLE input file.");
44  addParam("FilenameLER", m_filenameLER, "The filename of the LER TURTLE input file.");
45  addParam("ReadHER", m_readHER, "Set to false to skip reading the HER data.", true);
46  addParam("ReadLER", m_readLER, "Set to false to skip reading the LER data.", true);
47  addParam("zCoordinate", m_zPos,
48  "Indicates the z-coordinate of the TURTLE particles in the file. (default is 50cm, 400cm is also implemented.)", 50.0);
49  addParam("MaxParticles", m_maxParticles,
50  "The maximum number of particles per event that should be read. -1 means all of the particles are read.", -1);
51 
52  //Create and initialize member variables
53  m_herPipePartMatrix = new TGeoHMatrix("TouschekPlaneHER");
54  m_lerPipePartMatrix = new TGeoHMatrix("TouschekPlaneLER");
55  m_readerHER = new TouschekReaderTURTLE(m_herPipePartMatrix, 11); //HER: electrons
56  m_readerLER = new TouschekReaderTURTLE(m_lerPipePartMatrix, -11); //LER: positrons
57 }
58 
59 
60 TouschekTURTLEInputModule::~TouschekTURTLEInputModule()
61 {
62  delete m_readerHER;
63  delete m_readerLER;
64 }
65 
66 
67 void TouschekTURTLEInputModule::initialize()
68 {
69  //Check if the Gearbox is ready for reading
70  if (!Gearbox::getInstance().isOpen()) {
71  B2FATAL("The Touschek Turtle input module requires a valid Gearbox. Please make sure you have the Gearbox module added to your path.");
72  }
73 
74  //Initialize MCParticle collection
75  StoreArray<MCParticle> mcparticle;
76  mcparticle.registerInDataStore();
77 
78  //Check parameters
79  if ((m_readHER) && (!FileSystem::fileExists(m_filenameHER))) {
80  B2ERROR("Parameter <FilenameHER>: Could not open the file. The filename " << m_filenameHER << " does not exist !");
81  } else m_readerHER->open(m_filenameHER);
82 
83  if ((m_readLER) && (!FileSystem::fileExists(m_filenameLER))) {
84  B2ERROR("Parameter <FilenameLER>: Could not open the file. The filename " << m_filenameLER << " does not exist !");
85  } else m_readerLER->open(m_filenameLER);
86 
87  //Get the transformation from local Touschek plane space to global geant4 space
88  //For the HER
89  GearDir irDir = Gearbox::getInstance().getDetectorComponent("Cryostat");
90  double angleher = irDir.getAngle("AngleHER");
91  double angleler = irDir.getAngle("AngleLER");
92  m_herPipePartMatrix->RotateY(angleher / Unit::deg);
93  m_lerPipePartMatrix->RotateY(angleler / Unit::deg);
94 }
95 
96 
97 void TouschekTURTLEInputModule::event()
98 {
99  try {
100  int readHERParticles = 0;
101  int readLERParticles = 0;
102 
103  //Read the data
104  MCParticleGraph mpg;
105  if (m_readHER) readHERParticles = m_readerHER->getParticles(m_maxParticles, mpg); //HER: electrons
106  if (m_readLER) readLERParticles = m_readerLER->getParticles(m_maxParticles, mpg); //LER: positrons
107 
108  if ((readHERParticles > 0) || (readLERParticles > 0)) {
109  //Generate MCParticle list
110  mpg.generateList("", MCParticleGraph::c_setDecayInfo | MCParticleGraph::c_checkCyclic);
111 
112  B2INFO("Read " << readHERParticles << " e- particles (HER).");
113  B2INFO("Read " << readLERParticles << " e+ particles (LER).");
114  }
115  } catch (runtime_error& exc) {
116  B2ERROR(exc.what());
117  }
118 }
Belle2::TouschekReaderTURTLE
Class to read Touschek files and store their content in a MCParticle graph.
Definition: TouschekReaderTURTLE.h:44
Belle2::MCParticleGraph::generateList
void generateList(const std::string &name="", int options=c_setNothing)
Generates the MCParticle list and stores it in the StoreArray with the given name.
Definition: MCParticleGraph.cc:211
Belle2::TouschekTURTLEInputModule
The TouschekTURTLE Input module.
Definition: TouschekTURTLEInputModule.h:42
Belle2::gearbox::Interface::getAngle
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:301
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::MCParticleGraph
Class to build, validate and sort a particle decay chain.
Definition: MCParticleGraph.h:48
Belle2::Module
Base class for Modules.
Definition: Module.h:74
Belle2::ProcType::c_Input
@ c_Input
Input Process.
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::GearDir
GearDir is the basic class used for accessing the parameter store.
Definition: GearDir.h:41
Belle2::StoreArray< MCParticle >