Macro for local analysis.
[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()
9ee9f78d 43 : AliCluster(),fPHOSMod(0),
44 fMulTrack(0),fMaxDigit(100),fMulDigit(0),fMaxTrack(0),
45 fDigitsList(0),fTracksList(0),fAmp(0),
46 fIndexInList(-1), // to be set when the point is already stored
47 fLocPos(0,0,0),fLocPosM(0)
d15a28e7 48{
b2a60966 49 // ctor
50
d15a28e7 51}
52
53//____________________________________________________________________________
9ee9f78d 54AliPHOSRecPoint::AliPHOSRecPoint(const char * )
55 : AliCluster(),fPHOSMod(0),
56 fMulTrack(0),fMaxDigit(100),fMulDigit(0),fMaxTrack(200),
57 fDigitsList(new int[fMaxDigit]),fTracksList(new int[fMaxTrack]),fAmp(0),
58 fIndexInList(-1), // to be set when the point is already stored
59 fLocPos(0,0,0),fLocPosM(new TMatrixF(3,3))
60
73a68ccb 61{
62 // ctor
63
55fe9d13 64}
9ee9f78d 65//_______________________________________________________________________
66AliPHOSRecPoint::~AliPHOSRecPoint()
67{
68 // dtor
69
70 delete fLocPosM ;
71 delete [] fDigitsList ;
72 delete [] fTracksList ;
73
74}
75//____________________________________________________________________________
76AliPHOSRecPoint::AliPHOSRecPoint(const AliPHOSRecPoint &rp) :
77 AliCluster(rp),
78 fPHOSMod(rp.fPHOSMod),fMulTrack(rp.fMulTrack),fMaxDigit(rp.fMaxDigit),
79 fMulDigit(rp.fMulDigit),fMaxTrack(rp.fMaxTrack),fDigitsList(new int[rp.fMaxDigit]),
80 fTracksList(new int[rp.fMaxTrack]),fAmp(rp.fAmp),fIndexInList(rp.fIndexInList),
81 fLocPos(rp.fLocPos),fLocPosM(rp.fLocPosM)
82{
83 //copy ctor
55fe9d13 84
9ee9f78d 85 for(Int_t i=0; i<fMaxDigit; i++)
86 fDigitsList[i] = rp.fDigitsList[i];
87
88 for(Int_t i=0; i<fMaxTrack; i++)
89 fTracksList[i] = rp.fTracksList[i];
90
91}
92//____________________________________________________________________________
93AliPHOSRecPoint& AliPHOSRecPoint::operator= (const AliPHOSRecPoint &rp)
94{
95 if(&rp == this) return *this;
96
97 fPHOSMod = rp.fPHOSMod;
98 fMulTrack = rp.fMulTrack;
99 fMaxDigit = rp.fMaxDigit;
100 fMulDigit = rp.fMulDigit;
101 fMaxTrack = rp.fMaxTrack;
102 fAmp = rp.fAmp;
103 fIndexInList = rp.fIndexInList;
104 fLocPos = rp.fLocPos;
105 fLocPosM = rp.fLocPosM;
106
107 for(Int_t i=0; i<fMaxDigit; i++)
108 fDigitsList[i] = rp.fDigitsList[i];
109
110 for(Int_t i=0; i<fMaxTrack; i++)
111 fTracksList[i] = rp.fTracksList[i];
112
113 return *this;
114}
55fe9d13 115//____________________________________________________________________________
9f616d61 116Int_t AliPHOSRecPoint::DistancetoPrimitive(Int_t px, Int_t py)
117{
b2a60966 118 // Compute distance from point px,py to a AliPHOSRecPoint considered as a Tmarker
119 // Compute the closest distance of approach from point px,py to this marker.
120 // The distance is computed in pixels units.
121
122 TVector3 pos(0.,0.,0.) ;
123 GetLocalPosition( pos) ;
124 Float_t x = pos.X() ;
125 Float_t y = pos.Z() ;
126 const Int_t kMaxDiff = 10;
127 Int_t pxm = gPad->XtoAbsPixel(x);
128 Int_t pym = gPad->YtoAbsPixel(y);
129 Int_t dist = (px-pxm)*(px-pxm) + (py-pym)*(py-pym);
130
131 if (dist > kMaxDiff) return 9999;
132 return dist;
9f616d61 133}
6ad0bfa0 134
9f616d61 135//___________________________________________________________________________
136 void AliPHOSRecPoint::Draw(Option_t *option)
137 {
6ad0bfa0 138 // Draw this AliPHOSRecPoint with its current attributes
139
140 AppendPad(option);
9f616d61 141 }
142
143//______________________________________________________________________________
8f2a3661 144void AliPHOSRecPoint::ExecuteEvent(Int_t event, Int_t, Int_t)
9f616d61 145{
6ad0bfa0 146 // Execute action corresponding to one event
147 // This member function is called when a AliPHOSRecPoint is clicked with the locator
148 //
149 // If Left button is clicked on AliPHOSRecPoint, the digits are switched on
150 // and switched off when the mouse button is released.
9f616d61 151
152 // static Int_t pxold, pyold;
153
b2a60966 154 static TGraph * digitgraph = 0 ;
155 static TPaveText* clustertext = 0 ;
156
157 if (!gPad->IsEditable()) return;
9f616d61 158
b2a60966 159 switch (event) {
160
161
162 case kButton1Down:{
163 AliPHOSDigit * digit ;
88cb7938 164
165// Accessing geometry this way is equivalent to getting from gAlice
166// to have Detector in Folder one have to load gAlice anyway
167// AliPHOSLoader * gime = AliPHOSLoader::GetInstance();
168// AliPHOSGeometry * phosgeom = const_cast<AliPHOSGeometry*>(gime->PHOSGeometry());
169
170 AliPHOSGeometry * phosgeom = AliPHOSLoader::GetPHOSGeometry();
7b7c1533 171
b2a60966 172 Int_t iDigit;
173 Int_t relid[4] ;
31aa6d6c 174
88714635 175 const Int_t kMulDigit=AliPHOSRecPoint::GetDigitsMultiplicity() ;
176 Float_t * xi = new Float_t [kMulDigit] ;
177 Float_t * zi = new Float_t [kMulDigit] ;
b2a60966 178
88714635 179 for(iDigit = 0; iDigit < kMulDigit; iDigit++) {
4696e514 180 Fatal("AliPHOSRecPoint::ExecuteEvent", "-> Something wrong with the code");
7a9d98f9 181 digit = 0 ; //dynamic_cast<AliPHOSDigit *>((fDigitsList)[iDigit]);
b2a60966 182 phosgeom->AbsToRelNumbering(digit->GetId(), relid) ;
183 phosgeom->RelPosInModule(relid, xi[iDigit], zi[iDigit]) ;
184 }
185
186 if (!digitgraph) {
187 digitgraph = new TGraph(fMulDigit,xi,zi);
188 digitgraph-> SetMarkerStyle(5) ;
189 digitgraph-> SetMarkerSize(1.) ;
190 digitgraph-> SetMarkerColor(1) ;
191 digitgraph-> Draw("P") ;
192 }
193 if (!clustertext) {
194
195 TVector3 pos(0.,0.,0.) ;
196 GetLocalPosition(pos) ;
197 clustertext = new TPaveText(pos.X()-10,pos.Z()+10,pos.X()+50,pos.Z()+35,"") ;
198 Text_t line1[40] ;
199 Text_t line2[40] ;
200 sprintf(line1,"Energy=%1.2f GeV",GetEnergy()) ;
201 sprintf(line2,"%d Digits",GetDigitsMultiplicity()) ;
202 clustertext ->AddText(line1) ;
203 clustertext ->AddText(line2) ;
204 clustertext ->Draw("");
205 }
206 gPad->Update() ;
a8c47ab6 207 Print("dummy") ;
31aa6d6c 208 delete[] xi ;
209 delete[] zi ;
210 }
b2a60966 211
31aa6d6c 212break;
b2a60966 213
214 case kButton1Up:
215 if (digitgraph) {
216 delete digitgraph ;
217 digitgraph = 0 ;
218 }
219 if (clustertext) {
220 delete clustertext ;
221 clustertext = 0 ;
222 }
223
224 break;
225
9f616d61 226 }
9f616d61 227}
ad8cfaf4 228//____________________________________________________________________________
e957fea8 229void AliPHOSRecPoint::EvalAll(TClonesArray * digits)
88cb7938 230{
ad8cfaf4 231 //evaluates (if necessary) all RecPoint data members
9f616d61 232
2731cd1e 233 EvalPrimaries(digits) ;
ad8cfaf4 234}
88cb7938 235
d15a28e7 236//____________________________________________________________________________
2731cd1e 237void AliPHOSRecPoint::EvalPHOSMod(AliPHOSDigit * digit)
b2a60966 238{
239 // Returns the PHOS module in which the RecPoint is found
83974468 240
2731cd1e 241 if( fPHOSMod == 0){
ad8cfaf4 242 Int_t relid[4] ;
88cb7938 243
244 AliPHOSGeometry * phosgeom = (AliPHOSGetter::Instance())->PHOSGeometry();
d15a28e7 245
92862013 246 phosgeom->AbsToRelNumbering(digit->GetId(), relid) ;
d15a28e7 247 fPHOSMod = relid[0];
2731cd1e 248 }
d15a28e7 249}
6ad0bfa0 250
9f616d61 251//______________________________________________________________________________
2731cd1e 252void AliPHOSRecPoint::EvalPrimaries(TClonesArray * digits)
cf239357 253{
2731cd1e 254 // Constructs the list of primary particles (tracks) which have contributed to this RecPoint
b2a60966 255
cf239357 256 AliPHOSDigit * digit ;
2731cd1e 257 Int_t * tempo = new Int_t[fMaxTrack] ;
258
259 Int_t index ;
cf239357 260 for ( index = 0 ; index < GetDigitsMultiplicity() ; index++ ) { // all digits
7a9d98f9 261 digit = dynamic_cast<AliPHOSDigit *>(digits->At( fDigitsList[index] )) ;
88cb7938 262 Int_t nprimaries = digit->GetNprimary() ;
263 if(nprimaries){
264 Int_t * newprimaryarray = new Int_t[nprimaries] ;
265 Int_t ii ;
266 for ( ii = 0 ; ii < nprimaries ; ii++)
267 newprimaryarray[ii] = digit->GetPrimary(ii+1) ;
268
269 Int_t jndex ;
270 for ( jndex = 0 ; jndex < nprimaries ; jndex++ ) { // all primaries in digit
271 if ( fMulTrack > fMaxTrack ) {
272 fMulTrack = - 1 ;
273 Error("EvalPrimaries", "GetNprimaries ERROR > increase fMaxTrack" ) ;
274 break ;
275 }
276 Int_t newprimary = newprimaryarray[jndex] ;
277 Int_t kndex ;
278 Bool_t already = kFALSE ;
279 for ( kndex = 0 ; kndex < fMulTrack ; kndex++ ) { //check if not already stored
280 if ( newprimary == tempo[kndex] ){
281 already = kTRUE ;
884e9693 282 break ;
283 }
88cb7938 284 } // end of check
285 if ( !already) { // store it
286 tempo[fMulTrack] = newprimary ;
287 fMulTrack++ ;
288 } // store it
289 } // all primaries in digit
290 delete [] newprimaryarray ;
884e9693 291 }
cf239357 292 } // all digits
293
884e9693 294 if(fMulTrack)
295 fTracksList = new Int_t[fMulTrack] ;
2731cd1e 296 for(index = 0; index < fMulTrack; index++)
884e9693 297 fTracksList[index] = tempo[index] ;
298
780a31c1 299 delete [] tempo ;
884e9693 300
cf239357 301}
4b45b217 302//____________________________________________________________________________
e8d02863 303void AliPHOSRecPoint::GetGlobalPosition(TVector3 & gpos, TMatrixF & gmat) const
4b45b217 304{
305 // returns the position of the cluster in the global reference system of ALICE
306 // and the uncertainty on this position
9ee9f78d 307
308 (AliPHOSGetter::Instance())->PHOSGeometry()->GetGlobalPHOS(this, gpos, gmat);
309
310// Float_t xyz[3];
311// GetGlobalXYZ(xyz);
312// gpos.SetXYZ(xyz[0],xyz[1],xyz[2]);
313
314
4b45b217 315}
316
cf239357 317
318//______________________________________________________________________________
9f616d61 319void AliPHOSRecPoint::Paint(Option_t *)
320{
b2a60966 321 // Paint this ALiRecPoint as a TMarker with its current attributes
322
323 TVector3 pos(0.,0.,0.) ;
324 GetLocalPosition(pos) ;
325 Coord_t x = pos.X() ;
326 Coord_t y = pos.Z() ;
327 Color_t markercolor = 1 ;
328 Size_t markersize = 1. ;
329 Style_t markerstyle = 5 ;
330
331 if (!gPad->IsBatch()) {
332 gVirtualX->SetMarkerColor(markercolor) ;
333 gVirtualX->SetMarkerSize (markersize) ;
334 gVirtualX->SetMarkerStyle(markerstyle) ;
335 }
336 gPad->SetAttMarkerPS(markercolor,markerstyle,markersize) ;
337 gPad->PaintPolyMarker(1,&x,&y,"") ;
9f616d61 338}
88cb7938 339//______________________________________________________________________________
9ee9f78d 340void AliPHOSRecPoint::GetLocalPosition(TVector3 & pos) const
341{
342 // returns the position of the cluster in the local reference system
343 // of the sub-detector
344
345 pos = fLocPos;
346}