REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
TRestRawSignalEvent.h
1/*************************************************************************
2 * This file is part of the REST software framework. *
3 * *
4 * Copyright (C) 2016 GIFNA/TREX (University of Zaragoza) *
5 * For more information see http://gifna.unizar.es/trex *
6 * *
7 * REST is free software: you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation, either version 3 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * REST is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have a copy of the GNU General Public License along with *
18 * REST in $REST_PATH/LICENSE. *
19 * If not, see http://www.gnu.org/licenses/. *
20 * For the list of contributors see $REST_PATH/CREDITS. *
21 *************************************************************************/
22
23#ifndef RestDAQ_TRestRawSignalEvent
24#define RestDAQ_TRestRawSignalEvent
25
26#include <TAxis.h>
27#include <TGraph.h>
28#include <TPad.h>
29#include <TRestEvent.h>
30#include <TRestRawReadoutMetadata.h>
31#include <TRestRun.h>
32#include <TVector2.h>
33
34#include <iostream>
35#include <string>
36
37#include "TRestRawSignal.h"
38
41 protected:
42 TGraph* gr;
43 Double_t fMinTime;
44 Double_t fMaxTime;
45 Double_t fMinValue;
46 Double_t fMaxValue;
47
48 TVector2 fBaseLineRange = TVector2(-1, -1);
49 TVector2 fRange = TVector2(-1, -1);
50
51 std::vector<TRestRawSignal> fSignal; // Collection of signals that define the event
52
53 private:
54 void SetMaxAndMin();
55
56 public:
57 Bool_t signalIDExists(Int_t sID) {
58 if (GetSignalIndex(sID) == -1) return false;
59 return true;
60 }
61
62 std::vector<TRestRawSignal> GetSignals() const { return fSignal; }
63
64 // Setters
65 void AddSignal(TRestRawSignal& s);
66
67 void RemoveSignalWithId(Int_t sId);
68
69 void AddChargeToSignal(Int_t sgnlID, Int_t bin, Short_t value);
70
71 void SetTailPoints(Int_t p) {
72 for (int n = 0; n < GetNumberOfSignals(); n++) fSignal[n].SetTailPoints(p);
73 }
74
77 void SetBaseLineRange(TVector2 blRange, std::string option = "") {
78 SetBaseLineRange(blRange.X(), blRange.Y(), option);
79 }
80
83 void SetBaseLineRange(Int_t from, Int_t to, std::string option = "") {
84 fBaseLineRange = TVector2(from, to);
85 for (int n = 0; n < GetNumberOfSignals(); n++) fSignal[n].CalculateBaseLine(from, to, option);
86 }
87
88 void SetRange(TVector2 range) { SetRange(range.X(), range.Y()); }
89
90 void SetRange(Int_t from, Int_t to) {
91 fRange = TVector2(from, to);
92 for (int n = 0; n < GetNumberOfSignals(); n++) fSignal[n].SetRange(fRange);
93 }
94
95 // Getters
96 inline Int_t GetNumberOfSignals() const { return fSignal.size(); }
97 TRestRawSignal* GetSignal(Int_t n) { return &fSignal[n]; }
98
99 void PrintSignalIds() {
100 for (int n = 0; n < GetNumberOfSignals(); n++) {
101 if (n > 0) std::cout << " , ";
102 std::cout << GetSignal(n)->GetSignalID();
103 }
104 std::cout << std::endl;
105 }
106
107 std::vector<int> GetSignalIds() {
108 std::vector<int> ids;
109 for (int n = 0; n < GetNumberOfSignals(); n++) ids.push_back(GetSignal(n)->GetSignalID());
110 return ids;
111 }
112
113 Bool_t isBaseLineInitialized() {
114 // If one signal is initialized we assume initialization happened for any signal
115 for (int n = 0; n < GetNumberOfSignals(); n++)
116 if (fSignal[n].isBaseLineInitialized()) return true;
117 return false;
118 }
119
120 TRestRawSignal* GetSignalById(Int_t sid) {
121 Int_t index = GetSignalIndex(sid);
122 if (index < 0) return nullptr;
123
124 return &fSignal[index];
125 }
126
127 TRestRawSignalEvent GetSignalEventForType(const std::string& type) const;
128 TRestRawSignalEvent GetSignalEventForTypes(
129 const std::set<std::string>& types, const TRestRawReadoutMetadata* readoutMetadata = nullptr) const;
130
131 TRestRawSignal* GetMaxSignal();
132
133 Int_t GetLowestWidth(Double_t minPeakAmplitude = 0);
134 Double_t GetLowAverageWidth(Int_t nSignals = 5, Double_t minPeakAmplitude = 0);
135 Double_t GetAverageWidth(Double_t minPeakAmplitude = 0);
136
137 Int_t GetSignalIndex(Int_t signalID);
138
139 Double_t GetBaseLineAverage();
140 Double_t GetBaseLineSigmaAverage();
141 // void SubtractBaselines();
142 Double_t GetIntegral();
143 Double_t GetThresholdIntegral();
144
145 Double_t GetSlopeIntegral();
146 Double_t GetRiseSlope();
147 Double_t GetRiseTime();
148 Double_t GetTripleMaxIntegral();
149
150 Double_t GetMaxValue();
151 Double_t GetMinValue();
152 Double_t GetMinTime();
153 Double_t GetMaxTime();
154
155 // Default
156 void Initialize();
157 void PrintEvent();
158
159 TPad* DrawEvent(const TString& option = "");
160 void DrawSignals(TPad* pad, const std::vector<Int_t>& signals);
161 TPad* DrawSignal(Int_t signalID, const TString& option = "");
162
163 TRestRawReadoutMetadata* GetReadoutMetadata() const;
164
165 // Constructor
167 // Destructor
168 virtual ~TRestRawSignalEvent();
169
170 ClassDef(TRestRawSignalEvent, 1);
171};
172#endif
A base class for any REST event.
Definition: TRestEvent.h:38
An event container for time rawdata signals with fixed length.
void DrawSignals(TPad *pad, const std::vector< Int_t > &signals)
This method draws selected signal IDs, given by the vector passed as reference.
TPad * DrawEvent(const TString &option="")
This method draws current raw signal event in a TPad.
void SetBaseLineRange(Int_t from, Int_t to, std::string option="")
TPad * DrawSignal(Int_t signalID, const TString &option="")
This method draws selected signalID by ID, with baseline range and points over threshold highlighted.
void SetBaseLineRange(TVector2 blRange, std::string option="")
void AddChargeToSignal(Int_t sgnlID, Int_t bin, Short_t value)
It defines a Short_t array with a physical parameter that evolves in time using a fixed time bin.
Int_t GetSignalID() const
Returns the value of signal ID.