ATTPCROOT  0.3.0-alpha
A ROOT-based framework for analyzing data from active target detectors
AtRadialChargeModel.cxx
Go to the documentation of this file.
1 #include "AtRadialChargeModel.h"
2 
3 #include "AtDigiPar.h"
4 
5 #include <FairLogger.h>
6 
7 #include <Math/Point2D.h>
8 #include <Math/Point2Dfwd.h> // for XYPoint
9 #include <Math/Point3D.h> // for PositionVector3D
10 #include <Math/Point3Dfwd.h> // for RhoZPhiPoint, XYZPoint
11 #include <Math/Vector2D.h>
12 #include <Math/Vector2Dfwd.h> // for XYVector
13 #include <Math/Vector3D.h>
14 #include <Math/Vector3Dfwd.h> // for XYZVector
15 
16 #include <cmath>
17 #include <memory> // for allocator
18 #include <utility> // for move
19 
20 constexpr auto c = 29979.2; //< c in cm/us
21 constexpr auto c2 = c * c; //< c^2
22 constexpr auto me = 0.511e6; // mass of e- in eV
23 
28 
29 AtRadialChargeModel::AtRadialChargeModel(EFieldPtr eField) : AtSpaceChargeModel(), GetEField(std::move(eField)) {}
30 
32 {
33  auto offsetHit = OffsetForBeam(input);
34  LOG(debug) << input << " to " << offsetHit;
35  auto corrHit = SolveEqn(offsetHit / 10, true) * 10;
36  return UndoOffsetForBeam(corrHit);
37 }
38 
40 {
41  auto offsetHit = OffsetForBeam(input);
42  auto corrHit = SolveEqn(offsetHit / 10, false) * 10;
43  return UndoOffsetForBeam(corrHit);
44 }
45 
46 // Assumes units are cm
47 XYZPoint AtRadialChargeModel::SolveEqn(XYZPoint ele, bool correct)
48 {
49 
50  // Verify step size is logical
51  auto minStepSize = 2 * fMobilityElec * me / c2;
52  if (fStepSize < minStepSize) {
53  LOG(error) << "Using unphysical step size: " << fStepSize << " reseting to minimum step size:" << minStepSize;
54  fStepSize = minStepSize;
55  }
56 
57  // Drift to pad plane in z/vd
58  double timeToDrift = ele.Z() / fDriftVel; // us
59  int nBins = std::floor(timeToDrift / fStepSize);
60  LOG(debug) << "Drifting to " << ele.Z() << " in " << nBins << " steps of size " << fStepSize;
61 
62  double pos = ele.rho();
63 
64  // Calculate transporting from point to the pad plane
65  for (int i = 0; i < nBins; ++i) {
66 
67  // Z = 0 is pad plane
68  auto z = ele.Z() - i * fStepSize * fDriftVel;
69  if (z < 0) {
70  LOG(error) << "Space charge correction tried to bypass the pad plane!";
71  break;
72  }
73 
74  double Efield = 0;
75  if (GetEField == nullptr) {
76  LOG(fatal) << "The distrotion field was never set!";
77  } else
78  Efield = GetEField(pos, z);
79 
80  LOG(debug2) << "Field " << Efield << " V/cm rho: " << pos << " cm and z: " << z << " cm.";
81  if (!correct)
82  Efield *= -1;
83 
84  // Method assuming we are always at drift velocity
85  // This is true based on our check of the time step
86  double v = Efield * fMobilityElec;
87 
88  // Update the position of the electron
89  pos += fStepSize * v;
90  if (pos < 0) {
91  pos = 0;
92  }
93  }
94 
95  // Perform the final step using the remaining time
96  auto dT = timeToDrift - nBins * fStepSize;
97  auto z = dT * fDriftVel;
98  auto Efield = GetEField(pos, z);
99  if (!correct)
100  Efield *= -1;
101  double v = Efield * fMobilityElec;
102  pos += dT * v;
103  if (pos < 0) {
104  pos = 0;
105  }
106 
107  return XYZPoint(ROOT::Math::RhoZPhiPoint(pos, ele.Z(), ele.phi()));
108 }
109 
111 {
112  if (par == nullptr)
113  return;
114 
115  SetEField(par->GetEField() / 100.); // EField units in param are V/m. Need V/cm.
117  LOG(debug) << "Setting mobility to: " << fMobilityElec;
118 }
119 
121 {
122  fEFieldZ = field;
123  fMobilityElec = fDriftVel / fEFieldZ;
124 }
126 {
127  fDriftVel = v;
128  fMobilityElec = fDriftVel / fEFieldZ;
129 }
130 
131 /*
132 // Calculate the acceleration and update the velocity
133 auto a = Efield * c2 / me - c2 / fMobilityElec / me * v;
134 auto dV = fStepSize * a;
135 // v += fStepSize * dV;
136 
137 // Method used by Juan (equivalent mathematically, not tested)
138 auto G = c2 / fMobilityElec;
139 v = (v * (1.0 - 0.5 * fStepSize * G / me) + fStepSize * (Efield * c2 / me)) / (1.0 + 0.5 * fStepSize * G / me);
140 */
XYVector
ROOT::Math::XYVector XYVector
Definition: AtRadialChargeModel.cxx:27
XYVector
ROOT::Math::XYVector XYVector
Definition: AtEDistortionModel.cxx:23
AtRadialChargeModel::LoadParameters
void LoadParameters(const AtDigiPar *par) override
Load common parameters from AtDigiPar.
Definition: AtRadialChargeModel.cxx:110
XYPoint
ROOT::Math::XYPoint XYPoint
Definition: AtRadialChargeModel.cxx:26
XYZPoint
ROOT::Math::XYZPoint XYZPoint
Definition: AtRadialChargeModel.cxx:24
XYZVector
ROOT::Math::XYZVector XYZVector
Definition: AtFindVertex.h:20
c2
constexpr auto c2
Definition: AtRadialChargeModel.cxx:21
XYPoint
ROOT::Math::XYPoint XYPoint
Definition: AtPatternCircle2D.cxx:16
XYZVector
ROOT::Math::XYZVector XYZVector
Definition: AtRadialChargeModel.cxx:25
XYZPoint
ROOT::Math::XYZPoint XYZPoint
Definition: AtPatternCircle2D.h:18
AtRadialChargeModel.h
AtSpaceChargeModel::UndoOffsetForBeam
XYZPoint UndoOffsetForBeam(XYZPoint point)
Definition: AtSpaceChargeModel.cxx:14
AtSpaceChargeModel::XYZPoint
ROOT::Math::XYZPoint XYZPoint
Definition: AtSpaceChargeModel.h:11
AtSpaceChargeModel::OffsetForBeam
XYZPoint OffsetForBeam(XYZPoint point)
Definition: AtSpaceChargeModel.cxx:8
AtRadialChargeModel::ApplySpaceCharge
virtual XYZPoint ApplySpaceCharge(const XYZPoint &reverseInputPosition) override
Using model add space charge effect.
Definition: AtRadialChargeModel.cxx:39
AtRadialChargeModel::CorrectSpaceCharge
virtual XYZPoint CorrectSpaceCharge(const XYZPoint &directInputPosition) override
Using model correct for space charge.
Definition: AtRadialChargeModel.cxx:31
AtDigiPar.h
AtSpaceChargeModel
Definition: AtSpaceChargeModel.h:9
AtDigiPar
Definition: AtDigiPar.h:14
AtDigiPar::GetEField
Double_t GetEField() const
Definition: AtDigiPar.h:47
AtRadialChargeModel::SetEField
void SetEField(double field)
Definition: AtRadialChargeModel.cxx:120
AtRadialChargeModel::EFieldPtr
std::function< double(double rho, double z)> EFieldPtr
Definition: AtRadialChargeModel.h:20
me
constexpr auto me
Definition: AtRadialChargeModel.cxx:22
AtDigiPar::GetDriftVelocity
Double_t GetDriftVelocity() const
Definition: AtDigiPar.h:58
AtRadialChargeModel::SetDriftVelocity
void SetDriftVelocity(double v)
Definition: AtRadialChargeModel.cxx:125
AtRadialChargeModel::AtRadialChargeModel
AtRadialChargeModel(EFieldPtr efield)
Definition: AtRadialChargeModel.cxx:29
c
constexpr auto c
Definition: AtRadialChargeModel.cxx:20