ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
LArCalorimeter
LArCalibTools
src
LArPhysCaliTDiffAlg.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
#include "
LArCalibTools/LArPhysCaliTDiffAlg.h
"
6
#include "
LArRawConditions/LArPhysCaliTdiffComplete.h
"
7
8
#include <fstream>
9
10
LArPhysCaliTDiffAlg::LArPhysCaliTDiffAlg
(
const
std::string & name, ISvcLocator * pSvcLocator) :
11
LArCond2NtupleBase
(name,pSvcLocator) {
12
13
declareProperty
(
"InputContainer"
,
m_inputContainer
=
"LArPhysCaliTdiffIn"
);
14
declareProperty
(
"OutputContainer"
,
m_outputContainer
=
"LArPhysCaliTdiff"
);
15
declareProperty
(
"FileName"
,
m_fileName
);
16
declareProperty
(
"PerFebMGCorr"
,
m_perFebMG
=
false
);
17
}
18
19
LArPhysCaliTDiffAlg::~LArPhysCaliTDiffAlg
() =
default
;
20
21
22
StatusCode
LArPhysCaliTDiffAlg::initialize
() {
23
24
m_ntTitle
=
"TimeDiffs"
;
25
m_ntpath
=std::string(
"/NTUPLES/FILE1/TIMEDIFF"
);
26
return
LArCond2NtupleBase::initialize
();
27
}
28
29
StatusCode
LArPhysCaliTDiffAlg::execute
(
const
EventContext&
/*ctx*/
) {
30
31
32
NTuple::Item<float> ntold, ntnew, ntoffset, ntcorr;
33
NTuple::Item<long> ntgain;
34
35
CHECK
(
m_nt
->addItem(
"gain"
,ntgain,0,3));
36
CHECK
(
m_nt
->addItem(
"PCDiffOld"
,ntold,-200,200));
37
CHECK
(
m_nt
->addItem(
"PCDiffNew"
,ntnew,-200,200));
38
if
(!
m_perFebMG
)
CHECK
(
m_nt
->addItem(
"offset"
,ntoffset,0,200));
39
CHECK
(
m_nt
->addItem(
"correction"
,ntcorr,0,200));
40
41
42
const
LArOnlineID
* onlineID=
nullptr
;
43
CHECK
(
detStore
()->retrieve(onlineID));
44
45
std::vector<std::map<HWIdentifier,float> > offsetMap;
46
if
(
m_perFebMG
) offsetMap.resize(2);
else
offsetMap.resize(3);
47
std::ifstream rein(
m_fileName
.c_str(),std::ifstream::in);
48
if
(!rein.good()) {
49
ATH_MSG_ERROR
(
"Failed to open file "
<<
m_fileName
);
50
return
StatusCode::SUCCESS;
51
}
52
53
54
while
(rein.good()) {
55
unsigned
gain,chidint;
56
float
offset;
57
if
(
m_perFebMG
) {
58
rein >> std::hex>>chidint >>std::dec>> offset;
59
const
HWIdentifier
fid(chidint);
60
offsetMap[1][fid]=offset;
61
//std::cout <<std::hex<< fid <<std::dec<< " " << offset << std::endl;
62
}
else
{
63
rein >> chidint >> gain >> offset;
64
const
HWIdentifier
fid(chidint);
65
if
(gain >= offsetMap.size()) {
66
ATH_MSG_ERROR
(
"Read bad gain: "
<< gain);
67
return
StatusCode::FAILURE;
68
}
69
offsetMap[gain][fid]=offset;
70
}
71
}
72
73
rein.close();
74
75
const
LArPhysCaliTdiffComplete* oldCont=
nullptr
;
76
CHECK
(
detStore
()->retrieve(oldCont,
m_inputContainer
));
77
78
LArPhysCaliTdiffComplete* newCont=
new
LArPhysCaliTdiffComplete();
79
newCont->setGroupingType(
LArConditionsContainerBase::ExtendedSubDetGrouping
);
80
CHECK
(newCont->initialize());
81
StatusCode
sc
=
detStore
()->record(newCont,
m_outputContainer
);
82
if
(
sc
!=StatusCode::SUCCESS) {
83
ATH_MSG_ERROR
(
"Failed to register container with key "
<<
m_outputContainer
<<
" to StoreGate"
);
84
}
85
86
for
(
int
gain=0;gain<3;++gain) {
87
ATH_MSG_INFO
(
"Working on gain "
<< gain );
88
LArPhysCaliTdiffComplete::ConstConditionsMapIterator it=oldCont->begin(gain);
89
LArPhysCaliTdiffComplete::ConstConditionsMapIterator it_e=oldCont->end(gain);
90
for
(;it!=it_e;++it) {
91
const
HWIdentifier
chid=it.channelId();
92
const
HWIdentifier
fid=onlineID->
feb_Id
(chid);
93
const
LArPhysCaliTdiffP
& td=*it;
94
if
(td.
isEmpty
()) {
95
ATH_MSG_DEBUG
(
"Channel "
<< onlineID->
channel_name
(chid) <<
" has no data"
);
96
continue
;
97
}
98
float
timediff=td.
m_Tdiff
;
99
ntold=timediff;
100
if
(
m_perFebMG
&& gain != 1) {
// do nothing if we are only correcting MG per FEB
101
newCont->set(chid,gain,timediff);
102
continue
;
103
}
104
if
(!
m_perFebMG
) {
105
ntoffset=offsetMap[gain][fid];
106
int
refGain=0;
107
if
(onlineID->
isHECchannel
(chid)) refGain=1;
108
109
if
(gain>refGain) {
110
ntcorr=offsetMap[gain][fid]-offsetMap[refGain][fid];
111
const
float
correction=offsetMap[gain][fid]-offsetMap[refGain][fid];
112
timediff+=correction;
113
}
else
ntcorr=-999;
114
}
else
{
115
ntcorr=offsetMap[gain][fid];
116
const
float
correction=offsetMap[gain][fid];
117
timediff+=correction;
118
}
119
120
newCont->set(chid,gain,timediff);
121
ntnew=timediff;
122
fillFromIdentifier
(chid);
123
ntgain=gain;
124
ATH_MSG_DEBUG
(
"Gain "
<< gain <<
" Ch:"
<< onlineID->
channel_name
(chid) <<
":"
<< td.
m_Tdiff
<<
" -> "
<< timediff);
125
126
127
sc
=
ntupleSvc
()->writeRecord(
m_nt
);
128
if
(
sc
!=StatusCode::SUCCESS) {
129
ATH_MSG_ERROR
(
"writeRecord failed"
);
130
return
StatusCode::FAILURE;
131
}
132
133
}
//end loop over all channels
134
std::cout<<
"2"
<<std::endl;
135
}
//end loop over gains
136
137
138
return
StatusCode::SUCCESS;
139
}
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition
AthMsgStreamMacros.h:33
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition
AthMsgStreamMacros.h:31
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition
Control/AthenaKernel/AthenaKernel/errorcheck.h:422
LArPhysCaliTDiffAlg.h
LArPhysCaliTdiffComplete.h
sc
static Double_t sc
Definition
LArPhysWaveHECTool.cxx:37
ntupleSvc
INTupleSvc * ntupleSvc()
Definition
ServiceAccessor.h:14
AthCommonAlgorithm< Gaudi::Algorithm >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
Definition
AthCommonDataStore.h:145
AthCommonAlgorithm< Gaudi::Algorithm >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
Definition
AthCommonDataStore.h:95
HWIdentifier
Definition
HWIdentifier.h:13
LArCond2NtupleBase::initialize
StatusCode initialize()
Definition
LArCond2NtupleBase.cxx:33
LArCond2NtupleBase::m_ntTitle
std::string m_ntTitle
Definition
LArCond2NtupleBase.h:68
LArCond2NtupleBase::m_nt
NTuple::Tuple * m_nt
Definition
LArCond2NtupleBase.h:71
LArCond2NtupleBase::m_ntpath
std::string m_ntpath
Definition
LArCond2NtupleBase.h:68
LArCond2NtupleBase::fillFromIdentifier
bool fillFromIdentifier(const HWIdentifier &id)
Definition
LArCond2NtupleBase.cxx:290
LArCond2NtupleBase::LArCond2NtupleBase
LArCond2NtupleBase(const std::string &name, ISvcLocator *pSvcLocator)
Definition
LArCond2NtupleBase.cxx:15
LArConditionsContainerBase::ExtendedSubDetGrouping
@ ExtendedSubDetGrouping
Definition
LArConditionsContainerBase.h:50
LArOnlineID_Base::channel_name
std::string channel_name(const HWIdentifier id) const
Return a string corresponding to a feedthrough name given an identifier.
Definition
LArOnlineID_Base.cxx:223
LArOnlineID_Base::feb_Id
HWIdentifier feb_Id(int barrel_ec, int pos_neg, int feedthrough, int slot) const
Create feb_Id from fields.
Definition
LArOnlineID_Base.cxx:1194
LArOnlineID
Definition
LArOnlineID.h:21
LArOnlineID::isHECchannel
bool isHECchannel(const HWIdentifier id) const override final
Definition
LArOnlineID.cxx:533
LArPhysCaliTDiffAlg::execute
StatusCode execute(const EventContext &ctx)
Execute method.
Definition
LArPhysCaliTDiffAlg.cxx:29
LArPhysCaliTDiffAlg::initialize
StatusCode initialize()
Definition
LArPhysCaliTDiffAlg.cxx:22
LArPhysCaliTDiffAlg::LArPhysCaliTDiffAlg
LArPhysCaliTDiffAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition
LArPhysCaliTDiffAlg.cxx:10
LArPhysCaliTDiffAlg::m_fileName
std::string m_fileName
Definition
LArPhysCaliTDiffAlg.h:28
LArPhysCaliTDiffAlg::m_outputContainer
std::string m_outputContainer
Definition
LArPhysCaliTDiffAlg.h:27
LArPhysCaliTDiffAlg::m_inputContainer
std::string m_inputContainer
Definition
LArPhysCaliTDiffAlg.h:26
LArPhysCaliTDiffAlg::m_perFebMG
bool m_perFebMG
Definition
LArPhysCaliTDiffAlg.h:30
LArPhysCaliTDiffAlg::~LArPhysCaliTDiffAlg
virtual ~LArPhysCaliTDiffAlg()
LArPhysCaliTdiffP
Definition
LArPhysCaliTdiffP.h:11
LArPhysCaliTdiffP::isEmpty
bool isEmpty() const
Definition
LArPhysCaliTdiffP.h:17
LArPhysCaliTdiffP::m_Tdiff
float m_Tdiff
Definition
LArPhysCaliTdiffP.h:18
Generated on
for ATLAS Offline Software by
1.17.0