StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StarGenerator.cxx
1 #include "StarGenerator.h"
2 ClassImp(StarGenerator);
3 #include "TClass.h"
4 #include "TTree.h"
5 
6 #include "StarGenerator/EVENT/StarGenParticle.h"
7 #include "TSystem.h"
8 
9 //TString altLib = "StarGeneratorPool";
10 
11 // ----------------------------------------------------------------------------
12 // ----------------------------------------------------------------------------
13 // ----------------------------------------------------------------------------
14 StarGenerator::StarGenerator( const Char_t *name )//, StarGenEvent *event )
15  : StMaker(name), mm(0.1), cm(1.0),
16  mId(0),
17  mNumberOfParticles(0),
18  mEvent(0),
19  mBlue("-"),
20  mYell("-"),
21  mFrame("CMS"),
22  mRootS(510.0),
23  mDirect(1.0),
24  mImpactMin(0.0),
25  mImpactMax(-1.0),
26  mBlueMomentum(0,0,+255,255.0),
27  mYellMomentum(0,0,-255,255.0),
28  mBlueMass(0),
29  mYellMass(0),
30  mIOMode(0),
31  mInputTree(0),
32  mOutputTree(0),
33  mIsPileup(false),
34  mPileup(1.0),
35  mParticleDb(0),
36  mLibrary("na")
37 {
38 
39  // mEvent = (event)? event : new StarGenEvent("default");
40  for ( Int_t i=0;i<4;i++ ) { mBlueMomentum[i]=0;
41  mYellMomentum[i]=0; }
42 
43  mParticleDb = &StarParticleData::instance();
44 
45  Clear();
46 
47 }
48 // ----------------------------------------------------------------------------
49 //
50 // ----------------------------------------------------------------------------
51 void StarGenerator::Clear(const Option_t *opts)
52 {
53  mNumberOfParticles=0;
54  if(mEvent) mEvent->Clear();
55 }
56 // ----------------------------------------------------------------------------
57 //
58 // ----------------------------------------------------------------------------
60 {
61  // Increment the event counter
62  ++(*mEvent);
63  return 1;
64 }
65 // ----------------------------------------------------------------------------
66 //
67 // ----------------------------------------------------------------------------
68 void StarGenerator::SetBlue( const Char_t *b )
69 {
70  mBlue=b;
71 }
72 // ----------------------------------------------------------------------------
73 //
74 // ----------------------------------------------------------------------------
75 void StarGenerator::SetYell( const Char_t *y )
76 {
77  mYell=y;
78 }
79 // ----------------------------------------------------------------------------
80 //
81 // ----------------------------------------------------------------------------
82 void StarGenerator::SetFrame( const Char_t *frame, const Double_t value )
83 {
84  mFrame=frame;
85  mFrame.ToUpper();
86  mRootS=TMath::Abs(value);
87  mDirect=value / mRootS; assert(mDirect==1.0 || mDirect==-1.0);
88 
89  if ( mFrame!="CMS" && mFrame != "FIXT" )
90  {
91  Error(GetName(),"This method only applies to CMS and FIXT frames");
92  }
93  assert(mFrame=="CMS"||mFrame=="FIXT");
94 
95 }
96 // ----------------------------------------------------------------------------
97 //
98 // ----------------------------------------------------------------------------
99 void StarGenerator::SetFrame( const Char_t *frame, const Double_t *pb, const Double_t *py )
100 {
101  mFrame=frame;
102  mFrame.ToUpper();
103  if ( !mFrame.Contains("MOM") )
104  {
105  Error(GetName(),"This method only applies to 3MOM, 4MOM or 5MOM frames");
106  }
107  assert(mFrame=="3MOM"||mFrame=="4MOM"||mFrame=="5MOM");
108 
109  Int_t n=3; if ( mFrame=="4MOM" ) n=4;
110  for ( Int_t i=0;i<n;i++ ) {
111  mBlueMomentum[i]=pb[i];
112  mYellMomentum[i]=py[i];
113  }
114  if (mFrame=="5MOM") {
115  mBlueMass=pb[4];
116  mYellMass=py[4];
117  }
118 
119  cout << "== SetFrame == " << endl;
120  mBlueMomentum.Print();
121  mYellMomentum.Print();
122  cout << "mBlue: "
123  << mBlueMomentum.X() << " "
124  << mBlueMomentum.Y() << " "
125  << mBlueMomentum.Z() << " "
126  << mBlueMomentum.T() << " " << endl;
127  cout << "mYell: "
128  << mYellMomentum.X() << " "
129  << mYellMomentum.Y() << " "
130  << mYellMomentum.Z() << " "
131  << mYellMomentum.T() << " " << endl;
132 
133 }
134 // ----------------------------------------------------------------------------
135 //
136 // ----------------------------------------------------------------------------
137 void StarGenerator::SetOutputTree( TTree *tree )
138 {
139  mOutputTree = tree;
140  mIOMode = 1;
141  TString bname = GetName();
142  TString bclass = mEvent->IsA()->GetName();
146  mOutputTree -> Branch( bname, bclass, &mEvent, 64000, 1 );
147 }
148 // ----------------------------------------------------------------------------
149 //
150 // ----------------------------------------------------------------------------
151 void StarGenerator::SetInputFile( const Char_t *filename, const Char_t *treename, const Char_t *branchname )
152 {
153  TFile *file = TFile::Open( filename, "read" );
154  if ( 0 == file )
155  {
156  LOG_WARN << "-- WARNING: root event file " << filename << " not found." << endm;
157  return;
158  }
159  TTree *tree = (TTree *)file->Get(treename);
160  if ( 0 == tree )
161  {
162  LOG_WARN << "-- WARNING: tree "<< treename<< " not found in " << filename << endm;
163  return;
164  }
165  SetInputTree(tree, branchname);
166 
167 };
168 // ----------------------------------------------------------------------------
169 //
170 // ----------------------------------------------------------------------------
171 void StarGenerator::SetInputTree( TTree *tree, const Char_t *name )
172 {
173  mInputTree = tree;
174  mIOMode = 2;
175  TString bname = mEvent->GetName();
176  if ( name )
177  {
178  bname = name;
179  }
180 
181  mInputTree -> SetBranchAddress( bname, &mEvent );
182  // TBranch *branch = mInputTree->GetBranch( bname );
183  // branch -> SetAddress( &mEvent );
184 
185  LOG_INFO << "Input Tree with " << tree -> GetEntries() << " loaded" << endm;
186 
187 }
188 // ----------------------------------------------------------------------------
189 //
190 // ----------------------------------------------------------------------------
191 Int_t StarGenerator::PreGenerateHook()
192 {
193 
194  // Always add a 0th line to the event, containing some (redundant) summary
195  // information:
196  //
197  Int_t status = -201; // Flag this as the event generator line
198  Int_t pdgid = 0; // Rootino
199 
200  //
201  // NOTE: PDG values for std model particles are obtained from PDG book.
202  // PDG values for heavy ions are calculated.
203  //
204 
205  Int_t mother1 = 0, kid1 = -1, mother2 = 0, kid2 = -1;
206 
208  //
209  // Extract out the blue beam and yellow beam PDG ids based on particle name.
210  //
211  TParticlePDG *blue = mParticleDb -> GetParticle( mBlue );
212  if ( blue ) {
213  mother1 = blue->PdgCode();
214  }
215  else {
216  // ADD PDG id
217  }
218 
219 
220  TParticlePDG *yell = mParticleDb -> GetParticle( mYell );
221  if ( yell ) {
222  mother2 = yell->PdgCode();
223  }
224  else {
225  // ADD PDG id
226  }
227  //
229 
231  //
232  // kid1 = the generator ID
233  // kid2 = the number of particles generated (set after PostGenerate())
234  //
236  kid1 = mId;
237 
238  Double_t px = mBlueMomentum.Px(); // variables illustrate the event record entry
239  Double_t py = mBlueMomentum.Py();
240  Double_t pz = mBlueMomentum.Pz();
241  Double_t E = mBlueMomentum.Energy();
242  Double_t M = mRootS;
243 
244  Double_t vx = mYellMomentum.Px();
245  Double_t vy = mYellMomentum.Py();
246  Double_t vz = mYellMomentum.Pz();
247  Double_t tof = mYellMomentum.Energy();
248 
249  mEvent -> AddParticle( status, pdgid, mother1, mother2, kid1, kid2, px, py, pz, E, M, vx, vy, vz, tof );
250 
251  //
252  // General event information
253  //
254  mEvent -> SetBlue( mother1 );
255  mEvent -> SetYell( mother2 );
256  mEvent -> SetRootS( mRootS );
257 
258 
259  return PreGenerate();
260 }
261 // ----------------------------------------------------------------------------
262 //
263 // ----------------------------------------------------------------------------
264 Int_t StarGenerator::PostGenerateHook()
265 {
266 
267  Int_t stat = PostGenerate();
268 
269  // Set the last daughter to be the number of particles generated in this event
270  Int_t kid2 = GetNumberOfParticles();
271  (*mEvent)[0]->SetLastDaughter( kid2 );
272 
273  return stat;
274 }
275 
Double_t mRootS
CMS energy or incident beam momentum for fixed target collisions.
Definition: FJcore.h:367
void SetOutputTree(TTree *tree)
TString mYell
Name of the yellow beam particle (-z)
void SetFrame(const Char_t *frame, const Double_t val)
TLorentzVector mYellMomentum
4-Momentum of the yellow beam
Int_t mIOMode
IO flag. 0=no IO, 1=write, 2=read.
ABC for defining event generator interfaces.
Definition: StarGenerator.h:34
void Clear(const Option_t *opts="")
Clear the event.
void SetInputTree(TTree *tree, const Char_t *bname=0)
StarGenEvent * mEvent
Generated event.
Definition: tof.h:15
virtual void Clear(const Option_t *opts="part,data")
Clear the event.
static StarParticleData & instance()
Returns a reference to the single instance of this class.
TTree * mOutputTree
Pointer to the tree for writing out events.
void SetBlue(const Char_t *b)
Sets the particle species for the blue beam.
Double_t mDirect
Direction (+1 = W, -1 = E) of the beam in fixted target mode.
Int_t GetNumberOfParticles()
Returns the number of particles in the event.
TLorentzVector mBlueMomentum
4-Momentum of the blue beam
virtual Int_t PostGenerate()
Developers may provide a post-generate method which will execute after Generate().
Definition: StarGenerator.h:59
TTree * mInputTree
Pointer to the tree for reading in events.
virtual const char * GetName() const
special overload
Definition: StMaker.cxx:237
Double_t mBlueMass
Mass of the blue beam.
void SetYell(const Char_t *y)
Sets the particle species for the yellow beam.
Double_t mYellMass
Mass of the yellow beam.
StarParticleData * mParticleDb
Database for particle information (based on TDatabasePDG)
TString mFrame
Frame of the collision, i.e. CMS, FIXT, 3MOM, 4MOM, 5MOM.
TString mBlue
Name of the blue beam particle (+z)
virtual Int_t PreGenerate()
Developers may provide a pre-generate method which will execute before Generate().
Definition: StarGenerator.h:57