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