//  
// Author: Soeren Stamm <mailto: stamm@physik.hu-berlin.de>
// Update: $Id: AtlSgTop_sChannelBDT.h,v 1.4 2015/08/06 15:38:53 rieck Exp $
// Copyright: 2013 (C) Soeren Stamm
//
#ifndef SINGLETOP_AtlSgTop_sChannelBDT
#define SINGLETOP_AtlSgTop_sChannelBDT
#ifndef ATLAS_AtlSelector
#include <AtlSelector.h>
#endif
#ifndef ATLAS_AtlObjectsToolD3PDSgTop
#include <AtlObjectsToolD3PDSgTop.h>
#endif
#ifndef ATLAS_AtlObjRecoScaleFactorTool
#include <AtlObjRecoScaleFactorTool.h>
#endif
#ifndef ATLAS_AtlEvtReaderMemBDT
#include <AtlEvtReaderMemBDT.h>
#endif

#include "TMVA/Reader.h"

class AtlSgTop_sChannelBDT : public AtlSelector {
    
  private:
    TList   *fLeptons;   // List of selected leptons
    TList   *fElectrons; // List of selected electron objects
    TList   *fMuons;     // List of selected muon objects
    TList   *fJets;      // List of selected jets
    TList   *fBJets;     // List of selected b-jets

    // Pointer to tools in event loop
    AtlObjectsToolD3PDSgTop   *fObjTool;
    AtlObjRecoScaleFactorTool *fSFTool;

    // TMVA
    /* TMVA::Reader* fReader; */
    TMVA::Reader* fReaderEl; // electron case
    TMVA::Reader* fReaderMu; // muon case

    // TMVA variables
	// Kinematic variables
	Float_t fBDT_MtW;
	Float_t fBDT_DeltaPhiTopBJet2_BJet1;
	Float_t fBDT_DeltaPhiTopBJet1_BJet2;
	Float_t fBDT_SumEtLep_MET;
	Float_t fBDT_MET;
	Float_t fBDT_SumEtLep_MET_BJets;
	Float_t fBDT_Pt_Lep;
    Float_t fBDT_SumPt;
    Float_t fBDT_DeltaEtaLep_BJet1;
    Float_t fBDT_DeltaPhiBJet1_BJet2;
    Float_t fBDT_DeltaEtaLep_BJet2;
    Float_t fBDT_CosLepW_WTopBJet1;
    Float_t fBDT_DeltaPhiLep_MET;
    Float_t fBDT_DeltaEtaTopBJet2_BJet1;
    Float_t fBDT_CosLepTopBJet2_TopBJet2CMS;
    Float_t fBDT_CosLepTopBJet1_TopBJet1CMS;
	Float_t fBDT_MLep_BJet2;
	Float_t fBDT_CosMET_BJet2;
	Float_t fBDT_SumPtBJet1_BJet2;
	Float_t fBDT_DeltaEtaNu_BJetNonTop;
	
	// MEM likelihood ratios
    Float_t fBDTsChannelRatio;
    Float_t fBDTtChannelRatio;
    Float_t fBDTttbarSLRatio;
    Float_t fBDTWjjRatio;
    Float_t fBDTWbbRatio;

    // TMVA Histogram
    TH1F *fHist_BDT;      // BDT output
    TH1F *fHist_BDT_even; // BDT output, even event numbers
    TH1F *fHist_BDT_odd;  // BDT output, odd event numbers
    TH1F *fHist_BDT_rebinned;      // BDT output, rebinned
    TH1F *fHist_BDT_rebinned_even; // BDT output, rebinned, even event numbers
    TH1F *fHist_BDT_rebinned_odd;  // BDT output, rebinned, odd event numbers
    TH1F *fHist_BDT_manyBins; // BDT output, many bins, needed for rebinning
    
    Int_t     fNBins_BDT;     // number of bins for rebinned BDT response
    Double_t *fBinEdges_BDT;  // edges used for BDT response rebinning
	
    // Likelihood ratio Histograms
    TH1F *fHist_llh_ttbarSL_ratio;
    
  public:
    AtlSgTop_sChannelBDT(const char* OutputFilename);
    virtual ~AtlSgTop_sChannelBDT();
    
    virtual void SetBranchStatus();
    virtual void Clear( Option_t *option = "");
    virtual void Begin(TTree *tree);
    virtual void BookHistograms();
    virtual void FillHistograms();
    virtual Bool_t ProcessPreCut();
    virtual Bool_t ProcessCut();
    virtual void SetCutDefaults();
    virtual void Print(Option_t *option) const;
    virtual void Terminate();

  protected:
    void InitEvent();
    void BookHistogramsLikelihoodRatios();
    void BookHistogramsBDT();
    void FillHistogramsLikelihoodRatios();
    void ComputeLikelihoodRatios();

    AtlEvtReaderMemBDT* GetEvtReader() { return (AtlEvtReaderMemBDT*) fEvtReader; }
    
    ClassDef(AtlSgTop_sChannelBDT,0) // Single-top 8 TeV s-Channel BDT analysis
};
#endif
 AtlSgTop_sChannelBDT.h:1
 AtlSgTop_sChannelBDT.h:2
 AtlSgTop_sChannelBDT.h:3
 AtlSgTop_sChannelBDT.h:4
 AtlSgTop_sChannelBDT.h:5
 AtlSgTop_sChannelBDT.h:6
 AtlSgTop_sChannelBDT.h:7
 AtlSgTop_sChannelBDT.h:8
 AtlSgTop_sChannelBDT.h:9
 AtlSgTop_sChannelBDT.h:10
 AtlSgTop_sChannelBDT.h:11
 AtlSgTop_sChannelBDT.h:12
 AtlSgTop_sChannelBDT.h:13
 AtlSgTop_sChannelBDT.h:14
 AtlSgTop_sChannelBDT.h:15
 AtlSgTop_sChannelBDT.h:16
 AtlSgTop_sChannelBDT.h:17
 AtlSgTop_sChannelBDT.h:18
 AtlSgTop_sChannelBDT.h:19
 AtlSgTop_sChannelBDT.h:20
 AtlSgTop_sChannelBDT.h:21
 AtlSgTop_sChannelBDT.h:22
 AtlSgTop_sChannelBDT.h:23
 AtlSgTop_sChannelBDT.h:24
 AtlSgTop_sChannelBDT.h:25
 AtlSgTop_sChannelBDT.h:26
 AtlSgTop_sChannelBDT.h:27
 AtlSgTop_sChannelBDT.h:28
 AtlSgTop_sChannelBDT.h:29
 AtlSgTop_sChannelBDT.h:30
 AtlSgTop_sChannelBDT.h:31
 AtlSgTop_sChannelBDT.h:32
 AtlSgTop_sChannelBDT.h:33
 AtlSgTop_sChannelBDT.h:34
 AtlSgTop_sChannelBDT.h:35
 AtlSgTop_sChannelBDT.h:36
 AtlSgTop_sChannelBDT.h:37
 AtlSgTop_sChannelBDT.h:38
 AtlSgTop_sChannelBDT.h:39
 AtlSgTop_sChannelBDT.h:40
 AtlSgTop_sChannelBDT.h:41
 AtlSgTop_sChannelBDT.h:42
 AtlSgTop_sChannelBDT.h:43
 AtlSgTop_sChannelBDT.h:44
 AtlSgTop_sChannelBDT.h:45
 AtlSgTop_sChannelBDT.h:46
 AtlSgTop_sChannelBDT.h:47
 AtlSgTop_sChannelBDT.h:48
 AtlSgTop_sChannelBDT.h:49
 AtlSgTop_sChannelBDT.h:50
 AtlSgTop_sChannelBDT.h:51
 AtlSgTop_sChannelBDT.h:52
 AtlSgTop_sChannelBDT.h:53
 AtlSgTop_sChannelBDT.h:54
 AtlSgTop_sChannelBDT.h:55
 AtlSgTop_sChannelBDT.h:56
 AtlSgTop_sChannelBDT.h:57
 AtlSgTop_sChannelBDT.h:58
 AtlSgTop_sChannelBDT.h:59
 AtlSgTop_sChannelBDT.h:60
 AtlSgTop_sChannelBDT.h:61
 AtlSgTop_sChannelBDT.h:62
 AtlSgTop_sChannelBDT.h:63
 AtlSgTop_sChannelBDT.h:64
 AtlSgTop_sChannelBDT.h:65
 AtlSgTop_sChannelBDT.h:66
 AtlSgTop_sChannelBDT.h:67
 AtlSgTop_sChannelBDT.h:68
 AtlSgTop_sChannelBDT.h:69
 AtlSgTop_sChannelBDT.h:70
 AtlSgTop_sChannelBDT.h:71
 AtlSgTop_sChannelBDT.h:72
 AtlSgTop_sChannelBDT.h:73
 AtlSgTop_sChannelBDT.h:74
 AtlSgTop_sChannelBDT.h:75
 AtlSgTop_sChannelBDT.h:76
 AtlSgTop_sChannelBDT.h:77
 AtlSgTop_sChannelBDT.h:78
 AtlSgTop_sChannelBDT.h:79
 AtlSgTop_sChannelBDT.h:80
 AtlSgTop_sChannelBDT.h:81
 AtlSgTop_sChannelBDT.h:82
 AtlSgTop_sChannelBDT.h:83
 AtlSgTop_sChannelBDT.h:84
 AtlSgTop_sChannelBDT.h:85
 AtlSgTop_sChannelBDT.h:86
 AtlSgTop_sChannelBDT.h:87
 AtlSgTop_sChannelBDT.h:88
 AtlSgTop_sChannelBDT.h:89
 AtlSgTop_sChannelBDT.h:90
 AtlSgTop_sChannelBDT.h:91
 AtlSgTop_sChannelBDT.h:92
 AtlSgTop_sChannelBDT.h:93
 AtlSgTop_sChannelBDT.h:94
 AtlSgTop_sChannelBDT.h:95
 AtlSgTop_sChannelBDT.h:96
 AtlSgTop_sChannelBDT.h:97
 AtlSgTop_sChannelBDT.h:98
 AtlSgTop_sChannelBDT.h:99
 AtlSgTop_sChannelBDT.h:100
 AtlSgTop_sChannelBDT.h:101
 AtlSgTop_sChannelBDT.h:102
 AtlSgTop_sChannelBDT.h:103
 AtlSgTop_sChannelBDT.h:104
 AtlSgTop_sChannelBDT.h:105
 AtlSgTop_sChannelBDT.h:106
 AtlSgTop_sChannelBDT.h:107
 AtlSgTop_sChannelBDT.h:108
 AtlSgTop_sChannelBDT.h:109
 AtlSgTop_sChannelBDT.h:110
 AtlSgTop_sChannelBDT.h:111
 AtlSgTop_sChannelBDT.h:112