]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/UPGRADE/AliITSUAux.h
Reco Interface: changed sensor mapping in the layer to account for multiple rows
[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   void   BringTo02Pi(double &phi);
25   Bool_t OKforPhiMin(double phiMin,double phi);
26   Bool_t OKforPhiMax(double phiMax,double phi);
27   Double_t MeanPhiSmall(double phi0, double phi1);
28   Double_t DeltaPhiSmall(double phi0, double phi1);
29   UInt_t PackCluster(Int_t lr, Int_t clID);
30   Int_t  UnpackCluster(UInt_t p, Int_t &lr);
31   Int_t  UnpackLayer(UInt_t p);
32   Int_t  UnpackCluster(UInt_t p);
33   Bool_t IsCluster(UInt_t p);
34   Int_t  NumberOfBitsSet(UInt_t x);
35   void   PrintBits(ULong64_t patt, Int_t maxBits);
36   //
37   const Double_t kNominalBz = 5.01;           // nominal field
38   const Double_t kPionMass  = 1.3957e-01;
39   const UInt_t   kLrBitLow  = 28;             // layer mask lowest bit
40   const UInt_t   kLrMask    = 0xf0000000;     // layer mask
41   const UInt_t   kClMask    = 0x0fffffff;     // cluster mask
42   const UInt_t   kMaxLayers = 15;             // max number of active layers
43   const UInt_t   kMaxLrMask = 0x7fff;         // bitmask for allowed layers
44 }
45
46 //_________________________________________________________________________________
47 inline void AliITSUAux::BringTo02Pi(double &phi) {   
48   // bring phi to 0-2pi range
49   if (phi<0) phi+=TwoPi(); else if (phi>TwoPi()) phi-=TwoPi();
50 }
51
52 //_________________________________________________________________________________
53 inline Bool_t AliITSUAux::OKforPhiMin(double phiMin,double phi) {
54   // check if phi is above the phiMin, phi's must be in 0-2pi range
55   double dphi = phi-phiMin;
56   return ((dphi>0 && dphi<Pi()) || dphi<-Pi()) ? kTRUE:kFALSE;
57 }
58
59 //_________________________________________________________________________________
60 inline Bool_t AliITSUAux::OKforPhiMax(double phiMax,double phi) {
61   // check if phi is below the phiMax, phi's must be in 0-2pi range
62   double dphi = phi-phiMax;
63   return ((dphi<0 && dphi>-Pi()) || dphi>Pi()) ? kTRUE:kFALSE;
64 }
65
66 //_________________________________________________________________________________
67 inline UInt_t AliITSUAux::PackCluster(Int_t lr, Int_t clID) {
68   // pack layer/cluster into single uint
69   UInt_t p = (clID<0 ? 0 : clID+1) + (lr<<=kLrBitLow);
70   return p;
71 }
72
73 //_________________________________________________________________________________
74 inline Int_t AliITSUAux::UnpackCluster(UInt_t p, Int_t &lr) {
75   // unpack layer/cluster
76   lr = (p&kLrMask)>>kLrBitLow;
77   p &= kClMask;
78   return int(p)-1;
79 }
80
81 //_________________________________________________________________________________
82 inline Int_t AliITSUAux::UnpackLayer(UInt_t p) {
83   // unpack layer
84   return (p&kLrMask)>>kLrBitLow;
85 }
86
87 //_________________________________________________________________________________
88 inline Int_t AliITSUAux::UnpackCluster(UInt_t p) {
89   // unpack cluster
90   return int(p&kClMask)-1;
91 }
92
93 //_________________________________________________________________________________
94 inline Bool_t AliITSUAux::IsCluster(UInt_t p) {
95   // does it correspond to cluster?
96   return (p&kClMask);
97 }
98
99 //_________________________________________________________________________________
100 inline Int_t AliITSUAux::NumberOfBitsSet(UInt_t x) {
101   // count number of non-0 bits in 32bit word
102   x = x - ((x >> 1) & 0x55555555);
103   x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
104   return (((x + (x >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24;
105 }
106
107 //_________________________________________________________________________________
108 inline Double_t AliITSUAux::MeanPhiSmall(double phi0, double phi1) {
109   // return mean phi, assume phis in 0:2pi
110   double phi;
111   if (!OKforPhiMin(phi0,phi1)) {phi=phi0; phi0=phi1; phi1=phi;}
112   if (phi0>phi1) phi = (phi1 - (TwoPi()-phi0))/2; // wrap
113   else           phi = (phi0+phi1)/2;
114   BringTo02Pi(phi);
115   return phi;
116 }
117
118 //_________________________________________________________________________________
119 inline Double_t AliITSUAux::DeltaPhiSmall(double phi0, double phi1) {
120   // return delta phi, assume phis in 0:2pi
121   double del;
122   if (!OKforPhiMin(phi0,phi1)) {del=phi0; phi0=phi1; phi1=del;}
123   del = phi1 - phi0;
124   if (del<0) del += TwoPi();
125   return del;
126 }
127
128
129 #endif