Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-09-07 04:36:04

0001 #include "DQM/TrackerRemapper/interface/Phase1PixelMaps.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   // Parse command line arguments
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       // Treat as DetId list if no --input-file is provided
0026       uint32_t detid = std::stoul(argv[i]);
0027       detidValues.emplace_back(detid, 1.0);  // Default value is 1.0
0028     }
0029   }
0030 
0031   // If --input-file is provided, read from file
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;  // Default value
0044 
0045       iss >> detid;
0046       if (iss >> value) {  // If a second column exists, read it as value
0047         detidValues.emplace_back(detid, value);
0048       } else {
0049         detidValues.emplace_back(detid, 1.0);
0050       }
0051     }
0052   }
0053 
0054   // Create the map and fill it
0055   Phase1PixelMaps theMap("COLZ0A L");  // needed to not show the axis
0056   TCanvas c = TCanvas("c", "c", 1200, 800);
0057   theMap.book("mytest", "Marked modules", "input values");
0058   for (const auto& [detid, value] : detidValues) {
0059     theMap.fill("mytest", detid, value);
0060   }
0061 
0062   theMap.beautifyAllHistograms();
0063   theMap.drawSummaryMaps("mytest", c);
0064   c.SaveAs("Phase1PixelMaps_Summary.png");
0065 
0066   std::cout << "Filled tracker map with " << detidValues.size() << " detids." << std::endl;
0067 
0068   return 0;
0069 }