|
1 | 1 | #include "DQM/TrackerRemapper/interface/Phase1PixelROCMaps.h" |
2 | 2 | #include <bitset> |
3 | | -#include <cstdlib> |
| 3 | +#include <cstdint> // for uint32_t |
| 4 | +#include <cstdlib> // for std::exit |
4 | 5 | #include <fstream> |
5 | 6 | #include <iostream> |
6 | 7 | #include <numeric> // std::accumulate |
|
11 | 12 | #include "TCanvas.h" |
12 | 13 | #include "TStyle.h" |
13 | 14 |
|
| 15 | +// Define an enum for region |
| 16 | +enum class Region { |
| 17 | + Barrel = 0, // Assume 0 for barrel |
| 18 | + Forward = 1, // 1 for forward |
| 19 | + Full = 2 // 2 for full |
| 20 | +}; |
| 21 | + |
| 22 | +void showHelp(const std::string& scriptName) { |
| 23 | + std::cout << "Usage: " << scriptName << " [options] <detid>\n" |
| 24 | + << " --input-file <filename> Specify the input file\n" |
| 25 | + << " --input-ROCs <filename> Specify the input ROCs file\n" |
| 26 | + << " --region <barrel|forward|full> Specify the region (default: full)\n" |
| 27 | + << " --h or --help Show this help message\n" |
| 28 | + << " <detid> Provide DetId (list of DetIds)\n"; |
| 29 | +} |
| 30 | + |
| 31 | +// Helper function to convert region enum to string (for displaying) |
| 32 | +std::string regionToString(Region region) { |
| 33 | + switch (region) { |
| 34 | + case Region::Barrel: |
| 35 | + return "barrel"; |
| 36 | + case Region::Forward: |
| 37 | + return "forward"; |
| 38 | + case Region::Full: |
| 39 | + return "full"; |
| 40 | + default: |
| 41 | + return "unknown"; |
| 42 | + } |
| 43 | +} |
| 44 | + |
| 45 | +// Helper function to parse region from string |
| 46 | +Region parseRegion(const std::string& regionStr) { |
| 47 | + if (regionStr == "barrel") { |
| 48 | + return Region::Barrel; |
| 49 | + } else if (regionStr == "forward") { |
| 50 | + return Region::Forward; |
| 51 | + } else if (regionStr == "full") { |
| 52 | + return Region::Full; |
| 53 | + } else { |
| 54 | + throw std::invalid_argument("Invalid region value"); |
| 55 | + } |
| 56 | +} |
| 57 | + |
14 | 58 | int main(int argc, char* argv[]) { |
| 59 | + static constexpr std::array<int, 3> k_height = {{1200, 600, 1600}}; |
| 60 | + |
15 | 61 | std::string inputFile; |
16 | 62 | std::string inputROCsFile; |
| 63 | + Region region = Region::Full; // Default value: Full region |
17 | 64 | std::vector<std::pair<uint32_t, float>> detidValues; |
18 | 65 | std::vector<std::pair<uint32_t, std::bitset<16>>> detidRocs; |
19 | 66 |
|
| 67 | + // If no arguments are passed or --h/--help is passed, show the help message |
| 68 | + if (argc == 1) { |
| 69 | + showHelp(argv[0]); |
| 70 | + return 0; |
| 71 | + } |
| 72 | + |
20 | 73 | // Parse command line arguments |
21 | 74 | for (int i = 1; i < argc; ++i) { |
22 | | - if (std::string(argv[i]) == "--input-file" && i + 1 < argc) { |
23 | | - gStyle->SetPalette(kRainbow); |
24 | | - gStyle->SetNumberContours(256); |
| 75 | + std::string arg = argv[i]; |
| 76 | + |
| 77 | + if (arg == "--h" || arg == "--help") { |
| 78 | + showHelp(argv[0]); |
| 79 | + return 0; // Exit after displaying help |
| 80 | + } else if (arg == "--input-file" && i + 1 < argc) { |
25 | 81 | inputFile = argv[++i]; |
26 | | - } else if (std::string(argv[i]) == "--input-ROCs" && i + 1 < argc) { |
27 | | - gStyle->SetPalette(kRainBow); |
28 | | - gStyle->SetNumberContours(256); |
| 82 | + } else if (arg == "--input-ROCs" && i + 1 < argc) { |
29 | 83 | inputROCsFile = argv[++i]; |
| 84 | + } else if (arg == "--region" && i + 1 < argc) { |
| 85 | + std::string regionArg = argv[++i]; |
| 86 | + try { |
| 87 | + region = parseRegion(regionArg); // Parse region from string |
| 88 | + } catch (const std::invalid_argument&) { |
| 89 | + std::cerr << "Invalid value for --region: " << regionArg << "\n"; |
| 90 | + showHelp(argv[0]); |
| 91 | + return 1; |
| 92 | + } |
30 | 93 | } else { |
31 | | - gStyle->SetPalette(1); |
32 | | - // Treat as DetId list if no --input-file is provided |
33 | | - uint32_t detid = std::stoul(argv[i]); |
34 | | - detidValues.emplace_back(detid, 1.0); // Default value is 1.0 |
| 94 | + // Assume it's a DetId, convert to uint32_t |
| 95 | + try { |
| 96 | + uint32_t detid = std::stoul(arg); |
| 97 | + detidValues.emplace_back(detid, 1.0); // Default value is 1.0 |
| 98 | + } catch (const std::invalid_argument&) { |
| 99 | + std::cerr << "Invalid argument: " << arg << "\n"; |
| 100 | + showHelp(argv[0]); |
| 101 | + return 1; |
| 102 | + } |
35 | 103 | } |
36 | 104 | } |
37 | 105 |
|
@@ -96,10 +164,23 @@ int main(int argc, char* argv[]) { |
96 | 164 | theMap.fillSelectedRocs(detid, rocs, 1.0); // Default value 1.0 |
97 | 165 | } |
98 | 166 |
|
| 167 | + // Construct the full label string |
| 168 | + std::string title = "Marked Pixel ROCs - " + regionToString(region); |
| 169 | + |
99 | 170 | // Draw and save the map |
100 | | - TCanvas canvas("Summary", "Summary", 1200, 1600); |
101 | | - theMap.drawMaps(canvas, "Marked Pixel ROCs"); |
102 | | - canvas.SaveAs("Phase1PixelROCMap.png"); |
| 171 | + TCanvas canvas("Summary", "Summary", 1200, k_height[static_cast<int>(region)]); |
| 172 | + if (region == Region::Full) { |
| 173 | + theMap.drawMaps(canvas, title.c_str()); |
| 174 | + } else if (region == Region::Barrel) { |
| 175 | + theMap.drawBarrelMaps(canvas, title.c_str()); |
| 176 | + } else if (region == Region::Forward) { |
| 177 | + theMap.drawForwardMaps(canvas, title.c_str()); |
| 178 | + } |
| 179 | + |
| 180 | + // Construct the filename string based on the region |
| 181 | + std::string fileName = "Phase1PixelROCMap_" + regionToString(region) + ".png"; |
| 182 | + // Save the canvas with the constructed filename |
| 183 | + canvas.SaveAs(fileName.c_str()); |
103 | 184 |
|
104 | 185 | std::cout << "Filled Phase1 Pixel ROC map with " << detidValues.size() + detidRocs.size() << " detids." << std::endl; |
105 | 186 |
|
|
0 commit comments