CbmRoot
Loading...
Searching...
No Matches
CbmStsRecoBeamSpot.cxx
Go to the documentation of this file.
1/* Copyright (C) 2023 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Dario Ramirez [committer] */
4
6
7#include "CbmStsAddress.h"
8
10void CbmStsRecoBeamSpot::AddTarget(std::string trg_name, CbmTarget* trg)
11{
12 if (trg_name.length() == 0) {
13 trg_name = Form("target_%ld", fTargets.size());
14 }
15 fTargets[trg_name] = trg;
16}
17
19{
20 std::string h_name;
21 std::string h_name_base = "";
22 for (auto& [element_i, geo_i] : fStsGeoInfo) {
23 if (element_i < 8) continue;
24
25 for (auto& [element_j, geo_j] : fStsGeoInfo) {
26 if (element_j < 8) continue;
27 int32_t unit_i = CbmStsAddress::GetElementId(element_i, kStsUnit);
28 int32_t unit_j = CbmStsAddress::GetElementId(element_j, kStsUnit);
29
30 if (unit_i >= unit_j) continue;
31
32 for (auto& [trg_name, trg] : fTargets) {
33 h_name_base = Form("0x%x:0x%x_%s", element_i, element_j, trg_name.c_str());
34
35 fSampleRangeXmin = trg->GetPosition().Px() - 10.; // HARDCODE
36 fSampleRangeXmax = trg->GetPosition().Px() + 10.; // HARDCODE
37 fSampleRangeYmin = trg->GetPosition().Py() - 10.; // HARDCODE
38 fSampleRangeYmax = trg->GetPosition().Py() + 10.; // HARDCODE
39 fSampleRangeZmin = trg->GetPosition().Pz() - 10.; // HARDCODE
40 fSampleRangeZmax = trg->GetPosition().Pz() + 10.; // HARDCODE
41
42
43 unsigned int nb_bins_x = (fSampleRangeXmax - fSampleRangeXmin) / fSampleBinSizeX;
44 unsigned int nb_bins_y = (fSampleRangeYmax - fSampleRangeYmin) / fSampleBinSizeY;
45 unsigned int nb_bins_z = (fSampleRangeZmax - fSampleRangeZmin) / fSampleBinSizeZ;
46
47 h_name = Form("%s_Y_vs_X", h_name_base.c_str());
48 fH2D[h_name] = std::make_unique<TH2D>(h_name.c_str(), h_name.c_str(), nb_bins_x, fSampleRangeXmin,
50 fH2D[h_name]->GetXaxis()->SetTitle("X [cm]");
51 fH2D[h_name]->GetYaxis()->SetTitle("Y [cm]");
52
53 h_name = Form("%s_X_vs_Z", h_name_base.c_str());
54 fH2D[h_name] = std::make_unique<TH2D>(h_name.c_str(), h_name.c_str(), nb_bins_z, fSampleRangeZmin,
56 fH2D[h_name]->GetXaxis()->SetTitle("Z [cm]");
57 fH2D[h_name]->GetYaxis()->SetTitle("X [cm]");
58
59 h_name = Form("%s_Y_vs_Z", h_name_base.c_str());
60 fH2D[h_name] = std::make_unique<TH2D>(h_name.c_str(), h_name.c_str(), nb_bins_z, fSampleRangeZmin,
62 fH2D[h_name]->GetXaxis()->SetTitle("Z [cm]");
63 fH2D[h_name]->GetYaxis()->SetTitle("Y [cm]");
64
65 h_name = Form("%s_Y_beam_vs_X_beam", h_name_base.c_str());
66 fH2D[h_name] = std::make_unique<TH2D>(h_name.c_str(), h_name.c_str(), nb_bins_x, fSampleRangeXmin,
68 fH2D[h_name]->GetXaxis()->SetTitle("X_beam [cm]");
69 fH2D[h_name]->GetYaxis()->SetTitle("Y_beam [cm]");
70
71 } // end targets loop
72 } // end sts_i modules loop
73 } // end sts_j modules loop
74}
75
77{
78 TVector3 n0 = trg->GetPosition();
79 TVector3 n1(.0, .0, 1.);
80 n1.RotateY(trg->GetRotation());
81
82 TVector3 l0(hit_0->GetX(), hit_0->GetY(), hit_0->GetZ());
83 TVector3 l1(hit_1->GetX() - hit_0->GetX(), hit_1->GetY() - hit_0->GetY(), hit_1->GetZ() - hit_0->GetZ());
84
85 double l1_dot_n1 = l1.Dot(n1);
86 if (l1_dot_n1 <= 1e-6) { // tracklet is parallel (or close to it) to target plane
87 throw std::invalid_argument("Track-let parallel to target plane");
88 }
89
90 double t = (n0 - l0).Dot(n1) / l1.Dot(n1);
91 return l0 + t * l1;
92}
93
95{
96 if (!fStsHits.size()) return;
97 for (int sts_unit_i = 0; sts_unit_i < nb_sts_station_ - 1; sts_unit_i++) {
98 for (int sts_unit_j = sts_unit_i + 1; sts_unit_j < nb_sts_station_; sts_unit_j++) {
99 for (auto sts_hit_i : fStsHits[sts_unit_i]) {
100 for (auto sts_hit_j : fStsHits[sts_unit_j]) {
101 int32_t sts_address_i = sts_hit_i->GetAddress();
102 int32_t sts_address_j = sts_hit_j->GetAddress();
103
104 for (auto& [trg_name, trg] : fTargets) {
105 TVector3 sol = ExtrapolateTrackTo(sts_hit_i, sts_hit_j, trg);
106 std::string h_name_base = Form("0x%x:0x%x_%s", sts_address_i, sts_address_j, trg_name.c_str());
107
108 std::string h_name = Form("%s_X_vs_Z", h_name_base.c_str());
109 fH2D[h_name]->Fill(sol.Pz(), sol.Px());
110
111 h_name = Form("%s_Y_vs_Z", h_name_base.c_str());
112 fH2D[h_name]->Fill(sol.Pz(), sol.Py());
113
114 h_name = Form("%s_Y_vs_X", h_name_base.c_str());
115 fH2D[h_name]->Fill(sol.Px(), sol.Py());
116
117 TVector3 sol_beam = sol - trg->GetPosition();
118
119 double x_beam = sol_beam.Px() / cos(trg->GetRotation());
120 double y_beam = sol_beam.Py();
121 h_name = Form("%s_Y_beam_vs_X_beam", h_name_base.c_str());
122 fH2D[h_name]->Fill(x_beam, y_beam);
123 }
124 }
125 }
126 }
127 }
128 fStsHits.clear();
129}
130
131
133
134
136{
137 int nb_sts_hits = evt->GetNofData(ECbmDataType::kStsHit);
138 if (nb_sts_hits > 0)
139 for (int hit_evt_idx = 0; hit_evt_idx < nb_sts_hits; hit_evt_idx++) {
140 int sts_hit_idx = evt->GetIndex(ECbmDataType::kStsHit, hit_evt_idx);
141 CbmStsHit* hit = (CbmStsHit*) fStsHitArray->UncheckedAt(sts_hit_idx);
142 ProcessHit(hit);
143 }
144}
145
147{
148 if (hit == nullptr) return;
149 int32_t address = hit->GetAddress();
150 int32_t unit = CbmStsAddress::GetElementId(address, kStsUnit);
151
152 if (fAnalysisCuts != nullptr && fAnalysisCuts->CheckStsHit(hit, fStsCluArray)) {
153 fStsHits[unit].push_back(hit);
154 }
155}
156
158{
159
160 // Check if CbmEvent
161 if (fCbmEvtArray != nullptr) {
162
163 uint32_t nb_events = fCbmEvtArray->GetEntriesFast();
164 LOG(info) << "Running CbmStsRecoBeamSpot - Event like - Entry:" << entry_ << "\tEvents: " << nb_events;
165 for (uint32_t evt_idx = 0; evt_idx < nb_events; evt_idx++) {
166 CbmEvent* event = (CbmEvent*) fCbmEvtArray->UncheckedAt(evt_idx);
167 if (fAnalysisCuts != nullptr && fAnalysisCuts->CheckEvent(event)) {
168 ProcessEvent(event);
169 BeamSpotReco();
170 }
171 }
172 }
173 else {
174
175 uint32_t n_of_hits = fStsHitArray->GetEntriesFast();
176 LOG(info) << "Running CbmStsRecoBeamSpot - Time like - Entry:" << entry_ << "\tStsHit: " << n_of_hits;
177 for (uint32_t hit_idx = 0; hit_idx < n_of_hits; hit_idx++) {
178 CbmStsHit* sts_hit = (CbmStsHit*) fStsHitArray->UncheckedAt(hit_idx);
179 ProcessHit(sts_hit);
180 }
181 BeamSpotReco();
182 }
183 entry_++;
184}
185
187{
188 LOG(debug) << "Init CbmStsRecoBeamSpot ...";
189
190 FairRootManager* ioman = FairRootManager::Instance();
191 if (ioman == nullptr) return kERROR;
192
193 fCbmEvtArray = (TClonesArray*) ioman->GetObject("CbmEvent");
194 fStsHitArray = (TClonesArray*) ioman->GetObject("StsHit");
195 fStsCluArray = (TClonesArray*) ioman->GetObject("StsCluster");
196
197 for (auto& [trg_name, trg] : fTargets) {
198 LOG(debug) << trg_name << ": " << trg->ToString();
199 }
200
201 LoadSetup();
203
204 return kSUCCESS;
205}
@ kStsUnit
friend fvec cos(const fvec &a)
Class characterising one event by a collection of links (indices) to data objects,...
Definition CbmEvent.h:34
size_t GetNofData() const
Definition CbmEvent.cxx:58
uint32_t GetIndex(ECbmDataType type, uint32_t iData) const
Definition CbmEvent.cxx:42
int32_t GetAddress() const
Definition CbmHit.h:77
double GetZ() const
Definition CbmHit.h:74
double GetY() const
Definition CbmPixelHit.h:74
double GetX() const
Definition CbmPixelHit.h:73
CbmCutMap * fAnalysisCuts
std::map< std::string, std::unique_ptr< TH2D > > fH2D
void SaveToFile()
It write all mapped objects to the FairRunAna sink file.
void LoadSetup()
Load the STS setup and fill the map with XYZ boundaries for each STS setup element....
std::unordered_map< int32_t, std::vector< double > > fStsGeoInfo
data class for a reconstructed 3-d hit in the STS
Definition CbmStsHit.h:35
TVector3 ExtrapolateTrackTo(CbmPixelHit *, CbmPixelHit *, CbmTarget *)
Extrapolate a track-let to a target plane.
void AddTarget(CbmTarget *target=nullptr)
Add a CbmTarget object to the list of targets.
TClonesArray * fCbmEvtArray
void ProcessEvent(CbmEvent *)
Process an Cbm events It filters event based on the provided CbmCutMap.
TClonesArray * fStsCluArray
void ProcessHit(CbmStsHit *)
Process an STS hit It filters hits based on the provided CbmCutMap.
void BeamSpotReco()
Reconstruct the beam spot at each target planes.
std::map< std::string, CbmTarget * > fTargets
std::map< int32_t, std::vector< CbmStsHit * > > fStsHits
TClonesArray * fStsHitArray
Class for constructing the geometry of the CBM target.
Definition CbmTarget.h:37
Double_t GetRotation() const
Get target rotation angle.
Definition CbmTarget.h:109
TVector3 GetPosition() const
Definition CbmTarget.h:103
uint32_t GetElementId(int32_t address, int32_t level)
Get the index of an element.