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 electromagnetic/TestEm5/src/HistoMan << 26 // $Id: HistoManager.cc,v 1.16 2006/06/29 16:55:38 gunter Exp $ 27 /// \brief Implementation of the HistoManager << 27 // GEANT4 tag $Name: geant4-08-01 $ 28 // << 29 // 28 // 30 //....oooOO0OOooo........oooOO0OOooo........oo 29 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 31 //....oooOO0OOooo........oooOO0OOooo........oo 30 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 32 31 33 #include "HistoManager.hh" 32 #include "HistoManager.hh" 34 << 33 #include "HistoMessenger.hh" 35 #include "G4UnitsTable.hh" 34 #include "G4UnitsTable.hh" 36 35 >> 36 #ifdef G4ANALYSIS_USE >> 37 #include "AIDA/AIDA.h" >> 38 #endif >> 39 37 //....oooOO0OOooo........oooOO0OOooo........oo 40 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 38 41 39 HistoManager::HistoManager() 42 HistoManager::HistoManager() >> 43 :af(0),tree(0),factoryOn(false) >> 44 { >> 45 #ifdef G4ANALYSIS_USE >> 46 // Creating the analysis factory >> 47 af = AIDA_createAnalysisFactory(); >> 48 if(!af) { >> 49 G4cout << " HistoManager::HistoManager() :" >> 50 << " problem creating the AIDA analysis factory." >> 51 << G4endl; >> 52 } >> 53 #endif >> 54 >> 55 fileName[0] = "testem5"; >> 56 fileType = "hbook"; >> 57 fileOption = "--noErrors uncompress"; >> 58 // histograms >> 59 for (G4int k=0; k<MaxHisto; k++) { >> 60 histo[k] = 0; >> 61 exist[k] = false; >> 62 Unit[k] = 1.0; >> 63 Width[k] = 1.0; >> 64 } >> 65 >> 66 histoMessenger = new HistoMessenger(this); >> 67 } >> 68 >> 69 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 70 >> 71 HistoManager::~HistoManager() >> 72 { >> 73 delete histoMessenger; >> 74 >> 75 #ifdef G4ANALYSIS_USE >> 76 delete af; >> 77 #endif >> 78 } >> 79 >> 80 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 81 >> 82 void HistoManager::book() >> 83 { >> 84 #ifdef G4ANALYSIS_USE >> 85 if(!af) return; >> 86 >> 87 // Creating a tree mapped to an hbook file. >> 88 fileName[1] = fileName[0] + "." + fileType; >> 89 G4bool readOnly = false; >> 90 G4bool createNew = true; >> 91 AIDA::ITreeFactory* tf = af->createTreeFactory(); >> 92 tree = tf->create(fileName[1], fileType, readOnly, createNew, fileOption); >> 93 delete tf; >> 94 if(!tree) { >> 95 G4cout << "HistoManager::book() :" >> 96 << " problem creating the AIDA tree with " >> 97 << " storeName = " << fileName[1] >> 98 << " storeType = " << fileType >> 99 << " readOnly = " << readOnly >> 100 << " createNew = " << createNew >> 101 << " options = " << fileOption >> 102 << G4endl; >> 103 return; >> 104 } >> 105 >> 106 // Creating a histogram factory, whose histograms will be handled by the tree >> 107 AIDA::IHistogramFactory* hf = af->createHistogramFactory(*tree); >> 108 >> 109 // create selected histograms >> 110 for (G4int k=0; k<MaxHisto; k++) { >> 111 if (exist[k]) { >> 112 histo[k] = hf->createHistogram1D( Label[k], Title[k], >> 113 Nbins[k], Vmin[k], Vmax[k]); >> 114 factoryOn = true; >> 115 } >> 116 } >> 117 delete hf; >> 118 if(factoryOn) >> 119 G4cout << "\n----> Histogram Tree is opened in " << fileName[1] << G4endl; >> 120 >> 121 #endif >> 122 } >> 123 >> 124 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 125 >> 126 void HistoManager::save() 40 { 127 { 41 Book(); << 128 #ifdef G4ANALYSIS_USE >> 129 if (factoryOn) { >> 130 tree->commit(); // Writing the histograms to the file >> 131 tree->close(); // and closing the tree (and the file) >> 132 G4cout << "\n----> Histogram Tree is saved in " << fileName[1] << G4endl; >> 133 >> 134 delete tree; >> 135 tree = 0; >> 136 factoryOn = false; >> 137 } >> 138 #endif 42 } 139 } 43 140 44 //....oooOO0OOooo........oooOO0OOooo........oo 141 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 45 142 46 void HistoManager::Book() << 143 void HistoManager::FillHisto(G4int ih, G4double e, G4double weight) 47 { 144 { 48 // Create or get analysis manager << 145 if (ih > MaxHisto) { 49 // The choice of analysis technology is done << 146 G4cout << "---> warning from HistoManager::FillHisto() : histo " << ih 50 // in HistoManager.hh << 147 << "does not exist; e= " << e << " w= " << weight << G4endl; 51 G4AnalysisManager* analysisManager = G4Analy << 148 return; 52 analysisManager->SetDefaultFileType("root"); << 53 analysisManager->SetFileName(fFileName); << 54 analysisManager->SetVerboseLevel(1); << 55 analysisManager->SetActivation(true); // en << 56 << 57 // Define histograms start values << 58 const G4int kMaxHisto = 62; << 59 const G4String id[] = { << 60 "0", "1", "2", "3", "4", "5", "6", << 61 "16", "17", "18", "19", "20", "21", "22", << 62 "32", "33", "34", "35", "36", "37", "38", << 63 "48", "49", "50", "51", "52", "53", "54", << 64 << 65 const G4String title[] = { << 66 "dummy", // 0 << 67 "energy deposit in absorber: dN/dE", // 1 << 68 "energy of charged secondaries at creation << 69 "energy of neutral secondaries at creation << 70 "energy of charged at creation (log scale) << 71 "energy of neutral at creation (log scale) << 72 "x_vertex of charged secondaries (all)", << 73 "x_vertex of charged secondaries (not abso << 74 "dummy", << 75 "dummy", // 8-9 << 76 "(transmit, charged) : kinetic energy at e << 77 "(transmit, charged) : ener fluence: dE(Me << 78 "(transmit, charged) : space angle: dN/dOm << 79 "(transmit, charged) : projected angle at << 80 "(transmit, charged) : projected position << 81 "(transmit, charged) : radius at exit", / << 82 "dummy", // 16 << 83 "dummy", // 17 << 84 "dummy", // 18 << 85 "dummy", // 19 << 86 "(transmit, neutral) : kinetic energy at e << 87 "(transmit, neutral) : ener fluence: dE(Me << 88 "(transmit, neutral) : space angle: dN/dOm << 89 "(transmit, neutral) : projected angle at << 90 "dummy", << 91 "dummy", << 92 "dummy", << 93 "dummy", << 94 "dummy", << 95 "dummy", // 24-29 << 96 "(reflect , charged) : kinetic energy at e << 97 "(reflect , charged) : ener fluence: dE(Me << 98 "(reflect , charged) : space angle: dN/dOm << 99 "(reflect , charged) : projected angle at << 100 "dummy", << 101 "dummy", << 102 "dummy", << 103 "dummy", << 104 "dummy", << 105 "dummy", // 34-39 << 106 "(reflect , neutral) : kinetic energy at e << 107 "(reflect , neutral) : ener fluence: dE(Me << 108 "(reflect , neutral) : space angle: dN/dOm << 109 "(reflect , neutral) : projected angle at << 110 "dummy", // 44 << 111 "dummy", // 45 << 112 "dummy", // 46 << 113 "dummy", // 47 << 114 "dummy", // 48 << 115 "dummy", // 49 << 116 "energy of Auger e- at creation", // 50 << 117 "energy of fluorescence gamma at creation" << 118 "energy of Auger e- at creation (log scale << 119 "energy of fluorescence gamma at creation << 120 "energy of PIXE Auger e- at creation", // << 121 "energy of PIXE gamma at creation", // 55 << 122 "energy of PIXE Auger e- at creation (log << 123 "energy of PIXE gamma at creation (log sca << 124 "energy of DNA Auger e- at creation", // << 125 "energy of DNA gamma at creation", // 59 << 126 "energy of DNA Auger e- at creation (log s << 127 "energy of DNA gamma at creation (log scal << 128 }; << 129 << 130 // Default values (to be reset via /analysis << 131 G4int nbins = 100; << 132 G4double vmin = 0.; << 133 G4double vmax = 100.; << 134 << 135 // Create all histograms as inactivated << 136 // as we have not yet set nbins, vmin, vmax << 137 for (G4int k = 0; k < kMaxHisto; k++) { << 138 G4int ih = analysisManager->CreateH1("h" + << 139 analysisManager->SetH1Activation(ih, false << 140 } 149 } >> 150 #ifdef G4ANALYSIS_USE >> 151 if(exist[ih]) histo[ih]->fill(e/Unit[ih], weight); >> 152 #endif 141 } 153 } >> 154 >> 155 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 156 >> 157 void HistoManager::SetHisto(G4int ih, >> 158 G4int nbins, G4double valmin, G4double valmax, const G4String& unit) >> 159 { >> 160 if (ih > MaxHisto) { >> 161 G4cout << "---> warning from HistoManager::SetHisto() : histo " << ih >> 162 << "does not exist" << G4endl; >> 163 return; >> 164 } >> 165 >> 166 const G4String id[] = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", >> 167 "10","11","12","13","14","15","16"}; >> 168 const G4String title[] = >> 169 { "dummy", //0 >> 170 "energy deposit in absorber", //1 >> 171 "energy of charged secondaries at creation", //2 >> 172 "energy of gammas at creation (std::log10(ekin/MeV))",//3 >> 173 "(transmit, charged) : kinetic energy at exit", //4 >> 174 "(transmit, charged) : space angle at exit", //5 >> 175 "(transmit, charged) : projected angle at exit", //6 >> 176 "(transmit, charged) : projected position at exit", //7 >> 177 "(transmit, neutral) : kinetic energy at exit", //8 >> 178 "(transmit, neutral) : space angle at exit", //9 >> 179 "(transmit, neutral) : projected angle at exit", //10 >> 180 "(reflect , charged) : kinetic energy at exit", //11 >> 181 "(reflect , charged) : space angle at exit", //12 >> 182 "(reflect , charged) : projected angle at exit", //13 >> 183 "(reflect , neutral) : kinetic energy at exit", //14 >> 184 "(reflect , neutral) : space angle at exit", //15 >> 185 "(reflect , neutral) : projected angle at exit" //16 >> 186 }; >> 187 >> 188 G4String titl = title[ih]; >> 189 G4double vmin = valmin, vmax = valmax; >> 190 Unit[ih] = 1.; >> 191 >> 192 if (ih == 3) { vmin = std::log10(valmin/MeV); vmax = std::log10(valmax/MeV);} >> 193 else if (unit != "none") { >> 194 titl = title[ih] + " (" + unit + ")"; >> 195 Unit[ih] = G4UnitDefinition::GetValueOf(unit); >> 196 vmin = valmin/Unit[ih]; vmax = valmax/Unit[ih]; >> 197 } >> 198 >> 199 exist[ih] = true; >> 200 Label[ih] = id[ih]; >> 201 Title[ih] = titl; >> 202 Nbins[ih] = nbins; >> 203 Vmin[ih] = vmin; >> 204 Vmax[ih] = vmax; >> 205 Width[ih] = (valmax-valmin)/nbins; >> 206 >> 207 G4cout << "----> SetHisto " << ih << ": " << titl << "; " >> 208 << nbins << " bins from " >> 209 << vmin << " " << unit << " to " << vmax << " " << unit << G4endl; >> 210 >> 211 } >> 212 >> 213 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 214 >> 215 void HistoManager::RemoveHisto(G4int ih) >> 216 { >> 217 if (ih > MaxHisto) { >> 218 G4cout << "---> warning from HistoManager::RemoveHisto() : histo " << ih >> 219 << "does not exist" << G4endl; >> 220 return; >> 221 } >> 222 >> 223 histo[ih] = 0; exist[ih] = false; >> 224 } >> 225 >> 226 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 227 142 228