Belle II Software  release-08-01-10
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 <TVector3.h>
22 #include <TH1.h>
23 #include <TH2.h>
24 
25 int ctr = 0;
26 int co_ctr[4] = {0, 0, 0, 0};
27 int coe_ctr[4] = {0, 0, 0, 0};
28 int h1_ctr[4] = {0, 0, 0, 0};
29 int n_ctr[4] = {0, 0, 0, 0};
30 int he4_ctr[4] = {0, 0, 0, 0};
31 int o16_ctr[4] = {0, 0, 0, 0};
32 int c12_ctr[4] = {0, 0, 0, 0};
33 int ctr_ele[4] = {0, 0, 0, 0};
34 int ctr_pos[4] = {0, 0, 0, 0};
35 int ctr_pro[4] = {0, 0, 0, 0};
36 int ctr_neu[4] = {0, 0, 0, 0};
37 int ctr_good_neu[4] = {0, 0, 0, 0};
38 int ctr_bad_neu[4] = {0, 0, 0, 0};
39 int ctr_bak[4] = {0, 0, 0, 0};
40 
41 using namespace std;
42 
43 using namespace Belle2;
44 using namespace microtpc;
45 
46 //-----------------------------------------------------------------
47 // Register the Module
48 //-----------------------------------------------------------------
49 REG_MODULE(TPCStudy);
50 
51 //-----------------------------------------------------------------
52 // Implementation
53 //-----------------------------------------------------------------
54 
55 TPCStudyModule::TPCStudyModule() : HistoModule()
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 }
96 
98 {
99  //Here comes the actual event processing
100 
102  //StoreArray<MicrotpcHit> Hits;
103  //StoreArray<MicrotpcRecoTrack> Tracks;
104  //StoreArray<TPCG4TrackInfo> mcparts;
105  //StoreArray<SADMetaHit> sadMetaHits;
106 
107  int old_trkID[4] = { -1, -1, -1, -1};
108  int old_trkID_h1[4] = { -1, -1, -1, -1};
109  int old_trkID_he4[4] = { -1, -1, -1, -1};
110  int old_trkID_c12[4] = { -1, -1, -1, -1};
111  int old_trkID_o16[4] = { -1, -1, -1, -1};
112  bool aneu[4] = {false, false, false, false};
113  bool apro[4] = {false, false, false, false};
114  bool atrk[4] = {false, false, false, false};
115  bool aele[4] = {false, false, false, false};
116  bool apos[4] = {false, false, false, false};
117 
118  vector <double> RecoilE;
119  vector <int> Pdg[4];
120  int NbofPart[4] = {0, 0, 0, 0};
121 
122  cout << "Look at evt " << ctr << endl;
123 
124  for (const auto& MicrotpcSimHit : SimHits) {
125  int detNb = MicrotpcSimHit.getdetNb();
126  int pdg = MicrotpcSimHit.gettkPDG();
127  int trkID = MicrotpcSimHit.gettkID();
128  TVector3 position = MicrotpcSimHit.gettkPos();
129  TVector3 direction = MicrotpcSimHit.gettkMomDir();
130  double xpos = position.X() / 100. - TPCCenter[detNb].X();
131  double ypos = position.Y() / 100. - TPCCenter[detNb].Y();
132  double zpos = position.Z() / 100. - TPCCenter[detNb].Z() + m_z_DG / 2.;
133  //if (ctr == 95 && detNb == 0 && (MicrotpcSimHit.getEnergyDep() * 1e6) > 250.0) {
134  if (ctr == 95 && detNb == 0 && MicrotpcSimHit.getEnergyDep() > 0) {
135  cout << " pdg " << pdg << " Energy deposited " << MicrotpcSimHit.getEnergyDep() << " zpos " << zpos << endl;
136  h_tpc_xy[7]->Fill(xpos, ypos);
137  if (pdg == 1000020040) h_tpc_xy[8]->Fill(xpos, ypos);
138  if (pdg == Const::proton.getPDGCode()) h_tpc_xy[9]->Fill(xpos, ypos);
139  if (pdg == Const::electron.getPDGCode()) h_tpc_xy[10]->Fill(xpos, ypos);
140  }
141  if (old_trkID[detNb] != trkID && MicrotpcSimHit.gettkKEnergy() > 0 && MicrotpcSimHit.getEnergyDep() > 0) {
142  old_trkID[detNb] = trkID;
143  Pdg[detNb].push_back(pdg);
144  NbofPart[detNb] ++;
145  }
146 
147  if (pdg == 1000020040) {
148  //cout << "He4 detNb " << detNb << " trID " << trkID << endl;
149  //cout << "Direction x " << direction.X() << " y " << direction.Y() << " z " << direction.Z() << endl;
150  //cout << "Vertex x " << position.X() << " y " << position.Y() << " z " << position.Z() << endl;
151  //cout << "Kinetic energy " << MicrotpcSimHit.gettkKEnergy() << endl;
152  if (old_trkID_he4[detNb] != trkID && MicrotpcSimHit.gettkKEnergy() > 0 && MicrotpcSimHit.getEnergyDep() > 0) {
153  old_trkID_he4[detNb] = trkID;
154  //cout << "Output alpha track direction and vertex and momentum"<<endl;
155  //cout << "Direction x " << direction.X() << " y " << direction.Y() << " z " << direction.Z() << endl;
156  //cout << "Vertex x " << position.X() << " y " << position.Y() << " z " << position.Z() << endl;
157  //cout << "Kinetic energy " << MicrotpcSimHit.gettkKEnergy() << endl;
158  atrk[detNb] = true;
159  RecoilE.push_back(MicrotpcSimHit.gettkKEnergy());
161  he4_ctr[detNb] ++;
162  }
163  h_tpc_xy[0]->Fill(xpos, ypos);
164  }
165 
166  if (pdg == 1000060120) {
167  //cout << "C 12 detNb " << detNb << " trID " << trkID << endl;
168  //cout << "Direction x " << direction.X() << " y " << direction.Y() << " z " << direction.Z() << endl;
169  //cout << "Vertex x " << position.X() << " y " << position.Y() << " z " << position.Z() << endl;
170  //cout << "Kinetic energy " << MicrotpcSimHit.gettkKEnergy() << endl;
171  if (old_trkID_c12[detNb] != trkID && MicrotpcSimHit.gettkKEnergy() > 0 && MicrotpcSimHit.getEnergyDep() > 0) {
172  old_trkID_c12[detNb] = trkID;
173  //cout << "Output alpha track direction and vertex and momentum"<<endl;
174  //cout << "Direction x " << direction.X() << " y " << direction.Y() << " z " << direction.Z() << endl;
175  //cout << "Vertex x " << position.X() << " y " << position.Y() << " z " << position.Z() << endl;
176  //cout << "Kinetic energy " << MicrotpcSimHit.gettkKEnergy() << endl;
177  RecoilE.push_back(MicrotpcSimHit.gettkKEnergy());
178  atrk[detNb] = true;
180  c12_ctr[detNb] ++;
181  }
182  h_tpc_xy[1]->Fill(xpos, ypos);
183  }
184 
185  if (pdg == 1000080160) {
186  //cout << "O 16 detNb " << detNb << " trID " << trkID << endl;
187  //cout << "Direction x " << direction.X() << " y " << direction.Y() << " z " << direction.Z() << endl;
188  //cout << "Vertex x " << position.X() << " y " << position.Y() << " z " << position.Z() << endl;
189  //cout << "Kinetic energy " << MicrotpcSimHit.gettkKEnergy() << endl;
190  if (old_trkID_o16[detNb] != trkID && MicrotpcSimHit.gettkKEnergy() > 0 && MicrotpcSimHit.getEnergyDep() > 0) {
191  old_trkID_o16[detNb] = trkID;
192  //cout << "Output alpha track direction and vertex and momentum"<<endl;
193  //cout << "Direction x " << direction.X() << " y " << direction.Y() << " z " << direction.Z() << endl;
194  //cout << "Vertex x " << position.X() << " y " << position.Y() << " z " << position.Z() << endl;
195  //cout << "Kinetic energy " << MicrotpcSimHit.gettkKEnergy() << endl;
196  RecoilE.push_back(MicrotpcSimHit.gettkKEnergy());
197  atrk[detNb] = true;
199  o16_ctr[detNb] ++;
200  }
201  h_tpc_xy[2]->Fill(xpos, ypos);
202  }
203 
204  if (pdg == Const::proton.getPDGCode()) {
205  //atrk[detNb] = true;
206  //cout << "He4 detNb " << detNb << " trID " << trkID << endl;
207  //cout << "Direction x " << direction.X() << " y " << direction.Y() << " z " << direction.Z() << endl;
208  //cout << "Vertex x " << position.X() << " y " << position.Y() << " z " << position.Z() << endl;
209  //cout << "Kinetic energy " << MicrotpcSimHit.gettkKEnergy() << endl;
210  if (old_trkID_h1[detNb] != trkID && MicrotpcSimHit.gettkKEnergy() > 0 && MicrotpcSimHit.getEnergyDep() > 0) {
211  old_trkID_h1[detNb] = trkID;
212  //cout << "Output alpha track direction and vertex and momentum"<<endl;
213  //cout << "Direction x " << direction.X() << " y " << direction.Y() << " z " << direction.Z() << endl;
214  //cout << "Vertex x " << position.X() << " y " << position.Y() << " z " << position.Z() << endl;
215  //cout << "Kinetic energy " << MicrotpcSimHit.gettkKEnergy() << endl;
216  apro[detNb] = true;
218  h1_ctr[detNb] ++;
219  }
220  h_tpc_xy[3]->Fill(xpos, ypos);
221  }
222 
223  if (pdg == Const::neutron.getPDGCode()) {
224  aneu[detNb] = true;
226  h_tpc_xy[4]->Fill(xpos, ypos);
227  n_ctr[detNb] ++;
228  }
229 
230  if (pdg == Const::electron.getPDGCode()) {
231  aele[detNb] = true;
233  h_tpc_xy[5]->Fill(xpos, ypos);
234  }
235 
236  if (pdg == -Const::electron.getPDGCode()) {
237  apos[detNb] = true;
239  h_tpc_xy[6]->Fill(xpos, ypos);
240  }
241  }
242  for (int i = 0; i < 4; i ++) {
243  if (apro[i] && atrk[i] && aneu[i]) co_ctr[i]++;
244  if (apro[i] && atrk[i] && aneu[i] && aele[i]) coe_ctr[i]++;
245  if (apro[i] && atrk[i]) {
246  for (int j = 0; j < (int) RecoilE.size(); j ++) {
247  h_tpc_kin[7]->Fill(RecoilE[j]);
248  }
249  ctr_pro[i] ++;
250  }
251  if (apro[i] && aneu[i]) ctr_bak[i] ++;
252  if (atrk[i] && aneu[i]) {
253  for (int j = 0; j < (int) RecoilE.size(); j ++) {
254  h_tpc_kin[8]->Fill(RecoilE[j]);
255  }
256  ctr_neu[i] ++;
257  if (NbofPart[i] == 1) ctr_good_neu[i] ++;
258  if (NbofPart[i] > 1) ctr_bad_neu[i] ++;
259  }
260  if (atrk[i] && aele[i]) {
261  for (int j = 0; j < (int) RecoilE.size(); j ++) {
262  h_tpc_kin[9]->Fill(RecoilE[j]);
263  }
264  ctr_ele[i] ++;
265  }
266  if (atrk[i] && apos[i]) {
267  for (int j = 0; j < (int) RecoilE.size(); j ++) {
268  h_tpc_kin[10]->Fill(RecoilE[j]);
269  }
270  ctr_pos[i] ++;
271  }
272  }
273 
274  for (int i = 0; i < 4; i ++) {
275  if (NbofPart[i] > 0) {
276  cout << "det # " << i << " number of particle " << NbofPart[i] << endl;
277  for (int j = 0; j < (int) Pdg[i].size(); j ++) {
278  cout << " pdg " << Pdg[i][j] << endl;
279  }
280  }
281  }
282 
283  ctr ++;
284 }
285 //read tube centers, impulse response, and garfield drift data filename from MICROTPC.xml
287 {
288  GearDir content = GearDir("/Detector/DetectorComponent[@name=\"MICROTPC\"]/Content/");
289 
290  //get the location of the tubes
291  BOOST_FOREACH(const GearDir & activeParams, content.getNodes("Active")) {
292 
293  TPCCenter.push_back(TVector3(activeParams.getLength("TPCpos_x"), activeParams.getLength("TPCpos_y"),
294  activeParams.getLength("TPCpos_z")));
295  nTPC++;
296  }
297 
298  m_ChipColumnNb = content.getInt("ChipColumnNb");
299  m_ChipRowNb = content.getInt("ChipRowNb");
300  m_ChipColumnX = content.getDouble("ChipColumnX");
301  m_ChipRowY = content.getDouble("ChipRowY");
302  m_z_DG = content.getDouble("z_DG");
303 
304  B2INFO("TpcDigitizer: Aquired tpc locations and gas parameters");
305  B2INFO(" from MICROTPC.xml. There are " << nTPC << " TPCs implemented");
306 
307 }
309 {
310 
311  //B2RESULT("TPCStudyModule: # of p recoils: " << npHits);
312  //B2RESULT("TPCStudyModule: # of He recoils: " << nHeHits);
313  //B2RESULT("TPCStudyModule: # of O recoils: " << nOHits);
314  //B2RESULT("TPCStudyModule: # of C recoils: " << nCHits);
315  cout << " Total nb of evts " << ctr << endl;
316  for (int i = 0; i < 4; i ++) {
317  cout << "n " << n_ctr[i] << " n-recoil-p " << co_ctr[i] << " n-recoil " << ctr_neu[i] << " p-n " << ctr_bak[i] << " p-He4 " <<
318  ctr_pro[i] << " H1 " << h1_ctr[i] << " He4 " << he4_ctr[i] << " C12 " << c12_ctr[i] << " O16 " << o16_ctr[i] << " good n-recoil " <<
319  ctr_good_neu[i] << " bad n-recoil " << ctr_bad_neu[i];
320  cout << " w/ e- " << ctr_ele[i] << " w/ e+ " << ctr_pos[i] << " n-p-recoil-e- " << coe_ctr[i] << endl;
321  }
322 }
323 
325 {
326 }
327 
328 
static const ParticleType neutron
neutron particle
Definition: Const.h:666
static const ChargedStable proton
proton particle
Definition: Const.h:654
static const ChargedStable electron
electron particle
Definition: Const.h:650
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.
TVector3 gettkPos() const
Return the track position.
int gettkID() const
Return track ID.
float gettkKEnergy() const
Return the kinetic energy of the track.
float getdetNb() const
Return the TPC number.
TVector3 gettkMomDir() const
Return the track momentum direction.
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.
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.
virtual void terminate() override
Termination action.
virtual void beginRun() override
Called when entering a new run.
int m_ChipRowNb
Chip row number.
TH1F * h_tpc_kin[100]
Event counter.
int m_ChipColumnNb
Chip column number.
virtual void defineHisto() override
Defines the histograms.
std::vector< TVector3 > TPCCenter
TPC coordinate.
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.