1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////
20 // Representation and extrapolation of AliTracks in a magnetic field.
22 // This class is meant to provide a means to display and extrapolate
23 // AliTrack objects in the presence of a constant homogeneous magnetic field.
28 // Display and extrapolation of individual tracks
29 // ----------------------------------------------
38 // r1.SetVector(vec,"car");
43 // p.SetVector(vec,"car");
46 // t.SetBeginPoint(r1);
50 // // The magnetic field vector in Tesla
55 // b.SetVector(vec,"car");
57 // AliHelix* helix=new AliHelix();
59 // helix->SetTofmax(1e-7);
61 // TCanvas* c1=new TCanvas("c1","c1");
62 // TView* view=new TView(1);
63 // view->SetRange(-1000,-1000,-1000,1000,1000,1000);
67 // Double_t range[2]={0,600};
68 // helix->Display(&t,range,3);
69 // t.SetCharge(-t.GetCharge());
70 // helix->Display(&t);
72 // // Track extrapolation
73 // Double_t pars[3]={550,0.001,3};
74 // AliPosition* rext=helix->Extrapolate(&t,pars);
75 // if (rext) rext->Data();
76 // ======================================================================
78 // Online display of events generated via AliCollider
79 // --------------------------------------------------
80 // Int_t nevents=5; // Number of events to be generated
81 // Int_t jrun=1; // The run number of this batch of generated events
83 // cout << " ***" << endl;
84 // cout << " *** AliCollider run for " << nevents << " events." << endl;
85 // cout << " ***" << endl;
87 // AliCollider* gen=new AliCollider();
89 // gen->OpenFortranFile(6,"dump.log");
91 // gen->SetVertexMode(2);
92 // gen->SetResolution(1e-4);
94 // gen->SetRunNumber(jrun);
95 // gen->SetPrintFreq(1);
97 // gen->SetSpectatorPmin(0.01);
104 // gen->Init("fixt",zp,ap,zt,at,158);
106 // AliHelix* helix=new AliHelix();
107 // Float_t vec[3]={0,2,0};
109 // b.SetVector(vec,"car");
112 // helix->Refresh(-1); // Refresh display after each event
114 // TCanvas* c1=new TCanvas("c1","c1");
115 // TView* view=new TView(1);
116 // view->SetRange(-200,-200,-200,200,200,200);
119 // // Prepare random number sequence for this run
120 // // to obtain the number of participants for each event
121 // AliRandom rndm(abs(jrun));
122 // Float_t* rans=new Float_t[nevents];
123 // rndm.Uniform(rans,nevents,2,ap+at);
126 // for (Int_t i=0; i<nevents; i++)
129 // gen->MakeEvent(npart);
130 // AliEvent* evt=gen->GetEvent();
133 // helix->Display(evt);
135 // gSystem->Sleep(5000); // Some delay to keep the display on screen
138 // ======================================================================
140 //--- Author: Nick van Eijndhoven 17-jun-2004 Utrecht University
141 //- Modified: NvE $Date$ Utrecht University
142 ///////////////////////////////////////////////////////////////////////////
144 #include "AliHelix.h"
145 #include "Riostream.h"
147 ClassImp(AliHelix) // Class implementation to enable ROOT I/O
149 AliHelix::AliHelix() : THelix()
151 // Default constructor
157 ///////////////////////////////////////////////////////////////////////////
158 AliHelix::~AliHelix()
160 // Destructor to delete dynamically allocated memory.
172 ///////////////////////////////////////////////////////////////////////////
173 AliHelix::AliHelix(const AliHelix& h) : THelix(h)
179 ///////////////////////////////////////////////////////////////////////////
180 void AliHelix::SetB(Ali3Vector& b)
182 // Set the magnetic field vector in Tesla.
188 fB.GetVector(axis,"car");
192 ///////////////////////////////////////////////////////////////////////////
193 Ali3Vector& AliHelix::GetB()
195 // Provide the magnetic field vector in Tesla.
198 ///////////////////////////////////////////////////////////////////////////
199 void AliHelix::SetTofmax(Float_t tof)
201 // Set the maximum time of flight for straight tracks in seconds.
202 // This maximum tof will be used for drawing etc... in case no begin
203 // and endpoints can be determined from the track info.
206 // 1) In case the user specifies an explicit range, it will override
207 // the maximum tof limit.
208 // 2) By default the tofmax is set to 10 ns in the AliHelix constructor.
211 ///////////////////////////////////////////////////////////////////////////
212 Float_t AliHelix::GetTofmax() const
214 // Provide the maximum time of flight for straight tracks in seconds.
217 ///////////////////////////////////////////////////////////////////////////
218 void AliHelix::MakeCurve(AliTrack* t,Double_t* range,Int_t iaxis,Double_t scale)
220 // Make the helix curve for the specified AliTrack.
221 // Detailed information of all the helix points can be obtained via the
222 // GetN() and GetP() memberfunctions of TPolyLine3D.
223 // In case one wants to display or extrapolate an AliTrack it is preferable
224 // to use the Display() or Extrapolate() memberfunctions.
225 // It is assumed that the track charge is stored in elementary units
226 // (i.e. charge=1 for a proton) and that the track energy is stored in GeV.
227 // The input argument "scale" specifies the unit scale for the various
228 // locations where scale=0.01 indicates unit scales in cm etc...
229 // In case scale<=0, the unit scale for locations is determined from the
230 // begin, reference or endpoint of the track. If neither of these
231 // positions is present, all locations are assumed to be given in cm.
232 // The lower and upper bounds for the range are specified by range[0] and
233 // range[1] and the argument "iaxis" indicates along which axis this range
235 // The range can be specified either in the LAB frame or in the Helix frame.
236 // The latter is the frame in which the Z axis points in the B direction.
238 // The conventions for the "iaxis" argument are the following :
239 // iaxis = 1 ==> X axis in the LAB frame
240 // 2 ==> Y axis in the LAB frame
241 // 3 ==> Z axis in the LAB frame
242 // -1 ==> X axis in the Helix frame
243 // -2 ==> Y axis in the Helix frame
244 // -3 ==> Z axis in the Helix frame
246 // In case range=0 the begin/end/reference points of the AliTrack and the
247 // maximum time of flight (see the SetTofmax() memberfunction) will be used
248 // and an appropriate choice for the iaxis parameter will be made automatically
249 // based on the track kinematics.
250 // In case the reference point is not present, the begin or endpoint will be used
251 // as reference point for the 3-momentum specification. If neither of these positions
252 // is present, (0,0,0) will be taken as the reference point.
254 // The default values are range=0, iaxis=3 and scale=-1.
256 SetPolyLine(0); // Reset the polyline data points
258 if (!t || (range && !iaxis)) return;
260 Double_t energy=t->GetEnergy();
261 Double_t betanorm=t->GetBeta();
263 if (energy<=0 || betanorm<=0) return;
265 AliPosition* rbeg=t->GetBeginPoint();
266 AliPosition* rend=t->GetEndPoint();
267 AliPosition* rref=t->GetReferencePoint();
269 // Magnetic field vector or default Z-direction
270 Double_t bvec[3]={0,0,1};
271 if (fB.GetNorm()>0) fB.GetVector(bvec,"car");
273 // The unit scale for locations if not specified by the user
276 scale=0.01; // Set default to cm
279 scale=rbeg->GetUnitScale();
283 scale=rend->GetUnitScale();
287 scale=rref->GetUnitScale();
291 Double_t c=2.99792458e8/scale; // Lightspeed in the selected unit scale
293 // The helix angular frequency
294 Double_t w=9e7*(t->GetCharge()*fB.GetNorm())/energy;
296 // The particle velocity in the LAB frame
297 Ali3Vector beta=t->GetBetaVector();
300 v.GetVector(vel,"car");
302 // The particle velocity in the Helix frame
303 Ali3Vector betaprim=beta.GetPrimed(fRotMat);
304 v=v.GetPrimed(fRotMat);
306 v.GetVector(velprim,"car");
308 // Check compatibility of velocity and range specification.
312 if (iaxis>0) beta.GetVector(betavec,"car");
313 if (iaxis<0) betaprim.GetVector(betavec,"car");
314 if (fabs(betavec[abs(iaxis)-1])/betanorm<1e-10) return;
317 // The LAB location in which the velocity of the particle is defined
318 Double_t loc[3]={0,0,0};
323 rx=(Ali3Vector*)rref;
324 scalex=rref->GetUnitScale();
328 rx=(Ali3Vector*)rbeg;
329 scalex=rbeg->GetUnitScale();
333 rx=(Ali3Vector*)rend;
334 scalex=rend->GetUnitScale();
339 if (scalex/scale>1.1 || scale/scalex>1.1) (*rx)*=scalex/scale;
340 rx->GetVector(loc,"car");
343 // Initialisation of Helix kinematics
344 SetHelix(loc,vel,w,0,kUnchanged,bvec);
347 if (fabs(w)>0 && fabs(fVt)>0) bend=1;
349 // Flight time boundaries.
350 // The time origin t=0 is chosen to indicate the position in which
351 // the particle velocity was defined.
352 // The total flight time is initialised to the (user specified) tofmax.
353 Double_t tmin=0,tmax=0;
354 Double_t tof=fTofmax;
357 // The trajectory begin and end points
358 Double_t vec1[3]={0,0,0};
359 Double_t vec2[3]={0,0,0};
362 Double_t scale1=0.01;
363 Double_t scale2=0.01;
367 ////////////////////////////////////////
368 // Treatment of straight trajectories //
369 ////////////////////////////////////////
371 if (range) // Specified range allows for exact flight time boundaries
375 tmin=(range[0]-loc[iaxis-1])/vel[iaxis-1];
376 tmax=(range[1]-loc[iaxis-1])/vel[iaxis-1];
383 tmin=(range[0]-loc[abs(iaxis)-1])/velprim[abs(iaxis)-1];
384 tmax=(range[1]-loc[abs(iaxis)-1])/velprim[abs(iaxis)-1];
392 // Make the 'curve' in the LAB frame and exit.
393 // Use the parametrisation : r(t)=r0+t*v
394 // using the range based flight time boundaries.
395 // An additional point in the middle of the trajectory is
396 // generated in view of accuracy in the case of extrapolations.
402 r1.GetVector(vec1,"car");
403 SetNextPoint(float(vec1[0]),float(vec1[1]),float(vec1[2]));
406 r2.GetVector(vec2,"car");
407 SetNextPoint(float(vec2[0]),float(vec2[1]),float(vec2[2]));
410 r2.GetVector(vec2,"car");
411 SetNextPoint(float(vec2[0]),float(vec2[1]),float(vec2[2]));
413 else // Automatic range determination
415 // Initially the point with Z=0 in the Helix frame is taken as a starting point.
416 // In case this point can't be reached, the point in which the particle velocity
417 // was defined is taken as the starting point.
418 // The endpoint is initially obtained by applying the tofmax from the start point.
420 if (fabs(fVz)>0) tmin=-fZ0/fVz;
426 // Override the initial begin and endpoint settings by the track data
429 r1=(Ali3Vector)(*rbeg);
430 scale1=rbeg->GetUnitScale();
431 // All coordinates in the selected unit scale
432 if (scale1/scale>1.1 || scale/scale1>1.1) r1*=scale1/scale;
439 r2=(Ali3Vector)(*rend);
440 scale2=rend->GetUnitScale();
441 // All coordinates in the selected unit scale
442 if (scale2/scale>1.1 || scale/scale2>1.1) r2*=scale2/scale;
445 r1.GetVector(vec1,"car");
446 r2.GetVector(vec2,"car");
448 // Make the 'curve' in the LAB frame and exit.
449 SetNextPoint(float(vec1[0]),float(vec1[1]),float(vec1[2]));
450 SetNextPoint(float(vec2[0]),float(vec2[1]),float(vec2[2]));
455 //////////////////////////////////////
456 // Treatment of curved trajectories //
457 //////////////////////////////////////
459 // Initialisation of the flight time boundaries.
460 // Based on the constant motion of the particle along the Helix Z-axis,
461 // the parametrisation z(t)=z0+fVz*t in the Helix frame is used.
462 // If possible the point with Z=0 in the Helix frame is taken as a starting point.
463 // In case this point can't be reached, the point in which the particle velocity
464 // was defined is taken as the starting point.
466 if (fabs(fVz)>0) tmin=-fZ0/fVz;
476 // Determination of the range in the helix frame
478 if (!range) // Automatic range determination
484 r1=rbeg->GetPrimed(fRotMat);
485 scale1=rbeg->GetUnitScale();
486 // All coordinates in the selected unit scale
487 if (scale1/scale>1.1 || scale/scale1>1.1) r1*=scale1/scale;
488 // Re-calculate the tmin for this new starting point
489 r1.GetVector(vec1,"car");
490 if (fabs(fVz)>0) tmin=(vec1[2]-fZ0)/fVz;
495 r2=rend->GetPrimed(fRotMat);
496 scale2=rend->GetUnitScale();
497 // All coordinates in the selected unit scale
498 if (scale2/scale>1.1 || scale/scale2>1.1) r2*=scale2/scale;
499 r2.GetVector(vec2,"car");
500 if (fabs(fVz)>0) tmax=(vec2[2]-fZ0)/fVz;
502 // Make the curve on basis of the flight time boundaries and exit
509 SetRange(tmin,tmax,kHelixT);
511 else // User explicitly specified range
513 vec1[abs(iaxis)-1]=range[0];
514 vec2[abs(iaxis)-1]=range[1];
515 r1.SetVector(vec1,"car");
516 r2.SetVector(vec2,"car");
517 if (iaxis>0) // Range specified in LAB frame
519 r1=r1.GetPrimed(fRotMat);
520 r1.GetVector(vec1,"car");
521 r2=r2.GetPrimed(fRotMat);
522 r2.GetVector(vec2,"car");
524 // Determination of the axis component with the
525 // largest range difference
529 for (Int_t i=0; i<3; i++)
531 test=fabs(vec1[i]-vec2[i]);
539 Double_t rmin=vec1[imax];
540 Double_t rmax=vec2[imax];
548 // The kinematic range boundaries in the helix frame
549 Double_t xmin=fX0-fVt/fW;
550 Double_t xmax=fX0+fVt/fW;
551 Double_t ymin=fY0-fVt/fW;
552 Double_t ymax=fY0+fVt/fW;
567 // Set the range for the helix
568 if (imax==2 && dmax>0) SetRange(rmin,rmax,kHelixZ);
571 // Limit range to kinematic boundaries if needed
572 if (rmin<=ymin) rmin=ymin+1e-6*dmax;
573 if (rmax>=ymax) rmax=ymax-1e-6*dmax;
574 if (rmin<rmax) SetRange(rmin,rmax,kHelixY);
578 // Limit range to kinematic boundaries if needed
579 if (rmin<=xmin) rmin=xmin+1e-6*dmax;
580 if (rmax>=xmax) rmax=xmax-1e-6*dmax;
581 if (rmin<rmax) SetRange(rmin,rmax,kHelixX);
587 ///////////////////////////////////////////////////////////////////////////
588 void AliHelix::Display(AliTrack* t,Double_t* range,Int_t iaxis,Double_t scale)
590 // Display the helix curve of an AliTrack.
591 // Various curves can be displayed together or individually; please refer to
592 // the memberfunction Refresh() for further details.
593 // It is assumed that the track charge is stored in elementary units
594 // (i.e. charge=1 for a proton) and that the track energy is stored in GeV.
595 // The input argument "scale" specifies the unit scale for the various
596 // locations where scale=0.01 indicates unit scales in cm etc...
597 // In case scale<=0, the unit scale for locations is determined from the
598 // begin, reference or endpoint of the track. If neither of these
599 // positions is present, all locations are assumed to be given in cm.
600 // The lower and upper bounds for the range are specified by range[0] and
601 // range[1] and the argument "iaxis" indicates along which axis this range
603 // The range can be specified either in the LAB frame or in the Helix frame.
604 // The latter is the frame in which the Z axis points in the B direction.
606 // The conventions for the "iaxis" argument are the following :
607 // iaxis = 1 ==> X axis in the LAB frame
608 // 2 ==> Y axis in the LAB frame
609 // 3 ==> Z axis in the LAB frame
610 // -1 ==> X axis in the Helix frame
611 // -2 ==> Y axis in the Helix frame
612 // -3 ==> Z axis in the Helix frame
614 // In case range=0 the begin/end/reference points of the AliTrack and the
615 // maximum time of flight (see the SetTofmax() memberfunction) will be used
616 // and an appropriate choice for the iaxis parameter will be made automatically
617 // based on the track kinematics.
618 // In case the reference point is not present, the begin or endpoint will be used
619 // as reference point for the 3-momentum specification. If neither of these positions
620 // is present, (0,0,0) will be taken as the reference point.
622 // The default values are range=0, iaxis=3 and scale=-1.
626 // Before any display activity, a TCanvas and a TView have to be initiated
627 // first by the user like for instance
629 // TCanvas* c1=new TCanvas("c1","c1");
630 // TView* view=new TView(1);
631 // view->SetRange(-1000,-1000,-1000,1000,1000,1000);
634 if (!t || (range && !iaxis)) return;
636 MakeCurve(t,range,iaxis,scale);
638 if (fRefresh>0) Refresh(fRefresh);
643 Float_t* points=GetP();
644 TPolyLine3D* curve=new TPolyLine3D(np,points);
646 curve->SetLineWidth(2);
647 Float_t q=t->GetCharge();
648 curve->SetLineColor(kGreen);
649 if (q>0) curve->SetLineColor(kRed);
650 if (q<0) curve->SetLineColor(kBlue);
655 fCurves=new TObjArray();
660 ///////////////////////////////////////////////////////////////////////////
661 void AliHelix::Refresh(Int_t mode)
663 // Refresh the display screen before showing the next curve.
665 // mode = 0 : refreshing fully under user control.
666 // 1 : the display screen will be refreshed automatically
667 // at each individual track display.
668 // -1 : the display screen will be refreshed automatically
669 // at each event display.
671 // The default is mode=0.
673 if (abs(mode)<2) fRefresh=mode;
674 if (fCurves) fCurves->Delete();
676 ///////////////////////////////////////////////////////////////////////////
677 void AliHelix::Display(AliEvent* evt,Double_t* range,Int_t iaxis,Double_t scale)
679 // Display the helix curves of all tracks of the specified event.
680 // Various events can be displayed together or individually; please refer to
681 // the memberfunction Refresh() for further details.
682 // Please refer to the track display memberfunction for further details
683 // on the input arguments.
685 // The default values are range=0, iaxis=3 and scale=-1.
689 // Before any display activity, a TCanvas and a TView have to be initiated
690 // first by the user like for instance
692 // TCanvas* c1=new TCanvas("c1","c1");
693 // TView* view=new TView(1);
694 // view->SetRange(-1000,-1000,-1000,1000,1000,1000);
699 if (fRefresh<0) Refresh(fRefresh);
701 Int_t ntk=evt->GetNtracks();
702 for (Int_t jtk=1; jtk<=ntk; jtk++)
704 AliTrack* tx=evt->GetTrack(jtk);
705 if (tx) Display(tx,range,iaxis,scale);
708 ///////////////////////////////////////////////////////////////////////////
709 AliPosition* AliHelix::Extrapolate(AliTrack* t,Double_t* pars,Double_t scale)
711 // Extrapolate an AliTrack according to the corresponding helix curve
712 // and provide a pointer to the impact position w.r.t. a specified plane.
713 // In case the track can never reach the specified plane, the returned
714 // position pointer is zero.
715 // Detailed information of all the helix points used in the extrapolation
716 // can be obtained via the GetN() and GetP() memberfunctions of TPolyLine3D.
717 // It is assumed that the track charge is stored in elementary units
718 // (i.e. charge=1 for a proton) and that the track energy is stored in GeV.
719 // The input argument "scale" specifies the unit scale for the various
720 // locations where scale=0.01 indicates unit scales in cm etc...
721 // In case scale<=0, the unit scale for locations is determined from the
722 // begin, reference or endpoint of the track. If neither of these
723 // positions is present, all locations are assumed to be given in cm.
724 // The extrapolation parameters for the impact plane and required accuracy
725 // are specified by pars[0], pars[1] and pars[2], respectively.
726 // pars[0] = coordinate value of the plane for the impact point
727 // pars[1] = required accuracy on the specified impact plane coordinate
728 // pars[2] = the axis along which the value of par[0] is specified
730 // The parameters can be specified either w.r.t. the LAB frame or the Helix frame.
731 // The latter is the frame in which the Z axis points in the B direction.
733 // The conventions for the par[2] argument are the following :
734 // par[2] = 1 ==> X axis in the LAB frame
735 // 2 ==> Y axis in the LAB frame
736 // 3 ==> Z axis in the LAB frame
737 // -1 ==> X axis in the Helix frame
738 // -2 ==> Y axis in the Helix frame
739 // -3 ==> Z axis in the Helix frame
743 // To obtain an extrapolation to the plane Z=0 in the LAB frame
744 // with an accuracy of 0.001 cm the input arguments would be
745 // pars[0]=0 pars[1]=0.001 pars[2]=3 scale=0.01
747 // Note : The default value for the scale is -1.
755 if (!t || !pars) return fExt;
757 AliPosition* rbeg=t->GetBeginPoint();
758 AliPosition* rend=t->GetEndPoint();
759 AliPosition* rref=t->GetReferencePoint();
761 // The unit scale for locations if not specified by the user
764 scale=0.01; // Set default to cm
767 scale=rbeg->GetUnitScale();
771 scale=rend->GetUnitScale();
775 scale=rref->GetUnitScale();
780 range[0]=pars[0]-fabs(pars[1])/2.;
781 range[1]=pars[0]+fabs(pars[1])/2.;
783 Int_t iaxis=int(pars[2]);
785 MakeCurve(t,range,iaxis,scale);
788 if (!np) return fExt;
790 Float_t* points=GetP();
792 // First point of the curve around the impact
794 Float_t first[3]={points[3*ip],points[3*ip+1],points[3*ip+2]};
796 // Last point of the curve around the impact
798 Float_t last[3]={points[3*ip],points[3*ip+1],points[3*ip+2]};
800 // The accuracy on the impact point
802 err[0]=fabs(first[0]-last[0]);
803 err[1]=fabs(first[1]-last[1]);
804 err[2]=fabs(first[2]-last[2]);
806 // Take the middle point as impact location
808 Float_t imp[3]={points[3*ip],points[3*ip+1],points[3*ip+2]};
810 fExt=new AliPosition();
811 fExt->SetUnitScale(scale);
812 fExt->SetPosition(imp,"car");
813 fExt->SetPositionErrors(err,"car");
817 ///////////////////////////////////////////////////////////////////////////