REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
TRestRawSignalEvent.cxx
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
117
118#include "TRestRawSignalEvent.h"
119
120#include <TMath.h>
121
122#include "TRestStringHelper.h"
123
124using namespace std;
125
126ClassImp(TRestRawSignalEvent);
127
128TRestRawSignalEvent::TRestRawSignalEvent() {
129 // TRestRawSignalEvent default constructor
130 Initialize();
131}
132
133TRestRawSignalEvent::~TRestRawSignalEvent() {
134 // TRestRawSignalEvent destructor
135}
136
139 fSignal.clear();
140 fPad = nullptr;
141 gr = nullptr;
142
143 fMinValue = numeric_limits<Double_t>::max();
144 fMaxValue = numeric_limits<Double_t>::min();
145 fMinTime = numeric_limits<Double_t>::max();
146 fMaxTime = numeric_limits<Double_t>::min();
147}
148
149void TRestRawSignalEvent::AddSignal(TRestRawSignal& s) {
150 if (signalIDExists(s.GetSignalID())) {
151 cout << "Warning. Signal ID : " << s.GetSignalID()
152 << " already exists. Signal will not be added to signal event" << endl;
153 return;
154 }
155
156 s.CalculateBaseLine(fBaseLineRange.X(), fBaseLineRange.Y());
157 s.SetRange(fRange);
158
159 fSignal.emplace_back(s);
160}
161
162void TRestRawSignalEvent::RemoveSignalWithId(Int_t sId) {
163 Int_t index = GetSignalIndex(sId);
164
165 if (index == -1) {
166 cout << "Warning. Signal ID : " << sId
167 << " does not exist. Signal will not be removed from signal event" << endl;
168 return;
169 }
170
171 fSignal.erase(fSignal.begin() + index);
172}
173
174Int_t TRestRawSignalEvent::GetSignalIndex(Int_t signalID) {
175 for (int i = 0; i < GetNumberOfSignals(); i++)
176 if (fSignal[i].GetSignalID() == signalID) return i;
177 return -1;
178}
179
180Double_t TRestRawSignalEvent::GetIntegral() {
181 Double_t sum = 0;
182
183 for (int i = 0; i < GetNumberOfSignals(); i++) sum += fSignal[i].GetIntegral();
184
185 return sum;
186}
187
191 Double_t sum = 0;
192 for (int i = 0; i < GetNumberOfSignals(); i++) sum += fSignal[i].GetThresholdIntegral();
193 return sum;
194}
195
196TRestRawSignal* TRestRawSignalEvent::GetMaxSignal() {
197 if (GetNumberOfSignals() <= 0) return nullptr;
198
199 Double_t max = fSignal[0].GetIntegral();
200
201 Int_t sId = 0;
202 for (int i = 0; i < GetNumberOfSignals(); i++) {
203 Int_t integ = fSignal[i].GetIntegral();
204 if (max < integ) {
205 max = integ;
206 sId = i;
207 }
208 }
209
210 return &fSignal[sId];
211}
212
213Double_t TRestRawSignalEvent::GetSlopeIntegral() {
214 Double_t sum = 0;
215
216 for (int i = 0; i < GetNumberOfSignals(); i++) sum += fSignal[i].GetSlopeIntegral();
217
218 return sum;
219}
220
221Double_t TRestRawSignalEvent::GetRiseSlope() {
222 Double_t sum = 0;
223
224 Int_t n = 0;
225 for (int i = 0; i < GetNumberOfSignals(); i++) {
226 if (fSignal[i].GetThresholdIntegral() > 0) {
227 sum += fSignal[i].GetSlopeIntegral();
228 n++;
229 }
230 }
231
232 if (n == 0) return 0;
233
234 return sum / n;
235}
236
237Double_t TRestRawSignalEvent::GetRiseTime() {
238 Double_t sum = 0;
239
240 Int_t n = 0;
241 for (int i = 0; i < GetNumberOfSignals(); i++) {
242 if (fSignal[i].GetThresholdIntegral() > 0) {
243 sum += fSignal[i].GetRiseTime();
244 n++;
245 }
246 }
247
248 if (n == 0) return 0;
249
250 return sum / n;
251}
252
253Double_t TRestRawSignalEvent::GetTripleMaxIntegral() {
254 Double_t sum = 0;
255
256 for (int i = 0; i < GetNumberOfSignals(); i++)
257 if (fSignal[i].GetThresholdIntegral() > 0) sum += fSignal[i].GetTripleMaxIntegral();
258
259 return sum;
260}
261
262Double_t TRestRawSignalEvent::GetBaseLineAverage() {
263 Double_t baseLineMean = 0;
264
265 for (int signal = 0; signal < GetNumberOfSignals(); signal++) {
266 Double_t baseline = GetSignal(signal)->GetBaseLine();
267 baseLineMean += baseline;
268 }
269
270 return baseLineMean / GetNumberOfSignals();
271}
272
273Int_t TRestRawSignalEvent::GetLowestWidth(Double_t minPeakAmplitude) {
274 Int_t low = 10000000;
275
276 for (int signal = 0; signal < GetNumberOfSignals(); signal++) {
277 if (GetSignal(signal)->GetMaxPeakValue() > minPeakAmplitude) {
278 Int_t lW = GetSignal(signal)->GetMaxPeakWidth();
279 if (low > lW) low = lW;
280 }
281 }
282
283 return low;
284}
285
286Double_t TRestRawSignalEvent::GetAverageWidth(Double_t minPeakAmplitude) {
287 Double_t avg = 0;
288 Int_t n = 0;
289 for (int signal = 0; signal < GetNumberOfSignals(); signal++) {
290 if (GetSignal(signal)->GetMaxPeakValue() > minPeakAmplitude) {
291 avg += GetSignal(signal)->GetMaxPeakWidth();
292 n++;
293 }
294 }
295
296 if (n == 0)
297 return 0;
298 else
299 return avg / n;
300}
301
302Double_t TRestRawSignalEvent::GetLowAverageWidth(Int_t nSignals, Double_t minPeakAmplitude) {
303 std::vector<Double_t> widths;
304
305 for (int signal = 0; signal < GetNumberOfSignals(); signal++)
306 if (GetSignal(signal)->GetMaxPeakValue() > minPeakAmplitude)
307 widths.push_back(GetSignal(signal)->GetMaxPeakWidth());
308
309 if (widths.size() == 0) return 0;
310
311 std::sort(widths.begin(), widths.end());
312
313 Int_t nMax = nSignals;
314 if (widths.size() < (unsigned int)nSignals) nMax = widths.size();
315
316 Double_t avg = 0;
317 for (int n = 0; n < nMax; n++) avg += widths[n];
318
319 return avg / nSignals;
320}
321
322Double_t TRestRawSignalEvent::GetBaseLineSigmaAverage() {
323 Double_t baseLineSigmaMean = 0;
324
325 for (int signal = 0; signal < GetNumberOfSignals(); signal++) {
326 Double_t baselineSigma = GetSignal(signal)->GetBaseLineSigma();
327 baseLineSigmaMean += baselineSigma;
328 }
329
330 return baseLineSigmaMean / GetNumberOfSignals();
331}
332
338// void TRestRawSignalEvent::subtractBaselines() {
339// for (int signal = 0; signal < GetNumberOfSignals(); signal++)
340// GetSignal(signal)->subtractBaseline();
341//}
342
343void TRestRawSignalEvent::AddChargeToSignal(Int_t signalID, Int_t bin, Short_t value) {
344 Int_t signalIndex = GetSignalIndex(signalID);
345 if (signalIndex == -1) {
346 signalIndex = GetNumberOfSignals();
347
348 TRestRawSignal signal(512); // For the moment we use the default nBins=512
349 signal.SetSignalID(signalID);
350 AddSignal(signal);
351 }
352
353 fSignal[signalIndex].IncreaseBinBy(bin, value);
354}
355
356void TRestRawSignalEvent::PrintEvent() {
358
359 for (int i = 0; i < GetNumberOfSignals(); i++) {
360 cout << "================================================" << endl;
361 cout << "Signal ID : " << fSignal[i].GetSignalID() << endl;
362 cout << "Integral : " << fSignal[i].GetIntegral() << endl;
363 cout << "------------------------------------------------" << endl;
364 fSignal[i].Print();
365 cout << "================================================" << endl;
366 }
367}
368
369// TODO: GetMaxTimeFast, GetMinTimeFast, GetMaxValueFast that return the value
370// of fMinTime, fMaxTime, etc
371void TRestRawSignalEvent::SetMaxAndMin() {
372 fMinValue = numeric_limits<Double_t>::max();
373 fMaxValue = numeric_limits<Double_t>::min();
374 fMinTime = numeric_limits<Double_t>::max();
375 fMaxTime = numeric_limits<Double_t>::min();
376
377 for (int s = 0; s < GetNumberOfSignals(); s++) {
378 if (fMinValue > fSignal[s].GetMinValue()) {
379 fMinValue = fSignal[s].GetMinValue();
380 }
381 if (fMaxValue < fSignal[s].GetMaxValue()) {
382 fMaxValue = fSignal[s].GetMaxValue();
383 }
384 }
385
386 if (GetNumberOfSignals() > 0) {
387 fMaxTime = fSignal[0].GetNumberOfPoints();
388 }
389}
390
391Double_t TRestRawSignalEvent::GetMaxValue() {
392 SetMaxAndMin();
393 return fMaxValue;
394}
395
396Double_t TRestRawSignalEvent::GetMinValue() {
397 SetMaxAndMin();
398 return fMinValue;
399}
400
401Double_t TRestRawSignalEvent::GetMinTime() { return 0; }
402
403Double_t TRestRawSignalEvent::GetMaxTime() {
404 Double_t maxTime = 512;
405
406 if (GetNumberOfSignals() > 0) maxTime = fSignal[0].GetNumberOfPoints();
407
408 return maxTime;
409}
410
411// An auxiliar variable that can be used to store temporal values.
412Double_t fAuxiliar = 0;
413void TRestRawSignalEvent::SetAuxiliar(Double_t aux) { fAuxiliar = aux; }
414auto GetAuxiliar() { return fAuxiliar; }
415
467TPad* TRestRawSignalEvent::DrawEvent(const TString& option) {
468 const int nSignals = GetNumberOfSignals();
469
470 if (fPad != nullptr) {
471 delete fPad;
472 fPad = nullptr;
473 }
474
475 if (nSignals == 0) {
476 cout << "Empty event " << endl;
477 return nullptr;
478 }
479
480 fMinValue = numeric_limits<Double_t>::max();
481 fMaxValue = numeric_limits<Double_t>::min();
482 fMinTime = numeric_limits<Double_t>::max();
483 fMaxTime = numeric_limits<Double_t>::min();
484
485 fPad = new TPad(GetName(), " ", 0, 0, 1, 1);
486 fPad->Draw();
487 fPad->cd();
488 // fPad->DrawFrame(0, GetMinValue() - 1, GetMaxTime() + 1, GetMaxValue() + 1);
489
490 char title[256];
491 vector<TString> optList = Vector_cast<string, TString>(TRestTools::GetOptions((string)option));
492
493 bool thresholdCheck = false;
494 bool baselineCheck = false;
495 bool sRangeID = false;
496 bool printIDs = false;
497
498 double signalTh = 0, pointTh = 0, nOver = 0;
499 int baseLineRangeInit = 0, baseLineRangeEnd = 0;
500 int sRangeInit = 0, sRangeEnd = 0;
501
502 for (const auto& opt : optList) {
503 std::string str = (std::string)opt;
504 // Read threshold option
505 if (str.find("onlyGoodSignals[") != string::npos) {
506 size_t startPos = str.find('[');
507 size_t endPos = str.find(']');
508 TString tmpStr = opt(startPos + 1, endPos - startPos - 1);
509 vector<TString> optList_2 = Vector_cast<string, TString>(Split((string)tmpStr, ","));
510
511 pointTh = StringToDouble((string)optList_2[0]);
512 signalTh = StringToDouble((string)optList_2[1]);
513 nOver = StringToDouble((string)optList_2[2]);
514
515 thresholdCheck = true;
516 }
517
518 // Read baseline option
519 if (str.find("baseLineRange[") != string::npos) {
520 size_t startPos2 = str.find('[');
521 size_t endPos2 = str.find(']');
522 TString tmpStr2 = opt(startPos2 + 1, endPos2 - startPos2 - 1);
523 vector<TString> optList_3 = Vector_cast<string, TString>(Split((string)tmpStr2, ","));
524
525 baseLineRangeInit = StringToInteger((string)optList_3[0]);
526 baseLineRangeEnd = StringToInteger((string)optList_3[1]);
527
528 baselineCheck = true;
529 }
530
531 // Read signal range ID option
532 if (str.find("signalRangeID[") != string::npos || str.find("ids[") != string::npos) {
533 size_t startPos3 = str.find('[');
534 size_t endPos3 = str.find(']');
535 TString tmpStr3 = opt(startPos3 + 1, endPos3 - startPos3 - 1);
536 vector<TString> optList_4;
537 if (str.find(',') != string::npos)
538 optList_4 = Vector_cast<string, TString>(Split((string)tmpStr3, ","));
539 else if (str.find('-') != string::npos)
540 optList_4 = Vector_cast<string, TString>(Split((string)tmpStr3, "-"));
541 else
542 RESTError << "TRestRawSignalEvent::DrawEvent not valid ids format!" << RESTendl;
543
544 sRangeInit = StringToInteger((string)optList_4[0]);
545 sRangeEnd = StringToInteger((string)optList_4[1]);
546
547 sRangeID = true;
548 }
549
550 // Read print ID option
551 if (str.find("printIDs") != string::npos) {
552 printIDs = true;
553 cout << "IDs of printed signals: " << endl;
554 }
555 }
556
557 std::vector<int> signalIDs; // Signal IDs to print
558
560 if ((optList.empty()) || !(isANumber((string)optList[0]))) {
561 // If threshold and baseline options are given
562 if (thresholdCheck && baselineCheck) {
563 RESTDebug << "Draw only good signals with: " << RESTendl;
564 RESTDebug << " Signal threshold: " << signalTh << RESTendl;
565 RESTDebug << " Point threshold: " << pointTh << RESTendl;
566 RESTDebug << " Points over threshold: " << nOver << RESTendl;
567 RESTDebug << " Base line range: (" << baseLineRangeInit << "," << baseLineRangeEnd << ")"
568 << RESTendl;
569
570 for (int n = 0; n < nSignals; n++) {
571 fSignal[n].CalculateBaseLine(baseLineRangeInit, baseLineRangeEnd);
572 fSignal[n].InitializePointsOverThreshold(TVector2(pointTh, signalTh), nOver);
573 if (fSignal[n].GetPointsOverThreshold().size() >= 2) {
574 signalIDs.push_back(fSignal[n].GetID());
575 }
576 }
577 // If no threshold and baseline options are given
578 } else {
579 for (int n = 0; n < nSignals; n++) {
580 signalIDs.push_back(fSignal[n].GetID());
581 }
582 }
583
584 // Remove SIDs which are not in range
585 if (sRangeID) {
586 for (auto it = signalIDs.begin(); it != signalIDs.end();)
587 if (*it >= sRangeInit && *it <= sRangeEnd) {
588 ++it;
589 } else {
590 it = signalIDs.erase(it);
591 }
592 }
593
594 cout << "Number of drawn signals: " << signalIDs.size() << endl;
595
597 } else if (isANumber((string)optList[0])) {
598 string str = (string)optList[0];
599 size_t separation = str.find('-');
600
601 // Signals range //
602 if (separation != string::npos) {
603 TString firstSignal = optList[0](0, separation);
604 TString lastSignal = optList[0](separation + 1, str.size());
605 RESTDebug << "First signal: " << firstSignal << RESTendl;
606 RESTDebug << "Last signal: " << lastSignal << RESTendl;
607
608 if (StringToInteger((string)lastSignal) >= (int)fSignal.size()) {
609 fPad->SetTitle("No Such Signal");
610 cout << "No such last signal" << endl;
611 return fPad;
612 }
613
614 sprintf(title, "Event ID %d", this->GetID());
615
616 if (thresholdCheck && baselineCheck) {
617 RESTDebug << "Draw only good signals with: " << RESTendl;
618 RESTDebug << " Signal threshold: " << signalTh << RESTendl;
619 RESTDebug << " Point threshold: " << pointTh << RESTendl;
620 RESTDebug << " Points over threshold: " << nOver << RESTendl;
621 RESTDebug << " Base line range: (" << baseLineRangeInit << "," << baseLineRangeEnd << ")"
622 << RESTendl;
623
624 for (int n = 0; n < nSignals; n++) {
625 if (n < StringToInteger((string)firstSignal) || n > StringToInteger((string)lastSignal))
626 continue;
627 fSignal[n].CalculateBaseLine(baseLineRangeInit, baseLineRangeEnd);
628 fSignal[n].InitializePointsOverThreshold(TVector2(pointTh, signalTh), nOver);
629 if (fSignal[n].GetPointsOverThreshold().size() >= 2) {
630 signalIDs.push_back(fSignal[n].GetID());
631 }
632 }
633 cout << "Number of good signals in range (" << firstSignal << "," << lastSignal
634 << "): " << signalIDs.size() << endl;
635 // If no threshold and baseline options are given
636 } else {
637 for (int n = StringToInteger((string)firstSignal);
638 n < StringToInteger((string)lastSignal) + 1; n++) {
639 signalIDs.push_back(fSignal[n].GetID());
640 }
641 }
642 // Single signal
643 } else {
644 int signalID = StringToInteger((string)optList[0]);
645 signalIDs.push_back(signalID);
646 }
647 }
648
649 if (signalIDs.empty()) {
650 fPad->SetTitle("No Such Signal");
651 cout << "No signals found" << endl;
652 return fPad;
653 }
654
655 if (printIDs) {
656 cout << "SignalIDs:";
657 auto sortedSignalsIDs = signalIDs;
658 sort(sortedSignalsIDs.begin(), sortedSignalsIDs.end());
659 for (const auto& signalID : sortedSignalsIDs) {
660 cout << " " << signalID;
661 }
662 cout << endl;
663 }
664
665 DrawSignals(fPad, signalIDs);
666
667 return fPad;
668}
669
674void TRestRawSignalEvent::DrawSignals(TPad* pad, const std::vector<Int_t>& signals) {
675 int maxSID = -1;
676 int max = numeric_limits<Short_t>::min();
677 int graphIndex = 1;
678
679 for (const auto& s : signals) {
680 TRestRawSignal* signal = GetSignalById(s);
681 if (!signal) {
682 continue;
683 }
684 TGraph* graph = signal->GetGraph(graphIndex++);
685 const double maxValue = TMath::MaxElement(graph->GetN(), graph->GetY());
686 if (maxValue > max) {
687 max = maxValue;
688 maxSID = s;
689 }
690 }
691
692 RESTDebug << "Max SID " << maxSID << RESTendl;
693
694 if (maxSID == -1) {
695 cout << "No signals ID found" << endl;
696 return;
697 }
698
699 TRestRawSignal* signalMaxID = GetSignalById(maxSID);
700 std::string title = "Event ID " + std::to_string(GetID());
701 if (signals.size() == 1) {
702 title += " Signal ID " + std::to_string(maxSID);
703 }
704
705 signalMaxID->fGraph->SetTitle(title.c_str());
706 signalMaxID->fGraph->GetXaxis()->SetTitle("Time bin");
707 signalMaxID->fGraph->GetYaxis()->SetTitleOffset(1.4);
708 signalMaxID->fGraph->GetYaxis()->SetTitle("Amplitude [a.u.]");
709 pad->Draw();
710 pad->cd();
711 signalMaxID->fGraph->SetLineColor(kBlack);
712 signalMaxID->fGraph->Draw("AL");
713
714 for (const auto& signalID : signals) {
715 if (signalID == maxSID) {
716 continue;
717 }
718 TRestRawSignal* signal = GetSignalById(signalID);
719 pad->cd();
720 signal->fGraph->Draw("L");
721 }
722
723 pad->Update();
724}
725
746TPad* TRestRawSignalEvent::DrawSignal(Int_t signalID, const TString& option) {
747 int nSignals = this->GetNumberOfSignals();
748
749 if (fPad != nullptr) {
750 for (int n = 0; n < nSignals; n++) {
751 delete fSignal[n].fGraph;
752 fSignal[n].fGraph = nullptr;
753 }
754 delete fPad;
755 fPad = nullptr;
756 }
757
758 if (nSignals == 0) {
759 cout << "Empty event " << endl;
760 return nullptr;
761 }
762
763 vector<TString> optList = Vector_cast<string, TString>(TRestTools::GetOptions((string)option));
764
765 double signalTh = 0, pointTh = 0, nOver = 0;
766 int baseLineRangeInit = 0, baseLineRangeEnd = 0;
767
768 for (auto& opt : optList) {
769 string str = (string)opt;
770
771 // Read threshold option
772 size_t goodSigOpt = str.find("goodSignals[");
773
774 if (goodSigOpt != string::npos) {
775 size_t startPos = str.find('[');
776 size_t endPos = str.find(']');
777 TString tmpStr = opt(startPos + 1, endPos - startPos - 1);
778 vector<TString> optList_2 = Vector_cast<string, TString>(Split((string)tmpStr, ","));
779
780 pointTh = StringToDouble((string)optList_2[0]);
781 signalTh = StringToDouble((string)optList_2[1]);
782 nOver = StringToDouble((string)optList_2[2]);
783 }
784
785 // Read baseline option
786 size_t BLOpt = str.find("baseLineRange[");
787
788 if (BLOpt != string::npos) {
789 size_t startPos2 = str.find('[');
790 size_t endPos2 = str.find(']');
791 TString tmpStr2 = opt(startPos2 + 1, endPos2 - startPos2 - 1);
792 vector<TString> optList_3 = Vector_cast<string, TString>(Split((string)tmpStr2, ","));
793
794 baseLineRangeInit = StringToInteger((string)optList_3[0]);
795 baseLineRangeEnd = StringToInteger((string)optList_3[1]);
796 }
797 }
798
799 fPad = new TPad(this->GetName(), " ", 0, 0, 1, 1);
800 fPad->Draw();
801 fPad->cd();
802
803 TGraph* gr = new TGraph();
804
805 TRestRawSignal* signal = this->GetSignalById(signalID);
806 signal->CalculateBaseLine(baseLineRangeInit, baseLineRangeEnd);
807 signal->InitializePointsOverThreshold(TVector2(pointTh, signalTh), nOver);
808
809 RESTInfo << "Drawing signalID. Event ID : " << this->GetID() << " Signal ID : " << signal->GetID()
810 << RESTendl;
811
812 for (int n = 0; n < signal->GetNumberOfPoints(); n++) {
813 gr->SetPoint(n, n, signal->GetData(n));
814 }
815
816 gr->Draw("AC*");
817
818 TGraph* gr2 = new TGraph();
819
820 gr2->SetLineWidth(2);
821 gr2->SetLineColor(2); // Red
822
823 for (int n = baseLineRangeInit; n < baseLineRangeEnd; n++) {
824 gr2->SetPoint(n - baseLineRangeInit, n, signal->GetData(n));
825 }
826
827 gr2->Draw("CP");
828
829 vector<Int_t> pOver = signal->GetPointsOverThreshold();
830
831 TGraph* gr3[5];
832 Int_t nGraphs = 0;
833 gr3[nGraphs] = new TGraph();
834 gr3[nGraphs]->SetLineWidth(2);
835 gr3[nGraphs]->SetLineColor(3);
836 Int_t point = 0;
837 Int_t nPoints = pOver.size();
838 for (int n = 0; n < nPoints; n++) {
839 gr3[nGraphs]->SetPoint(point, pOver[n], signal->GetData(pOver[n]));
840 point++;
841 if (n + 1 < nPoints && pOver[n + 1] - pOver[n] > 1) {
842 gr3[nGraphs]->Draw("CP");
843 nGraphs++;
844 if (nGraphs > 4) cout << "Ngraphs : " << nGraphs << endl;
845 point = 0;
846 gr3[nGraphs] = new TGraph();
847 gr3[nGraphs]->SetLineWidth(2);
848 gr3[nGraphs]->SetLineColor(3); // Green
849 }
850 }
851
852 if (nPoints > 0) {
853 gr3[nGraphs]->Draw("CP");
854 }
855
856 return fPad;
857}
858
859TRestRawReadoutMetadata* TRestRawSignalEvent::GetReadoutMetadata() const {
860 if (fRun == nullptr) {
861 RESTError << "TRestRawSignalEvent::GetReadoutMetadata: fRun is nullptr" << RESTendl;
862 return nullptr;
863 }
864 return dynamic_cast<TRestRawReadoutMetadata*>(fRun->GetMetadataClass("TRestRawReadoutMetadata"));
865}
866
867TRestRawSignalEvent TRestRawSignalEvent::GetSignalEventForType(const string& type) const {
868 return GetSignalEventForTypes({type});
869}
870
871TRestRawSignalEvent TRestRawSignalEvent::GetSignalEventForTypes(
872 const std::set<std::string>& types, const TRestRawReadoutMetadata* readoutMetadata) const {
873 // TODO: verify this works
874 TRestRawSignalEvent signalEvent;
875 signalEvent.SetEventInfo((TRestEvent*)this);
876 auto metadata = readoutMetadata ? readoutMetadata : GetReadoutMetadata();
877 if (metadata == nullptr) {
878 // cerr << "TRestRawSignalEvent::GetSignalEventForTypes: metadata is nullptr" << endl;
879 // exit(1);
880 }
881 for (const auto& signal : fSignal) {
882 if (types.empty() ||
883 types.find(metadata->GetTypeForChannelDaqId(signal.GetSignalID())) != types.end()) {
884 signalEvent.AddSignal(const_cast<TRestRawSignal&>(signal));
885 }
886 }
887 return signalEvent;
888}
A base class for any REST event.
Definition: TRestEvent.h:38
void SetEventInfo(TRestEvent *eve)
Definition: TRestEvent.cxx:137
virtual void PrintEvent() const
Definition: TRestEvent.cxx:187
virtual void Initialize()=0
Definition: TRestEvent.cxx:73
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.
TPad * DrawSignal(Int_t signalID, const TString &option="")
This method draws selected signalID by ID, with baseline range and points over threshold highlighted.
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.
Double_t GetBaseLineSigma() const
Int_t GetID() const
Returns the value of signal ID.
TGraph * fGraph
A TGraph pointer used to store the TRestRawSignal drawing.
Double_t GetMaxPeakValue()
It returns the amplitude of the signal maximum, baseline will be corrected if CalculateBaseLine was c...
void CalculateBaseLine(Int_t startBin, Int_t endBin, const std::string &option="")
This method calculates the average and fluctuation of the baseline in the specified range and writes ...
void SetSignalID(Int_t sID)
It sets the id number of the signal.
std::vector< Int_t > GetPointsOverThreshold() const
Returns a std::vector containing the indexes of data points over threshold.
Double_t GetBaseLine() const
void InitializePointsOverThreshold(const TVector2 &thrPar, Int_t nPointsOver, Int_t nPointsFlat=512)
It initializes the fPointsOverThreshold array with the indexes of data points that are found over thr...
Int_t GetMaxPeakWidth()
It returns the temporal width of the peak with maximum amplitude inside the signal.
Double_t GetData(Int_t n) const
It returns the data value of point n including baseline correction.
TGraph * GetGraph(Int_t color=1)
It builds a TGraph object that can be used for drawing.
Int_t GetSignalID() const
Returns the value of signal ID.
void SetRange(const TVector2 &range)
It sets/constrains the range for any calculation.
Int_t GetNumberOfPoints() const
Returns the actual number of points, or size of the signal.
static std::vector< std::string > GetOptions(std::string optionsStr)
Returns all the options in an option string.
Definition: TRestTools.cxx:86
std::vector< std::string > Split(std::string in, std::string separator, bool allowBlankString=false, bool removeWhiteSpaces=false, int startPos=-1)
Split the input string according to the given separator. Returning a vector of fragments.
Double_t StringToDouble(std::string in)
Gets a double from a string.
Int_t StringToInteger(std::string in)
Gets an integer from a string.
Int_t isANumber(std::string in)
Returns 1 only if a valid number is found in the string in. If not it returns 0.