#ifndef TDsECalElectronControlSample_h
#define TDsECalElectronControlSample_h

#include "TGraph.h"
#include "TH1F.h"
#include <IControlSampleBase.hxx>
#include <IReconBase.hxx>
#include <ITrackState.hxx>

// Class to select electrons entering the DsECal, based on TPC3 information
class IDsECalElectronControlSample : public IControlSampleBase {
 public:
  IDsECalElectronControlSample();
  ~IDsECalElectronControlSample();

private:
  
  bool IsEventSelectedInternal(COMET::ICOMETEvent& event) ;
  void InitHistograms();

  /// Get the direction of the last node in the object with
  /// respect to the Z axis, in degrees
  double GetBackAngleToZ(COMET::IHandle<COMET::IReconBase> object);

  /// Get the momentum of the first node in the object
  double GetFrontMomentum(COMET::IHandle<COMET::IReconBase> object);

  /// Whether the object passes the TPC pull cuts
  bool PassesPullCuts(COMET::IHandle<COMET::IReconBase> object);

  /// Whether the last node of the object lies in the region
  /// defined as being near the front face of the DsECal
  bool AtDsECalFrontFace(COMET::IHandle<COMET::IReconBase> object);

  /// Histogram of momenta of selected tracks
  TH1F* hMom;


  // Track-level cuts

  /// Reject tracks with fewer than this number of hits
  int fMinTpc3Hits;

  /// Reject tracks with electron pull outside this region
  double fMinElePullAccept;
  double fMaxElePullAccept;

  /// Reject tracks with muon pull in this region
  double fMinMuonPullReject;
  double fMaxMuonPullReject;

  /// Reject tracks with pion pull in this region
  double fMinPionPullReject;
  double fMaxPionPullReject;

  /// Reject tracks with momentum less than this
  double fMinMomentum;

  /// Reject tracks with momentum greater than this
  double fMaxMomentum;

  /// Reject tracks with a final direction greater than this
  double fTpc3BackDirMaxAngle;


  // Event-level cuts

  /// Maximum number of TPC3 objects in event
  unsigned int fMaxNumTpc3Objects;

  /// Maximum number of TPC3 objects in event  that pass all our cuts
  unsigned int fMaxNumTpc3ObjectsPassingAllCuts;

};

#endif