Belle II Software development
Teegg.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#include <generators/teegg/Teegg.h>
10#include <framework/gearbox/Unit.h>
11#include <framework/logging/Logger.h>
12#include <framework/dataobjects/EventMetaData.h>
13#include <framework/dataobjects/EventExtraInfo.h>
14
15#include <framework/datastore/StoreObjPtr.h>
16
17#include <TDatabasePDG.h>
18#include <Math/Vector4D.h>
19#include <TMath.h>
20#include <TRandom3.h>
21
22using namespace std;
23using namespace Belle2;
24
25extern "C" {
26
27 //same convention as BHWIDE
28 extern struct {
29 double tp1[4];
30 double tq1[4];
31 double tp2[4];
32 double tq2[4];
33 double tphot[4][2];
34 int tnphot;
35 } momset_;
36
37// results for cross section and photon multiplicity
38 extern struct {
39 int resngen;
40 int resntrials;
41 double reseff;
42 double rescross;
43 double rescrosserr;
44 double avgq2;
45 } teeggresults_;
46
47// extrainfo
48 extern struct {
49 double tt;
50 double tw2;
51 double tweight;
52 double tvp2;
53 } teeggextra_;
54
55
57 void teegg_rndmarr_(double* drvec, const int* lengt)
58 {
59 for (int i = 0; i < *lengt; ++i) {
60 double rr = gRandom->Rndm();
61 drvec[i] = rr;
62 }
63 }
64
65 double teegg_rndm_(int*)
66 {
67 double r = gRandom->Rndm();
68 return r;
69 }
70
72 void teeggm_(int* mode, double* xpar, int* npar);
73
75 void teegg_warning_generic_(const double* weight, const double* max)
76 {
77 B2WARNING("TEEGG: Maximum weight " << *max << " to small, increase fmax to at least " << *weight);
78 }
79
81 void report_() { B2FATAL("Teegg: report_() is not implemented"); }
83 void golife_() { B2FATAL("Teegg: golife_() is not implemented"); }
85 void golint_() { B2FATAL("Teegg: golint_() is not implemented"); }
86}
87
89{
90 for (int i = 0; i < 100; ++i) {
91 m_npar[i] = 0;
92 m_xpar[i] = 0.0;
93 }
94
96}
97
99{
100
101}
102
104{
105 m_cmsEnergy = 5.28695 * 2.0 * Unit::GeV;
106
107 m_pi = 3.1415926535897932384626433832795029;
108 m_conversionFactor = 0.389379660e6;
109 m_alphaQED0 = 1.0 / 137.0359895;
110 m_massElectron = 0.51099906 * Unit::MeV;
111
112 m_sVACPOL = "HLMNT";
113 m_sRADCOR = "NONE";
114 m_sCONFIG = "EGAMMA";
115 m_sMATRIX = "BKM2";
116 m_sMTRXGG = "EPADC";
117
118 m_TEVETO = 0.1;
119 m_TEMIN = 20.0;// TMath::ACos(0.750);
120 m_TGMIN = 20.0;// TMath::ACos(0.750);
121 m_TGVETO = 0.05;
122 m_EEMIN = 2.00;
123 m_EGMIN = 2.00;
124 m_PEGMIN = m_pi / 4.00;
125 m_EEVETO = 0.00;
126 m_EGVETO = 0.00;
127 m_PHVETO = m_pi / 4.00;
128 m_CUTOFF = 0.25;
129 m_EPS = 0.01;
130 m_FRAPHI = 0.00;
131 m_EPSPHI = 1.0e-4;
132 m_WGHT1M = 1.001;
133 m_WGHTMX = 1.000;
134
135 m_RADCOR = -1;
136 m_CONFIG = -1;
137 m_MATRIX = -1;
138 m_MTRXGG = -1;
139 m_VACPOL = -1;
140 m_UNWGHT = 1;
141 m_t = 0.0;
142 m_w2 = 1.0;
143 m_weight = 1.0;
144 m_vp2 = 1.0;
145}
146
148{
149 StoreObjPtr<EventExtraInfo> eventextrainfo;
150 eventextrainfo.registerInDataStore();
151}
152
154{
156}
157
158
159void Teegg::generateEvent(MCParticleGraph& mcGraph, ROOT::Math::XYZVector vertex, ROOT::Math::LorentzRotation boost)
160{
161 //Generate event
162 int mode = 1;
163 teeggm_(&mode, m_xpar, m_npar);
164
165 //Store the final state fermions as real particle into the MCParticleGraph
166 storeParticle(mcGraph, momset_.tq2, 11, vertex, boost, false, false);
167 storeParticle(mcGraph, momset_.tp2, -11, vertex, boost, false, false);
168
169 //Store the real photon(s) into the MCParticleGraph
170 for (int iPhot = 0; iPhot < momset_.tnphot; ++iPhot) {
171 double photMom[4] = {momset_.tphot[0][iPhot], momset_.tphot[1][iPhot], momset_.tphot[2][iPhot], momset_.tphot[3][iPhot]};
172 storeParticle(mcGraph, photMom, 22, vertex, boost, false, false);
173 }
174
175 // Get extra information
176 m_t = teeggextra_.tt;
177 m_w2 = teeggextra_.tw2;
178 m_weight = teeggextra_.tweight;
179 m_vp2 = teeggextra_.tvp2;
180
181 // Fill event weight
182 StoreObjPtr<EventMetaData> eventMetaDataPtr("EventMetaData", DataStore::c_Event);
183 eventMetaDataPtr->setGeneratedWeight(m_weight);
184
185 // Fill vacuum polarization correction
186 StoreObjPtr<EventExtraInfo> eventExtraInfo;
187 if (not eventExtraInfo.isValid())
188 eventExtraInfo.create();
189 if (eventExtraInfo->hasExtraInfo("GeneratorVP2")) {
190 B2WARNING("EventExtraInfo with given name is already set! I won't set it again!");
191 } else {
192 eventExtraInfo->addExtraInfo("GeneratorVP2", m_vp2);
193 }
194
195}
196
198{
199 int mode = 2;
200 teeggm_(&mode, m_xpar, m_npar);
201
202 B2RESULT("Cross-section (nb) = " << teeggresults_.rescross / 1.e3 << " +/- " << teeggresults_.rescrosserr / 1.e3 << "");
203 B2RESULT("Events (unweighted) = " << teeggresults_.resngen);
204 B2RESULT("Trials = " << teeggresults_.resntrials);
205 B2RESULT("Efficiency = " << 100.*teeggresults_.reseff << " %");
206 B2RESULT("Average Q2 = " << teeggresults_.avgq2);
207
208}
209
210//=========================================================================
211// Protected methods
212//=========================================================================
213
215{
216 //--------------------
217 // Integer parameters
218 //--------------------
219 m_npar[0] = m_UNWGHT; //producing strange results...
220
221 if (m_sRADCOR == "NONE") m_RADCOR = 3; //DEFAULT
222 else if (m_sRADCOR == "SOFT") m_RADCOR = 2;
223 else if (m_sRADCOR == "HARD") m_RADCOR = 1;
224 else m_sRADCOR = 3;
225 m_npar[1] = m_RADCOR;
226
227 if (m_sCONFIG == "EGAMMA") m_CONFIG = 11; //DEFAULT
228 else if (m_sCONFIG == "ETRON") m_CONFIG = 12;
229 else if (m_sCONFIG == "GAMMA") m_CONFIG = 13;
230 else if (m_sCONFIG == "GAMMAE") m_CONFIG = 14;
231 else m_CONFIG = 11;
232 m_npar[2] = m_CONFIG;
233
234 if (m_sMATRIX == "BK") m_MATRIX = 21;
235 else if (m_sMATRIX == "BKM2") m_MATRIX = 22; //DEFAULT
236 else if (m_sMATRIX == "TCHAN") m_MATRIX = 23;
237 else if (m_sMATRIX == "EPA") m_MATRIX = 24;
238 else m_MATRIX = 22;
239 m_npar[3] = m_MATRIX;
240
241 if (m_sMTRXGG == "EPADC") m_MTRXGG = 31; //DEFAULT
242 else if (m_sMTRXGG == "BEEGG") m_MTRXGG = 32;
243 else if (m_sMTRXGG == "MEEGG") m_MTRXGG = 33;
244 else if (m_sMTRXGG == "HEEGG") m_MTRXGG = 34;
245 else m_MTRXGG = 31;
246 m_npar[4] = m_MTRXGG;
247
248 if (m_sVACPOL == "OFF") m_VACPOL = 41;
249 else if (m_sVACPOL == "HLMNT") m_VACPOL = 42; //DEFAULT
250 else if (m_sVACPOL == "NSK") m_VACPOL = 43;
251 else m_VACPOL = 42;
252 m_npar[5] = m_VACPOL;
253
254 //--------------------
255 // Double parameters
256 //--------------------
257 double toRad = TMath::DegToRad();
258 m_xpar[0] = m_TEVETO * toRad;
259 m_xpar[1] = m_TEMIN * toRad;
260 m_xpar[2] = m_TGMIN * toRad;
261 m_xpar[3] = m_TGVETO * toRad;
262 m_xpar[4] = m_EEMIN;
263 m_xpar[5] = m_EGMIN;
264 m_xpar[6] = m_PEGMIN * toRad;
265 m_xpar[7] = m_EEVETO;
266 m_xpar[8] = m_EGVETO;
267 m_xpar[9] = m_PHVETO * toRad;
268 m_xpar[10] = m_CUTOFF;
269 m_xpar[11] = m_EPS;
270 m_xpar[12] = m_FRAPHI;
271 m_xpar[13] = m_EPSPHI;
272 m_xpar[14] = m_WGHT1M;
273 m_xpar[15] = m_WGHTMX;
274 m_xpar[30] = m_cmsEnergy;
275
276 int mode = -1; //use mode to control init/generation/finalize in FORTRAN code
277 teeggm_(&mode, m_xpar, m_npar);
278}
279
280
281void Teegg::storeParticle(MCParticleGraph& mcGraph, const double* mom, int pdg, ROOT::Math::XYZVector vertex,
282 ROOT::Math::LorentzRotation boost,
283 bool isVirtual, bool isInitial)
284{
285 // Create particle
287 if (isVirtual) {
289 } else if (isInitial) {
291 }
292
293 // All particles from a generator are primary
295
296 // All particles from TEEGG are stable
298
299 // All gammas from TEEGG are ISR or FSR (impossible to distinguish due to IFI)
300 if (pdg == 22) {
303 }
304
305 part.setPDG(pdg);
306 part.setFirstDaughter(0);
307 part.setLastDaughter(0);
308 part.setMomentum(ROOT::Math::XYZVector(mom[0], mom[1], mom[2]));
309 part.setMass(TDatabasePDG::Instance()->GetParticle(pdg)->Mass());
310 part.setEnergy(mom[3]);
311
312 //boost
313 ROOT::Math::PxPyPzEVector p4 = part.get4Vector();
314 p4.SetPz(-1.0 * p4.Pz()); //TEEGG uses other direction convention
315 p4 = boost * p4;
316 part.set4Vector(p4);
317
318 //set vertex
319 if (!isInitial) {
320 ROOT::Math::XYZVector v3 = part.getProductionVertex();
321 v3 = v3 + vertex;
322 part.setProductionVertex(v3);
323 part.setValidVertex(true);
324 }
325}
@ c_Event
Different object in each event, all objects/arrays are invalidated after event() function has been ca...
Definition: DataStore.h:59
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_IsFSRPhoton
bit 7: Particle is from finial state radiation
Definition: MCParticle.h:61
@ 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
@ c_StableInGenerator
bit 1: Particle is stable, i.e., not decaying in the generator.
Definition: MCParticle.h:49
@ c_IsISRPhoton
bit 6: Particle is from initial state radiation
Definition: MCParticle.h:59
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
bool registerInDataStore(DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut)
Register the object/array in the DataStore.
Type-safe access to single objects in the data store.
Definition: StoreObjPtr.h:96
int m_MTRXGG
specifies which eegg matrix element (EPADC BEEGG or MEEGG)
Definition: Teegg.h:215
void init()
Initialize generator.
Definition: Teegg.cc:153
void generateEvent(MCParticleGraph &mcGraph, ROOT::Math::XYZVector vertex, ROOT::Math::LorentzRotation boost)
Generates one single event.
Definition: Teegg.cc:159
double m_EGVETO
minimum energy to veto(etron/gamma config with hard rad corr)
Definition: Teegg.h:202
double m_vp2
vacuum polarization squared (multiply with this to correcty for VP)
Definition: Teegg.h:226
~Teegg()
Destructor.
Definition: Teegg.cc:98
double m_alphaQED0
QED coupling constant at Q=0.
Definition: Teegg.h:189
double m_TEVETO
maximum theta of e+ in final state (in radians)
Definition: Teegg.h:194
int m_npar[100]
Integer parameters for Teegg.
Definition: Teegg.h:246
double m_conversionFactor
Conversion factor for hbarc to nb.
Definition: Teegg.h:188
Teegg()
Constructor.
Definition: Teegg.cc:88
double m_EEVETO
minimum energy to veto(gamma config with hard rad corr)
Definition: Teegg.h:201
double m_t
T=-Q2.
Definition: Teegg.h:223
void storeParticle(MCParticleGraph &mcGraph, const double *mom, 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: Teegg.cc:281
void setDefaultSettings()
Sets the default settings for the TEEGG Fortran generator.
Definition: Teegg.cc:103
double m_cmsEnergy
CMS Energy = 2*Ebeam [GeV].
Definition: Teegg.h:192
double m_WGHTMX
maximum weight for the trial events
Definition: Teegg.h:209
int m_CONFIG
specifies the event configuration (EGAMMA GAMMA or ETRON)
Definition: Teegg.h:213
double m_EGMIN
minimum energy of the gamma (egamma & gamma configurations)
Definition: Teegg.h:199
int m_UNWGHT
logical variable.
Definition: Teegg.h:221
std::string m_sMATRIX
specifies which eeg matrix element (BK BKM2 TCHAN or EPA)
Definition: Teegg.h:219
void term()
Terminates the generator.
Definition: Teegg.cc:197
double m_w2
W2.
Definition: Teegg.h:224
double m_weight
weight per event
Definition: Teegg.h:225
int m_MATRIX
specifies which eeg matrix element (BK BKM2 TCHAN or EPA)
Definition: Teegg.h:214
double m_WGHT1M
maximum weight for generation of QP0, cos(theta QP)
Definition: Teegg.h:208
double m_PHVETO
minimum phi sep to veto(etron/gamma config with hard rad corr
Definition: Teegg.h:203
double m_EPSPHI
param.
Definition: Teegg.h:207
std::string m_sCONFIG
specifies the event configuration (EGAMMA GAMMA or ETRON)
Definition: Teegg.h:218
int m_VACPOL
vacuum polarization: off, nsk (Novosibirsk) or hlmnt (Teubner).
Definition: Teegg.h:211
std::string m_sMTRXGG
specifies which eegg matrix element (EPADC BEEGG or MEEGG)
Definition: Teegg.h:220
double m_xpar[100]
Double parameters for Teegg.
Definition: Teegg.h:247
int m_RADCOR
specifies radiative correction (NONE SOFT or HARD)
Definition: Teegg.h:212
double m_TGVETO
maximum angle between the gamma and -z axis(etron conf.
Definition: Teegg.h:197
std::string m_sRADCOR
specifies radiative correction (NONE SOFT or HARD)
Definition: Teegg.h:217
double m_pi
pi=3.1415....
Definition: Teegg.h:187
double m_massElectron
muon mass.
Definition: Teegg.h:190
double m_EEMIN
minimum energy of the e- (egamma & etron configurations)
Definition: Teegg.h:198
double m_CUTOFF
cutoff energy for radiative corrections (in CM frame)
Definition: Teegg.h:204
double m_TGMIN
minimum angle between the gamma and -z axis
Definition: Teegg.h:196
std::string m_sVACPOL
vacuum polarization: off, nsk (Novosibirsk) or hlmnt (Teubner).
Definition: Teegg.h:216
double m_TEMIN
minimum angle between the e- and -z axis (egamma conf.
Definition: Teegg.h:195
void initExtraInfo()
Initializes the extra info.
Definition: Teegg.cc:147
double m_FRAPHI
fraction of time phi_ks is generated with peak(hard rad corr)
Definition: Teegg.h:206
double m_PEGMIN
minimum phi sep of e-gamma (egamma config with hard rad corr)
Definition: Teegg.h:200
void applySettings()
Apply the settings to the internal Fortran generator.
Definition: Teegg.cc:214
double m_EPS
param.
Definition: Teegg.h:205
static const double MeV
[megaelectronvolt]
Definition: Unit.h:114
static const double GeV
Standard of [energy, momentum, mass].
Definition: Unit.h:51
GraphParticle & addParticle()
Add new particle to the graph.
Abstract base class for different kinds of events.
STL namespace.