EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FairMCTracks.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file FairMCTracks.cxx
1 // -------------------------------------------------------------------------
2 // ----- FairMCTracks source file -----
3 // ----- Created 10/12/07 by M. Al-Turany -----
4 // -------------------------------------------------------------------------
5 
6 #include "FairMCTracks.h"
7 
8 #include "FairEventManager.h"
9 #include "FairRootManager.h"
10 
11 #include "TEveTrack.h"
12 #include "TEveTrackPropagator.h"
13 #include "TGeoTrack.h"
14 #include "TClonesArray.h"
15 #include "TObjArray.h"
16 #include "TEveManager.h"
17 #include "TParticle.h"
18 
19 #include <iostream>
20 using std::cout;
21 using std::endl;
22 
23 // ----- Default constructor -------------------------------------------
25  : FairTask("FairMCTracks", 0),
26  fTrackList(NULL),
27  fTrPr(NULL),
28  fEventManager(NULL),
29  fEveTrList(NULL),
30  fEvent(""),
31  fTrList(NULL),
32  MinEnergyLimit(-1.),
33  MaxEnergyLimit(-1.),
34  PEnergy(-1.)
35 {
36 }
37 // -------------------------------------------------------------------------
38 
39 
40 // ----- Standard constructor ------------------------------------------
41 FairMCTracks::FairMCTracks(const char* name, Int_t iVerbose)
42  : FairTask(name, iVerbose),
43  fTrackList(NULL),
44  fTrPr(NULL),
45  fEventManager(NULL),
46  fEveTrList(new TObjArray(16)),
47  fEvent(""),
48  fTrList(NULL),
49  MinEnergyLimit(-1.),
50  MaxEnergyLimit(-1.),
51  PEnergy(-1.)
52 {
53 }
54 // -------------------------------------------------------------------------
56 {
57  if(fVerbose>1) { cout<< "FairMCTracks::Init()" << endl; }
59  fTrackList = (TClonesArray*)fManager->GetObject("GeoTracks");
60  if(fTrackList==0) {
61  cout << "FairMCPointDraw::Init() branch " << GetName() << " Not found! Task will be deactivated "<< endl;
62  SetActive(kFALSE);
63  }
64  if(fVerbose>2) { cout<< "FairMCTracks::Init() get track list" << fTrackList<< endl; }
65  if(fVerbose>2) { cout<< "FairMCTracks::Init() create propagator" << endl; }
67  if(fVerbose>2) { cout<< "FairMCTracks::Init() get instance of FairEventManager " << endl; }
68  fEvent = "Current Event";
71  PEnergy=0;
72  if(IsActive()) { return kSUCCESS; }
73  else { return kERROR; }
74 }
75 // -------------------------------------------------------------------------
76 void FairMCTracks::Exec(Option_t* option)
77 {
78 
79  if (IsActive()) {
80 
81  if(fVerbose>1) { cout << " FairMCTracks::Exec "<< endl; }
82  TGeoTrack* tr;
83  const Double_t* point;
84 
85  Reset();
86 
87  for (Int_t i=0; i<fTrackList->GetEntriesFast(); i++) {
88  if(fVerbose>2) { cout << "FairMCTracks::Exec "<< i << endl; }
89  tr=(TGeoTrack*)fTrackList->At(i);
90  TParticle* P=(TParticle*)tr->GetParticle();
91  PEnergy=P->Energy();
94  if(fVerbose>2) { cout << "MinEnergyLimit " << MinEnergyLimit << " MaxEnergyLimit " << MaxEnergyLimit << endl; }
95  if (fEventManager->IsPriOnly() && P->GetMother(0)>-1) { continue; }
96  if(fEventManager->GetCurrentPDG()!=0 && fEventManager->GetCurrentPDG()!= tr->GetPDG()) { continue; }
97  if(fVerbose>2) { cout << "PEnergy " << PEnergy << " Min " << fEventManager->GetMinEnergy() << " Max " << fEventManager->GetMaxEnergy() <<endl; }
98  if( (PEnergy<fEventManager->GetMinEnergy()) || (PEnergy >fEventManager->GetMaxEnergy())) { continue; }
99 
100  Int_t Np=tr->GetNpoints();
101  fTrList= GetTrGroup(P);
102  TEveTrack* track= new TEveTrack(P, tr->GetPDG(), fTrPr);
103  track->SetLineColor(fEventManager->Color(tr->GetPDG()));
104  for (Int_t n=0; n<Np; n++) {
105  point=tr->GetPoint(n);
106  track->SetPoint(n,point[0],point[1],point[2]);
107  TEveVector pos= TEveVector(point[0], point[1],point[2]);
108  TEvePathMark* path = new TEvePathMark();
109  path->fV=pos ;
110  path->fTime= point[3];
111  if(n==0) {
112  TEveVector Mom= TEveVector(P->Px(), P->Py(),P->Pz());
113  path->fP=Mom;
114  }
115  if(fVerbose>3) { cout << "Path marker added " << path << endl; }
116 
117  track->AddPathMark(*path);
118 
119  if(fVerbose>3) { cout << "Path marker added " << path << endl; }
120  }
121  fTrList->AddElement(track);
122  if(fVerbose>3) { cout << "track added " << track->GetName() << endl; }
123  }
124  for (Int_t i=0; i<fEveTrList->GetEntriesFast(); i++) {
125  // TEveTrackList *TrListIn=( TEveTrackList *) fEveTrList->At(i);
126  //TrListIn->FindMomentumLimits(TrListIn, kFALSE);
127  }
130  gEve->Redraw3D(kFALSE);
131  }
132 }
133 // ----- Destructor ----------------------------------------------------
135 {
136 }
137 // -------------------------------------------------------------------------
139 {
140 
141 }
142 
143 // -------------------------------------------------------------------------
145 {
146 
147 }
148 // -------------------------------------------------------------------------
150 {
151  for (Int_t i=0; i<fEveTrList->GetEntriesFast(); i++) {
152  TEveTrackList* ele=( TEveTrackList*) fEveTrList->At(i);
153  gEve->RemoveElement(ele,fEventManager);
154  }
155  fEveTrList->Clear();
156 }
157 
158 TEveTrackList* FairMCTracks::GetTrGroup(TParticle* P)
159 {
160 
161  fTrList=0;
162  for (Int_t i=0; i<fEveTrList->GetEntriesFast(); i++) {
163  TEveTrackList* TrListIn=( TEveTrackList*) fEveTrList->At(i);
164  if ( strcmp(TrListIn->GetName(),P->GetName())==0 ) {
165  fTrList= TrListIn;
166  break;
167  }
168  }
169  if(fTrList ==0) {
170  fTrPr=new TEveTrackPropagator();
171  fTrList= new TEveTrackList(P->GetName(),fTrPr );
172  fTrList->SetMainColor(fEventManager->Color(P->GetPdgCode()));
173  fEveTrList->Add(fTrList);
174  gEve->AddElement( fTrList ,fEventManager );
175  fTrList->SetRnrLine(kTRUE);
176  }
177  return fTrList;
178 }
179 
181 
182