-
Notifications
You must be signed in to change notification settings - Fork 0
/
AliXXXAux.h
168 lines (146 loc) · 6.23 KB
/
AliXXXAux.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#ifndef ALIXXXAUX
#define ALIXXXAUX
///////////////////////////////////////////////////////////////////////
// //
// Namespace AliXXXAux //
// Set of utilities for the XXX classes //
// //
///////////////////////////////////////////////////////////////////////
namespace AliXXXAux {
void BringTo02Pi(double &phi);
void BringTo02Pi(float &phi);
bool OKforPhiMin(double phiMin,double phi);
bool OKforPhiMax(double phiMax,double phi);
double MeanPhiSmall(double phi0, double phi1);
double DeltaPhiSmall(double phi0, double phi1);
//
bool OKforPhiMin(float phiMin,float phi);
bool OKforPhiMax(float phiMax,float phi);
float MeanPhiSmall(float phi0, float phi1);
float DeltaPhiSmall(float phi0, float phi1);
unsigned int PackCluster(int lr, int clID);
int UnpackCluster(unsigned int p, int &lr);
int UnpackLayer(unsigned int p);
int UnpackCluster(unsigned int p);
bool IsCluster(unsigned int p);
int NumberOfBitsSet(unsigned int x);
void PrintBits(unsigned long long patt, int maxBits);
//
const double kNominalBz = 5.01; // nominal field
const double kPionMass = 1.3957e-01;
const double kPi = 3.14159265358979312e+00;
const double k2Pi = 2*kPi;
const unsigned int kLrBitLow = 28; // layer mask lowest bit
const unsigned int kLrMask = 0xf0000000; // layer mask
const unsigned int kClMask = 0x0fffffff; // cluster mask
const unsigned int kMaxLayers = 15; // max number of active layers
const unsigned int kMaxLrMask = 0x7fff; // bitmask for allowed layers
}
//_________________________________________________________________________________
inline void AliXXXAux::BringTo02Pi(double &phi) {
// bring phi to 0-2pi range
if (phi<0) phi+=k2Pi; else if (phi>k2Pi) phi-=k2Pi;
}
//_________________________________________________________________________________
inline void AliXXXAux::BringTo02Pi(float &phi) {
// bring phi to 0-2pi range
if (phi<0) phi+=k2Pi; else if (phi>k2Pi) phi-=k2Pi;
}
//_________________________________________________________________________________
inline bool AliXXXAux::OKforPhiMin(double phiMin,double phi) {
// check if phi is above the phiMin, phi's must be in 0-2pi range
double dphi = phi-phiMin;
return ((dphi>0 && dphi<kPi) || dphi<-kPi) ? true:false;
}
//_________________________________________________________________________________
inline bool AliXXXAux::OKforPhiMin(float phiMin,float phi) {
// check if phi is above the phiMin, phi's must be in 0-2pi range
float dphi = phi-phiMin;
return ((dphi>0 && dphi<kPi) || dphi<-kPi) ? true:false;
}
//_________________________________________________________________________________
inline bool AliXXXAux::OKforPhiMax(double phiMax,double phi) {
// check if phi is below the phiMax, phi's must be in 0-2pi range
double dphi = phi-phiMax;
return ((dphi<0 && dphi>-kPi) || dphi>kPi) ? true:false;
}
//_________________________________________________________________________________
inline bool AliXXXAux::OKforPhiMax(float phiMax,float phi) {
// check if phi is below the phiMax, phi's must be in 0-2pi range
float dphi = phi-phiMax;
return ((dphi<0 && dphi>-kPi) || dphi>kPi) ? true:false;
}
//_________________________________________________________________________________
inline unsigned int AliXXXAux::PackCluster(int lr, int clID) {
// pack layer/cluster into single uint
unsigned int p = (clID<0 ? 0 : clID+1) + (lr<<=kLrBitLow);
return p;
}
//_________________________________________________________________________________
inline int AliXXXAux::UnpackCluster(unsigned int p, int &lr) {
// unpack layer/cluster
lr = (p&kLrMask)>>kLrBitLow;
p &= kClMask;
return int(p)-1;
}
//_________________________________________________________________________________
inline int AliXXXAux::UnpackLayer(unsigned int p) {
// unpack layer
return (p&kLrMask)>>kLrBitLow;
}
//_________________________________________________________________________________
inline int AliXXXAux::UnpackCluster(unsigned int p) {
// unpack cluster
return int(p&kClMask)-1;
}
//_________________________________________________________________________________
inline bool AliXXXAux::IsCluster(unsigned int p) {
// does it correspond to cluster?
return (p&kClMask);
}
//_________________________________________________________________________________
inline int AliXXXAux::NumberOfBitsSet(unsigned int x) {
// count number of non-0 bits in 32bit word
x = x - ((x >> 1) & 0x55555555);
x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
return (((x + (x >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24;
}
//_________________________________________________________________________________
inline double AliXXXAux::MeanPhiSmall(double phi0, double phi1) {
// return mean phi, assume phis in 0:2pi
double phi;
if (!OKforPhiMin(phi0,phi1)) {phi=phi0; phi0=phi1; phi1=phi;}
if (phi0>phi1) phi = (phi1 - (k2Pi-phi0))/2; // wrap
else phi = (phi0+phi1)/2;
BringTo02Pi(phi);
return phi;
}
//_________________________________________________________________________________
inline float AliXXXAux::MeanPhiSmall(float phi0, float phi1) {
// return mean phi, assume phis in 0:2pi
float phi;
if (!OKforPhiMin(phi0,phi1)) {phi=phi0; phi0=phi1; phi1=phi;}
if (phi0>phi1) phi = (phi1 - (k2Pi-phi0))/2; // wrap
else phi = (phi0+phi1)/2;
BringTo02Pi(phi);
return phi;
}
//_________________________________________________________________________________
inline double AliXXXAux::DeltaPhiSmall(double phi0, double phi1) {
// return delta phi, assume phis in 0:2pi
double del;
if (!OKforPhiMin(phi0,phi1)) {del=phi0; phi0=phi1; phi1=del;}
del = phi1 - phi0;
if (del<0) del += k2Pi;
return del;
}
//_________________________________________________________________________________
inline float AliXXXAux::DeltaPhiSmall(float phi0, float phi1) {
// return delta phi, assume phis in 0:2pi
float del;
if (!OKforPhiMin(phi0,phi1)) {del=phi0; phi0=phi1; phi1=del;}
del = phi1 - phi0;
if (del<0) del += k2Pi;
return del;
}
#endif