58 G4Exception(
"MDTSensitiveDetectorCosmics::ProcessHits",
"MDTCosmicHitCollectionMissing", FatalException,
59 "Hit collection not initialized; did SetupEvent run?");
63 G4Track* currentTrack = aStep->GetTrack();
66 if (currentTrack->GetDefinition()->GetPDGCharge() == 0.0) {
67 if (currentTrack->GetDefinition()!=G4Geantino::GeantinoDefinition())
return true;
68 else if (currentTrack->GetDefinition()==G4ChargedGeantino::ChargedGeantinoDefinition())
return true;
71 G4VPhysicalVolume* physVolPostStep = aStep->GetPostStepPoint()->GetPhysicalVolume();
72 if (
nullptr == physVolPostStep)
return true;
78 localPosition.setZero();
81 const G4AffineTransform trans = currentTrack->GetTouchable()->GetHistory()->GetTopTransform();
85 G4ThreeVector globVrtx = aStep->GetPreStepPoint()->GetPosition();
88 double dist = globVrtx.mag();
89 double lightspeed = 299.792458;
90 double tOrigin = dist / lightspeed;
92 G4int trackid = aStep->GetTrack()->GetTrackID();
107 double globalDist = sqrt((
m_globH[0] - globVrtx[0])*(
m_globH[0] - globVrtx[0]) +
110 double tof = globalDist / lightspeed;
119 Amg::Vector3D localDirection( (localVertex2 - localVertex1) );
120 localDirection.z() = 0.;
123 if( (localVertex2.dot(localDirection)) * (localVertex1.dot(localDirection)) < 0 ) {
126 double Xpos = localVertex1[0];
127 double Ypos = localVertex1[1];
128 double Xdir = localDirection[0];
129 double Ydir = localDirection[1];
131 double Alpha = -1*(Xpos*Xdir + Ypos*Ydir)/(Xdir*Xdir + Ydir*Ydir);
133 localPosition = localVertex1 + Alpha*(localVertex2-localVertex1);
134 driftRadius = localPosition.perp();
135 globalTime = aStep->GetPreStepPoint()->GetGlobalTime();
140 double dist1 = localVertex1.perp();
141 double dist2 = localVertex2.perp();
144 localPosition = localVertex1;
145 globalTime = aStep->GetPreStepPoint()->GetGlobalTime();
148 localPosition = localVertex2;
149 globalTime = aStep->GetPostStepPoint()->GetGlobalTime();
164 G4String namePreStepMat = aStep->GetPreStepPoint()->GetMaterial()->GetName();
165 G4String namePostStepMat = aStep->GetPostStepPoint()->GetMaterial()->GetName();
166 G4String nameSD = aStep->GetPreStepPoint()->GetPhysicalVolume()->GetLogicalVolume()->GetSensitiveDetector()->GetName();
169 if( ((nameSD) && (namePreStepMat != namePostStepMat)) || (currentTrack->GetTrackStatus() == fStopAndKill)){
172 const G4TouchableHistory* touchHist =
static_cast<const G4TouchableHistory*
>(aStep->GetPreStepPoint()->GetTouchable());
180 aStep->GetStepLength(),
181 aStep->GetTotalEnergyDeposit(),
182 currentTrack->GetDefinition()->GetPDGEncoding(),
183 aStep->GetPreStepPoint()->GetKineticEnergy());
193 std::string stationName;
200 bool isAssembly =
false;
202 for (
int i = touchHist->GetHistoryDepth(); i>=0; i--) {
204 std::string::size_type npos;
205 std::string::size_type loc1;
206 std::string::size_type loc2;
207 std::string volName = touchHist->GetVolume(i)->GetName();
210 if ((npos = volName.find(
"av_")) != std::string::npos &&
211 (npos = volName.find(
"impr_")) != std::string::npos) isAssembly =
true;
214 if ((npos = volName.find(
"station")) != std::string::npos && (!isAssembly)) {
216 volName.resize(npos-2);
217 int volCopyNo = touchHist->GetVolume(i)->GetCopyNo();
218 volCopyNo=volCopyNo%1000;
219 stationName = volName;
220 stationEta = volCopyNo/100;
221 stationPhi = abs(volCopyNo%100);
224 else if ((npos = volName.find(
"component")) != std::string::npos && (!isAssembly)) {
227 if ((loc1 = volName.find(
'[')) != std::string::npos) {
228 if ((loc2 = volName.find(
']', loc1+1)) != std::string::npos) {
229 std::istringstream istrvar(volName.substr(loc1+1,loc2-loc1-1));
235 }
else if ((npos = volName.find(
"MDT")) != std::string::npos && isAssembly) {
253 if ((loc1 = volName.find(
"Muon::")) != std::string::npos) {
254 stationName = volName.substr(loc1+6,3);
257 int copyNr = touchHist->GetVolume(i)->GetCopyNo();
258 int copyNrBase = int(copyNr/100000);
259 int sideC = int(copyNrBase/10000);
260 int zi = int((copyNrBase%1000)/100);
261 int fi = int(copyNrBase%100);
262 if (sideC == 1) zi = -zi;
267 if ((loc1 = volName.find(
'[')) != std::string::npos) {
268 if ((loc2 = volName.find(
']', loc1+1)) != std::string::npos) {
269 std::istringstream istrvar(volName.substr(loc1+1,loc2-loc1-1));
274 }
else if ((npos = volName.find(
"Drift")) != std::string::npos) {
275 tubeLayer = touchHist->GetVolume(i)->GetCopyNo()/maxNTubesPerLayer;
276 tube = touchHist->GetVolume(i)->GetCopyNo()%maxNTubesPerLayer;
280 return m_muonHelper->BuildMdtHitId(stationName, stationPhi, stationEta, multilayer,tubeLayer, tube);