ATTPCROOT  0.3.0-alpha
A ROOT-based framework for analyzing data from active target detectors
AtRemovePulser.cxx
Go to the documentation of this file.
1 #include "AtRemovePulser.h"
2 
3 #include "AtPad.h"
4 #include "AtPadBase.h"
5 #include "AtPulserInfo.h"
6 
7 #include <FairLogger.h>
8 
9 #include <array> // for array
10 #include <memory> // for allocator, make_unique
11 #include <numeric>
12 
13 struct AtPadReference;
14 
15 void AtRemovePulser::Filter(AtPad *pad, AtPadReference *padReference)
16 {
17  addPulserInfo(pad);
18  removePulser(pad);
19 }
20 void AtRemovePulser::addPulserInfo(AtPad *pad)
21 {
22  auto &adc = pad->GetADC();
23  auto pulserInfo = dynamic_cast<AtPulserInfo *>(pad->AddAugment("pulserInfo", std::make_unique<AtPulserInfo>()));
24 
25  for (int i = 1; i < adc.size(); ++i) {
26  if (std::abs(adc.at(i) - adc.at(i - 1)) > fThreshold) {
27  auto [start, stop, mag] = getTransitionAround(pad, i);
28  i = stop;
29  if (mag > 0) {
30  pulserInfo->SetRiseBegin(start);
31  pulserInfo->SetRiseEnd(stop);
32  pulserInfo->SetRiseMag(mag);
33  } else {
34  pulserInfo->SetFallBegin(start);
35  pulserInfo->SetFallEnd(stop);
36  pulserInfo->SetFallMag(-mag);
37  }
38  }
39  }
40 }
41 
42 std::tuple<double, double, double> AtRemovePulser::getTransitionAround(AtPad *pad, int idx)
43 {
44  auto &adc = pad->GetADC();
45 
46  // Look backwards for when the difference is smaller than
47  int start = idx;
48  for (; start > 0; start--) {
49  if (std::abs(adc[start] - adc[start - 1]) < fThresholdLow)
50  break;
51  }
52 
53  int end = idx;
54  for (; end < 512; end++)
55  if (std::abs(adc[end] - adc[end - 1]) < fThresholdLow)
56  break;
57 
58  LOG(debug) << start << " " << end << " " << adc[end] - adc[start];
59 
60  return {start, end, adc[end] - adc[start]};
61 }
62 
63 void AtRemovePulser::removePulser(AtPad *pad)
64 {
65  auto pulserInfo = dynamic_cast<AtPulserInfo *>(pad->GetAugment("pulserInfo"));
66  auto mag =
67  std::accumulate(pulserInfo->GetMag().begin(), pulserInfo->GetMag().end(), 0.0) / pulserInfo->GetMag().size();
68 
69  // Values for transition region
70  auto zeroRise = pad->GetADC(pulserInfo->GetBegin()[0] - 2) + pad->GetADC(pulserInfo->GetBegin()[0] - 1);
71  zeroRise /= 2.0;
72  auto zeroFall = pad->GetADC(pulserInfo->GetEnd()[1] + 1) + pad->GetADC(pulserInfo->GetEnd()[1]);
73  zeroFall /= 2.0;
74 
75  for (int i = pulserInfo->GetBegin()[0]; i < pulserInfo->GetEnd()[1]; ++i) {
76 
77  if (i < pulserInfo->GetEnd()[0]) {
78  pad->SetADC(i, zeroRise);
79  continue;
80  }
81  if (i < pulserInfo->GetBegin()[1]) {
82  pad->SetADC(i, pad->GetADC(i) - mag);
83  continue;
84  }
85  pad->SetADC(i, zeroFall);
86  }
87 }
AtPad.h
AtRemovePulser::Filter
virtual void Filter(AtPad *pad, AtPadReference *padReference) override
Called to filter each pad.
Definition: AtRemovePulser.cxx:15
AtPad::SetADC
void SetADC(const trace &val)
Definition: AtPad.h:91
AtPulserInfo::GetMag
const IntArray & GetMag()
Definition: AtPulserInfo.h:33
AtPad::GetAugment
AtPadBase * GetAugment(std::string name)
Definition: AtPad.cxx:82
AtPad::GetADC
const trace & GetADC() const
Definition: AtPad.cxx:97
AtPulserInfo.h
AtPad
Container class for AtPadBase objects.
Definition: AtPad.h:38
AtRemovePulser.h
AtPadBase.h
AtPadReference
Definition: AtPadReference.h:20
AtPad::AddAugment
AtPadBase * AddAugment(std::string name, std::unique_ptr< AtPadBase > augment)
Definition: AtPad.cxx:63
AtPulserInfo
Definition: AtPulserInfo.h:14