Skip to content

Commit

Permalink
Merge pull request #45605 from max-zhao0/from-CMSSW_14_1_0_pre5
Browse files Browse the repository at this point in the history
Add L1TCaloLayer1Summary and necessary changes to emulator
  • Loading branch information
cmsbuild authored Aug 29, 2024
2 parents ab08a21 + 83fe29e commit a08cd11
Show file tree
Hide file tree
Showing 8 changed files with 270 additions and 3 deletions.
74 changes: 74 additions & 0 deletions DQM/L1TMonitor/interface/L1TCaloLayer1Summary.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// -*- C++ -*-
//
// Package: L1TMonitor/L1TCaloLayer1Summary
// Class: L1TCaloLayer1Summary
//
/**\class L1TCaloLayer1Summary L1TCaloLayer1Summary.cc Demo/L1TCaloLayer1Summary/plugins/L1TCaloLayer1Summary.cc
Description: DQM Analyzer for CaloLayer1 regions and CICADAScore
Implementation:
This module uses emulator sequence for CaloLayer1.
*/
//
// Original Author: Max Zhao <max.zhao@princeton.edu>
// Created: 31 Jul 2024
//
//

// system include files
#include <memory>
#include <string>

#include "DQMServices/Core/interface/DQMStore.h"
#include "DQMServices/Core/interface/DQMEDAnalyzer.h"

// user include files
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/one/EDAnalyzer.h"

#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"

#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Utilities/interface/InputTag.h"

#include "FWCore/ServiceRegistry/interface/Service.h"

#include "DataFormats/L1CaloTrigger/interface/CICADA.h"
#include "DataFormats/L1CaloTrigger/interface/L1CaloCollections.h"
#include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
#include "EventFilter/L1TXRawToDigi/interface/UCTDAQRawData.h"
#include "EventFilter/L1TXRawToDigi/interface/UCTAMCRawData.h"
#include "DataFormats/FEDRawData/interface/FEDNumbering.h"

class L1TCaloLayer1Summary : public DQMEDAnalyzer {
public:
explicit L1TCaloLayer1Summary(const edm::ParameterSet&);

static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);

private:
void analyze(const edm::Event&, const edm::EventSetup&) override;
void bookHistograms(DQMStore::IBooker&, const edm::Run&, const edm::EventSetup&) override;

// ----------member data ---------------------------
edm::EDGetTokenT<l1t::CICADABxCollection> caloLayer1CICADAScoreToken_;
edm::EDGetTokenT<l1t::CICADABxCollection> gtCICADAScoreToken_;
edm::EDGetTokenT<l1t::CICADABxCollection> simCICADAScoreToken_;
edm::EDGetTokenT<L1CaloRegionCollection> caloLayer1RegionsToken_;
edm::EDGetTokenT<L1CaloRegionCollection> simRegionsToken_;
edm::EDGetTokenT<FEDRawDataCollection> fedRawData_;

dqm::reco::MonitorElement* histoCaloLayer1CICADAScore;
dqm::reco::MonitorElement* histoGtCICADAScore;
dqm::reco::MonitorElement* histoSimCICADAScore;
dqm::reco::MonitorElement* histoCaloMinusSim;
dqm::reco::MonitorElement* histoCaloMinusGt;
dqm::reco::MonitorElement* histoSlot7MinusDaqBxid;
dqm::reco::MonitorElement* histoCaloRegions;
dqm::reco::MonitorElement* histoSimRegions;
dqm::reco::MonitorElement* histoCaloMinusSimRegions;

std::string histFolder_;
};
3 changes: 3 additions & 0 deletions DQM/L1TMonitor/plugins/SealModule.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ DEFINE_FWK_MODULE(L1TGMT);
#include "DQM/L1TMonitor/interface/L1TStage2CaloLayer1.h"
DEFINE_FWK_MODULE(L1TStage2CaloLayer1);

#include "DQM/L1TMonitor/interface/L1TCaloLayer1Summary.h"
DEFINE_FWK_MODULE(L1TCaloLayer1Summary);

#include "DQM/L1TMonitor/interface/L1TStage2CaloLayer2.h"
DEFINE_FWK_MODULE(L1TStage2CaloLayer2);

Expand Down
22 changes: 22 additions & 0 deletions DQM/L1TMonitor/python/L1TCaloLayer1Summary_cff.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import FWCore.ParameterSet.Config as cms

from L1Trigger.Configuration.CaloTriggerPrimitives_cff import *
simEcalTriggerPrimitiveDigis.Label = 'ecalDigis'
simHcalTriggerPrimitiveDigis.inputLabel = cms.VInputTag(
cms.InputTag('hcalDigis'),
cms.InputTag('hcalDigis')
)
simHcalTriggerPrimitiveDigis.inputUpgradeLabel = cms.VInputTag(
cms.InputTag('hcalDigis'),
cms.InputTag('hcalDigis')
)

from L1Trigger.L1TCaloLayer1.simCaloStage2Layer1Summary_cfi import *
from L1Trigger.L1TCaloLayer1.simCaloStage2Layer1Digis_cfi import *
from DQM.L1TMonitor.L1TCaloLayer1Summary_cfi import *

simCaloStage2Layer1Summary.caloLayer1Regions = cms.InputTag("caloLayer1Digis", "")
simCaloStage2Layer1Digis.ecalToken = cms.InputTag("ecalDigis", "EcalTriggerPrimitives")
simCaloStage2Layer1Digis.hcalToken = cms.InputTag("hcalDigis", "")

l1tCaloLayer1SummarySeq = cms.Sequence(simEcalTriggerPrimitiveDigis * simHcalTriggerPrimitiveDigis * simCaloStage2Layer1Digis * simCaloStage2Layer1Summary * l1tCaloLayer1Summary)
12 changes: 12 additions & 0 deletions DQM/L1TMonitor/python/L1TCaloLayer1Summary_cfi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import FWCore.ParameterSet.Config as cms
from DQMServices.Core.DQMEDAnalyzer import DQMEDAnalyzer

l1tCaloLayer1Summary = DQMEDAnalyzer("L1TCaloLayer1Summary",
caloLayer1CICADAScore = cms.InputTag("caloLayer1Digis", "CICADAScore"),
gtCICADAScore = cms.InputTag("gtTestcrateStage2Digis", "CICADAScore"),
simCICADAScore = cms.InputTag("simCaloStage2Layer1Summary", "CICADAScore"),
caloLayer1Regions = cms.InputTag("caloLayer1Digis", ""),
simRegions = cms.InputTag("simCaloStage2Layer1Digis", ""),
fedRawDataLabel = cms.InputTag("rawDataCollector"),
histFolder = cms.string('L1T/L1TCaloLayer1Summary')
)
6 changes: 5 additions & 1 deletion DQM/L1TMonitor/python/L1TStage2_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
# CaloLayer2
from DQM.L1TMonitor.L1TStage2CaloLayer2_cfi import *

# CaloLayer1Summary
from DQM.L1TMonitor.L1TCaloLayer1Summary_cff import *

# BMTF
from DQM.L1TMonitor.L1TStage2BMTF_cff import *

Expand Down Expand Up @@ -47,7 +50,8 @@
l1tStage2RegionalShower +
l1tStage2uGMTOnlineDQMSeq +
l1tObjectsTiming +
l1tStage2uGTOnlineDQMSeq
l1tStage2uGTOnlineDQMSeq +
l1tCaloLayer1SummarySeq
)

# sequence to run only for validation events
Expand Down
143 changes: 143 additions & 0 deletions DQM/L1TMonitor/src/L1TCaloLayer1Summary.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
#include "DQM/L1TMonitor/interface/L1TCaloLayer1Summary.h"

L1TCaloLayer1Summary::L1TCaloLayer1Summary(const edm::ParameterSet& iConfig)
: caloLayer1CICADAScoreToken_(
consumes<l1t::CICADABxCollection>(iConfig.getParameter<edm::InputTag>("caloLayer1CICADAScore"))),
gtCICADAScoreToken_(consumes<l1t::CICADABxCollection>(iConfig.getParameter<edm::InputTag>("gtCICADAScore"))),
simCICADAScoreToken_(consumes<l1t::CICADABxCollection>(iConfig.getParameter<edm::InputTag>("simCICADAScore"))),
caloLayer1RegionsToken_(
consumes<L1CaloRegionCollection>(iConfig.getParameter<edm::InputTag>("caloLayer1Regions"))),
simRegionsToken_(consumes<L1CaloRegionCollection>(iConfig.getParameter<edm::InputTag>("simRegions"))),
fedRawData_(consumes<FEDRawDataCollection>(iConfig.getParameter<edm::InputTag>("fedRawDataLabel"))),
histFolder_(iConfig.getParameter<std::string>("histFolder")) {}

// ------------ method called for each event ------------
void L1TCaloLayer1Summary::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
edm::Handle<FEDRawDataCollection> fedRawDataCollection;
iEvent.getByToken(fedRawData_, fedRawDataCollection);
if (fedRawDataCollection.isValid()) {
for (int iFed = FEDNumbering::MINRCTFEDID + 4; iFed < FEDNumbering::MAXRCTFEDID; iFed += 2) {
const FEDRawData& fedRawData = fedRawDataCollection->FEDData(iFed);
if (fedRawData.size() == 0) {
continue;
}
const uint64_t* fedRawDataArray = (const uint64_t*)fedRawData.data();
UCTDAQRawData daqData(fedRawDataArray);

if (daqData.nAMCs() == 7) {
UCTAMCRawData amcSlot7(daqData.amcPayload(3));
if (amcSlot7.amcNo() == 7) {
histoSlot7MinusDaqBxid->Fill(amcSlot7.BXID() - daqData.BXID());
}
}
}
}

L1CaloRegionCollection caloLayer1Regions = iEvent.get(caloLayer1RegionsToken_);
L1CaloRegionCollection simRegions = iEvent.get(simRegionsToken_);
int nRegions = caloLayer1Regions.size();

unsigned int maxEtaIdx = 0;
for (int iRegion = 0; iRegion < nRegions; iRegion++) {
if (maxEtaIdx < caloLayer1Regions[iRegion].gctEta()) {
maxEtaIdx = caloLayer1Regions[iRegion].gctEta();
}
}
int matrixSize = maxEtaIdx + 1;

bool foundMatrix[2][matrixSize][matrixSize];
int etMatrix[2][matrixSize][matrixSize];
for (int i = 0; i < 2; i++) {
for (int j = 0; j < matrixSize; j++) {
for (int k = 0; k < matrixSize; k++) {
foundMatrix[i][j][k] = false;
etMatrix[i][j][k] = 0;
}
}
}

for (int iRegion = 0; iRegion < nRegions; iRegion++) {
L1CaloRegion cRegion = caloLayer1Regions[iRegion];
L1CaloRegion sRegion = simRegions[iRegion];

foundMatrix[0][cRegion.gctEta()][cRegion.gctPhi()] = true;
etMatrix[0][cRegion.gctEta()][cRegion.gctPhi()] = cRegion.et();
foundMatrix[1][sRegion.gctEta()][sRegion.gctPhi()] = true;
etMatrix[1][sRegion.gctEta()][sRegion.gctPhi()] = sRegion.et();
}
int iRegion = 0;
for (int iEta = 0; iEta < matrixSize; iEta++) {
for (int iPhi = 0; iPhi < matrixSize; iPhi++) {
if (foundMatrix[0][iEta][iPhi] && foundMatrix[1][iEta][iPhi]) {
histoCaloRegions->Fill(iRegion, etMatrix[0][iEta][iPhi]);
histoSimRegions->Fill(iRegion, etMatrix[1][iEta][iPhi]);
histoCaloMinusSimRegions->Fill(iRegion, etMatrix[0][iEta][iPhi] - etMatrix[1][iEta][iPhi]);
iRegion++;
}
}
}

auto caloCICADAScores = iEvent.get(caloLayer1CICADAScoreToken_);
auto gtCICADAScores = iEvent.get(gtCICADAScoreToken_);
auto simCICADAScores = iEvent.get(simCICADAScoreToken_);

if (caloCICADAScores.size() > 0) {
histoCaloLayer1CICADAScore->Fill(caloCICADAScores[0]);
if (gtCICADAScores.size() > 0) {
histoGtCICADAScore->Fill(gtCICADAScores.at(0, 0));
histoCaloMinusGt->Fill(caloCICADAScores[0] - gtCICADAScores.at(0, 0));
}
if (simCICADAScores.size() > 0) {
histoSimCICADAScore->Fill(simCICADAScores[0]);
histoCaloMinusSim->Fill(caloCICADAScores[0] - simCICADAScores[0]);
}
}
}

void L1TCaloLayer1Summary::bookHistograms(DQMStore::IBooker& ibooker, edm::Run const&, edm::EventSetup const&) {
ibooker.setCurrentFolder(histFolder_);
histoSlot7MinusDaqBxid = ibooker.book1D("slot7BXID", "Slot 7- DAQ BXID", 50, -20, 20);

ibooker.setCurrentFolder(histFolder_ + "/CICADAScore");
histoCaloLayer1CICADAScore = ibooker.book1D("caloLayer1CICADAScore", "CaloLayer1 CICADAScore", 50, 0, 200);
histoGtCICADAScore = ibooker.book1D("gtCICADAScore", "GT CICADAScore at BX0", 50, 0, 200);
histoCaloMinusGt = ibooker.book1D("caloMinusGtCICADAScore", "CaloLayer1 - GT CICADAScore at BX0", 50, -50, 50);
histoSimCICADAScore =
ibooker.book1D("simCaloLayer1CICADAScore", "simCaloLayer1 CICADAScore (input: DAQ regions)", 50, 0, 200);
histoCaloMinusSim = ibooker.book1D(
"caloMinusSimCICADAScore", "CaloLayer1 - simCaloLayer1 (input: DAQ regions) CICADAScore", 50, -50, 50);

ibooker.setCurrentFolder(histFolder_ + "/Regions");
histoCaloMinusSimRegions =
ibooker.book2D("caloMinusSumRegions",
"CaloLayer1 - simCaloLayer1 (input: DAQ trigger primatives) Regions;Region;ET Difference",
252,
-0.5,
252.5,
100,
-400,
400);
histoCaloRegions = ibooker.book2D("caloLayer1Regions", "CaloLayer1 Regions;Region;ET", 252, -0.5, 252.5, 100, 0, 800);
histoSimRegions = ibooker.book2D("simCaloLayer1Regions",
"simCaloLayer1 Regions (input: DAQ trigger primatives);Region;ET",
252,
-0.5,
252.5,
100,
0,
800);
}

// ------------ method fills 'descriptions' with the allowed parameters for the module ------------
void L1TCaloLayer1Summary::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
// l1tCaloLayer1Summary
edm::ParameterSetDescription desc;
desc.add<edm::InputTag>("caloLayer1CICADAScore", edm::InputTag("caloLayer1Digis", "CICADAScore"));
desc.add<edm::InputTag>("gtCICADAScore", edm::InputTag("gtTestcrateStage2Digis", "CICADAScore"));
desc.add<edm::InputTag>("simCICADAScore", edm::InputTag("simCaloStage2Layer1Summary", "CICADAScore"));
desc.add<edm::InputTag>("caloLayer1Regions", edm::InputTag("caloLayer1Digis"));
desc.add<edm::InputTag>("simRegions", edm::InputTag("simCaloStage2Layer1Digis"));
desc.add<edm::InputTag>("fedRawDataLabel", edm::InputTag("rawDataCollector"));
desc.add<std::string>("histFolder", "L1T/L1TCaloLayer1Summary");
descriptions.add("l1tCaloLayer1Summary", desc);
}
10 changes: 9 additions & 1 deletion L1Trigger/L1TCaloLayer1/plugins/L1TCaloSummary.cc
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ class L1TCaloSummary : public edm::stream::EDProducer<> {
int fwVersion;

edm::EDGetTokenT<L1CaloRegionCollection> regionToken;
edm::EDGetTokenT<L1CaloRegionCollection> backupRegionToken;

UCTLayer1* layer1;

Expand Down Expand Up @@ -141,7 +142,8 @@ L1TCaloSummary<INPUT, OUTPUT>::L1TCaloSummary(const edm::ParameterSet& iConfig)
boostedJetPtFactor(iConfig.getParameter<double>("boostedJetPtFactor")),
verbose(iConfig.getParameter<bool>("verbose")),
fwVersion(iConfig.getParameter<int>("firmwareVersion")),
regionToken(consumes<L1CaloRegionCollection>(edm::InputTag("simCaloStage2Layer1Digis"))),
regionToken(consumes<L1CaloRegionCollection>(iConfig.getParameter<edm::InputTag>("caloLayer1Regions"))),
backupRegionToken(consumes<L1CaloRegionCollection>(edm::InputTag("simCaloStage2Layer1Digis"))),
loader(hls4mlEmulator::ModelLoader(iConfig.getParameter<string>("CICADAModelVersion"))),
overwriteWithTestPatterns(iConfig.getParameter<bool>("useTestPatterns")),
testPatterns(iConfig.getParameter<std::vector<edm::ParameterSet>>("testPatterns")) {
Expand Down Expand Up @@ -198,6 +200,12 @@ void L1TCaloSummary<INPUT, OUTPUT>::produce(edm::Event& iEvent, const edm::Event
if (!iEvent.getByToken(regionToken, regionCollection))
edm::LogError("L1TCaloSummary") << "UCT: Failed to get regions from region collection!";
iEvent.getByToken(regionToken, regionCollection);

if (regionCollection->size() == 0) {
iEvent.getByToken(backupRegionToken, regionCollection);
edm::LogWarning("L1TCaloSummary") << "Switched to emulated regions since data regions was empty.\n";
}

//Model input
//This is done as a flat vector input, but future versions may involve 2D input
//This will have to be handled later
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,6 @@
firmwareVersion = cms.int32(1),
CICADAModelVersion = cms.string("CICADAModel_v2p1p2"),
useTestPatterns = cms.bool(False),
testPatterns = standardCICADATestPatterns
testPatterns = standardCICADATestPatterns,
caloLayer1Regions = cms.InputTag("simCaloStage2Layer1Digis", "")
)

0 comments on commit a08cd11

Please sign in to comment.