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 setup Event Display by XML files. #1386

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 6 additions & 1 deletion examples/advanced/propagator/macros/conf.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@
<mctrack color="kGreen" pdg="211"></mctrack>
<mctrack color="kYellow" pdg="11"></mctrack>
</MCTracksColors>
</xmlconf>
<FairMCTrackColors>
<mctrack color="kCyan" pdg="2212"></mctrack>
<mctrack color="kPink" pdg="211"></mctrack>
<mctrack color="kOrange" pdg="11"></mctrack>
</FairMCTrackColors>
</xmlconf>
19 changes: 16 additions & 3 deletions examples/common/eventdisplay/FairEveMCTracks.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "FairRKPropagator.h" // for FairRKPropagator
#include "FairRootManager.h" // for FairRootManager
#include "FairRunAna.h" // for FairRunAna
#include "FairXMLNode.h" // for XML support

#include <TClonesArray.h> // for TClonesArray
#include <TDatabasePDG.h> // for TDatabasePDG
Expand Down Expand Up @@ -88,7 +89,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 = fXMLConf.GetColor(tr->GetPdgCode());
TEveTrackList* trList = FindTrackGroup(Form("%i", tr->GetPdgCode()), color);
TParticle p(tr->GetPdgCode(),
0,
Expand Down Expand Up @@ -145,7 +146,7 @@ void FairEveMCTracks::Repaint()

InitStatus FairEveMCTracks::Init()
{
FairEventManager* eveManager = GetEventManager();
FairEventManager* eveManager = FairEventManager::Instance();
FairRootManager* mngr = &(eveManager->GetRootManager());
fContainer = dynamic_cast<TClonesArray*>(mngr->GetObject("MCTrack"));
if (!fContainer) {
Expand All @@ -165,7 +166,19 @@ InitStatus FairEveMCTracks::Init()
}
fRK = std::make_unique<FairRKPropagator>(field);
fPDG = TDatabasePDG::Instance();
return FairEveTracks::Init();
TString xmlConfig = eveManager->GetXMLConfig();
if (xmlConfig.Length() > 4) {
FairXMLFile file(xmlConfig);
FairXMLNode* root = file.GetRootNode();
FairXMLNode* mcColors = root->GetChild("FairMCTrackColors"); // lok for MCtrack colors
if (!mcColors) { // not found MCTracks? maybe there is a general branch for MC colors
root->GetChild("MCTracksColors");
LOG(warning) << "Cannot find FairMCTrackColors";
}
if (mcColors)
fXMLConf = FairXMLPdgColor(mcColors);
}
return kSUCCESS;
}

FairEveMCTracks::~FairEveMCTracks() = default;
2 changes: 2 additions & 0 deletions examples/common/eventdisplay/FairEveMCTracks.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

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

#include <FairRKPropagator.h>
#include <Rtypes.h> // for THashConsistencyHolder, ClassDef
Expand All @@ -40,6 +41,7 @@ class FairEveMCTracks : public FairEveTracks
Int_t fPdgCut;
std::unique_ptr<FairRKPropagator> fRK{};
TDatabasePDG* fPDG{nullptr};
FairXMLPdgColor fXMLConf;

protected:
Bool_t CheckCuts(FairMCTrack *tr);
Expand Down
4 changes: 4 additions & 0 deletions fairroot/eventdisplay/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ set(sources
tracks/FairEveTracks.cxx
tracks/FairGeoTracksDraw.cxx
tracks/FairGeoTrackHandler.cxx
xml/FairXMLDetectorConf.cxx
xml/FairXMLEveConf.cxx
xml/FairXMLPdgColor.cxx
)

fair_change_extensions_if_exists(.cxx .h FILES "${sources}" OUTVAR headers)
Expand All @@ -51,6 +54,7 @@ target_include_directories(${target} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/tracks>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/gui>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/datasource>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/xml>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)

Expand Down
179 changes: 7 additions & 172 deletions fairroot/eventdisplay/FairEventManager.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include "FairRootManager.h" // for FairRootManager
#include "FairRunAna.h" // for FairRunAna
#include "FairXMLDetectorConf.h"
#include "FairXMLNode.h"

#include <TDatabasePDG.h> // for TDatabasePDG
Expand Down Expand Up @@ -70,55 +71,6 @@ FairEventManager::FairEventManager()
{
fgRinstance = this;
AddParticlesToPdgDataBase();
fPDGToColor[22] = 623; // photon
fPDGToColor[-2112] = 2; // anti-neutron
fPDGToColor[-11] = 3; // e+
fPDGToColor[-3122] = 4; // anti-lambda
fPDGToColor[11] = 5; // e-
fPDGToColor[-3222] = 6; // Sigma -
fPDGToColor[12] = 7; // e-neutrino
fPDGToColor[-3212] = 8; // Sigma0
fPDGToColor[-13] = 9; // mu+
fPDGToColor[-3112] = 10; // Sigma+ (PB
fPDGToColor[13] = 11; // mu-
fPDGToColor[-3322] = 12; // Xi0
fPDGToColor[111] = 13; // pi0
fPDGToColor[-3312] = 14; // Xi+
fPDGToColor[211] = 15; // pi+
fPDGToColor[-3334] = 16; // Omega+ (PB)
fPDGToColor[-211] = 17; // pi-
fPDGToColor[-15] = 18; // tau+
fPDGToColor[130] = 19; // K long
fPDGToColor[15] = 20; // tau -
fPDGToColor[321] = 21; // K+
fPDGToColor[411] = 22; // D+
fPDGToColor[-321] = 23; // K-
fPDGToColor[-411] = 24; // D-
fPDGToColor[2112] = 25; // n
fPDGToColor[421] = 26; // D0
fPDGToColor[2212] = 27; // p
fPDGToColor[-421] = 28; // D0
fPDGToColor[-2212] = 29; // anti-proton
fPDGToColor[431] = 30; // Ds+
fPDGToColor[310] = 31; // K short
fPDGToColor[-431] = 32; // anti Ds-
fPDGToColor[221] = 33; // eta
fPDGToColor[4122] = 34; // Lambda_C+
fPDGToColor[3122] = 35; // Lambda
fPDGToColor[24] = 36; // W+
fPDGToColor[3222] = 37; // Sigma+
fPDGToColor[-24] = 38; // W-
fPDGToColor[3212] = 39; // Sigma0
fPDGToColor[23] = 40; // Z
fPDGToColor[3112] = 41; // Sigma -
fPDGToColor[3322] = 42; // Xi0
fPDGToColor[3312] = 43; // Xi-
fPDGToColor[3334] = 44; // Omega- (PB)
fPDGToColor[50000050] = 801; // Cerenkov
fPDGToColor[1000010020] = 45;
fPDGToColor[1000010030] = 48;
fPDGToColor[1000020040] = 50;
fPDGToColor[1000020030] = 55;
}

void FairEventManager::Init(Int_t visopt, Int_t vislvl, Int_t maxvisnds)
Expand Down Expand Up @@ -253,14 +205,6 @@ void FairEventManager::Close() {}

void FairEventManager::DisplaySettings() {}

Int_t FairEventManager::Color(int pdg)
{
if (fPDGToColor.find(pdg) != fPDGToColor.end()) {
return fPDGToColor[pdg];
}
return 0;
}

void FairEventManager::AddParticlesToPdgDataBase(Int_t /*pdg*/)
{
// Add particles to the PDG data base
Expand Down Expand Up @@ -357,125 +301,16 @@ 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();
fPDGToColor[pgd_code.Atoi()] = StringToColor(color_code);
}
}
FairXMLNode* xml = xmlfile.GetRootNode();
FairXMLNode* detectors = xml->GetChild("Detectors");
if (detectors && detectors->GetNChildren()) {
TGeoNode* top = gGeoManager->GetTopNode();
FairXMLDetectorConf xmlGeoConf(detectors->GetChild(0));
xmlGeoConf.SetupNode(*top);
}
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(StringToColor(color));
node->GetVolume()->SetLineColor(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);
}
}
}
}
}

Int_t FairEventManager::StringToColor(TString color) const
{
if (color.Contains("k")) {
Int_t plus_index = color.First('+');
Int_t minus_index = color.First('-');
Int_t cut = plus_index;
if (cut == -1)
cut = minus_index;
if (cut == -1)
cut = color.Length();
TString col_name(color(0, cut));
Int_t col_val = 0;
if (col_name.EqualTo("kWhite")) {
col_val = 0;
} else if (col_name.EqualTo("kBlack")) {
col_val = 1;
} else if (col_name.EqualTo("kGray")) {
col_val = 920;
} else if (col_name.EqualTo("kRed")) {
col_val = 632;
} else if (col_name.EqualTo("kGreen")) {
col_val = 416;
} else if (col_name.EqualTo("kBlue")) {
col_val = 600;
} else if (col_name.EqualTo("kYellow")) {
col_val = 400;
} else if (col_name.EqualTo("kMagenta")) {
col_val = 616;
} else if (col_name.EqualTo("kCyan")) {
col_val = 432;
} else if (col_name.EqualTo("kOrange")) {
col_val = 800;
} else if (col_name.EqualTo("kSpring")) {
col_val = 820;
} else if (col_name.EqualTo("kTeal")) {
col_val = 840;
} else if (col_name.EqualTo("kAzure")) {
col_val = 860;
} else if (col_name.EqualTo("kViolet")) {
col_val = 880;
} else if (col_name.EqualTo("kPink")) {
col_val = 900;
}
TString col_num(color(cut + 1, color.Length()));
if (col_num.Length() > 0) {
if (color.Contains("+")) {
col_val += col_num.Atoi();
} else {
col_val -= col_num.Atoi();
}
}
return col_val;
} else {
return color.Atoi();
}
}

void FairEventManager::SetTransparency(Bool_t use_xml, Int_t trans)
{
if (!use_xml) { // high transparency
Expand Down
9 changes: 5 additions & 4 deletions fairroot/eventdisplay/FairEventManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ class FairEventManager : public TEveEventManager
virtual void PrevEvent(); // *MENU*
virtual void Close();
virtual void DisplaySettings(); // *Menu*
virtual Int_t Color(Int_t 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 @@ -85,6 +84,11 @@ class FairEventManager : public TEveEventManager
min = fTimeMin;
max = fTimeMax;
};
/**
*
* @return name of the xml file with configuration of event display
*/
TString GetXMLConfig() const { return fXMLConfig; };
virtual void AddParticlesToPdgDataBase(Int_t pdg = 0);
/**
* set detector's transparency
Expand Down Expand Up @@ -147,8 +151,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);
Int_t StringToColor(TString color) const;

private:
FairRunAna* fRunAna; //!
Expand Down Expand Up @@ -179,7 +181,6 @@ class FairEventManager : public TEveEventManager
TEveText* fEventTimeText{nullptr}; //!
TEveText* fEventNumberText{nullptr}; //!
TString fXMLConfig;
std::map<int, int> fPDGToColor;
void SetTransparencyForLayer(TGeoNode* node, Int_t depth, Char_t transparency);
static FairEventManager* fgRinstance; //!
FairEventManager(const FairEventManager&);
Expand Down
4 changes: 3 additions & 1 deletion fairroot/eventdisplay/LinkDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,7 @@
#pragma link C++ class FairTimebasedMCSource;
#pragma link C++ class FairTimebasedMCHitSource;
#pragma link C++ class FairGetEventTime + ;

#pragma link C++ class FairXMLDetectorConf + ;
#pragma link C++ class FairXMLPdgColor + ;
#pragma link C++ class FairXMLEveConf + ;
#endif
Loading