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 "G4RunManager.hh"
11#include "G4Step.hh"
14
15ZDC_G4CalibSD::ZDC_G4CalibSD(const G4String &a_name, const G4String& hitCollectionName, bool doPID)
16 : G4VSensitiveDetector(a_name), m_hitCollectionName(hitCollectionName), m_numberInvalidHits(0), m_doPID(doPID)
17{
19}
20
22{
23 if (verboseLevel > 5 && m_numberInvalidHits > 0)
24 {
25 G4cout << "Destructor: Sensitive Detector <" << SensitiveDetectorName << "> had " << m_numberInvalidHits
26 << " G4Step energy deposits outside the region determined by its Calculator." << G4endl;
27 }
29}
30
31G4bool ZDC_G4CalibSD::ProcessHits(G4Step *a_step, G4TouchableHistory *)
32{
33 // If there's no energy, there's no hit. (Aside: Isn't this energy
34 // the same as the energy from the calculator? Not necessarily.
35 // The calculator may include detector effects such as
36 // charge-collection which are not modeled by Geant4.)
37 if (a_step->GetTotalEnergyDeposit() == 0.)
38 return false;
39
40 // Convert the G4Step into (eta,phi,sampling).
41 // Check that hit was valid. (It might be invalid if, for example,
42 // it occurred outside the sensitive region. If such a thing
43 // happens, it means that the geometry definitions in the
44 // detector-construction routine and the calculator do not agree.)
45
46 m_energies.clear();
47 // classify different types of deposits (0: EM, 1: Non-EM, 2: Invisible, 3: Escaped)
48
49 m_simulationEnergies->Energies(a_step, m_energies);
50
51 // identifier needed to specify particular volme we're in. Used in HitCollection to make sure we don't have double hits
52 Identifier id;
53 id = a_step->GetPreStepPoint()->GetPhysicalVolume()->GetCopyNo();
54
55 // 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
56 return SimpleHit (id, m_energies );
57}
58
59
60G4bool ZDC_G4CalibSD::SimpleHit(const Identifier& id, const std::vector<double>& energies )
61{
62 if (!m_HitColl) {
64 if (!m_HitColl) {
65 return false;
66 }
67 }
68
69 // retreive particle ID
70 int particleID = HepMC::UNDEFINED_ID;
71 int particleUID = HepMC::UNDEFINED_ID;
72 if( m_doPID ) {
73 AtlasG4EventUserInfo * atlasG4EvtUserInfo = dynamic_cast<AtlasG4EventUserInfo*>(G4RunManager::GetRunManager()->GetCurrentEvent()->GetUserInformation());
74 if (atlasG4EvtUserInfo) {
75 particleID = HepMC::barcode(atlasG4EvtUserInfo->GetCurrentPrimaryGenParticle()); // FIXME Barcode-based
76 particleUID = HepMC::uniqueID(atlasG4EvtUserInfo->GetCurrentPrimaryGenParticle());
77 }
78 }
79
80
81 // Reject cases where invisible energy calculation produced values
82 // of order 10e-12 instead of 0 due to rounding errors in that
83 // calculation, or general cases where the energy deposits are
84 // trivially small.
85 if (energies[0] + energies[1] + energies[3] < 0.001 * CLHEP::eV && std::abs(energies[2]) < 0.001 * CLHEP::eV)
86 {
87 return true;
88 }
89
90 // Build the hit.
91 auto hit = std::make_unique<CaloCalibrationHit>(id,
92 energies[0],
93 energies[1],
94 energies[2],
95 energies[3],
96 particleID,
97 particleUID);
98 m_HitColl->MergeHit(std::move(hit));
99
100 return true;
101}
102
103// Something special has happened (probably the detection of escaped
104// energy in CaloG4Sim/SimulationEnergies). We have to bypass the
105// regular sensitive-detector processing. Determine the identifier
106// (and only the identifier) using the calculator, then built a hit
107// with that identifier and the energies in the vector.
108
109G4bool ZDC_G4CalibSD::SpecialHit(G4Step *a_step,
110 const std::vector<G4double> &a_energies)
111{
112 // If we can't get the identifier, something is wrong.
113 Identifier id;
114 id = a_step->GetPreStepPoint()->GetPhysicalVolume()->GetCopyNo();
115
116 return SimpleHit(id, a_energies);
117}
118
120{
121 auto* eventInfo = AtlasG4EventUserInfo::GetEventUserInfo();
122 if (!eventInfo) {
123 return nullptr;
124 }
125 auto hitCollections = eventInfo->GetHitCollectionMap();
126 return hitCollections ? hitCollections->Find<ZDC_CalibrationHitContainerBuilder>(m_hitCollectionName) : nullptr;
127}
This class is attached to G4Event objects as UserInformation.
HepMC::ConstGenParticlePtr GetCurrentPrimaryGenParticle() const
return a pointer to the HepMC::GenParticle used to create the current G4PrimaryParticle.
static AtlasG4EventUserInfo * GetEventUserInfo()
This class implements the calculations requires to categorize the energies deposited during the simul...
CaloG4::SimulationEnergies * m_simulationEnergies
std::vector< G4double > m_energies
std::string m_hitCollectionName
G4bool SimpleHit(const Identifier &id, const std::vector< double > &energies)
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 ProcessHits(G4Step *a_step, G4TouchableHistory *) override
int barcode(const T *p)
Definition Barcode.h:17
int uniqueID(const T &p)
constexpr int UNDEFINED_ID