{

 gROOT->Reset();
  gROOT->ProcessLine(".x /work/leverington/beamprofilemonitor/hitdata/Scripts/Scripts_20161126/lhcbStyle.C");



  TFile *_file0_p = TFile::Open("../../HIT_26-11-2016/with_timestamp/SAVE_PiN_run8.root");
  TH2D * g_0p = 0;
 _file0_p->GetObject("th2d_beamSignal_channel",g_0p);
 TProfile* g_0p_pfx = g_0p->ProfileX();

 TFile *_file1_p = TFile::Open("../../HIT_26-11-2016/with_timestamp/SAVE_PiN_run32.root");
 TH2D * g_1p = 0;
 _file1_p->GetObject("th2d_beamSignal_channel",g_1p);
 TProfile* g_1p_pfx = g_1p->ProfileX();

 TFile *_file0_he = TFile::Open("../../HIT_26-11-2016/with_timestamp/SAVE_PiN_run35.root");
 TH2D * g_0he = 0;
 _file0_he->GetObject("th2d_beamSignal_channel",g_0he);
 TProfile* g_0he_pfx = g_0he->ProfileX();

 TFile *_file1_he = TFile::Open("../../HIT_26-11-2016/with_timestamp/SAVE_PiN_run60.root");
 TH2D * g_1he = 0;
 _file1_he->GetObject("th2d_beamSignal_channel",g_1he);
 TProfile* g_1he_pfx = g_1he->ProfileX();



 TFile *_file0_c = TFile::Open("../../HIT_26-11-2016/with_timestamp/SAVE_PiN_run63.root");
TH2D * g_0c = 0;
 _file0_c->GetObject("th2d_beamSignal_channel",g_0c);
 TProfile* g_0c_pfx = g_0c->ProfileX();


 TFile *_file1_c = TFile::Open("../../HIT_26-11-2016/with_timestamp/SAVE_PiN_run86.root");
 TH2D * g_1c = 0;
 _file1_c->GetObject("th2d_beamSignal_channel",g_1c);
 TProfile* g_1c_pfx = g_1c->ProfileX();


 TFile *_file0_o = TFile::Open("../../HIT_26-11-2016/with_timestamp/SAVE_PiN_run89.root");
TH2D * g_0o = 0;
 _file0_o->GetObject("th2d_beamSignal_channel",g_0o);
 TProfile* g_0o_pfx = g_0o->ProfileX();



 TFile *_file1_o = TFile::Open("../../HIT_26-11-2016/with_timestamp/SAVE_PiN_run108.root");
 TH2D * g_1o = 0;
 _file1_o->GetObject("th2d_beamSignal_channel",g_1o);
 TProfile* g_1o_pfx = g_1o->ProfileX();

   TCanvas *c1 = new TCanvas("c1", "canvaspad1", 800, 800);




   gStyle->SetPadBorderMode(0);
   gStyle->SetFrameBorderMode(0);
   Float_t small = 1e-5;
   c1->Divide(2,2,small,small);
  
   c1->cd(1);
   gPad->SetBottomMargin(small);
   gPad->SetRightMargin(small);
   gPad->SetLeftMargin(0.2);

     g_0p_pfx->SetMarkerStyle(20);g_0p_pfx->SetMarkerColor(kGray);
     g_1p_pfx->SetMarkerStyle(20);

     g_0p_pfx->SetTitle("");
    


   // mg_p->GetXaxis()->SetTitle("Stopping Power / MeV#upointcm^{2}g^{-1}");
   g_0p_pfx->GetYaxis()->SetTitle("A_{BPM} / a.u./312#mus"); g_0p_pfx->GetYaxis()->SetTitleOffset(1.5);
   g_0p_pfx->GetXaxis()->SetRangeUser(4,64);
   g_0p_pfx->GetYaxis()->SetRangeUser(-200,3200);
   g_0p_pfx->SetMinimum(-200.);
   g_0p_pfx->SetMaximum(3200.);

   g_0p_pfx->Draw();
   g_1p_pfx->Draw("same");
 TLegend * mylegend = new TLegend(0.25,0.8,0.9,0.9);
  mylegend->SetFillColor(0); // white background
  mylegend->SetTextFont(22);
  mylegend->SetBorderSize(0); // get rid of the box
  mylegend->SetTextSize(0.045); // set text size
  mylegend->AddEntry(g_0p_pfx,"Protons:  70 MeV/u,  1.2#upoint10^{9} s^{-1}","p"); // options: p,l,f
  mylegend->AddEntry(g_1p_pfx,"Protons: 221 MeV/u,  1.2#upoint10^{9} s^{-1}","p"); // options: p,l,f
  mylegend->Draw();


   gPad->Modified();

   
   c1->cd(2);
   gPad->SetBottomMargin(small);
   gPad->SetRightMargin(0.2);
   gPad->SetLeftMargin(small);



     g_0he_pfx->SetMarkerStyle(20);g_0he_pfx->SetMarkerColor(kGray);
     g_1he_pfx->SetMarkerStyle(20);

     g_0he_pfx->SetTitle("");
   g_0he_pfx->GetYaxis()->SetTitle("A_{BHEM} / a.u./312#mus"); g_0he_pfx->GetYaxis()->SetTitleOffset(1.5);
   g_0he_pfx->GetXaxis()->SetRangeUser(4,64);
   g_0he_pfx->GetYaxis()->SetRangeUser(-200,3200);
   g_0he_pfx->SetMinimum(-200.);
   g_0he_pfx->SetMaximum(3200.);

   g_0he_pfx->Draw();
   g_1he_pfx->Draw("same");

  
TLegend * mylegend2 = new TLegend(0.05,0.8,0.7,0.9);
  mylegend2->SetFillColor(0); // white background
  mylegend2->SetTextFont(22);
  mylegend2->SetBorderSize(0); // get rid of the box
  mylegend2->SetTextSize(0.045); // set text size
  mylegend2->AddEntry(g_0he_pfx,"Helium:  72 MeV/u,  3.0#upoint10^{8} s^{-1}","p"); // options: p,l,f
  mylegend2->AddEntry(g_1he_pfx,"Helium: 221 MeV/u,  3.0#upoint10^{8} s^{-1}","p"); // options: p,l,f
  mylegend2->Draw();
   gPad->Modified();

  
   c1->cd(3);
   gPad->SetTopMargin(small);
   gPad->SetRightMargin(small);
   gPad->SetLeftMargin(0.2);
   gPad->SetTickx();



     g_0c_pfx->SetMarkerStyle(20);g_0c_pfx->SetMarkerColor(kGray);
     g_1c_pfx->SetMarkerStyle(20);

     g_0c_pfx->SetTitle("");
   g_0c_pfx->GetYaxis()->SetTitle("A_{BCM} / a.u./312#mus"); g_0c_pfx->GetYaxis()->SetTitleOffset(1.5);
   g_0c_pfx->GetXaxis()->SetRangeUser(4,64); g_0c_pfx->GetXaxis()->SetTitle("Channel");
   g_0c_pfx->GetYaxis()->SetRangeUser(-200,3200);
   g_0c_pfx->SetMinimum(-200.);
   g_0c_pfx->SetMaximum(3200.);

   g_0c_pfx->Draw();
   g_1c_pfx->Draw("same");


TLegend * mylegend3 = new TLegend(0.25,0.85,0.9,0.95);
  mylegend3->SetFillColor(0); // white background
  mylegend3->SetTextFont(22);
  mylegend3->SetBorderSize(0); // get rid of the box
  mylegend3->SetTextSize(0.045); // set text size
  mylegend3->AddEntry(g_0c_pfx,"Carbon: 130 MeV/u,  3.0#upoint10^{7} s^{-1}","p"); // options: p,l,f
  mylegend3->AddEntry(g_1c_pfx,"Carbon: 430 MeV/u,  3.0#upoint10^{7} s^{-1}","p"); // options: p,l,f
  mylegend3->Draw();

   gPad->Modified();


   c1->cd(4);
   gPad->SetTopMargin(small);
   gPad->SetRightMargin(0.2);
   gPad->SetLeftMargin(small);
   gPad->SetTickx();

     g_0o_pfx->SetMarkerStyle(20);g_0o_pfx->SetMarkerColor(kGray);
     g_1o_pfx->SetMarkerStyle(20);

     g_0o_pfx->SetTitle("");
   g_0o_pfx->GetYaxis()->SetTitle("A_{BOM} / a.u./312#mus"); g_0o_pfx->GetYaxis()->SetTitleOffset(1.5);
   g_0o_pfx->GetXaxis()->SetRangeUser(4,64); g_0o_pfx->GetXaxis()->SetTitle("Channel");
   g_0o_pfx->GetYaxis()->SetRangeUser(-200,3200);
   g_0o_pfx->SetMinimum(-200.);
   g_0o_pfx->SetMaximum(3200.);

   g_0o_pfx->Draw();
   g_1o_pfx->Draw("same");




TLegend * mylegend4 = new TLegend(0.05,0.85,0.7,0.95);
  mylegend4->SetFillColor(0); // white background
  mylegend4->SetTextFont(22);
  mylegend4->SetBorderSize(0); // get rid of the box
  mylegend4->SetTextSize(0.045); // set text size
  mylegend4->AddEntry(g_0o_pfx,"Oxygen: 152 MeV/u,  1.5#upoint10^{7} s^{-1}","p"); // options: p,l,f
  mylegend4->AddEntry(g_1o_pfx,"Oxygen: 423 MeV/u,  1.5#upoint10^{7} s^{-1}","p"); // options: p,l,f
  mylegend4->Draw();

   gPad->Modified();
   
   c1->cd();
   gPad->Modified();
   c1->SaveAs("figs/beamprofileexamples_avg.pdf");
   c1->SaveAs("figs/beamprofileexamples_avg.png");

}   




