]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/UPGRADE/AliITSUAux.h
Fix for ITS dictionaries
[u/mrichter/AliRoot.git] / ITS / UPGRADE / AliITSUAux.h
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
14 #define _ITSU_TUNING_MODE_
15 //#define _ITSU_DEBUG_
16
17 class AliITSUGeomTGeo;
18 class AliITSsegmentation;
19 using namespace TMath;
20
21
22
23 namespace AliITSUAux {
24   template<typename F>
25   void   BringTo02Pi(F &phi);
26   Bool_t OKforPhiMin(double phiMin,double phi);
27   Bool_t OKforPhiMax(double phiMax,double phi);
28   Double_t MeanPhiSmall(double phi0, double phi1);
29   Double_t DeltaPhiSmall(double phi0, double phi1);
30   UInt_t PackCluster(Int_t lr, Int_t clID);
31   Int_t  UnpackCluster(UInt_t p, Int_t &lr);
32   Int_t  UnpackLayer(UInt_t p);
33   Int_t  UnpackCluster(UInt_t p);
34   Bool_t IsCluster(UInt_t p);
35   Int_t  NumberOfBitsSet(UInt_t x);
36   void   PrintBits(ULong64_t patt, Int_t maxBits);
37   //
38   const Double_t kNominalBz = 5.01;           // nominal field
39   const Double_t kPionMass  = 1.3957e-01;
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
43   const UInt_t   kMaxLayers = 15;             // max number of active layers
44   const UInt_t   kMaxLrMask = 0x7fff;         // bitmask for allowed layers
45 }
46
47 //_________________________________________________________________________________
48 template<typename F>
49 inline void AliITSUAux::BringTo02Pi(F &phi) {
50   // bring phi to 0-2pi range
51   if (phi<0) phi+=TwoPi(); else if (phi>TwoPi()) phi-=TwoPi();
52 }
53
54 //_________________________________________________________________________________
55 inline 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 //_________________________________________________________________________________
62 inline 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
68 //_________________________________________________________________________________
69 inline UInt_t AliITSUAux::PackCluster(Int_t lr, Int_t clID) {
70   // pack layer/cluster into single uint
71   UInt_t p = (clID<0 ? 0 : clID+1) + (lr<<=kLrBitLow);
72   return p;
73 }
74
75 //_________________________________________________________________________________
76 inline Int_t AliITSUAux::UnpackCluster(UInt_t p, Int_t &lr) {
77   // unpack layer/cluster
78   lr = (p&kLrMask)>>kLrBitLow;
79   p &= kClMask;
80   return int(p)-1;
81 }
82
83 //_________________________________________________________________________________
84 inline Int_t AliITSUAux::UnpackLayer(UInt_t p) {
85   // unpack layer
86   return (p&kLrMask)>>kLrBitLow;
87 }
88
89 //_________________________________________________________________________________
90 inline Int_t AliITSUAux::UnpackCluster(UInt_t p) {
91   // unpack cluster
92   return int(p&kClMask)-1;
93 }
94
95 //_________________________________________________________________________________
96 inline Bool_t AliITSUAux::IsCluster(UInt_t p) {
97   // does it correspond to cluster?
98   return (p&kClMask);
99 }
100
101 //_________________________________________________________________________________
102 inline 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
109 //_________________________________________________________________________________
110 inline 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 //_________________________________________________________________________________
121 inline 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
130
131 #endif