Fork me on GitHub

Ticket #1420: JetParticles.C

File JetParticles.C, 2.9 KB (added by flywire, 5 years ago)

The macro I used to get constituents in Jets

Line 
1#ifdef __CLING__
2R__LOAD_LIBRARY(libDelphes)
3#include "classes/DelphesClasses.h"
4#include "external/ExRootAnalysis/ExRootTreeReader.h"
5#include "external/ExRootAnalysis/ExRootResult.h"
6#else
7class ExRootTreeReader;
8class ExRootResult;
9#endif
10
11
12//------------------------------------------------------------------------------
13
14void AnalyseEvents(ExRootTreeReader *treeReader)
15{
16 TClonesArray *branchJet = treeReader->UseBranch("Jet");
17
18 Long64_t allEntries = treeReader->GetEntries();
19 //Long64_t allEntries = 11;
20
21 cout << "** Chain contains " << allEntries << " events" << endl;
22
23 GenParticle *particle;
24
25 Track *track;
26 Tower *tower;
27
28 Jet *jet;
29 TObject *object;
30
31 Long64_t entry;
32
33 Int_t i, j, pdgCode;
34
35 // Loop over all events
36 for(entry = 0; entry < allEntries; ++entry)
37 {
38 // Load selected branches with data from specified event
39 treeReader->ReadEntry(entry);
40
41
42 // Loop over all jets in event
43 for(i = 0; i < branchJet->GetEntriesFast(); ++i)
44 {
45 jet = (Jet*) branchJet->At(i);
46
47 cout<<"Looping over jet constituents. Jet pt: "<<jet->PT<<", eta: "<<jet->Eta<<", phi: "<<jet->Phi<<" # constituents: "<<jet->Constituents.GetEntriesFast()<<endl;
48 //cout<<"Looping over jet particles. Jet pt: "<<jet->PT<<", eta: "<<jet->Eta<<", phi: "<<jet->Phi<<" # particles: "<<jet->Particles.GetEntriesFast()<<endl;
49
50 // Loop over all jet's constituents
51 for(j = 0; j < jet->Constituents.GetEntriesFast(); ++j)
52 {
53 object = jet->Constituents.At(j);
54 //cout << "The cons UID is: " << jet->Constituents.GetUID(j) << endl;
55 //cout << jet->Constituents << endl;
56
57 // Check if the constituent is accessible
58 if(object == 0) {
59 //cout << "constituent not accessible " << endl;
60 continue;
61 }
62
63 if(object->IsA() == GenParticle::Class())
64 {
65 particle = (GenParticle*) object;
66 cout << " GenPart pt: " << particle->PT << ", eta: " << particle->Eta << ", phi: " << particle->Phi << endl;
67 }
68 else if(object->IsA() == Track::Class())
69 {
70 track = (Track*) object;
71 cout << " Track pt: " << track->PT << ", eta: " << track->Eta << ", phi: " << track->Phi << endl;
72 }
73 else if(object->IsA() == Tower::Class())
74 {
75 tower = (Tower*) object;
76 cout << " Tower pt: " << tower->ET << ", eta: " << tower->Eta << ", phi: " << tower->Phi << endl;
77 }
78 else{
79 cout << " constituent type: " << object->IsA() << endl;
80 }
81 }
82 }
83 }
84}
85
86void JetParticles(const char *inputFile)
87{
88 gSystem->Load("libDelphes");
89
90 TChain *chain = new TChain("Delphes");
91 chain->Add(inputFile);
92
93 ExRootTreeReader *treeReader = new ExRootTreeReader(chain);
94 ExRootResult *result = new ExRootResult();
95
96 AnalyseEvents(treeReader);
97
98 cout << "** Exiting..." << endl;
99
100 delete result;
101 delete treeReader;
102 delete chain;
103}
104