14 #include "FairRunAna.h"
18 #include "KFPTrackVector.h"
19 #include "KFParticleTopoReconstructor.h"
21 #include "FairLogger.h"
24 #include "TClonesArray.h"
26 #include "TStopwatch.h"
35 : FairTask(name, iVerbose)
36 , fStsTrackBranchName(
"StsTrack")
39 , fTopoReconstructor(0)
42 , fSuperEventAnalysis(0)
61 FairRootManager* ioman = FairRootManager::Instance();
64 Error(
"CbmKFParticleFinder::Init",
"RootManager not instantiated!");
70 if (ioman->CheckBranch(
"Event")) {
72 LOG(info) << GetName() <<
": Running in the timeslice mode.";
74 LOG(info) << GetName() <<
": Running in the event by event mode.";
78 fEvents = (TClonesArray*) ioman->GetObject(
"Event");
80 Fatal(
"CbmKFParticleFinder::Init",
81 "No events available. Running in the event-by-event mode.");
87 Error(
"CbmKFParticleFinder::Init",
"track-array not found!");
97 Error(
"CbmKFParticleFinder::Init",
"MC Data Manager not found!");
102 Error(
"CbmKFParticleFinder::Init",
"MC track array not found!");
108 Error(
"CbmKFParticleFinder::Init",
"MC Event List not found!");
114 Error(
"CbmKFParticleFinder::Init",
"MC track array not found!");
131 vector<KFParticleTopoReconstructor> eventTopoReconstructor;
132 eventTopoReconstructor.resize(nEvents);
134 for (
int iEvent = 0; iEvent < nEvents; iEvent++) {
137 eventTopoReconstructor[iEvent].SetChi2PrimaryCut(
140 eventTopoReconstructor[iEvent].GetKFParticleFinder()->SetReconstructionList(
143 int nTracksEvent = 0;
145 nTracksEvent =
event->GetNofStsTracks();
152 int nCandidatesDHe4 = 0;
154 for (
int iTr = 0; iTr < nTracksEvent; iTr++)
155 if (TMath::Abs(
fPID->
GetPID()[iTr]) == 1000010029) nCandidatesDHe4++;
157 vector<CbmStsTrack> vRTracks(nTracksEvent + nCandidatesDHe4);
158 vector<int> pdg(nTracksEvent + nCandidatesDHe4, -1);
159 vector<int> trackId(nTracksEvent + nCandidatesDHe4, -1);
161 for (
int iTr = 0; iTr < nTracksEvent; iTr++) {
162 int stsTrackIndex = 0;
164 stsTrackIndex =
event->GetStsTrackIndex(iTr);
169 const FairTrackParam* parameters = stsTrack->
GetParamFirst();
171 Double_t V[15] = {0.f};
172 for (Int_t
i = 0, iCov = 0;
i < 5;
i++)
173 for (Int_t j = 0; j <=
i; j++, iCov++)
174 V[iCov] = parameters->GetCovariance(
i, j);
179 ok = ok &&
finite(parameters->GetX());
180 ok = ok &&
finite(parameters->GetY());
181 ok = ok &&
finite(parameters->GetZ());
182 ok = ok &&
finite(parameters->GetTx());
183 ok = ok &&
finite(parameters->GetTy());
184 ok = ok &&
finite(parameters->GetQp());
186 for (
unsigned short iC = 0; iC < 15; iC++)
188 ok = ok && (V[0] < 1. && V[0] > 0.) && (V[2] < 1. && V[2] > 0.)
189 && (V[5] < 1. && V[5] > 0.) && (V[9] < 1. && V[9] > 0.)
190 && (V[14] < 1. && V[14] > 0.);
195 if (
fPID->
GetPID()[stsTrackIndex] == -2)
continue;
198 if (TMath::Abs(
fPID->
GetPID()[stsTrackIndex]) == 1000010029) {
201 pdg[ntracks] =
sgn * 1000010020;
202 vRTracks[ntracks] = *stsTrack;
203 trackId[ntracks] = stsTrackIndex;
206 pdg[ntracks] =
sgn * 1000020040;
212 vRTracks[ntracks] = *stsTrack;
213 trackId[ntracks] = stsTrackIndex;
218 vRTracks.resize(ntracks);
220 trackId.resize(ntracks);
223 vector<float> vChiToPrimVtx;
229 float mcpv[3] = {0.f, 0.f, 0.f};
230 bool isMCPVFound =
false;
231 for (
int iMCEvent = 0; iMCEvent < nMCEvents; iMCEvent++) {
238 for (Int_t iMC = 0; iMC <
nMCTracks; iMC++) {
253 if (isMCPVFound)
break;
267 vector<L1FieldRegion> vField, vFieldAtLastPoint;
268 fitter.
Fit(vRTracks, pdg);
269 fitter.
GetChiToVertex(vRTracks, vField, vChiToPrimVtx, kfVertex, 3);
271 vector<KFFieldVector> vFieldVector(ntracks),
272 vFieldVectorAtLastPoint(ntracks);
273 for (Int_t iTr = 0; iTr < ntracks; iTr++) {
276 vFieldVector[iTr].fField[0] = vField[entrVec].cx0[entrSIMD];
277 vFieldVector[iTr].fField[1] = vField[entrVec].cx1[entrSIMD];
278 vFieldVector[iTr].fField[2] = vField[entrVec].cx2[entrSIMD];
279 vFieldVector[iTr].fField[3] = vField[entrVec].cy0[entrSIMD];
280 vFieldVector[iTr].fField[4] = vField[entrVec].cy1[entrSIMD];
281 vFieldVector[iTr].fField[5] = vField[entrVec].cy2[entrSIMD];
282 vFieldVector[iTr].fField[6] = vField[entrVec].cz0[entrSIMD];
283 vFieldVector[iTr].fField[7] = vField[entrVec].cz1[entrSIMD];
284 vFieldVector[iTr].fField[8] = vField[entrVec].cz2[entrSIMD];
285 vFieldVector[iTr].fField[9] = vField[entrVec].z0[entrSIMD];
287 for (Int_t iTr = 0; iTr < ntracks; iTr++) {
290 vFieldVectorAtLastPoint[iTr].fField[0] =
291 vFieldAtLastPoint[entrVec].cx0[entrSIMD];
292 vFieldVectorAtLastPoint[iTr].fField[1] =
293 vFieldAtLastPoint[entrVec].cx1[entrSIMD];
294 vFieldVectorAtLastPoint[iTr].fField[2] =
295 vFieldAtLastPoint[entrVec].cx2[entrSIMD];
296 vFieldVectorAtLastPoint[iTr].fField[3] =
297 vFieldAtLastPoint[entrVec].cy0[entrSIMD];
298 vFieldVectorAtLastPoint[iTr].fField[4] =
299 vFieldAtLastPoint[entrVec].cy1[entrSIMD];
300 vFieldVectorAtLastPoint[iTr].fField[5] =
301 vFieldAtLastPoint[entrVec].cy2[entrSIMD];
302 vFieldVectorAtLastPoint[iTr].fField[6] =
303 vFieldAtLastPoint[entrVec].cz0[entrSIMD];
304 vFieldVectorAtLastPoint[iTr].fField[7] =
305 vFieldAtLastPoint[entrVec].cz1[entrSIMD];
306 vFieldVectorAtLastPoint[iTr].fField[8] =
307 vFieldAtLastPoint[entrVec].cz2[entrSIMD];
308 vFieldVectorAtLastPoint[iTr].fField[9] =
309 vFieldAtLastPoint[entrVec].z0[entrSIMD];
315 &
tracks, vRTracks, vFieldVector, pdg, trackId, vChiToPrimVtx);
316 KFPTrackVector tracksAtLastPoint;
319 vFieldVectorAtLastPoint,
328 eventTopoReconstructor[iEvent].Init(
tracks, tracksAtLastPoint);
331 KFPVertex primVtx_tmp;
334 primVtx_tmp.SetCovarianceMatrix(0, 0, 0, 0, 0, 0);
335 primVtx_tmp.SetNContributors(0);
336 primVtx_tmp.SetChi2(-100);
338 vector<int> pvTrackIds;
339 KFVertex pv(primVtx_tmp);
340 eventTopoReconstructor[iEvent].AddPV(pv, pvTrackIds);
342 eventTopoReconstructor[iEvent].ReconstructPrimVertex();
344 eventTopoReconstructor[iEvent].ReconstructPrimVertex(0);
346 eventTopoReconstructor[iEvent].SortTracks();
347 eventTopoReconstructor[iEvent].ReconstructParticles();
350 eventTopoReconstructor[iEvent].SetTime(timer.RealTime());
352 for (
int iTr = 0; iTr < ntracks; iTr++) {
353 const FairTrackParam* parameters = vRTracks[iTr].GetParamFirst();
354 float a = parameters->GetTx(), b = parameters->GetTy(),
355 qp = parameters->GetQp();
358 if (qp < 0.
f) q = -1;
359 float c2 = 1.f / (1.f + a * a + b * b);
360 float pq = 1.f / qp * TMath::Abs(q);
362 float pz =
sqrt(p2 * c2);
365 float pt =
sqrt(px * px + py * py);
369 if (vChiToPrimVtx[iTr] < 3) {
370 if ((
fabs(pdg[iTr]) == 11 && pt > 0.2
f) || (
fabs(pdg[iTr]) == 13)
371 || (
fabs(pdg[iTr]) == 19))
375 if (vChiToPrimVtx[iTr] > 3) {
376 if ((
fabs(pdg[iTr]) == 211 ||
fabs(pdg[iTr]) == 321
377 ||
fabs(pdg[iTr]) == 2212 || pdg[iTr] == -1)
384 fSEField.push_back(vFieldVector[iTr]);
385 fSEpdg.push_back(pdg[iTr]);
394 vector<int> PVTrackIndexArray;
397 for (
int iEvent = 0; iEvent < nEvents; iEvent++) {
398 const KFParticleTopoReconstructor* eventTR =
399 &eventTopoReconstructor[iEvent];
401 for (
int iPV = 0; iPV < eventTR->NPrimaryVertices(); iPV++) {
402 PVTrackIndexArray = eventTR->GetPVTrackIndexArray(iPV);
403 for (
unsigned int iTr = 0; iTr < PVTrackIndexArray.size(); iTr++)
404 PVTrackIndexArray[iTr] = PVTrackIndexArray[iTr] + indexAdd;
408 PVTrackIndexArray.clear();
410 for (
unsigned int iP = 0; iP < eventTR->GetParticles().size(); iP++) {
412 const KFParticle& particleEvent = eventTR->GetParticles()[iP];
413 particle = particleEvent;
414 particle.CleanDaughtersId();
415 int idP = particleEvent.Id() + indexAdd;
417 for (
int nD = 0; nD < particleEvent.NDaughters(); nD++) {
418 if (particleEvent.NDaughters() == 1)
419 idDaughter = particleEvent.DaughterIds()[nD];
420 if (particleEvent.NDaughters() > 1)
421 idDaughter = particleEvent.DaughterIds()[nD] + indexAdd;
422 particle.AddDaughterId(idDaughter);
427 indexAdd += eventTR->GetParticles().size();
436 KFPTrackVector tracksAtLastPoint;
438 LOG(info) <<
"CbmKFParticleFinder: Start SE analysis";
444 KFPVertex primVtx_tmp;
445 primVtx_tmp.SetXYZ(0, 0, 0);
446 primVtx_tmp.SetCovarianceMatrix(0, 0, 0, 0, 0, 0);
447 primVtx_tmp.SetNContributors(0);
448 primVtx_tmp.SetChi2(-100);
449 vector<int> pvTrackIds;
450 KFVertex pv(primVtx_tmp);
458 LOG(info) <<
"CbmKFParticleFinder: Finish SE analysis" << timer.RealTime();
464 const vector<CbmStsTrack>& vRTracks,
465 const vector<KFFieldVector>& vField,
466 const vector<int>& pdg,
467 const vector<int>& trackId,
468 const vector<float>& vChiToPrimVtx,
469 bool atFirstPoint)
const {
470 int ntracks = vRTracks.size();
473 for (Int_t iTr = 0; iTr < ntracks; iTr++) {
474 const FairTrackParam* parameters;
476 parameters = vRTracks[iTr].GetParamFirst();
478 parameters = vRTracks[iTr].GetParamLast();
480 double par[6] = {0.f};
482 double tx = parameters->GetTx(), ty = parameters->GetTy(),
483 qp = parameters->GetQp();
487 if (qp < 0.
f) q = -1;
488 if (TMath::Abs(pdg[iTr]) == 1000020030
489 || TMath::Abs(pdg[iTr]) == 1000020040)
493 double c2 = 1.f / (1.f + tx * tx + ty * ty);
494 double pq = 1.f / qp * TMath::Abs(q);
496 double pz =
sqrt(p2 * c2);
500 par[0] = parameters->GetX();
501 par[1] = parameters->GetY();
502 par[2] = parameters->GetZ();
508 double t =
sqrt(1.
f + tx * tx + ty * ty);
509 double t3 = t * t * t;
510 double dpxdtx = q / qp * (1.f + ty * ty) / t3;
511 double dpxdty = -q / qp * tx * ty / t3;
512 double dpxdqp = -q / (qp * qp) * tx / t;
513 double dpydtx = -q / qp * tx * ty / t3;
514 double dpydty = q / qp * (1.f + tx * tx) / t3;
515 double dpydqp = -q / (qp * qp) * ty / t;
516 double dpzdtx = -q / qp * tx / t3;
517 double dpzdty = -q / qp * ty / t3;
518 double dpzdqp = -q / (qp * qp * t3);
520 double F[6][5] = {{1.f, 0.f, 0.f, 0.f, 0.f},
521 {0.f, 1.f, 0.f, 0.f, 0.f},
522 {0.f, 0.f, 0.f, 0.f, 0.f},
523 {0.f, 0.f, dpxdtx, dpxdty, dpxdqp},
524 {0.f, 0.f, dpydtx, dpydty, dpydqp},
525 {0.f, 0.f, dpzdtx, dpzdty, dpzdqp}};
528 for (
int i = 0;
i < 5;
i++)
529 for (
int j = 0; j < 6; j++) {
531 for (
int k = 0; k < 5; k++) {
532 VFT[
i][j] += parameters->GetCovariance(
i, k) * F[j][k];
537 for (
int i = 0, l = 0;
i < 6;
i++)
538 for (
int j = 0; j <=
i; j++, l++) {
540 for (
int k = 0; k < 5; k++) {
541 cov[l] += F[
i][k] * VFT[k][j];
545 for (Int_t iP = 0; iP < 6; iP++)
546 tracks->SetParameter(par[iP], iP, iTr);
547 for (Int_t iC = 0; iC < 21; iC++)
548 tracks->SetCovariance(cov[iC], iC, iTr);
549 for (Int_t iF = 0; iF < 10; iF++)
550 tracks->SetFieldCoefficient(vField[iTr].fField[iF], iF, iTr);
551 tracks->SetId(trackId[iTr], iTr);
552 tracks->SetPDG(pdg[iTr], iTr);
554 tracks->SetNPixelHits(vRTracks[iTr].GetNofMvdHits(), iTr);
557 if (vChiToPrimVtx[iTr] < 3)
558 tracks->SetPVIndex(0, iTr);
560 tracks->SetPVIndex(-1, iTr);
562 tracks->SetPVIndex(-1, iTr);
567 double epsilon = 1.e-14;
568 double chi2Left = 0.f;
569 double chi2Right = 10000.f;
571 double probLeft = p - TMath::Prob(chi2Left, ndf);
573 double chi2Centr = (chi2Left + chi2Right) / 2.
f;
574 double probCentr = p - TMath::Prob(chi2Centr, ndf);
576 while (TMath::Abs(chi2Right - chi2Centr) / chi2Centr > epsilon) {
577 if (probCentr * probLeft > 0.
f) {
578 chi2Left = chi2Centr;
579 probLeft = probCentr;
581 chi2Right = chi2Centr;
584 chi2Centr = (chi2Left + chi2Right) / 2.
f;
585 probCentr = p - TMath::Prob(chi2Centr, ndf);