File indexing completed on 2024-09-07 04:36:04
0001 #include "DQM/TrackerRemapper/interface/SiStripTkMaps.h"
0002 #include <cstdlib>
0003 #include <fstream>
0004 #include <iostream>
0005 #include <numeric> // std::accumulate
0006 #include <sstream>
0007 #include <string>
0008 #include <vector>
0009
0010 #include "TCanvas.h"
0011 #include "TStyle.h"
0012
0013 int main(int argc, char* argv[]) {
0014 std::string inputFile;
0015 std::vector<std::pair<uint32_t, float>> detidValues;
0016
0017
0018 for (int i = 1; i < argc; ++i) {
0019 if (std::string(argv[i]) == "--input-file" && i + 1 < argc) {
0020 gStyle->SetPalette(kRainbow);
0021 gStyle->SetNumberContours(256);
0022 inputFile = argv[++i];
0023 } else {
0024 gStyle->SetPalette(1);
0025
0026 uint32_t detid = std::stoul(argv[i]);
0027 detidValues.emplace_back(detid, 1.0);
0028 }
0029 }
0030
0031
0032 if (!inputFile.empty()) {
0033 std::ifstream file(inputFile);
0034 if (!file) {
0035 std::cerr << "Error: Unable to open input file " << inputFile << std::endl;
0036 return 1;
0037 }
0038
0039 std::string line;
0040 while (std::getline(file, line)) {
0041 std::istringstream iss(line);
0042 uint32_t detid;
0043 float value = 1.0;
0044
0045 iss >> detid;
0046 if (iss >> value) {
0047 detidValues.emplace_back(detid, value);
0048 } else {
0049 detidValues.emplace_back(detid, 1.0);
0050 }
0051 }
0052 }
0053
0054
0055 SiStripTkMaps theMap("COLZ0 AL");
0056 theMap.bookMap("Strip Tracker Map of Marked modules", "input values");
0057
0058 for (const auto& [detid, value] : detidValues) {
0059 theMap.fill(detid, value);
0060 }
0061
0062
0063 bool allSame = std::all_of(detidValues.begin(), detidValues.end(), [&](const std::pair<uint32_t, float>& p) {
0064 return p.second == detidValues[0].second;
0065 });
0066
0067 TCanvas c = TCanvas("c", "c");
0068 theMap.drawMap(c, "");
0069
0070
0071 if (allSame)
0072 theMap.setZAxisRange(0., detidValues[0].second);
0073
0074 c.SaveAs("SiStripsTkMaps.png");
0075
0076 std::cout << "Filled tracker map with " << detidValues.size() << " detids." << std::endl;
0077
0078 return 0;
0079 }