ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
B5HodoscopeSD.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file B5HodoscopeSD.cc
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
29 
30 #include "B5HodoscopeSD.hh"
31 #include "B5HodoscopeHit.hh"
32 
33 #include "G4HCofThisEvent.hh"
34 #include "G4TouchableHistory.hh"
35 #include "G4Track.hh"
36 #include "G4Step.hh"
37 #include "G4SDManager.hh"
38 #include "G4ios.hh"
39 
40 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
41 
43 : G4VSensitiveDetector(name),
44  fHitsCollection(nullptr), fHCID(-1)
45 {
46  collectionName.insert( "hodoscopeColl");
47 }
48 
49 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
50 
52 {}
53 
54 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
55 
57 {
60  if (fHCID<0) {
62  }
64 }
65 
66 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
67 
69 {
70  auto edep = step->GetTotalEnergyDeposit();
71  if (edep==0.) return true;
72 
73  auto preStepPoint = step->GetPreStepPoint();
74  auto touchable = preStepPoint->GetTouchable();
75  auto copyNo = touchable->GetVolume()->GetCopyNo();
76  auto hitTime = preStepPoint->GetGlobalTime();
77 
78  // check if this finger already has a hit
79  auto ix = -1;
80  for (std::size_t i=0;i<fHitsCollection->entries();++i) {
81  if ((*fHitsCollection)[i]->GetID()==copyNo) {
82  ix = i;
83  break;
84  }
85  }
86 
87  if (ix>=0) {
88  // if it has, then take the earlier time
89  if ((*fHitsCollection)[ix]->GetTime()>hitTime) {
90  (*fHitsCollection)[ix]->SetTime(hitTime);
91  }
92  }
93  else {
94  // if not, create a new hit and set it to the collection
95  auto hit = new B5HodoscopeHit(copyNo,hitTime);
96  auto physical = touchable->GetVolume();
97  hit->SetLogV(physical->GetLogicalVolume());
98  auto transform = touchable->GetHistory()->GetTopTransform();
99  transform.Invert();
100  hit->SetRot(transform.NetRotation());
101  hit->SetPos(transform.NetTranslation());
102  fHitsCollection->insert(hit);
103  }
104  return true;
105 }
106 
107 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......