Пример #1
0
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;
}
Пример #2
0
TEveBoxSet*
elliptic_boxset_cones(Float_t x=0, Float_t y=0, Float_t z=0,
                   Int_t num=100, Bool_t register=kTRUE)
{
  TEveManager::Create();

  using namespace TMath;

  TEveManager::Create();

  TEveStraightLineSet* lines = new TEveStraightLineSet("StraightLines");
  lines->SetLineColor(kYellow);
  lines->SetLineWidth(2);

  TRandom r(0);

  TEveBoxSet* cones = new TEveBoxSet("EllipticConeSet");
  cones->Reset(TEveBoxSet::kBT_EllipticCone, kTRUE, 64);

  cones->SetPickable(kTRUE);

  Float_t a = 40; // max distance between cones
  TEveVector dir, pos;
  Float_t theta, phi, height, rad;
  for (Int_t i=0; i<num; ++i)
  {
    theta  = r.Uniform(0,TMath::Pi());
    phi    = r.Uniform (-TMath::Pi(), TMath::Pi());
    height = r.Uniform(5, 15);
    rad    = r.Uniform(3, 5);
    dir.Set(Cos(phi)*Cos(theta), Sin(phi)*Cos(theta), Sin(theta));
    dir *= height;
    pos.Set(r.Uniform(-a,a), r.Uniform(-a, a), r.Uniform(-a, a));

    cones->AddEllipticCone(pos, dir, rad, 0.5*rad, r.Uniform(0,360));
    cones->DigitColor(r.Uniform(20, 255), r.Uniform(20, 255),
                      r.Uniform(20, 255), r.Uniform(20, 255));

    // draw axis line 30% longer than cone height
    TEveVector end = pos + dir*1.3f;
    lines->AddLine(pos.fX, pos.fY, pos.fZ, end.fX, end.fY, end.fZ);
  }

  // by default cone cap not drawn
  if (r.Integer(2)>0)  cones->SetDrawConeCap(kTRUE);

  cones->RefitPlex();
  TEveTrans& t = cones->RefMainTrans();
  t.SetPos(x, y, z);

  gEve->AddElement(cones);
  gEve->AddElement(lines);

  gEve->Redraw3D(kTRUE);

  return cones;
}
Пример #3
0
TEveBoxSet* boxset_colisval(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->Reset(TEveBoxSet::kBT_AABox, kTRUE, 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->DigitColor(r.Uniform(20, 255), r.Uniform(20, 255),
                    r.Uniform(20, 255), r.Uniform(20, 255));
   }
   q->RefitPlex();

   TEveTrans& t = q->RefMainTrans();
   t.SetPos(x, y, z);

   if (registerSet)
   {
      gEve->AddElement(q);
      gEve->Redraw3D(kTRUE);
   }

   return q;
}
Пример #4
0
TEveBoxSet* boxset(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);
   gStyle->SetPalette(1, 0);

   TEveRGBAPalette* pal = new TEveRGBAPalette(0, 130);

   TEveFrameBox* frm = new TEveFrameBox();
   frm->SetAABoxCenterHalfSize(0, 0, 0, 12, 12, 12);
   frm->SetFrameColor(kCyan);
   frm->SetBackColorRGBA(120,120,120,20);
   frm->SetDrawBack(kTRUE);

   TEveBoxSet* q = new TEveBoxSet("BoxSet");
   q->SetPalette(pal);
   q->SetFrame(frm);
   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->DigitValue(r.Uniform(0, 130));
   }
   q->RefitPlex();

   TEveTrans& t = q->RefMainTrans();
   t.SetPos(x, y, z);

   // Uncomment these two lines to get internal highlight / selection.
   // q->SetPickable(1);
   // q->SetAlwaysSecSelect(1);

   if (registerSet)
   {
      gEve->AddElement(q);
      gEve->Redraw3D(kTRUE);
   }

   return q;
}
Пример #5
0
TEveBoxSet* boxset_freebox(Int_t num=100, Bool_t registerSet=kTRUE)
{
   TEveManager::Create();

   TRandom r(0);
   gStyle->SetPalette(1, 0);

   TEveRGBAPalette* pal = new TEveRGBAPalette(0, 130);

   TEveBoxSet* q = new TEveBoxSet("BoxSet");
   q->SetPalette(pal);
   q->Reset(TEveBoxSet::kBT_FreeBox, kFALSE, 64);

#define RND_BOX(x) (Float_t)r.Uniform(-(x), (x))

   Float_t verts[24];
   for (Int_t i=0; i<num; ++i) {
      Float_t x = RND_BOX(10);
      Float_t y = RND_BOX(10);
      Float_t z = RND_BOX(10);
      Float_t a = r.Uniform(0.2, 0.5);
      Float_t d = 0.05;
      Float_t verts[24] = {
         x - a + RND_BOX(d), y - a + RND_BOX(d), z - a + RND_BOX(d),
         x - a + RND_BOX(d), y + a + RND_BOX(d), z - a + RND_BOX(d),
         x + a + RND_BOX(d), y + a + RND_BOX(d), z - a + RND_BOX(d),
         x + a + RND_BOX(d), y - a + RND_BOX(d), z - a + RND_BOX(d),
         x - a + RND_BOX(d), y - a + RND_BOX(d), z + a + RND_BOX(d),
         x - a + RND_BOX(d), y + a + RND_BOX(d), z + a + RND_BOX(d),
         x + a + RND_BOX(d), y + a + RND_BOX(d), z + a + RND_BOX(d),
         x + a + RND_BOX(d), y - a + RND_BOX(d), z + a + RND_BOX(d) };
      q->AddBox(verts);
      q->DigitValue(r.Uniform(0, 130));
   }
   q->RefitPlex();

#undef RND_BOX

   // Uncomment these two lines to get internal highlight / selection.
   // q->SetPickable(1);
   // q->SetAlwaysSecSelect(1);

   if (registerSet)
   {
      gEve->AddElement(q);
      gEve->Redraw3D(kTRUE);
   }

   return q;
}
Пример #6
0
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();
}
Пример #7
0
void display(bool showChannelIndex = false, TString fileNameCenters="../geom/dpgageom.csv", TString fileNameFull="../geom/dpgafullgeom.csv", Bool_t register=kTRUE)
{
  TEveManager::Create();

  gStyle->SetPalette(1, 0);
  
  TEveRGBAPalette* pal = new TEveRGBAPalette(0, 130);
  
  // Draw coordinate system
  TEveArrow* xAxis = new TEveArrow(150., 0., 0., 0., 0., 0.);
  TEveArrow* yAxis = new TEveArrow(0., 150., 0., 0., 0., 0.);
  TEveArrow* zAxis = new TEveArrow(0., 0., 150., 0., 0., 0.);
  xAxis->SetMainColor(15); xAxis->SetTubeR(0.042); xAxis->SetConeR(0.077); xAxis->SetConeL(0.245); xAxis->SetPickable(kTRUE);
  yAxis->SetMainColor(15); yAxis->SetTubeR(0.042); yAxis->SetConeR(0.077); yAxis->SetConeL(0.245); yAxis->SetPickable(kTRUE);
  zAxis->SetMainColor(15); zAxis->SetTubeR(0.042); zAxis->SetConeR(0.077); zAxis->SetConeL(0.245); zAxis->SetPickable(kTRUE);
  gEve->AddElement(xAxis);
  gEve->AddElement(yAxis);
  gEve->AddElement(zAxis);
  TEveText* tx = new TEveText("x"); tx->SetFontSize(20);
  TEveVector tvx = xAxis->GetVector()*1.1+xAxis->GetOrigin(); tx->RefMainTrans().SetPos(tvx.Arr());
  //xAxis->AddElement(tx);
  TEveText* ty = new TEveText("y"); ty->SetFontSize(20);
  TEveVector tvy = yAxis->GetVector()*1.1+yAxis->GetOrigin(); ty->RefMainTrans().SetPos(tvy.Arr());
  //yAxis->AddElement(ty);
  TEveText* tz = new TEveText("z"); tz->SetFontSize(20);
  TEveVector tvz = zAxis->GetVector()*1.1+zAxis->GetOrigin(); tz->RefMainTrans().SetPos(tvz.Arr());
  //zAxis->AddElement(tz);
  
  // Read full coordinates of scintillators and put them in a box set
  TEveBoxSet* bsright = new TEveBoxSet("BoxSetRight");
  bsright->Reset(TEveBoxSet::kBT_FreeBox, kFALSE, 64);
  bsright->SetPalette(pal);

  TEveBoxSet* bsleft = new TEveBoxSet("BoxSetLeft");
  bsleft->Reset(TEveBoxSet::kBT_FreeBox, kFALSE, 64);
  bsleft->SetPalette(pal);

  ifstream infull(fileNameFull.Data());
  if (!infull) {
    cerr << "ERROR ! Unable to open file '" << fileNameFull << "' !" << endl;
    return;
  }
  for(; !infull.eof() ;) {
    string line;
    if (!getline(infull,line)) break;
    if (!line.empty() && line[0]!='#') {
      istringstream istr(line);
      int iChannelAbs240;
      float X0, Y0, Z0;
      float X1, Y1, Z1;
      float X2, Y2, Z2;
      float X3, Y3, Z3;
      float X4, Y4, Z4;
      float X5, Y5, Z5;
      float X6, Y6, Z6;
      float X7, Y7, Z7;

      istr >> iChannelAbs240
	   >> X0 >> Y0 >> Z0
	   >> X1 >> Y1 >> Z1
	   >> X2 >> Y2 >> Z2
	   >> X3 >> Y3 >> Z3
	   >> X4 >> Y4 >> Z4
	   >> X5 >> Y5 >> Z5
	   >> X6 >> Y6 >> Z6
	   >> X7 >> Y7 >> Z7;
       
      Float_t verts[24] = {
	X0 , Y0 , Z0, 
	X1 , Y1 , Z1,
	X2 , Y2 , Z2,
	X3 , Y3 , Z3,
	X4 , Y4 , Z4,
	X5 , Y5 , Z5,
	X6 , Y6 , Z6,
	X7 , Y7 , Z7};
      
      // Color code:
      //  100 -> yellow
      //  10 -> blue
      if(iChannelAbs240 < 120) {
	bsright->AddBox(verts);
	bsright->DigitValue(100);
      }
      else {
	bsleft->AddBox(verts);
	bsleft->DigitValue(10);
      }
    }
  }