TG4HitChangeHandler.cxx
Go to the documentation of this file.
2 #include "TEventDisplay.hxx"
3 #include "TGUIManager.hxx"
4 
5 #include <TG4Event.h>
6 #include <TEventManager.hxx>
7 
8 #include <TGButton.h>
9 
10 #include <TEveManager.h>
11 #include <TEveLine.h>
12 
13 #include <sstream>
14 #include <iostream>
15 #include <iomanip>
16 
18  fG4HitList = new TEveElementList("g4HitList","Geant4 Truth Hits");
19  fG4HitList->SetMainColor(kCyan);
20  fG4HitList->SetMainAlpha(1.0);
21  gEve->AddElement(fG4HitList);
22 }
23 
25 }
26 
28 
29  fG4HitList->DestroyElements();
30 
31  if (!EDep::TEventDisplay::Get().GUI().GetShowG4HitsButton()->IsOn()) {
32  std::cout << "G4 hits disabled" << std::endl;
33  return;
34  }
35 
36  std::cout << "Handle the geant4 truth hits" << std::endl;
37  if (!gEDepSimEvent) return;
38 
39  double minEnergy = 0.18;
40  double maxEnergy = 3.0;
41 
44  detector != gEDepSimEvent->SegmentDetectors.end();
45  ++detector) {
46  std::cout << "Show hits for " << detector->first
47  << " (" << detector->second.size() << " hits)"<< std::endl;
48  TEveElementList* hitList
49  = new TEveElementList(
50  detector->first.c_str(),
51  ("Energy Deposit for " + detector->first).c_str());
52  for (TG4HitSegmentContainer::iterator g4Hit = detector->second.begin();
53  g4Hit != detector->second.end();
54  ++g4Hit) {
55  double energy = g4Hit->GetEnergyDeposit();
56  double length = g4Hit->GetTrackLength();
57  double dEdX = energy;
58  if (length>0.01) dEdX /= length;
59 
60  int contrib = g4Hit->Contrib.front();
61  std::string particle = gEDepSimEvent->Trajectories[contrib].GetName();
62 
63  TEveLine* eveHit = new TEveLine(2);
64  eveHit->SetName(detector->first.c_str());
65  std::ostringstream title;
66  title << "Hit(" << particle << ")";
67  title << std::fixed << std::setprecision(1)
68  << " " << dEdX*1000.0 << " keV/mm";
69  title << " for " << length << " mm"
70  << " at (" << g4Hit->GetStart().X() << " mm"
71  << "," << g4Hit->GetStart().Y() << " mm"
72  << "," << g4Hit->GetStart().Z() << " mm"
73  << ")";
74 
75  eveHit->SetTitle(title.str().c_str());
76  eveHit->SetLineWidth(5);
77  eveHit->SetLineColor(TEventDisplay::Get().LogColor(
78  dEdX,
79  minEnergy,
80  maxEnergy,
81  3));
82  eveHit->SetPoint(0,
83  g4Hit->GetStart().X(),
84  g4Hit->GetStart().Y(),
85  g4Hit->GetStart().Z());
86  eveHit->SetPoint(1,
87  g4Hit->GetStop().X(),
88  g4Hit->GetStop().Y(),
89  g4Hit->GetStop().Z());
90  hitList->AddElement(eveHit);
91  }
92  fG4HitList->AddElement(hitList);
93  }
94 
95 }
intermediate_table::iterator iterator
std::string string
Definition: nybbler.cc:12
TG4TrajectoryContainer Trajectories
Definition: TG4Event.h:35
TEveElementList * fG4HitList
The GEANT4 hits to draw in the event.
Q_EXPORT QTSManip setprecision(int p)
Definition: qtextstream.h:343
double dEdX(double KE, const simb::MCParticle *part)
virtual void Apply()
Draw the trajectories into the current scene.
TG4HitSegmentDetectors SegmentDetectors
Definition: TG4Event.h:39
static TEventDisplay & Get(void)
TG4Event * gEDepSimEvent
The event being displayed.
QTextStream & endl(QTextStream &s)