-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmd_resolist_feeddown_factor.cpp
More file actions
172 lines (149 loc) · 6.38 KB
/
cmd_resolist_feeddown_factor.cpp
File metadata and controls
172 lines (149 loc) · 6.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/* This file is a part of runjam <https://github.com/idthic/runjam>.
Copyright (C) 2022, Koichi Murase <myoga.murase at gmail.com>
SPDX-License-Identifier: GPL-2.0-or-later
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA */
#include "config.hpp"
#include <cstddef>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <memory>
#include <vector>
#include <numeric>
#include <fstream>
#include "util.hpp"
#include "args.hpp"
#include "ParticleSample.hpp"
#include "ResonanceList.hpp"
#include "jamimpl.hpp"
namespace idt::runjam {
int cmd_resolist_feeddown_factor(idt::runjam::runjam_context& ctx, idt::runjam::runjam_commandline_arguments const& args) {
(void) args;
ctx.set_config("runjam_switch_weak_decay", true);
ctx.set_config("runjam_phi_decay", true);
class ParticleSampleResonance: public idt::runjam::ParticleSampleBase {
std::size_t const m_count;
idt::runjam::ResonanceRecord const* m_reso = nullptr;
public:
ParticleSampleResonance(std::size_t count): m_count(count) {}
void setResonance(idt::runjam::ResonanceRecord const* reso) { this->m_reso = reso; }
virtual double getOverSamplingFactor() const override { return 1.0; }
virtual void update() override {
if (!m_reso) {
std::cerr << "FATAL runjam (resolist-feeddown-factor/ParticleSampleResonance): m_reso uinitialized" << std::endl;
std::exit(9);
}
this->clearParticleList();
for (std::size_t i = 0; i < m_count; i++) {
int const pdg = m_reso->pdg_codes[idt::util::irand(m_reso->pdg_codes.size())];
double const rx = 10.0 * idt::util::nrand();
double const ry = 10.0 * idt::util::nrand();
double const rz = 10.0 * idt::util::nrand();
this->addParticleCartesian(pdg, 0.0, 0.0, 0.0, m_reso->mass, rx, ry, rz, 0.0);
}
}
};
std::unique_ptr<idt::runjam::IJamRunner> runner = idt::runjam::create_runner(ctx);
if (!runner) {
std::cerr << "runjam: JAM unsupported." << std::endl;
std::exit(3);
}
runner->initialize(ctx, "decay");
std::vector<idt::runjam::Particle> final_state;
static std::size_t const jkbin_size = 1000;
static std::size_t const jkbin_count = 1000;
struct jackknife {
std::size_t count = 0;
void operator++(int) { count++;}
std::vector<double> bins;
void next_bin() {
bins.push_back((double) count / jkbin_size);
count = 0;
}
double value, error;
void summarize() {
double const total = std::accumulate(bins.begin(), bins.end(), 0.0);
double s1 = 0.0, s2 = 0.0;
for (auto const& v: bins) {
double const v1 = (total - v) / (bins.size() - 1);
s1 += v1;
s2 += v1 * v1;
}
s1 /= bins.size();
s2 /= bins.size();
value = total / bins.size();
error = std::sqrt((bins.size() - 1) * (s2 - s1 * s1));
}
};
ParticleSampleResonance psamp(jkbin_size);
idt::runjam::ResonanceList rlist(ctx);
std::ofstream file("feeddown.txt");
file << "#KEY PDGCODES Nch pi+ pi- pi+-avg K0 Kp Kn p pbar\n";
for (idt::runjam::ResonanceRecord const& reso: rlist) {
std::cerr << reso.key << "..." << std::endl;
psamp.setResonance(&reso);
jackknife jklist[9];
int jkindex = 0;
jackknife& nch = jklist[jkindex++];
jackknife& npip = jklist[jkindex++];
jackknife& npin = jklist[jkindex++];
jackknife& npic = jklist[jkindex++];
jackknife& nKp = jklist[jkindex++];
jackknife& nKn = jklist[jkindex++];
jackknife& nK0 = jklist[jkindex++];
jackknife& np = jklist[jkindex++];
jackknife& npbar = jklist[jkindex++];
// jackknife& npi0 = jklist[jkindex++];
// jackknife& nSig = jklist[jkindex++];
// jackknife& nLam = jklist[jkindex++];
for (std::size_t i = 0; i < jkbin_count; i++) {
psamp.update();
runner->do_decay(psamp, final_state);
for (idt::runjam::Particle& part: final_state) {
int const pdg = part.pdg;
switch (std::abs(pdg)) {
case 211: nch++; (pdg > 0 ? npip : npin)++; npic++; break;
case 321: nch++; (pdg > 0 ? nKp : nKn)++; break;
case 2212: nch++; (pdg > 0 ? np : npbar)++; break;
case 311: nK0++; break;
// case 130: case 310: nK0++; break; // K0S, K0L
// case 111: npi0++; break; (decays)
// case 3212: nLam++; break; // Lambda (decays)
// case 3112: case 3222: nch++; nSig++; break; // charged Sigma (decays)
}
}
for (auto& jk: jklist) jk.next_bin();
}
for (auto& jk: jklist) jk.summarize();
file << reso.key << " ";
bool first = true;
for (int pdg: reso.pdg_codes) {
if (first) first = false; else file << ",";
file << pdg;
}
file << " ";
file << reso.deg * nch.value << "(" << reso.deg * nch.error << ") " // N_ch
<< reso.deg * npip.value << "(" << reso.deg * npip.error << ") " // pi+
<< reso.deg * npin.value << "(" << reso.deg * npin.error << ") " // pi-
<< reso.deg * npic.value * 0.5 << "(" << reso.deg * npic.error * 0.5 << ") " // (pi+ + pi-)/2
<< reso.deg * nK0.value << "(" << reso.deg * nK0.error << ") " // K0 + K0bar
<< reso.deg * nKp.value << "(" << reso.deg * nKp.error << ") " // K+
<< reso.deg * nKn.value << "(" << reso.deg * nKn.error << ") " // K-
<< reso.deg * np.value << "(" << reso.deg * np.error << ") " // p
<< reso.deg * npbar.value << "(" << reso.deg * npbar.error << ") " // pbar
<< std::endl;
}
return 0;
}
}