ATLAS Offline Software
LArCalibShortCorrector.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 //#include "GaudiKernel/MsgStream.h"
8 
14 #include <cmath>
15 
16 LArCalibShortCorrector::LArCalibShortCorrector(const std::string& name, ISvcLocator* pSvcLocator) :
17  AthAlgorithm(name, pSvcLocator),
18  m_onlineId(nullptr),
19  m_caloCellId(nullptr)
20 {
21  declareProperty("KeyList", m_keylist,
22  "List of input keys (normally the 'HIGH','MEDIUM','LOW')");
23  declareProperty("PedestalKey",m_pedKey="Pedestal",
24  "Key of the pedestal object (to be subtracted)");
25  m_shortsCached=false;
26 }
27 
29 
31  ATH_CHECK( m_BCKey.initialize() );
33  ATH_CHECK( detStore()->retrieve(m_onlineId, "LArOnlineID") );
34  ATH_CHECK( detStore()->retrieve(m_caloCellId, "CaloCell_ID") );
35  ATH_CHECK( detStore()->regHandle(m_larPedestal,m_pedKey) );
36  return StatusCode::SUCCESS;
37 }
38 
40  //The current implementation assumes that we have very few shorted cells.
41  //Currently we have 2 pairs (one in EMBA, one in EMBC).
42  //If we find more shorts, the simple, un-ordered vector and linear search should be
43  //replaced by something faster
45  const LArBadChannelCont* bcCont{*bcHdl};
46  if(!bcCont) {
47  ATH_MSG_ERROR( "Do not have bad channels !" );
48  return StatusCode::FAILURE;
49  }
51  const LArOnOffIdMapping* cabling{*cablingHdl};
52  if(!cabling) {
53  ATH_MSG_ERROR( "Do not have cabling object LArOnOffIdMapping");
54  return StatusCode::FAILURE;
55  }
56 
57  m_shortedNeighbors.clear();
58  //Loop over all identifers (maybe better if we would have a loop only over bad-cahnnels)
59  for (const HWIdentifier chid1 : m_onlineId->channel_range()) {
60  if (bcCont->status(chid1).shortProblem()) {
61  //Already found?
62  SHORT_IT sit=m_shortedNeighbors.begin();
63  SHORT_IT sit_e=m_shortedNeighbors.end();
64  for (;sit!=sit_e && sit->second!=chid1;++sit)
65  ;
66  if (sit!=sit_e) continue; //This short was already found as neighbor of another shorted cell
67 
68  const Identifier id1=cabling->cnvToIdentifier(chid1);
69  const IdentifierHash id1_h=m_caloCellId->calo_cell_hash(id1);
70  ATH_MSG_DEBUG ( "Channel " << chid1.get_compact() << " marked as short" );
71  //Find neighbor
72  std::vector<IdentifierHash> neighbors;
74  HWIdentifier chid2;
75  if (neighbors.empty()) {
76  ATH_MSG_ERROR ( "No neighbors found for channel with id " << m_onlineId->channel_name(chid1) );
77  return StatusCode::FAILURE;
78  }
79  else
80  ATH_MSG_DEBUG ( " Found " << neighbors.size() << " neighbors found for channel with id " << m_onlineId->channel_name(chid1) );
81 
82 
83  std::vector<IdentifierHash>::const_iterator nbrit=neighbors.begin();
84  std::vector<IdentifierHash>::const_iterator nbrit_e=neighbors.end();
85  for (;nbrit!=nbrit_e;++nbrit) {
86  const HWIdentifier chid_nbr=cabling->createSignalChannelIDFromHash(*nbrit);
87  if (bcCont->status(chid_nbr).shortProblem()) { //Found neighbor with 'short'
88  if (chid2.is_valid()) {
89  ATH_MSG_ERROR ( "Found more than one neighbor with short bit set! Identifiers: "
90  << m_onlineId->channel_name(chid1) << ", "
91  << m_onlineId->channel_name(chid2) << ", "
92  << m_onlineId->channel_name(chid_nbr) );
93  return StatusCode::FAILURE;
94  }
95  else {
96  chid2=chid_nbr;
97  ATH_MSG_DEBUG ( "Found pair " << m_onlineId->channel_name(chid1) << " " << m_onlineId->channel_name(chid2) );
98  }
99  }
100  }//End loop over neighbors
101  if (!chid2.is_valid()) {
102  ATH_MSG_ERROR ( "No neighbor with 'short' bit set for channel with id: " << chid1.get_compact() );
103  return StatusCode::FAILURE;
104  }
105  m_shortedNeighbors.emplace_back(chid1,chid2);
106  }//end this channel has a short
107  }//End loop over all identifiers
108 
109  if (msgLvl(MSG::INFO)) {
110  ATH_MSG_INFO ( "Found " << m_shortedNeighbors.size() << " pairs of shorted neighbors" );
111  for (const std::pair<HWIdentifier, HWIdentifier>& p : m_shortedNeighbors)
112  ATH_MSG_INFO ( " Shorted pair: " << m_onlineId->channel_name(p.first) << ", " << m_onlineId->channel_name(p.second) );
113  }
114 
115  return StatusCode::SUCCESS;
116 }
117 
118 
119 
121  if (!m_shortsCached){
123  m_shortsCached=true;
124  }
125  const size_t nShorts=m_shortedNeighbors.size();
126 
127  //Loop over all digits in all containers to find the shorted ones
128 
129  const LArAccumulatedCalibDigitContainer* larAccumulatedCalibDigitContainer;
130 
131  // now start to deal with digits
132 
133  for (const std::string& key : m_keylist) {
134  StatusCode sc = evtStore()->retrieve(larAccumulatedCalibDigitContainer,key);
135  if (sc.isFailure()){
136  ATH_MSG_WARNING ( "Cannot read LArAccumulatedCalibDigitContainer from StoreGate! key=" << key );
137  continue; // Try next container
138  }
139 
140 
141  std::vector<std::pair<const LArAccumulatedCalibDigit*, const LArAccumulatedCalibDigit*> > shortedDigits;
142  shortedDigits.resize(nShorts);
143 
144  LArAccumulatedCalibDigitContainer::const_iterator it=larAccumulatedCalibDigitContainer->begin();
145  LArAccumulatedCalibDigitContainer::const_iterator it_e=larAccumulatedCalibDigitContainer->end();
146  if(it == it_e) {
147  ATH_MSG_VERBOSE ( "LArAccumulatedCalibDigitContainer with key = " << key << " is empty " );
148  //return StatusCode::SUCCESS;
149  continue; // Try next container
150  } else {
151  ATH_MSG_DEBUG ( "Processing LArAccumulatedCalibDigitContainer with key = " << key
152  << ". Size: " << larAccumulatedCalibDigitContainer->size() );
153  }
154 
155  for(;it!=it_e;++it) { //Loop over calib-digits
156  const HWIdentifier chid=(*it)->hardwareID();
157  size_t ii;
158  for (ii=0;ii<nShorts;ii++)
159  if (m_shortedNeighbors[ii].first==chid || m_shortedNeighbors[ii].second==chid) break;
160  if (ii==nShorts) continue; //Not found on the list of shorts
161 
162  //Got a channel on the list of shorted channels: Remember their pointers!
163  if ((*it)->isPulsed())
164  shortedDigits[ii].first=*it;
165  else
166  shortedDigits[ii].second=*it;
167  }//end loop over cells
168 
169 
170  for (size_t ii=0;ii<nShorts;ii++) {
171  if (shortedDigits[ii].first==NULL) continue; //Not in the data at all, or only the not-pulsed channel in the data
172  if (shortedDigits[ii].second==NULL) { //Only the pulsed channel in the data
173  ATH_MSG_WARNING ( "Second channel of a shorted pair not found in data. Try factor 2 correction." );
174  shortedDigits[ii].second=shortedDigits[ii].first;
175  }
176 
177  const std::vector<uint64_t>& sampleSumsPulsed=shortedDigits[ii].first->sampleSum();
178  const std::vector<uint64_t>& sampleSumsNeighbor=shortedDigits[ii].second->sampleSum();
179 
180  std::vector<uint64_t> newSampleSum(sampleSumsPulsed.size());
181 
182 
183  if (sampleSumsPulsed.size() != sampleSumsNeighbor.size()) {
184  ATH_MSG_ERROR ( "Inconsistent size of samples-vector!" );
185  return StatusCode::FAILURE;
186  }
187 
188  if (shortedDigits[ii].first->nTriggers() != shortedDigits[ii].second->nTriggers()) {
189  ATH_MSG_ERROR ( "Inconsistent number of Triggers!" );
190  return StatusCode::FAILURE;
191  }
192 
193 
194  float pedestal = m_larPedestal->pedestal(shortedDigits[ii].second->hardwareID(),
195  shortedDigits[ii].second->gain());
196  if (pedestal<= (1.0+LArElecCalib::ERRORCODE)) {
197  ATH_MSG_ERROR ( "Failed to get pedestal for channel " << m_onlineId->channel_name(shortedDigits[ii].second->hardwareID())
198  << ", gain=" << shortedDigits[ii].second->gain() );
199  return StatusCode::FAILURE;
200  }
201  const unsigned int ped=(unsigned)round(double(pedestal)*shortedDigits[ii].second->nTriggers());
202 
203 
204  for (size_t is=0;is<sampleSumsPulsed.size();++is) {
205  //std::cout << "Sample #"<< is << "=" << sampleSumsPulsed[is] << "+" << sampleSumsNeighbor[ii] << "-" << ped << "=";
206  newSampleSum[is]=sampleSumsPulsed[is]+(sampleSumsNeighbor[is]-ped);
207  //std::cout << newSampleSum[is] << std::endl;
208  }
209  // FIXME: const_cast can change objects in SG.
210  const_cast<LArAccumulatedCalibDigit*>(shortedDigits[ii].first)->setSampleSum(newSampleSum);
211  }//end loop over pairs of shorted digits
212  }//end loop over container keys
213  return StatusCode::SUCCESS;
214 }
215 
216 
218  ATH_MSG_INFO ( "in stop." );
219  return StatusCode::SUCCESS;
220 }
221 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
ILArPedestal::pedestal
virtual float pedestal(const HWIdentifier &id, int gain) const =0
python.SystemOfUnits.second
int second
Definition: SystemOfUnits.py:120
LArAccumulatedCalibDigit
Data class for calibration ADC samples preprocessed by the DSP.
Definition: LArAccumulatedCalibDigit.h:42
LArCalibShortCorrector::m_cablingKey
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKey
Definition: LArCalibShortCorrector.h:43
LArCalibShortCorrector::m_BCKey
SG::ReadCondHandleKey< LArBadChannelCont > m_BCKey
Definition: LArCalibShortCorrector.h:42
LArCalibShortCorrector::m_keylist
std::vector< std::string > m_keylist
Definition: LArCalibShortCorrector.h:51
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
CaloCell_Base_ID::calo_cell_hash
IdentifierHash calo_cell_hash(const Identifier cellId) const
create hash id from 'global' cell id
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
LArBadChannel.h
LArBadXCont
Conditions-Data class holding LAr Bad Channel or Bad Feb information.
Definition: LArBadChannelCont.h:28
LArNeighbours::faces2D
@ faces2D
Definition: LArNeighbours.h:16
MuonGM::round
float round(const float toRound, const unsigned int decimals)
Definition: Mdt.cxx:27
ReadCellNoiseFromCool.cabling
cabling
Definition: ReadCellNoiseFromCool.py:154
skel.it
it
Definition: skel.GENtoEVGEN.py:423
LArCalibShortCorrector::m_shortsCached
bool m_shortsCached
Definition: LArCalibShortCorrector.h:58
AthCommonMsg< Algorithm >::msgLvl
bool msgLvl(const MSG::Level lvl) const
Definition: AthCommonMsg.h:30
LArCalibShortCorrector::execute
StatusCode execute()
Definition: LArCalibShortCorrector.cxx:120
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
LArCalibShortCorrector::m_larPedestal
const DataHandle< ILArPedestal > m_larPedestal
Definition: LArCalibShortCorrector.h:48
HWIdentifier
Definition: HWIdentifier.h:13
Identifier::is_valid
bool is_valid() const
Check if id is in a valid state.
xAOD::unsigned
unsigned
Definition: RingSetConf_v1.cxx:662
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
CaloCell_ID.h
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
AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
LArOnlineID_Base::channel_range
id_range channel_range() const
Definition: LArOnlineID_Base.cxx:1936
LArCalibShortCorrector::stop
StatusCode stop()
Definition: LArCalibShortCorrector.cxx:217
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
LArCalibShortCorrector::m_caloCellId
const CaloCell_ID * m_caloCellId
Definition: LArCalibShortCorrector.h:46
LArCalibShortCorrector::m_onlineId
const LArOnlineID * m_onlineId
Definition: LArCalibShortCorrector.h:45
LArAccumulatedCalibDigitContainer.h
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
LArCalibShortCorrector::initialize
StatusCode initialize()
Definition: LArCalibShortCorrector.cxx:30
LArCalibShortCorrector::m_shortedNeighbors
std::vector< std::pair< HWIdentifier, HWIdentifier > > m_shortedNeighbors
Definition: LArCalibShortCorrector.h:55
LArCalibShortCorrector.h
LArCalibShortCorrector::findShortedNeighbors
StatusCode findShortedNeighbors()
Definition: LArCalibShortCorrector.cxx:39
AthAlgorithm
Definition: AthAlgorithm.h:47
LArCalibShortCorrector::m_pedKey
std::string m_pedKey
Definition: LArCalibShortCorrector.h:52
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
CaloCell_Base_ID::get_neighbours
int get_neighbours(const IdentifierHash caloHash, const LArNeighbours::neighbourOption &option, std::vector< IdentifierHash > &neighbourList) const
access to hashes for neighbours return == 0 for neighbours found
Definition: CaloCell_Base_ID.cxx:190
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
LArCalibShortCorrector::LArCalibShortCorrector
LArCalibShortCorrector(const std::string &name, ISvcLocator *pSvcLocator)
Definition: LArCalibShortCorrector.cxx:16
Example_ReadSampleNoise.ped
ped
Definition: Example_ReadSampleNoise.py:45
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
DeMoScan.first
bool first
Definition: DeMoScan.py:534
LArElecCalib::ERRORCODE
@ ERRORCODE
Definition: LArCalibErrorCode.h:17
IdentifierHash
Definition: IdentifierHash.h:38
LArCalibShortCorrector::~LArCalibShortCorrector
~LArCalibShortCorrector()
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
CaloGain.h
LArAccumulatedCalibDigitContainer
Container class for LArAccumulatedCalibDigit.
Definition: LArAccumulatedCalibDigitContainer.h:25
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
LArCalibShortCorrector::SHORT_IT
std::vector< std::pair< HWIdentifier, HWIdentifier > >::const_iterator SHORT_IT
Definition: LArCalibShortCorrector.h:56
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
LArOnlineID.h
LArOnOffIdMapping
Definition: LArOnOffIdMapping.h:20
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37