Updated denames of station 1 for the quadrants as they have been mounted in cave
[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 **************************************************************************/
b2a60966 15/* $Id$ */
d15a28e7 16//_________________________________________________________________________
b2a60966 17// Base Class for PHOS Reconstructed Points
2f04ed65 18// Why should I put meaningless comments
19// just to satisfy
20// the code checker
b2a60966 21//*-- Author: Gines Martinez (SUBATECH)
d15a28e7 22
23// --- ROOT system ---
9f616d61 24#include "TPad.h"
e957fea8 25#include "TGraph.h"
26#include "TPaveText.h"
2731cd1e 27#include "TClonesArray.h"
d15a28e7 28
29// --- Standard library ---
30
31// --- AliRoot header files ---
32
33#include "AliPHOSGeometry.h"
34#include "AliPHOSDigit.h"
35#include "AliPHOSRecPoint.h"
7b7c1533 36#include "AliPHOSGetter.h"
9f616d61 37
d15a28e7 38ClassImp(AliPHOSRecPoint)
39
40
41//____________________________________________________________________________
42AliPHOSRecPoint::AliPHOSRecPoint()
3663622c 43 : AliRecPoint(),
44 fPHOSMod(0)
d15a28e7 45{
b2a60966 46 // ctor
47
88cb7938 48 fMaxTrack = 0 ;
d15a28e7 49}
50
51//____________________________________________________________________________
3663622c 52AliPHOSRecPoint::AliPHOSRecPoint(const char * opt)
53 : AliRecPoint(opt),
54 fPHOSMod(0)
73a68ccb 55{
56 // ctor
57
58 fMaxTrack = 200 ;
55fe9d13 59}
60
61//____________________________________________________________________________
9f616d61 62Int_t AliPHOSRecPoint::DistancetoPrimitive(Int_t px, Int_t py)
63{
b2a60966 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;
9f616d61 79}
6ad0bfa0 80
9f616d61 81//___________________________________________________________________________
82 void AliPHOSRecPoint::Draw(Option_t *option)
83 {
6ad0bfa0 84 // Draw this AliPHOSRecPoint with its current attributes
85
86 AppendPad(option);
9f616d61 87 }
88
89//______________________________________________________________________________
8f2a3661 90void AliPHOSRecPoint::ExecuteEvent(Int_t event, Int_t, Int_t)
9f616d61 91{
6ad0bfa0 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.
9f616d61 97
98 // static Int_t pxold, pyold;
99
b2a60966 100 static TGraph * digitgraph = 0 ;
101 static TPaveText* clustertext = 0 ;
102
103 if (!gPad->IsEditable()) return;
9f616d61 104
b2a60966 105 switch (event) {
106
107
108 case kButton1Down:{
109 AliPHOSDigit * digit ;
88cb7938 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();
7b7c1533 117
b2a60966 118 Int_t iDigit;
119 Int_t relid[4] ;
31aa6d6c 120
88714635 121 const Int_t kMulDigit=AliPHOSRecPoint::GetDigitsMultiplicity() ;
122 Float_t * xi = new Float_t [kMulDigit] ;
123 Float_t * zi = new Float_t [kMulDigit] ;
b2a60966 124
88714635 125 for(iDigit = 0; iDigit < kMulDigit; iDigit++) {
4696e514 126 Fatal("AliPHOSRecPoint::ExecuteEvent", "-> Something wrong with the code");
7a9d98f9 127 digit = 0 ; //dynamic_cast<AliPHOSDigit *>((fDigitsList)[iDigit]);
b2a60966 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() ;
a8c47ab6 153 Print("dummy") ;
31aa6d6c 154 delete[] xi ;
155 delete[] zi ;
156 }
b2a60966 157
31aa6d6c 158break;
b2a60966 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
9f616d61 172 }
9f616d61 173}
ad8cfaf4 174//____________________________________________________________________________
e957fea8 175void AliPHOSRecPoint::EvalAll(TClonesArray * digits)
88cb7938 176{
ad8cfaf4 177 //evaluates (if necessary) all RecPoint data members
9f616d61 178
2731cd1e 179 EvalPrimaries(digits) ;
ad8cfaf4 180}
88cb7938 181
d15a28e7 182//____________________________________________________________________________
2731cd1e 183void AliPHOSRecPoint::EvalPHOSMod(AliPHOSDigit * digit)
b2a60966 184{
185 // Returns the PHOS module in which the RecPoint is found
83974468 186
2731cd1e 187 if( fPHOSMod == 0){
ad8cfaf4 188 Int_t relid[4] ;
88cb7938 189
190 AliPHOSGeometry * phosgeom = (AliPHOSGetter::Instance())->PHOSGeometry();
d15a28e7 191
92862013 192 phosgeom->AbsToRelNumbering(digit->GetId(), relid) ;
d15a28e7 193 fPHOSMod = relid[0];
2731cd1e 194 }
d15a28e7 195}
6ad0bfa0 196
9f616d61 197//______________________________________________________________________________
2731cd1e 198void AliPHOSRecPoint::EvalPrimaries(TClonesArray * digits)
cf239357 199{
2731cd1e 200 // Constructs the list of primary particles (tracks) which have contributed to this RecPoint
b2a60966 201
cf239357 202 AliPHOSDigit * digit ;
2731cd1e 203 Int_t * tempo = new Int_t[fMaxTrack] ;
204
205 Int_t index ;
cf239357 206 for ( index = 0 ; index < GetDigitsMultiplicity() ; index++ ) { // all digits
7a9d98f9 207 digit = dynamic_cast<AliPHOSDigit *>(digits->At( fDigitsList[index] )) ;
88cb7938 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 ;
884e9693 228 break ;
229 }
88cb7938 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 ;
884e9693 237 }
cf239357 238 } // all digits
239
884e9693 240 if(fMulTrack)
241 fTracksList = new Int_t[fMulTrack] ;
2731cd1e 242 for(index = 0; index < fMulTrack; index++)
884e9693 243 fTracksList[index] = tempo[index] ;
244
780a31c1 245 delete [] tempo ;
884e9693 246
cf239357 247}
4b45b217 248//____________________________________________________________________________
e8d02863 249void AliPHOSRecPoint::GetGlobalPosition(TVector3 & gpos, TMatrixF & gmat) const
4b45b217 250{
251 // returns the position of the cluster in the global reference system of ALICE
252 // and the uncertainty on this position
88cb7938 253 (AliPHOSGetter::Instance())->PHOSGeometry()->GetGlobal(this, gpos, gmat);
4b45b217 254}
255
cf239357 256
257//______________________________________________________________________________
9f616d61 258void AliPHOSRecPoint::Paint(Option_t *)
259{
b2a60966 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,"") ;
9f616d61 277}
88cb7938 278//______________________________________________________________________________
279