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),tupFact(0), >> 47 ntuple(0), voxelLeftBreast(0), voxelRightBreast(0) >> 48 { >> 49 aFact = AIDA_createAnalysisFactory(); >> 50 treeFact = aFact -> createTreeFactory(); >> 51 } 36 52 37 G4HumanPhantomAnalysisManager::G4HumanPhantomA << 53 G4HumanPhantomAnalysisManager::~G4HumanPhantomAnalysisManager() 38 { 54 { 39 fFactoryOn = false; << 55 delete voxelRightBreast; >> 56 voxelRightBreast = 0; 40 57 41 // Initialization ntuple << 58 delete voxelLeftBreast; 42 for (G4int k=0; k<MaxNtCol; k++) { << 59 voxelLeftBreast = 0; 43 fNtColId[k] = 0; << 44 } << 45 } << 46 60 47 void G4HumanPhantomAnalysisManager::book() << 61 delete ntuple; 48 { << 62 ntuple = 0; 49 G4AnalysisManager* analysisManager = G4Analy << 50 63 51 analysisManager->SetVerboseLevel(2); << 64 delete tupFact; 52 << 65 tupFact =0; 53 // Create a root file << 54 G4String fileName = "human_phantom.root"; << 55 66 56 // Create directories << 67 delete histogramFactory; 57 analysisManager->SetNtupleDirectoryName("hum << 68 histogramFactory = 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 69 73 analysisManager->FinishNtuple(); << 70 delete treeFact; 74 << 71 treeFact = 0; 75 fFactoryOn = true; << 76 } << 77 72 78 void G4HumanPhantomAnalysisManager::FillNtuple << 73 delete theTree; 79 { << 74 theTree = 0; 80 if (energyDep !=0) << 81 { << 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 } << 88 } << 89 75 90 void G4HumanPhantomAnalysisManager::save() << 76 delete aFact; 91 { << 77 aFact = 0; 92 if (fFactoryOn) << 93 { << 94 G4AnalysisManager* analysisManager = G4Ana << 95 analysisManager->Write(); << 96 analysisManager->CloseFile(); << 97 analysisManager->Clear(); << 98 fFactoryOn = false; << 99 } << 100 } 78 } 101 79 >> 80 G4HumanPhantomAnalysisManager* G4HumanPhantomAnalysisManager::getInstance() >> 81 { >> 82 if (instance == 0) instance = new G4HumanPhantomAnalysisManager; >> 83 return instance; >> 84 } 102 85 >> 86 void G4HumanPhantomAnalysisManager::book() >> 87 { >> 88 G4String fileName = "G4HumanPhantom.hbk"; >> 89 theTree = treeFact->create(fileName,"hbook",false, true); >> 90 >> 91 histogramFactory = aFact -> createHistogramFactory( *theTree ); >> 92 tupFact = aFact -> createTupleFactory( *theTree ); >> 93 >> 94 >> 95 voxelLeftBreast = histogramFactory->createHistogram2D("100", >> 96 "Edep(MeV) in LeftBreast, x= slice, y= sector", >> 97 10, -0.5, 9.5, >> 98 10, -0.5, 9.5); >> 99 >> 100 voxelRightBreast = histogramFactory->createHistogram2D("110", >> 101 "Edep(MeV) in RightBreast, x= slice, y= sector", >> 102 10, -0.5, 9.5, >> 103 10, -0.5, 9.5); 103 104 >> 105 >> 106 // Defining the ntuple columns' name >> 107 std::string columnNames = "int id; float energy"; >> 108 std::string options = ""; >> 109 >> 110 // Creating a ntuple >> 111 if (tupFact) ntuple = tupFact -> create("1","1",columnNames, options); >> 112 >> 113 G4cout<<"Booking !!!!"<<G4endl; >> 114 } 104 115 >> 116 void G4HumanPhantomAnalysisManager::bodyPartEnergyDeposit(G4int bodyPartID, >> 117 G4double eDep) >> 118 { >> 119 if (ntuple == 0) >> 120 { >> 121 G4cout << "AAAAAAAGH..... The Ntuple is 0" << G4endl; >> 122 return; >> 123 } >> 124 >> 125 // Fill the ntuple >> 126 >> 127 // Each organ is identified with an integer >> 128 G4int indexX = ntuple -> findColumn( "id" ); >> 129 G4int indexEnergy = ntuple -> findColumn( "energy" ); 105 130 >> 131 ntuple -> fill(indexX, bodyPartID); >> 132 ntuple -> fill(indexEnergy, eDep); 106 133 >> 134 ntuple->addRow(); >> 135 } 107 136 >> 137 void G4HumanPhantomAnalysisManager::voxelLeftBreastEnergyDeposit(G4int slice, G4int sector, G4double edep) >> 138 { >> 139 // G4cout << "analisis " << slice << " "<< sector << " "<< edep/MeV << G4endl; >> 140 voxelLeftBreast -> fill(slice,sector, edep); >> 141 } 108 142 >> 143 void G4HumanPhantomAnalysisManager::voxelRightBreastEnergyDeposit(G4int slice, G4int sector, G4double edep) >> 144 { >> 145 //G4cout << "analisis " << slice << " "<< sector << " "<< edep/MeV << G4endl; >> 146 voxelRightBreast -> fill(slice,sector, edep); >> 147 } 109 148 110 << 149 void G4HumanPhantomAnalysisManager::finish() 111 << 150 { 112 << 151 theTree -> commit(); >> 152 theTree -> close(); >> 153 G4cout<<"closing the hbk file"<<G4endl; >> 154 } >> 155 #endif 113 156