/**
 * @file event.hh
 * @author Christoph Langenbruch, Renata Kopecna
 * @date 2009-03-18
 *
 */

#ifndef EVENT_H
#define EVENT_H

#include <string>
#include <vector>

namespace fcnc { //Forward declaration, fully defined in options.hh
    class options;
}

namespace fcnc {

  //  typedef event_type enum {};
///The event class stores the different event quantities needed to extract the physically interesting parametes in the likelihood fit.
class event {
public: 
  //save the year into each event
  int year;
  ///the mass used to separate signal and background 
  double m;
  ///the error on the measured mass 
  double sigma_m;
  //the reconstructed mass of the K*+
  double mkpi;
  ///set in the toy data generation to distinguish background from signal in the plots 
  int event_type;
  /// magnet polarity (down = -1 and up = +1)
  int magnet;
  ///costhetal
  double costhetal;
  ///costhetak
  double costhetak;
  ///phi
  double phi;
  //full angular angles that are saved even after folding
  double costhetal_fa;
  double costhetak_fa;
  double phi_fa;
  ///weight
  double weight;
  double delta_weight;
  double max_mu_pt;
  double kaon_pt;
  ///xis
  //double xis[18];
  //float xis[18];
  ///q2
  double q2;
  ///from opening angle of leptons:
  double pseudo_q2;
  ///p2
  double p2;
  ///cp_conjugate (B) or not (Bbar)
  bool cp_conjugate;
  double sweight;
  double mjpsipi;
  event(): 
    year(2000),
    m(0.0),
    sigma_m(0.0),
    mkpi(892.0),
    event_type(0),
    magnet(0),
    costhetal(0.0),
    costhetak(0.0),
    phi(0.0),
    costhetal_fa(0.0),
    costhetak_fa(0.0),
    phi_fa(0.0),
    weight(1.0),
    delta_weight(0.0),
    max_mu_pt(0.0),
    kaon_pt(0.0),
    //norm(1.0),
    q2(0.0),
    pseudo_q2(0.0),
    cp_conjugate(false),
    sweight(1.0)
  {
    // xis[0] = 3.0/2.0;
    // xis[1] = 3.0/4.0;
    // xis[2] = -1.0/2.0;
    // xis[3] = -1.0/4.0;
    // xis[4] = 0.0;
    // xis[5] = 0.0;
    // xis[6] = 0.0;
    // xis[7] = 0.0;
    // xis[8] = 0.0;
    // xis[9] = 0.0;
    // xis[10] = 0.0;
    // xis[11] = 0.0;
    // xis[12] = 1.0;
    // xis[13] = 0.0;
    // xis[14] = 0.0;
    // xis[15] = 0.0;
    // xis[16] = 0.0;
    // xis[17] = 0.0;
  };

  //reset folded angles back to full angular
  void reset_angles()
  {
      costhetal = costhetal_fa;
      costhetak = costhetak_fa;
      phi = phi_fa;
  };
  
};

///print the quantities of event meas 
  void print_event(const event& meas);
  void save_events(std::string filename, const std::vector<event>& events);
  void save_eos_events(std::string filename, const std::vector<event>& events);
  std::vector<event> filterResonances(std::vector<event> events);
  std::vector<event> load_events(std::string filename, std::string treename="Events", int neventsmax = -1);

  ///convert between different angular conventions
  void lhcbtotheory(const bool bzero, const double ctl_lhcb, const double ctk_lhcb, const double phi_lhcb, double& ctl_th, double& ctk_th, double& phi_th);
  void theorytolhcb(const bool bzero, const double ctl_th, const double ctk_th, const double phi_th, double& ctl_lhcb, double& ctk_lhcb, double& phi_lhcb);
};


int convert_tuples(int job_id, std::string theFCNCpath, fcnc::options opts, std::vector<int> years);

std::vector<fcnc::event> merge_two_evtVecs(std::vector<fcnc::event> one, std::vector<fcnc::event> two);

#endif
