Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:17:11

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 XraySPOSteppingAction.cc
0027 /// \brief Implementation of the SteppingAction class
0028 //
0029 // Authors: P.Dondero (paolo.dondero@cern.ch), R.Stanzani (ronny.stanzani@cern.ch)
0030 //
0031 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0032 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0033 
0034 
0035 #include "XraySPOSteppingAction.hh"
0036 #include "XraySPODetectorConstruction.hh"
0037 #include "XraySPOHistoManager.hh"
0038 #include "G4SteppingManager.hh"
0039 #include "G4RunManager.hh"
0040 #include "Randomize.hh"
0041 
0042 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0043 
0044 void XraySPOSteppingAction::UserSteppingAction(const G4Step* step)
0045 {
0046   G4int parentID = step->GetTrack()->GetParentID();
0047 
0048   // Only primaries
0049   if (parentID == 0)
0050   {
0051     G4RunManager *rm = G4RunManager::GetRunManager();
0052     G4int eventID = rm->GetCurrentEvent()->GetEventID();
0053 
0054     G4double len_fraction = 0.1; // approx 1/20 of the lenght of the pore. Particles scatters an avg of 5 times, so by selecting all events with a distance >10mm we have all the scatters inside.
0055     G4bool proceed = false;
0056 
0057     if (fPrevEventID != eventID)
0058     {
0059       fNumReflections = -2;
0060     }
0061 
0062     G4ThreeVector direction = step->GetTrack()->GetMomentumDirection();
0063     auto theta = (G4double)direction.theta();
0064     auto phi = (G4double)direction.phi();
0065 
0066     G4double x = step->GetPreStepPoint()->GetPosition().x();
0067     G4double y = step->GetPreStepPoint()->GetPosition().y();
0068     G4double z = step->GetPreStepPoint()->GetPosition().z();
0069 
0070     const G4String& vol_name = step->GetTrack()->GetVolume()->GetName();
0071     G4int trackid = step->GetTrack()->GetTrackID();
0072 
0073     G4StepPoint * postStep = step->GetPostStepPoint();
0074     G4StepPoint* post_point = step->GetPostStepPoint();
0075 
0076     const G4String& proc_name = postStep->GetProcessDefinedStep()->GetProcessName();
0077 
0078     // Count the number of reflections
0079     G4String s = "";
0080     G4String& post_phys_name = s;
0081     if (fPrevEventID == eventID && step->GetStepLength() >= len_fraction)
0082     {
0083       if (post_point != nullptr)
0084       {
0085         G4VPhysicalVolume* post_phys = post_point->GetPhysicalVolume();
0086         if (post_phys != nullptr)
0087         {
0088           post_phys_name = post_phys->GetName();
0089         }
0090 
0091         if (post_phys_name == "cone_1" || post_phys_name == "cone_2" || post_phys_name == "cone_3" || post_phys_name == "cone_4" || post_phys_name == "cone_5" || post_phys_name == "cone_6" || post_phys_name == "cone_7" || post_phys_name == "cone_8")
0092         {
0093           if (fNumReflections < 0)
0094           {
0095             fNumReflections = 1;
0096           }
0097           else
0098           {
0099             fNumReflections += 1;
0100           }
0101           proceed = true;
0102         }
0103       }
0104     }
0105 
0106     if (vol_name == "pDummyEntrance" || vol_name == "pDummyExit" || vol_name == "pDummySphere")
0107     {
0108       proceed = true;
0109     }
0110 
0111     if (proceed)
0112     {
0113       // G4cout << "Save with " << fNumReflections << " reflections" << G4endl;
0114       G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
0115       analysisManager->FillNtupleIColumn(0, eventID);
0116       analysisManager->FillNtupleSColumn(1, vol_name);
0117       analysisManager->FillNtupleIColumn(2, trackid);
0118       analysisManager->FillNtupleDColumn(3, x);
0119       analysisManager->FillNtupleDColumn(4, y);
0120       analysisManager->FillNtupleDColumn(5, z);
0121       analysisManager->FillNtupleDColumn(6, theta);
0122       analysisManager->FillNtupleDColumn(7, phi);
0123       analysisManager->FillNtupleSColumn(8, proc_name);
0124       analysisManager->FillNtupleIColumn(9, parentID);
0125       analysisManager->FillNtupleIColumn(10, fNumReflections);
0126       analysisManager->AddNtupleRow();
0127     }
0128     fPrevx = x;
0129     fPrevy = y;
0130     fPrevz = z;
0131     fPrevEventID = eventID;
0132   }
0133 }
0134 
0135 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......