ATLAS Offline Software
Loading...
Searching...
No Matches
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"
10#include "G4Step.hh"
13#include "MCTruth/TrackHelper.h"
15
16ZDC_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{
20}
21
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 }
30}
31
32G4bool 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
61G4bool ZDC_G4CalibSD::SimpleHit(const Identifier& id, const std::vector<double>& energies, const G4Track* track )
62{
63 if (!m_HitColl) {
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 ) {
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
110G4bool 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
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}
static AtlasG4EventUserInfo * GetEventUserInfo()
This class implements the calculations requires to categorize the energies deposited during the simul...
HepMC::GenParticlePtr GetPrimaryGenParticle()
Return the primary truth particle associated with this track.
CaloG4::SimulationEnergies * m_simulationEnergies
std::vector< G4double > m_energies
std::string m_hitCollectionName
G4int m_numberInvalidHits
ZDC_CalibrationHitContainerBuilder * m_HitColl
G4bool SpecialHit(G4Step *a_step, const std::vector< G4double > &a_energies)
virtual ~ZDC_G4CalibSD()
ZDC_G4CalibSD(const G4String &a_name, const G4String &hitCollectionName, bool doPID=false)
ZDC_CalibrationHitContainerBuilder * getHitCollection() const
G4bool SimpleHit(const Identifier &id, const std::vector< double > &energies, const G4Track *track=nullptr)
G4bool ProcessHits(G4Step *a_step, G4TouchableHistory *) override
int barcode(const T *p)
Definition Barcode.h:15
int uniqueID(const T &p)
constexpr int UNDEFINED_ID
HepMC3::ConstGenParticlePtr ConstGenParticlePtr
Definition GenParticle.h:20