Belle II Software development
BeamabortStudyModule.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/beamabort/modules/BeamabortStudyModule.h>
10#include <beast/beamabort/dataobjects/BeamabortSimHit.h>
11#include <beast/beamabort/dataobjects/BeamabortHit.h>
12#include <framework/datastore/StoreArray.h>
13#include <framework/logging/Logger.h>
14#include <framework/gearbox/GearDir.h>
15#include <cmath>
16
17#include <string>
18
19// ROOT
20#include <TRandom.h>
21
22#include <generators/SAD/dataobjects/SADMetaHit.h>
23
24using namespace std;
25
26using namespace Belle2;
27using namespace beamabort;
28
29//-----------------------------------------------------------------
30// Register the Module
31//-----------------------------------------------------------------
32REG_MODULE(BeamabortStudy);
33
34//-----------------------------------------------------------------
35// Implementation
36//-----------------------------------------------------------------
37
39{
40 // Set module properties
41 setDescription("Study module for Beamaborts (BEAST)");
42
43 //Default values are set here. New values can be in PINDIODE.xml.
44 addParam("WorkFunction", m_WorkFunction, "Convert eV to e [e/eV] ", 1.12);
45 addParam("FanoFactor", m_FanoFactor, "e resolution ", 0.1);
46}
47
49{
50}
51
53{
54 B2INFO("BeamabortStudyModule: Initialize");
55
56 for (int i = 0; i < 8; i++) {
57 h_dia_dose[i] = new TH1F(TString::Format("dia_dose_%d", i), "", 10000, 0., 10000.);
58 h_dia_dose[i]->Sumw2();
59 }
60
61 //read beamabort xml file
62
63}
64
65//This module is a histomodule. Any histogram created here will be saved by the HistoManager module
67{
68 getXMLData();
69
70
71
72 //Default values are set here. New values can be in BEAMABORT.xml.
73 for (int i = 0; i < 4; i++) {
74 h_dia_rate[i] = new TH1F(TString::Format("dia_rate_%d", i), "Count", 8, 0., 8.);
75 h_dia_rate[i]->Sumw2();
76 }
77 for (int i = 0; i < 2; i++) {
78 h_dia_rs_rate[i] = new TH2F(TString::Format("dia_rs_rate_%d", i), "Count vs ring section", 8, 0., 8., 12, 0., 12.);
79 h_dia_rs_rate[i]->Sumw2();
80 }
81
82 for (int i = 0; i < 8; i++) {
83 h_dia_doseWeight[i] = new TH1F(TString::Format("dia_doseWeight_%d", i), "", 10000, 0., 10000.);
84 h_dia_amp[i] = new TH1F(TString::Format("dia_amp_%d", i), "", 10000, 0., 10000.);
85 h_dia_time[i] = new TH1F(TString::Format("dia_time_%d", i), "", 1000, 0., 100.);
86 h_dia_vtime[i] = new TH1F(TString::Format("dia_vtime_%d", i), "", 1000, 0., 100.);
87 h_dia_idose[i] = new TH1F(TString::Format("dia_idose_%d", i), "", 10000, 0., 10000.);
88 h_dia_idoseWeight[i] = new TH1F(TString::Format("dia_idoseWeight_%d", i), "", 10000, 0., 10000.);
89 h_dia_rs_idose[i] = new TH2F(TString::Format("dia_rs_idose_%d", i), "", 10000, 0., 10000., 12, 0., 12.);
90 h_dia_rs_idoseWeight[i] = new TH2F(TString::Format("dia_rs_idoseWeight_%d", i), "", 10000, 0., 10000., 12, 0., 12.);
91 h_dia_iamp[i] = new TH1F(TString::Format("dia_iamp_%d", i), "", 10000, 0., 10000.);
92 h_dia_itime[i] = new TH1F(TString::Format("dia_itime_%d", i), "", 1000, 0., 100.);
93 h_dia_ivtime[i] = new TH1F(TString::Format("dia_ivtime_%d", i), "", 1000, 0., 100.);
94 h_dia_Amp[i] = new TH1F(TString::Format("dia_Amp_%d", i), "", 100000, 0., 100000.);
95 h_dia_edep[i] = new TH1F(TString::Format("dia_edep_%d", i), "", 4000, 0., 4000.);
96
97 h_dia_doseWeight[i]->Sumw2();
98 h_dia_idose[i]->Sumw2();
99 h_dia_idoseWeight[i]->Sumw2();
100 h_dia_rs_idose[i]->Sumw2();
101 h_dia_rs_idoseWeight[i]->Sumw2();
102 }
103
104 REG_HISTOGRAM
105}
106
107
109{
110}
111
113{
114 //Here comes the actual event processing
115 double curr[8];
116 double Edep[8];
117 for (int i = 0; i < 8; i++) {
118 curr[i] = 0;
119 Edep[i] = 0;
120 }
123 StoreArray<SADMetaHit> MetaHits;
124
125 //Skip events with no Hits
126 if (SimHits.getEntries() == 0) {
127 return;
128 }
129
130 //Look at the meta data to extract IR rate and scattering ring section
131 double rate = 0;
132 int ring_section = -1;
133 const int section_ordering[12] = {1, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2};
134 for (const auto& MetaHit : MetaHits) {
135 rate = MetaHit.getrate();
136 double sad_ssraw = MetaHit.getssraw();
137 double ssraw = 0;
138 if (sad_ssraw >= 0) ssraw = sad_ssraw / 100.;
139 else ssraw = 3000. + sad_ssraw / 100.;
140 //else if (sad_ssraw < 0) ssraw = 3000. + sad_ssraw / 100.;
141 ring_section = section_ordering[(int)((ssraw) / 250.)] - 1;
142 //ring_section = MetaHit.getring_section() - 1;
143 }
144
145 for (const auto& SimHit : SimHits) {
146 int detNb = SimHit.getCellId();
147 if (detNb < 8) {
148 double edep = SimHit.getEnergyDep();
149 double time = SimHit.getFlightTime();
150 double meanEl = edep / m_WorkFunction * 1e9; //GeV to eV
151 double sigma = sqrt(m_FanoFactor * meanEl); //sigma in electron
152 int NbEle = (int)gRandom->Gaus(meanEl, sigma); //electron number
153 double Amp = NbEle / (6.25 * 1e18); // A x s
154 Edep[detNb] += edep;
155 curr[detNb] += Amp;
156 h_dia_dose[detNb]->Fill(edep * 1e6); //GeV to keV
157 h_dia_doseWeight[detNb]->Fill(edep * 1e6, rate); //GeV to keV
158 h_dia_amp[detNb]->Fill(Amp * 1e15); //A x s -> mA x s
159 h_dia_time[detNb]->Fill(time);
160 h_dia_vtime[detNb]->Fill(time, Amp * 1e15);
161 h_dia_rate[0]->Fill(detNb);
162 h_dia_rate[1]->Fill(detNb, rate);
163 }
164 }
165
166 for (int i = 0; i < 4; i++) {
167 if (curr[i] > 0 && Edep[i] > 0) {
168 h_dia_Amp[i]->Fill(curr[i] * 1e15);
169 h_dia_edep[i]->Fill(Edep[i] * 1e6);
170 }
171 }
172
173 for (const auto& Hit : Hits) {
174 int detNb = Hit.getdetNb();
175 double edep = Hit.getedep();
176 double current = Hit.getI();
177 double time = Hit.gettime();
178 h_dia_idose[detNb]->Fill(edep); //keV
179 h_dia_idoseWeight[detNb]->Fill(edep, rate); //keV
180 h_dia_rs_idose[detNb]->Fill(edep, ring_section); //keV
181 h_dia_rs_idoseWeight[detNb]->Fill(edep, ring_section, rate); //keV
182 h_dia_iamp[detNb]->Fill(current * 1e6); //I to uI
183 h_dia_itime[detNb]->Fill(time);
184 h_dia_ivtime[detNb]->Fill(time, current * 1e6);
185 h_dia_rate[2]->Fill(detNb);
186 h_dia_rate[3]->Fill(detNb, rate);
187
188 h_dia_rs_rate[0]->Fill(detNb, ring_section);
189 h_dia_rs_rate[1]->Fill(detNb, ring_section, rate);
190 }
191
192 //}
193}
194//read tube centers, impulse response, and garfield drift data filename from BEAMABORT.xml
196{
197 GearDir content = GearDir("/Detector/DetectorComponent[@name=\"BEAMABORT\"]/Content/");
198
199 m_WorkFunction = content.getDouble("WorkFunction");
200 m_FanoFactor = content.getDouble("FanoFactor");
201
202 B2INFO("BeamabortStudy");
203
204}
206{
207
208
209}
210
212{
213}
214
215
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
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_dia_ivtime[100]
histo time weighted by volt
virtual void initialize() override
Initialize the Module.
virtual void event() override
Event processor.
virtual void endRun() override
End-of-run action.
virtual void getXMLData()
reads data from BEAMABORT.xml: tube location, drift data filename, sigma of impulse response function
virtual void terminate() override
Termination action.
BeamabortStudyModule()
Constructor: Sets the description, the properties and the parameters of the module.
virtual void beginRun() override
Called when entering a new run.
TH1F * h_dia_vtime[100]
histo time weighted by volt
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
double sqrt(double a)
sqrt for double
Definition: beamHelpers.h:28
Abstract base class for different kinds of events.
STL namespace.
Structure to hold some of the calpulse data.