11 #include <generators/modules/SADInputModule.h>
12 #include <mdst/dataobjects/MCParticleGraph.h>
14 #include <framework/logging/Logger.h>
15 #include <framework/utilities/FileSystem.h>
17 #include <framework/gearbox/Unit.h>
18 #include <framework/gearbox/GearDir.h>
20 #include <framework/datastore/StoreArray.h>
22 #include <TGeoMatrix.h>
39 setDescription(
"Reads the SAD data from a root file and stores it into the MCParticle collection.");
43 addParam(
"AccRing", m_accRing,
"The accelerator ring: 0 = LER, 1 = HER");
44 addParam(
"ReadoutTime", m_readoutTime,
"The readout time of the detector [ns]", 20 * Unit::us);
45 addParam(
"ReadMode", m_readMode,
46 "The read mode: 0 = one SAD particle per event, 1 = one real particle per event, 2 = all SAD particles per event", 0);
47 addParam(
"Filename", m_filename,
"The filename of the SAD input file.");
48 addParam(
"Range", m_range,
"All particles within the range around the IP are loaded [cm].", 300.0 * Unit::cm);
49 addParam(
"PxResolution", m_pxRes,
"The resolution for the x momentum component of the SAD real particle.", 0.01);
50 addParam(
"PyResolution", m_pyRes,
"The resolution for the y momentum component of the SAD real particle.", 0.01);
51 addParam(
"RotateParticles", m_rotateParticles,
52 "Rotate the SAD particles around the nominal beam axis [deg] (just for unphysical tests !!!).", 0.0);
54 m_PipePartMatrix = NULL;
58 void SADInputModule::initialize()
61 m_eventMetaDataPtr.isRequired();
63 mcParticles.registerInDataStore();
66 if (!FileSystem::fileExists(m_filename)) {
67 B2ERROR(
"Parameter <Filename>: Could not open the file. The filename " << m_filename <<
" does not exist !");
68 }
else m_reader.open(m_filename);
72 m_PipePartMatrix =
new TGeoHMatrix(
"SADTrafo");
73 m_PipePartMatrix->RotateZ(m_rotateParticles);
75 GearDir ler(
"/Detector/SuperKEKB/LER/");
76 GearDir her(
"/Detector/SuperKEKB/HER/");
79 case 0 : m_PipePartMatrix->RotateY(ler.getDouble(
"angle") / Unit::deg);
80 m_reader.initialize(m_PipePartMatrix, m_range, ReaderSAD::c_LER, m_readoutTime);
82 case 1 : m_PipePartMatrix->RotateY(her.getDouble(
"angle") / Unit::deg);
83 m_reader.initialize(m_PipePartMatrix, m_range, ReaderSAD::c_HER, m_readoutTime);
85 default: B2FATAL(
"Please specify a valid number for the accRing parameter (0 = LER, 1 = HER) !");
89 m_reader.setMomentumRes(m_pxRes, m_pyRes);
93 void SADInputModule::event()
102 switch (m_readMode) {
103 case 0: readSADParticle(m_reader, mpg);
105 case 1: readRealParticle(m_reader, mpg);
107 case 2: m_reader.addAllSADParticles(mpg);
109 default: B2FATAL(
"Please specify a valid number for the readMode parameter !");
116 mpg.
generateList(
"", MCParticleGraph::c_setDecayInfo | MCParticleGraph::c_checkCyclic);
118 }
catch (ReaderSAD::SADEndOfFile& exc) {
119 B2DEBUG(10, exc.what());
120 m_eventMetaDataPtr->setEndOfData();
123 }
catch (runtime_error& exc) {
135 double rate = reader.getSADParticle(mpg);
136 if (rate < 0)
return;
137 m_eventMetaDataPtr->setGeneratedWeight(rate);
142 if (!reader.getRealParticle(mpg))
return;
143 m_eventMetaDataPtr->setGeneratedWeight(1.0);