Belle II Software  release-05-01-25
BabayagaNLOInputModule.cc
1 /************************************************************************
2 * BASF2 (Belle Analysis Framework 2) *
3 * Copyright(C) 2015 Belle II Collaboration *
4 * *
5 * Author: The Belle II Collaboration *
6 * Contributors: Torben Ferber *
7 * *
8 * This software is provided "as is" without any warranty. *
9 **************************************************************************/
10 
11 #include <generators/modules/babayaganloinput/BabayagaNLOInputModule.h>
12 
13 #include <framework/datastore/StoreArray.h>
14 #include <framework/utilities/FileSystem.h>
15 #include <framework/utilities/IOIntercept.h>
16 
17 using namespace std;
18 using namespace Belle2;
19 
20 //-----------------------------------------------------------------
21 // Register the Module
22 //-----------------------------------------------------------------
23 REG_MODULE(BabayagaNLOInput)
24 
25 //-----------------------------------------------------------------
26 // Implementation
27 //-----------------------------------------------------------------
28 
29 extern "C" {
30  double babayaganlo_getrandomcmsenergy_()
31  {
32  return BabayagaNLOInputModule::generateCMSEnergy();
33  }
34 }
35 
36 // BabayagaNLOInputModule::BabayagaNLOInputModule() : Module(), s_initial(BeamParameters::c_smearALL)
37 InitialParticleGeneration BabayagaNLOInputModule::s_initial{BeamParameters::c_smearALL};
38 
39 BabayagaNLOInputModule::BabayagaNLOInputModule() : Module()
40 {
41  //Set module properties
42  setDescription("Generates radiative Bhabha scattering and exclusive two-photon events with the high precision QED generator called BabaYaga@NLO.");
43 
44  //Parameter definition
45  addParam("VacuumPolarization", m_vacPol, "Vacuum polarization: off, hadr5 (Jegerlehner) or hlmnt (Teubner, default)",
46  std::string("hlmnt"));
47  addParam("Model", m_model, "Model: ps or matched (default)", std::string("matched"));
48  addParam("Order", m_order, "Order: born, alpha, exp (default)", std::string("exp"));
49  addParam("Mode", m_mode, "Mode: weighted or unweighted (default)", std::string("unweighted"));
50  addParam("FinalState", m_finalState, "Final state: ee (default), mm or gg", std::string("ee"));
51  addParam("MinEnergyFrac", m_eMinFrac,
52  "Fractional minimum energy for leptons (ee or mm mode) or photons (gg mode) in the final state [fraction of ECMS]", -1.0);
53  addParam("MinEnergy", m_eMin, "Minimum energy for leptons (ee or mm mode) or photons (gg mode) in the final state [GeV]", 0.10);
54  addParam("Epsilon", m_epsilon, "Soft/hard photon separator [fraction of ECMS/2], must be <=1e-7 for ee and mumu, <=1e-5 for gg",
55  1.e-7);
56  addParam("MaxAcollinearity", m_maxAcollinearity, "Maximum acollinearity angle between finale state leptons/photons [degree]",
57  180.0);
58  addParam("FMax", m_fMax, "Maximum of differential cross section weight (fmax)", -1.);
59  addParam("NPhotons", m_nPhot, "Fixed number of (hard) photons are generated, -1 for any number", -1);
60  addParam("SearchMax", m_nSearchMax, "Number of events used to search for maximum of differential cross section", 500000);
61  addParam("ScatteringAngleRange", m_ScatteringAngleRange, "Min [0] and Max [1] value for the scattering angle [deg].",
62  make_vector(15.0, 165.0));
63  addParam("ExtraFile", m_fileNameExtraInfo, "ROOT file that contains additional information.", std::string(""));
64  addParam("DebugEnergySpread", m_Spread, "TEMPORARY SOLUTION! Approximate energy spread per beam (CMS)", 5.e-3);
65  addParam("VPUncertainty", m_Uncertainty, "Calculate VP uncertainty by internal reweighting", false);
66  addParam("NSKDataFile", m_NSKDataFile, "File that contain VP data from Novosibirsk (nsk)",
67  FileSystem::findFile("/data/generators/babayaganlo/vpol_novosibirsk.dat"));
68 
69  // user cuts
70  addParam("UserMode", m_userMode, "User mode similar to TEEGG: ETRON, EGAMMA, GAMMA or PRESCALE or NONE (default)",
71  std::string("NONE"));
72  addParam("EEMIN", m_eemin, "Minimum CMS energy of the tagged e-/e+ (GeV)", -1.0);
73  addParam("TEMIN", m_temin, "Minimum CMS angle between the tagged e-/e+ and -z axis (deg)", -1.0);
74  addParam("EGMIN", m_egmin, "Minimum CMS energy of the gamma (GeV)", -1.0);
75  addParam("TGMIN", m_tgmin, "Minimum CMS angle between the gamma and -z axis (deg)", -1.0);
76  addParam("EEVETO", m_eeveto, "Minimum CMS energy to veto e-/e+ (GeV)", -1.0);
77  addParam("TEVETO", m_teveto, "Maximum CMS theta of e-/e+ in final state (deg)", -1.0);
78  addParam("EGVETO", m_egveto, "Minimum CMS energy to veto gamma (GeV)", -1.0);
79  addParam("TGVETO", m_tgveto, "Maximum CMS angle between the gamma and -z axis (deg)", -1.0);
80  addParam("MaxPrescale", m_maxprescale, "Maximum prescale factor (used for maximum differential cross section)", 1.0);
81 
82  //initialize member variables
83  m_fileExtraInfo = 0;
84  m_th1dSDif = 0;
85 }
86 
88 {
89 }
90 
92 {
93  //Initialize MCParticle collection
94  StoreArray<MCParticle> mcparticle;
95  mcparticle.registerInDataStore();
96 
97  //open extrafile
98  if (m_fileNameExtraInfo != "") {
99  m_fileExtraInfo = new TFile(m_fileNameExtraInfo.c_str(), "RECREATE") ;
100  m_fileExtraInfo->cd();
101  m_th1dSDif = new TH1D("sdif", "sdif", 1000, 0., 100000.);
102  }
103 
104  //Initialize initial particle for beam parameters.
106 
107  // Initialize ExtraInfo (hold prescale values)
109 }
110 
112 {
113  // Check if the BeamParameters have changed (if they do, abort the job! otherwise cross section calculation will be a nightmare.)
114  if (m_beamParams.hasChanged()) {
115  if (!m_initialized) {
117  } else {
118  B2FATAL("BabayagaNLOInputModule::event(): BeamParameters have changed within a job, this is not supported for BABAYAGA!");
119  }
120  }
121 
122  // initial particle from beam parameters
123  const MCInitialParticles& initial = s_initial.generate();
124 
125  // CM energy
126  double ecm = initial.getMass();
127 
128  // true boost (per event!)
129  TLorentzRotation boost = initial.getCMSToLab();
130 
131  // vertex
132  TVector3 vertex = initial.getVertex();
133 
134  m_mcGraph.clear();
135  m_generator.generateEvent(m_mcGraph, ecm, vertex, boost); // actual generator call
136 
138 }
139 
141 {
142  m_generator.term();
143 }
144 
146 {
147  // generator parameters
170 
171  // set a nominal value for some intialization inside the generator
172  const BeamParameters& nominal = s_initial.getBeamParameters();
173  double ecmnominal = nominal.getMass();
174  m_generator.setCmsEnergyNominal(ecmnominal);
175 
176  // check which of the emin values are used:
177  // its either a fixed value or a fractional one
178  // if both are provided, the fractional has priority
179  if (m_eMinFrac >= 0.) {
180  B2INFO("Setting EMIN using fraction " << m_eMinFrac << " of CMS energy: cut=" << m_eMinFrac * ecmnominal << " GeV");
181  m_generator.setMinEnergy(m_eMinFrac * ecmnominal);
183 
184  // check if a maximum weight is provided
185  if (m_fMax > 0. && (m_mode == "unweighted" || m_mode == "uw")) {
186  B2INFO("Setting FMax manually (no maximum search is performed)." <<
187  LogVar("FMax", m_fMax));
190  } else if (m_mode == "weighted" || m_mode == "w") {
192  } else {
194  }
195 
196  IOIntercept::OutputToLogMessages initLogCapture("BabaYaga@NLO", LogConfig::c_Info, LogConfig::c_Info, 100, 100);
197  initLogCapture.start();
198  m_generator.init();
199  initLogCapture.finish();
200 
201  m_initialized = true;
202 }
Belle2::BabayagaNLOInputModule::m_mcGraph
MCParticleGraph m_mcGraph
The MCParticle graph object.
Definition: BabayagaNLOInputModule.h:113
Belle2::MCParticleGraph::generateList
void generateList(const std::string &name="", int options=c_setNothing)
Generates the MCParticle list and stores it in the StoreArray with the given name.
Definition: MCParticleGraph.cc:211
Belle2::BabayagaNLOInputModule::initialize
virtual void initialize() override
Initializes the module.
Definition: BabayagaNLOInputModule.cc:91
Belle2::BabayagaNLO::setMaxAcollinearity
void setMaxAcollinearity(double maxAcollinearity)
Sets maximum acollinearity angle between finale state leptons/photons in degrees.
Definition: BabayagaNLO.h:69
Belle2::BabayagaNLOInputModule::m_beamParams
DBObjPtr< BeamParameters > m_beamParams
BeamParameter.
Definition: BabayagaNLOInputModule.h:128
Belle2::BabayagaNLO::setVacPol
void setVacPol(const std::string &vacPol)
Sets vacuum polarization.
Definition: BabayagaNLO.h:89
Belle2::BabayagaNLOInputModule::m_temin
double m_temin
Minimum CMS angle between the tagged e-/e+ and -z axis (deg).
Definition: BabayagaNLOInputModule.h:102
Belle2::BabayagaNLOInputModule::m_nPhot
int m_nPhot
fixed number of nphot (hard) photons are generated.
Definition: BabayagaNLOInputModule.h:93
Belle2::BabayagaNLO::setEGMIN
void setEGMIN(double egmin)
Sets the minimum CMS energy of the gamma.
Definition: BabayagaNLO.h:149
Belle2::BabayagaNLO::setEEVETO
void setEEVETO(double eeveto)
Sets the minimum CMS energy to veto e-/e+.
Definition: BabayagaNLO.h:159
Belle2::Module::setDescription
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:216
Belle2::BabayagaNLOInputModule::m_eemin
double m_eemin
Minimum CMS energy of the tagged e-/e+ (GeV).
Definition: BabayagaNLOInputModule.h:101
Belle2::BabayagaNLOInputModule::m_NSKDataFile
std::string m_NSKDataFile
data file for the NSK VP data.
Definition: BabayagaNLOInputModule.h:98
Belle2::BabayagaNLO::setTGVETO
void setTGVETO(double tgveto)
Sets the maximum CMS angle between the gamma and -z axis.
Definition: BabayagaNLO.h:174
Belle2::BabayagaNLO::setMode
void setMode(const std::string &mode)
Sets mode: weighted or unweighted.
Definition: BabayagaNLO.h:99
Belle2::BabayagaNLO::setModel
void setModel(const std::string &model)
Sets model: matched or ps.
Definition: BabayagaNLO.h:94
Belle2::BabayagaNLOInputModule::m_eMin
double m_eMin
Minimum energy for leptons in the final state, in GeV.
Definition: BabayagaNLOInputModule.h:88
Belle2::BabayagaNLOInputModule::m_model
std::string m_model
model: matched or ps.
Definition: BabayagaNLOInputModule.h:83
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::BabayagaNLO::setScatAngle
void setScatAngle(std::pair< double, double > angleRange)
Sets the theta scattering angle range for the scattered particles.
Definition: BabayagaNLO.h:54
Belle2::BabayagaNLOInputModule::m_generator
BabayagaNLO m_generator
Variables.
Definition: BabayagaNLOInputModule.h:112
Belle2::BabayagaNLOInputModule::terminate
virtual void terminate() override
Method is called at the end of the event processing.
Definition: BabayagaNLOInputModule.cc:140
Belle2::BabayagaNLO::setEpsilon
void setEpsilon(double epsilon)
Sets soft/hard photon energy separator.
Definition: BabayagaNLO.h:84
Belle2::MCParticleGraph::c_checkCyclic
@ c_checkCyclic
Check for cyclic dependencies.
Definition: MCParticleGraph.h:75
Belle2::BabayagaNLOInputModule::~BabayagaNLOInputModule
virtual ~BabayagaNLOInputModule()
Destructor.
Definition: BabayagaNLOInputModule.cc:87
Belle2::BabayagaNLO::setEGVETO
void setEGVETO(double egveto)
Sets the minimum CMS energy to veto gamma.
Definition: BabayagaNLO.h:169
Belle2::BabayagaNLOInputModule::m_epsilon
double m_epsilon
Soft/hard photon separator in units of CMS/2.
Definition: BabayagaNLOInputModule.h:89
Belle2::BabayagaNLOInputModule::m_tgveto
double m_tgveto
Maximum CMS angle between the gamma and -z axis (deg).
Definition: BabayagaNLOInputModule.h:108
Belle2::BabayagaNLOInputModule::m_ScatteringAngleRange
std::vector< double > m_ScatteringAngleRange
Min [0] and Max [1] value for the scat.
Definition: BabayagaNLOInputModule.h:94
Belle2::InitialParticleGeneration::getBeamParameters
const BeamParameters & getBeamParameters() const
Return reference to nominal beam parameters.
Definition: InitialParticleGeneration.h:66
Belle2::BabayagaNLO::setVPUncertainty
void setVPUncertainty(bool vpuncertainty)
Calculate VP uncertainty by internal reweighting (on/off)
Definition: BabayagaNLO.h:119
Belle2::IOIntercept::OutputToLogMessages::finish
bool finish()
Finish the capture and emit the message if output has appeard on stdout or stderr.
Definition: IOIntercept.cc:245
Belle2::BabayagaNLO::generateEvent
void generateEvent(MCParticleGraph &mcGraph, double ecm, TVector3 vertex, TLorentzRotation boost)
Generates one single event.
Definition: BabayagaNLO.cc:334
Belle2::LogConfig::c_Info
@ c_Info
Info: for informational messages, e.g.
Definition: LogConfig.h:37
Belle2::BabayagaNLOInputModule::m_maxAcollinearity
double m_maxAcollinearity
maximum acollinearity angle between finale state leptons in degrees.
Definition: BabayagaNLOInputModule.h:90
Belle2::BabayagaNLO::setMinEnergy
void setMinEnergy(double minEnergy)
Sets minimum energy for leptons/photons in the final state, in GeV.
Definition: BabayagaNLO.h:79
Belle2::BabayagaNLOInputModule::m_tgmin
double m_tgmin
Minimum CMS angle between the gamma and -z axis (deg).
Definition: BabayagaNLOInputModule.h:104
Belle2::BabayagaNLO::setTGMIN
void setTGMIN(double tgmin)
Sets the minimum CMS angle between the gamma and -z axis.
Definition: BabayagaNLO.h:154
Belle2::InitialParticleGeneration
Generate Collision.
Definition: InitialParticleGeneration.h:35
Belle2::MCParticleGraph::c_setDecayInfo
@ c_setDecayInfo
Set decay time and vertex.
Definition: MCParticleGraph.h:74
Belle2::BabayagaNLOInputModule::m_eeveto
double m_eeveto
Minimum CMS energy to veto e-/e+ (GeV).
Definition: BabayagaNLOInputModule.h:105
Belle2::Module
Base class for Modules.
Definition: Module.h:74
Belle2::BabayagaNLO::term
void term()
Terminates the generator.
Definition: BabayagaNLO.cc:383
Belle2::BabayagaNLOInputModule::m_Uncertainty
bool m_Uncertainty
vary all VP related parameters and extracted total uncertainty.
Definition: BabayagaNLOInputModule.h:97
Belle2::BabayagaNLOInputModule::m_finalState
std::string m_finalState
Final state: ee, mm or gg.
Definition: BabayagaNLOInputModule.h:86
Belle2::BabayagaNLO::setEEMIN
void setEEMIN(double eemin)
Sets the minimum CMS energy of the tagged e-/e+.
Definition: BabayagaNLO.h:139
Belle2::BabayagaNLO::initExtraInfo
void initExtraInfo()
Initializes the extra info.
Definition: BabayagaNLO.cc:322
Belle2::BabayagaNLO::setFinalState
void setFinalState(const std::string &finalState)
Sets final state minimum energy.
Definition: BabayagaNLO.h:109
Belle2::BabayagaNLO::setUserMode
void setUserMode(const std::string &usermode)
Sets User mode similar to TEEGG: ETRON, EGAMMA, GAMMA or PRESCALE or NONE (default)
Definition: BabayagaNLO.h:129
Belle2::BabayagaNLOInputModule::m_vacPol
std::string m_vacPol
Vacuum polarization: off, hadr5 or hmnt.
Definition: BabayagaNLOInputModule.h:85
Belle2::MCInitialParticles
This class contains the initial state for the given event.
Definition: MCInitialParticles.h:35
Belle2::BabayagaNLO::setCmsEnergyNominal
void setCmsEnergyNominal(double cmsEnergyNominal)
Sets nominal ECM.
Definition: BabayagaNLO.h:74
Belle2::BabayagaNLOInputModule::m_fileExtraInfo
TFile * m_fileExtraInfo
Output file.
Definition: BabayagaNLOInputModule.h:114
Belle2::BabayagaNLOInputModule::m_initialized
bool m_initialized
True if generator has been initialized.
Definition: BabayagaNLOInputModule.h:127
Belle2::MCInitialParticles::getMass
double getMass() const
Get the invariant mass of the collision (= energy in CMS)
Definition: MCInitialParticles.h:152
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::BabayagaNLOInputModule::m_maxprescale
double m_maxprescale
Maximum prescale value.
Definition: BabayagaNLOInputModule.h:109
Belle2::BabayagaNLOInputModule::m_egmin
double m_egmin
Minimum CMS energy of the gamma (GeV).
Definition: BabayagaNLOInputModule.h:103
Belle2::BabayagaNLOInputModule::m_Spread
double m_Spread
TEMPORARY SOLUTION! Approximate energy spread per beam (CMS).
Definition: BabayagaNLOInputModule.h:96
Belle2::BabayagaNLO::setNPhotons
void setNPhotons(int nPhot)
Sets the fixed number of nphot (hard) photons.
Definition: BabayagaNLO.h:124
LogVar
Class to store variables with their name which were sent to the logging service.
Definition: LogVariableStream.h:24
Belle2::BabayagaNLOInputModule::m_fMax
double m_fMax
Maximum differential cross section weight.
Definition: BabayagaNLOInputModule.h:91
Belle2::IOIntercept::InterceptOutput::start
bool start()
Start intercepting the output.
Definition: IOIntercept.h:165
Belle2::BabayagaNLOInputModule::make_vector
std::vector< T > make_vector(T const &t1, T const &t2)
make_vector.
Definition: BabayagaNLOInputModule.h:136
Belle2::BabayagaNLOInputModule::s_initial
static InitialParticleGeneration s_initial
Initial particle for beam parameters, static because we need to call it from FORTRAN here.
Definition: BabayagaNLOInputModule.h:131
Belle2::BabayagaNLO::setFMax
void setFMax(double fMax)
Maximum differential cross section.
Definition: BabayagaNLO.h:64
Belle2::BabayagaNLO::setEnergySpread
void setEnergySpread(double spread)
TEMPORARY SOLUTION! Approximate energy spread per beam (CMS)
Definition: BabayagaNLO.h:114
Belle2::BabayagaNLOInputModule::m_egveto
double m_egveto
Minimum CMS energy to veto gamma (GeV).
Definition: BabayagaNLOInputModule.h:107
Belle2::BabayagaNLOInputModule::m_mode
std::string m_mode
mode: weighted or unweighted.
Definition: BabayagaNLOInputModule.h:84
Belle2::MCInitialParticles::getVertex
const TVector3 & getVertex() const
Get the position of the collision.
Definition: MCInitialParticles.h:143
Belle2::BabayagaNLOInputModule::m_fileNameExtraInfo
std::string m_fileNameExtraInfo
Extra ROOT file that contains the weight distribution to check overweight bias.
Definition: BabayagaNLOInputModule.h:95
Belle2::BabayagaNLOInputModule::m_th1dSDif
TH1D * m_th1dSDif
Histograms with the event weights.
Definition: BabayagaNLOInputModule.h:115
Belle2::BabayagaNLOInputModule::m_teveto
double m_teveto
Maximum CMS theta of e-/e+ in final state (deg).
Definition: BabayagaNLOInputModule.h:106
Belle2::Module::addParam
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition: Module.h:562
Belle2::BabayagaNLOInputModule::m_userMode
std::string m_userMode
User mode similar to TEEGG: ETRON, EGAMMA, GAMMA or PRESCALE or NONE.
Definition: BabayagaNLOInputModule.h:100
Belle2::BabayagaNLOInputModule::m_eMinFrac
double m_eMinFrac
Fractional energy (of cms energy) for leptons in the final state.
Definition: BabayagaNLOInputModule.h:87
Belle2::BabayagaNLOInputModule::vectorToPair
std::pair< T, T > vectorToPair(std::vector< T > &vec, const std::string &name="")
Definition: BabayagaNLOInputModule.h:145
Belle2::BabayagaNLO::setOrder
void setOrder(const std::string &order)
Sets Order: born, alpha or exp.
Definition: BabayagaNLO.h:104
Belle2::InitialParticleGeneration::initialize
void initialize()
function to be executed on initialize()
Definition: InitialParticleGeneration.cc:29
Belle2::IOIntercept::OutputToLogMessages
Capture stdout and stderr and convert into log messages.
Definition: IOIntercept.h:236
Belle2::MCInitialParticles::getCMSToLab
const TLorentzRotation & getCMSToLab() const
Return the LorentzRotation to convert from CMS to lab frame.
Definition: MCInitialParticles.h:161
Belle2::StoreArray< MCParticle >
Belle2::BabayagaNLO::setNSearchMax
void setNSearchMax(int nSearchMax)
Sets the number of events used to search maximum.
Definition: BabayagaNLO.h:59
Belle2::BabayagaNLOInputModule::m_nSearchMax
int m_nSearchMax
Events used to search maximum of differential cross section.
Definition: BabayagaNLOInputModule.h:92
Belle2::InitialParticleGeneration::generate
MCInitialParticles & generate()
Generate a new event.
Definition: InitialParticleGeneration.cc:84
Belle2::FileSystem::findFile
static std::string findFile(const std::string &path, bool silent=false)
Search for given file or directory in local or central release directory, and return absolute path if...
Definition: FileSystem.cc:147
Belle2::BabayagaNLO::setTEVETO
void setTEVETO(double teveto)
Sets the maximum CMS theta of e-/e+ in final state.
Definition: BabayagaNLO.h:164
Belle2::MCParticleGraph::clear
void clear()
Reset particles and decay information to make the class reusable.
Definition: MCParticleGraph.h:298
Belle2::BabayagaNLOInputModule::initializeGenerator
void initializeGenerator()
Method is called to initialize the generator.
Definition: BabayagaNLOInputModule.cc:145
Belle2::BeamParameters
This class contains the nominal beam parameters and the parameters used for smearing of the primary v...
Definition: BeamParameters.h:33
Belle2::BabayagaNLO::setNSKDataFile
void setNSKDataFile(const std::string &NSKDataFile)
Sets NSK VP data file.
Definition: BabayagaNLO.h:134
Belle2::BabayagaNLOInputModule::event
virtual void event() override
Method is called for each event.
Definition: BabayagaNLOInputModule.cc:111
Belle2::BabayagaNLO::setTEMIN
void setTEMIN(double temin)
Sets the minimum CMS angle between the tagged e-/e+ and -z axis.
Definition: BabayagaNLO.h:144
Belle2::BabayagaNLOInputModule::m_order
std::string m_order
Module parameters.
Definition: BabayagaNLOInputModule.h:82
Belle2::BabayagaNLO::init
void init()
Initializes the generator.
Definition: BabayagaNLO.cc:328
Belle2::BabayagaNLO::setMaxPrescale
void setMaxPrescale(double maxprescale)
Sets the maximum prescale value.
Definition: BabayagaNLO.h:179