Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-14 08:09:01

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 /// @file Analysis.cc
0028 /// @brief Define histograms
0029 
0030 #include "Analysis.hh"
0031 
0032 #include "TFile.h"
0033 #include "TH1.h"
0034 #include "TH2.h"
0035 #include "TROOT.h"
0036 
0037 #include "G4AutoLock.hh"
0038 #include "G4SystemOfUnits.hh"
0039 
0040 G4ThreadLocal G4int Analysis::fincidentFlag = false;
0041 G4ThreadLocal Analysis* the_analysis = 0;
0042 
0043 G4Mutex rootm = G4MUTEX_INITIALIZER;
0044 
0045 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0046 Analysis* Analysis::GetAnalysis()
0047 {
0048   if (!the_analysis) the_analysis = new Analysis;
0049   return the_analysis;
0050 }
0051 
0052 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0053 Analysis::Analysis()
0054 {
0055   G4AutoLock l(&rootm);
0056   // define histograms
0057   fincident_map = new TH2D("incident map", "Incident Distributuon", 50, -5., 5., 50, -5., 5.);
0058   fincident_map->GetXaxis()->SetTitle("X (cm)");
0059   fincident_map->GetYaxis()->SetTitle("Y (cm)");
0060   fincident_map->SetStats(0);
0061 
0062   fincident_x_hist = new TH1D("incident x", "Incident X", 100, -5., 5.);
0063   fincident_x_hist->GetXaxis()->SetTitle("X (cm)");
0064   fincident_x_hist->SetFillColor(kRed);
0065 
0066   fdose_map = new TH2D("dose map", "Dose Distribution", 500, 0., 50., 200, -10., 10.);
0067   fdose_map->GetXaxis()->SetTitle("Z (cm)");
0068   fdose_map->GetYaxis()->SetTitle("X (cm)");
0069   fdose_map->SetStats(0);
0070 
0071   fdose_hist = new TH1D("dose", "Dose Distribution", 500, 0., 50.);
0072   fdose_hist->GetXaxis()->SetTitle("Z (cm)");
0073   fdose_hist->GetYaxis()->SetTitle("Dose (GeV)");
0074   fdose_hist->SetFillColor(kBlue);
0075   fdose_hist->SetStats(0);
0076 }
0077 
0078 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0079 Analysis::~Analysis()
0080 {
0081   delete fincident_map;
0082   delete fincident_x_hist;
0083   delete fdose_map;
0084   delete fdose_hist;
0085 }
0086 
0087 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0088 void Analysis::Update()
0089 {
0090   return;
0091 }
0092 
0093 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0094 void Analysis::Clear()
0095 {
0096   fincident_map->Reset();
0097   fincident_x_hist->Reset();
0098   fdose_map->Reset();
0099   fdose_hist->Reset();
0100 
0101   return;
0102 }
0103 
0104 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0105 void Analysis::Save(const G4String& fname)
0106 {
0107   G4AutoLock l(&rootm);
0108   TFile* file = new TFile(fname.c_str(), "RECREATE", "Geant4 ROOT analysis");
0109 
0110   fincident_map->Write();
0111   fincident_x_hist->Write();
0112   fdose_map->Write();
0113   fdose_hist->Write();
0114 
0115   file->Close();
0116 
0117   delete file;
0118 
0119   return;
0120 }
0121 
0122 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0123 void Analysis::FillIncident(const G4ThreeVector& p)
0124 {
0125   if (!fincidentFlag) {
0126     fincident_map->Fill(p.x() / cm, p.y() / cm);
0127     fincident_x_hist->Fill(p.x() / cm);
0128 
0129     fincidentFlag = true;
0130   }
0131 }
0132 
0133 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0134 void Analysis::FillDose(const G4ThreeVector& p, G4double dedx)
0135 {
0136   const G4double Z0 = 25. * cm;
0137   const G4double dxy = 10. * mm;
0138 
0139   if (std::abs(p.y()) < dxy) {
0140     fdose_map->Fill((p.z() + Z0) / cm, p.x() / cm, dedx / GeV);
0141 
0142     if (std::abs(p.x()) < dxy) {
0143       fdose_hist->Fill((p.z() + Z0) / cm, dedx / GeV);
0144     }
0145   }
0146 }