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