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