ATLAS Offline Software
Loading...
Searching...
No Matches
MuonWallSD.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//************************************************************
6//
7// Class MuonWallSD.
8// Sensitive detector for the muon wall
9//
10//************************************************************
11
12#include "MuonWallSD.h"
13
18
19#include "GaudiKernel/ISvcLocator.h"
20#include "GaudiKernel/Bootstrap.h"
21
22#include "G4EventManager.hh"
23#include "G4HCofThisEvent.hh"
24#include "G4VPhysicalVolume.hh"
25#include "G4Step.hh"
26#include "G4VTouchable.hh"
27#include "G4TouchableHistory.hh"
28
29MuonWallSD::MuonWallSD(const std::string& name, const std::string& hitCollectionName, int verbose)
30 : G4VSensitiveDetector(name),
31 m_hitCollectionName(hitCollectionName)
32{
33 verboseLevel = std::max(verboseLevel, verbose);
34
35 SmartIF<StoreGateSvc> detStore{Gaudi::svcLocator()->service("DetectorStore")};
36 if ( !detStore ) {
37 G4ExceptionDescription description;
38 description << "Constructor: DetectorStoreSvc not found!";
39 G4Exception("MuonWallSD", "NoDetStore", FatalException, description);
40 abort();
41 } else if (verboseLevel >= 5) {
42 G4cout << "DetectorStoreSvc initialized" << G4endl;
43 }
44
45 if (detStore->retrieve(m_tileTBID).isFailure()) {
46 G4ExceptionDescription description;
47 description << "Constructor: No TileTBID helper!";
48 G4Exception("MuonWallSD", "NoTileTBIDHelper", FatalException, description);
49 abort();
50 } else if (verboseLevel >= 5) {
51 G4cout << "TileTBID helper retrieved" << G4endl;
52 }
53
55 for (int channel=0; channel<s_nCellMu; ++channel) {
56 m_id[channel] = m_tileTBID->channel_id(type,module,channel);
57 }
58
59 module=TileTBID::CRACK_WALL;
60 for (int channel=0; channel<s_nCellS; ++channel) {
61 m_id[channel+s_nCellMu] = m_tileTBID->channel_id(type,module,channel);
62 }
63}
64
66{
67 auto* eventManager = G4EventManager::GetEventManager();
68 if (!eventManager) {
69 return nullptr;
70 }
71
72 auto* eventInfo = dynamic_cast<AtlasG4EventUserInfo*>(eventManager->GetUserInformation());
73 if (!eventInfo) {
74 return nullptr;
75 }
76
77 auto hitCollections = eventInfo->GetHitCollectionMap();
78 return hitCollections ? hitCollections->Find<HitVectorBuilder>(m_hitCollectionName) : nullptr;
79}
80
81void MuonWallSD::Initialize(G4HCofThisEvent* /* HCE */) {
82 if (verboseLevel >= 5) {
83 G4cout << "MuonWallSD::Initialize()" << G4endl;
84 }
85
87}
88
89G4bool MuonWallSD::ProcessHits(G4Step* aStep, G4TouchableHistory* /* ROhist */) {
90 if (verboseLevel >= 10) {
91 G4cout << "MuonWallSD::ProcessHits" << G4endl;
92 }
93
94 const G4TouchableHistory* theTouchable = static_cast<const G4TouchableHistory*>(aStep->GetPreStepPoint()->GetTouchable());
95 const G4VPhysicalVolume* physVol = theTouchable->GetVolume();
96 const G4LogicalVolume* logiVol = physVol->GetLogicalVolume();
97 const G4String nameLogiVol = logiVol->GetName();
98 const G4int nScinti = physVol->GetCopyNo();
99
100 const G4double edep = aStep->GetTotalEnergyDeposit() * aStep->GetTrack()->GetWeight();
101 G4double stepl = 0.;
102
103 if (aStep->GetTrack()->GetDefinition()->GetPDGCharge() != 0.){ // FIXME not-equal check on double
104
105 stepl = aStep->GetStepLength();
106 }
107
108 if ((edep == 0.) && (stepl == 0.)) { //FIXME equality check on double
109
110 return false;
111 }
112
113 int ind;
114
115 if(nameLogiVol.find("MuScintillatorLayer") !=G4String::npos) {
116 // for muon wall, nScinti-1 is the correct indice.
117 ind = nScinti-1;
118 } else if(nameLogiVol.find("S1") !=G4String::npos) {
119 ind = s_nCellMu + 0;
120 } else if(nameLogiVol.find("S2") !=G4String::npos) {
121 ind = s_nCellMu + 1;
122 } else if(nameLogiVol.find("S3") !=G4String::npos) {
123 ind = s_nCellMu + 2;
124 } else {
125 ind = s_nCellMu + 3;
126 }
127
128 if (verboseLevel >= 10) {
130 G4cout << ((hitCollection && hitCollection->HasHit(ind))?"Additional hit in ":"First hit in ")
131 << ((ind<s_nCellMu)?"MuonWall ":"beam counter S")
132 << ((ind<s_nCellMu)?nScinti:(ind-s_nCellMu+1))
133 << " time=" << aStep->GetPostStepPoint()->GetGlobalTime()
134 << " ene=" << edep << G4endl;
135 }
136
138 if (!hitCollection) {
139 if (verboseLevel >= 5) {
140 G4cout << "MuonWallSD::ProcessHits WARNING hit collection is not available" << G4endl;
141 }
142 return false;
143 }
144 m_hitCollection = hitCollection;
145 hitCollection->AddHit(ind, m_id[ind], edep);
146
147 return true;
148}
This class is attached to G4Event objects as UserInformation.
std::shared_ptr< HitCollectionMap > GetHitCollectionMap() const
Get the HitCollectionMap object with shared ownership.
T * Find(std::string const &hitCollectionName)
Get the hit collection for a given SDs.
HitVectorBuilder * GetHitCollection()
static const int s_nCellMu
Definition MuonWallSD.h:46
void Initialize(G4HCofThisEvent *) override final
Identifier m_id[NCells]
Definition MuonWallSD.h:51
const TileTBID * m_tileTBID
Definition MuonWallSD.h:44
G4bool ProcessHits(G4Step *, G4TouchableHistory *) override final
HitVectorBuilder * m_hitCollection
Definition MuonWallSD.h:53
const std::string m_hitCollectionName
Definition MuonWallSD.h:52
static const int s_nCellS
Definition MuonWallSD.h:47
TileHitVectorCellBuilder< NCells > HitVectorBuilder
Definition MuonWallSD.h:38
MuonWallSD(const std::string &name, const std::string &hitCollectionName, int verbose)
bool HasHit(std::size_t index) const
void AddHit(std::size_t index, Identifier id, double energy, double time=0.0, double deltaT=0.0)
std::string description
glabal timer - how long have I taken so far?
Definition hcg.cxx:93
bool verbose
Definition hcg.cxx:75