BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
MpdMCStack.cxx
Go to the documentation of this file.
1// -------------------------------------------------------------------------
2// ----- MpdMCStack source file -----
3// ----- Created 09/10/08 by M. Al-Turany -----
4// -------------------------------------------------------------------------
5
6#include "MpdMCStack.h"
7#ifdef BMNROOT
8#include "CbmMCTrack.h"
9#else
10#include "FairMCTrack.h"
11#endif
12#include "FairLogger.h"
13#include "FairRootManager.h"
14#include "TClonesArray.h"
15#include "TDatabasePDG.h"
16#include "TEveManager.h"
17#include "TGeoTrack.h"
18#include "TParticlePDG.h"
19
20#include <iostream>
21using namespace std;
22
23// ----- Default constructor -------------------------------------------
25
26// ----- Standard constructor ------------------------------------------
27MpdMCStack::MpdMCStack(const char* name, Int_t iVerbose)
28 : FairTask(name, iVerbose)
29 , fEveTrList(new TObjArray(16))
30{}
31
32// ----- Destructor ----------------------------------------------------
34
35// -------------------------------------------------------------------------
36InitStatus MpdMCStack::Init()
37{
38 if (fVerbose > 1)
39 cout << "MpdMCStack::Init()" << endl;
40
41 FairRootManager* fManager = FairRootManager::Instance();
42
43 fTrackList = (TClonesArray*)fManager->GetObject("MCTrack");
44 if (fTrackList == 0) {
45 LOG(error) << "MpdMCStack::Init() branch " << GetName() << " not found! Task will be deactivated";
46 SetActive(kFALSE);
47 }
48 if (fVerbose > 2)
49 cout << "MpdMCStack::Init() get track list" << fTrackList << endl;
50
52 if (fVerbose > 2)
53 cout << "MpdMCStack::Init() get instance of MpdEventManager" << endl;
54
55 fPro = new FairGeanePro();
56 gMC3 = (TGeant3*)gMC;
57
58 x1[0] = 0;
59 x1[1] = 0;
60 x1[2] = 0;
61 p1[0] = 0;
62 p1[1] = 0;
63 p1[2] = 0;
64 x2[0] = 0;
65 x2[1] = 0;
66 x2[2] = 0;
67 p2[0] = 0;
68 p2[1] = 0;
69 p2[2] = 0;
70 for (Int_t i = 0; i < 15; i++)
71 ein[i] = 0;
72
73 // Float_t length[1];
74 // length[0] = 100.0;
75 // gMC3->Eufill(1, ein, length);
76
77 fTrajFilter = FairTrajFilter::Instance();
78
79 if (IsActive())
80 return kSUCCESS;
81 else
82 return kERROR;
83}
84
85// -------------------------------------------------------------------------
86void MpdMCStack::Exec(Option_t* /*option*/)
87{
88 if (!IsActive())
89 return;
90
91 if (fVerbose > 1)
92 cout << "MpdMCStack::Exec" << endl;
93 Reset();
94
95 for (Int_t i = 0; i < fTrackList->GetEntriesFast(); i++) {
96 if (fVerbose > 2)
97 cout << "MpdMCStack::Exec " << i << endl;
98
99#ifdef BMNROOT
100 CbmMCTrack* tr = (CbmMCTrack*)fTrackList->At(i);
101#else
102 FairMCTrack* tr = (FairMCTrack*)fTrackList->At(i);
103#endif
104
105 TVector3 Ptot;
106 tr->GetMomentum(Ptot);
107 Int_t MotherId = tr->GetMotherId();
108 TVector3 Vertex;
109 tr->GetStartVertex(Vertex);
110
111 Double_t time = tr->GetStartT() * 1e-09;
112 x1[0] = Vertex.x();
113 x1[1] = Vertex.y();
114 x1[2] = Vertex.z();
115 p1[0] = Ptot.Px();
116 p1[1] = Ptot.Py();
117 p1[2] = Ptot.Pz();
118
119 // TParticle* P = (TParticle*) tr->GetParticle();
121
122 Double_t mass = 0, ene = 0;
123 if (fParticlePDG)
124 mass = fParticlePDG->Mass();
125 if (mass >= 0)
126 ene = TMath::Sqrt(mass * mass + Ptot.Mag2());
127
128 // TParticle(Int_t pdg, Int_t status, Int_t mother1, Int_t mother2, Int_t daughter1, Int_t daughter2, Double_t
129 // px, Double_t py, Double_t pz, Double_t etot, Double_t vx, Double_t vy, Double_t vz, Double_t time)
130 TParticle* P = new TParticle(tr->GetPdgCode(), i, MotherId, -1, -1, -1, Ptot.Px(), Ptot.Py(), Ptot.Pz(), ene,
131 Vertex.x(), Vertex.z(), Vertex.z(), time);
132 // Int_t particle_mother_id = P->GetMother(0);
133 Float_t particle_energy = P->Energy();
134 fEventManager->ExpandEnergyLimits(particle_energy);
135
136 if (fVerbose > 2)
137 cout << "MinEnergyLimit " << fEventManager->GetMinEnergyLimit() << " MaxEnergyLimit "
138 << fEventManager->GetMaxEnergyLimit() << endl;
139
140 if ((fEventManager->IsPriOnly() && (P->GetMother(0) > -1)))
141 continue;
142 if ((fEventManager->fCurrentPDG.size() != 0)
143 && (fEventManager->fCurrentPDG.find(tr->GetPdgCode()) == fEventManager->fCurrentPDG.end()))
144 continue;
145 if (fVerbose > 2)
146 cout << "PEnergy " << particle_energy << " Min " << fEventManager->GetMinEnergyCut() << " Max "
147 << fEventManager->GetMaxEnergyCut() << endl;
148 if ((particle_energy < fEventManager->GetMinEnergyCut())
149 || (particle_energy > fEventManager->GetMaxEnergyCut()))
150 continue;
151
152 // Int_t Np = tr->GetNpoints();
153 fTrList = GetTrGroup(P);
154 TEveTrack* track = new TEveTrack(P, tr->GetPdgCode(), fTrPr);
155 track->SetLineColor(fEventManager->Color(tr->GetPdgCode()));
156
157 // PROPAGATION
158 // Int_t GeantCode = TDatabasePDG::Instance()->ConvertPdgToGeant3(tr->GetPdgCode());
159 // gMC3->Ertrak(x1, p1, x2, p2,G eantCode, "L");
160 fPro->SetDestinationLength(100.0);
161 fPro->Propagate(x1, p1, x2, p2, tr->GetPdgCode());
162 TGeoTrack* tr1 = fTrajFilter->GetCurrentTrk();
163
164 const Double_t* point;
165 Int_t Np = tr1->GetNpoints();
166 for (Int_t n = 0; n < Np; n++) {
167 point = tr1->GetPoint(n);
168 track->SetPoint(n, point[0], point[1], point[2]);
169 TEveVector pos = TEveVector(point[0], point[1], point[2]);
170
171 TEvePathMark* path = new TEvePathMark();
172 path->fV = pos;
173 path->fTime = point[3];
174 if (n == 0) {
175 TEveVector Mom = TEveVector(P->Px(), P->Py(), P->Pz());
176 path->fP = Mom;
177 }
178
179 track->AddPathMark(*path);
180 if (fVerbose > 3)
181 cout << "Path marker added " << path << endl;
182 }
183
184 fTrList->AddElement(track);
185 if (fVerbose > 3)
186 cout << "Track added " << track->GetName() << endl;
187 }
188
189 // for (Int_t i = 0; i < fEveTrList->GetEntriesFast(); i++)
190 //{
191 // TEveTrackList* TrListIn = (TEveTrackList*) fEveTrList->At(i);
192 // TrListIn->FindMomentumLimits(TrListIn, kFALSE);
193 // }
194
195 // gEve->Redraw3D(kFALSE);
196}
197
198// -------------------------------------------------------------------------
200
201// -------------------------------------------------------------------------
203
204// -------------------------------------------------------------------------
206{
207 for (Int_t i = 0; i < fEveTrList->GetEntriesFast(); i++) {
209 gEve->RemoveElement(ele, fEventManager);
210 }
211 fEveTrList->Clear();
212}
213
215{
216 fTrList = 0;
217 for (Int_t i = 0; i < fEveTrList->GetEntriesFast(); i++) {
218 TEveTrackList* TrListIn = (TEveTrackList*)fEveTrList->At(i);
219
220 if (strcmp(TrListIn->GetName(), P->GetName()) == 0) {
221 fTrList = TrListIn;
222 break;
223 }
224 }
225
226 if (fTrList == 0) {
228 fTrList = new TEveTrackList(P->GetName(), fTrPr);
229 fTrList->SetMainColor(fEventManager->Color(P->GetPdgCode()));
230 fTrList->SetRnrLine(kTRUE);
231
232 fEveTrList->Add(fTrList);
233 gEve->AddElement(fTrList, fEventManager);
234 }
235
236 return fTrList;
237}
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
CbmMCTrack.h.
Definition CbmMCTrack.h:26
void GetMomentum(TVector3 &momentum) const
Definition CbmMCTrack.h:139
Int_t GetMotherId() const
Definition CbmMCTrack.h:57
Double_t GetStartT() const
Definition CbmMCTrack.h:64
void GetStartVertex(TVector3 &vertex) const
Definition CbmMCTrack.h:149
Int_t GetPdgCode() const
Accessors.
Definition CbmMCTrack.h:56
static MpdEventManager * Instance()
Float_t ein[15]
Definition MpdMCStack.h:52
TEveTrackList * GetTrGroup(TParticle *P)
MpdMCStack()
Default constructor.
TEveTrackList * fTrList
Definition MpdMCStack.h:50
virtual ~MpdMCStack()
Destructor.
TGeant3 * gMC3
Definition MpdMCStack.h:53
FairGeanePro * fPro
Definition MpdMCStack.h:54
TObjArray * fEveTrList
Definition MpdMCStack.h:48
virtual InitStatus Init()
virtual void Exec(Option_t *option)
Executed task.
FairTrajFilter * fTrajFilter
Definition MpdMCStack.h:55
TClonesArray * fTrackList
Definition MpdMCStack.h:47
virtual void Finish()
Action after each event.
Float_t x2[3]
Definition MpdMCStack.h:52
TEveTrackPropagator * fTrPr
Definition MpdMCStack.h:49
Float_t p1[3]
Definition MpdMCStack.h:52
virtual void SetParContainers()
Float_t p2[3]
Definition MpdMCStack.h:52
MpdEventManager * fEventManager
Definition MpdMCStack.h:45
Float_t x1[3]
Definition MpdMCStack.h:52
static TDatabasePDG * Instance()
TParticlePDG * GetParticle(const char *name) const
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 Mass() const
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
Int_t GetMother(Int_t i) const
void SetPoint(Int_t n, Double_t x, Double_t y, Double_t z)
const char * GetName() const override
Double_t Px() const
Double_t Py() const
Double_t Mag2() const
Double_t Pz() const
*brief user defined string literal for JSON values *sa std::size_t n
Definition json.hpp:20362
Double_t Sqrt(Double_t x)
Definition json.hpp:4446