StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
gen.C
1 // macro to instantiate the Geant3 from within
2 // STAR C++ framework and get the starsim prompt
3 // To use it do
4 // root4star starsim.C
5 
6 class St_geant_Maker;
7 St_geant_Maker *geant_maker = 0;
8 
9 class StarGenEvent;
10 StarGenEvent *event = 0;
11 
12 class StarPrimaryMaker;
13 StarPrimaryMaker *_primary = 0;
14 
15 class StarKinematics;
17 
18 
19 TH1F* hNumHits = 0;
20 TString nameParticle = "mu+";
21 float numParticles = 5;
22 
23 // ----------------------------------------------------------------------------
24 void geometry( TString tag, Bool_t agml=true )
25 {
26  TString cmd = "DETP GEOM "; cmd += tag + " field=-5.0";
27  if ( !geant_maker ) geant_maker = (St_geant_Maker *)chain->GetMaker("geant");
28  geant_maker -> LoadGeometry(cmd);
29  // if ( agml ) command("gexec $STAR_LIB/libxgeometry.so");
30 }
31 // ----------------------------------------------------------------------------
32 void command( TString cmd )
33 {
34  if ( !geant_maker ) geant_maker = (St_geant_Maker *)chain->GetMaker("geant");
35  geant_maker -> Do( cmd );
36 }
37 // ----------------------------------------------------------------------------
38 void trig( Int_t n=1 )
39 {
40 
41 
42  for ( Int_t i=0; i<n; i++ ) {
43 
44  // Clear the chain from the previous event
45  chain->Clear();
46 
47  kinematics->Kine( numParticles, nameParticle.Data(), 0.2, 5.0, 2.0, 4.50 );
48  // kinematics->Kine( numParticles, nameParticle.Data(), 10.2, 12.0, 2.5, 4.00 );
49 
50  // Generate the event
51  chain->Make();
52 
53  TTable* hits = chain->GetDataSet("bfc/.make/geant/.data/g2t_stg_hit");
54  if ( hits ) {
55  double nhits = hits->GetNRows();
56  hNumHits->Fill( double(i), nhits / 4.0 / numParticles );
57  std::cout << "N hits = " << nhits << std::endl;
58  }
59 
60  // Print the event
61  // command("gprint hits stgh");
62 
63  }
64 }
65 // ----------------------------------------------------------------------------
66 // ----------------------------------------------------------------------------
67 // ----------------------------------------------------------------------------
68 void Kinematics()
69 {
70 
71  // gSystem->Load( "libStarGeneratorPoolPythia6_4_23.so" );
72  gSystem->Load( "libKinematics.so");
73  kinematics = new StarKinematics();
74 
75  _primary->AddGenerator(kinematics);
76 }
77 // ----------------------------------------------------------------------------
78 // ----------------------------------------------------------------------------
79 // ----------------------------------------------------------------------------
80 void gen( Int_t nevents=100, Int_t rngSeed=12352342 )
81 {
82 
83  cout << "Generating: " << nevents << " events with seed: " << rngSeed << endl;
84  gSystem->Load( "libStarRoot.so" );
85  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");
86 
87  gROOT->ProcessLine(".L bfc.C");
88  {
89  TString simple = "sdt20211016 y2023 geant gstar usexgeom agml ";
90  bfc(0, simple );
91  }
92 
93  gSystem->Load( "libVMC.so");
94 
95  gSystem->Load( "StarGeneratorUtil.so" );
96  gSystem->Load( "StarGeneratorEvent.so" );
97  gSystem->Load( "StarGeneratorBase.so" );
98 
99  gSystem->Load( "libMathMore.so" );
100  gSystem->Load( "xgeometry.so" );
101 
102  // Setup RNG seed and map all ROOT TRandom here
103  StarRandom::seed( rngSeed );
105 
106  //
107  // Create the primary event generator and insert it
108  // before the geant maker
109  //
110  // StarPrimaryMaker *
111  _primary = new StarPrimaryMaker();
112  {
113  _primary -> SetFileName( "sim.root");
114  chain -> AddBefore( "geant", _primary );
115  }
116 
117  Kinematics();
118 
119  //
120  // Initialize primary event generator and all sub makers
121  //
122  _primary -> Init();
123  _primary->SetSigma( 0.1, 0.1, 0.1 ); // 1mm x 1mm x 1mm smearing at the vertex
124  _primary->SetVertex(0.0, 0.0, 0.0 );
125 
126  //
127  // Setup geometry and set starsim to use agusread for input
128  //
129  //geometry("y2012");
130  command("gkine -4 0");
131  command("gfile o sim.fzd");
132 
133 
134  hNumHits = new TH1F("hNumEvents","Nhits/plane/incident track vs event number",nevents + 1, -0.5, (float)( nevents ) + 0.5 );
135  // hNumHits->SetBit(TH1::kCanRebin);
136 
137 
138  // command( "DCAY 0" );
139  // command( "ANNI 0" );
140  // command( "BREM 0" );
141  // command( "COMP 0" );
142  // command( "HADR 0" );
143  // command( "MUNU 0" );
144  // command( "PAIR 0" );
145  // command( "PFIS 0" );
146  // command( "PHOT 0" );
147  // command( "RAYL 0" );
148  // command( "LOSS 4" );
149  // command( "DRAY 0" );
150  // command( "MULS 0" );
151  // command( "STRA 0" );
152  // command( "physi" );
153 
154  //
155  // Trigger on nevents
156  //
157  trig( nevents );
158 
159  // TFile * f = new TFile( "gen.root", "RECREATE" );
160  // f->cd();
161  // hNumHits->Write();
162  // f->Write();
163 
164  command("call agexit"); // Make sure that STARSIM exits properly
165 
166 }
167 // ----------------------------------------------------------------------------
168 
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 Long_t GetNRows() const
Returns the number of the used rows for the wrapped table.
Definition: TTable.cxx:1388
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.
Definition: TTable.h:48
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.