#include "WCPSst/GeomDataSource.h"
#include "WCPSst/DatauBooNEFrameDataSource.h"
#include "WCPSst/ToyuBooNESliceDataSource.h"
#include "WCP2dToy/ToyEventDisplay.h"
#include "WCP2dToy/ToyTiling.h"
#include "WCP2dToy/BadTiling.h"

#include "WCP2dToy/MergeToyTiling.h"
#include "WCP2dToy/TruthToyTiling.h"
#include "WCP2dToy/SimpleBlobToyTiling.h"

#include "WCP2dToy/ToyMatrix.h"
#include "WCP2dToy/ToyMatrixExclusive.h"
#include "WCP2dToy/ToyMatrixKalman.h"
#include "WCP2dToy/ToyMatrixIterate.h"
#include "WCP2dToy/ToyMatrixIterate_SingleWire.h"
#include "WCP2dToy/ToyMatrixIterate_Only.h"

#include "WCP2dToy/ToyMatrixMarkov.h"
#include "WCP2dToy/ToyMetric.h"
#include "WCP2dToy/BlobMetric.h"

#include "WCPData/MergeGeomCell.h"
#include "WCPData/MergeGeomWire.h"

#include "WCPData/GeomCluster.h"
//#include "WCPNav/SliceDataSource.h"

#include "WCPNav/FrameDataSource.h"
#include "WCPNav/SimDataSource.h"
#include "WCPNav/SliceDataSource.h"
#include "WCPSst/Util.h"
#include "WCPData/SimTruth.h"
#include "WCP2dToy/ToyDepositor.h"
#include "WCPNav/GenerativeFDS.h"
#include "WCP2dToy/ToySignalSimu.h"
#include "WCP2dToy/ToySignalSimuTrue.h"
#include "WCP2dToy/DataSignalGaus.h"
#include "WCP2dToy/DataSignalWien.h"

#include "TApplication.h"
#include "TCanvas.h"
#include "TStyle.h"
#include "TH1F.h"
#include "TFile.h"
#include "TGraph2D.h"
#include "TColor.h"
#include "TVectorD.h"
#include "TMatrixD.h"
#include <iostream>

using namespace WCP;
using namespace std;

int main(int argc, char *argv[])
{
    if (argc < 2) {
        cerr << "usage: wire-cell-uboone /path/to/ChannelWireGeometry.txt /path/to/celltree.root eve_num -t[0,1] "
                "-s[0,1,2]"
             << endl;
        return 1;
    }

    int two_plane = 0;
    int save_file = 0;
    int nt_off1 = 0;
    int nt_off2 = 0;
    for (Int_t i = 1; i != argc; i++) {
        switch (argv[i][1]) {
        case 't':
            two_plane = atoi(&argv[i][2]);
            break;
        case 's':
            save_file = atoi(&argv[i][2]);
            break;
        case 'a':
            nt_off1 = atoi(&argv[i][2]);
            break;
        case 'b':
            nt_off2 = atoi(&argv[i][2]);
            break;
        }
    }

    if (two_plane) cout << "Enable Two Plane Reconstruction " << endl;

    WCPSst::GeomDataSource gds(argv[1]);
    std::vector<double> ex = gds.extent();
    cerr << "Extent: "
         << " x:" << ex[0] / units::mm << " mm"
         << " y:" << ex[1] / units::m << " m"
         << " z:" << ex[2] / units::m << " m" << endl;

    cout << "Pitch: " << gds.pitch(WirePlaneType_t(0)) << " " << gds.pitch(WirePlaneType_t(1)) << " "
         << gds.pitch(WirePlaneType_t(2)) << endl;
    cout << "Angle: " << gds.angle(WirePlaneType_t(0)) << " " << gds.angle(WirePlaneType_t(1)) << " "
         << gds.angle(WirePlaneType_t(2)) << endl;

    for (Int_t i = 0; i != gds.wires_in_plane(WirePlaneType_t(0)).size(); i++) {
        const GeomWire *wire = gds.wires_in_plane(WirePlaneType_t(0)).at(i);
        std::cout << 0 << " " << i << " "
                  << sqrt(pow(wire->point1().y - wire->point2().y, 2) + pow(wire->point1().z - wire->point2().z, 2)) /
                         units::cm
                  << std::endl;
    }

    for (Int_t i = 0; i != gds.wires_in_plane(WirePlaneType_t(1)).size(); i++) {
        const GeomWire *wire = gds.wires_in_plane(WirePlaneType_t(1)).at(i);
        std::cout << 1 << " " << i << " "
                  << sqrt(pow(wire->point1().y - wire->point2().y, 2) + pow(wire->point1().z - wire->point2().z, 2)) /
                         units::cm
                  << std::endl;
    }

    for (Int_t i = 0; i != gds.wires_in_plane(WirePlaneType_t(2)).size(); i++) {
        const GeomWire *wire = gds.wires_in_plane(WirePlaneType_t(2)).at(i);
        std::cout << 2 << " " << i << " "
                  << sqrt(pow(wire->point1().y - wire->point2().y, 2) + pow(wire->point1().z - wire->point2().z, 2)) /
                         units::cm
                  << std::endl;
    }

    return 0;

}  // main()
