StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
AgStarReader.cxx
1 #include "AgStarReader.h"
2 ClassImp(AgStarReader);
3 
4 #include "StarCallf77.h"
5 #include "TDatabasePDG.h"
6 #include "TParticlePDG.h"
7 
8 #include "TLorentzVector.h"
9 #include <vector>
10 #include <map>
11 using namespace std;
12 
13 #include <cassert>
14 
15 #include "StarGenerator/UTIL/StarParticleData.h"
16 #include "StarGenerator/BASE/StarParticleStack.h"
17 
18 AgStarReader *AgStarReader::mInstance = 0;
19 
20 // TODO: Refactor TDatabasePDG to StarParticleData
21 
22 //
23 // Setup the interface with starsim and direct to geant3
24 //
25 #define ageventread F77_NAME(ageventread,AGEVENTREAD)
26 #define agsvert F77_NAME(agsvert, AGSVERT)
27 #define agskine F77_NAME(agskine, AGSKINE)
28 #define gskine F77_NAME(gskine, GSKINE)
29 #define gsvert F77_NAME(gsvert, GSVERT)
30 
31 // Comis routine for obtaining the address of common blocks
32 #define gcomad F77_NAME(gcomad,GCOMAD)
33 
34 extern "C" {
35  void type_of_call ageventread() { AgStarReader::Instance().ReadEvent(); }
36  void type_of_call agsvert( float *vertex, int *nb, int *nt, float *ubuf, int *nu, int *nv );
37  void type_of_call agskine( float *plab, int *ip, int *nv, float *ubuf, int *nb, int *nt );
38  void type_of_call gsvert( float *, int &, int &, float *, int &, int &);
39  void type_of_call gskine( float *, int &, int &, float *, int &, int &);
40  void type_of_call gcomad(DEFCHARD, int*& DEFCHARL);
41 };
42 
43 //
44 //----------GCTRAK ... normally I would rather poke my eye out rather than hardcode
45 // this... but this structure has existed w/in GEANT3 unchanged for 3 decades or so.
46 // Think we can get away with this here...
47 //
48 #define MAXMEC 30
49 typedef struct {
50  float vect[7];
51  float getot;
52  float gekin;
53  int vout[7];
54  int nmec;
55  int lmec[MAXMEC];
56  int namec[MAXMEC];
57  int nstep;
58  int maxnst;
59  float destep;
60  float destel;
61  float safety;
62  float sleng;
63  float step;
64  float snext;
65  float sfield;
66  float tofg;
67  float gekrat;
68  float upwght;
69  int ignext;
70  int inwvol;
71  int istop;
72  int igauto;
73  int iekbin;
74  int ilosl;
75  int imull;
76  int ingoto;
77  int nldown;
78  int nlevin;
79  int nlsav;
80  int istory;
81 } Gctrak_t;
82 
83 Gctrak_t* fGctrak = 0;
84 
85 
86 // ----------------------------------------------------------------------------------------------------
87 // ----------------------------------------------------------------------------------------------------
88 // ----------------------------------------------------------------------------------------------------
89 AgStarReader::AgStarReader() : TObject(), mStack(0), mParticleData(&StarParticleData::instance())
90 {
91 
92 }
93 // ----------------------------------------------------------------------------------------------------
94 //
95 // ----------------------------------------------------------------------------------------------------
97 {
98  if ( !mInstance ) {
99  mInstance = new AgStarReader();
100  gcomad(PASSCHARD("GCTRAK"),(int*&) fGctrak PASSCHARL("GCTRAK"));
101  }
102  return (*mInstance);
103 }
104 // ----------------------------------------------------------------------------------------------------
105 //
106 // ----------------------------------------------------------------------------------------------------
108 {
109 
110  TParticle *part = 0; // particle
111  int itrk = -1; // track number
112 
113  struct Vertex_t {
114  double x, y, z, t;
115  int idx;
116  };
117 
118  int idvtx = 0;
119  map<int, int> start_vtx;
120 
121  float* ubuf = 0;
122  int nwbuf=0;
123 
124  while( (part=mStack->PopNextTrack(itrk)) )
125  {
126 
127  // First check that the status of the particle is stable. If not,
128  // continue on to the next particle.
129  if ( part->GetStatusCode() != 1 ) continue;
130 
131  // Get the parent particle and lookup the vertex id
132  int parent = part->GetFirstMother();
133  int myvtx = start_vtx[parent];
134  if ( !myvtx )
135  {
136  start_vtx[parent]=++idvtx;
137 
138  // Build the vertex
139  float v[] = {
140  float(part->Vx()) ,
141  float(part->Vy()) ,
142  float(part->Vz())
143  };
144 
145  // Set the vertex of the track
146  {
147  int nt = 0;
148  int nb = 0;
149  gsvert(v, nt, nb, ubuf, nwbuf, myvtx);
150  assert(myvtx==idvtx);
151  }
152 
153  // Set time of flight
154  assert(fGctrak);
155  fGctrak->tofg = part->T();
156 
157  }
158 
159  // Now connect the particle to the vertex
160  float plab[] = {
161  float(part->Px()) ,
162  float(part->Py()) ,
163  float(part->Pz())
164  };
165 
166  int ipdg = part->GetPdgCode();
167  int g3id = 0;
168  {
169  TParticlePDG *pdg = mParticleData->GetParticle( ipdg ); assert(pdg);
170  g3id = pdg->TrackingCode();
171  if ( g3id < 1 )
172  {
173  Warning(GetName(),Form("Particle %s with PDG id=%i has no G3 code. Skipped.",pdg->GetName(),ipdg));
174  }
175  }
176 
177  // And add the particle
178  {
179  int nt = 0;
180  gskine( plab, g3id, myvtx, ubuf, nwbuf, nt );
181  }
182 
183  }
184 
185 }
186 // ----------------------------------------------------------------------------------------------------
187 //
188 // ----------------------------------------------------------------------------------------------------
189 void AgStarReader::SetVert( float *vertex, int ntbeam, int nttarg, float *ubuf, int nu, int &nv )
190 {
191  /* call */ agsvert( vertex, &ntbeam, &nttarg, ubuf, &nu, &nv );
192 }
193 // ----------------------------------------------------------------------------------------------------
194 //
195 // ----------------------------------------------------------------------------------------------------
196 void AgStarReader::SetKine( float *plab, int idpart, int nv, float *ubuf, int nb, int &nt )
197 {
198  /* call */ agskine( plab, &idpart, &nv, ubuf, &nb, &nt );
199 }
200 // ----------------------------------------------------------------------------------------------------
201 // ----------------------------------------------------------------------------------------------------
202 // ----------------------------------------------------------------------------------------------------
void ReadEvent()
Read events from the particle stack and push them out to starsim.
TParticlePDG * GetParticle(const Char_t *name)
Get a particle by name.
static AgStarReader & Instance()
Return the single instance of this class.
Interface to PDG information.
Pushes particles out from the StarParticleStack to geant3.
Definition: AgStarReader.h:15
virtual TParticle * PopNextTrack(Int_t &itrack)