File indexing completed on 2024-09-27 07:03:04
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <TFile.h>
0010 #include <TTree.h>
0011 #include <TTreeReader.h>
0012 #include <TTreeReaderArray.h>
0013 #include <fmt/core.h>
0014 #include <string>
0015
0016 void reco_particles_track_matching(const std::string &file_name) {
0017 auto *file = new TFile(file_name.c_str());
0018 auto *tree = (TTree *) file->Get("events");
0019 TTreeReader tree_reader(tree);
0020 tree->Print();
0021
0022
0023 TTreeReaderArray<float> reco_pz_array = {tree_reader, "ReconstructedChargedParticles.momentum.z"};
0024
0025
0026 TTreeReaderArray<float> mc_pz_array = {tree_reader, "MCParticles.momentum.z"};
0027
0028
0029
0030 TTreeReaderArray<unsigned int> rec_id = {tree_reader, "ReconstructedChargedParticleAssociations.recID"};
0031 TTreeReaderArray<unsigned int> sim_id = {tree_reader, "ReconstructedChargedParticleAssociations.simID"};
0032
0033
0034
0035 tree_reader.SetEntriesRange(0, 100);
0036 while (tree_reader.Next()) {
0037
0038
0039 fmt::print("New event. N reco particles: {}, N mc particles: {}, N assoc: {}\n",
0040 reco_pz_array.GetSize(), mc_pz_array.GetSize(), rec_id.GetSize());
0041
0042
0043 for(unsigned int i=0; i < rec_id.GetSize(); i++) {
0044
0045
0046 auto reco_array_index = rec_id[i];
0047 auto mc_array_index = sim_id[i];
0048
0049 float reco_pz = reco_pz_array[reco_array_index];
0050 float mc_pz = mc_pz_array[mc_array_index];
0051 fmt::print(" reco={:>10.4f} mc={:>10.4f}\n", reco_pz, mc_pz);
0052 }
0053 }
0054 }
0055
0056
0057 int main() {
0058 reco_particles_track_matching("input.edm4eic.root");
0059 return 0;
0060 }