ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
ForwardDetectors
ZDC
ZdcRec
src
ZdcRecNoiseTool.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
/*
6
* ZdcRecNoiseTool.cxx
7
*
8
* Pedestal calculation and retrieval from file or DB.
9
* Also used to study noise performance of the electronics
10
* Created on: Feb 18, 2010
11
* Author: leite
12
*/
13
14
15
16
#include <iostream>
17
#include <fstream>
18
19
#include <numeric>
20
#include <algorithm>
21
#include <vector>
22
#include <map>
23
24
25
#include "GaudiKernel/IInterface.h"
26
#include "GaudiKernel/MsgStream.h"
27
28
#include "
ZdcEvent/ZdcDigits.h
"
29
#include "
ZdcEvent/ZdcDigitsCollection.h
"
30
#include "
ZdcRec/ZdcRecNoiseTool.h
"
31
32
namespace
{
33
char
*
34
charAddress(
auto
&v){
35
return
reinterpret_cast<
char
*
>
(&
v
);
36
}
37
}
38
39
40
//==================================================================================================
41
const
InterfaceID&
ZdcRecNoiseTool::interfaceID
()
42
{
43
return
IID_IZdcRecNoiseTool
;
44
45
}
46
//==================================================================================================
47
48
//==================================================================================================
49
ZdcRecNoiseTool::ZdcRecNoiseTool
(
const
std::string&
type
,
50
const
std::string& name,
51
const
IInterface* parent) :
52
53
AthAlgTool
(
type
, name, parent)
54
55
{
56
//Declare properties here...
57
58
declareInterface<ZdcRecNoiseTool>(
this
);
59
60
declareProperty
(
"PedestalsDirectory"
,
m_pedestalDir
=
"/afs/cern.ch/user/l/leite/public/ZdcData/Pedestals"
,
61
"Pedestal files directory"
);
62
declareProperty
(
"PedestalsFile"
,
m_pedestalFile
=
"zdc_pedestal_0000.data"
,
63
"Pedestal file name"
);
64
65
}
66
//==================================================================================================
67
68
//==================================================================================================
69
ZdcRecNoiseTool::~ZdcRecNoiseTool
()
70
{
71
}
72
//==================================================================================================
73
74
//==================================================================================================
75
int
ZdcRecNoiseTool::readPedestals
()
76
{
77
m_pedestalData
= std::make_unique<ZdcDigitsCollection>();
78
79
int
nsamples = 0;
80
int
i = 0;
81
unsigned
int
id;
82
83
//Read the file name as passed to the tool for the pedestals
84
std::string
str
=
m_pedestalDir
+
m_pedestalFile
;
85
std::ifstream infile;
86
87
infile.open(
str
.data(), std::ifstream::in);
88
if
(infile.fail()) {
89
msg
(MSG::ERROR) <<
"ZDC ---> No pedestal file available - aborting "
;
90
return
0;
91
}
92
else
{
93
infile >> nsamples;
94
std::vector<int> fadc00(nsamples);
95
std::vector<int> fadc01(nsamples);
96
std::vector<int> fadc10(nsamples);
97
std::vector<int> fadc11(nsamples);
98
int
sz
=
sizeof
(int)*nsamples;
99
i = 0;
100
while
(infile.good()) {
101
infile.read (charAddress(
id
),
sizeof
(
id
));
102
infile.read (charAddress(fadc00[0]),
sz
);
103
infile.read (charAddress(fadc01[0]),
sz
);
104
infile.read (charAddress(fadc10[0]),
sz
);
105
infile.read (charAddress(fadc11[0]),
sz
);
106
107
ZdcDigits
* digits_p =
new
ZdcDigits
(
Identifier
(
id
));
108
digits_p->
set_digits_gain0_delay0
(fadc00);
109
digits_p->
set_digits_gain0_delay1
(fadc01);
110
digits_p->
set_digits_gain1_delay0
(fadc10);
111
digits_p->
set_digits_gain1_delay0
(fadc11);
112
m_pedestalData
->push_back(digits_p);
113
i++;
114
}
115
msg
(MSG::INFO) <<
"ZDC ---> Read "
<< i <<
" pedestal channels from file"
;
116
}
117
return
i;
118
}
119
//==================================================================================================
120
121
//==================================================================================================
122
int
ZdcRecNoiseTool::writePedestals
()
123
{
124
//remove this
125
m_pedestalData
= std::make_unique<ZdcDigitsCollection>();
126
127
int
nsamples = 0;
128
int
i = 0;
129
unsigned
int
id;
130
131
//Read the file name as passed to the tool for the pedestals
132
std::string
str
=
m_pedestalDir
+
m_pedestalFile
;
133
std::ofstream outfile;
134
135
//TODO: First check if it exists, never overwrites
136
//TODO: Check if size of pedestal collection is ok
137
138
outfile.open(
str
.data(), std::ofstream::out);
139
if
(outfile.fail()) {
140
msg
(MSG::ERROR) <<
"ZDC ---> Cannot create Pedestal File - aborting "
;
141
return
0;
142
}
143
else
{
144
std::vector<int> fadc00(nsamples);
145
std::vector<int> fadc01(nsamples);
146
std::vector<int> fadc10(nsamples);
147
std::vector<int> fadc11(nsamples);
148
outfile << nsamples;
149
int
sz
=
sizeof
(int)*nsamples;
150
151
for
(
const
ZdcDigits
* p : *
m_pedestalData
) {
152
id
= p->identify().get_identifier32().get_compact();
153
outfile.write(charAddress(
id
),
sizeof
(
id
));
154
155
fadc00 = p->get_digits_gain0_delay0();
156
fadc01 = p->get_digits_gain0_delay1();
157
fadc10 = p->get_digits_gain1_delay0();
158
fadc11 = p->get_digits_gain1_delay1();
159
outfile.write (charAddress(fadc00),
sz
);
160
outfile.write (charAddress(fadc01),
sz
);
161
outfile.write (charAddress(fadc10),
sz
);
162
outfile.write (charAddress(fadc11),
sz
);
163
i++;
164
}
165
}
166
return
i;
167
}
168
169
170
171
//==================================================================================================
172
//==================================================================================================
173
StatusCode
ZdcRecNoiseTool::initialize
()
174
{
175
msg
(MSG::INFO) <<
"Initializing "
<< name() <<
endmsg
;
176
177
//Get the pedestal information for the channels.
178
//For now, this is a file; later on it will be moved to a database
179
180
181
return
StatusCode::SUCCESS;
182
}
183
//==================================================================================================
184
185
//==================================================================================================
186
StatusCode
ZdcRecNoiseTool::finalize
()
187
{
188
msg
(MSG::INFO) <<
"Finalizing "
<< name() <<
endmsg
;
189
return
StatusCode::SUCCESS;
190
}
191
//==================================================================================================
endmsg
#define endmsg
Definition
AnalysisConfig_Ntuple.cxx:54
sz
static Double_t sz
Definition
LArPhysWaveHECTool.cxx:37
ZdcDigitsCollection.h
ZdcDigits.h
ZdcRecNoiseTool.h
IID_IZdcRecNoiseTool
static const InterfaceID IID_IZdcRecNoiseTool("ZdcRecNoiseTool", 1, 1)
AthAlgTool::AthAlgTool
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
Definition
AthAlgTool.cxx:16
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
Definition
AthCommonDataStore.h:145
AthCommonMsg< AlgTool >::msg
MsgStream & msg() const
Definition
AthCommonMsg.h:24
ZdcDigits
Definition
ZdcDigits.h:28
ZdcDigits::set_digits_gain0_delay1
void set_digits_gain0_delay1(const std::vector< int > &v)
Definition
ZdcDigits.cxx:129
ZdcDigits::set_digits_gain0_delay0
void set_digits_gain0_delay0(const std::vector< int > &v)
Definition
ZdcDigits.cxx:124
ZdcDigits::set_digits_gain1_delay0
void set_digits_gain1_delay0(const std::vector< int > &v)
Definition
ZdcDigits.cxx:134
ZdcRecNoiseTool::m_pedestalDir
std::string m_pedestalDir
Definition
ZdcRecNoiseTool.h:54
ZdcRecNoiseTool::finalize
virtual StatusCode finalize()
Definition
ZdcRecNoiseTool.cxx:186
ZdcRecNoiseTool::~ZdcRecNoiseTool
virtual ~ZdcRecNoiseTool()
Definition
ZdcRecNoiseTool.cxx:69
ZdcRecNoiseTool::interfaceID
static const InterfaceID & interfaceID()
Definition
ZdcRecNoiseTool.cxx:41
ZdcRecNoiseTool::m_pedestalFile
std::string m_pedestalFile
Definition
ZdcRecNoiseTool.h:55
ZdcRecNoiseTool::m_pedestalData
std::unique_ptr< ZdcDigitsCollection > m_pedestalData
Definition
ZdcRecNoiseTool.h:57
ZdcRecNoiseTool::readPedestals
int readPedestals()
Definition
ZdcRecNoiseTool.cxx:75
ZdcRecNoiseTool::writePedestals
int writePedestals()
Definition
ZdcRecNoiseTool.cxx:122
ZdcRecNoiseTool::initialize
virtual StatusCode initialize()
Definition
ZdcRecNoiseTool.cxx:173
ZdcRecNoiseTool::ZdcRecNoiseTool
ZdcRecNoiseTool(const std::string &type, const std::string &name, const IInterface *parent)
Definition
ZdcRecNoiseTool.cxx:49
Identifier
Definition
IdentifierFieldParser.cxx:14
python.PyAthena.v
v
Definition
PyAthena.py:153
str
Definition
BTagTrackIpAccessor.cxx:11
type
Generated on
for ATLAS Offline Software by
1.17.0