20 , PMatPath(
"PIDMatrix.dat")
36 std::cout.setf(std::ios::fixed);
37 std::cout.precision(6);
38 for (
unsigned i(0); i < PMax.size(); i++) {
39 for (
unsigned k(0); k < FalseIdent.size(); k++) {
40 std::cout << 1 <<
'\t' << i + 1 <<
'\t' << PMin.at(i) <<
'\t' <<
41 PMax.at(i) <<
'\t' << k + 1;
42 for (
unsigned j(0); j < TrueIdent.size(); j++) {
43 std::cout <<
'\t' << PMatrix.at(i).at(j).at(k);
45 std::cout << std::endl;
51 PMatrix.resize(PMin.size());
52 for (
unsigned i(0); i < PMatrix.size(); i++) {
53 PMatrix.at(i).resize(TrueIdent.size());
54 for (
unsigned j(0); j < PMatrix.at(i).size(); j++) {
55 PMatrix.at(i).at(j).resize(FalseIdent.size());
62 Range.resize(PMatrix.size());
63 for (
unsigned i(0); i < Range.size(); i++) {
64 Range.at(i).resize(PMatrix.at(i).size());
65 for (
unsigned j(0); j < Range.at(i).size(); j++) {
66 Range.at(i).at(j).resize(PMatrix.at(i).at(j).size());
67 for (
unsigned k = 0; k < Range.at(i).at(j).size(); k++) {
68 t += PMatrix.at(i).at(j).at(k);
69 Range.at(i).at(j).at(k) = t;
77 const double r = Ran.Rndm();
78 const int k = InListOfTrue(trueID);
79 int falseid(-999999999);
82 const std::vector<double>& values = Range.at(pbin).at(k);
83 for (
unsigned i(0); i < values.size(); i++) {
85 if (r < values.at(i)) {
86 falseid = FalseIdent.at(i);
88 }
else if (r > values.at(i-1) && r < values.at(i)) {
89 falseid = FalseIdent.at(i);
95 int ParticleID::InListOfTrue(
int ID) {
96 for (
unsigned i(0); i < TrueIdent.size(); i++) {
97 if (TrueIdent.at(i) == abs(ID)) {
104 int ParticleID::InListOfFalse(
int ID) {
105 for (
unsigned i(0); i < FalseIdent.size(); i++) {
106 if (FalseIdent.at(i) == abs(ID)) {
111 if (ID < 5 && ID > 0) {
130 Qfile.open(filename);
132 std::cerr <<
"Error in ParticleID: unable to open file "
133 << filename << std::endl;
138 bool operator()(
const std::string& s,
139 const std::string& pattern)
const {
140 return s.find(pattern, 0) == 0;
144 std::stringstream ss;
145 std::string line, dummy;
146 bool gotTrue(
false), gotFalse(
false), gotBins(
false);
147 while (std::getline(Qfile, line).good()) {
149 line.erase(0, line.find_first_not_of(
" \t"));
156 if (starts(line,
"!T")) {
158 while ((ss >> tmpint).good()) {
159 TrueIdent.push_back(tmpint);
161 gotTrue = !TrueIdent.empty();
162 }
else if (starts(line,
"!F")) {
165 while ((ss >> tmpint).good()) {
166 FalseIdent.push_back(tmpint);
168 gotFalse = !FalseIdent.empty();
169 }
else if (starts(line,
"!P")) {
175 gotBins = !PMin.empty();
176 }
else if (starts(line,
"1") || starts(line,
"2") || starts(line,
"3")) {
178 if (!(gotTrue && gotFalse && gotBins)) {
179 std::cerr <<
"Error in ParticleID: " <<
180 "P matrix input file has bad or missing format lines.\n";
183 int table, pbin, pid;
184 double pmin, pmax, p1, p2, p3;
185 ss >> table >> pbin >> pmin >> pmax >> pid >> p1 >> p2 >> p3;
186 if ((
unsigned)pbin > PMin.size()) {
187 std::cerr <<
"Error in ParticleID: " <<
188 "Out of bounds momentum bin listing.\n";
192 PMin.at(pbin) = pmin;
193 PMax.at(pbin) = pmax;
194 pid = InListOfFalse(pid);
195 if ((
unsigned)pid > FalseIdent.size()) {
196 std::cerr <<
"Error in ParticleID: " <<
197 "P matrix has bad particle listing.\n";
200 if (PMatrix.empty()) {
205 PMatrix.at(pbin).at(0).at(pid) = p1;
206 PMatrix.at(pbin).at(1).at(pid) = p2;
207 PMatrix.at(pbin).at(2).at(pid) = p3;
218 momentum = prt.
GetP();
222 const int pid = prt.
Id();
223 if (InListOfTrue(pid) != -1 && Accept.
Is(prt)) {
224 for (
unsigned i(0); i < PMin.size(); i++) {
225 if (momentum > PMin.at(i) && momentum < PMax.at(i)) {
231 prtOut.
id = -
Wild(i, pid);
239 std::cout <<
"ParticleID using " << PMatPath << std::endl;
Int_t id
PDG particle code.
virtual Double_t GetP() const =0
int Wild(int pbin, int trueID)
void Smear(const erhic::VirtualParticle &, ParticleMCS &)
Double32_t p
Total momentum of particle.
bool Is(const erhic::VirtualParticle &prt) const
virtual void Print(Option_t *="") const
virtual Pid Id() const =0
void SetupProbabilityArray()
Abstract base class for a general particle.
virtual void Clear(Option_t *="")
void ReadP(TString filename)