ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
ForwardDetectors
ZDC
ZDC_SD
src
ZDC_G4CalibSD.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
#include "
ZDC_G4CalibSD.h
"
6
#include "
CaloSimEvent/CaloCalibrationHitContainer.h
"
7
#include "
CaloSimEvent/CaloCalibrationHit.h
"
8
#include "
CaloG4Sim/SimulationEnergies.h
"
9
#include "
CaloG4Sim/EscapedEnergyRegistry.h
"
10
#include "G4Step.hh"
11
#include "
HitManagement/HitCollectionMap.h
"
12
#include "
MCTruth/AtlasG4EventUserInfo.h
"
13
#include "
MCTruth/TrackHelper.h
"
14
#include "
AtlasHepMC/GenParticle.h
"
15
16
ZDC_G4CalibSD::ZDC_G4CalibSD
(
const
G4String &a_name,
const
G4String& hitCollectionName,
bool
doPID)
17
: G4VSensitiveDetector(a_name),
m_hitCollectionName
(hitCollectionName),
m_numberInvalidHits
(0),
m_doPID
(doPID)
18
{
19
m_simulationEnergies
=
new
CaloG4::SimulationEnergies
();
20
}
21
22
ZDC_G4CalibSD::~ZDC_G4CalibSD
()
23
{
24
if
(verboseLevel > 5 &&
m_numberInvalidHits
> 0)
25
{
26
G4cout <<
"Destructor: Sensitive Detector <"
<< SensitiveDetectorName <<
"> had "
<<
m_numberInvalidHits
27
<<
" G4Step energy deposits outside the region determined by its Calculator."
<< G4endl;
28
}
29
delete
m_simulationEnergies
;
30
}
31
32
G4bool
ZDC_G4CalibSD::ProcessHits
(G4Step *a_step, G4TouchableHistory *)
33
{
34
// If there's no energy, there's no hit. (Aside: Isn't this energy
35
// the same as the energy from the calculator? Not necessarily.
36
// The calculator may include detector effects such as
37
// charge-collection which are not modeled by Geant4.)
38
if
(a_step->GetTotalEnergyDeposit() == 0.)
39
return
false
;
40
41
// Convert the G4Step into (eta,phi,sampling).
42
// Check that hit was valid. (It might be invalid if, for example,
43
// it occurred outside the sensitive region. If such a thing
44
// happens, it means that the geometry definitions in the
45
// detector-construction routine and the calculator do not agree.)
46
47
m_energies
.clear();
48
// classify different types of deposits (0: EM, 1: Non-EM, 2: Invisible, 3: Escaped)
49
50
m_simulationEnergies
->Energies(a_step,
m_energies
);
51
52
// identifier needed to specify particular volme we're in. Used in HitCollection to make sure we don't have double hits
53
Identifier
id;
54
id
= a_step->GetPreStepPoint()->GetPhysicalVolume()->GetCopyNo();
55
56
// build calibHit. check if we've had a hit in this cell already. if we havent add it to the set of cells. If we have add energies to existing energies. ie can't distinguish b/w different hits in single cell so must integrate all this information
57
return
SimpleHit
(
id
,
m_energies
, a_step->GetTrack() );
58
}
59
60
61
G4bool
ZDC_G4CalibSD::SimpleHit
(
const
Identifier
&
id
,
const
std::vector<double>& energies,
const
G4Track* track )
62
{
63
if
(!
m_HitColl
) {
64
m_HitColl
=
getHitCollection
();
65
if
(!
m_HitColl
) {
66
return
false
;
67
}
68
}
69
70
// retreive particle ID
71
int
particleID =
HepMC::UNDEFINED_ID
;
72
int
particleUID =
HepMC::UNDEFINED_ID
;
73
if
(
m_doPID
) {
74
HepMC::ConstGenParticlePtr
primary =
TrackHelper
(track).
GetPrimaryGenParticle
();
75
if
(primary) {
76
particleID =
HepMC::barcode
(primary);
// FIXME Barcode-based
77
particleUID =
HepMC::uniqueID
(primary);
78
}
79
}
80
81
82
// Reject cases where invisible energy calculation produced values
83
// of order 10e-12 instead of 0 due to rounding errors in that
84
// calculation, or general cases where the energy deposits are
85
// trivially small.
86
if
(energies[0] + energies[1] + energies[3] < 0.001 * CLHEP::eV && std::abs(energies[2]) < 0.001 * CLHEP::eV)
87
{
88
return
true
;
89
}
90
91
// Build the hit.
92
auto
hit
= std::make_unique<CaloCalibrationHit>(
id
,
93
energies[0],
94
energies[1],
95
energies[2],
96
energies[3],
97
particleID,
98
particleUID);
99
m_HitColl
->MergeHit(std::move(
hit
));
100
101
return
true
;
102
}
103
104
// Something special has happened (probably the detection of escaped
105
// energy in CaloG4Sim/SimulationEnergies). We have to bypass the
106
// regular sensitive-detector processing. Determine the identifier
107
// (and only the identifier) using the calculator, then built a hit
108
// with that identifier and the energies in the vector.
109
110
G4bool
ZDC_G4CalibSD::SpecialHit
(G4Step *a_step,
111
const
std::vector<G4double> &a_energies)
112
{
113
// If we can't get the identifier, something is wrong.
114
Identifier
id;
115
id
= a_step->GetPreStepPoint()->GetPhysicalVolume()->GetCopyNo();
116
117
return
SimpleHit
(
id
, a_energies, a_step->GetTrack());
118
}
119
120
ZDC_CalibrationHitContainerBuilder
*
ZDC_G4CalibSD::getHitCollection
()
const
121
{
122
auto
* eventInfo =
AtlasG4EventUserInfo::GetEventUserInfo
();
123
if
(!eventInfo) {
124
return
nullptr
;
125
}
126
auto
hitCollections = eventInfo->GetHitCollectionMap();
127
return
hitCollections ? hitCollections->Find<
ZDC_CalibrationHitContainerBuilder
>(
m_hitCollectionName
) :
nullptr
;
128
}
AtlasG4EventUserInfo.h
CaloCalibrationHitContainer.h
CaloCalibrationHit.h
EscapedEnergyRegistry.h
GenParticle.h
HitCollectionMap.h
hit
bool hit(const Container &ids, int pdgId)
Definition
JetIRCSafeLabelTool.cxx:64
SimulationEnergies.h
TrackHelper.h
ZDC_G4CalibSD.h
AtlasG4EventUserInfo::GetEventUserInfo
static AtlasG4EventUserInfo * GetEventUserInfo()
Definition
AtlasG4EventUserInfo.h:96
CaloG4::SimulationEnergies
This class implements the calculations requires to categorize the energies deposited during the simul...
Definition
SimulationEnergies.h:47
TrackHelper
Definition
TrackHelper.h:20
TrackHelper::GetPrimaryGenParticle
HepMC::GenParticlePtr GetPrimaryGenParticle()
Return the primary truth particle associated with this track.
Definition
TrackHelper.cxx:84
ZDC_CalibrationHitContainerBuilder
Definition
ZDC_HitCollectionBuilders.h:43
ZDC_G4CalibSD::m_simulationEnergies
CaloG4::SimulationEnergies * m_simulationEnergies
Definition
ZDC_G4CalibSD.h:60
ZDC_G4CalibSD::m_energies
std::vector< G4double > m_energies
Definition
ZDC_G4CalibSD.h:53
ZDC_G4CalibSD::m_hitCollectionName
std::string m_hitCollectionName
Definition
ZDC_G4CalibSD.h:50
ZDC_G4CalibSD::m_numberInvalidHits
G4int m_numberInvalidHits
Definition
ZDC_G4CalibSD.h:56
ZDC_G4CalibSD::m_doPID
G4bool m_doPID
Definition
ZDC_G4CalibSD.h:58
ZDC_G4CalibSD::m_HitColl
ZDC_CalibrationHitContainerBuilder * m_HitColl
Definition
ZDC_G4CalibSD.h:52
ZDC_G4CalibSD::SpecialHit
G4bool SpecialHit(G4Step *a_step, const std::vector< G4double > &a_energies)
Definition
ZDC_G4CalibSD.cxx:110
ZDC_G4CalibSD::~ZDC_G4CalibSD
virtual ~ZDC_G4CalibSD()
Definition
ZDC_G4CalibSD.cxx:22
ZDC_G4CalibSD::ZDC_G4CalibSD
ZDC_G4CalibSD(const G4String &a_name, const G4String &hitCollectionName, bool doPID=false)
Definition
ZDC_G4CalibSD.cxx:16
ZDC_G4CalibSD::getHitCollection
ZDC_CalibrationHitContainerBuilder * getHitCollection() const
Definition
ZDC_G4CalibSD.cxx:120
ZDC_G4CalibSD::SimpleHit
G4bool SimpleHit(const Identifier &id, const std::vector< double > &energies, const G4Track *track=nullptr)
Definition
ZDC_G4CalibSD.cxx:61
ZDC_G4CalibSD::ProcessHits
G4bool ProcessHits(G4Step *a_step, G4TouchableHistory *) override
Definition
ZDC_G4CalibSD.cxx:32
HepMC::barcode
int barcode(const T *p)
Definition
Barcode.h:15
HepMC::uniqueID
int uniqueID(const T &p)
Definition
MagicNumbers.h:89
HepMC::UNDEFINED_ID
constexpr int UNDEFINED_ID
Definition
MagicNumbers.h:57
HepMC::ConstGenParticlePtr
HepMC3::ConstGenParticlePtr ConstGenParticlePtr
Definition
GenParticle.h:20
Identifier
Definition
IdentifierFieldParser.cxx:14
Generated on
for ATLAS Offline Software by
1.17.0