TGeoTrack.cxx

Go to the documentation of this file.
00001 // @(#)root/geom:$Id: TGeoTrack.cxx 36535 2010-11-08 14:41:54Z agheata $
00002 // Author: Andrei Gheata  2003/04/10
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #include "TBrowser.h"
00013 #include "TPolyLine3D.h"
00014 #include "TPoint.h"
00015 #include "TVirtualPad.h"
00016 #include "TView.h"
00017 
00018 #include "TGeoManager.h"
00019 #include "TVirtualGeoPainter.h"
00020 #include "TGeoTrack.h"
00021 
00022 //______________________________________________________________________________
00023 // TGeoTrack - Class for user-defined tracks attached to a geometry.
00024 //             Tracks are 3D objects made of points and they store a 
00025 //             pointer to a TParticle. The geometry manager holds a list
00026 //             of all tracks that will be deleted on destruction of 
00027 //             gGeoManager.
00028 //
00029 //______________________________________________________________________________
00030 
00031 ClassImp(TGeoTrack)
00032 
00033 //______________________________________________________________________________
00034 TGeoTrack::TGeoTrack()
00035 {
00036 //*-*-*-*-*-*-*-*-*-*-*Tracks default constructor*-*-*-*-*-*-*-*-*
00037 //*-*                  ==========================
00038    fPointsSize = 0;
00039    fNpoints    = 0;
00040    fPoints     = 0;
00041 }
00042 
00043 //______________________________________________________________________________
00044 TGeoTrack::TGeoTrack(Int_t id, Int_t pdgcode, TVirtualGeoTrack *parent, TObject *particle)
00045           :TVirtualGeoTrack(id,pdgcode,parent,particle)
00046 {
00047 // Constructor.
00048    fPointsSize = 0;
00049    fNpoints    = 0;
00050    fPoints     = 0;
00051    if (fParent==0) {
00052       SetMarkerColor(2);
00053       SetMarkerStyle(8);
00054       SetMarkerSize(0.6);
00055       SetLineColor(2);
00056       SetLineWidth(2);
00057    } else {
00058       SetMarkerColor(4);
00059       SetMarkerStyle(8);
00060       SetMarkerSize(0.6);
00061       SetLineColor(4);
00062       SetLineWidth(2);
00063    }  
00064 }
00065 
00066 //_____________________________________________________________________________
00067 TGeoTrack::TGeoTrack(const TGeoTrack& other)
00068                  :TVirtualGeoTrack(other),
00069                   fPointsSize(other.fPointsSize),
00070                   fNpoints(other.fNpoints),
00071                   fPoints(other.fPoints)
00072 {
00073 // Copy ctor. NOT TO BE CALLED.
00074 }
00075 
00076 //_____________________________________________________________________________
00077 TGeoTrack& TGeoTrack::operator=(const TGeoTrack& gv) 
00078 {
00079    // Assignment operator. NOT TO BE CALLED.
00080    if(this!=&gv) {
00081       TVirtualGeoTrack::operator=(gv);
00082       fPointsSize=gv.fPointsSize;
00083       fNpoints=gv.fNpoints;
00084       fPoints=gv.fPoints;
00085    } 
00086    return *this;
00087 }
00088 
00089 //______________________________________________________________________________
00090 TGeoTrack::~TGeoTrack()
00091 {
00092 // Destructor.
00093    if (fPoints) delete [] fPoints;
00094 //   if (gPad) gPad->GetListOfPrimitives()->Remove(this);
00095 }
00096 
00097 //______________________________________________________________________________
00098 TVirtualGeoTrack *TGeoTrack::AddDaughter(Int_t id, Int_t pdgcode, TObject *particle)
00099 {
00100 // Add a daughter track to this.
00101    if (!fTracks) fTracks = new TObjArray(1);
00102    Int_t index = fTracks->GetEntriesFast();
00103    TGeoTrack *daughter = new TGeoTrack(id,pdgcode,this,particle);
00104    fTracks->AddAtAndExpand(daughter,index);
00105    return daughter;
00106 }
00107 
00108 //______________________________________________________________________________
00109 Int_t TGeoTrack::AddDaughter(TVirtualGeoTrack *other)
00110 {
00111 // Add a daughter and return its index.
00112    if (!fTracks) fTracks = new TObjArray(1);
00113    Int_t index = fTracks->GetEntriesFast();
00114    fTracks->AddAtAndExpand(other,index);
00115    other->SetParent(this);
00116    return index;
00117 }
00118 
00119 //______________________________________________________________________________
00120 void TGeoTrack::AnimateTrack(Double_t tmin, Double_t tmax, Double_t nframes, Option_t *option)
00121 {
00122 // Draw animation of this track
00123    if (tmin<0 || tmin>=tmax || nframes<1) return;
00124    gGeoManager->SetAnimateTracks();
00125    gGeoManager->SetVisLevel(1);
00126    if (!gPad) {
00127       gGeoManager->GetMasterVolume()->Draw();
00128    }   
00129    TList *list = gPad->GetListOfPrimitives();
00130    TIter next(list);
00131    TObject *obj;
00132    while ((obj = next())) {
00133       if (!strcmp(obj->ClassName(), "TGeoTrack")) list->Remove(obj);
00134    }      
00135    Double_t dt = (tmax-tmin)/Double_t(nframes);
00136    Double_t delt = 2E-9;
00137    Double_t t = tmin;
00138    Bool_t geomanim = kFALSE;
00139    Bool_t issave = kFALSE;
00140    TString fname;
00141    
00142    TString opt(option);
00143    if (opt.Contains("/G")) geomanim = kTRUE;
00144    if (opt.Contains("/S")) issave = kTRUE;
00145 
00146    TVirtualGeoPainter *p = gGeoManager->GetGeomPainter();
00147    Double_t *box = p->GetViewBox();
00148    box[0] = box[1] = box[2] = 0;
00149    box[3] = box[4] = box[5] = 100;
00150    gGeoManager->SetTminTmax(0,0);
00151    Draw(opt.Data());
00152    Double_t start[6], end[6];
00153    Int_t i, j;
00154    Double_t dlat=0, dlong=0, dpsi=0;
00155    Double_t dd[6] = {0,0,0,0,0,0};
00156    if (geomanim) {
00157       p->EstimateCameraMove(tmin+5*dt, tmin+15*dt, start, end);
00158       for (i=0; i<3; i++) {
00159          start[i+3] = 20 + 1.3*start[i+3];
00160          end[i+3] = 20 + 0.9*end[i+3];
00161       }
00162       for (i=0; i<6; i++) {
00163          dd[i] = (end[i]-start[i])/10.;
00164       }      
00165       memcpy(box, start, 6*sizeof(Double_t));
00166       p->GetViewAngles(dlong,dlat,dpsi);
00167       dlong = (-206-dlong)/Double_t(nframes);
00168       dlat  = (126-dlat)/Double_t(nframes);
00169       dpsi  = (75-dpsi)/Double_t(nframes);
00170       p->GrabFocus();
00171    }
00172    
00173    for (i=0; i<nframes; i++) {
00174       if (t-delt<0) gGeoManager->SetTminTmax(0,t);
00175       else gGeoManager->SetTminTmax(t-delt,t);
00176       if (geomanim) {
00177          for (j=0; j<6; j++) box[j]+=dd[j];
00178          p->GrabFocus(1,dlong,dlat,dpsi);
00179       } else {
00180          gPad->Modified();
00181          gPad->Update();
00182       }     
00183       if (issave) {
00184          fname = TString::Format("anim%04d.gif", i);
00185          gPad->Print(fname);
00186       }   
00187       t += dt;
00188    }   
00189    gGeoManager->SetAnimateTracks(kFALSE);
00190 }
00191 
00192 //______________________________________________________________________________
00193 void TGeoTrack::AddPoint(Double_t x, Double_t y, Double_t z, Double_t t)
00194 {
00195 // Add a point on the track.
00196    if (!fPoints) {
00197       fPointsSize = 16;
00198       fPoints = new Double_t[fPointsSize];
00199    } else {
00200       if (fNpoints>=fPointsSize) {
00201          Double_t *temp = new Double_t[2*fPointsSize];
00202          memcpy(temp, fPoints, fNpoints*sizeof(Double_t));
00203          fPointsSize *= 2;
00204          delete [] fPoints;
00205          fPoints = temp;
00206       }
00207    }
00208    fPoints[fNpoints++] = x;      
00209    fPoints[fNpoints++] = y;      
00210    fPoints[fNpoints++] = z;      
00211    fPoints[fNpoints++] = t;      
00212 }
00213 
00214 //______________________________________________________________________________
00215 void TGeoTrack::Browse(TBrowser *b)
00216 {
00217 // How-to-browse for a track.
00218    if (!b) return;
00219    Int_t nd = GetNdaughters();
00220    if (!nd) {
00221       b->Add(this);
00222       return;
00223    }   
00224    for (Int_t i=0; i<nd; i++) 
00225       b->Add(GetDaughter(i));
00226 
00227 }
00228 
00229 //______________________________________________________________________________
00230 Int_t TGeoTrack::DistancetoPrimitive(Int_t px, Int_t py)
00231 {
00232 // Returns distance to track primitive for picking.
00233    const Int_t inaxis = 7;
00234    const Int_t maxdist = 5;
00235    Int_t dist = 9999;
00236 
00237 
00238    Int_t puxmin = gPad->XtoAbsPixel(gPad->GetUxmin());
00239    Int_t puymin = gPad->YtoAbsPixel(gPad->GetUymin());
00240    Int_t puxmax = gPad->XtoAbsPixel(gPad->GetUxmax());
00241    Int_t puymax = gPad->YtoAbsPixel(gPad->GetUymax());
00242 
00243    // return if point is not in the user area
00244    if (px < puxmin - inaxis) return dist;
00245    if (py > puymin + inaxis) return dist;
00246    if (px > puxmax + inaxis) return dist;
00247    if (py < puymax - inaxis) return dist;
00248 
00249    TView *view = gPad->GetView();
00250    if (!view) return dist;
00251    Int_t imin, imax;
00252    if (TObject::TestBit(kGeoPDrawn) && Size(imin,imax)>=2) {
00253       Int_t i, dsegment;
00254       Double_t x1,y1,x2,y2;
00255       Double_t xndc[3];
00256       Int_t np = fNpoints>>2;
00257       if (imin<0) imin=0;
00258       if (imax>np-1) imax=np-1;
00259       for (i=imin;i<imax;i++) {
00260          view->WCtoNDC(&fPoints[i<<2], xndc);
00261          x1 = xndc[0];
00262          y1 = xndc[1];
00263          view->WCtoNDC(&fPoints[(i+1)<<2], xndc);
00264          x2 = xndc[0];
00265          y2 = xndc[1];
00266          dsegment = DistancetoLine(px,py,x1,y1,x2,y2);
00267 //         printf("%i: dseg=%i\n", i, dsegment); 
00268          if (dsegment < dist) {
00269             dist = dsegment;
00270             if (dist<maxdist) {
00271                gPad->SetSelected(this);
00272                return 0;
00273             }
00274          }      
00275       }
00276       if (dist<maxdist) {
00277          gPad->SetSelected(this);
00278          return 0;
00279       }   
00280    }
00281    // check now daughters   
00282    Int_t nd = GetNdaughters();
00283    if (!nd) return dist;
00284    TGeoTrack *track;
00285    for (Int_t id=0; id<nd; id++) {
00286       track = (TGeoTrack*)GetDaughter(id);
00287       dist = track->DistancetoPrimitive(px,py);
00288       if (dist<maxdist) return 0;
00289    }
00290    return dist;
00291 }
00292 
00293 //______________________________________________________________________________
00294 void TGeoTrack::Draw(Option_t *option)
00295 {
00296 // Draw this track overimposed on a geometry, according to option.
00297 // Options (case sensitive):
00298 //  default : track without daughters
00299 //  /D      : track and first level descendents only
00300 //  /*      : track and all descendents
00301 //  /Ntype
00302 //          : descendents of this track with particle name matching input type.
00303 // Options can appear only once but can be combined : e.g. Draw("/D /Npion-")
00304 // Time range for visible track segments can be set via TGeoManager::SetTminTmax()
00305 
00306    if (!gPad) gGeoManager->GetMasterVolume()->Draw();
00307    char *opt1 = Compress(option); // we will have to delete this ?
00308    TString opt(opt1);
00309    Bool_t is_default = kTRUE;
00310    Bool_t is_onelevel = kFALSE;
00311    Bool_t is_all = kFALSE;
00312    Bool_t is_type = kFALSE;
00313    if (opt.Contains("/D")) {
00314       is_onelevel = kTRUE;
00315       is_default = kFALSE;
00316    }   
00317    if (opt.Contains("/*")) {
00318       is_all = kTRUE;
00319       is_default = kFALSE;
00320    }   
00321    if (opt.Contains("/N")) {
00322       is_type = kTRUE;
00323       Int_t ist = opt.Index("/N")+2;
00324       Int_t ilast = opt.Index("/",ist);
00325       if (ilast<0) ilast=opt.Length();
00326       TString type = opt(ist, ilast-ist);
00327       gGeoManager->SetParticleName(type.Data());
00328    } 
00329    SetBits(is_default, is_onelevel, is_all, is_type);
00330    AppendPad("SAME"); 
00331    if (!gGeoManager->IsAnimatingTracks()) {
00332       gPad->Modified();
00333       gPad->Update();
00334    }      
00335    delete [] opt1;
00336    return;
00337 }      
00338 
00339  //______________________________________________________________________________
00340 void TGeoTrack::ExecuteEvent(Int_t /*event*/, Int_t /*px*/, Int_t /*py*/)     
00341 {
00342 // Event treatment.
00343    if (!gPad) return;
00344    gPad->SetCursor(kHand);
00345 }
00346 
00347 //______________________________________________________________________________
00348 char *TGeoTrack::GetObjectInfo(Int_t /*px*/, Int_t /*py*/) const
00349 {
00350 // Get some info about the track.
00351    static TString info;
00352    Double_t x=0,y=0,z=0,t=0;
00353    GetPoint(0,x,y,z,t);
00354    info = TString::Format("%s (%g, %g, %g) tof=%g", GetName(),x,y,z,t);
00355    return (char*)info.Data();
00356 }
00357 
00358 //______________________________________________________________________________
00359 Int_t TGeoTrack::GetPoint(Int_t i, Double_t &x, Double_t &y, Double_t &z, Double_t &t) const
00360 {
00361 // Get coordinates for point I on the track.
00362    Int_t np = fNpoints>>2;
00363    if (i<0 || i>=np) {
00364       Error("GetPoint", "no point %i, indmax=%d", i, np-1);
00365       return -1;
00366    }
00367    Int_t icrt = 4*i;   
00368    x = fPoints[icrt];
00369    y = fPoints[icrt+1];
00370    z = fPoints[icrt+2];
00371    t = fPoints[icrt+3];
00372    return i;
00373 }   
00374 
00375 //______________________________________________________________________________
00376 const Double_t *TGeoTrack::GetPoint(Int_t i) const
00377 {
00378 // Return the pointer to the array of points starting with index I.
00379    if (!fNpoints) return 0;
00380    return (&fPoints[i<<2]);
00381 }   
00382 
00383 //______________________________________________________________________________
00384 Int_t TGeoTrack::GetPoint(Double_t tof, Double_t *point, Int_t istart) const
00385 {
00386 // Return the index of point on track having closest TOF smaller than
00387 // the input value. Output POINT is filled with the interpolated value.
00388    Int_t np = fNpoints>>2;
00389    if (istart>(np-2)) return (np-1);
00390    Int_t ip = SearchPoint(tof, istart);
00391    if (ip<0 || ip>(np-2)) return ip;
00392    // point in segment (ip, ip+1) where 0<=ip<fNpoints-1
00393    Int_t i;
00394    Int_t j = ip<<2;
00395    Int_t k = (ip+1)<<2;
00396    Double_t dt  = tof-fPoints[j+3];
00397    Double_t ddt = fPoints[k+3]-fPoints[j+3];
00398    for (i=0; i<3; i++) point[i] = fPoints[j+i] +(fPoints[k+i]-fPoints[j+i])*dt/ddt;
00399    return ip;
00400 }   
00401 
00402 //______________________________________________________________________________
00403 void TGeoTrack::Paint(Option_t *option)
00404 {
00405 // Paint this track (and descendents) with current attributes.
00406    Bool_t is_default  = TObject::TestBit(kGeoPDefault);
00407    Bool_t is_onelevel = TObject::TestBit(kGeoPOnelevel);
00408    Bool_t is_all      = TObject::TestBit(kGeoPAllDaughters);
00409    Bool_t is_type     = TObject::TestBit(kGeoPType);
00410    Bool_t match_type  = kTRUE;
00411    TObject::SetBit(kGeoPDrawn, kFALSE);
00412    if (is_type) {
00413       const char *type = gGeoManager->GetParticleName();
00414       if (strlen(type) && strcmp(type, GetName())) match_type=kFALSE;
00415    }   
00416    if (match_type) {
00417       if (is_default || is_onelevel || is_all) PaintTrack(option);
00418    }
00419    // paint now daughters
00420    Int_t nd = GetNdaughters();
00421    if (!nd || is_default) return;
00422    TGeoTrack *track;
00423    for (Int_t i=0; i<nd; i++) {
00424       track = (TGeoTrack*)GetDaughter(i);
00425       if (track->IsInTimeRange()) {
00426          track->SetBits(is_default,kFALSE,is_all,is_type);
00427          track->Paint(option);
00428       }   
00429    }   
00430 }
00431 
00432 //______________________________________________________________________________
00433 void TGeoTrack::PaintCollect(Double_t time, Double_t *box)
00434 {
00435 // Paint track and daughters.
00436    Bool_t is_default  = TObject::TestBit(kGeoPDefault);
00437    Bool_t is_onelevel = TObject::TestBit(kGeoPOnelevel);
00438    Bool_t is_all      = TObject::TestBit(kGeoPAllDaughters);
00439    Bool_t is_type     = TObject::TestBit(kGeoPType);
00440    Bool_t match_type  = kTRUE;
00441    if (is_type) {
00442       const char *type = gGeoManager->GetParticleName();
00443       if (strlen(type) && strcmp(type, GetName())) match_type=kFALSE;
00444    }   
00445    if (match_type) {
00446       if (is_default || is_onelevel || is_all) PaintCollectTrack(time, box);
00447    }
00448    // loop now daughters
00449    Int_t nd = GetNdaughters();
00450    if (!nd || is_default) return;
00451    TGeoTrack *track;
00452    for (Int_t i=0; i<nd; i++) {
00453       track = (TGeoTrack*)GetDaughter(i);
00454       track->PaintCollect(time, box);
00455    }   
00456 }
00457 
00458 //______________________________________________________________________________
00459 void TGeoTrack::PaintCollectTrack(Double_t time, Double_t *box)
00460 {
00461 // Paint just this track.
00462    TVirtualGeoPainter *painter = gGeoManager->GetGeomPainter();
00463    if (!painter) return;
00464    Int_t np = fNpoints>>2;
00465    Double_t point[3], local[3];
00466    Bool_t convert = (gGeoManager->GetTopVolume() == gGeoManager->GetMasterVolume())?kFALSE:kTRUE;
00467    Int_t ip = GetPoint(time, point);
00468    if (ip>=0 && ip<np-1) {
00469       if (convert) gGeoManager->MasterToTop(point, local);
00470       else memcpy(local, point, 3*sizeof(Double_t));
00471       painter->AddTrackPoint(local, box);
00472    }
00473 }
00474 
00475 //______________________________________________________________________________
00476 void TGeoTrack::PaintMarker(Double_t *point, Option_t *)
00477 {
00478 // Paint current point of the track as marker.
00479    TPoint p;
00480    Double_t xndc[3];
00481    TView *view = gPad->GetView();
00482    if (!view) return;
00483    view->WCtoNDC(point, xndc);   
00484    if (xndc[0] < gPad->GetX1() || xndc[0] > gPad->GetX2()) return;
00485    if (xndc[1] < gPad->GetY1() || xndc[1] > gPad->GetY2()) return;
00486    p.fX = gPad->XtoPixel(xndc[0]);
00487    p.fY = gPad->YtoPixel(xndc[1]);
00488    TAttMarker::Modify();
00489    gVirtualX->DrawPolyMarker(1, &p);
00490 }
00491 
00492 //______________________________________________________________________________
00493 void TGeoTrack::PaintTrack(Option_t *option)
00494 {
00495 // Paint this track with its current attributes.
00496 
00497    // Check whether there is some 3D view class for this TPad
00498 //   TPadView3D *view3D = (TPadView3D*)gPad->GetView3D();
00499 //   if (view3D) view3D->PaintGeoTrack(this,option); // to be implemented
00500 
00501    // Check if option is 'x3d'.      NOTE: This is a simple checking
00502    //                                      but since there is no other
00503    //                                      options yet, this works fine.
00504    TString opt(option);
00505    opt.ToLower();
00506    TObject::SetBit(kGeoPDrawn, kFALSE);
00507    if (opt.Contains("x")) return;
00508    Int_t np = fNpoints>>2;
00509    Int_t imin=0;
00510    Int_t imax=np-1;
00511    Int_t ip;
00512    Double_t start[3], end[3], seg[6];
00513    Bool_t convert = (gGeoManager->GetTopVolume() == gGeoManager->GetMasterVolume())?kFALSE:kTRUE;
00514    Double_t tmin,tmax;
00515    Bool_t is_time = gGeoManager->GetTminTmax(tmin,tmax);
00516    if (is_time) {
00517       imin = GetPoint(tmin, start);
00518       if (imin>=0 && imin<np-1) {
00519       // we have a starting point -> find ending point
00520          imax = GetPoint(tmax, end, imin);
00521          if (imax<np-1) {
00522          // we also have an ending point -> check if on the same segment with imin
00523             if (imax==imin) {
00524                // paint the virtual segment between the 2 points
00525                TAttLine::Modify();
00526                if (convert) {
00527                   gGeoManager->MasterToTop(start, &seg[0]);
00528                   gGeoManager->MasterToTop(end, &seg[3]);
00529                   gPad->PaintLine3D(&seg[0], &seg[3]);
00530                } else {
00531                   gPad->PaintLine3D(start, end);
00532                }   
00533             } else {
00534                // paint the starting, ending and connecting segments
00535                TAttLine::Modify();
00536                if (convert) {
00537                   gGeoManager->MasterToTop(start, &seg[0]);
00538                   gGeoManager->MasterToTop(&fPoints[(imin+1)<<2], &seg[3]);
00539                   gPad->PaintLine3D(&seg[0], &seg[3]);
00540                   gGeoManager->MasterToTop(&fPoints[imax<<2], &seg[0]);
00541                   gGeoManager->MasterToTop(end, &seg[3]);
00542                   gPad->PaintLine3D(&seg[0], &seg[3]);
00543                   for (ip=imin+1; ip<imax; ip++) {
00544                      gGeoManager->MasterToTop(&fPoints[ip<<2], &seg[0]);
00545                      gGeoManager->MasterToTop(&fPoints[(ip+1)<<2], &seg[3]);
00546                      gPad->PaintLine3D(&seg[0], &seg[3]);
00547                   }
00548                } else {
00549                   gPad->PaintLine3D(start, &fPoints[(imin+1)<<2]);
00550                   gPad->PaintLine3D(&fPoints[imax<<2], end);
00551                   for (ip=imin+1; ip<imax; ip++) {
00552                      gPad->PaintLine3D(&fPoints[ip<<2], &fPoints[(ip+1)<<2]);
00553                   }
00554                }   
00555             }
00556             if (convert) {
00557                gGeoManager->MasterToTop(end, &seg[0]);
00558                PaintMarker(&seg[0]);
00559             } else {   
00560                PaintMarker(end);
00561             }   
00562          } else {
00563             TAttLine::Modify();
00564             if (convert) {
00565                gGeoManager->MasterToTop(start, &seg[0]);
00566                gGeoManager->MasterToTop(&fPoints[(imin+1)<<2], &seg[3]);
00567                gPad->PaintLine3D(&seg[0], &seg[3]);
00568                for (ip=imin+1; ip<np-2; ip++) {
00569                   gGeoManager->MasterToTop(&fPoints[ip<<2], &seg[0]);
00570                   gGeoManager->MasterToTop(&fPoints[(ip+1)<<2], &seg[3]);
00571                   gPad->PaintLine3D(&seg[0], &seg[3]);
00572                }
00573             } else {
00574                gPad->PaintLine3D(start, &fPoints[(imin+1)<<2]);
00575                for (ip=imin+1; ip<np-2; ip++) {
00576                   gPad->PaintLine3D(&fPoints[ip<<2], &fPoints[(ip+1)<<2]);
00577                }
00578             }   
00579          }
00580       } else {
00581          imax = GetPoint(tmax, end);
00582          if (imax<0 || imax>=(np-1)) return;
00583          // we have to draw just the end of the track    
00584          TAttLine::Modify();
00585          if (convert) {
00586             for (ip=0; ip<imax-1; ip++) {
00587                gGeoManager->MasterToTop(&fPoints[ip<<2], &seg[0]);
00588                gGeoManager->MasterToTop(&fPoints[(ip+1)<<2], &seg[3]);
00589                gPad->PaintLine3D(&seg[0], &seg[3]);
00590             }
00591          } else {      
00592             for (ip=0; ip<imax-1; ip++) {
00593                gPad->PaintLine3D(&fPoints[ip<<2], &fPoints[(ip+1)<<2]);
00594             }
00595          }        
00596          if (convert) {
00597             gGeoManager->MasterToTop(&fPoints[imax<<2], &seg[0]);
00598             gGeoManager->MasterToTop(end, &seg[3]);
00599             gPad->PaintLine3D(&seg[0], &seg[3]);
00600             PaintMarker(&seg[3]);
00601          } else {   
00602             gPad->PaintLine3D(&fPoints[imax<<2], end);
00603             PaintMarker(end);
00604          }   
00605       }
00606       TObject::SetBit(kGeoPDrawn);
00607       return;
00608    }         
00609    
00610    // paint all segments from track                   
00611    TObject::SetBit(kGeoPDrawn);
00612    TAttLine::Modify();  // change attributes if necessary
00613    for (ip=imin; ip<imax; ip++) {
00614       gPad->PaintLine3D(&fPoints[ip<<2], &fPoints[(ip+1)<<2]);
00615    }
00616 }
00617    
00618 //______________________________________________________________________________
00619 void TGeoTrack::Print(Option_t * /*option*/) const
00620 {
00621 // Print some info about the track.
00622    Int_t np = fNpoints>>2;
00623    printf(" TGeoTrack%6i : %s  ===============================\n", fId,GetName());
00624    printf("   parent =%6i    nd =%3i\n", (fParent)?fParent->GetId():-1, GetNdaughters());
00625    Double_t x,y,z,t;
00626    GetPoint(0,x,y,z,t);
00627    printf("   production vertex : (%g, %g, %g) at tof=%g\n", x,y,z,t);
00628    GetPoint(np-1,x,y,z,t);
00629    printf("   Npoints =%6i,  last : (%g, %g, %g) at tof=%g\n\n", np,x,y,z,t);
00630 }
00631 
00632 //______________________________________________________________________________
00633 Int_t TGeoTrack::Size(Int_t &imin, Int_t &imax)
00634 {
00635 // Return the number of points within the time interval specified by 
00636 // TGeoManager class and the corresponding indices.
00637    Double_t tmin, tmax;
00638    Int_t np = fNpoints>>2;
00639    imin = 0;
00640    imax = np-1;
00641    Int_t size = np;
00642    if (!gGeoManager->GetTminTmax(tmin, tmax)) return size;
00643    imin = SearchPoint(tmin);
00644    imax = SearchPoint(tmax, imin);
00645    return (imax-imin+1);
00646 }
00647    
00648 //______________________________________________________________________________
00649 Int_t TGeoTrack::SearchPoint(Double_t time, Int_t istart) const
00650 {
00651 // Search index of track point having the closest time tag smaller than
00652 // TIME. Optional start index can be provided.
00653    Int_t nabove, nbelow, middle, midloc;
00654    Int_t np = fNpoints>>2;
00655    nabove = np+1;
00656    nbelow = istart;
00657    while (nabove-nbelow > 1) {
00658       middle = (nabove+nbelow)/2;
00659       midloc = ((middle-1)<<2)+3;
00660       if (time == fPoints[midloc]) return middle-1;
00661       if (time < fPoints[midloc])  nabove = middle;
00662       else                         nbelow = middle;
00663    }
00664    return (nbelow-1);   
00665 }   
00666 
00667 //______________________________________________________________________________
00668 void TGeoTrack::SetBits(Bool_t is_default, Bool_t is_onelevel, 
00669                         Bool_t is_all, Bool_t is_type)
00670 {
00671 // Set drawing bits for this track
00672    TObject::SetBit(kGeoPDefault, is_default);
00673    TObject::SetBit(kGeoPOnelevel, is_onelevel);
00674    TObject::SetBit(kGeoPAllDaughters, is_all);
00675    TObject::SetBit(kGeoPType, is_type);
00676 }
00677 
00678 //______________________________________________________________________________
00679 void TGeoTrack::Sizeof3D() const
00680 {
00681 // Returns 3D size for the track.
00682 }   
00683 
00684 //______________________________________________________________________________
00685 void TGeoTrack::ResetTrack()
00686 {
00687 // Reset data for this track.
00688    fNpoints    = 0;   
00689    fPointsSize = 0;
00690    if (fTracks) {fTracks->Delete(); delete fTracks;}
00691    fTracks = 0;
00692    if (fPoints) delete [] fPoints;
00693    fPoints = 0;
00694 }   
00695 

Generated on Tue Jul 5 14:13:22 2011 for ROOT_528-00b_version by  doxygen 1.5.1