kyu
January 9, 2025, 9:57am
1
Dear experts,
I am using the CopyTree to filter the tuple. But I found there are something wrong.
For some variable the value changed after the filtering.
I have a branch with name “DataType” which indicate when the data is taken. For LHC Run2 Data it should be in the range of 2015 - 2018 , as you can find the information in the /afs/cern.ch/work/k/kyu/public/ROOT/CopyTree/input.root
.
[ 10:35:52 kyu@lxplus919 /afs/cern.ch/work/k/kyu/public/ROOT/CopyTree]$ rl input.root
root [0]
Attaching file input.root as _file0...
(TFile *) 0x55d69be32ed0
root [1] .ls
TFile** input.root
TFile* input.root
KEY: TTree DecayTree;19 [current cycle]
KEY: TTree DecayTree;18 [backup cycle]
root [2] DecayTree->GetMaximum("DataType")
(double) 2015.0000
root [3] DecayTree->Scan("DataType")
************************
* Row * DataType *
************************
* 0 * 2015 *
* 1 * 2015 *
* 2 * 2015 *
* 3 * 2015 *
* 4 * 2015 *
But after the filtering, the value of 2015 change to be the one unexpected.
[ 10:35:31 kyu@lxplus919 /afs/cern.ch/work/k/kyu/public/ROOT/CopyTree]$ rl output.root
root [0]
Attaching file output.root as _file0...
(TFile *) 0x5582716212c0
root [1] .ls
TFile** output.root
TFile* output.root
KEY: TTree DecayTree;5 [current cycle]
KEY: TTree DecayTree;4 [backup cycle]
KEY: TTree DecayTree;3 [backup cycle]
root [2] DecayTree->Scan("DataType")
************************
* Row * DataType *
************************
* 0 * 32765 *
* 1 * 32765 *
* 2 * 32765 *
* 3 * 32765 *
* 4 * 32765 *
* 5 * 32765 *
Besides, the value with 32765 could be chanded depend on which root version you used. such one is the result by the /cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.34.02/x86_64-almalinux9.5-gcc115-opt/bin/root
I also tries /cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.32.06/x86_64-almalinux9.4-gcc114-opt/bin/root
, It will becom another number.
Though such variable is useless in the analysis, but it is hard to understand, if it can not be resolved, the output is not reliable.
ROOT Version: 6.34.02 in LCG release
Platform: lxplus
Welcome to the ROOT Forum!
Can you show the code you are using?
kyu
January 9, 2025, 10:29am
3
Hello, Bertrand.
Many thanks for your reply.
The detail of the code and the working example are all listed in the lxplus. can be found here : /afs/cern.ch/work/k/kyu/public/ROOT/CopyTree
And of course, I can attatch the code here.
#include "./Get_Cut.h"
TCut in_range(const char *Var, Double_t low, Double_t up) { return TCut(Form("%s>%f && %s<%f", Var, low, Var, up)); }
TCut get_Trigger(TTree *tree, TString Particle) { return get_L0_Trigger(Particle) + get_HLT_Trigger(tree, Particle); }
void Cut_Data(TString input = "input.root", TString output = "output.root" ) {
TString TreeName = "DecayTree";
TChain *chain = new TChain(TreeName);
cout << "Input File : " << chain->Add(input) << " files in " << input << endl;
cout << "oldTree events = " << chain->GetEntries() << endl;
TCut cut = /* The details of the Cut */ ;
cout << "Present Cut : " << cut << endl;
TFile *outFile = TFile::Open(output, "recreate") ;
TTree *newTree = chain->CopyTree(cut) ;
Int_t Nentries = newTree->GetEntriesFast() ;
cout<<"newTree events = "<<Nentries<<endl;
newTree->Write() ;
outFile->Write() ;
outFile->Close() ;
}
OK, thanks. So after a first try with ROOT master on Windows, it seems to work fine:
C:\root-dev\rootdev\CopyTree>root -l Cut_Data.C
root [0]
Processing Cut_Data.C...
Input File : 1 files in input.root
oldTree events = 75167
(Lb_Hlt1TrackMVADecision_TOS || Lb_Hlt1TwoTrackMVADecision_TOS || Lb_Hlt1TrackAllL0Decision_TOS)&&(Lb_Hlt2Topo2BodyDecision_TOS || Lb_Hlt2Topo3BodyDecision_TOS || Lb_Hlt2Topo4BodyDecision_TOS || Lb_Hlt2IncPhiDecision_TOS)
(Lb_L0HadronDecision_TOS)||(Lb_L0ElectronDecision_TIS || Lb_L0PhotonDecision_TIS || Lb_L0HadronDecision_TIS || Lb_L0MuonDecision_TIS || Lb_L0DiMuonDecision_TIS)
Lc_p_ProbNNp_Tune>0.10 && Lc_K_ProbNNk_Tune>0.10 && Lc_pi_ProbNNpi_Tune>0.10 && Ds_Kp_ProbNNk_Tune>0.10 && Ds_Km_ProbNNk_Tune>0.10 && Ds_pi_ProbNNpi_Tune>0.10 && Kp_ProbNNk_Tune>0.10 && Km_ProbNNk_Tune>0.10
Present Cut : (((DTFonlyPV_Lb_M>5350.000000 && DTFonlyPV_Lb_M<6200.000000)&&(Lc_p_ProbNNp_Tune>0.10 && Lc_K_ProbNNk_Tune>0.10 && Lc_pi_ProbNNpi_Tune>0.10 && Ds_Kp_ProbNNk_Tune>0.10 && Ds_Km_ProbNNk_Tune>0.10 && Ds_pi_ProbNNpi_Tune>0.10 && Kp_ProbNNk_Tune>0.10 && Km_ProbNNk_Tune>0.10))&&(((Lb_L0HadronDecision_TOS)||(Lb_L0ElectronDecision_TIS || Lb_L0PhotonDecision_TIS || Lb_L0HadronDecision_TIS || Lb_L0MuonDecision_TIS || Lb_L0DiMuonDecision_TIS))&&((Lb_Hlt1TrackMVADecision_TOS || Lb_Hlt1TwoTrackMVADecision_TOS || Lb_Hlt1TrackAllL0Decision_TOS)&&(Lb_Hlt2Topo2BodyDecision_TOS || Lb_Hlt2Topo3BodyDecision_TOS || Lb_Hlt2Topo4BodyDecision_TOS || Lb_Hlt2IncPhiDecision_TOS))))&&((((((Lc_ENDVERTEX_Z-Lb_ENDVERTEX_Z>-2)&&(Ds_ENDVERTEX_Z-Lb_ENDVERTEX_Z>-2))&&((Ds_ENDVERTEX_CHI2/Ds_ENDVERTEX_NDOF<10)&&(Lb_ENDVERTEX_CHI2/Lb_ENDVERTEX_NDOF<10)))&&(Lb_IPCHI2_OWNPV<20))&&((Ds_DIRA_OWNPV>0.995)&&(Lb_DIRA_OWNPV>0.995)))&&(Lb_DTFonlyPV_chi2/Lb_DTFonlyPV_nDOF < 10))
newTree events = 13765
root [1] .q
C:\root-dev\rootdev\CopyTree>root -l output.root
root [0]
Attaching file output.root as _file0...
(TFile *) 0x27d70190c40
root [1] .ls
TFile** output.root
TFile* output.root
KEY: TTree DecayTree;5 [current cycle]
KEY: TTree DecayTree;4 [backup cycle]
KEY: TTree DecayTree;3 [backup cycle]
root [2] DecayTree->Scan("DataType")
************************
* Row * DataType *
************************
* 0 * 2015 *
* 1 * 2015 *
* 2 * 2015 *
* 3 * 2015 *
* 4 * 2015 *
* 5 * 2015 *
* 6 * 2015 *
* 7 * 2015 *
* 8 * 2015 *
* 9 * 2015 *
* 10 * 2015 *
* 11 * 2015 *
* 12 * 2015 *
* 13 * 2015 *
* 14 * 2015 *
* 15 * 2015 *
* 16 * 2015 *
* 17 * 2015 *
* 18 * 2015 *
* 19 * 2015 *
* 20 * 2015 *
* 21 * 2015 *
* 22 * 2015 *
* 23 * 2015 *
* 24 * 2015 *
Type <CR> to continue or q to quit ==>
I’ll try with another ROOT version on another computer
kyu
January 9, 2025, 11:50am
5
Many thanks for your time and patience here.
But what I used is the root from LCG release , in the cvmfs . ( /cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.34.02/x86_64-almalinux9.5-gcc115-opt/bin/root
)
And the platform is the AlmaLinux 9 .
Maybe something wrong for the root release ?
So it works on Windows but I see a problem on Linux. Maybe @couet can give it a try on MacOS?
I see the same problem with master on Ubuntu after running Cut_Data.C
:
root [1] DecayTree->Scan("DataType")
************************
* Row * DataType *
************************
* 0 * 0 *
* 1 * 0 *
* 2 * 0 *
* 3 * 0 *
* 4 * 0 *
* 5 * 0 *
* 6 * 0 *
* 7 * 0 *
* 8 * 0 *
* 9 * 0 *
* 10 * 0 *
* 11 * 0 *
* 12 * 0 *
* 13 * 0 *
* 14 * 0 *
* 15 * 0 *
* 16 * 0 *
* 17 * 0 *
* 18 * 0 *
* 19 * 0 *
* 20 * 0 *
* 21 * 0 *
* 22 * 0 *
* 23 * 0 *
* 24 * 0 *
Type <CR> to continue or q to quit ==> q
Note that for me, the DataType
are always zero. Maybe @pcanal could also take a look?
pcanal
January 9, 2025, 5:54pm
9
The problem is line Get_Cut.h:27
:
Int_t DataType ; tree->SetBranchAddress("DataType", &DataType) ; tree->GetEntry(0);
which associates a local variable address to the TTree
. This is fine, however this association persist beyond the end of the get_HLT_Trigger
function and the next call to GetEntry
(which happens to be inside the CloneTree
will lead the TTree
to still write to this address … which is by then ‘invalid’/‘reused by something else’ leading to random behavior (in my case, it leads to a segmentation fault).
To solve the problem call tree->ResetBranchAddresses();
at the end of the function:
*** Get_Cut.orig 2025-01-09 11:13:26.746882310 -0600
--- Get_Cut.h 2025-01-09 11:13:47.451489682 -0600
***************
*** 60,65 ****
--- 60,66 ----
TCut Trigger = HLT1_Trigger + HLT2_Trigger ;
+ tree->ResetBranchAddresses();
cout<<Trigger<<endl<<endl;
return Trigger ;
}
2 Likes
system
Closed
January 24, 2025, 4:08am
11
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.