BmnRoot
26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Toggle main menu visibility
Loading...
Searching...
No Matches
BmnEcalDigitizer.cxx
Go to the documentation of this file.
1
/*
2
* File: BmnEcalDigitizer.cxx
3
* Author: Petr Alekseev
4
*
5
* Created on 05.08.2020, 19:31
6
*/
7
8
#include "
BmnEcalDigitizer.h
"
9
10
#include "
BmnEcalPoint.h
"
11
#include "FairLogger.h"
12
#include "FairRootManager.h"
13
#include "
TGeoManager.h
"
14
15
#include <iostream>
16
17
BmnEcalDigitizer::BmnEcalDigitizer
() {}
18
19
BmnEcalDigitizer::~BmnEcalDigitizer
() {}
20
21
InitStatus
BmnEcalDigitizer::Init
()
22
{
23
24
FairRootManager* ioman = FairRootManager::Instance();
25
fArrayOfEcalPoints
= (
TClonesArray
*)ioman->GetObject(
"EcalPoint"
);
26
if
(
fArrayOfEcalPoints
==
nullptr
) {
27
LOG(error) <<
"BmnEcalDigitizer::Init() branch 'EcalPoint' not found! Task will be deactivated"
;
28
SetActive(
kFALSE
);
29
return
kERROR;
30
}
31
32
fArrayOfEcalDigits
=
new
TClonesArray
(
"BmnECALDigit"
);
33
ioman->Register(
"EcalDigit"
,
"Ecal"
,
fArrayOfEcalDigits
,
kTRUE
);
34
35
if
(
LoadGeometry
() != 0) {
36
SetActive(
kFALSE
);
37
return
kERROR;
38
}
39
40
Info
(__func__,
"ECAL digitizer ready"
);
41
return
kSUCCESS;
42
}
43
44
void
BmnEcalDigitizer::Exec
(
Option_t
* opt)
45
{
46
if
(!IsActive())
47
return
;
48
49
// Initialize
50
fArrayOfEcalDigits
->Delete();
51
52
for
(
Int_t
i
= 0;
i
<
fCellsSize
;
i
++) {
53
fCells
[
i
].SetAmp(0.);
54
fCells
[
i
].SetStartTime(0.);
55
}
56
57
// Collect points
58
Int_t
N =
fArrayOfEcalPoints
->GetEntries();
59
for
(
Int_t
i
= 0;
i
< N;
i
++) {
60
BmnEcalPoint
* p = (
BmnEcalPoint
*)
fArrayOfEcalPoints
->At(
i
);
61
62
Int_t
ch = p->
GetCopyMother
();
63
if
(ch <
fCellsSize
) {
64
if
(
fCells
[ch].GetChannel() == ch) {
65
Float_t
energyLoss = p->GetEnergyLoss();
66
if
(energyLoss > 0) {
67
Float_t
pointTime = p->GetTime();
68
if
(
fMaxPointTime
> 0 && pointTime >
fMaxPointTime
)
69
continue
;
70
if
(
fFiberSOL
> 0.) {
71
pointTime += (
fFiberLength
-
fLayerThickness
* (p->
GetCopy
() + 1)) /
fFiberSOL
;
72
}
73
fCells
[ch].SetAmp(
fCells
[ch].GetAmp() + energyLoss);
74
fCells
[ch].SetStartTime(
fCells
[ch].GetStartTime() + pointTime * energyLoss);
75
}
76
}
else
{
77
Error
(__func__,
"ECAL ch %d was not initialized"
, ch);
78
}
79
}
else
{
80
Error
(__func__,
"ECAL ch %d ignored"
, ch);
81
}
82
}
83
84
// Store digits
85
for
(
Int_t
i
= 0;
i
<
fCellsSize
;
i
++) {
86
if
(
fCells
[
i
].GetChannel() !=
i
)
87
continue
;
88
89
Float_t
amp =
fCells
[
i
].GetAmp() * 1000.;
90
91
if
(amp == 0.)
92
continue
;
93
if
(amp <
fThreshold
)
94
continue
;
95
96
Float_t
time =
fCells
[
i
].GetStartTime() /
fCells
[
i
].GetAmp();
97
98
BmnECALDigit
* p =
new
((*fArrayOfEcalDigits)[
fArrayOfEcalDigits
->GetEntriesFast()])
BmnECALDigit
();
99
*p =
fCells
[
i
];
100
p->
SetAmp
(amp);
101
p->
SetPeakAmp
(amp);
102
p->
SetStartTime
(time);
103
p->
SetPeakTime
(time +
fPeakTimeDelay
);
104
}
105
}
106
107
void
BmnEcalDigitizer::Print
(
Option_t
* option)
const
108
{
109
110
printf(
"\n"
111
"\e[1;92m"
);
112
printf(
"BMN ECAL Digitizer\n"
);
113
printf(
"ECAL geometry fileN: %s\n"
,
fEcalGeometryFileName
);
114
printf(
"ECAL interaction depth shift: %f\n"
,
fDepthShift
);
115
printf(
"ECAL cells coords (((\n"
);
116
Float_t
x, y, z;
117
for
(
Int_t
i
= 1;
i
<
fCellsSize
;
i
++) {
118
if
(
fCells
[
i
].GetChannel() ==
i
) {
119
fCells
[
i
].GetLabCoords(x, y, z);
120
printf(
" % 4d [%3.0f,%3.0f] -> [%7.2f,%7.2f,%7.2f]\n"
,
i
,
fCells
[
i
].GetX(),
fCells
[
i
].GetY(), x, y, z);
121
}
else
{
122
// printf(" % 04d - Not initialized\n", i);
123
}
124
}
125
printf(
"))) ECAL cells coords\n"
);
126
printf(
"\e[0m"
127
"\n"
);
128
}
129
130
int
BmnEcalDigitizer::LoadGeometry
()
131
{
132
Bool_t
loadFromFile =
fEcalGeometryFileName
!=
nullptr
;
133
TGeoNode
*ecal1 = 0, *ecal2 = 0;
134
if
(
gGeoManager
) {
135
TGeoVolume
* ecal =
gGeoManager
->FindVolumeFast(
"ecal"
);
136
if
(ecal) {
137
if
(ecal->
GetNdaughters
() > 0)
138
ecal1 = ecal->
GetNode
(0);
139
if
(ecal->
GetNdaughters
() > 1)
140
ecal2 = ecal->
GetNode
(1);
141
loadFromFile =
kFALSE
;
142
}
else
{
143
Info
(__func__,
"Ecal geometry not found by TGeoManager\n"
);
144
}
145
}
146
147
if
(loadFromFile) {
148
Info
(__func__,
"Loading coordinates of ECAL cells from %s\n"
,
fEcalGeometryFileName
);
149
TGeoVolume
* top =
TGeoVolume::Import
(
fEcalGeometryFileName
,
"TOP"
);
150
151
if
(!top) {
152
LOG(error) <<
"<BmnEcalDigitizer::LoadGeometry>: Volume TOP not found in "
153
<< (
fEcalGeometryFileName
==
nullptr
?
"(null)"
:
fEcalGeometryFileName
);
154
// Fatal(__func__, "Volume TOP not found in %s\n", fEcalGeometryFileName);
155
return
-1;
156
}
157
158
TGeoNode
* ecal = top->
GetNode
(0);
159
160
if
(!ecal
/*|| ecal->GetNdaughters() < 2*/
) {
161
LOG(error) <<
"<BmnEcalDigitizer::LoadGeometry>: Unexpected geometry structure "
162
<< (
fEcalGeometryFileName
==
nullptr
?
"(null)"
:
fEcalGeometryFileName
);
163
// Fatal(__func__, "Unexpected geometry structure %s\n",fEcalGeometryFileName);
164
return
-1;
165
}
166
ecal1 = ecal->
GetDaughter
(0);
167
ecal2 = ecal->
GetDaughter
(1);
168
}
169
170
if
(ecal1 == 0 && ecal2 == 0) {
171
Info
(__func__,
"BmnEcalDigitizer was set in inactive state, because ECAL geometry was not found"
);
172
return
-1;
173
}
174
175
for
(
Int_t
i
= 0;
i
<
fCellsSize
;
i
++) {
176
fCells
[
i
].SetChannel(0);
177
}
178
179
Double_t
coords[] = {0., 0., 0.};
180
Double_t
ecalCoords[3];
181
Double_t
labCoords[3];
182
183
coords[2] =
fDepthShift
;
184
185
if
(ecal1) {
186
Int_t
n
= ecal1->
GetNdaughters
();
187
if
(
n
> 504) {
188
LOG(error) <<
"<BmnEcalDigitizer::LoadGeometry>: Expected ecal node 1 with 504 daughters or less in "
189
<< (
fEcalGeometryFileName
==
nullptr
?
"(null)"
:
fEcalGeometryFileName
);
190
return
-1;
191
}
192
for
(
Int_t
i
= 0;
i
<
n
;
i
++) {
193
Int_t
ch = ecal1->
GetDaughter
(
i
)->
GetNumber
();
194
if
(ch < 1 || ch > 504) {
195
LOG(error) <<
"<BmnEcalDigitizer::LoadGeometry>: Unexpected chan "
<< ch <<
" at ecal node 1 in "
196
<< (
fEcalGeometryFileName
==
nullptr
?
"(null)"
:
fEcalGeometryFileName
);
197
return
-1;
198
}
199
ecal1->
GetDaughter
(
i
)->
LocalToMaster
(coords, ecalCoords);
200
ecal1->
LocalToMaster
(ecalCoords, labCoords);
201
fCells
[ch].SetChannel(ch);
202
fCells
[ch].SetX(ecalCoords[0]);
203
fCells
[ch].SetY(ecalCoords[1]);
204
fCells
[ch].SetLabCoords(labCoords[0], labCoords[1], labCoords[2]);
205
}
206
}
207
208
if
(ecal2) {
209
Int_t
n
= ecal2->GetNdaughters();
210
if
(
n
> 504) {
211
LOG(error) <<
"<BmnEcalDigitizer::LoadGeometry>: Expected ecal node 2 with 504 daughters or less in "
212
<< (
fEcalGeometryFileName
==
nullptr
?
"(null)"
:
fEcalGeometryFileName
);
213
return
-1;
214
}
215
for
(
Int_t
i
= 0;
i
<
n
;
i
++) {
216
Int_t
ch = ecal2->GetDaughter(
i
)->GetNumber();
217
if
(ch < 505 || ch > 1008) {
218
LOG(error) <<
"<BmnEcalDigitizer::LoadGeometry>: Unexpected chan="
<< ch <<
" at ecal node 2 in "
219
<< (
fEcalGeometryFileName
==
nullptr
?
"(null)"
:
fEcalGeometryFileName
);
220
return
-1;
221
}
222
ecal2->GetDaughter(
i
)->LocalToMaster(coords, ecalCoords);
223
ecal2->LocalToMaster(ecalCoords, labCoords);
224
fCells
[ch].SetChannel(ch);
225
fCells
[ch].SetX(ecalCoords[0]);
226
fCells
[ch].SetY(ecalCoords[1]);
227
fCells
[ch].SetLabCoords(labCoords[0], labCoords[1], labCoords[2]);
228
}
229
}
230
231
return
0;
232
}
i
int i
Definition
P4_F32vec4.h:22
Bool_t
bool Bool_t
Int_t
int Int_t
Float_t
float Float_t
kFALSE
constexpr Bool_t kFALSE
Double_t
double Double_t
kTRUE
constexpr Bool_t kTRUE
Option_t
const char Option_t
Info
void Info(const char *location, const char *msgfmt,...)
Error
void Error(const char *location, const char *msgfmt,...)
TGeoManager.h
gGeoManager
R__EXTERN TGeoManager * gGeoManager
BmnCaloDigit::SetAmp
void SetAmp(Float_t amp)
Definition
BmnCaloDigit.h:29
BmnECALDigit
Definition
BmnECALDigit.h:48
BmnECALDigit::SetPeakAmp
void SetPeakAmp(Float_t amp)
Definition
BmnECALDigit.h:67
BmnECALDigit::SetPeakTime
void SetPeakTime(Float_t ns)
Definition
BmnECALDigit.h:68
BmnECALDigit::SetStartTime
void SetStartTime(Float_t ns)
Definition
BmnECALDigit.h:69
BmnEcalDigitizer::fMaxPointTime
Float_t fMaxPointTime
Definition
BmnEcalDigitizer.h:89
BmnEcalDigitizer::fFiberLength
Float_t fFiberLength
Definition
BmnEcalDigitizer.h:93
BmnEcalDigitizer::fDepthShift
Float_t fDepthShift
Definition
BmnEcalDigitizer.h:87
BmnEcalDigitizer::fEcalGeometryFileName
const char * fEcalGeometryFileName
Definition
BmnEcalDigitizer.h:86
BmnEcalDigitizer::LoadGeometry
int LoadGeometry()
Definition
BmnEcalDigitizer.cxx:130
BmnEcalDigitizer::Exec
virtual void Exec(Option_t *opt)
Definition
BmnEcalDigitizer.cxx:44
BmnEcalDigitizer::fArrayOfEcalPoints
TClonesArray * fArrayOfEcalPoints
Definition
BmnEcalDigitizer.h:99
BmnEcalDigitizer::Init
virtual InitStatus Init()
Definition
BmnEcalDigitizer.cxx:21
BmnEcalDigitizer::BmnEcalDigitizer
BmnEcalDigitizer()
Definition
BmnEcalDigitizer.cxx:17
BmnEcalDigitizer::fLayerThickness
Float_t fLayerThickness
Definition
BmnEcalDigitizer.h:94
BmnEcalDigitizer::Print
virtual void Print(Option_t *option="") const
Definition
BmnEcalDigitizer.cxx:107
BmnEcalDigitizer::~BmnEcalDigitizer
virtual ~BmnEcalDigitizer()
Definition
BmnEcalDigitizer.cxx:19
BmnEcalDigitizer::fArrayOfEcalDigits
TClonesArray * fArrayOfEcalDigits
Definition
BmnEcalDigitizer.h:100
BmnEcalDigitizer::fPeakTimeDelay
Float_t fPeakTimeDelay
Definition
BmnEcalDigitizer.h:90
BmnEcalDigitizer::fThreshold
Float_t fThreshold
Definition
BmnEcalDigitizer.h:88
BmnEcalDigitizer::fFiberSOL
Float_t fFiberSOL
Definition
BmnEcalDigitizer.h:92
BmnEcalDigitizer::fCellsSize
const Int_t fCellsSize
Definition
BmnEcalDigitizer.h:97
BmnEcalDigitizer::fCells
BmnECALDigit fCells[1024]
Definition
BmnEcalDigitizer.h:96
BmnEcalPoint
Definition
BmnEcalPoint.h:18
BmnEcalPoint::GetCopy
Short_t GetCopy() const
Accessors.
Definition
BmnEcalPoint.h:54
BmnEcalPoint::GetCopyMother
Short_t GetCopyMother() const
Definition
BmnEcalPoint.h:55
TClonesArray
TGeoNode
TGeoNode::GetNdaughters
Int_t GetNdaughters() const
TGeoNode::GetDaughter
TGeoNode * GetDaughter(Int_t ind) const
TGeoNode::LocalToMaster
virtual void LocalToMaster(const Double_t *local, Double_t *master) const
TGeoNode::GetNumber
Int_t GetNumber() const
TGeoVolume
TGeoVolume::GetNdaughters
Int_t GetNdaughters() const
TGeoVolume::GetNode
TGeoNode * GetNode(const char *name) const
TGeoVolume::Import
static TGeoVolume * Import(const char *filename, const char *name="", Option_t *option="")
BmnEcalDigitizer.h
BmnEcalPoint.h
n
*brief user defined string literal for JSON values *sa std::size_t n
Definition
json.hpp:20362
detectors
ecal
BmnEcalDigitizer.cxx
Generated on
for BmnRoot by
1.17.0