Belle II Software development
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#include <TMath.h>
17
18//c++
19#include <string>
20#include <fstream>
21#include <vector>
22
23using namespace std;
24using namespace Belle2;
25using namespace csi;
26
27
28//-----------------------------------------------------------------
29// Register the Module
30//-----------------------------------------------------------------
31REG_MODULE(CsiDigitizer_v2);
32
33//-----------------------------------------------------------------
34// Implementation
35//-----------------------------------------------------------------
36
38{
39 // Set module properties
40 setDescription("Csi digitizer_v2 module");
41
42 //Default values are set here. New values can be in CSI.xml.
43 //addParam("EnergyResolutionPureCsIFactor", m_EnergyResolutionPureCsIFactor, "Energy resolution factor ", 1.4);
44 //addParam("EnergyResolutionPureCsIConst", m_EnergyResolutionPureCsIConst, "Energy resolution constant ", 1.4);
45}
46
48{
49}
50
52{
53 B2INFO("CsiDigitizer_v2: Initializing");
54 m_csiHit_v2.registerInDataStore();
55
56 //get xml data
57 getXMLData();
58
59}
60
62{
63}
64
66{
67 StoreArray<CsiSimHit> CsiSimHits;
68 StoreArray<CsiHit_v2> CsiHits_v2;
69 int nentries = CsiSimHits.getEntries();
70 for (int i = 0; i < nentries; i++) {
71 CsiSimHit* aHit = CsiSimHits[i];
72 int m_cellID = aHit->getCellId();
73 int m_box = (int)m_cellID / 6;
74 int m_cry = m_cellID - m_box * 3;
75 int m_trackID = aHit->getTrackId();
76 int pdgCode = aHit->getPDGCode();
77 double m_Time = aHit->getFlightTime();
78 ROOT::Math::XYZVector m_Mom = aHit->getMomentum();
79 ROOT::Math::XYZVector m_Pos = aHit->getPosition();
80 double m_energyDeposit = aHit->getEnergyDep();
81 double erecdep = m_energyDeposit;
82 erecdep += gRandom->Gaus(0, GetEnergyResolutionGeV(m_energyDeposit, m_cry));
83 //if (m_Threshold[m_cry] <= erecdep && erecdep <= m_Range[m_cry]) {
84 CsiHits_v2.appendNew(CsiHit_v2(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 CSI.xml
92{
93 GearDir content = GearDir("/Detector/DetectorComponent[@name=\"CSI\"]/Content/");
94
95 int iEnergyResolutionConst = 0;
96 for (double EnergyResolutionConst : content.getArray("EnergyResolutionConst", {0})) {
97 m_EnergyResolutionConst[iEnergyResolutionConst] = EnergyResolutionConst;
98 iEnergyResolutionConst++;
99 }
100 int iEnergyResolutionFactor = 0;
101 for (double EnergyResolutionFactor : content.getArray("EnergyResolutionFactor", {0})) {
102 m_EnergyResolutionFactor[iEnergyResolutionFactor] = EnergyResolutionFactor;
103 iEnergyResolutionFactor++;
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("CsiDigitizer_V2: Aquired csi locations and gas parameters");
119 B2INFO(" from CSI.xml. There are " << nCSI << " CSIs implemented");
120
121}
122
123
124Double_t CsiDigitizer_v2Module::GetEnergyResolutionGeV(Double_t pEnergy, int pcry)
125{
126 // Returns energy resolution in GeV when supplied Energy in GeV
127 return (m_EnergyResolutionFactor[pcry] * TMath::Sqrt(pEnergy) + m_EnergyResolutionConst[pcry] * pEnergy);
128
129}
130
131
133{
134}
135
137{
138}
139
140
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
ROOT::Math::XYZVector getMomentum() const
Get Momentum.
Definition: CsiSimHit.h:112
ROOT::Math::XYZVector 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.
CsiDigitizer_v2Module()
Constructor: Sets the description, the properties and the parameters of the module.
#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.
STL namespace.