File indexing completed on 2025-01-30 09:17:46
0001 #include "TROOT.h"
0002 #include "TColor.h"
0003 #include "TGeoCone.h"
0004 #include "TGeoMatrix.h"
0005 #include "TGeoManager.h"
0006 #include "TGeoElement.h"
0007 #include "TGeoMaterial.h"
0008
0009 #include <cstdio>
0010
0011
0012 class Test {
0013 public:
0014 TGeoManager* m_manager = nullptr;
0015 TGeoMaterial* m_vacuum = nullptr;
0016 TGeoMedium* m_air = nullptr;
0017
0018 TGeoBBox* m_worldShape = nullptr;
0019 TGeoVolume* m_world = nullptr;
0020
0021 struct Cone {
0022 TGeoMaterial* material = nullptr;
0023 TGeoMedium* medium = nullptr;
0024 TGeoConeSeg* shape = nullptr;
0025 TGeoVolume* volume = nullptr;
0026 TGeoNode* place = nullptr;
0027 void set_color(const char* typ, Float_t alpha, Float_t red, Float_t green, Float_t blue) {
0028 Int_t col = TColor::GetColor(red, green, blue);
0029 TColor* color = gROOT->GetColor(col);
0030 if ( !color ) {
0031 ::printf("+++ %s Failed to allocate Color: r:%02X g:%02X b:%02X\n",
0032 typ, int(red*255.), int(green*255.), int(blue*255));
0033 }
0034 char text[64];
0035 ::snprintf(text, sizeof(text), "%p", this);
0036 TColor* colortr = new TColor(gROOT->GetListOfColors()->GetLast()+1,
0037 color->GetRed(), color->GetGreen(), color->GetBlue(), text, alpha);
0038
0039
0040 ::printf("Plot cone %s (col: %d) with transparency %8.3f r:%02X g:%02X b:%02X\n",
0041 typ, col, (1.0-alpha)*100, int(red*255.), int(green*255.), int(blue*255));
0042
0043
0044 int col_num = color->GetNumber();
0045 int col_tr_num = colortr->GetNumber();
0046 volume->SetVisibility(kTRUE);
0047 volume->SetVisContainers(kTRUE);
0048 volume->SetVisDaughters(kTRUE);
0049 volume->SetLineWidth(10);
0050 volume->SetFillStyle(1001);
0051 volume->ResetTransparency((1.0-alpha)*100);
0052 volume->SetLineStyle(1);
0053
0054
0055 volume->SetLineColor(col_num);
0056
0057 volume->SetFillColor(col_tr_num);
0058 }
0059 } cone1, cone2;
0060
0061 public:
0062 Test() {
0063 }
0064 virtual ~Test() {
0065 }
0066 void build(int version);
0067 };
0068
0069 void Test::build(int version) {
0070 m_manager = new TGeoManager("geom","Tube test");
0071 m_vacuum = new TGeoMaterial("vacuum", 0, 0, 0);
0072 m_air = new TGeoMedium("Vacuum", 0, m_vacuum);
0073
0074 m_worldShape = new TGeoBBox("WorldBox", 100, 100, 100);
0075 m_world = new TGeoVolume("World", m_worldShape, m_air);
0076
0077 cone1.material = new TGeoMaterial("Fe1", 55.845, 26, 7.87);
0078 cone1.medium = new TGeoMedium("Iron1", 1, cone1.material);
0079 cone1.shape = new TGeoConeSeg("Cone1Shape", 40, 0e0, 20e0, 0e0, 20e0, 0e0, 360e0);
0080 cone1.volume = new TGeoVolume("Cone1", cone1.shape, cone1.medium);
0081 cone1.set_color("Cone1",
0082 version ? 0.1 : 0.9,
0083 version ? 1e0 : 0e0,
0084 0e0,
0085 version ? 0e0 : 1e0);
0086 m_world->AddNode(cone1.volume, 1, new TGeoTranslation(-30, -30, 0));
0087
0088 cone2.material = version ? new TGeoMaterial("Fe2", 55.845, 26, 7.87) : cone1.material;
0089 cone2.medium = version ? new TGeoMedium("Iron2", 1, cone2.material) : cone1.medium;
0090 cone2.shape = new TGeoConeSeg("Cone2Shape", 40, 0e0, 20e0, 0e0, 20e0, 0e0, 360e0);
0091 cone2.volume = new TGeoVolume("Cone2", cone2.shape, cone2.medium);
0092 cone2.set_color("Cone2",
0093 version ? 0.9 : 0.1,
0094 version ? 0e0 : 0.9,
0095 0e0,
0096 version ? 0.9 : 0e0);
0097 m_world->AddNode(cone2.volume, 1, new TGeoTranslation(30, 30, 0));
0098
0099 m_manager->SetTopVolume(m_world);
0100 m_manager->SetTopVisible(0);
0101
0102 m_manager->GetTopVolume()->Draw("ogl");
0103 }
0104
0105
0106 Test* visTest(int version=0) {
0107 Test* obj = new Test();
0108 obj->build(version);
0109 return obj;
0110 }