GGS(GenericGEANT4Simulation)Software  2.7.0
 All Data Structures Namespaces Files Functions Variables Typedefs Macros
SetMCTruth.cpp
1 /*
2  * SetMCTruth.cpp
3  *
4  * Created on: 16 Mar 2017
5  * Author: Valerio Formato
6  */
7 
8 /*
9  * This function reads MT truth info about the primary particle and eventually
10  * particle hits if they are present. Particle hits are not displayed by default
11  * due to performance issues with lots of tracks in the display.
12  */
13 
14 #include "TEveBrowser.h"
15 #include "TEveScene.h"
16 #include "TEveTrackPropagator.h"
17 #include "TEveTrans.h"
18 #include "TGButton.h"
19 #include "TGTab.h"
20 #include "TGeoBBox.h"
21 #include "TGeoNode.h"
22 #include "TParticlePDG.h"
23 #include "TSystem.h"
24 
25 #include "utils/GGSSmartLog.h"
26 
27 #include "application/Application.h"
28 #include "application/event/InteractionTree.h"
29 #include "application/gui/MainWindow.h"
30 
31 void MainWindow::SetMCTruth(GGSTMCTruthReader *reader) {
32  static const std::string routineName("MainWindow::SetMCTruth");
33 
34  int nPrim = reader->GetNPrimaries();
35  COUT(DEBUG) << nPrim << " Primary particles " << ENDL;
36  if (nPrim == 0)
37  return;
38 
39  TEveTrackList *trackList = new TEveTrackList("Primary Particles");
40 
41  TEveTrackPropagator *trkProp = trackList->GetPropagator();
42  trkProp->SetStepper(TEveTrackPropagator::kRungeKutta);
43 
44  TString primString = "";
45 
46  GGSTParticle *thisPrim = NULL;
47  for (int iPrim = 0; iPrim < nPrim; iPrim++) {
48  thisPrim = reader->GetPrimaryParticle(iPrim);
49 
50  COUT(DEBUG) << thisPrim << " " << thisPrim->PDGCode << "(" << thisPrim->trackID << ")" << ENDL;
51 
52  TParticle *tempPart = new TParticle();
53  tempPart->SetPdgCode(thisPrim->PDGCode);
54  tempPart->SetStatusCode(1);
55  tempPart->SetMother(0, 0);
56  COUT(DEBUG) << tempPart->GetMass() << " " << tempPart->GetNDaughters() << ENDL;
57 
58  TLorentzVector lpos(thisPrim->pos[0], thisPrim->pos[1], thisPrim->pos[2], thisPrim->time);
59  TLorentzVector lmom;
60  lmom.SetXYZM(thisPrim->mom[0], thisPrim->mom[1], thisPrim->mom[2], tempPart->GetMass());
61 
62  tempPart->SetProductionVertex(lpos);
63  tempPart->SetMomentum(lmom);
64 
65  primString += "Particle: ";
66  primString += tempPart->GetName();
67  primString += Form("\nE_{0}: %5.3f GeV", tempPart->Energy() - tempPart->GetMass());
68  primString += Form("\ntheta = %5.3f deg - phi = %5.3f deg", 180 * (1 - tempPart->Theta() / TMath::Pi()),
69  180 * tempPart->Phi() / TMath::Pi());
70 
71  TEveTrack *thisTrack = new TEveTrack(tempPart, thisPrim->trackID, trkProp);
72  thisTrack->SetLineWidth(2);
73  if (tempPart->GetPDG()->Charge() > 0)
74  thisTrack->SetMainColor(kCyan);
75  else if (tempPart->GetPDG()->Charge() < 0)
76  thisTrack->SetMainColor(kRed);
77  else
78  thisTrack->SetMainColor(kYellow);
79 
80  thisTrack->IncDenyDestroy();
81  thisTrack->SetName(Form("Prim Track %d", thisPrim->trackID));
82  thisTrack->SetStdTitle();
83 
84  trackList->AddElement(thisTrack);
85  }
86 
87  trackList->MakeTracks();
88  _MCTruthShortInfo->SetText(primString);
89 
90  CrossPTree();
91 
92  _MCTruthList->AddElement(trackList);
93 }
94 
95 void MainWindow::CrossPTree() {
96  static const std::string routineName("MainWindow::CrossPTree");
97 
98  EDApplication *thisApp = (EDApplication *)gApplication;
99 
100  InteractionTree<GGSTPartHit *> *pTree = thisApp->GetFileManager()->GetInteractionTree();
101 
102  TEveElementList *trackList = new TEveElementList("Particle tracks");
103 
104  TParticle *tempPart = new TParticle();
105 
106  for (std::pair<int, TreeNode<GGSTPartHit *> *> element : pTree->hashMap) {
107  TEveLine *line = new TEveLine();
108  if (!element.second->hits.size())
109  continue;
110  tempPart->SetPdgCode((int)element.second->hits[0]->particlePdg);
111  if (!element.second->hits[0]->eDep)
112  continue;
113  for (size_t ihit = 0; ihit < element.second->hits.size(); ihit++) {
114  line->SetNextPoint(element.second->hits[ihit]->entrancePoint[0], element.second->hits[ihit]->entrancePoint[1],
115  element.second->hits[ihit]->entrancePoint[2]);
116  line->SetNextPoint(element.second->hits[ihit]->exitPoint[0], element.second->hits[ihit]->exitPoint[1],
117  element.second->hits[ihit]->exitPoint[2]);
118  }
119  line->SetName(Form("trackID %i", element.first));
120  line->SetTitle(tempPart->GetName());
121 
122  if (tempPart->GetPDG()) {
123  if (tempPart->GetPDG()->Charge() > 0)
124  line->SetMainColor(kCyan);
125  else if (tempPart->GetPDG()->Charge() < 0)
126  line->SetMainColor(kRed);
127  else
128  line->SetMainColor(kYellow);
129  } else {
130  line->SetMainColor(kGray);
131  }
132 
133  trackList->AddElement(line);
134  // break;
135  }
136  // trackList->MakeTracks();
137  trackList->SetRnrState(0); // Don't render
138  _MCTruthList->AddElement(trackList);
139  _MCPartHitList = trackList;
140 }
Float_t mom[3]
Momentum at generation [GeV].
Definition: GGSTParticle.h:24
GGSTParticle * GetPrimaryParticle(UInt_t particleNumber)
Returns a primary particle.
#define ENDL
Definition: GGSSmartLog.h:105
#define COUT(level)
Smart log macro. It writes on stdout only if the specified verbosity level is lesser than the maximum...
Definition: GGSSmartLog.h:76
Int_t PDGCode
PDG code of particle (see http://www3.nd.edu/~avillano/geant4/geant4_pid.html).
Definition: GGSTParticle.h:21
Float_t time
Time of generation [ns].
Definition: GGSTParticle.h:25
Class for reading output of GGSMCTruthAction.
UInt_t GetNPrimaries()
Returns the number of primaries in current event.
Int_t trackID
Track ID.
Definition: GGSTParticle.h:22
Float_t pos[3]
Point of generation [cm].
Definition: GGSTParticle.h:23
Class to store G4 particles.
Definition: GGSTParticle.h:19