StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
jpsi.C
1 //usr/bin/env root4star -l -b -q $0'('$1', '$2')'; exit $?
2 // macro to instantiate the Geant3 from within
3 // STAR C++ framework and get the starsim prompt
4 // To use it do
5 // root4star starsim.C
6 
7 class St_geant_Maker;
8 St_geant_Maker *geant_maker = 0;
9 
10 class StarGenEvent;
11 StarGenEvent *event = 0;
12 
13 class StarPrimaryMaker;
14 StarPrimaryMaker *_primary = 0;
15 
16 class StarKinematics;
18 
19 
20 TH1F* hMll = 0;
21 bool decayJPsiToElectrons = false;
22 float numParticles = 1;
23 
24 // ----------------------------------------------------------------------------
25 void geometry( TString tag, Bool_t agml=true )
26 {
27  TString cmd = "DETP GEOM "; cmd += tag + " field=-5.0";
28  if ( !geant_maker ) geant_maker = (St_geant_Maker *)chain->GetMaker("geant");
29  geant_maker -> LoadGeometry(cmd);
30  // if ( agml ) command("gexec $STAR_LIB/libxgeometry.so");
31 }
32 // ----------------------------------------------------------------------------
33 void command( TString cmd )
34 {
35  if ( !geant_maker ) geant_maker = (St_geant_Maker *)chain->GetMaker("geant");
36  geant_maker -> Do( cmd );
37 }
38 // ----------------------------------------------------------------------------
39 void trig( Int_t n=1 )
40 {
41 
42 
43  for ( Int_t i=0; i<n; i++ ) {
44 
45  // Clear the chain from the previous event
46  chain->Clear();
47 
48  //(Momentum, Energy units are Gev/C, GeV)
49  Double_t masses[2] = { 0.00051099895000, 0.00051099895000} ;
50 
51  if (!decayJPsiToElectrons){
52  masses[0] = 0.1056583755;
53  masses[1] = 0.1056583755;
54  }
55 
56  TGenPhaseSpace genEvent;
57  TLorentzVector W;
58  // W.SetPtEtaPhiM( 0.0, 100.0, 0, 3.096 );
59  W.SetXYZM( 0, 0, 30, 3.096 );
60  genEvent.SetDecay(W, 2, masses);
61 
62  TLorentzVector lv;
63  for ( int j = 0; j < numParticles; j++ ){
64  Double_t weight = genEvent.Generate();
65  TLorentzVector *pElectron = genEvent.GetDecay(0);
66  TLorentzVector *pPositron = genEvent.GetDecay(1);
67  lv = *pElectron + *pPositron;
68 
69  StarGenParticle *ele;
70  if ( decayJPsiToElectrons )
71  ele = kinematics->AddParticle( "e-" );
72  else
73  ele = kinematics->AddParticle( "mu-" );
74  ele->SetPx(pElectron->Px());
75  ele->SetPy(pElectron->Py());
76  ele->SetPz(pElectron->Pz());
77  ele->SetMass( masses[0] );
78 
79  StarGenParticle *pos;
80  if ( decayJPsiToElectrons )
81  pos = kinematics->AddParticle( "e+" );
82  else
83  pos = kinematics->AddParticle( "mu+" );
84  pos->SetPx(pPositron->Px());
85  pos->SetPy(pPositron->Py());
86  pos->SetPz(pPositron->Pz());
87  pos->SetMass( masses[0] );
88 
89  hMll->Fill( lv.M() );
90 
91  cout << "ele eta = " << pElectron->Eta() << endl;
92  cout << "pos eta = " << pPositron->Eta() << endl;
93  }
94 
95 
96  // kinematics->Kine( numParticles, nameParticle.Data(), 10.2, 12.0, 2.5, 4.00 );
97 
98  // Generate the event
99  chain->Make();
100 
101  // TTable* hits = chain->GetDataSet("bfc/.make/geant/.data/g2t_stg_hit");
102  // if ( hits ) {
103  // double nhits = hits->GetNRows();
104  // hNumHits->Fill( double(i), nhits / 4.0 / numParticles );
105  // std::cout << "N hits = " << nhits << std::endl;
106  // }
107 
108  // Print the event
109  // command("gprint hits stgh");
110 
111  }
112 }
113 // ----------------------------------------------------------------------------
114 // ----------------------------------------------------------------------------
115 // ----------------------------------------------------------------------------
116 void Kinematics()
117 {
118 
119  // gSystem->Load( "libStarGeneratorPoolPythia6_4_23.so" );
120  gSystem->Load( "libKinematics.so");
121  kinematics = new StarKinematics();
122 
123  _primary->AddGenerator(kinematics);
124 }
125 // ----------------------------------------------------------------------------
126 // ----------------------------------------------------------------------------
127 // ----------------------------------------------------------------------------
128 void jpsi( Int_t nevents=10000, Int_t rngSeed=12352342, bool decayToElectrons = true )
129 {
130 
131  hMll = new TH1F("hMll",";Mll;counts [10MeV]", 200, 2.0, 4.0 );
132  decayJPsiToElectrons = decayToElectrons;
133  cout << "Generating: " << nevents << " events with seed: " << rngSeed << endl;
134  if ( decayToElectrons ){
135  cout << "Simulating J/psi->e+e-" << endl;
136  } else {
137  cout << "Simulating J/psi->mu+mu-" << endl;
138  }
139  gSystem->Load( "libStarRoot.so" );
140  gROOT->SetMacroPath(".:/star-sw/StRoot/macros/:./StRoot/macros:./StRoot/macros/graphics:./StRoot/macros/analysis:./StRoot/macros/test:./StRoot/macros/examples:./StRoot/macros/html:./StRoot/macros/qa:./StRoot/macros/calib:./StRoot/macros/mudst:/afs/rhic.bnl.gov/star/packages/DEV/StRoot/macros:/afs/rhic.bnl.gov/star/packages/DEV/StRoot/macros/graphics:/afs/rhic.bnl.gov/star/packages/DEV/StRoot/macros/analysis:/afs/rhic.bnl.gov/star/packages/DEV/StRoot/macros/test:/afs/rhic.bnl.gov/star/packages/DEV/StRoot/macros/examples:/afs/rhic.bnl.gov/star/packages/DEV/StRoot/macros/html:/afs/rhic.bnl.gov/star/packages/DEV/StRoot/macros/qa:/afs/rhic.bnl.gov/star/packages/DEV/StRoot/macros/calib:/afs/rhic.bnl.gov/star/packages/DEV/StRoot/macros/mudst:/afs/rhic.bnl.gov/star/ROOT/36/5.34.38/.sl73_x8664_gcc485/rootdeb/macros:/afs/rhic.bnl.gov/star/ROOT/36/5.34.38/.sl73_x8664_gcc485/rootdeb/tutorials");
141 
142  gROOT->ProcessLine(".L bfc.C");
143  {
144  TString simple = "sdt20211016 y2024 geant gstar usexgeom agml ";
145  bfc(0, simple );
146  }
147 
148  gSystem->Load( "libVMC.so");
149 
150  gSystem->Load( "StarGeneratorUtil.so" );
151  gSystem->Load( "StarGeneratorEvent.so" );
152  gSystem->Load( "StarGeneratorBase.so" );
153 
154  gSystem->Load( "libMathMore.so" );
155  gSystem->Load( "xgeometry.so" );
156 
157 
158 
159  // Setup RNG seed and map all ROOT TRandom here
160  StarRandom::seed( rngSeed );
162 
163  //
164  // Create the primary event generator and insert it
165  // before the geant maker
166  //
167  // StarPrimaryMaker *
168  _primary = new StarPrimaryMaker();
169  {
170  _primary -> SetFileName( "jpsi.root");
171  chain -> AddBefore( "geant", _primary );
172  }
173 
174  Kinematics();
175 
176  //
177  // Initialize primary event generator and all sub makers
178  //
179  _primary -> Init();
180  _primary->SetSigma( 0.1, 0.1, 0.1 ); // 1mm x 1mm x 1mm smearing at the vertex
181  _primary->SetVertex(0.0, 0.0, 0.0 );
182 
183  //
184  // Setup geometry and set starsim to use agusread for input
185  //
186  //geometry("y2012");
187  command("gkine -4 0");
188  command("gfile o jpsi.fzd");
189 
190 
191  hNumHits = new TH1F("hNumEvents","Nhits/plane/incident track vs event number",nevents + 1, -0.5, (float)( nevents ) + 0.5 );
192  // hNumHits->SetBit(TH1::kCanRebin);
193 
194 
195  // command( "DCAY 0" );
196  // command( "ANNI 0" );
197  // command( "BREM 0" );
198  // command( "COMP 0" );
199  // command( "HADR 0" );
200  // command( "MUNU 0" );
201  // command( "PAIR 0" );
202  // command( "PFIS 0" );
203  // command( "PHOT 0" );
204  // command( "RAYL 0" );
205  // command( "LOSS 4" );
206  // command( "DRAY 0" );
207  // command( "MULS 0" );
208  // command( "STRA 0" );
209  // command( "physi" );
210 
211  //
212  // Trigger on nevents
213  //
214  trig( nevents );
215 
216  TFile * f = new TFile( "jpsi_gen.root", "RECREATE" );
217  f->cd();
218  hMll->Write();
219  f->Write();
220 
221  command("call agexit"); // Make sure that STARSIM exits properly
222 
223 }
224 // ----------------------------------------------------------------------------
225 
StarGenParticle * AddParticle()
void SetPx(Float_t px)
Set the x-component of the momentum.
void SetSigma(Double_t sx, Double_t sy, Double_t sz, Double_t rho=0)
Star Simple Kinematics Generator.
Yet another particle class.
virtual void Clear(Option_t *option="")
User defined functions.
Definition: StChain.cxx:77
void AddGenerator(StarGenerator *gener)
void SetPz(Float_t pz)
Set the z-component of the momentum.
Int_t Init()
Initialize generator.
void SetMass(Float_t mass)
Set the mass.
virtual Int_t Make()
Definition: StChain.cxx:110
static void seed(UInt_t s)
Definition: StarRandom.cxx:119
Base class for event records.
Definition: StarGenEvent.h:81
Main steering class for event generation.
void SetPy(Float_t py)
Set the y-component of the momentum.
static void capture()
Capture gRandom random number generator.
Definition: StarRandom.cxx:57
Sparse class to hold track kinematics.
void SetVertex(Double_t x, Double_t y, Double_t z)
Set the x, y and z vertex position.