ATLAS Offline Software
ZdcRecNoiseTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2019 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 //#include "Identifier/HWIdentifier.h"
25 
26 #include "GaudiKernel/IInterface.h"
27 #include "GaudiKernel/MsgStream.h"
28 
29 //#include "ZdcIdentifier/ZdcID.h"
30 #include "ZdcEvent/ZdcDigits.h"
32 #include "ZdcRec/ZdcRecNoiseTool.h"
33 
34 
35 
36 //==================================================================================================
37 const InterfaceID& ZdcRecNoiseTool::interfaceID()
38 {
39  return IID_IZdcRecNoiseTool;
40 
41 }
42 //==================================================================================================
43 
44 //==================================================================================================
46  const std::string& name,
47  const IInterface* parent) :
48 
50 
51 {
52  //Declare properties here...
53 
54  declareInterface<ZdcRecNoiseTool>(this);
55 
56  declareProperty("PedestalsDirectory", m_pedestalDir = "/afs/cern.ch/user/l/leite/public/ZdcData/Pedestals",
57  "Pedestal files directory");
58  declareProperty("PedestalsFile", m_pedestalFile = "zdc_pedestal_0000.data",
59  "Pedestal file name");
60 
61 }
62 //==================================================================================================
63 
64 //==================================================================================================
66 {
67 }
68 //==================================================================================================
69 
70 //==================================================================================================
72 {
74 
75  int nsamples = 0;
76  int i = 0;
77  unsigned int id;
78 
79  //Read the file name as passed to the tool for the pedestals
80  std::string str = m_pedestalDir + m_pedestalFile;
81  std::ifstream infile;
82 
83  infile.open(str.data(), std::ifstream::in);
84  if (infile.fail()) {
85  msg(MSG::ERROR) << "ZDC ---> No pedestal file available - aborting ";
86  return 0;
87  }
88  else {
89  infile >> nsamples;
90  std::vector<int> fadc00(nsamples);
91  std::vector<int> fadc01(nsamples);
92  std::vector<int> fadc10(nsamples);
93  std::vector<int> fadc11(nsamples);
94  int sz = sizeof(int)*nsamples;
95  i = 0;
96  while (infile.good()) {
97  infile.read ((char *)&id,sizeof(id));
98  infile.read ((char *)&fadc00[0],sz);
99  infile.read ((char *)&fadc01[0],sz);
100  infile.read ((char *)&fadc10[0],sz);
101  infile.read ((char *)&fadc11[0],sz);
102 
103  ZdcDigits* digits_p = new ZdcDigits(Identifier(id));
104  digits_p->set_digits_gain0_delay0(fadc00);
105  digits_p->set_digits_gain0_delay1(fadc01);
106  digits_p->set_digits_gain1_delay0(fadc10);
107  digits_p->set_digits_gain1_delay0(fadc11);
108  m_pedestalData->push_back(digits_p);
109  i++;
110  }
111  msg(MSG::INFO) << "ZDC ---> Read " << i << " pedestal channels from file" ;
112  }
113 return i;
114 }
115 //==================================================================================================
116 
117 //==================================================================================================
119 {
120  //remove this
122 
123  int nsamples = 0;
124  int i = 0;
125  unsigned int id;
126 
127  //Read the file name as passed to the tool for the pedestals
128  std::string str = m_pedestalDir + m_pedestalFile;
129  std::ofstream outfile;
130 
131  //TODO: First check if it exists, never overwrites
132  //TODO: Check if size of pedestal collection is ok
133 
134  outfile.open(str.data(), std::ofstream::out);
135  if (outfile.fail()) {
136  msg(MSG::ERROR) << "ZDC ---> Cannot create Pedestal File - aborting ";
137  return 0;
138  }
139  else {
140  std::vector<int> fadc00(nsamples);
141  std::vector<int> fadc01(nsamples);
142  std::vector<int> fadc10(nsamples);
143  std::vector<int> fadc11(nsamples);
144  outfile << nsamples;
145  int sz = sizeof(int)*nsamples;
146 
147  for (const ZdcDigits* p : *m_pedestalData) {
148  id = p->identify().get_identifier32().get_compact();
149  outfile.write((char *)&id, sizeof(id));
150 
151  fadc00 = p->get_digits_gain0_delay0();
152  fadc01 = p->get_digits_gain0_delay1();
153  fadc10 = p->get_digits_gain1_delay0();
154  fadc11 = p->get_digits_gain1_delay1();
155  outfile.write ((char *)&fadc00, sz);
156  outfile.write ((char *)&fadc01, sz);
157  outfile.write ((char *)&fadc10, sz);
158  outfile.write ((char *)&fadc11, sz);
159  i++;
160  }
161  }
162  return i;
163 }
164 
165 
166 
167 //==================================================================================================
168 //==================================================================================================
170 {
171  msg(MSG::INFO) << "Initializing " << name() << endmsg;
172 
173  //Get the pedestal information for the channels.
174  //For now, this is a file; later on it will be moved to a database
175 
176 
177  return StatusCode::SUCCESS;
178 }
179 //==================================================================================================
180 
181 //==================================================================================================
183 {
184  msg(MSG::INFO) << "Finalizing " << name() << endmsg;
185  return StatusCode::SUCCESS;
186 }
187 //==================================================================================================
ZdcRecNoiseTool::~ZdcRecNoiseTool
virtual ~ZdcRecNoiseTool()
Definition: ZdcRecNoiseTool.cxx:65
fitman.sz
sz
Definition: fitman.py:527
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
run.infile
string infile
Definition: run.py:13
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
ZdcRecNoiseTool::m_pedestalData
ZdcDigitsCollection * m_pedestalData
Definition: ZdcRecNoiseTool.h:59
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
ZdcDigits
Definition: ZdcDigits.h:28
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
ZdcRecNoiseTool::initialize
virtual StatusCode initialize()
Definition: ZdcRecNoiseTool.cxx:169
ZdcDigitsCollection.h
lumiFormat.i
int i
Definition: lumiFormat.py:92
ZdcRecNoiseTool::ZdcRecNoiseTool
ZdcRecNoiseTool(const std::string &type, const std::string &name, const IInterface *parent)
Definition: ZdcRecNoiseTool.cxx:45
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
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
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:71
ZdcRecNoiseTool::interfaceID
static const InterfaceID & interfaceID()
Definition: ZdcRecNoiseTool.cxx:37
id
SG::auxid_t id
Definition: Control/AthContainers/Root/debug.cxx:191
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
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:57
ZdcRecNoiseTool.h
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
ZdcRecNoiseTool::writePedestals
int writePedestals()
Definition: ZdcRecNoiseTool.cxx:118
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
ZdcDigitsCollection
Definition: ZdcDigitsCollection.h:20
ZdcRecNoiseTool::finalize
virtual StatusCode finalize()
Definition: ZdcRecNoiseTool.cxx:182
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:56