CbmRoot
Loading...
Searching...
No Matches
CbmTofHitsConverter.cxx
Go to the documentation of this file.
1/* Copyright (C) 2020-2021 Physikalisches Institut, Eberhard Karls Universitaet Tuebingen, Tuebingen
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Viktor Klochkov [committer] */
4
6
7#include "CbmDefs.h"
8#include "CbmEvent.h"
9#include "CbmMCDataArray.h"
10#include "CbmMCDataManager.h"
11#include <CbmGlobalTrack.h>
12#include <CbmTofHit.h>
13#include <CbmTrackMatchNew.h>
14
15#include <FairMCPoint.h>
16#include <FairRootManager.h>
17
18#include "TClonesArray.h"
19
20#include <AnalysisTree/TaskManager.hpp>
21#include <cassert>
22
23#include "AnalysisTree/Matching.hpp"
24
26
28{
29 assert(!out_branch_.empty());
30 auto* ioman = FairRootManager::Instance();
31
32 cbm_tof_hits_ = (TClonesArray*) ioman->GetObject("TofHit");
33 cbm_global_tracks_ = (TClonesArray*) ioman->GetObject("GlobalTrack");
34 cbm_tof_match_ = (TClonesArray*) ioman->GetObject("TofHitMatch");
35 // cbm_tof_points_ = (TClonesArray*) ioman->GetObject("TofPoint");
36 // cbm_mc_tracks_ = (TClonesArray*) ioman->GetObject("MCTrack");
37
38 cbm_mc_manager_ = dynamic_cast<CbmMCDataManager*>(ioman->GetObject("MCDataManager"));
41
42 AnalysisTree::BranchConfig tof_branch(out_branch_, AnalysisTree::DetType::kHit);
43 tof_branch.AddField<float>("mass2", "Mass squared");
44 tof_branch.AddField<float>("l", "Track lenght");
45 tof_branch.AddField<float>("t", "ps(?), Measured time ");
46 tof_branch.AddField<float>("qp_tof", "charge * momentum extrapoleted to TOF");
47 tof_branch.AddFields<float>({"dx", "dy", "dz"}, "Distance between TOF hit and extrapolated global track, cm");
48
49 i_mass2_ = tof_branch.GetFieldId("mass2");
50 i_qp_ = tof_branch.GetFieldId("qp_tof");
51 i_dx_ = tof_branch.GetFieldId("dx");
52 i_t_ = tof_branch.GetFieldId("t");
53 i_l_ = tof_branch.GetFieldId("l");
54
55 auto* man = AnalysisTree::TaskManager::GetInstance();
56 man->AddBranch(tof_hits_, tof_branch);
57 man->AddMatching(match_to_, out_branch_, vtx_tracks_2_tof_);
59}
60
61void CbmTofHitsConverter::ExtrapolateStraightLine(FairTrackParam* params, float z)
62{
63 const Float_t Tx = params->GetTx();
64 const Float_t Ty = params->GetTy();
65 const Float_t old_z = params->GetZ();
66 const Float_t dz = z - old_z;
67
68 const Float_t x = params->GetX() + Tx * dz;
69 const Float_t y = params->GetY() + Ty * dz;
70
71 params->SetPosition({x, y, z});
72}
73
75{
76 assert(cbm_tof_hits_);
77 tof_hits_->ClearChannels();
78 vtx_tracks_2_tof_->Clear();
79 tof_hits_2_mc_tracks_->Clear();
80
81 auto* out_config_ = AnalysisTree::TaskManager::GetInstance()->GetConfig();
82 const auto& branch = out_config_->GetBranchConfig(out_branch_);
83
84 auto rec_tracks_map = GetMatchMap(match_to_);
85 auto sim_tracks_map = GetMatchMap(mc_tracks_);
86
87 int file_id {0}, event_id {0};
88 if (event && event->GetMatch() && event->GetMatch()->GetNofLinks() > 0) {
89 file_id = event->GetMatch()->GetMatchedLink().GetFile();
90 event_id = event->GetMatch()->GetMatchedLink().GetEntry();
91 }
92 else {
93 event_id = FairRootManager::Instance()->GetEntryNr();
94 }
95
96 const int n_tracks = event ? event->GetNofData(ECbmDataType::kGlobalTrack) : cbm_global_tracks_->GetEntriesFast();
97 // const int n_tof_hits = event ? event->GetNofData(ECbmDataType::kTofHit) : cbm_tof_hits_->GetEntriesFast(); // FU, 02.08.22
98
99 if (n_tracks <= 0) {
100 LOG(warn) << "No global tracks!";
101 return;
102 }
103 tof_hits_->Reserve(n_tracks);
104
105 for (Int_t igt = 0; igt < n_tracks; igt++) {
106 const auto trackIndex = event ? event->GetIndex(ECbmDataType::kGlobalTrack, igt) : igt;
107 const auto* globalTrack = static_cast<const CbmGlobalTrack*>(cbm_global_tracks_->At(trackIndex));
108 const Int_t tofHitIndex = globalTrack->GetTofHitIndex();
109 if (tofHitIndex < 0) continue;
110
111 const auto* tofHit = static_cast<const CbmTofHit*>(cbm_tof_hits_->At(tofHitIndex));
112
113 FairTrackParam param_last = *(globalTrack->GetParamLast());
114 TVector3 p_tof;
115 param_last.Momentum(p_tof);
116
117 const Float_t p = p_tof.Mag();
118 const Int_t q = param_last.GetQp() > 0 ? 1 : -1;
119 const Float_t l = globalTrack->GetLength(); // l is calculated by global tracking
120 const Float_t time = tofHit->GetTime();
121 const Float_t beta = event ? l / ((time - event->GetTzero()) * 29.9792458) : 0;
122 const Float_t m2 = event ? p * p * (1. / (beta * beta) - 1.) : -1.;
123
124 const Float_t hitX = tofHit->GetX();
125 const Float_t hitY = tofHit->GetY();
126 const Float_t hitZ = tofHit->GetZ();
127
128 ExtrapolateStraightLine(&param_last, tofHit->GetZ());
129
130 auto& hit = tof_hits_->AddChannel(branch);
131 hit.SetPosition(hitX, hitY, hitZ);
132 hit.SetSignal(time);
133 hit.SetField(m2, i_mass2_);
134 hit.SetField(float(q * p_tof.Mag()), i_qp_);
135 hit.SetField(float(param_last.GetX() - hitX), i_dx_);
136 hit.SetField(float(param_last.GetY() - hitY), i_dx_ + 1);
137 hit.SetField(float(param_last.GetZ() - hitZ), i_dx_ + 2);
138 hit.SetField(l, i_l_);
139 hit.SetField(time, i_t_);
140
141 if (rec_tracks_map.empty()) { continue; }
142 const Int_t stsTrackIndex = globalTrack->GetStsTrackIndex();
143 if (rec_tracks_map.find(stsTrackIndex) != rec_tracks_map.end()) {
144 vtx_tracks_2_tof_->AddMatch(rec_tracks_map.find(stsTrackIndex)->second, hit.GetId());
145 }
146
147 const auto* tofMatch = dynamic_cast<CbmMatch*>(cbm_tof_match_->At(tofHitIndex));
148 if (tofMatch && tofMatch->GetNofLinks() > 0) {
149 const auto& link = tofMatch->GetMatchedLink();
150 if (link.GetFile() != file_id || link.GetEntry() != event_id) { // match from different event
151 LOG(warn) << "match from different event";
152 // continue;
153 }
154 const auto* tofPoint = dynamic_cast<FairMCPoint*>(cbm_tof_points_new_->Get(link));
155 // const auto* tofPoint = dynamic_cast<FairMCPoint*>(cbm_tof_points_->At(link.GetIndex()));
156
157 if (!tofPoint) { throw std::runtime_error("no TOF point"); }
158
159 Int_t mc_track_id = tofPoint->GetTrackID();
160 if (mc_track_id >= 0) {
161 auto it = sim_tracks_map.find(mc_track_id);
162 if (it != sim_tracks_map.end()) { // match is found
163 tof_hits_2_mc_tracks_->AddMatch(hit.GetId(), it->second);
164 }
165 }
166 }
167 }
168}
169
170
ClassImp(CbmTofHitsConverter)
std::string match_to_
AT branch to match.
std::string out_branch_
Class characterising one event by a collection of links (indices) to data objects,...
Definition CbmEvent.h:34
CbmMatch * GetMatch() const
Definition CbmEvent.h:98
int32_t GetTofHitIndex() const
TObject * Get(const CbmLink *lnk)
Task class creating and managing CbmMCDataArray objects.
CbmMCDataArray * InitBranch(const char *name)
int32_t GetNofLinks() const
Definition CbmMatch.h:42
TClonesArray * cbm_tof_hits_
AnalysisTree::Matching * vtx_tracks_2_tof_
CbmMCDataArray * cbm_mc_tracks_new_
AnalysisTree::Matching * tof_hits_2_mc_tracks_
AnalysisTree::HitDetector * tof_hits_
CbmMCDataArray * cbm_tof_points_new_
const std::map< int, int > & GetMatchMap(const std::string &name) const
TClonesArray * cbm_tof_match_
TClonesArray * cbm_global_tracks_
void ProcessData(CbmEvent *event) final
static void ExtrapolateStraightLine(FairTrackParam *params, float z)
CbmMCDataManager * cbm_mc_manager_