]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HMPID/AliHMPIDDigit.h
First version of the raw-data decoding class
[u/mrichter/AliRoot.git] / HMPID / AliHMPIDDigit.h
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
6 // Class of HMPID to manage digits ---> pads
7 //.
8 //.
9 //.
10
11 #include <AliDigit.h>      //base class  
12 #include <AliRawReader.h>
13 #include <AliLog.h>
14 #include "TMath.h"         //Mathieson()
15 #include <AliBitPacking.h> //Raw()
16 #include "AliHMPIDParam.h"
17
18 class TClonesArray;        //Hit2Sdi()
19   
20 class AliHMPIDDigit :public AliDigit //TObject-AliDigit-AliHMPIDDigit
21 {
22 public:
23     
24 //ctor&dtor    
25   AliHMPIDDigit(                          ):AliDigit( ),fPad(AliHMPIDParam::Abs(-1,-1,-1,-1)),fQ(-1)  {}                         //default ctor
26   AliHMPIDDigit(Int_t pad,Int_t q,Int_t *t):AliDigit(t),fPad(pad             ),fQ(q )  {}                         //digit ctor
27   AliHMPIDDigit(const AliHMPIDDigit &d    ):AliDigit(d),fPad(d.fPad),fQ(d.fQ)          {}                         //copy ctor
28   virtual ~AliHMPIDDigit()                                                             {}                         //dtor   
29 //framework part    
30          Bool_t  IsSortable  (                               )const{return kTRUE;}                                                     //provision to use TObject::Sort() 
31   inline Int_t   Compare     (const TObject *pObj            )const;                                                                   //provision to use TObject::Sort()
32          void    Draw        (Option_t *opt=""               );                                                                        //TObject::Draw() overloaded
33          void    Print       (Option_t *opt=""               )const;                                                                   //TObject::Print() overloaded
34 //private part  
35
36          void    AddTidOffset(Int_t offset                   )     {for (Int_t i=0; i<3; i++) if (fTracks[i]>0) fTracks[i]+=offset;  } //needed for merging
37          Int_t   Ch          (                               )const{return AliHMPIDParam::A2C(fPad);                                                } //chamber number
38  
39          Float_t LorsX       (                               )const{return AliHMPIDParam::LorsX(AliHMPIDParam::A2P(fPad),AliHMPIDParam::A2X(fPad));                               } //center of the pad x, [cm]
40
41          Float_t LorsY       (                               )const{return AliHMPIDParam::LorsY(AliHMPIDParam::A2P(fPad),AliHMPIDParam::A2Y(fPad));                               } //center of the pad y, [cm]
42 //  
43   inline Float_t IntMathieson(Float_t x,Float_t y            )const;                                                                   //Mathieson distribution 
44          Int_t   PadPcX      (                               )const{return AliHMPIDParam::A2X(fPad);}                                                 //pad pc x # 0..79
45          Int_t   PadPcY      (                               )const{return AliHMPIDParam::A2Y(fPad);}                                                 //pad pc y # 0..47
46          Int_t   PadChX      (                               )const{return (Pc()%2)*AliHMPIDParam::kPadPcX+PadPcX();}                                 //pad ch x # 0..159
47          Int_t   PadChY      (                               )const{return (Pc()/2)*AliHMPIDParam::kPadPcY+PadPcY();}                                 //pad ch y # 0..143
48          Int_t   Pad         (                               )const{return fPad;}                                                      //absolute id of this pad
49          Int_t   Pc          (                               )const{return AliHMPIDParam::A2P(fPad);}                                                 //PC position number
50          Float_t Q           (                               )const{return fQ;}                                                        //charge, [QDC]
51   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)
52   inline Bool_t  Raw         (UInt_t  w32,Int_t  ddl,AliRawReader *pRR);                                                               //(w32,ddl)->digit
53   inline void    Raw         (Int_t ddl,Int_t r,Int_t d,Int_t a);                                                                      //raw->abs pad number
54   inline Bool_t  Set         (Int_t c,Int_t p,Int_t x,Int_t y,Int_t tid=0);                                                            //manual creation 
55          void    SetQ        (Float_t q                      )     {fQ=q;}                                                             //manual creation 
56          void    SetNsig     (Int_t sigmas                   )     {AliHMPIDParam::fgSigmas=sigmas;}                                                  //set n sigmas 
57   static void    WriteRaw    (TObjArray *pDigLst             );                                                                        //write as raw stream     
58   enum EHMPIDRawError {
59     kInvalidRawDataWord = 1
60   };
61
62 protected:                                                                   //AliDigit has fTracks[3]
63                                                                                
64
65   Int_t    fPad;                                                                                                                       //absolute pad number
66   Float_t  fQ;                                                               //QDC value, fractions are permitted for summable procedure  
67   ClassDef(AliHMPIDDigit,4)                                                  //HMPID digit class       
68 };//class AliHMPIDDigit
69
70 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
71
72 Int_t AliHMPIDDigit::Compare(const TObject *pObj) const
73 {
74 // 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.
75 // This feature is used in digitizer to facilitate finding of sdigits for the same pad since they all will come together after sorting.
76 // Arguments: pObj - pointer to object to compare with
77 //   Retunrs: -1 if AbsPad less then in pObj, 1 if more and 0 if they are the same      
78   if     (fPad==((AliHMPIDDigit*)pObj)->Pad()) return  0;
79   else if(fPad >((AliHMPIDDigit*)pObj)->Pad()) return  1;
80   else                                         return -1;
81 }
82 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
83
84 Float_t AliHMPIDDigit::IntMathieson(Float_t x,Float_t y)const
85 {
86 // Integration of Mathieson.
87 // This is the answer to electrostatic problem of charge distrubution in MWPC described elsewhere. (NIM A370(1988)602-603)
88 // Arguments: x,y- position of the center of Mathieson distribution
89 //  Returns: a charge fraction [0-1] imposed into the pad
90   Float_t  kK2=0.96242952, kSqrtK3 =0.77459667, kK4=0.37932926;
91
92   Float_t ux1=kSqrtK3*TMath::TanH(kK2*(x-LorsX()+0.5*AliHMPIDParam::SizePadX())/0.445);
93   Float_t ux2=kSqrtK3*TMath::TanH(kK2*(x-LorsX()-0.5*AliHMPIDParam::SizePadX())/0.445);
94   Float_t uy1=kSqrtK3*TMath::TanH(kK2*(y-LorsY()+0.5*AliHMPIDParam::SizePadY())/0.445);
95   Float_t uy2=kSqrtK3*TMath::TanH(kK2*(y-LorsY()-0.5*AliHMPIDParam::SizePadY())/0.445);
96   return 4*kK4*(TMath::ATan(ux2)-TMath::ATan(ux1))*kK4*(TMath::ATan(uy2)-TMath::ATan(uy1));
97 }
98 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
99 void AliHMPIDDigit::Raw(UInt_t &w32,Int_t &ddl,Int_t &r,Int_t &d,Int_t &a)const
100 {
101 // Convert digit structure to raw word format
102 // Arguments: w32,ddl,r,d,a where to write the results
103 //   Returns: none
104   Int_t y2a[6]={5,3,1,0,2,4};
105
106                                   ddl=2*Ch()+Pc()%2;                     //DDL# 0..13
107   Int_t tmp=1+Pc()/2*8+PadPcY()/6;  r=(Pc()%2)? 25-tmp:tmp;              //row r=1..24
108                                     d=1+PadPcX()/8;                      //DILOGIC# 1..10
109                                     a=y2a[PadPcY()%6]+6*(PadPcX()%8);    //ADDRESS 0..47        
110       
111   w32=0;    
112   AliBitPacking::PackWord((UInt_t)fQ,w32, 0,11);  // 0000 0rrr rrdd ddaa aaaa qqqq qqqq qqqq        Qdc               bits (00..11) counts (0..4095)
113   AliBitPacking::PackWord(        a ,w32,12,17);  // 3322 2222 2222 1111 1111 1000 0000 0000        DILOGIC address   bits (12..17) counts (0..47)
114   AliBitPacking::PackWord(        d ,w32,18,21);  // 1098 7654 3210 9876 5432 1098 7654 3210        DILOGIC number    bits (18..21) counts (1..10)
115   AliBitPacking::PackWord(        r ,w32,22,26);  //                                                Row number        bits (22..26) counts (1..24)  
116 }
117 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
118 Bool_t AliHMPIDDigit::Raw(UInt_t w32,Int_t ddl, AliRawReader *pRR)
119 {
120 // Converts a given raw data word to a digit
121 // Arguments: w32 - 32 bits raw data word
122 //            ddl - DDL idx  0 1 2 3 4 ... 13
123 //   Returns: none
124   Int_t r = AliBitPacking::UnpackWord(w32,22,26); assert(1<=r&&r<=24);   //                                         Row number      (1..24)    
125   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)
126   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)  
127   Int_t q = AliBitPacking::UnpackWord(w32, 0,11); assert(0<=q&&q<=4095); // 0000 0rrr rrdd ddaa aaaa qqqq qqqq qqqq Qdc             (0..4095) 
128   if (r<1 || r>24 || d<1 || d>10 || a<0 || a>47 || q<0 || q>4095) {
129     AliWarning(Form("Invalid raw data word %x",w32));
130     pRR->AddMajorErrorLog(kInvalidRawDataWord,Form("w=%x",w32));
131     return kFALSE;
132   }
133   Raw(ddl,r,d,a);
134   fQ=q;
135   return kTRUE;
136 }
137 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
138 void AliHMPIDDigit::Raw(Int_t ddl,Int_t r,Int_t d,Int_t a)
139 {
140   assert(0<=ddl&&ddl<=13); assert(1<=r&&r<=24); assert(1<=d&&d<=10);   assert(0<=a&&a<=47);  
141   Int_t a2y[6]={3,2,4,1,5,0};//pady for a given address (for single DILOGIC chip)
142                                   Int_t ch=ddl/2;
143   Int_t tmp=(r-1)/8;              Int_t pc=(ddl%2)? 5-2*tmp:2*tmp; 
144                                   Int_t px=(d-1)*8+a/6;
145         tmp=(ddl%2)?(24-r):r-1;   Int_t py=6*(tmp%8)+a2y[a%6];
146   fPad=AliHMPIDParam::Abs(ch,pc,px,py);
147 }
148
149
150 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
151 Bool_t AliHMPIDDigit::Set(Int_t ch,Int_t pc,Int_t px,Int_t py,Int_t tid)
152 {
153 // Manual creation of digit
154 // Arguments: ch,pc,px,py,qdc,tid  
155 //   Returns: kTRUE if wrong digit
156   if(px<AliHMPIDParam::kMinPx || px>AliHMPIDParam::kMaxPx) return kTRUE;
157   if(py<AliHMPIDParam::kMinPy || py>AliHMPIDParam::kMaxPy) return kTRUE;
158
159   fPad=AliHMPIDParam::Abs(ch,pc,px,py);fTracks[0]=tid;
160   fQ=0;
161   return kFALSE;
162 }
163 #endif