StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
gen.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* hNumHits = 0;
21 TString nameParticle = "mu+";
22 int numParticles = 1;
23 float minPt = 0.0;
24 float maxPt = 1.0;
25 float minEta = 2.5;
26 float maxEta = 4.00;
27 float minPhi = 0.0;
28 float maxPhi = 2.0 * TMath::Pi();
29 
30 float vtxX = 0.0;
31 float vtxY = 0.0;
32 float vtxZ = 0.0;
33 
34 float vtxSigmaX = 0.0001;
35 float vtxSigmaY = 0.0001;
36 float vtxSigmaZ = 0.0001;
37 
38 TString fzdFilename = "sim.fzd";
39 TString primaryName = "sim.root";
40 
41 // ----------------------------------------------------------------------------
42 void geometry( TString tag, Bool_t agml=true )
43 {
44  TString cmd = "DETP GEOM "; cmd += tag + " field=-5.0";
45  if ( !geant_maker ) geant_maker = (St_geant_Maker *)chain->GetMaker("geant");
46  geant_maker -> LoadGeometry(cmd);
47  // if ( agml ) command("gexec $STAR_LIB/libxgeometry.so");
48 }
49 // ----------------------------------------------------------------------------
50 void command( TString cmd )
51 {
52  if ( !geant_maker ) geant_maker = (St_geant_Maker *)chain->GetMaker("geant");
53  geant_maker -> Do( cmd );
54 }
55 // ----------------------------------------------------------------------------
56 void trig_event( Int_t i )
57 {
58  if ( gRandom->Rndm() > 0.5 ) {
59  nameParticle = "mu+";
60  } else {
61  nameParticle = "mu-";
62  }
63  kinematics->Kine( numParticles, nameParticle.Data(), minPt, maxPt, minEta, maxEta, minPhi, maxPhi );
64 }
65 // ----------------------------------------------------------------------------
66 void trig( Int_t n=1 )
67 {
68  for ( Int_t i=0; i<n; i++ ) {
69  // Clear the chain from the previous event
70  chain->Clear();
71  trig_event( i );
72  // Generate the event
73  chain->Make();
74  }
75 }
76 // ----------------------------------------------------------------------------
77 void Kinematics()
78 {
79 
80  // gSystem->Load( "libStarGeneratorPoolPythia6_4_23.so" );
81  gSystem->Load( "libKinematics.so");
82  kinematics = new StarKinematics();
83  _primary->AddGenerator(kinematics);
84 }
85 // ----------------------------------------------------------------------------
86 void gen( Int_t nevents=1000, Int_t rngSeed=12352342 )
87 {
88 
89  cout << "Generating: " << nevents << " events with seed: " << rngSeed << endl;
90  gSystem->Load( "libStarRoot.so" );
91  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");
92 
93  gROOT->ProcessLine(".L bfc.C");
94  {
95  TString simple = "sdt20211016 y2024 geant gstar usexgeom agml ";
96  bfc(0, simple );
97  }
98 
99  gSystem->Load( "libVMC.so");
100 
101  gSystem->Load( "StarGeneratorUtil.so" );
102  gSystem->Load( "StarGeneratorEvent.so" );
103  gSystem->Load( "StarGeneratorBase.so" );
104 
105  gSystem->Load( "libMathMore.so" );
106  gSystem->Load( "xgeometry.so" );
107 
108  // Setup RNG seed and map all ROOT TRandom here
109  StarRandom::seed( rngSeed );
111 
112  //
113  // Create the primary event generator and insert it
114  // before the geant maker
115  //
116  // StarPrimaryMaker *
117  _primary = new StarPrimaryMaker();
118  {
119  _primary -> SetFileName( primaryName );
120  chain -> AddBefore( "geant", _primary );
121  }
122 
123  Kinematics();
124 
125  //
126  // Initialize primary event generator and all sub makers
127  //
128  _primary -> Init();
129  _primary->SetSigma( vtxSigmaX, vtxSigmaY, vtxSigmaZ ); // 1mm x 1mm x 1mm smearing at the vertex
130  _primary->SetVertex(vtxX, vtxY, vtxZ );
131 
132  //
133  // Setup geometry and set starsim to use agusread for input
134  //
135  //geometry("y2012");
136  command("gkine -4 0");
137  command( TString::Format("gfile o %s", fzdFilename.Data()) );
138 
139 
140  // command( "DCAY 0" );
141  // command( "ANNI 0" );
142  // command( "BREM 0" );
143  // command( "COMP 0" );
144  // command( "HADR 0" );
145  // command( "MUNU 0" );
146  // command( "PAIR 0" );
147  // command( "PFIS 0" );
148  // command( "PHOT 0" );
149  // command( "RAYL 0" );
150  // command( "LOSS 4" );
151  // command( "DRAY 0" );
152  // command( "MULS 0" );
153  // command( "STRA 0" );
154  // command( "physi" );
155 
156  //
157  // Trigger on nevents
158  //
159  // StarMagField::setConstBz(true);
160  trig( nevents );
161 
162  command("call agexit"); // Make sure that STARSIM exits properly
163 
164 }
165 // ----------------------------------------------------------------------------
void SetSigma(Double_t sx, Double_t sy, Double_t sz, Double_t rho=0)
Star Simple Kinematics Generator.
virtual void Clear(Option_t *option="")
User defined functions.
Definition: StChain.cxx:77
void AddGenerator(StarGenerator *gener)
Int_t Init()
Initialize generator.
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.
static void capture()
Capture gRandom random number generator.
Definition: StarRandom.cxx:57
Sparse class to hold track kinematics.
void Kine(Int_t ntrack, const Char_t *type="pi+,pi-,K+,K-,proton,antiproton", Double_t ptlow=0.0, Double_t pthigh=500.0, Double_t ylow=-10.0, Double_t yhigh=+10.0, Double_t philow=0.0, Double_t phihigh=TMath::TwoPi())
void SetVertex(Double_t x, Double_t y, Double_t z)
Set the x, y and z vertex position.