//  
// Author: Holger Schulz <mailto:holger.schulz@physik.hu-berlin.de>, Oliver Maria Kind <mailto: kind@mail.desy.de>
// Update: $Id: AtlZ0Finder.h,v 1.3 2013/08/15 00:00:43 stamm Exp $
// Copyright: 2009 (C) Holger Schulz, Oliver Maria Kind
//
#ifndef ATLAS_AtlZ0Finder
#define ATLAS_AtlZ0Finder
#ifndef ATLAS_AtlKinFitterTool
#include <AtlKinFitterTool.h>
#endif
#ifndef ROOT_AtlSelector
#include <AtlSelector.h>
#endif
#include <fstream>
#include <iostream>
#include <TH2F.h>

class TH1F;
class AtlEvent;
class TTree;
class TString;
class TROOT;
class TFile;

class AtlZ0Finder : public AtlKinFitterTool {

  public:
    enum EModeLepton {kElectron= BIT(0),
		      kMuon    = BIT(1),
		      kTau     = BIT(2),
		      kAll     = (kElectron | kMuon | kTau)
                     };
    
    
    Bool_t   fchargetest;
    EModeLepton fModeLepton;
  private:
    //Bool_t   fchargetest;
    //EModeLepton fModeLepton;
    // small resolution study
    // this is a preliminary analysis and can be deleted once there is access to covariance matrices
    // other histograms are used to analyze the performance of the fitter and are also not mandatory

    TH1F *fHist_Zee_PtRes;     // Histograms to compare reconstructed and true particles
    TH1F *fHist_Zee_EtaRes;
    TH1F *fHist_Zee_PhiRes;

    TH1F *fHist_Zee_PtRes_KinFit;     // Histograms to compare Kinfitter Output and true particles
    TH1F *fHist_Zee_EtaRes_KinFit;
    TH1F *fHist_Zee_PhiRes_KinFit;

    // histogram to compare chi^2 probability with the Bremsstrahlungsloss of electrons and positrons

    TH2F *fHist_Zee_BremslossProb;

    // histogram to compare the occurence of final state radiation in Z->ee
    // with chi^2 probability of the kinematic fit

    TH1F *fHist_Zee_RadProb;
    
    // histogram to compare  Z boson properties with chi^2 probability of the kinematic fit
    
    TH2F *fHist_Zee_ZPtProb;
    TH2F *fHist_Zee_ZEProb;
    TH2F *fHist_Zee_ZMProb;
    
    // histogram to test TFitConstraintEta
    // comparison of chi^2 probability and Eta of the electron
    
    TH1D *EtaHist;              // input histogram for constraint
    TH1D *fHist_Zee_AbsEtaElectron;       // histogram of |eta| of one Z boson daughter
                                // to be used as input for TFitConstraintEta
    TH2F *fHist_Prob_EtaElec;   // comparison of chi^2 probability and electron eta
    
    // histogram of electron+positron px_true to set pt-conservation constraint
    
    TH1F *fHist_e_px_true;
    
    Int_t TruthMatchCounter;
    
    Double_t c11; // Elements of Covariance Matrix
    Double_t c22;
    Double_t c33;
    Double_t c12;
    Double_t c13;
    Double_t c23;
    
    // Z -> ee (signal)
    TH1F *fHistZreco_m_ee;     // Reconstructed invariant transverse mass of the Z decaying into electrons
    TH1F *fHistZreco_pt_ee;    // Reconstructed azimuth angle of the (real) Z decaying into electrons
    TH1F *fHistZreco_phi_ee;   // Reconstructed Pt of the Z decaying into electrons
    TH1F *fHistZreco_eta_ee;   // Reconstructed invariant transverse mass of the Z decaying into e-
    TH1F *fHistZreco_n_ee;     // Reconstructed invariant transverse mass of the Z decaying into e-
    //with probability cut
    TH1F *fHistZreco_m_ee_with_prob;     // Reconstructed invariant transverse mass of the Z decaying into electrons
    TH1F *fHistZreco_pt_ee_with_prob;    // Reconstructed azimuth angle of the (real) Z decaying into electrons
    TH1F *fHistZreco_phi_ee_with_prob;   // Reconstructed Pt of the Z decaying into electrons
    TH1F *fHistZreco_eta_ee_with_prob;   // Reconstructed invariant transverse mass of the Z decaying into e-
    TH1F *fHistZreco_n_ee_with_prob;     // Reconstructed invariant transverse mass of the Z decaying into e-
    TH1F *fHistZreco_DeltaPhi_ee_with_prob;     // Reconstructed absolute Value of Phi(e+)-Phi(e-)
    
    TH1F *fHistZreco_eplus_pt;   // Reconstructed transverse momentum of the e+ from Z decaying into ee
    TH1F *fHistZreco_eplus_eta;  // Reconstructed pseudo rapidity of e+ from Z decaying into ee
    TH1F *fHistZreco_eplus_phi;  // Reconstructed azimuth angle of e+ from Z decaying into ee
    TH1F *fHistZreco_eminus_pt;  // Reconstructed transverse momentum of the e- from Z decaying into ee
    TH1F *fHistZreco_eminus_eta; // Reconstructed pseudo rapidity of e- from Z decaying into ee
    TH1F *fHistZreco_eminus_phi;  // Reconstructed azimuth angle of e- from Z decaying into ee
    TH1F *fHistZreco_DeltaPhi_ee;     // Reconstructed absolute Value of Phi(e+)-Phi(e-)
    TH1F *fHistZreco_prob_ee;   //Probability of reconstructed Z->ee
    // Z -> mumu (signal)
    TH1F *fHistZreco_m_mumu_with_prob;     // Reconstructed invariant transverse mass of the Z decaying into muons
    TH1F *fHistZreco_pt_mumu_with_prob;    // Reconstructed azimuth angle of the (real) Z decaying into muons
    TH1F *fHistZreco_phi_mumu_with_prob;   // Reconstructed Pt of the Z decaying into muons
    TH1F *fHistZreco_eta_mumu_with_prob;   // Reconstructed invariant transverse mass of the Z decaying into e-
    TH1F *fHistZreco_n_mumu_with_prob;     // Reconstructed invariant transverse mass of the Z decaying into e-
    TH1F *fHistZreco_prob_mumu;   //Probability of reconstructed Z->mumu
    //Histogramm after probability cut
    TH1F *fHistZreco_m_mumu;     // Reconstructed invariant transverse mass of the Z decaying into muons
    TH1F *fHistZreco_pt_mumu;    // Reconstructed azimuth angle of the (real) Z decaying into muons
    TH1F *fHistZreco_phi_mumu;   // Reconstructed Pt of the Z decaying into muons
    TH1F *fHistZreco_eta_mumu;   // Reconstructed invariant transverse mass of the Z decaying into e-
    TH1F *fHistZreco_n_mumu;     // Reconstructed invariant transverse mass of the Z decaying into e-
    TH1F *fHistZreco_DeltaPhi_mumu_with_prob;     // Reconstructed absolute Value of Phi(mu+)-Phi(mu-)
    
    
    TH1F *fHistZreco_muplus_pt;   // Reconstructed transverse momentum of the mu+ from Z decaying into mumu
    TH1F *fHistZreco_muplus_eta;  // Reconstructed pseudo rapidity of mu+ from Z decaying into mumu
    TH1F *fHistZreco_muplus_phi;  // Reconstructed azimuth angle of mu+ from Z decaying into mumu
    TH1F *fHistZreco_muminus_pt;  // Reconstructed transverse momentum of the mu- from Z decaying into mumu
    TH1F *fHistZreco_muminus_eta; // Reconstructed pseudo rapidity of mu- from Z decaying into mumu
    TH1F *fHistZreco_muminus_phi;  // Reconstructed azimuth angle of mu- from Z decaying into mumu
    TH1F *fHistZreco_DeltaPhi_mumu;     // Reconstructed absolute Value of Phi(mu+)-Phi(mu-)

    // Z -> tautau (signal)
    TH1F *fHistZreco_m_tautau;     // Reconstructed invariant transverse mass of the Z decaying into taus
    TH1F *fHistZreco_pt_tautau;    // Reconstructed azimuth angle of the (real) Z decaying into taus
    TH1F *fHistZreco_phi_tautau;   // Reconstructed Pt of the Z decaying into taus
    TH1F *fHistZreco_eta_tautau;   // Reconstructed invariant transverse mass of the Z decaying into e-
    TH1F *fHistZreco_n_tautau;     // Reconstructed invariant transverse mass of the Z decaying into e-
    TH1F *fHistZreco_DeltaPhi_tautau;     // Reconstructed absolute Value of Phi(tau+)-Phi(tau-)
    
    
    // Z -> leptons (signal)
    TH1F *fHistZreco_m_ll;     // Reconstructed invariant transverse mass of the Z decaying into leptons
    TH1F *fHistZreco_pt_ll;    // Reconstructed azimuth angle of the (real) Z decaying into leptons
    TH1F *fHistZreco_phi_ll;   // Reconstructed Pt of the Z decaying into leptons
    TH1F *fHistZreco_eta_ll;   // Reconstructed invariant transverse mass of the Z decaying into e-
    TH1F *fHistZreco_n_ll;     // Reconstructed invariant transverse mass of the Z decaying into e-
    TH1F *fHistZreco_DeltaPhi_ll;     // Reconstructed absolute Value of Phi(l+)-Phi(l-)
    
    // Z -> ee (bkg)
    TH1F *fHistZreco_m_ee_bkg;        // Reconstructed invariant transverse mass of the Z decaying into electrons (bkg)
    TH1F *fHistZreco_pt_ee_bkg;       // Reconstructed azimuth angle of the (real) Z decaying into electrons (bkg)
    TH1F *fHistZreco_phi_ee_bkg;      // Reconstructed Pt of the Z decaying into electrons (bkg)
    TH1F *fHistZreco_eta_ee_bkg;      // Reconstructed invariant transverse mass of the Z decaying into e- (bkg)
    TH1F *fHistZreco_DeltaPhi_ee_bkg; // Reconstructed absolute Value of Phi(e+)-Phi(e-) (bkg)

    // Z -> mumu (bkg)
    TH1F *fHistZreco_m_mumu_bkg;     // Reconstructed invariant transverse mass of the Z decaying into muons (bkg)
    TH1F *fHistZreco_pt_mumu_bkg;    // Reconstructed azimuth angle of the (real) Z decaying into muons (bkg)
    TH1F *fHistZreco_phi_mumu_bkg;   // Reconstructed Pt of the Z decaying into muons (bkg)
    TH1F *fHistZreco_eta_mumu_bkg;   // Reconstructed invariant transverse mass of the Z decaying into e- (bkg)
    TH1F *fHistZreco_DeltaPhi_mumu_bkg;// Reconstructed absolute Value of Phi(mu+)-Phi(mu-) (bkg)
    
    // Z -> tautau (bkg)
    TH1F *fHistZreco_m_tautau_bkg;     // Reconstructed invariant transverse mass of the Z decaying into taus (bkg)
    TH1F *fHistZreco_pt_tautau_bkg;    // Reconstructed azimuth angle of the (real) Z decaying into taus (bkg)
    TH1F *fHistZreco_phi_tautau_bkg;   // Reconstructed Pt of the Z decaying into taus (bkg)
    TH1F *fHistZreco_eta_tautau_bkg;   // Reconstructed invariant transverse mass of the Z decaying into e- (bkg)
    TH1F *fHistZreco_DeltaPhi_tautau_bkg;// Reconstructed absolute Value of Phi(tau+)-Phi(tau-) (bkg)
    
    // Z -> leptons (bkg)
    TH1F *fHistZreco_m_ll_bkg;     // Reconstructed invariant transverse mass of the Z decaying into leptons (bkg)
    TH1F *fHistZreco_pt_ll_bkg;    // Reconstructed azimuth angle of the (real) Z decaying into leptons (bkg)
    TH1F *fHistZreco_phi_ll_bkg;   // Reconstructed Pt of the Z decaying into leptons (bkg)
    TH1F *fHistZreco_eta_ll_bkg;   // Reconstructed invariant transverse mass of the Z decaying into e- (bkg)
    TH1F *fHistZreco_DeltaPhi_ll_bkg;// Reconstructed absolute Value of Phi(l+)-Phi(l-) (bkg)
    
    TList *fSignalElectrons;   // List of tight e from Z decay
    TList *fSignalMuons;       // List of tight mu from Z decay
    TList *fSignalTaus;        // List of tight tau from Z decay
    TList *fBkgZ0Decays;       // List of combinatorial bkg.
    
  public:
    // Lepton selection cuts
    AtlEMShower::EAuthor fSignalElectronAuthor;   // Author type of signal electrons
    AtlEMShower::EIsEM   fSignalElectronIsEM;     // IsEM type of signal electrons
    Float_t              fSignalElectron_Pt_min;  // Min. Pt of signal electrons
    Float_t              fSignalElectron_Pt_max;  // Max. Pt of signal electrons
    Float_t              fSignalElectron_Eta_min; // Min. eta of signal electrons
    Float_t              fSignalElectron_Eta_max; // Max. eta of signal electrons
    Float_t              fSignalElectron_EtCone20_max; // Max. Et within a cone of 0.2
    
    AtlMuon::EAuthor     fSignalMuonAuthor;       // Author type of signal muons
    Float_t              fSignalMuon_Pt_min;      // Min. Pt of signal muons
    Float_t              fSignalMuon_Pt_max;      // Max. Pt of signal muons
    Float_t              fSignalMuon_Eta_min;     // Min. eta of signal muons
    Float_t              fSignalMuon_Eta_max;     // Max. eta of signal muons
    Float_t              fSignalMuon_Chi2_max;    // Max. chi2/ndof of signal muons
    Float_t              fSignalMuon_EtCone20_max; // Max. Et within a cone of 0.2
    
    AtlTau::EAuthor      fSignalTauAuthor;       // Author type of signal taus
    AtlTau::ETauFlag     fSignalTauAuthorFlag;   // AuthorFlag type of signal taus
    Float_t              fSignalTau_Pt_min;      // Min. Pt of signal taus
    Float_t              fSignalTau_Pt_max;      // Max. Pt of signal taus
    Float_t              fSignalTau_Eta_min;     // Min. eta of signal taus
    Float_t              fSignalTau_Eta_max;     // Max. eta of signal taus
    //Float_t              fSignalTau_Chi2_max;    // Max. chi2/ndof of signal taus
    //Float_t              fSignalTau_EtCone20_max; // Max. Et within a cone of 0.2
    
    Float_t              fZBoson_M_min; // Lower boundary for allowed Z mass range
    Float_t              fZBoson_M_max; // Upper boundary for allowed Z mass range
    
  public:
    AtlZ0Finder(const char* name, const char* title, Bool_t chargetest=kTRUE, EModeLepton fModeLepton=kAll);
    virtual ~AtlZ0Finder();
    virtual void SetBranchStatus();
    virtual void BookHistograms();
    virtual void FillHistograms();
    virtual void SetCutDefaults();
    virtual Bool_t AnalyzeEvent();
    virtual void Terminate();
    void InitEvent();
    void ReconstructZ0CutBased(TList *SignalLeptons);
    void ReconstructZ0KinFit(TList *SignalLeptons);
    void FillTruthHistograms();
    inline void SetMode(EMode mode = kKinFit)
    { fMode = mode; }
    ClassDef(AtlZ0Finder,0) // Z0 decay finder class
};
#endif

 AtlZ0Finder.h:1
 AtlZ0Finder.h:2
 AtlZ0Finder.h:3
 AtlZ0Finder.h:4
 AtlZ0Finder.h:5
 AtlZ0Finder.h:6
 AtlZ0Finder.h:7
 AtlZ0Finder.h:8
 AtlZ0Finder.h:9
 AtlZ0Finder.h:10
 AtlZ0Finder.h:11
 AtlZ0Finder.h:12
 AtlZ0Finder.h:13
 AtlZ0Finder.h:14
 AtlZ0Finder.h:15
 AtlZ0Finder.h:16
 AtlZ0Finder.h:17
 AtlZ0Finder.h:18
 AtlZ0Finder.h:19
 AtlZ0Finder.h:20
 AtlZ0Finder.h:21
 AtlZ0Finder.h:22
 AtlZ0Finder.h:23
 AtlZ0Finder.h:24
 AtlZ0Finder.h:25
 AtlZ0Finder.h:26
 AtlZ0Finder.h:27
 AtlZ0Finder.h:28
 AtlZ0Finder.h:29
 AtlZ0Finder.h:30
 AtlZ0Finder.h:31
 AtlZ0Finder.h:32
 AtlZ0Finder.h:33
 AtlZ0Finder.h:34
 AtlZ0Finder.h:35
 AtlZ0Finder.h:36
 AtlZ0Finder.h:37
 AtlZ0Finder.h:38
 AtlZ0Finder.h:39
 AtlZ0Finder.h:40
 AtlZ0Finder.h:41
 AtlZ0Finder.h:42
 AtlZ0Finder.h:43
 AtlZ0Finder.h:44
 AtlZ0Finder.h:45
 AtlZ0Finder.h:46
 AtlZ0Finder.h:47
 AtlZ0Finder.h:48
 AtlZ0Finder.h:49
 AtlZ0Finder.h:50
 AtlZ0Finder.h:51
 AtlZ0Finder.h:52
 AtlZ0Finder.h:53
 AtlZ0Finder.h:54
 AtlZ0Finder.h:55
 AtlZ0Finder.h:56
 AtlZ0Finder.h:57
 AtlZ0Finder.h:58
 AtlZ0Finder.h:59
 AtlZ0Finder.h:60
 AtlZ0Finder.h:61
 AtlZ0Finder.h:62
 AtlZ0Finder.h:63
 AtlZ0Finder.h:64
 AtlZ0Finder.h:65
 AtlZ0Finder.h:66
 AtlZ0Finder.h:67
 AtlZ0Finder.h:68
 AtlZ0Finder.h:69
 AtlZ0Finder.h:70
 AtlZ0Finder.h:71
 AtlZ0Finder.h:72
 AtlZ0Finder.h:73
 AtlZ0Finder.h:74
 AtlZ0Finder.h:75
 AtlZ0Finder.h:76
 AtlZ0Finder.h:77
 AtlZ0Finder.h:78
 AtlZ0Finder.h:79
 AtlZ0Finder.h:80
 AtlZ0Finder.h:81
 AtlZ0Finder.h:82
 AtlZ0Finder.h:83
 AtlZ0Finder.h:84
 AtlZ0Finder.h:85
 AtlZ0Finder.h:86
 AtlZ0Finder.h:87
 AtlZ0Finder.h:88
 AtlZ0Finder.h:89
 AtlZ0Finder.h:90
 AtlZ0Finder.h:91
 AtlZ0Finder.h:92
 AtlZ0Finder.h:93
 AtlZ0Finder.h:94
 AtlZ0Finder.h:95
 AtlZ0Finder.h:96
 AtlZ0Finder.h:97
 AtlZ0Finder.h:98
 AtlZ0Finder.h:99
 AtlZ0Finder.h:100
 AtlZ0Finder.h:101
 AtlZ0Finder.h:102
 AtlZ0Finder.h:103
 AtlZ0Finder.h:104
 AtlZ0Finder.h:105
 AtlZ0Finder.h:106
 AtlZ0Finder.h:107
 AtlZ0Finder.h:108
 AtlZ0Finder.h:109
 AtlZ0Finder.h:110
 AtlZ0Finder.h:111
 AtlZ0Finder.h:112
 AtlZ0Finder.h:113
 AtlZ0Finder.h:114
 AtlZ0Finder.h:115
 AtlZ0Finder.h:116
 AtlZ0Finder.h:117
 AtlZ0Finder.h:118
 AtlZ0Finder.h:119
 AtlZ0Finder.h:120
 AtlZ0Finder.h:121
 AtlZ0Finder.h:122
 AtlZ0Finder.h:123
 AtlZ0Finder.h:124
 AtlZ0Finder.h:125
 AtlZ0Finder.h:126
 AtlZ0Finder.h:127
 AtlZ0Finder.h:128
 AtlZ0Finder.h:129
 AtlZ0Finder.h:130
 AtlZ0Finder.h:131
 AtlZ0Finder.h:132
 AtlZ0Finder.h:133
 AtlZ0Finder.h:134
 AtlZ0Finder.h:135
 AtlZ0Finder.h:136
 AtlZ0Finder.h:137
 AtlZ0Finder.h:138
 AtlZ0Finder.h:139
 AtlZ0Finder.h:140
 AtlZ0Finder.h:141
 AtlZ0Finder.h:142
 AtlZ0Finder.h:143
 AtlZ0Finder.h:144
 AtlZ0Finder.h:145
 AtlZ0Finder.h:146
 AtlZ0Finder.h:147
 AtlZ0Finder.h:148
 AtlZ0Finder.h:149
 AtlZ0Finder.h:150
 AtlZ0Finder.h:151
 AtlZ0Finder.h:152
 AtlZ0Finder.h:153
 AtlZ0Finder.h:154
 AtlZ0Finder.h:155
 AtlZ0Finder.h:156
 AtlZ0Finder.h:157
 AtlZ0Finder.h:158
 AtlZ0Finder.h:159
 AtlZ0Finder.h:160
 AtlZ0Finder.h:161
 AtlZ0Finder.h:162
 AtlZ0Finder.h:163
 AtlZ0Finder.h:164
 AtlZ0Finder.h:165
 AtlZ0Finder.h:166
 AtlZ0Finder.h:167
 AtlZ0Finder.h:168
 AtlZ0Finder.h:169
 AtlZ0Finder.h:170
 AtlZ0Finder.h:171
 AtlZ0Finder.h:172
 AtlZ0Finder.h:173
 AtlZ0Finder.h:174
 AtlZ0Finder.h:175
 AtlZ0Finder.h:176
 AtlZ0Finder.h:177
 AtlZ0Finder.h:178
 AtlZ0Finder.h:179
 AtlZ0Finder.h:180
 AtlZ0Finder.h:181
 AtlZ0Finder.h:182
 AtlZ0Finder.h:183
 AtlZ0Finder.h:184
 AtlZ0Finder.h:185
 AtlZ0Finder.h:186
 AtlZ0Finder.h:187
 AtlZ0Finder.h:188
 AtlZ0Finder.h:189
 AtlZ0Finder.h:190
 AtlZ0Finder.h:191
 AtlZ0Finder.h:192
 AtlZ0Finder.h:193
 AtlZ0Finder.h:194
 AtlZ0Finder.h:195
 AtlZ0Finder.h:196
 AtlZ0Finder.h:197
 AtlZ0Finder.h:198
 AtlZ0Finder.h:199
 AtlZ0Finder.h:200
 AtlZ0Finder.h:201
 AtlZ0Finder.h:202
 AtlZ0Finder.h:203
 AtlZ0Finder.h:204
 AtlZ0Finder.h:205
 AtlZ0Finder.h:206
 AtlZ0Finder.h:207
 AtlZ0Finder.h:208
 AtlZ0Finder.h:209
 AtlZ0Finder.h:210
 AtlZ0Finder.h:211
 AtlZ0Finder.h:212
 AtlZ0Finder.h:213
 AtlZ0Finder.h:214
 AtlZ0Finder.h:215
 AtlZ0Finder.h:216
 AtlZ0Finder.h:217
 AtlZ0Finder.h:218
 AtlZ0Finder.h:219
 AtlZ0Finder.h:220
 AtlZ0Finder.h:221
 AtlZ0Finder.h:222
 AtlZ0Finder.h:223
 AtlZ0Finder.h:224
 AtlZ0Finder.h:225
 AtlZ0Finder.h:226
 AtlZ0Finder.h:227
 AtlZ0Finder.h:228
 AtlZ0Finder.h:229
 AtlZ0Finder.h:230
 AtlZ0Finder.h:231
 AtlZ0Finder.h:232
 AtlZ0Finder.h:233