FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FairTutPropTr.cxx
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2019 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  ********************************************************************************/
15 #include "FairTutPropTr.h"
16 
17 #include "FairLogger.h"
18 #include "FairRootManager.h"
19 #include "FairTrackParP.h"
20 #include "FairTutPropPoint.h"
21 #include "TClonesArray.h"
22 #include "TDatabasePDG.h"
23 
24 // ----- Default constructor -------------------------------------------
26  : FairTask("FairTutPropTr")
27  , fPropagatorSet(false)
28  , fPointArray(0)
29  , fTrackParIni(0)
30  , fTrackParFinal(0)
31  , fTrackParProp(0)
32  , fTrackParWrong(0)
33  , fPro(0)
34 {}
35 // -------------------------------------------------------------------------
36 
37 // ----- Destructor ----------------------------------------------------
39 {
40  Reset();
41  if (fTrackParIni) {
42  fTrackParIni->Delete();
43  delete fTrackParIni;
44  }
45  if (fTrackParProp) {
46  fTrackParProp->Delete();
47  delete fTrackParProp;
48  }
49  if (fTrackParWrong) {
50  fTrackParWrong->Delete();
51  delete fTrackParWrong;
52  }
53  if (fTrackParFinal) {
54  fTrackParFinal->Delete();
55  delete fTrackParFinal;
56  }
57 }
58 // -------------------------------------------------------------------------
59 
60 // ----- Public method Init --------------------------------------------
62 {
63 
64  // Get RootManager
66  if (!ioman) {
67  LOG(error) << "FairTutPropTr::Init: RootManager not instantised!";
68  return kFATAL;
69  }
70  fTrackParIni = new TClonesArray("FairTrackParP");
71  ioman->Register("PropTrackIni", "Prop", fTrackParIni, kTRUE);
72 
73  fTrackParFinal = new TClonesArray("FairTrackParP");
74  ioman->Register("PropTrackFinal", "Prop", fTrackParFinal, kTRUE);
75 
76  fTrackParProp = new TClonesArray("FairTrackParP");
77  ioman->Register("PropTrackPar", "Prop", fTrackParProp, kTRUE);
78 
79  fTrackParWrong = new TClonesArray("FairTrackParP");
80  ioman->Register("PropTrackParWrong", "Prop", fTrackParWrong, kTRUE);
81 
82  // Get input array
83 
84  fPointArray = static_cast<TClonesArray*>(ioman->GetObject("FairTutPropPoint"));
85 
86  return kSUCCESS;
87 }
88 // -------------------------------------------------------------------------
89 
90 // ----- Private method InitPropagator ---------------------------------
91 void FairTutPropTr::InitPropagator()
92 {
93  TVector3 planePoint(0., 0., 40.);
94  TVector3 planeVectJ(1., 0., 0.);
95  TVector3 planeVectK(0., 1., 0.);
96 
97  fPro->SetDestinationPlane(planePoint, planeVectJ, planeVectK);
98 
99  fPropagatorSet = true;
100  return;
101 }
102 // -------------------------------------------------------------------------
103 
104 // ----- Public method Exec --------------------------------------------
105 void FairTutPropTr::Exec(Option_t*)
106 {
107  Reset();
108 
109  if (!fPropagatorSet) {
110  InitPropagator();
111  }
112 
113  LOG(debug) << "FairTutPropTr::Exec";
114 
115  Int_t NoOfEntries = fPointArray->GetEntriesFast();
116  LOG(debug) << "fPointArray has " << NoOfEntries << " entries";
117  for (Int_t i = 0; i < NoOfEntries; i++) {
118  FairTutPropPoint* point1 = static_cast<FairTutPropPoint*>(fPointArray->At(i));
119  if (point1->GetZ() > 15.)
120  continue;
121  LOG(debug) << "first loop for " << i << "from " << NoOfEntries << " entries ";
122  Int_t trId = point1->GetTrackID();
123  FairTutPropPoint* point2 = 0;
124  for (Int_t k = 0; k < NoOfEntries; k++) {
125  point2 = static_cast<FairTutPropPoint*>(fPointArray->At(k));
126  if (point2->GetZ() < 35.)
127  continue;
128  LOG(debug) << "second loop for " << k;
129  if (point2->GetTrackID() == trId)
130  break;
131  }
132 
133  if (point2 == 0)
134  break;
135 
136  TVector3 StartPos(point1->GetX(), point1->GetY(), point1->GetZ());
137  TVector3 StartPosErr(0, 0, 0);
138  TVector3 StartMom(point1->GetPx(), point1->GetPy(), point1->GetPz());
139  TVector3 StartMomErr(0, 0, 0);
140 
141  TVector3 EndPos(point2->GetX(), point2->GetY(), point2->GetZ());
142  TVector3 EndPosErr(0, 0, 0);
143  TVector3 EndMom(point2->GetPx(), point2->GetPy(), point2->GetPz());
144  TVector3 EndMomErr(0, 0, 0);
145 
146  Int_t PDGCode = -13;
147 
148  TDatabasePDG* fdbPDG = TDatabasePDG::Instance();
149  TParticlePDG* fParticle = fdbPDG->GetParticle(PDGCode);
150  Double_t fCharge = fParticle->Charge();
151 
152  TClonesArray& clref1 = *fTrackParIni;
153  Int_t size1 = clref1.GetEntriesFast();
154  FairTrackParP* fStart = new (clref1[size1]) FairTrackParP(StartPos,
155  StartMom,
156  StartPosErr,
157  StartMomErr,
158  fCharge,
159  TVector3(0., 0., 10.),
160  TVector3(1., 0., 0.),
161  TVector3(0., 1., 0.));
162  // fStart->Print();
163 
164  TClonesArray& clref = *fTrackParProp;
165  Int_t size = clref.GetEntriesFast();
166  FairTrackParP* fRes = new (clref[size]) FairTrackParP();
167  // fRes->Print();
168 
169  TClonesArray& clrew = *fTrackParWrong;
170  Int_t sizeW = clrew.GetEntriesFast();
171  FairTrackParP* fWro = new (clrew[sizeW]) FairTrackParP();
172  // fRes->Print();
173 
174  TClonesArray& clref2 = *fTrackParFinal;
175  Int_t size2 = clref2.GetEntriesFast();
176  [[gnu::unused]] FairTrackParP* fFinal = new (clref2[size2]) FairTrackParP(EndPos,
177  EndMom,
178  EndPosErr,
179  EndMomErr,
180  fCharge,
181  TVector3(0., 0., 40.),
182  TVector3(1., 0., 0.),
183  TVector3(0., 1., 0.));
184 
185  fPro->Propagate(fStart, fRes, PDGCode);
186 
187  // use wrong pdg code
188  fPro->Propagate(fStart, fWro, -PDGCode);
189 
190  /*
191  LOG(info) << "SetPCAPropagation from " << fFinal->GetX() << ", " << fFinal->GetY() << ", " << fFinal->GetZ()
192  << " / " << fFinal->GetPx() << ", " << fFinal->GetPy() << ", " << fFinal->GetPz();
193  fPro->SetPCAPropagation(1,-1,fFinal);
194  LOG(info) << "FindPCA";
195  PCAOutputStruct pcaToPoint = fPro->FindPCA(1, PDGCode, TVector3(2.5,0.5,15.), TVector3(0.,0.,0.),
196  TVector3(0.,0.,0.), 15.); LOG(info) << "findpca = " << pcaToPoint.PCAStatusFlag << " with distance " <<
197  pcaToPoint.Distance
198  << ", closest point at (" << pcaToPoint.OnTrackPCA.X() << "," << pcaToPoint.OnTrackPCA.Y() << "," <<
199  pcaToPoint.OnTrackPCA.Z() << ")";
200 
201  PCAOutputStruct pcaToWire = fPro->FindPCA(2, PDGCode, TVector3(0.,0.,0.), TVector3(-10.,-10.,15.),
202  TVector3(10.,10.,15.), 15.); LOG(info) << "findpca = " << pcaToWire.PCAStatusFlag << " with distance " <<
203  pcaToWire.Distance
204  << ", closest point at (" << pcaToWire.OnTrackPCA.X() << "," << pcaToWire.OnTrackPCA.Y() << "," <<
205  pcaToWire.OnTrackPCA.Z() << ")"
206  << ", on the wire (" << pcaToWire.OnWirePCA.X() << "," << pcaToWire.OnWirePCA.Y() << "," <<
207  pcaToWire.OnWirePCA.Z() << ")";
208  */
209  }
210 }
211 
212 // ----- Private method Reset ------------------------------------------
213 void FairTutPropTr::Reset()
214 {
215  if (fTrackParIni)
216  fTrackParIni->Clear();
217  if (fTrackParProp)
218  fTrackParProp->Clear();
219  if (fTrackParWrong)
220  fTrackParWrong->Clear();
221  if (fTrackParFinal)
222  fTrackParFinal->Clear();
223 }
224 // -------------------------------------------------------------------------
225 
226 // ----- Public method Finish ------------------------------------------
227 void FairTutPropTr::Finish()
228 {
229  if (fTrackParIni)
230  fTrackParIni->Delete();
231  if (fTrackParProp)
232  fTrackParProp->Delete();
233  if (fTrackParWrong)
234  fTrackParWrong->Delete();
235  if (fTrackParFinal)
236  fTrackParFinal->Delete();
237 }
238 
Double_t GetPx() const
Definition: FairMCPoint.h:59
InitStatus
Definition: FairTask.h:33
Double_t GetZ() const
Definition: FairMCPoint.h:69
Double_t GetX() const
Definition: FairMCPoint.h:67
static FairRootManager * Instance()
ClassImp(FairEventBuilder)
virtual bool SetDestinationPlane([[gnu::unused]] const TVector3 &v0, [[gnu::unused]] const TVector3 &v1, [[gnu::unused]] const TVector3 &v2)
virtual bool Propagate([[gnu::unused]] FairTrackParH *TStart, [[gnu::unused]] FairTrackParH *TEnd, [[gnu::unused]] int PDG)
TObject * GetObject(const char *BrName)
Int_t GetTrackID() const
event identifier
Definition: FairMCPoint.h:58
Double_t GetPz() const
Definition: FairMCPoint.h:61
Double_t GetPy() const
Definition: FairMCPoint.h:60
void Register(const char *name, const char *Foldername, TNamed *obj, Bool_t toFile)
virtual void Exec(Option_t *opt)
Double_t GetY() const
Definition: FairMCPoint.h:68
virtual InitStatus Init()