MyParticle.cxx

Go to the documentation of this file.
00001 // Author: Bertrand Bellenot   22/08/02
00002 
00003 /*************************************************************************
00004  * Copyright (C) 1995-2002, Bertrand Bellenot.                           *
00005  * All rights reserved.                                                  *
00006  *                                                                       *
00007  * For the licensing terms see the LICENSE file.                         *
00008  *************************************************************************/
00009 
00010 #include <stdlib.h>
00011 
00012 #include <TSystem.h>
00013 #include <TRandom.h>
00014 #include <TParticle.h>
00015 #include "MyParticle.h"
00016 #include "TVector3.h"
00017 #include "constants.h"
00018 #include "RootShower.h"
00019 #include "ParticlesDef.h"
00020 
00021 //______________________________________________________________________________
00022 //
00023 // MyParticle class implementation
00024 //______________________________________________________________________________
00025 
00026 ClassImp(MyParticle)
00027 
00028 //______________________________________________________________________________
00029 MyParticle::MyParticle() : TParticle()
00030 {
00031    // MyParticle constructor.
00032 
00033    // initialize members to zero
00034    fStatus = 0;
00035    fNChildren = 0;
00036    fDecayType = UNDEFINE;
00037    fLocation = new TVector3();
00038    fPassed = 0.0;
00039    fEloss = 0.0;
00040    fDecayLength = 0.0;
00041    fChild[0] = 0;
00042    fChild[1] = 0;
00043    fChild[2] = 0;
00044    fChild[3] = 0;
00045    fChild[4] = 0;
00046    fChild[5] = 0;
00047    fTimeOfDecay = 0.0;
00048    fTracks = new TObjArray(1);
00049    fNtrack = 0;
00050 }
00051 
00052 //______________________________________________________________________________
00053 MyParticle::MyParticle(Int_t id, Int_t pType,Int_t pStat,Int_t pDecayType,const TVector3 &pLocation,
00054                        const TVector3 &pMomentum,Double_t pPassed, Double_t pDecayLen, 
00055                        Double_t pEnergy)
00056           : TParticle(pType, pStat, 1, 0, 0, 0, pMomentum.x(), pMomentum.y(), 
00057                         pMomentum.z(), pEnergy, pLocation.x(), pLocation.y(), 
00058                         pLocation.z(), 0.0)
00059 {
00060    // MyParticle constructor.
00061 
00062    // initialize members with parameters passed in argument
00063    fId = id;
00064    fStatus = pStat;
00065    fNChildren = 0;
00066    fDecayType = pDecayType;
00067    fLocation = new TVector3(pLocation);
00068    fPassed = pPassed;
00069    fDecayLength = pDecayLen;
00070    fChild[0] = 0;
00071    fChild[1] = 0;
00072    fChild[2] = 0;
00073    fChild[3] = 0;
00074    fChild[4] = 0;
00075    fChild[5] = 0;
00076    fTimeOfDecay = 0.0;
00077    fTracks = new TObjArray(1);
00078    fNtrack = 0;
00079 }
00080 
00081 //______________________________________________________________________________
00082 MyParticle::MyParticle(Int_t id, Int_t pType,Int_t pStat,Int_t pDecayType,const TVector3 &pLocation,
00083                        const TVector3 &pMomentum)
00084           : TParticle(pType, pStat, 1, 0, 0, 0, pMomentum.x(), pMomentum.y(), 
00085                         pMomentum.z(), 0.0, pLocation.x(), pLocation.y(),
00086                         pLocation.z(), 0.0)
00087 {
00088    // MyParticle constructor.
00089 
00090    // initialize members with parameters passed in argument
00091    fId = id;
00092    Double_t energy;
00093    fStatus = pStat;
00094    fNChildren = 0;
00095    fDecayType = pDecayType;
00096    fLocation = new TVector3(pLocation);
00097    fPassed = 0.0;
00098    fEloss = 0.0;
00099    fDecayLength = 0.0;
00100    fChild[0] = 0;
00101    fChild[1] = 0;
00102    fChild[2] = 0;
00103    fChild[3] = 0;
00104    fChild[4] = 0;
00105    fChild[5] = 0;
00106    if (GetMass() == 0.0)
00107       energy = pMomentum.Mag();
00108    else
00109       energy = TMath::Sqrt((pMomentum * pMomentum)
00110                +  (GetMass() * GetMass()));
00111    TParticle::SetMomentum(pMomentum.x(),pMomentum.y(),pMomentum.z(),energy);
00112    fTimeOfDecay = 0.0;
00113    fTracks = new TObjArray(1);
00114    fNtrack = 0;
00115 }
00116 
00117 //______________________________________________________________________________
00118 char *MyParticle::GetObjectInfo(Int_t, Int_t) const
00119 {
00120    // Returns particle informations.
00121 
00122    static char info[64];
00123    sprintf(info,"Particle = %s, E = %1.3e", GetName(), Energy());
00124    return info;
00125 }
00126 
00127 //______________________________________________________________________________
00128 void MyParticle::SetMoment(const TVector3 &mom)
00129 {
00130    // Set particle momentum with TVector3 members
00131 
00132    Double_t energy;
00133    if (GetMass() == 0.0)
00134       energy = mom.Mag();
00135    else
00136       energy = TMath::Sqrt((mom * mom) +  (GetMass() * GetMass()));
00137    SetMomentum(mom.x(), mom.y(), mom.z(), energy);
00138 }
00139 
00140 //______________________________________________________________________________
00141 void MyParticle::GenerateTimeOfDecay()
00142 {
00143    // Generates time of decay for this type of particle.
00144 
00145    Int_t i;
00146    fTimeOfDecay = (GetPDG()->Lifetime() > 0 && GetPDG()->Lifetime() < 1e8)
00147                    ? gRandom->Exp(GetPDG()->Lifetime())
00148                    : GetPDG()->Lifetime();
00149    if (fTimeOfDecay == 0.0) {
00150       Int_t my_code = GetPdgCode();
00151       fTimeOfDecay = 1.0e-20;
00152       for (i=0;i<total_defs;i++) {
00153          if (particle_def[i].code == my_code) {
00154             fTimeOfDecay = particle_def[i].lifetime;
00155             break;
00156          }
00157       }
00158       if (fTimeOfDecay <= 1.0e-20) {
00159          fTimeOfDecay = gRandom->Exp(1.0e-8);
00160       }
00161       else if (fTimeOfDecay > 0 && fTimeOfDecay < 1e8)
00162          fTimeOfDecay = gRandom->Exp(fTimeOfDecay);
00163    }
00164    // Apply Lorentz transformation for time dilatation
00165    fTimeOfDecay /= TMath::Sqrt(1.0 - (0.996 * 0.996));
00166 }
00167 
00168 //______________________________________________________________________________
00169 const Char_t *MyParticle::GetName() const
00170 {
00171    // Get name of particle with its PDG number, or Unknown if
00172    // particle name is not defined into ParticlesDef.h
00173 
00174    Int_t i;
00175    Int_t my_code = GetPdgCode();
00176 
00177    for (i=0;i<total_defs;i++) {
00178       if (particle_def[i].code == my_code)
00179          return(particle_def[i].name);
00180    }
00181    return ("Unknown");
00182 }
00183 
00184 //______________________________________________________________________________
00185 TPolyLine3D *MyParticle::AddTrack(const TVector3 &pos, Int_t color)
00186 {
00187    // Add a new track to the list of tracks for this particle.
00188 
00189    TPolyLine3D *poly;
00190    fTracks->Add(new TPolyLine3D());
00191    fNtrack = fTracks->GetLast();
00192    poly = (TPolyLine3D *)fTracks->At(fNtrack);
00193    poly->SetPoint(0, pos.x(), pos.y(), pos.z());
00194    poly->SetLineColor(color);
00195    return poly;
00196 }
00197 
00198 //______________________________________________________________________________
00199 TPolyLine3D *MyParticle::AddTrack(Double_t x, Double_t y, Double_t z, Int_t col)
00200 {
00201    // Add a new track to the list of tracks for this particle.
00202 
00203    TPolyLine3D *poly;
00204    fTracks->Add(new TPolyLine3D());
00205    fNtrack = fTracks->GetLast();
00206    poly = (TPolyLine3D *)fTracks->At(fNtrack);
00207    poly->SetPoint(0, x, y, z);
00208    poly->SetLineColor(col);
00209    return poly;
00210 }
00211 
00212 //______________________________________________________________________________
00213 void MyParticle::SetNextPoint(Int_t color)
00214 {
00215    // Set next polyline point for the current track if the color did not change
00216    // or add a new polyline with the new color.
00217 
00218    TPolyLine3D *poly;
00219    poly = (TPolyLine3D *)fTracks->At(fNtrack);
00220    poly->SetNextPoint(fLocation->x(), fLocation->y(), fLocation->z());
00221    if (color != poly->GetLineColor())
00222       AddTrack(fLocation->x(), fLocation->y(), fLocation->z(), color);
00223 }
00224 
00225 //______________________________________________________________________________
00226 MyParticle::~MyParticle()
00227 {
00228    // destructor
00229 
00230    fTracks->Delete();
00231    delete fTracks;
00232    delete fLocation;
00233 }
00234 
00235 //______________________________________________________________________________
00236 void MyParticle::HighLight()
00237 {
00238    // HighLight this particle track in the display.
00239 
00240    Int_t i;
00241    TPolyLine3D *poly;
00242    TIter next(fTracks);
00243    for (i=0;i<5;i++) {
00244       next.Reset();
00245       while ((poly = (TPolyLine3D *)next())) {
00246          poly->SetLineColor(poly->GetLineColor() + 25);
00247          poly->SetLineWidth(3);
00248          gSystem->ProcessEvents();
00249       }
00250       gRootShower->UpdateDisplay();
00251       gSystem->ProcessEvents();
00252       next.Reset();
00253       while ((poly = (TPolyLine3D *)next())) {
00254          poly->SetLineColor(poly->GetLineColor() - 25);
00255          poly->SetLineWidth(1);
00256          gSystem->ProcessEvents();
00257       }
00258       gRootShower->UpdateDisplay();
00259       gSystem->ProcessEvents();
00260    }
00261    gRootShower->UpdateDisplay();
00262 }
00263 
00264 

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