-
Notifications
You must be signed in to change notification settings - Fork 116
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
Timing Correction for MuonDIS generation #510
Open
anupama-reghunath
wants to merge
23
commits into
ShipSoft:master
Choose a base branch
from
anupama-reghunath:MuonDIS
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
5a580f6
Timing Implementation of MuDIS
anupama-reghunath dceb885
edit run_simScript to inactivate Muon Nuclear for MuDIS
anupama-reghunath 08e0063
Added MuonDIS directory for updated scripts
anupama-reghunath 908e32a
final fixes
anupama-reghunath 8060675
add CHANGELOG entry for MuonDIS
anupama-reghunath 7a1a5ff
Avoid listdir for non-directory case
anupama-reghunath cd92c6e
fixup! Avoid listdir for non-directory case
anupama-reghunath c029ddf
fixup! final fixes
anupama-reghunath dd237ed
fixup! final fixes
anupama-reghunath 4e83755
Added DIS cross section directly to the sim file
anupama-reghunath dfb602a
SBTchanges
anupama-reghunath 6ea2b5a
add default paths for MuBackground
anupama-reghunath e801db0
remove bug/allow saving multiple muons per event
anupama-reghunath 5a2080e
fixup! remove bug/allow saving multiple muons per event
anupama-reghunath 72bf1c2
add nmuons in the Dis file
anupama-reghunath a2cf336
Fix bug in make_nTuple scripts
anupama-reghunath bb845d6
fixup! Fix bug in make_nTuple scripts
anupama-reghunath 4400c35
add Carbon to PDG in run_simScript
anupama-reghunath 39641e7
fixup! Fix bug in make_nTuple scripts
anupama-reghunath 5892432
fixup! add Carbon to PDG in run_simScript
anupama-reghunath dbcdd93
fixup! fixup! Fix bug in make_nTuple scripts
anupama-reghunath 86b5434
Save DIS cross to MCTrack[1]
anupama-reghunath 2053461
lower MCTrack Energy Cut for MuonDIS in run_simScript
anupama-reghunath 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 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 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 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,117 @@ | ||
#!/usr/bin/env python | ||
"""Script to add the incoming muon's MC hits in the SBT to the simulation file.""" | ||
|
||
import argparse | ||
import logging | ||
|
||
import ROOT as r | ||
|
||
parser = argparse.ArgumentParser(description=__doc__) | ||
parser.add_argument( | ||
"-f", | ||
"--inputfile", | ||
required=True, | ||
help="Simulation file produced from DIS, WARNING: File will be modified.", | ||
) | ||
parser.add_argument( | ||
"-m", | ||
"--muonfile", | ||
required=True, | ||
help="Muon file used for DIS production (muonDis_<>.root)", | ||
) | ||
args = parser.parse_args() | ||
|
||
|
||
def inspect_file(inputfile): | ||
"""Inspecting the produced file for successfully added muon veto points.""" | ||
input_file = r.TFile.Open(inputfile, "READ") | ||
input_tree = input_file.cbmsim | ||
input_tree.GetEntry(0) | ||
|
||
muons = False | ||
for hit in input_tree.vetoPoint: | ||
if hit.GetTrackID() == 0: | ||
muons = True | ||
input_file.Close() | ||
|
||
if muons: | ||
print("File is already updated with incoming muon info. Nothing to do.") | ||
return False | ||
else: | ||
print( | ||
"Incoming muon's vetopoint info missing in file, proceeding with modification" | ||
) | ||
return True | ||
|
||
|
||
def modify_file(inputfile, muonfile): | ||
"""Add information from original muon to input simulation file.""" | ||
logging.warning(f"{inputfile} will be opened for modification") | ||
|
||
input_file = r.TFile.Open(inputfile, "UPDATE") | ||
try: | ||
input_tree = input_file.cbmsim | ||
except Exception as e: | ||
print(f"Error: {e}") | ||
input_file.Close() | ||
exit(1) | ||
|
||
# Open the external file with additional vetoPoints | ||
muon_file = r.TFile.Open(muonfile, "READ") | ||
try: | ||
muon_tree = muon_file.DIS | ||
except Exception as e: | ||
print(f"Error: {e}") | ||
muon_file.Close() | ||
exit(1) | ||
|
||
input_file.cd() | ||
output_tree = input_tree.CloneTree( | ||
0 | ||
) # Clone the structure of the existing tree, but do not copy the entries | ||
|
||
# Access the vetoPoint branch in the original and external trees | ||
original_vetoPoint = r.TClonesArray("vetoPoint") | ||
muon_vetoPoint = r.TClonesArray("vetoPoint") | ||
combined_vetoPoint = r.TClonesArray("vetoPoint") | ||
|
||
input_tree.SetBranchAddress("vetoPoint", original_vetoPoint) | ||
muon_tree.SetBranchAddress("muon_vetoPoints", muon_vetoPoint) | ||
output_tree.SetBranchAddress("vetoPoint", combined_vetoPoint) | ||
|
||
for input_event, muon_event in zip(input_tree, muon_tree): | ||
interaction_point = r.TVector3() | ||
input_event.MCTrack[0].GetStartVertex(interaction_point) | ||
|
||
combined_vetoPoint.Clear() | ||
|
||
index = 0 | ||
|
||
for hit in original_vetoPoint: | ||
if combined_vetoPoint.GetSize() == index: | ||
combined_vetoPoint.Expand(index + 1) | ||
combined_vetoPoint[index] = hit # pending fix to support ROOT 6.32+ | ||
index += 1 | ||
|
||
for hit in muon_vetoPoint: | ||
if hit.GetZ() < interaction_point.Z(): | ||
if combined_vetoPoint.GetSize() == index: | ||
combined_vetoPoint.Expand(index + 1) | ||
combined_vetoPoint[index] = hit # pending fix to support ROOT 6.32+ | ||
index += 1 | ||
|
||
output_tree.Fill() | ||
|
||
# Write the updated tree back to the same file | ||
input_file.cd() | ||
output_tree.Write("cbmsim", r.TObject.kOverwrite) | ||
input_file.Close() | ||
muon_file.Close() | ||
|
||
print(f"File updated with incoming muon info as {inputfile}") | ||
|
||
|
||
add_muons = inspect_file(args.inputfile) | ||
|
||
if add_muons: | ||
modify_file(args.inputfile, args.muonfile) |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe better as a ternary statement to avoid possible issues of variable scope.