Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-12-17 09:12:32

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