Check of bounds of RP arrays is added
[u/mrichter/AliRoot.git] / PHOS / AliPHOSTrackSegment.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// Track segment in PHOS
20// Can be : 1 EmcRecPoint
21// 1 EmcRecPoint + 1 PPSD
22// 1 EmcRecPoint + 1 PPSD + 1 PPSD
23//
24//*-- Author: Dmitri Peressounko (RRC KI & SUBATECH)
d15a28e7 25
26// --- ROOT system ---
27
28#include "TVector3.h"
9f616d61 29#include "TPad.h"
d15a28e7 30
31// --- Standard library ---
32
de9ec31b 33#include <iostream.h>
d15a28e7 34
35// --- AliRoot header files ---
36
37#include "AliPHOSTrackSegment.h"
38#include "AliPHOSv0.h"
83974468 39#include "AliPHOSIndexToObject.h"
d15a28e7 40
41ClassImp(AliPHOSTrackSegment)
42
43//____________________________________________________________________________
88714635 44AliPHOSTrackSegment::AliPHOSTrackSegment( AliPHOSEmcRecPoint * emc ,
45 AliPHOSPpsdRecPoint * ppsdrp1,
46 AliPHOSPpsdRecPoint * ppsdrp2 )
b2a60966 47{
48 // ctor
49
d15a28e7 50 if( emc )
83974468 51 fEmcRecPoint = emc->GetIndexInList() ;
52 else
53 fEmcRecPoint = -1 ;
d15a28e7 54
83974468 55 if( ppsdrp1 )
56 fPpsdUpRecPoint = ppsdrp1->GetIndexInList() ;
57 else
58 fPpsdUpRecPoint = -1 ;
d15a28e7 59
83974468 60 if( ppsdrp2 )
61 fPpsdLowRecPoint = ppsdrp2->GetIndexInList() ;
62 else
63 fPpsdLowRecPoint = -1 ;
d15a28e7 64
83974468 65 fIndexInList = -1 ;
d15a28e7 66}
67
68//____________________________________________________________________________
6ad0bfa0 69AliPHOSTrackSegment::AliPHOSTrackSegment( const AliPHOSTrackSegment & ts)
70{
b2a60966 71 // Copy ctor
72
c198e326 73 ( (AliPHOSTrackSegment &)ts ).Copy(*this) ;
6ad0bfa0 74}
75
d15a28e7 76
77//____________________________________________________________________________
6ad0bfa0 78void AliPHOSTrackSegment::Copy(TObject & obj)
79{
b2a60966 80 // Copy of a track segment into another track segment
81
6ad0bfa0 82 TObject::Copy(obj) ;
83974468 83 ( (AliPHOSTrackSegment &)obj ).fEmcRecPoint = fEmcRecPoint ;
84 ( (AliPHOSTrackSegment &)obj ).fPpsdLowRecPoint = fPpsdLowRecPoint ;
85 ( (AliPHOSTrackSegment &)obj ).fPpsdUpRecPoint = fPpsdUpRecPoint ;
86 ( (AliPHOSTrackSegment &)obj ).fIndexInList = fIndexInList ;
6ad0bfa0 87}
88//____________________________________________________________________________
9f616d61 89Int_t AliPHOSTrackSegment::DistancetoPrimitive(Int_t px, Int_t py)
90{
b2a60966 91 // Compute distance from point px,py to a AliPHOSTrackSegment considered as a Tmarker
92 // Compute the closest distance of approach from point px,py to this marker.
93 // The distance is computed in pixels units.
94
6ad0bfa0 95 Int_t div = 1 ;
83974468 96 Int_t dist = 9999 ;
97
6ad0bfa0 98 TVector3 pos(0.,0.,0.) ;
b2a60966 99
83974468 100 AliPHOSEmcRecPoint * emcrp = GetEmcRecPoint() ;
101 AliPHOSPpsdRecPoint * ppsdlrp = GetPpsdLowRecPoint() ;
102 AliPHOSPpsdRecPoint * ppsdurp = GetPpsdUpRecPoint() ;
103
104 if ( emcrp != 0 ) {
105 emcrp->GetLocalPosition( pos) ;
106 Float_t x = pos.X() ;
107 Float_t y = pos.Z() ;
108 if ( ppsdlrp != 0 ) {
109 ppsdlrp->GetLocalPosition( pos ) ;
110 x += pos.X() ;
111 y += pos.Z() ;
112 div++ ;
113 }
114 if ( ppsdurp != 0 ) {
115 ppsdurp->GetLocalPosition( pos ) ;
116 x += pos.X() ;
117 y += pos.Z() ;
118 div++ ;
119 }
120 x /= div ;
121 y /= div ;
9f616d61 122
83974468 123 const Int_t kMaxDiff = 10;
124 Int_t pxm = gPad->XtoAbsPixel(x);
125 Int_t pym = gPad->YtoAbsPixel(y);
126 dist = (px-pxm)*(px-pxm) + (py-pym)*(py-pym);
127
128 if (dist > kMaxDiff) return 9999;
129 }
130 return dist;
9f616d61 131}
132
133//___________________________________________________________________________
134 void AliPHOSTrackSegment::Draw(Option_t *option)
135 {
6ad0bfa0 136 // Draw this AliPHOSTrackSegment with its current attribute
b2a60966 137
6ad0bfa0 138 AppendPad(option);
9f616d61 139 }
140
141//______________________________________________________________________________
142void AliPHOSTrackSegment::ExecuteEvent(Int_t event, Int_t px, Int_t py)
143{
6ad0bfa0 144 // Execute action corresponding to one event
145 // This member function is called when a AliPHOSTrackSegment is clicked with the locator
146 //
147 // If Left button is clicked on AliPHOSRecPoint, the digits are switched on
148 // and switched off when the mouse button is released.
b2a60966 149
150 static TPaveText* textTS = 0 ;
151
83974468 152 AliPHOSEmcRecPoint * emcrp = GetEmcRecPoint() ;
153
b2a60966 154 if (!gPad->IsEditable())
155 return;
156
157 switch (event) {
9f616d61 158
b2a60966 159 case kButton1Down:{
160
161 if (!textTS) {
162
163 TVector3 pos(0.,0.,0.) ;
83974468 164 emcrp->GetLocalPosition(pos) ;
b2a60966 165 textTS = new TPaveText(pos.X()-10,pos.Z()+10,pos.X()+5,pos.Z()+15,"") ;
166 Text_t line1[40] ;
167 sprintf(line1,"See RecParticle for ID") ;
168 textTS ->AddText(line1) ;
169 textTS ->Draw("");
170 gPad->Update() ;
171 }
172 }
173
174 break;
9f616d61 175
b2a60966 176 case kButton1Up:
177 if (textTS) {
178 delete textTS ;
179 textTS = 0 ;
180 }
181 break;
182 }
9f616d61 183}
184
9f616d61 185//____________________________________________________________________________
d15a28e7 186Float_t AliPHOSTrackSegment::GetDistanceInPHOSPlane()
187{
b2a60966 188 // Calculates the distance between the EMC RecPoint and PPSD RecPoint
189
83974468 190 AliPHOSEmcRecPoint * emcrp = GetEmcRecPoint() ;
191 AliPHOSPpsdRecPoint * ppsdlrp = GetPpsdLowRecPoint() ;
192
d15a28e7 193 TVector3 vecEmc ;
83974468 194 emcrp->GetLocalPosition(vecEmc) ;
b2a60966 195
d15a28e7 196 TVector3 vecPpsd ;
83974468 197 if ( ppsdlrp !=0 ) {
198 if( ppsdlrp->GetMultiplicity() )
199 ppsdlrp->GetLocalPosition(vecPpsd) ;
200 else {
201 vecPpsd.SetX(10000.) ;
202 }
203 vecEmc -= vecPpsd ;
204 }
92862013 205 Float_t r = vecEmc.Mag();;
d15a28e7 206
92862013 207 return r ;
d15a28e7 208}
209
210//____________________________________________________________________________
83974468 211AliPHOSEmcRecPoint * AliPHOSTrackSegment::GetEmcRecPoint() const
212{
88714635 213 // get the EMC recpoint at the origin of this track
214
83974468 215 AliPHOSIndexToObject * please = AliPHOSIndexToObject::GetInstance() ;
216 AliPHOSEmcRecPoint * rv = 0 ;
217 if ( fEmcRecPoint > -1 )
218 rv = (AliPHOSEmcRecPoint *)please->GimeRecPoint( fEmcRecPoint, TString("emc") );
219
220 return rv ;
221
222}
223
224//____________________________________________________________________________
225 Float_t AliPHOSTrackSegment::GetEnergy()
226{
227 // Returns energy in EMC
228
229 AliPHOSEmcRecPoint * emcrp = GetEmcRecPoint() ;
230
231 return emcrp->GetTotalEnergy() ;
232}
233
234//____________________________________________________________________________
6ad0bfa0 235TVector3 AliPHOSTrackSegment::GetMomentumDirection()
b2a60966 236{
237 // Calculates the momentum direction:
238 // 1. if only a EMC RecPoint, direction is given by IP and this RecPoint
239 // 2. if a EMC RecPoint and one PPSD RecPoint, direction is given by the line through the 2 recpoints
240 // 3. if a EMC RecPoint and two PPSD RecPoints, dirrection is given by the average line through
241 // the 2 pairs of recpoints
242 // However because of the poor position resolution of PPSD the direction is always taken as if we were
243 // in case 1.
244
83974468 245
246 AliPHOSEmcRecPoint * emcrp = GetEmcRecPoint() ;
247 // AliPHOSPpsdRecPoint * ppsdlrp = GetPpsdLowRecPoint() ;
248 // AliPHOSPpsdRecPoint * ppsdurp = GetPpsdUpRecPoint() ;
249
b2a60966 250 TVector3 dir(0,0,0) ;
6ad0bfa0 251 TMatrix mdummy ;
d15a28e7 252
6ad0bfa0 253 TVector3 posEmc ;
83974468 254 emcrp->GetGlobalPosition(posEmc, mdummy) ;
6ad0bfa0 255
b2a60966 256 // Correction for the depth of the shower starting point (TDR p 127)
98569bc2 257
83974468 258 Float_t energy = emcrp->GetEnergy() ;
98569bc2 259 Float_t para = 0.925 ;
260 Float_t parb = 6.52 ;
261
262 TVector3 localpos ;
83974468 263 emcrp->GetLocalPosition(localpos) ;
98569bc2 264
265 AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance() ;
266 Float_t radius = geom->GetIPtoOuterCoverDistance() + geom->GetOuterBoxSize(1) ;
267 Float_t incidencephi = TMath::ATan(localpos.X() / radius) ;
268 Float_t incidencetheta = TMath::ATan(localpos.Z() / radius) ;
269
b2a60966 270 Float_t depthx = ( para * TMath::Log(energy) + parb ) * TMath::Sin(incidencephi) ;
271 Float_t depthz = ( para * TMath::Log(energy) + parb ) * TMath::Sin(incidencetheta) ;
98569bc2 272
b2a60966 273 localpos.SetX(localpos.X() - depthx ) ;
274 localpos.SetZ(localpos.Z() - depthz ) ;
d15a28e7 275
b2a60966 276 TVector3 emcglobalpos ;
277 TMatrix dummy ;
6ad0bfa0 278
83974468 279 emcrp->GetGlobalPosition(emcglobalpos, dummy) ;
b2a60966 280
281 emcglobalpos.SetX( emcglobalpos.X() - depthx ) ;
282 emcglobalpos.SetZ( emcglobalpos.Z() - depthz ) ;
6ad0bfa0 283
b2a60966 284 // The following commeneted code becomes valid once the PPSD provides
285 // a reasonable position resolution, at least as good as EMC !
286
287// TVector3 ppsdlglobalpos ;
288// TVector3 ppsduglobalpos ;
289
83974468 290// if( fPpsdLowRecPoint ){ // certainly a photon that has concerted
b2a60966 291
83974468 292// fPpsdLowRecPoint->GetGlobalPosition(ppsdlglobalpos, mdummy) ;
b2a60966 293// dir = emcglobalpos - ppsdlglobalpos ;
294
83974468 295// if( fPpsdUpRecPoint ){ // nop looks like a charged
b2a60966 296
83974468 297// fPpsdUpRecPoint->GetGlobalPosition(ppsduglobalpos, mdummy) ;
b2a60966 298// dir = ( dir + emcglobalpos - ppsduglobalpos ) * 0.5 ;
299// }
300// }
301
302// else { // looks like a neutral
303
304 dir = emcglobalpos ;
305// }
306
307 dir.SetZ( -dir.Z() ) ; // why ?
6ad0bfa0 308 dir.SetMag(1.) ;
b2a60966 309
6ad0bfa0 310 return dir ;
d15a28e7 311}
312
b2a60966 313//____________________________________________________________________________
83974468 314Int_t AliPHOSTrackSegment:: GetPHOSMod(void)
315{
88714635 316 // Returns the phos module which contains this track
317
83974468 318 AliPHOSEmcRecPoint * emcrp = GetEmcRecPoint() ;
319
320 return emcrp->GetPHOSMod();
321}
322
323//____________________________________________________________________________
324AliPHOSPpsdRecPoint * AliPHOSTrackSegment::GetPpsdLowRecPoint() const
325{
88714635 326 // Returns the lower PPSD rec point at the origin of this track
327
83974468 328 AliPHOSIndexToObject * please = AliPHOSIndexToObject::GetInstance() ;
329 AliPHOSPpsdRecPoint * rv = 0 ;
88714635 330
83974468 331 if ( fPpsdLowRecPoint > -1 )
332 rv = (AliPHOSPpsdRecPoint *)please->GimeRecPoint( fPpsdLowRecPoint, TString("ppsd") ) ;
333
334 return rv ;
335}
336
337//____________________________________________________________________________
338AliPHOSPpsdRecPoint * AliPHOSTrackSegment::GetPpsdUpRecPoint() const
339{
88714635 340 // Returns the lower PPSD rec point at the origin of this track
341
83974468 342 AliPHOSIndexToObject * please = AliPHOSIndexToObject::GetInstance() ;
343 AliPHOSPpsdRecPoint * rv = 0 ;
344
345 if ( fPpsdUpRecPoint > -1 )
346 rv = (AliPHOSPpsdRecPoint *)please->GimeRecPoint( fPpsdUpRecPoint, TString("ppsd") ) ;
347
348 return rv ;
349}
350
351//____________________________________________________________________________
b2a60966 352Int_t * AliPHOSTrackSegment::GetPrimariesEmc(Int_t & number)
353{
354 // Retrieves the primary particle(s) at the origin of the EMC RecPoint
83974468 355
356 AliPHOSEmcRecPoint * emcrp = GetEmcRecPoint() ;
357
b2a60966 358 Int_t * rv = 0 ;
359 number = 0 ;
83974468 360 if ( emcrp )
361 rv = emcrp->GetPrimaries(number) ;
b2a60966 362
363 return rv ;
364}
365
366//____________________________________________________________________________
367Int_t * AliPHOSTrackSegment::GetPrimariesPpsdLow(Int_t & number)
368{
369 // Retrieves the primary particle(s) at the origin of the lower PPSD RecPoint
370
83974468 371 AliPHOSPpsdRecPoint * ppsdlrp = GetPpsdLowRecPoint() ;
372
b2a60966 373 Int_t * rv = 0 ;
374 number = 0 ;
83974468 375 if ( ppsdlrp )
376 rv = ppsdlrp->GetPrimaries(number) ;
b2a60966 377
378 return rv ;
379}
380
381//____________________________________________________________________________
382Int_t * AliPHOSTrackSegment::GetPrimariesPpsdUp(Int_t & number)
383{
384 // Retrieves the primary particle(s) at the origin of the upper PPSD RecPoint
385
83974468 386 AliPHOSPpsdRecPoint * ppsdurp = GetPpsdUpRecPoint() ;
387
b2a60966 388 Int_t * rv = 0 ;
389 number = 0 ;
83974468 390 if ( ppsdurp )
391 rv = ppsdurp->GetPrimaries(number) ;
b2a60966 392
393 return rv ;
394}
d15a28e7 395
396//____________________________________________________________________________
397void AliPHOSTrackSegment::GetPosition( TVector3 & pos )
398{
b2a60966 399 // Returns position of the EMC RecPoint
83974468 400
401 AliPHOSEmcRecPoint * emcrp = GetEmcRecPoint() ;
402
92862013 403 TMatrix dummy ;
83974468 404 emcrp->GetGlobalPosition(pos, dummy) ;
d15a28e7 405}
406
b2a60966 407
9f616d61 408//______________________________________________________________________________
409void AliPHOSTrackSegment::Paint(Option_t *)
410{
83974468 411 // Paint this AliPHOSTrackSegment as a TMarker with its current attributes
412
413 AliPHOSEmcRecPoint * emcrp = GetEmcRecPoint() ;
414 AliPHOSPpsdRecPoint * ppsdlrp = GetPpsdLowRecPoint() ;
415 AliPHOSPpsdRecPoint * ppsdurp = GetPpsdUpRecPoint() ;
6ad0bfa0 416
b2a60966 417 TVector3 posemc(999., 999., 999.) ;
418 TVector3 posppsdl(999., 999., 999.) ;
419 TVector3 posppsdu(999., 999., 999.) ;
6ad0bfa0 420
83974468 421 emcrp->GetLocalPosition(posemc) ;
422 if (ppsdlrp !=0 )
423 ppsdlrp->GetLocalPosition(posppsdl) ;
424 if (ppsdurp !=0 )
425 ppsdurp->GetLocalPosition(posppsdu) ;
b2a60966 426
427 Coord_t xemc = posemc.X() ;
428 Coord_t yemc = posemc.Z() ;
429
430 Coord_t yppsdl = posppsdl.Z() ;
431 Coord_t xppsdl = posppsdl.X() ;
432
433 Coord_t yppsdu = posppsdu.Z() ;
434 Coord_t xppsdu = posppsdu.X() ;
435
436 Color_t markercolor = 1 ;
437 Size_t markersize = 1.5 ;
438 Style_t markerstyle = 20 ;
439
440 if (!gPad->IsBatch()) {
441 gVirtualX->SetMarkerColor(markercolor) ;
442 gVirtualX->SetMarkerSize (markersize) ;
443 gVirtualX->SetMarkerStyle(markerstyle) ;
444 }
445 gPad->SetAttMarkerPS(markercolor,markerstyle,markersize) ;
446 gPad->PaintPolyMarker(1, &xemc, &yemc, "") ;
447
448 if (xppsdl != 999. && yppsdl != 999. ) {
449
450 markercolor = 2 ;
451 markersize = 1.25 ;
452 markerstyle = 21 ;
453
454 if (!gPad->IsBatch()) {
455 gVirtualX->SetMarkerColor(markercolor) ;
456 gVirtualX->SetMarkerSize (markersize) ;
457 gVirtualX->SetMarkerStyle(markerstyle) ;
458 }
459 gPad->SetAttMarkerPS(markercolor,markerstyle,markersize) ;
460 gPad->PaintPolyMarker(1, &xppsdl, &yppsdl, "") ;
461 }
462
463 if (xppsdu != 999. && yppsdu != 999. ) {
464
465 markercolor = 3 ;
466 markersize = 1. ;
467 markerstyle = 22 ;
468
469 if (!gPad->IsBatch()) {
470 gVirtualX->SetMarkerColor(markercolor) ;
471 gVirtualX->SetMarkerSize (markersize) ;
472 gVirtualX->SetMarkerStyle(markerstyle) ;
6ad0bfa0 473 }
b2a60966 474 gPad->SetAttMarkerPS(markercolor,markerstyle,markersize) ;
475 gPad->PaintPolyMarker(1, &xppsdu, &yppsdu, "") ;
476 }
9f616d61 477}
478
d15a28e7 479//____________________________________________________________________________
0a6d52e3 480void AliPHOSTrackSegment::Print(const char * opt)
d15a28e7 481{
b2a60966 482 // Print all information on this track Segment
483
83974468 484 AliPHOSEmcRecPoint * emcrp = GetEmcRecPoint() ;
485 AliPHOSPpsdRecPoint * ppsdlrp = GetPpsdLowRecPoint() ;
486 AliPHOSPpsdRecPoint * ppsdurp = GetPpsdUpRecPoint() ;
d15a28e7 487
488 TVector3 pos ;
92862013 489 TMatrix dummy ;
d15a28e7 490
83974468 491 cout << "--------AliPHOSTrackSegment-------- "<<endl ;
d15a28e7 492
83974468 493 if ( emcrp != 0 ) {
494 cout << "******** EMC Reconstructed Point: " << endl;
495 emcrp->Print() ;
496
497 emcrp->GetGlobalPosition( pos, dummy ) ;
498
499 cout << " Global position " << pos.X() << " " << pos.Y() << " " << pos.Z() << " Energy " << emcrp->GetTotalEnergy() << endl ;
500 }
d15a28e7 501
83974468 502 if ( ppsdlrp != 0 ) {
503 cout << "******** PPSD Low Reconstructed Point: " << endl;
504
505 ppsdlrp->Print() ;
506 ppsdlrp->GetGlobalPosition( pos , dummy ) ;
507 cout << " position " << pos.X() << " " << pos.Y() << " " << pos.Z() << endl ;
d15a28e7 508 }
509
83974468 510 if( ppsdurp != 0 ) {
511 cout << "******** PPSD Up Reconstructed Point: " << endl;
512
513 ppsdurp->Print() ;
514 ppsdurp->GetGlobalPosition( pos, dummy ) ;
515 cout << " position " << pos.X() << " " << pos.Y() << " " << pos.Z() << endl ;
516 }
517
d15a28e7 518}
519