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