FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FairFastSimExample2.cxx
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
8 #include "FairFastSimExample2.h"
9 
10 #include "FairDetector.h" // for FairDetector
11 #include "FairDetectorList.h" // for DetectorId::kTutDet
12 #include "FairRootManager.h" // for FairRootManager
13 #include "FairStack.h" // for FairStack
14 #include "FairTutorialDet1Point.h" // for FairTutorialDet1Point
15 
16 #include <TClonesArray.h> // for TClonesArray
17 #include <TGeoBBox.h>
18 #include <TGeoManager.h>
19 #include <TGeoMatrix.h> // for TGeoCombiTrans, TGeoRotation
20 #include <TGeoVolume.h> // for TGeoVolume
21 #include <TVirtualMC.h> // for TVirtualMC
22 #include <TVirtualMCStack.h> // for TVirtualMCStack
23 
25  : FairFastSimDetector("TutorialDet", kTutDet)
26  , fTrackID(-1)
27  , fVolumeID(-1)
28  , fPos()
29  , fMom()
30  , fTime(-1.)
31  , fLength(-1.)
32  , fELoss(-1)
33  , fPointsArray(new TClonesArray("FairTutorialDet1Point"))
34 {}
35 
38  , fTrackID(-1)
39  , fVolumeID(-1)
40  , fPos()
41  , fMom()
42  , fTime(-1.)
43  , fLength(-1.)
44  , fELoss(-1)
45  , fPointsArray(new TClonesArray("FairTutorialDet1Point"))
46 {}
47 
49  : FairFastSimDetector(rhs)
50  , fTrackID(-1)
51  , fVolumeID(-1)
52  , fPos()
53  , fMom()
54  , fTime(-1.)
55  , fLength(-1.)
56  , fELoss(-1)
57  , fPointsArray(new TClonesArray("FairTutorialDet1Point"))
58 {}
59 
61 {
62  if (fPointsArray) {
63  fPointsArray->Delete();
64  delete fPointsArray;
65  }
66 }
67 
69 
71 {
72  TVirtualMC::GetMC()->TrackPosition(fPos);
73  TVirtualMC::GetMC()->TrackMomentum(fMom);
74 
75  FairStack* stack = static_cast<FairStack*>(TVirtualMC::GetMC()->GetStack());
76 
77  stack->FastSimMoveParticleTo(
78  24., 24., 50. + 5. + 0.1, TVirtualMC::GetMC()->TrackTime(), fMom.X(), fMom.Y(), fMom.Z(), 0.99 * fMom.E());
79 
80  fTrackID = TVirtualMC::GetMC()->GetStack()->GetCurrentTrackNumber();
81  fVolumeID = 0;
82  fTime = TVirtualMC::GetMC()->TrackTime() * 1.0e09;
83  fLength = TVirtualMC::GetMC()->TrackLength();
84  fELoss = 0.;
85 
86  AddHit(fTrackID,
87  fVolumeID,
88  TVector3(fPos.X(), fPos.Y(), fPos.Z()),
89  TVector3(fMom.Px(), fMom.Py(), fMom.Pz()),
90  fTime,
91  fLength,
92  fELoss);
93 
94  // Increment number of tutorial det points in TParticle
95  stack->AddPoint(kTutDet);
96 }
97 
98 void FairFastSimExample2::EndOfEvent() { fPointsArray->Clear(); }
99 
101 {
107  FairRootManager::Instance()->Register("FastSimPoint2", "FastSimDetDet", fPointsArray, kTRUE);
108 }
109 
110 TClonesArray* FairFastSimExample2::GetCollection(Int_t iColl) const
111 {
112  if (iColl == 0) {
113  return fPointsArray;
114  } else {
115  return nullptr;
116  }
117 }
118 
119 void FairFastSimExample2::Reset() { fPointsArray->Clear(); }
120 
122 {
124 
125  TGeoVolume* cave = gGeoManager->GetTopVolume();
126 
127  Double_t dx = 25.;
128  Double_t dy = 25.;
129  Double_t dz = 5.;
130  TGeoBBox* bbox = new TGeoBBox("bbox_2", dx, dy, dz);
131  TGeoVolume* vol = new TGeoVolume("fast_sim_vol_n2", bbox, fFastSimMedium);
132 
133  Double_t x = 0.;
134  Double_t y = 0.;
135  Double_t z = 50.;
136  TGeoRotation* rot = new TGeoRotation();
137  TGeoCombiTrans* matr = new TGeoCombiTrans(x, y, z, rot);
138 
139  cave->AddNode(vol, 1, matr);
140 
141  AddSensitiveVolume(vol);
142 }
143 
145  Int_t detID,
146  TVector3 pos,
147  TVector3 mom,
148  Double_t time,
149  Double_t length,
150  Double_t eLoss)
151 {
152  TClonesArray& clref = *fPointsArray;
153  Int_t size = clref.GetEntriesFast();
154  return new (clref[size]) FairTutorialDet1Point(trackID, detID, pos, mom, time, length, eLoss);
155 }
156 
157 Bool_t FairFastSimExample2::IsSensitive(const std::string& name) { return name == "fast_sim_vol_n2"; }
158 
160 
void AddSensitiveVolume(TGeoVolume *v)
Definition: FairModule.cxx:294
virtual void FastSimProcessParticle()
virtual FairModule * CloneModule() const
FairTutorialDet1Point * AddHit(Int_t trackID, Int_t detID, TVector3 pos, TVector3 mom, Double_t time, Double_t length, Double_t eLoss)
static FairRootManager * Instance()
ClassImp(FairEventBuilder)
virtual void Initialize()
virtual void ConstructGeometry()
virtual TClonesArray * GetCollection(Int_t iColl) const
void Register(const char *name, const char *Foldername, TNamed *obj, Bool_t toFile)
void AddPoint(DetectorId iDet)
Definition: FairStack.cxx:344
virtual void FastSimMoveParticleTo(Double_t xx, Double_t yy, Double_t zz, Double_t tt, Double_t px, Double_t py, Double_t pz, Double_t en)
virtual Bool_t IsSensitive(const std::string &name)