Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-03-28 07:49:53

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 GB03HodoSD.cc
0027 /// \brief Implementation of the GB03HodoSD class
0028 
0029 #include "GB03HodoSD.hh"
0030 
0031 #include "GB03DetectorConstruction.hh"
0032 #include "GB03Run.hh"
0033 
0034 #include "G4RunManager.hh"
0035 #include "G4SDManager.hh"
0036 #include "G4Step.hh"
0037 #include "G4SystemOfUnits.hh"
0038 #include "G4Track.hh"
0039 
0040 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0041 
0042 GB03HodoSD::GB03HodoSD(G4String name) : G4VSensitiveDetector(name)
0043 {
0044   collectionName.insert("Leaving");  // Paricles leaving the shield
0045 }
0046 
0047 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0048 
0049 void GB03HodoSD::Initialize(G4HCofThisEvent* hce)
0050 {
0051   auto rm = G4RunManager::GetRunManager();
0052   fRun = static_cast<GB03Run*>(rm->GetNonConstCurrentRun());
0053   auto det = static_cast<const GB03DetectorConstruction*>(rm->GetUserDetectorConstruction());
0054   fVerbose = det->GetVerboseLevel();
0055   // Create hits collection
0056   fHitsCollection = new GB03HodoHitsCollection(SensitiveDetectorName, collectionName[0]);
0057 
0058   // Add this collection in hce
0059   auto hcID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]);
0060   hce->AddHitsCollection(hcID, fHitsCollection);
0061 }
0062 
0063 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0064 
0065 G4bool GB03HodoSD::ProcessHits(G4Step* step, G4TouchableHistory*)
0066 {
0067   if (!step->IsFirstStepInVolume()) return false;
0068 
0069   auto track = step->GetTrack();
0070   auto preStepPoint = step->GetPreStepPoint();
0071   auto pname = track->GetParticleDefinition()->GetParticleName();
0072   auto pid = track->GetParticleDefinition()->GetPDGEncoding();
0073   auto weight = preStepPoint->GetWeight();
0074   auto Ekin = preStepPoint->GetKineticEnergy() / MeV;
0075   auto pos = preStepPoint->GetPosition();
0076 
0077   fRun->CountParticle(pname, weight, Ekin);
0078 
0079   auto hodoHit = new GB03HodoHit();
0080   hodoHit->Set(pid, Ekin, weight, pos);
0081   fHitsCollection->insert(hodoHit);
0082 
0083   if (fVerbose > 1) {
0084     G4cout << std::setw(7) << pid << std::setw(14) << pname
0085            << ", kinetic energy (MeV) = " << std::setw(12) << Ekin
0086            << ", position (cm) = " << pos / cm << std::setw(10) << "weight = " << std::setw(10)
0087            << weight << G4endl;
0088   }
0089   return true;
0090 }
0091 
0092 void GB03HodoSD::PrintAll()
0093 {
0094   G4cout << GetFullPathName() << " No of Col " << GetNumberOfCollections() << G4endl;
0095 }
0096 
0097 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......