Geant4 Cross Reference |
1 // 1 2 // ******************************************* 3 // * License and Disclaimer 4 // * 5 // * The Geant4 software is copyright of th 6 // * the Geant4 Collaboration. It is provided 7 // * conditions of the Geant4 Software License 8 // * LICENSE and available at http://cern.ch/ 9 // * include a list of copyright holders. 10 // * 11 // * Neither the authors of this software syst 12 // * institutes,nor the agencies providing fin 13 // * work make any representation or warran 14 // * regarding this software system or assum 15 // * use. Please see the license in the file 16 // * for the full disclaimer and the limitatio 17 // * 18 // * This code implementation is the result 19 // * technical work of the GEANT4 collaboratio 20 // * By using, copying, modifying or distri 21 // * any work based on the software) you ag 22 // * use in resulting scientific publicati 23 // * acceptance of all terms of the Geant4 Sof 24 // ******************************************* 25 // 26 // 27 /// \file optical/wls/src/WLSSteppingAction.cc 28 /// \brief Implementation of the WLSSteppingAc 29 // 30 // 31 #include "WLSSteppingAction.hh" 32 33 #include "WLSDetectorConstruction.hh" 34 #include "WLSEventAction.hh" 35 #include "WLSPhotonDetSD.hh" 36 #include "WLSSteppingActionMessenger.hh" 37 #include "WLSUserTrackInformation.hh" 38 39 #include "G4OpBoundaryProcess.hh" 40 #include "G4OpticalPhoton.hh" 41 #include "G4ProcessManager.hh" 42 #include "G4Run.hh" 43 #include "G4SDManager.hh" 44 #include "G4Step.hh" 45 #include "G4StepPoint.hh" 46 #include "G4SystemOfUnits.hh" 47 #include "G4ThreeVector.hh" 48 #include "G4Track.hh" 49 #include "G4TrackStatus.hh" 50 #include "G4UImanager.hh" 51 #include "G4VPhysicalVolume.hh" 52 #include "G4ios.hh" 53 54 // Purpose: Save relevant information into Use 55 56 //....oooOO0OOooo........oooOO0OOooo........oo 57 58 WLSSteppingAction::WLSSteppingAction(WLSDetect 59 : fDetector(detector), fEventAction(event) 60 { 61 fSteppingMessenger = new WLSSteppingActionMe 62 ResetCounters(); 63 } 64 65 //....oooOO0OOooo........oooOO0OOooo........oo 66 67 WLSSteppingAction::~WLSSteppingAction() 68 { 69 delete fSteppingMessenger; 70 } 71 72 //....oooOO0OOooo........oooOO0OOooo........oo 73 74 void WLSSteppingAction::SetBounceLimit(G4int i 75 { 76 fBounceLimit = i; 77 } 78 79 //....oooOO0OOooo........oooOO0OOooo........oo 80 81 G4int WLSSteppingAction::GetNumberOfBounces() 82 { 83 return fCounterBounce; 84 } 85 86 //....oooOO0OOooo........oooOO0OOooo........oo 87 88 G4int WLSSteppingAction::GetNumberOfClad1Bounc 89 { 90 return fCounterClad1Bounce; 91 } 92 93 //....oooOO0OOooo........oooOO0OOooo........oo 94 95 G4int WLSSteppingAction::GetNumberOfClad2Bounc 96 { 97 return fCounterClad2Bounce; 98 } 99 100 //....oooOO0OOooo........oooOO0OOooo........oo 101 102 G4int WLSSteppingAction::GetNumberOfWLSBounces 103 { 104 return fCounterWLSBounce; 105 } 106 107 //....oooOO0OOooo........oooOO0OOooo........oo 108 109 G4int WLSSteppingAction::ResetSuccessCounter() 110 { 111 G4int temp = fCounterEnd; 112 fCounterEnd = 0; 113 return temp; 114 } 115 116 //....oooOO0OOooo........oooOO0OOooo........oo 117 118 void WLSSteppingAction::UserSteppingAction(con 119 { 120 G4Track* theTrack = theStep->GetTrack(); 121 auto trackInformation = (WLSUserTrackInforma 122 123 G4StepPoint* thePrePoint = theStep->GetPreSt 124 G4StepPoint* thePostPoint = theStep->GetPost 125 126 G4VPhysicalVolume* thePrePV = thePrePoint->G 127 G4VPhysicalVolume* thePostPV = thePostPoint- 128 129 G4String thePrePVname = " "; 130 G4String thePostPVname = " "; 131 132 if (thePostPV) { 133 thePrePVname = thePrePV->GetName(); 134 thePostPVname = thePostPV->GetName(); 135 } 136 137 // Recording data for start 138 // static const G4ThreeVector ZHat = G4Three 139 if (theTrack->GetParentID() == 0) { 140 // This is a primary track 141 if (theTrack->GetCurrentStepNumber() == 1) 142 // G4double x = theTrack->GetVer 143 // G4double y = theTrack->GetVer 144 // G4double z = theTrack->GetVer 145 // G4double pz = theTrack->GetVer 146 // G4double fInitTheta = 147 // theTrack->Get 148 } 149 } 150 151 // Retrieve the status of the photon 152 G4OpBoundaryProcessStatus theStatus = Undefi 153 154 static G4ThreadLocal G4ProcessManager* OpMan 155 G4OpticalPhoton::OpticalPhoton()->GetProce 156 157 if (OpManager) { 158 G4int nproc = OpManager->GetPostStepProces 159 G4ProcessVector* fPostStepDoItVector = OpM 160 161 for (G4int i = 0; i < nproc; ++i) { 162 G4VProcess* fCurrentProcess = (*fPostSte 163 fOpProcess = dynamic_cast<G4OpBoundaryPr 164 if (fOpProcess) { 165 theStatus = fOpProcess->GetStatus(); 166 break; 167 } 168 } 169 } 170 171 // Find the skewness of the ray at first cha 172 if (fInitGamma == -1 173 && (theStatus == TotalInternalReflection 174 || theStatus == FresnelRefraction) 175 && trackInformation->IsStatus(InsideOfFi 176 { 177 G4double px = theTrack->GetVertexMomentumD 178 G4double py = theTrack->GetVertexMomentumD 179 G4double x = theTrack->GetPosition().x(); 180 G4double y = theTrack->GetPosition().y(); 181 182 fInitGamma = x * px + y * py; 183 184 fInitGamma = fInitGamma / std::sqrt(px * p 185 186 fInitGamma = std::acos(fInitGamma * rad); 187 188 if (fInitGamma / deg > 90.0) { 189 fInitGamma = 180 * deg - fInitGamma; 190 } 191 } 192 // Record Photons that missed the photon det 193 if (!thePostPV && trackInformation->IsStatus 194 // G4cout << "SteppingAction: status = Esc 195 fEventAction->AddEscaped(); 196 // UpdateHistogramSuccess(thePostPoint,the 197 ResetCounters(); 198 199 return; 200 } 201 202 // Assumed photons are originated at the fib 203 // the fiber is the first material the photo 204 switch (theStatus) { 205 // Exiting the fiber 206 case FresnelRefraction: 207 case SameMaterial: 208 fEventAction->AddExiting(); 209 210 if (thePostPVname == "WLSFiber" || thePo 211 if (trackInformation->IsStatus(Outside 212 trackInformation->AddStatusFlag(Insi 213 214 // Set the Exit flag when the photon r 215 } 216 else if (trackInformation->IsStatus(Insi 217 // EscapedFromReadOut if the z positio 218 if (theTrack->GetPosition().z() == fDe 219 trackInformation->AddStatusFlag(Esca 220 fCounterEnd++; 221 fEventAction->AddEscapedEnd(); 222 } 223 else // Escaped from side 224 { 225 trackInformation->AddStatusFlag(Esca 226 trackInformation->SetExitPosition(th 227 // UpdateHistogramEscape(thePostPoi 228 229 fCounterMid++; 230 fEventAction->AddEscapedMid(); 231 ResetCounters(); 232 } 233 234 trackInformation->AddStatusFlag(Outsid 235 trackInformation->SetExitPosition(theT 236 } 237 238 return; 239 240 // Internal Reflections 241 case TotalInternalReflection: 242 243 fEventAction->AddTIR(); 244 245 // Kill the track if it's number of boun 246 if (fBounceLimit > 0 && fCounterBounce > 247 theTrack->SetTrackStatus(fStopAndKill) 248 trackInformation->AddStatusFlag(murder 249 ResetCounters(); 250 G4cout << "\n Bounce Limit Exceeded" < 251 return; 252 } 253 break; 254 255 case FresnelReflection: 256 257 fCounterBounce++; 258 fEventAction->AddBounce(); 259 260 if (thePrePVname == "WLSFiber") { 261 fCounterWLSBounce++; 262 fEventAction->AddWLSBounce(); 263 } 264 else if (thePrePVname == "Clad1") { 265 fCounterClad1Bounce++; 266 fEventAction->AddClad1Bounce(); 267 } 268 else if (thePrePVname == "Clad2") { 269 fCounterClad2Bounce++; 270 fEventAction->AddClad1Bounce(); 271 } 272 273 // Determine if the photon has reflected 274 if (theTrack->GetPosition().z() == fDete 275 if (!trackInformation->IsStatus(Reflec 276 && trackInformation->IsStatus(Insi 277 { 278 trackInformation->AddStatusFlag(Refl 279 280 if (fDetector->IsPerfectFiber() && t 281 theTrack->SetTrackStatus(fStopAndK 282 trackInformation->AddStatusFlag(mu 283 // UpdateHistogramReflect(thePostP 284 ResetCounters(); 285 return; 286 } 287 } 288 } 289 return; 290 291 // Reflection off the mirror 292 case LambertianReflection: 293 case LobeReflection: 294 case SpikeReflection: 295 296 fEventAction->AddReflected(); 297 // Check if it hits the mirror 298 if (thePostPVname == "Mirror") { 299 trackInformation->AddStatusFlag(Reflec 300 fEventAction->AddMirror(); 301 } 302 return; 303 304 // Detected by a detector 305 case Detection: 306 // Detected automatically with G4OpBound 307 308 // Stop Tracking when it hits the detect 309 ResetCounters(); 310 theTrack->SetTrackStatus(fStopAndKill); 311 return; 312 313 default: 314 break; 315 } 316 317 // Check for absorbed photons 318 if (theTrack->GetTrackStatus() != fAlive && 319 // UpdateHistogramAbsorb(thePostPoint,theT 320 ResetCounters(); 321 return; 322 } 323 } 324