Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-19 07:35:10

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #include "ActsExamples/Utilities/Options.hpp"
0010 
0011 #include <array>
0012 #include <bitset>
0013 #include <exception>
0014 #include <iostream>
0015 #include <limits>
0016 #include <numbers>
0017 #include <optional>
0018 #include <string>
0019 #include <vector>
0020 
0021 #include <TApplication.h>
0022 #include <boost/program_options.hpp>
0023 #include <boost/timer/progress_display.hpp>
0024 #include <nlohmann/json.hpp>
0025 
0026 #define BOOST_AVAILABLE 1
0027 
0028 using progress_display = boost::timer::progress_display;
0029 
0030 #define NLOHMANN_AVAILABLE 1
0031 #include "trackSummaryAnalysis.C"
0032 
0033 using namespace boost::program_options;
0034 
0035 using Interval = ActsExamples::Options::Interval;
0036 using VariableReals = ActsExamples::Options::VariableReals;
0037 
0038 int main(int argc, char **argv) {
0039   std::cout << "*** ACTS Perigee parameters and Track summary plotting "
0040             << std::endl;
0041 
0042   try {
0043     options_description description("*** Usage:");
0044 
0045     // Add the program options
0046     auto ao = description.add_options();
0047     ao("help,h", "Display this help message");
0048     ao("silent,s", bool_switch(), "Silent mode (without X-window/display).");
0049     ao("events,n", value<unsigned long>()->default_value(0),
0050        "(Optionally) limit number of events to be processed.");
0051     ao("peak-events,p", value<unsigned long>()->default_value(0),
0052        "(Optionally) limit number of events for the range peaking.");
0053     ao("input,i", value<std::vector<std::string>>()->required(),
0054        "Input ROOT file(s) containing the input TTree.");
0055     ao("tree,t", value<std::string>()->default_value("tracksummary"),
0056        "Input TTree/TChain name.");
0057     ao("output,o", value<std::string>()->default_value(""),
0058        "Output ROOT file with histograms");
0059     ao("hist-bins", value<unsigned int>()->default_value(61),
0060        "Number of bins for the residual/pull histograms");
0061     ao("pull-range", value<float>()->default_value(5.),
0062        "Number of sigmas for the pull range.");
0063     ao("eta-bins", value<unsigned int>()->default_value(10),
0064        "Number of bins in eta.");
0065     ao("eta-range",
0066        value<Interval>()->value_name("MIN:MAX")->default_value({-3.0, 3.0}),
0067        "Range for the eta bins.");
0068     ao("phi-bins", value<unsigned int>()->default_value(10),
0069        "Number of bins in phi.");
0070     ao("phi-range",
0071        value<Interval>()->value_name("MIN:MAX")->default_value(
0072            {-std::numbers::pi, std::numbers::pi}),
0073        "Range for the phi bins.");
0074     ao("pt-borders", value<VariableReals>()->required(),
0075        "Transverse momentum borders.");
0076     ao("config-output", value<std::string>()->default_value(""),
0077        "(Optional) output histogram configuration json file.");
0078     ao("config-input", value<std::string>()->default_value(""),
0079        "(Optional) input histogram configuration json file.");
0080     // Define all parameters (overwrites individual parameters)
0081     ao("all", bool_switch(),
0082        "Process all residual/pull and auxiliary parameters");
0083     // Define the parameters for the residual/pull analysis
0084     std::vector<std::string> resPullPars = {"d0",  "z0",   "phi0", "theta0",
0085                                             "qop", "time", "pt"};
0086     for (const auto &rp : resPullPars) {
0087       ao(rp.c_str(), bool_switch(),
0088          (std::string("Residual/pulls for ") + rp).c_str());
0089     }
0090     // Define the auxiliary track information
0091     std::vector<std::string> auxPars = {"chi2ndf", "measurements", "holes",
0092                                         "outliers", "shared"};
0093     for (const auto &aux : auxPars) {
0094       ao(aux.c_str(), bool_switch(),
0095          (std::string("Auxiliary information for ") + aux).c_str());
0096     }
0097 
0098     // Set up the variables map
0099     variables_map vm;
0100     store(command_line_parser(argc, argv).options(description).run(), vm);
0101 
0102     if (vm.contains("help")) {
0103       std::cout << description;
0104       return 1;
0105     }
0106 
0107     notify(vm);
0108 
0109     // Events
0110     unsigned long nEntries = vm["events"].as<unsigned long>();
0111     unsigned long nPeakEntries = vm["peak-events"].as<unsigned long>();
0112 
0113     // Parse the parameters
0114     auto iFiles = vm["input"].as<std::vector<std::string>>();
0115     auto iTree = vm["tree"].as<std::string>();
0116     auto oFile = vm["output"].as<std::string>();
0117 
0118     // Configuration JSON files
0119     auto configInput = vm["config-input"].as<std::string>();
0120     auto configOutput = vm["config-output"].as<std::string>();
0121 
0122     float pullRange = vm["pull-range"].as<float>();
0123     unsigned int nHistBins = vm["hist-bins"].as<unsigned int>();
0124     unsigned int nEtaBins = vm["eta-bins"].as<unsigned int>();
0125 
0126     auto etaInterval = vm["eta-range"].as<Interval>();
0127     std::array<float, 2> etaRange = {
0128         static_cast<float>(etaInterval.lower.value_or(-3)),
0129         static_cast<float>(etaInterval.upper.value_or(3.))};
0130 
0131     unsigned int nPhiBins = vm["phi-bins"].as<unsigned int>();
0132     auto phiInterval = vm["phi-range"].as<Interval>();
0133     std::array<float, 2> phiRange = {
0134         static_cast<float>(phiInterval.lower.value_or(-std::numbers::pi)),
0135         static_cast<float>(phiInterval.upper.value_or(std::numbers::pi))};
0136 
0137     auto ptBorders = vm["pt-borders"].as<VariableReals>().values;
0138     if (ptBorders.empty()) {
0139       ptBorders = {0., std::numeric_limits<double>::infinity()};
0140     }
0141 
0142     TApplication *tApp =
0143         vm["silent"].as<bool>()
0144             ? nullptr
0145             : new TApplication("TrackSummary", nullptr, nullptr);
0146 
0147     std::bitset<7> residualPulls;
0148     std::bitset<5> auxiliaries;
0149     if (vm["all"].as<bool>()) {
0150       residualPulls = std::bitset<7>{"1111111"};
0151       auxiliaries = std::bitset<5>{"11111"};
0152     } else {
0153       // Set the bit for the chosen parameters(s)
0154       for (unsigned int iresp = 0; iresp < resPullPars.size(); ++iresp) {
0155         if (vm[resPullPars[iresp]].as<bool>()) {
0156           residualPulls.set(iresp);
0157         }
0158       }
0159       // Set the bit for the chosen auxiliaries
0160       for (unsigned int iaux = 0; iaux < auxPars.size(); ++iaux) {
0161         if (vm[auxPars[iaux]].as<bool>()) {
0162           auxiliaries.set(iaux);
0163         }
0164       }
0165     }
0166 
0167     // Run the actual resolution estimation
0168     switch (trackSummaryAnalysis(
0169         iFiles, iTree, oFile, configInput, configOutput, nEntries, nPeakEntries,
0170         pullRange, nHistBins, nPhiBins, phiRange, nEtaBins, etaRange, ptBorders,
0171         residualPulls, auxiliaries)) {
0172       case -1: {
0173         std::cout << "*** Input file could not be opened, check name/path."
0174                   << std::endl;
0175       } break;
0176       case -2: {
0177         std::cout << "*** Input tree could not be found, check name."
0178                   << std::endl;
0179       } break;
0180       default: {
0181         std::cout << "*** Successful run." << std::endl;
0182       };
0183     }
0184 
0185     if (tApp != nullptr) {
0186       tApp->Run();
0187     }
0188 
0189   } catch (std::exception &e) {
0190     std::cerr << e.what() << "\n";
0191   }
0192 
0193   std::cout << "*** Done." << std::endl;
0194   return 1;
0195 }