ATLAS Offline Software
Loading...
Searching...
No Matches
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"
31
32namespace{
33 char *
34 charAddress(auto &v){
35 return reinterpret_cast<char *>(&v);
36 }
37}
38
39
40//==================================================================================================
41const InterfaceID& ZdcRecNoiseTool::interfaceID()
42{
44
45}
46//==================================================================================================
47
48//==================================================================================================
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//==================================================================================================
72//==================================================================================================
73
74//==================================================================================================
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 }
117return i;
118}
119//==================================================================================================
120
121//==================================================================================================
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//==================================================================================================
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//==================================================================================================
187{
188 msg(MSG::INFO) << "Finalizing " << name() << endmsg;
189 return StatusCode::SUCCESS;
190}
191//==================================================================================================
#define endmsg
static Double_t sz
static const InterfaceID IID_IZdcRecNoiseTool("ZdcRecNoiseTool", 1, 1)
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
MsgStream & msg() const
void set_digits_gain0_delay1(const std::vector< int > &v)
void set_digits_gain0_delay0(const std::vector< int > &v)
void set_digits_gain1_delay0(const std::vector< int > &v)
std::string m_pedestalDir
virtual StatusCode finalize()
virtual ~ZdcRecNoiseTool()
static const InterfaceID & interfaceID()
std::string m_pedestalFile
std::unique_ptr< ZdcDigitsCollection > m_pedestalData
virtual StatusCode initialize()
ZdcRecNoiseTool(const std::string &type, const std::string &name, const IInterface *parent)