Q:

C Error: Expected Unqualified-id Before '{' Token

What I'm inputting: gcc -o plot plot_na22.C.
What I'm getting: plot_na22.C:1: error: expected unqualified-id before '{' token.
I have no clue what I'm doing. This is someone else's code and I don't know why it's not working. Any advice? 
{
  // ROOT style junk
  gStyle->SetOptStat(0);
  gStyle->SetTitleFont(132, "XYZ");
  gStyle->SetLabelFont(132, "XYZ");

  // some constants for binning
  double qmin = 0.0;
  double qmax = 500.0;
  int qbins = 250;
  double fmin = 0.0;
  double fmax = 1.0;
  int fbins = 200;
  double rscale = 435.0;
  double rmin = 0.0;
  double rmax = pow(435.0 / rscale, 3);
  int rbins = 200;

  // 1D charge, fprompt, and scaled centroid histograms
  TH1D* hq = new TH1D("hq", "", qbins, qmin, qmax);
  hq->SetLineColor(4);
  hq->SetXTitle("Charge (PE)");
  TH1D* hf = new TH1D("hf", "", fbins, fmin, fmax);
  hf->SetLineColor(4);
  hf->SetXTitle("f_{p}");
  TH1D* hr = new TH1D("hr", "", rbins,
                      pow(rmin/rscale, 3), rmax);
  hr->SetLineColor(4);
  hr->SetXTitle("(r / r_{tpb})^{3}");

  // 1D reconstructed coordinate histograms
  TH1D* hx = new TH1D("hx", "", rbins, -rscale, rscale);
  hx->SetLineColor(4);
  hx->SetXTitle("Position (mm)");
  TH1D* hy = new TH1D("hy", "", rbins, -rscale, rscale);
  hy->SetLineColor(2);
  hy->SetXTitle("Position (mm)");
  TH1D* hz = new TH1D("hz", "", rbins, -rscale, rscale);
  hz->SetLineColor(3);
  hz->SetXTitle("Position (mmm)");

  // 2D histograms
  TH2D* hfq = new TH2D("hfq", "", qbins, qmin, qmax, fbins, fmin, fmax);
  hfq->SetMarkerColor(4);
  hfq->SetMarkerStyle(20);
  hfq->SetMarkerSize(0.3);
  hfq->SetXTitle("Charge (PE)");
  hfq->SetYTitle("f_{p}");
  TH2D* hfr = new TH2D("hfr", "", rbins, rmin, rmax, fbins, fmin, fmax);
  hfr->SetMarkerColor(4);
  hfr->SetMarkerStyle(20);
  hfr->SetMarkerSize(0.3);
  hfr->SetXTitle("(r / r_{tpb})^{3}");
  hfr->SetYTitle("f_{p}");
  TH2D* hqr = new TH2D("hqr", "", qbins, qmin, qmax, rbins, rmin, rmax);
  hqr->SetMarkerColor(4);
  hqr->SetMarkerStyle(20);
  hqr->SetMarkerSize(0.3);
  hqr->SetXTitle("Charge (PE)");
  hqr->SetYTitle("(r / r_{tpb})^{3}");
  TH2D* hang = new TH2D("hang", "",
                        rbins/2, -TMath::Pi(), TMath::Pi(), rbins/2, -1.0,1.0);
  hang->SetMarkerStyle(20);
  hang->SetMarkerSize(0.2);
  hang->SetMarkerColor(4);
  hang->SetXTitle("#phi");
  hang->SetYTitle("cos(#theta)");

  // create a tchain with the simulated data
  TChain* tree = new TChain("T", "T");
  tree->Add("/home/benjiang/fuck/realdata_*.root");
  RAT::DS::Root* ds = new RAT::DS::Root();
  tree->SetBranchAddress("ds", &ds);

  // count for the number of triggers
  int ntriggers = 0;

  // begin reading events
  for(int iev=0; iev<tree->GetEntries(); iev++){
    if(iev % 10000 == 0)
      printf("event %i\t of %i\t%i triggers\n", iev, tree->GetEntries(), ntriggers);
    tree->GetEvent(iev);
    // ignore this event if there wasn't an event trigger
    if(ds->GetEVCount() != 1)
      continue;
    RAT::DS::EV* ev = ds->GetEV(0);
    ntriggers ++;
    // ignore this event if a data quality cut failed for some reason
    if(!ev->GetPassAllCuts())
      continue;
    // get values from the data structure
    double q = ev->GetQPE();
    double f = ev->GetFprompt();
    TVector3 v = ev->GetCentroid()->GetPosition();
    double r = pow(v.Mag() / rscale, 3.0);
    // fill histograms
    hq->Fill(q);
    hr->Fill(r);
    hf->Fill(f);
    hx->Fill(v.X());
    hy->Fill(v.Y());
    hz->Fill(v.Z());
    hfq->Fill(q, f);
    hfr->Fill(r, f);
    hqr->Fill(q, r);
    hang->Fill(v.Phi(), TMath::Cos(v.Theta()));
  };

  // legend for 1D coordinate histograms
  TLegend* plegend = new TLegend(0.6, 0.6, 0.8, 0.8);
  plegend->SetLineColor(0);
  plegend->SetFillColor(0);
  plegend->AddEntry(hx, "#font[132]{x}", "l");
  plegend->AddEntry(hy, "#font[132]{y}", "l");
  plegend->AddEntry(hz, "#font[132]{z}", "l");

  // canvases to draw the histograms
  TCanvas* c0 = new TCanvas("c0", "", 0, 0, 1400, 1200);
  c0->Divide(3, 2);
  c0->cd(1);
  hq->Draw();
  c0->cd(2);
  hf->Draw();
  c0->cd(3);
  hr->Draw();
  c0->cd(4);
  hfq->Draw("colz");
  c0->cd(5);
  hfr->Draw("colz");
  c0->cd(6);
  hqr->Draw("colz");
  c0->Update();
  TCanvas* c2 = new TCanvas("c2", "", 0, 0, 1400, 600);
  c2->Divide(2, 1);
  c2->cd(1);
  hx->Draw();
  hy->Draw("same");
  hz->Draw("same");
  plegend->Draw();
  c2->cd(2);
  hang->Draw("colz");
  c2->Update();

  // write the histograms and canvases to a root file
  TFile* outfile = new TFile("plot_na22.root", "recreate");
  outfile->cd();
  c0->Write();
  c2->Write();
  hq->Write();
  hf->Write();
  hr->Write();
  hfq->Write();
  hfr->Write();
  hqr->Write();
  hx->Write();
  hy->Write();
  hz->Write();
  hang->Write();
  outfile->Close();
}

A:

It looks like you have a C file meant for ROOT. You can't compile it on its own with GCC. I'm unfamiliar with ROOT, but try this.
root plot_na22.C

