![]() |
Precalibrated Ion Beam Identification Detector Simulation 1.0
A pilot study detector simulation, written in C++ with Geant4.
|
00001 #include "SteppingAction.hh" 00002 00003 00004 SteppingAction::SteppingAction(DetectorConstruction* det, 00005 EventAction* evt) 00006 :detector(det), eventaction(evt) 00007 { 00008 00009 } 00010 00011 SteppingAction::~SteppingAction() 00012 { } 00013 00014 void SteppingAction::UserSteppingAction(const G4Step* aStep) 00015 { 00016 00017 G4cout.precision(15); //increase precision of cout. 00018 00019 // get volume of the current step 00020 G4VPhysicalVolume* volume 00021 = aStep->GetPreStepPoint()->GetTouchableHandle()->GetVolume(); 00022 00023 // collect energy and track length step by step 00024 //G4double edep = aStep->GetTotalEnergyDeposit(); 00025 G4double edep = aStep->GetTotalEnergyDeposit(); 00026 00027 // record the time 00028 G4double time = aStep->GetTrack()->GetGlobalTime(); 00029 00030 if (volume == detector->GetScintillator()) 00031 { 00032 //Determine the scintillator ID. 00033 G4int scintillatorID = aStep->GetPreStepPoint()->GetTouchable()->GetReplicaNumber(1); 00034 scintillatorID += (aStep->GetPreStepPoint()->GetTouchable()->GetReplicaNumber(2))*(detector->GetNumberOfScintillatorsPerBox()); 00035 if (aStep->GetPreStepPoint()->GetTouchable()->GetVolume(3) == detector->GetLowerBetaDetector()) 00036 scintillatorID += (detector->GetNumberOfScintillatorBoxes())*(detector->GetNumberOfScintillatorsPerBox()); 00037 00038 00039 eventaction->AddScintillatorTubeEvent(scintillatorID,time, edep); 00040 std::stringstream ss; 00041 ss.precision(15); 00042 ss << time/ns << " " << scintillatorID << " " << edep/MeV << " " << aStep->GetTrack()->GetDefinition()->GetParticleName().c_str() << " " << aStep->GetTrack()->GetTotalEnergy()/MeV << std::endl; 00043 eventaction->PrintToVerboseFile(ss.str()); 00044 } 00045 00046 if (volume == detector->GetGermaniumDetector()) 00047 { 00048 eventaction->AddGeDetectorEvent(time, edep); 00049 00050 00051 std::stringstream ss; 00052 ss.precision(15); 00053 ss << time/ns << " GermaniumDetector " << edep/MeV << " " << aStep->GetTrack()->GetDefinition()->GetParticleName().c_str() << " " << aStep->GetTrack()->GetTotalEnergy()/MeV << std::endl; 00054 eventaction->PrintToVerboseFile(ss.str()); 00055 } 00056 00057 if (volume == detector->GetLowerFrontScintillatorPlate()) 00058 { 00059 eventaction->AddScintillatorPlateEvent(AllAccumulatedStatistics::LowerFront,time/ns,edep); 00060 } 00061 00062 00063 if (volume == detector->GetUpperFrontScintillatorPlate()) 00064 { 00065 eventaction->AddScintillatorPlateEvent(AllAccumulatedStatistics::UpperFront,time, edep); 00066 } 00067 00068 if (volume == detector->GetBackScintillatorPlate()) 00069 { 00070 eventaction->AddScintillatorPlateEvent(AllAccumulatedStatistics::Back,time, edep); 00071 } 00072 00073 if (volume == detector->GetUpperFrontScintillatorPlate() || volume == detector->GetBackScintillatorPlate() || volume == detector->GetLowerFrontScintillatorPlate()) 00074 { 00075 if (edep/eV > 1) 00076 { 00077 00078 std::stringstream ss; 00079 ss.precision(15); 00080 ss << time/ns << " " << volume->GetName().c_str() << " " << edep/MeV << " " << aStep->GetTrack()->GetDefinition()->GetParticleName().c_str() << " " << aStep->GetTrack()->GetTotalEnergy()/MeV << std::endl; 00081 eventaction->PrintToVerboseFile(ss.str()); 00082 } 00083 } 00084 00085 //if (aStep->GetTrack()->GetDefinition()->GetParticleName().compare("gamma")==0) 00086 // fprintf(file, "GAMMA: Time: %.15f, Energy: %f, Region: %s \n", time, aStep->GetTrack()->GetTotalEnergy()/MeV, volume->GetName().c_str()); 00087 00088 // G4cout << "Time: " << aStep->GetTrack()->GetGlobalTime()/s << G4endl; 00089 00090 } 00091