// Author: Sebastian Beumler <mailto: beumler@physik.hu-berlin.de>
// Update: $Id: AtlConvFinder.h,v 1.2 2013/08/15 00:00:42 stamm Exp $
// Copyright: 2010 (C) Sebastian Beumler
//
#ifndef ATLAS_AtlConvFinder
#define ATLAS_AtlConvFinder
#ifndef ATLAS_AtlKinFitterTool
#include <AtlKinFitterTool.h>
#include <TH1F.h>
#include <TH2F.h>
#endif
#include <fstream>
#include <iostream>

using namespace std;

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

class AtlConvFinder : public AtlKinFitterTool {
    
  public:
    enum EMode { kCutBased, kKinFit };
    EMode  fMode;              // Indicate the mode of running (eg cut-based or kinematic fit)
    Bool_t fDebugMode;         // Indicate the mode of running (if debug output should be available)
    
    
  private:
    ofstream fDebugOutput;      // Debugging output
    // Number of (truely))reconstructed Photo-Conv, number of rec Conv where no truthmatch decission was possible.
    Int_t    fN_TrueRecConv,fN_RecConv, fN_NoDecision; 

    TH1F *fHisteMatchingProb;   // Matching probability of Particles matching the reconstructed elektrons    

    
    // SIGNAL: gamma -> e+e-
    // -----------------------
    
    TH1F *fHistConvreco_m_ee;       // Reconstructed invariant mass of the conversion-candidate
    TH1F *fHistConvreco_pt_ee;      // Reconstructed pt
    TH1F *fHistConvreco_phi_ee;     // Reconstructed phi
    TH1F *fHistConvreco_eta_ee;     // Reconstructed Eta 
    TH1F *fHistConvreco_N_ee;       // Multilplicity of reconstructed conversion candidates
    TH1F *fHistConvreco_tau_ee;            // Lifetime 
    TH1F *fHistConvreco_DecayLength_ee;    // DecayLength
    TH1F *fHistConvreco_OpeningAngle_ee;   // Opening Angle 
    TH1F *fHistConvreco_DecayAngle_ee;     // Decay angle between gamma and e+ in K0s' restframe
    TH1F *fHistConvreco_PointingAngle_ee;  // cos of angle between reconstructed gamma' momentum and vec(PV)-vec(SecVtxa)
    TH1F *fHistConvreco_R_vtx;             // radial distance from vertex to beam pipe
    // elektron histograms
    TH1F *fHistConvreco_ePlus_pt;    // recosntructed pt  of e+ 
    TH1F *fHistConvreco_eMinus_pt;   // recosntructed pt  of e-  
    TH1F *fHistConvreco_ePlus_eta;   // recosntructed eta of e+  
    TH1F *fHistConvreco_eMinus_eta;  // recosntructed eta of e-   
    TH1F *fHistConvreco_ePlus_phi;   // recosntructed phi of e+   
    TH1F *fHistConvreco_eMinus_phi;  // recosntructed phi of e-   



    // BACKGROUND: Like-sign approach (gamma->e+e+ \ gamma->e-e-)
    // -----------------------------------------------------------
    TList *fBkgPhotonConv;            // List of like sign conversions
   
    TH1F *fHistConvreco_m_LS_bkg;       // invariant mass of the Kaon decaying into equally signed pions
    TH1F *fHistConvreco_pt_LS_bkg;      // azimuth angle of the Kaon decaying into equally signed pions
    TH1F *fHistConvreco_phi_LS_bkg;     // Pt of the Kaon decaying into equally signed pions
    TH1F *fHistConvreco_eta_LS_bkg;     // Eta of the Kaon decaying into equally signed pions
    TH1F *fHistConvreco_N_LS_bkg;       // Multilplicity of reconstructed Conv decaying into equally signed pions
    TH1F *fHistConvreco_tau_LS_bkg;     // Lifetime of reconstructed Conv decaying into equally signed pions
    TH1F *fHistConvreco_DecayLength_LS_bkg;  // DecayLength of reconstructed Conv decaying ito equaly signed pions
    
    // electron histograms
    TH1F *fHistConvreco_ePlus_pt_LS_bkg;    // recosntructed pt  of e+ 
    TH1F *fHistConvreco_eMinus_pt_LS_bkg;   // recosntructed pt  of e-  
    TH1F *fHistConvreco_ePlus_eta_LS_bkg;   // recosntructed eta of e+  
    TH1F *fHistConvreco_eMinus_eta_LS_bkg;  // recosntructed eta of e-   
    TH1F *fHistConvreco_ePlus_phi_LS_bkg;   // recosntructed phi of e+   
    TH1F *fHistConvreco_eMinus_phi_LS_bkg;  // recosntructed phi of e-   

    
    // ====================
    //    MC TRUTH STUDY
    // ====================
    
    TH2F *fHistConvreco_truthtype;   // truth type of Conv candidates
    TH1F *fHistAllMCConv_DecayAngle;

    // BACKGROUND: Reconstructed conv candidates that fail the MCTruthMatching
    // -------------------------------------------------------------------

    TH1F *fHistConvreco_m_MCbkg;       // Reconstructed invariant mass of conv-candidate
    TH1F *fHistConvreco_pt_MCbkg;      // Reconstructed transv. momentum
    TH1F *fHistConvreco_phi_MCbkg;     // Reconstructed phi
    TH1F *fHistConvreco_eta_MCbkg;     // Reconstructed Eta 
    TH1F *fHistConvreco_N_MCbkg;       // Multilplicity of conv-candidate
    TH1F *fHistConvreco_tau_MCbkg;     // Lifetime of reconstructed conv-candidate
    TH1F *fHistConvreco_DecayLength_MCbkg;    // DecayLength
    TH1F *fHistConvreco_OpeningAngle_MCbkg;   // Opening Angle of the electron tracks in the lab frame
    TH1F *fHistConvreco_DecayAngle_MCbkg;     // Decay angle between conv and e+ in K0s' restframe
    TH1F *fHistConvreco_PointingAngle_MCbkg;  // cos of angle between reconstructed conv' momentum and vec(PV)-vec(SecVtx)
    TH1F *fHistConvreco_R_vtx_MCbkg;          // radial distance from vertex to beam pipe
    
    // SIGNAL: Reconstructed Conv candidates that pass the MCTruthMatching
    // ---------------------------------------------------------------------

    TH1F *fHistConvreco_m_MCsignal;       // Reconstructed invariant mass mass of conv-candidate
    TH1F *fHistConvreco_pt_MCsignal;      // Reconstructed transv. momentum
    TH1F *fHistConvreco_phi_MCsignal;     // Reconstructed phi
    TH1F *fHistConvreco_eta_MCsignal;     // Reconstructed Eta 
    TH1F *fHistConvreco_N_MCsignal;       // Multilplicity of reconstructed photoconversions
    TH1F *fHistConvreco_tau_MCsignal;      // Lifetime of reconstructed gammas
    TH1F *fHistConvreco_DecayLength_MCsignal;    // DecayLengt
    TH1F *fHistConvreco_OpeningAngle_MCsignal;   // Opening Angle of the electron tracks in the lab frame
    TH1F *fHistConvreco_DecayAngle_MCsignal;     // Decay angle between gamma and e+ in K0s' restframe
    TH1F *fHistConvreco_PointingAngle_MCsignal;  // cos of angle between gamma's momentum and vec(PV)-vec(SecVt
    TH1F *fHistConvreco_R_vtx_MCsignal;          // radial distance from vertex to beam pipe
    
  public:
  // selection cuts

    // hard coded
    Float_t  fSignale_Pt_min;          // Min. Pt of signal electrons
    Float_t  fSignale_Pt_max;          // Max. Pt of signal electrons
    Float_t  fSignale_Eta_min;         // Min. eta of signal electrons
    Float_t  fSignale_Eta_max;         // Max. eta of signal electrons
    Float_t  fm_e;                        // electron mass hypothesis
    
    // KinFit
    Float_t  fKinFitPvalue_min;           // Minimal probability of Chi2/NDoF required (KinFit)
    Float_t  fm_PolMass;                  // Pol mass for kinematic fitting (KinFit)
    Float_t  fm_Width;                    // Decay Width for kinematic fitting (KinFit)
    // CutBased
    Float_t  fConv_M_max;                 // Upper boundary for allowed photon mass (Cutbased)

    // both
    Float_t  fMatchingProb_min;           // Min. of Matching probability
    Float_t  fTransvDecayLength_min;      // Minimal DecayLength
    Float_t  fPointingAngle_min;          // Minimal cos(PointingAngle)
    Float_t  fDecayAngle_min;             // Minimal DecayAngle (Angle between flightdirection of gamma
                                          // and momentum of e+ in K0s' restframe (well defined) )
    Float_t  fR_Vtx_min;                  // Minimum of radial distance from rec. conv Vtx to nominal beamline
    
  public:
  AtlConvFinder(const char* name, const char* title);
  virtual ~AtlConvFinder();
  virtual void SetBranchStatus();
  virtual void BookHistograms();
  virtual void FillHistograms();
  virtual void SetCutDefaults();
  virtual Bool_t AnalyzeEvent();
  void ReconstructConvCutBased(void);
  void ReconstructConvKinFit(void);
  void PrintCutValues(void);
  Int_t DoTruthMatch(AtlPhotonConv *ConvCandidate); 
  void FillHistograms_MCTruthStudy(AtlPhotonConv *ConvCandidate, char type);
  virtual void Terminate(void);
  
  inline void SetMode(EMode mode = kKinFit)
  { fMode = mode; }
  inline void SetDebugMode(Bool_t DebugMode = kFALSE)
  { fDebugMode = DebugMode; }
  inline Bool_t IsDebugRun() { return fDebugMode; }

  
  ClassDef(AtlConvFinder,0) // decay finder class
};
#endif

 AtlConvFinder.h:1
 AtlConvFinder.h:2
 AtlConvFinder.h:3
 AtlConvFinder.h:4
 AtlConvFinder.h:5
 AtlConvFinder.h:6
 AtlConvFinder.h:7
 AtlConvFinder.h:8
 AtlConvFinder.h:9
 AtlConvFinder.h:10
 AtlConvFinder.h:11
 AtlConvFinder.h:12
 AtlConvFinder.h:13
 AtlConvFinder.h:14
 AtlConvFinder.h:15
 AtlConvFinder.h:16
 AtlConvFinder.h:17
 AtlConvFinder.h:18
 AtlConvFinder.h:19
 AtlConvFinder.h:20
 AtlConvFinder.h:21
 AtlConvFinder.h:22
 AtlConvFinder.h:23
 AtlConvFinder.h:24
 AtlConvFinder.h:25
 AtlConvFinder.h:26
 AtlConvFinder.h:27
 AtlConvFinder.h:28
 AtlConvFinder.h:29
 AtlConvFinder.h:30
 AtlConvFinder.h:31
 AtlConvFinder.h:32
 AtlConvFinder.h:33
 AtlConvFinder.h:34
 AtlConvFinder.h:35
 AtlConvFinder.h:36
 AtlConvFinder.h:37
 AtlConvFinder.h:38
 AtlConvFinder.h:39
 AtlConvFinder.h:40
 AtlConvFinder.h:41
 AtlConvFinder.h:42
 AtlConvFinder.h:43
 AtlConvFinder.h:44
 AtlConvFinder.h:45
 AtlConvFinder.h:46
 AtlConvFinder.h:47
 AtlConvFinder.h:48
 AtlConvFinder.h:49
 AtlConvFinder.h:50
 AtlConvFinder.h:51
 AtlConvFinder.h:52
 AtlConvFinder.h:53
 AtlConvFinder.h:54
 AtlConvFinder.h:55
 AtlConvFinder.h:56
 AtlConvFinder.h:57
 AtlConvFinder.h:58
 AtlConvFinder.h:59
 AtlConvFinder.h:60
 AtlConvFinder.h:61
 AtlConvFinder.h:62
 AtlConvFinder.h:63
 AtlConvFinder.h:64
 AtlConvFinder.h:65
 AtlConvFinder.h:66
 AtlConvFinder.h:67
 AtlConvFinder.h:68
 AtlConvFinder.h:69
 AtlConvFinder.h:70
 AtlConvFinder.h:71
 AtlConvFinder.h:72
 AtlConvFinder.h:73
 AtlConvFinder.h:74
 AtlConvFinder.h:75
 AtlConvFinder.h:76
 AtlConvFinder.h:77
 AtlConvFinder.h:78
 AtlConvFinder.h:79
 AtlConvFinder.h:80
 AtlConvFinder.h:81
 AtlConvFinder.h:82
 AtlConvFinder.h:83
 AtlConvFinder.h:84
 AtlConvFinder.h:85
 AtlConvFinder.h:86
 AtlConvFinder.h:87
 AtlConvFinder.h:88
 AtlConvFinder.h:89
 AtlConvFinder.h:90
 AtlConvFinder.h:91
 AtlConvFinder.h:92
 AtlConvFinder.h:93
 AtlConvFinder.h:94
 AtlConvFinder.h:95
 AtlConvFinder.h:96
 AtlConvFinder.h:97
 AtlConvFinder.h:98
 AtlConvFinder.h:99
 AtlConvFinder.h:100
 AtlConvFinder.h:101
 AtlConvFinder.h:102
 AtlConvFinder.h:103
 AtlConvFinder.h:104
 AtlConvFinder.h:105
 AtlConvFinder.h:106
 AtlConvFinder.h:107
 AtlConvFinder.h:108
 AtlConvFinder.h:109
 AtlConvFinder.h:110
 AtlConvFinder.h:111
 AtlConvFinder.h:112
 AtlConvFinder.h:113
 AtlConvFinder.h:114
 AtlConvFinder.h:115
 AtlConvFinder.h:116
 AtlConvFinder.h:117
 AtlConvFinder.h:118
 AtlConvFinder.h:119
 AtlConvFinder.h:120
 AtlConvFinder.h:121
 AtlConvFinder.h:122
 AtlConvFinder.h:123
 AtlConvFinder.h:124
 AtlConvFinder.h:125
 AtlConvFinder.h:126
 AtlConvFinder.h:127
 AtlConvFinder.h:128
 AtlConvFinder.h:129
 AtlConvFinder.h:130
 AtlConvFinder.h:131
 AtlConvFinder.h:132
 AtlConvFinder.h:133
 AtlConvFinder.h:134
 AtlConvFinder.h:135
 AtlConvFinder.h:136
 AtlConvFinder.h:137
 AtlConvFinder.h:138
 AtlConvFinder.h:139
 AtlConvFinder.h:140
 AtlConvFinder.h:141
 AtlConvFinder.h:142
 AtlConvFinder.h:143
 AtlConvFinder.h:144
 AtlConvFinder.h:145
 AtlConvFinder.h:146
 AtlConvFinder.h:147
 AtlConvFinder.h:148
 AtlConvFinder.h:149
 AtlConvFinder.h:150
 AtlConvFinder.h:151
 AtlConvFinder.h:152
 AtlConvFinder.h:153
 AtlConvFinder.h:154
 AtlConvFinder.h:155
 AtlConvFinder.h:156
 AtlConvFinder.h:157
 AtlConvFinder.h:158
 AtlConvFinder.h:159
 AtlConvFinder.h:160
 AtlConvFinder.h:161
 AtlConvFinder.h:162
 AtlConvFinder.h:163
 AtlConvFinder.h:164
 AtlConvFinder.h:165
 AtlConvFinder.h:166
 AtlConvFinder.h:167
 AtlConvFinder.h:168
 AtlConvFinder.h:169
 AtlConvFinder.h:170
 AtlConvFinder.h:171
 AtlConvFinder.h:172
 AtlConvFinder.h:173