CbmRoot
CbmTofHitsConverter.cxx
Go to the documentation of this file.
1 #include <cassert>
2 #include <vector>
3 
4 #include "TClonesArray.h"
5 
6 #include <FairMCPoint.h>
7 #include <FairRootManager.h>
8 
9 #include "AnalysisTree/Matching.hpp"
10 
11 #include <CbmGlobalTrack.h>
12 #include <CbmMCTrack.h>
13 #include <CbmTofHit.h>
14 #include <CbmTrackMatchNew.h>
15 
16 #include "CbmTofHitsConverter.h"
17 
19 
20  void CbmTofHitsConverter::Init(std::map<std::string, void*>&) {
21 
22  assert(!in_branches_.empty() && !out_branch_.empty() && out_config_
23  && out_tree_);
24  auto* ioman = FairRootManager::Instance();
25 
26  cbm_tof_hits_ = (TClonesArray*) ioman->GetObject("TofHit");
27  cbm_global_tracks_ = (TClonesArray*) ioman->GetObject("GlobalTrack");
28  // cbm_tof_match_ = (TClonesArray*) ioman->GetObject("TofHitMatch");
29  // cbm_tof_points_ = (TClonesArray*) ioman->GetObject("TofPoint");
30  // cbm_mc_tracks_ = (TClonesArray*) ioman->GetObject("MCTrack");
31  // cbm_sts_match_ = (TClonesArray*) ioman->GetObject("StsTrackMatch");
32 
33  AnalysisTree::BranchConfig tof_branch("TofHits", AnalysisTree::DetType::kHit);
34  tof_branch.AddField<float>("mass2");
35  tof_branch.AddField<float>("l");
36  tof_branch.AddField<float>("t");
37  tof_branch.AddField<float>("qp_tof");
38  tof_branch.AddFields<float>({"dx", "dy", "dz"});
39  tof_branch.AddField<int>("mc_pdg");
40  tof_branch.AddField<bool>("is_correct_match");
41  out_config_->AddBranchConfig(std::move(tof_branch));
42  tof_hits_ = new AnalysisTree::HitDetector(out_config_->GetLastId());
43 
44  vtx_tracks_2_tof_ = new AnalysisTree::Matching(
45  out_config_->GetBranchConfig(match_to_).GetId(), out_config_->GetLastId());
46  out_config_->AddMatch(vtx_tracks_2_tof_);
47 
48  out_tree_->Branch(
49  out_branch_.c_str(), "AnalysisTree::HitDetector", &tof_hits_);
50  out_tree_->Branch((match_to_ + "2" + out_branch_).c_str(),
51  "AnalysisTree::Matching",
53 }
54 
56  float z) {
57 
58  const Float_t Tx = params->GetTx();
59  const Float_t Ty = params->GetTy();
60  const Float_t old_z = params->GetZ();
61  const Float_t dz = z - old_z;
62 
63  const Float_t x = params->GetX() + Tx * dz;
64  const Float_t y = params->GetY() + Ty * dz;
65 
66  params->SetPosition({x, y, z});
67 }
68 
70  assert(cbm_tof_hits_);
71  tof_hits_->ClearChannels();
72  vtx_tracks_2_tof_->Clear();
73 
74  const int i_mass2 =
75  out_config_->GetBranchConfig(tof_hits_->GetId()).GetFieldId("mass2");
76  const int i_qp =
77  out_config_->GetBranchConfig(tof_hits_->GetId()).GetFieldId("qp_tof");
78  const int i_dx =
79  out_config_->GetBranchConfig(tof_hits_->GetId()).GetFieldId("dx");
80  const int i_t =
81  out_config_->GetBranchConfig(tof_hits_->GetId()).GetFieldId("t");
82  const int i_l =
83  out_config_->GetBranchConfig(tof_hits_->GetId()).GetFieldId("l");
84  // const int i_is_correct =
85  // out_config_->GetBranchConfig(tof_hits_->GetId()).GetFieldId("is_correct_match");
86  // const int i_pdg =
87  // out_config_->GetBranchConfig(tof_hits_->GetId()).GetFieldId("mc_pdg");
88 
89  const auto it = indexes_map_->find(match_to_);
90  if (it == indexes_map_->end()) {
91  throw std::runtime_error(match_to_
92  + " is not found to match with TOF hits");
93  }
94  auto rec_tracks_map = it->second;
95 
96  tof_hits_->Reserve(cbm_global_tracks_->GetEntries());
97 
98  for (Int_t igt = 0; igt < cbm_global_tracks_->GetEntries(); igt++) {
99  const auto* globalTrack =
100  static_cast<const CbmGlobalTrack*>(cbm_global_tracks_->At(igt));
101  const Int_t tofHitIndex = globalTrack->GetTofHitIndex();
102  if (tofHitIndex < 0) continue;
103 
104  const auto* tofHit =
105  static_cast<const CbmTofHit*>(cbm_tof_hits_->At(tofHitIndex));
106 
107  FairTrackParam param_last = *(globalTrack->GetParamLast());
108  TVector3 p_tof;
109  param_last.Momentum(p_tof);
110 
111  const Float_t p = p_tof.Mag();
112  const Int_t q = param_last.GetQp() > 0 ? 1 : -1;
113  const Float_t l =
114  globalTrack->GetLength(); // l is calculated by global tracking
115  const Float_t time = tofHit->GetTime();
116  const Float_t beta = l / (time * 29.9792458);
117  const Float_t m2 = p * p * (1. / (beta * beta) - 1.);
118 
119  const Float_t hitX = tofHit->GetX();
120  const Float_t hitY = tofHit->GetY();
121  const Float_t hitZ = tofHit->GetZ();
122 
123  ExtrapolateStraightLine(&param_last, tofHit->GetZ());
124 
125  auto* Hit = tof_hits_->AddChannel();
126  Hit->Init(out_config_->GetBranchConfig(tof_hits_->GetId()));
127  Hit->SetPosition(hitX, hitY, hitZ);
128  Hit->SetSignal(time);
129  Hit->SetField(m2, i_mass2);
130  Hit->SetField(float(q * p_tof.Mag()), i_qp);
131  Hit->SetField(float(param_last.GetX() - hitX), i_dx);
132  Hit->SetField(float(param_last.GetY() - hitY), i_dx + 1);
133  Hit->SetField(float(param_last.GetZ() - hitZ), i_dx + 2);
134  Hit->SetField(l, i_l);
135  Hit->SetField(time, i_t);
136 
137  if (rec_tracks_map.empty()) { return; }
138  const Int_t stsTrackIndex = globalTrack->GetStsTrackIndex();
139  if (rec_tracks_map.find(stsTrackIndex) != rec_tracks_map.end()) {
140  vtx_tracks_2_tof_->AddMatch(rec_tracks_map.find(stsTrackIndex)->second,
141  Hit->GetId());
142  }
143 
144  // const auto* tofMatch =
145  // dynamic_cast<CbmMatch*>(cbm_tof_match_->At(tofHitIndex)); if(tofMatch
146  // != nullptr && tofMatch->GetNofLinks()>0) {
147  //
148  // const auto* tofPoint = dynamic_cast<FairMCPoint*>(
149  // cbm_tof_points_->At(tofMatch->GetMatchedLink().GetIndex()) );
150  //
151  // Int_t itofMC = (tofPoint ? tofPoint->GetTrackID() : -1 );
152  // if(itofMC >= 0){
153  // const auto* mc_track = dynamic_cast<const
154  // CbmMCTrack*>(cbm_mc_tracks_->At(itofMC));
155  // Hit->SetField(mc_track->GetPdgCode(), i_pdg);
156  //
157  // const Int_t stsTrackIndex = globalTrack->GetStsTrackIndex();
158  // if(stsTrackIndex<0) return;
159  //
160  // auto* match = (CbmTrackMatchNew*) cbm_sts_match_->At(stsTrackIndex);
161  // if(match == nullptr || match->GetNofLinks() == 0) continue;
162  // const int mc_id_sts = match->GetMatchedLink().GetIndex();
163  // Hit->SetField( bool(mc_id_sts == itofMC), i_is_correct);
164  // }
165  // }
166  }
167 }
168 
170 
172  delete tof_hits_;
173  delete vtx_tracks_2_tof_;
174 };
CbmTofHitsConverter::vtx_tracks_2_tof_
AnalysisTree::Matching * vtx_tracks_2_tof_
Definition: CbmTofHitsConverter.h:42
CbmConverterTask::match_to_
std::string match_to_
AT branch to match.
Definition: CbmConverterTask.h:36
CbmTofHitsConverter::FillTofHits
void FillTofHits()
Definition: CbmTofHitsConverter.cxx:69
CbmTofHitsConverter::tof_hits_
AnalysisTree::HitDetector * tof_hits_
Definition: CbmTofHitsConverter.h:41
CbmGlobalTrack.h
CbmTofHitsConverter::Init
void Init(std::map< std::string, void * > &) final
CbmConverterTask::indexes_map_
std::map< std::string, std::map< int, int > > * indexes_map_
Definition: CbmConverterTask.h:34
CbmHit::GetTime
Double_t GetTime() const
Definition: CbmHit.h:75
CbmTofHitsConverter::~CbmTofHitsConverter
~CbmTofHitsConverter() final
Definition: CbmTofHitsConverter.cxx:171
CbmTrackMatchNew.h
CbmTofHitsConverter.h
CbmTofHitsConverter::cbm_global_tracks_
TClonesArray * cbm_global_tracks_
Definition: CbmTofHitsConverter.h:34
CbmGlobalTrack
Definition: CbmGlobalTrack.h:26
CbmMCTrack.h
CbmTofHitsConverter::ExtrapolateStraightLine
static void ExtrapolateStraightLine(FairTrackParam *params, float z)
Definition: CbmTofHitsConverter.cxx:55
x
Double_t x
Definition: CbmMvdSensorDigiToHitTask.cxx:68
CbmTofHitsConverter
Definition: CbmTofHitsConverter.h:15
y
Double_t y
Definition: CbmMvdSensorDigiToHitTask.cxx:68
CbmTofHit
Definition: core/data/tof/CbmTofHit.h:26
CbmGlobalTrack::GetTofHitIndex
Int_t GetTofHitIndex() const
Definition: CbmGlobalTrack.h:42
CbmTofHitsConverter::Exec
void Exec() final
Definition: CbmTofHitsConverter.cxx:169
ClassImp
ClassImp(CbmTofHitsConverter) void CbmTofHitsConverter
Definition: CbmTofHitsConverter.cxx:18
CbmTofHitsConverter::cbm_tof_hits_
TClonesArray * cbm_tof_hits_
Definition: CbmTofHitsConverter.h:35