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#include <boost/foreach.hpp>
16
17#include <iostream>
18#include <string>
19
20// ROOT
21#include <Math/Vector3D.h>
22#include <TH1.h>
23#include <TH2.h>
24
25int ctr = 0;
26int co_ctr[4] = {0, 0, 0, 0};
27int coe_ctr[4] = {0, 0, 0, 0};
28int h1_ctr[4] = {0, 0, 0, 0};
29int n_ctr[4] = {0, 0, 0, 0};
30int he4_ctr[4] = {0, 0, 0, 0};
31int o16_ctr[4] = {0, 0, 0, 0};
32int c12_ctr[4] = {0, 0, 0, 0};
33int ctr_ele[4] = {0, 0, 0, 0};
34int ctr_pos[4] = {0, 0, 0, 0};
35int ctr_pro[4] = {0, 0, 0, 0};
36int ctr_neu[4] = {0, 0, 0, 0};
37int ctr_good_neu[4] = {0, 0, 0, 0};
38int ctr_bad_neu[4] = {0, 0, 0, 0};
39int ctr_bak[4] = {0, 0, 0, 0};
40
41using namespace std;
42
43using namespace Belle2;
44using namespace microtpc;
45
46//-----------------------------------------------------------------
47// Register the Module
48//-----------------------------------------------------------------
49REG_MODULE(TPCStudy);
50
51//-----------------------------------------------------------------
52// Implementation
53//-----------------------------------------------------------------
54
56{
57 // Set module properties
58 setDescription("Study module for Microtpcs (BEAST)");
59
60 //Default values are set here. New values can be in MICROTPC.xml.
61 addParam("ChipRowNb", m_ChipRowNb, "Chip number of row", 226);
62 addParam("ChipColumnNb", m_ChipColumnNb, "Chip number of column", 80);
63 addParam("ChipColumnX", m_ChipColumnX, "Chip x dimension in cm / 2", 1.0);
64 addParam("ChipRowY", m_ChipRowY, "Chip y dimension in cm / 2", 0.86);
65 addParam("z_DG", m_z_DG, "Drift gap distance [cm]", 12.0);
66}
67
69{
70}
71
72//This module is a histomodule. Any histogram created here will be saved by the HistoManager module
74{
75 for (int i = 0; i < 11; i ++) {
76 h_tpc_kin[i] = new TH1F(TString::Format("tpc_kin_%d", i), "", 1000, 0., 100.);
77 h_tpc_xy[i] = new TH2F(TString::Format("tpc_xy_%d", i), "", 300, -3., 3., 300, -3., 3.);
78 }
79
80}
81
83{
84 B2INFO("TPCStudyModule: Initialize");
85
86 //read microtpc xml file
87 getXMLData();
88
89 REG_HISTOGRAM
90
91}
92
94{
95 //Here comes the actual event processing
96
98
99 int old_trkID[4] = { -1, -1, -1, -1};
100 int old_trkID_h1[4] = { -1, -1, -1, -1};
101 int old_trkID_he4[4] = { -1, -1, -1, -1};
102 int old_trkID_c12[4] = { -1, -1, -1, -1};
103 int old_trkID_o16[4] = { -1, -1, -1, -1};
104 bool aneu[4] = {false, false, false, false};
105 bool apro[4] = {false, false, false, false};
106 bool atrk[4] = {false, false, false, false};
107 bool aele[4] = {false, false, false, false};
108 bool apos[4] = {false, false, false, false};
109
110 vector <double> RecoilE;
111 vector <int> Pdg[4];
112 int NbofPart[4] = {0, 0, 0, 0};
113
114 cout << "Look at evt " << ctr << endl;
115
116 for (const auto& MicrotpcSimHit : SimHits) {
117 int detNb = MicrotpcSimHit.getdetNb();
118 int pdg = MicrotpcSimHit.gettkPDG();
119 int trkID = MicrotpcSimHit.gettkID();
120 ROOT::Math::XYZVector position = MicrotpcSimHit.gettkPos();
121 double xpos = position.X() / 100. - TPCCenter[detNb].X();
122 double ypos = position.Y() / 100. - TPCCenter[detNb].Y();
123 double zpos = position.Z() / 100. - TPCCenter[detNb].Z() + m_z_DG / 2.;
124 //if (ctr == 95 && detNb == 0 && (MicrotpcSimHit.getEnergyDep() * 1e6) > 250.0) {
125 if (ctr == 95 && detNb == 0 && MicrotpcSimHit.getEnergyDep() > 0) {
126 cout << " pdg " << pdg << " Energy deposited " << MicrotpcSimHit.getEnergyDep() << " zpos " << zpos << endl;
127 h_tpc_xy[7]->Fill(xpos, ypos);
128 if (pdg == 1000020040) h_tpc_xy[8]->Fill(xpos, ypos);
129 if (pdg == Const::proton.getPDGCode()) h_tpc_xy[9]->Fill(xpos, ypos);
130 if (pdg == Const::electron.getPDGCode()) h_tpc_xy[10]->Fill(xpos, ypos);
131 }
132 if (old_trkID[detNb] != trkID && MicrotpcSimHit.gettkKEnergy() > 0 && MicrotpcSimHit.getEnergyDep() > 0) {
133 old_trkID[detNb] = trkID;
134 Pdg[detNb].push_back(pdg);
135 NbofPart[detNb] ++;
136 }
137
138 if (pdg == 1000020040) {
139 if (old_trkID_he4[detNb] != trkID && MicrotpcSimHit.gettkKEnergy() > 0 && MicrotpcSimHit.getEnergyDep() > 0) {
140 old_trkID_he4[detNb] = trkID;
141 atrk[detNb] = true;
142 RecoilE.push_back(MicrotpcSimHit.gettkKEnergy());
144 he4_ctr[detNb] ++;
145 }
146 h_tpc_xy[0]->Fill(xpos, ypos);
147 }
148
149 if (pdg == 1000060120) {
150 if (old_trkID_c12[detNb] != trkID && MicrotpcSimHit.gettkKEnergy() > 0 && MicrotpcSimHit.getEnergyDep() > 0) {
151 old_trkID_c12[detNb] = trkID;
152 RecoilE.push_back(MicrotpcSimHit.gettkKEnergy());
153 atrk[detNb] = true;
155 c12_ctr[detNb] ++;
156 }
157 h_tpc_xy[1]->Fill(xpos, ypos);
158 }
159
160 if (pdg == 1000080160) {
161 if (old_trkID_o16[detNb] != trkID && MicrotpcSimHit.gettkKEnergy() > 0 && MicrotpcSimHit.getEnergyDep() > 0) {
162 old_trkID_o16[detNb] = trkID;
163 RecoilE.push_back(MicrotpcSimHit.gettkKEnergy());
164 atrk[detNb] = true;
166 o16_ctr[detNb] ++;
167 }
168 h_tpc_xy[2]->Fill(xpos, ypos);
169 }
170
171 if (pdg == Const::proton.getPDGCode()) {
172 if (old_trkID_h1[detNb] != trkID && MicrotpcSimHit.gettkKEnergy() > 0 && MicrotpcSimHit.getEnergyDep() > 0) {
173 old_trkID_h1[detNb] = trkID;
174 apro[detNb] = true;
176 h1_ctr[detNb] ++;
177 }
178 h_tpc_xy[3]->Fill(xpos, ypos);
179 }
180
181 if (pdg == Const::neutron.getPDGCode()) {
182 aneu[detNb] = true;
184 h_tpc_xy[4]->Fill(xpos, ypos);
185 n_ctr[detNb] ++;
186 }
187
188 if (pdg == Const::electron.getPDGCode()) {
189 aele[detNb] = true;
191 h_tpc_xy[5]->Fill(xpos, ypos);
192 }
193
194 if (pdg == -Const::electron.getPDGCode()) {
195 apos[detNb] = true;
197 h_tpc_xy[6]->Fill(xpos, ypos);
198 }
199 }
200 for (int i = 0; i < 4; i ++) {
201 if (apro[i] && atrk[i] && aneu[i]) co_ctr[i]++;
202 if (apro[i] && atrk[i] && aneu[i] && aele[i]) coe_ctr[i]++;
203 if (apro[i] && atrk[i]) {
204 for (int j = 0; j < (int) RecoilE.size(); j ++) {
205 h_tpc_kin[7]->Fill(RecoilE[j]);
206 }
207 ctr_pro[i] ++;
208 }
209 if (apro[i] && aneu[i]) ctr_bak[i] ++;
210 if (atrk[i] && aneu[i]) {
211 for (int j = 0; j < (int) RecoilE.size(); j ++) {
212 h_tpc_kin[8]->Fill(RecoilE[j]);
213 }
214 ctr_neu[i] ++;
215 if (NbofPart[i] == 1) ctr_good_neu[i] ++;
216 if (NbofPart[i] > 1) ctr_bad_neu[i] ++;
217 }
218 if (atrk[i] && aele[i]) {
219 for (int j = 0; j < (int) RecoilE.size(); j ++) {
220 h_tpc_kin[9]->Fill(RecoilE[j]);
221 }
222 ctr_ele[i] ++;
223 }
224 if (atrk[i] && apos[i]) {
225 for (int j = 0; j < (int) RecoilE.size(); j ++) {
226 h_tpc_kin[10]->Fill(RecoilE[j]);
227 }
228 ctr_pos[i] ++;
229 }
230 }
231
232 for (int i = 0; i < 4; i ++) {
233 if (NbofPart[i] > 0) {
234 cout << "det # " << i << " number of particle " << NbofPart[i] << endl;
235 for (int j = 0; j < (int) Pdg[i].size(); j ++) {
236 cout << " pdg " << Pdg[i][j] << endl;
237 }
238 }
239 }
240
241 ctr ++;
242}
243//read tube centers, impulse response, and garfield drift data filename from MICROTPC.xml
245{
246 GearDir content = GearDir("/Detector/DetectorComponent[@name=\"MICROTPC\"]/Content/");
247
248 //get the location of the tubes
249 BOOST_FOREACH(const GearDir & activeParams, content.getNodes("Active")) {
250
251 TPCCenter.push_back(ROOT::Math::XYZVector(activeParams.getLength("TPCpos_x"),
252 activeParams.getLength("TPCpos_y"),
253 activeParams.getLength("TPCpos_z")));
254 nTPC++;
255 }
256
257 m_ChipColumnNb = content.getInt("ChipColumnNb");
258 m_ChipRowNb = content.getInt("ChipRowNb");
259 m_ChipColumnX = content.getDouble("ChipColumnX");
260 m_ChipRowY = content.getDouble("ChipRowY");
261 m_z_DG = content.getDouble("z_DG");
262
263 B2INFO("TpcDigitizer: Aquired tpc locations and gas parameters");
264 B2INFO(" from MICROTPC.xml. There are " << nTPC << " TPCs implemented");
265
266}
268{
269 cout << " Total nb of evts " << ctr << endl;
270 for (int i = 0; i < 4; i ++) {
271 cout << "n " << n_ctr[i] << " n-recoil-p " << co_ctr[i] << " n-recoil " << ctr_neu[i] << " p-n " << ctr_bak[i] << " p-He4 " <<
272 ctr_pro[i] << " H1 " << h1_ctr[i] << " He4 " << he4_ctr[i] << " C12 " << c12_ctr[i] << " O16 " << o16_ctr[i] << " good n-recoil " <<
273 ctr_good_neu[i] << " bad n-recoil " << ctr_bad_neu[i];
274 cout << " w/ e- " << ctr_ele[i] << " w/ e+ " << ctr_pos[i] << " n-p-recoil-e- " << coe_ctr[i] << endl;
275 }
276}
277
278
279
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 getLength(const std::string &path="") const noexcept(false)
Get the parameter path as a double converted to the standard length unit.
Definition: Interface.h:259
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:560
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
Abstract base class for different kinds of events.
STL namespace.