Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-05 07:50:33

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 /// \file TrackingAction.cc
0027 /// \brief Implementation of the TrackingAction class
0028 
0029 #include "TrackingAction.hh"
0030 
0031 #include "DetectorConstruction.hh"
0032 #include "HistoManager.hh"
0033 #include "Run.hh"
0034 
0035 #include "G4PhysicalConstants.hh"
0036 #include "G4RunManager.hh"
0037 #include "G4SystemOfUnits.hh"
0038 #include "G4Track.hh"
0039 
0040 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0041 
0042 TrackingAction::TrackingAction(DetectorConstruction* DET) : fDetector(DET)
0043 {
0044   fZend = 0.5 * (fDetector->GetThicknessWorld());
0045 }
0046 
0047 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0048 
0049 void TrackingAction::PreUserTrackingAction(const G4Track*) {}
0050 
0051 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0052 
0053 void TrackingAction::PostUserTrackingAction(const G4Track* track)
0054 {
0055   G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
0056 
0057   G4double charge = track->GetDefinition()->GetPDGCharge();
0058   G4ThreeVector position = track->GetPosition();
0059   G4ThreeVector direction = track->GetMomentumDirection();
0060 
0061   if (charge == 0.0) return;
0062   if (position.z() < fZend) return;
0063   if (direction.z() <= 0.) return;
0064 
0065   G4double rmin, dr, ds;
0066   G4int ih = 1;
0067 
0068   // projected angle at exit
0069 
0070   G4double ux = direction.x(), uy = direction.y(), uz = direction.z();
0071   G4double thetax = std::atan(ux / uz);
0072   G4double thetay = std::atan(uy / uz);
0073   analysisManager->FillH1(ih, thetax);
0074   analysisManager->FillH1(ih, thetay);
0075 
0076   // dN/dS at exit
0077 
0078   G4double x = position.x(), y = position.y();
0079   G4double r = std::sqrt(x * x + y * y);
0080   ih = 2;
0081   dr = analysisManager->GetH1Width(ih);
0082   rmin = ((int)(r / dr)) * dr;
0083   ds = twopi * (rmin + 0.5 * dr) * dr;
0084   analysisManager->FillH1(ih, r, 1 / ds);
0085 
0086   // d(N/cost)/dS at exit
0087 
0088   ih = 3;
0089   dr = analysisManager->GetH1Width(ih);
0090   rmin = ((int)(r / dr)) * dr;
0091   ds = twopi * (rmin + 0.5 * dr) * dr;
0092   analysisManager->FillH1(ih, r, 1 / (uz * ds));
0093 
0094   // vector of d(N/cost)/dS at exit
0095 
0096   Run* run = static_cast<Run*>(G4RunManager::GetRunManager()->GetNonConstCurrentRun());
0097 
0098   run->SumFluence(r, 1 / uz);
0099 
0100   // space angle at exit : dN/dOmega
0101 
0102   ih = 5;
0103   G4double theta = std::acos(uz);
0104   if (theta > 0.) {
0105     G4double dtheta = analysisManager->GetH1Width(ih);
0106     G4double unit = analysisManager->GetH1Unit(ih);
0107     if (dtheta > 0.) {
0108       G4double weight = unit * unit / (twopi * std::sin(theta) * dtheta);
0109       analysisManager->FillH1(ih, theta, weight);
0110     }
0111   }
0112 
0113   // measured space angle at exit : dN/dOmega_meas
0114   //
0115   ih = 6;
0116   const G4double dist = fDetector->GetZdist_foil_detector();
0117   G4double thetam = std::atan(r / dist);
0118   if (thetam > 0.) {
0119     G4double dtheta = analysisManager->GetH1Width(ih);
0120     G4double unit = analysisManager->GetH1Unit(ih);
0121     if (dtheta > 0.) {
0122       G4double weight = unit * unit / (twopi * std::sin(thetam) * dtheta);
0123       analysisManager->FillH1(ih, thetam, weight);
0124     }
0125   }
0126 }
0127 
0128 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......