#include TTimer timer(1000); void kill_timer(const char *message) { std::cout<<"Animation was stopped: "< objToInd; void create_geometry() { TCanvas *c1 = new TCanvas("c1"); TGeoManager *geom = new TGeoManager("geo", "geo"); TGeoMaterial *matVacuum = new TGeoMaterial("Vacuum", 0,0,0); TGeoMaterial *matAl = new TGeoMaterial("Al", 26.98,13,2.7); TGeoMedium *Vacuum = new TGeoMedium("Vacuum",1, matVacuum); TGeoMedium *Al = new TGeoMedium("Root Material",2, matAl); TGeoVolume *top = geom->MakeBox("TOP", Vacuum,2000.,2000.,1000.); geom->SetTopVolume(top); top->SetVisibility(kFALSE); for (Int_t tnr = 0; tnr < nTubes; ++tnr) { TGeoVolume *newVolume = geom->MakeBox("tub", Al, 2, 2, 200); //CINT does not want to work with pointers as keys. objToInd[(Int_t)newVolume] = tnr; top->AddNode(newVolume, tnr, new TGeoTranslation(6 * tnr, 0., 0.)); } gGeoManager->CloseGeometry(); top->Draw("ogl"); } Int_t currentEvent = 0; Int_t nEvents = 0; std::ifstream inputFile; void set_color(Float_t *color, Int_t ind) { TColor *c = gROOT->GetColor(ind); if (c) c->GetRGB(color[0], color[1], color[2]); } void animate_geometry() { if (!gROOT->GetListOfCanvases()->FindObject("c1")) return kill_timer("canvas was closed."); TGLViewer * viewer = 0; if (gPad->GetViewer3D()->InheritsFrom("TGLViewer")) viewer = static_cast(gPad->GetViewer3D()); else return kill_timer("no gl-viwer."); if (viewer->GetPhysicalShapesNumber() != nTubes) return kill_timer("unexpected number of shapes in gl-scene."); if (currentEvent == nEvents) { std::cout<<"Event "<>tubeAmps[i]; } TGLPhysicalShape **shapes = viewer->GetPhysicalShapes(); Float_t color[17] = {0.f}; for (Int_t i = 0; i < nTubes; ++i) { TGLPhysicalShape *pShape = shapes[i]; TGeoVolume *testVolume = (TGeoVolume *)pShape->GetLogical().GetExternal(); if (objToInd.find(Int_t(testVolume)) != objToInd.end())) { Int_t ind = objToInd[(Int_t)testVolume]; if (tubeAmps[ind] > 40) { set_color(color, 2); color[3] = 0.8f; } else if (tubeAmps[ind] > 30) { set_color(color, 5); color[3] = 0.8f; } else { color[3] = 0.3f; set_color(color, 38); } pShape->SetColor(color); } else { std::cout<<"No key "<<(Int_t)testVolume<RequestDraw(TGLDrawFlags::kLODMed); } void eventm() { std::cout<<"Enter the number of events\n"; std::cin>>nEvents; create_geometry(); inputFile.open("ampli.txt"); timer.SetCommand("animate_geometry()"); timer.TurnOn(); }