Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "DQM/TrackerRemapper/interface/Phase1PixelROCMaps.h"
0002 #include <bitset>
0003 #include <cstdlib>
0004 #include <fstream>
0005 #include <iostream>
0006 #include <numeric>  // std::accumulate
0007 #include <sstream>
0008 #include <string>
0009 #include <vector>
0010 
0011 #include "TCanvas.h"
0012 #include "TStyle.h"
0013 
0014 int main(int argc, char* argv[]) {
0015   std::string inputFile;
0016   std::string inputROCsFile;
0017   std::vector<std::pair<uint32_t, float>> detidValues;
0018   std::vector<std::pair<uint32_t, std::bitset<16>>> detidRocs;
0019 
0020   // Parse command line arguments
0021   for (int i = 1; i < argc; ++i) {
0022     if (std::string(argv[i]) == "--input-file" && i + 1 < argc) {
0023       gStyle->SetPalette(kRainbow);
0024       gStyle->SetNumberContours(256);
0025       inputFile = argv[++i];
0026     } else if (std::string(argv[i]) == "--input-ROCs" && i + 1 < argc) {
0027       gStyle->SetPalette(kRainBow);
0028       gStyle->SetNumberContours(256);
0029       inputROCsFile = argv[++i];
0030     } else {
0031       gStyle->SetPalette(1);
0032       // Treat as DetId list if no --input-file is provided
0033       uint32_t detid = std::stoul(argv[i]);
0034       detidValues.emplace_back(detid, 1.0);  // Default value is 1.0
0035     }
0036   }
0037 
0038   // If --input-file is provided, read from file
0039   if (!inputFile.empty()) {
0040     std::ifstream file(inputFile);
0041     if (!file) {
0042       std::cerr << "Error: Unable to open input file " << inputFile << std::endl;
0043       return 1;
0044     }
0045 
0046     std::string line;
0047     while (std::getline(file, line)) {
0048       std::istringstream iss(line);
0049       uint32_t detid;
0050       float value = 1.0;  // Default value
0051 
0052       iss >> detid;
0053       if (iss >> value) {  // If a second column exists, read it as value
0054         detidValues.emplace_back(detid, value);
0055       } else {
0056         detidValues.emplace_back(detid, 1.0);
0057       }
0058     }
0059   }
0060 
0061   // If --input-ROCs is provided, read from file
0062   if (!inputROCsFile.empty()) {
0063     std::ifstream file(inputROCsFile);
0064     if (!file) {
0065       std::cerr << "Error: Unable to open input ROCs file " << inputROCsFile << std::endl;
0066       return 1;
0067     }
0068 
0069     std::string line;
0070     while (std::getline(file, line)) {
0071       std::istringstream iss(line);
0072       uint32_t detid;
0073       std::string rocBits;
0074       iss >> detid >> rocBits;
0075 
0076       if (rocBits.length() == 16) {
0077         std::bitset<16> rocs(rocBits);
0078         detidRocs.emplace_back(detid, rocs);
0079       } else {
0080         std::cerr << "Error: Invalid ROC bits string for detid " << detid << std::endl;
0081         return 1;
0082       }
0083     }
0084   }
0085 
0086   // Create the map and fill it
0087   Phase1PixelROCMaps theMap("");
0088 
0089   // Fill with detidValues if --input-file or command line DetIds are used
0090   for (const auto& [detid, value] : detidValues) {
0091     theMap.fillWholeModule(detid, value);
0092   }
0093 
0094   // Fill with detidRocs if --input-ROCs is used
0095   for (const auto& [detid, rocs] : detidRocs) {
0096     theMap.fillSelectedRocs(detid, rocs, 1.0);  // Default value 1.0
0097   }
0098 
0099   // Draw and save the map
0100   TCanvas canvas("Summary", "Summary", 1200, 1600);
0101   theMap.drawMaps(canvas, "Marked Pixel ROCs");
0102   canvas.SaveAs("Phase1PixelROCMap.png");
0103 
0104   std::cout << "Filled Phase1 Pixel ROC map with " << detidValues.size() + detidRocs.size() << " detids." << std::endl;
0105 
0106   return 0;
0107 }