14 #include "CbmTofHit.h"
23 #include "FairRunAna.h"
26 #include "TClonesArray.h"
35 vector<double> vecCopy = vec;
36 sort(vecCopy.begin(), vecCopy.end());
37 int size = vecCopy.size();
39 median = (vecCopy[size / 2 - 1] + vecCopy[size / 2]) / 2;
41 median = vecCopy[size / 2];
46 : FairTask(name, iVerbose)
47 , fStsTrackBranchName(
"StsTrack")
48 , fGlobalTrackBranchName(
"GlobalTrack")
49 , fStsHitBranchName(
"StsHit")
50 , fStsClusterBranchName(
"StsCluster")
51 , fStsDigiBranchName(
"StsDigi")
52 , fTofBranchName(
"TofHit")
53 , fMCTracksBranchName(
"MCTrack")
54 , fTrackMatchBranchName(
"StsTrackMatch")
55 , fTrdBranchName(
"TrdTrack")
56 , fTrdHitBranchName(
"TrdHit")
57 , fRichBranchName(
"RichRing")
58 , fMuchTrackBranchName(
"MuchTrack")
60 , fGlobalTrackArray(0)
63 , fDigiManager(nullptr)
93 FairRootManager* ioman = FairRootManager::Instance();
96 Error(
"CbmKFParticleFinderPID::Init",
"RootManager not instantiated!");
103 if (ioman->CheckBranch(
"Event")) {
105 LOG(info) << GetName() <<
": Running in the timeslice mode.";
107 LOG(info) << GetName() <<
": Running in the event by event mode.";
112 FairRootManager* fManger = FairRootManager::Instance();
114 Fatal(
"CbmKFParticleFinder::Init",
"fManger is not found!");
125 if (mcManager == 0) {
126 Fatal(
"CbmKFParticleFinderPID::Init",
"MC Data Manager is not found!");
133 Fatal(
"CbmKFParticleFinderPID::Init",
"MC track array not found!");
139 Fatal(
"CbmKFParticleFinderPID::Init",
"MC track array not found!");
147 Error(
"CbmKFParticleFinderPID::Init",
"track match array not found!");
155 Error(
"CbmKFParticleFinderPID::Init",
"track-array not found!");
164 Error(
"CbmKFParticleFinderPID::Init",
"global track array not found!");
171 Error(
"CbmKFParticleFinderPID::Init",
"STS hit array not found!");
178 Error(
"CbmKFParticleFinderPID::Init",
"STS cluster array not found!");
189 LOG(fatal) << GetName() <<
": No StsDigi branch in input!";
194 Error(
"CbmKFParticleFinderPID::Init",
"TOF track-array not found!");
201 Error(
"CbmKFParticleFinderPID::Init",
"TRD track-array not found!");
208 Error(
"CbmKFParticleFinderPID::Init",
"TRD hit array not found!");
214 Error(
"CbmKFParticleFinderPID::Init",
"Rich ring array not found!");
222 Error(
"CbmKFParticleFinderPID::Init",
"Much track-array not found!");
235 fPID.resize(nTracks, -1);
248 for (
int iTr = 0; iTr < nTracks; iTr++) {
254 Float_t bestWeight = 0.f;
255 Float_t totalWeight = 0.f;
256 Int_t mcTrackId = -1;
260 for (
int iLink = 0; iLink < stsTrackMatch->
GetNofLinks(); iLink++) {
271 if (bestWeight / totalWeight < 0.7)
continue;
293 if (!(TMath::Abs(cbmMCTrack->
GetPdgCode()) == 11
295 || TMath::Abs(cbmMCTrack->
GetPdgCode()) == 211
296 || TMath::Abs(cbmMCTrack->
GetPdgCode()) == 321
297 || TMath::Abs(cbmMCTrack->
GetPdgCode()) == 2212
298 || TMath::Abs(cbmMCTrack->
GetPdgCode()) == 1000010020
299 || TMath::Abs(cbmMCTrack->
GetPdgCode()) == 1000010030
300 || TMath::Abs(cbmMCTrack->
GetPdgCode()) == 1000020030
301 || TMath::Abs(cbmMCTrack->
GetPdgCode()) == 1000020040))
309 const Double_t m2TOF[7] = {0.885, 0.245, 0.019479835, 0., 3.49, 7.83, 1.95};
314 Double_t sPLocal[7][5] = {
315 {0.056908, -0.0470572, 0.0216465, -0.0021016, 8.50396e-05},
316 {0.00943075, -0.00635429, 0.00998695, -0.00111527, 7.77811e-05},
317 {0.00176298, 0.00367263, 0.00308013, 0.000844013, -0.00010423},
318 {0.00218401, 0.00152391, 0.00895357, -0.000533423, 3.70326e-05},
319 {0.261491, -0.103121, 0.0247587, -0.00123286, 2.61731e-05},
320 {0.657274, -0.22355, 0.0430177, -0.0026822, 7.34146e-05},
321 {0.116525, -0.045522, 0.0151319, -0.000495545, 4.43144e-06}};
322 for (Int_t iSp = 0; iSp < 7; iSp++)
323 for (Int_t jSp = 0; jSp < 5; jSp++)
324 sP[iSp][jSp] = sPLocal[iSp][jSp];
329 Double_t sPLocal[7][5] = {
330 {0.0337428, -0.013939, 0.00567602, -0.000202229, 4.07531e-06},
331 {0.00717827, -0.00257353, 0.00389851, -9.83097e-05, 1.33011e-06},
332 {0.001348, 0.00220126, 0.0023619, 7.35395e-05, -4.06706e-06},
333 {0.00142972, 0.00308919, 0.00326995, 6.91715e-05, -2.44194e-06},
339 {0.657274, -0.22355, 0.0430177, -0.0026822, 7.34146e-05},
340 {0.116525, -0.045522, 0.0151319, -0.000495545, 4.43144e-06}};
341 for (Int_t iSp = 0; iSp < 7; iSp++)
342 for (Int_t jSp = 0; jSp < 5; jSp++)
343 sP[iSp][jSp] = sPLocal[iSp][jSp];
346 const Int_t PdgHypo[9] = {
347 2212, 321, 211, -11, 1000010029, 1000010030, 1000020030, -13, -19};
354 if (stsTrackIndex < 0)
continue;
356 Bool_t isElectronTRD = 0;
357 Bool_t isElectronRICH = 0;
358 Bool_t isElectron = 0;
365 stsPar->Momentum(mom);
367 Double_t p = mom.Mag();
368 Double_t pt = mom.Perp();
369 Double_t pz =
sqrt(p * p - pt * pt);
370 Int_t q = stsPar->GetQp() > 0 ? 1 : -1;
375 if (richIndex > -1) {
378 Double_t axisA = richRing->
GetAaxis();
379 Double_t axisB = richRing->
GetBaxis();
382 Double_t fMeanA = 4.95;
383 Double_t fMeanB = 4.54;
384 Double_t fRmsA = 0.30;
385 Double_t fRmsB = 0.22;
386 Double_t fRmsCoeff = 3.5;
387 Double_t fDistCut = 1.;
392 if (
fabs(axisA - fMeanA) < fRmsCoeff * fRmsA
393 &&
fabs(axisB - fMeanB) < fRmsCoeff * fRmsB
402 Double_t polAaxis = 5.64791 - 4.24077 / (p - 3.65494);
403 Double_t polBaxis = 5.41106 - 4.49902 / (p - 3.52450);
405 if (axisA < (fMeanA + fRmsCoeff * fRmsA) && axisA > polAaxis
406 && axisB < (fMeanB + fRmsCoeff * fRmsB) && axisB > polBaxis
421 if (trdTrack->
GetPidWkn() > 0.635) isElectronTRD = 1;
433 if (trdTrack->
GetPidANN() > 0.9) isElectronTRD = 1;
440 double dEdXTRD = 1e6;
447 for (Int_t iTRD = 0; iTRD < trdTrack->
GetNofHits(); iTRD++) {
453 dEdXTRD = 1e6 * pz / p * eloss / trdTrack->
GetNofHits();
459 vector<double> dEdxAllveto;
464 for (
int iHit = 0; iHit < cbmStsTrack->
GetNofStsHits(); ++iHit) {
465 bool frontVeto = kFALSE, backVeto = kFALSE;
469 double x,
y, z, xNext, yNext, zNext;
477 xNext = stsHitNext->
GetX();
478 yNext = stsHitNext->
GetY();
479 zNext = stsHitNext->
GetZ();
480 dr =
sqrt((xNext -
x) * (xNext -
x) + (yNext -
y) * (yNext -
y)
481 + (zNext - z) * (zNext - z))
490 if (!frontCluster || !backCluster) {
491 LOG(info) <<
"CbmKFParticleFinderPID: no front or back cluster";
496 for (
int iDigi = 0; iDigi < frontCluster->
GetNofDigis(); ++iDigi) {
502 for (
int iDigi = 0; iDigi < backCluster->
GetNofDigis(); ++iDigi) {
509 if (!frontVeto) dEdxAllveto.push_back((frontCluster->
GetCharge()) / dr);
510 if (!backVeto) dEdxAllveto.push_back((backCluster->
GetCharge()) / dr);
512 if (0 == frontVeto) nClustersWveto--;
513 if (0 == backVeto) nClustersWveto--;
515 float dEdXSTS = 1.e6;
516 if (dEdxAllveto.size() != 0) dEdXSTS =
vecMedian(dEdxAllveto);
522 if (muchIndex > -1) {
539 if (isElectronRICH && isElectronTRD) isElectron = 1;
541 if (
fTrdPIDMode == 0 && isElectronRICH) isElectron = 1;
542 }
else if (isElectronRICH)
549 if (!((l > 500.) && (l < 900.)))
continue;
551 if (!((l > 700.) && (l < 1500.)))
continue;
555 if (tofHitIndex >= 0) {
558 if (!tofHit)
continue;
564 if (!((time > 16.) && (time < 42.)))
continue;
566 if (!((time > 26.) && (time < 52.)))
continue;
569 p * p * (1. / ((l / time / 29.9792458) * (l / time / 29.9792458)) - 1.);
574 for (
int iSigma = 0; iSigma < 7; iSigma++) {
575 sigma[iSigma] = sP[iSigma][0] + sP[iSigma][1] * p
576 + sP[iSigma][2] * p * p + sP[iSigma][3] * p * p * p
577 + sP[iSigma][4] * p * p * p * p;
578 dm2[iSigma] =
fabs(m2 - m2TOF[iSigma]) / sigma[iSigma];
582 if (dm2[3] > 3.) isElectron = 0;
586 Double_t dm2min = dm2[2];
588 if (!isElectron && isMuon == 0) {
591 for (
int jPDG = 0; jPDG < 7; jPDG++) {
592 if (jPDG == 3)
continue;
593 if (dm2[jPDG] < dm2min) {
599 if (dm2min > 2) iPdg = -1;
601 Double_t dEdXTRDthresholdProton = 10.;
603 if (
fUseTRDdEdX && (dEdXTRD < dEdXTRDthresholdProton)) iPdg = 0;
607 if (iPdg > -1)
fPID[stsTrackIndex] = q * PdgHypo[iPdg];
611 if (isElectron)
fPID[stsTrackIndex] = q * PdgHypo[3];
613 if (isMuon == 1)
fPID[stsTrackIndex] = q * PdgHypo[7];
614 if (isMuon == 2)
fPID[stsTrackIndex] = q * PdgHypo[8];