Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
#include "DPGAnalysis/SiStripTools/bin/BSvsBPIX.h"
#include "TFile.h"
#include "TH1F.h"
#include "TProfile.h"
#include "TGraphErrors.h"
#include "TCanvas.h"
#include "TDirectory.h"
#include <iostream>

void BSvsBPIXPlot(TFile* ff, const char* bsmodule, const char* occumodule, const int run) {
  TGraphErrors* bspos = new TGraphErrors();
  TGraphErrors* bpixpos = new TGraphErrors();

  if (ff) {
    char bsfolder[200];
    sprintf(bsfolder, "%s/run_%d", bsmodule, run);
    if (ff->cd(bsfolder)) {
      TH1F* bsx = (TH1F*)gDirectory->Get("bsxrun");
      TH1F* bsy = (TH1F*)gDirectory->Get("bsyrun");
      if (bsx && bsy) {
        std::cout << "beam spot position (" << bsx->GetMean() << "+/-" << bsx->GetMeanError() << "," << bsy->GetMean()
                  << "+/-" << bsy->GetMeanError() << ")" << std::endl;
        bspos->SetPoint(0, bsx->GetMean(), bsy->GetMean());
        bspos->SetPointError(0, bsx->GetMeanError(), bsy->GetMeanError());
      }
    }
    char occufolder[200];
    sprintf(occufolder, "%s/run_%d", occumodule, run);
    if (ff->cd(occufolder)) {
      TProfile* xmean = (TProfile*)gDirectory->Get("avex");
      TProfile* ymean = (TProfile*)gDirectory->Get("avey");
      if (xmean && ymean) {
        for (int i = 1; i <= xmean->GetNbinsX(); ++i) {
          if (xmean->GetBinEntries(i) > 0) {
            std::cout << "ladder position " << i << " : (" << xmean->GetBinContent(i) << "+/-" << xmean->GetBinError(i)
                      << "," << ymean->GetBinContent(i) << "+/-" << ymean->GetBinError(i) << ")" << std::endl;
            int point = bpixpos->GetN();
            bpixpos->SetPoint(point, xmean->GetBinContent(i), ymean->GetBinContent(i));
            bpixpos->SetPointError(point, xmean->GetBinError(i), ymean->GetBinError(i));
          }
        }
      }
    }
  }
  new TCanvas("bsbpix", "bsbpix", 500, 500);
  bpixpos->Draw("ap");
  bspos->Draw("p");
}