Belle II Software  release-05-02-19
ClawDigitizerModule.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/claw/modules/ClawDigitizerModule.h>
12 #include <beast/claw/dataobjects/ClawSimHit.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 #include <vector>
22 
23 using namespace std;
24 using namespace Belle2;
25 using namespace claw;
26 
27 
28 //-----------------------------------------------------------------
29 // Register the Module
30 //-----------------------------------------------------------------
31 REG_MODULE(ClawDigitizer)
32 
33 //-----------------------------------------------------------------
34 // Implementation
35 //-----------------------------------------------------------------
36 
38 {
39  // Set module properties
40  setDescription("Claw digitizer module");
41 
42  //Default values are set here. New values can be in CLAW.xml.
43  addParam("ScintCell", m_ScintCell, "Number of scintillator cell", 16);
44  addParam("TimeStep", m_TimeStep, "Time step", 0.8);
45  addParam("C_keV_to_MIP", m_C_keV_to_MIP, "C_keV_to_MIP", 805.5);
46  addParam("C_MIP_to_PE", m_C_MIP_to_PE, "C_MIP_to_PE");
47  addParam("MinTime", m_MinTime, "Min. time", 0.0);
48  addParam("MaxTime", m_MaxTime, "Max. time", 750.0);
49  addParam("PEthres", m_PEthres, "Energy threshold in keV", 1.0);
50 }
51 
52 ClawDigitizerModule::~ClawDigitizerModule()
53 {
54 }
55 
56 void ClawDigitizerModule::initialize()
57 {
58  B2INFO("ClawDigitizer: Initializing");
59  m_clawHit.registerInDataStore();
60 
61  //get the garfield drift data, gas, and CLAW paramters
62  getXMLData();
63 
64 }
65 
66 void ClawDigitizerModule::beginRun()
67 {
68 }
69 
70 void ClawDigitizerModule::event()
71 {
72 
73  StoreArray<MCParticle> particles;
74  StoreArray<ClawSimHit> ClawSimHits;
75  StoreArray<ClawHit> ClawHits;
76 
77  //Skip events with no ClawSimHits, but continue the event counter
78  if (ClawSimHits.getEntries() == 0) {
79  return;
80  }
81 
82  StoreArray<ClawSimHit> SimHits;
84  /*
85  int number_of_timebins = (int)((m_MaxTime - m_MinTime) / m_TimeStep);
86 
87  for (int i = 0; i < 1000; i ++)
88  for (int j = 0; j < 100; j ++)
89  hitsarrayinPE[i][j] = 0;
90 
91  for (const auto& SimHit : SimHits) {
92  const int detNb = SimHit.getCellId();
93  const double Edep = SimHit.getEnergyDep() * 1e6; //GeV -> keV
94  const double tof = SimHit.getFlightTime(); //ns
95  int TimeBin = tof / m_TimeStep;
96  double MIP = Edep / m_C_keV_to_MIP;
97  double PE = MIP * m_C_MIP_to_PE;
98  if (m_MinTime < tof && tof < m_MaxTime && TimeBin < 1000 && detNb < 100)
99  hitsarrayinPE[TimeBin][detNb] += PE;
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[detNb];
110  if ((m_MinTime < tof && tof < m_MaxTime) && PE > m_PEthres)
111  Hits.appendNew(ClawHit(detNb, TimeBin, Edep, MIP, PE));
112  }
113  /*
114  for (int i = 0; i < number_of_timebins; i ++) {
115  for (int j = 0; j < m_ScintCell; j ++) {
116  if (hitsarrayinPE[i][j] > m_PEthres) {
117  double PE = hitsarrayinPE[i][j];
118  double MIP = PE / m_C_MIP_to_PE;
119  double Edep = MIP * m_C_keV_to_MIP * 1e-6; //keV -> GeV.
120  Hits.appendNew(ClawHit(j, i, Edep, MIP, PE));
121  }
122  }
123  }
124  */
125 }
126 
127 //read tube centers, impulse response, and garfield drift data filename from CLAW.xml
128 void ClawDigitizerModule::getXMLData()
129 {
130  GearDir content = GearDir("/Detector/DetectorComponent[@name=\"CLAW\"]/Content/");
131 
132  m_ScintCell = content.getInt("ScintCell");
133  m_TimeStep = content.getDouble("TimeStep");
134  m_MinTime = content.getDouble("MinTime");
135  m_MaxTime = content.getDouble("MaxTime");
136  m_PEthres = content.getDouble("PEthres");
137  m_C_keV_to_MIP = content.getDouble("C_keV_to_MIP");
138  //m_C_MIP_to_PE = content.getDouble("C_MIP_to_PE");
139 
140  B2INFO("ClawDigitizer: Aquired claw locations and gas parameters");
141 
142 }
143 
144 void ClawDigitizerModule::endRun()
145 {
146 }
147 
148 void ClawDigitizerModule::terminate()
149 {
150 }
151 
152 
Belle2::StoreArray::appendNew
T * appendNew()
Construct a new T object at the end of the array.
Definition: StoreArray.h:256
Belle2::ClawHit
ClassClawHit - digitization simulated hit for the Claw detector.
Definition: ClawHit.h:36
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
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
Belle2::claw::ClawDigitizerModule
Claw tube digitizer.
Definition: ClawDigitizerModule.h:36