ATLAS Offline Software
L1CaloHVCorrectionsForDB.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 #include "GaudiKernel/MsgStream.h"
10 
18 
19 L1CaloHVCorrectionsForDB::L1CaloHVCorrectionsForDB(const std::string& name, ISvcLocator *pSvcLocator)
20  : AthAlgorithm(name, pSvcLocator),
21  m_triggerTowerCollectionName("TriggerTowers"),
22  m_caloCellContainerName("AllCalo"),
23  m_ttTool("LVL1::L1TriggerTowerTool/L1TriggerTowerTool"),
24  m_jmTools("LVL1::L1CaloOfflineTriggerTowerTools/L1CaloOfflineTriggerTowerTools", this),
25  m_rxLayersContainer(0),
26  m_hvCorrectionsContainer(0),
27  m_firstEvent(true)
28 {
29  declareProperty("TriggerTowerCollectionName", m_triggerTowerCollectionName);
30  declareProperty("CaloCellContainerName", m_caloCellContainerName);
31 }
32 
34 {
35 }
36 
38 {
39  ATH_CHECK( m_ttTool.retrieve() );
40  ATH_CHECK( m_jmTools.retrieve() );
41 
45 
48 
49  return StatusCode::SUCCESS;
50 }
51 
53 {
54  if (m_firstEvent) {
55 
56  StatusCode sc;
57 
58  const TriggerTowerCollection *triggerTowerCollection(0);
59  sc = evtStore()->retrieve(triggerTowerCollection, m_triggerTowerCollectionName);
60  if(!sc.isSuccess()) {
61  msg(MSG::ERROR) << "Cannot retrieve TriggerTowerCollection '"
62  << m_triggerTowerCollectionName << "' from StoreGate." << endmsg;
63  return sc;
64  }
65 
66  const CaloCellContainer *caloCellContainer(0);
67  sc = evtStore()->retrieve(caloCellContainer, m_caloCellContainerName);
68  if(!sc.isSuccess()) {
69  msg(MSG::ERROR) << "Cannot retrieve CaloCellContainer '" << m_caloCellContainerName
70  << "'." << endmsg;
71  return sc;
72  }
73 
74  // init trigger tower to cell mapping - needed each event?
75  m_jmTools->caloCells(caloCellContainer);
76 
77  const LVL1::TriggerTower *tt;
78  TriggerTowerCollection::const_iterator p_itTT = triggerTowerCollection->begin();
79  TriggerTowerCollection::const_iterator p_itTTEnd = triggerTowerCollection->end();
80  std::vector<unsigned int> coolIdByRx;
81  std::vector<std::vector<int> > layernamesByRx;
82  std::vector<std::vector<int> > layerNcellsByRx;
83  std::vector<float> meanScaleByRx;
84  std::vector<std::vector<float> > affectedCellsFByRx;
85  std::vector<std::vector<float> > layerMeansByRx;
86  std::vector<int> affectedCells;
87  std::vector<float>::const_iterator affIt;
88  std::vector<float> layerMeans;
89  int hvCount = 0;
90  int rxCount = 0;
91 
92  for(;p_itTT != p_itTTEnd; ++p_itTT) {
93  tt = *p_itTT;
94  for (int sample = 0; sample < 2; ++sample) { // Loop over samples (em/had)
95  const bool isTile = (sample == 1 && fabs(tt->eta()) < 1.5);
96  if (isTile) continue;
97 
98  if (sample == 0) { //em
99  coolIdByRx = m_jmTools->emRxId(tt);
100  layernamesByRx = m_jmTools->emTTCellsLayerNamesByReceiver(tt);
101  layerNcellsByRx = m_jmTools->emNCellsByReceiverByLayer(tt);
102  meanScaleByRx = m_jmTools->emNonNominalMeanScaleByReceiver(tt);
103  affectedCellsFByRx = m_jmTools->emNCellsNonNominalByReceiverByLayer(tt);
104  layerMeansByRx = m_jmTools->emNonNominalMeanScaleByReceiverByLayer(tt);
105  } else { //had
106  coolIdByRx = m_jmTools->hadRxId(tt);
107  layernamesByRx = m_jmTools->hadTTCellsLayerNamesByReceiver(tt);
108  layerNcellsByRx = m_jmTools->hadNCellsByReceiverByLayer(tt);
109  meanScaleByRx = m_jmTools->hadNonNominalMeanScaleByReceiver(tt);
110  affectedCellsFByRx = m_jmTools->hadNCellsNonNominalByReceiverByLayer(tt);
111  layerMeansByRx = m_jmTools->hadNonNominalMeanScaleByReceiverByLayer(tt);
112  }
113  const unsigned int nRx = coolIdByRx.size();
114  if (nRx != layernamesByRx.size() ||
115  nRx != layerNcellsByRx.size() ||
116  nRx != meanScaleByRx.size() ||
117  nRx != affectedCellsFByRx.size() ||
118  nRx != layerMeansByRx.size()) {
119  msg(MSG::ERROR) << "Vectors by receiver have inconsistent size" << endmsg;
120  return StatusCode::FAILURE;
121  }
122  rxCount += nRx;
123  for (unsigned int i = 0; i < nRx; ++i) { // Loop over receivers
124  const unsigned int coolId(coolIdByRx[i]);
125  const std::vector<int>& layernames(layernamesByRx[i]);
126  const std::vector<int>& layerNcells(layerNcellsByRx[i]);
127  const float meanScale(meanScaleByRx[i]);
128  const std::vector<float>& affectedCellsF(affectedCellsFByRx[i]);
129  const std::vector<float>& layerMeans(layerMeansByRx[i]);
130 
131  const unsigned int nLayers = layernames.size();
132  if (nLayers != layerNcells.size()) {
133  msg(MSG::ERROR) << "layernames/layerNcells inconsistent size" << endmsg;
134  return StatusCode::FAILURE;
135  }
136  if (nLayers == 0 || nLayers > 4) {
137  //msg(MSG::ERROR) << "Unexpected number of layers: " << nLayers << endmsg;
138  //return StatusCode::FAILURE;
139  msg(MSG::WARNING) << "Unexpected number of layers: " << nLayers
140  << " eta/phi: " << tt->eta() << "/" << tt->phi()
141  << " sample: " << sample
142  << " Receiver: " << i << endmsg;
143  continue;
144  }
145  for (unsigned int j = 0; j < nLayers; ++j) {
146  if (layerNcells[j] == 0) {
147  msg(MSG::ERROR) << "Layer " << j << " has no cells" << endmsg;
148  return StatusCode::FAILURE;
149  }
150  for (unsigned int k = 0; k < j; ++k) {
151  if (layernames[j] == layernames[k]) {
152  msg(MSG::ERROR) << "Duplicate layernames" << endmsg;
153  return StatusCode::FAILURE;
154  }
155  }
156  }
157 
158  L1CaloRxLayers l1caloRxLayersSample(coolId, std::vector<int>(layernames), std::vector<int>(layerNcells));
159  m_rxLayersContainer->addRxLayers(coolId, std::move(l1caloRxLayersSample));
160 
161  if (nLayers != affectedCellsF.size()) {
162  msg(MSG::ERROR) << "layernames/affectedCellsF inconsistent size" << endmsg;
163  return StatusCode::FAILURE;
164  }
165  if (nLayers != layerMeans.size()) {
166  msg(MSG::ERROR) << "layernames/layerMeans inconsistent size" << endmsg;
167  return StatusCode::FAILURE;
168  }
169  float sum = 0.;
170  float ncells = 0;
171  for (unsigned int j = 0; j < nLayers; ++j) {
172  sum += layerMeans[j]*layerNcells[j];
173  ncells += layerNcells[j];
174  }
175  if (ncells > 0.) sum /= ncells;
176  const float tol = 1.e-4;
177  if (fabs(sum - meanScale) > tol) {
178  msg(MSG::ERROR) << "Total and layer means inconsistent: "
179  << meanScale << " " << sum << endmsg;
180  return StatusCode::FAILURE;
181  }
182  bool affected = (meanScale != 1.);
183  if (!affected) {
184  for (unsigned int j = 0; j < layerMeans.size(); ++j) {
185  if (layerMeans[j] != 1.) affected = true;
186  }
187  }
188 
189  if (affected) {
190  affectedCells.clear();
191  for (affIt = affectedCellsF.begin(); affIt != affectedCellsF.end(); ++affIt) {
192  affectedCells.push_back((int)(*affIt));
193  }
194  L1CaloHVCorrections l1caloHVCorrectionsSample(coolId, meanScale, std::move(affectedCells), std::vector<float>(layerMeans));
195  m_hvCorrectionsContainer->addHVCorrections(coolId, std::move(l1caloHVCorrectionsSample));
196  hvCount++;
197  }
198  }
199  }
200  }
201  const unsigned int ttsize = triggerTowerCollection->size();
202  const unsigned int exsize = 3584;
203  if (ttsize != exsize) {
204  msg(MSG::ERROR) << "First event has " << ttsize
205  << " TriggerTowers, expected " << exsize << endmsg;
206  return StatusCode::FAILURE;
207  } else {
208  msg(MSG::INFO) << "Number of TriggerTowers in first event is "
209  << ttsize << " Number of Receivers is " << rxCount << endmsg;
210  }
211  msg(MSG::INFO) << "Number of HV Correction entries is " << hvCount << endmsg;
212  m_firstEvent = false;
213 
214  }
215 
216  return StatusCode::SUCCESS;
217 }
218 
220 {
221  DataObject* dObj = m_rxLayersContainer->makePersistent();
222  if (dObj) {
223  CondAttrListCollection* coll = dynamic_cast<CondAttrListCollection*>(dObj);
224  if (coll) {
225  StatusCode sc;
226  sc = detStore()->record(coll, m_rxLayersContainer->coolOutputKey());
227  if (sc.isFailure()) {
228  msg(MSG::ERROR) << "Failed to record RxLayersContainer" << endmsg;
229  return sc;
230  }
231  } else {
232  msg(MSG::ERROR) << "Could not cast to CondAttrListCollection" << endmsg;
233  return StatusCode::FAILURE;
234  }
235  } else {
236  msg(MSG::ERROR) << "makePersistent failed for RxLayersContainer" << endmsg;
237  return StatusCode::FAILURE;
238  }
239  dObj = m_hvCorrectionsContainer->makePersistent();
240  if (dObj) {
241  CondAttrListCollection* coll = dynamic_cast<CondAttrListCollection*>(dObj);
242  if (coll) {
243  StatusCode sc;
244  sc = detStore()->record(coll, m_hvCorrectionsContainer->coolOutputKey());
245  if (sc.isFailure()) {
246  msg(MSG::ERROR) << "Failed to record HVCorrectionsContainer" << endmsg;
247  return sc;
248  }
249  } else {
250  msg(MSG::ERROR) << "Could not cast to CondAttrListCollection" << endmsg;
251  return StatusCode::FAILURE;
252  }
253  } else {
254  msg(MSG::ERROR) << "makePersistent failed for HVCorrectionsContainer" << endmsg;
255  return StatusCode::FAILURE;
256  }
257 
258  return StatusCode::SUCCESS;
259 }
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
L1CaloHVCorrectionsForDB.h
CondAttrListCollection.h
This file defines the class for a collection of AttributeLists where each one is associated with a ch...
L1CaloHVCorrectionsForDB::m_firstEvent
bool m_firstEvent
Definition: L1CaloHVCorrectionsForDB.h:56
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
L1CaloHVCorrectionsForDB::initialize
StatusCode initialize()
Definition: L1CaloHVCorrectionsForDB.cxx:37
IL1CaloOfflineTriggerTowerTools.h
IL1CaloCells2TriggerTowers.h
L1CaloHVCorrectionsForDB::finalize
StatusCode finalize()
Definition: L1CaloHVCorrectionsForDB.cxx:219
CondAttrListCollection
This class is a collection of AttributeLists where each one is associated with a channel number....
Definition: CondAttrListCollection.h:52
AthenaAttributeList.h
L1CaloRxLayersContainer.h
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
L1CaloHVCorrectionsForDB::~L1CaloHVCorrectionsForDB
virtual ~L1CaloHVCorrectionsForDB()
Definition: L1CaloHVCorrectionsForDB.cxx:33
AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
convertTimingResiduals.sum
sum
Definition: convertTimingResiduals.py:55
FullCPAlgorithmsTest_eljob.sample
sample
Definition: FullCPAlgorithmsTest_eljob.py:100
L1CaloHVCorrectionsContainer.h
lumiFormat.i
int i
Definition: lumiFormat.py:92
L1CaloHVCorrections
Class that holds mean HV corrections for receivers.
Definition: L1CaloHVCorrections.h:19
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
L1CaloHVCorrectionsForDB::L1CaloHVCorrectionsForDB
L1CaloHVCorrectionsForDB(const std::string &name, ISvcLocator *pSvcLocator)
Definition: L1CaloHVCorrectionsForDB.cxx:19
L1CaloHVCorrectionsContainer
Container of L1CaloHVCorrections objects, inherit from the abstract base class AbstractL1CaloConditio...
Definition: L1CaloHVCorrectionsContainer.h:30
L1CaloHVCorrectionsForDB::m_hvCorrectionsContainer
boost::scoped_ptr< L1CaloHVCorrectionsContainer > m_hvCorrectionsContainer
Definition: L1CaloHVCorrectionsForDB.h:54
L1CaloHVCorrectionsForDB::m_rxLayersContainer
boost::scoped_ptr< L1CaloRxLayersContainer > m_rxLayersContainer
Definition: L1CaloHVCorrectionsForDB.h:53
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
L1CaloRxLayersContainer
Container of L1CaloRxLayers objects, inherit from the abstract base class AbstractL1CaloConditionCont...
Definition: L1CaloRxLayersContainer.h:30
L1CaloHVCorrectionsForDB::m_cablingKey
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKey
Definition: L1CaloHVCorrectionsForDB.h:51
DataVector< LVL1::TriggerTower >
L1CaloHVCorrectionsForDB::m_scaleCorrKey
SG::ReadCondHandleKey< ILArHVScaleCorr > m_scaleCorrKey
Definition: L1CaloHVCorrectionsForDB.h:49
AthAlgorithm
Definition: AthAlgorithm.h:47
LVL1::TriggerTower
Trigger towers are the inputs to all other parts of the calorimeter trigger.
Definition: Trigger/TrigT1/TrigT1CaloEvent/TrigT1CaloEvent/TriggerTower.h:45
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
L1CaloHVCorrectionsForDB::execute
StatusCode execute()
Definition: L1CaloHVCorrectionsForDB.cxx:52
CaloCellContainer.h
CaloCellContainer
Container class for CaloCell.
Definition: CaloCellContainer.h:55
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
IL1TriggerTowerTool.h
L1CaloHVCorrectionsForDB::m_ttTool
ToolHandle< LVL1::IL1TriggerTowerTool > m_ttTool
Definition: L1CaloHVCorrectionsForDB.h:46
AthCommonMsg< Algorithm >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
L1CaloRxLayers
Class that holds information about calo layers that make up receivers.
Definition: L1CaloRxLayers.h:19
TriggerTowerCollection.h
L1CaloHVCorrectionsForDB::m_jmTools
ToolHandle< LVL1::IL1CaloOfflineTriggerTowerTools > m_jmTools
Definition: L1CaloHVCorrectionsForDB.h:47
L1CaloHVCorrectionsForDB::m_caloCellContainerName
std::string m_caloCellContainerName
Definition: L1CaloHVCorrectionsForDB.h:44
TileDCSDataPlotter.tt
tt
Definition: TileDCSDataPlotter.py:874
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
fitman.k
k
Definition: fitman.py:528
L1CaloHVCorrectionsForDB::m_triggerTowerCollectionName
std::string m_triggerTowerCollectionName
Definition: L1CaloHVCorrectionsForDB.h:43