StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
runSimFlat.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 // Set magnetic field (reversed full)
19 Float_t field = -5.0;
20 //Float_t field = 0.0;
21 
22 // ----------------------------------------------------------------------------
23 void geometry( TString tag, Bool_t agml=true ){
24  TString cmd = "DETP GEOM "; cmd += tag; cmd += Form(" field=%f", field);
25  if ( !geant_maker ) geant_maker = (St_geant_Maker *)chain->GetMaker("geant");
26  geant_maker -> LoadGeometry(cmd);
27  // if ( agml ) command("gexec $STAR_LIB/libxgeometry.so");
28 }
29 // ----------------------------------------------------------------------------
30 void command( TString cmd ){
31  if ( !geant_maker ) geant_maker = (St_geant_Maker *)chain->GetMaker("geant");
32  geant_maker -> Do( cmd );
33 }
34 // ----------------------------------------------------------------------------
35 void trig( Int_t n=1, char* pid="ele", float e=0.0, float pt=1.5, int npart=1, int print=0){
36  char* PID = pid;
37  char* ele="e-";
38  char* pos="e+";
39  if(pid[0]=='e' && pid[1]=='l' && pid[2]=='e') PID=ele;
40  if(pid[0]=='p' && pid[1]=='o' && pid[2]=='s') PID=pos;
41  for ( Int_t i=0; i<n; i++ ) {
42  double pi=3.141592654;
43  cout << "==== Event="<<i<<"===="<<endl;
44  // Clear the chain from the previous event
45  chain->Clear();
46  if(e>0.0){
47  kinematics->SetAttr("energy",1);
48  // In kinematics, generates single particle before Make is called.
49  //kinematics->Kine(npart, PID, e-0.01, e+0.01, 2.2, 4.2, 0.0, 3.141592654*2.0);
50  //kinematics->Kine(npart, PID, e-0.01, e+0.01, 3.0, 3.01, 0.0, 3.141592654*2.0);
51  kinematics->Kine(npart, PID, e-0.01, e+0.01, 3.0, 3.01, -pi/2, pi);
52  //kinematics->Kine(npart, PID, e-0.01, e+0.01, 2.2, 4.0, 0.0, 2*pi);
53  //kinematics->Kine(npart, PID, e-0.01, e+0.01, 2.60, 4.0, 0.0, 3.141592654*2.0);
54  //kinematics->Kine( 1, PID, 2.99, 3.01, 2.50, 4.20, 0.0, 3.141592654/2.0);
55  }else{
56  kinematics->SetAttr("energy",0);
57  kinematics->Kine(npart, PID, pt-0.001, pt+0.001, 2.0, 4.4, 0.0, 2*pi);
58  // kinematics->Kine(npart, PID, pt-0.01, pt+0.01, 2.9, 3.1, pi/4, pi/2);
59  //kinematics->Kine(npart, PID, pt-0.01, pt+0.01, 2.9, 3.1, -2.0*pi/8.0, -pi/8.0);
60  }
61 
62  // Generate the event
63  chain->Make();
64  // Print the event
65  if(print>0) primary->event()->Print();
66  if(print>1) {
67  TIter Iterator = primary->event()->IterAll();
68  StarGenParticle *p = 0;
69  while( ( p = (StarGenParticle*)Iterator.Next() ) ){
70  TLorentzVector v = p->momentum();
71  cout << Form(" ===> e=%6.3f pt=%7.3f eta=%7.3f phi=%7.3f\n",v.E(),v.Pt(),v.Eta(),v.Phi());
72  }
73  }
74  if(print>2) command("gpri hits");
75  }
76 }
77 // ----------------------------------------------------------------------------
78 void Kinematics(){
79  // gSystem->Load( "libStarGeneratorPoolPythia6_4_23.so" );
80  gSystem->Load( "libKinematics.so");
81  kinematics = new StarKinematics();
82  primary->AddGenerator(kinematics);
83 }
84 // ----------------------------------------------------------------------------
85 void runSimFlat( Int_t nevents=1000, Int_t run=1,
86  char* pid="ele", float e=0.0, float pt=1.5, float vz=0.0, int npart=1,
87  int ecal=1, int print=0){
88  gROOT->ProcessLine(".L bfc.C");{
89  TString simple = "y2017 geant gstar agml usexgeom";
90  bfc(0, simple );
91  }
92  gSystem->Load( "libVMC.so");
93  gSystem->Load( "StarGeneratorUtil.so" );
94  gSystem->Load( "StarGeneratorEvent.so" );
95  gSystem->Load( "StarGeneratorBase.so" );
96  gSystem->Load( "libMathMore.so" );
97  gSystem->Load( "xgeometry.so" );
98 
99  // Create the primary event generator and insert it
100  // before the geant maker
101  primary = new StarPrimaryMaker();
102  {
103  chain -> AddBefore( "geant", primary );
104  // Set the output filename for the event record
105  if(e>0.0){
106  primary -> SetFileName(Form("%s.e%d.vz%d.run%i.root",pid,(int)e,(int)vz,run));
107  }else{
108  primary -> SetFileName(Form("%s.pt%3.1f.vz%d.run%i.root",pid,pt,(int)vz,run));
109  }
110  // Set the x,y,z vertex and distribution
111  primary -> SetVertex( 0., 0., vz );
112  primary -> SetSigma ( 0., 0., 0. );
113  }
114 
115  // Initialize primary event generator and all sub makers
116  Kinematics();
117  primary -> Init();
118 
119  // Initialize random number generator
121  StarRandom::seed(run);
122 
123  // Setup geometry and set starsim to use agusread for input
124  geometry("dev2022=1");
125  command("gkine -4 0");
126  if(e>0.0){
127  command(Form("gfile o %s.e%d.vz%d.run%d.fzd",pid,(int)e,(int)vz,run));
128  }else{
129  command(Form("gfile o %s.pt%3.1f.vz%d.run%d.fzd",pid,pt,(int)vz,run));
130  }
131  if(ecal==0){
132  cout << "TURNING OFF ECAL!!!"<<endl;
133  command("DETP WCAL wver.active=0");
134  }
135 
136  // Switch off some physics
137  const Char_t *cmds[] = {
138  "CKOV 0"
139  };
140  for ( UInt_t i=0;i<sizeof(cmds)/sizeof(Char_t*); i++ ){command( cmds[i] );}
141 
142  // Trigger on nevents
143  trig(nevents, pid, e, pt, npart, print);
144 
145  command("call agexit");
146 }
147 // ----------------------------------------------------------------------------
148 
void Print(const Option_t *opts="head") const
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)
Int_t Init()
Initialize generator.
TLorentzVector momentum()
Return the 4-momentum of the particle.
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
StarGenEvent * event()
Return a pointer to the event.
Main steering class for event generation.
TIter IterAll(Bool_t dir=kIterForward)
Definition: StarGenEvent.h:173
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())