ATLAS Offline Software
Loading...
Searching...
No Matches
TeAsymmetry.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 * TeAsymmetry.cpp
6 * Created by Jack Harrison on 12/05/25.
7 *
8 * @brief Based on the JIRA ticket: https://its.cern.ch/jira/browse/ATR-31097
9 * Three conditions are implemented:
10 * abs(jTE_A - jTE_C) > deltaAbsMin
11 * abs(jTE_A - jTE_C) > asymFactor * (jTE + asymOffset)
12 * jTE_A * jTE_C < maxTeProduct
13 *
14 * @param deltaAbsMin, asymFactor, asymOffset, maxTeProduct
15**********************************/
16
17
18#include <cmath>
19
24
25REGISTER_ALG_TCS(TeAsymmetry)
26
27
29{
30
31 defineParameter("InputWidth", 1);
32 defineParameter("MaxTob", 0);
33 defineParameter("NumResultBits", 4);
34 defineParameter("Delay", 1);
36
37 for (unsigned int i=0;i<numberOutputBits();i++){
38 // Algo parameters
39 defineParameter("deltaAbsMin", 0, i);
40 defineParameter("asymFactor", 0, i);
41 defineParameter("asymOffset", 0, i);
42 defineParameter("maxTeProduct", 0, i);
43 }
44
45 // Histo monitoring parameters
46 defineParameter("MinSidejTE",0);
47 defineParameter("MaxSidejTE",999);
48
49}
50
52
53
56
57 //Algo parameters
58 for (unsigned int i=0;i<numberOutputBits();i++){
59 p_deltaAbsMin[i] = parameter("deltaAbsMin", i).value();
60 p_asymFactor[i] = parameter("asymFactor", i).value();
61 p_asymOffset[i] = parameter("asymOffset", i).value();
62 p_maxTeProduct[i] = parameter("maxTeProduct", i).value();
63 }
64
65 // Histo monitoring
66 p_MinSidejTE = parameter("MinSidejTE").value();
67 p_MaxSidejTE = parameter("MaxSidejTE").value();
68
69 TRG_MSG_INFO("number output : " << numberOutputBits());
70
71 // book histograms
72 for(unsigned int i=0; i<numberOutputBits(); ++i) {
73 std::string hname_accept = "hTeAsymmetry_accept_bit"+std::to_string((int)i);
74 std::string hname_reject = "hTeAsymmetry_reject_bit"+std::to_string((int)i);
75 bookHist(m_histAccept, hname_accept, "jTE SideA vs jTE SideC", 100, p_MinSidejTE, p_MaxSidejTE, 100, p_MinSidejTE, p_MaxSidejTE);
76 bookHist(m_histReject, hname_reject, "jTE SideA vs jTE SideC", 100, p_MinSidejTE, p_MaxSidejTE, 100, p_MinSidejTE, p_MaxSidejTE);
77 }
78
80}
81
82
84TCS::TeAsymmetry::processBitCorrect( const std::vector<TCS::TOBArray const *> & input,
85 const std::vector<TCS::TOBArray *> & output,
86 Decision & decision )
87{
88 if(input.size() == 1) {
89
90 if (input[0]->size()!=1) {
91 TCS_EXCEPTION("TeAsymmetry alg needs input list with a single jTE TOB, got " << input[0]->size());
92 }
93
94 for( TOBArray::const_iterator jte = input[0]->begin();
95 jte != input[0]->end();
96 ++jte)
97 {
98
99 for(unsigned int i=0; i<numberOutputBits(); ++i) {
100
101 bool accept = false;
102
103 // Cast to long to avoid overflow
104 long long jteSideA = (*jte)->sumEtSideA();
105 long long jteSideC = (*jte)->sumEtSideC();
106
107 //std::cout << "jTE SideA: " << jteSideA << ", jTE SideC: " << jteSideC << " , " << p_deltaAbsMin[i] << " , " << abs(jteSideA - jteSideC) << std::endl;
108
109 bool condition_1 = std::abs(jteSideA - jteSideC) > p_deltaAbsMin[i];
110
111 //std::cout << "Condition 1: " << condition_1 << std::endl;
112 //attention: some of these values are to be interpreted as signed,
113 //but also need to explicitly cast unsigned quantities to have correct results
114 static constexpr unsigned c2fractionalBits = 8; // 8 fractional bits in p_asymFactor
115 int offsetSumEt = static_cast<int>((*jte)->sumEt()) + static_cast<int>(p_asymOffset[i]);
116 bool condition_2 = std::abs(jteSideA - jteSideC) > (( static_cast<long long>(p_asymFactor[i]) * offsetSumEt ) >> c2fractionalBits);
117 //std::cout << "Condition 2: " << condition_2 << std::endl;
118 bool condition_3 = jteSideA * jteSideC < p_maxTeProduct[i];
119 //std::cout << "Condition 3: " << condition_3 << std::endl;
120
121 //Write out to the output bit
122 accept = condition_1 && condition_2 && condition_3;
123 //std::cout << "Accept: " << accept << std::endl;
124
125
126 const bool fillAccept = fillHistos() and (fillHistosBasedOnHardware() ? getDecisionHardwareBit(i) : accept);
127 const bool fillReject = fillHistos() and not fillAccept;
128 const bool alreadyFilled = decision.bit(i);
129
130 TRG_MSG_DEBUG("Decision " << i << ": " << (accept?"pass":"fail") << " jTE_A = " << (*jte)->sumEtSideA() << " , jTE_C = " << (*jte)->sumEtSideC());
131
132 if( accept ) {
133 decision.setBit(i, true);
134 output[i]->push_back( TCS::CompositeTOB(*jte) );
135 }
136 if(fillAccept and not alreadyFilled) {
137 fillHist2D(m_histAccept[i], jteSideA, jteSideC);
138 } else if(fillReject) {
139 fillHist2D(m_histReject[i], jteSideA, jteSideC);
140 }
141 }
142 }
144 } else {
145 TCS_EXCEPTION("TeAsymmetry alg must have 1 input, but got " << input.size());
146 }
147}
148
150TCS::TeAsymmetry::process( const std::vector<TCS::TOBArray const *> & input,
151 const std::vector<TCS::TOBArray *> & output,
152 Decision & decision )
153{
154 return processBitCorrect(input, output, decision);
155}
#define REGISTER_ALG_TCS(CLASS)
Definition AlgFactory.h:62
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 defineParameter(const std::string &name, TCS::parType_t value)
void fillHist2D(const std::string &histName, double x, double y)
data_t::const_iterator const_iterator
void setNumberOutputBits(unsigned int numberOutputBits)
Definition DecisionAlg.h:40
DecisionAlg(const std::string &name)
Definition DecisionAlg.h:25
bool fillHistosBasedOnHardware() const
! getter
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
bool getDecisionHardwareBit(const unsigned int &bitNumber) const
! get one hardware decision bit from this algo
bool bit(unsigned int index) const
Definition Decision.h:40
void setBit(unsigned int index, bool value)
Definition Decision.cxx:12
parType_t p_asymFactor[4]
Definition TeAsymmetry.h:41
virtual StatusCode initialize()
virtual StatusCode processBitCorrect(const std::vector< TCS::TOBArray const * > &input, const std::vector< TCS::TOBArray * > &output, Decision &decison)
virtual StatusCode process(const std::vector< TCS::TOBArray const * > &input, const std::vector< TCS::TOBArray * > &output, Decision &decison)
parType_t p_MinSidejTE
Definition TeAsymmetry.h:38
parType_t p_MaxSidejTE
Definition TeAsymmetry.h:39
virtual ~TeAsymmetry()
parType_t p_maxTeProduct[4]
Definition TeAsymmetry.h:43
parType_t p_deltaAbsMin[4]
Definition TeAsymmetry.h:40
parType_t p_asymOffset[4]
Definition TeAsymmetry.h:42
TeAsymmetry(const std::string &name)
STL namespace.