139 int nEvents =
fEvents->GetEntriesFast();
141 vector<KFParticleTopoReconstructor> eventTopoReconstructor(nEvents);
143 for (
int iEvent = 0, firstEventTrack = 0, nTracksEvent = 0; iEvent < nEvents;
144 iEvent++, firstEventTrack += nTracksEvent) {
151 eventTopoReconstructor[iEvent].SetChi2PrimaryCut(
InversedChi2Prob(0.0001, 2));
153 eventTopoReconstructor[iEvent].GetKFParticleFinder()->SetReconstructionList(
159 int nCandidatesDHe4 = 0;
161 if ((
int)
fPID->
GetPID().size() >= firstEventTrack + nTracksEvent) {
162 for (
int iTr = 0; iTr < nTracksEvent; iTr++) {
163 if (TMath::Abs(
fPID->
GetPID()[firstEventTrack + iTr]) == 1000010029) {
169 LOG(error) <<
"CbmKFParticleFinder::Event: PID task has a wrong number of tracks: " <<
fPID->
GetPID().size()
170 <<
" of " << firstEventTrack + nTracksEvent;
174 vector<CbmStsTrack> vRTracks(nTracksEvent + nCandidatesDHe4);
175 vector<int> pdg(nTracksEvent + nCandidatesDHe4, -1);
176 vector<int> trackId(nTracksEvent + nCandidatesDHe4, -1);
178 for (
int iTr = 0; iTr < nTracksEvent; iTr++) {
179 int stsTrackIndex =
event->GetStsTrackIndex(iTr);
182 const FairTrackParam* parameters = stsTrack->
GetParamFirst();
184 Double_t V[15] = {0.f};
185 for (Int_t i = 0, iCov = 0; i < 5; i++) {
186 for (Int_t j = 0; j <= i; j++, iCov++) {
187 V[iCov] = parameters->GetCovariance(i, j);
196 ok = ok && std::isfinite(parameters->GetX());
197 ok = ok && std::isfinite(parameters->GetY());
198 ok = ok && std::isfinite(parameters->GetZ());
199 ok = ok && std::isfinite(parameters->GetTx());
200 ok = ok && std::isfinite(parameters->GetTy());
201 ok = ok && std::isfinite(parameters->GetQp());
203 for (
unsigned short iC = 0; iC < 15; iC++) {
204 ok = ok && std::isfinite(V[iC]);
207 ok = ok && (V[0] < 1. && V[0] > 0.) && (V[2] < 1. && V[2] > 0.) && (V[5] < 1. && V[5] > 0.)
208 && (V[9] < 1. && V[9] > 0.) && (V[14] < 1. && V[14] > 0.);
220 if (TMath::Abs(
fPID->
GetPID()[stsTrackIndex]) == 1000010029) {
222 pdg[ntracks] =
sgn * 1000010020;
223 vRTracks[ntracks] = *stsTrack;
224 trackId[ntracks] = stsTrackIndex;
227 pdg[ntracks] =
sgn * 1000020040;
237 vRTracks[ntracks] = *stsTrack;
238 trackId[ntracks] = stsTrackIndex;
243 vRTracks.resize(ntracks);
245 trackId.resize(ntracks);
248 vector<float> vChiToPrimVtx;
258 std::vector<double> mcWeight(nMCEvents, 0.);
259 for (
int trId : trackId) {
261 for (
int iLink = 0; iLink < stsTrackMatch->
GetNofLinks(); iLink++) {
264 if (iTrackMcEvent < 0 || iTrackMcEvent >= nMCEvents)
continue;
265 mcWeight[iTrackMcEvent] += link.
GetWeight();
269 iMcEvent = std::distance(mcWeight.begin(), std::max_element(mcWeight.begin(), mcWeight.end()));
271 if (iMcEvent < 0 || iMcEvent >= nMCEvents) {
272 LOG(error) <<
"CbmKFParticleFinder::Event: No MC event found for event " << iEvent;
277 bool isMCPVFound =
false;
282 for (Int_t iMC = 0; (iMC <
nMCTracks) && (!isMCPVFound); iMC++) {
283 CbmLink mcTrackLink = mcEventLink;
287 if (cbmMCTrack->GetMotherId() < 0) {
288 kfVertex.
GetRefX() = cbmMCTrack->GetStartX();
289 kfVertex.
GetRefY() = cbmMCTrack->GetStartY();
290 kfVertex.
GetRefZ() = cbmMCTrack->GetStartZ();
300 const CbmVertex* primVertex =
event->GetVertex();
307 vector<CbmL1PFFitter::PFFieldRegion> vField, vFieldAtLastPoint;
308 fitter.
Fit(vRTracks, pdg);
309 fitter.
GetChiToVertex(vRTracks, vField, vChiToPrimVtx, kfVertex, 3);
311 vector<KFFieldVector> vFieldVector(ntracks), vFieldVectorAtLastPoint(ntracks);
312 for (Int_t iTr = 0; iTr < ntracks; iTr++) {
313 for (
int i = 0; i < 10; i++) {
314 vFieldVector[iTr].fField[i] = vField[iTr].fP[i];
317 for (Int_t iTr = 0; iTr < ntracks; iTr++) {
318 for (
int i = 0; i < 10; i++) {
319 vFieldVectorAtLastPoint[iTr].fField[i] = vFieldAtLastPoint[iTr].fP[i];
326 KFPTrackVector tracksAtLastPoint;
327 FillKFPTrackVector(&tracksAtLastPoint, vRTracks, vFieldVectorAtLastPoint, pdg, trackId, vChiToPrimVtx, 0);
332 eventTopoReconstructor[iEvent].Init(
tracks, tracksAtLastPoint);
335 KFPVertex primVtx_tmp;
337 primVtx_tmp.SetCovarianceMatrix(0, 0, 0, 0, 0, 0);
338 primVtx_tmp.SetNContributors(0);
339 primVtx_tmp.SetChi2(-100);
341 vector<int> pvTrackIds;
342 KFVertex pv(primVtx_tmp);
343 eventTopoReconstructor[iEvent].AddPV(pv, pvTrackIds);
346 eventTopoReconstructor[iEvent].ReconstructPrimVertex();
349 eventTopoReconstructor[iEvent].ReconstructPrimVertex(0);
352 eventTopoReconstructor[iEvent].SortTracks();
353 eventTopoReconstructor[iEvent].ReconstructParticles();
356 eventTopoReconstructor[iEvent].SetTime(timer.RealTime());
359 for (
int iTr = 0; iTr < ntracks; iTr++) {
360 const FairTrackParam* parameters = vRTracks[iTr].GetParamFirst();
361 float a = parameters->GetTx(), b = parameters->GetTy(), qp = parameters->GetQp();
369 float c2 = 1.f / (1.f + a * a + b * b);
370 float pq = 1.f / qp * TMath::Abs(q);
372 float pz =
sqrt(p2 * c2);
375 float pt =
sqrt(px * px + py * py);
379 if (vChiToPrimVtx[iTr] < 3) {
380 if ((fabs(pdg[iTr]) == 11 && pt > 0.2f) || (fabs(pdg[iTr]) == 13) || (fabs(pdg[iTr]) == 19)) {
385 if (vChiToPrimVtx[iTr] > 3) {
386 if ((fabs(pdg[iTr]) == 211 || fabs(pdg[iTr]) == 321 || fabs(pdg[iTr]) == 2212 || pdg[iTr] == -1)
394 fSEField.push_back(vFieldVector[iTr]);
395 fSEpdg.push_back(pdg[iTr]);
404 vector<int> PVTrackIndexArray;
406 for (
int iEvent = 0; iEvent < nEvents; iEvent++) {
407 const KFParticleTopoReconstructor* eventTR = &eventTopoReconstructor[iEvent];
409 for (
int iPV = 0; iPV < eventTR->NPrimaryVertices(); iPV++) {
410 PVTrackIndexArray = eventTR->GetPVTrackIndexArray(iPV);
411 for (
unsigned int iTr = 0; iTr < PVTrackIndexArray.size(); iTr++) {
412 PVTrackIndexArray[iTr] = PVTrackIndexArray[iTr] + indexAdd;
415 PVTrackIndexArray.clear();
418 for (
unsigned int iP = 0; iP < eventTR->GetParticles().
size(); iP++) {
419 const KFParticle& particleEvent = eventTR->GetParticles()[iP];
420 KFParticle particle = particleEvent;
421 particle.CleanDaughtersId();
422 int idP = particleEvent.Id() + indexAdd;
424 for (
int nD = 0; nD < particleEvent.NDaughters(); nD++) {
425 if (particleEvent.NDaughters() == 1) {
426 idDaughter = particleEvent.DaughterIds()[nD];
428 if (particleEvent.NDaughters() > 1) {
429 idDaughter = particleEvent.DaughterIds()[nD] + indexAdd;
431 particle.AddDaughterId(idDaughter);
437 indexAdd += eventTR->GetParticles().size();
473 const vector<KFFieldVector>& vField,
const vector<int>& pdg,
474 const vector<int>& trackId,
const vector<float>& vChiToPrimVtx,
475 bool atFirstPoint)
const
477 int ntracks = vRTracks.size();
480 for (Int_t iTr = 0; iTr < ntracks; iTr++) {
481 const FairTrackParam* parameters;
483 parameters = vRTracks[iTr].GetParamFirst();
486 parameters = vRTracks[iTr].GetParamLast();
489 double par[6] = {0.f};
491 double tx = parameters->GetTx(), ty = parameters->GetTy(), qp = parameters->GetQp();
500 if (TMath::Abs(pdg[iTr]) == 1000020030 || TMath::Abs(pdg[iTr]) == 1000020040) {
505 double c2 = 1.f / (1.f + tx * tx + ty * ty);
506 double pq = 1.f / qp * TMath::Abs(q);
508 double pz =
sqrt(p2 * c2);
512 par[0] = parameters->GetX();
513 par[1] = parameters->GetY();
514 par[2] = parameters->GetZ();
520 double t =
sqrt(1.f + tx * tx + ty * ty);
521 double t3 = t * t * t;
522 double dpxdtx = q / qp * (1.f + ty * ty) / t3;
523 double dpxdty = -q / qp * tx * ty / t3;
524 double dpxdqp = -q / (qp * qp) * tx / t;
525 double dpydtx = -q / qp * tx * ty / t3;
526 double dpydty = q / qp * (1.f + tx * tx) / t3;
527 double dpydqp = -q / (qp * qp) * ty / t;
528 double dpzdtx = -q / qp * tx / t3;
529 double dpzdty = -q / qp * ty / t3;
530 double dpzdqp = -q / (qp * qp * t3);
532 double F[6][5] = {{1.f, 0.f, 0.f, 0.f, 0.f}, {0.f, 1.f, 0.f, 0.f, 0.f},
533 {0.f, 0.f, 0.f, 0.f, 0.f}, {0.f, 0.f, dpxdtx, dpxdty, dpxdqp},
534 {0.f, 0.f, dpydtx, dpydty, dpydqp}, {0.f, 0.f, dpzdtx, dpzdty, dpzdqp}};
537 for (
int i = 0; i < 5; i++) {
538 for (
int j = 0; j < 6; j++) {
540 for (
int k = 0; k < 5; k++) {
541 VFT[i][j] += parameters->GetCovariance(i, k) * F[j][k];
547 for (
int i = 0, l = 0; i < 6; i++) {
548 for (
int j = 0; j <= i; j++, l++) {
550 for (
int k = 0; k < 5; k++) {
551 cov[l] += F[i][k] * VFT[k][j];
556 for (Int_t iP = 0; iP < 6; iP++) {
557 tracks->SetParameter(par[iP], iP, iTr);
559 for (Int_t iC = 0; iC < 21; iC++) {
560 tracks->SetCovariance(cov[iC], iC, iTr);
562 for (Int_t iF = 0; iF < 10; iF++) {
563 tracks->SetFieldCoefficient(vField[iTr].fField[iF], iF, iTr);
565 tracks->SetId(trackId[iTr], iTr);
566 tracks->SetPDG(pdg[iTr], iTr);
568 tracks->SetNPixelHits(vRTracks[iTr].GetNofMvdHits(), iTr);
571 if (vChiToPrimVtx[iTr] < 3) {
572 tracks->SetPVIndex(0, iTr);
575 tracks->SetPVIndex(-1, iTr);
579 tracks->SetPVIndex(-1, iTr);
void FillKFPTrackVector(KFPTrackVector *tracks, const std::vector< CbmStsTrack > &vRTracks, const std::vector< KFFieldVector > &vField, const std::vector< int > &pdg, const std::vector< int > &trackId, const std::vector< float > &vChiToPrimVtx, bool atFirstPoint=1) const