File indexing completed on 2025-01-18 09:17:11
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036 #include "XrayFluoRunAction.hh"
0037 #include "G4Run.hh"
0038 #include "G4UImanager.hh"
0039 #include "G4VVisManager.hh"
0040 #include "G4ios.hh"
0041 #include "XrayFluoDataSet.hh"
0042 #include "G4DataVector.hh"
0043 #include "G4LogLogInterpolation.hh"
0044 #include <fstream>
0045 #include <sstream>
0046 #include "XrayFluoNormalization.hh"
0047 #include "XrayFluoAnalysisManager.hh"
0048 #include "G4SystemOfUnits.hh"
0049
0050
0051
0052 XrayFluoRunAction::XrayFluoRunAction()
0053 : isInitialized(false), dataSet(0), dataGammaSet(0),
0054 dataAlphaSet(0)
0055 {;}
0056
0057
0058
0059 XrayFluoRunAction::~XrayFluoRunAction()
0060 {;}
0061
0062
0063
0064 void XrayFluoRunAction::Initialise()
0065 {
0066
0067
0068 if (!IsMaster())
0069 return;
0070
0071 XrayFluoNormalization normalization;
0072
0073 energies = new G4DataVector;
0074 data = new G4DataVector;
0075
0076
0077 ReadData(keV,"M_flare");
0078
0079
0080 G4double minGamma = 0.*keV;
0081 G4double maxGamma = 10. *keV;
0082 G4int nBinsGamma = 6;
0083
0084
0085 dataGammaSet = normalization.Normalize(minGamma, maxGamma, nBinsGamma,
0086 "M_flare");
0087 isInitialized = true;
0088 G4cout << "XrayFluoRunAction initialized" << G4endl;
0089 }
0090
0091
0092
0093 void XrayFluoRunAction::BeginOfRunAction(const G4Run* aRun)
0094 {
0095
0096
0097 if (IsMaster())
0098 {
0099 G4cout << "### Run " << aRun->GetRunID() << " starts (master)." << G4endl;
0100 if (!isInitialized)
0101 Initialise();
0102 }
0103 else
0104 G4cout << "### Run " << aRun->GetRunID() << " starts (worker)." << G4endl;
0105
0106 if (G4VVisManager::GetConcreteInstance())
0107 {
0108 G4UImanager* UI = G4UImanager::GetUIpointer();
0109 UI->ApplyCommand("/vis/scene/notifyHandlers");
0110 }
0111
0112
0113 XrayFluoAnalysisManager* analysis = XrayFluoAnalysisManager::getInstance();
0114 analysis->book();
0115 }
0116
0117
0118
0119 void XrayFluoRunAction::EndOfRunAction(const G4Run*)
0120 {
0121 XrayFluoAnalysisManager* analysis = XrayFluoAnalysisManager::getInstance();
0122 analysis->finish();
0123
0124 if (G4VVisManager::GetConcreteInstance()) {
0125 G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/update");
0126 }
0127 }
0128
0129
0130
0131
0132 const XrayFluoDataSet* XrayFluoRunAction::GetSet() const
0133 {
0134 return dataSet;
0135 }
0136
0137
0138
0139 const XrayFluoDataSet* XrayFluoRunAction::GetGammaSet() const
0140 {
0141 return dataGammaSet;
0142 }
0143
0144
0145
0146 const XrayFluoDataSet* XrayFluoRunAction::GetAlphaSet() const
0147 {
0148 return dataAlphaSet;
0149 }
0150
0151
0152
0153 G4DataVector* XrayFluoRunAction::GetEnergies() const
0154 {
0155 return energies;
0156 }
0157
0158
0159
0160 G4DataVector* XrayFluoRunAction::GetData() const
0161 {
0162 return data;
0163 }
0164
0165
0166
0167 G4double XrayFluoRunAction::GetDataSum() const
0168 {
0169
0170 G4double sum = 0;
0171 for (size_t i = 0; i < data->size(); i++)
0172 {
0173 sum+=(*data)[i];
0174 }
0175 return sum;
0176 }
0177
0178
0179
0180 void XrayFluoRunAction::ReadData(G4double unitE, G4String fileName)
0181 {
0182 G4cout << "Reading data...";
0183 std::ostringstream ost;
0184
0185 ost << fileName <<".dat";
0186
0187 G4String name = ost.str();
0188 char* path;
0189
0190 if (!(std::getenv("XRAYDATA"))) {
0191
0192 path = std::getenv("PWD");
0193 }
0194
0195 else {
0196 path = std::getenv("XRAYDATA");
0197 }
0198
0199
0200 G4String pathString(path);
0201 name = pathString + "/" + name;
0202
0203
0204 std::ifstream file(name);
0205 std::filebuf* lsdp = file.rdbuf();
0206
0207 if (! (lsdp->is_open()) )
0208 {
0209 G4ExceptionDescription execp;
0210 execp << "XrayFluoRunAction - data file: " + name + " not found";
0211 G4Exception("XrayFluoRunAction::ReadData()","example-xray_fluorescence04",
0212 FatalException, execp);
0213 }
0214 G4double a = 0;
0215 G4int k = 1;
0216
0217 do
0218 {
0219 file >> a;
0220 G4int nColumns = 2;
0221
0222
0223
0224
0225
0226 if (a == -1 || a == -2)
0227 {
0228
0229 }
0230 else
0231 {
0232 if (k%nColumns != 0)
0233 {
0234 G4double e = a * unitE;
0235
0236 energies->push_back(e);
0237
0238 k++;
0239
0240 }
0241 else if (k%nColumns == 0)
0242 {
0243 G4double value = a;
0244 data->push_back(value);
0245
0246 k = 1;
0247 }
0248 }
0249
0250 } while (a != -2);
0251
0252 file.close();
0253 G4cout << " done" << G4endl;
0254 }
0255
0256
0257
0258
0259
0260
0261
0262
0263
0264
0265
0266
0267
0268