ATTPCROOT  0.3.0-alpha
A ROOT-based framework for analyzing data from active target detectors
AtTPCIonGenerator.cxx
Go to the documentation of this file.
1 // -------------------------------------------------------------------------
2 // ----- Based on FairIonGenerator source file -----
3 // ----- Created 30/01/15 by Y. Ayyad -----
4 // -------------------------------------------------------------------------
5 #include "AtTPCIonGenerator.h"
6 
7 #include "AtVertexPropagator.h"
8 
9 #include <FairIon.h>
10 #include <FairParticle.h>
11 #include <FairPrimaryGenerator.h>
12 #include <FairRunSim.h>
13 
14 #include <TDatabasePDG.h>
15 #include <TMath.h>
16 #include <TObjArray.h>
17 #include <TObject.h> // for TObject
18 #include <TParticle.h>
19 #include <TParticlePDG.h>
20 #include <TRandom.h>
21 #include <TString.h>
22 
23 #include <cmath>
24 #include <iostream>
25 #include <limits> // for numeric_limits
26 
27 constexpr auto cRED = "\033[1;31m";
28 constexpr auto cYELLOW = "\033[1;33m";
29 constexpr auto cNORMAL = "\033[0m";
30 constexpr auto cGREEN = "\033[1;32m";
31 constexpr auto cBLUE = "\033[1;34m";
32 
33 using std::cout;
34 using std::endl;
35 
36 // ----- Initialsisation of static variables --------------------------
38 // ------------------------------------------------------------------------
39 
40 // ----- Default constructor ------------------------------------------
42  : fMult(0), fPx(0.), fPy(0.), fPz(0.), fR(0.), fz(0.), fOffsetX(0.), fOffsetY(0.), fVx(0.), fVy(0.), fVz(0.),
43  fIon(nullptr), fQ(0)
44 
45 {
46  // cout << "-W- AtTPCIonGenerator: "
47  // << " Please do not use the default constructor! " << endl;
48 }
49 // ------------------------------------------------------------------------
50 
51 AtTPCIonGenerator::AtTPCIonGenerator(const Char_t *ionName, Int_t mult, Double_t px, Double_t py, Double_t pz)
52  : fMult(0), fPx(0.), fPy(0.), fPz(0.), fR(0.), fz(0.), fOffsetX(0.), fOffsetY(0.), fVx(0.), fVy(0.), fVz(0.),
53  fIon(nullptr), fQ(0)
54 {
55 
56  FairRunSim *fRun = FairRunSim::Instance();
57  TObjArray *UserIons = fRun->GetUserDefIons();
58  TObjArray *UserParticles = fRun->GetUserDefParticles();
59  FairParticle *part = nullptr;
60  fIon = dynamic_cast<FairIon *>(UserIons->FindObject(ionName)); // NOLINT
61 
62  if (fIon) {
63  fgNIon++;
64  fMult = mult;
65  fPx = Double_t(fIon->GetA()) * px;
66  fPy = Double_t(fIon->GetA()) * py;
67  fPz = Double_t(fIon->GetA()) * pz;
68  // fVx = vx;
69  // fVy = vy;
70  // fVz = vz;
71  // }
72 
73  } else {
74  part = dynamic_cast<FairParticle *>(UserParticles->FindObject(ionName));
75  if (part) {
76  fgNIon++;
77  TParticle *particle = part->GetParticle();
78  fMult = mult;
79  fPx = Double_t(particle->GetMass() / 0.92827231) * px;
80  fPy = Double_t(particle->GetMass() / 0.92827231) * py;
81  fPz = Double_t(particle->GetMass() / 0.92827231) * pz;
82  // fVx = vx;
83  // fVy = vy;
84  // fVz = vz;
85  }
86  }
87  if (fIon == nullptr && part == nullptr) {
88  cout << "-E- AtTPCIonGenerator: Ion or Particle is not defined !" << endl;
89  Fatal("AtTPCIonGenerator", "No FairRun instantised!");
90  }
91 }
92 
93 AtTPCIonGenerator::AtTPCIonGenerator(const char *name, Int_t z, Int_t a, Int_t q, Int_t mult, Double_t px, Double_t py,
94  Double_t pz, Double_t Ex, Double_t m, Double_t ener, Double_t eLoss)
95  : fMult(mult), fPx(Double_t(a) * px), fPy(Double_t(a) * py), fPz(Double_t(a) * pz), fR(0.), fz(0.), fOffsetX(0.),
96  fOffsetY(0.), fVx(0.), fVy(0.), fVz(0.), fIon(nullptr), fQ(0), fNomEner(ener), fMaxEnLoss(eLoss < 0 ? ener : eLoss)
97 {
98  fgNIon++;
99 
100  fIon = new FairIon(TString::Format("FairIon%d", fgNIon).Data(), z, a, q, Ex, m); // NOLINT
101  cout << " Beam Ion mass : " << fIon->GetMass() << endl;
104  FairRunSim *run = FairRunSim::Instance();
105  if (!run) {
106  cout << "-E- FairIonGenerator: No FairRun instantised!" << endl;
107  Fatal("FairIonGenerator", "No FairRun instantised!");
108  return;
109  }
110  run->AddNewIon(fIon);
111 }
112 
114 {
115  fIon->SetExcEnergy(eExc);
116 }
117 void AtTPCIonGenerator::SetMass(Double_t mass)
118 {
119  fIon->SetMass(mass);
120 }
121 void AtTPCIonGenerator::SetSpotRadius(Double32_t r, Double32_t z, Double32_t offx, Double_t offy)
122 {
123  fR = r;
124  fz = z;
125  fOffsetX = offx;
126  fOffsetY = offy;
127 }
128 
130 {
131  auto Phi = gRandom->Uniform(0, 360) * TMath::DegToRad();
132  auto SpotR = gRandom->Uniform(0, fR);
133 
134  fVx = fOffsetX + SpotR * cos(Phi); // gRandom->Uniform(-fx,fx);
135  fVy = fOffsetY + SpotR * sin(Phi); // gRandom->Uniform(-fy,fy);
136  fVz = fz;
137 }
138 
139 Bool_t AtTPCIonGenerator::ReadEvent(FairPrimaryGenerator *primGen)
140 {
141 
142  // if ( ! fIon ) {
143  // cout << "-W- FairIonGenerator: No ion defined! " << endl;
144  // return kFALSE;
145  // }
146 
147  TParticlePDG *thisPart = TDatabasePDG::Instance()->GetParticle(fIon->GetName());
148  if (!thisPart) {
149  cout << "-W- FairIonGenerator: Ion " << fIon->GetName() << " not found in database!" << endl;
150  return kFALSE;
151  }
152 
153  int pdgType = thisPart->PdgCode();
155 
157 
158  if (AtVertexPropagator::Instance()->GetBeamEvtCnt() % 2 != 0) {
159  if (fDoReact) {
160  Double_t Er = gRandom->Uniform(0., fMaxEnLoss);
162  // std::cout << cGREEN << " Random Energy AtTPCIonGenerator : " << Er << cNORMAL << std::endl;
163  } else
164  AtVertexPropagator::Instance()->SetRndELoss(std::numeric_limits<double>::max());
165  }
166 
167  // We only want to add a beam track if it is a beam event or it is a reaction event and we are not doing a reaction
168  if (AtVertexPropagator::Instance()->GetBeamEvtCnt() % 2 != 0 ||
169  (AtVertexPropagator::Instance()->GetBeamEvtCnt() % 2 == 0 && !fDoReact))
170  for (Int_t i = 0; i < fMult; i++)
171  primGen->AddTrack(pdgType, fPx, fPy, fPz, fVx, fVy, fVz);
172 
173  return kTRUE;
174 }
175 
176 //_____________________________________________________________________________
177 
AtTPCIonGenerator::fgNIon
static Int_t fgNIon
Definition: AtTPCIonGenerator.h:24
AtTPCIonGenerator::fR
Double32_t fR
Definition: AtTPCIonGenerator.h:28
cYELLOW
constexpr auto cYELLOW
Definition: AtTPCIonGenerator.cxx:28
AtTPCIonGenerator::fPx
Double_t fPx
Definition: AtTPCIonGenerator.h:26
ClassImp
ClassImp(AtFindVertex)
AtTPCIonGenerator::SetMass
void SetMass(Double_t mass)
Definition: AtTPCIonGenerator.cxx:117
AtTPCIonGenerator::fMult
Int_t fMult
Number of the instance of this class.
Definition: AtTPCIonGenerator.h:25
AtTPCIonGenerator::fMaxEnLoss
Double_t fMaxEnLoss
Definition: AtTPCIonGenerator.h:34
cNORMAL
constexpr auto cNORMAL
Definition: AtTPCIonGenerator.cxx:29
AtTPCIonGenerator::fPz
Double_t fPz
Definition: AtTPCIonGenerator.h:26
AtTPCIonGenerator::SetSpotRadius
void SetSpotRadius(Double32_t r=0, Double32_t z=0, Double32_t offx=0, Double32_t offy=0)
Definition: AtTPCIonGenerator.cxx:121
cBLUE
constexpr auto cBLUE
Definition: AtTPCIonGenerator.cxx:31
AtTPCIonGenerator::fOffsetX
Double32_t fOffsetX
Definition: AtTPCIonGenerator.h:28
AtTPCIonGenerator::ReadEvent
virtual Bool_t ReadEvent(FairPrimaryGenerator *primGen)
Definition: AtTPCIonGenerator.cxx:139
AtTPCIonGenerator::fVz
Double_t fVz
Definition: AtTPCIonGenerator.h:29
AtTPCIonGenerator::fOffsetY
Double32_t fOffsetY
Definition: AtTPCIonGenerator.h:28
AtVertexPropagator.h
AtTPCIonGenerator::fIon
FairIon * fIon
Definition: AtTPCIonGenerator.h:31
AtTPCIonGenerator::SetExcitationEnergy
void SetExcitationEnergy(Double_t eExc)
Definition: AtTPCIonGenerator.cxx:113
AtVertexPropagator::SetBeamMass
void SetBeamMass(Double_t m)
Definition: AtVertexPropagator.cxx:87
cRED
constexpr auto cRED
Definition: AtTPCIonGenerator.cxx:27
AtTPCIonGenerator::fPy
Double_t fPy
Definition: AtTPCIonGenerator.h:26
AtTPCIonGenerator::fVx
Double_t fVx
Definition: AtTPCIonGenerator.h:29
AtTPCIonGenerator::fz
Double32_t fz
Definition: AtTPCIonGenerator.h:28
AtTPCIonGenerator
Definition: AtTPCIonGenerator.h:22
AtVertexPropagator::SetBeamNomE
void SetBeamNomE(Double_t ener)
Definition: AtVertexPropagator.cxx:60
AtTPCIonGenerator::fVy
Double_t fVy
Definition: AtTPCIonGenerator.h:29
AtVertexPropagator::Instance
static AtVertexPropagator * Instance()
Definition: AtVertexPropagator.cxx:18
AtTPCIonGenerator::SetVertexCoordinates
virtual void SetVertexCoordinates()
Sets fVx, fVy, fVz depending on the type of ion generator.
Definition: AtTPCIonGenerator.cxx:129
AtTPCIonGenerator::AtTPCIonGenerator
AtTPCIonGenerator()
Definition: AtTPCIonGenerator.cxx:41
AtVertexPropagator::SetRndELoss
void SetRndELoss(Double_t eloss)
Definition: AtVertexPropagator.cxx:55
AtVertexPropagator::IncBeamEvtCnt
void IncBeamEvtCnt()
Definition: AtVertexPropagator.cxx:317
AtTPCIonGenerator.h
cGREEN
constexpr auto cGREEN
Definition: AtTPCIonGenerator.cxx:30
AtTPCIonGenerator::fDoReact
Bool_t fDoReact
Definition: AtTPCIonGenerator.h:36