GGS(GenericGEANT4Simulation)Software  2.6.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 "TSystem.h"
15 #include "TGTab.h"
16 #include "TGButton.h"
17 #include "TGeoBBox.h"
18 #include "TGeoNode.h"
19 #include "TEveBrowser.h"
20 #include "TEveScene.h"
21 #include "TEveTrans.h"
22 #include "TEveTrackPropagator.h"
23 #include "TParticlePDG.h"
24 
25 #include "utils/GGSSmartLog.h"
26 
27 #include "application/gui/MainWindow.h"
28 #include "application/event/InteractionTree.h"
29 #include "application/Application.h"
30 
31 
32 void MainWindow::SetMCTruth(GGSTMCTruthReader* reader){
33  static const std::string routineName("MainWindow::SetMCTruth");
34 
35  int nPrim = reader->GetNPrimaries();
36  COUT(DEBUG) << nPrim << " Primary particles " << ENDL;
37  if( nPrim == 0 ) 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()), 180*tempPart->Phi()/TMath::Pi());
69 
70  TEveTrack* thisTrack = new TEveTrack(tempPart, thisPrim->trackID, trkProp);
71  thisTrack->SetLineWidth(2);
72  if( tempPart->GetPDG()->Charge() > 0 ) thisTrack->SetMainColor(kCyan);
73  else if( tempPart->GetPDG()->Charge() < 0 ) thisTrack->SetMainColor(kRed);
74  else thisTrack->SetMainColor(kYellow);
75 
76  thisTrack->IncDenyDestroy();
77  thisTrack->SetName(Form("Prim Track %d", thisPrim->trackID));
78  thisTrack->SetStdTitle();
79 
80  trackList->AddElement(thisTrack);
81  }
82 
83  trackList->MakeTracks();
84  _MCTruthShortInfo->SetText( primString );
85 
86  CrossPTree();
87 
88  _MCTruthList->AddElement( trackList );
89 
90 }
91 
92 void MainWindow::CrossPTree(){
93  static const std::string routineName("MainWindow::CrossPTree");
94 
95  EDApplication* thisApp = (EDApplication*) gApplication;
96 
97  InteractionTree<GGSTPartHit*>* pTree = thisApp->GetFileManager()->GetInteractionTree();
98 
99  TEveElementList* trackList = new TEveElementList("Particle tracks");
100 
101  TParticle* tempPart = new TParticle();
102 
103  for( std::pair<int, TreeNode<GGSTPartHit*>*> element : pTree->hashMap ){
104  TEveLine* line = new TEveLine();
105  if( !element.second->hits.size() ) continue;
106  tempPart->SetPdgCode( (int) element.second->hits[0]->particlePdg );
107  if( !element.second->hits[0]->eDep ) continue;
108  for(size_t ihit=0; ihit<element.second->hits.size(); ihit++){
109  line->SetNextPoint(
110  element.second->hits[ihit]->entrancePoint[0],
111  element.second->hits[ihit]->entrancePoint[1],
112  element.second->hits[ihit]->entrancePoint[2]
113  );
114  line->SetNextPoint(
115  element.second->hits[ihit]->exitPoint[0],
116  element.second->hits[ihit]->exitPoint[1],
117  element.second->hits[ihit]->exitPoint[2]
118  );
119  }
120  line->SetName( Form("trackID %i", element.first) );
121  line->SetTitle( tempPart->GetName() );
122 
123  if( tempPart->GetPDG() ){
124  if( tempPart->GetPDG()->Charge() > 0 ) line->SetMainColor(kCyan);
125  else if( tempPart->GetPDG()->Charge() < 0 ) line->SetMainColor(kRed);
126  else line->SetMainColor(kYellow);
127  } else {
128  line->SetMainColor(kGray);
129  }
130 
131  trackList->AddElement( line );
132  // break;
133  }
134  // trackList->MakeTracks();
135  trackList->SetRnrState(0); //Don't render
136  _MCTruthList->AddElement( trackList );
137  _MCPartHitList = trackList;
138 }
Float_t mom[3]
Momentum at generation [GeV].
Definition: GGSTParticle.h:25
GGSTParticle * GetPrimaryParticle(UInt_t particleNumber)
Returns a primary particle.
#define ENDL
Definition: GGSSmartLog.h:93
#define COUT(level)
Smart log macro. It writes on stdout only if the specified verbosity level is lesser than the maximum...
Definition: GGSSmartLog.h:66
Int_t PDGCode
PDG code of particle (see http://www3.nd.edu/~avillano/geant4/geant4_pid.html).
Definition: GGSTParticle.h:22
Float_t time
Time of generation [ns].
Definition: GGSTParticle.h:26
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:23
Float_t pos[3]
Point of generation [cm].
Definition: GGSTParticle.h:24
Class to store G4 particles.
Definition: GGSTParticle.h:19