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