Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-18 08:32:52

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 Par02FastSimModelEMCal.cc
0027 /// \brief Implementation of the Par02FastSimModelEMCal class
0028 
0029 #include "Par02FastSimModelEMCal.hh"
0030 
0031 #include "Par02EventInformation.hh"
0032 #include "Par02Output.hh"
0033 #include "Par02PrimaryParticleInformation.hh"
0034 #include "Par02Smearer.hh"
0035 
0036 #include "G4AnalysisManager.hh"
0037 #include "G4Electron.hh"
0038 #include "G4Event.hh"
0039 #include "G4Gamma.hh"
0040 #include "G4Positron.hh"
0041 #include "G4RunManager.hh"
0042 #include "G4SystemOfUnits.hh"
0043 #include "G4Track.hh"
0044 #include "Randomize.hh"
0045 
0046 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0047 
0048 Par02FastSimModelEMCal::Par02FastSimModelEMCal(G4String aModelName, G4Region* aEnvelope,
0049                                                Par02DetectorParametrisation::Parametrisation aType)
0050   : G4VFastSimulationModel(aModelName, aEnvelope),
0051     fCalculateParametrisation(),
0052     fParametrisation(aType)
0053 {}
0054 
0055 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0056 
0057 Par02FastSimModelEMCal::Par02FastSimModelEMCal(G4String aModelName, G4Region* aEnvelope)
0058   : G4VFastSimulationModel(aModelName, aEnvelope),
0059     fCalculateParametrisation(),
0060     fParametrisation(Par02DetectorParametrisation::eCMS)
0061 {}
0062 
0063 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0064 
0065 Par02FastSimModelEMCal::Par02FastSimModelEMCal(G4String aModelName)
0066   : G4VFastSimulationModel(aModelName),
0067     fCalculateParametrisation(),
0068     fParametrisation(Par02DetectorParametrisation::eCMS)
0069 {}
0070 
0071 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0072 
0073 Par02FastSimModelEMCal::~Par02FastSimModelEMCal() = default;
0074 
0075 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0076 
0077 G4bool Par02FastSimModelEMCal::IsApplicable(const G4ParticleDefinition& aParticleType)
0078 {
0079   // Applicable for electrons, positrons, and gammas
0080   return &aParticleType == G4Electron::Definition() || &aParticleType == G4Positron::Definition()
0081          || &aParticleType == G4Gamma::Definition();
0082 }
0083 
0084 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0085 
0086 G4bool Par02FastSimModelEMCal::ModelTrigger(const G4FastTrack& /*aFastTrack*/)
0087 {
0088   return true;  // No kinematical restrictions to apply the parametrisation
0089 }
0090 
0091 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0092 
0093 void Par02FastSimModelEMCal::DoIt(const G4FastTrack& aFastTrack, G4FastStep& aFastStep)
0094 {
0095   // G4cout << " ________EMCal model triggered _________" << G4endl;
0096 
0097   // Kill the parameterised particle at the entrance of the electromagnetic calorimeter
0098   aFastStep.KillPrimaryTrack();
0099   aFastStep.ProposePrimaryTrackPathLength(0.0);
0100   G4double Edep = aFastTrack.GetPrimaryTrack()->GetKineticEnergy();
0101 
0102   // Consider only primary tracks (do nothing else for secondary e-, e+, gammas)
0103   G4ThreeVector Pos = aFastTrack.GetPrimaryTrack()->GetPosition();
0104   if (!aFastTrack.GetPrimaryTrack()->GetParentID()) {
0105     auto info = (Par02EventInformation*)G4EventManager::GetEventManager()->GetUserInformation();
0106     if (info->GetDoSmearing()) {
0107       // Smearing according to the electromagnetic calorimeter resolution
0108       G4ThreeVector Porg = aFastTrack.GetPrimaryTrack()->GetMomentum();
0109       G4double res = fCalculateParametrisation->GetResolution(Par02DetectorParametrisation::eEMCAL,
0110                                                               fParametrisation, Porg.mag());
0111       G4double eff = fCalculateParametrisation->GetEfficiency(Par02DetectorParametrisation::eEMCAL,
0112                                                               fParametrisation, Porg.mag());
0113       G4double Esm;
0114       Esm = std::abs(Par02Smearer::Instance()->SmearEnergy(aFastTrack.GetPrimaryTrack(), res));
0115       Par02Output::Instance()->FillHistogram(1, (Esm / MeV) / (Edep / MeV));
0116       // Setting the values of Pos, Esm, res and eff
0117       ((Par02PrimaryParticleInformation*)(const_cast<G4PrimaryParticle*>(
0118                                             aFastTrack.GetPrimaryTrack()
0119                                               ->GetDynamicParticle()
0120                                               ->GetPrimaryParticle())
0121                                             ->GetUserInformation()))
0122         ->SetEMCalPosition(Pos);
0123       ((Par02PrimaryParticleInformation*)(const_cast<G4PrimaryParticle*>(
0124                                             aFastTrack.GetPrimaryTrack()
0125                                               ->GetDynamicParticle()
0126                                               ->GetPrimaryParticle())
0127                                             ->GetUserInformation()))
0128         ->SetEMCalEnergy(Esm);
0129       ((Par02PrimaryParticleInformation*)(const_cast<G4PrimaryParticle*>(
0130                                             aFastTrack.GetPrimaryTrack()
0131                                               ->GetDynamicParticle()
0132                                               ->GetPrimaryParticle())
0133                                             ->GetUserInformation()))
0134         ->SetEMCalResolution(res);
0135       ((Par02PrimaryParticleInformation*)(const_cast<G4PrimaryParticle*>(
0136                                             aFastTrack.GetPrimaryTrack()
0137                                               ->GetDynamicParticle()
0138                                               ->GetPrimaryParticle())
0139                                             ->GetUserInformation()))
0140         ->SetEMCalEfficiency(eff);
0141       // The (smeared) energy of the particle is deposited in the step
0142       // (which corresponds to the entrance of the electromagnetic calorimeter)
0143       aFastStep.ProposeTotalEnergyDeposited(Esm);
0144     }
0145     else {
0146       // No smearing: simply setting the value of Edep
0147       ((Par02PrimaryParticleInformation*)(const_cast<G4PrimaryParticle*>(
0148                                             aFastTrack.GetPrimaryTrack()
0149                                               ->GetDynamicParticle()
0150                                               ->GetPrimaryParticle())
0151                                             ->GetUserInformation()))
0152         ->SetEMCalEnergy(Edep);
0153       // The (initial) energy of the particle is deposited in the step
0154       // (which corresponds to the entrance of the electromagnetic calorimeter)
0155       aFastStep.ProposeTotalEnergyDeposited(Edep);
0156     }
0157   }
0158 }
0159 
0160 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......