Skip to content

Commit

Permalink
make L1 prescale start from a semi-random value
Browse files Browse the repository at this point in the history
  • Loading branch information
silviodonato committed Apr 8, 2022
1 parent eb7657b commit 05f0658
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
31 changes: 31 additions & 0 deletions L1Trigger/L1TGlobal/interface/GlobalBoard.h
Expand Up @@ -14,6 +14,7 @@

// system include files
#include <bitset>
#include <cassert>
#include <vector>

// user include files
Expand Down Expand Up @@ -164,6 +165,32 @@ namespace l1t {
/// pointer to Tau data list
inline const BXVector<const GlobalExtBlk*>* getCandL1External() const { return m_candL1External; }

//initializer prescale counter using a semi-random value between [1, prescale value]
static const std::vector<double> semirandomNumber(const edm::Event& iEvent,
const std::vector<double>& prescaleFactorsAlgoTrig) {
std::vector<double> out(prescaleFactorsAlgoTrig.size(), 1.);
//pick a random number from a combination of run, lumi, event numbers (different number for different threads)
std::srand(0);
std::srand(std::rand() + iEvent.id().run());
std::srand(std::rand() + iEvent.id().luminosityBlock());
//this causes different semirandomNumber number for different threads
std::srand(std::rand() + iEvent.id().event()); //reminder: different threads have different initial event number
const double semirandom = std::rand();
for (size_t i = 0; i < prescaleFactorsAlgoTrig.size(); i++) {
const double ps = prescaleFactorsAlgoTrig.at(i);
if (ps == 0 || ps == 1) { //do not touch ps = 0 and ps = 1
out[i] = ps;
} else { //replace ps with a semirandom number between [1,ps]
out[i] = semirandom - floor(semirandom / ps) * ps;
if (out[i] == 0)
out[i] = ps;
assert(out[i] > 0);
assert(out[i] <= ps);
}
}
return out;
}

/* Drop individual EtSums for Now
/// pointer to ETM data list
inline const l1t::EtSum* getCandL1ETM() const
Expand Down Expand Up @@ -194,6 +221,7 @@ namespace l1t {
void setBxLast(int bx);

void setResetPSCountersEachLumiSec(bool val) { m_resetPSCountersEachLumiSec = val; }
void setSemiRandomInitialPSCounters(bool val) { m_semiRandomInitialPSCounters = val; }

public:
inline void setVerbosity(const int verbosity) { m_verbosity = verbosity; }
Expand Down Expand Up @@ -268,6 +296,9 @@ namespace l1t {

//whether we reset the prescales each lumi or not
bool m_resetPSCountersEachLumiSec = true;

// start the PS counter from a random value between [1,PS] instead of PS
bool m_semiRandomInitialPSCounters = false;
};

} // namespace l1t
Expand Down
3 changes: 3 additions & 0 deletions L1Trigger/L1TGlobal/plugins/L1TGlobalProducer.cc
Expand Up @@ -69,6 +69,7 @@ void L1TGlobalProducer::fillDescriptions(edm::ConfigurationDescriptions& descrip
// switch for muon showers in Run-3
desc.add<bool>("useMuonShowers", false);
desc.add<bool>("resetPSCountersEachLumiSec", true);
desc.add<bool>("semiRandomInitialPSCounters", false);
// These parameters have well defined default values and are not currently
// part of the L1T/HLT interface. They can be cleaned up or updated at will:
desc.add<bool>("ProduceL1GtDaqRecord", true);
Expand Down Expand Up @@ -116,6 +117,7 @@ L1TGlobalProducer::L1TGlobalProducer(const edm::ParameterSet& parSet)
m_requireMenuToMatchAlgoBlkInput(parSet.getParameter<bool>("RequireMenuToMatchAlgoBlkInput")),
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_egInputToken = consumes<BXVector<EGamma>>(m_egInputTag);
m_tauInputToken = consumes<BXVector<Tau>>(m_tauInputTag);
Expand Down Expand Up @@ -197,6 +199,7 @@ L1TGlobalProducer::L1TGlobalProducer(const edm::ParameterSet& parSet)
m_uGtBrd = std::make_unique<GlobalBoard>();
m_uGtBrd->setVerbosity(m_verbosity);
m_uGtBrd->setResetPSCountersEachLumiSec(m_resetPSCountersEachLumiSec);
m_uGtBrd->setSemiRandomInitialPSCounters(m_semiRandomInitialPSCounters);

// initialize cached IDs

Expand Down
2 changes: 2 additions & 0 deletions L1Trigger/L1TGlobal/plugins/L1TGlobalProducer.h
Expand Up @@ -188,6 +188,8 @@ class L1TGlobalProducer : public edm::stream::EDProducer<> {

//disables reseting the prescale counters each lumisection (needed for offline)
bool m_resetPSCountersEachLumiSec;
// start the PS counter from a random value between [1,PS] instead of PS
bool m_semiRandomInitialPSCounters;
// switch to load muon showers in the global board
bool m_useMuonShowers;
};
Expand Down
12 changes: 10 additions & 2 deletions L1Trigger/L1TGlobal/src/GlobalBoard.cc
Expand Up @@ -974,7 +974,11 @@ void l1t::GlobalBoard::runFDL(edm::Event& iEvent,
m_prescaleCounterAlgoTrig.reserve(numberPhysTriggers * totalBxInEvent);

for (int iBxInEvent = 0; iBxInEvent <= totalBxInEvent; ++iBxInEvent) {
m_prescaleCounterAlgoTrig.push_back(prescaleFactorsAlgoTrig);
if (m_semiRandomInitialPSCounters) {
m_prescaleCounterAlgoTrig.push_back(semirandomNumber(iEvent, prescaleFactorsAlgoTrig));
} else {
m_prescaleCounterAlgoTrig.push_back(prescaleFactorsAlgoTrig);
}
}
m_firstEv = false;
m_currentLumi = iEvent.luminosityBlock();
Expand All @@ -984,7 +988,11 @@ void l1t::GlobalBoard::runFDL(edm::Event& iEvent,
if (m_firstEvLumiSegment || (m_currentLumi != iEvent.luminosityBlock() && m_resetPSCountersEachLumiSec)) {
m_prescaleCounterAlgoTrig.clear();
for (int iBxInEvent = 0; iBxInEvent <= totalBxInEvent; ++iBxInEvent) {
m_prescaleCounterAlgoTrig.push_back(prescaleFactorsAlgoTrig);
if (m_semiRandomInitialPSCounters) {
m_prescaleCounterAlgoTrig.push_back(semirandomNumber(iEvent, prescaleFactorsAlgoTrig));
} else {
m_prescaleCounterAlgoTrig.push_back(prescaleFactorsAlgoTrig);
}
}
m_firstEvLumiSegment = false;
m_currentLumi = iEvent.luminosityBlock();
Expand Down

0 comments on commit 05f0658

Please sign in to comment.