示例#1
0
void s_union()
{
   gROOT->GetListOfCanvases()->Delete();
   TCanvas *c = new TCanvas("composite shape", "Union boolean operation", 700, 1000);

   c->Divide(1,2,0,0);
   c->cd(2);
   gPad->SetPad(0,0,1,0.4);
   c->cd(1);
   gPad->SetPad(0,0.4,1,1);
   
   if (gGeoManager) delete gGeoManager;
   
   new TGeoManager("xtru", "poza12");
   TGeoMaterial *mat = new TGeoMaterial("Al", 26.98,13,2.7);
   TGeoMedium *med = new TGeoMedium("MED",1,mat);
   TGeoVolume *top = gGeoManager->MakeBox("TOP",med,100,100,100);
   gGeoManager->SetTopVolume(top);

   // define shape components with names
   TGeoPgon *pgon = new TGeoPgon("pg",0.,360.,6,2); 
   pgon->DefineSection(0,0,0,20);
   pgon->DefineSection(1, 30,0,20);

   TGeoSphere *sph = new TGeoSphere("sph", 40., 45., 5., 175., 0., 340.);
   // define named geometrical transformations with names
   TGeoTranslation *tr = new TGeoTranslation(0., 0., 45.);
   tr->SetName("tr");
   // register all used transformations
   tr->RegisterYourself();
   // create the composite shape based on a Boolean expression
   TGeoCompositeShape *cs = new TGeoCompositeShape("mir", "sph:tr + pg");

   TGeoVolume *vol = new TGeoVolume("COMP1",cs);
   top->AddNode(vol,1);
   gGeoManager->CloseGeometry();
   gGeoManager->SetNsegments(100);
   top->Draw();
   MakePicture();

   c->cd(2);
   TPaveText *pt = new TPaveText(0.01,0.01,0.99,0.99);
   pt->SetLineColor(1);
   TText *text = pt->AddText("TGeoCompositeShape - composite shape class");
   text->SetTextColor(2);
   pt->AddText("----- It's an example of boolean union operation : A + B");
   pt->AddText("----- A == part of sphere (5-175, 0-340), B == pgon");
   pt->AddText(" ");
   pt->SetAllWith("-----","color",4);
   pt->SetAllWith("-----","font",72);
   pt->SetAllWith("-----","size",0.04);
   pt->SetTextAlign(12);
   pt->SetTextSize(.044);
   pt->Draw();
   c->cd(1);
}
示例#2
0
void AddMirrors(AOpticalComponent* opt)
{
  // dummy hexagonal prism to cut a spherical mirror
  TGeoPgon* mirCut = new TGeoPgon("mirCut", 0., 360., 6, 2);
  mirCut->DefineSection(0, -100*mm, 0, kMirrorD/2.);
  mirCut->DefineSection(1,  100*mm, 0, kMirrorD/2.);

  double theta = TMath::ASin(kMirrorD/TMath::Sqrt(3)/kMirrorR)*TMath::RadToDeg();
  TGeoSphere* mirSphere = new TGeoSphere("mirSphere", kMirrorR, kMirrorR + kMirrorT, 180. - theta, 180.);
  TGeoTranslation* transZ = new TGeoTranslation("transZ", 0, 0, kMirrorR);
  transZ->RegisterYourself();
  TGeoCompositeShape* mirComposite = new TGeoCompositeShape("mirComposite", "mirSphere:transZ*mirCut");
  AMirror* mirror = new AMirror("mirror", mirComposite);

  const int kNMirror = 88;
  double dx = kMirrorD/TMath::Sqrt(3);
  double dy = kMirrorD/2.;
  double x[kNMirror] = {0, 0, 0, 0, 0, 0, 0, 0,
                        1.5*dx, 1.5*dx, 1.5*dx, 1.5*dx, 1.5*dx,
                        1.5*dx, 1.5*dx, 1.5*dx, 1.5*dx, 1.5*dx,
                        -1.5*dx, -1.5*dx, -1.5*dx, -1.5*dx, -1.5*dx,
                        -1.5*dx, -1.5*dx, -1.5*dx, -1.5*dx, -1.5*dx,
                        3*dx, 3*dx, 3*dx, 3*dx, 3*dx,
                        3*dx, 3*dx, 3*dx, 3*dx,
                        -3*dx, -3*dx, -3*dx, -3*dx, -3*dx,
                        -3*dx, -3*dx, -3*dx, -3*dx,
                        4.5*dx, 4.5*dx, 4.5*dx, 4.5*dx,
                        4.5*dx, 4.5*dx, 4.5*dx, 4.5*dx,
                        -4.5*dx, -4.5*dx, -4.5*dx, -4.5*dx,
                        -4.5*dx, -4.5*dx, -4.5*dx, -4.5*dx,
                        6*dx, 6*dx, 6*dx, 6*dx,
                        6*dx, 6*dx, 6*dx,
                        -6*dx, -6*dx, -6*dx, -6*dx,
                        -6*dx, -6*dx, -6*dx,
                        7.5*dx, 7.5*dx, 7.5*dx,
                        7.5*dx, 7.5*dx, 7.5*dx,
                        -7.5*dx, -7.5*dx, -7.5*dx,
                        -7.5*dx, -7.5*dx, -7.5*dx};

  double y[kNMirror] = {2*dy, 4*dy, 6*dy, 8*dy, -2*dy, -4*dy, -6*dy, -8*dy,
                        1*dy, 3*dy, 5*dy, 7*dy, 9*dy,
                        -1*dy, -3*dy, -5*dy, -7*dy, -9*dy,
                        1*dy, 3*dy, 5*dy, 7*dy, 9*dy,
                        -1*dy, -3*dy, -5*dy, -7*dy, -9*dy,
                        0*dy, 2*dy, 4*dy, 6*dy, 8*dy,
                        -2*dy, -4*dy, -6*dy, -8*dy,
                        0*dy, 2*dy, 4*dy, 6*dy, 8*dy,
                        -2*dy, -4*dy, -6*dy, -8*dy,
                        1*dy, 3*dy, 5*dy, 7*dy,
                        -1*dy, -3*dy, -5*dy, -7*dy,
                        1*dy, 3*dy, 5*dy, 7*dy,
                        -1*dy, -3*dy, -5*dy, -7*dy,
                        0*dy, 2*dy, 4*dy, 6*dy,
                        -2*dy, -4*dy, -6*dy,
                        0*dy, 2*dy, 4*dy, 6*dy,
                        -2*dy, -4*dy, -6*dy,
                        1*dy, 3*dy, 5*dy,
                        -1*dy, -3*dy, -5*dy,
                        1*dy, 3*dy, 5*dy,
                        -1*dy, -3*dy, -5*dy};

  for(int i = 0; i < kNMirror; i++){
    double r2d = TMath::RadToDeg();
    double r2 = TMath::Power(x[i], 2) + TMath::Power(y[i], 2);
    double z = kF - TMath::Sqrt(TMath::Power(kF, 2) - r2);

    // each mirror center is relocated from the origin (0, 0, 0) to (x, y, z)
    TGeoTranslation* trans = new TGeoTranslation(Form("mirTrans%d", i), x[i], y[i], z);

    // and is rotated to compose a DC optics
    double phi = TMath::ATan2(y[i], x[i])*r2d;
    TGeoRotation* rot = new TGeoRotation(Form("mirRot%d", i), - phi + 90., 0, 0);
    theta = TMath::ATan2(TMath::Sqrt(r2), 2*kF - z)*r2d;
    TGeoRotation* rot2 = new TGeoRotation("", phi - 90., theta, 0);
    rot->MultiplyBy(rot2, 0);
    
    // make a matrix from translation and rotation matrices
    TGeoCombiTrans* combi = new TGeoCombiTrans(*trans, *rot);

    // finally add this mirror to the world
    opt->AddNode(mirror, i + 1, combi);
  } // i
}