MdEdepSimulatorAG/SteppingAction.cc
Go to the documentation of this file.
1 #include "SteppingAction.h"
2 
3 #include <fwk/CentralConfig.h>
4 #include <utl/ErrorLogger.h>
5 #include <utl/Reader.h>
6 #include <utl/MathConstants.h>
7 
8 //G4 classes
9 #include <G4SteppingManager.hh>
10 #include <G4Track.hh>
11 #include <G4Step.hh>
12 #include <G4StepPoint.hh>
13 #include <G4TrackStatus.hh>
14 #include <G4VPhysicalVolume.hh>
15 #include <G4ParticleDefinition.hh>
16 #include <G4ParticleTypes.hh>
17 
18 #include <string>
19 using std::string;
20 
21 using namespace fwk;
22 using namespace utl;
23 using namespace EdepSimulatorAG;
24 
25 SteppingAction::SteppingAction () : fScintID(-1){}
26 
28 {;}
29 
30 void SteppingAction::UserSteppingAction ( const G4Step * theStep )
31 {
32  G4Track* theTrack = theStep->GetTrack ( );
33  G4double edep = theStep->GetTotalEnergyDeposit();
34 
35  if( !edep )
36  return;
37 
38  G4StepPoint * thePostPoint = theStep->GetPostStepPoint ( );
39  //G4VPhysicalVolume * thePostPV = thePostPoint->GetPhysicalVolume ( ); // Frank Schröder: commented since unused
40  G4ParticleDefinition * particleType = theTrack->GetDefinition ( );
41 
42  G4String process = "Undefined";
43  if ( thePostPoint->GetProcessDefinedStep() != NULL)
44  process = thePostPoint->GetProcessDefinedStep()->GetProcessName();
45 
46  G4double x = theStep->GetPostStepPoint()->GetPosition().x();
47  G4double y = theStep->GetPostStepPoint()->GetPosition().y();
48  G4double z = theStep->GetPostStepPoint()->GetPosition().z();
49  G4VPhysicalVolume *thePrePV = theStep->GetPreStepPoint ( )->GetPhysicalVolume ( );
50  string prePVName = string (thePrePV->GetName());
51  string postPVName = "OutOfWorld";
52 
53  G4int trackid = theTrack->GetTrackID();
54  G4int parentid = theTrack->GetParentID();
55 
56  int sId = fScintID; // fScintID is [1-64] by construction
57 
58  if ( prePVName == "RightScint" )
59  sId += 1;
60  else if ( prePVName == "LeftScint" )
61  sId -= 1;
62 
63  //do not add virtual strips
64  if( sId == 65 || sId == 0 )// strips 0 and 65 are always virtual
65  return;
66  else if( fScintID == 32 && sId == 33 ) // 33 is virtual for strips in the range [1-32]
67  return;
68  else if( fScintID == 33 && sId == 32 ) // 32 is virtual for strips in the range [33-64]
69  return;
70 
71  //If scintillator Id (key) not found, then creates the key
72  if ( fScintMap.find( sId ) == fScintMap.end()){
73  DataCollection nuovo;
74  // G4cerr << "Scinti ID not found... I will creat it" << G4endl;
75  fScintMap[sId] = nuovo;
76  //TODO: keep the identity of the "primary" impinging particle.
77  //should have partenID == 0 for central scintillator but not so for right and left scintillators
78  }
79 
80  Data stepd;
81  //Fill obj with relevant step data
82  stepd.Sname = prePVName;
83  stepd.Pname = particleType->GetParticleName();
84  stepd.PDGCode = particleType->GetPDGEncoding();
85  stepd.ParentID= parentid;
86  stepd.TrackID = trackid;
87  stepd.x = x;
88  stepd.y = y;
89  stepd.z = z;
90  stepd.px = theStep->GetPreStepPoint()->GetMomentumDirection().x();
91  stepd.py = theStep->GetPreStepPoint()->GetMomentumDirection().y();
92  stepd.pz = theStep->GetPreStepPoint()->GetMomentumDirection().z();
93  stepd.KinE = theStep->GetPreStepPoint()->GetKineticEnergy();
94  stepd.Edep = edep;
95  stepd.Time = theStep->GetPreStepPoint()->GetGlobalTime();
96 
97  //Fill the vector with the data of a given scintillator
98  fScintMap[sId].push_back( stepd );
99 /*
100  G4cerr << "\n===========================================\n";
101  G4cerr << " PARTICLE CROSSING A SCINTILLATOR STRIP!!!! \n";
102  G4cerr << particleType->GetParticleName() << " ";
103  G4cerr << "PDG code: " << particleType->GetPDGEncoding() << " ";
104  G4cerr << "prePV: " << prePVName << " ";
105  G4cerr << "trackID " << trackid << G4endl;
106  G4cerr << "Edep " << edep/CLHEP::MeV << G4endl;
107  G4cerr << "X:" << x/CLHEP::m << " m ";
108  G4cerr << "Y:" << y/CLHEP::m << " m ";
109  G4cerr << "Z:" << z/CLHEP::m << " m " << G4endl;
110  G4cerr << "===========================================\n";
111 */
112  return;
113 
114 }

, generated on Tue Sep 26 2023.