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;
92 bool condResult =
false;
93 int useBx = bxEval + m_gtAXOL1TLTemplate->condRelativeBx();
96 std::string AXOL1TLmodelversion =
"GTADModel_" + m_gtAXOL1TLTemplate->modelVersion();
99 hls4mlEmulator::ModelLoader
loader(AXOL1TLmodelversion);
100 std::shared_ptr<hls4mlEmulator::Model>
model;
104 }
catch (std::runtime_error&
e) {
107 <<
" ERROR: failed to load AXOL1TL model version \"" << AXOL1TLmodelversion
108 <<
"\" that was specified in menu. Model version not found in cms-hls4ml externals.";
117 const int NMuons = 4;
118 const int NJets = 10;
119 const int NEgammas = 4;
123 const int MuVecSize = 12;
124 const int JVecSize = 30;
125 const int EGVecSize = 12;
126 const int EtSumVecSize = 3;
129 const int NInputs = 57;
132 typedef ap_fixed<18, 13> inputtype;
133 typedef std::array<ap_fixed<10, 7, AP_RND_CONV, AP_SAT>, 8> resulttype;
134 typedef ap_ufixed<18, 14> losstype;
135 typedef std::pair<resulttype, losstype> pairtype;
139 inputtype fillzero = 0.0;
142 inputtype ADModelInput[NInputs] = {};
145 inputtype MuInput[MuVecSize];
146 inputtype JetInput[JVecSize];
147 inputtype EgammaInput[EGVecSize];
148 inputtype EtSumInput[EtSumVecSize];
153 pairtype ADModelResult;
157 int NCandMu = candMuVec->
size(useBx);
158 int NCandJet = candJetVec->
size(useBx);
159 int NCandEG = candEGVec->
size(useBx);
160 int NCandEtSum = candEtSumVec->
size(useBx);
163 std::fill(EtSumInput, EtSumInput + EtSumVecSize, fillzero);
164 std::fill(MuInput, MuInput + MuVecSize, fillzero);
165 std::fill(JetInput, JetInput + JVecSize, fillzero);
166 std::fill(EgammaInput, EgammaInput + EGVecSize, fillzero);
167 std::fill(ADModelInput, ADModelInput + NInputs, fillzero);
172 if (NCandEtSum > 0) {
173 for (
int iEtSum = 0; iEtSum < NCandEtSum; iEtSum++) {
176 ((candEtSumVec->
at(useBx, iEtSum))->
hwPt()) / 2;
178 EtSumInput[2] = (candEtSumVec->
at(useBx, iEtSum))->
hwPhi();
185 for (
int iEG = 0; iEG < NCandEG; iEG++) {
186 if (iEG < NEgammas) {
187 EgammaInput[0 + (3 * iEG)] = ((candEGVec->
at(useBx, iEG))->
hwPt()) /
189 EgammaInput[1 + (3 * iEG)] = (candEGVec->
at(useBx, iEG))->
hwEta();
190 EgammaInput[2 + (3 * iEG)] = (candEGVec->
at(useBx, iEG))->
hwPhi();
197 for (
int iMu = 0; iMu < NCandMu; iMu++) {
199 MuInput[0 + (3 * iMu)] = ((candMuVec->
at(useBx, iMu))->
hwPt()) /
201 MuInput[1 + (3 * iMu)] = (candMuVec->
at(useBx, iMu))->
hwEta();
202 MuInput[2 + (3 * iMu)] = (candMuVec->
at(useBx, iMu))->
hwPhi();
209 for (
int iJet = 0; iJet < NCandJet; iJet++) {
211 JetInput[0 + (3 * iJet)] = ((candJetVec->
at(useBx, iJet))->
hwPt()) /
213 JetInput[1 + (3 * iJet)] = (candJetVec->
at(useBx, iJet))->
hwEta();
214 JetInput[2 + (3 * iJet)] = (candJetVec->
at(useBx, iJet))->
hwPhi();
221 for (
int idET = 0; idET < EtSumVecSize; idET++) {
222 ADModelInput[
index++] = EtSumInput[idET];
224 for (
int idEG = 0; idEG < EGVecSize; idEG++) {
225 ADModelInput[
index++] = EgammaInput[idEG];
227 for (
int idMu = 0; idMu < MuVecSize; idMu++) {
228 ADModelInput[
index++] = MuInput[idMu];
230 for (
int idJ = 0; idJ < JVecSize; idJ++) {
231 ADModelInput[
index++] = JetInput[idJ];
235 model->prepare_input(ADModelInput);
237 model->read_result(&ADModelResult);
239 result = ADModelResult.first;
240 loss = ADModelResult.second;
247 int nObjInCond = m_gtAXOL1TLTemplate->nrObjects();
249 if (iCondition >= nObjInCond || iCondition < 0) {
256 bool condGEqVal = m_gtAXOL1TLTemplate->condGEq();
257 bool passCondition =
false;
261 condResult |= passCondition;
268 myCout <<
"Dummy Print for AXOL1TLCondition" << std::endl;
269 m_gtAXOL1TLTemplate->print(myCout);
void print(std::ostream &myCout) const override
print condition
~AXOL1TLCondition() override
unsigned size(int bx) const
void setScore(const float scoreval) const
get/set score value
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