forked from cms-sw/cmssw
-
Notifications
You must be signed in to change notification settings - Fork 2
Adding GenJets to LST input #214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c24c2b4
Adding GenJets to trackingNtuple.root and LST
kk428 a1cd7dd
Added comments
kk428 0168fd9
Plots DR and FR for GenJet deltaR
kk428 def261b
Merge branch 'master' into genjet
kk428 0bd1e2a
Added sim_deltaR, etc., to TrackingNtuple.cc
kk428 3a94ea9
Merge branch 'genjet' of github.com:kk428/cmssw into genjet
kk428 3134b07
Merge branch 'master' into genjet
kk428 50e325e
Fixing minor merge conflict
kk428 c8ce3d5
Added jet pT > 100 GeV cut
kk428 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
RecoTracker/LSTCore/standalone/analysis/jets/reformat_jets2.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| ########################################################## | ||
| # | ||
| # Adds deltaR branches to the trackingNtuple.root file | ||
| # using GenJets. | ||
| # | ||
| ########################################################## | ||
|
|
||
| import matplotlib.pyplot as plt | ||
| import ROOT | ||
| from ROOT import TFile | ||
| import numpy as np | ||
|
|
||
| # Load existing tree | ||
| # file = TFile("/data2/segmentlinking/CMSSW_12_2_0_pre2/trackingNtuple_ttbar_PU200.root") | ||
| file = TFile("trackingNtuple_100_GenJet.root") | ||
| old_tree = file["trackingNtuple"]["tree"] | ||
|
|
||
| # Create a new ROOT file to store the new TTree | ||
| new_file = ROOT.TFile("new_tree_100_GenJet2.root", "RECREATE") | ||
ariostas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| # Create a new subdirectory in the new file | ||
| new_directory = new_file.mkdir("trackingNtuple") | ||
|
|
||
| # Change the current directory to the new subdirectory | ||
| new_directory.cd() | ||
|
|
||
| # Create a new TTree with the same structure as the old one but empty | ||
| new_tree = old_tree.CloneTree(0) | ||
|
|
||
| # Account for bug in 12_2_X branch | ||
| new_tree.SetBranchStatus("ph2_bbxi", False) | ||
|
|
||
| # Create a variable to hold the new leaves' data (a list of floats) | ||
| new_leaf_deltaEta = ROOT.std.vector('float')() | ||
| new_leaf_deltaPhi = ROOT.std.vector('float')() | ||
| new_leaf_deltaR = ROOT.std.vector('float')() | ||
|
|
||
| # Create a new branch in the tree | ||
| new_tree.Branch("sim_deltaEta", new_leaf_deltaEta) | ||
| new_tree.Branch("sim_deltaPhi", new_leaf_deltaPhi) | ||
| new_tree.Branch("sim_deltaR", new_leaf_deltaR) | ||
|
|
||
| # Loop over entries in the old tree | ||
| for ind in range(old_tree.GetEntries()): | ||
| old_tree.GetEntry(ind) | ||
|
|
||
| # Clear the vector to start fresh for this entry | ||
| new_leaf_deltaEta.clear() | ||
| new_leaf_deltaPhi.clear() | ||
| new_leaf_deltaR.clear() | ||
|
|
||
| # Creates the lists that will fill the leaves | ||
| simPt = old_tree.sim_pt | ||
| simEta = old_tree.sim_eta | ||
| simPhi = old_tree.sim_phi | ||
| simLen = len(simPt) | ||
|
|
||
| print(old_tree.Print()) | ||
ariostas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| genJetsPt = old_tree.genJetPt | ||
| genJetsEta = old_tree.genJetEta | ||
| genJetsPhi = old_tree.genJetPhi | ||
ariostas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| genJetLen = len(genJetsPt) | ||
|
|
||
| # Declare arrays (all entries will be filled with non-dummy values) | ||
| deltaEtas = np.ones(simLen)*-999 | ||
| deltaPhis = np.ones(simLen)*-999 | ||
| deltaRs = np.ones(simLen)*-999 | ||
|
|
||
| for i in range(len(simPt)): | ||
| dRTemp = 999 | ||
| dPhiTemp = 999 | ||
| dEtaTemp = 999 | ||
| for j in range(genJetLen): | ||
| dEtaj = simEta[i] - genJetsEta[j] | ||
| dPhij = np.arccos(np.cos(simPhi[i] - genJetsPhi[j])) | ||
| dRj = np.sqrt(dEtaj**2 + dPhij**2) | ||
|
|
||
| # Selects smallest dR, corresponding to closest jet | ||
| if(dRj < dRTemp): | ||
ariostas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| dRTemp = dRj | ||
| dPhiTemp = dPhij | ||
| dEtaTemp = dEtaj | ||
| deltaRs[i] = dRTemp | ||
| deltaPhis[i] = dPhiTemp | ||
| deltaEtas[i] = dEtaTemp | ||
|
|
||
|
|
||
| # Add the list elements to the vector | ||
| for value in deltaEtas: | ||
| new_leaf_deltaEta.push_back(value) | ||
| for value in deltaPhis: | ||
| new_leaf_deltaPhi.push_back(value) | ||
| for value in deltaRs: | ||
| new_leaf_deltaR.push_back(value) | ||
|
|
||
| # Fill the tree with the new values | ||
| new_tree.Fill() | ||
|
|
||
| # Write the tree back to the file | ||
| new_tree.Write() | ||
| new_file.Close() | ||
| file.Close() | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.