CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
l1t::AXOL1TLCondition Class Reference

#include <AXOL1TLCondition.h>

Inheritance diagram for l1t::AXOL1TLCondition:
l1t::ConditionEvaluation

Public Member Functions

 AXOL1TLCondition ()
 
 AXOL1TLCondition (const GlobalCondition *, const GlobalBoard *)
 from base template condition (from event setup usually) More...
 
 AXOL1TLCondition (const AXOL1TLCondition &)
 
const bool evaluateCondition (const int bxEval) const override
 the core function to check if the condition matches More...
 
float getScore () const
 
const AXOL1TLTemplategtAXOL1TLTemplate () const
 get / set the pointer to a Condition More...
 
const GlobalBoardgtGTB () const
 get / set the pointer to GTL More...
 
AXOL1TLConditionoperator= (const AXOL1TLCondition &)
 
void print (std::ostream &myCout) const override
 print condition More...
 
void setGtAXOL1TLTemplate (const AXOL1TLTemplate *)
 
void setScore (const float scoreval) const
 get/set score value More...
 
void setuGtB (const GlobalBoard *)
 set the pointer to uGT GlobalBoard More...
 
 ~AXOL1TLCondition () override
 
- Public Member Functions inherited from l1t::ConditionEvaluation
 ConditionEvaluation ()
 constructor More...
 
bool condLastResult () const
 get the latest result for the condition More...
 
int condMaxNumberObjects () const
 
void evaluateConditionStoreResult (const int bxEval)
 call evaluateCondition and save last result More...
 
CombinationsInCond const & getCombinationsInCond () const
 get all the object combinations evaluated to true in the condition More...
 
virtual std::string getNumericExpression () const
 get numeric expression More...
 
void setCondMaxNumberObjects (int condMaxNumberObjectsValue)
 
void setVerbosity (const int verbosity)
 
virtual ~ConditionEvaluation ()
 destructor More...
 

Private Member Functions

void copy (const AXOL1TLCondition &cp)
 copy function for copy constructor and operator= More...
 

Private Attributes

const AXOL1TLTemplatem_gtAXOL1TLTemplate
 pointer to a AXOL1TLTemplate More...
 
const GlobalBoardm_gtGTB
 pointer to uGt GlobalBoard, to be able to get the trigger objects More...
 
float m_savedscore
 axo score for possible score saving More...
 

Additional Inherited Members

- Protected Member Functions inherited from l1t::ConditionEvaluation
template<class Type1 >
const bool checkBit (const Type1 &mask, const unsigned int bitNumber) const
 check if a bit with a given number is set in a mask More...
 
template<class Type1 , class Type2 >
const bool checkCut (const Type1 &cutL, const Type2 &value, bool condGEqValue) const
 
template<class Type1 >
const bool checkIndex (const Type1 &indexLo, const Type1 &indexHi, const unsigned int index) const
 check if a index is in a given range More...
 
template<class Type1 >
const bool checkRangeDeltaEta (const unsigned int obj1Eta, const unsigned int obj2Eta, const Type1 &lowerR, const Type1 &upperR, const unsigned int nEtaBits) const
 check if a value is in a given deltaEta range More...
 
template<class Type1 >
const bool checkRangeDeltaPhi (const unsigned int obj1Phi, const unsigned int obj2Phi, const Type1 &lowerR, const Type1 &upperR) const
 check if a value is in a given deltaPhi range More...
 
template<class Type1 >
const bool checkRangeEta (const unsigned int bitNumber, const std::vector< Type1 > &windows, const unsigned int nEtaBits) const
 
template<class Type1 >
const bool checkRangePhi (const unsigned int bitNumber, const Type1 &W1beginR, const Type1 &W1endR, const Type1 &W2beginR, const Type1 &W2endR) const
 check if a value is in a given phi range and outside of a veto range More...
 
template<class Type1 >
const bool checkRangeTfMuonIndex (const unsigned int bitNumber, const std::vector< Type1 > &windows) const
 check if a value is in a given muon track finder index range More...
 
template<class Type1 , class Type2 >
const bool checkThreshold (const Type1 &thresholdL, const Type1 &thresholdH, const Type2 &value, bool condGEqValue) const
 
template<class Type1 , class Type2 >
const bool checkUnconstrainedPt (const Type1 &thresholdL, const Type1 &thresholdH, const Type2 &value, bool condGEqValue) const
 
CombinationsInCondcombinationsInCond () const
 get all the object combinations (to fill it...) More...
 
- Protected Attributes inherited from l1t::ConditionEvaluation
CombinationsInCond m_combinationsInCond
 store all the object combinations evaluated to true in the condition More...
 
bool m_condLastResult
 the last result of evaluateCondition() More...
 
int m_condMaxNumberObjects
 
int m_verbosity
 verbosity level More...
 

Detailed Description

Definition at line 29 of file AXOL1TLCondition.h.

Constructor & Destructor Documentation

◆ AXOL1TLCondition() [1/3]

AXOL1TLCondition::AXOL1TLCondition ( )

constructors default

Definition at line 47 of file AXOL1TLCondition.cc.

48  // empty
49 }

◆ AXOL1TLCondition() [2/3]

AXOL1TLCondition::AXOL1TLCondition ( const GlobalCondition axol1tlTemplate,
const GlobalBoard ptrGTB 
)

from base template condition (from event setup usually)

Definition at line 52 of file AXOL1TLCondition.cc.

54  m_gtAXOL1TLTemplate(static_cast<const AXOL1TLTemplate*>(axol1tlTemplate)),
55  m_gtGTB(ptrGTB) {}
const AXOL1TLTemplate * m_gtAXOL1TLTemplate
pointer to a AXOL1TLTemplate
const GlobalBoard * m_gtGTB
pointer to uGt GlobalBoard, to be able to get the trigger objects

◆ AXOL1TLCondition() [3/3]

AXOL1TLCondition::AXOL1TLCondition ( const AXOL1TLCondition cp)

Definition at line 69 of file AXOL1TLCondition.cc.

References copy().

69 : ConditionEvaluation() { copy(cp); }
void copy(const AXOL1TLCondition &cp)
copy function for copy constructor and operator=

◆ ~AXOL1TLCondition()

AXOL1TLCondition::~AXOL1TLCondition ( )
override

Definition at line 72 of file AXOL1TLCondition.cc.

72  {
73  // empty
74 }

Member Function Documentation

◆ copy()

void AXOL1TLCondition::copy ( const AXOL1TLCondition cp)
private

copy function for copy constructor and operator=

Definition at line 58 of file AXOL1TLCondition.cc.

Referenced by AXOL1TLCondition().

58  {
59  m_gtAXOL1TLTemplate = cp.gtAXOL1TLTemplate();
60  m_gtGTB = cp.gtGTB();
61 
62  m_condMaxNumberObjects = cp.condMaxNumberObjects();
63  m_condLastResult = cp.condLastResult();
64  m_combinationsInCond = cp.getCombinationsInCond();
65 
66  m_verbosity = cp.m_verbosity;
67 }
const AXOL1TLTemplate * m_gtAXOL1TLTemplate
pointer to a AXOL1TLTemplate
CombinationsInCond m_combinationsInCond
store all the object combinations evaluated to true in the condition
int m_verbosity
verbosity level
const GlobalBoard * m_gtGTB
pointer to uGt GlobalBoard, to be able to get the trigger objects
bool m_condLastResult
the last result of evaluateCondition()

◆ evaluateCondition()

const bool AXOL1TLCondition::evaluateCondition ( const int  bxEval) const
overridevirtual

the core function to check if the condition matches

Implements l1t::ConditionEvaluation.

Definition at line 91 of file AXOL1TLCondition.cc.

References BXVector< T >::at(), MillePedeFileConverter_cfg::e, Exception, EcalPhiSymFlatTableProducers_cfi::fill, l1trig_cff::hwEta, l1trig_cff::hwPhi, l1trig_cff::hwPt, L1Analysis::kMissingEt, web.browse_db::loader, isotrackTrainRegressor::loss, AXOL1TLTemplate::ObjectParameter::minAXOL1TLThreshold, isotrackApplyRegressor::model, mps_fire::result, offlineSlimmedPrimaryVertices_cfi::score, BXVector< T >::size(), and AlCaHLTBitMon_QueryRunRegistry::string.

91  {
92  bool condResult = false;
93  int useBx = bxEval + m_gtAXOL1TLTemplate->condRelativeBx();
94 
95  //HLS4ML stuff
96  std::string AXOL1TLmodelversion = "GTADModel_" + m_gtAXOL1TLTemplate->modelVersion(); //loading from menu/template
97 
98  //otherwise load model (if possible) and run inference
99  hls4mlEmulator::ModelLoader loader(AXOL1TLmodelversion);
100  std::shared_ptr<hls4mlEmulator::Model> model;
101 
102  try {
103  model = loader.load_model();
104  } catch (std::runtime_error& e) {
105  // for stopping with exception if model version cannot be loaded
106  throw cms::Exception("ModelError")
107  << " ERROR: failed to load AXOL1TL model version \"" << AXOL1TLmodelversion
108  << "\" that was specified in menu. Model version not found in cms-hls4ml externals.";
109  }
110 
111  // //pointers to objects
112  const BXVector<const l1t::Muon*>* candMuVec = m_gtGTB->getCandL1Mu();
115  const BXVector<const l1t::EtSum*>* candEtSumVec = m_gtGTB->getCandL1EtSum();
116 
117  const int NMuons = 4;
118  const int NJets = 10;
119  const int NEgammas = 4;
120  //const int NEtSums = 1;
121 
122  //number of indices in vector is #objects * 3 for et, eta, phi
123  const int MuVecSize = 12; //NMuons * 3; //so 12
124  const int JVecSize = 30; //NJets * 3; //so 30
125  const int EGVecSize = 12; //NEgammas * 3; //so 12
126  const int EtSumVecSize = 3; //NEtSums * 3; //so 3
127 
128  //total # inputs in vector is (4+10+4+1)*3 = 57
129  const int NInputs = 57;
130 
131  //types of inputs and outputs
132  typedef ap_fixed<18, 13> inputtype;
133  typedef std::array<ap_fixed<10, 7, AP_RND_CONV, AP_SAT>, 8> resulttype; //v3
134  typedef ap_ufixed<18, 14> losstype;
135  typedef std::pair<resulttype, losstype> pairtype;
136  // typedef std::array<ap_fixed<10, 7>, 13> resulttype; //deprecated v1 type:
137 
138  //define zero
139  inputtype fillzero = 0.0;
140 
141  //AD vector declaration, will fill later
142  inputtype ADModelInput[NInputs] = {};
143 
144  //initializing vector by type for my sanity
145  inputtype MuInput[MuVecSize];
146  inputtype JetInput[JVecSize];
147  inputtype EgammaInput[EGVecSize];
148  inputtype EtSumInput[EtSumVecSize];
149 
150  //declare result vectors +score
151  resulttype result;
152  losstype loss;
153  pairtype ADModelResult; //model outputs a pair of the (result vector, loss)
154  float score = -1.0; //not sure what the best default is hm??
155 
156  //check number of input objects we actually have (muons, jets etc)
157  int NCandMu = candMuVec->size(useBx);
158  int NCandJet = candJetVec->size(useBx);
159  int NCandEG = candEGVec->size(useBx);
160  int NCandEtSum = candEtSumVec->size(useBx);
161 
162  //initialize arrays to zero (std::fill(first, last, value);)
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);
168 
169  //then fill the object vectors
170  //NOTE assume candidates are already sorted by pt
171  //loop over EtSums first, easy because there is max 1 of them
172  if (NCandEtSum > 0) { //check if not empty
173  for (int iEtSum = 0; iEtSum < NCandEtSum; iEtSum++) {
174  if ((candEtSumVec->at(useBx, iEtSum))->getType() == l1t::EtSum::EtSumType::kMissingEt) {
175  EtSumInput[0] =
176  ((candEtSumVec->at(useBx, iEtSum))->hwPt()) / 2; //have to do hwPt/2 in order to match original et inputs
177  // EtSumInput[1] = (candEtSumVec->at(useBx, iEtSum))->hwEta(); //this one is zero, so leave it zero
178  EtSumInput[2] = (candEtSumVec->at(useBx, iEtSum))->hwPhi();
179  }
180  }
181  }
182 
183  //next egammas
184  if (NCandEG > 0) { //check if not empty
185  for (int iEG = 0; iEG < NCandEG; iEG++) {
186  if (iEG < NEgammas) { //stop if fill the Nobjects we need
187  EgammaInput[0 + (3 * iEG)] = ((candEGVec->at(useBx, iEG))->hwPt()) /
188  2; //index 0,3,6,9 //have to do hwPt/2 in order to match original et inputs
189  EgammaInput[1 + (3 * iEG)] = (candEGVec->at(useBx, iEG))->hwEta(); //index 1,4,7,10
190  EgammaInput[2 + (3 * iEG)] = (candEGVec->at(useBx, iEG))->hwPhi(); //index 2,5,8,11
191  }
192  }
193  }
194 
195  //next muons
196  if (NCandMu > 0) { //check if not empty
197  for (int iMu = 0; iMu < NCandMu; iMu++) {
198  if (iMu < NMuons) { //stop if fill the Nobjects we need
199  MuInput[0 + (3 * iMu)] = ((candMuVec->at(useBx, iMu))->hwPt()) /
200  2; //index 0,3,6,9 //have to do hwPt/2 in order to match original et inputs
201  MuInput[1 + (3 * iMu)] = (candMuVec->at(useBx, iMu))->hwEta(); //index 1,4,7,10
202  MuInput[2 + (3 * iMu)] = (candMuVec->at(useBx, iMu))->hwPhi(); //index 2,5,8,11
203  }
204  }
205  }
206 
207  //next jets
208  if (NCandJet > 0) { //check if not empty
209  for (int iJet = 0; iJet < NCandJet; iJet++) {
210  if (iJet < NJets) { //stop if fill the Nobjects we need
211  JetInput[0 + (3 * iJet)] = ((candJetVec->at(useBx, iJet))->hwPt()) /
212  2; //index 0,3,6,9...27 //have to do hwPt/2 in order to match original et inputs
213  JetInput[1 + (3 * iJet)] = (candJetVec->at(useBx, iJet))->hwEta(); //index 1,4,7,10...28
214  JetInput[2 + (3 * iJet)] = (candJetVec->at(useBx, iJet))->hwPhi(); //index 2,5,8,11...29
215  }
216  }
217  }
218 
219  //now put it all together-> EtSum+EGamma+Muon+Jet into ADModelInput
220  int index = 0;
221  for (int idET = 0; idET < EtSumVecSize; idET++) {
222  ADModelInput[index++] = EtSumInput[idET];
223  }
224  for (int idEG = 0; idEG < EGVecSize; idEG++) {
225  ADModelInput[index++] = EgammaInput[idEG];
226  }
227  for (int idMu = 0; idMu < MuVecSize; idMu++) {
228  ADModelInput[index++] = MuInput[idMu];
229  }
230  for (int idJ = 0; idJ < JVecSize; idJ++) {
231  ADModelInput[index++] = JetInput[idJ];
232  }
233 
234  //now run the inference
235  model->prepare_input(ADModelInput); //scaling internal here
236  model->predict();
237  model->read_result(&ADModelResult); // this should be the square sum model result
238 
239  result = ADModelResult.first;
240  loss = ADModelResult.second;
241  score = ((loss).to_float()) * 16.0; //scaling to match threshold
242  //save score to class variable in case score saving needed
243  setScore(score);
244 
245  //number of objects/thrsholds to check
246  int iCondition = 0; // number of conditions: there is only one
247  int nObjInCond = m_gtAXOL1TLTemplate->nrObjects();
248 
249  if (iCondition >= nObjInCond || iCondition < 0) {
250  return false;
251  }
252 
253  const AXOL1TLTemplate::ObjectParameter objPar = (*(m_gtAXOL1TLTemplate->objectParameter()))[iCondition];
254 
255  // condGEqVal indicates the operator used for the condition (>=, =): true for >=
256  bool condGEqVal = m_gtAXOL1TLTemplate->condGEq();
257  bool passCondition = false;
258 
259  passCondition = checkCut(objPar.minAXOL1TLThreshold, score, condGEqVal);
260 
261  condResult |= passCondition; //condresult true if passCondition true else it is false
262 
263  //return result
264  return condResult;
265 }
const AXOL1TLTemplate * m_gtAXOL1TLTemplate
pointer to a AXOL1TLTemplate
const std::string & modelVersion() const
unsigned size(int bx) const
void setScore(const float scoreval) const
get/set score value
const bool condGEq() const
get / set condition GEq flag
const bool checkCut(const Type1 &cutL, const Type2 &value, bool condGEqValue) const
const T & at(int bx, unsigned i) const
const std::vector< ObjectParameter > * objectParameter() const
const GlobalBoard * m_gtGTB
pointer to uGt GlobalBoard, to be able to get the trigger objects
const BXVector< const l1t::L1Candidate * > * getCandL1Jet() const
pointer to Jet data list
Definition: GlobalBoard.h:168
const BXVector< const l1t::EtSum * > * getCandL1EtSum() const
pointer to EtSum data list
Definition: GlobalBoard.h:174
const BXVector< const l1t::Muon * > * getCandL1Mu() const
return global muon trigger candidate
Definition: GlobalBoard.h:159
const int & condRelativeBx() const
get / set the condition relative bx
const int nrObjects() const
get number of trigger objects
const BXVector< const l1t::L1Candidate * > * getCandL1EG() const
pointer to EG data list
Definition: GlobalBoard.h:165

◆ getScore()

float l1t::AXOL1TLCondition::getScore ( ) const
inline

Definition at line 65 of file AXOL1TLCondition.h.

References m_savedscore.

Referenced by l1t::GlobalBoard::runGTL().

65 { return m_savedscore; }
float m_savedscore
axo score for possible score saving

◆ gtAXOL1TLTemplate()

const AXOL1TLTemplate* l1t::AXOL1TLCondition::gtAXOL1TLTemplate ( ) const
inline

get / set the pointer to a Condition

Definition at line 53 of file AXOL1TLCondition.h.

References m_gtAXOL1TLTemplate.

53 { return m_gtAXOL1TLTemplate; }
const AXOL1TLTemplate * m_gtAXOL1TLTemplate
pointer to a AXOL1TLTemplate

◆ gtGTB()

const GlobalBoard* l1t::AXOL1TLCondition::gtGTB ( ) const
inline

get / set the pointer to GTL

Definition at line 58 of file AXOL1TLCondition.h.

References m_gtGTB.

58 { return m_gtGTB; }
const GlobalBoard * m_gtGTB
pointer to uGt GlobalBoard, to be able to get the trigger objects

◆ operator=()

l1t::AXOL1TLCondition & AXOL1TLCondition::operator= ( const AXOL1TLCondition cp)

Definition at line 77 of file AXOL1TLCondition.cc.

References filterCSVwithJSON::copy.

77  {
78  copy(cp);
79  return *this;
80 }
void copy(const AXOL1TLCondition &cp)
copy function for copy constructor and operator=

◆ print()

void AXOL1TLCondition::print ( std::ostream &  myCout) const
overridevirtual

print condition

Reimplemented from l1t::ConditionEvaluation.

Definition at line 267 of file AXOL1TLCondition.cc.

References l1t::ConditionEvaluation::print().

Referenced by l1t::GlobalBoard::runGTL().

267  {
268  myCout << "Dummy Print for AXOL1TLCondition" << std::endl;
269  m_gtAXOL1TLTemplate->print(myCout);
270 
272 }
const AXOL1TLTemplate * m_gtAXOL1TLTemplate
pointer to a AXOL1TLTemplate
void print(std::ostream &myCout) const override
print the condition
virtual void print(std::ostream &myCout) const
print condition

◆ setGtAXOL1TLTemplate()

void AXOL1TLCondition::setGtAXOL1TLTemplate ( const AXOL1TLTemplate caloTempl)

Definition at line 83 of file AXOL1TLCondition.cc.

83 { m_gtAXOL1TLTemplate = caloTempl; }
const AXOL1TLTemplate * m_gtAXOL1TLTemplate
pointer to a AXOL1TLTemplate

◆ setScore()

void AXOL1TLCondition::setScore ( const float  scoreval) const

get/set score value

set score for score saving

Definition at line 89 of file AXOL1TLCondition.cc.

89 { m_savedscore = scoreval; }
float m_savedscore
axo score for possible score saving

◆ setuGtB()

void AXOL1TLCondition::setuGtB ( const GlobalBoard ptrGTB)

set the pointer to uGT GlobalBoard

Definition at line 86 of file AXOL1TLCondition.cc.

86 { m_gtGTB = ptrGTB; }
const GlobalBoard * m_gtGTB
pointer to uGt GlobalBoard, to be able to get the trigger objects

Member Data Documentation

◆ m_gtAXOL1TLTemplate

const AXOL1TLTemplate* l1t::AXOL1TLCondition::m_gtAXOL1TLTemplate
private

pointer to a AXOL1TLTemplate

Definition at line 72 of file AXOL1TLCondition.h.

Referenced by gtAXOL1TLTemplate().

◆ m_gtGTB

const GlobalBoard* l1t::AXOL1TLCondition::m_gtGTB
private

pointer to uGt GlobalBoard, to be able to get the trigger objects

Definition at line 75 of file AXOL1TLCondition.h.

Referenced by gtGTB().

◆ m_savedscore

float l1t::AXOL1TLCondition::m_savedscore
mutableprivate

axo score for possible score saving

Definition at line 78 of file AXOL1TLCondition.h.

Referenced by getScore().