Geant4 Cross Reference |
1 // 2 // ******************************************************************** 3 // * License and Disclaimer * 4 // * * 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. * 10 // * * 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitation of liability. * 17 // * * 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************************************** 25 // 26 // Authors: Susanna Guatelli and Francesco Romano 27 // susanna@uow.edu.au, francesco.romano@ct.infn.it 28 // 29 30 #include <stdlib.h> 31 #include "AnalysisManager.hh" 32 #include "G4UnitsTable.hh" 33 #include "G4SystemOfUnits.hh" 34 35 #include "AnalysisMessenger.hh" 36 37 AnalysisManager::AnalysisManager(AnalysisMessenger* analysisMessenger) 38 { 39 factoryOn = false; 40 41 // Initialization 42 // histograms 43 //for (G4int k=0; k<MaxHisto; k++) fHistId[k] = 0; 44 45 // Initialization ntuple 46 for (G4int k=0; k<MaxNtCol; k++) fNtColId[k] = 0; 47 48 //h10 = 0; 49 //h20 = 0; 50 51 messenger = analysisMessenger; 52 } 53 54 AnalysisManager::~AnalysisManager() 55 { 56 } 57 58 void AnalysisManager::book(G4bool addExtraNt) 59 { 60 G4AnalysisManager* manager = G4AnalysisManager::Instance(); 61 62 manager->SetVerboseLevel(2); 63 64 extraNt = addExtraNt; 65 66 usingRoot = messenger -> IsRootOutput(); 67 68 // Create an output file 69 G4String fileName; 70 if( usingRoot == true ) fileName = "experimental_microdosimetry.root"; 71 else fileName = "experimental_microdosimetry.csv"; 72 73 // Create directories (not supported by csv) 74 if( usingRoot == true ) manager->SetNtupleDirectoryName("experimental_microdosimetry_ntuple"); 75 76 77 G4bool fileOpen = manager->OpenFile(fileName); 78 if (!fileOpen) { 79 G4cout << "\n---> HistoManager::book(): cannot open " 80 << fileName << G4endl; 81 return; 82 } 83 84 manager->SetFirstNtupleId(1); 85 86 //Create Primary Energy Ntuple 87 manager -> CreateNtuple("101", "Primary Energy"); 88 fNtColId[0] = manager -> CreateNtupleDColumn("Ek"); 89 manager -> FinishNtuple(); 90 91 //Create Energy Deposition and Path Length within SV Ntuple 92 manager -> CreateNtuple("102", "Edep"); 93 fNtColId[1] = manager -> CreateNtupleDColumn("edep"); 94 fNtColId[2] = manager -> CreateNtupleDColumn("len"); 95 if( extraNt == true ) fNtColId[3] = manager -> CreateNtupleIColumn("eventID"); 96 manager -> FinishNtuple(); 97 98 //creating a ntuple, containing the information about secondary particles 99 manager -> CreateNtuple("103", "secondary"); 100 fNtColId[4] = manager -> CreateNtupleDColumn("AA"); 101 fNtColId[5] = manager -> CreateNtupleDColumn("ZZ"); 102 fNtColId[6] = manager -> CreateNtupleDColumn("KE"); 103 manager -> FinishNtuple(); 104 105 // if the telescope is in use, add an exta ntuple for its information 106 if( extraNt == true) 107 { 108 manager -> CreateNtuple("104", "secondStageE"); 109 fNtColId[7] = manager -> CreateNtupleDColumn("edep"); 110 fNtColId[8] = manager -> CreateNtupleIColumn("eventID"); 111 manager -> FinishNtuple(); 112 } 113 114 factoryOn = true; 115 } 116 117 118 void AnalysisManager::SetPrimaryEnergy(G4double energy) 119 { 120 G4AnalysisManager* manager = G4AnalysisManager::Instance(); 121 manager -> FillNtupleDColumn(1, fNtColId[0], energy); 122 manager -> AddNtupleRow(1); 123 } 124 125 void AnalysisManager::StoreEnergyDeposition(G4double edep, G4double len, G4int eid) 126 { 127 G4AnalysisManager* manager = G4AnalysisManager::Instance(); 128 manager -> FillNtupleDColumn(2, fNtColId[1], edep); 129 manager -> FillNtupleDColumn(2, fNtColId[2], len); 130 if( extraNt == true ) manager -> FillNtupleIColumn(2, fNtColId[3], eid); 131 // the event ID is only useful when the 4th ntuple is enabled 132 manager -> AddNtupleRow(2); 133 } 134 135 void AnalysisManager::FillSecondaries(G4int AA, G4double charge, G4double energy) 136 { 137 138 G4AnalysisManager* manager = G4AnalysisManager::Instance(); 139 manager -> FillNtupleDColumn(3, fNtColId[4], AA); 140 manager -> FillNtupleDColumn(3, fNtColId[5], charge); 141 manager -> FillNtupleDColumn(3, fNtColId[6], energy); 142 manager -> AddNtupleRow(3); 143 } 144 145 void AnalysisManager::StoreSecondStageEnergyDeposition(G4double edep, G4int eid) 146 { 147 if( extraNt == true ) 148 { 149 G4AnalysisManager* manager = G4AnalysisManager::Instance(); 150 manager -> FillNtupleDColumn(4, fNtColId[7], edep); 151 manager -> FillNtupleIColumn(4, fNtColId[8], eid); 152 manager -> AddNtupleRow(4); 153 } 154 } 155 156 void AnalysisManager::finish() 157 { 158 if (factoryOn) 159 { 160 G4AnalysisManager* manager = G4AnalysisManager::Instance(); 161 manager -> Write(); 162 manager -> CloseFile(); 163 factoryOn = false; 164 } 165 } 166 167 168 169 170 171 172 173 174 175 176 177 178 179