er  dev
ERIonGenerator.cxx
1 /********************************************************************************
2  * Copyright (C) Joint Institute for Nuclear Research *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence version 3 (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
8 #include "ERIonGenerator.h"
9 
10 #include <iosfwd> // for ostream
11 #include "TDatabasePDG.h" // for TDatabasePDG
12 #include "TObjArray.h" // for TObjArray
13 #include "TParticle.h" // for TParticle
14 #include "TParticlePDG.h" // for TParticlePDG
15 #include "TRandom.h"
16 
17 #include "FairIon.h" // for FairIon
18 #include "FairParticle.h" // for FairParticle
19 #include "FairPrimaryGenerator.h" // for FairPrimaryGenerator
20 #include "FairRunSim.h" // for FairRunSim
21 #include "FairLogger.h" // for logging
22 #include "G4IonTable.hh"
23 //-------------------------------------------------------------------------------------------------
25  :FairGenerator(),
26  fMult(0),
27  fIon(NULL), fQ(0)
28 {
29 // LOG(WARNING) << "ERIonGenerator: "
30 // << " Please do not use the default constructor! "
31 // << FairLogger::endl;
32 }
33 //-------------------------------------------------------------------------------------------------
34 ERIonGenerator::ERIonGenerator(const Char_t* ionName, Int_t mult)
35  :FairGenerator(),
36  fMult(mult),
37  fIon(NULL), fQ(0)
38 
39 {
40  FairRunSim* fRun=FairRunSim::Instance();
41  TObjArray* UserIons=fRun->GetUserDefIons();
42  TObjArray* UserParticles=fRun->GetUserDefParticles();
43  FairParticle* part=0;
44  fIon =static_cast<FairIon*>(UserIons->FindObject(ionName));
45  if(fIon) {
46  fMult = mult;
47 
48  } else {
49  part= static_cast<FairParticle*>(UserParticles->FindObject(ionName));
50  if(part) {
51  TParticle* particle=part->GetParticle();
52  fMult = mult;
53  }
54  }
55  if(fIon==0 && part==0 ) {
56  LOG(FATAL) << "Ion or Particle is not defined !"
57  << FairLogger::endl;
58  }
59  SetPhiRange();
60 }
61 //-------------------------------------------------------------------------------------------------
62 ERIonGenerator::ERIonGenerator(TString name, Int_t z, Int_t a, Int_t q, Int_t mult)
63  :FairGenerator(),
64  fPDGType(-1),fMult(mult),fPtMin(0),fPtMax(0),
65  fPhiMin(0),fPhiMax(0),fEtaMin(0),fEtaMax(0),fYMin(0),fYMax(0),
66  fPMin(0),fPMax(0),fThetaMin(0),fThetaMax(0),fX(0),fY(0),fZ(0),
67  fX1(0),fY1(0),fX2(0),fY2(0),
68  fGausX(0), fGausY(0), fGausP(0),
69  fSigmaX(0), fSigmaY(0), fSigmaPIsSet(0),
70  fSigmaP(0),
73  fPointVtxIsSet(0),fBoxVtxIsSet(0),fIon(NULL), fName(name),
76  fKinE(0),
77  fRoundXYIsSet(0),
78  fRho(0), fCenterX(0), fCenterY(0)
79 {
80  SetPhiRange();
81  fIon= new FairIon(fName, z, a, q);
82  G4IonTable* fIonTable = G4IonTable::GetIonTable();
83  fIonMass = fIonTable->GetIonMass(z,a)/1000.;
84  FairRunSim* run = FairRunSim::Instance();
85  if ( ! run ) {
86  LOG(ERROR) << "No FairRunSim instantised!"
87  << FairLogger::endl;
88  } else {
89  run->AddNewIon(fIon);
90  }
91 }
92 //-------------------------------------------------------------------------------------------------
94 {
95 // if (fIon) delete fIon;
96 }
97 //-------------------------------------------------------------------------------------------------
99 {
100  fIon->SetExcEnergy(eExc);
101  fIonMass += eExc;
102 }
103 //-------------------------------------------------------------------------------------------------
104 void ERIonGenerator::SetKinERange(Double32_t kinEMin, Double32_t kinEMax)
105 {
106  fPMin = TMath::Sqrt(kinEMin*kinEMin + 2.*kinEMin*fIonMass);
107  fPMax = TMath::Sqrt(kinEMax*kinEMax + 2.*kinEMax*fIonMass);
108  fPRangeIsSet=kTRUE;
109 }
110 //-------------------------------------------------------------------------------------------------
111 void ERIonGenerator::SetKinESigma(Double32_t kinE, Double32_t sigmaKinE)
112 {
113  fGausP = TMath::Sqrt(kinE*kinE + 2.*kinE*fIonMass);
114  fSigmaP = sigmaKinE*(kinE + fIonMass) / TMath::Sqrt(kinE*kinE + 2.*kinE*fIonMass);
115  fSigmaPIsSet=kTRUE;
116 }
117 //-------------------------------------------------------------------------------------------------
118 void ERIonGenerator::SetKinE(Double32_t kinE)
119 {
120  fGausP = TMath::Sqrt(kinE*kinE + 2.*kinE*fIonMass);
121 }
122 //-------------------------------------------------------------------------------------------------
123 Bool_t ERIonGenerator::ReadEvent(FairPrimaryGenerator* primGen)
124 {
125  // Generate particles
126  for (Int_t k = 0; k < fMult; k++) {
128 
129  TParticlePDG* thisPart =
130  TDatabasePDG::Instance()->GetParticle(fIon->GetName());
131  if ( ! thisPart ) {
132  LOG(WARNING) << "ERIonGenerator: Ion " << fIon->GetName()
133  << " not found in database!" << FairLogger::endl;
134  return kFALSE;
135  }
136 
137  int pdgType = thisPart->PdgCode();
138 
139  LOG(DEBUG) << "ERIonGenerator: Generating " << fMult << " ions of type "
140  << fIon->GetName() << " (PDG code " << pdgType << ")"
141  << FairLogger::endl;
142  LOG(DEBUG) << " Momentum (" << fPx << ", " << fPy << ", " << fPz
143  << ") Gev from vertex (" << fX << ", " << fY
144  << ", " << fZ << ") cm" << FairLogger::endl;
145  primGen->AddTrack(pdgType, fPx, fPy, fPz, fX, fY, fZ);
146  }
147 
148  return kTRUE;
149 }
150 //-------------------------------------------------------------------------------------------------
152 {
153  Double32_t pabs=0, phi, pt=0, theta=0, eta, y, mt, kinE;
154 
155  fPz=0;
156 
157  phi = gRandom->Uniform(fPhiMin,fPhiMax) * TMath::DegToRad();
158 
159  if (fPRangeIsSet ) {
160  pabs = gRandom->Uniform(fPMin,fPMax);
161  }
162  else if (fPtRangeIsSet) {
163  pt = gRandom->Uniform(fPtMin,fPtMax);
164  }
165  if (fSigmaPIsSet) {
166  pabs = gRandom->Gaus(fGausP,fSigmaP);
167  fPRangeIsSet = kTRUE;
168  }
169  if(fSigmaThetaIsSet) {
170  theta = gRandom->Gaus(fGausTheta,fSigmaTheta) * TMath::DegToRad();
171  }
172  if (fThetaRangeIsSet) {
173  if (fCosThetaIsSet)
174  theta = acos(gRandom->Uniform(cos(fThetaMin* TMath::DegToRad()),
175  cos(fThetaMax* TMath::DegToRad())));
176  else {
177  theta = gRandom->Uniform(fThetaMin,fThetaMax) * TMath::DegToRad();
178  }
179  } else if (fEtaRangeIsSet) {
180  eta = gRandom->Uniform(fEtaMin,fEtaMax);
181  theta = 2*TMath::ATan(TMath::Exp(-eta));
182  } else if (fYRangeIsSet) {
183  y = gRandom->Uniform(fYMin,fYMax);
184  mt = TMath::Sqrt(fIonMass*fIonMass + pt*pt);
185  fPz = mt * TMath::SinH(y);
186  }
187 
189  if (fPRangeIsSet ) {
190  fPz = pabs*TMath::Cos(theta);
191  pt = pabs*TMath::Sin(theta);
192  } else if (fPtRangeIsSet) {
193  fPz = pt/TMath::Tan(theta);
194  }
195  }
196 
197  fPx = pt*TMath::Cos(phi);
198  fPy = pt*TMath::Sin(phi);
199 
200  if (fBoxVtxIsSet) {
201  fX = gRandom->Uniform(fX1,fX2);
202  fY = gRandom->Uniform(fY1,fY2);
203  }
204  if (fRoundXYIsSet) {
205  Bool_t isInCircle = kFALSE;
206  while (!isInCircle) {
207  fX = gRandom->Uniform(0, fRho);
208  fY = gRandom->Uniform(0, fRho);
209  if (sqrt(pow(fX, 2) + pow(fY, 2)) <= fRho) {
210  isInCircle = kTRUE;
211  }
212  }
213  fX += fCenterX;
214  fY += fCenterY;
215  }
216  if (fBoxSigmaIsSet) {
217  fX = gRandom->Gaus(fGausX,fSigmaX);
218  fY = gRandom->Gaus(fGausY,fSigmaY);
219  }
220  if(fSpreadingOnTarget) {
221  // Recontruction of beam start position
222  LOG(DEBUG) << "Coord on target x = " << fX << "; y = " << fY
223  << "; theta = " << theta << FairLogger::endl;
224  Double_t l = fZ / TMath::Cos(theta);
225  fX = l * TMath::Sin(theta) * TMath::Cos(phi) + fX;
226  fY = l * TMath::Sin(theta) * TMath::Sin(phi) + fY;
227  LOG(DEBUG) << "Coord on start x = " << fX << "; y = " << fY
228  << "; theta = " << theta << FairLogger::endl;
229  }
230 }
231 //-------------------------------------------------------------------------------------------------
232 ClassImp(ERIonGenerator)
Bool_t fRoundXYIsSet
True if spot spreading of the start position in XY-plane is setted.
Double32_t fPhiMax
Azimuth angle range [degree].
Double32_t fGausTheta
Amplitude value of theta angle in Gauss distibution [degree].
Bool_t fPtRangeIsSet
True if transverse momentum range is set.
Double32_t fGausP
Amplitude value of momentum in Gauss distibution [GeV].
Double32_t fYMax
Rapidity range in lab system.
Bool_t fYRangeIsSet
True if rapidity range is set.
Double32_t fThetaMax
Polar angle range in lab system [degree].
void SetKinERange(Double32_t kinEMin, Double32_t kinEMax)
Defines uniform distribution boundaries of ion kinetic energy [GeV].
Bool_t fEtaRangeIsSet
True if eta range is set.
void SetKinESigma(Double32_t kinE, Double32_t sigmaKinE)
Defines Gaussian distribution of ion kinetic energy [GeV].
Int_t fMult
Multiplicity per event.
Double32_t fGausY
Amplitude values of coordinates in Gauss distibution [cm].
void SetKinE(Double32_t kinE)
Defines fixed ion kinetic energy that is recalculated to the momentum according to equation ...
Double32_t fZ
Point vertex coordinates [cm].
Bool_t fPRangeIsSet
True if abs momentum range is set.
Bool_t fThetaRangeIsSet
True if theta range is set.
Double32_t fIonMass
Ion mass + Ion Exitation [GeV].
Bool_t fSigmaThetaIsSet
True if Gauss distribution for theta angle is set.
Int_t fPDGType
Particle type (PDG encoding)
Double32_t fKinE
Kinetic energy [GeV].
Double32_t fSigmaY
Coordinates normal deviation [cm].
Bool_t fSpreadingOnTarget
True if parameters are spreaded on target and reconstructed to beam start position.
virtual ~ERIonGenerator()
Destructor.
Double32_t fSigmaTheta
Theta angle normal deviation [degree].
Bool_t fPointVtxIsSet
True if point vertex is set.
Double32_t fPtMax
Transverse momentum range [GeV].
void SetExcitationEnergy(Double_t eExc)
Defines ion excitation energy of generated FairIon object.
TString fName
Ion name.
FairIon * fIon
Pointer to the FairIon to be generated.
void SpreadingParameters(void)
Spreads parameters recieved by accessor methods.
Int_t fQ
Electric charge [e].
Bool_t fBoxSigmaIsSet
True if Gauss distribution for coordinates is set.
Bool_t fCosThetaIsSet
True if uniform distribution in cos(theta) is set (default -> not set)
Bool_t fBoxVtxIsSet
True if box vertex is set.
Double32_t fPz
Momentum projection [GeV].
Double32_t fPMax
Momentum range in lab system.
void SetPhiRange(Double32_t phimin=0, Double32_t phimax=360)
Defines uniform distribution boundaries of ion azimuth angle[degree].
ERIonGenerator()
Default constructor.
Double32_t fY2
Box vertex coords (x1,y1)->(x2,y2)
virtual Bool_t ReadEvent(FairPrimaryGenerator *primGen)
Double32_t fSigmaP
Momentum normal deviation [GeV].
Double32_t fEtaMax
Pseudorapidity range in lab system.
Class for the generation ion.
Bool_t fSigmaPIsSet
True if Gauss distribution for momentum is set.