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
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #include <iostream>
0012 #include <fstream>
0013 #include <vector>
0014 #include <string>
0015 #include <TString.h>
0016 #include <TGeoManager.h>
0017
0018
0019 void RECURSIVE( TGeoNode * node, double tra, TString color, std::ofstream& myfile,std::vector<TString> &nodes){
0020 if (node->GetNdaughters() == 0) 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
0034 void Create_xml(const char *inputFile = "detector_geometry.root")
0035 {
0036 TEveManager::Create();
0037 gGeoManager = TGeoManager::Import(inputFile);
0038
0039
0040
0041
0042 if (gGeoManager == nullptr) return;
0043
0044
0045 TString color = "20";
0046
0047 double tra = 0.0;
0048
0049
0050 std::vector<TString> nodes;
0051
0052 ofstream myfile;
0053 myfile.open ("detector_colors.xml");
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
0081 nodes.clear();
0082 }
0083 myfile << "</config>\n";
0084
0085
0086
0087 myfile.close();
0088
0089
0090 TEveManager::Terminate();
0091
0092
0093 }
0094
0095
0096
0097