9 #include <generators/modules/SADInputModule.h>
10 #include <mdst/dataobjects/MCParticleGraph.h>
12 #include <framework/logging/Logger.h>
13 #include <framework/utilities/FileSystem.h>
15 #include <framework/gearbox/Unit.h>
16 #include <framework/gearbox/GearDir.h>
18 #include <framework/datastore/StoreArray.h>
20 #include <TGeoMatrix.h>
37 setDescription(
"Reads the SAD data from a root file and stores it into the MCParticle collection.");
41 addParam(
"AccRing", m_accRing,
"The accelerator ring: 0 = LER, 1 = HER");
42 addParam(
"ReadoutTime", m_readoutTime,
"The readout time of the detector [ns]", 20 * Unit::us);
43 addParam(
"ReadMode", m_readMode,
44 "The read mode: 0 = one SAD particle per event, 1 = one real particle per event, 2 = all SAD particles per event", 0);
45 addParam(
"Filename", m_filename,
"The filename of the SAD input file.");
46 addParam(
"Range", m_range,
"All particles within the range around the IP are loaded [cm].", 300.0 * Unit::cm);
47 addParam(
"PxResolution", m_pxRes,
"The resolution for the x momentum component of the SAD real particle.", 0.01);
48 addParam(
"PyResolution", m_pyRes,
"The resolution for the y momentum component of the SAD real particle.", 0.01);
49 addParam(
"RotateParticles", m_rotateParticles,
50 "Rotate the SAD particles around the nominal beam axis [deg] (just for unphysical tests !!!).", 0.0);
52 m_PipePartMatrix = NULL;
56 void SADInputModule::initialize()
59 m_eventMetaDataPtr.isRequired();
64 if (!FileSystem::fileExists(m_filename)) {
65 B2ERROR(
"Parameter <Filename>: Could not open the file. The filename " << m_filename <<
" does not exist !");
66 }
else m_reader.open(m_filename);
70 m_PipePartMatrix =
new TGeoHMatrix(
"SADTrafo");
71 m_PipePartMatrix->RotateZ(m_rotateParticles);
73 GearDir ler(
"/Detector/SuperKEKB/LER/");
74 GearDir her(
"/Detector/SuperKEKB/HER/");
77 case 0 : m_PipePartMatrix->RotateY(ler.getDouble(
"angle") / Unit::deg);
78 m_reader.initialize(m_PipePartMatrix, m_range, ReaderSAD::c_LER, m_readoutTime);
80 case 1 : m_PipePartMatrix->RotateY(her.getDouble(
"angle") / Unit::deg);
81 m_reader.initialize(m_PipePartMatrix, m_range, ReaderSAD::c_HER, m_readoutTime);
83 default: B2FATAL(
"Please specify a valid number for the accRing parameter (0 = LER, 1 = HER) !");
87 m_reader.setMomentumRes(m_pxRes, m_pyRes);
91 void SADInputModule::event()
100 switch (m_readMode) {
101 case 0: readSADParticle(m_reader, mpg);
103 case 1: readRealParticle(m_reader, mpg);
105 case 2: m_reader.addAllSADParticles(mpg);
107 default: B2FATAL(
"Please specify a valid number for the readMode parameter !");
114 mpg.
generateList(
"", MCParticleGraph::c_setDecayInfo | MCParticleGraph::c_checkCyclic);
116 }
catch (ReaderSAD::SADEndOfFile& exc) {
117 B2DEBUG(10, exc.what());
118 m_eventMetaDataPtr->setEndOfData();
121 }
catch (runtime_error& exc) {
133 double rate = reader.getSADParticle(mpg);
134 if (rate < 0)
return;
135 m_eventMetaDataPtr->setGeneratedWeight(rate);
140 if (!reader.getRealParticle(mpg))
return;
141 m_eventMetaDataPtr->setGeneratedWeight(1.0);
GearDir is the basic class used for accessing the parameter store.
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.
Class to read files that have been created by SAD and store their content in a MCParticle graph.
bool registerInDataStore(DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut)
Register the object/array in the DataStore.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Abstract base class for different kinds of events.