5 #include "TClonesArray.h"
7 #include "FairRootManager.h"
9 #include "AnalysisTree/Matching.hpp"
40 AnalysisTree::Track* track,
43 vector<CbmStsTrack>
tracks = {*sts_track};
45 vector<float> chi2_to_vtx;
46 vector<L1FieldRegion> field;
49 std::vector<int> pdgVector = {pdg};
56 track->SetField(
float(field.at(0).cx0[0]),
imf_);
57 track->SetField(
float(field.at(0).cx1[0]),
imf_ + 1);
58 track->SetField(
float(field.at(0).cx2[0]),
imf_ + 2);
59 track->SetField(
float(field.at(0).cy0[0]),
imf_ + 3);
60 track->SetField(
float(field.at(0).cy1[0]),
imf_ + 4);
61 track->SetField(
float(field.at(0).cy2[0]),
imf_ + 5);
62 track->SetField(
float(field.at(0).cz0[0]),
imf_ + 6);
63 track->SetField(
float(field.at(0).cz1[0]),
imf_ + 7);
64 track->SetField(
float(field.at(0).cz2[0]),
imf_ + 8);
65 track->SetField(
float(field.at(0).z0[0]),
imf_ + 9);
68 return chi2_to_vtx[0];
77 out_config_->GetBranchConfig(
vtx_tracks_->GetId()).GetFieldId(
"q");
79 out_config_->GetBranchConfig(
vtx_tracks_->GetId()).GetFieldId(
"ndf");
81 out_config_->GetBranchConfig(
vtx_tracks_->GetId()).GetFieldId(
"chi2");
83 out_config_->GetBranchConfig(
vtx_tracks_->GetId()).GetFieldId(
"nhits");
84 const int inhits_mvd =
85 out_config_->GetBranchConfig(
vtx_tracks_->GetId()).GetFieldId(
"nhits_mvd");
87 out_config_->GetBranchConfig(
vtx_tracks_->GetId()).GetFieldId(
"dcax");
89 out_config_->GetBranchConfig(
vtx_tracks_->GetId()).GetFieldId(
"vtx_chi2");
94 for (
short i_track = 0; i_track < n_sts_tracks; ++i_track) {
96 if (!sts_track) {
throw std::runtime_error(
"empty track!"); }
99 track->Init(out_config_->GetBranchConfig(
vtx_tracks_->GetId()));
106 const FairTrackParam* trackParamFirst = sts_track->GetParamFirst();
108 trackParamFirst->Momentum(momRec);
109 const Int_t q = trackParamFirst->GetQp() > 0 ? 1 : -1;
111 track->SetMomentum3(momRec);
112 track->SetField(
int(q), iq);
113 track->SetField(
int(sts_track->GetNDF()), indf);
114 track->SetField(
float(sts_track->GetChiSq()), ichi2);
115 track->SetField(
int(sts_track->GetNofHits()), inhits);
122 track->SetField(
int(sts_track->GetNofMvdHits()), inhits_mvd);
123 track->SetField(
float(chi2_vertex), ivtx_chi2);
133 bool is_good_track)
const {
134 assert(track && sts_track);
135 const FairTrackParam* trackParamFirst = sts_track->
GetParamFirst();
137 track->SetField(
float(trackParamFirst->GetX()),
ipar_);
138 track->SetField(
float(trackParamFirst->GetY()),
ipar_ + 1);
139 track->SetField(
float(trackParamFirst->GetZ()),
ipar_ + 2);
140 track->SetField(
float(trackParamFirst->GetTx()),
ipar_ + 3);
141 track->SetField(
float(trackParamFirst->GetTy()),
ipar_ + 4);
142 track->SetField(
float(trackParamFirst->GetQp()),
ipar_ + 5);
144 for (Int_t
i = 0, iCov = 0;
i < 5;
i++) {
145 for (Int_t j = 0; j <=
i; j++, iCov++) {
146 track->SetField(
float(trackParamFirst->GetCovariance(
i, j)),
159 const FairTrackParam* trackParamFirst = sts_track->
GetParamFirst();
161 Double_t cov_matrix[15] = {0.f};
162 for (Int_t
i = 0, iCov = 0;
i < 5;
i++) {
163 for (Int_t j = 0; j <=
i; j++, iCov++) {
164 cov_matrix[iCov] = trackParamFirst->GetCovariance(
i, j);
176 for (
auto element : cov_matrix) {
177 ok = ok && isfinite(element);
179 ok = ok && (cov_matrix[0] < 1. && cov_matrix[0] > 0.)
180 && (cov_matrix[2] < 1. && cov_matrix[2] > 0.)
181 && (cov_matrix[5] < 1. && cov_matrix[5] > 0.)
182 && (cov_matrix[9] < 1. && cov_matrix[9] > 0.)
183 && (cov_matrix[14] < 1. && cov_matrix[14] > 0.);
191 AnalysisTree::Track* track)
const {
200 Float_t bestWeight = 0.f;
201 Float_t totalWeight = 0.f;
202 Int_t mcTrackId = -1;
204 for (
int iLink = 0; iLink < match->
GetNofLinks(); iLink++) {
212 if (!((bestWeight / totalWeight < 0.7)
213 || (mcTrackId >=
nMCTracks || mcTrackId < 0))) {
216 if (!(TMath::Abs(mctrack->GetPdgCode()) == 11
217 || TMath::Abs(mctrack->GetPdgCode()) == 13
218 || TMath::Abs(mctrack->GetPdgCode()) == 211
219 || TMath::Abs(mctrack->GetPdgCode()) == 321
220 || TMath::Abs(mctrack->GetPdgCode()) == 2212
221 || TMath::Abs(mctrack->GetPdgCode()) == 1000010020
222 || TMath::Abs(mctrack->GetPdgCode()) == 1000010030
223 || TMath::Abs(mctrack->GetPdgCode()) == 1000020030
224 || TMath::Abs(mctrack->GetPdgCode()) == 1000020040)) {
229 if (mctrack->GetMotherId() > -1) {
243 auto* ioman = FairRootManager::Instance();
248 (TClonesArray*) ioman->GetObject(in_branches_.at(
eStsTracks).c_str());
250 (TClonesArray*) ioman->GetObject(in_branches_.at(
eSimTracks).c_str());
251 cbm_sts_match_ = (TClonesArray*) ioman->GetObject(
"StsTrackMatch");
257 AnalysisTree::BranchConfig vtx_tracks_config(out_branch_,
258 AnalysisTree::DetType::kTrack);
259 vtx_tracks_config.AddField<
float>(
"chi2");
260 vtx_tracks_config.AddField<
float>(
"vtx_chi2");
261 vtx_tracks_config.AddFields<
float>({
"dcax",
"dcay",
"dcaz"});
262 vtx_tracks_config.AddField<
int>(
"ndf");
263 vtx_tracks_config.AddField<
int>(
"q");
264 vtx_tracks_config.AddField<
int>(
"nhits");
265 vtx_tracks_config.AddField<
int>(
"nhits_mvd");
268 vtx_tracks_config.AddFields<
float>({
"x",
"y",
"z",
"tx",
"ty",
"qp"});
269 vtx_tracks_config.AddFields<
float>(
270 {
"cx0",
"cx1",
"cx2",
"cy0",
"cy1",
"cy2",
"cz0",
"cz1",
"cz2",
"z0"});
271 vtx_tracks_config.AddFields<
float>({
"cov1",
287 vtx_tracks_config.AddField<
int>(
"mother_pdg");
288 vtx_tracks_config.AddField<
int>(
"mc_pdg");
289 vtx_tracks_config.AddField<
bool>(
"pass_cuts");
291 ipar_ = vtx_tracks_config.GetFieldId(
"x");
292 imf_ = vtx_tracks_config.GetFieldId(
"cx0");
293 icov_ = vtx_tracks_config.GetFieldId(
"cov1");
294 imc_pdg_ = vtx_tracks_config.GetFieldId(
"mc_pdg");
295 imother_pdg_ = vtx_tracks_config.GetFieldId(
"mother_pdg");
296 ipasscuts_ = vtx_tracks_config.GetFieldId(
"pass_cuts");
299 out_config_->AddBranchConfig(std::move(vtx_tracks_config));
300 vtx_tracks_ =
new AnalysisTree::TrackDetector(out_config_->GetLastId());
302 out_config_->GetLastId(), out_config_->GetBranchConfig(
match_to_).GetId());
307 out_branch_.c_str(),
"AnalysisTree::TrackDetector", &
vtx_tracks_);
308 out_tree_->Branch((out_branch_ +
"2" +
match_to_).c_str(),
309 "AnalysisTree::Matching",
319 +
" is not found to match with vertex tracks");
321 auto sim_tracks_map = it->second;
327 const int cbm_id = track_id.first;
328 const int out_id = track_id.second;
330 if (match->GetNofLinks() > 0) {
331 const int mc_track_id = match->GetMatchedLink().GetIndex();
333 if (match->GetTrueOverAllHitsRatio()
337 auto p = sim_tracks_map.find(mc_track_id);
338 if (p == sim_tracks_map.end())