Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 09:55:32

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   //virtual void beginJob();
0026   //virtual void endJob();
0027 
0028   //virtual void beginRun(const edm::Run&, const edm::EventSetup&);
0029   //virtual void endRun(const edm::Run&, const edm::EventSetup&);
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     //if (address % (1<<20) == 0)
0104     //  std::cout << mode_inv << " " << address << " " << print_subaddresses(address) << " " << gmt_pt1 << " " << gmt_pt2 << " " << gmt_pt2 - gmt_pt1 << std::endl;
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       //if (mode_inv == 5) {  // debug
0111       //  histograms[100+0]->Fill(get_subword(address,25,21));  // theta
0112       //  histograms[100+1]->Fill(get_subword(address,20,20));  // FR3
0113       //  histograms[100+2]->Fill(get_subword(address,19,19));  // FR1
0114       //  histograms[100+3]->Fill(get_subword(address,18,18));  // CLCT3Sign
0115       //  histograms[100+4]->Fill(get_subword(address,17,16));  // CLCT3
0116       //  histograms[100+5]->Fill(get_subword(address,15,15));  // CLCT1Sign
0117       //  histograms[100+6]->Fill(get_subword(address,14,13));  // CLCT1
0118       //  histograms[100+7]->Fill(get_subword(address,12,10));  // dTheta13
0119       //  histograms[100+8]->Fill(get_subword(address, 9, 9));  // sign13
0120       //  histograms[100+9]->Fill(get_subword(address, 8, 0));  // dPhi13
0121       //}
0122 
0123       //if (mode_inv == 14) {  // debug
0124       //  histograms[100+0]->Fill(get_subword(address,25,21));  // theta
0125       //  histograms[100+1]->Fill(get_subword(address,20,20));  // CLCT2Sign
0126       //  histograms[100+2]->Fill(get_subword(address,19,18));  // CLCT2
0127       //  histograms[100+3]->Fill(get_subword(address,17,15));  // dTheta24
0128       //  histograms[100+4]->Fill(get_subword(address,14,14));  // sign34
0129       //  histograms[100+5]->Fill(get_subword(address,13,13));  // sign23
0130       //  histograms[100+6]->Fill(get_subword(address,12, 7));  // dPhi34
0131       //  histograms[100+7]->Fill(get_subword(address, 6, 0));  // dPhi23
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 // DEFINE THIS AS A PLUG-IN
0145 #include "FWCore/Framework/interface/MakerMacros.h"
0146 DEFINE_FWK_MODULE(ComparePtLUT);