From 90834f22977dc46837cae752eed97fc9ba81eebd Mon Sep 17 00:00:00 2001
From: "audrey.chatillon" <audrey.chatillon@gmail.com>
Date: Thu, 23 Jan 2025 18:53:05 +0100
Subject: [PATCH] [EventGeneratorAlphaDecay] Force the GlobalTime to random
 following the decay law associated to the activity of the sample

---
 NPSimulation/Core/Particle.cc                 | 21 +++++++++++++++++++
 NPSimulation/Core/Particle.hh                 |  5 +++++
 NPSimulation/Core/ParticleStack.cc            |  3 ++-
 NPSimulation/Detectors/Epic/Epic.cc           |  4 ++--
 .../EventGeneratorAlphaDecay.cc               |  4 ++--
 .../EventGenerator/EventGeneratorBeam.cc      |  2 +-
 6 files changed, 33 insertions(+), 6 deletions(-)

diff --git a/NPSimulation/Core/Particle.cc b/NPSimulation/Core/Particle.cc
index 1915b4f32..f14ceca58 100644
--- a/NPSimulation/Core/Particle.cc
+++ b/NPSimulation/Core/Particle.cc
@@ -44,6 +44,17 @@ Particle::Particle(G4ParticleDefinition* particle,double ThetaCM,double T,G4Thre
   m_Position = Position;
   m_ShootStatus = ShootStatus;
 }
+//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
+Particle::Particle(G4ParticleDefinition* particle,double ThetaCM,double T,G4ThreeVector Direction, G4ThreeVector Position,double Delay,bool ShootStatus){
+  m_ParticleDefinition = particle;
+  m_ThetaCM = ThetaCM;
+  m_T = T;
+  m_Direction = Direction;
+  m_Position = Position;
+  m_TimeDelay = Delay;
+  m_ShootStatus = ShootStatus;
+}
+
 
 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 G4ParticleDefinition* Particle::GetParticleDefinition(){
@@ -60,6 +71,11 @@ double Particle::GetParticleKineticEnergy(){
   return m_T;
 }
 
+//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
+double Particle::GetParticleTimeDelay(){
+  return m_TimeDelay;
+}
+
 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 G4ThreeVector Particle::GetParticleMomentumDirection(){
   return m_Direction;
@@ -90,6 +106,11 @@ void Particle::SetParticleKineticEnergy(double T){
   m_T = T ;
 }
 
+//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
+void Particle::SetParticleTimeDelay(double delay){
+  m_TimeDelay = delay ;
+}
+
 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 void Particle::SetParticleMomentumDirection(G4ThreeVector Direction){
   m_Direction = Direction;
diff --git a/NPSimulation/Core/Particle.hh b/NPSimulation/Core/Particle.hh
index f7e46bbc2..ac01bfe0d 100644
--- a/NPSimulation/Core/Particle.hh
+++ b/NPSimulation/Core/Particle.hh
@@ -37,6 +37,8 @@ namespace NPS{
       ~Particle();
       //  Constructor to be used
       Particle(G4ParticleDefinition* particle,double ThetaCM,double T,G4ThreeVector Direction, G4ThreeVector Position,bool ShootStatus=true);
+      //  Constructor to be used for EventGeneratorAlphaDecay
+      Particle(G4ParticleDefinition* particle,double ThetaCM,double T,G4ThreeVector Direction, G4ThreeVector Position,double Delay,bool ShootStatus=true);
 
     private: // Private Member
       G4ParticleDefinition* m_ParticleDefinition;
@@ -44,6 +46,7 @@ namespace NPS{
       double m_T ;
       G4ThreeVector m_Direction;
       G4ThreeVector m_Position;
+      double m_TimeDelay;
       bool m_ShootStatus;
 
     public: // Setter and Getter
@@ -51,6 +54,7 @@ namespace NPS{
       G4ParticleDefinition*   GetParticleDefinition();
       double                  GetParticleThetaCM();
       double                  GetParticleKineticEnergy();
+      double                  GetParticleTimeDelay();
       G4ThreeVector           GetParticleMomentumDirection();
       G4ThreeVector           GetParticlePosition();
       bool                    GetShootStatus();
@@ -58,6 +62,7 @@ namespace NPS{
       void SetParticleDefinition(G4ParticleDefinition*);
       void SetParticleThetaCM(double);
       void SetParticleKineticEnergy(double);
+      void SetParticleTimeDelay(double);
       void SetParticlePosition(G4ThreeVector);
       void SetParticleMomentumDirection(G4ThreeVector);
       void SetShootStatus(bool);
diff --git a/NPSimulation/Core/ParticleStack.cc b/NPSimulation/Core/ParticleStack.cc
index d71dc8767..50ae210bd 100644
--- a/NPSimulation/Core/ParticleStack.cc
+++ b/NPSimulation/Core/ParticleStack.cc
@@ -113,7 +113,7 @@ void ParticleStack::AddBeamParticleToStack(NPS::Particle& particle){
     m_InitialConditions-> SetIncidentParticleName   (particle.GetParticleDefinition()->GetParticleName());
     //m_InitialConditions-> SetIncidentInitialKineticEnergy  (particle. GetParticleThetaCM());
     m_InitialConditions-> SetIncidentInitialKineticEnergy  (particle. GetParticleKineticEnergy());
-    
+
     G4ThreeVector U(1,0,0);
     G4ThreeVector V(0,1,0);
     
@@ -273,6 +273,7 @@ void ParticleStack::ShootAllParticle(G4Event* anEvent){
       m_particleGun->SetParticleEnergy(m_ParticleStack[i].GetParticleKineticEnergy());
       m_particleGun->SetParticleMomentumDirection(m_ParticleStack[i].GetParticleMomentumDirection());
       m_particleGun->SetParticlePosition(m_ParticleStack[i].GetParticlePosition());
+      if(m_ParticleStack[i].GetParticleTimeDelay()) m_particleGun->SetParticleTime(m_ParticleStack[i].GetParticleTimeDelay());
       m_particleGun->GeneratePrimaryVertex(anEvent);
       //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
       m_InitialConditions-> SetParticleName       ( m_ParticleStack[i].GetParticleDefinition()->GetParticleName()) ;
diff --git a/NPSimulation/Detectors/Epic/Epic.cc b/NPSimulation/Detectors/Epic/Epic.cc
index 6501596fc..a87b151f3 100644
--- a/NPSimulation/Detectors/Epic/Epic.cc
+++ b/NPSimulation/Detectors/Epic/Epic.cc
@@ -568,14 +568,14 @@ void Epic::ReadSensitive(const G4Event* ){
 	        continue;
         }
         else{ // FF or alpha
-          //cout << "[FF or alpha]step #" << j << " , particle name = " << step_name.at(j) << " , z = " << step_posZ.at(j) << " , dE = " << step_DE.at(j) << " , t = " << step_time.at(j) << endl;
+          //cout << "[FF or alpha]step #" << j << " , particle name = " << step_name.at(j) << ", z = " << step_posZ.at(j) << " , dE = " << step_DE.at(j) << " , t = " << step_time.at(j) << endl;
           influence += step_DE.at(j) * TMath::Abs(step_posZ.at(j) - posZ_anode);
           name.push_back(step_name.at(j));
           parentid.push_back(step_parentid.at(j));
           trackid.push_back(step_trackid.at(j));
           z.push_back(step_posZ.at(j));
           de.push_back(step_DE.at(j));
-          dt.push_back(step_time.at(j) - Scorer->GetTime(i)); // dt = time from the first step in SensitiveVolume
+          dt.push_back(step_time.at(j)); 
 	      }
       }
       m_Event->Set(m_mapping_A[Anode],              // set anode number
diff --git a/NPSimulation/EventGenerator/EventGeneratorAlphaDecay.cc b/NPSimulation/EventGenerator/EventGeneratorAlphaDecay.cc
index c9615e4a0..403b0a525 100644
--- a/NPSimulation/EventGenerator/EventGeneratorAlphaDecay.cc
+++ b/NPSimulation/EventGenerator/EventGeneratorAlphaDecay.cc
@@ -174,8 +174,8 @@ void EventGeneratorAlphaDecay::GenerateEvent(G4Event* evt){
       momentum_z = sin(theta) * sin(phi)  ;
       momentum_x = cos(theta)             ;
     }
-
-    NPS::Particle particle(m_particle, theta, particle_energy, G4ThreeVector(momentum_x, momentum_y, momentum_z), G4ThreeVector(x0, y0, z0));
+    //cout << "add an alpha particle to stack with global time = " << alpha_t << " s ==> " << alpha_t*1.e9 << " ns" << endl;
+    NPS::Particle particle(m_particle, theta, particle_energy, G4ThreeVector(momentum_x, momentum_y, momentum_z), G4ThreeVector(x0, y0, z0),alpha_t*1.e9,true);
     m_ParticleStack->AddParticleToStack(particle);
   }
 
diff --git a/NPSimulation/EventGenerator/EventGeneratorBeam.cc b/NPSimulation/EventGenerator/EventGeneratorBeam.cc
index a8684d28b..7421c05d6 100644
--- a/NPSimulation/EventGenerator/EventGeneratorBeam.cc
+++ b/NPSimulation/EventGenerator/EventGeneratorBeam.cc
@@ -112,7 +112,7 @@ void EventGeneratorBeam::GenerateEvent(G4Event* anEvent){
                         InitialBeamEnergy,
                         BeamDir.unit(),
                         BeamPos,
-                        1);
+                        true);
   
   m_ParticleStack->AddBeamParticleToStack(BeamParticle);
 
-- 
GitLab