Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // Hadrontherapy advanced example for Geant4 << 26 // HadrontherapyProtonSteppingAction.cc; 27 // See more at: https://twiki.cern.ch/twiki/bi << 27 // See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy 28 28 29 #include "G4SteppingManager.hh" 29 #include "G4SteppingManager.hh" 30 #include "G4TrackVector.hh" 30 #include "G4TrackVector.hh" 31 #include "HadrontherapySteppingAction.hh" 31 #include "HadrontherapySteppingAction.hh" 32 #include "G4ios.hh" 32 #include "G4ios.hh" 33 #include "G4SteppingManager.hh" 33 #include "G4SteppingManager.hh" 34 #include "G4Track.hh" 34 #include "G4Track.hh" 35 #include "G4Step.hh" 35 #include "G4Step.hh" 36 #include "G4StepPoint.hh" 36 #include "G4StepPoint.hh" 37 #include "G4TrackStatus.hh" 37 #include "G4TrackStatus.hh" 38 #include "G4TrackVector.hh" 38 #include "G4TrackVector.hh" 39 #include "G4ParticleDefinition.hh" 39 #include "G4ParticleDefinition.hh" 40 #include "G4ParticleTypes.hh" 40 #include "G4ParticleTypes.hh" 41 #include "G4UserEventAction.hh" << 41 42 #include "G4TransportationManager.hh" << 42 #include "HadrontherapyAnalysisManager.hh" 43 #include "G4VSensitiveDetector.hh" << 43 44 #include "HadrontherapyRunAction.hh" 44 #include "HadrontherapyRunAction.hh" 45 #include "HadrontherapyMatrix.hh" << 46 #include "G4SystemOfUnits.hh" << 47 45 48 ////////////////////////////////////////////// 46 ///////////////////////////////////////////////////////////////////////////// 49 HadrontherapySteppingAction::HadrontherapyStep 47 HadrontherapySteppingAction::HadrontherapySteppingAction( HadrontherapyRunAction *run) 50 { 48 { 51 runAction = run; << 49 runAction = run; 52 } 50 } 53 51 54 ////////////////////////////////////////////// 52 ///////////////////////////////////////////////////////////////////////////// 55 HadrontherapySteppingAction::~HadrontherapySte 53 HadrontherapySteppingAction::~HadrontherapySteppingAction() 56 { 54 { 57 } 55 } 58 56 59 ////////////////////////////////////////////// 57 ///////////////////////////////////////////////////////////////////////////// 60 void HadrontherapySteppingAction::UserStepping 58 void HadrontherapySteppingAction::UserSteppingAction(const G4Step* aStep) 61 { << 59 { 62 << 60 if( aStep->GetTrack()->GetVolume()->GetName() == "NewDetectorPhys"){ 63 // The followings are calls to usefuls inf << 61 #ifdef ANALYSIS_USE 64 // Please, comment out them if want to use << 62 G4ParticleDefinition *def = aStep->GetTrack()->GetDefinition(); 65 << 63 G4double secondaryParticleKineticEnergy = aStep->GetTrack()->GetKineticEnergy(); 66 // G4Track* theTrack = aStep->GetTrack(); << 64 G4String particleType = def->GetParticleType(); // particle type = nucleus for d, t, He3, alpha, and heavier nuclei 67 << 65 G4String particleName = def->GetParticleName(); // e.g. for alpha: the name = "alpha" and type = "nucleus" 68 G4StepPoint* PreStep = aStep->GetPreStepPo << 66 if(particleType == "nucleus") { 69 G4StepPoint* PostStep = aStep->GetPostStep << 67 G4int A = def->GetBaryonNumber(); 70 << 68 G4double Z = def->GetPDGCharge(); 71 G4TouchableHandle touchPreStep = PreStep-> << 69 G4double posX = aStep->GetTrack()->GetPosition().x() / cm; 72 G4TouchableHandle touchPostStep = PostStep << 70 G4double posY = aStep->GetTrack()->GetPosition().y() / cm; 73 << 71 G4double posZ = aStep->GetTrack()->GetPosition().z() / cm; 74 //G4double PreStepX =PreStep->GetPosition( << 72 G4double energy = secondaryParticleKineticEnergy / A / MeV; 75 //G4double PreStepY =PreStep->GetPosition( << 73 76 //G4double PreStepZ =PreStep->GetPosition( << 74 HadrontherapyAnalysisManager* analysisMgr = HadrontherapyAnalysisManager::getInstance(); 77 << 75 analysisMgr->fillFragmentTuple(A, Z, energy, posX, posY, posZ); 78 //G4double PostStepX =PostStep->GetPositio << 76 } else if(particleName == "proton") { // proton (hydrogen-1) is a special case 79 //G4double PostStepY =PostStep->GetPositio << 77 G4double posX = aStep->GetTrack()->GetPosition().x() / cm ; 80 //G4double PostStepZ =PostStep->GetPositi << 78 G4double posY = aStep->GetTrack()->GetPosition().y() / cm ; 81 << 79 G4double posZ = aStep->GetTrack()->GetPosition().z() / cm ; 82 //To get the current volume: << 80 G4double energy = secondaryParticleKineticEnergy * MeV; // Hydrogen-1: A = 1, Z = 1 83 G4VPhysicalVolume* volumePre = touchPreSte << 81 HadrontherapyAnalysisManager::getInstance()->fillFragmentTuple(1, 1.0, energy, posX, posY, posZ); 84 //G4VPhysicalVolume* volumePost =touchPost << 82 } 85 << 83 86 //To get its name: << 84 G4String secondaryParticleName = def -> GetParticleName(); 87 G4String namePre = volumePre->GetName(); << 85 //G4cout <<"Particle: " << secondaryParticleName << G4endl; 88 << 86 //G4cout <<"Energy: " << secondaryParticleKineticEnergy << G4endl; 89 << 87 HadrontherapyAnalysisManager* analysis = HadrontherapyAnalysisManager::getInstance(); 90 // positions in the global coordinate syst << 88 //There is a bunch of stuff recorded with the energy 0, something should perhaps be done about this. 91 //G4ThreeVector posPreStep = PreStep->Get << 89 if(secondaryParticleName == "proton") { 92 //G4ThreeVector posPostStep = PostStep->Ge << 90 analysis->hydrogenEnergy(secondaryParticleKineticEnergy / MeV); 93 << 91 } 94 //G4int eventNum = G4RunManager::GetRunMan << 92 if(secondaryParticleName == "deuteron") { 95 << 93 analysis->hydrogenEnergy((secondaryParticleKineticEnergy/2) / MeV); 96 //G4double parentID =aStep->GetTrack()->Ge << 94 } 97 //G4double trackID =aStep->GetTrack()->Get << 95 if(secondaryParticleName == "triton") { 98 << 96 analysis->hydrogenEnergy((secondaryParticleKineticEnergy/3) / MeV); 99 G4double eKin = aStep -> GetPreStepPoint() << 97 } 100 << 98 if(secondaryParticleName == "alpha") { 101 G4double PosX = aStep->GetTrack()->GetPosi << 99 analysis->heliumEnergy((secondaryParticleKineticEnergy/4) / MeV); 102 G4double PosY = aStep->GetTrack()->GetPosi << 100 } 103 G4double PosZ = aStep->GetTrack()->GetPosi << 101 if(secondaryParticleName == "He3"){ 104 << 102 analysis->heliumEnergy((secondaryParticleKineticEnergy/3) / MeV); 105 G4String volume= aStep->GetTrack()->GetVo << 103 } 106 G4Track* theTrack = aStep->GetTrack(); << 104 #endif 107 << 105 108 //G4String material= aStep -> GetTrack() - << 106 aStep->GetTrack()->SetTrackStatus(fKillTrackAndSecondaries); 109 //G4cout << "material " << material << G << 110 //G4String volume= aStep->GetTrack()->Get << 111 //G4String pvname= pv-> GetName(); << 112 << 113 G4String particleName = aStep->GetTrack()- << 114 << 115 G4double momentumX = aStep->GetTrack()->G << 116 G4double momentumY = aStep->GetTrack()->G << 117 G4double momentumZ = aStep->GetTrack()->G << 118 << 119 << 120 G4ParticleDefinition *particleDef = theTra << 121 G4int pdg = particleDef ->GetPDGEncoding() << 122 << 123 if(namePre == "VirtualLayer") << 124 { << 125 std::ofstream WriteDataIn("Virtual_Lay << 126 WriteDataIn << 127 << 128 << eKin <<" " // 1 << 129 << PosX <<" " // 2 << 130 << PosY <<" " // 3 << 131 << PosZ <<" " // 4 << 132 << momentumX <<" " // 5 << 133 << momentumY <<" " // 6 << 134 << momentumZ <<" " // 7 << 135 << pdg << 136 //<< theTrack << '\t' << " << 137 << 138 << G4endl; << 139 << 140 theTrack -> SetTrackStatus(fKillTrackA << 141 << 142 << 143 } 107 } 144 << 108 145 << 109 // Electromagnetic and hadronic processes of primary particles in the phantom 146 << 110 //setting phantomPhys correctly will break something here fixme >> 111 if ((aStep -> GetTrack() -> GetTrackID() == 1) && >> 112 (aStep -> GetTrack() -> GetVolume() -> GetName() == "PhantomPhys") && >> 113 (aStep -> GetPostStepPoint() -> GetProcessDefinedStep() != NULL)) >> 114 { >> 115 G4String process = aStep -> GetPostStepPoint() -> >> 116 GetProcessDefinedStep() -> GetProcessName(); >> 117 >> 118 if ((process == "Transportation") || (process == "StepLimiter")) {;} >> 119 else { >> 120 if ((process == "msc") || (process == "hLowEIoni") || (process == "hIoni")) >> 121 { >> 122 runAction -> AddEMProcess(); >> 123 } >> 124 else >> 125 { >> 126 runAction -> AddHadronicProcess(); >> 127 >> 128 if ( (process != "LElastic") && (process != "ProtonInelastic") && (process != "hElastic") ) >> 129 G4cout << "Warning! Unknown proton process: "<< process << G4endl; >> 130 } >> 131 } >> 132 } >> 133 >> 134 // Retrieve information about the secondaries originated in the phantom >> 135 >> 136 G4SteppingManager* steppingManager = fpSteppingManager; 147 137 >> 138 // check if it is alive >> 139 //if(theTrack-> GetTrackStatus() == fAlive) { return; } >> 140 >> 141 // Retrieve the secondary particles >> 142 G4TrackVector* fSecondary = steppingManager -> GetfSecondary(); >> 143 >> 144 for(size_t lp1=0;lp1<(*fSecondary).size(); lp1++) >> 145 { >> 146 G4String volumeName = (*fSecondary)[lp1] -> GetVolume() -> GetName(); >> 147 >> 148 if (volumeName == "phantomPhys") >> 149 { >> 150 #ifdef ANALYSIS_USE >> 151 G4String secondaryParticleName = (*fSecondary)[lp1]->GetDefinition() -> GetParticleName(); >> 152 G4double secondaryParticleKineticEnergy = (*fSecondary)[lp1] -> GetKineticEnergy(); >> 153 >> 154 HadrontherapyAnalysisManager* analysis = HadrontherapyAnalysisManager::getInstance(); >> 155 >> 156 if (secondaryParticleName == "e-") >> 157 analysis -> electronEnergyDistribution(secondaryParticleKineticEnergy/MeV); >> 158 >> 159 if (secondaryParticleName == "gamma") >> 160 analysis -> gammaEnergyDistribution(secondaryParticleKineticEnergy/MeV); >> 161 >> 162 if (secondaryParticleName == "deuteron") >> 163 analysis -> deuteronEnergyDistribution(secondaryParticleKineticEnergy/MeV); >> 164 >> 165 if (secondaryParticleName == "triton") >> 166 analysis -> tritonEnergyDistribution(secondaryParticleKineticEnergy/MeV); >> 167 >> 168 if (secondaryParticleName == "alpha") >> 169 analysis -> alphaEnergyDistribution(secondaryParticleKineticEnergy/MeV); >> 170 >> 171 G4double z = (*fSecondary)[lp1]-> GetDynamicParticle() -> GetDefinition() -> GetPDGCharge(); >> 172 if (z > 0.) >> 173 { >> 174 G4int a = (*fSecondary)[lp1]-> GetDynamicParticle() -> GetDefinition() -> GetBaryonNumber(); >> 175 G4int electronOccupancy = (*fSecondary)[lp1] -> GetDynamicParticle() -> GetTotalOccupancy(); >> 176 >> 177 // If a generic ion is originated in the detector, its baryonic number, PDG charge, >> 178 // total number of electrons in the orbitals are stored in a ntuple >> 179 analysis -> genericIonInformation(a, z, electronOccupancy, secondaryParticleKineticEnergy/MeV); >> 180 } >> 181 #endif >> 182 } >> 183 } 148 } 184 } >> 185 >> 186 149 187 150 188 151 189 152 190