// Plots an efficiency scan over the foils seam
// Change the run number to change data set
{
	#include "TGraphErrors.h"

        TFile f("../RootData/Run0703.root");
	rd51tb->AddFriend("recotree","../RootData/Run0703_reco.root");
	TCut Beff("Beff","dist(GetX(bgch.ch),GetY(bgch.ch),trackx[0]->q - 303.2,tracky[0]->q - 34.4)<7");
	TCut goodtr("goodtr","trackx@.GetEntries()==1 && tracky@.GetEntries()==1 && trackx[0].chi2<10 && tracky[0].chi2<10 && residualx[0]<10 && residualy[0]<10");
	rd51tb->Draw("tracky->q >>h2(60,0,60)",goodtr);
	rd51tb->Draw("tracky->q >>h1(60,0,60)",goodtr && Beff);
	TH1F *h2 = (TH1F*)gDirectory->Get("h2");
	TH1F *h1 = (TH1F*)gDirectory->Get("h1");
	Double_t efficiency[60];
	Double_t x[60];
	Double_t errors[60];
	Double_t errorsx[60];
	for (Int_t i = 1; i < 60 + 1; i++)
	  {
	    if (h2->GetBinContent(i) != 0)
	      {
		efficiency[i-1] = h1->GetBinContent(i) / h2->GetBinContent(i);
	      }
	    else efficiency[i-1] = 0;
	    errors[i-1] = (efficiency[i-1] * (1 - efficiency[i-1])) / sqrt(h2->GetBinContent(i));
	    errorsx[i-1] = 0;
	    x[i-1] = i - 1;
	  }
	TGraphErrors effgraph(60,x,efficiency,errorsx,errors);
	effgraph.GetYaxis()->SetRangeUser(0,1);
	effgraph.GetYaxis()->SetDecimals();
	effgraph.SetTitle("LG efficiency over GEM foils junction");
	effgraph.GetXaxis()->SetTitle("Y [mm]");
	effgraph.GetYaxis()->SetTitle("LG efficiency");
	effgraph.GetXaxis()->SetRangeUser(15,49);
	effgraph.SetMarkerStyle(7);
	effgraph.Draw("ALP");
	
}
