ATLAS Offline Software
Loading...
Searching...
No Matches
InvariantMassDeltaPhiInclusive1.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 * InvariantMassDeltaPhiInclusive1.cxx
6 * Based on implementation of InvariantMassDeltaPhiInclusive2. For questions contact atlas-trig-l1topo-algcom@cern.ch.
7 *
8 * @brief algorithm calculates the sqr of the INVMASS between all element of a list and applies invmass criteria.
9 * For pairs passing the INVMASS cut a further requirement based on DeltaPhi is applied, addressing ATR-19377
10 *
11**********************************/
12// TO DO size of the input list to be possbly refined
13
18
19#include <cmath>
20
21REGISTER_ALG_TCS(InvariantMassDeltaPhiInclusive1)
22
23
25{
26 defineParameter("InputWidth", 9);
27 defineParameter("MaxTob", 0);
28 defineParameter("NumResultBits", 6);
29 defineParameter("MinMSqr", 0, 0);
30 defineParameter("MaxMSqr", 999, 0);
31 defineParameter("MinMSqr", 0, 1);
32 defineParameter("MaxMSqr", 999, 1);
33 defineParameter("MinMSqr", 0, 2);
34 defineParameter("MaxMSqr", 999, 2);
35 defineParameter("MinMSqr", 0, 3);
36 defineParameter("MaxMSqr", 999, 3);
37 defineParameter("MinMSqr", 0, 4);
38 defineParameter("MaxMSqr", 999, 4);
39 defineParameter("MinMSqr", 0, 5);
40 defineParameter("MaxMSqr", 999, 5);
41 defineParameter("MinET1",0,0);
42 defineParameter("MinET1",0,1);
43 defineParameter("MinET1",0,2);
44 defineParameter("MinET1",0,3);
45 defineParameter("MinET1",0,4);
46 defineParameter("MinET1",0,5);
47 defineParameter("MinET2",0,0);
48 defineParameter("MinET2",0,1);
49 defineParameter("MinET2",0,2);
50 defineParameter("MinET2",0,3);
51 defineParameter("MinET2",0,4);
52 defineParameter("MinET2",0,5);
53 defineParameter("ApplyEtaCut", 0);
54 defineParameter("MinEta1", 0);
55 defineParameter("MaxEta1", 31);
56 defineParameter("MinEta2", 0);
57 defineParameter("MaxEta2", 31);
58 defineParameter("MinDeltaPhi", 0, 0);
59 defineParameter("MaxDeltaPhi", 31, 0);
60 defineParameter("MinDeltaPhi", 0, 1);
61 defineParameter("MaxDeltaPhi", 31, 1);
62 defineParameter("MinDeltaPhi", 0, 2);
63 defineParameter("MaxDeltaPhi", 31, 2);
64 defineParameter("MinDeltaPhi", 0, 3);
65 defineParameter("MaxDeltaPhi", 31, 3);
66 defineParameter("MinDeltaPhi", 0, 4);
67 defineParameter("MaxDeltaPhi", 31, 4);
68 defineParameter("MinDeltaPhi", 0, 5);
69 defineParameter("MaxDeltaPhi", 31, 5);
70 //does this need to change?
72}
73
75
76
79 p_NumberLeading = parameter("InputWidth").value();
80 if(parameter("MaxTob").value() > 0) p_NumberLeading = parameter("MaxTob").value();
81
82 for(unsigned int i=0; i<numberOutputBits(); ++i) {
83 p_InvMassMin[i] = parameter("MinMSqr", i).value();
84 p_InvMassMax[i] = parameter("MaxMSqr", i).value();
85 p_DeltaPhiMin[i] = parameter("MinDeltaPhi", i).value();
86 p_DeltaPhiMax[i] = parameter("MaxDeltaPhi", i).value();
87 p_MinET1[i] = parameter("MinET1",i).value();
88 p_MinET2[i] = parameter("MinET2",i).value();
89 }
90
91 TRG_MSG_INFO("NumberLeading : " << p_NumberLeading);
92 for(unsigned int i=0; i<numberOutputBits(); ++i) {
93 TRG_MSG_INFO("InvMassMin : " << p_InvMassMin[i]);
94 TRG_MSG_INFO("InvMassMax : " << p_InvMassMax[i]);
95 TRG_MSG_INFO("DeltaPhiMin : " << p_DeltaPhiMin[i]);
96 TRG_MSG_INFO("DeltaPhiMax : " << p_DeltaPhiMax[i]);
97 TRG_MSG_INFO("MinET1 : " << p_MinET1[i]);
98 TRG_MSG_INFO("MinET2 : " << p_MinET2[i]);
99 }
100
101 p_ApplyEtaCut = parameter("ApplyEtaCut").value();
102 p_MinEta1 = parameter("MinEta1" ).value();
103 p_MaxEta1 = parameter("MaxEta1" ).value();
104 p_MinEta2 = parameter("MinEta2" ).value();
105 p_MaxEta2 = parameter("MaxEta2" ).value();
106 TRG_MSG_INFO("ApplyEtaCut : "<<p_ApplyEtaCut );
107 TRG_MSG_INFO("MinEta1 : "<<p_MinEta1 );
108 TRG_MSG_INFO("MaxEta1 : "<<p_MaxEta1 );
109 TRG_MSG_INFO("MinEta2 : "<<p_MinEta2 );
110 TRG_MSG_INFO("MaxEta2 : "<<p_MaxEta2 );
111
112 TRG_MSG_INFO("number output : " << numberOutputBits());
113
114 // book histograms
115 for(unsigned int i=0; i<numberOutputBits(); ++i) {
116 std::string hname_accept = "hInvariantMassDeltaPhiInclusive1_accept_bit"+std::to_string((int)i);
117 std::string hname_reject = "hInvariantMassDeltaPhiInclusive1_reject_bit"+std::to_string((int)i);
118 // mass
119 bookHist(m_histAcceptM, hname_accept, "INVM vs DPHI", 100, sqrt(p_InvMassMin[i]), sqrt(p_InvMassMax[i]), 100, p_DeltaPhiMin[i], p_DeltaPhiMax[i]);
120 bookHist(m_histRejectM, hname_reject, "INVM vs DPHI", 100, sqrt(p_InvMassMin[i]), sqrt(p_InvMassMax[i]), 100, p_DeltaPhiMin[i], p_DeltaPhiMax[i]);
121 // eta2 vs. eta1
122 bookHist(m_histAcceptEta1Eta2, hname_accept, "ETA vs ETA", 100, p_MinEta1, p_MaxEta1, 100, p_MinEta2, p_MaxEta2);
123 bookHist(m_histRejectEta1Eta2, hname_reject, "ETA vs ETA", 100, p_MinEta1, p_MaxEta1, 100, p_MinEta2, p_MaxEta2);
124 }
125 return StatusCode::SUCCESS;
126}
127
128
129
131TCS::InvariantMassDeltaPhiInclusive1::processBitCorrect( const std::vector<TCS::TOBArray const *> & input,
132 const std::vector<TCS::TOBArray *> & output,
133 Decision & decision )
134{
135 int k=0; int j;
136 if( input.size() == 1) {
137 for( TOBArray::const_iterator tob1 = input[0]->begin();
138 tob1 != input[0]->end() && distance(input[0]->begin(), tob1) < p_NumberLeading;
139 ++tob1)
140 {
141 k++; j=0;
142 if (p_NumberLeading < input[0]->size()) {
143 TCS::TOBArray::const_iterator tob1_plus1 = tob1; ++tob1_plus1;
144 if ((*tob1)->Et() == (*tob1_plus1)->Et() && distance(input[0]->begin(), tob1) == p_NumberLeading - 1) {
145 for(unsigned int i=0; i<numberOutputBits(); ++i) {
146 output[i]->setAmbiguityFlag(true);
147 }
148 }
149 }
150 for( TCS::TOBArray::const_iterator tob2 = input[0]->begin();
151 tob2 != input[0]->end() && distance(input[0]->begin(), tob2) < p_NumberLeading;
152 ++tob2) {
153 j++; if(j==k) continue; //Avoid diagonal cases. Both above and below diagonal cases are calculated due to asymmetric ET and eta cuts
154 // Inv Mass calculation
155 unsigned int invmass2 = calcInvMassBW( *tob1, *tob2 );
156 // test DeltaPhiMin, DeltaPhiMax
157 unsigned int deltaPhi = calcDeltaPhiBW( *tob1, *tob2 );
158 const int eta1 = (*tob1)->eta();
159 const int eta2 = (*tob2)->eta();
160 const unsigned int aeta1 = std::abs(eta1);
161 const unsigned int aeta2 = std::abs(eta2);
162 for(unsigned int i=0; i<numberOutputBits(); ++i) {
163 bool accept = false;
164 if( parType_t((*tob1)->Et()) <= p_MinET1[i]) continue; // ET cut
165 if( parType_t((*tob2)->Et()) <= p_MinET2[i]) continue; // ET cut
166 if(p_ApplyEtaCut &&
167 ((aeta1 < p_MinEta1 || aeta1 > p_MaxEta1 ) ||
168 (aeta2 < p_MinEta2 || aeta2 > p_MaxEta2 ) )) continue;
169 accept = invmass2 >= p_InvMassMin[i] && invmass2 <= p_InvMassMax[i] && deltaPhi >= p_DeltaPhiMin[i] && deltaPhi <= p_DeltaPhiMax[i];
170 const bool fillAccept = fillHistos() and (fillHistosBasedOnHardware() ? getDecisionHardwareBit(i) : accept);
171 const bool fillReject = fillHistos() and not fillAccept;
172 const bool alreadyFilled = decision.bit(i);
173 if( accept ) {
174 decision.setBit(i, true);
175 output[i]->push_back( TCS::CompositeTOB(*tob1, *tob2) );
176 }
177 if(fillAccept and not alreadyFilled) {
178 fillHist2D(m_histAcceptM[i],sqrt((float)invmass2),(float)deltaPhi);
179 fillHist2D(m_histAcceptEta1Eta2[i],eta1, eta2);
180 } else if(fillReject) {
181 fillHist2D(m_histRejectM[i],sqrt((float)invmass2),(float)deltaPhi);
182 fillHist2D(m_histRejectEta1Eta2[i],eta1, eta2);
183 }
184 TRG_MSG_DEBUG("Decision " << i << ": " << (accept?"pass":"fail") << " invmass2 = " << invmass2);
185 }
186 }
187 }
188 for (unsigned int i=0; i < numberOutputBits(); ++i) {
189 bool hasAmbiguousInputs = TSU::isAmbiguousTruncation(input[0], p_NumberLeading, p_MinET1[i])
191 output[i]->setAmbiguityFlag(hasAmbiguousInputs);
192 }
193 } else {
194
195 TCS_EXCEPTION("InvariantMassDeltaPhiInclusive1 alg must have 1 inputs, but got " << input.size());
196
197 }
199
200}
201
203TCS::InvariantMassDeltaPhiInclusive1::process( const std::vector<TCS::TOBArray const *> & input,
204 const std::vector<TCS::TOBArray *> & output,
205 Decision & decision )
206{
207
208
209 if( input.size() == 1) {
210 int k=0; int j;
211 for( TOBArray::const_iterator tob1 = input[0]->begin();
212 tob1 != input[0]->end() && distance(input[0]->begin(), tob1) < p_NumberLeading;
213 ++tob1)
214 {
215 k++; j=0;
216 if (p_NumberLeading < input[0]->size()) {
217 TCS::TOBArray::const_iterator tob1_plus1 = tob1; ++tob1_plus1;
218 if ((*tob1)->Et() == (*tob1_plus1)->Et() && distance(input[0]->begin(), tob1) == p_NumberLeading - 1) {
219 for(unsigned int i=0; i<numberOutputBits(); ++i) {
220 output[i]->setAmbiguityFlag(true);
221 }
222 }
223 }
224 for( TCS::TOBArray::const_iterator tob2 = input[0]->begin();
225 tob2 != input[0]->end() && distance(input[0]->begin(), tob2) < p_NumberLeading;
226 ++tob2) {
227 j++; if (j==k) continue; //Avoid diagonal cases. Both above and below diagonal cases are calculated due to asymmetric ET and eta cuts
228 // Inv Mass calculation
229 unsigned int invmass2 = calcInvMass( *tob1, *tob2 );
230 // test DeltaPhiMin, DeltaPhiMax
231 unsigned int deltaPhi = calcDeltaPhi( *tob1, *tob2 );
232 const int eta1 = (*tob1)->eta();
233 const int eta2 = (*tob2)->eta();
234 const unsigned int aeta1 = std::abs(eta1);
235 const unsigned int aeta2 = std::abs(eta2);
236 for(unsigned int i=0; i<numberOutputBits(); ++i) {
237 if( parType_t((*tob1)->Et()) <= p_MinET1[i]) continue; // ET cut
238 if( parType_t((*tob2)->Et()) <= p_MinET2[i]) continue; // ET cut
239 if(p_ApplyEtaCut &&
240 ((aeta1 < p_MinEta1 || aeta1 > p_MaxEta1 ) ||
241 (aeta2 < p_MinEta2 || aeta2 > p_MaxEta2 ) )) continue;
242 bool accept = invmass2 >= p_InvMassMin[i] && invmass2 <= p_InvMassMax[i] && deltaPhi >= p_DeltaPhiMin[i] && deltaPhi <= p_DeltaPhiMax[i];
243 const bool fillAccept = fillHistos() and (fillHistosBasedOnHardware() ? getDecisionHardwareBit(i) : accept);
244 const bool fillReject = fillHistos() and not fillAccept;
245 const bool alreadyFilled = decision.bit(i);
246 if( accept ) {
247 decision.setBit(i, true);
248 output[i]->push_back( TCS::CompositeTOB(*tob1, *tob2) );
249 }
250 if(fillAccept and not alreadyFilled) {
251 fillHist2D(m_histAcceptM[i],sqrt((float)invmass2),(float)deltaPhi);
252 fillHist2D(m_histAcceptEta1Eta2[i],eta1, eta2);
253 } else if(fillReject) {
254 fillHist2D(m_histRejectM[i],sqrt((float)invmass2),(float)deltaPhi);
255 fillHist2D(m_histRejectEta1Eta2[i],eta1, eta2);
256 }
257 TRG_MSG_DEBUG("Decision " << i << ": " << (accept ?"pass":"fail") << " invmass2 = " << invmass2);
258 }
259 }
260 }
261 } else {
262 TCS_EXCEPTION("InvariantMassDeltaPhiInclusive1 alg must have 1 inputs, but got " << input.size());
263 }
265}
#define REGISTER_ALG_TCS(CLASS)
Definition AlgFactory.h:62
Scalar deltaPhi(const MatrixBase< Derived > &vec) const
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)
unsigned int calcDeltaPhiBW(const TCS::GenericTOB *tob1, const TCS::GenericTOB *tob2)
unsigned int calcInvMassBW(const TCS::GenericTOB *tob1, const TCS::GenericTOB *tob2)
void defineParameter(const std::string &name, TCS::parType_t value)
unsigned int calcDeltaPhi(const TCS::GenericTOB *tob1, const TCS::GenericTOB *tob2)
unsigned int calcInvMass(const TCS::GenericTOB *tob1, const TCS::GenericTOB *tob2)
void fillHist2D(const std::string &histName, double x, double y)
data_t::const_iterator const_iterator
std::vector< std::string > m_histAcceptEta1Eta2
Definition DecisionAlg.h:79
std::vector< std::string > m_histAcceptM
Definition DecisionAlg.h:75
void setNumberOutputBits(unsigned int numberOutputBits)
Definition DecisionAlg.h:40
DecisionAlg(const std::string &name)
Definition DecisionAlg.h:25
std::vector< std::string > m_histRejectEta1Eta2
Definition DecisionAlg.h:80
bool fillHistosBasedOnHardware() const
! getter
bool fillHistos() const
whether the monitoring histograms should be filled
unsigned int numberOutputBits() const
Definition DecisionAlg.h:39
bool getDecisionHardwareBit(const unsigned int &bitNumber) const
! get one hardware decision bit from this algo
std::vector< std::string > m_histRejectM
Definition DecisionAlg.h:76
bool bit(unsigned int index) const
Definition Decision.h:40
void setBit(unsigned int index, bool value)
Definition Decision.cxx:12
virtual StatusCode process(const std::vector< TCS::TOBArray const * > &input, const std::vector< TCS::TOBArray * > &output, Decision &decison) override final
virtual StatusCode processBitCorrect(const std::vector< TCS::TOBArray const * > &input, const std::vector< TCS::TOBArray * > &output, Decision &decison) override final
uint32_t parType_t
Definition Parameter.h:22
bool isAmbiguousTruncation(TCS::TOBArray const *tobs, size_t pos, unsigned minEt=0)
STL namespace.