StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StEpdTrivialEventGenerator.cxx
1 #include "./StEpdTrivialEventGenerator.h"
2 #include "TClonesArray.h"
3 #include "TVector3.h"
4 #include "TH1D.h"
5 #include "TRandom3.h"
6 #include "TMath.h"
7 #include <iostream>
8 //using namespace std;
9 
10 // --------------------------------------------------------
11 // this function does a binary search to invert the equation
12 // C(phi) = xran
13 // where C(phi) is the normalized integral of 1+0.5*(v1*cos(phi) + v2*cos(2phi))
14 double FindPhi(double v1, double v2, double xran){
15  double tolerance=0.01;
16  double lo=0.0;
17  double hi=2.0*TMath::Pi();
18  double mid;
19  do{
20  mid = (hi+lo)/2.0;
21  double Cvalue = (mid/2.0 + v1*sin(mid) + 0.5*v2*sin(2.0*mid))/TMath::Pi();
22  if (Cvalue > xran){hi=mid;}
23  else {lo=mid;}
24  } while(hi-lo>tolerance);
25  return mid;
26 }
27 
28 
29 // --------------------------------------------------------
30 StEpdTrivialEventGenerator::StEpdTrivialEventGenerator(TH1D* DnDeta, TH1D* V1versusEta, TH1D* V2versusEta){
31  if (DnDeta==0) std::cout << "You gave me no dNdeta histogram. Um, okay, but you're getting nothing but empty events-- have fun!\n\n";
32  mDnDeta = DnDeta;
33  mV1versusEta = V1versusEta;
34  mV2versusEta = V2versusEta;
35 
36  // check that the user made the x-axes the same.... please!
37  int nbins = mDnDeta->GetXaxis()->GetNbins();
38  float low = mDnDeta->GetXaxis()->GetBinLowEdge(1);
39  float hi = mDnDeta->GetXaxis()->GetBinUpEdge(1);
40  if ((mV1versusEta->GetXaxis()->GetNbins() != nbins)
41  || (mV2versusEta->GetXaxis()->GetNbins() != nbins)
42  || (fabs(mV1versusEta->GetXaxis()->GetBinLowEdge(1)- low) > 0.000001)
43  || (fabs(mV2versusEta->GetXaxis()->GetBinLowEdge(1)- low) > 0.000001)
44  || (fabs(mV1versusEta->GetXaxis()->GetBinUpEdge(1)- hi) > 0.000001)
45  || (fabs(mV2versusEta->GetXaxis()->GetBinUpEdge(1)- hi) > 0.000001))
46  // || (mV2versusEta->GetXaxis()->GetBinLowEdge(1) != low))
47  // || (mV1versusEta->GetXaxis()->GetBinUpEdge(1) != hi)
48  // || (mV2versusEta->GetXaxis()->GetBinUpEdge(1) != hi))
49  {
50  std::cout << "Dude, come on. Give me the same x-axis. I'm killing the v1 and v2 histograms. Your events will be isotropic.\n";
51  std::cout << low << " " << mV1versusEta->GetXaxis()->GetBinLowEdge(1) << " " << mV2versusEta->GetXaxis()->GetBinLowEdge(1) << "\n";
52  mV1versusEta=0;
53  mV2versusEta=0;
54  }
55  mRan = new TRandom3();
56  mRan->SetSeed();
57  mTracks = new TClonesArray("TVector3",1000);
58 }
59 
60 // --------------------------------------------------------
61 StEpdTrivialEventGenerator::~StEpdTrivialEventGenerator(){
62  /* no op */
63 }
64 
65 // --------------------------------------------------------
66 TClonesArray* StEpdTrivialEventGenerator::Momenta(){
67  if (mDnDeta==0) return 0;
68 
69  mTracks->Clear();
70 
71  // first, sample the dNdEta distribution.
72  // each bin has an average, and we sample a Poissonian with that average
73 
74  for (int ibin=1; ibin<=mDnDeta->GetXaxis()->GetNbins(); ibin++){
75  double ave = mDnDeta->GetBinContent(ibin)*mDnDeta->GetXaxis()->GetBinWidth(ibin);
76  if (ave<0.00001) continue;
77  int n = mRan->Poisson(ave);
78  for (int i=0; i<n; i++){
79  double eta = mRan->Uniform(mDnDeta->GetXaxis()->GetBinLowEdge(ibin),mDnDeta->GetXaxis()->GetBinUpEdge(ibin));
80  double v1 = (mV1versusEta==0)?0.0:mV1versusEta->GetBinContent(ibin);
81  double v2 = (mV2versusEta==0)?0.0:mV2versusEta->GetBinContent(ibin);
82  double phi = FindPhi(v1,v2,mRan->Uniform());
83  double pt = 1.0; // irrelevant, EPD only cares about eta and phi, and the simulator makes everything a MIP
84  TVector3* v = (TVector3*)mTracks->ConstructedAt(mTracks->GetEntriesFast());
85  v->SetPtEtaPhi(pt,eta,phi);
86  }
87 
88  }
89 
90  return mTracks;
91 }
92 
93 
94