StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StarParticleData.cxx
1 #include "StarParticleData.h"
2 ClassImp(StarParticleData);
3 
4 #include "TDatabasePDG.h"
5 #include "TCollection.h"
6 #include "THashList.h"
7 #include "assert.h"
8 #include <iostream>
9 #include <map>
10 
11 #include "AgStarParticle.h"
12 
13 using namespace std;
14 
19 Int_t hid( Int_t z, Int_t a, Int_t l=0 )
20 {
21  // 10LZZZAAAI
22  return ( 1000000000
23  + 10000000*l
24  + 10000*z
25  + 10*a );
26 }
27 
28 
29 
30 
31 
32 
33 
34 
35 
36 // Functor class which converts PDG code to STAR definition.
38 public:
39  virtual Int_t operator()(Int_t pdgcode)=0;
40 };
42 public:
43  virtual Int_t operator()( Int_t ipdg )
44  {
45  int g3id = TDatabasePDG::Instance()->ConvertPdgToGeant3(ipdg);
46  if ( ipdg == 12 || ipdg == -12 ) g3id = 4; // nu_e
47  if ( ipdg == 14 || ipdg == -14 ) g3id = 4; // nu_mu
48  if ( ipdg == 16 || ipdg == -16 ) g3id = 4; // nu_tau
49  return g3id;
50  }
51 };
52 
53 // Instance should exist from the start
54 StarParticleData* StarParticleData::sInstance = nullptr;
55 
56 // ---------------------------------------------------------------------------------------------
57 StarParticleData::~StarParticleData()
58 {
59 
60 }
61 // ---------------------------------------------------------------------------------------------
62 StarParticleData::StarParticleData( const Char_t *_name, TDataSet *parent ) :
63  TObjectSet(_name)
64 {
65 
66 
67  if ( parent ) Shunt(parent);
68 
69  // Particle list will own the particles added to it, and is responsible for
70  // cleaning up their memory.
71  mParticleList.SetOwner();
72 
73  //
74  // Intiailze the particle data from TDatabasePDG
75  //
76  TDatabasePDG *pdg = TDatabasePDG::Instance();
77  pdg -> ReadPDGTable(); // because it's too much to expect from a singleton
78 
79 
80  //
81  // Iterate over all particles in the PDG database, and add them to the local list.
82  // Set the tracking code according to the G3 standard. TODO: Allow user to select
83  // differnt tracking code standard.
84  //
85  TIter Next( pdg->ParticleList() );
86 
87  G3TrackingCode G3ID;
88 
89  TParticlePDG *particle = 0;
90 
91  //Int_t g3new = 100;
92  while( (particle=(TParticlePDG *)Next()) )
93  {
94 
95  //
96  // Clone the particle and add in the tracking code, which maps the PDG ID to the ID
97  // used in the simulation package.
98  //
99  TString name = particle->GetName();
100  TString title = particle->GetTitle();
101  Double_t mass = particle->Mass();
102  Bool_t stable = particle->Stable();
103  Double_t width = particle->Width();
104  Double_t charge = particle->Charge();
105  TString class_ = particle->ParticleClass();
106 
107  Int_t code = particle->PdgCode();
108  Int_t anti = 0; if ( particle->AntiParticle() == particle ) anti = -code;
109 
110  Int_t g3id = G3ID( code );
111 
112  TParticlePDG *myparticle = new TParticlePDG( name, title, mass, stable, width, charge, class_, code, anti, g3id );
113 
114  mParticleList. Add( myparticle );
115  mParticleNameMap[ name ] = myparticle;
116  mParticleIdMap[ code ] = myparticle;
117  mParticleG3IdMap[ g3id ] = myparticle;
118 
119  }
120 
121 
122 
123  //
124  // Register the object array with the dataset
125  //
126  AddObject( &mParticleList, false );
127 
128  //
129  // Create aliases for typical beam particles to handle differences
130  // between event generator names and TDatabasePDG names... shouldn't
131  // need e+ or pbar, but who knows...
132  //
133  AddAlias("electron", "e-");
134  AddAlias("positron", "e+");
135  AddAlias("p", "proton");
136  AddAlias("pbar", "antiproton");
137 
138  //
139  // Next create typical heavy ions used in beams at RHIC... "hid" is defined
140  // to help define PDG ids for the heavy ions
141  //
142 
143  TParticlePDG *D = new TParticlePDG( "D", "Deuteron", /* mass */ 0.0, true, 0., 1.0, "heavyion", hid(1,2,0), 0, 45 );
144  TParticlePDG *He3 = new TParticlePDG( "He3", "Helium-3", /* mass */ 0.0, true, 0., 2.0, "heavyion", hid(2,1,0), 0, 49 );
145  TParticlePDG *Cu = new TParticlePDG( "Cu", "Copper", /* mass */ 0.0, true, 0., 29, "heavyion", hid(29,64,0), 0, 0 );
146  TParticlePDG *Au = new TParticlePDG( "Au", "Gold", /* mass */ 0.0, true, 0., 79, "heavyion", hid(79,197,0), 0, 0 );
147  TParticlePDG *U = new TParticlePDG( "U", "Uranium", /* mass */ 0.0, true, 0., 92, "heavyion", hid(92,238,0), 0, 0 );
148 
149  AddParticle("D", D);
150  AddParticle("He3", He3);
151  AddParticle("Cu", Cu);
152  AddParticle("Au", Au);
153  AddParticle("U", U);
154 
155  //
156  // TODO: Add in the hypertriton and its antiparticles
157  //
158 
159 #undef hid
160 
161 
162 
163 }
164 // ---------------------------------------------------------------------------------------------
165 //
166 // ---------------------------------------------------------------------------------------------
167 TParticlePDG *StarParticleData::GetParticle( const Char_t *name )
168 {
169  return mParticleNameMap[ name ];
170 }
171 // ---------------------------------------------------------------------------------------------
172 //
173 // ---------------------------------------------------------------------------------------------
174 TParticlePDG *StarParticleData::GetParticle( const Int_t id )
175 {
176  return mParticleIdMap[id];
177 }
178 TParticlePDG *StarParticleData::GetParticleG3( const Int_t id )
179 {
180  return mParticleG3IdMap[id];
181 }
182 // ---------------------------------------------------------------------------------------------
183 //
184 // ---------------------------------------------------------------------------------------------
185 void StarParticleData::AddParticle( const Char_t *name, TParticlePDG *particle )
186 {
187  Int_t code = particle->PdgCode();
188  mParticleList.Add( particle );
189  if ( mParticleNameMap[ name ] ) { Warning( "AddParticle()", Form("Overwriting entry %s",name) ); }
190  mParticleNameMap[ name ] = particle;
191  if ( mParticleIdMap[ code ] ) { Warning( "AddParticle()", Form("Overwriting entry %i",code) ); }
192  mParticleIdMap[code] = particle;
193  G3TrackingCode G3ID;
194  mParticleG3IdMap[ G3ID(code) ] = particle;
195  return;
196 }
197 // ---------------------------------------------------------------------------------------------
198 //
199 // ---------------------------------------------------------------------------------------------
200 
201 // ---------------------------------------------------------------------------------------------
202 //
203 // ---------------------------------------------------------------------------------------------
204 TParticlePDG *StarParticleData::AddParticle( const Char_t *name, const Char_t *title, Double_t mass,
205 Bool_t stable, Double_t width, Double_t charge3, const char* particleClass, Int_t PdgCode, Int_t Anti, Int_t geantCode )
206 {
207  // Create the particle
208  TParticlePDG *part = new TParticlePDG(name,title,mass,stable,width,charge3,particleClass,PdgCode,Anti,geantCode);
209  // Register the particle
210  AddParticle( name, part );
211  // And return a pointer to it
212  return part;
213 }
214 // ---------------------------------------------------------------------------------------------
215 //
216 // ---------------------------------------------------------------------------------------------
217 TParticlePDG *StarParticleData::AddParticleToG3( TParticlePDG *part, int g3code )
218 {
219  TString name = part->GetName();
220  TString type = part->ParticleClass();
221  type.ToLower();
222  double mass = part->Mass();
223  double life = part->Lifetime();
224  double charge = part->Charge() / 3.0;
225  int pdgcode = part->PdgCode();
226 
227  int tracktype = 0;
228  if ( type.Contains("meson") || type.Contains("baryon") || type.Contains("hadron") )
229  {
230  if ( charge == 0 ) tracktype = AgStarParticle::kGtNeut;
231  else tracktype = AgStarParticle::kGtHadr;
232  }
233  if ( type.Contains("photon") || type.Contains("gamma") )
234  {
235  tracktype = AgStarParticle::kGtGama;
236  }
237  if ( type.Contains("lepton") )
238  {
239  if ( charge == 0 ) tracktype = AgStarParticle::kGtNeut;
240  else tracktype = AgStarParticle::kGtHadr;
241  }
242  if ( name == "e-" || name == "e+" )
243  {
244  tracktype = AgStarParticle::kGtElec;
245  }
246  if ( name == "mu-" || name == "mu+" )
247  {
248  tracktype = AgStarParticle::kGtMuon;
249  }
250  if ( type.Contains("heavyion") )
251  {
252  tracktype = AgStarParticle::kGtHion;
253  }
254 
255  return AddParticleToG3( name.Data(), mass, life, charge, tracktype, pdgcode, g3code );
256 
257 
258 }
259 // ---------------------------------------------------------------------------------------------
260 //
261 // ---------------------------------------------------------------------------------------------
262 TParticlePDG *StarParticleData::AddParticleToG3( const char* name,
263  const double mass,
264  const double lifetime,
265  const double charge,
266  const int type,
267  const int pdgcode,
268  const int g3code,
269  const double *bratio,
270  const int *mode
271 
272 
273  )
274 {
275 
276  static std::map< int, TString > ParticleClass =
277  {
278  { 1, "Photon" },
279  { 2, "Leptom" },
280  { 3, "Hadron" },
281  { 4, "Hadron" },
282  { 5, "Lepton" },
283  { 6, "Geantino" },
284  { 7, "Cherenkov" },
285  { 8, "Heavyion" },
286  { 9, "Monopole" }
287  };
288 
289  const double kHbar = 6.58211889e-25; // GeV s
290  double width = (lifetime > 0 )? kHbar / lifetime : 0.;
291  double charge3 = 3*charge;
292 
293  bool stable = (lifetime<=0);
294 
295  TParticlePDG *part = AddParticle( name, Form("%s [geant3 id=%i]",name,g3code), mass, stable, width, charge3, ParticleClass[type], pdgcode, 0, g3code );
297 
299  float fbratio[6];
300  if ( bratio ) { for ( int i=0;i<6;i++ ) fbratio[i] = bratio[i];
301  AgStarParticle::Add( name, g3code, type, float(mass), float(charge), float(lifetime), fbratio, mode, pdgcode );
302  }
303  else {
304  AgStarParticle::Add( name, g3code, type, float(mass), float(charge), float(lifetime), 0, 0, pdgcode );
305  }
306 
307  TParticlePDG *myparticle = part;
308  mParticleList. Add( myparticle );
309  mParticleNameMap[ name ] = myparticle;
310  mParticleIdMap[ pdgcode ] = myparticle;
311  mParticleG3IdMap[ g3code ] = myparticle;
312 
313  return part;
314 
315 }
316 
317 // ---------------------------------------------------------------------------------------------
318 //
319 // ---------------------------------------------------------------------------------------------
320 void StarParticleData::AddAlias( const Char_t *alias, const Char_t *name )
321 {
322  TParticlePDG *particle = GetParticle(name);
323  AddParticle( alias, particle );
324 }
325 // ---------------------------------------------------------------------------------------------
326 //
327 // ---------------------------------------------------------------------------------------------
328 TParticlePDG *StarParticleData::SetTrackingCode( const int pdgid, const int g3id )
329 {
330  TParticlePDG *particle = GetParticle(pdgid);
331 
332  TString name = particle->GetName();
333  TString title = particle->GetTitle();
334  double mass = particle->Mass();
335  bool stable = particle->Stable();
336  double width = particle->Width();
337  double charge = particle->Charge();
338  TString class_ = particle->ParticleClass();
339 
340  int code = particle->PdgCode();
341  int anti = 0; if ( particle->AntiParticle() == particle ) anti = -code;
342 
343  TParticlePDG *myparticle = new TParticlePDG( name, title, mass, stable, width, charge, class_, code, anti, g3id );
344 
345  mParticleList. Add( myparticle );
346  mParticleNameMap[ name ] = myparticle;
347  mParticleIdMap[ code ] = myparticle;
348  mParticleG3IdMap[ g3id ] = myparticle;
349 
350  return myparticle;
351 
352 }
353 //_______________________________________________________________________________________________
355 { return (sInstance)? *sInstance : *(sInstance = new StarParticleData()); }
356 //_______________________________________________________________________________________________
357 TParticlePDG* StarParticleData::operator()(const char* name){ return instance().GetParticle(name); }
358 TParticlePDG* StarParticleData::operator()(const int id ){ return instance().GetParticle(id ); }
359 //_______________________________________________________________________________________________
360 
361 
TParticlePDG * GetParticleG3(const Int_t id)
Get a particle by G3 ID.
void AddAlias(const Char_t *alias, const Char_t *realname)
Add an alias to a particle in the database.
static StarParticleData & instance()
Returns a reference to the single instance of this class.
static void Add(const char *name, const int g3id, const int type, const float mass, const float charge, const float lifetime=0., const float *bratio=0, const int *mode=0, const int pdgid=0)
TParticlePDG * GetParticle(const Char_t *name)
Get a particle by name.
Interface to PDG information.
void AddParticle(const Char_t *name, TParticlePDG *particle)
Add a particle to the database.
TParticlePDG * SetTrackingCode(const int pdgid, const int g3id)
Maps the particle with the given PDG id to G3 tracking ID and returns pointer to the particle data...
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)