Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-06-26 07:05:37

0001 /**
0002  \file
0003  Implementation of class Smear::ParticleMCS.
0004  
0005  \author    Michael Savastio
0006  \date      2011-08-19
0007  \copyright 2011 Brookhaven National Lab
0008  */
0009 
0010 #include "eicsmear/smear/ParticleMCS.h"
0011 
0012 #include <iomanip>
0013 #include <iostream>
0014 
0015 #include <TMath.h>
0016 
0017 namespace Smear {
0018 
0019 ParticleMCS::ParticleMCS()
0020 : status(0)
0021 , id(0)
0022 , px(0.)
0023 , py(0.)
0024 , pz(0.)
0025 , E(0.)
0026 , pt(0.)
0027 , p(0.)
0028 , theta(0.)
0029 , phi(0.)
0030 , numSigma( std::nan("") )
0031 , numSigmaType(0)
0032 {
0033 }
0034 
0035 ParticleMCS::ParticleMCS(const TLorentzVector& ep, int pdg, int stat)
0036 : status(stat)
0037 , id(pdg)
0038 , px(ep.Px())
0039 , py(ep.Py())
0040 , pz(ep.Pz())
0041 , E(ep.E())
0042 , pt(ep.Pt())
0043 , p(ep.P())
0044 , theta(ep.Theta())
0045 , phi(ep.Phi())
0046 , numSigma( std::nan("") )
0047 , numSigmaType(0)
0048 {
0049 }
0050 
0051 ParticleMCS::~ParticleMCS() {
0052 }
0053 
0054 TLorentzVector ParticleMCS::Get4Vector() const {
0055   return TLorentzVector(px, py, pz, E);
0056 }
0057 
0058 void ParticleMCS::Print(Option_t* /* unused */) const {
0059   // Store initial flags for cout so we can restore them later.
0060   std::ios_base::fmtflags ff = std::cout.flags();
0061   // Configure flags for output
0062   std::cout.setf(std::ios_base::fixed, std::ios_base::basefield);
0063   std::cout.precision(4);
0064   // Output values.
0065   std::cout <<
0066   std::setw(3) << status <<
0067   std::setw(12) << id <<
0068   std::setw(10) << px <<
0069   std::setw(10) << py <<
0070   std::setw(10) << pz <<
0071   std::setw(10) << E << std::endl;
0072   // Restore initial cout flags.
0073   std::cout.flags(ff);
0074 }
0075 
0076 Double_t ParticleMCS::GetEta() const {
0077   // The default value of -19 is used in the main eRHIC code,
0078   // so use that for consistency.
0079   double eta(-19.);
0080   const double theta = GetTheta();
0081   if (theta > 0. && theta < TMath::Pi() && !TMath::IsNaN(theta)) {
0082     eta = -log(tan(theta / 2.));
0083   }  // if
0084   return eta;
0085 }
0086 
0087 Double_t ParticleMCS::GetRapidity() const {
0088   // The default value of -19 is used in the main eRHIC code,
0089   // so use that for consistency.
0090   double y(-19.);
0091   // Be careful here, as the energy and momentum can become
0092   // smeared such that the stored E < pz, giving NaN when
0093   // taking a log of a negative.
0094   // In that case, return the default value.
0095   // E > pz already takes care of the case if E is NaN, so
0096   // no need to check that again.
0097   if (E > pz && !TMath::IsNaN(pz)) {
0098     y = 0.5 * log((E + pz) / (E - pz));
0099   }  // if
0100   return y;
0101 }
0102 
0103   // -----------------------------------------------------------
0104   
0105   Double_t ParticleMCS::GetPx() const {
0106     return p * sin(theta) * cos(phi);
0107   }
0108 
0109   Double_t ParticleMCS::GetPy() const {
0110     return p * sin(theta) * sin(phi);
0111   }
0112 
0113   Double_t ParticleMCS::GetPz() const {
0114     return pz;
0115   }
0116 
0117   Double_t ParticleMCS::GetE() const {
0118     return E;
0119   }
0120 
0121   Double_t ParticleMCS::GetM() const {
0122     return sqrt(pow(E, 2.) - pow(p, 2.));
0123   }
0124 
0125   Double_t ParticleMCS::GetPt() const {
0126     return pt;
0127   }
0128 
0129   TVector3 ParticleMCS::GetVertex() const {
0130     return TVector3();
0131   }
0132 
0133   Double_t ParticleMCS::GetP() const {
0134     return p;
0135   }
0136 
0137   Double_t ParticleMCS::GetTheta() const {
0138     return theta;
0139   }
0140 
0141   Double_t ParticleMCS::GetPhi() const {
0142     return phi;
0143   }
0144 
0145   UShort_t ParticleMCS::GetStatus() const {
0146     return status;
0147   }
0148 
0149   double ParticleMCS::GetNumSigma() const {
0150     return numSigma;
0151   }
0152 
0153   int ParticleMCS::GetNumSigmaType() const {
0154     return numSigmaType;
0155   }
0156 
0157   bool ParticleMCS::IsSmeared() const { return kParticleSmeared; }
0158   bool ParticleMCS::IsESmeared() const { return kESmeared; }
0159   bool ParticleMCS::IsPSmeared() const { return kPSmeared; }
0160   bool ParticleMCS::IsPtSmeared() const { return kPtSmeared; }
0161   bool ParticleMCS::IsPxSmeared() const { return kPxSmeared; }
0162   bool ParticleMCS::IsPySmeared() const { return kPySmeared; }
0163   bool ParticleMCS::IsPzSmeared() const { return kPzSmeared; }
0164   bool ParticleMCS::IsThetaSmeared() const { return kThetaSmeared; }
0165   bool ParticleMCS::IsPhiSmeared() const { return kPhiSmeared; }
0166   bool ParticleMCS::IsIdSmeared() const { return kIdSmeared; }
0167   bool ParticleMCS::IsNumSigmaSmeared() const { return kNumSigmaSmeared; }
0168   
0169   // -----------------------------------------------------------
0170   void ParticleMCS::SetVariable( const double z, const KinType kin) {
0171     switch (kin) {
0172     case kE:
0173       SetE(z); break;
0174     case kP:
0175       SetP(z); break;
0176     case kTheta:
0177       SetTheta(z); break;
0178     case kPhi:
0179       SetPhi(z); break;
0180     case kPz:
0181       SetPz(z); break;
0182     case kPt:
0183       SetPt(z); break;
0184     default:
0185       break;
0186     }  // switch
0187   }
0188 
0189   void ParticleMCS::SetE(const Double_t value, const bool CheckSetSmearFlag){
0190     if ( kESmeared && CheckSetSmearFlag ) throw std::runtime_error ("Attempting to smear E twice");
0191     else kESmeared = true;
0192     E = value;
0193   }
0194 
0195   void ParticleMCS::SetP(Double_t value, const bool CheckSetSmearFlag){
0196     if ( kPSmeared && CheckSetSmearFlag ) throw std::runtime_error ("Attempting to smear P twice");
0197     else kPSmeared = true;
0198     p = value;
0199   }
0200 
0201   void ParticleMCS::SetPt(Double_t value, const bool CheckSetSmearFlag){
0202     if ( kPtSmeared && CheckSetSmearFlag ) throw std::runtime_error ("Attempting to smear Pt twice");
0203     else kPtSmeared = true;
0204     pt = value;
0205   }
0206 
0207   void ParticleMCS::SetPx(Double_t value, const bool CheckSetSmearFlag){
0208     if ( kPxSmeared && CheckSetSmearFlag ) throw std::runtime_error ("Attempting to smear Px twice");
0209     else kPxSmeared = true;
0210     px = value;
0211   }
0212 
0213   void ParticleMCS::SetPy(Double_t value, const bool CheckSetSmearFlag){
0214     if ( kPySmeared && CheckSetSmearFlag ) throw std::runtime_error ("Attempting to smear Py twice");
0215     else kPySmeared = true;
0216     py = value;
0217   }
0218 
0219   void ParticleMCS::SetPz(Double_t value, const bool CheckSetSmearFlag){
0220     if ( kPzSmeared && CheckSetSmearFlag ) throw std::runtime_error ("Attempting to smear Pz twice");
0221     else kPzSmeared = true;
0222     pz = value;
0223   }
0224 
0225   void ParticleMCS::SetPhi(Double_t value, const bool CheckSetSmearFlag){
0226     if ( kPhiSmeared && CheckSetSmearFlag ) throw std::runtime_error ("Attempting to smear Phi twice");
0227     else kPhiSmeared = true;
0228     phi = value;
0229   }
0230 
0231   void ParticleMCS::SetTheta(Double_t value, const bool CheckSetSmearFlag){
0232     if ( kThetaSmeared && CheckSetSmearFlag ) throw std::runtime_error ("Attempting to smear Theta twice");
0233     else kThetaSmeared = true;
0234     theta = value;
0235   }
0236 
0237   void ParticleMCS::SetId(Int_t i, const bool CheckSetSmearFlag){
0238     if ( kIdSmeared && CheckSetSmearFlag ) throw std::runtime_error ("Attempting to smear Id twice");
0239     else kIdSmeared = true; 
0240     id = i;
0241   }
0242 
0243   void ParticleMCS::SetStatus(Int_t i) {
0244     status = i;
0245   }
0246 
0247   void ParticleMCS::SetNumSigma( const double d, const bool CheckSetSmearFlag){
0248     if ( kNumSigmaSmeared && CheckSetSmearFlag ) throw std::runtime_error ("Attempting to smear numSigma twice");
0249     else kNumSigmaSmeared = true;
0250     numSigma = d;
0251   }
0252 
0253   void ParticleMCS::SetNumSigmaType( const int i){
0254     numSigmaType = i;
0255   }
0256 
0257   erhic::Pid ParticleMCS::Id() const {
0258     return ::erhic::Pid(id);
0259   }
0260 
0261   void ParticleMCS::HandleBogusValues( KinType kin ) {
0262     double fault(0.);
0263     if (kE == kin && GetE() < 0.) {
0264       SetE(fault, false);
0265     } else if (kP == kin && GetP() < 0.) {
0266       SetP(fault, false);
0267     } else if (kPt == kin && GetPt() < 0.) {
0268       SetPt(fault, false);
0269     }
0270   }  
0271   
0272   void ParticleMCS::SetSmeared( bool flag) {kParticleSmeared=flag;}
0273   void ParticleMCS::SetESmeared( bool flag) {kESmeared=flag;}
0274   void ParticleMCS::SetPSmeared( bool flag) {kPSmeared=flag;}
0275   void ParticleMCS::SetPtSmeared( bool flag) {kPtSmeared=flag;}
0276   void ParticleMCS::SetPxSmeared( bool flag) {kPxSmeared=flag;}
0277   void ParticleMCS::SetPySmeared( bool flag) {kPySmeared=flag;}
0278   void ParticleMCS::SetPzSmeared( bool flag) {kPzSmeared=flag;}
0279   void ParticleMCS::SetThetaSmeared( bool flag) {kThetaSmeared=flag;}
0280   void ParticleMCS::SetPhiSmeared( bool flag) {kPhiSmeared=flag;}
0281   void ParticleMCS::SetIdSmeared( bool flag) {kIdSmeared=flag;}
0282   void ParticleMCS::SetNumSigmaSmeared( bool flag) {kNumSigmaSmeared=flag;}
0283 
0284 }  // namespace Smear