ATLAS Offline Software
Loading...
Searching...
No Matches
HGTDSensorGmxSD.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5// HGTD Sensitive Detector.
6// The Hits are processed here. For every hit, the position and information
7// on the sensor in which the interaction happened are obtained.
8
9// Class header
10#include "HGTDSensorGmxSD.h"
11
12// Athena headers
15#include "MCTruth/TrackHelper.h"
16
17// Geant4 headers
18#include "G4ChargedGeantino.hh"
19#include "G4Geantino.hh"
20#include "G4SDManager.hh"
21#include "G4Step.hh"
22#include "G4VisExtent.hh" // Added to get extent of sensors
23#include "G4VSolid.hh" // Added to get extent of sensors
24
25// GeoModel headers
26#include <GeoModelKernel/GeoFullPhysVol.h>
27#include <GeoModelRead/ReadGeoModel.h>
28
30
31// CLHEP headers
32#include "CLHEP/Geometry/Transform3D.h"
33#include "CLHEP/Units/SystemOfUnits.h"
34#include <stdint.h>
35#include <string.h>
36
37HGTDSensorGmxSD::HGTDSensorGmxSD(const std::string& name, const std::string& hitCollectionName, GeoModelIO::ReadGeoModel * sqlreader)
38 : G4VSensitiveDetector( name ),
39 m_hitCollectionName( hitCollectionName ),
40 m_sqlreader( sqlreader )
41{
42
43}
44
45// Initialize from G4
46void HGTDSensorGmxSD::Initialize(G4HCofThisEvent *)
47{
49}
50
51G4bool HGTDSensorGmxSD::ProcessHits(G4Step* aStep, G4TouchableHistory* /*ROhist*/)
52{
53 if (!m_hitColl) {
55 if (!m_hitColl) {
56 return false;
57 }
58 }
59
60 if (verboseLevel>5) G4cout << "Process Hit" << G4endl;
61
62 G4double edep = aStep->GetTotalEnergyDeposit();
63 edep *= CLHEP::MeV;
64
65 if (edep==0.) {
66 if (aStep->GetTrack()->GetDefinition() != G4Geantino::GeantinoDefinition() &&
67 aStep->GetTrack()->GetDefinition() != G4ChargedGeantino::ChargedGeantinoDefinition())
68 return false;
69 }
70
71 //
72 // Get the Touchable History:
73 //
74 const G4TouchableHistory* myTouch = dynamic_cast<const G4TouchableHistory*>(aStep->GetPreStepPoint()->GetTouchable());
75 if (not myTouch){
76 G4cout<<"HGTDSensorGmxSD::ProcessHits: dynamic cast failed"<<G4endl;
77 return false;
78 }
79 if(verboseLevel>5){
80 for (int i=0;i<myTouch->GetHistoryDepth();i++){
81 std::string detname = myTouch->GetVolume(i)->GetLogicalVolume()->GetName();
82 int copyno = myTouch->GetVolume(i)->GetCopyNo();
83 G4cout << "Volume " << detname << " Copy Nr. " << copyno << G4endl;
84 }
85 }
86
87 //
88 // Get the hit coordinates. Start and End Point
89 //
90 G4ThreeVector startCoord = aStep->GetPreStepPoint()->GetPosition();
91 G4ThreeVector endCoord = aStep->GetPostStepPoint()->GetPosition();
92
93 // Create the SiHits
94
95 const G4AffineTransform transformation = myTouch->GetHistory()->GetTopTransform();
96
97 G4ThreeVector localPosition1 = transformation.TransformPoint(startCoord);
98 G4ThreeVector localPosition2 = transformation.TransformPoint(endCoord);
99
100 HepGeom::Point3D<double> lP1,lP2;
101 //TODO need to check
102 lP1[SiHit::xEta] = localPosition1[1]*CLHEP::mm; //long edge of the module
103 lP1[SiHit::xPhi] = localPosition1[0]*CLHEP::mm; //short edge of the module
104 lP1[SiHit::xDep] = localPosition1[2]*CLHEP::mm; //depth (z)
105
106 lP2[SiHit::xEta] = localPosition2[1]*CLHEP::mm;
107 lP2[SiHit::xPhi] = localPosition2[0]*CLHEP::mm;
108 lP2[SiHit::xDep] = localPosition2[2]*CLHEP::mm;
109
110 // get the HepMcParticleLink from the TrackHelper
111 TrackHelper trHelp(aStep->GetTrack());
112
113 if(m_sqlreader){
114 // if sqlite inputs, Identifier indices come from PhysVol Name
115 std::string physVolName = myTouch->GetVolume()->GetName();
116
117 int hitIdOfWafer = SiHitIdHelper::GetHelper()->buildHitIdFromStringHGTD(2,physVolName);
118
119 m_hitColl->Emplace(lP1,
120 lP2,
121 edep,
122 aStep->GetPreStepPoint()->GetGlobalTime(),
123 trHelp.GenerateParticleLink(),
124 hitIdOfWafer);
125
126 return true;
127 }
128
129 // if not from SQLite, we assume that the Identifier has already been written in as the copy number
130 // (it should hsave done if GeoModel building ran within Athena)
131 //
132 // Get the indexes of which detector the hit is in
133 //
134 const int id = myTouch->GetVolume()->GetCopyNo();
135
136 m_hitColl->Emplace(lP1,
137 lP2,
138 edep,
139 aStep->GetPreStepPoint()->GetGlobalTime(),
140 trHelp.GenerateParticleLink(),
141 id);
142
143 return true;
144}
145
147{
148 auto* eventInfo = AtlasG4EventUserInfo::GetEventUserInfo();
149 if (!eventInfo) {
150 return nullptr;
151 }
152
153 auto hitCollections = eventInfo->GetHitCollectionMap();
154 return hitCollections ? hitCollections->Find<SiHitCollection>(m_hitCollectionName) : nullptr;
155}
AtlasHitsVector< SiHit > SiHitCollection
static AtlasG4EventUserInfo * GetEventUserInfo()
GeoModelIO::ReadGeoModel * m_sqlreader
std::string m_hitCollectionName
SiHitCollection * m_hitColl
G4bool ProcessHits(G4Step *, G4TouchableHistory *) override final
SiHitCollection * getHitCollection() const
HGTDSensorGmxSD(const std::string &name, const std::string &hitCollectionName, GeoModelIO::ReadGeoModel *sqlreader=nullptr)
void Initialize(G4HCofThisEvent *) override final
int buildHitIdFromStringHGTD(int part, const std::string &) const
static const SiHitIdHelper * GetHelper()
@ xPhi
Definition SiHit.h:162
@ xEta
Definition SiHit.h:162
@ xDep
Definition SiHit.h:162
HepMcParticleLink GenerateParticleLink()
Generates a new HepMcParticleLink object on the stack based on the generation-zero unique id,...
Definition TrackHelper.h:75