ATLAS Offline Software
Loading...
Searching...
No Matches
CSCSensitiveDetector.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
6#include "G4Trd.hh"
7#include <string>
8#include <sstream>
11#include "MCTruth/TrackHelper.h"
12#include "G4Exception.hh"
13#include "G4Geantino.hh"
14#include "G4ChargedGeantino.hh"
15
16
18
19// construction/destruction
21 const std::string& hitCollectionName)
22 : G4VSensitiveDetector( name )
23 , m_hitCollectionName( hitCollectionName )
24{
26}
27
28// Implemenation of memebr functions
30{
31 m_myCSCHitColl = nullptr;
32 if (auto* eventInfo = AtlasG4EventUserInfo::GetEventUserInfo()) {
33 m_myCSCHitColl = eventInfo->GetHitCollectionMap()->Find<CSCSimHitCollection>(m_hitCollectionName);
34 m_g4UserEventInfo = eventInfo;
35 }
36}
37
38G4bool CSCSensitiveDetector::ProcessHits(G4Step* aStep,G4TouchableHistory* /*ROHist*/) {
39
40 if (!m_myCSCHitColl) {
41 G4Exception("CSCSensitiveDetector::ProcessHits", "CSCHitCollectionMissing", FatalException,
42 "Hit collection not initialized; did SetupEvent run?");
43 return false;
44 }
45
46 G4Track* currentTrack = aStep->GetTrack();
47
49 auto trackDef = currentTrack->GetDefinition();
50 if (trackDef->GetPDGCharge() == 0.0) {
51 if (trackDef != G4Geantino::GeantinoDefinition()) return true;
52 else if (trackDef == G4ChargedGeantino::ChargedGeantinoDefinition()) return true;
53 }
54
55 const G4TouchableHistory* touchHist = static_cast<const G4TouchableHistory*>(aStep->GetPreStepPoint()->GetTouchable());
56 G4ThreeVector startPos=aStep->GetPreStepPoint()->GetPosition();
57 G4ThreeVector endPos=aStep->GetPostStepPoint()->GetPosition();
58 double kinEnergy = aStep->GetPreStepPoint()->GetKineticEnergy();
59
61
62 std::string stationName="";
63 int stationEta=1;
64 int stationPhi=1;
65 int multiLayer=1;
66 int wireLayer=0;
67
69
70 Amg::Vector3D HitStart = Amg::Vector3D(-1000,-1000,-1000);
71 Amg::Vector3D HitEnd = Amg::Vector3D(-1000,-1000,-1000);
72 double globalTime = -1;
73 double energyDeposit= -1;
74 G4int lundcode = -1;
75 // int trackid = -1;
76
78
79 bool isAssembly = false;
80 for (int i = touchHist->GetHistoryDepth(); i>=0; --i) {
81 std::string::size_type npos;
82 std::string volName = touchHist->GetVolume(i)->GetName();
83
84 //G4cout << "Csc SD: swimming through the tree: level "<<i-touchHist->GetHistoryDepth() << G4endl;
85 //G4cout << "Csc SD: name "<<volName << G4endl;
86
88 if ((npos = volName.find("av_")) != std::string::npos &&
89 (npos = volName.find("impr_")) != std::string::npos) isAssembly = true;
90
91 if ((npos = volName.find("station")) != std::string::npos && (!isAssembly)) {
92
94 volName.resize(npos-2);
95 int volCopyNo = touchHist->GetVolume(i)->GetCopyNo();
96 stationName = volName;
97 //stationEta = volCopyNo/100;
98 // bug fix for 14.2.0 to cope with non-mirrored chambers as proposed by
99 // S.Spagnolo
100 stationEta = (volCopyNo%1000)/100;
101 stationPhi = abs(volCopyNo%100);
102
103 } else if ((npos = volName.find("CSC")) != std::string::npos && isAssembly ) {
104 // vol name for Assembly components are
105 // av_WWW_impr_XXX_Muon::BMSxMDTxx_pv_ZZZ_NAME
106 // where WWW is ass. istance nr.
107 // XXX is comp. imprint nr.
108 // BMSxMDTxx is the name of the comp. log.Vol.
109 // x station sub-type; xx technology subtype
110 // ZZZ is No of order of this daugther
111 // NAME is the comp. tag (geoIdentifierTag)
112 // for CSCs it is cl[1] or cl[2]
113 // copy numbers for Ass.components are =
114 // CopyNoBase(= geoIdentifierTag of the assembly) + geoIdentifierTag of the component
115 // geoIdentifierTag of the component = Job
116 // geoIdentifierTag of the assembly = (sideC*10000 +
117 // mirsign*1000 + abs(zi)*100 + fi+1)*100000;
118 // mirsign*1000 + abs(zi)*100 + fi+1)*100000;
119
121 std::string::size_type loc1,loc2;
122 if ((loc1 = volName.find("Muon::")) != std::string::npos) {
123 stationName = volName.substr(loc1+6,3); //type only
124 }
125
127 int volCopyNo = touchHist->GetVolume(i)->GetCopyNo();
128 int copyNrBase = int(volCopyNo/100000);
129 int sideC = int(copyNrBase/10000);
130 int zi = int((copyNrBase%1000)/100);
131 // int mirfl = int((copyNrBase%10000)/1000);
132 int fi = int(copyNrBase%100);
133 if (sideC == 1) zi = -zi;
134 stationEta = zi;
135 stationPhi = fi;
136
137 // now get the geoIdentifierTag of the rpc components
138 int gmID = 0;
139 if ((loc1 = volName.find('[')) != std::string::npos) {
140 if ((loc2 = volName.find(']', loc1+1)) != std::string::npos) {
141 std::istringstream istrvar(volName.substr(loc1+1,loc2-loc1-1));
142 istrvar>>gmID;
143 }
144 }
146 multiLayer = gmID;
147 } else if ((npos = volName.find("component")) != std::string::npos && (!isAssembly)) {
148
150 multiLayer = touchHist->GetVolume(i)->GetCopyNo();
151 if(multiLayer==3) multiLayer=2; //multilayer index
152 } else if ((npos = volName.find("CscArCO2")) != std::string::npos) {
153
155 wireLayer=touchHist->GetVolume(i)->GetCopyNo();
156 wireLayer+=1;
157 if(wireLayer==4) wireLayer=1;
158 else if(wireLayer==3) wireLayer=2;
159 else if(wireLayer==2) wireLayer=3;
160 else if(wireLayer==1) wireLayer=4;
161 // G4cout << "CSC:::::: wireLayer "<<wireLayer << G4endl;
162
164 G4String particle=aStep->GetTrack()->GetDefinition()->GetParticleName();
165 // http://www.slac.stanford.edu/BFROOT/www/Computing/Environment/NewUser/htmlbug/node51.html #GEANT code
166 if (particle=="gamma") lundcode=1;
167 else if (particle=="e+") lundcode=2;
168 else if (particle=="e-") lundcode=3;
169 else if (particle=="mu+") lundcode=5;
170 else if (particle=="mu-") lundcode=6;
171 else if (particle=="pi+") lundcode=8;
172 else if (particle=="pi-") lundcode=9;
173 else if (particle=="kaon+") lundcode=11;
174 else if (particle=="kaon-") lundcode=12;
175 else if (particle=="proton") lundcode=14;
176 else if (particle=="anti_proton") lundcode=15;
177 else if (particle=="sigma+") lundcode=19;
178 else if (particle=="sigma-") lundcode=21;
179 else if (particle=="anti_sigma-") lundcode=27;
180 else if (particle=="anti_sigma+") lundcode=29;
181 else if (particle=="deuteron") lundcode=45;
182 //else if (particle=="geantino") lundcode=999;
183 //else lundcode=999;
184
185 if (lundcode < 0)
186 G4cout << "WP CSCSensitiveDetector.cxx have exceptional particlue out of selection:: "
187 << particle<< G4endl;
188
190 // trackid=aStep->GetTrack()->GetTrackID();
191
193 globalTime = aStep->GetPreStepPoint()->GetGlobalTime();
194
196 energyDeposit = aStep->GetTotalEnergyDeposit();
197
199 const G4AffineTransform transform = touchHist->GetHistory()->GetTopTransform();
200
202 HitStart = Amg::Hep3VectorToEigen( transform.TransformPoint(startPos) );
203
206 HitEnd = Amg::Hep3VectorToEigen( transform.TransformPoint(endPos) );
207
208 }
209 }
210
211 TrackHelper trHelp(aStep->GetTrack());
212
214 HitID CSCid = m_muonHelper->BuildCscHitId(stationName, stationPhi,
215 stationEta, multiLayer, wireLayer);
217 m_myCSCHitColl->Emplace(CSCid, globalTime, energyDeposit,
218 HitStart, HitEnd, lundcode,
219 trHelp.GenerateParticleLink(m_g4UserEventInfo ? m_g4UserEventInfo->GetEventStore() : nullptr),kinEnergy);
220
221 return true;
222}
AtlasHitsVector< CSCSimHit > CSCSimHitCollection
int HitID
static AtlasG4EventUserInfo * GetEventUserInfo()
std::string m_hitCollectionName
member data
CSCSensitiveDetector(const std::string &name, const std::string &hitCollectionName)
construction/destruction
const CscHitIdHelper * m_muonHelper
G4bool ProcessHits(G4Step *aStep, G4TouchableHistory *ROhist) override final
AtlasG4EventUserInfo * m_g4UserEventInfo
void Initialize(G4HCofThisEvent *HCE) override final
member functions
CSCSimHitCollection * m_myCSCHitColl
static const CscHitIdHelper * GetHelper()
HepMcParticleLink GenerateParticleLink()
Generates a creates new HepMcParticleLink object on the stack based on GetUniqueID(),...
Definition TrackHelper.h:52
Amg::Vector3D Hep3VectorToEigen(const CLHEP::Hep3Vector &CLHEPvector)
Converts a CLHEP-based CLHEP::Hep3Vector into an Eigen-based Amg::Vector3D.
Eigen::Matrix< double, 3, 1 > Vector3D