<commit_before>// @(#)root/eg:$Name:  $:$Id: TDatabasePDG.cxx,v 1.11 2001/03/15 17:53:02 brun Exp $
// Author: <NAME>   12/02/99

#include "TROOT.h"
#include "TEnv.h"
#include "TSystem.h"
#include "TDatabasePDG.h"
#include "TDecayChannel.h"
#include "TParticlePDG.h"

#ifdef WIN32
#include <strstrea.h>
#else
#include <strstream.h>
#endif

////////////////////////////////////////////////////////////////////////
//
//  Particle database manager class
//
//  This manager creates a list of particles which by default is
//  initialised from with the constants used by PYTHIA6 (plus some
//  other particles added). See definition and the format of the default
//  particle list in $ROOTSYS/etc/pdg_table.txt
//
//  there are 2 ways of redefining the name of the file containing the
//  particle properties
//
//  1. one can define the name in .rootrc file:
//
//  Root.DatabasePDG: $(HOME)/my_pdg_table.txt
//
//  2. one can use TDatabasePDG::ReadPDGTable method explicitly:
//
//     - TDatabasePDG *pdg = new TDatabasePDG();
//     - pdg->ReadPDGtable(filename)
//
//  See TParticlePDG for the description of a static particle properties.
//  See TParticle    for the description of a dynamic particle particle.
//
////////////////////////////////////////////////////////////////////////

ClassImp(TDatabasePDG)

TDatabasePDG*  TDatabasePDG::fgInstance = 0;
//______________________________________________________________________________
TDatabasePDG::TDatabasePDG(): TNamed("PDGDB","The PDG particle data base")
{
  // Create PDG database. Initialization of the DB has to be done via explicit
  // call to ReadDataBasePDG (also done by GetParticle methods)

   fParticleList  = 0;
   fListOfClasses = 0;
   if (fgInstance) {
     Warning("TDatabasePDG", "object already instantiated");
   }
   else {
     fgInstance = this;
     gROOT->GetListOfSpecials()->Add(this);
   }
}

//______________________________________________________________________________
TDatabasePDG::~TDatabasePDG()
{
   // Cleanup the PDG database.

   if (fParticleList) {
      fParticleList->Delete();
      delete fParticleList;
   }
				// classes do not own particles...
   if (fListOfClasses) delete fListOfClasses;
   gROOT->GetListOfSpecials()->Remove(this);
   fgInstance = 0;
}

//______________________________________________________________________________
TDatabasePDG*  TDatabasePDG::Instance() 
{
   //static function 
  return (fgInstance) ? (TDatabasePDG*) fgInstance : new TDatabasePDG();
}


//______________________________________________________________________________
TParticlePDG* TDatabasePDG::AddParticle(const char *name, const char *title,
					Double_t mass, Bool_t stable,
					Double_t width, Double_t charge,
					const char* ParticleClass,
					Int_t PDGcode,
					Int_t Anti,
					Int_t TrackingCode)
{
  //
  //  Particle definition normal constructor. If the particle is set to be
  //  stable, the decay width parameter does have no meaning and can be set to
  //  any value. The parameters granularity, LowerCutOff and HighCutOff are
  //  used for the construction of the mean free path look up tables. The
  //  granularity will be the number of logwise energy points for which the
  //  mean free path will be calculated.
  //

  TParticlePDG* old = GetParticle(PDGcode);

  if (old) {
    printf(" *** TDatabasePDG::AddParticle: particle with PDGcode=%d already defined\n",PDGcode);
    return 0;
  }

  TParticlePDG* p = new TParticlePDG(name, title, mass, stable, width,
				     charge, ParticleClass, PDGcode, Anti,
				     TrackingCode);
  fParticleList->Add(p);

  TParticleClassPDG* pclass = GetParticleClass(ParticleClass);

  if (!pclass) {
    pclass = new TParticleClassPDG(ParticleClass);
    fListOfClasses->Add(pclass);
  }

  pclass->AddParticle(p);

  return p;
}

//______________________________________________________________________________
TParticlePDG* TDatabasePDG::AddAntiParticle(const char* Name, Int_t PdgCode)
{
  // assuming particle has already been defined

  TParticlePDG* old = GetParticle(PdgCode);

  if (old) {
    printf(" *** TDatabasePDG::AddAntiParticle: can't redefine parameters\n");
    return NULL;
  }

  Int_t pdg_code  = abs(PdgCode);
  TParticlePDG* p = GetParticle(pdg_code);

  TParticlePDG* ap = AddParticle(Name,
				 Name,
				 p->Mass(),
				 1,
				 p->Width(),
				 -p->Charge(),
				 p->ParticleClass(),
				 PdgCode,
				 1,
				 p->TrackingCode());
  return ap;
}


//______________________________________________________________________________
TParticlePDG *TDatabasePDG::GetParticle(const char *name) const
{
   //
   //  Get a pointer to the particle object according to the name given
   //

  if (fParticleList == 0)  ((TDatabasePDG*)this)->ReadPDGTable();

  TParticlePDG *def = (TParticlePDG *)fParticleList->FindObject(name);
//     if (!def) {
//        Error("GetParticle","No match for %s exists!",name);
//     }
   return def;
}

//______________________________________________________________________________
TParticlePDG *TDatabasePDG::GetParticle(Int_t PDGcode) const
{
   //
   //  Get a pointer to the particle object according to the MC code number
   //

  if (fParticleList == 0)  ((TDatabasePDG*)this)->ReadPDGTable();

   TIter next(fParticleList);
   TParticlePDG *p;
   while ((p = (TParticlePDG *)next())) {
      if (p->PdgCode() == PDGcode) return p;
   }
   //   Error("GetParticle","No match for PDG code %d exists!",PDGcode);
   return 0;
}

//______________________________________________________________________________
void TDatabasePDG::Print(Option_t *option) const<commit_msg>In TDatabasePDG::GetParticle, replace the TIter object by an explicit loop on all particles. This gives a huge gain in speed. A more important gain could be obtained in adding a TMap object in the class maintaining the association between a given PDG code and the corresponding particle.<commit_after>// @(#)root/eg:$Name:  $:$Id: TDatabasePDG.cxx,v 1.12 2001/05/17 06:45:55 brun Exp $
// Author: <NAME>   12/02/99

#include "TROOT.h"
#include "TEnv.h"
#include "TSystem.h"
#include "TDatabasePDG.h"
#include "TDecayChannel.h"
#include "TParticlePDG.h"

#ifdef WIN32
#include <strstrea.h>
#else
#include <strstream.h>
#endif

////////////////////////////////////////////////////////////////////////
//
//  Particle database manager class
//
//  This manager creates a list of particles which by default is
//  initialised from with the constants used by PYTHIA6 (plus some
//  other particles added). See definition and the format of the default
//  particle list in $ROOTSYS/etc/pdg_table.txt
//
//  there are 2 ways of redefining the name of the file containing the
//  particle properties
//
//  1. one can define the name in .rootrc file:
//
//  Root.DatabasePDG: $(HOME)/my_pdg_table.txt
//
//  2. one can use TDatabasePDG::ReadPDGTable method explicitly:
//
//     - TDatabasePDG *pdg = new TDatabasePDG();
//     - pdg->ReadPDGtable(filename)
//
//  See TParticlePDG for the description of a static particle properties.
//  See TParticle    for the description of a dynamic particle particle.
//
////////////////////////////////////////////////////////////////////////

ClassImp(TDatabasePDG)

TDatabasePDG*  TDatabasePDG::fgInstance = 0;
//______________________________________________________________________________
TDatabasePDG::TDatabasePDG(): TNamed("PDGDB","The PDG particle data base")
{
  // Create PDG database. Initialization of the DB has to be done via explicit
  // call to ReadDataBasePDG (also done by GetParticle methods)

   fParticleList  = 0;
   fListOfClasses = 0;
   if (fgInstance) {
     Warning("TDatabasePDG", "object already instantiated");
   }
   else {
     fgInstance = this;
     gROOT->GetListOfSpecials()->Add(this);
   }
}

//______________________________________________________________________________
TDatabasePDG::~TDatabasePDG()
{
   // Cleanup the PDG database.

   if (fParticleList) {
      fParticleList->Delete();
      delete fParticleList;
   }
				// classes do not own particles...
   if (fListOfClasses) delete fListOfClasses;
   gROOT->GetListOfSpecials()->Remove(this);
   fgInstance = 0;
}

//______________________________________________________________________________
TDatabasePDG*  TDatabasePDG::Instance() 
{
   //static function 
  return (fgInstance) ? (TDatabasePDG*) fgInstance : new TDatabasePDG();
}


//______________________________________________________________________________
TParticlePDG* TDatabasePDG::AddParticle(const char *name, const char *title,
					Double_t mass, Bool_t stable,
					Double_t width, Double_t charge,
					const char* ParticleClass,
					Int_t PDGcode,
					Int_t Anti,
					Int_t TrackingCode)
{
  //
  //  Particle definition normal constructor. If the particle is set to be
  //  stable, the decay width parameter does have no meaning and can be set to
  //  any value. The parameters granularity, LowerCutOff and HighCutOff are
  //  used for the construction of the mean free path look up tables. The
  //  granularity will be the number of logwise energy points for which the
  //  mean free path will be calculated.
  //

  TParticlePDG* old = GetParticle(PDGcode);

  if (old) {
    printf(" *** TDatabasePDG::AddParticle: particle with PDGcode=%d already defined\n",PDGcode);
    return 0;
  }

  TParticlePDG* p = new TParticlePDG(name, title, mass, stable, width,
				     charge, ParticleClass, PDGcode, Anti,
				     TrackingCode);
  fParticleList->Add(p);

  TParticleClassPDG* pclass = GetParticleClass(ParticleClass);

  if (!pclass) {
    pclass = new TParticleClassPDG(ParticleClass);
    fListOfClasses->Add(pclass);
  }

  pclass->AddParticle(p);

  return p;
}

//______________________________________________________________________________
TParticlePDG* TDatabasePDG::AddAntiParticle(const char* Name, Int_t PdgCode)
{
  // assuming particle has already been defined

  TParticlePDG* old = GetParticle(PdgCode);

  if (old) {
    printf(" *** TDatabasePDG::AddAntiParticle: can't redefine parameters\n");
    return NULL;
  }

  Int_t pdg_code  = abs(PdgCode);
  TParticlePDG* p = GetParticle(pdg_code);

  TParticlePDG* ap = AddParticle(Name,
				 Name,
				 p->Mass(),
				 1,
				 p->Width(),
				 -p->Charge(),
				 p->ParticleClass(),
				 PdgCode,
				 1,
				 p->TrackingCode());
  return ap;
}


//______________________________________________________________________________
TParticlePDG *TDatabasePDG::GetParticle(const char *name) const
{
   //
   //  Get a pointer to the particle object according to the name given
   //

  if (fParticleList == 0)  ((TDatabasePDG*)this)->ReadPDGTable();

  TParticlePDG *def = (TParticlePDG *)fParticleList->FindObject(name);
//     if (!def) {
//        Error("GetParticle","No match for %s exists!",name);
//     }
   return def;
}

//______________________________________________________________________________
TParticlePDG *TDatabasePDG::GetParticle(Int_t PDGcode) const
{
   //
   //  Get a pointer to the particle object according to the MC code number
   //

  if (fParticleList == 0)  ((TDatabasePDG*)this)->ReadPDGTable();

   TParticlePDG *p;
   TObjLink *lnk = fParticleList->FirstLink();
   while (lnk) {
      p = (TParticlePDG*)lnk->GetObject();
      if (p->PdgCode() == PDGcode) return p;
      lnk = lnk->Next();
   }
   //   Error("GetParticle","No match for PDG code %d exists!",PDGcode);
   return 0;
}

//______________________________________________________________________________
void TDatabasePDG::Print(Option_t *option) const
{'fraction_non_alphanumeric': 0.13048378706433153, 'fraction_numerical': 0.006762614877752731, 'mean_word_length': 3.3993135011441646, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 48, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6401956', 'n_tokens_mistral': 3661, 'n_tokens_neox': 3438, 'n_words': 970}