FairRoot/PandaRoot
PndMvdRiemannTrackFinderTaskEff.cxx
Go to the documentation of this file.
2 
3 #include <iostream>
4 #include <stdlib.h>
5 #include <math.h>
6 #include <vector>
7 
8 // Root includes
9 #include "TROOT.h"
10 #include "TString.h"
11 #include "TClonesArray.h"
12 #include "TParticlePDG.h"
13 #include "TFile.h"
14 #include "TVector.h"
15 
16 // framework includes
17 #include "FairRootManager.h"
18 #include "FairRun.h"
19 #include "FairRuntimeDb.h"
20 #include "PndMCTrack.h"
21 
22 
23 // PndMvd includes
24 #include "PndTrackCand.h"
25 #include "PndSdsHit.h"
26 #include "PndMCTrack.h"
27 #include "PndDetectorList.h"
28 
29 #include "PndRiemannHit.h"
30 #include "PndRiemannTrack.h"
31 
33  eff0H(NULL),
34  effH(NULL),
35  GhH(NULL),
36  fHitBranch("MVDHitsPixel"),
37  fHitBranch2("MVDHitsStrip"),
38  fMCTrackBranch("MCTrack"),
39  fIdealTrackBranch("MVDIdealTrackCand"),
40  fFTrackBranch("MVDRiemannTrackCand"),
41  fEventNr(0),
42  fMaxSZChi2(1),
43  fMaxSZDist(10),
44  fMinPointDist(1),
45  fMaxDist(1),
46  fHitArray(NULL),
47  fHitArray2(NULL),
48  fTrackCandArray(NULL),
49  fIdealTrackCandArray(NULL),
50  fMCTracksArray(NULL)
51 {
52 }
53 
55 {
56 }
57 
59 {
60 }
61 
63 {
64  InitStatus stat=kSUCCESS;
65  return stat;
66 }
67 
68 // ----- Public method Init --------------------------------------------
70 {
71 
72  FairRootManager* ioman = FairRootManager::Instance();
73 
74  if ( ! ioman )
75  {
76  std::cout << "-E- PndMvdRiemannTrackFinderTask::Init: "
77  << "RootManager not instantiated!" << std::endl;
78  return kFATAL;
79  }
80 
81  // Get input array
82  fHitArray = (TClonesArray*) ioman->GetObject(fHitBranch);
83  if ( !fHitArray){
84  std::cout << "-W- PndMvdRiemannTrackFinderTask::Init: " << "No hitArray!" << std::endl;
85  return kERROR;
86  }
87 
88  fHitArray2 = (TClonesArray*) ioman->GetObject(fHitBranch2);
89  if ( !fHitArray2){
90  std::cout << "-W- PndMvdRiemannTrackFinderTask::Init: " << "No hitArray2!" << std::endl;
91  return kERROR;
92  }
93 
94  fMCTracksArray = (TClonesArray*) ioman->GetObject(fMCTrackBranch);
95  if ( !fMCTracksArray){
96  std::cout << "-W- PndMvdRiemannTrackFinderTask::Init: " << "No MCtracks!" << std::endl;
97  return kERROR;
98  }
99 
100  fIdealTrackCandArray = (TClonesArray*) ioman->GetObject(fIdealTrackBranch);
101  if ( !fIdealTrackCandArray){
102  std::cout << "-W- PndMvdRiemannTrackFinderTask::Init: " << "No IdealTrackCands!" << std::endl;
103  return kERROR;
104  }
105  fTrackCandArray = (TClonesArray*) ioman->GetObject(fFTrackBranch);
106  if ( !fTrackCandArray){
107  std::cout << "-W- PndMvdRiemannTrackFinderTask::Init: " << "No FTrackCands!" << std::endl;
108  return kERROR;
109  }
110 
111  int Nbin=10;
112  eff0H = new TH2F("eff0H","eff0H",Nbin,0.1,1,Nbin,15,150);
113  effH = new TH2F("effH","effH",Nbin,0.1,1,Nbin,15,150);
114 
115  GhH = new TH2F("GhH","GhH",Nbin,0.1,1,Nbin,15,150);
116 
117  std::cout << "-I- PndMvdRiemannTrackFinderTask: Initialisation successfull" << std::endl;
118  return kSUCCESS;
119 }
120 
121 // ----- Public method Exec --------------------------------------------
123 {
124 
125  std::vector<PndTrackCand*> RecoT;
126 
127  for(int i=0;i<fIdealTrackCandArray->GetEntriesFast();i++){
129  PndMCTrack* myTrack = (PndMCTrack*)fMCTracksArray->At(cand->getMcTrackId());
130  if (CheckRecoTrack(cand,myTrack)){
131  if (myTrack->GetMotherID()==-1) cand->AddHit(0,0,0);
132  RecoT.push_back(cand);
133  TVector3 Pvec=myTrack->GetMomentum();
134  double Theta=180.0*Pvec.Theta()/TMath::Pi();
135  double P=Pvec.Mag();
136  eff0H->Fill(P,Theta);
137  }
138  }
139  ComparingFandR(RecoT);
140  std::cout<<" Event n: "<<fEventNr++<<std::endl;
141 
142 }
143 
145 {
146 }
147 bool PndMvdRiemannTrackFinderTaskEff::CheckRecoTrack(PndTrackCand *cand,PndMCTrack* ) //myTrack //[R.K.03/2017] unused variable(s)
148 {
149  if (/*myTrack->GetPdgCode()==211 &&*/ (cand->GetNHits()>2)/* && (myTrack->GetMotherID()==-1)*/){
150  int count=0;
151  unsigned int detIDi, hitIDi;
152  unsigned int detIDj, hitIDj;
153  for(unsigned int i=0;i<cand->GetNHits();i++){
154  detIDi=cand->GetSortedHit(i).GetDetId();
155  hitIDi=cand->GetSortedHit(i).GetHitId();
156  PndSdsHit *pointI;
157  if ((int)detIDi == FairRootManager::Instance()->GetBranchId(fHitBranch))
158  pointI = (PndSdsHit*)fHitArray->At(hitIDi);
159  else if ((int)detIDi == FairRootManager::Instance()->GetBranchId(fHitBranch2))
160  pointI = (PndSdsHit*)fHitArray2->At(hitIDi);
161  else pointI = 0;
162 
163  for(unsigned int j=0;j<cand->GetNHits();j++){
164  detIDj=cand->GetSortedHit(j).GetDetId();
165  hitIDj=cand->GetSortedHit(j).GetHitId();
166  PndSdsHit *pointJ;
167  if ((int)detIDj == FairRootManager::Instance()->GetBranchId(fHitBranch))
168  pointJ = (PndSdsHit*)fHitArray->At(hitIDj);
169  else if ((int)detIDj == FairRootManager::Instance()->GetBranchId(fHitBranch2))
170  pointJ = (PndSdsHit*)fHitArray2->At(hitIDj);
171  else pointJ = 0;
172 
173  if ((pointI!=0) && (pointJ!=0) && (i!=j)){
174  TVector3 a=pointI->GetPosition() - pointJ->GetPosition();
175  if (a.Mag()<fMinPointDist){
176  count++;
177  }
178  }
179  }
180  }
181  if ((cand->GetNHits()-count/2)<3){
182  std::cout <<"Less then 3 base points in RecoTrack"<<" "<<cand->GetNHits()<<" "<<count <<std::endl;
183  return false;
184  }
185  else return true;
186  }
187  else
188  return false;
189 }
190 void PndMvdRiemannTrackFinderTaskEff::ComparingFandR(std::vector<PndTrackCand*> RecoT)
191 {
192  unsigned int detidRC, hitidRC;
193  unsigned int detidF, hitidF;
194  for(int trackF=0;trackF<fTrackCandArray->GetEntriesFast();trackF++){
195  for(unsigned int trackRC=0;trackRC<RecoT.size();trackRC++){
196  int cSame=0;
197  for(unsigned int iF=0;iF<((PndTrackCand*)fTrackCandArray->At(trackF))->GetNHits();iF++){
198  detidF=((PndTrackCand*)fTrackCandArray->At(trackF))->GetSortedHit(iF).GetDetId();
199  hitidF=((PndTrackCand*)fTrackCandArray->At(trackF))->GetSortedHit(iF).GetHitId();
200  for(unsigned int iRC=0;iRC<RecoT[trackRC]->GetNHits();iRC++){
201  detidRC=RecoT[trackRC]->GetSortedHit(iRC).GetDetId();
202  hitidRC=RecoT[trackRC]->GetSortedHit(iRC).GetHitId();
203  if (detidRC==detidF && hitidRC==hitidF){
204  cSame++;
205  }
206  }
207  }
208 
209  PndMCTrack* myTrack = (PndMCTrack*)fMCTracksArray->At(RecoT[trackRC]->getMcTrackId());
210  if ( (cSame>=4) && ((int)(((PndTrackCand*)fTrackCandArray->At(trackF))->GetNHits())==cSame)){
211  std::cout<<"TRUE FOUND"<<std::endl;
212  TVector3 Pvec=myTrack->GetMomentum();
213  double Theta=180.0*Pvec.Theta()/TMath::Pi();
214  double P=Pvec.Mag();
215  effH->Fill(P,Theta);
216  RecoT.erase(RecoT.begin()+trackRC);
217  break;
218  }
219  else{
220  if ((trackRC)==RecoT.size()-1){
221  std::cout<<" FALSE FOUND"<<std::endl;
222  AddGhostTrack(trackF);
223  }
224  }
225 
226  }
227  }
228 }
229 
230 
232 {
234  unsigned int detID, hitID;
235  bool sign=true;
236  for(UInt_t i=0;i<((PndTrackCand*)fTrackCandArray->At(trackF))->GetNHits();i++){
237  detID=((PndTrackCand*)fTrackCandArray->At(trackF))->GetSortedHit(i).GetDetId();
238  hitID=((PndTrackCand*)fTrackCandArray->At(trackF))->GetSortedHit(i).GetHitId();
239  PndSdsHit *point;
240  if ((int)detID == FairRootManager::Instance()->GetBranchId(fHitBranch))
241  point = (PndSdsHit*)fHitArray->At(hitID);
242  else if ((int)detID == FairRootManager::Instance()->GetBranchId(fHitBranch2))
243  point = (PndSdsHit*)fHitArray2->At(hitID);
244  else point = 0;
245  if (point!=0){
247  hit.setXYZ(point->GetX(),point->GetY(),point->GetZ());
248  hit.setDXYZ(point->GetDx(),point->GetDy(),point->GetDz());
249  track.addHit(hit);
250  }
251  if (i==1){
252  if (point->GetZ()>0){
253  sign=true;
254  }
255  else sign=false;
256  }
257  }
258  track.refit();
259  track.szFit();
260  Double_t R=track.r();
261  Double_t Pt=R*(2*3*1E8)/(1E9*100);
262  Double_t dip=track.dip();
263  Double_t Theta;
264  if (sign) Theta=(TMath::ATan(TMath::Power(TMath::Tan(TMath::ACos(dip)),-1)))*180/TMath::Pi();
265  else Theta=(TMath::Pi()-TMath::ATan(TMath::Power(TMath::Tan(TMath::ACos(dip)),-1)))*180/TMath::Pi();
266  Double_t P=Pt/TMath::Cos(Theta);
267  GhH->Fill(P,Theta);
268 
269 }
270 
272 
int getMcTrackId() const
Definition: PndTrackCand.h:60
Int_t i
Definition: run_full.C:25
TVector3 GetPosition() const
Definition: PndSdsHit.h:93
PndRiemannTrack track
Definition: RiemannTest.C:33
PndTrackCandHit GetSortedHit(UInt_t i)
Definition: PndTrackCand.h:54
TVector3 GetMomentum() const
Definition: PndMCTrack.h:78
float Tan(float x)
Definition: PndCAMath.h:165
static T Cos(const T &x)
Definition: PndCAMath.h:43
void setDXYZ(double dx, double dy, double dz)
void ComparingFandR(std::vector< PndTrackCand * > RecoT)
Int_t a
Definition: anaLmdDigi.C:126
void AddHit(UInt_t detId, UInt_t hitId, Double_t rho)
Double_t
void setXYZ(double x, double y, double z)
TClonesArray * point
Definition: anaLmdDigi.C:29
void refit(bool withErrorCalc=true)
double r() const
int hit(Int_t nEvents=0, TString inFile="sim.root", TString parFile="par.root", TString inDigi="digi.root", TString outFile="hit.root", Int_t timeBased=0)
Definition: hit.C:1
GeV c P
bool CheckRecoTrack(PndTrackCand *cand, PndMCTrack *myTrack)
UInt_t GetNHits() const
Definition: PndTrackCand.h:59
void szFit(bool withErrorCalc=true)
void addHit(PndRiemannHit &hit)
int count
int sign(T val)
Definition: PndCADef.h:48
Int_t GetMotherID() const
Definition: PndMCTrack.h:74
Int_t GetHitId() const
Double_t Pi
Double_t R
Definition: checkhelixhit.C:61
Int_t GetDetId() const
ClassImp(PndMvdRiemannTrackFinderTaskEff)