#pragma once

#include <math.h>
#include <stdlib.h>

// Histogram struct.
//
struct bin
  {
  size_t amo;  // Amount of events in the bin.
  double sum;  // Sum of |p_v|s of all the events in the bin.
  };

// Minimization struct.
//
struct parameters
  {
  struct bin* histo;  // Histogram
  size_t n;           // Number of bins
  double step;        // Bin width
  };

/////////////////////////////////////////////////////////////////

// Minimization wrapper.
//
double chi2 (double p_max, void* params);

// Expected function.
//
double expected (double x, double p_max);

// First derivative of the expected function.
//
double exp1d (double x, double p_max);

// Second derivative of the expected function.
//
double exp2d (double x, double p_max);
