12 #include <b2bii/modules/BelleMCOutput/BelleMCOutputModule.h>
15 #include <framework/gearbox/Unit.h>
16 #include <framework/logging/Logger.h>
19 #include <belle_legacy/tables/belletdf.h>
20 #include <belle_legacy/tables/hepevt.h>
21 #include <belle_legacy/tables/filespec.h>
33 setDescription(
"Output of MC particle list in Belle format.");
35 addParam(
"outputFileName", m_OutputFileName,
36 "Output file name.", std::string(
"belle_mc.mdst"));
37 addParam(
"decayKsInGenerator", m_DecayKsInGenerator,
38 "Decay K_S0 in generator.",
false);
39 addParam(
"decayLambdaInGenerator", m_DecayLambdaInGenerator,
40 "Decay Lambda in generator.",
false);
56 "************ ATTENTION! ************\n"
58 " Belle MC generation differs from Belle II. In order to generate MC "
59 "correctly, you must do the following:\n"
61 " 1. Use global tag with smearing of beam parameters and generation "
62 "flags: b2bii_beamParameters_with_smearing (there are no smearing data "
63 "or generation flags in the tags B2BII or B2BII_MC).\n"
64 " 2. Disable smearing in Belle simulation by removing the module "
65 "\"bpsmear\" from basf gsim scripts.\n"
67 "It is also necessary to consider the following differences:\n"
69 " 1. When converting the simulation result back to Belle II format, "
70 "it is recommended to disable conversion of beam parameters "
71 "(convertBeamParameters = False). Since the format of the table "
72 "BELLE_NOMINAL_BEAM is not sufficient to store an arbitrary covariance "
73 "matrix, the covariance matrix of IP position (BeamSpot) is not guaranteed "
74 "to be exactly the same after conversion.\n"
75 " 2. By default, decays of long-lived particles are removed and particles "
76 "are declared to be stable in generator (ISTHEP == 1 in basf) because "
77 "such decays are simulated by GEANT3 in basf. However, you may choose "
78 "to decay such particles via module parameters. This results in direct "
79 "passing of the decay products to simulation, i.e. material effects are "
80 "ignored. In this case, you may need to perform an additional study "
81 "of the difference between data and MC.\n"
83 "************************************\n"
89 Belle::Belle_file_specification_Manager& fileManager =
90 Belle::Belle_file_specification_Manager::get_manager();
95 Belle::Belle_file_specification& file = fileManager.add();
100 Belle::Belle_runhead_Manager& runheadManager =
101 Belle::Belle_runhead_Manager::get_manager();
102 runheadManager.remove();
103 Belle::Belle_runhead& runhead = runheadManager.add();
107 runhead.Time(time(
nullptr));
111 runhead.ELER(momentumLER.E());
112 runhead.EHER(momentumHER.E());
113 Belle::Belle_nominal_beam_Manager& beamManager =
114 Belle::Belle_nominal_beam_Manager::get_manager();
115 beamManager.remove();
116 Belle::Belle_nominal_beam& beam = beamManager.add();
117 beam.px_high(momentumHER.X());
118 beam.py_high(momentumHER.Y());
119 beam.pz_high(momentumHER.Z());
120 beam.px_low(momentumLER.X());
121 beam.py_low(momentumLER.Y());
122 beam.pz_low(momentumLER.Z());
124 beam.sigma_p_high(sqrt(herCovariance[0][0]));
126 beam.sigma_p_low(sqrt(lerCovariance[0][0]));
132 beam.ip_x(vertex.X());
133 beam.ip_y(vertex.Y());
134 beam.ip_z(vertex.Z());
136 beam.cang_high(momentumHER.Vect().Theta());
137 beam.cang_low(M_PI - momentumLER.Vect().Theta());
138 double angleIPZX = momentumHER.Vect().Theta() / 2;
139 beam.angle_ip_zx(angleIPZX);
145 rotationY.RotateY(-angleIPZX);
146 TMatrixD rotationMatrix(3, 3);
147 rotationMatrix[0][0] = rotationY.XX();
148 rotationMatrix[0][1] = rotationY.XY();
149 rotationMatrix[0][2] = rotationY.XZ();
150 rotationMatrix[1][0] = rotationY.YX();
151 rotationMatrix[1][1] = rotationY.YY();
152 rotationMatrix[1][2] = rotationY.YZ();
153 rotationMatrix[2][0] = rotationY.ZX();
154 rotationMatrix[2][1] = rotationY.ZY();
155 rotationMatrix[2][2] = rotationY.ZZ();
156 TMatrixDSym vertexCovariance2 = vertexCovariance.Similarity(rotationMatrix);
157 beam.sigma_ip_x(sqrt(vertexCovariance2[0][0]));
158 beam.sigma_ip_y(sqrt(vertexCovariance2[1][1]));
159 beam.sigma_ip_z(sqrt(vertexCovariance2[2][2]));
168 if (mother !=
nullptr)
169 part.comesFrom(*mother);
170 int pdg = abs(particle->getPDG());
186 std::vector<MCParticle*> daughters = particle->getDaughters();
193 Belle::Gen_hepevt_Manager& hepevtManager =
194 Belle::Gen_hepevt_Manager::get_manager();
195 hepevtManager.remove();
212 if (particle.getMother() ==
nullptr)
219 Belle::Gen_hepevt& hepevt = hepevtManager.add();
226 hepevt.idhep(particle.getPDG());
227 hepevt.reset_mother();
228 const MCParticle* mother = particle.getMother();
230 if (mother !=
nullptr)
231 motherIndex = mother->getIndex();
232 hepevt.moFirst(motherIndex);
233 hepevt.moLast(motherIndex);
234 hepevt.daFirst(particle.getFirstDaughter());
235 hepevt.daLast(particle.getLastDaughter());
236 TLorentzVector momentum = particle.get4Vector();
237 hepevt.PX(momentum.Px());
238 hepevt.PY(momentum.Py());
239 hepevt.PZ(momentum.Pz());
240 hepevt.E(momentum.E());
241 hepevt.M(particle.getMass());
242 TVector3 vertex = particle.getVertex();