[e7e90df] | 1 | /*
|
---|
| 2 | Simple macro showing how to access branches from the delphes output root file,
|
---|
| 3 | loop over events, and plot simple quantities such as the jet pt and the di-electron invariant
|
---|
[fbb617b] | 4 | mass.
|
---|
[e7e90df] | 5 |
|
---|
| 6 | root -l examples/Example1.C'("delphes_output.root")'
|
---|
| 7 | */
|
---|
| 8 |
|
---|
[c9803f7] | 9 | #ifdef __CLING__
|
---|
| 10 | R__LOAD_LIBRARY(libDelphes)
|
---|
| 11 | #include "classes/DelphesClasses.h"
|
---|
| 12 | #include "external/ExRootAnalysis/ExRootTreeReader.h"
|
---|
| 13 | #endif
|
---|
| 14 |
|
---|
[e7e90df] | 15 | //------------------------------------------------------------------------------
|
---|
| 16 |
|
---|
| 17 | void Example1(const char *inputFile)
|
---|
| 18 | {
|
---|
| 19 | gSystem->Load("libDelphes");
|
---|
| 20 |
|
---|
| 21 | // Create chain of root trees
|
---|
| 22 | TChain chain("Delphes");
|
---|
| 23 | chain.Add(inputFile);
|
---|
[fbb617b] | 24 |
|
---|
[e7e90df] | 25 | // Create object of class ExRootTreeReader
|
---|
| 26 | ExRootTreeReader *treeReader = new ExRootTreeReader(&chain);
|
---|
| 27 | Long64_t numberOfEntries = treeReader->GetEntries();
|
---|
[fbb617b] | 28 |
|
---|
[e7e90df] | 29 | // Get pointers to branches used in this analysis
|
---|
| 30 | TClonesArray *branchJet = treeReader->UseBranch("Jet");
|
---|
| 31 | TClonesArray *branchElectron = treeReader->UseBranch("Electron");
|
---|
[9047a02] | 32 | TClonesArray *branchEvent = treeReader->UseBranch("Event");
|
---|
[fbb617b] | 33 |
|
---|
[e7e90df] | 34 | // Book histograms
|
---|
| 35 | TH1 *histJetPT = new TH1F("jet_pt", "jet P_{T}", 100, 0.0, 100.0);
|
---|
| 36 | TH1 *histMass = new TH1F("mass", "M_{inv}(e_{1}, e_{2})", 100, 40.0, 140.0);
|
---|
| 37 |
|
---|
| 38 | // Loop over all events
|
---|
| 39 | for(Int_t entry = 0; entry < numberOfEntries; ++entry)
|
---|
| 40 | {
|
---|
| 41 | // Load selected branches with data from specified event
|
---|
| 42 | treeReader->ReadEntry(entry);
|
---|
[9047a02] | 43 |
|
---|
| 44 | //HepMCEvent *event = (HepMCEvent*) branchEvent -> At(0);
|
---|
| 45 | //LHEFEvent *event = (LHEFEvent*) branchEvent -> At(0);
|
---|
| 46 | //Float_t weight = event->Weight;
|
---|
[fbb617b] | 47 |
|
---|
[e7e90df] | 48 | // If event contains at least 1 jet
|
---|
| 49 | if(branchJet->GetEntries() > 0)
|
---|
| 50 | {
|
---|
| 51 | // Take first jet
|
---|
| 52 | Jet *jet = (Jet*) branchJet->At(0);
|
---|
[fbb617b] | 53 |
|
---|
[e7e90df] | 54 | // Plot jet transverse momentum
|
---|
[92263a8] | 55 | //histJetPT->Fill(jet->PT, weight);
|
---|
| 56 | histJetPT->Fill(jet->PT);
|
---|
[fbb617b] | 57 |
|
---|
[e7e90df] | 58 | // Print jet transverse momentum
|
---|
| 59 | cout << "Jet pt: "<<jet->PT << endl;
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | Electron *elec1, *elec2;
|
---|
| 63 |
|
---|
| 64 | // If event contains at least 2 electrons
|
---|
| 65 | if(branchElectron->GetEntries() > 1)
|
---|
| 66 | {
|
---|
| 67 | // Take first two electrons
|
---|
| 68 | elec1 = (Electron *) branchElectron->At(0);
|
---|
| 69 | elec2 = (Electron *) branchElectron->At(1);
|
---|
| 70 |
|
---|
| 71 | // Plot their invariant mass
|
---|
[92263a8] | 72 | //histMass->Fill(((elec1->P4()) + (elec2->P4())).M(), weight);
|
---|
| 73 | histMass->Fill(((elec1->P4()) + (elec2->P4())).M());
|
---|
[e7e90df] | 74 | }
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | // Show resulting histograms
|
---|
| 78 | histJetPT->Draw();
|
---|
| 79 | histMass->Draw();
|
---|
| 80 | }
|
---|
| 81 |
|
---|