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 <utility>
6 
7 #include "FCS_StepInfoSD.h"
8 
14 #include "CaloIdentifier/TileID.h"
15 #include "CaloDetDescr/CaloDetDescrElement.h"
16 
19 
20 #include "G4Step.hh"
21 #include "G4ThreeVector.hh"
22 
24  : G4VSensitiveDetector(std::move(a_name))
25  , m_config(config)
26  , m_calo_dd_man(nullptr)
27 {
28 }
29 
30 G4bool FCS_StepInfoSD::ProcessHits(G4Step*,G4TouchableHistory*)
31 {
32  G4ExceptionDescription description;
33  description << "ProcessHits: Base class method should not be called!!!";
34  G4Exception("FCS_StepInfoSD", "FCSBadCall", FatalException, description);
35  abort();
36  return false;
37 }
38 
40 {
43  return m_config.m_maxTimeLAr;
44  }
46  return m_config.m_maxTimeHEC;
47  }
49  return m_config.m_maxTimeFCAL;
50  }
51  return m_config.m_maxTime;
52 }
53 
55 {
58  return m_config.m_maxRadiusLAr;
59  }
61  return m_config.m_maxRadiusHEC;
62  }
65  }
66  return m_config.m_maxRadius;
67 }
68 
70 {
72  if(m_config.m_maxRadiusLAr != 25) return 999.;
75  // PS default is 1mm in eta, 5mm in phi, no cut in r
76  return m_config.m_maxrPS;
77  }
79  // EM1 default is 1mm in eta, 5mm in phi, 15mm in r
80  return m_config.m_maxrEM1;
81  }
83  // EM2 default is 1mm in eta, 5mm in phi, 60mm in r
84  return m_config.m_maxrEM2;
85  }
87  // EM3 default is 1mm in eta, 5mm in phi, 8mm in r
88  return m_config.m_maxrEM3;
89  }
90  }
91  return 999.;
92 }
93 
95 {
97  if(m_config.m_maxRadiusLAr != 25) return 999.;
100  // PS default is 1mm in eta, 5mm in phi, no cut in r
101  return m_config.m_maxEtaPS;
102  }
104  // EM1 default is 1mm in eta, 5mm in phi, 15mm in r
105  return m_config.m_maxEtaEM1;
106  }
108  // EM2 default is 1mm in eta, 5mm in phi, 60mm in r
109  return m_config.m_maxEtaEM2;
110  }
112  // EM3 default is 1mm in eta, 5mm in phi, 8mm in r
113  return m_config.m_maxEtaEM3;
114  }
115  }
116  return 999.;
117 }
118 
120 {
122  if(m_config.m_maxRadiusLAr != 25) return 999.;
125  // PS default is 1mm in eta, 5mm in phi, no cut in r
126  return m_config.m_maxPhiPS;
127  }
129  // EM1 default is 1mm in eta, 5mm in phi, 15mm in r
130  return m_config.m_maxPhiEM1;
131  }
133  // EM2 default is 1mm in eta, 5mm in phi, 60mm in r
134  return m_config.m_maxPhiEM2;
135  }
137  // EM3 default is 1mm in eta, 5mm in phi, 8mm in r
138  return m_config.m_maxPhiEM3;
139  }
140  }
141  return 999.;
142 }
143 
144 
146 {
147  SG::ReadCondHandleKey<CaloDetDescrManager> caloMgrKey{"CaloDetDescrManager"};
148  if(caloMgrKey.initialize().isFailure()) {
149  G4ExceptionDescription description;
150  description << "Failed to get CaloDetDescrManager!";
151  G4Exception("FCS_StepInfoSD", "FCSBadCall", FatalException, description);
152  abort();
153  }
154  SG::ReadCondHandle<CaloDetDescrManager> caloMgr(caloMgrKey,Gaudi::Hive::currentContext());
155  m_calo_dd_man.set(*caloMgr);
156 }
157 
158 void FCS_StepInfoSD::update_map(const CLHEP::Hep3Vector & l_vec, const Identifier & l_identifier, double l_energy, double l_time, bool l_valid, int l_detector, double timeWindow, double distanceWindow)
159 {
160  // NB l_identifier refers to:
161  // - the cell identifier for LAr
162  // - the PMT identifier for Tile
163 
164  // Drop any hits that don't have a good identifier attached
165  if (!m_calo_dd_man.get()->get_element(l_identifier)) {
166  if(m_config.verboseLevel > 4) {
167  G4cout<<this->GetName()<<" DEBUG update_map: bad identifier: "<<l_identifier.getString()<<" skipping this hit."<<G4endl;
168  }
169  return;
170  }
171 
172  auto map_item = m_hit_map.find( l_identifier );
173  if (map_item==m_hit_map.end()) {
174  m_hit_map[l_identifier] = new std::vector< ISF_FCS_Parametrization::FCS_StepInfo* >;
175  m_hit_map[l_identifier]->reserve(200);
176  m_hit_map[l_identifier]->push_back( new ISF_FCS_Parametrization::FCS_StepInfo( l_vec , l_identifier , l_energy , l_time , l_valid , l_detector ) );
177  }
178  else {
179 
180  // Get the appropriate merging limits
181  const CaloCell_ID::CaloSample& layer = m_calo_dd_man.get()->get_element(l_identifier)->getSampling();
182  const double tsame(this->getMaxTime(layer));
183  bool match = false;
184  for (auto *map_it : * map_item->second) {
185  // Time check ... both a global flag and a check on the layer
186  const double delta_t = std::fabs(map_it->time()-l_time);
187  if ( delta_t >= tsame ) { continue; }
188  if ( delta_t >= timeWindow ) { continue; }
189 
190  // Distance check
191  const CLHEP::Hep3Vector & currentPosition = map_it->position();
192  const double hit_diff2 = currentPosition.diff2( l_vec );
193  // Global distance check
194  if ( hit_diff2 >= distanceWindow ) { continue; }
195 
196  // Found a match. Make a temporary that will be deleted!
197  const ISF_FCS_Parametrization::FCS_StepInfo my_info( l_vec , l_identifier , l_energy , l_time , l_valid , l_detector );
198  *map_it += my_info;
199  match = true;
200  break;
201  } // End of search for match in time and space
202  if (!match) {
203  map_item->second->push_back( new ISF_FCS_Parametrization::FCS_StepInfo( l_vec , l_identifier , l_energy , l_time , l_valid , l_detector ) );
204  } // Didn't match
205  } // ID already in the map
206  return;
207 } // That's it for updating the map!
208 
210 {
211  // Unpack map into vector
212  for (auto it : m_hit_map) {
213  for (auto *a_s : * it.second) {
214  // Giving away ownership of the objects!
215  hitContainer->push_back( a_s );
216  }
217  it.second->clear();
218  delete it.second;
219  } // Vector of IDs in the map
220  m_hit_map.clear();
221  if (m_config.verboseLevel > 4) {
222  G4cout <<this->GetName()<< " DEBUG EndOfAthenaEvent: After initial cleanup, N=" << hitContainer->size() << G4endl;
223  }
224  return;
225 }
FCS_StepInfoSD::m_hit_map
std::map< Identifier, std::vector< ISF_FCS_Parametrization::FCS_StepInfo * > * > m_hit_map
Definition: FCS_StepInfoSD.h:129
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, double timeWindow, double distanceWindow)
Definition: FCS_StepInfoSD.cxx:158
FCS_Param::Config::m_maxEtaEM3
double m_maxEtaEM3
Definition: FCS_StepInfoSD.h:76
LArEM_ID.h
constants.EMB1
int EMB1
Definition: Calorimeter/CaloClusterCorrection/python/constants.py:53
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
FCS_StepInfoSD.h
FCS_StepInfoSD::getCaloDDManager
void getCaloDDManager()
Keep a map instead of trying to keep the full vector.
Definition: FCS_StepInfoSD.cxx:145
FCS_Param::Config::m_maxRadius
double m_maxRadius
property, see LArG4GenShowerLib::LArG4GenShowerLib
Definition: FCS_StepInfoSD.h:50
LArID_Exception.h
skel.it
it
Definition: skel.GENtoEVGEN.py:423
FCS_StepInfoSD::getMaxTime
double getMaxTime(const CaloCell_ID::CaloSample &layer) const
Definition: FCS_StepInfoSD.cxx:39
FCS_StepInfoSD::m_calo_dd_man
CxxUtils::CachedPointer< const CaloDetDescrManager > m_calo_dd_man
Definition: FCS_StepInfoSD.h:128
FCS_StepInfoSD::getMaxDeltaR
double getMaxDeltaR(const CaloCell_ID::CaloSample &layer) const
Definition: FCS_StepInfoSD.cxx:69
FCS_Param::Config::m_maxEtaPS
double m_maxEtaPS
Definition: FCS_StepInfoSD.h:64
FCS_Param::Config::m_maxrEM3
double m_maxrEM3
Definition: FCS_StepInfoSD.h:78
LArHEC_ID.h
FCS_Param::Config::m_maxrEM1
double m_maxrEM1
Definition: FCS_StepInfoSD.h:70
FCS_Param::Config::m_maxrEM2
double m_maxrEM2
Definition: FCS_StepInfoSD.h:74
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:23
FCS_Param::Config::m_maxPhiPS
double m_maxPhiPS
Definition: FCS_StepInfoSD.h:65
FCS_Param::Config::m_maxPhiEM3
double m_maxPhiEM3
Definition: FCS_StepInfoSD.h:77
FCS_Param::Config::m_maxrPS
double m_maxrPS
Definition: FCS_StepInfoSD.h:66
constants.EMB2
int EMB2
Definition: Calorimeter/CaloClusterCorrection/python/constants.py:54
CaloSampling::CaloSample
CaloSample
Definition: Calorimeter/CaloGeoHelpers/CaloGeoHelpers/CaloSampling.h:22
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
TRT::Hit::layer
@ layer
Definition: HitInfo.h:79
FCS_Param::Config::m_maxTime
double m_maxTime
Definition: FCS_StepInfoSD.h:57
constants.EME1
int EME1
Definition: Calorimeter/CaloClusterCorrection/python/constants.py:55
FCS_StepInfoSD::getMaxRadius
double getMaxRadius(const CaloCell_ID::CaloSample &layer) const
Definition: FCS_StepInfoSD.cxx:54
FCS_Param::Config::m_maxTimeFCAL
double m_maxTimeFCAL
Definition: FCS_StepInfoSD.h:60
FCS_Param::Config::m_maxPhiEM1
double m_maxPhiEM1
Definition: FCS_StepInfoSD.h:69
ReadCondHandleKey.h
FCS_StepInfoSD::getMaxDeltaPhi
double getMaxDeltaPhi(const CaloCell_ID::CaloSample &layer) const
Definition: FCS_StepInfoSD.cxx:119
FCS_Param::Config::m_maxRadiusLAr
double m_maxRadiusLAr
property, see LArG4GenShowerLib::LArG4GenShowerLib
Definition: FCS_StepInfoSD.h:52
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:209
FCS_Param::Config::m_maxTimeHEC
double m_maxTimeHEC
Definition: FCS_StepInfoSD.h:59
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:58
CaloCell_ID_FCS::PreSamplerE
@ PreSamplerE
Definition: FastCaloSim_CaloCell_ID.h:23
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
FCS_Param::Config::m_maxEtaEM2
double m_maxEtaEM2
Definition: FCS_StepInfoSD.h:72
CaloCell_ID_FCS::FCAL2
@ FCAL2
Definition: FastCaloSim_CaloCell_ID.h:42
FCS_StepInfoSD::m_config
FCS_Param::Config m_config
Definition: FCS_StepInfoSD.h:122
CaloCell_ID_FCS::HEC3
@ HEC3
Definition: FastCaloSim_CaloCell_ID.h:30
FCS_Param::Config
Definition: FCS_StepInfoSD.h:42
CaloCell_ID_FCS::FCAL0
@ FCAL0
Definition: FastCaloSim_CaloCell_ID.h:40
CaloCell_ID_FCS::EMB3
@ EMB3
Definition: FastCaloSim_CaloCell_ID.h:22
FCS_Param::Config::verboseLevel
int verboseLevel
Helper to keep the same verbosity everywhere.
Definition: FCS_StepInfoSD.h:44
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
FCS_Param::Config::m_maxRadiusFCAL
double m_maxRadiusFCAL
property, see LArG4GenShowerLib::LArG4GenShowerLib
Definition: FCS_StepInfoSD.h:54
FCS_Param::Config::m_maxPhiEM2
double m_maxPhiEM2
Definition: FCS_StepInfoSD.h:73
FCS_StepInfoSD::ProcessHits
virtual G4bool ProcessHits(G4Step *a_step, G4TouchableHistory *) override
Main processing method.
Definition: FCS_StepInfoSD.cxx:30
FCS_Param::Config::m_maxRadiusHEC
double m_maxRadiusHEC
property, see LArG4GenShowerLib::LArG4GenShowerLib
Definition: FCS_StepInfoSD.h:53
constants.EME2
int EME2
Definition: Calorimeter/CaloClusterCorrection/python/constants.py:56
match
bool match(std::string s1, std::string s2)
match the individual directories of two strings
Definition: hcg.cxx:356
description
std::string description
glabal timer - how long have I taken so far?
Definition: hcg.cxx:88
FCS_StepInfoSD::getMaxDeltaEta
double getMaxDeltaEta(const CaloCell_ID::CaloSample &layer) const
Definition: FCS_StepInfoSD.cxx:94
FCS_Param::Config::m_maxEtaEM1
double m_maxEtaEM1
Definition: FCS_StepInfoSD.h:68