Belle II Software development
SetupGenfitExtrapolationModule.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//
10// Common setup for everything that uses genfit's extrapolation code.
11//
12
13#include <tracking/modules/genfitUtilities/SetupGenfitExtrapolationModule.h>
14#include <tracking/modules/genfitUtilities/Geant4MaterialInterface.h>
15
16#include <geometry/GeometryManager.h>
17
18#include <tracking/gfbfield/GFGeant4Field.h>
19#include <genfit/FieldManager.h>
20#include <genfit/MaterialEffects.h>
21#include <genfit/TGeoMaterialInterface.h>
22#include <genfit/IO.h>
23
24#include <boost/iostreams/stream_buffer.hpp>
25#include <boost/iostreams/concepts.hpp>
26
27#include <TGeoManager.h>
28
29using namespace Belle2;
30
31REG_MODULE(SetupGenfitExtrapolation)
32
33namespace {
36 template<size_t T_level>
37 class genfitSink : public boost::iostreams::sink {
38 public:
40 std::streamsize write(const char* s, std::streamsize n)
41 {
42 B2DEBUG(T_level, s);
43 return n;
44 }
45 };
46
48 genfitSink<200> debugSink;
50 boost::iostreams::stream_buffer<genfitSink<200> > debugStreamBuf(debugSink);
52 genfitSink<100> errorSink;
54 boost::iostreams::stream_buffer<genfitSink<100> > errorStreamBuf(errorSink);
56 genfitSink<150> printSink;
58 boost::iostreams::stream_buffer<genfitSink<150> > printStreamBuf(printSink);
59
61 void setupGenfitStreams()
62 {
63 genfit::debugOut.rdbuf(&debugStreamBuf);
64 genfit::errorOut.rdbuf(&errorStreamBuf);
65 genfit::printOut.rdbuf(&printStreamBuf);
66 }
67}
68
70 Module(), m_vxdAlignment()
71{
72
73 setDescription("Sets up material handling for genfit extrapolation. Also setups up I/O streams for"
74 " genfit in order to integrate it into basf2 logging system. Also sets up update of VXDAlignment from DB (temporary).");
76
77 addParam("ignoreIfPresent", m_ignoreIfPresent,
78 "If true this module will silently ignore if the geometry is already "
79 "present and do nothing in that case. If false a B2FATAL will be "
80 "if the geometry was already created before", m_ignoreIfPresent);
81
82 //input
83 addParam("whichGeometry", m_geometry,
84 "Which geometry should be used, either 'TGeo' or 'Geant4'", m_geometry);
85
86 // Energy loss, multiple scattering configuration.
87 addParam("energyLossBetheBloch", m_energyLossBetheBloch,
88 "activate the material effect: EnergyLossBetheBloch", m_energyLossBetheBloch);
89 addParam("noiseBetheBloch", m_noiseBetheBloch,
90 "activate the material effect: NoiseBetheBloch", m_noiseBetheBloch);
91 addParam("noiseCoulomb", m_noiseCoulomb,
92 "activate the material effect: NoiseCoulomb", m_noiseCoulomb);
93 addParam("energyLossBrems", m_energyLossBrems,
94 "activate the material effect: EnergyLossBrems", m_energyLossBrems);
95 addParam("noiseBrems", m_noiseBrems,
96 "activate the material effect: NoiseBrems", m_noiseBrems);
97 addParam("noEffects", m_noEffects,
98 "switch off all material effects in Genfit. This overwrites all "
99 "individual material effects switches", m_noEffects);
100 addParam("MSCModel", m_mscModel,
101 "Multiple scattering model", m_mscModel);
102 addParam("useVXDAlignment", m_useVXDAlignment,
103 "Use VXD alignment from database?", m_useVXDAlignment);
104}
105
107{
108 if (genfit::FieldManager::getInstance()->isInitialized() or genfit::MaterialEffects::getInstance()->isInitialized()) {
109 if (m_ignoreIfPresent) {
110 B2DEBUG(29, "Magnetic field or material handling already initialized. Not touching settings.");
111 return;
112 } else {
113 B2FATAL("Magnetic field or material handling already initialized. Not touching settings.");
114 }
115 }
116
117 setupGenfitStreams();
118
119 genfit::FieldManager::getInstance()->init(new GFGeant4Field());
120 genfit::FieldManager::getInstance()->useCache();
121
122 if (!geometry::GeometryManager::getInstance().getTopVolume()) {
123 B2FATAL("No geometry set up so far. Load the geometry module.");
124 }
125
126 if (m_geometry == "TGeo") {
127 if (!gGeoManager) {
128 B2INFO("Building TGeo representation.");
130 geoManager.createTGeoRepresentation();
131 }
132 genfit::MaterialEffects::getInstance()->init(new genfit::TGeoMaterialInterface());
133 } else if (m_geometry == "Geant4") {
134 genfit::MaterialEffects::getInstance()->init(new Geant4MaterialInterface());
135 } else {
136 B2FATAL("Invalid choice of geometry interface. Please use 'TGeo' or 'Geant4'.");
137 }
138
139 // activate / deactivate material effects in genfit
140 if (m_noEffects) {
141 genfit::MaterialEffects::getInstance()->setNoEffects(true);
142 } else {
143 genfit::MaterialEffects::getInstance()->setEnergyLossBetheBloch(m_energyLossBetheBloch);
144 genfit::MaterialEffects::getInstance()->setNoiseBetheBloch(m_noiseBetheBloch);
145 genfit::MaterialEffects::getInstance()->setNoiseCoulomb(m_noiseCoulomb);
146 genfit::MaterialEffects::getInstance()->setEnergyLossBrems(m_energyLossBrems);
147 genfit::MaterialEffects::getInstance()->setNoiseBrems(m_noiseBrems);
148 genfit::MaterialEffects::getInstance()->setMscModel(m_mscModel);
149 }
150}
AbsMaterialInterface implementation for use with Geant4's navigator.
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
Definition: Module.cc:208
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Definition: Module.h:80
std::string m_mscModel
Multiple scattering model.
std::string m_geometry
choice of geometry representation: 'TGeo' or 'Geant4'.
bool m_noEffects
switch on/off ALL material effects in Genfit. "true" overwrites "true" flags for the individual effec...
void initialize() override
Initialize the Module.
bool m_noiseBetheBloch
Determines if calculation of energy loss variance is on/off in Genfit.
bool m_noiseBrems
Determines if calculation of bremsstrahlung energy loss variance is on/off in Genfit.
bool m_energyLossBrems
Determines if calculation of bremsstrahlung energy loss is on/off in Genfit.
bool m_noiseCoulomb
Determines if calculation of multiple scattering covariance matrix on/off in Genfit.
bool m_useVXDAlignment
Use VXD alignment from database?
bool m_energyLossBetheBloch
Determines if calculation of energy loss is on/off in Genfit.
bool m_ignoreIfPresent
Whether or not this module will raise an error if the geometry is already present.
Class to manage the creation and conversion of the geometry.
static GeometryManager & getInstance()
Return a reference to the instance.
void createTGeoRepresentation()
Create a TGeo representation of the native geometry description.
Interface of the Belle II B-field with GenFit.
Definition: GFGeant4Field.h:16
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
Abstract base class for different kinds of events.