CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/src/FastSimulation/Particle/src/RawParticle.cc

Go to the documentation of this file.
00001 // -----------------------------------------------------------------------------
00002 //  Prototype for a particle class
00003 // -----------------------------------------------------------------------------
00004 //  $Date: 2007/10/01 09:05:25 $
00005 //  $Revision: 1.14 $
00006 // -----------------------------------------------------------------------------
00007 //  Author: Stephan Wynhoff - RWTH-Aachen (Email: Stephan.Wynhoff@cern.ch)
00008 // -----------------------------------------------------------------------------
00009 #include "FastSimulation/Particle/interface/ParticleTable.h"
00010 #include "FastSimulation/Particle/interface/RawParticle.h"
00011 
00012 #include <iostream>
00013 #include <iomanip>
00014 #include <cmath>
00015 
00016 //using namespace HepPDT;
00017 
00018 RawParticle::RawParticle() {
00019   init();
00020 }
00021 
00022 RawParticle::RawParticle(const XYZTLorentzVector& p) 
00023   : XYZTLorentzVector(p) {
00024   init();
00025 }
00026 
00027 RawParticle::RawParticle(const int id, 
00028                          const XYZTLorentzVector& p) 
00029   : XYZTLorentzVector(p) {
00030   this->init();
00031   this->setID(id);
00032 }
00033 
00034 RawParticle::RawParticle(const std::string name, 
00035                          const XYZTLorentzVector& p) 
00036   : XYZTLorentzVector(p) {
00037   this->init();
00038   this->setID(name);
00039 }
00040 
00041 RawParticle::RawParticle(const XYZTLorentzVector& p, 
00042                          const XYZTLorentzVector& xStart)  : 
00043   XYZTLorentzVector(p)
00044 {
00045   init();
00046   myVertex = xStart;
00047 }
00048 
00049 RawParticle::RawParticle(double px, double py, double pz, double e) : 
00050   XYZTLorentzVector(px,py,pz,e)
00051 {
00052   init();
00053 }
00054 
00055 RawParticle::RawParticle(const RawParticle &right) : 
00056   XYZTLorentzVector(right.Px(),right.Py(),right.Pz(),right.E()) 
00057 {
00058   myId     = right.myId; 
00059   myStatus = right.myStatus;
00060   myUsed   = right.myUsed;
00061   myCharge = right.myCharge;
00062   myMass   = right.myMass;
00063   myVertex = (right.myVertex);
00064   tab = (right.tab);
00065   myInfo = (right.myInfo);
00066 }
00067 
00068 RawParticle::~RawParticle() {
00069   //  nParticles--;
00070 }
00071 
00072 RawParticle&  
00073 RawParticle::operator = (const RawParticle & right ) {
00074   //  cout << "Copy assignment " << endl;
00075   if (this != &right) { // don't copy into yourself
00076     this->SetXYZT(right.Px(),right.Py(),right.Pz(),right.E());
00077     myId     = right.myId; 
00078     myStatus = right.myStatus;
00079     myUsed   = right.myUsed;
00080     myCharge = right.myCharge;
00081     myMass   = right.myMass;
00082     myVertex = right.myVertex;
00083     tab      = right.tab;
00084     myInfo   = right.myInfo;
00085   }
00086   return *this;
00087 }
00088 
00089 void 
00090 RawParticle::init() {
00091   myId=0;  
00092   myStatus=99;
00093   myUsed=0;
00094   myCharge=0.;
00095   myMass=0.;
00096   tab = ParticleTable::instance();
00097   myInfo=0;
00098 }
00099 
00100 void 
00101 RawParticle::setID(const int id) {
00102   myId = id;
00103   if ( tab ) {
00104     if ( !myInfo ) 
00105       myInfo = tab->theTable()->particle(HepPDT::ParticleID(myId));
00106     if ( myInfo ) { 
00107       myCharge = myInfo->charge();
00108       myMass   = myInfo->mass().value();
00109     }
00110   }
00111 }
00112 
00113 void 
00114 RawParticle::setID(const std::string name) {
00115   if ( tab ) { 
00116     if ( !myInfo ) myInfo = tab->theTable()->particle(name);
00117     if ( myInfo ) { 
00118       myId = myInfo->pid();
00119       myCharge = myInfo->charge();
00120       myMass   = myInfo->mass().value();
00121     } else {
00122       myId = 0;
00123     }
00124   }
00125 }
00126 
00127 void 
00128 RawParticle::setStatus(int istat) {
00129   myStatus = istat;
00130 }
00131 
00132 void 
00133 RawParticle::setMass(float m) {
00134   myMass = m;
00135 }
00136 
00137 void 
00138 RawParticle::setCharge(float q) {
00139   myCharge = q;
00140 }
00141 
00142 void 
00143 RawParticle::chargeConjugate() {
00144   myId = -myId;
00145   myCharge = -1*myCharge;
00146 }
00147 
00148 void 
00149 RawParticle::setT(const double t) {
00150   myVertex.SetE(t);
00151 }
00152 
00153 void 
00154 RawParticle::rotate(double angle, const XYZVector& raxis) {
00155   Rotation r(raxis,angle);
00156   XYZVector v(r * Vect());
00157   SetXYZT(v.X(),v.Y(),v.Z(),E());
00158 }
00159 
00160 void 
00161 RawParticle::rotateX(double rphi) {
00162   RotationX r(rphi);
00163   XYZVector v(r * Vect());
00164   SetXYZT(v.X(),v.Y(),v.Z(),E());
00165 }
00166 
00167 void 
00168 RawParticle::rotateY(double rphi) {
00169   RotationY r(rphi);
00170   XYZVector v(r * Vect());
00171   SetXYZT(v.X(),v.Y(),v.Z(),E());
00172 }
00173 
00174 void 
00175 RawParticle::rotateZ(double rphi) {
00176   RotationZ r(rphi);
00177   XYZVector v(r * Vect());
00178   SetXYZT(v.X(),v.Y(),v.Z(),E());
00179 }
00180 
00181 void 
00182 RawParticle::boost(double betax, double betay, double betaz) {
00183   Boost b(betax,betay,betaz);
00184   XYZTLorentzVector p ( b * momentum() );
00185   SetXYZT(p.X(),p.Y(),p.Z(),p.T());
00186 }
00187 
00188 std::string RawParticle::PDGname() const {
00189   std::string MyParticleName;
00190   if ( tab && myInfo ) {
00191     MyParticleName = myInfo->name();
00192   } else {
00193     MyParticleName = "unknown  ";
00194   }
00195   return (std::string) MyParticleName;}
00196 
00197 
00198 void 
00199 RawParticle::printName() const {
00200   std::string MyParticleName = PDGname();
00201   if (MyParticleName.length() != 0) {
00202     std::cout <<  MyParticleName;
00203     for(unsigned int k=0;k<9-MyParticleName.length() && k<10; k++) 
00204       std::cout << " " ;
00205   } else {
00206     std::cout << "unknown  ";
00207   }
00208 }
00209 
00210 void 
00211 RawParticle::print() const {
00212   printName();
00213   std::cout << std::setw(3) << status();
00214   std::cout.setf(std::ios::fixed, std::ios::floatfield);
00215   std::cout.setf(std::ios::right, std::ios::adjustfield);
00216   std::cout << std::setw(8) << std::setprecision(2) << Px();
00217   std::cout << std::setw(8) << std::setprecision(2) << Py();
00218   std::cout << std::setw(8) << std::setprecision(2) << Pz();
00219   std::cout << std::setw(8) << std::setprecision(2) << E();
00220   std::cout << std::setw(8) << std::setprecision(2) << M();
00221   std::cout << std::setw(8) << std::setprecision(2) << mass();
00222   std::cout << std::setw(8) << std::setprecision(2) << charge();
00223   std::cout << std::setw(8) << std::setprecision(2) << X();
00224   std::cout << std::setw(8) << std::setprecision(2) << Y();
00225   std::cout << std::setw(8) << std::setprecision(2) << Z();
00226   std::cout << std::setw(8) << std::setprecision(2) << T();
00227   std::cout << std::setw(0) << std::endl;
00228 }
00229 
00230 std::ostream& operator <<(std::ostream& o , const RawParticle& p) {
00231 
00232   o.setf(std::ios::fixed, std::ios::floatfield);
00233   o.setf(std::ios::right, std::ios::adjustfield);
00234 
00235 
00236   o << std::setw(4) << std::setprecision(2) << p.pid() << " (";
00237   o << std::setw(2) << std::setprecision(2) << p.status() << "): ";
00238   o << std::setw(10) << std::setprecision(4) << p.momentum() << " ";
00239   o << std::setw(10) << std::setprecision(4) << p.vertex();
00240   return o;
00241 
00242 } 
00243 
00244 double 
00245 RawParticle::PDGcharge() const { 
00246   double q=-99999;
00247   if ( myInfo ) {
00248     q=myInfo->charge();
00249   }
00250   return q;
00251 }
00252 
00253 double 
00254 RawParticle::PDGmass() const  { 
00255   double m=-99999;
00256   if ( myInfo ) {
00257     m = myInfo->mass().value();
00258   }
00259   return m;
00260 }
00261 
00262 double 
00263 RawParticle::PDGcTau() const {
00264   double ct=1E99;
00265   if ( myInfo ) {
00266 
00267     // The lifetime is 0. in the Pythia Particle Data Table !
00268     //    ct=tab->theTable()->particle(ParticleID(myId))->lifetime().value();
00269 
00270     // Get it from the width (apparently Gamma/c!)
00271     double w = myInfo->totalWidth().value();
00272     if ( w != 0. && myId != 1000022 ) { 
00273       ct = 6.582119e-25 / w / 10.;   // ctau in cm 
00274     } else {
00275     // Temporary fix of a bug in the particle data table
00276       unsigned amyId = abs(myId);
00277       if ( amyId != 22 &&    // photon 
00278            amyId != 11 &&    // e+/-
00279            amyId != 10 &&    // nu_e
00280            amyId != 12 &&    // nu_mu
00281            amyId != 14 &&    // nu_tau
00282            amyId != 1000022 && // Neutralino
00283            amyId != 1000039 && // Gravitino
00284            amyId != 2112 &&  // neutron/anti-neutron
00285            amyId != 2212 &&  // proton/anti-proton
00286            amyId != 101 &&   // Deutreron etc..
00287            amyId != 102 &&   // Deutreron etc..
00288            amyId != 103 &&   // Deutreron etc..
00289            amyId != 104 ) {  // Deutreron etc.. 
00290         ct = 0.;
00291         /* */
00292       }
00293     }
00294   }
00295 
00296   /*
00297   std::cout << setw(20) << setprecision(18) 
00298        << "myId/ctau/width = " << myId << " " 
00299        << ct << " " << w << endl;  
00300   */
00301 
00302   return ct;
00303 }
00304 
00305 double 
00306 RawParticle::et() const { 
00307   double mypp, tmpEt=-1.;
00308   
00309   mypp = std::sqrt(momentum().mag2());
00310   if ( mypp != 0 ) {
00311     tmpEt = E() * pt() / mypp;
00312   }
00313   return tmpEt;
00314 }