ATLAS Offline Software
Loading...
Searching...
No Matches
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
7
8#include <fstream>
9
10LArPhysCaliTDiffAlg::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
20
21
23
24 m_ntTitle="TimeDiffs";
25 m_ntpath=std::string("/NTUPLES/FILE1/TIMEDIFF");
27}
28
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
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 );
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}
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
#define CHECK(...)
Evaluate an expression and check for errors.
static Double_t sc
INTupleSvc * ntupleSvc()
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
const ServiceHandle< StoreGateSvc > & detStore() const
bool fillFromIdentifier(const HWIdentifier &id)
LArCond2NtupleBase(const std::string &name, ISvcLocator *pSvcLocator)
void setGroupingType(GroupingType type)
allow group type to be set externally - need to (re)initialize after setting grouping type
ConditionsMap::const_iterator ConstConditionsMapIterator
virtual StatusCode initialize()
Initialization done after creation or read back - derived classes may augment the functionality.
ConstConditionsMapIterator begin(unsigned int gain) const
get iterator for all channels for a gain
ConstConditionsMapIterator end(unsigned int gain) const
end of all channels for this gain
std::string channel_name(const HWIdentifier id) const
Return a string corresponding to a feedthrough name given an identifier.
HWIdentifier feb_Id(int barrel_ec, int pos_neg, int feedthrough, int slot) const
Create feb_Id from fields.
bool isHECchannel(const HWIdentifier id) const override final
LArPhysCaliTDiffAlg(const std::string &name, ISvcLocator *pSvcLocator)
virtual ~LArPhysCaliTDiffAlg()
This class implements the ILArPhysCaliTdiff interface ` *.
void set(const HWIdentifier &CellID, int gain, float tdiff)