Belle II Software  release-06-02-00
He3tubeStudyModule.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/he3tube/modules/He3tubeStudyModule.h>
10 #include <beast/he3tube/dataobjects/He3tubeSimHit.h>
11 #include <beast/he3tube/dataobjects/He3tubeHit.h>
12 #include <beast/he3tube/dataobjects/HE3G4TrackInfo.h>
13 #include <generators/SAD/dataobjects/SADMetaHit.h>
14 #include <framework/datastore/StoreArray.h>
15 #include <framework/logging/Logger.h>
16 #include <framework/gearbox/Const.h>
17 #include <cmath>
18 
19 #include <iostream>
20 #include <fstream>
21 #include <sstream>
22 #include <string>
23 
24 // ROOT
25 #include <TVector3.h>
26 #include <TH1.h>
27 #include <TH2.h>
28 #include <TMath.h>
29 
30 int eventNum = 0;
31 
32 using namespace std;
33 
34 using namespace Belle2;
35 using namespace he3tube;
36 
37 //-----------------------------------------------------------------
38 // Register the Module
39 //-----------------------------------------------------------------
40 REG_MODULE(He3tubeStudy)
41 
42 //-----------------------------------------------------------------
43 // Implementation
44 //-----------------------------------------------------------------
45 
47 {
48  // Set module properties
49  setDescription("Study module for He3tubes (BEAST)");
50 
51  // Parameter definitions
52  addParam("sampleTime", m_sampletime, "Length of sample, in us", 10000);
53 
54 }
55 
56 He3tubeStudyModule::~He3tubeStudyModule()
57 {
58 }
59 
60 //This module is a histomodule. Any histogram created here will be saved by the HistoManager module
61 void He3tubeStudyModule::defineHisto()
62 {
63  for (int i = 0 ; i < 9 ; i++) {
64  h_mche3_kinetic[i] = new TH1F(TString::Format("h_mche3_kinetic_%d", i), "MC kin. energy [GeV]", 1000, 0., 10.);
65  h_mche3_kinetic_zoom[i] = new TH1F(TString::Format("h_mche3_kinetic_zoom_%d", i), "MC kin. energy [MeV]", 1000, 0., 10.);
66  h_mche3_tvp[i] = new TH2F(TString::Format("h_mche3_tvp_%d", i), "theta v phi", 180, 0., 180., 360, -180., 180.);
67  h_mche3_tvpW[i] = new TH2F(TString::Format("h_mche3_tvpW_%d", i), "theta v phi weighted by kin", 180, 0., 180., 360, -180., 180.);
68  h_mche3_zr[i] = new TH2F(TString::Format("h_mche3_zr_%d", i), "r v z", 200, -400., 400., 200, 0., 400.);
69  h_mche3_kinetic[i]->Sumw2();
70  h_mche3_kinetic_zoom[i]->Sumw2();
71  h_mche3_tvp[i]->Sumw2();
72  h_mche3_tvpW[i]->Sumw2();
73  h_mche3_zr[i]->Sumw2();
74  }
75 
76  h_NeutronHits = new TH1F("NeutronHits", "Neutron Hits;Tube ", 4, -0.5, 3.5);
77  h_NeutronHitsWeighted = new TH1F("NeutronHitsWeighted", "Neutron Hits;Tube ", 4, -0.5, 3.5);
78  h_DefNeutronHits = new TH1F("DefNeutronHits", "Definite Neutron Hits;Tube ", 4, -0.5, 3.5);
79  h_DefNeutronHitsWeighted = new TH1F("DefNeutronHitsWeighted", "Definite Neutron Hits;Tube ", 4, -0.5, 3.5);
80  h_NeutronRate = new TH1F("NeutronRate", "Neutron Hits per second;Tube; Rate (Hz)", 4, -0.5, 3.5);
81  h_DefNeutronRate = new TH1F("DefNeutronRate", "Neutron Hits per second;Tube; Rate (Hz)", 4, -0.5, 3.5);
82 
83  h_NeutronHitsVrs = new TH2F("NeutronHitsVrs", "Neutron Hits;Tube ", 4, -0.5, 3.5, 12, 0., 12.);
84  h_NeutronHitsWeightedVrs = new TH2F("NeutronHitsWeightedVrs", "Neutron Hits;Tube ", 4, -0.5, 3.5, 12, 0., 12.);
85  h_DefNeutronHitsVrs = new TH2F("DefNeutronHitsVrs", "Definite Neutron Hits;Tube ", 4, -0.5, 3.5, 12, 0., 12.);
86  h_DefNeutronHitsWeightedVrs = new TH2F("DefNeutronHitsWeightedVrs", "Definite Neutron Hits;Tube ", 4, -0.5, 3.5, 12, 0., 12.);
87  h_NeutronRateVrs = new TH2F("NeutronRateVrs", "Neutron Hits per second;Tube; Rate (Hz)", 4, -0.5, 3.5, 12, 0., 12.);
88  h_DefNeutronRateVrs = new TH2F("DefNeutronRateVrs", "Neutron Hits per second;Tube; Rate (Hz)", 4, -0.5, 3.5, 12, 0., 12.);
89 
90  h_Edep1H3H = new TH1F("Edep1H3H" , "Energy deposited by Proton and Tritium; MeV", 100, 0.7, 0.8);
91  h_Edep1H3H_detNB = new TH1F("Edep1H3H_tube", "Energy deposited by Proton and Tritium in each tube;Tube Num; MeV", 4, -0.5, 3.5);
92  h_Edep1H = new TH1F("Edep1H" , "Energy deposited by Protons;MeV", 100, 0, 0.7);
93  h_Edep3H = new TH1F("Edep3H" , "Energy deposited by Tritiums;MeV", 100, 0, 0.4);
94  h_TotEdep = new TH1F("TotEdep" , "Total energy deposited;MeV", 100, 0, 1.5);
95  h_DetN_Edep = new TH1F("DetN_Edep" , "Energy deposited vs detector number;Tube Num;MeV", 4, -0.5, 3.5);
96 
97  h_PulseHeights_NotNeutron = new TH1F("PulseHeights_NotNeutron", "Pulse height of waveforms from non-neutron events", 100, 0, 18000);
98  h_PulseHeights_Neutron = new TH1F("PulseHeights_Neutron" , "Pulse height of waveforms from neutron events", 100, 0, 18000);
99  h_PulseHeights_DefNeutron = new TH1F("PulseHeights_DefNeutron" , "Pulse height of waveforms from definite neutron events", 100,
100  0, 18000);
101  h_PulseHeights_All = new TH1F("PulseHeights_All" , "Pulse height of waveforms from all events", 100, 0, 18000);
102 
103  h_DefNeutronHits->Sumw2();
104  h_DefNeutronRate->Sumw2();
105  h_DefNeutronHitsWeighted->Sumw2();
106  h_NeutronHits->Sumw2();
107  h_NeutronRate->Sumw2();
108  h_NeutronHitsWeighted->Sumw2();
109 
110  h_DefNeutronHitsVrs->Sumw2();
111  h_DefNeutronRateVrs->Sumw2();
112  h_DefNeutronHitsWeightedVrs->Sumw2();
113  h_NeutronHitsVrs->Sumw2();
114  h_NeutronRateVrs->Sumw2();
115  h_NeutronHitsWeightedVrs->Sumw2();
116 
117 }
118 
119 
120 void He3tubeStudyModule::initialize()
121 {
122  B2INFO("He3tubeStudyModule: Initialize");
123 
124  REG_HISTOGRAM
125 
126  //convert sample time into rate in Hz
127  rateCorrection = m_sampletime / 1e6;
128 }
129 
130 void He3tubeStudyModule::beginRun()
131 {
132 }
133 
134 void He3tubeStudyModule::event()
135 {
136  //Here comes the actual event processing
137 
141  StoreArray<SADMetaHit> MetaHits;
142 
143  //Look at the meta data to extract IR rate and scattering ring section
144  double rate = 0;
145  int ring_section = -1;
146  for (const auto& MetaHit : MetaHits) {
147  rate = MetaHit.getrate();
148  ring_section = MetaHit.getring_section() - 1;
149  }
150 
151  for (const auto& mcpart : mcparts) { // start loop over all Tracks
152  const double energy = mcpart.getEnergy();
153  const double mass = mcpart.getMass();
154  double kin = energy - mass;
155  const double PDG = mcpart.getPDG();
156  const TVector3 vtx = mcpart.getProductionVertex();
157  const TVector3 mom = mcpart.getMomentum();
158  double theta = mom.Theta() * TMath::RadToDeg();
159  double phi = mom.Phi() * TMath::RadToDeg();
160  double z = vtx.Z();
161  double r = sqrt(vtx.X() * vtx.X() + vtx.Y() * vtx.Y()); int partID[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
162 
163  if (PDG == Const::electron.getPDGCode()) partID[0] = 1; //positron
164  else if (PDG == -Const::electron.getPDGCode()) partID[1] = 1; //electron
165  else if (PDG == Const::photon.getPDGCode()) partID[2] = 1; //photon
166  else if (PDG == Const::neutron.getPDGCode()) partID[3] = 1; //neutron
167  else if (PDG == Const::proton.getPDGCode()) partID[4] = 1; //proton
168  else if (PDG == 1000080160) partID[5] = 1; // O
169  else if (PDG == 1000060120) partID[6] = 1; // C
170  else if (PDG == 1000020040) partID[7] = 1; // He
171  else partID[8] = 1;
172  for (int i = 0; i < 9; i++) {
173  if (partID[i] == 1) {
174  h_mche3_kinetic[i]->Fill(kin);
175  h_mche3_kinetic_zoom[i]->Fill(kin * 1e3);
176  h_mche3_tvp[i]->Fill(theta, phi);
177  h_mche3_tvpW[i]->Fill(theta, phi, kin);
178  h_mche3_zr[i]->Fill(z, r);
179  }
180  }
181  }
182 
183  //initalize various counters
184  double edepSum = 0;
185  double edepSum_1H = 0;
186  double edepSum_3H = 0;
187  double totedepSum = 0;
188  double totedepDet[4] = {0};
189 
190  bool ContainsP[4] = {false};
191  bool Contains3H[4] = {false};
192 
193  for (int i = 0; i < simHits.getEntries(); i++) {
194  He3tubeSimHit* aHit = simHits[i];
195  double edep = aHit->getEnergyDep();
196  int detNB = aHit->getdetNb();
197  int PID = aHit->gettkPDG();
198 
199  if (detNB > 3) {
200  B2WARNING("Hit registered in undefined tube, ignoring");
201  continue;
202 
203  }
204 
205 
206  h_DetN_Edep->AddBinContent(detNB + 1, edep);
207  totedepSum = totedepSum + edep;
208  totedepDet[detNB] = totedepDet[detNB] + edep;
209 
210  //energy deposited by protons
211  if (PID == 2212) {
212  ContainsP[detNB] = true;
213  //nPhits++;
214  h_Edep1H3H_detNB->AddBinContent(detNB + 1, edep);
215  edepSum_1H = edepSum_1H + edep;
216  edepSum = edepSum + edep;
217 
218  }
219  //energy deposited by tritiums
220  if (PID == 1000010030) {
221  Contains3H[detNB] = true;
222  //n3Hhits++;
223  h_Edep1H3H_detNB->AddBinContent(detNB + 1, edep);
224  edepSum_3H = edepSum_3H + edep;
225  edepSum = edepSum + edep;
226  }
227 
228 
229  }
230 
231  if (totedepSum != 0) h_TotEdep->Fill(totedepSum);
232  if (edepSum != 0) h_Edep1H3H->Fill(edepSum);
233  if (edepSum_1H != 0) h_Edep1H->Fill(edepSum_1H);
234  if (edepSum_3H != 0) h_Edep3H->Fill(edepSum_3H);
235 
236 
237  int neutronStatus = 0;
238  int tubeNum = -1;
239 
240  //pulse heights of digitized waveforms
241  for (int i = 0; i < Hits.getEntries(); i++) {
242  He3tubeHit* aHit = Hits[i];
243  if (aHit->definiteNeutron()) { //if this is true, this hit was definitely caused by a neutron.
244  nDefiniteNeutron++;
245  h_DefNeutronHits->Fill(aHit->getdetNb());
246  h_DefNeutronHitsWeighted->Fill(aHit->getdetNb(), rate);
247  h_DefNeutronRate->Fill(aHit->getdetNb(), 1 / rateCorrection);
248  h_DefNeutronHitsVrs->Fill(aHit->getdetNb(), ring_section);
249  h_DefNeutronHitsWeightedVrs->Fill(aHit->getdetNb(), ring_section, rate);
250  h_DefNeutronRateVrs->Fill(aHit->getdetNb(), ring_section, 1 / rateCorrection);
251  h_PulseHeights_DefNeutron->Fill(aHit->getPeakV());
252  neutronStatus = 1;
253  tubeNum = aHit->getdetNb();
254  }
255 
256  if (ContainsP[aHit->getdetNb()] && Contains3H[aHit->getdetNb()]) {
257  if (neutronStatus == 0) neutronStatus = 2;
258  tubeNum = aHit->getdetNb();
259  h_PulseHeights_Neutron->Fill(aHit->getPeakV());
260  h_NeutronHits->Fill(aHit->getdetNb());
261  h_NeutronRate->Fill(aHit->getdetNb(), 1 / rateCorrection);
262  h_NeutronHitsWeighted->Fill(aHit->getdetNb(), rate);
263  h_NeutronHitsVrs->Fill(aHit->getdetNb(), ring_section);
264  h_NeutronRateVrs->Fill(aHit->getdetNb(), ring_section, 1 / rateCorrection);
265  h_NeutronHitsWeightedVrs->Fill(aHit->getdetNb(), ring_section, rate);
266  nNeutronHits++;
267  } else {
268  h_PulseHeights_NotNeutron->Fill(aHit->getPeakV());
269  }
270  h_PulseHeights_All->Fill(aHit->getPeakV());
271 
272  }
273 
274  if (neutronStatus == 1) B2DEBUG(80, "He3tubeStudyModule: Definite Neutron in tube #" << tubeNum);
275  else if (neutronStatus == 2) B2DEBUG(80, "He3tubeStudyModule: Possible Neutron in tube #" << tubeNum);
276 
277  for (int i = 0; i < 4; i++) {
278  if (ContainsP[i]) nPhits++;
279  if (Contains3H[i]) n3Hhits++;
280  }
281 
282  eventNum++;
283 
284 
285 
286 }
287 
288 void He3tubeStudyModule::endRun()
289 {
290 
291  B2RESULT("He3tubeStudyModule: # of neutrons: " << nNeutronHits);
292  B2RESULT(" # of definite neutrons " << nDefiniteNeutron);
293  B2RESULT(" # of 3H hits: " << n3Hhits);
294  B2RESULT(" # of H hits: " << nPhits);
295 
296 
297 
298 }
299 
300 void He3tubeStudyModule::terminate()
301 {
302 }
303 
304 
ClassHe3Hit - digitization simulated hit for the He3tube detector.
Definition: He3tubeHit.h:26
bool definiteNeutron() const
true if this is definitely a neutron event
Definition: He3tubeHit.h:60
double getPeakV() const
Return peak.
Definition: He3tubeHit.h:56
int getdetNb() const
Return the tube number.
Definition: He3tubeHit.h:54
ClassHe3tubeSimHit - Geant4 simulated hit for the He3tube detector.
Definition: He3tubeSimHit.h:30
float getEnergyDep() const
Return the energy deposition in electrons.
Definition: He3tubeSimHit.h:63
float getdetNb() const
Return the He3tube number.
Definition: He3tubeSimHit.h:71
int gettkPDG() const
Return the PDG number of the track.
Definition: He3tubeSimHit.h:67
HistoModule.h is supposed to be used instead of Module.h for the modules with histogram definitions t...
Definition: HistoModule.h:29
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
int getEntries() const
Get the number of objects in the array.
Definition: StoreArray.h:216
Study module for He3tubes (BEAST)
#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.