Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:20:23

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 
0029 #include "TrackingAction.hh"
0030 #include "G4Track.hh"
0031 #include "G4VSolid.hh"
0032 #include "G4Region.hh"
0033 #include "G4Electron.hh"
0034 #include "G4Gamma.hh"
0035 #include "DetectorConstruction.hh"
0036 
0037 using namespace std;
0038 
0039 TrackingAction::TrackingAction(DetectorConstruction* detector)
0040 {
0041     fDetector = detector;
0042     fTargetRegion = 0;
0043 }
0044 
0045 TrackingAction::~TrackingAction()
0046 {
0047     fDetector = 0;
0048     fTargetRegion = 0;
0049 }
0050 
0051 void TrackingAction::PreUserTrackingAction(const G4Track* track)
0052 {
0053     const G4ParticleDefinition* particleDefinition = track->GetParticleDefinition();
0054 
0055     if(particleDefinition == G4Electron::Definition() || particleDefinition == G4Gamma::Definition())
0056     {
0057         if(fTargetRegion == 0) // target region is initialized after detector construction instantiation
0058         {
0059             fTargetRegion = fDetector->GetTargetRegion();
0060         }
0061 
0062         const G4ThreeVector& position = track->GetPosition();
0063 
0064         int N =  fTargetRegion->GetNumberOfRootVolumes();
0065         std::vector<G4LogicalVolume*>::iterator it_logicalVolumeInRegion =
0066                 fTargetRegion->GetRootLogicalVolumeIterator();
0067 
0068         bool inside_target = false;
0069 
0070         for(int i = 0; i < N ; i++, it_logicalVolumeInRegion++)
0071         {
0072             EInside test_status = (*it_logicalVolumeInRegion)->GetSolid()->Inside(position) ;
0073             if(test_status == kInside)
0074             {
0075                 inside_target = true;
0076                 break;
0077             }
0078             /*
0079             else if (test_status == kSurface)
0080             {
0081             }
0082             */
0083         }
0084 
0085         if(inside_target == true)
0086         {
0087             fNParticleInTarget[particleDefinition]++;
0088         }
0089         else
0090         {
0091             fNParticleInWorld[particleDefinition]++;
0092         }
0093     }
0094 }
0095