REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
Loading...
Searching...
No Matches
TRestHaloEvent.h
1#ifndef RestCore_TRestHaloEvent
2#define RestCore_TRestHaloEvent
3
4#include "TRestEvent.h"
5#include "TRestHaloMetadata.h"
6#include <vector>
7
8// Unified event for haloscope power (or volts) spectra.
9// Stores a single data vector whose units
10// are described in the associated TRestHaloMetadata (V_RMS or W).
11class TRestHaloEvent : public TRestEvent {
12private:
13 std::vector<double> fFrequency; // Hz
14 std::vector<double> fValues; // stored values (units in metadata)
15 std::vector<double> fUncertainties; // per-bin uncertainties (same units as values)
16
17 // metadata containing units and acquisition info
18 TRestHaloMetadata fMetadata;
19
20 double fStartFrequency = 0; // Hz
21 double fStopFrequency = 0; // Hz
22 double fResolution = 0; // Hz per bin
23 double fStdDev = 0; // Sample standard deviation across all bins
24
25public:
26 TRestHaloEvent();
27 ~TRestHaloEvent();
28
29 // Accept input values and optionally their per-bin uncertainties
30 // If no uncertainties are provided, they can be added later via SetUncertainties
31 void SetSpectrum(const std::vector<double>& freq,
32 const std::vector<double>& values,
33 TRestHaloMetadata::EValueUnit unit,
34 const std::vector<double>& uncertainties = std::vector<double>());
35
36 // Set or update uncertainties for an existing spectrum
37 void SetUncertainties(const std::vector<double>& uncertainties);
38
39 const std::vector<double>& GetFrequencies() const { return fFrequency; }
40 const std::vector<double>& GetValues() const { return fValues; }
41 const std::vector<double>& GetUncertainties() const { return fUncertainties; }
42
43 const TRestHaloMetadata& GetMetadata() const { return fMetadata; }
44 TRestHaloMetadata& GetMetadata() { return fMetadata; }
45
46 // Query stored unit
47 TRestHaloMetadata::EValueUnit GetStoredUnit() const {
48 return static_cast<TRestHaloMetadata::EValueUnit>(fMetadata.GetValueUnit());
49 }
50
51 // Return value at nearest frequency bin converted to outUnit
52 double GetValueAtFrequency(double f, TRestHaloMetadata::EValueUnit outUnit) const;
53
54 // Convenience overload: returns value in stored unit
55 double GetValueAtFrequency(double f) const { return GetValueAtFrequency(f, GetStoredUnit()); }
56
57 // Get standard deviation of spectrum
58 double GetStdDev() const { return fStdDev; }
59
60 // Statistics (converted to outUnit)
61
62 void PrintEvent() const override;
63 void Initialize() override;
64
65 // Draw the event as a graph (frequency vs value). Returns the pad used.
66 virtual TPad* DrawEvent(const TString& option = "") override;
67 // Provide a custom browser entry so TBrowser can show a drawable graph
68 virtual void Browse(TBrowser* b) override;
69
70 // conversion helpers
71 static double VoltsToWatts(double v) { return v * v * 8.0; }
72 static double WattsToVolts(double w) { return std::sqrt(std::max(0.0, w / 8.0)); }
73
74 ClassDefOverride(TRestHaloEvent, 1);
75};
76
77#endif
virtual TPad * DrawEvent(const TString &option="") override
Draw the event.
void Initialize() override
void PrintEvent() const override
Dedicated metadata for halo/acquisition settings.