FairShip
Loading...
Searching...
No Matches
TimeDet.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// Timing Detector
6// 26/01/2017
7// Alexander.Korzenev@cern.ch
8
9#include "TimeDet.h"
10
11#include <iostream>
12#include <sstream>
13
14#include "FairGeoBuilder.h"
15#include "FairGeoInterface.h"
16#include "FairGeoLoader.h"
17#include "FairGeoMedia.h"
18#include "FairGeoNode.h"
19#include "FairGeoVolume.h"
20#include "FairRootManager.h"
21#include "FairRun.h"
22#include "FairRuntimeDb.h"
23#include "FairVolume.h"
24#include "ShipDetectorList.h"
25#include "ShipGeoUtil.h"
26#include "ShipStack.h"
27#include "TClonesArray.h"
28#include "TGeoBBox.h"
29#include "TGeoCompositeShape.h"
30#include "TGeoManager.h"
31#include "TGeoMaterial.h"
32#include "TGeoMedium.h"
33#include "TGeoTube.h"
34#include "TMath.h"
35#include "TParticle.h"
36#include "TVector3.h"
37#include "TVirtualMC.h"
38#include "TimeDetPoint.h"
39using std::cout;
40using std::endl;
41
43 : Detector("TimeDet", kTRUE, kTimeDet),
44 fzPos(0),
45 fxSize(450),
46 fySize(650),
47 fxBar(168),
48 fyBar(6),
49 fzBar(1),
50 fdzBarCol(2.4),
51 fdzBarRow(1.2),
52 fNCol(3),
53 fNRow(148),
54 fxCenter(0),
55 fyCenter(0) {
56 fNBars = fNCol * fNRow;
57 if (fNCol > 1)
58 fxOv = (fxBar * fNCol - fxSize) / static_cast<double>(fNCol - 1);
59 else
60 fxOv = 0;
61 if (fNRow > 1)
62 fyOv = (fyBar * fNRow - fySize) / static_cast<double>(fNRow - 1);
63 else
64 fyOv = 0;
65}
66
67TimeDet::TimeDet(const char* name, Bool_t active)
68 : Detector(name, active, kTimeDet),
69 //
70 fzPos(0),
71 fxSize(450),
72 fySize(650),
73 fxBar(168),
74 fyBar(6),
75 fzBar(1),
76 fdzBarCol(2.4),
77 fdzBarRow(1.2),
78 fNCol(3),
79 fNRow(148),
80 fxCenter(0),
81 fyCenter(0) {
82 fNBars = fNCol * fNRow;
83 if (fNCol > 1)
84 fxOv = (fxBar * fNCol - fxSize) / static_cast<double>(fNCol - 1);
85 else
86 fxOv = 0;
87 if (fNRow > 1)
88 fyOv = (fyBar * fNRow - fySize) / static_cast<double>(fNRow - 1);
89 else
90 fyOv = 0;
91}
92
93Bool_t TimeDet::ProcessHits(FairVolume* vol) {
95 // Set parameters at entrance of volume. Reset ELoss.
96 if (gMC->IsTrackEntering()) {
97 fELoss = 0.;
98 fTime = gMC->TrackTime() * 1.0e09;
99 fLength = gMC->TrackLength();
100 gMC->TrackPosition(fPos);
101 gMC->TrackMomentum(fMom);
102 }
103
104 // Sum energy loss for all steps in the active volume
105 fELoss += gMC->Edep();
106
107 // Create vetoPoint at exit of active volume
108 if (gMC->IsTrackExiting() || gMC->IsTrackStop() ||
109 gMC->IsTrackDisappeared()) {
110 if (fELoss == 0.) {
111 return kFALSE;
112 }
113
114 fTrackID = gMC->GetStack()->GetCurrentTrackNumber();
115 fEventID = gMC->CurrentEvent();
116 Int_t uniqueId;
117 gMC->CurrentVolID(uniqueId);
118 if (uniqueId > 1000000) // Solid scintillator case
119 {
120 Int_t vcpy;
121 gMC->CurrentVolOffID(1, vcpy);
122 if (vcpy == 5) uniqueId += 4; // Copy of half
123 }
124
125 TParticle* p = gMC->GetStack()->GetCurrentTrack();
126 Int_t pdgCode = p->GetPdgCode();
127 TLorentzVector Pos;
128 gMC->TrackPosition(Pos);
129 TLorentzVector Mom;
130 gMC->TrackMomentum(Mom);
131 Double_t xmean = (fPos.X() + Pos.X()) / 2.;
132 Double_t ymean = (fPos.Y() + Pos.Y()) / 2.;
133 Double_t zmean = (fPos.Z() + Pos.Z()) / 2.;
134
135 // cout << uniqueId << " :(" << xmean << ", " << ymean << ", " << zmean <<
136 // "): " << gMC->CurrentVolName() << endl;
137
138 AddHit(fEventID, fTrackID, uniqueId, TVector3(xmean, ymean, zmean),
139 TVector3(fMom.Px(), fMom.Py(), fMom.Pz()), fTime, fLength, fELoss,
140 pdgCode, TVector3(Pos.X(), Pos.Y(), Pos.Z()),
141 TVector3(Mom.Px(), Mom.Py(), Mom.Pz()));
142
143 // Increment number of veto det points in TParticle
144 ShipStack* stack = dynamic_cast<ShipStack*>(gMC->GetStack());
145 stack->AddPoint(kTimeDet);
146 }
147
148 return kTRUE;
149}
150
152 TGeoVolume* top = gGeoManager->GetTopVolume();
153
154 ShipGeo::InitMedium("polyvinyltoluene");
155 TGeoMedium* Scint = gGeoManager->GetMedium("polyvinyltoluene");
156
158
159 fDetector = new TGeoVolumeAssembly("Timing Detector");
160
161 TGeoVolume* plate =
162 gGeoManager->MakeBox("TimeDet", Scint, fxBar / 2, fyBar / 2, fzBar / 2);
163 plate->SetLineColor(kBlue);
164 AddSensitiveVolume(plate);
165
166 for (int ib = 0; ib < fNBars; ib++) {
167 int irow = 0, icol = 0;
168 GetBarRowCol(ib, irow, icol);
169
170 double xbar = 0, ybar = 0, zbar = 0;
171 xbar = GetXCol(icol);
172 ybar = GetYRow(irow);
173 zbar = GetZBar(irow, icol);
174
175 fDetector->AddNode(plate, ib, new TGeoTranslation(xbar, ybar, zbar));
176
177 // printf("%3i %3i %2i %8.3f %8.3f %8.3f\n",ib, irow,icol,
178 // xbar,ybar,zbar);
179 }
180
181 top->AddNode(fDetector, 1, new TGeoTranslation(0, 0, fzPos));
182
184
185 return;
186}
187
188void TimeDet::GetBarRowCol(int ib, int& irow, int& icol) const {
189 irow = ib / fNCol;
190 icol = (ib % fNCol);
191 return;
192}
193
194double TimeDet::GetXCol(int ic) const {
195 ic += 1;
196 double x = fxBar * ic - fxOv * (ic - 1) - fxBar / 2;
197 return x - fxSize / 2 + fxCenter;
198}
199
200double TimeDet::GetYRow(int ir) const {
201 ir += 1;
202 double y = fyBar * ir - fyOv * (ir - 1) - fyBar / 2;
203 return y - fySize / 2 + fyCenter;
204}
205
206double TimeDet::GetZBar(int ir, int ic) const {
207 double z = (ir % 2) * fdzBarRow + (ic % 2) * fdzBarCol;
208 return z;
209}
@ kTimeDet
Int_t fTrackID
event index
Definition: Detector.h:85
TLorentzVector fPos
volume id
Definition: Detector.h:87
Double_t fTime
momentum at entrance
Definition: Detector.h:89
TimeDetPoint * AddHit(Args &&... args)
Definition: Detector.h:38
TLorentzVector fMom
position at entrance
Definition: Detector.h:88
Double_t fxSize
z-position of veto station
Definition: TimeDet.h:57
Double_t fxBar
height of the detector
Definition: TimeDet.h:60
Double_t fyOv
Overlap along x.
Definition: TimeDet.h:75
Double_t fxCenter
Number of rows.
Definition: TimeDet.h:70
void GetBarRowCol(int ib, int &irow, int &icol) const
Definition: TimeDet.cxx:188
double GetXCol(int ic) const
Definition: TimeDet.cxx:194
Int_t fNRow
Number of columns.
Definition: TimeDet.h:68
Int_t fNBars
y-position of the detector center
Definition: TimeDet.h:73
Double_t fdzBarRow
z-distance between columns
Definition: TimeDet.h:65
Double_t fySize
width of the detector
Definition: TimeDet.h:58
Double_t fyBar
length of the bar
Definition: TimeDet.h:61
Bool_t ProcessHits(FairVolume *v=0) override
Definition: TimeDet.cxx:93
Double_t fzPos
Definition: TimeDet.h:55
Double_t fyCenter
x-position of the detector center
Definition: TimeDet.h:71
Double_t fzBar
width of the bar
Definition: TimeDet.h:62
Int_t fNCol
z-distance between rows
Definition: TimeDet.h:67
void ConstructGeometry() override
Definition: TimeDet.cxx:151
Double_t fdzBarCol
depth of the bar
Definition: TimeDet.h:64
double GetZBar(int ir, int ic) const
Definition: TimeDet.cxx:206
TimeDet()
Definition: TimeDet.cxx:42
Double_t fxOv
Number of bars.
Definition: TimeDet.h:74
double GetYRow(int ir) const
Definition: TimeDet.cxx:200
Int_t InitMedium(const char *name)
Definition: ShipGeoUtil.h:20