TEveBoxSet* boxset_single_color(Float_t x=0, Float_t y=0, Float_t z=0, Int_t num=100, Bool_t registerSet=kTRUE) { TEveManager::Create(); TRandom r(0); TEveBoxSet* q = new TEveBoxSet("BoxSet"); q->UseSingleColor(); q->SetMainColor(kCyan-2); q->SetMainTransparency(50); q->Reset(TEveBoxSet::kBT_AABox, kFALSE, 64); for (Int_t i=0; i<num; ++i) { q->AddBox(r.Uniform(-10, 10), r.Uniform(-10, 10), r.Uniform(-10, 10), r.Uniform(0.2, 1), r.Uniform(0.2, 1), r.Uniform(0.2, 1)); } q->RefitPlex(); TEveTrans& t = q->RefMainTrans(); t.SetPos(x, y, z); if (registerSet) { gEve->AddElement(q); gEve->Redraw3D(kTRUE); } return q; }
void Plot_Bend_SR_Cones(const Ntuple& nt,const Beam &Mach,const double zmin,const double zmax,const double Scale_xy,const unsigned int verbose,const bool goto_CM_units,const double sign) // see also ~/root_git_build/tutorials/eve/jetcone.C // -- draw tangential lines and SR cones towards z=0 w/o beam divergence, relevant for neutral tracking --- lines ok, cones shuld be improved // done here in TEve. Alternative could be to create each cone as a geometry which could be saved as and reloaded, to allow for individual colors, names .. { if(verbose) cout << __FILE__ << " " << __PRETTY_FUNCTION__ << " line " << __LINE__ << " Scale_xy=" << Scale_xy << endl; unsigned int n=nt.Noent(); vector<string> NameCol =nt.GetStrCol("NAME"); vector<string> KeywordCol=nt.GetStrCol("KEYWORD"); if(gEve==NULL) cout << " *** careful *** global gEve=" << gEve << " is not defined, some general features like setting colors may cause segmentation violation" << endl; // use two line sets, one for start and one for end of bend TEveStraightLineSet* eve_line_s = new TEveStraightLineSet("BendLines"); // can display lines together as set, but only save one by one seems http://root.cern.ch/root/html/TEveStraightLineSet.html TEveStraightLineSet* eve_line_e = new TEveStraightLineSet("BendLines"); // can display lines together as set, but only save one by one seems http://root.cern.ch/root/html/TEveStraightLineSet.html eve_line_s->SetLineWidth(2); eve_line_s->SetLineColor(kRed); // draw a red line from start of bend eve_line_e->SetLineWidth(2); eve_line_e->SetLineColor(kGreen); // draw a green line from end of bend double length=1; Plot_axis_arrow("x",length,Scale_xy,verbose); Plot_axis_arrow("y",length,Scale_xy,verbose); if(zmax>20) length=100; Plot_axis_arrow("z",length,Scale_xy,verbose); // PlotCone TEveStraightLineSet* eve_line_m = new TEveStraightLineSet("BendLines"); // middle vector eve_line_m->SetLineWidth(1); eve_line_m->SetLineColor(kGray); eve_line_m->SetLineStyle(7); // https://root.cern.ch/root/html/TAttLine.html use 7 to get dashed 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]); const valarray<double> angle=nt.GetVar("ANGLE"); const valarray<double> theta=nt.GetVar("THETA"); const valarray<double> phi=nt.GetVar("PHI"); const valarray<double> psi=nt.GetVar("PSI"); const valarray<double> EcritBend=nt.GetVar("EcritBend"); const valarray<double> ngamBend=nt.GetVar("ngamBend"); Vec3 z_unit_vec(0,0,1); if(sign<0) z_unit_vec=-1.*z_unit_vec; // (0,0,-1) if(verbose) cout << __FILE__ << " " << __FUNCTION__ << " line " << __LINE__ << setprecision(3) << " n=" << n << " yvec.size()=" << yvec.size() << '\n'; for(unsigned int i=1; i<n; ++i) // loop over elements { if(KeywordCol[i].find("BEND") !=string::npos) // sbend or rbend { Vec3 p0_s(xvec[i-1],yvec[i-1],zvec[i-1]); // Start of beand from previous element, ordered by increasing s Vec3 p0_e( xvec[i], yvec[i], zvec[i]); // End of bend if(verbose>1) cout << __FILE__ << " " << __FUNCTION__ << " line " << __LINE__ << " i=" << i << " zvec[i]=" << zvec[i] << '\n'; if(zvec[i] > zmin && zvec[i] < zmax) // in z within range { // power double U0=ngamBend[i]*MeanSyn*EcritBend[i]; double PowBend=Mach.ibeam*1.e9*U0; //---- cone declaration --- here in loop to get separate cones -- change color.. TEveBoxSet* cones = new TEveBoxSet(NameCol[i].c_str()); // see http://root.cern.ch/root/html/TEveBoxSet.html $EDITOR $ROOTSYS/tutorials/eve/boxset_cones.C // cones->SetPickable(kTRUE); cones->UseSingleColor(); // seems needed for Transparency, do not make shape too flat, then always grey cones->SetMainColor(kGreen); // see $EDITOR ~/root_git/include/root/TEveDigitSet.h ~/root_git/src/graf3d/eve/src/TEveDigitSet.cxx void DigitColor(Color_t ci, Char_t transparency); https://root.cern.ch/root/html/TColor.html Char_t MaxTransp=99; // seen in boxset.C boxset_single_color 50 is half transparent, 90 is very transparent https://root.cern.ch/root/html/TEveElement.html Char_t DeltaTransp=1; cones->SetMainTransparency(MaxTransp); if(PowBend>1.e1) { cones->SetMainTransparency(MaxTransp-1*DeltaTransp); } if(PowBend>1.e2) { cones->SetMainTransparency(MaxTransp-2*DeltaTransp); } if(PowBend>1.e3) { cones->SetMainTransparency(MaxTransp-3*DeltaTransp); cones->SetMainColor(kRed-2); } if(PowBend>1.e4) { cones->SetMainTransparency(MaxTransp-4*DeltaTransp); cones->SetMainColor(kRed-3); } if(PowBend>1.e5) { cones->SetMainTransparency(MaxTransp-5*DeltaTransp); cones->SetMainColor(kRed-4); } cones->Reset(TEveBoxSet::kBT_EllipticCone, kFALSE, 64); // EllipticCone //----- Mat3x3 WCS_s(WCS_mat3(theta[i-1],phi[i-1],psi[i-1])); // matrix, bend start Mat3x3 WCS_e(WCS_mat3(theta[i], phi[i], psi[i])); // matrix, bend end Vec3 dirvec_s=WCS_s*z_unit_vec; // tanget bend start Vec3 dirvec_e=WCS_e*z_unit_vec; // tanget bend end if(verbose>1) cout << left << setw(12) << NameCol[i] << setw(6) << " zvec[i]=" << setw(6) << zvec[i] << " dirvec_s " << dirvec_s.Print() << '\n' << WCS_s.Print(); if(verbose>1) cout << left << setw(12) << NameCol[i] << setw(6) << " zvec[i]=" << setw(6) << zvec[i] << " dirvec_e " << dirvec_e.Print() << '\n' << WCS_e.Print(); Vec3 p1_s=p0_s+dirvec_s; // start bend vector + direction unit vector Vec3 p1_e=p0_e+dirvec_e; // end bend vector + direction unit vector double len_s=1; double len_e=1; if(fabs(p1_e.r[2])<fabs(p0_e.r[2])) // get length to reach to 0 in z { len_s=fabs(p0_s.r[2]/(p1_s.r[2]-p0_s.r[2])); len_e=fabs(p0_e.r[2]/(p1_e.r[2]-p0_e.r[2])); if(verbose>1) cout << " pointing in z to 0 len_s=" << setw(10) << len_s << " p1_s.r[2]-p0_s.r[2]= " << setw(10) << p1_s.r[2]-p0_s.r[2] << '\n'; if(verbose>1) cout << " pointing in z to 0 len_e=" << setw(10) << len_e << " p1_e.r[2]-p0_e.r[2]= " << setw(10) << p1_e.r[2]-p0_e.r[2] << '\n'; } p1_s=p0_s+len_s*dirvec_s; p1_e=p0_e+len_e*dirvec_e; if(verbose) cout << setw(5) << i << setw(15) << NameCol[i-1] << " line from " << p0_s.Print() << " to " << p1_s.Print() << " theta=" << setw(12) << theta[i-1] << '\n'; if(verbose) cout << setw(5) << i << setw(15) << NameCol[i] << " line from " << p0_e.Print() << " to " << p1_e.Print() << " theta=" << setw(12) << theta[i] << '\n'; if(fabs(p1_e.r[0])> zmax) { if(verbose) cout << " x1=p1_e.r[0]=" << p1_e.r[0] << " larger than zmax=" << zmax << " skip" << '\n'; continue; } if(abs(p1_s)>zmax || abs(p1_e)>zmax) { if(verbose) cout << " abs(p1_s)=" << abs(p1_s) << " abs(p1_e)=" << abs(p1_e) << " too large, skip" << '\n'; continue; } // now Scale_xy p0_s.r[0]*=Scale_xy; p0_s.r[1]*=Scale_xy; p1_s.r[0]*=Scale_xy; p1_s.r[1]*=Scale_xy; p0_e.r[0]*=Scale_xy; p0_e.r[1]*=Scale_xy; p1_e.r[0]*=Scale_xy; p1_e.r[1]*=Scale_xy; Vec3 p0_m = 0.5*(p0_s+p0_e); // middle of magnet Vec3 v_s=(p1_s-p0_m); // from middle of magnet to left end of cone, same length as v_e Vec3 v_e= p1_e-p0_m; // from middle of magnet to right end of cone v_s=(len_e/len_s)*v_s; // same unscaled length as v_e if(verbose>1) cout << "p0_m magnet middle " << p0_m.Print() << '\n'; if(verbose>1) cout << "v_s to left end of cone " << v_s.Print() << " len=" << abs(v_s) << '\n'; if(verbose>1) cout << "v_e to right end of cone " << v_e.Print() << " len=" << abs(v_e) << '\n'; if(abs(v_s)>Scale_xy*zmax || abs(v_e)>Scale_xy*zmax) { if(verbose) cout << " abs(v_s)=" << abs(v_s) << " abs(v_e)=" << abs(v_e) << " too large, skip" << '\n'; continue; } // angle between vectors after scaling double cos_angle_cone=(v_s*v_e)/(abs(v_s)*abs(v_e)); double angle_cone=acos(cos_angle_cone); if(verbose) cout << " cos_angle_cone=" << cos_angle_cone << " angle_cone=" << angle_cone << " Scale_xy*angle[i]=" << Scale_xy*angle[i] << " v_s*v_e=" << v_s*v_e << " abs(v_s)=" << abs(v_s) << " abs(v_e)=" << abs(v_e) << " PowBend=" << PowerWithUnits(PowBend) << '\n' << '\n'; TEveVectorT<double> P0_s=to_TEveVector(p0_s), P1_s=to_TEveVector(p1_s); TEveVectorT<double> P0_e=to_TEveVector(p0_e), P1_e=to_TEveVector(p1_e); if(goto_CM_units) // change to CM just before plotting { P0_s*=100; P1_s*=100; P0_e*=100; P1_e*=100; } eve_line_s->AddLine( P0_s,P1_s); eve_line_e->AddLine( P0_e,P1_e); // draw also cones double cone_len=abs(v_s+v_e)/2; if(goto_CM_units) cone_len*=100; // middle vector TEveVectorT<double> P0_m=0.5*(P0_s +P0_e); TEveVectorT<double> P1_m=0.5*(P1_s +P1_e); // tricky part -- take simple approx eve_line_m->AddLine( P0_m,P1_s ); eve_line_m->AddLine( P0_m,P1_e ); eve_line_m->AddLine( P0_m,P1_m ); double r1=angle_cone*cone_len/2; double r2=r1/10; // color effects better visible when not too small cones->AddEllipticCone(P0_m,P1_m-P0_m,r1,r2,0); gEve->AddElement(cones); } } } gEve->AddElement(eve_line_s); // show start lines gEve->AddElement(eve_line_e); // show end lines gEve->AddElement(eve_line_m); // show middle lines gEve->Redraw3D(kTRUE); PlotGuidesAtOrigin(); }