//____________________________________________________________________
//
// Single-top FCNC tZ analysis: Z+jets tri-lepton ctrl region
// 
//  
// Author: Oliver Maria Kind <mailto: kind@physik.hu-berlin.de>
// Update: $Id: AtlSgTopFCNC_tZ_CtrlZjets3L.cxx,v 1.11 2017/01/14 10:02:11 apeixoto Exp $
// Copyright: 2015 (C) Oliver Maria Kind 
//
#ifndef SGTOP_AtlSgTopFCNC_tZ_CtrlZjets3L
#include <AtlSgTopFCNC_tZ_CtrlZjets3L.h>
#endif

#ifndef __CINT__
ClassImp(AtlSgTopFCNC_tZ_CtrlZjets3L);
#endif

//____________________________________________________________________

AtlSgTopFCNC_tZ_CtrlZjets3L::AtlSgTopFCNC_tZ_CtrlZjets3L(const char* OutputFileName) :
    AtlSgTopFCNC_tZ_Base3L(OutputFileName) {
    //
    // Default constructor
    //
    SetCutDefaults();
}

//____________________________________________________________________

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

//____________________________________________________________________

void AtlSgTopFCNC_tZ_CtrlZjets3L::SetCutDefaults() {
    //
    // Selection cut defaults
    //
}

//____________________________________________________________________

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

//____________________________________________________________________

Bool_t AtlSgTopFCNC_tZ_CtrlZjets3L::ProcessCut() {
    //
    // Event selection
    //
    // Select tri-lepton events with the given kinematic, while
    // accepting all tri-lepton combinations allowed in Zt events
    // (permutations like e+e-mu+, e+e-mu- will be sorted out later by
    // the ME method).
    // 

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

    // Fetch leptons and cut on individual lepton Pt
    Float_t tot_chg = 0.;
    HepParticle *lep = 0;
    for ( Int_t i = 0; i < fLeptons->GetEntries(); i++ ) {
	lep = (HepParticle*)fLeptons->At(i);
	if ( i == 0 && lep->Pt() < fPt_Lep1_min ) return kFALSE;
	if ( i == 1 && lep->Pt() < fPt_Lep2_min ) return kFALSE;
	if ( i == 2 && lep->Pt() < fPt_Lep3_min ) return kFALSE;
	tot_chg += lep->Charge();
    }

    // Remove all +++ and --- combinations (trilepton case only)
    if ( fLeptons->GetEntries() == 3 ) {
	if ( TMath::Abs(tot_chg) > 2. ) return kFALSE;
    }

    // ===================
    // Kinematic selection
    // ===================
    
    // 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());
    
    // =================
    // tZ reconstruction
    // =================
    ReconstructZ0Top();

    // Require a Z candidate
    if ( fRequireZ && fEvent->GetN_Z0Decays() < 1 ) return kFALSE;

    // Fill all pre-tagged hisotgrams and count number of pre-tagged events
    FillHistogramsCommon(fHistsPreTag, fEvent->GetPreTagEvtWeight());
    FillHistogramsTop(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());
    FillHistogramsTop(fHistsAllCuts, fEvent->GetTagEvtWeight());
    FillHistogramsZ0(fHistsAllCuts, fEvent->GetTagEvtWeight(),
    		     "Z0_best", GetZ0DecayBest());

    // Accept event
    return kTRUE;
}
    
//____________________________________________________________________

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