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