]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/UPGRADE/ITSUpgradeBase/AliITSUAux.h
ITS UPGRADE
[u/mrichter/AliRoot.git] / ITS / UPGRADE / ITSUpgradeBase / AliITSUAux.h
CommitLineData
a11ef2e4 1#ifndef ALIITSUAUX
2#define ALIITSUAUX
3
4#include <TObject.h>
5#include <TMath.h>
6
7///////////////////////////////////////////////////////////////////////
8// //
9// Namespace AliITSUAux //
10// Set of utilities for the ITSU classes //
11// //
12///////////////////////////////////////////////////////////////////////
13
08419930 14#define _ITSU_TUNING_MODE_
e1ef49ad 15//#define _ITSU_DEBUG_
a11ef2e4 16
17class AliITSUGeomTGeo;
18class AliITSsegmentation;
19using namespace TMath;
20
08419930 21
a11ef2e4 22
23namespace AliITSUAux {
14fb7846 24 template<typename F>
25 void BringTo02Pi(F &phi);
a11ef2e4 26 Bool_t OKforPhiMin(double phiMin,double phi);
27 Bool_t OKforPhiMax(double phiMax,double phi);
68b7631d 28 Double_t MeanPhiSmall(double phi0, double phi1);
29 Double_t DeltaPhiSmall(double phi0, double phi1);
c61e50c3 30 UInt_t PackCluster(Int_t lr, Int_t clID);
f8832015 31 Int_t UnpackCluster(UInt_t p, Int_t &lr);
32 Int_t UnpackLayer(UInt_t p);
33 Int_t UnpackCluster(UInt_t p);
c61e50c3 34 Bool_t IsCluster(UInt_t p);
f8832015 35 Int_t NumberOfBitsSet(UInt_t x);
3c18eefd 36 void PrintBits(ULong64_t patt, Int_t maxBits);
32d38de2 37 //
38 const Double_t kNominalBz = 5.01; // nominal field
c61e50c3 39 const Double_t kPionMass = 1.3957e-01;
5a0f97ba 40 const UInt_t kLrBitLow = 28; // layer mask lowest bit
41 const UInt_t kLrMask = 0xf0000000; // layer mask
42 const UInt_t kClMask = 0x0fffffff; // cluster mask
f8832015 43 const UInt_t kMaxLayers = 15; // max number of active layers
70f61d86 44 const UInt_t kMaxLrMask = 0x7fff; // bitmask for allowed layers
a11ef2e4 45}
46
47//_________________________________________________________________________________
14fb7846 48template<typename F>
49inline void AliITSUAux::BringTo02Pi(F &phi) {
a11ef2e4 50 // bring phi to 0-2pi range
51 if (phi<0) phi+=TwoPi(); else if (phi>TwoPi()) phi-=TwoPi();
52}
53
54//_________________________________________________________________________________
55inline Bool_t AliITSUAux::OKforPhiMin(double phiMin,double phi) {
56 // check if phi is above the phiMin, phi's must be in 0-2pi range
57 double dphi = phi-phiMin;
58 return ((dphi>0 && dphi<Pi()) || dphi<-Pi()) ? kTRUE:kFALSE;
59}
60
61//_________________________________________________________________________________
62inline Bool_t AliITSUAux::OKforPhiMax(double phiMax,double phi) {
63 // check if phi is below the phiMax, phi's must be in 0-2pi range
64 double dphi = phi-phiMax;
65 return ((dphi<0 && dphi>-Pi()) || dphi>Pi()) ? kTRUE:kFALSE;
66}
67
c61e50c3 68//_________________________________________________________________________________
69inline UInt_t AliITSUAux::PackCluster(Int_t lr, Int_t clID) {
70 // pack layer/cluster into single uint
a616242b 71 UInt_t p = (clID<0 ? 0 : clID+1) + (lr<<=kLrBitLow);
5a0f97ba 72 return p;
c61e50c3 73}
74
75//_________________________________________________________________________________
f8832015 76inline Int_t AliITSUAux::UnpackCluster(UInt_t p, Int_t &lr) {
c61e50c3 77 // unpack layer/cluster
5a0f97ba 78 lr = (p&kLrMask)>>kLrBitLow;
79 p &= kClMask;
c61e50c3 80 return int(p)-1;
81}
82
f8832015 83//_________________________________________________________________________________
84inline Int_t AliITSUAux::UnpackLayer(UInt_t p) {
85 // unpack layer
5a0f97ba 86 return (p&kLrMask)>>kLrBitLow;
f8832015 87}
88
89//_________________________________________________________________________________
90inline Int_t AliITSUAux::UnpackCluster(UInt_t p) {
91 // unpack cluster
a616242b 92 return int(p&kClMask)-1;
f8832015 93}
94
c61e50c3 95//_________________________________________________________________________________
96inline Bool_t AliITSUAux::IsCluster(UInt_t p) {
97 // does it correspond to cluster?
5a0f97ba 98 return (p&kClMask);
c61e50c3 99}
100
f8832015 101//_________________________________________________________________________________
102inline Int_t AliITSUAux::NumberOfBitsSet(UInt_t x) {
103 // count number of non-0 bits in 32bit word
104 x = x - ((x >> 1) & 0x55555555);
105 x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
106 return (((x + (x >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24;
107}
108
68b7631d 109//_________________________________________________________________________________
110inline Double_t AliITSUAux::MeanPhiSmall(double phi0, double phi1) {
111 // return mean phi, assume phis in 0:2pi
112 double phi;
113 if (!OKforPhiMin(phi0,phi1)) {phi=phi0; phi0=phi1; phi1=phi;}
114 if (phi0>phi1) phi = (phi1 - (TwoPi()-phi0))/2; // wrap
115 else phi = (phi0+phi1)/2;
116 BringTo02Pi(phi);
117 return phi;
118}
119
120//_________________________________________________________________________________
121inline Double_t AliITSUAux::DeltaPhiSmall(double phi0, double phi1) {
122 // return delta phi, assume phis in 0:2pi
123 double del;
124 if (!OKforPhiMin(phi0,phi1)) {del=phi0; phi0=phi1; phi1=del;}
125 del = phi1 - phi0;
126 if (del<0) del += TwoPi();
127 return del;
128}
129
a11ef2e4 130
131#endif