TParticle.cxx

Go to the documentation of this file.
00001 // @(#)root/eg:$Id: TParticle.cxx 30824 2009-10-22 05:32:45Z brun $
00002 // Author: Rene Brun , Federico Carminati  26/04/99
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 //______________________________________________________________________________
00013 //
00014 // a dynamic particle class created by event generators and used during
00015 // the propagation in detectors. The static attributes of a TParticle
00016 // are described by TParticlePDG.
00017 //
00018 //  Int_t          fPdgCode;              // PDG code of the particle
00019 //  Int_t          fStatusCode;           // generation status code
00020 //  Int_t          fMother[2];            // Indices of the mother particles
00021 //  Int_t          fDaughter[2];          // Indices of the daughter particles
00022 //  Float_t        fWeight;               // particle weight
00023 //
00024 //  Double_t       fCalcMass;             // Calculated mass
00025 //
00026 //  Double_t       fPx;                   // x component of momentum
00027 //  Double_t       fPy;                   // y component of momentum
00028 //  Double_t       fPz;                   // z component of momentum
00029 //  Double_t       fE;                    // Energy
00030 //
00031 //  Double_t       fVx;                   // x of production vertex
00032 //  Double_t       fVy;                   // y of production vertex
00033 //  Double_t       fVz;                   // z of production vertex
00034 //  Double_t       fVt;                   // t of production vertex
00035 //
00036 //  Double_t       fPolarTheta;           // Polar angle of polarisation
00037 //  Double_t       fPolarPhi;             // azymutal angle of polarisation
00038 //
00039 //  TParticlePDG*  fParticlePDG;          //! reference to the particle record in PDG database
00040 
00041 #include "TView.h"
00042 #include "TVirtualPad.h"
00043 #include "TPolyLine3D.h"
00044 #include "TParticlePDG.h"
00045 #include "TDatabasePDG.h"
00046 #include "TParticle.h"
00047 #include "TClass.h"
00048 #include "X3DBuffer.h"
00049 
00050 ClassImp(TParticle)
00051 
00052 //______________________________________________________________________________
00053 TParticle::TParticle() :
00054   fPdgCode(0), fStatusCode(0), fWeight(0),fCalcMass(0), fPx(0), fPy(0),
00055   fPz(0), fE(0), fVx(0), fVy(0), fVz(0), fVt(0), fPolarTheta(0), fPolarPhi(0)
00056 {
00057    //default constructor
00058    fMother[0]   = 0;
00059    fMother[1]   = 0;
00060    fDaughter[0] = 0;
00061    fDaughter[1] = 0;
00062    fParticlePDG = 0;
00063 }
00064 
00065 //______________________________________________________________________________
00066 TParticle::TParticle(Int_t pdg,       Int_t status,
00067                      Int_t mother1,   Int_t mother2,
00068                      Int_t daughter1, Int_t daughter2,
00069                      Double_t px, Double_t py, Double_t pz, Double_t etot,
00070                      Double_t vx, Double_t vy, Double_t vz, Double_t time):
00071   fPdgCode(pdg), fStatusCode(status), fWeight(1.),fPx(px), fPy(py),
00072   fPz(pz), fE(etot), fVx(vx), fVy(vy), fVz(vz), fVt(time)
00073 {
00074    //constructor
00075    fMother[0]   = mother1;
00076    fMother[1]   = mother2;
00077    fDaughter[0] = daughter1;
00078    fDaughter[1] = daughter2;
00079 
00080    SetPolarisation(0,0,0);
00081 
00082    SetPdgCode(pdg);
00083 }
00084 
00085 //______________________________________________________________________________
00086 TParticle::TParticle(Int_t pdg,       Int_t status,
00087                      Int_t mother1,   Int_t mother2,
00088                      Int_t daughter1, Int_t daughter2,
00089                      const TLorentzVector &p,
00090                      const TLorentzVector &v) :
00091   fPdgCode(pdg), fStatusCode(status), fWeight(1.),fPx(p.Px()), fPy(p.Py()),
00092   fPz(p.Pz()), fE(p.E()), fVx(v.X()), fVy(v.Y()), fVz(v.Z()), fVt(v.T())
00093 {
00094    //constructor
00095    fMother[0]   = mother1;
00096    fMother[1]   = mother2;
00097    fDaughter[0] = daughter1;
00098    fDaughter[1] = daughter2;
00099 
00100    SetPolarisation(0,0,0);
00101 
00102    SetPdgCode(pdg);
00103 }
00104 
00105 //______________________________________________________________________________
00106 TParticle::TParticle(const TParticle &p) :
00107   TObject(p), TAttLine(p), TAtt3D(p), fPdgCode(p.fPdgCode), fStatusCode(p.fStatusCode),
00108   fWeight(p.fWeight), fCalcMass(p.fCalcMass), fPx(p.fPx), fPy(p.fPy), fPz(p.fPz),
00109   fE(p.fE), fVx(p.fVx), fVy(p.fVy), fVz(p.fVz), fVt(p.fVt), fPolarTheta(p.fPolarTheta),
00110   fPolarPhi(p.fPolarPhi), fParticlePDG(p.fParticlePDG)
00111 {
00112    // copy constructor
00113 
00114    fMother[0]=p.fMother[0];
00115    fMother[1]=p.fMother[1];
00116    fDaughter[0]=p.fDaughter[0];
00117    fDaughter[1]=p.fDaughter[1];
00118 }
00119 
00120 //______________________________________________________________________________
00121 TParticle& TParticle::operator=(const TParticle &p)
00122 {
00123    // Equal operator
00124 
00125    if(this!=&p) {
00126       TObject::operator=(p);
00127       TAttLine::operator=(p);
00128       TAtt3D::operator=(p);
00129       fPdgCode=p.fPdgCode;
00130       fStatusCode=p.fStatusCode;
00131       fMother[0]=p.fMother[0];
00132       fMother[1]=p.fMother[1];
00133       fDaughter[0]=p.fDaughter[0];
00134       fDaughter[1]=p.fDaughter[1];
00135       fWeight=p.fWeight;
00136 
00137       fCalcMass=p.fCalcMass;
00138 
00139       fPx=p.fPx;
00140       fPy=p.fPy;
00141       fPz=p.fPz;
00142       fE=p.fE;
00143 
00144       fVx=p.fVx;
00145       fVy=p.fVy;
00146       fVz=p.fVz;
00147       fVt=p.fVt;
00148 
00149       fPolarTheta=p.fPolarTheta;
00150       fPolarPhi=p.fPolarPhi;
00151 
00152       fParticlePDG=p.fParticlePDG;
00153    }
00154    return   *this;
00155 }
00156 
00157 //______________________________________________________________________________
00158 TParticle::~TParticle()
00159 {
00160    //destructor
00161 }
00162 
00163 //______________________________________________________________________________
00164 Double_t TParticle::GetMass()
00165 {
00166    // Return nominal particle mass from PDG table.
00167    return GetPDG()->Mass();
00168 }
00169 
00170 //______________________________________________________________________________
00171 Int_t TParticle::Beauty()
00172 {
00173    // Return beauty quantum number.
00174    return GetPDG()->Beauty();
00175 }
00176 
00177 //______________________________________________________________________________
00178 Int_t TParticle::Charm()
00179 {
00180    // Return charm quantum number.
00181    return GetPDG()->Charm();
00182 }
00183 
00184 //______________________________________________________________________________
00185 Int_t TParticle::Strangeness()
00186 {
00187    // Return strangeness quantum number.
00188    return GetPDG()->Strangeness();
00189 }
00190 
00191 //______________________________________________________________________________
00192 Int_t TParticle::DistancetoPrimitive(Int_t px, Int_t py)
00193 {
00194 //*-*-*-*-*-*-*-*Compute distance from point px,py to a primary track*-*-*-*
00195 //*-*            ====================================================
00196 //*-*
00197 //*-*  Compute the closest distance of approach from point px,py to each segment
00198 //*-*  of a track.
00199 //*-*  The distance is computed in pixels units.
00200 //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
00201 
00202    const Int_t big = 9999;
00203    Float_t xv[3], xe[3], xndc[3];
00204    Float_t rmin[3], rmax[3];
00205    TView *view = gPad->GetView();
00206    if(!view) return big;
00207 
00208    // compute first and last point in pad coordinates
00209    Float_t pmom = this->P();
00210    if (pmom == 0) return big;
00211    view->GetRange(rmin,rmax);
00212    Float_t rbox = rmax[2];
00213    xv[0] = fVx;
00214    xv[1] = fVy;
00215    xv[2] = fVz;
00216    xe[0] = xv[0]+rbox*fPx/pmom;
00217    xe[1] = xv[1]+rbox*fPy/pmom;
00218    xe[2] = xv[2]+rbox*fPz/pmom;
00219    view->WCtoNDC(xv, xndc);
00220    Float_t x1 = xndc[0];
00221    Float_t y1 = xndc[1];
00222    view->WCtoNDC(xe, xndc);
00223    Float_t x2 = xndc[0];
00224    Float_t y2 = xndc[1];
00225 
00226    return DistancetoLine(px,py,x1,y1,x2,y2);
00227 }
00228 
00229 
00230 //______________________________________________________________________________
00231 void TParticle::ExecuteEvent(Int_t, Int_t, Int_t)
00232 {
00233 //*-*-*-*-*-*-*-*-*-*-*Execute action corresponding to one event*-*-*-*
00234 //*-*                  =========================================
00235 
00236    gPad->SetCursor(kPointer);
00237 }
00238 
00239 //______________________________________________________________________________
00240 const char* TParticle::GetName() const {
00241    //return particle name
00242    static char def[4] = "XXX";
00243    const TParticlePDG *ap = TDatabasePDG::Instance()->GetParticle(fPdgCode);
00244    if (ap) return ap->GetName();
00245    else    return def;
00246 }
00247 
00248 
00249 //______________________________________________________________________________
00250 TParticlePDG*  TParticle::GetPDG(Int_t mode)
00251 {
00252 // returns a pointer to the TParticlePDG object using the pdgcode
00253 // if mode == 0 (default) always get a fresh value for the pointer.
00254 // if mode != 0 this function returns directly the previously
00255 //              computed pointer from a previous call
00256 // One can use mode=1 (faster) when the TParticle object is not part of a
00257 // TClonesArray used in split mode in a Root TTree.
00258 
00259    if (!mode || !fParticlePDG) {
00260       (((TParticle*)this)->fParticlePDG = TDatabasePDG::Instance()->GetParticle(fPdgCode));
00261       // when mutable will be allowed, change above line to the following line
00262       //   fParticlePDG = TDatabasePDG::Instance()->GetParticle(fPdgCode);}
00263    }
00264    return fParticlePDG;
00265 }
00266 
00267 //______________________________________________________________________________
00268 void TParticle::GetPolarisation(TVector3 &v)
00269 {
00270    //return particle polarisation
00271    if(fPolarTheta == -99 && fPolarPhi == -99)
00272       //No polarisation to return
00273       v.SetXYZ(0.,0.,0.);
00274    else
00275       v.SetXYZ(TMath::Cos(fPolarPhi)*TMath::Sin(fPolarTheta),
00276                TMath::Sin(fPolarPhi)*TMath::Sin(fPolarTheta),
00277                TMath::Cos(fPolarTheta));
00278 }
00279 
00280 //______________________________________________________________________________
00281 const char *TParticle::GetTitle() const
00282 {
00283    //return particle title
00284    static char def[4] = "XXX";
00285    const TParticlePDG *ap = TDatabasePDG::Instance()->GetParticle(fPdgCode);
00286    if (ap) return ap->GetTitle();
00287    else    return def;
00288 }
00289 
00290 //______________________________________________________________________________
00291 void TParticle::Paint(Option_t *option)
00292 {
00293 //
00294 //  Paint a primary track
00295 //
00296    Float_t rmin[3], rmax[3];
00297    static TPolyLine3D *pline = 0;
00298    if (!pline) {
00299       pline = new TPolyLine3D(2);
00300    }
00301    Float_t pmom = this->P();
00302    if (pmom == 0) return;
00303    TView *view = gPad->GetView();
00304    if (!view) return;
00305    view->GetRange(rmin,rmax);
00306    Float_t rbox = rmax[2];
00307    pline->SetPoint(0,Vx(), Vy(), Vz());
00308    Float_t xend = Vx()+rbox*Px()/pmom;
00309    Float_t yend = Vy()+rbox*Py()/pmom;
00310    Float_t zend = Vz()+rbox*Pz()/pmom;
00311    pline->SetPoint(1, xend, yend, zend);
00312    pline->SetLineColor(GetLineColor());
00313    pline->SetLineStyle(GetLineStyle());
00314    pline->SetLineWidth(GetLineWidth());
00315    pline->Paint(option);
00316 }
00317 
00318 //______________________________________________________________________________
00319 void TParticle::Print(Option_t *) const
00320 {
00321 //
00322 //  Print the internals of the primary vertex particle
00323 //
00324    //TParticlePDG* pdg = ((TParticle*)this)->GetPDG();
00325    Printf("TParticle: %-13s  p: %8f %8f %8f Vertex: %8e %8e %8e %5d %5d",
00326           GetName(),Px(),Py(),Pz(),Vx(),Vy(),Vz(),
00327           fMother[0],fMother[1]);
00328 }
00329 
00330 //______________________________________________________________________________
00331 void TParticle::SetPdgCode(Int_t pdg)
00332 {
00333    //change the PDG code for this particle
00334    //Get a new pointer to a TParticlePDG from TDatabasePDG
00335    //Recompute the mass
00336 
00337    static Int_t nWarnings = 0;
00338    fPdgCode = pdg;
00339    fParticlePDG = TDatabasePDG::Instance()->GetParticle(pdg);
00340    if (fParticlePDG) {
00341       fCalcMass    = fParticlePDG->Mass();
00342    } else {
00343       if (nWarnings < 10) {
00344          Warning("SetPdgCode","PDG code %d unknown from TDatabasePDG",pdg);
00345          nWarnings++;
00346       }
00347       Double_t a2 = fE*fE -fPx*fPx -fPy*fPy -fPz*fPz;
00348       if (a2 >= 0) fCalcMass =  TMath::Sqrt(a2);
00349       else         fCalcMass = -TMath::Sqrt(-a2);
00350    }
00351 }
00352 
00353 //______________________________________________________________________________
00354 void TParticle::SetPolarisation(Double_t polx, Double_t poly, Double_t polz)
00355 {
00356    //set particle polarisation
00357    if(polx || poly || polz) {
00358       fPolarTheta = TMath::ACos(polz/TMath::Sqrt(polx*polx+poly*poly+polz*polz));
00359       fPolarPhi   = TMath::Pi()+TMath::ATan2(-poly,-polx);
00360    } else {
00361       fPolarTheta = -99;
00362       fPolarPhi = -99;
00363    }
00364 }
00365 
00366 //______________________________________________________________________________
00367 void TParticle::Sizeof3D() const
00368 {
00369 //*-*-*-*-*-*Return total X3D size of this primary*-*-*-*-*-*-*
00370 //*-*        =====================================
00371 
00372    Float_t pmom = this->P();
00373    if (pmom == 0) return;
00374    Int_t npoints = 2;
00375    gSize3D.numPoints += npoints;
00376    gSize3D.numSegs   += (npoints-1);
00377    gSize3D.numPolys  += 0;
00378 
00379 }
00380 
00381 //______________________________________________________________________________
00382 void TParticle::Streamer(TBuffer &R__b)
00383 {
00384    // Stream an object of class TParticle.
00385 
00386    if (R__b.IsReading()) {
00387       UInt_t R__s, R__c;
00388       Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
00389       if (R__v > 1) {
00390          R__b.ReadClassBuffer(TParticle::Class(), this, R__v, R__s, R__c);
00391          fParticlePDG = TDatabasePDG::Instance()->GetParticle(fPdgCode);
00392          return;
00393       }
00394       //====process old versions before automatic schema evolution
00395       TObject::Streamer(R__b);
00396       TAttLine::Streamer(R__b);
00397       R__b >> fPdgCode;
00398       R__b >> fStatusCode;
00399       R__b.ReadStaticArray(fMother);
00400       R__b.ReadStaticArray(fDaughter);
00401       R__b >> fWeight;
00402       R__b >> fCalcMass;
00403       R__b >> fPx;
00404       R__b >> fPy;
00405       R__b >> fPz;
00406       R__b >> fE;
00407       R__b >> fVx;
00408       R__b >> fVy;
00409       R__b >> fVz;
00410       R__b >> fVt;
00411       R__b >> fPolarTheta;
00412       R__b >> fPolarPhi;
00413       fParticlePDG = TDatabasePDG::Instance()->GetParticle(fPdgCode);
00414       R__b.CheckByteCount(R__s, R__c, TParticle::IsA());
00415       //====end of old versions
00416 
00417    } else {
00418       R__b.WriteClassBuffer(TParticle::Class(),this);
00419    }
00420 }

Generated on Tue Jul 5 14:45:15 2011 for ROOT_528-00b_version by  doxygen 1.5.1