Belle II Software  release-08-01-10
CsiDigitizer_v2Module.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/csi/modules/CsiDigitizer_v2Module.h>
10 #include <beast/csi/dataobjects/CsiSimHit.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 csi;
24 
25 
26 //-----------------------------------------------------------------
27 // Register the Module
28 //-----------------------------------------------------------------
29 REG_MODULE(CsiDigitizer_v2);
30 
31 //-----------------------------------------------------------------
32 // Implementation
33 //-----------------------------------------------------------------
34 
35 CsiDigitizer_v2Module::CsiDigitizer_v2Module() : Module()
36 {
37  // Set module properties
38  setDescription("Csi digitizer_v2 module");
39 
40  //Default values are set here. New values can be in CSI.xml.
41  //addParam("EnergyResolutionPureCsIFactor", m_EnergyResolutionPureCsIFactor, "Energy resolution factor ", 1.4);
42  //addParam("EnergyResolutionPureCsIConst", m_EnergyResolutionPureCsIConst, "Energy resolution constant ", 1.4);
43 }
44 
46 {
47 }
48 
50 {
51  B2INFO("CsiDigitizer_v2: Initializing");
52  m_csiHit_v2.registerInDataStore();
53 
54  //get xml data
55  getXMLData();
56 
57 }
58 
60 {
61 }
62 
64 {
65  StoreArray<CsiSimHit> CsiSimHits;
66  StoreArray<CsiHit_v2> CsiHits_v2;
67  int nentries = CsiSimHits.getEntries();
68  for (int i = 0; i < nentries; i++) {
69  CsiSimHit* aHit = CsiSimHits[i];
70  int m_cellID = aHit->getCellId();
71  int m_box = (int)m_cellID / 6;
72  int m_cry = m_cellID - m_box * 3;
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_cry));
81  //if (m_Threshold[m_cry] <= erecdep && erecdep <= m_Range[m_cry]) {
82  CsiHits_v2.appendNew(CsiHit_v2(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 CSI.xml
90 {
91  GearDir content = GearDir("/Detector/DetectorComponent[@name=\"CSI\"]/Content/");
92 
93  int iEnergyResolutionConst = 0;
94  for (double EnergyResolutionConst : content.getArray("EnergyResolutionConst", {0})) {
95  m_EnergyResolutionConst[iEnergyResolutionConst] = EnergyResolutionConst;
96  iEnergyResolutionConst++;
97  }
98  int iEnergyResolutionFactor = 0;
99  for (double EnergyResolutionFactor : content.getArray("EnergyResolutionFactor", {0})) {
100  m_EnergyResolutionFactor[iEnergyResolutionFactor] = EnergyResolutionFactor;
101  iEnergyResolutionFactor++;
102  }
103  int iThres = 0;
104  for (double Threshold : content.getArray("Threshold", {0})) {
105  //Threshold *= CLHEP::GeV;
106  m_Threshold[iThres] = Threshold;
107  iThres++;
108  }
109  int iRange = 0;
110  for (double Range : content.getArray("Range", {0})) {
111  //Range *= CLHEP::GeV;
112  m_Range[iRange] = Range;
113  iRange++;
114  }
115 
116  B2INFO("CsiDigitizer_V2: Aquired csi locations and gas parameters");
117  B2INFO(" from CSI.xml. There are " << nCSI << " CSIs implemented");
118 
119 }
120 
121 
122 Double_t CsiDigitizer_v2Module::GetEnergyResolutionGeV(Double_t pEnergy, int pcry)
123 {
124  // Returns energy resolution in GeV when supplied Energy in GeV
125  return (m_EnergyResolutionFactor[pcry] * TMath::Sqrt(pEnergy) + m_EnergyResolutionConst[pcry] * pEnergy);
126 
127 }
128 
129 
131 {
132 }
133 
135 {
136 }
137 
138 
ClassCsiHit_v2 - Geant4 simulated hits in CsI crystals in BEAST.
Definition: CsiHit_v2.h:31
ClassCsiSimHit - Geant4 simulated hits in CsI crystals in BEAST.
Definition: CsiSimHit.h:31
int getPDGCode() const
Get Particle PDG (can be one of secondaries)
Definition: CsiSimHit.h:97
int getTrackId() const
Get Track ID.
Definition: CsiSimHit.h:92
int getCellId() const
Get Cell ID.
Definition: CsiSimHit.h:87
double getFlightTime() const
Get Flight time from IP.
Definition: CsiSimHit.h:102
double getEnergyDep() const
Get Deposit energy.
Definition: CsiSimHit.h:107
TVector3 getMomentum() const
Get Momentum.
Definition: CsiSimHit.h:112
TVector3 getPosition() const
Get Position.
Definition: CsiSimHit.h:122
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
virtual void initialize() override
Initialize the Module.
virtual void event() override
Event processor.
double m_EnergyResolutionConst[18]
Energy resolution constant.
Double_t GetEnergyResolutionGeV(Double_t, int)
Fold energy resolution.
virtual void endRun() override
End-of-run action.
virtual void getXMLData()
reads data from CSI.xml: threshold in MeV, range in MeV, and resolution in %
virtual void terminate() override
Termination action.
StoreArray< CsiHit_v2 > m_csiHit_v2
array for CsiHit_v2
virtual void beginRun() override
Called when entering a new run.
double m_Threshold[18]
Energy threshold.
double m_EnergyResolutionFactor[18]
Energy resolution factor.
#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.