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) {
132 std::vector<u_int> jet_pt(6,0), tau_pt(4,0),
mu_pt(4,0), met_pt(1,0);
133 std::vector<int> jet_eta(6,0), tau_eta(4,0),
mu_eta(4,0);
134 std::vector<int>
jet_phi(6,0), tau_phi(4,0),
mu_phi(4,0), met_phi(1,0);
136 for (u_int
i = 0;
i<(*jets).size() &&
i<6; ++
i) {
138 jet_pt[
i] = (*jets)[
i].Et();
139 jet_eta[
i] = (*jets)[
i].eta();
142 for (u_int
i = 0;
i < (*taus).size() &&
i<4; ++
i) {
143 if (
parType_t( (*taus)[
i].Et() ) <= p_minEt2 )
continue;
144 tau_pt[
i] = (*taus)[
i].Et();
145 tau_eta[
i] = (*taus)[
i].eta();
146 tau_phi[
i] = (*taus)[
i].phi();
148 for (u_int
i = 0;
i < (*mus).size() &&
i<4; ++
i) {
149 if (
parType_t( (*mus)[
i].Et() ) <= p_minEt3 )
continue;
154 for (u_int
i = 0;
i < (*met).size() &&
i<1; ++
i) {
156 met_pt[
i] = (*met)[
i].Et();
157 met_phi[
i] = (*met)[
i].phi();
168 TRG_MSG_DEBUG(
"Tau0: " << tau_pt[0] <<
", " << tau_eta[0] <<
", " << tau_phi[0] );
169 TRG_MSG_DEBUG(
"Tau1: " << tau_pt[1] <<
", " << tau_eta[1] <<
", " << tau_phi[1] );
170 TRG_MSG_DEBUG(
"Tau2: " << tau_pt[2] <<
", " << tau_eta[2] <<
", " << tau_phi[2] );
171 TRG_MSG_DEBUG(
"Tau3: " << tau_pt[3] <<
", " << tau_eta[3] <<
", " << tau_phi[3] );
178 TRG_MSG_DEBUG(
"MET: " << met_pt[0] <<
", " << met_phi[0] << std::endl);
180 ADVAE2A::VAENetwork AD_Network( jet_pt[0], jet_eta[0],
jet_phi[0],
181 jet_pt[1], jet_eta[1],
jet_phi[1],
182 jet_pt[2], jet_eta[2],
jet_phi[2],
183 jet_pt[3], jet_eta[3],
jet_phi[3],
184 jet_pt[4], jet_eta[4],
jet_phi[4],
185 jet_pt[5], jet_eta[5],
jet_phi[5],
186 tau_pt[0], tau_eta[0], tau_phi[0],
187 tau_pt[1], tau_eta[1], tau_phi[1],
188 tau_pt[2], tau_eta[2], tau_phi[2],
189 tau_pt[3], tau_eta[3], tau_phi[3],
194 met_pt[0], met_phi[0] );
195 std::vector<int64_t> anomScoreInt64Vec = AD_Network.getAnomalyScoreInt64Vec();
197 for(u_int
i=0;
i<numberOutputBits(); ++
i) {
200 int32_t
threshold = int32_t ( p_AnomalyScoreThresh[
i] );
202 int64_t anomScoreInt64 = 0;
203 anomScoreInt64 = (p_ScaleSqr1[
i] * anomScoreInt64Vec.at(0)*anomScoreInt64Vec.at(0) >> p_ScaleSqr_DropBits) +
204 (p_ScaleSqr2[
i] * anomScoreInt64Vec.at(1)*anomScoreInt64Vec.at(1) >> p_ScaleSqr_DropBits) +
205 (p_ScaleSqr3[
i] * anomScoreInt64Vec.at(2)*anomScoreInt64Vec.at(2) >> p_ScaleSqr_DropBits);
209 for ( u_int j = 0; j<6 && j<(*jets).size(); ++j ) output[
i]->push_back((*
jets)[j]);
210 for ( u_int j = 0; j<4 && j<(*taus).size(); ++j ) output[
i]->push_back((*taus)[j]);
211 for ( u_int j = 0; j<4 && j<(*mus).size() ; ++j ) output[
i]->push_back((*mus) [j]);
212 output[
i]->push_back((*
met)[0]);
214 output[
i]->setAmbiguityFlag(hasAmbiguousInputs);
216 if(fillHistos() and
accept) {
217 fillHist1D(m_histAccept[
i],anomScoreInt64);
218 }
else if(fillHistos() && !
accept) {
219 fillHist1D(m_histReject[
i],anomScoreInt64);
222 TRG_MSG_DEBUG(
"Decision for bit" <<
i <<
": " << (
accept?
"pass":
"fail") <<
" anomaly score = " << anomScoreInt64 << std::endl);
225 TCS_EXCEPTION(
"ADVAE_2A alg must have 4 inputs, but got " << input.size());
233 const std::vector<TCS::TOBArray *> & output,
238 if( input.size() == 4) {
249 std::vector<u_int> jet_pt(6,0), tau_pt(4,0),
mu_pt(4,0), met_pt(1,0);
250 std::vector<int> jet_eta(6,0), tau_eta(4,0),
mu_eta(4,0);
251 std::vector<int>
jet_phi(6,0), tau_phi(4,0),
mu_phi(4,0), met_phi(1,0);
253 for (u_int
i = 0;
i<(*jets).size() &&
i<6; ++
i) {
255 jet_pt[
i] = (*jets)[
i].Et();
256 jet_eta[
i] = (*jets)[
i].eta();
259 for (u_int
i = 0;
i < (*taus).size() &&
i<4; ++
i) {
260 if (
parType_t( (*taus)[
i].Et() ) <= p_minEt2 )
continue;
261 tau_pt[
i] = (*taus)[
i].Et();
262 tau_eta[
i] = (*taus)[
i].eta();
263 tau_phi[
i] = (*taus)[
i].phi();
265 for (u_int
i = 0;
i < (*mus).size() &&
i<4; ++
i) {
266 if (
parType_t( (*mus)[
i].Et() ) <= p_minEt3 )
continue;
271 for (u_int
i = 0;
i < (*met).size() &&
i<1; ++
i) {
273 met_pt[
i] = (*met)[
i].Et();
274 met_phi[
i] = (*met)[
i].phi();
277 ADVAE2A::VAENetwork AD_Network( jet_pt[0], jet_eta[0],
jet_phi[0],
278 jet_pt[1], jet_eta[1],
jet_phi[1],
279 jet_pt[2], jet_eta[2],
jet_phi[2],
280 jet_pt[3], jet_eta[3],
jet_phi[3],
281 jet_pt[4], jet_eta[4],
jet_phi[4],
282 jet_pt[5], jet_eta[5],
jet_phi[5],
283 tau_pt[0], tau_eta[0], tau_phi[0],
284 tau_pt[1], tau_eta[1], tau_phi[1],
285 tau_pt[2], tau_eta[2], tau_phi[2],
286 tau_pt[3], tau_eta[3], tau_phi[3],
291 met_pt[0], met_phi[0] );
292 std::vector<int64_t> anomScoreInt64Vec = AD_Network.getAnomalyScoreInt64Vec();
294 for(u_int
i=0;
i<numberOutputBits(); ++
i) {
297 int32_t
threshold = int32_t ( p_AnomalyScoreThresh[
i] );
299 int64_t anomScoreInt64 = 0;
300 anomScoreInt64 = p_ScaleSqr1[
i]/
std::pow(2,p_ScaleSqr_DropBits) * anomScoreInt64Vec.at(0)*anomScoreInt64Vec.at(0) +
301 p_ScaleSqr2[
i]/
std::pow(2,p_ScaleSqr_DropBits) * anomScoreInt64Vec.at(1)*anomScoreInt64Vec.at(1) +
302 p_ScaleSqr3[
i]/
std::pow(2,p_ScaleSqr_DropBits) * anomScoreInt64Vec.at(2)*anomScoreInt64Vec.at(2);
306 for ( u_int j = 0; j<6 && j<(*jets).size(); ++j ) output[
i]->push_back((*
jets)[j]);
307 for ( u_int j = 0; j<4 && j<(*taus).size(); ++j ) output[
i]->push_back((*taus)[j]);
308 for ( u_int j = 0; j<4 && j<(*mus).size() ; ++j ) output[
i]->push_back((*mus) [j]);
309 output[
i]->push_back((*
met)[0]);
312 if(fillHistos() and
accept) {
313 fillHist1D(m_histAccept[
i],anomScoreInt64);
314 }
else if(fillHistos() && !
accept) {
315 fillHist1D(m_histReject[
i],anomScoreInt64);
318 TRG_MSG_DEBUG(
"Decision for bit" <<
i <<
": " << (
accept?
"pass":
"fail") <<
" anomaly score = " << anomScoreInt64 << std::endl);
321 TCS_EXCEPTION(
"ADVAE_2A alg must have 4 inputs, but got " << input.size());