ATLAS Offline Software
Loading...
Searching...
No Matches
TileFCSmStepToTileHitVec.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 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 , m_geoModSvc("GeoModelSvc",name)
52 , m_FCS_StepInfo ("MergedEventSteps")
53 , m_hitVec ("TileHitVec_FCS")
54 , m_infoName ("TileInfo")
55 , m_tileID(nullptr)
56 , m_tileInfo(nullptr)
57 , m_tileMgr(nullptr)
58 , m_calc("TileGeoG4SDCalc", name)
59 , m_deltaT(0.5 * Gaudi::Units::nanosecond)
60 , m_allHits(0)
61 , m_uShape(-1)
62{
63 declareProperty( "GeoModelSvc", m_geoModSvc );
64 declareProperty( "TileCalculator", m_calc);
65 declareProperty("StepInfoCollection", m_FCS_StepInfo, "Name of input container (default=TileHitCnt)");
66 declareProperty("TileHitVector", m_hitVec, "Name of output hit vector (default=TileHitVec)");
67 declareProperty("TileInfoName", m_infoName, "Name of TileInfo store (default=TileInfo");
68 declareProperty("DeltaT", m_deltaT, "Minimal Time granularity in TileHit (default=0.5ns)");
69
70}
71
72
73//****************************************************************************
74//* Destructor
75//****************************************************************************
78
79
80//****************************************************************************
81//* Initialization
82//****************************************************************************
84{
85 ATH_CHECK( m_calc.retrieve() );
86 // retrieve Tile detector manager, TileID helper and TileIfno from det store
87 ATH_CHECK( detStore()->retrieve(m_tileMgr) );
88 ATH_CHECK( detStore()->retrieve(m_tileID) );
89 ATH_CHECK( detStore()->retrieve(m_tileInfo, m_infoName) );
90 ATH_CHECK(m_geoModSvc.retrieve());
91 ATH_MSG_VERBOSE("GeoModelSvc initialized.");
92
93 m_uShape = this->getUshapeFromGM();
94 if (m_uShape < -2) {
95 ATH_MSG_WARNING("Changing U-shape from " << m_uShape << " to -2");
96 m_uShape = -2;
97 }
98 if (m_uShape > 1 && m_uShape < 10) {
99 ATH_MSG_WARNING("Changing U-shape from " << m_uShape << " to 1");
100 m_uShape = 1;
101 }
102
103 return StatusCode::SUCCESS;
104}
105
107 const TileDetectorTool* tileDetectorTool =
108 dynamic_cast<const TileDetectorTool *>(m_geoModSvc->getTool("TileDetectorTool"));
109 return (tileDetectorTool) ? tileDetectorTool->uShape() : 0;
110}
111
112
113//****************************************************************************
114//* Execution
115//****************************************************************************
117{
118 ATH_MSG_DEBUG( "Execution beginning" );
119
120 m_allHits.clear();
121 m_allHits.resize(m_tileID->pmt_hash_max(),0);
122 int nHit = 0;
123 float Etot = 0.0;
124 int newHits = 0;
125 int sum_size = 0;
126 const double tile_radius[13] = { 2300.,
127 2400., 2500., 2600.,
128 2730., 2860., 2990.,
129 3140., 3290., 3440.,
130 3640., 3820.,
131 3820.01 };
132
133 const double M_PI_32 = M_PI/32.;
134 const double M_PI_64 = M_PI/64.;
135 const double TAN_PI_64 = tan(M_PI/64.);
136
137 // size is amaller than master plate and there is a gap between modules
138 const double size_correction = 2.75 + 1.5/2.;
139
140 const ISF_FCS_Parametrization::FCS_StepInfoCollection* inCollect = nullptr;
141 std::unique_ptr<TileHitVector> FCS_hits = std::make_unique<TileHitVector>();
142
143 // Get FCS_StepInfo from FCS_StepInfoCollection
144 ATH_CHECK(evtStore()->retrieve(inCollect,m_FCS_StepInfo)); //FIXME use a ReadHandle
145
146 IdContext pmt_context = m_tileID->pmt_context();
147
148 // Iterating over Steps, creating new TileHits
149 for(const ISF_FCS_Parametrization::FCS_StepInfo* stepInfo : *inCollect) {
150 Identifier hit_id = stepInfo->identify();
151 if (m_tileID->is_tile(hit_id)) {
152 double ene = stepInfo->energy();
153 double time = stepInfo->time();
154
155 IdentifierHash hit_idhash;
156 m_tileID->get_hash(hit_id, hit_idhash, &pmt_context);
157
158 if (m_uShape < 0) { // do not change anything for negative uShape values
159
160 if ( ! m_allHits[hit_idhash] ) {
161 m_allHits[hit_idhash] = new TileHit(hit_id,ene,time);
162 ++newHits;
163 // ATH_MSG_INFO(
165 "Iterating over Steps: new hit with id " << m_tileID->to_string(hit_id,-1)
166 << " nHit=" << nHit << " energy=" << ene << " time=" << time);
167 } else {
168 m_allHits[hit_idhash]->add(ene,time,m_deltaT);
169 // ATH_MSG_INFO(
171 "Iterating over Steps: extra hit with id " << m_tileID->to_string(hit_id,-1)
172 << " nHit=" << nHit << " energy=" << ene << " time=" << time);
173 }
174
175 } else {
176
177 int section = m_tileID->section(hit_id);
178 int side = m_tileID->side(hit_id);
179 int module = m_tileID->module(hit_id);
180 int sample = m_tileID->sample(hit_id);
181
182 bool Ecell = (sample == 3);
183 bool spC10 = (section == 3 && sample == 1 &&
184 ((module >= 38 && module <= 41) || (module >= 54 && module <= 57)));
185
186 if ( Ecell || spC10 ) {
187 if ( ! m_allHits[hit_idhash] ) {
188 m_allHits[hit_idhash] = new TileHit(hit_id,ene,time);
189 // ATH_MSG_INFO(
191 "Iterating over Steps: new E/C10 hit with id " << m_tileID->to_string(hit_id,-1)
192 << " nHit=" << nHit << " energy=" << ene );
193 ++newHits;
194 } else {
195 m_allHits[hit_idhash]->add(ene,time,m_deltaT);
196 // ATH_MSG_INFO(
198 "Iterating over Steps: extra E/C10 hit with id " << m_tileID->to_string(hit_id,-1)
199 << " nHit=" << nHit << " energy=" << ene );
200 }
201
202 } else { //cell have two pmt
203
204 double x = stepInfo->x(); // coordinates of the hit
205 double y = stepInfo->y(); // coordinates of the hit
206 int pmt = m_tileID->pmt(hit_id); // original pmt index
207 double edep[2];
208 Identifier cell_id = m_tileID->cell_id(hit_id);
209
210 double phi_module=(module + 0.5) * M_PI_32;
211 double phi_hit = atan2(y,x);
212 if (phi_hit<0) phi_hit += 2*M_PI;
213 double dphi = phi_hit - phi_module; // should be in the range [-pi/64, pi/64]
214 if (dphi < -M_PI_64 || dphi > M_PI_64) {
215 ATH_MSG_ERROR( "Displaced hit with id " << m_tileID->to_string(hit_id,-1)
216 << " x " << x << " y " << y
217 << " phi_module " << phi_module << " phi_hit " << phi_hit
218 << " dphi " << dphi );
219 // correcting dphi
220 dphi -= trunc(dphi/M_PI_64) * M_PI_64;
221 }
222
223 double radius = sqrt(x*x+y*y);
224 double radius_corrected = radius * cos(dphi);
225 double yLocal = radius * sin(dphi); // if negative, we are closer to pmt with index 0
226 double zLocal = radius * cos(dphi);
227 double halfYLocal = radius_corrected * TAN_PI_64 - size_correction;
228 if (fabs(yLocal) > halfYLocal) {
229 ATH_MSG_ERROR( "Displaced hit with id " << m_tileID->to_string(hit_id,-1)
230 << " x " << x << " y " << y
231 << " radius_corr " << radius_corrected
232 << " yLocal " << yLocal << " halfYlocal_corr " << halfYLocal
233 << " delta " << fabs(yLocal) - halfYLocal );
234 // correcting yLocal
235 yLocal = copysign(halfYLocal,yLocal);
236 }
237
238 // tile row or tile index - number from 0 to 10
239 int tile_ind = std::lower_bound (tile_radius, tile_radius+12,radius_corrected)-tile_radius-1;
240 if (tile_ind < 0 || tile_ind > 10 ) {
241 ATH_MSG_ERROR( "Displaced hit with id " << m_tileID->to_string(hit_id,-1)
242 << " x " << x << " y " << y
243 << " radius " << radius << " corrected " << radius_corrected
244 << " tile_index " << tile_ind );
245 // correcting tile index
246 if (tile_ind<0) tile_ind = 0;
247 if (tile_ind>10) tile_ind = 10;
248 }
249 TileHitData hitData;
250 hitData.tileSize = tile_ind;
251 hitData.nDetector = section;
252 hitData.nSide = side;
253 m_calc->pmtEdepFromFCS_StepInfo(hitData, ene, yLocal, halfYLocal, zLocal, m_uShape);
254 edep[0] = hitData.edep_down;
255 edep[1] = hitData.edep_up;
256
257 for (int pm=0; pm<2; ++pm) {
258 // changing hit_id, - use proper pm index (0 or 1) for down/up pmt
259 hit_id = m_tileID->pmt_id(cell_id,pm);
260 m_tileID->get_hash(hit_id, hit_idhash, &pmt_context);
261
262 double tim=time;
263 if (pm != pmt) { // need to correct time
264 const double ref_ind_tile = 1.59;
265 const double inv_speed = ref_ind_tile / CLHEP::c_light;
266 if (pmt) tim -= 2 * yLocal * inv_speed;
267 else tim += 2 * yLocal * inv_speed;
268 }
269
270 if ( ! m_allHits[hit_idhash] ) {
271 m_allHits[hit_idhash] = new TileHit(hit_id,edep[pm],tim,m_deltaT);
272 ++newHits;
273 // ATH_MSG_INFO(
275 "Iterating over Steps: new hit with id " << m_tileID->to_string(hit_id,-1)
276 << " nHit=" << nHit << " pmt " << pmt << " energy=" << edep[pm] << " time="
277 << time << " + " << tim-time << " = " << tim);
278 } else {
279 m_allHits[hit_idhash]->add(edep[pm],tim,m_deltaT);
280 // ATH_MSG_INFO(
282 "Iterating over Steps: extra hit with id " << m_tileID->to_string(hit_id,-1)
283 << " nHit=" << nHit << " pmt " << pmt << " energy=" << edep[pm] << " time="
284 << time << " + " << tim-time << " = " << tim);
285 }
286 }
287
288 }//cell have two pmt
289
290 }//m_uShape >= 0
291
292 ++nHit;
293 Etot += ene;
294 }//is_tile(hit_id)
295
296 }//Iterating over Steps
297
298 ATH_MSG_DEBUG( "End of Iterating over Steps: nHit=" << nHit << " newHits=" << newHits << " Etot=" << Etot );
299 // ATH_MSG_INFO( "End of Iterating over Steps: nHit=" << nHit << " newHits=" << newHits << " Etot=" << Etot );
300 nHit = 0;
301 Etot = 0.0;
302
303 // Addition of each TileHit to the TileHitVector
304 std::vector<TileHit*>::const_iterator curr = m_allHits.begin();
305 std::vector<TileHit*>::const_iterator iend = m_allHits.end();
306 for ( ; curr != iend; ++curr) {
307 if (*curr) {
308 TileHit *pHit = (*curr);
309
310 // ATH_MSG_INFO(
312 "Iterating over Hits: nHit=" << nHit << " size="
313 << pHit->size() << " energy=" << pHit->energy() );
314 FCS_hits->push_back(*pHit);
315 ++nHit;
316 for (int ii=0; ii<pHit->size(); ++ii ) Etot += pHit->energy(ii);
317 sum_size += pHit->size();
318 }
319 }
320
321 // Register the set of TileHits to the event store
322 CHECK( evtStore()->record(std::move(FCS_hits), m_hitVec, false ) );
323
324 ATH_MSG_DEBUG( "Execution completed, nHit=" << nHit << " sum_size=" << sum_size << " Etot=" << Etot );
325 // ATH_MSG_INFO( "Execution completed, nHit=" << nHit << " sum_size=" << sum_size << " Etot=" << Etot );
326
327 return StatusCode::SUCCESS;
328}
329
330//****************************************************************************
331//* Finalize
332//****************************************************************************
334{
335 ATH_MSG_INFO( "Finalized successfully" );
336
337 return StatusCode::SUCCESS;
338}
339
#define M_PI
#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)
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 with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
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.
TileFCSmStepToTileHitVec(const std::string &name, ISvcLocator *pSvcLocator)
const TileDetDescrManager * m_tileMgr
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