//____________________________________________________________________
//
// Single-top FCNC tZ analysis: Z+jets di-lepton ctrl region
// 
//  
// Author: Oliver Maria Kind <mailto: kind@physik.hu-berlin.de>
// Update: $Id: AtlSgTopFCNC_tZ_CtrlZjets2L.cxx,v 1.9 2016/11/11 10:36:23 mergelm Exp $
// Copyright: 2015 (C) Oliver Maria Kind 
//
#ifndef SGTOP_AtlSgTopFCNC_tZ_CtrlZjets2L
#include <AtlSgTopFCNC_tZ_CtrlZjets2L.h>
#endif

#ifndef __CINT__
ClassImp(AtlSgTopFCNC_tZ_CtrlZjets2L);
#endif

//____________________________________________________________________

AtlSgTopFCNC_tZ_CtrlZjets2L::AtlSgTopFCNC_tZ_CtrlZjets2L(const char* OutputFileName) :
    AtlSgTopFCNC_tZ_Base(OutputFileName) {
    //
    // Default constructor
    //
    SetCutDefaults();
}

//____________________________________________________________________

AtlSgTopFCNC_tZ_CtrlZjets2L::~AtlSgTopFCNC_tZ_CtrlZjets2L() {
    //
    // Default destructor
    //
}

//____________________________________________________________________

void AtlSgTopFCNC_tZ_CtrlZjets2L::SetCutDefaults() {
    //
    // Selection cut defaults
    //
    fNLeptons_max=2;
}

//____________________________________________________________________

Bool_t AtlSgTopFCNC_tZ_CtrlZjets2L::ProcessPreCut() {
    //
    // Event pre-selection
    //

    // Check whether SingleTopAnalysis "triggered" on the event.
    return (fEvent->GetEventHeader()
     ->TestPreselectionFlagsAny(AtlEventHeader::kElEl | AtlEventHeader::kElMu | AtlEventHeader::kMuMu));
}

//____________________________________________________________________

void AtlSgTopFCNC_tZ_CtrlZjets2L::Print(Option_t *option) const {
    //
    // Print user analysis configuration
    //
    cout << endl
	 << "========================================================" << endl
	 << "  Atlas Single-Top FCNC tZ Selector : Z+jets 2L CR      " << endl
	 << "========================================================" << endl
	 << endl;
    AtlSgTopFCNC_tZ_Base::Print(option);
    cout << endl
	 << "========================================================"
	 << endl << endl;   
}

//____________________________________________________________________

Bool_t AtlSgTopFCNC_tZ_CtrlZjets2L::ProcessCut() {
    //
    // Event selection
    //

    // Fill histograms w/o any cuts applied
    FillHistogramsCommon(fHistsNoCuts, fEvent->GetPreTagEvtWeight());
    
    // ==========================
    // Quick lepton pre-selection
    // ==========================
    
    // Minimum/maximum  no. of leptons (default = 2)
    if ( fLeptons->GetEntries() < fNLeptons_min
	 || fLeptons->GetEntries() > fNLeptons_max ) return kFALSE;

    // ====================
    // Kinematic selection
    // ====================
    
    // Leading lepton Pt
    HepParticle *lep1 = (HepParticle*)fLeptons->At(0);
    HepParticle *lep2 = (HepParticle*)fLeptons->At(1);
    if ( lep1->Pt() < fPt_Lep1_min ) return kFALSE;
    if ( lep2->Pt() < fPt_Lep2_min ) return kFALSE;

    // Missing Et
    fMET = fEvent->GetEnergySum()->MissingEt_Mag();
    if ( fMET < fMET_min || fMET > fMET_max ) return kFALSE;
    
    // Transverse W mass (leading lepton !)
    fMtW = fEvent->W_Mperp((HepParticle*)fLeptons->At(0));
    if ( fMtW < fMtW_min || fMtW > fMtW_max ) return kFALSE;

    //Fill all pre-selection histograms
    FillHistogramsCommon(fHistsPreSel, fEvent->GetPreTagEvtWeight());
    
    // =================
    // Z reconstruction
    // =================
    ReconstructZ0Decays();
    
    // Require a Z candidate;
    if ( fRequireZ && fEvent->GetN_Z0Decays() < 1 ) return kFALSE;
    
    // // Veto a top candidate
    // if (fEvent->GetN_TopDecays() > 0) return kFALSE;
    //
    //OMK Comment this veto for now. It would require a top-quark
    //OMK reconstrution using one of the two leptons (or both?)
    
    // Fill all pre-tagged hisotgrams and count number of pre-tagged events
    FillHistogramsCommon(fHistsPreTag, fEvent->GetPreTagEvtWeight());
    FillHistogramsZ0(fHistsPreTag, fEvent->GetPreTagEvtWeight(),
    		     "Z0_best", GetZ0DecayBest());
    fPreTaggedEvents++;
    fPreTaggedEventsW += fEvent->GetPreTagEvtWeight();
    
    // =====================
    // B-tagging requirement
    // =====================
    if ( fBJets->GetEntries() < fNBTags_min
         || fBJets->GetEntries() > fNBTags_max) return kFALSE;

    // Fill histograms for with all cuts applied
    FillHistogramsCommon(fHistsAllCuts, fEvent->GetTagEvtWeight());
    FillHistogramsZ0(fHistsAllCuts, fEvent->GetTagEvtWeight(),
    		     "Z0_best", GetZ0DecayBest());

    return kTRUE;
}
    
//____________________________________________________________________

void AtlSgTopFCNC_tZ_CtrlZjets2L::BookHistograms() {
    //
    // Book histograms
    //
    AtlSgTopFCNC_tZ_Base::BookHistograms();
}
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:1
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:2
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:3
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:4
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:5
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:6
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:7
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:8
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:9
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:10
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:11
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:12
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:13
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:14
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:15
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:16
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:17
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:18
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:19
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:20
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:21
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:22
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:23
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:24
 AtlSgTopFCNC_tZ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CtrlZjets2L.cxx:87
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:88
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:89
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:90
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:91
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:92
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:93
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:94
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:95
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:96
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:97
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:98
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:99
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:100
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:101
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:102
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:103
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:104
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:105
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:106
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:107
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:108
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:109
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:110
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:111
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:112
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:113
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:114
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:115
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:116
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:117
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:118
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:119
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:120
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:121
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:122
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:123
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:124
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:125
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:126
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:127
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:128
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:129
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:130
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:131
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:132
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:133
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:134
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:135
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:136
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:137
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:138
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:139
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:140
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:141
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:142
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:143
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:144
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:145
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:146
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:147
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:148
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:149
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:150
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:151
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:152
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:153
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:154
 AtlSgTopFCNC_tZ_CtrlZjets2L.cxx:155