FairRoot/PandaRoot
PndMvdRiemannTrackFinderTaskCutPar.cxx
Go to the documentation of this file.
2 
3 #include <iostream>
4 // Root includes
5 #include "TROOT.h"
6 #include "TString.h"
7 #include "TClonesArray.h"
8 #include "TParticlePDG.h"
9 #include "TVector.h"
10 #include "TH2F.h"
11 
12 // framework includes
13 #include "FairRootManager.h"
14 #include "FairRun.h"
15 #include "FairRuntimeDb.h"
16 #include "PndMCTrack.h"
17 
18 
19 // PndMvd includes
20 //#include "TrackCand.h"
21 #include "PndTrackCand.h"
22 #include "PndRiemannTrack.h"
23 #include "PndRiemannHit.h"
24 #include "PndDetectorList.h"
25 
26 
27 PndMvdRiemannTrackFinderTaskCutPar::PndMvdRiemannTrackFinderTaskCutPar() : FairTask("MVD Riemann Track Finder Cuts"),
28  fHitBranch("MVDHitsPixel"),
29  fHitBranch2("MVDHitsStrip"),
30  fMCTrackBranch("MCTrack"),
31  fTrackBranch("MVDIdealTrackCand"),
32  fEventNr(0),
33  fMaxSZChi2(1),
34  fMaxSZDist(10),
35  fMinPointDist(1),
36  fMaxDist(1),
37  fHitArray(NULL),
38  fHitArray2(NULL),
39  fTrackCandArray(NULL),
40  fMCTrackArray(NULL),
41  fRiemannTracks(NULL),
42  fNCut(10),
43  fNbin(100000),
44  frangeDist(2),
45  frangeChi2(1),
46  fPtS(0.1),
47  fPtF(1.0),
48  fThetaS(15),
49  fThetaF(150),
50  fhistsDist(),
51  fhistsChi2(),
52  fCutDistH(NULL),
53  fCutChi2H(NULL)
54 {
56  for(int i=0;i<fNPt;i++){
57  for(int j=0;j<fNTh;j++){
58  TH1F *Hist1 = new TH1F("histDist","h",fNbin,-frangeDist,frangeDist);
59  fhistsDist[i][j]=Hist1;
60  TH1F *Hist2 = new TH1F("histChi2","h",fNbin,0,frangeChi2);
61  fhistsChi2[i][j]=Hist2;
62  }
63  }
64 
65  fCutDistH = new TH2F("CutDist","CutDist",fNPt,fPtS,fPtF,fNTh,fThetaS,fThetaF);
66  fCutChi2H = new TH2F("CutChi2","CutChi2",fNPt,fPtS,fPtF,fNTh,fThetaS,fThetaF);
67 
68  fCutDistH->GetXaxis()->SetTitle("Pt, GeV/c");
69  fCutDistH->GetYaxis()->SetTitle("Theta");
70  fCutChi2H->GetXaxis()->SetTitle("Pt, GeV/c");
71  fCutChi2H->GetYaxis()->SetTitle("Theta");
72 }
73 
75 {
76 }
77 
79 {
80 }
81 
83 {
84 
85  InitStatus stat=kSUCCESS;
86  return stat;
87 }
88 
89 // ----- Public method Init --------------------------------------------
91 {
92 
93  FairRootManager* ioman = FairRootManager::Instance();
94 
95  if ( ! ioman )
96  {
97  std::cout << "-E- PndMvdRiemannTrackFinderTaskCutPar::Init: "
98  << "RootManager not instantiated!" << std::endl;
99  return kFATAL;
100  }
101 
102  // Get input array
103  fHitArray = (TClonesArray*) ioman->GetObject(fHitBranch);
104  if ( !fHitArray){
105  std::cout << "-W- PndMvdRiemannTrackFinderTaskCutPar::Init: " << "No hitArray!" << std::endl;
106  return kERROR;
107  }
108 
109  fHitArray2 = (TClonesArray*) ioman->GetObject(fHitBranch2);
110  if ( !fHitArray2){
111  std::cout << "-W- PndMvdRiemannTrackFinderTaskCutPar::Init: " << "No hitArray2!" << std::endl;
112  return kERROR;
113  }
114 
115  fRiemannTracks = new TClonesArray("PndRiemannTrack");
116 
117  fTrackCandArray = (TClonesArray*) ioman->GetObject(fTrackBranch);
118  if ( !fTrackCandArray){
119  std::cout << "-W- PndMvdRiemannTrackFinderTaskCutPar::Init: " << "No IdealTrackCands!" << std::endl;
120  return kERROR;
121  }
122 
123  fMCTrackArray = (TClonesArray*) ioman->GetObject(fMCTrackBranch);
124  if ( !fMCTrackArray){
125  std::cout << "-W- PndMvdRiemannTrackFinderTaskCutPar::Init: " << "No MCTrack!" << std::endl;
126  return kERROR;
127  }
128 
129  std::cout << "-I- PndMvdRiemannTrackFinderTaskCutPar: Initialisation successfull" << std::endl;
130  return kSUCCESS;
131 }
132 
133 // ----- Public method Exec --------------------------------------------
135 {
136 
137  // Reset output array
138  if ( ! fTrackCandArray )
139  Fatal("Exec", "No trackCandArray");
140 
141  fRiemannTracks->Clear();
143  CalcParHists();
144  std::cout << "Done event no. " << fEventNr++ << std::endl;
145 }
146 
148 {
149  for(int j=0;j<fTrackCandArray->GetEntriesFast();j++){
150  PndRiemannHit hit[20];
152  PndRiemannTrack track0;
153  if (((PndTrackCand*)fTrackCandArray->At(j))->GetNHits()>fNCut){
154  new ((*fRiemannTracks)[j])PndRiemannTrack(track0);
155  continue;
156  }
157  PndMCTrack *myTrack = (PndMCTrack*)fMCTrackArray->At(((PndTrackCand*)fTrackCandArray->At(j))->getMcTrackId());
158  int shift=0;
159  if (myTrack->GetMotherID()==-1){
160  hit[0].setXYZ(0,0,0);
161  hit[0].setDXYZ(0.1,0.1,0.1);
162  shift=1;
163  }
164  int count=shift;
165  int i=0;
166  while ((count<3) && (i<(int)((PndTrackCand*)fTrackCandArray->At(j))->GetNHits())){
167  unsigned int detId,hitId;
168  detId=((PndTrackCand*)fTrackCandArray->At(j))->GetSortedHit(i).GetDetId();
169  hitId=((PndTrackCand*)fTrackCandArray->At(j))->GetSortedHit(i).GetHitId();
170  if ((int)detId==FairRootManager::Instance()->GetBranchId(fHitBranch)){
171  hit[count].setXYZ(((PndSdsHit*)fHitArray->At(hitId))->GetPosition().X(),((PndSdsHit*)fHitArray->At(hitId))->GetPosition().Y(),((PndSdsHit*)fHitArray->At(hitId))->GetPosition().Z());
172  hit[count].setDXYZ(((PndSdsHit*)fHitArray->At(hitId))->GetDx(),((PndSdsHit*)fHitArray->At(hitId))->GetDy(),((PndSdsHit*)fHitArray->At(hitId))->GetDz());
173  i++;
174  count++;
175  }
176  else if ((int)detId==FairRootManager::Instance()->GetBranchId(fHitBranch2)){
177  hit[count].setXYZ(((PndSdsHit*)fHitArray2->At(hitId))->GetPosition().X(),((PndSdsHit*)fHitArray2->At(hitId))->GetPosition().Y(),((PndSdsHit*)fHitArray2->At(hitId))->GetPosition().Z());
178  hit[count].setDXYZ(((PndSdsHit*)fHitArray2->At(hitId))->GetDx(),((PndSdsHit*)fHitArray2->At(hitId))->GetDy(),((PndSdsHit*)fHitArray2->At(hitId))->GetDz());
179  i++;
180  count++;
181  }
182  else {i++;std::cout<<"ERROR"<<std::endl; continue;};
183 
184  if (i>1){
185  if (!CheckTooCloseHits(hit[i-2+shift],hit[i-1+shift]))
186  count--;
187  }
188  }
189  if (count==3){
190  for(int k=0;k<count;k++){
191  track.addHit(hit[k]);
192  }
193  track.refit();
194  track.szFit();
195  new ((*fRiemannTracks)[j])PndRiemannTrack(track);
196  }
197  else {
198  new ((*fRiemannTracks)[j])PndRiemannTrack(track0);
199  }
200  }
201 }
203 {
204  for(int i=0;i<fTrackCandArray->GetEntriesFast();i++){
205  if((((PndRiemannTrack*)fRiemannTracks->At(i))->r()>0) && (((PndTrackCand*)fTrackCandArray->At(i))->GetNHits()<=fNCut)){
206  unsigned int detId,hitId;
207  TVector3 pos;
208  PndMCTrack* myTrack= (PndMCTrack*)fMCTrackArray->At(((PndTrackCand*)fTrackCandArray->At(i))->getMcTrackId());
209  double Pt=myTrack->GetPt();
210  double Theta=(myTrack->GetMomentum().Theta())*180/TMath::Pi();
211  PndRiemannHit hit0;
212  for(unsigned int j=0;j<((PndTrackCand*)fTrackCandArray->At(i))->GetNHits();j++){
213  detId=((PndTrackCand*)fTrackCandArray->At(i))->GetSortedHit(j).GetDetId();
214  hitId=((PndTrackCand*)fTrackCandArray->At(i))->GetSortedHit(j).GetHitId();
215  if ((int)detId==FairRootManager::Instance()->GetBranchId(fHitBranch)){
216  hit0.setXYZ(((PndSdsHit*)fHitArray->At(hitId))->GetPosition().X(),((PndSdsHit*)fHitArray->At(hitId))->GetPosition().Y(),((PndSdsHit*)fHitArray->At(hitId))->GetPosition().Z());
217  hit0.setDXYZ(((PndSdsHit*)fHitArray->At(hitId))->GetDx(),((PndSdsHit*)fHitArray->At(hitId))->GetDy(),((PndSdsHit*)fHitArray->At(hitId))->GetDz());
218  }
219  else if ((int)detId==FairRootManager::Instance()->GetBranchId(fHitBranch2)){
220  hit0.setXYZ(((PndSdsHit*)fHitArray2->At(hitId))->GetPosition().X(),((PndSdsHit*)fHitArray2->At(hitId))->GetPosition().Y(),((PndSdsHit*)fHitArray2->At(hitId))->GetPosition().Z());
221  hit0.setDXYZ(((PndSdsHit*)fHitArray2->At(hitId))->GetDx(),((PndSdsHit*)fHitArray2->At(hitId))->GetDy(),((PndSdsHit*)fHitArray2->At(hitId))->GetDz());
222  }
223  else {std::cout<<"ERROR"<<std::endl; continue;};
224  }
225  if((Pt>=fPtS) && (Pt<=fPtF) && (Theta>=fThetaS) && (Theta<=fThetaF)){
226  fhistsDist[TMath::FloorNint(((Pt-fPtS)*fNPt/(fPtF-fPtS)))][TMath::FloorNint(((Theta-fThetaS)*fNTh/(fThetaF-fThetaS)))]->Fill(((PndRiemannTrack*)fRiemannTracks->At(i))->dist(&hit0));
227  fhistsChi2[TMath::FloorNint(((Pt-fPtS)*fNPt/(fPtF-fPtS)))][TMath::FloorNint(((Theta-fThetaS)*fNTh/(fThetaF-fThetaS)))]->Fill(((PndRiemannTrack*)fRiemannTracks->At(i))->calcSZChi2(&hit0));
228  }
229  }
230  }
231 }
233 {
234  // int count=0;
235  TVector3 delta;
236  delta=hit1.x()-hit2.x();
237  if (delta.Mag()<fMinPointDist){
238  return false;
239  }
240  else return true;
241 }
242 
244 {
245  for(int i=0;i<fNPt;i++){
246  for(int j=0;j<fNTh;j++){
247  double Th1=0.95;
248  double CutDist=0;
249  double CutChi2=0;
250  double S01=fhistsDist[i][j]->Integral();
251  double S1=0;
252  if(S01>0){
253  S1+=fhistsDist[i][j]->GetBinContent(fNbin/2);
254  for(int k=1;k<(fNbin/2);k++){
255  S1+=fhistsDist[i][j]->GetBinContent(fNbin/2-k)+fhistsDist[i][j]->GetBinContent(fNbin/2+k);
256  if ((S1/S01)>=Th1){
257  CutDist=((double)k*frangeDist)/((double)fNbin/2.0);
258  break;
259  }
260  }
261  }
262 
263  double Th2=Th1;
264  double S02=fhistsChi2[i][j]->Integral();
265  double S2=0;
266  if(S02>0){
267  for(int k=0;k<fNbin;k++){
268  S2+=fhistsChi2[i][j]->GetBinContent(k);
269  if ((S2/S02)>=Th2){
270  CutChi2=((double)k*frangeChi2)/((double)fNbin);
271  break;
272  }
273  }
274  }
275  fCutDistH->SetBinContent(i+1,j+1,CutDist);
276  fCutChi2H->SetBinContent(i+1,j+1,CutChi2);
277  }
278  }
279  TFile fout("MVDCutHists.root","recreate");
280  fCutDistH->Write();
281  fCutChi2H->Write();
282  fout.Close();
283 }
285 {
286  fRiemannTracks->Clear();
287 }
288 
290 
int fNbin
number of bins in the cut hists during calculation of the cut parameters
TVector3 pos
double r
Definition: RiemannTest.C:14
Int_t i
Definition: run_full.C:25
unsigned int fNCut
cut max number of hits in IdealTrack
TVector3 GetMomentum() const
Definition: PndMCTrack.h:78
void setDXYZ(double dx, double dy, double dz)
bool CheckTooCloseHits(PndRiemannHit hit1, PndRiemannHit hit2)
static const int fNTh
number of Theta bins
Double_t GetPt() const
Definition: PndMCTrack.h:79
void setXYZ(double x, double y, double z)
PndMCTrack * track
Definition: anaLmdCluster.C:89
void refit(bool withErrorCalc=true)
const TVector3 & x() const
Definition: PndRiemannHit.h:71
ClassImp(PndAnaContFact)
void szFit(bool withErrorCalc=true)
void addHit(PndRiemannHit &hit)
int count
PndSdsMCPoint * hit
Definition: anasim.C:70
Int_t GetMotherID() const
Definition: PndMCTrack.h:74
cout<<"the mcX, mcY, mcZ are "<< mcX<<","<< mcY<<","<< mcZ<< endl;vecmc.SetXYZ(mcX, mcY, mcZ);vecrc=hit-> GetPosition()
Double_t Pi