Back to home page

EIC code displayed by LXR

 
 

    


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

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