FairShip
Loading...
Searching...
No Matches
TimeDetHit.cxx
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-3.0-or-later
2// SPDX-FileCopyrightText: Copyright CERN for the benefit of the SHiP
3// Collaboration
4
5#include "TimeDetHit.h"
6
7#include <cmath>
8#include <iostream>
9
10#include "TGeoBBox.h"
11#include "TGeoManager.h"
12#include "TGeoNode.h"
13#include "TMath.h"
14#include "TRandom1.h"
15#include "TRandom3.h"
16#include "TVector3.h"
17#include "TimeDet.h"
18
19using std::cout;
20using std::endl;
21
22// ----- Default constructor --------------
24
25// ----- constructor from TimeDetPoint from
26// TimeDetHit-------------------------------
28 if (!p) {
29 LOG(error) << "TimeDetHit: null TimeDetPoint pointer";
30 return;
31 }
32 fDetectorID = p->GetDetectorID();
33 Float_t lpos, lneg;
34 Dist(p->GetX(), lpos, lneg);
35 Double_t sigma = Resol(lneg); // in ns
36 t_1 = gRandom->Gaus(0, sigma) + lneg / v_drift + t0 + p->GetTime();
37 sigma = Resol(lpos); // in ns
38 t_2 = gRandom->Gaus(0, sigma) + lpos / v_drift + t0 + p->GetTime();
39}
40
41// ---- return time information for a given track extrapolation
42std::vector<double> TimeDetHit::GetTime(Double_t x) const {
43 // calculate distance to left and right end
44 Float_t lpos, lneg;
45 Dist(x, lpos, lneg);
46 Double_t r = Resol(lneg);
47 Double_t w1 = 1. / (r * r);
48 r = Resol(lpos);
49 Double_t w2 = 1. / (r * r);
50 Double_t dt = 1. / TMath::Sqrt(w1 + w2);
51 Double_t t =
52 ((t_1 - lneg / v_drift) * w1 + (t_2 - lpos / v_drift) * w2) / (w1 + w2);
53 return {t, dt};
54}
55// ---- return mean time information
56std::vector<double> TimeDetHit::GetTime() const {
57 TGeoBBox* shape =
58 dynamic_cast<TGeoBBox*>(gGeoManager->GetVolume("TimeDet")->GetShape());
59 Double_t t0 = (t_1 + t_2) / 2. - shape->GetDX() / v_drift;
60 Float_t lpos, lneg;
61 lneg = (t_1 - t0) * v_drift;
62 lpos = (t_2 - t0) * v_drift;
63 Float_t r1 = Resol(lneg);
64 Float_t r2 = Resol(lpos);
65 Double_t dt = TMath::Sqrt(r1 * r1 + r2 * r2);
66 return {t0, dt};
67}
68// ----- resolution function-------------------
69Double_t TimeDetHit::Resol(Double_t x) const {
70 return par[0] * TMath::Exp((x - par[2]) / par[1]) + par[3];
71}
72
73std::vector<double> TimeDetHit::GetMeasurements() const { return {t_1, t_2}; }
74
75// distance to edges
76void TimeDetHit::Dist(Float_t x, Float_t& lpos, Float_t& lneg) const {
77 TGeoNode* node = GetNode();
78 auto shape = dynamic_cast<TGeoBBox*>(node->GetVolume()->GetShape());
79 TVector3 pos = GetXYZ();
80 lpos = TMath::Abs(pos.X() + shape->GetDX() - x);
81 lneg = TMath::Abs(pos.X() - shape->GetDX() - x);
82}
83// ----------------------------------------------
84TVector3 TimeDetHit::GetXYZ() const {
85 TGeoNavigator* nav = gGeoManager->GetCurrentNavigator();
86 TGeoNode* node = GetNode();
87 auto shape = dynamic_cast<TGeoBBox*>(node->GetVolume()->GetShape());
88 Double_t origin[3] = {shape->GetOrigin()[0], shape->GetOrigin()[1],
89 shape->GetOrigin()[2]};
90 Double_t master[3] = {0, 0, 0};
91 nav->LocalToMaster(origin, master);
92 TVector3 pos = TVector3(master[0], master[1], master[2]);
93 return pos;
94}
95
96Double_t TimeDetHit::GetX() const {
97 TVector3 pos = GetXYZ();
98 return pos.X();
99}
100
101Double_t TimeDetHit::GetY() const {
102 TVector3 pos = GetXYZ();
103 return pos.Y();
104}
105
106Double_t TimeDetHit::GetZ() const {
107 TVector3 pos = GetXYZ();
108 return pos.Z();
109}
110
111TGeoNode* TimeDetHit::GetNode() const {
112 TGeoNavigator* nav = gGeoManager->GetCurrentNavigator();
113 TString path = "/Timing Detector_1/TimeDet_";
114 path += fDetectorID;
115 nav->cd(path);
116 return nav->GetCurrentNode();
117}
118
119// ----- Public method Print -----------------------
120void TimeDetHit::Print() const {
121 cout << "-I- TimeDetHit: TimeDet hit " << " in detector " << fDetectorID
122 << endl;
123 cout << " TDC left " << t_1 << " ns TDC right " << t_2 << " ns" << endl;
124}
125
126// -----------------------------------------------------
Int_t fDetectorID
Detector unique identifier.
Definition DetectorHit.h:40
Double_t GetX() const
std::vector< double > GetMeasurements() const
Double_t GetZ() const
TVector3 GetXYZ() const
static constexpr Double_t v_drift
Definition TimeDetHit.h:56
std::vector< double > GetTime() const
Float_t t_1
Definition TimeDetHit.h:60
Double_t Resol(Double_t x) const
TGeoNode * GetNode() const
static constexpr Double_t par[4]
Definition TimeDetHit.h:57
void Dist(Float_t x, Float_t &lpos, Float_t &lneg) const
Double_t GetY() const
void Print() const
Float_t t_2
TDC on both sides.
Definition TimeDetHit.h:60