FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FairEveRecoTracksExample.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  * FairEveRecoTracksExample.cxx
10  *
11  * Created on: 16 cze 2020
12  * Author: Daniel Wielanek
13  * E-mail: daniel.wielanek@gmail.com
14  * Warsaw University of Technology, Faculty of Physics
15  */
16 
18 
19 #include "FairEveRecoTrack.h"
20 #include "FairEveTrack.h"
21 #include "FairField.h"
22 #include "FairHit.h"
23 #include "FairMCTrack.h"
24 #include "FairRKPropagator.h"
25 #include "FairRootManager.h"
26 #include "FairRunAna.h"
27 #include "FairTrackPar.h"
28 #include "FairTrackParP.h"
29 #include "FairTutPropHit.h"
30 #include "FairTutPropTrack.h"
31 
32 #include <TClonesArray.h>
33 #include <TDatabasePDG.h>
34 #include <TEveCompound.h>
35 #include <TEveElement.h>
36 #include <TEveManager.h>
37 #include <TEveTrack.h>
38 #include <TEveTrackPropagator.h>
39 #include <TMath.h>
40 #include <TObjArray.h>
41 #include <TParticle.h>
42 #include <TString.h>
43 #include <TVector3.h>
44 #include <utility>
45 
47  : FairEveTracks(kTRUE)
48  , fContainerReco(nullptr)
49  , fContainerSim(nullptr)
50  , fHits1(nullptr)
51  , fHits2(nullptr)
52  , fShowPrimary(kTRUE)
53  , fShowSecondary(kTRUE)
54  , fDrawMC(kTRUE)
55  , fUsePdg(kFALSE)
56  , fPdgCut(0)
57  , fRK(nullptr)
58  , fPDG(nullptr)
59 {
60  SetElementNameTitle("FairEveRecoTracksExample", "FairEveRecoTracksExample");
61 }
62 
64 {
66  TVector3 mom(par.GetPx(), par.GetPy(), par.GetPz());
67  if (UsePtCut()) {
68  if (mom.Pt() < GetPtMin())
69  return kFALSE;
70  if (mom.Pt() > GetPtMax())
71  return kFALSE;
72  }
73  if (UseEtaCut()) {
74  if (mom.Eta() < GetEtaMin())
75  return kFALSE;
76  if (mom.Eta() > GetEtaMax())
77  return kFALSE;
78  }
79  // assume pion mass
80  Double_t energy = TMath::Sqrt(mom.Mag2() + 0.139 * 0.139);
81  if (UseEnergyCut()) {
82  if (energy < GetEnergyMin())
83  return kFALSE;
84  if (energy > GetEnergyMax())
85  return kFALSE;
86  }
87  return kTRUE;
88 }
89 
91 {
92  FairTutPropTrack *tr = static_cast<FairTutPropTrack *>(fContainerReco->UncheckedAt(id));
93  FairMCTrack *mc = nullptr; // TODO add MC stuff
94  if (!CheckCuts(tr))
95  return;
96  Color_t col = kYellow;
97  TString gropuName = "neutral";
98  Int_t dummy_pid = 111;
99  Int_t q = tr->GetParamFirst().GetQ();
100  if (q < 0) {
101  gropuName = "neg";
102  col = kBlue;
103  dummy_pid = -211;
104  } else if (q > 0) {
105  gropuName = "pos";
106  col = kRed;
107  dummy_pid = 211;
108  }
109  TEveTrackList *trList = FindTrackGroup(gropuName, col);
111  TParticle p(
112  dummy_pid, 0, 0, 0, 0, 0, par.GetPx(), par.GetPy(), par.GetPz(), 0, par.GetX(), par.GetY(), par.GetZ(), 0);
113  FairEveRecoTrack *track = new FairEveRecoTrack(&p, par.GetQ(), trList->GetPropagator());
114  track->SetElementTitle(Form("p={%4.3f,%4.3f,%4.3f}", p.Px(), p.Py(), p.Pz()));
115  track->SetMainColor(col);
116  TVector3 pos(p.Vx(), p.Vy(), p.Vz());
117  TVector3 mom(p.Px(), p.Py(), p.Pz());
118  track->GetRecoTrack()->SetFirstPoint(mom, pos);
119  Double_t charge = par.GetQ();
120  Double_t P = 1.0 / mom.Mag();
121  Double_t vecRKIn[7] = {pos.X(), pos.Y(), pos.Z(), mom.Px() * P, mom.Py() * P, mom.Pz() * P, 1.0 / P};
122  Double_t vec1[3] = {0, 1, 0};
123  Double_t vec2[3] = {1, 0, 0};
124  Double_t vec3[3] = {0, 0, 0};
125  Double_t vecOut[7];
126 
127  for (int i = 0; i < 100; i++) {
128  vec3[2] = 10. * i;
129  fRK->PropagateToPlane(charge, vecRKIn, vec1, vec2, vec3, vecOut);
130  pos.SetXYZ(vecOut[0], vecOut[1], vecOut[2]);
131  track->GetRecoTrack()->SetNextPoint(pos);
132  }
133  for (int i = 0; i < tr->GetNofHits(); i++) {
134  std::pair<int, int> hitid = tr->GetHitIndex(i);
135  switch (hitid.first) {
136  case 1: {
137  FairTutPropHit *hit = static_cast<FairTutPropHit *>(fHits1->UncheckedAt(hitid.second));
138  track->AddHit(TVector3(hit->GetX(), hit->GetY(), hit->GetZ()));
139  } break;
140  case 2: {
141  FairTutPropHit *hit = static_cast<FairTutPropHit *>(fHits2->UncheckedAt(hitid.second));
142  track->AddHit(TVector3(hit->GetX(), hit->GetY(), hit->GetZ()));
143  } break;
144  default:
145  break;
146  }
147  }
148  if (fDrawMC && tr->GetMCTrackIndex() >= 0) {
149  mc = (FairMCTrack *)fContainerSim->UncheckedAt(tr->GetMCTrackIndex());
150  TParticle p_mc(mc->GetPdgCode(),
151  0,
152  0,
153  0,
154  0,
155  0,
156  mc->GetPx(),
157  mc->GetPy(),
158  mc->GetPz(),
159  mc->GetEnergy(),
160  mc->GetStartX(),
161  mc->GetStartY(),
162  mc->GetStartZ(),
163  mc->GetStartT());
164  track->InitMCTrack(&p_mc);
165  vecRKIn[0] = mc->GetStartX();
166  vecRKIn[1] = mc->GetStartY();
167  vecRKIn[2] = mc->GetStartZ();
168  P = 1.0 / TMath::Sqrt(mc->GetPx() * mc->GetPx() + mc->GetPy() * mc->GetPy() + mc->GetPz() * mc->GetPz());
169  vecRKIn[3] = mc->GetPx() * P;
170  vecRKIn[4] = mc->GetPy() * P;
171  vecRKIn[5] = mc->GetPz() * P;
172  vecRKIn[6] = 1.0 / P;
173  for (double z = mc->GetStartZ(); z < 100; z++) {
174  vec3[2] = z;
175  fRK->PropagateToPlane(charge, vecRKIn, vec1, vec2, vec3, vecOut);
176  pos.SetXYZ(vecOut[0], vecOut[1], vecOut[2]);
177  track->GetMCTrack()->SetNextPoint(pos);
178  }
179  }
180  track->CloseCompound();
181  track->GetRecoTrack()->SetRnrLine(kTRUE);
182  trList->AddElement(track);
183 }
184 
186 {
187  Int_t nTracks = fContainerReco->GetEntriesFast();
188  RemoveElements();
189  for (int i = 0; i < nTracks; i++) {
190  DrawTrack(i);
191  }
192  gEve->Redraw3D(kFALSE);
193 }
194 
196 {
198  fContainerReco = (TClonesArray *)mngr->GetObject("FairTutPropTracks");
199  if (fContainerReco == nullptr) {
200  LOG(ERROR) << "Reco traks not found";
201  return kFATAL;
202  }
203  fHits1 = (TClonesArray *)mngr->GetObject("FairTutPropHits");
204  fHits2 = (TClonesArray *)mngr->GetObject("FairTutPropHits2");
205  if (fHits1 == nullptr || fHits2 == nullptr) {
206  LOG(ERROR) << "Hits not found";
207  return kFATAL;
208  }
209  fContainerSim = (TClonesArray *)mngr->GetObject("MCTrack");
210  if (fContainerSim == nullptr) {
211  LOG(WARNING) << "No branch with MC tracks";
212  }
214  FairField *field = ana->GetField();
215  if (field == nullptr) {
216  LOG(ERROR) << "Lack of magnetic field map!";
217  field = new FairField();
218  }
219  fRK = new FairRKPropagator(field);
220  fPDG = TDatabasePDG::Instance();
221  return FairEveTracks::Init();
222 }
223 
225 {
226  if (fContainerSim) {
227  fDrawMC = draw;
228  }
229 }
230 
virtual Double_t GetPz() const
Definition: FairTrackPar.h:62
Double_t GetStartT() const
Definition: FairMCTrack.h:81
Double_t GetZ() const
Definition: FairHit.h:50
InitStatus
Definition: FairTask.h:33
Double_t GetPz() const
Definition: FairMCTrack.h:77
Double_t GetStartY() const
Definition: FairMCTrack.h:79
Double_t GetEtaMax() const
Definition: FairEveTracks.h:52
FairTrackParP GetParamFirst()
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
Double_t GetX() const
Definition: FairHit.h:48
TObject * GetObject(const char *BrName)
virtual Double_t GetZ()
Definition: FairTrackPar.h:51
void SetMainColor(Color_t color)
Double_t GetPx() const
Definition: FairMCTrack.h:75
virtual Double_t GetPx() const
Definition: FairTrackPar.h:60
Double_t GetEnergyMax() const
Definition: FairEveTracks.h:54
static FairRunAna * Instance()
Definition: FairRunAna.cxx:61
FairMQExParamsParOne * par
Double_t GetStartZ() const
Definition: FairMCTrack.h:80
Int_t GetQ() const
Definition: FairTrackPar.h:52
Bool_t UseEtaCut() const
Definition: FairEveTracks.h:56
Double_t GetY() const
Definition: FairHit.h:49
virtual Double_t GetPy() const
Definition: FairTrackPar.h:61
Bool_t CheckCuts(FairTutPropTrack *tr)
Double_t GetPtMax() const
Definition: FairEveTracks.h:50
Int_t GetPdgCode() const
Definition: FairMCTrack.h:73
virtual InitStatus Init()
virtual Double_t GetY()
Definition: FairTrackPar.h:50
Double_t GetEtaMin() const
Definition: FairEveTracks.h:51
Double_t GetPy() const
Definition: FairMCTrack.h:76
std::pair< int, int > GetHitIndex(int i)
TEveTrackList * FindTrackGroup(TString groupName, Color_t color)
virtual Double_t GetX()
Definition: FairTrackPar.h:49
Double_t GetPtMin() const
Definition: FairEveTracks.h:49
Double_t GetEnergy() const
Definition: FairMCTrack.h:133
FairField * GetField()
Definition: FairRunAna.h:78
void PropagateToPlane(double Charge, double *vecRKIn, double *vec1, double *vec2, double *vec3, double *vecOut)