SND@LHC Software
Loading...
Searching...
No Matches
sndUSPlane.cxx
Go to the documentation of this file.
1#include "sndUSPlane.h"
2
3#include <cmath>
4#include <stdexcept>
5#include <algorithm>
6#include <vector>
7
8#include "TClonesArray.h"
9#include "TVector3.h"
10#include "MuFilter.h"
11#include "MuFilterHit.h"
12
13snd::analysis_tools::USPlane::USPlane(TClonesArray *snd_hits, snd::Configuration configuration, MuFilter *muon_filter_geometry, int index_begin, int index_end, int station) : configuration_(configuration), centroid_(std::nan(""), std::nan(""), std::nan("")), centroid_error_(std::nan(""), std::nan(""),std::nan("")), station_(station)
14{
15 if (index_begin > index_end)
16 {
17 throw std::runtime_error{"Begin index > end index"};
18 }
19 for (int j{index_begin}; j < index_end; ++j)
20 {
21 auto mu_hit = static_cast<MuFilterHit *>(snd_hits->At(j));
22
23 for (int i{0}; i < 16; ++i)
24 {
25 if (mu_hit->isMasked(i) || mu_hit->GetSignal(i) < -990.) continue;
26 USHit hit;
27 hit.bar = static_cast<int>(mu_hit->GetDetectorID() % 1000);
28 hit.channel_index = 16 * hit.bar + i;
29 hit.timestamp = mu_hit->GetTime(i);
30 hit.qdc = mu_hit->GetSignal(i);
31 hit.is_large = !mu_hit->isShort(i);
32
33 TVector3 A, B;
34 int detectorID = mu_hit->GetDetectorID();
35 muon_filter_geometry->GetPosition(detectorID, A, B);
36 hit.is_right = i > 7 ? true : false;
37 hit.x = hit.is_right ? B.X() : A.X();
38 hit.y = A.Y();
39 hit.z = A.Z();
40 hits_.push_back(hit);
41 }
42 }
43}
44
46{
47 // min number of hit in the plane to attempt to find a centroid
48 if (hits_.size() < configuration_.us_min_n_hits_for_centroid)
49 {
50 // std::cout<<"Not enough hits in US plane " << station_ <<" to find centroid\n";
51 return;
52 }
53
54 double total_qdc = GetTotQdc().large;
55 if (total_qdc > 0.0)
56 {
57 for (const auto &hit : hits_)
58 {
59 // weigthed sum
60 double weighted_sum_x{0.0}, weighted_sum_y{0.0}, weighted_sum_z{0.0};
61 double total_qdc_positive{0.0};
62
63 if (hit.qdc > 0.0)
64 {
65 weighted_sum_x += hit.x * hit.qdc;
66 weighted_sum_y += hit.y * hit.qdc;
67 weighted_sum_z += hit.z * hit.qdc;
68 total_qdc_positive += hit.qdc;
69 }
70
71 double x = weighted_sum_x / total_qdc_positive;
72 double y = weighted_sum_y / total_qdc_positive;
73 double z = weighted_sum_z / total_qdc_positive;
74 centroid_.SetXYZ(x, y, z);
75 }
76 }
77 centroid_error_.SetXYZ(configuration_.us_centroid_error_x, configuration_.us_centroid_error_y, configuration_.us_centroid_error_z);
78}
79
81{
82 sl_pair<double> totQdc{0.0, 0.0};
83 for (const auto &hit : hits_)
84 {
85 if (hit.is_large)
86 totQdc.large += hit.qdc;
87 else
88 totQdc.small += hit.qdc;
89 }
90 return totQdc;
91}
92
94{
95 sl_pair<double> tot_energy{0.0, 0.0};
96 sl_pair<double> tot_qdc = GetTotQdc();
97
98 tot_energy.large = tot_qdc.large *configuration_.us_qdc_to_gev;
99 tot_energy.small = tot_qdc.small *configuration_.us_qdc_to_gev;
100
101 return tot_energy;
102}
103
104
106{
107 rl_pair<double> side_qdc{0.0, 0.0};
108 for (const auto &hit : hits_)
109 {
110 if (hit.is_large)
111 {
112 if (hit.is_right)
113 side_qdc.right += hit.qdc;
114 else
115 side_qdc.left += hit.qdc;
116 }
117 }
118 return side_qdc;
119}
120
122{
123 rl_pair<double> bar_qdc{0.0, 0.0};
124 for (const auto &hit : hits_)
125 {
126 if (hit.bar != bar_to_compute)
127 continue;
128 else
129 {
130 if (hit.is_large)
131 {
132 if (hit.is_right)
133 bar_qdc.right += hit.qdc;
134 else
135 bar_qdc.left += hit.qdc;
136 }
137 }
138 }
139 return bar_qdc;
140}
141
143{
144 sl_pair<int> bar_hit{0, 0};
145 for (const auto &hit : hits_)
146 {
147 if (hit.bar != bar_to_compute)
148 continue;
149 else
150 {
151 if (hit.is_large)
152
153 bar_hit.large++;
154 else
155 bar_hit.small++;
156
157 }
158 }
159 return bar_hit;
160}
161
162void snd::analysis_tools::USPlane::TimeFilter(double min_timestamp, double max_timestamp)
163{
164 hits_.erase(std::remove_if(hits_.begin(), hits_.end(),
165 [&](auto &hit)
166 { return hit.timestamp < min_timestamp || hit.timestamp > max_timestamp; }),
167 hits_.end());
168}
169
171{
172 sl_pair<int> counts{0, 0};
173 counts.large = std::count_if(hits_.begin(), hits_.end(), [](auto &hit)
174 { return hit.is_large; });
175 counts.small = hits_.size() - counts.large;
176
177 return counts;
178}
void GetPosition(Int_t id, TVector3 &vLeft, TVector3 &vRight)
Definition MuFilter.cxx:639
const rl_pair< double > GetBarQdc(int bar_to_compute) const
const sl_pair< int > GetBarNHits(int bar_to_compute) const
const rl_pair< double > GetSideQdc() const
const sl_pair< int > GetNHits() const
USPlane(TClonesArray *snd_hits, Configuration configuration, MuFilter *muon_filter_geometry, int index_begin, int index_end, int station)
std::vector< USHit > hits_
Definition sndUSPlane.h:67
const sl_pair< double > GetTotQdc() const
const sl_pair< double > GetTotEnergy() const
void TimeFilter(double min_timestamp, double max_timestamp)