GENIEGenerator
Loading...
Searching...
No Matches
PDGCodeList.cxx
Go to the documentation of this file.
1//____________________________________________________________________________
2/*
3 Copyright (c) 2003-2025, The GENIE Collaboration
4 For the full text of the license visit http://copyright.genie-mc.org
5
6 Costas Andreopoulos <c.andreopoulos \at cern.ch>
7 University of Liverpool
8*/
9//____________________________________________________________________________
10
11#include <algorithm>
12#include <iomanip>
13#include <string>
14
18
19using std::setw;
20using std::setfill;
21using std::endl;
22using std::string;
23
24using namespace genie;
25
26//____________________________________________________________________________
27namespace genie {
28 ostream & operator << (ostream & stream, const PDGCodeList & list)
29 {
30 list.Print(stream);
31 return stream;
32 }
33}
34//___________________________________________________________________________
36vector<int>()
37{
38 fAllowDuplicateEntries = allowdup;
39}
40//___________________________________________________________________________
41PDGCodeList::PDGCodeList(size_type n, bool allowdup) :
42vector<int>(n)
43{
44 fAllowDuplicateEntries = allowdup;
45}
46//___________________________________________________________________________
48vector<int>()
49{
50 this->Copy(list);
51}
52//___________________________________________________________________________
57//___________________________________________________________________________
58void PDGCodeList::push_back(int pdg_code)
59{
60 if(this->CheckPDGCode(pdg_code)) vector<int>::push_back(pdg_code);
61}
62//___________________________________________________________________________
63void PDGCodeList::insert(iterator pos, size_type n, const int& pdg_code)
64{
65 if(this->CheckPDGCode(pdg_code)) {
66 if(n>1) n = 1;
67 vector<int>::insert(pos,n,pdg_code);
68 }
69}
70//___________________________________________________________________________
71bool PDGCodeList::CheckPDGCode(int pdg_code) const
72{
73// check whether the PDG code can be inserted
74
75 bool exists = this->ExistsInPDGLibrary(pdg_code);
76 if(!exists) {
77 LOG("PDG", pERROR)
78 << "Can't add non-existent particle [pdgc = " << pdg_code << "]";
79 return false;
80 }
81
83 bool added = this->ExistsInPDGCodeList(pdg_code);
84 if(added) {
85 LOG("PDG", pDEBUG)
86 << "Particle [pdgc = " << pdg_code << "] was already added";
87 return false;
88 }
89 }
90 return true;
91}
92//___________________________________________________________________________
93bool PDGCodeList::ExistsInPDGLibrary(int pdg_code) const
94{
95// check whether the PDG code is a valid one (exists in PDGLibrary)
96
98 TParticlePDG * particle = pdglib->Find(pdg_code);
99 if(!particle) return false;
100 return true;
101}
102//___________________________________________________________________________
103bool PDGCodeList::ExistsInPDGCodeList(int pdg_code) const
104{
105// check whether the PDG code already exists in the list
106
107 PDGCodeList::const_iterator bci = this->begin();
108 PDGCodeList::const_iterator eci = this->end();
109
110 if(find(bci,eci,pdg_code) != eci) return true;
111
112 return false;
113/*
114 int n = count(this->begin(), this->end(), pdg_code);
115 if(n!=0) return true;
116 return false;
117*/
118}
119//___________________________________________________________________________
120void PDGCodeList::Print(ostream & stream) const
121{
122 stream << "\n[-]" << endl;
123
124 PDGLibrary * pdglib = PDGLibrary::Instance();
125
126 PDGCodeList::const_iterator iter;
127 size_t nc = this->size();
128
129 for(iter = this->begin(); iter != this->end(); ++iter) {
130 int pdg_code = *iter;
131 TParticlePDG * p = pdglib->Find(pdg_code);
132
133 if(!p) {
134 stream << " |---o ** ERR: no particle with PDG code: " << pdg_code;
135 } else {
136 string name = p->GetName();
137 stream << " |---o "
138 << setfill(' ') << setw(15) << name
139 << " (PDG code = " << pdg_code << ")";
140 }
141 if( (--nc) > 0) stream << endl;
142 }
143}
144//___________________________________________________________________________
146{
147 this->clear();
148
149 PDGCodeList::const_iterator iter;
150 for(iter = list.begin(); iter != list.end(); ++iter) {
151 int code = *iter;
152 this->push_back(code);
153 }
154
156}
157//___________________________________________________________________________
159{
160 this->Copy(list);
161 return (*this);
162}
163//___________________________________________________________________________
vector< vector< double > > clear
#define pERROR
Definition Messenger.h:59
#define pDEBUG
Definition Messenger.h:63
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE,...
Definition Messenger.h:96
void Print(ostream &stream) const
bool ExistsInPDGCodeList(int pdg_code) const
PDGCodeList & operator=(const PDGCodeList &list)
overloaded operators
bool fAllowDuplicateEntries
allow duplicate entries in the list?
Definition PDGCodeList.h:64
PDGCodeList(bool allowdup=false)
void Copy(const PDGCodeList &list)
copy / print
bool ExistsInPDGLibrary(int pdg_code) const
void push_back(int pdg_code)
void insert(iterator pos, size_type n, const int &x)
bool CheckPDGCode(int pdg_code) const
PDG code checks used by PDGCodeList.
Singleton class to load & serve a TDatabasePDG.
Definition PDGLibrary.h:36
static PDGLibrary * Instance(void)
TParticlePDG * Find(int pdgc, bool must_exist=true)
THE MAIN GENIE PROJECT NAMESPACE
Definition AlgCmp.h:25
ostream & operator<<(ostream &stream, const AlgConfigPool &config_pool)