CbmRoot
Loading...
Searching...
No Matches
CbmTrdTracksConverter.cxx
Go to the documentation of this file.
1/* Copyright (C) 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 <CbmGlobalTrack.h>
10#include <CbmTrdHit.h>
11#include <CbmTrdTrack.h>
12
13#include <FairMCPoint.h>
14#include <FairRootManager.h>
15
16#include "TClonesArray.h"
17
18#include <AnalysisTree/TaskManager.hpp>
19#include <cassert>
20
21#include "AnalysisTree/Matching.hpp"
22
24
25
27{
28 assert(!out_branch_.empty());
29 auto* ioman = FairRootManager::Instance();
30
31 cbm_trd_tracks_ = (TClonesArray*) ioman->GetObject("TrdTrack");
32 cbm_global_tracks_ = (TClonesArray*) ioman->GetObject("GlobalTrack");
33 cbm_trd_hits_ = (TClonesArray*) ioman->GetObject("TrdHit");
34
35 AnalysisTree::BranchConfig trd_branch(out_branch_, AnalysisTree::DetType::kTrack);
36 trd_branch.AddFields<float>({"energy_loss_0", "energy_loss_1", "energy_loss_2", "energy_loss_3"},
37 "keV(?), Energy loss per TRD station");
38 trd_branch.AddFields<float>({"pid_like_e", "pid_like_pi", "pid_like_k", "pid_like_p"},
39 "Probability to be a given particle specie");
40 trd_branch.AddField<float>("chi2_ov_ndf", "chi2 divided by NDF of the track fit");
41 trd_branch.AddFields<float>({"pT_out", "p_out"}, "Momentum at last point (?)");
42 trd_branch.AddField<int>("n_hits", "Number of hits");
43
44 i_e_loss_i_ = trd_branch.GetFieldId("energy_loss_0");
45 i_pid_like_ = trd_branch.GetFieldId("pid_like_e");
46 i_chi2_ov_ndf_ = trd_branch.GetFieldId("chi2_ov_ndf");
47 i_pT_out_ = trd_branch.GetFieldId("pT_out");
48 i_n_hits_ = trd_branch.GetFieldId("n_hits");
49
50 auto* man = AnalysisTree::TaskManager::GetInstance();
51 man->AddBranch(trd_tracks_, trd_branch);
52 man->AddMatching(match_to_, out_branch_, vtx_tracks_2_trd_);
53}
54
56{
57 assert(cbm_trd_tracks_);
58 trd_tracks_->ClearChannels();
59 vtx_tracks_2_trd_->Clear();
60
61 auto* out_config_ = AnalysisTree::TaskManager::GetInstance()->GetConfig();
62 const auto& branch = out_config_->GetBranchConfig(out_branch_);
63
64 const auto it = indexes_map_->find(match_to_);
65 if (it == indexes_map_->end()) { throw std::runtime_error(match_to_ + " is not found to match with TRD tracks"); }
66 auto rec_tracks_map = it->second;
67
68 const int n_tracks = event ? event->GetNofData(ECbmDataType::kGlobalTrack) : cbm_global_tracks_->GetEntriesFast();
69 if (n_tracks <= 0) {
70 LOG(warn) << "No global tracks!";
71 return;
72 }
73
74 trd_tracks_->Reserve(n_tracks);
75
76 for (Int_t igt = 0; igt < n_tracks; igt++) {
77 const auto trackIndex = event ? event->GetIndex(ECbmDataType::kGlobalTrack, igt) : igt;
78
79 const auto* global_track = static_cast<const CbmGlobalTrack*>(cbm_global_tracks_->At(trackIndex));
80
81 Int_t itrd = global_track->GetTrdTrackIndex();
82 if (itrd < 0) continue;
83
84 auto trd_track = static_cast<CbmTrdTrack*>(cbm_trd_tracks_->At(itrd));
85 if (trd_track == nullptr) {
86 LOG(warn) << "No TRD track!";
87 continue;
88 }
89 auto& track = trd_tracks_->AddChannel(branch);
90 TVector3 mom, mom_last;
91 trd_track->GetParamFirst()->Momentum(mom);
92 trd_track->GetParamLast()->Momentum(mom_last);
93
94 track.SetMomentum3(mom);
95
96 track.SetField(float(trd_track->GetPidLikeEL()), i_pid_like_);
97 track.SetField(float(trd_track->GetPidLikePI()), i_pid_like_ + 1);
98 track.SetField(float(trd_track->GetPidLikeKA()), i_pid_like_ + 2);
99 track.SetField(float(trd_track->GetPidLikePR()), i_pid_like_ + 3);
100
101 track.SetField(float(trd_track->GetNDF() > 0. ? trd_track->GetChiSq() / trd_track->GetNDF() : -999.),
103
104 track.SetField(float(mom_last.Pt()), i_pT_out_);
105 track.SetField(float(mom_last.Mag()), i_pT_out_ + 1);
106
107 for (int i = 0; i < 4; ++i) {
108 track.SetField(0.f, i_e_loss_i_ + i);
109 }
110
111 int trd_hits = trd_track->GetNofHits();
112 for (Int_t ihit = 0; ihit < trd_track->GetNofHits(); ihit++) {
113 Int_t idx = trd_track->GetHitIndex(ihit);
114 auto* hit = (CbmTrdHit*) cbm_trd_hits_->At(idx);
115 if (hit) {
116 if (hit->GetELoss() > 0) {
117 track.SetField(float(hit->GetELoss() * 1e6), i_e_loss_i_ + hit->GetPlaneId());
118 }
119 else {
120 trd_hits--;
121 }
122 }
123 }
124
125 track.SetField(trd_hits, i_n_hits_);
126
127 if (rec_tracks_map.empty()) { continue; }
128 const Int_t stsTrackIndex = global_track->GetStsTrackIndex();
129 if (rec_tracks_map.find(stsTrackIndex) != rec_tracks_map.end()) {
130 vtx_tracks_2_trd_->AddMatch(rec_tracks_map.find(stsTrackIndex)->second, track.GetId());
131 }
132 }
133}
134
Class for hits in TRD detector.
ClassImp(CbmTrdTracksConverter)
std::string match_to_
AT branch to match.
std::string out_branch_
std::map< std::string, MapType > * indexes_map_
from other tasks
Class characterising one event by a collection of links (indices) to data objects,...
Definition CbmEvent.h:34
int32_t GetTrdTrackIndex() const
const FairTrackParam * GetParamFirst() const
Definition CbmTrack.h:68
data class for a reconstructed Energy-4D measurement in the TRD
Definition CbmTrdHit.h:40
void ProcessData(CbmEvent *event) final
AnalysisTree::Matching * vtx_tracks_2_trd_
AnalysisTree::TrackDetector * trd_tracks_