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 =
"GTADModel_" + m_gtAXOL1TLTemplate->modelVersion();
96 hls4mlEmulator::ModelLoader
loader(AXOL1TLmodelversion);
97 std::shared_ptr<hls4mlEmulator::Model>
model;
101 }
catch (std::runtime_error&
e) {
104 <<
" ERROR: failed to load AXOL1TL model version \"" << AXOL1TLmodelversion
105 <<
"\" that was specified in menu. Model version not found in cms-hls4ml externals.";
114 const int NMuons = 4;
115 const int NJets = 10;
116 const int NEgammas = 4;
120 const int MuVecSize = 12;
121 const int JVecSize = 30;
122 const int EGVecSize = 12;
123 const int EtSumVecSize = 3;
126 const int NInputs = 57;
129 typedef ap_fixed<18, 13> inputtype;
130 typedef std::array<ap_fixed<10, 7, AP_RND_CONV, AP_SAT>, 8> resulttype;
131 typedef ap_ufixed<18, 14> losstype;
132 typedef std::pair<resulttype, losstype> pairtype;
136 inputtype fillzero = 0.0;
139 inputtype ADModelInput[NInputs] = {};
142 inputtype MuInput[MuVecSize];
143 inputtype JetInput[JVecSize];
144 inputtype EgammaInput[EGVecSize];
145 inputtype EtSumInput[EtSumVecSize];
150 pairtype ADModelResult;
154 int NCandMu = candMuVec->
size(useBx);
155 int NCandJet = candJetVec->
size(useBx);
156 int NCandEG = candEGVec->
size(useBx);
157 int NCandEtSum = candEtSumVec->
size(useBx);
160 std::fill(EtSumInput, EtSumInput + EtSumVecSize, fillzero);
161 std::fill(MuInput, MuInput + MuVecSize, fillzero);
162 std::fill(JetInput, JetInput + JVecSize, fillzero);
163 std::fill(EgammaInput, EgammaInput + EGVecSize, fillzero);
164 std::fill(ADModelInput, ADModelInput + NInputs, fillzero);
169 if (NCandEtSum > 0) {
170 for (
int iEtSum = 0; iEtSum < NCandEtSum; iEtSum++) {
173 ((candEtSumVec->
at(useBx, iEtSum))->
hwPt()) / 2;
175 EtSumInput[2] = (candEtSumVec->
at(useBx, iEtSum))->
hwPhi();
182 for (
int iEG = 0; iEG < NCandEG; iEG++) {
183 if (iEG < NEgammas) {
184 EgammaInput[0 + (3 * iEG)] = ((candEGVec->
at(useBx, iEG))->
hwPt()) /
186 EgammaInput[1 + (3 * iEG)] = (candEGVec->
at(useBx, iEG))->
hwEta();
187 EgammaInput[2 + (3 * iEG)] = (candEGVec->
at(useBx, iEG))->
hwPhi();
194 for (
int iMu = 0; iMu < NCandMu; iMu++) {
196 MuInput[0 + (3 * iMu)] = ((candMuVec->
at(useBx, iMu))->
hwPt()) /
198 MuInput[1 + (3 * iMu)] = (candMuVec->
at(useBx, iMu))->
hwEta();
199 MuInput[2 + (3 * iMu)] = (candMuVec->
at(useBx, iMu))->
hwPhi();
206 for (
int iJet = 0; iJet < NCandJet; iJet++) {
208 JetInput[0 + (3 * iJet)] = ((candJetVec->
at(useBx, iJet))->
hwPt()) /
210 JetInput[1 + (3 * iJet)] = (candJetVec->
at(useBx, iJet))->
hwEta();
211 JetInput[2 + (3 * iJet)] = (candJetVec->
at(useBx, iJet))->
hwPhi();
218 for (
int idET = 0; idET < EtSumVecSize; idET++) {
219 ADModelInput[
index++] = EtSumInput[idET];
221 for (
int idEG = 0; idEG < EGVecSize; idEG++) {
222 ADModelInput[
index++] = EgammaInput[idEG];
224 for (
int idMu = 0; idMu < MuVecSize; idMu++) {
225 ADModelInput[
index++] = MuInput[idMu];
227 for (
int idJ = 0; idJ < JVecSize; idJ++) {
228 ADModelInput[
index++] = JetInput[idJ];
232 model->prepare_input(ADModelInput);
234 model->read_result(&ADModelResult);
236 result = ADModelResult.first;
237 loss = ADModelResult.second;
238 score = ((loss).to_float()) * 16.0;
242 int nObjInCond = m_gtAXOL1TLTemplate->nrObjects();
244 if (iCondition >= nObjInCond || iCondition < 0) {
251 bool condGEqVal = m_gtAXOL1TLTemplate->condGEq();
252 bool passCondition =
false;
256 condResult |= passCondition;
263 myCout <<
"Dummy Print for AXOL1TLCondition" << std::endl;
264 m_gtAXOL1TLTemplate->print(myCout);
void print(std::ostream &myCout) const override
print condition
~AXOL1TLCondition() override
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