File indexing completed on 2024-04-06 12:20:59
0001 #include <map>
0002 #include <memory>
0003 #include <iostream>
0004
0005 #include "TH1F.h"
0006 #include "TFile.h"
0007
0008 #include "FWCore/Framework/interface/Frameworkfwd.h"
0009 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0010 #include "FWCore/Framework/interface/Event.h"
0011 #include "FWCore/Framework/interface/ESHandle.h"
0012 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0013
0014 #include "L1Trigger/L1TMuonEndCap/interface/PtLUTReader.h"
0015
0016 #include "helper.h"
0017 #include "progress_bar.h"
0018
0019 class ComparePtLUT : public edm::one::EDAnalyzer<> {
0020 public:
0021 explicit ComparePtLUT(const edm::ParameterSet&);
0022 ~ComparePtLUT() override;
0023
0024 private:
0025
0026
0027
0028
0029
0030
0031 void analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) override;
0032
0033 void compareLUTs();
0034
0035 private:
0036 PtLUTReader ptlut_reader1_;
0037 PtLUTReader ptlut_reader2_;
0038
0039 const edm::ParameterSet config_;
0040
0041 int verbose_;
0042
0043 std::string infile1_;
0044 std::string infile2_;
0045
0046 bool done_;
0047 };
0048
0049
0050 #define PTLUT_SIZE (1 << 30)
0051
0052 ComparePtLUT::ComparePtLUT(const edm::ParameterSet& iConfig)
0053 : ptlut_reader1_(),
0054 ptlut_reader2_(),
0055 config_(iConfig),
0056 verbose_(iConfig.getUntrackedParameter<int>("verbosity")),
0057 infile1_(iConfig.getParameter<std::string>("infile1")),
0058 infile2_(iConfig.getParameter<std::string>("infile2")),
0059 done_(false) {
0060 ptlut_reader1_.read(infile1_);
0061 ptlut_reader2_.read(infile2_);
0062 }
0063
0064 ComparePtLUT::~ComparePtLUT() {}
0065
0066 void ComparePtLUT::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0067 if (done_)
0068 return;
0069
0070 compareLUTs();
0071
0072 done_ = true;
0073 return;
0074 }
0075
0076 void ComparePtLUT::compareLUTs() {
0077 TFile* f = TFile::Open("diff.root", "RECREATE");
0078
0079 std::map<int, TH1F*> histograms;
0080 int diff_limit = 20;
0081 for (int mode_inv = 0; mode_inv < 16; ++mode_inv) {
0082 histograms[mode_inv] = new TH1F(
0083 Form("diff_mode_inv_%i", mode_inv), "", 2 * diff_limit + 1, -1.0 * diff_limit - 0.5, 1.0 * diff_limit + 0.5);
0084 }
0085
0086 for (int ivar = 0; ivar < 10; ++ivar) {
0087 histograms[100 + ivar] = new TH1F(Form("diff_subaddress_%i", ivar), "", 32 + 1, 0. - 0.5, 32. + 0.5);
0088 }
0089
0090 PtLUTReader::address_t address = 0;
0091
0092 for (; address < PTLUT_SIZE; ++address) {
0093 show_progress_bar(address, PTLUT_SIZE);
0094
0095 int mode_inv = (address >> (30 - 4)) & ((1 << 4) - 1);
0096
0097 int gmt_pt1 = ptlut_reader1_.lookup(address);
0098 int gmt_pt2 = ptlut_reader2_.lookup(address);
0099
0100 int diff = gmt_pt2 - gmt_pt1;
0101 diff = std::min(std::max(-diff_limit, diff), diff_limit);
0102
0103
0104
0105
0106 if (std::abs(gmt_pt2 - gmt_pt1) > diff_limit) {
0107 std::cout << mode_inv << " " << address << " " << print_subaddresses(address) << " " << gmt_pt1 << " " << gmt_pt2
0108 << " " << gmt_pt2 - gmt_pt1 << std::endl;
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133 }
0134
0135 histograms[mode_inv]->Fill(diff);
0136 }
0137
0138 for (const auto& kv : histograms) {
0139 kv.second->Write();
0140 }
0141 f->Close();
0142 }
0143
0144
0145 #include "FWCore/Framework/interface/MakerMacros.h"
0146 DEFINE_FWK_MODULE(ComparePtLUT);