#include #include #include #include #include #include #include #include #include void add_volumes (TGeoVolume* top_volume_) { for (unsigned int i_volume = 0; i_volume < 100; ++i_volume) { std::ostringstream volume_name; volume_name << "volume_" << i_volume; const double length = rand () % 100; const double width = rand () % 100; const double height = rand () % 100; const double x = rand () % 10; const double y = rand () % 10; const double z = rand () % 10; TGeoVolume* volume = gGeoManager->MakeBox (volume_name.str().c_str(), NULL, length/2., width/2., height/2.); TGeoTranslation trans (x, y, z); top_volume_->AddNodeOverlap (volume, 1, new TGeoCombiTrans (trans)); } } void making_3d_view () { if (gGeoManager) delete gGeoManager; TGeoManager* geo_mgr = new TGeoManager ("EventViewer", "3D Event Viewer"); TGeoVolume* world = gGeoManager->MakeBox("TOP", NULL, 1000, 1000, 1000); world->SetVisibility (false); geo_mgr->SetTopVolume (world); add_volumes (world); geo_mgr->CloseGeometry (); world->Draw (); } void show_3d_event (TObjArray* objects_) { for (unsigned int i_vertex = 0; i_vertex < 100; ++i_vertex) { TMarker3DBox* vertex_3d_box = new TMarker3DBox (); objects_->Add(vertex_3d_box); vertex_3d_box->SetLineColor(kViolet); const double x = rand () % 100; const double y = rand () % 100; const double z = rand () % 100; vertex_3d_box->SetPosition (x, y, z); vertex_3d_box->SetSize (10, 10, 10); vertex_3d_box->Draw("same"); } } void show_2d_event (TCanvas* canvas_2d_) { canvas_2d_->cd (); // changing view ... } void test_clone (const bool enable_2d_ = false, const unsigned int nbr_event_ = 100) { srand (time (NULL)); // actually canvas 3d and 2d are coming from TRootEmbeddedCanvas via GetCanvas method TRootEmbeddedCanvas* embedded_3d = new TRootEmbeddedCanvas (); TCanvas* canvas_3d = embedded_3d->GetCanvas (); canvas_3d->cd (); making_3d_view (); TRootEmbeddedCanvas* embedded_2d = new TRootEmbeddedCanvas (); TCanvas* canvas_2d = embedded_2d->GetCanvas ();; TObjArray* objects = new TObjArray (); for (unsigned int i_event = 0; i_event < nbr_event_; ++i_event) { objects->Delete (); // 3D part show_3d_event (objects); if (enable_2d_) { // 2D part if (canvas_2d) { TList* list_primi1 = canvas_2d->GetListOfPrimitives (); std::cout << "number of primitives before = " << list_primi1->GetSize () << std::endl; canvas_2d->SetEditable (true); canvas_2d->Clear (); TList* list_primi2 = canvas_2d->GetListOfPrimitives (); std::cout << "number of primitives after = " << list_primi2->GetSize () << std::endl; delete canvas_2d; } embedded_2d->AdoptCanvas ((TCanvas*)canvas_3d->Clone ("2DView")); canvas_2d = embedded_2d->GetCanvas ();; show_2d_event (canvas_2d); } } }