ATLAS Offline Software
sTGCSensitiveDetector.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 #include "MCTruth/TrackHelper.h"
7 #include "G4Geantino.hh"
8 #include "G4ChargedGeantino.hh"
9 
10 #include "G4Track.hh"
11 
14 
15 #include <string>
16 
17 // construction/destruction
19  const std::string& hitCollectionName,
20  unsigned baseDepth):
21  G4VSensitiveDetector( name ),
23  m_sTGCSimHitCollection( hitCollectionName ),
24  m_baseDepth{baseDepth} {}
25 
26 // Implemenation of memebr functions
27 void sTGCSensitiveDetector::Initialize(G4HCofThisEvent*)
28 {
29  if (!m_sTGCSimHitCollection.isValid()) m_sTGCSimHitCollection = std::make_unique<sTGCSimHitCollection>();
30 }
31 
32 G4bool sTGCSensitiveDetector::ProcessHits(G4Step* aStep,G4TouchableHistory* /*ROHist*/)
33 {
34  G4Track* currentTrack = aStep->GetTrack();
35  int charge=currentTrack->GetDefinition()->GetPDGCharge();
36 
37  bool geantinoHit = (currentTrack->GetDefinition()==G4Geantino::GeantinoDefinition()) ||
38  (currentTrack->GetDefinition()==G4ChargedGeantino::ChargedGeantinoDefinition());
39 
40  if (!charge && (!geantinoHit)) return false;
41  // G4cout << "\t\t sTGCSD: Hit in a sensitive layer!!!!! " << G4endl;
42  G4StepPoint* postStep=aStep->GetPostStepPoint();
43  const G4Step* post_Step=aStep->GetTrack()->GetStep();
44 
45  Amg::Vector3D position = Amg::Hep3VectorToEigen(postStep->GetPosition());
46 
47  G4StepPoint* preStep = aStep->GetPreStepPoint();
48  Amg::Vector3D preposition = Amg::Hep3VectorToEigen(preStep->GetPosition());
49 
50  int pdgCode=currentTrack->GetDefinition()->GetPDGEncoding();
51 
52  float globalTime=postStep->GetGlobalTime();
53 
54  Amg::Vector3D direction= Amg::Hep3VectorToEigen( postStep->GetMomentumDirection() );
55  float depositEnergy=post_Step->GetTotalEnergyDeposit();
56 
57  if (depositEnergy<0.0001 && (!geantinoHit)) return false;
58 
59  const G4TouchableHistory* touchHist = static_cast<const G4TouchableHistory*>(aStep->GetPreStepPoint()->GetTouchable());
60 
61  // int iDepth=touchHist->GetHistoryDepth();
62  // G4cout << "\t\t\t\t Touchable history dump "<<G4endl;
63  int nLayer=touchHist->GetVolume(m_baseDepth)->GetCopyNo();
64  std::string chName=touchHist->GetVolume(1+m_baseDepth)->GetLogicalVolume()->GetName();
65  //G4cout << "sTGCSensitiveDetector name: "<<chName<<G4endl;
66  std::string subType=chName.substr(chName.find('-')+1);
67  //G4cout << "\t\t sType: "<<subType);
68  if (subType[0]!='T'&&subType[0]!='Q' ) ATH_MSG_WARNING(" something is wrong, this is no sTGC! "<<chName<<", "<<Amg::toString(preposition));
69  int iRing = std::atoi(&subType[2]) -1;
70  ATH_MSG_VERBOSE("Volume name: "<<chName<<", nLayer: "<<nLayer<<", subType: "<<subType<<", iRing: "<<iRing);
71 
72  // identifiers have eta naming 0-2, eta encoded in subtype is 1-3
73  // double phiDiff=2*M_PI;
74 
75  G4ThreeVector posH=postStep->GetPosition(); //posH is equivalent to position - eigen not used to avoid additional dependence on EventPrimitives
76  if (subType[1]=='L') posH.rotateZ(M_PI/8.);
77  double phiHit=posH.phi();
78  if(phiHit<=0) phiHit+=2.*M_PI;
79  int iPhi=1+int(phiHit/(M_PI/4.));
80  iPhi*=2;
81  if (subType[1]=='L') iPhi-=1;
82 
83  int iSide=1;
84  if (position.z()<0) iSide=-1;
85 
86  int mLayer=0;
87  if (subType[1]=='S')
88  {
89  if (subType[3]=='C') mLayer=1;
90  else if (subType[3]=='P') mLayer=2;
91  }
92  else if (subType[1]=='L')
93  {
94  if (subType[3]=='P') mLayer=1;
95  else if (subType[3]=='C') mLayer=2;
96  }
97 
98  if (mLayer != 1 && mLayer !=2) G4cout << " something is wrong - multilayer index is " << mLayer << G4endl;
99 
100  int sTgcId = m_muonHelper->BuildsTgcHitId(subType, iPhi, iRing, mLayer,nLayer, iSide);
101  TrackHelper trHelp(aStep->GetTrack());
102  m_sTGCSimHitCollection->Emplace(sTgcId,globalTime,position,pdgCode,direction,depositEnergy,
103  trHelp.GenerateParticleLink(),
104  preStep->GetKineticEnergy(),preposition);
105 
106  return true;
107 }
108 
sTGCSensitiveDetector::ProcessHits
G4bool ProcessHits(G4Step *aStep, G4TouchableHistory *ROhist) override final
Definition: sTGCSensitiveDetector.cxx:32
TrackHelper.h
M_PI
#define M_PI
Definition: ActiveFraction.h:11
sTGCSensitiveDetector.h
sTGCSensitiveDetector::m_muonHelper
const sTgcHitIdHelper * m_muonHelper
Definition: sTGCSensitiveDetector.h:36
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
Amg::Hep3VectorToEigen
Amg::Vector3D Hep3VectorToEigen(const CLHEP::Hep3Vector &CLHEPvector)
Converts a CLHEP-based CLHEP::Hep3Vector into an Eigen-based Amg::Vector3D.
Definition: CLHEPtoEigenConverter.h:137
sTgcHitIdHelper::BuildsTgcHitId
int BuildsTgcHitId(const std::string &, const int, const int, const int, const int, const int) const
Definition: sTgcHitIdHelper.cxx:89
TrackHelper
Definition: TrackHelper.h:14
Amg::toString
std::string toString(const Translation3D &translation, int precision=4)
GeoPrimitvesToStringConverter.
Definition: GeoPrimitivesToStringConverter.h:40
sTGCSensitiveDetector::sTGCSensitiveDetector
sTGCSensitiveDetector(const std::string &name, const std::string &hitCollectionName, unsigned baseDepth)
construction/destruction
Definition: sTGCSensitiveDetector.cxx:18
sTGCSensitiveDetector::m_baseDepth
unsigned m_baseDepth
basic depth to travel along the G4 history.
Definition: sTGCSensitiveDetector.h:39
Muon::MuonStationIndex::chName
const std::string & chName(ChIndex index)
convert ChIndex into a string
Definition: MuonStationIndex.cxx:119
AthMessaging
Class to provide easy MsgStream access and capabilities.
Definition: AthMessaging.h:55
sTGCSensitiveDetector::Initialize
void Initialize(G4HCofThisEvent *HCE) override final
member functions
Definition: sTGCSensitiveDetector.cxx:27
CLHEPtoEigenConverter.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
charge
double charge(const T &p)
Definition: AtlasPID.h:986
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
Trk::iPhi
@ iPhi
Definition: ParamDefs.h:47
sTGCSensitiveDetector::m_sTGCSimHitCollection
SG::WriteHandle< sTGCSimHitCollection > m_sTGCSimHitCollection
Definition: sTGCSensitiveDetector.h:35
python.CaloAddPedShiftConfig.int
int
Definition: CaloAddPedShiftConfig.py:45
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
GeoPrimitivesToStringConverter.h
CxxUtils::atoi
int atoi(std::string_view str)
Helper functions to unpack numbers decoded in string into integers and doubles The strings are requir...
Definition: Control/CxxUtils/Root/StringUtils.cxx:85
TrackHelper::GenerateParticleLink
HepMcParticleLink GenerateParticleLink()
Generates a creates new HepMcParticleLink object on the stack based on GetUniqueID(),...
Definition: TrackHelper.h:35