CbmRoot
Loading...
Searching...
No Matches
CbmStsHitAna.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
5#include "CbmStsHitAna.h"
6
7#include <CbmStsTrack.h>
8
9#include <ctime>
10#include <iostream>
11#include <typeinfo>
12
14
15CbmStsHitAna::CbmStsHitAna(std::string cal_par_file) : fHitModifier({":all"}), fCalibrationFile(cal_par_file) {}
16
18{
19 if (fModuleParSet == nullptr) {
20 LOG(debug) << "Loading charge calibration ...";
21 fModuleParSet = std::make_unique<CbmStsParSetModule>("CbmParSetModule", "STS parameters", "Default");
22 fModuleParSet->LoadParASCII(fCalibrationFile);
23 }
24
25 FairRootManager* ioman = FairRootManager::Instance();
26 if (ioman == nullptr) return kERROR;
27
28 fCbmEvtArray = (TClonesArray*) ioman->GetObject("CbmEvent");
29
30 fGlbTrkArray = (TClonesArray*) ioman->GetObject("GlobalTrack");
31 fStsTrkArray = (TClonesArray*) ioman->GetObject("StsTrack");
32 fRchTrkArray = (TClonesArray*) ioman->GetObject("RichTrack");
33 fMchTrkArray = (TClonesArray*) ioman->GetObject("MuchTrack");
34 fTrdTrkArray = (TClonesArray*) ioman->GetObject("TrdTrack");
35 fTofTrkArray = (TClonesArray*) ioman->GetObject("TofTrack");
36
37 fStsHitArray = (TClonesArray*) ioman->GetObject("StsHit");
38 fStsCluArray = (TClonesArray*) ioman->GetObject("StsCluster");
39
40 if (fGlbTrkArray) fHitModifier.push_back(":trk");
41
42 LoadSetup();
43
44 return kSUCCESS;
45}
46
47void CbmStsHitAna::BookHistograms(int32_t address)
48{
49 LOG(debug) << Form("Booking histograms for module: 0x%x", address);
50
51 const CbmStsParModule& par_module = fModuleParSet->GetParModule(address);
52 const auto [n_side_binning, p_side_binning] = cbm_sts_utils::ChargeBinning(par_module, fMaxCluSize);
53
54 std::string h_name;
55
56 double x_min = fStsGeoInfo.count(address) ? fStsGeoInfo[address][0] : -15;
57 double x_max = fStsGeoInfo.count(address) ? fStsGeoInfo[address][1] : +15;
58 double y_min = fStsGeoInfo.count(address) ? fStsGeoInfo[address][2] : -15;
59 double y_max = fStsGeoInfo.count(address) ? fStsGeoInfo[address][3] : +15;
60
61 double t_min = -150 - 0.5 * cbm_sts_utils::kStsClock;
62 double t_max = +150 + 0.5 * cbm_sts_utils::kStsClock;
63
64 auto x_binning = cbm_sts_utils::HBinning{uint32_t((x_max - x_min) / cbm_sts_utils::kStsDx), x_min, x_max};
65 auto y_binning = cbm_sts_utils::HBinning{uint32_t((y_max - y_min) / cbm_sts_utils::kStsDy), y_min, y_max};
66 auto t_binning = cbm_sts_utils::HBinning{uint32_t((t_max - t_min) / cbm_sts_utils::kStsClock), t_min, t_max};
67
68 for (const char* mod : fHitModifier) {
69 h_name = Form("0x%x_Q_asymmetry%s", address, mod);
70 fH1D[h_name] = std::make_unique<TH1D>(h_name.c_str(), h_name.c_str(), 1000, -1.01, +1.01);
71
72 h_name = Form("0x%x_Qp_vs_Qn%s", address, mod);
73 fH2D[h_name] = std::make_unique<TH2D>(h_name.c_str(), h_name.c_str(), n_side_binning.n_of_bins,
74 n_side_binning.x_min, n_side_binning.x_max, p_side_binning.n_of_bins,
75 p_side_binning.x_min, p_side_binning.x_max);
76
77 h_name = Form("0x%x_Qp_vs_size%s", address, mod);
78 fH2D[h_name] = std::make_unique<TH2D>(h_name.c_str(), h_name.c_str(), p_side_binning.n_of_bins,
79 p_side_binning.x_min, p_side_binning.x_max, fMaxCluSize, 1, fMaxCluSize + 1);
80
81 h_name = Form("0x%x_Qn_vs_size%s", address, mod);
82 fH2D[h_name] = std::make_unique<TH2D>(h_name.c_str(), h_name.c_str(), n_side_binning.n_of_bins,
83 n_side_binning.x_min, n_side_binning.x_max, fMaxCluSize, 1, fMaxCluSize + 1);
84
85 h_name = Form("0x%x_psize_vs_nsize%s", address, mod);
86 fH2D[h_name] = std::make_unique<TH2D>(h_name.c_str(), h_name.c_str(), fMaxCluSize, 1, fMaxCluSize + 1, fMaxCluSize,
87 1, fMaxCluSize + 1);
88
89 h_name = Form("0x%x_y_vs_x%s", address, mod);
90 fH2D[h_name] = std::make_unique<TH2D>(h_name.c_str(), h_name.c_str(), x_binning.n_of_bins, x_binning.x_min,
91 x_binning.x_max, y_binning.n_of_bins, y_binning.x_min, y_binning.x_max);
92
93 h_name = Form("0x%x_cluster_dt%s", address, mod);
94 fH1D[h_name] =
95 std::make_unique<TH1D>(h_name.c_str(), h_name.c_str(), t_binning.n_of_bins, t_binning.x_min, t_binning.x_max);
96 }
97}
98
100{
101 if (fAnalysisCuts != nullptr && !fAnalysisCuts->CheckEvent(evt)) return;
102
103 int nb_sts_hits = evt->GetNofData(ECbmDataType::kStsHit);
104 for (int hit_evt_idx = 0; hit_evt_idx < nb_sts_hits; hit_evt_idx++) {
105 int sts_hit_idx = evt->GetIndex(ECbmDataType::kStsHit, hit_evt_idx);
106 CbmStsHit* hit = (CbmStsHit*) fStsHitArray->UncheckedAt(sts_hit_idx);
107 ProcessHit(hit, false);
108 }
109
110 int nb_of_glob_trk = evt->GetNofData(ECbmDataType::kGlobalTrack);
111 for (int evt_glob_trk_idx = 0; evt_glob_trk_idx < nb_of_glob_trk; evt_glob_trk_idx++) {
112 int glob_trk_idx = evt->GetIndex(ECbmDataType::kGlobalTrack, evt_glob_trk_idx);
113 CbmGlobalTrack* glob_trk = (CbmGlobalTrack*) fGlbTrkArray->UncheckedAt(glob_trk_idx);
114 ProcessGlobalTrack(glob_trk);
115 }
116}
117
118void CbmStsHitAna::ProcessHit(CbmStsHit* hit, bool belong_to_trk)
119{
120 if (hit == nullptr) return;
121 int32_t address = hit->GetAddress();
122
123 if (fAnalysisCuts != nullptr && !fAnalysisCuts->CheckStsHit(hit, fStsCluArray)) {
124 return;
125 }
126
127 if (!fAddressBook.count(address)) {
128 fAddressBook.insert(address);
129 BookHistograms(address);
130 }
131
134
135 int32_t size_n = cbm_sts_utils::GetHitCluSizeF(hit, fStsCluArray);
136 int32_t size_p = cbm_sts_utils::GetHitCluSizeB(hit, fStsCluArray);
137
138 const char* mod = fHitModifier[belong_to_trk];
139
140 fH1D[Form("0x%x_Q_asymmetry%s", address, mod)]->Fill(cbm_sts_utils::GetHitChargeAsy(hit, fStsCluArray));
141 fH2D[Form("0x%x_Qp_vs_Qn%s", address, mod)]->Fill(q_n, q_p);
142 fH2D[Form("0x%x_Qp_vs_size%s", address, mod)]->Fill(q_p, size_p);
143 fH2D[Form("0x%x_Qn_vs_size%s", address, mod)]->Fill(q_n, size_n);
144 fH2D[Form("0x%x_psize_vs_nsize%s", address, mod)]->Fill(size_p, size_n);
145 fH2D[Form("0x%x_y_vs_x%s", address, mod)]->Fill(hit->GetX(), hit->GetY());
146 fH1D[Form("0x%x_cluster_dt%s", address, mod)]->Fill(cbm_sts_utils::GetHitTimeF(hit, fStsCluArray)
148}
149
151{
152 auto sts_trk_idx = trk->GetStsTrackIndex();
153 auto rich_trk_idx = trk->GetRichRingIndex();
154 auto much_trk_idx = trk->GetMuchTrackIndex();
155 auto trd_trk_idx = trk->GetTrdTrackIndex();
156 auto tof_trk_idx = trk->GetTofTrackIndex();
157 float trk_p_val = TMath::Prob(trk->GetChi2(), trk->GetNDF());
158
159 // Apply GlobalTracks cuts
160 int32_t mvd_trk_size = sts_trk_idx != -1 && fStsTrkArray != nullptr
161 ? ((CbmStsTrack*) fStsTrkArray->UncheckedAt(sts_trk_idx))->GetNofMvdHits()
162 : 0;
163
164 int32_t sts_trk_size = sts_trk_idx != -1 && fStsTrkArray != nullptr
165 ? ((CbmStsTrack*) fStsTrkArray->UncheckedAt(sts_trk_idx))->GetNofStsHits()
166 : 0;
167
168 int32_t rich_trk_size = rich_trk_idx != -1 && fRchTrkArray != nullptr
169 ? ((CbmTrack*) fRchTrkArray->UncheckedAt(rich_trk_idx))->GetNofHits()
170 : 0;
171
172 int32_t much_trk_size = much_trk_idx != -1 && fMchTrkArray != nullptr
173 ? ((CbmTrack*) fMchTrkArray->UncheckedAt(much_trk_idx))->GetNofHits()
174 : 0;
175
176 int32_t trd_trk_size = trd_trk_idx != -1 && fTrdTrkArray != nullptr
177 ? ((CbmTrack*) fTrdTrkArray->UncheckedAt(trd_trk_idx))->GetNofHits()
178 : 0;
179
180 int32_t tof_trk_size = tof_trk_idx != -1 && fTofTrkArray != nullptr
181 ? ((CbmTrack*) fTofTrkArray->UncheckedAt(tof_trk_idx))->GetNofHits()
182 : 0;
183
184 if (fAnalysisCuts != nullptr
185 && (!fAnalysisCuts->Check(CbmCutId::kGlobalTrackMvdSize, mvd_trk_size)
186 || !fAnalysisCuts->Check(CbmCutId::kGlobalTrackStsSize, sts_trk_size)
187 || !fAnalysisCuts->Check(CbmCutId::kGlobalTrackRichSize, rich_trk_size)
188 || !fAnalysisCuts->Check(CbmCutId::kGlobalTrackMuchSize, much_trk_size)
189 || !fAnalysisCuts->Check(CbmCutId::kGlobalTrackTrdSize, trd_trk_size)
190 || !fAnalysisCuts->Check(CbmCutId::kGlobalTrackTofSize, tof_trk_size)
192 || !fAnalysisCuts->Check(CbmCutId::kGlobalTrackPval, trk_p_val))) {
193 return;
194 }
195 LOG(debug) << Form("Processing %d StsHit that were attached to a CATrack", sts_trk_size);
196 CbmStsTrack* sts_track = (CbmStsTrack*) fStsTrkArray->UncheckedAt(sts_trk_idx);
197
198 // ------------------------------------
199 // Process StsHit attached to a CATrack
200 // ------------------------------------
201 for (int hit_idx = 0; hit_idx < sts_trk_size; hit_idx++) {
202 uint32_t sts_hit_idx = sts_track->GetStsHitIndex(hit_idx);
203 CbmStsHit* sts_hit = (CbmStsHit*) fStsHitArray->UncheckedAt(sts_hit_idx);
204 ProcessHit(sts_hit, true);
205 }
206 // ------------------------------------
207}
208
209void CbmStsHitAna::Exec(Option_t*)
210{
211 if (fCbmEvtArray != nullptr) {
212 uint32_t nb_events = fCbmEvtArray->GetEntriesFast();
213 double avg_nb_sts_hits = 0;
214 double avg_nb_of_glob_trk = 0;
215 for (uint32_t evt_idx = 0; evt_idx < nb_events; evt_idx++) {
216 ProcessEvent((CbmEvent*) fCbmEvtArray->UncheckedAt(evt_idx));
217 avg_nb_sts_hits += ((CbmEvent*) fCbmEvtArray->UncheckedAt(evt_idx))->GetNofData(ECbmDataType::kStsHit);
218 avg_nb_of_glob_trk += ((CbmEvent*) fCbmEvtArray->UncheckedAt(evt_idx))->GetNofData(ECbmDataType::kGlobalTrack);
219 }
220 LOG_IF(info, nb_events) << "Running CbmStsHitAna - Event-like - Entry: " << entry_ << "\tEvents: " << nb_events
221 << "\tAvg StsHit/Events: " << avg_nb_sts_hits / nb_events
222 << "\tAvg GlobalTrk/Events: " << avg_nb_of_glob_trk / nb_events;
223 LOG_IF(info, !nb_events) << "Running CbmStsHitAna - Event-like - Entry: " << entry_ << "\tEvents: " << nb_events;
224 }
225 else {
226 uint32_t n_of_hits = fStsHitArray->GetEntriesFast();
227 LOG(info) << "Running CbmStsHitAna - Time-like - Entry: " << entry_ << "\tStsHits: " << n_of_hits;
228 for (uint32_t hit_idx = 0; hit_idx < n_of_hits; hit_idx++) {
229 CbmStsHit* sts_hit = (CbmStsHit*) fStsHitArray->UncheckedAt(hit_idx);
230 ProcessHit(sts_hit, false);
231 }
232 }
233 entry_++;
234}
235
237{
238 SaveToFile();
239 fH1D.clear();
240 fH2D.clear();
241}
@ kGlobalTrackMvdSize
Definition CbmCutId.h:132
@ kGlobalTrackChi2
Definition CbmCutId.h:126
@ kGlobalTrackMuchSize
Definition CbmCutId.h:141
@ kGlobalTrackTrdSize
Definition CbmCutId.h:144
@ kGlobalTrackStsSize
Definition CbmCutId.h:135
@ kGlobalTrackPval
Definition CbmCutId.h:127
@ kGlobalTrackTofSize
Definition CbmCutId.h:147
@ kGlobalTrackRichSize
Definition CbmCutId.h:138
Data class for STS tracks.
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 GetStsTrackIndex() const
double GetChi2() const
int32_t GetRichRingIndex() const
int32_t GetTofTrackIndex() const
int32_t GetMuchTrackIndex() const
int32_t GetNDF() const
int32_t GetTrdTrackIndex() const
int32_t GetAddress() const
Definition CbmHit.h:77
double GetY() const
Definition CbmPixelHit.h:74
double GetX() const
Definition CbmPixelHit.h:73
CbmCutMap * fAnalysisCuts
std::unordered_set< int32_t > fAddressBook
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
std::map< std::string, std::unique_ptr< TH1D > > fH1D
TClonesArray * fStsHitArray
TClonesArray * fStsCluArray
TClonesArray * fTofTrkArray
void BookHistograms(int32_t)
std::unique_ptr< CbmStsParSetModule > fModuleParSet
void ProcessHit(CbmStsHit *hit, bool belong_to_trk=false)
Process an STS hit It filters hits based on the provided CbmCutMap and fill the corresponding histogr...
uint32_t fMaxCluSize
TClonesArray * fTrdTrkArray
void Exec(Option_t *)
TClonesArray * fMchTrkArray
std::vector< const char * > fHitModifier
InitStatus Init()
TClonesArray * fGlbTrkArray
void ProcessEvent(CbmEvent *)
Process an Cbm events It filters event based on the provided CbmCutMap.
void ProcessGlobalTrack(CbmGlobalTrack *)
Process an STS hit attached to a Track It filters hits based on the provided CbmCutMap and check the ...
std::string fCalibrationFile
TClonesArray * fStsTrkArray
TClonesArray * fCbmEvtArray
TClonesArray * fRchTrkArray
data class for a reconstructed 3-d hit in the STS
Definition CbmStsHit.h:35
Parameters for one STS module.
int32_t GetStsHitIndex(int32_t iHit) const
int32_t GetHitCluSizeB(CbmStsHit *hit=nullptr, TClonesArray *clusters=nullptr)
Get the cluster size of a hit from the back side.
double GetHitChargeAsy(CbmStsHit *hit=nullptr, TClonesArray *clusters=nullptr)
Get the charge asymmetry of a hit.
static const double kStsDy
Definition CbmStsUtils.h:22
double GetHitChargeF(CbmStsHit *hit=nullptr, TClonesArray *clusters=nullptr)
Get the charge of a hit from the front side.
double GetHitTimeB(CbmStsHit *hit=nullptr, TClonesArray *clusters=nullptr)
Get the charge of a hit from the back side.
std::pair< HBinning, HBinning > ChargeBinning(const CbmStsParModule &par_module, const uint32_t max_clu_size=1)
Generate the charge binning from module config obj.
static const double kStsClock
Definition CbmStsUtils.h:20
double GetHitChargeB(CbmStsHit *hit=nullptr, TClonesArray *clusters=nullptr)
Get the charge of a hit from the back side.
double GetHitTimeF(CbmStsHit *hit=nullptr, TClonesArray *clusters=nullptr)
Get the charge of a hit from the front side.
static const double kStsDx
Definition CbmStsUtils.h:21
int32_t GetHitCluSizeF(CbmStsHit *hit=nullptr, TClonesArray *clusters=nullptr)
Get the cluster size of a hit from the front side.
Structure to hold the binning for 1D histogram.
Definition CbmStsUtils.h:92