Back to home page

EIC code displayed by LXR

 
 

    


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

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