ATLAS Offline Software
Loading...
Searching...
No Matches
TileFCSmStepToTileHitVec.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// Filename : TileFCSmStepToTileHitVec.cxx
7// Author : Sergey Karpov <Sergey.Karpov@cern.ch>
8// Created : Nov. 2013
9//
10// DESCRIPTION:
11// Only implementation comments. Class level comments are in *.h file
12//
13// HISTORY:
14// 01 Nov 2013 - Created from TileCellIDCToCell.cxx
15// 28 Nov 2013 - Work with U-shape was added (Sasha Solodkov)
16//
17// BUGS:
18//
19//*****************************************************************************
20
21// access to all containers
24#include "GaudiKernel/SystemOfUnits.h"
25#include "CLHEP/Units/SystemOfUnits.h"
26
29
30// Calo includes
33
34// Tile includes
40
41// ISF_FCS_Parametrization includes
43
44#include "CLHEP/Units/PhysicalConstants.h"
45
46//****************************************************************************
47//* Constructor
48//****************************************************************************
49TileFCSmStepToTileHitVec::TileFCSmStepToTileHitVec(const std::string& name, ISvcLocator* pSvcLocator)
50 : AthAlgorithm(name, pSvcLocator)
51{
52}
53
54
55//****************************************************************************
56//* Destructor
57//****************************************************************************
60
61
62//****************************************************************************
63//* Initialization
64//****************************************************************************
66{
67 ATH_CHECK( m_calc.retrieve() );
68 // retrieve Tile detector manager, TileID helper and TileIfno from det store
69 ATH_CHECK( detStore()->retrieve(m_tileMgr) );
70 ATH_CHECK( detStore()->retrieve(m_tileID) );
71 ATH_CHECK( detStore()->retrieve(m_tileInfo, m_infoName.value()) );
72 ATH_CHECK(m_geoModSvc.retrieve());
73 ATH_MSG_VERBOSE("GeoModelSvc initialized.");
74
75 m_uShape = this->getUshapeFromGM();
76 if (m_uShape < -2) {
77 ATH_MSG_WARNING("Changing U-shape from " << m_uShape << " to -2");
78 m_uShape = -2;
79 }
80 if (m_uShape > 1 && m_uShape < 10) {
81 ATH_MSG_WARNING("Changing U-shape from " << m_uShape << " to 1");
82 m_uShape = 1;
83 }
84
85 return StatusCode::SUCCESS;
86}
87
89 const TileDetectorTool* tileDetectorTool =
90 dynamic_cast<const TileDetectorTool *>(m_geoModSvc->getTool("TileDetectorTool"));
91 return (tileDetectorTool) ? tileDetectorTool->uShape() : 0;
92}
93
94
95//****************************************************************************
96//* Execution
97//****************************************************************************
98StatusCode TileFCSmStepToTileHitVec::execute(const EventContext& /*ctx*/)
99{
100 ATH_MSG_DEBUG( "Execution beginning" );
101
102 m_allHits.clear();
103 m_allHits.resize(m_tileID->pmt_hash_max(),0);
104 int nHit = 0;
105 float Etot = 0.0;
106 int newHits = 0;
107 int sum_size = 0;
108 const double tile_radius[13] = { 2300.,
109 2400., 2500., 2600.,
110 2730., 2860., 2990.,
111 3140., 3290., 3440.,
112 3640., 3820.,
113 3820.01 };
114
115 const double M_PI_32 = M_PI/32.;
116 const double M_PI_64 = M_PI/64.;
117 const double TAN_PI_64 = tan(M_PI/64.);
118
119 // size is amaller than master plate and there is a gap between modules
120 const double size_correction = 2.75 + 1.5/2.;
121
122 const ISF_FCS_Parametrization::FCS_StepInfoCollection* inCollect = nullptr;
123 std::unique_ptr<TileHitVector> FCS_hits = std::make_unique<TileHitVector>();
124
125 // Get FCS_StepInfo from FCS_StepInfoCollection
126 ATH_CHECK(evtStore()->retrieve(inCollect,m_FCS_StepInfo.value())); //FIXME use a ReadHandle
127
128 IdContext pmt_context = m_tileID->pmt_context();
129
130 // Iterating over Steps, creating new TileHits
131 for(const ISF_FCS_Parametrization::FCS_StepInfo* stepInfo : *inCollect) {
132 Identifier hit_id = stepInfo->identify();
133 if (m_tileID->is_tile(hit_id)) {
134 double ene = stepInfo->energy();
135 double time = stepInfo->time();
136
137 IdentifierHash hit_idhash;
138 m_tileID->get_hash(hit_id, hit_idhash, &pmt_context);
139
140 if (m_uShape < 0) { // do not change anything for negative uShape values
141
142 if ( ! m_allHits[hit_idhash] ) {
143 m_allHits[hit_idhash] = new TileHit(hit_id,ene,time);
144 ++newHits;
145 // ATH_MSG_INFO(
147 "Iterating over Steps: new hit with id " << m_tileID->to_string(hit_id,-1)
148 << " nHit=" << nHit << " energy=" << ene << " time=" << time);
149 } else {
150 m_allHits[hit_idhash]->add(ene,time,m_deltaT);
151 // ATH_MSG_INFO(
153 "Iterating over Steps: extra hit with id " << m_tileID->to_string(hit_id,-1)
154 << " nHit=" << nHit << " energy=" << ene << " time=" << time);
155 }
156
157 } else {
158
159 int section = m_tileID->section(hit_id);
160 int side = m_tileID->side(hit_id);
161 int module = m_tileID->module(hit_id);
162 int sample = m_tileID->sample(hit_id);
163
164 bool Ecell = (sample == 3);
165 bool spC10 = (section == 3 && sample == 1 &&
166 ((module >= 38 && module <= 41) || (module >= 54 && module <= 57)));
167
168 if ( Ecell || spC10 ) {
169 if ( ! m_allHits[hit_idhash] ) {
170 m_allHits[hit_idhash] = new TileHit(hit_id,ene,time);
171 // ATH_MSG_INFO(
173 "Iterating over Steps: new E/C10 hit with id " << m_tileID->to_string(hit_id,-1)
174 << " nHit=" << nHit << " energy=" << ene );
175 ++newHits;
176 } else {
177 m_allHits[hit_idhash]->add(ene,time,m_deltaT);
178 // ATH_MSG_INFO(
180 "Iterating over Steps: extra E/C10 hit with id " << m_tileID->to_string(hit_id,-1)
181 << " nHit=" << nHit << " energy=" << ene );
182 }
183
184 } else { //cell have two pmt
185
186 double x = stepInfo->x(); // coordinates of the hit
187 double y = stepInfo->y(); // coordinates of the hit
188 int pmt = m_tileID->pmt(hit_id); // original pmt index
189 double edep[2];
190 Identifier cell_id = m_tileID->cell_id(hit_id);
191
192 double phi_module=(module + 0.5) * M_PI_32;
193 double phi_hit = atan2(y,x);
194 if (phi_hit<0) phi_hit += 2*M_PI;
195 double dphi = phi_hit - phi_module; // should be in the range [-pi/64, pi/64]
196 if (dphi < -M_PI_64 || dphi > M_PI_64) {
197 ATH_MSG_ERROR( "Displaced hit with id " << m_tileID->to_string(hit_id,-1)
198 << " x " << x << " y " << y
199 << " phi_module " << phi_module << " phi_hit " << phi_hit
200 << " dphi " << dphi );
201 // correcting dphi
202 dphi -= trunc(dphi/M_PI_64) * M_PI_64;
203 }
204
205 double radius = sqrt(x*x+y*y);
206 double radius_corrected = radius * cos(dphi);
207 double yLocal = radius * sin(dphi); // if negative, we are closer to pmt with index 0
208 double zLocal = radius * cos(dphi);
209 double halfYLocal = radius_corrected * TAN_PI_64 - size_correction;
210 if (fabs(yLocal) > halfYLocal) {
211 ATH_MSG_ERROR( "Displaced hit with id " << m_tileID->to_string(hit_id,-1)
212 << " x " << x << " y " << y
213 << " radius_corr " << radius_corrected
214 << " yLocal " << yLocal << " halfYlocal_corr " << halfYLocal
215 << " delta " << fabs(yLocal) - halfYLocal );
216 // correcting yLocal
217 yLocal = copysign(halfYLocal,yLocal);
218 }
219
220 // tile row or tile index - number from 0 to 10
221 int tile_ind = std::lower_bound (tile_radius, tile_radius+12,radius_corrected)-tile_radius-1;
222 if (tile_ind < 0 || tile_ind > 10 ) {
223 ATH_MSG_ERROR( "Displaced hit with id " << m_tileID->to_string(hit_id,-1)
224 << " x " << x << " y " << y
225 << " radius " << radius << " corrected " << radius_corrected
226 << " tile_index " << tile_ind );
227 // correcting tile index
228 if (tile_ind<0) tile_ind = 0;
229 if (tile_ind>10) tile_ind = 10;
230 }
231 TileHitData hitData;
232 hitData.tileSize = tile_ind;
233 hitData.nDetector = section;
234 hitData.nSide = side;
235 m_calc->pmtEdepFromFCS_StepInfo(hitData, ene, yLocal, halfYLocal, zLocal, m_uShape);
236 edep[0] = hitData.edep_down;
237 edep[1] = hitData.edep_up;
238
239 for (int pm=0; pm<2; ++pm) {
240 // changing hit_id, - use proper pm index (0 or 1) for down/up pmt
241 hit_id = m_tileID->pmt_id(cell_id,pm);
242 m_tileID->get_hash(hit_id, hit_idhash, &pmt_context);
243
244 double tim=time;
245 if (pm != pmt) { // need to correct time
246 const double ref_ind_tile = 1.59;
247 const double inv_speed = ref_ind_tile / CLHEP::c_light;
248 if (pmt) tim -= 2 * yLocal * inv_speed;
249 else tim += 2 * yLocal * inv_speed;
250 }
251
252 if ( ! m_allHits[hit_idhash] ) {
253 m_allHits[hit_idhash] = new TileHit(hit_id,edep[pm],tim,m_deltaT);
254 ++newHits;
255 // ATH_MSG_INFO(
257 "Iterating over Steps: new hit with id " << m_tileID->to_string(hit_id,-1)
258 << " nHit=" << nHit << " pmt " << pmt << " energy=" << edep[pm] << " time="
259 << time << " + " << tim-time << " = " << tim);
260 } else {
261 m_allHits[hit_idhash]->add(edep[pm],tim,m_deltaT);
262 // ATH_MSG_INFO(
264 "Iterating over Steps: extra hit with id " << m_tileID->to_string(hit_id,-1)
265 << " nHit=" << nHit << " pmt " << pmt << " energy=" << edep[pm] << " time="
266 << time << " + " << tim-time << " = " << tim);
267 }
268 }
269
270 }//cell have two pmt
271
272 }//m_uShape >= 0
273
274 ++nHit;
275 Etot += ene;
276 }//is_tile(hit_id)
277
278 }//Iterating over Steps
279
280 ATH_MSG_DEBUG( "End of Iterating over Steps: nHit=" << nHit << " newHits=" << newHits << " Etot=" << Etot );
281 // ATH_MSG_INFO( "End of Iterating over Steps: nHit=" << nHit << " newHits=" << newHits << " Etot=" << Etot );
282 nHit = 0;
283 Etot = 0.0;
284
285 // Addition of each TileHit to the TileHitVector
286 std::vector<TileHit*>::const_iterator curr = m_allHits.begin();
287 std::vector<TileHit*>::const_iterator iend = m_allHits.end();
288 for ( ; curr != iend; ++curr) {
289 if (*curr) {
290 TileHit *pHit = (*curr);
291
292 // ATH_MSG_INFO(
294 "Iterating over Hits: nHit=" << nHit << " size="
295 << pHit->size() << " energy=" << pHit->energy() );
296 FCS_hits->push_back(*pHit);
297 ++nHit;
298 for (int ii=0; ii<pHit->size(); ++ii ) Etot += pHit->energy(ii);
299 sum_size += pHit->size();
300 }
301 }
302
303 // Register the set of TileHits to the event store
304 CHECK( evtStore()->record(std::move(FCS_hits), m_hitVec.value(), false ) );
305
306 ATH_MSG_DEBUG( "Execution completed, nHit=" << nHit << " sum_size=" << sum_size << " Etot=" << Etot );
307 // ATH_MSG_INFO( "Execution completed, nHit=" << nHit << " sum_size=" << sum_size << " Etot=" << Etot );
308
309 return StatusCode::SUCCESS;
310}
311
312//****************************************************************************
313//* Finalize
314//****************************************************************************
316{
317 ATH_MSG_INFO( "Finalized successfully" );
318
319 return StatusCode::SUCCESS;
320}
321
#define M_PI
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_WARNING(x,...)
#define ATH_MSG_VERBOSE(x,...)
#define ATH_MSG_INFO(x,...)
Helpers for checking error return status codes and reporting errors.
#define CHECK(...)
Evaluate an expression and check for errors.
void section(const std::string &sec)
#define y
#define x
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
ServiceHandle< StoreGateSvc > & evtStore()
const ServiceHandle< StoreGateSvc > & detStore() const
Class for collection of StepInfo class (G4 hits) copied and modified version to ISF.
This class saves the "context" of an expanded identifier (ExpandedIdentifier) for compact or hash ver...
Definition IdContext.h:26
This is a "hash" representation of an Identifier.
StatusCode execute(const EventContext &ctx)
Execute method.
Gaudi::Property< std::string > m_hitVec
Gaudi::Property< std::string > m_infoName
TileFCSmStepToTileHitVec(const std::string &name, ISvcLocator *pSvcLocator)
Gaudi::Property< float > m_deltaT
const TileDetDescrManager * m_tileMgr
Gaudi::Property< std::string > m_FCS_StepInfo
ServiceHandle< IGeoModelSvc > m_geoModSvc
std::vector< TileHit * > m_allHits
ServiceHandle< ITileCalculator > m_calc
float energy(int ind=0) const
Return energy of ind-th sub-hit.
int size(void) const
Return length of energy/time vectors.
Variables to identify Hit objects.
G4double edep_up
G4double edep_down