int x3d( TString cut, int showFlag ) { // Retrieve trees and apply cut TFile* alignedFile = new TFile("aligned.root"); TTree* tmpTree = (TTree*)alignedFile->Get("theTree"); TTree* alignedTree = (TTree*)tmpTree->CopyTree(cut); TFile* misalignedFile = new TFile("misaligned.root"); tmpTree = (TTree*)misalignedFile->Get("theTree"); TTree* misalignedTree = (TTree*)tmpTree->CopyTree(cut); // Set tree branches float x,y,z,phi,theta,length,thick,width; float mx,my,mz,mphi,mtheta,mlength,mthick,mwidth; TRotMatrix* rot; TRotMatrix* mrot; double rad2deg = 180./3.1415926; alignedTree->SetBranchAddress( "x", &x ); alignedTree->SetBranchAddress( "y", &y ); alignedTree->SetBranchAddress( "z", &z ); alignedTree->SetBranchAddress( "phi", &phi ); alignedTree->SetBranchAddress( "theta", &theta ); alignedTree->SetBranchAddress( "length", &length ); alignedTree->SetBranchAddress( "width", &width ); alignedTree->SetBranchAddress( "thick", &thick ); alignedTree->SetBranchAddress( "rot", &rot ); misalignedTree->SetBranchAddress( "x", &mx ); misalignedTree->SetBranchAddress( "y", &my ); misalignedTree->SetBranchAddress( "z", &mz ); misalignedTree->SetBranchAddress( "phi", &mphi ); misalignedTree->SetBranchAddress( "theta", &mtheta ); misalignedTree->SetBranchAddress( "length", &mlength ); misalignedTree->SetBranchAddress( "width", &mwidth ); misalignedTree->SetBranchAddress( "thick", &mthick ); misalignedTree->SetBranchAddress( "rot", &mrot ); // Create canvas TCanvas* c1 = new TCanvas("c1","Detector units", 200, 10, 700, 500); c1->cd(); TBRIK* IP = new TBRIK("IP","IP","void",0.,0.,0.); TNode* rootNode = new TNode("Root","Root","IP",0.,0.,0.); rootNode->cd(); int entry = 0; while ( alignedTree->GetEntry(entry) && misalignedTree->GetEntry(entry) ) { entry++; std::ostringstream name; // Aligned detector name << "aBrik" << entry; TBRIK* aBrik = new TBRIK(name.str().c_str(),"Aligned detector unit","void", 0.01,0.01,length); aBrik->SetLineColor(4); // Detector node (position and orientation) name.str("aNode"); name << entry; TNode* aNode = new TNode(name.str().c_str(),name.str().c_str(),aBrik,x,y,z); // Misaligned detector name.str("mBrik"); name << entry; TBRIK* mBrik = new TBRIK(name.str().c_str(),"Misaligned detector unit","void", 0.01,0.01,mlength); mBrik->SetLineColor(2); // Detector node (position and orientation) name.str("mNode"); name << entry; TNode* mNode = new TNode(name.str().c_str(),name.str().c_str(),mBrik,mx,my,mz); //if (entry>5) break; } rootNode->cd(); rootNode->Draw(); c1->GetViewer3D(); return 0; }
void shapes() { //The old geometry shapes (see script geodemo.C) //To see the output of this macro, click begin_html <a href="gif/shapes.gif" >here</a> end_html //Author: Rene Brun TCanvas *c1 = new TCanvas("glc1","Geometry Shapes",200,10,700,500); //delete previous geometry objects in case this script is reexecuted if (gGeometry) { gGeometry->GetListOfNodes()->Delete(); gGeometry->GetListOfShapes()->Delete(); } // Define some volumes TBRIK *brik = new TBRIK("BRIK","BRIK","void",200,150,150); TTRD1 *trd1 = new TTRD1("TRD1","TRD1","void",200,50,100,100); TTRD2 *trd2 = new TTRD2("TRD2","TRD2","void",200,50,200,50,100); TTRAP *trap = new TTRAP("TRAP","TRAP","void",190,0,0,60,40,90,15,120,80,180,15); TPARA *para = new TPARA("PARA","PARA","void",100,200,200,15,30,30); TGTRA *gtra = new TGTRA("GTRA","GTRA","void",390,0,0,20,60,40,90,15,120,80,180,15); TTUBE *tube = new TTUBE("TUBE","TUBE","void",150,200,400); TTUBS *tubs = new TTUBS("TUBS","TUBS","void",80,100,100,90,235); TCONE *cone = new TCONE("CONE","CONE","void",100,50,70,120,150); TCONS *cons = new TCONS("CONS","CONS","void",50,100,100,200,300,90,270); TSPHE *sphe = new TSPHE("SPHE","SPHE","void",25,340, 45,135, 0,270); TSPHE *sphe1 = new TSPHE("SPHE1","SPHE1","void",0,140, 0,180, 0,360); TSPHE *sphe2 = new TSPHE("SPHE2","SPHE2","void",0,200, 10,120, 45,145); TPCON *pcon = new TPCON("PCON","PCON","void",180,270,4); pcon->DefineSection(0,-200,50,100); pcon->DefineSection(1,-50,50,80); pcon->DefineSection(2,50,50,80); pcon->DefineSection(3,200,50,100); TPGON *pgon = new TPGON("PGON","PGON","void",180,270,8,4); pgon->DefineSection(0,-200,50,100); pgon->DefineSection(1,-50,50,80); pgon->DefineSection(2,50,50,80); pgon->DefineSection(3,200,50,100); // Set shapes attributes brik->SetLineColor(1); trd1->SetLineColor(2); trd2->SetLineColor(3); trap->SetLineColor(4); para->SetLineColor(5); gtra->SetLineColor(7); tube->SetLineColor(6); tubs->SetLineColor(7); cone->SetLineColor(2); cons->SetLineColor(3); pcon->SetLineColor(6); pgon->SetLineColor(2); sphe->SetLineColor(kRed); sphe1->SetLineColor(kBlack); sphe2->SetLineColor(kBlue); // Build the geometry hierarchy TNode *node1 = new TNode("NODE1","NODE1","BRIK"); node1->cd(); TNode *node2 = new TNode("NODE2","NODE2","TRD1",0,0,-1000); TNode *node3 = new TNode("NODE3","NODE3","TRD2",0,0,1000); TNode *node4 = new TNode("NODE4","NODE4","TRAP",0,-1000,0); TNode *node5 = new TNode("NODE5","NODE5","PARA",0,1000,0); TNode *node6 = new TNode("NODE6","NODE6","TUBE",-1000,0,0); TNode *node7 = new TNode("NODE7","NODE7","TUBS",1000,0,0); TNode *node8 = new TNode("NODE8","NODE8","CONE",-300,-300,0); TNode *node9 = new TNode("NODE9","NODE9","CONS",300,300,0); TNode *node10 = new TNode("NODE10","NODE10","PCON",0,-1000,-1000); TNode *node11 = new TNode("NODE11","NODE11","PGON",0,1000,1000); TNode *node12 = new TNode("NODE12","NODE12","GTRA",0,-400,700); TNode *node13 = new TNode("NODE13","NODE13","SPHE",10,-400,500); TNode *node14 = new TNode("NODE14","NODE14","SPHE1",10, 250,300); TNode *node15 = new TNode("NODE15","NODE15","SPHE2",10,-100,-200); // Draw this geometry in the current canvas node1->cd(); node1->Draw("gl"); c1->Update(); // // Draw the geometry using the OpenGL viewver. // Note that this viewver may also be invoked from the "View" menu in // the canvas tool bar // // once in the viewer, select the Help button // For example typing r will show a solid model of this geometry. }
void shapesAnim() { TCanvas *c1 = new TCanvas("c1","Geometry Shapes",10,10,500,500); // Define some volumes TBRIK *brik = new TBRIK("BRIK","BRIK","void",200,150,150); TTRD1 *trd1 = new TTRD1("TRD1","TRD1","void",200,50,100,100); TTRD2 *trd2 = new TTRD2("TRD2","TRD2","void",200,50,200,50,100); TTRAP *trap = new TTRAP("TRAP","TRAP","void",190,0,0,60,40,90,15,120,80,180,15); TPARA *para = new TPARA("PARA","PARA","void",100,200,200,15,30,30); TGTRA *gtra = new TGTRA("GTRA","GTRA","void",390,0,0,20,60,40,90,15,120,80,180,15); TTUBE *tube = new TTUBE("TUBE","TUBE","void",150,200,400); TTUBS *tubs = new TTUBS("TUBS","TUBS","void",80,100,100,90,235); TCONE *cone = new TCONE("CONE","CONE","void",100,50,70,120,150); TCONS *cons = new TCONS("CONS","CONS","void",50,100,100,200,300,90,270); TSPHE *sphe = new TSPHE("SPHE","SPHE","void",25,340, 45,135, 0,270); TSPHE *sphe1 = new TSPHE("SPHE1","SPHE1","void",0,140, 0,180, 0,360); TSPHE *sphe2 = new TSPHE("SPHE2","SPHE2","void",0,200, 10,120, 45,145); TPCON *pcon = new TPCON("PCON","PCON","void",180,270,4); pcon->DefineSection(0,-200,50,100); pcon->DefineSection(1,-50,50,80); pcon->DefineSection(2,50,50,80); pcon->DefineSection(3,200,50,100); TPGON *pgon = new TPGON("PGON","PGON","void",180,270,8,4); pgon->DefineSection(0,-200,50,100); pgon->DefineSection(1,-50,50,80); pgon->DefineSection(2,50,50,80); pgon->DefineSection(3,200,50,100); // Set shapes attributes brik->SetLineColor(1); trd1->SetLineColor(2); trd2->SetLineColor(3); trap->SetLineColor(4); para->SetLineColor(5); gtra->SetLineColor(7); tube->SetLineColor(6); tubs->SetLineColor(7); cone->SetLineColor(2); cons->SetLineColor(3); pcon->SetLineColor(6); pgon->SetLineColor(2); sphe->SetLineColor(kRed); sphe1->SetLineColor(kBlack); sphe2->SetLineColor(kBlue); // Build the geometry hierarchy TNode *node1 = new TNode("NODE1","NODE1","BRIK"); node1->cd(); TNode *node2 = new TNode("NODE2","NODE2","TRD1",0,0,-1000); TNode *node3 = new TNode("NODE3","NODE3","TRD2",0,0,1000); TNode *node4 = new TNode("NODE4","NODE4","TRAP",0,-1000,0); TNode *node5 = new TNode("NODE5","NODE5","PARA",0,1000,0); TNode *node6 = new TNode("NODE6","NODE6","TUBE",-1000,0,0); TNode *node7 = new TNode("NODE7","NODE7","TUBS",1000,0,0); TNode *node8 = new TNode("NODE8","NODE8","CONE",-300,-300,0); TNode *node9 = new TNode("NODE9","NODE9","CONS",300,300,0); TNode *node10 = new TNode("NODE10","NODE10","PCON",0,-1000,-1000); TNode *node11 = new TNode("NODE11","NODE11","PGON",0,1000,1000); TNode *node12 = new TNode("NODE12","NODE12","GTRA",0,-400,700); TNode *node13 = new TNode("NODE13","NODE13","SPHE",10,-400,500); TNode *node14 = new TNode("NODE14","NODE14","SPHE1",10, 250,300); TNode *node15 = new TNode("NODE15","NODE15","SPHE2",10,-100,-200); // Draw this geometry in the current canvas node1->cd(); node1->Draw(); c1->Update(); //start a Timer TTimer *timer = new TTimer(20); timer->SetCommand("Animate()"); timer->TurnOn(); }
void xtruSamples() { // Draw a sample of TXTRU shapes some convex, concave (and possibly malformed) // Change Bool_t's to test alternative specifications // Author: Robert Hatcher ([email protected]) 2000.09.06 // One normally specifies the x-y points in counter-clockwise order; // flip this to TRUE to test that it doesn't matter. Bool_t makecw = kFALSE; // One normally specifies the z points in increasing z order; // flip this to TRUE to test that it doesn't matter. Bool_t reversez = kFALSE; // One shouldn't be creating malformed polygons // but to test what happens when one does here's a flag. // The effect will be only apparent in solid rendering mode Bool_t domalformed = kFALSE; // domalformed = kTRUE; c1 = new TCanvas("c1","sample TXTRU Shapes",200,10,640,640); // Create a new geometry TGeometry* geom = new TGeometry("sample","sample"); geom->cd(); // Define the complexity of the drawing Float_t zseg = 6; // either 2 or 6 Int_t extravis = 0; // make extra z "arrow" visible Float_t unit = 1; // Create a large BRIK to embed things into Float_t bigdim = 12.5*unit; TBRIK* world = new TBRIK("world","world","void",bigdim,bigdim,bigdim); // Create the main node, make it invisible TNode* worldnode = new TNode("worldnode","world node",world); worldnode->SetVisibility(0); worldnode->cd(); // Canonical shape ... gets further modified by scale factors // to create convex (and malformed) versions Float_t x[] = { -0.50, -1.20, 1.20, 0.50, 0.50, 1.20, -1.20, -0.50 }; Float_t y[] = { -0.75, -2.00, -2.00, -0.75, 0.75, 2.00, 2.00, 0.75 }; Float_t z[] = { -0.50, -1.50, -1.50, 1.50, 1.50, 0.50 }; Float_t s[] = { 0.50, 1.00, 1.50, 1.50, 1.00, 0.50 }; Int_t nxy = sizeof(x)/sizeof(Float_t); Float_t convexscale[] = { 7.0, -1.0, 1.5 }; Int_t icolor[] = { 1, 2, 3, 2, 2, 2, 4, 2, 6 }; // xycase and zcase: 0=convex, 1=malformed, 2=concave // this will either create a 2x2 matrix of shapes // or a 3x3 array (if displaying malformed versions) for (Int_t zcase = 0; zcase<3; zcase++) { if (zcase == 1 && !domalformed) continue; for (Int_t xycase = 0; xycase<3; xycase++) { if (xycase == 1 && !domalformed) continue; Char_t *name = "txtruXYZ"; sprintf(name,"txtru%1d%1d%1d",xycase,zcase,zseg); TXTRU* mytxtru = new TXTRU(name,name,"void",8,2); Int_t i, j; Float_t xsign = (makecw) ? -1 : 1; Float_t zsign = (reversez) ? -1 : 1; // set the vertex points for (i=0; i<nxy; i++) { Float_t xtmp = x[i]*xsign; Float_t ytmp = y[i]; if (i==0||i==3||i==4||i==7) xtmp *= convexscale[xycase]; if (xycase==2) xtmp *=2; mytxtru->DefineVertex(i,xtmp,ytmp); } // set the z segment positions and scales for (i=0, j=0; i<zseg; i++) { Float_t ztmp = z[i]*zsign; if (i==0||i==5) ztmp *= convexscale[zcase]; if (zcase==2) ztmp *= 2.5; if (zseg>2 && zcase!=2 && (i==1||i==4)) continue; mytxtru->DefineSection(j,ztmp,s[i]); j++; } TNode* txtrunode = new TNode(name,name,mytxtru); txtrunode->SetLineColor(icolor[3*zcase+xycase]); Float_t pos_scale = (domalformed) ? 10 : 6; Float_t xpos = (xycase-1)*pos_scale*unit; Float_t ypos = (zcase-1)*pos_scale*unit; txtrunode->SetPosition(xpos,ypos,0.); } } // Some extra shapes to show the direction of "z" Float_t zhalf = 0.5*bigdim; Float_t rmax = 0.03*bigdim; TCONE* zcone = new TCONE("zcone","zcone","void",zhalf,0.,rmax,0.,0.); zcone->SetVisibility(extravis); TNode* zconenode = new TNode("zconenode","zconenode",zcone); zconenode->SetLineColor(3); Float_t dzstub = 2*rmax; TBRIK* zbrik = new TBRIK("zbrik","zbrik","void",rmax,rmax,dzstub); zbrik->SetVisibility(extravis); TNode* zbriknode = new TNode("zbriknode","zbriknode",zbrik); zbriknode->SetPosition(0.,0.,zhalf+dzstub); zbriknode->SetLineColor(3); // geom->ls(); geom->Draw(); // Tweak the pad so that it displays the entire geometry undistorted TVirtualPad *thisPad = gPad; if (thisPad) { TView *view = thisPad->GetView(); if (!view) return; Double_t min[3],max[3],center[3]; view->GetRange(min,max); int i; // Find the boxed center for (i=0;i<3; i++) center[i] = 0.5*(max[i]+min[i]); Double_t maxSide = 0; // Find the largest side for (i=0;i<3; i++) maxSide = TMath::Max(maxSide,max[i]-center[i]); file://Adjust scales: for (i=0;i<3; i++) { max[i] = center[i] + maxSide; min[i] = center[i] - maxSide; } view->SetRange(min,max); thisPad->Modified(); thisPad->Update(); } }
void GetVertexes() { TIVShape::V[0][0] = -Brik->GetDx(); TIVShape::V[0][1] = -Brik->GetDy(); TIVShape::V[0][2] = -Brik->GetDz(); TIVShape::V[1][0] = Brik->GetDx(); TIVShape::V[1][1] = -Brik->GetDy(); TIVShape::V[1][2] = -Brik->GetDz(); TIVShape::V[2][0] = -Brik->GetDx(); TIVShape::V[2][1] = -Brik->GetDy(); TIVShape::V[2][2] = Brik->GetDz(); TIVShape::V[3][0] = Brik->GetDx(); TIVShape::V[3][1] = -Brik->GetDy(); TIVShape::V[3][2] = Brik->GetDz(); TIVShape::V[4][0] = -Brik->GetDx(); TIVShape::V[4][1] = Brik->GetDy(); TIVShape::V[4][2] = -Brik->GetDz(); TIVShape::V[5][0] = Brik->GetDx(); TIVShape::V[5][1] = Brik->GetDy(); TIVShape::V[5][2] = -Brik->GetDz(); TIVShape::V[6][0] = -Brik->GetDx(); TIVShape::V[6][1] = Brik->GetDy(); TIVShape::V[6][2] = Brik->GetDz(); TIVShape::V[7][0] = Brik->GetDx(); TIVShape::V[7][1] = Brik->GetDy(); TIVShape::V[7][2] = Brik->GetDz(); }