const MaterialVec&MaterialManager:: materialsBetween(const DDSurfaces::Vector3D& p0, const DDSurfaces::Vector3D& p1 , double epsilon) { if( ( p0 != _p0 ) || ( p1 != _p1 ) ) { //--------------------------------------- _mV.clear() ; // // algorithm copied from TGeoGearDistanceProperties.cc (A.Munnich): // double startpoint[3], endpoint[3], direction[3]; double L=0; for(unsigned int i=0; i<3; i++) { startpoint[i] = p0[i]; endpoint[i] = p1[i]; direction[i] = endpoint[i] - startpoint[i]; L+=direction[i]*direction[i]; } double totDist = sqrt( L ) ; //normalize direction for(unsigned int i=0; i<3; i++) direction[i]=direction[i]/totDist; _tgeoMgr->AddTrack(0, 12 ) ; // electron neutrino TGeoNode *node1 = _tgeoMgr->InitTrack(startpoint, direction); //check if there is a node at startpoint if(!node1) throw std::runtime_error("No geometry node found at given location. Either there is no node placed here or position is outside of top volume."); while ( !_tgeoMgr->IsOutside() ) { // TGeoNode *node2; // TVirtualGeoTrack *track; // step to (and over) the next Boundary TGeoNode * node2 = _tgeoMgr->FindNextBoundaryAndStep( 500, 1) ; if( !node2 || _tgeoMgr->IsOutside() ) break; const double *position = _tgeoMgr->GetCurrentPoint(); const double *previouspos = _tgeoMgr->GetLastPoint(); double length = _tgeoMgr->GetStep(); TVirtualGeoTrack *track = _tgeoMgr->GetLastTrack(); //protection against infinitive loop in root which should not happen, but well it does... //work around until solution within root can be found when the step gets very small e.g. 1e-10 //and the next boundary is never reached #if 1 //fg: is this still needed ? if( length < MINSTEP ) { _tgeoMgr->SetCurrentPoint( position[0] + MINSTEP * direction[0], position[1] + MINSTEP * direction[1], position[2] + MINSTEP * direction[2] ); length = _tgeoMgr->GetStep(); node2 = _tgeoMgr->FindNextBoundaryAndStep(500, 1) ; position = _tgeoMgr->GetCurrentPoint(); previouspos = _tgeoMgr->GetLastPoint(); } #endif // printf( " -- step length : %1.8e %1.8e %1.8e %1.8e %1.8e %1.8e %1.8e - %s \n" , length , // position[0], position[1], position[2], previouspos[0], previouspos[1], previouspos[2] , node1->GetMedium()->GetMaterial()->GetName() ) ; DDSurfaces::Vector3D posV( position ) ; double currDistance = ( posV - p0 ).r() ; // //if the next boundary is further than end point // if(fabs(position[0])>fabs(endpoint[0]) || fabs(position[1])>fabs(endpoint[1]) // || fabs(position[2])>fabs(endpoint[2])) //if we travelled too far: if( currDistance > totDist ) { length = sqrt( pow(endpoint[0]-previouspos[0],2) + pow(endpoint[1]-previouspos[1],2) + pow(endpoint[2]-previouspos[2],2) ); track->AddPoint( endpoint[0], endpoint[1], endpoint[2], 0. ); if( length > epsilon ) _mV.push_back( std::make_pair( Material( node1->GetMedium() ) , length ) ) ; break; } track->AddPoint( position[0], position[1], position[2], 0.); if( length > epsilon ) _mV.push_back( std::make_pair( Material( node1->GetMedium() ), length ) ) ; node1 = node2 ; } //fg: protect against empty list: if( _mV.empty() ){ _mV.push_back( std::make_pair( Material( node1->GetMedium() ), totDist ) ) ; } _tgeoMgr->ClearTracks(); _tgeoMgr->CleanGarbage(); //--------------------------------------- _p0 = p0 ; _p1 = p1 ; } return _mV ; ; }
void MyTrack3D(const Ntuple& nt,Int_t PdgCode ,const double zmin,const double zmax,const unsigned int color,const double Scale_xy,unsigned int verbose) // fname like /Users/hbu/mad/lhc/twiss_track_ref/002_px_0b1.tfs event display in canvas, did not manage to get this in OpenGl with Geometry --- better got to Eve, see below { bool goto_CM_units=true; if(verbose) cout << __FILE__ << " " << __PRETTY_FUNCTION__ << " line " << __LINE__ << " start verbose=" << verbose << " nt.Noent()=" << nt.Noent() << " Scale_xy=" << Scale_xy << '\n'; if(gGeoManager==NULL) { cout << "No geometry defined to attach tracking" << '\n'; return; } unsigned int n=nt.Noent(); double xt[n],yt[n],zt[n],st[n]; valarray<double> xvec=nt.GetVar("X"); valarray<double> yvec=nt.GetVar("Y"); // valarray<double> zvec=nt.GetVar("Z"); valarray<double> svec=nt.GetVar("S"); for(unsigned int i=0; i<n; ++i) st[i]=svec[i]; for(unsigned int i=0; i<n; ++i) xt[i]=xvec[i]; for(unsigned int i=0; i<n; ++i) yt[i]=yvec[i]; for(unsigned int i=0; i<n; ++i) zt[i]=st[i]; // zvec[i]; // for the moment use s instead of z if(goto_CM_units) { for(unsigned int i=0; i<n; ++i) xt[i]*=100; for(unsigned int i=0; i<n; ++i) yt[i]*=100; for(unsigned int i=0; i<n; ++i) zt[i]*=100; } if(verbose) cout << __FILE__ << " " << __PRETTY_FUNCTION__ << " line " << __LINE__ << '\n'; Int_t itrk=0; TObject *particle=NULL; Int_t iPrimary = gGeoManager->AddTrack(itrk,PdgCode,particle); TVirtualGeoTrack *myTrack = gGeoManager->GetTrack(iPrimary); // keep link in class for(unsigned int i=0; i<n; ++i) { if(zt[i]>zmax) break; double tt=MyConstPhys::CLight*st[i]; if(verbose&&i<1000) cout << " i=" << setw(3) << i << " x=" << setw(12) << xt[i] << " y=" << setw(12) << yt[i] << " z=" << setw(10) << zt[i] << " tt=" << setw(10) << tt << '\n'; if(zt[i]>zmin) myTrack->AddPoint(xt[i],yt[i],zt[i],tt); } if(verbose) cout << __FILE__ << " " << __PRETTY_FUNCTION__ << " line " << __LINE__ << '\n'; myTrack->Print(); // myTrack->Draw(); // Draw("ogl") gGeoManager->GetTopVolume()->SetVisRaytrace(true); // switches to more solid view --- more similar to OpenGL if(verbose) cout << __FILE__ << " " << __PRETTY_FUNCTION__ << " line " << __LINE__ << '\n'; // gGeoManager->GetTopVolume()->Draw(); // shows geometry, but track not visible Draw("ogl") cout << " gGeoManager->GetNtracks()=" << gGeoManager->GetNtracks() << '\n'; // fNtracks // cout << " myTrack->GetNtracks()=" << myTrack->GetNtracks() << '\n'; // fNtracks // gGeoManager->DrawTracks(); // shows track in c1 after click in window, also tried with "ogl" which has not effect here if(verbose) cout << __FILE__ << " " << __PRETTY_FUNCTION__ << " line " << __LINE__ << '\n'; if (gROOT->GetListOfCanvases()->FindObject("c1")) cout << " UseGL()=" << ((TCanvas*)gROOT->GetListOfCanvases()->FindObject("c1"))->UseGL() << '\n'; // check if ogl on, still off // shows track after click in canvas window -- track immediately visible when not calling gGeoManager->GetTopVolume()->Draw(); after myTrack->Draw(); // gGeoManager->DrawTracks(); // shows track in c1 // myTrack->Clear(); // myTrack->Draw(); // track visible in 2 dim only }