Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-03-30 07:49:56

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 HodoscopeSD.cc
0027 /// \brief Implementation of the B5::HodoscopeSD class
0028 
0029 #include "HodoscopeSD.hh"
0030 
0031 #include "HodoscopeHit.hh"
0032 
0033 #include "G4AffineTransform.hh"
0034 #include "G4HCofThisEvent.hh"
0035 #include "G4SDManager.hh"
0036 #include "G4Step.hh"
0037 #include "G4StepPoint.hh"
0038 #include "G4VPhysicalVolume.hh"
0039 #include "G4VTouchable.hh"
0040 
0041 namespace B5
0042 {
0043 
0044 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0045 
0046 HodoscopeSD::HodoscopeSD(G4String name) : G4VSensitiveDetector(name)
0047 {
0048   collectionName.insert("hodoscopeColl");
0049 }
0050 
0051 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0052 
0053 void HodoscopeSD::Initialize(G4HCofThisEvent* hce)
0054 {
0055   fHitsCollection = new HodoscopeHitsCollection(SensitiveDetectorName, collectionName[0]);
0056   if (fHCID < 0) {
0057     fHCID = G4SDManager::GetSDMpointer()->GetCollectionID(fHitsCollection);
0058   }
0059   hce->AddHitsCollection(fHCID, fHitsCollection);
0060 }
0061 
0062 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0063 
0064 G4bool HodoscopeSD::ProcessHits(G4Step* step, G4TouchableHistory*)
0065 {
0066   auto edep = step->GetTotalEnergyDeposit();
0067   if (edep == 0.) return true;
0068 
0069   auto preStepPoint = step->GetPreStepPoint();
0070   auto touchable = preStepPoint->GetTouchable();
0071   auto copyNo = touchable->GetVolume()->GetCopyNo();
0072   auto hitTime = preStepPoint->GetGlobalTime();
0073 
0074   // check if this finger already has a hit
0075   auto ix = -1;
0076   for (std::size_t i = 0; i < fHitsCollection->entries(); ++i) {
0077     if ((*fHitsCollection)[i]->GetID() == copyNo) {
0078       ix = i;
0079       break;
0080     }
0081   }
0082 
0083   if (ix >= 0) {
0084     // if it has, then take the earlier time
0085     if ((*fHitsCollection)[ix]->GetTime() > hitTime) {
0086       (*fHitsCollection)[ix]->SetTime(hitTime);
0087     }
0088   }
0089   else {
0090     // if not, create a new hit and set it to the collection
0091     auto hit = new HodoscopeHit(copyNo, hitTime);
0092     auto physical = touchable->GetVolume();
0093     hit->SetLogV(physical->GetLogicalVolume());
0094     auto transform = touchable->GetHistory()->GetTopTransform();
0095     transform.Invert();
0096     hit->SetRot(transform.NetRotation());
0097     hit->SetPos(transform.NetTranslation());
0098     fHitsCollection->insert(hit);
0099   }
0100   return true;
0101 }
0102 
0103 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0104 
0105 }  // namespace B5