Belle II Software development
PindiodeStudyModule.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/pindiode/modules/PindiodeStudyModule.h>
10#include <beast/pindiode/dataobjects/PindiodeSimHit.h>
11#include <beast/pindiode/dataobjects/PindiodeHit.h>
12#include <generators/SAD/dataobjects/SADMetaHit.h>
13#include <framework/datastore/StoreArray.h>
14#include <framework/logging/Logger.h>
15#include <framework/gearbox/GearDir.h>
16#include <cmath>
17
18#include <string>
19
20// ROOT
21#include <TRandom.h>
22
23using namespace std;
24
25using namespace Belle2;
26using namespace pindiode;
27
28//-----------------------------------------------------------------
29// Register the Module
30//-----------------------------------------------------------------
31REG_MODULE(PindiodeStudy);
32
33//-----------------------------------------------------------------
34// Implementation
35//-----------------------------------------------------------------
36
38{
39 // Set module properties
40 setDescription("Study module for Pindiodes (BEAST)");
41
42 //Default values are set here. New values can be in PINDIODE.xml.
43 addParam("CrematGain", m_CrematGain, "Charge sensitive preamplifier gain [volts/C] ", 1.4);
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
52//This module is a histomodule. Any histogram created here will be saved by the HistoManager module
54{
55 //Default values are set here. New values can be in PINDIODE.xml.
56 for (int i = 0; i < 4; i++) {
57 h_pin_rate[i] = new TH1F(TString::Format("pin_rate_%d", i), "Count", 64, 0., 64.);
58 h_pin_rate[i]->Sumw2();
59 }
60 for (int i = 0; i < 2; i++) {
61 h_pin_rs_rate[i] = new TH2F(TString::Format("pin_rs_rate_%d", i), "Count vs. ring section", 64, 0., 64., 12, 0., 12.);
62 h_pin_rs_rate[i]->Sumw2();
63 }
64 for (int i = 0; i < 64; i++) {
65 h_pin_dose1[i] = new TH1F(TString::Format("pin_dose1_%d", i), "", 10000, 0., 10000.);
66 h_pin_dose2[i] = new TH1F(TString::Format("pin_dose2_%d", i), "", 10000, 0., 10000.);
67 h_pin_dose1Weight[i] = new TH1F(TString::Format("pin_dose1Weight_%d", i), "", 10000, 0., 10000.);
68 h_pin_dose2Weight[i] = new TH1F(TString::Format("pin_dose2Weight_%d", i), "", 10000, 0., 10000.);
69 h_pin_volt[i] = new TH1F(TString::Format("pin_volt_%d", i), "", 10000, 0., 100.);
70 h_pin_time[i] = new TH1F(TString::Format("pin_time_%d", i), "", 1000, 0., 100.);
71 h_pin_vtime[i] = new TH1F(TString::Format("pin_vtime_%d", i), "", 1000, 0., 100.);
72
73 h_pin_idose[i] = new TH1F(TString::Format("pin_idose_%d", i), "", 10000, 0., 10000.);
74 h_pin_idoseWeight[i] = new TH1F(TString::Format("pin_idoseWeight_%d", i), "", 10000, 0., 10000.);
75
76 h_pin_rs_idose[i] = new TH2F(TString::Format("pin_rs_idose_%d", i), "", 10000, 0., 10000., 12, 0., 12.);
77 h_pin_rs_idoseWeight[i] = new TH2F(TString::Format("pin_rs_idoseWeight_%d", i), "", 10000, 0., 10000., 12, 0., 12.);
78
79 h_pin_ivolt[i] = new TH1F(TString::Format("pin_ivolt_%d", i), "", 10000, 0., 100.);
80 h_pin_itime[i] = new TH1F(TString::Format("pin_itime_%d", i), "", 1000, 0., 100.);
81 h_pin_ivtime[i] = new TH1F(TString::Format("pin_ivtime_%d", i), "", 1000, 0., 100.);
82
83 h_pin_dose1[i]->Sumw2();
84 h_pin_dose2[i]->Sumw2();
85 h_pin_dose1Weight[i]->Sumw2();
86 h_pin_dose2Weight[i]->Sumw2();
87 h_pin_idose[i]->Sumw2();
88 h_pin_idoseWeight[i]->Sumw2();
89 h_pin_rs_idose[i]->Sumw2();
90 h_pin_rs_idoseWeight[i]->Sumw2();
91 }
92
93}
94
95
97{
98 B2INFO("PindiodeStudyModule: Initialize");
99
100 //read pindiode xml file
101 getXMLData();
102
103 REG_HISTOGRAM
104
105}
106
108{
109}
110
112{
113 //Here comes the actual event processing
114
117 StoreArray<SADMetaHit> MetaHits;
118
119 //Look at the meta data to extract IR rate and scattering ring section
120 double rate = 0;
121 int ring_section = -1;
122 const int section_ordering[12] = {1, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2};
123 for (const auto& MetaHit : MetaHits) {
124 rate = MetaHit.getrate();
125 double sad_ssraw = MetaHit.getssraw();
126 double ssraw = 0;
127 if (sad_ssraw >= 0) ssraw = sad_ssraw / 100.;
128 else ssraw = 3000. + sad_ssraw / 100.;
129 //else if (sad_ssraw < 0) ssraw = 3000. + sad_ssraw / 100.;
130 ring_section = section_ordering[(int)((ssraw) / 250.)] - 1;
131 //ring_section = MetaHit.getring_section() - 1;
132 }
133
134 //Skip events with no Hits
135 if (SimHits.getEntries() == 0) {
136 return;
137 }
138
139 for (const auto& SimHit : SimHits) {
140 int detNb = SimHit.getCellId();
141 if (detNb < 64) {
142 double edep = SimHit.getEnergyDep();
143 double time = SimHit.getFlightTime();
144 //int PDG = aHit->getPDGCode();
145 const double meanEl = edep / m_WorkFunction * 1e9; //GeV to eV
146 const double sigma = sqrt(m_FanoFactor * meanEl); //sigma in electron
147 const int NbEle = (int)gRandom->Gaus(meanEl, sigma); //electron number
148 double volt = NbEle * 1.602176565e-19 * m_CrematGain * 1e12; // volt
149 h_pin_dose1[detNb]->Fill(edep * 1e6); //GeV to keV
150 h_pin_dose1Weight[detNb]->Fill(edep * 1e6, rate); //GeV to keV
151 if ((edep * 1e9) > m_WorkFunction) {
152 h_pin_dose2[detNb]->Fill(edep * 1e6); //GeV to keV
153 h_pin_dose2Weight[detNb]->Fill(edep * 1e6, rate); //GeV to keV
154 h_pin_volt[detNb]->Fill(volt * 1e3); //V to mV
155 h_pin_time[detNb]->Fill(time);
156 h_pin_vtime[detNb]->Fill(time, volt);
157 h_pin_rate[0]->Fill(detNb);
158 h_pin_rate[1]->Fill(detNb, rate);
159 }
160 }
161 }
162
163 for (const auto& Hit : Hits) {
164 int detNb = Hit.getdetNb();
165 if (detNb < 64) {
166 double edep = Hit.getedep();
167 double volt = Hit.getV();
168 double time = Hit.gettime();
169 h_pin_idose[detNb]->Fill(edep); //keV
170 h_pin_idoseWeight[detNb]->Fill(edep, rate); //keV
171 h_pin_ivolt[detNb]->Fill(volt * 1e3); //V to mV
172 h_pin_itime[detNb]->Fill(time);
173 h_pin_ivtime[detNb]->Fill(time, volt);
174 h_pin_rate[2]->Fill(detNb);
175 h_pin_rate[3]->Fill(detNb, rate);
176
177 h_pin_rs_rate[0]->Fill(detNb, ring_section);
178 h_pin_rs_rate[1]->Fill(detNb, ring_section, rate);
179 h_pin_rs_idose[detNb]->Fill(edep, ring_section); //keV
180 h_pin_rs_idoseWeight[detNb]->Fill(edep, ring_section, rate); //keV
181 }
182 }
183
184
185}
186//read tube centers, impulse response, and garfield drift data filename from PINDIODE.xml
188{
189 GearDir content = GearDir("/Detector/DetectorComponent[@name=\"PINDIODE\"]/Content/");
190 /*
191 //get the location of the tubes
192 for (const GearDir& activeParams : content.getNodes("Active")) {
193
194 PINCenter.push_back(ROOT::Math::XYZVector(activeParams.getLength("z_pindiode"),
195 activeParams.getLength("r_pindiode"),
196 activeParams.getLength("Phi")));
197 nPIN++;
198 }
199 */
200 m_CrematGain = content.getDouble("CrematGain");
201 m_WorkFunction = content.getDouble("WorkFunction");
202 m_FanoFactor = content.getDouble("FanoFactor");
203
204 B2INFO("PinDigitizer");
205
206}
208{
209
210
211}
212
214{
215}
216
217
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
virtual void initialize() override
Initialize the Module.
TH1F * h_pin_vtime[100]
histo time weighted by volt
virtual void event() override
Event processor.
virtual void endRun() override
End-of-run action.
virtual void getXMLData()
reads data from PINDIODE.xml: tube location, drift data filename, sigma of impulse response function
virtual void terminate() override
Termination action.
PindiodeStudyModule()
Constructor: Sets the description, the properties and the parameters of the module.
virtual void beginRun() override
Called when entering a new run.
double m_CrematGain
number of detectors.
TH1F * h_pin_ivtime[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.