File indexing completed on 2024-10-25 05:06:28
0001 #include "DQM/TrackerRemapper/interface/Phase1PixelMaps.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 << "Options:\n"
0017 << " --input-file <filename> Specify the input file\n"
0018 << " --h or --help Show this help message\n"
0019 << " <detid> Provide DetId (list of DetIds)\n";
0020 }
0021
0022 int main(int argc, char* argv[]) {
0023 std::string inputFile;
0024 std::vector<std::pair<uint32_t, float>> detidValues;
0025
0026
0027 if (argc == 1) {
0028 showHelp(argv[0]);
0029 return 0;
0030 }
0031
0032
0033 for (int i = 1; i < argc; ++i) {
0034 std::string arg = argv[i];
0035
0036 if (arg == "--h" || arg == "--help") {
0037 showHelp(argv[0]);
0038 return 0;
0039 } else if (arg == "--input-file" && i + 1 < argc) {
0040 gStyle->SetPalette(kRainbow);
0041 gStyle->SetNumberContours(256);
0042 inputFile = argv[++i];
0043 } else {
0044 gStyle->SetPalette(1);
0045
0046 try {
0047 uint32_t detid = std::stoul(arg);
0048 detidValues.emplace_back(detid, 1.0);
0049 } catch (const std::invalid_argument&) {
0050 std::cerr << "Invalid DetId: " << arg << "\n";
0051 showHelp(argv[0]);
0052 return 1;
0053 }
0054 }
0055 }
0056
0057
0058 if (!inputFile.empty()) {
0059 std::ifstream file(inputFile);
0060 if (!file) {
0061 std::cerr << "Error: Unable to open input file " << inputFile << std::endl;
0062 return 1;
0063 }
0064
0065 std::string line;
0066 while (std::getline(file, line)) {
0067 std::istringstream iss(line);
0068 uint32_t detid;
0069 float value = 1.0;
0070
0071 iss >> detid;
0072 if (iss >> value) {
0073 detidValues.emplace_back(detid, value);
0074 } else {
0075 detidValues.emplace_back(detid, 1.0);
0076 }
0077 }
0078 }
0079
0080
0081 Phase1PixelMaps theMap("COLZ0A L");
0082 TCanvas c = TCanvas("c", "c", 1200, 800);
0083 theMap.book("mytest", "Marked modules", "input values");
0084 for (const auto& [detid, value] : detidValues) {
0085 theMap.fill("mytest", detid, value);
0086 }
0087
0088 theMap.beautifyAllHistograms();
0089 theMap.drawSummaryMaps("mytest", c);
0090 c.SaveAs("Phase1PixelMaps_Summary.png");
0091
0092 std::cout << "Filled tracker map with " << detidValues.size() << " detids." << std::endl;
0093
0094 return 0;
0095 }