//////////////////////////////////////////////////////////
// This class has been automatically generated on
// Fri Jun 20 13:41:57 2014 by ROOT version 5.34/10
// from TTree fiTQun/
// found on file: ../hk-fitqun/HyperK_muminus_1000MeV_random_4pi_000_v3r4.root
//////////////////////////////////////////////////////////

#ifndef fitQunDisplay_h
#define fitQunDisplay_h


#include <math.h>
#include <TROOT.h>
#include <TChain.h>
#include <TFile.h>
#include <TSelector.h>
#include <TEveManager.h>
#include <TEveLine.h>
#include <TEveScene.h>
#include "TEveStraightLineSet.h"


#include "WCSimWrap.h"

#include "hyperk_esd_html_summary.h"

#include "THKGamma.h"
#include "THKMCTrack.h"
#include "THKCherenkov.h"
#include "THKCherenkov2D.h"
#include "THKLine.h"
#include "CherenkovDisplay.h"

class fitQunDisplay {
private:
    //    const	float pScale=1.0;
    #define pScale 1.0
   TString HYPO[7];
   int     HYPERCOLOUR[7];
   float   MASS[7];
public :
    TTree          *fChain;   //!pointer to the analyzed TTree or TChain
private:
    WCSimRootGeom *wcsimrootgeom;
public :    
    // Declaration of leaf types
    Int_t           cluster_ncand;
    Float_t         cluster_tstart[2];   //[cluster_ncand]
    Float_t         cluster_tend[2];   //[cluster_ncand]
    Int_t           cluster_nhits[2];   //[cluster_ncand]
    Float_t         cluster_totq[2];   //[cluster_ncand]
    Int_t           cluster_goodflag[2];   //[cluster_ncand]
    Int_t           cluster_npeaks[2][6];   //[cluster_ncand]
    Int_t           cluster_ipeak[2][6][10];   //[cluster_ncand]
    Float_t         cluster_timeofpeak[2][6][10];   //[cluster_ncand]
    Int_t           muechk_ncand[6];
    Float_t         muechk_toya[6];
    Float_t         muechk_tpeak[6][10];
    Int_t           muechk_bg[6][10];
    Float_t         muechk_mean[6][10];
    Float_t         muechk_excess[6][10];
    Float_t         muechk_signif[6][10];
    Int_t           muechk_icluster[6][10];
    Float_t         trgoff;
    Int_t           fqntwnd;
    Int_t           fqtwnd_iclstr[2];   //[fqntwnd]
    Int_t           fqtwnd_npeak[2];   //[fqntwnd]
    Float_t         fqtwnd_prftt0[2];   //[fqntwnd]
    Float_t         fqtwnd_prftpos[2][3];   //[fqntwnd]
    Float_t         fqtwnd[2][2];   //[fqntwnd]
    Float_t         fqtwnd_peakt0[2][10];   //[fqntwnd]
    Float_t         fqtwnd_peakiness[2][10];   //[fqntwnd]
    Int_t           fqnse;
    Int_t           fqitwnd[3];   //[fqnse]
    Int_t           fqipeak[3];   //[fqnse]
    Int_t           fqnhitpmt[3];   //[fqnse]
    Float_t         fqtotq[3];   //[fqnse]
    Float_t         fq0rtotmu[3];   //[fqnse]
    Float_t         fq0rnll[3];   //[fqnse]
    Int_t           fqn50[3];   //[fqnse]
    Float_t         fqq50[3];   //[fqnse]
    Int_t           fq1rpcflg[3][7];   //[fqnse]
    Float_t         fq1rmom[3][7];   //[fqnse]
    Float_t         fq1rt0[3][7];   //[fqnse]
    Float_t         fq1rtotmu[3][7];   //[fqnse]
    Float_t         fq1rnll[3][7];   //[fqnse]
    Float_t         fq1rpos[3][7][3];   //[fqnse]
    Float_t         fq1rdir[3][7][3];   //[fqnse]
    Float_t         fq1rdconv[3][7];   //[fqnse]
    Float_t         fq1reloss[3][7];   //[fqnse]
    Int_t           fqpi0pcflg[2];
    Float_t         fqpi0mom1[2];
    Float_t         fqpi0mom2[2];
    Float_t         fqpi0momtot[2];
    Float_t         fqpi0dconv1[2];
    Float_t         fqpi0dconv2[2];
    Float_t         fqpi0t0[2];
    Float_t         fqpi0totmu[2];
    Float_t         fqpi0nll[2];
    Float_t         fqpi0mass[2];
    Float_t         fqpi0photangle[2];
    Float_t         fqpi0pos[2][3];
    Float_t         fqpi0dir1[2][3];
    Float_t         fqpi0dir2[2][3];
    Float_t         fqpi0dirtot[2][3];
    Int_t           fqnmrfit;
    Int_t           fqmrifit[44];   //[fqnmrfit]
    Int_t           fqmrnring[44];   //[fqnmrfit]
    Int_t           fqmrpcflg[44];   //[fqnmrfit]
    Float_t         fqmrnll[44];   //[fqnmrfit]
    Float_t         fqmrtotmu[44];   //[fqnmrfit]
    Int_t           fqmrpid[44][6];   //[fqnmrfit]
    Float_t         fqmrmom[44][6];   //[fqnmrfit]
    Float_t         fqmrdconv[44][6];   //[fqnmrfit]
    Float_t         fqmreloss[44][6];   //[fqnmrfit]
    Float_t         fqmrt0[44][6];   //[fqnmrfit]
    Float_t         fqmrpos[44][6][3];   //[fqnmrfit]
    Float_t         fqmrdir[44][6][3];   //[fqnmrfit]
    Int_t           fqmsnfit;
    Int_t           fqmspcflg[2];   //[fqmsnfit]
    Int_t           fqmsnseg[2];   //[fqmsnfit]
    Int_t           fqmspid[2];   //[fqmsnfit]
    Int_t           fqmsifit[2];   //[fqmsnfit]
    Int_t           fqmsimer[2];   //[fqmsnfit]
    Float_t         fqmstotmu[2];   //[fqmsnfit]
    Float_t         fqmsnll[2];   //[fqmsnfit]
    Float_t         fqmsmom[2][20];   //[fqmsnfit]
    Float_t         fqmseloss[2][20];   //[fqmsnfit]
    Float_t         fqmst0[2][20];   //[fqmsnfit]
    Float_t         fqmspos[2][20][3];   //[fqmsnfit]
    Float_t         fqmsdir[2][20][3];   //[fqmsnfit]
    Int_t           fqtestn1r;
    Int_t           fqtest1rstage[10];   //[fqtestn1r]
    Int_t           fqtest1rse[10];   //[fqtestn1r]
    Int_t           fqtest1rpid[10];   //[fqtestn1r]
    Int_t           fqtest1rpcflg[10];   //[fqtestn1r]
    Float_t         fqtest1rmom[10];   //[fqtestn1r]
    Float_t         fqtest1rt0[10];   //[fqtestn1r]
    Float_t         fqtest1rtotmu[10];   //[fqtestn1r]
    Float_t         fqtest1rnll[10];   //[fqtestn1r]
    Float_t         fqtest1rpos[10][3];   //[fqtestn1r]
    Float_t         fqtest1rdir[10][3];   //[fqtestn1r]
    Float_t         fqtest1rdconv[10];   //[fqtestn1r]
    Float_t         fqtest1reloss[10];   //[fqtestn1r]
    Int_t           fqtestnpi0;
    Int_t           fqtestpi0stage[2];   //[fqtestnpi0]
    Int_t           fqtestpi0pcflg[2];   //[fqtestnpi0]
    Float_t         fqtestpi0mom1[2];   //[fqtestnpi0]
    Float_t         fqtestpi0mom2[2];   //[fqtestnpi0]
    Float_t         fqtestpi0momtot[2];   //[fqtestnpi0]
    Float_t         fqtestpi0dconv1[2];   //[fqtestnpi0]
    Float_t         fqtestpi0dconv2[2];   //[fqtestnpi0]
    Float_t         fqtestpi0t0[2];   //[fqtestnpi0]
    Float_t         fqtestpi0totmu[2];   //[fqtestnpi0]
    Float_t         fqtestpi0nll[2];   //[fqtestnpi0]
    Float_t         fqtestpi0mass[2];   //[fqtestnpi0]
    Float_t         fqtestpi0photangle[2];   //[fqtestnpi0]
    Float_t         fqtestpi0pos[2][3];   //[fqtestnpi0]
    Float_t         fqtestpi0dir1[2][3];   //[fqtestnpi0]
    Float_t         fqtestpi0dir2[2][3];   //[fqtestnpi0]
    Float_t         fqtestpi0dirtot[2][3];   //[fqtestnpi0]
    Int_t           ifqver;
    Float_t         fqproctime[20];
    Int_t           nevt;
    
    // List of branches
    TBranch        *b_cluster_ncand;   //!
    TBranch        *b_cluster_tstart;   //!
    TBranch        *b_cluster_tend;   //!
    TBranch        *b_cluster_nhits;   //!
    TBranch        *b_cluster_totq;   //!
    TBranch        *b_cluster_goodflag;   //!
    TBranch        *b_cluster_npeaks;   //!
    TBranch        *b_cluster_ipeak;   //!
    TBranch        *b_cluster_timeofpeak;   //!
    TBranch        *b_muechk_ncand;   //!
    TBranch        *b_muechk_toya;   //!
    TBranch        *b_muechk_tpeak;   //!
    TBranch        *b_muechk_bg;   //!
    TBranch        *b_muechk_mean;   //!
    TBranch        *b_muechk_excess;   //!
    TBranch        *b_muechk_signif;   //!
    TBranch        *b_muechk_icluster;   //!
    TBranch        *b_trgoff;   //!
    TBranch        *b_fqntwnd;   //!
    TBranch        *b_fqtwnd_iclstr;   //!
    TBranch        *b_fqtwnd_npeak;   //!
    TBranch        *b_fqtwnd_prftt0;   //!
    TBranch        *b_fqtwnd_prftpos;   //!
    TBranch        *b_fqtwnd;   //!
    TBranch        *b_fqtwnd_peakt0;   //!
    TBranch        *b_fqtwnd_peakiness;   //!
    TBranch        *b_fqnse;   //!
    TBranch        *b_fqitwnd;   //!
    TBranch        *b_fqipeak;   //!
    TBranch        *b_fqnhitpmt;   //!
    TBranch        *b_fqtotq;   //!
    TBranch        *b_fq0rtotmu;   //!
    TBranch        *b_fq0rnll;   //!
    TBranch        *b_fqn50;   //!
    TBranch        *b_fqq50;   //!
    TBranch        *b_fq1rpcflg;   //!
    TBranch        *b_fq1rmom;   //!
    TBranch        *b_fq1rt0;   //!
    TBranch        *b_fq1rtotmu;   //!
    TBranch        *b_fq1rnll;   //!
    TBranch        *b_fq1rpos;   //!
    TBranch        *b_fq1rdir;   //!
    TBranch        *b_fq1rdconv;   //!
    TBranch        *b_fq1reloss;   //!
    TBranch        *b_fqpi0pcflg;   //!
    TBranch        *b_fqpi0mom1;   //!
    TBranch        *b_fqpi0mom2;   //!
    TBranch        *b_fqpi0momtot;   //!
    TBranch        *b_fqpi0dconv1;   //!
    TBranch        *b_fqpi0dconv2;   //!
    TBranch        *b_fqpi0t0;   //!
    TBranch        *b_fqpi0totmu;   //!
    TBranch        *b_fqpi0nll;   //!
    TBranch        *b_fqpi0mass;   //!
    TBranch        *b_fqpi0photangle;   //!
    TBranch        *b_fqpi0pos;   //!
    TBranch        *b_fqpi0dir1;   //!
    TBranch        *b_fqpi0dir2;   //!
    TBranch        *b_fqpi0dirtot;   //!
    TBranch        *b_fqnmrfit;   //!
    TBranch        *b_fqmrifit;   //!
    TBranch        *b_fqmrnring;   //!
    TBranch        *b_fqmrpcflg;   //!
    TBranch        *b_fqmrnll;   //!
    TBranch        *b_fqmrtotmu;   //!
    TBranch        *b_fqmrpid;   //!
    TBranch        *b_fqmrmom;   //!
    TBranch        *b_fqmrdconv;   //!
    TBranch        *b_fqmreloss;   //!
    TBranch        *b_fqmrt0;   //!
    TBranch        *b_fqmrpos;   //!
    TBranch        *b_fqmrdir;   //!
    TBranch        *b_fqmsnfit;   //!
    TBranch        *b_fqmspcflg;   //!
    TBranch        *b_fqmsnseg;   //!
    TBranch        *b_fqmspid;   //!
    TBranch        *b_fqmsifit;   //!
    TBranch        *b_fqmsimer;   //!
    TBranch        *b_fqmstotmu;   //!
    TBranch        *b_fqmsnll;   //!
    TBranch        *b_fqmsmom;   //!
    TBranch        *b_fqmseloss;   //!
    TBranch        *b_fqmst0;   //!
    TBranch        *b_fqmspos;   //!
    TBranch        *b_fqmsdir;   //!
    TBranch        *b_fqtestn1r;   //!
    TBranch        *b_fqtest1rstage;   //!
    TBranch        *b_fqtest1rse;   //!
    TBranch        *b_fqtest1rpid;   //!
    TBranch        *b_fqtest1rpcflg;   //!
    TBranch        *b_fqtest1rmom;   //!
    TBranch        *b_fqtest1rt0;   //!
    TBranch        *b_fqtest1rtotmu;   //!
    TBranch        *b_fqtest1rnll;   //!
    TBranch        *b_fqtest1rpos;   //!
    TBranch        *b_fqtest1rdir;   //!
    TBranch        *b_fqtest1rdconv;   //!
    TBranch        *b_fqtest1reloss;   //!
    TBranch        *b_fqtestnpi0;   //!
    TBranch        *b_fqtestpi0stage;   //!
    TBranch        *b_fqtestpi0pcflg;   //!
    TBranch        *b_fqtestpi0mom1;   //!
    TBranch        *b_fqtestpi0mom2;   //!
    TBranch        *b_fqtestpi0momtot;   //!
    TBranch        *b_fqtestpi0dconv1;   //!
    TBranch        *b_fqtestpi0dconv2;   //!
    TBranch        *b_fqtestpi0t0;   //!
    TBranch        *b_fqtestpi0totmu;   //!
    TBranch        *b_fqtestpi0nll;   //!
    TBranch        *b_fqtestpi0mass;   //!
    TBranch        *b_fqtestpi0photangle;   //!
    TBranch        *b_fqtestpi0pos;   //!
    TBranch        *b_fqtestpi0dir1;   //!
    TBranch        *b_fqtestpi0dir2;   //!
    TBranch        *b_fqtestpi0dirtot;   //!
    TBranch        *b_ifqver;   //!
    TBranch        *b_fqproctime;   //!
    TBranch        *b_nevt;   //!
public:
    fitQunDisplay(float maxR,float minZ,float maxZ,float maxY,WCSimRootGeom* wcsimrootgeom,TTree * /*tree*/ =0) : fChain(0),wcsimrootgeom(NULL),CD(maxR,minZ,maxZ,wcsimrootgeom)  { }
    fitQunDisplay() : fChain(0),wcsimrootgeom(NULL){} ;
    virtual ~fitQunDisplay() { }
    virtual void    Init(TTree *tree);
    virtual Bool_t  Process(Long64_t entry);
    virtual Int_t   GetEntry(Long64_t entry, Int_t getall = 0) { return fChain ? fChain->GetTree()->GetEntry(entry, getall) : 0; }
    void            CreateTable(HtmlSummary* fgHtmlSummary);
    CherenkovDisplay* GetChernkovDisplay() {return &CD;};

    
private:
    //int nextMaxTube,nextNextMaxTube;
  
    CherenkovDisplay CD;
    
    TEveElementList *fitQunResults, *fitQunResults2D;
    void addTrack(double pos[3],double theta,double phi,double momentum,TString Name,int colour,float Mass,TEveElementList* se3d, TEveElementList* se2d);
    void describe_event(int entry);
    void load_event();
    void addTableRow(HtmlObjTable *table,int nused,int subevent,const char* name,double pos[3],double theta,double phi,double mod);
    void addPi0Rows (HtmlObjTable *table,int used ,int subevent,double pos[3],double theta1,double phi1,double mom1,double theta2,double phi2,double mom2);
   void addPi0(double pos[3],double theta1,double phi1,double mom1,double theta2,double phi2,double mom2,TEveElementList* se3d, TEveElementList* se2d);
    
};

#endif