Hello, I have a problem with read leaf. I attach a file with a root tree. My tree has branches, and then the branches have files. In all the examples and in the tutorial, SetBranchAddress
is used, but I have no idea how to apply it in my case.
decay3.root (1.0 MB)
Please read tips for efficient and successful posting and posting code
ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided
couet
January 6, 2021, 2:35pm
2
I guess @pcanal can help you.
Should I write to him in private messages?
couet
January 6, 2021, 3:00pm
4
No, he will see this post.
Hi,
you need to read ROOT data stored in a TTree? The easiest way is probably to use RDataFrame. Docs , tutorials .
Otherwise, please share a minimal program that should do what you want so we can point out how to improve it.
Cheers,
Enrico
Look,
I need to take data from leaves. That is, for example, I have a path: Decay3->LV1->Energy()
, where Energy()
is an array of double (I guess I don’t know what it is. If you tell me a way to find out that it will be grateful too). I want to use this data to build a histogram, say:
TH2D* his(...);
TFile* f = new TFile(...);
TTree* decay;
gDirectory->GetObject("Decay3", decay);
for (int i; i < all point in file; i++)
{
TLorentzVector one (Decay3->LV1->Px(), Decay3->LV1->Py(), Decay3->LV1->Pz(), Decay3->LV1->Energy());
TLorentzVector two (Decay3->LV2->Px(), Decay3->LV2->Py(), Decay3->LV2->Pz(), Decay3->LV2->Energy());
TLorentzVector tree (Decay3->LV3->Px(), Decay3->LV3->Py(), Decay3->LV3->Pz(), Decay3->LV3->Energy());
his->Fill( (one + two).M(), (tree + two).M() );
}
And the problem is Decay3->LV3->Px()
. I don’t understand how to read and take this data.
Can you share the output of decay->Print()
(it will also tell you what type the leaves are)?
Or with RDataFrame you can explore the dataset interactively at the root prompt, for example:
$ root
root [0] ROOT::RDataFrame df("Decay3", "filename.root");
root [1] df.GetColumnNames()
root [2] df.GetColumnType("LV1")
or also
$ root filename.root
root [0] Decay3->Print()
Yes of course. If that I have attached the file to the post.
******************************************************************************
*Tree :Decay3 : Decay3 *
*Entries : 6405 : Total = 1099229 bytes File Size = 1082198 *
* : : Tree compression factor = 1.00 *
******************************************************************************
*Branch :LV1 *
*Entries : 6405 : BranchElement (see below) *
*............................................................................*
*Br 0 :fUniqueID : UInt_t *
*Entries : 6405 : Total Size= 26203 bytes File Size = 25698 *
*Baskets : 1 : Basket Size= 32000 bytes Compression= 1.00 *
*............................................................................*
*Br 1 :fBits : UInt_t *
*Entries : 6405 : Total Size= 51975 bytes File Size = 51486 *
*Baskets : 3 : Basket Size= 32000 bytes Compression= 1.00 *
*............................................................................*
*Br 2 :fP : *
*Entries : 6405 : Total Size= 3630 bytes One basket in memory *
*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 *
*............................................................................*
*Br 3 :fP.fUniqueID : UInt_t *
*Entries : 6405 : Total Size= 26218 bytes File Size = 25701 *
*Baskets : 1 : Basket Size= 32000 bytes Compression= 1.00 *
*............................................................................*
*Br 4 :fP.fBits : UInt_t *
*Entries : 6405 : Total Size= 51996 bytes File Size = 51495 *
*Baskets : 3 : Basket Size= 32000 bytes Compression= 1.00 *
*............................................................................*
*Br 5 :fP.fX : Double_t *
*Entries : 6405 : Total Size= 51877 bytes File Size = 51388 *
*Baskets : 2 : Basket Size= 32000 bytes Compression= 1.00 *
*............................................................................*
*Br 6 :fP.fY : Double_t *
*Entries : 6405 : Total Size= 51877 bytes File Size = 51388 *
*Baskets : 2 : Basket Size= 32000 bytes Compression= 1.00 *
*............................................................................*
*Br 7 :fP.fZ : Double_t *
*Entries : 6405 : Total Size= 51877 bytes File Size = 51388 *
*Baskets : 2 : Basket Size= 32000 bytes Compression= 1.00 *
*............................................................................*
*Br 8 :fE : Double_t *
*Entries : 6405 : Total Size= 51859 bytes File Size = 51382 *
*Baskets : 2 : Basket Size= 32000 bytes Compression= 1.00 *
*............................................................................*
*Branch :LV2 *
*Entries : 6405 : BranchElement (see below) *
*............................................................................*
*Br 9 :fUniqueID : UInt_t *
*Entries : 6405 : Total Size= 26203 bytes File Size = 25698 *
*Baskets : 1 : Basket Size= 32000 bytes Compression= 1.00 *
*............................................................................*
*Br 10 :fBits : UInt_t *
*Entries : 6405 : Total Size= 51975 bytes File Size = 51486 *
*Baskets : 3 : Basket Size= 32000 bytes Compression= 1.00 *
*............................................................................*
*Br 11 :fP : *
*Entries : 6405 : Total Size= 3630 bytes One basket in memory *
*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 *
*............................................................................*
*Br 12 :fP.fUniqueID : UInt_t *
*Entries : 6405 : Total Size= 26218 bytes File Size = 25701 *
*Baskets : 1 : Basket Size= 32000 bytes Compression= 1.00 *
*............................................................................*
*Br 13 :fP.fBits : UInt_t *
*Entries : 6405 : Total Size= 51996 bytes File Size = 51495 *
*Baskets : 3 : Basket Size= 32000 bytes Compression= 1.00 *
*............................................................................*
*Br 14 :fP.fX : Double_t *
*Entries : 6405 : Total Size= 51877 bytes File Size = 51388 *
*Baskets : 2 : Basket Size= 32000 bytes Compression= 1.00 *
*............................................................................*
*Br 15 :fP.fY : Double_t *
*Entries : 6405 : Total Size= 51877 bytes File Size = 51388 *
*Baskets : 2 : Basket Size= 32000 bytes Compression= 1.00 *
*............................................................................*
*Br 16 :fP.fZ : Double_t *
*Entries : 6405 : Total Size= 51877 bytes File Size = 51388 *
*Baskets : 2 : Basket Size= 32000 bytes Compression= 1.00 *
*............................................................................*
*Br 17 :fE : Double_t *
*Entries : 6405 : Total Size= 51859 bytes File Size = 51382 *
*Baskets : 2 : Basket Size= 32000 bytes Compression= 1.00 *
*............................................................................*
*Branch :LV3 *
*Entries : 6405 : BranchElement (see below) *
*............................................................................*
*Br 18 :fUniqueID : UInt_t *
*Entries : 6405 : Total Size= 26203 bytes File Size = 25698 *
*Baskets : 1 : Basket Size= 32000 bytes Compression= 1.00 *
*............................................................................*
*Br 19 :fBits : UInt_t *
*Entries : 6405 : Total Size= 51975 bytes File Size = 51486 *
*Baskets : 3 : Basket Size= 32000 bytes Compression= 1.00 *
*............................................................................*
*Br 20 :fP : *
*Entries : 6405 : Total Size= 3630 bytes One basket in memory *
*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 *
*............................................................................*
*Br 21 :fP.fUniqueID : UInt_t *
*Entries : 6405 : Total Size= 26218 bytes File Size = 25701 *
*Baskets : 1 : Basket Size= 32000 bytes Compression= 1.00 *
*............................................................................*
*Br 22 :fP.fBits : UInt_t *
*Entries : 6405 : Total Size= 51996 bytes File Size = 51495 *
*Baskets : 3 : Basket Size= 32000 bytes Compression= 1.00 *
*............................................................................*
*Br 23 :fP.fX : Double_t *
*Entries : 6405 : Total Size= 51877 bytes File Size = 51388 *
*Baskets : 2 : Basket Size= 32000 bytes Compression= 1.00 *
*............................................................................*
*Br 24 :fP.fY : Double_t *
*Entries : 6405 : Total Size= 51877 bytes File Size = 51388 *
*Baskets : 2 : Basket Size= 32000 bytes Compression= 1.00 *
*............................................................................*
*Br 25 :fP.fZ : Double_t *
*Entries : 6405 : Total Size= 51877 bytes File Size = 51388 *
*Baskets : 2 : Basket Size= 32000 bytes Compression= 1.00 *
*............................................................................*
*Br 26 :fE : Double_t *
*Entries : 6405 : Total Size= 51859 bytes File Size = 51382 *
*Baskets : 2 : Basket Size= 32000 bytes Compression= 1.00 *
*............................................................................*
And decay->Print()
written above
decay3.root (1.0 MB)
LV1
is a TLorenzVector
:
~/Downloads root -l decay3.root (cern-root)
root [0]
Attaching file decay3.root as _file0...
(TFile *) 0x55c81e2a0510
root [0] ROOT::RDataFrame(*Decay3).GetColumnType("LV1")
(std::string) "TLorentzVector"
and to plot LV1.M() + LV2.M()
vs LV3.M() + LV2.M()
you can do e.g.:
ROOT::RDataFrame df(*Decay3);
auto df2 = df.Define("m12", "LV1.M() + LV2.M()").Define("m32", "LV3.M() + LV2.M()");
auto h2 = df2.Histo2D({"h2", "h2", ...}, "m12", "m32");
h2->Draw();
To read the LorenzVectors directly with TTree:
void foo() {
TFile f("decay3.root");
auto *t = f.Get<TTree>("Decay3");
TLorentzVector *lv1 = nullptr;
t->SetBranchAddress("LV1", &lv1);
t->GetEntry(0);
std::cout << lv1->M() << std::endl;
}
Cheers,
Enrico
system
Closed
January 21, 2021, 9:28am
11
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.