Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-09-27 07:02:38

0001 ////////////////////////////////////////
0002 // Read reconstruction ROOT output file
0003 // Plot variables
0004 ////////////////////////////////////////
0005 
0006 #include "ROOT/RDataFrame.hxx"
0007 #include <iostream>
0008 #include <fmt/core.h>
0009 
0010 #include "edm4hep/MCParticleCollection.h"
0011 #include "edm4hep/SimTrackerHitCollection.h"
0012 
0013 #include "TCanvas.h"
0014 #include "TStyle.h"
0015 #include "TMath.h"
0016 #include "TH1.h"
0017 #include "TF1.h"
0018 #include "TH1D.h"
0019 
0020 using ROOT::RDataFrame;
0021 using namespace ROOT::VecOps;
0022 
0023 void drich_analysis(const char* input_fname = "sim_output/sim_pid_forward_e-_5GeV.edm4hep.root", const char* input_pname = "e-")
0024 {
0025   // Setting for graphs
0026   gROOT->SetStyle("Plain");
0027   gStyle->SetOptFit(1);
0028   gStyle->SetLineWidth(2);
0029   gStyle->SetPadTickX(1);
0030   gStyle->SetPadTickY(1);
0031   gStyle->SetPadGridX(1);
0032   gStyle->SetPadGridY(1);
0033   gStyle->SetPadLeftMargin(0.14);
0034   gStyle->SetPadRightMargin(0.14);
0035 
0036   ROOT::EnableImplicitMT();
0037   ROOT::RDataFrame d0("events", input_fname);
0038 
0039   // Define variables
0040   auto d1 = d0.Define("nhits", {"DRICHHits.size()"});
0041 
0042   // Define Histograms
0043   auto hNhits =
0044       d1.Histo1D({"hNhits", "Number of hits per events; Number of hits; Events",
0045                   100, 0.0, 2000.0},
0046                  "nhits");
0047   auto hXYhits =
0048       d1.Histo2D({"hXYhits", "Hit positions for events; Horizontal position [mm]; Vertical position [mm]",
0049                   1000, -2500.0, +2500.0, 1000, -2500.0, +2500.0},
0050                  "DRICHHits.position.x", "DRICHHits.position.y");
0051 
0052   // Event Counts
0053   auto nevents_thrown = d1.Count();
0054   std::cout << "Number of Thrown Events: " << (*nevents_thrown) << "\n";
0055 
0056   // Draw Histograms
0057   {
0058     TCanvas* c1 = new TCanvas("c1", "c1", 700, 500);
0059     auto h = hXYhits->DrawCopy();
0060     c1->SaveAs(fmt::format("results/pid/forward/drich/drich_{}_hits_xy.png",input_pname).c_str());
0061     c1->SaveAs(fmt::format("results/pid/forward/drich/drich_{}_hits_xy.pdf",input_pname).c_str());
0062   }
0063   {
0064     TCanvas* c2 = new TCanvas("c2", "c2", 700, 500);
0065     c2->SetLogy(1);
0066     auto h = hNhits->DrawCopy();
0067     //h->GetYaxis()->SetTitleOffset(1.4);
0068     h->SetLineWidth(2);
0069     h->SetLineColor(kBlue);
0070     c2->SaveAs(fmt::format("results/pid/forward/drich/drich_{}_nhits.png",input_pname).c_str());
0071     c2->SaveAs(fmt::format("results/pid/forward/drich/drich_{}_nhits.pdf",input_pname).c_str());
0072   }
0073 }