FairRoot/PandaRoot
PndVolGenerator.cxx
Go to the documentation of this file.
1 // -------------------------------------------------------------------------
2 // ----- PndVolGenerator source file -----
3 // ----- Created 22/05/07 by S.Spataro -----
4 // -------------------------------------------------------------------------
5 
6 
7 #include "TRandom.h"
8 #include "TMath.h"
9 #include "PndVolGenerator.h"
10 #include "FairPrimaryGenerator.h"
11 #include "TParticlePDG.h"
12 #include "TDatabasePDG.h"
13 
14 #include "FairVolume.h"
15 #include "FairGeoLoader.h"
16 #include "FairGeoInterface.h"
17 #include "FairGeoMedia.h"
18 #include "FairGeoMedium.h"
19 #include "TGeoVolume.h"
20 //#include "TGeoVolumeAssembly.h"
21 #include "TGeoMatrix.h"
22 #include "TGeoManager.h"
23 
24 // ------------------------------------------------------------------------
26  fPDGType(0),fMult(0),fPDGMass(0),fPtMin(0),fPtMax(0),
27  fPhiMin(0),fPhiMax(0),fEtaMin(0),fEtaMax(0),fYMin(0),fYMax(0),
28  fPMin(0),fPMax(0),fThetaMin(0),fThetaMax(0),fX(0),fY(0),fZ(0),
29  fX1(0),fY1(0),fX2(0),fY2(0),
30  fEtaRangeIsSet(0),fYRangeIsSet(0),fThetaRangeIsSet(0),
31  fCosThetaIsSet(0),fPtRangeIsSet(0),fPRangeIsSet(0),fInversePIsSet(0),
32  fAbs(0),fQuad(0),fFunc(0),fExt(0)
33 {
34  //fGeoH = PndGeoHandling::Instance();
35  // Default constructor
36 }
37 
38 // ------------------------------------------------------------------------
40  fPDGType(pdgid),fMult(mult),fPDGMass(0),
41  fEtaMin(0),fEtaMax(0),fYMin(0),fYMax(0),
42  fPMin(0),fPMax(0),fX(0),fY(0),fZ(0),
43  fX1(0),fY1(0),fX2(0),fY2(0),
44  fEtaRangeIsSet(0),fYRangeIsSet(0),fThetaRangeIsSet(0),
45  fCosThetaIsSet(0),fPtRangeIsSet(0),fPRangeIsSet(0),fInversePIsSet(0),
46  fAbs(0),fQuad(0),fFunc(0),fExt(0)
47 
48 {
49  // Constructor. Set default kinematics limits
50  SetPhiRange ();
51 }
52 // ------------------------------------------------------------------------
54 {
55  // Initialize generator
56 
57  if (fPhiMax-fPhiMin>360)
58  Fatal("Init()","PndVolGenerator: phi range is too wide: %f<phi<%f",
61  Fatal("Init()","PndVolGenerator: Cannot set P and Pt ranges simultaneously");
63  Fatal("Init()","PndVolGenerator: Cannot set P and Y ranges simultaneously");
64  if ( (fThetaRangeIsSet && fYRangeIsSet) ||
67  Fatal("Init()","PndVolGenerator: Cannot set Y, Theta or Eta ranges simultaneously");
69  Fatal("Init()","PndVolGenerator: Cannot set point and box vertices simultaneously");
70  if (fInversePIsSet && ( ( fPRangeIsSet && ( fPMin==0 || fPMax==0 ) ) || ( fPRangeIsSet && ( fPtMin==0 || fPtMax==0 ) ) ) )
71  Fatal("Init()","PndVolGenerator: Cannot use P == 0 as limit for inverse momentum distribution");
72 
73  // Check for particle type
74  //FairGeoLoader* geoLoad = new FairGeoLoader("TGeo","FairGeoLoader");
75  //FairGeoInterface *geoFace = geoLoad->getGeoInterface();
76 
77 
78  std::cout<<" gGeoManager 1 "<<gGeoManager<<" "<<std::endl;
79 
80  TDatabasePDG* pdgBase = TDatabasePDG::Instance();
81  TParticlePDG *particle = pdgBase->GetParticle(fPDGType);
82  if (! particle) Fatal("PndVolGenerator","PDG code %d not defined.",fPDGType);
83  fPDGMass = particle->Mass();
84 }
85 
86 // ------------------------------------------------------------------------
88 {
89  // Generate one event: produce primary particles emitted from one vertex.
90  // Primary particles are distributed uniformly along
91  // those kinematics variables which were limitted by setters.
92  // if SetCosTheta() function is used, the distribution will be uniform in cos(theta)
93 
94  Double32_t pabs, phi, pt, theta=0, eta, y, mt, px, py, pz, pinv=0;
95 
96  // TGeoVolume *top ;
97  //if(gGeoManager)top = (TGeoVolume*)gGeoManager->GetTopVolume();
98 
99  TGeoVolume *top ;
100  if(gGeoManager)top = (TGeoVolume*)gGeoManager->GetTopVolume();
101  gGeoManager->GetCache()->BuildIdArray();
102  std::cout<<" gGeoManager 2 "<<gGeoManager<<std::endl;
103 
104  //if(gGeoManager)std::cout<<" gGeoManager 2 "<<gGeoManager<<" "<<top<<std::endl;
105  //std::cout<<" first volume "<<gGeoManager->GetCurrentVolume()->GetName()<<std::endl;
106 
107  if(top->GetName()!=gGeoManager->GetCurrentVolume()->GetName()){
108  gGeoManager->CdTop();
109  // std::cout<<" first volume Top "<<gGeoManager->GetCurrentVolume()->GetName()<<" top "<<top->GetName()<<std::endl;
110  }
111  gGeoManager->CdDown(0); //complex
112  //std::cout<<" volume 1 "<<gGeoManager->GetPath()<<" "
113  // <<gGeoManager->GetCurrentVolume()->GetNdaughters()<<std::endl;
114 
115  Int_t Daught;
116  Daught = gGeoManager->GetCurrentVolume()->GetNdaughters();
117 
118  gGeoManager->CdDown(fQuad); // stgQuad0 , 1 -> stgQuad2 , CdUp(), CdDown(2)
119 
120  //std::cout<<" volume 2 "<<gGeoManager->GetPath()<<" "
121  // <<gGeoManager->GetCurrentVolume()->GetNdaughters()<<std::endl;
122 
123  if(fExt) {gGeoManager->CdDown(fAbs); //stglAb0 ,0 -> stglSi0_0 ,CdUp(), CdDown(1)
124  }else {fAbs = TMath::Nint(fFunc->GetRandom());
125  std::cout<<" random fabs "<<fAbs<<std::endl;
126  gGeoManager->CdDown(fAbs);}
127 
128  fCurrentTransMat = gGeoManager->GetCurrentMatrix();
129  Double_t posLab[3], posSens[3];
130 
131  posSens[0]=0.; posSens[1]=0.; posSens[2]=0.;
132  fCurrentTransMat->LocalToMaster(posSens,posLab);
133 
134  fX = posLab[0];
135  fY = posLab[1];
136  fZ = posLab[2];
137 
138  std::cout<<" vertex "<<fX<<" "<<fY<<" "<<fZ<<std::endl;
139 
140 
141  // Generate particles
142  for (Int_t k = 0; k < fMult; k++) {
143  phi = gRandom->Uniform(fPhiMin,fPhiMax) * TMath::DegToRad();
144 
145  if (fPRangeIsSet ) {
146  if (fInversePIsSet)
147  {
148  pinv = gRandom->Uniform(1./fPMax, 1./fPMin);
149  pabs = 1./pinv;
150  }
151  else
152  {
153  pabs = gRandom->Uniform(fPMin,fPMax);
154  }
155  }
156  else if (fPtRangeIsSet) {
157  if (fInversePIsSet)
158  {
159  pinv = gRandom->Uniform(1./fPtMax, 1./fPtMin);
160  pt = 1./pinv;
161  }
162  else
163  {
164  pt = gRandom->Uniform(fPtMin,fPtMax);
165  }
166  }
167 
168  if (fThetaRangeIsSet) {
169  if (fCosThetaIsSet)
170  theta = acos(gRandom->Uniform(cos(fThetaMin* TMath::DegToRad()),cos(fThetaMax* TMath::DegToRad())));
171  else
172  theta = gRandom->Uniform(fThetaMin,fThetaMax) * TMath::DegToRad();
173  }
174  else if (fEtaRangeIsSet) {
175  eta = gRandom->Uniform(fEtaMin,fEtaMax);
176  theta = 2*TMath::ATan(TMath::Exp(-eta));
177  }
178  else if (fYRangeIsSet) {
179  y = gRandom->Uniform(fYMin,fYMax);
180  mt = TMath::Sqrt(fPDGMass*fPDGMass + pt*pt);
181  pz = mt * TMath::SinH(y);
182  }
183 
185  if (fPRangeIsSet ) {
186  pz = pabs*TMath::Cos(theta);
187  pt = pabs*TMath::Sin(theta);
188  }
189  else if (fPtRangeIsSet)
190  pz = pt/TMath::Tan(theta);
191  }
192 
193  px = pt*TMath::Cos(phi);
194  py = pt*TMath::Sin(phi);
195 
196  if (fVolVtxIsSet) {
197  fX = gRandom->Uniform(fX1,fX2);
198  fY = gRandom->Uniform(fY1,fY2);
199  }
200 
201  if (fDebug)
202  printf("VolGen: kf=%d, p=(%.2f, %.2f, %.2f) GeV, x=(%.1f, %.1f, %.1f) cm\n",
203  fPDGType, px, py, pz, fX, fY, fZ);
204 
205  primGen->AddTrack(fPDGType, px, py, pz, fX, fY, fZ);
206  }
207  return kTRUE;
208 
209 }
210 // ------------------------------------------------------------------------
211 
212 
friend F32vec4 acos(const F32vec4 &a)
Definition: P4_F32vec4.h:113
printf("RealTime=%f seconds, CpuTime=%f seconds\n", rtime, ctime)
friend F32vec4 cos(const F32vec4 &a)
Definition: P4_F32vec4.h:112
static T Sqrt(const T &x)
Definition: PndCAMath.h:37
Double32_t fThetaMin
static T Sin(const T &x)
Definition: PndCAMath.h:42
Double_t fX
Definition: PndCaloDraw.cxx:34
float Tan(float x)
Definition: PndCAMath.h:165
Double32_t fThetaMax
TGeoManager * gGeoManager
static T Cos(const T &x)
Definition: PndCAMath.h:43
Double_t fZ
Definition: PndCaloDraw.cxx:34
void SetPhiRange(Double32_t phimin=0, Double32_t phimax=360)
TGeoVolume * top
Double_t fThetaMin
Definition: run_full.C:19
Double_t fPMin
Definition: run_full.C:16
TGeoHMatrix * fCurrentTransMat
FairPrimaryGenerator * primGen
Definition: sim_emc_apd.C:81
virtual Bool_t ReadEvent(FairPrimaryGenerator *primGen)
TString pt(TString pts, TString exts="px py pz")
Definition: invexp.C:133
const int particle
Double_t
Double32_t fEtaMin
Double32_t fEtaMax
Double_t fPMax
Definition: run_full.C:18
Double_t fY
Definition: PndCaloDraw.cxx:34
Double32_t fPDGMass
ClassImp(PndAnaContFact)
TParticlePDG * eta
Double_t y
Double_t fThetaMax
Definition: run_full.C:21
Double32_t fPhiMax
Double32_t fPhiMin
Double_t mult
int Nint(float x)
Definition: PndCAMath.h:117
double pz[39]
Definition: pipisigmas.h:14