Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-09-07 04:37:10

0001 #include "FWCore/Framework/interface/MakerMacros.h"
0002 
0003 #include <fstream>
0004 #include <iomanip>
0005 #include <memory>
0006 #include <string>
0007 #include <cmath>
0008 
0009 #include "FWCore/Framework/interface/stream/EDAnalyzer.h"
0010 #include "FWCore/Framework/interface/Event.h"
0011 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0012 #include "FWCore/Utilities/interface/EDGetToken.h"
0013 #include "FWCore/Utilities/interface/InputTag.h"
0014 #include "FWCore/Framework/interface/EventSetup.h"
0015 #include "FWCore/Framework/interface/Frameworkfwd.h"
0016 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0017 #include "FWCore/MessageLogger/interface/MessageDrop.h"
0018 
0019 #include "DataFormats/L1Scouting/interface/OrbitCollection.h"
0020 #include "DataFormats/L1Scouting/interface/L1ScoutingMuon.h"
0021 #include "DataFormats/L1Scouting/interface/L1ScoutingCalo.h"
0022 #include "L1TriggerScouting/Utilities/interface/printScObjects.h"
0023 #include "L1TriggerScouting/Utilities/interface/convertToL1TFormat.h"
0024 
0025 using namespace l1ScoutingRun3;
0026 
0027 // ----------------------------- CLASS DECLARATION  ----------------------------
0028 class DumpScObjects : public edm::stream::EDAnalyzer<> {
0029 public:
0030   // constructor and destructor
0031   explicit DumpScObjects(const edm::ParameterSet&);
0032   ~DumpScObjects() override {}
0033 
0034   // method for analyzing the events
0035   void analyze(const edm::Event&, const edm::EventSetup&) override;
0036 
0037 private:
0038   // dump contenct of BX
0039   void printBx(unsigned bx);
0040 
0041   // the tokens to access the data
0042   edm::EDGetTokenT<MuonOrbitCollection> gmtMuonsToken_;
0043   edm::EDGetTokenT<JetOrbitCollection> caloJetsToken_;
0044   edm::EDGetTokenT<EGammaOrbitCollection> caloEGammasToken_;
0045   edm::EDGetTokenT<TauOrbitCollection> caloTausToken_;
0046   edm::EDGetTokenT<BxSumsOrbitCollection> caloEtSumsToken_;
0047 
0048   edm::Handle<MuonOrbitCollection> muonHandle_;
0049   edm::Handle<JetOrbitCollection> jetHandle_;
0050   edm::Handle<EGammaOrbitCollection> eGammaHandle_;
0051   edm::Handle<TauOrbitCollection> tauHandle_;
0052   edm::Handle<BxSumsOrbitCollection> etSumHandle_;
0053 
0054   // the min and max BX to be analyzed
0055   unsigned minBx_;
0056   unsigned maxBx_;
0057 
0058   // select collection to be printed
0059   bool checkMuons_;
0060   bool checkJets_;
0061   bool checkEGammas_;
0062   bool checkTaus_;
0063   bool checkEtSums_;
0064 
0065   // dump a specific (ORBIT, BX RANGE)
0066   bool searchEvent_;
0067   unsigned orbitNum_;
0068   unsigned searchStartBx_;
0069   unsigned searchStopBx_;
0070 
0071   // utils
0072   bool skipEmptyBx_;
0073 };
0074 // -----------------------------------------------------------------------------
0075 
0076 // -------------------------------- constructor  -------------------------------
0077 
0078 DumpScObjects::DumpScObjects(const edm::ParameterSet& iConfig)
0079     : minBx_(iConfig.getUntrackedParameter<unsigned>("minBx", 0)),
0080       maxBx_(iConfig.getUntrackedParameter<unsigned>("maxBx", 3564)),
0081 
0082       checkMuons_(iConfig.getUntrackedParameter<bool>("checkMuons", true)),
0083       checkJets_(iConfig.getUntrackedParameter<bool>("checkJets", true)),
0084       checkEGammas_(iConfig.getUntrackedParameter<bool>("checkEGammas", true)),
0085       checkTaus_(iConfig.getUntrackedParameter<bool>("checkTaus", true)),
0086       checkEtSums_(iConfig.getUntrackedParameter<bool>("checkEtSums", true)),
0087 
0088       searchEvent_(iConfig.getUntrackedParameter<bool>("searchEvent", false)),
0089       orbitNum_(iConfig.getUntrackedParameter<unsigned>("orbitNumber", 0)),
0090       searchStartBx_(iConfig.getUntrackedParameter<unsigned>("searchStartBx", 0)),
0091       searchStopBx_(iConfig.getUntrackedParameter<unsigned>("searchStopBx", 0)),
0092 
0093       skipEmptyBx_(iConfig.getUntrackedParameter<bool>("skipEmptyBx", true)) {
0094   if (checkMuons_)
0095     gmtMuonsToken_ = consumes<MuonOrbitCollection>(iConfig.getParameter<edm::InputTag>("gmtMuonsTag"));
0096   if (checkJets_)
0097     caloJetsToken_ = consumes<JetOrbitCollection>(iConfig.getParameter<edm::InputTag>("caloJetsTag"));
0098   if (checkEGammas_)
0099     caloEGammasToken_ = consumes<EGammaOrbitCollection>(iConfig.getParameter<edm::InputTag>("caloEGammasTag"));
0100   if (checkTaus_)
0101     caloTausToken_ = consumes<TauOrbitCollection>(iConfig.getParameter<edm::InputTag>("caloTausTag"));
0102   if (checkEtSums_)
0103     caloEtSumsToken_ = consumes<BxSumsOrbitCollection>(iConfig.getParameter<edm::InputTag>("caloEtSumsTag"));
0104 }
0105 // -----------------------------------------------------------------------------
0106 
0107 // ----------------------- method called for each orbit  -----------------------
0108 void DumpScObjects::analyze(const edm::Event& iEvent, const edm::EventSetup& evSetup) {
0109   if (checkMuons_)
0110     iEvent.getByToken(gmtMuonsToken_, muonHandle_);
0111   if (checkJets_)
0112     iEvent.getByToken(caloJetsToken_, jetHandle_);
0113   if (checkEGammas_)
0114     iEvent.getByToken(caloEGammasToken_, eGammaHandle_);
0115   if (checkTaus_)
0116     iEvent.getByToken(caloTausToken_, tauHandle_);
0117   if (checkEtSums_)
0118     iEvent.getByToken(caloEtSumsToken_, etSumHandle_);
0119 
0120   // get the orbit number
0121   unsigned currOrbit = iEvent.id().event();
0122 
0123   // if we are looking for a specific orbit
0124   if (searchEvent_) {
0125     if (currOrbit != orbitNum_)
0126       return;
0127 
0128     // found the orbit
0129     for (unsigned bx = searchStartBx_; bx <= searchStopBx_; bx++) {
0130       printBx(bx);
0131     }
0132   } else {
0133     if (skipEmptyBx_) {
0134       // create a set of non empty BXs
0135       std::set<unsigned> uniqueBx;
0136 
0137       if (checkMuons_) {
0138         for (const unsigned& bx : muonHandle_->getFilledBxs()) {
0139           if ((bx >= minBx_) || (bx <= maxBx_))
0140             uniqueBx.insert(bx);
0141         }
0142       }
0143       if (checkJets_) {
0144         for (const unsigned& bx : jetHandle_->getFilledBxs()) {
0145           if ((bx >= minBx_) || (bx <= maxBx_))
0146             uniqueBx.insert(bx);
0147         }
0148       }
0149       if (checkEGammas_) {
0150         for (const unsigned& bx : eGammaHandle_->getFilledBxs()) {
0151           if ((bx >= minBx_) || (bx <= maxBx_))
0152             uniqueBx.insert(bx);
0153         }
0154       }
0155       if (checkTaus_) {
0156         for (const unsigned& bx : tauHandle_->getFilledBxs()) {
0157           if ((bx >= minBx_) || (bx <= maxBx_))
0158             uniqueBx.insert(bx);
0159         }
0160       }
0161       if (checkEtSums_) {
0162         for (const unsigned& bx : etSumHandle_->getFilledBxs()) {
0163           if ((bx >= minBx_) || (bx <= maxBx_))
0164             uniqueBx.insert(bx);
0165         }
0166       }
0167 
0168       // process bx
0169       for (const unsigned& bx : uniqueBx) {
0170         printBx(bx);
0171       }
0172 
0173     } else {
0174       // dump all objects
0175       for (unsigned bx = minBx_; bx <= maxBx_; bx++) {
0176         printBx(bx);
0177       }
0178     }
0179   }
0180 }
0181 // -----------------------------------------------------------------------------
0182 
0183 void DumpScObjects::printBx(unsigned bx) {
0184   std::cout << "BX = " << bx << " ****" << std::endl;
0185 
0186   if (checkMuons_ && muonHandle_.isValid()) {
0187     int i = 0;
0188     const auto& muons = muonHandle_->bxIterator(bx);
0189     for (const auto& muon : muons) {
0190       std::cout << "--- Muon " << i << " ---\n";
0191       printMuon(muon);
0192       i++;
0193     }
0194   }
0195 
0196   if (checkJets_ && jetHandle_.isValid()) {
0197     int i = 0;
0198     const auto& jets = jetHandle_->bxIterator(bx);
0199     for (const auto& jet : jets) {
0200       std::cout << "--- Jet " << i << " ---\n";
0201       printJet(jet);
0202       i++;
0203     }
0204   }
0205 
0206   if (checkEGammas_ && jetHandle_.isValid()) {
0207     int i = 0;
0208     const auto& eGammas = eGammaHandle_->bxIterator(bx);
0209     for (const auto& egamma : eGammas) {
0210       std::cout << "--- E/Gamma " << i << " ---\n";
0211       printEGamma(egamma);
0212       i++;
0213     }
0214   }
0215 
0216   if (checkTaus_ && tauHandle_.isValid()) {
0217     int i = 0;
0218     const auto& taus = tauHandle_->bxIterator(bx);
0219     for (const auto& tau : taus) {
0220       std::cout << "--- Tau " << i << " ---\n";
0221       printTau(tau);
0222       i++;
0223     }
0224   }
0225 
0226   if (checkEtSums_ && etSumHandle_.isValid()) {
0227     const auto& sums = etSumHandle_->bxIterator(bx);
0228     for (const auto& sum : sums) {
0229       std::cout << "--- Calo Sums ---\n";
0230       printBxSums(sum);
0231     }
0232   }
0233 }
0234 
0235 DEFINE_FWK_MODULE(DumpScObjects);