StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
starsim.pythia8.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 StarFilterMaker;
16 StarFilterMaker *filter = 0;
17 
18 // ----------------------------------------------------------------------------
19 void geometry( TString tag, Bool_t agml=true )
20 {
21  TString cmd = "DETP GEOM "; cmd += tag;
22  if ( !geant_maker ) geant_maker = (St_geant_Maker *)chain->GetMaker("geant");
23  geant_maker -> LoadGeometry(cmd);
24  // if ( agml ) command("gexec $STAR_LIB/libxgeometry.so");
25 }
26 // ----------------------------------------------------------------------------
27 void command( TString cmd )
28 {
29  if ( !geant_maker ) geant_maker = (St_geant_Maker *)chain->GetMaker("geant");
30  geant_maker -> Do( cmd );
31 }
32 // ----------------------------------------------------------------------------
33 // trig() -- generates one event
34 // trig(n) -- generates n+1 events.
35 //
36 // NOTE: last event generated will be corrupt in the FZD file
37 //
38 void trig( Int_t n=1 )
39 {
40  chain->EventLoop(n);
41  _primary->event()->Print();
42 
43 }
44 // ----------------------------------------------------------------------------
45 // ----------------------------------------------------------------------------
46 // ----------------------------------------------------------------------------
47 void Pythia8( TString config="pp:W", Double_t ckin3=0.0, Double_t ckin4=-1.0 )
48 {
49 
50  //
51  // Create the pythia 8 event generator and add it to
52  // the primary generator
53  //
54  StarPythia8 *pythia8 = new StarPythia8();
55  if ( config=="pp:W" )
56  {
57  pythia8->SetFrame("CMS", 510.0);
58  pythia8->SetBlue("proton");
59  pythia8->SetYell("proton");
60 
61  pythia8->Set("WeakSingleBoson:all=off");
62  pythia8->Set("WeakSingleBoson:ffbar2W=on");
63  pythia8->Set("24:onMode=0"); // switch off all W+/- decaus
64  pythia8->Set("24:onIfAny 11 -11"); // switch on for decays to e+/-
65 
66  }
67  if ( config=="pp:minbias" )
68  {
69  pythia8->SetFrame("CMS", 500.0);
70  pythia8->SetBlue("proton");
71  pythia8->SetYell("proton");
72 
73  pythia8->Set("HardQCD:all = on");
74 
75  }
76  if ( config=="pp:heavyflavor:D0jets" )
77  {
78  pythia8->Set("HardQCD:gg2ccbar = on");
79  pythia8->Set("HardQCD:qqbar2ccbar = on");
80  pythia8->Set("Charmonium:all = on");
81 
82  pythia8->Set("421:mayDecay = 0");
83 
84  pythia8->SetFrame("CMS", 200.0);
85  pythia8->SetBlue("proton");
86  pythia8->SetYell("proton");
87 
88  }
89 
90  // Setup phase space cuts
91  pythia8 -> Set(Form("PhaseSpace:ptHatMin=%f", ckin3 ));
92  pythia8 -> Set(Form("PhaseSpace:ptHatMax=%f", ckin4 ));
93 
94  _primary -> AddGenerator( pythia8 );
95 
96 }
97 // ----------------------------------------------------------------------------
98 // ----------------------------------------------------------------------------
99 // ----------------------------------------------------------------------------
100 void starsim( Int_t nevents=10, Int_t rngSeed=1234 )
101 {
102 
103  gROOT->ProcessLine(".L bfc.C");
104  {
105  TString simple = "y2014x geant gstar usexgeom agml sdt20140530 DbV20150316 misalign ";
106  bfc(0, simple );
107  }
108 
109  gSystem->Load( "libVMC.so");
110 
111  gSystem->Load( "StarGeneratorUtil.so");
112  gSystem->Load( "StarGeneratorEvent.so");
113  gSystem->Load( "StarGeneratorBase.so" );
114 
115  gSystem->Load( "Pythia8_3_03.so" );
116 
117  gSystem->Load( "libMathMore.so" );
118 
119  // Force loading of xgeometry
120  gSystem->Load( "xgeometry.so" );
121 
122  gSystem->Load("$OPTSTAR/lib/libfastjet.so");
123  gSystem->Load( "StarGeneratorFilt.so" );
124  gSystem->Load( "FastJetFilter.so" );
125 
126 // // And unloading of geometry
127 // TString geo = gSystem->DynamicPathName("geometry.so");
128 // if ( !geo.Contains("Error" ) ) {
129 // std::cout << "Unloading geometry.so" << endl;
130 // gSystem->Unload( gSystem->DynamicPathName("geometry.so") );
131 // }
132 
133 
134  // Setup RNG seed and map all ROOT TRandom here
135  StarRandom::seed( rngSeed );
137 
138  //
139  // Create the primary event generator and insert it
140  // before the geant maker
141  //
142  // StarPrimaryMaker *
143  _primary = new StarPrimaryMaker();
144  {
145  _primary -> SetFileName( "pythia8.starsim.root");
146  _primary -> SetVertex( 0.1, -0.1, 0.0 );
147  _primary -> SetSigma ( 0.1, 0.1, 30.0 );
148  chain -> AddBefore( "geant", _primary );
149  }
150 
151  //
152  // Setup an event generator
153  //
154  double ckin3=3.0;
155  double ckin4=-1.0;
156  Pythia8("pp:heavyflavor:D0jets", ckin3, ckin4 );
157  command("call gstar_part");
158 
159 
160 #if 1
161  //
162  // Setup the generator filter
163  //
164  // filter = new StDijetFilter();
165 
166  filter = new FastJetFilter();
167  _primary -> AddFilter( filter );
168 
169  // If set to 1, tracks will be saved in the tree on events which were
170  // rejected. If the tree size is too big (because the filter is too
171  // powerful) you may want to set this equal to zero. In which case
172  // only header information is saved for the event.
173  _primary->SetAttr("FilterKeepAll", int(1));
174 
175  // By default, the primary maker enters an infinite loop and executes
176  // the event generator until it yields an event which passes the filter.
177  // The big full chain treats this as a single event.
178  //
179  // If you want the BFC to see an empty event, set the FilterSkipRejects
180  // attribute on the primary maker and give it the priveledge it needs
181  // to kill the event.
182  //--- primary->SetAttr("FilterSkipRejects", int(1) ); // enables event skipping
183  //--- chain->SetAttr(".Privilege",1,"StarPrimaryMaker::*" );
184 #endif
185 
186  //
187  // Setup cuts on which particles get passed to geant for
188  // simulation. (To run generator in standalone mode,
189  // set ptmin=1.0E9.)
190  // ptmin ptmax
191  _primary->SetPtRange (0.0, -1.0); // GeV
192  // etamin etamax
193  _primary->SetEtaRange ( -3.0, +3.0 );
194  // phimin phimax
195  _primary->SetPhiRange ( 0., TMath::TwoPi() );
196 
197 
198  //
199  // Setup a realistic z-vertex distribution:
200  // x = 0 gauss width = 1mm
201  // y = 0 gauss width = 1mm
202  // z = 0 gauss width = 30cm
203  //
204  _primary->SetVertex( 0., 0., 0. );
205  _primary->SetSigma( 0.1, 0.1, 30.0 );
206 
207 
208  //
209  // Initialize primary event generator and all sub makers
210  //
211  _primary -> Init();
212 
213  command("gkine -4 0");
214  command("gfile o pythia8.starsim.fzd");
215 
216 
217  //
218  // Trigger on nevents
219  //
220  trig( nevents );
221 
222  //
223  // Finish the chain
224  //
225  chain->Finish();
226 
227  //
228  // EXIT starsim
229  //
230  command("call agexit"); // Make sure that STARSIM exits properly
231 
232 }
233 // ----------------------------------------------------------------------------
234 
void SetSigma(Double_t sx, Double_t sy, Double_t sz, Double_t rho=0)
void SetFrame(const Char_t *frame, const Double_t val)
void Print(const Option_t *opts="head") const
void SetPhiRange(Double_t phimin, Double_t phimax)
Set phi range. Particles falling outside this range will be dropped from simulation.
virtual Int_t Finish()
Definition: StChain.cxx:85
Main filter class. Goes anywhere in the chain, filters StarGenEvent objects.
void SetBlue(const Char_t *b)
Sets the particle species for the blue beam.
static void seed(UInt_t s)
Definition: StarRandom.cxx:119
Filter which requires one or more particles in the final state of the event record.
Definition: FastJetFilter.h:20
Base class for event records.
Definition: StarGenEvent.h:81
StarGenEvent * event()
Return a pointer to the event.
Main steering class for event generation.
void SetYell(const Char_t *y)
Sets the particle species for the yellow beam.
void SetPtRange(Double_t ptmin, Double_t ptmax=-1)
Set PT range. Particles falling outside this range will be dropped from simulation.
static void capture()
Capture gRandom random number generator.
Definition: StarRandom.cxx:57
void SetEtaRange(Double_t etamin, Double_t etamax)
Set rapidity range. Particles falling outside this range will be dropped from simulation.
void Set(const char *s)
Pass a string to Pythia8::Pythia::readString(), for user configuration.
Definition: StarPythia8.h:91
void SetVertex(Double_t x, Double_t y, Double_t z)
Set the x, y and z vertex position.