Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:17:11

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 //
0027 //
0028 // Author: Elena Guardincerri (Elena.Guardincerri@ge.infn.it)
0029 //
0030 // History:
0031 // -----------
0032 // 28 Nov 2001 Elena Guardincerri     Created
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 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0051 
0052 XrayFluoRunAction::XrayFluoRunAction()
0053   : isInitialized(false), dataSet(0), dataGammaSet(0), 
0054     dataAlphaSet(0)
0055 {;}
0056 
0057 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0058 
0059 XrayFluoRunAction::~XrayFluoRunAction()
0060 {;}
0061 
0062 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0063 
0064 void XrayFluoRunAction::Initialise()
0065 {
0066   //Only the master is initialized and keeps the data
0067   //(or in sequential mode)
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   //ReadResponse("SILIresponse");
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 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0092 
0093 void XrayFluoRunAction::BeginOfRunAction(const G4Run* aRun)
0094 {
0095  
0096   //Master mode or sequential
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   // Book histograms and ntuples
0113   XrayFluoAnalysisManager* analysis = XrayFluoAnalysisManager::getInstance();
0114   analysis->book();
0115 }
0116 
0117 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0118 
0119 void XrayFluoRunAction::EndOfRunAction(const G4Run*)
0120 {
0121   XrayFluoAnalysisManager* analysis = XrayFluoAnalysisManager::getInstance();
0122   analysis->finish();
0123   // Run ended, update the visualization
0124   if (G4VVisManager::GetConcreteInstance()) {
0125     G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/update");
0126   }
0127 }
0128 
0129 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0130 
0131 
0132 const XrayFluoDataSet* XrayFluoRunAction::GetSet() const
0133 {
0134   return  dataSet;
0135 }
0136 
0137 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0138 
0139 const XrayFluoDataSet* XrayFluoRunAction::GetGammaSet() const
0140 {
0141   return  dataGammaSet;
0142 }
0143 
0144 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0145 
0146 const XrayFluoDataSet* XrayFluoRunAction::GetAlphaSet() const
0147 {
0148   return  dataAlphaSet;
0149 }
0150 
0151 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0152 
0153 G4DataVector* XrayFluoRunAction::GetEnergies() const
0154 {
0155   return energies;
0156 }
0157 
0158 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0159 
0160 G4DataVector* XrayFluoRunAction::GetData() const
0161 {
0162   return data;
0163 }
0164 
0165 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
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 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
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       // The file is organized into two columns:
0222       // 1st column is the energy
0223       // 2nd column is the corresponding value
0224       // The file terminates with the pattern: -1   -1
0225       //                                       -2   -2
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); // end of file
0251   
0252   file.close();
0253   G4cout << " done" << G4endl;
0254 }
0255 
0256 
0257 
0258 
0259 
0260 
0261 
0262 
0263 
0264 
0265 
0266 
0267 
0268