BmnRoot
26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Toggle main menu visibility
Loading...
Searching...
No Matches
BmnBdDigitizer.cxx
Go to the documentation of this file.
1
// -------------------------------------------------------------------------
2
// ----- BmnBdDigitizer source file -----
3
// ----- Created 11/04/22 by S. Merts -----
4
// ----- Updated 11/04/25 by N. Lashmanov -----
5
// -------------------------------------------------------------------------
6
7
#include "
BmnBdDigitizer.h
"
8
9
#include "
BmnBdPoint.h
"
10
#include "BmnTrigDigit.h"
11
#include "FairRootManager.h"
12
#include "
TClonesArray.h
"
13
#include "
TMath.h
"
14
#include "
TRandom3.h
"
15
16
#include <iostream>
17
#include <map>
18
19
using namespace
std
;
20
using namespace
TMath
;
21
22
static
Double_t
workTime
= 0.0;
23
24
// Default constructor for BmnBdDigitizer.
25
BmnBdDigitizer::BmnBdDigitizer
()
26
:
FairTask
(
"Bmn BD Digitizer"
)
27
,
fPointArray
(nullptr)
28
,
fDigitArray
(nullptr)
29
,
fNMod
(40)
30
,
fNoiseSigma
(0.00001)
31
,
// Default noise level (GeV)
32
fThreshold
(0.0004)
33
,
// Default signal threshold (GeV)
34
fFiredChannels
(0)
35
{}
36
37
// Destructor for BmnBdDigitizer.
38
BmnBdDigitizer::~BmnBdDigitizer
()
39
{
40
if
(
fDigitArray
) {
41
delete
fDigitArray
;
42
fDigitArray
=
nullptr
;
43
}
44
}
45
46
// Converts amplitude (GeV) to signal duration (ns).
47
Double_t
BmnBdDigitizer::ConvertAmplitudeToTime
(
Double_t
amplitude)
48
{
49
50
const
Double_t
eMin = 0.0003;
// 300 keV in GeV
51
const
Double_t
eMax = 0.05;
// 50 MeV in GeV
52
const
Double_t
tMin = 6.0;
// ns
53
const
Double_t
tMax = 18.0;
// ns
54
55
// Linear interpolation
56
if
(amplitude <= eMin)
57
return
tMin;
58
if
(amplitude >= eMax)
59
return
tMax;
60
61
Double_t
fraction = (amplitude - eMin) / (eMax - eMin);
62
Double_t
timeNs = tMin + fraction * (tMax - tMin);
63
return
timeNs;
64
}
65
66
InitStatus
BmnBdDigitizer::Init
()
67
{
68
// Get RootManager
69
FairRootManager* ioman = FairRootManager::Instance();
70
if
(!ioman) {
71
cout <<
"-E- BmnBdDigitizer::Init: RootManager not instantiated!"
<< endl;
72
return
kFATAL;
73
}
74
75
// Get input array
76
fPointArray
= (
TClonesArray
*)ioman->GetObject(
"BdPoint"
);
77
if
(!
fPointArray
) {
78
cout <<
"-E- BmnBdDigitizer::Init: Branch BdPoint not found! Task will be deactivated"
<< endl;
79
SetActive(
kFALSE
);
80
return
kERROR;
81
}
82
83
// Create and register output array
84
fDigitArray
=
new
TClonesArray
(
"BmnTrigDigit"
);
85
ioman->Register(
"BdDigit"
,
"BD"
,
fDigitArray
,
kTRUE
);
86
87
if
(fVerbose)
88
cout <<
"BmnBdDigitizer::Init() finished successfully\n"
;
89
return
kSUCCESS;
90
}
91
92
// Executes the digitization process for each event.
93
void
BmnBdDigitizer::Exec
(
Option_t
* opt)
94
{
95
if
(!IsActive())
96
return
;
97
98
TStopwatch
sw;
99
sw.
Start
();
100
101
// Check output array
102
if
(!
fDigitArray
)
103
Fatal
(
"Exec"
,
"No BdDigit array"
);
104
105
// Reset output array
106
fDigitArray
->Delete();
107
fFiredChannels
= 0;
108
109
// Map for storing energies at modules
110
map<Int_t, pair<Double_t, Double_t>> ampTimeMap;
111
112
// Random number generator for noise
113
TRandom3
rand(0);
114
115
// Loop over MCPoints
116
for
(
Int_t
iPoint = 0; iPoint <
fPointArray
->GetEntriesFast(); iPoint++) {
117
BmnBdPoint
* point = (
BmnBdPoint
*)
fPointArray
->At(iPoint);
118
if
(!point)
119
continue
;
120
121
Int_t
mod = point->
GetCopy
() - 1;
122
123
// Validate module number
124
if
(mod < 0 || mod >=
fNMod
) {
125
if
(fVerbose)
126
cout <<
"-W- BmnBdDigitizer::Exec: Invalid module number "
<< mod << endl;
127
continue
;
128
}
129
130
// Add energy loss with noise
131
Double_t
energyLoss = point->GetEnergyLoss();
132
Double_t
noise = rand.
Gaus
(0,
fNoiseSigma
);
133
Double_t
totalEnergy = energyLoss + noise;
134
Double_t
time = point->GetTime();
135
136
auto
it = ampTimeMap.find(mod);
137
if
(it != ampTimeMap.end()) {
138
it->second.first += totalEnergy;
139
if
(time < it->second.second)
140
it->second.second = time;
141
}
else
{
142
ampTimeMap[mod] = {totalEnergy, time};
143
}
144
}
145
146
// Create digits for modules with energy above threshold
147
for
(
auto
mit : ampTimeMap) {
148
if
(mit.second.first <
fThreshold
)
149
continue
;
// Skip signals below threshold
150
151
BmnTrigDigit
digi;
152
digi.
SetMod
((
Short_t
)mit.first);
153
Double_t
duration =
ConvertAmplitudeToTime
(mit.second.first);
154
digi.
SetAmp
(duration);
155
digi.
SetTime
(mit.second.second);
156
// digi.SetFiredChannels(fFiredChannels + 1);
157
new
((*fDigitArray)[
fDigitArray
->GetEntriesFast()])
BmnTrigDigit
(digi);
158
fFiredChannels
++;
// Increment fired channels counter
159
}
160
161
if
(fVerbose) {
162
// printf("Number of BmnBdPoints = %d\n", fPointArray->GetEntriesFast());
163
// printf("Number of BmnBdDigits = %d\n", fDigitArray->GetEntriesFast());
164
// printf("Number of BmnBdDigits = %d\n", fFiredChannels);
165
// cout << "BmnBdDigitizer::Exec() finished\n";
166
}
167
168
sw.
Stop
();
169
workTime
+= sw.
RealTime
();
170
}
171
172
// Finalizes the digitizer task.
173
void
BmnBdDigitizer::Finish
()
174
{
175
printf(
"Work time of the BD digitizer: %.4f sec.\n"
,
workTime
);
176
}
workTime
static Double_t workTime
Definition
BmnBdDigitizer.cxx:22
Int_t
int Int_t
Short_t
short Short_t
kFALSE
constexpr Bool_t kFALSE
Double_t
double Double_t
kTRUE
constexpr Bool_t kTRUE
Option_t
const char Option_t
TClonesArray.h
Fatal
void Fatal(const char *location, const char *msgfmt,...)
TMath.h
TRandom3.h
BmnBdDigitizer::fFiredChannels
Int_t fFiredChannels
Definition
BmnBdDigitizer.h:41
BmnBdDigitizer::fNMod
Int_t fNMod
Definition
BmnBdDigitizer.h:38
BmnBdDigitizer::fPointArray
TClonesArray * fPointArray
Input array of BmnBdPoints.
Definition
BmnBdDigitizer.h:30
BmnBdDigitizer::Init
virtual InitStatus Init()
Virtual method Init.
Definition
BmnBdDigitizer.cxx:66
BmnBdDigitizer::~BmnBdDigitizer
~BmnBdDigitizer()
Destructor.
Definition
BmnBdDigitizer.cxx:38
BmnBdDigitizer::fDigitArray
TClonesArray * fDigitArray
Output array of BmnBdDigits.
Definition
BmnBdDigitizer.h:33
BmnBdDigitizer::fThreshold
Double_t fThreshold
Definition
BmnBdDigitizer.h:40
BmnBdDigitizer::fNoiseSigma
Double_t fNoiseSigma
Definition
BmnBdDigitizer.h:39
BmnBdDigitizer::ConvertAmplitudeToTime
Double_t ConvertAmplitudeToTime(Double_t amplitude)
Definition
BmnBdDigitizer.cxx:47
BmnBdDigitizer::Finish
virtual void Finish()
Definition
BmnBdDigitizer.cxx:173
BmnBdDigitizer::BmnBdDigitizer
BmnBdDigitizer()
Default constructor.
Definition
BmnBdDigitizer.cxx:25
BmnBdDigitizer::Exec
virtual void Exec(Option_t *opt)
Virtual method Exec.
Definition
BmnBdDigitizer.cxx:93
BmnBdPoint
Definition
BmnBdPoint.h:17
BmnBdPoint::GetCopy
Short_t GetCopy() const
Accessors.
Definition
BmnBdPoint.h:61
BmnTrigDigit
Definition
BmnTrigDigit.h:7
BmnTrigDigit::SetTime
void SetTime(Double_t time)
Definition
BmnTrigDigit.h:27
BmnTrigDigit::SetMod
void SetMod(Short_t mod)
Definition
BmnTrigDigit.h:25
BmnTrigDigit::SetAmp
void SetAmp(Double_t amp)
Definition
BmnTrigDigit.h:23
FairTask
TClonesArray
TRandom3
TRandom::Gaus
virtual Double_t Gaus(Double_t mean=0, Double_t sigma=1)
TStopwatch
TStopwatch::RealTime
Double_t RealTime()
TStopwatch::Start
void Start(Bool_t reset=kTRUE)
TStopwatch::Stop
void Stop()
BmnBdDigitizer.h
BmnBdPoint.h
TMath
std
Definition
json.hpp:4446
detectors
bd
BmnBdDigitizer.cxx
Generated on
for BmnRoot by
1.17.0