ATLAS Offline Software
Loading...
Searching...
No Matches
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
11LArAutoCorr2Ntuple::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
22 ATH_CHECK(m_objKey.initialize());
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;
102 for ( unsigned igain=CaloGain::LARHIGHGAIN; igain<CaloGain::LARNGAIN ; ++igain ) {
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) {
124 for ( unsigned igain=CaloGain::LARHIGHGAIN; igain<CaloGain::LARNGAIN ; ++igain ) {
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
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
static Double_t sc
INTupleSvc * ntupleSvc()
#define ATLAS_THREAD_SAFE
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
const ServiceHandle< StoreGateSvc > & detStore() const
This class defines the interface for accessing AutoCorrelation parameters for each channel @stereotyp...
LArVectorProxy AutoCorrRef_t
virtual AutoCorrRef_t autoCorr(const HWIdentifier &CellID, int gain) const =0
BooleanProperty m_applyCorr
BooleanProperty m_addCorrUndo
LArAutoCorr2Ntuple(const std::string &name, ISvcLocator *pSvcLocator)
virtual StatusCode stop()
virtual StatusCode initialize()
SG::ReadCondHandleKey< ILArAutoCorr > m_objKey
This class implements the ILArAutoCorr interface.
c-struct reproducing the structure of the persistent data
std::vector< float > m_vAutoCorr
const LArOnlineID_Base * m_onlineId
bool fillFromIdentifier(const HWIdentifier &id)
LArCond2NtupleBase(const std::string &name, ISvcLocator *pSvcLocator)
Subset::ConstCorrectionVecIt ConstCorrectionIt
@ LARNGAIN
Definition CaloGain.h:19
@ LARHIGHGAIN
Definition CaloGain.h:18