]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/AliPHOSRecPoint.cxx
Buffer Size can be defined
[u/mrichter/AliRoot.git] / PHOS / AliPHOSRecPoint.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 /* $Id$ */
16 //_________________________________________________________________________
17 //  Base Class for PHOS Reconstructed Points  
18 //  Why should I put meaningless comments
19 //  just to satisfy
20 //  the code checker                
21 //*-- Author: Gines Martinez (SUBATECH)
22
23 // --- ROOT system ---
24 #include "TPad.h"
25 #include "TClonesArray.h"
26
27 // --- Standard library ---
28 #include <iostream.h>
29 #include <stdio.h>
30
31 // --- AliRoot header files ---
32
33 #include "AliPHOSGeometry.h"
34 #include "AliPHOSDigit.h"
35 #include "AliPHOSRecPoint.h"
36 #include "AliPHOSGetter.h"
37
38 ClassImp(AliPHOSRecPoint)
39
40
41 //____________________________________________________________________________
42 AliPHOSRecPoint::AliPHOSRecPoint()
43   : AliRecPoint()
44 {
45   // ctor
46
47   fMaxTrack = 200 ;
48   fPHOSMod = 0;
49
50 }
51
52 //____________________________________________________________________________
53 AliPHOSRecPoint::AliPHOSRecPoint(const char * opt) : AliRecPoint(opt)
54 {
55   // ctor
56   
57   fMaxTrack = 200 ;
58   fPHOSMod = 0;
59   
60 }
61
62 //____________________________________________________________________________
63 Int_t AliPHOSRecPoint::DistancetoPrimitive(Int_t px, Int_t py)
64 {
65   // Compute distance from point px,py to  a AliPHOSRecPoint considered as a Tmarker
66   // Compute the closest distance of approach from point px,py to this marker.
67   // The distance is computed in pixels units.
68
69   TVector3 pos(0.,0.,0.) ;
70   GetLocalPosition( pos) ;
71   Float_t x =  pos.X() ;
72   Float_t y =  pos.Z() ;
73   const Int_t kMaxDiff = 10;
74   Int_t pxm  = gPad->XtoAbsPixel(x);
75   Int_t pym  = gPad->YtoAbsPixel(y);
76   Int_t dist = (px-pxm)*(px-pxm) + (py-pym)*(py-pym);
77   
78   if (dist > kMaxDiff) return 9999;
79   return dist;
80 }
81
82 //___________________________________________________________________________
83  void AliPHOSRecPoint::Draw(Option_t *option)
84  {
85    // Draw this AliPHOSRecPoint with its current attributes
86    
87    AppendPad(option);
88  }
89
90 //______________________________________________________________________________
91 void AliPHOSRecPoint::ExecuteEvent(Int_t event, Int_t px, Int_t py)
92 {
93   // Execute action corresponding to one event
94   // This member function is called when a AliPHOSRecPoint is clicked with the locator
95   //
96   // If Left button is clicked on AliPHOSRecPoint, the digits are switched on    
97   // and switched off when the mouse button is released.
98
99   //  static Int_t pxold, pyold;
100
101   static TGraph *  digitgraph = 0 ;
102   static TPaveText* clustertext = 0 ;
103   
104   if (!gPad->IsEditable()) return;
105   
106   switch (event) {
107     
108     
109   case kButton1Down:{
110     AliPHOSDigit * digit ;
111     AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ; 
112     AliPHOSGeometry * phosgeom =  const_cast<AliPHOSGeometry*>(gime->PHOSGeometry());
113
114     Int_t iDigit;
115     Int_t relid[4] ;
116   
117     const Int_t kMulDigit=AliPHOSRecPoint::GetDigitsMultiplicity() ;
118     Float_t * xi = new Float_t [kMulDigit] ; 
119     Float_t * zi = new Float_t [kMulDigit] ;
120     
121     for(iDigit = 0; iDigit < kMulDigit; iDigit++) {
122       Fatal("AliPHOSRecPoint::ExecuteEvent", "-> Something wrong with the code"); 
123       digit = 0 ; //dynamic_cast<AliPHOSDigit *>((fDigitsList)[iDigit]);
124       phosgeom->AbsToRelNumbering(digit->GetId(), relid) ;
125       phosgeom->RelPosInModule(relid, xi[iDigit], zi[iDigit]) ;
126     }
127     
128     if (!digitgraph) {
129       digitgraph = new TGraph(fMulDigit,xi,zi);
130       digitgraph-> SetMarkerStyle(5) ; 
131       digitgraph-> SetMarkerSize(1.) ;
132       digitgraph-> SetMarkerColor(1) ;
133       digitgraph-> Draw("P") ;
134     }
135     if (!clustertext) {
136       
137       TVector3 pos(0.,0.,0.) ;
138       GetLocalPosition(pos) ;
139       clustertext = new TPaveText(pos.X()-10,pos.Z()+10,pos.X()+50,pos.Z()+35,"") ;
140       Text_t  line1[40] ;
141       Text_t  line2[40] ;
142       sprintf(line1,"Energy=%1.2f GeV",GetEnergy()) ;
143       sprintf(line2,"%d Digits",GetDigitsMultiplicity()) ;
144       clustertext ->AddText(line1) ;
145       clustertext ->AddText(line2) ;
146       clustertext ->Draw("");
147     }
148     gPad->Update() ; 
149     Print() ;
150     delete[] xi ; 
151     delete[] zi ; 
152    }
153   
154 break;
155   
156   case kButton1Up:
157     if (digitgraph) {
158       delete digitgraph  ;
159       digitgraph = 0 ;
160     }
161     if (clustertext) {
162       delete clustertext ;
163       clustertext = 0 ;
164     }
165     
166     break;
167     
168   }
169 }
170 //____________________________________________________________________________
171 void AliPHOSRecPoint::EvalAll(Float_t logWeight,TClonesArray * digits) {
172   //evaluates (if necessary) all RecPoint data members 
173
174   EvalPrimaries(digits) ;
175 }
176 //____________________________________________________________________________
177 void AliPHOSRecPoint::EvalPHOSMod(AliPHOSDigit * digit) 
178 {
179   // Returns the PHOS module in which the RecPoint is found
180
181   if( fPHOSMod == 0){
182   Int_t relid[4] ; 
183   
184   AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ; 
185   AliPHOSGeometry * phosgeom =  const_cast<AliPHOSGeometry*>(gime->PHOSGeometry());
186
187   phosgeom->AbsToRelNumbering(digit->GetId(), relid) ;
188   fPHOSMod = relid[0];
189   }
190 }
191
192 //______________________________________________________________________________
193 void  AliPHOSRecPoint::EvalPrimaries(TClonesArray * digits)
194 {
195   // Constructs the list of primary particles (tracks) which have contributed to this RecPoint
196   
197   AliPHOSDigit * digit ;
198   Int_t * tempo    = new Int_t[fMaxTrack] ;
199
200   Int_t index ;  
201   for ( index = 0 ; index < GetDigitsMultiplicity() ; index++ ) { // all digits
202     digit = dynamic_cast<AliPHOSDigit *>(digits->At( fDigitsList[index] )) ; 
203     Int_t nprimaries = digit->GetNprimary() ;
204     Int_t * newprimaryarray = new Int_t[nprimaries] ;
205     Int_t ii ; 
206     for ( ii = 0 ; ii < nprimaries ; ii++)
207       newprimaryarray[ii] = digit->GetPrimary(ii+1) ; 
208
209     Int_t jndex ;
210     for ( jndex = 0 ; jndex < nprimaries ; jndex++ ) { // all primaries in digit
211       if ( fMulTrack > fMaxTrack ) {
212         fMulTrack = - 1 ;
213         cout << "AliPHOSRecPoint::GetNprimaries ERROR > increase fMaxTrack " << endl ;
214         break ;
215       }
216       Int_t newprimary = newprimaryarray[jndex] ;
217       Int_t kndex ;
218       Bool_t already = kFALSE ;
219       for ( kndex = 0 ; kndex < fMulTrack ; kndex++ ) { //check if not already stored
220         if ( newprimary == tempo[kndex] ){
221           already = kTRUE ;
222           break ;
223         }
224       } // end of check
225       if ( !already) { // store it
226         tempo[fMulTrack] = newprimary ; 
227         fMulTrack++ ;
228       } // store it
229     } // all primaries in digit
230     delete newprimaryarray ; 
231   } // all digits
232
233   
234   fTracksList = new Int_t[fMulTrack] ;
235   for(index = 0; index < fMulTrack; index++)
236    fTracksList[index] = tempo[index] ;
237  
238   delete tempo ;
239
240 }
241 //____________________________________________________________________________
242 void AliPHOSRecPoint::GetGlobalPosition(TVector3 & gpos, TMatrix & gmat) const
243 {
244   // returns the position of the cluster in the global reference system of ALICE
245   // and the uncertainty on this position
246   
247   
248   AliPHOSGetter::GetInstance()->PHOSGeometry()->GetGlobal(this, gpos, gmat) ;
249  
250 }
251
252
253 //______________________________________________________________________________
254 void AliPHOSRecPoint::Paint(Option_t *)
255 {
256   // Paint this ALiRecPoint as a TMarker  with its current attributes
257   
258   TVector3 pos(0.,0.,0.)  ;
259   GetLocalPosition(pos)   ;
260   Coord_t x = pos.X()     ;
261   Coord_t y = pos.Z()     ;
262   Color_t markercolor = 1 ;
263   Size_t  markersize = 1. ;
264   Style_t markerstyle = 5 ;
265   
266   if (!gPad->IsBatch()) {
267     gVirtualX->SetMarkerColor(markercolor) ;
268     gVirtualX->SetMarkerSize (markersize)  ;
269     gVirtualX->SetMarkerStyle(markerstyle) ;
270   }
271   gPad->SetAttMarkerPS(markercolor,markerstyle,markersize) ;
272   gPad->PaintPolyMarker(1,&x,&y,"") ;
273 }