xtruDraw.C

Go to the documentation of this file.
00001 void xtruDraw() {
00002 // Draw a "representative" TXTRU shape
00003 // Canvas saved as xtru.gif can be used for TXTRU THtml output
00004 // Author: Robert Hatcher (rhatcher@fnal.gov) 2000.09.06
00005 
00006   TCanvas *canvas = new TCanvas("xtru","Example XTRU object",200,10,640,640);
00007 
00008 // Create a new geometry
00009   TGeometry* geometry = new TGeometry("geometry","geometry");
00010   geometry->cd();
00011 
00012   TXTRU* atxtru = new TXTRU("atxtru","atxtru","void",5,2);
00013 
00014 // outline and z segment specifications
00015 
00016   Float_t x[] = 
00017     {   -177.292,   -308.432,   -308.432,   -305.435,   -292.456,    -280.01
00018     ,    -241.91,    -241.91,   -177.292,   -177.292,    177.292,    177.292
00019     ,     241.91,     241.91,     280.06,    297.942,    305.435,    308.432
00020     ,    308.432,    177.292,    177.292,   -177.292 };
00021   Float_t y[] = 
00022     {    154.711,    23.5712,     1.1938,     1.1938,     8.6868,     8.6868
00023     ,    -3.7592,   -90.0938,   -154.711,   -190.602,   -190.602,   -154.711
00024     ,   -90.0938,    -3.7592,     8.6868,     8.6868,     1.1938,     1.1938
00025     ,    23.5712,    154.711,    190.602,    190.602 };
00026   Float_t z[] = 
00027     {       0.00,      500.0 };
00028   Float_t scale[] = 
00029     {       1.00,       1.00 };
00030   Float_t x0[] = 
00031     {          0,          0 };
00032   Float_t y0[] = 
00033     {          0,          0 };
00034 
00035   Int_t i;
00036 
00037   Int_t nxy = sizeof(x)/sizeof(Float_t);
00038   for (i=0; i<nxy; i++) {
00039      atxtru->DefineVertex(i,x[i],y[i]);
00040   }
00041 
00042   Int_t nz = sizeof(z)/sizeof(Float_t);
00043   for (i=0; i<nz; i++) {
00044      atxtru->DefineSection(i,z[i],scale[i],x0[i],y0[i]);
00045   }
00046 
00047 // Define a TNode where this example resides in the TGeometry
00048 // Draw the TGeometry
00049 
00050   TNode* anode = new TNode("anode","anode",atxtru);
00051   anode->SetLineColor(1);
00052 
00053   geometry->Draw();
00054 
00055 // Tweak the pad scales so as not to distort the shape
00056 
00057   TVirtualPad *thisPad = gPad;
00058   if (thisPad) {
00059     TView *view = thisPad->GetView(); 
00060     if (!view) return;
00061     Double_t min[3],max[3],center[3];
00062     view->GetRange(min,max);
00063     int i;
00064     // Find the boxed center
00065     for (i=0;i<3; i++) center[i] = 0.5*(max[i]+min[i]);
00066     Double_t maxSide = 0;
00067     // Find the largest side
00068     for (i=0;i<3; i++) maxSide = TMath::Max(maxSide,max[i]-center[i]);
00069     file://Adjust scales:
00070     for (i=0;i<3; i++) {
00071        max[i] = center[i] + maxSide;
00072        min[i] = center[i] - maxSide;
00073     }
00074     view->SetRange(min,max);
00075     Int_t ireply;
00076     thisPad->Modified();
00077     thisPad->Update();
00078   }
00079 
00080 }

Generated on Tue Jul 5 15:44:17 2011 for ROOT_528-00b_version by  doxygen 1.5.1