/** TrackingNtupleObjs.hpp created on 2018-05-22 17:07:59.784846 by generate_class.py
 * AVOID EDITING THIS FILE BY HAND!! Instead edit TrackingNtupleObjs.yaml and re-run
 * generate_class.py
 */
#include "filval.hpp"
#include "root_filval.hpp"

#include<cmath>

#include "TrackingNtuple.h"

using namespace std;
using namespace fv;
using namespace fv_root;

typedef TreeDataSet<TrackingNtuple> TrackingDataSet;
struct Seed;

class SeedCollection {
  public:
    class iter {
      public:
        iter(SeedCollection* collection, size_t idx)
          :collection(collection), idx(idx) { }
        iter operator++() { ++idx; return *this; }
        bool operator!=(const iter & other) { return idx != other.idx; }
        Seed operator*();
      private:
        SeedCollection* collection;
        size_t idx;
    };
    TrackingDataSet* tds;

    Value<vector<short>>* val_fitok;
    bool fitok_loaded;
    Value<vector<float>>* val_px;
    bool px_loaded;
    Value<vector<float>>* val_py;
    bool py_loaded;
    Value<vector<float>>* val_pz;
    bool pz_loaded;
    Value<vector<float>>* val_pt;
    bool pt_loaded;
    Value<vector<float>>* val_eta;
    bool eta_loaded;
    Value<vector<float>>* val_phi;
    bool phi_loaded;
    Value<vector<float>>* val_dxy;
    bool dxy_loaded;
    Value<vector<float>>* val_dz;
    bool dz_loaded;
    Value<vector<float>>* val_ptErr;
    bool ptErr_loaded;
    Value<vector<float>>* val_etaErr;
    bool etaErr_loaded;
    Value<vector<float>>* val_phiErr;
    bool phiErr_loaded;
    Value<vector<float>>* val_dxyErr;
    bool dxyErr_loaded;
    Value<vector<float>>* val_dzErr;
    bool dzErr_loaded;
    Value<vector<float>>* val_chi2;
    bool chi2_loaded;
    Value<vector<int>>* val_q;
    bool q_loaded;
    Value<vector<unsigned int>>* val_nValid;
    bool nValid_loaded;
    Value<vector<unsigned int>>* val_nPixel;
    bool nPixel_loaded;
    Value<vector<unsigned int>>* val_nGlued;
    bool nGlued_loaded;
    Value<vector<unsigned int>>* val_nStrip;
    bool nStrip_loaded;
    Value<vector<unsigned int>>* val_algo;
    bool algo_loaded;
    Value<vector<int>>* val_trkIdx;
    bool trkIdx_loaded;
    Value<vector<vector<float>>>* val_shareFrac;
    bool shareFrac_loaded;
    Value<vector<vector<int>>>* val_simTrkIdx;
    bool simTrkIdx_loaded;
    Value<vector<unsigned int>>* val_offset;
    bool offset_loaded;
    Value<vector<float>>* val_Et;
    bool Et_loaded;
    Value<vector<float>>* val_hoe;
    bool hoe_loaded;
    Value<vector<vector<int>>>* val_isBarrel;
    bool isBarrel_loaded;
    Value<vector<vector<int>>>* val_layerOrDiskNr;
    bool layerOrDiskNr_loaded;
    Value<vector<vector<int>>>* val_isValidPos;
    bool isValidPos_loaded;
    Value<vector<vector<float>>>* val_dRZPos;
    bool dRZPos_loaded;
    Value<vector<vector<float>>>* val_dPhiPos;
    bool dPhiPos_loaded;
    Value<vector<vector<int>>>* val_isValidNeg;
    bool isValidNeg_loaded;
    Value<vector<vector<float>>>* val_dRZNeg;
    bool dRZNeg_loaded;
    Value<vector<vector<float>>>* val_dPhiNeg;
    bool dPhiNeg_loaded;
    Value<vector<short>>* val_isECALDriven;
    bool isECALDriven_loaded;
    Value<vector<int>>* val_sclIdx;
    bool sclIdx_loaded;

    SeedCollection() { }

    void init(TrackingDataSet* tds){
        this->tds = tds;
    }

    size_t size() {
        if (!this->fitok_loaded) {
            this->val_fitok = this->tds->track_branch_obj<vector<short>>("see_fitok");
            this->fitok_loaded = true;
        }
        return (*this->val_fitok)().size();
    }


    Seed operator[](size_t);
    iter begin() { return iter(this, 0); }
    iter end() { return iter(this, size()); }
};

struct Seed {
    SeedCollection* collection;
    size_t idx;
    Seed(SeedCollection* collection, const size_t idx)
      :collection(collection), idx(idx) { }

    const short& fitok() const {
        if (!collection->fitok_loaded) {
            collection->val_fitok = collection->tds->track_branch_obj<vector<short>>("see_fitok");
            collection->fitok_loaded = true;
        }
        return (*collection->val_fitok)().at(idx);
    }

    const float& px() const {
        if (!collection->px_loaded) {
            collection->val_px = collection->tds->track_branch_obj<vector<float>>("see_px");
            collection->px_loaded = true;
        }
        return (*collection->val_px)().at(idx);
    }

    const float& py() const {
        if (!collection->py_loaded) {
            collection->val_py = collection->tds->track_branch_obj<vector<float>>("see_py");
            collection->py_loaded = true;
        }
        return (*collection->val_py)().at(idx);
    }

    const float& pz() const {
        if (!collection->pz_loaded) {
            collection->val_pz = collection->tds->track_branch_obj<vector<float>>("see_pz");
            collection->pz_loaded = true;
        }
        return (*collection->val_pz)().at(idx);
    }

    const float& pt() const {
        if (!collection->pt_loaded) {
            collection->val_pt = collection->tds->track_branch_obj<vector<float>>("see_pt");
            collection->pt_loaded = true;
        }
        return (*collection->val_pt)().at(idx);
    }

    const float& eta() const {
        if (!collection->eta_loaded) {
            collection->val_eta = collection->tds->track_branch_obj<vector<float>>("see_eta");
            collection->eta_loaded = true;
        }
        return (*collection->val_eta)().at(idx);
    }

    const float& phi() const {
        if (!collection->phi_loaded) {
            collection->val_phi = collection->tds->track_branch_obj<vector<float>>("see_phi");
            collection->phi_loaded = true;
        }
        return (*collection->val_phi)().at(idx);
    }

    const float& dxy() const {
        if (!collection->dxy_loaded) {
            collection->val_dxy = collection->tds->track_branch_obj<vector<float>>("see_dxy");
            collection->dxy_loaded = true;
        }
        return (*collection->val_dxy)().at(idx);
    }

    const float& dz() const {
        if (!collection->dz_loaded) {
            collection->val_dz = collection->tds->track_branch_obj<vector<float>>("see_dz");
            collection->dz_loaded = true;
        }
        return (*collection->val_dz)().at(idx);
    }

    const float& ptErr() const {
        if (!collection->ptErr_loaded) {
            collection->val_ptErr = collection->tds->track_branch_obj<vector<float>>("see_ptErr");
            collection->ptErr_loaded = true;
        }
        return (*collection->val_ptErr)().at(idx);
    }

    const float& etaErr() const {
        if (!collection->etaErr_loaded) {
            collection->val_etaErr = collection->tds->track_branch_obj<vector<float>>("see_etaErr");
            collection->etaErr_loaded = true;
        }
        return (*collection->val_etaErr)().at(idx);
    }

    const float& phiErr() const {
        if (!collection->phiErr_loaded) {
            collection->val_phiErr = collection->tds->track_branch_obj<vector<float>>("see_phiErr");
            collection->phiErr_loaded = true;
        }
        return (*collection->val_phiErr)().at(idx);
    }

    const float& dxyErr() const {
        if (!collection->dxyErr_loaded) {
            collection->val_dxyErr = collection->tds->track_branch_obj<vector<float>>("see_dxyErr");
            collection->dxyErr_loaded = true;
        }
        return (*collection->val_dxyErr)().at(idx);
    }

    const float& dzErr() const {
        if (!collection->dzErr_loaded) {
            collection->val_dzErr = collection->tds->track_branch_obj<vector<float>>("see_dzErr");
            collection->dzErr_loaded = true;
        }
        return (*collection->val_dzErr)().at(idx);
    }

    const float& chi2() const {
        if (!collection->chi2_loaded) {
            collection->val_chi2 = collection->tds->track_branch_obj<vector<float>>("see_chi2");
            collection->chi2_loaded = true;
        }
        return (*collection->val_chi2)().at(idx);
    }

    const int& q() const {
        if (!collection->q_loaded) {
            collection->val_q = collection->tds->track_branch_obj<vector<int>>("see_q");
            collection->q_loaded = true;
        }
        return (*collection->val_q)().at(idx);
    }

    const unsigned int& nValid() const {
        if (!collection->nValid_loaded) {
            collection->val_nValid = collection->tds->track_branch_obj<vector<unsigned int>>("see_nValid");
            collection->nValid_loaded = true;
        }
        return (*collection->val_nValid)().at(idx);
    }

    const unsigned int& nPixel() const {
        if (!collection->nPixel_loaded) {
            collection->val_nPixel = collection->tds->track_branch_obj<vector<unsigned int>>("see_nPixel");
            collection->nPixel_loaded = true;
        }
        return (*collection->val_nPixel)().at(idx);
    }

    const unsigned int& nGlued() const {
        if (!collection->nGlued_loaded) {
            collection->val_nGlued = collection->tds->track_branch_obj<vector<unsigned int>>("see_nGlued");
            collection->nGlued_loaded = true;
        }
        return (*collection->val_nGlued)().at(idx);
    }

    const unsigned int& nStrip() const {
        if (!collection->nStrip_loaded) {
            collection->val_nStrip = collection->tds->track_branch_obj<vector<unsigned int>>("see_nStrip");
            collection->nStrip_loaded = true;
        }
        return (*collection->val_nStrip)().at(idx);
    }

    const unsigned int& algo() const {
        if (!collection->algo_loaded) {
            collection->val_algo = collection->tds->track_branch_obj<vector<unsigned int>>("see_algo");
            collection->algo_loaded = true;
        }
        return (*collection->val_algo)().at(idx);
    }

    const int& trkIdx() const {
        if (!collection->trkIdx_loaded) {
            collection->val_trkIdx = collection->tds->track_branch_obj<vector<int>>("see_trkIdx");
            collection->trkIdx_loaded = true;
        }
        return (*collection->val_trkIdx)().at(idx);
    }

    const vector<float>& shareFrac() const {
        if (!collection->shareFrac_loaded) {
            collection->val_shareFrac = collection->tds->track_branch_obj<vector<vector<float>>>("see_shareFrac");
            collection->shareFrac_loaded = true;
        }
        return (*collection->val_shareFrac)().at(idx);
    }

    const vector<int>& simTrkIdx() const {
        if (!collection->simTrkIdx_loaded) {
            collection->val_simTrkIdx = collection->tds->track_branch_obj<vector<vector<int>>>("see_simTrkIdx");
            collection->simTrkIdx_loaded = true;
        }
        return (*collection->val_simTrkIdx)().at(idx);
    }

    const unsigned int& offset() const {
        if (!collection->offset_loaded) {
            collection->val_offset = collection->tds->track_branch_obj<vector<unsigned int>>("see_offset");
            collection->offset_loaded = true;
        }
        return (*collection->val_offset)().at(idx);
    }

    const float& Et() const {
        if (!collection->Et_loaded) {
            collection->val_Et = collection->tds->track_branch_obj<vector<float>>("see_Et");
            collection->Et_loaded = true;
        }
        return (*collection->val_Et)().at(idx);
    }

    const float& hoe() const {
        if (!collection->hoe_loaded) {
            collection->val_hoe = collection->tds->track_branch_obj<vector<float>>("see_hoe");
            collection->hoe_loaded = true;
        }
        return (*collection->val_hoe)().at(idx);
    }

    const vector<int>& isBarrel() const {
        if (!collection->isBarrel_loaded) {
            collection->val_isBarrel = collection->tds->track_branch_obj<vector<vector<int>>>("see_isBarrel");
            collection->isBarrel_loaded = true;
        }
        return (*collection->val_isBarrel)().at(idx);
    }

    const vector<int>& layerOrDiskNr() const {
        if (!collection->layerOrDiskNr_loaded) {
            collection->val_layerOrDiskNr = collection->tds->track_branch_obj<vector<vector<int>>>("see_layerOrDiskNr");
            collection->layerOrDiskNr_loaded = true;
        }
        return (*collection->val_layerOrDiskNr)().at(idx);
    }

    const vector<int>& isValidPos() const {
        if (!collection->isValidPos_loaded) {
            collection->val_isValidPos = collection->tds->track_branch_obj<vector<vector<int>>>("see_isValidPos");
            collection->isValidPos_loaded = true;
        }
        return (*collection->val_isValidPos)().at(idx);
    }

    const vector<float>& dRZPos() const {
        if (!collection->dRZPos_loaded) {
            collection->val_dRZPos = collection->tds->track_branch_obj<vector<vector<float>>>("see_dRZPos");
            collection->dRZPos_loaded = true;
        }
        return (*collection->val_dRZPos)().at(idx);
    }

    const vector<float>& dPhiPos() const {
        if (!collection->dPhiPos_loaded) {
            collection->val_dPhiPos = collection->tds->track_branch_obj<vector<vector<float>>>("see_dPhiPos");
            collection->dPhiPos_loaded = true;
        }
        return (*collection->val_dPhiPos)().at(idx);
    }

    const vector<int>& isValidNeg() const {
        if (!collection->isValidNeg_loaded) {
            collection->val_isValidNeg = collection->tds->track_branch_obj<vector<vector<int>>>("see_isValidNeg");
            collection->isValidNeg_loaded = true;
        }
        return (*collection->val_isValidNeg)().at(idx);
    }

    const vector<float>& dRZNeg() const {
        if (!collection->dRZNeg_loaded) {
            collection->val_dRZNeg = collection->tds->track_branch_obj<vector<vector<float>>>("see_dRZNeg");
            collection->dRZNeg_loaded = true;
        }
        return (*collection->val_dRZNeg)().at(idx);
    }

    const vector<float>& dPhiNeg() const {
        if (!collection->dPhiNeg_loaded) {
            collection->val_dPhiNeg = collection->tds->track_branch_obj<vector<vector<float>>>("see_dPhiNeg");
            collection->dPhiNeg_loaded = true;
        }
        return (*collection->val_dPhiNeg)().at(idx);
    }

    const short& isECALDriven() const {
        if (!collection->isECALDriven_loaded) {
            collection->val_isECALDriven = collection->tds->track_branch_obj<vector<short>>("see_isECALDriven");
            collection->isECALDriven_loaded = true;
        }
        return (*collection->val_isECALDriven)().at(idx);
    }

    const int& sclIdx() const {
        if (!collection->sclIdx_loaded) {
            collection->val_sclIdx = collection->tds->track_branch_obj<vector<int>>("see_sclIdx");
            collection->sclIdx_loaded = true;
        }
        return (*collection->val_sclIdx)().at(idx);
    }

};

Seed SeedCollection::iter::operator*() {
    return {collection, idx};
}
Seed SeedCollection::operator[](size_t idx) {
    return {this, idx};
}
struct Track;

class TrackCollection {
  public:
    class iter {
      public:
        iter(TrackCollection* collection, size_t idx)
          :collection(collection), idx(idx) { }
        iter operator++() { ++idx; return *this; }
        bool operator!=(const iter & other) { return idx != other.idx; }
        Track operator*();
      private:
        TrackCollection* collection;
        size_t idx;
    };
    TrackingDataSet* tds;

    Value<vector<float>>* val_px;
    bool px_loaded;
    Value<vector<float>>* val_py;
    bool py_loaded;
    Value<vector<float>>* val_pz;
    bool pz_loaded;
    Value<vector<float>>* val_pt;
    bool pt_loaded;
    Value<vector<float>>* val_inner_px;
    bool inner_px_loaded;
    Value<vector<float>>* val_inner_py;
    bool inner_py_loaded;
    Value<vector<float>>* val_inner_pz;
    bool inner_pz_loaded;
    Value<vector<float>>* val_inner_pt;
    bool inner_pt_loaded;
    Value<vector<float>>* val_outer_px;
    bool outer_px_loaded;
    Value<vector<float>>* val_outer_py;
    bool outer_py_loaded;
    Value<vector<float>>* val_outer_pz;
    bool outer_pz_loaded;
    Value<vector<float>>* val_outer_pt;
    bool outer_pt_loaded;
    Value<vector<float>>* val_eta;
    bool eta_loaded;
    Value<vector<float>>* val_lambda;
    bool lambda_loaded;
    Value<vector<float>>* val_cotTheta;
    bool cotTheta_loaded;
    Value<vector<float>>* val_phi;
    bool phi_loaded;
    Value<vector<float>>* val_dxy;
    bool dxy_loaded;
    Value<vector<float>>* val_dz;
    bool dz_loaded;
    Value<vector<float>>* val_ptErr;
    bool ptErr_loaded;
    Value<vector<float>>* val_etaErr;
    bool etaErr_loaded;
    Value<vector<float>>* val_lambdaErr;
    bool lambdaErr_loaded;
    Value<vector<float>>* val_phiErr;
    bool phiErr_loaded;
    Value<vector<float>>* val_dxyErr;
    bool dxyErr_loaded;
    Value<vector<float>>* val_dzErr;
    bool dzErr_loaded;
    Value<vector<float>>* val_refpoint_x;
    bool refpoint_x_loaded;
    Value<vector<float>>* val_refpoint_y;
    bool refpoint_y_loaded;
    Value<vector<float>>* val_refpoint_z;
    bool refpoint_z_loaded;
    Value<vector<float>>* val_nChi2;
    bool nChi2_loaded;
    Value<vector<int>>* val_q;
    bool q_loaded;
    Value<vector<unsigned int>>* val_nValid;
    bool nValid_loaded;
    Value<vector<unsigned int>>* val_nInvalid;
    bool nInvalid_loaded;
    Value<vector<unsigned int>>* val_nPixel;
    bool nPixel_loaded;
    Value<vector<unsigned int>>* val_nStrip;
    bool nStrip_loaded;
    Value<vector<unsigned int>>* val_nPixelLay;
    bool nPixelLay_loaded;
    Value<vector<unsigned int>>* val_nStripLay;
    bool nStripLay_loaded;
    Value<vector<unsigned int>>* val_n3DLay;
    bool n3DLay_loaded;
    Value<vector<unsigned int>>* val_nOuterLost;
    bool nOuterLost_loaded;
    Value<vector<unsigned int>>* val_nInnerLost;
    bool nInnerLost_loaded;
    Value<vector<unsigned int>>* val_algo;
    bool algo_loaded;
    Value<vector<unsigned int>>* val_originalAlgo;
    bool originalAlgo_loaded;
    Value<vector<ULong64_t>>* val_algoMask;
    bool algoMask_loaded;
    Value<vector<unsigned int>>* val_stopReason;
    bool stopReason_loaded;
    Value<vector<short>>* val_isHP;
    bool isHP_loaded;
    Value<vector<int>>* val_seedIdx;
    bool seedIdx_loaded;
    Value<vector<float>>* val_vtxx;
    bool vtxx_loaded;
    Value<vector<float>>* val_vtxy;
    bool vtxy_loaded;
    Value<vector<float>>* val_vtxz;
    bool vtxz_loaded;
    Value<vector<vector<float>>>* val_shareFrac;
    bool shareFrac_loaded;
    Value<vector<vector<int>>>* val_simTrkIdx;
    bool simTrkIdx_loaded;
    Value<vector<int>>* val_genIdx;
    bool genIdx_loaded;
    Value<vector<float>>* val_genDR;
    bool genDR_loaded;

    TrackCollection() { }

    void init(TrackingDataSet* tds){
        this->tds = tds;
    }

    size_t size() {
        if (!this->px_loaded) {
            this->val_px = this->tds->track_branch_obj<vector<float>>("trk_px");
            this->px_loaded = true;
        }
        return (*this->val_px)().size();
    }


    Track operator[](size_t);
    iter begin() { return iter(this, 0); }
    iter end() { return iter(this, size()); }
};

struct Track {
    TrackCollection* collection;
    size_t idx;
    Track(TrackCollection* collection, const size_t idx)
      :collection(collection), idx(idx) { }

    const float& px() const {
        if (!collection->px_loaded) {
            collection->val_px = collection->tds->track_branch_obj<vector<float>>("trk_px");
            collection->px_loaded = true;
        }
        return (*collection->val_px)().at(idx);
    }

    const float& py() const {
        if (!collection->py_loaded) {
            collection->val_py = collection->tds->track_branch_obj<vector<float>>("trk_py");
            collection->py_loaded = true;
        }
        return (*collection->val_py)().at(idx);
    }

    const float& pz() const {
        if (!collection->pz_loaded) {
            collection->val_pz = collection->tds->track_branch_obj<vector<float>>("trk_pz");
            collection->pz_loaded = true;
        }
        return (*collection->val_pz)().at(idx);
    }

    const float& pt() const {
        if (!collection->pt_loaded) {
            collection->val_pt = collection->tds->track_branch_obj<vector<float>>("trk_pt");
            collection->pt_loaded = true;
        }
        return (*collection->val_pt)().at(idx);
    }

    const float& inner_px() const {
        if (!collection->inner_px_loaded) {
            collection->val_inner_px = collection->tds->track_branch_obj<vector<float>>("trk_inner_px");
            collection->inner_px_loaded = true;
        }
        return (*collection->val_inner_px)().at(idx);
    }

    const float& inner_py() const {
        if (!collection->inner_py_loaded) {
            collection->val_inner_py = collection->tds->track_branch_obj<vector<float>>("trk_inner_py");
            collection->inner_py_loaded = true;
        }
        return (*collection->val_inner_py)().at(idx);
    }

    const float& inner_pz() const {
        if (!collection->inner_pz_loaded) {
            collection->val_inner_pz = collection->tds->track_branch_obj<vector<float>>("trk_inner_pz");
            collection->inner_pz_loaded = true;
        }
        return (*collection->val_inner_pz)().at(idx);
    }

    const float& inner_pt() const {
        if (!collection->inner_pt_loaded) {
            collection->val_inner_pt = collection->tds->track_branch_obj<vector<float>>("trk_inner_pt");
            collection->inner_pt_loaded = true;
        }
        return (*collection->val_inner_pt)().at(idx);
    }

    const float& outer_px() const {
        if (!collection->outer_px_loaded) {
            collection->val_outer_px = collection->tds->track_branch_obj<vector<float>>("trk_outer_px");
            collection->outer_px_loaded = true;
        }
        return (*collection->val_outer_px)().at(idx);
    }

    const float& outer_py() const {
        if (!collection->outer_py_loaded) {
            collection->val_outer_py = collection->tds->track_branch_obj<vector<float>>("trk_outer_py");
            collection->outer_py_loaded = true;
        }
        return (*collection->val_outer_py)().at(idx);
    }

    const float& outer_pz() const {
        if (!collection->outer_pz_loaded) {
            collection->val_outer_pz = collection->tds->track_branch_obj<vector<float>>("trk_outer_pz");
            collection->outer_pz_loaded = true;
        }
        return (*collection->val_outer_pz)().at(idx);
    }

    const float& outer_pt() const {
        if (!collection->outer_pt_loaded) {
            collection->val_outer_pt = collection->tds->track_branch_obj<vector<float>>("trk_outer_pt");
            collection->outer_pt_loaded = true;
        }
        return (*collection->val_outer_pt)().at(idx);
    }

    const float& eta() const {
        if (!collection->eta_loaded) {
            collection->val_eta = collection->tds->track_branch_obj<vector<float>>("trk_eta");
            collection->eta_loaded = true;
        }
        return (*collection->val_eta)().at(idx);
    }

    const float& lambda() const {
        if (!collection->lambda_loaded) {
            collection->val_lambda = collection->tds->track_branch_obj<vector<float>>("trk_lambda");
            collection->lambda_loaded = true;
        }
        return (*collection->val_lambda)().at(idx);
    }

    const float& cotTheta() const {
        if (!collection->cotTheta_loaded) {
            collection->val_cotTheta = collection->tds->track_branch_obj<vector<float>>("trk_cotTheta");
            collection->cotTheta_loaded = true;
        }
        return (*collection->val_cotTheta)().at(idx);
    }

    const float& phi() const {
        if (!collection->phi_loaded) {
            collection->val_phi = collection->tds->track_branch_obj<vector<float>>("trk_phi");
            collection->phi_loaded = true;
        }
        return (*collection->val_phi)().at(idx);
    }

    const float& dxy() const {
        if (!collection->dxy_loaded) {
            collection->val_dxy = collection->tds->track_branch_obj<vector<float>>("trk_dxy");
            collection->dxy_loaded = true;
        }
        return (*collection->val_dxy)().at(idx);
    }

    const float& dz() const {
        if (!collection->dz_loaded) {
            collection->val_dz = collection->tds->track_branch_obj<vector<float>>("trk_dz");
            collection->dz_loaded = true;
        }
        return (*collection->val_dz)().at(idx);
    }

    const float& ptErr() const {
        if (!collection->ptErr_loaded) {
            collection->val_ptErr = collection->tds->track_branch_obj<vector<float>>("trk_ptErr");
            collection->ptErr_loaded = true;
        }
        return (*collection->val_ptErr)().at(idx);
    }

    const float& etaErr() const {
        if (!collection->etaErr_loaded) {
            collection->val_etaErr = collection->tds->track_branch_obj<vector<float>>("trk_etaErr");
            collection->etaErr_loaded = true;
        }
        return (*collection->val_etaErr)().at(idx);
    }

    const float& lambdaErr() const {
        if (!collection->lambdaErr_loaded) {
            collection->val_lambdaErr = collection->tds->track_branch_obj<vector<float>>("trk_lambdaErr");
            collection->lambdaErr_loaded = true;
        }
        return (*collection->val_lambdaErr)().at(idx);
    }

    const float& phiErr() const {
        if (!collection->phiErr_loaded) {
            collection->val_phiErr = collection->tds->track_branch_obj<vector<float>>("trk_phiErr");
            collection->phiErr_loaded = true;
        }
        return (*collection->val_phiErr)().at(idx);
    }

    const float& dxyErr() const {
        if (!collection->dxyErr_loaded) {
            collection->val_dxyErr = collection->tds->track_branch_obj<vector<float>>("trk_dxyErr");
            collection->dxyErr_loaded = true;
        }
        return (*collection->val_dxyErr)().at(idx);
    }

    const float& dzErr() const {
        if (!collection->dzErr_loaded) {
            collection->val_dzErr = collection->tds->track_branch_obj<vector<float>>("trk_dzErr");
            collection->dzErr_loaded = true;
        }
        return (*collection->val_dzErr)().at(idx);
    }

    const float& refpoint_x() const {
        if (!collection->refpoint_x_loaded) {
            collection->val_refpoint_x = collection->tds->track_branch_obj<vector<float>>("trk_refpoint_x");
            collection->refpoint_x_loaded = true;
        }
        return (*collection->val_refpoint_x)().at(idx);
    }

    const float& refpoint_y() const {
        if (!collection->refpoint_y_loaded) {
            collection->val_refpoint_y = collection->tds->track_branch_obj<vector<float>>("trk_refpoint_y");
            collection->refpoint_y_loaded = true;
        }
        return (*collection->val_refpoint_y)().at(idx);
    }

    const float& refpoint_z() const {
        if (!collection->refpoint_z_loaded) {
            collection->val_refpoint_z = collection->tds->track_branch_obj<vector<float>>("trk_refpoint_z");
            collection->refpoint_z_loaded = true;
        }
        return (*collection->val_refpoint_z)().at(idx);
    }

    const float& nChi2() const {
        if (!collection->nChi2_loaded) {
            collection->val_nChi2 = collection->tds->track_branch_obj<vector<float>>("trk_nChi2");
            collection->nChi2_loaded = true;
        }
        return (*collection->val_nChi2)().at(idx);
    }

    const int& q() const {
        if (!collection->q_loaded) {
            collection->val_q = collection->tds->track_branch_obj<vector<int>>("trk_q");
            collection->q_loaded = true;
        }
        return (*collection->val_q)().at(idx);
    }

    const unsigned int& nValid() const {
        if (!collection->nValid_loaded) {
            collection->val_nValid = collection->tds->track_branch_obj<vector<unsigned int>>("trk_nValid");
            collection->nValid_loaded = true;
        }
        return (*collection->val_nValid)().at(idx);
    }

    const unsigned int& nInvalid() const {
        if (!collection->nInvalid_loaded) {
            collection->val_nInvalid = collection->tds->track_branch_obj<vector<unsigned int>>("trk_nInvalid");
            collection->nInvalid_loaded = true;
        }
        return (*collection->val_nInvalid)().at(idx);
    }

    const unsigned int& nPixel() const {
        if (!collection->nPixel_loaded) {
            collection->val_nPixel = collection->tds->track_branch_obj<vector<unsigned int>>("trk_nPixel");
            collection->nPixel_loaded = true;
        }
        return (*collection->val_nPixel)().at(idx);
    }

    const unsigned int& nStrip() const {
        if (!collection->nStrip_loaded) {
            collection->val_nStrip = collection->tds->track_branch_obj<vector<unsigned int>>("trk_nStrip");
            collection->nStrip_loaded = true;
        }
        return (*collection->val_nStrip)().at(idx);
    }

    const unsigned int& nPixelLay() const {
        if (!collection->nPixelLay_loaded) {
            collection->val_nPixelLay = collection->tds->track_branch_obj<vector<unsigned int>>("trk_nPixelLay");
            collection->nPixelLay_loaded = true;
        }
        return (*collection->val_nPixelLay)().at(idx);
    }

    const unsigned int& nStripLay() const {
        if (!collection->nStripLay_loaded) {
            collection->val_nStripLay = collection->tds->track_branch_obj<vector<unsigned int>>("trk_nStripLay");
            collection->nStripLay_loaded = true;
        }
        return (*collection->val_nStripLay)().at(idx);
    }

    const unsigned int& n3DLay() const {
        if (!collection->n3DLay_loaded) {
            collection->val_n3DLay = collection->tds->track_branch_obj<vector<unsigned int>>("trk_n3DLay");
            collection->n3DLay_loaded = true;
        }
        return (*collection->val_n3DLay)().at(idx);
    }

    const unsigned int& nOuterLost() const {
        if (!collection->nOuterLost_loaded) {
            collection->val_nOuterLost = collection->tds->track_branch_obj<vector<unsigned int>>("trk_nOuterLost");
            collection->nOuterLost_loaded = true;
        }
        return (*collection->val_nOuterLost)().at(idx);
    }

    const unsigned int& nInnerLost() const {
        if (!collection->nInnerLost_loaded) {
            collection->val_nInnerLost = collection->tds->track_branch_obj<vector<unsigned int>>("trk_nInnerLost");
            collection->nInnerLost_loaded = true;
        }
        return (*collection->val_nInnerLost)().at(idx);
    }

    const unsigned int& algo() const {
        if (!collection->algo_loaded) {
            collection->val_algo = collection->tds->track_branch_obj<vector<unsigned int>>("trk_algo");
            collection->algo_loaded = true;
        }
        return (*collection->val_algo)().at(idx);
    }

    const unsigned int& originalAlgo() const {
        if (!collection->originalAlgo_loaded) {
            collection->val_originalAlgo = collection->tds->track_branch_obj<vector<unsigned int>>("trk_originalAlgo");
            collection->originalAlgo_loaded = true;
        }
        return (*collection->val_originalAlgo)().at(idx);
    }

    const ULong64_t& algoMask() const {
        if (!collection->algoMask_loaded) {
            collection->val_algoMask = collection->tds->track_branch_obj<vector<ULong64_t>>("trk_algoMask");
            collection->algoMask_loaded = true;
        }
        return (*collection->val_algoMask)().at(idx);
    }

    const unsigned int& stopReason() const {
        if (!collection->stopReason_loaded) {
            collection->val_stopReason = collection->tds->track_branch_obj<vector<unsigned int>>("trk_stopReason");
            collection->stopReason_loaded = true;
        }
        return (*collection->val_stopReason)().at(idx);
    }

    const short& isHP() const {
        if (!collection->isHP_loaded) {
            collection->val_isHP = collection->tds->track_branch_obj<vector<short>>("trk_isHP");
            collection->isHP_loaded = true;
        }
        return (*collection->val_isHP)().at(idx);
    }

    const int& seedIdx() const {
        if (!collection->seedIdx_loaded) {
            collection->val_seedIdx = collection->tds->track_branch_obj<vector<int>>("trk_seedIdx");
            collection->seedIdx_loaded = true;
        }
        return (*collection->val_seedIdx)().at(idx);
    }

    const float& vtxx() const {
        if (!collection->vtxx_loaded) {
            collection->val_vtxx = collection->tds->track_branch_obj<vector<float>>("trk_vtxx");
            collection->vtxx_loaded = true;
        }
        return (*collection->val_vtxx)().at(idx);
    }

    const float& vtxy() const {
        if (!collection->vtxy_loaded) {
            collection->val_vtxy = collection->tds->track_branch_obj<vector<float>>("trk_vtxy");
            collection->vtxy_loaded = true;
        }
        return (*collection->val_vtxy)().at(idx);
    }

    const float& vtxz() const {
        if (!collection->vtxz_loaded) {
            collection->val_vtxz = collection->tds->track_branch_obj<vector<float>>("trk_vtxz");
            collection->vtxz_loaded = true;
        }
        return (*collection->val_vtxz)().at(idx);
    }

    const vector<float>& shareFrac() const {
        if (!collection->shareFrac_loaded) {
            collection->val_shareFrac = collection->tds->track_branch_obj<vector<vector<float>>>("trk_shareFrac");
            collection->shareFrac_loaded = true;
        }
        return (*collection->val_shareFrac)().at(idx);
    }

    const vector<int>& simTrkIdx() const {
        if (!collection->simTrkIdx_loaded) {
            collection->val_simTrkIdx = collection->tds->track_branch_obj<vector<vector<int>>>("trk_simTrkIdx");
            collection->simTrkIdx_loaded = true;
        }
        return (*collection->val_simTrkIdx)().at(idx);
    }

    const int& genIdx() const {
        if (!collection->genIdx_loaded) {
            collection->val_genIdx = collection->tds->track_branch_obj<vector<int>>("trk_genIdx");
            collection->genIdx_loaded = true;
        }
        return (*collection->val_genIdx)().at(idx);
    }

    const float& genDR() const {
        if (!collection->genDR_loaded) {
            collection->val_genDR = collection->tds->track_branch_obj<vector<float>>("trk_genDR");
            collection->genDR_loaded = true;
        }
        return (*collection->val_genDR)().at(idx);
    }

};

Track TrackCollection::iter::operator*() {
    return {collection, idx};
}
Track TrackCollection::operator[](size_t idx) {
    return {this, idx};
}
struct SimTrack;

class SimTrackCollection {
  public:
    class iter {
      public:
        iter(SimTrackCollection* collection, size_t idx)
          :collection(collection), idx(idx) { }
        iter operator++() { ++idx; return *this; }
        bool operator!=(const iter & other) { return idx != other.idx; }
        SimTrack operator*();
      private:
        SimTrackCollection* collection;
        size_t idx;
    };
    TrackingDataSet* tds;

    Value<vector<int>>* val_event;
    bool event_loaded;
    Value<vector<int>>* val_bunchCrossing;
    bool bunchCrossing_loaded;
    Value<vector<int>>* val_pdgId;
    bool pdgId_loaded;
    Value<vector<float>>* val_px;
    bool px_loaded;
    Value<vector<float>>* val_py;
    bool py_loaded;
    Value<vector<float>>* val_pz;
    bool pz_loaded;
    Value<vector<float>>* val_pt;
    bool pt_loaded;
    Value<vector<float>>* val_eta;
    bool eta_loaded;
    Value<vector<float>>* val_phi;
    bool phi_loaded;
    Value<vector<float>>* val_pca_pt;
    bool pca_pt_loaded;
    Value<vector<float>>* val_pca_eta;
    bool pca_eta_loaded;
    Value<vector<float>>* val_pca_lambda;
    bool pca_lambda_loaded;
    Value<vector<float>>* val_pca_cotTheta;
    bool pca_cotTheta_loaded;
    Value<vector<float>>* val_pca_phi;
    bool pca_phi_loaded;
    Value<vector<float>>* val_pca_dxy;
    bool pca_dxy_loaded;
    Value<vector<float>>* val_pca_dz;
    bool pca_dz_loaded;
    Value<vector<int>>* val_q;
    bool q_loaded;
    Value<vector<unsigned int>>* val_nValid;
    bool nValid_loaded;
    Value<vector<unsigned int>>* val_nPixel;
    bool nPixel_loaded;
    Value<vector<unsigned int>>* val_nStrip;
    bool nStrip_loaded;
    Value<vector<unsigned int>>* val_nLay;
    bool nLay_loaded;
    Value<vector<unsigned int>>* val_nPixelLay;
    bool nPixelLay_loaded;
    Value<vector<unsigned int>>* val_n3DLay;
    bool n3DLay_loaded;
    Value<vector<vector<int>>>* val_trkIdx;
    bool trkIdx_loaded;
    Value<vector<vector<float>>>* val_shareFrac;
    bool shareFrac_loaded;
    Value<vector<int>>* val_parentVtxIdx;
    bool parentVtxIdx_loaded;
    Value<vector<vector<int>>>* val_decayVtxIdx;
    bool decayVtxIdx_loaded;
    Value<vector<vector<int>>>* val_seedIdx;
    bool seedIdx_loaded;

    SimTrackCollection() { }

    void init(TrackingDataSet* tds){
        this->tds = tds;
    }

    size_t size() {
        if (!this->event_loaded) {
            this->val_event = this->tds->track_branch_obj<vector<int>>("sim_event");
            this->event_loaded = true;
        }
        return (*this->val_event)().size();
    }


    SimTrack operator[](size_t);
    iter begin() { return iter(this, 0); }
    iter end() { return iter(this, size()); }
};

struct SimTrack {
    SimTrackCollection* collection;
    size_t idx;
    SimTrack(SimTrackCollection* collection, const size_t idx)
      :collection(collection), idx(idx) { }

    const int& event() const {
        if (!collection->event_loaded) {
            collection->val_event = collection->tds->track_branch_obj<vector<int>>("sim_event");
            collection->event_loaded = true;
        }
        return (*collection->val_event)().at(idx);
    }

    const int& bunchCrossing() const {
        if (!collection->bunchCrossing_loaded) {
            collection->val_bunchCrossing = collection->tds->track_branch_obj<vector<int>>("sim_bunchCrossing");
            collection->bunchCrossing_loaded = true;
        }
        return (*collection->val_bunchCrossing)().at(idx);
    }

    const int& pdgId() const {
        if (!collection->pdgId_loaded) {
            collection->val_pdgId = collection->tds->track_branch_obj<vector<int>>("sim_pdgId");
            collection->pdgId_loaded = true;
        }
        return (*collection->val_pdgId)().at(idx);
    }

    const float& px() const {
        if (!collection->px_loaded) {
            collection->val_px = collection->tds->track_branch_obj<vector<float>>("sim_px");
            collection->px_loaded = true;
        }
        return (*collection->val_px)().at(idx);
    }

    const float& py() const {
        if (!collection->py_loaded) {
            collection->val_py = collection->tds->track_branch_obj<vector<float>>("sim_py");
            collection->py_loaded = true;
        }
        return (*collection->val_py)().at(idx);
    }

    const float& pz() const {
        if (!collection->pz_loaded) {
            collection->val_pz = collection->tds->track_branch_obj<vector<float>>("sim_pz");
            collection->pz_loaded = true;
        }
        return (*collection->val_pz)().at(idx);
    }

    const float& pt() const {
        if (!collection->pt_loaded) {
            collection->val_pt = collection->tds->track_branch_obj<vector<float>>("sim_pt");
            collection->pt_loaded = true;
        }
        return (*collection->val_pt)().at(idx);
    }

    const float& eta() const {
        if (!collection->eta_loaded) {
            collection->val_eta = collection->tds->track_branch_obj<vector<float>>("sim_eta");
            collection->eta_loaded = true;
        }
        return (*collection->val_eta)().at(idx);
    }

    const float& phi() const {
        if (!collection->phi_loaded) {
            collection->val_phi = collection->tds->track_branch_obj<vector<float>>("sim_phi");
            collection->phi_loaded = true;
        }
        return (*collection->val_phi)().at(idx);
    }

    const float& pca_pt() const {
        if (!collection->pca_pt_loaded) {
            collection->val_pca_pt = collection->tds->track_branch_obj<vector<float>>("sim_pca_pt");
            collection->pca_pt_loaded = true;
        }
        return (*collection->val_pca_pt)().at(idx);
    }

    const float& pca_eta() const {
        if (!collection->pca_eta_loaded) {
            collection->val_pca_eta = collection->tds->track_branch_obj<vector<float>>("sim_pca_eta");
            collection->pca_eta_loaded = true;
        }
        return (*collection->val_pca_eta)().at(idx);
    }

    const float& pca_lambda() const {
        if (!collection->pca_lambda_loaded) {
            collection->val_pca_lambda = collection->tds->track_branch_obj<vector<float>>("sim_pca_lambda");
            collection->pca_lambda_loaded = true;
        }
        return (*collection->val_pca_lambda)().at(idx);
    }

    const float& pca_cotTheta() const {
        if (!collection->pca_cotTheta_loaded) {
            collection->val_pca_cotTheta = collection->tds->track_branch_obj<vector<float>>("sim_pca_cotTheta");
            collection->pca_cotTheta_loaded = true;
        }
        return (*collection->val_pca_cotTheta)().at(idx);
    }

    const float& pca_phi() const {
        if (!collection->pca_phi_loaded) {
            collection->val_pca_phi = collection->tds->track_branch_obj<vector<float>>("sim_pca_phi");
            collection->pca_phi_loaded = true;
        }
        return (*collection->val_pca_phi)().at(idx);
    }

    const float& pca_dxy() const {
        if (!collection->pca_dxy_loaded) {
            collection->val_pca_dxy = collection->tds->track_branch_obj<vector<float>>("sim_pca_dxy");
            collection->pca_dxy_loaded = true;
        }
        return (*collection->val_pca_dxy)().at(idx);
    }

    const float& pca_dz() const {
        if (!collection->pca_dz_loaded) {
            collection->val_pca_dz = collection->tds->track_branch_obj<vector<float>>("sim_pca_dz");
            collection->pca_dz_loaded = true;
        }
        return (*collection->val_pca_dz)().at(idx);
    }

    const int& q() const {
        if (!collection->q_loaded) {
            collection->val_q = collection->tds->track_branch_obj<vector<int>>("sim_q");
            collection->q_loaded = true;
        }
        return (*collection->val_q)().at(idx);
    }

    const unsigned int& nValid() const {
        if (!collection->nValid_loaded) {
            collection->val_nValid = collection->tds->track_branch_obj<vector<unsigned int>>("sim_nValid");
            collection->nValid_loaded = true;
        }
        return (*collection->val_nValid)().at(idx);
    }

    const unsigned int& nPixel() const {
        if (!collection->nPixel_loaded) {
            collection->val_nPixel = collection->tds->track_branch_obj<vector<unsigned int>>("sim_nPixel");
            collection->nPixel_loaded = true;
        }
        return (*collection->val_nPixel)().at(idx);
    }

    const unsigned int& nStrip() const {
        if (!collection->nStrip_loaded) {
            collection->val_nStrip = collection->tds->track_branch_obj<vector<unsigned int>>("sim_nStrip");
            collection->nStrip_loaded = true;
        }
        return (*collection->val_nStrip)().at(idx);
    }

    const unsigned int& nLay() const {
        if (!collection->nLay_loaded) {
            collection->val_nLay = collection->tds->track_branch_obj<vector<unsigned int>>("sim_nLay");
            collection->nLay_loaded = true;
        }
        return (*collection->val_nLay)().at(idx);
    }

    const unsigned int& nPixelLay() const {
        if (!collection->nPixelLay_loaded) {
            collection->val_nPixelLay = collection->tds->track_branch_obj<vector<unsigned int>>("sim_nPixelLay");
            collection->nPixelLay_loaded = true;
        }
        return (*collection->val_nPixelLay)().at(idx);
    }

    const unsigned int& n3DLay() const {
        if (!collection->n3DLay_loaded) {
            collection->val_n3DLay = collection->tds->track_branch_obj<vector<unsigned int>>("sim_n3DLay");
            collection->n3DLay_loaded = true;
        }
        return (*collection->val_n3DLay)().at(idx);
    }

    const vector<int>& trkIdx() const {
        if (!collection->trkIdx_loaded) {
            collection->val_trkIdx = collection->tds->track_branch_obj<vector<vector<int>>>("sim_trkIdx");
            collection->trkIdx_loaded = true;
        }
        return (*collection->val_trkIdx)().at(idx);
    }

    const vector<float>& shareFrac() const {
        if (!collection->shareFrac_loaded) {
            collection->val_shareFrac = collection->tds->track_branch_obj<vector<vector<float>>>("sim_shareFrac");
            collection->shareFrac_loaded = true;
        }
        return (*collection->val_shareFrac)().at(idx);
    }

    const int& parentVtxIdx() const {
        if (!collection->parentVtxIdx_loaded) {
            collection->val_parentVtxIdx = collection->tds->track_branch_obj<vector<int>>("sim_parentVtxIdx");
            collection->parentVtxIdx_loaded = true;
        }
        return (*collection->val_parentVtxIdx)().at(idx);
    }

    const vector<int>& decayVtxIdx() const {
        if (!collection->decayVtxIdx_loaded) {
            collection->val_decayVtxIdx = collection->tds->track_branch_obj<vector<vector<int>>>("sim_decayVtxIdx");
            collection->decayVtxIdx_loaded = true;
        }
        return (*collection->val_decayVtxIdx)().at(idx);
    }

    const vector<int>& seedIdx() const {
        if (!collection->seedIdx_loaded) {
            collection->val_seedIdx = collection->tds->track_branch_obj<vector<vector<int>>>("sim_seedIdx");
            collection->seedIdx_loaded = true;
        }
        return (*collection->val_seedIdx)().at(idx);
    }

};

SimTrack SimTrackCollection::iter::operator*() {
    return {collection, idx};
}
SimTrack SimTrackCollection::operator[](size_t idx) {
    return {this, idx};
}
struct SimVertex;

class SimVertexCollection {
  public:
    class iter {
      public:
        iter(SimVertexCollection* collection, size_t idx)
          :collection(collection), idx(idx) { }
        iter operator++() { ++idx; return *this; }
        bool operator!=(const iter & other) { return idx != other.idx; }
        SimVertex operator*();
      private:
        SimVertexCollection* collection;
        size_t idx;
    };
    TrackingDataSet* tds;

    Value<vector<int>>* val_event;
    bool event_loaded;
    Value<vector<int>>* val_bunchCrossing;
    bool bunchCrossing_loaded;
    Value<vector<unsigned int>>* val_processType;
    bool processType_loaded;
    Value<vector<float>>* val_x;
    bool x_loaded;
    Value<vector<float>>* val_y;
    bool y_loaded;
    Value<vector<float>>* val_z;
    bool z_loaded;
    Value<vector<vector<int>>>* val_sourceSimIdx;
    bool sourceSimIdx_loaded;
    Value<vector<vector<int>>>* val_daughterSimIdx;
    bool daughterSimIdx_loaded;

    SimVertexCollection() { }

    void init(TrackingDataSet* tds){
        this->tds = tds;
    }

    size_t size() {
        if (!this->event_loaded) {
            this->val_event = this->tds->track_branch_obj<vector<int>>("simvtx_event");
            this->event_loaded = true;
        }
        return (*this->val_event)().size();
    }


    SimVertex operator[](size_t);
    iter begin() { return iter(this, 0); }
    iter end() { return iter(this, size()); }
};

struct SimVertex {
    SimVertexCollection* collection;
    size_t idx;
    SimVertex(SimVertexCollection* collection, const size_t idx)
      :collection(collection), idx(idx) { }

    const int& event() const {
        if (!collection->event_loaded) {
            collection->val_event = collection->tds->track_branch_obj<vector<int>>("simvtx_event");
            collection->event_loaded = true;
        }
        return (*collection->val_event)().at(idx);
    }

    const int& bunchCrossing() const {
        if (!collection->bunchCrossing_loaded) {
            collection->val_bunchCrossing = collection->tds->track_branch_obj<vector<int>>("simvtx_bunchCrossing");
            collection->bunchCrossing_loaded = true;
        }
        return (*collection->val_bunchCrossing)().at(idx);
    }

    const unsigned int& processType() const {
        if (!collection->processType_loaded) {
            collection->val_processType = collection->tds->track_branch_obj<vector<unsigned int>>("simvtx_processType");
            collection->processType_loaded = true;
        }
        return (*collection->val_processType)().at(idx);
    }

    const float& x() const {
        if (!collection->x_loaded) {
            collection->val_x = collection->tds->track_branch_obj<vector<float>>("simvtx_x");
            collection->x_loaded = true;
        }
        return (*collection->val_x)().at(idx);
    }

    const float& y() const {
        if (!collection->y_loaded) {
            collection->val_y = collection->tds->track_branch_obj<vector<float>>("simvtx_y");
            collection->y_loaded = true;
        }
        return (*collection->val_y)().at(idx);
    }

    const float& z() const {
        if (!collection->z_loaded) {
            collection->val_z = collection->tds->track_branch_obj<vector<float>>("simvtx_z");
            collection->z_loaded = true;
        }
        return (*collection->val_z)().at(idx);
    }

    const vector<int>& sourceSimIdx() const {
        if (!collection->sourceSimIdx_loaded) {
            collection->val_sourceSimIdx = collection->tds->track_branch_obj<vector<vector<int>>>("simvtx_sourceSimIdx");
            collection->sourceSimIdx_loaded = true;
        }
        return (*collection->val_sourceSimIdx)().at(idx);
    }

    const vector<int>& daughterSimIdx() const {
        if (!collection->daughterSimIdx_loaded) {
            collection->val_daughterSimIdx = collection->tds->track_branch_obj<vector<vector<int>>>("simvtx_daughterSimIdx");
            collection->daughterSimIdx_loaded = true;
        }
        return (*collection->val_daughterSimIdx)().at(idx);
    }

};

SimVertex SimVertexCollection::iter::operator*() {
    return {collection, idx};
}
SimVertex SimVertexCollection::operator[](size_t idx) {
    return {this, idx};
}
struct SuperCluster;

class SuperClusterCollection {
  public:
    class iter {
      public:
        iter(SuperClusterCollection* collection, size_t idx)
          :collection(collection), idx(idx) { }
        iter operator++() { ++idx; return *this; }
        bool operator!=(const iter & other) { return idx != other.idx; }
        SuperCluster operator*();
      private:
        SuperClusterCollection* collection;
        size_t idx;
    };
    TrackingDataSet* tds;

    Value<vector<float>>* val_e;
    bool e_loaded;
    Value<vector<float>>* val_px;
    bool px_loaded;
    Value<vector<float>>* val_py;
    bool py_loaded;
    Value<vector<float>>* val_pz;
    bool pz_loaded;
    Value<vector<float>>* val_x;
    bool x_loaded;
    Value<vector<float>>* val_y;
    bool y_loaded;
    Value<vector<float>>* val_z;
    bool z_loaded;
    Value<vector<float>>* val_hoe;
    bool hoe_loaded;

    SuperClusterCollection() { }

    void init(TrackingDataSet* tds){
        this->tds = tds;
    }

    size_t size() {
        if (!this->e_loaded) {
            this->val_e = this->tds->track_branch_obj<vector<float>>("scl_e");
            this->e_loaded = true;
        }
        return (*this->val_e)().size();
    }


    SuperCluster operator[](size_t);
    iter begin() { return iter(this, 0); }
    iter end() { return iter(this, size()); }
};

struct SuperCluster {
    SuperClusterCollection* collection;
    size_t idx;
    SuperCluster(SuperClusterCollection* collection, const size_t idx)
      :collection(collection), idx(idx) { }

    const float& e() const {
        if (!collection->e_loaded) {
            collection->val_e = collection->tds->track_branch_obj<vector<float>>("scl_e");
            collection->e_loaded = true;
        }
        return (*collection->val_e)().at(idx);
    }

    const float& px() const {
        if (!collection->px_loaded) {
            collection->val_px = collection->tds->track_branch_obj<vector<float>>("scl_px");
            collection->px_loaded = true;
        }
        return (*collection->val_px)().at(idx);
    }

    const float& py() const {
        if (!collection->py_loaded) {
            collection->val_py = collection->tds->track_branch_obj<vector<float>>("scl_py");
            collection->py_loaded = true;
        }
        return (*collection->val_py)().at(idx);
    }

    const float& pz() const {
        if (!collection->pz_loaded) {
            collection->val_pz = collection->tds->track_branch_obj<vector<float>>("scl_pz");
            collection->pz_loaded = true;
        }
        return (*collection->val_pz)().at(idx);
    }

    const float& x() const {
        if (!collection->x_loaded) {
            collection->val_x = collection->tds->track_branch_obj<vector<float>>("scl_x");
            collection->x_loaded = true;
        }
        return (*collection->val_x)().at(idx);
    }

    const float& y() const {
        if (!collection->y_loaded) {
            collection->val_y = collection->tds->track_branch_obj<vector<float>>("scl_y");
            collection->y_loaded = true;
        }
        return (*collection->val_y)().at(idx);
    }

    const float& z() const {
        if (!collection->z_loaded) {
            collection->val_z = collection->tds->track_branch_obj<vector<float>>("scl_z");
            collection->z_loaded = true;
        }
        return (*collection->val_z)().at(idx);
    }

    const float& hoe() const {
        if (!collection->hoe_loaded) {
            collection->val_hoe = collection->tds->track_branch_obj<vector<float>>("scl_hoe");
            collection->hoe_loaded = true;
        }
        return (*collection->val_hoe)().at(idx);
    }

};

SuperCluster SuperClusterCollection::iter::operator*() {
    return {collection, idx};
}
SuperCluster SuperClusterCollection::operator[](size_t idx) {
    return {this, idx};
}
