9#include <generators/babayaganlo/BabayagaNLO.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>
15#include <TDatabasePDG.h>
18#include <generators/utilities/InitialParticleGeneration.h>
43 double rescrossphot[40];
44 double rescrossphoterr[40];
45 double rescrossphotfrac[40];
56 double hnmmaxtriallimit;
65 double biasneghitmiss;
80 double babayaganlo_rndm_(
int*)
82 double r = gRandom->Rndm();
87 double babayaganlo_getrandomcmsenergy_()
89 B2FATAL(
"babayaganlo_getrandomcmsenergy() is not implmented");
94 void main_belle2_(
int* mode,
double* ecm,
double* xpar,
int* npar);
97 void babayaga_setvpolnsk_(
const char* vpolnskfilename,
size_t* length);
100 void babayaganlo_warning_overweight_(
const double* weight,
const double* max)
102 B2WARNING(
"Babayaga.NLO: Maximum weight " << *max <<
" to small, increase fmax to at least " << *weight);
106 void babayaganlo_error_rejection_(
const double* ratio)
108 B2ERROR(
"Babayaga.NLO: Event rejected! Ratio of cross section error increase too large: " << *ratio);
112 void babayaganlo_error_negative_(
const double* weight)
114 B2ERROR(
"Babayaga.NLO: Event has negative weight: " << *weight);
118 void babayaganlo_result_nominalcmsenergy_(
const double* energy)
120 B2RESULT(
"Babayaga.NLO: Nominal CMS energy (GeV): " << *energy);
123 void babayaganlo_result_weightedxsec_(
const double* xsec,
const double* xsecerr)
125 B2RESULT(
"Babayaga.NLO: Weighted cross section (nb): " << *xsec <<
" +/- " << *xsecerr);
128 void babayaganlo_result_unweightedxsec_(
const double* xsec,
const double* xsecerr)
130 B2RESULT(
"Babayaga.NLO: Unweighted cross section (nb): " << *xsec <<
" +/- " << *xsecerr);
133 void babayaganlo_result_unweightedxsec_biascorrected_(
const double* xsec,
const double* xsecerr)
135 B2RESULT(
"Babayaga.NLO: Unweighted cross section, bias corrected (nb): " << *xsec <<
" +/- " << *xsecerr);
138 void babayaganlo_result_unweightedxsec_overweight_(
const double* xsec,
const double* xsecerr)
140 B2RESULT(
"Babayaga.NLO: Unweighted cross section overweight (nb): " << *xsec <<
" +/- " << *xsecerr);
143 void babayaganlo_result_unweightedxsec_underweight_(
const double* xsec,
const double* xsecerr)
145 B2RESULT(
"Babayaga.NLO: Unweighted cross section underweight (nb): " << -*xsec <<
" +/- " << *xsecerr);
148 void babayaganlo_result_hitormisseff_(
const double* eff)
150 B2RESULT(
"Babayaga.NLO: Hit or miss efficiency: " << *eff * 100. <<
" % ");
153 void babayaganlo_result_nover_(
const int* nover)
155 B2RESULT(
"Babayaga.NLO: Points with w > fmax (bias): " << *nover);
158 void babayaganlo_result_biashit_(
const double* biashit)
160 B2RESULT(
"Babayaga.NLO: Bias/hit: " << *biashit * 100. <<
" % ");
163 void babayaganlo_result_biashitpmiss_(
const double* biashitpmiss)
165 B2RESULT(
"Babayaga.NLO: Bias/(hit+missed): " << *biashitpmiss * 100. <<
" % ");
168 void babayaganlo_result_nneg_(
const int* nneg)
170 B2RESULT(
"Babayaga.NLO: Points with w > fmax (bias): " << *nneg);
173 void babayaganlo_result_biasneghit_(
const double* biasneghit)
175 B2RESULT(
"Babayaga.NLO: Neg. bias/hit: " << *biasneghit * 100. <<
" % ");
178 void babayaganlo_result_biasneghitmiss_(
const double* biasneghitmiss)
180 B2RESULT(
"Babayaga.NLO: Neg. bias/(hit+missed): " << *biasneghitmiss * 100. <<
" % ");
183 void babayaganlo_result_maxweight_(
const double* sdifmax,
const double* fmax)
185 B2RESULT(
"Babayaga.NLO: Maximum weight (sdifmax): " << *sdifmax <<
", user maximum weight(fmax): " << *fmax);
188 void babayaganlo_result_vpmin_(
const double* xsec,
const double* xsecerr,
const double* frac)
190 B2RESULT(
"Babayaga.NLO: VP Uncertainty, minimum (nb): " << *xsec <<
" +/- " << *xsecerr <<
" (" << *frac <<
" %)");
193 void babayaganlo_result_vpcentral_(
const double* xsec,
const double* xsecerr)
195 B2RESULT(
"Babayaga.NLO: VP Uncertainty, central (nb): " << *xsec <<
" +/- " << *xsecerr);
198 void babayaganlo_result_vpmax_(
const double* xsec,
const double* xsecerr,
const double* frac)
200 B2RESULT(
"Babayaga.NLO: VP Uncertainty, maximum (nb): " << *xsec <<
" +/- " << *xsecerr <<
" ( " << *frac <<
" %)");
203 void babayaganlo_finishedmaxsearch_(
const double* fmax)
205 B2INFO(
"Babayaga.NLO: Finished maximum search: " << *fmax <<
", starting now unweighted generation");
208 void babayaganlo_fatal_usercuts_()
210 B2FATAL(
"Babayaga.NLO: UserMode is selected but wrong user cuts are provided!");
213 void babayaganlo_fatal_usercutsfs_()
215 B2FATAL(
"Babayaga.NLO: UserMode is only possible for ee final states!");
218 void babayaganlo_fatal_usercutsprescale_()
220 B2FATAL(
"Babayaga.NLO: Prescale value must be larger than 0 (zero), hint: ~100 is reasonable!");
223 void babayaganlo_fatal_weightedprescale_()
225 B2FATAL(
"Babayaga.NLO: Generator prescale is not allowed with usermode = weighted");
228 void babayaganlo_result_weightsum_(
const double* wsum)
230 B2RESULT(
"Babayaga.NLO: Sum of weights: " << *wsum);
233 void babayaganlo_result_intlum_(
const double* lum,
const double* lumerr)
235 B2RESULT(
"Babayaga.NLO: Luminosity equivalent (using calc. xsec) (fb-1): " << *lum <<
" +/- " << *lumerr);
238 void babayaganlo_warning_prescaleweight_(
const double* weight)
240 B2WARNING(
"Babayaga.NLO: Prescale of less than one, increase prescale safety margin " << *weight);
243 void babayaganlo_error_isnan1_(
const double* phsp,
const double* w)
245 B2ERROR(
"Babayaga.NLO: phsp (" << *phsp <<
") or w (" << *w <<
") are NAN, skipping event (nan1 type)");
248 void babayaganlo_error_isnan2_(
const double* sdif)
250 B2ERROR(
"Babayaga.NLO: sdif (" << *sdif <<
") is NAN, skipping event (nan2 type)");
259 for (
int i = 0; i < 100; ++i) {
288 m_pi = 3.1415926535897932384626433832795029;
332 ROOT::Math::LorentzRotation boost)
339 storeParticle(mcGraph, momset_.bq1, 11, vertex, boost,
false,
true,
false);
340 storeParticle(mcGraph, momset_.bp1, -11, vertex, boost,
false,
true,
false);
354 storeParticle(mcGraph, momset_.bq2, pdg, vertex, boost,
false,
false,
false);
355 storeParticle(mcGraph, momset_.bp2, antipdg, vertex, boost,
false,
false,
false);
358 for (
int iPhot = 0; iPhot < momset_.bnphot; ++iPhot) {
359 double photMom[4] = {momset_.bphot[0][iPhot], momset_.bphot[1][iPhot], momset_.bphot[2][iPhot], momset_.bphot[3][iPhot]};
360 storeParticle(mcGraph, photMom, 22, vertex, boost,
false,
false,
true);
365 eventMetaDataPtr->setGeneratedWeight(momset_.bweight);
369 if (not eventExtraInfo.isValid())
370 eventExtraInfo.create();
371 if (eventExtraInfo->hasExtraInfo(
"GeneratedPrescale")) {
372 B2WARNING(
"EventExtraInfo with given name is already set! I won't set it again!");
374 float targetValue = prescale_.bprescale;
375 eventExtraInfo->addExtraInfo(
"GeneratedPrescale", targetValue);
384 B2RESULT(
"Babayaga.NLO: Final state: " <<
m_finalState);
385 B2RESULT(
"Babayaga.NLO: Mode: " <<
m_mode);
386 B2RESULT(
"Babayaga.NLO: Order: " <<
m_order);
387 B2RESULT(
"Babayaga.NLO: Model: " <<
m_model);
388 B2RESULT(
"Babayaga.NLO: Vac. pol. (VP): " <<
m_vacPol);
389 B2RESULT(
"Babayaga.NLO: Usercuts: " <<
m_userMode);
454 else B2FATAL(
"Invalid matching model: " <<
m_model);
459 else B2FATAL(
"Invalid QED order: " <<
m_order);
464 else B2FATAL(
"Invalid vacuum polarization code: " <<
m_vacPol);
468 else B2FATAL(
"Invalid mode: " <<
m_mode);
475 else B2FATAL(
"Invalid user mode: " <<
m_userMode);
489 ROOT::Math::LorentzRotation boost,
bool isVirtual,
bool isInitial,
bool isISRFSR)
496 }
else if (isInitial) {
515 part.
setMomentum(ROOT::Math::XYZVector(mom[0], mom[1], mom[2]));
516 part.
setMass(TDatabasePDG::Instance()->GetParticle(pdg)->Mass());
520 ROOT::Math::PxPyPzEVector p4 = part.
get4Vector();
double m_eeveto
Minimum CMS energy to veto e-/e+ (GeV).
void init()
Initializes the generator.
std::string m_NSKDataFile
data file for NSK VP.
double m_sDif
Differential xsec/weight used for event.
double m_tgveto
Maximum CMS angle between the gamma and -z axis (deg).
std::pair< double, double > m_ScatteringAngleRange
Min and Max val.
double m_maxAcollinearity
Maximum acollinearity of the electron-positron pair.
~BabayagaNLO()
Destrucotr.
double m_alphaQED0
QED coupling constant at Q=0.
void generateEvent(MCParticleGraph &mcGraph, double ecm, ROOT::Math::XYZVector vertex, ROOT::Math::LorentzRotation boost)
Generates one single event.
double m_EnergySpread
TEMPORARY SOLUTION! Approximate energy spread per beam (CMS).
double m_maxprescale
Maximum prescale value.
int m_npar[100]
Integer parameters for BabayagaNLO.
double m_conversionFactor
Conversion factor for hbarc to nb.
bool m_applyBoost
Apply a boost to the MCParticles.
void storeParticle(MCParticleGraph &mcGraph, const double *mom, int pdg, ROOT::Math::XYZVector vertex, ROOT::Math::LorentzRotation boost, bool isVirtual=false, bool isInitial=false, bool isISRFSR=false)
Store a single generated particle into the MonteCarlo graph.
void setDefaultSettings()
Sets the default settings for the BhWide Fortran generator.
std::string m_order
order: born, alpha or exp.
double m_tgmin
Minimum CMS angle between the gamma and -z axis (deg).
double m_epsilon
Soft/hard photon separator in units of CMS/2.
double m_massMuon
electron mass.
double m_teveto
Maximum CMS theta of e-/e+ in final state (deg).
BabayagaNLO()
Constructor.
double m_massW
W mass [GeV] for on shell sin2theta and GF.
double m_temin
Minimum CMS angle between the tagged e-/e+ and -z axis (deg).
std::string m_userMode
User mode similar to TEEGG: ETRON, EGAMMA, GAMMA or PRESCALE.
std::pair< double, double > m_ScatteringAngleRangePhoton
Min and Max val.
double m_widthZ
Z width [GeV] (may be recalculated by EW library).
void term()
Terminates the generator.
int m_nSearchMax
Events used to search maximum of differential cross section.
int m_nPhot
fixed number of nphot (hard) photons are generated.
std::string m_vacPol
vacuum polarization: off, hadr5 (Jegerlehner) or hmnt (Teubner).
bool m_VPUncertainty
vary all VP related parameters and extracted total uncertainty.
double m_egmin
Minimum CMS energy of the gamma (GeV).
double m_eemin
Minimum CMS energy of the tagged e-/e+ (GeV).
double m_xpar[100]
Double parameters for BabayagaNLO.
std::string m_finalState
final state: ee, gg or mm.
double m_massZ
Z mass [GeV].
double m_cmsEnergyNominal
Nominal CMS Energy = 2*Ebeam [GeV].
double m_egveto
Minimum CMS energy to veto gamma (GeV).
double m_massElectron
muon mass.
void initExtraInfo()
Initializes the extra info.
std::string m_model
model: matched or ps.
std::string m_mode
mode: weighted or unweighted.
void applySettings()
Apply the settings to the internal Fortran generator.
double m_fMax
Maximum of differential cross section.
@ c_Event
Different object in each event, all objects/arrays are invalidated after event() function has been ca...
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
@ c_Initial
bit 5: Particle is initial such as e+ or e- and not going to Geant4
@ c_PrimaryParticle
bit 0: Particle is primary particle.
@ c_IsVirtual
bit 4: Particle is virtual and not going to Geant4.
@ c_StableInGenerator
bit 1: Particle is stable, i.e., not decaying in the generator.
@ c_IsISRPhoton
bit 6: Particle is from initial state radiation
void setMass(float mass)
Set particle mass.
void addStatus(unsigned short int bitmask)
Add bitmask to current status.
void setEnergy(float energy)
Set energy.
ROOT::Math::XYZVector getProductionVertex() const
Return production vertex position.
void setValidVertex(bool valid)
Set indication wether vertex and time information is valid or just default.
void setProductionVertex(const ROOT::Math::XYZVector &vertex)
Set production vertex position.
ROOT::Math::PxPyPzEVector get4Vector() const
Return 4Vector of particle.
void setPDG(int pdg)
Set PDG code of the particle.
void set4Vector(const ROOT::Math::PxPyPzEVector &p4)
Sets the 4Vector of particle.
void setMomentum(const ROOT::Math::XYZVector &momentum)
Set particle momentum.
void setStatus(unsigned short int status)
Set Status code for the particle.
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.
static const double MeV
[megaelectronvolt]
static const double GeV
Standard of [energy, momentum, mass].
GraphParticle & addParticle()
Add new particle to the graph.
Abstract base class for different kinds of events.