Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:21:10

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