BmnRoot
26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Toggle main menu visibility
Loading...
Searching...
No Matches
BmnScWallDigitizer.cxx
Go to the documentation of this file.
1
/*
2
* File: BmnScWallDigitizer.cxx
3
* Author: Sergey Morozov
4
*
5
* Created on 16.09.2021, 12:00
6
*/
7
8
#include "
BmnScWallDigitizer.h
"
9
10
#include "
BmnScWallAddress.h
"
11
#include "FairRootManager.h"
12
#include "
TStopwatch.h
"
13
14
#include <FairRun.h>
15
#include <FairRunSim.h>
16
#include <
nlohmann/json.hpp
>
17
18
BmnScWallDigitizer::BmnScWallDigitizer
(
int
period)
19
:
BmnScWallDigitizer
(
Form
(
"SCWALL_digitizer_period%d.json"
, period))
20
{}
21
22
BmnScWallDigitizer::BmnScWallDigitizer
(
const
char
* config)
23
:
FairTask
(
"BmnScWallDigitizer"
)
24
,
fScale
(1.0)
25
,
fThreshold
(0.0)
26
,
fTimeCut
(1000.0)
27
,
fSiPM
(2668, 55, 0.1, 0.0021)
28
,
fPointArray
(nullptr)
29
,
fDigiArray
(nullptr)
30
,
fworkTime
(0.0f)
31
{
32
if
(config && config[0] !=
'\0'
) {
33
LoadConfig
(config);
34
}
35
}
36
37
InitStatus
BmnScWallDigitizer::LoadConfig
(
const
char
* config)
38
{
39
const
char
* vmc = getenv(
"VMCWORKDIR"
);
40
if
(!vmc || !vmc[0]) {
41
LOG(error) <<
Form
(
"%s::LoadConfig: VMCWORKDIR is not set"
, GetName());
42
SetActive(
kFALSE
);
43
return
kERROR;
44
}
45
46
const
std::string fullPath = std::string(vmc) +
"/parameters/scwall/"
+ config;
47
std::ifstream input(fullPath);
48
if
(!input.is_open()) {
49
LOG(error) <<
Form
(
"%s::LoadConfig: cannot open file %s"
, GetName(), fullPath.c_str());
50
SetActive(
kFALSE
);
51
return
kERROR;
52
}
53
54
nlohmann::json
j;
55
try
{
56
input >> j;
57
}
catch
(
const
std::exception& e) {
58
LOG(error) <<
Form
(
"%s::LoadConfig: failed to parse JSON %s: %s"
, GetName(), fullPath.c_str(), e.what());
59
SetActive(
kFALSE
);
60
return
kERROR;
61
}
62
63
const
std::string version = j.value(
"version"
,
"unknown"
);
64
const
std::string comment = j.value(
"comment"
,
"none"
);
65
66
if
(j.contains(
"scale"
))
67
fScale
= j[
"scale"
].get<
double
>();
68
69
if
(j.contains(
"threshold"
))
70
fThreshold
= j[
"threshold"
].get<
double
>();
71
72
if
(j.contains(
"timecut"
))
73
fTimeCut
= j[
"timecut"
].get<
double
>();
74
75
if
(j.contains(
"sipm"
) && j[
"sipm"
].is_object()) {
76
const
auto
& jsipm = j[
"sipm"
];
77
78
int
nPixels =
fSiPM
.Npixels;
79
int
mipPixels =
fSiPM
.pixPerMIP;
80
double
noise =
fSiPM
.noiseMIP;
81
double
mipEnergy =
fSiPM
.gevPerMIP;
82
83
if
(jsipm.contains(
"n_pixels"
))
84
nPixels = jsipm[
"n_pixels"
].get<
int
>();
85
86
if
(jsipm.contains(
"mip_pixels"
))
87
mipPixels = jsipm[
"mip_pixels"
].get<
int
>();
88
89
if
(jsipm.contains(
"noise"
))
90
noise = jsipm[
"noise"
].get<
double
>();
91
92
if
(jsipm.contains(
"mip_energy"
))
93
mipEnergy = jsipm[
"mip_energy"
].get<
double
>();
94
95
fSiPM
=
SiPM
(nPixels, mipPixels, noise, mipEnergy);
96
}
97
98
LOG(info) <<
Form
(
"%s::LoadConfig: loaded %s (version=%s, comment=%s)"
, GetName(), fullPath.c_str(),
99
version.c_str(), comment.c_str());
100
101
return
kSUCCESS;
102
}
103
104
// Destructor
105
BmnScWallDigitizer::~BmnScWallDigitizer
()
106
{
107
if
(
fDigiArray
) {
108
fDigiArray
->Delete();
109
delete
fDigiArray
;
110
}
111
}
112
113
// Initialization method
114
InitStatus
BmnScWallDigitizer::Init
()
115
{
116
fworkTime
= 0.0;
117
LOG(detail) <<
"-I- BmnScWallDigitizer: Init started..."
<< std::endl;
118
119
FairRootManager* ioman = FairRootManager::Instance();
120
if
(!ioman) {
121
LOG(error) <<
"-E- BmnScWallDigitizer::Init: RootManager not instantiated!"
<< std::endl;
122
return
kFATAL;
123
}
124
125
fPointArray
=
static_cast<
TClonesArray
*
>
(ioman->GetObject(
"ScWallPoint"
));
126
if
(!
fPointArray
) {
127
LOG(error) <<
"-E- BmnScWallDigitizer::Init: No ScWallPoint array!"
<< std::endl;
128
return
kERROR;
129
}
130
131
fDigiArray
=
new
TClonesArray
(
"BmnScWallDigit"
);
132
ioman->Register(
"ScWallDigit"
,
"ScWall"
,
fDigiArray
,
kTRUE
);
133
134
LOG(detail) <<
"-I- BmnScWallDigitizer: Initialization successful"
<< std::endl;
135
return
kSUCCESS;
136
}
137
138
void
BmnScWallDigitizer::Exec
(
Option_t
* opt)
139
{
140
if
(!IsActive())
141
return
;
142
TStopwatch
sw;
143
sw.
Start
();
144
145
LOG(debug2) <<
"BmnScWallDigitizer::Exec() started..."
<< std::endl;
146
if
(!
fDigiArray
)
147
Fatal
(
"Exec"
,
"No DigiArray"
);
148
149
fDigiArray
->Clear();
150
FillHitMap
();
// One address (key) is now associated with a sorted vector of tracks which fired it
151
152
for
(
auto
& it :
fuoHitMap
) {
153
uint32_t address = it.first;
154
const
auto
& tracks_contributions = it.second;
155
156
double
totalEnergy = 0.0;
157
double
crossTime = 0.0;
// time when threshold is crossed
158
bool
reachedThreshold =
false
;
159
for
(
const
auto
* point : tracks_contributions) {
160
if
(point->GetTime() >
fTimeCut
)
161
break
;
162
163
totalEnergy += point->GetEnergyLoss();
164
if
(!reachedThreshold && totalEnergy *
fScale
>
fThreshold
) {
165
crossTime = point->GetTime();
166
reachedThreshold =
true
;
167
LOG(debug2) <<
Form
(
"Reached threshold. Energy %.4f Weighted time %.4f"
, totalEnergy, crossTime);
168
}
169
}
170
totalEnergy =
fSiPM
.ModelResponse(totalEnergy);
171
totalEnergy *=
fScale
;
172
173
if
(!reachedThreshold || totalEnergy < std::numeric_limits<double>::epsilon()) {
174
continue
;
175
}
else
{
176
TClonesArray
& ar = *
fDigiArray
;
177
long
entries =
fDigiArray
->GetEntriesFast();
178
new
(ar[entries])
BmnScWallDigit
(address, crossTime, totalEnergy);
179
if
(FairLogger::GetLogger()->IsLogNeeded(fair::Severity::debug2))
180
static_cast<
BmnScWallDigit
*
>
(ar.
At
(entries))->
Print
();
181
}
182
}
183
184
sw.
Stop
();
185
fworkTime
+= sw.
RealTime
();
186
}
187
188
void
BmnScWallDigitizer::FillHitMap
()
189
{
190
fuoHitMap
.clear();
191
192
// Fill the hit map with points from the TClonesArray
193
for
(
int
iPoint = 0, nPoint =
fPointArray
->GetEntriesFast(); iPoint < nPoint; ++iPoint) {
194
auto
* point =
static_cast<
BmnScWallPoint
*
>
(
fPointArray
->At(iPoint));
195
uint32_t address =
BmnScWallAddress::GetAddress
(point->GetCopyMother());
196
fuoHitMap
[address].push_back(point);
197
}
198
199
// Sort each vector of points by their time
200
for
(
auto
& pair :
fuoHitMap
) {
201
std::vector<BmnScWallPoint*>& points = pair.second;
202
std::sort(points.begin(), points.end(),
203
[](
BmnScWallPoint
* a,
BmnScWallPoint
* b) { return a->GetTime() < b->GetTime(); });
204
}
205
206
LOG(debug2) <<
"BmnScWallDigitizer::FillHitMap() event "
<< gMC->CurrentEvent() <<
" fired sections "
207
<<
fuoHitMap
.size();
208
}
209
210
void
BmnScWallDigitizer::Finish
()
211
{
212
printf(
"Work time of the ScWall digitizer: %.4f sec.\n"
,
fworkTime
);
213
}
kFALSE
constexpr Bool_t kFALSE
kTRUE
constexpr Bool_t kTRUE
Option_t
const char Option_t
Fatal
void Fatal(const char *location, const char *msgfmt,...)
TStopwatch.h
Form
char * Form(const char *fmt,...)
BmnScWallAddress::GetAddress
static uint32_t GetAddress(uint32_t CellId)
Return address from system ID, Cell ID.
Definition
BmnScWallAddress.h:30
BmnScWallDigit
Definition
BmnScWallDigit.h:14
BmnScWallDigit::Print
virtual void Print(const Option_t *opt="")
Definition
BmnScWallDigit.h:31
BmnScWallDigitizer::fuoHitMap
std::unordered_map< uint32_t, std::vector< BmnScWallPoint * > > fuoHitMap
Definition
BmnScWallDigitizer.h:95
BmnScWallDigitizer::Exec
virtual void Exec(Option_t *opt)
Definition
BmnScWallDigitizer.cxx:138
BmnScWallDigitizer::LoadConfig
InitStatus LoadConfig(const char *config)
Definition
BmnScWallDigitizer.cxx:37
BmnScWallDigitizer::fTimeCut
double fTimeCut
Definition
BmnScWallDigitizer.h:88
BmnScWallDigitizer::FillHitMap
void FillHitMap()
Definition
BmnScWallDigitizer.cxx:188
BmnScWallDigitizer::~BmnScWallDigitizer
virtual ~BmnScWallDigitizer()
Definition
BmnScWallDigitizer.cxx:105
BmnScWallDigitizer::fDigiArray
TClonesArray * fDigiArray
Definition
BmnScWallDigitizer.h:92
BmnScWallDigitizer::BmnScWallDigitizer
BmnScWallDigitizer(const int period)
Definition
BmnScWallDigitizer.cxx:18
BmnScWallDigitizer::Finish
virtual void Finish()
Definition
BmnScWallDigitizer.cxx:210
BmnScWallDigitizer::fPointArray
TClonesArray * fPointArray
Definition
BmnScWallDigitizer.h:91
BmnScWallDigitizer::fScale
double fScale
Definition
BmnScWallDigitizer.h:86
BmnScWallDigitizer::Init
virtual InitStatus Init()
Definition
BmnScWallDigitizer.cxx:114
BmnScWallDigitizer::fSiPM
SiPM fSiPM
Definition
BmnScWallDigitizer.h:89
BmnScWallDigitizer::fworkTime
float fworkTime
Definition
BmnScWallDigitizer.h:98
BmnScWallDigitizer::fThreshold
double fThreshold
Definition
BmnScWallDigitizer.h:87
BmnScWallPoint
Definition
BmnScWallPoint.h:19
FairTask
TClonesArray
TObjArray::At
TObject * At(Int_t idx) const override
TStopwatch
TStopwatch::RealTime
Double_t RealTime()
TStopwatch::Start
void Start(Bool_t reset=kTRUE)
TStopwatch::Stop
void Stop()
BmnScWallAddress.h
BmnScWallDigitizer.h
json.hpp
nlohmann::json
basic_json<> json
default specialization
Definition
json.hpp:3365
BmnScWallDigitizer::SiPM
Definition
BmnScWallDigitizer.h:26
detectors
scwall
BmnScWallDigitizer.cxx
Generated on
for BmnRoot by
1.17.0