ATLAS Offline Software
Loading...
Searching...
No Matches
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
19L1CaloHVCorrectionsForDB::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(nullptr),
27 m_firstEvent(true)
28{
29 declareProperty("TriggerTowerCollectionName", m_triggerTowerCollectionName);
30 declareProperty("CaloCellContainerName", m_caloCellContainerName);
31}
32
36
38{
39 ATH_CHECK( m_ttTool.retrieve() );
40 ATH_CHECK( m_jmTools.retrieve() );
41
42 ATH_CHECK( m_scaleCorrKey.initialize() );
43 ATH_CHECK( m_cablingKey.initialize() );
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}
#define endmsg
#define ATH_CHECK
Evaluate an expression and check for errors.
This file defines the class for a collection of AttributeLists where each one is associated with a ch...
static Double_t sc
DataVector< LVL1::TriggerTower > TriggerTowerCollection
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
const ServiceHandle< StoreGateSvc > & detStore() const
MsgStream & msg() const
Container class for CaloCell.
This class is a collection of AttributeLists where each one is associated with a channel number.
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
size_type size() const noexcept
Returns the number of elements in the collection.
Container of L1CaloHVCorrections objects, inherit from the abstract base class AbstractL1CaloConditio...
std::unique_ptr< L1CaloHVCorrectionsContainer > m_hvCorrectionsContainer
std::unique_ptr< L1CaloRxLayersContainer > m_rxLayersContainer
SG::ReadCondHandleKey< ILArHVScaleCorr > m_scaleCorrKey
ToolHandle< LVL1::IL1TriggerTowerTool > m_ttTool
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKey
ToolHandle< LVL1::IL1CaloOfflineTriggerTowerTools > m_jmTools
L1CaloHVCorrectionsForDB(const std::string &name, ISvcLocator *pSvcLocator)
Class that holds mean HV corrections for receivers.
Container of L1CaloRxLayers objects, inherit from the abstract base class AbstractL1CaloConditionCont...
Class that holds information about calo layers that make up receivers.
Trigger towers are the inputs to all other parts of the calorimeter trigger.