File indexing completed on 2024-04-06 12:10:41
0001 #include <memory>
0002 #include <iostream>
0003 #include <TTree.h>
0004
0005 #include "FWCore/Framework/interface/Frameworkfwd.h"
0006 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0007 #include "FWCore/ServiceRegistry/interface/Service.h"
0008 #include "CommonTools/UtilAlgos/interface/TFileService.h"
0009
0010 #include "FWCore/Framework/interface/Event.h"
0011 #include "FWCore/Framework/interface/MakerMacros.h"
0012
0013 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0014 #include "FWCore/Utilities/interface/InputTag.h"
0015 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
0016 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
0017 #include "DataFormats/FEDRawData/interface/FEDTrailer.h"
0018 #include "DataFormats/GEMDigi/interface/GEMDigiCollection.h"
0019
0020 using namespace std;
0021 class GEMPackingTester : public edm::one::EDAnalyzer<edm::one::SharedResources> {
0022 public:
0023 explicit GEMPackingTester(const edm::ParameterSet&);
0024 ~GEMPackingTester() override;
0025
0026 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0027
0028 private:
0029 void beginJob() override;
0030 void analyze(const edm::Event&, const edm::EventSetup&) override;
0031 void endJob() override;
0032
0033 edm::EDGetTokenT<FEDRawDataCollection> fedToken_;
0034 edm::EDGetTokenT<GEMDigiCollection> gemDigiToken_;
0035 edm::EDGetTokenT<GEMDigiCollection> gemSimDigiToken_;
0036 bool readMultiBX_;
0037
0038 TTree* tree_;
0039 int b_ge0, b_ge1, b_ge2;
0040 };
0041
0042 GEMPackingTester::GEMPackingTester(const edm::ParameterSet& iConfig)
0043 : fedToken_(consumes<FEDRawDataCollection>(iConfig.getParameter<edm::InputTag>("fed"))),
0044 gemDigiToken_(consumes<GEMDigiCollection>(iConfig.getParameter<edm::InputTag>("gemDigi"))),
0045 gemSimDigiToken_(consumes<GEMDigiCollection>(iConfig.getParameter<edm::InputTag>("gemSimDigi"))),
0046 readMultiBX_(iConfig.getParameter<bool>("readMultiBX")) {
0047 usesResource("TFileService");
0048 edm::Service<TFileService> fs;
0049 tree_ = fs->make<TTree>("fed", "fed");
0050 tree_->Branch("ge0", &b_ge0, "ge0/I");
0051 tree_->Branch("ge1", &b_ge1, "ge1/I");
0052 tree_->Branch("ge2", &b_ge2, "ge2/I");
0053 }
0054
0055 GEMPackingTester::~GEMPackingTester() {}
0056
0057 void GEMPackingTester::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0058 using namespace edm;
0059
0060 b_ge0 = 0;
0061 b_ge1 = 0;
0062 b_ge2 = 0;
0063
0064 auto const& fed_buffers = iEvent.get(fedToken_);
0065
0066 for (unsigned int fedId = FEDNumbering::MINGEMFEDID; fedId <= FEDNumbering::MAXGEMFEDID; ++fedId) {
0067 const FEDRawData& fedData = fed_buffers.FEDData(fedId);
0068
0069 if (fedId == 1473 or fedId == 1474)
0070 b_ge0 += fedData.size();
0071 if (fedId == 1467 or fedId == 1468)
0072 b_ge1 += fedData.size();
0073 if (fedId == 1469 or fedId == 1470)
0074 b_ge2 += fedData.size();
0075 }
0076
0077 auto const& gemDigis = iEvent.get(gemDigiToken_);
0078 auto const& gemSimDigis = iEvent.get(gemSimDigiToken_);
0079
0080 for (auto const& simDigi : gemSimDigis) {
0081 const GEMDetId& gemId = simDigi.first;
0082 const GEMDigiCollection::Range& sim = simDigi.second;
0083 const GEMDigiCollection::Range& packed = gemDigis.get(gemId);
0084
0085 for (auto digi = sim.first; digi != sim.second; ++digi) {
0086 if (!readMultiBX_ && digi->bx() != 0)
0087 continue;
0088
0089 bool foundDigi = false;
0090 for (auto unpackeddigi = packed.first; unpackeddigi != packed.second; ++unpackeddigi) {
0091 if ((digi->strip() == unpackeddigi->strip()) && (digi->bx() == unpackeddigi->bx()))
0092 foundDigi = true;
0093 }
0094 if (!foundDigi) {
0095 edm::LogInfo("GEMPackingTester") << "simMuonGEMDigi NOT found " << gemId << " " << digi->strip() << " "
0096 << digi->bx();
0097 for (auto unpackeddigi = packed.first; unpackeddigi != packed.second; ++unpackeddigi) {
0098 edm::LogInfo("GEMPackingTester") << "rec " << unpackeddigi->strip() << " " << unpackeddigi->bx();
0099 }
0100 }
0101 }
0102 }
0103
0104 tree_->Fill();
0105 }
0106
0107 void GEMPackingTester::beginJob() {}
0108
0109 void GEMPackingTester::endJob() {}
0110
0111 void GEMPackingTester::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0112 edm::ParameterSetDescription desc;
0113 desc.add<edm::InputTag>("fed", edm::InputTag("rawDataCollector"));
0114 desc.add<edm::InputTag>("gemDigi", edm::InputTag("muonGEMDigis"));
0115 desc.add<edm::InputTag>("gemSimDigi", edm::InputTag("simMuonGEMDigis"));
0116 desc.add<bool>("readMultiBX", false);
0117 descriptions.add("GEMPackingTester", desc);
0118 }
0119
0120 DEFINE_FWK_MODULE(GEMPackingTester);