Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

MCAppParticle.cxx

Go to the documentation of this file.
00001 
00002 //
00003 // MCAppParticle
00004 //
00005 // MCAppParticle is a base class to store data for a particle primary or
00006 // secondary produced during particle transport.
00007 //
00008 // Author:  S. Kasahara 10/2006
00009 //
00010 // Notes: The principle requirement of this class is that it HasA TParticle
00011 //        with particle data information, since TParticle is the format
00012 //        expected by the VMC.
00013 //
00015 
00016 #include <TParticlePDG.h>
00017 
00018 #include "MessageService/MsgService.h"
00019 #include "MCApplication/MCAppParticle.h"
00020 
00021 ClassImp(MCAppParticle)
00022 
00023 CVSID("$Id: MCAppParticle.cxx,v 1.11 2009/06/22 04:11:21 kasahara Exp $");
00024 
00025 std::ostream& operator << (std::ostream& os, const MCAppParticle& mp)
00026                           { return mp.Print(os); }
00027 
00028 //_____________________________________________________________________________
00029 MCAppParticle::MCAppParticle(Int_t id,Int_t pdg, Int_t statuscode, 
00030                     Double_t px, Double_t py, Double_t pz, Double_t e, 
00031                     Double_t vx, Double_t vy, Double_t vz, Double_t tof,
00032                     TMCProcess process) 
00033   : fID(id), fTParticle(pdg,statuscode,-1,-1,-1,-1,
00034     px,py,pz,e,vx,vy,vz,tof), fProcess(process), 
00035     fPrintPreface(""),  fPrintOption("")  {
00036   // Normal constructor, Recommended
00037 
00038 }
00039 
00040 //_____________________________________________________________________________
00041 MCAppParticle::MCAppParticle(Int_t id,TParticle* particle, TMCProcess process) 
00042   : fID(id), fTParticle(), fProcess(process), 
00043     fPrintPreface(""),fPrintOption("") {
00044   // Normal constructor
00045   // The input particle is copied, but not adopted
00046 
00047   if ( particle ) fTParticle = *particle;  // copy the input particle
00048 
00049 }
00050 
00051 //_____________________________________________________________________________
00052 MCAppParticle::MCAppParticle() : fID(-1), fTParticle(), fProcess(kPNoProcess),
00053                                  fPrintPreface(""), fPrintOption("") {
00054   // Default constructor
00055 
00056 }
00057 
00058 
00059 //_____________________________________________________________________________
00060 MCAppParticle::~MCAppParticle() {
00061   // Destructor.  Delete all owned sub-objects
00062 
00063 }
00064 
00065 //_____________________________________________________________________________
00066 std::ostream& MCAppParticle::Print(std::ostream& os) const {
00067   // Print particle data on ostream.
00068   // GetPrintOption() == "full" will print child particles
00069   // GetPrintOption() == "" prints this particle only
00070   //
00071   
00072   os << GetPrintPreface().c_str() << GetID() << ")";
00073   os << GetPdgCode() << "/" << fTParticle.GetName()
00074      << " s: " << GetStatusCode() << "/" 
00075      << GetStatusCodeName().c_str() 
00076      << " v: " << fTParticle.Vx() 
00077      << " "    << fTParticle.Vy() 
00078      << " "    << fTParticle.Vz() 
00079      << " t: " << fTParticle.T()
00080      << " p: " << fTParticle.Px() 
00081      << " "    << fTParticle.Py()
00082      << " "    << fTParticle.Pz()
00083      << " P:"  << GetParentID(0) 
00084      << ","    << GetParentID(1) 
00085      << " C:"  << GetChildID(0) 
00086      << " to " << GetChildID(GetNChildren()-1)
00087      << "."    << endl;
00088 
00089   if ( !strcmp(GetPrintOption().c_str(),"full") ) {
00090     Int_t nd = GetNChildren();
00091     if ( nd > 0 ) {
00092       os << GetPrintPreface().c_str() << "  " << nd;
00093       if ( nd == 1 ) os << " Child:" << endl;
00094       else os  << " Children:" << endl;
00095       // Recursive loop over children, children's children,...
00096       for ( Int_t id = 0; id < nd; id++ ) {
00097         MCAppParticle* cdpart = const_cast<MCAppParticle*>(GetChild(id));
00098         std::string saveoption  = cdpart->GetPrintOption();
00099         std::string savepreface = cdpart->GetPrintPreface();
00100         cdpart -> SetPrintOption(GetPrintOption());
00101         cdpart -> SetPrintPreface(GetPrintPreface() + "  ");
00102         os << *(cdpart);
00103         cdpart -> SetPrintOption(saveoption);
00104         cdpart -> SetPrintPreface(savepreface);
00105       }
00106     }
00107   }
00108 
00109 
00110   return os;
00111 
00112 }
00113 
00114 //_____________________________________________________________________________
00115 void MCAppParticle::Print(Option_t* /* option */) const {
00116   // Print particle in form supported by TObject::Print
00117   // The user can also control the print by specifying a preface using
00118   // the SetPrintPreface method, e.g. to set an indentation.
00119 
00120   Print(std::cout);
00121   return;
00122 
00123 }
00124 
00125 //_____________________________________________________________________________
00126 const MCAppParticle* MCAppParticle::GetChild(UInt_t id) const {
00127   // Return pointer to id-th child or null if out-of-range
00128 
00129   if ( id >= fChildren.size() ) return 0;
00130   
00131   const MCAppParticle* child = fChildren[id];
00132 
00133   return child;
00134   
00135 }
00136 
00137 
00138 //_____________________________________________________________________________
00139 const MCAppParticle* MCAppParticle::GetParent(UInt_t id) const {
00140   // Return pointer to id-th parent (0 or 1) or null if out-of-range
00141 
00142   if ( id >= fParents.size() ) return 0;
00143   
00144   const MCAppParticle* parent = fParents[id];
00145 
00146   return parent;
00147 
00148 }
00149 
00150 //_____________________________________________________________________________
00151 const MCAppParticle* MCAppParticle::GetSibling(UInt_t id) const {
00152   // Return pointer to id-th sibling or null if out-of-range
00153   // Siblings are particles all generated in the same production
00154   // mechanism event.  For example, decay products from a single decay
00155   // are siblings.
00156 
00157   if ( id >= fSiblings.size() ) return 0;
00158   
00159   const MCAppParticle* sibling = fSiblings[id];
00160 
00161   return sibling;
00162 
00163 }
00164 
00165 //_____________________________________________________________________________
00166 void MCAppParticle::AddChild(const MCAppParticle* child) {
00167   // Add child to list of indices.
00168 
00169   if ( !child ) {
00170     MSG("MCApp",Msg::kWarning) 
00171       << "MCAppParticle::AddChild received null child ptr" << endl;
00172     return;
00173   }
00174 
00175   fChildren.push_back(child);
00176   
00177 }
00178 
00179 //_____________________________________________________________________________
00180 void MCAppParticle::AddParent(const MCAppParticle* parent) {
00181   // Add parent to list of indices.
00182 
00183   if ( !parent ) {
00184     MSG("MCApp",Msg::kWarning) 
00185       << "MCAppParticle::AddParent received null parent ptr" << endl;
00186     return;
00187   }
00188   
00189   fParents.push_back(parent);
00190   
00191 }
00192 
00193 //_____________________________________________________________________________
00194 void MCAppParticle::AddSibling(const MCAppParticle* sibling) {
00195   // Add sibling to list of indices.
00196   // Siblings are particles all generated in the same production
00197   // mechanism event.  For example, decay products from a single decay
00198   // are siblings.
00199 
00200   if ( !sibling ) {
00201     MSG("MCApp",Msg::kWarning) 
00202       << "MCAppParticle::AddSibling received null sibling ptr" << endl;
00203     return;
00204   }
00205   
00206   fSiblings.push_back(sibling);
00207   
00208 }
00209 
00210 //_____________________________________________________________________________
00211 Double_t MCAppParticle::GetCharge() { 
00212   return ( fTParticle.GetPDG() ) ?  fTParticle.GetPDG() -> Charge() : 0; 
00213 }
00214 
00215 //_____________________________________________________________________________
00216 void MCAppParticle::ProductionVertex(TLorentzVector& lv) const {
00217   lv.SetXYZT(0,0,0,0);
00218   fTParticle.ProductionVertex(lv); 
00219 }
00220 
00221 //_____________________________________________________________________________
00222 void MCAppParticle::ProductionMomentum(TLorentzVector& lv) const {
00223   lv.SetPxPyPzE(0,0,0,0);
00224   fTParticle.Momentum(lv); 
00225 }
00226 
00227 //_____________________________________________________________________________
00228 void MCAppParticle::GetPolarisation(TVector3& vec) {
00229   vec.SetXYZ(0,0,0);
00230   fTParticle.GetPolarisation(vec); 
00231 }
00232 
00233 //_____________________________________________________________________________
00234 Int_t MCAppParticle::GetParentID(UInt_t i) const {
00235   const MCAppParticle* parent = GetParent(i);
00236   if ( parent ) return parent->GetID();
00237   else return -1;
00238 }
00239 
00240 //_____________________________________________________________________________
00241 Int_t MCAppParticle::GetChildID(UInt_t i) const {
00242   const MCAppParticle* child = GetChild(i);
00243   if ( child ) return child->GetID();
00244   else return -1;
00245 }
00246 
00247 //_____________________________________________________________________________
00248 Int_t MCAppParticle::GetSiblingID(UInt_t i) const {
00249   const MCAppParticle* sibling = GetSibling(i);
00250   if ( sibling ) return sibling->GetID();
00251   else return -1;
00252 }

Generated on Mon Feb 15 11:06:57 2010 for loon by  doxygen 1.3.9.1