ATLAS Offline Software
LArPedestalAutoCorrBuilder.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 /********************************************************************
6 
7  NAME: LArPedestalAutoCorrBuilder.cxx
8  PACKAGE: offline/LArCalorimeter/LArCalibUtils
9 
10  AUTHORS: W. Lampl
11  CREATED: Aug 17th, 2009, merging LArPedestalBuilder & LArAutoCorrBuilder
12 
13  PURPOSE: Create LArPedestalComplete and LArAutoCorrComplete objects
14  out of pre-accmulated LArAccumulatedDigits
15 
16 ********************************************************************/
17 
18 // Include files
20 
24 
27 
28 
29 LArPedestalAutoCorrBuilder::LArPedestalAutoCorrBuilder(const std::string& name, ISvcLocator* pSvcLocator)
30  : AthAlgorithm(name, pSvcLocator),
31  m_onlineHelper(nullptr),
32  m_event_counter(0),
33  m_fatalFebErrorPattern(0xffff)
34 {
35  declareProperty("KeyList", m_keylist);
36  declareProperty("PedestalKey", m_pedContName="LArPedestal");
37  declareProperty("normalize", m_normalize=1);
38  declareProperty("AutoCorrKey", m_acContName="LArAutoCorr");
39  declareProperty("GroupingType", m_groupingType="ExtendedFeedThrough");
40  declareProperty("doPedestal", m_doPedestal=true);
41  declareProperty("doAutoCorr", m_doAutoCorr=true);
42  declareProperty("sample_min", m_sample_min=-1);
43  declareProperty("sample_max", m_sample_max=-1);
44 }
45 
47 = default;
48 
50 {
51  if (m_groupingType == "SuperCells") {
52  ATH_MSG_INFO("Processing LAr SuperCells");
53  const LArOnline_SuperCellID* onlID;
54  ATH_CHECK(detStore()->retrieve(onlID,"LArOnline_SuperCellID"));
55  m_onlineHelper=onlID; // cast to base-class
56  }
57  else {
58  ATH_MSG_INFO("Processing regular LArCells");
59  const LArOnlineID* onlID;
60  ATH_CHECK(detStore()->retrieve(onlID, "LArOnlineID"));
61  m_onlineHelper=onlID; // cast to base-class
62  }
63 
64 
65 
66  if (!m_doPedestal && !m_doAutoCorr) {
67  ATH_MSG_ERROR( "Configuration Problem: Neither doPedstal nor doAutoCorr set!" );
68  return StatusCode::FAILURE;
69  }
70 
71  if (m_keylist.empty()) // Not key list given
72  {m_keylist.emplace_back("HIGH");
73  m_keylist.emplace_back("MEDIUM");
74  m_keylist.emplace_back("LOW");
75  m_keylist.emplace_back("FREE"); //For H6....
76  }
77 
78  //Container for internal accumulation
81  if (sc.isFailure()) {
82  ATH_MSG_ERROR( "Failed initialize LArConditionsContainer 'm_accu'" );
83  return sc;
84  }
85  return StatusCode::SUCCESS;
86 }
87 
88 
89 //---------------------------------------------------------------------------
91 //---------------------------------------------------------------------------
92 {
93 
94  StatusCode sc;
96  if (m_keylist.empty()) {
97  ATH_MSG_ERROR( "Key list is empty! No containers processed!" );
98  return StatusCode::FAILURE;
99  }
100 
101 
102  const LArFebErrorSummary* febErrSum=nullptr;
103  if (evtStore()->contains<LArFebErrorSummary>("LArFebErrorSummary")) {
104  sc=evtStore()->retrieve(febErrSum);
105  if (sc.isFailure()) {
106  ATH_MSG_ERROR( "Failed to retrieve FebErrorSummary object!" );
107  return sc;
108  }
109  }
110  else
111  if (m_event_counter==1)
112  ATH_MSG_WARNING( "No FebErrorSummaryObject found! Feb errors not checked!" );
113 
114 
115  const LArAccumulatedDigitContainer* container = nullptr;
116  //Outermost loop goes over all gains (different containers).
117  int foundkey = 0;
118 
119  for (const std::string& key : m_keylist) {
120  sc= evtStore()->retrieve(container,key);
121  if (sc.isFailure() || !container) {
122  ATH_MSG_DEBUG("Cannot read LArAccumulatedDigitContainer from StoreGate! key=" << key);
123  if ( ( (&key == &m_keylist.back()) ) && foundkey==0 ){
124  ATH_MSG_ERROR("None of the provided LArAccumulatedDigitContainer keys could be read");
125  return StatusCode::FAILURE;
126  }else{
127  continue;
128  }
129  }
130  foundkey+=1;
131 
132  // check that container is not empty
133  if(container->empty() ) {
134  ATH_MSG_DEBUG("LArAccumulatedDigitContainer (key=" << key << ") is empty ");
135  continue;
136  }else{
137  ATH_MSG_DEBUG("LArAccumulatedDigitContainer (key=" << key << ") has length " << container->size());
138  }
139 
140  HWIdentifier lastFailedFEB(0);
141  //Inner loop goes over the cells.
142  for (const LArAccumulatedDigit* dg : *container) { //Loop over all cells
143  if (dg->nTrigger()==0) continue; //Don't care about empty digits
144  const HWIdentifier chid=dg->hardwareID();
145  const HWIdentifier febid=m_onlineHelper->feb_Id(chid);
146  if (febErrSum) {
147  const uint16_t febErrs=febErrSum->feb_error(febid);
148  if (febErrs & m_fatalFebErrorPattern) {
149  if (febid!=lastFailedFEB) {
150  lastFailedFEB=febid;
151  ATH_MSG_ERROR( "Event " << m_event_counter << " Feb " << m_onlineHelper->channel_name(febid)
152  << " reports error(s):" << febErrSum->error_to_string(febErrs) << ". Data ignored." );
153  }
154  continue;
155  } //end if fatal feb error
156  }//end if check feb error summary
157 
158  const CaloGain::CaloGain gain=dg->gain();
159 
160  LArAccumulatedDigit& accDg=m_accu.get(chid,gain);
161  if (!accDg.setAddSubStep(*dg))
162  ATH_MSG_ERROR( "Failed to accumulate sub-steps! Inconsistent number of ADC samples" );
163  } //end loop over input container
164  }//end loop over keys
165  return StatusCode::SUCCESS;
166 }
167 
168 
169 
171 
172  std::unique_ptr<LArAutoCorrComplete> larAutoCorrComplete;
173  std::unique_ptr<LArPedestalComplete> larPedestalComplete;
174 
175  if (m_doAutoCorr) {
176  //Book and initialize LArAutoCorrComplete object
177  ATH_MSG_INFO("Creating LArAutoCorrComplete");
178  larAutoCorrComplete = std::make_unique<LArAutoCorrComplete>();
179  ATH_CHECK( larAutoCorrComplete->setGroupingType(m_groupingType,msg()) );
180  ATH_CHECK( larAutoCorrComplete->initialize() );
181  }
182 
183  if (m_doPedestal) {
184  //Book and initialize LArPedestalComplete object
185  ATH_MSG_INFO("Creating LArAutoPedestalComplete");
186  larPedestalComplete = std::make_unique<LArPedestalComplete>();
187  ATH_CHECK( larPedestalComplete->setGroupingType(m_groupingType,msg()) );
188  ATH_CHECK( larPedestalComplete->initialize() );
189  }
190 
191  //For the log output further down
192  std::string objName;
193  if (m_doPedestal)
194  objName="pedestal";
195  if (m_doAutoCorr)
196  objName="autocorr";
197  if (m_doAutoCorr && m_doPedestal)
198  objName="pedestal & autocorr";
199 
200  int n_zero,n_min, n_max, n_cur;
201  n_zero=0; n_max=n_min=-1;
202  unsigned NCells=0;
203  std::vector<float> cov;
204  //Loop over gains
205  for (unsigned k=0;k<(int)CaloGain::LARNGAIN;k++) {
207  //Loop over cells
210 
211  if (cell_it==cell_it_e){
212  continue; //No data for this gain
213  }
214  for (;cell_it!=cell_it_e;cell_it++) {
215  const LArAccumulatedDigit& dg=*cell_it;
216  n_cur = dg.nTrigger();
217  if(n_cur==0) { n_zero++; continue; }
218 
219  HWIdentifier chid = cell_it.channelId();
220 
221  if(n_cur<n_min || n_min<0) n_min=n_cur;
222  if(n_cur>n_max || n_max<0) n_max=n_cur;
223 
224  // Fill the data class with pedestal and rms values
225  if (larPedestalComplete)
226  larPedestalComplete->set(chid,gain,dg.mean(m_sample_min, m_sample_max),dg.RMS(m_sample_min, m_sample_max));
227 
228  if (larAutoCorrComplete) {
229  dg.getCov(cov,m_normalize);
230  larAutoCorrComplete->set(chid,gain,cov);
231  }
232  NCells++;
233  }//end loop over all cells
234 
235  ATH_MSG_INFO( "Gain " << gain << " Number of cells with 0 events to compute "<<objName<< ": " << n_zero );
236  ATH_MSG_INFO( "Gain " << gain << " Minimum number of events*samples to compute " <<objName<<": "<< n_min );
237  ATH_MSG_INFO( "Gain " << gain << " Maximum number of events*samples to compute " <<objName<<": " <<n_max );
238  }// End loop over all containers
239 
240  ATH_MSG_INFO( " Summary : Number of cells with " <<objName<<" value computed : " << NCells );
241  ATH_MSG_INFO( " Summary : Number of Barrel PS cells side A or C (connected+unconnected): 3904+ 192 = 4096 " );
242  ATH_MSG_INFO( " Summary : Number of Barrel cells side A or C (connected+unconnected): 50944+2304 = 53248 " );
243  ATH_MSG_INFO( " Summary : Number of EMEC cells side A or C (connected+unconnected): 31872+3456 = 35328 " );
244  ATH_MSG_INFO( " Summary : Number of HEC cells side A or C (connected+unconnected): 2816+ 256 = 3072 " );
245  ATH_MSG_INFO( " Summary : Number of FCAL cells side A or C (connected+unconnected): 1762+ 30 = 1792 " );
246 
247  if (larPedestalComplete) {
248  ATH_CHECK( detStore()->record(std::move(larPedestalComplete),m_pedContName) );
249  }
250 
251 
252  if (larAutoCorrComplete) {
253  ATH_CHECK( detStore()->record(std::move(larAutoCorrComplete),m_acContName) );
254  }
255 
256  return StatusCode::SUCCESS;
257 }
258 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
LArConditionsContainerBase::SuperCells
@ SuperCells
Definition: LArConditionsContainerBase.h:51
LArPedestalAutoCorrBuilder::m_sample_max
int m_sample_max
Definition: LArPedestalAutoCorrBuilder.h:75
LArConditionsContainerDB::iteratorT::channelId
HWIdentifier channelId() const
checkCoolLatestUpdate.dg
dg
Definition: checkCoolLatestUpdate.py:9
LArPedestalAutoCorrBuilder::m_sample_min
int m_sample_min
Definition: LArPedestalAutoCorrBuilder.h:74
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
LArAccumulatedDigitContainer
Container class for LArAccumulatedDigit.
Definition: LArAccumulatedDigitContainer.h:22
LArConditionsContainerBase::SingleGroup
@ SingleGroup
Definition: LArConditionsContainerBase.h:46
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
LArAccumulatedDigit::setAddSubStep
bool setAddSubStep(const CaloGain::CaloGain gain_value, const HWIdentifier chid, const std::vector< uint64_t > &sampleSum, const std::vector< uint64_t > &sampleSquare, const unsigned nTrigger)
Accumulate new values
Definition: LArAccumulatedDigit.cxx:113
LArPedestalAutoCorrBuilder::stop
virtual StatusCode stop()
Definition: LArPedestalAutoCorrBuilder.cxx:170
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
LArPedestalAutoCorrBuilder::m_keylist
std::vector< std::string > m_keylist
Definition: LArPedestalAutoCorrBuilder.h:54
LArConditionsContainerDB::iteratorT
Declaration of const iterator.
Definition: LArConditionsContainerDB.h:72
LArPedestalAutoCorrBuilder::m_groupingType
std::string m_groupingType
Definition: LArPedestalAutoCorrBuilder.h:57
CaloCondBlobAlgs_fillNoiseFromASCII.gain
gain
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:110
plotBeamSpotVxVal.cov
cov
Definition: plotBeamSpotVxVal.py:201
LArPedestalAutoCorrBuilder::~LArPedestalAutoCorrBuilder
~LArPedestalAutoCorrBuilder()
LArFebErrorSummary::error_to_string
static std::string error_to_string(uint16_t error)
interpret the error in string
Definition: LArFebErrorSummary.cxx:58
LArAutoCorrComplete::set
void set(const HWIdentifier &CellID, int gain, const std::vector< float > &vAutoCorr)
Definition: LArAutoCorrComplete.cxx:13
LArPedestalAutoCorrBuilder::m_accu
ACCU m_accu
Definition: LArPedestalAutoCorrBuilder.h:61
HWIdentifier
Definition: HWIdentifier.h:13
CaloGain::LARNGAIN
@ LARNGAIN
Definition: CaloGain.h:19
LArPedestalAutoCorrBuilder::initialize
StatusCode initialize()
Definition: LArPedestalAutoCorrBuilder.cxx:49
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
LArFebErrorSummary::feb_error
uint16_t feb_error(HWIdentifier febid) const
get error for feb
Definition: LArFebErrorSummary.cxx:20
AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
LArAccumulatedDigit
Data class for ADC samples and autocorr preprocessed by the DSP.
Definition: LArAccumulatedDigit.h:32
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
xAOD::uint16_t
setWord1 uint16_t
Definition: eFexEMRoI_v1.cxx:88
LArConditionsContainer::end
ConstConditionsMapIterator end(unsigned int gain) const
end of all channels for this gain
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
LArPedestalAutoCorrBuilder::m_onlineHelper
const LArOnlineID_Base * m_onlineHelper
Definition: LArPedestalAutoCorrBuilder.h:52
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
LArPedestalAutoCorrBuilder::m_acContName
std::string m_acContName
Definition: LArPedestalAutoCorrBuilder.h:66
LArAutoCorrComplete.h
LArPedestalComplete::set
void set(const HWIdentifier &CellID, const int gain, const float vPedestal, const float vPedestalRMS)
Definition: LArPedestalComplete.cxx:19
AthAlgorithm
Definition: AthAlgorithm.h:47
LArOnlineID_Base::feb_Id
HWIdentifier feb_Id(int barrel_ec, int pos_neg, int feedthrough, int slot) const
Create feb_Id from fields.
Definition: LArOnlineID_Base.cxx:1483
LArPedestalAutoCorrBuilder::m_doPedestal
bool m_doPedestal
Definition: LArPedestalAutoCorrBuilder.h:68
LArPedestalAutoCorrBuilder.h
LArPedestalAutoCorrBuilder::m_event_counter
unsigned m_event_counter
Definition: LArPedestalAutoCorrBuilder.h:63
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
LArPedestalAutoCorrBuilder::m_doAutoCorr
bool m_doAutoCorr
Definition: LArPedestalAutoCorrBuilder.h:68
LArOnlineID
Definition: LArOnlineID.h:20
LArPedestalAutoCorrBuilder::LArPedestalAutoCorrBuilder
LArPedestalAutoCorrBuilder(const std::string &name, ISvcLocator *pSvcLocator)
Definition: LArPedestalAutoCorrBuilder.cxx:29
LArOnline_SuperCellID
Definition: LArOnline_SuperCellID.h:20
CaloGain::CaloGain
CaloGain
Definition: CaloGain.h:11
LArPedestalAutoCorrBuilder::m_fatalFebErrorPattern
uint16_t m_fatalFebErrorPattern
Definition: LArPedestalAutoCorrBuilder.h:70
LArConditionsContainer::initialize
virtual StatusCode initialize()
Initialization done after creation or read back - derived classes may augment the functionality.
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
LArPedestalAutoCorrBuilder::m_pedContName
std::string m_pedContName
Definition: LArPedestalAutoCorrBuilder.h:65
LArFebErrorSummary
Holds information from the FEB Error Summary.
Definition: LArFebErrorSummary.h:23
AthCommonMsg< Algorithm >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
LArPedestalComplete.h
LArConditionsContainer::begin
ConstConditionsMapIterator begin(unsigned int gain) const
get iterator for all channels for a gain
LArPedestalAutoCorrBuilder::m_normalize
int m_normalize
Definition: LArPedestalAutoCorrBuilder.h:72
LArOnline_SuperCellID.h
LArFebErrorSummary.h
LArPedestalAutoCorrBuilder::execute
StatusCode execute()
Definition: LArPedestalAutoCorrBuilder.cxx:90
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
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
DataVector::empty
bool empty() const noexcept
Returns true if the collection is empty.
fitman.k
k
Definition: fitman.py:528
LArOnlineID.h
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37