ATLAS Offline Software
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"
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 //==================================================================================================
50  const std::string& name,
51  const IInterface* parent) :
52 
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 //==================================================================================================
70 {
71 }
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  }
117 return 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 //==================================================================================================
ZdcRecNoiseTool::~ZdcRecNoiseTool
virtual ~ZdcRecNoiseTool()
Definition: ZdcRecNoiseTool.cxx:69
fitman.sz
sz
Definition: fitman.py:527
run.infile
string infile
Definition: run.py:13
ZdcDigits
Definition: ZdcDigits.h:28
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:70
ZdcRecNoiseTool::initialize
virtual StatusCode initialize()
Definition: ZdcRecNoiseTool.cxx:173
ZdcDigitsCollection.h
ZdcRecNoiseTool::m_pedestalData
std::unique_ptr< ZdcDigitsCollection > m_pedestalData
Definition: ZdcRecNoiseTool.h:57
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:209
lumiFormat.i
int i
Definition: lumiFormat.py:85
ZdcRecNoiseTool::ZdcRecNoiseTool
ZdcRecNoiseTool(const std::string &type, const std::string &name, const IInterface *parent)
Definition: ZdcRecNoiseTool.cxx:49
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
Definition: AthCommonDataStore.h:145
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ZdcDigits::set_digits_gain1_delay0
void set_digits_gain1_delay0(const std::vector< int > &v)
Definition: ZdcDigits.cxx:134
ZdcRecNoiseTool::readPedestals
int readPedestals()
Definition: ZdcRecNoiseTool.cxx:75
ZdcRecNoiseTool::interfaceID
static const InterfaceID & interfaceID()
Definition: ZdcRecNoiseTool.cxx:41
id
SG::auxid_t id
Definition: Control/AthContainers/Root/debug.cxx:239
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
ZdcDigits.h
ZdcDigits::set_digits_gain0_delay1
void set_digits_gain0_delay1(const std::vector< int > &v)
Definition: ZdcDigits.cxx:129
ReadOfcFromCool.nsamples
nsamples
Definition: ReadOfcFromCool.py:115
ZdcRecNoiseTool::m_pedestalFile
std::string m_pedestalFile
Definition: ZdcRecNoiseTool.h:55
python.PyAthena.v
v
Definition: PyAthena.py:154
ZdcRecNoiseTool.h
python.CaloAddPedShiftConfig.int
int
Definition: CaloAddPedShiftConfig.py:45
python.Constants.INFO
int INFO
Definition: Control/AthenaCommon/python/Constants.py:15
ZdcRecNoiseTool::writePedestals
int writePedestals()
Definition: ZdcRecNoiseTool.cxx:122
ZdcDigits::set_digits_gain0_delay0
void set_digits_gain0_delay0(const std::vector< int > &v)
Definition: ZdcDigits.cxx:124
AthCommonMsg< AlgTool >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
ZdcRecNoiseTool::finalize
virtual StatusCode finalize()
Definition: ZdcRecNoiseTool.cxx:186
str
Definition: BTagTrackIpAccessor.cxx:11
AthAlgTool
Definition: AthAlgTool.h:26
PrepareReferenceFile.outfile
outfile
Definition: PrepareReferenceFile.py:42
ZdcRecNoiseTool::m_pedestalDir
std::string m_pedestalDir
Definition: ZdcRecNoiseTool.h:54
Identifier
Definition: IdentifierFieldParser.cxx:14