TTrajectoryChangeHandler.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 <TGeoManager.h>
9 #include <TGButton.h>
10 
11 #include <TEveManager.h>
12 #include <TEveLine.h>
13 #include <TDatabasePDG.h>
14 #include <TParticlePDG.h>
15 
16 #include <sstream>
17 #include <iostream>
18 
20  fTrajectoryList = new TEveElementList("g4Trajectories",
21  "Geant4 Trajectories");
22  fTrajectoryList->SetMainColor(kRed);
23  fTrajectoryList->SetMainAlpha(1.0);
24  gEve->AddElement(fTrajectoryList);
25 }
26 
28 }
29 
31 
32  fTrajectoryList->DestroyElements();
33 
34  if (!EDep::TEventDisplay::Get().GUI().GetShowTrajectoriesButton()->IsOn()) {
35  return;
36  }
37 
38  std::cout <<"Handle the trajectories" << std::endl;
39 
41  = gEDepSimEvent->Trajectories.begin();
42  traj != gEDepSimEvent->Trajectories.end();
43  ++traj) {
44  const TG4Trajectory::TrajectoryPoints& points = traj->Points;
45 
46  std::ostringstream label;
47  label << traj->GetName()
48  << " (" << traj->GetInitialMomentum().E() << " MeV)";
49 
50  if (traj->GetParentId() < 1) {
51  std::cout << "Primary " << traj->GetTrackId()
52  << " " << traj->GetName()
53  << " " << traj->GetInitialMomentum().P() << " MeV/c"
54  << " w/ points " << points.size()
55  << std::endl;
56  }
57 
58  bool charged = false;
59  std::string particleClass("none");
60  TParticlePDG* particle
61  = TDatabasePDG::Instance()->GetParticle(traj->GetPDGCode());
62  if (particle) {
63  if (std::abs(particle->Charge()) > 0.01) charged = true;
64  particleClass = particle->ParticleClass();
65  }
66 
67  TEveLine *track = new TEveLine();
68  track->SetName("trajectory");
69  track->SetTitle(label.str().c_str());
70 
71  if (particleClass == "Lepton") track->SetLineColor(kMagenta);
72  else if (particleClass == "Baryon") track->SetLineColor(kOrange);
73  else if (particleClass == "Meson") track->SetLineColor(kGreen);
74  else if (particleClass == "GaugeBoson") track->SetLineColor(kCyan);
75  else track->SetLineColor(kRed);
76 
77  if (charged) track->SetLineStyle(3);
78  else track->SetLineStyle(4);
79 
80  for (std::size_t p = 0; p < points.size(); ++p) {
81  track->SetPoint(p,
82  points[p].GetPosition().X(),
83  points[p].GetPosition().Y(),
84  points[p].GetPosition().Z());
85  }
86  fTrajectoryList->AddElement(track);
87  }
88 }
intermediate_table::iterator iterator
std::vector< TG4TrajectoryPoint > TrajectoryPoints
Definition: TG4Trajectory.h:29
std::string string
Definition: nybbler.cc:12
TG4TrajectoryContainer Trajectories
Definition: TG4Event.h:35
T abs(T value)
TEveElementList * fTrajectoryList
The trajectories to draw in the event.
p
Definition: test.py:223
static TEventDisplay & Get(void)
TG4Event * gEDepSimEvent
The event being displayed.
virtual void Apply()
Draw the trajectories into the current scene.
QTextStream & endl(QTextStream &s)