ATLAS Offline Software
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 
12 LArOFCBinAlg::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 
22 LArOFCBinAlg::~LArOFCBinAlg() = default;
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;
91 
92  LArOFCBinComplete* newCont=new LArOFCBinComplete();
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 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
LArFCAL_Base_ID
Definition: LArFCAL_Base_ID.h:19
LArOFCBinAlg::~LArOFCBinAlg
virtual ~LArOFCBinAlg()
LArOFCBinAlg::m_outputContainer
std::string m_outputContainer
Definition: LArOFCBinAlg.h:29
LArOFCBinP
Definition: LArOFCBinP.h:8
LArCond2NtupleBase::m_fcalId
const LArFCAL_Base_ID * m_fcalId
Definition: LArCond2NtupleBase.h:84
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
CaloCell_ID::em_idHelper
const LArEM_ID * em_idHelper() const
access to EM idHelper
Definition: CaloCell_ID.h:63
AtlasDetectorID::is_lar_fcal
bool is_lar_fcal(Identifier id) const
Definition: AtlasDetectorID.h:839
LArHEC_Base_ID
This class factors out code common between LArEM_ID and LArEM_SuperCell_ID.
Definition: LArHEC_Base_ID.h:44
LArEM_Base_ID
This class factors out code common between LArEM_ID and LArEM_SuperCell_ID.
Definition: LArEM_Base_ID.h:38
LArConditionsContainerBase::ExtendedSubDetGrouping
@ ExtendedSubDetGrouping
Definition: LArConditionsContainerBase.h:50
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
LArConditionsContainerDB::iteratorT
Declaration of const iterator.
Definition: LArConditionsContainerDB.h:72
CaloCondBlobAlgs_fillNoiseFromASCII.gain
gain
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:110
ReadCellNoiseFromCool.cabling
cabling
Definition: ReadCellNoiseFromCool.py:154
skel.it
it
Definition: skel.GENtoEVGEN.py:423
LArFCAL_Base_ID::module
int module(const Identifier id) const
module [1,3]
LArEM_Base_ID::sampling
int sampling(const Identifier id) const
return sampling according to :
LArOFCBinAlg::LArOFCBinAlg
LArOFCBinAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: LArOFCBinAlg.cxx:12
HWIdentifier
Definition: HWIdentifier.h:13
LArCond2NtupleBase::initialize
StatusCode initialize()
Definition: LArCond2NtupleBase.cxx:33
LArOnlineID_Base::barrel_ec
int barrel_ec(const HWIdentifier id) const
Return the position barrel or endcap of a hardware cell identifier: barrel_ec = [0,...
Definition: LArOnlineID_Base.cxx:1942
LArCond2NtupleBase::cablingKey
const SG::ReadCondHandleKey< LArOnOffIdMapping > & cablingKey() const
Definition: LArCond2NtupleBase.cxx:449
LArCond2NtupleBase
Definition: LArCond2NtupleBase.h:32
LArOFCBinAlg::m_perFebMG
bool m_perFebMG
Definition: LArOFCBinAlg.h:32
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
LArOFCBinP::m_bin
int m_bin
Definition: LArOFCBinP.h:12
CaloCell_ID.h
CaloCell_ID::hec_idHelper
const LArHEC_ID * hec_idHelper() const
access to HEC idHelper
Definition: CaloCell_ID.h:69
AthCommonDataStore< AthCommonMsg< Algorithm > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
tools.zlumi_mc_cf.correction
def correction(mu, runmode, campaign, run=None)
Definition: zlumi_mc_cf.py:4
LArOFCBinAlg::initialize
StatusCode initialize()
Definition: LArOFCBinAlg.cxx:25
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
LArConditionsContainer::end
ConstConditionsMapIterator end(unsigned int gain) const
end of all channels for this gain
LArOFCBinComplete.h
lumiFormat.i
int i
Definition: lumiFormat.py:92
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
LArCond2NtupleBase::m_ntpath
std::string m_ntpath
Definition: LArCond2NtupleBase.h:65
TRT::Hit::layer
@ layer
Definition: HitInfo.h:79
LArCond2NtupleBase::m_nt
NTuple::Tuple * m_nt
Definition: LArCond2NtupleBase.h:68
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
AtlasDetectorID::is_lar_hec
bool is_lar_hec(Identifier id) const
Definition: AtlasDetectorID.h:829
CaloCell_ID
Helper class for offline cell identifiers.
Definition: CaloCell_ID.h:34
LArOFCBinAlg::m_perFeb
bool m_perFeb
Definition: LArOFCBinAlg.h:33
LArOFCBinComplete
Definition: LArOFCBinComplete.h:13
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:1483
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
LArCond2NtupleBase::m_ntTitle
std::string m_ntTitle
Definition: LArCond2NtupleBase.h:65
LArOFCBinP::isEmpty
bool isEmpty() const
Definition: LArOFCBinP.h:12
LArOnlineID
Definition: LArOnlineID.h:20
LArOFCBinAlg::execute
StatusCode execute()
Definition: LArOFCBinAlg.cxx:36
LArCond2NtupleBase::fillFromIdentifier
bool fillFromIdentifier(const HWIdentifier &id)
Definition: LArCond2NtupleBase.cxx:288
LArConditionsContainer::initialize
virtual StatusCode initialize()
Initialization done after creation or read back - derived classes may augment the functionality.
LArHEC_Base_ID::sampling
int sampling(const Identifier id) const
return sampling [0,3] (only 0 for supercells)
LArConditionsContainer::begin
ConstConditionsMapIterator begin(unsigned int gain) const
get iterator for all channels for a gain
convertTimingResiduals.offset
offset
Definition: convertTimingResiduals.py:71
LArOFCBinAlg::m_fileName
std::string m_fileName
Definition: LArOFCBinAlg.h:30
LArOFCBinAlg::m_inputContainer
std::string m_inputContainer
Definition: LArOFCBinAlg.h:28
LArOFCBinComplete::set
void set(const HWIdentifier &chid, const int &gain, const int &bin)
Definition: LArOFCBinComplete.cxx:11
LArOFCBinAlg.h
Identifier::get_identifier32
Identifier32 get_identifier32(void) const
Get the 32-bit version Identifier, will be invalid if >32 bits needed.
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:218
LArCond2NtupleBase::m_hecId
const LArHEC_Base_ID * m_hecId
Definition: LArCond2NtupleBase.h:83
ntupleSvc
INTupleSvc * ntupleSvc()
Definition: ServiceAccessor.h:14
AtlasDetectorID::is_lar_em
bool is_lar_em(Identifier id) const
Definition: AtlasDetectorID.h:818
CaloCell_ID::fcal_idHelper
const LArFCAL_ID * fcal_idHelper() const
access to FCAL idHelper
Definition: CaloCell_ID.h:75
LArOnOffIdMapping
Definition: LArOnOffIdMapping.h:20
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37