ATTPCROOT  0.3.0-alpha
A ROOT-based framework for analyzing data from active target detectors
AtDataManip.cxx
Go to the documentation of this file.
1 #include "AtDataManip.h"
2 
3 #include "AtDigiPar.h"
4 
5 #include <FairLogger.h>
6 #include <FairParSet.h> // for FairParSet
7 #include <FairRun.h>
8 #include <FairRuntimeDb.h>
9 
10 #include <TF1.h>
11 #include <TMath.h> // for Pi
12 
13 #include <AtHit.h>
14 
15 #include <cmath> // for sqrt
16 
21 double AtTools::GetTB(double z, const AtDigiPar *fPar)
22 {
23  if (fPar == nullptr)
24  fPar = dynamic_cast<const AtDigiPar *>(FairRun::Instance()->GetRuntimeDb()->getContainer("AtDigiPar"));
25  if (fPar == nullptr) {
26  LOG(error) << "Could not find the digipar file!";
27  return -1;
28  }
29 
30  auto driftDistance = fPar->GetZPadPlane() - z;
31  auto driftTB = fPar->GetTBEntrance() - GetDriftTB(driftDistance, fPar);
32  LOG(debug) << driftDistance << " " << driftTB;
33 
34  return driftTB;
35 }
36 
37 double AtTools::GetDriftTB(double d, const AtDigiPar *fPar)
38 {
39  if (fPar == nullptr)
40  fPar = dynamic_cast<const AtDigiPar *>(FairRun::Instance()->GetRuntimeDb()->getContainer("AtDigiPar"));
41  if (fPar == nullptr) {
42  LOG(error) << "Could not find the digipar file!";
43  return -1;
44  }
45  auto driftTime = d / (fPar->GetDriftVelocity() * 10.);
46  return driftTime / (fPar->GetTBTime() / 1000.);
47 }
48 std::unique_ptr<TF1> AtTools::GetHitFunction(const AtHit &hit, const AtDigiPar *fPar)
49 {
50  if (hit.GetPositionSigma().Z() == 0) {
51  LOG(error) << "Hits that are points (sig_z = 0) are not supported yet!";
52  return nullptr;
53  }
54 
55  // position in mm to TB.
56  if (fPar == nullptr)
57  fPar = dynamic_cast<const AtDigiPar *>(FairRun::Instance()->GetRuntimeDb()->getContainer("AtDigiPar"));
58 
59  if (fPar == nullptr) {
60  LOG(error) << "Could not find the digipar file!";
61  return nullptr;
62  }
63 
64  // Create the function we are going to set and make sure it isn't added to the global list
65  auto func = std::make_unique<TF1>("hitFunc", "gaus", 0, fPar->GetZPadPlane(), TF1::EAddToList::kNo);
66  auto ampl = hit.GetCharge() / (hit.GetPositionSigma().Z() * std::sqrt(2 * TMath::Pi()));
67  func->SetParameter(0, ampl);
68  func->SetParameter(1, hit.GetPosition().Z());
69  func->SetParameter(2, hit.GetPositionSigma().Z());
70 
71  return func;
72 }
73 
74 std::unique_ptr<TF1> AtTools::GetHitFunctionTB(const AtHit &hit, const AtDigiPar *fPar)
75 {
76  if (hit.GetPositionSigma().Z() == 0) {
77  LOG(error) << "Hits that are points (sig_z = 0) are not supported yet!";
78  return nullptr;
79  }
80  if (fPar == nullptr)
81  fPar = dynamic_cast<const AtDigiPar *>(FairRun::Instance()->GetRuntimeDb()->getContainer("AtDigiPar"));
82 
83  // Create the function we are going to set and make sure it isn't added to the global list
84  auto func = std::make_unique<TF1>("hitFuncTB", "gaus", 0, 512, TF1::EAddToList::kNo);
85 
86  auto ampl = hit.GetCharge() / (GetDriftTB(hit.GetPositionSigma().Z(), fPar) * std::sqrt(2 * TMath::Pi()));
87  func->SetParameter(0, ampl);
88  func->SetParameter(1, GetTB(hit.GetPosition().Z(), fPar));
89  func->SetParameter(2, GetDriftTB(hit.GetPositionSigma().Z(), fPar));
90 
91  return func;
92 }
AtHit::GetPositionSigma
XYZVector GetPositionSigma() const
Definition: AtHit.cxx:25
AtDigiPar::GetZPadPlane
Double_t GetZPadPlane() const
Definition: AtDigiPar.h:50
AtDigiPar::GetTBEntrance
Int_t GetTBEntrance() const
Definition: AtDigiPar.h:49
AtTools::GetTB
double GetTB(double z, const AtDigiPar *par=nullptr)
Get TB that corresponds to the passed z position [mm].
Definition: AtDataManip.cxx:21
AtDigiPar::GetTBTime
Int_t GetTBTime() const
returns the time duration of a time bucket in given sampling time in ns.
Definition: AtDigiPar.cxx:17
AtDataManip.h
AtHit::GetPosition
const XYZPoint & GetPosition() const
Definition: AtHit.h:79
AtHit.h
AtTools::GetHitFunctionTB
std::unique_ptr< TF1 > GetHitFunctionTB(const AtHit &hit, const AtDigiPar *par=nullptr)
Get charge as a function of TB.
Definition: AtDataManip.cxx:74
AtDigiPar.h
AtDigiPar
Definition: AtDigiPar.h:14
AtTools::GetDriftTB
double GetDriftTB(double d, const AtDigiPar *par=nullptr)
Get TB that corresponds to a drift of distance d [mm].
Definition: AtDataManip.cxx:37
AtTools::GetHitFunction
std::unique_ptr< TF1 > GetHitFunction(const AtHit &hit, const AtDigiPar *par=nullptr)
Get charge as a function of z (mm).
Definition: AtDataManip.cxx:48
AtDigiPar::GetDriftVelocity
Double_t GetDriftVelocity() const
Definition: AtDigiPar.h:58
AtHit::GetCharge
Double_t GetCharge() const
Definition: AtHit.h:82
AtHit
Point in space with charge.
Definition: AtHit.h:27