Belle II Software development
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 <Math/Vector3D.h>
26#include <TH1.h>
27#include <TH2.h>
28#include <TMath.h>
29
30int eventNum = 0;
31
32using namespace std;
33
34using namespace Belle2;
35using namespace he3tube;
36
37//-----------------------------------------------------------------
38// Register the Module
39//-----------------------------------------------------------------
40REG_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 //convert sample time into rate in Hz
56}
57
59{
60}
61
62//This module is a histomodule. Any histogram created here will be saved by the HistoManager module
64{
65 for (int i = 0 ; i < 9 ; i++) {
66 h_mche3_kinetic[i] = new TH1F(TString::Format("h_mche3_kinetic_%d", i), "MC kin. energy [GeV]", 1000, 0., 10.);
67 h_mche3_kinetic_zoom[i] = new TH1F(TString::Format("h_mche3_kinetic_zoom_%d", i), "MC kin. energy [MeV]", 1000, 0., 10.);
68 h_mche3_tvp[i] = new TH2F(TString::Format("h_mche3_tvp_%d", i), "theta v phi", 180, 0., 180., 360, -180., 180.);
69 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.);
70 h_mche3_zr[i] = new TH2F(TString::Format("h_mche3_zr_%d", i), "r v z", 200, -400., 400., 200, 0., 400.);
71 h_mche3_kinetic[i]->Sumw2();
72 h_mche3_kinetic_zoom[i]->Sumw2();
73 h_mche3_tvp[i]->Sumw2();
74 h_mche3_tvpW[i]->Sumw2();
75 h_mche3_zr[i]->Sumw2();
76 }
77
78 h_NeutronHits = new TH1F("NeutronHits", "Neutron Hits;Tube ", 4, -0.5, 3.5);
79 h_NeutronHitsWeighted = new TH1F("NeutronHitsWeighted", "Neutron Hits;Tube ", 4, -0.5, 3.5);
80 h_DefNeutronHits = new TH1F("DefNeutronHits", "Definite Neutron Hits;Tube ", 4, -0.5, 3.5);
81 h_DefNeutronHitsWeighted = new TH1F("DefNeutronHitsWeighted", "Definite Neutron Hits;Tube ", 4, -0.5, 3.5);
82 h_NeutronRate = new TH1F("NeutronRate", "Neutron Hits per second;Tube; Rate (Hz)", 4, -0.5, 3.5);
83 h_DefNeutronRate = new TH1F("DefNeutronRate", "Neutron Hits per second;Tube; Rate (Hz)", 4, -0.5, 3.5);
84
85 h_NeutronHitsVrs = new TH2F("NeutronHitsVrs", "Neutron Hits;Tube ", 4, -0.5, 3.5, 12, 0., 12.);
86 h_NeutronHitsWeightedVrs = new TH2F("NeutronHitsWeightedVrs", "Neutron Hits;Tube ", 4, -0.5, 3.5, 12, 0., 12.);
87 h_DefNeutronHitsVrs = new TH2F("DefNeutronHitsVrs", "Definite Neutron Hits;Tube ", 4, -0.5, 3.5, 12, 0., 12.);
88 h_DefNeutronHitsWeightedVrs = new TH2F("DefNeutronHitsWeightedVrs", "Definite Neutron Hits;Tube ", 4, -0.5, 3.5, 12, 0., 12.);
89 h_NeutronRateVrs = new TH2F("NeutronRateVrs", "Neutron Hits per second;Tube; Rate (Hz)", 4, -0.5, 3.5, 12, 0., 12.);
90 h_DefNeutronRateVrs = new TH2F("DefNeutronRateVrs", "Neutron Hits per second;Tube; Rate (Hz)", 4, -0.5, 3.5, 12, 0., 12.);
91
92 h_Edep1H3H = new TH1F("Edep1H3H", "Energy deposited by Proton and Tritium; MeV", 100, 0.7, 0.8);
93 h_Edep1H3H_detNB = new TH1F("Edep1H3H_tube", "Energy deposited by Proton and Tritium in each tube;Tube Num; MeV", 4, -0.5, 3.5);
94 h_Edep1H = new TH1F("Edep1H", "Energy deposited by Protons;MeV", 100, 0, 0.7);
95 h_Edep3H = new TH1F("Edep3H", "Energy deposited by Tritiums;MeV", 100, 0, 0.4);
96 h_TotEdep = new TH1F("TotEdep", "Total energy deposited;MeV", 100, 0, 1.5);
97 h_DetN_Edep = new TH1F("DetN_Edep", "Energy deposited vs detector number;Tube Num;MeV", 4, -0.5, 3.5);
98
99 h_PulseHeights_NotNeutron = new TH1F("PulseHeights_NotNeutron", "Pulse height of waveforms from non-neutron events", 100, 0, 18000);
100 h_PulseHeights_Neutron = new TH1F("PulseHeights_Neutron", "Pulse height of waveforms from neutron events", 100, 0, 18000);
101 h_PulseHeights_DefNeutron = new TH1F("PulseHeights_DefNeutron", "Pulse height of waveforms from definite neutron events", 100,
102 0, 18000);
103 h_PulseHeights_All = new TH1F("PulseHeights_All", "Pulse height of waveforms from all events", 100, 0, 18000);
104
105 h_DefNeutronHits->Sumw2();
106 h_DefNeutronRate->Sumw2();
108 h_NeutronHits->Sumw2();
109 h_NeutronRate->Sumw2();
110 h_NeutronHitsWeighted->Sumw2();
111
112 h_DefNeutronHitsVrs->Sumw2();
113 h_DefNeutronRateVrs->Sumw2();
115 h_NeutronHitsVrs->Sumw2();
116 h_NeutronRateVrs->Sumw2();
118
119}
120
121
123{
124 B2INFO("He3tubeStudyModule: Initialize");
125
126 REG_HISTOGRAM
127}
128
130{
131}
132
134{
135 //Here comes the actual event processing
136
140 StoreArray<SADMetaHit> MetaHits;
141
142 //Look at the meta data to extract IR rate and scattering ring section
143 double rate = 0;
144 int ring_section = -1;
145 for (const auto& MetaHit : MetaHits) {
146 rate = MetaHit.getrate();
147 ring_section = MetaHit.getring_section() - 1;
148 }
149
150 for (const auto& mcpart : mcparts) { // start loop over all Tracks
151 const double energy = mcpart.getEnergy();
152 const double mass = mcpart.getMass();
153 double kin = energy - mass;
154 const double PDG = mcpart.getPDG();
155 const ROOT::Math::XYZVector vtx = mcpart.getProductionVertex();
156 const ROOT::Math::XYZVector mom = mcpart.getMomentum();
157 double theta = mom.Theta() * TMath::RadToDeg();
158 double phi = mom.Phi() * TMath::RadToDeg();
159 double z = vtx.Z();
160 double r = sqrt(vtx.X() * vtx.X() + vtx.Y() * vtx.Y()); int partID[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
161
162 if (PDG == Const::electron.getPDGCode()) partID[0] = 1; //positron
163 else if (PDG == -Const::electron.getPDGCode()) partID[1] = 1; //electron
164 else if (PDG == Const::photon.getPDGCode()) partID[2] = 1; //photon
165 else if (PDG == Const::neutron.getPDGCode()) partID[3] = 1; //neutron
166 else if (PDG == Const::proton.getPDGCode()) partID[4] = 1; //proton
167 else if (PDG == 1000080160) partID[5] = 1; // O
168 else if (PDG == 1000060120) partID[6] = 1; // C
169 else if (PDG == 1000020040) partID[7] = 1; // He
170 else partID[8] = 1;
171 for (int i = 0; i < 9; i++) {
172 if (partID[i] == 1) {
173 h_mche3_kinetic[i]->Fill(kin);
174 h_mche3_kinetic_zoom[i]->Fill(kin * 1e3);
175 h_mche3_tvp[i]->Fill(theta, phi);
176 h_mche3_tvpW[i]->Fill(theta, phi, kin);
177 h_mche3_zr[i]->Fill(z, r);
178 }
179 }
180 }
181
182 //initalize various counters
183 double edepSum = 0;
184 double edepSum_1H = 0;
185 double edepSum_3H = 0;
186 double totedepSum = 0;
187 double totedepDet[4] = {0};
188
189 bool ContainsP[4] = {false};
190 bool Contains3H[4] = {false};
191
192 for (int i = 0; i < simHits.getEntries(); i++) {
193 He3tubeSimHit* aHit = simHits[i];
194 double edep = aHit->getEnergyDep();
195 int detNB = aHit->getdetNb();
196 int PID = aHit->gettkPDG();
197
198 if (detNB > 3) {
199 B2WARNING("Hit registered in undefined tube, ignoring");
200 continue;
201
202 }
203
204
205 h_DetN_Edep->AddBinContent(detNB + 1, edep);
206 totedepSum = totedepSum + edep;
207 totedepDet[detNB] = totedepDet[detNB] + edep;
208
209 //energy deposited by protons
210 if (PID == 2212) {
211 ContainsP[detNB] = true;
212 //nPhits++;
213 h_Edep1H3H_detNB->AddBinContent(detNB + 1, edep);
214 edepSum_1H = edepSum_1H + edep;
215 edepSum = edepSum + edep;
216
217 }
218 //energy deposited by tritiums
219 if (PID == 1000010030) {
220 Contains3H[detNB] = true;
221 //n3Hhits++;
222 h_Edep1H3H_detNB->AddBinContent(detNB + 1, edep);
223 edepSum_3H = edepSum_3H + edep;
224 edepSum = edepSum + edep;
225 }
226
227
228 }
229
230 if (totedepSum != 0) h_TotEdep->Fill(totedepSum);
231 if (edepSum != 0) h_Edep1H3H->Fill(edepSum);
232 if (edepSum_1H != 0) h_Edep1H->Fill(edepSum_1H);
233 if (edepSum_3H != 0) h_Edep3H->Fill(edepSum_3H);
234
235
236 int neutronStatus = 0;
237 int tubeNum = -1;
238
239 //pulse heights of digitized waveforms
240 for (int i = 0; i < Hits.getEntries(); i++) {
241 He3tubeHit* aHit = Hits[i];
242 if (aHit->definiteNeutron()) { //if this is true, this hit was definitely caused by a neutron.
244 h_DefNeutronHits->Fill(aHit->getdetNb());
245 h_DefNeutronHitsWeighted->Fill(aHit->getdetNb(), rate);
246 h_DefNeutronRate->Fill(aHit->getdetNb(), 1 / rateCorrection);
247 h_DefNeutronHitsVrs->Fill(aHit->getdetNb(), ring_section);
248 h_DefNeutronHitsWeightedVrs->Fill(aHit->getdetNb(), ring_section, rate);
249 h_DefNeutronRateVrs->Fill(aHit->getdetNb(), ring_section, 1 / rateCorrection);
250 h_PulseHeights_DefNeutron->Fill(aHit->getPeakV());
251 neutronStatus = 1;
252 tubeNum = aHit->getdetNb();
253 }
254
255 if (ContainsP[aHit->getdetNb()] && Contains3H[aHit->getdetNb()]) {
256 if (neutronStatus == 0) neutronStatus = 2;
257 tubeNum = aHit->getdetNb();
258 h_PulseHeights_Neutron->Fill(aHit->getPeakV());
259 h_NeutronHits->Fill(aHit->getdetNb());
260 h_NeutronRate->Fill(aHit->getdetNb(), 1 / rateCorrection);
261 h_NeutronHitsWeighted->Fill(aHit->getdetNb(), rate);
262 h_NeutronHitsVrs->Fill(aHit->getdetNb(), ring_section);
263 h_NeutronRateVrs->Fill(aHit->getdetNb(), ring_section, 1 / rateCorrection);
264 h_NeutronHitsWeightedVrs->Fill(aHit->getdetNb(), ring_section, rate);
265 nNeutronHits++;
266 } else {
267 h_PulseHeights_NotNeutron->Fill(aHit->getPeakV());
268 }
269 h_PulseHeights_All->Fill(aHit->getPeakV());
270
271 }
272
273 if (neutronStatus == 1) B2DEBUG(80, "He3tubeStudyModule: Definite Neutron in tube #" << tubeNum);
274 else if (neutronStatus == 2) B2DEBUG(80, "He3tubeStudyModule: Possible Neutron in tube #" << tubeNum);
275
276 for (int i = 0; i < 4; i++) {
277 if (ContainsP[i]) nPhits++;
278 if (Contains3H[i]) n3Hhits++;
279 }
280
281 eventNum++;
282
283
284
285}
286
288{
289
290 B2RESULT("He3tubeStudyModule: # of neutrons: " << nNeutronHits);
291 B2RESULT(" # of definite neutrons " << nDefiniteNeutron);
292 B2RESULT(" # of 3H hits: " << n3Hhits);
293 B2RESULT(" # of H hits: " << nPhits);
294
295
296
297}
298
300{
301}
302
303
static const ParticleType neutron
neutron particle
Definition: Const.h:675
static const ChargedStable proton
proton particle
Definition: Const.h:663
static const ParticleType photon
photon particle
Definition: Const.h:673
static const ChargedStable electron
electron particle
Definition: Const.h:659
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
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
int getEntries() const
Get the number of objects in the array.
Definition: StoreArray.h:216
TH1F * h_Edep1H3H_detNB
Energy deposited by Proton and Tritium in each tube.
TH2F * h_NeutronHitsWeightedVrs
Neutron Hits.
TH2F * h_NeutronRateVrs
Neutron Hits per second.
int m_sampletime
The sample time in us.
TH1F * h_PulseHeights_NotNeutron
Pulse height of waveforms from non-neutrons.
TH1F * h_NeutronRate
Neutron Hits per second.
virtual void initialize() override
Initialize the Module.
TH1F * h_PulseHeights_Neutron
Pulse height of waveforms from neutrons.
virtual void event() override
Event processor.
He3tubeStudyModule()
Constructor: Sets the description, the properties and the parameters of the module.
TH1F * h_Edep1H3H
Energy deposited by Proton and Tritium.
TH2F * h_DefNeutronHitsWeightedVrs
Definite Neutron Hits.
TH2F * h_DefNeutronRateVrs
Definite Neutron Hits per second.
virtual void endRun() override
End-of-run action.
TH1F * h_DefNeutronRate
Definite Neutron Hits per second.
virtual void terminate() override
Termination action.
TH1F * h_mche3_kinetic[10]
MC kin energy dis.
virtual void beginRun() override
Called when entering a new run.
TH1F * h_PulseHeights_DefNeutron
Pulse height of waveforms from definite neutrons.
TH1F * h_DefNeutronHitsWeighted
Definite Neutron Hits.
TH1F * h_DefNeutronHits
Definite Neutron Hits.
TH1F * h_Edep3H
Energy deposited by Tritiums.
TH2F * h_mche3_tvpW[10]
theta v phi dis
TH2F * h_mche3_tvp[10]
theta v phi dis
TH1F * h_mche3_kinetic_zoom[10]
Neutron kin energy dis.
TH1F * h_TotEdep
Momentum of neutrons.
int nDefiniteNeutron
Number of definte neutrons.
TH1F * h_Edep1H
Energy deposited by Protons.
TH1F * h_PulseHeights_All
Pulse heught of all waveforms.
TH1F * h_DetN_Edep
Energy deposited vs detector number
TH2F * h_DefNeutronHitsVrs
Definite Neutron Hits.
double rateCorrection
converts sample time to rate in s
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
double sqrt(double a)
sqrt for double
Definition: beamHelpers.h:28
Abstract base class for different kinds of events.
STL namespace.