Data classes for RICH (completely updated) (JB,AM)
[u/mrichter/AliRoot.git] / RICH / DataStructures.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /*
17   $Log$
18 */
19
20
21 #include "DataStructures.h"
22 #include "AliRun.h"
23 #include <TObjArray.h>
24 #include <TParticle.h>
25
26 ClassImp(AliRICHPadHit)
27
28 ClassImp(AliRICHHit)
29     
30 //___________________________________________
31 AliRICHHit::AliRICHHit(Int_t shunt, Int_t track, Int_t *vol, Float_t *hits):
32     AliHit(shunt, track)
33 {
34     fChamber=vol[0];
35     fParticle=hits[0];
36     fX=hits[1];
37     fY=hits[2];
38     fZ=hits[3];
39     fTheta=hits[4];
40     fPhi=hits[5];
41     fTlength=hits[6];
42     fEloss=hits[7];
43     fPHfirst=(Int_t) hits[8];
44     fPHlast=(Int_t) hits[9];
45     fLoss=hits[13];
46     fMomX=hits[14];
47     fMomY=hits[15];
48     fMomZ=hits[16];
49 }
50
51 ClassImp(AliRICHCerenkov)
52 //___________________________________________
53 AliRICHCerenkov::AliRICHCerenkov(Int_t shunt, Int_t track, Int_t *vol, Float_t *hits):
54     AliHit(shunt, track)
55 {
56     fChamber=vol[0];
57     fX=hits[1];
58     fY=hits[2];
59     fZ=hits[3];
60     fTheta=hits[4];
61     fPhi=hits[5];
62     fEloss=hits[7];
63     fPHfirst=(Int_t) hits[8];
64     fPHlast=(Int_t) hits[9];
65     fCMother=Int_t(hits[10]);
66     fIndex = hits[11];
67     fProduction = hits[12];  
68     fLoss=hits[13];
69     fMomX=hits[14];
70     fMomY=hits[15];
71     fMomZ=hits[16];
72 }
73
74 //___________________________________________
75 AliRICHPadHit::AliRICHPadHit(Int_t *clhits)
76 {
77     fHitNumber=clhits[0];
78     fCathode=clhits[1];
79     fQ=clhits[2];
80     fPadX=clhits[3];
81     fPadY=clhits[4];
82     fQpad=clhits[5];
83     fRSec=clhits[6];
84 }
85
86 ClassImp(AliRICHDigit)
87 //_____________________________________________________________________________
88 AliRICHDigit::AliRICHDigit(Int_t *digits)
89 {
90     //
91     // Creates a RICH digit object to be updated
92     //
93     fPadX        = digits[0];
94     fPadY        = digits[1];
95     fSignal      = digits[2];
96     
97 }
98 //_____________________________________________________________________________
99 AliRICHDigit::AliRICHDigit(Int_t *tracks, Int_t *charges, Int_t *digits)
100 {
101     //
102     // Creates a RICH digit object
103     //
104     fPadX        = digits[0];
105     fPadY        = digits[1];
106     fSignal      = digits[2];
107     for(Int_t i=0; i<100; i++) {
108         fTcharges[i]  = charges[i];
109         fTracks[i]    = tracks[i];
110     }
111 }
112
113 ClassImp(AliRICHTransientDigit)
114     
115 //____________________________________________________________________________
116 AliRICHTransientDigit::AliRICHTransientDigit(Int_t ich, Int_t *digits): 
117     AliRICHDigit(digits)
118 {
119     //
120     // Creates a RICH digit list object
121     //
122     
123     fChamber = ich;
124     fTrackList   = new TObjArray;
125     
126 }
127 //_____________________________________________________________________________
128
129
130 ClassImp(AliRICHRawCluster)
131 Int_t AliRICHRawCluster::Compare(TObject *obj)
132 {
133          AliRICHRawCluster *raw=(AliRICHRawCluster *)obj;
134          Float_t y=fY;
135          Float_t yo=raw->fY;
136          if (y>yo) return 1;
137          else if (y<yo) return -1;
138          else return 0;
139
140 }
141
142 Int_t AliRICHRawCluster::
143 BinarySearch(Float_t y, TArrayF coord, Int_t from, Int_t upto)
144 {
145    // Find object using a binary search. Array must first have been sorted.
146    // Search can be limited by setting upto to desired index.
147
148    Int_t low=from, high=upto-1, half;
149    while(high-low>1) {
150         half=(high+low)/2;
151         if(y>coord[half]) low=half;
152         else high=half;
153    }
154    return low;
155 }
156
157 void AliRICHRawCluster::SortMin(Int_t *idx,Float_t *xdarray,Float_t *xarray,Float_t *yarray,Float_t *qarray, Int_t ntr)
158 {
159   //
160   // Get the 3 closest points(cog) one can find on the second cathode 
161   // starting from a given cog on first cathode
162   //
163   
164   //
165   //  Loop over deltax, only 3 times
166   //
167   
168     Float_t xmin;
169     Int_t jmin;
170     Int_t id[3] = {-2,-2,-2};
171     Float_t jx[3] = {0.,0.,0.};
172     Float_t jy[3] = {0.,0.,0.};
173     Float_t jq[3] = {0.,0.,0.};
174     Int_t jid[3] = {-2,-2,-2};
175     Int_t i,j,imax;
176   
177     if (ntr<3) imax=ntr;
178     else imax=3;
179     for(i=0;i<imax;i++){
180         xmin=1001.;
181         jmin=0;
182     
183         for(j=0;j<ntr;j++){
184             if ((i == 1 && j == id[i-1]) 
185                   ||(i == 2 && (j == id[i-1] || j == id[i-2]))) continue;
186            if (TMath::Abs(xdarray[j]) < xmin) {
187               xmin = TMath::Abs(xdarray[j]);
188               jmin=j;
189            }       
190         } // j
191         if (xmin != 1001.) {    
192            id[i]=jmin;
193            jx[i]=xarray[jmin]; 
194            jy[i]=yarray[jmin]; 
195            jq[i]=qarray[jmin]; 
196            jid[i]=idx[jmin];
197         } 
198     
199     }  // i
200   
201     for (i=0;i<3;i++){
202         if (jid[i] == -2) {
203             xarray[i]=1001.;
204             yarray[i]=1001.;
205             qarray[i]=1001.;
206             idx[i]=-1;
207         } else {
208             xarray[i]=jx[i];
209             yarray[i]=jy[i];
210             qarray[i]=jq[i];
211             idx[i]=jid[i];
212         }
213     }
214
215 }
216
217
218 Int_t AliRICHRawCluster::PhysicsContribution()
219 {
220     Int_t iPhys=0;
221     Int_t iBg=0;
222     Int_t iMixed=0;
223     for (Int_t i=0; i<fMultiplicity; i++) {
224         if (fPhysicsMap[i]==2) iPhys++;
225         if (fPhysicsMap[i]==1) iMixed++;
226         if (fPhysicsMap[i]==0) iBg++;
227     }
228     if (iMixed==0 && iBg==0) {
229         return 2;
230     } else if ((iPhys != 0 && iBg !=0) || iMixed != 0) {
231         return 1;
232     } else {
233         return 0;
234     }
235 }
236 //_____________________________________________________________________________
237
238
239 ClassImp(AliRICHRecHit)
240
241
242 //_____________________________________________________________________________
243 AliRICHRecHit::AliRICHRecHit(Int_t id, Float_t *rechit)
244 {
245     //
246     // Creates a RICH rec. hit object
247     //
248     Theta        = rechit[0];
249     Phi          = rechit[1];
250     Omega        = rechit[2];
251     fX           = rechit[3];
252     fY           = rechit[4];
253 }