StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StarPrimaryMaker.cxx
1 #include "StarPrimaryMaker.h"
2 
3 #include "g2t/St_g2t_particle_Module.h"
4 #include "tables/St_g2t_event_Table.h"
5 #include "tables/St_g2t_gepart_Table.h"
6 #include "tables/St_g2t_vertex_Table.h"
7 #include "tables/St_g2t_event_Table.h"
8 
9 #include "StarGenerator.h"
10 #include "StarCallf77.h"
11 #include <iostream>
12 #include <map>
13 #include "TString.h"
14 #include "TSystem.h"
15 
16 #include "StBFChain.h"
17 #include "TFile.h"
18 #include "TTree.h"
19 #include "TClass.h"
20 
21 #include "StarGenerator/BASE/AgStarReader.h"
22 #include "StarGenerator/EVENT/StarGenEvent.h"
23 #include "StarGenerator/EVENT/StarGenParticle.h"
24 #include "StarGenerator/UTIL/StarRandom.h"
25 #include "StarGenerator/FILT/StarFilterMaker.h"
26 
27 #include "TMCProcess.h"
28 
29 #include "tables/St_vertexSeed_Table.h"
30 #include <map>
31 #include <string>
32 
33 using namespace std;
34 
35 // 1 mm / speed of light
36 const double mmOverC = 1.0E-3 / TMath::C();
37 
38 // --------------------------------------------------------------------------------------------------------------
39 StarPrimaryMaker *fgPrimary = 0;
40 // --------------------------------------------------------------------------------------------------------------
42  StMaker("PrimaryMaker"),
43  mNumParticles(0),
44  mTree(0),
45  mFile(0),
46  mTreeName("none"),
47  mFileName("none"),
48  mStack(0),
49  mPrimaryEvent(0),
50  mVx(0), mVy(0), mVz(0), mSx(0.1), mSy(0.1), mSz(30.0), mRho(0), mVdxdz(0), mVdydz(0),
51  mDoBeamline(0),
52  mPtMin(0), mPtMax(-1), mRapidityMin(0), mRapidityMax(-1), mPhiMin(0), mPhiMax(-1), mZMin(-999), mZMax(+999),
53  mRunNumber(0),
54  mPrimaryVertex(0,0,0,0),
55  mFilter(0),
56  mAccepted(0),
57  mVertexFunction(),
58  mVertexFunctionMap()
59 {
60  assert(fgPrimary == 0); // cannot create more than one primary generator
61  fgPrimary = this;
62 
63  mStack = new StarParticleStack("PrimaryMakerStack");
64  SetAttr("usestarsim", int(1) );
65 
66  // Publish the stack
67  AddObj( mStack, ".const" );
68 
69  // Register the particle database with this maker
71  // Shunt( &pdb );
72  AddData( &pdb, ".const" );
73 
74  SetAttr("FilterKeepHeader", int(1) );
75 
76 
77  // Defaults to gaussian
78  mVertexFunctionMap[""] = std::bind( &StarPrimaryMaker::vertexGaussXYZ, this );
79  mVertexFunctionMap["gaussXYZ"] = std::bind( &StarPrimaryMaker::vertexGaussXYZ, this );
80  mVertexFunctionMap["flatZ"] = std::bind( &StarPrimaryMaker::vertexFlatZ, this );
81  mVertexFunctionMap["flatABZ"] = std::bind( &StarPrimaryMaker::vertexFlatABZ, this );
82  mVertexFunctionMap["flatRZ"] = std::bind( &StarPrimaryMaker::vertexFlatRZ, this );
83  mVertexFunctionMap["flatXYZ"] = std::bind( &StarPrimaryMaker::vertexFlatXYZ, this );
84 
85  SetAttr( "vertexDistribution", "gaussXYZ" );
91 
92  mVertexFunction = GetVertexFunction( SAttr("vertexDistribution") );
93 
94 }
95 // --------------------------------------------------------------------------------------------------------------
96 StarPrimaryMaker::~StarPrimaryMaker()
97 {
98  fgPrimary = 0; // Cleanup
99  if ( mStack ) delete mStack;
100  if ( mFile ) delete mFile;
101  /* deleting mTree and mPrimaryEvent cause seg violation here... why? */
102 }
103 // --------------------------------------------------------------------------------------------------------------
104 TParticlePDG *StarPrimaryMaker::pdg( Int_t id ){
105 
107 
108 }
109 // --------------------------------------------------------------------------------------------------------------
110 Int_t StarPrimaryMaker::Init()
111 {
112 
113  if ( 1 == IAttr("usestarsim") ) {
114  LOG_INFO << "Registered starsim callbacks" << endm;
116  }
117 
118 
119  //
120  // Initialize runtime flags
121  //
122  mDoBeamline = IAttr("beamline");
123 
124  // Vertex function
125  mVertexFunction = GetVertexFunction( SAttr("vertexDistribution") );
126 
127  //
128  // Initialize all submakers first
129  //
130  Int_t result = StMaker::Init();
131 
132  //
133  // The filter is properly a maker, so initialize it. Also create accepted event list.
134  // and add it as an object set.
135  //
136  if (mFilter) {
137  mFilter->Init();
138  mAccepted=new TEventList(mFilter->GetName(),"Accepted events");
139  }
140 
141  //
142  // Intialize the TTree with one event branch for each sub generator
143  // and one branch for the primary event
144  //
145  if ( mFileName == "" ) {
146  mFileName = ((StBFChain*)StMaker::GetTopChain())->GetFileOut();
147  mFileName.ReplaceAll(".root",".gener.root");
148  }
149 
150  mFile = TFile::Open( mFileName, "recreate" );
151  if ( !mFile ) result = (result<kStWarn)? kStWarn : result;
152 
153  mTree = new TTree( "genevents", "TTree containing event generator information" );
154 
155  mPrimaryEvent = new StarGenEvent("primaryEvent","Primary Event... particle-wise information from all event generators");
156  mTree->Branch("primaryEvent","StarGenEvent",&mPrimaryEvent,64000,99);
157 
158  if (mFilter) mFilter->SetEvent(mPrimaryEvent);
159 
160  TIter Next( GetMakeList() );
161  StarGenerator *generator = 0;
162  StMaker *_maker = 0;
163 
164  Int_t id = 0;
165 
166  while ( (_maker=(StMaker *)Next()) )
167  {
168 
169  //
170  // Dynamic cast to StarGenerator and punt if it's not one
171  //
172  generator = dynamic_cast<StarGenerator *>(_maker);
173  if ( !generator )
174  {
175  continue;
176  }
177 
178  // Set ID of the event generator
179  generator -> SetId( id++ );
180 
181 
182  //
183  // By default, connect generator to output tree. It the IO mode
184  // of the generator has been set, skip this step.
185  //
186  if ( generator->IOmode()==0 )
187  {
188  generator -> SetOutputTree( mTree );
189  }
190 
191  }
192 
193  return result;
194 }
195 // --------------------------------------------------------------------------------------------------------------
197 {
198 
199  // Calls finish on all sub makers to collect statisitcs
200  StMaker::Finish();
201 
202  // Now call finish on the filter
203  if ( mFilter ) {
204 
205  // Call finish on the generator
206  mFilter->Finish();
207 
208  mAccepted->Print("all");
209  mTree->SetEventList( mAccepted );
210  }
211 
212  if (mFile)
213  {
214 
215  // Add the instance of the particle data so we have a record of
216  // the particles used as input to the generator
217  TObjArray particles = StarParticleData::instance().GetParticles();
218  mTree->GetUserInfo()->Add( &particles );
219  // mTree->GetUserInfo()->Add( &(StarParticleData::instance().GetParticles()) );
220 
222 
223  TIter Next( GetMakeList() );
224  StarGenerator *generator = 0;
225  StMaker *_maker = 0;
226 
227  //Int_t id = 0;
228 
229  while ( (_maker=(StMaker *)Next()) )
230  {
231  generator = dynamic_cast<StarGenerator *>(_maker);
232  if ( !generator )
233  {
234  continue;
235  }
236  StarGenStats stats = generator->Stats();
237  if ( mFilter ) stats.nFilterSeen = mFilter->numberOfEvents();
238  if ( mFilter ) stats.nFilterAccept = mFilter->acceptedEvents();
239  stats.Dump();
240  stats.Write(); // write to fiel
241  }
242 
243  mFile -> Write();
244  mFile -> Close();
245  }
246  else
247  {
248  Warning(GetName(),"Could not write to unopened file");
249  }
250 
251 
252  return kStOK;
253 }
254 // --------------------------------------------------------------------------------------------------------------
256 {
257 
258  Bool_t go = true;
259 
260  while (go) {
261 
263  PreGenerate();
264 
266  Generate();
267 
269  PostGenerate();
270 
272  BuildTables();
273 
275  Finalize();
276 
278  if (mFilter)
279  {
280  mFilter->Make(); // properly this is a maker but we fake it here...
281  }
282 
284  if ( IAttr("Debug")==1 ) event()->Print("head");
285 
289  if ( event()->GetFilterResult() & ( StarGenEvent::kAccept | StarGenEvent::kFlag ) )
290  {
291 
292  //
293  // Increment the event number in the master event record
294  //
295  (*event())++;
296 
297  //
298  // Fill the TTree
299  //
300  mTree->Fill();
301 
302  //
303  // Add the event to the accepted event list
304  //
305  if ( mAccepted ) mAccepted->Enter( mTree->GetEntries() );
306 
307  // Break out of loop and accept event.
308  break;
309 
310  }
311 
316  if ( IAttr( "FilterKeepAll" ) == 0 ) mPrimaryEvent->Clear("part");
317  if ( IAttr( "FilterKeepAll" ) || IAttr( "FilterKeepHeader" ) ) mTree->Fill();
318  Clear();
319 
320  //
321  // If enabled, skip rejected events
322  //
323  if ( IAttr("FilterSkipRejects") ) return kStSKIP;
324 
325 
326  }// infinite loop
327 
328  return kStOK;
329 }
330 // --------------------------------------------------------------------------------------------------------------
331 // Intialize for this run
332 Int_t StarPrimaryMaker::InitRun( Int_t runnumber )
333 {
334  // Set the run number
335  mPrimaryEvent->SetRunNumber(runnumber);
336  mRunNumber = runnumber;
337 
338  mVertexFunction = GetVertexFunction( SAttr("vertexDistribution") );
339 
340  return StMaker::InitRun( runnumber );
341 }
342 
343 // --------------------------------------------------------------------------------------------------------------
344 void StarPrimaryMaker::Clear( const Option_t *opts )
345 {
346  mNumParticles = 0;
347  if ( mStack ) {
348  mStack->Clear();
349  }
350  if ( mPrimaryEvent ) {
351  mPrimaryEvent->Clear();
352  }
353  StMaker::Clear(opts);
354  TIter Next( GetMakeList() );
355  StarGenerator *generator = 0;
356  while ( (generator=(StarGenerator *)Next()) )
357  {
358  generator->Clear();
359  }
360 }
361 
362 // --------------------------------------------------------------------------------------------------------------
364 {
365  static Int_t id = 0;
366  gener->mId = ++id;
367  AddMaker(gener);
368 }
369 
371 {
372  mFilter = filter;
373  AddData( 0, ".filter" );
374  mFilter -> Shunt( GetDataSet( ".filter" ) );
375 }
376 // --------------------------------------------------------------------------------------------------------------
377 Int_t StarPrimaryMaker::PreGenerate()
378 {
379 
380  // Check for beamline constraint and load values
381  if ( mDoBeamline )
382  {
383  TDataSet* dbDataSet = GetChain()->GetDataBase("Calibrations/rhic/vertexSeed");
384  vertexSeed_st* vSeed = 0;
385  if ( dbDataSet )
386  {
387  vSeed = ((St_vertexSeed*) (dbDataSet->FindObject("vertexSeed")))->GetTable();
388  }
389  if ( vSeed ) {
390 
391  mVx = vSeed->x0;
392  mVy = vSeed->y0;
393  mVdxdz = vSeed->dxdz;
394  mVdydz = vSeed->dydz;
395  }
396  else {
397  LOG_WARN << "-- Beamline constraint requested but none seen in DB --" << endm;
398  }
399 
400  }
401 
402  if ( mDoBeamline )
403  LOG_INFO << Form("[%i]Beamline Parameters run=%i vx=%6.4f vy=%6.4f vz=%6.3f dxdz=%6.4f dydz=%6.4f",mDoBeamline,mRunNumber,mVx,mVy,mVz,mVdxdz,mVdydz) << endm;
404 
405 
406  TIter Next( GetMakeList() );
407  StarGenerator *generator = 0;
408  while ( (generator=(StarGenerator *)Next()) )
409  {
410  generator -> PreGenerateHook();
411  }
412 
413  return kStOK;
414 }
415 // --------------------------------------------------------------------------------------------------------------
416 Int_t StarPrimaryMaker::PostGenerate()
417 {
418 
419  TIter Next( GetMakeList() );
420  StarGenerator *generator = 0;
421  while ( (generator=(StarGenerator *)Next()) )
422  {
423  generator -> PostGenerateHook();
424  }
425 
426  return kStOK;
427 }
428 // --------------------------------------------------------------------------------------------------------------
429 Int_t StarPrimaryMaker::Generate()
430 {
431  TIter Next( GetMakeList() );
432  StarGenerator *generator = 0;
433  while ( (generator=(StarGenerator *)Next()) )
434  {
435 
436  // Generate the event with probability equal to the pileup
437  // probability
438  Double_t prob = generator -> GetPileup();
439  if ( StarRandom::Instance().flat() < prob )
440  generator -> Generate();
441 
442  // Accumulate total number of particles
443  mNumParticles += generator->GetNumberOfParticles();
444 
445  }
446  return kStOK;
447 }
448 // --------------------------------------------------------------------------------------------------------------
449 // --------------------------------------------------------------------------------------------------------------
450 // --------------------------------------------------------------------------------------------------------------
451 void StarPrimaryMaker::SetCuts( Double_t ptmin, Double_t ptmax,
452  Double_t ymin, Double_t ymax,
453  Double_t phimin, Double_t phimax,
454  Double_t zmin, Double_t zmax )
455 {
456 
457  LOG_INFO << "-- StarPrimaryMaker::SetCuts --" << " ptmin=" << ptmin << " ptmax=" << ptmax << endm;
458  LOG_INFO << "-- StarPrimaryMaker::SetCuts --" << " ymin=" << ymin << " ymax=" << ymax << endm;
459  LOG_INFO << "-- StarPrimaryMaker::SetCuts --" << " phimn=" << phimin << " phimx=" << phimax << endm;
460  LOG_INFO << "-- StarPrimaryMaker::SetCuts --" << " zmin=" << zmin << " zmax=" << zmax << endm;
461 
462  mPtMin = ptmin; mPtMax = ptmax;
463  mRapidityMin = ymin; mRapidityMax = ymax;
464  mPhiMin = phimin; mPhiMax = phimax;
465  mZMin = zmin; mZMax = zmax;
466 }
467 // --------------------------------------------------------------------------------------------------------------
468 // --------------------------------------------------------------------------------------------------------------
469 // --------------------------------------------------------------------------------------------------------------
471 {
472 
473  Bool_t go = particle->Simulate(); if (!go) return go;
474 
475  Double_t px = particle -> GetPx();
476  Double_t py = particle -> GetPy();
477  Double_t pz = particle -> GetPz();
478  Double_t pt = TMath::Sqrt(px*px + py*py);
479  TVector3 p( px, py, pz );
480 
481  // Check PT range
482  if ( pt < mPtMin ) return false;
483  if ( mPtMin < mPtMax )
484  {
485  if ( pt > mPtMax ) return false;
486  }
487 
488  if ( pt > 0 )
489  if ( mRapidityMin < mRapidityMax )
490  {
491  if ( p.Eta() < mRapidityMin ) return false;
492  if ( p.Eta() > mRapidityMax ) return false;
493  } // else, no cut
494 
495 
496  // Extend this ... add phi and z-vertex range cuts.
497 
498  return true;
499 
500 }
501 // --------------------------------------------------------------------------------------------------------------
502 // --------------------------------------------------------------------------------------------------------------
503 // --------------------------------------------------------------------------------------------------------------
504 Int_t StarPrimaryMaker::Finalize()
505 {
506 
507  TIter Next( GetMakeList() );
508  StarGenerator *generator = 0;
509  Int_t offset = 0;
510 
511  //
512  // Loop over all generators and call finalize on them.
513  //
514  while ( (generator=(StarGenerator *)Next()) )
515  {
516  generator -> Finalize();
517  }
518  Next.Reset();
519 
520  //
521  // Retrieve the particle_st table
522  //
523  St_particle *table = (St_particle*) GetDataSet("particle");
524  if ( !table )
525  {
526  //assert(!mNumParticles);
527  Error(GetName(),"No particle table found, but we have particles.");
528  return kStFatal;
529  }
530 
531  //
532  // Generate the primary vertex within allowed limits
533  //
534  TLorentzVector primary = mVertexFunction(); while ( primary.Z() < mZMin || primary.Z() > mZMax ) primary = mVertexFunction();
535 
536  mPrimaryVertex = primary;
537 
538  //
539  // Next loop over all generators and push their tracks onto the particle stack.
540  // Add them to the local event record and establish the connection between the
541  // particle index on the stack and the particle index in the event record.
542  //
543  Int_t nstack = 0;
544  while ( (generator=(StarGenerator *)Next()) )
545  {
546 
547  // Obtain the vertex for this event. If the generator is marked as
548  // pileup, sample a new vertex. Otherwise use the primary vertex
549  TLorentzVector vertex = (generator->IsPileup())? mVertexFunction() : primary;
550 
551  StarGenEvent *event = generator->Event();
552  Int_t npart = event->GetNumberOfParticles();
553 
554  // Set the offset on the event
555  event -> SetOffset( offset );
556 
557  // cout << "Pushing particles to particle stack" << endl;
558  // event->Print();
559 
560  Int_t ntrack; // set by stack
561  Int_t ndone = 0;
562 
563  for ( Int_t i=0; i<npart; i++ )
564  {
565 
566  StarGenParticle *particle = (*event)[i];
567  assert(particle);
568 
569  Int_t toDo = Simulate(particle); //particle->Simulate();
570 
571  Double_t px = particle->GetPx();
572  Double_t py = particle->GetPy();
573  Double_t pz = particle->GetPz();
574  Double_t E = particle->GetEnergy();
575  Double_t M = particle->GetMass();
576  Double_t vx = particle->GetVx() / 10; // mm --> cm as per the HEPEVT standard
577  Double_t vy = particle->GetVy() / 10; // mm --> cm
578  Double_t vz = particle->GetVz() / 10; // mm --> cm
579  Double_t vt = particle->GetTof() * mmOverC; // mm/c to s
580 
581  Double_t polx=0, poly=0, polz=0;
582 
583  Int_t parent = particle->GetFirstMother();
584  Int_t parent2 = particle->GetLastMother();
585  Int_t kid1 = particle->GetFirstDaughter();
586  Int_t kid2 = particle->GetLastDaughter();
587  Int_t id = particle->GetId();
588  Int_t status = particle->GetStatus();
589 
590  Double_t weight = 1.0;
591 
592  //
593  // Except for the first event, offset the particle's start vertex and update the
594  // particle ids
595  //
596  if ( i )
597  {
598 
599  // Offset z-vertex first so that we can apply the beamline
600  // constraint.
601  vz += vertex.Z();
602 
603  // Rotate the particle along the specified beamline
604  RotateBeamline( px, py, pz, E, M, vx, vy, vz, vt );
605 
606  // Smear the vertex in X, Y, and Z.
607  // NOTE: This is wrong, in the sense that we *should* measure the vertex
608  // distributions along the beam line. In practice, users give us
609  // the x,y and z distributions as measured in the STAR reference
610  // system. So long as dxdz and dydz are small, this should all be
611  // a good approximation.
612  vx += vertex.X();
613  vy += vertex.Y();
614  // vz was already offset
615  vt += vertex.T();
616 
617 
618  // Handle bookkeepting between event generators
619  parent += offset;
620  parent2 += offset;
621  kid1 += offset;
622  kid2 += offset;
623 
624  }
625 
626 
627 
628 
629  // Add the track to the particle stack and register the
630  // track number with the particle
631  mStack -> PushTrack( toDo, parent, id, px, py, pz, E, vx, vy, vz, vt, polx, poly, polz, kPNoProcess, ntrack, weight, status );
632  // particle->SetStack( ntrack ); //?????
633 
634  // Add the track to the g2t table iff it is pushed out to the simulator
635  if ( toDo ) table -> AddAt( particle->get_hepevt_address(), nstack );
636 
637  // Add it to the primary event record
638  StarGenParticle *p = mPrimaryEvent->AddParticle( status, id, parent, parent2, kid1, kid2, px, py, pz, E, M, vx, vy, vz, vt );
639 
640  // Associate this event record entry with the particle stack
641  p->SetIndex( particle -> GetIndex() );
642  // Set the primary key
643  p->SetPrimaryKey( i + offset );
644 
645  // If the particle is to be simulated, increment the stack ID
646  if ( toDo ) p->SetStack( 1 + nstack );
647  else p->SetStack( -1 );
648 
649  if ( toDo ) { nstack++; ndone++; }
650 
651  }
652 
653 
654  // Add the total number of particles
655  // (npart includes the 0th entry
656  // generator record).
657  offset += npart;
658 
659 
660  //
661  // Clear the generator's particle record so that only one
662  // such record appears for the user
663  //
664  event->Clear("part");
665 
666  }
667 
668  return kStOK;
669 }
670 
671 // --------------------------------------------------------------------------------------------------------------
672 void StarPrimaryMaker::BuildTables()
673 {
674 
675  // Loop over all generators and total the number of particles
676  TIter Next( GetMakeList() );
677  StarGenerator *generator = 0;
678  Int_t sum = 0;
679 
680  while ( (generator=(StarGenerator *)Next()) )
681  {
682  sum += generator -> Event() -> GetNumberOfParticles();
683  }
684  mNumParticles = sum;
685 
686  // Create g2t_event and g2t_particle tables for geant maker.
687  St_g2t_event *g2t_event = new St_g2t_event( "event", 1 );
688  AddData( g2t_event );
689  if ( mNumParticles ) {
690  St_particle *g2t_particle = new St_particle( "particle", mNumParticles );
691  AddData( g2t_particle );
692  }
693  // note: m_DataSet owns the new object(s) and is responsible for cleanup
694 
695 }
696 // --------------------------------------------------------------------------------------------------------------
697 void StarPrimaryMaker::RotateBeamline( Double_t &px, Double_t &py, Double_t &pz, Double_t &E, Double_t &M, Double_t &vx, Double_t &vy, Double_t &vz, Double_t &vt )
698 {
699 
700  // Unit vectors
701  static const TVector3 xhat(1,0,0), yhat(0,1,0), zhat(0,0,1);
702 
703  if ( mVdxdz == 0.0 && mVdydz == 0.0 ) return; // Nothing to do
704 
705  // Vertex position and momentum
706  TLorentzVector vertex(vx,vy,vz,vt);
707  TLorentzVector moment(px,py,pz,E);
708 
709  Double_t thetaX = TMath::ATan( mVdxdz );
710  Double_t thetaY = TMath::ATan( mVdydz );
711 
712  vertex.Rotate( -thetaY, xhat ); // - comes about because of the cross product, order of rotations, ...
713  vertex.Rotate( +thetaX, yhat );
714  moment.Rotate( -thetaY, xhat );
715  moment.Rotate( +thetaX, yhat );
716 
717  vx = vertex[0];
718  vy = vertex[1];
719  vz = vertex[2];
720  px = moment[0];
721  py = moment[1];
722  pz = moment[2];
723 
724 }
725 
726 
727 //_________________________________________________________________________________________
728 TLorentzVector StarPrimaryMaker::vertexGaussXYZ() {
729  double x=0,y=0,z=0,t=0;
730  TVector2 xy = StarRandom::Instance().gauss2d( mSx, mSy, mRho );
731  x = mVx + xy.X();
732  y = mVy + xy.Y();
733  z = mVz + StarRandom::Instance().gauss( mSz );
734  double dist = TMath::Sqrt(x*x+y*y+z*z);
735  t = dist / TMath::Ccgs();
736  return TLorentzVector(x,y,z,t);
737 };
738 //_________________________________________________________________________________________
739 TLorentzVector StarPrimaryMaker::vertexFlatZ() {
740  double x=0,y=0,z=0,t=0;
741  // Throw uniform between -sigmaZ and + sigmaZ (and etc...)
742  z = mVz - mSz + StarRandom::Instance().flat() * ( mSz * 2.0 );
743  x = mVx;
744  y = mVy;
745  double dist = TMath::Sqrt(x*x+y*y+z*z);
746  t = dist / TMath::Ccgs();
747  return TLorentzVector(x,y,z,t);
748 };
749 //_________________________________________________________________________________________
750 TLorentzVector StarPrimaryMaker::vertexFlatABZ() {
751  double x=0,y=0,z=0,t=0;
752  // Throw uniform between -sigmaZ and + sigmaZ (and etc...)
753  z = mVz - mSz + StarRandom::Instance().flat() * ( mSz * 2.0 );
754  double a = mSx;
755  double b = mSy;
756  while (true) {
757  // Sample uniformly in rectangle length 2a width 2b
758  x = ( StarRandom::Instance().flat() * 2 * a - a );
759  y = ( StarRandom::Instance().flat() * 2 * b - b );
760  // If point w/in perimeter of the elipse... accept the point
761  if ( (x/a)*(x/a) + (y/b)*(y/b) <= 1.0 ) break;
762  };
763  double dist = TMath::Sqrt(x*x+y*y+z*z);
764  t = dist / TMath::Ccgs();
765  TLorentzVector result(x,y,z,t);
766  result.RotateZ( mRho );
767  return result;
768  };
769 //_________________________________________________________________________________________
770 TLorentzVector StarPrimaryMaker::vertexFlatRZ() {
771  double x=0,y=0,z=0,t=0;
772  // Throw uniform between -sigmaZ and + sigmaZ (and etc...)
773  z = mVz - mSz + StarRandom::Instance().flat() * ( mSz * 2.0 );
774  double R = mSx;
775  double r = R * sqrt(StarRandom::Instance().flat());
776  double phi = 2.0 * TMath::Pi() * StarRandom::Instance().flat();
777  x = r * TMath::Cos(phi);
778  y = r * TMath::Sin(phi);
779  double dist = TMath::Sqrt(x*x+y*y+z*z);
780  t = dist / TMath::Ccgs();
781  TLorentzVector result(x,y,z,t);
782  return result;
783 };
784 //_________________________________________________________________________________________
785 TLorentzVector StarPrimaryMaker::vertexFlatXYZ() {
786  double x=0,y=0,z=0,t=0;
787  // Throw uniform between -sigmaZ and + sigmaZ (and etc...)
788  z = mVz - mSz + StarRandom::Instance().flat() * ( mSz * 2.0 );
789  x = mVx - mSx + StarRandom::Instance().flat() * ( mSx * 2.0 );
790  y = mVy - mSy + StarRandom::Instance().flat() * ( mSy * 2.0 );
791  double dist = TMath::Sqrt(x*x+y*y+z*z);
792  t = dist / TMath::Ccgs();
793  return TLorentzVector(x,y,z,t);
794 };
795 //_________________________________________________________________________________________
796 std::function<TLorentzVector()> StarPrimaryMaker::GetVertexFunction( const char* name ){
797  auto result = mVertexFunctionMap[ "gaussXYZ" ];
798  if ( mVertexFunctionMap.count(name) == 1 )
799  {
800  result = mVertexFunctionMap[ name ];
801  }
802  else {
803  LOG_WARN << "Vertex function " << name << " not defined. Defaulting to gaussian." << endm;
804  }
805  return result;
806 }
static TParticlePDG * pdg(Int_t pdgid)
Double_t gauss(const Double_t sigma) const
Return a random number distributed according to a gaussian with specified sigma.
Definition: StarRandom.cxx:72
TTree * mTree
The output tree.
Float_t GetVz()
Get the z-component of the start vertex.
Definition: FJcore.h:367
Bool_t Simulate(StarGenParticle *p)
Tests to see whether the particle passes all appropriate cuts to be passed to the simulator...
static StarRandom & Instance()
Obtain the single instance of the random number generator.
Definition: StarRandom.cxx:87
Bool_t IsPileup()
Returns true if this is a pileup generator.
Int_t IOmode()
Returns the ID of this event generator.
Definition: Stypes.h:48
virtual void AddData(TDataSet *data, const char *dir=".data")
User methods.
Definition: StMaker.cxx:332
Int_t GetNumberOfParticles()
Obtain the number of particles in the event record.
Definition: StarGenEvent.h:187
StarGenEvent * Event()
Retrieves the event record.
void Print(const Option_t *opts="head") const
Yet another particle class.
Int_t GetStatus()
Get the status code of the particle according to the HEPEVT standard.
Float_t GetTof()
Get the tof.
ABC for defining event generator interfaces.
Definition: StarGenerator.h:34
Float_t GetPz()
Get the z-component of the momentum.
void Clear(const Option_t *opts="")
Clear the event.
virtual void Clear(Option_t *option="")
User defined functions.
Definition: StMaker.cxx:634
Float_t GetEnergy()
Get the energy.
void SetIndex(Int_t i)
Set the line number in the event record.
void SetCuts(Double_t ptmin, Double_t ptmax=-1, Double_t ymin=0, Double_t ymax=-1, Double_t phimin=0, Double_t phimax=-1, Double_t zmin=-999, Double_t zmax=+999)
Set particle cuts.
virtual void Clear(const Option_t *opts="part,data")
Clear the event.
Int_t mNumParticles
Total number of particles.
virtual Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0)
Definition: TDataSet.cxx:893
static StarParticleData & instance()
Returns a reference to the single instance of this class.
TParticlePDG * GetParticle(const Char_t *name)
Get a particle by name.
Int_t GetId()
Get the id code of the particle according to the PDG standard.
static AgStarReader & Instance()
Return the single instance of this class.
Main filter class. Goes anywhere in the chain, filters StarGenEvent objects.
Interface to PDG information.
const TObjArray & GetParticles() const
Returns a reference to the list of particles.
void AddGenerator(StarGenerator *gener)
Int_t GetNumberOfParticles()
Returns the number of particles in the event.
Implementation of the VMC particle stack for use in STAR.
Double_t flat() const
Return a random number uniformly distributed between 0 and 1.
Definition: StarRandom.cxx:68
Float_t GetPx()
Get the x-component of the momentum.
End of run statistics for event generators.
Definition: StarGenStats.h:21
virtual TDataSet * Next() const
Definition: TDataSet.cxx:447
Int_t GetLastMother()
Get the last mother particle.
Float_t GetVy()
Get the y-component of the start vertex.
Float_t GetPy()
Get the y-component of the momentum.
Int_t GetFirstMother()
Get the first mother particle.
Base class for event records.
Definition: StarGenEvent.h:81
virtual const char * GetName() const
special overload
Definition: StMaker.cxx:237
Definition: Stypes.h:42
Float_t GetVx()
Get the x-component of the start vertex.
StarGenEvent * event()
Return a pointer to the event.
Int_t GetLastDaughter()
Get the last daughter particle.
Definition: Stypes.h:40
virtual StarGenStats Stats()
Create and retrieve end-of-run statistics.
virtual void AddAt(TDataSet *dataset, Int_t idx=0)
Definition: TDataSet.cxx:235
Main steering class for event generation.
Definition: AgUStep.h:26
virtual void Shunt(TDataSet *newParent=0)
Definition: TDataSet.cxx:810
virtual Int_t Finish()
Definition: StMaker.cxx:776
TVector2 gauss2d(const Double_t sx, const Double_t sy, const Double_t rho) const
Returns a pair of random numbers generated according to a 2D gaussian.
Definition: StarRandom.cxx:73
void RotateBeamline(Double_t &px, Double_t &py, Double_t &pz, Double_t &E, Double_t &M, Double_t &vx, Double_t &vy, Double_t &vz, Double_t &vt)
Float_t GetMass()
Get the mass.
Int_t GetFirstDaughter()
Get the first daughter particle.
void SetStack(StarParticleStack *stack)
Definition: AgStarReader.h:23
StarGenParticle * AddParticle()
virtual void Clear(const Option_t *opts="")
Clear the stack.
void SetRunNumber(Int_t run)
Set the run number for this event.
Definition: StarGenEvent.h:111
void AddFilter(StarFilterMaker *filt)