FairRoot/PandaRoot
TtLinFitTask.cxx
Go to the documentation of this file.
1 // Simone Bianco
2 // 15.07.2010
3 
4 // This Class' Header ------------------
5 #include "TtLinFitTask.h"
6 #include "TtFitRes.h"
7 
8 // C/C++ Headers ----------------------
9 #include <iostream>
10 
11 // Collaborating Class Headers --------
12 #include "FairRootManager.h"
13 #include "TClonesArray.h"
14 
15 //#include "PndLinTrack.h"
16 #include "../../../pnddata/TrackData/PndTrackCand.h"
17 #include "../../../pnddata/SdsData/PndSdsHit.h"
18 #include "../../../pnddata/MvdData/PndMvdHit.h"
19 #include "../../../pnddata/TrackData/PndTrackCandHit.h"
20 
21 #include "TFile.h"
22 #include "TGeoTrack.h"
23 #include "TGeoManager.h"
24 #include "TLorentzVector.h"
25 
26 // Fit Classes -----------
27 #include <TMath.h>
28 #include <TVector3.h>
29 #include <TRandom2.h>
30 //#include <TStyle.h>
31 #include <TCanvas.h>
32 #include <TF2.h>
33 #include <TH1.h>
34 #include <TVirtualFitter.h>
35 #include <TPolyLine3D.h>
36 #include <Math/Vector3D.h>
37 #include <TGraphErrors.h>
38 #include <TCanvas.h>
39 
40 #include <fstream>
41 
42 using namespace ROOT::Math;
43 using namespace std;
44 
46  : FairTask("3D-Straight-Line-Fit")
47 {
48  fTCandBranchName = "MVDHitsStrip";
49 }
50 
51 
53 {
54 
55 }
56 
57 InitStatus TtLinFitTask::Init()
58 {
59  //Get ROOT Manager
60  FairRootManager* ioman= FairRootManager::Instance();
61 
62  if(ioman==0)
63  {
64  Error("TtLinFitTask::Init","RootManager not instantiated!");
65  return kERROR;
66  }
67 
68  //Get input collection
69 
70  fTCandArray=(TClonesArray*) ioman->GetObject(fTCandBranchName);
71 
72  if(fTCandArray==0)
73  {
74  Error("TtLinFitTask::Init","trackcand-array not found!");
75  return kERROR;
76  }
77 
78 
79  fTrackArray = new TClonesArray("TtFitRes");
80  ioman->Register("TTFit", "PndMvd", fTrackArray, kTRUE);
81 
82  std::cout << "-I- TtLinFitTask: Initialisation successfull" << std::endl;
83 
84  fEvent = 0;
85 
86  return kSUCCESS;
87 }
88 
89 
90 void TtLinFitTask::Exec(Option_t*)
91 {
92 
93  fTrackcount = 0;
94 
95  // resetting energy losses
96 
97  for (Int_t qq = 0 ; qq < 6 ; qq++)
98  {
99  fEloss[qq]=0;
100  }
101 
102  Int_t ntcand=fTCandArray->GetEntriesFast();
103 
104  if (ntcand == 6)
105  {
106 
107  // std::cout << "Entries: " << ntcand << std::endl;
108 
109 
110  std::map<Double_t,Int_t> SensorsPos;
111 
112  // std::cout<<"TtLinFitTask::Exec"<<std::endl;
113  // Reset output Array
114  if(fTrackArray==0) Fatal("TtLinFitTask::Exec","No TrackArray");
115 
116  Int_t name;
117 
118 
119  for(Int_t itr=0;itr<ntcand;++itr){
120 
121  PndSdsHit *theHit = (PndSdsHit*) fTCandArray->At(itr);
122 
123  name = theHit->GetSensorID();
124 
125  if (SensorsPos.size() < 6) SensorsPos[theHit->GetZ()] = name;
126 
127  }
128 
129  const Int_t sizeMap = SensorsPos.size();
130 
131  Int_t DetNames[sizeMap];
132  Double_t Pos[sizeMap];
133  Int_t jj = 0;
134 
135  if (SensorsPos.size()>=6)
136  {
137  //std::cout << "Number of Sensors:" << SensorsPos.size() << std::endl;
138  for (std::map<Double_t,Int_t>::iterator it=SensorsPos.begin();it!=SensorsPos.end();++it)
139  {
140  // if (fEvent < 5) std::cout << "position: " << it->first << " name: " << (it->second) << std::endl;
141 
142  DetNames[jj] = it->second;
143  Pos[jj] = it -> first;
144  jj++;
145  }
146 
147  }
148 
149 
150 
151 
152  if (fEvent < 5) // just to check
153  {
154 
155  for (Int_t l = 0 ; l < sizeMap ; l++)
156  {
157  //std::cout << DetNames[l] << std::endl;
158  }
159  }
160 
161  if (SensorsPos.size()==6)
162  {
163 
164  Double_t x[6];
165  Double_t y[6];
166  Double_t z[6];
167 
168  Double_t Erx[6];
169  Double_t Ery[6];
170  Double_t Erz[6];
171 
172  Int_t track = 0;
173 
174 
175  Double_t buffErrX = -0.099999;
176  Double_t buffErrY = -0.099999;
177 
178 
179  // std::cout << "Event: " << fEvent << std::endl;
180 
181 
182  Int_t ihit = 0;
183 
184  for (Int_t it1 = 0 ; it1 < ntcand ; it1++)
185  {
186 
187  PndSdsHit *theHit = (PndSdsHit*) fTCandArray->At(it1);
188 
189  if ((theHit->GetSensorID()) == DetNames[0])
190  {
191  x[0] = theHit->GetX();
192  y[0] = theHit->GetY();
193  z[0] = theHit->GetZ();
194  Erx[0] = theHit->GetDx();
195  Ery[0] = theHit->GetDy();
196  Erz[0] = theHit->GetDz();
197  fEloss[0] = theHit->GetEloss();
198  }
199 
200  if ((theHit->GetSensorID()) == DetNames[1])
201  {
202  x[1] = theHit->GetX();
203  y[1] = theHit->GetY();
204  z[1] = theHit->GetZ();
205  Erx[1] = theHit->GetDx();
206  Ery[1] = theHit->GetDy();
207  Erz[1] = theHit->GetDz();
208  fEloss[1] = theHit->GetEloss();
209  }
210  if ((theHit->GetSensorID()) == DetNames[2])
211  {
212  x[2] = theHit->GetX();
213  y[2] = theHit->GetY();
214  z[2] = theHit->GetZ();
215  Erx[2] = theHit->GetDx();
216  Ery[2] = theHit->GetDy();
217  Erz[2] = theHit->GetDz();
218  fEloss[2] = theHit->GetEloss();
219  }
220 
221  if ((theHit->GetSensorID()) == DetNames[3])
222  {
223  x[3] = theHit->GetX();
224  y[3] = theHit->GetY();
225  z[3] = theHit->GetZ();
226  Erx[3] = theHit->GetDx();
227  Ery[3] = theHit->GetDy();
228  Erz[3] = theHit->GetDz();
229  fEloss[3] = theHit->GetEloss();
230  }
231  if ((theHit->GetSensorID()) == DetNames[4])
232  {
233  x[4] = theHit->GetX();
234  y[4] = theHit->GetY();
235  z[4] = theHit->GetZ();
236  Erx[4] = theHit->GetDx();
237  Ery[4] = theHit->GetDy();
238  Erz[4] = theHit->GetDz();
239  fEloss[4] = theHit->GetEloss();
240  }
241 
242  if ((theHit->GetSensorID()) == DetNames[5])
243  {
244  x[5] = theHit->GetX();
245  y[5] = theHit->GetY();
246  z[5] = theHit->GetZ();
247  Erx[5] = theHit->GetDx();
248  Ery[5] = theHit->GetDy();
249  Erz[5] = theHit->GetDz();
250  fEloss[5] = theHit->GetEloss();
251  }
252 
253  ihit++;
254 
255 
256  } // end loop on points
257 
258 
259  Int_t uu = 0;
260 
261 
262  for (Int_t ww = 0 ; ww < 6 ; ww++)
263  { // setting big errors for the bottom side
264  {
265  if (TMath::Abs(Erx[ww]) > 0.5) Erx[ww] = 1000000;
266  if (TMath::Abs(Ery[ww]) > 0.5) Ery[ww] = 1000000;
267  }
268 
269  // std::cout << "(" << x[ww] << "," << y[ww] << "," << z[ww] << ")" << std::endl;
270 
271  }
272 
273 
274  Double_t parFit[4]; //fit-parameter
275 
276  Double_t chiX, chiY;
277 
278  MyFit(x,y,z,Erx,Ery,Erz,parFit, chiX, chiY);
279 
280  Double_t pointX,pointY,pointZ;
281 
282  TtFitRes* trackfit = new TtFitRes(parFit[0], parFit[1], parFit[2], parFit[3], fEloss, chiX, chiY, 6);
283 
284  new((*fTrackArray)[fTrackcount]) TtFitRes(*(trackfit)); //save Track
285  fTrackcount++;
286 
287  }// if 6 hits
288 
289 
290  }
291 
292  fEvent++;
293 
294 
295  return;
296 
297 }
298 
299 
301 {
302 
303  TGraphErrors grX;
304  TGraphErrors grY;
305 
306  Int_t ix=0,iy=0;
307 
308  for (Int_t j = 0 ; j < 6 ; j++)
309  {
310  //std::cout << j << "@(" << Erx[j] << "," << Ery[j] << "," << Erz[j] << ")" << std::endl;
311 
312  if (TMath::Abs(Erx[j])<0.5)
313  {
314  grX.SetPoint(ix,z[j],x[j]);
315  grX.SetPointError(ix,TMath::Abs(Erz[j]),TMath::Abs(Erx[j]));
316  //cout << "erz : " << Erz[j] << " erx : " << Erx[j] << endl;
317  ix++;
318  }
319 
320  if (TMath::Abs(Ery[j])<0.5)
321  {
322  grY.SetPoint(iy,z[j],y[j]);
323  grY.SetPointError(iy,TMath::Abs(Erz[j]),TMath::Abs(Ery[j]));
324  //cout << "erz : " << Erz[j] << " ery : " << Ery[j] << endl;
325  iy++;
326  }
327 
328  }
329 
330  // std::cout << "POINTS " << ix << " " << iy << std::endl;
331 
332 
333  Double_t mx,nx,my,ny;
334 
335  grX.Fit("pol1","");
336 
337  nx = (grX.GetFunction("pol1"))->GetParameter(0);
338  mx = (grX.GetFunction("pol1"))->GetParameter(1);
339 
340 
341  grY.Fit("pol1","");//"Q"
342 
343  ny = (grY.GetFunction("pol1"))->GetParameter(0);
344  my = (grY.GetFunction("pol1"))->GetParameter(1);
345 
346 
347  par[0] = nx;
348  par[1] = mx;
349  par[2] = ny;
350  par[3] = my;
351 
352  chiX = (grX.GetFunction("pol1"))->GetChisquare();
353 
354  chiY = (grY.GetFunction("pol1"))->GetChisquare();
355 
356 }
357 
358 
359 
360 
361 
TString fTCandBranchName
Definition: TtLinFitTask.h:42
PndRiemannTrack track
Definition: RiemannTest.C:33
virtual void Exec(Option_t *opt)
TClonesArray * fTrackArray
Definition: TtLinFitTask.h:45
Double_t par[3]
TClonesArray * fTCandArray
Definition: TtLinFitTask.h:41
cout<< "ifile "<< ifile<< endl;cout<< " momentum sampled over "<< nsteps<< " with step width "<< 1.5/nsteps<< endl;cout<< endl;cout<< "MEAN DEDX PARAMETRIZATION"<< endl;cout<< "mom limits "<< mean_inf<< " "<< mean_sup<< endl;cout<< "mu: ";for(int param=0;param< npardedx;param++) cout<< fdedx-> GetParameter(param)<< "
Double_t GetEloss() const
Definition: PndSdsHit.h:97
static T Abs(const T &x)
Definition: PndCAMath.h:39
void MyFit(Double_t *x, Double_t *y, Double_t *z, Double_t *Erx, Double_t *Ery, Double_t *Erz, Double_t *par, Double_t &chiX, Double_t &chiY)
Int_t fTrackcount
Definition: TtLinFitTask.h:49
Double_t
Double_t z
Double_t fEloss[6]
Definition: TtLinFitTask.h:53
TString name
ClassImp(TtLinFitTask)
Double_t x
Double_t y
virtual InitStatus Init()
Int_t GetSensorID() const
Definition: PndSdsHit.h:90
virtual ~TtLinFitTask()