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/TestEm16/src/HistoMa << 27 /// \brief Implementation of the HistoManager << 28 // << 29 // 26 // 30 //....oooOO0OOooo........oooOO0OOooo........oo 27 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 31 //....oooOO0OOooo........oooOO0OOooo........oo 28 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 32 29 33 #include "HistoManager.hh" 30 #include "HistoManager.hh" 34 << 31 #include "HistoMessenger.hh" 35 #include "G4RunManager.hh" << 36 #include "G4UnitsTable.hh" 32 #include "G4UnitsTable.hh" 37 33 >> 34 #ifdef G4ANALYSIS_USE >> 35 #include "AIDA/AIDA.h" >> 36 #endif >> 37 >> 38 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 39 >> 40 HistoManager::HistoManager() >> 41 :af(0),tree(0),factoryOn(false) >> 42 { >> 43 #ifdef G4ANALYSIS_USE >> 44 // Creating the analysis factory >> 45 af = AIDA_createAnalysisFactory(); >> 46 if(!af) { >> 47 G4cout << " HistoManager::HistoManager() :" >> 48 << " problem creating the AIDA analysis factory." >> 49 << G4endl; >> 50 } >> 51 #endif >> 52 >> 53 fileName[0] = "testem16"; >> 54 fileType = "hbook"; >> 55 fileOption = "--noErrors uncompress"; >> 56 // histograms >> 57 for (G4int k=0; k<MaxHisto; k++) { >> 58 histo[k] = 0; >> 59 exist[k] = false; >> 60 Unit[k] = 1.0; >> 61 Width[k] = 1.0; >> 62 } >> 63 >> 64 histoMessenger = new HistoMessenger(this); >> 65 } >> 66 38 //....oooOO0OOooo........oooOO0OOooo........oo 67 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 39 68 40 HistoManager::HistoManager() : fFileName("test << 69 HistoManager::~HistoManager() 41 { 70 { 42 Book(); << 71 delete histoMessenger; >> 72 >> 73 #ifdef G4ANALYSIS_USE >> 74 delete af; >> 75 #endif 43 } 76 } 44 77 45 //....oooOO0OOooo........oooOO0OOooo........oo 78 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 46 79 47 void HistoManager::Book() << 80 void HistoManager::book() 48 { 81 { 49 // Create or get analysis manager << 82 #ifdef G4ANALYSIS_USE 50 // The choice of analysis technology is done << 83 if(!af) { 51 // in HistoManager.hh << 84 G4cout << "HistoManager::book: WARNING AnalysisFactory is not created," 52 G4AnalysisManager* analysisManager = G4Analy << 85 << " there will be no AIDA histos" << G4endl; 53 analysisManager->SetDefaultFileType("root"); << 86 return; 54 analysisManager->SetFileName(fFileName); << 55 if (analysisManager->GetVerboseLevel() > 1) << 56 G4cout << __FILE__ << " line " << __LINE__ << 57 << " G4RunManager::GetRunManager()= << 58 << G4endl; // booked once per thre << 59 analysisManager->SetVerboseLevel(1); << 60 analysisManager->SetActivation(true); // en << 61 << 62 // Define histograms start values << 63 const std::vector<G4String> title({"dummy", << 64 // Default values (to be reset via /analysis << 65 G4int nbins = 100; << 66 G4double vmin = 0.; << 67 G4double vmax = 100.; << 68 << 69 // Create all histograms as inactivated << 70 // as we have not yet set nbins, vmin, vmax << 71 for (std::size_t k = 0; k < title.size(); ++ << 72 G4int ih = analysisManager->CreateH1(ToStr << 73 analysisManager->SetH1Activation(ih, false << 74 if (analysisManager->GetVerboseLevel() > 1 << 75 G4cout << __FILE__ << " line " << __LINE << 76 << " title=" << title[k] << " cre << 77 } 87 } >> 88 G4cout << "\n----> Book AIDA histograms "<< G4endl; >> 89 >> 90 // Creating a tree mapped to an hbook file. >> 91 fileName[1] = fileName[0] + "." + fileType; >> 92 G4bool readOnly = false; >> 93 G4bool createNew = true; >> 94 AIDA::ITreeFactory* tf = af->createTreeFactory(); >> 95 tree = tf->create(fileName[1], fileType, readOnly, createNew, fileOption); >> 96 delete tf; >> 97 if(!tree) { >> 98 G4cout << "HistoManager::book() :" >> 99 << " problem creating the AIDA tree with " >> 100 << " storeName = " << fileName[1] >> 101 << " storeType = " << fileType >> 102 << " readOnly = " << readOnly >> 103 << " createNew = " << createNew >> 104 << " options = " << fileOption >> 105 << G4endl; >> 106 return; >> 107 } >> 108 >> 109 // Creating a histogram factory, whose histograms will be handled by the tree >> 110 AIDA::IHistogramFactory* hf = af->createHistogramFactory(*tree); >> 111 >> 112 // create selected histograms >> 113 for (G4int k=0; k<MaxHisto; k++) { >> 114 if (exist[k]) { >> 115 histo[k] = hf->createHistogram1D( Label[k], Title[k], >> 116 Nbins[k], Vmin[k], Vmax[k]); >> 117 factoryOn = true; >> 118 } >> 119 } >> 120 delete hf; >> 121 if (factoryOn) >> 122 G4cout << "\n----> Histogram Tree is opened in " << fileName[1] << G4endl; >> 123 #else >> 124 G4cout << "G4ANALYSIS_USE was not set, there will be no AIDA histos" >> 125 << G4endl; >> 126 #endif 78 } 127 } 79 128 80 //....oooOO0OOooo........oooOO0OOooo........oo 129 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 130 >> 131 void HistoManager::save() >> 132 { >> 133 #ifdef G4ANALYSIS_USE >> 134 if (factoryOn) { >> 135 tree->commit(); // Writing the histograms to the file >> 136 tree->close(); // and closing the tree (and the file) >> 137 G4cout << "\n----> Histogram Tree is saved in " << fileName[1] << G4endl; >> 138 >> 139 delete tree; >> 140 tree = 0; >> 141 factoryOn = false; >> 142 } >> 143 #endif >> 144 } >> 145 >> 146 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 147 >> 148 void HistoManager::FillHisto(G4int ih, G4double e, G4double weight) >> 149 { >> 150 if (ih > MaxHisto) { >> 151 G4cout << "---> warning from HistoManager::FillHisto() : histo " << ih >> 152 << "does not exist; e= " << e << " w= " << weight << G4endl; >> 153 return; >> 154 } >> 155 #ifdef G4ANALYSIS_USE >> 156 if(exist[ih]) histo[ih]->fill(e/Unit[ih], weight); >> 157 #endif >> 158 } >> 159 >> 160 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 161 >> 162 void HistoManager::SetHisto(G4int ih, >> 163 G4int nbins, G4double valmin, G4double valmax, const G4String& unit) >> 164 { >> 165 if (ih > MaxHisto) { >> 166 G4cout << "---> warning from HistoManager::SetHisto() : histo " << ih >> 167 << "does not exist" << G4endl; >> 168 return; >> 169 } >> 170 >> 171 const G4String id[] = { "0", "1", "2", "3" }; >> 172 const G4String title[] = >> 173 { "dummy", //0 >> 174 "SynRad Energy", //1 >> 175 "SynRad Power ", //2 >> 176 "Path Length" //3 >> 177 }; >> 178 >> 179 >> 180 G4String titl = title[ih]; >> 181 G4double vmin = valmin, vmax = valmax; >> 182 Unit[ih] = 1.; >> 183 >> 184 if (unit != "none") { >> 185 titl = title[ih] + " (" + unit + ")"; >> 186 Unit[ih] = G4UnitDefinition::GetValueOf(unit); >> 187 vmin = valmin/Unit[ih]; vmax = valmax/Unit[ih]; >> 188 } >> 189 >> 190 exist[ih] = true; >> 191 Label[ih] = id[ih]; >> 192 Title[ih] = titl; >> 193 Nbins[ih] = nbins; >> 194 Vmin[ih] = vmin; >> 195 Vmax[ih] = vmax; >> 196 Width[ih] = (valmax-valmin)/nbins; >> 197 >> 198 G4cout << "----> SetHisto " << ih << ": " << titl << "; " >> 199 << nbins << " bins from " >> 200 << vmin << " " << unit << " to " << vmax << " " << unit << G4endl; >> 201 >> 202 } >> 203 >> 204 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 205 >> 206 void HistoManager::RemoveHisto(G4int ih) >> 207 { >> 208 if (ih > MaxHisto) { >> 209 G4cout << "---> warning from HistoManager::RemoveHisto() : histo " << ih >> 210 << "does not exist" << G4endl; >> 211 return; >> 212 } >> 213 >> 214 histo[ih] = 0; exist[ih] = false; >> 215 } >> 216 >> 217 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 218 81 219