// Do NOT change. Changes will be lost next time file is generated

#define R__DICTIONARY_FILENAME dIhomedIyuhwdIwcdIwiremIcelldIbuilddIsstdIWCPSstDict
#define R__NO_DEPRECATION

/*******************************************************************/
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#define G__DICTIONARY
#include "RConfig.h"
#include "TClass.h"
#include "TDictAttributeMap.h"
#include "TInterpreter.h"
#include "TROOT.h"
#include "TBuffer.h"
#include "TMemberInspector.h"
#include "TInterpreter.h"
#include "TVirtualMutex.h"
#include "TError.h"

#ifndef G__ROOT
#define G__ROOT
#endif

#include "RtypesImp.h"
#include "TIsAProxy.h"
#include "TFileMergeInfo.h"
#include <algorithm>
#include "TCollectionProxyInfo.h"
/*******************************************************************/

#include "TDataMember.h"

// The generated code does not explicitly qualifies STL entities
namespace std {} using namespace std;

// Header files passed as explicit arguments
#include "/home/yuhw/wc/wire-cell/sst/inc/WCPSst/DatauBooNEFrameDataSource.h"
#include "/home/yuhw/wc/wire-cell/sst/inc/WCPSst/DatauBooNEFrameDataSource_afterHF.h"
#include "/home/yuhw/wc/wire-cell/sst/inc/WCPSst/DetectorGDS.h"
#include "/home/yuhw/wc/wire-cell/sst/inc/WCPSst/FrameDataSource.h"
#include "/home/yuhw/wc/wire-cell/sst/inc/WCPSst/GeomDataSource.h"
#include "/home/yuhw/wc/wire-cell/sst/inc/WCPSst/MCTruth.h"
#include "/home/yuhw/wc/wire-cell/sst/inc/WCPSst/NewDatauBooNEFrameDataSource.h"
#include "/home/yuhw/wc/wire-cell/sst/inc/WCPSst/RootEvent.h"
#include "/home/yuhw/wc/wire-cell/sst/inc/WCPSst/RootSimTruth.h"
#include "/home/yuhw/wc/wire-cell/sst/inc/WCPSst/SimulationuBooNEFrameDataSource.h"
#include "/home/yuhw/wc/wire-cell/sst/inc/WCPSst/ToyuBooNEFrameDataSource.h"
#include "/home/yuhw/wc/wire-cell/sst/inc/WCPSst/ToyuBooNESliceDataSource.h"
#include "/home/yuhw/wc/wire-cell/sst/inc/WCPSst/Util.h"
#include "/home/yuhw/wc/wire-cell/sst/inc/WCPSst/uBooNESliceDataSource.h"

// Header files passed via #pragma extra_include

namespace WCPSst {
   namespace ROOT {
      inline ::ROOT::TGenericClassInfo *GenerateInitInstance();
      static TClass *WCPSst_Dictionary();

      // Function generating the singleton type initializer
      inline ::ROOT::TGenericClassInfo *GenerateInitInstance()
      {
         static ::ROOT::TGenericClassInfo 
            instance("WCPSst", 0 /*version*/, "WCPSst/RootEvent.h", 7,
                     ::ROOT::Internal::DefineBehavior((void*)0,(void*)0),
                     &WCPSst_Dictionary, 0);
         return &instance;
      }
      // Insure that the inline function is _not_ optimized away by the compiler
      ::ROOT::TGenericClassInfo *(*_R__UNIQUE_DICT_(InitFunctionKeeper))() = &GenerateInitInstance;  
      // Static variable to force the class initialization
      static ::ROOT::TGenericClassInfo *_R__UNIQUE_DICT_(Init) = GenerateInitInstance(); R__UseDummy(_R__UNIQUE_DICT_(Init));

      // Dictionary for non-ClassDef classes
      static TClass *WCPSst_Dictionary() {
         return GenerateInitInstance()->GetClass();
      }

   }
}

namespace ROOT {
   static TClass *WCPSstcLcLRootEvent_Dictionary();
   static void WCPSstcLcLRootEvent_TClassManip(TClass*);
   static void *new_WCPSstcLcLRootEvent(void *p = 0);
   static void *newArray_WCPSstcLcLRootEvent(Long_t size, void *p);
   static void delete_WCPSstcLcLRootEvent(void *p);
   static void deleteArray_WCPSstcLcLRootEvent(void *p);
   static void destruct_WCPSstcLcLRootEvent(void *p);

   // Function generating the singleton type initializer
   static TGenericClassInfo *GenerateInitInstanceLocal(const ::WCPSst::RootEvent*)
   {
      ::WCPSst::RootEvent *ptr = 0;
      static ::TVirtualIsAProxy* isa_proxy = new ::TIsAProxy(typeid(::WCPSst::RootEvent));
      static ::ROOT::TGenericClassInfo 
         instance("WCPSst::RootEvent", "WCPSst/RootEvent.h", 9,
                  typeid(::WCPSst::RootEvent), ::ROOT::Internal::DefineBehavior(ptr, ptr),
                  &WCPSstcLcLRootEvent_Dictionary, isa_proxy, 0,
                  sizeof(::WCPSst::RootEvent) );
      instance.SetNew(&new_WCPSstcLcLRootEvent);
      instance.SetNewArray(&newArray_WCPSstcLcLRootEvent);
      instance.SetDelete(&delete_WCPSstcLcLRootEvent);
      instance.SetDeleteArray(&deleteArray_WCPSstcLcLRootEvent);
      instance.SetDestructor(&destruct_WCPSstcLcLRootEvent);
      return &instance;
   }
   TGenericClassInfo *GenerateInitInstance(const ::WCPSst::RootEvent*)
   {
      return GenerateInitInstanceLocal((::WCPSst::RootEvent*)0);
   }
   // Static variable to force the class initialization
   static ::ROOT::TGenericClassInfo *_R__UNIQUE_DICT_(Init) = GenerateInitInstanceLocal((const ::WCPSst::RootEvent*)0x0); R__UseDummy(_R__UNIQUE_DICT_(Init));

   // Dictionary for non-ClassDef classes
   static TClass *WCPSstcLcLRootEvent_Dictionary() {
      TClass* theClass =::ROOT::GenerateInitInstanceLocal((const ::WCPSst::RootEvent*)0x0)->GetClass();
      WCPSstcLcLRootEvent_TClassManip(theClass);
   return theClass;
   }

   static void WCPSstcLcLRootEvent_TClassManip(TClass* ){
   }

} // end of namespace ROOT

namespace ROOT {
   static TClass *WCPSstcLcLFrameDataSource_Dictionary();
   static void WCPSstcLcLFrameDataSource_TClassManip(TClass*);
   static void delete_WCPSstcLcLFrameDataSource(void *p);
   static void deleteArray_WCPSstcLcLFrameDataSource(void *p);
   static void destruct_WCPSstcLcLFrameDataSource(void *p);

   // Function generating the singleton type initializer
   static TGenericClassInfo *GenerateInitInstanceLocal(const ::WCPSst::FrameDataSource*)
   {
      ::WCPSst::FrameDataSource *ptr = 0;
      static ::TVirtualIsAProxy* isa_proxy = new ::TIsAProxy(typeid(::WCPSst::FrameDataSource));
      static ::ROOT::TGenericClassInfo 
         instance("WCPSst::FrameDataSource", "", 322,
                  typeid(::WCPSst::FrameDataSource), ::ROOT::Internal::DefineBehavior(ptr, ptr),
                  &WCPSstcLcLFrameDataSource_Dictionary, isa_proxy, 0,
                  sizeof(::WCPSst::FrameDataSource) );
      instance.SetDelete(&delete_WCPSstcLcLFrameDataSource);
      instance.SetDeleteArray(&deleteArray_WCPSstcLcLFrameDataSource);
      instance.SetDestructor(&destruct_WCPSstcLcLFrameDataSource);
      return &instance;
   }
   TGenericClassInfo *GenerateInitInstance(const ::WCPSst::FrameDataSource*)
   {
      return GenerateInitInstanceLocal((::WCPSst::FrameDataSource*)0);
   }
   // Static variable to force the class initialization
   static ::ROOT::TGenericClassInfo *_R__UNIQUE_DICT_(Init) = GenerateInitInstanceLocal((const ::WCPSst::FrameDataSource*)0x0); R__UseDummy(_R__UNIQUE_DICT_(Init));

   // Dictionary for non-ClassDef classes
   static TClass *WCPSstcLcLFrameDataSource_Dictionary() {
      TClass* theClass =::ROOT::GenerateInitInstanceLocal((const ::WCPSst::FrameDataSource*)0x0)->GetClass();
      WCPSstcLcLFrameDataSource_TClassManip(theClass);
   return theClass;
   }

   static void WCPSstcLcLFrameDataSource_TClassManip(TClass* ){
   }

} // end of namespace ROOT

namespace ROOT {
   static TClass *WCPSstcLcLGeomDataSource_Dictionary();
   static void WCPSstcLcLGeomDataSource_TClassManip(TClass*);
   static void *new_WCPSstcLcLGeomDataSource(void *p = 0);
   static void *newArray_WCPSstcLcLGeomDataSource(Long_t size, void *p);
   static void delete_WCPSstcLcLGeomDataSource(void *p);
   static void deleteArray_WCPSstcLcLGeomDataSource(void *p);
   static void destruct_WCPSstcLcLGeomDataSource(void *p);

   // Function generating the singleton type initializer
   static TGenericClassInfo *GenerateInitInstanceLocal(const ::WCPSst::GeomDataSource*)
   {
      ::WCPSst::GeomDataSource *ptr = 0;
      static ::TVirtualIsAProxy* isa_proxy = new ::TIsAProxy(typeid(::WCPSst::GeomDataSource));
      static ::ROOT::TGenericClassInfo 
         instance("WCPSst::GeomDataSource", "", 367,
                  typeid(::WCPSst::GeomDataSource), ::ROOT::Internal::DefineBehavior(ptr, ptr),
                  &WCPSstcLcLGeomDataSource_Dictionary, isa_proxy, 0,
                  sizeof(::WCPSst::GeomDataSource) );
      instance.SetNew(&new_WCPSstcLcLGeomDataSource);
      instance.SetNewArray(&newArray_WCPSstcLcLGeomDataSource);
      instance.SetDelete(&delete_WCPSstcLcLGeomDataSource);
      instance.SetDeleteArray(&deleteArray_WCPSstcLcLGeomDataSource);
      instance.SetDestructor(&destruct_WCPSstcLcLGeomDataSource);
      return &instance;
   }
   TGenericClassInfo *GenerateInitInstance(const ::WCPSst::GeomDataSource*)
   {
      return GenerateInitInstanceLocal((::WCPSst::GeomDataSource*)0);
   }
   // Static variable to force the class initialization
   static ::ROOT::TGenericClassInfo *_R__UNIQUE_DICT_(Init) = GenerateInitInstanceLocal((const ::WCPSst::GeomDataSource*)0x0); R__UseDummy(_R__UNIQUE_DICT_(Init));

   // Dictionary for non-ClassDef classes
   static TClass *WCPSstcLcLGeomDataSource_Dictionary() {
      TClass* theClass =::ROOT::GenerateInitInstanceLocal((const ::WCPSst::GeomDataSource*)0x0)->GetClass();
      WCPSstcLcLGeomDataSource_TClassManip(theClass);
   return theClass;
   }

   static void WCPSstcLcLGeomDataSource_TClassManip(TClass* ){
   }

} // end of namespace ROOT

namespace ROOT {
   // Wrappers around operator new
   static void *new_WCPSstcLcLRootEvent(void *p) {
      return  p ? ::new((::ROOT::Internal::TOperatorNewHelper*)p) ::WCPSst::RootEvent : new ::WCPSst::RootEvent;
   }
   static void *newArray_WCPSstcLcLRootEvent(Long_t nElements, void *p) {
      return p ? ::new((::ROOT::Internal::TOperatorNewHelper*)p) ::WCPSst::RootEvent[nElements] : new ::WCPSst::RootEvent[nElements];
   }
   // Wrapper around operator delete
   static void delete_WCPSstcLcLRootEvent(void *p) {
      delete ((::WCPSst::RootEvent*)p);
   }
   static void deleteArray_WCPSstcLcLRootEvent(void *p) {
      delete [] ((::WCPSst::RootEvent*)p);
   }
   static void destruct_WCPSstcLcLRootEvent(void *p) {
      typedef ::WCPSst::RootEvent current_t;
      ((current_t*)p)->~current_t();
   }
} // end of namespace ROOT for class ::WCPSst::RootEvent

namespace ROOT {
   // Wrapper around operator delete
   static void delete_WCPSstcLcLFrameDataSource(void *p) {
      delete ((::WCPSst::FrameDataSource*)p);
   }
   static void deleteArray_WCPSstcLcLFrameDataSource(void *p) {
      delete [] ((::WCPSst::FrameDataSource*)p);
   }
   static void destruct_WCPSstcLcLFrameDataSource(void *p) {
      typedef ::WCPSst::FrameDataSource current_t;
      ((current_t*)p)->~current_t();
   }
} // end of namespace ROOT for class ::WCPSst::FrameDataSource

namespace ROOT {
   // Wrappers around operator new
   static void *new_WCPSstcLcLGeomDataSource(void *p) {
      return  p ? ::new((::ROOT::Internal::TOperatorNewHelper*)p) ::WCPSst::GeomDataSource : new ::WCPSst::GeomDataSource;
   }
   static void *newArray_WCPSstcLcLGeomDataSource(Long_t nElements, void *p) {
      return p ? ::new((::ROOT::Internal::TOperatorNewHelper*)p) ::WCPSst::GeomDataSource[nElements] : new ::WCPSst::GeomDataSource[nElements];
   }
   // Wrapper around operator delete
   static void delete_WCPSstcLcLGeomDataSource(void *p) {
      delete ((::WCPSst::GeomDataSource*)p);
   }
   static void deleteArray_WCPSstcLcLGeomDataSource(void *p) {
      delete [] ((::WCPSst::GeomDataSource*)p);
   }
   static void destruct_WCPSstcLcLGeomDataSource(void *p) {
      typedef ::WCPSst::GeomDataSource current_t;
      ((current_t*)p)->~current_t();
   }
} // end of namespace ROOT for class ::WCPSst::GeomDataSource

namespace {
  void TriggerDictionaryInitialization_WCPSstDict_Impl() {
    static const char* headers[] = {
"0",
0
    };
    static const char* includePaths[] = {
0
    };
    static const char* fwdDeclCode = R"DICTFWDDCLS(
#line 1 "WCPSstDict dictionary forward declarations' payload"
#pragma clang diagnostic ignored "-Wkeyword-compat"
#pragma clang diagnostic ignored "-Wignored-attributes"
#pragma clang diagnostic ignored "-Wreturn-type-c-linkage"
extern int __Cling_AutoLoading_Map;
namespace WCPSst{struct __attribute__((annotate("$clingAutoload$WCPSst/RootEvent.h")))  RootEvent;}
namespace WCPSst{class FrameDataSource;}
namespace WCPSst{class GeomDataSource;}
)DICTFWDDCLS";
    static const char* payloadCode = R"DICTPAYLOAD(
#line 1 "WCPSstDict dictionary payload"


#define _BACKWARD_BACKWARD_WARNING_H
// Inline headers
#ifndef WIRECELLSST_DATAUBOONEFRAMEDATASOURCE_H
#define  WIRECELLSST_DATAUBOONEFRAMEDATASOURCE_H

#include "WCPNav/FrameDataSource.h"
#include "WCPSst/RootEvent.h"
#include "WCPNav/GeomDataSource.h"
#include "WCPData/GeomWire.h"
#include "WCPData/PMTNoiseROI.h"

#include "TTree.h"
#include "TH1F.h"
#include "TH2F.h"

namespace WCPSst {

 

    /**
       
     */
    class DatauBooNEFrameDataSource : public WCP::FrameDataSource {
      //mutable TTree* tree;	// or TChain
      //WCPSst::RootEvent event;

      public:
      DatauBooNEFrameDataSource(const char* root_file, const WCP::GeomDataSource& gds,int bins_per_frame1 = 9600, int inactiveNF = 0, int flag_add_noise = 0);
	DatauBooNEFrameDataSource(const TH2F *hu_raw, const TH2F *hv_raw, const TH2F *hw_raw, TTree *T_bad, TTree *T_lf, TTree *Trun, const WCP::GeomDataSource& gds);

	virtual ~DatauBooNEFrameDataSource();

	void Save();
	void Clear();

	/// Return the number of frames this data source knows about.  Return -1 if unlimited.
	virtual int size() const;

	/// Explicitly set the "frame" (event) to process.  Frame number returned or -1 on error.
	virtual int jump(int frame_number);

    // Dummy noise filter for processing simulation w/o noise
	virtual int jump_no_noise(int frame_number);

	void fix_ADC_shift(int chid, TH1F *h1);
	int shift_right(int value, int n, int filling, int totalBit);
	int lowest_bits(int value, int n);


	bool chirp_check(double rms, int plane, int channel);
	double correlation1(TH1F *h1, TH1F *h2);
	
 	void GetChannelStatus(TH1F *h1, int plane, int chan, bool& isCut, double &rmsOut);
	void zigzag_removal(TH1F *h1, int plane, int channel_no, int flag_RC = 1, int flag_restore=0);
	bool ID_RC(TH1F *h1, int plane, int channel_no);

	bool ID_lf_noisy(TH1F *h1);

	void chirp_id(TH1F *h1, int plane, int channel_no);

	void chirp_raise_baseline(TH1F *h1, int bin1, int bin2);

	void SignalFilter(TH1F *h1);
	double CalcRMSWithFlags(TH1F *hist);
	void RemoveFilterFlags(TH1F *hist);
	void RawAdaptiveBaselineAlg(TH1F *hist);
	void NoisyFilterAlg(TH1F *hist, int plane, int channel_no);
	
	void IDPMTSignalCollection(TH1F *hist, float rms, int channel);
	void IDPMTSignalInduction(TH1F *hist, float rms, int plane, int channel);
	void RemovePMTSignal(TH1F *hist, int start_bin, int end_bin, int flag=0);
	
	void Simu_Noise_uBooNE_Empirical(TH1F *h1, Int_t plane, Int_t channel);

	int get_run_no(){return run_no;};
	int get_subrun_no(){return subrun_no;};
	int get_event_no(){return event_no;};

	WCP::WireMap& get_u_map(){return uplane_map;};
	WCP::WireMap& get_v_map(){return vplane_map;};
	WCP::WireMap& get_w_map(){return wplane_map;};

	WCP::ChirpMap& get_u_cmap(){return uchirp_map;};
	WCP::ChirpMap& get_v_cmap(){return vchirp_map;};
	WCP::ChirpMap& get_w_cmap(){return wchirp_map;};

	std::set<int>& get_lf_noisy_channels(){return lf_noisy_channels;};

    private:
	std::vector<WCP::PMTNoiseROI*> PMT_ROIs;
	
	int flag_add_noise;
	int inactiveNF;

	const WCP::GeomDataSource& gds;
	const char* root_file;
	int nwire_u, nwire_v, nwire_w;

	int nevents;
	
	int flag_mis_config;
	
	bool load_results_from_file;

	int run_no, subrun_no, event_no;

	WCP::WireMap uplane_map;
	WCP::WireMap vplane_map;
	WCP::WireMap wplane_map;

	WCP::ChirpMap uchirp_map;
	WCP::ChirpMap vchirp_map;
	WCP::ChirpMap wchirp_map;
	
	std::set<int> lf_noisy_channels;

	std::map<int, float> urms_map;
	std::map<int, float> vrms_map;
	std::map<int, float> wrms_map;

	// RC+RC 
	TH1F *h_rc;
	TH1 *hm_rc, *hp_rc;
	TH1F *h_1us;
	TH1 *hm_1us, *hp_1us;
	TH1F *h_2us;
	TH1 *hm_2us, *hp_2us;

	/* TH1F *hu_resp; */
	/* TH1F *hv_resp; */
    };

    

}

#endif
#ifndef WIRECELLSST_DATAUBOONEFRAMEDATASOURCE_AFTERHF_H
#define  WIRECELLSST_DATAUBOONEFRAMEDATASOURCE_AFTERHF_H

#include "WCPNav/FrameDataSource.h"
#include "WCPSst/RootEvent.h"
#include "WCPNav/GeomDataSource.h"
#include "WCPData/GeomWire.h"
#include "WCPData/PMTNoiseROI.h"

#include "TTree.h"
#include "TH1F.h"
#include "TH2F.h"

namespace WCPSst {

 

    /**
       
     */
    class DatauBooNEFrameDataSource_afterHF : public WCP::FrameDataSource {
      //mutable TTree* tree;	// or TChain
      //WCPSst::RootEvent event;

      public:


      DatauBooNEFrameDataSource_afterHF(const char* root_file, const WCP::GeomDataSource& gds,int bins_per_frame1 = 9600, int flag_add_noise = 0);
	DatauBooNEFrameDataSource_afterHF(const TH2F *hu_raw, const TH2F *hv_raw, const TH2F *hw_raw, TTree *T_bad, TTree *T_lf, TTree *Trun, const WCP::GeomDataSource& gds);

	virtual ~DatauBooNEFrameDataSource_afterHF();

	void Save();
	void Clear();

	/// Return the number of frames this data source knows about.  Return -1 if unlimited.
	virtual int size() const;

	/// Explicitly set the "frame" (event) to process.  Frame number returned or -1 on error.
	virtual int jump(int frame_number);

	void fix_ADC_shift(int chid, TH1F *h1);
	int shift_right(int value, int n, int filling, int totalBit);
	int lowest_bits(int value, int n);



	bool chirp_check(double rms, int plane, int channel);
	double correlation1(TH1F *h1, TH1F *h2);
	
 	void GetChannelStatus(TH1F *h1, int plane, int chan, bool& isCut, double &rmsOut);
	void zigzag_removal(TH1F *h1, int plane, int channel_no, int flag_RC = 1);
	bool ID_RC(TH1F *h1, int plane, int channel_no);

	bool ID_lf_noisy(TH1F *h1);

	void chirp_id(TH1F *h1, int plane, int channel_no);

	void chirp_raise_baseline(TH1F *h1, int bin1, int bin2);

	void SignalFilter(TH1F *h1);
	double CalcRMSWithFlags(TH1F *hist);
	void RemoveFilterFlags(TH1F *hist);
	void RawAdaptiveBaselineAlg(TH1F *hist);
	void NoisyFilterAlg(TH1F *hist, int plane, int channel_no);
	void RemovePMTSignalCollection(TH1F *hist, float rms, int channel);
	void IDPMTSignalInduction(TH1F *hist, float rms, int plane, int channel);
	void RemovePMTSignalInduction(TH1F *hist, int start_bin, int end_bin);


	void Simu_Noise_uBooNE_Empirical(TH1F *h1, Int_t plane, Int_t channel);

	int get_run_no(){return run_no;};
	int get_subrun_no(){return subrun_no;};
	int get_event_no(){return event_no;};

	WCP::WireMap& get_u_map(){return uplane_map;};
	WCP::WireMap& get_v_map(){return vplane_map;};
	WCP::WireMap& get_w_map(){return wplane_map;};

	WCP::ChirpMap& get_u_cmap(){return uchirp_map;};
	WCP::ChirpMap& get_v_cmap(){return vchirp_map;};
	WCP::ChirpMap& get_w_cmap(){return wchirp_map;};

	std::set<int>& get_lf_noisy_channels(){return lf_noisy_channels;};



    private:
	std::vector<WCP::PMTNoiseROI*> PMT_ROIs;

	int flag_add_noise;

	const WCP::GeomDataSource& gds;
	const char* root_file;
	int nwire_u, nwire_v, nwire_w;

	int nevents;
	
	int flag_mis_config;
	
	bool load_results_from_file;

	int run_no, subrun_no, event_no;

	WCP::WireMap uplane_map;
	WCP::WireMap vplane_map;
	WCP::WireMap wplane_map;

	WCP::ChirpMap uchirp_map;
	WCP::ChirpMap vchirp_map;
	WCP::ChirpMap wchirp_map;
	
	std::set<int> lf_noisy_channels;

	std::map<int, float> urms_map;
	std::map<int, float> vrms_map;
	std::map<int, float> wrms_map;

	// RC+RC 
	TH1F *h_rc;
	TH1 *hm_rc, *hp_rc;
	TH1F *h_1us;
	TH1 *hm_1us, *hp_1us;
	TH1F *h_2us;
	TH1 *hm_2us, *hp_2us;

	/* TH1F *hu_resp; */
	/* TH1F *hv_resp; */
    };

    

}

#endif
#ifndef WIRECELLSST_DETECTORGDS
#define WIRECELLSST_DETECTORGDS

#include "WCPNav/DetectorGDS.h"
#include "WCPNav/GeomDataSource.h"
#include "WCPNav/WrappedGDS.h"

#include <istream>
#include <string>
#include <vector>

namespace WCPSst {

    /**
       WCPSst::DetectorGDS - read in a Channel Wire Geometry database.
       
     */

    class DetectorGDS : public WCP::DetectorGDS {//WCP::DetectorGDS {
    public:
	/// Read from an input stream containing content from ChannelWireGeometry.txt
        DetectorGDS(std::vector<std::string> geometry);
	virtual ~DetectorGDS();

    };

} 

#endif
#ifndef WIRECELLSST_FRAMEDATASOURCE_H
#define  WIRECELLSST_FRAMEDATASOURCE_H

#include "WCPNav/FrameDataSource.h"
#include "WCPNav/SimDataSource.h"
#include "WCPData/SimTruth.h"
#include "WCPSst/RootEvent.h"
#include "WCPSst/RootSimTruth.h"

#include "TTree.h"

namespace WCPSst {

    /**
       
     */
    class FrameDataSource : public WCP::FrameDataSource, virtual public WCP::SimDataSource {
	mutable TTree *event_tree, *sim_tree;	// or TChain
	WCPSst::RootEvent event;
	mutable WCPSst::RootSimTruth rootsimtruth;
	mutable WCP::SimTruthSet simtruth;

      public:
	FrameDataSource(TTree& event_tree, const char* br="calib");
	virtual ~FrameDataSource();

	/// Return the number of frames this data source knows about.  Return -1 if unlimited.
	virtual int size() const;

	/// Explicitly set the "frame" (event) to process.  Frame number returned or -1 on error.
	virtual int jump(int frame_number);

	/// Must explicitly set sim tree if truth() is going to be useful
	void set_sim_tree(TTree& sim_tree);

	/// Access to the sim truth objects
	WCP::SimTruthSelection truth() const; 
	
	

    };

}

#endif
#ifndef WIRECELLSST_GEOMETRYDATASOURCE
#define WIRECELLSST_GEOMETRYDATASOURCE

#include "WCPNav/GeomDataSource.h"

#include <istream>

namespace WCPSst {

    /**
       WCPSst::GeomDataSource - read in a Channel Wire Geometry database.

       
     */

    class GeomDataSource : public WCP::GeomDataSource {
    public:
	/// Read from an input stream containing content from ChannelWireGeometry.txt
	GeomDataSource(const char* filename=0);
	virtual ~GeomDataSource();

	void load(std::istream& data);


    };

} 

#endif
#ifndef WIRECELLSST_MCTRUTH_H
#define WIRECELLSST_MCTRUTH_H

#include "TClonesArray.h"
#include "TObjArray.h"
#include <vector>
#include <iostream>
#include <string>
#include "TFile.h"
#include "TTree.h"

#include "WCPData/Point.h"
#include "WCPData/MCParticle.h"

#define MAX_TRACKS 10000

namespace WCPSst {

  class MCTruth {
  public:
    MCTruth(std::string rootfile);
    MCTruth(TTree *TMC);
    
    ~MCTruth();
    void GetEntry(int i);
    void Rotate_Shift(float x_center=0, float y_center=0, float z_center=0, float rotate_angle=0, float x_shift=0, float y_shift=0, float z_shift=0);

    WCP::Point find_primary_vertex(int event_no = 0);
    WCP::Point find_neutrino_vertex(int event_no = 0);
    WCP::MCParticle* find_primary_electron(int event_no = 0);
    WCP::MCParticleSelection find_primary_photons(int event_no = 0);
    float find_neutrino_true_energy(int event_no=0);
    float find_neutrino_visible_energy(int event_no = 0);

  private:
    TTree *mcTree;

    
    
  public:
    int runNo;
    int subrunNo;
    int eventNo;
    int mc_Ntrack;  // number of tracks in MC
    int mc_id[MAX_TRACKS];  // track id; size == mc_Ntrack
    int mc_pdg[MAX_TRACKS];  // track particle pdg; size == mc_Ntrack
    int mc_process[MAX_TRACKS];  // track generation process code; size == mc_Ntrack
    int mc_mother[MAX_TRACKS];  // mother id of this track; size == mc_Ntrack
    float mc_startXYZT[MAX_TRACKS][4];  // start position of this track; size == mc_Ntrack
    float mc_endXYZT[MAX_TRACKS][4];  // end position of this track; size == mc_Ntrack
    float mc_startMomentum[MAX_TRACKS][4];  // start momentum of this track; size == mc_Ntrack
    float mc_endMomentum[MAX_TRACKS][4];  // end momentum of this track; size == mc_Ntrack
    std::vector<std::vector<int> > *mc_daughters;  // daughters id of this track; vector
    TObjArray* mc_trackPosition;  

    int mc_isnu; // is neutrino interaction
    int mc_nGeniePrimaries; // number of Genie primaries
    int mc_nu_pdg; // pdg code of neutrino
    int mc_nu_ccnc; // cc or nc
    int mc_nu_mode; // mode: http://nusoft.fnal.gov/larsoft/doxsvn/html/MCNeutrino_8h_source.html
    int mc_nu_intType; // interaction type
    int mc_nu_target; // target interaction
    int mc_hitnuc; // hit nucleon
    int mc_hitquark; // hit quark
    double mc_nu_Q2; // Q^2
    double mc_nu_W; // W
    double mc_nu_X; // X
    double mc_nu_Y; // Y
    double mc_nu_Pt; // Pt
    double mc_nu_Theta; // angle relative to lepton
    float mc_nu_pos[4];  // interaction position of nu
    float mc_nu_mom[4];  // interaction momentum of nu

    float mc_oldVertex[3];
  };
  
}

#endif
#ifndef WIRECELLSST_NEWDATAUBOONEFRAMEDATASOURCE_H
#define WIRECELLSST_NEWDATAUBOONEFRAMEDATASOURCE_H

#include "WCPNav/FrameDataSource.h"
#include "WCPSst/RootEvent.h"
#include "WCPNav/GeomDataSource.h"
#include "WCPData/GeomWire.h"

#include "TTree.h"
#include "TH1F.h"

namespace WCPSst {

 

    /**
       
     */
    class NewDatauBooNEFrameDataSource : public WCP::FrameDataSource {
	mutable TTree* tree;	// or TChain
	WCPSst::RootEvent event;

      public:
	NewDatauBooNEFrameDataSource(TTree& tree, const WCP::GeomDataSource& gds,int bins_per_frame1 = 9600);
	virtual ~NewDatauBooNEFrameDataSource();

        Int_t fPlaneNum;

	void Save();

	/// Return the number of frames this data source knows about.  Return -1 if unlimited.
	virtual int size() const;

	/// Explicitly set the "frame" (event) to process.  Frame number returned or -1 on error.
	virtual int jump(int frame_number);

        Double_t CalcRMSWithFlags(TH1F *hist);
        void ChirpFilterAlg(TH1F *hist);
        void ZigzagFilterAlg(TH1F *hist);
        void SignalFilterAlg(TH1F *hist);
        void NoisyFilterAlg(TH1F *hist,int planeNum);
        void WaveFilterAlg(TH1F **filtHists);
        void RawAdaptiveBaselineAlg(TH1F *filtHist) ;
        void RemoveFilterFlags(TH1F *filtHist);


    private:
	const WCP::GeomDataSource& gds;
	int nwire_u, nwire_v, nwire_w;

	TH1F **hu;
        TH1F **hv;
        TH1F **hw;
    };

    

}

#endif
#ifndef WIRECELLSST_ROOTEVENT_H
#define WIRECELLSST_ROOTEVENT_H

#include "TClonesArray.h"
#include <vector>

namespace WCPSst{

    struct RootEvent {
	RootEvent();
	~RootEvent();
	

	int number;
	int run;
	int subrun;
	int nchannels;
	std::vector<int> *channelid;
	TClonesArray* signal;
    };
}

#endif
#ifndef WIRECELLSST_ROOTSIMTRUTH_H
#define WIRECELLSST_ROOTSIMTRUTH_H

#include "TClonesArray.h"
#include <vector>

namespace WCPSst{

    /// Match structure of the SST sim truth
    struct RootSimTruth {

	int size;
	std::vector<int>   *channelIdY;
	std::vector<int>   *trackId;
	std::vector<int>   *tdc;
	std::vector<float> *x;
	std::vector<float> *y;
	std::vector<float> *z;
	std::vector<float> *q;


	RootSimTruth();
	~RootSimTruth();

	void clear();

    };
}

#endif




#ifndef WIRECELLSST_SIMULATIONUBOONEFRAMEDATASOURCE_H
#define  WIRECELLSST_SIMULATIONUBOONEFRAMEDATASOURCE_H

#include "WCPNav/FrameDataSource.h"
#include "WCPSst/RootEvent.h"
#include "WCPNav/GeomDataSource.h"
#include "WCPData/GeomWire.h"
#include "WCPData/PMTNoiseROI.h"

#include "TTree.h"
#include "TH1F.h"
#include "TH2F.h"

namespace WCPSst {

 

    /**
       
     */
    class SimulationuBooNEFrameDataSource : public WCP::FrameDataSource {
      //mutable TTree* tree;	// or TChain
      //WCPSst::RootEvent event;

      public:
      SimulationuBooNEFrameDataSource(const char* root_file, const WCP::GeomDataSource& gds,int bins_per_frame1 = 9600, int flag_add_noise = 0);
	SimulationuBooNEFrameDataSource(const TH2F *hu_raw, const TH2F *hv_raw, const TH2F *hw_raw, TTree *T_bad, TTree *T_lf, TTree *Trun, const WCP::GeomDataSource& gds);

	virtual ~SimulationuBooNEFrameDataSource();

	void Save();
	void Clear();

	/// Return the number of frames this data source knows about.  Return -1 if unlimited.
	virtual int size() const;

	/// Explicitly set the "frame" (event) to process.  Frame number returned or -1 on error.
	virtual int jump(int frame_number);

    // Dummy noise filter for processing simulation w/o noise
	virtual int jump_no_noise(int frame_number);

	void fix_ADC_shift(int chid, TH1F *h1);
	int shift_right(int value, int n, int filling, int totalBit);
	int lowest_bits(int value, int n);


	bool chirp_check(double rms, int plane, int channel);
	double correlation1(TH1F *h1, TH1F *h2);
	
 	void GetChannelStatus(TH1F *h1, int plane, int chan, bool& isCut, double &rmsOut);
	void zigzag_removal(TH1F *h1, int plane, int channel_no, int flag_RC = 1, int flag_restore=0);
	bool ID_RC(TH1F *h1, int plane, int channel_no);

	bool ID_lf_noisy(TH1F *h1);

	void chirp_id(TH1F *h1, int plane, int channel_no);

	void chirp_raise_baseline(TH1F *h1, int bin1, int bin2);

	void SignalFilter(TH1F *h1);
	double CalcRMSWithFlags(TH1F *hist);
	void RemoveFilterFlags(TH1F *hist);
	void RawAdaptiveBaselineAlg(TH1F *hist);
	void NoisyFilterAlg(TH1F *hist, int plane, int channel_no);
	
	void IDPMTSignalCollection(TH1F *hist, float rms, int channel);
	void IDPMTSignalInduction(TH1F *hist, float rms, int plane, int channel);
	void RemovePMTSignal(TH1F *hist, int start_bin, int end_bin);
    
	void Simu_Noise_uBooNE_Empirical(TH1F *h1, Int_t plane, Int_t channel);

	int get_run_no(){return run_no;};
	int get_subrun_no(){return subrun_no;};
	int get_event_no(){return event_no;};

	WCP::WireMap& get_u_map(){return uplane_map;};
	WCP::WireMap& get_v_map(){return vplane_map;};
	WCP::WireMap& get_w_map(){return wplane_map;};

	WCP::ChirpMap& get_u_cmap(){return uchirp_map;};
	WCP::ChirpMap& get_v_cmap(){return vchirp_map;};
	WCP::ChirpMap& get_w_cmap(){return wchirp_map;};

	std::set<int>& get_lf_noisy_channels(){return lf_noisy_channels;};

    private:
	std::vector<WCP::PMTNoiseROI*> PMT_ROIs;
	
	int flag_add_noise;

	const WCP::GeomDataSource& gds;
	const char* root_file;
	int nwire_u, nwire_v, nwire_w;

	int nevents;
	
	int flag_mis_config;
	
	bool load_results_from_file;

	int run_no, subrun_no, event_no;

	WCP::WireMap uplane_map;
	WCP::WireMap vplane_map;
	WCP::WireMap wplane_map;

	WCP::ChirpMap uchirp_map;
	WCP::ChirpMap vchirp_map;
	WCP::ChirpMap wchirp_map;
	
	std::set<int> lf_noisy_channels;

	std::map<int, float> urms_map;
	std::map<int, float> vrms_map;
	std::map<int, float> wrms_map;

	// RC+RC 
	TH1F *h_rc;
	TH1 *hm_rc, *hp_rc;
	TH1F *h_1us;
	TH1 *hm_1us, *hp_1us;
	TH1F *h_2us;
	TH1 *hm_2us, *hp_2us;

	/* TH1F *hu_resp; */
	/* TH1F *hv_resp; */
    };

    

}

#endif
#ifndef WIRECELLSST_TOYUBOONEFRAMEDATASOURCE_H
#define  WIRECELLSST_TOYUBOONEFRAMEDATASOURCE_H

#include "WCPNav/FrameDataSource.h"
#include "WCPSst/RootEvent.h"
#include "WCPNav/GeomDataSource.h"

#include "TTree.h"
#include "TH1F.h"

namespace WCPSst {

    /**
       
     */
    class ToyuBooNEFrameDataSource : public WCP::FrameDataSource {
	mutable TTree* tree;	// or TChain
	WCPSst::RootEvent event;

      public:
	ToyuBooNEFrameDataSource(TTree& tree, const WCP::GeomDataSource& gds,int bins_per_frame1 = 9600);
	virtual ~ToyuBooNEFrameDataSource();

	void Save();

	/// Return the number of frames this data source knows about.  Return -1 if unlimited.
	virtual int size() const;

	/// Explicitly set the "frame" (event) to process.  Frame number returned or -1 on error.
	virtual int jump(int frame_number);

    private:
	const WCP::GeomDataSource& gds;
	int nwire_u, nwire_v, nwire_w;

	TH1F **hu;
	TH1F **hv;
	TH1F **hw;	
    };

}

#endif
#ifndef WIRECELLSST_TOYUBOONESLICEDATASOURCE_H
#define WIRECELLSST_TOYUBOONESLICEDATASOURCE_H

#include "WCPNav/FrameDataSource.h"
#include "WCPNav/GeomDataSource.h"
#include "WCPNav/DetectorGDS.h"
#include "WCPData/Slice.h"
#include "WCPData/Frame.h"
#include "WCPData/GeomWire.h"

namespace WCPSst {

    /**
       SliceDataSource - deliver slices of frames from a FrameDataSource
     */
    class ToyuBooNESliceDataSource {
    public:

      ToyuBooNESliceDataSource(WCP::FrameDataSource& fds, float th);
      ToyuBooNESliceDataSource(WCP::FrameDataSource& fds, WCP::FrameDataSource& fds1, float th_u, float th_v, float th_w,  float th_ug, float th_vg, float th_wg, int nwire_u, int nwire_v, int nwire_w, std::vector<float>* uplane_rms = 0, std::vector<float>* vplane_rms = 0, std::vector<float>* wplane_rms = 0);
      ToyuBooNESliceDataSource(const WCP::DetectorGDS& gds,WCP::FrameDataSource& fds, WCP::FrameDataSource& fds1, float th_u, float th_v, float th_w,  float th_ug, float th_vg, float th_wg, int nwire_u, int nwire_v, int nwire_w, std::vector<float>* uplane_rms = 0, std::vector<float>* vplane_rms = 0, std::vector<float>* wplane_rms = 0);
      

      virtual ~ToyuBooNESliceDataSource();
      
      /// Return the number of slices in the current frame.  
      virtual int size() const;
      void set_flag(int flag1);
      /// Go to the given slice, return slice number or -1 on error
      virtual int jump(int slice_number); 
      
      /// Go to the next slice, return its number or -1 on error
      virtual int next();
      
      /// Get the current slice
      virtual WCP::Slice&  get();
      virtual const WCP::Slice&  get() const;
      
    private:
      
      WCP::FrameDataSource& _fds;
      WCP::FrameDataSource& _fds1;
      const WCP::DetectorGDS* gds;
      int gds_flag;

      int nwire_u, nwire_v, nwire_w;
      
      WCP::Slice _slice;	// cache the current slice
      int _frame_index;	// last frame we loaded
      int _slice_index;	// current slice, for caching
      mutable int _slices_begin; // tbin index of earliest bin of all traces
      mutable int _slices_end; // tbin index of one past the latest bin of all traces
      int flag;
      float threshold;
      
      float threshold_u;
      float threshold_v;
      float threshold_w;

      float threshold_ug;
      float threshold_vg;
      float threshold_wg;

      std::vector<float>* uplane_rms;
      std::vector<float>* vplane_rms;
      std::vector<float>* wplane_rms;
      
      
      virtual void update_slices_bounds() const;
      virtual void clear();
      
    };
    
}

#endif
#ifndef WIRECELLSST_UTIL
#define WIRECELLSST_UTIL

#include "WCPSst/FrameDataSource.h"

#include "TFile.h"

namespace WCPSst {

    /** Make and return a frame data source attached to the given filename.
     *
     * This will attempt to check for file schema versions.
     */
    WCPSst::FrameDataSource* make_fds(TFile& tfile, const char* tpath = "/Event/Sim");
    WCPSst::FrameDataSource* make_fds(const char* filename, const char* tpath = "/Event/Sim");


}

#endif

#ifndef WIRECELLSST_UBOONESLICEDATASOURCE_H
#define WIRECELLSST_UBOONESLICEDATASOURCE_H

#include "WCPNav/FrameDataSource.h"
#include "WCPNav/GeomDataSource.h"
#include "WCPNav/DetectorGDS.h"
#include "WCPData/Slice.h"
#include "WCPData/Frame.h"
#include "WCPData/GeomWire.h"

namespace WCPSst {

    /**
       SliceDataSource - deliver slices of frames from a FrameDataSource
     */
    class uBooNESliceDataSource {
    public:

      uBooNESliceDataSource(WCP::FrameDataSource& fds, WCP::FrameDataSource& fds1, WCP::FrameDataSource& fds1_error, float th_u, float th_v, float th_w, int nwire_u, int nwire_v, int nwire_w, std::vector<float>* uplane_rms = 0, std::vector<float>* vplane_rms = 0, std::vector<float>* wplane_rms = 0);
      
      virtual ~uBooNESliceDataSource();
      
      /// Return the number of slices in the current frame.  
      virtual int size() const;
      /// Go to the given slice, return slice number or -1 on error
      virtual int jump(int slice_number); 
      
      /// Go to the next slice, return its number or -1 on error
      virtual int next();
      
      /// Get the current slice
      virtual WCP::Slice&  get();
      virtual const WCP::Slice&  get() const;

      virtual WCP::Slice& get_error();
      virtual const WCP::Slice&  get_error() const;
      
    private:
      
      WCP::FrameDataSource& _fds;
      WCP::FrameDataSource& _fds1;
      WCP::FrameDataSource& _fds2;
      
     
      int nwire_u, nwire_v, nwire_w;
      
      WCP::Slice _slice;	// cache the current slice
      WCP::Slice _slice_error;	// cache the current slice
      
      int _frame_index;	// last frame we loaded
      int _slice_index;	// current slice, for caching
      mutable int _slices_begin; // tbin index of earliest bin of all traces
      mutable int _slices_end; // tbin index of one past the latest bin of all traces
      float threshold;
      
      float threshold_u;
      float threshold_v;
      float threshold_w;
      
      std::vector<float>* uplane_rms;
      std::vector<float>* vplane_rms;
      std::vector<float>* wplane_rms;
      
      
      virtual void update_slices_bounds() const;
      virtual void clear();
      
    };
    
}

#endif

#undef  _BACKWARD_BACKWARD_WARNING_H
)DICTPAYLOAD";
    static const char* classesHeaders[] = {
"WCPSst::FrameDataSource", payloadCode, "@",
"WCPSst::GeomDataSource", payloadCode, "@",
"WCPSst::RootEvent", payloadCode, "@",
nullptr
};
    static bool isInitialized = false;
    if (!isInitialized) {
      TROOT::RegisterModule("WCPSstDict",
        headers, includePaths, payloadCode, fwdDeclCode,
        TriggerDictionaryInitialization_WCPSstDict_Impl, {}, classesHeaders, /*hasCxxModule*/false);
      isInitialized = true;
    }
  }
  static struct DictInit {
    DictInit() {
      TriggerDictionaryInitialization_WCPSstDict_Impl();
    }
  } __TheDictionaryInitializer;
}
void TriggerDictionaryInitialization_WCPSstDict() {
  TriggerDictionaryInitialization_WCPSstDict_Impl();
}
