eic-smear  1.0.3
A collection of ROOT classes for Monte Carlo events and a fast-smearing code simulating detector effects for the Electron-Ion Collider task force
PerfectID.cxx
Go to the documentation of this file.
1 
11 
12 #include <set>
13 #include <sstream>
14 #include <string>
15 #include <vector>
16 
17 #include <TDatabasePDG.h>
18 #include <TParticlePDG.h>
19 
20 namespace {
21 
22 // Returns the name of the particle species with the PDG code,
23 // or the integer converted to a string if the PDG information
24 // cannot be found.
25 std::string particleName(int pdg) {
26  std::stringstream stream;
27  TParticlePDG* p = TDatabasePDG::Instance()->GetParticle(pdg);
28  if (p) {
29  stream << p->GetName();
30  } else {
31  stream << pdg;
32  } // if
33  return stream.str();
34 }
35 
36 } // anonymous namespace
37 
38 namespace Smear {
39 
40 PerfectID::PerfectID(const std::vector<Int_t>& pdg)
41 : mPdg(pdg.begin(), pdg.end()) {
42 }
43 
45 }
46 
48  // If the PDG list is empty, always copy PDG code.
49  // Otherwise, copy the PDG code if it is in the list.
50  bool copy = mPdg.empty() || mPdg.find(in.Id()) != mPdg.end();
51  if (copy) {
52  out.SetId(in.Id());
53  } // if
54 }
55 
56 PerfectID* PerfectID::Clone(const char*) const {
57  return new PerfectID(*this);
58 }
59 
60 void PerfectID::Print(Option_t* /* option */) const {
61  std::stringstream stream;
62  stream << "Copies PDG ID for ";
63  if (mPdg.empty()) {
64  stream << "all particles";
65  } else {
66  // List the PDG codes. Insert the first one into the stream,
67  // then loop from the second (if it exists) onward so we
68  // can delimit with commas.
69  std::set<Int_t>::const_iterator iter = mPdg.begin();
70  stream << particleName(*iter);
71  for (++iter; iter != mPdg.end(); ++iter) {
72  stream << ", " << particleName(*iter);
73  } // for
74  } // if
75  std::cout << stream.str() << std::endl;
76 }
77 
78 void PerfectID::Insert(Int_t i) {
79  mPdg.insert(i);
80 }
81 
82 } // namespace Smear
virtual void Insert(Int_t)
Definition: PerfectID.cxx:78
virtual void Smear(const erhic::VirtualParticle &, ParticleMCS &)
Definition: PerfectID.cxx:47
virtual ~PerfectID()
Definition: PerfectID.cxx:44
virtual PerfectID * Clone(const char *="") const
Definition: PerfectID.cxx:56
PerfectID(const std::vector< Int_t > &pdg=std::vector< int >())
Definition: PerfectID.cxx:40
virtual Pid Id() const =0
std::set< Int_t > mPdg
PDG codes to copy. Does not operate on particles with other codes.
Definition: PerfectID.h:67
Abstract base class for a general particle.
virtual void Print(Option_t *="") const
Definition: PerfectID.cxx:60