ATLAS Offline Software
LArAutoCorr2Ntuple.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
10 
11 LArAutoCorr2Ntuple::LArAutoCorr2Ntuple(const std::string& name, ISvcLocator* pSvcLocator)
12  : LArCond2NtupleBase(name, pSvcLocator)
13 {
14  declareProperty("Nsamples", m_nsamples=32);
15 
16  m_ntTitle="AutoCorrelation";
17  m_ntpath="/NTUPLES/FILE1/AUTOCORR";
18 
19 }
20 
24 }
25 
26 
27 
29  ATH_MSG_INFO( "LArAutoCorr2Ntuple in stop " << m_nt);
30  StatusCode sc;
31  NTuple::Array<float> cov;
32  NTuple::Item<long> gain, cellIndex;
33  NTuple::Item<long> corrUndo;
34  sc=m_nt->addItem("gain",gain,0,3);
35  if (sc!=StatusCode::SUCCESS) {
36  ATH_MSG_ERROR( "addItem 'gain' failed" );
37  return StatusCode::FAILURE;
38  }
39 
40  sc=m_nt->addItem("cellIndex",cellIndex,0,200000);
41  if (sc!=StatusCode::SUCCESS) {
42  ATH_MSG_ERROR( "addItem 'cellIndex' failed" );
43  return StatusCode::FAILURE;
44  }
45 
46  sc=m_nt->addItem("covr",m_nsamples-1,cov);
47  if (sc!=StatusCode::SUCCESS) {
48  ATH_MSG_ERROR( "addItem 'covr' failed" );
49  return StatusCode::FAILURE;
50  }
51 
52  sc=m_nt->addItem("corrUndo",corrUndo,0,2);
53  if (sc!=StatusCode::SUCCESS) {
54  ATH_MSG_ERROR( "addItem 'corrUndo' failed" );
55  return StatusCode::FAILURE;
56  }
57 
58  ATH_MSG_DEBUG( "LArAutoCorr2Ntuple reading container " << m_objKey.key());
59  // For compatibility with existing configurations, look in the detector
60  // store first, then in conditions.
61  const ILArAutoCorr* larAutoCorr=nullptr;
62  larAutoCorr = detStore()->tryConstRetrieve<ILArAutoCorr>(m_objKey.key());
63  if(!larAutoCorr) {
64  ATH_MSG_DEBUG( "No ILArAutoCorr found, trying LArAutoCorrComplete " << m_objKey.key());
65  const LArAutoCorrComplete *larComplete =
66  detStore()->tryConstRetrieve<LArAutoCorrComplete>(m_objKey.key());
67  if(larComplete) {
68  larAutoCorr = larComplete;
69  } else {
70  ATH_MSG_DEBUG( "LArAutoCorr2Ntuple reading conditions" );
72  larAutoCorr = *acHdl;
73  }
74  }
75 
76  if(larAutoCorr==nullptr){
77  ATH_MSG_ERROR( "Unable to retrieve ILArAutoCorr with key " << m_objKey.key() << " neither from DetectorStore neither from conditions" );
78  return StatusCode::FAILURE;
79  }
80  auto * larAutoCorr_c = dynamic_cast<const LArAutoCorrComplete*>(larAutoCorr);
81  if (not larAutoCorr_c) {
82  ATH_MSG_ERROR("Dynamic cast failed in LArAutoCorr2Ntuple::stop");
83  return StatusCode::FAILURE;
84  }
85  if (m_applyCorr) {
86  if (not larAutoCorr_c->correctionsApplied()) {
87  //ouch; but we are only in 'stop'
88  auto larAutoCorr_nc ATLAS_THREAD_SAFE = const_cast<LArAutoCorrComplete*>(larAutoCorr_c);
89  sc=larAutoCorr_nc->applyCorrections();
90  if (sc.isFailure()) {
91  ATH_MSG_ERROR( "Failed to apply corrections to LArCaliWaveContainer!" );
92  } else {
93  ATH_MSG_INFO( "Applied corrections to LArCaliWaveContainer" );
94  }
95  } else {
96  ATH_MSG_WARNING( "Corrections already applied. Can't apply twice!" );
97  }
98  }// end if applyCorr
99 
100  unsigned cellCounter=0;
101  unsigned cellZeroCounter=0;
103  for (HWIdentifier hwid : m_onlineId->channel_range()) {
104  ILArAutoCorr::AutoCorrRef_t corr=larAutoCorr->autoCorr(hwid,igain);
105  if (corr.size()>0) {
106  fillFromIdentifier(hwid);
107  gain = igain;
108  cellIndex = cellCounter;
109  for(unsigned i=0;i<m_nsamples-1 && i<corr.size();i++){
110  cov[i] = corr[i];
111  }
112  corrUndo=0;
113  sc = ntupleSvc()->writeRecord(m_nt);
114  if (sc!=StatusCode::SUCCESS) {
115  ATH_MSG_ERROR( "writeRecord failed" );
116  return StatusCode::FAILURE;
117  }
118  cellCounter++;
119  } else { ++cellZeroCounter;}//end if size>0
120  }//end if loop over cells
121  }//end if loop over gains
122 
123  if (m_addCorrUndo) {
125  LArAutoCorrComplete::ConstCorrectionIt itUndo=larAutoCorr_c->undoCorrBegin(igain);
126  LArAutoCorrComplete::ConstCorrectionIt itUndo_e=larAutoCorr_c->undoCorrEnd(igain);
127  for(;itUndo!=itUndo_e;++itUndo) {
128  const HWIdentifier hwid(itUndo->first);
129  const LArAutoCorrP1& ac = itUndo->second;
130  fillFromIdentifier(hwid);
131  for(unsigned i=0;i<m_nsamples-1 && i<ac.m_vAutoCorr.size();i++) cov[i] = ac.m_vAutoCorr[i];
132  gain=igain;
133  corrUndo=1;
134  sc = ntupleSvc()->writeRecord(m_nt);
135  if (sc!=StatusCode::SUCCESS) {
136  ATH_MSG_ERROR( "writeRecord failed" );
137  return StatusCode::FAILURE;
138  }
139  }
140  }//gain
141  }//if m_corrUndo
142 
143 
144  ATH_MSG_INFO( "LArAutoCorr2Ntuple has finished, " << cellCounter << "records written, " << cellZeroCounter << " zero length vectors" );
145  return StatusCode::SUCCESS;
146 }// end finalize-method.
147 
LArAutoCorr2Ntuple::m_applyCorr
BooleanProperty m_applyCorr
Definition: LArAutoCorr2Ntuple.h:46
LArAutoCorr2Ntuple::m_nsamples
unsigned m_nsamples
Definition: LArAutoCorr2Ntuple.h:50
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
LArAutoCorr2Ntuple::stop
virtual StatusCode stop()
Definition: LArAutoCorr2Ntuple.cxx:28
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
CaloCondBlobAlgs_fillNoiseFromASCII.gain
gain
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:110
LArAutoCorrP1
c-struct reproducing the structure of the persistent data
Definition: LArAutoCorrP1.h:25
plotBeamSpotVxVal.cov
cov
Definition: plotBeamSpotVxVal.py:201
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
HWIdentifier
Definition: HWIdentifier.h:13
CaloGain::LARNGAIN
@ LARNGAIN
Definition: CaloGain.h:19
LArCond2NtupleBase::initialize
StatusCode initialize()
Definition: LArCond2NtupleBase.cxx:33
LArCond2NtupleBase
Definition: LArCond2NtupleBase.h:32
ILArAutoCorr::autoCorr
virtual AutoCorrRef_t autoCorr(const HWIdentifier &CellID, int gain) const =0
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
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
ILArAutoCorr
This class defines the interface for accessing AutoCorrelation parameters for each channel @stereotyp...
Definition: ILArAutoCorr.h:29
LArAutoCorrComplete
This class implements the ILArAutoCorr interface.
Definition: LArAutoCorrComplete.h:26
LArConditionsContainer< LArAutoCorrP1 >::ConstCorrectionIt
Subset::ConstCorrectionVecIt ConstCorrectionIt
Definition: LArConditionsContainer.h:78
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:1932
lumiFormat.i
int i
Definition: lumiFormat.py:85
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
LArAutoCorr2Ntuple::m_addCorrUndo
BooleanProperty m_addCorrUndo
Definition: LArAutoCorr2Ntuple.h:47
LArAutoCorr2Ntuple::initialize
virtual StatusCode initialize()
Definition: LArAutoCorr2Ntuple.cxx:21
LArCond2NtupleBase::m_nt
NTuple::Tuple * m_nt
Definition: LArCond2NtupleBase.h:68
LArAutoCorr2Ntuple::LArAutoCorr2Ntuple
LArAutoCorr2Ntuple(const std::string &name, ISvcLocator *pSvcLocator)
Definition: LArAutoCorr2Ntuple.cxx:11
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
WriteCellNoiseToCool.igain
igain
Definition: WriteCellNoiseToCool.py:338
LArAutoCorr2Ntuple::m_objKey
SG::ReadCondHandleKey< ILArAutoCorr > m_objKey
Definition: LArAutoCorr2Ntuple.h:44
LArAutoCorrComplete.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
LArCond2NtupleBase::m_ntTitle
std::string m_ntTitle
Definition: LArCond2NtupleBase.h:65
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
LArCond2NtupleBase::m_onlineId
const LArOnlineID_Base * m_onlineId
Definition: LArCond2NtupleBase.h:85
CaloGain::LARHIGHGAIN
@ LARHIGHGAIN
Definition: CaloGain.h:18
LArAutoCorr2Ntuple.h
LArCond2NtupleBase::fillFromIdentifier
bool fillFromIdentifier(const HWIdentifier &id)
Definition: LArCond2NtupleBase.cxx:288
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
ATLAS_THREAD_SAFE
#define ATLAS_THREAD_SAFE
Definition: checker_macros.h:211
LArAutoCorrP1::m_vAutoCorr
std::vector< float > m_vAutoCorr
Definition: LArAutoCorrP1.h:31
CaloGain.h
ntupleSvc
INTupleSvc * ntupleSvc()
Definition: ServiceAccessor.h:14
StoreGateSvc.h
LArOnlineID.h
LArVectorProxy
Proxy for accessing a range of float values like a vector.
Definition: LArVectorProxy.h:38