REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
TRestDetectorSignal.cxx
1
21// dec 2015:
22//
23// Javier Galan
25
26#include "TRestDetectorSignal.h"
27
28#include <TCanvas.h>
29#include <TF1.h>
30#include <TFitResult.h>
31#include <TH1.h>
32#include <TMath.h>
33#include <TRandom3.h>
34
35#include <algorithm>
36#include <limits>
37
38using namespace std;
39
40ClassImp(TRestDetectorSignal);
41
42TRestDetectorSignal::TRestDetectorSignal() {
43 // TRestDetectorSignal default constructor
44 fGraph = nullptr;
45 fSignalID = -1;
46 fSignalTime.clear();
47 fSignalCharge.clear();
48
49 fPointsOverThreshold.clear();
50}
51
52TRestDetectorSignal::~TRestDetectorSignal() = default;
53
54void TRestDetectorSignal::NewPoint(Double_t time, Double_t data) {
55 fSignalTime.push_back(time);
56 fSignalCharge.push_back(data);
57}
58
63void TRestDetectorSignal::IncreaseAmplitude(Double_t t, Double_t d) { IncreaseAmplitude({t, d}); }
64
72 Double_t x = p.X();
73 Double_t y = p.Y();
74 Int_t index = GetTimeIndex(x);
75
76 if (index >= 0) {
77 fSignalTime[index] = x;
78 fSignalCharge[index] += y;
79 } else {
80 fSignalTime.push_back(x);
81 fSignalCharge.push_back(y);
82 }
83}
84
92void TRestDetectorSignal::SetPoint(const TVector2& p) {
93 Int_t index = GetTimeIndex(p.X());
94 Double_t x = p.X();
95 Double_t y = p.Y();
96
97 if (index >= 0) {
98 fSignalTime[index] = x;
99 fSignalCharge[index] = y;
100 } else {
101 fSignalTime.push_back(x);
102 fSignalCharge.push_back(y);
103 }
104}
105
113void TRestDetectorSignal::SetPoint(Double_t t, Double_t d) {
114 TVector2 p(t, d);
115 SetPoint(p);
116}
117
122void TRestDetectorSignal::SetPoint(Int_t index, Double_t t, Double_t d) {
123 fSignalTime[index] = t;
124 fSignalCharge[index] = d;
125}
126
127Double_t TRestDetectorSignal::GetIntegral(Int_t startBin, Int_t endBin) const {
128 if (startBin < 0) {
129 startBin = 0;
130 }
131 if (endBin <= 0 || endBin > GetNumberOfPoints()) {
132 endBin = GetNumberOfPoints();
133 }
134
135 Double_t sum = 0;
136 for (int i = startBin; i < endBin; i++) {
137 sum += GetData(i);
138 }
139
140 return sum;
141}
142
143void TRestDetectorSignal::Normalize(Double_t scale) {
144 Double_t sum = GetIntegral();
145 for (int i = 0; i < GetNumberOfPoints(); i++) {
146 fSignalCharge[i] = scale * GetData(i) / sum;
147 }
148}
149
150Double_t TRestDetectorSignal::GetIntegralWithTime(Double_t startTime, Double_t endTime) const {
151 Double_t sum = 0;
152 for (int i = 0; i < GetNumberOfPoints(); i++) {
153 const auto time = GetTime(i);
154 if (time >= startTime && time <= endTime) {
155 sum += GetData(i);
156 }
157 }
158 return sum;
159}
160
161Double_t TRestDetectorSignal::GetMaxPeakWithTime(Double_t startTime, Double_t endTime) const {
162 Double_t max = std::numeric_limits<double>::min();
163 for (int i = 0; i < GetNumberOfPoints(); i++) {
164 if (GetTime(i) >= startTime && GetTime(i) < endTime) {
165 if (this->GetData(i) > max) max = GetData(i);
166 }
167 }
168 return max;
169}
170
171/* {{{
172Double_t TRestDetectorSignal::GetIntegralWithThreshold(Int_t from, Int_t to, Int_t startBaseline, Int_t
173endBaseline,
174 Double_t nSigmas, Int_t nPointsOverThreshold,
175 Double_t nMinSigmas) {
176 if (startBaseline < 0) startBaseline = 0;
177 if (endBaseline <= 0 || endBaseline > GetNumberOfPoints()) endBaseline = GetNumberOfPoints();
178
179 Double_t baseLine = GetBaseLine(startBaseline, endBaseline);
180
181 Double_t pointThreshold = nSigmas * GetBaseLineSigma(startBaseline, endBaseline);
182 Double_t signalThreshold = nMinSigmas * GetBaseLineSigma(startBaseline, endBaseline);
183
184 return GetIntegralWithThreshold(from, to, baseLine, pointThreshold, nPointsOverThreshold,
185 signalThreshold);
186}
187
188Double_t TRestDetectorSignal::GetIntegralWithThreshold(Int_t from, Int_t to, Double_t baseline,
189 Double_t pointThreshold, Int_t nPointsOverThreshold,
190 Double_t signalThreshold) {
191 Double_t sum = 0;
192 Int_t nPoints = 0;
193 fPointsOverThreshold.clear();
194
195 if (to > GetNumberOfPoints()) to = GetNumberOfPoints();
196
197 Float_t maxValue = 0;
198 for (int i = from; i < to; i++) {
199 if (GetData(i) > baseline + pointThreshold) {
200 if (GetData(i) > maxValue) maxValue = GetData(i);
201 nPoints++;
202 } else {
203 if (nPoints >= nPointsOverThreshold) {
204 Double_t sig = GetStandardDeviation(i - nPoints, i);
205 if (sig > signalThreshold) {
206 for (int j = i - nPoints; j < i; j++) {
207 sum += this->GetData(j);
208 fPointsOverThreshold.push_back(j);
209 }
210 }
211 }
212 nPoints = 0;
213 maxValue = 0;
214 }
215 }
216
217 if (nPoints >= nPointsOverThreshold) {
218 Double_t sig = GetStandardDeviation(to - nPoints, to);
219 if (sig > signalThreshold) {
220 for (int j = to - nPoints; j < to; j++) {
221 sum += this->GetData(j);
222 fPointsOverThreshold.push_back(j);
223 }
224 }
225 }
226
227 return sum;
228}
229}}} */
230
231Double_t TRestDetectorSignal::GetAverage(Int_t start, Int_t end) {
232 this->Sort();
233
234 if (end == 0) end = this->GetNumberOfPoints();
235
236 Double_t sum = 0;
237 for (int i = start; i <= end; i++) {
238 sum += this->GetData(i);
239 }
240 return sum / (end - start + 1);
241}
242
243Int_t TRestDetectorSignal::GetMaxPeakWidth() {
244 this->Sort();
245
246 Int_t mIndex = this->GetMaxIndex();
247 Double_t maxValue = this->GetData(mIndex);
248
249 Double_t value = maxValue;
250 Int_t rightIndex = mIndex;
251 while (value > maxValue / 2) {
252 value = this->GetData(rightIndex);
253 rightIndex++;
254 }
255 Int_t leftIndex = mIndex;
256 value = maxValue;
257 while (value > maxValue / 2) {
258 value = this->GetData(leftIndex);
259 leftIndex--;
260 }
261
262 return rightIndex - leftIndex;
263}
264
265Double_t TRestDetectorSignal::GetMaxPeakValue() { return GetData(GetMaxIndex()); }
266
267Int_t TRestDetectorSignal::GetMaxIndex(Int_t from, Int_t to) {
268 Double_t max = std::numeric_limits<double>::min();
269 Int_t index = 0;
270
271 if (from < 0) {
272 from = 0;
273 }
274 if (to > GetNumberOfPoints()) {
275 to = GetNumberOfPoints();
276 }
277
278 if (to == 0) {
279 to = GetNumberOfPoints();
280 }
281
282 for (int i = from; i < to; i++) {
283 if (this->GetData(i) > max) {
284 max = GetData(i);
285 index = i;
286 }
287 }
288
289 return index;
290}
291
292// z position by gaussian fit
293
294optional<pair<Double_t, Double_t>>
295TRestDetectorSignal::GetPeakGauss() // returns a 2vector with the time of the peak time in us and the energy
296{
297 const auto indexMax =
298 std::distance(fSignalCharge.begin(), std::max_element(fSignalCharge.begin(), fSignalCharge.end()));
299 const auto timeMax = fSignalTime[indexMax];
300 const auto signalMax = fSignalCharge[indexMax];
301
302 // Define fit limits
303 Double_t threshold = signalMax * 0.9; // 90% of the maximum value
304
305 Double_t lowerLimit = timeMax, upperLimit = timeMax;
306
307 // Find the lower limit: time when signal drops to 90% of the max before the peak
308 for (auto i = indexMax; i >= 0; --i) {
309 if (fSignalCharge[i] <= threshold) {
310 lowerLimit = fSignalTime[i];
311 break;
312 }
313 }
314 // Find the upper limit: time when signal drops to 90% of the max after the peak
315 for (auto i = indexMax; i < GetNumberOfPoints(); ++i) {
316 if (fSignalCharge[i] <= threshold) {
317 lowerLimit = fSignalTime[i];
318 break;
319 }
320 }
321
322 TF1 gauss("gaus", "gaus", lowerLimit, upperLimit);
323
324 auto signal_graph = std::unique_ptr<TGraph>(GetGraph());
325
326 TFitResultPtr fitResult =
327 signal_graph->Fit(&gauss, "QNRS"); // Q = quiet, no info in screen; N = no plot; R = fit in
328 // the function range; S = save and return the fit result
329
330 if (!fitResult->IsValid()) {
331 return nullopt;
332 }
333
334 double energy = gauss.GetParameter(0);
335 double time = gauss.GetParameter(1);
336
337 return make_pair(time, energy);
338}
339
340// z position by landau fit
341
342optional<pair<Double_t, Double_t>>
343TRestDetectorSignal::GetPeakLandau() // returns a 2vector with the time of the peak time in us and the energy
344{
345 Int_t maxRaw = GetMaxIndex(); // The bin where the maximum of the raw signal is found
346 Double_t maxRawTime =
347 GetTime(maxRaw); // The time of the bin where the maximum of the raw signal is found
348
349 // Define fit limits
350 Double_t threshold = GetData(maxRaw) * 0.9; // 90% of the maximum value
351
352 Double_t lowerLimit = maxRawTime, upperLimit = maxRawTime;
353
354 // Find the lower limit: time when signal drops to 90% of the max before the peak
355 for (int i = maxRaw; i >= 0; --i) {
356 if (GetData(i) <= threshold) {
357 lowerLimit = GetTime(i);
358 break;
359 }
360 }
361
362 // Find the upper limit: time when signal drops to 90% of the max after the peak
363 for (int i = maxRaw; i < GetNumberOfPoints(); ++i) {
364 if (GetData(i) <= threshold) {
365 upperLimit = GetTime(i);
366 break;
367 }
368 }
369
370 TF1 landau("landau", "landau", lowerLimit, upperLimit);
371
372 auto signal_graph = std::unique_ptr<TGraph>(GetGraph());
373
374 TFitResultPtr fitResult =
375 signal_graph->Fit(&landau, "QNRS"); // Q = quiet, no info in screen; N = no plot; R = fit in the
376 // function range; S = save and return the fit result
377 if (!fitResult->IsValid()) {
378 return nullopt;
379 }
380
381 double energy = landau.GetParameter(0);
382 double time = landau.GetParameter(1);
383
384 return make_pair(time, energy);
385}
386
387// z position by aget fit
388
389Double_t agetResponseFunction(Double_t* x, Double_t* par) { // x contains as many elements as the number of
390 // dimensions (in this case 1, i.e. x[0]), and
391 // par contains as many elements as the number of free parameters in my function.
392
393 Double_t arg =
394 (x[0] - par[1] + 1.1664) /
395 par[2]; // 1.1664 is the x value where the maximum of the base function (i.e. without parameters) is.
396 Double_t f = par[0] / 0.0440895 * exp(-3 * (arg)) * (arg) * (arg) *
397 (arg)*sin(arg); // to rescale the Y axis and get amplitude.
398 return f;
399}
400
401optional<pair<Double_t, Double_t>>
402TRestDetectorSignal::GetPeakAget() // returns a 2vector with the time of the peak time in us and the energy
403{
404 Int_t maxRaw = GetMaxIndex(); // The bin where the maximum of the raw signal is found
405 Double_t maxRawTime =
406 GetTime(maxRaw); // The time of the bin where the maximum of the raw signal is found
407
408 // Define fit limits
409 Double_t threshold = GetData(maxRaw) * 0.9; // 90% of the maximum value
410
411 Double_t lowerLimit = maxRawTime, upperLimit = maxRawTime;
412
413 // Find the lower limit: time when signal drops to 90% of the max before the peak
414 for (int i = maxRaw; i >= 0; --i) {
415 if (GetData(i) <= threshold) {
416 lowerLimit = GetTime(i);
417 break;
418 }
419 }
420
421 // Find the upper limit: time when signal drops to 90% of the max after the peak
422 for (int i = maxRaw; i < GetNumberOfPoints(); ++i) {
423 if (GetData(i) <= threshold) {
424 upperLimit = GetTime(i);
425 break;
426 }
427 }
428
429 TF1 aget("aget", agetResponseFunction, lowerLimit, upperLimit, 3); //
430 aget.SetParameters(500, maxRawTime, 1.2);
431
432 auto signal_graph = std::unique_ptr<TGraph>(GetGraph());
433
434 TFitResultPtr fitResult =
435 signal_graph->Fit(&aget, "QNRS"); // Q = quiet, no info in screen; N = no plot; R = fit in
436 // the function range; S = save and return the fit result
437
438 if (!fitResult->IsValid()) {
439 return nullopt;
440 }
441
442 double energy = aget.GetParameter(0);
443 double time = aget.GetParameter(1);
444
445 return make_pair(time, energy);
446}
447
448Double_t TRestDetectorSignal::GetMaxPeakTime(Int_t from, Int_t to) { return GetTime(GetMaxIndex(from, to)); }
449
450Double_t TRestDetectorSignal::GetMinPeakValue() { return GetData(GetMinIndex()); }
451
452Int_t TRestDetectorSignal::GetMinIndex() const {
453 Double_t min = numeric_limits<Double_t>::max();
454 Int_t index = 0;
455
456 for (int i = 0; i < GetNumberOfPoints(); i++) {
457 if (this->GetData(i) < min) {
458 min = GetData(i);
459 index = i;
460 }
461 }
462
463 return index;
464}
465
466Double_t TRestDetectorSignal::GetMinTime() const {
467 if (GetNumberOfPoints() == 0) {
468 return 0;
469 }
470 Double_t minTime = numeric_limits<Double_t>::max();
471 for (int i = 0; i < GetNumberOfPoints(); i++) {
472 const Double_t time = GetTime(i);
473 if (time < minTime) {
474 minTime = time;
475 }
476 }
477 return minTime;
478}
479
480Double_t TRestDetectorSignal::GetMaxTime() const {
481 if (GetNumberOfPoints() == 0) {
482 return 0;
483 }
484 Double_t maxTime = numeric_limits<Double_t>::min();
485 for (int i = 0; i < GetNumberOfPoints(); i++) {
486 const auto time = GetTime(i);
487 if (time > maxTime) {
488 maxTime = time;
489 }
490 }
491 return maxTime;
492}
493
494Int_t TRestDetectorSignal::GetTimeIndex(Double_t t) {
495 Double_t time = t;
496
497 for (int n = 0; n < GetNumberOfPoints(); n++) {
498 if (time == fSignalTime[n]) {
499 return n;
500 }
501 }
502 return -1;
503}
504
505Bool_t TRestDetectorSignal::isSorted() const {
506 for (int i = 0; i < GetNumberOfPoints() - 1; i++) {
507 if (GetTime(i + 1) < GetTime(i)) {
508 return false;
509 }
510 }
511 return true;
512}
513
514void TRestDetectorSignal::Sort() {
515 while (!isSorted()) {
516 for (int i = 0; i < GetNumberOfPoints(); i++) {
517 for (int j = i; j < GetNumberOfPoints(); j++) {
518 if (GetTime(i) > GetTime(j)) {
519 iter_swap(fSignalTime.begin() + i, fSignalTime.begin() + j);
520 iter_swap(fSignalCharge.begin() + i, fSignalCharge.begin() + j);
521 }
522 }
523 }
524 }
525}
526
527void TRestDetectorSignal::GetDifferentialSignal(TRestDetectorSignal* diffSignal, Int_t smearPoints) {
528 this->Sort();
529
530 for (int i = 0; i < smearPoints; i++) diffSignal->IncreaseAmplitude(GetTime(i), 0);
531
532 for (int i = smearPoints; i < this->GetNumberOfPoints() - smearPoints; i++) {
533 Double_t value = (this->GetData(i + smearPoints) - GetData(i - smearPoints)) /
534 (GetTime(i + smearPoints) - GetTime(i - smearPoints));
535 Double_t time = (GetTime(i + smearPoints) + GetTime(i - smearPoints)) / 2.;
536
537 diffSignal->IncreaseAmplitude(time, value);
538 }
539
540 for (int i = GetNumberOfPoints() - smearPoints; i < GetNumberOfPoints(); i++) {
541 diffSignal->IncreaseAmplitude(GetTime(i), 0);
542 }
543}
544
545void TRestDetectorSignal::GetSignalDelayed(TRestDetectorSignal* delayedSignal, Int_t delay) {
546 this->Sort();
547
548 for (int i = 0; i < delay; i++) delayedSignal->IncreaseAmplitude(GetTime(i), GetData(i));
549
550 for (int i = delay; i < GetNumberOfPoints(); i++) {
551 delayedSignal->IncreaseAmplitude(GetTime(i), GetData(i - delay));
552 }
553}
554
555void TRestDetectorSignal::GetSignalSmoothed(TRestDetectorSignal* smthSignal, Int_t averagingPoints) {
556 this->Sort();
557
558 averagingPoints = (averagingPoints / 2) * 2 + 1; // make it odd >= averagingPoints
559
560 Double_t sum = GetIntegral(0, averagingPoints);
561 for (int i = 0; i <= averagingPoints / 2; i++)
562 smthSignal->IncreaseAmplitude(GetTime(i), sum / averagingPoints);
563
564 for (int i = averagingPoints / 2 + 1; i < GetNumberOfPoints() - averagingPoints / 2; i++) {
565 sum -= this->GetData(i - (averagingPoints / 2 + 1));
566 sum += this->GetData(i + averagingPoints / 2);
567 smthSignal->IncreaseAmplitude(this->GetTime(i), sum / averagingPoints);
568 }
569
570 for (int i = GetNumberOfPoints() - averagingPoints / 2; i < GetNumberOfPoints(); i++)
571 smthSignal->IncreaseAmplitude(GetTime(i), sum / averagingPoints);
572}
573
574Double_t TRestDetectorSignal::GetBaseLine(Int_t startBin, Int_t endBin) {
575 if (endBin - startBin <= 0) return 0.;
576
577 Double_t baseLine = 0;
578 for (int i = startBin; i < endBin; i++) baseLine += fSignalCharge[i];
579
580 return baseLine / (endBin - startBin);
581}
582
583Double_t TRestDetectorSignal::GetStandardDeviation(Int_t startBin, Int_t endBin) {
584 Double_t bL = GetBaseLine(startBin, endBin);
585 return GetBaseLineSigma(startBin, endBin, bL);
586}
587
588Double_t TRestDetectorSignal::GetBaseLineSigma(Int_t startBin, Int_t endBin, Double_t baseline) {
589 Double_t bL = baseline;
590 if (bL == 0) bL = GetBaseLine(startBin, endBin);
591
592 Double_t baseLineSigma = 0;
593 for (int i = startBin; i < endBin; i++)
594 baseLineSigma += (bL - fSignalCharge[i]) * (bL - fSignalCharge[i]);
595
596 return TMath::Sqrt(baseLineSigma / (endBin - startBin));
597}
598
599Double_t TRestDetectorSignal::SubstractBaseline(Int_t startBin, Int_t endBin) {
600 Double_t bL = GetBaseLine(startBin, endBin);
601
602 AddOffset(-bL);
603
604 return bL;
605}
606
607void TRestDetectorSignal::AddOffset(Double_t offset) {
608 for (int i = 0; i < GetNumberOfPoints(); i++) fSignalCharge[i] = fSignalCharge[i] + offset;
609}
610
611void TRestDetectorSignal::MultiplySignalBy(Double_t factor) {
612 for (int i = 0; i < GetNumberOfPoints(); i++) fSignalCharge[i] = factor * fSignalCharge[i];
613}
614
615void TRestDetectorSignal::ExponentialConvolution(Double_t fromTime, Double_t decayTime, Double_t offset) {
616 for (int i = 0; i < GetNumberOfPoints(); i++) {
617 if (fSignalTime[i] > fromTime) {
618 fSignalCharge[i] =
619 (fSignalCharge[i] - offset) * exp(-(fSignalTime[i] - fromTime) / decayTime) + offset;
620 }
621 }
622}
623
624void TRestDetectorSignal::SignalAddition(TRestDetectorSignal* inSignal) {
625 if (this->GetNumberOfPoints() != inSignal->GetNumberOfPoints()) {
626 cout << "ERROR : I cannot add two signals with different number of points" << endl;
627 return;
628 }
629
630 Int_t badSignalTimes = 0;
631
632 for (int i = 0; i < GetNumberOfPoints(); i++)
633 if (GetTime(i) != inSignal->GetTime(i)) {
634 cout << "Time : " << GetTime(i) << " != " << inSignal->GetTime(i) << endl;
635 badSignalTimes++;
636 }
637
638 if (badSignalTimes) {
639 cout << "ERROR : The times of signal addition must be the same" << endl;
640 return;
641 }
642
643 for (int i = 0; i < GetNumberOfPoints(); i++) fSignalCharge[i] += inSignal->GetData(i);
644}
645
646void TRestDetectorSignal::AddGaussianSignal(Double_t amp, Double_t sigma, Double_t time, Int_t N,
647 Double_t fromTime, Double_t toTime) {
648 for (int i = 0; i < N; i++) {
649 Double_t tme = fromTime + (double)i / (N - 1) * (toTime - fromTime);
650
651 Double_t dta = 300 + amp * TMath::Exp(-0.5 * (tme - time) * (tme - time) / sigma / sigma);
652
653 cout << "T : " << tme << " D : " << dta << endl;
654 IncreaseAmplitude(tme, dta);
655 }
656}
657
658void TRestDetectorSignal::GetWhiteNoiseSignal(TRestDetectorSignal* noiseSignal, Double_t noiseLevel) {
659 this->Sort();
660
661 for (int i = 0; i < GetNumberOfPoints(); i++) {
662 TRandom3* fRandom = new TRandom3(0);
663
664 noiseSignal->IncreaseAmplitude(GetTime(i), GetData(i) + fRandom->Gaus(0, noiseLevel));
665
666 delete fRandom;
667 }
668}
669
670void TRestDetectorSignal::GetSignalGaussianConvolution(TRestDetectorSignal* convSignal, Double_t sigma,
671 Int_t nSigmas) {
672 this->Sort();
673
674 Int_t nPoints = GetMaxTime() - GetMinTime();
675 TF1* fGaus = new TF1("fGauss", "exp(-0.5*((x-[1])/[2])**2)", -nPoints, nPoints);
676 sigma = sigma * 1000.; // conversion to nanoseconds
677 fGaus->SetParameter(2, sigma); // the width of the gaussian is set
678
679 Double_t totChargeInitial = 0.;
680 Double_t totChargeFinal = 0.;
681
682 Double_t sum;
683
684 // We calculate the charge of the event before convolution
685 for (int i = 0; i < GetNumberOfPoints(); i++) totChargeInitial += fSignalCharge[i];
686
687 // The gaussian convolution of the initial signal is performed
688 for (int i = GetMinTime() - nSigmas * sigma; i < GetMaxTime() + nSigmas * sigma; i++) {
689 for (int j = 0; j < GetNumberOfPoints(); j++) {
690 if (TMath::Abs(i - GetTime(j)) > nSigmas * sigma) continue;
691 if (TMath::Abs(i - GetTime(j)) > nSigmas * sigma && i < GetTime(j)) break;
692
693 fGaus->SetParameter(1, GetTime(j));
694 sum = fSignalCharge[j] / TMath::Sqrt(2. * TMath::Pi()) / sigma * fGaus->Integral(i, i + 1);
695
696 convSignal->IncreaseAmplitude(i, sum);
697 totChargeFinal += sum;
698 }
699 }
700
701 cout << "Initial charge of the pulse " << totChargeInitial << endl;
702 cout << "Final charge of the pulse " << totChargeFinal << endl;
703}
704
705void TRestDetectorSignal::WriteSignalToTextFile(const TString& filename) const {
706 FILE* fff = fopen(filename.Data(), "w");
707 for (int i = 0; i < GetNumberOfPoints(); i++) {
708 fprintf(fff, "%e\t%e\n", GetTime(i), GetData(i));
709 }
710 fclose(fff);
711}
712
713void TRestDetectorSignal::Print() const {
714 cout << "Signal ID : " << GetSignalID() << endl;
715 cout << "Integral : " << GetIntegral() << endl;
716 if (!GetSignalName().empty()) {
717 cout << "Name: " << GetSignalName() << endl;
718 }
719 if (!GetSignalType().empty()) {
720 cout << "Type: " << GetSignalType() << endl;
721 }
722
723 cout << "------------------------------------------------" << endl;
724 for (int i = 0; i < GetNumberOfPoints(); i++) {
725 cout << "Time : " << GetTime(i) << " Charge : " << GetData(i) << endl;
726 }
727
728 cout << "================================================" << endl;
729}
730
731TGraph* TRestDetectorSignal::GetGraph(Int_t color) {
732 if (fGraph != nullptr) {
733 delete fGraph;
734 fGraph = nullptr;
735 }
736
737 fGraph = new TGraph();
738
739 // cout << "Signal ID " << this->GetSignalID( ) << " points " <<
740 // this->GetNumberOfPoints() << endl;
741
742 fGraph->SetLineWidth(2);
743 fGraph->SetLineColor(color);
744 fGraph->SetMarkerStyle(7);
745
746 int points = 0;
747 for (int n = 0; n < GetNumberOfPoints(); n++) {
748 fGraph->SetPoint(points, GetTime(n), GetData(n));
749 points++;
750 }
751
752 return fGraph;
753}
void IncreaseAmplitude(const TVector2 &p)
If the point already exists inside the detector signal event, the amplitude value will be added to th...
void SetPoint(const TVector2 &p)
If the point already exists inside the detector signal event, it will be overwritten....