ATLAS Offline Software
Loading...
Searching...
No Matches
Artemis_2A.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4/*********************************
5 * Artemis_2A.cxx
6 * Created by Paula Martinez Suarez, Ralf Gugel, Sagar Addepalli on 09/12/2025.
7 *
8 * @brief A Rapid Tagger Electing Missed Interesting Signatures:
9 * algorithm uses a variational auto-encoder based anomaly detection network
10 * Uses 6 jets, 4 muons, 4 taus, and MET to calculate the anomaly score
11 * based on the KL-divergence in a lower dimension latent space
12 *
13 * @param MinEt1 : zero any jJet TOB if its ET is below this value
14 * @param MinEt2 : zero any eTau TOB if its ET is below this value
15 * @param MinEt3 : zero any Muon TOB if its ET is below this value
16 * @param MinEt4 : zero jXE TOB if its ET is below this value
17 * @param MaxEt1 : veto event if any jJet ET exceeds this value
18 * @param MaxEt2 : veto event if any eTau ET exceeds this value
19 * @param MaxEt3 : veto event if any muon ET exceeds this value
20 * @param MaxEt4 : veto event if jXE exceeds this value
21 * @param AnomalyScoreThresh
22**********************************/
23
24#include <cmath>
25
30//TODO: replace once correct ARTEMIS NN is available via Externals, using Gelato NN as placeholder for now
31#include <VAENetwork.h>
32
33REGISTER_ALG_TCS(ARTEMIS_2A)
34
35
37{
38 defineParameter("InputWidth1", 6);
39 defineParameter("InputWidth2", 6);
40 defineParameter("InputWidth3", 6);
41 defineParameter("InputWidth4", 1);
42 defineParameter("MaxTob1", 6);
43 defineParameter("MaxTob2", 4);
44 defineParameter("MaxTob3", 4);
45 defineParameter("MaxTob4", 1);
46 defineParameter("NumResultBits", 2);
47
48 // Version parameter, used for L1TopoFW book-keeping, no practical application for now
49 defineParameter("Version", 1);
50 // minEt cuts, one per input list (TOBs failing these are set to ET = eta = phi = 0)
51 defineParameter("MinET1",0);
52 defineParameter("MinET2",0);
53 defineParameter("MinET3",0);
54 defineParameter("MinET4",0);
55 // maxEt cuts, veto event if a TOB exceeds its corresponding threshold to avoid excessive triggering at (trivial) high-ET
56 defineParameter("MaxET1",0);
57 defineParameter("MaxET2",0);
58 defineParameter("MaxET3",0);
59 defineParameter("MaxET4",0);
60 // The value used is sum of squares of the NN result vector elements, bit-shifted by 8 to get all decimal bits
61 defineParameter("AnomalyScoreThresh", 1000000, 0);
62 defineParameter("AnomalyScoreThresh", 1000000, 1);
63
65}
66
68
69
72 p_NumberLeading1 = parameter("InputWidth1").value();
73 p_NumberLeading2 = parameter("InputWidth2").value();
74 p_NumberLeading3 = parameter("InputWidth3").value();
75 p_NumberLeading4 = parameter("InputWidth4").value();
76
77 if(parameter("MaxTob1").value() > 0) p_NumberLeading1 = parameter("MaxTob1").value();
78 if(parameter("MaxTob2").value() > 0) p_NumberLeading2 = parameter("MaxTob2").value();
79 if(parameter("MaxTob3").value() > 0) p_NumberLeading3 = parameter("MaxTob3").value();
80 if(parameter("MaxTob4").value() > 0) p_NumberLeading4 = parameter("MaxTob4").value();
81
82 p_minEt1 = parameter("MinET1").value();
83 p_minEt2 = parameter("MinET2").value();
84 p_minEt3 = parameter("MinET3").value();
85 p_minEt4 = parameter("MinET4").value();
86
87 p_maxEt1 = parameter("MaxET1").value();
88 p_maxEt2 = parameter("MaxET2").value();
89 p_maxEt3 = parameter("MaxET3").value();
90 p_maxEt4 = parameter("MaxET4").value();
91
92 for(unsigned int i=0; i<numberOutputBits(); ++i) {
93 p_AnomalyScoreThresh[i] = parameter("AnomalyScoreThresh", i).value();
94 }
95
96 TRG_MSG_INFO("number output : " << numberOutputBits());
97
98 // book histograms
99 for(unsigned int i=0; i<numberOutputBits(); ++i) {
100 std::string hname_accept = "hAnomalyScore_accept_bit"+std::to_string((int)i);
101 std::string hname_reject = "hAnomalyScore_reject_bit"+std::to_string((int)i);
102 // score
103 bookHist(m_histAccept, hname_accept, "ADScore", 2000, 0, 2000000);
104 bookHist(m_histReject, hname_reject, "ADScore", 2000, 0, 2000000);
105 }
106
107 return StatusCode::SUCCESS;
108}
109
110
112TCS::ARTEMIS_2A::processBitCorrect( const std::vector<TCS::TOBArray const *> & input,
113 const std::vector<TCS::TOBArray *> & output,
114 Decision & decision )
115{
116
117
118 if( input.size() == 4) {
119
120 TCS::TOBArray const* jets = input[0];
121 TCS::TOBArray const* taus = input[1];
122 TCS::TOBArray const* mus = input[2];
123 TCS::TOBArray const* met = input[3];
124 TRG_MSG_DEBUG("Number of jets are " << (*jets).size());
125 TRG_MSG_DEBUG("Number of taus are " << (*taus).size());
126 TRG_MSG_DEBUG("Number of mus are " << (*mus).size());
127 TRG_MSG_DEBUG("Number of met are " << (*met).size());
128
129 //check for ambiguous sorting and set corresponding flag if an ambiguity is found
130 bool hasAmbiguousInputs = TSU::isAmbiguousTruncation(jets, p_NumberLeading1, p_minEt1)
138
139 std::vector<u_int> jet_pt(6,0), tau_pt(4,0), mu_pt(4,0), met_pt(1,0);
140 std::vector<int> jet_eta(6,0), tau_eta(4,0), mu_eta(4,0); //no met_eta
141 std::vector<int> jet_phi(6,0), tau_phi(4,0), mu_phi(4,0), met_phi(1,0);
142
143 bool highEtVeto = false;
144
145 for (u_int i = 0; i<(*jets).size() && i<6; ++i) {
146 if ( parType_t( (*jets)[i].Et() ) <= p_minEt1 ) { continue; } //ET cut, leave NN inputs at default values (0)
147 if ( p_maxEt1 > 0 && parType_t( (*jets)[i].Et() ) > p_maxEt1 ) { highEtVeto = true; } // high-Et veto, to be applied later
148 jet_pt[i] = (*jets)[i].Et();
149 jet_eta[i] = (*jets)[i].eta();
150 jet_phi[i] = (*jets)[i].phi();
151 }
152 for (u_int i = 0; i < (*taus).size() && i<4; ++i) {
153 if ( parType_t( (*taus)[i].Et() ) <= p_minEt2 ) { continue; } //ET cut, leave NN inputs at default values (0)
154 if ( p_maxEt2 > 0 &&parType_t( (*taus)[i].Et() ) > p_maxEt2 ) { highEtVeto = true; } // high-Et veto, to be applied later
155 tau_pt[i] = (*taus)[i].Et();
156 tau_eta[i] = (*taus)[i].eta();
157 tau_phi[i] = (*taus)[i].phi();
158 }
159 for (u_int i = 0; i < (*mus).size() && i<4; ++i) {
160 if ( parType_t( (*mus)[i].Et() ) <= p_minEt3 ) { continue; } //ET cut, leave NN inputs at default values (0)
161 if ( p_maxEt3 > 0 &&parType_t( (*mus)[i].Et() ) > p_maxEt3 ) { highEtVeto = true; } // high-Et veto, to be applied later
162 mu_pt[i] = (*mus)[i].Et();
163 mu_eta[i] = (*mus)[i].eta();
164 mu_phi[i] = (*mus)[i].phi();
165 }
166 for (u_int i = 0; i < (*met).size() && i<1; ++i) {
167 if ( parType_t( (*met)[i].Et() ) <= p_minEt4 ) { continue; } //ET cut, leave NN inputs at default values (0)
168 if ( p_maxEt4 > 0 && parType_t( (*met)[i].Et() ) > p_maxEt4 ) { highEtVeto = true; } // high-Et veto, to be applied later
169 met_pt[i] = (*met)[i].Et();
170 met_phi[i] = (*met)[i].phi();
171 }
172
173
174 ADVAE2A::VAENetwork AD_Network( jet_pt[0], jet_eta[0], jet_phi[0],
175 jet_pt[1], jet_eta[1], jet_phi[1],
176 jet_pt[2], jet_eta[2], jet_phi[2],
177 jet_pt[3], jet_eta[3], jet_phi[3],
178 jet_pt[4], jet_eta[4], jet_phi[4],
179 jet_pt[5], jet_eta[5], jet_phi[5],
180 tau_pt[0], tau_eta[0], tau_phi[0],
181 tau_pt[1], tau_eta[1], tau_phi[1],
182 tau_pt[2], tau_eta[2], tau_phi[2],
183 tau_pt[3], tau_eta[3], tau_phi[3],
184 mu_pt [0], mu_eta [0], mu_phi [0],
185 mu_pt [1], mu_eta [1], mu_phi [1],
186 mu_pt [2], mu_eta [2], mu_phi [2],
187 mu_pt [3], mu_eta [3], mu_phi [3],
188 met_pt[0], met_phi[0] );
189 std::vector<int64_t> anomScoreInt64Vec = AD_Network.getAnomalyScoreInt64Vec();
190
191 for(u_int i=0; i<numberOutputBits(); ++i) {
192 bool accept = false;
193 // Retrieve threshold
194 int32_t threshold = int32_t ( p_AnomalyScoreThresh[i] );
195 // Calculate event score
196 int64_t anomScoreInt64 = 0;
197 anomScoreInt64 = ( anomScoreInt64Vec.at(0)*anomScoreInt64Vec.at(0) ) +
198 ( anomScoreInt64Vec.at(1)*anomScoreInt64Vec.at(1) ) +
199 ( anomScoreInt64Vec.at(2)*anomScoreInt64Vec.at(2) );
200 if ( anomScoreInt64 > threshold && !highEtVeto ) {
201 accept = true;
202 decision.setBit(i, true);
203 for ( u_int j = 0; j<6 && j<(*jets).size(); ++j ) output[i]->push_back((*jets)[j]);
204 for ( u_int j = 0; j<4 && j<(*taus).size(); ++j ) output[i]->push_back((*taus)[j]);
205 for ( u_int j = 0; j<4 && j<(*mus).size() ; ++j ) output[i]->push_back((*mus) [j]);
206 output[i]->push_back((*met)[0]);
207 }
208 output[i]->setAmbiguityFlag(hasAmbiguousInputs);
209
210 if(fillHistos() and accept) {
211 fillHist1D(m_histAccept[i],anomScoreInt64);
212 } else if(fillHistos() && !accept) {
213 fillHist1D(m_histReject[i],anomScoreInt64);
214 }
215
216 TRG_MSG_DEBUG("Decision for bit" << i << ": " << (accept?"pass":"fail") << " anomaly score = " << anomScoreInt64 << std::endl);
217 }
218 } else {
219 TCS_EXCEPTION("ARTEMIS_2A alg must have 4 inputs, but got " << input.size());
220 }
221
223}
224
226TCS::ARTEMIS_2A::process( const std::vector<TCS::TOBArray const *> & input,
227 const std::vector<TCS::TOBArray *> & output,
228 Decision & decision )
229{
230 // as there is a bitwise implementation available use it
231 return this->processBitCorrect(input, output, decision);
232}
#define REGISTER_ALG_TCS(CLASS)
Definition AlgFactory.h:62
static Double_t taus
parType_t p_maxEt3
Definition Artemis_2A.h:44
parType_t p_NumberLeading3
Definition Artemis_2A.h:36
parType_t p_maxEt4
Definition Artemis_2A.h:45
parType_t p_NumberLeading2
Definition Artemis_2A.h:35
parType_t p_minEt2
Definition Artemis_2A.h:39
virtual StatusCode process(const std::vector< TCS::TOBArray const * > &input, const std::vector< TCS::TOBArray * > &output, Decision &decison)
virtual ~ARTEMIS_2A()
virtual StatusCode initialize()
parType_t p_NumberLeading4
Definition Artemis_2A.h:37
parType_t p_minEt4
Definition Artemis_2A.h:41
parType_t p_NumberLeading1
Definition Artemis_2A.h:34
parType_t p_AnomalyScoreThresh[2]
Definition Artemis_2A.h:46
virtual StatusCode processBitCorrect(const std::vector< TCS::TOBArray const * > &input, const std::vector< TCS::TOBArray * > &output, Decision &decison)
ARTEMIS_2A(const std::string &name)
parType_t p_maxEt2
Definition Artemis_2A.h:43
parType_t p_minEt1
Definition Artemis_2A.h:38
parType_t p_minEt3
Definition Artemis_2A.h:40
parType_t p_maxEt1
Definition Artemis_2A.h:42
const Parameter & parameter(const std::string &parameterName) const
const std::string & name() const
void bookHist(std::vector< std::string > &regName, const std::string &name, const std::string &title, const int binx, const int xmin, const int xmax)
void fillHist1D(const std::string &histName, double x)
void defineParameter(const std::string &name, TCS::parType_t value)
void setNumberOutputBits(unsigned int numberOutputBits)
Definition DecisionAlg.h:40
DecisionAlg(const std::string &name)
Definition DecisionAlg.h:25
bool fillHistos() const
whether the monitoring histograms should be filled
std::vector< std::string > m_histAccept
Definition DecisionAlg.h:73
std::vector< std::string > m_histReject
Definition DecisionAlg.h:74
unsigned int numberOutputBits() const
Definition DecisionAlg.h:39
void setBit(unsigned int index, bool value)
Definition Decision.cxx:12
uint32_t parType_t
Definition Parameter.h:22
bool isAmbiguousAnywhere(TCS::TOBArray const *tobs, size_t pos, unsigned minEt=0)
bool isAmbiguousTruncation(TCS::TOBArray const *tobs, size_t pos, unsigned minEt=0)
STL namespace.