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  Double_t fAuxiliar = 0;
48 
49  TVector2 fBaseLineRange = TVector2(-1, -1);
50  TVector2 fRange = TVector2(-1, -1);
51 
52  std::vector<TRestRawSignal> fSignal; // Collection of signals that define the event
53 
54  private:
55  void SetMaxAndMin();
56 
57  public:
58  Bool_t signalIDExists(Int_t sID) {
59  if (GetSignalIndex(sID) == -1) return false;
60  return true;
61  }
62 
63  std::vector<TRestRawSignal> GetSignals() const { return fSignal; }
64 
65  // Setters
66  void AddSignal(TRestRawSignal& s);
67 
68  void RemoveSignalWithId(Int_t sId);
69 
70  void AddChargeToSignal(Int_t sgnlID, Int_t bin, Short_t value);
71 
72  void SetTailPoints(Int_t p) {
73  for (int n = 0; n < GetNumberOfSignals(); n++) fSignal[n].SetTailPoints(p);
74  }
75 
76  // Set and Get a tmp variable (for BiPo)
77  void SetAuxiliar(Double_t aux);
78  auto GetAuxiliar() { return fAuxiliar; }
79 
82  void SetBaseLineRange(TVector2 blRange, std::string option = "") {
83  SetBaseLineRange(blRange.X(), blRange.Y(), option);
84  }
85 
88  void SetBaseLineRange(Int_t from, Int_t to, std::string option = "") {
89  fBaseLineRange = TVector2(from, to);
90  for (int n = 0; n < GetNumberOfSignals(); n++) fSignal[n].CalculateBaseLine(from, to, option);
91  }
92 
93  void SetRange(TVector2 range) { SetRange(range.X(), range.Y()); }
94 
95  void SetRange(Int_t from, Int_t to) {
96  fRange = TVector2(from, to);
97  for (int n = 0; n < GetNumberOfSignals(); n++) fSignal[n].SetRange(fRange);
98  }
99 
100  // Getters
101  inline Int_t GetNumberOfSignals() const { return fSignal.size(); }
102  TRestRawSignal* GetSignal(Int_t n) { return &fSignal[n]; }
103 
104  void PrintSignalIds() {
105  for (int n = 0; n < GetNumberOfSignals(); n++) {
106  if (n > 0) std::cout << " , ";
107  std::cout << GetSignal(n)->GetSignalID();
108  }
109  std::cout << std::endl;
110  }
111 
112  std::vector<int> GetSignalIds() {
113  std::vector<int> ids;
114  for (int n = 0; n < GetNumberOfSignals(); n++) ids.push_back(GetSignal(n)->GetSignalID());
115  return ids;
116  }
117 
118  Bool_t isBaseLineInitialized() {
119  // If one signal is initialized we assume initialization happened for any signal
120  for (int n = 0; n < GetNumberOfSignals(); n++)
121  if (fSignal[n].isBaseLineInitialized()) return true;
122  return false;
123  }
124 
125  TRestRawSignal* GetSignalById(Int_t sid) {
126  Int_t index = GetSignalIndex(sid);
127  if (index < 0) return nullptr;
128 
129  return &fSignal[index];
130  }
131 
132  TRestRawSignalEvent GetSignalEventForType(const std::string& type) const;
133  TRestRawSignalEvent GetSignalEventForTypes(
134  const std::set<std::string>& types, const TRestRawReadoutMetadata* readoutMetadata = nullptr) const;
135 
136  TRestRawSignal* GetMaxSignal();
137 
138  Int_t GetLowestWidth(Double_t minPeakAmplitude = 0);
139  Double_t GetLowAverageWidth(Int_t nSignals = 5, Double_t minPeakAmplitude = 0);
140  Double_t GetAverageWidth(Double_t minPeakAmplitude = 0);
141 
142  Int_t GetSignalIndex(Int_t signalID);
143 
144  Double_t GetBaseLineAverage();
145  Double_t GetBaseLineSigmaAverage();
146  // void SubtractBaselines();
147  Double_t GetIntegral();
148  Double_t GetThresholdIntegral();
149 
150  Double_t GetSlopeIntegral();
151  Double_t GetRiseSlope();
152  Double_t GetRiseTime();
153  Double_t GetTripleMaxIntegral();
154 
155  Double_t GetMaxValue();
156  Double_t GetMinValue();
157  Double_t GetMinTime();
158  Double_t GetMaxTime();
159 
160  // Default
161  void Initialize();
162  void PrintEvent();
163 
164  TPad* DrawEvent(const TString& option = "");
165  void DrawSignals(TPad* pad, const std::vector<Int_t>& signals);
166  TPad* DrawSignal(Int_t signalID, const TString& option = "");
167 
168  TRestRawReadoutMetadata* GetReadoutMetadata() const;
169 
170  // Constructor
172  // Destructor
173  virtual ~TRestRawSignalEvent();
174 
175  ClassDef(TRestRawSignalEvent, 1);
176 };
177 #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.