ATLAS Offline Software
FCS_StepInfoSD.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "FCS_StepInfoSD.h"
6 
7 #include <utility>
8 
9 #include "CaloDetDescr/CaloDetDescrElement.h"
15 #include "CaloIdentifier/TileID.h"
16 #include "G4Step.hh"
17 #include "G4ThreeVector.hh"
20 
22  : G4VSensitiveDetector(std::move(a_name)),
23  m_config(config),
24  m_calo_dd_man(nullptr) {}
25 
26 G4bool FCS_StepInfoSD::ProcessHits(G4Step*, G4TouchableHistory*) {
27  G4ExceptionDescription description;
28  description << "ProcessHits: Base class method should not be called!!!";
29  G4Exception("FCS_StepInfoSD", "FCSBadCall", FatalException, description);
30  abort();
31  return false;
32 }
33 
35  const CaloCell_ID::CaloSample& layer) const {
38  return m_config.m_maxTimeLAr;
39  }
41  return m_config.m_maxTimeHEC;
42  }
44  return m_config.m_maxTimeFCAL;
45  }
46  return m_config.m_maxTime;
47 }
48 
50  SG::ReadCondHandleKey<CaloDetDescrManager> caloMgrKey{"CaloDetDescrManager"};
51  if (caloMgrKey.initialize().isFailure()) {
52  G4ExceptionDescription description;
53  description << "Failed to get CaloDetDescrManager!";
54  G4Exception("FCS_StepInfoSD", "FCSBadCall", FatalException, description);
55  abort();
56  }
58  caloMgrKey, Gaudi::Hive::currentContext());
59  m_calo_dd_man.set(*caloMgr);
60 }
61 
62 void FCS_StepInfoSD::update_map(const CLHEP::Hep3Vector& l_vec,
63  const Identifier& l_identifier, double l_energy,
64  double l_time, bool l_valid,
65  int l_detector) // TODO: is the "&" needed?
66 {
67  // NB l_identifier refers to:
68  // - the cell identifier for LAr
69  // - the PMT identifier for Tile
70 
71  // Drop any hits that don't have a good identifier attached
72  if (!m_calo_dd_man.get()->get_element(l_identifier)) {
73  if (m_config.verboseLevel > 4) {
74  G4cout << this->GetName() << " DEBUG update_map: bad identifier: "
75  << l_identifier.getString() << " skipping this hit." << G4endl;
76  }
77  return;
78  }
79 
80  auto map_item = m_hit_map.find(l_identifier);
81  if (map_item == m_hit_map.end()) {
82  m_hit_map[l_identifier] =
83  new std::vector<ISF_FCS_Parametrization::FCS_StepInfo*>;
84  m_hit_map[l_identifier]->reserve(200);
85  m_hit_map[l_identifier]->push_back(
86  new ISF_FCS_Parametrization::FCS_StepInfo(l_vec, l_identifier, l_energy,
87  l_time, l_valid, l_detector));
88  } else {
89 
90  // Get the appropriate merging limits
92  m_calo_dd_man.get()->get_element(l_identifier)->getSampling();
93 
94  double timeWindow = m_config.m_maxTime;
95  const double distWinLong = m_config.m_maxRadiusLongitudinal.at(layer);
96  const double distWinLat = m_config.m_maxRadiusLateral.at(layer);
97 
98  const double tsame(this->getMaxTime(layer));
99  bool match = false;
100  for (auto* map_it : *map_item->second) {
101  // Time check ... both a global flag and a check on the layer
102  const double delta_t = std::fabs(map_it->time() - l_time);
103  if (delta_t >= tsame) {
104  continue;
105  }
106  if (delta_t >= timeWindow) {
107  continue;
108  }
109 
110  // Distance check
111  const CLHEP::Hep3Vector& currentPosition = map_it->position();
112  const double currentPosition_mag = currentPosition.mag();
113  const double proj_longitudinal =
114  currentPosition.dot(l_vec) / currentPosition_mag;
115  const double delta_longitudinal = currentPosition_mag - proj_longitudinal;
116  if (std::fabs(delta_longitudinal) >= distWinLong) {
117  continue;
118  }
119 
120  // Lateral distance check
121  double delta_lateral_2 = l_vec.mag2() - proj_longitudinal * proj_longitudinal;
122  if (delta_lateral_2 < 0) {
123  delta_lateral_2 = 0; // Avoid negative square root
124  }
125  const double delta_lateral =
126  std::sqrt(delta_lateral_2);
127  if (delta_lateral >= distWinLat) {
128  continue;
129  }
130 
131  // Found a match. Make a temporary that will be deleted!
133  l_vec, l_identifier, l_energy, l_time, l_valid, l_detector);
134  *map_it += my_info;
135  match = true;
136  break;
137  } // End of search for match in time and space
138  if (!match) {
139  map_item->second->push_back(new ISF_FCS_Parametrization::FCS_StepInfo(
140  l_vec, l_identifier, l_energy, l_time, l_valid, l_detector));
141  } // Didn't match
142  } // ID already in the map
143  return;
144 } // That's it for updating the map!
145 
148  // Unpack map into vector
149  for (auto it : m_hit_map) {
150  for (auto* a_s : *it.second) {
151  // Giving away ownership of the objects!
152  hitContainer->push_back(a_s);
153  }
154  it.second->clear();
155  delete it.second;
156  } // Vector of IDs in the map
157  m_hit_map.clear();
158  if (m_config.verboseLevel > 4) {
159  G4cout << this->GetName()
160  << " DEBUG EndOfAthenaEvent: After initial cleanup, N="
161  << hitContainer->size() << G4endl;
162  }
163  return;
164 }
LArEM_ID.h
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
FCS_Param::Config::m_maxRadiusLateral
std::vector< double > m_maxRadiusLateral
property, see LArG4GenShowerLib::LArG4GenShowerLib
Definition: FCS_StepInfoSD.h:46
FCS_StepInfoSD.h
FCS_StepInfoSD::getCaloDDManager
void getCaloDDManager()
Keep a map instead of trying to keep the full vector.
Definition: FCS_StepInfoSD.cxx:49
LArID_Exception.h
skel.it
it
Definition: skel.GENtoEVGEN.py:407
FCS_StepInfoSD::getMaxTime
double getMaxTime(const CaloCell_ID::CaloSample &layer) const
Definition: FCS_StepInfoSD.cxx:34
FCS_StepInfoSD::update_map
void update_map(const CLHEP::Hep3Vector &l_vec, const Identifier &l_identifier, double l_energy, double l_time, bool l_valid, int l_detector)
Definition: FCS_StepInfoSD.cxx:62
FCS_StepInfoSD::m_calo_dd_man
CxxUtils::CachedPointer< const CaloDetDescrManager > m_calo_dd_man
Definition: FCS_StepInfoSD.h:106
LArHEC_ID.h
ReadCondHandle.h
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
TileID.h
CxxUtils::CachedPointer::set
void set(pointer_t elt) const
Set the element, assuming it is currently null.
FCS_StepInfoSD::FCS_StepInfoSD
FCS_StepInfoSD(G4String a_name, const FCS_Param::Config &config)
Constructor.
Definition: FCS_StepInfoSD.cxx:21
FCS_Param::Config::m_maxRadiusLongitudinal
std::vector< double > m_maxRadiusLongitudinal
property, see LArG4GenShowerLib::LArG4GenShowerLib
Definition: FCS_StepInfoSD.h:49
CaloSampling::CaloSample
CaloSample
Definition: Calorimeter/CaloGeoHelpers/CaloGeoHelpers/CaloSampling.h:22
TRT::Hit::layer
@ layer
Definition: HitInfo.h:79
FCS_Param::Config::m_maxTime
double m_maxTime
Definition: FCS_StepInfoSD.h:53
FCS_Param::Config::m_maxTimeFCAL
double m_maxTimeFCAL
Definition: FCS_StepInfoSD.h:56
ReadCondHandleKey.h
CaloCell_ID_FCS::EME3
@ EME3
Definition: FastCaloSim_CaloCell_ID.h:26
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
FCS_StepInfoSD::EndOfAthenaEvent
void EndOfAthenaEvent(ISF_FCS_Parametrization::FCS_StepInfoCollection *hitContnainer)
End of athena event processing.
Definition: FCS_StepInfoSD.cxx:146
FCS_Param::Config::m_maxTimeHEC
double m_maxTimeHEC
Definition: FCS_StepInfoSD.h:55
ISF_FCS_Parametrization::FCS_StepInfo
Definition: FCS_StepInfo.h:45
CaloCell_ID_FCS::HEC0
@ HEC0
Definition: FastCaloSim_CaloCell_ID.h:27
SG::ReadCondHandleKey< CaloDetDescrManager >
LArFCAL_ID.h
Identifier::getString
std::string getString() const
Provide a string form of the identifier - hexadecimal.
Definition: Identifier.cxx:25
FCS_Param::Config::m_maxTimeLAr
double m_maxTimeLAr
Definition: FCS_StepInfoSD.h:54
CaloCell_ID_FCS::PreSamplerB
@ PreSamplerB
Definition: FastCaloSim_CaloCell_ID.h:19
CxxUtils::CachedPointer::get
pointer_t get() const
Return the current value of the element.
ISF_FCS_Parametrization::FCS_StepInfoCollection
Class for collection of StepInfo class (G4 hits) copied and modified version to ISF.
Definition: FCS_StepInfoCollection.h:30
CaloIdManager.h
CaloCell_ID_FCS::FCAL2
@ FCAL2
Definition: FastCaloSim_CaloCell_ID.h:42
FCS_StepInfoSD::m_config
FCS_Param::Config m_config
Definition: FCS_StepInfoSD.h:100
CaloCell_ID_FCS::HEC3
@ HEC3
Definition: FastCaloSim_CaloCell_ID.h:30
FCS_Param::Config
Definition: FCS_StepInfoSD.h:37
CaloCell_ID_FCS::FCAL0
@ FCAL0
Definition: FastCaloSim_CaloCell_ID.h:40
FCS_Param::Config::verboseLevel
int verboseLevel
Helper to keep the same verbosity everywhere.
Definition: FCS_StepInfoSD.h:39
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
FCS_StepInfoSD::ProcessHits
virtual G4bool ProcessHits(G4Step *a_step, G4TouchableHistory *) override
Main processing method.
Definition: FCS_StepInfoSD.cxx:26
match
bool match(std::string s1, std::string s2)
match the individual directories of two strings
Definition: hcg.cxx:356
FCS_StepInfoSD::m_hit_map
std::map< Identifier, std::vector< ISF_FCS_Parametrization::FCS_StepInfo * > * > m_hit_map
Definition: FCS_StepInfoSD.h:108
description
std::string description
glabal timer - how long have I taken so far?
Definition: hcg.cxx:88
Identifier
Definition: IdentifierFieldParser.cxx:14