Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer << 3 // * DISCLAIMER * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th << 5 // * The following disclaimer summarizes all the specific disclaimers * 6 // * the Geant4 Collaboration. It is provided << 6 // * of contributors to this software. The specific disclaimers,which * 7 // * conditions of the Geant4 Software License << 7 // * govern, are listed with their locations in: * 8 // * LICENSE and available at http://cern.ch/ << 8 // * http://cern.ch/geant4/license * 9 // * include a list of copyright holders. << 10 // * 9 // * * 11 // * Neither the authors of this software syst 10 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 11 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 12 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 13 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file << 14 // * use. * 16 // * for the full disclaimer and the limitatio << 17 // * 15 // * * 18 // * This code implementation is the result << 16 // * This code implementation is the intellectual property of the * 19 // * technical work of the GEANT4 collaboratio << 17 // * GEANT4 collaboration. * 20 // * By using, copying, modifying or distri << 18 // * By copying, distributing or modifying the Program (or any work * 21 // * any work based on the software) you ag << 19 // * based on the Program) you indicate your acceptance of this * 22 // * use in resulting scientific publicati << 20 // * statement, and all its terms. * 23 // * acceptance of all terms of the Geant4 Sof << 24 // ******************************************* 21 // ******************************************************************** 25 // 22 // 26 /// \file electromagnetic/TestEm1/src/HistoMan << 23 // $Id: HistoManager.cc,v 1.6 2005/06/01 10:20:12 maire Exp $ 27 /// \brief Implementation of the HistoManager << 24 // GEANT4 tag $Name: geant4-08-00-patch-01 $ 28 // << 29 // 25 // 30 //....oooOO0OOooo........oooOO0OOooo........oo 26 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 31 //....oooOO0OOooo........oooOO0OOooo........oo 27 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 32 28 33 #include "HistoManager.hh" 29 #include "HistoManager.hh" 34 << 30 #include "HistoMessenger.hh" 35 #include "G4UnitsTable.hh" 31 #include "G4UnitsTable.hh" 36 32 >> 33 #ifdef G4ANALYSIS_USE >> 34 #include "AIDA/AIDA.h" >> 35 #endif >> 36 37 //....oooOO0OOooo........oooOO0OOooo........oo 37 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 38 38 39 HistoManager::HistoManager() 39 HistoManager::HistoManager() >> 40 :af(0),tree(0),factoryOn(false) >> 41 { >> 42 #ifdef G4ANALYSIS_USE >> 43 // Creating the analysis factory >> 44 af = AIDA_createAnalysisFactory(); >> 45 if(!af) { >> 46 G4cout << " HistoManager::HistoManager() :" >> 47 << " problem creating the AIDA analysis factory." >> 48 << G4endl; >> 49 } >> 50 #endif >> 51 >> 52 fileName[0] = "testem1"; >> 53 fileType = "hbook"; >> 54 fileOption = "--noErrors uncompress"; >> 55 // histograms >> 56 for (G4int k=0; k<MaxHisto; k++) { >> 57 histo[k] = 0; >> 58 exist[k] = false; >> 59 Unit[k] = 1.0; >> 60 Width[k] = 1.0; >> 61 } >> 62 >> 63 histoMessenger = new HistoMessenger(this); >> 64 } >> 65 >> 66 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 67 >> 68 HistoManager::~HistoManager() >> 69 { >> 70 delete histoMessenger; >> 71 >> 72 #ifdef G4ANALYSIS_USE >> 73 delete af; >> 74 #endif >> 75 } >> 76 >> 77 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 78 >> 79 void HistoManager::book() >> 80 { >> 81 #ifdef G4ANALYSIS_USE >> 82 if(!af) return; >> 83 >> 84 // Creating a tree mapped to an hbook file. >> 85 fileName[1] = fileName[0] + "." + fileType; >> 86 G4bool readOnly = false; >> 87 G4bool createNew = true; >> 88 AIDA::ITreeFactory* tf = af->createTreeFactory(); >> 89 tree = tf->create(fileName[1], fileType, readOnly, createNew, fileOption); >> 90 delete tf; >> 91 if(!tree) { >> 92 G4cout << "HistoManager::book() :" >> 93 << " problem creating the AIDA tree with " >> 94 << " storeName = " << fileName[1] >> 95 << " storeType = " << fileType >> 96 << " readOnly = " << readOnly >> 97 << " createNew = " << createNew >> 98 << " options = " << fileOption >> 99 << G4endl; >> 100 return; >> 101 } >> 102 >> 103 // Creating a histogram factory, whose histograms will be handled by the tree >> 104 AIDA::IHistogramFactory* hf = af->createHistogramFactory(*tree); >> 105 >> 106 // create selected histograms >> 107 for (G4int k=0; k<MaxHisto; k++) { >> 108 if (exist[k]) { >> 109 histo[k] = hf->createHistogram1D( Label[k], Title[k], >> 110 Nbins[k], Vmin[k], Vmax[k]); >> 111 factoryOn = true; >> 112 } >> 113 } >> 114 delete hf; >> 115 if (factoryOn) >> 116 G4cout << "\n----> Histogram Tree is opened in " << fileName[1] << G4endl; >> 117 #endif >> 118 } >> 119 >> 120 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 121 >> 122 void HistoManager::save() >> 123 { >> 124 #ifdef G4ANALYSIS_USE >> 125 if (factoryOn) { >> 126 tree->commit(); // Writing the histograms to the file >> 127 tree->close(); // and closing the tree (and the file) >> 128 G4cout << "\n----> Histogram Tree is saved in " << fileName[1] << G4endl; >> 129 >> 130 delete tree; >> 131 tree = 0; >> 132 factoryOn = false; >> 133 } >> 134 #endif >> 135 } >> 136 >> 137 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 138 >> 139 void HistoManager::FillHisto(G4int ih, G4double e, G4double weight) >> 140 { >> 141 if (ih > MaxHisto) { >> 142 G4cout << "---> warning from HistoManager::FillHisto() : histo " << ih >> 143 << "does not exist; e= " << e << " w= " << weight << G4endl; >> 144 return; >> 145 } >> 146 #ifdef G4ANALYSIS_USE >> 147 if(exist[ih]) histo[ih]->fill(e/Unit[ih], weight); >> 148 #endif >> 149 } >> 150 >> 151 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 152 >> 153 void HistoManager::SetHisto(G4int ih, >> 154 G4int nbins, G4double valmin, G4double valmax, const G4String& unit) 40 { 155 { 41 Book(); << 156 if (ih > MaxHisto) { >> 157 G4cout << "---> warning from HistoManager::SetHisto() : histo " << ih >> 158 << "does not exist" << G4endl; >> 159 return; >> 160 } >> 161 >> 162 const G4String id[] = { "0", "1", "2", "3" }; >> 163 const G4String title[] = >> 164 { "dummy", //0 >> 165 "total track length of a charged particle", //1 >> 166 "nb steps per track (charged particles)", //2 >> 167 "step length of charged particles" //3 >> 168 }; >> 169 >> 170 >> 171 G4String titl = title[ih]; >> 172 G4double vmin = valmin, vmax = valmax; >> 173 Unit[ih] = 1.; >> 174 >> 175 if (unit != "none") { >> 176 titl = title[ih] + " (" + unit + ")"; >> 177 Unit[ih] = G4UnitDefinition::GetValueOf(unit); >> 178 vmin = valmin/Unit[ih]; vmax = valmax/Unit[ih]; >> 179 } >> 180 >> 181 exist[ih] = true; >> 182 Label[ih] = id[ih]; >> 183 Title[ih] = titl; >> 184 Nbins[ih] = nbins; >> 185 Vmin[ih] = vmin; >> 186 Vmax[ih] = vmax; >> 187 Width[ih] = (valmax-valmin)/nbins; >> 188 >> 189 G4cout << "----> SetHisto " << ih << ": " << titl << "; " >> 190 << nbins << " bins from " >> 191 << vmin << " " << unit << " to " << vmax << " " << unit << G4endl; >> 192 42 } 193 } 43 194 44 //....oooOO0OOooo........oooOO0OOooo........oo 195 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 45 196 46 void HistoManager::Book() << 197 void HistoManager::RemoveHisto(G4int ih) 47 { 198 { 48 // Create or get analysis manager << 199 if (ih > MaxHisto) { 49 // The choice of analysis technology is done << 200 G4cout << "---> warning from HistoManager::RemoveHisto() : histo " << ih 50 // in HistoManager.hh << 201 << "does not exist" << G4endl; 51 G4AnalysisManager* analysisManager = G4Analy << 202 return; 52 analysisManager->SetDefaultFileType("root"); << 53 analysisManager->SetFileName(fFileName); << 54 analysisManager->SetVerboseLevel(1); << 55 analysisManager->SetFirstHistoId(1); // sta << 56 analysisManager->SetActivation(true); // en << 57 << 58 // Define histograms start values << 59 const G4int kMaxHisto = 9; << 60 const G4String id[] = {"1", "2", "3", "4", " << 61 const G4String title[] = { << 62 "total track length of primary particle", << 63 "nb steps of primary particle", << 64 "step size of primary particle", << 65 "total energy deposit", << 66 "energy of charged secondaries at creation << 67 "energy of neutral secondaries at creation << 68 "NIEL energy deposit", << 69 "energy leakage", << 70 "energy total: deposit + leakage" << 71 }; << 72 // Default values (to be reset via /analysis << 73 G4int nbins = 100; << 74 G4double vmin = 0.; << 75 G4double vmax = 100.; << 76 << 77 // Create all histograms as inactivated << 78 // as we have not yet set nbins, vmin, vmax << 79 for (G4int k = 0; k < kMaxHisto; k++) { << 80 G4int ih = analysisManager->CreateH1(id[k] << 81 analysisManager->SetH1Activation(ih, false << 82 } 203 } >> 204 >> 205 histo[ih] = 0; exist[ih] = false; 83 } 206 } 84 207 85 //....oooOO0OOooo........oooOO0OOooo........oo 208 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 209 86 210