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
17
18#include "GaudiKernel/ISvcLocator.h"
19#include "GaudiKernel/Bootstrap.h"
20
21#include "G4HCofThisEvent.hh"
22#include "G4VPhysicalVolume.hh"
23#include "G4Step.hh"
24#include "G4VTouchable.hh"
25#include "G4TouchableHistory.hh"
26
27MuonWallSD::MuonWallSD(const std::string& name, const std::string& hitCollectionName, int verbose)
28 : G4VSensitiveDetector(name),
29 m_nhits(),
30 m_hit(),
31 m_HitColl(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 if (verboseLevel >= 5) {
67 G4cout << "Initializing SD" << G4endl;
68 }
69
70 memset(m_nhits, 0, sizeof(m_nhits));
71}
72
73void MuonWallSD::Initialize(G4HCofThisEvent* /* HCE */) {
74 if (verboseLevel >= 5) {
75 G4cout << "MuonWallSD::Initialize()" << G4endl;
76 }
77
78 if (!m_HitColl.isValid()) {
79 m_HitColl = std::make_unique<TileHitVector>(m_HitColl.name());
80 }
81}
82
83G4bool MuonWallSD::ProcessHits(G4Step* aStep, G4TouchableHistory* /* ROhist */) {
84 if (verboseLevel >= 10) {
85 G4cout << "MuonWallSD::ProcessHits" << G4endl;
86 }
87
88 const G4TouchableHistory* theTouchable = static_cast<const G4TouchableHistory*>(aStep->GetPreStepPoint()->GetTouchable());
89 const G4VPhysicalVolume* physVol = theTouchable->GetVolume();
90 const G4LogicalVolume* logiVol = physVol->GetLogicalVolume();
91 const G4String nameLogiVol = logiVol->GetName();
92 const G4int nScinti = physVol->GetCopyNo();
93
94 const G4double edep = aStep->GetTotalEnergyDeposit() * aStep->GetTrack()->GetWeight();
95 G4double stepl = 0.;
96
97 if (aStep->GetTrack()->GetDefinition()->GetPDGCharge() != 0.){ // FIXME not-equal check on double
98
99 stepl = aStep->GetStepLength();
100 }
101
102 if ((edep == 0.) && (stepl == 0.)) { //FIXME equality check on double
103
104 return false;
105 }
106
107 int ind;
108
109 if(nameLogiVol.find("MuScintillatorLayer") !=G4String::npos) {
110 // for muon wall, nScinti-1 is the correct indice.
111 ind = nScinti-1;
112 } else if(nameLogiVol.find("S1") !=G4String::npos) {
113 ind = s_nCellMu + 0;
114 } else if(nameLogiVol.find("S2") !=G4String::npos) {
115 ind = s_nCellMu + 1;
116 } else if(nameLogiVol.find("S3") !=G4String::npos) {
117 ind = s_nCellMu + 2;
118 } else {
119 ind = s_nCellMu + 3;
120 }
121
122 if (verboseLevel >= 10) {
123 G4cout << ((m_nhits[ind] > 0)?"Additional hit in ":"First hit in ")
124 << ((ind<s_nCellMu)?"MuonWall ":"beam counter S")
125 << ((ind<s_nCellMu)?nScinti:(ind-s_nCellMu+1))
126 << " time=" << aStep->GetPostStepPoint()->GetGlobalTime()
127 << " ene=" << edep << G4endl;
128 }
129
130 if ( m_nhits[ind] > 0 ) {
131 m_hit[ind]->add(edep,0.0,0.0);
132 } else {
133 // First hit in a cell
134 m_hit[ind] = new TileSimHit(m_id[ind],edep,0.0,0.0);
135 }
136
137 ++m_nhits[ind];
138
139 return true;
140}
141
143 for (int ind = 0; ind < s_nCell; ++ind) {
144 int nhit = m_nhits[ind];
145 if (nhit > 0) {
146 if (verboseLevel >= 5) {
147 G4cout << "Cell id=" << m_tileTBID->to_string(m_id[ind])
148 << " nhit=" << nhit
149 << " ene=" << m_hit[ind]->energy() << G4endl;
150 }
151 m_HitColl->Insert(TileHit(m_hit[ind]));
152 delete m_hit[ind];
153 } else if (verboseLevel >= 10) {
154 G4cout << "Cell id=" << m_tileTBID->to_string(m_id[ind])
155 << " nhit=0" << G4endl;
156 }
157 }
158
159 if (verboseLevel >= 5) {
160 G4cout << "Total number of hits is " << m_HitColl->size() << G4endl;
161 }
162 return ;
163}
void EndOfAthenaEvent()
static const int s_nCellMu
Definition MuonWallSD.h:47
void Initialize(G4HCofThisEvent *) override final
const TileTBID * m_tileTBID
Definition MuonWallSD.h:45
TileSimHit * m_hit[s_nCell]
Definition MuonWallSD.h:52
G4bool ProcessHits(G4Step *, G4TouchableHistory *) override final
Identifier m_id[s_nCell]
Definition MuonWallSD.h:53
void StartOfAthenaEvent()
int m_nhits[s_nCell]
Definition MuonWallSD.h:51
static const int s_nCell
Definition MuonWallSD.h:49
SG::WriteHandle< TileHitVector > m_HitColl
Definition MuonWallSD.h:55
static const int s_nCellS
Definition MuonWallSD.h:48
MuonWallSD(const std::string &name, const std::string &hitCollectionName, int verbose)
std::string description
glabal timer - how long have I taken so far?
Definition hcg.cxx:91
bool verbose
Definition hcg.cxx:73