#include #include "TGeoManager.h" #include "TEveGeoNode.h" #include "TEveManager.h" #include "TRint.h" #include "TEveBrowser.h" #include "TEveElement.h" #include "TGeoNode.h" #include "TGeoNavigator.h" #include "TEveTrans.h" #include "TEvePathMark.h" #include "TEveTrack.h" TEveTrackList *gTrackList = 0; //============================================================================== // GUI stuff //------------------------------------------------------------------------------ class EvNavHandler { private: //TFile *mFile; ifstream mFile; TDatabasePDG *mPDG; int curEventN=0; public: EvNavHandler(string fname){ mFile.open(fname.c_str()); mPDG=TDatabasePDG::Instance(); } void Fwd() { DrawEvent(); curEventN++; } void Bck() { curEventN--; DrawEvent(); } void DrawEvent(){ cout<<"Draw event: "<DestroyElements(); TEveTrackPropagator *trkProp = gTrackList->GetPropagator(); int nP=0; string line; string w0,w1; double px,py,pz,e; istringstream sstream; int istep; double x,y,z; static bool isfirst=true; static TParticle pb; TEveTrack* track = 0; while(getline(mFile,line)){ cout<>w0; if (w0=="NEWP:"){ //new particle if (!isfirst && track){ cout<<"ADD THE TRACK "<GetPropagator()->SetMaxZ(1000); track->SetStdTitle(); track->SetAttLineAttMarker(gTrackList); SetColor(track); gTrackList->AddElement(track); } isfirst=false; sstream>>w1>>px>>py>>pz>>e; cout<<"NEW PARTICLE: "<GetParticle(w1.c_str()); TLorentzVector P(px,py,pz,e); pb.SetPdgCode(part->PdgCode()); pb.SetMomentum(P); }else{ istep=atoi(w0.c_str()); sstream>>x>>y>>z; if (istep==0){ TLorentzVector V(x,y,z,0); pb.SetProductionVertex(V); cout<<" CREATE THE TRACK "< v(x,y,z); TEvePathMarkD pm(TEvePathMarkD::kReference,v,0); track->AddPathMark(pm); } } } mFile.close(); track->SetStdTitle(); track->SetAttLineAttMarker(gTrackList); SetColor(track); gTrackList->AddElement(track); gTrackList->MakeTracks(); gEve->Redraw3D(); } //Same as Gemc void SetColor(TEveTrack *track){ switch (track->GetPdg()){ case 2112: track->SetLineColor(kBlack); break; case 22: track->SetLineColor(kBlue); break; case 211: track->SetLineColor(kMagenta); break; case -211: track->SetLineColor(kYellow); break; default: auto q=track->GetCharge(); if (q>0){ track->SetLineColor(kRed); } else if (q<0){ track->SetLineColor(kGreen); } else{ track->SetLineColor(kWhite); } break; } } }; //Add current depth element, loop on daughters, addElements void addElementsRecursive(TGeoManager *geo,TEveElementList *elements,int maxDepth,int thisDepth,bool buildOnlyDeepest){ if (thisDepth>maxDepth) return; //cout<<"addElementsRecursive thisDepth: "<GetCurrentNode()->GetNdaughters(); //1) Add current node to the list if ((!buildOnlyDeepest)||(thisDepth==(maxDepth))||(ndau==0)){ TGeoNode* node = geo->GetCurrentNode(); auto nodeName = node->GetName(); cout<<"ADD: "<GetCurrentVolume(); TEveGeoShape* shape = new TEveGeoShape(node->GetName(), vol->GetMaterial()->GetName()); shape->SetShape((TGeoShape*) vol->GetShape()->Clone()); shape->SetMainColor(vol->GetLineColor()); shape->SetFillColor(vol->GetFillColor()); shape->SetMainTransparency(vol->GetTransparency()); shape->RefMainTrans().SetFrom(*geo->GetCurrentMatrix()); elements->AddElement(shape); } //2) Check the daughters and do recursive thisDepth++; for (int i=0; iCdDown(i); addElementsRecursive(geo,elements,maxDepth,thisDepth,buildOnlyDeepest); geo->CdUp(); } } TEveElementList* buildDetector(TGeoManager* geo,string det,int maxDepth=0,bool buildOnlyDeepest=true){ auto elements = new TEveElementList(det.c_str()); geo->cd("/WorldLV_1/"); auto ndau = geo->GetCurrentNode()->GetNdaughters(); for (int i=0; iCdDown(i); TGeoNode* node = geo->GetCurrentNode(); if (std::string(node->GetName()).find(det) != std::string::npos) { //This node is the one to start diving into int thisDepth=0; addElementsRecursive(geo,elements,maxDepth,thisDepth,buildOnlyDeepest); } geo->CdUp(); } return elements; } void eve_test2() { // Create ROOT intepreter app TRint *app = 0; app = new TRint("Eve App", 0, 0); // Create Eve manager TEveManager *manager = TEveManager::Create(kTRUE, "FV"); //Track list gTrackList = new TEveTrackList("Pythia Tracks"); gTrackList->GetPropagator()->SetMagField(0.); gTrackList->SetMainColor(kYellow); gTrackList->SetMarkerColor(kRed); gTrackList->SetMarkerStyle(4); gTrackList->SetMarkerSize(0.5); gEve->AddElement(gTrackList); // Get Eve browser and embed it TEveBrowser *browser = manager->GetBrowser(); browser->StartEmbedding(TRootBrowser::kLeft); TGMainFrame* frmMain = new TGMainFrame(gClient->GetRoot(), 1000, 600); frmMain->SetWindowName("XX GUI"); frmMain->SetCleanup(kDeepCleanup); TGHorizontalFrame* hf = new TGHorizontalFrame(frmMain); { TString icondir( Form("%s/icons/", gSystem->Getenv("ROOTSYS")) ); TGPictureButton* b = 0; EvNavHandler *fh = new EvNavHandler("data.txt"); b = new TGPictureButton(hf, gClient->GetPicture(icondir+"GoBack.gif")); b->SetToolTipText("Go to previous event"); hf->AddFrame(b); // b->Connect("Clicked()", "EvNavHandler", fh, "Bck()"); b = new TGPictureButton(hf, gClient->GetPicture(icondir+"GoForward.gif")); b->SetToolTipText("Generate new event."); hf->AddFrame(b); b->Connect("Clicked()", "EvNavHandler", fh, "Fwd()"); } frmMain->AddFrame(hf); frmMain->MapSubwindows(); frmMain->Resize(); frmMain->MapWindow(); const std::string& geomFile = std::string("example116.gdml.txt"); auto geo = TGeoManager::Import(geomFile.c_str()); geo->DefaultColors(); auto topNode = gGeoManager->GetTopNode(); TEveElement *MM = buildDetector(geo,"MM",1,true); manager->AddGlobalElement(MM); TEveElement *Trigger = buildDetector(geo,"Trigger",1,true); manager->AddGlobalElement(Trigger); TEveElement *VETO = buildDetector(geo,"VETO",1,true); manager->AddGlobalElement(VETO); TEveElement *HCAL = buildDetector(geo,"HCAL",1,true); manager->AddGlobalElement(HCAL); TEveElement *MAGNET = buildDetector(geo,"Magnet",1,true); manager->AddGlobalElement(MAGNET); browser->SetTabTitle("Event Control", 0); browser->StopEmbedding(); // manager->FullRedraw3D(); app->Run(kFALSE); }