Added functionalities in display the RICH event and pattern recognition. Minor bugs...
[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 <Riostream.h>
8 #include <TClonesArray.h>
9 #include <TObjArray.h>
10 #include <TVector.h>
11 #include <TVector3.h>
12
13 #include "AliRICHDigitizer.h"
14 #include "AliRICHParam.h"
15 #include <AliDetector.h>
16 #include <AliDigit.h>
17 #include <AliHit.h>
18
19 //__________________AliRICHhit______________________________________________________________________
20 class AliRICHhit : public AliHit
21 {
22 public:
23            AliRICHhit():AliHit(),fChamber(kBad),fEloss(kBad) {fInX3.SetXYZ(0,0,0);fOutX3.SetXYZ(0,0,0);}
24            AliRICHhit(Int_t c,Int_t tid,TVector3 in,TVector3 out,Double_t e):AliHit(0,tid)
25                                           {fChamber=c;fInX3=in; fOutX3=out;fEloss=e; fX=out.X();fY=out.Y();fZ=out.Z();}
26   virtual ~AliRICHhit()                   {;}
27
28   Int_t    C()                       const{return fChamber;}              //chamber number 
29   Int_t    Chamber()                 const{return fChamber;}              //chamber number 
30   Float_t  Eloss()                   const{return fEloss;}                //energy lost by track inside amplification gap  
31   TVector3 InX3()                    const{return fInX3;}                 //track position at the faceplane of the gap 
32   TVector3 OutX3()                   const{return fOutX3;}                //track position at the backplane of the gap 
33   Double_t Length()                  const{return (fOutX3-fInX3).Mag();}  //track length inside the amplification gap
34   void     Print(Option_t *option="")const;                               //virtual
35 protected:
36   Int_t     fChamber;                      //chamber number
37   Double_t  fEloss;                        //ionisation energy lost in GAP
38   TVector3  fInX3;                         //position at the entrance of the GAP   
39   TVector3  fOutX3;                        //position at the exit of the GAP
40   ClassDef(AliRICHhit,2)                   //RICH hit class
41 };//class AliRICHhit
42
43 //__________________AliRICHdigit____________________________________________________________________
44 class AliRICHdigit :public AliDigit
45 {
46 public:
47   AliRICHdigit():AliDigit(),fCFM(0),fChamber(0),fPadX(0),fPadY(0),fQdc(kBad){fTracks[0]=fTracks[1]=fTracks[2]=kBad;}
48   AliRICHdigit(Int_t c,TVector pad,Double_t q,Int_t cfm,Int_t tid0,Int_t tid1,Int_t tid2)  
49        {fPadX=(Int_t)pad[0];fPadY=(Int_t)pad[1];fQdc=q;fChamber=10*c+AliRICHParam::Pad2Sec(pad);fCFM=cfm;fTracks[0]=tid0;fTracks[1]=tid1;fTracks[2]=tid2;}
50   virtual ~AliRICHdigit() {;}  
51   Int_t    Compare(const TObject *pObj) const
52                  {if(Id()==((AliRICHdigit*)pObj)->Id())return 0;else if(Id()>((AliRICHdigit*)pObj)->Id())return 1;else return -1;}  //virtual      
53   virtual Bool_t   IsSortable()                 const{return kTRUE;}                              //sort interface
54   virtual void     Print(Option_t *option="")   const;                                            //virtual
55   Int_t    ChFbMi()                     const{return fCFM;}                               //particle mixture for this digit
56   Int_t    C()                          const{return fChamber/10;}                        //chamber number
57   Int_t    S()                          const{return fChamber-(fChamber/10)*10;}          //sector number
58   Int_t    X()                          const{return fPadX;}                              //x position of the pad
59   Int_t    Y()                          const{return fPadY;}                              //y postion of the pad
60   TVector  Pad()                        const{Float_t v[2]={fPadX,fPadY}; return TVector(2,v);}
61   Int_t    Id()                         const{return fChamber*10000000+fPadX*1000+fPadY;} //absolute id of this pad
62   Double_t Q()                          const{return fQdc;}                               //charge in terms of ADC channels
63   void     AddTidOffset(Int_t offset) 
64     {for (Int_t i=0; i<3; i++) if (fTracks[i]>0) fTracks[i]+=offset;};
65 protected:
66   Int_t    fCFM;  //1000000*Ncerenkovs+1000*Nfeedbacks+Nmips  
67   Int_t    fChamber;  //10*chamber number+ sector number 
68   Int_t    fPadX;     //pad number along X
69   Int_t    fPadY;     //pad number along Y
70   Double_t fQdc;      //QDC value, fractions are permitted for summable procedure  
71   ClassDef(AliRICHdigit,3) //RICH digit class       
72 };//class AliRICHdigit
73
74 //__________________AliRICHcluster__________________________________________________________________
75 class AliRICHcluster :public TObject
76 {
77 public:
78   enum ClusterStatus {kEdge,kShape,kSize,kRaw,kResolved,kEmpty=kBad};
79                     AliRICHcluster():TObject(),fCFM(0),fSize(0),fShape(0),fQdc(0),fChamber(0),fX(0),fY(0),fStatus(kEmpty),fDigits(0) {}    
80   virtual          ~AliRICHcluster()                 {AliDebug(1,"Start");/*Reset();*/}  
81          void       Reset()                          {DeleteDigits();fCFM=fSize=fShape=fQdc=fChamber=0;fX=fY=0;fStatus=kEmpty;} //cleans the cluster
82          void       DeleteDigits()                   {if(fDigits) {delete fDigits;} fDigits=0;}           //deletes the list of digits  
83   AliRICHcluster&   operator=(const AliRICHcluster&) {return *this;}                                 
84          Int_t      Nlocals()                   const{return fSize-10000*(fSize/10000);}                //number of local maximums
85          Int_t      Size()                      const{return fSize/10000;}                              //number of digits in cluster
86          Int_t      Fsize()                     const{return fSize;}                                    //
87          Int_t      Shape()                     const{return fShape;}                                   //cluster shape rectangulare
88          Int_t      C()                         const{return fChamber/10;}                              //chamber number
89          Int_t      S()                         const{return fChamber-(fChamber/10)*10;}                //sector number
90          Int_t      Fchamber()                  const{return fChamber;}                                 //
91          Int_t      Q()                         const{return fQdc;}                                     //cluster charge in QDC channels 
92          Double_t   X()                         const{return fX;}                                       //cluster x position in LRS
93          Double_t   Y()                         const{return fY;}                                       //cluster y position in LRS 
94          Int_t      Status()                    const{return fStatus;}                                  //
95          void       SetStatus(Int_t status)         {fStatus=status;}                                     //
96          Int_t      Nmips()                     const{return fCFM-1000000*Ncerenkovs()-1000*Nfeedbacks();} //
97          Int_t      Ncerenkovs()                const{return fCFM/1000000;}                                //
98          Int_t      Nfeedbacks()                const{return (fCFM-1000000*Ncerenkovs())/1000;}            //
99          Bool_t     IsPureMip()                 const{return fCFM<1000;}                                   //
100          Bool_t     IsPureCerenkov()            const{return Nmips()==0&&Nfeedbacks()==0;}                 //
101          Bool_t     IsPureFeedback()            const{return Nmips()==0&&Ncerenkovs()==0;}                 //
102          Bool_t     IsSingleMip()               const{return Nmips()==1&&Ncerenkovs()==0&&Nfeedbacks()==0;}  //
103          Bool_t     IsSingleCerenkov()          const{return Nmips()==0&&Ncerenkovs()==1&&Nfeedbacks()==0;}  //
104          Bool_t     IsSingleFeedback()          const{return Nmips()==0&&Ncerenkovs()==0&&Nfeedbacks()==1;}  //
105          Bool_t     IsMip()                     const{return Nmips()!=0;}                                  //
106          Bool_t     IsCerenkov()                const{return Ncerenkovs()!=0;}                             //
107          Bool_t     IsFeedback()                const{return Nfeedbacks()!=0;}                             //
108          Int_t      CombiPid()                  const{return fCFM;}                                        //
109          void       CFM(Int_t c,Int_t f,Int_t m)     {fCFM=1000000*c+1000*f+m;}                            //cluster contributors
110          TObjArray* Digits()                    const{return fDigits;}                                     //  
111   virtual void      Print(Option_t *option="")const;                                                   //
112   inline  void      AddDigit(AliRICHdigit *pDig);                                                      //
113   inline  void      CoG(Int_t nLocals);                                                                //calculates center of gravity
114           void      Fill(AliRICHcluster *pRaw,Double_t x,Double_t y,Double_t q,Int_t cfm)              //form new resolved cluster from raw one
115                     {fCFM=cfm;fChamber=pRaw->Fchamber();fSize=pRaw->Fsize();fQdc=(Int_t)(q*pRaw->Q());fX=x;fY=y;fStatus=kResolved;} 
116          Double_t   DistTo(TVector2 x)          const{return TMath::Sqrt((x.X()-fX)*(x.X()-fX)+(x.Y()-fY)*(x.Y()-fY));} //distance to given point 
117          Double_t   DistX(TVector2 x)           const{return (x.X()-fX);} //distance in x to given point 
118          Double_t   DistY(TVector2 x)           const{return (x.Y()-fY);} //distance to given point 
119 protected:
120   Int_t         fCFM;         //1000000*Ncerenkovs+1000*Nfeedbacks+Nmips  
121   Int_t         fSize;        //10000*(how many digits belong to this cluster) + nLocalMaxima     
122   Int_t         fShape;       //100*xdim+ydim box containing the cluster
123   Int_t         fQdc;         //QDC value
124   Int_t         fChamber;     //10*module number+sector number 
125   Double_t      fX;           //local x postion 
126   Double_t      fY;           //local y postion  
127   Int_t         fStatus;      //flag to mark the quality of the cluster   
128   TObjArray    *fDigits;      //! list of digits forming this cluster
129   ClassDef(AliRICHcluster,2)  //RICH cluster class       
130 };//class AliRICHcluster
131 //__________________________________________________________________________________________________
132 void AliRICHcluster::AddDigit(AliRICHdigit *pDig)
133 {
134 // Adds a given digit to the list of digits belonging to this cluster    
135   if(!fDigits) {fQdc=fSize=fCFM=0;fDigits = new TObjArray;}
136   fQdc+=(Int_t)pDig->Q(); fDigits->Add(pDig);
137   fChamber=10*pDig->C()+pDig->S();
138   fSize+=10000;
139   fStatus=kRaw;
140 }
141 //__________________________________________________________________________________________________
142 void AliRICHcluster::CoG(Int_t nLocals)
143 {
144 // Calculates naive cluster position as a center of gravity of its digits.
145   Float_t xmin=999,ymin=999,xmax=0,ymax=0;   
146   fX=fY=0;
147   for(Int_t iDig=0;iDig<Size();iDig++) {
148     AliRICHdigit *pDig=(AliRICHdigit*)fDigits->At(iDig);
149     TVector pad=pDig->Pad(); Double_t q=pDig->Q();
150     TVector2 x2=AliRICHParam::Pad2Loc(pad);
151     fX += x2.X()*q;fY +=x2.Y()*q;
152     if(pad[0]<xmin)xmin=pad[0];if(pad[0]>xmax)xmax=pad[0];if(pad[1]<ymin)ymin=pad[1];if(pad[1]>ymax)ymax=pad[1];
153    }
154    fX/=fQdc;fY/=fQdc;//Center of Gravity
155    fShape=Int_t(100*(xmax-xmin+1)+ymax-ymin+1);//find box containing cluster
156    fSize+=nLocals;
157    fStatus=kRaw;
158 }//CoG()
159
160 //__________________AliRICH_________________________________________________________________________
161 class AliESD;
162
163 class AliRICH : public AliDetector 
164 {
165 public:
166             AliRICH();                                            
167             AliRICH(const char *name, const char *title);
168             AliRICH(const AliRICH& RICH):AliDetector(RICH) {;}  //copy ctor 
169   virtual  ~AliRICH();                                            
170           
171   AliRICH&  operator=(const AliRICH&)                 {return *this;}
172 //framework part  
173   virtual Int_t         IsVersion()                           const =0;                                  //interface from         
174   virtual void          StepManager()                               =0;                                  //interface from AliMC
175   virtual void          Hits2SDigits();                                                                  //interface from AliSimulation
176   virtual AliDigitizer* CreateDigitizer(AliRunDigitizer* man) const {return new AliRICHDigitizer(man);}  //interface from AliSimulation
177 //  virtual void          Reconstruct()                         const;                                     //interface from AliReconstruction
178 //  virtual void          FillESD(AliESD *pESD)                 const;                                     //interface from AliReconstruction          
179   virtual void          SetTreeAddress();                                                                //interface from AliLoader
180   virtual void          MakeBranch(Option_t *opt=" ");                                                   //interface from AliLoader
181   virtual void          CreateMaterials();                                                               //interface from AliMC
182   virtual void          CreateGeometry();                                                                //interface from AliMC
183   virtual void          BuildGeometry();                                                                 //interface 
184 //private part  
185           Float_t AbsoCH4(Float_t x)const;                               //calculates absorption length for methane
186           Float_t Fresnel(Float_t ene,Float_t pdoti, Bool_t pola)const;  //deals with Fresnel absorption
187   inline  void    CreateHits();                                          //create hits container as a simple list
188   inline  void    CreateSDigits();                                       //create sdigits container as a simple list
189   inline  void    CreateDigits();                                        //create digits container as 7 lists, one per chamber
190   inline  void    CreateClusters();                                      //create clusters container  as 7 lists, one per chamber
191 //        void    ResetHits()                {AliDetector::ResetHits();}  //virtual  
192           void    ResetSDigits()             {fNsdigits=0;  if(fSdigits)  fSdigits ->Clear();}                                 
193           void    ResetDigits()              {if(fDigitsNew)for(int i=0;i<kNchambers;i++){fDigitsNew->At(i)->Clear();fNdigitsNew[i]=0;}} //virtual
194           void    ResetClusters()            {if(fClusters) for(int i=0;i<kNchambers;i++){fClusters ->At(i)->Clear();fNclusters[i]=0;}}
195   TClonesArray*   SDigits()             const{return fSdigits;}
196   TClonesArray*   Digits(Int_t iC)      const{if(fDigitsNew) return (TClonesArray *)fDigitsNew->At(iC-1);else return 0;}
197   TClonesArray*   Clusters(Int_t iC)    const{if(fClusters)  return (TClonesArray *)fClusters->At(iC-1);else return 0;}
198   AliRICHChamber* C(Int_t iC)           const{return fpParam->C(iC);}                       //provides pointer to a given chamber
199   AliRICHParam*   P()                   const{return fpParam;}                              //provides pointer to a RICH params
200   AliRICH*        R()                        {return this;}                                 //provides pointer to RICH main object
201   TVector         Counters()            const{return fCounters;}                            //provides a set of counters
202   void            ControlPlots();                                                           //utility
203   virtual void    Print(Option_t *option="")               const;                           //prints current RICH status
204   void            PrintHits    (Int_t iEvent=0);                                            //utility
205   void            PrintSDigits (Int_t iEvent=0);                                            //utility
206   void            PrintDigits  (Int_t iEvent=0);                                            //utility
207   void            PrintClusters(Int_t iEvent=0);                                            //utility
208   void            PrintTracks  (Int_t iEvent=0);                                            //utility
209             
210   void AddHit(Int_t c,Int_t tid,TVector3 i3,TVector3 o3,Double_t eloss=0){TClonesArray &tmp=*fHits;new(tmp[fNhits++])AliRICHhit(c,tid,i3,o3,eloss);}
211   inline void AddSDigit(Int_t c,TVector pad,Double_t q,Int_t pid,Int_t tid); 
212   void AddDigit(int c,TVector pad,int q,int cfm,int *tid)//Add simulated digit
213        {TClonesArray &tmp=*((TClonesArray*)fDigitsNew->At(c-1));new(tmp[fNdigitsNew[c-1]++])AliRICHdigit(c,pad,q,cfm,tid[0],tid[1],tid[2]);}  
214   void AddDigit(Int_t c,TVector pad,Int_t q)//for real data digits
215        {TClonesArray &tmp=*((TClonesArray*)fDigitsNew->At(0));new(tmp[fNdigitsNew[0]++])AliRICHdigit(c,pad,q,0,-1,-1,-1);}  
216   void AddCluster(AliRICHcluster &cl)                     
217        {Int_t c=cl.C()-1;TClonesArray &tmp=*((TClonesArray*)fClusters->At(c));new(tmp[fNclusters[c]++])AliRICHcluster(cl);}
218   AliRICHhit* Hit(Int_t tid);           //returns pointer ot RICH hit for a given tid
219 protected:  
220   enum                  {kAir=1,kRoha,kSiO2,kC6F14,kCH4,kCsI,kGridCu,kOpSiO2,kGap,kAl,kGlass,kCu,kW,kSteel,kPerpex,kSr90};
221   AliRICHParam         *fpParam;             //main RICH parametrization     
222                                              //fHits and fDigits belong to AliDetector
223   TClonesArray         *fSdigits;            //! list of sdigits  
224   Int_t                 fNsdigits;           //! current number of sdigits
225   
226   TObjArray            *fDigitsNew;          //! each chamber holds it's one lists of digits
227   Int_t                 fNdigitsNew[kNchambers];   //! array of current numbers of digits
228   
229   TObjArray            *fClusters;           //! each chamber holds it's one lists of clusters 
230   Int_t                 fNclusters[kNchambers];    //! array of current numbers of raw clusters
231   
232   TVector               fCounters;           //Photon history conters, explanation in StepManager() 
233   ClassDef(AliRICH,7)                        //Main RICH class 
234 };//class AliRICH  
235
236 //__________________________________________________________________________________________________
237 void AliRICH::CreateHits()
238 {
239   if(fHits) return;
240   AliDebug(1,"creating hits container.");
241   fHits=new TClonesArray("AliRICHhit",10000);   fNhits=0;
242 }
243 //__________________________________________________________________________________________________
244 void AliRICH::CreateSDigits()
245 {
246   if(fSdigits) return;
247   AliDebug(1,"creating sdigits container.");
248   fSdigits=new TClonesArray("AliRICHdigit",10000); fNsdigits=0;
249 }
250 //__________________________________________________________________________________________________
251 void AliRICH::CreateDigits()
252 {
253   if(fDigitsNew) return;
254   AliDebug(1,"creating digits containers.");
255   fDigitsNew = new TObjArray(kNchambers);  
256   for(Int_t i=0;i<kNchambers;i++) {fDigitsNew->AddAt(new TClonesArray("AliRICHdigit",10000), i); fNdigitsNew[i]=0;}
257 }
258 //__________________________________________________________________________________________________
259 void AliRICH::CreateClusters()
260 {
261   if(fClusters) return;
262   AliDebug(1,"creating clusters containers.");
263   fClusters = new TObjArray(kNchambers);  
264   for(Int_t i=0;i<kNchambers;i++) {fClusters->AddAt(new TClonesArray("AliRICHcluster",10000), i); fNclusters[i]=0;}
265 }
266 //__________________________________________________________________________________________________
267 void AliRICH::AddSDigit(Int_t c,TVector pad,Double_t q,Int_t pid,Int_t tid) 
268
269   Int_t cfm;  
270   switch(pid){
271     case 50000050: cfm=1000000;break;//cerenkov
272     case 50000051: cfm=1000;   break;//feedback
273     default:       cfm=1;      break;//mip
274   }   
275   TClonesArray &tmp=*fSdigits; new(tmp[fNsdigits++])AliRICHdigit(c,pad,q,cfm,tid,kBad,kBad);
276 }
277 //__________________________________________________________________________________________________
278 #endif//#ifndef AliRICH_h