Adding makefile for Darwin and XLC compiler
[u/mrichter/AliRoot.git] / RICH / AliRICH.h
1 #ifndef AliRICH_h
2 #define AliRICH_h
3
4 /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
5  * See cxx source for full Copyright notice                               */
6
7 #include <TObjArray.h>
8 #include <TClonesArray.h>
9 #include <TVector3.h>
10 #include <Riostream.h>
11 #include <AliDetector.h>
12 #include <AliHit.h>
13 #include <AliDigit.h>
14 #include "AliRICHDigitizer.h"
15 #include "AliRICHParam.h"
16
17 //__________________AliRICHhit______________________________________________________________________
18 class AliRICHhit : public AliHit
19 {
20 public:
21            AliRICHhit():AliHit()          {fChamber=kBad;  fEloss=kBad;  fInX3.SetXYZ(0,0,0);fOutX3.SetXYZ(0,0,0);}
22            AliRICHhit(Int_t c,Int_t tid,TVector3 in,TVector3 out,Double_t e):AliHit(0,tid)
23                                           {fChamber=c;fInX3=in; fOutX3=out;fEloss=e; fX=out.X();fY=out.Y();fZ=out.Z();}
24   virtual ~AliRICHhit()                   {;}
25
26   Int_t    C()                       const{return fChamber;}              //chamber number 
27   Int_t    Chamber()                 const{return fChamber;}              //chamber number 
28   Float_t  Eloss()                   const{return fEloss;}                //energy lost by track inside amplification gap  
29   TVector3 InX3()                    const{return fInX3;}                 //track position at the faceplane of the gap 
30   TVector3 OutX3()                   const{return fOutX3;}                //track position at the backplane of the gap 
31   Double_t Length()                  const{return (fOutX3-fInX3).Mag();}  //track length inside the amplification gap
32   void     Print(Option_t *option="")const;                               //virtual
33 protected:
34   Int_t     fChamber;                      //chamber number
35   Double_t  fEloss;                        //ionisation energy lost in GAP
36   TVector3  fInX3;                         //position at the entrance of the GAP   
37   TVector3  fOutX3;                        //position at the exit of the GAP
38   ClassDef(AliRICHhit,2)                   //RICH hit class
39 };//class AliRICHhit
40
41 //__________________AliRICHdigit____________________________________________________________________
42 class AliRICHdigit :public AliDigit
43 {
44 public:
45   AliRICHdigit() {fChFbMip=fChamber=fPadX=fPadY=fTracks[0]=fTracks[1]=fTracks[2]=kBad;fQdc=kBad;}
46   AliRICHdigit(Int_t c,Int_t x,Int_t y,Double_t q,Int_t cpid,Int_t tid0,Int_t tid1,Int_t tid2)  
47                  {fPadX=x;fPadY=y;fQdc=q;fChamber=10*c+AliRICHParam::Sector(x,y);fChFbMip=cpid;fTracks[0]=tid0;fTracks[1]=tid1;fTracks[2]=tid2;}
48   virtual ~AliRICHdigit() {;}  
49   Int_t    Compare(const TObject *pObj) const
50                  {if(Id()==((AliRICHdigit*)pObj)->Id())return 0;else if(Id()>((AliRICHdigit*)pObj)->Id())return 1;else return -1;}  //virtual      
51   Bool_t   IsSortable()                 const{return kTRUE;}                              //virtual
52   void     Print(Option_t *option="")   const;                                            //virtual
53   Int_t    ChFbMi()                     const{return fChFbMip;}                           //particle mixture for this digit
54   Int_t    C()                          const{return fChamber/10;}                        //chamber number
55   Int_t    S()                          const{return fChamber-(fChamber/10)*10;}          //sector number
56   Int_t    X()                          const{return fPadX;}                              //x position of the pad
57   Int_t    Y()                          const{return fPadY;}                              //y postion of the pad
58   Int_t    Id()                         const{return fChamber*10000000+fPadX*1000+fPadY;} //absolute id of this pad
59   Double_t Q()                          const{return fQdc;}                               //charge in terms of ADC channels
60   Int_t    Tid(Int_t i)                 const{return fTracks[i];}                         //track reference produced this digit
61   void     AddTidOffset(Int_t offset) 
62     {for (Int_t i=0; i<3; i++) if (fTracks[i]>0) fTracks[i]+=offset;};
63 protected:
64   Int_t    fChFbMip;  //1000000*Ncerenkovs+1000*Nfeedbacks+Nmips  
65   Int_t    fChamber;  //10*chamber number+ sector number 
66   Int_t    fPadX;     //pad number along X
67   Int_t    fPadY;     //pad number along Y
68   Double_t fQdc;      //QDC value, fractions are permitted for summable procedure  
69   ClassDef(AliRICHdigit,3) //RICH digit class       
70 };//class AliRICHdigit
71
72 //__________________AliRICHcluster__________________________________________________________________
73 class AliRICHcluster :public TObject
74 {
75 public:
76   enum ClusterStatus {kEdge,kShape,kSize,kRaw,kResolved};
77                     AliRICHcluster()                                 {fSize=fQdc=fStatus=fChamber=fDimXY=0;fX=fY=kBad;fDigits=0;}
78   virtual          ~AliRICHcluster()                                 {delete fDigits;}  
79   AliRICHcluster&   operator=(const AliRICHcluster&)                 {return *this;}
80          Int_t      Nlocals()                                   const{return fSize - 10000*(fSize/10000);} //
81          Int_t      Size()                                      const{return fSize/10000;}                 //
82          Int_t      Fsize()                                     const{return fSize;}                       //
83          Int_t      DimXY()                                     const{return fDimXY;}                      //
84          Int_t      C()                                         const{return fChamber/10;}                 //
85          Int_t      S()                                         const{return fChamber-(fChamber/10)*10;}   //
86          Int_t      Fchamber()                                  const{return fChamber;}                    //
87          Int_t      Q()                                         const{return fQdc;}                        // 
88          Double_t   X()                                         const{return fX;}                          //
89          Double_t   Y()                                         const{return fY;}                          // 
90          Int_t      Status()                                    const{return fStatus;}                     //
91          void       SetStatus(Int_t status)                          {fStatus=status;}                     //
92          Int_t      Nmips()                                     const{return fCombiPid-1000000*Ncerenkovs()-1000*Nfeedbacks();}  //
93          Int_t      Ncerenkovs()                                const{return fCombiPid/1000000;}           //
94          Int_t      Nfeedbacks()                                const{return (fCombiPid-1000000*Ncerenkovs())/1000;}      //
95          Bool_t     IsPureMip()                                 const{return fCombiPid<1000;}   
96          Bool_t     IsPureCerenkov()                            const{return Nmips()==0&&Nfeedbacks()==0;} //
97          Bool_t     IsPureFeedback()                            const{return Nmips()==0&&Ncerenkovs()==0;} //
98          Int_t      CombiPid()                                  const{return fCombiPid;} //
99          void       SetCombiPid(Int_t ckov,Int_t feeds,Int_t mips)   {fCombiPid=1000000*ckov+1000*feeds+mips;}            //
100          void       Fill(AliRICHcluster *pRaw,Double_t x,Double_t y, Double_t q, Int_t combipid)
101              {fCombiPid=combipid;fChamber=pRaw->Fchamber();fSize=pRaw->Fsize();
102               fQdc=(Int_t)(q*pRaw->Q());fX=x;fY=y;fStatus=kResolved;} //
103          TObjArray* Digits()                                    const{return fDigits;}                     //  
104          void       Print(Option_t *option="")const;                                                       //virtual
105   inline void       AddDigit(AliRICHdigit *pDig);                                                          //
106   inline void       CoG(Int_t nLocals);                                                                                 // 
107          void       Reset() {fSize=fQdc=fStatus=fChamber=fDimXY=kBad;fX=fY=kBad;delete fDigits;fDigits=0;} //
108 protected:
109   Int_t         fCombiPid;    //1000000*Ncerenkovs+1000*Nfeedbacks+Nmips  
110   Int_t         fSize;        //10000*(how many digits belong to this cluster) + nLocalMaxima     
111   Int_t         fDimXY;       //100*xdim+ydim box containing the cluster
112   Int_t         fQdc;         //QDC value
113   Int_t         fChamber;     //10*module number+sector number 
114   Double_t      fX;           //local x postion 
115   Double_t      fY;           //local y postion  
116   Int_t         fStatus;      //flag to mark the quality of the cluster   
117   TObjArray    *fDigits;      //! list of digits forming this cluster
118   ClassDef(AliRICHcluster,2)  //RICH cluster class       
119 };//class AliRICHcluster
120 //__________________________________________________________________________________________________
121 void AliRICHcluster::AddDigit(AliRICHdigit *pDig)
122 {//    
123   if(!fDigits) {fQdc=fSize=fCombiPid=0;fDigits = new TObjArray;}
124   fQdc+=(Int_t)pDig->Q(); fDigits->Add(pDig);
125   fChamber=10*pDig->C()+pDig->S();
126   fSize+=10000;
127 }
128 //__________________________________________________________________________________________________
129 void AliRICHcluster::CoG(Int_t nLocals)
130 {//
131   Int_t xmin=999,ymin=999,xmax=0,ymax=0;   
132   fX=fY=0;
133   for(Int_t iDig=0;iDig<Size();iDig++) {
134     AliRICHdigit *pDig=(AliRICHdigit*)fDigits->At(iDig);
135     Int_t padX = pDig->X();Int_t padY = pDig->Y();Double_t q=pDig->Q();
136     TVector2 x2=AliRICHParam::Pad2Loc(padX,padY);
137     fX += x2.X()*q;fY +=x2.Y()*q;
138     if(padX<xmin)xmin=padX;if(padX>xmax)xmax=padX;if(padY<ymin)ymin=padY;if(padY>ymax)ymax=padY;
139    }
140    fX/=fQdc;fY/=fQdc;//Center of Gravity
141    fDimXY = 100*(xmax-xmin+1)+ymax-ymin+1;//find box containing cluster
142    fSize+=nLocals;
143    fStatus=kRaw;
144 }//CoG()
145
146
147 class AliRICHreco: public TObject
148 {
149 public:
150             AliRICHreco() {fTid=fNphotons=kBad; fThetaCherenkov=kBad;}
151             AliRICHreco(Int_t tid,Double_t thetaCherenkov,Int_t nPhotons) {fTid=tid;fThetaCherenkov=thetaCherenkov;fNphotons=nPhotons;}
152
153   virtual  ~AliRICHreco() {;}
154
155   void    Print(Option_t *option="")const;      //virtual print
156   
157 protected:
158    Int_t fTid;                 // track Id reference
159    Int_t fNphotons;            // number of photons contributed to the recontruction
160    Double_t fThetaCherenkov;   // reconstructed Theta Cerenkov for a given charged track
161
162    ClassDef(AliRICHreco,1)  //RICH reco class
163
164 };//class AliRICHreco
165
166 //__________________AliRICH_________________________________________________________________________
167 class AliRICHParam;
168 class AliRICHChamber;
169
170 class AliRICH : public AliDetector 
171 {
172 public:
173             AliRICH();                                            
174             AliRICH(const char *name, const char *title);
175             AliRICH(const AliRICH& RICH):AliDetector(RICH) {;}  //copy ctor 
176   virtual  ~AliRICH();                                            
177           
178   AliRICH&  operator=(const AliRICH&)                 {return *this;}
179 //framework part  
180   virtual Int_t   IsVersion()                                            const =0;                                //virtual         
181   virtual void    StepManager()                                                =0;                                //virtual
182           void    Hits2SDigits();                                                                                 //virtual
183   AliDigitizer*   CreateDigitizer(AliRunDigitizer* man) const {return new AliRICHDigitizer(man);}                 //virtual
184           void    Print(Option_t *option)const;                                                                   //virtual
185           void    SetTreeAddress();                                                                               //virtual
186           void    MakeBranch(Option_t *opt=" ");                                                                  //virtual
187           void    CreateMaterials();                                                                              //virtual
188   virtual void    BuildGeometry();                                                                                //virtual
189   virtual void    CreateGeometry();                                                                               //virtual
190 //private part  
191           Float_t AbsoCH4(Float_t x)const;                               //calculates absorption length for methane
192           Float_t Fresnel(Float_t ene,Float_t pdoti, Bool_t pola)const;  //deals with Fresnel absorption
193           void    GenerateFeedbacks(Int_t iChamber,Float_t eloss=0);     //generates feedback photons; eloss=0 for photon
194           void    CreateChambers();                                      //creates set of chambers
195   inline  void    CreateHits();                                          //create hits container as a simple list
196   inline  void    CreateSDigits();                                       //create sdigits container as a simple list
197   inline  void    CreateDigits();                                        //create digits container as 7 lists, one per chamber
198   inline  void    CreateClusters();                                      //create clusters container  as 7 lists, one per chamber
199   inline  void    CreateRecos();                                         //create recos container
200 //        void    ResetHits()                {AliDetector::ResetHits();}  //virtual  
201           void    ResetSDigits()             {fNsdigits=0;  if(fSdigits)  fSdigits ->Clear();}                                 
202           void    ResetDigits()              {if(fDigitsNew)for(int i=0;i<kNCH;i++){fDigitsNew->At(i)->Clear();fNdigitsNew[i]=0;}} //virtual
203           void    ResetClusters()            {if(fClusters) for(int i=0;i<kNCH;i++){fClusters ->At(i)->Clear();fNclusters[i]=0;}}
204           void    ResetRecos()               {if(fRecos) fRecos->Clear();fNrecos=0;}
205   TClonesArray*   SDigits()             const{return fSdigits;}
206   TClonesArray*   Digits(Int_t iC)      const{if(fDigitsNew) return (TClonesArray *)fDigitsNew->At(iC-1);else return 0;}
207   TClonesArray*   Clusters(Int_t iC)    const{if(fClusters)  return (TClonesArray *)fClusters->At(iC-1);else return 0;}
208   TClonesArray*   Recos()               const{return fRecos;}
209   AliRICHChamber* C(Int_t iC)           const{return (AliRICHChamber*)fChambers->At(iC-1);}
210   AliRICHParam*   P()                   const{return fpParam;}
211           void    PrintDigits()         const{for(Int_t i=0;i<kNCH;i++) fDigitsNew->At(i)->Print();}
212           void    PrintClusters()       const{for(Int_t i=0;i<kNCH;i++) fClusters->At(i)->Print();}
213             
214   void AddHit(Int_t chamber,Int_t tid,TVector3 iX3,TVector3 oX3,Double_t eloss=0)
215        {TClonesArray &tmp=*fHits;new(tmp[fNhits++])AliRICHhit(chamber,tid,iX3,oX3,eloss);} 
216   inline void AddSDigit(Int_t c,Int_t x,Int_t y,Double_t q,Int_t pid,Int_t tid); 
217   void AddDigit(int c,int x,int y,int q,int cfm,int *tid)
218        {TClonesArray &tmp=*((TClonesArray*)fDigitsNew->At(c-1));new(tmp[fNdigitsNew[c-1]++])AliRICHdigit(c,x,y,q,cfm,tid[0],tid[1],tid[2]);}  
219   void AddCluster(AliRICHcluster &cl)                     
220        {Int_t c=cl.C()-1;/*cout<<c<<endl*/;TClonesArray &tmp=*((TClonesArray*)fClusters->At(c));new(tmp[fNclusters[c]++])AliRICHcluster(cl);}
221   void AddReco(Int_t tid,Double_t thetaCherenkov,Int_t nPhotons) 
222        {TClonesArray &tmp=*(TClonesArray*)fRecos;new(tmp[fNrecos++])AliRICHreco(tid,thetaCherenkov,nPhotons);}  
223           
224   virtual void Reconstruct() const;
225
226 protected:  
227   enum                  {kCSI=6,kGAP=9};
228   AliRICHParam         *fpParam;             //main RICH parametrization     
229   TObjArray            *fChambers;           //list of RICH chambers
230   
231                                              //fHits and fDigits belong to AliDetector
232   TClonesArray         *fSdigits;            //! List of sdigits  
233   Int_t                 fNsdigits;           //! Current number of sdigits
234   
235   TObjArray            *fDigitsNew;          //! Each chamber holds it's one lists of digits
236   Int_t                 fNdigitsNew[kNCH];   //! Array of current numbers of digits
237   
238   TObjArray            *fClusters;           //! Each chamber holds it's one lists of clusters 
239   Int_t                 fNclusters[kNCH];    //! Array of current numbers of raw clusters
240   
241   TClonesArray         *fRecos;              //! pointer to the list of recos
242   Int_t                 fNrecos;             //! number of recos
243
244   ClassDef(AliRICH,5)                        //Main RICH class 
245 };//class AliRICH  
246
247 //__________________________________________________________________________________________________
248 void AliRICH::CreateHits()
249 {
250   if(fHits) return;
251   if(GetDebug())Info("CreateHits","creating hits container.");
252   fHits=new TClonesArray("AliRICHhit",10000);   fNhits=0;
253 }
254 //__________________________________________________________________________________________________
255 void AliRICH::CreateSDigits()
256 {
257   if(fSdigits) return;
258   if(GetDebug())Info("CreateSDigits","creating sdigits container.");
259   fSdigits=new TClonesArray("AliRICHdigit",10000); fNsdigits=0;
260 }
261 //__________________________________________________________________________________________________
262 void AliRICH::CreateDigits()
263 {
264   if(fDigitsNew) return;
265   if(GetDebug())Info("CreateDigits","creating digits containers.");
266   fDigitsNew = new TObjArray(kNCH);  
267   for(Int_t i=0;i<kNCH;i++) {fDigitsNew->AddAt(new TClonesArray("AliRICHdigit",10000), i); fNdigitsNew[i]=0;}
268 }
269 //__________________________________________________________________________________________________
270 void AliRICH::CreateClusters()
271 {
272   if(fClusters) return;
273   if(GetDebug())Info("CreateClusters","creating clusters containers.");
274   fClusters = new TObjArray(kNCH);  
275   for(Int_t i=0;i<kNCH;i++) {fClusters->AddAt(new TClonesArray("AliRICHcluster",10000), i); fNclusters[i]=0;}
276 }
277 //__________________________________________________________________________________________________
278 void AliRICH::CreateRecos()
279 {
280   if(fRecos) return;
281   if(GetDebug())Info("CreateRecos","creating recos containers.");
282   fRecos = new TClonesArray("AliRICHreco",1000);fNrecos=0;  
283 }
284 //__________________________________________________________________________________________________
285 void AliRICH::AddSDigit(Int_t c,Int_t x,Int_t y,Double_t q,Int_t pid,Int_t tid) 
286 {   
287   switch(pid){
288     case 50000050: pid=1000000;break;//cerenkov
289     case 50000051: pid=1000;   break;//feedback
290     default:       pid=1;      break;//mip
291   }   
292   TClonesArray &tmp=*fSdigits;
293   new(tmp[fNsdigits++])AliRICHdigit(c,x,y,q,pid,tid,kBad,kBad);
294 }//AddSDigit()   
295 //__________________________________________________________________________________________________
296 #endif//#ifndef AliRICH_h