ATLAS Offline Software
Loading...
Searching...
No Matches
Kinematics.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include <cmath>
6#include <string>
7#include <iostream>
8#include <sstream>
9#include <vector>
10
17
18
20 int dphiB = std::abs( tob1->phi() - tob2->phi() );
21 if(dphiB>64)
22 dphiB = dphiB - 64;
23 if(dphiB>32)
24 dphiB = 64 - dphiB;
25
26 return dphiB ;
27}
28
30 double deta = std::abs( tob1->eta() - tob2->eta() );
31 return deta;
32}
33
35
36 auto bit_cosheta = TSU::L1TopoDataTypes<19,7>(TSU::Hyperbolic::Coshleg.at(std::abs(tob1->eta() - tob2->eta())));
37 //In case of EM objects / jets / taus the phi angle goes between 0 and 64 while muons are between -32 and 32, applying a shift to keep delta-phi in the allowed range.
38 int phi_tob1 = tob1->phi();
39 int phi_tob2 = tob2->phi();
40 //those cases should happen only in mixed EM/jets/tau plus mu triggers, if both phi's are in [0,2pi] will not get in
41 if ( std::abs(phi_tob1-phi_tob2)>=64 )
42 {
43 if(phi_tob1 >= 32) phi_tob1 = phi_tob1-64;
44 if(phi_tob2 >= 32) phi_tob2 = phi_tob2-64;
45 }
46 auto bit_cosphi = TSU::L1TopoDataTypes<9,7>(TSU::Trigo::Cosleg.at(std::abs( phi_tob1 - phi_tob2 )));
47 TSU::L1TopoDataTypes<11,0> bit_Et1(tob1->Et());
48 TSU::L1TopoDataTypes<11,0> bit_Et2(tob2->Et());
49 auto bit_invmass2 = bit_Et1*bit_Et2*(bit_cosheta - bit_cosphi)*2;
50 return static_cast<unsigned>(bit_invmass2) ;
51}
52
54 auto bit_cosphi = TSU::L1TopoDataTypes<9,7>(TSU::Trigo::Cosleg.at(std::abs(tob1->phi() - tob2->phi())));
55 TSU::L1TopoDataTypes<11,0> bit_Et1(tob1->Et());
56 TSU::L1TopoDataTypes<11,0> bit_Et2(tob2->Et());
57 TSU::L1TopoDataTypes<22,0> bit_tmass2 = 2*bit_Et1*bit_Et2*(1. - bit_cosphi);
58 return static_cast<unsigned>(bit_tmass2) ;
59 // end bitwise implementation
60}
61
63 int detaB = std::abs( tob1->eta() - tob2->eta() );
64 int dphiB = std::abs( tob1->phi() - tob2->phi() );
65 if(dphiB>64) //Probably same error here as in DeltaPhiBW. Check
66 dphiB = dphiB - 64;
67 if(dphiB>32)
68 dphiB = 64 - dphiB;
69
70 unsigned int bit_dr2 = dphiB*dphiB + detaB*detaB;
71 return bit_dr2;
72}
73
75 return static_cast<float>(TSU::L1TopoDataTypes<9,7>(TSU::Trigo::Cosleg.at(phi)));
76}
77
79 return static_cast<float>(TSU::L1TopoDataTypes<9,7>(TSU::Trigo::Sinleg.at(phi)));
80}
81
83 int dphiB = std::abs( tob1->phi() - tob2->phi() );
84 if(dphiB>128)
85 dphiB = dphiB - 128;
86 if(dphiB>64)
87 dphiB = 128 - dphiB;
88
89 return dphiB ;
90}
91
92unsigned int TSU::Kinematics::calcDeltaEtaBW(const TCS::GenericTOB* tob1, const TCS::GenericTOB* tob2) {
93 double deta = std::abs( tob1->eta() - tob2->eta() );
94 return deta;
95}
96
97unsigned int TSU::Kinematics::calcInvMassBW(const TCS::GenericTOB* tob1, const TCS::GenericTOB* tob2){
98
99 auto bit_cosheta = TSU::L1TopoDataTypes<25,10>(TSU::Hyperbolic::Cosh.at(std::abs(tob1->eta() - tob2->eta())));
100 //In case of EM objects / jets / taus the phi angle goes between 0 and 128 while muons are between -128 and 128, applying a shift to keep delta-phi in the allowed range.
101 //those cases should happen only in mixed EM/jets/tau plus mu triggers, if both phi's are in [0,2pi] will not get in
102 int phi_tob1 = tob1->phi();
103 int phi_tob2 = tob2->phi();
104 if ( std::abs(phi_tob1-phi_tob2)>=128 )
105 {
106 if(phi_tob1 >= 64) phi_tob1 = phi_tob1-128;
107 if(phi_tob2 >= 64) phi_tob2 = phi_tob2-128;
108 }
109 auto bit_cosphi = TSU::L1TopoDataTypes<12,10>(TSU::Trigo::Cos.at(std::abs( phi_tob1 - phi_tob2 )));
110 TSU::L1TopoDataTypes<15,0> bit_Et1(tob1->Et());
111 TSU::L1TopoDataTypes<15,0> bit_Et2(tob2->Et());
112 auto bit_invmass2 = bit_Et1*bit_Et2*(bit_cosheta - bit_cosphi)*2;
113
114 auto u_invmass2 = static_cast<unsigned long long>(bit_invmass2);
115
116 if (u_invmass2 > std::numeric_limits<int>::max())
117 {return std::numeric_limits<int>::max();}
118 else
119 {return u_invmass2;}
120}
121
122unsigned int TSU::Kinematics::calcTMassBW(const TCS::GenericTOB* tob1, const TCS::GenericTOB* tob2) {
123 auto bit_cosphi = TSU::L1TopoDataTypes<12,10>(TSU::Trigo::Cos.at(std::abs(tob1->phi() - tob2->phi())));
124 TSU::L1TopoDataTypes<11,0> bit_Et1(tob1->Et());
125 TSU::L1TopoDataTypes<11,0> bit_Et2(tob2->Et());
126 TSU::L1TopoDataTypes<22,0> bit_tmass2 = 2*bit_Et1*bit_Et2*(1. - bit_cosphi);
127 return static_cast<unsigned>(bit_tmass2) ;
128 // end bitwise implementation
129}
130
131unsigned int TSU::Kinematics::calcDeltaR2BW(const TCS::GenericTOB* tob1, const TCS::GenericTOB* tob2) {
132 int detaB = std::abs( tob1->eta() - tob2->eta() );
133 int dphiB = std::abs( tob1->phi() - tob2->phi() );
134 if(dphiB>128) //Probably same error here as in DeltaPhiBW. Check
135 dphiB = dphiB - 128;
136 if(dphiB>64)
137 dphiB = 128 - dphiB;
138
139 // Use the same granularity for eta and phi (0.025) in dR calculation (need to multiply dphiB*2)
140 // Return (40*dR)^2
141 dphiB = 2*dphiB;
142 unsigned int bit_dr2 = dphiB*dphiB + detaB*detaB;
143 return bit_dr2;
144}
145
146unsigned long TSU::Kinematics::quadraticSumBW(int i1, int i2){
147 unsigned int ui1 = i1, ui2=i2;
148 unsigned int a = ui1*ui1 + ui2*ui2;
149
150 unsigned int result=0;
151 int left=0, right=0;
152 unsigned int r=0;
153 int sign=0;
154
155 //The values for halflength and bitmask enforce the
156 //bitwise overflow limit, not the precision of the chosen C++ parameters
157 int halflength = 16; //max 16
158 unsigned int bitmask = 0b11111111111111111111111111111111; //32 bits
159 bitmask >>= (32 - halflength*2); //does nothing unless halflength changes
160
161 for(int i = 0; i < halflength; i++){ //16-->4
162 right = 1 + (sign<<1) + (result<<2);
163 left = (r<<2) + (a >> (2*halflength-2));
164 a <<= 2;
165 a = a & bitmask;
166 r = sign ? (left + right) : (left - right);
167 sign = ((r & (1 << (halflength+1) )) > 0) ? 1 : 0;
168 result <<= 1;
169 if(sign==0) result += 1;
170 }
171 return result;
172}
173
174unsigned int TSU::Kinematics::calcXi1(const TCS::GenericTOB* tob1, const TCS::GenericTOB* tob2, unsigned ptShift, unsigned ptScale) {
175 //firmware: 19 bits unsigned + 1 sign bit due to L1TopoDataTypes assuming to be signed
176 TSU::L1TopoDataTypes<20,0> bit_Et1(static_cast<unsigned>(ptScale*tob1->Et()+ptShift));
177 TSU::L1TopoDataTypes<20,0> bit_Et2(static_cast<unsigned>(ptScale*tob2->Et()+ptShift));
178
179 //10 bits *unsigned* integer + 10 bits decimals + 1 sign bit since L1TopoDataTypes always assumes to represent signed values!
180 auto bit_eeta1 = TSU::L1TopoDataTypes<21,10>(TSU::Expo::E.at(tob1->eta()));
181 auto bit_eeta2 = TSU::L1TopoDataTypes<21,10>(TSU::Expo::E.at(tob2->eta()));
182
183 auto xi_bit = bit_Et1*bit_eeta1+bit_Et2*bit_eeta2;
184
185 return static_cast<unsigned>(xi_bit);
186}
187
188unsigned int TSU::Kinematics::calcXi2(const TCS::GenericTOB* tob1, const TCS::GenericTOB* tob2, unsigned ptShift, unsigned ptScale) {
189 TSU::L1TopoDataTypes<20,0> bit_Et1(static_cast<unsigned>(ptScale*tob1->Et()+ptShift));
190 TSU::L1TopoDataTypes<20,0> bit_Et2(static_cast<unsigned>(ptScale*tob2->Et()+ptShift));
191 auto bit_eeta1 = TSU::L1TopoDataTypes<21,10>(TSU::Expo::E.at(-tob1->eta()));
192 auto bit_eeta2 = TSU::L1TopoDataTypes<21,10>(TSU::Expo::E.at(-tob2->eta()));
193
194 auto xi_bit = bit_Et1*bit_eeta1+bit_Et2*bit_eeta2;
195
196 return static_cast<unsigned>(xi_bit);
197}
198
200 return static_cast<float>(TSU::L1TopoDataTypes<12,10>(TSU::Trigo::Cos.at(phi)));
201}
202
204 return static_cast<float>(TSU::L1TopoDataTypes<12,10>(TSU::Trigo::Sin.at(phi)));
205}
206
207/*------------------------------------------ NON-BITWISE --------------------------------------------------*/
208
210 double dphi = std::fabs( tob1->phiDouble() - tob2->phiDouble() );
211 if(dphi>M_PI)
212 dphi = 2*M_PI - dphi;
213
214 return round( 10 * dphi );
215}
216
218 double deta = std::fabs( tob1->etaDouble() - tob2->etaDouble() );
219 return round( 10 * deta );
220}
221
223 double deta = ( tob1->etaDouble() - tob2->etaDouble() );
224 double dphi = std::fabs( tob1->phiDouble() - tob2->phiDouble() );
225 if(dphi>M_PI)
226 dphi = 2*M_PI - dphi;
227
228 return round ( 100 * ((dphi)*(dphi) + (deta)*(deta) )) ;
229}
230
231unsigned int TSU::Kinematics::calcDeltaPhi(const TCS::GenericTOB* tob1, const TCS::GenericTOB* tob2) {
232 double dphi = std::fabs( tob1->phiDouble() - tob2->phiDouble() );
233 if(dphi>M_PI)
234 dphi = 2*M_PI - dphi;
235
236 return round( 20 * dphi );
237}
238
239unsigned int TSU::Kinematics::calcDeltaEta(const TCS::GenericTOB* tob1, const TCS::GenericTOB* tob2) {
240 double deta = std::fabs( tob1->etaDouble() - tob2->etaDouble() );
241 return round( 40 * deta );
242}
243
244unsigned int TSU::Kinematics::calcInvMass(const TCS::GenericTOB* tob1, const TCS::GenericTOB* tob2) {
245 double deta = std::fabs( tob1->etaDouble() - tob2->etaDouble() );
246 double dphi = std::fabs( tob1->phiDouble() - tob2->phiDouble() );
247 if(dphi>M_PI)
248 dphi = 2*M_PI - dphi;
249
250 double cosheta = cosh ( deta);
251 double cosphi = cos ( dphi);
252 double invmass2 = 2*tob1->Et()*tob2->Et()*(cosheta - cosphi);
253 return round( invmass2 );
254}
255
256unsigned int TSU::Kinematics::calcTMass(const TCS::GenericTOB* tob1, const TCS::GenericTOB* tob2) {
257 double dphi = std::fabs( tob1->phiDouble() - tob2->phiDouble() );
258 if(dphi>M_PI)
259 dphi = 2*M_PI - dphi;
260
261 double cosphi = cos ( dphi);
262 double tmass2 = 2*tob1->Et()*tob2->Et()*(1 - cosphi);
263 return round( tmass2 );
264}
265
266unsigned int TSU::Kinematics::calcDeltaR2(const TCS::GenericTOB* tob1, const TCS::GenericTOB* tob2) {
267 double deta = ( tob1->etaDouble() - tob2->etaDouble() );
268 double dphi = std::fabs( tob1->phiDouble() - tob2->phiDouble() );
269 if(dphi>M_PI)
270 dphi = 2*M_PI - dphi;
271
272 // Return (40*dR)^2 consistent with BW calculation
273 return round ( 40*40 * ((dphi)*(dphi) + (deta)*(deta) )) ;
274}
#define M_PI
Scalar phi() const
phi method
static Double_t a
int sign(int a)
double phiDouble() const
Definition GenericTOB.h:136
unsigned int Et() const
Definition GenericTOB.h:113
int eta() const
Definition GenericTOB.h:124
int phi() const
Definition GenericTOB.h:125
double etaDouble() const
Definition GenericTOB.h:135
int r
Definition globals.cxx:22
static const std::unordered_map< int, std::string > E
Definition Expo.h:8
static const std::vector< std::string > Cosh
Definition Hyperbolic.h:102
static const std::vector< std::string > Coshleg
Definition Hyperbolic.h:17
static unsigned int calcDeltaEtaBWLegacy(const TCS::GenericTOB *tob1, const TCS::GenericTOB *tob2)
static float calcCos(unsigned phi)
static unsigned int calcDeltaEtaBW(const TCS::GenericTOB *tob1, const TCS::GenericTOB *tob2)
static unsigned int calcTMass(const TCS::GenericTOB *tob1, const TCS::GenericTOB *tob2)
static unsigned int calcDeltaR2Legacy(const TCS::GenericTOB *tob1, const TCS::GenericTOB *tob2)
static unsigned int calcInvMassBW(const TCS::GenericTOB *tob1, const TCS::GenericTOB *tob2)
static unsigned int calcDeltaPhiBWLegacy(const TCS::GenericTOB *tob1, const TCS::GenericTOB *tob2)
static unsigned int calcDeltaPhi(const TCS::GenericTOB *tob1, const TCS::GenericTOB *tob2)
static unsigned int calcDeltaPhiLegacy(const TCS::GenericTOB *tob1, const TCS::GenericTOB *tob2)
static unsigned int calcDeltaEta(const TCS::GenericTOB *tob1, const TCS::GenericTOB *tob2)
static unsigned int calcInvMass(const TCS::GenericTOB *tob1, const TCS::GenericTOB *tob2)
static float calcSin(unsigned phi)
static unsigned int calcDeltaR2BW(const TCS::GenericTOB *tob1, const TCS::GenericTOB *tob2)
static unsigned int calcTMassBWLegacy(const TCS::GenericTOB *tob1, const TCS::GenericTOB *tob2)
static unsigned int calcXi1(const TCS::GenericTOB *tob1, const TCS::GenericTOB *tob2, unsigned ptShift, unsigned ptScale)
static unsigned int calcDeltaPhiBW(const TCS::GenericTOB *tob1, const TCS::GenericTOB *tob2)
static unsigned int calcTMassBW(const TCS::GenericTOB *tob1, const TCS::GenericTOB *tob2)
static float calcCosLegacy(unsigned phi)
static unsigned int calcDeltaEtaLegacy(const TCS::GenericTOB *tob1, const TCS::GenericTOB *tob2)
static unsigned int calcInvMassBWLegacy(const TCS::GenericTOB *tob1, const TCS::GenericTOB *tob2)
static unsigned long quadraticSumBW(int i1, int i2)
compute the sum in quadrature of two ints
static unsigned int calcDeltaR2(const TCS::GenericTOB *tob1, const TCS::GenericTOB *tob2)
static unsigned int calcXi2(const TCS::GenericTOB *tob1, const TCS::GenericTOB *tob2, unsigned ptShift, unsigned ptScale)
static unsigned int calcDeltaR2BWLegacy(const TCS::GenericTOB *tob1, const TCS::GenericTOB *tob2)
static float calcSinLegacy(unsigned phi)
static const std::vector< std::string > Sin
Definition Trigo.h:305
static const std::vector< std::string > Cos
Definition Trigo.h:100
static const std::vector< std::string > Sinleg
Definition Trigo.h:234
static const std::vector< std::string > Cosleg
Definition Trigo.h:28