Skip to content

Commit a4244ea

Browse files
committed
[mlp] Prepare mlp for TEventLists that don't auto-register to gDirectory.
When TEventLists don't register themselves to gDirectory, TTree::Draw expressions can't fill them. Therefore, a few lists need to be added to gDirectory manually. Once their Draw expressions have run, they are removed again.
1 parent b41106e commit a4244ea

2 files changed

Lines changed: 19 additions & 5 deletions

File tree

math/mlp/src/TMLPAnalyzer.cxx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,8 @@ void TMLPAnalyzer::DrawNetwork(Int_t neuron, const char* signal, const char* bg)
350350
// build event lists for signal and background
351351
TEventList* signal_list = new TEventList("__tmpSig_MLPA");
352352
TEventList* bg_list = new TEventList("__tmpBkg_MLPA");
353+
signal_list->SetDirectory(gDirectory);
354+
bg_list->SetDirectory(gDirectory);
353355
data->Draw(">>__tmpSig_MLPA",signal,"goff");
354356
data->Draw(">>__tmpBkg_MLPA",bg,"goff");
355357

math/mlp/src/TMultiLayerPerceptron.cxx

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -459,12 +459,12 @@ TMultiLayerPerceptron::TMultiLayerPerceptron(const char * layout, TTree * data,
459459
fCurrentTree = -1;
460460
fCurrentTreeWeight = 1;
461461
{
462-
TDirectory::TContext ctxt;
462+
TDirectory::TContext ctxt{nullptr};
463463
fTraining = new TEventList(Form("fTrainingList_%zu",(size_t)this));
464464
}
465465
fTrainingOwner = true;
466466
{
467-
TDirectory::TContext ctxt;
467+
TDirectory::TContext ctxt{nullptr};
468468
fTest = new TEventList(Form("fTestList_%zu",(size_t)this));
469469
}
470470
fTestOwner = true;
@@ -479,8 +479,12 @@ TMultiLayerPerceptron::TMultiLayerPerceptron(const char * layout, TTree * data,
479479
fManager = nullptr;
480480
if (data) {
481481
BuildNetwork();
482+
fTraining->SetDirectory(gDirectory);
483+
fTest->SetDirectory(gDirectory);
482484
data->Draw(Form(">>fTrainingList_%zu",(size_t)this),training,"goff");
483485
data->Draw(Form(">>fTestList_%zu",(size_t)this),(const char *)testcut,"goff");
486+
fTraining->SetDirectory(nullptr);
487+
fTest->SetDirectory(nullptr);
484488
AttachData();
485489
}
486490
else {
@@ -538,12 +542,12 @@ TMultiLayerPerceptron::TMultiLayerPerceptron(const char * layout,
538542
fCurrentTree = -1;
539543
fCurrentTreeWeight = 1;
540544
{
541-
TDirectory::TContext ctxt;
545+
TDirectory::TContext ctxt{nullptr};
542546
fTraining = new TEventList(Form("fTrainingList_%zu",(size_t)this));
543547
}
544548
fTrainingOwner = true;
545549
{
546-
TDirectory::TContext ctxt;
550+
TDirectory::TContext ctxt{nullptr};
547551
fTest = new TEventList(Form("fTestList_%zu",(size_t)this));
548552
}
549553
fTestOwner = true;
@@ -558,8 +562,12 @@ TMultiLayerPerceptron::TMultiLayerPerceptron(const char * layout,
558562
fManager = nullptr;
559563
if (data) {
560564
BuildNetwork();
565+
fTraining->SetDirectory(gDirectory);
566+
fTest->SetDirectory(gDirectory);
561567
data->Draw(Form(">>fTrainingList_%zu",(size_t)this),training,"goff");
562568
data->Draw(Form(">>fTestList_%zu",(size_t)this),(const char *)testcut,"goff");
569+
fTraining->SetDirectory(nullptr);
570+
fTest->SetDirectory(nullptr);
563571
AttachData();
564572
}
565573
else {
@@ -646,12 +654,14 @@ void TMultiLayerPerceptron::SetTrainingDataSet(const char * train)
646654
{
647655
if(fTraining && fTrainingOwner) delete fTraining;
648656
{
649-
TDirectory::TContext ctxt;
657+
TDirectory::TContext ctxt{nullptr};
650658
fTraining = new TEventList(Form("fTrainingList_%zu",(size_t)this));
651659
}
652660
fTrainingOwner = true;
653661
if (fData) {
662+
fTraining->SetDirectory(gDirectory);
654663
fData->Draw(Form(">>fTrainingList_%zu",(size_t)this),train,"goff");
664+
fTraining->SetDirectory(nullptr);
655665
}
656666
else {
657667
Warning("TMultiLayerPerceptron::TMultiLayerPerceptron","Data not set. Cannot define datasets");
@@ -673,7 +683,9 @@ void TMultiLayerPerceptron::SetTestDataSet(const char * test)
673683
}
674684
fTestOwner = true;
675685
if (fData) {
686+
fTraining->SetDirectory(gDirectory);
676687
fData->Draw(Form(">>fTestList_%zu",(size_t)this),test,"goff");
688+
fTraining->SetDirectory(nullptr);
677689
}
678690
else {
679691
Warning("TMultiLayerPerceptron::TMultiLayerPerceptron","Data not set. Cannot define datasets");

0 commit comments

Comments
 (0)