Belle II Software development
TPCStudyModule.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/microtpc/modules/TPCStudyModule.h>
10#include <beast/microtpc/dataobjects/MicrotpcSimHit.h>
11#include <framework/datastore/StoreArray.h>
12#include <framework/logging/Logger.h>
13#include <framework/gearbox/GearDir.h>
14#include <framework/gearbox/Const.h>
15
16#include <iostream>
17#include <string>
18
19// ROOT
20#include <Math/Vector3D.h>
21
22int ctr = 0;
23int co_ctr[4] = {0, 0, 0, 0};
24int coe_ctr[4] = {0, 0, 0, 0};
25int h1_ctr[4] = {0, 0, 0, 0};
26int n_ctr[4] = {0, 0, 0, 0};
27int he4_ctr[4] = {0, 0, 0, 0};
28int o16_ctr[4] = {0, 0, 0, 0};
29int c12_ctr[4] = {0, 0, 0, 0};
30int ctr_ele[4] = {0, 0, 0, 0};
31int ctr_pos[4] = {0, 0, 0, 0};
32int ctr_pro[4] = {0, 0, 0, 0};
33int ctr_neu[4] = {0, 0, 0, 0};
34int ctr_good_neu[4] = {0, 0, 0, 0};
35int ctr_bad_neu[4] = {0, 0, 0, 0};
36int ctr_bak[4] = {0, 0, 0, 0};
37
38using namespace std;
39
40using namespace Belle2;
41using namespace microtpc;
42
43//-----------------------------------------------------------------
44// Register the Module
45//-----------------------------------------------------------------
46REG_MODULE(TPCStudy);
47
48//-----------------------------------------------------------------
49// Implementation
50//-----------------------------------------------------------------
51
53{
54 // Set module properties
55 setDescription("Study module for Microtpcs (BEAST)");
56
57 //Default values are set here. New values can be in MICROTPC.xml.
58 addParam("ChipRowNb", m_ChipRowNb, "Chip number of row", 226);
59 addParam("ChipColumnNb", m_ChipColumnNb, "Chip number of column", 80);
60 addParam("ChipColumnX", m_ChipColumnX, "Chip x dimension in cm / 2", 1.0);
61 addParam("ChipRowY", m_ChipRowY, "Chip y dimension in cm / 2", 0.86);
62 addParam("z_DG", m_z_DG, "Drift gap distance [cm]", 12.0);
63}
64
66{
67}
68
69//This module is a histomodule. Any histogram created here will be saved by the HistoManager module
71{
72 for (int i = 0; i < 11; i ++) {
73 h_tpc_kin[i] = new TH1F(TString::Format("tpc_kin_%d", i), "", 1000, 0., 100.);
74 h_tpc_xy[i] = new TH2F(TString::Format("tpc_xy_%d", i), "", 300, -3., 3., 300, -3., 3.);
75 }
76
77}
78
80{
81 B2INFO("TPCStudyModule: Initialize");
82
83 //read microtpc xml file
84 getXMLData();
85
86 REG_HISTOGRAM
87
88}
89
91{
92 //Here comes the actual event processing
93
95
96 int old_trkID[4] = { -1, -1, -1, -1};
97 int old_trkID_h1[4] = { -1, -1, -1, -1};
98 int old_trkID_he4[4] = { -1, -1, -1, -1};
99 int old_trkID_c12[4] = { -1, -1, -1, -1};
100 int old_trkID_o16[4] = { -1, -1, -1, -1};
101 bool aneu[4] = {false, false, false, false};
102 bool apro[4] = {false, false, false, false};
103 bool atrk[4] = {false, false, false, false};
104 bool aele[4] = {false, false, false, false};
105 bool apos[4] = {false, false, false, false};
106
107 vector <double> RecoilE;
108 vector <int> Pdg[4];
109 int NbofPart[4] = {0, 0, 0, 0};
110
111 cout << "Look at evt " << ctr << endl;
112
113 for (const auto& MicrotpcSimHit : SimHits) {
114 int detNb = MicrotpcSimHit.getdetNb();
115 int pdg = MicrotpcSimHit.gettkPDG();
116 int trkID = MicrotpcSimHit.gettkID();
117 ROOT::Math::XYZVector position = MicrotpcSimHit.gettkPos();
118 double xpos = position.X() / 100. - TPCCenter[detNb].X();
119 double ypos = position.Y() / 100. - TPCCenter[detNb].Y();
120 double zpos = position.Z() / 100. - TPCCenter[detNb].Z() + m_z_DG / 2.;
121 //if (ctr == 95 && detNb == 0 && (MicrotpcSimHit.getEnergyDep() * 1e6) > 250.0) {
122 if (ctr == 95 && detNb == 0 && MicrotpcSimHit.getEnergyDep() > 0) {
123 cout << " pdg " << pdg << " Energy deposited " << MicrotpcSimHit.getEnergyDep() << " zpos " << zpos << endl;
124 h_tpc_xy[7]->Fill(xpos, ypos);
125 if (pdg == 1000020040) h_tpc_xy[8]->Fill(xpos, ypos);
126 if (pdg == Const::proton.getPDGCode()) h_tpc_xy[9]->Fill(xpos, ypos);
127 if (pdg == Const::electron.getPDGCode()) h_tpc_xy[10]->Fill(xpos, ypos);
128 }
129 if (old_trkID[detNb] != trkID && MicrotpcSimHit.gettkKEnergy() > 0 && MicrotpcSimHit.getEnergyDep() > 0) {
130 old_trkID[detNb] = trkID;
131 Pdg[detNb].push_back(pdg);
132 NbofPart[detNb] ++;
133 }
134
135 if (pdg == 1000020040) {
136 if (old_trkID_he4[detNb] != trkID && MicrotpcSimHit.gettkKEnergy() > 0 && MicrotpcSimHit.getEnergyDep() > 0) {
137 old_trkID_he4[detNb] = trkID;
138 atrk[detNb] = true;
139 RecoilE.push_back(MicrotpcSimHit.gettkKEnergy());
141 he4_ctr[detNb] ++;
142 }
143 h_tpc_xy[0]->Fill(xpos, ypos);
144 }
145
146 if (pdg == 1000060120) {
147 if (old_trkID_c12[detNb] != trkID && MicrotpcSimHit.gettkKEnergy() > 0 && MicrotpcSimHit.getEnergyDep() > 0) {
148 old_trkID_c12[detNb] = trkID;
149 RecoilE.push_back(MicrotpcSimHit.gettkKEnergy());
150 atrk[detNb] = true;
152 c12_ctr[detNb] ++;
153 }
154 h_tpc_xy[1]->Fill(xpos, ypos);
155 }
156
157 if (pdg == 1000080160) {
158 if (old_trkID_o16[detNb] != trkID && MicrotpcSimHit.gettkKEnergy() > 0 && MicrotpcSimHit.getEnergyDep() > 0) {
159 old_trkID_o16[detNb] = trkID;
160 RecoilE.push_back(MicrotpcSimHit.gettkKEnergy());
161 atrk[detNb] = true;
163 o16_ctr[detNb] ++;
164 }
165 h_tpc_xy[2]->Fill(xpos, ypos);
166 }
167
168 if (pdg == Const::proton.getPDGCode()) {
169 if (old_trkID_h1[detNb] != trkID && MicrotpcSimHit.gettkKEnergy() > 0 && MicrotpcSimHit.getEnergyDep() > 0) {
170 old_trkID_h1[detNb] = trkID;
171 apro[detNb] = true;
173 h1_ctr[detNb] ++;
174 }
175 h_tpc_xy[3]->Fill(xpos, ypos);
176 }
177
178 if (pdg == Const::neutron.getPDGCode()) {
179 aneu[detNb] = true;
181 h_tpc_xy[4]->Fill(xpos, ypos);
182 n_ctr[detNb] ++;
183 }
184
185 if (pdg == Const::electron.getPDGCode()) {
186 aele[detNb] = true;
188 h_tpc_xy[5]->Fill(xpos, ypos);
189 }
190
191 if (pdg == -Const::electron.getPDGCode()) {
192 apos[detNb] = true;
194 h_tpc_xy[6]->Fill(xpos, ypos);
195 }
196 }
197 for (int i = 0; i < 4; i ++) {
198 if (apro[i] && atrk[i] && aneu[i]) co_ctr[i]++;
199 if (apro[i] && atrk[i] && aneu[i] && aele[i]) coe_ctr[i]++;
200 if (apro[i] && atrk[i]) {
201 for (int j = 0; j < (int) RecoilE.size(); j ++) {
202 h_tpc_kin[7]->Fill(RecoilE[j]);
203 }
204 ctr_pro[i] ++;
205 }
206 if (apro[i] && aneu[i]) ctr_bak[i] ++;
207 if (atrk[i] && aneu[i]) {
208 for (int j = 0; j < (int) RecoilE.size(); j ++) {
209 h_tpc_kin[8]->Fill(RecoilE[j]);
210 }
211 ctr_neu[i] ++;
212 if (NbofPart[i] == 1) ctr_good_neu[i] ++;
213 if (NbofPart[i] > 1) ctr_bad_neu[i] ++;
214 }
215 if (atrk[i] && aele[i]) {
216 for (int j = 0; j < (int) RecoilE.size(); j ++) {
217 h_tpc_kin[9]->Fill(RecoilE[j]);
218 }
219 ctr_ele[i] ++;
220 }
221 if (atrk[i] && apos[i]) {
222 for (int j = 0; j < (int) RecoilE.size(); j ++) {
223 h_tpc_kin[10]->Fill(RecoilE[j]);
224 }
225 ctr_pos[i] ++;
226 }
227 }
228
229 for (int i = 0; i < 4; i ++) {
230 if (NbofPart[i] > 0) {
231 cout << "det # " << i << " number of particle " << NbofPart[i] << endl;
232 for (int j = 0; j < (int) Pdg[i].size(); j ++) {
233 cout << " pdg " << Pdg[i][j] << endl;
234 }
235 }
236 }
237
238 ctr ++;
239}
240//read tube centers, impulse response, and garfield drift data filename from MICROTPC.xml
242{
243 GearDir content = GearDir("/Detector/DetectorComponent[@name=\"MICROTPC\"]/Content/");
244
245 //get the location of the tubes
246 for (const GearDir& activeParams : content.getNodes("Active")) {
247
248 TPCCenter.push_back(ROOT::Math::XYZVector(activeParams.getLength("TPCpos_x"),
249 activeParams.getLength("TPCpos_y"),
250 activeParams.getLength("TPCpos_z")));
251 nTPC++;
252 }
253
254 m_ChipColumnNb = content.getInt("ChipColumnNb");
255 m_ChipRowNb = content.getInt("ChipRowNb");
256 m_ChipColumnX = content.getDouble("ChipColumnX");
257 m_ChipRowY = content.getDouble("ChipRowY");
258 m_z_DG = content.getDouble("z_DG");
259
260 B2INFO("TpcDigitizer: Acquired tpc locations and gas parameters");
261 B2INFO(" from MICROTPC.xml. There are " << nTPC << " TPCs implemented");
262
263}
265{
266 cout << " Total nb of evts " << ctr << endl;
267 for (int i = 0; i < 4; i ++) {
268 cout << "n " << n_ctr[i] << " n-recoil-p " << co_ctr[i] << " n-recoil " << ctr_neu[i] << " p-n " << ctr_bak[i] << " p-He4 " <<
269 ctr_pro[i] << " H1 " << h1_ctr[i] << " He4 " << he4_ctr[i] << " C12 " << c12_ctr[i] << " O16 " << o16_ctr[i] << " good n-recoil " <<
270 ctr_good_neu[i] << " bad n-recoil " << ctr_bad_neu[i];
271 cout << " w/ e- " << ctr_ele[i] << " w/ e+ " << ctr_pos[i] << " n-p-recoil-e- " << coe_ctr[i] << endl;
272 }
273}
274
275
276
static const ParticleType neutron
neutron particle
Definition: Const.h:675
static const ChargedStable proton
proton particle
Definition: Const.h:663
static const ChargedStable electron
electron particle
Definition: Const.h:659
GearDir is the basic class used for accessing the parameter store.
Definition: GearDir.h:31
HistoModule.h is supposed to be used instead of Module.h for the modules with histogram definitions t...
Definition: HistoModule.h:29
ClassMicrotpcSimHit - Geant4 simulated hit for the Microtpc detector.
float getEnergyDep() const
Return the energy deposition in electrons.
int gettkID() const
Return track ID.
float gettkKEnergy() const
Return the kinetic energy of the track.
ROOT::Math::XYZVector gettkPos() const
Return the track position.
float getdetNb() const
Return the TPC number.
int gettkPDG() const
Return the PDG number of the track.
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
double m_ChipRowY
Chip row y dimension.
virtual void initialize() override
Initialize the Module.
virtual void event() override
Event processor.
int nTPC
number of detectors.
virtual void endRun() override
End-of-run action.
TPCStudyModule()
Constructor: Sets the description, the properties and the parameters of the module.
double m_ChipColumnX
Chip column x dimension.
virtual void getXMLData()
reads data from MICROTPC.xml: tube location, drift data filename, sigma of impulse response function
virtual ~TPCStudyModule()
Destructor.
int m_ChipRowNb
Chip row number.
std::vector< ROOT::Math::XYZVector > TPCCenter
TPC coordinate.
TH1F * h_tpc_kin[100]
Event counter.
TH2F * h_tpc_xy[100]
Track XY.
int m_ChipColumnNb
Chip column number.
virtual void defineHisto() override
Defines the histograms.
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition: Module.h:559
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:649
Abstract base class for different kinds of events.
STL namespace.