Belle II Software  release-06-00-14
BgoDigitizerModule.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 <beast/bgo/modules/BgoDigitizerModule.h>
10 #include <beast/bgo/dataobjects/BgoSimHit.h>
11 
12 #include <framework/logging/Logger.h>
13 #include <framework/gearbox/GearDir.h>
14 #include <framework/core/RandomNumbers.h>
15 
16 //c++
17 #include <string>
18 #include <fstream>
19 #include <vector>
20 
21 using namespace std;
22 using namespace Belle2;
23 using namespace bgo;
24 
25 
26 //-----------------------------------------------------------------
27 // Register the Module
28 //-----------------------------------------------------------------
29 REG_MODULE(BgoDigitizer)
30 
31 //-----------------------------------------------------------------
32 // Implementation
33 //-----------------------------------------------------------------
34 
36 {
37  // Set module properties
38  setDescription("Bgo digitizer module");
39 
40  //Default values are set here. New values can be in BGO.xml.
41  //addParam("EnergyResolutionFactor", m_EnergyResolutionFactor, "Energy resolution factor ");
42  //addParam("EnergyResolutionConst", m_EnergyResolutionConst, "Energy resolution constant ");
43  //addParam("Threshold", m_Threshold, "Energy threshold");
44  //addParam("Range", m_Range, "Energy range")
45 }
46 
47 BgoDigitizerModule::~BgoDigitizerModule()
48 {
49 }
50 
51 void BgoDigitizerModule::initialize()
52 {
53  B2INFO("BgoDigitizer: Initializing");
54  m_bgoHit.registerInDataStore();
55 
56  //get xml data
57  getXMLData();
58 
59 }
60 
61 void BgoDigitizerModule::beginRun()
62 {
63 }
64 
65 void BgoDigitizerModule::event()
66 {
67  StoreArray<BgoSimHit> BgoSimHits;
68  StoreArray<BgoHit> BgoHits;
69  int nentries = BgoSimHits.getEntries();
70  for (int i = 0; i < nentries; i++) {
71  BgoSimHit* aHit = BgoSimHits[i];
72  int m_cellID = aHit->getCellId();
73  int m_trackID = aHit->getTrackId();
74  int pdgCode = aHit->getPDGCode();
75  double m_Time = aHit->getFlightTime();
76  TVector3 m_Mom = aHit->getMomentum();
77  TVector3 m_Pos = aHit->getPosition();
78  double m_energyDeposit = aHit->getEnergyDep();
79  double erecdep = m_energyDeposit;
80  erecdep += gRandom->Gaus(0, GetEnergyResolutionGeV(m_energyDeposit, m_cellID));
81  //if (m_Threshold[m_cellID] <= erecdep && erecdep <= m_Range[m_cellID]) {
82  BgoHits.appendNew(BgoHit(m_cellID, m_trackID, pdgCode, m_Time * m_energyDeposit / erecdep, m_energyDeposit, m_Mom,
83  m_Pos * (m_energyDeposit / erecdep), erecdep));
84  //}
85  }
86 
87 }
88 //read from BGO.xml
89 void BgoDigitizerModule::getXMLData()
90 {
91  GearDir content = GearDir("/Detector/DetectorComponent[@name=\"BGO\"]/Content/");
92 
93  //m_EnergyResolutionConst = content.getDouble("EnergyResolutionConst");
94  //m_EnergyResolutionFactor = content.getDouble("EnergyResolutionFactor");
95  int iEnResConst = 0;
96  for (double EnResConst : content.getArray("EnergyResolutionConst", {0})) {
97  m_EnergyResolutionConst[iEnResConst] = EnResConst;
98  iEnResConst++;
99  }
100  int iEnResFac = 0;
101  for (double EnResFac : content.getArray("EnergyResolutionFactor", {0})) {
102  m_EnergyResolutionFactor[iEnResFac] = EnResFac / 100.;
103  iEnResFac++;
104  }
105  int iThres = 0;
106  for (double Threshold : content.getArray("Threshold", {0})) {
107  //Threshold *= CLHEP::GeV;
108  m_Threshold[iThres] = Threshold;
109  iThres++;
110  }
111  int iRange = 0;
112  for (double Range : content.getArray("Range", {0})) {
113  //Range *= CLHEP::GeV;
114  m_Range[iRange] = Range;
115  iRange++;
116  }
117 
118  B2INFO("BgoDigitizer: Aquired bgo locations and gas parameters");
119  B2INFO(" from BGO.xml. There are " << nBGO << " BGOs implemented");
120 
121 }
122 
123 
124 Double_t BgoDigitizerModule::GetEnergyResolutionGeV(Double_t pEnergy, int CellId)
125 {
126  // Returns energy resolution in GeV when supplied Energy in GeV
127  return (m_EnergyResolutionFactor[CellId] * TMath::Sqrt(pEnergy) + m_EnergyResolutionConst[CellId] * pEnergy);
128 
129 }
130 
131 
132 void BgoDigitizerModule::endRun()
133 {
134 }
135 
136 void BgoDigitizerModule::terminate()
137 {
138 }
139 
140 
ClassBgoHit - Geant4 ulated hit for the Bgo crystal in beast.
Definition: BgoHit.h:31
ClassBgoSimHit - Geant4 simulated hit for the Bgo crystal in beast.
Definition: BgoSimHit.h:31
int getPDGCode() const
Get Particle PDG (can be one of secondaries)
Definition: BgoSimHit.h:99
int getTrackId() const
Get Track ID.
Definition: BgoSimHit.h:94
int getCellId() const
Get Cell ID.
Definition: BgoSimHit.h:89
double getFlightTime() const
Get Flight time from IP.
Definition: BgoSimHit.h:104
double getEnergyDep() const
Get Deposit energy.
Definition: BgoSimHit.h:109
TVector3 getMomentum() const
Get Momentum.
Definition: BgoSimHit.h:114
TVector3 getPosition() const
Get Position.
Definition: BgoSimHit.h:124
GearDir is the basic class used for accessing the parameter store.
Definition: GearDir.h:31
Base class for Modules.
Definition: Module.h:72
Represents a range of arithmetic types.
Definition: Range.h:29
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
T * appendNew()
Construct a new T object at the end of the array.
Definition: StoreArray.h:246
int getEntries() const
Get the number of objects in the array.
Definition: StoreArray.h:216
#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.