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