forked from ShipSoft/FairShip
-
Notifications
You must be signed in to change notification settings - Fork 27
SNDSW - FEDRA conversion functions #132
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
Open
antonioiuliano2
wants to merge
21
commits into
SND-LHC:master
Choose a base branch
from
antonioiuliano2:ConvertEmuBaseTracks
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
21 commits
Select commit
Hold shift + click to select a range
944f251
position and angles in sndsw system
antonioiuliano2 4481e68
first draft of conversion functions
antonioiuliano2 b206089
adding function for vertices
antonioiuliano2 a39f9ea
applying draw vertex and track functions
antonioiuliano2 702f407
adding conversion from physics reference system to our emulsion refer…
antonioiuliano2 f21d146
adding conversion from physics reference system to our emulsion refer…
antonioiuliano2 be1a6ba
get sie from ROOT file
antonioiuliano2 1983071
restoring drawText as value in master
antonioiuliano2 5c8f025
fixing some typos
antonioiuliano2 38c65d2
adding codes by Daniele for interface
antonioiuliano2 60b6e11
updated version by Daniele
antonioiuliano2 4ead4f4
fixing path and removing unused file
antonioiuliano2 6ae6161
option added to transform coordinates in local brick reference
antonioiuliano2 6d90ab7
removing confirmation prompts
antonioiuliano2 40ccd01
reducing angular limit t to GPU scans
antonioiuliano2 3c0a421
remove debugging messages and changing paths
antonioiuliano2 5aee9dc
adding mother folder to path
antonioiuliano2 e433f8d
simpler way to initialize list
antonioiuliano2 3a403fd
adding year in comment
antonioiuliano2 8d6fbc9
adding python shebang
antonioiuliano2 f9cd7c1
fixing linebreak, removing default file name
antonioiuliano2 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| #!/usr/bin/env python | ||
| '''Conversion tools from FEDRA to SNDSW''' | ||
|
|
||
| from xml.sax.handler import feature_external_ges | ||
| import ROOT as r | ||
| import fedrarootlogon | ||
| import numpy as np | ||
|
|
||
| #getting class instance | ||
| emureader = r.EmulsionDet() | ||
|
|
||
| def importgeofile(geofile): | ||
| '''importing geometry file, can be replaced with sndsw config function if needed''' | ||
| r.gGeoManager.Import(geofile) | ||
|
|
||
|
|
||
| def convertseg(seg,brickID,refplate = 60): | ||
| '''convert position and angles from an EdbSegP into the global system | ||
| Seg: EdbSegP instance; | ||
| brickID: number of the brick the track was reconstructed in (ex. 31); | ||
| returns a 6-values array (x,y,z,Vx,Vy,Vz) | ||
| refplate: which is our reference plate | ||
| ''' | ||
| detID = int(brickID * 1e3 + refplate) | ||
|
|
||
|
|
||
| localarr = np.array([seg.X(), seg.Y(), seg.Z()]) | ||
| globalarr = np.zeros(3) | ||
|
|
||
| emureader.GetPosition(detID,localarr,globalarr) | ||
|
|
||
| anglocalarr = np.array([seg.TX(), seg.TY(), 1.]) | ||
| angglobalarr = np.zeros(3) | ||
|
|
||
| emureader.GetAngles(detID,anglocalarr,angglobalarr) | ||
|
|
||
|
|
||
| return np.concatenate([globalarr,angglobalarr]) | ||
|
|
||
| def converttrack(track,brickID, refplate=60, fittedsegments = False): | ||
| '''convert all segments from a volumetrack: | ||
| track: EdbTrackP instance; | ||
| brickID: number of the brick the track was reconstructed in (ex. 31); | ||
| fittedsegments: used fitted segments instead of true segments (default False) | ||
| refplate: which is our reference plate | ||
| ''' | ||
|
|
||
| nseg = track.N() | ||
| globaltracklist = [] | ||
| for iseg in range(nseg): | ||
| myseg = track.GetSegment(iseg) | ||
| if fittedsegments: #replace true segment with fittedsegment | ||
| myseg = track.GetSegmentF(iseg) | ||
| globalsegarr = convertseg(myseg,brickID,refplate) | ||
| globaltracklist.append(globalsegarr) | ||
|
|
||
| globaltrackarr = np.array(globaltracklist) | ||
| return globaltrackarr | ||
|
|
||
| def convertvertex(vertex, brickID, refplate=60, fittedsegments=False): | ||
| '''Converting EdbVertex position into SNDSW system | ||
| vertex: EdbVertex instance; | ||
| brickID: number of the brick the vertex was reconstructed in (ex. 31) | ||
| fittedsegments: used fitted segments instead of true segments (default False) | ||
| refplate: which is our reference plate | ||
| ''' | ||
| detID = int(brickID * 1e3 + refplate) | ||
| #vertex position | ||
| localvarr = np.array([vertex.VX(),vertex.VY(),vertex.VZ()]) | ||
| globalvarr = np.zeros(3) | ||
| emureader.GetPosition(detID,localvarr,globalvarr) | ||
| #track info | ||
| ntracks = vertex.N() | ||
| globaltracklist = [] | ||
| for itrack in range(ntracks): | ||
| track = vertex.GetTrack(itrack) | ||
| globaltrackarr = converttrack(track,brickID,refplate,fittedsegments) | ||
| globaltracklist.append(globaltrackarr) | ||
|
|
||
| globaltracksarr = np.array(globaltracklist) | ||
| return globalvarr, globaltracksarr | ||
|
|
||
| def convertmcpoint(emupoint, MCEventID, EmulsionID = 0, weight = 70): | ||
| ''' Converting EmuPoint from MCEventID into EdbSegP''' | ||
|
|
||
| detID = emupoint.GetDetectorID() | ||
| momentum = r.TMath.Sqrt(pow(emupoint.GetPx(),2) + pow(emupoint.GetPy(),2) + pow(emupoint.GetPz(),2)) | ||
| #first, convert positions | ||
| globalpos = np.array([emupoint.GetX(),emupoint.GetY(),emupoint.GetZ()]) | ||
| localpos = np.zeros(3) | ||
|
|
||
| emureader.GetLocalPosition(detID, globalpos, localpos) | ||
|
|
||
| xem = localpos[0] | ||
| yem = localpos[1] | ||
|
|
||
| #second, convert angles | ||
| globalang = np.array([emupoint.GetPx(),emupoint.GetPy(),emupoint.GetPz()]) | ||
| localang = np.zeros(3) | ||
|
|
||
| emureader.GetLocalAngles(detID, globalang, localang) | ||
| #angles in TX, TY format | ||
| tx = localang[0]/localang[2] #px/pz | ||
| ty = localang[1]/localang[2] #py/pz | ||
| #MCTruth info | ||
| pdgcode = emupoint.PdgCode() | ||
| trackID = emupoint.GetTrackID() | ||
|
|
||
| #ready to write the segment | ||
| emuseg = r.EdbSegP() | ||
| emuseg.Set(EmulsionID, xem, yem, tx, ty, weight, 1) | ||
| emuseg.SetMC(MCEventID, emupoint.GetTrackID()) | ||
| emuseg.SetP(momentum) | ||
| emuseg.SetVid(pdgcode,0) | ||
|
|
||
| emuseg.SetZ(localpos[2]) #0 is the center of the volume (center of plastic base in emulsion film) | ||
|
|
||
| return emuseg | ||
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.