FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FairIonGenerator.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 // -------------------------------------------------------------------------
9 // ----- FairIonGenerator source file -----
10 // ----- Created 09/07/04 by V. Friese / D.Bertini -----
11 // -------------------------------------------------------------------------
12 #include "FairIonGenerator.h"
13 
14 #include "FairIon.h" // for FairIon
15 #include "FairLogger.h" // for logging
16 #include "FairParticle.h" // for FairParticle
17 #include "FairPrimaryGenerator.h" // for FairPrimaryGenerator
18 #include "FairRunSim.h" // for FairRunSim
19 
20 #include <TDatabasePDG.h> // for TDatabasePDG
21 #include <TObjArray.h> // for TObjArray
22 #include <TParticle.h> // for TParticle
23 #include <TParticlePDG.h> // for TParticlePDG
24 #include <cstdio> // for sprintf
25 
26 Int_t FairIonGenerator::fgNIon = 0;
27 
30  , fPx(0)
31  , fPy(0)
32  , fPz(0)
33  , fIon(nullptr)
34  , fQ(0)
35 {
36  // LOG(warn) << "FairIonGenerator: Please do not use the default constructor!";
37 }
38 
39 FairIonGenerator::FairIonGenerator(const Char_t* ionName,
40  Int_t mult,
41  Double_t px,
42  Double_t py,
43  Double_t pz,
44  Double_t vx,
45  Double_t vy,
46  Double_t vz)
48  , fPx(px)
49  , fPy(py)
50  , fPz(pz)
51  , fIon(nullptr)
52  , fQ(0)
53 {
54  SetVertex(vx, vy, vz);
55  SetMultiplicity(mult);
57  TObjArray* UserIons = fRun->GetUserDefIons();
58  TObjArray* UserParticles = fRun->GetUserDefParticles();
59  FairParticle* part = 0;
60  fIon = static_cast<FairIon*>(UserIons->FindObject(ionName));
61  if (fIon) {
62  fgNIon++;
63  fPx = Double_t(fIon->GetA()) * px;
64  fPy = Double_t(fIon->GetA()) * py;
65  fPz = Double_t(fIon->GetA()) * pz;
66  } else {
67  part = static_cast<FairParticle*>(UserParticles->FindObject(ionName));
68  if (part) {
69  fgNIon++;
70  TParticle* particle = part->GetParticle();
71  fPx = Double_t(particle->GetMass() / 0.92827231) * px;
72  fPy = Double_t(particle->GetMass() / 0.92827231) * py;
73  fPz = Double_t(particle->GetMass() / 0.92827231) * pz;
74  }
75  }
76  if (fIon == 0 && part == 0) {
77  LOG(fatal) << "Ion or Particle is not defined !";
78  }
79 }
80 
82  Int_t a,
83  Int_t q,
84  Int_t mult,
85  Double_t px,
86  Double_t py,
87  Double_t pz,
88  Double_t vx,
89  Double_t vy,
90  Double_t vz)
92  , fPx(Double_t(a) * px)
93  , fPy(Double_t(a) * py)
94  , fPz(Double_t(a) * pz)
95  , fIon(nullptr)
96  , fQ(0)
97 {
98  fgNIon++;
99  SetVertex(vx, vy, vz);
100  SetMultiplicity(mult);
101  /*
102  fMult = mult;
103  fPx = Double_t(a) * px;
104  fPy = Double_t(a) * py;
105  fPz = Double_t(a) * pz;
106  fVx = vx;
107  fVy = vy;
108  fVz = vz;
109  */
110  char buffer[20];
111  sprintf(buffer, "FairIon%d", fgNIon);
112  fIon = new FairIon(buffer, z, a, q);
114  if (!run) {
115  LOG(error) << "No FairRun instantised!";
116  } else {
117  run->AddNewIon(fIon);
118  }
119 }
120 
122  : FairBaseMCGenerator(rhs)
123  , fPx(rhs.fPx)
124  , fPy(rhs.fPy)
125  , fPz(rhs.fPz)
126  , fIon(rhs.fIon)
127  , // CHECK
128  fQ(0)
129 {
130  // fIon= new FairIon(buffer, z, a, q);
132  if (!run) {
133  LOG(error) << "No FairRun instantised!";
134  } else {
135  run->AddNewIon(fIon);
136  }
137 }
138 
140 {
141  // if (fIon) delete fIon;
142 }
143 
144 void FairIonGenerator::SetExcitationEnergy(Double_t eExc) { fIon->SetExcEnergy(eExc); }
145 
146 void FairIonGenerator::SetMass(Double_t mass) { fIon->SetMass(mass); }
147 
149 {
150  // if ( ! fIon ) {
151  // LOG(warn) << "FairIonGenerator: No ion defined! ";
152  // return kFALSE;
153  // }
155  TParticlePDG* thisPart = TDatabasePDG::Instance()->GetParticle(fIon->GetName());
156  if (!thisPart) {
157  LOG(warn) << "FairIonGenerator: Ion " << fIon->GetName() << " not found in database!";
158  return kFALSE;
159  }
160 
161  int pdgType = thisPart->PdgCode();
162 
163  for (Int_t i = 0; i < GetMultiplicity(); i++) {
164  LOG(debug) << "FairIonGenerator: Generating ion " << fIon->GetName()
165  << Form(" p=(%.2f, %.2f, %.2f) GeV,", fPx, fPy, fPz);
166  primGen->AddTrack(pdgType, fPx, fPy, fPz, fX, fY, fZ);
167  }
168 
169  return kTRUE;
170 }
171 
173 {
174  // Clone for worker (used in MT mode only)
175 
176  return new FairIonGenerator(*this);
177 }
178 
TParticle * GetParticle() const
Int_t GetA() const
Definition: FairIon.h:66
void SetMultiplicity(Int_t mult)
void SetMass(Double_t mass)
static FairRunSim * Instance()
Definition: FairRunSim.cxx:116
ClassImp(FairEventBuilder)
void SetExcitationEnergy(Double_t eExc)
TObjArray * GetUserDefIons()
Definition: FairRunSim.cxx:131
void SetMass(Double_t mass)
Definition: FairIon.h:92
virtual Bool_t ReadEvent(FairPrimaryGenerator *primGen)
void SetExcEnergy(Double_t eExc)
Definition: FairIon.h:84
virtual void AddTrack(Int_t pdgid, Double_t px, Double_t py, Double_t pz, Double_t vx, Double_t vy, Double_t vz, Int_t parent=-1, Bool_t wanttracking=true, Double_t e=-9e9, Double_t tof=0., Double_t weight=0., TMCProcess proc=kPPrimary)
virtual void GenerateEventParameters()
void SetVertex(Double_t vx, Double_t vy, Double_t vz, Double_t evx=0, Double_t evy=0, Double_t evz=0, eVertexSmear sm=kBox)
void AddNewIon(FairIon *ion)
Definition: FairRunSim.h:51
Int_t GetMultiplicity() const
TObjArray * GetUserDefParticles()
Definition: FairRunSim.cxx:137
virtual FairGenerator * CloneGenerator() const