Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-17 09:57:14

0001 // Macro for visualizing, changing color and transparency of volumes using Eve
0002 // Ondrej Lomicky, lomicond@fjfi.cvut.cz
0003 
0004 void RecursiveColor(TGeoVolume *vol, Color_t color)
0005 {
0006     if(!vol) return;
0007     vol->SetLineColor(color);
0008     Int_t nd = vol->GetNdaughters();
0009     for (Int_t i=0; i<nd; i++) {
0010         RecursiveColor(vol->GetNode(i)->GetVolume(),color);
0011     }
0012 }
0013 
0014 void RecursiveTransparency(TGeoVolume *vol, double tra){
0015     if(!vol) return;
0016     vol->SetTransparency(tra);
0017     Int_t nd = vol->GetNdaughters();
0018     for (Int_t i=0; i<nd; i++) {
0019         RecursiveTransparency(vol->GetNode(i)->GetVolume(),tra);
0020     }
0021 }
0022 
0023 void pfRICHcolor(TGeoVolume *vol){
0024     if(!vol) return;
0025     Int_t nd = vol->GetNdaughters();
0026     for (Int_t i=0; i<nd; i++) {
0027         TGeoVolume *voldaughter = vol->GetNode(i)->GetVolume();
0028         TString volname = voldaughter->GetIconName();
0029         volname.Remove(volname.Index("_shape"));
0030         //Write out all subnodes
0031         //cout << volname << endl;
0032         if (volname.Contains("Mirror")) voldaughter->SetLineColor(kAzure-4);
0033         else if (volname.Contains("QuartzWindow")) voldaughter->SetLineColor(kYellow);
0034         else voldaughter->SetLineColor(kGray+2);
0035         pfRICHcolor(vol->GetNode(i)->GetVolume());
0036     }
0037 }
0038 
0039 void Draw_model()
0040 {
0041     TEveManager::Create();
0042     gGeoManager = TGeoManager::Import("geo/detector_geometry.root");
0043 
0044     //Default colors
0045     gGeoManager->DefaultColors();
0046 
0047     if (gGeoManager == nullptr) return;
0048 
0049     //Vector of strings
0050     std::vector<TString> nodes;
0051 
0052     //cycle over all nodes
0053     TObjArray* allnodes = gGeoManager->GetTopNode()->GetNodes();
0054     const int nNodes = allnodes->GetEntries();
0055     for(Int_t i=0; i<nNodes;i++) {
0056         TGeoNode *node = (TGeoNode *) allnodes->At(i);
0057         TGeoVolume *vol = node->GetVolume();
0058         TString volname2 = vol->GetIconName();
0059         volname2.Remove(volname2.Index("_shape"));
0060         nodes.push_back(volname2);
0061         //Write out all nodes
0062         //cout << nodes[i] << endl;
0063     }
0064 
0065     //RecursiveColor(gGeoManager->GetVolume("PFRICH"), kGreen);
0066     //RecursiveTransparency(gGeoManager->GetVolume("PFRICH"),0);
0067 
0068     //Set transparency and colors to all nodes
0069     for (int i = 0; i < nodes.size(); i++)
0070     {
0071         if (nodes[i]=="PFRICH") pfRICHcolor(gGeoManager->GetVolume(nodes[i]));
0072         //if (nodes[i]=="PFRICH") RecursiveColor(gGeoManager->GetVolume(nodes[i]), kMagenta);
0073         //else if (nodes[i]=="EcalEndcapP");
0074         else RecursiveColor(gGeoManager->GetVolume(nodes[i]), 20);
0075         //RecursiveTransparency(gGeoManager->GetVolume(nodes[i]),100);
0076         //if (nodes[i]!="PFRICH") RecursiveColor(gGeoManager->GetVolume(nodes[i]), 20);
0077     }
0078 
0079 
0080     TEveGeoTopNode *EPIC_Tracker = new TEveGeoTopNode(gGeoManager,gGeoManager->GetTopNode());
0081 
0082     EPIC_Tracker->SetVisLevel(100);
0083     gEve->AddGlobalElement(EPIC_Tracker);
0084     gEve->FullRedraw3D(kTRUE);
0085 
0086     TGLViewer  *viewer = gEve->GetDefaultGLViewer();
0087     viewer->GetClipSet()->SetClipType(TGLClip::EType(1));
0088     viewer->DoDraw();
0089 
0090     //Save it to a root file
0091     TFile *f = new TFile("model.root","RECREATE");
0092     f->cd();
0093     gGeoManager->Write();
0094     f->Close();
0095 
0096 //////gEve->GetDefaultGLViewer()->SavePicture("test.png");
0097 
0098 }
0099 
0100 
0101 
0102