SND@LHC Software
Loading...
Searching...
No Matches
TimeDet.cxx
Go to the documentation of this file.
1// Timing Detector
2// 26/01/2017
3// Alexander.Korzenev@cern.ch
4
5#include "TimeDet.h"
6#include "TimeDetPoint.h"
7
8#include "FairVolume.h"
9#include "FairGeoVolume.h"
10#include "FairGeoNode.h"
11#include "FairRootManager.h"
12#include "FairGeoLoader.h"
13#include "FairGeoInterface.h"
14#include "FairGeoMedia.h"
15#include "FairGeoBuilder.h"
16#include "FairRun.h"
17#include "FairRuntimeDb.h"
18#include "ShipDetectorList.h"
19#include "ShipStack.h"
20
21#include "TClonesArray.h"
22#include "TVirtualMC.h"
23#include "TGeoManager.h"
24#include "TGeoBBox.h"
25#include "TGeoCompositeShape.h"
26#include "TGeoTube.h"
27#include "TGeoMaterial.h"
28#include "TGeoMedium.h"
29#include "TMath.h"
30#include "TParticle.h"
31#include "TVector3.h"
32
33#include <iostream>
34#include <sstream>
35using std::cout;
36using std::endl;
37
38
40 : FairDetector("TimeDet", kTRUE, kTimeDet),
41 fTrackID(-1),
42 fVolumeID(-1),
43 fPos(),
44 fMom(),
45 fTime(-1.),
46 fLength(-1.),
47 fELoss(-1),
48 //
49 fzPos(0),
50 fxSize(500),
51 fySize(1000),
52 fxBar(168),
53 fyBar(6),
54 fzBar(1),
55 fdzBarCol(2.4),
56 fdzBarRow(1.2),
57 fNCol(3),
58 fNRow(182),
59 fxCenter(0),
60 fyCenter(0),
61 //
62 fDetector(0),
63 //
64 fTimeDetPointCollection(new TClonesArray("TimeDetPoint"))
65{
66 fNBars = fNCol * fNRow;
67 if(fNCol>1) fxOv = (fxBar*fNCol - fxSize) / (double)(fNCol-1); else fxOv = 0;
68 if(fNRow>1) fyOv = (fyBar*fNRow - fySize) / (double)(fNRow-1); else fyOv = 0;
69}
70
71
72
73TimeDet::TimeDet(const char* name, Bool_t active)
74 : FairDetector(name, active, kTimeDet),
75 fTrackID(-1),
76 fVolumeID(-1),
77 fPos(),
78 fMom(),
79 fTime(-1.),
80 fLength(-1.),
81 fELoss(-1),
82 //
83 fzPos(0),
84 fxSize(500),
85 fySize(1000),
86 fxBar(168),
87 fyBar(6),
88 fzBar(1),
89 fdzBarCol(2.4),
90 fdzBarRow(1.2),
91 fNCol(3),
92 fNRow(182),
93 fxCenter(0),
94 fyCenter(0),
95 //
96 fDetector(0),
97 //
98 fTimeDetPointCollection(new TClonesArray("TimeDetPoint"))
99{
100 fNBars = fNCol * fNRow;
101 if(fNCol>1) fxOv = (fxBar*fNCol - fxSize) / (double)(fNCol-1); else fxOv = 0;
102 if(fNRow>1) fyOv = (fyBar*fNRow - fySize) / (double)(fNRow-1); else fyOv = 0;
103
104}
105
107{
108 FairDetector::Initialize();
109}
110
111
113{
115 fTimeDetPointCollection->Delete();
117 }
118}
119
120
121
122Int_t TimeDet::InitMedium(const char* name)
123{
124
125 static FairGeoLoader *geoLoad=FairGeoLoader::Instance();
126 static FairGeoInterface *geoFace=geoLoad->getGeoInterface();
127 static FairGeoMedia *media=geoFace->getMedia();
128 static FairGeoBuilder *geoBuild=geoLoad->getGeoBuilder();
129
130 FairGeoMedium *ShipMedium=media->getMedium(name);
131
132 if (!ShipMedium)
133 {
134 Fatal("InitMedium","Material %s not defined in media file.", name);
135 return -1111;
136 }
137 TGeoMedium* medium=gGeoManager->GetMedium(name);
138 if (medium!=NULL)
139 return ShipMedium->getMediumIndex();
140
141 return geoBuild->createMedium(ShipMedium);
142
143 return 0;
144}
145
146
147
148Bool_t TimeDet::ProcessHits(FairVolume* vol)
149{
151 //Set parameters at entrance of volume. Reset ELoss.
152 if ( gMC->IsTrackEntering() ) {
153 fELoss = 0.;
154 fTime = gMC->TrackTime() * 1.0e09;
155 fLength = gMC->TrackLength();
156 gMC->TrackPosition(fPos);
157 gMC->TrackMomentum(fMom);
158 }
159
160 // Sum energy loss for all steps in the active volume
161 fELoss += gMC->Edep();
162
163 // Create vetoPoint at exit of active volume
164 if ( gMC->IsTrackExiting() ||
165 gMC->IsTrackStop() ||
166 gMC->IsTrackDisappeared() ) {
167 if (fELoss == 0. ) { return kFALSE; }
168
169 fTrackID = gMC->GetStack()->GetCurrentTrackNumber();
170
171 Int_t uniqueId;
172 gMC->CurrentVolID(uniqueId);
173 if (uniqueId>1000000) //Solid scintillator case
174 {
175 Int_t vcpy;
176 gMC->CurrentVolOffID(1, vcpy);
177 if (vcpy==5) uniqueId+=4; //Copy of half
178 }
179
180 TParticle* p = gMC->GetStack()->GetCurrentTrack();
181 Int_t pdgCode = p->GetPdgCode();
182 TLorentzVector Pos;
183 gMC->TrackPosition(Pos);
184 TLorentzVector Mom;
185 gMC->TrackMomentum(Mom);
186 Double_t xmean = (fPos.X()+Pos.X())/2. ;
187 Double_t ymean = (fPos.Y()+Pos.Y())/2. ;
188 Double_t zmean = (fPos.Z()+Pos.Z())/2. ;
189
190 //cout << uniqueId << " :(" << xmean << ", " << ymean << ", " << zmean << "): " << gMC->CurrentVolName() << endl;
191
192 AddHit(fTrackID, uniqueId, TVector3(xmean, ymean, zmean),
193 TVector3(fMom.Px(), fMom.Py(), fMom.Pz()), fTime, fLength,
194 fELoss,pdgCode,TVector3(Pos.X(), Pos.Y(), Pos.Z()),
195 TVector3(Mom.Px(), Mom.Py(), Mom.Pz()) );
196
197 // Increment number of veto det points in TParticle
198 ShipStack* stack = (ShipStack*) gMC->GetStack();
199 stack->AddPoint(kTimeDet);
200 }
201
202 return kTRUE;
203}
204
205
206
208{
210}
211
212
213
215{
216
223 FairRootManager::Instance()->Register("TimeDetPoint", "TimeDet",
225}
226
227
228
229TClonesArray* TimeDet::GetCollection(Int_t iColl) const
230{
231 if (iColl == 0) { return fTimeDetPointCollection; }
232 else { return NULL; }
233}
234
235
236
238{
240}
241
242
243
245{
246 TGeoVolume *top = gGeoManager->GetTopVolume();
247
248 InitMedium("polyvinyltoluene");
249 TGeoMedium *Scint =gGeoManager->GetMedium("polyvinyltoluene");
250
252
253 fDetector = new TGeoVolumeAssembly("Timing Detector");
254
255 TGeoVolume *plate = gGeoManager->MakeBox("TimeDet", Scint, fxBar/2,fyBar/2,fzBar/2);
256 plate->SetLineColor(kBlue);
257 AddSensitiveVolume(plate);
258
259 for(int ib=0; ib<fNBars; ib++) {
260
261 int irow=0, icol=0;
262 GetBarRowCol(ib,irow,icol);
263
264 double xbar=0,ybar=0,zbar=0;
265 xbar = GetXCol(icol);
266 ybar = GetYRow(irow);
267 zbar = GetZBar(irow,icol);
268
269 fDetector->AddNode(plate, ib, new TGeoTranslation( xbar,ybar,zbar) );
270
271 //printf("%3i %3i %2i %8.3f %8.3f %8.3f\n",ib, irow,icol, xbar,ybar,zbar);
272 }
273
274 top->AddNode(fDetector, 1, new TGeoTranslation(0,0,fzPos));
275
277
278 return;
279}
280
281
282
283TimeDetPoint* TimeDet::AddHit(Int_t trackID, Int_t detID,
284 TVector3 pos, TVector3 mom,
285 Double_t time, Double_t length,
286 Double_t eLoss, Int_t pdgCode,TVector3 Lpos, TVector3 Lmom)
287{
288 TClonesArray& clref = *fTimeDetPointCollection;
289 Int_t size = clref.GetEntriesFast();
290 // cout << "veto hit called "<< pos.z()<<endl;
291 return new(clref[size]) TimeDetPoint(trackID, detID, pos, mom,
292 time, length, eLoss, pdgCode,Lpos,Lmom);
293}
294
295
296void TimeDet::GetBarRowCol(int ib,int &irow,int& icol) const
297{
298 irow = ib / fNCol;
299 icol = (ib%fNCol);
300 return;
301}
302
303
304double TimeDet::GetXCol(int ic) const
305{
306 ic += 1;
307 double x = fxBar*ic - fxOv*(ic-1) - fxBar/2;
308 return x - fxSize/2 + fxCenter;
309}
310
311
312double TimeDet::GetYRow(int ir) const
313{
314 ir += 1;
315 double y = fyBar*ir - fyOv*(ir-1) - fyBar/2;
316 return y - fySize/2 + fyCenter;
317}
318
319
320double TimeDet::GetZBar(int ir,int ic) const
321{
322 double z = (ir%2) * fdzBarRow + (ic%2) * fdzBarCol;
323 return z;
324}
325
326
@ kTimeDet
TGeoVolume * fDetector
Overlap along y.
Definition TimeDet.h:118
Double_t fxSize
z-position of veto station
Definition TimeDet.h:98
Double_t fxBar
height of the detector
Definition TimeDet.h:101
Double_t fTime
momentum at entrance
Definition TimeDet.h:91
Double_t fyOv
Overlap along x.
Definition TimeDet.h:116
virtual void Register()
Definition TimeDet.cxx:214
Double_t fxCenter
Number of rows.
Definition TimeDet.h:111
void GetBarRowCol(int ib, int &irow, int &icol) const
Definition TimeDet.cxx:296
double GetXCol(int ic) const
Definition TimeDet.cxx:304
Int_t fNRow
Number of columns.
Definition TimeDet.h:109
Int_t fNBars
y-position of the detector center
Definition TimeDet.h:114
Double_t fdzBarRow
z-distance between columns
Definition TimeDet.h:106
TimeDetPoint * AddHit(Int_t trackID, Int_t detID, TVector3 pos, TVector3 mom, Double_t time, Double_t length, Double_t eLoss, Int_t pdgCode, TVector3 Lpos, TVector3 Lmom)
Definition TimeDet.cxx:283
void ConstructGeometry()
Definition TimeDet.cxx:244
Int_t InitMedium(const char *name)
Definition TimeDet.cxx:122
Double_t fySize
width of the detector
Definition TimeDet.h:99
Double_t fyBar
length of the bar
Definition TimeDet.h:102
Double_t fzPos
energy loss
Definition TimeDet.h:96
Double_t fyCenter
x-position of the detector center
Definition TimeDet.h:112
Double_t fELoss
length
Definition TimeDet.h:93
Int_t fTrackID
Definition TimeDet.h:87
virtual TClonesArray * GetCollection(Int_t iColl) const
Definition TimeDet.cxx:229
Double_t fzBar
width of the bar
Definition TimeDet.h:103
TClonesArray * fTimeDetPointCollection
Definition TimeDet.h:121
Int_t fNCol
z-distance between rows
Definition TimeDet.h:108
virtual void Reset()
Definition TimeDet.cxx:237
TLorentzVector fMom
position at entrance
Definition TimeDet.h:90
Double_t fdzBarCol
depth of the bar
Definition TimeDet.h:105
double GetZBar(int ir, int ic) const
Definition TimeDet.cxx:320
virtual Bool_t ProcessHits(FairVolume *v=0)
Definition TimeDet.cxx:148
virtual ~TimeDet()
Definition TimeDet.cxx:112
virtual void EndOfEvent()
Definition TimeDet.cxx:207
TimeDet()
Definition TimeDet.cxx:39
TLorentzVector fPos
volume id
Definition TimeDet.h:89
virtual void Initialize()
Definition TimeDet.cxx:106
Double_t fLength
time
Definition TimeDet.h:92
Double_t fxOv
Number of bars.
Definition TimeDet.h:115
double GetYRow(int ir) const
Definition TimeDet.cxx:312
ClassImp(ecalContFact) ecalContFact