[807] | 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 | // |
---|
| 27 | // $Id: XrayFluoRunAction.cc |
---|
| 28 | // GEANT4 tag $Name: xray_fluo-V03-02-00 |
---|
| 29 | // |
---|
| 30 | // Author: Elena Guardincerri (Elena.Guardincerri@ge.infn.it) |
---|
| 31 | // |
---|
| 32 | // History: |
---|
| 33 | // ----------- |
---|
| 34 | // 28 Nov 2001 Elena Guardincerri Created |
---|
| 35 | // |
---|
| 36 | // ------------------------------------------------------------------- |
---|
| 37 | |
---|
| 38 | #include "XrayFluoRunAction.hh" |
---|
| 39 | #include "G4Run.hh" |
---|
| 40 | #include "G4UImanager.hh" |
---|
| 41 | #include "G4VVisManager.hh" |
---|
| 42 | #include "G4ios.hh" |
---|
| 43 | #include "XrayFluoDataSet.hh" |
---|
| 44 | #include "G4DataVector.hh" |
---|
| 45 | #include "G4LogLogInterpolation.hh" |
---|
| 46 | #include <fstream> |
---|
| 47 | #include <sstream> |
---|
| 48 | #include "XrayFluoNormalization.hh" |
---|
| 49 | #ifdef G4ANALYSIS_USE |
---|
| 50 | #include "XrayFluoAnalysisManager.hh" |
---|
| 51 | #endif |
---|
| 52 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
| 53 | |
---|
| 54 | #ifdef G4ANALYSIS_USE |
---|
| 55 | |
---|
| 56 | XrayFluoRunAction::XrayFluoRunAction() |
---|
| 57 | :dataSet(0),dataGammaSet(0),dataAlphaSet(0) |
---|
| 58 | { |
---|
| 59 | XrayFluoNormalization normalization; |
---|
| 60 | |
---|
| 61 | energies = new G4DataVector; |
---|
| 62 | data = new G4DataVector; |
---|
| 63 | |
---|
| 64 | |
---|
| 65 | ReadData(MeV,"mercury_flx_solmin"); |
---|
| 66 | //ReadResponse("SILIresponse"); |
---|
| 67 | |
---|
| 68 | G4double minGamma = 0.*keV; |
---|
| 69 | G4double maxGamma = 10. *keV; |
---|
| 70 | G4int nBinsGamma = 5; |
---|
| 71 | |
---|
| 72 | |
---|
| 73 | dataGammaSet = normalization.Normalize(minGamma, maxGamma, nBinsGamma, |
---|
| 74 | "FlatSpectrum"); |
---|
| 75 | |
---|
| 76 | |
---|
| 77 | //G4String fileName = "SILIefficiency"; |
---|
| 78 | //G4VDataSetAlgorithm* interpolation4 = new G4LogLogInterpolation(); |
---|
| 79 | //efficiencySet = new XrayFluoDataSet(1,fileName,interpolation4,keV,1); |
---|
| 80 | //delete interpolation4; |
---|
| 81 | G4cout << "XrayFluoRunAction created" << G4endl; |
---|
| 82 | } |
---|
| 83 | #else |
---|
| 84 | XrayFluoRunAction::XrayFluoRunAction() |
---|
| 85 | { |
---|
| 86 | G4cout << "XrayFluoRunAction created" << G4endl; |
---|
| 87 | } |
---|
| 88 | #endif |
---|
| 89 | |
---|
| 90 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
| 91 | #ifdef G4ANALYSIS_USE |
---|
| 92 | |
---|
| 93 | XrayFluoRunAction::~XrayFluoRunAction() |
---|
| 94 | { |
---|
| 95 | |
---|
| 96 | //std::map<G4int,G4DataVector*,std::less<G4int> >::iterator pos; |
---|
| 97 | |
---|
| 98 | // delete energies; |
---|
| 99 | // delete data; |
---|
| 100 | // G4cout << "energies and data deleted " << G4endl; |
---|
| 101 | |
---|
| 102 | //for (pos = energyMap.begin(); pos != energyMap.end(); pos++) |
---|
| 103 | //{ |
---|
| 104 | // G4DataVector* dataSet = (*pos).second; |
---|
| 105 | // delete dataSet; |
---|
| 106 | // dataSet = 0; |
---|
| 107 | // } |
---|
| 108 | //for (pos = dataMap.begin(); pos != dataMap.end(); pos++) |
---|
| 109 | // { |
---|
| 110 | // G4DataVector* dataSet = (*pos).second; |
---|
| 111 | // delete dataSet; |
---|
| 112 | // dataSet = 0; |
---|
| 113 | // } |
---|
| 114 | |
---|
| 115 | |
---|
| 116 | G4cout << "XrayFluoRunAction deleted" << G4endl; |
---|
| 117 | |
---|
| 118 | } |
---|
| 119 | |
---|
| 120 | #else |
---|
| 121 | XrayFluoRunAction::~XrayFluoRunAction() |
---|
| 122 | { |
---|
| 123 | G4cout << "XrayFluoRunAction deleted" << G4endl; |
---|
| 124 | } |
---|
| 125 | #endif |
---|
| 126 | |
---|
| 127 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
| 128 | |
---|
| 129 | void XrayFluoRunAction::BeginOfRunAction(const G4Run* aRun) |
---|
| 130 | { |
---|
| 131 | |
---|
| 132 | G4cout << "### Run " << aRun << " start." << G4endl; |
---|
| 133 | if (G4VVisManager::GetConcreteInstance()) |
---|
| 134 | { |
---|
| 135 | G4UImanager* UI = G4UImanager::GetUIpointer(); |
---|
| 136 | UI->ApplyCommand("/vis/scene/notifyHandlers"); |
---|
| 137 | } |
---|
| 138 | #ifdef G4ANALYSIS_USE |
---|
| 139 | |
---|
| 140 | // Book histograms and ntuples |
---|
| 141 | XrayFluoAnalysisManager* analysis = XrayFluoAnalysisManager::getInstance(); |
---|
| 142 | analysis->book(); |
---|
| 143 | analysis->InitializePlotter(); |
---|
| 144 | #endif |
---|
| 145 | } |
---|
| 146 | |
---|
| 147 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
| 148 | |
---|
| 149 | void XrayFluoRunAction::EndOfRunAction(const G4Run*) |
---|
| 150 | { |
---|
| 151 | #ifdef G4ANALYSIS_USE |
---|
| 152 | XrayFluoAnalysisManager* analysis = XrayFluoAnalysisManager::getInstance(); |
---|
| 153 | #endif |
---|
| 154 | // Run ended, update the visualization |
---|
| 155 | if (G4VVisManager::GetConcreteInstance()) { |
---|
| 156 | G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/update"); |
---|
| 157 | } |
---|
| 158 | #ifdef G4ANALYSIS_USE |
---|
| 159 | analysis->finish(); |
---|
| 160 | #endif |
---|
| 161 | } |
---|
| 162 | |
---|
| 163 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
| 164 | |
---|
| 165 | |
---|
| 166 | const XrayFluoDataSet* XrayFluoRunAction::GetSet() |
---|
| 167 | { |
---|
| 168 | return dataSet; |
---|
| 169 | } |
---|
| 170 | const XrayFluoDataSet* XrayFluoRunAction::GetGammaSet() |
---|
| 171 | { |
---|
| 172 | return dataGammaSet; |
---|
| 173 | } |
---|
| 174 | const XrayFluoDataSet* XrayFluoRunAction::GetAlphaSet() |
---|
| 175 | { |
---|
| 176 | return dataAlphaSet; |
---|
| 177 | } |
---|
| 178 | //const XrayFluoDataSet* XrayFluoRunAction::GetEfficiencySet() |
---|
| 179 | //{ |
---|
| 180 | // return efficiencySet; |
---|
| 181 | //} |
---|
| 182 | G4DataVector* XrayFluoRunAction::GetEnergies() |
---|
| 183 | { |
---|
| 184 | return energies; |
---|
| 185 | } |
---|
| 186 | G4DataVector* XrayFluoRunAction::GetData() |
---|
| 187 | { |
---|
| 188 | return data; |
---|
| 189 | } |
---|
| 190 | G4double XrayFluoRunAction::GetDataSum() |
---|
| 191 | { |
---|
| 192 | G4double sum = 0; |
---|
| 193 | size_t size = data->size(); |
---|
| 194 | for (size_t i = 0; i <size; i++) |
---|
| 195 | { |
---|
| 196 | sum+=(*data)[i]; |
---|
| 197 | } |
---|
| 198 | return sum; |
---|
| 199 | } |
---|
| 200 | |
---|
| 201 | |
---|
| 202 | void XrayFluoRunAction::ReadData(G4double unitE, G4String fileName) |
---|
| 203 | { |
---|
| 204 | std::ostringstream ost; |
---|
| 205 | |
---|
| 206 | ost << fileName <<".dat"; |
---|
| 207 | |
---|
| 208 | G4String name = ost.str(); |
---|
| 209 | char* path; |
---|
| 210 | |
---|
| 211 | if (!(getenv("XRAYDATA"))) { |
---|
| 212 | |
---|
| 213 | path = getenv("PWD"); |
---|
| 214 | } |
---|
| 215 | |
---|
| 216 | else { |
---|
| 217 | path = getenv("XRAYDATA"); |
---|
| 218 | } |
---|
| 219 | |
---|
| 220 | |
---|
| 221 | G4String pathString(path); |
---|
| 222 | name = pathString + "/" + name; |
---|
| 223 | |
---|
| 224 | |
---|
| 225 | std::ifstream file(name); |
---|
| 226 | std::filebuf* lsdp = file.rdbuf(); |
---|
| 227 | |
---|
| 228 | if (! (lsdp->is_open()) ) |
---|
| 229 | { |
---|
| 230 | G4String excep = "XrayFluoRunAction - data file: " + name + " not found"; |
---|
| 231 | G4Exception(excep); |
---|
| 232 | } |
---|
| 233 | G4double a = 0; |
---|
| 234 | G4int k = 1; |
---|
| 235 | |
---|
| 236 | do |
---|
| 237 | { |
---|
| 238 | file >> a; |
---|
| 239 | G4int nColumns = 2; |
---|
| 240 | // The file is organized into two columns: |
---|
| 241 | // 1st column is the energy |
---|
| 242 | // 2nd column is the corresponding value |
---|
| 243 | // The file terminates with the pattern: -1 -1 |
---|
| 244 | // -2 -2 |
---|
| 245 | if (a == -1 || a == -2) |
---|
| 246 | { |
---|
| 247 | |
---|
| 248 | } |
---|
| 249 | else |
---|
| 250 | { |
---|
| 251 | if (k%nColumns != 0) |
---|
| 252 | { |
---|
| 253 | G4double e = a * unitE; |
---|
| 254 | |
---|
| 255 | energies->push_back(e); |
---|
| 256 | |
---|
| 257 | k++; |
---|
| 258 | |
---|
| 259 | } |
---|
| 260 | else if (k%nColumns == 0) |
---|
| 261 | { |
---|
| 262 | G4double value = a; |
---|
| 263 | data->push_back(value); |
---|
| 264 | |
---|
| 265 | k = 1; |
---|
| 266 | } |
---|
| 267 | } |
---|
| 268 | |
---|
| 269 | } while (a != -2); // end of file |
---|
| 270 | |
---|
| 271 | file.close(); |
---|
| 272 | } |
---|
| 273 | |
---|
| 274 | |
---|
| 275 | |
---|
| 276 | |
---|
| 277 | |
---|
| 278 | |
---|
| 279 | |
---|
| 280 | |
---|
| 281 | |
---|
| 282 | |
---|
| 283 | |
---|
| 284 | |
---|
| 285 | |
---|
| 286 | |
---|