d_ana
August 22, 2023, 3:42am
1
Hello, I am a beginner.
My branches are:
*Br 0 :event_number : Int_t *
*Entries : 10 : Total Size= 745 bytes One basket in memory *
*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 *
…
*Br 1 :momentum_unit : Int_t *
*Entries : 10 : Total Size= 739 bytes One basket in memory *
*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 *
…
*Br 2 :particles : Int_t particles_ *
*Entries : 10 : Total Size= 92400 bytes One basket in memory *
*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 *
…
*Br 3 :particles.pid : Int_t pid[particles_] *
*Entries : 10 : Total Size= 7711 bytes One basket in memory *
*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00
…
where Br 3 has 10 entries and each of those 10 entries have varying sub-entries when I used TBrowser to check individual
event_numberplots for example,
tree->Draw(“particles.pid”, “event_number==1”), but i am not able to access the sub-entries and when I print
particles.pid` it only returns 24 subentries repeatedly for all 10 entries.
Any suggestions? Thank you!!!
My current C code is:
TFile f("TTreefile.root");
TTree* tree;
f.GetObject("tree", tree);
Int_t totalEntries = tree->GetEntries();
Int_t event_number, momentum_unit, pid[particles_];
tree->SetBranchAddress("event_number",&event_number);
tree->SetBranchAddress("particles", &particles_);
tree->SetBranchAddress("particles.pid", pid);
for (int i = 0; i < totalEntries; ++i) {
tree->GetEntry(i);
for (Int_t j=0; j< particles_; ++j){
printf("Sub-entry %d: %d\n", i++, pid[i]);
}
}
ROOT Version: 6.26/06
Platform: mac
Compiler: Not Provided
couet
August 22, 2023, 6:47am
2
Welcome to the ROOT forum
Maybe you can provide your file TTreefile.root
in order to inspect it ?
d_ana
August 25, 2023, 5:52pm
3
I am not able to attach or link the root file as I am a new user, is there is a way to share the root file?
Thank you!!
Dear @d_ana ,
Is this a good starting point for you?
ROOT::RDataFrame df{"tree", "TTreefile.root"};
df.Display()->Print();
Or equivalently in Python
df = ROOT.RDataFrame("tree", "TTreefile.root")
df.Display().Print()
For other operations you can define on your dataset, see the docs at ROOT: ROOT::RDataFrame Class Reference
Cheers,
Vincenzo
d_ana
August 26, 2023, 10:06pm
5
Thank you for the quick response. I am trying what you suggested, but is df.Display().Print()
not supposed to print out anything?
Dear @d_ana ,
Not sure what you mean, Display
does what the documentation suggests
$: rootls -l Run2012BC_DoubleMuParked_Muons.root
TTree May 20 06:17 2019 Events;75 "Events" [current cycle]
TTree May 20 06:17 2019 Events;74 "Events" [backup cycle]
$: python -c "import ROOT; df = ROOT.RDataFrame('Events','Run2012BC_DoubleMuParked_Muons.root'); df.Display().Print()"
+-----+-------------+------------+-----------+-------------+----------+-------+
| Row | Muon_charge | Muon_eta | Muon_mass | Muon_phi | Muon_pt | nMuon |
+-----+-------------+------------+-----------+-------------+----------+-------+
| 0 | -1 | 1.06683f | 0.105658f | -0.0342727f | 10.7637f | 2 |
| | -1 | -0.563787f | 0.105658f | 2.54262f | 15.7365f | |
+-----+-------------+------------+-----------+-------------+----------+-------+
| 1 | 1 | -0.427780f | 0.105658f | -0.274792f | 10.5385f | 2 |
| | -1 | 0.349225f | 0.105658f | 2.53978f | 16.3271f | |
+-----+-------------+------------+-----------+-------------+----------+-------+
| 2 | 1 | 2.21086f | 0.105658f | -1.22341f | 3.27533f | 1 |
+-----+-------------+------------+-----------+-------------+----------+-------+
| 3 | 1 | -1.58824f | 0.105658f | -2.07730f | 11.4292f | 4 |
| | 1 | -1.75118f | 0.105658f | 0.251358f | 17.6340f | |
| | 1 | -1.59100f | 0.105658f | -2.01305f | 9.62473f | |
| | 1 | -1.65596f | 0.105658f | -1.84997f | 3.50223f | |
+-----+-------------+------------+-----------+-------------+----------+-------+
| 4 | -1 | -2.17248f | 0.105658f | -2.37001f | 3.28344f | 4 |
| | -1 | -2.18253f | 0.105658f | -2.30514f | 3.64401f | |
| | 1 | -1.12336f | 0.105658f | -0.975242f | 32.9112f | |
| | 1 | -1.16290f | 0.105658f | -0.773005f | 23.7218f | |
+-----+-------------+------------+-----------+-------------+----------+-------+
d_ana
August 27, 2023, 10:48pm
7
Thank you @vpadulan , I think using RDataFrame
is the right direction to explore.
One follow-up question: Is there a docs reference to save df.Display().Print()
? Or something that would expand the entries ...
e.g.:
+-----+----------------+
| Row | particles.mass |
+-----+----------------+
| 5 | 0.93827000 |
| | 0.93827000 |
| | 0.0000000 |
| | 0.0000000 |
| | 1.5000000 |
| | 1.5000000 |
| | 0.0000000 |
| | 0.0000000 |
| | 0.0000000 |
| | 0.0000000 |
| | ... |
+-----+----------------+
``
HI @d_ana ,
Sure, it’s all in the docs ROOT: ROOT::RDF::RInterface< Proxied, DataSource > Class Template Reference .
nMaxCollectionElements Maximum number of collection elements to display per row.
d_ana
August 28, 2023, 5:15pm
9
Thank you @vpadulan for all your help!