Belle II Software development
KoralW.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/* Own header. */
10#include <generators/koralw/KoralW.h>
11
12/* Basf2 headers. */
13#include <framework/gearbox/Unit.h>
14#include <framework/logging/Logger.h>
15
16/* ROOT headers. */
17#include <TRandom.h>
18
19using namespace std;
20using namespace Belle2;
21
22//Declaration of the KoralW FORTRAN methods and common blocks.
23extern"C" {
24
25 extern struct {
26 double q1[4];
27 double q2[4];
28 double p1[4];
29 double p2[4];
30 double p3[4];
31 double p4[4];
32 } momdec_;
33
34 extern struct {
35 double qeff1[4];
36 double qeff2[4];
37 double sphum[4];
38 double sphot[4][100];
39 int nphot;
40 } momset_;
41
42 extern struct {
43 int nevhep;
44 int nhep;
45 int isthep[2000];
46 int idhep[2000];
47 int jmohep[2000][2];
48 int jdahep[2000][2];
49 float phep[2000][5];
50 float vhep[2000][4];
51 } hepevt_;
52
53 void kw_setdatapath_(const char* filename, size_t* length);
54 void kw_readatax_(const char* filename, size_t* length, int* reset, const int* max, double* xpar);
55 void kw_initialize_(double* ecm, double* xpar);
56 void marini_(unsigned int* mar1, unsigned int* mar2, unsigned int* mar3);
57 void rmarin_(unsigned int* mar1, unsigned int* mar2, unsigned int* mar3);
58 void kw_make_();
59 void kw_finalize_();
60 void kw_getmomdec_(double* p1, double* p2, double* p3, double* p4);
61 void kw_getxsecmc_(double* xSecMC, double* xErrMC);
62
63 void koralw_warning_ecm_(const double* ecmconfig, const double* ecm)
64 {
65 B2WARNING("KORALW: Different center of mass energy in config file (obsolete), E=" << *ecmconfig << ", and from beam parameters, E="
66 << *ecm);
67 }
68
69}
70
71void KoralW::init(const std::string& dataPath, const std::string& userDataFile)
72{
73 if (dataPath.empty()) B2FATAL("KoralW: The specified data path is empty !");
74 if (userDataFile.empty()) B2FATAL("KoralW: The specified user data file is empty !");
75
76 //Make sure the dataPath ends with an "/"
77 string dataPathNew = dataPath;
78 if (dataPath[dataPath.length() - 1] != '/') dataPathNew += "/";
79
80 //Set the path to the data files
81 size_t pathLength = dataPathNew.size();
82 kw_setdatapath_(dataPathNew.c_str(), &pathLength);
83
84 //Load the default KoralW input data
85 int reset = 1;
86 const string defaultDataFile = dataPathNew + "KoralW_Default.data";
87 pathLength = defaultDataFile.size();
88 kw_readatax_(defaultDataFile.c_str(), &pathLength, &reset, &m_numXPar, m_XPar);
89
90 //Load the user KoralW input data
91 reset = 0;
92 pathLength = userDataFile.size();
93 kw_readatax_(userDataFile.c_str(), &pathLength, &reset, &m_numXPar, m_XPar);
94
95 //Initialize KoralW
96 kw_initialize_(&m_cmsEnergy, m_XPar);
97
98 //Initialize random number generator
99 unsigned int mar1 = gRandom->Integer(m_seed1); //The range for this seed seems to be [0, 900000000]
100 unsigned int mar2 = gRandom->Integer(m_seed2);
101 unsigned int mar3 = gRandom->Integer(m_seed3);
102 marini_(&mar1, &mar2, &mar3);
103 rmarin_(&mar1, &mar2, &mar3);
104}
105
106
107void KoralW::generateEvent(MCParticleGraph& mcGraph, ROOT::Math::XYZVector vertex, ROOT::Math::LorentzRotation boost)
108{
109 kw_make_();
110
111 //Store the particles with status id 3 and 2 as virtual particles, the particles with status id 1 as real particles
112 for (int iPart = 0; iPart < hepevt_.nhep; ++iPart) {
113 if (hepevt_.isthep[iPart] > 1) {
114 storeParticle(mcGraph, hepevt_.phep[iPart], hepevt_.vhep[iPart], hepevt_.idhep[iPart], vertex, boost, true);
115 } else {
116 storeParticle(mcGraph, hepevt_.phep[iPart], hepevt_.vhep[iPart], hepevt_.idhep[iPart], vertex, boost);
117 }
118 }
119}
120
121
123{
124 kw_finalize_();
125
126 //Get the cross section
127 kw_getxsecmc_(&m_crossSection, &m_crossSectionError);
128}
129
130//=========================================================================
131// Protected methods
132//=========================================================================
133
134void KoralW::storeParticle(MCParticleGraph& mcGraph, const float* mom, const float* vtx, int pdg, ROOT::Math::XYZVector vertex,
135 ROOT::Math::LorentzRotation boost, bool isVirtual, bool isInitial)
136{
137 // //Create particle
138 //MCParticleGraph::GraphParticle& part = mcGraph.addParticle();
139 //if (!isVirtual) {
140 // part.setStatus(MCParticle::c_PrimaryParticle);
141 //} else {
142 // part.setStatus(MCParticle::c_IsVirtual);
143 //}
144
145 // RG 6/25/14 Add new flag for ISR "c_Initial"
147 if (isVirtual) {
149 } else if (isInitial) {
151 }
152
153 //every particle from a generator is primary, TF
155 part.setPDG(pdg);
156 part.setFirstDaughter(0);
157 part.setLastDaughter(0);
158 part.setMomentum(ROOT::Math::XYZVector(mom[0], mom[1], mom[2]));
159 part.setEnergy(mom[3]);
160 part.setMass(mom[4]);
161 part.setProductionVertex(vtx[0]*Unit::mm, vtx[1]*Unit::mm, vtx[2]*Unit::mm);
162
163 //boost, TF
164 ROOT::Math::PxPyPzEVector p4 = part.get4Vector();
165 p4 = boost * p4;
166 part.set4Vector(p4);
167
168 //set vertex, TF
169 if (!isInitial) {
170 ROOT::Math::XYZVector v3 = part.getProductionVertex();
171 v3 = v3 + vertex;
172 part.setProductionVertex(v3);
173 part.setValidVertex(true);
174 }
175}
void generateEvent(MCParticleGraph &mcGraph, ROOT::Math::XYZVector vertex, ROOT::Math::LorentzRotation boost)
Generates one single event.
Definition: KoralW.cc:107
double m_crossSection
The cross section of the generated KoralW events.
Definition: KoralW.h:85
double m_cmsEnergy
CMS Energy = 2*Ebeam [GeV].
Definition: KoralW.h:89
static constexpr int m_numXPar
Number of parameters for KoralW.
Definition: KoralW.h:107
unsigned int m_seed2
Second seed for the random number generator.
Definition: KoralW.h:113
unsigned int m_seed3
Third seed for the random number generator.
Definition: KoralW.h:115
void term()
Terminates the generator.
Definition: KoralW.cc:122
void init(const std::string &dataPath, const std::string &userDataFile)
Initializes the generator.
Definition: KoralW.cc:71
double m_crossSectionError
The error on the cross section of the generated KoralW events.
Definition: KoralW.h:87
void storeParticle(MCParticleGraph &mcGraph, const float *mom, const float *vtx, int pdg, ROOT::Math::XYZVector vertex, ROOT::Math::LorentzRotation boost, bool isVirtual=false, bool isInitial=false)
Store a single generated particle into the MonteCarlo graph.
Definition: KoralW.cc:134
double m_XPar[m_numXPar]
Values of parameters for KoralW.
Definition: KoralW.h:109
unsigned int m_seed1
First seed for the random number generator.
Definition: KoralW.h:111
Class to represent Particle data in graph.
void setFirstDaughter(int daughter)
Set the 1-based index of the first daughter, 0 means no daughters.
void setLastDaughter(int daughter)
Set the 1-based index of the last daughter, 0 means no daughters.
Class to build, validate and sort a particle decay chain.
@ c_Initial
bit 5: Particle is initial such as e+ or e- and not going to Geant4
Definition: MCParticle.h:57
@ c_PrimaryParticle
bit 0: Particle is primary particle.
Definition: MCParticle.h:47
@ c_IsVirtual
bit 4: Particle is virtual and not going to Geant4.
Definition: MCParticle.h:55
void setMass(float mass)
Set particle mass.
Definition: MCParticle.h:366
void addStatus(unsigned short int bitmask)
Add bitmask to current status.
Definition: MCParticle.h:353
void setEnergy(float energy)
Set energy.
Definition: MCParticle.h:372
ROOT::Math::XYZVector getProductionVertex() const
Return production vertex position.
Definition: MCParticle.h:189
void setValidVertex(bool valid)
Set indication wether vertex and time information is valid or just default.
Definition: MCParticle.h:378
void setProductionVertex(const ROOT::Math::XYZVector &vertex)
Set production vertex position.
Definition: MCParticle.h:396
ROOT::Math::PxPyPzEVector get4Vector() const
Return 4Vector of particle.
Definition: MCParticle.h:207
void setPDG(int pdg)
Set PDG code of the particle.
Definition: MCParticle.h:335
void set4Vector(const ROOT::Math::PxPyPzEVector &p4)
Sets the 4Vector of particle.
Definition: MCParticle.h:438
void setMomentum(const ROOT::Math::XYZVector &momentum)
Set particle momentum.
Definition: MCParticle.h:417
void setStatus(unsigned short int status)
Set Status code for the particle.
Definition: MCParticle.h:346
static const double mm
[millimeters]
Definition: Unit.h:70
GraphParticle & addParticle()
Add new particle to the graph.
Abstract base class for different kinds of events.
STL namespace.
int isthep[nmxhep]
status code.
double vhep[nmxhep][4]
vertex [mm].
double phep[nmxhep][5]
four-momentum, mass [GeV].
int idhep[nmxhep]
particle ident KF.
int nhep
number of particles.