Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-03-28 07:51:00

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 WLSPhotonDetSD.cc
0027 /// \brief Implementation of the WLSPhotonDetSD class
0028 
0029 #include "WLSPhotonDetSD.hh"
0030 
0031 #include "WLSPhotonDetHit.hh"
0032 #include "WLSUserTrackInformation.hh"
0033 
0034 #include "G4OpticalPhoton.hh"
0035 #include "G4SDManager.hh"
0036 #include "G4Step.hh"
0037 #include "G4ThreeVector.hh"
0038 #include "G4TouchableHistory.hh"
0039 #include "G4Track.hh"
0040 #include "G4VTouchable.hh"
0041 
0042 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0043 
0044 WLSPhotonDetSD::WLSPhotonDetSD(G4String name) : G4VSensitiveDetector(name)
0045 {
0046   collectionName.insert("PhotonDetHitCollection");
0047 }
0048 
0049 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0050 
0051 void WLSPhotonDetSD::Initialize(G4HCofThisEvent* HCE)
0052 {
0053   fPhotonDetHitCollection =
0054     new WLSPhotonDetHitsCollection(SensitiveDetectorName, collectionName[0]);
0055 
0056   if (fHCID < 0) {
0057     fHCID = G4SDManager::GetSDMpointer()->GetCollectionID(fPhotonDetHitCollection);
0058   }
0059   HCE->AddHitsCollection(fHCID, fPhotonDetHitCollection);
0060 }
0061 
0062 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0063 
0064 G4bool WLSPhotonDetSD::ProcessHits(G4Step* aStep, G4TouchableHistory*)
0065 {
0066   if (!aStep) return false;
0067   G4Track* theTrack = aStep->GetTrack();
0068 
0069   // Need to know if this is an optical photon
0070   if (theTrack->GetDefinition() != G4OpticalPhoton::OpticalPhotonDefinition()) {
0071     return false;
0072   }
0073 
0074   // Find out information regarding the hit
0075   G4StepPoint* thePostPoint = aStep->GetPostStepPoint();
0076 
0077   auto trackInformation = (WLSUserTrackInformation*)theTrack->GetUserInformation();
0078 
0079   auto theTouchable = (G4TouchableHistory*)(thePostPoint->GetTouchable());
0080 
0081   G4ThreeVector photonExit = trackInformation->GetExitPosition();
0082   G4ThreeVector photonArrive = thePostPoint->GetPosition();
0083   G4double arrivalTime = theTrack->GetGlobalTime();
0084   G4double energy = theTrack->GetTotalEnergy();
0085 
0086   // Convert the global coordinate for arriving photons into
0087   // the local coordinate of the detector
0088   photonArrive = theTouchable->GetHistory()->GetTopTransform().TransformPoint(photonArrive);
0089 
0090   // Creating the hit and add it to the collection
0091   fPhotonDetHitCollection->insert(
0092     new WLSPhotonDetHit(photonExit, photonArrive, arrivalTime, energy));
0093 
0094   return true;
0095 }
0096 
0097 void WLSPhotonDetSD::EndOfEvent(G4HCofThisEvent*)
0098 {
0099   if (verboseLevel > 1) {
0100     G4int nofHits = fPhotonDetHitCollection->entries();
0101     G4cout << G4endl << "-------->Hits Collection: in this event there are " << nofHits
0102            << " hits in the photon detector: " << G4endl;
0103     for (G4int i = 0; i < nofHits; i++)
0104       (*fPhotonDetHitCollection)[i]->Print();
0105   }
0106 }