Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /pfRICH/Visualization/Create_xml.C was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // Macro for creating xml file defining color and transparency of volumes
0002 // Ondrej Lomicky, lomicond@fjfi.cvut.cz
0003 
0004 //run
0005 //root Create_xml\(\"detector_geometry.root\"\)
0006 //to create xml file
0007 //Used colors have root names (kBlue, kAzure-3, 20, etc.)
0008 //Transparency is set to 0.0 (not transparent) by default
0009 
0010 //Libraries
0011 #include <iostream>
0012 #include <fstream>
0013 #include <vector>
0014 #include <string>
0015 #include <TString.h>
0016 #include <TGeoManager.h>
0017 
0018 //Recursive function for finding all subnodes
0019 void RECURSIVE( TGeoNode * node, double tra, TString color, std::ofstream& myfile,std::vector<TString> &nodes){
0020     if (node->GetNdaughters() == 0) return; //if there are no daughters, return
0021     for (Int_t i = 0; i < node->GetNdaughters(); i++) {
0022         TString NodaName = node->GetDaughter(i)->GetVolume()->GetName();
0023             if (std::find(nodes.begin(), nodes.end(), NodaName) == nodes.end()) {
0024                 nodes.push_back(NodaName);
0025                 myfile << "\t\t<part name=\"" << NodaName << "\" color=\""<<color<<"\" transparency=\""<<tra<<"\" />\n";
0026                 RECURSIVE(node->GetDaughter(i), tra, color, myfile,nodes) ;
0027             }
0028 
0029     }
0030     return;
0031 }
0032 
0033 //Main function
0034 void Create_xml(const char *inputFile = "detector_geometry.root")
0035 {
0036     TEveManager::Create();
0037     gGeoManager = TGeoManager::Import(inputFile); //Import geometry
0038 
0039     //Default colors
0040     //gGeoManager->DefaultColors();
0041 
0042     if (gGeoManager == nullptr) return;
0043 
0044     //Default color
0045     TString color = "20";
0046     //Default transparency
0047     double tra = 0.0;
0048 
0049     //Vector of strings
0050     std::vector<TString> nodes;
0051 
0052     ofstream myfile;
0053     myfile.open ("detector_colors.xml"); //Open xml file
0054 
0055     myfile << "<config>\n";
0056 
0057     cout << "Nodes: " << endl;
0058     TGeoNode * noda = gGeoManager->GetTopNode();
0059         for (Int_t k = 0; k < noda->GetNdaughters(); k++) {
0060             TString NodaName = noda->GetDaughter(k)->GetVolume()->GetName();
0061 
0062             if(NodaName.Contains("World")) {
0063                 NodaName = noda->GetDaughter(k)->GetDaughter(0)->GetVolume()->GetName();
0064                 TGeoNode * noda2 = noda->GetDaughter(k)->GetDaughter(0);
0065                 myfile << "    <detector name=\"" << NodaName << "\">\n";
0066                 if (noda2->GetNdaughters() == 0){
0067                     myfile << "\t\t<part name=\"" << NodaName << "\" color=\""<<color<<"\" transparency=\""<<tra<<"\" />\n";
0068                 }
0069                 RECURSIVE(noda->GetDaughter(k)->GetDaughter(0), tra, color, myfile, nodes);
0070                 myfile << "</detector>\n";
0071             } else {
0072             myfile << "    <detector name=\"" << NodaName << "\">\n";
0073             if (noda->GetNdaughters() == 0){
0074                 myfile << "\t\t<part name=\"" << NodaName << "\" color=\""<<color<<"\" transparency=\""<<tra<<"\" />\n";
0075             }
0076             RECURSIVE(noda->GetDaughter(k), tra, color, myfile, nodes);
0077             myfile << "</detector>\n";
0078             }
0079             cout << NodaName << endl;
0080             //Clean vector
0081             nodes.clear();
0082         }
0083     myfile << "</config>\n";
0084 
0085 
0086   //Close the file
0087   myfile.close();
0088 
0089   //Close the manager
0090   TEveManager::Terminate();
0091 
0092 
0093 }
0094 
0095 
0096 
0097