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::PerfectId.
0004  
0005  \author    Michael Savastio
0006  \date      2011-08-19
0007  \copyright 2011 Brookhaven National Lab
0008  */
0009 
0010 #include "eicsmear/smear/PerfectID.h"
0011 
0012 #include <set>
0013 #include <sstream>
0014 #include <string>
0015 #include <vector>
0016 
0017 #include <TDatabasePDG.h>
0018 #include <TParticlePDG.h>
0019 
0020 namespace {
0021 
0022 // Returns the name of the particle species with the PDG code,
0023 // or the integer converted to a string if the PDG information
0024 // cannot be found.
0025 std::string particleName(int pdg) {
0026   std::stringstream stream;
0027   TParticlePDG* p = TDatabasePDG::Instance()->GetParticle(pdg);
0028   if (p) {
0029     stream << p->GetName();
0030   } else {
0031     stream << pdg;
0032   }  // if
0033   return stream.str();
0034 }
0035 
0036 }  // anonymous namespace
0037 
0038 namespace Smear {
0039 
0040 PerfectID::PerfectID(const std::vector<Int_t>& pdg)
0041 : mPdg(pdg.begin(), pdg.end()) {
0042 }
0043 
0044 PerfectID::~PerfectID() {
0045 }
0046 
0047 void PerfectID::Smear(const erhic::VirtualParticle& in, ParticleMCS& out) {
0048   // If the PDG list is empty, always copy PDG code.
0049   // Otherwise, copy the PDG code if it is in the list.
0050   bool copy = mPdg.empty() || mPdg.find(in.Id()) != mPdg.end();
0051   if (copy) {
0052     out.SetId(in.Id());
0053   }  // if
0054 }
0055 
0056 PerfectID* PerfectID::Clone(const char*) const {
0057   return new PerfectID(*this);
0058 }
0059 
0060 void PerfectID::Print(Option_t* /* option */) const {
0061   std::stringstream stream;
0062   stream << "Copies PDG ID for ";
0063   if (mPdg.empty()) {
0064     stream << "all particles";
0065   } else {
0066     // List the PDG codes. Insert the first one into the stream,
0067     // then loop from the second (if it exists) onward so we
0068     // can delimit with commas.
0069     std::set<Int_t>::const_iterator iter = mPdg.begin();
0070     stream << particleName(*iter);
0071     for (++iter; iter != mPdg.end(); ++iter) {
0072       stream << ", " << particleName(*iter);
0073     }  // for
0074   }  // if
0075   std::cout << stream.str() << std::endl;
0076 }
0077 
0078 void PerfectID::Insert(Int_t i) {
0079   mPdg.insert(i);
0080 }
0081 
0082 }  // namespace Smear