[1199] | 1 | // |
---|
| 2 | // ******************************************************************** |
---|
| 3 | // * License and Disclaimer * |
---|
| 4 | // * * |
---|
| 5 | // * The Geant4 software is copyright of the Copyright Holders of * |
---|
| 6 | // * the Geant4 Collaboration. It is provided under the terms and * |
---|
| 7 | // * conditions of the Geant4 Software License, included in the file * |
---|
| 8 | // * LICENSE and available at http://cern.ch/geant4/license . These * |
---|
| 9 | // * include a list of copyright holders. * |
---|
| 10 | // * * |
---|
| 11 | // * Neither the authors of this software system, nor their employing * |
---|
| 12 | // * institutes,nor the agencies providing financial support for this * |
---|
| 13 | // * work make any representation or warranty, express or implied, * |
---|
| 14 | // * regarding this software system or assume any liability for its * |
---|
| 15 | // * use. Please see the license in the file LICENSE and URL above * |
---|
| 16 | // * for the full disclaimer and the limitation of liability. * |
---|
| 17 | // * * |
---|
| 18 | // * This code implementation is the result of the scientific and * |
---|
| 19 | // * technical work of the GEANT4 collaboration. * |
---|
| 20 | // * By using, copying, modifying or distributing the software (or * |
---|
| 21 | // * any work based on the software) you agree to acknowledge its * |
---|
| 22 | // * use in resulting scientific publications, and indicate your * |
---|
| 23 | // * acceptance of all terms of the Geant4 Software license. * |
---|
| 24 | // ******************************************************************** |
---|
| 25 | // |
---|
| 26 | // |
---|
| 27 | // $Id: G4PenelopeBremsstrahlungTest.cc,v 1.9 2006/06/29 19:44:16 gunter Exp $ |
---|
| 28 | // GEANT4 tag $Name: geant4-09-03-cand-01 $ |
---|
| 29 | // |
---|
| 30 | // ------------------------------------------------------------------- |
---|
| 31 | // GEANT 4 class file --- Copyright CERN 1998 |
---|
| 32 | // CERN Geneva Switzerland |
---|
| 33 | // |
---|
| 34 | // |
---|
| 35 | // File name: G4PenelopeBremsstrahlungTest.cc |
---|
| 36 | // |
---|
| 37 | // Author: Francesco Longo |
---|
| 38 | // |
---|
| 39 | // Creation date: 04 january 2001 |
---|
| 40 | // |
---|
| 41 | // Modifications: Luciano Pandola (27 november 2002) |
---|
| 42 | // Adapted in order to test G4PenelopeBremsstrahlung |
---|
| 43 | // Minor modification in n-tuple filling |
---|
| 44 | // Updated analysis to AIDA 3.0 |
---|
| 45 | // |
---|
| 46 | // ------------------------------------------------------------------- |
---|
| 47 | |
---|
| 48 | #include "globals.hh" |
---|
| 49 | #include "G4ios.hh" |
---|
| 50 | #include <fstream> |
---|
| 51 | #include <iomanip> |
---|
| 52 | |
---|
| 53 | #include "G4ParticleDefinition.hh" |
---|
| 54 | #include "G4ParticleTypes.hh" |
---|
| 55 | #include "G4ParticleTable.hh" |
---|
| 56 | #include "G4Material.hh" |
---|
| 57 | #include "G4MaterialTable.hh" |
---|
| 58 | #include "G4VContinuousDiscreteProcess.hh" |
---|
| 59 | #include "G4VProcess.hh" |
---|
| 60 | #include "G4ProcessManager.hh" |
---|
| 61 | #include "G4RunManager.hh" |
---|
| 62 | |
---|
| 63 | #include "G4PenelopeBremsstrahlung.hh" |
---|
| 64 | #include "G4LowEnergyBremsstrahlung.hh" |
---|
| 65 | #include "G4eBremsstrahlung.hh" |
---|
| 66 | |
---|
| 67 | #include "G4EnergyLossTables.hh" |
---|
| 68 | #include "G4VParticleChange.hh" |
---|
| 69 | #include "G4ParticleChange.hh" |
---|
| 70 | #include "G4DynamicParticle.hh" |
---|
| 71 | #include "G4ForceCondition.hh" |
---|
| 72 | |
---|
| 73 | #include "G4LowEnergyBremsstrahlung.hh" |
---|
| 74 | #include "G4LowEnergyIonisation.hh" |
---|
| 75 | #include "G4eIonisation.hh" |
---|
| 76 | #include "G4MultipleScattering.hh" |
---|
| 77 | #include "G4eIonisation.hh" |
---|
| 78 | #include "G4eBremsstrahlung.hh" |
---|
| 79 | #include "G4eplusAnnihilation.hh" |
---|
| 80 | |
---|
| 81 | //#include "G4ComptonScattering.hh" |
---|
| 82 | //#include "G4PhotoElectricEffect.hh" |
---|
| 83 | |
---|
| 84 | #include "G4Electron.hh" |
---|
| 85 | #include "G4Positron.hh" |
---|
| 86 | #include "G4Gamma.hh" |
---|
| 87 | |
---|
| 88 | #include "G4GRSVolume.hh" |
---|
| 89 | #include "G4Box.hh" |
---|
| 90 | #include "G4PVPlacement.hh" |
---|
| 91 | #include "G4Step.hh" |
---|
| 92 | #include "G4ProductionCutsTable.hh" |
---|
| 93 | #include "G4MaterialCutsCouple.hh" |
---|
| 94 | |
---|
| 95 | #include "G4UnitsTable.hh" |
---|
| 96 | #include "AIDA/IManagedObject.h" |
---|
| 97 | |
---|
| 98 | #include <memory> |
---|
| 99 | #include "AIDA/IAnalysisFactory.h" |
---|
| 100 | #include "AIDA/ITreeFactory.h" |
---|
| 101 | #include "AIDA/ITree.h" |
---|
| 102 | #include "AIDA/IHistogramFactory.h" |
---|
| 103 | #include "AIDA/IHistogram1D.h" |
---|
| 104 | #include "AIDA/IHistogram2D.h" |
---|
| 105 | #include "AIDA/IHistogram3D.h" |
---|
| 106 | #include "AIDA/ITupleFactory.h" |
---|
| 107 | #include "AIDA/ITuple.h" |
---|
| 108 | |
---|
| 109 | |
---|
| 110 | int main() |
---|
| 111 | { |
---|
| 112 | |
---|
| 113 | // Setup |
---|
| 114 | |
---|
| 115 | G4int nIterations = 100000; |
---|
| 116 | G4int materialId = 3; |
---|
| 117 | G4int test=0; |
---|
| 118 | G4int tPart=1; |
---|
| 119 | //G4cout.setf(std::ios::scientific,std::ios::floatfield ); |
---|
| 120 | |
---|
| 121 | // ------------------------------------------------------------------- |
---|
| 122 | |
---|
| 123 | // ---- HBOOK initialization |
---|
| 124 | |
---|
| 125 | std::auto_ptr< AIDA::IAnalysisFactory > af( AIDA_createAnalysisFactory() ); |
---|
| 126 | std::auto_ptr< AIDA::ITreeFactory > tf (af->createTreeFactory()); |
---|
| 127 | std::auto_ptr< AIDA::ITree > tree (tf->create("pen_br_test.hbook","hbook",false,true)); |
---|
| 128 | G4cout << "Tree store: " << tree->storeName() << G4endl; |
---|
| 129 | std::auto_ptr< AIDA::ITupleFactory > tpf (af->createTupleFactory(*tree)); |
---|
| 130 | std::auto_ptr< AIDA::IHistogramFactory > hf (af->createHistogramFactory(*tree)); |
---|
| 131 | |
---|
| 132 | // ---- primary ntuple ------ |
---|
| 133 | AIDA::ITuple* ntuple1 = tpf->create("1","Primary Ntuple","double eprimary,energyf,de,dedx,pxch,pych,pzch,pch,thetach"); |
---|
| 134 | |
---|
| 135 | // ---- secondary ntuple ------ |
---|
| 136 | AIDA::ITuple* ntuple2 = tpf->create("2","Secondary Ntuple","double eprimary,px_ga,py_ga,pz_ga,p_ga,e_ga,theta_ga"); |
---|
| 137 | |
---|
| 138 | // ---- table ntuple ------ |
---|
| 139 | AIDA::ITuple* ntuple3 = tpf->create("3","Mean Free Path Ntuple","double kinen,mfp"); |
---|
| 140 | |
---|
| 141 | //--------- Materials definition --------- |
---|
| 142 | |
---|
| 143 | G4Material* Si = new G4Material("Silicon", 14., 28.055*g/mole, 2.33*g/cm3); |
---|
| 144 | G4Material* Fe = new G4Material("Iron", 26., 55.85*g/mole, 7.87*g/cm3); |
---|
| 145 | G4Material* Cu = new G4Material("Copper", 29., 63.55*g/mole, 8.96*g/cm3); |
---|
| 146 | G4Material* W = new G4Material("Tungsten", 74., 183.85*g/mole, 19.30*g/cm3); |
---|
| 147 | G4Material* Pb = new G4Material("Lead", 82., 207.19*g/mole, 11.35*g/cm3); |
---|
| 148 | G4Material* U = new G4Material("Uranium", 92., 238.03*g/mole, 18.95*g/cm3); |
---|
| 149 | G4Material* Al = new G4Material("Aluminum",13.,26.98*g/mole,2.7*g/cm3); |
---|
| 150 | G4Material* Au = new G4Material("Gold" ,79.,196.97*g/mole,19.3*g/cm3); |
---|
| 151 | |
---|
| 152 | G4Element* H = new G4Element ("Hydrogen", "H", 1. , 1.01*g/mole); |
---|
| 153 | G4Element* O = new G4Element ("Oxygen" , "O", 8. , 16.00*g/mole); |
---|
| 154 | G4Element* C = new G4Element ("Carbon" , "C", 6. , 12.00*g/mole); |
---|
| 155 | G4Element* Cs = new G4Element ("Cesium" , "Cs", 55. , 132.905*g/mole); |
---|
| 156 | G4Element* I = new G4Element ("Iodine" , "I", 53. , 126.9044*g/mole); |
---|
| 157 | |
---|
| 158 | G4Material* maO = new G4Material("Oxygen", 8., 16.00*g/mole, 1.1*g/cm3); |
---|
| 159 | |
---|
| 160 | G4Material* water = new G4Material ("Water" , 1.*g/cm3, 2); |
---|
| 161 | water->AddElement(H,2); |
---|
| 162 | water->AddElement(O,1); |
---|
| 163 | |
---|
| 164 | G4Material* ethane = new G4Material ("Ethane" , 0.4241*g/cm3, 2); |
---|
| 165 | ethane->AddElement(H,6); |
---|
| 166 | ethane->AddElement(C,2); |
---|
| 167 | |
---|
| 168 | G4Material* csi = new G4Material ("CsI" , 4.53*g/cm3, 2); |
---|
| 169 | csi->AddElement(Cs,1); |
---|
| 170 | csi->AddElement(I,1); |
---|
| 171 | |
---|
| 172 | |
---|
| 173 | // Interactive set-up |
---|
| 174 | G4cout << "Electrons [1] or Positrons [2] ?" << G4endl; |
---|
| 175 | G4cin >> tPart; |
---|
| 176 | if ( !(tPart == 1 || tPart == 2)) G4Exception("Wrong input"); |
---|
| 177 | |
---|
| 178 | |
---|
| 179 | G4cout << "Test AlongStepDoIt [1] or PostStepDoIt [2] ?" << G4endl; |
---|
| 180 | G4cin >> test; |
---|
| 181 | if ( !(test == 1 || test == 2)) G4Exception("Wrong input"); |
---|
| 182 | |
---|
| 183 | |
---|
| 184 | |
---|
| 185 | G4cout << "How many interactions? " << G4endl; |
---|
| 186 | G4cin >> nIterations; |
---|
| 187 | |
---|
| 188 | if (nIterations <= 0) G4Exception("Wrong input"); |
---|
| 189 | |
---|
| 190 | G4double initEnergy = 1*MeV; |
---|
| 191 | G4double initX = 0.; |
---|
| 192 | G4double initY = 0.; |
---|
| 193 | G4double initZ = 1.; |
---|
| 194 | |
---|
| 195 | G4cout << "Enter the initial particle energy E (MeV)" << G4endl; |
---|
| 196 | G4cin >> initEnergy ; |
---|
| 197 | |
---|
| 198 | |
---|
| 199 | initEnergy = initEnergy*MeV; |
---|
| 200 | |
---|
| 201 | if (initEnergy <= 0.) G4Exception("Wrong input"); |
---|
| 202 | |
---|
| 203 | static const G4MaterialTable* theMaterialTable = G4Material::GetMaterialTable(); |
---|
| 204 | |
---|
| 205 | G4int nMaterials = G4Material::GetNumberOfMaterials(); |
---|
| 206 | |
---|
| 207 | G4cout << "Available materials are: " << G4endl; |
---|
| 208 | for (G4int mat = 0; mat < nMaterials; mat++) |
---|
| 209 | { |
---|
| 210 | G4cout << mat << ") " |
---|
| 211 | << (*theMaterialTable)[mat]->GetName() |
---|
| 212 | << G4endl; |
---|
| 213 | } |
---|
| 214 | |
---|
| 215 | G4cout << "Which material? " << G4endl; |
---|
| 216 | G4cin >> materialId; |
---|
| 217 | |
---|
| 218 | G4Material* material = (*theMaterialTable)[materialId] ; |
---|
| 219 | |
---|
| 220 | G4cout << "The selected material is: " |
---|
| 221 | << material->GetName() |
---|
| 222 | << G4endl; |
---|
| 223 | |
---|
| 224 | G4double dimX = 1*mm; |
---|
| 225 | G4double dimY = 1*mm; |
---|
| 226 | G4double dimZ = 1*mm; |
---|
| 227 | |
---|
| 228 | // Geometry |
---|
| 229 | |
---|
| 230 | G4Box* theFrame = new G4Box ("Frame",dimX, dimY, dimZ); |
---|
| 231 | |
---|
| 232 | G4LogicalVolume* logicalFrame = new G4LogicalVolume(theFrame, |
---|
| 233 | (*theMaterialTable)[materialId], |
---|
| 234 | "LFrame", 0, 0, 0); |
---|
| 235 | logicalFrame->SetMaterial(material); |
---|
| 236 | |
---|
| 237 | G4PVPlacement* physicalFrame = new G4PVPlacement(0,G4ThreeVector(), |
---|
| 238 | "PFrame",logicalFrame,0,false,0); |
---|
| 239 | G4RunManager* rm = new G4RunManager(); |
---|
| 240 | G4cout << "World is defined " << G4endl; |
---|
| 241 | rm->GeometryHasBeenModified(); |
---|
| 242 | rm->DefineWorldVolume(physicalFrame); |
---|
| 243 | // Particle definitions |
---|
| 244 | |
---|
| 245 | G4ParticleDefinition* gamma = G4Gamma::GammaDefinition(); |
---|
| 246 | G4ParticleDefinition* electron = G4Electron::ElectronDefinition(); |
---|
| 247 | G4ParticleDefinition* positron = G4Positron::PositronDefinition(); |
---|
| 248 | |
---|
| 249 | |
---|
| 250 | G4ParticleDefinition* realpt = G4Electron::ElectronDefinition(); |
---|
| 251 | |
---|
| 252 | if (tPart == 2) |
---|
| 253 | { |
---|
| 254 | realpt = G4Positron::PositronDefinition(); |
---|
| 255 | } |
---|
| 256 | |
---|
| 257 | G4ProductionCutsTable* cutsTable = G4ProductionCutsTable::GetProductionCutsTable(); |
---|
| 258 | G4ProductionCuts* cuts = cutsTable->GetDefaultProductionCuts(); |
---|
| 259 | G4double cutG=1*micrometer; |
---|
| 260 | G4double cutE=1*micrometer; |
---|
| 261 | cuts->SetProductionCut(cutG, 0); //gammas |
---|
| 262 | cuts->SetProductionCut(cutE, 1); //electrons |
---|
| 263 | cuts->SetProductionCut(cutE, 2); //positrons |
---|
| 264 | G4cout << "Cuts are defined " << G4endl; |
---|
| 265 | |
---|
| 266 | //G4Gamma::SetEnergyRange(2.5e-4*MeV,1e5*MeV); |
---|
| 267 | //G4Electron::SetEnergyRange(2.5e-4*MeV,1e5*MeV); |
---|
| 268 | //G4Positron::SetEnergyRange(2.5e-4*MeV,1e5*MeV); |
---|
| 269 | |
---|
| 270 | cutsTable->UpdateCoupleTable(); |
---|
| 271 | //cutsTable->DumpCouples(); |
---|
| 272 | const G4MaterialCutsCouple* theCouple = cutsTable->GetMaterialCutsCouple(material,cuts); |
---|
| 273 | |
---|
| 274 | // Processes |
---|
| 275 | |
---|
| 276 | |
---|
| 277 | G4int processType; |
---|
| 278 | G4cout << "Standard [1] or LowEnergy[2] or Penelope [3] Bremsstrahlung?" << G4endl; |
---|
| 279 | G4cin >> processType; |
---|
| 280 | if ( !(processType == 1 || processType == 2 || processType == 3)) |
---|
| 281 | { |
---|
| 282 | G4Exception("Wrong input"); |
---|
| 283 | } |
---|
| 284 | |
---|
| 285 | G4VContinuousDiscreteProcess* bremProcess; |
---|
| 286 | |
---|
| 287 | if (processType == 1) |
---|
| 288 | { |
---|
| 289 | bremProcess = new G4eBremsstrahlung(); |
---|
| 290 | G4cout << "The selected model is Standard" << G4endl; |
---|
| 291 | } |
---|
| 292 | else if (processType == 2) |
---|
| 293 | { |
---|
| 294 | bremProcess = new G4LowEnergyBremsstrahlung(); |
---|
| 295 | G4cout << "The selected model is Low Energy" << G4endl; |
---|
| 296 | } |
---|
| 297 | else if (processType == 3) |
---|
| 298 | { |
---|
| 299 | |
---|
| 300 | bremProcess = new G4PenelopeBremsstrahlung(); |
---|
| 301 | G4cout << "The selected model is Penelope" << G4endl; |
---|
| 302 | } |
---|
| 303 | |
---|
| 304 | //---------------- |
---|
| 305 | // process manager |
---|
| 306 | //---------------- |
---|
| 307 | |
---|
| 308 | // electron or positron |
---|
| 309 | |
---|
| 310 | |
---|
| 311 | G4ProcessManager* ProcessManager = new G4ProcessManager(realpt); |
---|
| 312 | realpt->SetProcessManager(ProcessManager); |
---|
| 313 | ProcessManager->AddProcess(bremProcess); |
---|
| 314 | G4ForceCondition* condition; |
---|
| 315 | |
---|
| 316 | |
---|
| 317 | //-------------- |
---|
| 318 | // set ordering |
---|
| 319 | //-------------- |
---|
| 320 | |
---|
| 321 | |
---|
| 322 | // eProcessManager-> |
---|
| 323 | // SetProcessOrdering(theeminusMultipleScattering, idxAlongStep,1); |
---|
| 324 | // eProcessManager-> |
---|
| 325 | // SetProcessOrdering(theeminusIonisation, idxAlongStep,2); |
---|
| 326 | |
---|
| 327 | // eProcessManager-> |
---|
| 328 | // SetProcessOrdering(theeminusMultipleScattering, idxPostStep,1); |
---|
| 329 | // eProcessManager-> |
---|
| 330 | // SetProcessOrdering(theeminusIonisation, idxPostStep,2); |
---|
| 331 | // eProcessManager-> |
---|
| 332 | // SetProcessOrdering(theeminusBremsstrahlung, idxPostStep,3); |
---|
| 333 | |
---|
| 334 | |
---|
| 335 | |
---|
| 336 | // pProcessManager->SetProcessOrderingToFirst(theeplusAnnihilation, idxAtRest); |
---|
| 337 | // pProcessManager-> |
---|
| 338 | // SetProcessOrdering(theeplusMultipleScattering, idxAlongStep,1); |
---|
| 339 | // pProcessManager-> |
---|
| 340 | // SetProcessOrdering(theeplusIonisation, idxAlongStep,2); |
---|
| 341 | |
---|
| 342 | // pProcessManager-> |
---|
| 343 | // SetProcessOrdering(theeplusMultipleScattering, idxPostStep,1); |
---|
| 344 | // pProcessManager-> |
---|
| 345 | // SetProcessOrdering(theeplusIonisation, idxPostStep,2); |
---|
| 346 | // pProcessManager-> |
---|
| 347 | // SetProcessOrdering(theeplusBremsstrahlung, idxPostStep,3); |
---|
| 348 | // pProcessManager-> |
---|
| 349 | // SetProcessOrdering(theeplusAnnihilation, idxPostStep,4); |
---|
| 350 | |
---|
| 351 | // G4LowEnergyIonisation IonisationProcess; |
---|
| 352 | // eProcessManager->AddProcess(&IonisationProcess); |
---|
| 353 | // eProcessManager->SetProcessOrdering(&IonisationProcess,idxAlongStep,1); |
---|
| 354 | // eProcessManager->SetProcessOrdering(&IonisationProcess,idxPostStep, 1); |
---|
| 355 | |
---|
| 356 | // G4LowEnergyBremsstrahlung BremstrahlungProcess; |
---|
| 357 | // eProcessManager->AddProcess(&BremstrahlungProcess); |
---|
| 358 | // eProcessManager->SetProcessOrdering(&BremstrahlungProcess,idxAlongStep,1); |
---|
| 359 | // eProcessManager->SetProcessOrdering(&BremstrahlungProcess,idxPostStep, 1); |
---|
| 360 | |
---|
| 361 | // G4eIonisation IonisationPlusProcess; |
---|
| 362 | // pPositronProcessManager->AddProcess(&IonisationPlusProcess); |
---|
| 363 | // pProcessManager-> |
---|
| 364 | // SetProcessOrdering(&IonisationPlusProcess,idxAlongStep,1); |
---|
| 365 | // pProcessManager->SetProcessOrdering(&IonisationPlusProcess,idxPostStep,1); |
---|
| 366 | |
---|
| 367 | |
---|
| 368 | |
---|
| 369 | // Create a DynamicParticle |
---|
| 370 | |
---|
| 371 | G4double eEnergy = initEnergy*MeV; |
---|
| 372 | G4ParticleMomentum eDirection(initX,initY,initZ); |
---|
| 373 | //eEnergy is the KINETIK energy |
---|
| 374 | G4DynamicParticle dynamicPrimary(realpt,eDirection,eEnergy); |
---|
| 375 | |
---|
| 376 | dynamicPrimary.DumpInfo(0); |
---|
| 377 | |
---|
| 378 | // Track |
---|
| 379 | |
---|
| 380 | G4ThreeVector aPosition(0.,0.,0.); |
---|
| 381 | G4double aTime = 0. ; |
---|
| 382 | |
---|
| 383 | G4Track* eTrack = new G4Track(&dynamicPrimary,aTime,aPosition); |
---|
| 384 | G4GRSVolume* touche = new G4GRSVolume(physicalFrame, NULL, aPosition); |
---|
| 385 | eTrack->SetTouchableHandle(touche); //verificare!!!!!!!!!!!! |
---|
| 386 | |
---|
| 387 | |
---|
| 388 | // Step |
---|
| 389 | |
---|
| 390 | G4Step* step = new G4Step(); |
---|
| 391 | step->SetTrack(eTrack); |
---|
| 392 | |
---|
| 393 | G4StepPoint* aPoint = new G4StepPoint(); |
---|
| 394 | aPoint->SetPosition(aPosition); |
---|
| 395 | aPoint->SetMaterial(material); |
---|
| 396 | aPoint->SetMaterialCutsCouple(theCouple); |
---|
| 397 | G4double safety = 10000.*cm; |
---|
| 398 | aPoint->SetSafety(safety); |
---|
| 399 | step->SetPreStepPoint(aPoint); |
---|
| 400 | |
---|
| 401 | // Check applicability |
---|
| 402 | |
---|
| 403 | if (! (bremProcess->IsApplicable(*realpt))) |
---|
| 404 | { |
---|
| 405 | G4Exception("Not Applicable"); |
---|
| 406 | } |
---|
| 407 | else |
---|
| 408 | { |
---|
| 409 | G4cout<< "applicability OK" << G4endl; |
---|
| 410 | } |
---|
| 411 | |
---|
| 412 | // Initialize the physics tables (in which material?) |
---|
| 413 | bremProcess->BuildPhysicsTable(*realpt); |
---|
| 414 | |
---|
| 415 | G4cout<< "table OK" << G4endl; |
---|
| 416 | |
---|
| 417 | // Test GetMeanFreePath() |
---|
| 418 | // E' protected! Il membro accessibile e' DumpMeanFreePath() |
---|
| 419 | |
---|
| 420 | G4Material* apttoMaterial ; |
---|
| 421 | G4String MaterialName ; |
---|
| 422 | |
---|
| 423 | G4double minArg = 100*eV,maxArg = 100*GeV, argStp; |
---|
| 424 | const G4int pntNum = 300; |
---|
| 425 | G4double Tkin[pntNum+1]; |
---|
| 426 | G4double meanFreePath=0. ; |
---|
| 427 | |
---|
| 428 | argStp = (std::log10(maxArg)-std::log10(minArg))/pntNum; |
---|
| 429 | |
---|
| 430 | for(G4int d = 0; d < pntNum+1; d++) |
---|
| 431 | { |
---|
| 432 | Tkin[d] = std::pow(10,(std::log10(minArg) + d*argStp)); |
---|
| 433 | } |
---|
| 434 | |
---|
| 435 | G4double sti = 1.*mm; |
---|
| 436 | step->SetStepLength(sti); |
---|
| 437 | |
---|
| 438 | // for ( G4int J = 0 ; J < nMaterials ; J++ ) |
---|
| 439 | // { |
---|
| 440 | apttoMaterial = (*theMaterialTable)[materialId] ; |
---|
| 441 | MaterialName = apttoMaterial->GetName() ; |
---|
| 442 | logicalFrame->SetMaterial(apttoMaterial); |
---|
| 443 | |
---|
| 444 | eTrack->SetStep(step); |
---|
| 445 | |
---|
| 446 | G4PenelopeBremsstrahlung* LowEProcess = |
---|
| 447 | (G4PenelopeBremsstrahlung*) bremProcess; |
---|
| 448 | G4LowEnergyBremsstrahlung* LowEProcess2 = |
---|
| 449 | (G4LowEnergyBremsstrahlung*) bremProcess; |
---|
| 450 | G4eBremsstrahlung* StdProcess = |
---|
| 451 | (G4eBremsstrahlung*) bremProcess; |
---|
| 452 | |
---|
| 453 | |
---|
| 454 | for (G4int i=0 ; i<pntNum; i++) |
---|
| 455 | { |
---|
| 456 | dynamicPrimary.SetKineticEnergy(Tkin[i]); |
---|
| 457 | if (processType == 3) |
---|
| 458 | { |
---|
| 459 | //meanFreePath=LowEProcess |
---|
| 460 | // ->DumpMeanFreePath(*eTrack, sti, condition); |
---|
| 461 | } |
---|
| 462 | else if (processType == 2) |
---|
| 463 | { |
---|
| 464 | //meanFreePath=electronLowEProcess2 |
---|
| 465 | // ->DumpMeanFreePath(*eTrack, sti, condition); |
---|
| 466 | |
---|
| 467 | } |
---|
| 468 | else if (processType == 1) |
---|
| 469 | { |
---|
| 470 | //meanFreePath=StdProcess |
---|
| 471 | // ->GetMeanFreePath(*eTrack, sti, condition); |
---|
| 472 | } |
---|
| 473 | |
---|
| 474 | ntuple3->fill(ntuple3->findColumn("kinen"),std::log10(Tkin[i])); |
---|
| 475 | ntuple3->fill(ntuple3->findColumn("mfp"),meanFreePath/cm); |
---|
| 476 | ntuple3->addRow(); |
---|
| 477 | |
---|
| 478 | |
---|
| 479 | //G4cout << Tkin[i]/MeV << " " << meanFreePath/cm << G4endl; |
---|
| 480 | |
---|
| 481 | } |
---|
| 482 | G4cout << "Mean Free Path OK" << G4endl; |
---|
| 483 | |
---|
| 484 | // --------- Test the DoIt |
---|
| 485 | |
---|
| 486 | G4cout << "DoIt in " << material->GetName() << G4endl; |
---|
| 487 | |
---|
| 488 | |
---|
| 489 | dynamicPrimary.SetKineticEnergy(eEnergy); |
---|
| 490 | G4int iter; |
---|
| 491 | for (iter=0; iter<nIterations; iter++) |
---|
| 492 | { |
---|
| 493 | |
---|
| 494 | step->SetStepLength(1*micrometer); |
---|
| 495 | |
---|
| 496 | G4cout << "Iteration = " << iter |
---|
| 497 | << " - Step Length = " |
---|
| 498 | << step->GetStepLength()/mm << " mm " |
---|
| 499 | << G4endl; |
---|
| 500 | |
---|
| 501 | |
---|
| 502 | eTrack->SetStep(step); |
---|
| 503 | |
---|
| 504 | |
---|
| 505 | // G4cout << "Iteration = " << iter |
---|
| 506 | // << " - Step Length = " |
---|
| 507 | // << step->GetStepLength()/mm << " mm " |
---|
| 508 | // << G4endl; |
---|
| 509 | |
---|
| 510 | //G4cout << eTrack->GetStep()->GetStepLength()/mm |
---|
| 511 | // << G4endl; |
---|
| 512 | |
---|
| 513 | //G4cout << "Prima" << G4endl; |
---|
| 514 | G4VParticleChange* dummy; |
---|
| 515 | if (test==1) dummy = bremProcess->AlongStepDoIt(*eTrack, *step); |
---|
| 516 | if (test==2) dummy = bremProcess->PostStepDoIt(*eTrack,*step); |
---|
| 517 | //G4cout << "Dopo" << G4endl; |
---|
| 518 | |
---|
| 519 | G4ParticleChange* particleChange = (G4ParticleChange*) dummy; |
---|
| 520 | |
---|
| 521 | // Primary physical quantities |
---|
| 522 | |
---|
| 523 | G4double energyChange = particleChange->GetEnergy(); |
---|
| 524 | G4double dedx = initEnergy - energyChange ; |
---|
| 525 | G4double dedxNow = dedx / (step->GetStepLength()); |
---|
| 526 | |
---|
| 527 | G4ThreeVector eChange = |
---|
| 528 | particleChange->CalcMomentum(energyChange, |
---|
| 529 | (*particleChange->GetMomentumDirection()), |
---|
| 530 | particleChange->GetMass()); |
---|
| 531 | |
---|
| 532 | G4double pxChange = eChange.x(); |
---|
| 533 | G4double pyChange = eChange.y(); |
---|
| 534 | G4double pzChange = eChange.z(); |
---|
| 535 | G4double pChange = |
---|
| 536 | std::sqrt(pxChange*pxChange + pyChange*pyChange + pzChange*pzChange); |
---|
| 537 | |
---|
| 538 | G4double xChange = particleChange->GetPosition()->x(); |
---|
| 539 | G4double yChange = particleChange->GetPosition()->y(); |
---|
| 540 | G4double zChange = particleChange->GetPosition()->z(); |
---|
| 541 | |
---|
| 542 | G4double thetaChange = particleChange->GetMomentumDirection()->theta(); |
---|
| 543 | thetaChange = thetaChange/deg; //conversion in degrees |
---|
| 544 | |
---|
| 545 | G4cout << "---- Primary after the step ---- " << G4endl; |
---|
| 546 | |
---|
| 547 | // G4cout << "Position (x,y,z) = " |
---|
| 548 | // << xChange << " " |
---|
| 549 | // << yChange << " " |
---|
| 550 | // << zChange << " " |
---|
| 551 | // << G4endl; |
---|
| 552 | |
---|
| 553 | G4cout << "---- Energy: " << energyChange/MeV << " MeV, " |
---|
| 554 | << "(px,py,pz): (" |
---|
| 555 | << pxChange/MeV << "," |
---|
| 556 | << pyChange/MeV << "," |
---|
| 557 | << pzChange/MeV << ") MeV" |
---|
| 558 | << G4endl; |
---|
| 559 | |
---|
| 560 | G4cout << "---- Energy loss (dE) = " << dedx/keV << " keV" << G4endl; |
---|
| 561 | // G4cout << "Stopping power (dE/dx)=" << dedxNow << G4endl; |
---|
| 562 | |
---|
| 563 | ntuple1->fill(ntuple1->findColumn("eprimary"),initEnergy/MeV); |
---|
| 564 | ntuple1->fill(ntuple1->findColumn("energyf"),energyChange/MeV); |
---|
| 565 | ntuple1->fill(ntuple1->findColumn("de"),dedx/MeV); |
---|
| 566 | ntuple1->fill(ntuple1->findColumn("dedx"),dedxNow/(MeV/cm)); |
---|
| 567 | ntuple1->fill(ntuple1->findColumn("pxch"),pxChange/MeV); |
---|
| 568 | ntuple1->fill(ntuple1->findColumn("pych"),pyChange/MeV); |
---|
| 569 | ntuple1->fill(ntuple1->findColumn("pzch"),pzChange/MeV); |
---|
| 570 | ntuple1->fill(ntuple1->findColumn("pch"),pChange/MeV); |
---|
| 571 | ntuple1->fill(ntuple1->findColumn("thetach"),thetaChange); |
---|
| 572 | ntuple1->addRow(); |
---|
| 573 | |
---|
| 574 | // Secondaries physical quantities |
---|
| 575 | |
---|
| 576 | // Secondaries |
---|
| 577 | G4cout << " secondaries " << |
---|
| 578 | particleChange->GetNumberOfSecondaries() << G4endl; |
---|
| 579 | G4double px_ga,py_ga,pz_ga,p_ga,e_ga,theta_ga,eKin_ga; |
---|
| 580 | |
---|
| 581 | for (G4int i = 0; i < (particleChange->GetNumberOfSecondaries()); i++) |
---|
| 582 | { |
---|
| 583 | // The following two items should be filled per event, not |
---|
| 584 | // per secondary; filled here just for convenience, to avoid |
---|
| 585 | // complicated logic to dump ntuple when there are no secondaries |
---|
| 586 | |
---|
| 587 | G4Track* finalParticle = particleChange->GetSecondary(i) ; |
---|
| 588 | |
---|
| 589 | G4double e = finalParticle->GetTotalEnergy(); |
---|
| 590 | G4double eKin = finalParticle->GetKineticEnergy(); |
---|
| 591 | G4double px = (finalParticle->GetMomentum()).x(); |
---|
| 592 | G4double py = (finalParticle->GetMomentum()).y(); |
---|
| 593 | G4double pz = (finalParticle->GetMomentum()).z(); |
---|
| 594 | G4double theta = (finalParticle->GetMomentum()).theta(); |
---|
| 595 | G4double p = std::sqrt(px*px+py*py+pz*pz); |
---|
| 596 | theta = theta/deg; //conversion in degrees |
---|
| 597 | if (e > initEnergy) |
---|
| 598 | { |
---|
| 599 | G4cout << "WARNING: eFinal > eInit " << G4endl; |
---|
| 600 | // << e |
---|
| 601 | // << " > " initEnergy |
---|
| 602 | |
---|
| 603 | } |
---|
| 604 | |
---|
| 605 | G4String particleName = |
---|
| 606 | finalParticle->GetDefinition()->GetParticleName(); |
---|
| 607 | G4cout << "==== Final " |
---|
| 608 | << particleName << " " |
---|
| 609 | << "energy: " << e/MeV << " MeV, " |
---|
| 610 | << "eKin: " << eKin/MeV << " MeV, " |
---|
| 611 | << "(px,py,pz): (" |
---|
| 612 | << px/MeV << "," |
---|
| 613 | << py/MeV << "," |
---|
| 614 | << pz/MeV << ") MeV " |
---|
| 615 | << G4endl; |
---|
| 616 | |
---|
| 617 | G4int partType; |
---|
| 618 | if (particleName == "e-") { |
---|
| 619 | partType = 1; |
---|
| 620 | } |
---|
| 621 | else if (particleName == "gamma") |
---|
| 622 | { |
---|
| 623 | partType = 2; |
---|
| 624 | px_ga=px; |
---|
| 625 | py_ga=py; |
---|
| 626 | pz_ga=pz; |
---|
| 627 | p_ga=p; |
---|
| 628 | e_ga=e; |
---|
| 629 | theta_ga=theta; |
---|
| 630 | } |
---|
| 631 | else if (particleName == "e+") partType = 3; |
---|
| 632 | |
---|
| 633 | |
---|
| 634 | delete particleChange->GetSecondary(i); |
---|
| 635 | } |
---|
| 636 | |
---|
| 637 | // Fill the secondaries ntuple |
---|
| 638 | |
---|
| 639 | // Normalize all to the energy of primary |
---|
| 640 | // for gammas initEnergy=initP |
---|
| 641 | ntuple2->fill(ntuple2->findColumn("eprimary"),initEnergy/MeV); |
---|
| 642 | ntuple2->fill(ntuple2->findColumn("px_ga"),px_ga/MeV); |
---|
| 643 | ntuple2->fill(ntuple2->findColumn("py_ga"),py_ga/MeV); |
---|
| 644 | ntuple2->fill(ntuple2->findColumn("pz_ga"),pz_ga/MeV); |
---|
| 645 | ntuple2->fill(ntuple2->findColumn("p_ga"),p_ga/MeV); |
---|
| 646 | ntuple2->fill(ntuple2->findColumn("e_ga"),e_ga/MeV); |
---|
| 647 | ntuple2->fill(ntuple2->findColumn("theta_ga"),theta_ga); |
---|
| 648 | ntuple2->addRow(); |
---|
| 649 | particleChange->Clear(); |
---|
| 650 | |
---|
| 651 | } |
---|
| 652 | |
---|
| 653 | |
---|
| 654 | G4cout << "Iteration number: " << iter << G4endl; |
---|
| 655 | |
---|
| 656 | G4cout << "Committing.............." << G4endl; |
---|
| 657 | tree->commit(); |
---|
| 658 | G4cout << "Closing the tree........" << G4endl; |
---|
| 659 | tree->close(); |
---|
| 660 | |
---|
| 661 | delete step; |
---|
| 662 | |
---|
| 663 | |
---|
| 664 | G4cout << "END OF THE MAIN PROGRAM" << G4endl; |
---|
| 665 | return 0; |
---|
| 666 | } |
---|
| 667 | |
---|
| 668 | |
---|
| 669 | |
---|
| 670 | |
---|
| 671 | |
---|
| 672 | |
---|
| 673 | |
---|
| 674 | |
---|
| 675 | |
---|
| 676 | |
---|
| 677 | |
---|
| 678 | |
---|
| 679 | |
---|
| 680 | |
---|
| 681 | |
---|
| 682 | |
---|
| 683 | |
---|