ATTPCROOT  0.3.0-alpha
A ROOT-based framework for analyzing data from active target detectors
AtClusterize.cxx
Go to the documentation of this file.
1 #include "AtClusterize.h"
2 
3 #include "AtDigiPar.h"
4 #include "AtMCPoint.h"
5 #include "AtSimulatedPoint.h"
6 
7 #include <FairLogger.h>
8 
9 #include <TClonesArray.h>
10 #include <TMath.h> // for Sqrt, Cos, Sin, TwoPi
11 #include <TMathBase.h> // for Abs
12 #include <TObject.h> // for TObject
13 #include <TRandom.h>
14 #include <TString.h> // for operator!=, TString
15 
16 #include <algorithm> // for max
17 #include <utility> // for move
18 
20 thread_local int AtClusterize::fTrackID = 0;
21 
23 {
24  fEIonize = fPar->GetEIonize() / 1000000; // [MeV]
25  fFano = fPar->GetFano();
26  fVelDrift = fPar->GetDriftVelocity(); // [cm/us]
27  fCoefT = fPar->GetCoefDiffusionTrans(); // [cm^2/us]
28  fCoefL = fPar->GetCoefDiffusionLong(); // [cm^2/us]
29 
30  fDetPadPlane = fPar->GetZPadPlane(); //[mm]
31 
32  LOG(info) << " Ionization energy of gas: " << fEIonize << " MeV";
33  LOG(info) << " Fano factor of gas: " << fFano;
34  LOG(info) << " Drift velocity: " << fVelDrift;
35  LOG(info) << " Longitudal coefficient of diffusion: " << fCoefL;
36  LOG(info) << " Transverse coefficient of diffusion: " << fCoefT;
37  LOG(info) << " Position of the pad plane (Z): " << fDetPadPlane;
38 }
39 
40 void AtClusterize::FillTClonesArray(TClonesArray &array, std::vector<SimPointPtr> &vec)
41 {
42  for (auto &point : vec) {
43  auto size = array.GetEntriesFast();
44  new (array[size]) AtSimulatedPoint(std::move(*point)); // NO LINT
45  }
46 }
47 
48 std::vector<AtClusterize::SimPointPtr> AtClusterize::ProcessEvent(const TClonesArray &fMCPointArray)
49 {
50  std::vector<SimPointPtr> ret;
51  for (int i = 0; i < fMCPointArray.GetEntries(); ++i) {
52  auto mcPoint = dynamic_cast<AtMCPoint *>(fMCPointArray.At(i));
53 
54  for (auto &point : processPoint(*mcPoint, i))
55  ret.push_back(std::move(point));
56  }
57  return ret;
58 }
59 
60 std::vector<AtClusterize::SimPointPtr> AtClusterize::processPoint(AtMCPoint &mcPoint, int pointID)
61 {
62  if (mcPoint.GetVolName() != "drift_volume") {
63  LOG(info) << "Skipping point " << pointID << ". Not in drift volume.";
64  return {};
65  }
66 
67  auto trackID = mcPoint.GetTrackID();
68  XYZPoint currentPoint = getCurrentPointLocation(mcPoint); // [mm, mm, us]
69 
70  // If it is a new track entering the volume or no energy was deposited
71  // record its location and the new track ID
72  if (mcPoint.GetEnergyLoss() == 0 || fTrackID != trackID) {
73  fPrevPoint = currentPoint;
74  fTrackID = mcPoint.GetTrackID();
75  return {};
76  }
77 
78  auto genElectrons = getNumberOfElectronsGenerated(mcPoint);
79  XYZVector step;
80  if (genElectrons > 0) {
81  step = (currentPoint - fPrevPoint) / genElectrons;
82  }
83 
84  auto sigTrans = getTransverseDiffusion(currentPoint.z()); // mm
85  auto sigLong = getLongitudinalDiffusion(currentPoint.z()); // us
86 
87  std::vector<SimPointPtr> ret;
88 
89  // Need to loop through electrons
90  for (int i = 0; i < genElectrons; ++i) {
91  auto loc = applyDiffusion(currentPoint + i * step, sigTrans, sigLong);
92  XYZVector locVec(loc.X(), loc.Y(), loc.Z());
93  ret.push_back(std::make_unique<AtSimulatedPoint>(pointID, i, locVec));
94  LOG(debug2) << loc << " from " << currentPoint + i * step;
95  }
96 
97  fPrevPoint = currentPoint;
98  return ret;
99 }
100 
102 {
103  auto sigInCm = TMath::Sqrt(fCoefL * 2 * driftTime);
104  auto sigInUs = sigInCm / fVelDrift;
105  return sigInUs;
106 }
107 
108 // Takes drift time in us returns sigma in mm
109 double AtClusterize::getTransverseDiffusion(double driftTime)
110 {
111  return 10. * TMath::Sqrt(fCoefT * 2 * driftTime);
112 }
113 
115 {
116  auto energyLoss = mcPoint.GetEnergyLoss() * 1000.;
117  auto meanElec = energyLoss / fEIonize;
118  auto sigElec = TMath::Sqrt(fFano * meanElec);
119  return gRandom->Gaus(meanElec, sigElec);
120 }
121 
123 {
124  auto zInCm = fDetPadPlane / 10. - mcPoint.GetZ();
125  auto driftTime = TMath::Abs(zInCm) / fVelDrift; // us
126 
127  return {mcPoint.GetX() * 10., mcPoint.GetY() * 10., driftTime};
128 }
129 
131 AtClusterize::applyDiffusion(const AtClusterize::XYZPoint &loc, double_t sigTrans, double sigLong)
132 {
133  auto r = gRandom->Gaus(0, sigTrans);
134  auto phi = gRandom->Uniform(0, TMath::TwoPi());
135  auto dz = gRandom->Gaus(0, sigLong);
136 
137  return loc + XYZVector(r * TMath::Cos(phi), r * TMath::Sin(phi), dz);
138 }
AtClusterize::fEIonize
double fEIonize
Effective ionization energy of gas. [eV].
Definition: AtClusterize.h:30
AtDigiPar::GetZPadPlane
Double_t GetZPadPlane() const
Definition: AtDigiPar.h:50
AtClusterize.h
AtClusterize::getCurrentPointLocation
XYZPoint getCurrentPointLocation(const AtMCPoint &mcPoint)
Definition: AtClusterize.cxx:122
AtClusterize::fPrevPoint
static thread_local XYZPoint fPrevPoint
The previous point we recorded charge.
Definition: AtClusterize.h:37
AtClusterize::fTrackID
static thread_local int fTrackID
The current track ID.
Definition: AtClusterize.h:38
AtSimulatedPoint.h
AtSimulatedPoint
Definition: AtSimulatedPoint.h:16
AtClusterize::processPoint
virtual std::vector< SimPointPtr > processPoint(AtMCPoint &mcPoint, int pointID=-1)
Definition: AtClusterize.cxx:60
AtDigiPar::GetEIonize
Double_t GetEIonize() const
Definition: AtDigiPar.h:52
AtClusterize::getLongitudinalDiffusion
double getLongitudinalDiffusion(double driftTime)
Definition: AtClusterize.cxx:101
AtClusterize::fCoefT
double fCoefT
Transversal diffusion coefficient. [cm^2/us].
Definition: AtClusterize.h:33
AtDigiPar.h
AtDigiPar
Definition: AtDigiPar.h:14
AtClusterize::GetParameters
virtual void GetParameters(const AtDigiPar *fPar)
Definition: AtClusterize.cxx:22
AtClusterize::fCoefL
double fCoefL
Longitudinal diffusion coefficient. [cm^2/us].
Definition: AtClusterize.h:34
AtClusterize::FillTClonesArray
virtual void FillTClonesArray(TClonesArray &array, std::vector< SimPointPtr > &vec)
Definition: AtClusterize.cxx:40
AtClusterize::XYZVector
ROOT::Math::XYZVector XYZVector
Definition: AtClusterize.h:26
AtMCPoint.h
AtClusterize::XYZPoint
ROOT::Math::XYZPoint XYZPoint
Definition: AtClusterize.h:27
AtDigiPar::GetFano
Double_t GetFano() const
Definition: AtDigiPar.h:53
AtMCPoint::GetVolName
TString GetVolName() const
Definition: AtMCPoint.h:68
AtClusterize::ProcessEvent
std::vector< SimPointPtr > ProcessEvent(const TClonesArray &fMCPointArray)
Definition: AtClusterize.cxx:48
AtClusterize::fDetPadPlane
double fDetPadPlane
Position of the pad plane with respect to the entrance [mm].
Definition: AtClusterize.h:35
AtDigiPar::GetDriftVelocity
Double_t GetDriftVelocity() const
Definition: AtDigiPar.h:58
AtMCPoint
Definition: AtMCPoint.h:26
AtClusterize::getNumberOfElectronsGenerated
uint64_t getNumberOfElectronsGenerated(const AtMCPoint &mcPoint)
Definition: AtClusterize.cxx:114
AtClusterize::fVelDrift
double fVelDrift
Drift velocity of electron in gas. [cm/us].
Definition: AtClusterize.h:32
AtClusterize::getTransverseDiffusion
double getTransverseDiffusion(double driftTime)
Definition: AtClusterize.cxx:109
AtClusterize::fFano
double fFano
Fano factor of the gas.
Definition: AtClusterize.h:31
AtDigiPar::GetCoefDiffusionLong
Double_t GetCoefDiffusionLong() const
Definition: AtDigiPar.h:55
AtDigiPar::GetCoefDiffusionTrans
Double_t GetCoefDiffusionTrans() const
Definition: AtDigiPar.h:54