StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
simulation.y2014x.pythia8.HFjets.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 #define USE_PYTHIA8_DECAYER
19 
20 // ----------------------------------------------------------------------------
21 void geometry( TString tag, Bool_t agml=true )
22 {
23  TString cmd = "DETP GEOM "; cmd += tag;
24  if ( !geant_maker ) geant_maker = (St_geant_Maker *)chain->GetMaker("geant");
25  geant_maker -> LoadGeometry(cmd);
26  // if ( agml ) command("gexec $STAR_LIB/libxgeometry.so");
27 }
28 // ----------------------------------------------------------------------------
29 void command( TString cmd )
30 {
31  if ( !geant_maker ) geant_maker = (St_geant_Maker *)chain->GetMaker("geant");
32  geant_maker -> Do( cmd );
33 }
34 // ----------------------------------------------------------------------------
35 // trig() -- generates one event
36 // trig(n) -- generates n+1 events.
37 //
38 // NOTE: last event generated will be corrupt in the FZD file
39 //
40 double _vx = 0;
41 double _vy = 0;
42 double _vz = 0;
43 int _runId = 0;
44 int _eventId = 0;
45 void trig( int runId, int eventId, double vz )
46 {
47 
48  _primary -> SetVertex( 0.1, -0.1, vz );
49  _primary -> SetSigma ( 0.1E-12, 0.1E-12, 0.1E-12 );
50 
51  chain->Clear();
52  chain->Make();
53 
54  // command("message gprint kine:");
55  // command("gprint kine");
56 
57 
58 
59 }
60 // ----------------------------------------------------------------------------
61 // ----------------------------------------------------------------------------
62 // ----------------------------------------------------------------------------
63 void Pythia8( TString config="pp:W", Double_t ckin3=0.0, Double_t ckin4=-1.0 )
64 {
65 
66  //
67  // Create the pythia 8 event generator and add it to
68  // the primary generator
69  //
70  StarPythia8 *pythia8 = new StarPythia8();
71  if ( config=="pp:W" )
72  {-
73  pythia8->SetFrame("CMS", 510.0);
74  pythia8->SetBlue("proton");
75  pythia8->SetYell("proton");
76 
77  pythia8->Set("WeakSingleBoson:all=off");
78  pythia8->Set("WeakSingleBoson:ffbar2W=on");
79  pythia8->Set("24:onMode=0"); // switch off all W+/- decaus
80  pythia8->Set("24:onIfAny 11 -11"); // switch on for decays to e+/-
81 
82  }
83  if ( config=="pp:minbias" )
84  {
85  pythia8->SetFrame("CMS", 500.0);
86  pythia8->SetBlue("proton");
87  pythia8->SetYell("proton");
88 
89  pythia8->Set("HardQCD:all = on");
90 
91  }
92  if ( config=="pp:heavyflavor:D0jets" )
93  {
94  pythia8->Set("HardQCD:gg2ccbar = on");
95  pythia8->Set("HardQCD:qqbar2ccbar = on");
96  pythia8->Set("Charmonium:all = on");
97 
98  pythia8->Set("421:mayDecay = 0");
99 
100  pythia8->SetFrame("CMS", 200.0);
101  pythia8->SetBlue("proton");
102  pythia8->SetYell("proton");
103 
104  }
105 
106  // Setup phase space cuts
107  pythia8 -> Set(Form("PhaseSpace:ptHatMin=%f", ckin3 ));
108  pythia8 -> Set(Form("PhaseSpace:ptHatMax=%f", ckin4 ));
109 
110  _primary -> AddGenerator( pythia8 );
111 
112 
113 }
114 // ----------------------------------------------------------------------------
115 // ----------------------------------------------------------------------------
116 TString runfile = "";
117 
118 void getNextRun( int& event, int& run, double& z ) {
119 
120  static ifstream myfile;
121  double x, y;
122 
123  // Initialize on first call
124  if ( event == 0 ) {
125  myfile.open(runfile.Data());
126  }
127 
128  // Handle end of file
129  if ( myfile.eof() ) {
130  event = 0;
131  run = 0;
132  z = -999.0;
133  return;
134  }
135 
136  // 15165057 2586838 -0.23291 -0.151908 -2.82513
137  myfile >> run >> event >> x >> y >> z;
138 
139 }
140 
141 // ----------------------------------------------------------------------------
142 
143 void starsim( Int_t nevents=10000, Int_t runnumber=15117062, TString runfile_="15117062.dat", int sequence=0, int dummy = 0 )
144 {
145 
146  // nevents -- number of events to process
147  // runnumber -- the run number this simulation is to be compared to
148  // runfile -- a file containing one event per line, specifying the run #, event #, reconstructed vx, vy, vz
149  // sequence -- can be used (with stride > 1) to specify independent RNG seeds for the same input file
150  // dummy -- is ignored
151 
152  const int stride = 1;
153 
154  int rngSeed = runnumber * stride + sequence;
155  // runfile = Form("/gpfs01/star/pwg/droy1/EMBEDDING_2021_D0Analysis/VERTEX/VertexFiles/%i.txt",runnumber);
156  // runfile = Form("INPUTFILES/%i.txt",runnumber);
157  runfile = runfile_;
158 
159 
160 
161 
162  TString basename = Form("rcf22000_%s_%i_%ievts",runfile.Data(),sequence,nevents);
163 
164  gROOT->ProcessLine(".L bfc.C");
165  {
166  TString simple = "y2014x geant gstar usexgeom agml sdt20140530 DbV20150316 misalign ";
167  bfc(0, simple );
168  }
169 
170  gSystem->Load( "libVMC.so");
171 
172  gSystem->Load( "StarGeneratorUtil.so");
173  gSystem->Load( "StarGeneratorEvent.so");
174  gSystem->Load( "StarGeneratorBase.so" );
175 #ifdef USE_PYTHIA8_DECAYER
176  gSystem->Load( "StarGeneratorDecay.so" );
177 #endif
178  gSystem->Load( "Pythia8_3_03.so" );
179 
180  gSystem->Load( "libMathMore.so" );
181 
182  // Force loading of xgeometry
183  gSystem->Load( "xgeometry.so" );
184 
185  gSystem->Load("$OPTSTAR/lib/libfastjet.so");
186  gSystem->Load( "StarGeneratorFilt.so" );
187  gSystem->Load( "FastJetFilter.so" );
188 
189 // // And unloading of geometry
190 // TString geo = gSystem->DynamicPathName("geometry.so");
191 // if ( !geo.Contains("Error" ) ) {
192 // std::cout << "Unloading geometry.so" << endl;
193 // gSystem->Unload( gSystem->DynamicPathName("geometry.so") );
194 // }
195 
196 
197  // Setup RNG seed and map all ROOT TRandom here
198  StarRandom::seed( rngSeed );
200 
201  //
202  // Create the primary event generator and insert it
203  // before the geant maker
204  //
205  // StarPrimaryMaker *
206  _primary = new StarPrimaryMaker();
207  {
208  _primary -> SetFileName( "pythia8.starsim.root");
209  _primary->SetAttr("beamline", 1);
210  chain -> AddBefore( "geant", _primary );
211  }
212 
213  //
214  // Setup an event generator
215  //
216  double ckin3=3.0;
217  double ckin4=-1.0;
218 
219  Pythia8("pp:heavyflavor:D0jets", ckin3, ckin4 );
220 
221 #ifdef USE_PYTHIA8_DECAYER
222  //
223  // Setup decay manager
224  //
225  StarDecayManager *decayMgr = AgUDecay::Manager();
226  StarPythia8Decayer *decayPy8 = new StarPythia8Decayer();
227  decayMgr->AddDecayer( 0, decayPy8 ); // Handle any decay requested
228  decayPy8->SetDebug(1);
229  // decayPy8->Set("WeakSingleBoson:all = on");
230  decayPy8->Set("421:onMode = 0");
231  // decayPy8->Set("421:onIfAll = 321 -211");
232  decayPy8->Set("421:onIfMatch = 321 -211");
233 
234  //
235 
236  TString name;
237  double mass, lifetime, charge;
238  int tracktype, pdgcode, g3code;
239 
240  // Particle data
242  // One can add a particle to G3 using...
243  //data.AddParticleToG3( "MyD0", 0.1865E+01, 0.42800E-12, 0., 3, 421, 37, 0, 0 );
244  TParticlePDG* D0 = data.GetParticle("D0");
245  TParticlePDG* rho_pl = data.GetParticle("rho+");
246  TParticlePDG* rho_mn = data.GetParticle("rho-");
247  data.AddParticleToG3( D0, 37 );
248  data.AddParticleToG3( rho_pl, 153 );
249  data.AddParticleToG3( rho_mn, 154 );
250 #else
251  command("call gstar_part");
252 #endif
253 
254 
255 #if 1
256  //
257  // Setup the generator filter
258  //
259  // filter = new StDijetFilter();
260 
261  filter = new FastJetFilter();
262  _primary -> AddFilter( filter );
263 
264  // If set to 1, tracks will be saved in the tree on events which were
265  // rejected. If the tree size is too big (because the filter is too
266  // powerful) you may want to set this equal to zero. In which case
267  // only header information is saved for the event.
268  _primary->SetAttr("FilterKeepAll", int(0));
269 
270  // By default, the primary maker enters an infinite loop and executes
271  // the event generator until it yields an event which passes the filter.
272  // The big full chain treats this as a single event.
273  //
274  // If you want the BFC to see an empty event, set the FilterSkipRejects
275  // attribute on the primary maker and give it the priveledge it needs
276  // to kill the event.
277  //--- primary->SetAttr("FilterSkipRejects", int(1) ); // enables event skipping
278  //--- chain->SetAttr(".Privilege",1,"StarPrimaryMaker::*" );
279 #endif
280 
281  //
282  // Setup cuts on which particles get passed to geant for
283  // simulation. (To run generator in standalone mode,
284  // set ptmin=1.0E9.)
285  // ptmin ptmax
286  _primary->SetPtRange (0.0, -1.0); // GeV
287  // etamin etamax
288  _primary->SetEtaRange ( -3.0, +3.0 );
289  // phimin phimax
290  _primary->SetPhiRange ( 0., TMath::TwoPi() );
291 
292 
293  //
294  // Setup a realistic z-vertex distribution:
295  // x = 0 gauss width = 1mm
296  // y = 0 gauss width = 1mm
297  // z = 0 gauss width = 30cm
298  //
299  // _primary->SetVertex( 0., 0., 0. );
300  //_primary->SetSigma( 0.1, 0.1, 30.0 );
301 
302 
303  //
304  // Initialize primary event generator and all sub makers
305  //
306  _primary -> Init();
307 
308  command("gkine -4 0");
309  command( Form("gfile o %s.fzd",basename.Data()) );
310 
311  int count = 0;
312  while (true) {
313 
314  int event;
315  double z;
316  for ( int _s=0;_s<stride;_s++) {
317  getNextRun( event, runnumber, z );
318  if ( 0==runnumber ) {
319  std::cout << "End of run file encountered" << std::endl;
320  goto DONE;
321  }
322  }
323 
324  // Set run and event number in starsim
325  command( Form( "rung %i %i", runnumber, event ) );
326 
327  trig( event, runnumber, z );
328 
329  if ( count++ > nevents ) {
330  std::cout << "Last event requested" << std::endl;
331  break;
332  }
333 
334  }
335 
336  DONE:
337  std::cout << "Finishing up" << std::endl;
338 
339 
340 
341  //
342  // Finish the chain
343  //
344  chain->Finish();
345 
346  //
347  // EXIT starsim
348  //
349  command("call agexit"); // Make sure that STARSIM exits properly
350 
351 }
352 // ----------------------------------------------------------------------------
353 
void SetFrame(const Char_t *frame, const Double_t val)
void SetPhiRange(Double_t phimin, Double_t phimax)
Set phi range. Particles falling outside this range will be dropped from simulation.
virtual void Clear(Option_t *option="")
User defined functions.
Definition: StChain.cxx:77
static StarParticleData & instance()
Returns a reference to the single instance of this class.
TParticlePDG * GetParticle(const Char_t *name)
Get a particle by name.
virtual Int_t Finish()
Definition: StChain.cxx:85
Main filter class. Goes anywhere in the chain, filters StarGenEvent objects.
Interface to PDG information.
void SetBlue(const Char_t *b)
Sets the particle species for the blue beam.
Connects VMC to class(es) which handle particle decays.
virtual Int_t Make()
Definition: StChain.cxx:110
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
Main steering class for event generation.
void AddDecayer(Int_t pdgid, TVirtualMCDecayer *decayer)
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.
void SetDebug(int dbg=1)
Set the debug level.
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
TParticlePDG * AddParticleToG3(const char *name, const double mass, const double lifetime, const double charge, const int tracktype, const int pdgcode, const int g3code, const double *bratio=0, const int *mode=0)
void Set(const char *cmd)
Modify pythia8 behavior.