12 #include "TDirectory.h"
22 #include "CbmTofHit.h"
26 #include "FairMCEventHeader.h"
42 #include "KFParticleTopoReconstructor.h"
45 #include "DataTreeConstants.h"
46 #include "DataTreeEvent.h"
47 #include "DataTreeTrack.h"
53 : FairTask(
"DataTreeCbmInterface", 1) {
69 const char* fairGeom =
"FAIRGeom";
70 const char* moduleNamePrefix =
"module";
72 TGeoManager* geoMan = TGeoManager::Import(geoFile.Data(), fairGeom);
73 TGeoNode* caveNode = geoMan->GetTopNode();
74 TGeoNode* psdNode =
nullptr;
77 for (
int i = 0;
i < caveNode->GetNdaughters();
i++) {
78 psdNode = caveNode->GetDaughter(
i);
79 nodeName = psdNode->GetName();
80 if (nodeName.Contains(
"psd"))
break;
82 std::cout <<
"-I- " << psdNode->GetName() << std::endl;
84 auto psdGeoMatrix = psdNode->GetMatrix();
85 auto psdBox = (TGeoBBox*) psdNode->GetVolume()->GetShape();
86 TVector3 frontFaceLocal(0, 0, -psdBox->GetDZ());
88 TVector3 frontFaceGlobal;
89 psdGeoMatrix->LocalToMaster(&frontFaceLocal[0], &frontFaceGlobal[0]);
95 for (
int i_d = 0; i_d < psdNode->GetNdaughters(); ++i_d) {
96 auto* daughter = psdNode->GetDaughter(i_d);
97 TString daughterName(daughter->GetName());
98 if (daughterName.BeginsWith(moduleNamePrefix)) {
100 auto geoMatrix = daughter->GetMatrix();
101 TVector3 translation(geoMatrix->GetTranslation());
103 int modID = daughter->GetNumber();
104 double x = translation.X();
105 double y = translation.Y();
107 std::cout <<
"mod" << modID <<
" : " << Form(
"(%.3f, %3f)",
x,
y)
113 std::cout <<
"-I- Number of PSD modules: " <<
fPsdModules << std::endl;
115 if (gROOT->GetVersionInt() >= 60602) {
116 geoMan->GetListOfVolumes()->Delete();
117 geoMan->GetListOfShapes()->Delete();
125 FairRootManager* ioman = FairRootManager::Instance();
128 fHeader = (FairMCEventHeader*) ioman->GetObject(
"MCEventHeader.");
129 flistPSDhit = (TClonesArray*) ioman->GetObject(
"PsdHit");
130 flistMCtrack = (TClonesArray*) ioman->GetObject(
"MCTrack");
134 fTofHitArray = (TClonesArray*) ioman->GetObject(
"TofHit");
154 fDataTree =
new TTree(
"DataTree",
"DataTree");
185 cout <<
"No fHeader!" << endl;
196 if (
fPsdModules != 0) cout <<
"No fPrimVtx!" << endl;
215 const int nPSDhits =
flistPSDhit->GetEntriesFast();
224 Float_t PsdEnergy {0.};
226 for (
int i = 0;
i < nPSDhits; ++
i) {
228 if (hit ==
nullptr)
continue;
229 fDTEvent->GetPSDModule(hit->GetModuleID() - 1)->SetEnergy(hit->GetEdep());
230 PsdEnergy += hit->GetEdep();
239 for (
int i = 0;
i < nPSDdigits; ++
i) {
241 if (digit ==
nullptr)
continue;
242 fDTEvent->GetPSDModule(digit->GetModuleID() - 1)
243 ->GetSection(digit->GetSectionID() - 1)
244 ->AddEnergy(digit->GetEdep());
250 for (Int_t iPoint = 0; iPoint < nPoints; iPoint++) {
253 cout <<
"No PSD point number " << iPoint << endl;
258 cout <<
"No MC track number " << point->GetTrackID()
259 <<
"matched to PSD point number " << iPoint << endl;
265 mass = (type / 10 % 1000) * 0.931;
266 TLorentzVector momentum;
267 momentum.SetXYZM(point->GetPx(), point->GetPy(), point->GetPz(), mass);
268 TVector3 position(point->GetX(), point->GetY(), point->GetZ());
270 DataTreePSDPrimaryParticle* psdParticle =
fDTEvent->AddPSDPrimaryParticle();
271 psdParticle->SetMomentum(momentum);
272 psdParticle->SetPosition(position);
281 if (
fDTEvent->GetTrack(
i)->GetMCTrackId() == idx)
return i;
282 return EnumGlobalConst::kUndefinedValue;
295 for (
int i = 0;
i < nTracks; ++
i) {
297 const int motherid = mctrack->GetMotherId();
300 const long int type = mctrack->GetPdgCode();
301 if (type < 1000000000) {
302 charge = mctrack->GetCharge() / 3;
303 mass = mctrack->GetMass();
306 charge = type / 10000 % 1000;
307 mass = (type / 10 % 1000) * 0.931;
310 mom.SetXYZM(mctrack->GetPx(), mctrack->GetPy(), mctrack->GetPz(), mass);
314 DataTreeMCTrack* DTMCTrack =
fDTEvent->GetLastMCTrack();
316 DTMCTrack->SetMomentum(mom);
317 DTMCTrack->SetCharge(charge);
319 DTMCTrack->SetPdgId(type);
320 DTMCTrack->SetMotherId(motherid);
330 std::cout <<
"ReadTracks" << std::endl;
332 const Float_t mass = 0.14;
336 int nMCtracks =
fDTEvent->GetNMCTracks();
338 for (Int_t
i = 0;
i < nSTStracks; ++
i) {
341 Int_t mcTrackID {-999};
343 DataTreeTrack* DTTrack {
nullptr};
344 DataTreeTrack* DTVertexTrack {
nullptr};
345 const FairTrackParam* trackParam {
nullptr};
346 DataTreeTrackParams Params;
352 if (track ==
nullptr) {
353 cout <<
"ERROR: empty track!";
359 trackParam = track->GetParamFirst();
360 trackParam->Momentum(momRec);
361 const Int_t q = trackParam->GetQp() > 0 ? 1 : -1;
363 mom.SetXYZM(momRec.X(), momRec.Y(), momRec.Z(), mass);
367 DTTrack->SetMomentum(mom);
369 DTTrack->SetNumberOfHits(track->GetNofHits(), 0);
370 DTTrack->SetFlag(track->GetFlag());
371 DTTrack->SetChi2(track->GetChiSq());
372 DTTrack->SetNDF(track->GetNDF());
373 DTTrack->SetCharge(q);
375 Params.SetMagFieldFit(0., 0., 0., 0., 0., 0., 0., 0., 0., 0.);
377 std::vector<double> trackParametersValuesT = {trackParam->GetX(),
382 trackParam->GetQp()};
384 std::vector<double> covMatrixValuesT(25, 0.);
389 Params.SetParameters(trackParametersValuesT);
390 Params.SetCovMatrix(covMatrixValuesT);
392 trackParam->GetX(), trackParam->GetY(), trackParam->GetZ());
393 DTTrack->SetParams(Params, EnumParamsPoint::kVertex);
402 vector<CbmStsTrack> vRTracks(1);
403 vRTracks[0] = *track;
405 vector<float> vChiToPrimVtx;
412 vector<L1FieldRegion> vField;
414 std::vector<int> pdg = {211};
415 fitter.
Fit(vRTracks, pdg);
416 fitter.
GetChiToVertex(vRTracks, vField, vChiToPrimVtx, kfVertex, 100000.);
430 track = &(vRTracks[0]);
432 trackParam = track->GetParamFirst();
433 trackParam->Momentum(momRec);
444 mom.SetXYZM(momRec.X(), momRec.Y(), momRec.Z(), mass);
446 DTVertexTrack =
fDTEvent->GetLastVertexTrack();
447 DTVertexTrack->SetId(
i);
448 DTVertexTrack->SetMomentum(mom);
449 DTVertexTrack->SetFlag(track->GetFlag());
450 DTVertexTrack->SetChi2(track->GetChiSq());
451 DTVertexTrack->SetNDF(track->GetNDF());
452 DTVertexTrack->SetNumberOfHits(track->GetNofHits(), 0);
453 DTVertexTrack->SetCharge(q);
454 DTVertexTrack->SetDCA(trackParam->GetX() -
fPrimVtx->
GetX(),
458 Params.SetMagFieldFit(
float(vField.at(0).cx0[0]),
459 float(vField.at(0).cx1[0]),
460 float(vField.at(0).cx2[0]),
461 float(vField.at(0).cy0[0]),
462 float(vField.at(0).cy1[0]),
463 float(vField.at(0).cy2[0]),
464 float(vField.at(0).cz0[0]),
465 float(vField.at(0).cz1[0]),
466 float(vField.at(0).cz2[0]),
467 float(vField.at(0).z0[0]));
469 std::vector<double> trackParametersValues = {trackParam->GetX(),
474 trackParam->GetQp()};
476 DTVertexTrack->SetVtxChi2(vChiToPrimVtx[0]);
478 std::vector<double> covMatrixValues(25, 0.);
480 Params.SetParameters(trackParametersValues);
481 Params.SetCovMatrix(covMatrixValues);
483 trackParam->GetX(), trackParam->GetY(), trackParam->GetZ());
485 DTVertexTrack->SetParams(Params, EnumParamsPoint::kVertex);
487 if (match->GetNofLinks() > 0) {
488 mcTrackID = match->GetMatchedLink().GetIndex();
489 if (mcTrackID >= 0 && mcTrackID < nMCtracks) {
491 DTVertexTrack->SetMCTrackId(mcTrackID);
511 for (; j <
fDTEvent->GetNMCTracks() && !found; j++) {
523 fDTEvent->GetTrack(
i)->SetMCTrackId(EnumGlobalConst::kUndefinedValue);
531 std::cout <<
"ReadTOF" << std::endl;
538 if (stsTrackIndex < 0)
continue;
544 if (tofHitIndex < 0)
continue;
548 if (!tofHit)
continue;
550 const FairTrackParam* globalPar = globalTrack->
GetParamLast();
554 const Float_t p = mom.Mag();
555 const Int_t q = globalPar->GetQp() > 0 ? 1 : -1;
559 const Float_t time = tofHit->
GetTime();
562 * (1. / ((l / time / SpeedOfLight) * (l / time / SpeedOfLight)) - 1.);
563 const Float_t hitX = tofHit->
GetX();
564 const Float_t hitY = tofHit->
GetY();
565 const Float_t hitZ = tofHit->
GetZ();
567 const Float_t Tx = globalPar->GetTx();
568 const Float_t Ty = globalPar->GetTy();
569 const Float_t trackZ = globalPar->GetZ();
570 const Float_t dz = hitZ - trackZ;
572 const Float_t trackX =
573 globalPar->GetX() + Tx * dz;
574 const Float_t trackY = globalPar->GetY() + Ty * dz;
576 DataTreeTOFHit* DTTOFHit =
fDTEvent->AddTOFHit();
577 DTTOFHit->SetId(tofHitIndex);
578 DTTOFHit->SetPosition(hitX, hitY, hitZ);
579 DTTOFHit->SetTime(time);
580 DTTOFHit->SetPathLength(l);
581 DTTOFHit->SetCharge(q);
582 DTTOFHit->SetSquaredMass(m2);
586 for (; iTrk <
fDTEvent->GetNTracks(); iTrk++) {
587 if (stsTrackIndex >= 0
588 &&
fDTEvent->GetTrack(iTrk)->GetId() == UInt_t(stsTrackIndex))
591 if (iTrk ==
fDTEvent->GetNTracks())
continue;
593 DTTOFHit->AddRecoTrackId(iTrk);
595 DataTreeTrackParams par;
596 par.SetPosition(trackX, trackY, hitZ);
601 DataTreeTrack* track =
fDTEvent->GetTrack(iTrk);
603 track->SetTOFHitId(
fDTEvent->GetNTOFHits() - 1);
604 track->SetParams(par, EnumParamsPoint::kTof);
606 DataTreeTrack* vtrack =
fDTEvent->GetVertexTrack(iTrk);
607 vtrack->SetLength(l);
608 vtrack->SetTOFHitId(
fDTEvent->GetNTOFHits() - 1);
609 vtrack->SetParams(par, EnumParamsPoint::kTof);
615 const KFParticleTopoReconstructor* topo_rec;
621 <<
"DataTreeCbmInterface::ReadV0: ERROR: no KFParticleTopoReconstructor!"
629 const int ConstNV0Types =
fDTEvent->GetNV0Types();
631 int V0Mult[ConstNV0Types];
632 for (
int i = 0;
i < ConstNV0Types; ++
i) {
636 for (
unsigned int iP = 0; iP < topo_rec->GetParticles().size(); iP++) {
637 bool accept_V0 =
false;
638 for (
int i = 0;
i < ConstNV0Types; ++
i) {
639 if (topo_rec->GetParticles()[iP].GetPDG() ==
fDTEvent->GetNV0Pdg(
i)) {
644 if (!accept_V0)
continue;
646 const KFParticle& V0 = topo_rec->GetParticles()[iP];
647 DataTreeV0Candidate* V0Candidate;
648 if (!UseMCpid) { V0Candidate =
fDTEvent->AddV0CandidateTOFpid(); }
649 if (UseMCpid) { V0Candidate =
fDTEvent->AddV0CandidateMCpid(); }
651 cout <<
"DataTreeCbmInterface::ReadV0_TOF: ERROR: no V0Candidate!"
654 mom.SetXYZM(V0.GetPx(), V0.GetPy(), V0.GetPz(), V0.GetMass());
656 V0Candidate->SetMomentum(mom);
657 V0Candidate->SetPdgId(V0.GetPDG());
658 V0Candidate->SetChi2(V0.GetChi2());
659 V0Candidate->SetCharge((
int) V0.GetQ());
661 if (V0.NDaughters() != 2) {
662 printf(
"Number of daughters not %d (%d)!\n", 2, V0.NDaughters());
666 for (
int iDaughter = 0; iDaughter < V0.NDaughters(); iDaughter++) {
667 const int daugherIndex = V0.DaughterIds()[iDaughter];
668 const KFParticle& daughter = topo_rec->GetParticles()[daugherIndex];
670 V0Candidate->AddDaughter();
671 DataTreeV0Candidate* Daughter = V0Candidate->GetDaughter(iDaughter);
673 mom.SetXYZM(daughter.GetPx(),
678 Daughter->SetMomentum(mom);
679 Daughter->SetPdgId(daughter.GetPDG());
680 Daughter->SetChi2(daughter.GetChi2());
681 if (daughter.NDaughters() == 1) {
682 Daughter->SetTrackId(daughter.DaughterIds()[0]);
687 for (
int i = 0;
i < ConstNV0Types; ++
i) {
688 if (!UseMCpid) {
fDTEvent->SetNV0SpecificCandidatesTOFpid(
i, V0Mult[
i]); }
689 if (UseMCpid) {
fDTEvent->SetNV0SpecificCandidatesMCpid(
i, V0Mult[
i]); }
690 V0Mult_All += V0Mult[
i];
693 if (!UseMCpid) {
fDTEvent->SetNV0CandidatesTOFpid(V0Mult_All); }
694 if (UseMCpid) {
fDTEvent->SetNV0CandidatesMCpid(V0Mult_All); }
699 cout <<
"DataTreeCbmInterface::Finish" << endl;