ATLAS Offline Software
Loading...
Searching...
No Matches
LArCaliWaves2Ntuple.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
4
7
8LArCaliWaves2Ntuple::LArCaliWaves2Ntuple(const std::string& name, ISvcLocator* pSvcLocator): LArWaves2Ntuple(name, pSvcLocator)
9{
10 m_keylist.clear() ;
11 declareProperty("KeyList", m_keylist);
12 declareProperty("DACSaturSkip", m_dacSaturSkip=false);
13 declareProperty("SaveJitter", m_saveJitter=false);
14 declareProperty("NtupleName", m_ntName="DELAYS");
15 declareProperty("NtupleFile", m_ntFile= "FILE1");
16 m_dacSaturLayer0.resize(0);
17 m_dacSaturLayer1.resize(0);
18 m_dacSaturLayer2.resize(0);
19 m_dacSaturLayer3.resize(0);
20 declareProperty("DACSaturPS", m_dacSaturLayer0);
21 declareProperty("DACSaturStrips",m_dacSaturLayer1);
22 declareProperty("DACSaturMiddle",m_dacSaturLayer2);
23 declareProperty("DACSaturBack", m_dacSaturLayer3);
24 declareProperty("AddCorrUndo", m_addCorrUndo=true);
25 declareProperty("ApplyCorrection",m_applyCorr=false);
26
27
28}
29
31 m_ntTitle="Calibration Wave";
32 m_ntpath=std::string("/NTUPLES/")+m_ntFile+std::string("/")+m_ntName;
33
34 if (! m_addCalib) {
35 //This dumper needs the calib-line-map anyway, even if the calib-line id is not dumped to the ntuple
36 //init the handle from the base-class here ... if not done by the base-class
37 ATH_CHECK( m_calibMapSCKey.initialize(m_isSC));
38 ATH_CHECK( m_calibMapKey.initialize(!m_isSC));
39 }
40
41
43}
44
46= default;
47
48StatusCode LArCaliWaves2Ntuple::stop ATLAS_NOT_THREAD_SAFE ()
49{
50
51 // Check DACSatur jobOption consistency, in case setup default values
52 if ( m_dacSaturSkip && m_dacSaturLayer0.size()<3 ) {
53 ATH_MSG_WARNING( "DACSaturPS jobOption has wrong size. Will use default." ) ;
54 m_dacSaturLayer0.resize(3);
55 m_dacSaturLayer0[0] = 15000 ;
56 m_dacSaturLayer0[1] = 50000 ;
57 m_dacSaturLayer0[2] = 65000 ;
58 }
59 if ( m_dacSaturSkip && m_dacSaturLayer1.size()<3 ) {
60 ATH_MSG_WARNING( "DACSaturStrips jobOption has wrong size. Will use default." ) ;
61 m_dacSaturLayer1.resize(3);
62 m_dacSaturLayer1[0] = 800 ;
63 m_dacSaturLayer1[1] = 8000 ;
64 m_dacSaturLayer1[2] = 65000 ;
65 }
66 if ( m_dacSaturSkip && m_dacSaturLayer2.size()<3 ) {
67 ATH_MSG_WARNING( "DACSaturMiddle jobOption has wrong size. Will use default." ) ;
68 m_dacSaturLayer2.resize(3);
69 m_dacSaturLayer2[0] = 1000 ;
70 m_dacSaturLayer2[1] = 10000 ;
71 m_dacSaturLayer2[2] = 65000 ;
72 }
73 if ( m_dacSaturSkip && m_dacSaturLayer3.size()<3 ) {
74 ATH_MSG_WARNING( "DACSaturBack jobOption has wrong size. Will use default." ) ;
75 m_dacSaturLayer3.resize(3);
76 m_dacSaturLayer3[0] = 800 ;
77 m_dacSaturLayer3[1] = 8000 ;
78 m_dacSaturLayer3[2] = 65000 ;
79 }
80
81 StatusCode sc;
82 sc=m_nt->addItem("DAC",m_dac,0,600000);
83 if (sc!=StatusCode::SUCCESS) {
84 ATH_MSG_ERROR( "addItem 'DAC' failed" );
85 return StatusCode::FAILURE;
86 }
87
88 sc=m_nt->addItem("gain",m_gain,0,3);
89 if (sc!=StatusCode::SUCCESS) {
90 ATH_MSG_ERROR( "addItem 'gain' failed" );
91 return StatusCode::FAILURE;
92 }
93
94 if (m_addCalib) {
95 sc=m_nt->addItem("isPulsed",m_isPulsed);
96 if (sc!=StatusCode::SUCCESS) {
97 ATH_MSG_ERROR( "addItem 'isPulsed' failed" );
98 return StatusCode::FAILURE;
99 }
100 sc=m_nt->addItem("nPulsedCalibLines",m_nPulsedCalibLines,0,4);
101 if (sc!=StatusCode::SUCCESS) {
102 ATH_MSG_ERROR( "addItem 'nPulsedCalibLines' failed" );
103 return StatusCode::FAILURE;
104 }
105
106 sc=m_nt->addItem("pulsedCalibLines",4,m_pulsedCalibLines);
107 if (sc!=StatusCode::SUCCESS) {
108 ATH_MSG_ERROR( "addItem 'pulsedCalibLines' failed" );
109 return StatusCode::FAILURE;
110 }
111 }
112
113 if (m_saveJitter) {
114 sc=m_nt->addItem("Jitter",m_jitter,0.,1.);
115 if (sc!=StatusCode::SUCCESS) {
116 ATH_MSG_ERROR( "addItem 'Jitter' failed" );
117 return StatusCode::FAILURE;
118 }
119 }
120
121 if (m_addCorrUndo) {
122 sc=m_nt->addItem("corrUndo",m_corrUndo,0,1);
123 if (sc!=StatusCode::SUCCESS) {
124 ATH_MSG_ERROR( "addItem 'corrUndo' failed" );
125 return StatusCode::FAILURE;
126 }
127 }
128
129
130 const LArCalibLineMapping *clCont=nullptr;
131 if(m_isSC) {
132 ATH_MSG_DEBUG( "LArCaliWaves2Ntuple: using SC calib map" );
133 SG::ReadCondHandle<LArCalibLineMapping> clHdl{m_calibMapSCKey};
134 clCont=*clHdl;
135 } else {
136 SG::ReadCondHandle<LArCalibLineMapping> clHdl{m_calibMapKey};
137 clCont=*clHdl;
138 }
139
140 if(!clCont) {
141 ATH_MSG_WARNING( "Do not have calib line mapping !!!" );
142 return StatusCode::FAILURE;
143 }
144
145 for ( unsigned k=0 ; k<m_keylist.size() ; k++ ) {
146 const std::string& key = m_keylist[k] ;
147
148
149 ATH_MSG_INFO( "Processing WaveContainer from StoreGate! key=" << m_keylist[k] );
150 const LArCaliWaveContainer* caliWaveContainer = nullptr;
151 StatusCode sc = m_detStore->retrieve(caliWaveContainer,key);
152 if (sc.isFailure()) {
153 ATH_MSG_ERROR( "Cannot read LArCaliWaveContainer from StoreGate! key=" << key );
154 return StatusCode::FAILURE;
155 } else
156 ATH_MSG_INFO( "Read LArCaliWaveContainer from StoreGate! key= " << key );
157 LArCaliWaveContainer* caliWaveContainer_nc=nullptr;
158 if (m_applyCorr) {
159 if (!caliWaveContainer->correctionsApplied()) {
160 caliWaveContainer_nc=const_cast<LArCaliWaveContainer*>(caliWaveContainer);
161 sc=caliWaveContainer_nc->applyCorrections();
162 if (sc.isFailure()) {
163 ATH_MSG_ERROR( "Failed to apply corrections to LArCaliWaveContainer!" );
164 }
165 else
166 ATH_MSG_INFO( "Applied corrections to LArCaliWaveContainer" );
167 }
168 else {
169 ATH_MSG_WARNING( "Corrections already applied. Can't apply twice!" );
170 }
171 }// end if applyCorr
172
173
174 for (int igain=CaloGain::LARHIGHGAIN;igain<m_NGains.value() ;++igain){
175 for (const HWIdentifier chid: m_onlineId->channel_range()) {
176 m_gain=(long)igain;
177 const LArCaliWaveVec& cwv = caliWaveContainer->get(chid,igain);
178 if (cwv.empty()) continue;
179
180 LArCaliWaveVec::const_iterator cwv_it=cwv.begin();
181 LArCaliWaveVec::const_iterator cwv_it_e=cwv.end();
182 for (;cwv_it!=cwv_it_e;++cwv_it) {
183 const LArCaliWave& wave=*cwv_it;
184 if (wave.isEmpty()) continue;
185 if (m_addCorrUndo) m_corrUndo=0;
186 bool skip=writeEntry(chid,igain,wave,clCont);
187 if (skip) continue;
188 sc=ntupleSvc()->writeRecord(m_nt);
189 if (sc!=StatusCode::SUCCESS) {
190 ATH_MSG_ERROR( "writeRecord failed" );
191 return sc;
192 }
193 }//End loop over DAC
194 }//end loop over identifiers
195 }//end loop over gains
196
197
198 if (m_addCorrUndo) {
199 for (int igain=CaloGain::LARHIGHGAIN;igain<m_NGains.value();++igain) {
200 LArCaliWaveContainer::ConstCorrectionIt itUndo=caliWaveContainer->undoCorrBegin(igain);
201 LArCaliWaveContainer::ConstCorrectionIt itUndo_e=caliWaveContainer->undoCorrEnd(igain);
202 for(;itUndo!=itUndo_e;itUndo++) {
203 const HWIdentifier chid(itUndo->first);
204 const LArCaliWaveVec& cwv = itUndo->second;
205 LArCaliWaveVec::const_iterator cwv_it=cwv.begin();
206 LArCaliWaveVec::const_iterator cwv_it_e=cwv.end();
207 for (;cwv_it!=cwv_it_e;++cwv_it) {
208 const LArCaliWave& wave=*cwv_it;
209 m_gain = (long)igain;
210 m_corrUndo = 1;
211 bool skip=writeEntry(chid,igain,wave,clCont);
212 if (skip) continue;
213 sc=ntupleSvc()->writeRecord(m_nt);
214 if (sc!=StatusCode::SUCCESS) {
215 ATH_MSG_ERROR( "writeRecord failed" );
216 return sc;
217 }
218 }//end loop over DAC
219 }//end loop over corrections
220 }//end loop over gain
221 }//end if addUndoCorr
222 if (caliWaveContainer_nc) {
223 ATH_CHECK(caliWaveContainer_nc->undoCorrections());
224 ATH_MSG_INFO("Reverted corrections of CaliWave container");
225 }
226 }
227 ATH_MSG_INFO( "LArWave2Ntuple has finished." );
228 return StatusCode::SUCCESS;
229} // end finalize-method.
230
231
232
233bool LArCaliWaves2Ntuple::writeEntry(const HWIdentifier chid, const unsigned gain, const LArCaliWave& wave,const LArCalibLineMapping *clCont) {
234 //call fill method of base-class
235 fillWave(chid,wave);
236 m_dac = wave.getDAC();
237 int DACSatur = 100000;
238 if (m_dacSaturSkip) {
239 switch (m_layer) {
240 case 0:
241 DACSatur = m_dacSaturLayer0[gain];
242 break;
243 case 1:
244 DACSatur = m_dacSaturLayer1[gain];
245 break;
246 case 2:
247 DACSatur = m_dacSaturLayer2[gain];
248 break;
249 case 3:
250 DACSatur = m_dacSaturLayer3[gain];
251 break;
252 }
253 if (m_dac > DACSatur ) return true;
254 }
255
256
258 if ( !m_isSC && m_addCalib) {
259 const std::vector<HWIdentifier>& calibLineV = clCont->calibSlotLine(chid);
260 if ( !calibLineV.empty() ) {
261 ATH_MSG_DEBUG( " chan: " << chid.get_identifier32().get_compact() << " wave.getIsPulsedInt() " << wave.getIsPulsedInt()<<" : "<< calibLineV.size());
262 for(int i=0;i<4;i++) {
264 }
265 std::vector<HWIdentifier>::const_iterator calibLineIt = calibLineV.begin();
266 unsigned iCalibLine=0;
268 for(calibLineIt = calibLineV.begin(); calibLineIt != calibLineV.end();++calibLineIt) {
269 if ( (wave.getIsPulsedInt()>>(15+iCalibLine+1)) & 1 ){
270 m_pulsedCalibLines[iCalibLine] = m_onlineId->channel(*calibLineIt);
271 if (m_pulsedCalibLines[iCalibLine]>=0) m_calibLine = m_onlineId->channel(*calibLineIt);
273 ATH_MSG_DEBUG(" iCalibLine: "<< iCalibLine << " CL: "<<m_pulsedCalibLines[iCalibLine]);
274 }
275 iCalibLine++;
276 }
277 ATH_MSG_DEBUG( "m_pulsedCalibLines: "<<m_pulsedCalibLines[0]<<"/"<<m_pulsedCalibLines[1]<<"/"<<m_pulsedCalibLines[2]<<"/"<<m_pulsedCalibLines[3]);
278 } // else if calibLineV.size()>0
279 else {
282 }
284 }//end if !m_isSC && m_addCalib
285
286 // Jitter
287 if ( m_saveJitter ) {
288 m_jitter = m_waveHelper.getJitter(wave);
289 }
290
291 return false;
292}
#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)
StatusCode LArCaliWaves2Ntuple::stop ATLAS_NOT_THREAD_SAFE()
Install fatal handler with default options.
static Double_t sc
INTupleSvc * ntupleSvc()
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
value_type get_compact() const
Get the compact id.
Identifier32 get_identifier32() const
Get the 32-bit version Identifier, will be invalid if >32 bits needed.
Liquid Argon Cumulative Wave Container.
int getIsPulsedInt() const
isPulsed value
int getDAC() const
DAC value.
std::vector< unsigned > m_dacSaturLayer2
NTuple::Item< long > m_nPulsedCalibLines
std::vector< unsigned > m_dacSaturLayer3
NTuple::Array< int > m_pulsedCalibLines
virtual StatusCode initialize() override
LArCaliWaves2Ntuple(const std::string &name, ISvcLocator *pSvcLocator)
std::vector< unsigned > m_dacSaturLayer0
NTuple::Item< double > m_jitter
NTuple::Item< long > m_isPulsed
bool writeEntry(const HWIdentifier chid, const unsigned gain, const LArCaliWave &wave, const LArCalibLineMapping *clCont)
std::vector< unsigned > m_dacSaturLayer1
std::vector< std::string > m_keylist
NTuple::Item< long > m_dac
const std::vector< HWIdentifier > & calibSlotLine(const HWIdentifier id) const
Gaudi::Property< bool > m_isSC
NTuple::Item< long > m_calibLine
NTuple::Item< long > m_layer
Gaudi::Property< bool > m_addCalib
SG::ReadCondHandleKey< LArCalibLineMapping > m_calibMapKey
const LArOnlineID_Base * m_onlineId
SG::ReadCondHandleKey< LArCalibLineMapping > m_calibMapSCKey
bool correctionsApplied() const
Have corrections been applied?
StatusCode applyCorrections()
apply correction set
StatusCode undoCorrections()
undo corrections that have been already applied
ConstCorrectionIt undoCorrBegin(unsigned int gain) const
get iterator over the Undo-Vector for a certain gain
ConstCorrectionIt undoCorrEnd(unsigned int gain) const
ConstReference get(const HWIdentifier id, unsigned int gain=0) const
get data with online identifier
bool isEmpty() const
is LArWave uninitialized?
Definition LArWave.h:183
LArWaveHelper m_waveHelper
StatusCode initialize()
LArWaves2Ntuple(const std::string &name, ISvcLocator *pSvcLocator)
bool fillWave(const HWIdentifier chid, const LArWaveCumul &wave)
@ LARHIGHGAIN
Definition CaloGain.h:18