Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Saving score as part of AXOL1TL Emulator #45227

Merged
merged 8 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions DataFormats/L1TGlobal/interface/AXOL1TLScore.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#ifndef DataFormats_L1TGlobal_AXOL1TLScore_h
#define DataFormats_L1TGlobal_AXOL1TLScore_h
quinnanm marked this conversation as resolved.
Show resolved Hide resolved

/**
* \class AXOL1TLScore
*
*
* Description: L1 micro Global Trigger - Extra NN score emulation information for AXOL1TL.
*
*
* \author: Melissa Quinnan - UC San Diego
*
*
*/

// system include files
#include <vector>
#include <iostream>
#include <iomanip>

// user include files
#include "FWCore/Utilities/interface/typedefs.h"
#include "DataFormats/L1Trigger/interface/L1Candidate.h"
#include "DataFormats/L1Trigger/interface/BXVector.h"
#include "DataFormats/L1Trigger/interface/L1TObjComparison.h"

// forward declarations

// namespace l1t {
class AXOL1TLScore;
typedef BXVector<AXOL1TLScore> AXOL1TLScoreBxCollection;

typedef l1t::ObjectRef<AXOL1TLScore> AXOL1TLScoreRef;
typedef l1t::ObjectRefBxCollection<AXOL1TLScore> AXOL1TLScoreRefBxCollection;
// typedef l1t::ObjectRefPair<AXOL1TLScore> AXOL1TLScoreRefPair;
// typedef l1t::ObjectRefPairBxCollection<AXOL1TLScore> AXOL1TLScoreRefPairBxCollection; //dont think pair part is needed

// class interface
class AXOL1TLScore {
public:
/// constructors
AXOL1TLScore(); //empty constructor

AXOL1TLScore(int bxInEvent);

AXOL1TLScore(int bxInEvent, float score);

/// destructor
virtual ~AXOL1TLScore();

///set/get axo score and other simple members
void setAXOScore(float score) { axoscore_ = score; }
void setbxInEventNr(int bxNr) { m_bxInEvent = bxNr; }

inline float const& getAXOScore() const { return axoscore_; }
inline const int getbxInEventNr() const { return m_bxInEvent; }
quinnanm marked this conversation as resolved.
Show resolved Hide resolved

void reset();

private:
/// bunch cross in the GT event record (E,F,0,1,2)
int m_bxInEvent;

//axo score value
float axoscore_;

//store version or type of network?
// std::string nnversion;
};
//} l1t namespace
#endif /*DataFormats_L1TGlobal_AXOL1TLScore_h*/
28 changes: 28 additions & 0 deletions DataFormats/L1TGlobal/src/AXOL1TLScore.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* \class AXOL1TLScore
*
*
*
* \author: Melissa Quinnan -- UC San Diego
*
*
*/

// this class header
#include "DataFormats/L1TGlobal/interface/AXOL1TLScore.h"

void AXOL1TLScore::reset() {
axoscore_ = 0.0;
m_bxInEvent = 0;
}

AXOL1TLScore::AXOL1TLScore() { reset(); }

AXOL1TLScore::AXOL1TLScore(int bxInEvent) : m_bxInEvent(bxInEvent) { axoscore_ = 0.0; }

AXOL1TLScore::AXOL1TLScore(int bxInEvent, float score) : m_bxInEvent(bxInEvent), axoscore_(score) {}

//destructor
AXOL1TLScore::~AXOL1TLScore() {
//empty
}
1 change: 1 addition & 0 deletions DataFormats/L1TGlobal/src/classes.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "DataFormats/Common/interface/Wrapper.h"
#include "DataFormats/L1TGlobal/interface/GlobalAlgBlk.h"
#include "DataFormats/L1TGlobal/interface/GlobalExtBlk.h"
#include "DataFormats/L1TGlobal/interface/AXOL1TLScore.h"
#include "DataFormats/L1TGlobal/interface/GlobalObjectMapRecord.h"
#include "DataFormats/L1TGlobal/interface/GlobalObjectMapFwd.h"
#include "DataFormats/L1TGlobal/interface/GlobalObjectMap.h"
Expand Down
12 changes: 12 additions & 0 deletions DataFormats/L1TGlobal/src/classes_def.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@
<class name="edm::Wrapper<GlobalExtBlkBxCollection>"/>
<class name="std::vector<GlobalExtBlk>"/>

<class name="AXOL1TLScore" ClassVersion="3">
<version ClassVersion="3" checksum="1744705474"/>
</class>
<class name="AXOL1TLScoreBxCollection"/>
<class name="edm::Wrapper<AXOL1TLScoreBxCollection>"/>
<class name="std::vector<AXOL1TLScore>"/>

<class name="GlobalObjectMapRecord" ClassVersion="10">
<version ClassVersion="10" checksum="1219328086"/>
</class>
Expand Down Expand Up @@ -55,6 +62,11 @@
<class name="GlobalAlgBlkRefPairBxCollection"/>
<class name="edm::Wrapper<GlobalAlgBlkRefPairBxCollection>"/>

<class name="AXOL1TLScoreRef"/>
<class name="std::vector<AXOL1TLScoreRef>"/>
<class name="AXOL1TLScoreRefBxCollection"/>
<class name="edm::Wrapper<AXOL1TLScoreRefBxCollection>"/>

</lcgdict>


Expand Down
8 changes: 8 additions & 0 deletions L1Trigger/L1TGlobal/interface/AXOL1TLCondition.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ namespace l1t {

void setuGtB(const GlobalBoard*);

/// get/set score value
void setScore(const float scoreval) const;

inline float getScore() const { return m_savedscore; }

private:
/// copy function for copy constructor and operator=
void copy(const AXOL1TLCondition& cp);
Expand All @@ -68,6 +73,9 @@ namespace l1t {

/// pointer to uGt GlobalBoard, to be able to get the trigger objects
const GlobalBoard* m_gtGTB;

///axo score for possible score saving
mutable float m_savedscore;
quinnanm marked this conversation as resolved.
Show resolved Hide resolved
};

} // namespace l1t
Expand Down
10 changes: 10 additions & 0 deletions L1Trigger/L1TGlobal/interface/GlobalBoard.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
// Objects to produce for the output record.
#include "DataFormats/L1TGlobal/interface/GlobalAlgBlk.h"
#include "DataFormats/L1TGlobal/interface/GlobalExtBlk.h"
#include "DataFormats/L1TGlobal/interface/AXOL1TLScore.h"

#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
Expand Down Expand Up @@ -90,6 +91,8 @@ namespace l1t {

void receiveExternalData(const edm::Event&, const edm::EDGetTokenT<BXVector<GlobalExtBlk>>&, const bool receiveExt);

void fillAXOScore(int iBxInEvent, std::unique_ptr<AXOL1TLScoreBxCollection>& AxoScoreRecord);

/// initialize the class (mainly reserve)
void init(const int numberPhysTriggers,
const int nrL1Mu,
Expand Down Expand Up @@ -207,6 +210,8 @@ namespace l1t {
public:
inline void setVerbosity(const int verbosity) { m_verbosity = verbosity; }

inline void enableAXOScoreSaving(bool savescore) { m_saveAXOScore = savescore; }

private:
// cached stuff

Expand Down Expand Up @@ -247,6 +252,11 @@ namespace l1t {

GlobalAlgBlk m_uGtAlgBlk;

//for optional software-only saving of axol1tl score
AXOL1TLScore m_uGtAXOScore; //score dataformat
float m_storedAXOScore = -999.0; //score from cond class
bool m_saveAXOScore = false;

// cache of maps
std::vector<AlgorithmEvaluation::ConditionEvaluationMap> m_conditionResultMaps;

Expand Down
27 changes: 26 additions & 1 deletion L1Trigger/L1TGlobal/plugins/L1TGlobalProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "DataFormats/L1TGlobal/interface/GlobalAlgBlk.h"
#include "DataFormats/L1TGlobal/interface/GlobalExtBlk.h"
#include "DataFormats/L1TGlobal/interface/GlobalObjectMapRecord.h"
#include "DataFormats/L1TGlobal/interface/AXOL1TLScore.h"

#include "L1Trigger/L1TGlobal/interface/TriggerMenu.h"

Expand Down Expand Up @@ -71,6 +72,9 @@ void L1TGlobalProducer::fillDescriptions(edm::ConfigurationDescriptions& descrip
// switch for muon showers in Run-3
desc.add<bool>("useMuonShowers", false);

//switch for saving AXO score
desc.add<bool>("produceAXOL1TLScore", true);

// disables resetting the prescale counters each lumisection (needed for offline)
// originally, the L1T firmware applied the reset of prescale counters at the end of every LS;
// this reset was disabled in the L1T firmware starting from run-362658 (November 25th, 2022), see
Expand Down Expand Up @@ -107,6 +111,7 @@ L1TGlobalProducer::L1TGlobalProducer(const edm::ParameterSet& parSet)
m_sumInputTag(parSet.getParameter<edm::InputTag>("EtSumInputTag")),
m_sumZdcInputTag(parSet.getParameter<edm::InputTag>("EtSumZdcInputTag")),
m_extInputTag(parSet.getParameter<edm::InputTag>("ExtInputTag")),
m_axoInputTag(parSet.getParameter<edm::InputTag>("AxoScoreInputTag")),
quinnanm marked this conversation as resolved.
Show resolved Hide resolved

m_produceL1GtDaqRecord(parSet.getParameter<bool>("ProduceL1GtDaqRecord")),
m_produceL1GtObjectMapRecord(parSet.getParameter<bool>("ProduceL1GtObjectMapRecord")),
Expand All @@ -130,7 +135,8 @@ L1TGlobalProducer::L1TGlobalProducer(const edm::ParameterSet& parSet)
m_algoblkInputTag(parSet.getParameter<edm::InputTag>("AlgoBlkInputTag")),
m_resetPSCountersEachLumiSec(parSet.getParameter<bool>("resetPSCountersEachLumiSec")),
m_semiRandomInitialPSCounters(parSet.getParameter<bool>("semiRandomInitialPSCounters")),
m_useMuonShowers(parSet.getParameter<bool>("useMuonShowers")) {
m_useMuonShowers(parSet.getParameter<bool>("useMuonShowers")),
m_produceAXOL1TLScore(parSet.getParameter<bool>("produceAXOL1TLScore")) {
m_egInputToken = consumes<BXVector<EGamma>>(m_egInputTag);
m_tauInputToken = consumes<BXVector<Tau>>(m_tauInputTag);
m_jetInputToken = consumes<BXVector<Jet>>(m_jetInputTag);
Expand Down Expand Up @@ -208,6 +214,10 @@ L1TGlobalProducer::L1TGlobalProducer(const edm::ParameterSet& parSet)
produces<GlobalObjectMapRecord>();
}

if (m_produceAXOL1TLScore) {
produces<AXOL1TLScoreBxCollection>("AXOScore");
}

// create new uGt Board
m_uGtBrd = std::make_unique<GlobalBoard>();
m_uGtBrd->setVerbosity(m_verbosity);
Expand Down Expand Up @@ -556,6 +566,9 @@ void L1TGlobalProducer::produce(edm::Event& iEvent, const edm::EventSetup& evSet
// * produce the GlobalObjectMapRecord
std::unique_ptr<GlobalObjectMapRecord> gtObjectMapRecord(new GlobalObjectMapRecord());

// if (m_produceAXOL1TLScore)
std::unique_ptr<AXOL1TLScoreBxCollection> uGtAXOScoreRecord(new AXOL1TLScoreBxCollection());
quinnanm marked this conversation as resolved.
Show resolved Hide resolved

// fill the boards not depending on the BxInEvent in the L1 GT DAQ record
// GMT, PSB and FDL depend on BxInEvent

Expand Down Expand Up @@ -624,6 +637,9 @@ void L1TGlobalProducer::produce(edm::Event& iEvent, const edm::EventSetup& evSet
if (m_useMuonShowers)
m_uGtBrd->receiveMuonShowerObjectData(iEvent, m_muShowerInputToken, receiveMuShower, m_nrL1MuShower);

//tell board to save axo scores when running GTL
m_uGtBrd->enableAXOScoreSaving(m_produceAXOL1TLScore);

m_uGtBrd->receiveExternalData(iEvent, m_extInputToken, receiveExt);

// loop over BxInEvent
Expand Down Expand Up @@ -668,6 +684,11 @@ void L1TGlobalProducer::produce(edm::Event& iEvent, const edm::EventSetup& evSet
m_l1GtMenu->gtTriggerMenuImplementation());
}

//save scores to score collection
if (m_produceAXOL1TLScore) {
m_uGtBrd->fillAXOScore(iBxInEvent, uGtAXOScoreRecord);
}

} //End Loop over Bx

// Add explicit reset of Board
Expand Down Expand Up @@ -710,6 +731,10 @@ void L1TGlobalProducer::produce(edm::Event& iEvent, const edm::EventSetup& evSet
if (m_produceL1GtObjectMapRecord) {
iEvent.put(std::move(gtObjectMapRecord));
}

if (m_produceAXOL1TLScore) {
iEvent.put(std::move(uGtAXOScoreRecord), "AXOScore");
}
}

//define this as a plug-in
Expand Down
7 changes: 7 additions & 0 deletions L1Trigger/L1TGlobal/plugins/L1TGlobalProducer.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ class L1TGlobalProducer : public edm::stream::EDProducer<> {
edm::InputTag m_extInputTag;
edm::EDGetTokenT<BXVector<GlobalExtBlk>> m_extInputToken;

// input tag for saving axol1tl scores
edm::InputTag m_axoInputTag;
edm::EDGetTokenT<BXVector<AXOL1TLScore>> m_axoInputToken;

quinnanm marked this conversation as resolved.
Show resolved Hide resolved
/// logical flag to produce the L1 GT DAQ readout record
bool m_produceL1GtDaqRecord;

Expand Down Expand Up @@ -197,6 +201,9 @@ class L1TGlobalProducer : public edm::stream::EDProducer<> {

// switch to load muon showers in the global board
bool m_useMuonShowers;

//switch to save axo scores in global board
bool m_produceAXOL1TLScore;
};

#endif // L1TGlobalProducer_h
5 changes: 5 additions & 0 deletions L1Trigger/L1TGlobal/src/AXOL1TLCondition.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ void l1t::AXOL1TLCondition::setGtAXOL1TLTemplate(const AXOL1TLTemplate* caloTemp
/// set the pointer to uGT GlobalBoard
void l1t::AXOL1TLCondition::setuGtB(const GlobalBoard* ptrGTB) { m_gtGTB = ptrGTB; }

/// set score for score saving
void l1t::AXOL1TLCondition::setScore(const float scoreval) const { m_savedscore = scoreval; }

const bool l1t::AXOL1TLCondition::evaluateCondition(const int bxEval) const {
bool condResult = false;
int useBx = bxEval + m_gtAXOL1TLTemplate->condRelativeBx();
Expand Down Expand Up @@ -236,6 +239,8 @@ const bool l1t::AXOL1TLCondition::evaluateCondition(const int bxEval) const {
result = ADModelResult.first;
loss = ADModelResult.second;
score = ((loss).to_float()) * 16.0; //scaling to match threshold
//save score to class variable in case score saving needed
setScore(score);

//number of objects/thrsholds to check
int iCondition = 0; // number of conditions: there is only one
Expand Down
27 changes: 27 additions & 0 deletions L1Trigger/L1TGlobal/src/GlobalBoard.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ l1t::GlobalBoard::GlobalBoard()
m_currentLumi(0),
m_isDebugEnabled(edm::isDebugEnabled()) {
m_uGtAlgBlk.reset();
m_uGtAXOScore.reset();

m_gtlAlgorithmOR.reset();
m_gtlDecisionWord.reset();
Expand Down Expand Up @@ -492,6 +493,22 @@ void l1t::GlobalBoard::receiveExternalData(const edm::Event& iEvent,
} //end if ReceiveExt data
}

// fill axo score value per bx in event
void l1t::GlobalBoard::fillAXOScore(int iBxInEvent, std::unique_ptr<AXOL1TLScoreBxCollection>& AxoScoreRecord) {
m_uGtAXOScore.reset();
m_uGtAXOScore.setbxInEventNr((iBxInEvent & 0xF));

//save stored condition score if Bx is zero, else set to 0
float scorevalue = 0.0;
if (iBxInEvent == 0) {
quinnanm marked this conversation as resolved.
Show resolved Hide resolved
scorevalue = m_storedAXOScore;
}

//set dataformat value
m_uGtAXOScore.setAXOScore(scorevalue);
AxoScoreRecord->push_back(iBxInEvent, m_uGtAXOScore);
}

// run GTL
void l1t::GlobalBoard::runGTL(const edm::Event&,
const edm::EventSetup& evSetup,
Expand Down Expand Up @@ -655,6 +672,12 @@ void l1t::GlobalBoard::runGTL(const edm::Event&,

cMapResults[itCond->first] = axol1tlCondition;

//for optional software-only saving of axol1tl score
//m_storedAXOScore < 0.0 ensures only sets once per condition if score not default of -999
if (m_saveAXOScore && m_storedAXOScore < 0.0) {
m_storedAXOScore = axol1tlCondition->getScore();
quinnanm marked this conversation as resolved.
Show resolved Hide resolved
}

if (m_verbosity && m_isDebugEnabled) {
std::ostringstream myCout;
axol1tlCondition->print(myCout);
Expand Down Expand Up @@ -1154,6 +1177,10 @@ void l1t::GlobalBoard::reset() {

m_uGtAlgBlk.reset();

//reset AXO score
m_storedAXOScore = -999.0;
m_uGtAXOScore.reset();

m_gtlDecisionWord.reset();
m_gtlAlgorithmOR.reset();
}
Expand Down
Loading