Belle II Software  release-05-02-19
QcsmonitorDigitizerModule.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/qcsmonitor/modules/QcsmonitorDigitizerModule.h>
12 #include <beast/qcsmonitor/dataobjects/QcsmonitorSimHit.h>
13 
14 #include <mdst/dataobjects/MCParticle.h>
15 #include <framework/logging/Logger.h>
16 #include <framework/gearbox/GearDir.h>
17 
18 //c++
19 #include <string>
20 #include <fstream>
21 
22 using namespace std;
23 using namespace Belle2;
24 using namespace qcsmonitor;
25 
26 
27 //-----------------------------------------------------------------
28 // Register the Module
29 //-----------------------------------------------------------------
30 REG_MODULE(QcsmonitorDigitizer)
31 
32 //-----------------------------------------------------------------
33 // Implementation
34 //-----------------------------------------------------------------
35 
37 {
38  // Set module properties
39  setDescription("Qcsmonitor digitizer module");
40 
41  //Default values are set here. New values can be in QCSMONITOR.xml.
42  addParam("ScintCell", m_ScintCell, "Number of scintillator cell", 2);
43  addParam("TimeStep", m_TimeStep, "Time step", 0.8);
44  addParam("C_keV_to_MIP", m_C_keV_to_MIP, "C_keV_to_MIP", 241.65);
45  addParam("C_MIP_to_PE", m_C_MIP_to_PE, "C_MIP_to_PE", 15.0);
46  addParam("MinTime", m_MinTime, "Min. time", 0.0);
47  addParam("MaxTime", m_MaxTime, "Max. time", 750.0);
48  addParam("MIPthres", m_MIPthres, "Energy threshold in keV", 0.5);
49 }
50 
51 QcsmonitorDigitizerModule::~QcsmonitorDigitizerModule()
52 {
53 }
54 
55 void QcsmonitorDigitizerModule::initialize()
56 {
57  B2INFO("QcsmonitorDigitizer: Initializing");
58  m_qcsmonitorHit.registerInDataStore();
59 
60  //get the garfield drift data, gas, and QCSMONITOR paramters
61  getXMLData();
62 
63 }
64 
65 void QcsmonitorDigitizerModule::beginRun()
66 {
67 }
68 
69 void QcsmonitorDigitizerModule::event()
70 {
71 
72  StoreArray<MCParticle> particles;
73  StoreArray<QcsmonitorSimHit> QcsmonitorSimHits;
74  StoreArray<QcsmonitorHit> QcsmonitorHits;
75 
76  //Skip events with no QcsmonitorSimHits, but continue the event counter
77  if (QcsmonitorSimHits.getEntries() == 0) {
78  return;
79  }
80 
83 
84  int number_of_timebins = (int)((m_MaxTime - m_MinTime) / m_TimeStep);
85 
86  for (int i = 0; i < 1000; i ++)
87  for (int j = 0; j < 100; j ++)
88  hitsarrayinMIP[i][j] = 0;
89 
90  for (const auto& SimHit : SimHits) {
91  const int detNb = SimHit.getCellId();
92  const double Edep = SimHit.getEnergyDep() * 1e6; //GeV -> keV
93  const double tof = SimHit.getFlightTime(); //ns
94  int TimeBin = tof / m_TimeStep;
95  double MIP = Edep / m_C_keV_to_MIP;
96  //double PE = MIP * m_C_MIP_to_PE;
97  if (m_MinTime < tof && tof < m_MaxTime && TimeBin < 1000 && detNb < 100)
98  hitsarrayinMIP[TimeBin][detNb] += MIP;
99  }
100 
101  /*
102  for (const auto& SimHit : SimHits) {
103  const int detNb = SimHit.getCellId();
104  //int pdg = SimHit.getPDGCode();
105  const double Edep = SimHit.getEnergyDep() * 1e6; //GeV -> keV
106  const double tof = SimHit.getFlightTime(); //ns
107  int TimeBin = tof / m_TimeStep;
108  double MIP = Edep / m_C_keV_to_MIP;
109  double PE = MIP * m_C_MIP_to_PE;
110  if ((m_MinTime < tof && tof < m_MaxTime) && MIP > m_MIPthres)
111  //if (hitsarrayinMIP[TimeBin][detNb] > m_MIPthres)
112  Hits.appendNew(QcsmonitorHit(detNb, TimeBin, Edep, MIP, PE));
113  }
114  */
115 
116  for (int i = 0; i < number_of_timebins; i ++) {
117  for (int j = 0; j < m_ScintCell; j ++) {
118  if (hitsarrayinMIP[i][j] > m_MIPthres) {
119  double MIP = hitsarrayinMIP[i][j];
120  double Edep = MIP * m_C_keV_to_MIP * 1e-6; //keV -> GeV.
121  double PE = MIP * m_C_MIP_to_PE;
122  Hits.appendNew(QcsmonitorHit(j, i, Edep, MIP, PE));
123  }
124  }
125  }
126 
127 }
128 
129 //read tube centers, impulse response, and garfield drift data filename from QCSMONITOR.xml
130 void QcsmonitorDigitizerModule::getXMLData()
131 {
132  GearDir content = GearDir("/Detector/DetectorComponent[@name=\"QCSMONITOR\"]/Content/");
133 
134  m_ScintCell = content.getInt("ScintCell");
135  m_TimeStep = content.getDouble("TimeStep");
136  m_MinTime = content.getDouble("MinTime");
137  m_MaxTime = content.getDouble("MaxTime");
138  m_MIPthres = content.getDouble("MIPthres");
139  m_C_keV_to_MIP = content.getDouble("C_keV_to_MIP");
140  m_C_MIP_to_PE = content.getDouble("C_MIP_to_PE");
141 
142  B2INFO("QcsmonitorDigitizer: Aquired qcsmonitor locations and gas parameters");
143 
144 }
145 
146 void QcsmonitorDigitizerModule::endRun()
147 {
148 }
149 
150 void QcsmonitorDigitizerModule::terminate()
151 {
152 }
153 
154 
Belle2::qcsmonitor::QcsmonitorDigitizerModule
Qcsmonitor tube digitizer.
Definition: QcsmonitorDigitizerModule.h:35
Belle2::StoreArray::appendNew
T * appendNew()
Construct a new T object at the end of the array.
Definition: StoreArray.h:256
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::Module
Base class for Modules.
Definition: Module.h:74
Belle2::QcsmonitorHit
ClassQcsmonitorHit - digitization simulated hit for the Qcsmonitor detector.
Definition: QcsmonitorHit.h:36
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::GearDir
GearDir is the basic class used for accessing the parameter store.
Definition: GearDir.h:41
Belle2::StoreArray< MCParticle >
Belle2::StoreArray::getEntries
int getEntries() const
Get the number of objects in the array.
Definition: StoreArray.h:226