CbmRoot
DataTreeCbmInterface.cxx
Go to the documentation of this file.
1 //TODO runid, eventid, vertex, fitter!, match in STS, constants
2 
3 #include "DataTreeCbmInterface.h"
4 #include <fstream>
5 #include <iostream>
6 #include <vector>
7 using std::cout;
8 using std::endl;
9 using std::ifstream;
10 using std::vector;
11 
12 #include "TDirectory.h"
13 #include "TROOT.h"
14 
15 #include "CbmDigiManager.h"
16 #include "CbmGlobalTrack.h"
17 #include "CbmMCTrack.h"
18 #include "CbmPsdDigi.h"
19 #include "CbmPsdHit.h"
20 #include "CbmPsdPoint.h"
21 #include "CbmStsTrack.h"
22 #include "CbmTofHit.h"
23 #include "CbmTrackMatchNew.h"
24 // #include "CbmTrackMatch.h"
25 
26 #include "FairMCEventHeader.h"
27 
28 //L1Algo tools
29 // #include "CbmL1.h"
30 // #include "L1Algo.h"
31 // #include "CbmL1Track.h"
32 // #include "L1TrackPar.h"
33 // #include "L1Station.h"
34 // #include "L1Extrapolation.h"
35 // #include "L1AddMaterial.h"
36 // #include "L1Filtration.h"
37 // #include "L1MaterialInfo.h"
38 #include "CbmKFTrack.h"
39 #include "CbmL1PFFitter.h"
40 
41 #include "CbmKFVertex.h"
42 #include "KFParticleTopoReconstructor.h"
43 #include "L1Field.h"
44 
45 #include "DataTreeConstants.h"
46 #include "DataTreeEvent.h"
47 #include "DataTreeTrack.h"
48 
49 #include <TGeoBBox.h>
50 
51 //=================================================================> MAIN <===============================================================
53  : FairTask("DataTreeCbmInterface", 1) {
54  fDTEvent = new DataTreeEvent();
55 }
57 
58 
59 //=================================================================> INIT <===============================================================
60 //----------------------------------
62  InitInput();
63  InitOutput();
64  return kSUCCESS;
65 }
66 
67 
68 void DataTreeCbmInterface::LoadGeo(const TString& geoFile) {
69  const char* fairGeom = "FAIRGeom";
70  const char* moduleNamePrefix = "module";
71 
72  TGeoManager* geoMan = TGeoManager::Import(geoFile.Data(), fairGeom);
73  TGeoNode* caveNode = geoMan->GetTopNode();
74  TGeoNode* psdNode = nullptr;
75  TString nodeName;
76 
77  for (int i = 0; i < caveNode->GetNdaughters(); i++) {
78  psdNode = caveNode->GetDaughter(i);
79  nodeName = psdNode->GetName();
80  if (nodeName.Contains("psd")) break;
81  }
82  std::cout << "-I- " << psdNode->GetName() << std::endl;
83 
84  auto psdGeoMatrix = psdNode->GetMatrix();
85  auto psdBox = (TGeoBBox*) psdNode->GetVolume()->GetShape();
86  TVector3 frontFaceLocal(0, 0, -psdBox->GetDZ());
87 
88  TVector3 frontFaceGlobal;
89  psdGeoMatrix->LocalToMaster(&frontFaceLocal[0], &frontFaceGlobal[0]);
90 
91  fPsdPosition = frontFaceGlobal;
92 
93  fPsdModules = 0;
94  fPsdModulePositions.clear();
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)) {
99 
100  auto geoMatrix = daughter->GetMatrix();
101  TVector3 translation(geoMatrix->GetTranslation());
102 
103  int modID = daughter->GetNumber();
104  double x = translation.X();
105  double y = translation.Y();
106 
107  std::cout << "mod" << modID << " : " << Form("(%.3f, %3f)", x, y)
108  << std::endl;
109  fPsdModulePositions.insert({modID, translation});
110  fPsdModules++;
111  }
112  }
113  std::cout << "-I- Number of PSD modules: " << fPsdModules << std::endl;
114  // Fix to avoid crash
115  if (gROOT->GetVersionInt() >= 60602) {
116  geoMan->GetListOfVolumes()->Delete();
117  geoMan->GetListOfShapes()->Delete();
118  }
119  delete geoMan;
120 }
121 
122 
123 //----------------------------------
125  FairRootManager* ioman = FairRootManager::Instance();
126  fPrimVtx = (CbmVertex*) ioman->GetObject("PrimaryVertex.");
127  if (!fPrimVtx) fPrimVtx = (CbmVertex*) ioman->GetObject("PrimaryVertex.");
128  fHeader = (FairMCEventHeader*) ioman->GetObject("MCEventHeader.");
129  flistPSDhit = (TClonesArray*) ioman->GetObject("PsdHit");
130  flistMCtrack = (TClonesArray*) ioman->GetObject("MCTrack");
131  flistSTSRECOtrack = (TClonesArray*) ioman->GetObject("StsTrack");
132  flistSTStrackMATCH = (TClonesArray*) ioman->GetObject("StsTrackMatch");
133  fGlobalTrackArray = (TClonesArray*) ioman->GetObject("GlobalTrack");
134  fTofHitArray = (TClonesArray*) ioman->GetObject("TofHit");
135  fTofHitMatchArray = (TClonesArray*) ioman->GetObject("TofHitMatch");
136  fPsdPointArray = (TClonesArray*) ioman->GetObject("PsdPoint");
138  fDigiMan->Init();
139 }
140 
141 //----------------------------------
143 
144 //--------------------------------------------------------------------------------------------------
146  for (int i = 0; i < fPsdModules; ++i)
147  fDTEvent->AddPSDModule(10);
148 }
149 
150 //--------------------------------------------------------------------------------------------------
152  fTreeFile = new TFile(fOutputFileName, "RECREATE");
153  fTreeFile->cd();
154  fDataTree = new TTree("DataTree", "DataTree");
155  fDataTree->Branch("DTEvent", &fDTEvent);
156 }
157 
158 //=================================================================> EXEC <===============================================================
159 void DataTreeCbmInterface::Exec(Option_t*) {
160  ClearEvent();
161 
163  ReadEvent();
164  ReadPSD();
165  ReadMC();
166  ReadTracks();
167  // LinkSTS();
168  ReadV0(0);
169  ReadV0(1);
170  ReadTOF();
172 
173  fDataTree->Fill();
174 }
175 //--------------------------------------------------------------------------------------------------
177  fMCTrackIDs.clear();
178  fTrackIDs.clear();
179  fDTEvent->ClearEvent();
180 }
181 
182 //--------------------------------------------------------------------------------------------------
184  if (!fHeader) {
185  cout << "No fHeader!" << endl;
186  return;
187  }
188 
189  fDTEvent->SetRPAngle(fHeader->GetRotZ());
190  fDTEvent->SetImpactParameter(fHeader->GetB());
191  fDTEvent->SetRunId(fHeader->GetRunID());
192  fDTEvent->SetEventId(fHeader->GetEventID());
193  fDTEvent->SetMCVertexPosition(
194  fHeader->GetX(), fHeader->GetY(), fHeader->GetZ());
195  if (!fPrimVtx) {
196  if (fPsdModules != 0) cout << "No fPrimVtx!" << endl;
197  return;
198  } else {
199  fDTEvent->SetVertexPosition(
200  fPrimVtx->GetX(), fPrimVtx->GetY(), fPrimVtx->GetZ());
201  fDTEvent->SetVertexQuality(fPrimVtx->GetChi2() / fPrimVtx->GetNDF(), 0);
202  }
203 
204  // KFParticle KFParticle_vtx_TOF = fFinderTOF->GetTopoReconstructor()->GetPrimVertex(0);
205  // fDTEvent -> SetVertexPosition (KFParticle_vtx_TOF.X(), KFParticle_vtx_TOF.Y(), KFParticle_vtx_TOF.Z(), 0);
206  // fDTEvent -> SetVertexQuality (KFParticle_vtx_TOF.Chi2() / KFParticle_vtx_TOF.NDF(), 0);
207  // KFParticle KFParticle_vtx_MC = fFinderMC->GetTopoReconstructor()->GetPrimVertex(0);
208  // fDTEvent -> SetVertexPosition (KFParticle_vtx_MC.X(), KFParticle_vtx_MC.Y(), KFParticle_vtx_MC.Z(), 1);
209  // fDTEvent -> SetVertexQuality (KFParticle_vtx_MC.Chi2() / KFParticle_vtx_MC.NDF(), 1);
210 }
211 
212 //--------------------------------------------------------------------------------------------------
214  if (!flistPSDhit) return;
215  const int nPSDhits = flistPSDhit->GetEntriesFast();
216 
217  for (int i = 0; i < fPsdModules; ++i) {
218  fDTEvent->GetPSDModule(i)->SetPosition(fPsdModulePositions[i].X(),
219  fPsdModulePositions[i].Y(),
220  fPsdModulePositions[i].Z());
221  }
222 
223  CbmPsdHit* hit {nullptr};
224  Float_t PsdEnergy {0.};
225 
226  for (int i = 0; i < nPSDhits; ++i) {
227  hit = (CbmPsdHit*) flistPSDhit->At(i);
228  if (hit == nullptr) continue;
229  fDTEvent->GetPSDModule(hit->GetModuleID() - 1)->SetEnergy(hit->GetEdep());
230  PsdEnergy += hit->GetEdep();
231  }
232 
233  fDTEvent->SetPsdEnergy(PsdEnergy);
234  fDTEvent->SetPsdPosition(
235  fPsdPosition.X(), fPsdPosition.Y(), fPsdPosition.Z());
236 
237  const int nPSDdigits = fDigiMan->GetNofDigis(ECbmModuleId::kPsd);
238  const CbmPsdDigi* digit {nullptr};
239  for (int i = 0; i < nPSDdigits; ++i) {
240  digit = fDigiMan->Get<CbmPsdDigi>(i);
241  if (digit == nullptr) continue;
242  fDTEvent->GetPSDModule(digit->GetModuleID() - 1)
243  ->GetSection(digit->GetSectionID() - 1)
244  ->AddEnergy(digit->GetEdep());
245  }
246 }
247 //--------------------------------------------------------------------------------------------------
249  Int_t nPoints = fPsdPointArray->GetEntriesFast();
250  for (Int_t iPoint = 0; iPoint < nPoints; iPoint++) {
251  CbmPsdPoint* point = (CbmPsdPoint*) fPsdPointArray->At(iPoint);
252  if (!point) {
253  cout << "No PSD point number " << iPoint << endl;
254  continue;
255  }
256  CbmMCTrack* mctrack = (CbmMCTrack*) flistMCtrack->At(point->GetTrackID());
257  if (!mctrack)
258  cout << "No MC track number " << point->GetTrackID()
259  << "matched to PSD point number " << iPoint << endl;
260  float mass;
261  const long int type = mctrack->GetPdgCode();
262  if (type < 10000)
263  mass = mctrack->GetMass();
264  else
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());
269 
270  DataTreePSDPrimaryParticle* psdParticle = fDTEvent->AddPSDPrimaryParticle();
271  psdParticle->SetMomentum(momentum);
272  psdParticle->SetPosition(position);
273  psdParticle->SetPdgID(mctrack->GetPdgCode());
274  psdParticle->SetType(mctrack->GetMotherId());
275  }
276 }
277 
278 //--------------------------------------------------------------------------------------------------
280  for (int i = 0; i < fDTEvent->GetNTracks(); ++i)
281  if (fDTEvent->GetTrack(i)->GetMCTrackId() == idx) return i;
282  return EnumGlobalConst::kUndefinedValue;
283 }
284 
285 //--------------------------------------------------------------------------------------------------
287  if (!flistMCtrack) return;
288  CbmMCTrack* mctrack {nullptr};
289  Float_t mass {0.};
290  Int_t charge {0};
291  TLorentzVector mom;
292 
293  const int nTracks = flistMCtrack->GetEntries();
294 
295  for (int i = 0; i < nTracks; ++i) {
296  mctrack = (CbmMCTrack*) flistMCtrack->At(i);
297  const int motherid = mctrack->GetMotherId();
298  // if (motherid != -1) continue;
299 
300  const long int type = mctrack->GetPdgCode();
301  if (type < 1000000000) {
302  charge = mctrack->GetCharge() / 3;
303  mass = mctrack->GetMass();
304  } else {
305  //pdg = 1000000000 + 10*1000*z + 10*a + i;
306  charge = type / 10000 % 1000;
307  mass = (type / 10 % 1000) * 0.931;
308  }
309 
310  mom.SetXYZM(mctrack->GetPx(), mctrack->GetPy(), mctrack->GetPz(), mass);
311 
312  fMCTrackIDs.push_back(i);
313  fDTEvent->AddMCTrack();
314  DataTreeMCTrack* DTMCTrack = fDTEvent->GetLastMCTrack();
315 
316  DTMCTrack->SetMomentum(mom);
317  DTMCTrack->SetCharge(charge);
318 
319  DTMCTrack->SetPdgId(type);
320  DTMCTrack->SetMotherId(motherid);
321 
322  // std::cout << GetMCTrackMatch(i) << std::endl;
323  // DTMCTrack->SetRecoTrackId( {GetMCTrackMatch(i)} );
324  }
325 }
326 
327 //--------------------------------------------------------------------------------------------------
329  if (!flistSTSRECOtrack) return;
330  std::cout << "ReadTracks" << std::endl;
331 
332  const Float_t mass = 0.14; // pion mass assumption to write TLorentzVector
333 
334  const Int_t nSTStracks = flistSTSRECOtrack->GetEntries();
335 
336  int nMCtracks = fDTEvent->GetNMCTracks();
337 
338  for (Int_t i = 0; i < nSTStracks; ++i) {
339  CbmStsTrack* track {nullptr};
340  CbmTrackMatchNew* match {nullptr};
341  Int_t mcTrackID {-999};
342  // CbmMCTrack* mctrack{nullptr}; (FU) unused
343  DataTreeTrack* DTTrack {nullptr};
344  DataTreeTrack* DTVertexTrack {nullptr};
345  const FairTrackParam* trackParam {nullptr};
346  DataTreeTrackParams Params;
347  TVector3 momRec;
348  TLorentzVector mom;
349  // std::cout << "i = " << i << std::endl;
350  track = (CbmStsTrack*) flistSTSRECOtrack->At(i);
351 
352  if (track == nullptr) {
353  cout << "ERROR: empty track!";
354  continue;
355  }
356 
357  fDTEvent->AddTrack();
358 
359  trackParam = track->GetParamFirst();
360  trackParam->Momentum(momRec);
361  const Int_t q = trackParam->GetQp() > 0 ? 1 : -1;
362 
363  mom.SetXYZM(momRec.X(), momRec.Y(), momRec.Z(), mass);
364 
365  DTTrack = fDTEvent->GetLastTrack();
366 
367  DTTrack->SetMomentum(mom);
368  DTTrack->SetId(i);
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);
374 
375  Params.SetMagFieldFit(0., 0., 0., 0., 0., 0., 0., 0., 0., 0.);
376 
377  std::vector<double> trackParametersValuesT = {trackParam->GetX(),
378  trackParam->GetY(),
379  trackParam->GetZ(),
380  trackParam->GetTx(),
381  trackParam->GetTy(),
382  trackParam->GetQp()};
383 
384  std::vector<double> covMatrixValuesT(25, 0.);
385 
386  // if (i==0)
387  // std::cout << "V: before " << momRec.X() << std::endl;
388 
389  Params.SetParameters(trackParametersValuesT);
390  Params.SetCovMatrix(covMatrixValuesT);
391  Params.SetPosition(
392  trackParam->GetX(), trackParam->GetY(), trackParam->GetZ());
393  DTTrack->SetParams(Params, EnumParamsPoint::kVertex);
394 
395  fTrackIDs.push_back(i);
396 
397 
398  // // // // // // // // // // // // // // // // // // // // // // //
399  // Vertex tracks
400  // // // // // // // // // // // // // // // // // // // // // // //
401 
402  vector<CbmStsTrack> vRTracks(1);
403  vRTracks[0] = *track;
404  CbmL1PFFitter fitter;
405  vector<float> vChiToPrimVtx;
406 
407  if (!fPrimVtx) continue;
408 
409  // CbmKFTrack kftrack(vRTracks[0]);
410  // kftrack.Extrapolate(fPrimVtx->GetZ());
411 
412  vector<L1FieldRegion> vField;
413  CbmKFVertex kfVertex = CbmKFVertex(*fPrimVtx);
414  std::vector<int> pdg = {211};
415  fitter.Fit(vRTracks, pdg);
416  fitter.GetChiToVertex(vRTracks, vField, vChiToPrimVtx, kfVertex, 100000.);
417 
418  // if (i==0)
419  {
420  // std::cout << vField.at(0).cx0 << " " << vField.at(0).cx1 << " " << vField.at(0).cx2 << std::endl;
421  // std::cout << vField.at(0).cy0 << " " << vField.at(0).cy1 << " " << vField.at(0).cy2 << std::endl;
422  // std::cout << vField.at(0).cz0 << " " << vField.at(0).cz1 << " " << vField.at(0).cz2 << std::endl;
423  // std::cout << vField.at(0).z0 << std::endl;
424  }
425 
426  fDTEvent->AddVertexTrack();
427  //
428  //BEGIN vertex point
429 
430  track = &(vRTracks[0]);
431 
432  trackParam = track->GetParamFirst();
433  trackParam->Momentum(momRec);
434 
435  //const float xyz[] = {0.,0.,0.};
436  //CbmKFParticle tmpPart(kftrack);
437  //tmpPart.TransportToPoint(xyz);
438 
439 
440  // if (i==0)
441  // std::cout << "V: after 1 " << momRec.X() << std::endl;
442  //std::cout << "V: after 2 " << kftrack.GetTrack()[2] << std::endl;
443 
444  mom.SetXYZM(momRec.X(), momRec.Y(), momRec.Z(), mass);
445 
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(),
455  trackParam->GetY() - fPrimVtx->GetY(),
456  trackParam->GetZ() - fPrimVtx->GetZ());
457 
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]));
468 
469  std::vector<double> trackParametersValues = {trackParam->GetX(),
470  trackParam->GetY(),
471  trackParam->GetZ(),
472  trackParam->GetTx(),
473  trackParam->GetTy(),
474  trackParam->GetQp()};
475 
476  DTVertexTrack->SetVtxChi2(vChiToPrimVtx[0]);
477 
478  std::vector<double> covMatrixValues(25, 0.);
479 
480  Params.SetParameters(trackParametersValues);
481  Params.SetCovMatrix(covMatrixValues);
482  Params.SetPosition(
483  trackParam->GetX(), trackParam->GetY(), trackParam->GetZ());
484 
485  DTVertexTrack->SetParams(Params, EnumParamsPoint::kVertex);
486  match = (CbmTrackMatchNew*) flistSTStrackMATCH->At(i);
487  if (match->GetNofLinks() > 0) {
488  mcTrackID = match->GetMatchedLink().GetIndex();
489  if (mcTrackID >= 0 && mcTrackID < nMCtracks) {
490  fDTEvent->AddTrackMatch(DTVertexTrack, fDTEvent->GetMCTrack(mcTrackID));
491  DTVertexTrack->SetMCTrackId(mcTrackID);
492  }
493  // else
494  // {
495  // cout << "Reco id = " << i;
496  // cout << "\tMC id = " << mcTrackID;
497  // cout << "\tnMCtracks = " << nMCtracks << endl;
498  // }
499  }
500  }
501 }
502 
503 //--------------------------------------------------------------------------------------------------
505  bool found = false;
506  // std::cout << "==================== MC" << std::endl;
507 
508  for (int i = 0; i < fDTEvent->GetNTracks(); ++i) {
509  found = false;
510  int j {0};
511  for (; j < fDTEvent->GetNMCTracks() && !found; j++) {
512  // std::cout<<j<<" "<<fMCTrackIDs.at(j)<<" " <<fDTEvent->GetTrack(i)->GetMCTrackId()<<" "<<fDTEvent->GetMCTrack(j)->GetId() <<std::endl;
513  if (fMCTrackIDs.at(j) == fDTEvent->GetTrack(i)->GetMCTrackId()) {
514  // std::cout<<"track id: "<<i<<"; before: " << fDTEvent->GetTrack(i)->GetMCTrackId()<<"; after: "<<j << std::endl;
515  found = true;
516  fDTEvent->GetTrack(i)->SetMCTrackId(j);
517  break;
518  }
519  }
520  if (found) {
521  fDTEvent->AddTrackMatch(fDTEvent->GetTrack(i), fDTEvent->GetMCTrack(j));
522  } else {
523  fDTEvent->GetTrack(i)->SetMCTrackId(EnumGlobalConst::kUndefinedValue);
524  }
525  }
526 }
527 
528 //--------------------------------------------------------------------------------------------------
530  if (!fGlobalTrackArray) return;
531  std::cout << "ReadTOF" << std::endl;
532 
533  for (Int_t igt = 0; igt < fGlobalTrackArray->GetEntries(); igt++) {
534  const CbmGlobalTrack* globalTrack =
535  static_cast<const CbmGlobalTrack*>(fGlobalTrackArray->At(igt));
536 
537  const Int_t stsTrackIndex = globalTrack->GetStsTrackIndex();
538  if (stsTrackIndex < 0) continue;
539 
540  CbmStsTrack* cbmStsTrack =
541  (CbmStsTrack*) flistSTSRECOtrack->At(stsTrackIndex);
542  const Int_t tofHitIndex = globalTrack->GetTofHitIndex();
543 
544  if (tofHitIndex < 0) continue;
545 
546  const CbmTofHit* tofHit =
547  static_cast<const CbmTofHit*>(fTofHitArray->At(tofHitIndex));
548  if (!tofHit) continue;
549 
550  const FairTrackParam* globalPar = globalTrack->GetParamLast();
551  TVector3 mom;
552  cbmStsTrack->GetParamFirst()->Momentum(mom);
553 
554  const Float_t p = mom.Mag();
555  const Int_t q = globalPar->GetQp() > 0 ? 1 : -1;
556  const Float_t l =
557  globalTrack->GetLength(); // l is calculated by global tracking
558 
559  const Float_t time = tofHit->GetTime();
560  const Float_t m2 =
561  p * p
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();
566 
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;
571 
572  const Float_t trackX =
573  globalPar->GetX() + Tx * dz; //extrapolation to TOF hit
574  const Float_t trackY = globalPar->GetY() + Ty * dz;
575 
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);
583 
584 
585  Int_t iTrk = 0;
586  for (; iTrk < fDTEvent->GetNTracks(); iTrk++) {
587  if (stsTrackIndex >= 0
588  && fDTEvent->GetTrack(iTrk)->GetId() == UInt_t(stsTrackIndex))
589  break;
590  }
591  if (iTrk == fDTEvent->GetNTracks()) continue;
592 
593  DTTOFHit->AddRecoTrackId(iTrk);
594 
595  DataTreeTrackParams par;
596  par.SetPosition(trackX, trackY, hitZ); //extrapolated to hit
597 
598  // std::cout << "X : " << hitX << " " << globalPar->GetX() << " " << trackX << std::endl;
599  // std::cout << "Z : " << hitZ << " " << trackZ << " " << Tx * dz << std::endl;
600 
601  DataTreeTrack* track = fDTEvent->GetTrack(iTrk);
602  track->SetLength(l);
603  track->SetTOFHitId(fDTEvent->GetNTOFHits() - 1);
604  track->SetParams(par, EnumParamsPoint::kTof);
605 
606  DataTreeTrack* vtrack = fDTEvent->GetVertexTrack(iTrk);
607  vtrack->SetLength(l);
608  vtrack->SetTOFHitId(fDTEvent->GetNTOFHits() - 1);
609  vtrack->SetParams(par, EnumParamsPoint::kTof);
610  }
611 }
612 
613 //--------------------------------------------------------------------------------------------------
614 void DataTreeCbmInterface::ReadV0(const int UseMCpid) {
615  const KFParticleTopoReconstructor* topo_rec;
616  if (UseMCpid) topo_rec = fFinderMC->GetTopoReconstructor();
617  if (!UseMCpid) topo_rec = fFinderTOF->GetTopoReconstructor();
618 
619  if (!topo_rec) {
620  cout
621  << "DataTreeCbmInterface::ReadV0: ERROR: no KFParticleTopoReconstructor!"
622  << endl;
623  return;
624  }
625  TLorentzVector mom;
626 
627  // cout << "DataTreeCbmInterface::ReadV0 1" << endl;
628 
629  const int ConstNV0Types = fDTEvent->GetNV0Types();
630 
631  int V0Mult[ConstNV0Types];
632  for (int i = 0; i < ConstNV0Types; ++i) {
633  V0Mult[i] = 0;
634  }
635 
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)) {
640  accept_V0 = true;
641  V0Mult[i]++;
642  }
643  }
644  if (!accept_V0) continue;
645 
646  const KFParticle& V0 = topo_rec->GetParticles()[iP];
647  DataTreeV0Candidate* V0Candidate;
648  if (!UseMCpid) { V0Candidate = fDTEvent->AddV0CandidateTOFpid(); }
649  if (UseMCpid) { V0Candidate = fDTEvent->AddV0CandidateMCpid(); }
650  if (!V0Candidate)
651  cout << "DataTreeCbmInterface::ReadV0_TOF: ERROR: no V0Candidate!"
652  << endl;
653 
654  mom.SetXYZM(V0.GetPx(), V0.GetPy(), V0.GetPz(), V0.GetMass());
655 
656  V0Candidate->SetMomentum(mom);
657  V0Candidate->SetPdgId(V0.GetPDG());
658  V0Candidate->SetChi2(V0.GetChi2());
659  V0Candidate->SetCharge((int) V0.GetQ());
660 
661  if (V0.NDaughters() != 2) {
662  printf("Number of daughters not %d (%d)!\n", 2, V0.NDaughters());
663  continue;
664  }
665 
666  for (int iDaughter = 0; iDaughter < V0.NDaughters(); iDaughter++) {
667  const int daugherIndex = V0.DaughterIds()[iDaughter];
668  const KFParticle& daughter = topo_rec->GetParticles()[daugherIndex];
669 
670  V0Candidate->AddDaughter();
671  DataTreeV0Candidate* Daughter = V0Candidate->GetDaughter(iDaughter);
672 
673  mom.SetXYZM(daughter.GetPx(),
674  daughter.GetPy(),
675  daughter.GetPz(),
676  daughter.GetMass());
677 
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]);
683  }
684  }
685  }
686  int V0Mult_All = 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];
691  }
692 
693  if (!UseMCpid) { fDTEvent->SetNV0CandidatesTOFpid(V0Mult_All); }
694  if (UseMCpid) { fDTEvent->SetNV0CandidatesMCpid(V0Mult_All); }
695 }
696 
697 //================================================================> FINISH <==============================================================
699  cout << "DataTreeCbmInterface::Finish" << endl;
700  fDataTree->Write();
701  fTreeFile->Write();
702  fTreeFile->Close();
703 }
704 
DataTreeCbmInterface::InitOutput
void InitOutput()
Definition: DataTreeCbmInterface.cxx:142
DataTreeCbmInterface::LinkSTS
void LinkSTS()
Definition: DataTreeCbmInterface.cxx:504
CbmHit::GetZ
Double_t GetZ() const
Definition: CbmHit.h:70
CbmMCTrack::GetMotherId
Int_t GetMotherId() const
Definition: CbmMCTrack.h:71
DataTreeCbmInterface::flistPSDhit
TClonesArray * flistPSDhit
Definition: DataTreeCbmInterface.h:81
CbmMCTrack::GetMass
Double_t GetMass() const
Mass of the associated particle.
Definition: CbmMCTrack.cxx:114
DataTreeCbmInterface::ClearEvent
void ClearEvent()
Definition: DataTreeCbmInterface.cxx:176
CbmPsdPoint
Definition: CbmPsdPoint.h:24
CbmPixelHit::GetX
Double_t GetX() const
Definition: CbmPixelHit.h:83
DataTreeCbmInterface::~DataTreeCbmInterface
~DataTreeCbmInterface()
Definition: DataTreeCbmInterface.cxx:56
CbmPsdDigi.h
DataTreeCbmInterface::Exec
virtual void Exec(Option_t *opt)
Definition: DataTreeCbmInterface.cxx:159
DataTreeCbmInterface::fPrimVtx
CbmVertex * fPrimVtx
Definition: DataTreeCbmInterface.h:78
CbmPsdHit.h
CbmPixelHit::GetY
Double_t GetY() const
Definition: CbmPixelHit.h:84
L1Field.h
CbmL1PFFitter
Definition: CbmL1PFFitter.h:31
CbmL1PFFitter::Fit
void Fit(std::vector< CbmStsTrack > &Tracks, std::vector< int > &pidHypo)
Definition: CbmL1PFFitter.cxx:81
CbmDigiManager::Init
InitStatus Init()
Initialisation.
Definition: CbmDigiManager.cxx:71
CbmGlobalTrack::GetParamLast
const FairTrackParam * GetParamLast() const
Definition: CbmGlobalTrack.h:44
DataTreeCbmInterface::fTofHitMatchArray
TClonesArray * fTofHitMatchArray
Definition: DataTreeCbmInterface.h:87
CbmMCTrack::GetPdgCode
Int_t GetPdgCode() const
Definition: CbmMCTrack.h:70
i
int i
Definition: L1/vectors/P4_F32vec4.h:25
DataTreeCbmInterface::GetMCTrackMatch
int GetMCTrackMatch(const int idx)
Definition: DataTreeCbmInterface.cxx:279
DataTreeCbmInterface::fTrackIDs
std::vector< int > fTrackIDs
Definition: DataTreeCbmInterface.h:98
DataTreeCbmInterface::fTreeFile
TFile * fTreeFile
Definition: DataTreeCbmInterface.h:75
CbmGlobalTrack.h
CbmDigiManager::GetNofDigis
static Int_t GetNofDigis(ECbmModuleId systemId)
Definition: CbmDigiManager.cxx:62
CbmGlobalTrack::GetLength
Double_t GetLength() const
Definition: CbmGlobalTrack.h:50
DataTreeCbmInterface::Init
virtual InitStatus Init()
Definition: DataTreeCbmInterface.cxx:61
DataTreeCbmInterface::ReadMC
void ReadMC()
Definition: DataTreeCbmInterface.cxx:286
DataTreeCbmInterface::fFinderTOF
const CbmKFParticleFinder * fFinderTOF
Definition: DataTreeCbmInterface.h:100
DataTreeCbmInterface::Finish
virtual void Finish()
Definition: DataTreeCbmInterface.cxx:698
CbmVertex::GetX
Double_t GetX() const
Definition: CbmVertex.h:68
CbmVertex::GetChi2
Double_t GetChi2() const
Definition: CbmVertex.h:71
DataTreeCbmInterface::fOutputFileName
TString fOutputFileName
Definition: DataTreeCbmInterface.h:74
DataTreeCbmInterface::ReadTracks
void ReadTracks()
Definition: DataTreeCbmInterface.cxx:328
CbmDigiManager::Instance
static CbmDigiManager * Instance()
Static instance.
Definition: CbmDigiManager.h:93
DataTreeCbmInterface::InitInput
void InitInput()
Definition: DataTreeCbmInterface.cxx:124
DataTreeCbmInterface::fDTEvent
DataTreeEvent * fDTEvent
Definition: DataTreeCbmInterface.h:90
DataTreeCbmInterface::ReadPsdPrimaryParticles
void ReadPsdPrimaryParticles()
Definition: DataTreeCbmInterface.cxx:248
CbmStsTrack.h
Data class for STS tracks.
CbmGlobalTrack::GetStsTrackIndex
Int_t GetStsTrackIndex() const
Definition: CbmGlobalTrack.h:38
DataTreeCbmInterface::ReadV0
void ReadV0(const int UseMCpid=0)
Definition: DataTreeCbmInterface.cxx:614
DataTreeCbmInterface::fMCTrackIDs
std::vector< int > fMCTrackIDs
Definition: DataTreeCbmInterface.h:97
CbmL1PFFitter::GetChiToVertex
void GetChiToVertex(std::vector< CbmStsTrack > &Tracks, std::vector< L1FieldRegion > &field, std::vector< float > &chiToVtx, CbmKFVertex &primVtx, float chiPrim=-1)
Definition: CbmL1PFFitter.cxx:403
DataTreeCbmInterface
Definition: DataTreeCbmInterface.h:37
DataTreeCbmInterface::flistSTSRECOtrack
TClonesArray * flistSTSRECOtrack
Definition: DataTreeCbmInterface.h:83
CbmDigiManager::Get
const Digi * Get(Int_t index) const
Get a digi object.
Definition: CbmDigiManager.h:52
CbmHit::GetTime
Double_t GetTime() const
Definition: CbmHit.h:75
CbmTrackMatchNew.h
DataTreeCbmInterface::fPsdModulePositions
std::map< int, TVector3 > fPsdModulePositions
Definition: DataTreeCbmInterface.h:94
CbmVertex
Definition: CbmVertex.h:26
DataTreeCbmInterface.h
CbmL1PFFitter.h
DataTreeCbmInterface::InitOutputTree
void InitOutputTree()
Definition: DataTreeCbmInterface.cxx:151
DataTreeCbmInterface::LoadGeo
void LoadGeo(const TString &geoFile)
Definition: DataTreeCbmInterface.cxx:68
CbmVertex::GetZ
Double_t GetZ() const
Definition: CbmVertex.h:70
ClassImp
ClassImp(CbmConverterManager) InitStatus CbmConverterManager
Definition: CbmConverterManager.cxx:12
CbmKFTrack.h
DataTreeCbmInterface::ReadTOF
void ReadTOF()
Definition: DataTreeCbmInterface.cxx:529
CbmTrack::GetParamFirst
const FairTrackParam * GetParamFirst() const
Definition: CbmTrack.h:61
DataTreeCbmInterface::fDigiMan
CbmDigiManager * fDigiMan
Definition: DataTreeCbmInterface.h:80
DataTreeCbmInterface::fDataTree
TTree * fDataTree
Definition: DataTreeCbmInterface.h:76
DataTreeCbmInterface::InitDataTreeEvent
void InitDataTreeEvent()
Definition: DataTreeCbmInterface.cxx:145
DataTreeCbmInterface::fHeader
FairMCEventHeader * fHeader
Definition: DataTreeCbmInterface.h:79
CbmGlobalTrack
Definition: CbmGlobalTrack.h:26
DataTreeCbmInterface::fPsdPointArray
TClonesArray * fPsdPointArray
Definition: DataTreeCbmInterface.h:88
DataTreeCbmInterface::fPsdPosition
TVector3 fPsdPosition
Definition: DataTreeCbmInterface.h:93
CbmMCTrack.h
CbmDigiManager.h
CbmKFParticleFinder::GetTopoReconstructor
const KFParticleTopoReconstructor * GetTopoReconstructor() const
Definition: CbmKFParticleFinder.h:46
CbmVertex::GetY
Double_t GetY() const
Definition: CbmVertex.h:69
CbmMCTrack
Definition: CbmMCTrack.h:34
x
Double_t x
Definition: CbmMvdSensorDigiToHitTask.cxx:68
DataTreeCbmInterface::fGlobalTrackArray
TClonesArray * fGlobalTrackArray
Definition: DataTreeCbmInterface.h:85
DataTreeCbmInterface::fTofHitArray
TClonesArray * fTofHitArray
Definition: DataTreeCbmInterface.h:86
y
Double_t y
Definition: CbmMvdSensorDigiToHitTask.cxx:68
CbmTrackMatchNew
Definition: CbmTrackMatchNew.h:19
DataTreeCbmInterface::fFinderMC
const CbmKFParticleFinder * fFinderMC
Definition: DataTreeCbmInterface.h:101
ECbmModuleId::kPsd
@ kPsd
Projectile spectator detector.
CbmTofHit
Definition: core/data/tof/CbmTofHit.h:26
DataTreeCbmInterface::ReadPSD
void ReadPSD()
Definition: DataTreeCbmInterface.cxx:213
CbmGlobalTrack::GetTofHitIndex
Int_t GetTofHitIndex() const
Definition: CbmGlobalTrack.h:42
DataTreeCbmInterface::flistSTStrackMATCH
TClonesArray * flistSTStrackMATCH
Definition: DataTreeCbmInterface.h:84
CbmPsdDigi
Data class for PSD digital information.
Definition: CbmPsdDigi.h:31
DataTreeCbmInterface::flistMCtrack
TClonesArray * flistMCtrack
Definition: DataTreeCbmInterface.h:82
CbmVertex::GetNDF
Int_t GetNDF() const
Definition: CbmVertex.h:72
CbmStsTrack
Definition: CbmStsTrack.h:37
DataTreeCbmInterface::fPsdModules
int fPsdModules
Definition: DataTreeCbmInterface.h:92
CbmKFVertex.h
DataTreeCbmInterface::DataTreeCbmInterface
DataTreeCbmInterface()
Definition: DataTreeCbmInterface.cxx:52
CbmKFVertex
Definition: CbmKFVertex.h:6
CbmPsdPoint.h
DataTreeCbmInterface::ReadEvent
void ReadEvent()
Definition: DataTreeCbmInterface.cxx:183
CbmPsdHit
Definition: CbmPsdHit.h:20