Skip to content

Commit

Permalink
Merge pull request #45227 from quinnanm/axol1tl_scoresaving_pr
Browse files Browse the repository at this point in the history
Saving score as part of AXOL1TL Emulator
  • Loading branch information
cmsbuild authored Jul 15, 2024
2 parents a61bc4f + d4cba30 commit 5950987
Show file tree
Hide file tree
Showing 13 changed files with 295 additions and 1 deletion.
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

/**
* \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; }

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;
};

} // 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 @@ -92,6 +93,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 @@ -213,6 +216,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 @@ -255,6 +260,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
28 changes: 27 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 @@ -73,6 +74,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", false);

// 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 @@ -133,7 +137,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 @@ -212,6 +217,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 @@ -562,6 +571,11 @@ void L1TGlobalProducer::produce(edm::Event& iEvent, const edm::EventSetup& evSet
// * produce the GlobalObjectMapRecord
std::unique_ptr<GlobalObjectMapRecord> gtObjectMapRecord(new GlobalObjectMapRecord());

std::unique_ptr<AXOL1TLScoreBxCollection> uGtAXOScoreRecord(nullptr);
if (m_produceAXOL1TLScore) {
uGtAXOScoreRecord = std::make_unique<AXOL1TLScoreBxCollection>();
}

// 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 @@ -632,6 +646,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 @@ -676,6 +693,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 @@ -718,6 +740,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
3 changes: 3 additions & 0 deletions L1Trigger/L1TGlobal/plugins/L1TGlobalProducer.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,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 @@ -78,6 +78,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 @@ -519,6 +520,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) {
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 @@ -682,6 +699,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();
}

if (m_verbosity && m_isDebugEnabled) {
std::ostringstream myCout;
axol1tlCondition->print(myCout);
Expand Down Expand Up @@ -1196,6 +1219,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

0 comments on commit 5950987

Please sign in to comment.