Back to home page

EIC code displayed by LXR

 
 

    


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