FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FairEveMCTracks.cxx
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2020 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
8 /*
9  * FairMCTracks.cxx
10  *
11  * Created on: 27 sie 2020
12  * Author: Daniel Wielanek
13  * E-mail: daniel.wielanek@gmail.com
14  * Warsaw University of Technology, Faculty of Physics
15  */
16 #include "FairEveMCTracks.h"
17 
18 #include "FairEveTrack.h" // for FairEveTrack
19 #include "FairEventManager.h" // for FairEventManager
20 #include "FairField.h" // for FairField
21 #include "FairMCTrack.h" // for FairMCTrack
22 #include "FairRKPropagator.h" // for FairRKPropagator
23 #include "FairRootManager.h" // for FairRootManager
24 #include "FairRunAna.h" // for FairRunAna
25 
26 #include <TClonesArray.h> // for TClonesArray
27 #include <TDatabasePDG.h> // for TDatabasePDG
28 #include <TEveManager.h> // for TEveManager, gEve
29 #include <TEveTrack.h> // for TEveTrackList
30 #include <TLorentzVector.h> // for TLorentzVector
31 #include <TParticle.h> // for TParticle
32 #include <TParticlePDG.h> // for TParticlePDG
33 #include <TString.h> // for Form
34 #include <TVector3.h> // for TVector3
35 #include <fairlogger/Logger.h> // for LOG
36 
38  : FairEveTracks(kFALSE)
39  , fContainer(nullptr)
40  , fShowPrimary(kTRUE)
41  , fShowSecondary(kTRUE)
42  , fUsePdg(kFALSE)
43  , fPdgCut(0)
44  , fRK(nullptr)
45  , fPDG(nullptr)
46 {
47  SetElementNameTitle("FairMCTracks", "FairMCTracks");
48 }
49 
51 {
52  TLorentzVector mom;
53  tr->Get4Momentum(mom);
54  if (UsePtCut()) {
55  if (tr->GetPt() < GetPtMin())
56  return kFALSE;
57  if (tr->GetPt() > GetPtMax())
58  return kFALSE;
59  }
60  if (UseEtaCut()) {
61  if (mom.Eta() < GetEtaMin())
62  return kFALSE;
63  if (mom.Eta() > GetEtaMax())
64  return kFALSE;
65  }
66  if (UseEnergyCut()) {
67  if (mom.Energy() < GetEnergyMin())
68  return kFALSE;
69  if (mom.Energy() > GetEnergyMax())
70  return kFALSE;
71  }
72  if (fUsePdg) {
73  if (tr->GetPdgCode() != fPdgCut)
74  return kFALSE;
75  }
76  Bool_t primary = kTRUE;
77  if (tr->GetMotherId() != -1)
78  primary = kFALSE;
79  if (fShowPrimary && primary)
80  return kTRUE;
81  if (fShowSecondary && !primary)
82  return kTRUE;
83  return kFALSE;
84 }
85 
87 {
88  if (!fRK)
89  return;
90 
91  FairMCTrack *tr = (FairMCTrack *)fContainer->UncheckedAt(id);
92  if (!CheckCuts(tr))
93  return;
94  Color_t color = GetEventManager()->Color(tr->GetPdgCode());
95  TEveTrackList *trList = FindTrackGroup(Form("%i", tr->GetPdgCode()), color);
96  TParticle p(tr->GetPdgCode(),
97  0,
98  0,
99  0,
100  0,
101  0,
102  tr->GetPx(),
103  tr->GetPy(),
104  tr->GetPz(),
105  tr->GetEnergy(),
106  tr->GetStartX(),
107  tr->GetStartY(),
108  tr->GetStartZ(),
109  tr->GetStartT());
110  FairEveTrack *track = new FairEveTrack(&p, tr->GetPdgCode(), trList->GetPropagator());
111  track->SetElementTitle(Form("p={%4.3f,%4.3f,%4.3f}", p.Px(), p.Py(), p.Pz()));
112  track->SetMainColor(color);
113  TVector3 pos(p.Vx(), p.Vy(), p.Vz());
114  TVector3 mom(p.Px(), p.Py(), p.Pz());
115  track->SetFirstPoint(mom, pos);
116 
117  TParticlePDG *part = fPDG->GetParticle(tr->GetPdgCode());
118 
119  Double_t charge = 0;
120  if (part) {
121  charge = part->Charge() / 3.0;
122  }
123  Double_t P = 1.0 / mom.Mag();
124  Double_t vecRKIn[7] = {pos.X(), pos.Y(), pos.Z(), mom.Px() * P, mom.Py() * P, mom.Pz() * P, 1.0 / P};
125  Double_t vec1[3] = {0, 1, 0};
126  Double_t vec2[3] = {1, 0, 0};
127  Double_t vec3[3] = {0, 0, 0};
128  Double_t vecOut[7];
129  for (int i = 0; i < 100; i++) {
130  vec3[2] = 10. * i;
131  fRK->PropagateToPlane(charge, vecRKIn, vec1, vec2, vec3, vecOut);
132  pos.SetXYZ(vecOut[0], vecOut[1], vecOut[2]);
133  track->SetNextPoint(pos);
134  }
135  track->SetRnrLine(kTRUE);
136  trList->AddElement(track);
137 }
138 
140 {
141  Int_t nTracks = fContainer->GetEntriesFast();
142  RemoveElements();
143  for (int i = 0; i < nTracks; i++) {
144  DrawTrack(i);
145  }
146  gEve->Redraw3D(kFALSE);
147 }
148 
150 {
152  fContainer = (TClonesArray *)mngr->GetObject("MCTrack");
153  if (fContainer == nullptr)
154  return kFATAL;
156  FairField *field = ana->GetField();
157  if (field == nullptr) {
158  LOG(ERROR) << "Lack of magnetic field map!";
159  } else {
160  fRK = new FairRKPropagator(field);
161  }
162  fPDG = TDatabasePDG::Instance();
163  return FairEveTracks::Init();
164 }
165 
Double_t GetStartT() const
Definition: FairMCTrack.h:81
InitStatus
Definition: FairTask.h:33
Int_t GetMotherId() const
Definition: FairMCTrack.h:74
Double_t GetPz() const
Definition: FairMCTrack.h:77
FairEventManager * GetEventManager() const
Definition: FairEveTracks.h:58
Double_t GetStartY() const
Definition: FairMCTrack.h:79
Double_t GetEtaMax() const
Definition: FairEveTracks.h:52
virtual ~FairEveMCTracks()
virtual InitStatus Init()
Double_t GetStartX() const
Definition: FairMCTrack.h:78
Bool_t UseEnergyCut() const
Definition: FairEveTracks.h:57
static FairRootManager * Instance()
Bool_t UsePtCut() const
Definition: FairEveTracks.h:55
Double_t GetEnergyMin() const
Definition: FairEveTracks.h:53
TObject * GetObject(const char *BrName)
void DrawTrack(Int_t id)
Double_t GetPx() const
Definition: FairMCTrack.h:75
void Get4Momentum(TLorentzVector &momentum)
Definition: FairMCTrack.h:141
Double_t GetEnergyMax() const
Definition: FairEveTracks.h:54
static FairRunAna * Instance()
Definition: FairRunAna.cxx:61
virtual Int_t Color(Int_t pdg)
Double_t GetStartZ() const
Definition: FairMCTrack.h:80
Double_t GetPt() const
Definition: FairMCTrack.h:84
Bool_t UseEtaCut() const
Definition: FairEveTracks.h:56
Double_t GetPtMax() const
Definition: FairEveTracks.h:50
Int_t GetPdgCode() const
Definition: FairMCTrack.h:73
virtual InitStatus Init()
Bool_t CheckCuts(FairMCTrack *tr)
Double_t GetEtaMin() const
Definition: FairEveTracks.h:51
Double_t GetPy() const
Definition: FairMCTrack.h:76
TEveTrackList * FindTrackGroup(TString groupName, Color_t color)
Double_t GetPtMin() const
Definition: FairEveTracks.h:49
Double_t GetEnergy() const
Definition: FairMCTrack.h:133
FairField * GetField()
Definition: FairRunAna.h:78
void SetFirstPoint(const TVector3 &mom, const TVector3 &pos)
void PropagateToPlane(double Charge, double *vecRKIn, double *vec1, double *vec2, double *vec3, double *vecOut)