Esempio n. 1
0
def getMuonCalibAlg(eventTag):
    global topSequence, beamFlags
    try:
        return topSequence.MuonCalibAlg
    except AttributeError:
        from MuonCalibAlgs.MuonCalibAlgsConf import MuonCalib__MuonCalibAlg
        MuonCalibAlg = MuonCalib__MuonCalibAlg(
            "MuonCalibAlg",
            doMDTs=muonRecFlags.doMDTs(),
            doCSCs=muonRecFlags.doCSCs(),
            doRPCs=muonRecFlags.doRPCs(),
            doTGCs=(muonRecFlags.doTGCs()
                    and muonRecFlags.calibNtupleRawTGC()),
            doTGCCoinData=(muonRecFlags.doTGCs()
                           and muonRecFlags.calibNtupleRawTGC()),
            doTruth=rec.doTruth(),
            DoPrdSelect=muonRecFlags.doPrdSelect(
            ),  # optional cutting away of PRD hits to simulate dead channels
            NtupleName=muonRecFlags.calibNtupleOutput(
            ),  # set the name of the output calibration ntuple
            EventTag=eventTag)

        if beamFlags.beamType == 'singlebeam' or beamFlags.beamType == 'cosmics':
            MuonCalibAlg.addTriggerTag = False
        else:
            MuonCalibAlg.addTriggerTag = rec.doTrigger()
        MuonCalibAlg.doTruth = rec.doTruth()
        topSequence += MuonCalibAlg
        return topSequence.MuonCalibAlg
Esempio n. 2
0
def setupMuonCalibNtuple():
    global topSequence, muonRecFlags, beamFlags, ToolSvc, rec, DetFlags
    if not rec.doMuon() or not DetFlags.Muon_on():
        logMuon.warning(
            "Not setting up requested Muon Calibration Ntuple because Muons are off"
        )
        return

    logMuon.info("Setting up Muon Calibration Ntuple")
    try:
        configs = getCalibConfigs()
        # MuonSegmentToCalibSegment is only needed if we want segments
        if muonRecFlags.calibNtupleSegments and muonRecFlags.calibMuonStandalone:
            MuonSegmentToCalibSegment = getMuonSegmentToCalibSegment()

        # MuonCalibAlg is always needed
        eventTag = "UNKNOWN"
        if (muonRecFlags.calibNtupleSegments or muonRecFlags.calibNtupleTracks
            ) and muonRecFlags.calibMuonStandalone:
            if len(configs) >= 1:
                eventTag = configs[0]["eventTag"]
        elif muonRecFlags.calibNtupleTrigger:
            eventTag = "TRIG"
        else:
            eventTag = "HITS"

        MuonCalibAlg = getMuonCalibAlg(eventTag)
        # configure for writing ntuple
        from MuonCalibTools.MuonCalibToolsConf import MuonCalib__PatternNtupleMaker
        MuonCalibTool = MuonCalib__PatternNtupleMaker(
            "MuonCalibPatternNtupleMaker")
        MuonCalibTool.FillTruth = rec.doTruth()
        MuonCalibTool.DoRawTGC = (muonRecFlags.doTGCs()
                                  and muonRecFlags.calibNtupleRawTGC())
        ToolSvc += MuonCalibTool
        MuonCalibAlg.MuonCalibTool = MuonCalibTool

        # MuonCalibExtraTree only if we want to write tracks
        if muonRecFlags.calibNtupleTracks:
            MuonCalibTool.DelayFinish = True
            from MuonCalibExtraTreeAlg.MuonCalibExtraTreeAlgConf import MuonCalib__MuonCalibExtraTreeAlg
            MuonCalibExtraTreeAlg = MuonCalib__MuonCalibExtraTreeAlg(
                "MuonCalibExtraTreeAlg",
                NtupleName="PatternNtupleMaker",
            )
            segmentOnTrackSelector = None
            if hasattr(topSequence, "MuonSegmentToCalibSegment"):
                from MuonCalibExtraTreeAlg.MuonCalibExtraTreeAlgConf import MuonCalib__SegmentOnTrackSelector
                segmentOnTrackSelector = MuonCalib__SegmentOnTrackSelector()
                segmentOnTrackSelector.PattternLocation = "PatternsForCalibration"
                ToolSvc += segmentOnTrackSelector
                MuonCalibExtraTreeAlg.SegmentOnTrackSelector = segmentOnTrackSelector
            if not rec.doMuonCombined():
                tool_nr = 0
                from MuonCalibExtraTreeAlg.MuonCalibExtraTreeAlgConf import MuonCalib__ExtraTreeTrackFillerTool
                resPullCalc = getPublicTool("ResidualPullCalculator")
                for config in configs:
                    trackDumpTool = MuonCalib__ExtraTreeTrackFillerTool(
                        "ExtraTreeTrackFillerTool" + str(tool_nr))
                    trackDumpTool.TrackCollectionKey = config['tracksKey']
                    trackDumpTool.SegmentAuthors = [config['segmentAuthor']]
                    trackDumpTool.TrackAuthor = config['trackAuthor']
                    trackDumpTool.PullCalculator = resPullCalc
                    ToolSvc += trackDumpTool
                    MuonCalibExtraTreeAlg.TrackFillerTools.append(
                        trackDumpTool)
                    tool_nr += 1
            # configure needed tools

            # add to topSequence
            topSequence += MuonCalibExtraTreeAlg

        # MuonCalibExtraTreeTriggerAlg only if trigger is available
        if muonRecFlags.calibNtupleTrigger:  # and DetFlags.detdescr.LVL1_on() and DetFlags.haveRDO.LVL1_on():
            # protect against running without AtlasTrigger project
            doMuCTPI = True
            if doMuCTPI:
                try:
                    from TrigT1RPCRecRoiSvc import TrigT1RPCRecRoiConfig
                    from TrigT1TGCRecRoiSvc import TrigT1TGCRecRoiConfig
                except ImportError:
                    logMuon.warning(
                        "MuonCalibExtraTreeTriggerAlg.doMuCTPI = False because AtlasTrigger is not available"
                    )
                    doMuCTPI = False

            # delay writing of MuonCalibAlg
            MuonCalibTool.DelayFinish = True
            # also delay MuonCalibExtraTreeAlg if it is running
            try:
                topSequence.MuonCalibExtraTreeAlg.DelayFinish = True
            except AttributeError:
                pass

            from MuonCalibExtraTreeAlg.MuonCalibExtraTreeAlgConf import MuonCalib__MuonCalibExtraTreeTriggerAlg
            topSequence += MuonCalib__MuonCalibExtraTreeTriggerAlg(
                'MuonCalibExtraTreeTriggerAlg',
                doMuCTPI=doMuCTPI,
                doLVL1Calo=rec.doTile() or rec.doLArg()
                or DetFlags.haveRDO.Calo_on(),
                doMBTS=rec.doTile() or DetFlags.haveRDO.Tile_on())

    except:
        from AthenaCommon.Resilience import treatException
        treatException(
            "Problem in MuonCalib - Muon Calibration Ntuple configuration probably incomplete"
        )
    def configure(self,keys=None):
        super(MuonStandalone,self).configure(keys)
        if not self.isEnabled(): return

        print " configuring MuonStandalone: flags ", muonStandaloneFlags

        from AthenaCommon.BeamFlags import jobproperties
        beamFlags = jobproperties.Beam 
        SegmentLocation = "MuonSegments"
        if muonStandaloneFlags.segmentOrigin == 'TruthTracking':
            SegmentLocation = "ThirdChainSegments"

        if muonRecFlags.doNSWNewThirdChain():
            getPublicTool("MuonLayerHoughTool")
            self.addAlg( CfgMgr.MuonLayerHoughAlg( "MuonLayerHoughAlg", PrintSummary = muonStandaloneFlags.printSummary()  ) )
            if not muonStandaloneFlags.patternsOnly():
                SegmentFinder = getPublicTool("MuonClusterSegmentFinderTool")
                Cleaner = getPublicToolClone("MuonTrackCleaner_seg","MuonTrackCleaner")
                Cleaner.PullCut = 3
                Cleaner.PullCutPhi = 3
                SegmentFinder.TrackCleaner = Cleaner
            # for test purposes allow parallel running of truth segment finding and new segment finder
                MuonSegmentFinderAlg = CfgMgr.MuonSegmentFinderAlg( "MuonSegmentMaker",SegmentCollectionName=SegmentLocation, 
                                                                    MuonPatternCalibration = getPublicTool("MuonPatternCalibration"),
                                                                    MuonPatternSegmentMaker = getPublicTool("MuonPatternSegmentMaker"),
                                                                    MuonTruthSummaryTool = None,
                                                                    PrintSummary = muonStandaloneFlags.printSummary() )
                if( muonRecFlags.doCSCs() ):
                    getPublicTool("CscSegmentUtilTool")
                    getPublicTool("Csc2dSegmentMaker")
                    getPublicTool("Csc4dSegmentMaker")
                else:
                    MuonSegmentFinderAlg.Csc2dSegmentMaker = None
                    MuonSegmentFinderAlg.Csc4dSegmentMaker = None
                self.addAlg( MuonSegmentFinderAlg )
        else:
            getPublicTool("MuonLayerHoughTool")
            self.addAlg( CfgMgr.MooSegmentFinderAlg( "MuonSegmentMaker",
                                                     SegmentFinder = getPublicToolClone("MuonSegmentFinder","MooSegmentFinder",
                                                                                        DoSummary=muonStandaloneFlags.printSummary()),
                                                     MuonSegmentOutputLocation = SegmentLocation,
                                                     UseCSC = muonRecFlags.doCSCs(),
                                                     UseMDT = muonRecFlags.doMDTs(),
                                                     UseRPC = muonRecFlags.doRPCs(),
                                                     UseTGC = muonRecFlags.doTGCs(),
                                                     UseTGCPriorBC = muonRecFlags.doTGCs() and muonRecFlags.useTGCPriorNextBC(),
                                                     UseTGCNextBC  = muonRecFlags.doTGCs() and muonRecFlags.useTGCPriorNextBC(),
                                                     doTGCClust = muonRecFlags.doTGCClusterSegmentFinding(),
                                                     doRPCClust = muonRecFlags.doRPCClusterSegmentFinding() ))



            self.addAlg( CfgMgr.MooSegmentFinderAlg( "MuonSegmentMaker_NCB",
                                                     SegmentFinder = getPublicToolClone("MooSegmentFinder_NCB","MuonSegmentFinder",
                                                                                        DoSummary=False,
                                                                                        Csc2dSegmentMaker = getPublicToolClone("Csc2dSegmentMaker_NCB","Csc2dSegmentMaker",
                                                                                                                               segmentTool = getPublicToolClone("CscSegmentUtilTool_NCB",
                                                                                                                                                                "CscSegmentUtilTool",
                                                                                                                                                                TightenChi2 = False, 
                                                                                                                                                                IPconstraint=False)),
                                                                                        Csc4dSegmentMaker = getPublicToolClone("Csc4dSegmentMaker_NCB","Csc4dSegmentMaker",
                                                                                                                               segmentTool = getPublicTool("CscSegmentUtilTool_NCB")),
                                                                                        DoMdtSegments=False,DoSegmentCombinations=False,DoSegmentCombinationCleaning=False),
                                                     MuonPatternCombinationLocation = "NCB_MuonHoughPatternCombinations", 
                                                     MuonSegmentOutputLocation = "NCB_MuonSegments", 
                                                     MuonSegmentCombinationOutputLocation = "NCB_MooreSegmentCombinations",
                                                     UseCSC = muonRecFlags.doCSCs(),
                                                     UseMDT = False,
                                                     UseRPC = False,
                                                     UseTGC = False,
                                                     UseTGCPriorBC = False,
                                                     UseTGCNextBC  = False,
                                                     doTGCClust = False,
                                                     doRPCClust = False) )

        self.addAlg( CfgMgr.xAODMaker__MuonSegmentCnvAlg("MuonSegmentCnvAlg") )
        self.addAlg( CfgMgr.xAODMaker__MuonSegmentCnvAlg("MuonSegmentCnvAlg_NCB",SegmentContainerName="NCB_MuonSegments",xAODContainerName="NCB_MuonSegments") )
        
        if muonStandaloneFlags.doSegmentsOnly():
            return	                    
        # Tracks builder
        #
        # add the algorithm (which uses the MuonTrackSteering)
        # 
        TrackBuilder = CfgMgr.MuPatTrackBuilder("MuPatTrackBuilder", TrackSteering = getPublicTool("MuonTrackSteering") )
        self.addAlg( TrackBuilder )
        
        self.registerOutputKey("MuonSpectrometerTracks",   self.MuPatTrackBuilder, "SpectrometerTrackOutputLocation")
        self.registerInputKey ("MuonSegments", self.MuPatTrackBuilder, "MuonSegmentCollection"   )

        
        if muonStandaloneFlags.createTrackParticles() and DetFlags.ID_on():
            from xAODTrackingCnv.xAODTrackingCnvConf import xAODMaker__TrackParticleCnvAlg
            xAODTrackParticleCnvAlg = xAODMaker__TrackParticleCnvAlg( name = "MuonStandaloneTrackParticleCnvAlg", 
                                                                      TrackParticleCreator = getPublicTool("MuonParticleCreatorTool"),
                                                                      TrackContainerName = "MuonSpectrometerTracks",
                                                                      xAODTrackParticlesFromTracksContainerName = "MuonSpectrometerTrackParticles",
                                                                      ConvertTrackParticles = False,
                                                                      ConvertTracks = True )
            self.addAlg( xAODTrackParticleCnvAlg )