Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-06-26 07:05:22

0001 // draw various momentum scan plots
0002 R__LOAD_LIBRARY(podioDict)
0003 R__LOAD_LIBRARY(podioRootIO)
0004 R__LOAD_LIBRARY(edm4hep)
0005 R__LOAD_LIBRARY(edm4eic)
0006 R__LOAD_LIBRARY(fmt)
0007 
0008 #include "fmt/format.h"
0009 
0010 // radiators
0011 enum rad_enum {kAgl, kGas, nRad};
0012 
0013 //=========================================================
0014 
0015 void momentum_scan_eicrecon_draw(
0016     TString  ana_file_name  = "out/rec.ana.root",        // output analysis file from EICrecon benchmarks
0017     TString  out_file_name  = "out/rec.scan_plots.root", // this script will produce this file
0018     unsigned which_radiator = 1                          // see `rad_enum` above
0019     )
0020 {
0021 
0022   // files
0023   TFile *ana_file = new TFile(TString(ana_file_name));
0024   TFile *out_file = new TFile(TString(out_file_name),"RECREATE");
0025 
0026   // radiators
0027   TString radiator_name;
0028   double mom_max;
0029   switch(which_radiator) {
0030     case kAgl:
0031       radiator_name = "Aerogel";
0032       mom_max       = 22;
0033       break;
0034     case kGas:
0035       radiator_name = "Gas";
0036       mom_max       = 65;
0037       break;
0038     default:
0039       fmt::print(stderr,"ERROR: unknown which_radiator={}\n",which_radiator);
0040       return;
0041   }
0042 
0043   // get plots
0044   std::map<TString,TH2D*> scans;
0045   auto get_scan = [&] (TString dir, TString name, TString suffix="") {
0046     TString hist_name = dir + "/" + name + "_vs_p";
0047     if(suffix!="") hist_name += "_" + suffix;
0048     fmt::print("get histogram '{}'\n",hist_name);
0049     auto hist = ana_file->Get<TH2D>(hist_name);
0050     hist->SetName(name+"_scan");
0051     scans.insert({name,hist});
0052   };
0053   get_scan( "pid_irt", "nphot"       );
0054   get_scan( "pid_irt", "npe",        radiator_name );
0055   get_scan( "pid_irt", "theta",      radiator_name );
0056   get_scan( "pid_irt", "thetaResid", radiator_name );
0057 
0058   // make scan profiles
0059   std::map<TString,TProfile*> scan_profs;
0060   std::map<TString,TCanvas*> scan_canvs;
0061   for(const auto& [name,scan] : scans) {
0062     auto prof = scan->ProfileX("_pfx",1,-1,"");
0063     prof->SetLineColor(kBlack);
0064     prof->SetLineWidth(3);
0065     scan_profs.insert({name,prof});
0066     TString canv_name(name+"_canv");
0067     auto canv = new TCanvas(canv_name,canv_name);
0068     canv->SetGrid(1,1);
0069     scan->Draw("box");
0070     prof->Draw("same");
0071     scan_canvs.insert({name,canv});
0072   }
0073 
0074   // write output
0075   auto WriteScans = [] (auto vec) { for(const auto& [name,obj] : vec) obj->Write(); };
0076   WriteScans(scans);
0077   WriteScans(scan_profs);
0078   WriteScans(scan_canvs);
0079   out_file->Close();
0080   fmt::print("\n{:=<50}\nwrote: {}\n\n","",out_file_name);
0081 }