Skip to content
Open
Show file tree
Hide file tree
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 Sep 21, 2022
4481e68
first draft of conversion functions
antonioiuliano2 Sep 22, 2022
b206089
adding function for vertices
antonioiuliano2 Sep 23, 2022
a39f9ea
applying draw vertex and track functions
antonioiuliano2 Oct 28, 2022
702f407
adding conversion from physics reference system to our emulsion refer…
antonioiuliano2 Oct 28, 2022
f21d146
adding conversion from physics reference system to our emulsion refer…
antonioiuliano2 Oct 28, 2022
be1a6ba
get sie from ROOT file
antonioiuliano2 Nov 10, 2022
1983071
restoring drawText as value in master
antonioiuliano2 Nov 21, 2022
5c8f025
fixing some typos
antonioiuliano2 Nov 21, 2022
38c65d2
adding codes by Daniele for interface
antonioiuliano2 Jul 5, 2023
60b6e11
updated version by Daniele
antonioiuliano2 Jul 5, 2023
4ead4f4
fixing path and removing unused file
antonioiuliano2 Jul 5, 2023
6ae6161
option added to transform coordinates in local brick reference
antonioiuliano2 Jul 5, 2023
6d90ab7
removing confirmation prompts
antonioiuliano2 Jul 7, 2023
40ccd01
reducing angular limit t to GPU scans
antonioiuliano2 Jul 7, 2023
3c0a421
remove debugging messages and changing paths
antonioiuliano2 Aug 10, 2023
5aee9dc
adding mother folder to path
antonioiuliano2 Aug 10, 2023
e433f8d
simpler way to initialize list
antonioiuliano2 Sep 30, 2023
3a403fd
adding year in comment
antonioiuliano2 Sep 30, 2023
8d6fbc9
adding python shebang
antonioiuliano2 Sep 30, 2023
f9cd7c1
fixing linebreak, removing default file name
antonioiuliano2 Sep 30, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 118 additions & 0 deletions python/Fedra2sndsw.py
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
Loading