Belle II Software  release-06-02-00
BBBremInputModule.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/bbbreminput/BBBremInputModule.h>
10 
11 #include <framework/logging/Logger.h>
12 #include <framework/datastore/DataStore.h>
13 #include <framework/datastore/StoreArray.h>
14 #include <framework/datastore/StoreObjPtr.h>
15 #include <framework/dataobjects/EventMetaData.h>
16 
17 using namespace std;
18 using namespace Belle2;
19 
20 //-----------------------------------------------------------------
21 // Register the Module
22 //-----------------------------------------------------------------
23 REG_MODULE(BBBremInput)
24 
25 
26 //-----------------------------------------------------------------
27 // Implementation
28 //-----------------------------------------------------------------
29 
30 BBBremInputModule::BBBremInputModule() : Module(), m_initial(BeamParameters::c_smearVertex)
31 {
32  //Set module properties
33  setDescription("Generates low scattering angle radiative Bhabha events (Beam-Beam Bremsstrahlung).");
34 
35  //Parameter definition
36  addParam("MinPhotonEnergyFraction", m_photonEFrac, "Fraction of the minimum photon energy.", 0.000001);
37  addParam("Unweighted", m_unweighted, "Produce unweighted or weighted events.", true);
38  addParam("MaxWeight", m_maxWeight, "The max weight (only for Unweighted=True).", 2000.0);
39  addParam("DensityCorrectionMode", m_densityCorrectionMode, "Mode for bunch density correction (none=0, hard=1 (default), soft=2)",
40  1);
41  addParam("DensityCorrectionParameter", m_DensityCorrectionParameter, "Density correction parameter tc (=(hbarc/sigma_y)^2)",
42  1.68e-17);
43 }
44 
45 
46 BBBremInputModule::~BBBremInputModule()
47 {
48 
49 }
50 
51 
52 void BBBremInputModule::initialize()
53 {
54  StoreArray<MCParticle> mcparticle;
55  mcparticle.registerInDataStore();
56 
57  //Beam Parameters, initial particle - BBBREM cannot handle beam energy spread
58  m_initial.initialize();
59 
60 }
61 
62 
63 void BBBremInputModule::event()
64 {
65  // Check if the BeamParameters have changed (if they do, abort the job! otherwise cross section calculation will be a nightmare.)
66  if (m_beamParams.hasChanged()) {
67  if (!m_initialized) {
68  initializeGenerator();
69  } else {
70  B2FATAL("BBBremInputModule::event(): BeamParameters have changed within a job, this is not supported for BBBREM!");
71  }
72  }
73 
74  StoreObjPtr<EventMetaData> evtMetaData("EventMetaData", DataStore::c_Event);
75 
76  // initial particle from beam parameters
77  const MCInitialParticles& initial = m_initial.generate();
78 
79  // true boost
80  TLorentzRotation boost = initial.getCMSToLab();
81 
82  // vertex
83  TVector3 vertex = initial.getVertex();
84 
85  m_mcGraph.clear();
86  double weight = m_generator.generateEvent(m_mcGraph, vertex, boost);
87 
88  m_mcGraph.generateList("", MCParticleGraph::c_setDecayInfo | MCParticleGraph::c_checkCyclic);
89 
90  //store the weight (1.0 for unweighted events)
91  evtMetaData->setGeneratedWeight(weight);
92 }
93 
94 
95 void BBBremInputModule::terminate()
96 {
97  m_generator.term();
98 
99  B2RESULT("Cross-section (weighted): " << m_generator.getCrossSection() << " +/- " <<
100  m_generator.getCrossSectionError() << " [mb]");
101  B2RESULT("Maximum weight delivered: " << m_generator.getMaxWeightDelivered());
102  B2RESULT("Overweight bias cross-section (unweighted): " << m_generator.getCrossSectionOver() << " +/- " <<
103  m_generator.getCrossSectionErrorOver() << " [mb]");
104 }
105 
106 void BBBremInputModule::initializeGenerator()
107 {
108 
109  const BeamParameters& nominal = m_initial.getBeamParameters();
110  double centerOfMassEnergy = nominal.getMass();
111 
112  m_generator.init(centerOfMassEnergy, m_photonEFrac, m_unweighted, m_maxWeight, m_densityCorrectionMode,
113  m_DensityCorrectionParameter);
114 
115  m_initialized = true;
116 
117 }
The BBBrem Generator module.
This class contains the nominal beam parameters and the parameters used for smearing of the primary v...
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.
Base class for Modules.
Definition: Module.h:72
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:95
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
Abstract base class for different kinds of events.