aboutsummaryrefslogtreecommitdiff
path: root/src/fit.c
diff options
context:
space:
mode:
authortlatorre <tlatorre@uchicago.edu>2018-08-14 14:58:04 -0500
committertlatorre <tlatorre@uchicago.edu>2018-08-14 14:58:04 -0500
commit4e1d2393200d1ce6c2e47d124f6cf5c2008b4785 (patch)
tree4097f4caa7c30146c20c3fab9342f3b9aa77aef2 /src/fit.c
parent414ceefe8f651605ddf1cd80704cccfd8690a153 (diff)
downloadsddm-4e1d2393200d1ce6c2e47d124f6cf5c2008b4785.tar.gz
sddm-4e1d2393200d1ce6c2e47d124f6cf5c2008b4785.tar.bz2
sddm-4e1d2393200d1ce6c2e47d124f6cf5c2008b4785.zip
add function to fit event and clear event after each fit
Diffstat (limited to 'src/fit.c')
-rw-r--r--src/fit.c69
1 files changed, 41 insertions, 28 deletions
diff --git a/src/fit.c b/src/fit.c
index d28a58d..afbf5bb 100644
--- a/src/fit.c
+++ b/src/fit.c
@@ -51,6 +51,41 @@ double nll(unsigned int n, const double *x, double *grad, void *params)
return fval;
}
+int fit_event(event *ev, double *fmin)
+{
+ double x[7];
+ double ss[7];
+ int rv;
+
+ nlopt_opt opt = nlopt_create(NLOPT_LN_SBPLX, 7);
+ nlopt_set_min_objective(opt,nll,&ev);
+ nlopt_set_ftol_abs(opt, 1e-5);
+
+ x[0] = 1000.0;
+ x[1] = 100.0;
+ x[2] = 100.0;
+ x[3] = 100.0;
+ x[4] = 1.57;
+ x[5] = 0.0;
+ x[6] = 130.0;
+
+ ss[0] = 10.0;
+ ss[1] = 10.0;
+ ss[2] = 10.0;
+ ss[3] = 10.0;
+ ss[4] = 0.1;
+ ss[5] = 0.1;
+ ss[6] = 1.0;
+
+ nlopt_set_initial_step(opt, ss);
+
+ rv = nlopt_optimize(opt,x,fmin);
+
+ nlopt_destroy(opt);
+
+ return rv;
+}
+
int main(int argc, char **argv)
{
int i;
@@ -62,9 +97,7 @@ int main(int argc, char **argv)
event ev = {0};
int crate, card, channel;
int id;
- double x[7];
- double ss[7];
- double opt_f;
+ double fmin;
if (argc < 2) {
fprintf(stderr, "usage: fit [filename]\n");
@@ -87,10 +120,6 @@ int main(int argc, char **argv)
ev.run = -1;
- nlopt_opt opt = nlopt_create(NLOPT_LN_SBPLX, 7);
- nlopt_set_min_objective(opt,nll,&ev);
- nlopt_set_ftol_abs(opt, 1e-5);
-
init_interpolation();
init_charge();
dict *db = db_init();
@@ -133,29 +162,15 @@ int main(int argc, char **argv)
if (ev.run != -1) {
if (ev.run != bev.run || ev.gtid != bev.gtr_id) {
/* New event, so we need to fit the old event. */
- x[0] = 1000.0;
- x[1] = 100.0;
- x[2] = 100.0;
- x[3] = 100.0;
- x[4] = 1.57;
- x[5] = 0.0;
- x[6] = 130.0;
-
- ss[0] = 10.0;
- ss[1] = 10.0;
- ss[2] = 10.0;
- ss[3] = 10.0;
- ss[4] = 0.1;
- ss[5] = 0.1;
- ss[6] = 1.0;
-
- nlopt_set_initial_step(opt, ss);
-
- nlopt_optimize(opt,x,&opt_f);
+ fit_event(&ev,&fmin);
}
}
ev.run = bev.run;
ev.gtid = bev.gtr_id;
+
+ for (i = 0; i < 10000; i++) {
+ ev.pmt_hits[i].hit = 0;
+ }
}
}
@@ -163,8 +178,6 @@ int main(int argc, char **argv)
db_free(db);
- nlopt_destroy(opt);
-
zebra_close(f);
return 0;