]> git.uio.no Git - u/mrichter/AliRoot.git/blob - RICH/AliRICHpoints.cxx
Correct improper use of negative parameters
[u/mrichter/AliRoot.git] / RICH / AliRICHpoints.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 //                                                                           //
22 //  This class contains the points for the ALICE event display               //
23 //                                                                           //
24 //Begin_Html
25 /*
26 <img src="gif/AliRICHpointsClass.gif">
27 */
28 //End_Html
29 //                                                                           //
30 //                                                                           //
31 ///////////////////////////////////////////////////////////////////////////////
32 #include "AliRICHdisplay.h"
33 #include "AliRICHpoints.h"
34 #include "AliRun.h"
35 #include "TPad.h"
36 #include "TView.h"
37 #include "TMath.h"
38
39 const Int_t MAX_Nipx=400, MAX_Nipy=800;
40  
41 ClassImp(AliRICHpoints)
42
43 //_____________________________________________________________________________
44 AliRICHpoints::AliRICHpoints()
45 {
46   //
47   // Default constructor
48   //
49   fHitIndex = 0;
50   fTrackIndex = 0;
51   fDigitIndex = 0;
52 }
53
54 //_____________________________________________________________________________
55 AliRICHpoints::AliRICHpoints(Int_t npoints)
56   :AliPoints(npoints)
57 {
58   //
59   // Standard constructor
60   //
61   fHitIndex = 0;
62   fTrackIndex = 0;
63   fDigitIndex = 0;
64 }
65          
66 //_____________________________________________________________________________
67 AliRICHpoints::~AliRICHpoints()
68 {
69   //
70   // Default destructor
71   //
72   fHitIndex = 0;
73   fTrackIndex = 0;
74   fDigitIndex = 0;
75 }
76
77 //_____________________________________________________________________________
78 void AliRICHpoints::DumpHit()
79 {
80   //
81   //   Dump hit corresponding to this point
82   //
83   AliRICHhit *hit = GetHit();
84   if (hit) hit->Dump();
85 }
86
87 //_____________________________________________________________________________
88 void AliRICHpoints::DumpDigit()
89 {
90   //
91   //   Dump digit corresponding to this point
92   //
93   AliRICHdigit *digit = GetDigit();
94   if (digit) digit->Dump();
95 }
96
97 //_____________________________________________________________________________
98 void AliRICHpoints::InspectHit()
99 {
100   //
101   //   Inspect hit corresponding to this point
102   //
103   AliRICHhit *hit = GetHit();
104   if (hit) hit->Inspect();
105 }
106
107 //_____________________________________________________________________________
108 void AliRICHpoints::InspectDigit()
109 {
110   //
111   //   Inspect digit corresponding to this point
112   //
113   AliRICHdigit *digit = GetDigit();
114   if (digit) digit->Inspect();
115 }
116
117 //_____________________________________________________________________________
118 Int_t AliRICHpoints::GetTrackIndex()
119 {
120   //
121   //   Dump digit corresponding to this point
122   //
123   printf("GetTrackIndex - fTrackIndex %d \n",fTrackIndex);
124   this->Inspect();
125   return fTrackIndex;
126 }
127
128 //_____________________________________________________________________________
129 AliRICHhit *AliRICHpoints::GetHit() const
130 {
131   //
132   //   Returns pointer to hit index in AliRun::fParticles
133   //
134   AliRICH *RICH  = (AliRICH*)gAlice->GetDetector("RICH");
135   gAlice->TreeH()->GetEvent(fTrackIndex);
136   TClonesArray *RICHhits  = RICH->Hits();
137   Int_t nhits = RICHhits->GetEntriesFast();
138   if (fHitIndex < 0 || fHitIndex >= nhits) return 0;
139   return (AliRICHhit*)RICHhits->UncheckedAt(fHitIndex);
140 }
141
142 //_____________________________________________________________________________
143 AliRICHdigit *AliRICHpoints::GetDigit() const
144 {
145   //
146   //   Returns pointer to digit index in AliRun::fParticles
147   //
148
149   AliRICHdisplay *display=(AliRICHdisplay*)gAlice->Display();
150   Int_t chamber=display->GetChamber();
151   Int_t cathode=display->GetCathode();
152    
153   AliRICH *RICH  = (AliRICH*)gAlice->GetDetector("RICH");
154   TClonesArray *RICHdigits  = RICH->DigitsAddress(chamber-1);
155   gAlice->TreeD()->GetEvent(cathode);
156   Int_t ndigits = RICHdigits->GetEntriesFast();
157   if (fDigitIndex < 0 || fDigitIndex >= ndigits) return 0;
158   return (AliRICHdigit*)RICHdigits->UncheckedAt(fDigitIndex);
159 }
160 //_____________________________________________________________________________
161 struct Bin {
162    const AliRICHdigit *dig;
163    int idx;
164    Bin() {dig=0; idx=-1;}
165 };
166
167 struct PreCluster : public AliRICHreccluster {
168    const AliRICHdigit* summit;
169    int idx;
170    int cut;
171    int npeaks;
172    PreCluster() : AliRICHreccluster() {cut=npeaks=0;}
173 };
174 //_____________________________________________________________________________
175
176 static void FindCluster(AliRICHchamber *iChamber, AliRICHsegmentation *segmentation, int i, int j, Bin bins[MAX_Nipx][MAX_Nipy], PreCluster &c) 
177
178 {
179
180   //
181   // Find clusters
182   //
183
184   printf("I'm in FindCluster \n"); 
185
186   Bin& b=bins[i][j];
187   Int_t q=b.dig->fSignal;
188
189   printf("FindCluster - i j q %d %d %d\n",i,j,q);
190   
191   if (q<0) { 
192     q=-q;
193     c.cut=1;
194   } 
195   if (b.idx >= 0 && b.idx != c.idx) {
196     c.idx=b.idx;
197     c.npeaks++;
198   }
199   
200   if (q > TMath::Abs(c.summit->fSignal)) c.summit=b.dig;
201
202   Int_t npx  = segmentation->Npx();
203   Int_t npy  = segmentation->Npy();
204   Float_t x,y;
205   segmentation->GetPadCxy(i-npx, j-npy, x,y);
206   printf("FindCluster - x  y %f %f \n",x,y);
207
208
209   c.fX += q*x;
210   c.fY += q*y;
211   c.fQ += q;
212   
213   b.dig = 0;  b.idx = c.idx;
214   
215   if (bins[i-1][j].dig) FindCluster(iChamber,segmentation,i-1,j,bins,c);
216   if (bins[i][j-1].dig) FindCluster(iChamber,segmentation,i,j-1,bins,c);
217   if (bins[i+1][j].dig) FindCluster(iChamber,segmentation,i+1,j,bins,c);
218   if (bins[i][j+1].dig) FindCluster(iChamber,segmentation,i,j+1,bins,c);
219
220 }
221
222 //_____________________________________________________________________________
223
224 void AliRICHpoints::GetCenterOfGravity()
225 {
226   //
227   // simple RICH cluster finder from digits -- finds neighbours and 
228   // calculates center of gravity for the cluster
229   //
230   const Int_t MAX_nipx=400, MAX_nipy=800;
231   printf("\n Hallo world");
232   AliRICHdisplay *display=(AliRICHdisplay*)gAlice->Display();
233   Int_t chamber=display->GetChamber();
234   Int_t cathode=display->GetCathode();
235    
236   AliRICH *RICH  = (AliRICH*)gAlice->GetDetector("RICH");
237   AliRICHchamber *iChamber;
238   AliRICHsegmentation *segmentation;
239   iChamber =&(RICH->Chamber(chamber-1));
240   segmentation=iChamber->GetSegmentationModel(cathode);
241   Int_t npx  = segmentation->Npx();
242   Int_t npy  = segmentation->Npy();
243   Float_t zpos=iChamber->ZPosition();
244   
245   TClonesArray *RICHdigits  = RICH->DigitsAddress(chamber-1);
246   gAlice->TreeD()->GetEvent(cathode);
247   Int_t ndigits = RICHdigits->GetEntriesFast();
248   if (fDigitIndex < 0 || fDigitIndex >= ndigits) return;
249
250   AliRICHdigit  *dig;
251   dig=(AliRICHdigit*)RICHdigits->UncheckedAt(fDigitIndex);
252   Int_t ipx=dig->fPadX;
253   Int_t ipy=dig->fPadY;
254   Bin bins[MAX_nipx][MAX_nipy]; 
255   bins[ipx+npx][ipy+npy].dig=dig;
256     
257   int ndig;
258   int ncls=0;
259   for (ndig=0; ndig<ndigits; ndig++) {
260       dig = (AliRICHdigit*)RICHdigits->UncheckedAt(ndig);
261       int i=dig->fPadX, j=dig->fPadY;
262       bins[i+npx][j+npy].dig=dig;
263   }
264
265   PreCluster c; c.summit=bins[ipx+npx][ipy+npy].dig; c.idx=ncls;
266   FindCluster(iChamber,segmentation,ipx+npx, ipy+npy, bins, c);
267   if (c.npeaks>1) {
268       printf("GetCenterOfGravity -- more than one peak");
269   }
270   c.fX /= c.fQ;
271   c.fY /= c.fQ;
272   printf("GetCenterOfGravity - c.fX c.fY c.fQ %f %f %d \n",c.fX,c.fY,c.fQ);
273   
274   c.fTracks[0]=c.summit->fTracks[0];
275   c.fTracks[1]=c.summit->fTracks[1];
276   c.fTracks[2]=c.summit->fTracks[2];
277   ncls++;
278   AliRICHpoints *points = 0;
279   points = new AliRICHpoints(1);
280   points->SetMarkerColor(kYellow);
281   points->SetMarkerStyle(5);
282   points->SetMarkerSize(1.);
283   points->SetPoint(0,c.fX,c.fY,zpos);
284   points->Draw();
285   
286   printf("GetCenterOfGravity -- ncls %d \n",ncls);
287
288 }
289
290
291