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