void compound() { TEveManager::Create(); TEveLine* ml = new TEveLine; ml->SetMainColor(kRed); ml->SetLineStyle(2); ml->SetLineWidth(3); gEve->InsertVizDBEntry("BigLine", ml); TEveCompound* cmp = new TEveCompound; cmp->SetMainColor(kGreen); gEve->AddElement(cmp); TRandom rnd(0); cmp->OpenCompound(); cmp->AddElement(random_line(rnd, 20, 10)); cmp->AddElement(random_line(rnd, 20, 10)); TEveLine* line = random_line(rnd, 20, 12); line->ApplyVizTag("BigLine"); cmp->AddElement(line); cmp->CloseCompound(); // Projected view TEveViewer *viewer = gEve->SpawnNewViewer("Projected"); TEveScene *scene = gEve->SpawnNewScene("Projected Event"); viewer->AddScene(scene); { TGLViewer* v = viewer->GetGLViewer(); v->SetCurrentCamera(TGLViewer::kCameraOrthoXOY); } // projections TEveProjectionManager* mng = new TEveProjectionManager(TEveProjection::kPT_RPhi); scene->AddElement(mng); TEveProjectionAxes* axes = new TEveProjectionAxes(mng); scene->AddElement(axes); gEve->AddToListTree(axes, kTRUE); gEve->AddToListTree(mng, kTRUE); mng->ImportElements(cmp); gEve->Redraw3D(kTRUE); }
TEveLine* random_line(TRandom& rnd, Int_t n, Float_t delta) { TEveLine* line = new TEveLine; line->SetMainColor(kGreen); Float_t x = 0, y = 0, z = 0; for (Int_t i=0; i<n; ++i) { line->SetNextPoint(x, y, z); x += rnd.Uniform(0, delta); y += rnd.Uniform(0, delta); z += rnd.Uniform(0, delta); } return line; }
void projection() { TFile::SetCacheFileDir("."); TEveManager::Create(); // camera TEveScene* s = gEve->SpawnNewScene("Projected Event"); gEve->GetDefaultViewer()->AddScene(s); TGLViewer* v = gEve->GetDefaultGLViewer(); v->SetCurrentCamera(TGLViewer::kCameraOrthoXOY); TGLOrthoCamera* cam = (TGLOrthoCamera*) v->CurrentCamera(); cam->SetZoomMinMax(0.2, 20); // projections TEveProjectionManager* mng = new TEveProjectionManager(TEveProjection::kPT_RPhi); s->AddElement(mng); TEveProjectionAxes* axes = new TEveProjectionAxes(mng); axes->SetTitle("TEveProjections demo"); s->AddElement(axes); gEve->AddToListTree(axes, kTRUE); gEve->AddToListTree(mng, kTRUE); // Simple geometry TFile* geom = TFile::Open(esd_geom_file_name, "CACHEREAD"); if (!geom) return; TEveGeoShapeExtract* gse = (TEveGeoShapeExtract*) geom->Get("Gentle"); TEveGeoShape* gsre = TEveGeoShape::ImportShapeExtract(gse, 0); geom->Close(); delete geom; gsre->SetPickableRecursively(kTRUE); gEve->AddGlobalElement(gsre); gEve->GetGlobalScene()->SetRnrState(kFALSE); mng->ImportElements(gsre); TEveLine* line = new TEveLine; line->SetMainColor(kGreen); for (Int_t i=0; i<160; ++i) line->SetNextPoint(120*sin(0.2*i), 120*cos(0.2*i), 80-i); gEve->AddElement(line); mng->ImportElements(line); line->SetRnrSelf(kFALSE); gEve->Redraw3D(kTRUE); }
void EveSingleTrackDisplay(const Ntuple& nt,const double zmin,const double zmax,const unsigned int color,const double Scale_xy,unsigned int verbose) // use euclidian coordinates X_2, Y_2, Z_2 if available, x,y, z or s otherwise // zmin, zmax -- tricky for rings, check also x not to jump to other side // // using root global gEve // // with TEveLine as in tutorial compound.C // // TEve has concept of tracks with vertex, momentum and optional reference points, maybe overkill // en->ExpandIntoListTreesRecursively(); // TEveTrackList *gTrackList = new TEveTrackList("MyTracks"); // cout << " gTrackList=" << gTrackList << " defined" << '\n'; // { bool goto_CM_units=true; if(verbose) cout << __FILE__ << " " << __PRETTY_FUNCTION__ << " line " << __LINE__ << " start verbose=" << verbose << " nt.Noent()=" << nt.Noent() << " Scale_xy=" << Scale_xy << " goto_CM_units=" << goto_CM_units << '\n'; bool SaveTrack=true; if(gEve==NULL) { cout << "*** Error *** Eve not setup. Do first StartEveWithGeomDisplay" << '\n'; return; } string dir,fname; string full_ntuple_fname=nt.GetFname(); GetDirFname(full_ntuple_fname,dir,fname); string fname_no_ext=WithoutExtension(fname); cout << "now plot track file with fname_no_ext=" << fname_no_ext << '\n'; unsigned int n=nt.Noent(); double xt[n],yt[n],zt[n]; const vector<const char*> koord =GetKoordNames(nt);; const valarray<double> xvec=nt.GetVar(koord[0]); const valarray<double> yvec=nt.GetVar(koord[1]); const valarray<double> zvec=nt.GetVar(koord[2]); vector<int> iElList; // http://www.cplusplus.com/reference/vector/vector/ // find elements in allowed z range, tricky in rings, check also for x not to jumo to other side double zstart=0; if(zmin<0) // start on negative side, go to zero { for(unsigned int i=0;i<nt.Noent();++i) if(zvec[i] < zstart && zvec[i] >= zmin && fabs(xvec[i])< zmax ) iElList.push_back(i); zstart=1.e-10; // put to some positive small value, to avoid to plot the zero point again on the positive side } // now the positive side for(unsigned int i=0;i<nt.Noent();++i) if(zvec[i] >= zstart && fabs(xvec[i])< zmax ) { iElList.push_back(i); if(zvec[i] >= zmax) break; } for(unsigned int i=0; i<n; ++i) xt[i]=Scale_xy*xvec[i]; for(unsigned int i=0; i<n; ++i) yt[i]=Scale_xy*yvec[i]; for(unsigned int i=0; i<n; ++i) zt[i]= zvec[i]; // order in increasing z if(verbose) cout << __FILE__ << " " << __PRETTY_FUNCTION__ << " line " << __LINE__ << " goto_CM_units=" << goto_CM_units << " zmin=" << zmin << " zmax=" << zmax << '\n'; TEveLine* line = new TEveLine(fname_no_ext.c_str()); // give the line the name of the track file line->SetMainColor(kBlack); for(unsigned int j=0;j<iElList.size();++j) // --- loop over elements and plot range { unsigned int i=iElList[j]; //if(zt[i]>=zmin && zt[i]<=zmax && fabs(xt[i])< zmax) // draw //{ if(verbose>1 && i<1000) cout << " j=" << setw(3) << j << " i=" << setw(3) << i << " x=" << setw(12) << xt[i] << " y=" << setw(12) << yt[i] << " z=" << setw(10) << zt[i] << '\n'; if(goto_CM_units) { xt[i]*=100; yt[i]*=100; zt[i]*=100; } // unit change only just before drawing with SetNextPoint line->SetNextPoint(xt[i],yt[i],zt[i]); //} } if(verbose>1) cout << __FILE__ << " " << __PRETTY_FUNCTION__ << " line " << __LINE__ << '\n'; gEve->AddElement(line); if(SaveTrack) // save track in root format - such that it can be read without need for my root extensions { // http://root.cern.ch/drupal/content/how-read-objects-file string line_fname=WithoutExtension(fname)+string(".root"); // http://root.cern.ch/root/html/TGObject.html if(verbose) cout << __FILE__ << " " << __PRETTY_FUNCTION__ << " line " << __LINE__ << " line->SaveAs(" << line_fname << ")" << '\n'; line->SaveAs(line_fname.c_str()); // TEveLine::SaveAs where is this ? cd /opt/local/include/root ; find . -type f -exec cat {} \; | grep -R SaveAs } if(verbose>2) cout << __FILE__ << " " << __PRETTY_FUNCTION__ << " line " << __LINE__ << " before gEve->Redraw3D()"<< '\n'; gEve->Redraw3D(); if(verbose>2) cout << __FILE__ << " " << __PRETTY_FUNCTION__ << " line " << __LINE__ << " after gEve->Redraw3D()"<< '\n'; }