Belle II Software development
CsiStudy_v2Module.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/csi/modules/CsiStudy_v2Module.h>
10#include <framework/logging/Logger.h>
11#include <framework/gearbox/GearDir.h>
12#include <cmath>
13
14#include <string>
15
16using namespace std;
17
18using namespace Belle2;
19using namespace csi;
20
21//-----------------------------------------------------------------
22// Register the Module
23//-----------------------------------------------------------------
24REG_MODULE(CsiStudy_v2);
25
26//-----------------------------------------------------------------
27// Implementation
28//-----------------------------------------------------------------
29
31{
32 // Set module properties
33 setDescription("Study_v2 module for Csis (BEAST)");
34
35 addParam("Ethres", m_Ethres, "Energy threshold in MeV", 0.0);
36}
37
39{
40}
41
42//This module is a histomodule. Any histogram created here will be saved by the HistoManager module
44{
45 for (int i = 0; i < 153; i++) {
46 h_csi_drate[i] = new TH1F(TString::Format("csi_rate_%d", i), "count", 18, 0., 18.);
47 h_csi_drate[i]->Sumw2();
48
49 h_csi_rs_drate[i] = new TH2F(TString::Format("csi_rs_drate_%d", i), "count v. ring section", 18, 0., 18., 12, 0., 12.);
50 h_csi_rs_drate[i]->Sumw2();
51
52 for (int j = 0; j < 18; j++) {
53
54 h_csi_dedep[j][i] = new TH1F(TString::Format("csi_dedep_%d_%d", j, i), "Energy deposited [MeV]", 5000, 0., 400.);
55 h_csi_rs_dedep[j][i] = new TH2F(TString::Format("csi_rs_dedep_%d_%d", j, i), "Energy deposited [MeV]", 5000, 0., 400., 12, 0., 12.);
56
57 h_csi_denergy[j][i] = new TH1F(TString::Format("csi_denergy_%d_%d", j, i), "Energy deposited [MeV]", 200, 0.1, 3.);
58 h_csi_rs_denergy[j][i] = new TH2F(TString::Format("csi_rs_denergy_%d_%d", j, i), "Energy deposited [MeV] per section", 200, 0.1, 3.,
59 12, 0.,
60 12.);
61
62 h_csi_dedep[j][i]->Sumw2();
63 h_csi_rs_dedep[j][i]->Sumw2();
64 h_csi_denergy[j][i]->Sumw2();
65 h_csi_rs_denergy[j][i]->Sumw2();
66 }
67 }
68 /*
69 for (int i = 0; i < 2; i++) {
70 h_csi_rate[i] = new TH1F(TString::Format("csi_rate_%d", i), "count", 18, 0., 18.);
71 h_csi_rate[i]->Sumw2();
72
73 h_csi_rs_rate[i] = new TH2F(TString::Format("csi_rs_rate_%d", i), "count v. ring section", 18, 0., 18., 12, 0., 12.);
74 h_csi_rs_rate[i]->Sumw2();
75 }
76 for (int i = 0; i < 18; i++) {
77 h_csi_energyVrs1[i] = new TH2F(TString::Format("csi_energyVrs1_%d", i), "Energy deposited [MeV] per section", 200, 0.1, 3., 12, 0.,
78 12.);
79 h_csi_energyVrs2[i] = new TH2F(TString::Format("csi_energyVrs2_%d", i), "Energy deposited [MeV] per section", 200, 0.1, 3., 12, 0.,
80 12.);
81 h_csi_energyVrs3[i] = new TH2F(TString::Format("csi_energyVrs3_%d", i), "Energy deposited [MeV] per section", 200, 0.1, 3., 12, 0.,
82 12.);
83
84 h_csi_energyVrs1W[i] = new TH2F(TString::Format("csi_energyVrs1W_%d", i), "Energy deposited [MeV] per section", 200, 0.1, 3., 12,
85 0.,
86 12.);
87 h_csi_energyVrs2W[i] = new TH2F(TString::Format("csi_energyVrs2W_%d", i), "Energy deposited [MeV] per section", 200, 0.1, 3., 12,
88 0.,
89 12.);
90 h_csi_energyVrs3W[i] = new TH2F(TString::Format("csi_energyVrs3W_%d", i), "Energy deposited [MeV] per section", 200, 0.1, 3., 12,
91 0.,
92 12.);
93
94 h_csi_energy1[i] = new TH1F(TString::Format("csi_energy1_%d", i), "Energy deposited [MeV]", 200, 0.1, 3.);
95 h_csi_energy2[i] = new TH1F(TString::Format("csi_energy2_%d", i), "Energy deposited [MeV]", 200, 0.1, 3.);
96 h_csi_energy3[i] = new TH1F(TString::Format("csi_energy3_%d", i), "Energy deposited [MeV]", 200, 0.1, 3.);
97
98 h_csi_energy1W[i] = new TH1F(TString::Format("csi_energy1W_%d", i), "Energy deposited [MeV]", 200, 0.1, 3.);
99 h_csi_energy2W[i] = new TH1F(TString::Format("csi_energy2W_%d", i), "Energy deposited [MeV]", 200, 0.1, 3.);
100 h_csi_energy3W[i] = new TH1F(TString::Format("csi_energy3W_%d", i), "Energy deposited [MeV]", 200, 0.1, 3.);
101
102 h_csi_Evtof[i] = new TH2F(TString::Format("csi_Evtof_%d", i), "Energy deposited [MeV] vs TOF [ns] - all", 5000, 0., 1000.,
103 1000, 0., 400.);
104 h_csi_Evtof1[i] = new TH2F(TString::Format("csi_Evtof1_%d", i), "Energy deposited [MeV] vs TOF [ns] - all", 5000, 0., 1000.,
105 1000, 0., 400.);
106 h_csi_Evtof2[i] = new TH2F(TString::Format("csi_Evtof2_%d", i), "Energy deposited [MeV] vs TOF [ns] - only photons", 5000, 0.,
107 1000., 1000, 0., 400.);
108 h_csi_Evtof3[i] = new TH2F(TString::Format("csi_Evtof3_%d", i), "Energy deposited [MeV] vs TOF [ns] - only e+/e-", 5000, 0.,
109 1000., 1000, 0., 400.);
110
111 h_csi_edep[i] = new TH1F(TString::Format("csi_edep_%d", i), "Energy deposited [MeV]", 5000, 0., 400.);
112 h_csi_edep1[i] = new TH1F(TString::Format("csi_edep1_%d", i), "Energy deposited [MeV]", 5000, 0., 400.);
113 h_csi_edep2[i] = new TH1F(TString::Format("csi_edep2_%d", i), "Energy deposited [MeV]", 5000, 0., 400.);
114 h_csi_edep1Weight[i] = new TH1F(TString::Format("csi_edep1Weight_%d", i), "Energy deposited [MeV]", 5000, 0., 400.);
115 h_csi_edep2Weight[i] = new TH1F(TString::Format("csi_edep2Weight_%d", i), "Energy deposited [MeV]", 5000, 0., 400.);
116
117 h_csi_rs_edep1[i] = new TH2F(TString::Format("csi_rs_edep1_%d", i), "Energy deposited [MeV]", 5000, 0., 400., 12, 0., 12.);
118 h_csi_rs_edep2[i] = new TH2F(TString::Format("csi_rs_edep2_%d", i), "Energy deposited [MeV]", 5000, 0., 400., 12, 0., 12.);
119 h_csi_rs_edep1Weight[i] = new TH2F(TString::Format("csi_rs_edep1Weight_%d", i), "Energy deposited [MeV]", 5000, 0., 400., 12, 0.,
120 12.);
121 h_csi_rs_edep2Weight[i] = new TH2F(TString::Format("csi_rs_edep2Weight_%d", i), "Energy deposited [MeV]", 5000, 0., 400., 12, 0.,
122 12.);
123
124 h_csi_energy1[i]->Sumw2();
125 h_csi_energy2[i]->Sumw2();
126 h_csi_energy3[i]->Sumw2();
127 h_csi_energy1W[i]->Sumw2();
128 h_csi_energy2W[i]->Sumw2();
129 h_csi_energy3W[i]->Sumw2();
130 h_csi_energyVrs1[i]->Sumw2();
131 h_csi_energyVrs2[i]->Sumw2();
132 h_csi_energyVrs3[i]->Sumw2();
133 h_csi_energyVrs1W[i]->Sumw2();
134 h_csi_energyVrs2W[i]->Sumw2();
135 h_csi_energyVrs3W[i]->Sumw2();
136 h_csi_edep[i]->Sumw2();
137 h_csi_edep1[i]->Sumw2();
138 h_csi_edep2[i]->Sumw2();
139 h_csi_edep1Weight[i]->Sumw2();
140 h_csi_edep2Weight[i]->Sumw2();
141 h_csi_rs_edep1[i]->Sumw2();
142 h_csi_rs_edep2[i]->Sumw2();
143 h_csi_rs_edep1Weight[i]->Sumw2();
144 h_csi_rs_edep2Weight[i]->Sumw2();
145 }
146 */
147}
148
149
151{
152 B2INFO("CsiStudy_v2Module: Initialize");
153
154 //load
155 MetaHits.isRequired();
156 SimHits.isOptional();
157 Hits.isOptional();
158
159 //read csi xml file
160 getXMLData();
161
162 REG_HISTOGRAM
163
164}
165
167{
168}
169
171{
172 //Skip events with no Hits
173 if (SimHits.getEntries() == 0) {
174 return;
175 }
176
177 //Look at the meta data to extract IR rate and scattering ring section
178 //double rate = 0;
179 int ring_section = -1;
180 const int section_ordering[12] = {1, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2};
181 for (const auto& MetaHit : MetaHits) {
182 //rate = MetaHit.getrate();
183 double sad_ssraw = MetaHit.getssraw();
184 double ssraw = 0;
185 if (sad_ssraw >= 0) ssraw = sad_ssraw / 100.;
186 else ssraw = 3000. + sad_ssraw / 100.;
187 //else if (sad_ssraw < 0) ssraw = 3000. + sad_ssraw / 100.;
188 ring_section = section_ordering[(int)((ssraw) / 250.)] - 1;
189 //ring_section = MetaHit.getring_section() - 1;
190 }
191 /*
192 //Loop over SimHit
193 for (const auto& SimHit : SimHits) {
194 int detNB = SimHit.getCellId();
195 int pdg = SimHit.getPDGCode();
196 double Edep = SimHit.getEnergyDep() * 1e3; //GeV -> MeV
197 double tof = SimHit.getFlightTime(); //ns
198
199 h_csi_edep[detNB]->Fill(Edep);
200 h_csi_Evtof[detNB]->Fill(tof, Edep);
201 if (pdg == Const::photon.getPDGCode()) h_csi_Evtof1[detNB]->Fill(tof, Edep);
202 else if (fabs(pdg) == Const::electron.getPDGCode()) h_csi_Evtof2[detNB]->Fill(tof, Edep);
203 h_csi_energy1[detNB]->Fill(log10(Edep));
204 h_csi_energy1W[detNB]->Fill(log10(Edep), rate);
205 h_csi_energyVrs1[detNB]->Fill(log10(Edep), ring_section);
206 h_csi_energyVrs1W[detNB]->Fill(log10(Edep), ring_section, rate);
207 }
208 */
209 //Loop over DigiHit
210 for (const auto& Hit : Hits) {
211 int detNB = Hit.getCellId();
212 double Edep = Hit.getEnergyDep() * 1e3; //GeV -> MeV
213 double RecEdep = Edep;//Hit.getEnergyRecDep() * 1e3; //GeV -> MeV
214 //double tof = Hit.getFlightTime(); //ns
215 /*
216 h_csi_rate[0]->Fill(detNB);
217 h_csi_rate[1]->Fill(detNB, rate);
218 h_csi_edep1[detNB]->Fill(Edep);
219 h_csi_edep2[detNB]->Fill(RecEdep);
220 h_csi_edep1Weight[detNB]->Fill(Edep, rate);
221 h_csi_edep2Weight[detNB]->Fill(RecEdep, rate);
222 h_csi_Evtof3[detNB]->Fill(tof, RecEdep);
223 h_csi_rs_rate[0]->Fill(detNB, ring_section);
224 h_csi_rs_rate[1]->Fill(detNB, ring_section, rate);
225 h_csi_rs_edep1[detNB]->Fill(Edep, ring_section);
226 h_csi_rs_edep2[detNB]->Fill(RecEdep, ring_section);
227 h_csi_rs_edep1Weight[detNB]->Fill(Edep, ring_section, rate);
228 h_csi_rs_edep2Weight[detNB]->Fill(RecEdep, ring_section, rate);
229 h_csi_energy2[detNB]->Fill(log10(Edep));
230 h_csi_energy3[detNB]->Fill(log10(RecEdep));
231 h_csi_energy2W[detNB]->Fill(log10(Edep), rate);
232 h_csi_energy3W[detNB]->Fill(log10(RecEdep), rate);
233 h_csi_energyVrs2[detNB]->Fill(log10(Edep), ring_section);
234 h_csi_energyVrs3[detNB]->Fill(log10(RecEdep), ring_section);
235 h_csi_energyVrs2W[detNB]->Fill(log10(Edep), ring_section, rate);
236 h_csi_energyVrs3W[detNB]->Fill(log10(RecEdep), ring_section, rate);
237 */
238 for (int i = 0; i < 153; i ++) {
239 /*cout << " thres1 " << m_Thres_hitRate[detNB][i]
240 << " thres2 " << m_Thres_sumE[detNB][i]
241 << " edep " << RecEdep << " true Edep " << Edep << endl;*/
242 if (RecEdep >= m_Thres_hitRate[detNB][i] && m_Thres_hitRate[detNB][i] > 0) {
243 h_csi_drate[i]->Fill(detNB);
244 h_csi_rs_drate[i]->Fill(detNB, ring_section);
245 }
246 if (RecEdep >= m_Thres_sumE[detNB][i] && m_Thres_sumE[detNB][i] > 0) {
247 h_csi_dedep[detNB][i]->Fill(RecEdep);
248 h_csi_rs_dedep[detNB][i]->Fill(RecEdep, ring_section);
249
250 h_csi_denergy[detNB][i]->Fill(log10(RecEdep));
251 h_csi_rs_denergy[detNB][i]->Fill(log10(RecEdep), ring_section);
252 }
253 }
254 }
255}
256//read tube centers, impulse response, and garfield drift data filename from CSI.xml
258{
259 GearDir content = GearDir("/Detector/DetectorComponent[@name=\"CSI\"]/Content/");
260 m_Ethres = content.getDouble("Ethres");
261
262
263 for (int i = 0; i < 18; i ++) {
264 int iThres_hitRate = 0;
265 for (double Thres : content.getArray(TString::Format("thres_hitRate_det%d", i).Data(), {0})) {
266 m_Thres_hitRate[i][iThres_hitRate] = Thres;
267 iThres_hitRate++;
268 }
269 int iThres_sumE = 0;
270 for (double Thres : content.getArray(TString::Format("thres_sumE_det%d", i).Data(), {0})) {
271 m_Thres_sumE[i][iThres_sumE] = Thres;
272 iThres_sumE++;
273 }
274 }
275
276 B2INFO("CsiStudy_v2");
277
278}
280{
281
282
283}
284
286{
287}
288
289
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
TH1F * h_csi_dedep[18][153]
Energy.
CsiStudy_v2Module()
Constructor: Sets the description, the properties and the parameters of the module.
double m_Thres_hitRate[18][200]
Rate.
StoreArray< CsiSimHit > SimHits
Array of sim hits.
virtual void initialize() override
Initialize the Module.
virtual void event() override
Event processor.
virtual void endRun() override
End-of-run action.
TH1F * h_csi_denergy[18][153]
Energy.
virtual void getXMLData()
reads data from CSI.xml: tube location, drift data filename, sigma of impulse response function
virtual void terminate() override
Termination action.
virtual ~CsiStudy_v2Module()
Destructor.
StoreArray< CsiHit_v2 > Hits
Array of digi hits.
TH2F * h_csi_rs_denergy[18][153]
Energy.
virtual void beginRun() override
Called when entering a new run.
StoreArray< SADMetaHit > MetaHits
Array of SAD particle.
double m_Thres_sumE[18][200]
Energy threshold.
double m_Ethres
Energy threshold.
TH2F * h_csi_rs_dedep[18][153]
Energy.
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
Abstract base class for different kinds of events.
STL namespace.
Structure to hold some of the calpulse data.