Using reference to TLorenzVector in one of the constructors, initialization of all...
[u/mrichter/AliRoot.git] / HMPID / AliHMPIDDigit.h
CommitLineData
d3da6dc4 1#ifndef AliHMPIDDigit_h
2#define AliHMPIDDigit_h
3/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * See cxx source for full Copyright notice */
5
ea925242 6// Class of HMPID to manage digits ---> pads
1b10372c 7//.
8//.
9//.
ea925242 10
d3da6dc4 11#include <AliDigit.h> //base class
49dfd67a 12#include <AliRawReader.h>
13#include <AliLog.h>
ea925242 14#include "TMath.h" //Mathieson()
d3da6dc4 15#include <AliBitPacking.h> //Raw()
1d4857c5 16
d3da6dc4 17
d3da6dc4 18class TClonesArray; //Hit2Sdi()
3c6274c1 19
d3da6dc4 20class AliHMPIDDigit :public AliDigit //TObject-AliDigit-AliHMPIDDigit
21{
22public:
a1d55ff3 23 enum EChamberData{kMinCh=0,kMaxCh=6,kMinPc=0,kMaxPc=5}; //Segmenation
24 enum EPadxData{kPadPcX=80,kMinPx=0,kMaxPx=79,kMaxPcx=159}; //Segmentation structure along x
25 enum EPadyData{kPadPcY=48,kMinPy=0,kMaxPy=47,kMaxPcy=143}; //Segmentation structure along y
d3da6dc4 26//ctor&dtor
1d4857c5 27 AliHMPIDDigit( ):AliDigit( ),fPad(Abs(-1,-1,-1,-1)),fQ(-1) {} //default ctor
28 AliHMPIDDigit(Int_t pad,Int_t q,Int_t *t):AliDigit(t),fPad(pad ),fQ(q ) {} //digit ctor
29 AliHMPIDDigit(const AliHMPIDDigit &d ):AliDigit(d),fPad(d.fPad),fQ(d.fQ) {} //copy ctor
30 virtual ~AliHMPIDDigit() {} //dtor
d3da6dc4 31//framework part
32 Bool_t IsSortable ( )const{return kTRUE;} //provision to use TObject::Sort()
33 inline Int_t Compare (const TObject *pObj )const; //provision to use TObject::Sort()
d1bf51e1 34 void Draw (Option_t *opt="" ); //TObject::Draw() overloaded
d3da6dc4 35 void Print (Option_t *opt="" )const; //TObject::Print() overloaded
36//private part
c5c19d6a 37 static Int_t Abs (Int_t ch,Int_t pc,Int_t x,Int_t y) {return ch*100000000+pc*1000000+x*1000+y; } //(ch,pc,padx,pady)-> abs pad
1d4857c5 38 static Int_t A2C (Int_t pad ) {return pad/100000000; } //abs pad -> chamber
39 static Int_t A2P (Int_t pad ) {return pad%100000000/1000000; } //abs pad -> pc
40 static Int_t A2X (Int_t pad ) {return pad%1000000/1000; } //abs pad -> pad X
41 static Int_t A2Y (Int_t pad ) {return pad%1000; } //abs pad -> pad Y
42 void AddTidOffset(Int_t offset ) {for (Int_t i=0; i<3; i++) if (fTracks[i]>0) fTracks[i]+=offset; } //needed for merging
43 Int_t Ch ( )const{return A2C(fPad); } //chamber number
a0e5c1b9 44 static Bool_t IsOverTh (Float_t q ) {return q >= fgSigmas; } //is digit over threshold?
0112d781 45 inline static Bool_t IsInDead(Float_t x,Float_t y ); //is point in dead area?
46 static Bool_t IsInside (Float_t x,Float_t y,Float_t d=0) {return x>-d&&y>-d&&x<fgkMaxPcX[kMaxPc]+d&&y<fgkMaxPcY[kMaxPc]+d; } //is point inside chamber boundary?
1d4857c5 47 Float_t LorsX ( )const{return LorsX(A2P(fPad),A2X(fPad)); } //center of the pad x, [cm]
0112d781 48 static Float_t LorsX (Int_t pc,Int_t padx ) {return (padx +0.5)*SizePadX()+fgkMinPcX[pc]; } //center of the pad x, [cm]
1d4857c5 49 Float_t LorsY ( )const{return LorsY(A2P(fPad),A2Y(fPad)); } //center of the pad y, [cm]
0112d781 50 static Float_t LorsY (Int_t pc,Int_t pady ) {return (pady +0.5)*SizePadY()+fgkMinPcY[pc]; } //center of the pad y, [cm]
c5c19d6a 51 inline Float_t IntMathieson(Float_t x,Float_t y )const; //Mathieson distribution
3c6274c1 52 Int_t PadPcX ( )const{return A2X(fPad);} //pad pc x # 0..79
53 Int_t PadPcY ( )const{return A2Y(fPad);} //pad pc y # 0..47
54 Int_t PadChX ( )const{return (Pc()%2)*kPadPcX+PadPcX();} //pad ch x # 0..159
55 Int_t PadChY ( )const{return (Pc()/2)*kPadPcY+PadPcY();} //pad ch y # 0..143
d3da6dc4 56 Int_t Pad ( )const{return fPad;} //absolute id of this pad
d3da6dc4 57 Int_t Pc ( )const{return A2P(fPad);} //PC position number
da08475b 58 Float_t Q ( )const{return fQ;} //charge, [QDC]
1d4857c5 59 inline void Raw (UInt_t &w32,Int_t &ddl,Int_t &r,Int_t &d,Int_t &a)const; //digit->(w32,ddl,r,d,a)
49dfd67a 60 inline Bool_t Raw (UInt_t w32,Int_t ddl,AliRawReader *pRR); //(w32,ddl)->digit
a0e5c1b9 61 inline void Raw (Int_t ddl,Int_t r,Int_t d,Int_t a); //raw->abs pad number
f3bae3e2 62 inline Bool_t Set (Int_t c,Int_t p,Int_t x,Int_t y,Int_t tid=0); //manual creation
63 void SetQ (Float_t q ) {fQ=q;} //manual creation
a0e5c1b9 64 void SetNsig (Int_t sigmas ) {fgSigmas=sigmas;} //set n sigmas
1d4857c5 65 static void WriteRaw (TObjArray *pDigLst ); //write as raw stream
d3da6dc4 66
ea925242 67 static Float_t MaxPcX (Int_t iPc ) {return fgkMaxPcX[iPc];} // PC limits
68 static Float_t MaxPcY (Int_t iPc ) {return fgkMaxPcY[iPc];} // PC limits
69 static Float_t MinPcX (Int_t iPc ) {return fgkMinPcX[iPc];} // PC limits
70 static Float_t MinPcY (Int_t iPc ) {return fgkMinPcY[iPc];} // PC limits
a0e5c1b9 71 static Int_t Nsig ( ) {return fgSigmas;} //Getter n. sigmas for noise
ea925242 72 static Float_t SizeAllX ( ) {return fgkMaxPcX[5];} //all PCs size x, [cm]
73 static Float_t SizeAllY ( ) {return fgkMaxPcY[5];} //all PCs size y, [cm]
d3da6dc4 74 static Float_t SizePadX ( ) {return 0.8;} //pad size x, [cm]
75 static Float_t SizePadY ( ) {return 0.84;} //pad size y, [cm]
ea925242 76 inline static void Lors2Pad(Float_t x,Float_t y,Int_t &pc,Int_t &px,Int_t &py); //(x,y)->(pc,px,py)
49dfd67a 77 enum EHMPIDRawError {
78 kInvalidRawDataWord = 1
79 };
c5c19d6a 80protected: //AliDigit has fTracks[3]
a0e5c1b9 81 static Int_t fgSigmas; //n. sigma to cut on charge
ea925242 82 static const Float_t fgkMinPcX[6]; //limits PC
83 static const Float_t fgkMinPcY[6]; //limits PC
84 static const Float_t fgkMaxPcX[6]; //limits PC
85 static const Float_t fgkMaxPcY[6]; //limits PC
1b10372c 86 Int_t fPad; //absolute pad number
c5c19d6a 87 Float_t fQ; //QDC value, fractions are permitted for summable procedure
88 ClassDef(AliHMPIDDigit,4) //HMPID digit class
89};//class AliHMPIDDigit
cf7e313e 90
d3da6dc4 91//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1d4857c5 92void AliHMPIDDigit::Lors2Pad(Float_t x,Float_t y,Int_t &pc,Int_t &px,Int_t &py)
d3da6dc4 93{
1d4857c5 94// Check the pad of given position
95// Arguments: x,y- position [cm] in LORS; pc,px,py- pad where to store the result
96// Returns: none
97 pc=px=py=-1;
0112d781 98 if (x>fgkMinPcX[0] && x<fgkMaxPcX[0]) {pc=0; px=Int_t( x / SizePadX());}//PC 0 or 2 or 4
99 else if(x>fgkMinPcX[1] && x<fgkMaxPcX[1]) {pc=1; px=Int_t((x-fgkMinPcX[1]) / SizePadX());}//PC 1 or 3 or 5
1d4857c5 100 else return;
0112d781 101 if (y>fgkMinPcY[0] && y<fgkMaxPcY[0]) { py=Int_t( y / SizePadY());}//PC 0 or 1
102 else if(y>fgkMinPcY[2] && y<fgkMaxPcY[2]) {pc+=2;py=Int_t((y-fgkMinPcY[2]) / SizePadY());}//PC 2 or 3
103 else if(y>fgkMinPcY[4] && y<fgkMaxPcY[4]) {pc+=4;py=Int_t((y-fgkMinPcY[4]) / SizePadY());}//PC 4 or 5
1d4857c5 104 else return;
105}
d3da6dc4 106//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
107Int_t AliHMPIDDigit::Compare(const TObject *pObj) const
108{
109// Used in Sort() method to compare to objects. Note that abs pad structure is first x then y, hence will be sorted on column basis.
110// This feature is used in digitizer to facilitate finding of sdigits for the same pad since they all will come together after sorting.
111// Arguments: pObj - pointer to object to compare with
112// Retunrs: -1 if AbsPad less then in pObj, 1 if more and 0 if they are the same
113 if (fPad==((AliHMPIDDigit*)pObj)->Pad()) return 0;
114 else if(fPad >((AliHMPIDDigit*)pObj)->Pad()) return 1;
da08475b 115 else return -1;
d3da6dc4 116}
117//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
118Bool_t AliHMPIDDigit::IsInDead(Float_t x,Float_t y)
119{
120// Check is the current point is outside of sensitive area or in dead zones
121// Arguments: x,y -position
122// Returns: 1 if not in sensitive zone
0112d781 123 for(Int_t iPc=0;iPc<=6;iPc++)
124 if(x>fgkMinPcX[iPc] && x<fgkMaxPcX[iPc] && y>fgkMinPcY[iPc] && y<fgkMaxPcY [iPc]) return kFALSE; //in current pc
d3da6dc4 125
0112d781 126 return kTRUE;
d3da6dc4 127}
128//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
c5c19d6a 129Float_t AliHMPIDDigit::IntMathieson(Float_t x,Float_t y)const
d3da6dc4 130{
c5c19d6a 131// Integration of Mathieson.
d3da6dc4 132// This is the answer to electrostatic problem of charge distrubution in MWPC described elsewhere. (NIM A370(1988)602-603)
133// Arguments: x,y- position of the center of Mathieson distribution
134// Returns: a charge fraction [0-1] imposed into the pad
0112d781 135 Float_t kK2=0.96242952, kSqrtK3 =0.77459667, kK4=0.37932926;
d3da6dc4 136
0112d781 137 Float_t ux1=kSqrtK3*TMath::TanH(kK2*(x-LorsX()+0.5*SizePadX())/0.445);
138 Float_t ux2=kSqrtK3*TMath::TanH(kK2*(x-LorsX()-0.5*SizePadX())/0.445);
139 Float_t uy1=kSqrtK3*TMath::TanH(kK2*(y-LorsY()+0.5*SizePadY())/0.445);
140 Float_t uy2=kSqrtK3*TMath::TanH(kK2*(y-LorsY()-0.5*SizePadY())/0.445);
141 return 4*kK4*(TMath::ATan(ux2)-TMath::ATan(ux1))*kK4*(TMath::ATan(uy2)-TMath::ATan(uy1));
d3da6dc4 142}
143//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1d4857c5 144void AliHMPIDDigit::Raw(UInt_t &w32,Int_t &ddl,Int_t &r,Int_t &d,Int_t &a)const
d3da6dc4 145{
146// Convert digit structure to raw word format
1d4857c5 147// Arguments: w32,ddl,r,d,a where to write the results
148// Returns: none
149 Int_t y2a[6]={5,3,1,0,2,4};
150
151 ddl=2*Ch()+Pc()%2; //DDL# 0..13
152 Int_t tmp=1+Pc()/2*8+PadPcY()/6; r=(Pc()%2)? 25-tmp:tmp; //row r=1..24
153 d=1+PadPcX()/8; //DILOGIC# 1..10
154 a=y2a[PadPcY()%6]+6*(PadPcX()%8); //ADDRESS 0..47
155
156 w32=0;
157 AliBitPacking::PackWord((UInt_t)fQ,w32, 0,11); // 0000 0rrr rrdd ddaa aaaa qqqq qqqq qqqq Qdc bits (00..11) counts (0..4095)
158 AliBitPacking::PackWord( a ,w32,12,17); // 3322 2222 2222 1111 1111 1000 0000 0000 DILOGIC address bits (12..17) counts (0..47)
159 AliBitPacking::PackWord( d ,w32,18,21); // 1098 7654 3210 9876 5432 1098 7654 3210 DILOGIC number bits (18..21) counts (1..10)
160 AliBitPacking::PackWord( r ,w32,22,26); // Row number bits (22..26) counts (1..24)
d3da6dc4 161}
162//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
49dfd67a 163Bool_t AliHMPIDDigit::Raw(UInt_t w32,Int_t ddl, AliRawReader *pRR)
d3da6dc4 164{
165// Converts a given raw data word to a digit
166// Arguments: w32 - 32 bits raw data word
167// ddl - DDL idx 0 1 2 3 4 ... 13
168// Returns: none
1d4857c5 169 Int_t r = AliBitPacking::UnpackWord(w32,22,26); assert(1<=r&&r<=24); // Row number (1..24)
170 Int_t d = AliBitPacking::UnpackWord(w32,18,21); assert(1<=d&&d<=10); // 3322 2222 2222 1111 1111 1000 0000 0000 DILOGIC number (1..10)
171 Int_t a = AliBitPacking::UnpackWord(w32,12,17); assert(0<=a&&a<=47); // 1098 7654 3210 9876 5432 1098 7654 3210 DILOGIC address (0..47)
a0e5c1b9 172 Int_t q = AliBitPacking::UnpackWord(w32, 0,11); assert(0<=q&&q<=4095); // 0000 0rrr rrdd ddaa aaaa qqqq qqqq qqqq Qdc (0..4095)
49dfd67a 173 if (r<1 || r>24 || d<1 || d>10 || a<0 || a>47 || q<0 || q>4095) {
174 AliWarning(Form("Invalid raw data word %x",w32));
175 pRR->AddMajorErrorLog(kInvalidRawDataWord,Form("w=%x",w32));
176 return kFALSE;
177 }
a0e5c1b9 178 Raw(ddl,r,d,a);
179 fQ=q;
49dfd67a 180 return kTRUE;
a0e5c1b9 181}
182//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
183void AliHMPIDDigit::Raw(Int_t ddl,Int_t r,Int_t d,Int_t a)
184{
56d2de52 185 assert(0<=ddl&&ddl<=13); assert(1<=r&&r<=24); assert(1<=d&&d<=10); assert(0<=a&&a<=47);
a0e5c1b9 186 Int_t a2y[6]={3,2,4,1,5,0};//pady for a given address (for single DILOGIC chip)
1d4857c5 187 Int_t ch=ddl/2;
188 Int_t tmp=(r-1)/8; Int_t pc=(ddl%2)? 5-2*tmp:2*tmp;
189 Int_t px=(d-1)*8+a/6;
190 tmp=(ddl%2)?(24-r):r-1; Int_t py=6*(tmp%8)+a2y[a%6];
a0e5c1b9 191 fPad=Abs(ch,pc,px,py);
d3da6dc4 192}
a0e5c1b9 193
194
d3da6dc4 195//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
f3bae3e2 196Bool_t AliHMPIDDigit::Set(Int_t ch,Int_t pc,Int_t px,Int_t py,Int_t tid)
1d4857c5 197{
198// Manual creation of digit
199// Arguments: ch,pc,px,py,qdc,tid
f3bae3e2 200// Returns: kTRUE if wrong digit
1d4857c5 201 if(px<kMinPx || px>kMaxPx) return kTRUE;
202 if(py<kMinPy || py>kMaxPy) return kTRUE;
203
f3bae3e2 204 fPad=Abs(ch,pc,px,py);fTracks[0]=tid;
205 fQ=0;
1d4857c5 206 return kFALSE;
207}
d3da6dc4 208#endif