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