ATLAS Offline Software
Loading...
Searching...
No Matches
TBEMECXTalkToyModel.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5/********************************************************************
6
7NAME: TBEMECXTalkToyModel
8PACKAGE: offline/Calorimeter/CaloRec
9
10AUTHORS: Johannes Erdmann
11CREATED: October 14,2008
12
13PURPOSE: A simple toy model to simulate longitudinal cross-talk
14 between EMEC2 and EMEC3 in the reco step.
15 Code mainly copied from CaloCellContainerCorrectorTool
16
17********************************************************************/
18
19#include "TBEMECXTalkToyModel.h"
20
22#include "CaloEvent/CaloCell.h"
23
24#include "CaloDetDescr/CaloDetDescrElement.h"
26
28// CONSTRUCTOR:
30
32 const std::string& type,
33 const std::string& name,
34 const IInterface* parent)
35 :base_class (type, name, parent),
36 m_caloSelection(false),
37 m_calo_id(nullptr)
38{
39 declareProperty("CaloNums",m_caloNums);
40 declareProperty("XTalkScaleLong", m_xtalkScaleLong);
41 declareProperty("XTalkScaleEta", m_xtalkScaleEta);
42 declareProperty("XTalkScaleEMEC2Eta",m_xtalkScaleEMEC2Eta);
43 m_caloNums.clear();
44 //default: process all calo
45 m_caloNums.push_back( static_cast<int>(CaloCell_ID::NSUBCALO) );
46}
47
48
49
50
52// INITIALIZE:
53// The initialize method will create all the required algorithm objects
55
57{
58 unsigned int nSubCalo=static_cast<unsigned int>(CaloCell_ID::NSUBCALO) ;
59
60 //check calo number specified
61 m_caloSelection = true ;
62 if (m_caloNums.size()==0) {
63 ATH_MSG_WARNING (" no calo specified for correction. Will do nothing. ");
64 return StatusCode::SUCCESS;
65 } else if (m_caloNums.size()>nSubCalo ) {
66 ATH_MSG_ERROR (" More than "
67 << nSubCalo << " calo specified. Must be wrong. Stop.");
68 return StatusCode::FAILURE;
69 } else if (m_caloNums.size()==1 && m_caloNums[0]==static_cast<int>(nSubCalo)) {
70 m_caloSelection = false ;
71 ATH_MSG_INFO (" Correction will be applied on all calo.");
72 } else {
73 for (unsigned int index=0; index < m_caloNums.size() ; ++index) {
74 if (m_caloNums[index]<0 || m_caloNums[index]>=static_cast<int>(nSubCalo) ) {
75 ATH_MSG_ERROR ("Invalid calo specification:"
76 << m_caloNums[index] << "Stop.");
77 return StatusCode::FAILURE;
78 } else {
79 ATH_MSG_INFO (" Correction will be applied on calo:"
80 << static_cast<int>(m_caloNums[index]));
81 }
82 }
83 }
84
85 ATH_CHECK(detStore()->retrieve(m_calo_id,"CaloCell_ID"));
86
87 ATH_MSG_VERBOSE ("XTalkScaleLong = " << m_xtalkScaleLong);
88 ATH_MSG_VERBOSE ("XTalkScaleEta = " << m_xtalkScaleEta);
89 ATH_MSG_VERBOSE ("XTalkScaleEMEC2Eta = " << m_xtalkScaleEMEC2Eta);
90 ATH_MSG_VERBOSE ("Initialization completed successfully" );
91
92 return StatusCode::SUCCESS;
93
94}
95
97 const EventContext& /*ctx*/) const
98{
99 StatusCode sc;
100
101 if (!m_caloSelection) {
102 // no selection mode (faster)
103 CaloCellContainer::iterator itrCellBeg=theCont->begin();
104 CaloCellContainer::iterator itrCellEnd=theCont->end();
105
106 sc = processOnCellIterators(itrCellBeg, itrCellEnd );
107 if (sc.isFailure())
108 ATH_MSG_WARNING ("Failure from processOnCellIterators");
109 }else {
110 // selection mode
111
112 for (std::vector<int>::const_iterator itrCalo=m_caloNums.begin();itrCalo!=m_caloNums.end();++itrCalo){
113
114
115 CaloCell_ID::SUBCALO caloNum=static_cast<CaloCell_ID::SUBCALO>(*itrCalo);
116
117 CaloCellContainer::iterator itrCellBeg=theCont->beginCalo(caloNum);
118 CaloCellContainer::iterator itrCellEnd=theCont->endCalo(caloNum);
119
120 if (!theCont->hasCalo(caloNum))
121 {
122 ATH_MSG_WARNING (" Attempt to apply correction but CaloCellContainer has not been filled for this calo : "
123 << *itrCalo);
124 } else
125 {
126 sc=processOnCellIterators(itrCellBeg, itrCellEnd );
127 if (sc.isFailure())
128 ATH_MSG_WARNING ("Failure from processOnCellIterators for calo "
129 << static_cast<int> (caloNum));
130 }
131 }
132 }
133
134 return StatusCode::SUCCESS ;
135}
136
138 const CaloCellContainer::iterator & itrCellEnd ) const
139{
140 IdentifierHash myHashMin,myHashMax;
141 m_calo_id->calo_cell_hash_range (CaloCell_ID::LAREM,myHashMin,myHashMax);
142 unsigned int myCellHashOffset = myHashMin;
143
145 std::map<Identifier,CaloCell*> cellMap;
146 std::map<Identifier,float> energyMap;
147 for (itrCell=itrCellBeg;itrCell!=itrCellEnd;++itrCell) {
148 CaloCell * theCell = *itrCell;
149 cellMap.insert(std::pair<Identifier,CaloCell*>(theCell->ID(),theCell));
150 energyMap.insert(std::pair<Identifier,float>(theCell->ID(),theCell->energy()));
151 }
152
153 for (itrCell=itrCellBeg;itrCell!=itrCellEnd;++itrCell) {
154 CaloCell * theCell = *itrCell;
155 const CaloDetDescrElement* element = theCell->caloDDE();
156
157 if (element->is_lar_em_endcap_inner()) {
158 CaloCell_ID::CaloSample sample = element->getSampling();
159
160 if (sample==6) { // this is the EMEC2
161 std::map<Identifier,float>::iterator cellItEng = energyMap.find(theCell->ID());
162 if (cellItEng==energyMap.end()) {
163 ATH_MSG_ERROR ("Identifier not found in energyMap");
164 return StatusCode::FAILURE;
165 }
166 double e = (*cellItEng).second;
167
168 const CaloCell_ID::SUBCALO mySubDet = element->getSubCalo();
169 std::vector<IdentifierHash> theNeighbors;
170
171 int otherSubDet;
172 Identifier myId = theCell->ID();
173 IdentifierHash myHashId = m_calo_id->subcalo_cell_hash(myId,otherSubDet);
174
175 // longitudinal neighbor (N1)
176 m_calo_id->get_neighbours(myHashId+myCellHashOffset,LArNeighbours::nextInSamp,theNeighbors);
177 ATH_MSG_DEBUG ("N1 theNeighbors.size() = " << theNeighbors.size());
178 IdentifierHash nId = theNeighbors.at(0)-myCellHashOffset;
179 myId = m_calo_id->cell_id(mySubDet,nId);
180 std::map<Identifier,CaloCell*>::iterator cellIt = cellMap.find(myId);
181 if (cellIt==cellMap.end()) {
182 ATH_MSG_ERROR ("neighbor CaloCell object not found in cellMap");
183 return StatusCode::FAILURE;
184 }
185 CaloCell * theCellN1 = (*cellIt).second;
186 if (!theCellN1) {
187 ATH_MSG_ERROR ("neighbor CaloCell object not found in cellMap");
188 return StatusCode::FAILURE;
189 }
190 cellItEng = energyMap.find(theCellN1->ID());
191 if (cellItEng==energyMap.end()) {
192 ATH_MSG_ERROR ( "Identifier not found in energyMap" );
193 return StatusCode::FAILURE;
194 }
195 double eN1 = (*cellItEng).second;
196
197 // neighbors in eta of EMEC3 cell (N2,N3) -- only if they exist
198 int EMEC3neighbors = 0;
199 myHashId = m_calo_id->subcalo_cell_hash(theCellN1->ID(),otherSubDet);
200 //
201 m_calo_id->get_neighbours(myHashId+myCellHashOffset,LArNeighbours::nextInEta,theNeighbors);
202 ATH_MSG_DEBUG ( "N2 theNeighbors.size() = " << theNeighbors.size() );
203 CaloCell * theCellN2 = 0x0;
204 double eN2 = 0.;
205 if (theNeighbors.size()>0) {
206 nId = theNeighbors.at(0)-myCellHashOffset;
207 myId = m_calo_id->cell_id(mySubDet,nId);
208 cellIt = cellMap.find(myId);
209 if (cellIt!=cellMap.end()) {
210 theCellN2 = (*cellIt).second;
211 cellItEng = energyMap.find(theCellN2->ID());
212 if (cellItEng==energyMap.end()) {
213 ATH_MSG_ERROR ( "Identifier not found in energyMap" );
214 return StatusCode::FAILURE;
215 }
216 eN2 = (*cellItEng).second;
217 EMEC3neighbors++;
218 }
219 }
220 //
221 m_calo_id->get_neighbours(myHashId+myCellHashOffset,LArNeighbours::prevInEta,theNeighbors);
222 ATH_MSG_DEBUG ( "N3 theNeighbors.size() = " << theNeighbors.size() );
223 CaloCell * theCellN3 = 0x0;
224 double eN3 = 0.;
225 if (theNeighbors.size()>0) {
226 nId = theNeighbors.at(0)-myCellHashOffset;
227 myId = m_calo_id->cell_id(mySubDet,nId);
228 cellIt = cellMap.find(myId);
229 if (cellIt!=cellMap.end()) {
230 theCellN3 = (*cellIt).second;
231 cellItEng = energyMap.find(theCellN3->ID());
232 if (cellItEng==energyMap.end()) {
233 ATH_MSG_ERROR ( "Identifier not found in energyMap" );
234 return StatusCode::FAILURE;
235 }
236 eN3 = (*cellItEng).second;
237 EMEC3neighbors++;
238 }
239 }
240
241 // neighbors in eta of EMEC2 cell (N4,N5) -- only if they exist
242 int EMEC2neighbors = 0;
243 myHashId = m_calo_id->subcalo_cell_hash(theCell->ID(),otherSubDet);
244 //
245 m_calo_id->get_neighbours(myHashId+myCellHashOffset,LArNeighbours::nextInEta,theNeighbors);
246 ATH_MSG_DEBUG ( "N4 theNeighbors.size() = " << theNeighbors.size() );
247 CaloCell * theCellN4 = 0x0;
248 double eN4 = 0.;
249 if (theNeighbors.size()>0) {
250 nId = theNeighbors.at(0)-myCellHashOffset;
251 myId = m_calo_id->cell_id(mySubDet,nId);
252 cellIt = cellMap.find(myId);
253 if (cellIt!=cellMap.end()) {
254 theCellN4 = (*cellIt).second;
255 if (!theCellN4){
256 ATH_MSG_ERROR ( "theCellN4 is a nulllptr" );
257 return StatusCode::FAILURE;
258 }
259 cellItEng = energyMap.find(theCellN4->ID());
260 if (cellItEng==energyMap.end()) {
261 ATH_MSG_ERROR ( "Identifier not found in energyMap" );
262 return StatusCode::FAILURE;
263 }
264 eN4 = (*cellItEng).second;
265 EMEC2neighbors++;
266 }
267 }
268 //
269 m_calo_id->get_neighbours(myHashId+myCellHashOffset,LArNeighbours::prevInEta,theNeighbors);
270 ATH_MSG_DEBUG ( "N5 theNeighbors.size() = " << theNeighbors.size() );
271 CaloCell * theCellN5 = 0x0;
272 double eN5 = 0.;
273 if (theNeighbors.size()>0) {
274 nId = theNeighbors.at(0)-myCellHashOffset;
275 myId = m_calo_id->cell_id(mySubDet,nId);
276 cellIt = cellMap.find(myId);
277 if (cellIt!=cellMap.end()) {
278 theCellN5 = (*cellIt).second;
279 cellItEng = energyMap.find(theCellN5->ID());
280 if (cellItEng==energyMap.end()) {
281 ATH_MSG_ERROR ( "Identifier not found in energyMap" );
282 return StatusCode::FAILURE;
283 }
284 eN5 = (*cellItEng).second;
285 EMEC2neighbors++;
286 }
287 }
288
289 double rescaled_e = (1.-m_xtalkScaleLong-EMEC3neighbors*m_xtalkScaleEta-EMEC2neighbors*m_xtalkScaleEMEC2Eta)*e
290 + m_xtalkScaleLong*eN1 + m_xtalkScaleEta*(eN2+eN3) + m_xtalkScaleEMEC2Eta*(eN4+eN5)
291 + (theCell->energy()-e);
292 double rescaled_eN1 = 0;
293 if (theCellN1) rescaled_eN1 = (1.-m_xtalkScaleLong)*eN1 + m_xtalkScaleLong*e + (theCellN1->energy()-eN1);
294 double rescaled_eN2 = 0.;
295 if (theCellN2) rescaled_eN2 = (1.-m_xtalkScaleEta)*eN2 + m_xtalkScaleEta*e + (theCellN2->energy()-eN2);
296 double rescaled_eN3 = 0.;
297 if (theCellN3) rescaled_eN3 = (1.-m_xtalkScaleEta)*eN3 + m_xtalkScaleEta*e + (theCellN3->energy()-eN3);
298 /*
299 double rescaled_eN4 = 0.;
300 if (theCellN4) rescaled_eN4 = (1.-m_xtalkScaleEMEC2Eta)*eN4 + m_xtalkScaleEMEC2Eta*e + (theCellN4->energy()-eN4);
301 double rescaled_eN5 = 0.;
302 if (theCellN5) rescaled_eN5 = (1.-m_xtalkScaleEMEC2Eta)*eN5 + m_xtalkScaleEMEC2Eta*e + (theCellN5->energy()-eN5);
303 */
304
305 ATH_MSG_DEBUG ("");
306 ATH_MSG_DEBUG ( "neighbors of cell [" << m_calo_id->show_to_string(theCell ->ID(),0,'/') << "] : " );
307 if (theCellN1)
308 ATH_MSG_DEBUG ( " N1 = [" << m_calo_id->show_to_string(theCellN1->ID(),0,'/') << "]" );
309 if (theCellN2)
310 ATH_MSG_DEBUG ( " N2 = [" << m_calo_id->show_to_string(theCellN2->ID(),0,'/') << "]" );
311 if (theCellN3)
312 ATH_MSG_DEBUG ( " N3 = [" << m_calo_id->show_to_string(theCellN3->ID(),0,'/') << "]" );
313 if (theCellN4)
314 ATH_MSG_DEBUG ( " N4 = [" << m_calo_id->show_to_string(theCellN4->ID(),0,'/') << "]" );
315 if (theCellN5)
316 ATH_MSG_DEBUG ( " N5 = [" << m_calo_id->show_to_string(theCellN5->ID(),0,'/') << "]" );
317
318 ATH_MSG_DEBUG ( "EMEC2 cell : energy before = " << e << " | energy after rescaling = " << rescaled_e );
319 ATH_MSG_DEBUG ( " "
320 << (1.-m_xtalkScaleLong-EMEC3neighbors*m_xtalkScaleEta-EMEC2neighbors*m_xtalkScaleEMEC2Eta)*e
321 << " | " << m_xtalkScaleLong*eN1
322 << " | " << m_xtalkScaleEta*(eN2+eN3)
323 << " | " << m_xtalkScaleEMEC2Eta*(eN4+eN5)
324 << " | " << (theCell->energy()-e) );
325 ATH_MSG_DEBUG ( "EMEC3 cell (N1): energy before = " << eN1 << " | energy after rescaling = " << rescaled_eN1 );
327 << " | " << (theCellN1->energy()-eN1) );
328 if (theCellN2) {
329 ATH_MSG_DEBUG ( "EMEC3 cell (N2): energy before = " << eN2 << " | energy after rescaling = " << rescaled_eN2 );
330 ATH_MSG_DEBUG ( " " << (1.-m_xtalkScaleEta)*eN2 + m_xtalkScaleEta*e
331 << " | " << (theCellN2->energy()-eN2) );
332 }
333 if (theCellN3) {
334 ATH_MSG_DEBUG ( "EMEC3 cell (N3): energy before = " << eN3 << " | energy after rescaling = " << rescaled_eN3 );
335 ATH_MSG_DEBUG ( " " << (1.-m_xtalkScaleEta)*eN3 + m_xtalkScaleEta*e
336 << " | " << (theCellN3->energy()-eN3) );
337 }
338 /*
339 if (theCellN4) {
340 log << MSG::DEBUG << "EMEC2 cell (N4): energy before = " << eN4 << " | energy after rescaling = " << rescaled_eN4 << endmsg;
341 log << MSG::DEBUG << " " << (1.-m_xtalkScaleEMEC2Eta)*eN4 + m_xtalkScaleEMEC2Eta*e
342 << " | " << (theCellN4->energy()-eN4) << endmsg;
343 }
344 if (theCellN5) {
345 log << MSG::DEBUG << "EMEC2 cell (N5): energy before = " << eN5 << " | energy after rescaling = " << rescaled_eN5 << endmsg;
346 log << MSG::DEBUG << " " << (1.-m_xtalkScaleEMEC2Eta)*eN5 + m_xtalkScaleEMEC2Eta*e
347 << " | " << (theCellN5->energy()-eN5) << endmsg;
348 }
349 */
350 theCell ->setEnergy(rescaled_e);
351 if (theCellN1) theCellN1->setEnergy(rescaled_eN1);
352 if (theCellN2) theCellN2->setEnergy(rescaled_eN2);
353 if (theCellN3) theCellN3->setEnergy(rescaled_eN3);
354 //if (theCellN4) theCellN4->setEnergy(rescaled_eN4);
355 //if (theCellN5) theCellN5->setEnergy(rescaled_eN5);
356 }
357 }
358 }
359 return StatusCode::SUCCESS;
360}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
static Double_t sc
Container class for CaloCell.
CaloCellContainer::iterator beginCalo(CaloCell_ID::SUBCALO caloNum)
get non const iterators on cell of just one calo
bool hasCalo(const CaloCell_ID::SUBCALO caloNum) const
tell wether it has been filled with cells (maybe none) of a given calo
CaloCellContainer::iterator endCalo(CaloCell_ID::SUBCALO caloNum)
CaloCell_Base_ID::SUBCALO SUBCALO
Definition CaloCell_ID.h:50
CaloSampling::CaloSample CaloSample
Definition CaloCell_ID.h:53
Data object for each calorimeter readout cell.
Definition CaloCell.h:57
double energy() const
get energy (data member)
Definition CaloCell.h:327
const CaloDetDescrElement * caloDDE() const
get pointer to CaloDetDescrElement (data member)
Definition CaloCell.h:321
virtual void setEnergy(float energy)
set energy
Definition CaloCell.h:472
Identifier ID() const
get ID (from cached data member) non-virtual and inline for fast access
Definition CaloCell.h:295
This class groups all DetDescr information related to a CaloCell.
CaloCell_ID::CaloSample getSampling() const
cell sampling
bool is_lar_em_endcap_inner() const
cell belongs to the inner wheel of EM end cap
DataModel_detail::iterator< DataVector > iterator
Definition DataVector.h:842
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.
This is a "hash" representation of an Identifier.
StatusCode processOnCellIterators(const CaloCellContainer::iterator &itrCellBeg, const CaloCellContainer::iterator &itrCellEnd) const
virtual StatusCode process(CaloCellContainer *theCellContainer, const EventContext &ctx) const override
virtual StatusCode initialize() override
std::vector< int > m_caloNums
const CaloCell_ID * m_calo_id
TBEMECXTalkToyModel(const std::string &type, const std::string &name, const IInterface *parent)
Definition index.py:1