// @(#)root/eg:$Id$
// Author: Pasha Murat   12/02/99

/*************************************************************************
 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

//______________________________________________________________________________
//
// Description of the static properties of a particle.
// The class is typically generated by the TDatabasePDG class.
// It is referenced by the dynamic particle class TParticle.
//  Int_t            fPdgCode;          // PDG code of the particle
//  Double_t         fMass;             // particle mass in GeV
//  Double_t         fCharge;           // charge in units of |e|/3
//  Double_t         fLifetime;         // proper lifetime in seconds
//  Double_t         fWidth;            // total width in GeV
//  Int_t            fParity;           // parity
//  Double_t         fSpin;             // spin
//  Double_t         fIsospin;          // isospin
//  Double_t         fI3;               // i3
//  Int_t            fStrangeness;      // flavours are defined if i3 != -1
//  Int_t            fCharm;            // 1 or -1 for C-particles,  0 for others
//  Int_t            fBeauty;
//  Int_t            fTop;
//  Int_t            fY;                // X,Y: quantum numbers for the 4-th generation
//  Int_t            fX;
//  Int_t            fStable;           // 1 if stable, 0 otherwise
//
//  TObjArray*       fDecayList;        // array of decay channels
//
//  TString          fParticleClass;    // lepton, meson etc
//
//  Int_t            fTrackingCode;     // G3 tracking code of the particle
//  TParticlePDG*    fAntiParticle;     // pointer to antiparticle

#include "TDecayChannel.h"
#include "TParticlePDG.h"
#include "TDatabasePDG.h"

ClassImp(TParticlePDG)

//______________________________________________________________________________
TParticlePDG::TParticlePDG()
{
   //default constructor
   fPdgCode      = 0;
   fMass         = 0;
   fCharge       = 0;
   fLifetime     = 0;
   fWidth        = 0;
   fParity       = 0;
   fSpin         = 0;
   fIsospin      = 0;
   fI3           = 0;
   fStrangeness  = 0;
   fCharm        = 0;
   fBeauty       = 0;
   fTop          = 0;
   fY            = 0;
   fX            = 0;
   fStable       = 0;
   fDecayList    = 0;
   fTrackingCode = 0;
   fAntiParticle = 0;
}

//______________________________________________________________________________
TParticlePDG::TParticlePDG(const char* Name, const char* Title, Double_t aMass,
                           Bool_t aStable, Double_t aWidth, Double_t aCharge,
                           const char* aParticleClass, Int_t aPdgCode, Int_t Anti,
                           Int_t aTrackingCode)
  : TNamed(Name,Title)
{

   // empty for the time  being
   fLifetime      = 0;
   fParity        = 0;
   fSpin          = 0;
   fIsospin       = 0;
   fI3            = 0;
   fStrangeness   = 0;
   fCharm         = 0;
   fBeauty        = 0;
   fTop           = 0;
   fY             = 0;
   fX             = 0;
   fStable        = 0;

   fMass          = aMass;
   fStable        = aStable;
   fWidth         = aWidth;
   fCharge        = aCharge;
   fParticleClass = aParticleClass;
   fPdgCode       = aPdgCode;
   fTrackingCode  = aTrackingCode;
   fDecayList     = NULL;
   if (Anti) fAntiParticle = this;
   else      fAntiParticle = 0;

   const Double_t kHbar = 6.58211889e-25; // GeV s
   if (fWidth != 0.) fLifetime = kHbar / fWidth;
}

//______________________________________________________________________________
TParticlePDG::TParticlePDG(const TParticlePDG& pdg) :
  TNamed(pdg),
  fPdgCode(pdg.fPdgCode),
  fMass(pdg.fMass),
  fCharge(pdg.fCharge),
  fLifetime(pdg.fLifetime),
  fWidth(pdg.fWidth),
  fParity(pdg.fParity),
  fSpin(pdg.fSpin),
  fIsospin(pdg.fIsospin),
  fI3(pdg.fI3),
  fStrangeness(pdg.fStrangeness),
  fCharm(pdg.fCharm),
  fBeauty(pdg.fBeauty),
  fTop(pdg.fTop),
  fY(pdg.fY),
  fX(pdg.fX),
  fStable(pdg.fStable),
  fDecayList(pdg.fDecayList),
  fParticleClass(pdg.fParticleClass),
  fTrackingCode(pdg.fTrackingCode),
  fAntiParticle(pdg.fAntiParticle)
{
   //copy constructor
}

//______________________________________________________________________________
TParticlePDG& TParticlePDG::operator=(const TParticlePDG& pdg)
{
   //assignement operator
   if(this!=&pdg) {
      TNamed::operator=(pdg);
      fPdgCode=pdg.fPdgCode;
      fMass=pdg.fMass;
      fCharge=pdg.fCharge;
      fLifetime=pdg.fLifetime;
      fWidth=pdg.fWidth;
      fParity=pdg.fParity;
      fSpin=pdg.fSpin;
      fIsospin=pdg.fIsospin;
      fI3=pdg.fI3;
      fStrangeness=pdg.fStrangeness;
      fCharm=pdg.fCharm;
      fBeauty=pdg.fBeauty;
      fTop=pdg.fTop;
      fY=pdg.fY;
      fX=pdg.fX;
      fStable=pdg.fStable;
      fDecayList=pdg.fDecayList;
      fParticleClass=pdg.fParticleClass;
      fTrackingCode=pdg.fTrackingCode;
      fAntiParticle=pdg.fAntiParticle;
   }
   return *this;
}

//______________________________________________________________________________
TParticlePDG::~TParticlePDG() {
   //destructor
   if (fDecayList) {
      fDecayList->Delete();
      delete fDecayList;
   }
}


//______________________________________________________________________________
Int_t TParticlePDG::AddDecayChannel(Int_t        Type,
                                    Double_t     BranchingRatio,
                                    Int_t        NDaughters,
                                    Int_t*       DaughterPdgCode)
{
   // add new decay channel, Particle owns those...

   Int_t n = NDecayChannels();
   if (NDecayChannels() == 0) {
      fDecayList = new TObjArray(5);
   }
   TDecayChannel* dc = new TDecayChannel(n,Type,BranchingRatio,NDaughters,
                                        DaughterPdgCode);
   fDecayList->Add(dc);
   return 0;
}

//_____________________________________________________________________________
TDecayChannel* TParticlePDG::DecayChannel(Int_t i)
{
   //return pointer to decay channel object at index i
   return (TDecayChannel*) fDecayList->At(i);
}

//_____________________________________________________________________________
void TParticlePDG::PrintDecayChannel(TDecayChannel* dc, Option_t* option) const
{
   //print the list of decays
   if (strstr(option,"banner")) {
                                // print banner

      printf(" Channel Code BranchingRatio Nd  ");
      printf(" ...................Daughters.................... \n");
   }
   if (strstr(option,"data")) {

      TDatabasePDG* db = TDatabasePDG::Instance();

      printf("%7i %5i %12.5e %5i  ",
           dc->Number(),
           dc->MatrixElementCode(),
           dc->BranchingRatio(),
           dc->NDaughters());

      for (int i=0; i<dc->NDaughters(); i++) {
         int ic = dc->DaughterPdgCode(i);
         TParticlePDG* p = db->GetParticle(ic);
         printf(" %15s(%8i)",p->GetName(),ic);
      }
      printf("\n");
   }
}


//______________________________________________________________________________
void TParticlePDG::Print(Option_t *) const
{
//
//  Print the entire information of this kind of particle
//

   printf("%-20s  %6d\t",GetName(),fPdgCode);
   if (!fStable) {
      printf("Mass:%9.4f Width (GeV):%11.4e\tCharge: %5.1f\n",
              fMass, fWidth, fCharge);
   } else {
      printf("Mass:%9.4f Width (GeV): Stable\tCharge: %5.1f\n",
              fMass, fCharge);
   }
   if (fDecayList) {
      int banner_printed = 0;
      TIter next(fDecayList);
      TDecayChannel* dc;
      while ((dc = (TDecayChannel*)next())) {
         if (! banner_printed) {
            PrintDecayChannel(dc,"banner");
            banner_printed = 1;
         }
         PrintDecayChannel(dc,"data");
      }
   }
}

 TParticlePDG.cxx:1
 TParticlePDG.cxx:2
 TParticlePDG.cxx:3
 TParticlePDG.cxx:4
 TParticlePDG.cxx:5
 TParticlePDG.cxx:6
 TParticlePDG.cxx:7
 TParticlePDG.cxx:8
 TParticlePDG.cxx:9
 TParticlePDG.cxx:10
 TParticlePDG.cxx:11
 TParticlePDG.cxx:12
 TParticlePDG.cxx:13
 TParticlePDG.cxx:14
 TParticlePDG.cxx:15
 TParticlePDG.cxx:16
 TParticlePDG.cxx:17
 TParticlePDG.cxx:18
 TParticlePDG.cxx:19
 TParticlePDG.cxx:20
 TParticlePDG.cxx:21
 TParticlePDG.cxx:22
 TParticlePDG.cxx:23
 TParticlePDG.cxx:24
 TParticlePDG.cxx:25
 TParticlePDG.cxx:26
 TParticlePDG.cxx:27
 TParticlePDG.cxx:28
 TParticlePDG.cxx:29
 TParticlePDG.cxx:30
 TParticlePDG.cxx:31
 TParticlePDG.cxx:32
 TParticlePDG.cxx:33
 TParticlePDG.cxx:34
 TParticlePDG.cxx:35
 TParticlePDG.cxx:36
 TParticlePDG.cxx:37
 TParticlePDG.cxx:38
 TParticlePDG.cxx:39
 TParticlePDG.cxx:40
 TParticlePDG.cxx:41
 TParticlePDG.cxx:42
 TParticlePDG.cxx:43
 TParticlePDG.cxx:44
 TParticlePDG.cxx:45
 TParticlePDG.cxx:46
 TParticlePDG.cxx:47
 TParticlePDG.cxx:48
 TParticlePDG.cxx:49
 TParticlePDG.cxx:50
 TParticlePDG.cxx:51
 TParticlePDG.cxx:52
 TParticlePDG.cxx:53
 TParticlePDG.cxx:54
 TParticlePDG.cxx:55
 TParticlePDG.cxx:56
 TParticlePDG.cxx:57
 TParticlePDG.cxx:58
 TParticlePDG.cxx:59
 TParticlePDG.cxx:60
 TParticlePDG.cxx:61
 TParticlePDG.cxx:62
 TParticlePDG.cxx:63
 TParticlePDG.cxx:64
 TParticlePDG.cxx:65
 TParticlePDG.cxx:66
 TParticlePDG.cxx:67
 TParticlePDG.cxx:68
 TParticlePDG.cxx:69
 TParticlePDG.cxx:70
 TParticlePDG.cxx:71
 TParticlePDG.cxx:72
 TParticlePDG.cxx:73
 TParticlePDG.cxx:74
 TParticlePDG.cxx:75
 TParticlePDG.cxx:76
 TParticlePDG.cxx:77
 TParticlePDG.cxx:78
 TParticlePDG.cxx:79
 TParticlePDG.cxx:80
 TParticlePDG.cxx:81
 TParticlePDG.cxx:82
 TParticlePDG.cxx:83
 TParticlePDG.cxx:84
 TParticlePDG.cxx:85
 TParticlePDG.cxx:86
 TParticlePDG.cxx:87
 TParticlePDG.cxx:88
 TParticlePDG.cxx:89
 TParticlePDG.cxx:90
 TParticlePDG.cxx:91
 TParticlePDG.cxx:92
 TParticlePDG.cxx:93
 TParticlePDG.cxx:94
 TParticlePDG.cxx:95
 TParticlePDG.cxx:96
 TParticlePDG.cxx:97
 TParticlePDG.cxx:98
 TParticlePDG.cxx:99
 TParticlePDG.cxx:100
 TParticlePDG.cxx:101
 TParticlePDG.cxx:102
 TParticlePDG.cxx:103
 TParticlePDG.cxx:104
 TParticlePDG.cxx:105
 TParticlePDG.cxx:106
 TParticlePDG.cxx:107
 TParticlePDG.cxx:108
 TParticlePDG.cxx:109
 TParticlePDG.cxx:110
 TParticlePDG.cxx:111
 TParticlePDG.cxx:112
 TParticlePDG.cxx:113
 TParticlePDG.cxx:114
 TParticlePDG.cxx:115
 TParticlePDG.cxx:116
 TParticlePDG.cxx:117
 TParticlePDG.cxx:118
 TParticlePDG.cxx:119
 TParticlePDG.cxx:120
 TParticlePDG.cxx:121
 TParticlePDG.cxx:122
 TParticlePDG.cxx:123
 TParticlePDG.cxx:124
 TParticlePDG.cxx:125
 TParticlePDG.cxx:126
 TParticlePDG.cxx:127
 TParticlePDG.cxx:128
 TParticlePDG.cxx:129
 TParticlePDG.cxx:130
 TParticlePDG.cxx:131
 TParticlePDG.cxx:132
 TParticlePDG.cxx:133
 TParticlePDG.cxx:134
 TParticlePDG.cxx:135
 TParticlePDG.cxx:136
 TParticlePDG.cxx:137
 TParticlePDG.cxx:138
 TParticlePDG.cxx:139
 TParticlePDG.cxx:140
 TParticlePDG.cxx:141
 TParticlePDG.cxx:142
 TParticlePDG.cxx:143
 TParticlePDG.cxx:144
 TParticlePDG.cxx:145
 TParticlePDG.cxx:146
 TParticlePDG.cxx:147
 TParticlePDG.cxx:148
 TParticlePDG.cxx:149
 TParticlePDG.cxx:150
 TParticlePDG.cxx:151
 TParticlePDG.cxx:152
 TParticlePDG.cxx:153
 TParticlePDG.cxx:154
 TParticlePDG.cxx:155
 TParticlePDG.cxx:156
 TParticlePDG.cxx:157
 TParticlePDG.cxx:158
 TParticlePDG.cxx:159
 TParticlePDG.cxx:160
 TParticlePDG.cxx:161
 TParticlePDG.cxx:162
 TParticlePDG.cxx:163
 TParticlePDG.cxx:164
 TParticlePDG.cxx:165
 TParticlePDG.cxx:166
 TParticlePDG.cxx:167
 TParticlePDG.cxx:168
 TParticlePDG.cxx:169
 TParticlePDG.cxx:170
 TParticlePDG.cxx:171
 TParticlePDG.cxx:172
 TParticlePDG.cxx:173
 TParticlePDG.cxx:174
 TParticlePDG.cxx:175
 TParticlePDG.cxx:176
 TParticlePDG.cxx:177
 TParticlePDG.cxx:178
 TParticlePDG.cxx:179
 TParticlePDG.cxx:180
 TParticlePDG.cxx:181
 TParticlePDG.cxx:182
 TParticlePDG.cxx:183
 TParticlePDG.cxx:184
 TParticlePDG.cxx:185
 TParticlePDG.cxx:186
 TParticlePDG.cxx:187
 TParticlePDG.cxx:188
 TParticlePDG.cxx:189
 TParticlePDG.cxx:190
 TParticlePDG.cxx:191
 TParticlePDG.cxx:192
 TParticlePDG.cxx:193
 TParticlePDG.cxx:194
 TParticlePDG.cxx:195
 TParticlePDG.cxx:196
 TParticlePDG.cxx:197
 TParticlePDG.cxx:198
 TParticlePDG.cxx:199
 TParticlePDG.cxx:200
 TParticlePDG.cxx:201
 TParticlePDG.cxx:202
 TParticlePDG.cxx:203
 TParticlePDG.cxx:204
 TParticlePDG.cxx:205
 TParticlePDG.cxx:206
 TParticlePDG.cxx:207
 TParticlePDG.cxx:208
 TParticlePDG.cxx:209
 TParticlePDG.cxx:210
 TParticlePDG.cxx:211
 TParticlePDG.cxx:212
 TParticlePDG.cxx:213
 TParticlePDG.cxx:214
 TParticlePDG.cxx:215
 TParticlePDG.cxx:216
 TParticlePDG.cxx:217
 TParticlePDG.cxx:218
 TParticlePDG.cxx:219
 TParticlePDG.cxx:220
 TParticlePDG.cxx:221
 TParticlePDG.cxx:222
 TParticlePDG.cxx:223
 TParticlePDG.cxx:224
 TParticlePDG.cxx:225
 TParticlePDG.cxx:226
 TParticlePDG.cxx:227
 TParticlePDG.cxx:228
 TParticlePDG.cxx:229
 TParticlePDG.cxx:230
 TParticlePDG.cxx:231
 TParticlePDG.cxx:232
 TParticlePDG.cxx:233
 TParticlePDG.cxx:234
 TParticlePDG.cxx:235
 TParticlePDG.cxx:236
 TParticlePDG.cxx:237
 TParticlePDG.cxx:238
 TParticlePDG.cxx:239
 TParticlePDG.cxx:240
 TParticlePDG.cxx:241
 TParticlePDG.cxx:242
 TParticlePDG.cxx:243
 TParticlePDG.cxx:244
 TParticlePDG.cxx:245
 TParticlePDG.cxx:246
 TParticlePDG.cxx:247
 TParticlePDG.cxx:248
 TParticlePDG.cxx:249
 TParticlePDG.cxx:250
 TParticlePDG.cxx:251
 TParticlePDG.cxx:252
 TParticlePDG.cxx:253
 TParticlePDG.cxx:254
 TParticlePDG.cxx:255
 TParticlePDG.cxx:256
 TParticlePDG.cxx:257
 TParticlePDG.cxx:258
 TParticlePDG.cxx:259