// HV scan: hadron beam
{
  // Threshold 60
  TVectorD i1th60 (5);
  i1th60[0] = 0.993580;
  i1th60[1] = 0.990909;
  i1th60[2] = 0.978039;
  i1th60[3] = 0.722178;
  i1th60[4] = 0.475573;

  TVectorD i2th60 (1);
  i2th60[0] = 0.994738;

  TVectorD i3th60 (2);
  i3th60[0] = 0.991283;
  i3th60[1] = 0.981350;

  TVectorD i1th60ey (5);
  i1th60ey[0] = 0.001364;
  i1th60ey[1] = 0.000910;
  i1th60ey[2] = 0.001474;
  i1th60ey[3] = 0.005644;
  i1th60ey[4] = 0.008672;

  TVectorD i2th60ey (1);
  i2th60ey[0] = 0.000708;

  TVectorD i3th60ey (2);
  i3th60ey[0] = 0.000996;
  i3th60ey[1] = 0.001413;


  // Threshold 40
  TVectorD i1th40 (5);
  i1th40[0] = 0.997995;
  i1th40[1] = 0.993154;
  i1th40[2] = 0.982443;
  i1th40[3] = 0.861188;
  i1th40[4] = 0.625832;

  TVectorD i2th40 (1);
  i2th40[0] = 0.997329;

  TVectorD i3th40 (2);
  i3th40[0] = 0.995623;
  i3th40[1] = 0.990536;

  TVectorD i1th40ey (5);
  i1th40ey[0] = 0.000757;
  i1th40ey[1] = 0.000840;
  i1th40ey[2] = 0.001637;
  i1th40ey[3] = 0.004301;
  i1th40ey[4] = 0.008416;

  TVectorD i2th40ey (1);
  i2th40ey[0] = 0.000495;

  TVectorD i3th40ey (2);
  i3th40ey[0] = 0.000708;
  i3th40ey[1] = 0.001360;

  TVectorD i1hv (5);
  i1hv[0] = 5.0;
  i1hv[1] = 4.9;
  i1hv[2] = 4.8;
  i1hv[3] = 4.6;
  i1hv[4] = 4.5;

  TVectorD i2hv (1);
  i2hv[0] = 5.0;

  TVectorD i3hv (2);
  i3hv[0] = 5.0;
  i3hv[1] = 4.9;

  TVectorD i1ex (5);
  TVectorD i2ex (1);
  TVectorD i3ex (2);


  TGraphErrors *i1_60 = new TGraphErrors (i1hv,i1th60,i1ex,i1th60ey);
  i1_60->SetTitle("I ~380k c/spill  | th -60 DAC steps");
  i1_60->SetLineColor(kBlack);
  i1_60->SetMarkerColor(kBlack);
  i1_60->SetMarkerStyle(7);
  i1_60->SetLineWidth(1);


  TGraphErrors *i1_40 = new TGraphErrors (i1hv,i1th40,i1ex,i1th40ey);
  i1_40->SetTitle("I ~380k c/spill  | th -40 DAC steps");
  i1_40->SetLineColor(kBlack);
  i1_40->SetMarkerColor(kBlack);
  i1_40->SetMarkerStyle(7);
  i1_40->SetLineWidth(1);

  TGraphErrors *i2_60 = new TGraphErrors (i2hv,i2th60,i2ex,i2th60ey);
  i2_60->SetTitle("I ~36k c/spill    | th -60 DAC steps");
  i2_60->SetLineColor(kBlack);
  i2_60->SetMarkerColor(kBlack);
  i2_60->SetMarkerStyle(21);

  TGraphErrors *i2_40 = new TGraphErrors (i2hv,i2th40,i2ex,i2th40ey);
  i2_40->SetTitle("I ~36k c/spill    | th -40 DAC steps");
  i2_40->SetLineColor(kBlack);
  i2_40->SetMarkerColor(kBlack);
  i2_40->SetMarkerStyle(20);

  TGraphErrors *i3_60 = new TGraphErrors (i3hv,i3th60,i3ex,i3th60ey);
  i3_60->SetTitle("I ~12.5k c/spill | th -60 DAC steps");
  i3_60->SetLineColor(kBlack);
  i3_60->SetMarkerColor(kBlack);
  i3_60->SetMarkerStyle(29);
  i3_60->SetLineWidth(3);
  i3_60->SetLineStyle(2);

  TGraphErrors *i3_40 = new TGraphErrors (i3hv,i3th40,i3ex,i3th40ey);
  i3_40->SetTitle("I ~12.5k c/spill | th -40 DAC steps");
  i3_40->SetLineColor(kBlack);
  i3_40->SetMarkerColor(kBlack);
  i3_40->SetMarkerStyle(29);
  i3_40->SetLineWidth(3);

  TCanvas *c1 = new TCanvas("c1","Hadrons");

  TMultiGraph *plot = new TMultiGraph();
  plot->Add(i1_60);
  plot->Add(i2_60);
  plot->Add(i3_60);
  plot->Add(i1_40);
  plot->Add(i2_40);
  plot->Add(i3_40);

  plot->Draw("ALP");
  plot->GetYaxis()->SetRangeUser(0,1);
  // These commands have to be put after the Draw command,
  // or it will cause segmentation violation
  plot->GetXaxis()->SetRangeUser(4.5,5);
  plot->GetYaxis()->SetDecimals();
  plot->GetXaxis()->SetTitle("Divider voltage [kV]");
  plot->GetYaxis()->SetTitle("LG efficiency");

  c1->Update();
  c1->SetGridx();
  c1->SetGridy();
  c1->SetTickx();
  c1->SetTicky();

  TLegend *legend = new TLegend (0.1,0.4,0.4,0.9);
  legend->SetHeader("Variable intensity hadrons");
  legend->AddEntry(i1_40,i1_40->GetTitle(),"lp");
  legend->AddEntry(i1_60,i1_60->GetTitle(),"lp");
  legend->AddEntry(i2_40,i2_40->GetTitle(),"p");
  legend->AddEntry(i2_60,i2_60->GetTitle(),"p");
  legend->AddEntry(i3_40,i3_40->GetTitle(),"lp");
  legend->AddEntry(i3_60,i3_60->GetTitle(),"lp");
  legend->Draw();

  c1->Update();

}
