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" 57 #include "L1Trigger/L1TCaloLayer1/src/UCTLogging.hh" 65 #include "hls4ml/emulator.h" 75 template <
class INPUT,
class OUTPUT>
94 std::vector<std::vector<std::vector<uint32_t>>>
pumLUT;
113 std::shared_ptr<hls4mlEmulator::Model>
model;
130 template <
class INPUT,
class OUTPUT>
132 :
nPumBins(iConfig.getParameter<unsigned
int>(
"nPumBins")),
135 jetSeed(iConfig.getParameter<unsigned
int>(
"jetSeed")),
136 tauSeed(iConfig.getParameter<unsigned
int>(
"tauSeed")),
138 eGammaSeed(iConfig.getParameter<unsigned
int>(
"eGammaSeed")),
142 fwVersion(iConfig.getParameter<
int>(
"firmwareVersion")),
144 loader(hls4mlEmulator::ModelLoader(iConfig.getParameter<
string>(
"CICADAModelVersion"))),
145 overwriteWithTestPatterns(iConfig.getParameter<
bool>(
"useTestPatterns")),
147 std::vector<double> pumLUTData;
148 char pumLUTString[10];
149 for (uint32_t pumBin = 0; pumBin <
nPumBins; pumBin++) {
152 sprintf(pumLUTString,
"pumLUT%2.2dp", pumBin);
154 sprintf(pumLUTString,
"pumLUT%2.2dn", pumBin);
155 pumLUTData = iConfig.
getParameter<std::vector<double>>(pumLUTString);
156 for (uint32_t
iEta = 0;
iEta <
std::max((uint32_t)pumLUTData.size(), MaxUCTRegionsEta);
iEta++) {
159 if (pumLUTData.size() != (MaxUCTRegionsEta))
160 edm::LogError(
"L1TCaloSummary") <<
"PUM LUT Data size integrity check failed; Expected size = " 161 << MaxUCTRegionsEta <<
"; Provided size = " << pumLUTData.size()
162 <<
"; Will use what is provided :(" << std::endl;
165 produces<L1JetParticleCollection>(
"Boosted");
169 produces<float>(
"CICADAScore");
177 template <
class INPUT,
class OUTPUT>
183 std::unique_ptr<float> CICADAScore = std::make_unique<float>();
191 UCTSummaryCard summaryCard =
193 std::vector<UCTRegion*> inputRegions;
194 inputRegions.clear();
197 edm::LogError(
"L1TCaloSummary") <<
"UCT: Failed to get regions from region collection!";
202 INPUT modelInput[252];
204 UCTRegionIndex r =
g.getUCTRegionIndexFromL1CaloRegion(
i.gctEta(),
i.gctPhi());
205 UCTTowerIndex
t =
g.getUCTTowerIndexFromL1CaloRegion(r,
i.raw());
207 uint32_t absCaloPhi =
std::abs(
t.second);
208 bool negativeEta =
false;
211 uint32_t crate =
g.getCrate(
t.first,
t.second);
212 uint32_t card =
g.getCard(
t.first,
t.second);
213 uint32_t
region =
g.getRegion(absCaloEta, absCaloPhi);
215 test->setRegionSummary(
i.raw());
216 inputRegions.push_back(
test);
222 modelInput[14 *
i.gctPhi() + (
i.gctEta() - 4)] =
i.et();
225 if (overwriteWithTestPatterns) {
226 unsigned int evt =
iEvent.id().event();
228 unsigned int patternElement = evt % totalTestPatterns;
230 std::stringstream inputStream;
233 edm::LogWarning(
"L1TCaloSummary") <<
"Overwriting existing CICADA input with test pattern!\n";
235 for (
unsigned short int iPhi = 1; iPhi <= 18; ++iPhi) {
237 std::stringstream PhiRowStringStream;
238 PhiRowStringStream <<
"iPhi_" << iPhi;
239 PhiRowString = PhiRowStringStream.str();
240 std::vector<unsigned int> phiRow = element.
getParameter<std::vector<unsigned int>>(PhiRowString);
242 modelInput[14 * (iPhi - 1) + (
iEta - 1)] = phiRow.at(
iEta - 1);
243 inputStream << phiRow.at(
iEta - 1) <<
" ";
247 edm::LogInfo(
"L1TCaloSummary") <<
"Input Stream:\n" << inputStream.str();
251 OUTPUT modelResult[1] = {
253 model->prepare_input(modelInput);
255 model->read_result(modelResult);
257 *CICADAScore = modelResult[0].to_float();
259 if (overwriteWithTestPatterns)
260 edm::LogInfo(
"L1TCaloSummary") <<
"Test Pattern Output: " << *CICADAScore;
262 summaryCard.setRegionData(inputRegions);
264 if (!summaryCard.process()) {
265 edm::LogError(
"L1TCaloSummary") <<
"UCT: Failed to process summary card" << std::endl;
274 std::list<UCTObject*> boostedJetObjs = summaryCard.getBoostedJetObjs();
275 for (std::list<UCTObject*>::const_iterator
i = boostedJetObjs.begin();
i != boostedJetObjs.end();
i++) {
276 const UCTObject*
object = *
i;
279 phi =
g.getUCTTowerPhi(
object->iPhi());
280 bitset<3> activeRegionEtaPattern = 0;
282 bool activeStrip =
false;
283 for (uint32_t iPhi = 0; iPhi < 3; iPhi++) {
284 if (
object->boostedJetRegionET()[3 *
iEta + iPhi] > 30 &&
285 object->boostedJetRegionET()[3 *
iEta + iPhi] >
object->et() * 0.0625)
289 activeRegionEtaPattern |= (0x1 <<
iEta);
291 bitset<3> activeRegionPhiPattern = 0;
292 for (uint32_t iPhi = 0; iPhi < 3; iPhi++) {
293 bool activeStrip =
false;
295 if (
object->boostedJetRegionET()[3 *
iEta + iPhi] > 30 &&
296 object->boostedJetRegionET()[3 *
iEta + iPhi] >
object->et() * 0.0625)
300 activeRegionPhiPattern |= (0x1 << iPhi);
302 string regionEta = activeRegionEtaPattern.to_string<char, std::string::traits_type, std::string::allocator_type>();
303 string regionPhi = activeRegionPhiPattern.to_string<char, std::string::traits_type, std::string::allocator_type>();
305 bool centralHighest =
object->boostedJetRegionET()[4] >=
object->boostedJetRegionET()[0] &&
306 object->boostedJetRegionET()[4] >=
object->boostedJetRegionET()[1] &&
307 object->boostedJetRegionET()[4] >=
object->boostedJetRegionET()[2] &&
308 object->boostedJetRegionET()[4] >=
object->boostedJetRegionET()[3] &&
309 object->boostedJetRegionET()[4] >=
object->boostedJetRegionET()[5] &&
310 object->boostedJetRegionET()[4] >=
object->boostedJetRegionET()[6] &&
311 object->boostedJetRegionET()[4] >=
object->boostedJetRegionET()[7] &&
312 object->boostedJetRegionET()[4] >=
object->boostedJetRegionET()[8];
314 if (
abs(
eta) < 2.5 && ((regionEta ==
"101" && (regionPhi ==
"110" || regionPhi ==
"101" || regionPhi ==
"010")) ||
315 ((regionEta ==
"110" || regionEta ==
"101" || regionEta ==
"010") && regionPhi ==
"101") ||
316 (regionEta ==
"111" && (regionPhi ==
"110" || regionPhi ==
"010")) ||
317 ((regionEta ==
"110" || regionEta ==
"010") && regionPhi ==
"111") ||
318 ((regionEta ==
"010" || regionPhi ==
"010" || regionEta ==
"110" || regionPhi ==
"110" ||
319 regionEta ==
"011" || regionPhi ==
"011") &&
330 template <
class INPUT,
class OUTPUT>
T getParameter(std::string const &) const
L1TCaloSummary< ap_ufixed< 10, 10 >, ap_fixed< 11, 5 > > L1TCaloSummaryCICADAv1
ALPAKA_FN_ACC int side(int ieta, int iphi)
bool overwriteWithTestPatterns
L1TCaloSummary< ap_uint< 10 >, ap_ufixed< 16, 8 > > L1TCaloSummaryCICADAv2
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
PtEtaPhiMLorentzVectorD PtEtaPhiMLorentzVector
Lorentz vector with cartesian internal representation.
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)
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)
std::shared_ptr< hls4mlEmulator::Model > model
double boostedJetPtFactor
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