File indexing completed on 2024-10-25 05:06:28
0001 #include "DQM/TrackerRemapper/interface/Phase1PixelSummaryMap.h"
0002 #include <cstdint> // For uint32_t
0003 #include <cstdlib> // For std::exit
0004 #include <fstream>
0005 #include <iostream>
0006 #include <numeric> // std::accumulate
0007 #include <sstream>
0008 #include <string>
0009 #include <vector>
0010
0011 #include "TCanvas.h"
0012 #include "TStyle.h"
0013
0014 void showHelp(const std::string& scriptName) {
0015 std::cout << "Usage: " << scriptName << " [options] <detid>\n"
0016 << " --input-file <filename> Specify the input file\n"
0017 << " --h or --help Show this help message\n"
0018 << " <detid> Provide DetId (list of DetIds)\n";
0019 }
0020
0021 int main(int argc, char* argv[]) {
0022 std::string inputFile;
0023 std::vector<std::pair<uint32_t, float>> detidValues;
0024
0025
0026 if (argc == 1) {
0027 showHelp(argv[0]);
0028 return 0;
0029 }
0030
0031
0032 for (int i = 1; i < argc; ++i) {
0033 std::string arg = argv[i];
0034
0035 if (arg == "--h" || arg == "--help") {
0036 showHelp(argv[0]);
0037 return 0;
0038 } else if (arg == "--input-file" && i + 1 < argc) {
0039 gStyle->SetPalette(kRainbow);
0040 gStyle->SetNumberContours(256);
0041 inputFile = argv[++i];
0042 } else {
0043 gStyle->SetPalette(1);
0044
0045 try {
0046 uint32_t detid = std::stoul(arg);
0047 detidValues.emplace_back(detid, 1.0);
0048 } catch (const std::invalid_argument&) {
0049 std::cerr << "Invalid DetId: " << arg << "\n";
0050 showHelp(argv[0]);
0051 return 1;
0052 }
0053 }
0054 }
0055
0056
0057 if (!inputFile.empty()) {
0058 std::ifstream file(inputFile);
0059 if (!file) {
0060 std::cerr << "Error: Unable to open input file " << inputFile << std::endl;
0061 return 1;
0062 }
0063
0064 std::string line;
0065 while (std::getline(file, line)) {
0066 std::istringstream iss(line);
0067 uint32_t detid;
0068 float value = 1.0;
0069
0070 iss >> detid;
0071 if (iss >> value) {
0072 detidValues.emplace_back(detid, value);
0073 } else {
0074 detidValues.emplace_back(detid, 1.0);
0075 }
0076 }
0077 }
0078
0079
0080 Phase1PixelSummaryMap theMap("colz", "Marked Pixel Modules", "input values");
0081 theMap.createTrackerBaseMap();
0082
0083 for (const auto& [detid, value] : detidValues) {
0084 theMap.fillTrackerMap(detid, value);
0085 }
0086
0087 TCanvas c = TCanvas("c", "c", 3000, 2000);
0088 theMap.printTrackerMap(c);
0089 c.SaveAs("Phase1PixelSummaryMap.png");
0090
0091 std::cout << "Filled tracker map with " << detidValues.size() << " detids." << std::endl;
0092
0093 return 0;
0094 }