ATLAS Offline Software
MuonWallSD.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 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 
15 #include "StoreGate/StoreGateSvc.h"
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 
27 MuonWallSD::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) {
57  }
58 
60  for (int channel=0; channel<s_nCellS; ++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 
73 void 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 
83 G4bool MuonWallSD::ProcessHits(G4Step* aStep, G4TouchableHistory* /* ROhist */) {
84  if (verboseLevel >= 10) {
85  G4cout << "MuonWallSD::ProcessHits" << G4endl;
86  }
87 
88  const G4TouchableHistory* theTouchable = (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 }
MuonWallSD::ProcessHits
G4bool ProcessHits(G4Step *, G4TouchableHistory *) override final
Definition: MuonWallSD.cxx:83
TileTBID::channel_id
Identifier channel_id(int type, int module, int channel) const
identifer for one channel of a Tile testbeam detector
Definition: TileTBID.cxx:197
TileTBID::to_string
std::string to_string(const Identifier &id, int level=0) const
extract all fields from TileTB identifier Identifier get_all_fields ( const Identifier & id,...
Definition: TileTBID.cxx:49
MuonWallSD::m_nhits
int m_nhits[s_nCell]
Definition: MuonWallSD.h:51
plotting.yearwise_efficiency.channel
channel
Definition: yearwise_efficiency.py:24
MuonWallSD::MuonWallSD
MuonWallSD(const std::string &name, const std::string &hitCollectionName, int verbose)
Definition: MuonWallSD.cxx:27
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
MuonWallSD::m_hit
TileSimHit * m_hit[s_nCell]
Definition: MuonWallSD.h:52
TileSimHit
Definition: TileSimHit.h:31
TileTBID::ADC_TYPE
@ ADC_TYPE
Definition: Calorimeter/CaloIdentifier/CaloIdentifier/TileTBID.h:84
MuonWallSD::EndOfAthenaEvent
void EndOfAthenaEvent()
Definition: MuonWallSD.cxx:142
MuonWallSD::m_tileTBID
const TileTBID * m_tileTBID
Definition: MuonWallSD.h:45
TileSimHit::add
int add(double energy, double time, double deltaT)
Add sub-hit to a given hit with time rounding to the center of nearest deltaT bin.
Definition: TileSimHit.cxx:41
python.PyAthena.module
module
Definition: PyAthena.py:131
MuonWallSD::m_id
Identifier m_id[s_nCell]
Definition: MuonWallSD.h:53
MuonWallSD.h
TileTBID.h
MuonWallSD::m_HitColl
SG::WriteHandle< TileHitVector > m_HitColl
Definition: MuonWallSD.h:55
MuonWallSD::s_nCell
static const int s_nCell
Definition: MuonWallSD.h:49
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
TileHitVector.h
TileSimHit::energy
double energy(int ind=0) const
Return energy of ind-th sub-hit
Definition: TileSimHit.h:51
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
TileHit
Definition: TileSimEvent/TileSimEvent/TileHit.h:30
MuonWallSD::s_nCellMu
static const int s_nCellMu
Definition: MuonWallSD.h:47
TileTBID::CRACK_WALL
@ CRACK_WALL
Definition: Calorimeter/CaloIdentifier/CaloIdentifier/TileTBID.h:93
TileTBID::BACK_WALL
@ BACK_WALL
Definition: Calorimeter/CaloIdentifier/CaloIdentifier/TileTBID.h:91
MuonWallSD::s_nCellS
static const int s_nCellS
Definition: MuonWallSD.h:48
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
python.TriggerHandler.verbose
verbose
Definition: TriggerHandler.py:297
MuonWallSD::StartOfAthenaEvent
void StartOfAthenaEvent()
Definition: MuonWallSD.cxx:65
MuonWallSD::Initialize
void Initialize(G4HCofThisEvent *) override final
Definition: MuonWallSD.cxx:73
StoreGateSvc.h
checkFileSG.ind
list ind
Definition: checkFileSG.py:118
description
std::string description
glabal timer - how long have I taken so far?
Definition: hcg.cxx:88