Belle II Software  release-05-02-19
CsiDigitizer_v2Module.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/csi/modules/CsiDigitizer_v2Module.h>
12 #include <beast/csi/dataobjects/CsiSimHit.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 csi;
26 
27 
28 //-----------------------------------------------------------------
29 // Register the Module
30 //-----------------------------------------------------------------
31 REG_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 
47 CsiDigitizer_v2Module::~CsiDigitizer_v2Module()
48 {
49 }
50 
51 void CsiDigitizer_v2Module::initialize()
52 {
53  B2INFO("CsiDigitizer_v2: Initializing");
54  m_csiHit_v2.registerInDataStore();
55 
56  //get xml data
57  getXMLData();
58 
59 }
60 
61 void CsiDigitizer_v2Module::beginRun()
62 {
63 }
64 
65 void CsiDigitizer_v2Module::event()
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  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_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
91 void CsiDigitizer_v2Module::getXMLData()
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 
124 Double_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 
132 void CsiDigitizer_v2Module::endRun()
133 {
134 }
135 
136 void CsiDigitizer_v2Module::terminate()
137 {
138 }
139 
140 
Belle2::StoreArray::appendNew
T * appendNew()
Construct a new T object at the end of the array.
Definition: StoreArray.h:256
Belle2::CsiSimHit::getEnergyDep
double getEnergyDep() const
Get Deposit energy.
Definition: CsiSimHit.h:124
Belle2::CsiHit_v2
ClassCsiHit_v2 - Geant4 simulated hits in CsI crystals in BEAST.
Definition: CsiHit_v2.h:41
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::CsiSimHit
ClassCsiSimHit - Geant4 simulated hits in CsI crystals in BEAST.
Definition: CsiSimHit.h:41
Belle2::CsiSimHit::getTrackId
int getTrackId() const
Get Track ID.
Definition: CsiSimHit.h:109
Belle2::Module
Base class for Modules.
Definition: Module.h:74
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::csi::CsiDigitizer_v2Module
Csi tube digitizer_v2.
Definition: CsiDigitizer_v2Module.h:41
Belle2::CsiSimHit::getCellId
int getCellId() const
Get Cell ID.
Definition: CsiSimHit.h:104
Belle2::CsiSimHit::getMomentum
TVector3 getMomentum() const
Get Momentum.
Definition: CsiSimHit.h:129
Belle2::CsiSimHit::getFlightTime
double getFlightTime() const
Get Flight time from IP.
Definition: CsiSimHit.h:119
Belle2::CsiSimHit::getPosition
TVector3 getPosition() const
Get Position.
Definition: CsiSimHit.h:139
Belle2::StoreArray
Accessor to arrays stored in the data store.
Definition: ECLMatchingPerformanceExpertModule.h:33
Belle2::CsiSimHit::getPDGCode
int getPDGCode() const
Get Particle PDG (can be one of secondaries)
Definition: CsiSimHit.h:114
Belle2::StoreArray::getEntries
int getEntries() const
Get the number of objects in the array.
Definition: StoreArray.h:226