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