FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FairFastSimExample.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 "FairFastSimExample.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 <TMCProcess.h> // for kPHadronic
22 #include <TVirtualMC.h> // for TVirtualMC
23 #include <TVirtualMCStack.h> // for TVirtualMCStack
24 
26  : FairFastSimDetector("TutorialDet", kTutDet)
27  , fTrackID(-1)
28  , fVolumeID(-1)
29  , fPos()
30  , fMom()
31  , fTime(-1.)
32  , fLength(-1.)
33  , fELoss(-1)
34  , fPointsArray(new TClonesArray("FairTutorialDet1Point"))
35 {}
36 
39  , fTrackID(-1)
40  , fVolumeID(-1)
41  , fPos()
42  , fMom()
43  , fTime(-1.)
44  , fLength(-1.)
45  , fELoss(-1)
46  , fPointsArray(new TClonesArray("FairTutorialDet1Point"))
47 {}
48 
50  : FairFastSimDetector(rhs)
51  , fTrackID(-1)
52  , fVolumeID(-1)
53  , fPos()
54  , fMom()
55  , fTime(-1.)
56  , fLength(-1.)
57  , fELoss(-1)
58  , fPointsArray(new TClonesArray("FairTutorialDet1Point"))
59 {}
60 
62 {
63  if (fPointsArray) {
64  fPointsArray->Delete();
65  delete fPointsArray;
66  }
67 }
68 
70 
72 {
73  TVirtualMC::GetMC()->TrackPosition(fPos);
74  TVirtualMC::GetMC()->TrackMomentum(fMom);
75 
76  FairStack* stack = static_cast<FairStack*>(TVirtualMC::GetMC()->GetStack());
77  fTrackID = TVirtualMC::GetMC()->GetStack()->GetCurrentTrackNumber();
78 
79  if (TVirtualMC::GetMC()->TrackPid() == 211) { // let only pion create secondaries
80  stack->FastSimPushSecondary(
81  fTrackID, 11, -12.5, -12.5, 20. + 5. + 0.1, fPos.T(), 0.1, 0.1, 1.0, 1.0, 0., 0., 0., kPHadronic, 1, 0);
82  stack->FastSimPushSecondary(
83  fTrackID, 11, -12.5, -12.5, 20. + 5. + 0.1, fPos.T(), -0.1, -0.1, 1.0, 1.0, 0., 0., 0., kPHadronic, 1, 0);
84  }
85  stack->FastSimMoveParticleTo(
86  12.5, 12.5, 20. + 5. + 0.1, TVirtualMC::GetMC()->TrackTime(), fMom.X(), fMom.Y(), fMom.Z(), 0.99 * fMom.E());
87 
88  if (TVirtualMC::GetMC()->TrackPid() == 211) { // let only pion create secondaries
89  stack->FastSimPushSecondary(
90  fTrackID, 11, -12.5, -12.5, 20. + 5. + 0.1, fPos.T(), -0.1, 0.1, 1.0, 1.0, 0., 0., 0., kPHadronic, 1, 0);
91  stack->FastSimPushSecondary(
92  fTrackID, 11, -12.5, -12.5, 20. + 5. + 0.1, fPos.T(), 0.1, -0.1, 1.0, 1.0, 0., 0., 0., kPHadronic, 1, 0);
93  }
94 
95  // stack->FastSimMoveParticleTo(
96  // 25., 25., 20. + 0.1, TVirtualMC::GetMC()->TrackTime(), fMom.X(), fMom.Y(), fMom.Z(), fMom.E());
97 
98  // stack->FastSimMoveParticleTo(
99  // 24., 24., 50. + 0.1, TVirtualMC::GetMC()->TrackTime(), fMom.X(), fMom.Y(), fMom.Z(), fMom.E());
100 
101  fVolumeID = 0;
102  fTime = TVirtualMC::GetMC()->TrackTime() * 1.0e09;
103  fLength = TVirtualMC::GetMC()->TrackLength();
104  fELoss = 0.;
105 
106  AddHit(fTrackID,
107  fVolumeID,
108  TVector3(fPos.X(), fPos.Y(), fPos.Z()),
109  TVector3(fMom.Px(), fMom.Py(), fMom.Pz()),
110  fTime,
111  fLength,
112  fELoss);
113 
114  // Increment number of tutorial det points in TParticle
115  stack->AddPoint(kTutDet);
116 }
117 
118 void FairFastSimExample::EndOfEvent() { fPointsArray->Clear(); }
119 
121 {
127  FairRootManager::Instance()->Register("FastSimPoint", "FastSimDetDet", fPointsArray, kTRUE);
128 }
129 
130 TClonesArray* FairFastSimExample::GetCollection(Int_t iColl) const
131 {
132  if (iColl == 0) {
133  return fPointsArray;
134  } else {
135  return nullptr;
136  }
137 }
138 
139 void FairFastSimExample::Reset() { fPointsArray->Clear(); }
140 
142 {
144 
145  TGeoVolume* cave = gGeoManager->GetTopVolume();
146 
147  Double_t dx = 25.;
148  Double_t dy = 25.;
149  Double_t dz = 5.;
150  TGeoBBox* bbox = new TGeoBBox("bbox", dx, dy, dz);
151  TGeoVolume* vol = new TGeoVolume("fast_sim_vol", bbox, fFastSimMedium);
152 
153  Double_t x = 0.;
154  Double_t y = 0.;
155  Double_t z = 20.;
156  TGeoRotation* rot = new TGeoRotation();
157  TGeoCombiTrans* matr = new TGeoCombiTrans(x, y, z, rot);
158 
159  cave->AddNode(vol, 1, matr);
160 
161  AddSensitiveVolume(vol);
162 }
163 
165  Int_t detID,
166  TVector3 pos,
167  TVector3 mom,
168  Double_t time,
169  Double_t length,
170  Double_t eLoss)
171 {
172  TClonesArray& clref = *fPointsArray;
173  Int_t size = clref.GetEntriesFast();
174  return new (clref[size]) FairTutorialDet1Point(trackID, detID, pos, mom, time, length, eLoss);
175 }
176 
177 Bool_t FairFastSimExample::IsSensitive(const std::string& name) { return name == "fast_sim_vol"; }
178 
180 
void AddSensitiveVolume(TGeoVolume *v)
Definition: FairModule.cxx:294
virtual void FastSimProcessParticle()
virtual void FastSimPushSecondary(Int_t parentID, Int_t pdgCode, Double_t xx, Double_t yy, Double_t zz, Double_t tt, Double_t px, Double_t py, Double_t pz, Double_t en, Double_t polx, Double_t poly, Double_t polz, TMCProcess proc, Double_t weight, Int_t is)
static FairRootManager * Instance()
ClassImp(FairEventBuilder)
virtual void Initialize()
virtual Bool_t IsSensitive(const std::string &name)
virtual TClonesArray * GetCollection(Int_t iColl) const
virtual void ConstructGeometry()
FairTutorialDet1Point * AddHit(Int_t trackID, Int_t detID, TVector3 pos, TVector3 mom, Double_t time, Double_t length, Double_t eLoss)
void Register(const char *name, const char *Foldername, TNamed *obj, Bool_t toFile)
void AddPoint(DetectorId iDet)
Definition: FairStack.cxx:344
virtual FairModule * CloneModule() const
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 void Initialize()