ATLAS Offline Software
Loading...
Searching...
No Matches
TGCSensitiveDetectorCosmics Class Reference

#include <TGCSensitiveDetectorCosmics.h>

Inheritance diagram for TGCSensitiveDetectorCosmics:
Collaboration diagram for TGCSensitiveDetectorCosmics:

Public Member Functions

 TGCSensitiveDetectorCosmics (const std::string &name, const std::string &hitCollectionName)
 construction/destruction
void Initialize (G4HCofThisEvent *HCE) override final
 member functions
G4bool ProcessHits (G4Step *aStep, G4TouchableHistory *ROHist) override final

Private Member Functions

 FRIEND_TEST (TGCSensitiveDetectorCosmicstest, Initialize)
 FRIEND_TEST (TGCSensitiveDetectorCosmicstest, ProcessHits)

Private Attributes

Amg::Vector3D m_mom
double m_momMag
Amg::Vector3D m_vertex
Amg::Vector3D m_currVertex
Amg::Vector3D m_globH
double m_globalTime
std::string m_hitCollectionName
 member data
TGCSimHitCollectionm_myTGCHitColl {nullptr}
AtlasG4EventUserInfom_g4UserEventInfo {nullptr}
const TgcHitIdHelperm_muonHelper

Detailed Description

Author
haseg.nosp@m.awa@.nosp@m.azusa.nosp@m..shi.nosp@m.nshu-.nosp@m.u.ac.nosp@m..jp

methods and properties

The method TGCSensitiveDetectorCosmics::ProcessHits is executed by the G4 kernel each time a charged particle (or a geantino) crosses one of the TGC Gas volumes.

Navigating with the touchableHistory method GetHistoryDepth() through the hierarchy of the volumes crossed by the particles, the TGCSensitiveDetectorCosmicsCosmicsdeterminates the correct set of geometry parameters to be folded in the Simulation Identifier associated to each hit. The TGC SimIDs are 32-bit unsigned integers, built using the MuonSimEvent/TgcHitIdHelper class which inherits from the MuonHitIdHelper base class.

The modified version (Daniela Rebuzzi, 16/12/2005) calculates the tof for the cosmics, using as t0 the time to the closest approach of the track to (0,0,0). This implementation works also for slow particles, since the discrimination physics event/cosmics is done relying on the G4Track vertex (not on the tof).

We describe in the following, how each field of the identifier is retrieved.

1) stationName and stationPhi: when a volume is found in the hierarchy, whose name contains the substring "station", the stationName is extracted from the volume's name; stationPhi is calculated starting from the volume copy number assigned by MuonGeoModel. Separate cases when the station are "F" or "E" type.

2) stationEta: when a volume is found in the hierarchy, whose name contains the substring "tgccomponent", stationEta is calculated starting from the volume copy number assigned by MuonGeoModel. Possibility to calculate the stationPhi at this level, from the copy number assigned by MuonGeoModel (if the copyNo > 1000).

3) gasGap: when a volume is found in the hierarchy, whose name contains the substring "Gas Volume Layer" or "TGCGas", the gasGap is calculated from the volume copy number, according to the positive or negative Z value, in the Atlas global reference system.

@section Some notes:

1) since the volume copy numbers strongly depend on the database layout, the volume name (whether it contains the string "Q02", for instance) is used to retrieve geometry information. In the year 2018 and even some years before there are not any more other database layouts / volumes than MUONQ02 and therefore some logic was removed.

2) for each hit, the time of flight (the G4 globalTime), is recorded and associated to the hit.

3) the TGCHit object contains: the SimID, the globalTime, the hit position in the local reference system, the track director cosine in the local reference system and the track identifier.

Definition at line 77 of file TGCSensitiveDetectorCosmics.h.

Constructor & Destructor Documentation

◆ TGCSensitiveDetectorCosmics()

TGCSensitiveDetectorCosmics::TGCSensitiveDetectorCosmics ( const std::string & name,
const std::string & hitCollectionName )

construction/destruction

Definition at line 17 of file TGCSensitiveDetectorCosmics.cxx.

18 : G4VSensitiveDetector( name )
19 , m_momMag(0)
20 , m_globalTime(0)
21 , m_hitCollectionName( hitCollectionName )
22{
24}
static const TgcHitIdHelper * GetHelper()

Member Function Documentation

◆ FRIEND_TEST() [1/2]

TGCSensitiveDetectorCosmics::FRIEND_TEST ( TGCSensitiveDetectorCosmicstest ,
Initialize  )
private

◆ FRIEND_TEST() [2/2]

TGCSensitiveDetectorCosmics::FRIEND_TEST ( TGCSensitiveDetectorCosmicstest ,
ProcessHits  )
private

◆ Initialize()

void TGCSensitiveDetectorCosmics::Initialize ( G4HCofThisEvent * HCE)
finaloverride

member functions

Definition at line 27 of file TGCSensitiveDetectorCosmics.cxx.

28{
29 m_myTGCHitColl = nullptr;
30 if (auto* eventInfo = AtlasG4EventUserInfo::GetEventUserInfo()) {
31 m_myTGCHitColl = eventInfo->GetHitCollectionMap()->Find<TGCSimHitCollection>(m_hitCollectionName);
32 m_g4UserEventInfo = eventInfo;
33 }
34 // START OF COSMICS-SPECIFIC CODE
35 m_mom = Amg::Vector3D(0.,0.,0.);
36 m_globH = Amg::Vector3D(0.,0.,0.);
37 // END OF COSMICS-SPECIFIC CODE
38}
AtlasHitsVector< TGCSimHit > TGCSimHitCollection
static AtlasG4EventUserInfo * GetEventUserInfo()
Eigen::Matrix< double, 3, 1 > Vector3D

◆ ProcessHits()

G4bool TGCSensitiveDetectorCosmics::ProcessHits ( G4Step * aStep,
G4TouchableHistory * ROHist )
finaloverride

Definition at line 40 of file TGCSensitiveDetectorCosmics.cxx.

40 {
41
42 if (!m_myTGCHitColl) {
43 G4Exception("TGCSensitiveDetectorCosmics::ProcessHits", "TGCCosmicHitCollectionMissing", FatalException,
44 "Hit collection not initialized; did SetupEvent run?");
45 return false;
46 }
47
48 G4Track* track = aStep->GetTrack();
49
50 if (track->GetDefinition()->GetPDGCharge() == 0.0) {
51 if (track->GetDefinition()!=G4Geantino::GeantinoDefinition()) return true;
52 else if (track->GetDefinition()==G4ChargedGeantino::ChargedGeantinoDefinition()) return true;
53 }
54 const G4TouchableHistory* touchHist = static_cast<const G4TouchableHistory*>(aStep->GetPreStepPoint()->GetTouchable());
55 G4ThreeVector position = aStep->GetPreStepPoint()->GetPosition();
56 const G4AffineTransform trans = track->GetTouchable()->GetHistory()->GetTopTransform();
57
58 // fields for the TGC identifier construction
59 std::string stationName;
60 int stationEta(0);
61 int stationPhi(0);
62 int gasGap = 0;
63
64 // TGC hit information
65 double globalTime = aStep->GetPreStepPoint()->GetGlobalTime();
66 Amg::Vector3D localPosition = Amg::Hep3VectorToEigen( trans.TransformPoint(position) );
67 G4ThreeVector direcos = aStep->GetPreStepPoint()->GetMomentumDirection();
68 Amg::Vector3D localDireCos = Amg::Hep3VectorToEigen( trans.TransformAxis(direcos) );
69
70 // START OF COSMICS-SPECIFIC CODE
71 // global coordinates
72 G4ThreeVector globVrtx = aStep->GetPreStepPoint()->GetPosition();
73
74 // distance of the hit from (0,0,0) vertex - calculated from the PreStepPoint (approximation)
75 double dist = globVrtx.mag();
76 double inv_lightspeed = 1. / CLHEP::c_light;
77 double tOrigin = dist * inv_lightspeed;
78
79 G4int trackid = aStep->GetTrack()->GetTrackID();
80 m_currVertex = Amg::Hep3VectorToEigen(aStep->GetTrack()->GetVertexPosition());
81
82 // for cosmics: only primary muon tracks - track momentum when first entering the spectrometer (one muon per event)
83 if ((m_currVertex != m_vertex) && (trackid == 1)) {
84 // after calculationg the momentum magnidude, normalize it
85 m_mom = Amg::Hep3VectorToEigen(track->GetMomentum());
86 m_momMag = m_mom.mag();
87 m_mom.normalize();
88 // the direction of the primary mu is used to calculate the t0, the position ot the t0, m_globH, is ONE for a track
89 Amg::Vector3D globVrtxFix = Amg::Hep3VectorToEigen( globVrtx );
90 double AlphaGlobal = -1*(globVrtxFix[0]*m_mom[0] + globVrtxFix[1]*m_mom[1] + globVrtxFix[2]*m_mom[2])/(m_mom[0]*m_mom[0] + m_mom[1]*m_mom[1] + m_mom[2]*m_mom[2]);
91 m_globH = globVrtxFix + AlphaGlobal*m_mom;
92 // G4cout << "COSMICS MAIN TRACK IN THE TGC!" << G4endl;
93 }
94 double globalDist = sqrt((m_globH[0] - globVrtx[0])*(m_globH[0] - globVrtx[0]) +
95 (m_globH[1] - globVrtx[1])*(m_globH[1] - globVrtx[1]) +
96 (m_globH[2] - globVrtx[2])*(m_globH[2] - globVrtx[2]));
97 double tof = globalDist * inv_lightspeed;
98 // END OF COSMICS-SPECIFIC CODE
99
100 // scan geometry tree to identify hit channel
101 int zside(0);
102 for (int i=touchHist->GetHistoryDepth();i>=0;i--) {
103
104 std::string::size_type npos;
105 std::string volName = touchHist->GetVolume(i)->GetName();
106
107 // stationName and stationPhi
108 if ((npos = volName.find("station")) != std::string::npos) {
109
110 stationName = volName.substr(0,npos-2);
111 int volCopyNo = touchHist->GetVolume(i)->GetCopyNo();
112 if (volCopyNo > 0) {
113 zside = 1;
114 } else {
115 zside = -1;
116 }
117 if (stationName.compare(2,1, "F") == 0) {
118
119 stationPhi = (abs(volCopyNo%100)-1)*3;
120 if (abs(volCopyNo/100) > 3) {
121 stationPhi += abs(volCopyNo/100)-3;
122 } else {
123 stationPhi += abs(volCopyNo/100);
124 }
125
126 stationPhi -= 1;
127 if (stationPhi <= 0) {
128 stationPhi = 24 - stationPhi;
129 }
130
131 } else if (stationName.compare(2,1,"E") == 0) {
132 if (stationName.compare(1,1,"4") == 0) {
133
134 stationPhi = (abs(volCopyNo%100)-1)*3+abs(volCopyNo/100);
135
136 if (abs(volCopyNo%100) < 4) {
138 if (stationPhi <= 0) {
139 stationPhi = 21 - stationPhi;
140 }
141 } else if(abs(volCopyNo%100) < 7) {
142 stationPhi = stationPhi - 1 - 1;
143 } else {
144 stationPhi = stationPhi - 2 - 1;
145 }
146
147 } else {
148
149 stationPhi = (abs(volCopyNo%100)-1)*6+abs(volCopyNo/100);
150
151 stationPhi -= 2;
152 if (stationPhi <= 0) {
153 stationPhi = 48 - stationPhi;
154 }
155 }
156 }
157
158 // stationEta
159 } else if ((npos = volName.find("tgccomponent")) != std::string::npos) {
160 int volCopyNo = abs(touchHist->GetVolume(i)->GetCopyNo());
161 stationEta = zside*volCopyNo%100;
162 if (volCopyNo > 1000) { // stationPhi overridden by the number assigned by MuonGeoModel
163 stationPhi = volCopyNo/1000;
164 }
165
166 // gasGap
167 } else if ((npos = volName.find("Gas Volume Layer")) != std::string::npos) {
168 int volCopyNo = touchHist->GetVolume(i)->GetCopyNo();
169 int iStation = atoi(stationName.substr(1,1).c_str());
170 if (zside < 0) {
171 if (iStation == 1)
172 gasGap = 3-(volCopyNo-3)/4;
173 else
174 gasGap = 2-(volCopyNo-3)/4;
175 } else {
176// if (iStation == 1)
177 gasGap = (volCopyNo-3)/4+1;
178// else
179// gasGap = (volCopyNo-3)/4+1;
180 }
181 } else if ((npos = volName.find("TGCGas")) != std::string::npos) {
182
183 int volCopyNo = touchHist->GetVolume(i)->GetCopyNo();
184
185 if (volCopyNo != 0)
186 gasGap = volCopyNo;
187 }
188 }
189
190 //construct the hit identifier
191 HitID TGCid = m_muonHelper->BuildTgcHitId(stationName,
192 stationPhi,
193 stationEta,
194 gasGap);
195 //m_muonHelper->Print(TGCid);
196 // START OF COSMICS-SPECIFIC CODE
197 m_vertex = Amg::Hep3VectorToEigen(aStep->GetTrack()->GetVertexPosition());
198 // if the track m_vertex is far from (0,0,0), takes the tof, otherwise take the "usual" g4 globalTime
199 ((((m_vertex.mag()) < 100) || ((fabs(globalTime - tOrigin)) < 0.1) ) ? (m_globalTime = globalTime) : (m_globalTime = tof));
200 // if m_globalTime != globalTime and m_globalTime != tof in the output, this is due to multiple hits
201 // before founding the good one (small approximation)
202 // END OF COSMICS-SPECIFIC CODE
203
204 // construct new mdt hit
205 TrackHelper trHelp(aStep->GetTrack());
206
207 m_myTGCHitColl->Emplace(TGCid,
209 localPosition,
210 localDireCos,
211 trHelp.GenerateParticleLink(m_g4UserEventInfo ? m_g4UserEventInfo->GetEventStore() : nullptr),
212 aStep->GetTotalEnergyDeposit(),
213 aStep->GetStepLength());
214 return true;
215}
int HitID
Amg::Vector3D Hep3VectorToEigen(const CLHEP::Hep3Vector &CLHEPvector)
Converts a CLHEP-based CLHEP::Hep3Vector into an Eigen-based Amg::Vector3D.
int atoi(std::string_view str)
Helper functions to unpack numbers decoded in string into integers and doubles The strings are requir...
constexpr uint8_t stationPhi
station Phi 1 to 8

Member Data Documentation

◆ m_currVertex

Amg::Vector3D TGCSensitiveDetectorCosmics::m_currVertex
private

Definition at line 93 of file TGCSensitiveDetectorCosmics.h.

◆ m_g4UserEventInfo

AtlasG4EventUserInfo* TGCSensitiveDetectorCosmics::m_g4UserEventInfo {nullptr}
private

Definition at line 100 of file TGCSensitiveDetectorCosmics.h.

100{nullptr};

◆ m_globalTime

double TGCSensitiveDetectorCosmics::m_globalTime
private

Definition at line 95 of file TGCSensitiveDetectorCosmics.h.

◆ m_globH

Amg::Vector3D TGCSensitiveDetectorCosmics::m_globH
private

Definition at line 94 of file TGCSensitiveDetectorCosmics.h.

◆ m_hitCollectionName

std::string TGCSensitiveDetectorCosmics::m_hitCollectionName
private

member data

Definition at line 98 of file TGCSensitiveDetectorCosmics.h.

◆ m_mom

Amg::Vector3D TGCSensitiveDetectorCosmics::m_mom
private

Definition at line 90 of file TGCSensitiveDetectorCosmics.h.

◆ m_momMag

double TGCSensitiveDetectorCosmics::m_momMag
private

Definition at line 91 of file TGCSensitiveDetectorCosmics.h.

◆ m_muonHelper

const TgcHitIdHelper* TGCSensitiveDetectorCosmics::m_muonHelper
private

Definition at line 101 of file TGCSensitiveDetectorCosmics.h.

◆ m_myTGCHitColl

TGCSimHitCollection* TGCSensitiveDetectorCosmics::m_myTGCHitColl {nullptr}
private

Definition at line 99 of file TGCSensitiveDetectorCosmics.h.

99{nullptr};

◆ m_vertex

Amg::Vector3D TGCSensitiveDetectorCosmics::m_vertex
private

Definition at line 92 of file TGCSensitiveDetectorCosmics.h.


The documentation for this class was generated from the following files: