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 /// \file medical/GammaTherapy/src/HistoManage 26 /// \file medical/GammaTherapy/src/HistoManager.cc 27 /// \brief Implementation of the HistoManager 27 /// \brief Implementation of the HistoManager class 28 // 28 // 29 // 29 // 30 // << 30 // 31 //....oooOO0OOooo........oooOO0OOooo........oo 31 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 32 //....oooOO0OOooo........oooOO0OOooo........oo 32 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 33 33 34 #include "HistoManager.hh" 34 #include "HistoManager.hh" 35 << 36 #include "DetectorConstruction.hh" << 37 << 38 #include "G4SystemOfUnits.hh" 35 #include "G4SystemOfUnits.hh" >> 36 #include "DetectorConstruction.hh" 39 37 40 //....oooOO0OOooo........oooOO0OOooo........oo 38 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 41 39 42 HistoManager::HistoManager() 40 HistoManager::HistoManager() 43 { 41 { 44 fNBinsZ = 60; << 42 45 fNBinsR = 80; << 43 fNBinsZ = 60; 46 fNBinsE = 200; << 44 fNBinsR = 80; 47 << 45 fNBinsE = 200; 48 fAbsorberZ = 300. * mm; << 46 49 fAbsorberR = 200. * mm; << 47 fAbsorberZ = 300.*mm; 50 fScoreZ = 100. * mm; << 48 fAbsorberR = 200.*mm; 51 fMaxEnergy = 50. * MeV; << 49 fScoreZ = 100.*mm; >> 50 fMaxEnergy = 50.*MeV; 52 51 53 fStepZ = fStepR = fStepE = 0.0; 52 fStepZ = fStepR = fStepE = 0.0; 54 53 55 Book(); 54 Book(); >> 55 56 } 56 } 57 57 58 //....oooOO0OOooo........oooOO0OOooo........oo 58 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 59 59 60 HistoManager::~HistoManager() {} << 60 HistoManager::~HistoManager() >> 61 { >> 62 } 61 63 62 //....oooOO0OOooo........oooOO0OOooo........oo 64 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 63 65 64 void HistoManager::Book() 66 void HistoManager::Book() 65 { 67 { >> 68 66 G4AnalysisManager* analysisManager = G4Analy 69 G4AnalysisManager* analysisManager = G4AnalysisManager::Instance(); 67 70 68 // Create or get analysis manager 71 // Create or get analysis manager 69 analysisManager->SetDefaultFileType("root"); 72 analysisManager->SetDefaultFileType("root"); 70 analysisManager->SetVerboseLevel(1); 73 analysisManager->SetVerboseLevel(1); 71 analysisManager->SetActivation(true); // en << 74 analysisManager->SetActivation(true); // enable inactivation of histograms 72 75 73 // Creating an 1-dimensional histograms in t 76 // Creating an 1-dimensional histograms in the root directory of the tree 74 fHisto.assign(10, 0); << 77 fHisto.assign(10,0); 75 int iHisto = 0; << 78 int iHisto=0; 76 fHisto[iHisto] = analysisManager->CreateH1( << 79 fHisto[iHisto] = analysisManager->CreateH1("10", 77 "10", "Energy deposit at radius (mm) norma << 80 "Energy deposit at radius (mm) normalised on 1st channel", 78 << 81 fNBinsR, 0., fAbsorberR/mm); >> 82 79 iHisto++; 83 iHisto++; 80 fHisto[iHisto] = analysisManager->CreateH1( << 84 fHisto[iHisto] = analysisManager->CreateH1("11", 81 "11", "Energy deposit at radius (mm) norma << 85 "Energy deposit at radius (mm) normalised to integral", >> 86 fNBinsR, 0., fAbsorberR/mm); 82 87 83 iHisto++; 88 iHisto++; 84 fHisto[iHisto] = analysisManager->CreateH1( << 89 fHisto[iHisto] = analysisManager->CreateH1("12", 85 "12", "Energy deposit (MeV/kg/electron) at << 90 "Energy deposit (MeV/kg/electron) at radius (mm)", >> 91 fNBinsR, 0., fAbsorberR/mm); 86 92 87 iHisto++; 93 iHisto++; 88 fHisto[iHisto] = analysisManager->CreateH1(" << 94 fHisto[iHisto] = analysisManager->CreateH1("13", 89 f << 95 "Energy profile (MeV/kg/electron) over Z (mm)",fNBinsZ,0.,fAbsorberZ/mm); 90 96 91 iHisto++; 97 iHisto++; 92 fHisto[iHisto] = << 98 fHisto[iHisto] = analysisManager->CreateH1("14", 93 analysisManager->CreateH1("14", "Energy pr << 99 "Energy profile (MeV/kg/electron) over Z (mm) at Central Voxel", 94 fNBinsZ, 0., fAb << 100 fNBinsZ, 0., fAbsorberZ/mm); 95 101 96 iHisto++; 102 iHisto++; 97 fHisto[iHisto] = analysisManager->CreateH1(" << 103 fHisto[iHisto] = analysisManager->CreateH1("15", 98 f << 104 "Energy (MeV) of fGamma produced in the target", >> 105 fNBinsE, 0., fMaxEnergy/MeV); 99 106 100 iHisto++; 107 iHisto++; 101 fHisto[iHisto] = analysisManager->CreateH1(" << 108 fHisto[iHisto] = analysisManager->CreateH1("16", 102 0 << 109 "Energy (MeV) of fGamma before phantom",fNBinsE,0.,fMaxEnergy/MeV); 103 110 104 iHisto++; 111 iHisto++; 105 fHisto[iHisto] = analysisManager->CreateH1(" << 112 fHisto[iHisto] = analysisManager->CreateH1("17", 106 f << 113 "Energy (MeV) of electrons produced in phantom",fNBinsE,0.,fMaxEnergy/MeV); 107 114 108 iHisto++; 115 iHisto++; 109 fHisto[iHisto] = analysisManager->CreateH1(" << 116 fHisto[iHisto] = analysisManager->CreateH1("18", 110 f << 117 "Energy (MeV) of electrons produced in target",fNBinsE,0.,fMaxEnergy/MeV); 111 118 112 iHisto++; 119 iHisto++; 113 fHisto[iHisto] = analysisManager->CreateH1( << 120 fHisto[iHisto] = analysisManager->CreateH1("19", 114 "19", "Gamma Energy Fluence (MeV/cm2) at r << 121 "Gamma Energy Fluence (MeV/cm2) at radius(mm) in front of phantom", 115 fAbsorberR / mm); << 122 fNBinsR, 0., fAbsorberR/mm); 116 123 117 // Create all histograms as inactivated << 124 // Create all histograms as inactivated 118 // as we have not yet set nbins, vmin, vmax 125 // as we have not yet set nbins, vmin, vmax 119 for (int i = 0; i < iHisto + 1; i++) << 126 for(int i=0; i<iHisto+1; i++) analysisManager->SetH1Activation(i, false); 120 analysisManager->SetH1Activation(i, false) << 127 121 } 128 } 122 129 >> 130 123 void HistoManager::Update(DetectorConstruction 131 void HistoManager::Update(DetectorConstruction* det, bool bForceActivation) 124 { 132 { >> 133 125 G4AnalysisManager* analysisManager = G4Analy 134 G4AnalysisManager* analysisManager = G4AnalysisManager::Instance(); 126 135 127 if (bForceActivation) { << 136 if(bForceActivation) { 128 for (int i = 0; i < (int)fHisto.size(); i+ << 137 for(int i=0; i<(int)fHisto.size(); i++) 129 analysisManager->SetH1Activation(fHisto[ 138 analysisManager->SetH1Activation(fHisto[i], true); 130 analysisManager->SetActivation(true); 139 analysisManager->SetActivation(true); 131 } 140 } 132 141 133 if (analysisManager->IsActive()) { << 142 if(analysisManager->IsActive()) { >> 143 134 // Check nBinsR / fAbsorberR histograms 144 // Check nBinsR / fAbsorberR histograms 135 if (det->GetNumberDivR() != fNBinsR || std << 145 if(det->GetNumberDivR()!=fNBinsR|| 136 { << 146 std::fabs(det->GetAbsorberR()-fAbsorberR)>0.01*mm) 137 fNBinsR = det->GetNumberDivR(); << 147 { 138 fAbsorberR = det->GetAbsorberR(); << 148 fNBinsR = det->GetNumberDivR(); 139 std::vector<G4int> histoId{0, 1, 2, 9}; << 149 fAbsorberR = det->GetAbsorberR(); 140 for (auto v : histoId) { << 150 std::vector<G4int> histoId { 0, 1, 2, 9 }; 141 analysisManager->SetH1(fHisto[v], fNBi << 151 for(auto v : histoId) 142 } << 152 { 143 } << 153 analysisManager->SetH1(fHisto[v], fNBinsR, 0., fAbsorberR/mm); >> 154 } 144 155 >> 156 } >> 157 145 // Check nBinsZ / fAbsorberZ histograms 158 // Check nBinsZ / fAbsorberZ histograms 146 if (det->GetNumberDivZ() != fNBinsZ || std << 159 if(det->GetNumberDivZ()!=fNBinsZ|| 147 { << 160 std::fabs(det->GetAbsorberZ()-fAbsorberZ)>0.01*mm) 148 fNBinsZ = det->GetNumberDivZ(); << 161 { 149 fAbsorberZ = det->GetAbsorberZ(); << 162 fNBinsZ = det->GetNumberDivZ(); 150 std::vector<G4int> histoId{3, 4}; << 163 fAbsorberZ = det->GetAbsorberZ(); 151 for (auto v : histoId) { << 164 std::vector<G4int> histoId { 3, 4 }; 152 analysisManager->SetH1(fHisto[v], fNBi << 165 for(auto v : histoId) >> 166 { >> 167 analysisManager->SetH1(fHisto[v], fNBinsZ, 0., fAbsorberZ/mm); >> 168 } 153 } 169 } 154 } << 170 155 << 156 // Check nBinsE / fAbsorberE histograms 171 // Check nBinsE / fAbsorberE histograms 157 if (det->GetNumberDivE() != fNBinsE || std << 172 if(det->GetNumberDivE()!=fNBinsE|| 158 fNBinsE = det->GetNumberDivE(); << 173 std::fabs(det->GetMaxEnergy()-fMaxEnergy)>0.01) 159 fMaxEnergy = det->GetMaxEnergy(); << 174 { 160 std::vector<G4int> histoId{5, 6, 7, 8}; << 175 fNBinsE = det->GetNumberDivE(); 161 for (auto v : histoId) { << 176 fMaxEnergy = det->GetMaxEnergy(); 162 analysisManager->SetH1(fHisto[v], fNBi << 177 std::vector<G4int> histoId { 5, 6, 7 ,8 }; >> 178 for(auto v : histoId) >> 179 { >> 180 analysisManager->SetH1(fHisto[v], fNBinsE, 0., fMaxEnergy/MeV); >> 181 } 163 } 182 } 164 } << 165 } 183 } >> 184 166 } 185 } 167 186 >> 187 168 //....oooOO0OOooo........oooOO0OOooo........oo 188 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 169 189 170 void HistoManager::DumpHistoParameters() 190 void HistoManager::DumpHistoParameters() 171 { 191 { 172 if (!G4AnalysisManager::Instance()->IsActive << 192 if(!G4AnalysisManager::Instance()->IsActive()) return; >> 193 >> 194 for(int i=0; i<(int)fHisto.size(); i++) >> 195 { >> 196 G4int histoId=fHisto[i]; >> 197 G4String title = G4AnalysisManager::Instance()->GetH1Title(histoId); >> 198 G4int nbins = G4AnalysisManager::Instance()->GetH1Nbins(histoId); >> 199 G4double xmin = G4AnalysisManager::Instance()->GetH1Xmin(histoId); >> 200 G4double xmax = G4AnalysisManager::Instance()->GetH1Xmax(histoId); >> 201 G4double width = G4AnalysisManager::Instance()->GetH1Width(histoId); >> 202 G4cout<<"Histogram parameters : "<<i<<" "<<histoId<<" : "<<nbins<<" "; >> 203 G4cout<<xmin<<"/"<<xmax<<" "<<width<<G4endl; >> 204 >> 205 } 173 206 174 for (int i = 0; i < (int)fHisto.size(); i++) << 175 G4int histoId = fHisto[i]; << 176 G4String title = G4AnalysisManager::Instan << 177 G4int nbins = G4AnalysisManager::Instance( << 178 G4double xmin = G4AnalysisManager::Instanc << 179 G4double xmax = G4AnalysisManager::Instanc << 180 G4double width = G4AnalysisManager::Instan << 181 G4cout << "Histogram parameters : " << i < << 182 G4cout << xmin << "/" << xmax << " " << wi << 183 } << 184 } 207 } >> 208 >> 209 >> 210 >> 211 185 212