BmnRoot
Loading...
Searching...
No Matches
MpdMCTracks.cxx
Go to the documentation of this file.
1// -------------------------------------------------------------------------
2// ----- MpdMCTracks source file -----
3// ----- Created 10/12/07 by M. Al-Turany -----
4// -------------------------------------------------------------------------
5#include "MpdMCTracks.h"
6
7#include "FairRootManager.h"
8#include "FairLogger.h"
9
10#include "TEveManager.h" // for gEve
11#include "TEvePathMark.h"
12#include "TEveVector.h"
13#include "TGeoTrack.h"
14#include "TMathBase.h"
15#include "TObjArray.h"
16
17#include <iostream>
18using namespace std;
19
20
21// ----- Default constructor -------------------------------------------
23 : FairTask("MpdMCTracks", 0),
24 fTrackList(NULL),
25 fTrPr(NULL),
26 fEventManager(NULL),
27 fEveTrList(NULL),
28 fTrList(NULL)
29{
30}
31
32// ----- Standard constructor ------------------------------------------
33MpdMCTracks::MpdMCTracks(const char* name, Int_t iVerbose)
34 : FairTask(name, iVerbose),
35 fTrackList(NULL),
36 fTrPr(NULL),
37 fEventManager(NULL),
38 fEveTrList(new TObjArray(16)),
39 fTrList(NULL)
40{
41}
42
43// ----- Destructor ----------------------------------------------------
47
48// -------------------------------------------------------------------------
50{
51 LOG(debug)<<"MpdMCTracks::Init()";
52
53 FairRootManager* fManager = FairRootManager::Instance();
55 LOG(debug1) << "MpdMCTracks::Init() get instance of MpdEventManager ";
56
57 fTrackList = (TClonesArray*) fManager->GetObject("GeoTracks");
58 if (fTrackList == 0)
59 {
60 LOG(error)<<"MpdMCTracks::Init() branch "<<GetName()<<" not found! Task will be deactivated";
61 SetActive(kFALSE);
62 }
63 LOG(debug1)<<"MpdMCTracks::Init() get track list "<<fTrackList;
64
65 if (IsActive()) return kSUCCESS;
66 else return kERROR;
67}
68
69// -------------------------------------------------------------------------
70void MpdMCTracks::Exec(Option_t* /*option*/)
71{
72 if (!IsActive())
73 return;
74 LOG(debug1)<<"MpdMCTracks::Exec";
75
76 Reset();
77
78 TGeoTrack* tr;
79 const Double_t* point;
80 for (Int_t i = 0; i < fTrackList->GetEntriesFast(); i++)
81 {
82 LOG(debug3)<<"MpdMCTracks::Exec "<<i;
83 tr = (TGeoTrack*) fTrackList->At(i);
84
85 TParticle* P = (TParticle*) tr->GetParticle();
86 Int_t particle_mother_id = P->GetMother(0);
87 Float_t particle_energy = P->Energy();
88 fEventManager->ExpandEnergyLimits(particle_energy);
89
90 LOG(debug3)<<"MinEnergyLimit "<<fEventManager->GetMinEnergyLimit()<<" MaxEnergyLimit "<<fEventManager->GetMaxEnergyLimit();
91 LOG(debug3)<<"Particle name: "<<P->GetName()<<" (pdg = "<<P->GetPdgCode()<<")";
92 LOG(debug3)<<"Parent track id = "<<particle_mother_id;
93 LOG(debug3)<<"Particle energy: "<<particle_energy<<" (cut: "<<fEventManager->GetMinEnergyCut()<<" - "<<fEventManager->GetMaxEnergyCut()<<")";
94 LOG(debug3)<<"Particle Px : Py : Pz = "<<P->Px()<<" : "<<P->Py()<<" : "<<P->Pz();
95 LOG(debug3)<<"Particle Vx : Vy : Vz: "<<P->Vx()<<" : "<<P->Vy()<<" : "<<P->Vz();
96
97 if ((fEventManager->IsPriOnly() && (particle_mother_id > -1)))
98 continue;
99 if ((fEventManager->fCurrentPDG.size() != 0) && (fEventManager->fCurrentPDG.find(tr->GetPDG()) == fEventManager->fCurrentPDG.end()))
100 continue;
101 if ((particle_energy < fEventManager->GetMinEnergyCut()) || (particle_energy > fEventManager->GetMaxEnergyCut()))
102 continue;
103
104 fTrList = GetTrGroup(P);
105 TEveTrack* track = new TEveTrack(P, tr->GetPDG(), fTrPr);
106 track->SetLineColor(fEventManager->Color(tr->GetPDG()));
107
108 Int_t Np = tr->GetNpoints();
109 for (Int_t n = 0; n < Np; n++)
110 {
111 point = tr->GetPoint(n);
112
113 track->SetPoint(n, point[0], point[1], point[2]);
114 TEveVector pos = TEveVector(point[0], point[1], point[2]);
115
116 TEvePathMark* path = new TEvePathMark();
117 path->fV = pos;
118 path->fTime = point[3];
119 if (n == 0)
120 {
121 TEveVector Mom = TEveVector(P->Px(), P->Py(), P->Pz());
122 path->fP = Mom;
123 }
124
125 track->AddPathMark(*path);
126 LOG(debug4)<<"Path marker added: "<<path<<". X : Y : Z = "<<point[0]<<" : "<<point[1]<<" : "<<point[2];
127
128 delete path;
129 }
130
131 fTrList->AddElement(track);
132 LOG(debug3)<<"Track added "<<track->GetName();
133 }
134
135 //for (Int_t i = 0; i < fEveTrList->GetEntriesFast(); i++)
136 //{
137 // TEveTrackList* TrListIn = (TEveTrackList*) fEveTrList->At(i);
138 // TrListIn->FindMomentumLimits(TrListIn, kFALSE);
139 //}
140
141 //gEve->Redraw3D(kFALSE);
142}
143
144// -------------------------------------------------------------------------
148
149// -------------------------------------------------------------------------
151{
152}
153
154// -------------------------------------------------------------------------
156{
157 for (Int_t i = 0; i < fEveTrList->GetEntriesFast(); i++)
158 {
159 TEveTrackList* ele = (TEveTrackList*) fEveTrList->At(i);
160 gEve->RemoveElement(ele, fEventManager->EveMCTracks);
161 }
162 fEveTrList->Clear();
163}
164
165TEveTrackList* MpdMCTracks::GetTrGroup(TParticle* P)
166{
167 fTrList = 0;
168 for (Int_t i = 0; i < fEveTrList->GetEntriesFast(); i++)
169 {
170 TEveTrackList* TrListIn = (TEveTrackList*) fEveTrList->At(i);
171 if (strcmp(TrListIn->GetName(), P->GetName()) == 0)
172 {
173 fTrList = TrListIn;
174 break;
175 }
176 }
177
178 if (fTrList == 0)
179 {
180 fTrPr = new TEveTrackPropagator();
181 fTrList = new TEveTrackList(P->GetName(), fTrPr);
182 // set track color by particle PDG from MpdEventManager
183 fTrList->SetMainColor(fEventManager->Color(P->GetPdgCode()));
184 fTrList->SetRnrLine(kTRUE);
185 fEveTrList->Add(fTrList);
186
188 }
189
190 return fTrList;
191}
int i
Definition P4_F32vec4.h:22
virtual void ExpandEnergyLimits(Float_t check_energy, float add_multiplier=1)
virtual Bool_t IsPriOnly()
static MpdEventManager * Instance()
TEveElementList * EveMCTracks
virtual Float_t GetMinEnergyLimit()
unordered_set< Int_t > fCurrentPDG
void AddEventElement(TEveElement *element, ElementList element_list)
virtual Int_t Color(Int_t pdg)
virtual Float_t GetMinEnergyCut()
virtual Float_t GetMaxEnergyCut()
virtual Float_t GetMaxEnergyLimit()
virtual void Exec(Option_t *option)
TClonesArray * fTrackList
Definition MpdMCTracks.h:51
TEveTrackList * GetTrGroup(TParticle *P)
virtual ~MpdMCTracks()
TObjArray * fEveTrList
Definition MpdMCTracks.h:54
TEveTrackList * fTrList
Definition MpdMCTracks.h:55
virtual void Finish()
virtual InitStatus Init()
virtual void SetParContainers()
TEveTrackPropagator * fTrPr
Definition MpdMCTracks.h:52
MpdEventManager * fEventManager
Definition MpdMCTracks.h:53
@ MCTrackList
STL namespace.