24 #include <VAENetwork.h>
31 defineParameter(
"InputWidth1", 6);
32 defineParameter(
"InputWidth2", 6);
33 defineParameter(
"InputWidth3", 6);
34 defineParameter(
"InputWidth4", 1);
35 defineParameter(
"MaxTob1", 6);
36 defineParameter(
"MaxTob2", 4);
37 defineParameter(
"MaxTob3", 4);
38 defineParameter(
"MaxTob4", 1);
39 defineParameter(
"NumResultBits", 2);
42 defineParameter(
"ADVAEVersion", 1);
44 defineParameter(
"MinET1",0);
45 defineParameter(
"MinET2",0);
46 defineParameter(
"MinET3",0);
47 defineParameter(
"MinET4",0);
50 defineParameter(
"ScaleSqr1",128,0);
51 defineParameter(
"ScaleSqr2",128,0);
52 defineParameter(
"ScaleSqr3",128,0);
53 defineParameter(
"AnomalyScoreThresh", 1000000, 0);
54 defineParameter(
"ScaleSqr1",128,1);
55 defineParameter(
"ScaleSqr2",128,1);
56 defineParameter(
"ScaleSqr3",128,1);
57 defineParameter(
"AnomalyScoreThresh", 1000000, 1);
59 setNumberOutputBits(2);
67 p_NumberLeading1 = parameter(
"InputWidth1").value();
68 p_NumberLeading2 = parameter(
"InputWidth2").value();
69 p_NumberLeading3 = parameter(
"InputWidth3").value();
70 p_NumberLeading4 = parameter(
"InputWidth4").value();
72 if(parameter(
"MaxTob1").
value() > 0) p_NumberLeading1 = parameter(
"MaxTob1").value();
73 if(parameter(
"MaxTob2").
value() > 0) p_NumberLeading2 = parameter(
"MaxTob2").value();
74 if(parameter(
"MaxTob3").
value() > 0) p_NumberLeading3 = parameter(
"MaxTob3").value();
75 if(parameter(
"MaxTob4").
value() > 0) p_NumberLeading4 = parameter(
"MaxTob4").value();
77 p_minEt1 = parameter(
"MinET1").value();
78 p_minEt2 = parameter(
"MinET2").value();
79 p_minEt3 = parameter(
"MinET3").value();
80 p_minEt4 = parameter(
"MinET4").value();
82 for(
unsigned int i=0;
i<numberOutputBits(); ++
i) {
83 p_ScaleSqr1[
i] = parameter(
"ScaleSqr1",
i).value();
84 p_ScaleSqr2[
i] = parameter(
"ScaleSqr2",
i).value();
85 p_ScaleSqr3[
i] = parameter(
"ScaleSqr3",
i).value();
86 p_AnomalyScoreThresh[
i] = parameter(
"AnomalyScoreThresh",
i).value();
92 for(
unsigned int i=0;
i<numberOutputBits(); ++
i) {
93 std::string hname_accept =
"hAnomalyScore_accept_bit"+
std::to_string((
int)
i);
94 std::string hname_reject =
"hAnomalyScore_reject_bit"+
std::to_string((
int)
i);
96 bookHist(m_histAccept, hname_accept,
"ADScore", 2000, 0, 2000000);
97 bookHist(m_histReject, hname_reject,
"ADScore", 2000, 0, 2000000);
106 const std::vector<TCS::TOBArray *> & output,
111 if( input.size() == 4) {
128 std::vector<u_int> jet_pt(6,0), tau_pt(4,0),
mu_pt(4,0), met_pt(1,0);
129 std::vector<int> jet_eta(6,0), tau_eta(4,0),
mu_eta(4,0);
130 std::vector<int>
jet_phi(6,0), tau_phi(4,0),
mu_phi(4,0), met_phi(1,0);
132 for (u_int
i = 0;
i<(*jets).size() &&
i<6; ++
i) {
134 jet_pt[
i] = (*jets)[
i].Et();
135 jet_eta[
i] = (*jets)[
i].eta();
138 for (u_int
i = 0;
i < (*taus).size() &&
i<4; ++
i) {
139 if (
parType_t( (*taus)[
i].Et() ) <= p_minEt2 )
continue;
140 tau_pt[
i] = (*taus)[
i].Et();
141 tau_eta[
i] = (*taus)[
i].eta();
142 tau_phi[
i] = (*taus)[
i].phi();
144 for (u_int
i = 0;
i < (*mus).size() &&
i<4; ++
i) {
145 if (
parType_t( (*mus)[
i].Et() ) <= p_minEt3 )
continue;
150 for (u_int
i = 0;
i < (*met).size() &&
i<1; ++
i) {
152 met_pt[
i] = (*met)[
i].Et();
153 met_phi[
i] = (*met)[
i].phi();
164 TRG_MSG_DEBUG(
"Tau0: " << tau_pt[0] <<
", " << tau_eta[0] <<
", " << tau_phi[0] );
165 TRG_MSG_DEBUG(
"Tau1: " << tau_pt[1] <<
", " << tau_eta[1] <<
", " << tau_phi[1] );
166 TRG_MSG_DEBUG(
"Tau2: " << tau_pt[2] <<
", " << tau_eta[2] <<
", " << tau_phi[2] );
167 TRG_MSG_DEBUG(
"Tau3: " << tau_pt[3] <<
", " << tau_eta[3] <<
", " << tau_phi[3] );
174 TRG_MSG_DEBUG(
"MET: " << met_pt[0] <<
", " << met_phi[0] << std::endl);
176 ADVAE2A::VAENetwork AD_Network( jet_pt[0], jet_eta[0],
jet_phi[0],
177 jet_pt[1], jet_eta[1],
jet_phi[1],
178 jet_pt[2], jet_eta[2],
jet_phi[2],
179 jet_pt[3], jet_eta[3],
jet_phi[3],
180 jet_pt[4], jet_eta[4],
jet_phi[4],
181 jet_pt[5], jet_eta[5],
jet_phi[5],
182 tau_pt[0], tau_eta[0], tau_phi[0],
183 tau_pt[1], tau_eta[1], tau_phi[1],
184 tau_pt[2], tau_eta[2], tau_phi[2],
185 tau_pt[3], tau_eta[3], tau_phi[3],
190 met_pt[0], met_phi[0] );
191 std::vector<int64_t> anomScoreInt64Vec = AD_Network.getAnomalyScoreInt64Vec();
193 for(u_int
i=0;
i<numberOutputBits(); ++
i) {
196 int32_t
threshold = int32_t ( p_AnomalyScoreThresh[
i] );
198 int64_t anomScoreInt64 = 0;
199 anomScoreInt64 = (p_ScaleSqr1[
i] * anomScoreInt64Vec.at(0)*anomScoreInt64Vec.at(0) >> p_ScaleSqr_DropBits) +
200 (p_ScaleSqr2[
i] * anomScoreInt64Vec.at(1)*anomScoreInt64Vec.at(1) >> p_ScaleSqr_DropBits) +
201 (p_ScaleSqr3[
i] * anomScoreInt64Vec.at(2)*anomScoreInt64Vec.at(2) >> p_ScaleSqr_DropBits);
205 for ( u_int j = 0; j<6 && j<(*jets).size(); ++j ) output[
i]->push_back((*
jets)[j]);
206 for ( u_int j = 0; j<4 && j<(*taus).size(); ++j ) output[
i]->push_back((*taus)[j]);
207 for ( u_int j = 0; j<4 && j<(*mus).size() ; ++j ) output[
i]->push_back((*mus) [j]);
208 output[
i]->push_back((*
met)[0]);
210 output[
i]->setAmbiguityFlag(hasAmbiguousInputs);
212 if(fillHistos() and
accept) {
213 fillHist1D(m_histAccept[
i],anomScoreInt64);
214 }
else if(fillHistos() && !
accept) {
215 fillHist1D(m_histReject[
i],anomScoreInt64);
218 TRG_MSG_DEBUG(
"Decision for bit" <<
i <<
": " << (
accept?
"pass":
"fail") <<
" anomaly score = " << anomScoreInt64 << std::endl);
221 TCS_EXCEPTION(
"ADVAE_2A alg must have 4 inputs, but got " << input.size());
229 const std::vector<TCS::TOBArray *> & output,
234 if( input.size() == 4) {
245 std::vector<u_int> jet_pt(6,0), tau_pt(4,0),
mu_pt(4,0), met_pt(1,0);
246 std::vector<int> jet_eta(6,0), tau_eta(4,0),
mu_eta(4,0);
247 std::vector<int>
jet_phi(6,0), tau_phi(4,0),
mu_phi(4,0), met_phi(1,0);
249 for (u_int
i = 0;
i<(*jets).size() &&
i<6; ++
i) {
251 jet_pt[
i] = (*jets)[
i].Et();
252 jet_eta[
i] = (*jets)[
i].eta();
255 for (u_int
i = 0;
i < (*taus).size() &&
i<4; ++
i) {
256 if (
parType_t( (*taus)[
i].Et() ) <= p_minEt2 )
continue;
257 tau_pt[
i] = (*taus)[
i].Et();
258 tau_eta[
i] = (*taus)[
i].eta();
259 tau_phi[
i] = (*taus)[
i].phi();
261 for (u_int
i = 0;
i < (*mus).size() &&
i<4; ++
i) {
262 if (
parType_t( (*mus)[
i].Et() ) <= p_minEt3 )
continue;
267 for (u_int
i = 0;
i < (*met).size() &&
i<1; ++
i) {
269 met_pt[
i] = (*met)[
i].Et();
270 met_phi[
i] = (*met)[
i].phi();
273 ADVAE2A::VAENetwork AD_Network( jet_pt[0], jet_eta[0],
jet_phi[0],
274 jet_pt[1], jet_eta[1],
jet_phi[1],
275 jet_pt[2], jet_eta[2],
jet_phi[2],
276 jet_pt[3], jet_eta[3],
jet_phi[3],
277 jet_pt[4], jet_eta[4],
jet_phi[4],
278 jet_pt[5], jet_eta[5],
jet_phi[5],
279 tau_pt[0], tau_eta[0], tau_phi[0],
280 tau_pt[1], tau_eta[1], tau_phi[1],
281 tau_pt[2], tau_eta[2], tau_phi[2],
282 tau_pt[3], tau_eta[3], tau_phi[3],
287 met_pt[0], met_phi[0] );
288 std::vector<int64_t> anomScoreInt64Vec = AD_Network.getAnomalyScoreInt64Vec();
290 for(u_int
i=0;
i<numberOutputBits(); ++
i) {
293 int32_t
threshold = int32_t ( p_AnomalyScoreThresh[
i] );
295 int64_t anomScoreInt64 = 0;
296 anomScoreInt64 = p_ScaleSqr1[
i]/
std::pow(2,p_ScaleSqr_DropBits) * anomScoreInt64Vec.at(0)*anomScoreInt64Vec.at(0) +
297 p_ScaleSqr2[
i]/
std::pow(2,p_ScaleSqr_DropBits) * anomScoreInt64Vec.at(1)*anomScoreInt64Vec.at(1) +
298 p_ScaleSqr3[
i]/
std::pow(2,p_ScaleSqr_DropBits) * anomScoreInt64Vec.at(2)*anomScoreInt64Vec.at(2);
302 for ( u_int j = 0; j<6 && j<(*jets).size(); ++j ) output[
i]->push_back((*
jets)[j]);
303 for ( u_int j = 0; j<4 && j<(*taus).size(); ++j ) output[
i]->push_back((*taus)[j]);
304 for ( u_int j = 0; j<4 && j<(*mus).size() ; ++j ) output[
i]->push_back((*mus) [j]);
305 output[
i]->push_back((*
met)[0]);
308 if(fillHistos() and
accept) {
309 fillHist1D(m_histAccept[
i],anomScoreInt64);
310 }
else if(fillHistos() && !
accept) {
311 fillHist1D(m_histReject[
i],anomScoreInt64);
314 TRG_MSG_DEBUG(
"Decision for bit" <<
i <<
": " << (
accept?
"pass":
"fail") <<
" anomaly score = " << anomScoreInt64 << std::endl);
317 TCS_EXCEPTION(
"ADVAE_2A alg must have 4 inputs, but got " << input.size());