22 #include "hls4ml/emulator.h" 59 m_gtAXOL1TLTemplate =
cp.gtAXOL1TLTemplate();
62 m_condMaxNumberObjects =
cp.condMaxNumberObjects();
63 m_condLastResult =
cp.condLastResult();
64 m_combinationsInCond =
cp.getCombinationsInCond();
66 m_verbosity =
cp.m_verbosity;
89 bool condResult =
false;
90 int useBx = bxEval + m_gtAXOL1TLTemplate->condRelativeBx();
93 std::string AXOL1TLmodelversion = m_AXOL1TLmodelversion;
94 hls4mlEmulator::ModelLoader
loader(AXOL1TLmodelversion);
95 std::shared_ptr<hls4mlEmulator::Model>
model;
104 const int NMuons = 4;
105 const int NJets = 10;
106 const int NEgammas = 4;
110 const int MuVecSize = 12;
111 const int JVecSize = 30;
112 const int EGVecSize = 12;
113 const int EtSumVecSize = 3;
116 const int NInputs = 57;
119 typedef ap_fixed<18, 13> inputtype;
120 typedef std::array<ap_fixed<10, 7, AP_RND_CONV, AP_SAT>, 8> resulttype;
121 typedef ap_ufixed<18, 14> losstype;
122 typedef std::pair<resulttype, losstype> pairtype;
126 inputtype fillzero = 0.0;
129 inputtype ADModelInput[NInputs] = {};
132 inputtype MuInput[MuVecSize];
133 inputtype JetInput[JVecSize];
134 inputtype EgammaInput[EGVecSize];
135 inputtype EtSumInput[EtSumVecSize];
140 pairtype ADModelResult;
144 int NCandMu = candMuVec->
size(useBx);
145 int NCandJet = candJetVec->
size(useBx);
146 int NCandEG = candEGVec->
size(useBx);
147 int NCandEtSum = candEtSumVec->
size(useBx);
150 std::fill(EtSumInput, EtSumInput + EtSumVecSize, fillzero);
151 std::fill(MuInput, MuInput + MuVecSize, fillzero);
152 std::fill(JetInput, JetInput + JVecSize, fillzero);
153 std::fill(EgammaInput, EgammaInput + EGVecSize, fillzero);
154 std::fill(ADModelInput, ADModelInput + NInputs, fillzero);
159 if (NCandEtSum > 0) {
160 for (
int iEtSum = 0; iEtSum < NCandEtSum; iEtSum++) {
163 ((candEtSumVec->
at(useBx, iEtSum))->
hwPt()) / 2;
165 EtSumInput[2] = (candEtSumVec->
at(useBx, iEtSum))->
hwPhi();
172 for (
int iEG = 0; iEG < NCandEG; iEG++) {
173 if (iEG < NEgammas) {
174 EgammaInput[0 + (3 * iEG)] = ((candEGVec->
at(useBx, iEG))->
hwPt()) /
176 EgammaInput[1 + (3 * iEG)] = (candEGVec->
at(useBx, iEG))->
hwEta();
177 EgammaInput[2 + (3 * iEG)] = (candEGVec->
at(useBx, iEG))->
hwPhi();
184 for (
int iMu = 0; iMu < NCandMu; iMu++) {
186 MuInput[0 + (3 * iMu)] = ((candMuVec->
at(useBx, iMu))->
hwPt()) /
188 MuInput[1 + (3 * iMu)] = (candMuVec->
at(useBx, iMu))->
hwEta();
189 MuInput[2 + (3 * iMu)] = (candMuVec->
at(useBx, iMu))->
hwPhi();
196 for (
int iJet = 0; iJet < NCandJet; iJet++) {
198 JetInput[0 + (3 * iJet)] = ((candJetVec->
at(useBx, iJet))->
hwPt()) /
200 JetInput[1 + (3 * iJet)] = (candJetVec->
at(useBx, iJet))->
hwEta();
201 JetInput[2 + (3 * iJet)] = (candJetVec->
at(useBx, iJet))->
hwPhi();
208 for (
int idET = 0; idET < EtSumVecSize; idET++) {
209 ADModelInput[
index++] = EtSumInput[idET];
211 for (
int idEG = 0; idEG < EGVecSize; idEG++) {
212 ADModelInput[
index++] = EgammaInput[idEG];
214 for (
int idMu = 0; idMu < MuVecSize; idMu++) {
215 ADModelInput[
index++] = MuInput[idMu];
217 for (
int idJ = 0; idJ < JVecSize; idJ++) {
218 ADModelInput[
index++] = JetInput[idJ];
222 model->prepare_input(ADModelInput);
224 model->read_result(&ADModelResult);
226 result = ADModelResult.first;
227 loss = ADModelResult.second;
228 score = ((loss).to_float()) * 16.0;
232 int nObjInCond = m_gtAXOL1TLTemplate->nrObjects();
234 if (iCondition >= nObjInCond || iCondition < 0) {
241 bool condGEqVal = m_gtAXOL1TLTemplate->condGEq();
242 bool passCondition =
false;
246 condResult |= passCondition;
254 m_AXOL1TLmodelversion = modelversionname;
258 myCout <<
"Dummy Print for AXOL1TLCondition" << std::endl;
259 m_gtAXOL1TLTemplate->print(myCout);
void print(std::ostream &myCout) const override
print condition
~AXOL1TLCondition() override
void setModelVersion(const std::string modelversionname)
unsigned size(int bx) const
void setGtAXOL1TLTemplate(const AXOL1TLTemplate *)
const T & at(int bx, unsigned i) const
virtual void print(std::ostream &myCout) const
print condition
void copy(const AXOL1TLCondition &cp)
copy function for copy constructor and operator=
AXOL1TLCondition & operator=(const AXOL1TLCondition &)
void setuGtB(const GlobalBoard *)
set the pointer to uGT GlobalBoard
const bool evaluateCondition(const int bxEval) const override
the core function to check if the condition matches