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