ROOT team hello,
I am a beginner (apologize) and trying to read a value of Jet.Pt. from a 3-event root file, which I attached.
My code is as follows:
{
gROOT->ProcessLine(".L $ROOTSYS/lib/libPhysics.so");
gROOT->ProcessLine(".L Event.cxx");
Int_t jetsize;
Event *event;
Track *track;
TClonesArray *a=new TClonesArray();
TFile *fi=new TFile("Event.root","READ");
TTree *mt=(TTree *)fi->Get("LHCO;1");
mt->SetBranchAddress("Jet_size",&jetsize);
mt->GetEntry(2);
mt->Show();
Event *event= new Event();
TBranch *branch = mt->GetBranch("Jet");
mt->SetBranchAddress("Jet",&a);
cout << endl;
cout << jetsize << endl;
cout << &event << endl;
Track *track= new Track();
*track=a[1];
cout << track->GetPt() << endl;
};
However, I only succeed in getting the value of the Jet_size. Here is the output (of the third event):
======> EVENT:2
Event = 1
Event.fUniqueID = 0
Event.fBits = 50331648
Event.Number = 3
Event.Trigger = 3585
Event_size = 1
Photon_size = 0
Electron_size = 0
Muon_size = 0
Tau_size = 0
Jet = 6
Jet.fUniqueID = 0, 0, 0, 0, 0, 0
Jet.fBits = 50331648, 50331648, 50331648, 50331648, 50331648, 50331648
Jet.PT = 881.47, 471.62, 359.37, 60.55, 50.7, 52.95
Jet.Eta = 0.448, -0.025, 1.141, 1.636, 2.31, -1.545
Jet.Phi = 2.447, 5.196, 6.122, 0.484, 4.467, 5.449
Jet.Mass = 59.35, 55.58, 16.82, 7.61, 5.3, 5.33
Jet.Ntrk = 20, 29, 24, 25, 7, 4
Jet.BTag = 0, 0, 0, 0, 0, 0
Jet.EhadOverEem = 2.83, 2.18, 1.53, 1.97, 1.59, 0.49
Jet.Index = 1, 2, 3, 4, 5, 6
Jet_size = 6
MissingET = 1
MissingET.fUniqueID = 0
MissingET.fBits = 50331648
MissingET.MET = 35.33
MissingET.Phi = 5.373
MissingET_size = 1
6
0x118c680
0
Only the Jet_size reading (i.e. 6) is correct. My question is, how do I read also the values of e.g. Jet.PT (or e.g. Jet.Phi). For example I want to read the value of 881.47 (the first Jet.PT). What am I doing wrong?
Thanks very much in advance.
Event.root (18.8 KB)
couet
June 8, 2015, 12:12pm
2
I think we also need Event.cxx:
you do:
gROOT->ProcessLine(".L Event.cxx");
Hi.
I used this line in the code (it’s the second line).
I attach Event.cxx.
Thanks.
Event.cxx (18 KB)
couet
June 8, 2015, 12:52pm
4
I get:
root [0] .x diaspar.C
Error: cannot open file "Event.h" Event.cxx:87:
*** Interpreter error recovered ***
Error: Symbol Event is not defined in current scope diaspar.C:5:
Error: Symbol event is not defined in current scope diaspar.C:5:
*** Interpreter error recovered ***
I’m sorry about this, I don’t know why this happens.
I changed the code a bit and removed references to events:
{
gROOT->ProcessLine(".L $ROOTSYS/lib/libPhysics.so");
Int_t jetsize;
TFile *fi=new TFile("Event.root","READ");
TTree *mt=(TTree *)fi->Get("LHCO;1");
mt->SetBranchAddress("Jet_size",&jetsize);
mt->GetEntry(2);
mt->Show();
TBranch *branch = mt->GetBranch("Jet");
cout << endl;
cout << jetsize << endl;
};
couet
June 8, 2015, 1:28pm
6
I'm sorry about this, I don't know why this happens.
because you forgot to send Event.h
I also send Event.h.
Event.h (7.82 KB)
couet
June 9, 2015, 7:22am
8
You should get all the Tracks from event using:
TClonesArray *All_Tracks = Event->GetTracks();
and the you us GetPt() on the track you need.
Got it.
One needs to install Pavel Demin’s package, ExRootAnalysis (available on the MADGRAPH site), and write the code from his README file:
{
gSystem->Load("ExRootAnalysis/libExRootAnalysis.so");
gSystem->Load("libPhysics");
TChain chain("LHCO");
chain.Add("Event.root");
ExRootTreeReader *treeReader = new ExRootTreeReader(&chain);
Long64_t numberOfEntries = treeReader->GetEntries();
TClonesArray *branchJet = treeReader->UseBranch("Jet");
for(Int_t entry = 0; entry < numberOfEntries; ++entry) {
treeReader->ReadEntry(entry);
TRootJet *jet = (TRootJet*) branchJet->At(1);
cout << jet->PT << endl;
}
}
This will give access to all the track numbers.