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
42namespace {
43constexpr Double_t kDefaultBarOverlapX = 10.0; // 100 mm
44constexpr Double_t kDefaultBarOverlapY = 0.55; // 5.5 mm
45} // namespace
46
48 : Detector("TimeDet", kTRUE, kTimeDet),
49 fzPos(0),
50 fxSize(550),
51 fySize(650),
52 fxBar(140),
53 fyBar(6),
54 fzBar(1),
55 fdzBarCol(9.0),
56 fdzBarRow(1.2),
57 fNCol(3),
58 fNRow(110),
59 fxCenter(0),
60 fyCenter(0) {
61 fNBars = fNCol * fNRow;
62 fxOv = kDefaultBarOverlapX;
63 fyOv = kDefaultBarOverlapY;
64}
65
66TimeDet::TimeDet(const char* name, Bool_t active)
67 : Detector(name, active, kTimeDet),
68 //
69 fzPos(0),
70 fxSize(550),
71 fySize(650),
72 fxBar(140),
73 fyBar(6),
74 fzBar(1),
75 fdzBarCol(9.0),
76 fdzBarRow(1.2),
77 fNCol(3),
78 fNRow(110),
79 fxCenter(0),
80 fyCenter(0) {
81 fNBars = fNCol * fNRow;
82 fxOv = kDefaultBarOverlapX;
83 fyOv = kDefaultBarOverlapY;
84}
85
86Bool_t TimeDet::ProcessHits(FairVolume* vol) {
88 // Set parameters at entrance of volume. Reset ELoss.
89 if (gMC->IsTrackEntering()) {
90 fELoss = 0.;
91 fTime = gMC->TrackTime() * 1.0e09;
92 fLength = gMC->TrackLength();
93 gMC->TrackPosition(fPos);
94 gMC->TrackMomentum(fMom);
95 }
96
97 // Sum energy loss for all steps in the active volume
98 fELoss += gMC->Edep();
99
100 // Create vetoPoint at exit of active volume
101 if (gMC->IsTrackExiting() || gMC->IsTrackStop() ||
102 gMC->IsTrackDisappeared()) {
103 if (fELoss == 0.) {
104 return kFALSE;
105 }
106
107 fTrackID = gMC->GetStack()->GetCurrentTrackNumber();
108 fEventID = gMC->CurrentEvent();
109 Int_t uniqueId;
110 gMC->CurrentVolID(uniqueId);
111 if (uniqueId > 1000000) // Solid scintillator case
112 {
113 Int_t vcpy;
114 gMC->CurrentVolOffID(1, vcpy);
115 if (vcpy == 5) uniqueId += 4; // Copy of half
116 }
117
118 TParticle* p = gMC->GetStack()->GetCurrentTrack();
119 Int_t pdgCode = p->GetPdgCode();
120 TLorentzVector Pos;
121 gMC->TrackPosition(Pos);
122 TLorentzVector Mom;
123 gMC->TrackMomentum(Mom);
124 Double_t xmean = (fPos.X() + Pos.X()) / 2.;
125 Double_t ymean = (fPos.Y() + Pos.Y()) / 2.;
126 Double_t zmean = (fPos.Z() + Pos.Z()) / 2.;
127
128 // cout << uniqueId << " :(" << xmean << ", " << ymean << ", " << zmean <<
129 // "): " << gMC->CurrentVolName() << endl;
130
131 AddHit(fEventID, fTrackID, uniqueId, TVector3(xmean, ymean, zmean),
132 TVector3(fMom.Px(), fMom.Py(), fMom.Pz()), fTime, fLength, fELoss,
133 pdgCode, TVector3(Pos.X(), Pos.Y(), Pos.Z()),
134 TVector3(Mom.Px(), Mom.Py(), Mom.Pz()));
135
136 // Increment number of veto det points in TParticle
137 ShipStack* stack = dynamic_cast<ShipStack*>(gMC->GetStack());
138 stack->AddPoint(kTimeDet);
139 }
140
141 return kTRUE;
142}
143
145 TGeoVolume* top = gGeoManager->GetTopVolume();
146
147 ShipGeo::InitMedium("polyvinyltoluene");
148 TGeoMedium* Scint = gGeoManager->GetMedium("polyvinyltoluene");
149
151
152 fDetector = new TGeoVolumeAssembly("Timing Detector");
153
154 TGeoVolume* plate =
155 gGeoManager->MakeBox("TimeDet", Scint, fxBar / 2, fyBar / 2, fzBar / 2);
156 plate->SetLineColor(kBlue);
157 AddSensitiveVolume(plate);
158
159 for (int ib = 0; ib < fNBars; ib++) {
160 int irow = 0, icol = 0;
161 GetBarRowCol(ib, irow, icol);
162
163 double xbar = 0, ybar = 0, zbar = 0;
164 xbar = GetXCol(icol);
165 ybar = GetYRow(irow);
166 zbar = GetZBar(irow, icol);
167
168 fDetector->AddNode(plate, ib, new TGeoTranslation(xbar, ybar, zbar));
169
170 // printf("%3i %3i %2i %8.3f %8.3f %8.3f\n",ib, irow,icol,
171 // xbar,ybar,zbar);
172 }
173
174 top->AddNode(fDetector, 1, new TGeoTranslation(0, 0, fzPos));
175
177
178 return;
179}
180
181void TimeDet::GetBarRowCol(int ib, int& irow, int& icol) const {
182 irow = ib / fNCol;
183 icol = (ib % fNCol);
184 return;
185}
186
187double TimeDet::GetXCol(int ic) const {
188 return (ic - 0.5 * (fNCol - 1)) * (fxBar - fxOv) + fxCenter;
189}
190
191double TimeDet::GetYRow(int ir) const {
192 return (ir - 0.5 * (fNRow - 1)) * (fyBar - fyOv) + fyCenter;
193}
194
195double TimeDet::GetZBar(int ir, int ic) const {
196 double z = (ir % 2) * fdzBarRow + (ic % 2) * fdzBarCol;
197 return z;
198}
@ kTimeDet
TimeDetPoint * AddHit(Args &&... args)
Definition Detector.h:38
Double_t fxSize
z-position of veto station
Definition TimeDet.h:66
Double_t fxBar
height of the detector
Definition TimeDet.h:69
Double_t fyOv
Overlap along x.
Definition TimeDet.h:84
Double_t fxCenter
Number of rows.
Definition TimeDet.h:79
void GetBarRowCol(int ib, int &irow, int &icol) const
Definition TimeDet.cxx:181
double GetXCol(int ic) const
Definition TimeDet.cxx:187
Int_t fNRow
Number of columns.
Definition TimeDet.h:77
Int_t fNBars
y-position of the detector center
Definition TimeDet.h:82
Double_t fdzBarRow
z-distance between columns
Definition TimeDet.h:74
Double_t fySize
width of the detector
Definition TimeDet.h:67
Double_t fyBar
length of the bar
Definition TimeDet.h:70
Double_t fzPos
Definition TimeDet.h:64
Double_t fyCenter
x-position of the detector center
Definition TimeDet.h:80
Double_t fzBar
width of the bar
Definition TimeDet.h:71
Int_t fNCol
z-distance between rows
Definition TimeDet.h:76
Bool_t ProcessHits(FairVolume *v=nullptr) override
Definition TimeDet.cxx:86
void ConstructGeometry() override
Definition TimeDet.cxx:144
Double_t fdzBarCol
depth of the bar
Definition TimeDet.h:73
double GetZBar(int ir, int ic) const
Definition TimeDet.cxx:195
TimeDet()
Definition TimeDet.cxx:47
Double_t fxOv
Number of bars.
Definition TimeDet.h:83
double GetYRow(int ir) const
Definition TimeDet.cxx:191
Int_t InitMedium(const char *name)
Definition ShipGeoUtil.h:22