71 FILE *
fp = fopen(
"lbn",
"r");
73 fprintf(
stderr,
"Failed to open lbn input file!!!\n");
77 char *
line =
new char[500];
79 int liveL1, livebp, liveap;
80 float instlumi,
dt, avevtperbx, live, L1p, HLTp, LARp;
82 float gtotaltotallumi{}, gtotaltotallumiprescaled{};
83 float gtotallumi{}, gtotallumiprescaled{};
87 printf(
"- myrand seed is %u\n",
myrand.GetSeed());
89 printf(
"- myrand seed is now %u\n",
myrand.GetSeed());
91 std::map<int, run_info> runmap;
92 std::map<int, int> eventcounts;
93 while (fgets(
line, 480,
fp)) {
98 int s = sscanf(&
line[0],
99 "--- LumiCalculator : %d[%d]: L1Acc: %d, Livetime trigger L1Acc: %d, InstLumi: %f, deltaT: %f, AvEvtsPerBX: %f, BeforePrescale: %d, AfterPrescale: %d, Livetime trigger BeforePrescale: %d Livetime trigger AfterPrescale: %d, Livefrac: %f, L1Presc: %f, HLTPresc: %f, Valid: %d, LAr ready fraction: %f",
100 &
run, &
lbn, &L1Acc, &liveL1, &
instlumi, &
dt, &avevtperbx, &beforeps, &afterps, &livebp, &liveap, &live, &L1p, &HLTp, &
valid, &LARp);
103 printf(
"Got %d values : run=%d, lbn=%d, L1Acc=%d, instlumi=%f, L1p=%f, dt=%f, live=%f, afterps=%d \n",
s,
run,
lbn, L1Acc,
instlumi, L1p,
dt, live, afterps);
107 runmap[grun].intlumi = gtotallumi;
108 printf(
"Setting lumi for run %d to %f\n", grun, gtotallumi);
109 gtotaltotallumi += gtotallumi;
110 gtotaltotallumiprescaled += gtotallumiprescaled;
113 gtotallumiprescaled = 0;
117 printf(
"Setting grun to %d\n",
run);
129 runmap[
run].lbnmap[
lbn].nevt = 0;
130 if (eventcounts[
lbn] !=0 ) {
131 printf(
"For lbn %d, L1p<0 but eventcounts is %d\n",
lbn,eventcounts[
lbn]);
135 if (ne != eventcounts[
lbn]) {
137 printf(
"For lbn %d, ne from lumicalc is %d but we will trust runquery value of %d\n",
lbn, ne, eventcounts[
lbn]);
139 ne = eventcounts[
lbn];
143 printf(
"For lbn %d, setting lumi to 0 since 0 events were recorded\n",
lbn);
145 runmap[
run].lbnmap[
lbn].nevt = ne;
147 runmap[
run].nevt += ne;
148 gtotallumiprescaled +=
instlumi *
dt * live / L1p;
151 printf(
"grun=%d, gtotallumi=%f, gtotallumiprescaled=%f\n", grun, gtotallumi, gtotallumiprescaled);
157 runmap[grun].intlumi = gtotallumi;
158 printf(
"Setting lumi for run %d to %f\n", grun, gtotallumi);
159 gtotaltotallumi += gtotallumi;
160 gtotaltotallumiprescaled += gtotallumiprescaled;
164 printf(
"- %lu runs, gtotaltotallumi=%f, gtotaltotallumiprescaled=%f\n", runmap.size(), gtotaltotallumi, gtotaltotallumiprescaled);
166 if (runmap.size() < 1) {
168 printf(
"- runmap size is %lu, quitting!\n", runmap.size());
174 for (
const auto &[
r,
info] : runmap) {
175 tempr +=
info.intlumi;
177 if (fabs(tempr - gtotaltotallumi) / tempr > 0.001) {
178 fprintf(
stderr,
"tempr=%f and gtotaltotallumi=%f\n", tempr, gtotaltotallumi);
182 for (
int e = 0;
e < nwanted; ++
e) {
184 double rnd =
myrand.Uniform(tempr);
186 for (
const auto &[
r,
info] : runmap) {
187 if (rnd <
info.intlumi) {
199 for (
const auto &[
l,
info] : runmap[
run].lbnmap) {
200 tempt +=
info.intlumi;
202 if (fabs(tempt - runmap[
run].
intlumi) / tempt > 0.001) {
208 rnd =
myrand.Uniform(tempt);
210 for (
const auto &[
l,
info] : runmap[
run].lbnmap) {
211 if (rnd <
info.intlumi) {
221 runmap[
run].nevtwanted++;
222 runmap[
run].lbnmap[
lbn].nevtwanted++;
223 printf(
"- stream %d, run %d, lbn %d, choose %d of out %d\n",
stream,
run,
lbn, runmap[
run].lbnmap[
lbn].nevtwanted, runmap[
run].lbnmap[
lbn].nevt);
226 for (
const auto &[
r, rinfo] : runmap) {
229 printf(
"stream %d, run %d, has %d events and %f/ub, %f intlumi of total, and %d wanted\n",
stream,
230 r, rinfo.nevt, rinfo.intlumi, rinfo.intlumi / gtotaltotallumi, rinfo.nevtwanted);
231 for (
const auto &[
l,
linfo] : rinfo.lbnmap) {
232 fprintf(
outfile,
"stream %d, run %d, lbn %d, has %d events and %f/ub, %f intlumi of run, and %d wanted",
stream,
r,
235 fprintf(
outfile,
" : WARNING, more than available, will be duplicates!\n");
239 totnevt +=
linfo.nevt;
240 totintlumi +=
linfo.intlumi;
242 if (totnevt != rinfo.nevt) {
243 fprintf(
stderr,
" XXX events do not agree !!! \n");
245 if (totintlumi > 0.0 && fabs(totintlumi - rinfo.intlumi) / totintlumi > .001) {
246 fprintf(
stderr,
" XXX intlumi does not agree !!! %f %f \n", totintlumi, rinfo.intlumi);