ATLAS Offline Software
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 
8 LArCaliWaves2Ntuple::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
39  }
40 
41 
43 }
44 
46 = default;
47 
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("nPulsedCalibLines",m_nPulsedCalibLines,0,4);
96  if (sc!=StatusCode::SUCCESS) {
97  ATH_MSG_ERROR( "addItem 'nPulsedCalibLines' failed" );
98  return StatusCode::FAILURE;
99  }
100 
101  sc=m_nt->addItem("pulsedCalibLines",4,m_pulsedCalibLines);
102  if (sc!=StatusCode::SUCCESS) {
103  ATH_MSG_ERROR( "addItem 'pulsedCalibLines' failed" );
104  return StatusCode::FAILURE;
105  }
106  }
107 
108  if (m_saveJitter) {
109  sc=m_nt->addItem("Jitter",m_jitter,0.,1.);
110  if (sc!=StatusCode::SUCCESS) {
111  ATH_MSG_ERROR( "addItem 'Jitter' failed" );
112  return StatusCode::FAILURE;
113  }
114  }
115 
116  if (m_addCorrUndo) {
117  sc=m_nt->addItem("corrUndo",m_corrUndo,0,1);
118  if (sc!=StatusCode::SUCCESS) {
119  ATH_MSG_ERROR( "addItem 'corrUndo' failed" );
120  return StatusCode::FAILURE;
121  }
122  }
123 
124 
125  const LArCalibLineMapping *clCont=nullptr;
126  if(m_isSC) {
127  ATH_MSG_DEBUG( "LArCaliWaves2Ntuple: using SC calib map" );
128  SG::ReadCondHandle<LArCalibLineMapping> clHdl{m_calibMapSCKey};
129  clCont=*clHdl;
130  } else {
131  SG::ReadCondHandle<LArCalibLineMapping> clHdl{m_calibMapKey};
132  clCont=*clHdl;
133  }
134 
135  if(!clCont) {
136  ATH_MSG_WARNING( "Do not have calib line mapping !!!" );
137  return StatusCode::FAILURE;
138  }
139 
140  for ( unsigned k=0 ; k<m_keylist.size() ; k++ ) {
141  const std::string& key = m_keylist[k] ;
142 
143 
144  ATH_MSG_INFO( "Processing WaveContainer from StoreGate! key=" << m_keylist[k] );
145  const LArCaliWaveContainer* caliWaveContainer = nullptr;
146  StatusCode sc = m_detStore->retrieve(caliWaveContainer,key);
147  if (sc.isFailure()) {
148  ATH_MSG_ERROR( "Cannot read LArCaliWaveContainer from StoreGate! key=" << key );
149  return StatusCode::FAILURE;
150  } else
151  ATH_MSG_INFO( "Read LArCaliWaveContainer from StoreGate! key= " << key );
152  LArCaliWaveContainer* caliWaveContainer_nc=nullptr;
153  if (m_applyCorr) {
154  if (!caliWaveContainer->correctionsApplied()) {
155  caliWaveContainer_nc=const_cast<LArCaliWaveContainer*>(caliWaveContainer);
156  sc=caliWaveContainer_nc->applyCorrections();
157  if (sc.isFailure()) {
158  ATH_MSG_ERROR( "Failed to apply corrections to LArCaliWaveContainer!" );
159  }
160  else
161  ATH_MSG_INFO( "Applied corrections to LArCaliWaveContainer" );
162  }
163  else {
164  ATH_MSG_WARNING( "Corrections already applied. Can't apply twice!" );
165  }
166  }// end if applyCorr
167 
168 
170  for (const HWIdentifier chid: m_onlineId->channel_range()) {
171  m_gain=(long)igain;
172  const LArCaliWaveVec& cwv = caliWaveContainer->get(chid,igain);
173  if (cwv.empty()) continue;
174 
175  LArCaliWaveVec::const_iterator cwv_it=cwv.begin();
176  LArCaliWaveVec::const_iterator cwv_it_e=cwv.end();
177  for (;cwv_it!=cwv_it_e;++cwv_it) {
178  const LArCaliWave& wave=*cwv_it;
179  if (wave.isEmpty()) continue;
180  if (m_addCorrUndo) m_corrUndo=0;
181  bool skip=writeEntry(chid,igain,wave,clCont);
182  if (skip) continue;
183  sc=ntupleSvc()->writeRecord(m_nt);
184  if (sc!=StatusCode::SUCCESS) {
185  ATH_MSG_ERROR( "writeRecord failed" );
186  return sc;
187  }
188  }//End loop over DAC
189  }//end loop over identifiers
190  }//end loop over gains
191 
192 
193  if (m_addCorrUndo) {
196  LArCaliWaveContainer::ConstCorrectionIt itUndo_e=caliWaveContainer->undoCorrEnd(igain);
197  for(;itUndo!=itUndo_e;itUndo++) {
198  const HWIdentifier chid(itUndo->first);
199  const LArCaliWaveVec& cwv = itUndo->second;
200  LArCaliWaveVec::const_iterator cwv_it=cwv.begin();
201  LArCaliWaveVec::const_iterator cwv_it_e=cwv.end();
202  for (;cwv_it!=cwv_it_e;++cwv_it) {
203  const LArCaliWave& wave=*cwv_it;
204  m_gain = (long)igain;
205  m_corrUndo = 1;
206  bool skip=writeEntry(chid,igain,wave,clCont);
207  if (skip) continue;
208  sc=ntupleSvc()->writeRecord(m_nt);
209  if (sc!=StatusCode::SUCCESS) {
210  ATH_MSG_ERROR( "writeRecord failed" );
211  return sc;
212  }
213  }//end loop over DAC
214  }//end loop over corrections
215  }//end loop over gain
216  }//end if addUndoCorr
217  if (caliWaveContainer_nc) {
218  ATH_CHECK(caliWaveContainer_nc->undoCorrections());
219  ATH_MSG_INFO("Reverted corrections of CaliWave container");
220  }
221  }
222  ATH_MSG_INFO( "LArWave2Ntuple has finished." );
223  return StatusCode::SUCCESS;
224 } // end finalize-method.
225 
226 
227 
228 bool LArCaliWaves2Ntuple::writeEntry(const HWIdentifier chid, const unsigned gain, const LArCaliWave& wave,const LArCalibLineMapping *clCont) {
229  //call fill method of base-class
230  fillWave(chid,wave);
231  m_dac = wave.getDAC();
232  int DACSatur = 100000;
233  if (m_dacSaturSkip) {
234  switch (m_layer) {
235  case 0:
236  DACSatur = m_dacSaturLayer0[gain];
237  break;
238  case 1:
239  DACSatur = m_dacSaturLayer1[gain];
240  break;
241  case 2:
242  DACSatur = m_dacSaturLayer2[gain];
243  break;
244  case 3:
245  DACSatur = m_dacSaturLayer3[gain];
246  break;
247  }
248  if (m_dac > DACSatur ) return true;
249  }
250 
251 
253  if ( !m_isSC && m_addCalib) {
254  const std::vector<HWIdentifier>& calibLineV = clCont->calibSlotLine(chid);
255  if ( !calibLineV.empty() ) {
256  ATH_MSG_DEBUG( "wave.getIsPulsedInt() " << wave.getIsPulsedInt()<<" : "<< calibLineV.size());
257  for(int i=0;i<4;i++) {
259  }
260  std::vector<HWIdentifier>::const_iterator calibLineIt = calibLineV.begin();
261  unsigned iCalibLine=0;
263  for(calibLineIt = calibLineV.begin(); calibLineIt != calibLineV.end();++calibLineIt) {
264  if ( (wave.getIsPulsedInt()>>iCalibLine) & 1 ){
265  m_pulsedCalibLines[iCalibLine] = m_onlineId->channel(*calibLineIt);
266  if (m_pulsedCalibLines[iCalibLine]>=0) m_calibLine = m_onlineId->channel(*calibLineIt);
268  }
269  iCalibLine++;
270  }
271  ATH_MSG_DEBUG( "m_pulsedCalibLines: "<<m_pulsedCalibLines[0]<<"/"<<m_pulsedCalibLines[1]<<"/"<<m_pulsedCalibLines[2]<<"/"<<m_pulsedCalibLines[3]);
272  } // else if calibLineV.size()>0
273  else {
274  m_nPulsedCalibLines = 0 ;
276  }
277  }//end if !m_isSC && m_addCalib
278 
279  // Jitter
280  if ( m_saveJitter ) {
282  }
283 
284  return false;
285 }
LArConditionsContainer::applyCorrections
StatusCode applyCorrections()
apply correction set
LArCond2NtupleBase::m_layer
NTuple::Item< long > m_layer
Definition: LArCond2NtupleBase.h:71
LArCaliWaves2Ntuple.h
LArWaves2Ntuple::initialize
StatusCode initialize()
Definition: LArWaves2Ntuple.cxx:18
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
LArCond2NtupleBase::m_addCalib
Gaudi::Property< bool > m_addCalib
Definition: LArCond2NtupleBase.h:59
LArConditionsContainer::undoCorrections
StatusCode undoCorrections()
undo corrections that have been already applied
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
LArCalibLineMapping::calibSlotLine
const std::vector< HWIdentifier > & calibSlotLine(const HWIdentifier id) const
Definition: LArCalibLineMapping.cxx:15
LArCalibLineMapping
Definition: LArCalibLineMapping.h:17
CaloCondBlobAlgs_fillNoiseFromASCII.gain
gain
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:110
LArWaves2Ntuple::fillWave
bool fillWave(const HWIdentifier chid, const LArWaveCumul &wave)
Definition: LArWaves2Ntuple.cxx:107
LArCaliWaves2Ntuple::m_dacSaturLayer2
std::vector< unsigned > m_dacSaturLayer2
Definition: LArCaliWaves2Ntuple.h:51
LArCaliWaves2Ntuple::m_applyCorr
bool m_applyCorr
Definition: LArCaliWaves2Ntuple.h:47
LArWaveHelper::getJitter
double getJitter(const LArWaveCumul &theWave) const
Definition: LArWaveHelper.cxx:429
LArCaliWave::getDAC
int getDAC() const
DAC value.
Definition: LArCaliWave.h:156
LArCaliWaves2Ntuple::m_pulsedCalibLines
NTuple::Array< int > m_pulsedCalibLines
Definition: LArCaliWaves2Ntuple.h:58
LArConditionsContainer::undoCorrEnd
ConstCorrectionIt undoCorrEnd(unsigned int gain) const
PixelModuleFeMask_create_db.stop
int stop
Definition: PixelModuleFeMask_create_db.py:76
HWIdentifier
Definition: HWIdentifier.h:13
CaloGain::LARNGAIN
@ LARNGAIN
Definition: CaloGain.h:19
LArCond2NtupleBase::NOT_VALID
@ NOT_VALID
Definition: LArCond2NtupleBase.h:63
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
LArCaliWaveContainer
Liquid Argon Cumulative Wave Container.
Definition: LArCaliWaveContainer.h:33
LArCaliWave::getIsPulsedInt
int getIsPulsedInt() const
isPulsed value
Definition: LArCaliWave.h:163
LArWaves2Ntuple::m_waveHelper
LArWaveHelper m_waveHelper
Definition: LArWaves2Ntuple.h:56
LArCaliWaves2Ntuple::m_nPulsedCalibLines
NTuple::Item< long > m_nPulsedCalibLines
Definition: LArCaliWaves2Ntuple.h:57
LArConditionsContainer< LArCaliWaveVec >::ConstCorrectionIt
Subset::ConstCorrectionVecIt ConstCorrectionIt
Definition: LArConditionsContainer.h:78
LArOnlineID_Base::channel
int channel(const HWIdentifier id) const
Return the channel number of a hardware cell identifier channel = [0,127] in all FEB.
Definition: LArOnlineID_Base.cxx:1963
LArCaliWave
Definition: LArCaliWave.h:44
LArCaliWaves2Ntuple::initialize
virtual StatusCode initialize() override
Definition: LArCaliWaves2Ntuple.cxx:30
LArWave::isEmpty
bool isEmpty() const
is LArWave uninitialized?
Definition: LArWave.h:183
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
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
LArConditionsContainer::get
ConstReference get(const HWIdentifier id, unsigned int gain=0) const
get data with online identifier
LArCond2NtupleBase::m_ntpath
std::string m_ntpath
Definition: LArCond2NtupleBase.h:65
LArCond2NtupleBase::m_calibMapKey
SG::ReadCondHandleKey< LArCalibLineMapping > m_calibMapKey
Definition: LArCond2NtupleBase.h:93
LArWaves2Ntuple
Definition: LArWaves2Ntuple.h:25
LArCaliWaves2Ntuple::m_ntName
std::string m_ntName
Definition: LArCaliWaves2Ntuple.h:42
LArCaliWaveVec
Definition: LArCaliWave.h:91
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
LArCaliWaves2Ntuple::m_dacSaturLayer0
std::vector< unsigned > m_dacSaturLayer0
Definition: LArCaliWaves2Ntuple.h:49
WriteCellNoiseToCool.igain
igain
Definition: WriteCellNoiseToCool.py:338
LArCaliWaves2Ntuple::m_dacSaturLayer1
std::vector< unsigned > m_dacSaturLayer1
Definition: LArCaliWaves2Ntuple.h:50
LArCaliWaves2Ntuple::m_ntFile
std::string m_ntFile
Definition: LArCaliWaves2Ntuple.h:43
LArCaliWaves2Ntuple::writeEntry
bool writeEntry(const HWIdentifier chid, const unsigned gain, const LArCaliWave &wave, const LArCalibLineMapping *clCont)
Definition: LArCaliWaves2Ntuple.cxx:228
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
LArCond2NtupleBase::m_ntTitle
std::string m_ntTitle
Definition: LArCond2NtupleBase.h:65
LArCaliWaves2Ntuple::m_jitter
NTuple::Item< double > m_jitter
Definition: LArCaliWaves2Ntuple.h:59
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
LArConditionsContainer::undoCorrBegin
ConstCorrectionIt undoCorrBegin(unsigned int gain) const
get iterator over the Undo-Vector for a certain gain
LArCond2NtupleBase::m_onlineId
const LArOnlineID_Base * m_onlineId
Definition: LArCond2NtupleBase.h:85
CaloGain::LARHIGHGAIN
@ LARHIGHGAIN
Definition: CaloGain.h:18
LArCaliWaves2Ntuple::m_dacSaturLayer3
std::vector< unsigned > m_dacSaturLayer3
Definition: LArCaliWaves2Ntuple.h:52
LArCaliWaves2Ntuple::m_saveJitter
bool m_saveJitter
Definition: LArCaliWaves2Ntuple.h:45
LArCaliWaves2Ntuple::m_addCorrUndo
bool m_addCorrUndo
Definition: LArCaliWaves2Ntuple.h:46
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
LArCond2NtupleBase::m_isSC
Gaudi::Property< bool > m_isSC
Definition: LArCond2NtupleBase.h:55
LArCaliWaves2Ntuple::m_dacSaturSkip
bool m_dacSaturSkip
Definition: LArCaliWaves2Ntuple.h:44
LArCaliWaves2Ntuple::m_keylist
std::vector< std::string > m_keylist
Definition: LArCaliWaves2Ntuple.h:41
skip
bool skip
Definition: TrigGlobEffCorrValidation.cxx:190
LArCond2NtupleBase::m_calibMapSCKey
SG::ReadCondHandleKey< LArCalibLineMapping > m_calibMapSCKey
Definition: LArCond2NtupleBase.h:94
CaloGain.h
LArCond2NtupleBase::m_calibLine
NTuple::Item< long > m_calibLine
Definition: LArCond2NtupleBase.h:73
ntupleSvc
INTupleSvc * ntupleSvc()
Definition: ServiceAccessor.h:14
LArCaliWaves2Ntuple::m_dac
NTuple::Item< long > m_dac
Definition: LArCaliWaves2Ntuple.h:55
ATLAS_NOT_THREAD_SAFE
StatusCode LArCaliWaves2Ntuple::stop ATLAS_NOT_THREAD_SAFE()
Install fatal handler with default options.
Definition: LArCaliWaves2Ntuple.cxx:48
LArCaliWaves2Ntuple::LArCaliWaves2Ntuple
LArCaliWaves2Ntuple(const std::string &name, ISvcLocator *pSvcLocator)
Definition: LArCaliWaves2Ntuple.cxx:8
fitman.k
k
Definition: fitman.py:528
LArConditionsContainer::correctionsApplied
bool correctionsApplied() const
Have corrections been applied?
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
LArCaliWaves2Ntuple::~LArCaliWaves2Ntuple
~LArCaliWaves2Ntuple()