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;
114 std::shared_ptr<hls4mlEmulator::Model>
model;
131 template <
class INPUT,
class OUTPUT>
133 :
nPumBins(iConfig.getParameter<unsigned
int>(
"nPumBins")),
136 jetSeed(iConfig.getParameter<unsigned
int>(
"jetSeed")),
137 tauSeed(iConfig.getParameter<unsigned
int>(
"tauSeed")),
139 eGammaSeed(iConfig.getParameter<unsigned
int>(
"eGammaSeed")),
143 fwVersion(iConfig.getParameter<
int>(
"firmwareVersion")),
145 loader(hls4mlEmulator::ModelLoader(iConfig.getParameter<
string>(
"CICADAModelVersion"))),
146 overwriteWithTestPatterns(iConfig.getParameter<
bool>(
"useTestPatterns")),
148 std::vector<double> pumLUTData;
149 char pumLUTString[10];
150 for (uint32_t pumBin = 0; pumBin <
nPumBins; pumBin++) {
153 sprintf(pumLUTString,
"pumLUT%2.2dp", pumBin);
155 sprintf(pumLUTString,
"pumLUT%2.2dn", pumBin);
156 pumLUTData = iConfig.
getParameter<std::vector<double>>(pumLUTString);
157 for (uint32_t
iEta = 0;
iEta <
std::max((uint32_t)pumLUTData.size(), MaxUCTRegionsEta);
iEta++) {
160 if (pumLUTData.size() != (MaxUCTRegionsEta))
161 edm::LogError(
"L1TCaloSummary") <<
"PUM LUT Data size integrity check failed; Expected size = " 162 << MaxUCTRegionsEta <<
"; Provided size = " << pumLUTData.size()
163 <<
"; Will use what is provided :(" << std::endl;
166 produces<L1JetParticleCollection>(
"Boosted");
170 produces<l1t::CICADABxCollection>(
"CICADAScore");
178 template <
class INPUT,
class OUTPUT>
184 std::unique_ptr<l1t::CICADABxCollection> CICADAScore = std::make_unique<l1t::CICADABxCollection>();
185 CICADAScore->setBXRange(-2, 2);
193 UCTSummaryCard summaryCard =
195 std::vector<UCTRegion*> inputRegions;
196 inputRegions.clear();
199 edm::LogError(
"L1TCaloSummary") <<
"UCT: Failed to get regions from region collection!";
204 INPUT modelInput[252];
206 UCTRegionIndex r =
g.getUCTRegionIndexFromL1CaloRegion(
i.gctEta(),
i.gctPhi());
207 UCTTowerIndex
t =
g.getUCTTowerIndexFromL1CaloRegion(r,
i.raw());
209 uint32_t absCaloPhi =
std::abs(
t.second);
210 bool negativeEta =
false;
213 uint32_t
crate =
g.getCrate(
t.first,
t.second);
214 uint32_t card =
g.getCard(
t.first,
t.second);
215 uint32_t
region =
g.getRegion(absCaloEta, absCaloPhi);
217 test->setRegionSummary(
i.raw());
218 inputRegions.push_back(
test);
224 modelInput[14 *
i.gctPhi() + (
i.gctEta() - 4)] =
i.et();
227 if (overwriteWithTestPatterns) {
228 unsigned int evt =
iEvent.id().event();
230 unsigned int patternElement = evt % totalTestPatterns;
232 std::stringstream inputStream;
235 edm::LogWarning(
"L1TCaloSummary") <<
"Overwriting existing CICADA input with test pattern!\n";
237 for (
unsigned short int iPhi = 1; iPhi <= 18; ++iPhi) {
239 std::stringstream PhiRowStringStream;
240 PhiRowStringStream <<
"iPhi_" << iPhi;
241 PhiRowString = PhiRowStringStream.str();
242 std::vector<unsigned int> phiRow = element.
getParameter<std::vector<unsigned int>>(PhiRowString);
244 modelInput[14 * (iPhi - 1) + (
iEta - 1)] = phiRow.at(
iEta - 1);
245 inputStream << phiRow.at(
iEta - 1) <<
" ";
249 edm::LogInfo(
"L1TCaloSummary") <<
"Input Stream:\n" << inputStream.str();
253 OUTPUT modelResult[1] = {
255 model->prepare_input(modelInput);
257 model->read_result(modelResult);
259 CICADAScore->push_back(0, modelResult[0].to_float());
261 if (overwriteWithTestPatterns)
262 edm::LogInfo(
"L1TCaloSummary") <<
"Test Pattern Output: " << CICADAScore->at(0, 0);
264 summaryCard.setRegionData(inputRegions);
266 if (!summaryCard.process()) {
267 edm::LogError(
"L1TCaloSummary") <<
"UCT: Failed to process summary card" << std::endl;
276 std::list<UCTObject*> boostedJetObjs = summaryCard.getBoostedJetObjs();
277 for (std::list<UCTObject*>::const_iterator
i = boostedJetObjs.begin();
i != boostedJetObjs.end();
i++) {
278 const UCTObject*
object = *
i;
281 phi =
g.getUCTTowerPhi(
object->iPhi());
282 bitset<3> activeRegionEtaPattern = 0;
284 bool activeStrip =
false;
285 for (uint32_t iPhi = 0; iPhi < 3; iPhi++) {
286 if (
object->boostedJetRegionET()[3 *
iEta + iPhi] > 30 &&
287 object->boostedJetRegionET()[3 *
iEta + iPhi] >
object->et() * 0.0625)
291 activeRegionEtaPattern |= (0x1 <<
iEta);
293 bitset<3> activeRegionPhiPattern = 0;
294 for (uint32_t iPhi = 0; iPhi < 3; iPhi++) {
295 bool activeStrip =
false;
297 if (
object->boostedJetRegionET()[3 *
iEta + iPhi] > 30 &&
298 object->boostedJetRegionET()[3 *
iEta + iPhi] >
object->et() * 0.0625)
302 activeRegionPhiPattern |= (0x1 << iPhi);
304 string regionEta = activeRegionEtaPattern.to_string<char, std::string::traits_type, std::string::allocator_type>();
305 string regionPhi = activeRegionPhiPattern.to_string<char, std::string::traits_type, std::string::allocator_type>();
307 bool centralHighest =
object->boostedJetRegionET()[4] >=
object->boostedJetRegionET()[0] &&
308 object->boostedJetRegionET()[4] >=
object->boostedJetRegionET()[1] &&
309 object->boostedJetRegionET()[4] >=
object->boostedJetRegionET()[2] &&
310 object->boostedJetRegionET()[4] >=
object->boostedJetRegionET()[3] &&
311 object->boostedJetRegionET()[4] >=
object->boostedJetRegionET()[5] &&
312 object->boostedJetRegionET()[4] >=
object->boostedJetRegionET()[6] &&
313 object->boostedJetRegionET()[4] >=
object->boostedJetRegionET()[7] &&
314 object->boostedJetRegionET()[4] >=
object->boostedJetRegionET()[8];
316 if (
abs(
eta) < 2.5 && ((regionEta ==
"101" && (regionPhi ==
"110" || regionPhi ==
"101" || regionPhi ==
"010")) ||
317 ((regionEta ==
"110" || regionEta ==
"101" || regionEta ==
"010") && regionPhi ==
"101") ||
318 (regionEta ==
"111" && (regionPhi ==
"110" || regionPhi ==
"010")) ||
319 ((regionEta ==
"110" || regionEta ==
"010") && regionPhi ==
"111") ||
320 ((regionEta ==
"010" || regionPhi ==
"010" || regionEta ==
"110" || regionPhi ==
"110" ||
321 regionEta ==
"011" || regionPhi ==
"011") &&
332 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
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