FairRoot/PandaRoot
Functions
check_trackcand.C File Reference

Go to the source code of this file.

Functions

int check_trackcand (Int_t nEntries=0)
 

Function Documentation

int check_trackcand ( Int_t  nEntries = 0)

Definition at line 1 of file check_trackcand.C.

References Double_t, PndTrackCandHit::GetDetId(), PndTrackCandHit::GetHitId(), PndTrackCand::GetNHits(), PndTrack::GetParamFirst(), PndTrackCandHit::GetRho(), PndTrackCand::GetSortedHit(), PndTrack::GetTrackCandPtr(), hit, inDigiFile, inFile, inRecoFile, inSimFile, mc_array, mom, out, point, PndTrackCand::Print(), rootlogon(), tree, trk, trk_array, TString, x, y, and z.

2 {
3  gROOT->LoadMacro("$VMCWORKDIR/gconfig/rootlogon.C");
4  rootlogon();
5  TString inRecoFile = "reco_sttcombi.root";
6  TString inDigiFile = "digi_sttcombi.root";
7  TString inSimFile = "points_sttcombi.root";
8 
9  TFile *inFile = TFile::Open(inSimFile,"READ");
10  TFile *fiDigiFile = TFile::Open(inDigiFile,"READ");
11  TFile *fiReco1File = TFile::Open(inRecoFile,"READ");
12 
13  TTree *tree=(TTree *) inFile->Get("pndsim") ;
14  tree->AddFriend("pndsim",inRecoFile);
15  tree->AddFriend("pndsim",inDigiFile);
16 
17  TClonesArray* trk_array=new TClonesArray("PndTrack");
18  tree->SetBranchAddress("SttMvdTrack", &trk_array);
19 
20  TClonesArray* mc_array=new TClonesArray("PndMCTrack");
21  tree->SetBranchAddress("MCTrack", &mc_array);
22 
23  TClonesArray *mvdpixarray = new TClonesArray("PndSdsHit");
24  tree->SetBranchAddress("MVDHitsPixel",&mvdpixarray);
25  TClonesArray *mvdstrarray = new TClonesArray("PndSdsHit");
26  tree->SetBranchAddress("MVDHitsStrip",&mvdstrarray);
27  TClonesArray *mvdmcarray = new TClonesArray("PndSdsMCPoint");
28  tree->SetBranchAddress("MVDPoint",&mvdmcarray);
29  TClonesArray *sttarray = new TClonesArray("PndSttHit");
30  tree->SetBranchAddress("STTHit",&sttarray);
31  TClonesArray *sttmcarray = new TClonesArray("PndSttPoint");
32  tree->SetBranchAddress("STTPoint",&sttmcarray);
33  TClonesArray *gemarray = new TClonesArray("PndGemHit");
34  tree->SetBranchAddress("GEMHit",&gemarray);
35  TClonesArray *gemmcarray = new TClonesArray("PndGemMCPoint");
36  tree->SetBranchAddress("GEMPoint",&gemmcarray);
37 
38 
39  TFile *out = TFile::Open("out_test.root","RECREATE");
40  TNtuple *nt = new TNtuple("nt","nt","evt:trk:num:id:hit:x:y:z:mcx:mcy:mcz:rho:p:theta:phi:q");
41 
42  TList *bl = (TList*) fiDigiFile->Get("BranchList");
43  FairRootManager *fairman = new FairRootManager();
44  fairman->SetBranchNameList(bl);
45  int mvdpixdetid = fairman->GetBranchId("MVDHitsPixel");
46  int mvdstrdetid = fairman->GetBranchId("MVDHitsStrip");
47  int sttdetid = fairman->GetBranchId("STTHit");
48  int gemdetid = fairman->GetBranchId("GEMHit");
49  cout << mvdpixdetid << endl;
50  cout << mvdstrdetid << endl;
51  cout << sttdetid << endl;
52  cout << gemdetid << endl;
53 
54  if (nEntries==0) nEntries = tree->GetEntriesFast();
55  for (Int_t j=0; j< nEntries; j++){
56 
57  tree->GetEntry(j);
58  //if (cand_array->GetEntriesFast()==0) continue;
59  //if ((j%100)==0)
60  cout << "processing event " << j << "\n";
61 
62  for(int itrk = 0; itrk < trk_array->GetEntriesFast(); itrk++)
63  {
64  cout << "*** track " << itrk << endl;
65 
66  PndTrack *trk = (PndTrack*) trk_array->At(itrk);
67  if(!trk) {
68  cout << "ERROR track " << itrk << " does not exist" << endl;
69  continue;
70  }
71 
72  PndTrackCand *cand = trk->GetTrackCandPtr();
73  if(!cand)
74  {
75  cout << "ERROR track " << itrk << " has no candidate association" << endl;
76  continue;
77  }
78  FairTrackParP parFirst = trk->GetParamFirst();
79  TVector3 mom = parFirst.GetMomentum();
80  for (Int_t ihit = 0; ihit < cand->GetNHits(); ihit++) {
81  PndTrackCandHit candhit = cand->GetSortedHit(ihit);
82 
83  Int_t hitId = candhit.GetHitId();
84  Int_t detId = candhit.GetDetId();
85  Double_t rho = candhit.GetRho();
86  Float_t x = 0, y= 0, z=0, mcx = 0, mcy= 0, mcz=0;
87  FairHit *hit = NULL;
88  FairMCPoint *point = NULL;
89  if(detId == FairRootManager::Instance()->GetBranchId("MVDHitsPixel"))
90  {
91  hit = (FairHit*) mvdpixarray->At(hitId);
92  if(!hit)
93  {
94  cout << "ERROR mvd pix " << hitId << " does not exist" << endl;
95  }
96  else
97  {
98  if (hit->GetRefIndex()==-1) cout << "ERROR mvd: ref index -1" << endl;
99  else
100  {
101  point = (PndSdsMCPoint*)(mvdmcarray->At(hit->GetRefIndex()));
102  mcx = point->GetX(); mcy = point->GetY(); mcz = point->GetZ();
103  }
104  }
105  }
106  else if(detId == FairRootManager::Instance()->GetBranchId("MVDHitsStrip"))
107  {
108  hit = (FairHit*) mvdstrarray->At(hitId);
109  if(!hit) cout << "ERROR mvd str " << hitId << " does not exist" << endl;
110  else
111  {
112  if (hit->GetRefIndex()==-1) cout << "ERROR mvd: ref index -1" << endl;
113  else
114  {
115  point = (PndSdsMCPoint*)(mvdmcarray->At(hit->GetRefIndex()));
116  mcx = point->GetX(); mcy = point->GetY(); mcz = point->GetZ();
117  }
118  }
119  }
120  else if(detId == FairRootManager::Instance()->GetBranchId("STTHit"))
121  {
122  hit = (FairHit*) sttarray->At(hitId);
123  if(!hit) cout << "ERROR stt " << hitId << " does not exist" << endl;
124  else
125  {
126  if (hit->GetRefIndex()==-1) cout << "ERROR stt: ref index -1" << endl;
127  else
128  {
129  point = (PndSttPoint*)(sttmcarray->At(hit->GetRefIndex()));
130  mcx = point->GetX(); mcy = point->GetY(); mcz = point->GetZ();
131  }
132  }
133  }
134  else if(detId == FairRootManager::Instance()->GetBranchId("GEMHit"))
135  {
136  hit = (FairHit*) gemarray->At(hitId);
137  if(!hit) cout << "ERROR gem " << hitId << " does not exist" << endl;
138  else
139  {
140  if (hit->GetRefIndex()==-1) cout << "ERROR gem: ref index -1" << endl;
141  else
142  {
143  point = (PndGemMCPoint*)(gemmcarray->At(hit->GetRefIndex()));
144  mcx = point->GetX(); mcy = point->GetY(); mcz = point->GetZ();
145  }
146  }
147  }
148  else cout << "ERROR detId unknown " << detId << " for hit " << hitId << endl;
149  if (hit)
150  {
151  x = hit->GetX(); y = hit->GetY(); z = hit->GetZ();
152  }
153  //mcx = point->GetX(); mcy = point->GetY(); mcz = point->GetZ();
154  Float_t ntArray[] = {
155  j, itrk, cand->GetNHits(), detId, ihit,
156  x, y, z, mcx, mcy, mcz, rho,
157  mom.Mag(), mom.Theta()*TMath::RadToDeg(), mom.Phi()*TMath::RadToDeg(), parFirst.GetQ()
158  };
159 
160  nt->Fill(ntArray);
161  }
162  cout << "Momentum @ first point" << endl;
163  mom.Print();
164  cout << "TrackCand:" << endl;
165  cand->Print();
166  }
167 
168 
169 
170  } // end of event loop
171 
172 
173  out->cd();
174 
175  nt->Write();
176 
177  out->Save();
178 
179  return 0;
180 }
void Print() const
TTree * tree
Definition: plot_dirc.C:12
TString inRecoFile
PndTrackCandHit GetSortedHit(UInt_t i)
Definition: PndTrackCand.h:54
TClonesArray * mc_array
Definition: anaLmdCluster.C:25
Double_t mom
Definition: plot_dirc.C:14
TString inFile
Definition: hit_dirc.C:8
TString inSimFile
Double_t
Double_t GetRho() const
Double_t z
TFile * out
Definition: reco_muo.C:20
TString inDigiFile
GFTrack * trk
Definition: checkgenfit.C:13
Double_t x
UInt_t GetNHits() const
Definition: PndTrackCand.h:59
PndSdsMCPoint * hit
Definition: anasim.C:70
Double_t y
PndTrackCand * GetTrackCandPtr()
Definition: PndTrack.h:48
Int_t GetHitId() const
Int_t GetDetId() const
FairTrackParP GetParamFirst()
Definition: PndTrack.h:49
TClonesArray * trk_array
Definition: reco_muo.C:7
PndSdsMCPoint * point
Definition: anaLmdCluster.C:72