ghit
ghit.cc
Go to the documentation of this file.
1 // ghit
2 #include "ghit.h"
3 
4 #include <utility>
5 
6 // glibrary
7 #include "gutsConventions.h"
8 
9 // geant4
10 #include "G4VVisManager.hh"
11 #include "G4Circle.hh"
12 #include "G4VisAttributes.hh"
13 
14 using std::string;
15 using std::vector;
16 
17 // MT definitions, as from:
18 // https://twiki.cern.ch/twiki/bin/view/Geant4/QuickMigrationGuideForGeant4V10
19 G4ThreadLocal G4Allocator<GHit>* GHitAllocator = nullptr;
20 
21 GHit::GHit(GTouchable *gt, const HitBitSet hbs, const G4Step *thisStep, string cScheme) : G4VHit(),
22  colorSchema(std::move(cScheme)),
23  gtouchable(gt) {
24 
25  // initialize quantities based on HitBitSet, like globalPositions
26  if (thisStep) { addHitInfosForBitset(hbs, thisStep); }
27 
28  // unitialized quantities. To be calculated at the end of the steps by collectTrueInformation
29  // bit 0: always there
30  averageTime = UNINITIALIZEDNUMBERQUANTITY;
31  avgGlobalPosition = G4ThreeVector(UNINITIALIZEDNUMBERQUANTITY, UNINITIALIZEDNUMBERQUANTITY, UNINITIALIZEDNUMBERQUANTITY);
32  avgLocalPosition = G4ThreeVector(UNINITIALIZEDNUMBERQUANTITY, UNINITIALIZEDNUMBERQUANTITY, UNINITIALIZEDNUMBERQUANTITY);
33  processName = UNINITIALIZEDSTRINGQUANTITY;
34 
35 }
36 
37 bool GHit::is_same_hit(GHit *hit) {
38  return (*gtouchable) == (*hit->getGTouchable());
39 }
40 
41 
42 vector<int> GHit::getTTID() {
43  vector<int> ttid;
44  // Retrieve the identity vector from the associated GTouchable.
45  vector <GIdentifier> gids = getGID();
46  ttid.reserve(gids.size());
47  for (auto &gid: gids) {
48  // Push back the integer value of each identifier.
49  ttid.push_back(gid.getValue());
50  }
51  return ttid;
52 }
53 
54 
62  void GHit::Draw() {
63  G4VVisManager *pVVisManager = G4VVisManager::GetConcreteInstance();
64 
65  // only care about schema if we are interactive
66  if (pVVisManager) {
67  setColorSchema();
68 
69  // Check that globalPositions is not empty before accessing the first element.
70  if (globalPositions.empty()) return;
71 
72  G4Circle circle(globalPositions[0]);
73  circle.SetFillStyle(G4Circle::filled);
74 
75  double etot = getTotalEnergyDeposited();
76 
77  if (etot > 0) {
78  circle.SetScreenSize(10);
79  circle.SetVisAttributes(G4VisAttributes(colour_hit));
80  } else if (etot == 0) {
81  circle.SetScreenSize(8);
82  circle.SetVisAttributes(G4VisAttributes(colour_passby));
83  }
84 
85  pVVisManager->Draw(circle);
86  }
87 }
88 
89 
96 bool GHit::setColorSchema() {
97  // For now, hard-code the color schema.
98  colour_hit = G4Colour(1.0, 0.0, 0.0); // Red for hits with energy.
99  colour_passby = G4Colour(0.0, 1.0, 0.0); // Green for pass-by.
100  return false;
101 }
Represents a hit in the detector.
Definition: ghit.h:28
GTouchable * getGTouchable() const
Returns the GTouchable associated with the hit.
Definition: ghit.h:163
void addHitInfosForBitset(HitBitSet hbs, const G4Step *thisStep)
Adds hit information based on a HitBitSet.
Definition: addHitInfos.cc:17
GHit(GTouchable *gt, HitBitSet hbs, const G4Step *thisStep=nullptr, std::string cScheme="default")
Constructor for GHit.
Definition: ghit.cc:21
std::vector< GIdentifier > getGID() const
Returns the detector element identity.
Definition: ghit.h:169
bool is_same_hit(GHit *hit)
Compare two ghits.
Definition: ghit.cc:37
void Draw() override
Draws the hit using Geant4 visualization.
Definition: ghit.cc:62
double getTotalEnergyDeposited()
Computes the total energy deposited.
Definition: calculations.cc:76
std::vector< int > getTTID()
Returns the touchable identity values as integers.
Definition: ghit.cc:42
std::bitset< NHITBITS > HitBitSet
G4ThreadLocal G4Allocator< GHit > * GHitAllocator
Definition: ghit.cc:19