7 #include "GaudiKernel/MsgStream.h"
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),
49 return StatusCode::SUCCESS;
61 msg(MSG::ERROR) <<
"Cannot retrieve TriggerTowerCollection '"
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;
92 for(;p_itTT != p_itTTEnd; ++p_itTT) {
95 const bool isTile = (
sample == 1 && fabs(
tt->eta()) < 1.5);
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);
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);
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;
123 for (
unsigned int i = 0;
i < nRx; ++
i) {
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]);
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;
136 if (nLayers == 0 || nLayers > 4) {
139 msg(MSG::WARNING) <<
"Unexpected number of layers: " << nLayers
140 <<
" eta/phi: " <<
tt->eta() <<
"/" <<
tt->phi()
142 <<
" Receiver: " <<
i <<
endmsg;
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;
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;
158 L1CaloRxLayers l1caloRxLayersSample(coolId, std::vector<int>(layernames), std::vector<int>(layerNcells));
161 if (nLayers != affectedCellsF.size()) {
162 msg(MSG::ERROR) <<
"layernames/affectedCellsF inconsistent size" <<
endmsg;
163 return StatusCode::FAILURE;
165 if (nLayers != layerMeans.size()) {
166 msg(MSG::ERROR) <<
"layernames/layerMeans inconsistent size" <<
endmsg;
167 return StatusCode::FAILURE;
171 for (
unsigned int j = 0; j < nLayers; ++j) {
172 sum += layerMeans[j]*layerNcells[j];
173 ncells += layerNcells[j];
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: "
180 return StatusCode::FAILURE;
182 bool affected = (meanScale != 1.);
184 for (
unsigned int j = 0; j < layerMeans.size(); ++j) {
185 if (layerMeans[j] != 1.) affected =
true;
190 affectedCells.clear();
191 for (affIt = affectedCellsF.begin(); affIt != affectedCellsF.end(); ++affIt) {
192 affectedCells.push_back((
int)(*affIt));
194 L1CaloHVCorrections l1caloHVCorrectionsSample(coolId, meanScale, std::move(affectedCells), std::vector<float>(layerMeans));
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;
208 msg(MSG::INFO) <<
"Number of TriggerTowers in first event is "
209 << ttsize <<
" Number of Receivers is " << rxCount <<
endmsg;
211 msg(MSG::INFO) <<
"Number of HV Correction entries is " << hvCount <<
endmsg;
216 return StatusCode::SUCCESS;
227 if (
sc.isFailure()) {
228 msg(MSG::ERROR) <<
"Failed to record RxLayersContainer" <<
endmsg;
232 msg(MSG::ERROR) <<
"Could not cast to CondAttrListCollection" <<
endmsg;
233 return StatusCode::FAILURE;
236 msg(MSG::ERROR) <<
"makePersistent failed for RxLayersContainer" <<
endmsg;
237 return StatusCode::FAILURE;
245 if (
sc.isFailure()) {
246 msg(MSG::ERROR) <<
"Failed to record HVCorrectionsContainer" <<
endmsg;
250 msg(MSG::ERROR) <<
"Could not cast to CondAttrListCollection" <<
endmsg;
251 return StatusCode::FAILURE;
254 msg(MSG::ERROR) <<
"makePersistent failed for HVCorrectionsContainer" <<
endmsg;
255 return StatusCode::FAILURE;
258 return StatusCode::SUCCESS;