CbmRoot
Loading...
Searching...
No Matches
CbmRichRingsConverter.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 <CbmRichRing.h>
11
12#include <FairMCPoint.h>
13#include <FairRootManager.h>
14
15#include "TClonesArray.h"
16
17#include <AnalysisTree/TaskManager.hpp>
18#include <cassert>
19#include <vector>
20
21#include "AnalysisTree/Matching.hpp"
22
24{
25
26 assert(!out_branch_.empty());
27 auto* ioman = FairRootManager::Instance();
28
29 cbm_rich_rings_ = (TClonesArray*) ioman->GetObject("RichRing");
30 cbm_global_tracks_ = (TClonesArray*) ioman->GetObject("GlobalTrack");
31
32 AnalysisTree::BranchConfig rich_branch(out_branch_, AnalysisTree::DetType::kHit);
33 rich_branch.AddField<float>("radius");
34 rich_branch.AddFields<int>({"n_hits", "n_hits_on_ring"});
35 rich_branch.AddFields<float>({"axis_a", "axis_b"});
36 rich_branch.AddFields<float>({"center_x", "center_y"});
37 rich_branch.AddField<float>("chi2_ov_ndf", "chi2/ndf ring fit");
38 rich_branch.AddField<float>("phi_ellipse", "phi rotation angle of ellipse");
39 rich_branch.AddField<float>("radial_pos", "sqrt(x**2+abs(y-110)**2)");
40 rich_branch.AddField<float>("radial_angle", "(0||1||2)*pi +- atan( abs((+-100-y)/-x) )");
41
42 i_r_ = rich_branch.GetFieldId("radius");
43 i_n_hits_ = rich_branch.GetFieldId("n_hits");
44 i_axis_ = rich_branch.GetFieldId("axis_a");
45 i_center_ = rich_branch.GetFieldId("center_x");
46 i_chi2_ = rich_branch.GetFieldId("chi2_ov_ndf");
47 i_radial_angle_ = rich_branch.GetFieldId("radial_angle");
48 i_radial_pos_ = rich_branch.GetFieldId("radial_pos");
49 i_phi_ellipse_ = rich_branch.GetFieldId("phi_ellipse");
50
51 auto* man = AnalysisTree::TaskManager::GetInstance();
52 man->AddBranch(rich_rings_, rich_branch);
53 man->AddMatching(match_to_, out_branch_, vtx_tracks_2_rich_);
54}
55
57{
58 assert(cbm_rich_rings_);
59 rich_rings_->ClearChannels();
60 vtx_tracks_2_rich_->Clear();
61
62 auto* out_config_ = AnalysisTree::TaskManager::GetInstance()->GetConfig();
63 const auto& branch = out_config_->GetBranchConfig(out_branch_);
64
65 const auto it = indexes_map_->find(match_to_);
66 if (it == indexes_map_->end()) { throw std::runtime_error(match_to_ + " is not found to match with RICH rings"); }
67 auto rec_tracks_map = it->second;
68
69 const int n_tracks = event ? event->GetNofData(ECbmDataType::kGlobalTrack) : cbm_global_tracks_->GetEntriesFast();
70 if (n_tracks <= 0) {
71 LOG(warn) << "No global tracks!";
72 return;
73 }
74 rich_rings_->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 const auto* global_track = static_cast<const CbmGlobalTrack*>(cbm_global_tracks_->At(trackIndex));
79
80 Int_t i_rich = global_track->GetRichRingIndex();
81 if (i_rich < 0) continue;
82 auto rich_ring = static_cast<CbmRichRing*>(cbm_rich_rings_->At(i_rich));
83 if (rich_ring == nullptr) {
84 LOG(warn) << "No RICH ring!";
85 continue;
86 }
87
88 auto& ring = rich_rings_->AddChannel(branch);
89 ring.SetPosition(rich_ring->GetCenterX(), rich_ring->GetCenterY(), 0.f);
90 ring.SetField(int(rich_ring->GetNofHits()), i_n_hits_);
91 ring.SetField(int(rich_ring->GetNofHitsOnRing()), i_n_hits_ + 1);
92 ring.SetField(float(rich_ring->GetAaxis()), i_axis_);
93 ring.SetField(float(rich_ring->GetBaxis()), i_axis_ + 1);
94 ring.SetField(float(rich_ring->GetCenterX()), i_center_);
95 ring.SetField(float(rich_ring->GetCenterY()), i_center_ + 1);
96 ring.SetField(float(rich_ring->GetRadius()), i_r_);
97 ring.SetField(float(rich_ring->GetNDF() > 0. ? rich_ring->GetChi2() / rich_ring->GetNDF() : -999.), i_chi2_);
98 ring.SetField(float(rich_ring->GetRadialAngle()), i_radial_angle_);
99 ring.SetField(float(rich_ring->GetRadialPosition()), i_radial_pos_);
100 ring.SetField(float(rich_ring->GetPhi()), i_phi_ellipse_);
101
102 if (rec_tracks_map.empty()) { continue; }
103 const Int_t stsTrackIndex = global_track->GetStsTrackIndex();
104 if (rec_tracks_map.find(stsTrackIndex) != rec_tracks_map.end()) {
105 vtx_tracks_2_rich_->AddMatch(rec_tracks_map.find(stsTrackIndex)->second, ring.GetId());
106 }
107 }
108}
109
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 GetRichRingIndex() const
AnalysisTree::HitDetector * rich_rings_
AnalysisTree::Matching * vtx_tracks_2_rich_
void ProcessData(CbmEvent *event) final