ATTPCROOT  0.3.0-alpha
A ROOT-based framework for analyzing data from active target detectors
AtPulseGADGET.cxx
Go to the documentation of this file.
1 #include "AtPulseGADGET.h"
2 
3 #include "AtElectronicResponse.h"
4 #include "AtMap.h"
5 #include "AtRawEvent.h"
6 #include "AtSimulatedPoint.h"
7 
8 #include <FairLogger.h>
9 
10 #include <Math/Point2D.h> // for PositionVector2D
11 #include <Math/Point2Dfwd.h> // for XYPoint
12 #include <Math/Vector3D.h>
13 #include <TH1.h>
14 #include <TMath.h>
15 
16 #include <iostream>
17 #include <set> // for set
18 class AtPad;
19 
20 constexpr auto cRED = "\033[1;31m";
21 constexpr auto cYELLOW = "\033[1;33m";
22 constexpr auto cNORMAL = "\033[0m";
23 constexpr auto cGREEN = "\033[1;32m";
25 
26 using namespace ElectronicResponse;
28 
29 Double_t AtPulseGADGET::ChargeDispersion(Double_t G, Double_t time, Double_t x0, Double_t y0, Double_t xi, Double_t yi)
30 {
31  Double_t Sigma = TMath::Sqrt(2 * time / (R * C) + 2 * Dc * t_amp) * SigmaPercent;
32  Double_t rtTwo = TMath::Sqrt(2);
33  Double_t Charge =
34  G / 4 * (TMath::Erf((xi + W / 2 - x0) / (rtTwo * Sigma)) - TMath::Erf((xi - W / 2 - x0) / (rtTwo * Sigma))) *
35  (TMath::Erf((yi + W / 2 - y0) / (rtTwo * Sigma)) - TMath::Erf((yi - W / 2 - y0) / (rtTwo * Sigma)));
36  return Charge;
37 };
38 
40 {
41  fSkippy = 0;
42 
43  if (point == nullptr)
44  return false;
45 
46  if (AdjecentPads == 0) {
47  SetSigmaPercent(0.01);
48  };
49 
50  auto coord = point->GetPosition();
51  auto xElectron = coord.x(); // mm
52  auto yElectron = coord.y(); // mm
53  auto eTime = coord.z(); // us
54  eTime += fTBPadPlane * fTBTime; // correct time for pad plane location
55  auto padNumber = fMap->GetPadNum(XYPoint{xElectron, yElectron});
56 
57  if (padNumber < 0 || padNumber >= fMap->GetNumPads()) { // if electron cloud hits edge center cant be calculated thus
58  // were moving the cloud an edge away.
59  padNumber = fMap->GetPadNum(XYPoint{xElectron + 0.001, yElectron + 0.001});
60  };
61 
62  auto PadCenter = fMap->CalcPadCenter(padNumber); // get pad center
63 
64  // Setting up cordinates for adjecent pads
65  Double_t coords[Items];
66  for (Int_t n = 0; n < Items; n++) {
67  coords[n] = AdjecentPads * -2.2 + 2.2 * n;
68  };
69  // Store the pad range in a variable
70  Int_t numPads = fMap->GetNumPads();
71 
72  // Calculate xPadCurrent and yPadCurrent outside the loop
73  Double_t xPadCurrent, yPadCurrent;
74  for (Int_t i = 0; i < Items; i++) {
75  xPadCurrent = PadCenter.X() + coords[i]; // NOLINT
76  for (Int_t j = 0; j < Items; j++) {
77  yPadCurrent = PadCenter.Y() + coords[j]; // NOLINT
78 
79  // Calculate newpadNumber directly from newbinNumber
80  auto newpadNumber = fMap->GetPadNum(XYPoint{xPadCurrent, yPadCurrent});
81  auto gAvg = GetGain(newpadNumber, point->GetCharge()); // get average gain
82 
83  if (newpadNumber < 0 || newpadNumber >= numPads || gAvg == 0) {
84  LOG(debug) << "Skipping electron...";
85  fSkippy++;
86  continue;
87  }
88 
89  Double_t ChargeDispersed = ChargeDispersion(gAvg, eTime, xElectron, yElectron, xPadCurrent, yPadCurrent);
90  fPadCharge[newpadNumber]->Fill(eTime, ChargeDispersed);
91  fPadsWithCharge.insert(newpadNumber);
92  }
93  }
94 
95  if (padNumber < 0 || padNumber >= numPads) {
96  LOG(debug) << "Skipping electron...";
97  return false;
98  }
99 
100  return true;
101 }
102 
103 AtRawEvent AtPulseGADGET::GenerateEvent(std::vector<AtSimulatedPoint *> &vec)
104 {
105  LOG(debug) << "Exec of AtPulseGADGET";
106  Reset();
107 
108  Int_t nMCPoints = vec.size();
109  std::cout << " AtPulseGADGET: Number of Points " << nMCPoints << std::endl;
110  std::cout << " AtPulseGADGET: Number of Points (plus dispersion) " << (nMCPoints * Items * Items) << std::endl;
111  // Distributing electron pulses among the pads
112 
113  int numFilled = 0;
114  int skippedDispersion = 0;
115  for (auto &point : vec) {
116  numFilled += AssignElectronsToPad(point);
117  numFilled -= fSkippy;
118  skippedDispersion += fSkippy;
119  }
120  LOG(info) << "Skipped " << (double)(vec.size() - numFilled) / vec.size() * 100 << "% of " << vec.size()
121  << " points.";
122 
123  LOG(info) << "Skipped dispersion " << (double)skippedDispersion / (nMCPoints * Items * Items) * 100 << "% of "
124  << (nMCPoints * Items * Items);
125 
126  AtRawEvent ret;
127  for (auto padNum : fPadsWithCharge) {
128  AtPad *pad = ret.AddPad(padNum);
129  FillPad(*pad, *fPadCharge[padNum]);
130  }
131  return ret;
132 }
AtRawEvent.h
cNORMAL
constexpr auto cNORMAL
Definition: AtPulseGADGET.cxx:22
AtPulse::Reset
void Reset()
Definition: AtPulse.cxx:127
AtElectronicResponse.h
cYELLOW
constexpr auto cYELLOW
Definition: AtPulseGADGET.cxx:21
XYPoint
ROOT::Math::XYPoint XYPoint
Definition: AtPatternCircle2D.cxx:16
AtPulseGADGET.h
AtPulseGADGET::GenerateEvent
virtual AtRawEvent GenerateEvent(std::vector< AtSimulatedPoint * > &vec) override
Executed for each event.
Definition: AtPulseGADGET.cxx:103
AtRawEvent
Definition: AtRawEvent.h:34
cGREEN
constexpr auto cGREEN
Definition: AtPulseGADGET.cxx:23
AtSimulatedPoint.h
AtPulseGADGET::AtPulseGADGET
AtPulseGADGET(AtMapPtr map)
Definition: AtPulseGADGET.cxx:27
AtSimulatedPoint
Definition: AtSimulatedPoint.h:16
AtPulse::AtMapPtr
std::shared_ptr< AtMap > AtMapPtr
Definition: AtPulse.h:24
AtPulseGADGET::SetSigmaPercent
void SetSigmaPercent(Float_t sigma)
Definition: AtPulseGADGET.h:43
AtPulse::GetGain
double GetGain(int padNum, int numElectrons)
Definition: AtPulse.cxx:205
AtPulse::FillPad
void FillPad(AtPad &pad, TH1F &hist)
Definition: AtPulse.cxx:82
AtPulse::fPadsWithCharge
std::set< int > fPadsWithCharge
Definition: AtPulse.h:51
AtPulse::fPadCharge
std::vector< std::unique_ptr< TH1F > > fPadCharge
Definition: AtPulse.h:50
XYPoint
ROOT::Math::XYPoint XYPoint
Definition: AtPulseGADGET.cxx:24
AtPulse::fTBTime
double fTBTime
Electronic peaking time in us.
Definition: AtPulse.h:39
cRED
constexpr auto cRED
Definition: AtPulseGADGET.cxx:20
AtRawEvent::AddPad
AtPad * AddPad(Ts &&...params)
Create a new pad in this event.
Definition: AtRawEvent.h:82
AtSimulatedPoint::GetPosition
virtual ROOT::Math::XYZVector GetPosition()
Definition: AtSimulatedPoint.cxx:46
AtPulse::fTBPadPlane
int fTBPadPlane
Window location in timebuckets (from config)
Definition: AtPulse.h:42
AtMap.h
AtPulseGADGET::ChargeDispersion
Double_t ChargeDispersion(Double_t G, Double_t time, Double_t x0, Double_t y0, Double_t xi, Double_t yi)
Definition: AtPulseGADGET.cxx:29
AtPad
Container class for AtPadBase objects.
Definition: AtPad.h:38
AtPulse
Definition: AtPulse.h:22
AtPulse::fMap
AtMapPtr fMap
AtTPC map.
Definition: AtPulse.h:32
AtPulseGADGET::AssignElectronsToPad
virtual bool AssignElectronsToPad(AtSimulatedPoint *point) override
Definition: AtPulseGADGET.cxx:39
AtSimulatedPoint::GetCharge
Int_t GetCharge()
Definition: AtSimulatedPoint.cxx:62
ElectronicResponse
Definition: AtVectorResponse.h:8