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
22namespace {
23constexpr Double_t speedOfLight = 29.9792458; // TMath::C() * 100 / 1e9, cm/ns
24} // namespace
25
26// ----- Default constructor --------------
27TimeDetHit::TimeDetHit() : SHiP::DetectorHit() {}
28
29// ----- constructor from TimeDetPoint from
30// TimeDetHit-------------------------------
31TimeDetHit::TimeDetHit(TimeDetPoint* p, Double_t t0) : SHiP::DetectorHit() {
32 if (!p) {
33 LOG(error) << "TimeDetHit: null TimeDetPoint pointer";
34 return;
35 }
36 fDetectorID = p->GetDetectorID();
37 Float_t lpos, lneg;
38 Dist(p->GetX(), lpos, lneg);
39 Double_t sigma = Resol(lneg); // in ns
40 t_1 = gRandom->Gaus(0, sigma) + lneg / v_drift + t0 + p->GetTime();
41 sigma = Resol(lpos); // in ns
42 t_2 = gRandom->Gaus(0, sigma) + lpos / v_drift + t0 + p->GetTime();
43}
44
45// ---- return time information for a given track extrapolation
46std::vector<double> TimeDetHit::GetTime(Double_t x) const {
47 // calculate distance to left and right end
48 Float_t lpos, lneg;
49 Dist(x, lpos, lneg);
50 Double_t r = Resol(lneg);
51 Double_t w1 = 1. / (r * r);
52 r = Resol(lpos);
53 Double_t w2 = 1. / (r * r);
54 Double_t dt = 1. / TMath::Sqrt(w1 + w2);
55 Double_t t =
56 ((t_1 - lneg / v_drift) * w1 + (t_2 - lpos / v_drift) * w2) / (w1 + w2);
57 return {t, dt};
58}
59// ---- return mean time information
60std::vector<double> TimeDetHit::GetTime() const {
61 TGeoBBox* shape =
62 dynamic_cast<TGeoBBox*>(gGeoManager->GetVolume("TimeDet")->GetShape());
63 Double_t t0 = (t_1 + t_2) / 2. - shape->GetDX() / v_drift;
64 Float_t lpos, lneg;
65 lneg = (t_1 - t0) * v_drift;
66 lpos = (t_2 - t0) * v_drift;
67 Float_t r1 = Resol(lneg);
68 Float_t r2 = Resol(lpos);
69 Double_t dt = TMath::Sqrt(r1 * r1 + r2 * r2);
70 return {t0, dt};
71}
72// ----- resolution function-------------------
73Double_t TimeDetHit::Resol(Double_t x) const {
74 return par[0] * TMath::Exp((x - par[2]) / par[1]) + par[3];
75}
76
77std::vector<double> TimeDetHit::GetMeasurements() const { return {t_1, t_2}; }
78
79// distance to edges
80void TimeDetHit::Dist(Float_t x, Float_t& lpos, Float_t& lneg) const {
81 TGeoNode* node = GetNode();
82 auto shape = dynamic_cast<TGeoBBox*>(node->GetVolume()->GetShape());
83 TVector3 pos = GetXYZ();
84 lpos = TMath::Abs(pos.X() + shape->GetDX() - x);
85 lneg = TMath::Abs(pos.X() - shape->GetDX() - x);
86}
87// ----------------------------------------------
88TVector3 TimeDetHit::GetXYZ() const {
89 TGeoNavigator* nav = gGeoManager->GetCurrentNavigator();
90 TGeoNode* node = GetNode();
91 auto shape = dynamic_cast<TGeoBBox*>(node->GetVolume()->GetShape());
92 Double_t origin[3] = {shape->GetOrigin()[0], shape->GetOrigin()[1],
93 shape->GetOrigin()[2]};
94 Double_t master[3] = {0, 0, 0};
95 nav->LocalToMaster(origin, master);
96 TVector3 pos = TVector3(master[0], master[1], master[2]);
97 return pos;
98}
99
100Double_t TimeDetHit::GetX() const {
101 TVector3 pos = GetXYZ();
102 return pos.X();
103}
104
105Double_t TimeDetHit::GetY() const {
106 TVector3 pos = GetXYZ();
107 return pos.Y();
108}
109
110Double_t TimeDetHit::GetZ() const {
111 TVector3 pos = GetXYZ();
112 return pos.Z();
113}
114
115TGeoNode* TimeDetHit::GetNode() const {
116 TGeoNavigator* nav = gGeoManager->GetCurrentNavigator();
117 TString path = "/Timing Detector_1/TimeDet_";
118 path += fDetectorID;
119 nav->cd(path);
120 return nav->GetCurrentNode();
121}
122
123// ----- Public method Print -----------------------
124void TimeDetHit::Print() const {
125 cout << "-I- TimeDetHit: TimeDet hit " << " in detector " << fDetectorID
126 << endl;
127 cout << " TDC left " << t_1 << " ns TDC right " << t_2 << " ns" << endl;
128}
129
130// -----------------------------------------------------
Int_t fDetectorID
Detector unique identifier.
Definition: DetectorHit.h:40
Double_t GetX() const
Definition: TimeDetHit.cxx:100
std::vector< double > GetMeasurements() const
Definition: TimeDetHit.cxx:77
Double_t GetZ() const
Definition: TimeDetHit.cxx:110
TVector3 GetXYZ() const
Definition: TimeDetHit.cxx:88
static constexpr Double_t v_drift
Definition: TimeDetHit.h:56
std::vector< double > GetTime() const
Definition: TimeDetHit.cxx:60
Float_t t_1
Definition: TimeDetHit.h:60
Double_t Resol(Double_t x) const
Definition: TimeDetHit.cxx:73
TGeoNode * GetNode() const
Definition: TimeDetHit.cxx:115
static constexpr Double_t par[4]
Definition: TimeDetHit.h:57
void Dist(Float_t x, Float_t &lpos, Float_t &lneg) const
Definition: TimeDetHit.cxx:80
Double_t GetY() const
Definition: TimeDetHit.cxx:105
void Print() const
Definition: TimeDetHit.cxx:124
Float_t t_2
TDC on both sides.
Definition: TimeDetHit.h:60
Definition: Detector.h:18
int speedOfLight
Definition: shipunit.py:317