REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
Loading...
Searching...
No Matches
TRestHaloTrimProcess.cxx
1
2
3#include "TRestHaloTrimProcess.h"
4#include "TRestHaloEvent.h"
5#include "TRestHaloMetadata.h"
6
8
9TRestHaloTrimProcess::TRestHaloTrimProcess() : fEvent(nullptr), fTrimBins(8000) {}
10TRestHaloTrimProcess::~TRestHaloTrimProcess() {}
11
13 // Nothing needed for now.
14}
15
17 // Called once before processing begins; nothing to init here yet.
18}
19
21 if (!evInput) return nullptr;
22
23 // Try to interpret input as TRestHaloEvent
24 TRestHaloEvent* in = dynamic_cast<TRestHaloEvent*>(evInput);
25 if (!in) {
26 // Not a halo event, pass through unchanged
27 return evInput;
28 }
29
30 const auto& freqs = in->GetFrequencies();
31 const auto& vals = in->GetValues();
32 size_t n = vals.size();
33 if (n == 0 || freqs.size() != n) {
34 // Malformed event: nothing to do
35 return evInput;
36 }
37
38 // Convert values to power (W) if needed
39 std::vector<double> converted;
40 converted.reserve(n);
41 auto stored = in->GetStoredUnit();
42 for (size_t i = 0; i < n; ++i) {
43 double v = vals[i];
44 double p = v;
45 if (stored == TRestHaloMetadata::V_RMS) {
46 // Convert volts to watts (VoltsToWatts returns watts)
47 p = TRestHaloEvent::VoltsToWatts(v);
48 }
49 // If already in W (watts) we keep as-is. Note: TRestHaloMetadata uses W
50 converted.push_back(p);
51 }
52
53 // Determine trimming bounds
54 size_t trim = static_cast<size_t>(std::max(0, fTrimBins));
55 if (n <= 2 * trim) {
56 // Too short after trimming: return converted (no trimming)
57 // Create a new event with converted values and W unit
58 TRestHaloEvent* out = new TRestHaloEvent();
59 out->SetSpectrum(freqs, converted, TRestHaloMetadata::W);
60 return out;
61 }
62
63 size_t first = trim;
64 size_t last_excl = n - trim;
65 std::vector<double> tfreqs;
66 std::vector<double> tvals;
67 tfreqs.reserve(last_excl - first);
68 tvals.reserve(last_excl - first);
69 for (size_t i = first; i < last_excl; ++i) {
70 tfreqs.push_back(freqs[i]);
71 tvals.push_back(converted[i]);
72 }
73
74 // Create new output event (power units)
75 TRestHaloEvent* out = new TRestHaloEvent();
76 out->SetSpectrum(tfreqs, tvals, TRestHaloMetadata::W);
77
78 return out;
79}
80
82 // Nothing to finalize for now.
83}
84
85// Note: SetTrimBins/GetTrimBins are implemented inline in the header.
A base class for any REST event.
Definition TRestEvent.h:38
Process that converts and trims halo spectra.
void InitProcess() override
To be executed at the beginning of the run (outside event loop).
void EndProcess() override
To be executed at the end of the run (outside event loop).
Int_t fTrimBins
pointer to input event
void Initialize() override
Making default settings.
TRestEvent * ProcessEvent(TRestEvent *eventInput) override
Process one event.