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