EvtGen
2.2.0
Monte Carlo generator of particle decays, in particular the weak decays of heavy flavour particles such as B mesons.
Toggle main menu visibility
Loading...
Searching...
No Matches
src
EvtGen.cpp
Go to the documentation of this file.
1
2
/***********************************************************************
3
* Copyright 1998-2020 CERN for the benefit of the EvtGen authors *
4
* *
5
* This file is part of EvtGen. *
6
* *
7
* EvtGen is free software: you can redistribute it and/or modify *
8
* it under the terms of the GNU General Public License as published by *
9
* the Free Software Foundation, either version 3 of the License, or *
10
* (at your option) any later version. *
11
* *
12
* EvtGen is distributed in the hope that it will be useful, *
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15
* GNU General Public License for more details. *
16
* *
17
* You should have received a copy of the GNU General Public License *
18
* along with EvtGen. If not, see <https://www.gnu.org/licenses/>. *
19
***********************************************************************/
20
21
#include "
EvtGen/EvtGen.hh
"
22
23
#include "
EvtGenBase/EvtAbsRadCorr.hh
"
24
#include "
EvtGenBase/EvtCPUtil.hh
"
25
#include "
EvtGenBase/EvtDecayTable.hh
"
26
#include "
EvtGenBase/EvtHepMCEvent.hh
"
27
#include "
EvtGenBase/EvtPDL.hh
"
28
#include "
EvtGenBase/EvtParticle.hh
"
29
#include "
EvtGenBase/EvtParticleFactory.hh
"
30
#include "
EvtGenBase/EvtRadCorr.hh
"
31
#include "
EvtGenBase/EvtRandom.hh
"
32
#include "
EvtGenBase/EvtRandomEngine.hh
"
33
#include "
EvtGenBase/EvtReport.hh
"
34
#include "
EvtGenBase/EvtSimpleRandomEngine.hh
"
35
#include "
EvtGenBase/EvtStatus.hh
"
36
#include "
EvtGenBase/EvtVector4R.hh
"
37
38
#include "
EvtGenModels/EvtModelReg.hh
"
39
#include "
EvtGenModels/EvtNoRadCorr.hh
"
40
41
#include <cstdlib>
42
#include <fstream>
43
#include <string>
44
45
using
std::endl;
46
using
std::fstream;
47
using
std::ifstream;
48
49
EvtGen::~EvtGen
()
50
{
51
//This is a bit ugly, should not do anything
52
//in a destructor. This will fail if EvtGen is made a static
53
//because then this destructor might be called _after_
54
//the destruction of objects that it depends on, e.g., EvtPDL.
55
56
if
( getenv(
"EVTINFO"
) ) {
57
EvtDecayTable::getInstance
().
printSummary
();
58
}
59
}
60
61
EvtGen::EvtGen
(
const
std::string& decayName,
const
std::string& pdtTableName,
62
EvtRandomEngine
* randomEngine,
EvtAbsRadCorr
* isrEngine,
63
const
std::list<EvtDecayBase*>* extraModels,
int
mixingType,
64
bool
useXml )
65
{
66
std::ifstream pdtIn( pdtTableName );
67
if
( !pdtIn ) {
68
EvtGenReport
(
EVTGEN_ERROR
,
"EvtGen"
)
69
<<
"Could not open:"
<< pdtTableName <<
"EvtPDL"
<< endl;
70
return
;
71
}
72
initialize
( decayName, pdtIn, randomEngine, isrEngine, extraModels,
73
mixingType, useXml );
74
pdtIn.close();
75
}
76
77
EvtGen::EvtGen
(
const
std::string& decayName, std::istream& pdtTableData,
78
EvtRandomEngine
* randomEngine,
EvtAbsRadCorr
* isrEngine,
79
const
std::list<EvtDecayBase*>* extraModels,
int
mixingType,
80
bool
useXml )
81
{
82
initialize
( decayName, pdtTableData, randomEngine, isrEngine, extraModels,
83
mixingType, useXml );
84
}
85
86
void
EvtGen::initialize
(
const
std::string& decayName, std::istream& pdtTable,
87
EvtRandomEngine
* randomEngine,
EvtAbsRadCorr
* isrEngine,
88
const
std::list<EvtDecayBase*>* extraModels,
89
int
mixingType,
bool
useXml )
90
{
91
EvtGenReport
(
EVTGEN_INFO
,
"EvtGen"
) <<
"Initializing EvtGen"
<< endl;
92
93
if
( !randomEngine ) {
94
static
thread_local
EvtSimpleRandomEngine
defaultRandomEngine;
95
EvtRandom::setRandomEngine
( &defaultRandomEngine );
96
EvtGenReport
(
EVTGEN_INFO
,
"EvtGen"
)
97
<<
"No random engine given in "
98
<<
"EvtGen::EvtGen constructor, "
99
<<
"will use default EvtSimpleRandomEngine."
<< endl;
100
}
else
{
101
EvtRandom::setRandomEngine
( randomEngine );
102
}
103
104
EvtGenReport
(
EVTGEN_INFO
,
"EvtGen"
) <<
"Storing known decay models"
<< endl;
105
EvtModelReg
dummy( extraModels );
106
107
EvtGenReport
(
EVTGEN_INFO
,
"EvtGen"
)
108
<<
"Main decay file name :"
<< decayName << endl;
109
110
EvtPDL::readPDT
( pdtTable );
111
112
if
( useXml ) {
113
EvtDecayTable::getInstance
().
readXMLDecayFile
( decayName,
false
);
114
}
else
{
115
EvtDecayTable::getInstance
().
readDecayFile
( decayName,
false
);
116
}
117
118
m_mixingType
= mixingType;
119
EvtGenReport
(
EVTGEN_INFO
,
"EvtGen"
)
120
<<
"Mixing type integer set to "
<<
m_mixingType
<< endl;
121
EvtCPUtil::getInstance
()->
setMixingType
(
m_mixingType
);
122
123
// Set the radiative correction engine
124
125
if
( isrEngine !=
nullptr
) {
126
EvtRadCorr::setRadCorrEngine
( isrEngine );
127
128
}
else
{
129
// Owing to the pure abstract interface, we still need to define a concrete
130
// implementation of a radiative correction engine. Use one which does nothing.
131
EvtAbsRadCorr
* noRadCorr =
new
EvtNoRadCorr
();
132
EvtRadCorr::setRadCorrEngine
( noRadCorr );
133
}
134
135
EvtGenReport
(
EVTGEN_INFO
,
"EvtGen"
) <<
"Done initializing EvtGen"
<< endl;
136
}
137
138
void
EvtGen::readUDecay
(
const
std::string& uDecayName,
bool
useXml )
139
{
140
ifstream indec;
141
142
if
( uDecayName.size() == 0 ) {
143
EvtGenReport
(
EVTGEN_INFO
,
"EvtGen"
)
144
<<
"Is not reading a user decay file!"
<< endl;
145
}
else
{
146
indec.open( uDecayName );
147
if
( indec ) {
148
if
( useXml ) {
149
EvtDecayTable::getInstance
().
readXMLDecayFile
( uDecayName,
true
);
150
}
else
{
151
EvtDecayTable::getInstance
().
readDecayFile
( uDecayName,
true
);
152
}
153
}
else
{
154
EvtGenReport
(
EVTGEN_INFO
,
"EvtGen"
)
155
<<
"Can not find UDECAY file '"
<< uDecayName <<
"'. Stopping"
156
<< endl;
157
::abort();
158
}
159
}
160
}
161
162
EvtHepMCEvent
*
EvtGen::generateDecay
(
int
PDGId,
EvtVector4R
refFrameP4,
163
EvtVector4R
translation,
164
EvtSpinDensity
* spinDensity )
165
{
166
EvtParticle
* theParticle(
nullptr
);
167
168
if
( spinDensity ==
nullptr
) {
169
theParticle =
EvtParticleFactory::particleFactory
(
170
EvtPDL::evtIdFromStdHep
( PDGId ), refFrameP4 );
171
}
else
{
172
theParticle =
EvtParticleFactory::particleFactory
(
173
EvtPDL::evtIdFromStdHep
( PDGId ), refFrameP4, *spinDensity );
174
}
175
176
generateDecay
( theParticle );
177
EvtHepMCEvent
* hepMCEvent =
new
EvtHepMCEvent
();
178
hepMCEvent->
constructEvent
( theParticle, translation );
179
180
theParticle->
deleteTree
();
181
182
return
hepMCEvent;
183
}
184
185
void
EvtGen::generateDecay
(
EvtParticle
* p )
186
{
187
int
times = 0;
188
do
{
189
times += 1;
190
EvtStatus::initRejectFlag
();
191
192
p->
decay
();
193
//ok then finish.
194
if
(
EvtStatus::getRejectFlag
() == 0 ) {
195
times = 0;
196
}
else
{
197
for
(
size_t
ii = 0; ii < p->
getNDaug
(); ii++ ) {
198
EvtParticle
* temp = p->
getDaug
( ii );
199
temp->
deleteTree
();
200
}
201
p->
resetFirstOrNot
();
202
p->
resetNDaug
();
203
}
204
205
if
( times == 10000 ) {
206
EvtGenReport
(
EVTGEN_ERROR
,
"EvtGen"
)
207
<<
"Your event has been rejected 10000 times!"
<< endl;
208
EvtGenReport
(
EVTGEN_ERROR
,
"EvtGen"
) <<
"Will now abort."
<< endl;
209
::abort();
210
times = 0;
211
}
212
}
while
( times );
213
}
EvtAbsRadCorr.hh
EvtCPUtil.hh
EvtDecayTable.hh
EvtGen.hh
EvtHepMCEvent.hh
EvtModelReg.hh
EvtNoRadCorr.hh
EvtPDL.hh
EvtParticleFactory.hh
EvtParticle.hh
EvtRadCorr.hh
EvtRandomEngine.hh
EvtRandom.hh
EvtReport.hh
EvtGenReport
std::ostream & EvtGenReport(EvtGenSeverity severity, const char *facility=nullptr)
Definition
EvtReport.cpp:32
EVTGEN_INFO
@ EVTGEN_INFO
Definition
EvtReport.hh:52
EVTGEN_ERROR
@ EVTGEN_ERROR
Definition
EvtReport.hh:49
EvtSimpleRandomEngine.hh
EvtStatus.hh
EvtVector4R.hh
EvtAbsRadCorr
Definition
EvtAbsRadCorr.hh:28
EvtCPUtil::getInstance
static EvtCPUtil * getInstance()
Definition
EvtCPUtil.cpp:42
EvtCPUtil::setMixingType
void setMixingType(int mixingType)
Definition
EvtCPUtil.hh:41
EvtDecayTable::readXMLDecayFile
void readXMLDecayFile(const std::string dec_name, bool verbose=true)
Definition
EvtDecayTable.cpp:931
EvtDecayTable::printSummary
void printSummary() const
Definition
EvtDecayTable.cpp:75
EvtDecayTable::getInstance
static EvtDecayTable & getInstance()
Definition
EvtDecayTable.cpp:58
EvtDecayTable::readDecayFile
void readDecayFile(const std::string dec_name, bool verbose=true)
Definition
EvtDecayTable.cpp:93
EvtGen::m_mixingType
int m_mixingType
Definition
EvtGen.hh:67
EvtGen::~EvtGen
~EvtGen()
Definition
EvtGen.cpp:49
EvtGen::readUDecay
void readUDecay(const std::string &udecay_name, bool useXml=false)
Definition
EvtGen.cpp:138
EvtGen::initialize
void initialize(const std::string &decayName, std::istream &pdtTable, EvtRandomEngine *randomEngine=nullptr, EvtAbsRadCorr *isrEngine=nullptr, const std::list< EvtDecayBase * > *extraModels=nullptr, int mixingType=1, bool useXml=false)
Definition
EvtGen.cpp:86
EvtGen::generateDecay
EvtHepMCEvent * generateDecay(int PDGid, EvtVector4R refFrameP4, EvtVector4R translation, EvtSpinDensity *spinDensity=nullptr)
Definition
EvtGen.cpp:162
EvtGen::EvtGen
EvtGen(const std::string &decayName, const std::string &pdtTableName, EvtRandomEngine *randomEngine=nullptr, EvtAbsRadCorr *isrEngine=nullptr, const std::list< EvtDecayBase * > *extraModels=nullptr, int mixingType=1, bool useXml=false)
Definition
EvtGen.cpp:61
EvtHepMCEvent
Definition
EvtHepMCEvent.hh:74
EvtHepMCEvent::constructEvent
void constructEvent(EvtParticle *baseParticle)
Definition
EvtHepMCEvent.cpp:45
EvtModelReg
Definition
EvtModelReg.hh:28
EvtNoRadCorr
Definition
EvtNoRadCorr.hh:34
EvtPDL::readPDT
static void readPDT(std::istream &data)
Definition
EvtPDL.cpp:59
EvtPDL::evtIdFromStdHep
static EvtId evtIdFromStdHep(int stdhep)
Definition
EvtPDL.cpp:241
EvtParticleFactory::particleFactory
static EvtParticle * particleFactory(EvtSpinType::spintype spinType)
Definition
EvtParticleFactory.cpp:44
EvtParticle
Definition
EvtParticle.hh:45
EvtParticle::resetNDaug
void resetNDaug()
Definition
EvtParticle.hh:290
EvtParticle::decay
void decay()
Definition
EvtParticle.cpp:438
EvtParticle::resetFirstOrNot
void resetFirstOrNot()
Definition
EvtParticle.cpp:80
EvtParticle::getDaug
EvtParticle * getDaug(const int i)
Definition
EvtParticle.hh:173
EvtParticle::getNDaug
size_t getNDaug() const
Definition
EvtParticle.cpp:154
EvtParticle::deleteTree
void deleteTree()
Definition
EvtParticle.cpp:604
EvtRadCorr::setRadCorrEngine
static void setRadCorrEngine(EvtAbsRadCorr *fsrEngine)
Definition
EvtRadCorr.cpp:34
EvtRandomEngine
Definition
EvtRandomEngine.hh:28
EvtRandom::setRandomEngine
static void setRandomEngine(EvtRandomEngine *randomEngine)
Definition
EvtRandom.cpp:36
EvtSimpleRandomEngine
Definition
EvtSimpleRandomEngine.hh:26
EvtSpinDensity
Definition
EvtSpinDensity.hh:28
EvtStatus::initRejectFlag
static void initRejectFlag()
Definition
EvtStatus.hh:32
EvtStatus::getRejectFlag
static int getRejectFlag()
Definition
EvtStatus.hh:43
EvtVector4R
Definition
EvtVector4R.hh:29
Generated by
1.17.0