#include <string>
#include <iostream>
#include <sstream>
#include <TTree.h>
#include <TFile.h>
#include <cstdio>
#include <TH1.h>
#include <TVectorT.h>

using namespace std;

double effex2(TFile& file0);

// Gives a fast print of efficiency and
// corresponding statistical errors
void efferrors(long int run_number, long int last_run){

  Int_t size = last_run - run_number + 1;

  TVectorD nRun (size);
  TVectorD run_eff (size);
  TVectorD errors (size);
  Int_t count = 0;
  long int j = run_number;

  for (long int i=j;i<last_run+1;i++)
    {
      string s;
      char run_n[3];
      sprintf(run_n,"%ld",i);
      s = string(run_n);
      string rootfile_name = "../RootData/Run0" + s + ".root";
      string recofile_name = "../RootData/Run0" + s + "_reco.root";

      TFile file0(recofile_name.c_str());
      double eff = effex2(file0);
      run_eff[count] = eff;
      nRun[count] = i;
      TH1F* heffbgch = dynamic_cast<TH1F*>(file0.Get("heffbgch"));	
      double n = heffbgch->GetEntries();
      double staterror = eff * (1 - eff) / sqrt( n );
      errors[count] = staterror;
      count = count + 1;
      file0.Close();
    }

}
