Fork me on GitHub

Opened 7 years ago

Closed 7 years ago

#1168 closed Bug (fixed)

Unknown Directory Delphes

Reported by: Goko Owned by:
Priority: minor Milestone:
Component: Delphes code Version: Delphes 3
Keywords: unknown directory Cc:

Description

Hello everyone,

My problem is about root but looks like little bit also Delphes.
I think a person may solve this.

I have a delphes_output.root file.
I want to open this data with the TFile method and access histograms.

When i list the root file with f.ls();
I see this:

https://ibb.co/mHcKkG

It says, unknown directory Delphes..

I want to access JetEta...
Under the Delphes, i can see Jet->JetEta etc.
When i use TBrowser i can access all of them.

So, I don't know the method how to access this.

I also asked root forum's but couldn't find an answer.
Thank you.

Attachments (2)

JetPlot.C (3.4 KB ) - added by Goko 7 years ago.
Example1.C (2.6 KB ) - added by Goko 7 years ago.

Download all attachments as: .zip

Change History (16)

comment:1 by Pavel Demin, 7 years ago

Please have a look at WorkBook/QuickTour. It contains the answers to your questions.

comment:2 by Goko, 7 years ago

Hi, Thank you for your answer.

I already can access all branches and can loop all over events etc.
I use all Delphes examples.

My problem is a little bit different.
I have a macro and ı use this macro for overlap root files.
I have two data one is pythia6 + ATLAS other is pythia8 + ATLAS.
My macro is not working so first i try to solve one root file's problem.
Because of this i asked how to access with f.cd("Delphes");.
Gives error and says "unknown directory delphes" so first i need to overcome this problem.
if i solve it probably my macro will work.

Thank you.

Last edited 7 years ago by Goko (previous) (diff)

comment:3 by Goko, 7 years ago

İf you look at the screenshot which i sent you, you can see i listed root file.
There are Proccess ID's and at the end of the list there is Delphes.
Normally if you look with TBrowser i can open Delphes and than can access to Jet, Muon, electron etc.
But when i try with::
TFile *f = new TFile("my_root_file.root");
f.ls();
than, f.cd("Delphes");
I want to access Delphes->Jet->JetEta..
What should i write command line to access JetEta ?

Thank you.

Version 0, edited 7 years ago by Goko (next)

comment:4 by Pavel Demin, 7 years ago

From your description of the problem it's unclear why you expect f.cd("Delphes") to work.

Delphes in the ROOT file isn't a directory it's a ROOT tree. As far as I know, it can only be accessed with the Get method:

TFile *f = TFile::Open("delphes_output.root");
TTree *delphes = (TTree *) f->Get("Delphes");

To analyze overlapping files, I'd suggest to have a look at the ROOT tree friends example:

https://root.cern.ch/root/html/tutorials/tree/treefriend.C.html

Last edited 7 years ago by Pavel Demin (previous) (diff)

comment:5 by Goko, 7 years ago

Thank you so much.
Now it's clear.
I look the tree friend example.

comment:6 by Pavel Demin, 7 years ago

I already can access all branches and can loop all over events etc.
I use all Delphes examples.

I'm afraid that I don't understand what is your problem.

If you can access all the branches, then you should be able to read jet's eta without any problem.

The only code that I can propose is already more or less in the examples:

gSystem->Load("libDelphes");

// Create chain of root trees
TChain chain("Delphes");
chain.Add("delphes_output.root");

// Create object of class ExRootTreeReader
ExRootTreeReader *treeReader = new ExRootTreeReader(&chain);
Long64_t numberOfEntries = treeReader->GetEntries();

// Get pointers to branches used in this analysis
TClonesArray *branchJet = treeReader->UseBranch("Jet");

// Loop over all events
for(Int_t entry = 0; entry < numberOfEntries; ++entry) {

  // Load selected branches with data from specified event
  treeReader->ReadEntry(entry);

  // Loop over all jets
  for(Int_t i = 0; i < branchJet->GetEntries(); ++i) {

    // Take jet
    Jet *jet = (Jet*) branchJet->At(i);
    
    // Print jet's eta
    cout << jet->Eta << endl;
  }
}

comment:8 by Goko, 7 years ago

Yes probably i couldn't tell my problem clear.
My Colleague gives me some works to do.
First work was to access all branches + loop over all events then make plots.
(i did first work)
Second one is, use two different root files.
my data's are
1- pythia6 + ATLAS
2- pythia8 + ATLAS
so i need to take data from each root file than, make plot in one histo.
(compare data)
For example compare pythia6 jet-eta vs pythia8 jet-eta in same plot.
datas will be recive from different root files.

he gave me a macro, but he didint tell me whats wrong with it.

now if you go back the first question:

i was supposing that my macro doesnt work because i couldnt acces the list..
But now, i understand it's not about listing or something else.

maybe while i am trying to look your examples, you can understand what is wrong with my macro.

thank you so much.

Last edited 7 years ago by Goko (previous) (diff)

by Goko, 7 years ago

Attachment: JetPlot.C added

comment:9 by Pavel Demin, 7 years ago

Thanks for providing the JetPlot.C script. It helped me to better understand your problem.

This script doesn't read the files generated by Delphes. This scripts reads histograms from two separate files and draws them on the same canvas.

I think that AddFriend isn't needed to solve this problem.

You'll just need to loop over all events and make histograms for each of the two root files generated by Delphes. After this step you'll have two sets of histograms. Then you'll need to apply SavePlot from the script to each pair of histograms.

comment:10 by Goko, 7 years ago

Thank you for identifying my problem.

Under the Delphes/Examples/Example2.C shows everything how to access branches and so on.
Just changing the parameters I did some examples like JetEta, MuonCharge etc.

But I don't think, I can do this example from the beginning.
Would be great if I had an example!
Thank you.


comment:11 by Goko, 7 years ago

Edit::
Or I will try to do like this.
My first macro was putting all histograms in a root file.
Probably PlotJet.C takes root (with histogram).
I try this...

comment:12 by Goko, 7 years ago

Dear pavel,
Thank you so much for your kindness and help.
After you said "the script read histograms from two seperate files..." i realized my fault!
From Delphes/Examples i found a macro which puts all histograms to result.root file.
And with that result.root, i run my macro again now it's working.
Thank you again.

by Goko, 7 years ago

Attachment: Example1.C added

comment:13 by Goko, 7 years ago

Also you can close the ticket.
My problem Solved.

comment:14 by Pavel Demin, 7 years ago

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.