]> git.uio.no Git - u/mrichter/AliRoot.git/blob - RICH/AliRICHDigit.h
MAJOR UPGRADE: 1. all objects are counted from 0 2. new AliRICHRecon 3. calib off...
[u/mrichter/AliRoot.git] / RICH / AliRICHDigit.h
1 #ifndef AliRICHDigit_h
2 #define AliRICHDigit_h
3 /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4  * See cxx source for full Copyright notice                               */
5
6 #include <AliDigit.h>      //base class  
7 #include <TMath.h>         //Mathieson()
8 #include <TRandom.h>       //IsOverTh()  
9 #include <AliBitPacking.h> //Raw()
10
11 class AliRICHHit;          //Hit2Sdi()
12 class TClonesArray;        //Hit2Sdi()
13  
14 class AliRICHDigit :public AliDigit //TObject-AliDigit-AliRICHDigit
15 {
16 public:
17   enum EAbsPad {kChAbs=100000000,kPcAbs=1000000,kPadAbsX=1000,kPadAbsY=1};       //absolute pad number structure
18   enum ERawData{kDilX=8,kDilY=6,kNdil=10,kNrow=24,kNddls=14};                    //RAW data structure
19   enum EPadData{kPcX=2,kPcY=3,kPad1=0,kPadPcX=80,kPadPcY=48,kPadAllX=kPadPcX*kPcX,kPadAllY=kPadPcY*kPcY,kPcAll=kPcX*kPcY,kPadAll=kPadAllX*kPadAllY};   //Segmentation structure 
20   enum EPadShif{kC=0,kU=1,kUR=2,kR=3,kDR=4,kD=5,kDL=6,kL=7,kUL=8};                 
21 //ctor&dtor    
22            AliRICHDigit(                                                     ):AliDigit( ),fPad(Abs(-1,-1,-1,-1)),fQ(-1)  {}                //default ctor
23            AliRICHDigit(Int_t pad,Int_t q,Int_t *t                           ):AliDigit(t),fPad(pad             ),fQ(q )  {}                //digit ctor 
24   inline   AliRICHDigit(Int_t c,Float_t q,Int_t t,Float_t x,Float_t y,Int_t f=0);                                                               //sdigit ctor 
25   virtual ~AliRICHDigit()                                {} //dtor
26 //framework part    
27          Bool_t  IsSortable  (                               )const{return kTRUE;}                                                     //provision to use TObject::Sort() 
28   inline Int_t   Compare     (const TObject *pObj            )const;                                                                   //provision to use TObject::Sort()
29          void    Print       (Option_t *opt=""               )const;                                                                   //TObject::Print() overloaded
30 //private part  
31   static Int_t   Abs         (Int_t c,Int_t s,Int_t x,Int_t y)     {return c*kChAbs+s*kPcAbs+x*kPadAbsX+y*kPadAbsY; }                  //(ch,pc,padx,pady)-> abs pad
32   static Int_t   A2C         (Int_t pad                      )     {return pad/kChAbs;                              }                  //abs pad -> chamber
33   static Int_t   A2P         (Int_t pad                      )     {return pad%kChAbs/kPcAbs;                       }                  //abs pad -> pc
34   static Int_t   A2X         (Int_t pad                      )     {return pad%kPcAbs/kPadAbsX;                     }                  //abs pad -> pad X 
35   static Int_t   A2Y         (Int_t pad                      )     {return pad%kPadAbsX;                            }                  //abs pad -> pad Y 
36          Int_t   Addr        (                               )const{Int_t mapY2A[kDilY]={5,3,1,0,2,4}; return mapY2A[A2Y(fPad)%kDilY]+kDilY*(A2X(fPad)%kDilX);}//raw a=0..47
37          void    AddTidOffset(Int_t offset                   )     {for (Int_t i=0; i<3; i++) if (fTracks[i]>0) fTracks[i]+=offset;};  //needed for merging
38          Int_t   Ch          (                               )const{return A2C(fPad);                               }                  //chamber number
39          Int_t   Dilogic     (                               )const{return 10-PadX()/kDilX;                         }                  //raw d=1..10
40   static void    DrawPc      (Bool_t isFill=kTRUE            );                                                                        //draw PCs
41          Int_t   Ddl         (                               )const{return (PadX()<kPadPcX) ? 2*Ch()-2 : 2*Ch()-1;}                    //DDL number 0..13
42   static Float_t Hit2Sdi     (AliRICHHit *pHit,TClonesArray *);                                                                        //hit -> 9 sdigits, returns total QDC   
43   static Bool_t  IsOverTh    (Float_t q                      )     {return q > 6;                                                  }   //is digit over threshold????
44   static Bool_t  IsInside    (Float_t x,Float_t y            )     {return x>0&&y>0&&x<SizeAllX()&&y<SizeAllY();                   }   //is point inside pc boundary?
45   inline static Bool_t  IsInDead    (Float_t x,Float_t y            );                                                                 //is point in dead area?
46          Float_t LorsX       (                               )const{return (PadX()+0.5)*SizePadX()+(Pc()%2)*(SizePcX()+SizeDead());}   //center of the pad x, [cm]
47          Float_t LorsY       (                               )const{return (PadY()+0.5)*SizePadY()+(Pc()/2)*(SizePcY()+SizeDead());}   //center of the pad y, [cm]
48   inline Float_t Mathieson   (Float_t x,Float_t y            )const;                                                                   //Mathieson distribution 
49          Int_t   PadX        (                               )const{return A2X(fPad);}                                                 //x position of the pad
50          Int_t   PadY        (                               )const{return A2Y(fPad);}                                                 //y postion of the pad     
51          Int_t   Pad         (                               )const{return fPad;}                                                      //absolute id of this pad
52          Float_t Q           (                               )const{return fQ;}                                                        //charge, [QDC]
53          Int_t   Pc          (                               )const{return A2P(fPad);}                                                 //PC position number
54   static void    PrintSize   (                               );                                                                        //print all segmentation sizes      
55   inline Int_t   Raw         (UInt_t &w32                    )const;                                                                   //raw
56          Int_t   Row         (                               )const{Int_t r=1+Pc()/2*8+PadY()/kDilY; return (Pc()%2)?kNrow-r+1:r;}     //row r=1..24
57          void    Set         (Int_t c,Int_t s,Int_t x,Int_t y)     {fPad=Abs(c,s,x,y);}                                                //set new digit
58          void    ReadRaw     (Int_t ddl,Int_t r,Int_t d,Int_t a){Int_t mapA2Y[kDilY]={3,2,4,1,5,0};fPad=Abs(ddl/2,ddl%7,d*kDilX+a/kDilY,r*kDilY+mapA2Y[a%kDilY]);} //from raw
59   inline void    ReadRaw     (Int_t ddl,UInt_t w32           );                                                                        //read raw word
60   
61   static Float_t SizeAllX    (                               )     {return SizePadX()*kPadAllX+SizeDead();}                            //all PCs size x, [cm]        
62   static Float_t SizeAllY    (                               )     {return SizePadY()*kPadAllY+2*SizeDead();}                          //all PCs size y, [cm]    
63   static Float_t SizeArea    (                               )     {return SizePcX()*SizePcY()*kPcAll;}                                //sence area, [cm^2]  
64   static Float_t SizeDead    (                               )     {return 2.6;}                                                       //dead zone size x, [cm]         
65   static Float_t SizeGap     (                               )     {return 8;  }
66   static Float_t SizePadX    (                               )     {return 0.8;}                                                       //pad size x, [cm]  
67   static Float_t SizePadY    (                               )     {return 0.84;}                                                      //pad size y, [cm]  
68   static Float_t SizePcX     (                               )     {return SizePadX()*kPadPcX;}                                        //PC size x, [cm]        
69   static Float_t SizePcY     (                               )     {return SizePadY()*kPadPcY;}                                        //PC size y, [cm]    
70   static Float_t SizeWin     (                               )     {return 0.5;}
71   static Float_t SizeRad     (                               )     {return 1.5;}     
72   static void    TestSeg     (                               );                                                                        //test segmentation
73          void    Zoom        (                               ); 
74 protected:                  //AliDigit has fTracks[3]
75   Int_t   fPad;             //absolute pad number is chamber*kCham
76   Float_t fQ;               //QDC value, fractions are permitted for summable procedure  
77   ClassDef(AliRICHDigit,4) //RICH digit class       
78 };//class AliRICHDigitN
79 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
80 AliRICHDigit::AliRICHDigit(Int_t c,Float_t q,Int_t t,Float_t x,Float_t y,Int_t flag):AliDigit(),fPad(Abs(-1,-1,-1,-1)),fQ(-1)  
81 {
82 // Creation of sdigit  
83 // Arguments: c- chamber 
84 //            q- total QDC
85 //            t -TID
86 //            x,y - hit position, LORS        
87 //   Returns: none    
88   Int_t pc,padx,pady;
89   if     (x>=          0          && x<=  SizePcX()            ) {pc=0; padx=Int_t( x                           / SizePadX());}//PC 0 or 2 or 4
90   else if(x>=SizePcX()+SizeDead() && x<=  SizeAllX()           ) {pc=1; padx=Int_t((x-  SizePcX()-  SizeDead()) / SizePadX());}//PC 2 or 4 or 6
91   else return;
92   if     (y>=          0          && y<=  SizePcY()            ) {      pady=Int_t( y                           / SizePadY());}//PC 0 or 1
93   else if(y>=SizePcY()+SizeDead() && y<=2*SizePcY()+SizeDead() ) {pc+=2;pady=Int_t((y-  SizePcY()-  SizeDead()) / SizePadY());}//PC 2 or 3
94   else if(y>=SizeAllY()-SizePcY() && y<=  SizeAllY()           ) {pc+=4;pady=Int_t((y-2*SizePcY()-2*SizeDead()) / SizePadY());}//PC 4 or 5
95   else return;
96   
97   switch(flag){
98     case kUL:padx--;pady++;break;    case kU:pady++;break;     case kUR:padx++; pady++;break;
99                                               
100     case kL: padx--;       break;    case kC:       break;     case kR:padx++;         break;
101                                                  
102     case kDL:padx--;pady--;break;    case kD:pady--;break;     case kDR:padx++; pady--;break;                                            
103   }
104   if(padx<0 || padx>=kPadPcX) return;
105   if(pady<0 || pady>=kPadPcY) return;
106   fPad=Abs(c,pc,padx,pady);
107   fQ=q*Mathieson(x,y);
108   fTracks[0]=t; 
109 }    
110 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
111 Int_t AliRICHDigit::Compare(const TObject *pObj) const
112 {
113 // 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.
114 // This feature is used in digitizer to facilitate finding of sdigits for the same pad since they all will come together after sorting.
115 // Arguments: pObj - pointer to object to compare with
116 //   Retunrs: -1 if AbsPad less then in pObj, 1 if more and 0 if they are the same      
117   if     (fPad==((AliRICHDigit*)pObj)->Pad()) return  0;
118   else if(fPad >((AliRICHDigit*)pObj)->Pad()) return  1;
119   else                                        return -1;
120 }
121 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
122 Bool_t AliRICHDigit::IsInDead(Float_t x,Float_t y)
123 {
124 // Check is the current point is outside of sensitive area or in dead zones
125 // Arguments: x,y -position
126 //   Returns: 1 if not in sensitive zone           
127   if(x<0 || x>SizeAllX() || y<0 || y>SizeAllY()) return kTRUE; //out of pc 
128   
129   if(x>SizePcX()  && x<SizePcX()+SizeDead())   return kTRUE; //in dead zone along x  
130   
131   if(y>SizePcY()                       && y<SizePcY()+SizeDead())      return kTRUE; //in first dead zone along y   
132   if(y>SizeAllY()-SizePcY()-SizeDead() && y<SizeAllY()-SizePcY())      return kTRUE; //in second dead zone along y   
133   return kFALSE;
134 }
135 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
136 Float_t AliRICHDigit::Mathieson(Float_t x,Float_t y)const
137 {
138 // This is the answer to electrostatic problem of charge distrubution in MWPC described elsewhere. (NIM A370(1988)602-603)
139 // Arguments: x,y- position of the center of Mathieson distribution
140 //  Returns: a charge fraction [0-1] imposed into the pad
141   const Float_t kSqrtK3=0.77459667,k2=0.962,k4=0.379;
142
143   Float_t ux1=kSqrtK3*TMath::TanH(k2*(x-LorsX()+0.5*SizePadX())/0.425);
144   Float_t ux2=kSqrtK3*TMath::TanH(k2*(x-LorsX()-0.5*SizePadX())/0.425);
145   Float_t uy1=kSqrtK3*TMath::TanH(k2*(y-LorsY()+0.5*SizePadY())/0.425);
146   Float_t uy2=kSqrtK3*TMath::TanH(k2*(y-LorsY()-0.5*SizePadY())/0.425);
147   return 4*k4*(TMath::ATan(ux2)-TMath::ATan(ux1))*k4*(TMath::ATan(uy2)-TMath::ATan(uy1));
148 }
149 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
150 Int_t AliRICHDigit::Raw(UInt_t &w32)const
151 {
152 // Convert digit structure to raw word format
153 // Arguments: 32 bits raw word to fill
154 //   Returns: DDL ID where to write this digit
155   w32=0;
156   AliBitPacking::PackWord((UInt_t)fQ        ,w32, 0,11);  // 0000 0rrr rrdd ddaa aaaa qqqq qqqq qqqq        Qdc               bits (00..11) counts (0..4095)
157   AliBitPacking::PackWord(         Addr()   ,w32,12,17);  // 3322 2222 2222 1111 1111 1000 0000 0000        DILOGIC address   bits (12..17) counts (0..47)
158   AliBitPacking::PackWord(         Dilogic(),w32,18,21);  // 1098 7654 3210 9876 5432 1098 7654 3210        DILOGIC number    bits (18..21) counts (1..10)
159   AliBitPacking::PackWord(         Row()    ,w32,22,26);  //                                                Row number        bits (22..26) counts (1..24)  
160   return Ddl(); //ddl 0..13 where to write this digit 
161 }
162 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
163 void AliRICHDigit::ReadRaw(Int_t ddl,UInt_t w32)
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
169         fQ = AliBitPacking::UnpackWord(w32, 0,11);  // 0000 0rrr rrdd ddaa aaaa qqqq qqqq qqqq         Qdc               bits (00..11) counts (0..4095)   
170   UInt_t a = AliBitPacking::UnpackWord(w32,12,17);  // 3322 2222 2222 1111 1111 1000 0000 0000         DILOGIC address   bits (12..17) counts (0..47)
171   UInt_t d = AliBitPacking::UnpackWord(w32,18,21);  // 1098 7654 3210 9876 5432 1098 7654 3210         DILOGIC number    bits (18..21) counts (1..10)
172   UInt_t r = AliBitPacking::UnpackWord(w32,22,26);  //                                                 Row number        bits (22..26) counts (1..24)    
173   ReadRaw(ddl,r,d,a);    
174 }
175 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
176 #endif