Commit 4ec44bdc authored by Edward Moyse's avatar Edward Moyse
Browse files

Merge branch 'master-add-more-new-config-muon-test' into master-SoftwareDevTutorial

parents c2fc6dcc ae64892f
......@@ -17,7 +17,6 @@ def TriggerChamberClusterOnTrackCreatorCfg(flags, **kwargs):
result.setPrivateTools(Muon__TriggerChamberClusterOnTrackCreator(**kwargs))
return result
def CscClusterOnTrackCreatorCfg(flags,**kwargs):
from MuonConfig.MuonSegmentFindingConfig import QratCscClusterFitterCfg, CscClusterUtilToolCfg
......
......@@ -29,10 +29,13 @@ def MuonSeededSegmentFinderCfg(flags,name="MuonSeededSegmentFinder", **kwargs):
kwargs.setdefault("SegmentMakerNoHoles", seg_maker) #FIXME. Just remove one.
if not flags.Detector.GeometryCSC:
kwargs.setdefault("CscPrepDataContainer","")
else:
if not flags.Detector.GeometrysTGC:
kwargs.setdefault("sTgcPrepDataContainer","")
if not flags.Detector.GeometryMM:
kwargs.setdefault("MMPrepDataContainer","")
kwargs.setdefault('TgcPrepDataContainer', 'TGC_MeasurementsAllBCs' if not flags.Muon.useTGCPriorNextBC and not flags.Muon.useTGCPriorNextBC else 'TGC_Measurements')
muon_seeded_segment_finder = Muon__MuonSeededSegmentFinder(name, **kwargs)
result.setPrivateTools(muon_seeded_segment_finder)
return result
......
......@@ -511,19 +511,19 @@ def MooSegmentFinderCfg(flags, name='MooSegmentFinder', **kwargs):
csc_2d_segment_maker=None
csc_4d_segment_maker=None
segment_finder_tool = Muon__MooSegmentCombinationFinder(name=name,
SegmentCombiner = muon_curved_segment_combiner_tool,
SegmentCombinationCleaner = muon_segment_combination_cleaner_tool,
HoughPatternFinder =muon_pattern_finder_tool,
MdtSegmentMaker=muon_pattern_segment_maker,
DoSegmentCombinations=False,
DoSegmentCombinationCleaning=False,
DoCscSegments = flags.Muon.doCSCs,
DoMdtSegments = flags.Muon.doMDTs,
Csc2dSegmentMaker = csc_2d_segment_maker,
Csc4dSegmentMaker = csc_4d_segment_maker,
DoSummary = flags.Muon.printSummary
)
kwargs.setdefault('SegmentCombiner', muon_curved_segment_combiner_tool)
kwargs.setdefault('SegmentCombinationCleaner', muon_segment_combination_cleaner_tool)
kwargs.setdefault('HoughPatternFinder', muon_pattern_finder_tool)
kwargs.setdefault('MdtSegmentMaker', muon_pattern_segment_maker)
kwargs.setdefault('DoSegmentCombinations', False)
kwargs.setdefault('DoSegmentCombinationCleaning', False)
kwargs.setdefault('DoCscSegments', flags.Muon.doCSCs)
kwargs.setdefault('DoMdtSegments', flags.Muon.doMDTs)
kwargs.setdefault('Csc2dSegmentMaker', csc_2d_segment_maker)
kwargs.setdefault('Csc4dSegmentMaker', csc_4d_segment_maker)
kwargs.setdefault('DoSummary', flags.Muon.printSummary)
segment_finder_tool = Muon__MooSegmentCombinationFinder(name=name, **kwargs)
result.setPrivateTools(segment_finder_tool)
return result
......@@ -638,6 +638,7 @@ def MooSegmentFinderAlgCfg(flags, name = "MuonSegmentMaker", **kwargs):
kwargs.setdefault('MuonSegmentOutputLocation', "ThirdChainSegments" if flags.Muon.segmentOrigin=="TruthTracking" else "MuonSegments")
moo_segment_finder_alg = MooSegmentFinderAlg( name=name, **kwargs )
moo_segment_finder_alg.Cardinality=10
result.addEventAlgo( moo_segment_finder_alg )
return result
......@@ -658,7 +659,9 @@ def MooSegmentFinderAlg_NCBCfg(flags, name = "MuonSegmentMaker_NCB", **kwargs):
csc_4d_segment_maker = acc.getPrimary()
result.merge(acc)
acc = MooSegmentFinderCfg(flags, name='MooSegmentFinder_NCB', Csc2dSegmentMaker=csc_2d_segment_maker, Csc4dSegmentMaker=csc_4d_segment_maker)
acc = MooSegmentFinderCfg(flags, name='MooSegmentFinder_NCB', Csc2dSegmentMaker=csc_2d_segment_maker,
Csc4dSegmentMaker=csc_4d_segment_maker,
DoMdtSegments=False,DoSegmentCombinations=False,DoSegmentCombinationCleaning=False)
segment_finder_tool=(acc.popPrivateTools())
result.addPublicTool(segment_finder_tool)
result.merge(acc)
......@@ -701,14 +704,33 @@ def MuonSegmentFindingCfg(flags):
result.merge(acc)
return result
if __name__=="__main__":
if __name__=="__main__":
# To run this, do e.g.
# python ../athena/MuonSpectrometer/MuonConfig/python/MuonSegmentFindingConfig.py
# python -m MuonConfig.MuonSegmentFindingConfig --run --threads=1
from argparse import ArgumentParser
parser = ArgumentParser()
parser.add_argument("-t", "--threads", dest="threads", type=int,
help="number of threads", default=1)
parser.add_argument("-o", "--output", dest="output", default='newESD.pool.root',
help="write ESD to FILE", metavar="FILE")
parser.add_argument("--run", help="Run directly from the python. If false, just stop once the pickle is written.",
action="store_true")
args = parser.parse_args()
from AthenaCommon.Configurable import Configurable
from AthenaConfiguration.AllConfigFlags import ConfigFlags
from AthenaCommon.Logging import log
from AthenaConfiguration.TestDefaults import defaultTestFiles
ConfigFlags.Concurrency.NumThreads=args.threads
ConfigFlags.Concurrency.NumConcurrentEvents=args.threads # Might change this later, but good enough for the moment.
Configurable.configurableRun3Behavior=1
ConfigFlags.Detector.GeometryMDT = True
......@@ -717,41 +739,55 @@ if __name__=="__main__":
ConfigFlags.Detector.GeometryRPC = True
ConfigFlags.Input.Files = defaultTestFiles.ESD
ConfigFlags.Output.ESDFileName='newESD.pool.root'
ConfigFlags.Output.ESDFileName=args.output
# from AthenaCommon.Constants import DEBUG
#log.setLevel(DEBUG)
from AthenaCommon.Constants import DEBUG
log.setLevel(DEBUG)
log.debug('About to set up Segment Finding.')
ConfigFlags.Input.isMC = True
ConfigFlags.lock()
# import pdb; pdb.set_trace()
from AthenaConfiguration.MainServicesConfig import MainServicesThreadedCfg
cfg = MainServicesThreadedCfg(ConfigFlags)
ConfigFlags.dump()
# When running from a pickled file, athena inserts some services automatically. So only use this if running now.
if args.run:
from AthenaConfiguration.MainServicesConfig import MainServicesThreadedCfg
cfg = MainServicesThreadedCfg(ConfigFlags)
else:
cfg=ComponentAccumulator()
from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
cfg.merge(PoolReadCfg(ConfigFlags))
cfg.merge(MuonSegmentFindingCfg(ConfigFlags))
# from OutputStreamAthenaPool.OutputStreamConfig import OutputStreamCfg
# itemsToRecord = ["Trk::SegmentCollection#MuonSegments"]
#
# cfg.merge( OutputStreamCfg( ConfigFlags, 'ESD', ItemList=itemsToRecord) )
# outstream = cfg.getEventAlgo("OutputStreamESD")
# outstream.OutputLevel=DEBUG
# outstream.ForceRead = True
# This is a temporary fix - it should go someplace central as it replaces the functionality of addInputRename from here:
# https://gitlab.cern.ch/atlas/athena/blob/master/Control/SGComps/python/AddressRemappingSvc.py
from SGComps.SGCompsConf import AddressRemappingSvc, ProxyProviderSvc
pps = ProxyProviderSvc()
ars=AddressRemappingSvc()
pps.ProviderNames += [ 'AddressRemappingSvc' ]
ars.TypeKeyRenameMaps += [ '%s#%s->%s' % ("Trk::SegmentCollection", "MuonSegments", "MuonSegments_old") ]
ars.TypeKeyRenameMaps += [ '%s#%s->%s' % ("Trk::SegmentCollection", "MuonSegments_NCB", "MuonSegments_NCB_old") ]
cfg.addService(pps)
cfg.addService(ars)
# Set up output
from OutputStreamAthenaPool.OutputStreamConfig import OutputStreamCfg
itemsToRecord = ["Trk::SegmentCollection#MuonSegments", "Trk::SegmentCollection#NCB_MuonSegments"]
ConfigFlags.dump()
cfg.printConfig()
cfg.merge( OutputStreamCfg( ConfigFlags, 'ESD', ItemList=itemsToRecord) )
outstream = cfg.getEventAlgo("OutputStreamESD")
outstream.OutputLevel=DEBUG
outstream.ForceRead = True
# cfg.getService("StoreGateSvc").Dump = True
cfg.printConfig()
f=open("MuonSegmentFinding.pkl","w")
cfg.store(f)
f.close()
# cfg.run()
if args.run:
cfg.run(20)
......@@ -188,9 +188,40 @@ def MuPatCandidateToolCfg(flags, name="MuPatCandidateTool", **kwargs):
kwargs.setdefault("SegmentExtender", "") #FIXME If this is always empty, can it be removed?
mu_pat_cand_tool = Muon__MuPatCandidateTool(name, **kwargs)
from AthenaCommon.Constants import VERBOSE
mu_pat_cand_tool = Muon__MuPatCandidateTool(name, OutputLevel=VERBOSE, **kwargs)
result.setPrivateTools(mu_pat_cand_tool)
return result
def MuonChamberHoleRecoveryToolCfg(flags, name="MuonChamberHoleRecoveryTool", **kwargs):
from MuonTrackFinderTools.MuonTrackFinderToolsConf import Muon__MuonChamberHoleRecoveryTool
result=ComponentAccumulator()
kwargs.setdefault("AddMeasurements", not flags.Muon.doSegmentT0Fit )
if flags.Detector.GeometryCSC:
from MuonConfig.MuonRIO_OnTrackCreatorConfig import CscClusterOnTrackCreatorCfg
extrakwargs={}
if flags.Muon.enableErrorTuning or not flags.Input.isMC:
extrakwargs["ErrorScalerBeta"] = 0.200
acc = CscClusterOnTrackCreatorCfg(flags, **extrakwargs)
csc_cluster_creator = acc.getPrimary()
result.merge(acc)
kwargs.setdefault("CscRotCreator", csc_cluster_creator)
else:
kwargs["CscRotCreator"] = None
if not flags.Detector.GeometrysTGC:
kwargs.setdefault("sTgcPrepDataContainer","")
if not flags.Detector.GeometryMM:
kwargs.setdefault("MMPrepDataContainer","")
kwargs.setdefault('TgcPrepDataContainer', 'TGC_MeasurementsAllBCs' if not flags.Muon.useTGCPriorNextBC and not flags.Muon.useTGCPriorNextBC else 'TGC_Measurements')
hole_rec_tool = Muon__MuonChamberHoleRecoveryTool(name, **kwargs)
result.setPrivateTools(hole_rec_tool)
return result
def MuonTrackSteeringCfg(flags, name="MuonTrackSteering", **kwargs):
from MuonTrackSteeringTools.MuonTrackSteeringToolsConf import Muon__MuonTrackSteering
......@@ -270,6 +301,13 @@ def MuonTrackSteeringCfg(flags, name="MuonTrackSteering", **kwargs):
kwargs.setdefault("MuonSegmentFittingTool", seg_fitting_tool)
kwargs.setdefault("MuonTrackSelector", MuonTrackSelector(flags))
acc = MuonChamberHoleRecoveryToolCfg(flags)
hole_recovery_tool = acc.getPrimary()
result.addPublicTool(hole_recovery_tool)
result.merge(acc)
kwargs.setdefault("HoleRecoveryTool", hole_recovery_tool)
track_maker_steering = Muon__MuonTrackSteering(name,**kwargs)
result.setPrivateTools(track_maker_steering)
return result
......@@ -311,20 +349,39 @@ def MuonTrackBuildingCfg(flags):
result.merge(acc)
result.addPublicTool(track_steering)
track_builder = MuPatTrackBuilder("MuPatTrackBuilder", TrackSteering = track_steering )
track_builder = MuPatTrackBuilder("MuPatTrackBuilder", TrackSteering = track_steering, MuonSegmentCollection="MuonSegments", SpectrometerTrackOutputLocation="MuonSpectrometerTracks" )
track_builder.Cardinality=10
result.addEventAlgo( track_builder )
return result
if __name__=="__main__":
# To run this, do e.g.
# python ../athena/MuonSpectrometer/MuonConfig/python/MuonTrackBuildingConfig.py
# python -m MuonConfig.MuonTrackBuildingConfig --run --threads=
from argparse import ArgumentParser
parser = ArgumentParser()
parser.add_argument("-t", "--threads", dest="threads", type=int,
help="number of threads", default=1)
parser.add_argument("-o", "--output", dest="output", default='newESD.pool.root',
help="write ESD to FILE", metavar="FILE")
parser.add_argument("--run", help="Run directly from the python. If false, just stop once the pickle is written.",
action="store_true")
args = parser.parse_args()
from AthenaCommon.Configurable import Configurable
Configurable.configurableRun3Behavior=1
from AthenaCommon.Logging import log
from AthenaConfiguration.AllConfigFlags import ConfigFlags
ConfigFlags.Concurrency.NumThreads=args.threads
ConfigFlags.Concurrency.NumConcurrentEvents=args.threads # Might change this later, but good enough for the moment.
ConfigFlags.Detector.GeometryMDT = True
ConfigFlags.Detector.GeometryTGC = True
ConfigFlags.Detector.GeometryCSC = True
......@@ -332,47 +389,60 @@ if __name__=="__main__":
from AthenaConfiguration.TestDefaults import defaultTestFiles
ConfigFlags.Input.Files = defaultTestFiles.ESD
ConfigFlags.Output.ESDFileName='newESD.pool.root'
ConfigFlags.Output.ESDFileName=args.output
# from AthenaCommon.Constants import DEBUG
#log.setLevel(DEBUG)
log.debug('About to set up Muon Track Building.')
from AthenaCommon.Constants import DEBUG
# log.setLevel(DEBUG)
# log.info('About to set up Muon Track Building.')
ConfigFlags.Input.isMC = True
ConfigFlags.lock()
log.info('Flags set as follows:')
ConfigFlags.dump()
from AthenaConfiguration.MainServicesConfig import MainServicesThreadedCfg
cfg = MainServicesThreadedCfg(ConfigFlags)
# cfg = ComponentAccumulator()
# acc = MainServicesThreadedCfg(ConfigFlags)
# print acc._isMergable
# cfg.merge(acc)
# When running from a pickled file, athena inserts some services automatically. So only use this if running now.
if args.run:
from AthenaConfiguration.MainServicesConfig import MainServicesThreadedCfg
cfg = MainServicesThreadedCfg(ConfigFlags)
else:
cfg=ComponentAccumulator()
log.info(cfg._allSequences)
from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
cfg.merge(PoolReadCfg(ConfigFlags))
log.info(cfg._allSequences)
cfg.merge(MuonTrackBuildingCfg(ConfigFlags))
log.info(cfg._allSequences)
# This is a temporary fix - it should go someplace central as it replaces the functionality of addInputRename from here:
# https://gitlab.cern.ch/atlas/athena/blob/master/Control/SGComps/python/AddressRemappingSvc.py
from SGComps.SGCompsConf import AddressRemappingSvc, ProxyProviderSvc
pps = ProxyProviderSvc()
ars=AddressRemappingSvc()
pps.ProviderNames += [ 'AddressRemappingSvc' ]
ars.TypeKeyRenameMaps += [ '%s#%s->%s' % ("TrackCollection", "MuonSpectrometerTracks", "MuonSpectrometerTracks_old") ]
cfg.addService(pps)
cfg.addService(ars)
from OutputStreamAthenaPool.OutputStreamConfig import OutputStreamCfg
itemsToRecord = ["TrackCollection#MuonSpectrometerTracks"]
itemsToRecord = ["TrackCollection#MuonSpectrometerTracks", "TrackCollection#MuonSpectrometerTracks_old"]
cfg.merge( OutputStreamCfg( ConfigFlags, 'ESD', ItemList=itemsToRecord) )
log.info(cfg._allSequences)
outstream = cfg.getEventAlgo("OutputStreamESD")
outstream.OutputLevel=DEBUG
# outstream.OutputLevel=DEBUG
outstream.ForceRead = True
# cfg.printConfig(withDetails = True, summariseProps = True)
msgService = cfg.getService('MessageSvc')
msgService.Format = "% F%48W%S%7W%R%T %0W%M"
msgService.OutputLevel=DEBUG
cfg.printConfig(withDetails = True, summariseProps = True)
f=open("MuonTrackBuilding.pkl","w")
cfg.store(f)
f.close()
# cfg.run()
if args.run:
cfg.run(20)
......@@ -464,31 +464,31 @@ namespace Muon {
IdClusIt chit_end = idClusters.end();
for( ;chit!=chit_end;++chit ){
if( msgLvl(MSG::VERBOSE) ) {
msg(MSG::VERBOSE) << " in " << m_idHelperTool->toStringDetEl(chit->first)
<< " clusters: " << chit->second.size() << std::endl;
msg(MSG::VERBOSE) << " in " << m_idHelperTool->toStringDetEl(chit->first)
<< " clusters: " << chit->second.size() << std::endl;
std::vector<const MuonClusterOnTrack*>::iterator clit = chit->second.begin();
std::vector<const MuonClusterOnTrack*>::iterator clit_end = chit->second.end();
for( ;clit!=clit_end;++clit){
msg(MSG::VERBOSE) << " " << m_idHelperTool->toString((*clit)->identify());
std::vector<const MuonClusterOnTrack*>::iterator clit = chit->second.begin();
std::vector<const MuonClusterOnTrack*>::iterator clit_end = chit->second.end();
for( ;clit!=clit_end;++clit){
msg(MSG::VERBOSE) << " " << m_idHelperTool->toString((*clit)->identify());
// hack to get correct print-out
if( clit+1 == clit_end ) msg(MSG::VERBOSE) << endmsg;
else msg(MSG::VERBOSE) << std::endl;
}
// hack to get correct print-out
if( clit+1 == clit_end ) msg(MSG::VERBOSE) << endmsg;
else msg(MSG::VERBOSE) << std::endl;
}
}
if( chit->second.empty() ){
ATH_MSG_WARNING(" empty list, could not create CompetingMuonClustersOnTrack in chamber "
<< m_idHelperTool->toString(chit->first) );
continue;
ATH_MSG_WARNING(" empty list, could not create CompetingMuonClustersOnTrack in chamber "
<< m_idHelperTool->toString(chit->first) );
continue;
}
// only create competing ROT if there is more than one PRD
if( chit->second.size() == 1 ) {
hits.push_back(chit->second.front());
allHits.push_back(chit->second.front());
continue;
hits.push_back(chit->second.front());
allHits.push_back(chit->second.front());
continue;
}
// create list of PRDs
......@@ -496,13 +496,18 @@ namespace Muon {
std::vector<const MuonClusterOnTrack*>::iterator clit = chit->second.begin();
std::vector<const MuonClusterOnTrack*>::iterator clit_end = chit->second.end();
for( ;clit!=clit_end;++clit){
prds.push_back( (*clit)->prepRawData() );
const Trk::PrepRawData* prd = (*clit)->prepRawData();
if (prd){
prds.push_back( prd );
} else {
ATH_MSG_ERROR("MuonClusterOnTrack has no PRD.");
}
}
const CompetingMuonClustersOnTrack* comprot = m_compClusterCreator->createBroadCluster(prds,0);
if( !comprot ){
ATH_MSG_WARNING(" could not create CompetingMuonClustersOnTrack in chamber " << m_idHelperTool->toString(chit->first));
continue;
ATH_MSG_WARNING(" could not create CompetingMuonClustersOnTrack in chamber " << m_idHelperTool->toString(chit->first));
continue;
}
hits.push_back(comprot);
allHits.push_back(comprot);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment