]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HMPID/AliHMPIDDigit.h
Calibration object splitted in: pedestal + E calib + reco parameters
[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(Int_t pad,Int_t q         ):AliDigit( ),fPad(pad             ),fQ(q )  {}                         //digit ctor
28   AliHMPIDDigit(const AliHMPIDDigit &d    ):AliDigit(d),fPad(d.fPad),fQ(d.fQ)          {}                         //copy ctor
29   virtual ~AliHMPIDDigit()                                                             {}                         //dtor   
30 //framework part    
31          Bool_t  IsSortable  (                               )const{return kTRUE;}                                                     //provision to use TObject::Sort() 
32   inline Int_t   Compare     (const TObject *pObj            )const;                                                                   //provision to use TObject::Sort()
33          void    Draw        (Option_t *opt=""               );                                                                        //TObject::Draw() overloaded
34          void    Print       (Option_t *opt=""               )const;                                                                   //TObject::Print() overloaded
35 //private part  
36
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 AliHMPIDParam::A2C(fPad);                                                } //chamber number
39  
40          Float_t LorsX       (                               )const{return AliHMPIDParam::LorsX(AliHMPIDParam::A2P(fPad),AliHMPIDParam::A2X(fPad));                               } //center of the pad x, [cm]
41
42          Float_t LorsY       (                               )const{return AliHMPIDParam::LorsY(AliHMPIDParam::A2P(fPad),AliHMPIDParam::A2Y(fPad));                               } //center of the pad y, [cm]
43 //  
44   inline Float_t Mathieson   (Float_t x                      )const;                                                                   //Mathieson distribution 
45   inline Float_t IntPartMathi(Float_t z, Int_t axis          )const;                                                                   //integral in 1-dim of Mathieson
46   inline Float_t IntMathieson(Float_t x,Float_t y            )const;                                                                   //integral in 2-dim of Mathieson  
47          Int_t   PadPcX      (                               )const{return AliHMPIDParam::A2X(fPad);}                                                 //pad pc x # 0..79
48          Int_t   PadPcY      (                               )const{return AliHMPIDParam::A2Y(fPad);}                                                 //pad pc y # 0..47
49          Int_t   PadChX      (                               )const{return (Pc()%2)*AliHMPIDParam::kPadPcX+PadPcX();}                                 //pad ch x # 0..159
50          Int_t   PadChY      (                               )const{return (Pc()/2)*AliHMPIDParam::kPadPcY+PadPcY();}                                 //pad ch y # 0..143
51          Int_t   Pad         (                               )const{return fPad;}                                                      //absolute id of this pad
52          Int_t   Pc          (                               )const{return AliHMPIDParam::A2P(fPad);}                                                 //PC position number
53          Float_t Q           (                               )const{return fQ;}                                                        //charge, [QDC]
54   inline void    Raw(UInt_t &w32,Int_t &ddl,Int_t &r,Int_t &d,Int_t &a)const;
55   inline Bool_t  Set         (Int_t c,Int_t p,Int_t x,Int_t y,Int_t tid=0);                                                            //manual creation 
56          void    SetQ        (Float_t q                      )     {fQ=q;}                                                             //manual creation 
57          void    SetNsig     (Int_t sigmas                   )     {AliHMPIDParam::fgSigmas=sigmas;}                                                  //set n sigmas 
58
59  
60 protected:                                                                   //AliDigit has fTracks[3]
61                                                                                
62
63   Int_t    fPad;                                                                                                                       //absolute pad number
64   Float_t  fQ;                                                               //QDC value, fractions are permitted for summable procedure  
65   ClassDef(AliHMPIDDigit,4)                                                  //HMPID digit class       
66 };//class AliHMPIDDigit
67
68 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
69
70 Int_t AliHMPIDDigit::Compare(const TObject *pObj) const
71 {
72 // 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.
73 // This feature is used in digitizer to facilitate finding of sdigits for the same pad since they all will come together after sorting.
74 // Arguments: pObj - pointer to object to compare with
75 //   Retunrs: -1 if AbsPad less then in pObj, 1 if more and 0 if they are the same      
76   if     (fPad==((AliHMPIDDigit*)pObj)->Pad()) return  0;
77   else if(fPad >((AliHMPIDDigit*)pObj)->Pad()) return  1;
78   else                                         return -1;
79 }
80 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
81
82 Float_t AliHMPIDDigit::Mathieson(Float_t x)const
83 {
84 // Mathieson function.
85 // This is the answer to electrostatic problem of charge distrubution in MWPC described elsewhere. (NIM A370(1988)602-603)
86 // Arguments: x- position of the center of Mathieson distribution
87 //  Returns: value of the Mathieson function
88   Float_t  kK1=0.28278795,kK2=0.96242952, kSqrtK3 =0.77459667, kD=0.445;
89   Float_t lambda = x/kD;
90   Float_t a=1-TMath::TanH(kK2*lambda)*TMath::TanH(kK2*lambda);
91   Float_t b=1+kSqrtK3*kSqrtK3*TMath::TanH(kK2*lambda)*TMath::TanH(kK2*lambda);
92   Float_t mathi = kK1*a/b;
93   return mathi;
94 }
95 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
96
97 Float_t AliHMPIDDigit::IntPartMathi(Float_t z, Int_t axis)const
98 {
99 // Integration of Mathieson.
100 // This is the answer to electrostatic problem of charge distrubution in MWPC described elsewhere. (NIM A370(1988)602-603)
101 // Arguments: x,y- position of the center of Mathieson distribution
102 //  Returns: a charge fraction [0-1] imposed into the pad
103   Float_t shift1,shift2;
104   if(axis==1) {
105     shift1 = -LorsX()+0.5*AliHMPIDParam::SizePadX();
106     shift2 = -LorsX()-0.5*AliHMPIDParam::SizePadX();
107   } else {
108     shift1 = -LorsY()+0.5*AliHMPIDParam::SizePadY();
109     shift2 = -LorsY()-0.5*AliHMPIDParam::SizePadY();
110   }
111     
112   Float_t  kK2=0.96242952, kSqrtK3 =0.77459667,  kK4=0.37932926, kD=0.445;
113
114   Float_t ux1=kSqrtK3*TMath::TanH(kK2*(z+shift1)/kD);
115   Float_t ux2=kSqrtK3*TMath::TanH(kK2*(z+shift2)/kD);
116   
117   return kK4*(TMath::ATan(ux2)-TMath::ATan(ux1));
118 }
119 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
120
121 Float_t AliHMPIDDigit::IntMathieson(Float_t x,Float_t y)const
122 {
123 // Integration of Mathieson.
124 // This is the answer to electrostatic problem of charge distrubution in MWPC described elsewhere. (NIM A370(1988)602-603)
125 // Arguments: x,y- position of the center of Mathieson distribution
126 //  Returns: a charge fraction [0-1] imposed into the pad
127
128   Float_t xm = IntPartMathi(x,1);
129   Float_t ym = IntPartMathi(y,2);
130   return 4*xm*ym;
131 }
132 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
133 void AliHMPIDDigit::Raw(UInt_t &w32,Int_t &ddl,Int_t &r,Int_t &d,Int_t &a)const
134 {
135 // Convert digit structure to raw word format
136 // Arguments: w32,ddl,r,d,a where to write the results
137 //   Returns: none
138   Int_t y2a[6]={5,3,1,0,2,4};
139
140                                     ddl=2*Ch()+Pc()%2;                     //DDL# 0..13
141   Int_t tmp=1+Pc()/2*8+PadPcY()/6;  r=(Pc()%2)? 25-tmp:tmp;              //row r=1..24
142                                     d=1+PadPcX()/8;                      //DILOGIC# 1..10
143                                     a=y2a[PadPcY()%6]+6*(PadPcX()%8);    //ADDRESS 0..47        
144       
145   w32=0;   
146   //Printf("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
147   //
148   //Printf("AliHMPIDDigit::Raw ddl: %d r: %d d: %d a: %d",ddl,r,d,a);
149   //Printf("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
150 //  Bool_t isOK=kTRUE; isOK=
151   AliBitPacking::PackWord((fQ>4095)?(UInt_t)4095:(UInt_t)fQ,w32, 0,11);       // 0000 0rrr rrdd ddaa aaaa qqqq qqqq qqqq        Qdc               bits (00..11) counts (0..4095)
152   //Printf("isOK: %d",isOK);
153   //molnarl: Since in simulation the the charge can be > than 4095 but not in real life we need to protect. If fQ>4095 after packing we will get 0 for the charge! 
154   assert(0<=a&&a<=47);AliBitPacking::PackWord(        a ,w32,12,17);  // 3322 2222 2222 1111 1111 1000 0000 0000        DILOGIC address   bits (12..17) counts (0..47)
155   assert(1<=d&&d<=10);AliBitPacking::PackWord(        d ,w32,18,21);  // 1098 7654 3210 9876 5432 1098 7654 3210        DILOGIC number    bits (18..21) counts (1..10)
156   assert(1<=r&&r<=24);AliBitPacking::PackWord(        r ,w32,22,26);  //                                                Row number        bits (22..26) counts (1..24)  
157                       AliBitPacking::PackWord((UInt_t)0, w32,27,27);  //To make sure set the 27th bit to Zero so we can distinguis it from the EoE
158 }
159 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
160 Bool_t AliHMPIDDigit::Set(Int_t ch,Int_t pc,Int_t px,Int_t py,Int_t tid)
161 {
162 // Manual creation of digit
163 // Arguments: ch,pc,px,py,qdc,tid  
164 //   Returns: kTRUE if wrong digit
165   if(px<AliHMPIDParam::kMinPx || px>AliHMPIDParam::kMaxPx) return kTRUE;
166   if(py<AliHMPIDParam::kMinPy || py>AliHMPIDParam::kMaxPy) return kTRUE;
167
168   fPad=AliHMPIDParam::Abs(ch,pc,px,py);fTracks[0]=tid;
169   fQ=0;
170   return kFALSE;
171 }
172 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
173
174 #endif