Skip to content
Snippets Groups Projects

Prototype of new alignment configuration

Merged Florian Reiss requested to merge pyconf into master
Compare and Show latest version
4 files
+ 26
209
Compare changes
  • Side-by-side
  • Inline
Files
4
+ 0
204
###############################################################################
# (c) Copyright 2021 CERN for the benefit of the LHCb Collaboration #
# #
# This software is distributed under the terms of the GNU General Public #
# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". #
# #
# In applying this licence, CERN does not waive the privileges and immunities #
# granted to it by virtue of its status as an Intergovernmental Organization #
# or submit itself to any jurisdiction. #
###############################################################################
from PyConf.application import configure_input, configure
from PyConf.control_flow import CompositeNode, NodeLogic
from PyConf.tonic import configurable
from RecoConf.hlt2_tracking import make_hlt2_tracks
from Moore import options
options.set_input_and_conds_from_testfiledb('MiniBrunel_2018_MinBias_FTv4_MDF')
options.input_files = list(set(options.input_files)) # remove dups
options.evt_max = 10
# options.use_iosvc = True
options.event_store = 'EvtStoreSvc'
options.ntuple_file = "testmonitoring.root"
# set options above this line!
configure_input(options)
# only configure data flow after this line !
from RecoConf.reconstruction_objects import reconstruction
from PyConf.Algorithms import AlignAlgorithm
from PyConf.Tools import AlignUpdateTool, EigenDiagSolvTool, AlignChisqConstraintTool
@configurable
def createAlignAlgorithm(pvs,
tracks,
odin,
particles,
elements,
updateFinalize=True,
outputlevel=3,
nIterations=1,
usecorrelations=True,
chi2Outlier=10000,
histoPrint=False,
outputDataFile='',
onlineMode=False,
runList=[],
useLocalFrame=True,
xmlWriters='[xml/Conditions/VP/Alignment/Global.xml:/dd/Structure/LHCb/BeforeMagnetRegion/VP:10:0/1:0:1,xml/Conditions/VP/Alignment/Modules.xml:/dd/Structure/LHCb/BeforeMagnetRegion/VP:10:2:0:1]'):
updatetool = createAlignUpdateTool()
alignment = AlignAlgorithm(
name='myAlignmentAlgorithm',
VertexLocation=pvs,
ODINLocation=odin,
TracksLocation=tracks,
ParticleLocation=particles,
UpdateTool=updatetool,
Elements=list(elements),
UpdateInFinalize=updateFinalize,
OutputLevel=outputlevel,
NumberOfIterations=nIterations,
UseCorrelations=usecorrelations,
Chi2Outlier=chi2Outlier,
HistoPrint=histoPrint,
OutputDataFile=outputDataFile,
OnlineMode=onlineMode,
RunList=runList,
UseLocalFrame=useLocalFrame,
XmlWriters = xmlWriters)
return alignment
@configurable
def createAlignUpdateTool(surveyconstraintTool=AlignChisqConstraintTool(),
matrixSolverTool=EigenDiagSolvTool(public=True),
constraints=[],
minNumberOfHits=10,
usePreconditioning=True,
logFile="alignlog.txt",
useWeightedAverage=False):
updatetool = AlignUpdateTool(
MatrixSolverTool=matrixSolverTool,
SurveyConstraintTool=surveyconstraintTool,
Constraints=constraints,
MinNumberOfHits=minNumberOfHits,
UsePreconditioning=usePreconditioning,
LogFile=logFile,
UseWeightedAverage=useWeightedAverage)
return updatetool
from PyConf.Algorithms import VeloClusterTrackingSIMDFull
# note that the PVs reconstructed by TrackBeamLineVertexFinderSoA do not store the list of associated tracks. Use PatPV3DFuture instead
from RecoConf.hlt1_tracking import make_reco_pvs, make_PatPV3DFuture_pvs, make_VeloClusterTrackingSIMD_tracks
#, make_reco_pvs.bind( make_pvs_from_velo_tracks=make_PatPV3DFuture_pvs)
#with reconstruction.bind(from_file=False), make_hlt2_tracks.bind(light_reco=True, use_pr_kf=True, fast_reco=False), make_reco_pvs.bind( make_pvs_from_velo_tracks=make_PatPV3DFuture_pvs):
with reconstruction.bind(from_file=False), make_hlt2_tracks.bind(light_reco=False), make_reco_pvs.bind( make_pvs_from_velo_tracks=make_PatPV3DFuture_pvs), make_VeloClusterTrackingSIMD_tracks.bind(make_tracks=VeloClusterTrackingSIMDFull):
#make tracks and PVs
# TODO: in principle the PVs should be an optional input for the alignment
reco = reconstruction()
#hlt2_tracks = make_hlt2_tracks(light_reco=False)
#best_tracks = hlt2_tracks["Best"]['v1']
#pvs = make_pvs()
hlt2_tracks = reco["Tracks"]
best_tracks = hlt2_tracks
pvs = reco["PVs"]
#select tracks and PVs
from PyConf.Tools import VPTrackSelector
from PyConf.Algorithms import TrackListRefiner, VertexListRefiner, TrackSelectionMerger
from PyConf.Algorithms import LHCb__Converters__RecVertex__v2__fromVectorLHCbRecVertices as fromLHCbRecVertices
myTrackSelector = VPTrackSelector(
TrackTypes=["Long"], MinHits=5, MaxChi2Cut=5)
selected_tracks = TrackListRefiner(
inputLocation=best_tracks, Selector=myTrackSelector).outputLocation
myBackwardTrackSelector = VPTrackSelector(
TrackTypes=["Backward"], MinHits=5, MaxChi2Cut=5)
selected_BackwardTracks = TrackListRefiner(
inputLocation=best_tracks,
Selector=myBackwardTrackSelector).outputLocation
alignmentTracks = TrackSelectionMerger(
InputLocations=[selected_tracks, selected_BackwardTracks
]).OutputLocation
#need to convert PVs first
#converted_pvs = fromLHCbRecVertices(
# InputVerticesName=pvs,
# InputTracksName=all_velo_track_types()["v1"]).OutputVerticesName
selected_pvs = VertexListRefiner(
InputLocation=pvs).OutputLocation
#create ODIN
from PyConf.application import default_raw_banks, createODIN
odin = createODIN( RawBanks=default_raw_banks(("ODIN"))).ODIN
# create input particles, use long pions as dummy for now
# TODO: in principle these should be composite particles and be an optional input for the alginment
from Hlt2Conf.standard_particles import make_long_pions
pions = make_long_pions()
#define elements and degrees of freedom to be aligned
from TAlignment.Alignables import Alignables
elements = Alignables()
dofs = "TxTyTzRxRyRz"
dofsmodules = "TxTyTzRxRyRz"
elements.VPLeft(dofs)
elements.VPRight(dofs)
elements.VPModules(dofsmodules)
# add survey constraints
from Configurables import SurveyConstraints
surveyconstraints = SurveyConstraints()
surveyconstraints.VP()
myAlignChisqConstraintTool = AlignChisqConstraintTool(Constraints=surveyconstraints.Constraints,
XmlUncertainties=surveyconstraints.XmlUncertainties,
XmlFiles=surveyconstraints.XmlFiles)
# define Lagrange constraints
constraints = []
constraints.append("VPHalfAverage : VP/VP(Left|Right) : Tx Ty Tz Rx Ry Rz")
constraints.append(
"VPInternal : VP/VPRight/Module..WithSupport: Tx Ty Tz Rx Ry Rz")
constraints.append(
"VPInternal : VP/VPLeft/Module..WithSupport: Tx Ty Tz Rx Ry Rz")
with createAlignUpdateTool.bind(surveyconstraintTool=myAlignChisqConstraintTool, constraints=constraints):
alignment = createAlignAlgorithm(pvs=selected_pvs, tracks=alignmentTracks, odin=odin, particles=pions, elements=elements)
# add track and vertex monitoring
from PyConf.Algorithms import TrackMonitor, TrackFitMatchMonitor, TrackVertexMonitor
# TODO: should only use selected PVs
myTrackMonitor = TrackMonitor(
TracksInContainer=alignmentTracks, PrimaryVertices=pvs)
myTrackFitMatchMonitor = TrackFitMatchMonitor(
TrackContainer=alignmentTracks)
# TODO: check vertices
myTrackVertexMonitor = TrackVertexMonitor(
TrackContainer=alignmentTracks, PVContainer=pvs)
top_node = CompositeNode(
"alignment", [
alignment, myTrackMonitor, myTrackFitMatchMonitor,
myTrackVertexMonitor
],
combine_logic=NodeLogic.NONLAZY_OR,
force_order=True)
configure(options, top_node, public_tools=[])
Loading