34 #include "L1Trigger/L1TCaloLayer1/src/UCTLayer1.hh" 35 #include "L1Trigger/L1TCaloLayer1/src/UCTCrate.hh" 36 #include "L1Trigger/L1TCaloLayer1/src/UCTCard.hh" 37 #include "L1Trigger/L1TCaloLayer1/src/UCTRegion.hh" 38 #include "L1Trigger/L1TCaloLayer1/src/UCTTower.hh" 39 #include "L1Trigger/L1TCaloLayer1/src/UCTGeometry.hh" 41 #include "L1Trigger/L1TCaloLayer1/src/UCTObject.hh" 42 #include "L1Trigger/L1TCaloLayer1/src/UCTSummaryCard.hh" 43 #include "L1Trigger/L1TCaloLayer1/src/UCTGeometryExtended.hh" 58 #include "L1Trigger/L1TCaloLayer1/src/UCTLogging.hh" 66 #include "hls4ml/emulator.h" 76 template <
class INPUT,
class OUTPUT>
95 std::vector<std::vector<std::vector<uint32_t>>>
pumLUT;
115 std::shared_ptr<hls4mlEmulator::Model>
model;
132 template <
class INPUT,
class OUTPUT>
134 :
nPumBins(iConfig.getParameter<unsigned
int>(
"nPumBins")),
137 jetSeed(iConfig.getParameter<unsigned
int>(
"jetSeed")),
138 tauSeed(iConfig.getParameter<unsigned
int>(
"tauSeed")),
140 eGammaSeed(iConfig.getParameter<unsigned
int>(
"eGammaSeed")),
144 fwVersion(iConfig.getParameter<
int>(
"firmwareVersion")),
147 loader(hls4mlEmulator::ModelLoader(iConfig.getParameter<
string>(
"CICADAModelVersion"))),
148 overwriteWithTestPatterns(iConfig.getParameter<
bool>(
"useTestPatterns")),
150 std::vector<double> pumLUTData;
151 char pumLUTString[10];
152 for (uint32_t pumBin = 0; pumBin <
nPumBins; pumBin++) {
155 sprintf(pumLUTString,
"pumLUT%2.2dp", pumBin);
157 sprintf(pumLUTString,
"pumLUT%2.2dn", pumBin);
158 pumLUTData = iConfig.
getParameter<std::vector<double>>(pumLUTString);
159 for (uint32_t
iEta = 0;
iEta <
std::max((uint32_t)pumLUTData.size(), MaxUCTRegionsEta);
iEta++) {
162 if (pumLUTData.size() != (MaxUCTRegionsEta))
163 edm::LogError(
"L1TCaloSummary") <<
"PUM LUT Data size integrity check failed; Expected size = " 164 << MaxUCTRegionsEta <<
"; Provided size = " << pumLUTData.size()
165 <<
"; Will use what is provided :(" << std::endl;
168 produces<L1JetParticleCollection>(
"Boosted");
172 produces<l1t::CICADABxCollection>(
"CICADAScore");
180 template <
class INPUT,
class OUTPUT>
186 std::unique_ptr<l1t::CICADABxCollection> CICADAScore = std::make_unique<l1t::CICADABxCollection>();
187 CICADAScore->setBXRange(-2, 2);
195 UCTSummaryCard summaryCard =
197 std::vector<UCTRegion*> inputRegions;
198 inputRegions.clear();
201 edm::LogError(
"L1TCaloSummary") <<
"UCT: Failed to get regions from region collection!";
204 if (regionCollection->size() == 0) {
205 iEvent.getByToken(backupRegionToken, regionCollection);
206 edm::LogWarning(
"L1TCaloSummary") <<
"Switched to emulated regions since data regions was empty.\n";
212 INPUT modelInput[252];
214 UCTRegionIndex r =
g.getUCTRegionIndexFromL1CaloRegion(
i.gctEta(),
i.gctPhi());
215 UCTTowerIndex
t =
g.getUCTTowerIndexFromL1CaloRegion(r,
i.raw());
217 uint32_t absCaloPhi =
std::abs(
t.second);
218 bool negativeEta =
false;
221 uint32_t
crate =
g.getCrate(
t.first,
t.second);
222 uint32_t card =
g.getCard(
t.first,
t.second);
223 uint32_t
region =
g.getRegion(absCaloEta, absCaloPhi);
225 test->setRegionSummary(
i.raw());
226 inputRegions.push_back(
test);
232 modelInput[14 *
i.gctPhi() + (
i.gctEta() - 4)] =
i.et();
235 if (overwriteWithTestPatterns) {
236 unsigned int evt =
iEvent.id().event();
238 unsigned int patternElement = evt % totalTestPatterns;
240 std::stringstream inputStream;
243 edm::LogWarning(
"L1TCaloSummary") <<
"Overwriting existing CICADA input with test pattern!\n";
245 for (
unsigned short int iPhi = 1; iPhi <= 18; ++iPhi) {
247 std::stringstream PhiRowStringStream;
248 PhiRowStringStream <<
"iPhi_" << iPhi;
249 PhiRowString = PhiRowStringStream.str();
250 std::vector<unsigned int> phiRow = element.
getParameter<std::vector<unsigned int>>(PhiRowString);
252 modelInput[14 * (iPhi - 1) + (
iEta - 1)] = phiRow.at(
iEta - 1);
253 inputStream << phiRow.at(
iEta - 1) <<
" ";
257 edm::LogInfo(
"L1TCaloSummary") <<
"Input Stream:\n" << inputStream.str();
261 OUTPUT modelResult[1] = {
263 model->prepare_input(modelInput);
265 model->read_result(modelResult);
267 CICADAScore->push_back(0, modelResult[0].to_float());
269 if (overwriteWithTestPatterns)
270 edm::LogInfo(
"L1TCaloSummary") <<
"Test Pattern Output: " << CICADAScore->at(0, 0);
272 summaryCard.setRegionData(inputRegions);
274 if (!summaryCard.process()) {
275 edm::LogError(
"L1TCaloSummary") <<
"UCT: Failed to process summary card" << std::endl;
284 std::list<UCTObject*> boostedJetObjs = summaryCard.getBoostedJetObjs();
285 for (std::list<UCTObject*>::const_iterator
i = boostedJetObjs.begin();
i != boostedJetObjs.end();
i++) {
286 const UCTObject*
object = *
i;
289 phi =
g.getUCTTowerPhi(
object->iPhi());
290 bitset<3> activeRegionEtaPattern = 0;
292 bool activeStrip =
false;
293 for (uint32_t iPhi = 0; iPhi < 3; iPhi++) {
294 if (
object->boostedJetRegionET()[3 *
iEta + iPhi] > 30 &&
295 object->boostedJetRegionET()[3 *
iEta + iPhi] >
object->et() * 0.0625)
299 activeRegionEtaPattern |= (0x1 <<
iEta);
301 bitset<3> activeRegionPhiPattern = 0;
302 for (uint32_t iPhi = 0; iPhi < 3; iPhi++) {
303 bool activeStrip =
false;
305 if (
object->boostedJetRegionET()[3 *
iEta + iPhi] > 30 &&
306 object->boostedJetRegionET()[3 *
iEta + iPhi] >
object->et() * 0.0625)
310 activeRegionPhiPattern |= (0x1 << iPhi);
312 string regionEta = activeRegionEtaPattern.to_string<char, std::string::traits_type, std::string::allocator_type>();
313 string regionPhi = activeRegionPhiPattern.to_string<char, std::string::traits_type, std::string::allocator_type>();
315 bool centralHighest =
object->boostedJetRegionET()[4] >=
object->boostedJetRegionET()[0] &&
316 object->boostedJetRegionET()[4] >=
object->boostedJetRegionET()[1] &&
317 object->boostedJetRegionET()[4] >=
object->boostedJetRegionET()[2] &&
318 object->boostedJetRegionET()[4] >=
object->boostedJetRegionET()[3] &&
319 object->boostedJetRegionET()[4] >=
object->boostedJetRegionET()[5] &&
320 object->boostedJetRegionET()[4] >=
object->boostedJetRegionET()[6] &&
321 object->boostedJetRegionET()[4] >=
object->boostedJetRegionET()[7] &&
322 object->boostedJetRegionET()[4] >=
object->boostedJetRegionET()[8];
324 if (
abs(
eta) < 2.5 && ((regionEta ==
"101" && (regionPhi ==
"110" || regionPhi ==
"101" || regionPhi ==
"010")) ||
325 ((regionEta ==
"110" || regionEta ==
"101" || regionEta ==
"010") && regionPhi ==
"101") ||
326 (regionEta ==
"111" && (regionPhi ==
"110" || regionPhi ==
"010")) ||
327 ((regionEta ==
"110" || regionEta ==
"010") && regionPhi ==
"111") ||
328 ((regionEta ==
"010" || regionPhi ==
"010" || regionEta ==
"110" || regionPhi ==
"110" ||
329 regionEta ==
"011" || regionPhi ==
"011") &&
340 template <
class INPUT,
class OUTPUT>
T getParameter(std::string const &) const
ALPAKA_FN_ACC int side(int ieta, int iphi)
bool overwriteWithTestPatterns
Log< level::Error, false > LogError
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
L1TCaloSummary< ap_uint< 10 >, ap_ufixed< 16, 8 > > L1TCaloSummary_CICADA_v2p1p0
PtEtaPhiMLorentzVectorD PtEtaPhiMLorentzVector
Lorentz vector with cartesian internal representation.
L1TCaloSummary< ap_uint< 10 >, ap_ufixed< 16, 8, AP_RND_CONV, AP_SAT > > L1TCaloSummary_CICADA_vXp1p2
L1TCaloSummary(const edm::ParameterSet &)
void addDefault(ParameterSetDescription const &psetDescription)
void produce(edm::Event &, const edm::EventSetup &) override
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
L1TCaloSummary< ap_ufixed< 10, 10 >, ap_fixed< 11, 5 > > L1TCaloSummary_CICADA_v1p0p0
Abs< T >::type abs(const T &t)
#define DEFINE_FWK_MODULE(type)
std::vector< edm::ParameterSet > testPatterns
edm::EDGetTokenT< L1CaloRegionCollection > regionToken
Log< level::Info, false > LogInfo
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
L1TCaloSummary< ap_ufixed< 10, 10 >, ap_fixed< 11, 5 > > L1TCaloSummary_CICADA_v1p1p0
edm::EDGetTokenT< L1CaloRegionCollection > backupRegionToken
std::shared_ptr< hls4mlEmulator::Model > model
L1TCaloSummary< ap_uint< 10 >, ap_ufixed< 16, 8 > > L1TCaloSummary_CICADA_v2p0p0
double boostedJetPtFactor
L1TCaloSummary< ap_uint< 10 >, ap_ufixed< 16, 8, AP_RND, AP_SAT, AP_SAT > > L1TCaloSummary_CICADA_vXp1p1
double eGammaIsolationFactor
hls4mlEmulator::ModelLoader loader
std::vector< std::vector< std::vector< uint32_t > > > pumLUT
A calorimeter trigger region (sum of 4x4 trigger towers)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::vector< L1CaloRegion > L1CaloRegionCollection
Log< level::Warning, false > LogWarning