]> git.uio.no Git - u/mrichter/AliRoot.git/blob - RICH/AliRICHPoints.cxx
Added the ShowRing function.
[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   Revision 1.1  2000/04/19 13:16:47  morsch
19   Minor changes on class names.
20
21 */
22
23
24 ///////////////////////////////////////////////////////////////////////////////
25 //                                                                           //
26 //  This class contains the points for the ALICE event display               //
27 //                                                                           //
28 //Begin_Html
29 /*
30 <img src="gif/AliRICHPointsClass.gif">
31 */
32 //End_Html
33 //                                                                           //
34 //                                                                           //
35 ///////////////////////////////////////////////////////////////////////////////
36 #include "AliRICHDisplay.h"
37 #include "AliRICHPoints.h"
38 #include "AliRun.h"
39 #include "TPad.h"
40 #include "TView.h"
41 #include "TMath.h"
42
43 const Int_t MAX_Nipx=400, MAX_Nipy=800;
44  
45 ClassImp(AliRICHPoints)
46
47 //_____________________________________________________________________________
48 AliRICHPoints::AliRICHPoints()
49 {
50   //
51   // Default constructor
52   //
53   fHitIndex = 0;
54   fTrackIndex = 0;
55   fDigitIndex = 0;
56   fMarker[0] = fMarker[1] = fMarker[2]=0;
57 }
58
59 //_____________________________________________________________________________
60 AliRICHPoints::AliRICHPoints(Int_t npoints)
61   :AliPoints(npoints)
62 {
63   //
64   // Standard constructor
65   //
66   fHitIndex = 0;
67   fTrackIndex = 0;
68   fDigitIndex = 0;
69   fMarker[0] = fMarker[1] = fMarker[2]=0;
70 }
71          
72 //_____________________________________________________________________________
73 AliRICHPoints::~AliRICHPoints()
74 {
75   //
76   // Default destructor
77   //
78   fHitIndex = 0;
79   fTrackIndex = 0;
80   fDigitIndex = 0;
81 }
82
83 //_____________________________________________________________________________
84 void AliRICHPoints::DumpHit()
85 {
86   //
87   //   Dump hit corresponding to this point
88   //
89   AliRICHHit *hit = GetHit();
90   if (hit) hit->Dump();
91 }
92
93 //_____________________________________________________________________________
94 void AliRICHPoints::DumpDigit()
95 {
96   //
97   //   Dump digit corresponding to this point
98   //
99   AliRICHDigit *digit = GetDigit();
100   if (digit) digit->Dump();
101 }
102
103 //_____________________________________________________________________________
104 void AliRICHPoints::InspectHit()
105 {
106   //
107   //   Inspect hit corresponding to this point
108   //
109   AliRICHHit *hit = GetHit();
110   if (hit) hit->Inspect();
111 }
112
113 //_____________________________________________________________________________
114 void AliRICHPoints::InspectDigit()
115 {
116   //
117   //   Inspect digit corresponding to this point
118   //
119   AliRICHDigit *digit = GetDigit();
120   if (digit) digit->Inspect();
121 }
122
123 //_____________________________________________________________________________
124 Int_t AliRICHPoints::GetTrackIndex()
125 {
126   //
127   //   Dump digit corresponding to this point
128   //
129   printf("GetTrackIndex - fTrackIndex %d \n",fTrackIndex);
130   this->Inspect();
131   return fTrackIndex;
132 }
133 //_____________________________________________________________________________
134 TParticle *AliRICHPoints::GetParticle() const
135 {
136   //
137   //   Returns pointer to particle index in AliRun::fParticles
138   //
139   TClonesArray *particles = gAlice->Particles();
140   Int_t nparticles = particles->GetEntriesFast();
141   if (fIndex < 0 || fIndex >= nparticles) return 0;
142   return (TParticle*)particles->UncheckedAt(fIndex);
143 }
144
145 //_____________________________________________________________________________
146 AliRICHHit *AliRICHPoints::GetHit() const
147 {
148   //
149   //   Returns pointer to hit index in AliRun::fParticles
150   //
151   AliRICH *RICH  = (AliRICH*)gAlice->GetDetector("RICH");
152   gAlice->TreeH()->GetEvent(fTrackIndex);
153   TClonesArray *RICHhits  = RICH->Hits();
154   Int_t nhits = RICHhits->GetEntriesFast();
155   if (fHitIndex < 0 || fHitIndex >= nhits) return 0;
156   return (AliRICHHit*)RICHhits->UncheckedAt(fHitIndex);
157 }
158
159 //_____________________________________________________________________________
160 AliRICHDigit *AliRICHPoints::GetDigit() const
161 {
162   //
163   //   Returns pointer to digit index in AliRun::fParticles
164   //
165
166   AliRICHDisplay *display=(AliRICHDisplay*)gAlice->Display();
167   Int_t chamber=display->GetChamber();
168   Int_t cathode=display->GetCathode();
169    
170   AliRICH *RICH  = (AliRICH*)gAlice->GetDetector("RICH");
171   TClonesArray *RICHdigits  = RICH->DigitsAddress(chamber-1);
172   gAlice->TreeD()->GetEvent(cathode);
173   Int_t ndigits = RICHdigits->GetEntriesFast();
174   if (fDigitIndex < 0 || fDigitIndex >= ndigits) return 0;
175   return (AliRICHDigit*)RICHdigits->UncheckedAt(fDigitIndex);
176 }
177 //----------------------------------------------------------------------------
178 void AliRICHPoints::ShowRing(Int_t highlight) {
179    
180   AliRICH *RICH  = (AliRICH*)gAlice->GetDetector("RICH");
181   AliRICHChamber*       iChamber;
182   AliRICHSegmentation*  segmentation;
183
184       
185   AliRICHPoints *points = 0;
186   TMarker3DBox  *marker = 0;
187     
188   AliRICHHit *mHit = GetHit();
189
190   printf("Hit %d on chamber: %d\n",fHitIndex, mHit->fChamber);
191
192   TClonesArray *digits  = RICH->DigitsAddress(mHit->fChamber - 1);
193   iChamber = &(RICH->Chamber(mHit->fChamber - 1));
194   segmentation=iChamber->GetSegmentationModel();
195
196   Float_t dpx  = segmentation->Dpx();
197   Float_t dpy  = segmentation->Dpy();
198
199   int ndigits=digits->GetEntriesFast();
200   
201   printf("Show Ring called with %d digits\n",ndigits);
202   
203   for (int digit=0;digit<ndigits;digit++) {
204     AliRICHDigit *mdig = (AliRICHDigit*)digits->UncheckedAt(digit);
205     points = new AliRICHPoints(1);
206     
207      //printf("Particle %d belongs to ring %d \n", fTrackIndex, mdig->fTracks[1]);
208
209     if (!points) continue;
210     if (fTrackIndex == mdig->fTracks[0]) {
211
212       printf("Digit %d from particle %d belongs to ring %d \n", digit, fTrackIndex, mdig->fTracks[0]);
213
214       Int_t charge=mdig->fSignal;
215       Int_t index=Int_t(TMath::Log(charge)/(TMath::Log(adc_satm)/22));
216       Int_t color=701+index;
217       if (color>722) color=722;
218       points->SetMarkerColor(color);
219       points->SetMarkerStyle(21);
220       points->SetMarkerSize(.5);
221       Float_t xpad, ypad;
222       segmentation->GetPadCxy(mdig->fPadX, mdig->fPadY,xpad, ypad);
223       Float_t VecLoc[3]={xpad,6.276,ypad};
224       Float_t  VecGlob[3];
225       points->SetParticle(-1);
226       points->SetHitIndex(-1);
227       points->SetTrackIndex(-1);
228       points->SetDigitIndex(digit);
229       iChamber->LocaltoGlobal(VecLoc,VecGlob);
230       points->SetPoint(0,VecGlob[0],VecGlob[1],VecGlob[2]);
231       
232       segmentation->GetPadCxy(mdig->fPadX, mdig->fPadY, xpad, ypad);
233       Float_t theta = iChamber->GetRotMatrix()->GetTheta();
234       Float_t phi   = iChamber->GetRotMatrix()->GetPhi();          
235       marker=new TMarker3DBox(VecGlob[0],VecGlob[1],VecGlob[2],
236                               dpy/2,0,dpx/2,theta,phi);
237       marker->SetLineColor(highlight);
238       marker->SetFillStyle(1001);
239       marker->SetFillColor(color);
240       marker->SetRefObject((TObject*)points);
241       points->Set3DMarker(0, marker);
242       
243       points->Draw("same");
244       for (Int_t im=0;im<3;im++) {
245         TMarker3DBox *marker=points->GetMarker(im);
246         if (marker)
247           marker->Draw();
248       }
249       TClonesArray *particles=gAlice->Particles();
250       TParticle *p = (TParticle*)particles->UncheckedAt(fIndex);
251       printf("\nTrack index %d\n",fTrackIndex);
252       printf("Particle ID %d\n",p->GetPdgCode());
253       printf("Parent %d\n",p->GetFirstMother());
254       printf("First child %d\n",p->GetFirstDaughter());
255       printf("Px,Py,Pz %f %f %f\n",p->Px(),p->Py(),p->Pz());
256     }
257   }
258 }
259 //_____________________________________________________________________________
260 struct Bin {
261    const AliRICHDigit *dig;
262    int idx;
263    Bin() {dig=0; idx=-1;}
264 };
265
266 struct PreCluster : public AliRICHRawCluster {
267    const AliRICHDigit* summit;
268    int idx;
269    int cut;
270    int npeaks;
271    PreCluster() : AliRICHRawCluster() {cut=npeaks=0;}
272 };
273 //_____________________________________________________________________________
274
275 static void FindCluster(AliRICHChamber *iChamber, AliRICHSegmentation *segmentation, int i, int j, Bin bins[MAX_Nipx][MAX_Nipy], PreCluster &c) 
276
277 {
278
279   //
280   // Find clusters
281   //
282
283   printf("I'm in FindCluster \n"); 
284
285   Bin& b=bins[i][j];
286   Int_t q=b.dig->fSignal;
287
288   printf("FindCluster - i j q %d %d %d\n",i,j,q);
289   
290   if (q<0) { 
291     q=-q;
292     c.cut=1;
293   } 
294   if (b.idx >= 0 && b.idx != c.idx) {
295     c.idx=b.idx;
296     c.npeaks++;
297   }
298   
299   if (q > TMath::Abs(c.summit->fSignal)) c.summit=b.dig;
300
301   Int_t npx  = segmentation->Npx();
302   Int_t npy  = segmentation->Npy();
303   Float_t x,y;
304   segmentation->GetPadCxy(i-npx, j-npy, x,y);
305   printf("FindCluster - x  y %f %f \n",x,y);
306
307
308   c.fX += q*x;
309   c.fY += q*y;
310   c.fQ += q;
311   
312   b.dig = 0;  b.idx = c.idx;
313   
314   if (bins[i-1][j].dig) FindCluster(iChamber,segmentation,i-1,j,bins,c);
315   if (bins[i][j-1].dig) FindCluster(iChamber,segmentation,i,j-1,bins,c);
316   if (bins[i+1][j].dig) FindCluster(iChamber,segmentation,i+1,j,bins,c);
317   if (bins[i][j+1].dig) FindCluster(iChamber,segmentation,i,j+1,bins,c);
318
319 }
320
321 //_____________________________________________________________________________
322
323 void AliRICHPoints::GetCenterOfGravity()
324 {
325   //
326   // simple RICH cluster finder from digits -- finds neighbours and 
327   // calculates center of gravity for the cluster
328   //
329   const Int_t MAX_nipx=400, MAX_nipy=800;
330   printf("\n Hallo world");
331   AliRICHDisplay *display=(AliRICHDisplay*)gAlice->Display();
332   Int_t chamber=display->GetChamber();
333   Int_t cathode=display->GetCathode();
334    
335   AliRICH *RICH  = (AliRICH*)gAlice->GetDetector("RICH");
336   AliRICHChamber *iChamber;
337   AliRICHSegmentation *segmentation;
338   iChamber =&(RICH->Chamber(chamber-1));
339   segmentation=iChamber->GetSegmentationModel(cathode);
340   Int_t npx  = segmentation->Npx();
341   Int_t npy  = segmentation->Npy();
342   Float_t zpos=iChamber->ZPosition();
343   
344   TClonesArray *RICHdigits  = RICH->DigitsAddress(chamber-1);
345   gAlice->TreeD()->GetEvent(cathode);
346   Int_t ndigits = RICHdigits->GetEntriesFast();
347   if (fDigitIndex < 0 || fDigitIndex >= ndigits) return;
348
349   AliRICHDigit  *dig;
350   dig=(AliRICHDigit*)RICHdigits->UncheckedAt(fDigitIndex);
351   Int_t ipx=dig->fPadX;
352   Int_t ipy=dig->fPadY;
353   Bin bins[MAX_nipx][MAX_nipy]; 
354   bins[ipx+npx][ipy+npy].dig=dig;
355     
356   int ndig;
357   int ncls=0;
358   for (ndig=0; ndig<ndigits; ndig++) {
359       dig = (AliRICHDigit*)RICHdigits->UncheckedAt(ndig);
360       int i=dig->fPadX, j=dig->fPadY;
361       bins[i+npx][j+npy].dig=dig;
362   }
363
364   PreCluster c; c.summit=bins[ipx+npx][ipy+npy].dig; c.idx=ncls;
365   FindCluster(iChamber,segmentation,ipx+npx, ipy+npy, bins, c);
366   if (c.npeaks>1) {
367       printf("GetCenterOfGravity -- more than one peak");
368   }
369   c.fX /= c.fQ;
370   c.fY /= c.fQ;
371   printf("GetCenterOfGravity - c.fX c.fY c.fQ %f %f %d \n",c.fX,c.fY,c.fQ);
372   
373   c.fTracks[0]=c.summit->fTracks[0];
374   c.fTracks[1]=c.summit->fTracks[1];
375   c.fTracks[2]=c.summit->fTracks[2];
376   ncls++;
377   AliRICHPoints *points = 0;
378   points = new AliRICHPoints(1);
379   points->SetMarkerColor(kYellow);
380   points->SetMarkerStyle(5);
381   points->SetMarkerSize(1.);
382   points->SetPoint(0,c.fX,c.fY,zpos);
383   points->Draw();
384   
385   printf("GetCenterOfGravity -- ncls %d \n",ncls);
386
387 }
388
389 //_____________________________________________________________________________
390 const Text_t *AliRICHPoints::GetName() const
391 {
392   //
393   // Return name of the Geant3 particle corresponding to this point
394   //
395   TParticle *particle = GetParticle();
396   if (!particle) return "Particle";
397   return particle->GetName();
398 }
399
400 //_____________________________________________________________________________
401 Text_t *AliRICHPoints::GetObjectInfo(Int_t, Int_t)
402 {
403   //
404   //   Redefines TObject::GetObjectInfo.
405   //   Displays the info (particle,etc
406   //   corresponding to cursor position px,py
407   //
408   static char info[64];
409   sprintf(info,"%s %d",GetName(),fIndex);
410   return info;
411 }
412
413
414