ATLAS Offline Software
HGTDSensorGmxSD.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 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
13 #include "MCTruth/TrackHelper.h"
14 
15 // Geant4 headers
16 #include "G4ChargedGeantino.hh"
17 #include "G4Geantino.hh"
18 #include "G4SDManager.hh"
19 #include "G4Step.hh"
20 #include "G4VisExtent.hh" // Added to get extent of sensors
21 #include "G4VSolid.hh" // Added to get extent of sensors
22 
23 // GeoModel headers
24 #include <GeoModelKernel/GeoFullPhysVol.h>
25 #include <GeoModelRead/ReadGeoModel.h>
26 
28 
29 // CLHEP headers
30 #include "CLHEP/Geometry/Transform3D.h"
31 #include "CLHEP/Units/SystemOfUnits.h"
32 #include <stdint.h>
33 #include <string.h>
34 
35 HGTDSensorGmxSD::HGTDSensorGmxSD(const std::string& name, const std::string& hitCollectionName, GeoModelIO::ReadGeoModel * sqlreader)
36  : G4VSensitiveDetector( name ),
37  m_HitColl( hitCollectionName ),
38  m_sqlreader( sqlreader )
39 {
40 
41 }
42 
43 // Initialize from G4
44 void HGTDSensorGmxSD::Initialize(G4HCofThisEvent *)
45 {
46  if (!m_HitColl.isValid()) m_HitColl = std::make_unique<SiHitCollection>();
47 }
48 
49 G4bool HGTDSensorGmxSD::ProcessHits(G4Step* aStep, G4TouchableHistory* /*ROhist*/)
50 {
51  if (verboseLevel>5) G4cout << "Process Hit" << G4endl;
52 
53  G4double edep = aStep->GetTotalEnergyDeposit();
54  edep *= CLHEP::MeV;
55 
56  if (edep==0.) {
57  if (aStep->GetTrack()->GetDefinition() != G4Geantino::GeantinoDefinition() &&
58  aStep->GetTrack()->GetDefinition() != G4ChargedGeantino::ChargedGeantinoDefinition())
59  return false;
60  }
61 
62  //
63  // Get the Touchable History:
64  //
65  const G4TouchableHistory* myTouch = dynamic_cast<const G4TouchableHistory*>(aStep->GetPreStepPoint()->GetTouchable());
66 
67  if(verboseLevel>5){
68  for (int i=0;i<myTouch->GetHistoryDepth();i++){
69  std::string detname = myTouch->GetVolume(i)->GetLogicalVolume()->GetName();
70  int copyno = myTouch->GetVolume(i)->GetCopyNo();
71  G4cout << "Volume " << detname << " Copy Nr. " << copyno << G4endl;
72  }
73  }
74 
75  //
76  // Get the hit coordinates. Start and End Point
77  //
78  G4ThreeVector startCoord = aStep->GetPreStepPoint()->GetPosition();
79  G4ThreeVector endCoord = aStep->GetPostStepPoint()->GetPosition();
80 
81  // Create the SiHits
82 
83  const G4AffineTransform transformation = myTouch->GetHistory()->GetTopTransform();
84 
85  G4ThreeVector localPosition1 = transformation.TransformPoint(startCoord);
86  G4ThreeVector localPosition2 = transformation.TransformPoint(endCoord);
87 
88  HepGeom::Point3D<double> lP1,lP2;
89  //TODO need to check
90  lP1[SiHit::xEta] = localPosition1[1]*CLHEP::mm; //long edge of the module
91  lP1[SiHit::xPhi] = localPosition1[0]*CLHEP::mm; //short edge of the module
92  lP1[SiHit::xDep] = localPosition1[2]*CLHEP::mm; //depth (z)
93 
94  lP2[SiHit::xEta] = localPosition2[1]*CLHEP::mm;
95  lP2[SiHit::xPhi] = localPosition2[0]*CLHEP::mm;
96  lP2[SiHit::xDep] = localPosition2[2]*CLHEP::mm;
97 
98  // get the HepMcParticleLink from the TrackHelper
99  TrackHelper trHelp(aStep->GetTrack());
100 
101  if(m_sqlreader){
102  // if sqlite inputs, Identifier indices come from PhysVol Name
103  std::string physVolName = myTouch->GetVolume()->GetName();
104 
105  int hitIdOfWafer = SiHitIdHelper::GetHelper()->buildHitIdFromStringHGTD(2,physVolName);
106 
107  m_HitColl->Emplace(lP1,
108  lP2,
109  edep,
110  aStep->GetPreStepPoint()->GetGlobalTime(),
111  trHelp.GenerateParticleLink(),
112  hitIdOfWafer);
113 
114  return true;
115  }
116 
117  // if not from SQLite, we assume that the Identifier has already been written in as the copy number
118  // (it should hsave done if GeoModel building ran within Athena)
119  //
120  // Get the indexes of which detector the hit is in
121  //
122  const int id = myTouch->GetVolume()->GetCopyNo();
123 
124  m_HitColl->Emplace(lP1,
125  lP2,
126  edep,
127  aStep->GetPreStepPoint()->GetGlobalTime(),
128  trHelp.GenerateParticleLink(),
129  id);
130 
131  return true;
132 }
HGTDSensorGmxSD::m_sqlreader
GeoModelIO::ReadGeoModel * m_sqlreader
Definition: HGTDSensorGmxSD.h:53
SiHitIdHelper::buildHitIdFromStringHGTD
int buildHitIdFromStringHGTD(int part, const std::string &) const
Definition: SiHitIdHelper.cxx:149
TrackHelper.h
python.SystemOfUnits.MeV
int MeV
Definition: SystemOfUnits.py:154
HGTDSensorGmxSD::HGTDSensorGmxSD
HGTDSensorGmxSD(const std::string &name, const std::string &hitCollectionName, GeoModelIO::ReadGeoModel *sqlreader=nullptr)
Definition: HGTDSensorGmxSD.cxx:35
HGTDSensorGmxSD::ProcessHits
G4bool ProcessHits(G4Step *, G4TouchableHistory *) override final
Definition: HGTDSensorGmxSD.cxx:49
SiHitIdHelper.h
TrackHelper
Definition: TrackHelper.h:14
SiHit::xDep
@ xDep
Definition: SiHit.h:162
lumiFormat.i
int i
Definition: lumiFormat.py:85
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
SiHit::xEta
@ xEta
Definition: SiHit.h:162
python.SystemOfUnits.mm
int mm
Definition: SystemOfUnits.py:83
SiHitIdHelper::GetHelper
static const SiHitIdHelper * GetHelper()
Definition: SiHitIdHelper.cxx:19
SiHit::xPhi
@ xPhi
Definition: SiHit.h:162
TrackHelper::GenerateParticleLink
HepMcParticleLink GenerateParticleLink()
Generates a creates new HepMcParticleLink object on the stack based on GetUniqueID(),...
Definition: TrackHelper.h:35
HGTDSensorGmxSD::Initialize
void Initialize(G4HCofThisEvent *) override final
Definition: HGTDSensorGmxSD.cxx:44
HGTDSensorGmxSD::m_HitColl
SG::WriteHandle< SiHitCollection > m_HitColl
Definition: HGTDSensorGmxSD.h:52
HGTDSensorGmxSD.h