Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:22:32

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 Par01/src/Par01PionShowerModel.cc
0027 /// \brief Implementation of the Par01PionShowerModel class
0028 //
0029 //
0030 //
0031 #include "Par01PionShowerModel.hh"
0032 
0033 #include "Par01EnergySpot.hh"
0034 
0035 #include "G4Colour.hh"
0036 #include "G4PhysicalConstants.hh"
0037 #include "G4PionMinus.hh"
0038 #include "G4PionPlus.hh"
0039 #include "G4SystemOfUnits.hh"
0040 #include "G4TouchableHistory.hh"
0041 #include "G4TransportationManager.hh"
0042 #include "G4VSensitiveDetector.hh"
0043 #include "Randomize.hh"
0044 
0045 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0046 
0047 Par01PionShowerModel::Par01PionShowerModel(G4String modelName, G4Region* envelope)
0048   : G4VFastSimulationModel(modelName, envelope)
0049 {
0050   fFakeStep = new G4Step();
0051   fFakePreStepPoint = fFakeStep->GetPreStepPoint();
0052   fFakePostStepPoint = fFakeStep->GetPostStepPoint();
0053   fTouchableHandle = new G4TouchableHistory();
0054   fpNavigator = new G4Navigator();
0055   fNaviSetup = false;
0056 }
0057 
0058 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0059 
0060 Par01PionShowerModel::Par01PionShowerModel(G4String modelName) : G4VFastSimulationModel(modelName)
0061 {
0062   fFakeStep = new G4Step();
0063   fFakePreStepPoint = fFakeStep->GetPreStepPoint();
0064   fFakePostStepPoint = fFakeStep->GetPostStepPoint();
0065   fTouchableHandle = new G4TouchableHistory();
0066   fpNavigator = new G4Navigator();
0067   fNaviSetup = false;
0068 }
0069 
0070 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0071 
0072 Par01PionShowerModel::~Par01PionShowerModel()
0073 {
0074   delete fFakeStep;
0075   delete fpNavigator;
0076 }
0077 
0078 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0079 
0080 G4bool Par01PionShowerModel::IsApplicable(const G4ParticleDefinition& particleType)
0081 {
0082   return &particleType == G4PionMinus::PionMinusDefinition()
0083          || &particleType == G4PionPlus::PionPlusDefinition();
0084 }
0085 
0086 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0087 
0088 G4bool Par01PionShowerModel::ModelTrigger(const G4FastTrack&)
0089 {
0090   // Applies the parameterisation always:
0091   // ie as soon as the pion enters the envelope
0092   return true;
0093 }
0094 
0095 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0096 
0097 void Par01PionShowerModel::DoIt(const G4FastTrack& fastTrack, G4FastStep& fastStep)
0098 {
0099   //  G4cout << "Par01PionShowerModel::DoIt" << G4endl;
0100 
0101   // Kill the parameterised particle:
0102   fastStep.KillPrimaryTrack();
0103   fastStep.ProposePrimaryTrackPathLength(0.0);
0104   fastStep.ProposeTotalEnergyDeposited(fastTrack.GetPrimaryTrack()->GetKineticEnergy());
0105 
0106   // split into "energy spots" energy according to the shower shape:
0107   Explode(fastTrack);
0108 
0109   // and put those energy spots into the crystals:
0110   BuildDetectorResponse();
0111 }
0112 
0113 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0114 
0115 void Par01PionShowerModel::Explode(const G4FastTrack& fastTrack)
0116 {
0117   //-----------------------------------------------------
0118   // Non-physical shower generated: exp along z and
0119   // transverse.
0120   //-----------------------------------------------------
0121 
0122   // center of the shower, we put at the middle of the ghost:
0123   G4ThreeVector showerCenter;
0124   G4double distOut;
0125   distOut = fastTrack.GetEnvelopeSolid()->DistanceToOut(fastTrack.GetPrimaryTrackLocalPosition(),
0126                                                         fastTrack.GetPrimaryTrackLocalDirection());
0127   showerCenter = fastTrack.GetPrimaryTrackLocalPosition()
0128                  + (distOut / 2.) * fastTrack.GetPrimaryTrackLocalDirection();
0129 
0130   showerCenter = fastTrack.GetInverseAffineTransformation()->TransformPoint(showerCenter);
0131 
0132   // axis of the shower, in global reference frame:
0133   G4ThreeVector xShower, yShower, zShower;
0134   zShower = fastTrack.GetPrimaryTrack()->GetMomentumDirection();
0135   xShower = zShower.orthogonal();
0136   yShower = zShower.cross(xShower);
0137 
0138   // shoot the energy spots:
0139   G4double Energy = fastTrack.GetPrimaryTrack()->GetKineticEnergy();
0140   G4int nSpot = 50;
0141   G4double deposit = Energy / double(nSpot);
0142   Par01EnergySpot eSpot;
0143   eSpot.SetEnergy(deposit);
0144   G4ThreeVector ePoint;
0145 
0146   // clear the spot list before use
0147   feSpotList.clear();
0148 
0149   G4double z, r, phi;
0150   for (int i = 0; i < nSpot; i++) {
0151     z = G4RandGauss::shoot(0, 20 * cm);
0152     r = G4RandGauss::shoot(0, 10 * cm);
0153     phi = G4UniformRand() * twopi;
0154     ePoint = showerCenter + z * zShower + r * std::cos(phi) * xShower + r * std::sin(phi) * yShower;
0155     eSpot.SetPosition(ePoint);
0156     feSpotList.push_back(eSpot);
0157   }
0158 }
0159 
0160 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0161 
0162 void Par01PionShowerModel::BuildDetectorResponse()
0163 {
0164   // Does the assignation of the energy spots to the sensitive volumes:
0165   for (size_t i = 0; i < feSpotList.size(); i++) {
0166     // Draw the energy spot:
0167     //      G4Colour red(1.,0.,0.);
0168     //      feSpotList[i].Draw(&red);
0169     //      feSpotList[i].Print();
0170 
0171     // "converts" the energy spot into the fake
0172     // G4Step to pass to sensitive detector:
0173     AssignSpotAndCallHit(feSpotList[i]);
0174   }
0175 }
0176 
0177 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0178 
0179 void Par01PionShowerModel::AssignSpotAndCallHit(const Par01EnergySpot& eSpot)
0180 {
0181   //
0182   // "converts" the energy spot into the fake
0183   // G4Step to pass to sensitive detector:
0184   //
0185   FillFakeStep(eSpot);
0186 
0187   //
0188   // call sensitive part: taken/adapted from the stepping:
0189   // Send G4Step information to Hit/Dig if the volume is sensitive
0190   //
0191   G4VPhysicalVolume* pCurrentVolume = fFakeStep->GetPreStepPoint()->GetPhysicalVolume();
0192   G4VSensitiveDetector* pSensitive;
0193 
0194   if (pCurrentVolume != nullptr) {
0195     pSensitive = pCurrentVolume->GetLogicalVolume()->GetSensitiveDetector();
0196     if (pSensitive != nullptr) {
0197       pSensitive->Hit(fFakeStep);
0198     }
0199   }
0200 }
0201 
0202 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0203 
0204 void Par01PionShowerModel::FillFakeStep(const Par01EnergySpot& eSpot)
0205 {
0206   //-----------------------------------------------------------
0207   // find in which volume the spot is.
0208   //-----------------------------------------------------------
0209   if (!fNaviSetup) {
0210     fpNavigator->SetWorldVolume(G4TransportationManager::GetTransportationManager()
0211                                   ->GetNavigatorForTracking()
0212                                   ->GetWorldVolume());
0213     fpNavigator->LocateGlobalPointAndUpdateTouchableHandle(
0214       eSpot.GetPosition(), G4ThreeVector(0., 0., 0.), fTouchableHandle, false);
0215     fNaviSetup = true;
0216   }
0217   else {
0218     fpNavigator->LocateGlobalPointAndUpdateTouchableHandle(
0219       eSpot.GetPosition(), G4ThreeVector(0., 0., 0.), fTouchableHandle);
0220   }
0221   //--------------------------------------
0222   // Fills attribute of the G4Step needed
0223   // by our sensitive detector:
0224   //-------------------------------------
0225   // set touchable volume at PreStepPoint:
0226   fFakePreStepPoint->SetTouchableHandle(fTouchableHandle);
0227   // set total energy deposit:
0228   fFakeStep->SetTotalEnergyDeposit(eSpot.GetEnergy());
0229 }