BmnRoot
Loading...
Searching...
No Matches
CbmStsFitPerformanceTask.cxx
Go to the documentation of this file.
1// -------------------------------------------------------------------------
2// ----- CbmStsFitPerformanceTask source file -----
3// ----- Created 02/02/05 by E. Kryshen -----
4// -------------------------------------------------------------------------
5
7
9#include "CbmPVFinderKF.h"
11#include "CbmKF.h"
12#include "CbmKFMath.h"
13#include "CbmKFTrack.h"
14#include "CbmKFVertex.h"
15#include "CbmKFPrimaryVertexFinder.h"
16#include "CbmKFPrimaryVertexFinder.h"
17#include "CbmKF.h"
18#include "CbmKFTrackInterface.h"
19#include "CbmKFVertexInterface.h"
20#include "CbmKFTrack.h"
21#include "CbmKFVertex.h"
22
23#include "CbmMCTrack.h"
24#include "CbmTrackMatch.h"
25#include "CbmStsHit.h"
26#include "FairRootManager.h"
27#include "FairMCApplication.h"
28#include "CbmStsTrack.h"
29#include "CbmVertex.h"
30#include "CbmMvdHit.h"
31
32#include "TVector3.h"
33#include "TF1.h"
34#include "TParticlePDG.h"
35#include "TDatabasePDG.h"
36
37
38#include <iostream>
39#include <iomanip>
40#include <cmath>
41
42using std::cout;
43using std::endl;
44using std::vector;
45using std::fabs;
46
47// -------------------------------------------------------------------------
48
49void writedir2current( TObject *obj ){
50 if( !obj->IsFolder() ) obj->Write();
51 else{
52 TDirectory *cur = gDirectory;
53 TDirectory *sub = cur->mkdir(obj->GetName());
54 sub->cd();
55 TList *listSub = ((TDirectory*)obj)->GetList();
56 TIter it(listSub);
57 while( TObject *obj1=it() ) writedir2current(obj1);
58 cur->cd();
59 }
60}
61
62void CbmStsFitPerformanceTask::CreateTrackHisto(TH1D* hist[10], const char* name, const char* title ){
63 struct {
64 const char *name;
65 const char *title;
66 Int_t n;
67 Double_t l,r;
68 } Table[10]=
69 {
70 {"x", "Residual X [#mum]", 100, -100., 100.},
71 {"y", "Residual Y [#mum]", 100, -100., 100.},
72 {"tx", "Residual Tx [mrad]", 100, -2., 2.},
73 {"ty", "Residual Ty [mrad]", 100, -2., 2.},
74 {"P", "Resolution P/Q [100%]", 100, -.1, .1 },
75 {"px", "Pull X [residual/estimated_error]", 100, -10., 10.},
76 {"py", "Pull Y [residual/estimated_error]", 100, -10., 10.},
77 {"ptx","Pull Tx [residual/estimated_error]", 100, -10., 10.},
78 {"pty","Pull Ty [residual/estimated_error]", 100, -10., 10.},
79 {"pQP","Pull Q/P [residual/estimated_error]", 100, -10., 10.}
80 };
81
82 for( int i=0; i<10; i++ ){
83 char n[225], t[255];
84 sprintf(n,"%s_%s",name,Table[i].name);
85 sprintf(t,"%s %s",title,Table[i].title);
86 hist[i] = new TH1D(n,t, Table[i].n, Table[i].l, Table[i].r);
87 }
88}
89
90void CbmStsFitPerformanceTask::CreateVertexHisto(TH1D* hist[9], const char* name, const char* title ){
91 struct {
92 const char *name;
93 const char *title;
94 Int_t n;
95 Double_t l,r;
96 } Table[9]=
97 {
98 {"x", "Residual X [#mum]", 100, -5., 5.},
99 {"y", "Residual Y [#mum]", 100, -5., 5.},
100 {"z", "Residual Z [#mum]", 100, -40., 40.},
101 {"px", "Pull X [residual/estimated_error]", 100, -10., 10.},
102 {"py", "Pull Y [residual/estimated_error]", 100, -10., 10.},
103 {"pz", "Pull Z [residual/estimated_error]", 100, -10., 10.},
104 {"chi2","Chi2/NDF", 100, 0., 10.},
105 {"prob","Prob(Chi2,NDF)", 100, 0., 1.},
106 {"ntracks","N tracks", 100, 0., 1000.},
107 };
108
109 for( int i=0; i<9; i++ ){
110 char n[225], t[255];
111 sprintf(n,"%s_%s",name,Table[i].name);
112 sprintf(t,"%s %s",title,Table[i].title);
113 hist[i] = new TH1D(n,t, Table[i].n, Table[i].l, Table[i].r);
114 }
115}
116
117void CbmStsFitPerformanceTask::CreateD0Histo(TH1D* hist[15], const char* name, const char* title ){
118 struct {
119 const char *name;
120 const char *title;
121 Int_t n;
122 Double_t l,r;
123 } Table[14]=
124 {
125 {"x", "Residual X [#mum]", 100, -100., 100.},
126 {"y", "Residual Y [#mum]", 100, -100., 100.},
127 {"z", "Residual Z [#mum]", 100, -500., 500.},
128 {"px", "Pull X [residual/estimated_error]", 100, -10., 10.},
129 {"py", "Pull Y [residual/estimated_error]", 100, -10., 10.},
130 {"pz", "Pull Z [residual/estimated_error]", 100, -10., 10.},
131 {"chi2","Chi2/NDF", 100, 0., 10.},
132 {"prob","Prob(Chi2,NDF)", 100, 0., 1.},
133 {"mass","Residual Mass", 100, -.1, .1},
134 {"pmass", "Pull Mass [residual/estimated_error]", 100, -10., 10.},
135 {"KaonP", "Kaon P resolution", 100, -.05, .05},
136 {"PionP", "Pion P resolution", 100, -.05, .05},
137 {"KaonP0", "Kaon P resolution before fit", 100, -.05, .05},
138 {"PionP0", "Pion P resolutionbefore fit", 100, -.05, .05}
139 };
140
141 for( int i=0; i<14; i++ ){
142 char n[225], t[255];
143 sprintf(n,"%s_%s",name,Table[i].name);
144 sprintf(t,"%s %s",title,Table[i].title);
145 hist[i] = new TH1D(n,t, Table[i].n, Table[i].l, Table[i].r);
146 }
147}
148
149
150// ----- Standard constructor ------------------------------------------
152 :FairTask(name,iVerbose),
153 fEvent(0),
154 fVertexAnalysis(0), fD0Analysis(0), fTrackAnalysis(1),
155
156 fMCTrackArray(0),
157 fStsPointArray(0),
158 fMvdPointArray(0),
159 fRecStsTrackArray(0),
160 fStsHitArray(0),
161 fMvdHitArray(0),
162 fPrimaryVertex(0),
163 fSTSTrackMatch(0),
164
165 fhChi2(0), // x=chi2(), y=entries for all
166 fhProb(0), // x=Prob function(), y=entries for all
167 fhDP(0),
168 fhDP2(0),
169 fhDsP(0),
170 fhDsP2(0),
171
172 fhZMCf(0), fhZMCl(0), // z first/last of MC track
173 fhZRecof(0), fhZRecol(0), // z first/last of Reco track
174
175 fhRes_vs_Mom_f(0), fhRes_vs_Mom_l(0), // resolution vs momentum
176 fhExtraTracks2ndMVD(0), // extra tracks not detected in the second mvd chamber
177
178 // TH1D* fhFrst[10](),
179 // TH1D* fhMid[10](),
180 // TH1D* fhLast[10](),
181 // TH1D* fhImp[10](),
182 // TH1D* fhImpPi[10](),
183 // TH1D* fhVfit[10](),
184 // TH1D* fhVtx[9](),
185 // TH1D* fhV[13][9](),
186 fhPq(),
187 // fhD0[4][14](),
188
189 // fhHitDensity[10](),
190 // fhTrackDensity[8](),
191 fhTrackDensity0L(0),
192
193 histodir(0),
194 fFitter()
195{
196}
197// -------------------------------------------------------------------------
198
199
200
201// ----- Destructor ----------------------------------------------------
204
205// ----- Init CbmStsFitPerformanceTask task -------------------------------
207 fEvent = 0;
208
209 TDirectory *curdir = gDirectory;
210 histodir = gDirectory->mkdir("StsFitPerformance");
211 histodir->cd();
212
213 gDirectory->mkdir("TrackFit");
214 gDirectory->cd("TrackFit");
215 {
216 fhChi2 = new TH1D("hChi2","hChi2",100,0,10);
217 fhProb = new TH1D("hProb","hProb",100,0,1.0);
218
219 fhDP = new TH1D("hDP","hDP",1000,-.005,.005);
220 fhDP2 = new TH2D("hDP2","hDP2",100,0.,5.0,1000,-.005,.005);
221
222 fhDsP = new TH1D("hDsP","hDsP",100,-1,1);
223 fhDsP2 = new TH2D("hDsP2","hDsP2",100,0.,5.0,100,-1,1);
224
225 fhZMCf = new TH1D("hZMCf","h Z MC first",102,-1.0,101.0);
226 fhZRecof = new TH1D("hZRecof","h Z Reco first",102,-1.0,101.0);
227 fhZMCl = new TH1D("hZMCl","h Z MC last",102,-1.0,101.0);
228 fhZRecol = new TH1D("hZRecol","h Z Reco last",102,-1.0,101.0);
229
230 fhRes_vs_Mom_f = new TH2D("hRes_vs_Mom_f","TX Resolusion vs Momentum (first hit)",100, 0.0, 5.0, 100, -50.0, 50.0);
231 fhRes_vs_Mom_l = new TH2D("hRes_vs_Mom_l","TX Resolusion vs Momentum (last hit)",100, 0.0, 5.0, 100, -10.0, 10.0);
232
233 fhExtraTracks2ndMVD = new TH2D("hExtraTracks2ndMVD","ExtraTracks in the 2nd MVD",200, -10.0, 10.0, 200, -10.0, 10.0);
234
235 gDirectory->mkdir("AtFirstHit");
236 gDirectory->cd("AtFirstHit");
237 CreateTrackHisto( fhFrst, "fst", "at first STS Hit" );
238 gDirectory->cd("..");
239 gDirectory->mkdir("AtLastHit");
240 gDirectory->cd("AtLastHit");
241 CreateTrackHisto( fhLast, "lst", "at last STS Hit" );
242 gDirectory->cd("..");
243 gDirectory->mkdir("AtImpactPoint");
244 gDirectory->cd("AtImpactPoint");
245 CreateTrackHisto( fhImp, "imp", "at impact point" );
246 gDirectory->cd("..");
247 gDirectory->mkdir("AtImpactPointPion");
248 gDirectory->cd("AtImpactPointPion");
249 CreateTrackHisto( fhImpPi, "impPi", "at impact point" );
250 gDirectory->cd("..");
251 gDirectory->mkdir("InTheMiddle");
252 gDirectory->cd("InTheMiddle");
253 CreateTrackHisto( fhMid, "mid", "at 4th station" );
254 gDirectory->cd("..");
255 gDirectory->mkdir("FittedToVertex");
256 gDirectory->cd("FittedToVertex");
257 CreateTrackHisto( fhVfit, "vfit", "for vertex fitted track" );
258 gDirectory->cd("..");
259
260 gDirectory->mkdir("PSlidesOnP");
261 gDirectory->cd("PSlidesOnP");
262 fhPq = new TH2D("Pq","Resolution P/Q at impact point vs P", 100, 0, 10, 100, -.1 , .1 );
263 gDirectory->cd("..");
264 }
265 gDirectory->cd("..");
266
267 for( int i=0; i<10; i++ ){
268 char n[225], t[255];
269 sprintf(n,"hHitDens%i",i);
270 sprintf(t,"Hit Density, Sts station %i",i);
271 fhHitDensity[i] = new TH1D(n,t,300,0,300);
272 }
273 fhTrackDensity[0] = new TH1D("hTrackDensity0","Track Density 0cm",300,0,300);
274 fhTrackDensity0L = new TH1D("hTrackDensity0L","Track Density Line 0cm",300,0,300);
275 fhTrackDensity[1] = new TH1D("hTrackDensity1","Track Density 1cm",300,0,300);
276 fhTrackDensity[2] = new TH1D("hTrackDensity2","Track Density 2cm",300,0,300);
277 fhTrackDensity[3] = new TH1D("hTrackDensity3","Track Density 3cm",300,0,300);
278 fhTrackDensity[4] = new TH1D("hTrackDensity4","Track Density 4cm",300,0,300);
279 fhTrackDensity[5] = new TH1D("hTrackDensity5","Track Density 5cm",300,0,300);
280 fhTrackDensity[6] = new TH1D("hTrackDensity10","Track Density 10cm",300,0,300);
281 fhTrackDensity[7] = new TH1D("hTrackDensity100","Track Density 1m",300,0,300);
282
283 gDirectory->mkdir("VertexFit");
284 gDirectory->cd("VertexFit");
285 {
286 CreateVertexHisto( fhVtx, "vtx", "for Primary Vertex" );
287 gDirectory->mkdir("VertexOnNTracks");
288 gDirectory->cd("VertexOnNTracks");
289 for( int i=0; i<13; i++){
290 char name[225], namedir[225], title[225];
291 if( i==0 ){
292 sprintf(namedir,"AllTracks");
293 sprintf(name,"Vall");
294 sprintf(title,"for Primary Vertex on all tracks");
295 }else{
296 sprintf(namedir,"%iTracks",i*50);
297 sprintf(name,"V%i",i*50);
298 sprintf(title,"for Primary Vertex on %i tracks",i*50);
299 }
300 gDirectory->mkdir(namedir);
301 gDirectory->cd(namedir);
302 CreateVertexHisto( fhV[i], name, title );
303 gDirectory->cd("..");
304 }
305 gDirectory->cd("..");
306 }
307 gDirectory->cd("..");
308
309 gDirectory->mkdir("D0Fit");
310 gDirectory->cd("D0Fit");
311 {
312 gDirectory->mkdir("No constraints");
313 gDirectory->cd("No constraints");
314 CreateD0Histo( fhD0[0], "D0", "for D0 Sec. Vertex" );
315 gDirectory->cd("..");
316 gDirectory->mkdir("Topological constraint");
317 gDirectory->cd("Topological constraint");
318 CreateD0Histo( fhD0[1], "D0T", "for D0 Topo Sec. Vertex" );
319 gDirectory->cd("..");
320 gDirectory->mkdir("Mass constraint");
321 gDirectory->cd("Mass constraint");
322 CreateD0Histo( fhD0[2], "D0M", "for D0 Mass Sec. Vertex" );
323 gDirectory->cd("..");
324 gDirectory->mkdir("Mass+Topological constraint");
325 gDirectory->cd("Mass+Topological constraint");
326 CreateD0Histo( fhD0[3], "D0TM", "for D0 Topo+Mass Sec. Vertex" );
327 gDirectory->cd("..");
328 }
329 gDirectory->cd("..");
330
331 curdir->cd();
332 return ReInit();
333}
334
335// ----- ReInit CbmStsFitPerformanceTask task -------------------------------
337
338 FairRootManager* fManger =FairRootManager::Instance();
339 fMCTrackArray = reinterpret_cast<TClonesArray*>(fManger->GetObject("MCTrack"));
340 fStsPointArray = reinterpret_cast<TClonesArray*>(fManger->GetObject("StsPoint"));
341 fMvdPointArray = reinterpret_cast<TClonesArray*>(fManger->GetObject("MvdPoint"));
342 fRecStsTrackArray = reinterpret_cast<TClonesArray*>(fManger->GetObject("StsTrack"));
343 fStsHitArray = reinterpret_cast<TClonesArray*>(fManger->GetObject("StsHit"));
344 fMvdHitArray = reinterpret_cast<TClonesArray*>(fManger->GetObject("MvdHit"));
345 fPrimaryVertex = reinterpret_cast<CbmVertex*>(fManger->GetObject("PrimaryVertex"));
346 fSTSTrackMatch = reinterpret_cast<TClonesArray*>(fManger->GetObject("StsTrackMatch"));
347 fFitter.Init();
348
349 return kSUCCESS;
350}
351// -------------------------------------------------------------------------
352
353
354
355// ----- Exec CbmStsFitPerformanceTask task -------------------------------
356void CbmStsFitPerformanceTask::Exec(Option_t * option){
357 cout << "Event: " << ++fEvent << " ";
358
359 Int_t nTracks=fRecStsTrackArray->GetEntriesFast();
360 cout << " nTracks: " << nTracks << endl;
361
362 if( !fSTSTrackMatch ) return;
363
364 Double_t mc[6];
365
366 Int_t Quality[nTracks];
367
368 for (Int_t iTrack=0; iTrack<nTracks; iTrack++ ){
369 Quality[iTrack]=0;
370 CbmStsTrack* track= (CbmStsTrack*) fRecStsTrackArray->At(iTrack);
371 if( !track ) continue;
373 if( !m ) continue;
374 if( m->GetNofTrueHits() <
375 0.7*(m->GetNofTrueHits()+m->GetNofWrongHits()+m->GetNofFakeHits())
376 ) continue;
377 Int_t mcTrackID = m->GetMCTrackId();
378 if (mcTrackID<0) continue;
379 if (!IsLong(track)) continue;
380
381 CbmMCTrack* mcTrack= (CbmMCTrack*) fMCTrackArray->At(mcTrackID);
382 if( !mcTrack ) continue;
383 if (fabs((mcTrack->GetStartZ()))>1.) continue;
384
385 if( mcTrack->GetMotherId() !=-1 ) continue;
386 Quality[iTrack]=1;
387 }
388
389 if(0){
390// CbmKF &KF = *CbmKF::Instance();
391 int nStsHits = fStsHitArray->GetEntries();
392 int nMvdHits = fMvdHitArray->GetEntries();
393 cout<<"Mvd hit density..."<<endl;
394 for( int ih=0; ih<nMvdHits; ih++){
395 if( ih%100 ==0 ) cout<<ih<<endl;
396 CbmMvdHit* h1 = (CbmMvdHit*) fMvdHitArray->At(ih);
397 if( !h1 ) continue;
398 double V[3] = { 2*h1->GetDx()*h1->GetDx(), 2*0, 2*h1->GetDy()*h1->GetDy()};
399 Double_t v = 1./(V[0]*V[2] - V[1]*V[1]) ;
400 V[0]*=v;
401 V[1]*=v;
402 V[2]*=v;
403 double D2 = 1.e10;
404 for( int jh=0; jh<nMvdHits; jh++){
405 if( ih==jh ) continue;
406 CbmMvdHit* h2 = (CbmMvdHit*) fMvdHitArray->At(jh);
407 if( !h2 ) continue;
408 if( h1->GetStationNr() != h2->GetStationNr() ) continue;
409 Double_t dx = h1->GetX() - h2->GetX();
410 Double_t dy = h1->GetY() - h2->GetY();
411 Double_t d2 = fabs(dx*dx*V[0]-2*dx*dy*V[1]+dy*dy*V[2]);
412 if( d2<D2 ) D2 = d2;
413 }
414 fhHitDensity[h1->GetStationNr()-1]->Fill(sqrt(D2/2.));
415 }
416 cout<<"Sts hit density..."<<endl;
417 for( int ih=0; ih<nStsHits; ih++){
418 if( ih%1000 ==0 ) cout<<ih<<endl;
419 CbmStsHit* h1 = (CbmStsHit*) fStsHitArray->At(ih);
420 if( !h1 ) continue;
421 double V[3] = { 2*h1->GetDx()*h1->GetDx(), 2*h1->GetCovXY(), 2*h1->GetDy()*h1->GetDy()};
422 Double_t v = 1./(V[0]*V[2] - V[1]*V[1]) ;
423 V[0]*=v;
424 V[1]*=v;
425 V[2]*=v;
426 double D2 = 1.e10;
427 for( int jh=0; jh<nStsHits; jh++){
428 if( ih==jh ) continue;
429 CbmStsHit* h2 = (CbmStsHit*) fStsHitArray->At(jh);
430 if( !h2 ) continue;
431 if( h1->GetStationNr() != h2->GetStationNr() ) continue;
432 if( h1->GetDigi(1)>=0 ){
433 if( h1->GetDigi(0)!=h2->GetDigi(0) &&
434 h1->GetDigi(1)!=h2->GetDigi(1) ) continue;
435 }
436 Double_t dx = h1->GetX() - h2->GetX();
437 Double_t dy = h1->GetY() - h2->GetY();
438 Double_t d2 = fabs(dx*dx*V[0]-2*dx*dy*V[1]+dy*dy*V[2]);
439 if( d2<D2 ) D2 = d2;
440 }
441 fhHitDensity[CbmKF::Instance()->MvdStationIDMap.size()+h1->GetStationNr()-1]->Fill(sqrt(D2/2));
442 }
443 }
444
445 if(0){ // track density
446 cout<<"Track density..."<<endl;
447 bool flag[nTracks];
448 double sC[nTracks][8][15];
449 double sT[nTracks][8][5];
450 for (Int_t iTrack=0;iTrack<nTracks;iTrack++){
451 flag[iTrack] = 0;
452
453 CbmStsTrack* trackI= (CbmStsTrack*) fRecStsTrackArray->At(iTrack);
454 if( !IsLong(trackI) ) continue;
455 flag[iTrack] = 1;
456 double z[8] = {0.2,1,2,3,4,5,10,100};
457 for( int iz=0; iz<8; iz++ ){
458 FairTrackParam paramI;
459 fFitter.Extrapolate(trackI, z[iz], &paramI);
460 CbmKFMath::CopyTrackParam2TC( &paramI, sT[iTrack][iz], sC[iTrack][iz] );
461 if( !finite(sC[iTrack][iz][0]) || sC[iTrack][iz][0]<0 || sC[iTrack][iz][0]>10. ){
462 flag[iTrack] = 0;
463 break;
464 }
465 }
466 }
467 for (Int_t iTrack=0;iTrack<nTracks;iTrack++){
468
469 if( iTrack%10==0 ) cout<<iTrack<<endl;
470 if (!flag[iTrack]) continue;
471 double Chi2[8];
472 for( int iz=0; iz<8; iz++ ) Chi2[iz] = 1.e10;
473 double Chi2L=1.e10;
474
475 for (Int_t jTrack=0;jTrack<nTracks;jTrack++){
476 if( jTrack==iTrack ) continue;
477 if (!flag[jTrack]) continue;
478
479 for( int iz=0; iz<8; iz++ ){
480 Double_t C[15], d[5];
481 for( int i=0; i<15; i++ ) C[i] = sC[iTrack][iz][i] + sC[jTrack][iz][i];
482 for( int i=0; i<5; i++ ) d[i] = sT[iTrack][iz][i] - sT[jTrack][iz][i];
483 CbmKFMath::invS(C,5);
484
485 double chi2=0;
486 for( int i=0; i<5; i++ ){
487 double dCi=0;
488 for( int j=0; j<5; j++ ) dCi+=d[j]*C[CbmKFMath::indexS(i,j)];
489 chi2+=dCi*d[i];
490 }
491 chi2 = fabs(chi2);
492 if( chi2<Chi2[iz] ) Chi2[iz] = chi2;
493
494 if( iz==0 ){
495 chi2=0;
496 for( int i=0; i<4; i++ ){
497 double dCi=0;
498 for( int j=0; j<4; j++ ) dCi+=d[j]*C[CbmKFMath::indexS(i,j)];
499 chi2+=dCi*d[i];
500 }
501 chi2 = fabs(chi2);
502 if( chi2<Chi2L ) Chi2L = chi2;
503 }
504 }
505 }
506 for( int iz=0; iz<8; iz++ ){
507 fhTrackDensity[iz]->Fill(sqrt(Chi2[iz]/5));
508 }
509 fhTrackDensity0L->Fill(sqrt(Chi2L/4));
510 }
511 }
512 if( fTrackAnalysis ){
513 for (Int_t iTrack=0;iTrack<nTracks;iTrack++){
514 if( Quality[iTrack]<1 ) continue;
515 CbmStsTrack* track= (CbmStsTrack*) fRecStsTrackArray->At(iTrack);
517 CbmMCTrack* mcTrack= (CbmMCTrack*) fMCTrackArray->At(m->GetMCTrackId());
518
519 if( mcTrack->GetMotherId() !=-1 ) continue; // not primary track //IK
520
521 // Get MC points;
522 vector<CbmStsPoint*> vPoints;
523 for( Int_t i=0; i<track->GetNStsHits(); i++ ){
524 Int_t hitID = track->GetStsHitIndex(i);
525 if( hitID<0 ) continue;
526 CbmStsHit* hit = (CbmStsHit*) fStsHitArray->At(hitID);
527 if( !hit ) continue;
528 Int_t pointID = hit->GetRefIndex();
529 if( pointID<0 ) continue;
530 CbmStsPoint *point = (CbmStsPoint*) fStsPointArray->At(pointID);
531 if( !point ) continue;
532 vPoints.push_back(point);
533 }
534 vector<CbmMvdPoint*> vMPoints;
535 for( Int_t i=0; i<track->GetNMvdHits(); i++ ){
536 Int_t hitID = track->GetMvdHitIndex(i);
537 if( hitID<0 ) continue;
538 CbmMvdHit* hit = (CbmMvdHit*) fMvdHitArray->At(hitID);
539 if( !hit ) continue;
540 Int_t pointID = hit->GetRefIndex();
541 if( pointID<0 ) continue;
542 CbmMvdPoint *point = (CbmMvdPoint*) fMvdPointArray->At(pointID);
543 if( !point ) continue;
544 vMPoints.push_back(point);
545 }
546 // impact mc track
547 Double_t mci[6];
548 Double_t pzi = mcTrack->GetPz();
549 if( fabs( pzi )>1.e-4 ) pzi = 1./pzi;
550 mci[0] = mcTrack->GetStartX();
551 mci[1] = mcTrack->GetStartY();
552 mci[2] = mcTrack->GetPx() * pzi;
553 mci[3] = mcTrack->GetPy() * pzi;
554 mci[4] = (fabs(mcTrack->GetP())>1.e-4 ) ? GetCharge(mcTrack) / mcTrack->GetP() :0;
555 mci[5] = mcTrack->GetStartZ();
556 if( !vPoints.empty() )
557 {
558 if( track->GetNStsHits()+track->GetNMvdHits()>=8 ){
559 Double_t p1 = mcTrack->GetP();
560 TVector3 mom;
561 vPoints.back()->MomentumOut(mom);
562 Double_t p2 = mom.Mag();
563 Double_t s = p1*p1*TMath::Sqrt(TMath::Abs(track->GetParamFirst()->GetCovariance(4,4)));
564 Double_t dp = (p1-p2)*TMath::Sqrt(1+mci[2]*mci[2]+mci[3]*mci[3]);
565 fhDP->Fill(dp);
566 fhDP2->Fill(p1,dp );
567 fhDsP->Fill( dp/s );
568 fhDsP2->Fill(p1, dp/s );
569 }
570 // first point
571 if( !vMPoints.empty() )
572 FillMCStateVectors(vMPoints.front(),mc);
573 else FillMCStateVectors(vPoints.front(),mc);
574 FillTrackHisto( mc, track, fhFrst );
575 fhZMCf->Fill(mc[5]);
576 fhZRecof->Fill(track->GetParamFirst()->GetZ());
577
578 // last point
579 FillMCStateVectors(vPoints.back(),mc,1);
580 FillTrackHisto( mc, track, fhLast );
581 fhZMCl->Fill(mc[5]);
582 fhZRecol->Fill(track->GetParamLast()->GetZ());
583
584 // impact point
585
586 if(TMath::Abs(mcTrack->GetPdgCode())==211) FillTrackHisto(mci,track,fhImpPi);
587 else
588 FillTrackHisto(mci,track,fhImp);
589
590 // 4th station (check smoother)
591
592 for( vector<CbmStsPoint*>::iterator i=vPoints.begin(); i!=vPoints.end(); i++){
593 int id = (*i)->GetDetectorID();
594 CbmKF &KF = *CbmKF::Instance();
595 if( KF.StsStationIDMap.find(id) == KF.StsStationIDMap.end() ) continue;
596 if( KF.StsStationIDMap[id] != 3 ) continue;
597 FillMCStateVectors(*i,mc,1);
598 //FillTrackHisto( mc, track, fhMid );
599 break;
600 }
601 }
602
603 if( fPrimaryVertex && mcTrack->GetMotherId() ==-1 ){
604
605 // fit track to Primary Vertex
606
607 CbmStsTrack tt(*track);
609 //FillTrackHisto(mci,&tt,fhVfit);
610
611 // fill momentum resolution
612
613 double z = mci[5];
614 FairTrackParam param;
615 fFitter.Extrapolate(track, z, &param);
616 if( fabs(mci[4])>1.e-4 && fabs( param.GetQp() )>1.e-4 )
617 fhPq->Fill( fabs(1./mci[4]), (mci[4]/param.GetQp() - 1.) );
618 }
619
620 if( track->GetNDF()>0 ){
621 fhChi2->Fill(track->GetChi2()/track->GetNDF());
622 fhProb->Fill(TMath::Prob(track->GetChi2(),track->GetNDF()));
623 }
624 }
625 }
626
627 if( fPrimaryVertex ){
628
629 // find MC Primary vertex
630
631 TVector3 MC_V(0,0,0);
632 Bool_t Is_MC_V = 0;
633 {
634 TVector3 MC_Vcurr(0,0,0);
635 Int_t nvtracks=0, nvtrackscurr=0;
636 Int_t nMCTracks = fMCTrackArray->GetEntriesFast();
637 for (Int_t iTrack=0;iTrack<nMCTracks;iTrack++){
638 CbmMCTrack* mcTrack= (CbmMCTrack*) fMCTrackArray->At(iTrack);
639 if( mcTrack->GetMotherId() !=-1 ) continue; // not primary track
640 double z = mcTrack->GetStartZ();
641 if ( !Is_MC_V || fabs(z-MC_Vcurr.Z())>1.e-7 ){// new vertex
642 Is_MC_V = 1;
643 if( nvtrackscurr > nvtracks ){
644 MC_V = MC_Vcurr;
645 nvtracks = nvtrackscurr;
646 }
647 mcTrack->GetStartVertex(MC_Vcurr);
648 nvtrackscurr = 1;
649 }else nvtrackscurr++;
650 }
651 if( nvtrackscurr > nvtracks ) MC_V = MC_Vcurr;
652 }
653
654
655 if( Is_MC_V ){
656
657 // primary vertex fit performance
658
660
661 if( fVertexAnalysis ){
662
663 CbmPVFinderKF Finder;
664 TClonesArray TracksToFit("CbmStsTrack");
665 Int_t N=0;
666 for (Int_t iTrack=0;iTrack<nTracks;iTrack++){
667 if( Quality[iTrack]<1 ) continue;
668 new( TracksToFit[N] ) CbmStsTrack();
669 *(CbmStsTrack*)TracksToFit.At(N) = *(CbmStsTrack*)fRecStsTrackArray->At(iTrack);
670 N++;
671 if( N%50!=0 ) continue;
672 Int_t i = N/50;
673 if( i>=13 ) continue;
674 CbmVertex V;
675 Finder.FindPrimaryVertex( &TracksToFit, &V );
676 FillVertexHisto( MC_V, &V, fhV[i] );
677 }
678 CbmVertex V;
679 Finder.FindPrimaryVertex( &TracksToFit, &V );
680 FillVertexHisto( MC_V, &V, fhV[0] );
681 }
682
683 // D0 fit performance (if there are)
684
685 if( fD0Analysis&&fabs(MC_V.Z())<1.e-5 ){
686 // search for Kaon
687 for (Int_t iK=0;iK<nTracks;iK++){
688 if( Quality[iK]<1 ) continue;
691 CbmMCTrack* mcK = (CbmMCTrack*) fMCTrackArray->At(m->GetMCTrackId());
692 if( mcK->GetMotherId() !=-1 ) continue; // not primary or D0 track
693 if( abs(mcK->GetPdgCode())!=321 ) continue;
694 double zK = mcK->GetPz();
695 if( zK-MC_V.Z()<1.e-5 ) continue; // primary
696 double MCPK = mcK->GetP();
697 fFitter.DoFit( tK, 321 ); // refit
698 // search for Pion
699 for (Int_t iP=0;iP<nTracks;iP++){
700 if( Quality[iP]<1 ) continue;
702 m = (CbmTrackMatch*) fSTSTrackMatch->At(iP);
703 CbmMCTrack* mcP = (CbmMCTrack*) fMCTrackArray->At(m->GetMCTrackId());
704 if( mcP->GetMotherId() !=-1 ) continue; // not primary or D0 track
705 if( abs(mcP->GetPdgCode())!=211 ) continue;
706 if( mcK->GetPdgCode()*mcP->GetPdgCode() >=0 ) continue; //same charge
707 double zP = mcP->GetStartZ();
708 if( fabs(zP-zK)>1.e-8 ) continue; // different vertex
709 double MCPP = mcP->GetP();
710
711 const double D0 = 1.8645 ;
712
713 TVector3 mc_;
714 mcK->GetStartVertex(mc_);
715
717 SVFinder.AddTrack(tK);
718 SVFinder.AddTrack(tP);
719
720 for( int iconst=0; iconst<4; iconst++){
721
722 switch( iconst ){
723 case 0:
724 SVFinder.SetMassConstraint(); // no constraints
725 SVFinder.SetTopoConstraint();
726 break;
727 case 1:
728 SVFinder.SetMassConstraint();// Topo constraint
730 break;
731 case 2:
732 SVFinder.SetMassConstraint(D0);// Mass constraint
733 SVFinder.SetTopoConstraint();
734 break;
735 case 3:
736 SVFinder.SetMassConstraint(D0);// Topo + Mass constraint
738 break;
739 default:
740 break;
741 }
742 SVFinder.Fit();
743 CbmVertex sv;
744 //FairTrackParam KFitted, PFitted;
745 Double_t mass, mass_err;
746 SVFinder.GetVertex(sv);
747 //SVFinder.GetFittedTrack(0, &KFitted );
748 //SVFinder.GetFittedTrack(1, &PFitted );
749 SVFinder.GetMass(&mass, &mass_err);
750 if( sv.GetNDF()<=0) continue;
751 Double_t dx = sv.GetX() - mc_.X();
752 Double_t dy = sv.GetY() - mc_.Y();
753 Double_t dz = sv.GetZ() - mc_.Z();
754 Double_t sx = sv.GetCovariance(0,0);
755 Double_t sy = sv.GetCovariance(1,1);
756 Double_t sz = sv.GetCovariance(2,2);
757 fhD0[iconst][0]->Fill( 1.E4*dx );
758 fhD0[iconst][1]->Fill( 1.E4*dy );
759 fhD0[iconst][2]->Fill( 1.E4*dz );
760 if ( sx >1.e-10 ) fhD0[iconst][3]->Fill( dx/sqrt(sx) );
761 if ( sy >1.e-10 ) fhD0[iconst][4]->Fill( dy/sqrt(sy) );
762 if ( sz >1.e-10 ) fhD0[iconst][5]->Fill( dz/sqrt(sz) );
763 if( sv.GetNDF()>0 ){
764 fhD0[iconst][6]->Fill( sv.GetChi2()/sv.GetNDF() );
765 fhD0[iconst][7]->Fill( TMath::Prob(sv.GetChi2(),sv.GetNDF()) );
766 }
767 fhD0[iconst][8]->Fill( (mass-D0) );
768 if( mass_err>1.e-10 ) fhD0[iconst][9]->Fill( (mass-D0)/mass_err );
769 //fhD0[iconst][10]->Fill( ( fabs(1./KFitted.GetQp()) - MCPK)/MCPK );
770 //fhD0[iconst][11]->Fill( (fabs(1./PFitted.GetQp()) - MCPP)/MCPP );
771 if( fabs(tK->GetParamFirst()->GetQp())>1.e-4 && MCPK>1.e-4)
772 fhD0[iconst][12]->Fill( ( fabs(1./tK->GetParamFirst()->GetQp()) - MCPK)/MCPK );
773 if( fabs(tP->GetParamFirst()->GetQp())>1.e-4 && MCPP>1.e-4)
774 fhD0[iconst][13]->Fill( ( fabs(1./tP->GetParamFirst()->GetQp()) - MCPP)/MCPP );
775 }
776 }
777 }
778 }
779 }
780 }// vertex analysis
781}
782// -------------------------------------------------------------------------
783
784
785
786// ----- Finish CbmStsFitPerformanceTask task -----------------------------
790// -------------------------------------------------------------------------
791
792
793
794// -------------------------------------------------------------------------
795void CbmStsFitPerformanceTask::FillTrackHisto(const Double_t mc[6], CbmStsTrack *track, TH1D* hist[10] )
796{
797 if ((mc[5] > 31.0) ||(mc[5] < 29.0)){
798 //cout << " Z out " << track->GetParamFirst()->GetZ() << endl;
799 //return;
800 }
801 //cout << "*Z in " << track->GetParamFirst()->GetZ() << endl;
802 double z = mc[5];
803 FairTrackParam param;
804 //cout<<1<<endl;
805 fFitter.Extrapolate(track, z, &param);
806 //cout<<2<<endl;
807
808 double t[6],c[15];
809 CbmKFMath::CopyTrackParam2TC( &param, t, c );
810 Bool_t ok = 1;
811 for( int i=0; i<6; i++ ) ok = ok && finite(t[i]);
812 for( int i=0; i<15; i++ ) ok = ok && finite(c[i]);
813 if( !ok ) return;
814 //fhExtraTracks2ndMVD->Fill(t[0], t[1]);
815
816 hist[0]->Fill(1.E4*(t[0] - mc[0]));
817 hist[1]->Fill(1.E4*(t[1] - mc[1]));
818 hist[2]->Fill( 1.E3*(t[2] - mc[2]) );
819 hist[3]->Fill( 1.E3*(t[3] - mc[3]) );
820 if ( fabs( t[4] )>1.e-10 ) hist[4]->Fill( (mc[4]/t[4] - 1.) );
821 //if (z < 7.0) // first hit
822 //if ( fabs( t[4] )>1.e-10 ) fhRes_vs_Mom_f->Fill(fabs(1.0/t[4]),1.E3*(t[2] - mc[2]));
823 //if (z > 80.0) // last hit
824 //if ( fabs( t[4] )>1.e-10 ) fhRes_vs_Mom_l->Fill(fabs(1.0/t[4]),1.E3*(t[2] - mc[2]));
825
826 if ( c[ 0] >1.e-10 ) hist[5]->Fill( ( t[0] - mc[0] )/sqrt(c[ 0]) );
827 if ( c[ 2] >1.e-10 ) hist[6]->Fill( ( t[1] - mc[1] )/sqrt(c[ 2]) );
828 if ( c[ 5] >1.e-10 ) hist[7]->Fill( ( t[2] - mc[2] )/sqrt(c[ 5]) );
829 if ( c[ 9] >1.e-10 ) hist[8]->Fill( ( t[3] - mc[3] )/sqrt(c[ 9]) );
830 if ( c[14] >1.e-10 ) hist[9]->Fill( ( t[4] - mc[4] )/sqrt(c[14]) );
831}
832// -------------------------------------------------------------------------
833
834void CbmStsFitPerformanceTask::FillVertexHisto( TVector3 &mc, CbmVertex *V, TH1D* hist[8] )
835{
836 Double_t dx = V->GetX() - mc.X() ;
837 Double_t dy = V->GetY() - mc.Y() ;
838 Double_t dz = V->GetZ() - mc.Z() ;
839 Double_t s2x = V->GetCovariance(0,0);
840 Double_t s2y = V->GetCovariance(1,1);
841 Double_t s2z = V->GetCovariance(2,2);
842
843 hist[0]->Fill(1.E4*dx);
844 hist[1]->Fill(1.E4*dy);
845 hist[2]->Fill(1.E4*dz);
846 if ( s2x >1.e-10 ) hist[3]->Fill( dx/sqrt(s2x) );
847 if ( s2y >1.e-10 ) hist[4]->Fill( dy/sqrt(s2y) );
848 if ( s2z >1.e-10 ) hist[5]->Fill( dz/sqrt(s2z) );
849 hist[6]->Fill( V->GetChi2()/V->GetNDF() );
850 hist[7]->Fill( TMath::Prob(V->GetChi2(),V->GetNDF()));
851 hist[8]->Fill( V->GetNTracks() );
852}
853
854// -------------------------------------------------------------------------
855void CbmStsFitPerformanceTask::FillMCStateVectors( CbmStsPoint* point, Double_t mc[], Bool_t out){
856 if( !point ) return;
857 Int_t mcTrackID = point->GetTrackID();
858 CbmMCTrack* mcTrack = (CbmMCTrack*) fMCTrackArray->At(mcTrackID);
859 if( !mcTrack ) return;
860 Double_t q=GetCharge(mcTrack);
861
862 // Get MC state vector
863 TVector3 r,p;
864 if( !out ){
865 point->Momentum(p);
866 point->Position(r);
867 }else{
868 point->MomentumOut(p);
869 point->PositionOut(r);
870 }
871 double pzi = p.z();
872 if( fabs(pzi)>1.e-4 ) pzi = 1./pzi;
873 mc[2]=p.x()*pzi;
874 mc[3]=p.y()*pzi;
875 mc[4]=p.Mag()>1.e-4 ? q/p.Mag() :0;
876 mc[0]=r.x();
877 mc[1]=r.y();
878 mc[5]=r.z();
879}
880
881void CbmStsFitPerformanceTask::FillMCStateVectors( CbmMvdPoint* point, Double_t mc[], Bool_t out){
882 if( !point ) return;
883 Int_t mcTrackID = point->GetTrackID();
884 CbmMCTrack* mcTrack = (CbmMCTrack*) fMCTrackArray->At(mcTrackID);
885 if( !mcTrack ) return;
886 Double_t q=GetCharge(mcTrack);
887
888 // Get MC state vector
889 TVector3 r,p;
890 if( !out ){
891 point->Momentum(p);
892 point->Position(r);
893 }else{
894 point->MomentumOut(p);
895 point->PositionOut(r);
896 }
897 double pzi = p.z();
898 if( fabs(pzi)>1.e-4 ) pzi = 1./pzi;
899 mc[2]=p.x()*pzi;
900 mc[3]=p.y()*pzi;
901 mc[4]=p.Mag()>1.e-4 ? q/p.Mag() :0;
902 mc[0]=r.x();
903 mc[1]=r.y();
904 mc[5]=r.z();
905}
906
907
908// ----- GetCharge ----------------------------------------------------
910 Double_t q;
911 Int_t pdgCode = mcTrack->GetPdgCode();
912 TParticlePDG* particlePDG = TDatabasePDG::Instance()->GetParticle(pdgCode);
913 if (particlePDG) q = particlePDG->Charge()/3.; else q = 0;
914 return q;
915}
916
917
918// -------------------------------------------------------------------------
920 Int_t nHits = track->GetNStsHits();
921 if (nHits <4) return 0;
922 Int_t stmin=1000, stmax=-1000;
923 Int_t st,iHit,hitID;
924 for (iHit=0;iHit<nHits; iHit++){
925 hitID=track->GetStsHitIndex(iHit);
926 st=((CbmStsHit*) fStsHitArray->At(hitID))->GetDetectorID();
927 if (st<stmin) stmin=st;
928 if (st>stmax) stmax=st;
929 }
930 if (stmax-stmin+1<4) return 0;
931 return 1;
932}
const Float_t d
Z-ccordinate of the first GEM-station.
Definition BmnMwpcHit.cxx:7
void writedir2current(TObject *obj)
friend F32vec4 sqrt(const F32vec4 &a)
Definition P4_F32vec4.h:34
friend F32vec4 fabs(const F32vec4 &a)
Definition P4_F32vec4.h:52
__m128 v
Definition P4_F32vec4.h:1
int i
Definition P4_F32vec4.h:22
__m128 m
Definition P4_F32vec4.h:27
Double_t GetCovXY() const
Definition CbmHit.h:48
static void CopyTrackParam2TC(FairTrackParam *par, Double_t T[], Double_t C[])
static Bool_t invS(Double_t A[], Int_t N)
static Int_t indexS(Int_t i, Int_t j)
Definition CbmKFMath.h:33
Definition CbmKF.h:28
std::map< Int_t, Int_t > MvdStationIDMap
Definition CbmKF.h:75
static CbmKF * Instance()
Definition CbmKF.h:35
std::map< Int_t, Int_t > StsStationIDMap
Definition CbmKF.h:76
Double_t GetPy() const
Definition CbmMCTrack.h:59
Double_t GetPz() const
Definition CbmMCTrack.h:60
Double_t GetPx() const
Definition CbmMCTrack.h:58
Double_t GetStartZ() const
Definition CbmMCTrack.h:63
Double_t GetStartY() const
Definition CbmMCTrack.h:62
Int_t GetMotherId() const
Definition CbmMCTrack.h:57
Double_t GetP() const
Definition CbmMCTrack.h:68
Double_t GetStartX() const
Definition CbmMCTrack.h:61
void GetStartVertex(TVector3 &vertex) const
Definition CbmMCTrack.h:149
Int_t GetPdgCode() const
Definition CbmMCTrack.h:56
virtual Int_t GetStationNr() const
Definition CbmMvdHit.h:55
void MomentumOut(TVector3 &mom)
Definition CbmMvdPoint.h:74
void PositionOut(TVector3 &pos)
Definition CbmMvdPoint.h:73
Int_t FindPrimaryVertex(TClonesArray *tracks, CbmVertex *vertex)
TClonesArray * fMCTrackArray
MCTracks.
void FillMCStateVectors(CbmStsPoint *point, Double_t mc[], Bool_t out=0)
Bool_t IsLong(CbmStsTrack *track)
TClonesArray * fMvdHitArray
Sts hits.
TClonesArray * fStsHitArray
Sts hits.
CbmVertex * fPrimaryVertex
Primary vertex.
CbmStsFitPerformanceTask(const char *name="CbmStsFitPerformanceTask", Int_t iVerbose=1)
TClonesArray * fSTSTrackMatch
Related MC tracks.
TClonesArray * fMvdPointArray
StsPoints.
Double_t GetCharge(CbmMCTrack *mcTrack)
TClonesArray * fRecStsTrackArray
Reconstructed StsTracks.
void CreateTrackHisto(TH1D *hist[10], const char *name, const char *title)
void FillVertexHisto(TVector3 &mc, CbmVertex *V, TH1D *hist[8])
void FillTrackHisto(const Double_t mc[6], CbmStsTrack *track, TH1D *hist[10])
void CreateD0Histo(TH1D *hist[14], const char *name, const char *title)
TClonesArray * fStsPointArray
StsPoints.
void CreateVertexHisto(TH1D *hist[9], const char *name, const char *title)
virtual Int_t GetStationNr() const
Definition CbmStsHit.h:66
Int_t GetDigi(Int_t iSide) const
void SetMassConstraint(Double_t MotherMass=-1)
void GetMass(Double_t *M, Double_t *Error)
void Extrapolate(CbmStsTrack *track, Double_t z, FairTrackParam *e_track)
Double_t FitToVertex(CbmStsTrack *track, CbmVertex *vtx, FairTrackParam *v_track)
Int_t DoFit(CbmStsTrack *track, Int_t pidHypo=211)
void PositionOut(TVector3 &pos)
Definition CbmStsPoint.h:79
void MomentumOut(TVector3 &mom)
Definition CbmStsPoint.h:80
FairTrackParam * GetParamLast()
Definition CbmStsTrack.h:70
Int_t GetNMvdHits() const
Definition CbmStsTrack.h:61
Int_t GetMvdHitIndex(Int_t iHit) const
Definition CbmStsTrack.h:63
Int_t GetNStsHits() const
Definition CbmStsTrack.h:60
Double_t GetChi2() const
Definition CbmStsTrack.h:66
Int_t GetStsHitIndex(Int_t iHit) const
Definition CbmStsTrack.h:62
FairTrackParam * GetParamFirst()
Definition CbmStsTrack.h:69
Int_t GetNDF() const
Definition CbmStsTrack.h:67
Int_t GetMCTrackId() const
Double_t GetZ() const
Definition CbmVertex.h:60
Double_t GetX() const
Definition CbmVertex.h:58
Int_t GetNTracks() const
Definition CbmVertex.h:63
Double_t GetChi2() const
Definition CbmVertex.h:61
Double_t GetCovariance(Int_t i, Int_t j) const
Double_t GetY() const
Definition CbmVertex.h:59
Int_t GetNDF() const
Definition CbmVertex.h:62