[f8e61b2] | 1 | #!/usr/bin/env python
|
---|
| 2 |
|
---|
| 3 | import sys
|
---|
| 4 |
|
---|
| 5 | import ROOT
|
---|
| 6 |
|
---|
| 7 | try:
|
---|
| 8 | input = raw_input
|
---|
| 9 | except:
|
---|
| 10 | pass
|
---|
| 11 |
|
---|
| 12 | if len(sys.argv) < 2:
|
---|
| 13 | print(" Usage: Example1.py input_file")
|
---|
| 14 | sys.exit(1)
|
---|
| 15 |
|
---|
| 16 | ROOT.gSystem.Load("libDelphes")
|
---|
| 17 |
|
---|
| 18 | try:
|
---|
| 19 | ROOT.gInterpreter.Declare('#include "classes/DelphesClasses.h"')
|
---|
| 20 | ROOT.gInterpreter.Declare('#include "external/ExRootAnalysis/ExRootTreeReader.h"')
|
---|
| 21 | except:
|
---|
| 22 | pass
|
---|
| 23 |
|
---|
| 24 | inputFile = sys.argv[1]
|
---|
| 25 |
|
---|
| 26 | # Create chain of root trees
|
---|
| 27 | chain = ROOT.TChain("Delphes")
|
---|
| 28 | chain.Add(inputFile)
|
---|
| 29 |
|
---|
| 30 | # Create object of class ExRootTreeReader
|
---|
| 31 | treeReader = ROOT.ExRootTreeReader(chain)
|
---|
| 32 | numberOfEntries = treeReader.GetEntries()
|
---|
| 33 |
|
---|
| 34 | # Get pointers to branches used in this analysis
|
---|
[b03c0d0] | 35 | branchJet = treeReader.UseBranch("JetPUPPITight")
|
---|
[f8e61b2] | 36 | branchElectron = treeReader.UseBranch("ElectronMedium")
|
---|
[b03c0d0] | 37 | branchWeight = treeReader.UseBranch("Weight")
|
---|
| 38 | branchEvent = treeReader.UseBranch("Event")
|
---|
[f8e61b2] | 39 |
|
---|
| 40 | # Book histograms
|
---|
| 41 | histJetPT = ROOT.TH1F("jet_pt", "jet P_{T}", 100, 0.0, 1000.0)
|
---|
| 42 | histElectronPT = ROOT.TH1F("Electron_pt", "electron P_{T}", 100, 0.0, 1000.0)
|
---|
| 43 |
|
---|
| 44 | # Loop over all events
|
---|
| 45 | for entry in range(0, numberOfEntries):
|
---|
| 46 | # Load selected branches with data from specified event
|
---|
| 47 | treeReader.ReadEntry(entry)
|
---|
| 48 |
|
---|
[b03c0d0] | 49 | ## main MC event weight
|
---|
| 50 | w = branchEvent[0].Weight
|
---|
[f8e61b2] | 51 |
|
---|
[b03c0d0] | 52 | ## read lhe event weight
|
---|
| 53 | for weight in branchWeight:
|
---|
| 54 | lhe_weight = weight.Weight
|
---|
| 55 | ## do stuff ...
|
---|
| 56 | ## print lhe_weight
|
---|
| 57 |
|
---|
[f8e61b2] | 58 | # If event contains at least 1 jet
|
---|
| 59 | if branchJet.GetEntries() > 0:
|
---|
| 60 | # Take first jet
|
---|
| 61 | jet = branchJet.At(0)
|
---|
| 62 |
|
---|
| 63 | ## 0 - Loose , 1 - Medium, 2 - Tight
|
---|
| 64 | wp = 1
|
---|
| 65 |
|
---|
| 66 | BtagOk = ( jet.BTag & (1 << wp) )
|
---|
| 67 | pt = jet.PT
|
---|
| 68 | eta = abs(jet.Eta)
|
---|
| 69 |
|
---|
| 70 | # Plot jet transverse momentum
|
---|
| 71 | if (BtagOk and pt > 30. and eta < 5.):
|
---|
| 72 | histJetPT.Fill(jet.PT, w)
|
---|
| 73 |
|
---|
| 74 |
|
---|
| 75 | # If event contains at least 1 electron
|
---|
| 76 | if branchElectron.GetEntries() > 0:
|
---|
| 77 | # Take first electron
|
---|
| 78 | electron = branchElectron.At(0)
|
---|
| 79 |
|
---|
| 80 | pt = electron.PT
|
---|
| 81 | eta = abs(electron.Eta)
|
---|
| 82 |
|
---|
[b03c0d0] | 83 | ## looseCut = 0.3, mediumCut = 0.2, tightCut = 0.1
|
---|
[f8e61b2] | 84 | IsoCut = 0.2
|
---|
| 85 | IsoOk = electron.IsolationVar < IsoCut
|
---|
| 86 |
|
---|
| 87 | # Plot electron transverse momentum
|
---|
| 88 | if (IsoOk and pt > 10. and eta < 5.):
|
---|
| 89 | histElectronPT.Fill(electron.PT, w)
|
---|
| 90 |
|
---|
| 91 |
|
---|
| 92 | # Show resulting histograms
|
---|
| 93 | cnv = ROOT.TCanvas("cnv", "cnv", 50, 50, 800, 500)
|
---|
| 94 | cnv.Divide(2, 1)
|
---|
| 95 | cnv.cd(1)
|
---|
| 96 | ROOT.gStyle.SetOptStat(0)
|
---|
| 97 |
|
---|
| 98 | histJetPT.Draw()
|
---|
| 99 |
|
---|
| 100 | cnv.cd(2)
|
---|
| 101 | ROOT.gStyle.SetOptStat(0)
|
---|
| 102 | histElectronPT.Draw()
|
---|
| 103 |
|
---|
| 104 | input("Press Enter to continue...")
|
---|