Skip to content
Snippets Groups Projects
hitmaps_shms.cxx 3.41 KiB
#include <ROOT/RDataFrame.hxx>
#include <TCanvas.h>
#include <TH1D.h>
#include <string>
#include <vector>

// NOTE: YOU WILL HAVE TO CHANGE $USER in this line with your own username!
const std::string kReplayDir =
    "/group/c-polhe3/Users/$USER/hallc_replay/ROOTfiles";

template <class T> using result_vector = std::vector<ROOT::RDF::RResultPtr<T>>;

int hitmaps_shms(int run = 7121, int nevents = 5000) {

  ROOT::RDataFrame d{"T", Form("%s/shms_replay_production_0%i_%i.root",
                               kReplayDir.c_str(), run, nevents)};

  // ADC Response histos
  result_vector<TH1D> hadc_pos; // positive side
  result_vector<TH1D> hadc_neg; // negative side

  // TDC response histos
  result_vector<TH1D> htdc_pos; // positive side
  result_vector<TH1D> htdc_neg; // negative side

  // Define your histograms
  // (looping over all planes we are interested in)
  for (auto plane : {"1x", "1y", "2x", "2y"}) {
    // This code defines a 1D histogram of the positive side ADC output, and
    // then adds it to the vector of histograms we defined above.
    // The histogram has 16 bins, corresponding to the hodoscope paddles 1 -> 16
    hadc_pos.push_back(
        d.Histo1D({Form("hadc_pos_%s", plane), Form("SHMS %s ADC hits;paddle number;counts", plane),
                   16, 0.5, 16.5},
                  Form("P.hod.%s.posAdcCounter", plane)));
    // Same for the other ADC side
    hadc_neg.push_back(
        d.Histo1D({Form("hadc_neg_%s", plane), Form("SHMS %s ADC hits", plane),
                   16, 0.5, 16.5},
                  Form("P.hod.%s.negAdcCounter", plane)));
    // And same for the TDC
    htdc_pos.push_back(
        d.Histo1D({Form("htdc_pos_%s", plane), Form("SHMS %s TDC hits", plane),
                   16, 0.5, 16.5},
                  Form("P.hod.%s.posTdcCounter", plane)));
    // Same for the other TDC side
    htdc_neg.push_back(
        d.Histo1D({Form("htdc_neg_%s", plane), Form("SHMS %s TDC hits", plane),
                   16, 0.5, 16.5},
                  Form("P.hod.%s.negTdcCounter", plane)));
  }

  // A canvas for us to draw our results on
  TCanvas* c = new TCanvas("c", "Scintillator Hit Maps", 800, 800);

  //
  // We will subdivide the canvas such that each plane occupies a single iplane
  // on the canvas
  c->Divide(2,                // 2 columns
            hadc_pos.size()); // enough iplanes to accomodate each plane

  // Note that ROOT will number the pads starting at 1 as follows:
  //
  // Pad 1    Pad 2
  // Pad 3    Pad 4
  // ...
  //
  for (int iplane = 0; iplane < hadc_pos.size(); ++iplane) {
    // ADC results on the left
    c->cd(2 * iplane + 1); // our subdivided pads start counting at 1
    // positive histogram
    hadc_pos[iplane]->SetFillColor(kGreen + 2);
    hadc_pos[iplane]->SetFillStyle(3345);
    hadc_pos[iplane]->DrawClone();
    // negative histogram
    hadc_neg[iplane]->SetFillColor(kBlue + 1);
    hadc_neg[iplane]->SetFillStyle(3354);
    hadc_neg[iplane]->DrawClone("same");

    // TDC results on the right, which is the next pad
    c->cd(2 * iplane + 2);
    // positive histogram
    htdc_pos[iplane]->SetFillColor(kGreen + 2);
    htdc_pos[iplane]->SetFillStyle(3345);
    htdc_pos[iplane]->DrawClone();
    // negative histogram
    htdc_neg[iplane]->SetFillColor(kBlue + 1);
    htdc_neg[iplane]->SetFillStyle(3354);
    htdc_neg[iplane]->DrawClone("same");
  }

  // Finally: make a PDF file with our figure
  c->Print(Form("hitmaps_shms_%i.pdf", run));
  return 0;
}