Skip to content
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

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions examples/advanced/propagator/macros/conf.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,21 @@
<detector name="Pixel2_0" color="kRed+1" transparency="30" recursive="0"></detector>
<detector name="Pixel3_0" color="kRed+2" transparency="30" recursive="0"></detector>
<detector name="Pixel4_0" color="kRed+3" transparency="30" recursive="0"></detector>
<detector name="Pixel101_0" color="kCyan" transparency="30" recursive="0"></detector>
<detector name="Pixel102_0" color="kCyan+1" transparency="30" recursive="0"></detector>
<detector name="Pixel103_0" color="kCyan+2" transparency="30" recursive="0"></detector>
<detector name="Pixel104_0" color="kCyan+3" transparency="30" recursive="0"></detector>
<detector name="Pixel5_0" color="kCyan" transparency="30" recursive="0"></detector>
<detector name="Pixel6_0" color="kCyan+1" transparency="30" recursive="0"></detector>
<detector name="Pixel7_0" color="kCyan+2" transparency="30" recursive="0"></detector>
<detector name="Pixel8_0" color="kGreen" transparency="30" recursive="0"></detector>
</detector>
</Detectors>
<MCTracksColors>
<mctrack color="kRed" pdg="2212"></mctrack>
<mctrack color="kGreen" pdg="211"></mctrack>
<mctrack color="kYellow" pdg="11"></mctrack>
</MCTracksColors>
<MCTrackColors>
<track color="kRed" pdg="2212"></track>
<track color="kGreen" pdg="211"></track>
<track color="kYellow" pdg="11"></track>
</MCTrackColors>
<GeoTracksColors>
<track color="kRed+2" pdg="2212"></track>
<track color="kGreen+2" pdg="211"></track>
<track color="kYellow+2" pdg="11"></track>
</GeoTracksColors>

</xmlconf>
5 changes: 4 additions & 1 deletion examples/common/eventdisplay/FairEveMCTracks.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void FairEveMCTracks::DrawTrack(Int_t id)
auto tr = static_cast<FairMCTrack*>(fContainer->UncheckedAt(id));
if (!CheckCuts(tr))
return;
Color_t color = GetEventManager()->Color(tr->GetPdgCode());
Color_t color = fPdgColor.GetColor(tr->GetPdgCode());
TEveTrackList* trList = FindTrackGroup(Form("%i", tr->GetPdgCode()), color);
TParticle p(tr->GetPdgCode(),
0,
Expand Down Expand Up @@ -149,6 +149,9 @@ InitStatus FairEveMCTracks::Init()
if (status != kSUCCESS)
return status;
FairEventManager* eveManager = GetEventManager();
auto colorConf = eveManager->GetXMLConfigNode("MCTrackColors");
if (colorConf)
fPdgColor = FairXMLPdgColor(colorConf);
FairRootManager* mngr = &(eveManager->GetRootManager());
fContainer = dynamic_cast<TClonesArray*>(mngr->GetObject("MCTrack"));
if (!fContainer) {
Expand Down
8 changes: 5 additions & 3 deletions examples/common/eventdisplay/FairEveMCTracks.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
#ifndef FAIREVEMCTRACKS_H_
#define FAIREVEMCTRACKS_H_

#include "FairEveTracks.h" // for FairEveTracks
#include "FairTask.h" // for InitStatus
#include "FairEveTracks.h" // for FairEveTracks
#include "FairTask.h" // for InitStatus
#include "FairXMLPdgColor.h" //for pdg color

#include <FairRKPropagator.h>
#include <Rtypes.h> // for THashConsistencyHolder, ClassDef
Expand All @@ -37,11 +38,12 @@ class FairEveMCTracks : public FairEveTracks
Bool_t fShowSecondary;
Bool_t fUsePdg;
Int_t fPdgCut;
FairXMLPdgColor fPdgColor;
std::unique_ptr<FairRKPropagator> fRK{};
TDatabasePDG* fPDG{nullptr};

protected:
Bool_t CheckCuts(FairMCTrack *tr);
Bool_t CheckCuts(FairMCTrack* tr);
void DrawTrack(Int_t id);

public:
Expand Down
1 change: 1 addition & 0 deletions fairroot/eventdisplay/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ set(sources
tracks/FairGeoTrackHandler.cxx
xml/FairXMLEveConf.cxx
xml/FairXMLPdgColor.cxx
xml/FairXMLDetectorColor.cxx
)

fair_change_extensions_if_exists(.cxx .h FILES "${sources}" OUTVAR headers)
Expand Down
88 changes: 27 additions & 61 deletions fairroot/eventdisplay/FairEventManager.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -64,7 +65,6 @@ FairEventManager::FairEventManager()
, fRhoZPlane{-1, 0, 0, 0}
, fRphiCam(TGLViewer::kCameraOrthoXOY)
, fRhoCam(TGLViewer::kCameraOrthoZOY)
, fXMLConfig("")
{
fgRinstance = this;
AddParticlesToPdgDataBase();
Expand All @@ -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)
Copy link

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 calling LoadXMLSettings.

The method should include a check to ensure fXMLFile is valid before calling LoadXMLSettings.

if (fXMLFile && fXMLFile->IsValid()) {
    LoadXMLSettings();
}

LoadXMLSettings();
gEve->AddGlobalElement(TNod);
gEve->FullRedraw3D(kTRUE);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding error handling in LoadXMLSettings.

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();
Expand Down Expand Up @@ -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;
}
12 changes: 8 additions & 4 deletions fairroot/eventdisplay/FairEventManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class TEveViewer;
class TEveText;
class TGeoNode;
class TGListTreeItem;
class FairXMLFile;

/**
* \ingroup eventdisplay fairroot_singleton
Expand All @@ -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; }
Expand Down Expand Up @@ -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; }

Expand All @@ -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);
Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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);
Expand Down Expand Up @@ -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&);
Expand Down
9 changes: 7 additions & 2 deletions fairroot/eventdisplay/tracks/FairEveGeoTracks.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "FairEventManager.h" // for FairEventManager
#include "FairGetEventTime.h"
#include "FairRootManager.h" // for FairRootManager
#include "FairXMLNode.h"

#include <TBranch.h>
#include <TClonesArray.h> // for TClonesArray
Expand Down Expand Up @@ -51,6 +52,10 @@ InitStatus FairEveGeoTracks::Init()
if (status != kSUCCESS)
return status;
FairEventManager* eveManager = GetEventManager();
auto confColors = eveManager->GetXMLConfigNode("GeoTracksColors");
if (confColors) {
fPdgColor = FairXMLPdgColor(confColors);
}
auto& mngr = eveManager->GetRootManager();
fContainer = dynamic_cast<TClonesArray*>(mngr.GetObject("GeoTracks"));
if (!fContainer) {
Expand All @@ -68,7 +73,7 @@ void FairEveGeoTracks::DrawTrack(Int_t id)
if (!CheckCuts(tr))
return;
auto p = static_cast<TParticle*>(tr->GetParticle());
Color_t color = GetEventManager()->Color(p->GetPdgCode());
Color_t color = fPdgColor.GetColor(p->GetPdgCode());
TEveTrackList* trList = FindTrackGroup(p->GetName(), color);

auto track = new FairEveTrack(p, p->GetPdgCode(), trList->GetPropagator());
Expand Down Expand Up @@ -100,7 +105,7 @@ void FairEveGeoTracks::DrawAnimatedTrack(TGeoTrack* tr, double t0)
if (tr->GetPoint(0)[3] * timeScale + t0 > fTMax)
return; // first point after tmax
auto p = static_cast<TParticle*>(tr->GetParticle());
Color_t color = GetEventManager()->Color(p->GetPdgCode());
Color_t color = fPdgColor.GetColor(p->GetPdgCode());
TEveTrackList* trList = FindTrackGroup(p->GetName(), color);
auto track = new FairEveTrack(p, p->GetPdgCode(), trList->GetPropagator());
track->SetElementTitle(Form("p={%4.3f,%4.3f,%4.3f}", p->Px(), p->Py(), p->Pz()));
Expand Down
3 changes: 3 additions & 0 deletions fairroot/eventdisplay/tracks/FairEveGeoTracks.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@

#include "FairEveTracks.h" // for FairEveTracks
#include "FairTask.h" // for InitStatus
#include "FairXMLPdgColor.h"

#include <FairTimebasedDataHandlerT.h>
#include <Rtypes.h> // for THashConsistencyHolder, ClassDef
#include <RtypesCore.h> // for Bool_t, Int_t, Double_t

class TBuffer;
class TClass;
class TClonesArray;
Expand All @@ -41,6 +43,7 @@ class FairEveGeoTracks : public FairEveTracks
Int_t fPdgCut;
Double_t fTMin, fTMax;
TBranch* fBranch = nullptr;
FairXMLPdgColor fPdgColor;
FairTimebasedDataHandlerT<TGeoTrack> fGeoTrackHandler;

protected:
Expand Down
Loading
Loading