Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-31 09:22:53

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