ATLAS Offline Software
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
31 #include "CaloIdentifier/TileID.h"
33 
34 // Tile includes
40 
41 // ISF_FCS_Parametrization includes
43 
44 #include "CLHEP/Units/PhysicalConstants.h"
45 
46 //****************************************************************************
47 //* Constructor
48 //****************************************************************************
49 TileFCSmStepToTileHitVec::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 //****************************************************************************
77 {}
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
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 
TileHitData::edep_down
G4double edep_down
Definition: ITileCalculator.h:62
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
FCS_StepInfoCollection.h
TileHitData::nSide
int nSide
Definition: ITileCalculator.h:52
TileFCSmStepToTileHitVec::m_tileID
const TileID * m_tileID
Definition: TileFCSmStepToTileHitVec.h:66
TileFCSmStepToTileHitVec::m_infoName
std::string m_infoName
Definition: TileFCSmStepToTileHitVec.h:64
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
TileFCSmStepToTileHitVec::m_tileMgr
const TileDetDescrManager * m_tileMgr
Definition: TileFCSmStepToTileHitVec.h:68
python.SystemOfUnits.nanosecond
int nanosecond
Definition: SystemOfUnits.py:119
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
Tile_Base_ID::pmt
int pmt(const Identifier &id) const
Definition: Tile_Base_ID.cxx:180
ReadBchFromCool.pmt
pmt
Definition: ReadBchFromCool.py:62
TileDetectorTool::uShape
int uShape() const
Definition: TileDetectorTool.h:31
Tile_Base_ID::side
int side(const Identifier &id) const
Definition: Tile_Base_ID.cxx:153
TileFCSmStepToTileHitVec::m_calc
ServiceHandle< ITileCalculator > m_calc
Definition: TileFCSmStepToTileHitVec.h:69
Tile_Base_ID::sample
int sample(const Identifier &id) const
Definition: Tile_Base_ID.cxx:171
M_PI
#define M_PI
Definition: ActiveFraction.h:11
TileInfo.h
drawFromPickle.cos
cos
Definition: drawFromPickle.py:36
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
x
#define x
TileFCSmStepToTileHitVec::m_hitVec
std::string m_hitVec
Definition: TileFCSmStepToTileHitVec.h:63
TileHitData
Variables to identify Hit objects.
Definition: ITileCalculator.h:45
TileHit::size
int size(void) const
Return length of energy/time vectors
Definition: TileSimEvent/TileSimEvent/TileHit.h:94
TileID.h
TileDetDescrManager.h
AthCommonDataStore< AthCommonMsg< Algorithm > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
TRT::Hit::side
@ side
Definition: HitInfo.h:83
python.PyAthena.module
module
Definition: PyAthena.py:134
AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
TileFCSmStepToTileHitVec::execute
StatusCode execute()
Definition: TileFCSmStepToTileHitVec.cxx:116
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
TileFCSmStepToTileHitVec::m_uShape
int m_uShape
Definition: TileFCSmStepToTileHitVec.h:74
Tile_Base_ID::module
int module(const Identifier &id) const
Definition: Tile_Base_ID.cxx:159
FullCPAlgorithmsTest_eljob.sample
sample
Definition: FullCPAlgorithmsTest_eljob.py:100
TileFCSmStepToTileHitVec::m_deltaT
float m_deltaT
Definition: TileFCSmStepToTileHitVec.h:71
TileDetectorTool.h
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
TileHitData::nDetector
int nDetector
Definition: ITileCalculator.h:49
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
TileFCSmStepToTileHitVec::~TileFCSmStepToTileHitVec
virtual ~TileFCSmStepToTileHitVec()
Definition: TileFCSmStepToTileHitVec.cxx:76
TileHitData::edep_up
G4double edep_up
Definition: ITileCalculator.h:61
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
AtlasDetectorID::is_tile
bool is_tile(Identifier id) const
Definition: AtlasDetectorID.h:695
drawFromPickle.tan
tan
Definition: drawFromPickle.py:36
TileFCSmStepToTileHitVec.h
TileFCSmStepToTileHitVec::m_geoModSvc
ServiceHandle< IGeoModelSvc > m_geoModSvc
Definition: TileFCSmStepToTileHitVec.h:61
AthAlgorithm
Definition: AthAlgorithm.h:47
Tile_Base_ID::get_hash
virtual int get_hash(const Identifier &id, IdentifierHash &hash_id, const IdContext *context=0) const
create hash id from compact id (return == 0 for OK)
Definition: Tile_Base_ID.cxx:1151
Athena::Units
Definition: Units.h:45
TileHitVector.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
errorcheck.h
Helpers for checking error return status codes and reporting errors.
TileHitData::tileSize
int tileSize
Definition: ITileCalculator.h:54
python.PhysicalConstants.c_light
float c_light
Definition: PhysicalConstants.py:63
TileFCSmStepToTileHitVec::finalize
StatusCode finalize()
Definition: TileFCSmStepToTileHitVec.cxx:333
TileHit
Definition: TileSimEvent/TileSimEvent/TileHit.h:30
CaloCellContainer.h
ParticleGun_SamplingFraction.radius
radius
Definition: ParticleGun_SamplingFraction.py:96
TileFCSmStepToTileHitVec::m_allHits
std::vector< TileHit * > m_allHits
Definition: TileFCSmStepToTileHitVec.h:72
ISF_FCS_Parametrization::FCS_StepInfo
Definition: FCS_StepInfo.h:45
Tile_Base_ID::pmt_hash_max
size_type pmt_hash_max(void) const
Definition: Tile_Base_ID.cxx:1318
y
#define y
TileFCSmStepToTileHitVec::m_tileInfo
const TileInfo * m_tileInfo
Definition: TileFCSmStepToTileHitVec.h:67
CaloSwCorrections.time
def time(flags, cells_name, *args, **kw)
Definition: CaloSwCorrections.py:242
Tile_Base_ID::to_string
std::string to_string(const Identifier &id, int level=0) const
Definition: Tile_Base_ID.cxx:52
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
TileHit::energy
float energy(int ind=0) const
Return energy of ind-th sub-hit
Definition: TileSimEvent/TileSimEvent/TileHit.h:90
Tile_Base_ID::pmt_id
Identifier pmt_id(const Identifier &any_id) const
Definition: Tile_Base_ID.cxx:640
TileFCSmStepToTileHitVec::m_FCS_StepInfo
std::string m_FCS_StepInfo
Definition: TileFCSmStepToTileHitVec.h:62
ITileCalculator.h
Tile_Base_ID::pmt_context
IdContext pmt_context(void) const
id for PMTs
Definition: Tile_Base_ID.cxx:1065
Gaudi
=============================================================================
Definition: CaloGPUClusterAndCellDataMonitorOptions.h:273
ISF_FCS_Parametrization::FCS_StepInfoCollection
Class for collection of StepInfo class (G4 hits) copied and modified version to ISF.
Definition: FCS_StepInfoCollection.h:30
TileDetectorTool
Definition: TileDetectorTool.h:17
TileFCSmStepToTileHitVec::initialize
StatusCode initialize()
Definition: TileFCSmStepToTileHitVec.cxx:83
TileFCSmStepToTileHitVec::getUshapeFromGM
int getUshapeFromGM() const
Definition: TileFCSmStepToTileHitVec.cxx:106
SelectAllObject.h
Tile_Base_ID::section
int section(const Identifier &id) const
Definition: Tile_Base_ID.cxx:147
drawFromPickle.sin
sin
Definition: drawFromPickle.py:36
IdentifierHash
Definition: IdentifierHash.h:38
section
void section(const std::string &sec)
Definition: TestTriggerMenuAccess.cxx:22
Tile_Base_ID::cell_id
Identifier cell_id(const Identifier &any_id) const
Definition: Tile_Base_ID.cxx:581
IGeoModelSvc.h
IdContext
class IdContext
Definition: IdContext.h:34
TileFCSmStepToTileHitVec::TileFCSmStepToTileHitVec
TileFCSmStepToTileHitVec(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TileFCSmStepToTileHitVec.cxx:49
AtlasHitsVector::push_back
void push_back(const T &t)
Definition: AtlasHitsVector.h:145