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