-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New way to color tracks. #1579
base: dev
Are you sure you want to change the base?
New way to color tracks. #1579
Changes from 1 commit
986a8e4
064b18e
8a1980e
65ae245
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
#include "FairRootManager.h" // for FairRootManager | ||
#include "FairRunAna.h" // for FairRunAna | ||
#include "FairXMLNode.h" | ||
#include "xml/FairXMLDetectorColor.h" | ||
|
||
#include <TDatabasePDG.h> // for TDatabasePDG | ||
#include <TEveBrowser.h> | ||
|
@@ -64,7 +65,6 @@ FairEventManager::FairEventManager() | |
, fRhoZPlane{-1, 0, 0, 0} | ||
, fRphiCam(TGLViewer::kCameraOrthoXOY) | ||
, fRhoCam(TGLViewer::kCameraOrthoZOY) | ||
, fXMLConfig("") | ||
{ | ||
fgRinstance = this; | ||
AddParticlesToPdgDataBase(); | ||
|
@@ -84,7 +84,7 @@ void FairEventManager::Init(Int_t visopt, Int_t vislvl, Int_t maxvisnds) | |
fWorldSizeY = box->GetDY(); | ||
fWorldSizeZ = box->GetDZ(); | ||
} | ||
if (!fXMLConfig.EqualTo("")) | ||
if (fXMLFile) | ||
LoadXMLSettings(); | ||
gEve->AddGlobalElement(TNod); | ||
gEve->FullRedraw3D(kTRUE); | ||
|
@@ -174,6 +174,11 @@ FairEventManager::~FairEventManager() | |
|
||
void FairEventManager::Open() {} | ||
|
||
void FairEventManager::SetXMLConfig(TString xml_config) | ||
{ | ||
if (xml_config.Length() && xml_config.EndsWith(".xml")) | ||
fXMLFile.reset(new FairXMLFile(xml_config)); | ||
DanielWielanek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
void FairEventManager::GotoEvent(Int_t event) | ||
{ | ||
fEntry = event; | ||
|
@@ -297,77 +302,28 @@ void FairEventManager::SetRhoZPlane(Double_t a, Double_t b, Double_t c, Double_t | |
|
||
void FairEventManager::LoadXMLSettings() | ||
{ | ||
FairXMLFile xmlfile(fXMLConfig, "read"); | ||
FairXMLNode *xml = xmlfile.GetRootNode(); | ||
for (int i = 0; i < xml->GetNChildren(); i++) { | ||
TString nodename = xml->GetChild(i)->GetName(); | ||
if (nodename.EqualTo("Detectors")) { | ||
TGeoNode *top = gGeoManager->GetTopNode(); | ||
FairXMLNode *top_xml = xml->GetChild(i)->GetChild(0); | ||
if (top_xml != nullptr) | ||
LoadXMLDetector(top, top_xml); | ||
} else if (nodename.EqualTo("MCTracksColors")) { | ||
FairXMLNode *colors = xml->GetChild(i); | ||
for (int j = 0; j < colors->GetNChildren(); j++) { | ||
FairXMLNode *color = colors->GetChild(j); | ||
TString pgd_code = color->GetAttrib("pdg")->GetValue(); | ||
TString color_code = color->GetAttrib("color")->GetValue(); | ||
fPDGColor.SetColor(pgd_code.Atoi(), FairXMLPdgColor::StringToColor(color_code)); | ||
} | ||
auto colors = GetXMLConfigNode("MCTracksColors"); | ||
auto detectors = GetXMLConfigNode("Detectors"); | ||
if (colors) | ||
fPDGColor = FairXMLPdgColor(colors); | ||
if (detectors) { | ||
auto cave = detectors->GetChild(0); | ||
if (cave) { | ||
FairXMLDetectorColor detCol(cave); | ||
detCol.Colorize(gGeoManager->GetTopNode()); | ||
Comment on lines
+305
to
+313
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding error handling in The method should include error handling to manage cases where XML nodes are not found. void FairEventManager::LoadXMLSettings()
{
auto colors = GetXMLConfigNode("MCTracksColors");
auto detectors = GetXMLConfigNode("Detectors");
if (colors) {
fPDGColor = FairXMLPdgColor(colors);
} else {
// Handle error
}
if (detectors) {
auto cave = detectors->GetChild(0);
if (cave) {
FairXMLDetectorColor detCol(cave);
detCol.Colorize(gGeoManager->GetTopNode());
} else {
// Handle error
}
} else {
// Handle error
}
gEve->Redraw3D();
} |
||
} | ||
} | ||
gEve->Redraw3D(); | ||
} | ||
|
||
void FairEventManager::LoadXMLDetector(TGeoNode* node, FairXMLNode* xml, Int_t depth) | ||
{ | ||
TString name = xml->GetAttrib("name")->GetValue(); | ||
TString node_name = node->GetName(); | ||
Bool_t recursive = (xml->GetAttrib("recursive")->GetValue().Length() != 0 && !name.EqualTo(node_name)); | ||
if (recursive && depth == 0) | ||
return; | ||
TString transparency = xml->GetAttrib("transparency")->GetValue(); | ||
TString color = xml->GetAttrib("color")->GetValue(); | ||
if (!color.EqualTo("")) { | ||
node->GetVolume()->SetFillColor(FairXMLPdgColor::StringToColor(color)); | ||
node->GetVolume()->SetLineColor(FairXMLPdgColor::StringToColor(color)); | ||
} | ||
if (!transparency.EqualTo("")) { | ||
node->GetVolume()->SetTransparency((Char_t)(transparency.Atoi())); | ||
} | ||
if (xml->GetAttrib("recursive")->GetValue().Length() > 0) { | ||
TString val = xml->GetAttrib("recursive")->GetValue(); | ||
Int_t xml_depth = val.Atoi(); | ||
if (recursive) { | ||
xml_depth = depth - 1; | ||
} | ||
for (int i = 0; i < node->GetNdaughters(); i++) { | ||
TGeoNode *daughter_node = node->GetDaughter(i); | ||
LoadXMLDetector(daughter_node, xml, xml_depth); | ||
} | ||
} | ||
if (xml->GetNChildren() > 0 && !recursive) { | ||
for (int i = 0; i < node->GetNdaughters(); i++) { | ||
TString subdetector_name = node->GetDaughter(i)->GetName(); | ||
for (int j = 0; j < xml->GetNChildren(); j++) { | ||
FairXMLNode *subnode = xml->GetChild(j); | ||
TString subnode_name = subnode->GetAttrib("name")->GetValue(); | ||
if (subnode_name == subdetector_name) { | ||
LoadXMLDetector(node->GetDaughter(i), subnode); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
void FairEventManager::SetTransparency(Bool_t use_xml, Int_t trans) | ||
{ | ||
if (!use_xml) { // high transparency | ||
Int_t vis_level = gGeoManager->GetVisLevel(); | ||
TGeoNode* top = gGeoManager->GetTopNode(); | ||
SetTransparencyForLayer(top, vis_level, trans); | ||
} else { // normal transparency | ||
if (fXMLConfig != "") { | ||
if (fXMLFile) { | ||
LoadXMLSettings(); | ||
} else { | ||
Int_t vis_level = gGeoManager->GetVisLevel(); | ||
|
@@ -466,3 +422,13 @@ void FairEventManager::SetEvtNumberText(Int_t evtNumber) | |
text += evtNumber; | ||
fEventNumberText->SetText(text); | ||
} | ||
|
||
FairXMLNode* FairEventManager::GetXMLConfigNode(TString name) const | ||
{ | ||
if (fXMLFile) { | ||
auto root = fXMLFile->GetRootNode(); | ||
if (root) | ||
return root->GetChild(name); | ||
} | ||
return nullptr; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,7 @@ class TEveViewer; | |
class TEveText; | ||
class TGeoNode; | ||
class TGListTreeItem; | ||
class FairXMLFile; | ||
|
||
/** | ||
* \ingroup eventdisplay fairroot_singleton | ||
|
@@ -44,14 +45,17 @@ class FairEventManager : public TEveEventManager | |
static FairEventManager* Instance(); | ||
FairEventManager(); | ||
virtual ~FairEventManager(); | ||
virtual void SetXMLConfig(TString xml_config) { fXMLConfig = xml_config; }; | ||
virtual void SetXMLConfig(TString xml_config); | ||
virtual void Open(); | ||
virtual void GotoEvent(Int_t event); // *MENU* | ||
virtual void NextEvent(); // *MENU* | ||
virtual void PrevEvent(); // *MENU* | ||
virtual void Close(); | ||
virtual void DisplaySettings(); // *Menu* | ||
virtual Int_t Color(Int_t pdg) { return fPDGColor.GetColor(pdg); } | ||
[[deprecated("Use FairEventManager::GetXMLConfig")]] virtual Int_t Color(Int_t pdg) | ||
{ | ||
return fPDGColor.GetColor(pdg); | ||
} | ||
void AddTask(FairTask* t) { fRunAna->AddTask(t); } | ||
virtual void Init(Int_t visopt = 1, Int_t vislvl = 3, Int_t maxvisnds = 10000); | ||
virtual Int_t GetCurrentEvent() { return fEntry; } | ||
|
@@ -126,6 +130,7 @@ class FairEventManager : public TEveEventManager | |
Bool_t GetUseTimeOfEvent() const { return fUseTimeOfEvent; } | ||
Bool_t GetDrawAnimatedTracks() const { return fAnimatedTracks; } | ||
Bool_t GetClearHandler() const { return fClearHandler; } | ||
FairXMLNode* GetXMLConfigNode(TString name) const; | ||
FairRootManager& GetRootManager() { return fRootManager; } | ||
FairRootManager const& GetRootManager() const { return fRootManager; } | ||
|
||
|
@@ -151,7 +156,6 @@ class FairEventManager : public TEveEventManager | |
TEveProjectionAxes* GetRPhiAxes() const { return fAxesPhi; }; | ||
TEveProjectionAxes* GetRhoZAxes() const { return fAxesRho; }; | ||
virtual void LoadXMLSettings(); | ||
void LoadXMLDetector(TGeoNode* node, FairXMLNode* xml, Int_t depth = 0); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a public member function. So you're removing public API. This is a breaking change. If you really want this breaking change, then please write an appropriate CHANGELOG entry. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if I made change corretly, please check :) |
||
[[deprecated("Use FairXMLPdgColor::StringToColor")]] Int_t StringToColor(const TString& color) const | ||
{ | ||
return FairXMLPdgColor::StringToColor(color); | ||
|
@@ -186,7 +190,7 @@ class FairEventManager : public TEveEventManager | |
TEveText* fEventTimeText{nullptr}; //! | ||
TEveText* fEventNumberText{nullptr}; //! | ||
FairXMLPdgColor fPDGColor{}; //! | ||
TString fXMLConfig; | ||
std::unique_ptr<FairXMLFile> fXMLFile; //! | ||
void SetTransparencyForLayer(TGeoNode* node, Int_t depth, Char_t transparency); | ||
static FairEventManager* fgRinstance; //! | ||
FairEventManager(const FairEventManager&); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a check to ensure
fXMLFile
is valid before callingLoadXMLSettings
.The method should include a check to ensure
fXMLFile
is valid before callingLoadXMLSettings
.