Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-09 08:28:20

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 "HistoManager.hh"
0032 #include "PrimaryGeneratorAction.hh"
0033 #include "PrimaryGeneratorAction2.hh"
0034 #include "PrimaryGeneratorAction3.hh"
0035 #include "PrimaryGeneratorAction4.hh"
0036 #include "RunAction.hh"
0037 
0038 #include "G4PhysicalConstants.hh"
0039 #include "G4Track.hh"
0040 
0041 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0042 
0043 TrackingAction::TrackingAction(PrimaryGeneratorAction* prim) : fPrimary(prim)
0044 {
0045   // parameters for generator action #3
0046   fNewUz = fPrimary->GetAction3()->GetNewUz();
0047 }
0048 
0049 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0050 
0051 void TrackingAction::PreUserTrackingAction(const G4Track* track)
0052 {
0053   G4int selectedGeneratorAction = fPrimary->GetSelectedAction();
0054   G4AnalysisManager* analysis = G4AnalysisManager::Instance();
0055   G4int id = 0;
0056 
0057   if (selectedGeneratorAction == 2) {
0058     // energy spectrum
0059     //
0060     id = 1;
0061     analysis->FillH1(id, track->GetKineticEnergy());
0062   }
0063 
0064   else if (selectedGeneratorAction == 0) {
0065     // particle direction: cos(alpha)
0066     //
0067     id = 5;
0068     G4ThreeVector um = track->GetMomentumDirection();
0069     G4double cosalpha = um.z();
0070     analysis->FillH1(id, cosalpha);
0071 
0072     // particle direction: psi
0073     //
0074     id = 6;
0075     G4double psi = std::atan2(um.y(), um.x());
0076     if (psi < 0.) psi += twopi;
0077     analysis->FillH1(id, psi);
0078   }
0079   else if (selectedGeneratorAction == 3) {
0080     // particle direction in local frame: cos(alpha)
0081     //
0082     id = 5;
0083     G4ThreeVector um = track->GetMomentumDirection();
0084     G4double cosalpha = fNewUz * um;
0085     analysis->FillH1(id, cosalpha);
0086 
0087     // particle direction in local frame: psi
0088     //
0089     id = 6;
0090     // complete local frame
0091     G4ThreeVector u1(1., 0., 0.);
0092     u1.rotateUz(fNewUz);
0093     G4ThreeVector u2(0., 1., 0.);
0094     u2.rotateUz(fNewUz);
0095     //
0096     G4double psi = std::atan2(u2 * um, u1 * um);
0097     if (psi < 0.) psi += twopi;
0098     analysis->FillH1(id, psi);
0099   }
0100 
0101   else if (selectedGeneratorAction == 4) {
0102     G4ThreeVector vertex = track->GetVertexPosition();
0103     G4double r = vertex.mag();
0104     if (r <= 0.0) return;
0105     // local frame : new uz = ur
0106     G4ThreeVector ur = vertex / r;
0107 
0108     // vertex position. radial distribution dN/dv = f(r)
0109     //
0110     id = 2;
0111     G4double dr = analysis->GetH1Width(id);
0112     G4double dv = 2 * twopi * r * r * dr;
0113     if (dv > 0.) analysis->FillH1(id, r, 1. / dv);
0114 
0115     // vertex position: cos(theta)
0116     //
0117     id = 3;
0118     G4double costheta = ur.z();
0119     analysis->FillH1(id, costheta);
0120 
0121     // vertex position: phi
0122     //
0123     id = 4;
0124     G4double phi = std::atan2(ur.y(), ur.x());
0125     if (phi < 0.) phi += twopi;
0126     analysis->FillH1(id, phi);
0127 
0128     // particle direction in local frame: cos(alpha)
0129     //
0130     id = 5;
0131     G4ThreeVector um = track->GetMomentumDirection();
0132     G4double cosalpha = ur * um;
0133     analysis->FillH1(id, cosalpha);
0134 
0135     // particle direction in local frame: psi
0136     //
0137     id = 6;
0138     // complete local frame
0139     G4ThreeVector u1(1., 0., 0.);
0140     u1.rotateUz(ur);
0141     G4ThreeVector u2(0., 1., 0.);
0142     u2.rotateUz(ur);
0143     //
0144     G4double psi = std::atan2(u2 * um, u1 * um);
0145     if (psi < 0.) psi += twopi;
0146     analysis->FillH1(id, psi);
0147   }
0148 }
0149 
0150 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0151 
0152 void TrackingAction::PostUserTrackingAction(const G4Track*) {}
0153 
0154 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......