ATLAS Offline Software
Loading...
Searching...
No Matches
LArOFCBinAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
8
9//#include <ifstream>
10#include <fstream>
11
12LArOFCBinAlg::LArOFCBinAlg(const std::string & name, ISvcLocator * pSvcLocator) :
13 LArCond2NtupleBase(name,pSvcLocator) {
14
15 declareProperty("InputContainer",m_inputContainer="LArOFCBinIn");
16 declareProperty("OutputContainer",m_outputContainer="LArOFCBin");
17 declareProperty("FileName",m_fileName);
18 declareProperty("PerFebMGCorr",m_perFebMG=true);
19 declareProperty("PerFebCorr",m_perFeb=false);
20}
21
23
24
26
27 //if(!m_perFebMG) {
28 // ATH_MSG_ERROR( "Not implemented yet....." );
29 // return StatusCode::FAILURE;
30 //}
31 m_ntTitle="Bin";
32 m_ntpath=std::string("/NTUPLES/FILE1/OFCBINDIFF");
34}
35
37
38
39 NTuple::Item<long> ntold, ntnew, ntcorr;
40 NTuple::Item<long> ntgain;
41
42 CHECK(m_nt->addItem("gain",ntgain,0,3));
43 CHECK(m_nt->addItem("OFCBinOld",ntold,-200,200));
44 CHECK(m_nt->addItem("OFCBinNew",ntnew,-200,200));
45 CHECK(m_nt->addItem("correction",ntcorr,0,200));
46
47
48 const LArOnlineID* onlineID=nullptr;
49 CHECK(detStore()->retrieve(onlineID));
50
51 std::vector<std::map<HWIdentifier,float> > offsetMap;
52 if(m_perFebMG) offsetMap.resize(2); else offsetMap.resize(3);
53 std::ifstream rein;
54 if(m_perFebMG || m_perFeb) {
55 rein.open(m_fileName.c_str(),std::ifstream::in);
56 if (!rein.good()) {
57 ATH_MSG_ERROR( "Failed to open file " << m_fileName );
58 return StatusCode::FAILURE;
59 }
60 }
61
62
63 if(m_perFebMG) {
64 while (rein.good()) {
65 unsigned chidint;
66 float offset;
67 rein >> std::hex>>chidint >>std::dec>> offset;
68 const HWIdentifier fid(chidint);
69 offsetMap[1][fid]=offset;
70 //std::cout <<std::hex<< fid <<std::dec<< " " << offset << std::endl;
71 }
72 } else if (m_perFeb) {
73 while (rein.good()) {
74 unsigned chidint;
75 float offset[3];
76 rein >> std::hex>>chidint >>std::dec>> offset[0] >>offset[1] >>offset[2];
77 // cppcheck-suppress identicalInnerCondition; false positive
78 if(rein.good()){
79 const HWIdentifier fid(chidint);
80 for(unsigned i=0; i<3; ++i) offsetMap[i][fid]=offset[i];
81 }
82 //std::cout <<std::hex<< fid <<std::dec<< " " << offset << std::endl;
83 }
84
85 }
86
87 rein.close();
88
89 const LArOFCBinComplete* oldCont=nullptr;
90 CHECK(detStore()->retrieve(oldCont,m_inputContainer));
91
94 CHECK(newCont->initialize());
95 StatusCode sc=detStore()->record(newCont,m_outputContainer);
96 if(sc!=StatusCode::SUCCESS) {
97 ATH_MSG_ERROR( "Failed to register container with key " << m_outputContainer << " to StoreGate" );
98 }
99
101 const LArOnOffIdMapping* cabling{*cablingHdl};
102 if(!cabling) {
103 ATH_MSG_ERROR( "Do not have cabling mapping from key " << cablingKey().key() );
104 return StatusCode::FAILURE;
105 }
106 const CaloCell_ID* idHelper = nullptr;
107 ATH_CHECK( detStore()->retrieve (idHelper, "CaloCell_ID") );
108 const LArEM_Base_ID* emId = idHelper->em_idHelper();
109 const LArHEC_Base_ID* hecId = idHelper->hec_idHelper();
110 const LArFCAL_Base_ID* fcalId = idHelper->fcal_idHelper();
111
112 for (int gain=0;gain<3;++gain) {
113 ATH_MSG_INFO( "Working on gain " << gain );
116 for (;it!=it_e;++it) {
117 const HWIdentifier chid=it.channelId();
118 const HWIdentifier fid=onlineID->feb_Id(chid);
119 const LArOFCBinP& td=*it;
120 if (td.isEmpty()) {
121 ATH_MSG_DEBUG("Channel " << onlineID->channel_name(chid) << " has no data");
122 continue;
123 }
124 int bindiff=td.m_bin;
125 ntold=bindiff;
126 if(m_perFebMG && gain != 1) {// do nothing if we are only correcting MG per FEB
127 newCont->set(chid,gain,bindiff);
128 continue;
129 }
130 if(!(m_perFebMG || m_perFeb)) {
131 // shift by 24 bins (for L1Calo purposes)
132 ntcorr=24;
133 bindiff-=ntcorr;
134 } else {
135 // Do not make corrections for back layer
136 int barrel_ec = onlineID->barrel_ec(chid);
137 int layer=-1;
138 if (cabling->isOnlineConnected(chid)) {
139 Identifier id=cabling->cnvToIdentifier(chid);
140 if (emId->is_lar_em(id)) {
141 layer = emId->sampling(id);
142 } else if (hecId->is_lar_hec(id)) {
143 layer = m_hecId->sampling(id);
144 } else if (fcalId->is_lar_fcal(id)) {
145 layer = m_fcalId->module(id);
146 }
147 }
148 if( m_perFebMG && (layer<0 || (barrel_ec ==0 && layer==3 )) ) {
149 std::cout<<"Skipping channel: "<<chid.get_identifier32()<<std::endl;
150 newCont->set(chid,gain,bindiff);
151 continue;
152 }
153
154 const float correction=offsetMap[gain][fid];
155 int mfac;
156 if(correction>0) mfac=1; else mfac=-1;
157 const int imult = correction / 1.042; // 25./24. = 1.042
158 if(fabs(correction - imult*1.042) < 0.5) ntcorr = imult; else ntcorr=(imult + mfac);
159 //std::cout<<bindiff<<" : "<<correction<< " "<<imult<<" : "<<ntcorr<<std::endl;
160 std::cout<<std::hex<<fid.get_identifier32()<<" "<<std::dec<<ntcorr<<std::endl;
161 bindiff-=ntcorr;
162 }
163
164 newCont->set(chid,gain,bindiff);
165 ntnew=bindiff;
166 fillFromIdentifier(chid);
167 ntgain=gain;
168 ATH_MSG_DEBUG("Gain " << gain << " Ch:" << onlineID->channel_name(chid) << ":" << td.m_bin << " -> " << bindiff);
169
170
171 sc=ntupleSvc()->writeRecord(m_nt);
172 if (sc!=StatusCode::SUCCESS) {
173 ATH_MSG_ERROR( "writeRecord failed" );
174 return StatusCode::FAILURE;
175 }
176
177 }//end loop over all channels
178 }//end loop over gains
179
180
181 return StatusCode::SUCCESS;
182}
#define ATH_CHECK
Evaluate an expression and check for errors.
#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 is_lar_em(Identifier id) const
bool is_lar_fcal(Identifier id) const
bool is_lar_hec(Identifier id) const
Helper class for offline cell identifiers.
Definition CaloCell_ID.h:34
const LArFCAL_ID * fcal_idHelper() const
access to FCAL idHelper
Definition CaloCell_ID.h:75
const LArEM_ID * em_idHelper() const
access to EM idHelper
Definition CaloCell_ID.h:63
const LArHEC_ID * hec_idHelper() const
access to HEC idHelper
Definition CaloCell_ID.h:69
Identifier32 get_identifier32() const
Get the 32-bit version Identifier, will be invalid if >32 bits needed.
const SG::ReadCondHandleKey< LArOnOffIdMapping > & cablingKey() const
const LArHEC_Base_ID * m_hecId
const LArFCAL_Base_ID * m_fcalId
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
This class factors out code common between LArEM_ID and LArEM_SuperCell_ID.
int sampling(const Identifier id) const
return sampling according to :
This class factors out code common between LArEM_ID and LArEM_SuperCell_ID.
std::string m_fileName
StatusCode execute()
std::string m_outputContainer
StatusCode initialize()
virtual ~LArOFCBinAlg()
LArOFCBinAlg(const std::string &name, ISvcLocator *pSvcLocator)
std::string m_inputContainer
void set(const HWIdentifier &chid, const int &gain, const int &bin)
bool isEmpty() const
Definition LArOFCBinP.h:12
int barrel_ec(const HWIdentifier id) const
Return the position barrel or endcap of a hardware cell identifier: barrel_ec = [0,...
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.