ATTPCROOT  0.3.0-alpha
A ROOT-based framework for analyzing data from active target detectors
AtPSA.cxx
Go to the documentation of this file.
1 #include "AtPSA.h"
2 
3 #include "AtDigiPar.h"
4 #include "AtEvent.h"
5 #include "AtHit.h"
6 #include "AtMCPoint.h"
7 #include "AtPad.h"
8 #include "AtRawEvent.h"
9 
10 #include <FairLogger.h>
11 #include <FairRun.h>
12 #include <FairRuntimeDb.h>
13 
14 #include <Math/Point3D.h> // for PositionVector3D
15 #include <Rtypes.h>
16 #include <TClonesArray.h>
17 #include <TObject.h> // for TObject
18 
19 #include <algorithm>
20 #include <array> // for array
21 #include <cmath> // for pow
22 #include <iostream>
23 #include <iterator>
24 #include <utility> // for pair
25 
26 using std::distance;
27 using std::max_element;
28 using std::min_element;
29 
31 {
32 
33  FairRun *run = FairRun::Instance();
34  if (!run)
35  LOG(FATAL) << "No analysis run!";
36 
37  FairRuntimeDb *db = run->GetRuntimeDb(); // NOLINT
38  if (!db)
39  LOG(FATAL) << "No runtime database!";
40 
41  auto fPar = (AtDigiPar *)db->getContainer("AtDigiPar"); // NOLINT
42  if (!fPar) {
43  LOG(FATAL) << "AtDigiPar not found!!";
44  return;
45  }
46 
47  fTBTime = fPar->GetTBTime();
48  fDriftVelocity = fPar->GetDriftVelocity();
49  fBField = fPar->GetBField();
50  fEField = fPar->GetEField();
51  fZk = fPar->GetZPadPlane();
52  fEntTB = (Int_t)fPar->GetTBEntrance();
53 
54  auto timeToPadPlane = fZk / (fDriftVelocity * 1e-2); //[ns]
55  fTB0 = fEntTB - timeToPadPlane / fTBTime;
56 
57  std::cout << " ==== Parameters for Pulse Shape Analysis Task ==== " << std::endl;
58  std::cout << " ==== Magnetic Field : " << fBField << " T " << std::endl;
59  std::cout << " ==== Electric Field : " << fEField << " V/cm " << std::endl;
60  std::cout << " ==== Sampling Rate : " << fTBTime << " ns " << std::endl;
61  std::cout << " ==== Drift Velocity : " << fDriftVelocity << " cm/us " << std::endl;
62  std::cout << " ==== Entrance TB : " << fEntTB << std::endl;
63  std::cout << " ==== Pad plane TB : " << fTB0 << std::endl;
64  std::cout << " ==== NumTbs : " << fNumTbs << std::endl;
65 }
66 
67 void AtPSA::SetSimulatedEvent(TClonesArray *MCSimPointArray)
68 {
69  fMCSimPointArray = MCSimPointArray;
70 }
71 
72 void AtPSA::SetThreshold(Int_t threshold)
73 {
74  fThreshold = threshold;
75  if (!fUsingLowThreshold)
76  fThresholdlow = threshold;
77 }
78 
79 void AtPSA::SetThresholdLow(Int_t thresholdlow)
80 {
81  fThresholdlow = thresholdlow;
82  fUsingLowThreshold = kTRUE;
83 }
84 
85 Double_t AtPSA::CalculateZ(Double_t peakIdx)
86 {
87  return (fNumTbs - peakIdx) * fTBTime * fDriftVelocity / 100.;
88 }
89 
90 Double_t AtPSA::CalculateZGeo(Double_t peakIdx)
91 {
92  return fZk - (fEntTB - peakIdx) * fTBTime * fDriftVelocity / 100.;
93 }
94 
95 void AtPSA::TrackMCPoints(std::multimap<Int_t, std::size_t> &map, AtHit &hit)
96 {
97  auto padNum = hit.GetPadNum();
98  for (auto it = map.lower_bound(padNum); it != map.upper_bound(padNum); ++it) {
99 
100  if (fMCSimPointArray != nullptr) {
101  auto *MCPoint = dynamic_cast<AtMCPoint *>(fMCSimPointArray->At(it->second));
102 
103  AtHit::MCSimPoint mcpoint(it->second, MCPoint->GetTrackID(), MCPoint->GetEIni(), MCPoint->GetEnergyLoss(),
104  MCPoint->GetAIni(), MCPoint->GetMassNum(), MCPoint->GetAtomicNum());
105  hit.AddMCSimPoint(mcpoint);
106 
107  // std::cout << " Pad Num : "<<hit->GetHitPadNum()<<" MC Point ID : "<<it->second << std::endl;
108  // std::cout << " Track ID : "<<MCPoint->GetTrackID()<<" Energy (MeV) : "<<MCPoint->GetEIni()<<" Angle (deg) :
109  // "<<MCPoint->GetAIni()<<"\n"; std::cout << " Mass Number : "<<MCPoint->GetMassNum()<<" Atomic Number
110  // "<<MCPoint->GetAtomicNum()<<"\n";
111  }
112  // }
113  }
114 }
115 
117 {
118  AtEvent event;
119  Analyze(&rawEvent, &event);
120  return event;
121 }
122 
127 void AtPSA::Analyze(AtRawEvent *rawEvent, AtEvent *event)
128 {
129  Double_t QEventTot = 0.0;
130  Double_t RhoVariance = 0.0;
131  Double_t RhoMean = 0.0;
132  Double_t Rho2 = 0.0;
133 
134  std::map<Int_t, Int_t> PadMultiplicity;
135  std::array<Float_t, 512> mesh{};
136  mesh.fill(0);
137 
138  for (const auto &pad : rawEvent->GetPads()) {
139 
140  LOG(debug) << "Running PSA on pad " << pad->GetPadNum();
141 
142  auto hits = AnalyzePad(pad.get());
143 
144  PadMultiplicity.insert(std::pair<Int_t, Int_t>(pad->GetPadNum(), hits.size()));
145 
146  // If we got any hits update the mesh signal
147  if (hits.size() != 0)
148  for (Int_t iTb = 0; iTb < fNumTbs; iTb++)
149  mesh[iTb] += pad->GetADC(iTb);
150 
151  // Update AtEvent with hits
152  for (auto &&hit : hits) {
153  auto pos = hit->GetPosition();
154  QEventTot += hit->GetTraceIntegral();
155  Rho2 += pos.Mag2();
156  RhoMean += pos.Rho();
157 
158  auto mcPointsMap = rawEvent->GetSimMCPointMap();
159  if (mcPointsMap.size() > 0) {
160  LOG(debug) << "MC Simulated points Map size " << mcPointsMap.size();
161  TrackMCPoints(mcPointsMap, *(hit.get()));
162  }
163 
164  event->AddHit(std::move(hit));
165  }
166  }
167 
168  // RhoVariance = Rho2 - (pow(RhoMean, 2) / (event->GetNumHits()));
169  RhoVariance = Rho2 - (event->GetNumHits() * pow((RhoMean / event->GetNumHits()), 2));
170 
171  for (Int_t iTb = 0; iTb < fNumTbs; iTb++)
172  event->SetMeshSignal(iTb, mesh[iTb]);
173  event->SortHitArrayTime();
174  event->SetMultiplicityMap(PadMultiplicity);
175  event->SetRhoVariance(RhoVariance);
176  event->SetEventCharge(QEventTot);
177 }
178 
179 Double_t AtPSA::getThreshold(int padSize)
180 {
181  if (padSize == 0)
182  return fThresholdlow; // threshold for central pads
183  return fThreshold; // threshold for big pads (or all other not small)
184 }
185 
195 double AtPSA::getZhitVariance(double zLoc, double zLocVar) const
196 {
197  return 0;
198 }
199 
200 std::pair<double, double> AtPSA::getXYhitVariance() const
201 {
202  return {0, 0};
203 }
204 
AtPad.h
AtPSA::SetThresholdLow
void SetThresholdLow(Int_t thresholdlow)
Definition: AtPSA.cxx:79
AtEvent::GetNumHits
Int_t GetNumHits() const
Definition: AtEvent.h:108
AtRawEvent.h
AtPSA::CalculateZ
Double_t CalculateZ(Double_t peakIdx)
Calculate z position in mm using the peak index.
Definition: AtPSA.cxx:85
AtPSA::SetSimulatedEvent
void SetSimulatedEvent(TClonesArray *MCSimPointArray)
Definition: AtPSA.cxx:67
AtEvent.h
AtPSA::CalculateZGeo
Double_t CalculateZGeo(Double_t peakIdx)
Definition: AtPSA.cxx:90
ClassImp
ClassImp(AtFindVertex)
AtPSA::fUsingLowThreshold
Bool_t fUsingLowThreshold
Definition: AtPSA.h:36
AtPSA::TrackMCPoints
void TrackMCPoints(std::multimap< Int_t, std::size_t > &map, AtHit &hit)
Definition: AtPSA.cxx:95
AtPSA::fEField
Double_t fEField
Definition: AtPSA.h:40
AtPSA::SetThreshold
void SetThreshold(Int_t threshold)
Definition: AtPSA.cxx:72
AtPSA::fNumTbs
Int_t fNumTbs
Definition: AtPSA.h:44
AtEvent
Definition: AtEvent.h:22
AtHit::AddMCSimPoint
void AddMCSimPoint(const AtHit::MCSimPoint &point)
Definition: AtHit.h:76
AtRawEvent
Definition: AtRawEvent.h:34
AtPSA::Analyze
AtEvent Analyze(AtRawEvent &rawEvent)
Definition: AtPSA.cxx:116
AtPSA::fBField
Double_t fBField
Definition: AtPSA.h:39
AtPSA::getXYhitVariance
virtual std::pair< double, double > getXYhitVariance() const
Definition: AtPSA.cxx:200
AtPSA::fMCSimPointArray
TClonesArray * fMCSimPointArray
Definition: AtPSA.h:34
AtRawEvent::GetPads
const PadVector & GetPads() const
Definition: AtRawEvent.h:131
AtPSA::fZk
Double_t fZk
Definition: AtPSA.h:48
AtPSA::getThreshold
Double_t getThreshold(int padSize=-1)
Definition: AtPSA.cxx:179
AtHit.h
AtDigiPar.h
AtDigiPar
Definition: AtDigiPar.h:14
AtPSA::fTB0
Int_t fTB0
Definition: AtPSA.h:41
AtPSA::fEntTB
Int_t fEntTB
Definition: AtPSA.h:46
AtPSA::fDriftVelocity
Double_t fDriftVelocity
Definition: AtPSA.h:47
AtMCPoint.h
AtPSA.h
AtHit::GetPadNum
Int_t GetPadNum() const
Definition: AtHit.h:83
AtMCPoint
Definition: AtMCPoint.h:26
AtRawEvent::GetSimMCPointMap
std::multimap< Int_t, std::size_t > & GetSimMCPointMap()
Definition: AtRawEvent.h:137
AtPSA
Definition: AtPSA.h:27
AtHit::MCSimPoint
Definition: AtHit.h:104
AtPSA::getZhitVariance
virtual double getZhitVariance(double zLoc, double zLocVar) const
Definition: AtPSA.cxx:195
AtPSA::AnalyzePad
virtual HitVector AnalyzePad(AtPad *pad)=0
AtEvent::SetMeshSignal
void SetMeshSignal(TraceArray mesharray)
Definition: AtEvent.h:105
AtHit
Point in space with charge.
Definition: AtHit.h:27
AtPSA::Init
virtual void Init()
Definition: AtPSA.cxx:30
AtPSA::fTBTime
Int_t fTBTime
Definition: AtPSA.h:45