Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 /* << 25 // 26 Author: Susanna Guatelli, University of Wollon << 26 // 27 */ << 27 // Authors: S. Guatelli and M. G. Pia, INFN Genova, Italy 28 // The class G4HumanPhantomAnalysisManager cre << 28 // 29 << 29 // Based on code developed by the undergraduate student G. Guerrieri 30 // The analysis was included in this applicati << 30 // Note: this is a preliminary beta-version of the code; an improved 31 // example analysis/AnaEx01 << 31 // version will be distributed in the next Geant4 public release, compliant 32 << 32 // with the design in a forthcoming publication, and subject to a >> 33 // design and code review. >> 34 // >> 35 #ifdef G4ANALYSIS_USE >> 36 #include <stdlib.h> >> 37 #include <fstream> 33 #include "G4HumanPhantomAnalysisManager.hh" 38 #include "G4HumanPhantomAnalysisManager.hh" 34 #include "G4UnitsTable.hh" << 39 #include "G4ios.hh" 35 #include "G4SystemOfUnits.hh" << 40 #include <AIDA/AIDA.h> >> 41 #include "G4RunManager.hh" >> 42 >> 43 G4HumanPhantomAnalysisManager* G4HumanPhantomAnalysisManager::instance = 0; >> 44 >> 45 G4HumanPhantomAnalysisManager::G4HumanPhantomAnalysisManager() >> 46 : aFact(0), treeFact(0),theTree(0), histogramFactory(0), >> 47 histogramParticlePath(0), projectionXY(0), projectionYZ(0), >> 48 projectionZX(0), energy(0), innerBreast(0) >> 49 { >> 50 aFact = AIDA_createAnalysisFactory(); >> 51 treeFact = aFact -> createTreeFactory(); >> 52 } 36 53 37 G4HumanPhantomAnalysisManager::G4HumanPhantomA << 54 G4HumanPhantomAnalysisManager::~G4HumanPhantomAnalysisManager() 38 { 55 { 39 fFactoryOn = false; << 56 delete innerBreast; >> 57 innerBreast = 0; 40 58 41 // Initialization ntuple << 59 delete energy; 42 for (G4int k=0; k<MaxNtCol; k++) { << 60 energy = 0; 43 fNtColId[k] = 0; << 44 } << 45 } << 46 61 47 void G4HumanPhantomAnalysisManager::book() << 62 delete projectionXY; 48 { << 63 projectionXY = 0; 49 G4AnalysisManager* analysisManager = G4Analy << 50 << 51 analysisManager->SetVerboseLevel(2); << 52 << 53 // Create a root file << 54 G4String fileName = "human_phantom.root"; << 55 64 56 // Create directories << 65 delete projectionYZ; 57 analysisManager->SetNtupleDirectoryName("hum << 66 projectionYZ = 0; 58 << 59 G4bool fileOpen = analysisManager->OpenFile( << 60 if (!fileOpen) { << 61 G4cout << "\n---> HistoManager::book(): ca << 62 << fileName << 63 << G4endl; << 64 return; << 65 } << 66 << 67 //creating a ntuple, containg 3D energy depo << 68 analysisManager->SetFirstNtupleId(1); << 69 analysisManager->CreateNtuple("1", "3Dedep") << 70 fNtColId[0] = analysisManager->CreateNtupleD << 71 fNtColId[1] = analysisManager->CreateNtupleD << 72 67 73 analysisManager->FinishNtuple(); << 68 delete projectionZX; >> 69 projectionZX = 0; >> 70 >> 71 delete histogramParticlePath; >> 72 histogramParticlePath = 0; 74 73 75 fFactoryOn = true; << 74 delete histogramFactory; >> 75 histogramFactory = 0; >> 76 >> 77 delete treeFact; >> 78 treeFact = 0; >> 79 >> 80 delete theTree; >> 81 theTree = 0; >> 82 >> 83 delete aFact; >> 84 aFact = 0; 76 } 85 } 77 86 78 void G4HumanPhantomAnalysisManager::FillNtuple << 87 G4HumanPhantomAnalysisManager* G4HumanPhantomAnalysisManager::getInstance() 79 { 88 { 80 if (energyDep !=0) << 89 if (instance == 0) instance = new G4HumanPhantomAnalysisManager; 81 { << 90 return instance; 82 G4AnalysisManager* analysisManager = G4Analy << 83 analysisManager->FillNtupleDColumn(1, fNtCol << 84 analysisManager->FillNtupleDColumn(1, fNtCol << 85 analysisManager->AddNtupleRow(1); << 86 G4cout << "Analysis: organ " << organ << " e << 87 } 91 } 88 } << 89 92 90 void G4HumanPhantomAnalysisManager::save() << 93 void G4HumanPhantomAnalysisManager::book() 91 { << 94 { 92 if (fFactoryOn) << 95 G4String fileName = "G4HumanPhantom.hbk"; 93 { << 96 theTree = treeFact->create(fileName,"hbook",false, true); 94 G4AnalysisManager* analysisManager = G4Ana << 97 95 analysisManager->Write(); << 98 histogramFactory = aFact -> createHistogramFactory( *theTree ); 96 analysisManager->CloseFile(); << 99 97 analysisManager->Clear(); << 100 G4double histogramDimension = 20.; 98 fFactoryOn = false; << 99 } << 100 } << 101 101 >> 102 G4int bins = 3600; 102 103 >> 104 G4int binsProj = 300; 103 105 >> 106 histogramParticlePath = histogramFactory->createHistogram1D >> 107 ("10","Particle Path Distribution",bins,0.,histogramDimension); 104 108 >> 109 projectionXY = histogramFactory->createHistogram2D >> 110 ("20","Particle Projection XY",binsProj,-histogramDimension,histogramDimension,binsProj,-histogramDimension,histogramDimension); 105 111 >> 112 projectionYZ = histogramFactory->createHistogram2D >> 113 ("30","Particle Projection YZ",binsProj,-histogramDimension,histogramDimension,binsProj,-histogramDimension,histogramDimension); 106 114 >> 115 projectionZX = histogramFactory->createHistogram2D >> 116 ("40","Particle Projection ZX",binsProj,-histogramDimension,histogramDimension,binsProj,-histogramDimension,histogramDimension); 107 117 >> 118 energy = histogramFactory->createHistogram2D >> 119 ("50","Energy Deposit in Body Part", 1000,0.,30.,500,0.,100.); 108 120 >> 121 innerBreast = histogramFactory->createHistogram2D("100", "Edep(MeV) in innerBreast, x= slice, y= sector", >> 122 11, -0.5, 10.5, >> 123 11, -0.5, 10.5); 109 124 >> 125 G4cout<<"Booking the histograms"<<G4endl; 110 126 >> 127 } 111 128 >> 129 void G4HumanPhantomAnalysisManager::particlePath(G4double path) >> 130 { >> 131 histogramParticlePath -> fill(path); >> 132 } >> 133 >> 134 void G4HumanPhantomAnalysisManager::particleProjectionXY(G4double xx,G4double yy) >> 135 { >> 136 projectionXY -> fill(xx,yy,1.); >> 137 } >> 138 >> 139 void G4HumanPhantomAnalysisManager::particleProjectionYZ(G4double yy,G4double zz) >> 140 { >> 141 projectionYZ -> fill(yy,zz,1.); >> 142 } >> 143 >> 144 void G4HumanPhantomAnalysisManager::particleProjectionZX(G4double zz,G4double xx) >> 145 { >> 146 projectionZX -> fill(zz,xx,1.); >> 147 } 112 148 >> 149 void G4HumanPhantomAnalysisManager::bodypartEnergyDep(G4double bpID, G4double eDep) >> 150 { >> 151 energy -> fill(bpID,eDep); >> 152 } >> 153 >> 154 void G4HumanPhantomAnalysisManager::innerBreastEnergyDep(G4int slice, G4int sector, G4double edep) >> 155 { >> 156 // G4cout << "analisis " << slice << " "<< sector << " "<< edep << G4endl; >> 157 innerBreast -> fill(slice,sector, edep); >> 158 } >> 159 >> 160 void G4HumanPhantomAnalysisManager::finish() >> 161 { >> 162 theTree -> commit(); >> 163 theTree -> close(); >> 164 G4cout<<"closing the hbk file"<<G4endl; >> 165 } >> 166 #endif 113 167