ATTPCROOT  0.3.0-alpha
A ROOT-based framework for analyzing data from active target detectors
AtPSAMax.cxx
Go to the documentation of this file.
1 #include "AtPSAMax.h"
2 
3 #include "AtHit.h"
4 #include "AtPad.h"
5 
6 #include <FairLogger.h>
7 
8 #include <Math/Point3D.h> // for PositionVector3D
9 #include <Math/Point3Dfwd.h> // for XYZPoint
10 
11 #include <algorithm>
12 #include <array> // for array
13 #include <iterator> // for distance
14 #include <memory> // for unique_ptr, make_unique
15 #include <numeric>
16 #include <utility> // for pair
17 
18 //#ifdef _OPENMP
19 //#include <omp.h>
20 //#endif
22 
24 {
25  XYZPoint pos(pad->GetPadCoord().X(), pad->GetPadCoord().Y(), 0);
26 
27  if (pos.X() < -9000 || pos.Y() < -9000) {
28  LOG(debug) << "Skipping pad, position is invalid";
29  return {};
30  }
31 
32  if (!(pad->IsPedestalSubtracted())) {
33  LOG(ERROR) << "Pedestal should be subtracted to use this class!";
34  }
35 
36  std::array<Double_t, 512> floatADC = pad->GetADC();
37  auto maxAdcIt = std::max_element(floatADC.begin() + 20, floatADC.end() - 12);
38  Int_t maxAdcIdx = std::distance(floatADC.begin(), maxAdcIt);
39 
40  if (!shouldSaveHit(*maxAdcIt, getThreshold(pad->GetSizeID()), maxAdcIdx))
41  return {};
42 
43  // Calculation of the mean value of the peak time by interpolating the pulse
44  Double_t timemax = 0.5 * (floatADC[maxAdcIdx - 1] - floatADC[maxAdcIdx + 1]) /
45  (floatADC[maxAdcIdx - 1] + floatADC[maxAdcIdx + 1] - 2 * floatADC[maxAdcIdx]);
46  Double_t TBCorr = getTBCorr(floatADC, maxAdcIdx);
47  Double_t QHitTot = std::accumulate(floatADC.begin(), floatADC.end(), 0);
48 
49  if (fIsTimeCorr)
50  pos.SetZ(CalculateZGeo(TBCorr));
51  else
52  pos.SetZ(CalculateZGeo(maxAdcIdx));
53 
54  auto hit = std::make_unique<AtHit>(pad->GetPadNum(), pos, *maxAdcIt);
55 
56  hit->SetTimeStamp(maxAdcIdx);
57  hit->SetTimeStampCorr(TBCorr);
58  hit->SetTimeStampCorrInter(timemax);
59  hit->SetTraceIntegral(QHitTot);
60 
61  HitVector ret;
62  ret.push_back(std::move(hit));
63  return ret;
64 }
65 bool AtPSAMax::shouldSaveHit(double charge, double threshold, int tb)
66 {
67  bool ret = true;
68  if (threshold > 0 && charge < threshold) {
69  ret = false;
70  LOG(debug) << "Invalid threshold with charge: " << charge << " and threshold: " << threshold;
71  }
72  if ((tb < 20 || tb > 500)) {
73  ret = false;
74  LOG(debug) << "Peak is outside valid time window (20,500) TBs.";
75  }
76 
77  return ret;
78 }
79 
80 Double_t AtPSAMax::getTBCorr(AtPad::trace &adc, int maxAdcIdx)
81 {
82  if (maxAdcIdx < 11)
83  return 0;
84 
85  Double_t qTot = 0;
86  Double_t tbAvg = 0;
87  for (Int_t i = 0; i < 11; i++)
88  if (adc[maxAdcIdx - i + 10] > 0 && adc[maxAdcIdx - i + 10] < 4000) {
89  auto tb = maxAdcIdx - i + 5;
90  qTot += adc[tb];
91  tbAvg += adc[tb] / qTot * (tb - tbAvg);
92  }
93  return tbAvg;
94 }
95 
AtPad.h
AtPSAMax::AnalyzePad
virtual HitVector AnalyzePad(AtPad *pad) override
Definition: AtPSAMax.cxx:23
AtPSA::CalculateZGeo
Double_t CalculateZGeo(Double_t peakIdx)
Definition: AtPSA.cxx:90
AtPSAMax
Simple max finding PSA method.
Definition: AtPSAMax.h:22
AtPad::trace
std::array< Double_t, 512 > trace
Definition: AtPad.h:41
AtPad::GetSizeID
Int_t GetSizeID() const
Definition: AtPad.h:98
AtPSA::HitVector
std::vector< std::unique_ptr< AtHit > > HitVector
Definition: AtPSA.h:50
XYZPoint
ROOT::Math::XYZPoint XYZPoint
Definition: AtPatternCircle2D.h:18
AtPad::GetPadCoord
XYPoint GetPadCoord() const
Definition: AtPad.h:107
ClassImp
ClassImp(AtPSAMax)
AtPSA::getThreshold
Double_t getThreshold(int padSize=-1)
Definition: AtPSA.cxx:179
AtHit.h
AtPad::GetPadNum
Int_t GetPadNum() const
Definition: AtPad.h:96
AtPad::GetADC
const trace & GetADC() const
Definition: AtPad.cxx:97
AtPad::IsPedestalSubtracted
Bool_t IsPedestalSubtracted() const
Definition: AtPad.h:94
AtPad
Container class for AtPadBase objects.
Definition: AtPad.h:38
XYZPoint
ROOT::Math::XYZPoint XYZPoint
Definition: AtPSAMax.cxx:21
AtPSAMax.h