FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FairBoxGenerator.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 // ----- FairBoxGenerator source file -----
10 // ----- Created 09/09/04 by Yu.Kharlov
11 // -------------------------------------------------------------------------
12 
13 /* $Id: FairBoxGenerator.cxx,v 1.4 2006/07/18 09:28:06 prokudin Exp $ */
14 
15 /* History of cvs commits:
16  *
17  * $Log: FairBoxGenerator.cxx,v $
18  * Revision 1.4 2006/07/18 09:28:06 prokudin
19  * Should be * instead /
20  *
21  * Revision 1.3 2006/07/14 11:23:57 kharlov
22  * Add protection for simultaneously set ranges; split vertex and kinematics ranges
23  *
24  * Revision 1.2 2006/03/29 16:25:50 kharlov
25  * New functionality added
26  *
27  */
28 
29 #include "FairBoxGenerator.h"
30 
31 #include "FairLogger.h"
32 #include "FairPrimaryGenerator.h"
33 
34 #include <TDatabasePDG.h>
35 #include <TMath.h>
36 #include <TNamed.h>
37 #include <TParticlePDG.h>
38 #include <TRandom.h>
39 #include <cmath> // for cos, acos
40 #include <cstdio> // for printf
41 
44  , fPtMin(0)
45  , fPtMax(0)
46  , fPhiMin(0)
47  , fPhiMax(0)
48  , fEtaMin(0)
49  , fEtaMax(0)
50  , fYMin(0)
51  , fYMax(0)
52  , fPMin(0)
53  , fPMax(0)
54  , fThetaMin(0)
55  , fThetaMax(0)
56  , fEkinMin(0)
57  , fEkinMax(0)
58  , fEtaRangeIsSet(0)
59  , fYRangeIsSet(0)
60  , fThetaRangeIsSet(0)
61  , fCosThetaIsSet(0)
62  , fPtRangeIsSet(0)
63  , fPRangeIsSet(0)
64  , fEkinRangeIsSet(0)
65 {
66  // Default constructor
67 }
68 
69 FairBoxGenerator::FairBoxGenerator(Int_t pdgid, Int_t mult)
71  , fPtMin(0)
72  , fPtMax(0)
73  , fPhiMin(0)
74  , fPhiMax(0)
75  , fEtaMin(0)
76  , fEtaMax(0)
77  , fYMin(0)
78  , fYMax(0)
79  , fPMin(0)
80  , fPMax(0)
81  , fThetaMin(0)
82  , fThetaMax(0)
83  , fEkinMin(0)
84  , fEkinMax(0)
85  , fEtaRangeIsSet(0)
86  , fYRangeIsSet(0)
87  , fThetaRangeIsSet(0)
88  , fCosThetaIsSet(0)
89  , fPtRangeIsSet(0)
90  , fPRangeIsSet(0)
91  , fEkinRangeIsSet(0)
92 {
93  // Constructor. Set default kinematics limits
94  SetPDGType(pdgid);
95  SetMultiplicity(mult);
96  SetPhiRange();
97 }
98 
99 void FairBoxGenerator::SetXYZ(Double32_t x, Double32_t y, Double32_t z) { SetVertex(x, y, z, 0, 0, 0, kBox); }
100 
101 void FairBoxGenerator::SetBoxXYZ(Double32_t x1, Double32_t y1, Double32_t x2, Double32_t y2, Double32_t z)
102 {
103  Double_t X1 = TMath::Min(x1, x2);
104  Double_t X2 = TMath::Max(x1, x2);
105  Double_t Y1 = TMath::Min(y1, y2);
106  Double_t Y2 = TMath::Max(y1, y2);
107  Double_t dX = 0.5 * (X2 - X1);
108  Double_t dY = 0.5 * (Y2 - Y1);
109  Double_t x = 0.5 * (X1 + X2);
110  Double_t y = 0.5 * (Y1 + Y2);
111  SetVertex(x, y, z, dX, dY, 0, kBox);
112 }
113 
115 {
116  // Initialize parent generator
117  if (FairBaseMCGenerator::Init() == kFALSE)
118  return kFALSE;
119  // Check for particle type
120  TDatabasePDG* pdgBase = TDatabasePDG::Instance();
121  TParticlePDG* particle = pdgBase->GetParticle(GetPDGType());
122 
123  if (!particle) {
124  LOG(fatal) << "FairBoxGenerator: PDG " << GetPDGType() << " not defined";
125  }
126 
127  if (fPhiMax - fPhiMin > 360) {
128  LOG(fatal) << "FairBoxGenerator:Init(): phi range is too wide: " << fPhiMin << "<phi<" << fPhiMax;
129  }
130  if (fEkinRangeIsSet) {
131  if (fPRangeIsSet) {
132  LOG(fatal) << "FairBoxGenerator:Init(): Cannot set P and Ekin ranges simultaneously";
133  } else {
134  // Transform EkinRange to PRange, calculate momentum in GeV, p = √(K² + 2Kmc²)
135  fPMin = TMath::Sqrt(fEkinMin * fEkinMin + 2 * fEkinMin * GetPDGMass());
136  fPMax = TMath::Sqrt(fEkinMax * fEkinMax + 2 * fEkinMax * GetPDGMass());
137  fPRangeIsSet = kTRUE;
138  fEkinRangeIsSet = kFALSE;
139  }
140  }
141  if (fPRangeIsSet && fPtRangeIsSet) {
142  LOG(fatal) << "FairBoxGenerator:Init(): Cannot set P and Pt ranges simultaneously";
143  }
144  if (fPRangeIsSet && fYRangeIsSet) {
145  LOG(fatal) << "FairBoxGenerator:Init(): Cannot set P and Y ranges simultaneously";
146  }
147  if ((fThetaRangeIsSet && fYRangeIsSet) || (fThetaRangeIsSet && fEtaRangeIsSet)
148  || (fYRangeIsSet && fEtaRangeIsSet)) {
149  LOG(fatal) << "FairBoxGenerator:Init(): Cannot set Y, Theta or Eta ranges simultaneously";
150  }
151  return kTRUE;
152 }
153 
155 {
156  // Generate one event: produce primary particles emitted from one vertex.
157  // Primary particles are distributed uniformly along
158  // those kinematics variables which were limitted by setters.
159  // if SetCosTheta() function is used, the distribution will be uniform in
160  // cos(theta)
161 
162  Double32_t pabs = 0, phi, pt = 0, theta = 0, eta, y, mt, px, py, pz = 0;
164  // Generate particles
165  for (Int_t k = 0; k < GetMultiplicity(); k++) {
166  phi = gRandom->Uniform(fPhiMin, fPhiMax) * TMath::DegToRad();
167 
168  if (fPRangeIsSet) {
169  pabs = gRandom->Uniform(fPMin, fPMax);
170  } else if (fPtRangeIsSet) {
171  pt = gRandom->Uniform(fPtMin, fPtMax);
172  }
173 
174  if (fThetaRangeIsSet) {
175  if (fCosThetaIsSet)
176  theta = acos(gRandom->Uniform(cos(fThetaMin * TMath::DegToRad()), cos(fThetaMax * TMath::DegToRad())));
177  else {
178  theta = gRandom->Uniform(fThetaMin, fThetaMax) * TMath::DegToRad();
179  }
180  } else if (fEtaRangeIsSet) {
181  eta = gRandom->Uniform(fEtaMin, fEtaMax);
182  theta = 2 * TMath::ATan(TMath::Exp(-eta));
183  } else if (fYRangeIsSet) {
184  y = gRandom->Uniform(fYMin, fYMax);
185  mt = TMath::Sqrt(GetPDGMass() * GetPDGMass() + pt * pt);
186  pz = mt * TMath::SinH(y);
187  }
188 
189  if (fThetaRangeIsSet || fEtaRangeIsSet) {
190  if (fPRangeIsSet) {
191  pz = pabs * TMath::Cos(theta);
192  pt = pabs * TMath::Sin(theta);
193  } else if (fPtRangeIsSet) {
194  pz = pt / TMath::Tan(theta);
195  }
196  }
197 
198  px = pt * TMath::Cos(phi);
199  py = pt * TMath::Sin(phi);
200 
201  LOG(debug) << "FairBoxGen: " << Form("PDG %i p=(%.2f, %.2f, %.2f) GeV,", GetPDGType(), px, py, pz);
202  primGen->AddTrack(GetPDGType(), px, py, pz, fX, fY, fZ);
203  }
204  return kTRUE;
205 }
206 
208 {
209  // Clone for worker (used in MT mode only)
210 
211  return new FairBoxGenerator(*this);
212 }
213 
void SetMultiplicity(Int_t mult)
ClassImp(FairEventBuilder)
virtual Bool_t ReadEvent(FairPrimaryGenerator *primGen)
Int_t GetPDGType() const
void SetXYZ(Double32_t x=0, Double32_t y=0, Double32_t z=0)
virtual FairGenerator * CloneGenerator() const
void SetPDGType(Int_t pdg)
void SetBoxXYZ(Double32_t x1=0, Double32_t y1=0, Double32_t x2=0, Double32_t y2=0, Double32_t z=0)
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)
Double_t GetPDGMass() const
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)
Int_t GetMultiplicity() const
void SetPhiRange(Double32_t phimin=0, Double32_t phimax=360)