////////////////////////////////////////////////////////////////////////////////
/// \class  RAT::Classifiers::Ext0NuCosTheta
///
/// \brief  Classifies events as 0nu or external background based on topology
///
/// \author Tereza Kroupa <tereza.kroupova@physics.ox.ac.uk>
///
/// REVISION HISTORY:
///     - 10/04/2018 : Tereza Kroupa - Implemented as RAT Classifier
///
/// \detail Calculates 0nu/external background discriminator based on spatial
///         hit distribution wrt to reconstructed event position given weights
///         in RATDB table. Those can be likelihood ratios or other. For further
///         reference see DocDB 4903 or 3603. Based on studies by Jack Dunger.
///
////////////////////////////////////////////////////////////////////////////////



#ifndef __RAT_Classifiers_Ext0NuCosTheta_
#define __RAT_Classifiers_Ext0NuCosTheta_

#include <RAT/SeededClassifier.hh>
#include <RAT/DS/UniversalTime.hh>

namespace RAT {
    namespace Classifiers {

        class Ext0NuCosTheta : public SeededClassifier {
        public:

            /// Static Method returning Classifier Name
            static inline std::string Name() { return "Ext0NuCosTheta";}

            /// Class Method returning Classifier Name
            virtual std::string GetName() const;

            /// Initialise fParam
            /// @param[param] String containg classifier parameters set in macro
            virtual void Initialise(const std::string& param);

            /// Load weights for 0Nu and External bkg
            /// Load fCosThetaFirst, fCosThetaLast and fTimeWindow
            virtual void BeginOfRun(DS::Run& run);

            /// End Classifier call
            virtual void EndOfRun(DS::Run& run);

            /// Set fEventPos to zero vector and fEventTime to zero
            virtual void DefaultSeed();

            /// Set fEventTime and fEventPos from parameter seed
      /// @seed Seed (FitResult containing event time and position)
            virtual void SetSeed(const DS::FitResult& seed);

            /// Classify event as external bkg or signal
            /// @return ClassifierResult object containing the classification result
            virtual DS::ClassifierResult GetClassification();

        private:

            std::string fParam; ///< DB table name and index set in Initialise
            double fCosThetaFirst; ///< Lower boundary of the first cos theta bin
            double fCosThetaLast; ///< Upper boundary of the last cos theta bin
            double fCosThetaStep; ///< Binwidth

            std::vector<double> fTimeWindow; ///< Early time window used for discrimination
            std::vector<double> fWeights; ///< Weights from bkg and signal pdfs
            size_t fNormalisationFlag;

            TVector3 fEventPos; ///< Fitted event position
            double fEventTime; ///< Fitted event time

            double fDiscriminant; ///< Discriminant result

        };

    } //::Classifiers
} //::RAT

#endif