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#include "ShipUnit.h"
12
13snd::analysis_tools::USPlane::USPlane(std::vector<MuFilterHit*> snd_hits, const Configuration &configuration, MuFilter *muon_filter_geometry, int station, bool use_small_sipms_sipms) : configuration_(configuration), centroid_(std::nan(""), std::nan(""), std::nan("")), centroid_error_(std::nan(""), std::nan(""),std::nan("")), station_(station)
14{
15 for ( auto mu_hit : snd_hits)
16 {
17 TVector3 A, B;
18 int detectorID = mu_hit->GetDetectorID();
19 muon_filter_geometry->GetPosition(detectorID, A, B);
20 for (int i{0}; i < 16; ++i)
21 {
22 if (mu_hit->isMasked(i) || mu_hit->GetSignal(i) < -990.) continue;
23 USHit hit;
24 hit.bar = static_cast<int>(detectorID % 1000);
25 hit.channel_index = 16 * hit.bar + i;
26 hit.is_large = !mu_hit->isShort(i);
27 hit.is_right = i > 7 ? true : false;
28
29 if (!hit.is_large && !use_small_sipms_sipms)
30 {
31 hit.timestamp = std::nan("");
32 hit.qdc = std::nan("");
33 hit.x = std::nan("");
34 hit.y = std::nan("");
35 hit.z = std::nan("");
36 }
37 else
38 {
39 hit.timestamp = configuration_.is_mc ? mu_hit->GetTime(i) / ShipUnit::snd_TDC2ns : mu_hit->GetTime(i);
40 hit.qdc = mu_hit->GetSignal(i);
41 // use the left and right measurements to calculate the x coordinate along the bar
42 float timeConversion = configuration_.is_mc ? 1. : ShipUnit::snd_TDC2ns;
43 hit.x = A.X() - 0.5*(mu_hit->GetDeltaT()*timeConversion*configuration_.us_signal_speed+configuration_.us_bar_length);
44 hit.y = A.Y();
45 hit.z = A.Z();
46 }
47 hits_.push_back(hit);
48 }
49 }
50}
51
53{
54 // select large SiPM channels with positive qdc
55 std::vector<USHit> cleaned_hits = hits_;
56
57 cleaned_hits.erase(std::remove_if(cleaned_hits.begin(), cleaned_hits.end(),
58 [&](auto &hit)
59 { return (hit.qdc <= 0 || hit.is_large == false); }),
60 cleaned_hits.end());
61
62 // min number of hit in the plane to attempt to find a centroid
63 if (static_cast<int>(cleaned_hits.size()) < configuration_.us_min_n_hits_for_centroid)
64 {
65 // std::cout<<"Not enough hits in US plane " << station_ <<" to find centroid\n";
66 return;
67 }
68
69 // weigthed sum calculated per plane
70 double weighted_sum_x{0.0}, weighted_sum_y{0.0}, weighted_sum_z{0.0};
71 double total_qdc_positive{0.0}, sum_qdc2_positive{0.0};
72 // loop over hits in the plane
73 for (const auto &hit : cleaned_hits)
74 {
75 weighted_sum_x += hit.x * hit.qdc;
76 weighted_sum_y += hit.y * hit.qdc;
77 weighted_sum_z += hit.z * hit.qdc;
78 total_qdc_positive += hit.qdc;
79 sum_qdc2_positive += hit.qdc*hit.qdc;
80 }
81 weighted_sum_x /= total_qdc_positive;
82 weighted_sum_y /= total_qdc_positive;
83 weighted_sum_z /= total_qdc_positive;
84 centroid_.SetXYZ(weighted_sum_x, weighted_sum_y, weighted_sum_z);
85 auto qdc_error_scaler = sqrt(sum_qdc2_positive)/total_qdc_positive;
86 centroid_error_.SetXYZ(configuration_.us_centroid_error_x*qdc_error_scaler,
87 configuration_.us_centroid_error_y*qdc_error_scaler,
88 configuration_.us_centroid_error_z*qdc_error_scaler);
89}
90
92{
93 sl_pair<double> totQdc{0.0, 0.0};
94 for (const auto &hit : hits_)
95 {
96 if (hit.is_large)
97 totQdc.large += hit.qdc;
98 else
99 totQdc.small += hit.qdc;
100 }
101 return totQdc;
102}
103
105{
106 sl_pair<double> tot_energy{0.0, 0.0};
107 sl_pair<double> tot_qdc = GetTotQdc();
108
109 tot_energy.large = tot_qdc.large *configuration_.us_qdc_to_gev;
110 tot_energy.small = tot_qdc.small *configuration_.us_qdc_to_gev;
111
112 return tot_energy;
113}
114
115
117{
118 rl_pair<double> side_qdc{0.0, 0.0};
119 for (const auto &hit : hits_)
120 {
121 if (hit.is_large)
122 {
123 if (hit.is_right)
124 side_qdc.right += hit.qdc;
125 else
126 side_qdc.left += hit.qdc;
127 }
128 }
129 return side_qdc;
130}
131
133{
134 rl_pair<double> bar_qdc{0.0, 0.0};
135 for (const auto &hit : hits_)
136 {
137 if (hit.bar != bar_to_compute)
138 continue;
139 else
140 {
141 if (hit.is_large)
142 {
143 if (hit.is_right)
144 bar_qdc.right += hit.qdc;
145 else
146 bar_qdc.left += hit.qdc;
147 }
148 }
149 }
150 return bar_qdc;
151}
152
154{
155 sl_pair<int> bar_hit{0, 0};
156 for (const auto &hit : hits_)
157 {
158 if (hit.bar != bar_to_compute)
159 continue;
160 else
161 {
162 if (hit.is_large)
163
164 bar_hit.large++;
165 else
166 bar_hit.small++;
167
168 }
169 }
170 return bar_hit;
171}
172
173void snd::analysis_tools::USPlane::TimeFilter(double min_timestamp, double max_timestamp)
174{
175 hits_.erase(std::remove_if(hits_.begin(), hits_.end(),
176 [&](auto &hit)
177 { return hit.timestamp < min_timestamp || hit.timestamp > max_timestamp; }),
178 hits_.end());
179}
180
182{
183 sl_pair<int> counts{0, 0};
184 counts.large = std::count_if(hits_.begin(), hits_.end(), [](auto &hit)
185 { return hit.is_large; });
186 counts.small = static_cast<int>(hits_.size()) - counts.large;
187
188 return counts;
189}
190
192 int count{0};
193 for (int bar{0}; bar < configuration_.us_bar_per_station; ++bar) {
194 if (GetBarNHits(bar).large > configuration_.us_min_hit_on_bar) count++;
195 }
196 return count;
197}
198
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(std::vector< MuFilterHit * > snd_hits, const Configuration &configuration, MuFilter *muon_filter_geometry, int station, bool use_small_sipms=false)
const int GetNHitBars() const
std::vector< USHit > hits_
Definition sndUSPlane.h:70
const sl_pair< double > GetTotQdc() const
const sl_pair< double > GetTotEnergy() const
void TimeFilter(double min_timestamp, double max_timestamp)