Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-01 07:39:07

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 LXePMTSD.cc
0027 /// \brief Implementation of the LXePMTSD class
0028 
0029 #include "LXePMTSD.hh"
0030 
0031 #include "LXeDetectorConstruction.hh"
0032 #include "LXePMTHit.hh"
0033 #include "LXeUserTrackInformation.hh"
0034 
0035 #include "G4LogicalVolume.hh"
0036 #include "G4ParticleDefinition.hh"
0037 #include "G4ParticleTypes.hh"
0038 #include "G4SDManager.hh"
0039 #include "G4Step.hh"
0040 #include "G4TouchableHistory.hh"
0041 #include "G4Track.hh"
0042 #include "G4VPhysicalVolume.hh"
0043 #include "G4VTouchable.hh"
0044 #include "G4ios.hh"
0045 
0046 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0047 
0048 LXePMTSD::LXePMTSD(G4String name) : G4VSensitiveDetector(name)
0049 {
0050   collectionName.insert("pmtHitCollection");
0051 }
0052 
0053 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0054 
0055 LXePMTSD::~LXePMTSD()
0056 {
0057   delete fPMTPositionsX;
0058   delete fPMTPositionsY;
0059   delete fPMTPositionsZ;
0060 }
0061 
0062 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0063 
0064 void LXePMTSD::SetPmtPositions(const std::vector<G4ThreeVector>& positions)
0065 {
0066   for (size_t i = 0; i < positions.size(); ++i) {
0067     if (fPMTPositionsX) fPMTPositionsX->push_back(positions[i].x());
0068     if (fPMTPositionsY) fPMTPositionsY->push_back(positions[i].y());
0069     if (fPMTPositionsZ) fPMTPositionsZ->push_back(positions[i].z());
0070   }
0071 }
0072 
0073 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0074 
0075 void LXePMTSD::Initialize(G4HCofThisEvent* hitsCE)
0076 {
0077   fPMTHitCollection = new LXePMTHitsCollection(SensitiveDetectorName, collectionName[0]);
0078 
0079   if (fHitCID < 0) {
0080     fHitCID = G4SDManager::GetSDMpointer()->GetCollectionID(fPMTHitCollection);
0081   }
0082   hitsCE->AddHitsCollection(fHitCID, fPMTHitCollection);
0083 }
0084 
0085 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0086 
0087 G4bool LXePMTSD::ProcessHits(G4Step*, G4TouchableHistory*)
0088 {
0089   return false;
0090 }
0091 
0092 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0093 
0094 // Generates a hit and uses the postStepPoint's mother volume replica number
0095 // PostStepPoint because the hit is generated manually when the photon is
0096 // absorbed by the photocathode
0097 
0098 G4bool LXePMTSD::ProcessHits_boundary(const G4Step* aStep, G4TouchableHistory*)
0099 {
0100   // need to know if this is an optical photon
0101   if (aStep->GetTrack()->GetDefinition() != G4OpticalPhoton::OpticalPhotonDefinition())
0102     return false;
0103 
0104   // User replica number 1 since photocathode is a daughter volume
0105   // to the pmt which was replicated
0106   G4int pmtNumber = aStep->GetPostStepPoint()->GetTouchable()->GetReplicaNumber(1);
0107   G4VPhysicalVolume* physVol = aStep->GetPostStepPoint()->GetTouchable()->GetVolume(1);
0108 
0109   // Find the correct hit collection
0110   size_t n = fPMTHitCollection->entries();
0111   LXePMTHit* hit = nullptr;
0112   for (size_t i = 0; i < n; ++i) {
0113     if ((*fPMTHitCollection)[i]->GetPMTNumber() == pmtNumber) {
0114       hit = (*fPMTHitCollection)[i];
0115       break;
0116     }
0117   }
0118 
0119   if (hit == nullptr) {  // this pmt wasn't previously hit in this event
0120     hit = new LXePMTHit();  // so create new hit
0121     hit->SetPMTNumber(pmtNumber);
0122     hit->SetPMTPhysVol(physVol);
0123     fPMTHitCollection->insert(hit);
0124     hit->SetPMTPos((*fPMTPositionsX)[pmtNumber], (*fPMTPositionsY)[pmtNumber],
0125                    (*fPMTPositionsZ)[pmtNumber]);
0126   }
0127 
0128   hit->IncPhotonCount();  // increment hit for the selected pmt
0129 
0130   if (!LXeDetectorConstruction::GetSphereOn()) {
0131     hit->SetDrawit(true);
0132     // If the sphere is disabled then this hit is automaticaly drawn
0133   }
0134   else {  // sphere enabled
0135     auto trackInfo = (LXeUserTrackInformation*)aStep->GetTrack()->GetUserInformation();
0136     if (trackInfo->GetTrackStatus() & hitSphere)
0137       // only draw this hit if the photon has hit the sphere first
0138       hit->SetDrawit(true);
0139   }
0140 
0141   return true;
0142 }