CMS 3D CMS Logo

printPixelTrackerMap.cc
Go to the documentation of this file.
2 #include <cstdint> // For uint32_t
3 #include <cstdlib> // For std::exit
4 #include <fstream>
5 #include <iostream>
6 #include <numeric> // std::accumulate
7 #include <sstream>
8 #include <string>
9 #include <vector>
10 
11 #include "TCanvas.h"
12 #include "TStyle.h"
13 
15  std::cout << "Usage: " << scriptName << " [options] <detid>\n"
16  << " --input-file <filename> Specify the input file\n"
17  << " --h or --help Show this help message\n"
18  << " <detid> Provide DetId (list of DetIds)\n";
19 }
20 
21 int main(int argc, char* argv[]) {
23  std::vector<std::pair<uint32_t, float>> detidValues;
24 
25  // If no arguments are passed or --h/--help is passed, show the help message
26  if (argc == 1) {
27  showHelp(argv[0]);
28  return 0;
29  }
30 
31  // Parse command line arguments
32  for (int i = 1; i < argc; ++i) {
33  std::string arg = argv[i];
34 
35  if (arg == "--h" || arg == "--help") {
36  showHelp(argv[0]);
37  return 0; // Exit after displaying help
38  } else if (arg == "--input-file" && i + 1 < argc) {
39  gStyle->SetPalette(kRainbow);
40  gStyle->SetNumberContours(256);
41  inputFile = argv[++i];
42  } else {
43  gStyle->SetPalette(1);
44  // Treat as DetId list if no --input-file is provided
45  try {
46  uint32_t detid = std::stoul(arg);
47  detidValues.emplace_back(detid, 1.0); // Default value is 1.0
48  } catch (const std::invalid_argument&) {
49  std::cerr << "Invalid DetId: " << arg << "\n";
50  showHelp(argv[0]);
51  return 1;
52  }
53  }
54  }
55 
56  // If --input-file is provided, read from file
57  if (!inputFile.empty()) {
58  std::ifstream file(inputFile);
59  if (!file) {
60  std::cerr << "Error: Unable to open input file " << inputFile << std::endl;
61  return 1;
62  }
63 
65  while (std::getline(file, line)) {
66  std::istringstream iss(line);
67  uint32_t detid;
68  float value = 1.0; // Default value
69 
70  iss >> detid;
71  if (iss >> value) { // If a second column exists, read it as value
72  detidValues.emplace_back(detid, value);
73  } else {
74  detidValues.emplace_back(detid, 1.0);
75  }
76  }
77  }
78 
79  // Create the map and fill it
80  Phase1PixelSummaryMap theMap("colz", "Marked Pixel Modules", "input values");
81  theMap.createTrackerBaseMap();
82 
83  for (const auto& [detid, value] : detidValues) {
84  theMap.fillTrackerMap(detid, value);
85  }
86 
87  TCanvas c = TCanvas("c", "c", 3000, 2000);
88  theMap.printTrackerMap(c);
89  c.SaveAs("Phase1PixelSummaryMap.png");
90 
91  std::cout << "Filled tracker map with " << detidValues.size() << " detids." << std::endl;
92 
93  return 0;
94 }
int main(int argc, char *argv[])
void showHelp(const std::string &scriptName)
A arg
Definition: Factorize.h:31
Definition: value.py:1
void printTrackerMap(TCanvas &canvas, const float topMargin=0.02, int index=0)
bool fillTrackerMap(unsigned int id, double value)