Belle II Software  release-08-01-10
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 
35 BgoDigitizerModule::BgoDigitizerModule() : Module()
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 
48 {
49 }
50 
52 {
53  B2INFO("BgoDigitizer: Initializing");
54  m_bgoHit.registerInDataStore();
55 
56  //get xml data
57  getXMLData();
58 
59 }
60 
62 {
63 }
64 
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
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 
133 {
134 }
135 
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
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
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
int nBGO
number of detectors.
virtual void initialize() override
Initialize the Module.
double m_EnergyResolutionConst[8]
Energy resolution constant.
virtual void event() override
Event processor.
virtual ~BgoDigitizerModule()
Destructor.
double m_Threshold[8]
Energy threshold.
virtual void endRun() override
End-of-run action.
virtual void getXMLData()
reads data from BGO.xml: threshold in MeV, range in MeV, and resolution in %
double m_EnergyResolutionFactor[8]
Energy resolution factor.
virtual void terminate() override
Termination action.
StoreArray< BgoHit > m_bgoHit
Array for Bgo Hits.
virtual void beginRun() override
Called when entering a new run.
double m_Range[8]
Energy range.
Double_t GetEnergyResolutionGeV(Double_t, Int_t)
Fold energy resolution.
#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.