CMS 3D CMS Logo

printPixelLayersDisksMap.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  << "Options:\n"
17  << " --input-file <filename> Specify the input file\n"
18  << " --h or --help Show this help message\n"
19  << " <detid> Provide DetId (list of DetIds)\n";
20 }
21 
22 int main(int argc, char* argv[]) {
24  std::vector<std::pair<uint32_t, float>> detidValues;
25 
26  // If no arguments are passed or --h/--help is passed, show the help message
27  if (argc == 1) {
28  showHelp(argv[0]);
29  return 0;
30  }
31 
32  // Parse command line arguments
33  for (int i = 1; i < argc; ++i) {
34  std::string arg = argv[i];
35 
36  if (arg == "--h" || arg == "--help") {
37  showHelp(argv[0]);
38  return 0; // Exit after displaying help
39  } else if (arg == "--input-file" && i + 1 < argc) {
40  gStyle->SetPalette(kRainbow);
41  gStyle->SetNumberContours(256);
42  inputFile = argv[++i];
43  } else {
44  gStyle->SetPalette(1);
45  // Treat as DetId list if no --input-file is provided
46  try {
47  uint32_t detid = std::stoul(arg);
48  detidValues.emplace_back(detid, 1.0); // Default value is 1.0
49  } catch (const std::invalid_argument&) {
50  std::cerr << "Invalid DetId: " << arg << "\n";
51  showHelp(argv[0]);
52  return 1;
53  }
54  }
55  }
56 
57  // If --input-file is provided, read from file
58  if (!inputFile.empty()) {
59  std::ifstream file(inputFile);
60  if (!file) {
61  std::cerr << "Error: Unable to open input file " << inputFile << std::endl;
62  return 1;
63  }
64 
66  while (std::getline(file, line)) {
67  std::istringstream iss(line);
68  uint32_t detid;
69  float value = 1.0; // Default value
70 
71  iss >> detid;
72  if (iss >> value) { // If a second column exists, read it as value
73  detidValues.emplace_back(detid, value);
74  } else {
75  detidValues.emplace_back(detid, 1.0);
76  }
77  }
78  }
79 
80  // Create the map and fill it
81  Phase1PixelMaps theMap("COLZ0A L"); // needed to not show the axis
82  TCanvas c = TCanvas("c", "c", 1200, 800);
83  theMap.book("mytest", "Marked modules", "input values");
84  for (const auto& [detid, value] : detidValues) {
85  theMap.fill("mytest", detid, value);
86  }
87 
88  theMap.beautifyAllHistograms();
89  theMap.drawSummaryMaps("mytest", c);
90  c.SaveAs("Phase1PixelMaps_Summary.png");
91 
92  std::cout << "Filled tracker map with " << detidValues.size() << " detids." << std::endl;
93 
94  return 0;
95 }
int main(int argc, char *argv[])
A arg
Definition: Factorize.h:31
void drawSummaryMaps(const std::string &currentHistoName, TCanvas &canvas, const char *drawOption=nullptr)
Definition: value.py:1
void beautifyAllHistograms()
void showHelp(const std::string &scriptName)
void book(const std::string &currentHistoName, const char *what, const char *zaxis)
void fill(const std::string &currentHistoName, unsigned int id, double value)