G4UMDPixelAction.cc
Go to the documentation of this file.
1 #include "G4UMDPixelAction.h"
2 #include "G4UMDPixelHit.h"
3 
4 #include <G4Step.hh>
5 #include <G4HCofThisEvent.hh>
6 #include <G4TouchableHistory.hh>
7 #include <G4ios.hh>
8 #include <G4SystemOfUnits.hh>
9 #include <G4SDManager.hh>
10 #include <G4OpticalPhoton.hh>
11 
12 #include <utl/AugerUnits.h>
13 
14 
15 namespace G4StationSimulatorOG {
16 
17  G4UMDPixelAction::G4UMDPixelAction(const G4String& name) :
18  G4VSensitiveDetector(name), fHCID (-1)
19  {
20  collectionName.insert("pixelCollection");
21  }
22 
23 
24  void
25  G4UMDPixelAction::Initialize(G4HCofThisEvent* const hce)
26  {
27 
28  fPixelCollection = new G4UMDPixelHitCollection(SensitiveDetectorName, collectionName[0]);
29  if (fHCID<0) {
30  fHCID = G4SDManager::GetSDMpointer()->GetCollectionID(fPixelCollection);
31  }
32  hce->AddHitsCollection(fHCID,fPixelCollection);
33 
34  }
35 
36 
37  G4bool
38  G4UMDPixelAction::ProcessHits(G4Step* const step, G4TouchableHistory* const)
39  {
40  // If not an opticalphoton, continue
41  if (step->GetTrack()->GetDefinition() != G4OpticalPhoton::OpticalPhotonDefinition() )
42  return true;
43 
44  // Retrieve current physical volumen and its name (i.e. the current physical pixel)
45  G4VPhysicalVolume* const physVol = step->GetPreStepPoint()->GetPhysicalVolume();
46  const G4String& pixelName = physVol->GetName();
47  const G4int pixelId = physVol->GetCopyNo();
48  // Retrieve mother volume of the current physical volumen and its name (i.e. the current physical module)
49  G4VPhysicalVolume* const motherPhysVol = step->GetPreStepPoint()->GetTouchableHandle()->GetVolume(1);
50  const G4int moduleId = motherPhysVol->GetCopyNo();
51 
52  auto& pc = *fPixelCollection;
53  // Check if this pixel was previously hit
54  const G4int collEntries = pc.entries();
55  G4UMDPixelHit* pixelHit = nullptr;
56  // Loop over the pixel hit collection and control the pixel name
57  for (G4int i = 0; i < collEntries; ++i) {
58  if (pc[i]->GetPixelName() == pixelName) {
59  pixelHit = pc[i];
60  break;
61  }
62  }
63 
64  if (!pixelHit) { // this pixel wasn't previously hit in this event
65  // Creates a new hit
66  pixelHit = new G4UMDPixelHit;
67  // Stores information of this hit
68  pixelHit->SetPixelName(pixelName);
69  pixelHit->SetModuleId(moduleId);
70  pixelHit->SetPixelId(pixelId);
71  pixelHit->SetDrawIt(true);
72  pixelHit->SetUMDPixelPhysVol(physVol);
73  pc.insert(pixelHit);
74  }
75 
76  const G4double time = step->GetTrack()->GetGlobalTime() * (utl::ns/CLHEP::ns);
77  pixelHit->AddHit(time);
78 
79  return true;
80  }
81 
82 }
void SetModuleId(const G4int id)
Definition: G4UMDPixelHit.h:28
void AddHit(const G4double t)
Definition: G4UMDPixelHit.h:27
G4THitsCollection< G4StationSimulatorOG::G4UMDPixelHit > G4UMDPixelHitCollection
Definition: G4UMDPixelHit.h:53
void SetDrawIt(const G4bool draw)
Definition: G4UMDPixelHit.h:31
const double ns
G4UMDPixelHitCollection * fPixelCollection
G4bool ProcessHits(G4Step *const step, G4TouchableHistory *const rOhist) override
void Initialize(G4HCofThisEvent *const hce) override
void SetUMDPixelPhysVol(G4VPhysicalVolume *const physVol)
Definition: G4UMDPixelHit.h:32
constexpr double ns
Definition: AugerUnits.h:162
void SetPixelName(const G4String name)
Definition: G4UMDPixelHit.h:30

, generated on Tue Sep 26 2023.