Changeset 1230 for trunk/examples/advanced/hadrontherapy/src
- Timestamp:
- Jan 8, 2010, 3:02:48 PM (14 years ago)
- Location:
- trunk/examples/advanced/hadrontherapy/src
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/examples/advanced/hadrontherapy/src/HadrontherapyAnalysisManager.cc
r807 r1230 24 24 // ******************************************************************** 25 25 // 26 // $Id: HadrontherapyAnalisysManager.cc; May 2005 27 // ---------------------------------------------------------------------------- 28 // GEANT 4 - Hadrontherapy example 29 // ---------------------------------------------------------------------------- 30 // Code developed by: 31 // 32 // G.A.P. Cirrone(a)*, F. Di Rosa(a), S. Guatelli(b), G. Russo(a) 33 // 34 // (a) Laboratori Nazionali del Sud 35 // of the INFN, Catania, Italy 36 // (b) INFN Section of Genova, Genova, Italy 37 // 38 // * cirrone@lns.infn.it 39 // ---------------------------------------------------------------------------- 40 41 #ifdef G4ANALYSIS_USE 26 // $Id: HadrontherapyAnalisysManager.cc; 27 // See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy 28 42 29 #include "HadrontherapyAnalysisManager.hh" 43 30 #include "HadrontherapyMatrix.hh" 31 #include "HadrontherapyAnalysisFileMessenger.hh" 32 #include <time.h> 33 #ifdef ANALYSIS_USE 44 34 HadrontherapyAnalysisManager* HadrontherapyAnalysisManager::instance = 0; 45 35 46 HadrontherapyAnalysisManager::HadrontherapyAnalysisManager() : 47 aFact(0), theTree(0), histFact(0), tupFact(0), h1(0), h2(0), h3(0), 48 h4(0), h5(0), h6(0), h7(0), h8(0), h9(0), h10(0), h11(0), h12(0), h13(0), h14(0), ntuple(0), 49 ionTuple(0) 50 { 51 } 52 53 HadrontherapyAnalysisManager::~HadrontherapyAnalysisManager() 54 { 36 #ifdef G4ANALYSIS_USE_ROOT 37 #undef G4ANALYSIS_USE 38 #endif 39 40 ///////////////////////////////////////////////////////////////////////////// 41 42 #ifdef G4ANALYSIS_USE 43 HadrontherapyAnalysisManager::HadrontherapyAnalysisManager() : 44 analysisFileName("DoseDistribution.root"), aFact(0), theTree(0), histFact(0), tupFact(0), h1(0), h2(0), h3(0), 45 h4(0), h5(0), h6(0), h7(0), h8(0), h9(0), h10(0), h11(0), h12(0), h13(0), h14(0), h15(0), h16(0), ntuple(0), 46 ionTuple(0), 47 fragmentTuple(0), 48 eventCounter(0) 49 { 50 fMess = new HadrontherapyAnalysisFileMessenger(this); 51 } 52 #endif 53 #ifdef G4ANALYSIS_USE_ROOT 54 HadrontherapyAnalysisManager::HadrontherapyAnalysisManager() : 55 analysisFileName("DoseDistribution.root"),theTFile(0), histo1(0), histo2(0), histo3(0), 56 histo4(0), histo5(0), histo6(0), histo7(0), histo8(0), histo9(0), histo10(0), histo11(0), histo12(0), histo13(0), histo14(0), histo15(0), histo16(0), 57 theROOTNtuple(0), 58 theROOTIonTuple(0), 59 fragmentNtuple(0), 60 metaData(0), 61 eventCounter(0) 62 { 63 fMess = new HadrontherapyAnalysisFileMessenger(this); 64 } 65 #endif 66 ///////////////////////////////////////////////////////////////////////////// 67 HadrontherapyAnalysisManager::~HadrontherapyAnalysisManager() 68 { 69 delete(fMess); //kill the messenger 70 #ifdef G4ANALYSIS_USE 71 delete fragmentTuple; 72 fragmentTuple = 0; 73 55 74 delete ionTuple; 56 75 ionTuple = 0; 57 76 58 77 delete ntuple; 59 78 ntuple = 0; 60 79 80 delete h16; 81 h16 = 0; 82 83 delete h15; 84 h15 = 0; 85 61 86 delete h14; 62 87 h14 = 0; … … 100 125 delete h1; 101 126 h1 = 0; 102 127 103 128 delete tupFact; 104 129 tupFact = 0; … … 112 137 delete aFact; 113 138 aFact = 0; 114 } 115 139 #endif 140 #ifdef G4ANALYSIS_USE_ROOT 141 delete metaData; 142 metaData = 0; 143 144 delete fragmentNtuple; 145 fragmentNtuple = 0; 146 147 delete theROOTIonTuple; 148 theROOTIonTuple = 0; 149 150 delete theROOTNtuple; 151 theROOTNtuple = 0; 152 153 delete histo16; 154 histo14 = 0; 155 156 delete histo15; 157 histo14 = 0; 158 159 delete histo14; 160 histo14 = 0; 161 162 delete histo13; 163 histo13 = 0; 164 165 delete histo12; 166 histo12 = 0; 167 168 delete histo11; 169 histo11 = 0; 170 171 delete histo10; 172 histo10 = 0; 173 174 delete histo9; 175 histo9 = 0; 176 177 delete histo8; 178 histo8 = 0; 179 180 delete histo7; 181 histo7 = 0; 182 183 delete histo6; 184 histo6 = 0; 185 186 delete histo5; 187 histo5 = 0; 188 189 delete histo4; 190 histo4 = 0; 191 192 delete histo3; 193 histo3 = 0; 194 195 delete histo2; 196 histo2 = 0; 197 198 delete histo1; 199 histo1 = 0; 200 #endif 201 } 202 ///////////////////////////////////////////////////////////////////////////// 116 203 HadrontherapyAnalysisManager* HadrontherapyAnalysisManager::getInstance() 117 204 { … … 120 207 } 121 208 122 void HadrontherapyAnalysisManager::book() 123 { 209 ///////////////////////////////////////////////////////////////////////////// 210 void HadrontherapyAnalysisManager::SetAnalysisFileName(G4String aFileName) 211 { 212 this->analysisFileName = aFileName; 213 } 214 215 ///////////////////////////////////////////////////////////////////////////// 216 void HadrontherapyAnalysisManager::book() 217 { 218 #ifdef G4ANALYSIS_USE 124 219 // Build up the analysis factory 125 220 aFact = AIDA_createAnalysisFactory(); 126 221 AIDA::ITreeFactory* treeFact = aFact -> createTreeFactory(); 127 222 128 // Create the .hbk file 129 G4String fileName = "hadrontherapy.hbk"; 223 // Create the .hbk or the .root file 224 G4String fileName = "DoseDistribution.hbk"; 225 226 std::string opts = "export=root"; 227 130 228 theTree = treeFact -> create(fileName,"hbook",false,true); 229 theTree = treeFact -> create(analysisFileName,"ROOT",false,true,opts); 230 231 // Factories are not "managed" by an AIDA analysis system. 232 // They must be deleted by the AIDA user code. 131 233 delete treeFact; 132 234 … … 136 238 137 239 // Create the histograms with the enrgy deposit along the X axis 138 h1 = histFact -> createHistogram1D("10","slice, energy", 200, 0., 200. );139 140 h2 = histFact -> createHistogram1D("20","Secondary protons - slice, energy", 200, 0., 200. );141 142 h3 = histFact -> createHistogram1D("30","Secondary neutrons - slice, energy", 200, 0., 200. );143 144 h4 = histFact -> createHistogram1D("40","Secondary alpha - slice, energy", 200, 0., 200. );145 146 h5 = histFact -> createHistogram1D("50","Secondary gamma - slice, energy", 200, 0., 200. );147 148 h6 = histFact -> createHistogram1D("60","Secondary electron - slice, energy", 200, 0., 200. );149 150 h7 = histFact -> createHistogram1D("70","Secondary triton - slice, energy", 200, 0., 200. );151 152 h8 = histFact -> createHistogram1D("80","Secondary deuteron - slice, energy", 200, 0., 200. );153 154 h9 = histFact -> createHistogram1D("90","Secondary pion - slice, energy", 200, 0., 200. );155 240 h1 = histFact -> createHistogram1D("10","slice, energy", 400, 0., 400. ); 241 242 h2 = histFact -> createHistogram1D("20","Secondary protons - slice, energy", 400, 0., 400. ); 243 244 h3 = histFact -> createHistogram1D("30","Secondary neutrons - slice, energy", 400, 0., 400. ); 245 246 h4 = histFact -> createHistogram1D("40","Secondary alpha - slice, energy", 400, 0., 400. ); 247 248 h5 = histFact -> createHistogram1D("50","Secondary gamma - slice, energy", 400, 0., 400. ); 249 250 h6 = histFact -> createHistogram1D("60","Secondary electron - slice, energy", 400, 0., 400. ); 251 252 h7 = histFact -> createHistogram1D("70","Secondary triton - slice, energy", 400, 0., 400. ); 253 254 h8 = histFact -> createHistogram1D("80","Secondary deuteron - slice, energy", 400, 0., 400. ); 255 256 h9 = histFact -> createHistogram1D("90","Secondary pion - slice, energy", 400, 0., 400. ); 257 156 258 h10 = histFact -> createHistogram1D("100","Energy distribution of secondary electrons", 70, 0., 70. ); 157 259 158 260 h11 = histFact -> createHistogram1D("110","Energy distribution of secondary photons", 70, 0., 70. ); 159 261 160 262 h12 = histFact -> createHistogram1D("120","Energy distribution of secondary deuterons", 70, 0., 70. ); 161 263 162 264 h13 = histFact -> createHistogram1D("130","Energy distribution of secondary tritons", 70, 0., 70. ); 163 265 164 266 h14 = histFact -> createHistogram1D("140","Energy distribution of secondary alpha particles", 70, 0., 70. ); 267 268 h15 = histFact -> createHistogram1D("150","Energy distribution of helium fragments after the phantom", 70, 0., 500.); 269 270 h16 = histFact -> createHistogram1D("160","Energy distribution of hydrogen fragments after the phantom", 70, 0., 500.); 165 271 166 272 // Create the ntuple … … 173 279 G4String options2 = ""; 174 280 if (tupFact) ionTuple = tupFact -> create("2","2", columnNames2, options2); 175 } 176 177 void HadrontherapyAnalysisManager::FillEnergyDeposit(G4int i, 178 G4int j, 281 282 // Create the fragment ntuple 283 G4String columnNames3 = "int a; double z; double energy; double posX; double posY; double posZ;"; 284 G4String options3 = ""; 285 if (tupFact) fragmentTuple = tupFact -> create("3","3", columnNames3, options3); 286 #endif 287 #ifdef G4ANALYSIS_USE_ROOT 288 // Use ROOT 289 theTFile = new TFile(analysisFileName, "RECREATE"); 290 291 // Create the histograms with the energy deposit along the X axis 292 histo1 = createHistogram1D("braggPeak","slice, energy", 400, 0., 27.9); //<different waterthicknesses are accoutned for in ROOT-analysis stage 293 histo2 = createHistogram1D("h20","Secondary protons - slice, energy", 400, 0., 400.); 294 histo3 = createHistogram1D("h30","Secondary neutrons - slice, energy", 400, 0., 400.); 295 histo4 = createHistogram1D("h40","Secondary alpha - slice, energy", 400, 0., 400.); 296 histo5 = createHistogram1D("h50","Secondary gamma - slice, energy", 400, 0., 400.); 297 histo6 = createHistogram1D("h60","Secondary electron - slice, energy", 400, 0., 400.); 298 histo7 = createHistogram1D("h70","Secondary triton - slice, energy", 400, 0., 400.); 299 histo8 = createHistogram1D("h80","Secondary deuteron - slice, energy", 400, 0., 400.); 300 histo9 = createHistogram1D("h90","Secondary pion - slice, energy", 400, 0., 400.); 301 histo10 = createHistogram1D("h100","Energy distribution of secondary electrons", 70, 0., 70.); 302 histo11 = createHistogram1D("h110","Energy distribution of secondary photons", 70, 0., 70.); 303 histo12 = createHistogram1D("h120","Energy distribution of secondary deuterons", 70, 0., 70.); 304 histo13 = createHistogram1D("h130","Energy distribution of secondary tritons", 70, 0., 70.); 305 histo14 = createHistogram1D("h140","Energy distribution of secondary alpha particles", 70, 0., 70.); 306 histo15 = createHistogram1D("heliumEnergyAfterPhantom","Energy distribution of secondary helium fragments after the phantom", 307 70, 0., 500.); 308 histo16 = createHistogram1D("hydrogenEnergyAfterPhantom","Energy distribution of secondary helium fragments after the phantom", 309 70, 0., 500.); 310 311 theROOTNtuple = new TNtuple("theROOTNtuple", "Energy deposit by slice", "i:j:k:energy"); 312 theROOTIonTuple = new TNtuple("theROOTIonTuple", "Generic ion information", "a:z:occupancy:energy"); 313 fragmentNtuple = new TNtuple("fragmentNtuple", "Fragments", "A:Z:energy:posX:posY:posZ"); 314 metaData = new TNtuple("metaData", "Metadata", "events:detectorDistance:waterThickness:beamEnergy:energyError:phantomCenterDistance"); 315 #endif 316 } 317 318 ///////////////////////////////////////////////////////////////////////////// 319 void HadrontherapyAnalysisManager::FillEnergyDeposit(G4int i, 320 G4int j, 179 321 G4int k, 180 322 G4double energy) 181 323 { 324 #ifdef G4ANALYSIS_USE 182 325 if (ntuple) { 183 326 G4int iSlice = ntuple -> findColumn("i"); … … 185 328 G4int kSlice = ntuple -> findColumn("k"); 186 329 G4int iEnergy = ntuple -> findColumn("energy"); 187 330 188 331 ntuple -> fill(iSlice,i); 189 ntuple -> fill(jSlice,j); 332 ntuple -> fill(jSlice,j); 190 333 ntuple -> fill(kSlice,k); 191 334 ntuple -> fill(iEnergy, energy); } 192 335 193 ntuple -> addRow(); 194 } 195 336 ntuple -> addRow(); 337 #endif 338 #ifdef G4ANALYSIS_USE_ROOT 339 if (theROOTNtuple) { 340 theROOTNtuple->Fill(i, j, k, energy); 341 } 342 #endif 343 } 344 345 ///////////////////////////////////////////////////////////////////////////// 196 346 void HadrontherapyAnalysisManager::BraggPeak(G4int slice, G4double energy) 197 347 { 348 #ifdef G4ANALYSIS_USE 198 349 h1 -> fill(slice,energy); 199 } 200 350 #endif 351 #ifdef G4ANALYSIS_USE_ROOT 352 histo1->SetBinContent(slice, energy); //This uses setbincontent instead of fill to get labels correct 353 #endif 354 } 355 356 ///////////////////////////////////////////////////////////////////////////// 201 357 void HadrontherapyAnalysisManager::SecondaryProtonEnergyDeposit(G4int slice, G4double energy) 202 358 { 359 #ifdef G4ANALYSIS_USE 203 360 h2 -> fill(slice,energy); 204 } 205 361 #endif 362 #ifdef G4ANALYSIS_USE_ROOT 363 histo2->Fill(slice, energy); 364 #endif 365 } 366 367 ///////////////////////////////////////////////////////////////////////////// 206 368 void HadrontherapyAnalysisManager::SecondaryNeutronEnergyDeposit(G4int slice, G4double energy) 207 369 { 370 #ifdef G4ANALYSIS_USE 208 371 h3 -> fill(slice,energy); 209 } 210 372 #endif 373 #ifdef G4ANALYSIS_USE_ROOT 374 histo3->Fill(slice, energy); 375 #endif 376 } 377 378 ///////////////////////////////////////////////////////////////////////////// 211 379 void HadrontherapyAnalysisManager::SecondaryAlphaEnergyDeposit(G4int slice, G4double energy) 212 380 { 381 #ifdef G4ANALYSIS_USE 213 382 h4 -> fill(slice,energy); 214 } 215 383 #endif 384 #ifdef G4ANALYSIS_USE_ROOT 385 histo4->Fill(slice, energy); 386 #endif 387 } 388 389 ///////////////////////////////////////////////////////////////////////////// 216 390 void HadrontherapyAnalysisManager::SecondaryGammaEnergyDeposit(G4int slice, G4double energy) 217 391 { 392 #ifdef G4ANALYSIS_USE 218 393 h5 -> fill(slice,energy); 219 } 220 394 #endif 395 #ifdef G4ANALYSIS_USE_ROOT 396 histo5->Fill(slice, energy); 397 #endif 398 } 399 400 ///////////////////////////////////////////////////////////////////////////// 221 401 void HadrontherapyAnalysisManager::SecondaryElectronEnergyDeposit(G4int slice, G4double energy) 222 402 { 403 #ifdef G4ANALYSIS_USE 223 404 h6 -> fill(slice,energy); 224 } 225 405 #endif 406 #ifdef G4ANALYSIS_USE_ROOT 407 histo6->Fill(slice, energy); 408 #endif 409 } 410 411 ///////////////////////////////////////////////////////////////////////////// 226 412 void HadrontherapyAnalysisManager::SecondaryTritonEnergyDeposit(G4int slice, G4double energy) 227 413 { 414 #ifdef G4ANALYSIS_USE 228 415 h7 -> fill(slice,energy); 229 } 230 416 #endif 417 #ifdef G4ANALYSIS_USE_ROOT 418 histo7->Fill(slice, energy); 419 #endif 420 } 421 422 ///////////////////////////////////////////////////////////////////////////// 231 423 void HadrontherapyAnalysisManager::SecondaryDeuteronEnergyDeposit(G4int slice, G4double energy) 232 424 { 425 #ifdef G4ANALYSIS_USE 233 426 h8 -> fill(slice,energy); 234 } 235 427 #endif 428 #ifdef G4ANALYSIS_USE_ROOT 429 histo8->Fill(slice, energy); 430 #endif 431 } 432 433 ///////////////////////////////////////////////////////////////////////////// 236 434 void HadrontherapyAnalysisManager::SecondaryPionEnergyDeposit(G4int slice, G4double energy) 237 435 { 436 #ifdef G4ANALYSIS_USE 238 437 h9 -> fill(slice,energy); 239 } 240 438 #endif 439 #ifdef G4ANALYSIS_USE_ROOT 440 histo9->Fill(slice, energy); 441 #endif 442 } 443 444 ///////////////////////////////////////////////////////////////////////////// 241 445 void HadrontherapyAnalysisManager::electronEnergyDistribution(G4double energy) 242 446 { 447 #ifdef G4ANALYSIS_USE 243 448 h10 -> fill(energy); 244 } 245 449 #endif 450 #ifdef G4ANALYSIS_USE_ROOT 451 histo10->Fill(energy); 452 #endif 453 } 454 455 ///////////////////////////////////////////////////////////////////////////// 246 456 void HadrontherapyAnalysisManager::gammaEnergyDistribution(G4double energy) 247 457 { 458 #ifdef G4ANALYSIS_USE 248 459 h11 -> fill(energy); 249 } 250 460 #endif 461 #ifdef G4ANALYSIS_USE_ROOT 462 histo11->Fill(energy); 463 #endif 464 } 465 466 ///////////////////////////////////////////////////////////////////////////// 251 467 void HadrontherapyAnalysisManager::deuteronEnergyDistribution(G4double energy) 252 468 { 469 #ifdef G4ANALYSIS_USE 253 470 h12 -> fill(energy); 254 } 255 471 #endif 472 #ifdef G4ANALYSIS_USE_ROOT 473 histo12->Fill(energy); 474 #endif 475 } 476 477 ///////////////////////////////////////////////////////////////////////////// 256 478 void HadrontherapyAnalysisManager::tritonEnergyDistribution(G4double energy) 257 479 { 480 #ifdef G4ANALYSIS_USE 258 481 h13 -> fill(energy); 259 } 260 482 #endif 483 #ifdef G4ANALYSIS_USE_ROOT 484 histo13->Fill(energy); 485 #endif 486 } 487 488 ///////////////////////////////////////////////////////////////////////////// 261 489 void HadrontherapyAnalysisManager::alphaEnergyDistribution(G4double energy) 262 490 { 491 #ifdef G4ANALYSIS_USE 263 492 h14 -> fill(energy); 264 } 265 266 void HadrontherapyAnalysisManager::genericIonInformation(G4int a, 267 G4double z, 493 #endif 494 #ifdef G4ANALYSIS_USE_ROOT 495 histo14->Fill(energy); 496 #endif 497 } 498 ///////////////////////////////////////////////////////////////////////////// 499 void HadrontherapyAnalysisManager::heliumEnergy(G4double secondaryParticleKineticEnergy) 500 { 501 #ifdef G4ANALYSIS_USE 502 h15->fill(secondaryParticleKineticEnergy); 503 #endif 504 #ifdef G4ANALYSIS_USE_ROOT 505 histo15->Fill(secondaryParticleKineticEnergy); 506 #endif 507 } 508 509 ///////////////////////////////////////////////////////////////////////////// 510 void HadrontherapyAnalysisManager::hydrogenEnergy(G4double secondaryParticleKineticEnergy) 511 { 512 #ifdef G4ANALYSIS_USE 513 h16->fill(secondaryParticleKineticEnergy); 514 #endif 515 #ifdef G4ANALYSIS_USE_ROOT 516 histo16->Fill(secondaryParticleKineticEnergy); 517 #endif 518 } 519 520 521 522 void HadrontherapyAnalysisManager::fillFragmentTuple(G4int A, G4double Z, G4double energy, G4double posX, G4double posY, G4double posZ) 523 { 524 #ifdef G4ANALYSIS_USE 525 if (fragmentTuple) { 526 G4int aIndex = fragmentTuple -> findColumn("a"); 527 G4int zIndex = fragmentTuple -> findColumn("z"); 528 G4int energyIndex = fragmentTuple -> findColumn("energy"); 529 G4int posXIndex = fragmentTuple -> findColumn("posX"); 530 G4int posYIndex = fragmentTuple -> findColumn("posY"); 531 G4int posZIndex = fragmentTuple -> findColumn("posZ"); 532 533 fragmentTuple -> fill(aIndex,A); 534 fragmentTuple -> fill(zIndex,Z); 535 fragmentTuple -> fill(energyIndex, energy); 536 fragmentTuple -> fill(posXIndex, posX); 537 fragmentTuple -> fill(posYIndex, posY); 538 fragmentTuple -> fill(posZIndex, posZ); 539 fragmentTuple -> addRow(); 540 } 541 #endif 542 #ifdef G4ANALYSIS_USE_ROOT 543 //G4cout <<" A = " << A << " Z = " << Z << " energy = " << energy << G4endl; 544 fragmentNtuple->Fill(A, Z, energy, posX, posY, posZ); 545 #endif 546 } 547 548 ///////////////////////////////////////////////////////////////////////////// 549 void HadrontherapyAnalysisManager::genericIonInformation(G4int a, 550 G4double z, 268 551 G4int electronOccupancy, 269 G4double energy) 270 { 552 G4double energy) 553 { 554 #ifdef G4ANALYSIS_USE 271 555 if (ionTuple) { 272 556 G4int aIndex = ionTuple -> findColumn("a"); 273 557 G4int zIndex = ionTuple -> findColumn("z"); 274 G4int electronIndex = ionTuple -> findColumn("occupancy"); 558 G4int electronIndex = ionTuple -> findColumn("occupancy"); 275 559 G4int energyIndex = ionTuple -> findColumn("energy"); 276 560 277 561 ionTuple -> fill(aIndex,a); 278 ionTuple -> fill(zIndex,z); 279 ionTuple -> fill(electronIndex, electronOccupancy); 562 ionTuple -> fill(zIndex,z); 563 ionTuple -> fill(electronIndex, electronOccupancy); 280 564 ionTuple -> fill(energyIndex, energy); 281 565 } 282 ionTuple -> addRow(); 283 } 284 285 void HadrontherapyAnalysisManager::finish() 286 { 566 ionTuple -> addRow(); 567 #endif 568 #ifdef G4ANALYSIS_USE_ROOT 569 if (theROOTIonTuple) { 570 theROOTIonTuple->Fill(a, z, electronOccupancy, energy); 571 } 572 #endif 573 } 574 575 ///////////////////////////////////////////////////////////////////////////// 576 void HadrontherapyAnalysisManager::startNewEvent() 577 { 578 eventCounter++; 579 } 580 ///////////////////////////////////////////////////////////////////////////// 581 void HadrontherapyAnalysisManager::setGeometryMetaData(G4double endDetectorPosition, G4double waterThickness, G4double phantomCenter) 582 { 583 this->detectorDistance = endDetectorPosition; 584 this->phantomDepth = waterThickness; 585 this->phantomCenterDistance = phantomCenter; 586 } 587 void HadrontherapyAnalysisManager::setBeamMetaData(G4double meanKineticEnergy,G4double sigmaEnergy) 588 { 589 this->beamEnergy = meanKineticEnergy; 590 this->energyError = sigmaEnergy; 591 } 592 ///////////////////////////////////////////////////////////////////////////// 593 void HadrontherapyAnalysisManager::flush() 594 { 595 HadrontherapyMatrix* matrix = HadrontherapyMatrix::getInstance(); 596 597 matrix->TotalEnergyDeposit(); 598 #ifdef G4ANALYSIS_USE 599 theTree -> commit(); 600 theTree ->close(); 601 #endif 602 #ifdef G4ANALYSIS_USE_ROOT 603 metaData->Fill((Float_t) eventCounter,(Float_t) detectorDistance, (Float_t) phantomDepth, (Float_t) beamEnergy,(Float_t) energyError, (Float_t) phantomCenterDistance); 604 metaData->Write(); 605 theROOTNtuple->Write(); 606 theROOTIonTuple->Write(); 607 fragmentNtuple->Write(); 608 theTFile->Write(); 609 // theTFile->Clear(); 610 theTFile->Close(); 611 #endif 612 eventCounter = 0; 613 matrix->flush(); 614 } 615 ///////////////////////////////////////////////////////////////////////////// 616 void HadrontherapyAnalysisManager::finish() 617 { 618 #ifdef G4ANALYSIS_USE 287 619 // Write all histograms to file 288 620 theTree -> commit(); 289 290 621 // Close (will again commit) 291 622 theTree ->close(); 292 } 293 #endif 294 295 296 297 298 299 300 301 302 303 304 623 #endif 624 #ifdef G4ANALYSIS_USE_ROOT 625 metaData->Fill((Float_t) eventCounter,(Float_t) detectorDistance, (Float_t) phantomDepth, (Float_t) beamEnergy,(Float_t) energyError, (Float_t) phantomCenterDistance); 626 metaData->Write(); 627 theROOTNtuple->Write(); 628 theROOTIonTuple->Write(); 629 fragmentNtuple->Write(); 630 theTFile->Write(); 631 theTFile->Close(); 632 #endif 633 eventCounter = 0; 634 } 635 636 #endif 637 638 639 640 641 642 643 644 645 -
trunk/examples/advanced/hadrontherapy/src/HadrontherapyDetectorConstruction.cc
r807 r1230 24 24 // ******************************************************************** 25 25 // 26 // $Id: HadrontherapyDetectorConstruction.cc; Version 4.0 May 2005 27 // ---------------------------------------------------------------------------- 28 // GEANT 4 - Hadrontherapy example 29 // ---------------------------------------------------------------------------- 30 // Code developed by: 26 // HadrontherapyDetectorConstruction.cc 31 27 // 32 // G.A.P. Cirrone(a)*, F. Di Rosa(a), S. Guatelli(b), G. Russo(a) 33 // 34 // (a) Laboratori Nazionali del Sud 35 // of the INFN, Catania, Italy 36 // (b) INFN Section of Genova, Genova, Italy 37 // 38 // * cirrone@lns.infn.it 39 // ---------------------------------------------------------------------------- 28 // See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy 40 29 41 30 #include "G4SDManager.hh" … … 50 39 #include "G4Colour.hh" 51 40 #include "G4UserLimits.hh" 41 #include "G4UnitsTable.hh" 52 42 #include "G4VisAttributes.hh" 53 #include "HadrontherapyPhantomROGeometry.hh" 43 #include "G4NistManager.hh" 44 #include "HadrontherapyDetectorROGeometry.hh" 54 45 #include "HadrontherapyDetectorMessenger.hh" 55 #include "Hadrontherapy PhantomSD.hh"46 #include "HadrontherapyDetectorSD.hh" 56 47 #include "HadrontherapyDetectorConstruction.hh" 57 #include "HadrontherapyMaterial.hh" 58 #include "HadrontherapyBeamLine.hh" 59 #include "HadrontherapyModulator.hh" 60 61 HadrontherapyDetectorConstruction::HadrontherapyDetectorConstruction() 62 : phantomSD(0), phantomROGeometry(0), beamLine(0), modulator(0), 63 physicalTreatmentRoom(0), 64 patientPhysicalVolume(0), 65 phantomLogicalVolume(0), 66 phantomPhysicalVolume(0) 67 { 68 // Messenger to change parameters of the geometry 48 #include "HadrontherapyMatrix.hh" 49 50 ///////////////////////////////////////////////////////////////////////////// 51 HadrontherapyDetectorConstruction::HadrontherapyDetectorConstruction(G4VPhysicalVolume* physicalTreatmentRoom) 52 : motherPhys(physicalTreatmentRoom), 53 detectorSD(0), detectorROGeometry(0), matrix(0), 54 phantomPhysicalVolume(0), 55 detectorLogicalVolume(0), detectorPhysicalVolume(0), 56 phantomSizeX(20.*cm), phantomSizeY(20.*cm), phantomSizeZ(20.*cm), // Default half dimensions 57 detectorSizeX(2.*cm), detectorSizeY(2.*cm), detectorSizeZ(2.*cm), 58 phantomPosition(20.*cm, 0.*cm, 0.*cm), 59 detectorToPhantomPosition(0.*cm,18.*cm,18.*cm)// Default displacement of the detector respect to the phantom 60 { 61 // NOTE! that the HadrontherapyDetectorConstruction class 62 // does NOT inherit from G4VUserDetectorConstruction G4 class 63 // So the Construct() mandatory virtual method is inside another geometric class 64 // (like the passiveProtonBeamLIne, ...) 65 66 // Messenger to change parameters of the phantom/detector geometry 69 67 detectorMessenger = new HadrontherapyDetectorMessenger(this); 70 68 71 material = new HadrontherapyMaterial(); 72 73 // Phantom sizes 74 phantomSizeX = 20.*mm; 75 phantomSizeY = 20.*mm; 76 phantomSizeZ = 20.*mm; 77 78 // Number of the phantom voxels 79 numberOfVoxelsAlongX = 200; 80 numberOfVoxelsAlongY = 200; 81 numberOfVoxelsAlongZ = 200; 82 } 83 69 // Default detector voxels size 70 // 200 slabs along the beam direction (X) 71 sizeOfVoxelAlongX = 200 *um; 72 sizeOfVoxelAlongY = 2 * detectorSizeY; 73 sizeOfVoxelAlongZ = 2 * detectorSizeZ; 74 75 // Calculate (and eventually set) detector position by displacement, phantom size and detector size 76 SetDetectorPosition(); 77 78 // Build phantom and associated detector 79 ConstructPhantom(); 80 ConstructDetector(); 81 // Set number of the detector voxels along X Y and Z directions. 82 // This will construct also the sensitive detector, the ROGeometry 83 // and the matrix where the energy deposited is collected! 84 SetNumberOfVoxelBySize(sizeOfVoxelAlongX, sizeOfVoxelAlongY, sizeOfVoxelAlongZ); 85 } 86 87 ///////////////////////////////////////////////////////////////////////////// 84 88 HadrontherapyDetectorConstruction::~HadrontherapyDetectorConstruction() 85 89 { 86 delete material; 87 if (phantomROGeometry) delete phantomROGeometry; 88 delete detectorMessenger; 89 } 90 91 G4VPhysicalVolume* HadrontherapyDetectorConstruction::Construct() 90 delete detectorROGeometry;// This should be safe in C++ even if the argument is a NULL pointer 91 delete matrix; 92 delete detectorMessenger; 93 } 94 95 void HadrontherapyDetectorConstruction::ConstructPhantom() 96 { 97 //---------------------------------------- 98 // Phantom: 99 // A box used to approximate tissues 100 //---------------------------------------- 101 102 G4bool isotopes = false; 103 G4Material* waterNist = G4NistManager::Instance()->FindOrBuildMaterial("G4_WATER", isotopes); 104 phantom = new G4Box("Phantom",phantomSizeX, phantomSizeY, phantomSizeZ); 105 phantomLogicalVolume = new G4LogicalVolume(phantom, 106 waterNist, 107 "phantomLog", 0, 0, 0); 108 109 phantomPhysicalVolume = new G4PVPlacement(0, 110 phantomPosition, 111 "phantomPhys", 112 phantomLogicalVolume, 113 motherPhys, 114 false, 115 0); 116 117 // Visualisation attributes of the phantom 118 red = new G4VisAttributes(G4Colour(255/255., 0/255. ,0/255.)); 119 red -> SetVisibility(true); 120 red -> SetForceSolid(true); 121 //red -> SetForceWireframe(true); 122 phantomLogicalVolume -> SetVisAttributes(red); 123 } 124 125 ///////////////////////////////////////////////////////////////////////////// 126 void HadrontherapyDetectorConstruction::ConstructDetector() 127 { 128 //----------- 129 // Detector 130 //----------- 131 G4bool isotopes = false; 132 G4Material* waterNist = G4NistManager::Instance()->FindOrBuildMaterial("G4_WATER", isotopes); 133 detector = new G4Box("Detector",detectorSizeX,detectorSizeY,detectorSizeZ); 134 detectorLogicalVolume = new G4LogicalVolume(detector, 135 waterNist, 136 "DetectorLog", 137 0,0,0); 138 // Detector is attached by default to the phantom face directly exposed to the beam 139 detectorPhysicalVolume = new G4PVPlacement(0, 140 detectorPosition, // Setted by displacement 141 "DetectorPhys", 142 detectorLogicalVolume, 143 phantomPhysicalVolume, 144 false,0); 145 146 // Visualisation attributes of the detector 147 skyBlue = new G4VisAttributes( G4Colour(135/255. , 206/255. , 235/255. )); 148 skyBlue -> SetVisibility(true); 149 skyBlue -> SetForceSolid(true); 150 //skyBlue -> SetForceWireframe(true); 151 detectorLogicalVolume -> SetVisAttributes(skyBlue); 152 153 } 154 ///////////////////////////////////////////////////////////////////////////// 155 void HadrontherapyDetectorConstruction::ConstructSensitiveDetector(G4ThreeVector detectorToWorldPosition) 92 156 { 93 // Define the materials of the experimental set-up 94 material -> DefineMaterials(); 95 96 // Define the geometry components 97 ConstructBeamLine(); 98 ConstructPhantom(); 99 100 // Set the sensitive detector where the energy deposit is collected 101 ConstructSensitiveDetector(); 157 // Install new Sensitive Detector and ROGeometry 158 delete detectorROGeometry; // this should be safe in C++ also if we have a NULL pointer 159 160 // Sensitive Detector and ReadOut geometry definition 161 G4SDManager* sensitiveDetectorManager = G4SDManager::GetSDMpointer(); 162 163 G4String sensitiveDetectorName = "Detector"; 164 if (!detectorSD) 165 { 166 // The sensitive detector is instantiated 167 detectorSD = new HadrontherapyDetectorSD(sensitiveDetectorName); 168 } 169 // The Read Out Geometry is instantiated 170 G4String ROGeometryName = "DetectorROGeometry"; 171 detectorROGeometry = new HadrontherapyDetectorROGeometry(ROGeometryName, 172 detectorToWorldPosition, 173 detectorSizeX, 174 detectorSizeY, 175 detectorSizeZ, 176 numberOfVoxelsAlongX, 177 numberOfVoxelsAlongY, 178 numberOfVoxelsAlongZ); 179 180 G4cout << "Instantiating new Read Out Geometry \"" << ROGeometryName << "\""<< G4endl; 181 // This will invoke Build() HadrontherapyDetectorROGeometry virtual method 182 detectorROGeometry -> BuildROGeometry(); 183 // Attach ROGeometry to SDetector 184 detectorSD -> SetROgeometry(detectorROGeometry); 185 //sensitiveDetectorManager -> Activate(sensitiveDetectorName, true); 186 if (!sensitiveDetectorManager -> FindSensitiveDetector(sensitiveDetectorName, false)) 187 { 188 G4cout << "Registering new DetectorSD \"" << sensitiveDetectorName << "\""<< G4endl; 189 // Register user SD 190 sensitiveDetectorManager -> AddNewDetector(detectorSD); 191 // Attach SD to detector logical volume 192 detectorLogicalVolume -> SetSensitiveDetector(detectorSD); 193 } 194 } 195 196 ///////////////// 197 // MESSENGERS // 198 //////////////// 199 G4bool HadrontherapyDetectorConstruction::SetNumberOfVoxelBySize(G4double sizeX, G4double sizeY, G4double sizeZ) 200 { 201 // Only change positive dimensions 202 // XXX numberOfVoxels must be an integer, warn the user 203 204 if (sizeX > 0) 205 { 206 if (sizeX > 2*detectorSizeX) 207 { 208 G4cout << "WARNING: Voxel X size must be smaller or equal than that of detector X" << G4endl; 209 return false; 210 } 211 // Round to the nearest integer 212 numberOfVoxelsAlongX = lrint(2 * detectorSizeX / sizeX); 213 sizeOfVoxelAlongX = (2 * detectorSizeX / numberOfVoxelsAlongX ); 214 if(sizeOfVoxelAlongX!=sizeX) G4cout << "Rounding " << 215 G4BestUnit(sizeX, "Length") << " to " << 216 G4BestUnit(sizeOfVoxelAlongX, "Length") << G4endl; 217 } 218 219 if (sizeY > 0) 220 { 221 if (sizeY > 2*detectorSizeY) 222 { 223 G4cout << "WARNING: Voxel Y size must be smaller or equal than that of detector Y" << G4endl; 224 return false; 225 } 226 numberOfVoxelsAlongY = lrint(2 * detectorSizeY / sizeY); 227 sizeOfVoxelAlongY = (2 * detectorSizeY / numberOfVoxelsAlongY ); 228 if(sizeOfVoxelAlongY!=sizeY) G4cout << "Rounding " << 229 G4BestUnit(sizeY, "Length") << " to " << 230 G4BestUnit(sizeOfVoxelAlongY, "Length") << G4endl; 231 } 232 if (sizeZ > 0) 233 { 234 if (sizeZ > 2*detectorSizeZ) 235 { 236 G4cout << "WARNING: Voxel Z size must be smaller or equal than that of detector Z" << G4endl; 237 return false; 238 } 239 numberOfVoxelsAlongZ = lrint(2 * detectorSizeZ / sizeZ); 240 sizeOfVoxelAlongZ = (2 * detectorSizeZ / numberOfVoxelsAlongZ ); 241 if(sizeOfVoxelAlongZ!=sizeZ) G4cout << "Rounding " << 242 G4BestUnit(sizeZ, "Length") << " to " << 243 G4BestUnit(sizeOfVoxelAlongZ, "Length") << G4endl; 244 } 245 246 G4cout << "The (X, Y, Z) sizes of the Voxels are: (" << 247 G4BestUnit(sizeOfVoxelAlongX, "Length") << ", " << 248 G4BestUnit(sizeOfVoxelAlongY, "Length") << ", " << 249 G4BestUnit(sizeOfVoxelAlongZ, "Length") << ')' << G4endl; 250 251 G4cout << "The number of Voxels along (X,Y,Z) is: (" << 252 numberOfVoxelsAlongX << ", " << 253 numberOfVoxelsAlongY << ", " << 254 numberOfVoxelsAlongZ << ')' << G4endl; 255 256 // This will clear the existing matrix (together with data inside it)! 257 matrix = HadrontherapyMatrix::getInstance(numberOfVoxelsAlongX, 258 numberOfVoxelsAlongY, 259 numberOfVoxelsAlongZ); 260 261 // Here construct the Sensitive Detector and Read Out Geometry 262 ConstructSensitiveDetector(GetDetectorToWorldPosition()); 263 G4RunManager::GetRunManager() -> GeometryHasBeenModified(); 264 return true; 265 } 266 ///////////////////////////////////////////////////////////////////////////// 267 G4bool HadrontherapyDetectorConstruction::SetDetectorSize(G4double sizeX, G4double sizeY, G4double sizeZ) 268 { 269 // Check that the detector stay inside the phantom 270 if (sizeX > 0 && sizeX < sizeOfVoxelAlongX) {G4cout << "WARNING: Detector X size must be bigger than that of Voxel X" << G4endl; return false;} 271 if (sizeY > 0 && sizeY < sizeOfVoxelAlongY) {G4cout << "WARNING: Detector Y size must be bigger than that of Voxel Y" << G4endl; return false;} 272 if (sizeZ > 0 && sizeZ < sizeOfVoxelAlongZ) {G4cout << "WARNING: Detector Z size must be bigger than that of Voxel Z" << G4endl; return false;} 273 274 if (!IsInside(sizeX/2, 275 sizeY/2, 276 sizeZ/2, 277 phantomSizeX, 278 phantomSizeY, 279 phantomSizeZ, 280 detectorToPhantomPosition)) 281 {return false;} 282 // Negative or null values mean don't change it! 283 if (sizeX > 0) { 284 detectorSizeX = sizeX/2; 285 detector -> SetXHalfLength(detectorSizeX); 286 } 287 288 if (sizeY > 0) { 289 detectorSizeY = sizeY/2; 290 detector -> SetYHalfLength(detectorSizeY); 291 } 292 293 if (sizeZ > 0) { 294 detectorSizeZ = sizeZ/2; 295 detector -> SetZHalfLength(detectorSizeZ); 296 } 297 298 299 G4cout << "The (X, Y, Z) dimensions of the detector are : (" << 300 G4BestUnit( detector -> GetXHalfLength()*2., "Length") << ", " << 301 G4BestUnit( detector -> GetYHalfLength()*2., "Length") << ", " << 302 G4BestUnit( detector -> GetZHalfLength()*2., "Length") << ')' << G4endl; 303 // Adjust detector position 304 SetDetectorPosition(); 305 // Adjust voxels number accordingly to new detector geometry 306 // Matrix will be re-instantiated! 307 // Voxels and ROGeometry must follow the detector! 308 SetNumberOfVoxelBySize(sizeOfVoxelAlongX, sizeOfVoxelAlongY, sizeOfVoxelAlongZ); 309 G4RunManager::GetRunManager() -> GeometryHasBeenModified(); 310 return true; 311 } 312 313 ///////////////////////////////////////////////////////////////////////////// 314 G4bool HadrontherapyDetectorConstruction::SetPhantomSize(G4double sizeX, G4double sizeY, G4double sizeZ) 315 { 316 317 if (!IsInside(detectorSizeX, 318 detectorSizeY, 319 detectorSizeZ, 320 sizeX/2,//method parameters 321 sizeY/2, 322 sizeZ/2, 323 detectorToPhantomPosition 324 )) 325 return false; 326 327 // Only change positive dimensions 328 if (sizeX > 0) { 329 phantomSizeX = sizeX/2; 330 phantom -> SetXHalfLength(phantomSizeX); 331 } 332 if (sizeY > 0) { 333 phantomSizeY = sizeY/2; 334 phantom -> SetYHalfLength(phantomSizeY); 335 } 336 337 if (sizeZ > 0) { 338 phantomSizeZ = sizeZ/2; 339 phantom -> SetZHalfLength(phantomSizeZ); 340 } 102 341 103 return physicalTreatmentRoom; 104 } 105 106 void HadrontherapyDetectorConstruction::ConstructBeamLine() 107 { 108 G4Material* air = material -> GetMat("Air") ; 109 G4Material* water = material -> GetMat("Water"); 110 111 // --------------------- 112 // Treatment room - World volume 113 //--------------------- 114 115 // Treatment room sizes 116 const G4double worldX = 400.0 *cm; 117 const G4double worldY = 400.0 *cm; 118 const G4double worldZ = 400.0 *cm; 119 120 G4Box* treatmentRoom = new G4Box("TreatmentRoom",worldX,worldY,worldZ); 121 122 G4LogicalVolume* logicTreatmentRoom = new G4LogicalVolume(treatmentRoom, 123 air, 124 "logicTreatmentRoom", 125 0,0,0); 126 127 128 129 physicalTreatmentRoom = new G4PVPlacement(0, 130 G4ThreeVector(), 131 "physicalTreatmentRoom", 132 logicTreatmentRoom, 133 0,false,0); 134 135 G4double maxStepTreatmentRoom = 0.1 *mm; 136 logicTreatmentRoom -> SetUserLimits(new G4UserLimits(maxStepTreatmentRoom)); 137 138 // The treatment room is invisible in the Visualisation 139 logicTreatmentRoom -> SetVisAttributes (G4VisAttributes::Invisible); 140 141 beamLine = new HadrontherapyBeamLine(physicalTreatmentRoom); 142 beamLine -> HadrontherapyBeamLineSupport(); 143 beamLine -> HadrontherapyBeamScatteringFoils(); 144 beamLine -> HadrontherapyBeamCollimators(); 145 beamLine -> HadrontherapyBeamMonitoring(); 146 beamLine -> HadrontherapyBeamNozzle(); 147 beamLine -> HadrontherapyBeamFinalCollimator(); 148 149 modulator = new HadrontherapyModulator(); 150 modulator -> BuildModulator(physicalTreatmentRoom); 151 152 // Patient - Mother volume of the phantom 153 G4Box* patient = new G4Box("patient",20 *cm, 20 *cm, 20 *cm); 154 155 G4LogicalVolume* patientLogicalVolume = new G4LogicalVolume(patient, 156 water, 157 "patientLog", 0, 0, 0); 158 159 patientPhysicalVolume = new G4PVPlacement(0,G4ThreeVector(0., 0., 0.), 160 "patientPhys", 161 patientLogicalVolume, 162 physicalTreatmentRoom, 163 false,0); 164 165 // Visualisation attributes of the patient 166 G4VisAttributes * redWire = new G4VisAttributes(G4Colour(1. ,0. ,0.)); 167 redWire -> SetVisibility(true); 168 redWire -> SetForceWireframe(true); 169 patientLogicalVolume -> SetVisAttributes(redWire); 170 } 171 172 void HadrontherapyDetectorConstruction::ConstructPhantom() 173 { 174 G4Colour lightBlue (0.0, 0.0, .75); 175 176 G4Material* water = material -> GetMat("Water"); 177 178 //ComputeVoxelSize(); 179 180 //---------------------- 181 // Water phantom 182 //---------------------- 183 G4Box* phantom = new G4Box("Phantom",phantomSizeX,phantomSizeY,phantomSizeZ); 184 185 phantomLogicalVolume = new G4LogicalVolume(phantom, 186 water, 187 "PhantomLog", 188 0,0,0); 189 190 // Fixing the max step allowed in the phantom 191 G4double maxStep = 0.01 *mm; 192 phantomLogicalVolume -> SetUserLimits(new G4UserLimits(maxStep)); 193 194 G4double phantomXtranslation = -180.*mm; 195 phantomPhysicalVolume = new G4PVPlacement(0, 196 G4ThreeVector(phantomXtranslation, 0.0 *mm, 0.0 *mm), 197 "PhantomPhys", 198 phantomLogicalVolume, 199 patientPhysicalVolume, 200 false,0); 201 202 // Visualisation attributes of the phantom 203 G4VisAttributes* simpleBoxVisAttributes = new G4VisAttributes(lightBlue); 204 simpleBoxVisAttributes -> SetVisibility(true); 205 simpleBoxVisAttributes -> SetForceSolid(true); 206 phantomLogicalVolume -> SetVisAttributes(simpleBoxVisAttributes); 207 208 // ************** 209 // Cut per Region 210 // ************** 211 212 // A smaller cut is fixed in the phantom to calculate the energy deposit with the 213 // required accuracy 214 G4Region* aRegion = new G4Region("PhantomLog"); 215 phantomLogicalVolume -> SetRegion(aRegion); 216 aRegion -> AddRootLogicalVolume(phantomLogicalVolume); 217 } 218 219 void HadrontherapyDetectorConstruction::ConstructSensitiveDetector() 220 { 221 // Sensitive Detector and ReadOut geometry definition 222 G4SDManager* sensitiveDetectorManager = G4SDManager::GetSDMpointer(); 223 224 G4String sensitiveDetectorName = "Phantom"; 225 226 if(!phantomSD) 227 { 228 // The sensitive detector is instantiated 229 phantomSD = new HadrontherapyPhantomSD(sensitiveDetectorName); 230 231 // The Read Out Geometry is instantiated 232 G4String ROGeometryName = "PhantomROGeometry"; 233 phantomROGeometry = new HadrontherapyPhantomROGeometry(ROGeometryName, 234 phantomSizeX, 235 phantomSizeY, 236 phantomSizeZ, 237 numberOfVoxelsAlongX, 238 numberOfVoxelsAlongY, 239 numberOfVoxelsAlongZ); 240 phantomROGeometry -> BuildROGeometry(); 241 phantomSD -> SetROgeometry(phantomROGeometry); 242 sensitiveDetectorManager -> AddNewDetector(phantomSD); 243 phantomLogicalVolume -> SetSensitiveDetector(phantomSD); 244 } 245 } 246 247 void HadrontherapyDetectorConstruction::SetModulatorAngle(G4double value) 248 { 249 modulator -> SetModulatorAngle(value); 250 G4RunManager::GetRunManager() -> GeometryHasBeenModified(); 251 } 252 253 void HadrontherapyDetectorConstruction::SetRangeShifterXPosition(G4double value) 254 { 255 beamLine -> SetRangeShifterXPosition(value); 256 G4RunManager::GetRunManager() -> GeometryHasBeenModified(); 257 } 258 259 void HadrontherapyDetectorConstruction::SetRangeShifterXSize(G4double value) 260 { 261 beamLine -> SetRangeShifterXSize(value); 262 G4RunManager::GetRunManager() -> GeometryHasBeenModified(); 263 } 264 265 void HadrontherapyDetectorConstruction::SetFirstScatteringFoilSize(G4double value) 266 { 267 beamLine -> SetFirstScatteringFoilXSize(value); 268 G4RunManager::GetRunManager() -> GeometryHasBeenModified(); 269 } 270 271 void HadrontherapyDetectorConstruction::SetSecondScatteringFoilSize(G4double value) 272 { 273 beamLine -> SetSecondScatteringFoilXSize(value); 274 G4RunManager::GetRunManager() -> GeometryHasBeenModified(); 275 } 276 277 void HadrontherapyDetectorConstruction::SetOuterRadiusStopper(G4double value) 278 { 279 beamLine -> SetOuterRadiusStopper(value); 280 G4RunManager::GetRunManager() -> GeometryHasBeenModified(); 281 } 282 283 void HadrontherapyDetectorConstruction::SetInnerRadiusFinalCollimator(G4double value) 284 { 285 beamLine -> SetInnerRadiusFinalCollimator(value); 286 G4RunManager::GetRunManager() -> GeometryHasBeenModified(); 287 } 288 289 void HadrontherapyDetectorConstruction::SetRSMaterial(G4String materialChoice) 290 { 291 beamLine -> SetRSMaterial(materialChoice); 292 } 293 294 295 342 343 G4cout << "The (X, Y, Z) dimensions of the phantom are : (" << 344 G4BestUnit( phantom -> GetXHalfLength()*2., "Length") << ", " << 345 G4BestUnit( phantom -> GetYHalfLength()*2., "Length") << ", " << 346 G4BestUnit( phantom -> GetZHalfLength()*2., "Length") << ')' << G4endl; 347 //G4cout << '\n' << "Coordinate volume: " << phantomPhysicalVolume -> GetTranslation() << G4endl; 348 // Adjust detector position inside phantom 349 SetDetectorPosition(); 350 351 ConstructSensitiveDetector(GetDetectorToWorldPosition()); 352 G4RunManager::GetRunManager() -> GeometryHasBeenModified(); 353 return true; 354 } 355 ///////////////////////////////////////////////////////////////////////////// 356 G4bool HadrontherapyDetectorConstruction::SetPhantomPosition(G4ThreeVector displacement) 357 { 358 // Set Phantom position respect to the World 359 // TODO check for overlap! 360 phantomPosition = displacement; 361 if (phantomPhysicalVolume) 362 { 363 phantomPhysicalVolume -> SetTranslation(phantomPosition); 364 G4cout << "Displacement between Phantom and World is: "; 365 G4cout << "DX= "<< G4BestUnit(phantomPosition.getX(),"Length") << ", " << 366 "DY= "<< G4BestUnit(phantomPosition.getY(),"Length") << ", " << 367 "DZ= "<< G4BestUnit(phantomPosition.getZ(),"Length") << G4endl; 368 369 // Redraw ROGeometry! 370 ConstructSensitiveDetector(GetDetectorToWorldPosition()); 371 G4RunManager::GetRunManager() -> GeometryHasBeenModified(); 372 } 373 return true; 374 } 375 376 ///////////////////////////////////////////////////////////////////////////// 377 G4bool HadrontherapyDetectorConstruction::SetDetectorToPhantomPosition(G4ThreeVector displacement) 378 { 379 // Ignore negative values 380 if (displacement[0] < 0.) displacement[0] = detectorToPhantomPosition[0]; 381 if (displacement[1] < 0.) displacement[1] = detectorToPhantomPosition[1]; 382 if (displacement[2] < 0.) displacement[2] = detectorToPhantomPosition[2]; 383 384 if (!IsInside(detectorSizeX, 385 detectorSizeY, 386 detectorSizeZ, 387 phantomSizeX, 388 phantomSizeY, 389 phantomSizeZ, 390 displacement // method parameter! 391 )) 392 {return false;} 393 detectorToPhantomPosition = displacement; 394 395 // Adjust detector position inside phantom 396 SetDetectorPosition(); 397 398 ConstructSensitiveDetector(GetDetectorToWorldPosition()); 399 G4RunManager::GetRunManager() -> GeometryHasBeenModified(); 400 return true; 401 } -
trunk/examples/advanced/hadrontherapy/src/HadrontherapyDetectorMessenger.cc
r807 r1230 24 24 // ******************************************************************** 25 25 // 26 // $Id: HadrontherapyDetectorMessenger.cc; May 2005 27 // ---------------------------------------------------------------------------- 28 // GEANT 4 - Hadrontherapy example 29 // ---------------------------------------------------------------------------- 30 // Code developed by: 31 // 32 // G.A.P. Cirrone(a)*, F. Di Rosa(a), S. Guatelli(b), G. Russo(a) 33 // 34 // (a) Laboratori Nazionali del Sud 35 // of the INFN, Catania, Italy 36 // (b) INFN Section of Genova, Genova, Italy 37 // 38 // * cirrone@lns.infn.it 39 // ---------------------------------------------------------------------------- 26 // $Id: HadrontherapyDetectorMessenger.cc; 27 // See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy 28 29 40 30 #include "HadrontherapyDetectorMessenger.hh" 41 31 #include "HadrontherapyDetectorConstruction.hh" … … 43 33 #include "G4UIcmdWithADoubleAndUnit.hh" 44 34 #include "G4UIcmdWithAString.hh" 35 #include "G4UIcmdWith3VectorAndUnit.hh" 45 36 46 HadrontherapyDetectorMessenger::HadrontherapyDetectorMessenger( 47 37 ///////////////////////////////////////////////////////////////////////////// 38 HadrontherapyDetectorMessenger::HadrontherapyDetectorMessenger(HadrontherapyDetectorConstruction* detector) 48 39 :hadrontherapyDetector(detector) 49 { 50 modulatorDir = new G4UIdirectory("/modulator/"); 51 modulatorDir -> SetGuidance("Command to rotate the modulator wheel"); 52 53 beamLineDir = new G4UIdirectory("/beamLine/"); 54 beamLineDir -> SetGuidance("set specification of range shifter"); 40 { 41 // Change Phantom size 42 changeThePhantomDir = new G4UIdirectory("/changePhantom/"); 43 changeThePhantomDir -> SetGuidance("Command to change the Phantom Size/position"); 44 changeThePhantomSizeCmd = new G4UIcmdWith3VectorAndUnit("/changePhantom/size", this); 45 changeThePhantomSizeCmd -> SetGuidance("Insert sizes X Y and Z" 46 "\n 0 or negative values mean <<Don't change it!>>"); 47 changeThePhantomSizeCmd -> SetParameterName("PhantomSizeAlongX", 48 "PhantomSizeAlongY", 49 "PhantomSizeAlongZ", false); 50 changeThePhantomSizeCmd -> SetDefaultUnit("mm"); 51 changeThePhantomSizeCmd -> SetUnitCandidates("um mm cm"); 52 changeThePhantomSizeCmd -> AvailableForStates(G4State_Idle); 55 53 56 rangeShifterDir = new G4UIdirectory("/beamLine/RangeShifter/");57 rangeShifterDir -> SetGuidance("set specification of range shifter");58 54 59 firstScatteringFoilDir = new G4UIdirectory("/beamLine/ScatteringFoil1/"); 60 firstScatteringFoilDir -> SetGuidance("set specification of first scattering foil"); 61 62 secondScatteringFoilDir = new G4UIdirectory("/beamLine/ScatteringFoil2/"); 63 secondScatteringFoilDir -> SetGuidance("set specification of second scattering foil"); 64 65 rangeStopperDir = new G4UIdirectory("/beamLine/Stopper/"); 66 rangeStopperDir -> SetGuidance("set specification of stopper"); 55 // Change Phantom position 56 changeThePhantomPositionCmd = new G4UIcmdWith3VectorAndUnit("/changePhantom/position", this); 57 changeThePhantomPositionCmd -> SetGuidance("Insert X Y and Z dimensions for the position of the center of the Phantom" 58 " respect to that of the \"World\""); 59 changeThePhantomPositionCmd -> SetParameterName("PositionAlongX", 60 "PositionAlongY", 61 "PositionAlongZ", false); 62 changeThePhantomPositionCmd -> SetDefaultUnit("mm"); 63 changeThePhantomPositionCmd -> SetUnitCandidates("mm cm m"); 64 changeThePhantomPositionCmd -> AvailableForStates(G4State_Idle); 67 65 68 finalCollimatorDir = new G4UIdirectory("/beamLine/FinalCollimator/");69 finalCollimatorDir -> SetGuidance("set specification of final collimator");70 66 71 modulatorAngleCmd = new G4UIcmdWithADoubleAndUnit("/modulator/angle",this); 72 modulatorAngleCmd -> SetGuidance("Set Modulator Angle"); 73 modulatorAngleCmd -> SetParameterName("Size",false); 74 modulatorAngleCmd -> SetRange("Size>=0."); 75 modulatorAngleCmd -> SetUnitCategory("Angle"); 76 modulatorAngleCmd -> AvailableForStates(G4State_Idle); 77 78 rangeShifterMatCmd = new G4UIcmdWithAString("/beamLine/RangeShifter/RSMat",this); 79 rangeShifterMatCmd -> SetGuidance("Set material of range shifter"); 80 rangeShifterMatCmd -> SetParameterName("choice",false); 81 rangeShifterMatCmd -> AvailableForStates(G4State_Idle); 82 83 rangeShifterXSizeCmd = new G4UIcmdWithADoubleAndUnit("/beamLine/RangeShifter/thickness",this); 84 rangeShifterXSizeCmd -> SetGuidance("Set half of the thickness of range shifter along X axis"); 85 rangeShifterXSizeCmd -> SetParameterName("Size",false); 86 rangeShifterXSizeCmd -> SetDefaultUnit("mm"); 87 rangeShifterXSizeCmd -> SetUnitCandidates("mm cm m"); 88 rangeShifterXSizeCmd -> AvailableForStates(G4State_Idle); 89 90 rangeShifterXPositionCmd = new G4UIcmdWithADoubleAndUnit("/beamLine/RangeShifter/position",this); 91 rangeShifterXPositionCmd -> SetGuidance("Set position of range shifter"); 92 rangeShifterXPositionCmd -> SetParameterName("Size",false); 93 rangeShifterXPositionCmd -> SetDefaultUnit("mm"); 94 rangeShifterXPositionCmd -> SetUnitCandidates("mm cm m"); 95 rangeShifterXPositionCmd -> AvailableForStates(G4State_Idle); 96 97 firstScatteringFoilXSizeCmd = new G4UIcmdWithADoubleAndUnit("/beamLine/ScatteringFoil1/thickness",this); 98 firstScatteringFoilXSizeCmd -> SetGuidance("Set hlaf thickness of first scattering foil"); 99 firstScatteringFoilXSizeCmd -> SetParameterName("Size",false); 100 firstScatteringFoilXSizeCmd -> SetDefaultUnit("mm"); 101 firstScatteringFoilXSizeCmd -> SetUnitCandidates("mm cm m"); 102 firstScatteringFoilXSizeCmd -> AvailableForStates(G4State_Idle); 103 104 secondScatteringFoilXSizeCmd = new G4UIcmdWithADoubleAndUnit("/beamLine/ScatteringFoil2/thickness",this); 105 secondScatteringFoilXSizeCmd -> SetGuidance("Set half thickness of second scattering foil"); 106 secondScatteringFoilXSizeCmd -> SetParameterName("Size",false); 107 secondScatteringFoilXSizeCmd -> SetDefaultUnit("mm"); 108 secondScatteringFoilXSizeCmd -> SetUnitCandidates("mm cm m"); 109 secondScatteringFoilXSizeCmd -> AvailableForStates(G4State_Idle); 110 111 outerRadiusStopperCmd = new G4UIcmdWithADoubleAndUnit("/beamLine/Stopper/outRadius",this); 112 outerRadiusStopperCmd -> SetGuidance("Set size of outer radius"); 113 outerRadiusStopperCmd -> SetParameterName("Size",false); 114 outerRadiusStopperCmd -> SetDefaultUnit("mm"); 115 outerRadiusStopperCmd -> SetUnitCandidates("mm cm m"); 116 outerRadiusStopperCmd -> AvailableForStates(G4State_Idle); 117 118 innerRadiusFinalCollimatorCmd = new G4UIcmdWithADoubleAndUnit("/beamLine/FinalCollimator/halfInnerRad",this); 119 innerRadiusFinalCollimatorCmd -> SetGuidance("Set size of inner radius ( max 21.5 mm)"); 120 innerRadiusFinalCollimatorCmd -> SetParameterName("Size",false); 121 innerRadiusFinalCollimatorCmd -> SetDefaultUnit("mm"); 122 innerRadiusFinalCollimatorCmd -> SetUnitCandidates("mm cm m"); 123 innerRadiusFinalCollimatorCmd -> AvailableForStates(G4State_Idle); 67 // Change detector size 68 changeTheDetectorDir = new G4UIdirectory("/changeDetector/"); 69 changeTheDetectorDir -> SetGuidance("Command to change the Detector's Size/position/Voxels"); 70 71 changeTheDetectorSizeCmd = new G4UIcmdWith3VectorAndUnit("/changeDetector/size",this); 72 changeTheDetectorSizeCmd -> SetGuidance("Insert sizes for X Y and Z dimensions of the Detector" 73 "\n 0 or negative values mean <<Don't change it>>"); 74 changeTheDetectorSizeCmd -> SetParameterName("DetectorSizeAlongX", "DetectorSizeAlongY", "DetectorSizeAlongZ", false); 75 changeTheDetectorSizeCmd -> SetDefaultUnit("mm"); 76 changeTheDetectorSizeCmd -> SetUnitCandidates("um mm cm"); 77 changeTheDetectorSizeCmd -> AvailableForStates(G4State_Idle); 78 79 // Change the detector to phantom displacement 80 changeTheDetectorToPhantomPositionCmd = new G4UIcmdWith3VectorAndUnit("/changeDetector/displacement",this); 81 changeTheDetectorToPhantomPositionCmd -> SetGuidance("Insert X Y and Z displacements between Detector and Phantom" 82 "\nNegative values mean <<Don't change it!>>"); 83 changeTheDetectorToPhantomPositionCmd -> SetParameterName("DisplacementAlongX", 84 "DisplacementAlongY", 85 "DisplacementAlongZ", false); 86 changeTheDetectorToPhantomPositionCmd -> SetDefaultUnit("mm"); 87 changeTheDetectorToPhantomPositionCmd -> SetUnitCandidates("um mm cm"); 88 changeTheDetectorToPhantomPositionCmd -> AvailableForStates(G4State_Idle); 89 90 // Change voxels by its size 91 changeTheDetectorVoxelCmd = new G4UIcmdWith3VectorAndUnit("/changeDetector/voxelSize",this); 92 changeTheDetectorVoxelCmd -> SetGuidance("Insert Voxel sizes for X Y and Z dimensions" 93 "\n 0 or negative values mean <<Don't change it!>>"); 94 changeTheDetectorVoxelCmd -> SetParameterName("VoxelSizeAlongX", "VoxelSizeAlongY", "VoxelSizeAlongZ", false); 95 changeTheDetectorVoxelCmd -> SetDefaultUnit("mm"); 96 changeTheDetectorVoxelCmd -> SetUnitCandidates("um mm cm"); 97 changeTheDetectorVoxelCmd -> AvailableForStates(G4State_Idle); 98 } 99 100 ///////////////////////////////////////////////////////////////////////////// 101 HadrontherapyDetectorMessenger::~HadrontherapyDetectorMessenger() 102 { 103 delete changeThePhantomDir; 104 delete changeThePhantomSizeCmd; 105 delete changeThePhantomPositionCmd; 106 delete changeTheDetectorDir; 107 delete changeTheDetectorSizeCmd; 108 delete changeTheDetectorToPhantomPositionCmd; 109 delete changeTheDetectorVoxelCmd; 124 110 } 125 111 126 HadrontherapyDetectorMessenger::~HadrontherapyDetectorMessenger() 127 { 128 delete innerRadiusFinalCollimatorCmd; 129 delete outerRadiusStopperCmd; 130 delete secondScatteringFoilXSizeCmd; 131 delete firstScatteringFoilXSizeCmd; 132 delete rangeShifterXPositionCmd; 133 delete rangeShifterXSizeCmd; 134 delete rangeShifterMatCmd; 135 delete modulatorAngleCmd; 136 delete finalCollimatorDir; 137 delete rangeStopperDir; 138 delete secondScatteringFoilDir; 139 delete firstScatteringFoilDir; 140 delete rangeShifterDir; 141 delete beamLineDir; 142 delete modulatorDir; 112 ///////////////////////////////////////////////////////////////////////////// 113 void HadrontherapyDetectorMessenger::SetNewValue(G4UIcommand* command,G4String newValue) 114 { 115 116 if( command == changeThePhantomSizeCmd) 117 { 118 G4ThreeVector size = changeThePhantomSizeCmd -> GetNew3VectorValue(newValue); 119 hadrontherapyDetector -> SetPhantomSize(size.getX(),size.getY(),size.getZ()); 120 } 121 else if (command == changeThePhantomPositionCmd ) 122 { 123 G4ThreeVector size = changeThePhantomPositionCmd -> GetNew3VectorValue(newValue); 124 hadrontherapyDetector -> SetPhantomPosition(size); 125 } 126 else if (command == changeTheDetectorSizeCmd) 127 { 128 G4ThreeVector size = changeTheDetectorSizeCmd -> GetNew3VectorValue(newValue); 129 hadrontherapyDetector -> SetDetectorSize(size.getX(),size.getY(),size.getZ()); 130 } 131 else if (command == changeTheDetectorToPhantomPositionCmd) 132 { 133 G4ThreeVector size = changeTheDetectorToPhantomPositionCmd-> GetNew3VectorValue(newValue); 134 hadrontherapyDetector -> SetDetectorToPhantomPosition(size); 135 } 136 else if (command == changeTheDetectorVoxelCmd) 137 { 138 G4ThreeVector size = changeTheDetectorVoxelCmd -> GetNew3VectorValue(newValue); 139 hadrontherapyDetector -> SetNumberOfVoxelBySize(size.getX(),size.getY(),size.getZ()); 140 } 143 141 } 144 145 void HadrontherapyDetectorMessenger::SetNewValue(G4UIcommand* command,G4String newValue)146 {147 if( command == modulatorAngleCmd )148 { hadrontherapyDetector -> SetModulatorAngle149 (modulatorAngleCmd -> GetNewDoubleValue(newValue));}150 151 if( command == rangeShifterMatCmd )152 { hadrontherapyDetector -> SetRSMaterial(newValue);}153 154 if( command == rangeShifterXSizeCmd )155 { hadrontherapyDetector -> SetRangeShifterXSize156 (rangeShifterXSizeCmd -> GetNewDoubleValue(newValue));}157 158 if( command == rangeShifterXPositionCmd )159 { hadrontherapyDetector -> SetRangeShifterXPosition160 (rangeShifterXPositionCmd -> GetNewDoubleValue(newValue));}161 162 if( command == firstScatteringFoilXSizeCmd )163 { hadrontherapyDetector -> SetFirstScatteringFoilSize164 (firstScatteringFoilXSizeCmd -> GetNewDoubleValue(newValue));}165 166 if( command == secondScatteringFoilXSizeCmd )167 { hadrontherapyDetector -> SetSecondScatteringFoilSize168 (secondScatteringFoilXSizeCmd -> GetNewDoubleValue(newValue));}169 170 if( command == outerRadiusStopperCmd )171 { hadrontherapyDetector -> SetOuterRadiusStopper(172 outerRadiusStopperCmd -> GetNewDoubleValue(newValue));}173 174 if( command == innerRadiusFinalCollimatorCmd )175 { hadrontherapyDetector -> SetInnerRadiusFinalCollimator176 (innerRadiusFinalCollimatorCmd -> GetNewDoubleValue(newValue));}177 }178 -
trunk/examples/advanced/hadrontherapy/src/HadrontherapyEventAction.cc
r807 r1230 24 24 // ******************************************************************** 25 25 // 26 // $Id: HadrontherapyEventAction.cc; May 2005 27 // ---------------------------------------------------------------------------- 28 // GEANT 4 - Hadrontherapy example 29 // ---------------------------------------------------------------------------- 30 // Code developed by: 31 // 32 // G.A.P. Cirrone(a)*, G. Candiano, F. Di Rosa(a), S. Guatelli(b), G. Russo(a) 33 // 34 // (a) Laboratori Nazionali del Sud 35 // of the National Institute for Nuclear Physics, Catania, Italy 36 // (b) National Institute for Nuclear Physics Section of Genova, genova, Italy 37 // 38 // * cirrone@lns.infn.it 39 // -------------------------------------------------------------- 26 // $Id: HadrontherapyEventAction.cc; 27 // See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy 28 40 29 #include "G4Event.hh" 41 30 #include "G4EventManager.hh" … … 48 37 #include "G4VVisManager.hh" 49 38 #include "HadrontherapyEventAction.hh" 50 #include "Hadrontherapy PhantomHit.hh"51 #include "Hadrontherapy PhantomSD.hh"39 #include "HadrontherapyDetectorHit.hh" 40 #include "HadrontherapyDetectorSD.hh" 52 41 #include "HadrontherapyDetectorConstruction.hh" 53 42 #include "HadrontherapyMatrix.hh" 43 #include "HadrontherapyEventActionMessenger.hh" 54 44 55 HadrontherapyEventAction::HadrontherapyEventAction(HadrontherapyMatrix* matrixPointer) : 56 drawFlag("all" ) 45 ///////////////////////////////////////////////////////////////////////////// 46 HadrontherapyEventAction::HadrontherapyEventAction() : 47 drawFlag("all" ),printModulo(1000), pointerEventMessenger(0) 57 48 { 58 49 hitsCollectionID = -1; 59 matrix = matrixPointer;50 pointerEventMessenger = new HadrontherapyEventActionMessenger(this); 60 51 } 61 52 53 ///////////////////////////////////////////////////////////////////////////// 62 54 HadrontherapyEventAction::~HadrontherapyEventAction() 63 55 { 56 delete pointerEventMessenger; 64 57 } 65 58 66 void HadrontherapyEventAction::BeginOfEventAction(const G4Event* ) 67 { 68 G4SDManager* pSDManager = G4SDManager::GetSDMpointer(); 69 if(hitsCollectionID == -1) 70 hitsCollectionID = pSDManager -> GetCollectionID("HadrontherapyPhantomHitsCollection"); 59 ///////////////////////////////////////////////////////////////////////////// 60 void HadrontherapyEventAction::BeginOfEventAction(const G4Event* evt) 61 { 62 G4int evtNb = evt->GetEventID(); 63 64 //printing survey 65 if (evtNb%printModulo == 0) 66 G4cout << "\n---> Begin of Event: " << evtNb << G4endl; 67 68 G4SDManager* pSDManager = G4SDManager::GetSDMpointer(); 69 if(hitsCollectionID == -1) 70 hitsCollectionID = pSDManager -> GetCollectionID("HadrontherapyDetectorHitsCollection"); 71 71 } 72 72 73 ///////////////////////////////////////////////////////////////////////////// 73 74 void HadrontherapyEventAction::EndOfEventAction(const G4Event* evt) 74 75 { 75 76 if(hitsCollectionID < 0) 76 return; 77 77 return; 78 78 G4HCofThisEvent* HCE = evt -> GetHCofThisEvent(); 79 HadrontherapyPhantomHitsCollection* CHC = NULL;80 79 81 80 if(HCE) 82 CHC = (HadrontherapyPhantomHitsCollection*)(HCE -> GetHC(hitsCollectionID)); 83 84 if(CHC) 85 { 86 if(matrix) 87 { 88 // Fill the matrix with the information: voxel and associated energy deposit 89 // in the phantom at the end of the event 81 { 82 HadrontherapyDetectorHitsCollection* CHC = (HadrontherapyDetectorHitsCollection*)(HCE -> GetHC(hitsCollectionID)); 83 if(CHC) 84 { 85 matrix = HadrontherapyMatrix::getInstance(); 86 if(matrix) 87 { 88 // Fill the matrix with the information: voxel and associated energy deposit 89 // in the detector at the end of the event 90 90 91 91 G4int HitCount = CHC -> entries(); … … 98 98 matrix -> Fill(i, j, k, energyDeposit/MeV); 99 99 } 100 }100 } 101 101 } 102 102 } 103 103 // Extract the trajectories and draw them in the visualisation 104 104 -
trunk/examples/advanced/hadrontherapy/src/HadrontherapyMatrix.cc
r807 r1230 24 24 // ******************************************************************** 25 25 // 26 // $Id: HadrontherapyPhantomSD.cc; May 2005 27 // ---------------------------------------------------------------------------- 28 // GEANT 4 - Hadrontherapy example 29 // ---------------------------------------------------------------------------- 30 // Code developed by: 31 // 32 // G.A.P. Cirrone(a)*, F. Di Rosa(a), S. Guatelli(b), G. Russo(a) 33 // 34 // (a) Laboratori Nazionali del Sud 35 // of the National Institute for Nuclear Physics, Catania, Italy 36 // (b) National Institute for Nuclear Physics Section of Genova, genova, Italy 37 // 38 // * cirrone@lns.infn.it 39 // ---------------------------------------------------------------------------- 26 // $Id: HadrontherapyMatrix.cc; 27 // See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy// 40 28 41 29 #include "HadrontherapyMatrix.hh" … … 44 32 #include <fstream> 45 33 46 HadrontherapyMatrix::HadrontherapyMatrix() 34 HadrontherapyMatrix* HadrontherapyMatrix::instance = NULL; 35 // Static method that only return a pointer to the matrix object 36 HadrontherapyMatrix* HadrontherapyMatrix::getInstance() 37 { 38 return instance; 39 } 40 // This STATIC method delete (!) the old matrix and rewrite a new object returning a pointer to it 41 HadrontherapyMatrix* HadrontherapyMatrix::getInstance(G4int voxelX, G4int voxelY, G4int voxelZ) 42 { 43 if (instance) delete instance; 44 instance = new HadrontherapyMatrix(voxelX, voxelY, voxelZ); 45 instance -> Initialize(); 46 return instance; 47 } 48 49 HadrontherapyMatrix::HadrontherapyMatrix(G4int voxelX, G4int voxelY, G4int voxelZ): 50 matrix(0) 47 51 { 48 // Number of the voxels of the phantom 49 numberVoxelX = 200; 50 numberVoxelY = 200; 51 numberVoxelZ = 200; 52 53 // Create the matrix 52 // Number of the voxels of the phantom 53 // For Y = Z = 1 the phantom is divided in slices (and not in voxels) 54 // orthogonal to the beam axis 55 numberVoxelX = voxelX; 56 numberVoxelY = voxelY; 57 numberVoxelZ = voxelZ; 58 // Create the dose matrix 54 59 matrix = new G4double[numberVoxelX*numberVoxelY*numberVoxelZ]; 60 if (matrix) G4cout << "Matrix: Memory space to store physical dose into " << 61 numberVoxelX*numberVoxelY*numberVoxelZ << 62 " voxels has been allocated " << G4endl; 63 else G4Exception("Can't allocate memory to store physical dose!"); 55 64 } 56 65 57 66 HadrontherapyMatrix::~HadrontherapyMatrix() 58 67 { 59 delete[] matrix; 68 delete[] matrix; 69 } 70 71 void HadrontherapyMatrix::flush() 72 { 73 if(matrix) 74 for(int i=0; i<numberVoxelX*numberVoxelY*numberVoxelZ; i++) 75 { 76 matrix[i] = 0; 77 } 60 78 } 61 79 void HadrontherapyMatrix::Initialize() 62 80 { 63 // Initialise the elemnts of the matrix to zero 64 81 // Initialise the elements of the matrix to zero 65 82 for(G4int i = 0; i < numberVoxelX; i++) 66 83 { 67 84 for(G4int j = 0; j < numberVoxelY; j++) 68 {69 for(G4int k = 0; k < numberVoxelZ; k++)85 { 86 for(G4int k = 0; k < numberVoxelZ; k++) 70 87 71 matrix[(i*numberVoxelY+j)*numberVoxelZ+k] = 0.;72 }88 matrix[Index(i,j,k)] = 0.; 89 } 73 90 } 74 91 } … … 78 95 { 79 96 if (matrix) 80 matrix[ (i*numberVoxelY+j)*numberVoxelZ+k] += energyDeposit;97 matrix[Index(i,j,k)] += energyDeposit; 81 98 82 // Store the energy deposit in the matrix elem nt corresponding83 // to the phantom voxel 99 // Store the energy deposit in the matrix element corresponding 100 // to the phantom voxel i, j, k 84 101 } 85 102 … … 95 112 if (matrix) 96 113 { 97 for(G4int l = 0; l < numberVoxelZ; l++) 98 { 99 k = l; 100 101 for(G4int m = 0; m < numberVoxelY; m++) 102 { 103 j = m * numberVoxelZ + k; 114 std::ofstream ofs; 115 ofs.open("DoseDistribution.out"); 116 117 for(G4int l = 0; l < numberVoxelZ; l++) 118 { 119 k = l; 120 121 for(G4int m = 0; m < numberVoxelY; m++) 122 { 123 j = m * numberVoxelZ + k; 104 124 105 125 for(G4int n = 0; n < numberVoxelX; n++) … … 108 128 if(matrix[i] != 0) 109 129 { 110 111 #ifdef G4ANALYSIS_USE 130 ofs << n << '\t' << m << '\t' << 131 k << '\t' << matrix[i] << G4endl; 132 133 #ifdef ANALYSIS_USE 112 134 HadrontherapyAnalysisManager* analysis = 113 135 HadrontherapyAnalysisManager::getInstance(); 114 136 analysis -> FillEnergyDeposit(n, m, k, matrix[i]); 115 137 analysis -> BraggPeak(n, matrix[i]); 116 138 #endif 117 139 } 118 140 } 119 141 } 120 142 } -
trunk/examples/advanced/hadrontherapy/src/HadrontherapyModulator.cc
r807 r1230 24 24 // ******************************************************************** 25 25 // 26 // $Id: HadrontherapyModulator.cc; May 2005 27 // ---------------------------------------------------------------------------- 28 // GEANT 4 - Hadrontherapy example 29 // ---------------------------------------------------------------------------- 30 // Code developed by: 31 // 32 // G.A.P. Cirrone(a)*, F. Di Rosa(a), S. Guatelli(b), G. Russo(a) 33 // 34 // (a) Laboratori Nazionali del Sud 35 // of the National Institute for Nuclear Physics, Catania, Italy 36 // (b) National Institute for Nuclear Physics Section of Genova, genova, Italy 37 // 38 // * cirrone@lns.infn.it 39 // ---------------------------------------------------------------------------- 26 // $Id: HadrontherapyModulator.cc; 27 // See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy 40 28 41 29 #include "G4Material.hh" … … 51 39 #include "G4VisAttributes.hh" 52 40 #include "G4Colour.hh" 53 #include "HadrontherapyMaterial.hh"54 41 #include "HadrontherapyModulator.hh" 55 #include "HadrontherapyMaterial.hh"56 42 #include "G4Transform3D.hh" 57 43 #include "G4ios.hh" 58 44 #include <fstream> 59 45 #include "G4RunManager.hh" 46 #include "G4NistManager.hh" 60 47 61 48 HadrontherapyModulator::HadrontherapyModulator():physiMotherMod(0), … … 141 128 rm -> rotateY(phi); 142 129 } 143 130 ///////////////////////////////////////////////////////////////////////////// 144 131 HadrontherapyModulator::~HadrontherapyModulator() 145 132 { 146 133 delete rm; 147 134 } 148 135 ///////////////////////////////////////////////////////////////////////////// 149 136 void HadrontherapyModulator::BuildModulator(G4VPhysicalVolume* motherVolume) 150 137 { 151 152 153 //Materials used for the modulator wheel 154 HadrontherapyMaterial* material = new HadrontherapyMaterial(); 155 156 G4Material* Mod0Mater = material -> GetMat("Air"); 157 G4Material* ModMater = material -> GetMat("Air"); 158 delete material; 159 138 G4bool isotopes = false; 139 G4Material* airNist = G4NistManager::Instance()->FindOrBuildMaterial("G4_AIR", isotopes); 140 141 G4Material* Mod0Mater = airNist; 142 G4Material* ModMater = airNist; 143 160 144 G4double innerRadiusOfTheTube = 2.5 *cm; 161 145 G4double outerRadiusOfTheTube = 9.5 *cm; … … 163 147 164 148 // Mother of the modulator wheel 165 166 G4ThreeVector positionMotherMod = G4ThreeVector(-2260.50 *mm, 30 *mm, 50 *mm); 149 G4ThreeVector positionMotherMod = G4ThreeVector(-1960.50 *mm, 30 *mm, 50 *mm); 167 150 168 151 G4Box* solidMotherMod = new G4Box("MotherMod", 12 *cm, 12 *cm, 12 *cm); 169 152 170 153 G4LogicalVolume * logicMotherMod = new G4LogicalVolume(solidMotherMod, Mod0Mater,"MotherMod",0,0,0); 171 172 173 154 174 155 physiMotherMod = new G4PVPlacement(rm,positionMotherMod, "MotherMod", … … 200 181 logicMod0 = new G4LogicalVolume(solidMod0, Mod0Mater, "Mod0",0,0,0); 201 182 202 203 183 physiMod0 = new G4PVPlacement(G4Transform3D(rm2, positionMod0), 204 184 logicMod0, … … 212 192 // First modulator sclice 213 193 //---------------------------------------------------------- 214 215 194 216 195 G4double startAngleOfTheTube1 = 54.267*deg; -
trunk/examples/advanced/hadrontherapy/src/HadrontherapyParticles.cc
r807 r1230 24 24 // ******************************************************************** 25 25 // 26 // $Id: HadrontherapyParticles.cc; May 2005 27 // ---------------------------------------------------------------------------- 28 // GEANT 4 - Hadrontherapy example 29 // ---------------------------------------------------------------------------- 30 // Code developed by: 31 // 32 // G.A.P. Cirrone(a)*, F. Di Rosa(a), S. Guatelli(b), G. Russo(a) 33 // 34 // (a) Laboratori Nazionali del Sud 35 // of the National Institute for Nuclear Physics, Catania, Italy 36 // (b) National Institute for Nuclear Physics Section of Genova, genova, Italy 37 // 38 // * cirrone@lns.infn.it 39 // ---------------------------------------------------------------------------- 26 // $Id: HadrontherapyParticles.cc; 27 // See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy 28 40 29 #include "HadrontherapyParticles.hh" 41 30 #include "G4ParticleDefinition.hh" -
trunk/examples/advanced/hadrontherapy/src/HadrontherapyPhysicsList.cc
r807 r1230 24 24 // ******************************************************************** 25 25 // 26 // $Id: HadrontherapyPhysicsList.cc,v 1.0 27 // ---------------------------------------------------------------------------- 28 // GEANT 4 - Hadrontherapy example 29 // ---------------------------------------------------------------------------- 30 // Code developed by: 31 // 32 // G.A.P. Cirrone(a)*, F. Di Rosa(a), S. Guatelli(b), G. Russo(a) 33 // 34 // (a) Laboratori Nazionali del Sud 35 // of the National Institute for Nuclear Physics, Catania, Italy 36 // (b) National Institute for Nuclear Physics Section of Genova, genova, Italy 37 // 38 // * cirrone@lns.infn.it 39 // ---------------------------------------------------------------------------- 40 41 #include "globals.hh" 42 #include "G4ProcessManager.hh" 43 #include "G4Region.hh" 44 #include "G4RegionStore.hh" 45 #include "G4ParticleDefinition.hh" 46 #include "G4ParticleTypes.hh" 47 #include "G4ParticleTable.hh" 26 // HadrontherapyPhysicsList.cc 27 // See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy 28 29 // This class provides all the physic models that can be activated inside Hadrontherapy; 30 // Each model can be setted via macro commands; 31 // Inside Hadrontherapy the models can be activate with three different complementar methods: 32 // 33 // 1. Use of the *Packages*. 34 // Packages (that are contained inside the 35 // Geant4 distribution at $G4INSTALL/source/physics_lists/lists) provide a full set 36 // of models (both electromagnetic and hadronic). 37 // The User can use this method simply add the line /physic/addPackage <nameOfPackage> 38 // in his/her macro file. No other action is required. 39 // For Hadrontherapy applications we suggest the use of the QGSP_BIC package 40 // for proton beams. The same can be used 41 // also for ligth ion beam. 42 // Example of use of package can be found in the packageQGSP_BIC.mac file. 43 // 44 // 2. Use of the *Physic Lists*. 45 // Physic lists are also already ready to use inside the Geant4 distribution 46 // ($G4INSTALL/source/physics_lists/builders). To use them the simple 47 // /physic/addPhysics <nameOfPhysicList> command must be used in the macro. 48 // In Hadrontherapy we provide physics list to activate Electromagnetic, 49 // Hadronic elastic and Hadronic inelastic models. 50 // 51 // For Hadrontherapy we suggest the use of: 52 // 53 // /physic/addPhysic/emstandard_option3 (electromagnetic model) 54 // /physic/addPhysic/QElastic (hadronic elastic model) 55 // /physic/addPhysic/binary (hadronic inelastic models for proton and neutrons) 56 // /physic/addPhysic/binary_ion (hadronic inelastic models for ions) 57 // 58 // Example of the use of physics lists can be found in the macro files included in the 59 // 'macro' folder . 60 // 61 // 3. Use of a *local* physics. In this case the models are implemented in local files 62 // contained in the Hadrontherapy folder. The use of local physic is recommended 63 // to more expert Users. 64 // We provide as local, only the LocalStandardICRU73EmPhysic.cc (an Elecromagnetic 65 // implementation containing the new ICRU73 data table for ions stopping powers) 66 // and the LocalIonIonInelasticPhysic.cc (physic list to use for the ion-ion interaction 67 // case) 68 // The *local* physics can be activated with the same /physic/addPhysic <nameOfPhysic> command; 69 // 70 // While Packages approch must be used exclusively, Physics List and Local physics can 71 // be activated, if necessary, contemporaneously in the same simulation run. 72 // 73 // AT MOMENT, IF ACCURATE RESULTS ARE NEDED, WE STRONGLY RECOMMEND THE USE OF THE MACROS: 74 // proton_therapy.mac: use of the built-in Geant4 physics list for proton beams) 75 // ion_therapy.mac : use of mixed combination of native Geant4 physic lists 76 // and local physic for ion-ion enelastic processes) 77 48 78 #include "HadrontherapyPhysicsList.hh" 49 79 #include "HadrontherapyPhysicsListMessenger.hh" 50 #include "HadrontherapyParticles.hh" 51 #include "Decay.hh" 52 #include "EMPhotonStandard.hh" 53 #include "EMPhotonEPDL.hh" 54 #include "EMPhotonPenelope.hh" 55 #include "EMElectronStandard.hh" 56 #include "EMElectronEEDL.hh" 57 #include "EMElectronPenelope.hh" 58 #include "EMPositronStandard.hh" 59 #include "EMPositronPenelope.hh" 60 #include "EMMuonStandard.hh" 61 #include "EMHadronIonLowEICRU49.hh" 62 #include "EMHadronIonLowEZiegler1977.hh" 63 #include "EMHadronIonLowEZiegler1985.hh" 64 #include "EMHadronIonStandard.hh" 65 #include "HIProtonNeutronPrecompound.hh" 66 #include "HIProtonNeutronBertini.hh" 67 #include "HIProtonNeutronBinary.hh" 68 #include "HIProtonNeutronLEP.hh" 69 #include "HIProtonNeutronPrecompoundGEM.hh" 70 #include "HIProtonNeutronPrecompoundFermi.hh" 71 #include "HIProtonNeutronPrecompoundGEMFermi.hh" 72 #include "HIPionBertini.hh" 73 #include "HIPionLEP.hh" 74 #include "HIIonLEP.hh" 75 #include "HEHadronIonLElastic.hh" 76 #include "HEHadronIonBertiniElastic.hh" 77 #include "HEHadronIonQElastic.hh" 78 #include "HEHadronIonUElastic.hh" 79 #include "HRMuonMinusCapture.hh" 80 81 82 HadrontherapyPhysicsList::HadrontherapyPhysicsList(): G4VModularPhysicsList(), 83 decayIsRegistered(false), 84 emElectronIsRegistered(false), 85 emPositronIsRegistered(false), 86 emPhotonIsRegistered(false), 87 emIonIsRegistered(false), 88 emMuonIsRegistered(false), 89 hadrElasticHadronIonIsRegistered(false), 90 hadrInelasticPionIsRegistered(false), 91 hadrInelasticIonIsRegistered(false), 92 hadrInelasticProtonNeutronIsRegistered(false), 93 hadrAtRestMuonIsRegistered(false) 94 { 95 // The secondary production threshold is set to 10. mm 96 // for all the particles in all the experimental set-up 97 // The phantom is defined as a Geant4 Region. Here the cut is fixed to 0.001 mm 98 defaultCutValue = 0.01 * mm; 99 100 // Messenger: it is possible to activate physics processes and models interactively 101 messenger = new HadrontherapyPhysicsListMessenger(this); 80 #include "HadrontherapyStepMax.hh" 81 #include "G4PhysListFactory.hh" 82 #include "G4VPhysicsConstructor.hh" 83 84 // Local physic directly implemented in the Hadronthrapy directory 85 #include "LocalIonIonInelasticPhysic.hh" // Physic dedicated to the ion-ion inelastic processes 86 #include "LocalINCLIonIonInelasticPhysic.hh" // Physic dedicated to the ion-ion inelastic processes using INCL/ABLA 87 88 // Physic lists (contained inside the Geant4 distribution) 89 #include "G4EmStandardPhysics_option3.hh" 90 #include "G4EmLivermorePhysics.hh" 91 #include "G4EmPenelopePhysics.hh" 92 #include "G4DecayPhysics.hh" 93 #include "G4HadronElasticPhysics.hh" 94 #include "G4HadronDElasticPhysics.hh" 95 #include "G4HadronHElasticPhysics.hh" 96 #include "G4HadronQElasticPhysics.hh" 97 #include "G4HadronInelasticQBBC.hh" 98 #include "G4IonBinaryCascadePhysics.hh" 99 #include "G4Decay.hh" 100 101 #include "G4LossTableManager.hh" 102 #include "G4UnitsTable.hh" 103 #include "G4ProcessManager.hh" 104 105 #include "G4IonFluctuations.hh" 106 #include "G4IonParametrisedLossModel.hh" 107 #include "G4EmProcessOptions.hh" 108 109 #include "G4RadioactiveDecayPhysics.hh" 110 111 ///////////////////////////////////////////////////////////////////////////// 112 HadrontherapyPhysicsList::HadrontherapyPhysicsList() : G4VModularPhysicsList() 113 { 114 G4LossTableManager::Instance(); 115 defaultCutValue = 1.*mm; 116 cutForGamma = defaultCutValue; 117 cutForElectron = defaultCutValue; 118 cutForPositron = defaultCutValue; 119 120 helIsRegisted = false; 121 bicIsRegisted = false; 122 biciIsRegisted = false; 123 locIonIonInelasticIsRegistered = false; 124 radioactiveDecayIsRegisted = false; 125 126 stepMaxProcess = 0; 127 128 pMessenger = new HadrontherapyPhysicsListMessenger(this); 102 129 103 130 SetVerboseLevel(1); 104 131 105 // Register all the particles involved in the experimental set-up 106 RegisterPhysics( new HadrontherapyParticles("particles") ); 107 } 108 132 // EM physics 133 emPhysicsList = new G4EmStandardPhysics_option3(1); 134 emName = G4String("emstandard_opt3"); 135 136 // Deacy physics and all particles 137 decPhysicsList = new G4DecayPhysics(); 138 } 139 140 ///////////////////////////////////////////////////////////////////////////// 109 141 HadrontherapyPhysicsList::~HadrontherapyPhysicsList() 110 { 111 delete messenger; 112 } 113 142 { 143 delete pMessenger; 144 delete emPhysicsList; 145 delete decPhysicsList; 146 for(size_t i=0; i<hadronPhys.size(); i++) {delete hadronPhys[i];} 147 } 148 149 ///////////////////////////////////////////////////////////////////////////// 150 void HadrontherapyPhysicsList::AddPackage(const G4String& name) 151 { 152 G4PhysListFactory factory; 153 G4VModularPhysicsList* phys =factory.GetReferencePhysList(name); 154 G4int i=0; 155 const G4VPhysicsConstructor* elem= phys->GetPhysics(i); 156 G4VPhysicsConstructor* tmp = const_cast<G4VPhysicsConstructor*> (elem); 157 while (elem !=0) 158 { 159 RegisterPhysics(tmp); 160 elem= phys->GetPhysics(++i) ; 161 tmp = const_cast<G4VPhysicsConstructor*> (elem); 162 } 163 } 164 165 ///////////////////////////////////////////////////////////////////////////// 166 void HadrontherapyPhysicsList::ConstructParticle() 167 { 168 decPhysicsList->ConstructParticle(); 169 } 170 171 ///////////////////////////////////////////////////////////////////////////// 172 void HadrontherapyPhysicsList::ConstructProcess() 173 { 174 // transportation 175 // 176 AddTransportation(); 177 178 // electromagnetic physics list 179 // 180 emPhysicsList->ConstructProcess(); 181 em_config.AddModels(); 182 183 // decay physics list 184 // 185 decPhysicsList->ConstructProcess(); 186 187 // hadronic physics lists 188 for(size_t i=0; i<hadronPhys.size(); i++) { 189 hadronPhys[i]->ConstructProcess(); 190 } 191 192 // step limitation (as a full process) 193 // 194 AddStepMax(); 195 } 196 197 ///////////////////////////////////////////////////////////////////////////// 114 198 void HadrontherapyPhysicsList::AddPhysicsList(const G4String& name) 115 199 { 116 G4cout << "Adding PhysicsList component " << name << G4endl; 117 118 119 // **************** 120 // *** A. DECAY *** 121 // **************** 122 123 124 if (name == "Decay") 125 { 126 if (decayIsRegistered) 127 { 128 G4cout << "HadrontherapyPhysicsList::AddPhysicsList: " << name 129 << " cannot be registered ---- decay List already existing" 130 << G4endl; 131 } 132 else 133 { 134 G4cout << "HadrontherapyPhysicsList::AddPhysicsList: " << name 135 << " is registered" << G4endl; 136 RegisterPhysics( new Decay(name) ); 137 decayIsRegistered = true; 138 } 139 } 140 141 142 // *************************************** 143 // *** B. ELECTROMAGNETIC INTERACTIONS *** 144 // *************************************** 145 146 147 // *************** 148 // *** Photons *** 149 // *************** 150 151 // *** Option I: Standard 152 153 if (name == "EM-Photon-Standard") 154 { 155 if (emPhotonIsRegistered) 156 { 157 G4cout << "HadrontherapyPhysicsList::AddPhysicsList: " << name 158 << " cannot be registered ---- photon List already existing" 159 << G4endl; 160 } 161 else 162 { 163 G4cout << "HadrontherapyPhysicsList::AddPhysicsList: " << name 164 << " is registered" << G4endl; 165 RegisterPhysics( new EMPhotonStandard(name) ); 166 emPhotonIsRegistered = true; 167 } 168 } 169 170 171 // *** Option II: Low Energy based on the Livermore libraries 172 173 if (name == "EM-Photon-EPDL") 174 { 175 if (emPhotonIsRegistered) 176 { 177 G4cout << "HadrontherapyPhysicsList::AddPhysicsList: " << name 178 << " cannot be registered ---- photon List already existing" 179 << G4endl; 180 } 181 else 182 { 183 G4cout << "HadrontherapyPhysicsList::AddPhysicsList: " << name 184 << " is registered" << G4endl; 185 RegisterPhysics( new EMPhotonEPDL(name) ); 186 emPhotonIsRegistered = true; 187 } 188 } 189 190 191 // *** Option III: Low Energy Penelope 192 193 if (name == "EM-Photon-Penelope") 194 { 195 if (emPhotonIsRegistered) 196 { 197 G4cout << "HadrontherapyPhysicsList::AddPhysicsList: " << name 198 << " cannot be registered ---- photon List already existing" 199 << G4endl; 200 } 201 else 202 { 203 G4cout << "HadrontherapyPhysicsList::AddPhysicsList: " << name 204 << " is registered" << G4endl; 205 RegisterPhysics( new EMPhotonPenelope(name) ); 206 emPhotonIsRegistered = true; 207 } 208 } 209 210 211 // ***************** 212 // *** Electrons *** 213 // ***************** 214 215 // *** Option I: Standard 216 217 if (name == "EM-Electron-Standard") 218 { 219 if (emElectronIsRegistered) 220 { 221 G4cout << "HadrontherapyPhysicsList::AddPhysicsList: " << name 222 << " cannot be registered ---- electron List already existing" 223 << G4endl; 224 } 225 else 226 { 227 G4cout << "HadrontherapyPhysicsList::AddPhysicsList: " << name 228 << " is registered" << G4endl; 229 RegisterPhysics( new EMElectronStandard(name) ); 230 emElectronIsRegistered = true; 231 } 232 } 233 234 235 // *** Option II: Low Energy based on the Livermore libraries 236 237 if (name == "EM-Electron-EEDL") 238 { 239 if (emElectronIsRegistered) 240 { 241 G4cout << "HadrontherapyPhysicsList::AddPhysicsList: " << name 242 << " cannot be registered ---- electron List already existing" 243 << G4endl; 244 } 245 else 246 { 247 G4cout << "HadrontherapyPhysicsList::AddPhysicsList: " << name 248 << " is registered" << G4endl; 249 RegisterPhysics( new EMElectronEEDL(name) ); 250 emElectronIsRegistered = true; 251 } 252 } 253 254 255 // *** Option III: Low Energy Penelope 256 257 if (name == "EM-Electron-Penelope") 258 { 259 if (emElectronIsRegistered) 260 { 261 G4cout << "HadrontherapyPhysicsList::AddPhysicsList: " << name 262 << " cannot be registered ---- electron List already existing" 263 << G4endl; 264 } 265 else 266 { 267 G4cout << "HadrontherapyPhysicsList::AddPhysicsList: " << name 268 << " is registered" << G4endl; 269 RegisterPhysics( new EMElectronPenelope(name) ); 270 emElectronIsRegistered = true; 271 } 272 } 273 274 275 // ***************** 276 // *** Positrons *** 277 // ***************** 278 279 // *** Option I: Standard 280 if (name == "EM-Positron-Standard") 281 { 282 if (emPositronIsRegistered) 283 { 284 G4cout << "HadrontherapyPhysicsList::AddPhysicsList: " << name 285 << " cannot be registered ---- positron List already existing" 286 << G4endl; 287 } 288 else 289 { 290 G4cout << "HadrontherapyPhysicsList::AddPhysicsList: " << name 291 << " is registered" << G4endl; 292 RegisterPhysics( new EMPositronStandard(name) ); 293 emPositronIsRegistered = true; 294 } 295 } 296 297 298 // *** Option II: Low Energy Penelope 299 300 if (name == "EM-Positron-Penelope") 301 { 302 if (emPositronIsRegistered) 303 { 304 G4cout << "HadrontherapyPhysicsList::AddPhysicsList: " << name 305 << " cannot be registered ---- positron List already existing" 306 << G4endl; 307 } 308 else 309 { 310 G4cout << "HadrontherapyPhysicsList::AddPhysicsList: " << name 311 << " is registered" << G4endl; 312 RegisterPhysics( new EMPositronPenelope(name) ); 313 emPositronIsRegistered = true; 314 } 315 } 316 317 318 // ************************ 319 // *** Hadrons and Ions *** 320 // ************************ 321 322 // *** Option I: Low Energy with ICRU49 stopping power parametrisation 323 324 if (name == "EM-HadronIon-LowE") 325 { 326 if (emIonIsRegistered) 327 { 328 G4cout << "HadrontherapyPhysicsList::AddPhysicsList: " << name 329 << " cannot be registered ---- proton List already existing" 330 << G4endl; 331 } 332 else 333 { 334 G4cout << "HadrontherapyPhysicsList::AddPhysicsList: " << name 335 << " is registered" << G4endl; 336 RegisterPhysics( new EMHadronIonLowEICRU49(name) ); 337 emIonIsRegistered = true; 338 } 339 } 340 341 342 // *** Option II: Low Energy with Ziegler 1977 stopping power parametrisation 343 344 if (name == "EM-HadronIon-LowEZiegler1977") 345 { 346 if (emIonIsRegistered) 347 { 348 G4cout << "HadrontherapyPhysicsList::AddPhysicsList: " << name 349 << " cannot be registered ---- proton List already existing" 350 << G4endl; 351 } 352 else 353 { 354 G4cout << "HadrontherapyPhysicsList::AddPhysicsList: " << name 355 << " is registered" << G4endl; 356 RegisterPhysics( new EMHadronIonLowEZiegler1977(name) ); 357 emIonIsRegistered = true; 358 } 359 } 360 361 362 // *** Option III: Low Energy with Ziegler 1985 stopping power parametrisation 363 364 if (name == "EM-HadronIon-LowEZiegler1985") 365 { 366 if (emIonIsRegistered) 367 { 368 G4cout << "HadrontherapyPhysicsList::AddPhysicsList: " << name 369 << " cannot be registered ---- proton List already existing" 370 << G4endl; 371 } 372 else 373 { 374 G4cout << "HadrontherapyPhysicsList::AddPhysicsList: " << name 375 << " is registered" << G4endl; 376 RegisterPhysics( new EMHadronIonLowEZiegler1985(name) ); 377 emIonIsRegistered = true; 378 } 379 } 380 381 382 // *** Option IV: Standard 383 384 if (name == "EM-HadronIon-Standard") 385 { 386 if (emIonIsRegistered) 387 { 388 G4cout << "HadrontherapyPhysicsList::AddPhysicsList: " << name 389 << " cannot be registered ---- ion List already existing" 390 << G4endl; 391 } 392 else 393 { 394 G4cout << "HadrontherapyPhysicsList::AddPhysicsList: " << name 395 << " is registered" << G4endl; 396 RegisterPhysics( new EMHadronIonStandard(name) ); 397 emIonIsRegistered = true; 398 } 399 } 400 401 402 // ************* 403 // *** Muons *** 404 // ************* 405 406 // *** Option I: Standard 407 408 if (name == "EM-Muon-Standard") 409 { 410 if (emMuonIsRegistered) 411 { 412 G4cout << "HadrontherapyPhysicsList::AddPhysicsList: " << name 413 << " cannot be registered ---- decay List already existing" 414 << G4endl; 415 } 416 else 417 { 418 G4cout << "HadrontherapyPhysicsList::AddPhysicsList: " << name 419 << " is registered" << G4endl; 420 RegisterPhysics( new EMMuonStandard(name) ); 421 emMuonIsRegistered = true; 422 } 423 } 424 425 426 // ******************************** 427 // *** C. HADRONIC INTERACTIONS *** 428 // ******************************** 429 430 431 // ****************************** 432 // *** C.1. ELASTIC PROCESSES *** 433 // ****************************** 434 435 436 // ************************ 437 // *** Hadrons and Ions *** 438 // ************************ 439 440 // *** Option I: GHEISHA like LEP model 441 442 if (name == "HadronicEl-HadronIon-LElastic") 443 { 444 if (hadrElasticHadronIonIsRegistered) 445 { 446 G4cout << "HadrontherapyPhysicsList::AddPhysicsList: " << name 447 << " cannot be registered ---- hadronic Elastic Scattering List already existing" 448 << G4endl; 449 } 450 else 451 { 452 G4cout << "HadrontherapyPhysicsList::AddPhysicsList: " << name 453 << " is registered" << G4endl; 454 RegisterPhysics( new HEHadronIonLElastic(name) ); 455 hadrElasticHadronIonIsRegistered = true; 456 } 457 } 458 459 460 // *** Option II: Bertini model 461 462 if (name == "HadronicEl-HadronIon-Bert") 463 { 464 if (hadrElasticHadronIonIsRegistered) 465 { 466 G4cout << "HadrontherapyPhysicsList::AddPhysicsList: " << name 467 << " cannot be registered ---- hadronic Elastic Scattering List already existing" 468 << G4endl; 469 } 470 else 471 { 472 G4cout << "HadrontherapyPhysicsList::AddPhysicsList: " << name 473 << " is registered" << G4endl; 474 RegisterPhysics( new HEHadronIonBertiniElastic(name) ); 475 hadrElasticHadronIonIsRegistered = true; 476 } 477 } 478 479 480 // *** Option III: Process G4QElastic 481 482 if (name == "HadronicEl-HadronIon-QElastic") 483 { 484 if (hadrElasticHadronIonIsRegistered) 485 { 486 G4cout << "HadrontherapyPhysicsList::AddPhysicsList: " << name 487 << " cannot be registered ---- hadronic Elastic Scattering List already existing" 488 << G4endl; 489 } 490 else 491 { 492 G4cout << "HadrontherapyPhysicsList::AddPhysicsList: " << name 493 << " is registered" << G4endl; 494 RegisterPhysics( new HEHadronIonQElastic(name) ); 495 hadrElasticHadronIonIsRegistered = true; 496 } 497 } 498 499 500 // *** Option III: Process G4UHadronElasticProcess 501 502 if (name == "HadronicEl-HadronIon-UElastic") 503 { 504 if (hadrElasticHadronIonIsRegistered) 505 { 506 G4cout << "HadrontherapyPhysicsList::AddPhysicsList: " << name 507 << " cannot be registered ---- hadronic Elastic Scattering List already existing" 508 << G4endl; 509 } 510 else 511 { 512 G4cout << "HadrontherapyPhysicsList::AddPhysicsList: " << name 513 << " is registered" << G4endl; 514 RegisterPhysics( new HEHadronIonUElastic(name) ); 515 hadrElasticHadronIonIsRegistered = true; 516 } 517 } 518 519 520 // ******************************** 521 // *** C.2. INELASTIC PROCESSES *** 522 // ******************************** 523 524 525 // ************* 526 // *** Pions *** 527 // ************* 528 529 // *** Option I: Bertini model 530 531 if (name == "HadronicInel-Pion-Bertini") 532 { 533 if (hadrInelasticPionIsRegistered) 534 { 535 G4cout << "HadrontherapyPhysicsList::AddPhysicsList: " << name 536 << " cannot be registered ---- decay List already existing" 537 << G4endl; 538 } 539 else 540 { 541 G4cout << "HadrontherapyPhysicsList::AddPhysicsList: " << name 542 << " is registered" << G4endl; 543 RegisterPhysics( new HIPionBertini(name) ); 544 hadrInelasticPionIsRegistered = true; 545 } 546 } 547 548 549 // *** Option II: GHEISHA like LEP model 550 551 if (name == "HadronicInel-Pion-LEP") 552 { 553 if (hadrInelasticPionIsRegistered) 554 { 555 G4cout << "HadrontherapyPhysicsList::AddPhysicsList: " << name 556 << " cannot be registered ---- decay List already existing" 557 << G4endl; 558 } 559 else 560 { 561 G4cout << "HadrontherapyPhysicsList::AddPhysicsList: " << name 562 << " is registered" << G4endl; 563 RegisterPhysics( new HIPionLEP(name) ); 564 hadrInelasticPionIsRegistered = true; 565 } 566 } 567 568 569 // ************ 570 // *** Ions *** 571 // ************ 572 573 // *** Option I: GHEISHA like LEP model 574 575 if (name == "HadronicInel-Ion-LEP") 576 { 577 if (hadrInelasticIonIsRegistered) 578 { 579 G4cout << "HadrontherapyPhysicsList::AddPhysicsList: " << name 580 << " cannot be registered ---- decay List already existing" 581 << G4endl; 582 } 583 else 584 { 585 G4cout << "HadrontherapyPhysicsList::AddPhysicsList: " << name 586 << " is registered" << G4endl; 587 RegisterPhysics( new HIIonLEP(name) ); 588 hadrInelasticIonIsRegistered = true; 589 } 590 } 591 592 593 // ************************* 594 // *** Protons, Neutrons *** 595 // ************************* 596 597 // *** Option I: GHEISHA like LEP model 598 599 if (name == "HadronicInel-ProtonNeutron-LEP") 600 { 601 if (hadrInelasticProtonNeutronIsRegistered) 602 { 603 G4cout << "HadrontherapyPhysicsList::AddPhysicsList: " << name 604 << " cannot be registered ---- decay List already existing" 605 << G4endl; 606 } 607 else 608 { 609 G4cout << "HadrontherapyPhysicsList::AddPhysicsList: " << name 610 << " is registered" << G4endl; 611 RegisterPhysics( new HIProtonNeutronLEP(name) ); 612 hadrInelasticProtonNeutronIsRegistered = true; 613 } 614 } 615 616 617 // *** Option II: Bertini Cascade Model 618 619 if (name == "HadronicInel-ProtonNeutron-Bert") 620 { 621 if (hadrInelasticProtonNeutronIsRegistered) 622 { 623 G4cout << "HadrontherapyPhysicsList::AddPhysicsList: " << name 624 << " cannot be registered ---- decay List already existing" 625 << G4endl; 626 } 627 else 628 { 629 G4cout << "HadrontherapyPhysicsList::AddPhysicsList: " << name 630 << " is registered" << G4endl; 631 RegisterPhysics( new HIProtonNeutronBertini(name) ); 632 hadrInelasticProtonNeutronIsRegistered = true; 633 } 634 } 635 636 637 // *** Option III: Binary Cascade Model 638 639 if (name == "HadronicInel-ProtonNeutron-Bin") 640 { 641 if (hadrInelasticProtonNeutronIsRegistered) 642 { 643 G4cout << "HadrontherapyPhysicsList::AddPhysicsList: " << name 644 << " cannot be registered ---- decay List already existing" 645 << G4endl; 646 } 647 else 648 { 649 G4cout << "HadrontherapyPhysicsList::AddPhysicsList: " << name 650 << " is registered" << G4endl; 651 RegisterPhysics( new HIProtonNeutronBinary(name) ); 652 hadrInelasticProtonNeutronIsRegistered = true; 653 } 654 } 655 656 657 // *** Option IV: Precompound Model combined with Default Evaporation 658 659 if (name == "HadronicInel-ProtonNeutron-Prec") 660 { 661 if (hadrInelasticProtonNeutronIsRegistered) 662 { 663 G4cout << "HadrontherapyPhysicsList::AddPhysicsList: " << name 664 << " cannot be registered ---- decay List already existing" 665 << G4endl; 666 } 667 else 668 { 669 G4cout << "HadrontherapyPhysicsList::AddPhysicsList: " << name 670 << " is registered" << G4endl; 671 RegisterPhysics( new HIProtonNeutronPrecompound(name) ); 672 hadrInelasticProtonNeutronIsRegistered = true; 673 } 674 } 675 676 677 // *** Option V: Precompound Model combined with GEM Evaporation 678 679 if (name == "HadronicInel-ProtonNeutron-PrecGEM") 680 { 681 if (hadrInelasticProtonNeutronIsRegistered) 682 { 683 G4cout << "HadrontherapyPhysicsList::AddPhysicsList: " << name 684 << " cannot be registered ---- decay List already existing" 685 << G4endl; 686 } 687 else 688 { 689 G4cout << "HadrontherapyPhysicsList::AddPhysicsList: " << name 690 << " is registered" << G4endl; 691 RegisterPhysics( new HIProtonNeutronPrecompoundGEM(name) ); 692 hadrInelasticProtonNeutronIsRegistered = true; 693 } 694 } 695 696 697 // *** Option VI: Precompound Model combined with default Evaporation 698 // and Fermi Break-up model 699 700 if (name == "HadronicInel-ProtonNeutron-PrecFermi") 701 { 702 if (hadrInelasticProtonNeutronIsRegistered) 703 { 704 G4cout << "HadrontherapyPhysicsList::AddPhysicsList: " << name 705 << " cannot be registered ---- decay List already existing" 706 << G4endl; 707 } 708 else 709 { 710 G4cout << "HadrontherapyPhysicsList::AddPhysicsList: " << name 711 << " is registered" << G4endl; 712 RegisterPhysics( new HIProtonNeutronPrecompoundFermi(name) ); 713 hadrInelasticProtonNeutronIsRegistered = true; 714 } 715 } 716 717 718 // *** Option VII: Precompound Model combined with GEM Evaporation 719 // and Fermi Break-up model 720 721 if (name == "HadronicInel-ProtonNeutron-PrecGEMFermi") 722 { 723 if (hadrInelasticProtonNeutronIsRegistered) 724 { 725 G4cout << "HadrontherapyPhysicsList::AddPhysicsList: " << name 726 << " cannot be registered ---- decay List already existing" 727 << G4endl; 728 } 729 else 730 { 731 G4cout << "HadrontherapyPhysicsList::AddPhysicsList: " << name 732 << " is registered" << G4endl; 733 RegisterPhysics( new HIProtonNeutronPrecompoundGEMFermi(name) ); 734 hadrInelasticProtonNeutronIsRegistered = true; 735 } 736 } 737 738 739 // ****************************** 740 // *** C.3. AT-REST PROCESSES *** 741 // ****************************** 742 743 744 // ************** 745 // *** Muons- *** 746 // ************** 747 748 // *** Option I: Muon Minus Capture at Rest 749 750 if (name == "HadronicAtRest-MuonMinus-Capture") 751 { 752 if (hadrAtRestMuonIsRegistered) 753 { 754 G4cout << "HadrontherapyPhysicsList::AddPhysicsList: " << name 755 << " cannot be registered ---- decay List already existing" 756 << G4endl; 757 } 758 else 759 { 760 G4cout << "HadrontherapyPhysicsList::AddPhysicsList: " << name 761 << " is registered" << G4endl; 762 RegisterPhysics( new HRMuonMinusCapture(name) ); 763 hadrAtRestMuonIsRegistered = true; 764 } 765 } 766 767 } 768 200 201 if (verboseLevel>1) { 202 G4cout << "PhysicsList::AddPhysicsList: <" << name << ">" << G4endl; 203 } 204 if (name == emName) return; 205 206 ///////////////////////////////////////////////////////////////////////////// 207 // ELECTROMAGNETIC MODELS 208 ///////////////////////////////////////////////////////////////////////////// 209 210 if (name == "standard_opt3") { 211 emName = name; 212 delete emPhysicsList; 213 emPhysicsList = new G4EmStandardPhysics_option3(); 214 G4cout << "THE FOLLOWING ELECTROMAGNETIC PHYSICS LIST HAS BEEN ACTIVATED: G4EmStandardPhysics_option3" << G4endl; 215 216 } else if (name == "LowE_Livermore") { 217 emName = name; 218 delete emPhysicsList; 219 emPhysicsList = new G4EmLivermorePhysics(); 220 G4cout << "THE FOLLOWING ELECTROMAGNETIC PHYSICS LIST HAS BEEN ACTIVATED: G4EmLivermorePhysics" << G4endl; 221 222 } else if (name == "LowE_Penelope") { 223 emName = name; 224 delete emPhysicsList; 225 emPhysicsList = new G4EmPenelopePhysics(); 226 G4cout << "THE FOLLOWING ELECTROMAGNETIC PHYSICS LIST HAS BEEN ACTIVATED: G4EmLivermorePhysics" << G4endl; 227 228 ///////////////////////////////////////////////////////////////////////////// 229 // HADRONIC MODELS 230 ///////////////////////////////////////////////////////////////////////////// 231 } else if (name == "elastic" && !helIsRegisted) { 232 G4cout << "THE FOLLOWING HADRONIC ELASTIC PHYSICS LIST HAS BEEN ACTIVATED: G4HadronElasticPhysics()" << G4endl; 233 hadronPhys.push_back( new G4HadronElasticPhysics()); 234 helIsRegisted = true; 235 236 } else if (name == "DElastic" && !helIsRegisted) { 237 hadronPhys.push_back( new G4HadronDElasticPhysics()); 238 helIsRegisted = true; 239 240 } else if (name == "HElastic" && !helIsRegisted) { 241 hadronPhys.push_back( new G4HadronHElasticPhysics()); 242 helIsRegisted = true; 243 244 } else if (name == "QElastic" && !helIsRegisted) { 245 hadronPhys.push_back( new G4HadronQElasticPhysics()); 246 helIsRegisted = true; 247 248 } else if (name == "binary" && !bicIsRegisted) { 249 hadronPhys.push_back(new G4HadronInelasticQBBC()); 250 bicIsRegisted = true; 251 G4cout << "THE FOLLOWING HADRONIC INELASTIC PHYSICS LIST HAS BEEN ACTIVATED: G4HadronInelasticQBBC()" << G4endl; 252 253 } else if (name == "binary_ion" && !biciIsRegisted) { 254 hadronPhys.push_back(new G4IonBinaryCascadePhysics()); 255 biciIsRegisted = true; 256 257 } else if (name == "local_ion_ion_inelastic" && !locIonIonInelasticIsRegistered) { 258 hadronPhys.push_back(new LocalIonIonInelasticPhysic()); 259 locIonIonInelasticIsRegistered = true; 260 261 } else if (name == "local_incl_ion_ion_inelastic" && !locIonIonInelasticIsRegistered) { 262 hadronPhys.push_back(new LocalINCLIonIonInelasticPhysic()); 263 locIonIonInelasticIsRegistered = true; 264 265 } else if (name == "radioactive_decay" && !radioactiveDecayIsRegisted ) { 266 hadronPhys.push_back(new G4RadioactiveDecayPhysics()); 267 radioactiveDecayIsRegisted = true; 268 269 } else { 270 271 G4cout << "PhysicsList::AddPhysicsList: <" << name << ">" 272 << " is not defined" 273 << G4endl; 274 } 275 } 276 277 ///////////////////////////////////////////////////////////////////////////// 278 void HadrontherapyPhysicsList::AddStepMax() 279 { 280 // Step limitation seen as a process 281 stepMaxProcess = new HadrontherapyStepMax(); 282 283 theParticleIterator->reset(); 284 while ((*theParticleIterator)()){ 285 G4ParticleDefinition* particle = theParticleIterator->value(); 286 G4ProcessManager* pmanager = particle->GetProcessManager(); 287 288 if (stepMaxProcess->IsApplicable(*particle) && pmanager) 289 { 290 pmanager ->AddDiscreteProcess(stepMaxProcess); 291 } 292 } 293 } 294 295 ///////////////////////////////////////////////////////////////////////////// 769 296 void HadrontherapyPhysicsList::SetCuts() 770 { 771 // Set the threshold of production equal to the defaultCutValue 772 // in the experimental set-up 773 G4VUserPhysicsList::SetCutsWithDefault(); 774 775 G4double lowlimit=250*eV; 776 G4ProductionCutsTable::GetProductionCutsTable() ->SetEnergyRange(lowlimit, 100.*GeV); 777 // Definition of a smaller threshold of production in the phantom region 778 // where high accuracy is required in the energy deposit calculation 779 780 G4String regionName = "PhantomLog"; 781 G4Region* region = G4RegionStore::GetInstance()->GetRegion(regionName); 782 G4ProductionCuts* cuts = new G4ProductionCuts ; 783 G4double regionCut = 0.01*mm; 784 cuts -> SetProductionCut(regionCut,G4ProductionCuts::GetIndex("gamma")); 785 cuts -> SetProductionCut(regionCut,G4ProductionCuts::GetIndex("e-")); 786 cuts -> SetProductionCut(regionCut,G4ProductionCuts::GetIndex("e+")); 787 cuts -> SetProductionCut(regionCut,G4ProductionCuts::GetIndex("proton")); 788 cuts -> SetProductionCut(regionCut,G4ProductionCuts::GetIndex("genericIons")); 789 region -> SetProductionCuts(cuts); 297 { 298 299 if (verboseLevel >0){ 300 G4cout << "PhysicsList::SetCuts:"; 301 G4cout << "CutLength : " << G4BestUnit(defaultCutValue,"Length") << G4endl; 302 } 303 304 // set cut values for gamma at first and for e- second and next for e+, 305 // because some processes for e+/e- need cut values for gamma 306 SetCutValue(cutForGamma, "gamma"); 307 SetCutValue(cutForElectron, "e-"); 308 SetCutValue(cutForPositron, "e+"); 790 309 791 310 if (verboseLevel>0) DumpCutValuesTable(); 792 311 } 793 312 794 313 ///////////////////////////////////////////////////////////////////////////// 314 void HadrontherapyPhysicsList::SetCutForGamma(G4double cut) 315 { 316 cutForGamma = cut; 317 SetParticleCuts(cutForGamma, G4Gamma::Gamma()); 318 } 319 320 ///////////////////////////////////////////////////////////////////////////// 321 void HadrontherapyPhysicsList::SetCutForElectron(G4double cut) 322 { 323 cutForElectron = cut; 324 SetParticleCuts(cutForElectron, G4Electron::Electron()); 325 } 326 327 ///////////////////////////////////////////////////////////////////////////// 328 void HadrontherapyPhysicsList::SetCutForPositron(G4double cut) 329 { 330 cutForPositron = cut; 331 SetParticleCuts(cutForPositron, G4Positron::Positron()); 332 } -
trunk/examples/advanced/hadrontherapy/src/HadrontherapyPhysicsListMessenger.cc
r807 r1230 24 24 // ******************************************************************** 25 25 // 26 // $Id: HadrontherapyPhisicsListMessenger.cc; May 2005 27 // ---------------------------------------------------------------------------- 28 // GEANT 4 - Hadrontherapy example 29 // ---------------------------------------------------------------------------- 30 // Code developed by: 31 // 32 // G.A.P. Cirrone(a)*, F. Di Rosa(a), S. Guatelli(b), G. Russo(a) 33 // 34 // (a) Laboratori Nazionali del Sud 35 // of the National Institute for Nuclear Physics, Catania, Italy 36 // (b) National Institute for Nuclear Physics Section of Genova, genova, Italy 37 // 38 // * cirrone@lns.infn.it 39 // ---------------------------------------------------------------------------- 26 // HadrontherapyPhysicsListMessenger.cc 27 // See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy 28 40 29 #include "HadrontherapyPhysicsListMessenger.hh" 30 41 31 #include "HadrontherapyPhysicsList.hh" 42 32 #include "G4UIdirectory.hh" 43 #include "G4UIcmdWithoutParameter.hh"44 #include "G4UIcmdWithADouble.hh"45 33 #include "G4UIcmdWithADoubleAndUnit.hh" 46 #include "G4UIcmdWithABool.hh"47 34 #include "G4UIcmdWithAString.hh" 48 35 49 HadrontherapyPhysicsListMessenger::HadrontherapyPhysicsListMessenger(HadrontherapyPhysicsList * physList) 50 :physicsList(physList) 51 { 52 listDir = new G4UIdirectory("/physics/"); 53 // Building modular PhysicsList 36 ///////////////////////////////////////////////////////////////////////////// 37 HadrontherapyPhysicsListMessenger::HadrontherapyPhysicsListMessenger(HadrontherapyPhysicsList* pPhys) 38 :pPhysicsList(pPhys) 39 { 40 physDir = new G4UIdirectory("/physic/"); 41 physDir->SetGuidance("Commands to activate physics models and set cuts"); 42 43 gammaCutCmd = new G4UIcmdWithADoubleAndUnit("/physic/setGCut",this); 44 gammaCutCmd->SetGuidance("Set gamma cut."); 45 gammaCutCmd->SetParameterName("Gcut",false); 46 gammaCutCmd->SetUnitCategory("Length"); 47 gammaCutCmd->SetRange("Gcut>0.0"); 48 gammaCutCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 54 49 55 physicsListCmd = new G4UIcmdWithAString("/physics/addPhysics",this); 56 physicsListCmd->SetGuidance("Add chunks of PhysicsList."); 57 physicsListCmd->SetParameterName("physList",false); 58 physicsListCmd->AvailableForStates(G4State_PreInit); 50 electCutCmd = new G4UIcmdWithADoubleAndUnit("/physic/setECut",this); 51 electCutCmd->SetGuidance("Set electron cut."); 52 electCutCmd->SetParameterName("Ecut",false); 53 electCutCmd->SetUnitCategory("Length"); 54 electCutCmd->SetRange("Ecut>0.0"); 55 electCutCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 56 57 protoCutCmd = new G4UIcmdWithADoubleAndUnit("/physic/setPCut",this); 58 protoCutCmd->SetGuidance("Set positron cut."); 59 protoCutCmd->SetParameterName("Pcut",false); 60 protoCutCmd->SetUnitCategory("Length"); 61 protoCutCmd->SetRange("Pcut>0.0"); 62 protoCutCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 63 64 allCutCmd = new G4UIcmdWithADoubleAndUnit("/physic/setCuts",this); 65 allCutCmd->SetGuidance("Set cut for all."); 66 allCutCmd->SetParameterName("cut",false); 67 allCutCmd->SetUnitCategory("Length"); 68 allCutCmd->SetRange("cut>0.0"); 69 allCutCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 70 71 pListCmd = new G4UIcmdWithAString("/physic/addPhysics",this); 72 pListCmd->SetGuidance("Add physics list."); 73 pListCmd->SetParameterName("PList",false); 74 pListCmd->AvailableForStates(G4State_PreInit); 75 76 packageListCmd = new G4UIcmdWithAString("/physic/addPackage",this); 77 packageListCmd->SetGuidance("Add physics package."); 78 packageListCmd->SetParameterName("package",false); 79 packageListCmd->AvailableForStates(G4State_PreInit); 59 80 } 60 81 82 ///////////////////////////////////////////////////////////////////////////// 61 83 HadrontherapyPhysicsListMessenger::~HadrontherapyPhysicsListMessenger() 62 84 { 63 delete physicsListCmd; 64 delete listDir; 85 delete gammaCutCmd; 86 delete electCutCmd; 87 delete protoCutCmd; 88 delete allCutCmd; 89 delete pListCmd; 90 delete physDir; 91 delete packageListCmd; 65 92 } 66 93 67 void HadrontherapyPhysicsListMessenger::SetNewValue(G4UIcommand* command,G4String newValue) 68 { 69 if (command == physicsListCmd) 70 { physicsList->AddPhysicsList(newValue);} 71 } 94 ///////////////////////////////////////////////////////////////////////////// 95 void HadrontherapyPhysicsListMessenger::SetNewValue(G4UIcommand* command, 96 G4String newValue) 97 { 98 if( command == gammaCutCmd ) 99 { pPhysicsList->SetCutForGamma(gammaCutCmd->GetNewDoubleValue(newValue));} 100 101 if( command == electCutCmd ) 102 { pPhysicsList->SetCutForElectron(electCutCmd->GetNewDoubleValue(newValue));} 103 104 if( command == protoCutCmd ) 105 { pPhysicsList->SetCutForPositron(protoCutCmd->GetNewDoubleValue(newValue));} 106 107 if( command == allCutCmd ) 108 { 109 G4double cut = allCutCmd->GetNewDoubleValue(newValue); 110 pPhysicsList->SetCutForGamma(cut); 111 pPhysicsList->SetCutForElectron(cut); 112 pPhysicsList->SetCutForPositron(cut); 113 } 114 115 if( command == pListCmd ) 116 { pPhysicsList->AddPhysicsList(newValue);} 72 117 73 118 119 if( command == packageListCmd ) 120 { pPhysicsList->AddPackage(newValue);} 74 121 75 122 76 77 123 } -
trunk/examples/advanced/hadrontherapy/src/HadrontherapyPrimaryGeneratorAction.cc
r807 r1230 24 24 // ******************************************************************** 25 25 // 26 // $Id: HadrontherapyPositronPrimaryGeneratorAction.cc; May 2005 26 // HadrontherapyPrimarygeneratorAction.cc; 27 // See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy 27 28 // ---------------------------------------------------------------------------- 28 29 // GEANT 4 - Hadrontherapy example … … 30 31 // Code developed by: 31 32 // 32 // G.A.P. Cirrone(a)*, F. Di Rosa(a), S. Guatelli(b), G. Russo(a)33 // G.A.P. Cirrone(a)*, F.Romano(a) 33 34 // 34 35 // (a) Laboratori Nazionali del Sud 35 // of the National Institute for Nuclear Physics, Catania, Italy 36 // (b) National Institute for Nuclear Physics Section of Genova, genova, Italy 36 // of the INFN, Catania, Italy 37 37 // 38 38 // * cirrone@lns.infn.it 39 // ---------------------------------------------------------------------------- 39 // 40 // ------------------------------------------------------------------------------ 41 40 42 #include "HadrontherapyPrimaryGeneratorAction.hh" 41 43 #include "HadrontherapyPrimaryGeneratorMessenger.hh" … … 45 47 #include "G4ParticleDefinition.hh" 46 48 #include "Randomize.hh" 49 #include "HadrontherapyAnalysisManager.hh" 47 50 48 51 HadrontherapyPrimaryGeneratorAction::HadrontherapyPrimaryGeneratorAction() … … 75 78 76 79 // Define the energy of primary particles: 77 // gaussian distribution with mean energy = 6 4.55*MeV78 // and sigma = 300.0 *keV79 G4double defaultMeanKineticEnergy = 6 3.50 *MeV;80 // gaussian distribution with mean energy = 62.0 *MeV 81 // and sigma = 400.0 *keV 82 G4double defaultMeanKineticEnergy = 62.0 *MeV; 80 83 meanKineticEnergy = defaultMeanKineticEnergy; 81 84 82 G4double defaultsigmaEnergy = 300.0 *keV;85 G4double defaultsigmaEnergy = 400.0 *keV; 83 86 sigmaEnergy = defaultsigmaEnergy; 87 88 #ifdef ANALYSIS_USE 89 // Write these values into the analysis if needed. Have to be written separately on change. 90 HadrontherapyAnalysisManager::getInstance()->setBeamMetaData(meanKineticEnergy, sigmaEnergy); 91 #endif 84 92 85 93 // Define the parameters of the initial position: 86 94 // the y, z coordinates have a gaussian distribution 87 G4double defaultX0 = -3248.59 *mm; 95 96 G4double defaultX0 = -2700.0 *mm; 88 97 X0 = defaultX0; 89 98 … … 111 120 void HadrontherapyPrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent) 112 121 { 122 #ifdef ANALYSIS_USE 123 // Increment the event counter 124 HadrontherapyAnalysisManager::getInstance()->startNewEvent(); 125 #endif 126 113 127 // **************************************** 114 128 // Set the beam angular apread … … 162 176 163 177 void HadrontherapyPrimaryGeneratorAction::SetmeanKineticEnergy (G4double val ) 164 { meanKineticEnergy = val;} 178 { 179 meanKineticEnergy = val; 180 #ifdef ANALYSIS_USE 181 // Update the beam-data in the analysis manager 182 HadrontherapyAnalysisManager::getInstance()->setBeamMetaData(meanKineticEnergy, sigmaEnergy); 183 #endif 184 185 } 165 186 166 187 void HadrontherapyPrimaryGeneratorAction::SetsigmaEnergy (G4double val ) 167 { sigmaEnergy = val;} 188 { 189 sigmaEnergy = val; 190 #ifdef ANALYSIS_USE 191 // Update the sigmaenergy in the metadata. 192 HadrontherapyAnalysisManager::getInstance()->setBeamMetaData(meanKineticEnergy, sigmaEnergy); 193 #endif 194 } 168 195 169 196 void HadrontherapyPrimaryGeneratorAction::SetXposition (G4double val ) … … 187 214 void HadrontherapyPrimaryGeneratorAction::SetsigmaMomentumZ (G4double val ) 188 215 { sigmaMomentumZ = val;} 216 217 G4double HadrontherapyPrimaryGeneratorAction::GetmeanKineticEnergy(void) 218 { return meanKineticEnergy;} -
trunk/examples/advanced/hadrontherapy/src/HadrontherapyPrimaryGeneratorMessenger.cc
r807 r1230 24 24 // ******************************************************************** 25 25 // 26 // $Id: HadrontherapyPrimaryGeneratorMessenger.cc; May 2005 27 // ---------------------------------------------------------------------------- 28 // GEANT 4 - Hadrontherapy example 29 // ---------------------------------------------------------------------------- 30 // Code developed by: 31 // 32 // G.A.P. Cirrone(a)*, F. Di Rosa(a), S. Guatelli(b), G. Russo(a) 33 // 34 // (a) Laboratori Nazionali del Sud 35 // of the National Institute for Nuclear Physics, Catania, Italy 36 // (b) National Institute for Nuclear Physics Section of Genova, genova, Italy 37 // 38 // * cirrone@lns.infn.it 39 // ---------------------------------------------------------------------------- 26 // HadrontherapyPrimaryGeneratorMessenger.cc; 27 // See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy 40 28 41 29 #include "HadrontherapyPrimaryGeneratorMessenger.hh" -
trunk/examples/advanced/hadrontherapy/src/HadrontherapyRunAction.cc
r807 r1230 24 24 // ******************************************************************** 25 25 // 26 // $Id: HadrontherapyRunAction.cc,v 3.0, September 2004; 27 // ---------------------------------------------------------------------------- 28 // GEANT 4 - Hadrontherapy example 29 // ---------------------------------------------------------------------------- 30 // Code developed by: 31 // 32 // G.A.P. Cirrone(a)*, F. Di Rosa(a), S. Guatelli(b), G. Russo(a) 33 // 34 // (a) Laboratori Nazionali del Sud 35 // of the INFN, Catania, Italy 36 // (b) INFN Section of Genova, Genova, Italy 37 // 38 // * cirrone@lns.infn.it 39 // ---------------------------------------------------------------------------- 26 // $Id: HadrontherapyRunAction.cc 27 // See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy 40 28 41 29 #include "HadrontherapyRunAction.hh" -
trunk/examples/advanced/hadrontherapy/src/HadrontherapySteppingAction.cc
r807 r1230 24 24 // ******************************************************************** 25 25 // 26 // $Id: HadrontherapyProtonSteppingAction.cc; May 2005 27 // ---------------------------------------------------------------------------- 28 // GEANT 4 - Hadrontherapy example 29 // ---------------------------------------------------------------------------- 30 // Code developed by: 31 // 32 // G.A.P. Cirrone(a)*, F. Di Rosa(a), S. Guatelli(b), G. Russo(a) 33 // 34 // (a) Laboratori Nazionali del Sud 35 // of the INFN, Catania, Italy 36 // (b) INFN Section of Genova, Genova, Italy 37 // 38 // * cirrone@lns.infn.it 39 // ---------------------------------------------------------------------------- 26 // HadrontherapyProtonSteppingAction.cc; 27 // See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy 40 28 41 29 #include "G4SteppingManager.hh" … … 52 40 #include "G4ParticleTypes.hh" 53 41 54 #ifdef G4ANALYSIS_USE55 42 #include "HadrontherapyAnalysisManager.hh" 56 #endif57 43 58 44 #include "HadrontherapyRunAction.hh" 59 45 60 HadrontherapySteppingAction::HadrontherapySteppingAction( HadrontherapyRunAction* run) 46 ///////////////////////////////////////////////////////////////////////////// 47 HadrontherapySteppingAction::HadrontherapySteppingAction( HadrontherapyRunAction *run) 61 48 { 62 49 runAction = run; 63 50 } 64 51 52 ///////////////////////////////////////////////////////////////////////////// 65 53 HadrontherapySteppingAction::~HadrontherapySteppingAction() 66 54 { 67 55 } 68 56 57 ///////////////////////////////////////////////////////////////////////////// 69 58 void HadrontherapySteppingAction::UserSteppingAction(const G4Step* aStep) 70 59 { 60 if( aStep->GetTrack()->GetVolume()->GetName() == "NewDetectorPhys"){ 61 #ifdef ANALYSIS_USE 62 G4ParticleDefinition *def = aStep->GetTrack()->GetDefinition(); 63 G4double secondaryParticleKineticEnergy = aStep->GetTrack()->GetKineticEnergy(); 64 G4String particleType = def->GetParticleType(); // particle type = nucleus for d, t, He3, alpha, and heavier nuclei 65 G4String particleName = def->GetParticleName(); // e.g. for alpha: the name = "alpha" and type = "nucleus" 66 if(particleType == "nucleus") { 67 G4int A = def->GetBaryonNumber(); 68 G4double Z = def->GetPDGCharge(); 69 G4double posX = aStep->GetTrack()->GetPosition().x() / cm; 70 G4double posY = aStep->GetTrack()->GetPosition().y() / cm; 71 G4double posZ = aStep->GetTrack()->GetPosition().z() / cm; 72 G4double energy = secondaryParticleKineticEnergy / A / MeV; 73 74 HadrontherapyAnalysisManager* analysisMgr = HadrontherapyAnalysisManager::getInstance(); 75 analysisMgr->fillFragmentTuple(A, Z, energy, posX, posY, posZ); 76 } else if(particleName == "proton") { // proton (hydrogen-1) is a special case 77 G4double posX = aStep->GetTrack()->GetPosition().x() / cm ; 78 G4double posY = aStep->GetTrack()->GetPosition().y() / cm ; 79 G4double posZ = aStep->GetTrack()->GetPosition().z() / cm ; 80 G4double energy = secondaryParticleKineticEnergy * MeV; // Hydrogen-1: A = 1, Z = 1 81 HadrontherapyAnalysisManager::getInstance()->fillFragmentTuple(1, 1.0, energy, posX, posY, posZ); 82 } 83 84 G4String secondaryParticleName = def -> GetParticleName(); 85 //G4cout <<"Particle: " << secondaryParticleName << G4endl; 86 //G4cout <<"Energy: " << secondaryParticleKineticEnergy << G4endl; 87 HadrontherapyAnalysisManager* analysis = HadrontherapyAnalysisManager::getInstance(); 88 //There is a bunch of stuff recorded with the energy 0, something should perhaps be done about this. 89 if(secondaryParticleName == "proton") { 90 analysis->hydrogenEnergy(secondaryParticleKineticEnergy / MeV); 91 } 92 if(secondaryParticleName == "deuteron") { 93 analysis->hydrogenEnergy((secondaryParticleKineticEnergy/2) / MeV); 94 } 95 if(secondaryParticleName == "triton") { 96 analysis->hydrogenEnergy((secondaryParticleKineticEnergy/3) / MeV); 97 } 98 if(secondaryParticleName == "alpha") { 99 analysis->heliumEnergy((secondaryParticleKineticEnergy/4) / MeV); 100 } 101 if(secondaryParticleName == "He3"){ 102 analysis->heliumEnergy((secondaryParticleKineticEnergy/3) / MeV); 103 } 104 #endif 105 106 aStep->GetTrack()->SetTrackStatus(fKillTrackAndSecondaries); 107 } 108 71 109 // Electromagnetic and hadronic processes of primary particles in the phantom 72 73 if ((aStep -> GetTrack() -> GetTrackID() == 1) &&110 //setting phantomPhys correctly will break something here fixme 111 if ((aStep -> GetTrack() -> GetTrackID() == 1) && 74 112 (aStep -> GetTrack() -> GetVolume() -> GetName() == "PhantomPhys") && 75 113 (aStep -> GetPostStepPoint() -> GetProcessDefinedStep() != NULL)) … … 96 134 // Retrieve information about the secondaries originated in the phantom 97 135 98 #ifdef G4ANALYSIS_USE 99 G4SteppingManager* steppingManager = fpSteppingManager; 100 G4Track* theTrack = aStep -> GetTrack(); 101 136 G4SteppingManager* steppingManager = fpSteppingManager; 137 102 138 // check if it is alive 103 if(theTrack-> GetTrackStatus() == fAlive) { return; }139 //if(theTrack-> GetTrackStatus() == fAlive) { return; } 104 140 105 141 // Retrieve the secondary particles … … 110 146 G4String volumeName = (*fSecondary)[lp1] -> GetVolume() -> GetName(); 111 147 112 if (volumeName == " PhantomPhys")148 if (volumeName == "phantomPhys") 113 149 { 150 #ifdef ANALYSIS_USE 114 151 G4String secondaryParticleName = (*fSecondary)[lp1]->GetDefinition() -> GetParticleName(); 115 152 G4double secondaryParticleKineticEnergy = (*fSecondary)[lp1] -> GetKineticEnergy(); 116 153 117 154 HadrontherapyAnalysisManager* analysis = HadrontherapyAnalysisManager::getInstance(); 118 155 … … 137 174 G4int a = (*fSecondary)[lp1]-> GetDynamicParticle() -> GetDefinition() -> GetBaryonNumber(); 138 175 G4int electronOccupancy = (*fSecondary)[lp1] -> GetDynamicParticle() -> GetTotalOccupancy(); 139 // If a generic ion is originated in the phantom, its baryonic number, PDG charge, 176 177 // If a generic ion is originated in the detector, its baryonic number, PDG charge, 140 178 // total number of electrons in the orbitals are stored in a ntuple 141 analysis -> genericIonInformation(a, z, electronOccupancy, secondaryParticleKineticEnergy/MeV); 179 analysis -> genericIonInformation(a, z, electronOccupancy, secondaryParticleKineticEnergy/MeV); 142 180 } 181 #endif 143 182 } 144 183 } 145 #endif146 184 } 147 185
Note: See TracChangeset
for help on using the changeset viewer.