some minor changes to adpat for the situation when no digits or clusters avalbale
[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 protected:
62   Int_t    fChFbMip;  //1000000*Ncerenkovs+1000*Nfeedbacks+Nmips  
63   Int_t    fChamber;  //10*chamber number+ sector number 
64   Int_t    fPadX;     //pad number along X
65   Int_t    fPadY;     //pad number along Y
66   Double_t fQdc;      //QDC value, fractions are permitted for summable procedure  
67   ClassDef(AliRICHdigit,3) //RICH digit class       
68 };//class AliRICHdigit
69
70 //__________________AliRICHcluster__________________________________________________________________
71 class AliRICHcluster :public TObject
72 {
73 public:
74   enum ClusterStatus {kEdge,kShape,kSize,kRaw,kResolved};
75                     AliRICHcluster()                                 {fSize=fQdc=fStatus=fChamber=fDimXY=0;fX=fY=kBad;fDigits=0;}
76   virtual          ~AliRICHcluster()                                 {delete fDigits;}  
77   AliRICHcluster&   operator=(const AliRICHcluster&)                 {return *this;}
78          Int_t      Nlocals()                                   const{return fSize - 10000*(fSize/10000);} //
79          Int_t      Size()                                      const{return fSize/10000;}                 //
80          Int_t      Fsize()                                     const{return fSize;}                       //
81          Int_t      DimXY()                                     const{return fDimXY;}                      //
82          Int_t      C()                                         const{return fChamber/10;}                 //
83          Int_t      S()                                         const{return fChamber-(fChamber/10)*10;}   //
84          Int_t      Fchamber()                                  const{return fChamber;}                    //
85          Int_t      Q()                                         const{return fQdc;}                        // 
86          Double_t   X()                                         const{return fX;}                          //
87          Double_t   Y()                                         const{return fY;}                          // 
88          Int_t      Status()                                    const{return fStatus;}                     //
89          void       SetStatus(Int_t status)                          {fStatus=status;}                     //
90          Int_t      Nmips()                                     const{return fCombiPid-1000000*Ncerenkovs()-1000*Nfeedbacks();}  //
91          Int_t      Ncerenkovs()                                const{return fCombiPid/1000000;}           //
92          Int_t      Nfeedbacks()                                const{return (fCombiPid-1000000*Ncerenkovs())/1000;}      //
93          Bool_t     IsPureMip()                                 const{return fCombiPid<1000;}   
94          Bool_t     IsPureCerenkov()                            const{return Nmips()==0&&Nfeedbacks()==0;} //
95          Bool_t     IsPureFeedback()                            const{return Nmips()==0&&Ncerenkovs()==0;} //
96          Int_t      CombiPid()                                  const{return fCombiPid;} //
97          void       SetCombiPid(Int_t ckov,Int_t feeds,Int_t mips)   {fCombiPid=1000000*ckov+1000*feeds+mips;}            //
98          void       Fill(AliRICHcluster *pRaw,Double_t x,Double_t y, Double_t q, Int_t combipid)
99              {fCombiPid=combipid;fChamber=pRaw->Fchamber();fSize=pRaw->Fsize();
100               fQdc=(Int_t)(q*pRaw->Q());fX=x;fY=y;fStatus=kResolved;} //
101          TObjArray* Digits()                                    const{return fDigits;}                     //  
102          void       Print(Option_t *option="")const;                                                       //virtual
103   inline void       AddDigit(AliRICHdigit *pDig);                                                          //
104   inline void       CoG(Int_t nLocals);                                                                                 // 
105          void       Reset() {fSize=fQdc=fStatus=fChamber=fDimXY=kBad;fX=fY=kBad;delete fDigits;fDigits=0;} //
106 protected:
107   Int_t         fCombiPid;    //1000000*Ncerenkovs+1000*Nfeedbacks+Nmips  
108   Int_t         fSize;        //10000*(how many digits belong to this cluster) + nLocalMaxima     
109   Int_t         fDimXY;       //100*xdim+ydim box containing the cluster
110   Int_t         fQdc;         //QDC value
111   Int_t         fChamber;     //10*module number+sector number 
112   Double_t      fX;           //local x postion 
113   Double_t      fY;           //local y postion  
114   Int_t         fStatus;      //flag to mark the quality of the cluster   
115   TObjArray    *fDigits;      //! list of digits forming this cluster
116   ClassDef(AliRICHcluster,2)  //RICH cluster class       
117 };//class AliRICHcluster
118 //__________________________________________________________________________________________________
119 void AliRICHcluster::AddDigit(AliRICHdigit *pDig)
120 {//    
121   if(!fDigits) {fQdc=fSize=fCombiPid=0;fDigits = new TObjArray;}
122   fQdc+=(Int_t)pDig->Q(); fDigits->Add(pDig);
123   fChamber=10*pDig->C()+pDig->S();
124   fSize+=10000;
125 }
126 //__________________________________________________________________________________________________
127 void AliRICHcluster::CoG(Int_t nLocals)
128 {//
129   Int_t xmin=999,ymin=999,xmax=0,ymax=0;   
130   fX=fY=0;
131   for(Int_t iDig=0;iDig<Size();iDig++) {
132     AliRICHdigit *pDig=(AliRICHdigit*)fDigits->At(iDig);
133     Int_t padX = pDig->X();Int_t padY = pDig->Y();Double_t q=pDig->Q();
134     TVector2 x2=AliRICHParam::Pad2Loc(padX,padY);
135     fX += x2.X()*q;fY +=x2.Y()*q;
136     if(padX<xmin)xmin=padX;if(padX>xmax)xmax=padX;if(padY<ymin)ymin=padY;if(padY>ymax)ymax=padY;
137    }
138    fX/=fQdc;fY/=fQdc;//Center of Gravity
139    fDimXY = 100*(xmax-xmin+1)+ymax-ymin+1;//find box containing cluster
140    fSize+=nLocals;
141    fStatus=kRaw;
142 }//CoG()
143
144
145 class AliRICHreco: public TObject
146 {
147 public:
148             AliRICHreco() {fTid=fNphotons=kBad; fThetaCherenkov=kBad;}
149             AliRICHreco(Int_t tid,Double_t thetaCherenkov,Int_t nPhotons) {fTid=tid;fThetaCherenkov=thetaCherenkov;fNphotons=nPhotons;}
150
151   virtual  ~AliRICHreco() {;}
152
153   void    Print(Option_t *option="")const;      //virtual print
154   
155 protected:
156    Int_t fTid;                 // track Id reference
157    Int_t fNphotons;            // number of photons contributed to the recontruction
158    Double_t fThetaCherenkov;   // reconstructed Theta Cerenkov for a given charged track
159
160    ClassDef(AliRICHreco,1)  //RICH reco class
161
162 };//class AliRICHreco
163
164 //__________________AliRICH_________________________________________________________________________
165 class AliRICHParam;
166 class AliRICHChamber;
167
168 class AliRICH : public AliDetector 
169 {
170 public:
171             AliRICH();                                            
172             AliRICH(const char *name, const char *title);
173             AliRICH(const AliRICH& RICH):AliDetector(RICH) {;}  //copy ctor 
174   virtual  ~AliRICH();                                            
175           
176   AliRICH&  operator=(const AliRICH&)                 {return *this;}
177 //framework part  
178   virtual Int_t   IsVersion()                                            const =0;                                //virtual         
179   virtual void    StepManager()                                                =0;                                //virtual
180           void    Hits2SDigits();                                                                                 //virtual
181   AliDigitizer*   CreateDigitizer(AliRunDigitizer* man) const {return new AliRICHDigitizer(man);}                 //virtual
182           void    Print(Option_t *option)const;                                                                   //virtual
183           void    SetTreeAddress();                                                                               //virtual
184           void    MakeBranch(Option_t *opt=" ");                                                                  //virtual
185           void    CreateMaterials();                                                                              //virtual
186   virtual void    BuildGeometry();                                                                                //virtual
187   virtual void    CreateGeometry();                                                                               //virtual
188 //private part  
189           Float_t AbsoCH4(Float_t x)const;                               //calculates absorption length for methane
190           Float_t Fresnel(Float_t ene,Float_t pdoti, Bool_t pola)const;  //deals with Fresnel absorption
191           void    GenerateFeedbacks(Int_t iChamber,Float_t eloss=0);     //generates feedback photons; eloss=0 for photon
192           void    CreateChambers();                                      //creates set of chambers
193   inline  void    CreateHits();                                          //create hits container as a simple list
194   inline  void    CreateSDigits();                                       //create sdigits container as a simple list
195   inline  void    CreateDigits();                                        //create digits container as 7 lists, one per chamber
196   inline  void    CreateClusters();                                      //create clusters container  as 7 lists, one per chamber
197   inline  void    CreateRecos();                                         //create recos container
198 //        void    ResetHits()                {AliDetector::ResetHits();}  //virtual  
199           void    ResetSDigits()             {fNsdigits=0;  if(fSdigits)  fSdigits ->Clear();}                                 
200           void    ResetDigits()              {if(fDigitsNew)for(int i=0;i<kNCH;i++){fDigitsNew->At(i)->Clear();fNdigitsNew[i]=0;}} //virtual
201           void    ResetClusters()            {if(fClusters) for(int i=0;i<kNCH;i++){fClusters ->At(i)->Clear();fNclusters[i]=0;}}
202           void    ResetRecos()               {if(fRecos) fRecos->Clear();fNrecos=0;}
203   TClonesArray*   SDigits()             const{return fSdigits;}
204   TClonesArray*   Digits(Int_t iC)      const{if(fDigitsNew) return (TClonesArray *)fDigitsNew->At(iC-1);else return 0;}
205   TClonesArray*   Clusters(Int_t iC)    const{if(fClusters)  return (TClonesArray *)fClusters->At(iC-1);else return 0;}
206   TClonesArray*   Recos()               const{return fRecos;}
207   AliRICHChamber* C(Int_t iC)           const{return (AliRICHChamber*)fChambers->At(iC-1);}
208   AliRICHParam*   P()                   const{return fpParam;}
209           void    PrintDigits()         const{for(Int_t i=0;i<kNCH;i++) fDigitsNew->At(i)->Print();}
210           void    PrintClusters()       const{for(Int_t i=0;i<kNCH;i++) fClusters->At(i)->Print();}
211             
212   void AddHit(Int_t chamber,Int_t tid,TVector3 iX3,TVector3 oX3,Double_t eloss=0)
213        {TClonesArray &tmp=*fHits;new(tmp[fNhits++])AliRICHhit(chamber,tid,iX3,oX3,eloss);} 
214   inline void AddSDigit(Int_t c,Int_t x,Int_t y,Double_t q,Int_t pid,Int_t tid); 
215   void AddDigit(int c,int x,int y,int q,int cfm,int *tid)
216        {TClonesArray &tmp=*((TClonesArray*)fDigitsNew->At(c-1));new(tmp[fNdigitsNew[c-1]++])AliRICHdigit(c,x,y,q,cfm,tid[0],tid[1],tid[2]);}  
217   void AddCluster(AliRICHcluster &cl)                     
218        {Int_t c=cl.C()-1;cout<<c<<endl;TClonesArray &tmp=*((TClonesArray*)fClusters->At(c));new(tmp[fNclusters[c]++])AliRICHcluster(cl);}
219   void AddReco(Int_t tid,Double_t thetaCherenkov,Int_t nPhotons) 
220        {TClonesArray &tmp=*(TClonesArray*)fRecos;new(tmp[fNrecos++])AliRICHreco(tid,thetaCherenkov,nPhotons);}  
221           
222 protected:  
223   enum                  {kCSI=6,kGAP=9};
224   AliRICHParam         *fpParam;             //main RICH parametrization     
225   TObjArray            *fChambers;           //list of RICH chambers
226   
227                                              //fHits and fDigits belong to AliDetector
228   TClonesArray         *fSdigits;            //! List of sdigits  
229   Int_t                 fNsdigits;           //! Current number of sdigits
230   
231   TObjArray            *fDigitsNew;          //! Each chamber holds it's one lists of digits
232   Int_t                 fNdigitsNew[kNCH];   //! Array of current numbers of digits
233   
234   TObjArray            *fClusters;           //! Each chamber holds it's one lists of clusters 
235   Int_t                 fNclusters[kNCH];    //! Array of current numbers of raw clusters
236   
237   TClonesArray         *fRecos;              //! pointer to the list of recos
238   Int_t                 fNrecos;             //! number of recos
239
240   ClassDef(AliRICH,5)                        //Main RICH class 
241 };//class AliRICH  
242
243 //__________________________________________________________________________________________________
244 void AliRICH::CreateHits()
245 {
246   if(fHits) return;
247   if(GetDebug())Info("CreateHits","creating hits container.");
248   fHits=new TClonesArray("AliRICHhit",10000);   fNhits=0;
249 }
250 //__________________________________________________________________________________________________
251 void AliRICH::CreateSDigits()
252 {
253   if(fSdigits) return;
254   if(GetDebug())Info("CreateSDigits","creating sdigits container.");
255   fSdigits=new TClonesArray("AliRICHdigit",10000); fNsdigits=0;
256 }
257 //__________________________________________________________________________________________________
258 void AliRICH::CreateDigits()
259 {
260   if(fDigitsNew) return;
261   if(GetDebug())Info("CreateDigits","creating digits containers.");
262   fDigitsNew = new TObjArray(kNCH);  
263   for(Int_t i=0;i<kNCH;i++) {fDigitsNew->AddAt(new TClonesArray("AliRICHdigit",10000), i); fNdigitsNew[i]=0;}
264 }
265 //__________________________________________________________________________________________________
266 void AliRICH::CreateClusters()
267 {
268   if(fClusters) return;
269   if(GetDebug())Info("CreateClusters","creating clusters containers.");
270   fClusters = new TObjArray(kNCH);  
271   for(Int_t i=0;i<kNCH;i++) {fClusters->AddAt(new TClonesArray("AliRICHcluster",10000), i); fNclusters[i]=0;}
272 }
273 //__________________________________________________________________________________________________
274 void AliRICH::CreateRecos()
275 {
276   if(fRecos) return;
277   if(GetDebug())Info("CreateRecos","creating recos containers.");
278   fRecos = new TClonesArray("AliRICHreco",1000);fNrecos=0;  
279 }
280 //__________________________________________________________________________________________________
281 void AliRICH::AddSDigit(Int_t c,Int_t x,Int_t y,Double_t q,Int_t pid,Int_t tid) 
282 {   
283   switch(pid){
284     case 50000050: pid=1000000;break;//cerenkov
285     case 50000051: pid=1000;   break;//feedback
286     default:       pid=1;      break;//mip
287   }   
288   TClonesArray &tmp=*fSdigits;
289   new(tmp[fNsdigits++])AliRICHdigit(c,x,y,q,pid,tid,kBad,kBad);
290 }//AddSDigit()   
291 //__________________________________________________________________________________________________
292 #endif//#ifndef AliRICH_h