diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 33980e01bf52084b83cf7a5ae905242b734c1cd7..943296aba23d55877329c7c4b49a0600924be501 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -14,7 +14,7 @@ repos: - id: trailing-whitespace - id: end-of-file-fixer - id: check-yaml - exclude: "\\.clang-format$|DD4TESTCOND" + exclude: "\\.clang-format$|DD4TESTCOND|RichMirrorAlignmentOnline|RichMirrAlign" - id: check-added-large-files - repo: https://github.com/pre-commit/mirrors-clang-format rev: v16.0.6 diff --git a/Rich/Panoptes/doc/release.notes b/Rich/Panoptes/doc/release.notes index a6a31b8384f795b29b14659c164c1394085498e5..7c69c6ff385ee400eed9df9145e38a8d505df3c6 100755 --- a/Rich/Panoptes/doc/release.notes +++ b/Rich/Panoptes/doc/release.notes @@ -498,4 +498,3 @@ use FieldMap v5r* -no_auto_imports ! 2008-02-11 - Ulrich Kerzel - initial revision - diff --git a/Rich/Panoptes/options/2022-data-richalign.py b/Rich/Panoptes/options/2022-data-richalign.py index 54c3dc4f8c7b4f506e9939f595329e41db501142..98422ccb0b510dc169a04faf20d6424ec74324f8 100644 --- a/Rich/Panoptes/options/2022-data-richalign.py +++ b/Rich/Panoptes/options/2022-data-richalign.py @@ -9,8 +9,9 @@ # or submit itself to any jurisdiction. # ############################################################################### import os -from Moore import options + from Configurables import LHCbApp +from Moore import options # This script is dd4hep only @@ -20,24 +21,25 @@ absolutely_all_files = True if absolutely_all_files: import glob + base_dir = "/calib/align/LHCb/Rich/*/" dirs = glob.glob(base_dir, recursive=True) files = [] for dir_i in dirs: - files += glob.glob(dir_i + '*') + files += glob.glob(dir_i + "*") else: files = [os.path.join(base_dir, f) for f in os.listdir(base_dir)] -#files = files[:1000] +# files = files[:1000] files = files[:25] options.input_files = files -options.input_type = 'MDF' +options.input_type = "MDF" -LHCbApp().DataType = 'Upgrade' +LHCbApp().DataType = "Upgrade" options.simulation = False -options.conddb_tag = 'master' -options.dddb_tag = 'run3/trunk' +options.conddb_tag = "master" +options.dddb_tag = "run3/trunk" diff --git a/Rich/Panoptes/options/MinMomentum10GeV.py b/Rich/Panoptes/options/MinMomentum10GeV.py index e4672c45b4e1bdec37e8012b9db8e190ace6660a..ede855b72b1ea19b86aa3ebda9297c64a3957762 100644 --- a/Rich/Panoptes/options/MinMomentum10GeV.py +++ b/Rich/Panoptes/options/MinMomentum10GeV.py @@ -8,9 +8,8 @@ # granted to it by virtue of its status as an Intergovernmental Organization # # or submit itself to any jurisdiction. # ############################################################################### -from PyConf.Algorithms import (PrForwardTrackingVelo, PrMatchNN, - PrHybridSeeding) from GaudiKernel.SystemOfUnits import GeV +from PyConf.Algorithms import PrForwardTrackingVelo, PrHybridSeeding, PrMatchNN min_p = 10 * GeV PrForwardTrackingVelo.global_bind(MinP=min_p) diff --git a/Rich/Panoptes/options/MinMomentum30GeV.py b/Rich/Panoptes/options/MinMomentum30GeV.py index db0361a3e627f47b71ecdaf045692922c4428b47..3f3edaca4a308860b67ceb1df97312c774e6b36d 100644 --- a/Rich/Panoptes/options/MinMomentum30GeV.py +++ b/Rich/Panoptes/options/MinMomentum30GeV.py @@ -8,9 +8,8 @@ # granted to it by virtue of its status as an Intergovernmental Organization # # or submit itself to any jurisdiction. # ############################################################################### -from PyConf.Algorithms import (PrForwardTrackingVelo, PrMatchNN, - PrHybridSeeding) from GaudiKernel.SystemOfUnits import GeV +from PyConf.Algorithms import PrForwardTrackingVelo, PrHybridSeeding, PrMatchNN min_p = 30 * GeV PrForwardTrackingVelo.global_bind(MinP=min_p) diff --git a/Rich/Panoptes/options/RequiredDets.py b/Rich/Panoptes/options/RequiredDets.py index 1b47f0f10f212004adc4b81ca8cf64128ed41c66..e943dc7a2c237d6a2978f7f9555464f5df425d7c 100644 --- a/Rich/Panoptes/options/RequiredDets.py +++ b/Rich/Panoptes/options/RequiredDets.py @@ -10,16 +10,18 @@ ############################################################################### import os + from DDDB.CheckDD4Hep import UseDD4Hep # Define test name myName = os.getenv("QMTTEST_NAME", "UNDEFINED") # Is UT active in this task ? -noUT = ("noUT" in myName) +noUT = "noUT" in myName if UseDD4Hep: from Configurables import LHCb__Det__LbDD4hep__DD4hepSvc as DD4hepSvc - dd4hep = DD4hepSvc( - DetectorList=["/world", "Magnet", "VP", "FT", "Rich1", "Rich2"]) - if not noUT: dd4hep.DetectorList += ["UT"] + + dd4hep = DD4hepSvc(DetectorList=["/world", "Magnet", "VP", "FT", "Rich1", "Rich2"]) + if not noUT: + dd4hep.DetectorList += ["UT"] diff --git a/Rich/Panoptes/options/RichCommissioning-Online.py b/Rich/Panoptes/options/RichCommissioning-Online.py index 40616620b8c166057918e3e91fed77b3fb7eb5cf..d2c4b716b2ee34650dc33fcd4c8b9d6784f8285f 100644 --- a/Rich/Panoptes/options/RichCommissioning-Online.py +++ b/Rich/Panoptes/options/RichCommissioning-Online.py @@ -9,29 +9,26 @@ # or submit itself to any jurisdiction. # ############################################################################### """ - RICH comissioning monitor +RICH comissioning monitor - based on /group/online/dataflow/cmtuser/ONLINE_v7r10/Online/RawBankSizes/options/EventSizeMon.py +based on /group/online/dataflow/cmtuser/ONLINE_v7r10/Online/RawBankSizes/options/EventSizeMon.py - @author C.Jones +@author C.Jones """ + __version__ = "1.0" __author__ = "Markus Frank <Markus.Frank@cern.ch>" import Configurables import Gaudi.Configuration as Gaudi -import OnlineEnvBase as OnlineEnv - import GaudiOnline - -from Configurables import LHCbApp -from Configurables import Online__AlgFlowManager as AlgFlowManager -from Configurables import HLTControlFlowMgr, ExecutionReportsWriter +import OnlineEnvBase as OnlineEnv +from Configurables import ExecutionReportsWriter, HLTControlFlowMgr, LHCbApp from Configurables import LHCb__Det__LbDD4hep__DD4hepSvc as DD4hepSvc - +from Configurables import Online__AlgFlowManager as AlgFlowManager from Moore import options -from RecoConf.config import run_reconstruction from Panoptes.commissioning import daq_commissioning +from RecoConf.config import run_reconstruction options.data_type = "Upgrade" @@ -42,20 +39,22 @@ nThreads = 1 options.n_threads = nThreads OnlineEnv.NumberOfThreads = nThreads -#options.event_store = 'EvtStoreSvc' +# options.event_store = 'EvtStoreSvc' options.geometry_version = OnlineEnv.DDDBTag options.conditions_version = OnlineEnv.CondDBTag -options.input_type = 'Online' -options.output_type = 'Online' +options.input_type = "Online" +options.output_type = "Online" options.simulation = False dd4hep = DD4hepSvc(DetectorList=["/world", "Magnet", "Rich1", "Rich2"]) # When running online directly access the primary checkout on disc instead -dd4hep.ConditionsLocation = 'file:///group/online/hlt/conditions.run3/lhcb-conditions-database' +dd4hep.ConditionsLocation = ( + "file:///group/online/hlt/conditions.run3/lhcb-conditions-database" +) # Conditions that should also have an explicit run-by-run entry dd4hep.LimitedIOVPaths = ["Conditions/LHCb/Online/Tell40Links.yml"] @@ -65,17 +64,18 @@ application = GaudiOnline.Application( outputLevel=OnlineEnv.OutputLevel, partitionName=OnlineEnv.PartitionName, partitionID=OnlineEnv.PartitionID, - classType=GaudiOnline.Class1) + classType=GaudiOnline.Class1, +) # Something wrong with this, as causes configuration to silently # abort. So comment out for now.. -#application.setup_fifolog(format='%-8LEVEL %-24SOURCE', device='fifo') +# application.setup_fifolog(format='%-8LEVEL %-24SOURCE', device='fifo') -application.setup_mbm_access('Events', True) -cfm = HLTControlFlowMgr('HLTControlFlowMgr') +application.setup_mbm_access("Events", True) +cfm = HLTControlFlowMgr("HLTControlFlowMgr") application.setup_hive(cfm, 44) -application.setup_monitoring('RichMon') +application.setup_monitoring("RichMon") application.monSvc.DimUpdateInterval = 1 application.config.burstPrintCount = 30000 # Mode selection:: synch: 0 async_queued: 1 sync_queued: 2 @@ -89,9 +89,9 @@ application.updateAndReset.saveSetDir = "/hist/Savesets" if OnlineEnv.PartitionName.startswith("TEST"): application.updateAndReset.saveSetDir = "Savesets" application.config.MBM_requests = [ - 'EvType=2;TriggerMask=0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF;VetoMask=0,0,0,0;MaskType=ANY;UserType=USER;Frequency=PERC;Perc=100.0' + "EvType=2;TriggerMask=0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF;VetoMask=0,0,0,0;MaskType=ANY;UserType=USER;Frequency=PERC;Perc=100.0" ] application.config.expandTAE = True -print('Setup complete....') +print("Setup complete....") diff --git a/Rich/Panoptes/options/RichCommissioning-testIO.py b/Rich/Panoptes/options/RichCommissioning-testIO.py index ee25c5e3138e4a6205cc721e7173583e0f0b2221..03db39869826b7f6c8384582008473beaeb139a0 100644 --- a/Rich/Panoptes/options/RichCommissioning-testIO.py +++ b/Rich/Panoptes/options/RichCommissioning-testIO.py @@ -8,19 +8,21 @@ # granted to it by virtue of its status as an Intergovernmental Organization # # or submit itself to any jurisdiction. # ############################################################################### +import glob +import os + from Moore import options -from RecoConf.config import run_reconstruction from Panoptes.commissioning import daq_commissioning -import glob, os +from RecoConf.config import run_reconstruction -partition = os.getenv('partition') -runNumber = os.getenv('runNumber') +partition = os.getenv("partition") +runNumber = os.getenv("runNumber") print(partition, runNumber) -runNumber = '%010d' % int(runNumber) -if partition == 'local': - path = '/localdisk/rich_tmp_data/runs/' +runNumber = "%010d" % int(runNumber) +if partition == "local": + path = "/localdisk/rich_tmp_data/runs/" else: - path = '/hlt2/objects/%s/%s/' % (partition, runNumber) + path = "/hlt2/objects/%s/%s/" % (partition, runNumber) files = sorted(glob.glob(path + "*.mdf")) data = ["DATAFILE='PFN:" + file + "'" for file in files] @@ -31,9 +33,9 @@ options.evt_max = 100000 options.n_threads = 8 -#options.conddb_tag = 'upgrade/sim-20210625-vc-md100' -options.conddb_tag = 'upgrade/jonrob/rich-disable-link-for-beam-test' -options.dddb_tag = 'upgrade/dddb-20210617' +# options.conddb_tag = 'upgrade/sim-20210625-vc-md100' +options.conddb_tag = "upgrade/jonrob/rich-disable-link-for-beam-test" +options.dddb_tag = "upgrade/dddb-20210617" options.input_files = data @@ -45,10 +47,11 @@ with daq_commissioning.bind(offlineMode=True): run_reconstruction(options, daq_commissioning) # Swap out the IOSvcMM with IOSvcFileRead -from Configurables import LHCb__MDF__IOSvcFileRead, LHCb__MDF__IOAlg +from Configurables import LHCb__MDF__IOAlg, LHCb__MDF__IOSvcFileRead from Gaudi.Configuration import allConfigurables + iosvc = LHCb__MDF__IOSvcFileRead( - 'LHCb::MDF::IOSvcFileRead', + "LHCb::MDF::IOSvcFileRead", Input=options.input_files, # BufferNbEvents=20000, # NBanksReserve=1200, diff --git a/Rich/Panoptes/options/RichCommissioning.py b/Rich/Panoptes/options/RichCommissioning.py index 880544525a46f3792d765c39a20a0ded9866b327..0114518088694330505ae092db82aadf73ea5d70 100644 --- a/Rich/Panoptes/options/RichCommissioning.py +++ b/Rich/Panoptes/options/RichCommissioning.py @@ -9,35 +9,35 @@ # or submit itself to any jurisdiction. # ############################################################################### +import os + from Moore import options -from RecoConf.config import run_reconstruction from Panoptes.commissioning import daq_commissioning -import os +from RecoConf.config import run_reconstruction -isQMTTest = 'QMTTEST_NAME' in os.environ +isQMTTest = "QMTTEST_NAME" in os.environ -partition = os.getenv('partition') -runNumber = os.getenv('runNumber') -evtMax = os.getenv('evtMax') +partition = os.getenv("partition") +runNumber = os.getenv("runNumber") +evtMax = os.getenv("evtMax") if partition and runNumber and not isQMTTest: - print("Partition", partition, "Run", runNumber) options.histo_file = f"/calib/rich/RichCommissioning_{runNumber}.root" evt_max = evtMax if evtMax else -1 -options.evt_max = (1000 if isQMTTest else evt_max) +options.evt_max = 1000 if isQMTTest else evt_max options.n_threads = 1 -options.print_freq = (100 if isQMTTest else 1000) +options.print_freq = 100 if isQMTTest else 1000 from Configurables import LHCb__Det__LbDD4hep__DD4hepSvc as DD4hepSvc + dd4hep = DD4hepSvc(DetectorList=["/world", "Magnet", "Rich1", "Rich2"]) -pit_db_loc = '/group/online/hlt/conditions.run3/lhcb-conditions-database' +pit_db_loc = "/group/online/hlt/conditions.run3/lhcb-conditions-database" if os.path.exists(pit_db_loc): - dd4hep.ConditionsLocation = 'file:' + pit_db_loc + dd4hep.ConditionsLocation = "file:" + pit_db_loc -with daq_commissioning.bind( - offlineMode=True, enableTuple=False, runNumber=runNumber): +with daq_commissioning.bind(offlineMode=True, enableTuple=False, runNumber=runNumber): run_reconstruction(options, daq_commissioning) diff --git a/Rich/Panoptes/options/RichPhotonCounting-Online.py b/Rich/Panoptes/options/RichPhotonCounting-Online.py index 417e8932a5f64d2f799308ee5f678a6e9defa566..d5f8352b7a4e258ebda8efa9ba691fa67afd5177 100644 --- a/Rich/Panoptes/options/RichPhotonCounting-Online.py +++ b/Rich/Panoptes/options/RichPhotonCounting-Online.py @@ -9,28 +9,24 @@ # or submit itself to any jurisdiction. # ############################################################################### """ - RICH comissioning monitor +RICH comissioning monitor - based on /group/online/dataflow/cmtuser/ONLINE_v7r10/Online/RawBankSizes/options/EventSizeMon.py +based on /group/online/dataflow/cmtuser/ONLINE_v7r10/Online/RawBankSizes/options/EventSizeMon.py - @author C.Jones +@author C.Jones """ + __version__ = "1.0" __author__ = "Markus Frank <Markus.Frank@cern.ch>" import Configurables import Gaudi.Configuration as Gaudi -import OnlineEnvBase as OnlineEnv - import GaudiOnline - -from Configurables import LHCbApp -from Configurables import Online__AlgFlowManager as AlgFlowManager -from Configurables import HLTControlFlowMgr, ExecutionReportsWriter +import OnlineEnvBase as OnlineEnv +from Configurables import ExecutionReportsWriter, HLTControlFlowMgr, LHCbApp from Configurables import LHCb__Det__LbDD4hep__DD4hepSvc as DD4hepSvc - +from Configurables import Online__AlgFlowManager as AlgFlowManager from GaudiKernel.SystemOfUnits import GeV - from Moore import options from RecoConf.config import run_reconstruction @@ -43,10 +39,10 @@ nThreads = 1 options.n_threads = nThreads OnlineEnv.NumberOfThreads = nThreads -#options.event_store = 'EvtStoreSvc' +# options.event_store = 'EvtStoreSvc' -options.input_type = 'Online' -options.output_type = 'Online' +options.input_type = "Online" +options.output_type = "Online" options.simulation = False options.geometry_version = OnlineEnv.DDDBTag @@ -54,14 +50,16 @@ options.conditions_version = OnlineEnv.CondDBTag # Is UT active in this task ? noUT = False -#noUT = "no_ut" in OnlineEnv.HLTType +# noUT = "no_ut" in OnlineEnv.HLTType -dd4hep = DD4hepSvc( - DetectorList=["/world", "Magnet", "VP", "FT", "Rich1", "Rich2"]) -if not noUT: dd4hep.DetectorList += ["UT"] +dd4hep = DD4hepSvc(DetectorList=["/world", "Magnet", "VP", "FT", "Rich1", "Rich2"]) +if not noUT: + dd4hep.DetectorList += ["UT"] # When running online directly access the primary checkout on disc instead -dd4hep.ConditionsLocation = 'file:///group/online/hlt/conditions.run3/lhcb-conditions-database' +dd4hep.ConditionsLocation = ( + "file:///group/online/hlt/conditions.run3/lhcb-conditions-database" +) # Conditions that should also have an explicit run-by-run entry dd4hep.LimitedIOVPaths = [ # Tel40 links condition @@ -97,10 +95,12 @@ dd4hep.LimitedIOVPaths = [ "Conditions/Rich2/Alignment/PDPanels.yml", ] -from PyConf.Algorithms import Rich__Future__Rec__Counting__PhotonCounting as PhotonCounting -from PyConf.Algorithms import (PrForwardTrackingVelo, PrMatchNN, - PrHybridSeeding) from Panoptes.photoncounting import standalone_photon_counting +from PyConf.Algorithms import PrForwardTrackingVelo, PrHybridSeeding, PrMatchNN +from PyConf.Algorithms import ( + Rich__Future__Rec__Counting__PhotonCounting as PhotonCounting, +) + if noUT: from RecoConf.hlt2_tracking import make_hlt2_tracks_without_UT as track_maker else: @@ -112,40 +112,41 @@ out_level = Gaudi.INFO minPRads = (30 * GeV, 30 * GeV) min_p = min(minPRads) -with PrForwardTrackingVelo.bind(MinP=min_p),\ - PrMatchNN.bind(MinP=min_p),\ - PrHybridSeeding.bind(MinP=min_p),\ - track_maker.bind(use_pr_kf=True, light_reco=True, fast_reco=True),\ - PhotonCounting.bind(OutputLevel=out_level,\ - CreatePDFSummary=True),\ - standalone_photon_counting.bind(noUT=noUT,\ - do_data_monitoring=False) : +with ( + PrForwardTrackingVelo.bind(MinP=min_p), + PrMatchNN.bind(MinP=min_p), + PrHybridSeeding.bind(MinP=min_p), + track_maker.bind(use_pr_kf=True, light_reco=True, fast_reco=True), + PhotonCounting.bind(OutputLevel=out_level, CreatePDFSummary=True), + standalone_photon_counting.bind(noUT=noUT, do_data_monitoring=False), +): run_reconstruction(options, standalone_photon_counting) application = GaudiOnline.Application( outputLevel=options.output_level, partitionName=OnlineEnv.PartitionName, partitionID=OnlineEnv.PartitionID, - classType=GaudiOnline.Class1) + classType=GaudiOnline.Class1, +) # Something wrong with this, as causes configuration to silently # abort. So comment out for now.. -#application.setup_fifolog() +# application.setup_fifolog() -application.setup_mbm_access('Events', True) +application.setup_mbm_access("Events", True) flow = AlgFlowManager("EventLoop") application.setup_hive(flow, 44) # see https://gitlab.cern.ch/lhcb/MooreOnline/-/blob/15bc29016c0132f9a6034078471d857d568867da/MooreOnlineConf/options/online.py # HACK: transfer options from HLTControlFlowMgr -cfm = HLTControlFlowMgr('HLTControlFlowMgr') +cfm = HLTControlFlowMgr("HLTControlFlowMgr") flow.CompositeCFNodes = cfm.CompositeCFNodes flow.BarrierAlgNames = cfm.BarrierAlgNames # HACK: tell the HltDecReports creator to use the online scheduler # only works because there is exactly one instance of ExecutionReportsWriter -#ExecutionReportsWriter().Scheduler = flow +# ExecutionReportsWriter().Scheduler = flow -application.setup_monitoring('RichPhotonCounting') +application.setup_monitoring("RichPhotonCounting") application.monSvc.DimUpdateInterval = 1 application.config.burstPrintCount = 30000 # Mode selection:: synch: 0 async_queued: 1 sync_queued: 2 @@ -162,9 +163,9 @@ application.updateAndReset.saveHistograms = 1 application.updateAndReset.saverCycle = 180 application.updateAndReset.saveSetDir = "/hist/Savesets" application.config.MBM_requests = [ - 'EvType=2;TriggerMask=0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF;VetoMask=0,0,0,0;MaskType=ANY;UserType=USER;Frequency=PERC;Perc=100.0' + "EvType=2;TriggerMask=0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF;VetoMask=0,0,0,0;MaskType=ANY;UserType=USER;Frequency=PERC;Perc=100.0" ] application.outputLevel = options.output_level -print('Setup complete....') +print("Setup complete....") diff --git a/Rich/Panoptes/options/RichPhotonCounting.py b/Rich/Panoptes/options/RichPhotonCounting.py index 68d0f72aa10ddf6ff97e7ab5e33f8f4a8a91fae9..e97963a588107eee7ef92b5a0e7aba2d96945318 100644 --- a/Rich/Panoptes/options/RichPhotonCounting.py +++ b/Rich/Panoptes/options/RichPhotonCounting.py @@ -9,24 +9,26 @@ # or submit itself to any jurisdiction. # ############################################################################### -import os, multiprocessing +import multiprocessing +import os + +from Gaudi.Configuration import DEBUG, INFO, VERBOSE +from GaudiKernel.SystemOfUnits import GeV from Moore import options -from RecoConf.config import run_reconstruction from Panoptes.photoncounting import standalone_photon_counting -from PyConf.Algorithms import Rich__Future__Rec__Counting__PhotonCounting as PhotonCounting -from PyConf.Algorithms import (PrForwardTrackingVelo, PrMatchNN, - PrHybridSeeding) - +from PyConf.Algorithms import PrForwardTrackingVelo, PrHybridSeeding, PrMatchNN +from PyConf.Algorithms import ( + Rich__Future__Rec__Counting__PhotonCounting as PhotonCounting, +) +from RecoConf.config import run_reconstruction from ROOT import gROOT -from Gaudi.Configuration import VERBOSE, DEBUG, INFO -from GaudiKernel.SystemOfUnits import GeV options.output_level = INFO # Silence ROOT gROOT.ProcessLine("gErrorIgnoreLevel = kWarning;") -isQMTTest = 'QMTTEST_NAME' in os.environ +isQMTTest = "QMTTEST_NAME" in os.environ myName = os.getenv("QMTTEST_NAME", "RichPhotonCounting") @@ -34,13 +36,14 @@ options.histo_file = myName + ".root" # Override previously set defaults # ROOT file reader currently not thread safe :( -options.n_threads = (1 if options.input_type == 'ROOT' or isQMTTest else - multiprocessing.cpu_count()) -#options.n_threads = 1 -options.evt_max = (5000 if isQMTTest else -1) +options.n_threads = ( + 1 if options.input_type == "ROOT" or isQMTTest else multiprocessing.cpu_count() +) +# options.n_threads = 1 +options.evt_max = 5000 if isQMTTest else -1 # Is UT active in this task ? -noUT = ("noUT" in myName) +noUT = "noUT" in myName # Enable additional monitoring algorithms ? do_moni = isQMTTest @@ -52,7 +55,7 @@ run_by_run_histos = True quadratic_background_model = True # Output level for photon counting alg -out_level = (INFO if isQMTTest else VERBOSE) +out_level = INFO if isQMTTest else VERBOSE # Momentum Cuts minPRads = (30 * GeV, 30 * GeV) @@ -63,18 +66,21 @@ if noUT: else: from RecoConf.hlt2_tracking import make_hlt2_tracks as track_maker -with PrForwardTrackingVelo.bind(MinP=min_p),\ - PrMatchNN.bind(MinP=min_p),\ - PrHybridSeeding.bind(MinP=min_p),\ - track_maker.bind(use_pr_kf=True, light_reco=True, fast_reco=True),\ - PhotonCounting.bind( OutputLevel=out_level,\ - CreatePDFSummary=not isQMTTest,\ - OKToPublish=not isQMTTest,\ - AllowCountingAtStop=not isQMTTest,\ - RunByRunHists=run_by_run_histos,\ - QuadraticBckModel=quadratic_background_model),\ - standalone_photon_counting.bind(noUT=noUT,\ - min_p=minPRads,\ - offlineMode=True,\ - do_data_monitoring=do_moni) : +with ( + PrForwardTrackingVelo.bind(MinP=min_p), + PrMatchNN.bind(MinP=min_p), + PrHybridSeeding.bind(MinP=min_p), + track_maker.bind(use_pr_kf=True, light_reco=True, fast_reco=True), + PhotonCounting.bind( + OutputLevel=out_level, + CreatePDFSummary=not isQMTTest, + OKToPublish=not isQMTTest, + AllowCountingAtStop=not isQMTTest, + RunByRunHists=run_by_run_histos, + QuadraticBckModel=quadratic_background_model, + ), + standalone_photon_counting.bind( + noUT=noUT, min_p=minPRads, offlineMode=True, do_data_monitoring=do_moni + ), +): run_reconstruction(options, standalone_photon_counting) diff --git a/Rich/Panoptes/options/RichRefIndexCalib-Online.py b/Rich/Panoptes/options/RichRefIndexCalib-Online.py index b36a4bc811ec4c13a01dc849806812dca89d5c2e..710c952fd2286f28bb1b5b69b39613d2795f1e2b 100755 --- a/Rich/Panoptes/options/RichRefIndexCalib-Online.py +++ b/Rich/Panoptes/options/RichRefIndexCalib-Online.py @@ -9,28 +9,24 @@ # or submit itself to any jurisdiction. # ############################################################################### """ - RICH comissioning monitor +RICH comissioning monitor - based on /group/online/dataflow/cmtuser/ONLINE_v7r10/Online/RawBankSizes/options/EventSizeMon.py +based on /group/online/dataflow/cmtuser/ONLINE_v7r10/Online/RawBankSizes/options/EventSizeMon.py - @author C.Jones +@author C.Jones """ + __version__ = "1.0" __author__ = "Markus Frank <Markus.Frank@cern.ch>" import Configurables import Gaudi.Configuration as Gaudi -import OnlineEnvBase as OnlineEnv - import GaudiOnline - -from Configurables import LHCbApp -from Configurables import Online__AlgFlowManager as AlgFlowManager -from Configurables import HLTControlFlowMgr, ExecutionReportsWriter +import OnlineEnvBase as OnlineEnv +from Configurables import ExecutionReportsWriter, HLTControlFlowMgr, LHCbApp from Configurables import LHCb__Det__LbDD4hep__DD4hepSvc as DD4hepSvc - +from Configurables import Online__AlgFlowManager as AlgFlowManager from GaudiKernel.SystemOfUnits import GeV - from Moore import options from RecoConf.config import run_reconstruction @@ -43,10 +39,10 @@ nThreads = 1 options.n_threads = nThreads OnlineEnv.NumberOfThreads = nThreads -#options.event_store = 'EvtStoreSvc' +# options.event_store = 'EvtStoreSvc' -options.input_type = 'Online' -options.output_type = 'Online' +options.input_type = "Online" +options.output_type = "Online" options.simulation = False options.geometry_version = OnlineEnv.DDDBTag @@ -54,14 +50,16 @@ options.conditions_version = OnlineEnv.CondDBTag # Is UT active in this task ? noUT = False -#noUT = "no_ut" in OnlineEnv.HLTType +# noUT = "no_ut" in OnlineEnv.HLTType -dd4hep = DD4hepSvc( - DetectorList=["/world", "Magnet", "VP", "FT", "Rich1", "Rich2"]) -if not noUT: dd4hep.DetectorList += ["UT"] +dd4hep = DD4hepSvc(DetectorList=["/world", "Magnet", "VP", "FT", "Rich1", "Rich2"]) +if not noUT: + dd4hep.DetectorList += ["UT"] # When running online directly access the primary checkout on disc instead -dd4hep.ConditionsLocation = 'file:///group/online/hlt/conditions.run3/lhcb-conditions-database' +dd4hep.ConditionsLocation = ( + "file:///group/online/hlt/conditions.run3/lhcb-conditions-database" +) # Conditions that should also have an explicit run-by-run entry dd4hep.LimitedIOVPaths = [ # Tel40 links condition @@ -97,10 +95,10 @@ dd4hep.LimitedIOVPaths = [ "Conditions/Rich2/Alignment/PDPanels.yml", ] -from PyConf.Algorithms import Rich__Future__Rec__Calib__RefIndexCalib as RefIndexCalib -from PyConf.Algorithms import (PrForwardTrackingVelo, PrMatchNN, - PrHybridSeeding) from Panoptes.calibration import standalone_rich_ref_index_calib +from PyConf.Algorithms import PrForwardTrackingVelo, PrHybridSeeding, PrMatchNN +from PyConf.Algorithms import Rich__Future__Rec__Calib__RefIndexCalib as RefIndexCalib + if noUT: from RecoConf.hlt2_tracking import make_hlt2_tracks_without_UT as track_maker else: @@ -120,44 +118,49 @@ out_level = Gaudi.INFO minPRads = (10 * GeV, 20 * GeV) min_p = min(minPRads) -with PrForwardTrackingVelo.bind(MinP=min_p),\ - PrMatchNN.bind(MinP=min_p),\ - PrHybridSeeding.bind(MinP=min_p),\ - track_maker.bind(use_pr_kf=True, light_reco=True, fast_reco=True),\ - RefIndexCalib.bind(OutputLevel=out_level,\ - CreatePDFSummary=True,\ - UseRunningAverage=RunningAv,\ - nPolFull=nPolFull,\ - RichFitTypes=(ckFitForm, ckFitForm)),\ - standalone_rich_ref_index_calib.bind(noUT=noUT,\ - do_data_monitoring=False,\ - set_scale_factors_to_one=False) : +with ( + PrForwardTrackingVelo.bind(MinP=min_p), + PrMatchNN.bind(MinP=min_p), + PrHybridSeeding.bind(MinP=min_p), + track_maker.bind(use_pr_kf=True, light_reco=True, fast_reco=True), + RefIndexCalib.bind( + OutputLevel=out_level, + CreatePDFSummary=True, + UseRunningAverage=RunningAv, + nPolFull=nPolFull, + RichFitTypes=(ckFitForm, ckFitForm), + ), + standalone_rich_ref_index_calib.bind( + noUT=noUT, do_data_monitoring=False, set_scale_factors_to_one=False + ), +): run_reconstruction(options, standalone_rich_ref_index_calib) application = GaudiOnline.Application( outputLevel=options.output_level, partitionName=OnlineEnv.PartitionName, partitionID=OnlineEnv.PartitionID, - classType=GaudiOnline.Class1) + classType=GaudiOnline.Class1, +) # Something wrong with this, as causes configuration to silently # abort. So comment out for now.. -#application.setup_fifolog() +# application.setup_fifolog() -application.setup_mbm_access('Events', True) +application.setup_mbm_access("Events", True) flow = AlgFlowManager("EventLoop") application.setup_hive(flow, 44) # see https://gitlab.cern.ch/lhcb/MooreOnline/-/blob/15bc29016c0132f9a6034078471d857d568867da/MooreOnlineConf/options/online.py # HACK: transfer options from HLTControlFlowMgr -cfm = HLTControlFlowMgr('HLTControlFlowMgr') +cfm = HLTControlFlowMgr("HLTControlFlowMgr") flow.CompositeCFNodes = cfm.CompositeCFNodes flow.BarrierAlgNames = cfm.BarrierAlgNames # HACK: tell the HltDecReports creator to use the online scheduler # only works because there is exactly one instance of ExecutionReportsWriter -#ExecutionReportsWriter().Scheduler = flow +# ExecutionReportsWriter().Scheduler = flow -application.setup_monitoring('RichRefIndexCal') +application.setup_monitoring("RichRefIndexCal") application.monSvc.DimUpdateInterval = 1 application.config.burstPrintCount = 30000 # Mode selection:: synch: 0 async_queued: 1 sync_queued: 2 @@ -174,9 +177,9 @@ application.updateAndReset.saveHistograms = 1 application.updateAndReset.saverCycle = 180 application.updateAndReset.saveSetDir = "/hist/Savesets" application.config.MBM_requests = [ - 'EvType=2;TriggerMask=0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF;VetoMask=0,0,0,0;MaskType=ANY;UserType=USER;Frequency=PERC;Perc=100.0' + "EvType=2;TriggerMask=0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF;VetoMask=0,0,0,0;MaskType=ANY;UserType=USER;Frequency=PERC;Perc=100.0" ] application.outputLevel = options.output_level -print('Setup complete....') +print("Setup complete....") diff --git a/Rich/Panoptes/options/RichRefIndexCalib.py b/Rich/Panoptes/options/RichRefIndexCalib.py index 1793ea0b157b32cad29ec6ff057c24d334a525b5..1a664c9ee56752c5d2a76195003f994337da66b6 100644 --- a/Rich/Panoptes/options/RichRefIndexCalib.py +++ b/Rich/Panoptes/options/RichRefIndexCalib.py @@ -9,24 +9,24 @@ # or submit itself to any jurisdiction. # ############################################################################### -import os, multiprocessing +import multiprocessing +import os + +from Gaudi.Configuration import DEBUG, INFO, VERBOSE +from GaudiKernel.SystemOfUnits import GeV from Moore import options -from RecoConf.config import run_reconstruction from Panoptes.calibration import standalone_rich_ref_index_calib +from PyConf.Algorithms import PrForwardTrackingVelo, PrHybridSeeding, PrMatchNN from PyConf.Algorithms import Rich__Future__Rec__Calib__RefIndexCalib as RefIndexCalib -from PyConf.Algorithms import (PrForwardTrackingVelo, PrMatchNN, - PrHybridSeeding) - +from RecoConf.config import run_reconstruction from ROOT import gROOT -from Gaudi.Configuration import VERBOSE, DEBUG, INFO -from GaudiKernel.SystemOfUnits import GeV options.output_level = INFO # Silence ROOT gROOT.ProcessLine("gErrorIgnoreLevel = kWarning;") -isQMTTest = 'QMTTEST_NAME' in os.environ +isQMTTest = "QMTTEST_NAME" in os.environ myName = os.getenv("QMTTEST_NAME", "RichRefIndexCalib") @@ -34,32 +34,33 @@ options.histo_file = myName + ".root" # Override previously set defaults # ROOT file reader currently not thread safe :( -options.n_threads = (1 if options.input_type == 'ROOT' or isQMTTest else - multiprocessing.cpu_count()) -#options.n_threads = 1 -evtsForQMT = (1000 if options.simulation else 5000) -evtsForInt = (10000 if options.simulation else 50000) -options.evt_max = (evtsForQMT if isQMTTest else evtsForInt) +options.n_threads = ( + 1 if options.input_type == "ROOT" or isQMTTest else multiprocessing.cpu_count() +) +# options.n_threads = 1 +evtsForQMT = 1000 if options.simulation else 5000 +evtsForInt = 10000 if options.simulation else 50000 +options.evt_max = evtsForQMT if isQMTTest else evtsForInt # Is UT active in this task ? -noUT = ("noUT" in myName) +noUT = "noUT" in myName # PDF Writer options ckFitForm = ["AsymNormal:FreeNPol"] # Time between periodic calibrations -calibTime = (100000 if isQMTTest else 20) -#calibTime = 100000 +calibTime = 100000 if isQMTTest else 20 +# calibTime = 100000 # Fit retry period -retryPeriod = (20 if isQMTTest else 1) +retryPeriod = 20 if isQMTTest else 1 # Auditors (only with 1 thread) -#if not isQMTTest: +# if not isQMTTest: # options.auditors += ["MemoryAuditor"] # Enable additional monitoring algorithms ? -#do_moni = isQMTTest +# do_moni = isQMTTest do_moni = True do_det_debug = not isQMTTest do_mc_checking = options.simulation and do_moni @@ -71,7 +72,7 @@ run_by_run_histos = False set_scale_to_one = False # Output level for calibration alg -out_level = (INFO if isQMTTest else VERBOSE) +out_level = INFO if isQMTTest else VERBOSE # polynominal degree in background fits nPolFull = (3, 3) @@ -80,14 +81,14 @@ nPolFull = (3, 3) RunningAv = not isQMTTest # Override run number for MC samples -forcedRunN = (999999 if options.simulation else 0) +forcedRunN = 999999 if options.simulation else 0 # Momentum Cuts minPRads = (10 * GeV, 20 * GeV) min_p = min(minPRads) # Calib at stop ? -#runCalAtStop = not isQMTTest +# runCalAtStop = not isQMTTest runCalAtStop = True if noUT: @@ -95,26 +96,32 @@ if noUT: else: from RecoConf.hlt2_tracking import make_hlt2_tracks as track_maker -with PrForwardTrackingVelo.bind(MinP=min_p),\ - PrMatchNN.bind(MinP=min_p),\ - PrHybridSeeding.bind(MinP=min_p),\ - track_maker.bind(use_pr_kf=True, light_reco=True, fast_reco=True),\ - RefIndexCalib.bind( OutputLevel=out_level,\ - CreatePDFSummary=not isQMTTest,\ - OKToPublish=not isQMTTest,\ - RichFitTypes=(ckFitForm, ckFitForm),\ - UseRunningAverage=RunningAv,\ - AllowCalibAtStop=runCalAtStop,\ - nPolFull=nPolFull,\ - MinTimeBetweenCalibs=calibTime,\ - FailedFitRetryPeriod=retryPeriod,\ - RunByRunHists=run_by_run_histos, - ForcedRunNumber=forcedRunN),\ - standalone_rich_ref_index_calib.bind(noUT=noUT,\ - min_p=minPRads,\ - offlineMode=True,\ - do_detector_debug=do_det_debug,\ - do_data_monitoring=do_moni,\ - do_mc_checking=do_mc_checking, - set_scale_factors_to_one=set_scale_to_one) : +with ( + PrForwardTrackingVelo.bind(MinP=min_p), + PrMatchNN.bind(MinP=min_p), + PrHybridSeeding.bind(MinP=min_p), + track_maker.bind(use_pr_kf=True, light_reco=True, fast_reco=True), + RefIndexCalib.bind( + OutputLevel=out_level, + CreatePDFSummary=not isQMTTest, + OKToPublish=not isQMTTest, + RichFitTypes=(ckFitForm, ckFitForm), + UseRunningAverage=RunningAv, + AllowCalibAtStop=runCalAtStop, + nPolFull=nPolFull, + MinTimeBetweenCalibs=calibTime, + FailedFitRetryPeriod=retryPeriod, + RunByRunHists=run_by_run_histos, + ForcedRunNumber=forcedRunN, + ), + standalone_rich_ref_index_calib.bind( + noUT=noUT, + min_p=minPRads, + offlineMode=True, + do_detector_debug=do_det_debug, + do_data_monitoring=do_moni, + do_mc_checking=do_mc_checking, + set_scale_factors_to_one=set_scale_to_one, + ), +): run_reconstruction(options, standalone_rich_ref_index_calib) diff --git a/Rich/Panoptes/options/Rich_MC_DD4HEP_Recon_PID_Example.py b/Rich/Panoptes/options/Rich_MC_DD4HEP_Recon_PID_Example.py index 3b2b9d779c373037f99905a92da544f2d9fd2f44..e928c712e7c1255bc61341d93ec028a0d3ec94f3 100644 --- a/Rich/Panoptes/options/Rich_MC_DD4HEP_Recon_PID_Example.py +++ b/Rich/Panoptes/options/Rich_MC_DD4HEP_Recon_PID_Example.py @@ -9,19 +9,20 @@ # or submit itself to any jurisdiction. # ############################################################################### -import glob, os -from GaudiConf import IOHelper +import glob +import os + +from Configurables import DDDBConf, LHCbApp +from DDDB.CheckDD4Hep import UseDD4Hep from Gaudi.Configuration import * +from GaudiConf import IOHelper -from ROOT import gROOT -#from Gaudi.Configuration import VERBOSE, DEBUG, INFO +# from Gaudi.Configuration import VERBOSE, DEBUG, INFO from GaudiKernel.SystemOfUnits import GeV - from Moore import options -from DDDB.CheckDD4Hep import UseDD4Hep -from Configurables import DDDBConf, LHCbApp +from ROOT import gROOT -options.input_type = 'ROOT' +options.input_type = "ROOT" LHCbApp().CondDBtag = "sim10/run3-ideal" DDDBConf().GeometryVersion = "run3/trunk" @@ -29,9 +30,9 @@ DDDBConf().GeometryVersion = "run3/trunk" options.geometry_version = "run3/trunk" options.conditions_version = "sim10/run3-ideal" -#options.input_type = "XDIGI" +# options.input_type = "XDIGI" -#options.input_raw_format = 4.3 +# options.input_raw_format = 4.3 options.simulation = True @@ -54,15 +55,19 @@ Input_Local_File6 = "Rich-Boole-TimeGateCut-25000-Prod-set-9-10-SetC-Run3-trunk- Input_Local_File7 = "Rich-Boole-TimeGateCut-25000-Prod-set-11-12-SetC-Run3-trunk-Sim10-Ideal-Nov-2024-DD4HEP-Extended.digi" Input_Local_File8 = "Rich-Boole-TimeGateCut-25000-Prod-set-13-15-16-SetC-Run3-trunk-Sim10-Ideal-Nov-2024-DD4HEP-Extended.digi" -#print("InputFiles ",Input_Local_File0," ",Input_Local_File1," ",Input_Local_File2," ",Input_Local_File3," ",Input_Local_File4," ",Input_Local_File5," ",Input_Local_File6) -#print("InputFiles ",Input_Local_File7," ",Input_Local_File8) +# print("InputFiles ",Input_Local_File0," ",Input_Local_File1," ",Input_Local_File2," ",Input_Local_File3," ",Input_Local_File4," ",Input_Local_File5," ",Input_Local_File6) +# print("InputFiles ",Input_Local_File7," ",Input_Local_File8) options.input_files = [ - InputArea + Input_Local_File0, InputArea + Input_Local_File1, - InputArea + Input_Local_File2, InputArea + Input_Local_File3, - InputArea + Input_Local_File4, InputArea + Input_Local_File5, - InputArea + Input_Local_File6, InputArea + Input_Local_File7, - InputArea + Input_Local_File8 + InputArea + Input_Local_File0, + InputArea + Input_Local_File1, + InputArea + Input_Local_File2, + InputArea + Input_Local_File3, + InputArea + Input_Local_File4, + InputArea + Input_Local_File5, + InputArea + Input_Local_File6, + InputArea + Input_Local_File7, + InputArea + Input_Local_File8, ] ######################################################### @@ -80,41 +85,53 @@ options.print_freq = 10 # Due to issues with hit sorting in FT disable Mat corrections # See for more details https://gitlab.cern.ch/lhcb/Panoptes/-/issues/7 from PyConf.Algorithms import PrStoreSciFiHits + PrStoreSciFiHits.global_bind(ApplyMatContractionCalibration=False) # To be removed once the issue is resolved properly. -from PyConf.Algorithms import (PrForwardTrackingVelo, PrMatchNN, - PrHybridSeeding) +from PyConf.Algorithms import PrForwardTrackingVelo, PrHybridSeeding, PrMatchNN if UseDD4Hep: from Configurables import LHCb__Det__LbDD4hep__DD4hepSvc as DD4hepSvc - dd4hep = DD4hepSvc(DetectorList=[ - "/world", "Magnet", "VP", "FT", "UT", "Rich1", "Rich2", "Ecal", "Hcal" - ]) - #if not noUT: dd4hep.DetectorList += ["UT"] + dd4hep = DD4hepSvc( + DetectorList=[ + "/world", + "Magnet", + "VP", + "FT", + "UT", + "Rich1", + "Rich2", + "Ecal", + "Hcal", + ] + ) + + # if not noUT: dd4hep.DetectorList += ["UT"] ################################################################ -#Activate tracking +# Activate tracking importOptions("$PANOPTESROOT/options/Tracking.py") -import os, multiprocessing +import multiprocessing +import os + +from Gaudi.Configuration import DEBUG, INFO, VERBOSE +from GaudiKernel.SystemOfUnits import GeV from Moore import options, run_reconstruction from Panoptes.BrahmaSutraConfiguration import BrahmaSutraConf - from ROOT import gROOT -from Gaudi.Configuration import VERBOSE, DEBUG, INFO -from GaudiKernel.SystemOfUnits import GeV options.output_level = INFO -#options.output_level = DEBUG +# options.output_level = DEBUG # Silence ROOT gROOT.ProcessLine("gErrorIgnoreLevel = kWarning;") -#isQMTTest = 'QMTTEST_NAME' in os.environ -#myName = os.getenv("QMTTEST_NAME", "RichMCRecon") +# isQMTTest = 'QMTTEST_NAME' in os.environ +# myName = os.getenv("QMTTEST_NAME", "RichMCRecon") myOutputArea = "/afs/cern.ch/work/s/seaso/DataFiles/PanoptesOutput/Dec10-2024/prod/" myLocalName = "Rich_MC_Recon_Example_DataSet_0_16" myLocalNtupleName = "Rich_MC_ReconNtuple_Example_DataSet_0_16" @@ -126,10 +143,10 @@ options.ntuple_file = myOutputArea + myLocalNtupleName + ".root" options.n_threads = 1 # Is UT active in this task ? -#noUT = ("noUT" in myName) +# noUT = ("noUT" in myName) # Override run number for MC samples -forcedRunN = (999999 if options.simulation else 0) +forcedRunN = 999999 if options.simulation else 0 # Momentum Cuts @@ -137,11 +154,11 @@ minPRads = (2 * GeV, 2 * GeV, 2 * GeV) min_p = min(minPRads) # Enable additional monitoring algorithms ? -#do_moni = isQMTTest +# do_moni = isQMTTest do_moni = True # Output level for photon counting alg -#out_level = (INFO if isQMTTest else VERBOSE) +# out_level = (INFO if isQMTTest else VERBOSE) out_level = INFO options.output_level = INFO # Silence ROOT @@ -149,9 +166,10 @@ gROOT.ProcessLine("gErrorIgnoreLevel = kWarning;") from RecoConf.hlt2_tracking import make_hlt2_tracks as track_maker -with PrForwardTrackingVelo.bind(MinP=min_p),\ - PrMatchNN.bind(MinP=min_p),\ - track_maker.bind(use_pr_kf=True, light_reco=True, fast_reco=False),\ - BrahmaSutraConf.bind(do_data_monitoring=do_moni,ParticleGun=False): - +with ( + PrForwardTrackingVelo.bind(MinP=min_p), + PrMatchNN.bind(MinP=min_p), + track_maker.bind(use_pr_kf=True, light_reco=True, fast_reco=False), + BrahmaSutraConf.bind(do_data_monitoring=do_moni, ParticleGun=False), +): run_reconstruction(options, BrahmaSutraConf) diff --git a/Rich/Panoptes/options/Tracking.py b/Rich/Panoptes/options/Tracking.py index eac6aeb42ce5ee64e6cf90c2497223cf50db97af..9f6747e42836dab30205b16a81bc832b874ccdec 100644 --- a/Rich/Panoptes/options/Tracking.py +++ b/Rich/Panoptes/options/Tracking.py @@ -11,18 +11,23 @@ import os -from PyConf.Algorithms import ( - PrForwardTrackingVelo, VPRetinaFullClusterDecoder, - VeloRetinaClusterTrackingSIMD, PrMatchNN, PrHybridSeeding) - -from RecoConf.legacy_rec_hlt1_tracking import (make_VeloClusterTrackingSIMD, - make_velo_full_clusters) - from GaudiKernel.SystemOfUnits import GeV +from PyConf.Algorithms import ( + PrForwardTrackingVelo, + PrHybridSeeding, + PrMatchNN, + VeloRetinaClusterTrackingSIMD, + VPRetinaFullClusterDecoder, +) +from RecoConf.legacy_rec_hlt1_tracking import ( + make_velo_full_clusters, + make_VeloClusterTrackingSIMD, +) hltSettings = "UNKNOWN" try: import OnlineEnvBase + hltSettings = OnlineEnvBase.HLTType print("OnlineEnvBase.HLTType=", hltSettings) except ImportError: @@ -31,9 +36,7 @@ except ImportError: if not "veloSP" in hltSettings: print("Configuring for Velo cluster F/W") - make_VeloClusterTrackingSIMD.global_bind( - algorithm=VeloRetinaClusterTrackingSIMD) - make_velo_full_clusters.global_bind( - make_full_cluster=VPRetinaFullClusterDecoder) + make_VeloClusterTrackingSIMD.global_bind(algorithm=VeloRetinaClusterTrackingSIMD) + make_velo_full_clusters.global_bind(make_full_cluster=VPRetinaFullClusterDecoder) else: print("Configuring for Velo SuperPixel F/W") diff --git a/Rich/Panoptes/options/data_online.py b/Rich/Panoptes/options/data_online.py index 0d4068ebd37ea6287751a7103e4572956718df6b..0d2847bbd2d900951972a62b30bbade07ac5db0a 100644 --- a/Rich/Panoptes/options/data_online.py +++ b/Rich/Panoptes/options/data_online.py @@ -11,6 +11,7 @@ import os import re from datetime import datetime + from PyConf.application import ApplicationOptions filename_expr = re.compile( @@ -27,7 +28,7 @@ options.input_type = "MDF" base_dir = "/calib/align/LHCb/Rich/0000256292/" -#base_dir = "/calib/align/LHCb/Rich/0000261947/" +# base_dir = "/calib/align/LHCb/Rich/0000261947/" def sort_names(f): @@ -35,12 +36,8 @@ def sort_names(f): m = filename_expr.match(f) if m is None: return m - funs = [ - int, lambda t: int(datetime.strptime(t, "%Y%m%d-%H%M%S").timestamp()), - int - ] - return tuple( - fun(m.group(k)) for fun, k in zip(funs, ("run", "time", "rest"))) + funs = [int, lambda t: int(datetime.strptime(t, "%Y%m%d-%H%M%S").timestamp()), int] + return tuple(fun(m.group(k)) for fun, k in zip(funs, ("run", "time", "rest"))) absolutely_all_files = True @@ -50,35 +47,38 @@ divide_2022_2023 = 259566 if absolutely_all_files and exclude_2022 is False and exclude_2023 is False: import glob + base_dir = "/calib/align/LHCb/Rich/*/" dirs = glob.glob(base_dir, recursive=True) files = [] for dir_i in dirs: - files += glob.glob(dir_i + '*') + files += glob.glob(dir_i + "*") elif absolutely_all_files and exclude_2022 is True and exclude_2023 is False: import glob import re + base_dir = "/calib/align/LHCb/Rich/0000*/" dirs = glob.glob(base_dir, recursive=True) files = [] for dir_i in dirs: # Extract the number from the directory string using regular expressions - num = int(re.search(r'/0000(\d{6})/', dir_i).group(1)) + num = int(re.search(r"/0000(\d{6})/", dir_i).group(1)) # Check if the number is greater than or equal to 259 if num >= divide_2022_2023: - files += glob.glob(dir_i + '*') + files += glob.glob(dir_i + "*") elif absolutely_all_files and exclude_2022 is False and exclude_2023 is True: import glob import re + base_dir = "/calib/align/LHCb/Rich/0000*/" dirs = glob.glob(base_dir, recursive=True) files = [] for dir_i in dirs: # Extract the number from the directory string using regular expressions - num = int(re.search(r'/0000(\d{6})/', dir_i).group(1)) + num = int(re.search(r"/0000(\d{6})/", dir_i).group(1)) # Check if the number is greater than or equal to 259 if num < divide_2022_2023: - files += glob.glob(dir_i + '*') + files += glob.glob(dir_i + "*") elif absolutely_all_files and exclude_2022 is True and exclude_2023 is True: print("You just excluded everything") else: @@ -90,8 +90,8 @@ else: # print(file_size) # quit() -#files = files[:1000] -#files = files[:25] +# files = files[:1000] +# files = files[:25] # # files = sorted(files, key=sort_names) @@ -100,8 +100,8 @@ files = sorted(files, reverse=True) options.input_files = files -print(f'{len(options.input_files)} .mdf files...') +print(f"{len(options.input_files)} .mdf files...") file_size = 0 for file in files: file_size += os.path.getsize(file) -print('file_size', file_size) +print("file_size", file_size) diff --git a/Rich/Panoptes/options/hlt2_reco_rich2_panoptes.py b/Rich/Panoptes/options/hlt2_reco_rich2_panoptes.py index 82a14434faf576c372550a57c18ddc4d095c1ae9..38a851845e3b544d1a25f11b465e614743885fe3 100644 --- a/Rich/Panoptes/options/hlt2_reco_rich2_panoptes.py +++ b/Rich/Panoptes/options/hlt2_reco_rich2_panoptes.py @@ -12,66 +12,76 @@ import glob import math from ruamel.yaml import YAML + yaml = YAML() from GaudiKernel.SystemOfUnits import ( - GeV, ) + GeV, +) from Moore import ( options, run_reconstruction, ) from Panoptes.alignment import ( - standalone_rich_mirror_align_reco, ) + standalone_rich_mirror_align_reco, +) + """Options for running over data with FT raw bank version 6.""" from RecoConf.decoders import ( - default_ft_decoding_version, ) + default_ft_decoding_version, +) from RecoConf.rich_data_monitoring import ( - default_rich_monitoring_options, alignment_rich_monitoring_options, + default_rich_monitoring_options, ) from RecoConf.rich_reconstruction import ( - default_rich_reco_options, ) + default_rich_reco_options, +) options.n_threads = 10 -#options.n_threads = 40 - -options.input_files = sorted([ - 'mdf:root://eoslhcb.cern.ch/%s' % f for f in glob.glob( - r'/eos/lhcb/grid/prod/lhcb/MC/Upgrade/MDF/00146082/000*/00146082_*') -]) -options.input_type = 'MDF' -options.dddb_tag = 'dddb-20201211' -options.conddb_tag = 'sim-20201218-vc-md100' +# options.n_threads = 40 + +options.input_files = sorted( + [ + "mdf:root://eoslhcb.cern.ch/%s" % f + for f in glob.glob( + r"/eos/lhcb/grid/prod/lhcb/MC/Upgrade/MDF/00146082/000*/00146082_*" + ) + ] +) +options.input_type = "MDF" +options.dddb_tag = "dddb-20201211" +options.conddb_tag = "sim-20201218-vc-md100" -if 'md' in options.conddb_tag: - mp = 'md' -elif 'mu' in options.conddb_tag: - mp = 'mu' +if "md" in options.conddb_tag: + mp = "md" +elif "mu" in options.conddb_tag: + mp = "mu" options.evt_max = 100 -#options.evt_max = 40000 -#options.evt_max = 1000000 -#options.evt_max = 2000000 -#options.evt_max = 3000000 -#options.evt_max = 5000000 - -n_kevts = str(math.trunc(options.evt_max / 1000)) + 'k' - -#addinfo = '_minp60_'+mp+n_kevts -#addinfo = '_minp60_phi_'+mp+n_kevts -#addinfo = '_minp60_qnt20f60_'+mp+n_kevts -addinfo = '_minp60_qnt20f60_rndmpresc_' + mp + n_kevts -#addinfo = '_minp60_phi2_'+mp+n_kevts -#addinfo = '_'+mp+n_kevts -#addinfo = '_minp60_subset_'+mp+n_kevts -#addinfo = '_minp60_subset_theta2_'+mp+n_kevts -#addinfo = '' - -rich = 'rich2' -radiator = 'Rich2Gas' +# options.evt_max = 40000 +# options.evt_max = 1000000 +# options.evt_max = 2000000 +# options.evt_max = 3000000 +# options.evt_max = 5000000 + +n_kevts = str(math.trunc(options.evt_max / 1000)) + "k" + +# addinfo = '_minp60_'+mp+n_kevts +# addinfo = '_minp60_phi_'+mp+n_kevts +# addinfo = '_minp60_qnt20f60_'+mp+n_kevts +addinfo = "_minp60_qnt20f60_rndmpresc_" + mp + n_kevts +# addinfo = '_minp60_phi2_'+mp+n_kevts +# addinfo = '_'+mp+n_kevts +# addinfo = '_minp60_subset_'+mp+n_kevts +# addinfo = '_minp60_subset_theta2_'+mp+n_kevts +# addinfo = '' + +rich = "rich2" +radiator = "Rich2Gas" mirror_align_tasks = [ - 'Produce', # fill the production set of histograms + "Produce", # fill the production set of histograms #'Monitor', # add various checking histograms #'MapExlore', # explore tracks and photons for the HLT1 pre-selection line "map" #'MapConstruct', # construct exploratory data structure for the HLT1 pre-selection line "map" @@ -91,7 +101,7 @@ default_moni_opts_l2 = {} default_reco_opts = {} -default_reco_opts.update({"PhotonSelection": 'None'}) +default_reco_opts.update({"PhotonSelection": "None"}) align_opts = {} @@ -224,81 +234,88 @@ if 'qnt20f60' in addinfo: align_opts.update(optimal_mirr_combs) # yapf: enable -if 'minp60' in addinfo: - align_opts.update({"MinP4Align": 60. * GeV}) +if "minp60" in addinfo: + align_opts.update({"MinP4Align": 60.0 * GeV}) -if 'theta2' in addinfo: +if "theta2" in addinfo: align_opts.update({"DeltaThetaRange": 0.002}) -if not '_phi' in addinfo: - if '40k' in addinfo: - align_opts.update({"PoorestPopulation": 10.}) - elif '1000k' in addinfo: - align_opts.update({"PoorestPopulation": 341.}) - elif '5000k' in addinfo: - align_opts.update({"PoorestPopulation": 2688.}) - -if '_phi' in addinfo: - if '40k' in addinfo: - align_opts.update({"PoorestPopulation": 1.}) - elif '1000k' in addinfo: - align_opts.update({"PoorestPopulation": 20.}) - elif '5000k' in addinfo: - align_opts.update({"PoorestPopulation": 113.}) - -if 'qnt20f60' in addinfo: - if '5000k' in addinfo: - align_opts.update({"PoorestPopulation": 310.}) - -if '_phi2' in addinfo: +if not "_phi" in addinfo: + if "40k" in addinfo: + align_opts.update({"PoorestPopulation": 10.0}) + elif "1000k" in addinfo: + align_opts.update({"PoorestPopulation": 341.0}) + elif "5000k" in addinfo: + align_opts.update({"PoorestPopulation": 2688.0}) + +if "_phi" in addinfo: + if "40k" in addinfo: + align_opts.update({"PoorestPopulation": 1.0}) + elif "1000k" in addinfo: + align_opts.update({"PoorestPopulation": 20.0}) + elif "5000k" in addinfo: + align_opts.update({"PoorestPopulation": 113.0}) + +if "qnt20f60" in addinfo: + if "5000k" in addinfo: + align_opts.update({"PoorestPopulation": 310.0}) + +if "_phi2" in addinfo: align_opts.update({"MinUsefulTracks": 2}) -with open(rich + '_session_timestamp.yml') as inp: +with open(rich + "_session_timestamp.yml") as inp: ts = yaml.load(inp) -current_variant = ts + '_' + rich + addinfo +current_variant = ts + "_" + rich + addinfo variant = {"Variant": current_variant} align_opts.update(variant) -with open(rich + '_variant.yml', 'w') as out: +with open(rich + "_variant.yml", "w") as out: yaml.dump(current_variant, out) align_opts_dump = alignment_rich_monitoring_options( - radiator=radiator, align_rich_moni_opts_modify=align_opts) + radiator=radiator, align_rich_moni_opts_modify=align_opts +) align_opts_dump.update( default_rich_monitoring_options( default_rich_moni_opts_modify=default_moni_opts, default_rich_moni_opts_modify_level2=default_moni_opts_l2, - )) + ) +) opts_new = {} opts_new[ts] = {} -opts_new[ts]['reco_opts'] = align_opts_dump +opts_new[ts]["reco_opts"] = align_opts_dump -with open(rich + '_reco_opts.yml', 'a') as out: +with open(rich + "_reco_opts.yml", "a") as out: yaml.dump(opts_new, out) # cumulative substring with all tasks chosen -tasks = '' +tasks = "" for task in mirror_align_tasks: - if task != 'Produce': - tasks += '_' + task.lower() + if task != "Produce": + tasks += "_" + task.lower() # itertation number substring -with open(rich + '_iter_number.yml') as inp: - iN = '_i' + str(yaml.load(inp)) +with open(rich + "_iter_number.yml") as inp: + iN = "_i" + str(yaml.load(inp)) # output root file with histograms -options.histo_file = current_variant + tasks + '_histos' + iN + '.root' - -with default_ft_decoding_version.bind(value=6), \ - default_rich_reco_options.bind(default_rich_reco_opts_modify=default_reco_opts), \ - default_rich_monitoring_options.bind(default_rich_moni_opts_modify=default_moni_opts, \ - default_rich_moni_opts_modify_level2=default_moni_opts_l2), \ - alignment_rich_monitoring_options.bind(radiator=radiator, \ - align_rich_moni_opts_modify=align_opts), \ - standalone_rich_mirror_align_reco.bind(RichGas=radiator, \ - MirrorAlignTasks=mirror_align_tasks, \ - noUT=True): +options.histo_file = current_variant + tasks + "_histos" + iN + ".root" + +with ( + default_ft_decoding_version.bind(value=6), + default_rich_reco_options.bind(default_rich_reco_opts_modify=default_reco_opts), + default_rich_monitoring_options.bind( + default_rich_moni_opts_modify=default_moni_opts, + default_rich_moni_opts_modify_level2=default_moni_opts_l2, + ), + alignment_rich_monitoring_options.bind( + radiator=radiator, align_rich_moni_opts_modify=align_opts + ), + standalone_rich_mirror_align_reco.bind( + RichGas=radiator, MirrorAlignTasks=mirror_align_tasks, noUT=True + ), +): run_reconstruction(options, standalone_rich_mirror_align_reco) diff --git a/Rich/Panoptes/options/offline_data_2024.py b/Rich/Panoptes/options/offline_data_2024.py index 1bc488b6cb9dc5eb03ebcd528871d81e83f99855..dd8a805707125a3d2fa6262fa305e52d0afc2a17 100644 --- a/Rich/Panoptes/options/offline_data_2024.py +++ b/Rich/Panoptes/options/offline_data_2024.py @@ -13,26 +13,27 @@ # partition=calib runNumber=298770 evtMax=2000 gaudirun.py ${PANOPTESROOT}/options/offline_data_2024.py ${PANOPTESROOT}/options/RichCommissioning.py # note : wihtout partition or runNumber, evtMax should be less than 50000 (single in put file) -from Moore import options +import glob +import os + from Configurables import LHCbApp -import glob, os +from Moore import options -partition = os.getenv('partition') -runNumber = os.getenv('runNumber') +partition = os.getenv("partition") +runNumber = os.getenv("runNumber") if partition and runNumber: - - lrunNumber = '%010d' % int(runNumber) - if partition == 'local': - path = '/localdisk/rich_tmp_data/runs/' - elif partition == 'daqarea': - path = '/daqarea51/rich/' - elif partition == 'calib': - path = '/calib/online/tmpHlt1Dumps/LHCb/%s/' % lrunNumber - elif partition == 'tae': - path = '/calib/TAE/LHCb/%s/' % lrunNumber + lrunNumber = "%010d" % int(runNumber) + if partition == "local": + path = "/localdisk/rich_tmp_data/runs/" + elif partition == "daqarea": + path = "/daqarea51/rich/" + elif partition == "calib": + path = "/calib/online/tmpHlt1Dumps/LHCb/%s/" % lrunNumber + elif partition == "tae": + path = "/calib/TAE/LHCb/%s/" % lrunNumber else: - path = '/hlt2/objects/%s/%s/' % (partition, lrunNumber) + path = "/hlt2/objects/%s/%s/" % (partition, lrunNumber) files = sorted(glob.glob(path + "*.mdf"), key=os.path.getmtime) options.input_files = files @@ -49,5 +50,6 @@ else: # Due to issues with hit sorting in FT disable Mat corrections # See for more details https://gitlab.cern.ch/lhcb/Panoptes/-/issues/7 from PyConf.Algorithms import PrStoreSciFiHits + PrStoreSciFiHits.global_bind(ApplyMatContractionCalibration=False) # To be removed once the issue is resolved properly. diff --git a/Rich/Panoptes/options/rich1_iter_number.py b/Rich/Panoptes/options/rich1_iter_number.py index f8ec92b636c90ff5bfb07b1d16a8e4c5ccd7c047..b39a669477b7aa3f5a1bbc340351261673836cbd 100644 --- a/Rich/Panoptes/options/rich1_iter_number.py +++ b/Rich/Panoptes/options/rich1_iter_number.py @@ -12,5 +12,5 @@ from ruamel.yaml import YAML yaml = YAML() itNr = 0 -with open('rich1_iter_number.yml', 'w') as fout: +with open("rich1_iter_number.yml", "w") as fout: yaml.dump(itNr, fout) diff --git a/Rich/Panoptes/options/rich1_mirror_align_task.py b/Rich/Panoptes/options/rich1_mirror_align_task.py index 91f996a21aadd6731ae97d76888e3f786681bd9b..c7c0ecff0b1f70ce8c06967ab0c28a25159873b1 100644 --- a/Rich/Panoptes/options/rich1_mirror_align_task.py +++ b/Rich/Panoptes/options/rich1_mirror_align_task.py @@ -9,34 +9,36 @@ # or submit itself to any jurisdiction. # ############################################################################### -import os, multiprocessing, re +import multiprocessing +import os +import re +from DDDB.CheckDD4Hep import UseDD4Hep from GaudiKernel.SystemOfUnits import GeV - from Moore import ( - options, ) -from PyConf.application import ( - configure_input, - configure, + options, ) from Panoptes.alignment import ( standalone_rich_mirror_align_reco, standalone_rich_online_align_reco, ) +from PyConf.application import ( + configure, + configure_input, +) from RecoConf.rich_data_monitoring import ( - default_rich_monitoring_options, alignment_rich_monitoring_options, + default_rich_monitoring_options, ) from RecoConf.rich_reconstruction import ( - default_rich_reco_options, ) - + default_rich_reco_options, +) from ruamel.yaml import ( - YAML, ) - -from DDDB.CheckDD4Hep import UseDD4Hep + YAML, +) tasks = [ - 'Produce', # # fill the production set of histograms + "Produce", # # fill the production set of histograms #'Monitor', # add various checking histograms #'MapExlore', # explore tracks and photons for the HLT1 pre-selection line "map" #'MapConstruct', # construct exploratory data structure for the HLT1 pre-selection line "map" @@ -52,21 +54,22 @@ tasks = [ # cumulative substring with all tasks chosen # to be included into histo_file name -histo_tasks = '' +histo_tasks = "" for task in tasks: - histo_tasks += '_' + task + histo_tasks += "_" + task -isQMTest = 'QMTTEST_NAME' in os.environ +isQMTest = "QMTTEST_NAME" in os.environ # Override previously set defaults # ROOT file reader currently not thread safe :( -options.n_threads = (1 if options.input_type == 'ROOT' or isQMTest else - multiprocessing.cpu_count()) +options.n_threads = ( + 1 if options.input_type == "ROOT" or isQMTest else multiprocessing.cpu_count() +) yaml = YAML() # retrieve variant -with open('rich1_variant.yml') as inp: +with open("rich1_variant.yml") as inp: variant = yaml.load(inp) if isQMTest: @@ -76,7 +79,7 @@ if isQMTest: options.set_input_from_testfiledb("rich-mirror-align-2022") else: # retrieve number of events - em = re.findall(r'([\d]+)k', variant)[0] + em = re.findall(r"([\d]+)k", variant)[0] iem = int(em) if iem == 0: options.evt_max = 100 @@ -86,10 +89,13 @@ else: # configure input config = configure_input(options) -thisName = ("rich1_mirror_align_task_noUT" if '_noUT_' in variant else - f"rich1_mirror_align_task{'_detdesc' if not UseDD4Hep else ''}") +thisName = ( + "rich1_mirror_align_task_noUT" + if "_noUT_" in variant + else f"rich1_mirror_align_task{'_detdesc' if not UseDD4Hep else ''}" +) -myName = (os.environ["QMTTEST_NAME"] if isQMTest else thisName) +myName = os.environ["QMTTEST_NAME"] if isQMTest else thisName noUT = "noUT" in myName @@ -99,44 +105,44 @@ align_opts = {} # start updating the dicts: -default_reco_opts.update({"PhotonSelection": 'None'}) +default_reco_opts.update({"PhotonSelection": "None"}) align_opts.update({"Variant": variant}) -if 'subset' in variant: +if "subset" in variant: central_mirr_combs = { "PrebookHistos": [ - ('p00', 's03'), - ('p01', 's06'), - ('p02', 's12'), - ('p03', 's09'), + ("p00", "s03"), + ("p01", "s06"), + ("p02", "s12"), + ("p03", "s09"), ], } align_opts.update(central_mirr_combs) -if 'minp40' in variant: - align_opts.update({"MinP4Align": 40. * GeV}) +if "minp40" in variant: + align_opts.update({"MinP4Align": 40.0 * GeV}) -if 'theta2' in variant: +if "theta2" in variant: align_opts.update({"DeltaThetaRange": 0.002}) -if 'qnt20f60' in variant: - if '1000k' in variant: - align_opts.update({"PoorestPopulation": 358.}) - elif '5000k' in variant: - align_opts.update({"PoorestPopulation": 1950.}) +if "qnt20f60" in variant: + if "1000k" in variant: + align_opts.update({"PoorestPopulation": 358.0}) + elif "5000k" in variant: + align_opts.update({"PoorestPopulation": 1950.0}) -if '_phi2' in variant: +if "_phi2" in variant: align_opts.update({"MinUsefulTracks": 2}) # prepare part of the overridden options in use # to be recorded into the YAML file align_opts_dump = alignment_rich_monitoring_options( - radiator='Rich1Gas', init_override_opts=align_opts) + radiator="Rich1Gas", init_override_opts=align_opts +) # prepare override of the default_rich_monitoring_options -default_tight_track_sel = default_rich_monitoring_options( -)["TightTrackSelection"] +default_tight_track_sel = default_rich_monitoring_options()["TightTrackSelection"] default_tight_track_sel["MinP"] = 40.0 * GeV @@ -148,30 +154,31 @@ default_moni_opts = { # add overridden default_rich_monitoring_options # to the part of the options in use to be recorded into the YAML file align_opts_dump.update( - default_rich_monitoring_options(init_override_opts=default_moni_opts)) + default_rich_monitoring_options(init_override_opts=default_moni_opts) +) # retrieve timestamp from variant, not form file, to ensure consistency -ts = re.findall(r'[\d]{4}-[\d]{2}-[\d]{2}T[\d]{2}-[\d]{2}', variant)[0] +ts = re.findall(r"[\d]{4}-[\d]{2}-[\d]{2}T[\d]{2}-[\d]{2}", variant)[0] # prepare options in use to be recorded into the YAML file opts_dump = {} opts_dump[ts] = {} -opts_dump[ts]['reco_opts'] = align_opts_dump +opts_dump[ts]["reco_opts"] = align_opts_dump # append YAML file with the part of the options in use -with open('rich1_reco_opts.yml', 'a') as out: +with open("rich1_reco_opts.yml", "a") as out: yaml.dump(opts_dump, out) # retrieve iteration number substring -with open('rich1_iter_number.yml') as inp: - iN = '_i' + str(yaml.load(inp)) +with open("rich1_iter_number.yml") as inp: + iN = "_i" + str(yaml.load(inp)) # prepare histo_file name if not isQMTest: - if tasks[0] == 'Produce': - options.histo_file = variant + iN + '.root' + if tasks[0] == "Produce": + options.histo_file = variant + iN + ".root" else: - options.histo_file = variant + histo_tasks + iN + '.root' + options.histo_file = variant + histo_tasks + iN + ".root" # by default, no additional filtering of the events event_filter = [] @@ -180,13 +187,13 @@ event_filter = [] line = [] # when particular decision of HLT1 line about RICH1 or RICH2 is wanted -if '_R1_' in variant or '_R2_' in variant or '_R1M_' in variant or '_R2M_' in variant: +if "_R1_" in variant or "_R2_" in variant or "_R1M_" in variant or "_R2M_" in variant: # prepare filter for selecting events # chosen for alignment of mirrors of particular RICH import Functors as F from PyConf.Algorithms import ( - VoidFilter, HltDecReportsDecoder, + VoidFilter, ) from PyConf.application import ( default_raw_banks, @@ -194,25 +201,27 @@ if '_R1_' in variant or '_R2_' in variant or '_R1M_' in variant or '_R2M_' in va ) # in principle, there can be any number and combination of them: - if '_R1_' in variant: - line.append('Hlt1RICH1AlignmentDecision') - if '_R2_' in variant: - line.append('Hlt1RICH2AlignmentDecision') - if '_R1M_' in variant: - line.append('Hlt1RICH1MapAlignDecision') - if '_R2M_' in variant: - line.append('Hlt1RICH2MapAlignDecision') + if "_R1_" in variant: + line.append("Hlt1RICH1AlignmentDecision") + if "_R2_" in variant: + line.append("Hlt1RICH2AlignmentDecision") + if "_R1M_" in variant: + line.append("Hlt1RICH1MapAlignDecision") + if "_R2M_" in variant: + line.append("Hlt1RICH2MapAlignDecision") event_filter = [] with default_raw_event.bind(raw_event_format=0.3): hlt1_dec_reports = HltDecReportsDecoder( - RawBanks=default_raw_banks("HltDecReports"), SourceID='Hlt1') + RawBanks=default_raw_banks("HltDecReports"), SourceID="Hlt1" + ) if UseDD4Hep: hlt1_filter = VoidFilter( - name='Streaming_filter', + name="Streaming_filter", Cut=F.DECREPORTS_FILTER( - Lines=line, - DecReports=hlt1_dec_reports.OutputHltDecReportsLocation)) + Lines=line, DecReports=hlt1_dec_reports.OutputHltDecReportsLocation + ), + ) event_filter = [hlt1_filter] # choose the relevant track_maker @@ -221,24 +230,24 @@ if noUT: else: from RecoConf.hlt2_tracking import make_hlt2_tracks as track_maker -from PyConf.Algorithms import (PrForwardTrackingVelo, PrMatchNN, - PrHybridSeeding) +from PyConf.Algorithms import PrForwardTrackingVelo, PrHybridSeeding, PrMatchNN # Min track momentum for tracking algs min_p = 10 * GeV # finally, run the reconstruction and histogram filling -with PrForwardTrackingVelo.bind(MinP=min_p),\ - PrMatchNN.bind(MinP=min_p),\ - PrHybridSeeding.bind(MinP=min_p),\ - track_maker.bind(use_pr_kf=True, light_reco=True, fast_reco=True),\ - default_rich_reco_options.bind(init_override_opts=default_reco_opts), \ - default_rich_monitoring_options.bind(init_override_opts=default_moni_opts), \ - alignment_rich_monitoring_options.bind(radiator='Rich1Gas', \ - init_override_opts=align_opts): +with ( + PrForwardTrackingVelo.bind(MinP=min_p), + PrMatchNN.bind(MinP=min_p), + PrHybridSeeding.bind(MinP=min_p), + track_maker.bind(use_pr_kf=True, light_reco=True, fast_reco=True), + default_rich_reco_options.bind(init_override_opts=default_reco_opts), + default_rich_monitoring_options.bind(init_override_opts=default_moni_opts), + alignment_rich_monitoring_options.bind( + radiator="Rich1Gas", init_override_opts=align_opts + ), +): reconstruction = standalone_rich_mirror_align_reco( - RichGas='Rich1Gas', - MirrorAlignTasks=tasks, - EventFilter=event_filter, - noUT=noUT) + RichGas="Rich1Gas", MirrorAlignTasks=tasks, EventFilter=event_filter, noUT=noUT + ) config.update(configure(options, reconstruction.node)) diff --git a/Rich/Panoptes/options/rich1_session_timestamp.py b/Rich/Panoptes/options/rich1_session_timestamp.py index ea1f35e96f9744267399992ee00cb773374e7033..87c088068ef56990c84d26223cd22cc32c84aca5 100644 --- a/Rich/Panoptes/options/rich1_session_timestamp.py +++ b/Rich/Panoptes/options/rich1_session_timestamp.py @@ -9,9 +9,11 @@ # or submit itself to any jurisdiction. # ############################################################################### from datetime import datetime + from ruamel.yaml import YAML + yaml = YAML() -dt = datetime.now().isoformat(timespec='minutes') -dt = dt.replace(':', '-') -with open('rich1_session_timestamp.yml', 'w') as fout: +dt = datetime.now().isoformat(timespec="minutes") +dt = dt.replace(":", "-") +with open("rich1_session_timestamp.yml", "w") as fout: yaml.dump(dt, fout) diff --git a/Rich/Panoptes/options/rich1_variant.py b/Rich/Panoptes/options/rich1_variant.py index f8ed8fba3f0b1d7c30e23cc2138669704a1cffbb..35adc96f50362dfa7a04712139994975c73e1a81 100644 --- a/Rich/Panoptes/options/rich1_variant.py +++ b/Rich/Panoptes/options/rich1_variant.py @@ -1,55 +1,57 @@ ############################################################################### # (c) Copyright 2019-2023 CERN for the benefit of the LHCb Collaboration # ############################################################################### -import math, os +import math +import os from ruamel.yaml import ( - YAML, ) + YAML, +) -isQMTTest = 'QMTTEST_NAME' in os.environ +isQMTTest = "QMTTEST_NAME" in os.environ # indiccator of magnet polarity and additionally -- which data # this is optional -mp = 'mu2022data' -#mp = 'md2021mc' +mp = "mu2022data" +# mp = 'md2021mc' if isQMTTest: evt_max = 1000 else: - #evt_max = 1000 + # evt_max = 1000 evt_max = 40000 - #evt_max = 1000000 - #evt_max = 3000000 - #evt_max = 5000000 - -n_kevts = str(math.trunc(evt_max / 1000)) + 'k' - -#addinfo = '' -#addinfo = '_' + mp + n_kevts -#addinfo = '_minp40_' + mp + n_kevts -#addinfo = '_minp40_noUT_' + mp + n_kevts -addinfo = '_minp40_noUT_R1_' + mp + n_kevts -#addinfo = '_minp40_noUT_RM1_' + mp + n_kevts -#addinfo = '_minp40_phi2_' + mp + n_kevts -#addinfo = '_minp40_phi_' + mp + n_kevts -#addinfo = '_minp40_qnt20f60_' + mp + n_kevts -#addinfo = '_minp40_qnt20f60_noUT_' + mp + n_kevts -#addinfo = '_minp40_qnt20f60_noUT_R1_' + mp + n_kevts -#addinfo = '_minp40_qnt20f60_rndmpresc_' + mp + n_kevts -#addinfo = '_minp40_subset' + mp + n_kevts -#addinfo = '_minp40_subset_noUT_' + mp + n_kevts -#addinfo = '_minp40_subset_noUT_R1_' + mp + n_kevts -#addinfo = '_minp40_subset_theta2_' + mp + n_kevts + # evt_max = 1000000 + # evt_max = 3000000 + # evt_max = 5000000 + +n_kevts = str(math.trunc(evt_max / 1000)) + "k" + +# addinfo = '' +# addinfo = '_' + mp + n_kevts +# addinfo = '_minp40_' + mp + n_kevts +# addinfo = '_minp40_noUT_' + mp + n_kevts +addinfo = "_minp40_noUT_R1_" + mp + n_kevts +# addinfo = '_minp40_noUT_RM1_' + mp + n_kevts +# addinfo = '_minp40_phi2_' + mp + n_kevts +# addinfo = '_minp40_phi_' + mp + n_kevts +# addinfo = '_minp40_qnt20f60_' + mp + n_kevts +# addinfo = '_minp40_qnt20f60_noUT_' + mp + n_kevts +# addinfo = '_minp40_qnt20f60_noUT_R1_' + mp + n_kevts +# addinfo = '_minp40_qnt20f60_rndmpresc_' + mp + n_kevts +# addinfo = '_minp40_subset' + mp + n_kevts +# addinfo = '_minp40_subset_noUT_' + mp + n_kevts +# addinfo = '_minp40_subset_noUT_R1_' + mp + n_kevts +# addinfo = '_minp40_subset_theta2_' + mp + n_kevts yaml = YAML() # retrieve the timestamp -with open('rich1_session_timestamp.yml') as inp: +with open("rich1_session_timestamp.yml") as inp: ts = yaml.load(inp) # form the current variant name -variant = ts + '_rich1' + addinfo +variant = ts + "_rich1" + addinfo # record variant and tasks names into the YAML file -with open('rich1_variant.yml', 'w') as out: +with open("rich1_variant.yml", "w") as out: yaml.dump(variant, out) diff --git a/Rich/Panoptes/options/rich2_iter_number.py b/Rich/Panoptes/options/rich2_iter_number.py index e47844e930bac21286cdf1f3560c291b21e2bc95..cdc586cd908c4bc0cabec5b2a6f049ddddf2756e 100644 --- a/Rich/Panoptes/options/rich2_iter_number.py +++ b/Rich/Panoptes/options/rich2_iter_number.py @@ -12,5 +12,5 @@ from ruamel.yaml import YAML yaml = YAML() itNr = 0 -with open('rich2_iter_number.yml', 'w') as fout: +with open("rich2_iter_number.yml", "w") as fout: yaml.dump(itNr, fout) diff --git a/Rich/Panoptes/options/rich2_mirror_align_task.py b/Rich/Panoptes/options/rich2_mirror_align_task.py index a9b47f188b724ed09b19ea1e8a5fc6bed893d48a..4c0fe87893b37a9566ea29b0505236e1c741ce05 100644 --- a/Rich/Panoptes/options/rich2_mirror_align_task.py +++ b/Rich/Panoptes/options/rich2_mirror_align_task.py @@ -9,35 +9,38 @@ # or submit itself to any jurisdiction. # ############################################################################### -import os, multiprocessing, re +import multiprocessing +import os +import re +from DDDB.CheckDD4Hep import UseDD4Hep from GaudiKernel.SystemOfUnits import ( - GeV, ) - + GeV, +) from Moore import ( - options, ) -from PyConf.application import ( - configure_input, - configure, + options, ) from Panoptes.alignment import ( standalone_rich_mirror_align_reco, standalone_rich_online_align_reco, ) +from PyConf.application import ( + configure, + configure_input, +) from RecoConf.rich_data_monitoring import ( - default_rich_monitoring_options, alignment_rich_monitoring_options, + default_rich_monitoring_options, ) from RecoConf.rich_reconstruction import ( - default_rich_reco_options, ) - + default_rich_reco_options, +) from ruamel.yaml import ( - YAML, ) - -from DDDB.CheckDD4Hep import UseDD4Hep + YAML, +) tasks = [ - 'Produce', # # fill the production set of histograms + "Produce", # # fill the production set of histograms #'Monitor', # add various checking histograms #'MapExlore', # explore tracks and photons for the HLT1 pre-selection line "map" #'MapConstruct', # construct exploratory data structure for the HLT1 pre-selection line "map" @@ -53,21 +56,22 @@ tasks = [ # cumulative substring with all tasks chosen # to be included into histo_file name -histo_tasks = '' +histo_tasks = "" for task in tasks: - histo_tasks += '_' + task + histo_tasks += "_" + task -isQMTest = 'QMTTEST_NAME' in os.environ +isQMTest = "QMTTEST_NAME" in os.environ # Override previously set defaults # ROOT file reader currently not thread safe :( -options.n_threads = (1 if options.input_type == 'ROOT' or isQMTest else - multiprocessing.cpu_count()) +options.n_threads = ( + 1 if options.input_type == "ROOT" or isQMTest else multiprocessing.cpu_count() +) yaml = YAML() # retrieve variant -with open('rich2_variant.yml') as inp: +with open("rich2_variant.yml") as inp: variant = yaml.load(inp) if isQMTest: @@ -78,7 +82,7 @@ if isQMTest: else: # retrieve number of events - em = re.findall(r'([\d]+)k', variant)[0] + em = re.findall(r"([\d]+)k", variant)[0] iem = int(em) if iem == 0: options.evt_max = 100 @@ -88,10 +92,13 @@ else: # configure input config = configure_input(options) -thisName = ("rich2_mirror_align_task_noUT" if '_noUT_' in variant else - f"rich2_mirror_align_task{'_detdesc' if not UseDD4Hep else ''}") +thisName = ( + "rich2_mirror_align_task_noUT" + if "_noUT_" in variant + else f"rich2_mirror_align_task{'_detdesc' if not UseDD4Hep else ''}" +) -myName = (os.environ["QMTTEST_NAME"] if isQMTest else thisName) +myName = os.environ["QMTTEST_NAME"] if isQMTest else thisName noUT = "noUT" in myName @@ -101,279 +108,279 @@ align_opts = {} # start updating the dicts: -default_reco_opts.update({"PhotonSelection": 'None'}) +default_reco_opts.update({"PhotonSelection": "None"}) align_opts.update({"Variant": variant}) -if 'subset' in variant: +if "subset" in variant: central_mirr_combs = { "PrebookHistos": [ - ('p08', 's04'), - ('p08', 's08'), - ('p09', 's05'), - ('p09', 's09'), - ('p12', 's08'), - ('p12', 's09'), - ('p13', 's09'), - ('p13', 's10'), - ('p16', 's08'), - ('p16', 's12'), - ('p17', 's09'), - ('p17', 's13'), - ('p38', 's26'), - ('p38', 's30'), - ('p39', 's27'), - ('p39', 's31'), - ('p42', 's29'), - ('p42', 's30'), - ('p43', 's30'), - ('p43', 's31'), - ('p46', 's30'), - ('p46', 's34'), - ('p47', 's31'), - ('p47', 's35'), + ("p08", "s04"), + ("p08", "s08"), + ("p09", "s05"), + ("p09", "s09"), + ("p12", "s08"), + ("p12", "s09"), + ("p13", "s09"), + ("p13", "s10"), + ("p16", "s08"), + ("p16", "s12"), + ("p17", "s09"), + ("p17", "s13"), + ("p38", "s26"), + ("p38", "s30"), + ("p39", "s27"), + ("p39", "s31"), + ("p42", "s29"), + ("p42", "s30"), + ("p43", "s30"), + ("p43", "s31"), + ("p46", "s30"), + ("p46", "s34"), + ("p47", "s31"), + ("p47", "s35"), ], } align_opts.update(central_mirr_combs) -if '_phi' in variant: +if "_phi" in variant: optimal_mirr_combs = { "PrebookHistos": [ - ('p00', 's00'), - ('p01', 's01'), - ('p02', 's02'), - ('p03', 's03'), - ('p04', 's00'), - ('p04', 's01'), - ('p04', 's04'), - ('p05', 's02'), - ('p05', 's05'), - ('p06', 's06'), - ('p07', 's03'), - ('p07', 's07'), - ('p08', 's04'), - ('p08', 's08'), - ('p09', 's05'), - ('p09', 's09'), - ('p10', 's06'), - ('p10', 's10'), - ('p11', 's07'), - ('p11', 's11'), - ('p12', 's08'), - ('p12', 's09'), - ('p13', 's09'), - ('p13', 's10'), - ('p14', 's10'), - ('p14', 's11'), - ('p15', 's11'), - ('p16', 's08'), - ('p16', 's12'), - ('p17', 's09'), - ('p17', 's13'), - ('p18', 's10'), - ('p18', 's14'), - ('p19', 's11'), - ('p19', 's15'), - ('p20', 's12'), - ('p20', 's16'), - ('p21', 's13'), - ('p21', 's17'), - ('p21', 's18'), - ('p22', 's14'), - ('p23', 's15'), - ('p23', 's19'), - ('p24', 's16'), - ('p25', 's17'), - ('p26', 's18'), - ('p27', 's19'), - ('p28', 's20'), - ('p29', 's21'), - ('p30', 's22'), - ('p31', 's23'), - ('p32', 's20'), - ('p32', 's24'), - ('p33', 's25'), - ('p34', 's21'), - ('p34', 's22'), - ('p34', 's26'), - ('p35', 's23'), - ('p35', 's27'), - ('p36', 's24'), - ('p36', 's28'), - ('p37', 's25'), - ('p37', 's29'), - ('p38', 's26'), - ('p38', 's30'), - ('p39', 's27'), - ('p39', 's31'), - ('p40', 's28'), - ('p41', 's28'), - ('p41', 's29'), - ('p42', 's29'), - ('p42', 's30'), - ('p43', 's30'), - ('p43', 's31'), - ('p44', 's28'), - ('p44', 's32'), - ('p45', 's29'), - ('p45', 's33'), - ('p46', 's30'), - ('p46', 's34'), - ('p47', 's31'), - ('p47', 's35'), - ('p48', 's32'), - ('p49', 's33'), - ('p49', 's36'), - ('p50', 's34'), - ('p50', 's37'), - ('p51', 's35'), - ('p51', 's38'), - ('p51', 's39'), - ('p52', 's36'), - ('p53', 's37'), - ('p54', 's38'), - ('p55', 's39'), + ("p00", "s00"), + ("p01", "s01"), + ("p02", "s02"), + ("p03", "s03"), + ("p04", "s00"), + ("p04", "s01"), + ("p04", "s04"), + ("p05", "s02"), + ("p05", "s05"), + ("p06", "s06"), + ("p07", "s03"), + ("p07", "s07"), + ("p08", "s04"), + ("p08", "s08"), + ("p09", "s05"), + ("p09", "s09"), + ("p10", "s06"), + ("p10", "s10"), + ("p11", "s07"), + ("p11", "s11"), + ("p12", "s08"), + ("p12", "s09"), + ("p13", "s09"), + ("p13", "s10"), + ("p14", "s10"), + ("p14", "s11"), + ("p15", "s11"), + ("p16", "s08"), + ("p16", "s12"), + ("p17", "s09"), + ("p17", "s13"), + ("p18", "s10"), + ("p18", "s14"), + ("p19", "s11"), + ("p19", "s15"), + ("p20", "s12"), + ("p20", "s16"), + ("p21", "s13"), + ("p21", "s17"), + ("p21", "s18"), + ("p22", "s14"), + ("p23", "s15"), + ("p23", "s19"), + ("p24", "s16"), + ("p25", "s17"), + ("p26", "s18"), + ("p27", "s19"), + ("p28", "s20"), + ("p29", "s21"), + ("p30", "s22"), + ("p31", "s23"), + ("p32", "s20"), + ("p32", "s24"), + ("p33", "s25"), + ("p34", "s21"), + ("p34", "s22"), + ("p34", "s26"), + ("p35", "s23"), + ("p35", "s27"), + ("p36", "s24"), + ("p36", "s28"), + ("p37", "s25"), + ("p37", "s29"), + ("p38", "s26"), + ("p38", "s30"), + ("p39", "s27"), + ("p39", "s31"), + ("p40", "s28"), + ("p41", "s28"), + ("p41", "s29"), + ("p42", "s29"), + ("p42", "s30"), + ("p43", "s30"), + ("p43", "s31"), + ("p44", "s28"), + ("p44", "s32"), + ("p45", "s29"), + ("p45", "s33"), + ("p46", "s30"), + ("p46", "s34"), + ("p47", "s31"), + ("p47", "s35"), + ("p48", "s32"), + ("p49", "s33"), + ("p49", "s36"), + ("p50", "s34"), + ("p50", "s37"), + ("p51", "s35"), + ("p51", "s38"), + ("p51", "s39"), + ("p52", "s36"), + ("p53", "s37"), + ("p54", "s38"), + ("p55", "s39"), ], } align_opts.update(optimal_mirr_combs) -if 'qnt20f60' in variant: +if "qnt20f60" in variant: optimal_mirr_combs = { "PrebookHistos": [ - ('p00', 's00'), - ('p01', 's01'), - ('p02', 's02'), - ('p03', 's03'), - ('p04', 's00'), - ('p04', 's01'), - ('p04', 's04'), - ('p05', 's02'), - ('p05', 's05'), - ('p06', 's06'), - ('p07', 's03'), - ('p07', 's07'), - ('p08', 's04'), - ('p08', 's08'), - ('p09', 's05'), - ('p09', 's09'), - ('p10', 's06'), - ('p10', 's10'), - ('p11', 's07'), - ('p11', 's11'), - ('p12', 's08'), - ('p12', 's09'), - ('p13', 's09'), - ('p13', 's10'), - ('p14', 's10'), - ('p14', 's11'), - ('p15', 's11'), - ('p16', 's08'), - ('p16', 's12'), - ('p17', 's09'), - ('p17', 's13'), - ('p18', 's10'), - ('p18', 's14'), - ('p19', 's11'), - ('p19', 's15'), - ('p20', 's12'), - ('p20', 's16'), - ('p21', 's13'), - ('p21', 's17'), - ('p21', 's18'), - ('p22', 's14'), - ('p23', 's15'), - ('p23', 's19'), - ('p24', 's16'), - ('p25', 's17'), - ('p26', 's18'), - ('p27', 's19'), - ('p28', 's20'), - ('p29', 's21'), - ('p30', 's22'), - ('p31', 's23'), - ('p32', 's20'), - ('p32', 's24'), - ('p33', 's25'), - ('p34', 's21'), - ('p34', 's22'), - ('p34', 's26'), - ('p35', 's23'), - ('p35', 's27'), - ('p36', 's24'), - ('p36', 's28'), - ('p37', 's25'), - ('p37', 's29'), - ('p38', 's26'), - ('p38', 's30'), - ('p39', 's27'), - ('p39', 's31'), - ('p40', 's28'), - ('p41', 's28'), - ('p41', 's29'), - ('p42', 's29'), - ('p42', 's30'), - ('p43', 's30'), - ('p43', 's31'), - ('p44', 's28'), - ('p44', 's32'), - ('p45', 's29'), - ('p45', 's33'), - ('p46', 's30'), - ('p46', 's34'), - ('p47', 's31'), - ('p47', 's35'), - ('p48', 's32'), - ('p49', 's33'), - ('p49', 's36'), - ('p50', 's34'), - ('p50', 's37'), - ('p51', 's35'), - ('p51', 's38'), - ('p51', 's39'), - ('p52', 's36'), - ('p53', 's37'), - ('p54', 's38'), - ('p55', 's39'), + ("p00", "s00"), + ("p01", "s01"), + ("p02", "s02"), + ("p03", "s03"), + ("p04", "s00"), + ("p04", "s01"), + ("p04", "s04"), + ("p05", "s02"), + ("p05", "s05"), + ("p06", "s06"), + ("p07", "s03"), + ("p07", "s07"), + ("p08", "s04"), + ("p08", "s08"), + ("p09", "s05"), + ("p09", "s09"), + ("p10", "s06"), + ("p10", "s10"), + ("p11", "s07"), + ("p11", "s11"), + ("p12", "s08"), + ("p12", "s09"), + ("p13", "s09"), + ("p13", "s10"), + ("p14", "s10"), + ("p14", "s11"), + ("p15", "s11"), + ("p16", "s08"), + ("p16", "s12"), + ("p17", "s09"), + ("p17", "s13"), + ("p18", "s10"), + ("p18", "s14"), + ("p19", "s11"), + ("p19", "s15"), + ("p20", "s12"), + ("p20", "s16"), + ("p21", "s13"), + ("p21", "s17"), + ("p21", "s18"), + ("p22", "s14"), + ("p23", "s15"), + ("p23", "s19"), + ("p24", "s16"), + ("p25", "s17"), + ("p26", "s18"), + ("p27", "s19"), + ("p28", "s20"), + ("p29", "s21"), + ("p30", "s22"), + ("p31", "s23"), + ("p32", "s20"), + ("p32", "s24"), + ("p33", "s25"), + ("p34", "s21"), + ("p34", "s22"), + ("p34", "s26"), + ("p35", "s23"), + ("p35", "s27"), + ("p36", "s24"), + ("p36", "s28"), + ("p37", "s25"), + ("p37", "s29"), + ("p38", "s26"), + ("p38", "s30"), + ("p39", "s27"), + ("p39", "s31"), + ("p40", "s28"), + ("p41", "s28"), + ("p41", "s29"), + ("p42", "s29"), + ("p42", "s30"), + ("p43", "s30"), + ("p43", "s31"), + ("p44", "s28"), + ("p44", "s32"), + ("p45", "s29"), + ("p45", "s33"), + ("p46", "s30"), + ("p46", "s34"), + ("p47", "s31"), + ("p47", "s35"), + ("p48", "s32"), + ("p49", "s33"), + ("p49", "s36"), + ("p50", "s34"), + ("p50", "s37"), + ("p51", "s35"), + ("p51", "s38"), + ("p51", "s39"), + ("p52", "s36"), + ("p53", "s37"), + ("p54", "s38"), + ("p55", "s39"), ], } align_opts.update(optimal_mirr_combs) -if 'minp60' in variant: - align_opts.update({"MinP4Align": 60. * GeV}) +if "minp60" in variant: + align_opts.update({"MinP4Align": 60.0 * GeV}) -if 'theta2' in variant: +if "theta2" in variant: align_opts.update({"DeltaThetaRange": 0.002}) -if not '_phi' in variant: - if '40k' in variant: - align_opts.update({"PoorestPopulation": 10.}) - elif '1000k' in variant: - align_opts.update({"PoorestPopulation": 341.}) - elif '5000k' in variant: - align_opts.update({"PoorestPopulation": 2688.}) - -if '_phi' in variant: - if '40k' in variant: - align_opts.update({"PoorestPopulation": 1.}) - elif '1000k' in variant: - align_opts.update({"PoorestPopulation": 20.}) - elif '5000k' in variant: - align_opts.update({"PoorestPopulation": 113.}) - -if 'qnt20f60' in variant: - if '5000k' in variant: - align_opts.update({"PoorestPopulation": 310.}) - -if '_phi2' in variant: +if not "_phi" in variant: + if "40k" in variant: + align_opts.update({"PoorestPopulation": 10.0}) + elif "1000k" in variant: + align_opts.update({"PoorestPopulation": 341.0}) + elif "5000k" in variant: + align_opts.update({"PoorestPopulation": 2688.0}) + +if "_phi" in variant: + if "40k" in variant: + align_opts.update({"PoorestPopulation": 1.0}) + elif "1000k" in variant: + align_opts.update({"PoorestPopulation": 20.0}) + elif "5000k" in variant: + align_opts.update({"PoorestPopulation": 113.0}) + +if "qnt20f60" in variant: + if "5000k" in variant: + align_opts.update({"PoorestPopulation": 310.0}) + +if "_phi2" in variant: align_opts.update({"MinUsefulTracks": 2}) # prepare part of the overridden options in use # to be recorded into the YAML file align_opts_dump = alignment_rich_monitoring_options( - radiator='Rich2Gas', init_override_opts=align_opts) + radiator="Rich2Gas", init_override_opts=align_opts +) # prepare override of the default_rich_monitoring_options -default_tight_track_sel = default_rich_monitoring_options( -)["TightTrackSelection"] +default_tight_track_sel = default_rich_monitoring_options()["TightTrackSelection"] default_tight_track_sel["MinP"] = 60.0 * GeV @@ -385,30 +392,31 @@ default_moni_opts = { # add overridden default_rich_monitoring_options # to the part of the options in use to be recorded into the YAML file align_opts_dump.update( - default_rich_monitoring_options(init_override_opts=default_moni_opts)) + default_rich_monitoring_options(init_override_opts=default_moni_opts) +) # retrieve the timestamp -ts = re.findall(r'[\d]{4}-[\d]{2}-[\d]{2}T[\d]{2}-[\d]{2}', variant)[0] +ts = re.findall(r"[\d]{4}-[\d]{2}-[\d]{2}T[\d]{2}-[\d]{2}", variant)[0] # prepare options in use to be recorded into the YAML file opts_dump = {} opts_dump[ts] = {} -opts_dump[ts]['reco_opts'] = align_opts_dump +opts_dump[ts]["reco_opts"] = align_opts_dump # append YAML file with the part of the options in use -with open('rich2_reco_opts.yml', 'a') as out: +with open("rich2_reco_opts.yml", "a") as out: yaml.dump(opts_dump, out) # retrieve iteration number substring -with open('rich2_iter_number.yml') as inp: - iN = '_i' + str(yaml.load(inp)) +with open("rich2_iter_number.yml") as inp: + iN = "_i" + str(yaml.load(inp)) # prepare histo_file name if not isQMTest: - if tasks[0] == 'Produce': - options.histo_file = variant + iN + '.root' + if tasks[0] == "Produce": + options.histo_file = variant + iN + ".root" else: - options.histo_file = variant + histo_tasks + iN + '.root' + options.histo_file = variant + histo_tasks + iN + ".root" # by default, no additional filtering of the events event_filter = [] @@ -417,13 +425,13 @@ event_filter = [] line = [] # when particular decision of HLT1 line about RICH1 or RICH2 is wanted -if '_R1_' in variant or '_R2_' in variant or '_R1M_' in variant or '_R2M_' in variant: +if "_R1_" in variant or "_R2_" in variant or "_R1M_" in variant or "_R2M_" in variant: # prepare filter for selecting events # chosen for alignment of mirrors of particular RICH import Functors as F from PyConf.Algorithms import ( - VoidFilter, HltDecReportsDecoder, + VoidFilter, ) from PyConf.application import ( default_raw_banks, @@ -431,25 +439,26 @@ if '_R1_' in variant or '_R2_' in variant or '_R1M_' in variant or '_R2M_' in va ) # in principle, there can be any number and combination of them: - if '_R1_' in variant: - line.append('Hlt1RICH1AlignmentDecision') - if '_R2_' in variant: - line.append('Hlt1RICH2AlignmentDecision') - if '_R1M_' in variant: - line.append('Hlt1RICH1MapAlignDecision') - if '_R2M_' in variant: - line.append('Hlt1RICH2MapAlignDecision') + if "_R1_" in variant: + line.append("Hlt1RICH1AlignmentDecision") + if "_R2_" in variant: + line.append("Hlt1RICH2AlignmentDecision") + if "_R1M_" in variant: + line.append("Hlt1RICH1MapAlignDecision") + if "_R2M_" in variant: + line.append("Hlt1RICH2MapAlignDecision") with default_raw_event.bind(raw_event_format=0.3): - hlt1_dec_reports = HltDecReportsDecoder( - RawBanks=default_raw_banks("HltDecReports"), SourceID='Hlt1') + RawBanks=default_raw_banks("HltDecReports"), SourceID="Hlt1" + ) hlt1_filter = VoidFilter( - name='Streaming_filter', + name="Streaming_filter", Cut=F.DECREPORTS_FILTER( - Lines=line, - DecReports=hlt1_dec_reports.OutputHltDecReportsLocation)) + Lines=line, DecReports=hlt1_dec_reports.OutputHltDecReportsLocation + ), + ) """ print(hlt1_filter) print(type(hlt1_filter)) @@ -462,24 +471,24 @@ if noUT: else: from RecoConf.hlt2_tracking import make_hlt2_tracks as track_maker -from PyConf.Algorithms import (PrForwardTrackingVelo, PrMatchNN, - PrHybridSeeding) +from PyConf.Algorithms import PrForwardTrackingVelo, PrHybridSeeding, PrMatchNN # Min track momentum for tracking algs min_p = 10 * GeV # finally, run the reconstruction and histogram filling -with PrForwardTrackingVelo.bind(MinP=min_p),\ - PrMatchNN.bind(MinP=min_p),\ - PrHybridSeeding.bind(MinP=min_p),\ - track_maker.bind(use_pr_kf=True, light_reco=True, fast_reco=True),\ - default_rich_reco_options.bind(init_override_opts=default_reco_opts), \ - default_rich_monitoring_options.bind(init_override_opts=default_moni_opts), \ - alignment_rich_monitoring_options.bind(radiator='Rich2Gas', \ - init_override_opts=align_opts): +with ( + PrForwardTrackingVelo.bind(MinP=min_p), + PrMatchNN.bind(MinP=min_p), + PrHybridSeeding.bind(MinP=min_p), + track_maker.bind(use_pr_kf=True, light_reco=True, fast_reco=True), + default_rich_reco_options.bind(init_override_opts=default_reco_opts), + default_rich_monitoring_options.bind(init_override_opts=default_moni_opts), + alignment_rich_monitoring_options.bind( + radiator="Rich2Gas", init_override_opts=align_opts + ), +): reconstruction = standalone_rich_mirror_align_reco( - RichGas='Rich2Gas', - MirrorAlignTasks=tasks, - EventFilter=event_filter, - noUT=noUT) + RichGas="Rich2Gas", MirrorAlignTasks=tasks, EventFilter=event_filter, noUT=noUT + ) config.update(configure(options, reconstruction.node)) diff --git a/Rich/Panoptes/options/rich2_session_timestamp.py b/Rich/Panoptes/options/rich2_session_timestamp.py index 74367d69eda83610d5406d980c99be4303c8fcf3..4baa4dddcda487f1c4d92e92959c998bf31fa86e 100644 --- a/Rich/Panoptes/options/rich2_session_timestamp.py +++ b/Rich/Panoptes/options/rich2_session_timestamp.py @@ -9,9 +9,11 @@ # or submit itself to any jurisdiction. # ############################################################################### from datetime import datetime + from ruamel.yaml import YAML + yaml = YAML() -dt = datetime.now().isoformat(timespec='minutes') -dt = dt.replace(':', '-') -with open('rich2_session_timestamp.yml', 'w') as fout: +dt = datetime.now().isoformat(timespec="minutes") +dt = dt.replace(":", "-") +with open("rich2_session_timestamp.yml", "w") as fout: yaml.dump(dt, fout) diff --git a/Rich/Panoptes/options/rich2_variant.py b/Rich/Panoptes/options/rich2_variant.py index 5b497caa4d583e7b51076c044be58df1e299c7d9..b024b0cf49eeac4e54d94821834f04d8eae0cf27 100644 --- a/Rich/Panoptes/options/rich2_variant.py +++ b/Rich/Panoptes/options/rich2_variant.py @@ -1,55 +1,57 @@ ############################################################################### # (c) Copyright 2019-2023 CERN for the benefit of the LHCb Collaboration # ############################################################################### -import math, os +import math +import os from ruamel.yaml import ( - YAML, ) + YAML, +) -isQMTTest = 'QMTTEST_NAME' in os.environ +isQMTTest = "QMTTEST_NAME" in os.environ # indiccator of magnet polarity and additionally -- which data # this is optional -mp = 'mu2022data' -#mp = 'md2021mc' +mp = "mu2022data" +# mp = 'md2021mc' if isQMTTest: evt_max = 1000 else: - #evt_max = 1000 + # evt_max = 1000 evt_max = 40000 - #evt_max = 1000000 - #evt_max = 3000000 - #evt_max = 5000000 - -n_kevts = str(math.trunc(evt_max / 1000)) + 'k' - -#addinfo = '' -#addinfo = '_' + mp + n_kevts -#addinfo = '_minp60_' + mp + n_kevts -#addinfo = '_minp60_noUT_' + mp + n_kevts -addinfo = '_minp60_noUT_R2_' + mp + n_kevts -#addinfo = '_minp60_noUT_RM2_' + mp + n_kevts -#addinfo = '_minp60_phi2_' + mp + n_kevts -#addinfo = '_minp60_phi_' + mp + n_kevts -#addinfo = '_minp60_qnt20f60_' + mp + n_kevts -#addinfo = '_minp60_qnt20f60_noUT_' + mp + n_kevts -#addinfo = '_minp60_qnt20f60_noUT_R2_' + mp + n_kevts -#addinfo = '_minp60_qnt20f60_rndmpresc_' + mp + n_kevts -#addinfo = '_minp60_subset' + mp + n_kevts -#addinfo = '_minp60_subset_noUT_' + mp + n_kevts -#addinfo = '_minp60_subset_noUT_R2_' + mp + n_kevts -#addinfo = '_minp60_subset_theta2_' + mp + n_kevts + # evt_max = 1000000 + # evt_max = 3000000 + # evt_max = 5000000 + +n_kevts = str(math.trunc(evt_max / 1000)) + "k" + +# addinfo = '' +# addinfo = '_' + mp + n_kevts +# addinfo = '_minp60_' + mp + n_kevts +# addinfo = '_minp60_noUT_' + mp + n_kevts +addinfo = "_minp60_noUT_R2_" + mp + n_kevts +# addinfo = '_minp60_noUT_RM2_' + mp + n_kevts +# addinfo = '_minp60_phi2_' + mp + n_kevts +# addinfo = '_minp60_phi_' + mp + n_kevts +# addinfo = '_minp60_qnt20f60_' + mp + n_kevts +# addinfo = '_minp60_qnt20f60_noUT_' + mp + n_kevts +# addinfo = '_minp60_qnt20f60_noUT_R2_' + mp + n_kevts +# addinfo = '_minp60_qnt20f60_rndmpresc_' + mp + n_kevts +# addinfo = '_minp60_subset' + mp + n_kevts +# addinfo = '_minp60_subset_noUT_' + mp + n_kevts +# addinfo = '_minp60_subset_noUT_R2_' + mp + n_kevts +# addinfo = '_minp60_subset_theta2_' + mp + n_kevts yaml = YAML() # retrieve the timestamp -with open('rich2_session_timestamp.yml') as inp: +with open("rich2_session_timestamp.yml") as inp: ts = yaml.load(inp) # form the current variant name -variant = ts + '_rich2' + addinfo +variant = ts + "_rich2" + addinfo # record variant and tasks names into the YAML file -with open('rich2_variant.yml', 'w') as out: +with open("rich2_variant.yml", "w") as out: yaml.dump(variant, out) diff --git a/Rich/Panoptes/python/Panoptes/BrahmaSutraConfiguration.py b/Rich/Panoptes/python/Panoptes/BrahmaSutraConfiguration.py index 3644027abfc7cfd0e3fbf877dc857bbdfbc1c93d..387a01b9518a37d22a174214f9ca2006e04af366 100644 --- a/Rich/Panoptes/python/Panoptes/BrahmaSutraConfiguration.py +++ b/Rich/Panoptes/python/Panoptes/BrahmaSutraConfiguration.py @@ -8,50 +8,49 @@ # granted to it by virtue of its status as an Intergovernmental Organization # # or submit itself to any jurisdiction. # ############################################################################### +from DDDB.CheckDD4Hep import UseDD4Hep from GaudiKernel.SystemOfUnits import GeV - -from PyConf.tonic import configurable -from PyConf.application import make_odin +from Moore.config import Reconstruction +from MooreOnlineConf.utils import update_and_reset from PyConf import configurable - +from PyConf.Algorithms import ( + Rich__Future__MC__TrackToMCParticleRelations as TkToMCPRels, +) +from PyConf.Algorithms import ( + Rich__Future__Rec__MC__Moni__RichPIDTupleCreatorAlg as RichPIDTuple, +) +from PyConf.Algorithms import TracksToSelection +from PyConf.application import make_odin +from PyConf.tonic import configurable +from PyConf.Tools import TrackSelector from RecoConf.data_from_file import mc_unpacker - from RecoConf.mc_checking import ( make_links_lhcbids_mcparticles_tracking_system, - make_links_tracks_mcparticles, make_links_lhcbids_mcparticles_VP_FT) - -from RecoConf.rich_reconstruction import ( - default_rich_reco_options, make_rich_pids, get_detector_bool_opts) -from RecoConf.standalone import reco_prefilters + make_links_lhcbids_mcparticles_VP_FT, + make_links_tracks_mcparticles, +) from RecoConf.rich_data_monitoring import ( default_rich_monitoring_options, make_rich_pixel_monitors, make_rich_track_monitors, ) - from RecoConf.rich_mc_checking import ( - default_rich_checking_options, make_rich_checkers, default_rich_checkers) - -from PyConf.Algorithms import ( - TracksToSelection, Rich__Future__MC__TrackToMCParticleRelations as - TkToMCPRels, Rich__Future__Rec__MC__Moni__RichPIDTupleCreatorAlg as - RichPIDTuple) - -from PyConf.Tools import TrackSelector - -from Moore.config import Reconstruction -from MooreOnlineConf.utils import update_and_reset - -from DDDB.CheckDD4Hep import UseDD4Hep - -from GaudiKernel.SystemOfUnits import GeV + default_rich_checkers, + default_rich_checking_options, + make_rich_checkers, +) +from RecoConf.rich_reconstruction import ( + default_rich_reco_options, + get_detector_bool_opts, + make_rich_pids, +) +from RecoConf.standalone import reco_prefilters @configurable -def BrahmaSutraConf(offlineMode=True, - noUT=False, - do_data_monitoring=True, - ParticleGun=False): +def BrahmaSutraConf( + offlineMode=True, noUT=False, do_data_monitoring=True, ParticleGun=False +): """ The tracking and RICH reco for the RICH reconstruction from MC data """ @@ -59,16 +58,17 @@ def BrahmaSutraConf(offlineMode=True, if not noUT: print("Configuring tracking with UT") from RecoConf.hlt2_tracking import make_hlt2_tracks + hlt2_tracks = make_hlt2_tracks() else: print("Configuring tracking without UT") from RecoConf.hlt2_tracking import make_hlt2_tracks_without_UT - hlt2_tracks = make_hlt2_tracks_without_UT() - #print("BrahmaSutraConf: Available Track Types", hlt2_tracks.keys()) + hlt2_tracks = make_hlt2_tracks_without_UT() + # print("BrahmaSutraConf: Available Track Types", hlt2_tracks.keys()) -# The track type we use + # The track type we use track_version = "v1" tkType = "Long" @@ -76,13 +76,13 @@ def BrahmaSutraConf(offlineMode=True, # Get the fitted long tracks to use # In ParticleGun events only 'Best' tracks available. - if (not ParticleGun): + if not ParticleGun: tks = hlt2_tracks["Best" + tkType] else: tks = hlt2_tracks["Best"] # CK Theta res range to use - #CKResHistoRange = (0.0250, 0.0055, 0.0035) + # CKResHistoRange = (0.0250, 0.0055, 0.0035) CKResHistoRange = (0.0055, 0.0035) # Default RICH reco options @@ -95,12 +95,11 @@ def BrahmaSutraConf(offlineMode=True, # RICH photon reco conf = make_rich_pids( - track_name=tkType, - input_tracks=tkSel.OutputLocation, - options=reco_opts) + track_name=tkType, input_tracks=tkSel.OutputLocation, options=reco_opts + ) # The detector and radiator options. Not used for now. - #rad_opts = get_radiator_bool_opts(reco_opts, tkType) + # rad_opts = get_radiator_bool_opts(reco_opts, tkType) det_opts = get_detector_bool_opts(reco_opts, tkType) algs_to_run = [] @@ -128,7 +127,8 @@ def BrahmaSutraConf(offlineMode=True, reco_opts=reco_opts, moni_opts=moni_opts, moni_set=moni_set, - )) + ) + ) algs_to_run += [v for _, v in sorted(moni_algs.items())] check_opts = default_rich_checking_options() @@ -138,24 +138,19 @@ def BrahmaSutraConf(offlineMode=True, conf["OriginalV1Tracks"] = tks[track_version] check_algs = make_rich_checkers( - conf=conf, - reco_opts=reco_opts, - check_opts=check_opts, - moni_set=moni_set) + conf=conf, reco_opts=reco_opts, check_opts=check_opts, moni_set=moni_set + ) algs_to_run += [v for _, v in sorted(check_algs.items())] - if (not ParticleGun): + if not ParticleGun: make_pid_tuple = make_rich_PID_Ntuple( - conf=conf, - reco_opts=reco_opts, - check_opts=check_opts, - moni_set=moni_set) + conf=conf, reco_opts=reco_opts, check_opts=check_opts, moni_set=moni_set + ) algs_to_run += [v for _, v in sorted(make_pid_tuple.items())] - return Reconstruction('rich_MC_reconstruction', algs_to_run, - reco_prefilters()) + return Reconstruction("rich_MC_reconstruction", algs_to_run, reco_prefilters()) @configurable @@ -184,7 +179,7 @@ def make_rich_PID_Ntuple(conf, reco_opts, check_opts, moni_set="Standard"): # The detector and radiator options det_opts = get_detector_bool_opts(reco_opts, track_name) - #rad_opts = get_radiator_bool_opts(reco_opts, track_name) + # rad_opts = get_radiator_bool_opts(reco_opts, track_name) # get the list of checkers to activate checkers = default_rich_checkers(moni_set) @@ -200,32 +195,34 @@ def make_rich_PID_Ntuple(conf, reco_opts, check_opts, moni_set="Standard"): links_to_lhcbids = make_links_lhcbids_mcparticles_VP_FT() links_to_tracks = make_links_tracks_mcparticles( - InputTracks=conf["OriginalV1Tracks"], LinksToLHCbIDs=links_to_lhcbids) + InputTracks=conf["OriginalV1Tracks"], LinksToLHCbIDs=links_to_lhcbids + ) # Make the RICH Track -> MCParticle relations table tkMCPRels = TkToMCPRels( - name='RichTkToMCPRelations_{hash}', + name="RichTkToMCPRelations_{hash}", TracksLocation=conf["OriginalV1Tracks"], MCParticlesLinkLocation=links_to_tracks, - MCParticlesLocation=mcps) + MCParticlesLocation=mcps, + ) # Momentum cuts for plotting etc (by radiator) - #pCuts = { + # pCuts = { # "MinP": (0.5 * GeV, 0.5 * GeV, 0.5 * GeV), # "MaxP": (120.0 * GeV, 120.0 * GeV, 120.0 * GeV) - #} + # } pCutsPID = [2.0 * GeV, 100 * GeV] # PID performance key = "PIDPerformance" if key in checkers: - #print ("BrahmaSutra: Activating PID Ntuple Creation") + # print ("BrahmaSutra: Activating PID Ntuple Creation") # Make a PID monitor for this selection results[key] = RichPIDTuple( name="RichPIDTupleCreatorAlg", - TrackSelector=TrackSelector( - MinPCut=pCutsPID[0], MaxPCut=pCutsPID[1]), + TrackSelector=TrackSelector(MinPCut=pCutsPID[0], MaxPCut=pCutsPID[1]), TracksLocation=conf["InputTracks"], RichPIDsLocation=conf["RichPIDs"], - TrackToMCParticlesRelations=tkMCPRels.TrackToMCParticlesRelations) + TrackToMCParticlesRelations=tkMCPRels.TrackToMCParticlesRelations, + ) return results diff --git a/Rich/Panoptes/python/Panoptes/alignment.py b/Rich/Panoptes/python/Panoptes/alignment.py index fb216cd512535cb6629054d5f5051b2a55308941..4426807a4ffd7a4cd54de6794369712cebaef4bd 100644 --- a/Rich/Panoptes/python/Panoptes/alignment.py +++ b/Rich/Panoptes/python/Panoptes/alignment.py @@ -8,22 +8,30 @@ # granted to it by virtue of its status as an Intergovernmental Organization # # or submit itself to any jurisdiction. # ############################################################################### -from RecoConf.config import ( - Reconstruction, ) +import getpass +import os -from PyConf.application import ( - make_odin, ) from PyConf.Algorithms import ( - TracksToSelection, Rich__Future__Rec__Moni__SIMDAlignment as MirrorAlign, - Rich__Future__Rec__Moni__SIMDPhotonCherenkovAngles as - PanelAlignAndMonitoring, +) +from PyConf.Algorithms import ( + Rich__Future__Rec__Moni__SIMDPhotonCherenkovAngles as PanelAlignAndMonitoring, +) +from PyConf.Algorithms import ( + TracksToSelection, +) +from PyConf.application import ( + make_odin, ) from PyConf.tonic import ( - configurable, ) + configurable, +) from PyConf.Tools import ( - TrackSelector, ) - + TrackSelector, +) +from RecoConf.config import ( + Reconstruction, +) from RecoConf.hlt2_tracking import ( make_hlt2_tracks, make_hlt2_tracks_without_UT, @@ -38,19 +46,18 @@ from RecoConf.rich_reconstruction import ( make_rich_pids, ) from RecoConf.standalone import ( - reco_prefilters, ) -import getpass -import os + reco_prefilters, +) # Configurable that produces `Alignment` histograms ONLY # This is for the Mirror Alignment monitor's offline tests (e.g. CI tests) @configurable def standalone_rich_mirror_align_reco( - RichGas="Rich1Gas", - MirrorAlignTasks=['Produce'], - EventFilter=[], - noUT=False, + RichGas="Rich1Gas", + MirrorAlignTasks=["Produce"], + EventFilter=[], + noUT=False, ): """ Reconstruction for RICH mirror alignment @@ -58,8 +65,7 @@ def standalone_rich_mirror_align_reco( # Make the tracks if not noUT: - hlt2_tracks = make_hlt2_tracks( - light_reco=True, fast_reco=False, use_pr_kf=True) + hlt2_tracks = make_hlt2_tracks(light_reco=True, fast_reco=False, use_pr_kf=True) else: hlt2_tracks = make_hlt2_tracks_without_UT() @@ -83,16 +89,15 @@ def standalone_rich_mirror_align_reco( reco_opts["SaveMirrorData"] = True # As we aren't running PID, we do not need all hypos - #reco_opts["Particles"] = ["muon","pion","kaon"] + # reco_opts["Particles"] = ["muon","pion","kaon"] # Track selection tkSel = TracksToSelection(InputLocation=tks[track_version]) # RICH photon reco conf = make_rich_pids( - track_name=tkType, - input_tracks=tkSel.OutputLocation, - options=reco_opts) + track_name=tkType, input_tracks=tkSel.OutputLocation, options=reco_opts + ) # The detector options det_opts = get_detector_bool_opts(reco_opts, tkType) @@ -121,29 +126,30 @@ def standalone_rich_mirror_align_reco( NPhiBins=moni_opts["NPhiBins"], NThetaBins=moni_opts["NThetaBins"], HistoOutputLevel=moni_opts["HistoOutputLevel"], - MirrorAlignTasks=MirrorAlignTasks,\ + MirrorAlignTasks=MirrorAlignTasks, PoorestPopulation=moni_opts["PoorestPopulation"], MinUsefulTracks=moni_opts["MinUsefulTracks"], Variant=moni_opts["Variant"], ) - rich = ('rich1' if RichGas == "Rich1Gas" else 'rich2') + rich = "rich1" if RichGas == "Rich1Gas" else "rich2" # additional prefilter can be added, # e.g. for selecting events with certain HLT1 line decision prefilters = EventFilter + reco_prefilters() - return Reconstruction(rich + '_mirror_align_reco', - [make_odin().producer, alignMon], prefilters) + return Reconstruction( + rich + "_mirror_align_reco", [make_odin().producer, alignMon], prefilters + ) # Configurable that produces `PhotonCherenkovAngles` histograms ONLY # This is for the Panel Alignment (offline/online tests) @configurable def standalone_rich_panel_align_reco( - RichGas="Rich1Gas", - EventFilter=[], - noUT=False, + RichGas="Rich1Gas", + EventFilter=[], + noUT=False, ): """ Reconstruction for RICH panel alignment @@ -151,15 +157,17 @@ def standalone_rich_panel_align_reco( # Make the tracks if not noUT: - #hlt2_tracks = make_hlt2_tracks() + # hlt2_tracks = make_hlt2_tracks() # match Hlt/RecoConf/python/RecoConf/standalone.py in Moore hlt2_tracks = make_hlt2_tracks( - light_reco=True, fast_reco=False, use_pr_kf=False) + light_reco=True, fast_reco=False, use_pr_kf=False + ) else: - #hlt2_tracks = make_hlt2_tracks_without_UT() + # hlt2_tracks = make_hlt2_tracks_without_UT() # match Hlt/RecoConf/python/RecoConf/standalone.py in Moore hlt2_tracks = make_hlt2_tracks_without_UT( - light_reco=True, fast_reco=False, use_pr_kf=True) + light_reco=True, fast_reco=False, use_pr_kf=True + ) # The track type we use track_version = "v1" @@ -178,16 +186,15 @@ def standalone_rich_panel_align_reco( reco_opts["PhotonSelection"] = "None" # As we aren't running PID, we do not need all hypos - #reco_opts["Particles"] = ["muon","pion","kaon"] + # reco_opts["Particles"] = ["muon","pion","kaon"] # Track selection tkSel = TracksToSelection(InputLocation=tks[track_version]) # RICH photon reco conf = make_rich_pids( - track_name=tkType, - input_tracks=tkSel.OutputLocation, - options=reco_opts) + track_name=tkType, input_tracks=tkSel.OutputLocation, options=reco_opts + ) # The detector options det_opts = get_detector_bool_opts(reco_opts, tkType) @@ -198,14 +205,15 @@ def standalone_rich_panel_align_reco( # panel alignment histograms tight_sel = moni_opts["TightTrackSelection"] ckMon = PanelAlignAndMonitoring( - #name="RiCKRes" + tkType + "Tight", + # name="RiCKRes" + tkType + "Tight", name="RiCKRes" + conf["TrackName"] + "Tight", Detectors=det_opts, TrackSelector=TrackSelector( MinPCut=tight_sel["MinP"], MinPtCut=tight_sel["MinPt"], MaxChi2Cut=tight_sel["MaxChi2"], - MaxGhostProbCut=tight_sel["MaxGhostProb"]), + MaxGhostProbCut=tight_sel["MaxGhostProb"], + ), CKResHistoRange=moni_opts["CKResHistoRange"], TracksLocation=conf["InputTracks"], TrackSegmentsLocation=conf["TrackSegments"], @@ -215,24 +223,25 @@ def standalone_rich_panel_align_reco( PhotonToParentsLocation=conf["PhotonToParents"], ) - rich = ('rich1' if RichGas == "Rich1Gas" else 'rich2') + rich = "rich1" if RichGas == "Rich1Gas" else "rich2" # additional prefilter can be added, # e.g. for selecting events with certain HLT1 line decision prefilters = EventFilter + reco_prefilters() - return Reconstruction(rich + '_panel_align_reco', - [make_odin().producer, ckMon], prefilters) + return Reconstruction( + rich + "_panel_align_reco", [make_odin().producer, ckMon], prefilters + ) # Configurable that produces BOTH `Alignment` and `PhotonCherenkovAngles` # This is for ONLINE monitoring (a.k.a. Real-time Alignment) @configurable def standalone_rich_online_align_reco( - RichGas="Rich1Gas", - MirrorAlignTasks=['Produce'], - EventFilter=[], - noUT=False, + RichGas="Rich1Gas", + MirrorAlignTasks=["Produce"], + EventFilter=[], + noUT=False, ): """ Reconstruction for RICH mirror alignment & CK angle monitoring @@ -240,8 +249,7 @@ def standalone_rich_online_align_reco( # Make the tracks - should be the same as from standalone_rich_mirror_align_reco if not noUT: - hlt2_tracks = make_hlt2_tracks( - light_reco=True, fast_reco=False, use_pr_kf=True) + hlt2_tracks = make_hlt2_tracks(light_reco=True, fast_reco=False, use_pr_kf=True) else: hlt2_tracks = make_hlt2_tracks_without_UT() @@ -265,16 +273,15 @@ def standalone_rich_online_align_reco( reco_opts["SaveMirrorData"] = True # As we aren't running PID, we do not need all hypos - #reco_opts["Particles"] = ["muon","pion","kaon"] + # reco_opts["Particles"] = ["muon","pion","kaon"] # Track selection tkSel = TracksToSelection(InputLocation=tks[track_version]) # RICH photon reco conf = make_rich_pids( - track_name=tkType, - input_tracks=tkSel.OutputLocation, - options=reco_opts) + track_name=tkType, input_tracks=tkSel.OutputLocation, options=reco_opts + ) # The detector options det_opts = get_detector_bool_opts(reco_opts, tkType) @@ -311,14 +318,15 @@ def standalone_rich_online_align_reco( # CK res histograms for alignment monitoring tight_sel = moni_opts["TightTrackSelection"] ckMon = PanelAlignAndMonitoring( - #name="RiCKRes" + tkType + "Tight", + # name="RiCKRes" + tkType + "Tight", name="RiCKRes" + conf["TrackName"] + "Tight", Detectors=det_opts, TrackSelector=TrackSelector( MinPCut=tight_sel["MinP"], MinPtCut=tight_sel["MinPt"], MaxChi2Cut=tight_sel["MaxChi2"], - MaxGhostProbCut=tight_sel["MaxGhostProb"]), + MaxGhostProbCut=tight_sel["MaxGhostProb"], + ), CKResHistoRange=moni_opts["CKResHistoRange"], TracksLocation=conf["InputTracks"], TrackSegmentsLocation=conf["TrackSegments"], @@ -328,14 +336,15 @@ def standalone_rich_online_align_reco( PhotonToParentsLocation=conf["PhotonToParents"], ) - rich = ('rich1' if RichGas == "Rich1Gas" else 'rich2') + rich = "rich1" if RichGas == "Rich1Gas" else "rich2" # additional prefilter can be added, # e.g. for selecting events with certain HLT1 line decision prefilters = EventFilter + reco_prefilters() return Reconstruction( - rich + '_online_align_reco', + rich + "_online_align_reco", [make_odin().producer, alignMon, ckMon], - #[make_odin().producer, alignMon, ckMon, rtuple], - prefilters) + # [make_odin().producer, alignMon, ckMon, rtuple], + prefilters, + ) diff --git a/Rich/Panoptes/python/Panoptes/calibration.py b/Rich/Panoptes/python/Panoptes/calibration.py index c4482df7ba1c83b386f1f80eb96ab940043c2ba1..f39a0506b61f4723bfdf800ba2f742020409036d 100644 --- a/Rich/Panoptes/python/Panoptes/calibration.py +++ b/Rich/Panoptes/python/Panoptes/calibration.py @@ -9,44 +9,42 @@ # or submit itself to any jurisdiction. # ############################################################################### -from PyConf.tonic import configurable +from DDDB.CheckDD4Hep import UseDD4Hep +from GaudiKernel.SystemOfUnits import GeV +from MooreOnlineConf.utils import update_and_reset +from PyConf.Algorithms import Rich__Future__Rec__Calib__RefIndexCalib as RefIndexCalib +from PyConf.Algorithms import Rich__Future__TestDecodeAndIDs as TestDecodeAndIDs +from PyConf.Algorithms import ( + Rich__Future__TestDerivedDetObjects as TestDerivedDetObjects, +) +from PyConf.Algorithms import TracksToSelection from PyConf.application import make_odin -from PyConf.Algorithms import (TracksToSelection, - Rich__Future__Rec__Calib__RefIndexCalib as - RefIndexCalib) -from RecoConf.rich_reconstruction import ( - default_rich_reco_options, make_rich_pids, get_detector_bool_opts) -from RecoConf.standalone import reco_prefilters - +from PyConf.tonic import configurable +from RecoConf.config import Reconstruction from RecoConf.rich_data_monitoring import ( default_rich_monitoring_options, make_rich_pixel_monitors, make_rich_track_monitors, ) - -from RecoConf.rich_mc_checking import (default_rich_checking_options, - make_rich_checkers) - -from PyConf.Algorithms import ( - Rich__Future__TestDerivedDetObjects as TestDerivedDetObjects, - Rich__Future__TestDecodeAndIDs as TestDecodeAndIDs) - -from RecoConf.config import Reconstruction -from MooreOnlineConf.utils import update_and_reset - -from DDDB.CheckDD4Hep import UseDD4Hep - -from GaudiKernel.SystemOfUnits import GeV +from RecoConf.rich_mc_checking import default_rich_checking_options, make_rich_checkers +from RecoConf.rich_reconstruction import ( + default_rich_reco_options, + get_detector_bool_opts, + make_rich_pids, +) +from RecoConf.standalone import reco_prefilters @configurable -def standalone_rich_ref_index_calib(offlineMode=False, - noUT=False, - min_p=(10 * GeV, 20 * GeV), - do_data_monitoring=False, - do_mc_checking=False, - do_detector_debug=False, - set_scale_factors_to_one=False): +def standalone_rich_ref_index_calib( + offlineMode=False, + noUT=False, + min_p=(10 * GeV, 20 * GeV), + do_data_monitoring=False, + do_mc_checking=False, + do_detector_debug=False, + set_scale_factors_to_one=False, +): """ The tracking and RICH reco for the RICH refractive index calibration """ @@ -55,12 +53,14 @@ def standalone_rich_ref_index_calib(offlineMode=False, if not noUT: print("Configuring tracking with UT") from RecoConf.hlt2_tracking import make_hlt2_tracks + hlt2_tracks = make_hlt2_tracks() else: print("Configuring tracking without UT") from RecoConf.hlt2_tracking import make_hlt2_tracks_without_UT + hlt2_tracks = make_hlt2_tracks_without_UT() - #print("Available Track Types", hlt2_tracks.keys()) + # print("Available Track Types", hlt2_tracks.keys()) # The track type we use track_version = "v1" @@ -79,7 +79,7 @@ def standalone_rich_ref_index_calib(offlineMode=False, reco_opts["MinP"] = min_p # As we aren't running PID, we do not need all hypos - #reco_opts["Particles"] = ["muon","pion","kaon"] + # reco_opts["Particles"] = ["muon","pion","kaon"] # CK Theta res range to use CKResHistoRange = (0.0055, 0.0035) @@ -88,18 +88,20 @@ def standalone_rich_ref_index_calib(offlineMode=False, if set_scale_factors_to_one: if UseDD4Hep: from Configurables import LHCb__Det__LbDD4hep__DD4hepSvc as DD4hepSvc + condval = "{CurrentScaleFactor : 1.0}" - DD4hepSvc().ConditionsOverride.update({ - "/world/BeforeMagnetRegion/Rich1:RefractivityScaleFactor": - condval, - "/world/AfterMagnetRegion/Rich2:RefractivityScaleFactor": - condval - }) + DD4hepSvc().ConditionsOverride.update( + { + "/world/BeforeMagnetRegion/Rich1:RefractivityScaleFactor": condval, + "/world/AfterMagnetRegion/Rich2:RefractivityScaleFactor": condval, + } + ) else: from Configurables import UpdateManagerSvc + UpdateManagerSvc().ConditionsOverride += [ "Conditions/Environment/Rich1/RefractivityScaleFactor := double CurrentScaleFactor = 1.0;", - "Conditions/Environment/Rich2/RefractivityScaleFactor := double CurrentScaleFactor = 1.0;" + "Conditions/Environment/Rich2/RefractivityScaleFactor := double CurrentScaleFactor = 1.0;", ] # Track selection @@ -107,9 +109,8 @@ def standalone_rich_ref_index_calib(offlineMode=False, # RICH photon reco conf = make_rich_pids( - track_name=tkType, - input_tracks=tkSel.OutputLocation, - options=reco_opts) + track_name=tkType, input_tracks=tkSel.OutputLocation, options=reco_opts + ) # The detector options det_opts = get_detector_bool_opts(reco_opts, tkType) @@ -134,7 +135,8 @@ def standalone_rich_ref_index_calib(offlineMode=False, CherenkovPhotonLocation=conf["CherenkovPhotons"], CherenkovAnglesLocation=conf["SignalCKAngles"], SummaryTracksLocation=conf["SummaryTracks"], - PhotonToParentsLocation=conf["PhotonToParents"]) + PhotonToParentsLocation=conf["PhotonToParents"], + ) algs_to_run += [make_odin().producer, calib] @@ -156,15 +158,16 @@ def standalone_rich_ref_index_calib(offlineMode=False, reco_opts=reco_opts, moni_opts=moni_opts, moni_set=moni_set, - )) + ) + ) algs_to_run += [v for _, v in sorted(moni_algs.items())] if do_detector_debug: algs_to_run += [ TestDerivedDetObjects(name="RichDetPrint", OutputLevel=1), TestDecodeAndIDs( - name="RichPixPrint", - DecodedDataLocation=conf["RichDecodedData"]) + name="RichPixPrint", DecodedDataLocation=conf["RichDecodedData"] + ), ] if do_mc_checking: @@ -178,11 +181,8 @@ def standalone_rich_ref_index_calib(offlineMode=False, conf["OriginalV1Tracks"] = tks[track_version] # make checkers check_algs = make_rich_checkers( - conf=conf, - reco_opts=reco_opts, - check_opts=check_opts, - moni_set=moni_set) + conf=conf, reco_opts=reco_opts, check_opts=check_opts, moni_set=moni_set + ) algs_to_run += [v for _, v in sorted(check_algs.items())] - return Reconstruction('rich_ref_index_calib', algs_to_run, - reco_prefilters()) + return Reconstruction("rich_ref_index_calib", algs_to_run, reco_prefilters()) diff --git a/Rich/Panoptes/python/Panoptes/commissioning.py b/Rich/Panoptes/python/Panoptes/commissioning.py index a2ec416de455db26d5eba34ced393d9500308de8..a0ef816af572a4c66151d0cc34a180d6be5def3b 100644 --- a/Rich/Panoptes/python/Panoptes/commissioning.py +++ b/Rich/Panoptes/python/Panoptes/commissioning.py @@ -9,37 +9,32 @@ # or submit itself to any jurisdiction. # ############################################################################### -from PyConf.tonic import configurable +from MooreOnlineConf.utils import decode_tae, if_then, run_all, update_and_reset +from PyConf.Algorithms import HltRoutingBitsFilter, OdinTypesFilter +from PyConf.Algorithms import Rich__Future__Mon__BankSizes as BankSizes +from PyConf.Algorithms import Rich__Future__Mon__BXTypeMonitors as BXTypeMonitors +from PyConf.Algorithms import Rich__Future__Mon__DataTuple as DataTuple +from PyConf.Algorithms import Rich__Future__Mon__HitMaps as HitMaps +from PyConf.Algorithms import Rich__Future__Mon__TAEMonitor as TAEMonitor +from PyConf.application import default_raw_banks, make_odin from PyConf.control_flow import CompositeNode, NodeLogic -from PyConf.application import make_odin, default_raw_banks -from PyConf.Algorithms import ( - Rich__Future__Mon__HitMaps as HitMaps, Rich__Future__Mon__BXTypeMonitors as - BXTypeMonitors, Rich__Future__Mon__DataTuple as DataTuple, - Rich__Future__Mon__BankSizes as BankSizes, Rich__Future__Mon__TAEMonitor as - TAEMonitor, HltRoutingBitsFilter, OdinTypesFilter) - -from RecoConf.rich_reconstruction import (default_rich_reco_options, - make_rich_pixels) - +from PyConf.tonic import configurable from RecoConf.config import Reconstruction - -from MooreOnlineConf.utils import (update_and_reset, decode_tae, if_then, - run_all) +from RecoConf.rich_reconstruction import default_rich_reco_options, make_rich_pixels try: import OnlineEnvBase as OnlineEnv + TAE_HALF_WINDOW = OnlineEnv.TAE except ImportError: TAE_HALF_WINDOW = 3 @configurable -def daq_commissioning(offlineMode=False, - enableTuple=False, - enableTAE=False, - runNumber=0): - """ RICH commissioning - """ +def daq_commissioning( + offlineMode=False, enableTuple=False, enableTAE=False, runNumber=0 +): + """RICH commissioning""" # Default RICH reco options reco_opts = default_rich_reco_options() @@ -60,21 +55,24 @@ def daq_commissioning(offlineMode=False, rb_lumi_filter = HltRoutingBitsFilter( name="RBFilterLumi", - RawBanks=default_raw_banks('HltRoutingBits'), + RawBanks=default_raw_banks("HltRoutingBits"), RequireMask=(1 << 1, 0, 0), # Lumi events - PassOnError=False) + PassOnError=False, + ) rb_phys_filter = HltRoutingBitsFilter( name="RBFilterPhys", - RawBanks=default_raw_banks('HltRoutingBits'), + RawBanks=default_raw_banks("HltRoutingBits"), RequireMask=(1 << 14, 0, 0), # Physics events - PassOnError=False) + PassOnError=False, + ) rb_smog_filter = HltRoutingBitsFilter( name="RBFilterSMOG", - RawBanks=default_raw_banks('HltRoutingBits'), + RawBanks=default_raw_banks("HltRoutingBits"), RequireMask=(1 << 15, 0, 0), # SMOG events - PassOnError=False) + PassOnError=False, + ) # Hit Maps without filters hMaps = HitMaps( @@ -83,14 +81,16 @@ def daq_commissioning(offlineMode=False, OfflinePlots=offlineMode, SpatialPlots=offlineMode, ODINLocation=make_odin(), - DecodedDataLocation=rich_pixels["RichDecodedData"]) + DecodedDataLocation=rich_pixels["RichDecodedData"], + ) to_run += [hMaps] # BXType Monitors without filters hBXType = BXTypeMonitors( name="BXTypeMonitors", ODINLocation=make_odin(), - DecodedDataLocation=rich_pixels["RichDecodedData"]) + DecodedDataLocation=rich_pixels["RichDecodedData"], + ) to_run += [hBXType] # BXType Monitors with Lumi filter @@ -98,12 +98,15 @@ def daq_commissioning(offlineMode=False, name="BXTypeMonitorsLumi", allow_duplicate_instances_with_distinct_names=True, ODINLocation=make_odin(), - DecodedDataLocation=rich_pixels["RichDecodedData"]) + DecodedDataLocation=rich_pixels["RichDecodedData"], + ) to_run += [ CompositeNode( - "Lumi", [rb_lumi_filter, hBXTypeLumi], + "Lumi", + [rb_lumi_filter, hBXTypeLumi], combine_logic=NodeLogic.LAZY_AND, - force_order=True) + force_order=True, + ) ] # BXType Monitors and Hit Maps with Phys filter @@ -114,17 +117,21 @@ def daq_commissioning(offlineMode=False, OfflinePlots=offlineMode, SpatialPlots=offlineMode, ODINLocation=make_odin(), - DecodedDataLocation=rich_pixels["RichDecodedData"]) + DecodedDataLocation=rich_pixels["RichDecodedData"], + ) hBXTypePhys = BXTypeMonitors( name="BXTypeMonitorsPhys", allow_duplicate_instances_with_distinct_names=True, ODINLocation=make_odin(), - DecodedDataLocation=rich_pixels["RichDecodedData"]) + DecodedDataLocation=rich_pixels["RichDecodedData"], + ) to_run += [ CompositeNode( - "Phys", [rb_phys_filter, hBXTypePhys, hMapsPhys], + "Phys", + [rb_phys_filter, hBXTypePhys, hMapsPhys], combine_logic=NodeLogic.LAZY_AND, - force_order=True) + force_order=True, + ) ] # BXType Monitors and Hit Maps with SMOG filter @@ -135,17 +142,21 @@ def daq_commissioning(offlineMode=False, OfflinePlots=offlineMode, SpatialPlots=offlineMode, ODINLocation=make_odin(), - DecodedDataLocation=rich_pixels["RichDecodedData"]) + DecodedDataLocation=rich_pixels["RichDecodedData"], + ) hBXTypeSMOG = BXTypeMonitors( name="BXTypeMonitorsSMOG", allow_duplicate_instances_with_distinct_names=True, ODINLocation=make_odin(), - DecodedDataLocation=rich_pixels["RichDecodedData"]) + DecodedDataLocation=rich_pixels["RichDecodedData"], + ) to_run += [ CompositeNode( - "SMOG", [rb_smog_filter, hBXTypeSMOG, hMapsSMOG], + "SMOG", + [rb_smog_filter, hBXTypeSMOG, hMapsSMOG], combine_logic=NodeLogic.LAZY_AND, - force_order=True) + force_order=True, + ) ] # Bank Size Monitors @@ -158,20 +169,22 @@ def daq_commissioning(offlineMode=False, name="DataTuple", ODINLocation=make_odin(), DecodedDataLocation=rich_pixels["RichDecodedData"], - RunNumber=runNumber) + RunNumber=runNumber, + ) to_run += [rtuple] # TAE monitoring if enableTAE: is_tae, tae_decoding, tae_odins, tae_data = decode_tae( - make_rich_pixels_forTAE, half_window=TAE_HALF_WINDOW) + make_rich_pixels_forTAE, half_window=TAE_HALF_WINDOW + ) tae_monitor = TAEMonitor( name="TAEMonitor", ODINsLocation=list(tae_odins.values()), - DecodedDatasLocation=list(tae_data.values())) + DecodedDatasLocation=list(tae_data.values()), + ) to_run += [ - if_then("IfTAE", is_tae, run_all("TAE", - [tae_decoding, tae_monitor])) + if_then("IfTAE", is_tae, run_all("TAE", [tae_decoding, tae_monitor])) ] - return Reconstruction('rich_comissioning', to_run) + return Reconstruction("rich_comissioning", to_run) diff --git a/Rich/Panoptes/python/Panoptes/photoncounting.py b/Rich/Panoptes/python/Panoptes/photoncounting.py index 6eed5aceb289ed3bfab90ab66e6de72b8097b797..98eee9933cca0b3512ada700729702ab1d3401e2 100644 --- a/Rich/Panoptes/python/Panoptes/photoncounting.py +++ b/Rich/Panoptes/python/Panoptes/photoncounting.py @@ -9,35 +9,37 @@ # or submit itself to any jurisdiction. # ############################################################################### -from PyConf.tonic import configurable +from DDDB.CheckDD4Hep import UseDD4Hep +from GaudiKernel.SystemOfUnits import GeV +from MooreOnlineConf.utils import update_and_reset +from PyConf.Algorithms import ( + Rich__Future__Rec__Counting__PhotonCounting as PhotonCounting, +) +from PyConf.Algorithms import TracksToSelection from PyConf.application import make_odin -from PyConf.Algorithms import (TracksToSelection, - Rich__Future__Rec__Counting__PhotonCounting as - PhotonCounting) -from RecoConf.rich_reconstruction import ( - default_rich_reco_options, make_rich_pids, get_detector_bool_opts) -from RecoConf.standalone import reco_prefilters - +from PyConf.tonic import configurable +from RecoConf.config import Reconstruction from RecoConf.rich_data_monitoring import ( default_rich_monitoring_options, make_rich_pixel_monitors, make_rich_track_monitors, ) - -from RecoConf.config import Reconstruction -from MooreOnlineConf.utils import update_and_reset - -from DDDB.CheckDD4Hep import UseDD4Hep - -from GaudiKernel.SystemOfUnits import GeV +from RecoConf.rich_reconstruction import ( + default_rich_reco_options, + get_detector_bool_opts, + make_rich_pids, +) +from RecoConf.standalone import reco_prefilters @configurable -def standalone_photon_counting(offlineMode=False, - noUT=False, - min_p=(30 * GeV, 30 * GeV), - min_vphits=(8, 8), - do_data_monitoring=False): +def standalone_photon_counting( + offlineMode=False, + noUT=False, + min_p=(30 * GeV, 30 * GeV), + min_vphits=(8, 8), + do_data_monitoring=False, +): """ The tracking and RICH reco for the RICH photon counting """ @@ -46,12 +48,14 @@ def standalone_photon_counting(offlineMode=False, if not noUT: print("Configuring tracking with UT") from RecoConf.hlt2_tracking import make_hlt2_tracks + hlt2_tracks = make_hlt2_tracks() else: print("Configuring tracking without UT") from RecoConf.hlt2_tracking import make_hlt2_tracks_without_UT + hlt2_tracks = make_hlt2_tracks_without_UT() - #print("Available Track Types", hlt2_tracks.keys()) + # print("Available Track Types", hlt2_tracks.keys()) # The track type we use track_version = "v1" @@ -70,7 +74,7 @@ def standalone_photon_counting(offlineMode=False, reco_opts["MinP"] = min_p # As we aren't running PID, we do not need all hypos - #reco_opts["Particles"] = ["muon","pion","kaon"] + # reco_opts["Particles"] = ["muon","pion","kaon"] # CK Theta res range to use CKResHistoRange = (0.0055, 0.0035) @@ -80,9 +84,8 @@ def standalone_photon_counting(offlineMode=False, # RICH photon reco conf = make_rich_pids( - track_name=tkType, - input_tracks=tkSel.OutputLocation, - options=reco_opts) + track_name=tkType, input_tracks=tkSel.OutputLocation, options=reco_opts + ) # The detector options det_opts = get_detector_bool_opts(reco_opts, tkType) @@ -108,7 +111,8 @@ def standalone_photon_counting(offlineMode=False, CherenkovPhotonLocation=conf["CherenkovPhotons"], CherenkovAnglesLocation=conf["SignalCKAngles"], SummaryTracksLocation=conf["SummaryTracks"], - PhotonToParentsLocation=conf["PhotonToParents"]) + PhotonToParentsLocation=conf["PhotonToParents"], + ) algs_to_run += [make_odin().producer, count] @@ -130,8 +134,8 @@ def standalone_photon_counting(offlineMode=False, reco_opts=reco_opts, moni_opts=moni_opts, moni_set=moni_set, - )) + ) + ) algs_to_run += [v for _, v in sorted(moni_algs.items())] - return Reconstruction('rich_photon_counting', algs_to_run, - reco_prefilters()) + return Reconstruction("rich_photon_counting", algs_to_run, reco_prefilters()) diff --git a/Rich/Panoptes/python/Panoptes/qmtest/exclusions.py b/Rich/Panoptes/python/Panoptes/qmtest/exclusions.py index b32cf5d45ddef5f20f57058bf84bea6d2025edb2..84c6e68e3edfe1076e4ba82fde0463b31ebab07b 100644 --- a/Rich/Panoptes/python/Panoptes/qmtest/exclusions.py +++ b/Rich/Panoptes/python/Panoptes/qmtest/exclusions.py @@ -9,41 +9,45 @@ # or submit itself to any jurisdiction. # ############################################################################### from GaudiTesting.BaseTest import LineSkipper +from Moore.qmtest.exclusions import RecPreprocessor, skip_scheduler from Moore.qmtest.exclusions import ref_preprocessor as moore_ref_preprocessor from Moore.qmtest.exclusions import remove_known_warnings as moore_remove_known_warnings -from Moore.qmtest.exclusions import (RecPreprocessor, skip_scheduler) -remove_known_warnings = moore_remove_known_warnings + LineSkipper(regexps=[ - # Known warnings from calibration writer when not running in ONLINE env. - r".* +WARNING Cannot write to .*", - r".* +WARNING DIM_DNS_NODE not defined. Disabling DIM publishing", - r".* +WARNING Environment variable PARTITION is not set", - # Warnings when camera server not available (not ONLINE) - r".*CameraTool +WARNING Could not connect to any camera server.*", - r".*CameraTool +WARNING Above message repeated .*", - # dd4hep specific warnings - r".*WARNING TransportSvc is currently incompatible with DD4HEP. Disabling its use and thus any material corrections.", - r".*WARNING See https://gitlab.cern.ch/lhcb/Rec/-/issues/326 for more details", - r".*WARNING Source ID .* is missing in LHCb Tel40 Link condition", - r".*WARNING .* writing and publishing is DISABLED", - r".*WARNING Failed to write YML file for .*", - r".*WARNING Run number override enabled, forced to .*", - # Reported as an ERROR but really should be no more than a WARNING ... - r"FTRawBankDecoder .*ERROR .*Possibly corrupt data.*" -]) +remove_known_warnings = moore_remove_known_warnings + LineSkipper( + regexps=[ + # Known warnings from calibration writer when not running in ONLINE env. + r".* +WARNING Cannot write to .*", + r".* +WARNING DIM_DNS_NODE not defined. Disabling DIM publishing", + r".* +WARNING Environment variable PARTITION is not set", + # Warnings when camera server not available (not ONLINE) + r".*CameraTool +WARNING Could not connect to any camera server.*", + r".*CameraTool +WARNING Above message repeated .*", + # dd4hep specific warnings + r".*WARNING TransportSvc is currently incompatible with DD4HEP. Disabling its use and thus any material corrections.", + r".*WARNING See https://gitlab.cern.ch/lhcb/Rec/-/issues/326 for more details", + r".*WARNING Source ID .* is missing in LHCb Tel40 Link condition", + r".*WARNING .* writing and publishing is DISABLED", + r".*WARNING Failed to write YML file for .*", + r".*WARNING Run number override enabled, forced to .*", + # Reported as an ERROR but really should be no more than a WARNING ... + r"FTRawBankDecoder .*ERROR .*Possibly corrupt data.*", + ] +) -skip_calib_messages = LineSkipper(regexps=[ - # Skip lines with variable information (times, file paths etc.) - r".* +INFO Previous #Events = .*", - r".* +INFO Watermark = .*", - r".* +INFO Created .*", - r".* +INFO Removing .*", - r".* +INFO Setting .* conditions version .*", - r".* +INFO Successfully wrote .* Scale factor to .*", - r".* +INFO Seen .* events in past .*", -]) +skip_calib_messages = LineSkipper( + regexps=[ + # Skip lines with variable information (times, file paths etc.) + r".* +INFO Previous #Events = .*", + r".* +INFO Watermark = .*", + r".* +INFO Created .*", + r".* +INFO Removing .*", + r".* +INFO Setting .* conditions version .*", + r".* +INFO Successfully wrote .* Scale factor to .*", + r".* +INFO Seen .* events in past .*", + ] +) # Exclude anything before finalize ref_preprocessor = remove_known_warnings + moore_ref_preprocessor + skip_calib_messages # include all messages -#ref_preprocessor = remove_known_warnings + skip_calib_messages + RecPreprocessor + skip_scheduler +# ref_preprocessor = remove_known_warnings + skip_calib_messages + RecPreprocessor + skip_scheduler diff --git a/Rich/Panoptes/scripts/RichCalibMon.sh b/Rich/Panoptes/scripts/RichCalibMon.sh index 44814ff93f2f0585fcfd3c62564f2b65cd446896..a7309155eb489567ef97a884e77e7bca6938b742 100755 --- a/Rich/Panoptes/scripts/RichCalibMon.sh +++ b/Rich/Panoptes/scripts/RichCalibMon.sh @@ -60,4 +60,3 @@ import os,Gaudi,GaudiKernel.ProcessJobOptions;\ from Gaudi.Configuration import importOptions;\ GaudiKernel.ProcessJobOptions.printing_level=999;\ importOptions(os.environ['PANOPTESROOT']+'/options/RichCalibMon.py');" - diff --git a/Rich/Panoptes/scripts/RichDAQMon.sh b/Rich/Panoptes/scripts/RichDAQMon.sh index b69bce4474091056f5946ed1ae99c97d8f85df66..0bd7881cab0299720a797c37fe08ba9d7313913d 100755 --- a/Rich/Panoptes/scripts/RichDAQMon.sh +++ b/Rich/Panoptes/scripts/RichDAQMon.sh @@ -42,4 +42,3 @@ import os,Gaudi,GaudiKernel.ProcessJobOptions;\ from Gaudi.Configuration import importOptions;\ GaudiKernel.ProcessJobOptions.printing_level=999;\ importOptions(os.environ['PANOPTESROOT']+'/options/RichDAQMon.py');" - diff --git a/Rich/Panoptes/scripts/RichHPDImageMon.sh b/Rich/Panoptes/scripts/RichHPDImageMon.sh index 222ec45de83cb7b822abd3c6cfcd2d748e607c98..5e0d0bb5551d0f73628da72ffebd1e76ed8c3ed2 100755 --- a/Rich/Panoptes/scripts/RichHPDImageMon.sh +++ b/Rich/Panoptes/scripts/RichHPDImageMon.sh @@ -42,4 +42,3 @@ import os,Gaudi,GaudiKernel.ProcessJobOptions;\ from Gaudi.Configuration import importOptions;\ GaudiKernel.ProcessJobOptions.printing_level=999;\ importOptions(os.environ['PANOPTESROOT']+'/options/RichHPDImageMon.py');" - diff --git a/Rich/Panoptes/scripts/RichOnlineCalib.sh b/Rich/Panoptes/scripts/RichOnlineCalib.sh index e90b4cc607eada9dc1ebabebf2bb3e093cef7940..4bf0d01b86d7a54805d48c8f84c8b74d4bb1a537 100755 --- a/Rich/Panoptes/scripts/RichOnlineCalib.sh +++ b/Rich/Panoptes/scripts/RichOnlineCalib.sh @@ -74,4 +74,3 @@ import os,Gaudi,GaudiKernel.ProcessJobOptions;\ from Gaudi.Configuration import importOptions;\ GaudiKernel.ProcessJobOptions.printing_level=999;\ importOptions(os.environ['PANOPTESROOT']+'/options/RichOnlineCalib.py');" - diff --git a/Rich/Panoptes/scripts/RichRingMon.sh b/Rich/Panoptes/scripts/RichRingMon.sh index 63df37e0a0b0bfaf16c41fac56c711932a1fcb77..5856157cbee1edf14547887cbbd4865a2291fd2c 100755 --- a/Rich/Panoptes/scripts/RichRingMon.sh +++ b/Rich/Panoptes/scripts/RichRingMon.sh @@ -42,4 +42,3 @@ import os,Gaudi,GaudiKernel.ProcessJobOptions;\ from Gaudi.Configuration import importOptions;\ GaudiKernel.ProcessJobOptions.printing_level=999;\ importOptions(os.environ['PANOPTESROOT']+'/options/RichRingMon.py');" - diff --git a/Rich/Panoptes/scripts/postprocess.sh b/Rich/Panoptes/scripts/postprocess.sh index 03426f6843777d6e8feb059716a12e0edaa55230..90d03d1ed32292f349306afa3d16292360c93b87 100755 --- a/Rich/Panoptes/scripts/postprocess.sh +++ b/Rich/Panoptes/scripts/postprocess.sh @@ -34,5 +34,3 @@ export gaudi_exe2="${GAUDIONLINEROOT}/${CMTCONFIG}/Gaudi.exe libGaudiOnline.so O export UTGID=RichPost ; ${gaudi_exe} -opt=$RICHMONITORINGSYSROOT/options/RichOnlineAna2.opts -main=$GAUDIONLINEROOT/options/Main.opts # 1>${RICHLOG}/${UTGID}2.log 2>&1 & - - diff --git a/Rich/Panoptes/tests/options/2022-data.py b/Rich/Panoptes/tests/options/2022-data.py index cf4f472a8a5582112cbdf89b1e25237b32ed54d0..2419a57054fd8865e76810a39c8bcf3e7632b41b 100644 --- a/Rich/Panoptes/tests/options/2022-data.py +++ b/Rich/Panoptes/tests/options/2022-data.py @@ -10,14 +10,13 @@ ############################################################################### import os + from Moore import options options.set_input_and_conds_from_testfiledb("rich-decode-2022-panoptes") jonPath = "/usera/jonesc/NFS/data/RunIII/Hlt2/LHCb/RefIndexCalib/2022/" if os.path.exists(jonPath): - options.input_files = [ - jonPath + "data-{i:04d}.mdf".format(i=i) for i in range(38) - ] + options.input_files = [jonPath + "data-{i:04d}.mdf".format(i=i) for i in range(38)] options.simulation = False options.evt_max = 1000 diff --git a/Rich/Panoptes/tests/options/2023-data.py b/Rich/Panoptes/tests/options/2023-data.py index 3b00c9e67921bbb0403fb5b079ac9d349992a590..2eeee1e7d4df07e2cb936042d7480d33e8d28c33 100644 --- a/Rich/Panoptes/tests/options/2023-data.py +++ b/Rich/Panoptes/tests/options/2023-data.py @@ -10,6 +10,7 @@ ############################################################################### import os + from Moore import options options.set_input_and_conds_from_testfiledb("rich-decode-2023") diff --git a/Rich/Panoptes/tests/options/2024-data.py b/Rich/Panoptes/tests/options/2024-data.py index 363948ded073f63bd1c4ef3bacb73cbe3a5a9270..7dca9fe1200edda9a82398063014344dfe92ce37 100644 --- a/Rich/Panoptes/tests/options/2024-data.py +++ b/Rich/Panoptes/tests/options/2024-data.py @@ -10,6 +10,7 @@ ############################################################################### import os + from Moore import options # Start with config from TestFileDB @@ -28,5 +29,6 @@ options.print_freq = 100 # Due to issues with hit sorting in FT disable Mat corrections # See for more details https://gitlab.cern.ch/lhcb/Panoptes/-/issues/7 from PyConf.Algorithms import PrStoreSciFiHits + PrStoreSciFiHits.global_bind(ApplyMatContractionCalibration=False) # To be removed once the issue is resolved properly. diff --git a/Rich/Panoptes/tests/options/2024-mc.py b/Rich/Panoptes/tests/options/2024-mc.py index 6b40e8ab2e5fd938084a25e0ed4ec9a12ce00220..8d916906bcdf0c05b20fa925b001e1952d10294f 100644 --- a/Rich/Panoptes/tests/options/2024-mc.py +++ b/Rich/Panoptes/tests/options/2024-mc.py @@ -10,12 +10,12 @@ ############################################################################### import os + from Moore import options options.set_input_and_conds_from_testfiledb("rich-decode-2024-mc") jonPath = "/usera/jonesc/NFS/data/MC/Run3/30000000/dddb-20231017/sim-20231017-vc-md100/2024-Expected-lumi_2.0e33/DIGI/" if os.path.exists(jonPath): options.input_files = [ - jonPath + "30000000_42604869_{i:08d}.digi".format(i=i) - for i in range(0, 80) + jonPath + "30000000_42604869_{i:08d}.digi".format(i=i) for i in range(0, 80) ] diff --git a/Rich/Panoptes/tests/options/download_digi_input.py b/Rich/Panoptes/tests/options/download_digi_input.py index 2dad5cf14fa8a52e7e1246ffaacc1017522fa5f2..0bd297a94f586f1e5af4636fbba2251baf5840c6 100644 --- a/Rich/Panoptes/tests/options/download_digi_input.py +++ b/Rich/Panoptes/tests/options/download_digi_input.py @@ -9,20 +9,21 @@ # or submit itself to any jurisdiction. # ############################################################################### import os + from Moore import options from Moore.qmtest.context import download_digi_inputs_locally jonPath = "/usera/jonesc/NFS/data/MC/Run3/Download/" if options.simulation and os.path.exists(jonPath): - - #AVERAGE_EVENT_SIZE = 500 * 1000 # upper limit of average event size + # AVERAGE_EVENT_SIZE = 500 * 1000 # upper limit of average event size options.input_files = download_digi_inputs_locally( - options.input_files, dest_dir=jonPath) - #max_size=options.evt_max * AVERAGE_EVENT_SIZE) + options.input_files, dest_dir=jonPath + ) + # max_size=options.evt_max * AVERAGE_EVENT_SIZE) # avoid later options file changing this property and running more events # than were downloaded which usually results in weird errors when processing # the last event which was only partially downloaded. - #options.lockOption('evt_max') - #options.lockOption('input_files') + # options.lockOption('evt_max') + # options.lockOption('input_files') diff --git a/Rich/Panoptes/tests/options/master-db-tag.py b/Rich/Panoptes/tests/options/master-db-tag.py index b6d4875419de6d46130db02bb2a88dea31b47933..79f57a74d78be6af05b83facae687d179799e968 100644 --- a/Rich/Panoptes/tests/options/master-db-tag.py +++ b/Rich/Panoptes/tests/options/master-db-tag.py @@ -9,8 +9,8 @@ # or submit itself to any jurisdiction. # ############################################################################### -from Moore import options from DDDB.CheckDD4Hep import UseDD4Hep +from Moore import options if UseDD4Hep: # https://gitlab.cern.ch/lhcb-conddb/lhcb-conditions-database/-/merge_requests/26 diff --git a/Rich/Panoptes/tests/options/pmt-v3-data.py b/Rich/Panoptes/tests/options/pmt-v3-data.py index 6879a64308deb02b9ee84f69eb135d5210bffe40..5d08f40495a575ff6ff311276920bf992178222e 100644 --- a/Rich/Panoptes/tests/options/pmt-v3-data.py +++ b/Rich/Panoptes/tests/options/pmt-v3-data.py @@ -10,14 +10,14 @@ ############################################################################### import os -from Moore import options -from DDDB.CheckDD4Hep import UseDD4Hep + from Configurables import DDDBConf, LHCbApp +from DDDB.CheckDD4Hep import UseDD4Hep +from Moore import options from PRConfig.TestFileDB import test_file_db -options.input_files = test_file_db[ - "rich-decode-detdesc-compat-old-rich1"].filenames -options.input_type = 'ROOT' +options.input_files = test_file_db["rich-decode-detdesc-compat-old-rich1"].filenames +options.input_type = "ROOT" if UseDD4Hep: # https://gitlab.cern.ch/lhcb-conddb/lhcb-conditions-database/-/merge_requests/26 @@ -26,7 +26,7 @@ if UseDD4Hep: LHCbApp().CondDBtag = tag # Work around PyConf bug # Use a geometry from before changes to RICH1 # https://gitlab.cern.ch/lhcb/Detector/-/merge_requests/205 - tag = 'run3/before-rich1-geom-update-26052022' + tag = "run3/before-rich1-geom-update-26052022" DDDBConf().GeometryVersion = tag options.geometry_version = tag else: diff --git a/Rich/RichLAMSImageAnalysis/src/RichLAMSImageAnalysis.cpp b/Rich/RichLAMSImageAnalysis/src/RichLAMSImageAnalysis.cpp index d2a9d287a4b71798f06cbec011ad7a3b4e1db7d4..f3a910dc61c9210c520be62ed6450b7eea54b915 100644 --- a/Rich/RichLAMSImageAnalysis/src/RichLAMSImageAnalysis.cpp +++ b/Rich/RichLAMSImageAnalysis/src/RichLAMSImageAnalysis.cpp @@ -77,7 +77,7 @@ int main() { DimCommand PVSSCommand( "RichLAMS/ImageFilename", "I:1;C" ); // create DIM services, one per camera - ImgAnalysisResults result = {0, 0, 0, 0, 0, 0, 0, 999, 0}; + ImgAnalysisResults result = { 0, 0, 0, 0, 0, 0, 0, 999, 0 }; DimService LAMSResults( "RichLAMS/ImgAnalResults", "D:8;I:1", (void*)&result, sizeof( result ) ); // start the DIM server diff --git a/Rich/RichMirrAlign/Test/Rich1CondDBUpdate__Mp9Wi4.0Fv1Cm2Sm1_MUCollision10_i1.xml b/Rich/RichMirrAlign/Test/Rich1CondDBUpdate__Mp9Wi4.0Fv1Cm2Sm1_MUCollision10_i1.xml index 0224bfbfa4a8655db224b225c8128ea5e338b7de..c7df429422ceb6094b3d943587a662009266d9c8 100644 --- a/Rich/RichMirrAlign/Test/Rich1CondDBUpdate__Mp9Wi4.0Fv1Cm2Sm1_MUCollision10_i1.xml +++ b/Rich/RichMirrAlign/Test/Rich1CondDBUpdate__Mp9Wi4.0Fv1Cm2Sm1_MUCollision10_i1.xml @@ -131,4 +131,4 @@ <paramVector name="dRotXYZ" type="double"> 0.00000*mrad 1.46647*mrad -0.35587*mrad</paramVector> <paramVector name="pivotXYZ" type="double">632.6*m 0*mm 0*mm</paramVector> </condition> -</DDDB> \ No newline at end of file +</DDDB> diff --git a/Rich/RichMirrAlign/Test/Rich1MirrAlign_i0.conf b/Rich/RichMirrAlign/Test/Rich1MirrAlign_i0.conf index 0764f856be574bc58ecbbc328cfcf1799e9ca22e..32cc2e2d2a32b3a9a8e9f9cd5e87506f74c7b93e 100644 --- a/Rich/RichMirrAlign/Test/Rich1MirrAlign_i0.conf +++ b/Rich/RichMirrAlign/Test/Rich1MirrAlign_i0.conf @@ -10,4 +10,3 @@ mirrCombinFitResults = Rich1MirrCombinFit__Mp9Wi4.0Fv1Cm2Sm1_MUCollision10_i0 zerothIterationXML = Rich1CondDBUpdate__Mp9Wi4.0Fv1Cm2Sm1_MUCollision10_i0.xml currentIterationXML = Rich1CondDBUpdate__Mp9Wi4.0Fv1Cm2Sm1_MUCollision10_i0.xml nextIterationXML = Rich1CondDBUpdate__Mp9Wi4.0Fv1Cm2Sm1_MUCollision10_i1.xml - diff --git a/Rich/RichMirrAlign/Test/Rich2CombAndMirrSubsets_96m94c_p12p43fix.txt b/Rich/RichMirrAlign/Test/Rich2CombAndMirrSubsets_96m94c_p12p43fix.txt index 75d12eb97d74fbd3433e7a54c373f430ced31b2f..377e4101b504d6edfdd903a8ed271b8e4f49c406 100644 --- a/Rich/RichMirrAlign/Test/Rich2CombAndMirrSubsets_96m94c_p12p43fix.txt +++ b/Rich/RichMirrAlign/Test/Rich2CombAndMirrSubsets_96m94c_p12p43fix.txt @@ -41,4 +41,3 @@ mirrors 07 06 05 04 27 26 25 24 03 02 01 00 23 22 21 20 ----------------------------------------------------- - diff --git a/Rich/RichMirrAlign/Test/Rich2CondDBUpdate__Mp9Wi3.0Fv3Cm2Sm1_MUCollision10_i1.xml b/Rich/RichMirrAlign/Test/Rich2CondDBUpdate__Mp9Wi3.0Fv3Cm2Sm1_MUCollision10_i1.xml index f7cf6140d61079307ad6b5f75c7ad37c16903cc3..6cd8d434480b825278fac73d466f897f059837fe 100644 --- a/Rich/RichMirrAlign/Test/Rich2CondDBUpdate__Mp9Wi3.0Fv3Cm2Sm1_MUCollision10_i1.xml +++ b/Rich/RichMirrAlign/Test/Rich2CondDBUpdate__Mp9Wi3.0Fv3Cm2Sm1_MUCollision10_i1.xml @@ -517,4 +517,4 @@ <paramVector name="dRotXYZ" type="double"> 0.00000*mrad -0.11551*mrad -0.98045*mrad</paramVector> <paramVector name="pivotXYZ" type="double">84409*mm 0.0*mm 0.0*mm</paramVector> </condition> -</DDDB> \ No newline at end of file +</DDDB> diff --git a/Rich/RichMirrAlign/Test/TestXmlReader.cpp b/Rich/RichMirrAlign/Test/TestXmlReader.cpp index edc7f58a105c4f5c04130913ee81e3ab1702079a..dc7f7b6d2366f68e73673958426eb36b507b554d 100644 --- a/Rich/RichMirrAlign/Test/TestXmlReader.cpp +++ b/Rich/RichMirrAlign/Test/TestXmlReader.cpp @@ -102,4 +102,4 @@ int main() { } } return 1; -} \ No newline at end of file +} diff --git a/Rich/RichMirrAlign/files/LHCb_Conditions_Database_Rich2_Alignment_updated.yaml b/Rich/RichMirrAlign/files/LHCb_Conditions_Database_Rich2_Alignment_updated.yaml index 688145b3be7fcab0645ee2e133016bcbbb76f633..ea2c658450f68ae25a2a3c74124ab191a490d89d 100644 --- a/Rich/RichMirrAlign/files/LHCb_Conditions_Database_Rich2_Alignment_updated.yaml +++ b/Rich/RichMirrAlign/files/LHCb_Conditions_Database_Rich2_Alignment_updated.yaml @@ -397,4 +397,4 @@ Rich2SphMirrorCont1_Align: !<!alignment> Rich2_Align: !<!alignment> position: [0.0*mm, 0.0*mm, 0.0*mm] rotation: [0.0*mrad, 0.0*mrad, 0.0*mrad] - pivot: [0.0*mm, 0.0*mm, 0.0*mm] \ No newline at end of file + pivot: [0.0*mm, 0.0*mm, 0.0*mm] diff --git a/Rich/RichMirrAlign/python/RichHPDAlignWrapper.py b/Rich/RichMirrAlign/python/RichHPDAlignWrapper.py index e16717b246ac701109784f8c2cb9e98f455b2e8e..e901e9c8abc123c31471d064201b62019aebfc35 100755 --- a/Rich/RichMirrAlign/python/RichHPDAlignWrapper.py +++ b/Rich/RichMirrAlign/python/RichHPDAlignWrapper.py @@ -9,50 +9,82 @@ # or submit itself to any jurisdiction. # ############################################################################### #!/usr/bin/env python -import sys +import getopt import os +import sys from subprocess import * -import getopt -#print sys.argv[0:] +# print sys.argv[0:] -varOpts = getopt.getopt(sys.argv[1:], 'h:p:u:v:o:w:r:i:a:f:', [ - 'home=', 'pathToScripts=', 'userReleaseArea=', - 'setupProjectPanoptesVersion=', 'setupProjectPanoptesOptions=', 'workDir=', - 'rich=', 'inputXML=', 'ouputFileXML=', 'fitresults=' -]) -#print varOpts +varOpts = getopt.getopt( + sys.argv[1:], + "h:p:u:v:o:w:r:i:a:f:", + [ + "home=", + "pathToScripts=", + "userReleaseArea=", + "setupProjectPanoptesVersion=", + "setupProjectPanoptesOptions=", + "workDir=", + "rich=", + "inputXML=", + "ouputFileXML=", + "fitresults=", + ], +) +# print varOpts for varOptKey, varOptValue in varOpts[0]: - if varOptKey in ['-h', '--home']: + if varOptKey in ["-h", "--home"]: home = varOptValue - elif varOptKey in ['-p', '--pathToScripts']: + elif varOptKey in ["-p", "--pathToScripts"]: pathToScripts = varOptValue - elif varOptKey in ['-u', '--userReleaseArea']: + elif varOptKey in ["-u", "--userReleaseArea"]: userReleaseArea = varOptValue - elif varOptKey in ['-v', '--setupProjectPanoptesVersion']: + elif varOptKey in ["-v", "--setupProjectPanoptesVersion"]: setupProjectPanoptesVersion = varOptValue - elif varOptKey in ['-o', '--setupProjectPanoptesOptions']: + elif varOptKey in ["-o", "--setupProjectPanoptesOptions"]: setupProjectPanoptesOptions = varOptValue - elif varOptKey in ['-w', '--workDir']: + elif varOptKey in ["-w", "--workDir"]: workDir = varOptValue - elif varOptKey in ['-r', '--rich']: + elif varOptKey in ["-r", "--rich"]: rich = varOptValue - elif varOptKey in ['-i', '--inputXML']: + elif varOptKey in ["-i", "--inputXML"]: inputXML = varOptValue - elif varOptKey in ['-a', '--ouputFileXML']: + elif varOptKey in ["-a", "--ouputFileXML"]: ouputFileXML = varOptValue - elif varOptKey in ['-f', '--fitresults']: + elif varOptKey in ["-f", "--fitresults"]: fitresults = varOptValue p = Popen( - "export HOME=" + home + ";" + "source " + pathToScripts + "/LbLogin.sh;" - + "export User_release_area=" + userReleaseArea + ";" + - "source `which SetupProject.sh` Panoptes " + setupProjectPanoptesVersion - + " " + setupProjectPanoptesOptions + ";" + - "$RICHMIRRALIGNROOT/$CMTCONFIG/RichHPDAlign.exe " + rich + " " + inputXML + - " " + ouputFileXML + " " + fitresults + " > " + workDir + "/Rich" + rich + - "HPDAlign.txt", + "export HOME=" + + home + + ";" + + "source " + + pathToScripts + + "/LbLogin.sh;" + + "export User_release_area=" + + userReleaseArea + + ";" + + "source `which SetupProject.sh` Panoptes " + + setupProjectPanoptesVersion + + " " + + setupProjectPanoptesOptions + + ";" + + "$RICHMIRRALIGNROOT/$CMTCONFIG/RichHPDAlign.exe " + + rich + + " " + + inputXML + + " " + + ouputFileXML + + " " + + fitresults + + " > " + + workDir + + "/Rich" + + rich + + "HPDAlign.txt", shell=True, - executable="/bin/bash") + executable="/bin/bash", +) sts = os.waitpid(p.pid, 0) diff --git a/Rich/RichMirrAlign/python/RichMirrAlignWrapper.py b/Rich/RichMirrAlign/python/RichMirrAlignWrapper.py index 30939898c40f8a6bf86047dc862a2d0277ca9695..04e8c4b6a21ba7051c582e0730bdcfbe884411cb 100755 --- a/Rich/RichMirrAlign/python/RichMirrAlignWrapper.py +++ b/Rich/RichMirrAlign/python/RichMirrAlignWrapper.py @@ -9,43 +9,69 @@ # granted to it by virtue of its status as an Intergovernmental Organization # # or submit itself to any jurisdiction. # ############################################################################### -import sys +import getopt import os +import sys from subprocess import * -import getopt -#print sys.argv[0:] +# print sys.argv[0:] -varOpts = getopt.getopt(sys.argv[1:], 'h:p:u:v:o:w:r:', [ - 'home=', 'pathToScripts=', 'userReleaseArea=', - 'setupProjectPanoptesVersion=', 'setupProjectPanoptesOptions=', 'workDir=', - 'rich=' -]) -#print varOpts +varOpts = getopt.getopt( + sys.argv[1:], + "h:p:u:v:o:w:r:", + [ + "home=", + "pathToScripts=", + "userReleaseArea=", + "setupProjectPanoptesVersion=", + "setupProjectPanoptesOptions=", + "workDir=", + "rich=", + ], +) +# print varOpts for varOptKey, varOptValue in varOpts[0]: - if varOptKey in ['-h', '--home']: + if varOptKey in ["-h", "--home"]: home = varOptValue - elif varOptKey in ['-p', '--pathToScripts']: + elif varOptKey in ["-p", "--pathToScripts"]: pathToScripts = varOptValue - elif varOptKey in ['-u', '--userReleaseArea']: + elif varOptKey in ["-u", "--userReleaseArea"]: userReleaseArea = varOptValue - elif varOptKey in ['-v', '--setupProjectPanoptesVersion']: + elif varOptKey in ["-v", "--setupProjectPanoptesVersion"]: setupProjectPanoptesVersion = varOptValue - elif varOptKey in ['-o', '--setupProjectPanoptesOptions']: + elif varOptKey in ["-o", "--setupProjectPanoptesOptions"]: setupProjectPanoptesOptions = varOptValue - elif varOptKey in ['-w', '--workDir']: + elif varOptKey in ["-w", "--workDir"]: workDir = varOptValue - elif varOptKey in ['-r', '--rich']: + elif varOptKey in ["-r", "--rich"]: rich = varOptValue p = Popen( - "export HOME=" + home + ";" + "source " + pathToScripts + "/LbLogin.sh;" - + "export User_release_area=" + userReleaseArea + ";" + - "source `which SetupProject.sh` Panoptes " + setupProjectPanoptesVersion - + " " + setupProjectPanoptesOptions + ";" + - "$RICHMIRRALIGNROOT/$CMTCONFIG/RichMirrAlign.exe " + workDir + "/Rich" + - rich + "MirrAlign.conf > " + workDir + "/Rich" + rich + "MirrAlign.out", + "export HOME=" + + home + + ";" + + "source " + + pathToScripts + + "/LbLogin.sh;" + + "export User_release_area=" + + userReleaseArea + + ";" + + "source `which SetupProject.sh` Panoptes " + + setupProjectPanoptesVersion + + " " + + setupProjectPanoptesOptions + + ";" + + "$RICHMIRRALIGNROOT/$CMTCONFIG/RichMirrAlign.exe " + + workDir + + "/Rich" + + rich + + "MirrAlign.conf > " + + workDir + + "/Rich" + + rich + + "MirrAlign.out", shell=True, - executable="/bin/bash") + executable="/bin/bash", +) sts = os.waitpid(p.pid, 0) diff --git a/Rich/RichMirrAlign/src/RichMirrAlign.cpp b/Rich/RichMirrAlign/src/RichMirrAlign.cpp index c9f28aae5abfc0650d152cf85878057f660552c1..a49ee210495eb64524805fac82936220e8147f96 100644 --- a/Rich/RichMirrAlign/src/RichMirrAlign.cpp +++ b/Rich/RichMirrAlign/src/RichMirrAlign.cpp @@ -494,7 +494,7 @@ int main( int argc, char* argv[] ) { // magnification factors: ifstream magnFactors_ifs; - regex tiltPattern{"[prisec]{3}[YZ][np]"}; + regex tiltPattern{ "[prisec]{3}[YZ][np]" }; smatch tiltMatch; for ( const auto& mffname : magnFactors_files ) { regex_search( mffname, tiltMatch, tiltPattern ); @@ -1769,9 +1769,7 @@ int main( int argc, char* argv[] ) { string alteAxis; if ( axisKind == "Y" ) alteAxis = "z"; - else { - alteAxis = "y"; - } + else { alteAxis = "y"; } // construct magnFactMirrName_sameAxis like e.g. p27Y_Y // construct magnFactMirrName_alteAxis like e.g. p27Y_z string magnFactMirrName_sameAxis = pname_val.first + "_" + axisKind; @@ -1805,9 +1803,7 @@ int main( int argc, char* argv[] ) { string alteAxis; if ( axisKind == "Y" ) alteAxis = "z"; - else { - alteAxis = "y"; - } + else { alteAxis = "y"; } string magnFactMirrName_sameAxis = pname_val.first + "_" + axisKind; string magnFactMirrName_alteAxis = pname_val.first + "_" + alteAxis; if ( fabs( pname_val.second ) * sqrt( pow( magnFactMirr.find( magnFactMirrName_sameAxis )->second, 2. ) + @@ -1911,7 +1907,7 @@ int main( int argc, char* argv[] ) { cout << endl; // mirror types: - string mirrTypes[2]{"p", "s"}; + string mirrTypes[2]{ "p", "s" }; // prepare dictionary of mirror type names map<string, string> mirrType_typeName; @@ -1946,7 +1942,7 @@ int main( int argc, char* argv[] ) { string rZ = conds[segName]["rotation"][2].as<string>(); smatch rotsma; - regex rotreg{"[-\\d]+.[\\d]+"}; + regex rotreg{ "[-\\d]+.[\\d]+" }; regex_search( rY, rotsma, rotreg ); double rotY = stod( rotsma.str() ); @@ -2045,7 +2041,7 @@ int main( int argc, char* argv[] ) { string rZ = conds[segName]["rotation"][2].as<string>(); smatch rotsma; - regex rotreg{"[-\\d]+.[\\d]+"}; + regex rotreg{ "[-\\d]+.[\\d]+" }; regex_search( rY, rotsma, rotreg ); double rotY = stod( rotsma.str() ); @@ -2116,8 +2112,8 @@ int main( int argc, char* argv[] ) { printStyles.push_back( 0 ); } - string printStyle_str[] = {" One-glance printout with no digits after decimal point", - " Detailed printout with one digit after decimal point"}; + string printStyle_str[] = { " One-glance printout with no digits after decimal point", + " Detailed printout with one digit after decimal point" }; for ( auto& printStyle : printStyles ) { cout << endl; diff --git a/Rich/RichMirrAlign/src/RichMirrAlignFcn.cpp b/Rich/RichMirrAlign/src/RichMirrAlignFcn.cpp index 20efaf8a0f38367215268286a0b0ec0ee4748c10..439d8ef22713a94bce26f8784ad78d4135adfba4 100644 --- a/Rich/RichMirrAlign/src/RichMirrAlignFcn.cpp +++ b/Rich/RichMirrAlign/src/RichMirrAlignFcn.cpp @@ -190,9 +190,7 @@ double RichMirrAlignFcn::operator()( const vector<double>& par ) const { string alteAxis; if ( axisKind == "Y" ) alteAxis = "z"; - else { - alteAxis = "y"; - } + else { alteAxis = "y"; } // construct magnFactMirrName_sameAxis like e.g. pri27Y_Y // construct magnFactMirrName_alteAxis like e.g. pri27Y_z string magnFactMirrName_sameAxis = name_nr.first + "_" + axisKind; diff --git a/Rich/RichMirrAlign/src/RichMirrAlignFcn.h b/Rich/RichMirrAlign/src/RichMirrAlignFcn.h index 3ff1148d641e6056b9e176055025e9829fbaf5bf..4979b936f88bf2f4f5cf7d318f885998eb28f71b 100644 --- a/Rich/RichMirrAlign/src/RichMirrAlignFcn.h +++ b/Rich/RichMirrAlign/src/RichMirrAlignFcn.h @@ -47,5 +47,5 @@ private: std::map<std::string, unsigned int> m_parName_ordNr; unsigned int m_regularizationMode; - double m_theErrorDef{0}; + double m_theErrorDef{ 0 }; }; diff --git a/Rich/RichMirrCombinFit/python/RichHPDFitWrapper.py b/Rich/RichMirrCombinFit/python/RichHPDFitWrapper.py index bf4c8655780184406030638b3615ba7531778a06..8c1f1f1ffbcf12ec084280f29f0d5fb7a5fd1675 100755 --- a/Rich/RichMirrCombinFit/python/RichHPDFitWrapper.py +++ b/Rich/RichMirrCombinFit/python/RichHPDFitWrapper.py @@ -9,50 +9,82 @@ # granted to it by virtue of its status as an Intergovernmental Organization # # or submit itself to any jurisdiction. # ############################################################################### -import sys +import getopt import os +import sys from subprocess import * -import getopt -#print sys.argv[0:] +# print sys.argv[0:] -varOpts = getopt.getopt(sys.argv[1:], 'h:p:u:v:o:w:r:d:i:f:', [ - 'home=', 'pathToScripts=', 'userReleaseArea=', - 'setupProjectPanoptesVersion=', 'setupProjectPanoptesOptions=', 'workDir=', - 'rich=', 'deltaThetaWindow=', 'histoFile=', 'outputFile=' -]) -#print varOpts +varOpts = getopt.getopt( + sys.argv[1:], + "h:p:u:v:o:w:r:d:i:f:", + [ + "home=", + "pathToScripts=", + "userReleaseArea=", + "setupProjectPanoptesVersion=", + "setupProjectPanoptesOptions=", + "workDir=", + "rich=", + "deltaThetaWindow=", + "histoFile=", + "outputFile=", + ], +) +# print varOpts for varOptKey, varOptValue in varOpts[0]: - if varOptKey in ['-h', '--home']: + if varOptKey in ["-h", "--home"]: home = varOptValue - elif varOptKey in ['-p', '--pathToScripts']: + elif varOptKey in ["-p", "--pathToScripts"]: pathToScripts = varOptValue - elif varOptKey in ['-u', '--userReleaseArea']: + elif varOptKey in ["-u", "--userReleaseArea"]: userReleaseArea = varOptValue - elif varOptKey in ['-v', '--setupProjectPanoptesVersion']: + elif varOptKey in ["-v", "--setupProjectPanoptesVersion"]: setupProjectPanoptesVersion = varOptValue - elif varOptKey in ['-o', '--setupProjectPanoptesOptions']: + elif varOptKey in ["-o", "--setupProjectPanoptesOptions"]: setupProjectPanoptesOptions = varOptValue - elif varOptKey in ['-w', '--workDir']: + elif varOptKey in ["-w", "--workDir"]: workDir = varOptValue - elif varOptKey in ['-r', '--rich']: + elif varOptKey in ["-r", "--rich"]: rich = varOptValue - elif varOptKey in ['-d', '--deltaThetaWindow']: + elif varOptKey in ["-d", "--deltaThetaWindow"]: deltaThetaWindow = varOptValue - elif varOptKey in ['-i', '--histoFile']: + elif varOptKey in ["-i", "--histoFile"]: histoFile = varOptValue - elif varOptKey in ['-f', '--outputFile']: + elif varOptKey in ["-f", "--outputFile"]: FitResultsFile = varOptValue p = Popen( - "export HOME=" + home + ";" + "source " + pathToScripts + "/LbLogin.sh;" - + "export User_release_area=" + userReleaseArea + ";" + - "source `which SetupProject.sh` Panoptes " + setupProjectPanoptesVersion - + " " + setupProjectPanoptesOptions + ";" + - "$RICHMIRRCOMBINFITROOT/$CMTCONFIG/RichHPDFit.exe " + rich + " " + - deltaThetaWindow + " " + histoFile + " " + FitResultsFile + " > " + workDir - + "/Rich" + rich + "HPDFit.out", + "export HOME=" + + home + + ";" + + "source " + + pathToScripts + + "/LbLogin.sh;" + + "export User_release_area=" + + userReleaseArea + + ";" + + "source `which SetupProject.sh` Panoptes " + + setupProjectPanoptesVersion + + " " + + setupProjectPanoptesOptions + + ";" + + "$RICHMIRRCOMBINFITROOT/$CMTCONFIG/RichHPDFit.exe " + + rich + + " " + + deltaThetaWindow + + " " + + histoFile + + " " + + FitResultsFile + + " > " + + workDir + + "/Rich" + + rich + + "HPDFit.out", shell=True, - executable="/bin/bash") + executable="/bin/bash", +) sts = os.waitpid(p.pid, 0) diff --git a/Rich/RichMirrCombinFit/python/RichMirrCombinFitWrapper.py b/Rich/RichMirrCombinFit/python/RichMirrCombinFitWrapper.py index 5b7921a2b3922195139090dd5bdab3e3b3ea7629..b0de58097264292c99ff44e42f0690df2fdfddc8 100755 --- a/Rich/RichMirrCombinFit/python/RichMirrCombinFitWrapper.py +++ b/Rich/RichMirrCombinFit/python/RichMirrCombinFitWrapper.py @@ -9,44 +9,71 @@ # granted to it by virtue of its status as an Intergovernmental Organization # # or submit itself to any jurisdiction. # ############################################################################### -import sys +import getopt import os +import sys from subprocess import * -import getopt -#print sys.argv[0:] +# print sys.argv[0:] -varOpts = getopt.getopt(sys.argv[1:], 'h:p:u:v:o:w:r:', [ - 'home=', 'pathToScripts=', 'userReleaseArea=', - 'setupProjectPanoptesVersion=', 'setupProjectPanoptesOptions=', 'workDir=', - 'rich=' -]) -#print varOpts +varOpts = getopt.getopt( + sys.argv[1:], + "h:p:u:v:o:w:r:", + [ + "home=", + "pathToScripts=", + "userReleaseArea=", + "setupProjectPanoptesVersion=", + "setupProjectPanoptesOptions=", + "workDir=", + "rich=", + ], +) +# print varOpts for varOptKey, varOptValue in varOpts[0]: - if varOptKey in ['-h', '--home']: + if varOptKey in ["-h", "--home"]: home = varOptValue - elif varOptKey in ['-p', '--pathToScripts']: + elif varOptKey in ["-p", "--pathToScripts"]: pathToScripts = varOptValue - elif varOptKey in ['-u', '--userReleaseArea']: + elif varOptKey in ["-u", "--userReleaseArea"]: userReleaseArea = varOptValue - elif varOptKey in ['-v', '--setupProjectPanoptesVersion']: + elif varOptKey in ["-v", "--setupProjectPanoptesVersion"]: setupProjectPanoptesVersion = varOptValue - elif varOptKey in ['-o', '--setupProjectPanoptesOptions']: + elif varOptKey in ["-o", "--setupProjectPanoptesOptions"]: setupProjectPanoptesOptions = varOptValue - elif varOptKey in ['-w', '--workDir']: + elif varOptKey in ["-w", "--workDir"]: workDir = varOptValue - elif varOptKey in ['-r', '--rich']: + elif varOptKey in ["-r", "--rich"]: rich = varOptValue p = Popen( - "export HOME=" + home + ";" + "source " + pathToScripts + "/LbLogin.sh;" - + "export User_release_area=" + userReleaseArea + ";" + - "source `which SetupProject.sh` Panoptes " + setupProjectPanoptesVersion - + " " + setupProjectPanoptesOptions + ";" + - "$RICHMIRRCOMBINFITROOT/$CMTCONFIG/RichMirrCombinFit.exe " + workDir + - "/Rich" + rich + "MirrCombinFit.conf " + rich + " > " + workDir + "/Rich" + - rich + "MirrCombinFit.out", + "export HOME=" + + home + + ";" + + "source " + + pathToScripts + + "/LbLogin.sh;" + + "export User_release_area=" + + userReleaseArea + + ";" + + "source `which SetupProject.sh` Panoptes " + + setupProjectPanoptesVersion + + " " + + setupProjectPanoptesOptions + + ";" + + "$RICHMIRRCOMBINFITROOT/$CMTCONFIG/RichMirrCombinFit.exe " + + workDir + + "/Rich" + + rich + + "MirrCombinFit.conf " + + rich + + " > " + + workDir + + "/Rich" + + rich + + "MirrCombinFit.out", shell=True, - executable="/bin/bash") + executable="/bin/bash", +) sts = os.waitpid(p.pid, 0) diff --git a/Rich/RichMirrCombinFit/src/DThetaFitter.h b/Rich/RichMirrCombinFit/src/DThetaFitter.h index d0a4f7fffae681bc0872557cd1dce17ac1d0f849..02a613c0122d142f00569e030461753fe9d2a0a4 100644 --- a/Rich/RichMirrCombinFit/src/DThetaFitter.h +++ b/Rich/RichMirrCombinFit/src/DThetaFitter.h @@ -31,9 +31,9 @@ class DThetaFitter { RooWorkspace* _wspace = nullptr; RooDataHist* _dThetaHist = nullptr; - double _dThetaMin{0}; - double _dThetaMax{0}; - int _fitShape{0}; + double _dThetaMin{ 0 }; + double _dThetaMax{ 0 }; + int _fitShape{ 0 }; void buildPdfBifurGauss( int backgroundOrder ); void buildPdfGauss( int backgroundOrder ); diff --git a/Rich/RichMirrCombinFit/src/FitSurf.h b/Rich/RichMirrCombinFit/src/FitSurf.h index d95a84e1666d6a94b5277b4c350f6d56b25dc30a..6d2ce57da837617c9b7ca687d4da027fc34271e7 100644 --- a/Rich/RichMirrCombinFit/src/FitSurf.h +++ b/Rich/RichMirrCombinFit/src/FitSurf.h @@ -63,7 +63,7 @@ public: return fitVal; } - int phiBins{0}; + int phiBins{ 0 }; }; // unified Gaussian Widths for all phi bins @@ -96,5 +96,5 @@ public: return fitVal; } - int phiBins{0}; + int phiBins{ 0 }; }; diff --git a/Rich/RichMirrCombinFit/src/MirrCombFitter.cpp b/Rich/RichMirrCombinFit/src/MirrCombFitter.cpp index 3b29e6574ed2111036949002dcef8e187f65e43c..15d3167bbf20523fb5d3de13bc94b7f77bb046bc 100644 --- a/Rich/RichMirrCombinFit/src/MirrCombFitter.cpp +++ b/Rich/RichMirrCombinFit/src/MirrCombFitter.cpp @@ -58,9 +58,7 @@ void MirrCombFitter::GetFitParams( TH2D* histo ) { FitSurface( false ); // unifyWidths == false else if ( m_combinFitMethod == 5 ) FitSurface( true ); // unifyWidths == true - else { - cout << "method not recognized" << endl; - } + else { cout << "method not recognized" << endl; } } //------------------------------------------------------------------------------ @@ -77,7 +75,7 @@ void MirrCombFitter::FitSurface( bool unifyWidths = false ) { if ( !unifyWidths ) { FitSurfBM* functorBM = new FitSurfBM( phiBins ); // The functor for independent Gaussian widths in each bin fitSurface = new TF2( "fitSurface", functorBM, &FitSurfBM::FitFcnBM, 0., 6.28, m_begRange, m_endRange, - 3 + phiBins * 5, "FitSurfBM", "FitFcnBM" ); + 3 + phiBins * 5, "FitSurfBM", "FitFcnBM" ); } else { corrUniWid = -phiBins + 1; // due to single unified sigma parameter (4) for BMUW, otherwise there are phiBins sigmas @@ -302,7 +300,7 @@ void MirrCombFitter::FitSurface( bool unifyWidths = false ) { } // Get MirrComb - regex combNameRegex{"p[\\d]{2}s[\\d]{2}"}; + regex combNameRegex{ "p[\\d]{2}s[\\d]{2}" }; smatch combNameSmatch; regex_search( histoName, combNameSmatch, combNameRegex ); string combName = combNameSmatch.str(); @@ -411,7 +409,7 @@ void MirrCombFitter::Fit2D( TGraphErrors* cleanPlot ) { } // Get MirrComb - regex combNameRegex{"p[\\d]{2}s[\\d]{2}"}; + regex combNameRegex{ "p[\\d]{2}s[\\d]{2}" }; smatch combNameSmatch; regex_search( histoName, combNameSmatch, combNameRegex ); string combName = combNameSmatch.str(); diff --git a/Rich/RichMirrCombinFit/src/RichMirrCombFit.h b/Rich/RichMirrCombinFit/src/RichMirrCombFit.h index 043418129339fa735a474f77427b5c68631f0e98..4b35f3e382fe5379298d1f49e117c47b7c1a128e 100644 --- a/Rich/RichMirrCombinFit/src/RichMirrCombFit.h +++ b/Rich/RichMirrCombinFit/src/RichMirrCombFit.h @@ -54,39 +54,39 @@ protected: void CreateMapCombNameCombObj(); // ATTENTION: for observability, please any future // additions below keep in the alphabetic order !!! - int m_backgroundOrder{0}; - double m_begRange{0}; - int m_combinFitMethod{0}; - double m_deltaThetaWindow{0}; - double m_endRange{0}; - bool m_fixSinusoidShift{0}; + int m_backgroundOrder{ 0 }; + double m_begRange{ 0 }; + int m_combinFitMethod{ 0 }; + double m_deltaThetaWindow{ 0 }; + double m_endRange{ 0 }; + bool m_fixSinusoidShift{ 0 }; std::vector<std::string> m_histoNames; std::string m_inputHistosFile; - int m_iterNumber{0}; + int m_iterNumber{ 0 }; MapCombNameCombObj m_mapCombNameCombObj; - int m_minAverageBinPop{0}; - double m_minFracPhiBinsPopulated{0}; + int m_minAverageBinPop{ 0 }; + double m_minFracPhiBinsPopulated{ 0 }; std::string m_mirrCombinFitResultsFile; std::vector<std::string> m_mirrCombsSubset; - double m_nominSigmRad{0}; - double m_nominalResolutionSigma{0}; + double m_nominSigmRad{ 0 }; + double m_nominalResolutionSigma{ 0 }; std::string m_outputResultsFile; - int m_phiBinFactor{0}; + int m_phiBinFactor{ 0 }; std::string m_plotDir; - int m_plotOutputLevel{0}; + int m_plotOutputLevel{ 0 }; std::string m_rN; std::string m_richOptsFile; - double m_sinusoidShift{0}; - double m_stopSigmaFraction{0}; - int m_stopToleranceMode{0}; - double m_stopTolerance{0}; + double m_sinusoidShift{ 0 }; + double m_stopSigmaFraction{ 0 }; + int m_stopToleranceMode{ 0 }; + double m_stopTolerance{ 0 }; std::string m_tiltName; std::string m_timeStamp; - bool m_useGlobalFitMean{0}; + bool m_useGlobalFitMean{ 0 }; std::string m_variant; - double m_warningFactor{0}; + double m_warningFactor{ 0 }; std::string m_workDir; - bool m_zeroGlobalFitMean{0}; + bool m_zeroGlobalFitMean{ 0 }; }; std::ostream& operator<<( std::ostream& out, const RichMirrCombFit& fit ); diff --git a/Rich/RichMirrorAlignmentGanga/files/EventSelectorInput_R1SelMd_Collision10.py b/Rich/RichMirrorAlignmentGanga/files/EventSelectorInput_R1SelMd_Collision10.py index 810435d460562073f14d2cd27ce7e4d300e5f53b..6c3c52bc013b1e24410094355ee1802010a29c6a 100644 --- a/Rich/RichMirrorAlignmentGanga/files/EventSelectorInput_R1SelMd_Collision10.py +++ b/Rich/RichMirrorAlignmentGanga/files/EventSelectorInput_R1SelMd_Collision10.py @@ -27,5 +27,5 @@ EventSelector().Input = [ " DATAFILE='LFN:/lhcb/user/t/thampson/2010_06/9455/9455929/AlignEventsRich1.dst' TYP='POOL_ROOTTREE' OPT='READ'", " DATAFILE='LFN:/lhcb/user/t/thampson/2010_06/9455/9455930/AlignEventsRich1.dst' TYP='POOL_ROOTTREE' OPT='READ'", " DATAFILE='LFN:/lhcb/user/t/thampson/2010_06/9455/9455931/AlignEventsRich1.dst' TYP='POOL_ROOTTREE' OPT='READ'", - " DATAFILE='LFN:/lhcb/user/t/thampson/2010_06/9455/9455932/AlignEventsRich1.dst' TYP='POOL_ROOTTREE' OPT='READ'" + " DATAFILE='LFN:/lhcb/user/t/thampson/2010_06/9455/9455932/AlignEventsRich1.dst' TYP='POOL_ROOTTREE' OPT='READ'", ] diff --git a/Rich/RichMirrorAlignmentGanga/files/HPD_xml_zeros/Conditions/Rich1/Alignment/HPDsP1.xml b/Rich/RichMirrorAlignmentGanga/files/HPD_xml_zeros/Conditions/Rich1/Alignment/HPDsP1.xml index 5bcd41173cb30e01e3db7330f05b46e8cd86c164..3260790e92ada122ed129dcf75d5eb1f6bfe201d 100644 --- a/Rich/RichMirrorAlignmentGanga/files/HPD_xml_zeros/Conditions/Rich1/Alignment/HPDsP1.xml +++ b/Rich/RichMirrorAlignmentGanga/files/HPD_xml_zeros/Conditions/Rich1/Alignment/HPDsP1.xml @@ -600,4 +600,3 @@ </condition> </DDDB> - diff --git a/Rich/RichMirrorAlignmentGanga/files/HPD_xml_zeros/Conditions/Rich2/Alignment/HPDsP0.xml b/Rich/RichMirrorAlignmentGanga/files/HPD_xml_zeros/Conditions/Rich2/Alignment/HPDsP0.xml index 9729113854631c213899a22bd184df3b8c02cb68..7a9c9e8c9d9777468dc844ba0d2fa0c6759151ed 100644 --- a/Rich/RichMirrorAlignmentGanga/files/HPD_xml_zeros/Conditions/Rich2/Alignment/HPDsP0.xml +++ b/Rich/RichMirrorAlignmentGanga/files/HPD_xml_zeros/Conditions/Rich2/Alignment/HPDsP0.xml @@ -876,4 +876,3 @@ </condition> </DDDB> - diff --git a/Rich/RichMirrorAlignmentGanga/files/HPD_xml_zeros/Conditions/Rich2/Alignment/HPDsP1.xml b/Rich/RichMirrorAlignmentGanga/files/HPD_xml_zeros/Conditions/Rich2/Alignment/HPDsP1.xml index b657849ff70fd94d644ba1d0fa1e73d4012e915d..479920283b3407e55dbe6ed7193b8c0e4a38e791 100644 --- a/Rich/RichMirrorAlignmentGanga/files/HPD_xml_zeros/Conditions/Rich2/Alignment/HPDsP1.xml +++ b/Rich/RichMirrorAlignmentGanga/files/HPD_xml_zeros/Conditions/Rich2/Alignment/HPDsP1.xml @@ -876,4 +876,3 @@ </condition> </DDDB> - diff --git a/Rich/RichMirrorAlignmentGanga/files/LHCbCollision11Beam3500GeV-VeloClosed-MagDownRealData91000000DST_R1Selv10.py b/Rich/RichMirrorAlignmentGanga/files/LHCbCollision11Beam3500GeV-VeloClosed-MagDownRealData91000000DST_R1Selv10.py index 419dc90fe548ccdaff944777882764efadafeb59..c2530bb1054069e3fe1bea0cff3c7686e735111f 100644 --- a/Rich/RichMirrorAlignmentGanga/files/LHCbCollision11Beam3500GeV-VeloClosed-MagDownRealData91000000DST_R1Selv10.py +++ b/Rich/RichMirrorAlignmentGanga/files/LHCbCollision11Beam3500GeV-VeloClosed-MagDownRealData91000000DST_R1Selv10.py @@ -10,6 +10,7 @@ ############################################################################### from Gaudi.Configuration import * + EventSelector().Input = [ "DATAFILE='LFN:/lhcb/user/t/thampson/2011_05/20065/20065498/AlignEventsRich1.dst' TYP='POOL_ROOTTREE' OPT='READ'", "DATAFILE='LFN:/lhcb/user/t/thampson/2011_05/20065/20065507/AlignEventsRich1.dst' TYP='POOL_ROOTTREE' OPT='READ'", @@ -97,5 +98,5 @@ EventSelector().Input = [ "DATAFILE='LFN:/lhcb/user/t/thampson/2011_05/20066/20066105/AlignEventsRich1.dst' TYP='POOL_ROOTTREE' OPT='READ'", "DATAFILE='LFN:/lhcb/user/t/thampson/2011_05/20066/20066114/AlignEventsRich1.dst' TYP='POOL_ROOTTREE' OPT='READ'", "DATAFILE='LFN:/lhcb/user/t/thampson/2011_05/20066/20066118/AlignEventsRich1.dst' TYP='POOL_ROOTTREE' OPT='READ'", - "DATAFILE='LFN:/lhcb/user/t/thampson/2011_05/20066/20066128/AlignEventsRich1.dst' TYP='POOL_ROOTTREE' OPT='READ'" + "DATAFILE='LFN:/lhcb/user/t/thampson/2011_05/20066/20066128/AlignEventsRich1.dst' TYP='POOL_ROOTTREE' OPT='READ'", ] diff --git a/Rich/RichMirrorAlignmentGanga/files/LHCbCollision11Beam3500GeV-VeloClosed-MagDownRealData91000000DST_R2Selv10.py b/Rich/RichMirrorAlignmentGanga/files/LHCbCollision11Beam3500GeV-VeloClosed-MagDownRealData91000000DST_R2Selv10.py index 52ad709d19f5a2b99e22262fc55bcfc687466a55..fb722d0840328dd215bf21dd48b838d9aa977363 100644 --- a/Rich/RichMirrorAlignmentGanga/files/LHCbCollision11Beam3500GeV-VeloClosed-MagDownRealData91000000DST_R2Selv10.py +++ b/Rich/RichMirrorAlignmentGanga/files/LHCbCollision11Beam3500GeV-VeloClosed-MagDownRealData91000000DST_R2Selv10.py @@ -10,6 +10,7 @@ ############################################################################### from Gaudi.Configuration import * + EventSelector().Input = [ "DATAFILE='LFN:/lhcb/user/t/thampson/2011_05/20068/20068113/AlignEventsRich2.dst' TYP='POOL_ROOTTREE' OPT='READ'", "DATAFILE='LFN:/lhcb/user/t/thampson/2011_05/20068/20068118/AlignEventsRich2.dst' TYP='POOL_ROOTTREE' OPT='READ'", @@ -99,5 +100,5 @@ EventSelector().Input = [ "DATAFILE='LFN:/lhcb/user/t/thampson/2011_05/20068/20068734/AlignEventsRich2.dst' TYP='POOL_ROOTTREE' OPT='READ'", "DATAFILE='LFN:/lhcb/user/t/thampson/2011_05/20068/20068745/AlignEventsRich2.dst' TYP='POOL_ROOTTREE' OPT='READ'", "DATAFILE='LFN:/lhcb/user/t/thampson/2011_05/20068/20068750/AlignEventsRich2.dst' TYP='POOL_ROOTTREE' OPT='READ'", - "DATAFILE='LFN:/lhcb/user/t/thampson/2011_05/20068/20068761/AlignEventsRich2.dst' TYP='POOL_ROOTTREE' OPT='READ'" + "DATAFILE='LFN:/lhcb/user/t/thampson/2011_05/20068/20068761/AlignEventsRich2.dst' TYP='POOL_ROOTTREE' OPT='READ'", ] diff --git a/Rich/RichMirrorAlignmentGanga/files/MagCoeffs/Rich1FixedMirrCoeff_sec_zerYnegZ_1.0mr.txt b/Rich/RichMirrorAlignmentGanga/files/MagCoeffs/Rich1FixedMirrCoeff_sec_zerYnegZ_1.0mr.txt index d468f1c0b19cced142ac65b4ee289d6be7840451..2c899fd815b4fca1a07c30472687c8f213856fbc 100644 --- a/Rich/RichMirrorAlignmentGanga/files/MagCoeffs/Rich1FixedMirrCoeff_sec_zerYnegZ_1.0mr.txt +++ b/Rich/RichMirrorAlignmentGanga/files/MagCoeffs/Rich1FixedMirrCoeff_sec_zerYnegZ_1.0mr.txt @@ -13,4 +13,4 @@ 0308 0.0 0.858 0309 0.0 0.858 0310 0.0 0.858 -0311 0.0 0.858 \ No newline at end of file +0311 0.0 0.858 diff --git a/Rich/RichMirrorAlignmentGanga/files/MagCoeffs/Rich1FixedMirrCoeff_sec_zerYposZ_1.0mr.txt b/Rich/RichMirrorAlignmentGanga/files/MagCoeffs/Rich1FixedMirrCoeff_sec_zerYposZ_1.0mr.txt index 3004573f762cc49133cf3aac0bbb4e0f6325092e..77882d8cc998dfcdafc4d11f46efc56c93be899a 100644 --- a/Rich/RichMirrorAlignmentGanga/files/MagCoeffs/Rich1FixedMirrCoeff_sec_zerYposZ_1.0mr.txt +++ b/Rich/RichMirrorAlignmentGanga/files/MagCoeffs/Rich1FixedMirrCoeff_sec_zerYposZ_1.0mr.txt @@ -13,4 +13,4 @@ 0308 0.0 0.858 0309 0.0 0.858 0310 0.0 0.858 -0311 0.0 0.858 \ No newline at end of file +0311 0.0 0.858 diff --git a/Rich/RichMirrorAlignmentGanga/files/MagCoeffs/Rich2FixedMirrCoeff_sec_negYzerZ_1.0mr.txt b/Rich/RichMirrorAlignmentGanga/files/MagCoeffs/Rich2FixedMirrCoeff_sec_negYzerZ_1.0mr.txt index 4a9623cb5a7bc773a143a264f6ebca8be07e46c0..7af3f710aabdcb0bbb01f1313ce69b9afe2bfa62 100644 --- a/Rich/RichMirrorAlignmentGanga/files/MagCoeffs/Rich2FixedMirrCoeff_sec_negYzerZ_1.0mr.txt +++ b/Rich/RichMirrorAlignmentGanga/files/MagCoeffs/Rich2FixedMirrCoeff_sec_negYzerZ_1.0mr.txt @@ -168,4 +168,3 @@ 5439 -1.000 0 5538 -1.000 0 5539 -1.000 0 - diff --git a/Rich/RichMirrorAlignmentGanga/files/MagCoeffs/Rich2FixedMirrCoeff_sec_posYzerZ_1.0mr.txt b/Rich/RichMirrorAlignmentGanga/files/MagCoeffs/Rich2FixedMirrCoeff_sec_posYzerZ_1.0mr.txt index 4a9623cb5a7bc773a143a264f6ebca8be07e46c0..7af3f710aabdcb0bbb01f1313ce69b9afe2bfa62 100644 --- a/Rich/RichMirrorAlignmentGanga/files/MagCoeffs/Rich2FixedMirrCoeff_sec_posYzerZ_1.0mr.txt +++ b/Rich/RichMirrorAlignmentGanga/files/MagCoeffs/Rich2FixedMirrCoeff_sec_posYzerZ_1.0mr.txt @@ -168,4 +168,3 @@ 5439 -1.000 0 5538 -1.000 0 5539 -1.000 0 - diff --git a/Rich/RichMirrorAlignmentGanga/job/Brunel_Ganga_RichAlignMoni.py b/Rich/RichMirrorAlignmentGanga/job/Brunel_Ganga_RichAlignMoni.py index ccd5c4414a4113d940c60544e44a6221470b5cdf..e2bd8777ba85536733702eb660d1510a8d53937d 100644 --- a/Rich/RichMirrorAlignmentGanga/job/Brunel_Ganga_RichAlignMoni.py +++ b/Rich/RichMirrorAlignmentGanga/job/Brunel_Ganga_RichAlignMoni.py @@ -9,9 +9,9 @@ # or submit itself to any jurisdiction. # ############################################################################### -#=============================================================================== +# =============================================================================== # Example ganga job submission file -#=============================================================================== +# =============================================================================== # # Set ganga environment first with (e.g. lxplus) # > GangaEnv @@ -32,7 +32,7 @@ # but in this way you will have the overhead of starting Ganga # for each job you submit. # -#=============================================================================== +# =============================================================================== # # For more information on ganga see http://cern.ch/ganga # @@ -48,9 +48,10 @@ # > help(Dirac) # For more information on the Dirac backend # -#=============================================================================== +# =============================================================================== import os from subprocess import * + """ setupProjectPanoptesVersion = "HEAD" setupProjectPanoptesOptions = "--nightly lhcb2" @@ -69,124 +70,123 @@ env_var_settings_txt = open( "env_var_settings.txt") RICHMIRRORALIGNMENTGANGAROOT = env_var_settings_txt.readline().strip() env_var_settings_txt.close() """ -RICHMIRRORALIGNMENTGANGAROOT = '/afs/cern.ch/user/a/asolomin/public/rich_align/Panoptes_HEAD/Rich/RichMirrorAlignmentGanga' -panoptesOptsPath = (RICHMIRRORALIGNMENTGANGAROOT + '/options') +RICHMIRRORALIGNMENTGANGAROOT = "/afs/cern.ch/user/a/asolomin/public/rich_align/Panoptes_HEAD/Rich/RichMirrorAlignmentGanga" +panoptesOptsPath = RICHMIRRORALIGNMENTGANGAROOT + "/options" -#thisCase = '2008_OnDIGI_WithMC_False' -#thisCase = '2008_OnDST_WithMC_True_reco' -#thisCase = '2008_OnDST_WithMC_True_total' -#thisCase = '2008_OnDST_WithMC_True_production' -thisCase = '2010-Collisions' +# thisCase = '2008_OnDIGI_WithMC_False' +# thisCase = '2008_OnDST_WithMC_True_reco' +# thisCase = '2008_OnDST_WithMC_True_total' +# thisCase = '2008_OnDST_WithMC_True_production' +thisCase = "2010-Collisions" -print thisCase +print(thisCase) brunel = Brunel() -#brunel.version = "HEAD" -#brunel.setupProjectOptions = '--nightly lhcb-prerelease' -brunel.setupProjectOptions = '--use-grid' +# brunel.version = "HEAD" +# brunel.setupProjectOptions = '--nightly lhcb-prerelease' +brunel.setupProjectOptions = "--use-grid" brunel.optsfile = [ - File(panoptesOptsPath + '/Brunel_RichAlignMoni_' + thisCase + '-DST.py'), + File(panoptesOptsPath + "/Brunel_RichAlignMoni_" + thisCase + "-DST.py"), # File( panoptesOptsPath+'/'+thisCase+'_test.py') ] # File( panoptesOptsPath+'/2008-Files_minbias_digi.py') ] # File( '/afs/cern.ch/user/t/thampson/public/2010-files/MagDownPFN.py') ] - File('Rich2Events.py') -] #//May have to change manually to Rich1Events -#------------------------------------------------------------------------------- -#------------------------------------------------------------------------------- + File("Rich2Events.py"), +] # //May have to change manually to Rich1Events +# ------------------------------------------------------------------------------- +# ------------------------------------------------------------------------------- # Make a new job object for Brunel -#------------------------------------------------------------------------------- +# ------------------------------------------------------------------------------- j = Job() j.application = brunel -#------------------------------------------------------------------------------- +# ------------------------------------------------------------------------------- # Define name for identifying the job (this name appears in the ganga job list) -#------------------------------------------------------------------------------- -j.name = 'BrunelOnDst' -#------------------------------------------------------------------------------- +# ------------------------------------------------------------------------------- +j.name = "BrunelOnDst" +# ------------------------------------------------------------------------------- # The job configuration -#------------------------------------------------------------------------------- +# ------------------------------------------------------------------------------- # Define the configuration file(s) to use # Extra options # Appended to the end of the main options to override default settings -#j.application.extraopts = '' -#------------------------------------------------------------------------------- +# j.application.extraopts = '' +# ------------------------------------------------------------------------------- -#------------------------------------------------------------------------------- +# ------------------------------------------------------------------------------- # Input data # Can either be specified in the main configuration files (DaVinci.py etc.) or # locally here as an LHCbDataset -#------------------------------------------------------------------------------- -#j.inputdata = LHCbDataset( files = [ +# ------------------------------------------------------------------------------- +# j.inputdata = LHCbDataset( files = [ #'LFN:/lhcb/production/DC06/phys-v2-lumi2/00001820/DIGI/0000/00001820_00000001_4.digi' ] ) -#------------------------------------------------------------------------------- +# ------------------------------------------------------------------------------- # Define a job splitter (very useful for many input data files) -#------------------------------------------------------------------------------- +# ------------------------------------------------------------------------------- # Use a single job, no splitting j.splitter = None # Split jobs into 1 input file per job. max of 5 files in total -#j.splitter = SplitByFiles ( filesPerJob = 1, maxFiles = 5 ) +# j.splitter = SplitByFiles ( filesPerJob = 1, maxFiles = 5 ) # This Splitter will query the Logical File Catalog (LFC) to find # at which sites a particular file is stored. Subjobs will be created # so that all the data required for each subjob is stored in # at least one common location. This prevents the submission of jobs that # are unrunnable due to data availability. # Useful when using the Dirac backend (see below) -#j.splitter = DiracSplitter ( filesPerJob = 1, maxFiles = 5 ) -#------------------------------------------------------------------------------- +# j.splitter = DiracSplitter ( filesPerJob = 1, maxFiles = 5 ) +# ------------------------------------------------------------------------------- j.splitter = SplitByFiles(filesPerJob=3, maxFiles=200) # Good for '1nh' j.splitter = SplitByFiles(filesPerJob=1, maxFiles=1) # Good for '1nh' -#j.splitter = SplitByFiles( filesPerJob = 3, maxFiles = 400 ) # Good for '1nh' -#j.splitter = SplitByFiles( filesPerJob = 3, maxFiles = 1000 ) # Good for '1nh' +# j.splitter = SplitByFiles( filesPerJob = 3, maxFiles = 400 ) # Good for '1nh' +# j.splitter = SplitByFiles( filesPerJob = 3, maxFiles = 1000 ) # Good for '1nh' -#------------------------------------------------------------------------------- +# ------------------------------------------------------------------------------- # Job merging (merge output from sub-jobs from job splitter, if used) -#------------------------------------------------------------------------------- +# ------------------------------------------------------------------------------- # No merging -#j.merger = None +# j.merger = None # Root file merging. See help( RootMerger ) for more details -#j.merger = RootMerger( files = ['histos.root'], ignorefailed = True ) +# j.merger = RootMerger( files = ['histos.root'], ignorefailed = True ) # SmartMerger - Able to handle various file formats (including root files) # See help( SmartMerger ) for more details -#j.merger = SmartMerger( files = ['histos.root'], ignorefailed = True ) -#------------------------------------------------------------------------------- +# j.merger = SmartMerger( files = ['histos.root'], ignorefailed = True ) +# ------------------------------------------------------------------------------- j.merger = SmartMerger( - files=['RichRecQCHistos_' + thisCase + '.root'], - ignorefailed=True, - overwrite=True) + files=["RichRecQCHistos_" + thisCase + ".root"], ignorefailed=True, overwrite=True +) -#------------------------------------------------------------------------------- +# ------------------------------------------------------------------------------- # Add here any special input files. Normally not needed. -#------------------------------------------------------------------------------- +# ------------------------------------------------------------------------------- j.inputsandbox = [] -#------------------------------------------------------------------------------- +# ------------------------------------------------------------------------------- -#------------------------------------------------------------------------------- +# ------------------------------------------------------------------------------- # Define where to run -#------------------------------------------------------------------------------- +# ------------------------------------------------------------------------------- # Run interactively on the local machine -#j.backend = Interactive() +# j.backend = Interactive() # Run directly on the local machine, but in the background j.backend = Local() # Submit to an LSF batch system, using the 8nm queue -#j.backend = LSF( queue = '1nh') +# j.backend = LSF( queue = '1nh') # Submit to a condor batch system -#j.backend = Condor() +# j.backend = Condor() # Submit to a PBS batch system -#j.backend = PBS() +# j.backend = PBS() # Submit to the grid. -#j.backend = Dirac() -#------------------------------------------------------------------------------- +# j.backend = Dirac() +# ------------------------------------------------------------------------------- -#------------------------------------------------------------------------------- +# ------------------------------------------------------------------------------- # Submit the job -#------------------------------------------------------------------------------- +# ------------------------------------------------------------------------------- j.submit() -#------------------------------------------------------------------------------- +# ------------------------------------------------------------------------------- diff --git a/Rich/RichMirrorAlignmentGanga/job/RichMirrorAlignment.py b/Rich/RichMirrorAlignmentGanga/job/RichMirrorAlignment.py index c2a81dd1cbcf92c4c42f01598d9c626bd9be1d02..ad0590cfadf0ef5ac5a66d1fdf10379d29a04239 100644 --- a/Rich/RichMirrorAlignmentGanga/job/RichMirrorAlignment.py +++ b/Rich/RichMirrorAlignmentGanga/job/RichMirrorAlignment.py @@ -25,54 +25,55 @@ # See the TWiki and keep it up-to-date!! # https://twiki.cern.ch/twiki/bin/view/LHCb/LHCbRichMirrorAlign -print "Python will give a warning about the line 'from Communicator import *', either during compiling or running if not compiled." -print "This does not matter for offline. For online it also should work, python just doesn't like it." - +print( + "Python will give a warning about the line 'from Communicator import *', either during compiling or running if not compiled." +) +print( + "This does not matter for offline. For online it also should work, python just doesn't like it." +) + +import builtins import distutils +import importlib +import math import os import re import shutil import sys -import math - from distutils import dir_util from os.path import expandvars from subprocess import * -from time import sleep -from time import time -from time import gmtime, strftime - -import importlib -import __builtin__ +from time import gmtime, sleep, strftime, time -#=============================================================================== +# =============================================================================== # defs -#=============================================================================== +# =============================================================================== # stdReport returns stdout and stderr from Popen.communicate() def stdReport(stdout, stderr): - print "The shell script gave some STANDARD OUTPUT:" - print stdout + print("The shell script gave some STANDARD OUTPUT:") + print(stdout) if stderr: - print "The shell script also gave some STANDARD ERROR:" - print stderr + print("The shell script also gave some STANDARD ERROR:") + print(stderr) else: - print "The shell script ran fine." + print("The shell script ran fine.") -#=============================================================================== +# =============================================================================== # exists checks to see if the name is in the locals/globals/builtin OR in obj if obj is not none) def exists(name, obj=None): if obj is None: - return (name in sys._getframe(1).f_locals # caller's locals - or name in sys._getframe(1).f_globals # caller's globals - or name in vars(__builtin__) # built-in - ) + return ( + name in sys._getframe(1).f_locals # caller's locals + or name in sys._getframe(1).f_globals # caller's globals + or name in vars(__builtin__) # built-in + ) else: return hasattr(obj, name) -#=============================================================================== +# =============================================================================== # staticVar reads in variables from a settings file def staticVar(varname, value): def decorate(func): @@ -86,17 +87,17 @@ def staticVar(varname, value): def getSettingsFile(InfoStr): if InfoStr in getSettingsFile.VarName: return getSettingsFile.VarName[InfoStr] - #print "InfoStr: %s" % InfoStr; - #SettingsFile = '/path/to/%s_python_file.py' % InfoStr - #SettingsFile = '/home/pnaik/cmtuser/Panoptes_v5r2/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/RMA_%s.py' % InfoStr - SettingsFile = '%s' % InfoStr - print "SettingsFile: %s" % SettingsFile + # print "InfoStr: %s" % InfoStr; + # SettingsFile = '/path/to/%s_python_file.py' % InfoStr + # SettingsFile = '/home/pnaik/cmtuser/Panoptes_v5r2/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/RMA_%s.py' % InfoStr + SettingsFile = "%s" % InfoStr + print(("SettingsFile: %s" % SettingsFile)) directory, filename = os.path.split(SettingsFile) - #print "directory: %s" % directory - #print "filename: %s" % filename + # print "directory: %s" % directory + # print "filename: %s" % filename name, extension = os.path.splitext(filename) - #print "name: %s" % name - #print "extension: %s" % extension + # print "name: %s" % name + # print "extension: %s" % extension sys.path.insert(1, directory) VarName = importlib.import_module(name) sys.path.remove(directory) @@ -109,15 +110,15 @@ def getSettingsFile(InfoStr): def getPatchFile(InfoStr): if InfoStr in getPatchFile.PatchName: return getPatchFile.PatchName[InfoStr] - #print "InfoStr: %s" % InfoStr; - PatchFile = '%s' % InfoStr - print "PatchFile: %s" % PatchFile + # print "InfoStr: %s" % InfoStr; + PatchFile = "%s" % InfoStr + print(("PatchFile: %s" % PatchFile)) directory, filename = os.path.split(PatchFile) - #print "directory: %s" % directory - #print "filename: %s" % filename + # print "directory: %s" % directory + # print "filename: %s" % filename name, extension = os.path.splitext(filename) - #print "name: %s" % name - #print "extension: %s" % extension + # print "name: %s" % name + # print "extension: %s" % extension sys.path.insert(1, directory) PatchName = importlib.import_module(name) sys.path.remove(directory) @@ -125,14 +126,15 @@ def getPatchFile(InfoStr): return PatchName -#=============================================================================== +# =============================================================================== # wait_until_exists is currently NOT USED as far as PN knows # it only shows up in rm_subjobs_except_0_last def wait_until_exists(j, filename, timeout=10 * 60, sleep_period=3): - print 'RMAG is in wait_until_exists' + print("RMAG is in wait_until_exists") import os from time import sleep - while (not (os.path.exists(filename)) and (timeout > 0)): + + while not (os.path.exists(filename)) and (timeout > 0): sleep(sleep_period) timeout -= sleep_period if timeout < 0: @@ -140,43 +142,53 @@ def wait_until_exists(j, filename, timeout=10 * 60, sleep_period=3): return True -#=============================================================================== +# =============================================================================== # rm_subjobs_except_0_last is currently NOT USED as far as PN knows -def rm_subjobs_except_0_last(j, - rootFile, - brunelVer, - backEnd='dirac', - timeout=10 * 60, - sleep_period=3): - print 'RMAG is in rm_subjobs_except_0_last' +def rm_subjobs_except_0_last( + j, rootFile, brunelVer, backEnd="dirac", timeout=10 * 60, sleep_period=3 +): + print("RMAG is in rm_subjobs_except_0_last") global wait_until_exists sjLast = len(j.subjobs.ids()) - 1 for sj in j.subjobs: - - if (not (sj.status in ['failed', 'killed'])): - if ((backEnd == 'dirac' and wait_until_exists( - sj, sj.outputdir + 'std.out', timeout, sleep_period) - and wait_until_exists(sj, sj.outputdir + 'stdout', timeout, - sleep_period) - and wait_until_exists( - sj, sj.outputdir + 'Step1_Ganga_Brunel_' + brunelVer + - '.log', timeout, sleep_period)) or - (backEnd != 'dirac' and wait_until_exists( - sj, sj.outputdir + '__jobstatus__', timeout, sleep_period) - and wait_until_exists(sj, sj.outputdir + '__syslog__', - timeout, sleep_period) - and wait_until_exists(sj, sj.outputdir + 'stderr', timeout, - sleep_period) - and wait_until_exists(sj, sj.outputdir + 'stdout', timeout, - sleep_period))): + if not (sj.status in ["failed", "killed"]): + if ( + backEnd == "dirac" + and wait_until_exists( + sj, sj.outputdir + "std.out", timeout, sleep_period + ) + and wait_until_exists( + sj, sj.outputdir + "stdout", timeout, sleep_period + ) + and wait_until_exists( + sj, + sj.outputdir + "Step1_Ganga_Brunel_" + brunelVer + ".log", + timeout, + sleep_period, + ) + ) or ( + backEnd != "dirac" + and wait_until_exists( + sj, sj.outputdir + "__jobstatus__", timeout, sleep_period + ) + and wait_until_exists( + sj, sj.outputdir + "__syslog__", timeout, sleep_period + ) + and wait_until_exists( + sj, sj.outputdir + "stderr", timeout, sleep_period + ) + and wait_until_exists( + sj, sj.outputdir + "stdout", timeout, sleep_period + ) + ): sjId = sj.id - if (sjId != 0 and sjId != sjLast): - j.peek('../' + str(sjId), 'rm -rf') + if sjId != 0 and sjId != sjLast: + j.peek("../" + str(sjId), "rm -rf") else: - sj.peek('../output/' + rootFile, 'rm -f') + sj.peek("../output/" + rootFile, "rm -f") -#=============================================================================== +# =============================================================================== # create_coeff_calibration_xml_files: using most recent Mirrors files, # manufacture from them modified Mirrors files # for evaluation of current magnification coefficients @@ -184,22 +196,22 @@ def rm_subjobs_except_0_last(j, # Paras changed this to take in the richDetector as input, # as in a python program this variable would otherwise not be in this scope. # def create_coeff_calibration_xml_files( inputFile=None, coeffCalibrTilt=0.5 ) : -def create_coeff_calibration_xml_files(inputFile=None, - coeffCalibrTilt=0.5, - richDetector=2): - import sys +def create_coeff_calibration_xml_files( + inputFile=None, coeffCalibrTilt=0.5, richDetector=2 +): import re - import fpformat + import sys from array import array + import fpformat from lxml import etree # Important! You need SetupProject Ganga pytools # or some other method (maybe modify python path) to get this module - print 'RMAG is in create_coeff_calibration_xml_files' + print("RMAG is in create_coeff_calibration_xml_files") # first cut inputFile into two parts: inputFileLeftPart and inputFileRightPart # and separate them - inputFilePartsRE = re.compile(r'([a-zA-Z0-9_\.]+)(_i[0-9]+\.xml)') + inputFilePartsRE = re.compile(r"([a-zA-Z0-9_\.]+)(_i[0-9]+\.xml)") inputFileParts = inputFilePartsRE.match(inputFile) inputFileLeftPart = inputFileParts.group(1) inputFileRightPart = inputFileParts.group(2) @@ -209,25 +221,25 @@ def create_coeff_calibration_xml_files(inputFile=None, """ # # prepare dictionary of sign names - signName = dict({'-': 'neg', '+': 'pos'}) + signName = dict({"-": "neg", "+": "pos"}) # prepare dictionary of sign-to-shift - signToShift = dict({'-': -coeffCalibrTilt, '+': coeffCalibrTilt}) + signToShift = dict({"-": -coeffCalibrTilt, "+": coeffCalibrTilt}) # prepare dictionary of mirror type names - mirrTypeName = dict({'pri': 'Sph', 'sec': 'Sec'}) + mirrTypeName = dict({"pri": "Sph", "sec": "Sec"}) # prepare dictionary of total mirror numbers if richDetector == 2: - totMirrNum = dict({'pri': 56, 'sec': 40}) + totMirrNum = dict({"pri": 56, "sec": 40}) if richDetector == 1: - totMirrNum = dict({'pri': 4, 'sec': 16}) + totMirrNum = dict({"pri": 4, "sec": 16}) # prepare dictionary of rotation vector's term sequence number depending on axis - seqNum = dict({'Y': 1, 'Z': 2}) + seqNum = dict({"Y": 1, "Z": 2}) # prepare regular expression - rotRE = re.compile(r'[\-|\+]?[0-9]+\.?[0-9]*|[\-|\+]?\.[0-9]+') + rotRE = re.compile(r"[\-|\+]?[0-9]+\.?[0-9]*|[\-|\+]?\.[0-9]+") # such an expression matches e.g. all of the following: -000 +20. 2.000 +0005.9000 .0 -.98 +.30000 """ for f in [-000, +20., 2.000, +0005.9000, .0, -.98, +.30000] : @@ -247,19 +259,16 @@ def create_coeff_calibration_xml_files(inputFile=None, rotValues = [] ## parse the tree and create DOM of it - #docOriginal = parse( inputFile ) + # docOriginal = parse( inputFile ) # loop over types of mirrors - for mirrType in ['pri', 'sec']: - + for mirrType in ["pri", "sec"]: # loop over axes - for axis in ['Y', 'Z']: - + for axis in ["Y", "Z"]: # loop over signs - for sign in ['-', '+']: - + for sign in ["-", "+"]: ## make a working copy in order not to parse each anew - #doc = docOriginal + # doc = docOriginal parser = etree.XMLParser(remove_blank_text=True) RichAlignmentConditions = etree.parse(inputFile, parser) """ @@ -268,24 +277,30 @@ def create_coeff_calibration_xml_files(inputFile=None, # loop over all mirrors of current type (primary/secondary) # total numbers of primary (spheric) and secondary (flat) mirrors are different for mirrNum in range(totMirrNum[mirrType]): - # array for matches in float - floatRotValues = array('f') + floatRotValues = array("f") # Different xml alignment names for the two Rich detectors - if (richDetector == 1): + if richDetector == 1: # store the whole element in dRotXYZ dRotXYZ = RichAlignmentConditions.xpath( - "//condition[@name='" + mirrTypeName[mirrType] + - "Mirror" + str(mirrNum) + - "_Align']/paramVector[@name='dRotXYZ']") - - if (richDetector == 2): + "//condition[@name='" + + mirrTypeName[mirrType] + + "Mirror" + + str(mirrNum) + + "_Align']/paramVector[@name='dRotXYZ']" + ) + + if richDetector == 2: # store the whole element in dRotXYZ dRotXYZ = RichAlignmentConditions.xpath( - "//condition[@name='Rich" + str(richDetector) + - mirrTypeName[mirrType] + "Mirror" + str(mirrNum) + - "_Align']/paramVector[@name='dRotXYZ']") + "//condition[@name='Rich" + + str(richDetector) + + mirrTypeName[mirrType] + + "Mirror" + + str(mirrNum) + + "_Align']/paramVector[@name='dRotXYZ']" + ) """ print(etree.tostring(dRotXYZ[0], pretty_print=True)) print(etree.tostring(dRotXYZ[0], pretty_print=True, method="text")) @@ -293,8 +308,8 @@ def create_coeff_calibration_xml_files(inputFile=None, # # store all three rotation correction values in the floatRotValues (float) array rotValues = rotRE.findall( - etree.tostring( - dRotXYZ[0], pretty_print=True, method="text")) + etree.tostring(dRotXYZ[0], pretty_print=True, method="text") + ) """ for i in range (3) : print rotValues[i] @@ -311,82 +326,98 @@ def create_coeff_calibration_xml_files(inputFile=None, # with the value of one of them shifted by +/- coeffCalibrTilt mrad floatRotValues[seqNum[axis]] += signToShift[sign] - dRotXYZ[0].text = fpformat.fix( - floatRotValues[0], 5) + '*mrad ' + fpformat.fix( - floatRotValues[1], 5) + '*mrad ' + fpformat.fix( - floatRotValues[2], 5) + '*mrad' + dRotXYZ[0].text = ( + fpformat.fix(floatRotValues[0], 5) + + "*mrad " + + fpformat.fix(floatRotValues[1], 5) + + "*mrad " + + fpformat.fix(floatRotValues[2], 5) + + "*mrad" + ) """ print(etree.tostring(dRotXYZ[0], pretty_print=True, encoding='iso-8859-1')) """ # - if axis == 'Y': - signCombinName = signName[sign] + 'YzerZ' + if axis == "Y": + signCombinName = signName[sign] + "YzerZ" else: - signCombinName = 'zerY' + signName[sign] + 'Z' + signCombinName = "zerY" + signName[sign] + "Z" newXML_File = open( - inputFileLeftPart + '_' + mirrType + '_' + signCombinName + - inputFileRightPart, 'w') + inputFileLeftPart + + "_" + + mirrType + + "_" + + signCombinName + + inputFileRightPart, + "w", + ) newXML_File.write( etree.tostring( RichAlignmentConditions, - encoding='iso-8859-1', + encoding="iso-8859-1", xml_declaration=True, pretty_print=True, - with_tail=False)) + with_tail=False, + ) + ) newXML_File.close() -#=============================================================================== +# =============================================================================== # just_prettify def just_prettify(inputFile=None): - print 'RMAG is in just_prettify' + print("RMAG is in just_prettify") from lxml import etree + parser = etree.XMLParser(remove_blank_text=True) RichAlignmentConditions = etree.parse(inputFile, parser) - newXML_File = open(inputFile, 'w') + newXML_File = open(inputFile, "w") newXML_File.write( etree.tostring( RichAlignmentConditions, - encoding='iso-8859-1', + encoding="iso-8859-1", xml_declaration=True, pretty_print=True, - with_tail=False)) + with_tail=False, + ) + ) newXML_File.close() -#=============================================================================== +# =============================================================================== # mirroralign retrieves necessary environment variables, and does the work of alignment: def mirroralign(RichInfoSettings="Something_Went_Wrong"): # The next line is a legacy line from when this code was also being used for Online alignment - #def mirroralign(RichInfoSettings = "/home/pnaik/cmtuser/Panoptes_v5r5/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/RichMirrorAlignmentSettings.py") : - #def mirroralign() : - print 'RMAG is in mirroralign(' + RichInfoSettings + ')' - print strftime("%Y-%m-%d %H:%M:%S", gmtime()) - print "-------------------" + # def mirroralign(RichInfoSettings = "/home/pnaik/cmtuser/Panoptes_v5r5/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/RichMirrorAlignmentSettings.py") : + # def mirroralign() : + print(("RMAG is in mirroralign(" + RichInfoSettings + ")")) + print((strftime("%Y-%m-%d %H:%M:%S", gmtime()))) + print("-------------------") # Paras - NEW: get settings from file, put them into RichInfo, instead of expecting them to already be in locals()... - print "RichInfoSettings: %s" % RichInfoSettings + print(("RichInfoSettings: %s" % RichInfoSettings)) RichInfo = getSettingsFile(RichInfoSettings) # OLD VERSION # Paras - eventually we want to pass this into the script somehow, to allow us to select the appropriate settings file # Paras - for now, if RichInfoName is already defined in globals() before we run this script then we will use that otherwise use the default # Paras - for now, RichInfoNameLocal should be the file name with full path information - #if (exists('RichInfoName')) : + # if (exists('RichInfoName')) : # print "RichInfoName: %s" % RichInfoName # RichInfoNameLocal = RichInfoName - #else : + # else : # #RichInfoNameLocal = "./RichMirrorAlignmentGanga_Collision10_settings_R2MD.py" # RichInfoNameLocal = "Something_Went_Wrong" # print "RichInfoNameLocal: %s" % RichInfoNameLocal - #RichInfo = getSettingsFile(RichInfoNameLocal) + # RichInfo = getSettingsFile(RichInfoNameLocal) RichInfoMembers = [ - attr for attr in dir(RichInfo) + attr + for attr in dir(RichInfo) if not callable(getattr(RichInfo, attr)) and not attr.startswith("__") ] - print "RichInfoMembers:" - print RichInfoMembers + print("RichInfoMembers:") + print(RichInfoMembers) # We no longer do HPD alignment, so the following is not important HPDiteration = 0 @@ -401,391 +432,416 @@ def mirroralign(RichInfoSettings="Something_Went_Wrong"): exec(key + " = RichInfo." + key) # Paras - check that what we need is among the local, global, and system variables now (of course, they should only be in locals()) - if (exists('workDir') == 0 or workDir == ""): + if exists("workDir") == 0 or workDir == "": workDir = "sorry, you must define your working directory !" exitFlag = True - if (exists('dDDB_tag') == 0): + if exists("dDDB_tag") == 0: dDDB_tag = "" - if (exists('condDB_tag') == 0): + if exists("condDB_tag") == 0: condDB_tag = "" - if (exists('date') == 0): + if exists("date") == 0: date = "" # note that you can set this one if you want to use # LocalCondDB_tag=localCondDB_tag instead of LocalCondDB_tag=CondDB_tag # And of course, I don't see LocalCondDB_tag actually being used anywhere in this script... candidate for deletion? - if (exists('localCondDB_tag') == 0): + if exists("localCondDB_tag") == 0: localCondDB_tag = "" - if (exists('setupProjectBrunelOpts') == 0): + if exists("setupProjectBrunelOpts") == 0: setupProjectBrunelOpts = "" - if (exists('eventSelectorInputFile') == 0 or eventSelectorInputFile == ""): - - if (exists('ioHelperInputFile') == 1 and not ioHelperInputFile == ""): + if exists("eventSelectorInputFile") == 0 or eventSelectorInputFile == "": + if exists("ioHelperInputFile") == 1 and not ioHelperInputFile == "": eventSelectorInputFile = ioHelperInputFile else: eventSelectorInputFile = "sorry, you must define your input !" exitFlag = True - if (exists('brunelVersion') == 0 or brunelVersion == ""): - brunelVersion = '' + if exists("brunelVersion") == 0 or brunelVersion == "": + brunelVersion = "" - if (exists('LHCbVersion') == 0 or LHCbVersion == ""): - LHCbVersion = '' + if exists("LHCbVersion") == 0 or LHCbVersion == "": + LHCbVersion = "" - if (exists('brunelEvtMax') == 0 or brunelEvtMax == ""): + if exists("brunelEvtMax") == 0 or brunelEvtMax == "": brunelEvtMax = "100" - if (exists('brunelPrintFreq') == 0 or brunelPrintFreq == ""): + if exists("brunelPrintFreq") == 0 or brunelPrintFreq == "": brunelPrintFreq = "10" - if (exists('brunelInitialInputType') == 0 or brunelInitialInputType == ""): + if exists("brunelInitialInputType") == 0 or brunelInitialInputType == "": brunelInitialInputType = "RAW" - if (exists('messageSvcOutputLevel') == 0 or messageSvcOutputLevel == ""): + if exists("messageSvcOutputLevel") == 0 or messageSvcOutputLevel == "": messageSvcOutputLevel = "7" - if (exists('splitFilesPerJob') == 0 or splitFilesPerJob == ""): + if exists("splitFilesPerJob") == 0 or splitFilesPerJob == "": splitFilesPerJob = 1 - if (exists('splitMaxFiles') == 0 or splitMaxFiles == ""): + if exists("splitMaxFiles") == 0 or splitMaxFiles == "": splitMaxFiles = 1 - if (exists('backEnd') == 0 or backEnd == ""): + if exists("backEnd") == 0 or backEnd == "": backEnd = "LSF_8nm" - if (exists('diracCPUTime') == 0 or diracCPUTime == ""): + if exists("diracCPUTime") == 0 or diracCPUTime == "": diracCPUTime = 12000 - if (exists('mirrCombinSubset') == 0 or mirrCombinSubset == ""): + if exists("mirrCombinSubset") == 0 or mirrCombinSubset == "": mirrCombinSubset = "17un18eq" - if (exists('thisCase') == 0): + if exists("thisCase") == 0: thisCase = "" - if (exists('dataVariant') == 0 or dataVariant == ""): + if exists("dataVariant") == 0 or dataVariant == "": dataVariant = "sorry, you must define your data variant !" exitFlag = True - if (exists('minAverageBinPop') == 0 or minAverageBinPop == ""): + if exists("minAverageBinPop") == 0 or minAverageBinPop == "": minAverageBinPop = 6.0 - if (exists('deltaThetaWindow') == 0 or deltaThetaWindow == ""): + if exists("deltaThetaWindow") == 0 or deltaThetaWindow == "": deltaThetaWindow = 4.0 - if (exists('coeffCalibrTilt') == 0 or coeffCalibrTilt == ""): + if exists("coeffCalibrTilt") == 0 or coeffCalibrTilt == "": coeffCalibrTilt = 0.3 - if (exists('useTruth') == 0): + if exists("useTruth") == 0: useTruth = "" - if (exists('useOffsetsFromMC') == 0 or useOffsetsFromMC == ""): + if exists("useOffsetsFromMC") == 0 or useOffsetsFromMC == "": useOffsetsFromMC = "false" - if (exists('verOffsetsFromMC') == 0): + if exists("verOffsetsFromMC") == 0: verOffsetsFromMC = "" - if (exists('usePremisaligned') == 0 or usePremisaligned == ""): + if exists("usePremisaligned") == 0 or usePremisaligned == "": usePremisaligned = "false" # leave empty unless needed for usePremisaligned - if (exists('verPremisaligned') == 0): + if exists("verPremisaligned") == 0: verPremisaligned = "" - if (exists('useSpecificAlignment') == 0 or useSpecificAlignment == ""): + if exists("useSpecificAlignment") == 0 or useSpecificAlignment == "": useSpecificAlignment = "false" # leave empty unless needed for useSpecificAlignment - if (exists('specificAlignment') == 0): + if exists("specificAlignment") == 0: specificAlignment = "" - if (exists('combinFitVariant') == 0 or combinFitVariant == ""): + if exists("combinFitVariant") == 0 or combinFitVariant == "": combinFitVariant = 3 - if (exists('maximumNumberOfIterations') == 0 - or maximumNumberOfIterations == ""): + if exists("maximumNumberOfIterations") == 0 or maximumNumberOfIterations == "": maximumNumberOfIterations = 8 - if (exists('startFromIteration') == 0 or startFromIteration == ""): + if exists("startFromIteration") == 0 or startFromIteration == "": startFromIteration = 0 - if (exists('richDetector') == 0 or richDetector == ""): + if exists("richDetector") == 0 or richDetector == "": richDetector = 2 - if (exists('magnifCoeffMode') == 0 or magnifCoeffMode == ""): + if exists("magnifCoeffMode") == 0 or magnifCoeffMode == "": magnifCoeffMode = 2 - if (exists('solutionMethod') == 0 or solutionMethod == ""): + if exists("solutionMethod") == 0 or solutionMethod == "": solutionMethod = 1 - if (exists('alignHPDs') == 0 or alignHPDs == ""): + if exists("alignHPDs") == 0 or alignHPDs == "": alignHPDs = "false" - if (exists('AddedDB') == 0): + if exists("AddedDB") == 0: AddedDB = [""] # Paras - These were somehow forgotten before, or new, so I add them here for completeness - if (exists('home') == 0 or home == ""): + if exists("home") == 0 or home == "": home = "sorry, you must define your home !" exitFlag = True - if (exists('userReleaseArea') == 0 or userReleaseArea == ""): + if exists("userReleaseArea") == 0 or userReleaseArea == "": userReleaseArea = "sorry, you must define your userReleaseArea !" exitFlag = True - if (exists('userReleaseArea') == 0 or userReleaseArea == ""): + if exists("userReleaseArea") == 0 or userReleaseArea == "": userReleaseArea = "sorry, you must define your userReleaseArea !" exitFlag = True - if (exists('pathToScripts') == 0 or pathToScripts == ""): + if exists("pathToScripts") == 0 or pathToScripts == "": pathToScripts = "sorry, you must define your pathToScripts !" exitFlag = True - if (exists('RICHMIRRCOMBINFITROOT') == 0 or RICHMIRRCOMBINFITROOT == ""): + if exists("RICHMIRRCOMBINFITROOT") == 0 or RICHMIRRCOMBINFITROOT == "": RICHMIRRCOMBINFITROOT = "sorry, you must define your RICHMIRRCOMBINFITROOT !" exitFlag = True - if (exists('RICHMIRRORALIGNMENTGANGAROOT') == 0 - or RICHMIRRORALIGNMENTGANGAROOT == ""): - RICHMIRRORALIGNMENTGANGAROOT = "sorry, you must define your RICHMIRRORALIGNMENTGANGAROOT !" + if ( + exists("RICHMIRRORALIGNMENTGANGAROOT") == 0 + or RICHMIRRORALIGNMENTGANGAROOT == "" + ): + RICHMIRRORALIGNMENTGANGAROOT = ( + "sorry, you must define your RICHMIRRORALIGNMENTGANGAROOT !" + ) exitFlag = True - if (exists('SQLITEDBPATH') == 0 or SQLITEDBPATH == ""): + if exists("SQLITEDBPATH") == 0 or SQLITEDBPATH == "": SQLITEDBPATH = "sorry, you must define your SQLITEDBPATH !" exitFlag = True - if (exists('previousJobNumbers') == 0 or previousJobNumbers == ""): - previousJobNumbers = range(899, 901) + if exists("previousJobNumbers") == 0 or previousJobNumbers == "": + previousJobNumbers = list(range(899, 901)) - if (exists('skipFirstCombinFit') == 0 or skipFirstCombinFit == ""): + if exists("skipFirstCombinFit") == 0 or skipFirstCombinFit == "": skipFirstCombinFit = 0 - if (exists('skipFirstRecoJob') == 0 or skipFirstRecoJob == ""): + if exists("skipFirstRecoJob") == 0 or skipFirstRecoJob == "": skipFirstRecoJob = 0 - if (exists('skipFirstMergeJob') == 0 or skipFirstMergeJob == ""): + if exists("skipFirstMergeJob") == 0 or skipFirstMergeJob == "": skipFirstMergeJob = 0 - if (exists('justGlobalFit') == 0 or justGlobalFit == ""): + if exists("justGlobalFit") == 0 or justGlobalFit == "": justGlobalFit = 0 - if (exists('stopTolerance') == 0 or stopTolerance == ""): + if exists("stopTolerance") == 0 or stopTolerance == "": stopTolerance = 0.1 # in mrad - if (exists('warningFactor') == 0 or warningFactor == ""): + if exists("warningFactor") == 0 or warningFactor == "": warningFactor = 20 - if (exists('phiBinFactor') == 0 or phiBinFactor == ""): + if exists("phiBinFactor") == 0 or phiBinFactor == "": phiBinFactor = 1 # PN - These are apparently unused in this script - if (exists('APPCONFIGOPTS') == 0): + if exists("APPCONFIGOPTS") == 0: APPCONFIGOPTS = "" - if (exists('thisAppConfigBrunelOpts') == 0 - or thisAppConfigBrunelOpts == ""): + if exists("thisAppConfigBrunelOpts") == 0 or thisAppConfigBrunelOpts == "": thisAppConfigBrunelOpts = "Default" brunelEvtMax = str(brunelEvtMax) brunelPrintFreq = str(brunelPrintFreq) messageSvcOutputLevel = str(messageSvcOutputLevel) - print "### ----------------------------------------------------------------------------" - print "### OK, here are the parameters that will be used (default, unless you defined" - print "### them for me in the settings file):" + print( + "### ----------------------------------------------------------------------------" + ) + print( + "### OK, here are the parameters that will be used (default, unless you defined" + ) + print("### them for me in the settings file):") # Directory paths, like workDir, should end with os.path.sep # Please ensure this is the case in the _settings_ file! - print "###" - print "### workDir = " + workDir - - print "### dDDB_tag = " + dDDB_tag - print "### condDB_tag = " + condDB_tag - print "### date = " + date - print "### localCondDB_tag = " + localCondDB_tag - - print "### setupProjectBrunelOpts = " + setupProjectBrunelOpts - - print "### eventSelectorInputFile = " + eventSelectorInputFile - print "### LHCbVersion = " + LHCbVersion - print "### brunelVersion = " + brunelVersion - print "### brunelEvtMax = " + brunelEvtMax - print "### brunelPrintFreq = " + brunelPrintFreq - print "### brunelInitialInputType = " + brunelInitialInputType - print "### messageSvcOutputLevel = " + messageSvcOutputLevel - - print "### splitFilesPerJob = " + str(splitFilesPerJob) - print "### splitMaxFiles = " + str(splitMaxFiles) - print "### backEnd = " + backEnd + print("###") + print("### workDir = " + workDir) + + print("### dDDB_tag = " + dDDB_tag) + print("### condDB_tag = " + condDB_tag) + print("### date = " + date) + print("### localCondDB_tag = " + localCondDB_tag) + + print("### setupProjectBrunelOpts = " + setupProjectBrunelOpts) + + print("### eventSelectorInputFile = " + eventSelectorInputFile) + print("### LHCbVersion = " + LHCbVersion) + print("### brunelVersion = " + brunelVersion) + print("### brunelEvtMax = " + brunelEvtMax) + print("### brunelPrintFreq = " + brunelPrintFreq) + print("### brunelInitialInputType = " + brunelInitialInputType) + print("### messageSvcOutputLevel = " + messageSvcOutputLevel) + + print("### splitFilesPerJob = " + str(splitFilesPerJob)) + print("### splitMaxFiles = " + str(splitMaxFiles)) + print("### backEnd = " + backEnd) backEnd = str(backEnd.lower()) - if (backEnd == 'dirac'): - print "### diracCPUTime = " + str(diracCPUTime) + if backEnd == "dirac": + print("### diracCPUTime = " + str(diracCPUTime)) - print "### mirrCombinSubset = " + mirrCombinSubset - print "### thisCase = " + thisCase - print "### dataVariant = " + dataVariant + print("### mirrCombinSubset = " + mirrCombinSubset) + print("### thisCase = " + thisCase) + print("### dataVariant = " + dataVariant) - print "### minAverageBinPop = " + str(minAverageBinPop) - print "### deltaThetaWindow = " + str(deltaThetaWindow) + print("### minAverageBinPop = " + str(minAverageBinPop)) + print("### deltaThetaWindow = " + str(deltaThetaWindow)) - print "### coeffCalibrTilt = " + str(coeffCalibrTilt) + print("### coeffCalibrTilt = " + str(coeffCalibrTilt)) - print "### useTruth = " + useTruth + print("### useTruth = " + useTruth) - print "### useOffsetsFromMC = " + useOffsetsFromMC - print "### alignHPDs = " + alignHPDs + print("### useOffsetsFromMC = " + useOffsetsFromMC) + print("### alignHPDs = " + alignHPDs) - print "### AddedDB = " - print AddedDB + print("### AddedDB = ") + print(AddedDB) # print "### AddedDB = "+str(len(AddedDB)) - useOffsets = (useOffsetsFromMC.lower() == "true" - or useOffsetsFromMC.lower() == "yes") - if (useOffsets): + useOffsets = useOffsetsFromMC.lower() == "true" or useOffsetsFromMC.lower() == "yes" + if useOffsets: useOffsetsFromMC = "true" - print "### verOffsetsFromMC = " + verOffsetsFromMC + print("### verOffsetsFromMC = " + verOffsetsFromMC) else: useOffsetsFromMC = "false" - print "### usePremisaligned = " + usePremisaligned - premisaligned = (usePremisaligned.lower() == "true" - or usePremisaligned.lower() == "yes") - if (premisaligned): + print("### usePremisaligned = " + usePremisaligned) + premisaligned = ( + usePremisaligned.lower() == "true" or usePremisaligned.lower() == "yes" + ) + if premisaligned: usePremisaligned = "true" - print "### verPremisaligned = " + verPremisaligned + print("### verPremisaligned = " + verPremisaligned) else: usePremisaligned = "false" - print "### useSpecificAlignment = " + useSpecificAlignment - specific = (useSpecificAlignment.lower() == "true" - or usePremisaligned.lower() == "yes") - if (specific): + print("### useSpecificAlignment = " + useSpecificAlignment) + specific = ( + useSpecificAlignment.lower() == "true" or usePremisaligned.lower() == "yes" + ) + if specific: useSpecificAlignment = "true" - print "### specificAlignment = " + specificAlignment + print("### specificAlignment = " + specificAlignment) else: useSpecificAlignment = "false" - print "### combinFitVariant = " + str(combinFitVariant) + print("### combinFitVariant = " + str(combinFitVariant)) - print "### maximumNumberOfIterations = " + str( - maximumNumberOfIterations) + print("### maximumNumberOfIterations = " + str(maximumNumberOfIterations)) - print "### startFromIteration = " + str(startFromIteration) + print("### startFromIteration = " + str(startFromIteration)) - print "### richDetector = " + str(richDetector) + print("### richDetector = " + str(richDetector)) - print "### solutionMethod = " + str(solutionMethod) + print("### solutionMethod = " + str(solutionMethod)) # And the additional stuff - print "### home = " + str(home) - print "### userReleaseArea = " + str(userReleaseArea) - print "### pathToScripts = " + str(pathToScripts) - print "### RICHMIRRALIGNROOT = " + str(RICHMIRRALIGNROOT) - print "### RICHMIRRCOMBINFITROOT = " + str(RICHMIRRCOMBINFITROOT) - print "### RICHMIRRORALIGNMENTGANGAROOT = " + str( - RICHMIRRORALIGNMENTGANGAROOT) - print "### SQLITEDBPATH = " + str(SQLITEDBPATH) - print "### previousJobNumbers = " - print previousJobNumbers - - print "### skipFirstCombinFit = " + str(skipFirstCombinFit) - print "### skipFirstRecoJob = " + str(skipFirstRecoJob) - print "### skipFirstMergeJob = " + str(skipFirstMergeJob) - - print "### justGlobalFit = " + str(justGlobalFit) - - print "### APPCONFIGOPTS = " + APPCONFIGOPTS - print "### thisAppConfigBrunelOpts = " + thisAppConfigBrunelOpts - - print "### stopTolerance = " + str(stopTolerance) - print "### warningFactor = " + str(warningFactor) - print "### phiBinFactor = " + str(phiBinFactor) - - print "### ----------------------------------------------------------------------------" - - if (exitFlag): - print "### ----------------------------------------------------------------------------" - print "### sorry, not enough information for running: check the settings file content !" - print "### ----------------------------------------------------------------------------" + print("### home = " + str(home)) + print("### userReleaseArea = " + str(userReleaseArea)) + print("### pathToScripts = " + str(pathToScripts)) + print("### RICHMIRRALIGNROOT = " + str(RICHMIRRALIGNROOT)) + print("### RICHMIRRCOMBINFITROOT = " + str(RICHMIRRCOMBINFITROOT)) + print("### RICHMIRRORALIGNMENTGANGAROOT = " + str(RICHMIRRORALIGNMENTGANGAROOT)) + print("### SQLITEDBPATH = " + str(SQLITEDBPATH)) + print("### previousJobNumbers = ") + print(previousJobNumbers) + + print("### skipFirstCombinFit = " + str(skipFirstCombinFit)) + print("### skipFirstRecoJob = " + str(skipFirstRecoJob)) + print("### skipFirstMergeJob = " + str(skipFirstMergeJob)) + + print("### justGlobalFit = " + str(justGlobalFit)) + + print("### APPCONFIGOPTS = " + APPCONFIGOPTS) + print("### thisAppConfigBrunelOpts = " + thisAppConfigBrunelOpts) + + print("### stopTolerance = " + str(stopTolerance)) + print("### warningFactor = " + str(warningFactor)) + print("### phiBinFactor = " + str(phiBinFactor)) + + print( + "### ----------------------------------------------------------------------------" + ) + + if exitFlag: + print( + "### ----------------------------------------------------------------------------" + ) + print( + "### sorry, not enough information for running: check the settings file content !" + ) + print( + "### ----------------------------------------------------------------------------" + ) sys.exit(1) - print "You are currently in this directory:" + print("You are currently in this directory:") wasHere = os.getcwd() - print wasHere - print "You are now in the working directory:" + print(wasHere) + print("You are now in the working directory:") os.chdir(workDir) - print os.getcwd() + print(os.getcwd()) - #------------------------------------------------------------------------------- + # ------------------------------------------------------------------------------- # PN - No longer necessary. You should have defined this in your _settings_ file # - #pathToScripts = "/afs/cern.ch/lhcb/software/releases/LBSCRIPTS/prod/InstallArea/scripts" - #if not pathToScripts.endswith(os.path.sep): + # pathToScripts = "/afs/cern.ch/lhcb/software/releases/LBSCRIPTS/prod/InstallArea/scripts" + # if not pathToScripts.endswith(os.path.sep): # pathToScripts += os.path.sep - #------------------------------------------------------------------------------- + # ------------------------------------------------------------------------------- # just not to forget later... RichDetectorStr = str(richDetector) iterationCount = startFromIteration collisionVariantList = [ - "Collision09", "Collision10", "Collision11", "Collision12", - "Collision15", "Collision15_30" + "Collision09", + "Collision10", + "Collision11", + "Collision12", + "Collision15", + "Collision15_30", ] # Real Data mcVariantList = ["NotUsed"] # PN - We don't use MC, yet theFileNowForOnline = workDir + "Rich" + RichDetectorStr + ".xml" - #------------------------------------------------------------------------------- - if (dataVariant in collisionVariantList): + # ------------------------------------------------------------------------------- + if dataVariant in collisionVariantList: CONDDB = "LHCBCOND" - #setupProjectBrunelOpts += " --use-grid" + # setupProjectBrunelOpts += " --use-grid" else: CONDDB = "SIMCOND" - #------------------------------------------------------------------------------- + # ------------------------------------------------------------------------------- DDDB_tag = dDDB_tag CondDB_tag = condDB_tag - #------------------------------------------------------------------------------- - if (localCondDB_tag != ''): + # ------------------------------------------------------------------------------- + if localCondDB_tag != "": LocalCondDB_tag = localCondDB_tag else: LocalCondDB_tag = CondDB_tag - #------------------------------------------------------------------------------- + # ------------------------------------------------------------------------------- # this is the case when the magnification coefficients are independent of the # sign of the rotation - if (magnifCoeffMode == 0 or magnifCoeffMode == 1): + if magnifCoeffMode == 0 or magnifCoeffMode == 1: tiltInJobnameDict = dict({"": ""}) tiltNames = [""] # and this is the case when the magnification coefficients are dependent on the # sign of the rotation - if (magnifCoeffMode == 2): + if magnifCoeffMode == 2: # in case of 2 we must run 9 times over the same data files during each # major iteration: one normal and 8 with 8 calibration-modified XML files to # evaluate the magnification coefficients, all 9 jobs in parallel, therefore we # prepare a convenient dictionary for the job names - tiltInJobnameDict = dict({ - "": "", - "pri_negYzerZ": "p_nz_", - "pri_posYzerZ": "p_pz_", - "pri_zerYnegZ": "p_zn_", - "pri_zerYposZ": "p_zp_", - "sec_negYzerZ": "s_nz_", - "sec_posYzerZ": "s_pz_", - "sec_zerYnegZ": "s_zn_", - "sec_zerYposZ": "s_zp_" - }) - #------------------------------------------------------------------------------------------------------------------------------------------------ + tiltInJobnameDict = dict( + { + "": "", + "pri_negYzerZ": "p_nz_", + "pri_posYzerZ": "p_pz_", + "pri_zerYnegZ": "p_zn_", + "pri_zerYposZ": "p_zp_", + "sec_negYzerZ": "s_nz_", + "sec_posYzerZ": "s_pz_", + "sec_zerYnegZ": "s_zn_", + "sec_zerYposZ": "s_zp_", + } + ) + # ------------------------------------------------------------------------------------------------------------------------------------------------ tiltNames = [ - "", "pri_negYzerZ", "pri_posYzerZ", "pri_zerYnegZ", "pri_zerYposZ", - "sec_negYzerZ", "sec_posYzerZ", "sec_zerYnegZ", "sec_zerYposZ" + "", + "pri_negYzerZ", + "pri_posYzerZ", + "pri_zerYnegZ", + "pri_zerYposZ", + "sec_negYzerZ", + "sec_posYzerZ", + "sec_zerYnegZ", + "sec_zerYposZ", ] - #------------------------------------------------------------------------------- + # ------------------------------------------------------------------------------- # also, here is the right place to prepare directories for the main # and for the coefficient variants branches # for that, we already need proper long names (but without major iteration number) @@ -797,26 +853,26 @@ def mirroralign(RichInfoSettings="Something_Went_Wrong"): thisTuning += "Cm" + str(magnifCoeffMode) thisTuning += "Sm" + str(solutionMethod) - if ("" != useTruth): + if "" != useTruth: thisTuning += "Tr" + useTruth.lower() - if (useOffsets): + if useOffsets: thisTuning += "Of" - #thisCaseStr += "_"+thisTuning + # thisCaseStr += "_"+thisTuning thisCaseStr += thisTuning - #------------------------------------------------------------------------------- - if (useOffsets and verOffsetsFromMC == ''): + # ------------------------------------------------------------------------------- + if useOffsets and verOffsetsFromMC == "": verOffsetsFromMC = thisCase + "_" + dataVariant - #------------------------------------------------------------------------------- - if (premisaligned): + # ------------------------------------------------------------------------------- + if premisaligned: thisCaseExtended = thisCase + "_" + verPremisaligned else: thisCaseExtended = thisCase - #------------------------------------------------------------------------------- + # ------------------------------------------------------------------------------- # we need thisNameStr for preparation of the misaligned xml files, etc. # in case where we do not need any loops over the tilts thisNameStr = thisCaseStr + "_" + thisCaseExtended + "_" + dataVariant @@ -826,64 +882,93 @@ def mirroralign(RichInfoSettings="Something_Went_Wrong"): tiltNamesLength = len(tiltNames) for tiltName in tiltNames: - - if (tiltName == ""): + if tiltName == "": theseNamesWithTilts[tiltName] = thisNameStr else: - theseNamesWithTilts[ - tiltName] = thisCaseStr + "_" + thisCaseExtended + "_" + dataVariant + "_" + tiltName + theseNamesWithTilts[tiltName] = ( + thisCaseStr + + "_" + + thisCaseExtended + + "_" + + dataVariant + + "_" + + tiltName + ) # clean-up the directories for the branches # Paras believes this only needs to be done once, if we are running completely from scratch - if (iterationCount == 0 and not skipFirstRecoJob == 1 - and not skipFirstMergeJob == 1 - and not skipFirstCombinFit == 1): - if os.path.exists(workDir + "Mirrors_rich" + RichDetectorStr + - "_" + theseNamesWithTilts[tiltName]): - dir_util.remove_tree(workDir + "Mirrors_rich" + - RichDetectorStr + "_" + - theseNamesWithTilts[tiltName]) + if ( + iterationCount == 0 + and not skipFirstRecoJob == 1 + and not skipFirstMergeJob == 1 + and not skipFirstCombinFit == 1 + ): + if os.path.exists( + workDir + + "Mirrors_rich" + + RichDetectorStr + + "_" + + theseNamesWithTilts[tiltName] + ): + dir_util.remove_tree( + workDir + + "Mirrors_rich" + + RichDetectorStr + + "_" + + theseNamesWithTilts[tiltName] + ) # Sam found that we have to rename stuff to get this to work # ONLY doing this for magnifCoeffMode == 0 for now. - if (magnifCoeffMode == 0): - + if magnifCoeffMode == 0: alternateTiltNames = [ - "pri_negYzerZ", "pri_posYzerZ", "pri_zerYnegZ", "pri_zerYposZ", - "sec_negYzerZ", "sec_posYzerZ", "sec_zerYnegZ", "sec_zerYposZ" + "pri_negYzerZ", + "pri_posYzerZ", + "pri_zerYnegZ", + "pri_zerYposZ", + "sec_negYzerZ", + "sec_posYzerZ", + "sec_zerYnegZ", + "sec_zerYposZ", ] - print alternateTiltNames + print(alternateTiltNames) theseNamesWithOtherTilts = {} for alternateTiltName in alternateTiltNames: - - theseNamesWithOtherTilts[ - alternateTiltName] = thisCaseStr + "_" + thisCaseExtended + "_" + dataVariant + "_" + alternateTiltName - - print theseNamesWithOtherTilts + theseNamesWithOtherTilts[alternateTiltName] = ( + thisCaseStr + + "_" + + thisCaseExtended + + "_" + + dataVariant + + "_" + + alternateTiltName + ) + + print(theseNamesWithOtherTilts) # ultra-rubbish way to deal with this - if (richDetector == 1): + if richDetector == 1: weHaveFileList = [ - workDir + 'Rich1FixedMirrCoeff_pri_negYzerZ_1.0mr.txt', - workDir + 'Rich1FixedMirrCoeff_pri_posYzerZ_1.0mr.txt', - workDir + 'Rich1FixedMirrCoeff_pri_zerYnegZ_1.0mr.txt', - workDir + 'Rich1FixedMirrCoeff_pri_zerYposZ_1.0mr.txt', - workDir + 'Rich1FixedMirrCoeff_sec_negYzerZ_1.0mr.txt', - workDir + 'Rich1FixedMirrCoeff_sec_posYzerZ_1.0mr.txt', - workDir + 'Rich1FixedMirrCoeff_sec_zerYnegZ_1.0mr.txt', - workDir + 'Rich1FixedMirrCoeff_sec_zerYposZ_1.0mr.txt' + workDir + "Rich1FixedMirrCoeff_pri_negYzerZ_1.0mr.txt", + workDir + "Rich1FixedMirrCoeff_pri_posYzerZ_1.0mr.txt", + workDir + "Rich1FixedMirrCoeff_pri_zerYnegZ_1.0mr.txt", + workDir + "Rich1FixedMirrCoeff_pri_zerYposZ_1.0mr.txt", + workDir + "Rich1FixedMirrCoeff_sec_negYzerZ_1.0mr.txt", + workDir + "Rich1FixedMirrCoeff_sec_posYzerZ_1.0mr.txt", + workDir + "Rich1FixedMirrCoeff_sec_zerYnegZ_1.0mr.txt", + workDir + "Rich1FixedMirrCoeff_sec_zerYposZ_1.0mr.txt", ] else: weHaveFileList = [ - workDir + 'Rich2FixedMirrCoeff_pri_negYzerZ_1.0mr.txt', - workDir + 'Rich2FixedMirrCoeff_pri_posYzerZ_1.0mr.txt', - workDir + 'Rich2FixedMirrCoeff_pri_zerYnegZ_1.0mr.txt', - workDir + 'Rich2FixedMirrCoeff_pri_zerYposZ_1.0mr.txt', - workDir + 'Rich2FixedMirrCoeff_sec_negYzerZ_1.0mr.txt', - workDir + 'Rich2FixedMirrCoeff_sec_posYzerZ_1.0mr.txt', - workDir + 'Rich2FixedMirrCoeff_sec_zerYnegZ_1.0mr.txt', - workDir + 'Rich2FixedMirrCoeff_sec_zerYposZ_1.0mr.txt' + workDir + "Rich2FixedMirrCoeff_pri_negYzerZ_1.0mr.txt", + workDir + "Rich2FixedMirrCoeff_pri_posYzerZ_1.0mr.txt", + workDir + "Rich2FixedMirrCoeff_pri_zerYnegZ_1.0mr.txt", + workDir + "Rich2FixedMirrCoeff_pri_zerYposZ_1.0mr.txt", + workDir + "Rich2FixedMirrCoeff_sec_negYzerZ_1.0mr.txt", + workDir + "Rich2FixedMirrCoeff_sec_posYzerZ_1.0mr.txt", + workDir + "Rich2FixedMirrCoeff_sec_zerYnegZ_1.0mr.txt", + workDir + "Rich2FixedMirrCoeff_sec_zerYposZ_1.0mr.txt", ] weHaveFileListIterator = 0 @@ -891,187 +976,348 @@ def mirroralign(RichInfoSettings="Something_Went_Wrong"): for alternateTiltName in alternateTiltNames: # length of weHaveFileList better be the same as alternateTiltNames if os.path.exists(weHaveFileList[weHaveFileListIterator]): - mirrAlignExpectsFile = workDir + "Rich" + RichDetectorStr + "MirrMagnFactors_" + theseNamesWithOtherTilts[ - alternateTiltName] + "_predefined.txt" - print "moving " + weHaveFileList[ - weHaveFileListIterator] + " to " + mirrAlignExpectsFile - os.system("cp " + weHaveFileList[weHaveFileListIterator] + - " " + mirrAlignExpectsFile) - #os.remove( weHaveFileList[weHaveFileListIterator] ) + mirrAlignExpectsFile = ( + workDir + + "Rich" + + RichDetectorStr + + "MirrMagnFactors_" + + theseNamesWithOtherTilts[alternateTiltName] + + "_predefined.txt" + ) + print( + "moving " + + weHaveFileList[weHaveFileListIterator] + + " to " + + mirrAlignExpectsFile + ) + os.system( + "cp " + + weHaveFileList[weHaveFileListIterator] + + " " + + mirrAlignExpectsFile + ) + # os.remove( weHaveFileList[weHaveFileListIterator] ) weHaveFileListIterator += 1 os.system("rm -rf *_1.0mr.txt") - #------------------------------------------------------------------------------- + # ------------------------------------------------------------------------------- """ if the iterationCount == 0 Before we start any major iterations, let us prepare local XML copy of the DB """ - #------------------------------------------------------------------------------- + # ------------------------------------------------------------------------------- # Paras believes this only needs to be done once, if we are running completely from scratch - if (iterationCount == 0 and not skipFirstRecoJob == 1 - and not skipFirstMergeJob == 1 and not skipFirstCombinFit == 1): + if ( + iterationCount == 0 + and not skipFirstRecoJob == 1 + and not skipFirstMergeJob == 1 + and not skipFirstCombinFit == 1 + ): # if ( iterationCount == 0 or skipFirstRecoJob == 1 ) : - if (premisaligned): - print "### creating appropriate local /Alignment branch, like in the official CondDB," - print "### and preparing a working copy of the premisaligned Mirrors.xml :" - print "### ----------------------------------------------------------------------------" - dir_util.mkpath(workDir + "Mirrors_rich" + RichDetectorStr + "_" + - thisNameStr + "/Conditions/Rich" + - RichDetectorStr + "/Alignment") - #------------------------------------------------------------------------------- + if premisaligned: + print( + "### creating appropriate local /Alignment branch, like in the official CondDB," + ) + print("### and preparing a working copy of the premisaligned Mirrors.xml :") + print( + "### ----------------------------------------------------------------------------" + ) + dir_util.mkpath( + workDir + + "Mirrors_rich" + + RichDetectorStr + + "_" + + thisNameStr + + "/Conditions/Rich" + + RichDetectorStr + + "/Alignment" + ) + # ------------------------------------------------------------------------------- # create a working [replaceable] copy called "Mirrors_rich2_"+thisNameStr+"_i0.xml" # we'd better assume that there is a consistent naming convention here... I have no idea since we don't deal with premisaligned yet... but we are going forward with this: - os.system("cp -p Rich" + RichDetectorStr + - "CondDBUpdate_random_1.xml Rich" + RichDetectorStr + - "CondDBUpdate_" + thisNameStr + "_i0.xml") + os.system( + "cp -p Rich" + + RichDetectorStr + + "CondDBUpdate_random_1.xml Rich" + + RichDetectorStr + + "CondDBUpdate_" + + thisNameStr + + "_i0.xml" + ) else: - if (backEnd != 'online'): - print "### preparing XML copy of the whole Mirrors.xml branch from the official CondDB:" - print "### and preparing a working copy of Mirrors.xml :" - print "### ----------------------------------------------------------------------------" - - if (setupProjectBrunelOpts.find("--use-grid") != -1): + if backEnd != "online": + print( + "### preparing XML copy of the whole Mirrors.xml branch from the official CondDB:" + ) + print("### and preparing a working copy of Mirrors.xml :") + print( + "### ----------------------------------------------------------------------------" + ) - print '( setupProjectBrunelOpts.find("--use-grid") != -1 ) is True' - print "dump_db_to_files.py -v -c CondDB/" + CONDDB + " -t `date +\"%s000000000\"` -T \'" + CondDB_tag + "\' -s /Conditions/Rich" + RichDetectorStr + "/Alignment/Mirrors.xml -d " + workDir + "Mirrors_rich" + RichDetectorStr + "_" + thisNameStr + if setupProjectBrunelOpts.find("--use-grid") != -1: + print('( setupProjectBrunelOpts.find("--use-grid") != -1 ) is True') + print( + "dump_db_to_files.py -v -c CondDB/" + + CONDDB + + ' -t `date +"%s000000000"` -T \'' + + CondDB_tag + + "' -s /Conditions/Rich" + + RichDetectorStr + + "/Alignment/Mirrors.xml -d " + + workDir + + "Mirrors_rich" + + RichDetectorStr + + "_" + + thisNameStr + ) p = Popen( - "export HOME=" + home + ";" + "source " + - pathToScripts + "LbLogin.sh;" + - "source `which SetupProject.sh` LHCb " + LHCbVersion + - " --use-grid;" + "dump_db_to_files.py -v -c CondDB/" - + CONDDB + " -t `date +\"%s000000000\"` -T \'" + - CondDB_tag + "\' -s /Conditions/Rich" + - RichDetectorStr + "/Alignment/Mirrors.xml -d " + - workDir + "Mirrors_rich" + RichDetectorStr + "_" + - thisNameStr, + "export HOME=" + + home + + ";" + + "source " + + pathToScripts + + "LbLogin.sh;" + + "source `which SetupProject.sh` LHCb " + + LHCbVersion + + " --use-grid;" + + "dump_db_to_files.py -v -c CondDB/" + + CONDDB + + ' -t `date +"%s000000000"` -T \'' + + CondDB_tag + + "' -s /Conditions/Rich" + + RichDetectorStr + + "/Alignment/Mirrors.xml -d " + + workDir + + "Mirrors_rich" + + RichDetectorStr + + "_" + + thisNameStr, shell=True, executable="/bin/bash", stdout=PIPE, - stderr=PIPE) + stderr=PIPE, + ) (stdout, stderr) = p.communicate() stdReport(stdout, stderr) else: - CONDDB1 = CONDDB - print '( setupProjectBrunelOpts.find("--use-grid") != -1 ) is False' + print( + '( setupProjectBrunelOpts.find("--use-grid") != -1 ) is False' + ) # print "dump_db_to_files.py -v -c sqlite_file:$SQLITEDBPATH/"+CONDDB1+".db/"+CONDDB+" -T \'"+ CondDB_tag+"\' -t \'"+date+"\' -s /Conditions/Rich"+RichDetectorStr+"/Alignment/Mirrors.xml -d Mirrors_"+thisNameStr - print "dump_db_to_files.py -v -c sqlite_file:" + SQLITEDBPATH + CONDDB1 + ".db/" + CONDDB + " -T \'" + CondDB_tag + "\' -t \'" + date + "\' -s /Conditions/Rich" + RichDetectorStr + "/Alignment/Mirrors.xml -d " + workDir + "Mirrors_rich" + RichDetectorStr + "_" + thisNameStr + print( + "dump_db_to_files.py -v -c sqlite_file:" + + SQLITEDBPATH + + CONDDB1 + + ".db/" + + CONDDB + + " -T '" + + CondDB_tag + + "' -t '" + + date + + "' -s /Conditions/Rich" + + RichDetectorStr + + "/Alignment/Mirrors.xml -d " + + workDir + + "Mirrors_rich" + + RichDetectorStr + + "_" + + thisNameStr + ) p = Popen( - "export HOME=" + home + ";" + "source " + - pathToScripts + "LbLogin.sh;" + - "source `which SetupProject.sh` LHCb " + LHCbVersion + - " ;" + "export HOME=" + + home + + ";" + + "source " + + pathToScripts + + "LbLogin.sh;" + + "source `which SetupProject.sh` LHCb " + + LHCbVersion + + " ;" # +"dump_db_to_files.py -v -c sqlite_file:$SQLITEDBPATH/"+CONDDB1+".db/"+CONDDB+" -T \'"+ CondDB_tag+"\' -t \'"+date+"\' -s /Conditions/Rich"+RichDetectorStr+"/Alignment/Mirrors.xml -d Mirrors_"+thisNameStr, - + "dump_db_to_files.py -v -c sqlite_file:" + - SQLITEDBPATH + CONDDB1 + ".db/" + CONDDB + " -T \'" + - CondDB_tag + "\' -t \'" + date + - "\' -s /Conditions/Rich" + RichDetectorStr + - "/Alignment/Mirrors.xml -d " + workDir + - "Mirrors_rich" + RichDetectorStr + "_" + thisNameStr, + + "dump_db_to_files.py -v -c sqlite_file:" + + SQLITEDBPATH + + CONDDB1 + + ".db/" + + CONDDB + + " -T '" + + CondDB_tag + + "' -t '" + + date + + "' -s /Conditions/Rich" + + RichDetectorStr + + "/Alignment/Mirrors.xml -d " + + workDir + + "Mirrors_rich" + + RichDetectorStr + + "_" + + thisNameStr, shell=True, executable="/bin/bash", stdout=PIPE, - stderr=PIPE) + stderr=PIPE, + ) (stdout, stderr) = p.communicate() stdReport(stdout, stderr) - #------------------------------------------------------------------------------- + # ------------------------------------------------------------------------------- # create a working [replaceable] copy called "Rich"+RichDetectorStr+"CondDBUpdate_"+thisNameStr+"_i0.xml" - os.system("cp -p " + workDir + "Mirrors_rich" + - RichDetectorStr + "_" + thisNameStr + - "/Conditions/Rich" + RichDetectorStr + - "/Alignment/Mirrors.xml Rich" + RichDetectorStr + - "CondDBUpdate_" + thisNameStr + "_i0.xml") - os.remove(workDir + "Mirrors_rich" + RichDetectorStr + "_" + - thisNameStr + "/Conditions/Rich" + RichDetectorStr + - "/Alignment/Mirrors.xml") - #------------------------------------------------------------------------------- + os.system( + "cp -p " + + workDir + + "Mirrors_rich" + + RichDetectorStr + + "_" + + thisNameStr + + "/Conditions/Rich" + + RichDetectorStr + + "/Alignment/Mirrors.xml Rich" + + RichDetectorStr + + "CondDBUpdate_" + + thisNameStr + + "_i0.xml" + ) + os.remove( + workDir + + "Mirrors_rich" + + RichDetectorStr + + "_" + + thisNameStr + + "/Conditions/Rich" + + RichDetectorStr + + "/Alignment/Mirrors.xml" + ) + # ------------------------------------------------------------------------------- # if we want to use an existing mirror alignment XML, copy specificAlignment as the zeroth major iteration XML # make sure this is *always* the case ONLINE - if (useSpecificAlignment == "true"): - print "copying specificAlignment to replace the current zeroth iteration XML file" - print "cp -p " + specificAlignment + " Rich" + RichDetectorStr + "CondDBUpdate_" + thisNameStr + "_i0.xml" - os.system("cp -p " + specificAlignment + " Rich" + - RichDetectorStr + "CondDBUpdate_" + thisNameStr + - "_i0.xml") - - #------------------------------------------------------------------------------- + if useSpecificAlignment == "true": + print( + "copying specificAlignment to replace the current zeroth iteration XML file" + ) + print( + "cp -p " + + specificAlignment + + " Rich" + + RichDetectorStr + + "CondDBUpdate_" + + thisNameStr + + "_i0.xml" + ) + os.system( + "cp -p " + + specificAlignment + + " Rich" + + RichDetectorStr + + "CondDBUpdate_" + + thisNameStr + + "_i0.xml" + ) + + # ------------------------------------------------------------------------------- # making Rich"+RichDetectorStr+"CondDBUpdate_"+thisNameStr+"_i0.xml pretty formatted - just_prettify("Rich" + RichDetectorStr + "CondDBUpdate_" + - thisNameStr + "_i0.xml") - #------------------------------------------------------------------------------- - - #define files - currentMirrorXMLFile = "Rich" + RichDetectorStr + "CondDBUpdate_" + thisNameStr + "_i" + str( - iterationCount) + ".xml" - nextIterationXMLFile = "Rich" + RichDetectorStr + "CondDBUpdate_" + thisNameStr + "_i" + str( - iterationCount + 1) + ".xml" - zeroMirrorXMLFile = "Rich" + RichDetectorStr + "CondDBUpdate_" + thisNameStr + "_i0.xml" - #------------------------------------------------------------------------------- - #------------------------------------------------------------------------------- + just_prettify( + "Rich" + RichDetectorStr + "CondDBUpdate_" + thisNameStr + "_i0.xml" + ) + # ------------------------------------------------------------------------------- + + # define files + currentMirrorXMLFile = ( + "Rich" + + RichDetectorStr + + "CondDBUpdate_" + + thisNameStr + + "_i" + + str(iterationCount) + + ".xml" + ) + nextIterationXMLFile = ( + "Rich" + + RichDetectorStr + + "CondDBUpdate_" + + thisNameStr + + "_i" + + str(iterationCount + 1) + + ".xml" + ) + zeroMirrorXMLFile = ( + "Rich" + RichDetectorStr + "CondDBUpdate_" + thisNameStr + "_i0.xml" + ) + # ------------------------------------------------------------------------------- + # ------------------------------------------------------------------------------- # we now create branches of directories for 8 tilts for tiltName in tiltNames: - #if ( tiltName != "" ) : - if (not (os.path.exists(workDir + "Mirrors_rich" + RichDetectorStr + - "_" + theseNamesWithTilts[tiltName] + - "/Conditions/Rich" + RichDetectorStr + - "/Alignment"))): - os.system("mkdir --parents " + workDir + "Mirrors_rich" + - RichDetectorStr + "_" + theseNamesWithTilts[tiltName] + - "/Conditions/Rich" + RichDetectorStr + "/Alignment") - - #------------------------------------------------------------------------------- + # if ( tiltName != "" ) : + if not ( + os.path.exists( + workDir + + "Mirrors_rich" + + RichDetectorStr + + "_" + + theseNamesWithTilts[tiltName] + + "/Conditions/Rich" + + RichDetectorStr + + "/Alignment" + ) + ): + os.system( + "mkdir --parents " + + workDir + + "Mirrors_rich" + + RichDetectorStr + + "_" + + theseNamesWithTilts[tiltName] + + "/Conditions/Rich" + + RichDetectorStr + + "/Alignment" + ) + + # ------------------------------------------------------------------------------- # define directory where additional files to use are - PanoptesJobPath = (RICHMIRRORALIGNMENTGANGAROOT + "job") - #------------------------------------------------------------------------------- + PanoptesJobPath = RICHMIRRORALIGNMENTGANGAROOT + "job" + # ------------------------------------------------------------------------------- # define directory where Brunel configuration files to use are - BrunelOptsPath = (RICHMIRRORALIGNMENTGANGAROOT + "options") + BrunelOptsPath = RICHMIRRORALIGNMENTGANGAROOT + "options" # Paras - OK, now we are getting into Ganga specific stuff. Try to separate this # so if ( backEnd == 'online' ) we don't use Ganga - #------------------------------------------------------------------------------- - if (backEnd == 'local'): + # ------------------------------------------------------------------------------- + if backEnd == "local": jBackend = Local() - jSplitter = SplitByFiles( - filesPerJob=splitFilesPerJob, maxFiles=splitMaxFiles) + jSplitter = SplitByFiles(filesPerJob=splitFilesPerJob, maxFiles=splitMaxFiles) jSplitter.ignoremissing = True - elif (backEnd == 'interactive'): + elif backEnd == "interactive": jBackend = Interactive() - jSplitter = SplitByFiles( - filesPerJob=splitFilesPerJob, maxFiles=splitMaxFiles) + jSplitter = SplitByFiles(filesPerJob=splitFilesPerJob, maxFiles=splitMaxFiles) jSplitter.ignoremissing = True - elif (backEnd == 'dirac'): - jBackend = Dirac(settings={'CPUTime': diracCPUTime}) - jSplitter = SplitByFiles( - filesPerJob=splitFilesPerJob, maxFiles=splitMaxFiles) + elif backEnd == "dirac": + jBackend = Dirac(settings={"CPUTime": diracCPUTime}) + jSplitter = SplitByFiles(filesPerJob=splitFilesPerJob, maxFiles=splitMaxFiles) jSplitter.ignoremissing = True - elif (backEnd == 'lsf'): - jBackend = LSF(queue='1nh') - jSplitter = SplitByFiles( - filesPerJob=splitFilesPerJob, maxFiles=splitMaxFiles) + elif backEnd == "lsf": + jBackend = LSF(queue="1nh") + jSplitter = SplitByFiles(filesPerJob=splitFilesPerJob, maxFiles=splitMaxFiles) jSplitter.ignoremissing = True - elif (backEnd == 'online'): - jBackend = 'online' # jBackend won't be used for online - jSplitter = 'online' # jSplitter won't be used for online + elif backEnd == "online": + jBackend = "online" # jBackend won't be used for online + jSplitter = "online" # jSplitter won't be used for online else: - queuePatt = re.compile(r'lsf_([\w]+)') + queuePatt = re.compile(r"lsf_([\w]+)") queueMatch = queuePatt.match(backEnd) LSF_queue = queueMatch.group(1) jBackend = LSF(queue=LSF_queue) - jSplitter = SplitByFiles( - filesPerJob=splitFilesPerJob, maxFiles=splitMaxFiles) + jSplitter = SplitByFiles(filesPerJob=splitFilesPerJob, maxFiles=splitMaxFiles) jSplitter.ignoremissing = True - #------------------------------------------------------------------------------- + # ------------------------------------------------------------------------------- - #------------------------------------------------------------------------------- + # ------------------------------------------------------------------------------- # initialize the verdict variable - verdict = 'CONTINUE' - #------------------------------------------------------------------------------- + verdict = "CONTINUE" + # ------------------------------------------------------------------------------- # PN - We don't run HPD alignment anymore, so this is always false runHPDalignment = "false" @@ -1083,35 +1329,36 @@ def mirroralign(RichInfoSettings="Something_Went_Wrong"): # Thankful for python variable scoping rules ########################################################################### - command = 'xxxxx' # set a default for OFFLINE + command = "xxxxx" # set a default for OFFLINE n_it = 0 # set minor iteration to 0 minors = tiltNamesLength + 1 # PN - Initialize the ONLINE communicator. - if (backEnd == 'online'): - print "ONLINE" + if backEnd == "online": + print("ONLINE") # import the communicator (python gives a warning, it is preferred to do this only at top level) from Communicator import * + # Start the communicator, before I do *any* iterative mirror alignment: com = Communicator( - 'ALIGNITER' + "ALIGNITER" ) # com established for the rest of this mirroralign function - print "com = Communicator('ALIGNITER') STARTED" + print("com = Communicator('ALIGNITER') STARTED") # FSM loop preparation state = State.NOT_READY com.set_status(state) # start in state NOT_READY - print "com.set_status(State.NOT_READY)" + print("com.set_status(State.NOT_READY)") # Massive while loop, necessary for ONLINE. For OFFLINE this is an innocuous loop like the original while iterationCount < maximumNumberOfIterations loop. ## justGlobalFit = 0 is typically what you want. ## note: stuff from justGlobalFit = 1 has been included into 0 to provide monitoring - #if justGlobalFit == 0: -# while iterationCount < maximumNumberOfIterations : + # if justGlobalFit == 0: + # while iterationCount < maximumNumberOfIterations : while True: # so now we need to have the effect of: while iterationCount < maximumNumberOfIterations - if (backEnd == 'online'): + if backEnd == "online": # Wait for the FSM to give us a command command = com.get_command() - if (command == 'configure' and state == State.NOT_READY): + if command == "configure" and state == State.NOT_READY: # Set up some xml configuration here, that the first RUNNING will process. # let it be be currentMirrorXMLFile on (n_it == 0 && iterationCount == 0) # So we dump it to the file that patchBrunel in the RichAnalyzer will expect it to be picked up from @@ -1120,67 +1367,71 @@ def mirroralign(RichInfoSettings="Something_Went_Wrong"): # We are running online, so write a file that can patch Brunel with key # variables that the RichAnalyzer needs. The RichAnalyzer should look for this file. # The file name will be fixed here, the output can be copied to the correct filename in the workDir when need be. - if (os.path.exists(workDir + "patch.py")): + if os.path.exists(workDir + "patch.py"): os.system( "rm -rf " + workDir + "patch.p*" ) # to get rid of .pyc files, as if the .pyc file is still there it doesn't know that the patch has changed - patchPyFile = open(workDir + 'patch.py', 'w') - patchPyFile.write('FullRichName = \'Rich' + RichDetectorStr + - '\' \n') # python will convert \n to os.linesep - patchPyFile.write('DataFileDir = \'' + eventSelectorInputFile + - '\' \n') - #hostName = os.getenv('HOSTNAME','unknownHost') - #onlineHistoFile = "RichRecQCHistos_rich"+RichDetectorStr+"_"+hostName+".root" - #print "Online ROOT filename ", onlineHistoFile - #patchPyFile.write('HistoName = \''+workDir+onlineHistoFile+'\' \n') - patchPyFile.write('DeltaThetaRange = [ 0.04,' + delthetawin + - ', ' + delthetawin + '] \n') - patchPyFile.write('BrunelEvtMax = ' + brunelEvtMax + ' \n') - patchPyFile.write('BrunelPrintFrequency = ' + brunelPrintFreq + - ' \n') + patchPyFile = open(workDir + "patch.py", "w") + patchPyFile.write( + "FullRichName = 'Rich" + RichDetectorStr + "' \n" + ) # python will convert \n to os.linesep + patchPyFile.write("DataFileDir = '" + eventSelectorInputFile + "' \n") + # hostName = os.getenv('HOSTNAME','unknownHost') + # onlineHistoFile = "RichRecQCHistos_rich"+RichDetectorStr+"_"+hostName+".root" + # print "Online ROOT filename ", onlineHistoFile + # patchPyFile.write('HistoName = \''+workDir+onlineHistoFile+'\' \n') patchPyFile.write( - 'TheFileNowForOnline = \'' + theFileNowForOnline + '\' \n' + "DeltaThetaRange = [ 0.04," + delthetawin + ", " + delthetawin + "] \n" + ) + patchPyFile.write("BrunelEvtMax = " + brunelEvtMax + " \n") + patchPyFile.write("BrunelPrintFrequency = " + brunelPrintFreq + " \n") + patchPyFile.write( + "TheFileNowForOnline = '" + theFileNowForOnline + "' \n" ) # the location of XML file to be picked up by the analyzer patchPyFile.close() state = State.READY - elif (command == 'start' and state == State.READY): + elif command == "start" and state == State.READY: # From READY we can start the Analyzers, # but we will throw this and every (minors)th iteration away # This is to maintain compatibility with the offline alignment. # Unfortunately the alignment will take 1/tiltNamesLength longer # This is a performance hit that for now we will have to absorb state = State.RUNNING - elif (command == 'stop' and state in (State.RUNNING, State.READY)): + elif command == "stop" and state in (State.RUNNING, State.READY): # Next time we go to READY the iterations should be done state = State.READY - elif (command == 'reset'): + elif command == "reset": # After a stop, we need a reset to break out of the loop state = State.NOT_READY break - elif not (command == 'xxxxx' or - (command == 'pause' and state == State.RUNNING)): + elif not ( + command == "xxxxx" or (command == "pause" and state == State.RUNNING) + ): # Something remaining that was unexpected - print 'iterator: bad transition from %s to %s' % (state, command) + print("iterator: bad transition from %s to %s" % (state, command)) state = State.ERROR break else: # time to iterate - if n_it == 0 and backEnd == 'online': - PatchIteratorInfo = getPatchFile(workDir + 'patchIterator.py') + if n_it == 0 and backEnd == "online": + PatchIteratorInfo = getPatchFile(workDir + "patchIterator.py") PatchIteratorMembers = [ - attr for attr in dir(PatchIteratorInfo) + attr + for attr in dir(PatchIteratorInfo) if not callable(getattr(PatchIteratorInfo, attr)) and not attr.startswith("__") ] - print "PatchIteratorMembers:" - print PatchIteratorMembers + print("PatchIteratorMembers:") + print(PatchIteratorMembers) AnalyzerWorkDir = PatchIteratorInfo.AnalyzerWorkDir - print 'major iteration %d' % iterationCount - print 'minor iteration %d' % n_it - if iterationCount >= maximumNumberOfIterations: # When State is back to READY the iterations are over - print 'iterator done' - if (backEnd == 'online'): + print("major iteration %d" % iterationCount) + print("minor iteration %d" % n_it) + if ( + iterationCount >= maximumNumberOfIterations + ): # When State is back to READY the iterations are over + print("iterator done") + if backEnd == "online": state = State.PAUSED com.set_status(state) state = State.READY @@ -1190,38 +1441,48 @@ def mirroralign(RichInfoSettings="Something_Went_Wrong"): if ( (n_it % minors) == 0 ): # iteration 0[0], 10[2], 20[4], etc... for tiltNamesLength = 9[1] - if (backEnd == 'dirac'): + if backEnd == "dirac": os.system( - 'kinit -R' + "kinit -R" ) # renews your local AFS ticket [for up to 7 days, given that "kinit -fp -r 7d" was run from the submitting machine, I think] - os.system('aklog') # renews your local AFS token + os.system("aklog") # renews your local AFS token # gridProxy.renew() # reactivate() # no longer needed, use -v 96:00 when you lhcb-proxy-init # PN - This is never used... should it be? # repeatIteration = False # reset this flag - print "### ----------------------------------------------------------------------------" - print "### starting major iteration named Iteration No. " + str( - iterationCount) - print "### ----------------------------------------------------------------------------" - print strftime("%Y-%m-%d %H:%M:%S", gmtime()) - print "-------------------" - #------------------------------------------------------------------------------- - if (magnifCoeffMode == 2): + print( + "### ----------------------------------------------------------------------------" + ) + print( + "### starting major iteration named Iteration No. " + + str(iterationCount) + ) + print( + "### ----------------------------------------------------------------------------" + ) + print(strftime("%Y-%m-%d %H:%M:%S", gmtime())) + print("-------------------") + # ------------------------------------------------------------------------------- + if magnifCoeffMode == 2: # let us create 8 misaligned xml files: modified by +/- coeffCalibrTilt Mirror.xml files # for evaluation of the magnification coefficients on-fly create_coeff_calibration_xml_files( currentMirrorXMLFile, coeffCalibrTilt, richDetector ) # PN - chose not to add workDir in front of XML file... hopefully this is OK as we should be in the workDir anyway. Would like to change this in the future but is not urgent. - print "### ----------------------------------------------------------------------------" - print "### modified by +/- " + str( - coeffCalibrTilt - ) + " mrad Mirror.xml files have just been prepared" - - #============================================================================ - #=== start Brunel for normal case and for evaluation of the coefficients ==== - #============================================================================ + print( + "### ----------------------------------------------------------------------------" + ) + print( + "### modified by +/- " + + str(coeffCalibrTilt) + + " mrad Mirror.xml files have just been prepared" + ) + + # ============================================================================ + # === start Brunel for normal case and for evaluation of the coefficients ==== + # ============================================================================ # GANGA: we prepare dictionary and sequence of job objects (9) for each major iteration # ONLINE: these just remain empty jobIds = [] @@ -1229,89 +1490,167 @@ def mirroralign(RichInfoSettings="Something_Went_Wrong"): jobId_tilt = {} jobId_submittedSince = {} -# if (iterationCount == 0 and skipFirstRecoJob == 1) : - if (skipFirstRecoJob == 1): - if ((n_it % minors) == 0): - print "### ----------------------------------------------------------------------------" - print "### ---------- SKIPPING BRUNEL RECONSTRUCTION FOR MAJOR ITERATION " + str( - iterationCount) + " ------------------" - print "### ----------------------------------------------------------------------------" + # if (iterationCount == 0 and skipFirstRecoJob == 1) : + if skipFirstRecoJob == 1: + if (n_it % minors) == 0: + print( + "### ----------------------------------------------------------------------------" + ) + print( + "### ---------- SKIPPING BRUNEL RECONSTRUCTION FOR MAJOR ITERATION " + + str(iterationCount) + + " ------------------" + ) + print( + "### ----------------------------------------------------------------------------" + ) n_it += tiltNamesLength + iterationCount * minors - print 'We have just skipped straight to minor iteration %d' % n_it + print( + "We have just skipped straight to minor iteration %d" % n_it + ) # COMMENTED OUT, WE CANNOT DO THIS HERE! IT IS NEEDED LATER # skipFirstRecoJob = 0 else: # run Brunel for the main and for all the tilted variants - #for tiltName in tiltNames : + # for tiltName in tiltNames : if ( - n_it % minors - ) != tiltNamesLength: # iterations 0-8[0] for tiltNamesLength = 9[1] - tiltName = tiltNames[(n_it - iterationCount) % - tiltNamesLength] - #------------------------------------------------------------------------------- + (n_it % minors) != tiltNamesLength + ): # iterations 0-8[0] for tiltNamesLength = 9[1] + tiltName = tiltNames[(n_it - iterationCount) % tiltNamesLength] + # ------------------------------------------------------------------------------- # create the [replaceable] symlinks to local # Mirrors_rich2_"+theseNamesWithTilts[tiltName]+"_i"+str(iterationCount)+".xml # so only .xml file names contain the iterationCount, while # directories' and dbs' names do not - #------------------------------------------------------------------------------- - os.system("ln -sf " + workDir + "Rich" + - RichDetectorStr + "CondDBUpdate_" + - theseNamesWithTilts[tiltName] + "_i" + - str(iterationCount) + ".xml " + workDir + - "Mirrors_rich" + RichDetectorStr + "_" + - theseNamesWithTilts[tiltName] + - "/Conditions/Rich" + RichDetectorStr + - "/Alignment/Mirrors.xml") + # ------------------------------------------------------------------------------- + os.system( + "ln -sf " + + workDir + + "Rich" + + RichDetectorStr + + "CondDBUpdate_" + + theseNamesWithTilts[tiltName] + + "_i" + + str(iterationCount) + + ".xml " + + workDir + + "Mirrors_rich" + + RichDetectorStr + + "_" + + theseNamesWithTilts[tiltName] + + "/Conditions/Rich" + + RichDetectorStr + + "/Alignment/Mirrors.xml" + ) # PN - Apparently the current .db file has outlived its usefulness, if it is there, then remove it. # - A .db file will, of course, not be there for ONLINE - if (os.path.exists( - workDir + "Mirrors_rich" + RichDetectorStr + - "_" + theseNamesWithTilts[tiltName] + ".db")): - os.system("rm -rf " + workDir + "Mirrors_rich" + - RichDetectorStr + "_" + - theseNamesWithTilts[tiltName] + ".db") - - if (backEnd != 'online'): + if os.path.exists( + workDir + + "Mirrors_rich" + + RichDetectorStr + + "_" + + theseNamesWithTilts[tiltName] + + ".db" + ): + os.system( + "rm -rf " + + workDir + + "Mirrors_rich" + + RichDetectorStr + + "_" + + theseNamesWithTilts[tiltName] + + ".db" + ) + + if backEnd != "online": # create local [replaceable] working copy of the conditions database slice # containing only Mirrors.xml branch - print "### ----------------------------------------------------------------------------" - print "### converting the whole Mirrors.xml branch into SQLite format:" - print "### ----------------------------------------------------------------------------" + print( + "### ----------------------------------------------------------------------------" + ) + print( + "### converting the whole Mirrors.xml branch into SQLite format:" + ) + print( + "### ----------------------------------------------------------------------------" + ) # prepare CondDB sqlite_file for this tilt, which will be additional layer to the main database - print "copy_files_to_db.py -s " + workDir + "Mirrors_rich" + RichDetectorStr + "_" + theseNamesWithTilts[ - tiltName] + " -c sqlite_file:Mirrors_rich" + RichDetectorStr + "_" + theseNamesWithTilts[ - tiltName] + ".db/" + CONDDB + print( + "copy_files_to_db.py -s " + + workDir + + "Mirrors_rich" + + RichDetectorStr + + "_" + + theseNamesWithTilts[tiltName] + + " -c sqlite_file:Mirrors_rich" + + RichDetectorStr + + "_" + + theseNamesWithTilts[tiltName] + + ".db/" + + CONDDB + ) p = Popen( - "export HOME=" + home + ";" + "source " + - pathToScripts + "LbLogin.sh;" + - "source `which SetupProject.sh` LHCb " + - LHCbVersion + " ;" + "copy_files_to_db.py -s " - + workDir + "Mirrors_rich" + RichDetectorStr + - "_" + theseNamesWithTilts[tiltName] + - " -c sqlite_file:Mirrors_rich" + - RichDetectorStr + "_" + - theseNamesWithTilts[tiltName] + ".db/" + CONDDB - + ";" + "python " + PanoptesJobPath + - "/tagger.py " + CondDB_tag + " " + workDir + - "Mirrors_rich" + RichDetectorStr + "_" + - theseNamesWithTilts[tiltName] + " " + CONDDB, + "export HOME=" + + home + + ";" + + "source " + + pathToScripts + + "LbLogin.sh;" + + "source `which SetupProject.sh` LHCb " + + LHCbVersion + + " ;" + + "copy_files_to_db.py -s " + + workDir + + "Mirrors_rich" + + RichDetectorStr + + "_" + + theseNamesWithTilts[tiltName] + + " -c sqlite_file:Mirrors_rich" + + RichDetectorStr + + "_" + + theseNamesWithTilts[tiltName] + + ".db/" + + CONDDB + + ";" + + "python " + + PanoptesJobPath + + "/tagger.py " + + CondDB_tag + + " " + + workDir + + "Mirrors_rich" + + RichDetectorStr + + "_" + + theseNamesWithTilts[tiltName] + + " " + + CONDDB, shell=True, executable="/bin/bash", stdout=PIPE, - stderr=PIPE) + stderr=PIPE, + ) (stdout, stderr) = p.communicate() stdReport(stdout, stderr) - print "### ----------------------------------------------------------------------------" - - outputHistoFile = "RichRecQCHistos_rich" + RichDetectorStr + "_" + theseNamesWithTilts[ - tiltName] + "_i" + str(iterationCount) + ".root" - print "Output ROOT filename ", outputHistoFile - - #------------------------------------------------------------------------------- + print( + "### ----------------------------------------------------------------------------" + ) + + outputHistoFile = ( + "RichRecQCHistos_rich" + + RichDetectorStr + + "_" + + theseNamesWithTilts[tiltName] + + "_i" + + str(iterationCount) + + ".root" + ) + print("Output ROOT filename ", outputHistoFile) + + # ------------------------------------------------------------------------------- # the job configuration - #------------------------------------------------------------------------------- + # ------------------------------------------------------------------------------- # PN - OK this is where it gets interesting. # There are two parts of the code where we need to # make this split in two directions. @@ -1320,57 +1659,81 @@ def mirroralign(RichInfoSettings="Something_Went_Wrong"): # Online needs to conform to the Online Alignment Framwork # # First, ONLINE - if (backEnd == 'online'): - print "ONLINE" + if backEnd == "online": + print("ONLINE") # print "The FSM controls all" # Pause the Analyzers. The histograms from the first running should now be available state = State.PAUSED com.set_status(state) # collect histograms (n_it = 0 is a throwaway probably) and store for later use - print "We need to figure out where the Analyzer should drop the histograms AND copy them to the right place" + print( + "We need to figure out where the Analyzer should drop the histograms AND copy them to the right place" + ) # Prepare the xml for the next RichAnalyzer crunching # Dump it to the file that patchBrunel in the RichAnalyzer will expect it to be picked up from - theFileNowInTheIterator = workDir + "Rich" + RichDetectorStr + "CondDBUpdate_" + theseNamesWithTilts[ - tiltName] + "_i" + str(iterationCount) + ".xml" - os.system("cp " + theFileNowInTheIterator + " " + - theFileNowForOnline) + theFileNowInTheIterator = ( + workDir + + "Rich" + + RichDetectorStr + + "CondDBUpdate_" + + theseNamesWithTilts[tiltName] + + "_i" + + str(iterationCount) + + ".xml" + ) + os.system( + "cp " + + theFileNowInTheIterator + + " " + + theFileNowForOnline + ) ## Ideally we'd patch Brunel somehow with a new file name, but it is hard at the moment... easier to just copy output to the right place for now # print "We need to prepare the Analyzer with any specific Brunel Options we need for this tiltname" - #if ( os.path.exists( workDir+"patch.py" ) ) : + # if ( os.path.exists( workDir+"patch.py" ) ) : # os.system("rm -rf "+workDir+"patch.p*") # to get rid of .pyc files, as if the .pyc file is still there it doesn't know that the patch has changed - #patchPyFile = open(workDir+'patch.py','w') - #patchPyFile.write('FullRichName = \'Rich'+RichDetectorStr+'\'\n') # python will convert \n to os.linesep - #patchPyFile.write('HistoName = \''+workDir+outputHistoFile+'\'\n') - #patchPyFile.write('DeltaThetaRange = [ 0.04,'+delthetawin+', '+delthetawin+']\n') - #patchPyFile.close() + # patchPyFile = open(workDir+'patch.py','w') + # patchPyFile.write('FullRichName = \'Rich'+RichDetectorStr+'\'\n') # python will convert \n to os.linesep + # patchPyFile.write('HistoName = \''+workDir+outputHistoFile+'\'\n') + # patchPyFile.write('DeltaThetaRange = [ 0.04,'+delthetawin+', '+delthetawin+']\n') + # patchPyFile.close() # Since we can't do the above, just copy the newest file now for online - os.system("cp " + theFileNowInTheIterator + " " + - AnalyzerWorkDir + "Rich" + - RichDetectorStr + ".xml") + os.system( + "cp " + + theFileNowInTheIterator + + " " + + AnalyzerWorkDir + + "Rich" + + RichDetectorStr + + ".xml" + ) # Second, GANGA (i.e. not ONLINE) else: - print "GANGA" + print("GANGA") gangaVersion = config.System.GANGA_VERSION - print "We are using " + gangaVersion + print("We are using " + gangaVersion) GV61flag = True # Assuming no one is using anything older than Ganga 5 - if 'Ganga-6-0' in gangaVersion: + if "Ganga-6-0" in gangaVersion: GV61flag = False - if 'Ganga-5-' in gangaVersion: + if "Ganga-5-" in gangaVersion: GV61flag = False if GV61flag == True: - print "Proceeding using job options for Ganga 6.1 or later." + print( + "Proceeding using job options for Ganga 6.1 or later." + ) else: - print "Proceeding using job options for Ganga 6.0 or earlier." + print( + "Proceeding using job options for Ganga 6.0 or earlier." + ) jAppBrunel = Brunel(version=brunelVersion) brunelVer = jAppBrunel.version - #------------------------------------------------------------------------------- + # ------------------------------------------------------------------------------- """ Only during the 0-th major iteration we take input data in the form of configuration and therefore append the file list as a configuration @@ -1380,128 +1743,167 @@ def mirroralign(RichInfoSettings="Something_Went_Wrong"): Job object; see below. """ - #jAppBrunel.optsfile = [File( BrunelOptsPath+"/Brunel_RichAlignMoni_"+dataVariant+"-"+brunelInitialInputType+".py")] + # jAppBrunel.optsfile = [File( BrunelOptsPath+"/Brunel_RichAlignMoni_"+dataVariant+"-"+brunelInitialInputType+".py")] jAppBrunel.optsfile = [ - File(BrunelOptsPath + "/Brunel_Rich" + - RichDetectorStr + "AlignMoni_" + - dataVariant + "-" + - brunelInitialInputType + ".py") + File( + BrunelOptsPath + + "/Brunel_Rich" + + RichDetectorStr + + "AlignMoni_" + + dataVariant + + "-" + + brunelInitialInputType + + ".py" + ) ] - print "### using the following Brunel options file:" - #print "### "+BrunelOptsPath+"/Brunel_RichAlignMoni_"+dataVariant+"-"+brunelInitialInputType+".py" - print "### " + BrunelOptsPath + "/Brunel_Rich" + RichDetectorStr + "AlignMoni_" + dataVariant + "-" + brunelInitialInputType + ".py" + print("### using the following Brunel options file:") + # print "### "+BrunelOptsPath+"/Brunel_RichAlignMoni_"+dataVariant+"-"+brunelInitialInputType+".py" + print( + "### " + + BrunelOptsPath + + "/Brunel_Rich" + + RichDetectorStr + + "AlignMoni_" + + dataVariant + + "-" + + brunelInitialInputType + + ".py" + ) DBSlices = [] DBSlicesNames = [] BrunelOptionsString = "" ThereAreAddedDBSlices = False LFNDBs = True - if len(AddedDB) > 0 and len( - AddedDB[0] - ) > 1 and backEnd == 'dirac': #note: can not use databases outside of dirac + if ( + len(AddedDB) > 0 + and len(AddedDB[0]) > 1 + and backEnd == "dirac" + ): # note: can not use databases outside of dirac ThereAreAddedDBSlices = True for i in range(0, len(AddedDB)): - if not AddedDB[i].startswith('LFN'): + if not AddedDB[i].startswith("LFN"): LFNDBs = False # databases are local AddedDB2 = AddedDB[i].split("/") for j in AddedDB2: - if (j.endswith(".db")): + if j.endswith(".db"): DBSlices.append(j) - print j + print(j) AddedDBName = j.split(".") for k in AddedDBName: if not k.endswith("db"): DBSlicesNames.append(k) - BrunelOptionsString = BrunelOptionsString + """CondDB().addLayer( CondDBAccessSvc(\'""" + DBSlicesNames[ - i] + """\', ConnectionString=\'sqlite_file:""" + DBSlices[ - i] + """/LHCBCOND\', DefaultTAG=\'HEAD\') )\n""" + BrunelOptionsString = ( + BrunelOptionsString + + """CondDB().addLayer( CondDBAccessSvc(\'""" + + DBSlicesNames[i] + + """\', ConnectionString=\'sqlite_file:""" + + DBSlices[i] + + """/LHCBCOND\', DefaultTAG=\'HEAD\') )\n""" + ) - print BrunelOptionsString + print(BrunelOptionsString) - if (dataVariant in collisionVariantList): + if dataVariant in collisionVariantList: tiltname = theseNamesWithTilts[tiltName] - jAppBrunel.extraopts = \ - "Brunel().DDDBtag = '{DDDB_tag}'\n" \ - "Brunel().CondDBtag = '{CondDB_tag}'\n" \ - "Brunel().EvtMax = {brunelEvtMax}\n" \ - "Brunel().PrintFreq = {brunelPrintFreq}\n" \ - "RichAlignmentConf ('OfflineRichMoni_RichAlignmentConf').setProp('Radiators', ['Rich{RichDetectorStr}Gas'])\n" \ - "MessageSvc().OutputLevel = {messageSvcOutputLevel}\n" \ - "RichAlignmentConf('OfflineRichMoni_RichAlignmentConf').setProp('DeltaThetaRange', [ 0.04,{delthetawin}, {delthetawin}])\n" \ - "CondDB().addLayer( CondDBAccessSvc('Rich{RichDetectorStr}AlignMirr', ConnectionString='sqlite_file:Mirrors_rich{RichDetectorStr}_{tiltname}.db/{CONDDB}', DefaultTAG='HEAD'))\n" \ - "from Configurables import EventClockSvc\n" \ - "EventClockSvc( InitialTime = {date} )\n" \ - "HistogramPersistencySvc().setProp('OutputFile', 'RichRecQCHistos_rich{RichDetectorStr}_{tiltname}_i{iterationCount}.root')\n" \ - "{BrunelOptionsString}\n" \ - "{BrunelOptionsString}\n".format(**locals()) - - jName = tiltInJobnameDict[ - tiltName] + thisCase + '_i' + str( - iterationCount) + jAppBrunel.extraopts = ( + "Brunel().DDDBtag = '{DDDB_tag}'\n" + "Brunel().CondDBtag = '{CondDB_tag}'\n" + "Brunel().EvtMax = {brunelEvtMax}\n" + "Brunel().PrintFreq = {brunelPrintFreq}\n" + "RichAlignmentConf ('OfflineRichMoni_RichAlignmentConf').setProp('Radiators', ['Rich{RichDetectorStr}Gas'])\n" + "MessageSvc().OutputLevel = {messageSvcOutputLevel}\n" + "RichAlignmentConf('OfflineRichMoni_RichAlignmentConf').setProp('DeltaThetaRange', [ 0.04,{delthetawin}, {delthetawin}])\n" + "CondDB().addLayer( CondDBAccessSvc('Rich{RichDetectorStr}AlignMirr', ConnectionString='sqlite_file:Mirrors_rich{RichDetectorStr}_{tiltname}.db/{CONDDB}', DefaultTAG='HEAD'))\n" + "from Configurables import EventClockSvc\n" + "EventClockSvc( InitialTime = {date} )\n" + "HistogramPersistencySvc().setProp('OutputFile', 'RichRecQCHistos_rich{RichDetectorStr}_{tiltname}_i{iterationCount}.root')\n" + "{BrunelOptionsString}\n" + "{BrunelOptionsString}\n".format(**locals()) + ) + + jName = ( + tiltInJobnameDict[tiltName] + + thisCase + + "_i" + + str(iterationCount) + ) j = Job( name=jName, application=jAppBrunel, splitter=jSplitter, - backend=jBackend) + backend=jBackend, + ) # For Ganga 6.1 and later, we'll leave this alone for now, hopefully it works try: tryString = eventSelectorInputFile + "abcd" except TypeError: - #print "Not a String" - for ff in range(0, - len(eventSelectorInputFile)): + # print "Not a String" + for ff in range(0, len(eventSelectorInputFile)): if ff == 0: j.inputdata = j.application.readInputData( - eventSelectorInputFile[ff]) + eventSelectorInputFile[ff] + ) else: j.inputdata.extend( j.application.readInputData( - eventSelectorInputFile[ff])) + eventSelectorInputFile[ff] + ) + ) else: - #print "String" + # print "String" j.inputdata = j.application.readInputData( - eventSelectorInputFile) + eventSelectorInputFile + ) - if (backEnd != 'dirac'): - print "Not Dirac" + if backEnd != "dirac": + print("Not Dirac") if GV61flag == False: j.inputsandbox += [ - workDir + "Mirrors_rich" + RichDetectorStr - + "_" + theseNamesWithTilts[tiltName] + - ".db" + workDir + + "Mirrors_rich" + + RichDetectorStr + + "_" + + theseNamesWithTilts[tiltName] + + ".db" ] else: j.inputfiles += [ - LocalFile(workDir + "Mirrors_rich" + - RichDetectorStr + "_" + - theseNamesWithTilts[tiltName] + - ".db") + LocalFile( + workDir + + "Mirrors_rich" + + RichDetectorStr + + "_" + + theseNamesWithTilts[tiltName] + + ".db" + ) ] if ThereAreAddedDBSlices == True and LFNDBs == True: if GV61flag == False: j.backend.inputSandboxLFNs = AddedDB # PN - Now we have some print statements to check that the AddedDBs from the settings file are as expected. - print "### j.backend.inputSandboxLFNs now reads:" + print("### j.backend.inputSandboxLFNs now reads:") for keys in j.backend.inputSandboxLFNs: - print keys + print(keys) else: - print "NOTE: This is UNTESTED in Ganga 6.1!!!! If it works, then please remove this print statement." + print( + "NOTE: This is UNTESTED in Ganga 6.1!!!! If it works, then please remove this print statement." + ) GV61AddedDB = [] for LFNstring in AddedDB: - if LFNstring.startswith('LFN:'): + if LFNstring.startswith("LFN:"): NewLFNstring = LFNstring[4:] else: NewLFNstring = LFNstring - GV61AddedDB.append( - DiracFile(lfn=NewLFNstring)) + GV61AddedDB.append(DiracFile(lfn=NewLFNstring)) j.inputfiles += GV61AddedDB if ThereAreAddedDBSlices == True and LFNDBs == False: - #print "NOTE: This Use Case NEEDS TO BE TESTED if you want to read .db from local files instead of LFNs (If it works, remove this print statement)" + # print "NOTE: This Use Case NEEDS TO BE TESTED if you want to read .db from local files instead of LFNs (If it works, remove this print statement)" if GV61flag == False: j.inputsandbox += AddedDB else: @@ -1515,103 +1917,126 @@ def mirroralign(RichInfoSettings="Something_Went_Wrong"): j.do_auto_resubmit = True # this automatically resubmits failed subjobs, *if* at least one of the subjobs completed - #Try it later + # Try it later # if GV61flag == True: # j.parallel_submit = True # Experimental parallel job submission, so we're trying it - print "### ----------------------------------------------------------------------------" - print j + print( + "### ----------------------------------------------------------------------------" + ) + print(j) ## Ban sites that fail # j.backend.settings['BannedSites'] = ['LCG.PIC.es','LCG.SARA.nl','LCG.NIKHEF.nl','LCG.CERN.ch'] ## Ban "ANY" sites by specifying remaining sites # j.backend.settings['Destination'] = ['LCG.GRIDKA.de','LCG.IN2P3.fr','LCG.CNAF.it'] - print strftime("%Y-%m-%d %H:%M:%S", gmtime()) - print "-------------------" + print(strftime("%Y-%m-%d %H:%M:%S", gmtime())) + print("-------------------") # j.submit() # Ganga 6 lets you parallelize this!!!!!!!! queues.add(j.submit) - print strftime("%Y-%m-%d %H:%M:%S", gmtime()) - print "-------------------" + print(strftime("%Y-%m-%d %H:%M:%S", gmtime())) + print("-------------------") jobIds.append(j.id) tilt_jobId[tiltName] = j.id jobId_tilt[j.id] = tiltName jobId_submittedSince[j.id] = time() - #------------------------------------------------------------------------------- + # ------------------------------------------------------------------------------- if ( - n_it % minors - ) == tiltNamesLength: # iteration 9,19...[1,3...] for tiltNamesLength = 9[1] - - #============================================================================ + (n_it % minors) == tiltNamesLength + ): # iteration 9,19...[1,3...] for tiltNamesLength = 9[1] + # ============================================================================ # end of loop over the tilts - #============================================================================ - #============================================================================ + # ============================================================================ + # ============================================================================ # Wait until enough subjobs have finished until we continue - #============================================================================ + # ============================================================================ # if iterationCount == 0 and skipFirstMergeJob == 1 : if skipFirstMergeJob == 1: - print "### ----------------------------------------------------------------------------" - print "### ---------- SKIPPING MERGE OF BRUNEL HISTOGRAMS FOR MAJOR ITERATION " + str( - iterationCount) + " -------------" - print "### ----------------------------------------------------------------------------" + print( + "### ----------------------------------------------------------------------------" + ) + print( + "### ---------- SKIPPING MERGE OF BRUNEL HISTOGRAMS FOR MAJOR ITERATION " + + str(iterationCount) + + " -------------" + ) + print( + "### ----------------------------------------------------------------------------" + ) skipFirstMergeJob = 0 else: # PN: Again, trying to make split this in two directions. # One is "GANGA" the other is "ONLINE" # # First, ONLINE - if (backEnd == 'online'): - print "ONLINE" + if backEnd == "online": + print("ONLINE") # Pause the Analyzers. The histograms from the first running should now be available state = State.PAUSED com.set_status(state) - print "The Analyzers will have finished running Brunel on the data by the time it gets here." - print "Loop over the tiltnames and merge the histos (maybe automatic)." - print "TO DO: swap outputdir stuff for where Online puts the histos and where we need our output." - print "Let's not worry about the adding for now" - print "Until the FSM control above is actually working" + print( + "The Analyzers will have finished running Brunel on the data by the time it gets here." + ) + print( + "Loop over the tiltnames and merge the histos (maybe automatic)." + ) + print( + "TO DO: swap outputdir stuff for where Online puts the histos and where we need our output." + ) + print("Let's not worry about the adding for now") + print("Until the FSM control above is actually working") # Set up some xml configuration here, that the next RUNNING will process. ## can't patch yet maybe don't need to so this is commented out - #if ( os.path.exists( workDir+"patch.py" ) ) : + # if ( os.path.exists( workDir+"patch.py" ) ) : # os.system("rm -rf "+workDir+"patch.p*") # to get rid of .pyc files, as if the .pyc file is still there it doesn't know that the patch has changed - #patchPyFile = open(workDir+'patch.py','w') - #patchPyFile.write('FullRichName = \'Rich'+RichDetectorStr+'\'\n') # python will convert \n to os.linesep - #patchPyFile.write('HistoName = \''+workDir+'Dummy2.root\'\n') - #patchPyFile.write('DeltaThetaRange = [ 0.04,'+delthetawin+', '+delthetawin+']\n') - #patchPyFile.close() + # patchPyFile = open(workDir+'patch.py','w') + # patchPyFile.write('FullRichName = \'Rich'+RichDetectorStr+'\'\n') # python will convert \n to os.linesep + # patchPyFile.write('HistoName = \''+workDir+'Dummy2.root\'\n') + # patchPyFile.write('DeltaThetaRange = [ 0.04,'+delthetawin+', '+delthetawin+']\n') + # patchPyFile.close() - #Actually we don't bother changing the xml file, as the next RUNNING will be scrapped + # Actually we don't bother changing the xml file, as the next RUNNING will be scrapped # Second, GANGA (i.e. not ONLINE) else: - print "GANGA" + print("GANGA") # we must first wait for the queues threads to finish their work. - print "Waiting for the queues threads to finish submitting all of the jobs." - print "-------------------" - - while (queues.totalNumUserThreads() > 0): - print "Total number of user threads still active %d" % queues.totalNumUserThreads( + print( + "Waiting for the queues threads to finish submitting all of the jobs." + ) + print("-------------------") + + while queues.totalNumUserThreads() > 0: + print( + "Total number of user threads still active %d" + % queues.totalNumUserThreads() ) - print strftime("%Y-%m-%d %H:%M:%S", gmtime()) - print "-------------------" + print(strftime("%Y-%m-%d %H:%M:%S", gmtime())) + print("-------------------") # create an empty file, can check the timestamp in your workDir to see if alignment is still running - os.system( - 'touch Mirrors_SubmittingJobs_touch.txt') + os.system("touch Mirrors_SubmittingJobs_touch.txt") sleep( 300 ) # check the status of the queues approx. every 5 minutes if skipFirstRecoJob != 1: - print "All jobs have been submitted for major iteration %d. Now we wait for 80 percent of the subjobs from each job to complete." % iterationCount + print( + "All jobs have been submitted for major iteration %d. Now we wait for 80 percent of the subjobs from each job to complete." + % iterationCount + ) else: - print "Checking jobIds from the Brunel reconstruction of major iteration %d" % iterationCount - print "-------------------" - #print "I am now going to give the command runMonitoring() [if we run this as a script and not from an interactive Ganga session, the monitoring loop does not run automatically]." - #print "If the monitoring loop is already running, the runMonitoring() command will give an ERROR. However this script should continue to run." - #runMonitoring() - print "-------------------" + print( + "Checking jobIds from the Brunel reconstruction of major iteration %d" + % iterationCount + ) + print("-------------------") + # print "I am now going to give the command runMonitoring() [if we run this as a script and not from an interactive Ganga session, the monitoring loop does not run automatically]." + # print "If the monitoring loop is already running, the runMonitoring() command will give an ERROR. However this script should continue to run." + # runMonitoring() + print("-------------------") # if iterationCount == 0 and skipFirstRecoJob == 1: if skipFirstRecoJob == 1: @@ -1621,75 +2046,78 @@ def mirroralign(RichInfoSettings="Something_Went_Wrong"): minutesCounter = 0 - while (len(jobIds) > 0): - - if (backEnd == 'dirac'): + while len(jobIds) > 0: + if backEnd == "dirac": os.system( - 'kinit -R' + "kinit -R" ) # renews your local AFS ticket [for up to 7 days, given that "kinit -fp -r 7d" was run from the submitting machine, I think] - os.system( - 'aklog') # renews your local AFS token + os.system("aklog") # renews your local AFS token # gridProxy.renew() # reactivate() # no longer needed, use -v 96:00 when you lhcb-proxy-init sleep( 60 ) # just wait to conserve CPU cycles, because some jobs are still not finished minutesCounter = minutesCounter + 1 - if ((minutesCounter % 15) == 0): - print "Still waiting for 80 percent of subjobs from all jobs to complete." - print strftime("%Y-%m-%d %H:%M:%S", - gmtime()) + if (minutesCounter % 15) == 0: + print( + "Still waiting for 80 percent of subjobs from all jobs to complete." + ) + print(strftime("%Y-%m-%d %H:%M:%S", gmtime())) # create an empty file, can check the timestamp in your workDir to see if alignment is still running os.system( - 'touch Mirrors_WaitingForSubjobs_touch.txt' + "touch Mirrors_WaitingForSubjobs_touch.txt" ) - print "-------------------" + print("-------------------") for jobId in jobIds: - sjIDs = [] sjIDsCompleted = [] for sj in jobs(jobId).subjobs: sjIDs.append(sj.id) - if ((sj.status == 'completed') - or (sj.status == 'failed')): + if (sj.status == "completed") or ( + sj.status == "failed" + ): sjIDsCompleted.append(sj.id) if ( - sj.status == 'new' + sj.status == "new" ): # PN - because we did j.do_auto_resubmit=True before, failed jobs get resubmitted, but I don't know if "new" jobs get resubmitted. So we keep this in. - print "Resubmitting subjob " + str( - sj.id) + print("Resubmitting subjob " + str(sj.id)) # Ganga 6 lets you parallelize this, but we don't want to as it's not expected to need much overhead. sj.submit() - if (float(len(sjIDsCompleted)) / float( - len(sjIDs)) > 0.8): - + if ( + float(len(sjIDsCompleted)) / float(len(sjIDs)) + > 0.8 + ): # create an empty file when any job has completed, can check the timestamp in your workDir to see if alignment is still running os.system( - 'touch Mirrors_LastJobCompleted_touch.txt' + "touch Mirrors_LastJobCompleted_touch.txt" ) - print "Job number " + str( - jobId - ) + " has " + str( - len(sjIDsCompleted) - ) + " out of " + str( - len(sjIDs) - ) + " subjobs completed or failed so will now merge the outputs\n" - print strftime("%Y-%m-%d %H:%M:%S", - gmtime()) - print "-------------------" - - rootFileName = "RichRecQCHistos_rich" + RichDetectorStr + "_" + theseNamesWithTilts[ - jobId_tilt[jobId]] + "_i" + str( - iterationCount) + ".root" - if (not (os.path.exists( - jobs(jobId).outputdir))): - os.system("mkdir " + - jobs(jobId).outputdir) - rootFile = jobs( - jobId).outputdir + rootFileName + print( + "Job number " + + str(jobId) + + " has " + + str(len(sjIDsCompleted)) + + " out of " + + str(len(sjIDs)) + + " subjobs completed or failed so will now merge the outputs\n" + ) + print(strftime("%Y-%m-%d %H:%M:%S", gmtime())) + print("-------------------") + + rootFileName = ( + "RichRecQCHistos_rich" + + RichDetectorStr + + "_" + + theseNamesWithTilts[jobId_tilt[jobId]] + + "_i" + + str(iterationCount) + + ".root" + ) + if not (os.path.exists(jobs(jobId).outputdir)): + os.system("mkdir " + jobs(jobId).outputdir) + rootFile = jobs(jobId).outputdir + rootFileName # # merge output histograms # p = Popen("export HOME="+home+";" @@ -1705,37 +2133,50 @@ def mirroralign(RichInfoSettings="Something_Went_Wrong"): # Claire's new merge output histograms import ROOT + mergesuccess = False - while (not mergesuccess): - os.system("rm -rf " + - jobs(jobId).outputdir + - rootFileName) + while not mergesuccess: + os.system( + "rm -rf " + + jobs(jobId).outputdir + + rootFileName + ) # merge output histograms p = Popen( - "export HOME=" + home + ";" + - "source " + pathToScripts + - "LbLogin.sh;" + - "export User_release_area=" + - userReleaseArea + ";" + - "source `which SetupProject.sh` Brunel " - + brunelVersion + " " + - setupProjectBrunelOpts + ";" + "export HOME=" + + home + + ";" + + "source " + + pathToScripts + + "LbLogin.sh;" + + "export User_release_area=" + + userReleaseArea + + ";" + + "source `which SetupProject.sh` Brunel " + + brunelVersion + + " " + + setupProjectBrunelOpts + + ";" # +"source `which SetupProject.sh` Gaudi;" - + "hadd " + - jobs(jobId).outputdir + - rootFileName + " " + - jobs(jobId).outputdir + - "../*/output/" + rootFileName + - ";", + + "hadd " + + jobs(jobId).outputdir + + rootFileName + + " " + + jobs(jobId).outputdir + + "../*/output/" + + rootFileName + + ";", shell=True, executable="/bin/bash", stdout=PIPE, - stderr=PIPE) + stderr=PIPE, + ) (stdout, stderr) = p.communicate() stdReport(stdout, stderr) - smerged = jobs( - jobId).outputdir + rootFileName + smerged = ( + jobs(jobId).outputdir + rootFileName + ) fmerged = ROOT.TFile.Open(smerged) if fmerged.GetStreamerInfoList(): mergesuccess = True @@ -1744,32 +2185,36 @@ def mirroralign(RichInfoSettings="Something_Went_Wrong"): fmerged.Close() # and now create link - os.system("ln -sf " + rootFile + " " + - rootFileName) + os.system( + "ln -sf " + rootFile + " " + rootFileName + ) # clear the diskspace - #rm_subjobs_except_0_last( jobs(jobId), rootFileName, brunelVer, backEnd ) + # rm_subjobs_except_0_last( jobs(jobId), rootFileName, brunelVer, backEnd ) - jobIds.remove( - jobId) # all done for this job + jobIds.remove(jobId) # all done for this job - print strftime("%Y-%m-%d %H:%M:%S", - gmtime()) - print "-------------------" + print(strftime("%Y-%m-%d %H:%M:%S", gmtime())) + print("-------------------") else: - - if ((minutesCounter % 15) == 0): + if (minutesCounter % 15) == 0: fracDone = math.ceil( - 100 * - (float(len(sjIDsCompleted)) / - float(len(sjIDs)))) - print "Job number " + str( - jobId - ) + " has just under %d percent of its subjobs completed or failed" % fracDone - - #============================================================================ - #============================================================================ + 100 + * ( + float(len(sjIDsCompleted)) + / float(len(sjIDs)) + ) + ) + print( + "Job number " + + str(jobId) + + " has just under %d percent of its subjobs completed or failed" + % fracDone + ) + + # ============================================================================ + # ============================================================================ # run per-combination fit to obtain the total tilts and the coefficients # Paras put this in to at least allow multiple instances of RichMirrCombinFit to run simultaneously, see later in the code as well @@ -1777,110 +2222,203 @@ def mirroralign(RichInfoSettings="Something_Went_Wrong"): # if iterationCount == 0 and skipFirstCombinFit == 1 : if skipFirstCombinFit == 1: - print "### ----------------------------------------------------------------------------" - print "### ---------- SKIPPING FITTING OF MERGED HISTOGRAMS ---------------------" - print "### ----------------------------------------------------------------------------" + print( + "### ----------------------------------------------------------------------------" + ) + print( + "### ---------- SKIPPING FITTING OF MERGED HISTOGRAMS ---------------------" + ) + print( + "### ----------------------------------------------------------------------------" + ) skipFirstCombinFit = 0 else: for tiltName in tiltNames: - - if (backEnd == 'dirac'): + if backEnd == "dirac": os.system( - 'kinit -R' + "kinit -R" ) # renews your local AFS ticket [for up to 7 days, given that "kinit -fp -r 7d" was run from the submitting machine, I think] - os.system( - 'aklog') # renews your local AFS token + os.system("aklog") # renews your local AFS token # gridProxy.renew() # reactivate() # no longer needed, use -v 96:00 when you lhcb-proxy-init - combinFitDir = workDir + "Rich" + RichDetectorStr + "MirrCombinFit_" + theseNamesWithTilts[ - tiltName] + "_i" + str( - iterationCount) + os.path.sep + combinFitDir = ( + workDir + + "Rich" + + RichDetectorStr + + "MirrCombinFit_" + + theseNamesWithTilts[tiltName] + + "_i" + + str(iterationCount) + + os.path.sep + ) combinFitPlotDir = combinFitDir + "plots" + os.path.sep - if (not (os.path.exists(combinFitPlotDir))): - os.system("mkdir --parents " + - combinFitPlotDir) - - combinResultsFile = combinFitDir + "Rich" + RichDetectorStr + "MirrCombinFit_" + theseNamesWithTilts[ - tiltName] + "_i" + str(iterationCount) + ".txt" - fitConfigFile = combinFitDir + "Rich" + RichDetectorStr + "MirrCombinFit_" + theseNamesWithTilts[ - tiltName] + "_i" + str( - iterationCount) + ".conf" - fitOutputFile = combinFitDir + "Rich" + RichDetectorStr + "MirrCombinFitOut_" + theseNamesWithTilts[ - tiltName] + "_i" + str(iterationCount) + ".txt" - fitStdOutFile = combinFitDir + "Rich" + RichDetectorStr + "MirrCombinFitStdOut_" + theseNamesWithTilts[ - tiltName] + "_i" + str(iterationCount) + ".txt" - fitStdErrFile = combinFitDir + "Rich" + RichDetectorStr + "MirrCombinFitStdErr_" + theseNamesWithTilts[ - tiltName] + "_i" + str(iterationCount) + ".txt" + if not (os.path.exists(combinFitPlotDir)): + os.system("mkdir --parents " + combinFitPlotDir) + + combinResultsFile = ( + combinFitDir + + "Rich" + + RichDetectorStr + + "MirrCombinFit_" + + theseNamesWithTilts[tiltName] + + "_i" + + str(iterationCount) + + ".txt" + ) + fitConfigFile = ( + combinFitDir + + "Rich" + + RichDetectorStr + + "MirrCombinFit_" + + theseNamesWithTilts[tiltName] + + "_i" + + str(iterationCount) + + ".conf" + ) + fitOutputFile = ( + combinFitDir + + "Rich" + + RichDetectorStr + + "MirrCombinFitOut_" + + theseNamesWithTilts[tiltName] + + "_i" + + str(iterationCount) + + ".txt" + ) + fitStdOutFile = ( + combinFitDir + + "Rich" + + RichDetectorStr + + "MirrCombinFitStdOut_" + + theseNamesWithTilts[tiltName] + + "_i" + + str(iterationCount) + + ".txt" + ) + fitStdErrFile = ( + combinFitDir + + "Rich" + + RichDetectorStr + + "MirrCombinFitStdErr_" + + theseNamesWithTilts[tiltName] + + "_i" + + str(iterationCount) + + ".txt" + ) # Paras thinks this should be removed. The only time we'd skip this is on major iteration zero if something went wrong - #if ( ( os.path.exists( combinResultsFile ) ) ) : + # if ( ( os.path.exists( combinResultsFile ) ) ) : # continue # Paras says, leave this naming convention alone - brunelHistoFile = "RichRecQCHistos_rich" + RichDetectorStr + "_" + theseNamesWithTilts[ - tiltName] + "_i" + str( - iterationCount) + ".root" + brunelHistoFile = ( + "RichRecQCHistos_rich" + + RichDetectorStr + + "_" + + theseNamesWithTilts[tiltName] + + "_i" + + str(iterationCount) + + ".root" + ) if os.path.exists(fitConfigFile): os.remove(fitConfigFile) - f = open(fitConfigFile, 'w') - args = 'plotDir = ' + combinFitPlotDir + '\n' - args += 'richDetector = ' + str( - richDetector) + '\n' - args += 'mirrCombinSubset = ' + workDir + mirrCombinSubset + '\n' - args += 'minAverageBinPop = ' + str( - minAverageBinPop) + '\n' - args += 'deltaThetaWindow = ' + str( - deltaThetaWindow) + '\n' - args += 'combinFitVariant = ' + str( - combinFitVariant) + '\n' - args += 'phiBinFactor = ' + str( - phiBinFactor) + '\n' - args += 'stopTolerance = ' + str( - stopTolerance) + '\n' - args += 'warningFactor = ' + str( - warningFactor) + '\n' - args += 'iterationCount = ' + str( - iterationCount) + '\n' - args += 'inputHistoFile = ' + str( - workDir + brunelHistoFile) + '\n' - args += 'outputResultsFile = ' + str( - combinResultsFile) + '\n' - args += 'plotOutputLevel = 2 \n' + f = open(fitConfigFile, "w") + args = "plotDir = " + combinFitPlotDir + "\n" + args += "richDetector = " + str(richDetector) + "\n" + args += ( + "mirrCombinSubset = " + + workDir + + mirrCombinSubset + + "\n" + ) + args += ( + "minAverageBinPop = " + str(minAverageBinPop) + "\n" + ) + args += ( + "deltaThetaWindow = " + str(deltaThetaWindow) + "\n" + ) + args += ( + "combinFitVariant = " + str(combinFitVariant) + "\n" + ) + args += "phiBinFactor = " + str(phiBinFactor) + "\n" + args += "stopTolerance = " + str(stopTolerance) + "\n" + args += "warningFactor = " + str(warningFactor) + "\n" + args += "iterationCount = " + str(iterationCount) + "\n" + args += ( + "inputHistoFile = " + + str(workDir + brunelHistoFile) + + "\n" + ) + args += ( + "outputResultsFile = " + str(combinResultsFile) + "\n" + ) + args += "plotOutputLevel = 2 \n" f.write(args) f.close() - print "### ----------------------------------------------------------------------------" - print "### We are still in major iteration %d" % iterationCount - print "### ----------------------------------------------------------------------------" - print "### running fitting program that yields total tilts being produced by each pair" - print "### of primary and secondary mirror segments out of a set of combinations chosen" - print "### in advance, and also the rotation-to-total-tilt magnification coefficients" - print "### for each mirror in such a pair:" - print "### ----------------------------------------------------------------------------" - print "### Now submitting subprocess for tilt named: " + theseNamesWithTilts[ - tiltName] - print "### ----------------------------------------------------------------------------" - print strftime("%Y-%m-%d %H:%M:%S", gmtime()) - print "-------------------" - - myStdOut = open(fitStdOutFile, 'w') - myStdErr = open(fitStdErrFile, 'w') + print( + "### ----------------------------------------------------------------------------" + ) + print( + "### We are still in major iteration %d" + % iterationCount + ) + print( + "### ----------------------------------------------------------------------------" + ) + print( + "### running fitting program that yields total tilts being produced by each pair" + ) + print( + "### of primary and secondary mirror segments out of a set of combinations chosen" + ) + print( + "### in advance, and also the rotation-to-total-tilt magnification coefficients" + ) + print("### for each mirror in such a pair:") + print( + "### ----------------------------------------------------------------------------" + ) + print( + "### Now submitting subprocess for tilt named: " + + theseNamesWithTilts[tiltName] + ) + print( + "### ----------------------------------------------------------------------------" + ) + print(strftime("%Y-%m-%d %H:%M:%S", gmtime())) + print("-------------------") + + myStdOut = open(fitStdOutFile, "w") + myStdErr = open(fitStdErrFile, "w") p = Popen( - "export HOME=" + home + ";" + - "export User_release_area=" + userReleaseArea + - ";" + "source " + pathToScripts + "LbLogin.sh;" - + "source `which SetupProject.sh` Panoptes " + - setupProjectPanoptesVersion + " " + - setupProjectPanoptesOptions + ";" + - "$RICHMIRRCOMBINFITROOT/$CMTCONFIG/RichMirrCombinFit.exe " - + fitConfigFile + " " + RichDetectorStr + - " 0 > " + fitOutputFile, + "export HOME=" + + home + + ";" + + "export User_release_area=" + + userReleaseArea + + ";" + + "source " + + pathToScripts + + "LbLogin.sh;" + + "source `which SetupProject.sh` Panoptes " + + setupProjectPanoptesVersion + + " " + + setupProjectPanoptesOptions + + ";" + + "$RICHMIRRCOMBINFITROOT/$CMTCONFIG/RichMirrCombinFit.exe " + + fitConfigFile + + " " + + RichDetectorStr + + " 0 > " + + fitOutputFile, shell=True, executable="/bin/bash", stdout=myStdOut, - stderr=myStdErr) + stderr=myStdErr, + ) myStdOut.close() myStdErr.close() # Add p to list of subprocesses @@ -1896,24 +2434,32 @@ def mirroralign(RichInfoSettings="Something_Went_Wrong"): if all([x is not None for x in ps_status]): PopenTotal = 0 for l in ps_status: - if l is not None: PopenTotal += 1 - print "%d of %d RichMirrCombinFit processes complete" % ( - PopenTotal, tiltNamesLength) - print strftime("%Y-%m-%d %H:%M:%S", gmtime()) - print "-------------------" + if l is not None: + PopenTotal += 1 + print( + "%d of %d RichMirrCombinFit processes complete" + % (PopenTotal, tiltNamesLength) + ) + print(strftime("%Y-%m-%d %H:%M:%S", gmtime())) + print("-------------------") break else: PopenDone = 0 for l in ps_status: - if l is not None: PopenDone += 1 + if l is not None: + PopenDone += 1 if PopenDone > PopenCount: - print "%d of %d RichMirrCombinFit processes complete" % ( - PopenDone, tiltNamesLength) - print strftime("%Y-%m-%d %H:%M:%S", gmtime()) - print "-------------------" - PopenCount = 0 + PopenDone # add the 0 so that PopenCount doesn't become a pointer to PopenNow + print( + "%d of %d RichMirrCombinFit processes complete" + % (PopenDone, tiltNamesLength) + ) + print(strftime("%Y-%m-%d %H:%M:%S", gmtime())) + print("-------------------") + PopenCount = ( + 0 + PopenDone + ) # add the 0 so that PopenCount doesn't become a pointer to PopenNow - #jid = j.id + # jid = j.id # wish to copy the output decision # PN - think this is now made after RichMirrAlign @@ -1923,56 +2469,117 @@ def mirroralign(RichInfoSettings="Something_Went_Wrong"): # NGEOutFile should have 0 lines in it # We only really need to check results from the current major iteration xml, not all of the tilts. # Numbers of photons should be approximately the same for each tilt. - combinFitDir_c = workDir + "Rich" + RichDetectorStr + "MirrCombinFit_" + thisNameStr + "_i" + str( - iterationCount) + os.path.sep - fitOutputFile_c = combinFitDir_c + "Rich" + RichDetectorStr + "MirrCombinFitOut_" + thisNameStr + "_i" + str( - iterationCount) + ".txt" - fitNGEFile_c = combinFitDir_c + "Rich" + RichDetectorStr + "MirrCombinFitNGEOut_" + thisNameStr + "_i" + str( - iterationCount) + ".txt" - os.system('cat ' + fitOutputFile_c + - ' | grep " not_good_enough " > ' + fitNGEFile_c) + combinFitDir_c = ( + workDir + + "Rich" + + RichDetectorStr + + "MirrCombinFit_" + + thisNameStr + + "_i" + + str(iterationCount) + + os.path.sep + ) + fitOutputFile_c = ( + combinFitDir_c + + "Rich" + + RichDetectorStr + + "MirrCombinFitOut_" + + thisNameStr + + "_i" + + str(iterationCount) + + ".txt" + ) + fitNGEFile_c = ( + combinFitDir_c + + "Rich" + + RichDetectorStr + + "MirrCombinFitNGEOut_" + + thisNameStr + + "_i" + + str(iterationCount) + + ".txt" + ) + os.system( + "cat " + + fitOutputFile_c + + ' | grep " not_good_enough " > ' + + fitNGEFile_c + ) num_lines = sum(1 for line in open(fitNGEFile_c)) - #print num_lines - if (num_lines != 0): + # print num_lines + if num_lines != 0: # Uncomment the lines in this if statement, if you are ready to use STOP_NGE to exit the alignment - print "### --------------------------------------------------------------------------------------------" + print( + "### --------------------------------------------------------------------------------------------" + ) # print "### No. "+str(iterationCount)+" major iteration's verdict is: STOP_NGE!" # print "### The mirror alignment has stopped, likely because there were not enough events for alignment." - print "### --------------------------------------------------------------------------------------------" + print( + "### --------------------------------------------------------------------------------------------" + ) iterations = " major iterations !" if iterationCount + 1 == 1: iterations = " major iteration !" - # print "### RICH"+RichDetectorStr+" mirror alignment is finished after "+str(iterationCount+1)+iterations - print strftime("%Y-%m-%d %H:%M:%S", gmtime()) - print "-------------------" + # print "### RICH"+RichDetectorStr+" mirror alignment is finished after "+str(iterationCount+1)+iterations + print(strftime("%Y-%m-%d %H:%M:%S", gmtime())) + print("-------------------") # os.system('echo "STOP_NGE" > '+"Rich"+RichDetectorStr+"_stop_or_continue.txt") # break [actually, NOW UNCOMMENTING THIS WON'T WORK... need to find another way to break the alignment] - print "STOP_NGE would have broken the alignment here due to lack of events, but we're just testing this feature right now and it is not implemented yet." - - #============================================================================ - #======================= FIND MAGNIFICATION FACTORS ========================= - #============================================================================ - - if (magnifCoeffMode == 2): - - print "### ----------------------------------------------------------------------------" - print "### -------------- CALCULATING THE MAGNIFICATION FACTORS ---------------" - print "### ----------------------------------------------------------------------------" - print strftime("%Y-%m-%d %H:%M:%S", gmtime()) - print "-------------------" + print( + "STOP_NGE would have broken the alignment here due to lack of events, but we're just testing this feature right now and it is not implemented yet." + ) + + # ============================================================================ + # ======================= FIND MAGNIFICATION FACTORS ========================= + # ============================================================================ + + if magnifCoeffMode == 2: + print( + "### ----------------------------------------------------------------------------" + ) + print( + "### -------------- CALCULATING THE MAGNIFICATION FACTORS ---------------" + ) + print( + "### ----------------------------------------------------------------------------" + ) + print(strftime("%Y-%m-%d %H:%M:%S", gmtime())) + print("-------------------") pNoTilt = [] for tiltNum, tiltName in enumerate(tiltNames): - - combinFitDir = workDir + "Rich" + RichDetectorStr + "MirrCombinFit_" + theseNamesWithTilts[ - tiltName] + "_i" + str( - iterationCount) + os.path.sep - combinResultsFile = combinFitDir + "Rich" + RichDetectorStr + "MirrCombinFit_" + theseNamesWithTilts[ - tiltName] + "_i" + str(iterationCount) + ".txt" - - magnificationOutputFile = workDir + "Rich" + RichDetectorStr + "MirrMagnFactors_" + theseNamesWithTilts[ - tiltName] + "_i" + str(iterationCount) + ".txt" + combinFitDir = ( + workDir + + "Rich" + + RichDetectorStr + + "MirrCombinFit_" + + theseNamesWithTilts[tiltName] + + "_i" + + str(iterationCount) + + os.path.sep + ) + combinResultsFile = ( + combinFitDir + + "Rich" + + RichDetectorStr + + "MirrCombinFit_" + + theseNamesWithTilts[tiltName] + + "_i" + + str(iterationCount) + + ".txt" + ) + + magnificationOutputFile = ( + workDir + + "Rich" + + RichDetectorStr + + "MirrMagnFactors_" + + theseNamesWithTilts[tiltName] + + "_i" + + str(iterationCount) + + ".txt" + ) # Each line in input file is as follows: | mirrorCombination | cos coeff | err(cos coeff) | sin coeff | err(sin coeff) pWithTilt = [] @@ -1986,14 +2593,16 @@ def mirroralign(RichInfoSettings="Something_Went_Wrong"): newpars = [] for i, j in enumerate(pars): - #print j + # print j if i == 0: - #newpars.append(j) + # newpars.append(j) newpars.append(str(j)) else: newpars.append(float(j)) - if tiltNum == 0: # just main fit results, no tilts for determination of magnification factors + if ( + tiltNum == 0 + ): # just main fit results, no tilts for determination of magnification factors pNoTilt.append(newpars) else: # fit results when mirrors were tilted for determination of magnification factors pWithTilt.append(newpars) @@ -2001,73 +2610,118 @@ def mirroralign(RichInfoSettings="Something_Went_Wrong"): line = fitfile.readline() if tiltNum != 0: # only when mirrors were tilted - with open(magnificationOutputFile, - 'w') as magfile: - + with open(magnificationOutputFile, "w") as magfile: for i, sp in enumerate(pWithTilt): tiltSign = 1.0 - if tiltName.count('neg') > 0: + if tiltName.count("neg") > 0: tiltSign = -1.0 mirrPair = sp[0] Y = (sp[1] - pNoTilt[i][1]) / ( - coeffCalibrTilt * tiltSign) + coeffCalibrTilt * tiltSign + ) Z = (sp[3] - pNoTilt[i][3]) / ( - coeffCalibrTilt * tiltSign) + coeffCalibrTilt * tiltSign + ) - #magfile.write("{mirrPair:4d} {Y: 9.5f} {Z: 9.5f}\n".format(**locals())) + # magfile.write("{mirrPair:4d} {Y: 9.5f} {Z: 9.5f}\n".format(**locals())) magfile.write( - "{mirrPair:s} {Y: 9.5f} {Z: 9.5f}\n" - .format(**locals())) + "{mirrPair:s} {Y: 9.5f} {Z: 9.5f}\n".format( + **locals() + ) + ) - #============================================================================ - #========================= START OF PER-MIRROR FIT ========================== - #============================================================================ + # ============================================================================ + # ========================= START OF PER-MIRROR FIT ========================== + # ============================================================================ # Rich2MirrAlign: misalignment correction for each mirror segment - #============================================================================ - - richMirrAlignConfFile = workDir + "Rich" + RichDetectorStr + "MirrAlign_i" + str( - iterationCount) + ".conf" - richMirrAlignOutFile = workDir + "Rich" + RichDetectorStr + "MirrAlignOut_i" + str( - iterationCount) + ".txt" - richMirrAlignNanOutFile = workDir + "Rich" + RichDetectorStr + "MirrAlignNanOut_i" + str( - iterationCount) + ".txt" + # ============================================================================ + + richMirrAlignConfFile = ( + workDir + + "Rich" + + RichDetectorStr + + "MirrAlign_i" + + str(iterationCount) + + ".conf" + ) + richMirrAlignOutFile = ( + workDir + + "Rich" + + RichDetectorStr + + "MirrAlignOut_i" + + str(iterationCount) + + ".txt" + ) + richMirrAlignNanOutFile = ( + workDir + + "Rich" + + RichDetectorStr + + "MirrAlignNanOut_i" + + str(iterationCount) + + ".txt" + ) # Let's not implement these for now - #richMirrAlignStdOutFile = "Rich"+RichDetectorStr+"MirrAlignStdOut_i"+str(iterationCount)+".txt" - #richMirrAlignStdErrFile = "Rich"+RichDetectorStr+"MirrAlignStdErr_i"+str(iterationCount)+".txt" - - combinFitDir = workDir + "Rich" + RichDetectorStr + "MirrCombinFit_" + theseNamesWithTilts[ - ""] + "_i" + str(iterationCount) + os.path.sep - combinResultsFile = combinFitDir + "Rich" + RichDetectorStr + "MirrCombinFit_" + theseNamesWithTilts[ - ""] + "_i" + str(iterationCount) + ".txt" + # richMirrAlignStdOutFile = "Rich"+RichDetectorStr+"MirrAlignStdOut_i"+str(iterationCount)+".txt" + # richMirrAlignStdErrFile = "Rich"+RichDetectorStr+"MirrAlignStdErr_i"+str(iterationCount)+".txt" + + combinFitDir = ( + workDir + + "Rich" + + RichDetectorStr + + "MirrCombinFit_" + + theseNamesWithTilts[""] + + "_i" + + str(iterationCount) + + os.path.sep + ) + combinResultsFile = ( + combinFitDir + + "Rich" + + RichDetectorStr + + "MirrCombinFit_" + + theseNamesWithTilts[""] + + "_i" + + str(iterationCount) + + ".txt" + ) if os.path.exists(richMirrAlignConfFile): os.remove(richMirrAlignConfFile) - f2 = open(richMirrAlignConfFile, 'w') - args = 'workDir = ' + workDir + '\n' - args += 'thisVariant = ' + thisNameStr + '\n' + f2 = open(richMirrAlignConfFile, "w") + args = "workDir = " + workDir + "\n" + args += "thisVariant = " + thisNameStr + "\n" # args += 'thisNameStr = '+thisNameStr +'\n' - args += 'richDetector = ' + str( - richDetector) + '\n' - args += 'magnFactorsMode = ' + str( - magnifCoeffMode) + '\n' + args += "richDetector = " + str(richDetector) + "\n" + args += "magnFactorsMode = " + str(magnifCoeffMode) + "\n" # args += 'magnifCoeffMode = '+str(magnifCoeffMode) +'\n' - args += 'solutionMethod = ' + str( - solutionMethod) + '\n' - args += 'usePremisaligned = ' + usePremisaligned + '\n' - args += 'iterationCount = ' + str( - iterationCount) + '\n' - args += 'combAndMirrSubsets = ' + workDir + mirrCombinSubset + '\n' + args += "solutionMethod = " + str(solutionMethod) + "\n" + args += "usePremisaligned = " + usePremisaligned + "\n" + args += "iterationCount = " + str(iterationCount) + "\n" + args += ( + "combAndMirrSubsets = " + workDir + mirrCombinSubset + "\n" + ) # args += 'mirrCombinSubset = '+workDir+mirrCombinSubset+'\n' - args += 'mirrCombinFitResults = ' + combinResultsFile + '\n' + args += "mirrCombinFitResults = " + combinResultsFile + "\n" # args += 'outputResultsFile = '+combinResultsFile+'\n' - args += 'stopTolerance = ' + str( - stopTolerance) + '\n' - args += 'zerothIterationXML = ' + workDir + zeroMirrorXMLFile + '\n' + args += "stopTolerance = " + str(stopTolerance) + "\n" + args += ( + "zerothIterationXML = " + workDir + zeroMirrorXMLFile + "\n" + ) # args += 'zerothIterationXMLFile = '+workDir+zeroMirrorXMLFile+'\n' # args += 'iterationZeroXMLFile = '+workDir+zeroMirrorXMLFile+'\n' # - args += 'currentIterationXML = ' + workDir + currentMirrorXMLFile + '\n' + args += ( + "currentIterationXML = " + + workDir + + currentMirrorXMLFile + + "\n" + ) # args += 'currentIterationXMLFile = '+workDir+currentMirrorXMLFile+'\n' - args += 'nextIterationXML = ' + workDir + nextIterationXMLFile + '\n' + args += ( + "nextIterationXML = " + + workDir + + nextIterationXMLFile + + "\n" + ) # args += 'nextIterationXMLFile = '+workDir+nextIterationXMLFile+'\n' f2.write(args) f2.close() @@ -2088,245 +2742,457 @@ def mirroralign(RichInfoSettings="Something_Went_Wrong"): We store them in Mirrors_rich2_thisNameStr_iterationCount+1.xml. """ - print "### ----------------------------------------------------------------------------" - print "### We are still in major iteration %d" % iterationCount - print "### ----------------------------------------------------------------------------" - print "### now running program that does the following:" - print "###" - print "### 1. finds individual misalignments of all Primary and Secondary mirror" - print "### segments" - print "###" - print "### 2. updates respective conditions in a temporary copy of RICH" + RichDetectorStr + " Mirrors.xml" - print "###" - print "### 3. if in result of this major iteration, absolute values of all calculated" - print "### improvements to the current misalignment compensations are < 0.1 mrad," - print "### the program decides that the mirrors are aligned, but of course applies" - print "### these final improvements although they are somewhat redundant" - print "### ----------------------------------------------------------------------------" - print strftime("%Y-%m-%d %H:%M:%S", gmtime()) - print "-------------------" + print( + "### ----------------------------------------------------------------------------" + ) + print("### We are still in major iteration %d" % iterationCount) + print( + "### ----------------------------------------------------------------------------" + ) + print("### now running program that does the following:") + print("###") + print( + "### 1. finds individual misalignments of all Primary and Secondary mirror" + ) + print("### segments") + print("###") + print( + "### 2. updates respective conditions in a temporary copy of RICH" + + RichDetectorStr + + " Mirrors.xml" + ) + print("###") + print( + "### 3. if in result of this major iteration, absolute values of all calculated" + ) + print( + "### improvements to the current misalignment compensations are < 0.1 mrad," + ) + print( + "### the program decides that the mirrors are aligned, but of course applies" + ) + print( + "### these final improvements although they are somewhat redundant" + ) + print( + "### ----------------------------------------------------------------------------" + ) + print(strftime("%Y-%m-%d %H:%M:%S", gmtime())) + print("-------------------") p = Popen( - "export HOME=" + home + ";" + "source " + - pathToScripts + "LbLogin.sh;" + - "export User_release_area=" + userReleaseArea + ";" + - "source `which SetupProject.sh` Panoptes " + - setupProjectPanoptesVersion + " " + - setupProjectPanoptesOptions + ";" + - "$RICHMIRRALIGNROOT/$CMTCONFIG/RichMirrAlign.exe " + - richMirrAlignConfFile + " > " + richMirrAlignOutFile, + "export HOME=" + + home + + ";" + + "source " + + pathToScripts + + "LbLogin.sh;" + + "export User_release_area=" + + userReleaseArea + + ";" + + "source `which SetupProject.sh` Panoptes " + + setupProjectPanoptesVersion + + " " + + setupProjectPanoptesOptions + + ";" + + "$RICHMIRRALIGNROOT/$CMTCONFIG/RichMirrAlign.exe " + + richMirrAlignConfFile + + " > " + + richMirrAlignOutFile, shell=True, executable="/bin/bash", stdout=PIPE, - stderr=PIPE) + stderr=PIPE, + ) (stdout, stderr) = p.communicate() stdReport(stdout, stderr) - #============================================================================ - if (backEnd == 'dirac' or backEnd == 'online'): - if os.path.isfile("Rich" + RichDetectorStr + - "CondDBUpdate_" + thisNameStr + - "_i" + str(iterationCount + 1) + - ".xml"): - just_prettify("Rich" + RichDetectorStr + - "CondDBUpdate_" + thisNameStr + - "_i" + str(iterationCount + 1) + - ".xml") - #======================== END OF PER-MIRROR CORRECTIONS ===================== + # ============================================================================ + if backEnd == "dirac" or backEnd == "online": + if os.path.isfile( + "Rich" + + RichDetectorStr + + "CondDBUpdate_" + + thisNameStr + + "_i" + + str(iterationCount + 1) + + ".xml" + ): + just_prettify( + "Rich" + + RichDetectorStr + + "CondDBUpdate_" + + thisNameStr + + "_i" + + str(iterationCount + 1) + + ".xml" + ) + # ======================== END OF PER-MIRROR CORRECTIONS ===================== """ break # <-- this can be used to run only one major iteration """ - #Check for nan values, NanOutFile should have 0 lines in it - os.system('cat ' + richMirrAlignOutFile + - ' | grep " nan " > ' + richMirrAlignNanOutFile) - os.system('cat ' + richMirrAlignOutFile + - ' | grep " -nan " > ' + richMirrAlignNanOutFile) - os.system('cat ' + richMirrAlignOutFile + - ' | grep " inf " > ' + richMirrAlignNanOutFile) - os.system('cat ' + richMirrAlignOutFile + - ' | grep " -inf " > ' + richMirrAlignNanOutFile) - #Check that you didn't accidentally run RichMirrCombinFit before merging histos - fitStdErrFileFirst = combinFitDir + "Rich" + RichDetectorStr + "MirrCombinFitStdErr_" + theseNamesWithTilts[ - ""] + "_i" + str(iterationCount) + ".txt" - os.system('cat ' + fitStdErrFileFirst + - ' | grep "root does not exist" > ' + - richMirrAlignNanOutFile) - num_lines = sum( - 1 for line in open(richMirrAlignNanOutFile)) - #print num_lines - if (num_lines != 0): - print "### --------------------------------------------------------------------------------------------" - print "### No. " + str( - iterationCount - ) + " major iteration's verdict is: STOP_NAN!" - print "### The mirror alignment has stopped, likely because there were not enough events for alignment." - print "### --------------------------------------------------------------------------------------------" + # Check for nan values, NanOutFile should have 0 lines in it + os.system( + "cat " + + richMirrAlignOutFile + + ' | grep " nan " > ' + + richMirrAlignNanOutFile + ) + os.system( + "cat " + + richMirrAlignOutFile + + ' | grep " -nan " > ' + + richMirrAlignNanOutFile + ) + os.system( + "cat " + + richMirrAlignOutFile + + ' | grep " inf " > ' + + richMirrAlignNanOutFile + ) + os.system( + "cat " + + richMirrAlignOutFile + + ' | grep " -inf " > ' + + richMirrAlignNanOutFile + ) + # Check that you didn't accidentally run RichMirrCombinFit before merging histos + fitStdErrFileFirst = ( + combinFitDir + + "Rich" + + RichDetectorStr + + "MirrCombinFitStdErr_" + + theseNamesWithTilts[""] + + "_i" + + str(iterationCount) + + ".txt" + ) + os.system( + "cat " + + fitStdErrFileFirst + + ' | grep "root does not exist" > ' + + richMirrAlignNanOutFile + ) + num_lines = sum(1 for line in open(richMirrAlignNanOutFile)) + # print num_lines + if num_lines != 0: + print( + "### --------------------------------------------------------------------------------------------" + ) + print( + "### No. " + + str(iterationCount) + + " major iteration's verdict is: STOP_NAN!" + ) + print( + "### The mirror alignment has stopped, likely because there were not enough events for alignment." + ) + print( + "### --------------------------------------------------------------------------------------------" + ) iterations = " major iterations !" if iterationCount + 1 == 1: iterations = " major iteration !" - print "### RICH" + RichDetectorStr + " mirror alignment is finished after " + str( - iterationCount + 1) + iterations - print strftime("%Y-%m-%d %H:%M:%S", gmtime()) - print "-------------------" - os.system('echo "STOP_NAN" > ' + "Rich" + - RichDetectorStr + "_stop_or_continue.txt") - #break - - Rich_stop_or_continue_txt = open("Rich" + RichDetectorStr + - "_stop_or_continue.txt") - verdict = Rich_stop_or_continue_txt.readline().strip( - ).upper() + print( + "### RICH" + + RichDetectorStr + + " mirror alignment is finished after " + + str(iterationCount + 1) + + iterations + ) + print(strftime("%Y-%m-%d %H:%M:%S", gmtime())) + print("-------------------") + os.system( + 'echo "STOP_NAN" > ' + + "Rich" + + RichDetectorStr + + "_stop_or_continue.txt" + ) + # break + + Rich_stop_or_continue_txt = open( + "Rich" + RichDetectorStr + "_stop_or_continue.txt" + ) + verdict = Rich_stop_or_continue_txt.readline().strip().upper() Rich_stop_or_continue_txt.close() # The iteration is officially done, now safe to reset skipFirstRecoJob skipFirstRecoJob = 0 - print "### ------------------------------------------------------------------------------" - print "### No. " + str( - iterationCount - ) + " major iteration's verdict is: " + verdict + "!" - print "### ------------------------------------------------------------------------------" - print strftime("%Y-%m-%d %H:%M:%S", gmtime()) - print "-------------------" - if (verdict == "STOP"): + print( + "### ------------------------------------------------------------------------------" + ) + print( + "### No. " + + str(iterationCount) + + " major iteration's verdict is: " + + verdict + + "!" + ) + print( + "### ------------------------------------------------------------------------------" + ) + print(strftime("%Y-%m-%d %H:%M:%S", gmtime())) + print("-------------------") + if verdict == "STOP": iterations = " major iterations !" if iterationCount + 1 == 1: iterations = " major iteration !" - print "### RICH" + RichDetectorStr + " mirror alignment is finished after " + str( - iterationCount + 1) + iterations + print( + "### RICH" + + RichDetectorStr + + " mirror alignment is finished after " + + str(iterationCount + 1) + + iterations + ) # softlink the final .xml file to be inside the directory structure needed to be converted into a DB slice - os.system("ln -sf " + workDir + "Rich" + - RichDetectorStr + "CondDBUpdate_" + - thisNameStr + "_i" + - str(iterationCount + 1) + ".xml " + - workDir + "Mirrors_rich" + RichDetectorStr + - "_" + thisNameStr + "/Conditions/Rich" + - RichDetectorStr + "/Alignment/Mirrors.xml") + os.system( + "ln -sf " + + workDir + + "Rich" + + RichDetectorStr + + "CondDBUpdate_" + + thisNameStr + + "_i" + + str(iterationCount + 1) + + ".xml " + + workDir + + "Mirrors_rich" + + RichDetectorStr + + "_" + + thisNameStr + + "/Conditions/Rich" + + RichDetectorStr + + "/Alignment/Mirrors.xml" + ) # PN - Apparently the current .db file has outlived its usefulness, if it is there, then remove it. # - A .db file will, of course, not be there for ONLINE - if (os.path.exists(workDir + "Mirrors_rich" + - RichDetectorStr + "_" + - thisNameStr + ".db")): - os.system("rm -rf " + workDir + "Mirrors_rich" + - RichDetectorStr + "_" + thisNameStr + - ".db") + if os.path.exists( + workDir + + "Mirrors_rich" + + RichDetectorStr + + "_" + + thisNameStr + + ".db" + ): + os.system( + "rm -rf " + + workDir + + "Mirrors_rich" + + RichDetectorStr + + "_" + + thisNameStr + + ".db" + ) # create a final conditions database slice # containing only the final Mirrors.xml branch # don't need to do this for ONLINE - if (backEnd != 'online'): - print "### ----------------------------------------------------------------------------" - print "### converting the whole final Mirrors.xml branch into SQLite format:" - print "### Note that this replaces " + workDir + "Mirrors_rich" + RichDetectorStr + "_" + thisNameStr + ".db with the final db slice." - print "### ----------------------------------------------------------------------------" + if backEnd != "online": + print( + "### ----------------------------------------------------------------------------" + ) + print( + "### converting the whole final Mirrors.xml branch into SQLite format:" + ) + print( + "### Note that this replaces " + + workDir + + "Mirrors_rich" + + RichDetectorStr + + "_" + + thisNameStr + + ".db with the final db slice." + ) + print( + "### ----------------------------------------------------------------------------" + ) # prepare CondDB sqlite_file, which will be additional layer to the main database - print "copy_files_to_db.py -s " + workDir + "Mirrors_rich" + RichDetectorStr + "_" + thisNameStr + " -c sqlite_file:Mirrors_rich" + RichDetectorStr + "_" + thisNameStr + ".db/" + CONDDB + print( + "copy_files_to_db.py -s " + + workDir + + "Mirrors_rich" + + RichDetectorStr + + "_" + + thisNameStr + + " -c sqlite_file:Mirrors_rich" + + RichDetectorStr + + "_" + + thisNameStr + + ".db/" + + CONDDB + ) p = Popen( - "export HOME=" + home + ";" + "source " + - pathToScripts + "LbLogin.sh;" + - "source `which SetupProject.sh` LHCb " + - LHCbVersion + " ;" + "copy_files_to_db.py -s " - + workDir + "Mirrors_rich" + RichDetectorStr + - "_" + thisNameStr + - " -c sqlite_file:Mirrors_rich" + - RichDetectorStr + "_" + thisNameStr + ".db/" + - CONDDB + ";" + "python " + PanoptesJobPath + - "/tagger.py " + CondDB_tag + " " + workDir + - "Mirrors_rich" + RichDetectorStr + "_" + - thisNameStr + " " + CONDDB, + "export HOME=" + + home + + ";" + + "source " + + pathToScripts + + "LbLogin.sh;" + + "source `which SetupProject.sh` LHCb " + + LHCbVersion + + " ;" + + "copy_files_to_db.py -s " + + workDir + + "Mirrors_rich" + + RichDetectorStr + + "_" + + thisNameStr + + " -c sqlite_file:Mirrors_rich" + + RichDetectorStr + + "_" + + thisNameStr + + ".db/" + + CONDDB + + ";" + + "python " + + PanoptesJobPath + + "/tagger.py " + + CondDB_tag + + " " + + workDir + + "Mirrors_rich" + + RichDetectorStr + + "_" + + thisNameStr + + " " + + CONDDB, shell=True, executable="/bin/bash", stdout=PIPE, - stderr=PIPE) + stderr=PIPE, + ) (stdout, stderr) = p.communicate() stdReport(stdout, stderr) - #break + # break - if (verdict != "STOP" and verdict != "STOP_NAN" and verdict - != "STOP_NGE"): #STOP_NGE not implemented yet - print "### updating SQLite copy of the whole Mirrors.xml branch:" - print "### ----------------------------------------------------------------------------" - """ + if ( + verdict != "STOP" + and verdict != "STOP_NAN" + and verdict != "STOP_NGE" + ): # STOP_NGE not implemented yet + print( + "### updating SQLite copy of the whole Mirrors.xml branch:" + ) + print( + "### ----------------------------------------------------------------------------" + ) + ( + """ so by now we have used up the current copy of - Mirrors_rich""" + RichDetectorStr + """_thisNameStr_iterationCount.xml that was utilized for the + Mirrors_rich""" + + RichDetectorStr + + """_thisNameStr_iterationCount.xml that was utilized for the reconstruction in this major iteration, and thus we increment the iterationCount and will now be using in the next major iteration the freshly produced by RichMirrAlign for us Mirrors_rich2_thisNameStr_iterationCount+1.xml """ + ) iterationCount += 1 - currentMirrorXMLFile = "Rich" + RichDetectorStr + "CondDBUpdate_" + thisNameStr + "_i" + str( - iterationCount) + ".xml" - nextIterationXMLFile = "Rich" + RichDetectorStr + "CondDBUpdate_" + thisNameStr + "_i" + str( - iterationCount + 1) + ".xml" - - print strftime("%Y-%m-%d %H:%M:%S", gmtime()) - print "-------------------" - - if (backEnd == 'online'): - print "We need to run the Analyzer every minor iteration" - state = State.RUNNING # note, we have to actually set this state later - if (verdict == "STOP" or verdict == "STOP_NAN" - or verdict == "STOP_NGE" - ): #STOP_NGE not implemented yet + currentMirrorXMLFile = ( + "Rich" + + RichDetectorStr + + "CondDBUpdate_" + + thisNameStr + + "_i" + + str(iterationCount) + + ".xml" + ) + nextIterationXMLFile = ( + "Rich" + + RichDetectorStr + + "CondDBUpdate_" + + thisNameStr + + "_i" + + str(iterationCount + 1) + + ".xml" + ) + + print(strftime("%Y-%m-%d %H:%M:%S", gmtime())) + print("-------------------") + + if backEnd == "online": + print("We need to run the Analyzer every minor iteration") + state = ( + State.RUNNING + ) # note, we have to actually set this state later + if ( + verdict == "STOP" + or verdict == "STOP_NAN" + or verdict == "STOP_NGE" + ): # STOP_NGE not implemented yet state = State.READY else: - if (verdict == "STOP" or verdict == "STOP_NAN" - or verdict == "STOP_NGE" - ): #STOP_NGE not implemented yet + if ( + verdict == "STOP" + or verdict == "STOP_NAN" + or verdict == "STOP_NGE" + ): # STOP_NGE not implemented yet break n_it += 1 # increase minor iteration number - if (backEnd == 'online'): + if backEnd == "online": # Set the status com.set_status(state) - #=============================================================================== + # =============================================================================== # end of loop over major iterations - #=============================================================================== + # =============================================================================== # the loop ended because either converged or reached the # maximum-number-of-major-iterations limit, so: - if (verdict == "CONTINUE"): - print "### ----------------------------------------------------------------------------" - print "### maximum-number-of-major-iterations limit (" + str( - maximumNumberOfIterations) + ") is reached, and the whole program" - print "### has to stop, but notice: RICH" + RichDetectorStr + " mirror alignment has NOT reached the" - print "### desired accuracy yet." - print "### ----------------------------------------------------------------------------" - - print 'The whole thing is done' - print 'You are here in the working directory:' - print os.getcwd() - print 'Now I have taken you back to your starting directory:' + if verdict == "CONTINUE": + print( + "### ----------------------------------------------------------------------------" + ) + print( + "### maximum-number-of-major-iterations limit (" + + str(maximumNumberOfIterations) + + ") is reached, and the whole program" + ) + print( + "### has to stop, but notice: RICH" + + RichDetectorStr + + " mirror alignment has NOT reached the" + ) + print("### desired accuracy yet.") + print( + "### ----------------------------------------------------------------------------" + ) + + print("The whole thing is done") + print("You are here in the working directory:") + print(os.getcwd()) + print("Now I have taken you back to your starting directory:") os.chdir(wasHere) - print os.getcwd() + print(os.getcwd()) - if (backEnd == 'online'): - print "ONLINE" + if backEnd == "online": + print("ONLINE") # Set our status one last time com.set_status(state) - print "com.set_status(state) one last time" + print("com.set_status(state) one last time") -#================================================================================= -#================================================================================= +# ================================================================================= +# ================================================================================= # This is the main program here. When this script is executed, it should run this: -print "Hi! All of the functions have now been defined. Time to run the RICH mirror alignment." -print strftime("%Y-%m-%d %H:%M:%S", gmtime()) -print "-------------------" +print( + "Hi! All of the functions have now been defined. Time to run the RICH mirror alignment." +) +print(strftime("%Y-%m-%d %H:%M:%S", gmtime())) +print("-------------------") if __name__ == "__main__": print( "This python file is being run directly, not being imported into another module." ) - print( - "mirroralign() is being called now, to perform the Offline mirror alignment." - ) - print strftime("%Y-%m-%d %H:%M:%S", gmtime()) - print "-------------------" - if (exists('RichInfoName')): + print("mirroralign() is being called now, to perform the Offline mirror alignment.") + print(strftime("%Y-%m-%d %H:%M:%S", gmtime())) + print("-------------------") + if exists("RichInfoName"): mirroralign(RichInfoName) else: mirroralign() @@ -2338,5 +3204,5 @@ else: print("mirroralign() will not be not run yet.") print("Now exiting the mirror alignment driver python script.") -print strftime("%Y-%m-%d %H:%M:%S", gmtime()) -print "-------------------" +print(strftime("%Y-%m-%d %H:%M:%S", gmtime())) +print("-------------------") diff --git a/Rich/RichMirrorAlignmentGanga/job/RichMirrorAlignmentGanga.py b/Rich/RichMirrorAlignmentGanga/job/RichMirrorAlignmentGanga.py index 18366c97cdc05829a2f3fa3d063a66806b7f3796..d9eef843944c156d4ef6381cb6ec18406f93c1f2 100644 --- a/Rich/RichMirrorAlignmentGanga/job/RichMirrorAlignmentGanga.py +++ b/Rich/RichMirrorAlignmentGanga/job/RichMirrorAlignmentGanga.py @@ -20,57 +20,54 @@ # See the TWiki and keep it up-to-date!! # https://twiki.cern.ch/twiki/bin/view/LHCb/LHCbRichMirrorAlign +import builtins import distutils +import importlib +import math import os import re import shutil import sys -import math - from distutils import dir_util from os.path import expandvars from subprocess import * -from time import sleep -from time import time -from time import gmtime, strftime - -import importlib -import __builtin__ +from time import gmtime, sleep, strftime, time -#=============================================================================== +# =============================================================================== # defs -#=============================================================================== +# =============================================================================== # listenToFSM def listenToFSM(com): - print "In listenToFSM" + print("In listenToFSM") -#=============================================================================== +# =============================================================================== # stdReport returns stdout and stderr from Popen.communicate() def stdReport(stdout, stderr): - print "The shell script gave some STANDARD OUTPUT:" - print stdout + print("The shell script gave some STANDARD OUTPUT:") + print(stdout) if stderr: - print "The shell script also gave some STANDARD ERROR:" - print stderr + print("The shell script also gave some STANDARD ERROR:") + print(stderr) else: - print "The shell script ran fine." + print("The shell script ran fine.") -#=============================================================================== +# =============================================================================== # exists checks to see if the name is in the locals/globals/builtin OR in obj if obj is not none) def exists(name, obj=None): if obj is None: - return (name in sys._getframe(1).f_locals # caller's locals - or name in sys._getframe(1).f_globals # caller's globals - or name in vars(__builtin__) # built-in - ) + return ( + name in sys._getframe(1).f_locals # caller's locals + or name in sys._getframe(1).f_globals # caller's globals + or name in vars(__builtin__) # built-in + ) else: return hasattr(obj, name) -#=============================================================================== +# =============================================================================== # staticVar reads in variables from a settings file def staticVar(varname, value): def decorate(func): @@ -84,17 +81,17 @@ def staticVar(varname, value): def getSettingsFile(InfoStr): if InfoStr in getSettingsFile.VarName: return getSettingsFile.VarName[InfoStr] - #print "InfoStr: %s" % InfoStr; - #SettingsFile = '/path/to/%s_python_file.py' % InfoStr - #SettingsFile = '/home/pnaik/cmtuser/Panoptes_v5r2/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/RMA_%s.py' % InfoStr - SettingsFile = '%s' % InfoStr - print "SettingsFile: %s" % SettingsFile + # print "InfoStr: %s" % InfoStr; + # SettingsFile = '/path/to/%s_python_file.py' % InfoStr + # SettingsFile = '/home/pnaik/cmtuser/Panoptes_v5r2/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/RMA_%s.py' % InfoStr + SettingsFile = "%s" % InfoStr + print("SettingsFile: %s" % SettingsFile) directory, filename = os.path.split(SettingsFile) - #print "directory: %s" % directory - #print "filename: %s" % filename + # print "directory: %s" % directory + # print "filename: %s" % filename name, extension = os.path.splitext(filename) - #print "name: %s" % name - #print "extension: %s" % extension + # print "name: %s" % name + # print "extension: %s" % extension sys.path.insert(1, directory) VarName = importlib.import_module(name) sys.path.remove(directory) @@ -102,18 +99,21 @@ def getSettingsFile(InfoStr): return VarName -#=============================================================================== +# =============================================================================== # sleep_until_state is currently NOT USED as far as PN knows # it only shows up in sleep_until_completed -def sleep_until_state(j, - timeout=None, - states=["completed"], - break_states=None, - sleep_period=60, - verbose=True): - print 'RMAG is in sleep_until_state' +def sleep_until_state( + j, + timeout=None, + states=["completed"], + break_states=None, + sleep_period=60, + verbose=True, +): + print("RMAG is in sleep_until_state") import os from time import sleep + """ Wait until the job reaches one of the specified states. @@ -129,52 +129,82 @@ def sleep_until_state(j, initial_timeout = timeout current_status = None - while (not (j.status in states) and (timeout > 0)): - if (current_status != j.status): + while not (j.status in states) and (timeout > 0): + if current_status != j.status: if verbose: - print "### ----------------------------------------------------------------------------" - print "### job " + str(j.id) + " previous status: \"" + str( - current_status) + "\" current status: \"" + str( - j.status) + "\"" + print( + "### ----------------------------------------------------------------------------" + ) + print( + "### job " + + str(j.id) + + ' previous status: "' + + str(current_status) + + '" current status: "' + + str(j.status) + + '"' + ) current_status = j.status - if ((type(break_states) == type([])) and (j.status in break_states)): + if (type(break_states) == type([])) and (j.status in break_states): if verbose: - print "### ----------------------------------------------------------------------------" - print "### job " + str(j.id) + " got status: \"" + str( - j.status) + "\" returns False" + print( + "### ----------------------------------------------------------------------------" + ) + print( + "### job " + + str(j.id) + + ' got status: "' + + str(j.status) + + '" returns False' + ) return False sleep(sleep_period) timeout -= sleep_period if timeout < 0: - print "### ----------------------------------------------------------------------------" - print "### job " + str( - j.id) + " sleep_until_state hit the timeout limit: " + str( - initial_timeout) + print( + "### ----------------------------------------------------------------------------" + ) + print( + "### job " + + str(j.id) + + " sleep_until_state hit the timeout limit: " + + str(initial_timeout) + ) if verbose: - print "### ----------------------------------------------------------------------------" - print "### job " + str(j.id) + " previous status: \"" + str( - current_status) + "\" current status: \"" + str(j.status) + "\"" - - return (j.status in states) - - -#=============================================================================== + print( + "### ----------------------------------------------------------------------------" + ) + print( + "### job " + + str(j.id) + + ' previous status: "' + + str(current_status) + + '" current status: "' + + str(j.status) + + '"' + ) + + return j.status in states + + +# =============================================================================== # sleep_until_completed is currently NOT USED as far as PN knows def sleep_until_completed(j, timeout=None): - print 'RMAG is in sleep_until_completed' + print("RMAG is in sleep_until_completed") global sleep_until_state - return sleep_until_state(j, timeout, ['completed', 'failed']) + return sleep_until_state(j, timeout, ["completed", "failed"]) -#=============================================================================== +# =============================================================================== # wait_until_exists is currently NOT USED as far as PN knows # it only shows up in rm_subjobs_except_0_last def wait_until_exists(j, filename, timeout=10 * 60, sleep_period=3): - print 'RMAG is in wait_until_exists' + print("RMAG is in wait_until_exists") import os from time import sleep - while (not (os.path.exists(filename)) and (timeout > 0)): + + while not (os.path.exists(filename)) and (timeout > 0): sleep(sleep_period) timeout -= sleep_period if timeout < 0: @@ -182,43 +212,53 @@ def wait_until_exists(j, filename, timeout=10 * 60, sleep_period=3): return True -#=============================================================================== +# =============================================================================== # rm_subjobs_except_0_last is currently NOT USED as far as PN knows -def rm_subjobs_except_0_last(j, - rootFile, - brunelVer, - backEnd='dirac', - timeout=10 * 60, - sleep_period=3): - print 'RMAG is in rm_subjobs_except_0_last' +def rm_subjobs_except_0_last( + j, rootFile, brunelVer, backEnd="dirac", timeout=10 * 60, sleep_period=3 +): + print("RMAG is in rm_subjobs_except_0_last") global wait_until_exists sjLast = len(j.subjobs.ids()) - 1 for sj in j.subjobs: - - if (not (sj.status in ['failed', 'killed'])): - if ((backEnd == 'dirac' and wait_until_exists( - sj, sj.outputdir + 'std.out', timeout, sleep_period) - and wait_until_exists(sj, sj.outputdir + 'stdout', timeout, - sleep_period) - and wait_until_exists( - sj, sj.outputdir + 'Step1_Ganga_Brunel_' + brunelVer + - '.log', timeout, sleep_period)) or - (backEnd != 'dirac' and wait_until_exists( - sj, sj.outputdir + '__jobstatus__', timeout, sleep_period) - and wait_until_exists(sj, sj.outputdir + '__syslog__', - timeout, sleep_period) - and wait_until_exists(sj, sj.outputdir + 'stderr', timeout, - sleep_period) - and wait_until_exists(sj, sj.outputdir + 'stdout', timeout, - sleep_period))): + if not (sj.status in ["failed", "killed"]): + if ( + backEnd == "dirac" + and wait_until_exists( + sj, sj.outputdir + "std.out", timeout, sleep_period + ) + and wait_until_exists( + sj, sj.outputdir + "stdout", timeout, sleep_period + ) + and wait_until_exists( + sj, + sj.outputdir + "Step1_Ganga_Brunel_" + brunelVer + ".log", + timeout, + sleep_period, + ) + ) or ( + backEnd != "dirac" + and wait_until_exists( + sj, sj.outputdir + "__jobstatus__", timeout, sleep_period + ) + and wait_until_exists( + sj, sj.outputdir + "__syslog__", timeout, sleep_period + ) + and wait_until_exists( + sj, sj.outputdir + "stderr", timeout, sleep_period + ) + and wait_until_exists( + sj, sj.outputdir + "stdout", timeout, sleep_period + ) + ): sjId = sj.id - if (sjId != 0 and sjId != sjLast): - j.peek('../' + str(sjId), 'rm -rf') + if sjId != 0 and sjId != sjLast: + j.peek("../" + str(sjId), "rm -rf") else: - sj.peek('../output/' + rootFile, 'rm -f') + sj.peek("../output/" + rootFile, "rm -f") -#=============================================================================== +# =============================================================================== # create_coeff_calibration_xml_files: using most recent Mirrors files, # manufacture from them modified Mirrors files # for evaluation of current magnification coefficients @@ -226,22 +266,22 @@ def rm_subjobs_except_0_last(j, # Paras changed this to take in the richDetector as input, # as in a python program this variable would otherwise not be in this scope. # def create_coeff_calibration_xml_files( inputFile=None, coeffCalibrTilt=0.5 ) : -def create_coeff_calibration_xml_files(inputFile=None, - coeffCalibrTilt=0.5, - richDetector=2): - import sys +def create_coeff_calibration_xml_files( + inputFile=None, coeffCalibrTilt=0.5, richDetector=2 +): import re - import fpformat + import sys from array import array + import fpformat from lxml import etree # Important! You need SetupProject Ganga pytools # or some other method (maybe modify python path) to get this module - print 'RMAG is in create_coeff_calibration_xml_files' + print("RMAG is in create_coeff_calibration_xml_files") # first cut inputFile into two parts: inputFileLeftPart and inputFileRightPart # and separate them - inputFilePartsRE = re.compile(r'([a-zA-Z0-9_\.]+)(_i[0-9]+\.xml)') + inputFilePartsRE = re.compile(r"([a-zA-Z0-9_\.]+)(_i[0-9]+\.xml)") inputFileParts = inputFilePartsRE.match(inputFile) inputFileLeftPart = inputFileParts.group(1) inputFileRightPart = inputFileParts.group(2) @@ -251,25 +291,25 @@ def create_coeff_calibration_xml_files(inputFile=None, """ # # prepare dictionary of sign names - signName = dict({'-': 'neg', '+': 'pos'}) + signName = dict({"-": "neg", "+": "pos"}) # prepare dictionary of sign-to-shift - signToShift = dict({'-': -coeffCalibrTilt, '+': coeffCalibrTilt}) + signToShift = dict({"-": -coeffCalibrTilt, "+": coeffCalibrTilt}) # prepare dictionary of mirror type names - mirrTypeName = dict({'pri': 'Sph', 'sec': 'Sec'}) + mirrTypeName = dict({"pri": "Sph", "sec": "Sec"}) # prepare dictionary of total mirror numbers if richDetector == 2: - totMirrNum = dict({'pri': 56, 'sec': 40}) + totMirrNum = dict({"pri": 56, "sec": 40}) if richDetector == 1: - totMirrNum = dict({'pri': 4, 'sec': 16}) + totMirrNum = dict({"pri": 4, "sec": 16}) # prepare dictionary of rotation vector's term sequence number depending on axis - seqNum = dict({'Y': 1, 'Z': 2}) + seqNum = dict({"Y": 1, "Z": 2}) # prepare regular expression - rotRE = re.compile(r'[\-|\+]?[0-9]+\.?[0-9]*|[\-|\+]?\.[0-9]+') + rotRE = re.compile(r"[\-|\+]?[0-9]+\.?[0-9]*|[\-|\+]?\.[0-9]+") # such an expression matches e.g. all of the following: -000 +20. 2.000 +0005.9000 .0 -.98 +.30000 """ for f in [-000, +20., 2.000, +0005.9000, .0, -.98, +.30000] : @@ -289,19 +329,16 @@ def create_coeff_calibration_xml_files(inputFile=None, rotValues = [] ## parse the tree and create DOM of it - #docOriginal = parse( inputFile ) + # docOriginal = parse( inputFile ) # loop over types of mirrors - for mirrType in ['pri', 'sec']: - + for mirrType in ["pri", "sec"]: # loop over axes - for axis in ['Y', 'Z']: - + for axis in ["Y", "Z"]: # loop over signs - for sign in ['-', '+']: - + for sign in ["-", "+"]: ## make a working copy in order not to parse each anew - #doc = docOriginal + # doc = docOriginal parser = etree.XMLParser(remove_blank_text=True) RichAlignmentConditions = etree.parse(inputFile, parser) """ @@ -310,24 +347,30 @@ def create_coeff_calibration_xml_files(inputFile=None, # loop over all mirrors of current type (primary/secondary) # total numbers of primary (spheric) and secondary (flat) mirrors are different for mirrNum in range(totMirrNum[mirrType]): - # array for matches in float - floatRotValues = array('f') + floatRotValues = array("f") # Different xml alignment names for the two Rich detectors - if (richDetector == 1): + if richDetector == 1: # store the whole element in dRotXYZ dRotXYZ = RichAlignmentConditions.xpath( - "//condition[@name='" + mirrTypeName[mirrType] + - "Mirror" + str(mirrNum) + - "_Align']/paramVector[@name='dRotXYZ']") + "//condition[@name='" + + mirrTypeName[mirrType] + + "Mirror" + + str(mirrNum) + + "_Align']/paramVector[@name='dRotXYZ']" + ) - if (richDetector == 2): + if richDetector == 2: # store the whole element in dRotXYZ dRotXYZ = RichAlignmentConditions.xpath( - "//condition[@name='Rich" + str(richDetector) + - mirrTypeName[mirrType] + "Mirror" + str(mirrNum) + - "_Align']/paramVector[@name='dRotXYZ']") + "//condition[@name='Rich" + + str(richDetector) + + mirrTypeName[mirrType] + + "Mirror" + + str(mirrNum) + + "_Align']/paramVector[@name='dRotXYZ']" + ) """ print(etree.tostring(dRotXYZ[0], pretty_print=True)) print(etree.tostring(dRotXYZ[0], pretty_print=True, method="text")) @@ -335,8 +378,8 @@ def create_coeff_calibration_xml_files(inputFile=None, # # store all three rotation correction values in the floatRotValues (float) array rotValues = rotRE.findall( - etree.tostring( - dRotXYZ[0], pretty_print=True, method="text")) + etree.tostring(dRotXYZ[0], pretty_print=True, method="text") + ) """ for i in range (3) : print rotValues[i] @@ -353,80 +396,96 @@ def create_coeff_calibration_xml_files(inputFile=None, # with the value of one of them shifted by +/- coeffCalibrTilt mrad floatRotValues[seqNum[axis]] += signToShift[sign] - dRotXYZ[0].text = fpformat.fix( - floatRotValues[0], 5) + '*mrad ' + fpformat.fix( - floatRotValues[1], 5) + '*mrad ' + fpformat.fix( - floatRotValues[2], 5) + '*mrad' + dRotXYZ[0].text = ( + fpformat.fix(floatRotValues[0], 5) + + "*mrad " + + fpformat.fix(floatRotValues[1], 5) + + "*mrad " + + fpformat.fix(floatRotValues[2], 5) + + "*mrad" + ) """ print(etree.tostring(dRotXYZ[0], pretty_print=True, encoding='iso-8859-1')) """ # - if axis == 'Y': - signCombinName = signName[sign] + 'YzerZ' + if axis == "Y": + signCombinName = signName[sign] + "YzerZ" else: - signCombinName = 'zerY' + signName[sign] + 'Z' + signCombinName = "zerY" + signName[sign] + "Z" newXML_File = open( - inputFileLeftPart + '_' + mirrType + '_' + signCombinName + - inputFileRightPart, 'w') + inputFileLeftPart + + "_" + + mirrType + + "_" + + signCombinName + + inputFileRightPart, + "w", + ) newXML_File.write( etree.tostring( RichAlignmentConditions, - encoding='iso-8859-1', + encoding="iso-8859-1", xml_declaration=True, pretty_print=True, - with_tail=False)) + with_tail=False, + ) + ) newXML_File.close() -#=============================================================================== +# =============================================================================== # just_prettify def just_prettify(inputFile=None): - print 'RMAG is in just_prettify' + print("RMAG is in just_prettify") from lxml import etree + parser = etree.XMLParser(remove_blank_text=True) RichAlignmentConditions = etree.parse(inputFile, parser) - newXML_File = open(inputFile, 'w') + newXML_File = open(inputFile, "w") newXML_File.write( etree.tostring( RichAlignmentConditions, - encoding='iso-8859-1', + encoding="iso-8859-1", xml_declaration=True, pretty_print=True, - with_tail=False)) + with_tail=False, + ) + ) newXML_File.close() -#=============================================================================== +# =============================================================================== # mirroralign retrieves necessary environment variables, and does the work of alignment: def mirroralign(RichInfoSettings="Something_Went_Wrong"): - #def mirroralign() : - print 'RMAG is in mirroralign(' + RichInfoSettings + ')' - print strftime("%Y-%m-%d %H:%M:%S", gmtime()) - print "-------------------" + # def mirroralign() : + print("RMAG is in mirroralign(" + RichInfoSettings + ")") + print(strftime("%Y-%m-%d %H:%M:%S", gmtime())) + print("-------------------") # Paras - NEW: get settings from file, put them into RichInfo, instead of expecting them to already be in locals()... - print "RichInfoSettings: %s" % RichInfoSettings + print("RichInfoSettings: %s" % RichInfoSettings) RichInfo = getSettingsFile(RichInfoSettings) # OLD VERSION # Paras - eventually we want to pass this into the script somehow, to allow us to select the appropriate settings file # Paras - for now, if RichInfoName is already defined in globals() before we run this script then we will use that otherwise use the default # Paras - for now, RichInfoNameLocal should be the file name with full path information - #if (exists('RichInfoName')) : + # if (exists('RichInfoName')) : # print "RichInfoName: %s" % RichInfoName # RichInfoNameLocal = RichInfoName - #else : + # else : # #RichInfoNameLocal = "./RichMirrorAlignmentGanga_Collision10_settings_R2MD.py" # RichInfoNameLocal = "Something_Went_Wrong" # print "RichInfoNameLocal: %s" % RichInfoNameLocal - #RichInfo = getSettingsFile(RichInfoNameLocal) + # RichInfo = getSettingsFile(RichInfoNameLocal) RichInfoMembers = [ - attr for attr in dir(RichInfo) + attr + for attr in dir(RichInfo) if not callable(getattr(RichInfo, attr)) and not attr.startswith("__") ] - print "RichInfoMembers:" - print RichInfoMembers + print("RichInfoMembers:") + print(RichInfoMembers) # We no longer do HPD alignment, so the following is not important HPDiteration = 0 @@ -441,383 +500,409 @@ def mirroralign(RichInfoSettings="Something_Went_Wrong"): exec(key + " = RichInfo." + key) # Paras - check that what we need is among the local, global, and system variables now (of course, they should only be in locals()) - if (exists('workDir') == 0 or workDir == ""): + if exists("workDir") == 0 or workDir == "": workDir = "sorry, you must define your working directory !" exitFlag = True - if (exists('dDDB_tag') == 0): + if exists("dDDB_tag") == 0: dDDB_tag = "" - if (exists('condDB_tag') == 0): + if exists("condDB_tag") == 0: condDB_tag = "" - if (exists('date') == 0): + if exists("date") == 0: date = "" # note that you can set this one if you want to use # LocalCondDB_tag=localCondDB_tag instead of LocalCondDB_tag=CondDB_tag # And of course, I don't see LocalCondDB_tag actually being used anywhere in this script... candidate for deletion? - if (exists('localCondDB_tag') == 0): + if exists("localCondDB_tag") == 0: localCondDB_tag = "" - if (exists('setupProjectBrunelOpts') == 0): + if exists("setupProjectBrunelOpts") == 0: setupProjectBrunelOpts = "" - if (exists('eventSelectorInputFile') == 0 or eventSelectorInputFile == ""): + if exists("eventSelectorInputFile") == 0 or eventSelectorInputFile == "": eventSelectorInputFile = "sorry, you must define your input !" exitFlag = True - if (exists('brunelVersion') == 0 or brunelVersion == ""): - brunelVersion = 'v47r5' + if exists("brunelVersion") == 0 or brunelVersion == "": + brunelVersion = "v47r5" - if (exists('LHCbVersion') == 0 or LHCbVersion == ""): - LHCbVersion = 'v36r2' + if exists("LHCbVersion") == 0 or LHCbVersion == "": + LHCbVersion = "v36r2" - if (exists('brunelEvtMax') == 0 or brunelEvtMax == ""): + if exists("brunelEvtMax") == 0 or brunelEvtMax == "": brunelEvtMax = "100" - if (exists('brunelPrintFreq') == 0 or brunelPrintFreq == ""): + if exists("brunelPrintFreq") == 0 or brunelPrintFreq == "": brunelPrintFreq = "10" - if (exists('brunelInitialInputType') == 0 or brunelInitialInputType == ""): + if exists("brunelInitialInputType") == 0 or brunelInitialInputType == "": brunelInitialInputType = "RAW" - if (exists('messageSvcOutputLevel') == 0 or messageSvcOutputLevel == ""): + if exists("messageSvcOutputLevel") == 0 or messageSvcOutputLevel == "": messageSvcOutputLevel = "7" - if (exists('splitFilesPerJob') == 0 or splitFilesPerJob == ""): + if exists("splitFilesPerJob") == 0 or splitFilesPerJob == "": splitFilesPerJob = 1 - if (exists('splitMaxFiles') == 0 or splitMaxFiles == ""): + if exists("splitMaxFiles") == 0 or splitMaxFiles == "": splitMaxFiles = 1 - if (exists('backEnd') == 0 or backEnd == ""): + if exists("backEnd") == 0 or backEnd == "": backEnd = "LSF_8nm" - if (exists('diracCPUTime') == 0 or diracCPUTime == ""): + if exists("diracCPUTime") == 0 or diracCPUTime == "": diracCPUTime = 12000 - if (exists('mirrCombinSubset') == 0 or mirrCombinSubset == ""): + if exists("mirrCombinSubset") == 0 or mirrCombinSubset == "": mirrCombinSubset = "17un18eq" - if (exists('thisCase') == 0): + if exists("thisCase") == 0: thisCase = "" - if (exists('dataVariant') == 0 or dataVariant == ""): + if exists("dataVariant") == 0 or dataVariant == "": dataVariant = "sorry, you must define your data variant !" exitFlag = True - if (exists('minAverageBinPop') == 0 or minAverageBinPop == ""): + if exists("minAverageBinPop") == 0 or minAverageBinPop == "": minAverageBinPop = 6.0 - if (exists('deltaThetaWindow') == 0 or deltaThetaWindow == ""): + if exists("deltaThetaWindow") == 0 or deltaThetaWindow == "": deltaThetaWindow = 4.0 - if (exists('coeffCalibrTilt') == 0 or coeffCalibrTilt == ""): + if exists("coeffCalibrTilt") == 0 or coeffCalibrTilt == "": coeffCalibrTilt = 0.3 - if (exists('useTruth') == 0): + if exists("useTruth") == 0: useTruth = "" - if (exists('useOffsetsFromMC') == 0 or useOffsetsFromMC == ""): + if exists("useOffsetsFromMC") == 0 or useOffsetsFromMC == "": useOffsetsFromMC = "false" - if (exists('verOffsetsFromMC') == 0): + if exists("verOffsetsFromMC") == 0: verOffsetsFromMC = "" - if (exists('usePremisaligned') == 0 or usePremisaligned == ""): + if exists("usePremisaligned") == 0 or usePremisaligned == "": usePremisaligned = "false" # leave empty unless needed for usePremisaligned - if (exists('verPremisaligned') == 0): + if exists("verPremisaligned") == 0: verPremisaligned = "" - if (exists('useSpecificAlignment') == 0 or useSpecificAlignment == ""): + if exists("useSpecificAlignment") == 0 or useSpecificAlignment == "": useSpecificAlignment = "false" # leave empty unless needed for useSpecificAlignment - if (exists('specificAlignment') == 0): + if exists("specificAlignment") == 0: specificAlignment = "" - if (exists('combinFitVariant') == 0 or combinFitVariant == ""): + if exists("combinFitVariant") == 0 or combinFitVariant == "": combinFitVariant = 3 - if (exists('maximumNumberOfIterations') == 0 - or maximumNumberOfIterations == ""): + if exists("maximumNumberOfIterations") == 0 or maximumNumberOfIterations == "": maximumNumberOfIterations = 8 - if (exists('startFromIteration') == 0 or startFromIteration == ""): + if exists("startFromIteration") == 0 or startFromIteration == "": startFromIteration = 0 - if (exists('richDetector') == 0 or richDetector == ""): + if exists("richDetector") == 0 or richDetector == "": richDetector = 2 - if (exists('magnifCoeffMode') == 0 or magnifCoeffMode == ""): + if exists("magnifCoeffMode") == 0 or magnifCoeffMode == "": magnifCoeffMode = 2 - if (exists('solutionMethod') == 0 or solutionMethod == ""): + if exists("solutionMethod") == 0 or solutionMethod == "": solutionMethod = 1 - if (exists('alignHPDs') == 0 or alignHPDs == ""): + if exists("alignHPDs") == 0 or alignHPDs == "": alignHPDs = "false" - if (exists('AddedDB') == 0): + if exists("AddedDB") == 0: AddedDB = [""] # Paras - These were somehow forgotten before, or new, so I add them here for completeness - if (exists('home') == 0 or home == ""): + if exists("home") == 0 or home == "": home = "sorry, you must define your home !" exitFlag = True - if (exists('userReleaseArea') == 0 or userReleaseArea == ""): + if exists("userReleaseArea") == 0 or userReleaseArea == "": userReleaseArea = "sorry, you must define your userReleaseArea !" exitFlag = True - if (exists('userReleaseArea') == 0 or userReleaseArea == ""): + if exists("userReleaseArea") == 0 or userReleaseArea == "": userReleaseArea = "sorry, you must define your userReleaseArea !" exitFlag = True - if (exists('pathToScripts') == 0 or pathToScripts == ""): + if exists("pathToScripts") == 0 or pathToScripts == "": pathToScripts = "sorry, you must define your pathToScripts !" exitFlag = True - if (exists('RICHMIRRCOMBINFITROOT') == 0 or RICHMIRRCOMBINFITROOT == ""): + if exists("RICHMIRRCOMBINFITROOT") == 0 or RICHMIRRCOMBINFITROOT == "": RICHMIRRCOMBINFITROOT = "sorry, you must define your RICHMIRRCOMBINFITROOT !" exitFlag = True - if (exists('RICHMIRRORALIGNMENTGANGAROOT') == 0 - or RICHMIRRORALIGNMENTGANGAROOT == ""): - RICHMIRRORALIGNMENTGANGAROOT = "sorry, you must define your RICHMIRRORALIGNMENTGANGAROOT !" + if ( + exists("RICHMIRRORALIGNMENTGANGAROOT") == 0 + or RICHMIRRORALIGNMENTGANGAROOT == "" + ): + RICHMIRRORALIGNMENTGANGAROOT = ( + "sorry, you must define your RICHMIRRORALIGNMENTGANGAROOT !" + ) exitFlag = True - if (exists('SQLITEDBPATH') == 0 or SQLITEDBPATH == ""): + if exists("SQLITEDBPATH") == 0 or SQLITEDBPATH == "": SQLITEDBPATH = "sorry, you must define your SQLITEDBPATH !" exitFlag = True - if (exists('previousJobNumbers') == 0 or previousJobNumbers == ""): - previousJobNumbers = range(899, 901) + if exists("previousJobNumbers") == 0 or previousJobNumbers == "": + previousJobNumbers = list(range(899, 901)) - if (exists('skipFirstCombinFit') == 0 or skipFirstCombinFit == ""): + if exists("skipFirstCombinFit") == 0 or skipFirstCombinFit == "": skipFirstCombinFit = 0 - if (exists('skipFirstRecoJob') == 0 or skipFirstRecoJob == ""): + if exists("skipFirstRecoJob") == 0 or skipFirstRecoJob == "": skipFirstRecoJob = 0 - if (exists('skipFirstMergeJob') == 0 or skipFirstMergeJob == ""): + if exists("skipFirstMergeJob") == 0 or skipFirstMergeJob == "": skipFirstMergeJob = 0 - if (exists('justGlobalFit') == 0 or justGlobalFit == ""): + if exists("justGlobalFit") == 0 or justGlobalFit == "": justGlobalFit = 0 - if (exists('stopTolerance') == 0 or stopTolerance == ""): + if exists("stopTolerance") == 0 or stopTolerance == "": stopTolerance = 0.1 # in mrad - if (exists('warningFactor') == 0 or warningFactor == ""): + if exists("warningFactor") == 0 or warningFactor == "": warningFactor = 20 - if (exists('phiBinFactor') == 0 or phiBinFactor == ""): + if exists("phiBinFactor") == 0 or phiBinFactor == "": phiBinFactor = 1 # PN - These are apparently unused in this script - if (exists('APPCONFIGOPTS') == 0): + if exists("APPCONFIGOPTS") == 0: APPCONFIGOPTS = "" - if (exists('thisAppConfigBrunelOpts') == 0 - or thisAppConfigBrunelOpts == ""): + if exists("thisAppConfigBrunelOpts") == 0 or thisAppConfigBrunelOpts == "": thisAppConfigBrunelOpts = "Default" brunelEvtMax = str(brunelEvtMax) brunelPrintFreq = str(brunelPrintFreq) messageSvcOutputLevel = str(messageSvcOutputLevel) - print "### ----------------------------------------------------------------------------" - print "### OK, here are the parameters that will be used (default, unless you defined" - print "### them for me in the settings file):" + print( + "### ----------------------------------------------------------------------------" + ) + print( + "### OK, here are the parameters that will be used (default, unless you defined" + ) + print("### them for me in the settings file):") # Directory paths, like workDir, should end with os.path.sep # Please ensure this is the case in the _settings_ file! - print "###" - print "### workDir = " + workDir - - print "### dDDB_tag = " + dDDB_tag - print "### condDB_tag = " + condDB_tag - print "### date = " + date - print "### localCondDB_tag = " + localCondDB_tag - - print "### setupProjectBrunelOpts = " + setupProjectBrunelOpts - - print "### eventSelectorInputFile = " + eventSelectorInputFile - print "### LHCbVersion = " + LHCbVersion - print "### brunelVersion = " + brunelVersion - print "### brunelEvtMax = " + brunelEvtMax - print "### brunelPrintFreq = " + brunelPrintFreq - print "### brunelInitialInputType = " + brunelInitialInputType - print "### messageSvcOutputLevel = " + messageSvcOutputLevel - - print "### splitFilesPerJob = " + str(splitFilesPerJob) - print "### splitMaxFiles = " + str(splitMaxFiles) - print "### backEnd = " + backEnd + print("###") + print("### workDir = " + workDir) + + print("### dDDB_tag = " + dDDB_tag) + print("### condDB_tag = " + condDB_tag) + print("### date = " + date) + print("### localCondDB_tag = " + localCondDB_tag) + + print("### setupProjectBrunelOpts = " + setupProjectBrunelOpts) + + print("### eventSelectorInputFile = " + eventSelectorInputFile) + print("### LHCbVersion = " + LHCbVersion) + print("### brunelVersion = " + brunelVersion) + print("### brunelEvtMax = " + brunelEvtMax) + print("### brunelPrintFreq = " + brunelPrintFreq) + print("### brunelInitialInputType = " + brunelInitialInputType) + print("### messageSvcOutputLevel = " + messageSvcOutputLevel) + + print("### splitFilesPerJob = " + str(splitFilesPerJob)) + print("### splitMaxFiles = " + str(splitMaxFiles)) + print("### backEnd = " + backEnd) backEnd = str(backEnd.lower()) - if (backEnd == 'dirac'): - print "### diracCPUTime = " + str(diracCPUTime) + if backEnd == "dirac": + print("### diracCPUTime = " + str(diracCPUTime)) - print "### mirrCombinSubset = " + mirrCombinSubset - print "### thisCase = " + thisCase - print "### dataVariant = " + dataVariant + print("### mirrCombinSubset = " + mirrCombinSubset) + print("### thisCase = " + thisCase) + print("### dataVariant = " + dataVariant) - print "### minAverageBinPop = " + str(minAverageBinPop) - print "### deltaThetaWindow = " + str(deltaThetaWindow) + print("### minAverageBinPop = " + str(minAverageBinPop)) + print("### deltaThetaWindow = " + str(deltaThetaWindow)) - print "### coeffCalibrTilt = " + str(coeffCalibrTilt) + print("### coeffCalibrTilt = " + str(coeffCalibrTilt)) - print "### useTruth = " + useTruth + print("### useTruth = " + useTruth) - print "### useOffsetsFromMC = " + useOffsetsFromMC - print "### alignHPDs = " + alignHPDs + print("### useOffsetsFromMC = " + useOffsetsFromMC) + print("### alignHPDs = " + alignHPDs) - print "### AddedDB = " - print AddedDB + print("### AddedDB = ") + print(AddedDB) # print "### AddedDB = "+str(len(AddedDB)) - useOffsets = (useOffsetsFromMC.lower() == "true" - or useOffsetsFromMC.lower() == "yes") - if (useOffsets): + useOffsets = useOffsetsFromMC.lower() == "true" or useOffsetsFromMC.lower() == "yes" + if useOffsets: useOffsetsFromMC = "true" - print "### verOffsetsFromMC = " + verOffsetsFromMC + print("### verOffsetsFromMC = " + verOffsetsFromMC) else: useOffsetsFromMC = "false" - print "### usePremisaligned = " + usePremisaligned - premisaligned = (usePremisaligned.lower() == "true" - or usePremisaligned.lower() == "yes") - if (premisaligned): + print("### usePremisaligned = " + usePremisaligned) + premisaligned = ( + usePremisaligned.lower() == "true" or usePremisaligned.lower() == "yes" + ) + if premisaligned: usePremisaligned = "true" - print "### verPremisaligned = " + verPremisaligned + print("### verPremisaligned = " + verPremisaligned) else: usePremisaligned = "false" - print "### useSpecificAlignment = " + useSpecificAlignment - specific = (useSpecificAlignment.lower() == "true" - or usePremisaligned.lower() == "yes") - if (specific): + print("### useSpecificAlignment = " + useSpecificAlignment) + specific = ( + useSpecificAlignment.lower() == "true" or usePremisaligned.lower() == "yes" + ) + if specific: useSpecificAlignment = "true" - print "### specificAlignment = " + specificAlignment + print("### specificAlignment = " + specificAlignment) else: useSpecificAlignment = "false" - print "### combinFitVariant = " + str(combinFitVariant) + print("### combinFitVariant = " + str(combinFitVariant)) - print "### maximumNumberOfIterations = " + str( - maximumNumberOfIterations) + print("### maximumNumberOfIterations = " + str(maximumNumberOfIterations)) - print "### startFromIteration = " + str(startFromIteration) + print("### startFromIteration = " + str(startFromIteration)) - print "### richDetector = " + str(richDetector) + print("### richDetector = " + str(richDetector)) - print "### solutionMethod = " + str(solutionMethod) + print("### solutionMethod = " + str(solutionMethod)) # And the additional stuff - print "### home = " + str(home) - print "### userReleaseArea = " + str(userReleaseArea) - print "### pathToScripts = " + str(pathToScripts) - print "### RICHMIRRALIGNROOT = " + str(RICHMIRRALIGNROOT) - print "### RICHMIRRCOMBINFITROOT = " + str(RICHMIRRCOMBINFITROOT) - print "### RICHMIRRORALIGNMENTGANGAROOT = " + str( - RICHMIRRORALIGNMENTGANGAROOT) - print "### SQLITEDBPATH = " + str(SQLITEDBPATH) - print "### previousJobNumbers = " - print previousJobNumbers - - print "### skipFirstCombinFit = " + str(skipFirstCombinFit) - print "### skipFirstRecoJob = " + str(skipFirstRecoJob) - print "### skipFirstMergeJob = " + str(skipFirstMergeJob) - - print "### justGlobalFit = " + str(justGlobalFit) - - print "### APPCONFIGOPTS = " + APPCONFIGOPTS - print "### thisAppConfigBrunelOpts = " + thisAppConfigBrunelOpts - - print "### stopTolerance = " + str(stopTolerance) - print "### warningFactor = " + str(warningFactor) - print "### phiBinFactor = " + str(phiBinFactor) - - print "### ----------------------------------------------------------------------------" - - if (exitFlag): - print "### ----------------------------------------------------------------------------" - print "### sorry, not enough information for running: check the settings file content !" - print "### ----------------------------------------------------------------------------" + print("### home = " + str(home)) + print("### userReleaseArea = " + str(userReleaseArea)) + print("### pathToScripts = " + str(pathToScripts)) + print("### RICHMIRRALIGNROOT = " + str(RICHMIRRALIGNROOT)) + print("### RICHMIRRCOMBINFITROOT = " + str(RICHMIRRCOMBINFITROOT)) + print("### RICHMIRRORALIGNMENTGANGAROOT = " + str(RICHMIRRORALIGNMENTGANGAROOT)) + print("### SQLITEDBPATH = " + str(SQLITEDBPATH)) + print("### previousJobNumbers = ") + print(previousJobNumbers) + + print("### skipFirstCombinFit = " + str(skipFirstCombinFit)) + print("### skipFirstRecoJob = " + str(skipFirstRecoJob)) + print("### skipFirstMergeJob = " + str(skipFirstMergeJob)) + + print("### justGlobalFit = " + str(justGlobalFit)) + + print("### APPCONFIGOPTS = " + APPCONFIGOPTS) + print("### thisAppConfigBrunelOpts = " + thisAppConfigBrunelOpts) + + print("### stopTolerance = " + str(stopTolerance)) + print("### warningFactor = " + str(warningFactor)) + print("### phiBinFactor = " + str(phiBinFactor)) + + print( + "### ----------------------------------------------------------------------------" + ) + + if exitFlag: + print( + "### ----------------------------------------------------------------------------" + ) + print( + "### sorry, not enough information for running: check the settings file content !" + ) + print( + "### ----------------------------------------------------------------------------" + ) sys.exit(1) - print "You are currently in this directory:" + print("You are currently in this directory:") wasHere = os.getcwd() - print wasHere - print "You are now in the working directory:" + print(wasHere) + print("You are now in the working directory:") os.chdir(workDir) - print os.getcwd() + print(os.getcwd()) - #------------------------------------------------------------------------------- + # ------------------------------------------------------------------------------- # PN - No longer necessary. You should have defined this in your _settings_ file # - #pathToScripts = "/afs/cern.ch/lhcb/software/releases/LBSCRIPTS/prod/InstallArea/scripts" - #if not pathToScripts.endswith(os.path.sep): + # pathToScripts = "/afs/cern.ch/lhcb/software/releases/LBSCRIPTS/prod/InstallArea/scripts" + # if not pathToScripts.endswith(os.path.sep): # pathToScripts += os.path.sep - #------------------------------------------------------------------------------- + # ------------------------------------------------------------------------------- # just not to forget later... RichDetectorStr = str(richDetector) iterationCount = startFromIteration - #------------------------------------------------------------------------------- - if (dataVariant == "Collision09" or dataVariant == "Collision10" - or dataVariant == "Collision11" or dataVariant == "Collision12" - or dataVariant == "Collision15"): + # ------------------------------------------------------------------------------- + if ( + dataVariant == "Collision09" + or dataVariant == "Collision10" + or dataVariant == "Collision11" + or dataVariant == "Collision12" + or dataVariant == "Collision15" + ): CONDDB = "LHCBCOND" - #setupProjectBrunelOpts += " --use-grid" + # setupProjectBrunelOpts += " --use-grid" else: CONDDB = "SIMCOND" - #------------------------------------------------------------------------------- + # ------------------------------------------------------------------------------- DDDB_tag = dDDB_tag CondDB_tag = condDB_tag - #------------------------------------------------------------------------------- - if (localCondDB_tag != ''): + # ------------------------------------------------------------------------------- + if localCondDB_tag != "": LocalCondDB_tag = localCondDB_tag else: LocalCondDB_tag = CondDB_tag - #------------------------------------------------------------------------------- + # ------------------------------------------------------------------------------- # this is the case when the magnification coefficients are independent of the # sign of the rotation - if (magnifCoeffMode == 0 or magnifCoeffMode == 1): + if magnifCoeffMode == 0 or magnifCoeffMode == 1: tiltInJobnameDict = dict({"": ""}) tiltNames = [""] # and this is the case when the magnification coefficients are dependent on the # sign of the rotation - if (magnifCoeffMode == 2): + if magnifCoeffMode == 2: # in case of 2 we must run 9 times over the same data files during each # iteration: one normal and 8 with 8 calibration-modified XML files to # evaluate the magnification coefficients, all 9 jobs in parallel, therefore we # prepare a convenient dictionary for the job names - tiltInJobnameDict = dict({ - "": "", - "pri_negYzerZ": "p_nz_", - "pri_posYzerZ": "p_pz_", - "pri_zerYnegZ": "p_zn_", - "pri_zerYposZ": "p_zp_", - "sec_negYzerZ": "s_nz_", - "sec_posYzerZ": "s_pz_", - "sec_zerYnegZ": "s_zn_", - "sec_zerYposZ": "s_zp_" - }) - #------------------------------------------------------------------------------------------------------------------------------------------------ + tiltInJobnameDict = dict( + { + "": "", + "pri_negYzerZ": "p_nz_", + "pri_posYzerZ": "p_pz_", + "pri_zerYnegZ": "p_zn_", + "pri_zerYposZ": "p_zp_", + "sec_negYzerZ": "s_nz_", + "sec_posYzerZ": "s_pz_", + "sec_zerYnegZ": "s_zn_", + "sec_zerYposZ": "s_zp_", + } + ) + # ------------------------------------------------------------------------------------------------------------------------------------------------ tiltNames = [ - "", "pri_negYzerZ", "pri_posYzerZ", "pri_zerYnegZ", "pri_zerYposZ", - "sec_negYzerZ", "sec_posYzerZ", "sec_zerYnegZ", "sec_zerYposZ" + "", + "pri_negYzerZ", + "pri_posYzerZ", + "pri_zerYnegZ", + "pri_zerYposZ", + "sec_negYzerZ", + "sec_posYzerZ", + "sec_zerYnegZ", + "sec_zerYposZ", ] - #------------------------------------------------------------------------------- + # ------------------------------------------------------------------------------- # also, here is the right place to prepare directories for the main # and for the coefficient variants branches # for that, we already need proper long names (but without iteration number) @@ -829,26 +914,26 @@ def mirroralign(RichInfoSettings="Something_Went_Wrong"): thisTuning += "Cm" + str(magnifCoeffMode) thisTuning += "Sm" + str(solutionMethod) - if ("" != useTruth): + if "" != useTruth: thisTuning += "Tr" + useTruth.lower() - if (useOffsets): + if useOffsets: thisTuning += "Of" - #thisCaseStr += "_"+thisTuning + # thisCaseStr += "_"+thisTuning thisCaseStr += thisTuning - #------------------------------------------------------------------------------- - if (useOffsets and verOffsetsFromMC == ''): + # ------------------------------------------------------------------------------- + if useOffsets and verOffsetsFromMC == "": verOffsetsFromMC = thisCase + "_" + dataVariant - #------------------------------------------------------------------------------- - if (premisaligned): + # ------------------------------------------------------------------------------- + if premisaligned: thisCaseExtended = thisCase + "_" + verPremisaligned else: thisCaseExtended = thisCase - #------------------------------------------------------------------------------- + # ------------------------------------------------------------------------------- # we need thisNameStr for preparation of the misaligned xml files, etc. # in case where we do not need any loops over the tilts thisNameStr = thisCaseStr + "_" + thisCaseExtended + "_" + dataVariant @@ -856,65 +941,90 @@ def mirroralign(RichInfoSettings="Something_Went_Wrong"): theseNamesWithTilts = {} for tiltName in tiltNames: - - if (tiltName == ""): + if tiltName == "": theseNamesWithTilts[tiltName] = thisNameStr else: - theseNamesWithTilts[ - tiltName] = thisCaseStr + "_" + thisCaseExtended + "_" + dataVariant + "_" + tiltName + theseNamesWithTilts[tiltName] = ( + thisCaseStr + + "_" + + thisCaseExtended + + "_" + + dataVariant + + "_" + + tiltName + ) # clean-up the directories for the branches # Paras believes this only needs to be done once, if we are running completely from scratch - if (iterationCount == 0 and not skipFirstRecoJob == 1 - and not skipFirstMergeJob == 1 - and not skipFirstCombinFit == 1): - if os.path.exists("Mirrors_rich" + RichDetectorStr + "_" + - theseNamesWithTilts[tiltName]): - dir_util.remove_tree("Mirrors_rich" + RichDetectorStr + "_" + - theseNamesWithTilts[tiltName]) + if ( + iterationCount == 0 + and not skipFirstRecoJob == 1 + and not skipFirstMergeJob == 1 + and not skipFirstCombinFit == 1 + ): + if os.path.exists( + "Mirrors_rich" + RichDetectorStr + "_" + theseNamesWithTilts[tiltName] + ): + dir_util.remove_tree( + "Mirrors_rich" + + RichDetectorStr + + "_" + + theseNamesWithTilts[tiltName] + ) - #------------------------------------------------------------------------------- + # ------------------------------------------------------------------------------- # Sam found that we have to rename stuff to get this to work # ONLY doing this for magnifCoeffMode == 0 for now. - if (magnifCoeffMode == 0): - + if magnifCoeffMode == 0: alternateTiltNames = [ - "pri_negYzerZ", "pri_posYzerZ", "pri_zerYnegZ", "pri_zerYposZ", - "sec_negYzerZ", "sec_posYzerZ", "sec_zerYnegZ", "sec_zerYposZ" + "pri_negYzerZ", + "pri_posYzerZ", + "pri_zerYnegZ", + "pri_zerYposZ", + "sec_negYzerZ", + "sec_posYzerZ", + "sec_zerYnegZ", + "sec_zerYposZ", ] - print alternateTiltNames + print(alternateTiltNames) theseNamesWithOtherTilts = {} for alternateTiltName in alternateTiltNames: - - theseNamesWithOtherTilts[ - alternateTiltName] = thisCaseStr + "_" + thisCaseExtended + "_" + dataVariant + "_" + alternateTiltName - - print theseNamesWithOtherTilts + theseNamesWithOtherTilts[alternateTiltName] = ( + thisCaseStr + + "_" + + thisCaseExtended + + "_" + + dataVariant + + "_" + + alternateTiltName + ) + + print(theseNamesWithOtherTilts) # ultra-rubbish way to deal with this - if (richDetector == 1): + if richDetector == 1: weHaveFileList = [ - workDir + 'Rich1FixedMirrCoeff_pri_negYzerZ_1.0mr.txt', - workDir + 'Rich1FixedMirrCoeff_pri_posYzerZ_1.0mr.txt', - workDir + 'Rich1FixedMirrCoeff_pri_zerYnegZ_1.0mr.txt', - workDir + 'Rich1FixedMirrCoeff_pri_zerYposZ_1.0mr.txt', - workDir + 'Rich1FixedMirrCoeff_sec_negYzerZ_1.0mr.txt', - workDir + 'Rich1FixedMirrCoeff_sec_posYzerZ_1.0mr.txt', - workDir + 'Rich1FixedMirrCoeff_sec_zerYnegZ_1.0mr.txt', - workDir + 'Rich1FixedMirrCoeff_sec_zerYposZ_1.0mr.txt' + workDir + "Rich1FixedMirrCoeff_pri_negYzerZ_1.0mr.txt", + workDir + "Rich1FixedMirrCoeff_pri_posYzerZ_1.0mr.txt", + workDir + "Rich1FixedMirrCoeff_pri_zerYnegZ_1.0mr.txt", + workDir + "Rich1FixedMirrCoeff_pri_zerYposZ_1.0mr.txt", + workDir + "Rich1FixedMirrCoeff_sec_negYzerZ_1.0mr.txt", + workDir + "Rich1FixedMirrCoeff_sec_posYzerZ_1.0mr.txt", + workDir + "Rich1FixedMirrCoeff_sec_zerYnegZ_1.0mr.txt", + workDir + "Rich1FixedMirrCoeff_sec_zerYposZ_1.0mr.txt", ] else: weHaveFileList = [ - workDir + 'Rich2FixedMirrCoeff_pri_negYzerZ_1.0mr.txt', - workDir + 'Rich2FixedMirrCoeff_pri_posYzerZ_1.0mr.txt', - workDir + 'Rich2FixedMirrCoeff_pri_zerYnegZ_1.0mr.txt', - workDir + 'Rich2FixedMirrCoeff_pri_zerYposZ_1.0mr.txt', - workDir + 'Rich2FixedMirrCoeff_sec_negYzerZ_1.0mr.txt', - workDir + 'Rich2FixedMirrCoeff_sec_posYzerZ_1.0mr.txt', - workDir + 'Rich2FixedMirrCoeff_sec_zerYnegZ_1.0mr.txt', - workDir + 'Rich2FixedMirrCoeff_sec_zerYposZ_1.0mr.txt' + workDir + "Rich2FixedMirrCoeff_pri_negYzerZ_1.0mr.txt", + workDir + "Rich2FixedMirrCoeff_pri_posYzerZ_1.0mr.txt", + workDir + "Rich2FixedMirrCoeff_pri_zerYnegZ_1.0mr.txt", + workDir + "Rich2FixedMirrCoeff_pri_zerYposZ_1.0mr.txt", + workDir + "Rich2FixedMirrCoeff_sec_negYzerZ_1.0mr.txt", + workDir + "Rich2FixedMirrCoeff_sec_posYzerZ_1.0mr.txt", + workDir + "Rich2FixedMirrCoeff_sec_zerYnegZ_1.0mr.txt", + workDir + "Rich2FixedMirrCoeff_sec_zerYposZ_1.0mr.txt", ] weHaveFileListIterator = 0 @@ -922,179 +1032,327 @@ def mirroralign(RichInfoSettings="Something_Went_Wrong"): for alternateTiltName in alternateTiltNames: # length of weHaveFileList better be the same as alternateTiltNames if os.path.exists(weHaveFileList[weHaveFileListIterator]): - mirrAlignExpectsFile = workDir + "Rich" + RichDetectorStr + "MirrMagnFactors_" + theseNamesWithOtherTilts[ - alternateTiltName] + "_predefined.txt" - print "moving" + weHaveFileList[ - weHaveFileListIterator] + " to " + mirrAlignExpectsFile - os.system("cp " + weHaveFileList[weHaveFileListIterator] + - " " + mirrAlignExpectsFile) - #os.remove( weHaveFileList[weHaveFileListIterator] ) + mirrAlignExpectsFile = ( + workDir + + "Rich" + + RichDetectorStr + + "MirrMagnFactors_" + + theseNamesWithOtherTilts[alternateTiltName] + + "_predefined.txt" + ) + print( + "moving" + + weHaveFileList[weHaveFileListIterator] + + " to " + + mirrAlignExpectsFile + ) + os.system( + "cp " + + weHaveFileList[weHaveFileListIterator] + + " " + + mirrAlignExpectsFile + ) + # os.remove( weHaveFileList[weHaveFileListIterator] ) weHaveFileListIterator += 1 os.system("rm -rf *_1.0mr.txt") """ if the iterationCount == 0 Before we start any iterations, let us prepare local XML copy of the DB """ - #------------------------------------------------------------------------------- + # ------------------------------------------------------------------------------- # Paras believes this only needs to be done once, if we are running completely from scratch - if (iterationCount == 0 and not skipFirstRecoJob == 1 - and not skipFirstMergeJob == 1 and not skipFirstCombinFit == 1): + if ( + iterationCount == 0 + and not skipFirstRecoJob == 1 + and not skipFirstMergeJob == 1 + and not skipFirstCombinFit == 1 + ): # if ( iterationCount == 0 or skipFirstRecoJob == 1 ) : - if (premisaligned): - print "### creating appropriate local /Alignment branch, like in the official CondDB," - print "### and preparing a working copy of the premisaligned Mirrors.xml :" - print "### ----------------------------------------------------------------------------" - dir_util.mkpath("Mirrors_rich" + RichDetectorStr + "_" + - thisNameStr + "/Conditions/Rich" + - RichDetectorStr + "/Alignment") - #------------------------------------------------------------------------------- + if premisaligned: + print( + "### creating appropriate local /Alignment branch, like in the official CondDB," + ) + print("### and preparing a working copy of the premisaligned Mirrors.xml :") + print( + "### ----------------------------------------------------------------------------" + ) + dir_util.mkpath( + "Mirrors_rich" + + RichDetectorStr + + "_" + + thisNameStr + + "/Conditions/Rich" + + RichDetectorStr + + "/Alignment" + ) + # ------------------------------------------------------------------------------- # create a working [replaceable] copy called "Mirrors_rich2_"+thisNameStr+"_i0.xml" # we'd better assume that there is a consistent naming convention here... I have no idea since we don't deal with premisaligned yet... but we are going forward with this: - os.system("cp -p Rich" + RichDetectorStr + - "CondDBUpdate_random_1.xml Rich" + RichDetectorStr + - "CondDBUpdate_" + thisNameStr + "_i0.xml") + os.system( + "cp -p Rich" + + RichDetectorStr + + "CondDBUpdate_random_1.xml Rich" + + RichDetectorStr + + "CondDBUpdate_" + + thisNameStr + + "_i0.xml" + ) else: - print "### preparing XML copy of the whole Mirrors.xml branch from the official CondDB:" - print "### and preparing a working copy of Mirrors.xml :" - print "### ----------------------------------------------------------------------------" - - if (setupProjectBrunelOpts.find("--use-grid") != -1): - - print '( setupProjectBrunelOpts.find("--use-grid") != -1 ) is True' - print "dump_db_to_files.py -v -c CondDB/" + CONDDB + " -t `date +\"%s000000000\"` -T \'" + CondDB_tag + "\' -s /Conditions/Rich" + RichDetectorStr + "/Alignment/Mirrors.xml -d Mirrors_rich" + RichDetectorStr + "_" + thisNameStr + print( + "### preparing XML copy of the whole Mirrors.xml branch from the official CondDB:" + ) + print("### and preparing a working copy of Mirrors.xml :") + print( + "### ----------------------------------------------------------------------------" + ) + + if setupProjectBrunelOpts.find("--use-grid") != -1: + print('( setupProjectBrunelOpts.find("--use-grid") != -1 ) is True') + print( + "dump_db_to_files.py -v -c CondDB/" + + CONDDB + + ' -t `date +"%s000000000"` -T \'' + + CondDB_tag + + "' -s /Conditions/Rich" + + RichDetectorStr + + "/Alignment/Mirrors.xml -d Mirrors_rich" + + RichDetectorStr + + "_" + + thisNameStr + ) p = Popen( - "export HOME=" + home + ";" + "source " + pathToScripts + - "LbLogin.sh;" + "source `which SetupProject.sh` LHCb " + - LHCbVersion + " --use-grid;" + - "dump_db_to_files.py -v -c CondDB/" + CONDDB + - " -t `date +\"%s000000000\"` -T \'" + CondDB_tag + - "\' -s /Conditions/Rich" + RichDetectorStr + - "/Alignment/Mirrors.xml -d Mirrors_rich" + RichDetectorStr - + "_" + thisNameStr, + "export HOME=" + + home + + ";" + + "source " + + pathToScripts + + "LbLogin.sh;" + + "source `which SetupProject.sh` LHCb " + + LHCbVersion + + " --use-grid;" + + "dump_db_to_files.py -v -c CondDB/" + + CONDDB + + ' -t `date +"%s000000000"` -T \'' + + CondDB_tag + + "' -s /Conditions/Rich" + + RichDetectorStr + + "/Alignment/Mirrors.xml -d Mirrors_rich" + + RichDetectorStr + + "_" + + thisNameStr, shell=True, executable="/bin/bash", stdout=PIPE, - stderr=PIPE) + stderr=PIPE, + ) (stdout, stderr) = p.communicate() stdReport(stdout, stderr) else: - CONDDB1 = CONDDB - print '( setupProjectBrunelOpts.find("--use-grid") != -1 ) is False' + print('( setupProjectBrunelOpts.find("--use-grid") != -1 ) is False') # print "dump_db_to_files.py -v -c sqlite_file:$SQLITEDBPATH/"+CONDDB1+".db/"+CONDDB+" -T \'"+ CondDB_tag+"\' -t \'"+date+"\' -s /Conditions/Rich"+RichDetectorStr+"/Alignment/Mirrors.xml -d Mirrors_"+thisNameStr - print "dump_db_to_files.py -v -c sqlite_file:" + SQLITEDBPATH + CONDDB1 + ".db/" + CONDDB + " -T \'" + CondDB_tag + "\' -t \'" + date + "\' -s /Conditions/Rich" + RichDetectorStr + "/Alignment/Mirrors.xml -d Mirrors_rich" + RichDetectorStr + "_" + thisNameStr + print( + "dump_db_to_files.py -v -c sqlite_file:" + + SQLITEDBPATH + + CONDDB1 + + ".db/" + + CONDDB + + " -T '" + + CondDB_tag + + "' -t '" + + date + + "' -s /Conditions/Rich" + + RichDetectorStr + + "/Alignment/Mirrors.xml -d Mirrors_rich" + + RichDetectorStr + + "_" + + thisNameStr + ) p = Popen( - "export HOME=" + home + ";" + "source " + pathToScripts + - "LbLogin.sh;" + "source `which SetupProject.sh` LHCb " + - LHCbVersion + " ;" + "export HOME=" + + home + + ";" + + "source " + + pathToScripts + + "LbLogin.sh;" + + "source `which SetupProject.sh` LHCb " + + LHCbVersion + + " ;" # +"dump_db_to_files.py -v -c sqlite_file:$SQLITEDBPATH/"+CONDDB1+".db/"+CONDDB+" -T \'"+ CondDB_tag+"\' -t \'"+date+"\' -s /Conditions/Rich"+RichDetectorStr+"/Alignment/Mirrors.xml -d Mirrors_"+thisNameStr, - + "dump_db_to_files.py -v -c sqlite_file:" + SQLITEDBPATH - + CONDDB1 + ".db/" + CONDDB + " -T \'" + CondDB_tag + - "\' -t \'" + date + "\' -s /Conditions/Rich" + - RichDetectorStr + "/Alignment/Mirrors.xml -d Mirrors_rich" - + RichDetectorStr + "_" + thisNameStr, + + "dump_db_to_files.py -v -c sqlite_file:" + + SQLITEDBPATH + + CONDDB1 + + ".db/" + + CONDDB + + " -T '" + + CondDB_tag + + "' -t '" + + date + + "' -s /Conditions/Rich" + + RichDetectorStr + + "/Alignment/Mirrors.xml -d Mirrors_rich" + + RichDetectorStr + + "_" + + thisNameStr, shell=True, executable="/bin/bash", stdout=PIPE, - stderr=PIPE) + stderr=PIPE, + ) (stdout, stderr) = p.communicate() stdReport(stdout, stderr) - #------------------------------------------------------------------------------- + # ------------------------------------------------------------------------------- # create a working [replaceable] copy called "Rich"+RichDetectorStr+"CondDBUpdate_"+thisNameStr+"_i0.xml" - os.system("cp -p Mirrors_rich" + RichDetectorStr + "_" + - thisNameStr + "/Conditions/Rich" + RichDetectorStr + - "/Alignment/Mirrors.xml Rich" + RichDetectorStr + - "CondDBUpdate_" + thisNameStr + "_i0.xml") - os.remove("Mirrors_rich" + RichDetectorStr + "_" + thisNameStr + - "/Conditions/Rich" + RichDetectorStr + - "/Alignment/Mirrors.xml") - #------------------------------------------------------------------------------- + os.system( + "cp -p Mirrors_rich" + + RichDetectorStr + + "_" + + thisNameStr + + "/Conditions/Rich" + + RichDetectorStr + + "/Alignment/Mirrors.xml Rich" + + RichDetectorStr + + "CondDBUpdate_" + + thisNameStr + + "_i0.xml" + ) + os.remove( + "Mirrors_rich" + + RichDetectorStr + + "_" + + thisNameStr + + "/Conditions/Rich" + + RichDetectorStr + + "/Alignment/Mirrors.xml" + ) + # ------------------------------------------------------------------------------- # if we want to use an existing mirror alignment XML, copy specificAlignment as the zeroth iteration XML - if (useSpecificAlignment == "true"): - print "copying specificAlignment to replace the current zeroth iteration XML file" - print "cp -p " + specificAlignment + " Rich" + RichDetectorStr + "CondDBUpdate_" + thisNameStr + "_i0.xml" - os.system("cp -p " + specificAlignment + " Rich" + - RichDetectorStr + "CondDBUpdate_" + thisNameStr + - "_i0.xml") - - #------------------------------------------------------------------------------- + if useSpecificAlignment == "true": + print( + "copying specificAlignment to replace the current zeroth iteration XML file" + ) + print( + "cp -p " + + specificAlignment + + " Rich" + + RichDetectorStr + + "CondDBUpdate_" + + thisNameStr + + "_i0.xml" + ) + os.system( + "cp -p " + + specificAlignment + + " Rich" + + RichDetectorStr + + "CondDBUpdate_" + + thisNameStr + + "_i0.xml" + ) + + # ------------------------------------------------------------------------------- # making Rich"+RichDetectorStr+"CondDBUpdate_"+thisNameStr+"_i0.xml pretty formatted - just_prettify("Rich" + RichDetectorStr + "CondDBUpdate_" + - thisNameStr + "_i0.xml") - #------------------------------------------------------------------------------- - - #define files - currentMirrorXMLFile = "Rich" + RichDetectorStr + "CondDBUpdate_" + thisNameStr + "_i" + str( - iterationCount) + ".xml" - nextIterationXMLFile = "Rich" + RichDetectorStr + "CondDBUpdate_" + thisNameStr + "_i" + str( - iterationCount + 1) + ".xml" - zeroMirrorXMLFile = "Rich" + RichDetectorStr + "CondDBUpdate_" + thisNameStr + "_i0.xml" - #------------------------------------------------------------------------------- - #------------------------------------------------------------------------------- + just_prettify( + "Rich" + RichDetectorStr + "CondDBUpdate_" + thisNameStr + "_i0.xml" + ) + # ------------------------------------------------------------------------------- + + # define files + currentMirrorXMLFile = ( + "Rich" + + RichDetectorStr + + "CondDBUpdate_" + + thisNameStr + + "_i" + + str(iterationCount) + + ".xml" + ) + nextIterationXMLFile = ( + "Rich" + + RichDetectorStr + + "CondDBUpdate_" + + thisNameStr + + "_i" + + str(iterationCount + 1) + + ".xml" + ) + zeroMirrorXMLFile = ( + "Rich" + RichDetectorStr + "CondDBUpdate_" + thisNameStr + "_i0.xml" + ) + # ------------------------------------------------------------------------------- + # ------------------------------------------------------------------------------- # we now create branches of directories for 8 tilts for tiltName in tiltNames: - #if ( tiltName != "" ) : - if (not (os.path.exists("Mirrors_rich" + RichDetectorStr + "_" + - theseNamesWithTilts[tiltName] + - "/Conditions/Rich" + RichDetectorStr + - "/Alignment"))): - os.system("mkdir --parents Mirrors_rich" + RichDetectorStr + "_" + - theseNamesWithTilts[tiltName] + "/Conditions/Rich" + - RichDetectorStr + "/Alignment") - - #------------------------------------------------------------------------------- + # if ( tiltName != "" ) : + if not ( + os.path.exists( + "Mirrors_rich" + + RichDetectorStr + + "_" + + theseNamesWithTilts[tiltName] + + "/Conditions/Rich" + + RichDetectorStr + + "/Alignment" + ) + ): + os.system( + "mkdir --parents Mirrors_rich" + + RichDetectorStr + + "_" + + theseNamesWithTilts[tiltName] + + "/Conditions/Rich" + + RichDetectorStr + + "/Alignment" + ) + + # ------------------------------------------------------------------------------- # define directory where additional files to use are - PanoptesJobPath = (RICHMIRRORALIGNMENTGANGAROOT + "job") - #------------------------------------------------------------------------------- + PanoptesJobPath = RICHMIRRORALIGNMENTGANGAROOT + "job" + # ------------------------------------------------------------------------------- # define directory where Brunel configuration files to use are - BrunelOptsPath = (RICHMIRRORALIGNMENTGANGAROOT + "options") + BrunelOptsPath = RICHMIRRORALIGNMENTGANGAROOT + "options" # Paras - OK, now we are getting into Ganga specific stuff. Try to separate this # so if ( backEnd == 'online' ) we don't use Ganga - #------------------------------------------------------------------------------- - if (backEnd == 'local'): + # ------------------------------------------------------------------------------- + if backEnd == "local": jBackend = Local() - jSplitter = SplitByFiles( - filesPerJob=splitFilesPerJob, maxFiles=splitMaxFiles) + jSplitter = SplitByFiles(filesPerJob=splitFilesPerJob, maxFiles=splitMaxFiles) jSplitter.ignoremissing = True - elif (backEnd == 'interactive'): + elif backEnd == "interactive": jBackend = Interactive() - jSplitter = SplitByFiles( - filesPerJob=splitFilesPerJob, maxFiles=splitMaxFiles) + jSplitter = SplitByFiles(filesPerJob=splitFilesPerJob, maxFiles=splitMaxFiles) jSplitter.ignoremissing = True - elif (backEnd == 'dirac'): - jBackend = Dirac(settings={'CPUTime': diracCPUTime}) - jSplitter = SplitByFiles( - filesPerJob=splitFilesPerJob, maxFiles=splitMaxFiles) + elif backEnd == "dirac": + jBackend = Dirac(settings={"CPUTime": diracCPUTime}) + jSplitter = SplitByFiles(filesPerJob=splitFilesPerJob, maxFiles=splitMaxFiles) jSplitter.ignoremissing = True - elif (backEnd == 'lsf'): - jBackend = LSF(queue='1nh') - jSplitter = SplitByFiles( - filesPerJob=splitFilesPerJob, maxFiles=splitMaxFiles) + elif backEnd == "lsf": + jBackend = LSF(queue="1nh") + jSplitter = SplitByFiles(filesPerJob=splitFilesPerJob, maxFiles=splitMaxFiles) jSplitter.ignoremissing = True - elif (backEnd == 'online'): - jBackend = 'online' # jBackend won't be used for online - jSplitter = 'online' # jSplitter won't be used for online + elif backEnd == "online": + jBackend = "online" # jBackend won't be used for online + jSplitter = "online" # jSplitter won't be used for online else: - queuePatt = re.compile(r'lsf_([\w]+)') + queuePatt = re.compile(r"lsf_([\w]+)") queueMatch = queuePatt.match(backEnd) LSF_queue = queueMatch.group(1) jBackend = LSF(queue=LSF_queue) - jSplitter = SplitByFiles( - filesPerJob=splitFilesPerJob, maxFiles=splitMaxFiles) + jSplitter = SplitByFiles(filesPerJob=splitFilesPerJob, maxFiles=splitMaxFiles) jSplitter.ignoremissing = True - #------------------------------------------------------------------------------- + # ------------------------------------------------------------------------------- - #------------------------------------------------------------------------------- + # ------------------------------------------------------------------------------- # initialize the verdict variable - verdict = 'CONTINUE' - #------------------------------------------------------------------------------- + verdict = "CONTINUE" + # ------------------------------------------------------------------------------- # PN - We don't run HPD alignment anymore, so this is always false runHPDalignment = "false" @@ -1106,55 +1364,60 @@ def mirroralign(RichInfoSettings="Something_Went_Wrong"): # Thankful for python variable scoping rules. # Hopefully the "from Communicator import *" in Iterator.py propagates down. # Otherwise we will need to find a way to rewrite this. - if (backEnd == 'online'): - print "ONLINE not supported in this legacy script" + if backEnd == "online": + print("ONLINE not supported in this legacy script") # Start the communicator, before I do *any* iterative mirror alignment: com = Communicator( - 'ALIGNITER' + "ALIGNITER" ) # com established for the rest of this mirroralign function - print "com = Communicator('ALIGNITER') STARTED" + print("com = Communicator('ALIGNITER') STARTED") # FSM loop preparation state = State.NOT_READY com.set_status(state) # start in state NOT_READY - print "com.set_status(State.NOT_READY)" + print("com.set_status(State.NOT_READY)") ## 0 is typically what you want. ## 1 is used to produce the combined fit to the sum of all delta(theta) histograms. ## Future plan: include stuff from 1 into 0 to provide monitoring if justGlobalFit == 0: - while iterationCount < maximumNumberOfIterations: - - if (backEnd == 'dirac'): + if backEnd == "dirac": os.system( - 'kinit -R' + "kinit -R" ) # renews your local AFS ticket [for up to 7 days, given that "kinit -fp -r 7d" was run from the submitting machine, I think] - os.system('aklog') # renews your local AFS token - gridProxy.renew( - ) # reactivate() # perhaps no longer needed, unless your grid proxy expires... + os.system("aklog") # renews your local AFS token + gridProxy.renew() # reactivate() # perhaps no longer needed, unless your grid proxy expires... repeatIteration = False # reset this flag - print "### ----------------------------------------------------------------------------" - print "### starting iteration named Iteration No. " + str( - iterationCount) - print "### ----------------------------------------------------------------------------" - print strftime("%Y-%m-%d %H:%M:%S", gmtime()) - print "-------------------" - #------------------------------------------------------------------------------- - if (magnifCoeffMode == 2): + print( + "### ----------------------------------------------------------------------------" + ) + print("### starting iteration named Iteration No. " + str(iterationCount)) + print( + "### ----------------------------------------------------------------------------" + ) + print(strftime("%Y-%m-%d %H:%M:%S", gmtime())) + print("-------------------") + # ------------------------------------------------------------------------------- + if magnifCoeffMode == 2: # let us create 8 misaligned xml files: modified by +/- coeffCalibrTilt Mirror.xml files # for evaluation of the magnification coefficients on-fly create_coeff_calibration_xml_files( - currentMirrorXMLFile, coeffCalibrTilt, richDetector) + currentMirrorXMLFile, coeffCalibrTilt, richDetector + ) - print "### ----------------------------------------------------------------------------" - print "### modified by +/- " + str( - coeffCalibrTilt - ) + " mrad Mirror.xml files have just been prepared" + print( + "### ----------------------------------------------------------------------------" + ) + print( + "### modified by +/- " + + str(coeffCalibrTilt) + + " mrad Mirror.xml files have just been prepared" + ) - #============================================================================ - #=== start Brunel for normal case and for evaluation of the coefficients ==== - #============================================================================ + # ============================================================================ + # === start Brunel for normal case and for evaluation of the coefficients ==== + # ============================================================================ # GANGA: we prepare dictionary and sequence of job objects (9) for each iteration # ONLINE: these just remain empty jobIds = [] @@ -1163,70 +1426,144 @@ def mirroralign(RichInfoSettings="Something_Went_Wrong"): jobId_submittedSince = {} if skipFirstRecoJob == 1: - print "### ----------------------------------------------------------------------------" - print "### ---------- SKIPPING BRUNEL RECONSTRUCTION FOR ITERATION " + str( - iterationCount) + " ------------------" - print "### ----------------------------------------------------------------------------" + print( + "### ----------------------------------------------------------------------------" + ) + print( + "### ---------- SKIPPING BRUNEL RECONSTRUCTION FOR ITERATION " + + str(iterationCount) + + " ------------------" + ) + print( + "### ----------------------------------------------------------------------------" + ) else: # run Brunel for the main and for all the tilted variants for tiltName in tiltNames: - - #------------------------------------------------------------------------------- + # ------------------------------------------------------------------------------- # create the [replaceable] symlinks to local # Mirrors_rich2_"+theseNamesWithTilts[tiltName]+"_i"+str(iterationCount)+".xml # so only .xml file names contain the iterationCount, while # directories' and dbs' names do not - #------------------------------------------------------------------------------- - os.system("ln -sf " + workDir + "Rich" + RichDetectorStr + - "CondDBUpdate_" + theseNamesWithTilts[tiltName] + - "_i" + str(iterationCount) + ".xml " + workDir + - "Mirrors_rich" + RichDetectorStr + "_" + - theseNamesWithTilts[tiltName] + - "/Conditions/Rich" + RichDetectorStr + - "/Alignment/Mirrors.xml") + # ------------------------------------------------------------------------------- + os.system( + "ln -sf " + + workDir + + "Rich" + + RichDetectorStr + + "CondDBUpdate_" + + theseNamesWithTilts[tiltName] + + "_i" + + str(iterationCount) + + ".xml " + + workDir + + "Mirrors_rich" + + RichDetectorStr + + "_" + + theseNamesWithTilts[tiltName] + + "/Conditions/Rich" + + RichDetectorStr + + "/Alignment/Mirrors.xml" + ) # PN - Apparently the current .db file has outlived its usefulness, if it is there, then remove it. - if (os.path.exists("Mirrors_rich" + RichDetectorStr + "_" + - theseNamesWithTilts[tiltName] + ".db")): - os.system("rm -rf Mirrors_rich" + RichDetectorStr + - "_" + theseNamesWithTilts[tiltName] + ".db") + if os.path.exists( + "Mirrors_rich" + + RichDetectorStr + + "_" + + theseNamesWithTilts[tiltName] + + ".db" + ): + os.system( + "rm -rf Mirrors_rich" + + RichDetectorStr + + "_" + + theseNamesWithTilts[tiltName] + + ".db" + ) # create local [replaceable] working copy of the conditions database slice # containing only Mirrors.xml branch - print "### ----------------------------------------------------------------------------" - print "### converting the whole Mirrors.xml branch into SQLite format:" - print "### ----------------------------------------------------------------------------" + print( + "### ----------------------------------------------------------------------------" + ) + print( + "### converting the whole Mirrors.xml branch into SQLite format:" + ) + print( + "### ----------------------------------------------------------------------------" + ) # prepare CondDB sqlite_file for this tilt, which will be additional layer to the main database - print "copy_files_to_db.py -s Mirrors_rich" + RichDetectorStr + "_" + theseNamesWithTilts[ - tiltName] + " -c sqlite_file:Mirrors_rich" + RichDetectorStr + "_" + theseNamesWithTilts[ - tiltName] + ".db/" + CONDDB + print( + "copy_files_to_db.py -s Mirrors_rich" + + RichDetectorStr + + "_" + + theseNamesWithTilts[tiltName] + + " -c sqlite_file:Mirrors_rich" + + RichDetectorStr + + "_" + + theseNamesWithTilts[tiltName] + + ".db/" + + CONDDB + ) p = Popen( - "export HOME=" + home + ";" + "source " + - pathToScripts + "LbLogin.sh;" + - "source `which SetupProject.sh` LHCb " + LHCbVersion + - " ;" + "copy_files_to_db.py -s Mirrors_rich" + - RichDetectorStr + "_" + theseNamesWithTilts[tiltName] + - " -c sqlite_file:Mirrors_rich" + RichDetectorStr + "_" - + theseNamesWithTilts[tiltName] + ".db/" + CONDDB + ";" - + "python " + PanoptesJobPath + "/tagger.py " + - CondDB_tag + " " + "Mirrors_rich" + RichDetectorStr + - "_" + theseNamesWithTilts[tiltName] + " " + CONDDB, + "export HOME=" + + home + + ";" + + "source " + + pathToScripts + + "LbLogin.sh;" + + "source `which SetupProject.sh` LHCb " + + LHCbVersion + + " ;" + + "copy_files_to_db.py -s Mirrors_rich" + + RichDetectorStr + + "_" + + theseNamesWithTilts[tiltName] + + " -c sqlite_file:Mirrors_rich" + + RichDetectorStr + + "_" + + theseNamesWithTilts[tiltName] + + ".db/" + + CONDDB + + ";" + + "python " + + PanoptesJobPath + + "/tagger.py " + + CondDB_tag + + " " + + "Mirrors_rich" + + RichDetectorStr + + "_" + + theseNamesWithTilts[tiltName] + + " " + + CONDDB, shell=True, executable="/bin/bash", stdout=PIPE, - stderr=PIPE) + stderr=PIPE, + ) (stdout, stderr) = p.communicate() stdReport(stdout, stderr) - print "### ----------------------------------------------------------------------------" - - outputHistoFile = "RichRecQCHistos_rich" + RichDetectorStr + "_" + theseNamesWithTilts[ - tiltName] + "_i" + str(iterationCount) + ".root" - print "Output ROOT filename ", outputHistoFile - - #------------------------------------------------------------------------------- + print( + "### ----------------------------------------------------------------------------" + ) + + outputHistoFile = ( + "RichRecQCHistos_rich" + + RichDetectorStr + + "_" + + theseNamesWithTilts[tiltName] + + "_i" + + str(iterationCount) + + ".root" + ) + print("Output ROOT filename ", outputHistoFile) + + # ------------------------------------------------------------------------------- # the job configuration - #------------------------------------------------------------------------------- + # ------------------------------------------------------------------------------- # PN - OK this is where it gets interesting. # There are two parts of the code where we need to # make this split in two directions. @@ -1235,27 +1572,31 @@ def mirroralign(RichInfoSettings="Something_Went_Wrong"): # Online needs to conform to the Online Alignment Framwork # # First, ONLINE - if (backEnd == 'online'): - print "ONLINE not supported in this legacy script" + if backEnd == "online": + print("ONLINE not supported in this legacy script") # Second, GANGA (i.e. not ONLINE) else: - print "GANGA" + print("GANGA") gangaVersion = config.System.GANGA_VERSION GV61flag = True # Assuming no one is using anything older than Ganga 5 - if 'Ganga-6-0' in gangaVersion: + if "Ganga-6-0" in gangaVersion: GV61flag = False - if 'Ganga-5-' in gangaVersion: + if "Ganga-5-" in gangaVersion: GV61flag = False if GV61flag == True: - print "Proceeding using job options for Ganga 6.1 or later." + print( + "Proceeding using job options for Ganga 6.1 or later." + ) else: - print "Proceeding using job options for Ganga 6.0 or earlier." + print( + "Proceeding using job options for Ganga 6.0 or earlier." + ) jAppBrunel = Brunel(version=brunelVersion) brunelVer = jAppBrunel.version - #------------------------------------------------------------------------------- + # ------------------------------------------------------------------------------- """ Only during the 0-th iteration we take input data in the form of configuration and therefore append the file list as a configuration @@ -1265,129 +1606,174 @@ def mirroralign(RichInfoSettings="Something_Went_Wrong"): Job object; see below. """ - #jAppBrunel.optsfile = [File( BrunelOptsPath+"/Brunel_RichAlignMoni_"+dataVariant+"-"+brunelInitialInputType+".py")] + # jAppBrunel.optsfile = [File( BrunelOptsPath+"/Brunel_RichAlignMoni_"+dataVariant+"-"+brunelInitialInputType+".py")] jAppBrunel.optsfile = [ - File(BrunelOptsPath + "/Brunel_Rich" + - RichDetectorStr + "AlignMoni_" + dataVariant + - "-" + brunelInitialInputType + ".py") + File( + BrunelOptsPath + + "/Brunel_Rich" + + RichDetectorStr + + "AlignMoni_" + + dataVariant + + "-" + + brunelInitialInputType + + ".py" + ) ] - print "### using the following Brunel options file:" - #print "### "+BrunelOptsPath+"/Brunel_RichAlignMoni_"+dataVariant+"-"+brunelInitialInputType+".py" - print "### " + BrunelOptsPath + "/Brunel_Rich" + RichDetectorStr + "AlignMoni_" + dataVariant + "-" + brunelInitialInputType + ".py" + print("### using the following Brunel options file:") + # print "### "+BrunelOptsPath+"/Brunel_RichAlignMoni_"+dataVariant+"-"+brunelInitialInputType+".py" + print( + "### " + + BrunelOptsPath + + "/Brunel_Rich" + + RichDetectorStr + + "AlignMoni_" + + dataVariant + + "-" + + brunelInitialInputType + + ".py" + ) DBSlices = [] DBSlicesNames = [] BrunelOptionsString = "" ThereAreAddedDBSlices = False LFNDBs = True - if len(AddedDB) > 0 and len( - AddedDB[0] - ) > 1 and backEnd == 'dirac': #note: can not use databases outside of dirac + if ( + len(AddedDB) > 0 + and len(AddedDB[0]) > 1 + and backEnd == "dirac" + ): # note: can not use databases outside of dirac ThereAreAddedDBSlices = True for i in range(0, len(AddedDB)): - if not AddedDB[i].startswith('LFN'): + if not AddedDB[i].startswith("LFN"): LFNDBs = False # databases are local AddedDB2 = AddedDB[i].split("/") for j in AddedDB2: - if (j.endswith(".db")): + if j.endswith(".db"): DBSlices.append(j) - print j + print(j) AddedDBName = j.split(".") for k in AddedDBName: if not k.endswith("db"): DBSlicesNames.append(k) - BrunelOptionsString = BrunelOptionsString + """CondDB().addLayer( CondDBAccessSvc(\'""" + DBSlicesNames[ - i] + """\', ConnectionString=\'sqlite_file:""" + DBSlices[ - i] + """/LHCBCOND\', DefaultTAG=\'HEAD\') )\n""" - - print BrunelOptionsString - - if (dataVariant == "Collision09" - or dataVariant == "Collision10" - or dataVariant == "Collision11" - or dataVariant == "Collision12" - or dataVariant == "Collision15"): + BrunelOptionsString = ( + BrunelOptionsString + + """CondDB().addLayer( CondDBAccessSvc(\'""" + + DBSlicesNames[i] + + """\', ConnectionString=\'sqlite_file:""" + + DBSlices[i] + + """/LHCBCOND\', DefaultTAG=\'HEAD\') )\n""" + ) + + print(BrunelOptionsString) + + if ( + dataVariant == "Collision09" + or dataVariant == "Collision10" + or dataVariant == "Collision11" + or dataVariant == "Collision12" + or dataVariant == "Collision15" + ): delthetawin = str(float(deltaThetaWindow) / 1000) tiltname = theseNamesWithTilts[tiltName] - jAppBrunel.extraopts = \ - "Brunel().DDDBtag = '{DDDB_tag}'\n" \ - "Brunel().CondDBtag = '{CondDB_tag}'\n" \ - "Brunel().EvtMax = {brunelEvtMax}\n" \ - "Brunel().PrintFreq = {brunelPrintFreq}\n" \ - "RichAlignmentConf ('OfflineRichMoni_RichAlignmentConf').setProp('Radiators', ['Rich{RichDetectorStr}Gas'])\n" \ - "MessageSvc().OutputLevel = {messageSvcOutputLevel}\n" \ - "RichAlignmentConf('OfflineRichMoni_RichAlignmentConf').setProp('DeltaThetaRange', [ 0.04,{delthetawin}, {delthetawin}])\n" \ - "CondDB().addLayer( CondDBAccessSvc('Rich{RichDetectorStr}AlignMirr', ConnectionString='sqlite_file:Mirrors_rich{RichDetectorStr}_{tiltname}.db/{CONDDB}', DefaultTAG='HEAD'))\n" \ - "from Configurables import EventClockSvc\n" \ - "EventClockSvc( InitialTime = {date} )\n" \ - "HistogramPersistencySvc().setProp('OutputFile', 'RichRecQCHistos_rich{RichDetectorStr}_{tiltname}_i{iterationCount}.root')\n" \ - "{BrunelOptionsString}\n" \ - "{BrunelOptionsString}\n".format(**locals()) - - jName = tiltInJobnameDict[ - tiltName] + thisCase + '_i' + str(iterationCount) + jAppBrunel.extraopts = ( + "Brunel().DDDBtag = '{DDDB_tag}'\n" + "Brunel().CondDBtag = '{CondDB_tag}'\n" + "Brunel().EvtMax = {brunelEvtMax}\n" + "Brunel().PrintFreq = {brunelPrintFreq}\n" + "RichAlignmentConf ('OfflineRichMoni_RichAlignmentConf').setProp('Radiators', ['Rich{RichDetectorStr}Gas'])\n" + "MessageSvc().OutputLevel = {messageSvcOutputLevel}\n" + "RichAlignmentConf('OfflineRichMoni_RichAlignmentConf').setProp('DeltaThetaRange', [ 0.04,{delthetawin}, {delthetawin}])\n" + "CondDB().addLayer( CondDBAccessSvc('Rich{RichDetectorStr}AlignMirr', ConnectionString='sqlite_file:Mirrors_rich{RichDetectorStr}_{tiltname}.db/{CONDDB}', DefaultTAG='HEAD'))\n" + "from Configurables import EventClockSvc\n" + "EventClockSvc( InitialTime = {date} )\n" + "HistogramPersistencySvc().setProp('OutputFile', 'RichRecQCHistos_rich{RichDetectorStr}_{tiltname}_i{iterationCount}.root')\n" + "{BrunelOptionsString}\n" + "{BrunelOptionsString}\n".format(**locals()) + ) + + jName = ( + tiltInJobnameDict[tiltName] + + thisCase + + "_i" + + str(iterationCount) + ) j = Job( name=jName, application=jAppBrunel, splitter=jSplitter, - backend=jBackend) + backend=jBackend, + ) # For Ganga 6.1 and later, we'll leave this alone for now, hopefully it works try: tryString = eventSelectorInputFile + "abcd" except TypeError: - #print "Not a String" + # print "Not a String" for ff in range(0, len(eventSelectorInputFile)): if ff == 0: j.inputdata = j.application.readInputData( - eventSelectorInputFile[ff]) + eventSelectorInputFile[ff] + ) else: j.inputdata.extend( j.application.readInputData( - eventSelectorInputFile[ff])) + eventSelectorInputFile[ff] + ) + ) else: - #print "String" + # print "String" j.inputdata = j.application.readInputData( - eventSelectorInputFile) + eventSelectorInputFile + ) - if (backEnd != 'dirac'): - print "Not Dirac" + if backEnd != "dirac": + print("Not Dirac") if GV61flag == False: j.inputsandbox += [ - workDir + "Mirrors_rich" + RichDetectorStr + - "_" + theseNamesWithTilts[tiltName] + ".db" + workDir + + "Mirrors_rich" + + RichDetectorStr + + "_" + + theseNamesWithTilts[tiltName] + + ".db" ] else: j.inputfiles += [ - LocalFile(workDir + "Mirrors_rich" + - RichDetectorStr + "_" + - theseNamesWithTilts[tiltName] + - ".db") + LocalFile( + workDir + + "Mirrors_rich" + + RichDetectorStr + + "_" + + theseNamesWithTilts[tiltName] + + ".db" + ) ] if ThereAreAddedDBSlices == True and LFNDBs == True: if GV61flag == False: j.backend.inputSandboxLFNs = AddedDB # PN - Now we have some print statements to check that the AddedDBs from the settings file are as expected. - print "### j.backend.inputSandboxLFNs now reads:" + print("### j.backend.inputSandboxLFNs now reads:") for keys in j.backend.inputSandboxLFNs: - print keys + print(keys) else: - print "NOTE: This is UNTESTED in Ganga 6.1!!!! If it works, then please remove this print statement." + print( + "NOTE: This is UNTESTED in Ganga 6.1!!!! If it works, then please remove this print statement." + ) GV61AddedDB = [] for LFNstring in AddedDB: - if LFNstring.startswith('LFN:'): + if LFNstring.startswith("LFN:"): NewLFNstring = LFNstring[4:] else: NewLFNstring = LFNstring - GV61AddedDB.append( - DiracFile(lfn=NewLFNstring)) + GV61AddedDB.append(DiracFile(lfn=NewLFNstring)) j.inputfiles += GV61AddedDB if ThereAreAddedDBSlices == True and LFNDBs == False: - #print "NOTE: This Use Case NEEDS TO BE TESTED if you want to read .db from local files instead of LFNs (If it works, remove this print statement)" + # print "NOTE: This Use Case NEEDS TO BE TESTED if you want to read .db from local files instead of LFNs (If it works, remove this print statement)" if GV61flag == False: j.inputsandbox += AddedDB else: @@ -1401,78 +1787,94 @@ def mirroralign(RichInfoSettings="Something_Went_Wrong"): j.do_auto_resubmit = True # this automatically resubmits failed subjobs, *if* at least one of the subjobs completed - #Try it later - #if GV61flag == True: + # Try it later + # if GV61flag == True: # j.parallel_submit = True # Experimental parallel job submission, so we're trying it - print "### ----------------------------------------------------------------------------" - print j + print( + "### ----------------------------------------------------------------------------" + ) + print(j) ## Ban sites that fail # j.backend.settings['BannedSites'] = ['LCG.PIC.es','LCG.SARA.nl','LCG.NIKHEF.nl','LCG.CERN.ch'] ## Ban "ANY" sites by specifying remaining sites # j.backend.settings['Destination'] = ['LCG.GRIDKA.de','LCG.IN2P3.fr','LCG.CNAF.it'] - print strftime("%Y-%m-%d %H:%M:%S", gmtime()) - print "-------------------" + print(strftime("%Y-%m-%d %H:%M:%S", gmtime())) + print("-------------------") # j.submit() # Ganga 6 lets you parallelize this!!!!!!!! queues.add(j.submit) - print strftime("%Y-%m-%d %H:%M:%S", gmtime()) - print "-------------------" + print(strftime("%Y-%m-%d %H:%M:%S", gmtime())) + print("-------------------") jobIds.append(j.id) tilt_jobId[tiltName] = j.id jobId_tilt[j.id] = tiltName jobId_submittedSince[j.id] = time() - #------------------------------------------------------------------------------- + # ------------------------------------------------------------------------------- - #============================================================================ + # ============================================================================ # end of loop over the tilts - #============================================================================ + # ============================================================================ queues # check the situation - #============================================================================ + # ============================================================================ # Wait until enough subjobs have finished until we continue - #============================================================================ + # ============================================================================ if skipFirstMergeJob == 1: - print "### ----------------------------------------------------------------------------" - print "### ---------- SKIPPING MERGE OF BRUNEL HISTOGRAMS FOR ITERATION " + str( - iterationCount) + " -------------" - print "### ----------------------------------------------------------------------------" + print( + "### ----------------------------------------------------------------------------" + ) + print( + "### ---------- SKIPPING MERGE OF BRUNEL HISTOGRAMS FOR ITERATION " + + str(iterationCount) + + " -------------" + ) + print( + "### ----------------------------------------------------------------------------" + ) else: # PN: Again, trying to make split this in two directions. # One is "GANGA" the other is "ONLINE" # # First, ONLINE - if (backEnd == 'online'): - print "ONLINE not supported in this legacy script" + if backEnd == "online": + print("ONLINE not supported in this legacy script") iterationCount = iterationCount + 1 continue # Second, GANGA (i.e. not ONLINE) else: - print "GANGA" + print("GANGA") # we must first wait for the queues threads to finish their work. - print "Waiting for the queues threads to finish submitting all of the jobs" - print "-------------------" - - while (queues.totalNumUserThreads() > 0): - print "Total number of user threads still active %d" % queues.totalNumUserThreads( + print( + "Waiting for the queues threads to finish submitting all of the jobs" + ) + print("-------------------") + + while queues.totalNumUserThreads() > 0: + print( + "Total number of user threads still active %d" + % queues.totalNumUserThreads() ) - print strftime("%Y-%m-%d %H:%M:%S", gmtime()) - print "-------------------" + print(strftime("%Y-%m-%d %H:%M:%S", gmtime())) + print("-------------------") # create an empty file, can check the timestamp in your workDir to see if alignment is still running - os.system('touch Mirrors_SubmittingJobs_touch.txt') - sleep( - 300 - ) # check the status of the queues every 5 minutes + os.system("touch Mirrors_SubmittingJobs_touch.txt") + sleep(300) # check the status of the queues every 5 minutes if skipFirstRecoJob != 1: - print "All jobs have been submitted. Now we wait for 80 percent of the subjobs from each job to complete." + print( + "All jobs have been submitted. Now we wait for 80 percent of the subjobs from each job to complete." + ) else: - print "Checking jobIds from the Brunel reconstruction of major iteration %d" % iterationCount + print( + "Checking jobIds from the Brunel reconstruction of major iteration %d" + % iterationCount + ) - print "-------------------" + print("-------------------") if skipFirstRecoJob == 1: jobIds = previousJobNumbers @@ -1481,64 +1883,67 @@ def mirroralign(RichInfoSettings="Something_Went_Wrong"): minutesCounter = 0 - while (len(jobIds) > 0): - - if (backEnd == 'dirac'): + while len(jobIds) > 0: + if backEnd == "dirac": os.system( - 'kinit -R' + "kinit -R" ) # renews your local AFS ticket [for up to 7 days, given that "kinit -fp -r 7d" was run from the submitting machine, I think] - os.system('aklog') # renews your local AFS token - gridProxy.renew( - ) # reactivate() # perhaps no longer needed, unless your grid proxy expires... + os.system("aklog") # renews your local AFS token + gridProxy.renew() # reactivate() # perhaps no longer needed, unless your grid proxy expires... sleep( 60 ) # just wait to conserve CPU cycles, because some jobs are still not finished minutesCounter = minutesCounter + 1 - if ((minutesCounter % 15) == 0): - print "Still waiting for 80 percent of subjobs from all jobs to complete." - print strftime("%Y-%m-%d %H:%M:%S", gmtime()) + if (minutesCounter % 15) == 0: + print( + "Still waiting for 80 percent of subjobs from all jobs to complete." + ) + print(strftime("%Y-%m-%d %H:%M:%S", gmtime())) # create an empty file, can check the timestamp in your workDir to see if alignment is still running - os.system( - 'touch Mirrors_WaitingForSubjobs_touch.txt') - print "-------------------" + os.system("touch Mirrors_WaitingForSubjobs_touch.txt") + print("-------------------") for jobId in jobIds: - sjIDs = [] sjIDsCompleted = [] for sj in jobs(jobId).subjobs: sjIDs.append(sj.id) - if ((sj.status == 'completed') - or (sj.status == 'failed')): + if (sj.status == "completed") or ( + sj.status == "failed" + ): sjIDsCompleted.append(sj.id) - if (sj.status == 'new'): - print "Resubmitting subjob " + str(sj.id) + if sj.status == "new": + print("Resubmitting subjob " + str(sj.id)) # Ganga 6 lets you parallelize this, but we don't want to as it's not expected to need much overhead. sj.submit() - if (float(len(sjIDsCompleted)) / float(len(sjIDs)) - > 0.8): - + if float(len(sjIDsCompleted)) / float(len(sjIDs)) > 0.8: # create an empty file when any job has completed, can check the timestamp in your workDir to see if alignment is still running - os.system( - 'touch Mirrors_LastJobCompleted_touch.txt') - - print "Job number " + str( - jobId - ) + " has " + str( - len(sjIDsCompleted) - ) + " out of " + str( - len(sjIDs) - ) + " subjobs completed or failed so will now merge the outputs\n" - print strftime("%Y-%m-%d %H:%M:%S", gmtime()) - print "-------------------" - - rootFileName = "RichRecQCHistos_rich" + RichDetectorStr + "_" + theseNamesWithTilts[ - jobId_tilt[jobId]] + "_i" + str( - iterationCount) + ".root" - if (not (os.path.exists( - jobs(jobId).outputdir))): + os.system("touch Mirrors_LastJobCompleted_touch.txt") + + print( + "Job number " + + str(jobId) + + " has " + + str(len(sjIDsCompleted)) + + " out of " + + str(len(sjIDs)) + + " subjobs completed or failed so will now merge the outputs\n" + ) + print(strftime("%Y-%m-%d %H:%M:%S", gmtime())) + print("-------------------") + + rootFileName = ( + "RichRecQCHistos_rich" + + RichDetectorStr + + "_" + + theseNamesWithTilts[jobId_tilt[jobId]] + + "_i" + + str(iterationCount) + + ".root" + ) + if not (os.path.exists(jobs(jobId).outputdir)): os.system("mkdir " + jobs(jobId).outputdir) rootFile = jobs(jobId).outputdir + rootFileName @@ -1556,35 +1961,46 @@ def mirroralign(RichInfoSettings="Something_Went_Wrong"): # Claire's new merge output histograms import ROOT + mergesuccess = False - while (not mergesuccess): - os.system("rm -rf " + - jobs(jobId).outputdir + - rootFileName) + while not mergesuccess: + os.system( + "rm -rf " + jobs(jobId).outputdir + rootFileName + ) # merge output histograms p = Popen( - "export HOME=" + home + ";" + - "source " + pathToScripts + - "LbLogin.sh;" + - "export User_release_area=" + - userReleaseArea + ";" + - "source `which SetupProject.sh` Brunel " - + brunelVersion + " " + - setupProjectBrunelOpts + ";" + "export HOME=" + + home + + ";" + + "source " + + pathToScripts + + "LbLogin.sh;" + + "export User_release_area=" + + userReleaseArea + + ";" + + "source `which SetupProject.sh` Brunel " + + brunelVersion + + " " + + setupProjectBrunelOpts + + ";" # +"source `which SetupProject.sh` Gaudi;" - + "hadd " + jobs(jobId).outputdir + - rootFileName + " " + - jobs(jobId).outputdir + "../*/output/" - + rootFileName + ";", + + "hadd " + + jobs(jobId).outputdir + + rootFileName + + " " + + jobs(jobId).outputdir + + "../*/output/" + + rootFileName + + ";", shell=True, executable="/bin/bash", stdout=PIPE, - stderr=PIPE) + stderr=PIPE, + ) (stdout, stderr) = p.communicate() stdReport(stdout, stderr) - smerged = jobs( - jobId).outputdir + rootFileName + smerged = jobs(jobId).outputdir + rootFileName fmerged = ROOT.TFile.Open(smerged) if fmerged.GetStreamerInfoList(): mergesuccess = True @@ -1593,133 +2009,219 @@ def mirroralign(RichInfoSettings="Something_Went_Wrong"): fmerged.Close() # and now create link - os.system("ln -sf " + rootFile + " " + - rootFileName) + os.system("ln -sf " + rootFile + " " + rootFileName) # clear the diskspace - #rm_subjobs_except_0_last( jobs(jobId), rootFileName, brunelVer, backEnd ) + # rm_subjobs_except_0_last( jobs(jobId), rootFileName, brunelVer, backEnd ) jobIds.remove(jobId) # all done for this job - print strftime("%Y-%m-%d %H:%M:%S", gmtime()) - print "-------------------" + print(strftime("%Y-%m-%d %H:%M:%S", gmtime())) + print("-------------------") else: - - if ((minutesCounter % 15) == 0): + if (minutesCounter % 15) == 0: fracDone = math.ceil( - 100 * (float(len(sjIDsCompleted)) / - float(len(sjIDs)))) - print "Job number " + str( - jobId - ) + " has just under %d percent of its subjobs completed or failed" % fracDone + 100 + * ( + float(len(sjIDsCompleted)) + / float(len(sjIDs)) + ) + ) + print( + "Job number " + + str(jobId) + + " has just under %d percent of its subjobs completed or failed" + % fracDone + ) # once the first reco jobs has been skipped, carry on as usual skipFirstRecoJob = 0 skipFirstMergeJob = 0 - #============================================================================ - #============================================================================ + # ============================================================================ + # ============================================================================ # run per-combination fit to obtain the total tilts and the coefficients # Paras put this in to at least allow multiple instances of RichMirrCombinFit to run simultaneously, see later in the code as well ps = [] if skipFirstCombinFit == 1: - print "### ----------------------------------------------------------------------------" - print "### ---------- SKIPPING FITTING OF MERGED HISTOGRAMS ---------------------" - print "### ----------------------------------------------------------------------------" + print( + "### ----------------------------------------------------------------------------" + ) + print( + "### ---------- SKIPPING FITTING OF MERGED HISTOGRAMS ---------------------" + ) + print( + "### ----------------------------------------------------------------------------" + ) skipFirstCombinFit = 0 else: for tiltName in tiltNames: - - if (backEnd == 'dirac'): + if backEnd == "dirac": os.system( - 'kinit -R' + "kinit -R" ) # renews your local AFS ticket [for up to 7 days, given that "kinit -fp -r 7d" was run from the submitting machine, I think] - os.system('aklog') # renews your local AFS token - gridProxy.renew( - ) # reactivate() # perhaps no longer needed, unless your grid proxy expires... - combinFitDir = workDir + "Rich" + RichDetectorStr + "MirrCombinFit_" + theseNamesWithTilts[ - tiltName] + "_i" + str(iterationCount) + "/" + os.system("aklog") # renews your local AFS token + gridProxy.renew() # reactivate() # perhaps no longer needed, unless your grid proxy expires... + combinFitDir = ( + workDir + + "Rich" + + RichDetectorStr + + "MirrCombinFit_" + + theseNamesWithTilts[tiltName] + + "_i" + + str(iterationCount) + + "/" + ) combinFitPlotDir = combinFitDir + "plots/" - if (not (os.path.exists(combinFitPlotDir))): + if not (os.path.exists(combinFitPlotDir)): os.system("mkdir --parents " + combinFitPlotDir) - combinResultsFile = combinFitDir + "Rich" + RichDetectorStr + "MirrCombinFit_" + theseNamesWithTilts[ - tiltName] + "_i" + str(iterationCount) + ".txt" - fitConfigFile = combinFitDir + "Rich" + RichDetectorStr + "MirrCombinFit_" + theseNamesWithTilts[ - tiltName] + "_i" + str(iterationCount) + ".conf" - fitOutputFile = combinFitDir + "Rich" + RichDetectorStr + "MirrCombinFitOut_" + theseNamesWithTilts[ - tiltName] + "_i" + str(iterationCount) + ".txt" - fitStdOutFile = combinFitDir + "Rich" + RichDetectorStr + "MirrCombinFitStdOut_" + theseNamesWithTilts[ - tiltName] + "_i" + str(iterationCount) + ".txt" - fitStdErrFile = combinFitDir + "Rich" + RichDetectorStr + "MirrCombinFitStdErr_" + theseNamesWithTilts[ - tiltName] + "_i" + str(iterationCount) + ".txt" + combinResultsFile = ( + combinFitDir + + "Rich" + + RichDetectorStr + + "MirrCombinFit_" + + theseNamesWithTilts[tiltName] + + "_i" + + str(iterationCount) + + ".txt" + ) + fitConfigFile = ( + combinFitDir + + "Rich" + + RichDetectorStr + + "MirrCombinFit_" + + theseNamesWithTilts[tiltName] + + "_i" + + str(iterationCount) + + ".conf" + ) + fitOutputFile = ( + combinFitDir + + "Rich" + + RichDetectorStr + + "MirrCombinFitOut_" + + theseNamesWithTilts[tiltName] + + "_i" + + str(iterationCount) + + ".txt" + ) + fitStdOutFile = ( + combinFitDir + + "Rich" + + RichDetectorStr + + "MirrCombinFitStdOut_" + + theseNamesWithTilts[tiltName] + + "_i" + + str(iterationCount) + + ".txt" + ) + fitStdErrFile = ( + combinFitDir + + "Rich" + + RichDetectorStr + + "MirrCombinFitStdErr_" + + theseNamesWithTilts[tiltName] + + "_i" + + str(iterationCount) + + ".txt" + ) # Paras thinks this should be removed. The only time we'd skip this is on iteration zero if something went wrong - #if ( ( os.path.exists( combinResultsFile ) ) ) : + # if ( ( os.path.exists( combinResultsFile ) ) ) : # continue # Paras says, leave this naming convention alone - brunelHistoFile = "RichRecQCHistos_rich" + RichDetectorStr + "_" + theseNamesWithTilts[ - tiltName] + "_i" + str(iterationCount) + ".root" + brunelHistoFile = ( + "RichRecQCHistos_rich" + + RichDetectorStr + + "_" + + theseNamesWithTilts[tiltName] + + "_i" + + str(iterationCount) + + ".root" + ) if os.path.exists(fitConfigFile): os.remove(fitConfigFile) - f = open(fitConfigFile, 'w') - args = 'plotDir = ' + combinFitPlotDir + '\n' - args += 'richDetector = ' + str(richDetector) + '\n' - args += 'mirrCombinSubset = ' + mirrCombinSubset + '\n' - args += 'minAverageBinPop = ' + str( - minAverageBinPop) + '\n' - args += 'deltaThetaWindow = ' + str( - deltaThetaWindow) + '\n' - args += 'combinFitVariant = ' + str( - combinFitVariant) + '\n' - args += 'phiBinFactor = ' + str(phiBinFactor) + '\n' - args += 'stopTolerance = ' + str(stopTolerance) + '\n' - args += 'warningFactor = ' + str(warningFactor) + '\n' - args += 'iterationCount = ' + str( - iterationCount) + '\n' - args += 'inputHistoFile = ' + str( - workDir + brunelHistoFile) + '\n' - args += 'outputResultsFile = ' + str( - combinResultsFile) + '\n' - args += 'plotOutputLevel = 2 \n' + f = open(fitConfigFile, "w") + args = "plotDir = " + combinFitPlotDir + "\n" + args += "richDetector = " + str(richDetector) + "\n" + args += "mirrCombinSubset = " + mirrCombinSubset + "\n" + args += "minAverageBinPop = " + str(minAverageBinPop) + "\n" + args += "deltaThetaWindow = " + str(deltaThetaWindow) + "\n" + args += "combinFitVariant = " + str(combinFitVariant) + "\n" + args += "phiBinFactor = " + str(phiBinFactor) + "\n" + args += "stopTolerance = " + str(stopTolerance) + "\n" + args += "warningFactor = " + str(warningFactor) + "\n" + args += "iterationCount = " + str(iterationCount) + "\n" + args += ( + "inputHistoFile = " + str(workDir + brunelHistoFile) + "\n" + ) + args += "outputResultsFile = " + str(combinResultsFile) + "\n" + args += "plotOutputLevel = 2 \n" f.write(args) f.close() - print "### ----------------------------------------------------------------------------" - print "### running fitting program that yields total tilts being produced by each pair" - print "### of primary and secondary mirror segments out of a set of combinations chosen" - print "### in advance, and also the rotation-to-total-tilt magnification coefficients" - print "### for each mirror in such a pair:" - print "### ----------------------------------------------------------------------------" - print "### Now sumbitting subprocess for tilt named: " + theseNamesWithTilts[ - tiltName] - print "### ----------------------------------------------------------------------------" - print strftime("%Y-%m-%d %H:%M:%S", gmtime()) - print "-------------------" - - myStdOut = open(fitStdOutFile, 'w') - myStdErr = open(fitStdErrFile, 'w') + print( + "### ----------------------------------------------------------------------------" + ) + print( + "### running fitting program that yields total tilts being produced by each pair" + ) + print( + "### of primary and secondary mirror segments out of a set of combinations chosen" + ) + print( + "### in advance, and also the rotation-to-total-tilt magnification coefficients" + ) + print("### for each mirror in such a pair:") + print( + "### ----------------------------------------------------------------------------" + ) + print( + "### Now sumbitting subprocess for tilt named: " + + theseNamesWithTilts[tiltName] + ) + print( + "### ----------------------------------------------------------------------------" + ) + print(strftime("%Y-%m-%d %H:%M:%S", gmtime())) + print("-------------------") + + myStdOut = open(fitStdOutFile, "w") + myStdErr = open(fitStdErrFile, "w") p = Popen( - "export HOME=" + home + ";" + - "export User_release_area=" + userReleaseArea + ";" + - "source " + pathToScripts + "LbLogin.sh;" + - "source `which SetupProject.sh` Panoptes " + - setupProjectPanoptesVersion + " " + - setupProjectPanoptesOptions + ";" + - "$RICHMIRRCOMBINFITROOT/$CMTCONFIG/RichMirrCombinFit.exe " - + fitConfigFile + " " + RichDetectorStr + " 0 > " + - fitOutputFile, + "export HOME=" + + home + + ";" + + "export User_release_area=" + + userReleaseArea + + ";" + + "source " + + pathToScripts + + "LbLogin.sh;" + + "source `which SetupProject.sh` Panoptes " + + setupProjectPanoptesVersion + + " " + + setupProjectPanoptesOptions + + ";" + + "$RICHMIRRCOMBINFITROOT/$CMTCONFIG/RichMirrCombinFit.exe " + + fitConfigFile + + " " + + RichDetectorStr + + " 0 > " + + fitOutputFile, shell=True, executable="/bin/bash", stdout=myStdOut, - stderr=myStdErr) + stderr=myStdErr, + ) myStdOut.close() myStdErr.close() # Add p to list of subprocesses @@ -1735,24 +2237,32 @@ def mirroralign(RichInfoSettings="Something_Went_Wrong"): if all([x is not None for x in ps_status]): PopenTotal = 0 for l in ps_status: - if l is not None: PopenTotal += 1 - print "%d of %d RichMirrCombinFit processes complete" % ( - PopenTotal, tiltNamesLength) - print strftime("%Y-%m-%d %H:%M:%S", gmtime()) - print "-------------------" + if l is not None: + PopenTotal += 1 + print( + "%d of %d RichMirrCombinFit processes complete" + % (PopenTotal, tiltNamesLength) + ) + print(strftime("%Y-%m-%d %H:%M:%S", gmtime())) + print("-------------------") break else: PopenDone = 0 for l in ps_status: - if l is not None: PopenDone += 1 + if l is not None: + PopenDone += 1 if PopenDone > PopenCount: - print "%d of %d RichMirrCombinFit processes complete" % ( - PopenDone, tiltNamesLength) - print strftime("%Y-%m-%d %H:%M:%S", gmtime()) - print "-------------------" - PopenCount = 0 + PopenDone # add the 0 so that PopenCount doesn't become a pointer to PopenNow + print( + "%d of %d RichMirrCombinFit processes complete" + % (PopenDone, tiltNamesLength) + ) + print(strftime("%Y-%m-%d %H:%M:%S", gmtime())) + print("-------------------") + PopenCount = ( + 0 + PopenDone + ) # add the 0 so that PopenCount doesn't become a pointer to PopenNow - #jid = j.id + # jid = j.id # wish to copy the output decision # PN - think this is now made after RichMirrAlign @@ -1762,57 +2272,119 @@ def mirroralign(RichInfoSettings="Something_Went_Wrong"): # NGEOutFile should have 0 lines in it # We only really need to check results from the current iteration xml, not all of the tilts. # Numbers of photons should be approximately the same for each tilt. - combinFitDir_c = workDir + "Rich" + RichDetectorStr + "MirrCombinFit_" + thisNameStr + "_i" + str( - iterationCount) + "/" - fitOutputFile_c = combinFitDir_c + "Rich" + RichDetectorStr + "MirrCombinFitOut_" + thisNameStr + "_i" + str( - iterationCount) + ".txt" - fitNGEFile_c = combinFitDir_c + "Rich" + RichDetectorStr + "MirrCombinFitNGEOut_" + thisNameStr + "_i" + str( - iterationCount) + ".txt" - os.system('cat ' + fitOutputFile_c + - ' | grep " not_good_enough " > ' + fitNGEFile_c) + combinFitDir_c = ( + workDir + + "Rich" + + RichDetectorStr + + "MirrCombinFit_" + + thisNameStr + + "_i" + + str(iterationCount) + + "/" + ) + fitOutputFile_c = ( + combinFitDir_c + + "Rich" + + RichDetectorStr + + "MirrCombinFitOut_" + + thisNameStr + + "_i" + + str(iterationCount) + + ".txt" + ) + fitNGEFile_c = ( + combinFitDir_c + + "Rich" + + RichDetectorStr + + "MirrCombinFitNGEOut_" + + thisNameStr + + "_i" + + str(iterationCount) + + ".txt" + ) + os.system( + "cat " + + fitOutputFile_c + + ' | grep " not_good_enough " > ' + + fitNGEFile_c + ) num_lines = sum(1 for line in open(fitNGEFile_c)) - #print num_lines - if (num_lines != 0): + # print num_lines + if num_lines != 0: # Uncomment the lines in this if statement, if you are ready to use STOP_NGE to exit the alignment - print "### --------------------------------------------------------------------------------------------" + print( + "### --------------------------------------------------------------------------------------------" + ) # print "### No. "+str(iterationCount)+" iteration's verdict is: STOP_NGE!" # print "### The mirror alignment has stopped, likely because there were not enough events for alignment." - print "### --------------------------------------------------------------------------------------------" + print( + "### --------------------------------------------------------------------------------------------" + ) iterations = " iterations !" if iterationCount + 1 == 1: iterations = " iteration !" -# print "### RICH"+RichDetectorStr+" mirror alignment is finished after "+str(iterationCount+1)+iterations - print strftime("%Y-%m-%d %H:%M:%S", gmtime()) - print "-------------------" + # print "### RICH"+RichDetectorStr+" mirror alignment is finished after "+str(iterationCount+1)+iterations + print(strftime("%Y-%m-%d %H:%M:%S", gmtime())) + print("-------------------") # os.system('echo "STOP_NGE" > '+"Rich"+RichDetectorStr+"_stop_or_continue.txt") # break - print "STOP_NGE would have broken the alignment here due to lack of events, but we're just testing this feature right now and it is not implemented yet." - - #============================================================================ - #=================== FIND MAGNIFICATION COEFFICIENTS ======================== - #============================================================================ + print( + "STOP_NGE would have broken the alignment here due to lack of events, but we're just testing this feature right now and it is not implemented yet." + ) - if (magnifCoeffMode == 2): + # ============================================================================ + # =================== FIND MAGNIFICATION COEFFICIENTS ======================== + # ============================================================================ - print "### ----------------------------------------------------------------------------" - print "### ------------ CALCULATING THE MAGNIFICATION COEFFICIENTS ------------" - print "### ----------------------------------------------------------------------------" - print strftime("%Y-%m-%d %H:%M:%S", gmtime()) - print "-------------------" + if magnifCoeffMode == 2: + print( + "### ----------------------------------------------------------------------------" + ) + print( + "### ------------ CALCULATING THE MAGNIFICATION COEFFICIENTS ------------" + ) + print( + "### ----------------------------------------------------------------------------" + ) + print(strftime("%Y-%m-%d %H:%M:%S", gmtime())) + print("-------------------") pNoTilt = [] for tiltNum, tiltName in enumerate(tiltNames): - - combinFitDir = workDir + "Rich" + RichDetectorStr + "MirrCombinFit_" + theseNamesWithTilts[ - tiltName] + "_i" + str(iterationCount) + "/" - combinResultsFile = combinFitDir + "Rich" + RichDetectorStr + "MirrCombinFit_" + theseNamesWithTilts[ - tiltName] + "_i" + str(iterationCount) + ".txt" - - magnificationOuputFile = workDir + "Rich" + RichDetectorStr + "MirrMagnFactors_" + theseNamesWithTilts[ - tiltName] + "_i" + str(iterationCount) + ".txt" - - #Input file is as follows | mirrorCombination | cos coeff | delta (cos coeff) | sin coeff | delta (sin coeff) + combinFitDir = ( + workDir + + "Rich" + + RichDetectorStr + + "MirrCombinFit_" + + theseNamesWithTilts[tiltName] + + "_i" + + str(iterationCount) + + "/" + ) + combinResultsFile = ( + combinFitDir + + "Rich" + + RichDetectorStr + + "MirrCombinFit_" + + theseNamesWithTilts[tiltName] + + "_i" + + str(iterationCount) + + ".txt" + ) + + magnificationOuputFile = ( + workDir + + "Rich" + + RichDetectorStr + + "MirrMagnFactors_" + + theseNamesWithTilts[tiltName] + + "_i" + + str(iterationCount) + + ".txt" + ) + + # Input file is as follows | mirrorCombination | cos coeff | delta (cos coeff) | sin coeff | delta (sin coeff) pWithTilt = [] with open(combinResultsFile) as fitfile: line = fitfile.readline() @@ -1824,7 +2396,7 @@ def mirroralign(RichInfoSettings="Something_Went_Wrong"): newpars = [] for i, j in enumerate(pars): - #print j + # print j if i == 0: newpars.append(j) else: @@ -1835,65 +2407,90 @@ def mirroralign(RichInfoSettings="Something_Went_Wrong"): pNoTilt.append(newpars) line = fitfile.readline() - with open(magnificationOuputFile, 'w') as magfile: - + with open(magnificationOuputFile, "w") as magfile: for i, sp in enumerate(pWithTilt): tiltSign = 1.0 - if tiltName.count('neg') > 0: + if tiltName.count("neg") > 0: tiltSign = -1.0 mirrPair = sp[0] - Y = (sp[1] - pNoTilt[i][1]) / ( - coeffCalibrTilt * tiltSign) - Z = (sp[3] - pNoTilt[i][3]) / ( - coeffCalibrTilt * tiltSign) + Y = (sp[1] - pNoTilt[i][1]) / (coeffCalibrTilt * tiltSign) + Z = (sp[3] - pNoTilt[i][3]) / (coeffCalibrTilt * tiltSign) - magfile.write(mirrPair + " " + str(Y) + " " + - str(Z) + "\n") + magfile.write( + mirrPair + " " + str(Y) + " " + str(Z) + "\n" + ) - #============================================================================ - #========================= START OF PER-MIRROR FIT ========================== - #============================================================================ + # ============================================================================ + # ========================= START OF PER-MIRROR FIT ========================== + # ============================================================================ # Rich2MirrAlign: misalignment correction for each mirror segment - #============================================================================ - - richMirrAlignConfFile = "Rich" + RichDetectorStr + "MirrAlign_i" + str( - iterationCount) + ".conf" - richMirrAlignOutFile = "Rich" + RichDetectorStr + "MirrAlignOut_i" + str( - iterationCount) + ".txt" - richMirrAlignNanOutFile = "Rich" + RichDetectorStr + "MirrAlignNanOut_i" + str( - iterationCount) + ".txt" + # ============================================================================ + + richMirrAlignConfFile = ( + "Rich" + RichDetectorStr + "MirrAlign_i" + str(iterationCount) + ".conf" + ) + richMirrAlignOutFile = ( + "Rich" + + RichDetectorStr + + "MirrAlignOut_i" + + str(iterationCount) + + ".txt" + ) + richMirrAlignNanOutFile = ( + "Rich" + + RichDetectorStr + + "MirrAlignNanOut_i" + + str(iterationCount) + + ".txt" + ) # Let's not implement these for now - #richMirrAlignStdOutFile = "Rich"+RichDetectorStr+"MirrAlignStdOut_i"+str(iterationCount)+".txt" - #richMirrAlignStdErrFile = "Rich"+RichDetectorStr+"MirrAlignStdErr_i"+str(iterationCount)+".txt" - - combinFitDir = workDir + "Rich" + RichDetectorStr + "MirrCombinFit_" + theseNamesWithTilts[ - ""] + "_i" + str(iterationCount) + "/" - combinResultsFile = combinFitDir + "Rich" + RichDetectorStr + "MirrCombinFit_" + theseNamesWithTilts[ - ""] + "_i" + str(iterationCount) + ".txt" + # richMirrAlignStdOutFile = "Rich"+RichDetectorStr+"MirrAlignStdOut_i"+str(iterationCount)+".txt" + # richMirrAlignStdErrFile = "Rich"+RichDetectorStr+"MirrAlignStdErr_i"+str(iterationCount)+".txt" + + combinFitDir = ( + workDir + + "Rich" + + RichDetectorStr + + "MirrCombinFit_" + + theseNamesWithTilts[""] + + "_i" + + str(iterationCount) + + "/" + ) + combinResultsFile = ( + combinFitDir + + "Rich" + + RichDetectorStr + + "MirrCombinFit_" + + theseNamesWithTilts[""] + + "_i" + + str(iterationCount) + + ".txt" + ) if os.path.exists(richMirrAlignConfFile): os.remove(richMirrAlignConfFile) - f = open(richMirrAlignConfFile, 'w') - args = 'workDir = ' + workDir + '\n' - args += 'thisVariant = ' + thisNameStr + '\n' + f = open(richMirrAlignConfFile, "w") + args = "workDir = " + workDir + "\n" + args += "thisVariant = " + thisNameStr + "\n" # args += 'thisNameStr = '+thisNameStr +'\n' - args += 'richDetector = ' + str(richDetector) + '\n' - args += 'magnFactorsMode = ' + str(magnifCoeffMode) + '\n' + args += "richDetector = " + str(richDetector) + "\n" + args += "magnFactorsMode = " + str(magnifCoeffMode) + "\n" # args += 'magnifCoeffMode = '+str(magnifCoeffMode) +'\n' - args += 'solutionMethod = ' + str(solutionMethod) + '\n' - args += 'usePremisaligned = ' + usePremisaligned + '\n' - args += 'iterationCount = ' + str(iterationCount) + '\n' - args += 'combAndMirrSubsets = ' + workDir + mirrCombinSubset + '\n' + args += "solutionMethod = " + str(solutionMethod) + "\n" + args += "usePremisaligned = " + usePremisaligned + "\n" + args += "iterationCount = " + str(iterationCount) + "\n" + args += "combAndMirrSubsets = " + workDir + mirrCombinSubset + "\n" # args += 'mirrCombinSubset = '+workDir+mirrCombinSubset+'\n' - args += 'mirrCombinFitResults = ' + combinResultsFile + '\n' + args += "mirrCombinFitResults = " + combinResultsFile + "\n" # args += 'outputResultsFile = '+combinResultsFile+'\n' - args += 'stopTolerance = ' + str(stopTolerance) + '\n' - args += 'zerothIterationXML = ' + workDir + zeroMirrorXMLFile + '\n' + args += "stopTolerance = " + str(stopTolerance) + "\n" + args += "zerothIterationXML = " + workDir + zeroMirrorXMLFile + "\n" # args += 'zerothIterationXMLFile = '+workDir+zeroMirrorXMLFile+'\n' # args += 'iterationZeroXMLFile = '+workDir+zeroMirrorXMLFile+'\n' # - args += 'currentIterationXML = ' + workDir + currentMirrorXMLFile + '\n' + args += "currentIterationXML = " + workDir + currentMirrorXMLFile + "\n" # args += 'currentIterationXMLFile = '+workDir+currentMirrorXMLFile+'\n' - args += 'nextIterationXML = ' + workDir + nextIterationXMLFile + '\n' + args += "nextIterationXML = " + workDir + nextIterationXMLFile + "\n" # args += 'nextIterationXMLFile = '+workDir+nextIterationXMLFile+'\n' f.write(args) f.close() @@ -1915,240 +2512,467 @@ def mirroralign(RichInfoSettings="Something_Went_Wrong"): We store them in Mirrors_rich2_thisNameStr_iterationCount+1.xml. """ - print "### ----------------------------------------------------------------------------" - print "### now running program that does the following:" - print "###" - print "### 1. finds individual misalignments of all Primary and Secondary mirror" - print "### segments" - print "###" - print "### 2. updates respective conditions in a temporary copy of RICH" + RichDetectorStr + " Mirrors.xml" - print "###" - print "### 3. if in result of this iteration, absolute values of all calculated" - print "### improvements to the current misalignment compensations are < 0.1 mrad," - print "### the program decides that the mirrors are aligned, but of course applies" - print "### these final improvements although they are somewhat redundant" - print "### ----------------------------------------------------------------------------" - print strftime("%Y-%m-%d %H:%M:%S", gmtime()) - print "-------------------" + print( + "### ----------------------------------------------------------------------------" + ) + print("### now running program that does the following:") + print("###") + print( + "### 1. finds individual misalignments of all Primary and Secondary mirror" + ) + print("### segments") + print("###") + print( + "### 2. updates respective conditions in a temporary copy of RICH" + + RichDetectorStr + + " Mirrors.xml" + ) + print("###") + print( + "### 3. if in result of this iteration, absolute values of all calculated" + ) + print( + "### improvements to the current misalignment compensations are < 0.1 mrad," + ) + print( + "### the program decides that the mirrors are aligned, but of course applies" + ) + print( + "### these final improvements although they are somewhat redundant" + ) + print( + "### ----------------------------------------------------------------------------" + ) + print(strftime("%Y-%m-%d %H:%M:%S", gmtime())) + print("-------------------") p = Popen( - "export HOME=" + home + ";" + "source " + pathToScripts + - "LbLogin.sh;" + "export User_release_area=" + userReleaseArea + - ";" + "source `which SetupProject.sh` Panoptes " + - setupProjectPanoptesVersion + " " + setupProjectPanoptesOptions - + ";" + "$RICHMIRRALIGNROOT/$CMTCONFIG/RichMirrAlign.exe " + - richMirrAlignConfFile + " > " + richMirrAlignOutFile, + "export HOME=" + + home + + ";" + + "source " + + pathToScripts + + "LbLogin.sh;" + + "export User_release_area=" + + userReleaseArea + + ";" + + "source `which SetupProject.sh` Panoptes " + + setupProjectPanoptesVersion + + " " + + setupProjectPanoptesOptions + + ";" + + "$RICHMIRRALIGNROOT/$CMTCONFIG/RichMirrAlign.exe " + + richMirrAlignConfFile + + " > " + + richMirrAlignOutFile, shell=True, executable="/bin/bash", stdout=PIPE, - stderr=PIPE) + stderr=PIPE, + ) (stdout, stderr) = p.communicate() stdReport(stdout, stderr) - #============================================================================ - if (backEnd == 'dirac' or backEnd == 'online'): - if os.path.isfile("Rich" + RichDetectorStr + "CondDBUpdate_" + - thisNameStr + "_i" + - str(iterationCount + 1) + ".xml"): - just_prettify("Rich" + RichDetectorStr + "CondDBUpdate_" + - thisNameStr + "_i" + - str(iterationCount + 1) + ".xml") - #======================== END OF PER-MIRROR CORRECTIONS ===================== + # ============================================================================ + if backEnd == "dirac" or backEnd == "online": + if os.path.isfile( + "Rich" + + RichDetectorStr + + "CondDBUpdate_" + + thisNameStr + + "_i" + + str(iterationCount + 1) + + ".xml" + ): + just_prettify( + "Rich" + + RichDetectorStr + + "CondDBUpdate_" + + thisNameStr + + "_i" + + str(iterationCount + 1) + + ".xml" + ) + # ======================== END OF PER-MIRROR CORRECTIONS ===================== """ break # <-- this can be used to run only one iteration """ - #Check for nan values, NanOutFile should have 0 lines in it - os.system('cat ' + richMirrAlignOutFile + ' | grep " nan " > ' + - richMirrAlignNanOutFile) - os.system('cat ' + richMirrAlignOutFile + ' | grep " -nan " > ' + - richMirrAlignNanOutFile) - os.system('cat ' + richMirrAlignOutFile + ' | grep " inf " > ' + - richMirrAlignNanOutFile) - os.system('cat ' + richMirrAlignOutFile + ' | grep " -inf " > ' + - richMirrAlignNanOutFile) - #Check that you didn't accidentally run RichMirrCombinFit before merging histos - fitStdErrFileFirst = combinFitDir + "Rich" + RichDetectorStr + "MirrCombinFitStdErr_" + theseNamesWithTilts[ - ""] + "_i" + str(iterationCount) + ".txt" - os.system('cat ' + fitStdErrFileFirst + - ' | grep "root does not exist" > ' + - richMirrAlignNanOutFile) + # Check for nan values, NanOutFile should have 0 lines in it + os.system( + "cat " + + richMirrAlignOutFile + + ' | grep " nan " > ' + + richMirrAlignNanOutFile + ) + os.system( + "cat " + + richMirrAlignOutFile + + ' | grep " -nan " > ' + + richMirrAlignNanOutFile + ) + os.system( + "cat " + + richMirrAlignOutFile + + ' | grep " inf " > ' + + richMirrAlignNanOutFile + ) + os.system( + "cat " + + richMirrAlignOutFile + + ' | grep " -inf " > ' + + richMirrAlignNanOutFile + ) + # Check that you didn't accidentally run RichMirrCombinFit before merging histos + fitStdErrFileFirst = ( + combinFitDir + + "Rich" + + RichDetectorStr + + "MirrCombinFitStdErr_" + + theseNamesWithTilts[""] + + "_i" + + str(iterationCount) + + ".txt" + ) + os.system( + "cat " + + fitStdErrFileFirst + + ' | grep "root does not exist" > ' + + richMirrAlignNanOutFile + ) num_lines = sum(1 for line in open(richMirrAlignNanOutFile)) - #print num_lines - if (num_lines != 0): - print "### --------------------------------------------------------------------------------------------" - print "### No. " + str( - iterationCount) + " iteration's verdict is: STOP_NAN!" - print "### The mirror alignment has stopped, likely because there were not enough events for alignment." - print "### --------------------------------------------------------------------------------------------" + # print num_lines + if num_lines != 0: + print( + "### --------------------------------------------------------------------------------------------" + ) + print( + "### No. " + + str(iterationCount) + + " iteration's verdict is: STOP_NAN!" + ) + print( + "### The mirror alignment has stopped, likely because there were not enough events for alignment." + ) + print( + "### --------------------------------------------------------------------------------------------" + ) iterations = " iterations !" if iterationCount + 1 == 1: iterations = " iteration !" - print "### RICH" + RichDetectorStr + " mirror alignment is finished after " + str( - iterationCount + 1) + iterations - print strftime("%Y-%m-%d %H:%M:%S", gmtime()) - print "-------------------" - os.system('echo "STOP_NAN" > ' + "Rich" + RichDetectorStr + - "_stop_or_continue.txt") + print( + "### RICH" + + RichDetectorStr + + " mirror alignment is finished after " + + str(iterationCount + 1) + + iterations + ) + print(strftime("%Y-%m-%d %H:%M:%S", gmtime())) + print("-------------------") + os.system( + 'echo "STOP_NAN" > ' + + "Rich" + + RichDetectorStr + + "_stop_or_continue.txt" + ) break - Rich_stop_or_continue_txt = open("Rich" + RichDetectorStr + - "_stop_or_continue.txt") + Rich_stop_or_continue_txt = open( + "Rich" + RichDetectorStr + "_stop_or_continue.txt" + ) verdict = Rich_stop_or_continue_txt.readline().strip().upper() Rich_stop_or_continue_txt.close() - print "### ------------------------------------------------------------------------------" - print "### No. " + str( - iterationCount) + " iteration's verdict is: " + verdict + "!" - print "### ------------------------------------------------------------------------------" - print strftime("%Y-%m-%d %H:%M:%S", gmtime()) - print "-------------------" - if (verdict == "STOP"): + print( + "### ------------------------------------------------------------------------------" + ) + print( + "### No. " + + str(iterationCount) + + " iteration's verdict is: " + + verdict + + "!" + ) + print( + "### ------------------------------------------------------------------------------" + ) + print(strftime("%Y-%m-%d %H:%M:%S", gmtime())) + print("-------------------") + if verdict == "STOP": iterations = " iterations !" if iterationCount + 1 == 1: iterations = " iteration !" - print "### RICH" + RichDetectorStr + " mirror alignment is finished after " + str( - iterationCount + 1) + iterations + print( + "### RICH" + + RichDetectorStr + + " mirror alignment is finished after " + + str(iterationCount + 1) + + iterations + ) # softlink the final .xml file to be inside the directory structure needed to be converted into a DB slice - os.system("ln -sf " + workDir + "Rich" + RichDetectorStr + - "CondDBUpdate_" + thisNameStr + "_i" + - str(iterationCount + 1) + ".xml " + workDir + - "Mirrors_rich" + RichDetectorStr + "_" + - thisNameStr + "/Conditions/Rich" + RichDetectorStr + - "/Alignment/Mirrors.xml") - if (os.path.exists("Mirrors_rich" + RichDetectorStr + "_" + - thisNameStr + ".db")): - os.system("rm -rf Mirrors_rich" + RichDetectorStr + "_" + - thisNameStr + ".db") + os.system( + "ln -sf " + + workDir + + "Rich" + + RichDetectorStr + + "CondDBUpdate_" + + thisNameStr + + "_i" + + str(iterationCount + 1) + + ".xml " + + workDir + + "Mirrors_rich" + + RichDetectorStr + + "_" + + thisNameStr + + "/Conditions/Rich" + + RichDetectorStr + + "/Alignment/Mirrors.xml" + ) + if os.path.exists( + "Mirrors_rich" + RichDetectorStr + "_" + thisNameStr + ".db" + ): + os.system( + "rm -rf Mirrors_rich" + + RichDetectorStr + + "_" + + thisNameStr + + ".db" + ) # create a final conditions database slice # containing only the final Mirrors.xml branch - print "### ----------------------------------------------------------------------------" - print "### converting the whole final Mirrors.xml branch into SQLite format:" - print "### Note that this replaces Mirrors_rich" + RichDetectorStr + "_" + thisNameStr + ".db with the final db slice." - print "### ----------------------------------------------------------------------------" + print( + "### ----------------------------------------------------------------------------" + ) + print( + "### converting the whole final Mirrors.xml branch into SQLite format:" + ) + print( + "### Note that this replaces Mirrors_rich" + + RichDetectorStr + + "_" + + thisNameStr + + ".db with the final db slice." + ) + print( + "### ----------------------------------------------------------------------------" + ) # prepare CondDB sqlite_file, which will be additional layer to the main database - print "copy_files_to_db.py -s Mirrors_rich" + RichDetectorStr + "_" + thisNameStr + " -c sqlite_file:Mirrors_rich" + RichDetectorStr + "_" + thisNameStr + ".db/" + CONDDB + print( + "copy_files_to_db.py -s Mirrors_rich" + + RichDetectorStr + + "_" + + thisNameStr + + " -c sqlite_file:Mirrors_rich" + + RichDetectorStr + + "_" + + thisNameStr + + ".db/" + + CONDDB + ) p = Popen( - "export HOME=" + home + ";" + "source " + pathToScripts + - "LbLogin.sh;" + "source `which SetupProject.sh` LHCb " + - LHCbVersion + " ;" + "copy_files_to_db.py -s Mirrors_rich" - + RichDetectorStr + "_" + thisNameStr + - " -c sqlite_file:Mirrors_rich" + RichDetectorStr + "_" + - thisNameStr + ".db/" + CONDDB + ";" + "python " + - PanoptesJobPath + "/tagger.py " + CondDB_tag + " " + - "Mirrors_rich" + RichDetectorStr + "_" + thisNameStr + " " + "export HOME=" + + home + + ";" + + "source " + + pathToScripts + + "LbLogin.sh;" + + "source `which SetupProject.sh` LHCb " + + LHCbVersion + + " ;" + + "copy_files_to_db.py -s Mirrors_rich" + + RichDetectorStr + + "_" + + thisNameStr + + " -c sqlite_file:Mirrors_rich" + + RichDetectorStr + + "_" + + thisNameStr + + ".db/" + + CONDDB + + ";" + + "python " + + PanoptesJobPath + + "/tagger.py " + + CondDB_tag + + " " + + "Mirrors_rich" + + RichDetectorStr + + "_" + + thisNameStr + + " " + CONDDB, shell=True, executable="/bin/bash", stdout=PIPE, - stderr=PIPE) + stderr=PIPE, + ) (stdout, stderr) = p.communicate() stdReport(stdout, stderr) break - print "### updating SQLite copy of the whole Mirrors.xml branch:" - print "### ----------------------------------------------------------------------------" - """ + print("### updating SQLite copy of the whole Mirrors.xml branch:") + print( + "### ----------------------------------------------------------------------------" + ) + ( + """ so by now we have used up the current copy of - Mirrors_rich""" + RichDetectorStr + """_thisNameStr_iterationCount.xml that was utilized for the + Mirrors_rich""" + + RichDetectorStr + + """_thisNameStr_iterationCount.xml that was utilized for the reconstruction in this iteration, and thus we increment the iterationCount and will now be using in the next iteration the freshly produced by RichMirrAlign for us Mirrors_rich2_thisNameStr_iterationCount+1.xml """ + ) iterationCount += 1 - currentMirrorXMLFile = "Rich" + RichDetectorStr + "CondDBUpdate_" + thisNameStr + "_i" + str( - iterationCount) + ".xml" - nextIterationXMLFile = "Rich" + RichDetectorStr + "CondDBUpdate_" + thisNameStr + "_i" + str( - iterationCount + 1) + ".xml" - print strftime("%Y-%m-%d %H:%M:%S", gmtime()) - print "-------------------" + currentMirrorXMLFile = ( + "Rich" + + RichDetectorStr + + "CondDBUpdate_" + + thisNameStr + + "_i" + + str(iterationCount) + + ".xml" + ) + nextIterationXMLFile = ( + "Rich" + + RichDetectorStr + + "CondDBUpdate_" + + thisNameStr + + "_i" + + str(iterationCount + 1) + + ".xml" + ) + print(strftime("%Y-%m-%d %H:%M:%S", gmtime())) + print("-------------------") iterationCount = 0 if justGlobalFit == 1: - RichDetectorStr = str(richDetector) - print strftime("%Y-%m-%d %H:%M:%S", gmtime()) - print "-------------------" + print(strftime("%Y-%m-%d %H:%M:%S", gmtime())) + print("-------------------") while iterationCount < maximumNumberOfIterations: - combinFitDir = workDir + "Rich" + RichDetectorStr + "MirrCombinFit_" + theseNamesWithTilts[ - tiltNames[0]] + "_i" + str(iterationCount) + "/" - fitConfigFile = combinFitDir + "Rich" + RichDetectorStr + "MirrCombinFit_" + theseNamesWithTilts[ - tiltNames[0]] + "_i" + str(iterationCount) + ".conf" - print "Using config file " + fitConfigFile + combinFitDir = ( + workDir + + "Rich" + + RichDetectorStr + + "MirrCombinFit_" + + theseNamesWithTilts[tiltNames[0]] + + "_i" + + str(iterationCount) + + "/" + ) + fitConfigFile = ( + combinFitDir + + "Rich" + + RichDetectorStr + + "MirrCombinFit_" + + theseNamesWithTilts[tiltNames[0]] + + "_i" + + str(iterationCount) + + ".conf" + ) + print("Using config file " + fitConfigFile) if os.path.exists(fitConfigFile) == 1: p = Popen( - "export HOME=" + home + ";" + "export User_release_area=" + - userReleaseArea + ";" + "source " + pathToScripts + - "LbLogin.sh;" + "source `which SetupProject.sh` Panoptes " - + setupProjectPanoptesVersion + " " + - setupProjectPanoptesOptions + ";" + - "$RICHMIRRCOMBINFITROOT/$CMTCONFIG/RichMirrCombinFit.exe " - + fitConfigFile + " " + RichDetectorStr + " 1", + "export HOME=" + + home + + ";" + + "export User_release_area=" + + userReleaseArea + + ";" + + "source " + + pathToScripts + + "LbLogin.sh;" + + "source `which SetupProject.sh` Panoptes " + + setupProjectPanoptesVersion + + " " + + setupProjectPanoptesOptions + + ";" + + "$RICHMIRRCOMBINFITROOT/$CMTCONFIG/RichMirrCombinFit.exe " + + fitConfigFile + + " " + + RichDetectorStr + + " 1", shell=True, executable="/bin/bash", stdout=PIPE, - stderr=PIPE) + stderr=PIPE, + ) (stdout, stderr) = p.communicate() stdReport(stdout, stderr) - print strftime("%Y-%m-%d %H:%M:%S", gmtime()) - print "-------------------" + print(strftime("%Y-%m-%d %H:%M:%S", gmtime())) + print("-------------------") iterationCount += 1 - #=============================================================================== + # =============================================================================== # end of loop over iterations - #=============================================================================== + # =============================================================================== # the loop ended because either converged or reached the # maximum-number-of-iterations limit, so: - if (verdict == "CONTINUE"): - print "### ----------------------------------------------------------------------------" - print "### maximum-number-of-iterations limit (" + str( - maximumNumberOfIterations) + ") is reached, and the whole program" - print "### has to stop, but notice: RICH" + RichDetectorStr + " mirror alignment has NOT reached the" - print "### desired accuracy yet." - print "### ----------------------------------------------------------------------------" - - print 'The whole thing is done' - print 'You are here in the working directory:' - print os.getcwd() - print 'Now I have taken you back to your starting directory:' + if verdict == "CONTINUE": + print( + "### ----------------------------------------------------------------------------" + ) + print( + "### maximum-number-of-iterations limit (" + + str(maximumNumberOfIterations) + + ") is reached, and the whole program" + ) + print( + "### has to stop, but notice: RICH" + + RichDetectorStr + + " mirror alignment has NOT reached the" + ) + print("### desired accuracy yet.") + print( + "### ----------------------------------------------------------------------------" + ) + + print("The whole thing is done") + print("You are here in the working directory:") + print(os.getcwd()) + print("Now I have taken you back to your starting directory:") os.chdir(wasHere) - print os.getcwd() + print(os.getcwd()) - if (backEnd == 'online'): - print "ONLINE not supported in this legacy script" + if backEnd == "online": + print("ONLINE not supported in this legacy script") # Set our status one last time com.set_status(state) - print "state = " - print state - print "com.set_status(state) one last time" + print("state = ") + print(state) + print("com.set_status(state) one last time") -#================================================================================= -#================================================================================= +# ================================================================================= +# ================================================================================= # This is the main program here. When this script is executed, it should run this: -print "Hi! All of the functions have now been defined. Time to run the RICH mirror alignment." -print strftime("%Y-%m-%d %H:%M:%S", gmtime()) -print "-------------------" +print( + "Hi! All of the functions have now been defined. Time to run the RICH mirror alignment." +) +print(strftime("%Y-%m-%d %H:%M:%S", gmtime())) +print("-------------------") if __name__ == "__main__": print( "This python file is being run directly, not being imported into another module." ) - print( - "mirroralign() is being called now, to perform the Offline mirror alignment." - ) - print strftime("%Y-%m-%d %H:%M:%S", gmtime()) - print "-------------------" - if (exists('RichInfoName')): + print("mirroralign() is being called now, to perform the Offline mirror alignment.") + print(strftime("%Y-%m-%d %H:%M:%S", gmtime())) + print("-------------------") + if exists("RichInfoName"): mirroralign(RichInfoName) else: - mirroralign() #this is going to crash + mirroralign() # this is going to crash print("mirroralign() has been run.") else: print( @@ -2157,5 +2981,5 @@ else: print("mirroralign() will not be not run yet.") print("Now exiting the mirror alignment driver python script.") -print strftime("%Y-%m-%d %H:%M:%S", gmtime()) -print "-------------------" +print(strftime("%Y-%m-%d %H:%M:%S", gmtime())) +print("-------------------") diff --git a/Rich/RichMirrorAlignmentGanga/job/settings/RichMirrorAlignmentGanga_Collision10_settings_R2MD.py b/Rich/RichMirrorAlignmentGanga/job/settings/RichMirrorAlignmentGanga_Collision10_settings_R2MD.py index 116362c0e020ee8df8f90cfddac846d563a319a5..86f8866b64548528aa6126d8d8a19cef1fa33ba7 100644 --- a/Rich/RichMirrorAlignmentGanga/job/settings/RichMirrorAlignmentGanga_Collision10_settings_R2MD.py +++ b/Rich/RichMirrorAlignmentGanga/job/settings/RichMirrorAlignmentGanga_Collision10_settings_R2MD.py @@ -12,21 +12,21 @@ import os from subprocess import * -#=============================================================================== +# =============================================================================== # defs -#=============================================================================== +# =============================================================================== # stdReporter returns stdout and stderr from Popen.communicate() def stdReporter(stdout, stderr): - print "The shell script gave some STANDARD OUTPUT:" - print stdout + print("The shell script gave some STANDARD OUTPUT:") + print(stdout) if stderr: - print "The shell script also gave some STANDARD ERROR:" - print stderr + print("The shell script also gave some STANDARD ERROR:") + print(stderr) else: - print "The shell script ran fine." + print("The shell script ran fine.") -#=============================================================================== +# =============================================================================== ######################################################## # Search "Important" to find things you had better check @@ -34,35 +34,37 @@ def stdReporter(stdout, stderr): ######################################################## ### Important: What is the backend -backEnd = 'dirac' -#backEnd = 'online' +backEnd = "dirac" +# backEnd = 'online' ### Important: Set your home directory home = "/afs/cern.ch/user/p/pnaik" # point this to your home directory -if (backEnd.lower() == 'online'): +if backEnd.lower() == "online": home = "/home/pnaik" # point this to the online home ### Important: Choose Panoptes Version (HEAD is usually fine, for Offline Alignment) setupProjectPanoptesVersion = "HEAD" -if (backEnd.lower() == 'online'): +if backEnd.lower() == "online": setupProjectPanoptesVersion = "v5r2" # you want a fixed version online ### Important: Choose Panoptes Options -setupProjectPanoptesOptions = "--nightly lhcb-head Thu" # Safest to specify a day that you know is working -#setupProjectPanoptesOptions = "--nightly lhcb-head" # will fail if running the script overnight -#setupProjectPanoptesOptions = "--nightly lhcb-prerelease Sun" -#setupProjectPanoptesOptions = "--nightly lhcb-prerelease" -#setupProjectPanoptesOptions = "--dev-dir=/afs/cern.ch/user/p/pnaik/PANOPTES" -if (backEnd.lower() == 'online'): +setupProjectPanoptesOptions = ( + "--nightly lhcb-head Thu" # Safest to specify a day that you know is working +) +# setupProjectPanoptesOptions = "--nightly lhcb-head" # will fail if running the script overnight +# setupProjectPanoptesOptions = "--nightly lhcb-prerelease Sun" +# setupProjectPanoptesOptions = "--nightly lhcb-prerelease" +# setupProjectPanoptesOptions = "--dev-dir=/afs/cern.ch/user/p/pnaik/PANOPTES" +if backEnd.lower() == "online": setupProjectPanoptesOptions = "" ### Important: Define a working directory. If it does not exist, make it. workDir = "/afs/cern.ch/user/p/pnaik/RichAlignment/2010/ParasR2MD" # Point this to your working directory -if (backEnd.lower() == 'online'): +if backEnd.lower() == "online": workDir = "/home/pnaik/rich/2010/R2MD" if not os.path.isdir(workDir): - print "*** DOES NOT EXIST: workDir = " + workDir - print "*** Making " + workDir + print("*** DOES NOT EXIST: workDir = " + workDir) + print("*** Making " + workDir) os.makedirs(workDir) ### Important: Get the database tags right @@ -70,20 +72,20 @@ dDDB_tag = "head-20110721" condDB_tag = "cond-20140328" ### Important: Set the LHCb and Brunel version and Brunel extra options -LHCbVersion = '' -if (backEnd.lower() == 'online'): - LHCbVersion = 'v36r2' -brunelVersion = 'v47r5' +LHCbVersion = "" +if backEnd.lower() == "online": + LHCbVersion = "v36r2" +brunelVersion = "v47r5" setupProjectBrunelOpts = "" ### Important: Where is the data eventSelectorInputFile = "/afs/cern.ch/user/p/pnaik/RichAlignment/2010/data/RICH2-selectionMagDown.py" # make sure this exists -if (backEnd.lower() == 'online'): +if backEnd.lower() == "online": eventSelectorInputFile = "/home/pnaik/rich/2010/R2MD/RICH2-selectionMagDown.py" # we will be using the data from the HLT ### Important: What is the input type of your data brunelInitialInputType = "DST" -if (backEnd.lower() == 'online'): +if backEnd.lower() == "online": brunelInitialInputType = "RAW" ### Important: Which RICH? @@ -99,23 +101,23 @@ dataVariant = "Collision10" date = "1341100800000000000" ### Important: What are the Added DBs? (NOTE: reading local DBs is currently untested.... please do sometime, then remove this note) -#AddedDB = [ # make sure these exist -#"/afs/cern.ch/user/p/pnaik/lhcb/rich/2010/dbSlices/v6.2series.2010.db", -#"/afs/cern.ch/user/p/pnaik/lhcb/rich/2010/dbSlices/v6.2series.2010.TT.temperature.db", -#"/afs/cern.ch/user/p/pnaik/lhcb/rich/2010/dbSlices/OT_t0s_2010.db", -#"/afs/cern.ch/user/p/pnaik/lhcb/rich/2010/dbSlices/MDCS-RICH1-FINAL-08052014.db", -#"/afs/cern.ch/user/p/pnaik/lhcb/rich/2010/dbSlices/RefInCalib-2010RePro-V1_BR-v45r1-15052014.db", -#"/afs/cern.ch/user/p/pnaik/lhcb/rich/2010/dbSlices/2010RePro-RootFiles-V1-RunAligned-Sobel-Smoothed1.0hours-HPDAlign-15052014.db", -#"/afs/cern.ch/user/p/pnaik/lhcb/rich/2010/dbSlices/2010RePro-RootFiles-V1-RunAligned-Sobel-Smoothed0.5hours-HPDOcc-16052014.db" -#] +# AddedDB = [ # make sure these exist +# "/afs/cern.ch/user/p/pnaik/lhcb/rich/2010/dbSlices/v6.2series.2010.db", +# "/afs/cern.ch/user/p/pnaik/lhcb/rich/2010/dbSlices/v6.2series.2010.TT.temperature.db", +# "/afs/cern.ch/user/p/pnaik/lhcb/rich/2010/dbSlices/OT_t0s_2010.db", +# "/afs/cern.ch/user/p/pnaik/lhcb/rich/2010/dbSlices/MDCS-RICH1-FINAL-08052014.db", +# "/afs/cern.ch/user/p/pnaik/lhcb/rich/2010/dbSlices/RefInCalib-2010RePro-V1_BR-v45r1-15052014.db", +# "/afs/cern.ch/user/p/pnaik/lhcb/rich/2010/dbSlices/2010RePro-RootFiles-V1-RunAligned-Sobel-Smoothed1.0hours-HPDAlign-15052014.db", +# "/afs/cern.ch/user/p/pnaik/lhcb/rich/2010/dbSlices/2010RePro-RootFiles-V1-RunAligned-Sobel-Smoothed0.5hours-HPDOcc-16052014.db" +# ] AddedDB = [ # make sure these exist - 'LFN:/lhcb/user/j/jonrob/DBs/v6.2series.2010.db', - 'LFN:/lhcb/user/j/jonrob/DBs/v6.2series.2010.TT.temperature.db', - 'LFN:/lhcb/user/j/jonrob/DBs/OT_t0s_2010.db', - 'LFN:/lhcb/user/j/jonrob/DBs/MDCS-RICH1-FINAL-08052014.db', - 'LFN:/lhcb/user/j/jonrob/DBs/RefInCalib-2010RePro-V1_BR-v45r1-15052014.db', - 'LFN:/lhcb/user/j/jonrob/DBs/2010RePro-RootFiles-V1-RunAligned-Sobel-Smoothed1.0hours-HPDAlign-15052014.db', - 'LFN:/lhcb/user/j/jonrob/DBs/2010RePro-RootFiles-V1-RunAligned-Sobel-Smoothed0.5hours-HPDOcc-16052014.db' + "LFN:/lhcb/user/j/jonrob/DBs/v6.2series.2010.db", + "LFN:/lhcb/user/j/jonrob/DBs/v6.2series.2010.TT.temperature.db", + "LFN:/lhcb/user/j/jonrob/DBs/OT_t0s_2010.db", + "LFN:/lhcb/user/j/jonrob/DBs/MDCS-RICH1-FINAL-08052014.db", + "LFN:/lhcb/user/j/jonrob/DBs/RefInCalib-2010RePro-V1_BR-v45r1-15052014.db", + "LFN:/lhcb/user/j/jonrob/DBs/2010RePro-RootFiles-V1-RunAligned-Sobel-Smoothed1.0hours-HPDAlign-15052014.db", + "LFN:/lhcb/user/j/jonrob/DBs/2010RePro-RootFiles-V1-RunAligned-Sobel-Smoothed0.5hours-HPDOcc-16052014.db", ] ######################################################## @@ -126,39 +128,45 @@ AddedDB = [ # make sure these exist ### This is standard, do not change userReleaseArea = os.getenv("User_release_area") pathToScripts = "/afs/cern.ch/lhcb/software/releases/LBSCRIPTS/prod/InstallArea/scripts" -if (backEnd.lower() == 'online'): +if backEnd.lower() == "online": pathToScripts = "/cvmfs/lhcb.cern.ch/lib/lhcb/LBSCRIPTS/prod/InstallArea/scripts" ### This gets the environment variables we will need automatically, based on the above p = Popen( - "export HOME=" + home + ";" + "source " + pathToScripts + "/LbLogin.sh;" + - "export User_release_area=" + userReleaseArea + ";" + "export HOME=" + + home + + ";" + + "source " + + pathToScripts + + "/LbLogin.sh;" + + "export User_release_area=" + + userReleaseArea + + ";" # +"export CMTPROJECTPATH=/afs/cern.ch/sw/lcg/external/xqilla/2.2.4/x86_64-slc5-gcc43-opt/lib:$CMTPROJECTPATH;" # probably obsolete - + "source `which SetupProject.sh` Panoptes " + setupProjectPanoptesVersion - + " " + setupProjectPanoptesOptions + ";" + - "rm -f env_var_settings_mirroralign.txt;" - + - "echo $RICHMIRRALIGNROOT > env_var_settings_mirroralign.txt; " # Line 1 - + - "echo $RICHMIRRCOMBINFITROOT >> env_var_settings_mirroralign.txt; " # Line 2 - + - "echo $RICHMIRRORALIGNMENTGANGAROOT >> env_var_settings_mirroralign.txt; " # Line 3 - + - "echo $SQLITEDBPATH >> env_var_settings_mirroralign.txt; " # Line 4 + + "source `which SetupProject.sh` Panoptes " + + setupProjectPanoptesVersion + + " " + + setupProjectPanoptesOptions + + ";" + + "rm -f env_var_settings_mirroralign.txt;" + + "echo $RICHMIRRALIGNROOT > env_var_settings_mirroralign.txt; " # Line 1 + + "echo $RICHMIRRCOMBINFITROOT >> env_var_settings_mirroralign.txt; " # Line 2 + + "echo $RICHMIRRORALIGNMENTGANGAROOT >> env_var_settings_mirroralign.txt; " # Line 3 + + "echo $SQLITEDBPATH >> env_var_settings_mirroralign.txt; " # Line 4 + "echo $SHELL", shell=True, executable="/bin/bash", stdout=PIPE, - stderr=PIPE) + stderr=PIPE, +) (stdout, stderr) = p.communicate() stdReporter(stdout, stderr) env_var_settings_mirroralign_txt = open("env_var_settings_mirroralign.txt") -RICHMIRRALIGNROOT = env_var_settings_mirroralign_txt.readline().strip( -) # Line 1 -RICHMIRRCOMBINFITROOT = env_var_settings_mirroralign_txt.readline().strip( -) # Line 2 -RICHMIRRORALIGNMENTGANGAROOT = env_var_settings_mirroralign_txt.readline( -).strip() # Line 3 +RICHMIRRALIGNROOT = env_var_settings_mirroralign_txt.readline().strip() # Line 1 +RICHMIRRCOMBINFITROOT = env_var_settings_mirroralign_txt.readline().strip() # Line 2 +RICHMIRRORALIGNMENTGANGAROOT = ( + env_var_settings_mirroralign_txt.readline().strip() +) # Line 3 SQLITEDBPATH = env_var_settings_mirroralign_txt.readline().strip() # Line 4 env_var_settings_mirroralign_txt.close() os.system("rm -f env_var_settings_mirroralign.txt") @@ -197,27 +205,35 @@ messageSvcOutputLevel = "3" ### Automatic choice of mirrCombinSubset file mirrCombinSubset = "" -if (richDetector == 2): +if richDetector == 2: mirrCombinSubset = "Rich2CombAndMirrSubsets_96m94c_p12p43fix.txt" # not yet available in PANOPTES HEAD, so I don't try to read it using os.system on the next line - #os.system("cp "+RICHMIRRORALIGNMENTGANGAROOT+"files/Rich2CombAndMirrSubsets_96m94c_p12p43fix.txt .") - os.system("cp " + RICHMIRRALIGNROOT + - "Test/Rich2CombAndMirrSubsets_96m94c_p12p43fix.txt " + - workDir) # Requires RICHMIRRALIGNROOT to be defined -if (richDetector == 1): + # os.system("cp "+RICHMIRRORALIGNMENTGANGAROOT+"files/Rich2CombAndMirrSubsets_96m94c_p12p43fix.txt .") + os.system( + "cp " + + RICHMIRRALIGNROOT + + "Test/Rich2CombAndMirrSubsets_96m94c_p12p43fix.txt " + + workDir + ) # Requires RICHMIRRALIGNROOT to be defined +if richDetector == 1: mirrCombinSubset = "Rich1CombAndMirrSubsets_20m16c_p0p1p2p3fix.txt" - #os.system("cp "+RICHMIRRORALIGNMENTGANGAROOT+"files/Rich1CombAndMirrSubsets_20m16c_p0p1p2p3fix.txt .") - os.system("cp " + RICHMIRRALIGNROOT + - "Test/Rich1CombAndMirrSubsets_20m16c_p0p1p2p3fix.txt " + - workDir) # Requires RICHMIRRALIGNROOT to be defined + # os.system("cp "+RICHMIRRORALIGNMENTGANGAROOT+"files/Rich1CombAndMirrSubsets_20m16c_p0p1p2p3fix.txt .") + os.system( + "cp " + + RICHMIRRALIGNROOT + + "Test/Rich1CombAndMirrSubsets_20m16c_p0p1p2p3fix.txt " + + workDir + ) # Requires RICHMIRRALIGNROOT to be defined ### Standard RICH mirror Alignment parameters, do not touch unless you are an expert groupSlices = 1 groupBins = 1 -minAverageBinPop = 6 # 6 * 50 deltaTheta bins in one phi bin slice = 300 photons minimum per phi bin +minAverageBinPop = ( + 6 # 6 * 50 deltaTheta bins in one phi bin slice = 300 photons minimum per phi bin +) -deltaThetaWindow = 4.0 #4 -if (richDetector == 2): - deltaThetaWindow = 3.0 #2 +deltaThetaWindow = 4.0 # 4 +if richDetector == 2: + deltaThetaWindow = 3.0 # 2 coeffCalibrTilt = 0.3 @@ -228,24 +244,30 @@ verOffsetsFromMC = "" usePremisaligned = "false" -combinFitVariant = 1 #"slices" -if (richDetector == 2): - combinFitVariant = 3 #"surfaceB" RICH2 +combinFitVariant = 1 # "slices" +if richDetector == 2: + combinFitVariant = 3 # "surfaceB" RICH2 maximumNumberOfIterations = 10 ### Change these if something bad happens in an iteration, but it is recoverable (i.e. Ganga jobs failed) startFromIteration = 0 # which iteration do you want to start from? NEED TO CHECK/CONFIRM THIS WORKS FOR ANYTHING OTHER THAN 0 -skipFirstRecoJob = 0 # currently only for iteration 0, skip submitting Brunel jobs to grid -skipFirstMergeJob = 0 # currently only for iteration 0, skip the merging Brunel histograms +skipFirstRecoJob = ( + 0 # currently only for iteration 0, skip submitting Brunel jobs to grid +) +skipFirstMergeJob = ( + 0 # currently only for iteration 0, skip the merging Brunel histograms +) if skipFirstRecoJob == 0: if skipFirstMergeJob == 1: skipFirstMergeJob == 0 -#if you are not skipping brunel jobs, you do not want to skip the merging of the brunel jobs! -#if you want to merge the jobs from a previous run of the script you must provide the job numbers -previousJobNumbers = range(984, 993) +# if you are not skipping brunel jobs, you do not want to skip the merging of the brunel jobs! +# if you want to merge the jobs from a previous run of the script you must provide the job numbers +previousJobNumbers = list(range(984, 993)) -skipFirstCombinFit = 0 # currently only for iteration 0, skip the combinFit before mirrAlign +skipFirstCombinFit = ( + 0 # currently only for iteration 0, skip the combinFit before mirrAlign +) ### Standard RICH mirror Alignment parameters, do not touch unless you are an expert @@ -258,9 +280,10 @@ skipFirstCombinFit = 0 # currently only for iteration 0, skip the combinFit bef magnifCoeffMode = 2 # 2: individual for each pair # evaluated on-fly for each iteration # depedent on sign of rotation -if (magnifCoeffMode == 0): - os.system("cp " + RICHMIRRORALIGNMENTGANGAROOT + "/files/MagCoeffs/* " + - workDir) # Requires RICHMIRRORALIGNMENTGANGAROOT to be defined +if magnifCoeffMode == 0: + os.system( + "cp " + RICHMIRRORALIGNMENTGANGAROOT + "/files/MagCoeffs/* " + workDir + ) # Requires RICHMIRRORALIGNMENTGANGAROOT to be defined # 0: Minuit solutionMethod = 1 # 1: algebraic diff --git a/Rich/RichMirrorAlignmentGanga/job/settings/RichMirrorAlignmentGanga_Collision11_settings_R2MD.py b/Rich/RichMirrorAlignmentGanga/job/settings/RichMirrorAlignmentGanga_Collision11_settings_R2MD.py index 10b4fd712c3f227cae9f57e7a44d4c454e594f7a..147d640d6d82339d2f18b5582683807a981fd848 100644 --- a/Rich/RichMirrorAlignmentGanga/job/settings/RichMirrorAlignmentGanga_Collision11_settings_R2MD.py +++ b/Rich/RichMirrorAlignmentGanga/job/settings/RichMirrorAlignmentGanga_Collision11_settings_R2MD.py @@ -12,21 +12,21 @@ import os from subprocess import * -#=============================================================================== +# =============================================================================== # defs -#=============================================================================== +# =============================================================================== # stdReporter returns stdout and stderr from Popen.communicate() def stdReporter(stdout, stderr): - print "The shell script gave some STANDARD OUTPUT:" - print stdout + print("The shell script gave some STANDARD OUTPUT:") + print(stdout) if stderr: - print "The shell script also gave some STANDARD ERROR:" - print stderr + print("The shell script also gave some STANDARD ERROR:") + print(stderr) else: - print "The shell script ran fine." + print("The shell script ran fine.") -#=============================================================================== +# =============================================================================== ######################################################## # Search "Important" to find things you had better check @@ -37,34 +37,36 @@ def stdReporter(stdout, stderr): ### Important: What is the backend backEnd = "dirac" -#backEnd = "online" +# backEnd = "online" ### Important: Set your home directory home = "/afs/cern.ch/user/p/pnaik" # point this to your home directory -if (backEnd.lower() == 'online'): +if backEnd.lower() == "online": home = "/home/pnaik" # point this to the online home ### Important: Choose Panoptes Version (HEAD is usually fine, for Offline Alignment) setupProjectPanoptesVersion = "HEAD" -if (backEnd.lower() == 'online'): +if backEnd.lower() == "online": setupProjectPanoptesVersion = "v5r2" # you want a fixed version online ### Important: Choose Panoptes Options -setupProjectPanoptesOptions = "--nightly lhcb-head Thu" # Safest to specify a day that you know is working -#setupProjectPanoptesOptions = "--nightly lhcb-head" # will fail if running the script overnight -#setupProjectPanoptesOptions = "--nightly lhcb-prerelease Sun" -#setupProjectPanoptesOptions = "--nightly lhcb-prerelease" -#setupProjectPanoptesOptions = "--dev-dir=/afs/cern.ch/user/p/pnaik/PANOPTES" -if (backEnd.lower() == 'online'): +setupProjectPanoptesOptions = ( + "--nightly lhcb-head Thu" # Safest to specify a day that you know is working +) +# setupProjectPanoptesOptions = "--nightly lhcb-head" # will fail if running the script overnight +# setupProjectPanoptesOptions = "--nightly lhcb-prerelease Sun" +# setupProjectPanoptesOptions = "--nightly lhcb-prerelease" +# setupProjectPanoptesOptions = "--dev-dir=/afs/cern.ch/user/p/pnaik/PANOPTES" +if backEnd.lower() == "online": setupProjectPanoptesOptions = "" ### Important: Define a working directory. If it does not exist, make it. workDir = "/afs/cern.ch/user/p/pnaik/RichAlignment/2011/ParasR2MD" # Point this to your working directory -if (backEnd.lower() == 'online'): +if backEnd.lower() == "online": workDir = "/home/pnaik/rich/2011/R2MD" if not os.path.isdir(workDir): - print "*** DOES NOT EXIST: workDir = " + workDir - print "*** Making " + workDir + print("*** DOES NOT EXIST: workDir = " + workDir) + print("*** Making " + workDir) os.makedirs(workDir) ### Important: Get the database tags right @@ -72,20 +74,20 @@ dDDB_tag = "dddb-20120831" condDB_tag = "cond-20120917" ### Important: Set the LHCb and Brunel version and Brunel extra options -LHCbVersion = '' -if (backEnd.lower() == 'online'): - LHCbVersion = 'v36r2' -brunelVersion = 'v47r5' +LHCbVersion = "" +if backEnd.lower() == "online": + LHCbVersion = "v36r2" +brunelVersion = "v47r5" setupProjectBrunelOpts = "" ### Important: Where is the data eventSelectorInputFile = "/afs/cern.ch/user/p/pnaik/RichAlignment/2011/data/RICH2-selectionMagDown.py" # make sure this exists -if (backEnd.lower() == 'online'): +if backEnd.lower() == "online": eventSelectorInputFile = "/home/pnaik/rich/2011/R2MD/RICH2-selectionMagDown.py" # we will be using the data from the HLT ### Important: What is the input type of your data brunelInitialInputType = "RAW" -if (backEnd.lower() == 'online'): +if backEnd.lower() == "online": brunelInitialInputType = "RAW" ### Important: Which RICH? @@ -111,39 +113,45 @@ AddedDB = [""] ### This is standard, do not change userReleaseArea = os.getenv("User_release_area") pathToScripts = "/afs/cern.ch/lhcb/software/releases/LBSCRIPTS/prod/InstallArea/scripts" -if (backEnd.lower() == 'online'): +if backEnd.lower() == "online": pathToScripts = "/cvmfs/lhcb.cern.ch/lib/lhcb/LBSCRIPTS/prod/InstallArea/scripts" ### This gets the environment variables we will need automatically, based on the above p = Popen( - "export HOME=" + home + ";" + "source " + pathToScripts + "/LbLogin.sh;" + - "export User_release_area=" + userReleaseArea + ";" + "export HOME=" + + home + + ";" + + "source " + + pathToScripts + + "/LbLogin.sh;" + + "export User_release_area=" + + userReleaseArea + + ";" # +"export CMTPROJECTPATH=/afs/cern.ch/sw/lcg/external/xqilla/2.2.4/x86_64-slc5-gcc43-opt/lib:$CMTPROJECTPATH;" # probably obsolete - + "source `which SetupProject.sh` Panoptes " + setupProjectPanoptesVersion - + " " + setupProjectPanoptesOptions + ";" + - "rm -f env_var_settings_mirroralign.txt;" - + - "echo $RICHMIRRALIGNROOT > env_var_settings_mirroralign.txt; " # Line 1 - + - "echo $RICHMIRRCOMBINFITROOT >> env_var_settings_mirroralign.txt; " # Line 2 - + - "echo $RICHMIRRORALIGNMENTGANGAROOT >> env_var_settings_mirroralign.txt; " # Line 3 - + - "echo $SQLITEDBPATH >> env_var_settings_mirroralign.txt; " # Line 4 + + "source `which SetupProject.sh` Panoptes " + + setupProjectPanoptesVersion + + " " + + setupProjectPanoptesOptions + + ";" + + "rm -f env_var_settings_mirroralign.txt;" + + "echo $RICHMIRRALIGNROOT > env_var_settings_mirroralign.txt; " # Line 1 + + "echo $RICHMIRRCOMBINFITROOT >> env_var_settings_mirroralign.txt; " # Line 2 + + "echo $RICHMIRRORALIGNMENTGANGAROOT >> env_var_settings_mirroralign.txt; " # Line 3 + + "echo $SQLITEDBPATH >> env_var_settings_mirroralign.txt; " # Line 4 + "echo $SHELL", shell=True, executable="/bin/bash", stdout=PIPE, - stderr=PIPE) + stderr=PIPE, +) (stdout, stderr) = p.communicate() stdReporter(stdout, stderr) env_var_settings_mirroralign_txt = open("env_var_settings_mirroralign.txt") -RICHMIRRALIGNROOT = env_var_settings_mirroralign_txt.readline().strip( -) # Line 1 -RICHMIRRCOMBINFITROOT = env_var_settings_mirroralign_txt.readline().strip( -) # Line 2 -RICHMIRRORALIGNMENTGANGAROOT = env_var_settings_mirroralign_txt.readline( -).strip() # Line 3 +RICHMIRRALIGNROOT = env_var_settings_mirroralign_txt.readline().strip() # Line 1 +RICHMIRRCOMBINFITROOT = env_var_settings_mirroralign_txt.readline().strip() # Line 2 +RICHMIRRORALIGNMENTGANGAROOT = ( + env_var_settings_mirroralign_txt.readline().strip() +) # Line 3 SQLITEDBPATH = env_var_settings_mirroralign_txt.readline().strip() # Line 4 env_var_settings_mirroralign_txt.close() os.system("rm -f env_var_settings_mirroralign.txt") @@ -182,27 +190,35 @@ messageSvcOutputLevel = "3" ### Automatic choice of mirrCombinSubset file mirrCombinSubset = "" -if (richDetector == 2): +if richDetector == 2: mirrCombinSubset = "Rich2CombAndMirrSubsets_96m94c_p12p43fix.txt" # not yet available in PANOPTES HEAD, so I don't try to read it using os.system on the next line - #os.system("cp "+RICHMIRRORALIGNMENTGANGAROOT+"files/Rich2CombAndMirrSubsets_96m94c_p12p43fix.txt .") - os.system("cp " + RICHMIRRALIGNROOT + - "Test/Rich2CombAndMirrSubsets_96m94c_p12p43fix.txt " + - workDir) # Requires RICHMIRRALIGNROOT to be defined -if (richDetector == 1): + # os.system("cp "+RICHMIRRORALIGNMENTGANGAROOT+"files/Rich2CombAndMirrSubsets_96m94c_p12p43fix.txt .") + os.system( + "cp " + + RICHMIRRALIGNROOT + + "Test/Rich2CombAndMirrSubsets_96m94c_p12p43fix.txt " + + workDir + ) # Requires RICHMIRRALIGNROOT to be defined +if richDetector == 1: mirrCombinSubset = "Rich1CombAndMirrSubsets_20m16c_p0p1p2p3fix.txt" - #os.system("cp "+RICHMIRRORALIGNMENTGANGAROOT+"files/Rich1CombAndMirrSubsets_20m16c_p0p1p2p3fix.txt .") - os.system("cp " + RICHMIRRALIGNROOT + - "Test/Rich1CombAndMirrSubsets_20m16c_p0p1p2p3fix.txt " + - workDir) # Requires RICHMIRRALIGNROOT to be defined + # os.system("cp "+RICHMIRRORALIGNMENTGANGAROOT+"files/Rich1CombAndMirrSubsets_20m16c_p0p1p2p3fix.txt .") + os.system( + "cp " + + RICHMIRRALIGNROOT + + "Test/Rich1CombAndMirrSubsets_20m16c_p0p1p2p3fix.txt " + + workDir + ) # Requires RICHMIRRALIGNROOT to be defined ### Standard RICH mirror Alignment parameters, do not touch unless you are an expert groupSlices = 1 groupBins = 1 -minAverageBinPop = 6 # 6 * 50 deltaTheta bins in one phi bin slice = 300 photons minimum per phi bin +minAverageBinPop = ( + 6 # 6 * 50 deltaTheta bins in one phi bin slice = 300 photons minimum per phi bin +) -deltaThetaWindow = 4.0 #4 -if (richDetector == 2): - deltaThetaWindow = 3.0 #2 +deltaThetaWindow = 4.0 # 4 +if richDetector == 2: + deltaThetaWindow = 3.0 # 2 coeffCalibrTilt = 0.3 @@ -213,24 +229,30 @@ verOffsetsFromMC = "" usePremisaligned = "false" -combinFitVariant = 1 #"slices" -if (richDetector == 2): - combinFitVariant = 3 #"surfaceB" RICH2 +combinFitVariant = 1 # "slices" +if richDetector == 2: + combinFitVariant = 3 # "surfaceB" RICH2 maximumNumberOfIterations = 10 ### Change these if something bad happens in an iteration, but it is recoverable (i.e. Ganga jobs failed) startFromIteration = 0 # which iteration do you want to start from? NEED TO CHECK/CONFIRM THIS WORKS FOR ANYTHING OTHER THAN 0 -skipFirstRecoJob = 0 # currently only for iteration 0, skip submitting Brunel jobs to grid -skipFirstMergeJob = 0 # currently only for iteration 0, skip the merging Brunel histograms +skipFirstRecoJob = ( + 0 # currently only for iteration 0, skip submitting Brunel jobs to grid +) +skipFirstMergeJob = ( + 0 # currently only for iteration 0, skip the merging Brunel histograms +) if skipFirstRecoJob == 0: if skipFirstMergeJob == 1: skipFirstMergeJob == 0 -#if you are not skipping brunel jobs, you do not want to skip the merging of the brunel jobs! -#if you want to merge the jobs from a previous run of the script you must provide the job numbers -previousJobNumbers = range(984, 993) +# if you are not skipping brunel jobs, you do not want to skip the merging of the brunel jobs! +# if you want to merge the jobs from a previous run of the script you must provide the job numbers +previousJobNumbers = list(range(984, 993)) -skipFirstCombinFit = 0 # currently only for iteration 0, skip the combinFit before mirrAlign +skipFirstCombinFit = ( + 0 # currently only for iteration 0, skip the combinFit before mirrAlign +) ### Standard RICH mirror Alignment parameters, do not touch unless you are an expert @@ -243,9 +265,10 @@ skipFirstCombinFit = 0 # currently only for iteration 0, skip the combinFit bef magnifCoeffMode = 2 # 2: individual for each pair # evaluated on-fly for each iteration # depedent on sign of rotation -if (magnifCoeffMode == 0): - os.system("cp " + RICHMIRRORALIGNMENTGANGAROOT + "/files/MagCoeffs/* " + - workDir) # Requires RICHMIRRORALIGNMENTGANGAROOT to be defined +if magnifCoeffMode == 0: + os.system( + "cp " + RICHMIRRORALIGNMENTGANGAROOT + "/files/MagCoeffs/* " + workDir + ) # Requires RICHMIRRORALIGNMENTGANGAROOT to be defined # 0: Minuit solutionMethod = 1 # 1: algebraic diff --git a/Rich/RichMirrorAlignmentGanga/job/settings/RichMirrorAlignmentGanga_Collision12_settings_R2MD.py b/Rich/RichMirrorAlignmentGanga/job/settings/RichMirrorAlignmentGanga_Collision12_settings_R2MD.py index 2ced67fb8e2411537e109f76b6a44825cac409fc..a4c1ddd4487200e325cb8286166dbac0f0d1081f 100644 --- a/Rich/RichMirrorAlignmentGanga/job/settings/RichMirrorAlignmentGanga_Collision12_settings_R2MD.py +++ b/Rich/RichMirrorAlignmentGanga/job/settings/RichMirrorAlignmentGanga_Collision12_settings_R2MD.py @@ -12,21 +12,21 @@ import os from subprocess import * -#=============================================================================== +# =============================================================================== # defs -#=============================================================================== +# =============================================================================== # stdReporter returns stdout and stderr from Popen.communicate() def stdReporter(stdout, stderr): - print "The shell script gave some STANDARD OUTPUT:" - print stdout + print("The shell script gave some STANDARD OUTPUT:") + print(stdout) if stderr: - print "The shell script also gave some STANDARD ERROR:" - print stderr + print("The shell script also gave some STANDARD ERROR:") + print(stderr) else: - print "The shell script ran fine." + print("The shell script ran fine.") -#=============================================================================== +# =============================================================================== ######################################################## # Search "Important" to find things you had better check @@ -37,34 +37,36 @@ def stdReporter(stdout, stderr): ### Important: What is the backend backEnd = "dirac" -#backEnd = "online" +# backEnd = "online" ### Important: Set your home directory home = "/afs/cern.ch/user/p/pnaik" # point this to your home directory -if (backEnd.lower() == 'online'): +if backEnd.lower() == "online": home = "/home/pnaik" # point this to the online home ### Important: Choose Panoptes Version (HEAD is usually fine, for Offline Alignment) setupProjectPanoptesVersion = "HEAD" -if (backEnd.lower() == 'online'): +if backEnd.lower() == "online": setupProjectPanoptesVersion = "v5r2" # you want a fixed version online ### Important: Choose Panoptes Options -setupProjectPanoptesOptions = "--nightly lhcb-head Thu" # Safest to specify a day that you know is working -#setupProjectPanoptesOptions = "--nightly lhcb-head" # will fail if running the script overnight -#setupProjectPanoptesOptions = "--nightly lhcb-prerelease Sun" -#setupProjectPanoptesOptions = "--nightly lhcb-prerelease" -#setupProjectPanoptesOptions = "--dev-dir=/afs/cern.ch/user/p/pnaik/PANOPTES" -if (backEnd.lower() == 'online'): +setupProjectPanoptesOptions = ( + "--nightly lhcb-head Thu" # Safest to specify a day that you know is working +) +# setupProjectPanoptesOptions = "--nightly lhcb-head" # will fail if running the script overnight +# setupProjectPanoptesOptions = "--nightly lhcb-prerelease Sun" +# setupProjectPanoptesOptions = "--nightly lhcb-prerelease" +# setupProjectPanoptesOptions = "--dev-dir=/afs/cern.ch/user/p/pnaik/PANOPTES" +if backEnd.lower() == "online": setupProjectPanoptesOptions = "" ### Important: Define a working directory. If it does not exist, make it. workDir = "/afs/cern.ch/user/p/pnaik/RichAlignment/2012/ParasR2MD" # Point this to your working directory -if (backEnd.lower() == 'online'): +if backEnd.lower() == "online": workDir = "/home/pnaik/rich/2012/R2MD" if not os.path.isdir(workDir): - print "*** DOES NOT EXIST: workDir = " + workDir - print "*** Making " + workDir + print("*** DOES NOT EXIST: workDir = " + workDir) + print("*** Making " + workDir) os.makedirs(workDir) ### Important: Get the database tags right @@ -72,20 +74,20 @@ dDDB_tag = "dddb-20120831" condDB_tag = "cond-20120917" ### Important: Set the LHCb and Brunel version and Brunel extra options -LHCbVersion = '' -if (backEnd.lower() == 'online'): - LHCbVersion = 'v36r2' -brunelVersion = 'v47r5' +LHCbVersion = "" +if backEnd.lower() == "online": + LHCbVersion = "v36r2" +brunelVersion = "v47r5" setupProjectBrunelOpts = "" ### Important: Where is the data eventSelectorInputFile = "/afs/cern.ch/user/p/pnaik/RichAlignment/2012/data/RICH2-selectionMagDown.py" # make sure this exists -if (backEnd.lower() == 'online'): +if backEnd.lower() == "online": eventSelectorInputFile = "/home/pnaik/rich/2012/R2MD/RICH2-selectionMagDown.py" # we will be using the data from the HLT ### Important: What is the input type of your data brunelInitialInputType = "RAW" -if (backEnd.lower() == 'online'): +if backEnd.lower() == "online": brunelInitialInputType = "RAW" ### Important: Which RICH? @@ -115,39 +117,45 @@ specificAlignment = "/afs/cern.ch/user/c/clinn/cmtuser/Panoptes_HEAD/RichAlignme ### This is standard, do not change userReleaseArea = os.getenv("User_release_area") pathToScripts = "/afs/cern.ch/lhcb/software/releases/LBSCRIPTS/prod/InstallArea/scripts" -if (backEnd.lower() == 'online'): +if backEnd.lower() == "online": pathToScripts = "/cvmfs/lhcb.cern.ch/lib/lhcb/LBSCRIPTS/prod/InstallArea/scripts" ### This gets the environment variables we will need automatically, based on the above p = Popen( - "export HOME=" + home + ";" + "source " + pathToScripts + "/LbLogin.sh;" + - "export User_release_area=" + userReleaseArea + ";" + "export HOME=" + + home + + ";" + + "source " + + pathToScripts + + "/LbLogin.sh;" + + "export User_release_area=" + + userReleaseArea + + ";" # +"export CMTPROJECTPATH=/afs/cern.ch/sw/lcg/external/xqilla/2.2.4/x86_64-slc5-gcc43-opt/lib:$CMTPROJECTPATH;" # probably obsolete - + "source `which SetupProject.sh` Panoptes " + setupProjectPanoptesVersion - + " " + setupProjectPanoptesOptions + ";" + - "rm -f env_var_settings_mirroralign.txt;" - + - "echo $RICHMIRRALIGNROOT > env_var_settings_mirroralign.txt; " # Line 1 - + - "echo $RICHMIRRCOMBINFITROOT >> env_var_settings_mirroralign.txt; " # Line 2 - + - "echo $RICHMIRRORALIGNMENTGANGAROOT >> env_var_settings_mirroralign.txt; " # Line 3 - + - "echo $SQLITEDBPATH >> env_var_settings_mirroralign.txt; " # Line 4 + + "source `which SetupProject.sh` Panoptes " + + setupProjectPanoptesVersion + + " " + + setupProjectPanoptesOptions + + ";" + + "rm -f env_var_settings_mirroralign.txt;" + + "echo $RICHMIRRALIGNROOT > env_var_settings_mirroralign.txt; " # Line 1 + + "echo $RICHMIRRCOMBINFITROOT >> env_var_settings_mirroralign.txt; " # Line 2 + + "echo $RICHMIRRORALIGNMENTGANGAROOT >> env_var_settings_mirroralign.txt; " # Line 3 + + "echo $SQLITEDBPATH >> env_var_settings_mirroralign.txt; " # Line 4 + "echo $SHELL", shell=True, executable="/bin/bash", stdout=PIPE, - stderr=PIPE) + stderr=PIPE, +) (stdout, stderr) = p.communicate() stdReporter(stdout, stderr) env_var_settings_mirroralign_txt = open("env_var_settings_mirroralign.txt") -RICHMIRRALIGNROOT = env_var_settings_mirroralign_txt.readline().strip( -) # Line 1 -RICHMIRRCOMBINFITROOT = env_var_settings_mirroralign_txt.readline().strip( -) # Line 2 -RICHMIRRORALIGNMENTGANGAROOT = env_var_settings_mirroralign_txt.readline( -).strip() # Line 3 +RICHMIRRALIGNROOT = env_var_settings_mirroralign_txt.readline().strip() # Line 1 +RICHMIRRCOMBINFITROOT = env_var_settings_mirroralign_txt.readline().strip() # Line 2 +RICHMIRRORALIGNMENTGANGAROOT = ( + env_var_settings_mirroralign_txt.readline().strip() +) # Line 3 SQLITEDBPATH = env_var_settings_mirroralign_txt.readline().strip() # Line 4 env_var_settings_mirroralign_txt.close() os.system("rm -f env_var_settings_mirroralign.txt") @@ -186,27 +194,35 @@ messageSvcOutputLevel = "3" ### Automatic choice of mirrCombinSubset file mirrCombinSubset = "" -if (richDetector == 2): +if richDetector == 2: mirrCombinSubset = "Rich2CombAndMirrSubsets_96m94c_p12p43fix.txt" # not yet available in PANOPTES HEAD, so I don't try to read it using os.system on the next line - #os.system("cp "+RICHMIRRORALIGNMENTGANGAROOT+"files/Rich2CombAndMirrSubsets_96m94c_p12p43fix.txt .") - os.system("cp " + RICHMIRRALIGNROOT + - "Test/Rich2CombAndMirrSubsets_96m94c_p12p43fix.txt " + - workDir) # Requires RICHMIRRALIGNROOT to be defined -if (richDetector == 1): + # os.system("cp "+RICHMIRRORALIGNMENTGANGAROOT+"files/Rich2CombAndMirrSubsets_96m94c_p12p43fix.txt .") + os.system( + "cp " + + RICHMIRRALIGNROOT + + "Test/Rich2CombAndMirrSubsets_96m94c_p12p43fix.txt " + + workDir + ) # Requires RICHMIRRALIGNROOT to be defined +if richDetector == 1: mirrCombinSubset = "Rich1CombAndMirrSubsets_20m16c_p0p1p2p3fix.txt" - #os.system("cp "+RICHMIRRORALIGNMENTGANGAROOT+"files/Rich1CombAndMirrSubsets_20m16c_p0p1p2p3fix.txt .") - os.system("cp " + RICHMIRRALIGNROOT + - "Test/Rich1CombAndMirrSubsets_20m16c_p0p1p2p3fix.txt " + - workDir) # Requires RICHMIRRALIGNROOT to be defined + # os.system("cp "+RICHMIRRORALIGNMENTGANGAROOT+"files/Rich1CombAndMirrSubsets_20m16c_p0p1p2p3fix.txt .") + os.system( + "cp " + + RICHMIRRALIGNROOT + + "Test/Rich1CombAndMirrSubsets_20m16c_p0p1p2p3fix.txt " + + workDir + ) # Requires RICHMIRRALIGNROOT to be defined ### Standard RICH mirror Alignment parameters, do not touch unless you are an expert groupSlices = 1 groupBins = 1 -minAverageBinPop = 6 # 6 * 50 deltaTheta bins in one phi bin slice = 300 photons minimum per phi bin +minAverageBinPop = ( + 6 # 6 * 50 deltaTheta bins in one phi bin slice = 300 photons minimum per phi bin +) -deltaThetaWindow = 4.0 #4 -if (richDetector == 2): - deltaThetaWindow = 3.0 #2 +deltaThetaWindow = 4.0 # 4 +if richDetector == 2: + deltaThetaWindow = 3.0 # 2 coeffCalibrTilt = 0.3 @@ -217,24 +233,30 @@ verOffsetsFromMC = "" usePremisaligned = "false" -combinFitVariant = 1 #"slices" -if (richDetector == 2): - combinFitVariant = 3 #"surfaceB" RICH2 +combinFitVariant = 1 # "slices" +if richDetector == 2: + combinFitVariant = 3 # "surfaceB" RICH2 maximumNumberOfIterations = 10 ### Change these if something bad happens in an iteration, but it is recoverable (i.e. Ganga jobs failed) startFromIteration = 0 # which iteration do you want to start from? NEED TO CHECK/CONFIRM THIS WORKS FOR ANYTHING OTHER THAN 0 -skipFirstRecoJob = 0 # currently only for iteration 0, skip submitting Brunel jobs to grid -skipFirstMergeJob = 0 # currently only for iteration 0, skip the merging Brunel histograms +skipFirstRecoJob = ( + 0 # currently only for iteration 0, skip submitting Brunel jobs to grid +) +skipFirstMergeJob = ( + 0 # currently only for iteration 0, skip the merging Brunel histograms +) if skipFirstRecoJob == 0: if skipFirstMergeJob == 1: skipFirstMergeJob == 0 -#if you are not skipping brunel jobs, you do not want to skip the merging of the brunel jobs! -#if you want to merge the jobs from a previous run of the script you must provide the job numbers -previousJobNumbers = range(984, 993) +# if you are not skipping brunel jobs, you do not want to skip the merging of the brunel jobs! +# if you want to merge the jobs from a previous run of the script you must provide the job numbers +previousJobNumbers = list(range(984, 993)) -skipFirstCombinFit = 0 # currently only for iteration 0, skip the combinFit before mirrAlign +skipFirstCombinFit = ( + 0 # currently only for iteration 0, skip the combinFit before mirrAlign +) ### Standard RICH mirror Alignment parameters, do not touch unless you are an expert @@ -247,9 +269,10 @@ skipFirstCombinFit = 0 # currently only for iteration 0, skip the combinFit bef magnifCoeffMode = 2 # 2: individual for each pair # evaluated on-fly for each iteration # depedent on sign of rotation -if (magnifCoeffMode == 0): - os.system("cp " + RICHMIRRORALIGNMENTGANGAROOT + "/files/MagCoeffs/* " + - workDir) # Requires RICHMIRRORALIGNMENTGANGAROOT to be defined +if magnifCoeffMode == 0: + os.system( + "cp " + RICHMIRRORALIGNMENTGANGAROOT + "/files/MagCoeffs/* " + workDir + ) # Requires RICHMIRRORALIGNMENTGANGAROOT to be defined # 0: Minuit solutionMethod = 1 # 1: algebraic diff --git a/Rich/RichMirrorAlignmentGanga/job/settings/RichMirrorAlignmentGanga_Collision15_settings_R2MD.py b/Rich/RichMirrorAlignmentGanga/job/settings/RichMirrorAlignmentGanga_Collision15_settings_R2MD.py index c4639b716291097db62c29107e8562d488ec3be5..8cd209bb91426f076e376d4e7aaaced570eb97e0 100644 --- a/Rich/RichMirrorAlignmentGanga/job/settings/RichMirrorAlignmentGanga_Collision15_settings_R2MD.py +++ b/Rich/RichMirrorAlignmentGanga/job/settings/RichMirrorAlignmentGanga_Collision15_settings_R2MD.py @@ -12,21 +12,21 @@ import os from subprocess import * -#=============================================================================== +# =============================================================================== # defs -#=============================================================================== +# =============================================================================== # stdReporter returns stdout and stderr from Popen.communicate() def stdReporter(stdout, stderr): - print "The shell script gave some STANDARD OUTPUT:" - print stdout + print("The shell script gave some STANDARD OUTPUT:") + print(stdout) if stderr: - print "The shell script also gave some STANDARD ERROR:" - print stderr + print("The shell script also gave some STANDARD ERROR:") + print(stderr) else: - print "The shell script ran fine." + print("The shell script ran fine.") -#=============================================================================== +# =============================================================================== ######################################################## # Search "Important" to find things you had better check @@ -37,33 +37,33 @@ def stdReporter(stdout, stderr): ### Important: What is the backend backEnd = "dirac" -#backEnd = "online" +# backEnd = "online" ### Important: Set your home directory home = "/usera/naik/claire" # point this to your home directory -if (backEnd.lower() == 'online'): +if backEnd.lower() == "online": home = "" # point this to the online home ### Important: Choose Panoptes Version (HEAD is usually fine, for Offline Alignment, given that you run from one of the nightly builds) setupProjectPanoptesVersion = "HEAD" -#setupProjectPanoptesVersion = "v5r4" -if (backEnd.lower() == 'online'): +# setupProjectPanoptesVersion = "v5r4" +if backEnd.lower() == "online": setupProjectPanoptesVersion = "v5r5" # you want a fixed version online ### Important: Choose Panoptes Options setupProjectPanoptesOptions = "--nightly lhcb-head Sat" # Safest to specify a day that you know is working; try the previous day in general -#setupProjectPanoptesOptions = "" -if (backEnd.lower() == 'online'): +# setupProjectPanoptesOptions = "" +if backEnd.lower() == "online": setupProjectPanoptesOptions = "" ### Important: Define a working directory. If it does not exist, make it. workDir = "/usera/naik/claire/RichAlignment/2015/output/2015Down_R2" # Point this to your working directory -if (backEnd.lower() == 'online'): +if backEnd.lower() == "online": workDir = "" if not os.path.isdir(workDir): - print "*** DOES NOT EXIST: workDir = " + workDir - print "*** Making " + workDir + print("*** DOES NOT EXIST: workDir = " + workDir) + print("*** Making " + workDir) os.makedirs(workDir) ### Important: Get the database tags right @@ -71,21 +71,21 @@ dDDB_tag = "dddb-20150526" condDB_tag = "cond-20150601" ### Important: Set the LHCb and Brunel version and Brunel extra options -LHCbVersion = '' -if (backEnd.lower() == 'online'): +LHCbVersion = "" +if backEnd.lower() == "online": # LHCbVersion = 'v36r2' - LHCbVersion = '' -brunelVersion = 'v47r5' + LHCbVersion = "" +brunelVersion = "v47r5" setupProjectBrunelOpts = "" ### Important: Where is the data ioHelperInputFile = "/afs/cern.ch/user/p/pnaik/ReduceRawFiles/2015CalibrationMagDown.py" # make sure this exists -if (backEnd.lower() == 'online'): +if backEnd.lower() == "online": ioHelperInputFile = "" # we will be using the data from the HLT ### Important: What is the input type of your data brunelInitialInputType = "RAW" -if (backEnd.lower() == 'online'): +if backEnd.lower() == "online": brunelInitialInputType = "RAW" ### Important: Which RICH? @@ -105,7 +105,9 @@ AddedDB = [""] ### Important: Do you want to start from an existing alignment? useSpecificAlignment = "false" -specificAlignment = "/var/nwork/pckw/naik/claire/RichAlignment/2012/jobs/CondDB_IOV4_R2.xml" +specificAlignment = ( + "/var/nwork/pckw/naik/claire/RichAlignment/2012/jobs/CondDB_IOV4_R2.xml" +) ######################################################## # Standard items that could be changed, if need be @@ -115,39 +117,45 @@ specificAlignment = "/var/nwork/pckw/naik/claire/RichAlignment/2012/jobs/CondDB_ ### This is standard, do not change userReleaseArea = os.getenv("User_release_area") pathToScripts = "/afs/cern.ch/lhcb/software/releases/LBSCRIPTS/prod/InstallArea/scripts" -if (backEnd.lower() == 'online'): +if backEnd.lower() == "online": pathToScripts = "" ### This gets the environment variables we will need automatically, based on the above p = Popen( - "export HOME=" + home + ";" + "source " + pathToScripts + "/LbLogin.sh;" + - "export User_release_area=" + userReleaseArea + ";" + "export HOME=" + + home + + ";" + + "source " + + pathToScripts + + "/LbLogin.sh;" + + "export User_release_area=" + + userReleaseArea + + ";" # +"export CMTPROJECTPATH=/afs/cern.ch/sw/lcg/external/xqilla/2.2.4/x86_64-slc5-gcc43-opt/lib:$CMTPROJECTPATH;" # probably obsolete - + "source `which SetupProject.sh` Panoptes " + setupProjectPanoptesVersion - + " " + setupProjectPanoptesOptions + ";" + - "rm -f env_var_settings_mirroralign.txt;" - + - "echo $RICHMIRRALIGNROOT > env_var_settings_mirroralign.txt; " # Line 1 - + - "echo $RICHMIRRCOMBINFITROOT >> env_var_settings_mirroralign.txt; " # Line 2 - + - "echo $RICHMIRRORALIGNMENTGANGAROOT >> env_var_settings_mirroralign.txt; " # Line 3 - + - "echo $SQLITEDBPATH >> env_var_settings_mirroralign.txt; " # Line 4 + + "source `which SetupProject.sh` Panoptes " + + setupProjectPanoptesVersion + + " " + + setupProjectPanoptesOptions + + ";" + + "rm -f env_var_settings_mirroralign.txt;" + + "echo $RICHMIRRALIGNROOT > env_var_settings_mirroralign.txt; " # Line 1 + + "echo $RICHMIRRCOMBINFITROOT >> env_var_settings_mirroralign.txt; " # Line 2 + + "echo $RICHMIRRORALIGNMENTGANGAROOT >> env_var_settings_mirroralign.txt; " # Line 3 + + "echo $SQLITEDBPATH >> env_var_settings_mirroralign.txt; " # Line 4 + "echo $SHELL", shell=True, executable="/bin/bash", stdout=PIPE, - stderr=PIPE) + stderr=PIPE, +) (stdout, stderr) = p.communicate() stdReporter(stdout, stderr) env_var_settings_mirroralign_txt = open("env_var_settings_mirroralign.txt") -RICHMIRRALIGNROOT = env_var_settings_mirroralign_txt.readline().strip( -) # Line 1 -RICHMIRRCOMBINFITROOT = env_var_settings_mirroralign_txt.readline().strip( -) # Line 2 -RICHMIRRORALIGNMENTGANGAROOT = env_var_settings_mirroralign_txt.readline( -).strip() # Line 3 +RICHMIRRALIGNROOT = env_var_settings_mirroralign_txt.readline().strip() # Line 1 +RICHMIRRCOMBINFITROOT = env_var_settings_mirroralign_txt.readline().strip() # Line 2 +RICHMIRRORALIGNMENTGANGAROOT = ( + env_var_settings_mirroralign_txt.readline().strip() +) # Line 3 SQLITEDBPATH = env_var_settings_mirroralign_txt.readline().strip() # Line 4 env_var_settings_mirroralign_txt.close() os.system("rm -f env_var_settings_mirroralign.txt") @@ -186,31 +194,39 @@ messageSvcOutputLevel = "3" ### Automatic choice of mirrCombinSubset file mirrCombinSubset = "" -if (richDetector == 2): +if richDetector == 2: mirrCombinSubset = "Rich2CombAndMirrSubsets_96m94c_p12p43fix.txt" # not yet available in PANOPTES HEAD, so I don't try to read it using os.system on the next line - #os.system("cp "+RICHMIRRORALIGNMENTGANGAROOT+"files/Rich2CombAndMirrSubsets_96m94c_p12p43fix.txt .") - os.system("cp " + RICHMIRRALIGNROOT + - "Test/Rich2CombAndMirrSubsets_96m94c_p12p43fix.txt " + - workDir) # Requires RICHMIRRALIGNROOT to be defined -if (richDetector == 1): + # os.system("cp "+RICHMIRRORALIGNMENTGANGAROOT+"files/Rich2CombAndMirrSubsets_96m94c_p12p43fix.txt .") + os.system( + "cp " + + RICHMIRRALIGNROOT + + "Test/Rich2CombAndMirrSubsets_96m94c_p12p43fix.txt " + + workDir + ) # Requires RICHMIRRALIGNROOT to be defined +if richDetector == 1: mirrCombinSubset = "Rich1CombAndMirrSubsets_20m16c_p0p1p2p3fix.txt" - #os.system("cp "+RICHMIRRORALIGNMENTGANGAROOT+"files/Rich1CombAndMirrSubsets_20m16c_p0p1p2p3fix.txt .") - os.system("cp " + RICHMIRRALIGNROOT + - "Test/Rich1CombAndMirrSubsets_20m16c_p0p1p2p3fix.txt " + - workDir) # Requires RICHMIRRALIGNROOT to be defined + # os.system("cp "+RICHMIRRORALIGNMENTGANGAROOT+"files/Rich1CombAndMirrSubsets_20m16c_p0p1p2p3fix.txt .") + os.system( + "cp " + + RICHMIRRALIGNROOT + + "Test/Rich1CombAndMirrSubsets_20m16c_p0p1p2p3fix.txt " + + workDir + ) # Requires RICHMIRRALIGNROOT to be defined ### Standard RICH mirror Alignment parameters, do not touch unless you are an expert groupSlices = 1 groupBins = 1 -#minAverageBinPop = 6 # 6 * 50 deltaTheta bins in one phi bin slice = 300 photons minimum per phi bin -minAverageBinPop = 2.0 # 2 * 50 deltaTheta bins in one phi bin slice = 100 photons minimum per phi bin +# minAverageBinPop = 6 # 6 * 50 deltaTheta bins in one phi bin slice = 300 photons minimum per phi bin +minAverageBinPop = ( + 2.0 # 2 * 50 deltaTheta bins in one phi bin slice = 100 photons minimum per phi bin +) -deltaThetaWindow = 4.0 #4 -if (richDetector == 2): - deltaThetaWindow = 3.0 #2 +deltaThetaWindow = 4.0 # 4 +if richDetector == 2: + deltaThetaWindow = 3.0 # 2 coeffCalibrTilt = 0.3 -#if (richDetector == 1): +# if (richDetector == 1): # coeffCalibrTilt = 0.7 useTruth = "" @@ -220,25 +236,31 @@ verOffsetsFromMC = "" usePremisaligned = "false" -#combinFitVariant = 1#"slices" -combinFitVariant = 3 #"slices" -if (richDetector == 2): - combinFitVariant = 3 #"surfaceB" RICH2 +# combinFitVariant = 1#"slices" +combinFitVariant = 3 # "slices" +if richDetector == 2: + combinFitVariant = 3 # "surfaceB" RICH2 maximumNumberOfIterations = 10 ### Change these if something bad happens in an iteration, but it is recoverable (i.e. Ganga jobs failed) startFromIteration = 0 # which iteration do you want to start from? NEED TO CHECK/CONFIRM THIS WORKS FOR ANYTHING OTHER THAN 0 -skipFirstRecoJob = 0 # currently only for iteration 0, skip submitting Brunel jobs to grid -skipFirstMergeJob = 0 # currently only for iteration 0, skip the merging Brunel histograms +skipFirstRecoJob = ( + 0 # currently only for iteration 0, skip submitting Brunel jobs to grid +) +skipFirstMergeJob = ( + 0 # currently only for iteration 0, skip the merging Brunel histograms +) if skipFirstRecoJob == 0: if skipFirstMergeJob == 1: skipFirstMergeJob == 0 -#if you are not skipping brunel jobs, you do not want to skip the merging of the brunel jobs! -#if you want to merge the jobs from a previous run of the script you must provide the job numbers -previousJobNumbers = range(57, 66) +# if you are not skipping brunel jobs, you do not want to skip the merging of the brunel jobs! +# if you want to merge the jobs from a previous run of the script you must provide the job numbers +previousJobNumbers = list(range(57, 66)) -skipFirstCombinFit = 0 # currently only for iteration 0, skip the combinFit before mirrAlign +skipFirstCombinFit = ( + 0 # currently only for iteration 0, skip the combinFit before mirrAlign +) ### Standard RICH mirror Alignment parameters, do not touch unless you are an expert @@ -251,9 +273,10 @@ skipFirstCombinFit = 0 # currently only for iteration 0, skip the combinFit bef magnifCoeffMode = 2 # 2: individual for each pair # evaluated on-fly for each iteration # depedent on sign of rotation -if (magnifCoeffMode == 0): - os.system("cp " + RICHMIRRORALIGNMENTGANGAROOT + "/files/MagCoeffs/* " + - workDir) # Requires RICHMIRRORALIGNMENTGANGAROOT to be defined +if magnifCoeffMode == 0: + os.system( + "cp " + RICHMIRRORALIGNMENTGANGAROOT + "/files/MagCoeffs/* " + workDir + ) # Requires RICHMIRRORALIGNMENTGANGAROOT to be defined # 0: Minuit solutionMethod = 1 # 1: algebraic diff --git a/Rich/RichMirrorAlignmentGanga/job/settings/prior/RichMirrorAlignmentGanga_Collision11_settings.py b/Rich/RichMirrorAlignmentGanga/job/settings/prior/RichMirrorAlignmentGanga_Collision11_settings.py index 79df6be86f27a8a2b112259889fcdf25c0397f2a..8f67b4fcda15f6593a67812b3cec9d0bfc6e44c4 100644 --- a/Rich/RichMirrorAlignmentGanga/job/settings/prior/RichMirrorAlignmentGanga_Collision11_settings.py +++ b/Rich/RichMirrorAlignmentGanga/job/settings/prior/RichMirrorAlignmentGanga_Collision11_settings.py @@ -21,27 +21,38 @@ SQLITEDBPATH = os.getenv("SQLITEDBPATH") home = "/afs/cern.ch/user/a/auser" setupProjectPanoptesVersion = "v4r1" -#setupProjectPanoptesOptions = "--nightly lhcb-prerelease" -#setupProjectPanoptesOptions = "--nightly lhcb-prerelease Sun" +# setupProjectPanoptesOptions = "--nightly lhcb-prerelease" +# setupProjectPanoptesOptions = "--nightly lhcb-prerelease Sun" setupProjectPanoptesOptions = "" pathToScripts = "/afs/cern.ch/lhcb/software/releases/LBSCRIPTS/prod/InstallArea/scripts" -#os.system("rm -f env_var_settings.txt") -#os.system("echo $RICHMIRRORALIGNMENTGANGAROOT > env_var_settings.txt") +# os.system("rm -f env_var_settings.txt") +# os.system("echo $RICHMIRRORALIGNMENTGANGAROOT > env_var_settings.txt") p = Popen( - "export HOME=" + home + ";" + "export HOME=" + + home + + ";" # +"export CMTPROJECTPATH=/afs/cern.ch/sw/lcg/external/xqilla/2.2.4/x86_64-slc5-gcc43-opt/lib:$CMTPROJECTPATH;" - + "source " + pathToScripts + "/LbLogin.sh;" + "export User_release_area=" - + userReleaseArea + ";" + - "source `which SetupProject.sh` Panoptes " + - setupProjectPanoptesVersion + " " + setupProjectPanoptesOptions + ";" + - "source $User_release_area/Panoptes_" + setupProjectPanoptesVersion + - "/Rich/RichMirrAlign/cmt/setup.sh;" + - "rm -f env_var_settings.txt;" + - "echo $RICHMIRRORALIGNMENTGANGAROOT > env_var_settings.txt ", + + "source " + + pathToScripts + + "/LbLogin.sh;" + + "export User_release_area=" + + userReleaseArea + + ";" + + "source `which SetupProject.sh` Panoptes " + + setupProjectPanoptesVersion + + " " + + setupProjectPanoptesOptions + + ";" + + "source $User_release_area/Panoptes_" + + setupProjectPanoptesVersion + + "/Rich/RichMirrAlign/cmt/setup.sh;" + + "rm -f env_var_settings.txt;" + + "echo $RICHMIRRORALIGNMENTGANGAROOT > env_var_settings.txt ", shell=True, - executable="/bin/bash") + executable="/bin/bash", +) sts = os.waitpid(p.pid, 0) env_var_settings_txt = open("env_var_settings.txt") @@ -53,49 +64,49 @@ scriptOfEverything = RICHMIRRORALIGNMENTGANGAROOT + "/job/RichMirrorAlignmentGan workDir = "/afs/cern.ch/user/a/auser/scratch0/workdir_R1" dDDB_tag = "head-20111102" -#dDDB_tag = "head-20100119" -#dDDB_tag = "head-20100624" # EventSelectorInput_R2SelEnh_Collision10.py -#dDDB_tag = "head-20101026" # EventSelectorInput_R2md198f_Collision10.py -#dDDB_tag = "head-20101026" # EventSelectorInput_R2Sel199f_Collision10.py +# dDDB_tag = "head-20100119" +# dDDB_tag = "head-20100624" # EventSelectorInput_R2SelEnh_Collision10.py +# dDDB_tag = "head-20101026" # EventSelectorInput_R2md198f_Collision10.py +# dDDB_tag = "head-20101026" # EventSelectorInput_R2Sel199f_Collision10.py condDB_tag = "head-20111111" -#condDB_tag = "head-20100325" -#condDB_tag = "head-20100303" -#condDB_tag = "head-20100715" # EventSelectorInput_R2SelEnh_Collision10.py -#condDB_tag = "head-20101106" # EventSelectorInput_R2md198f_Collision10.py -#condDB_tag = "head-20101106" # EventSelectorInput_R2Sel199f_Collision10.py +# condDB_tag = "head-20100325" +# condDB_tag = "head-20100303" +# condDB_tag = "head-20100715" # EventSelectorInput_R2SelEnh_Collision10.py +# condDB_tag = "head-20101106" # EventSelectorInput_R2md198f_Collision10.py +# condDB_tag = "head-20101106" # EventSelectorInput_R2Sel199f_Collision10.py -#setupProjectBrunelOpts = "--use-grid" +# setupProjectBrunelOpts = "--use-grid" setupProjectBrunelOpts = "" -#eventSelectorInputFile = RICHMIRRORALIGNMENTGANGAROOT+"/options/EventSelectorInput_R2SelEnh_Collision10.py" -#eventSelectorInputFile = "EventSelectorInput_R2SelEnh_Collision10.py" -#eventSelectorInputFile = "EventSelectorInput_R2md198f_Collision10.py" +# eventSelectorInputFile = RICHMIRRORALIGNMENTGANGAROOT+"/options/EventSelectorInput_R2SelEnh_Collision10.py" +# eventSelectorInputFile = "EventSelectorInput_R2SelEnh_Collision10.py" +# eventSelectorInputFile = "EventSelectorInput_R2md198f_Collision10.py" eventSelectorInputFile = "LFN-MagUpMagDown_2011.py" -#brunelEvtMax = 10 -#brunelPrintFreq = 1 -#splitMaxFiles = 1 -#brunelEvtMax = 100 -#brunelPrintFreq = 10 -#splitMaxFiles = 6 +# brunelEvtMax = 10 +# brunelPrintFreq = 1 +# splitMaxFiles = 1 +# brunelEvtMax = 100 +# brunelPrintFreq = 10 +# splitMaxFiles = 6 brunelEvtMax = 1500 brunelPrintFreq = 500 splitMaxFiles = 200 -#splitFilesPerJob = 1 +# splitFilesPerJob = 1 splitFilesPerJob = 2 -#splitFilesPerJob = 4 +# splitFilesPerJob = 4 -#backEnd = "LSF_8nm" -#backEnd = "LSF_8nh" -#backEnd = "local" +# backEnd = "LSF_8nm" +# backEnd = "LSF_8nh" +# backEnd = "local" backEnd = "dirac" -#backEnd = "interactive" +# backEnd = "interactive" -#diracCPUTime = 1200 -#diracCPUTime = 2400 -#diracCPUTime = 9600 +# diracCPUTime = 1200 +# diracCPUTime = 2400 +# diracCPUTime = 9600 diracCPUTime = 19200 brunelInitialInputType = "RAW" @@ -104,54 +115,54 @@ messageSvcOutputLevel = "3" richDetector = 1 # 1: RICH1, 2: RICH2 mirrCombinSubset = "" -if (richDetector == 2): +if richDetector == 2: mirrCombinSubset = "48m48c_p12p43s09s30fix" os.system( - 'cp $RICHMIRRORALIGNMENTGANGAROOT/files/Rich2MirrCombinList_48m48c_p12p43s09s30fix.txt .' + "cp $RICHMIRRORALIGNMENTGANGAROOT/files/Rich2MirrCombinList_48m48c_p12p43s09s30fix.txt ." ) -if (richDetector == 1): +if richDetector == 1: mirrCombinSubset = "Rich1MirrCombinList_10m12c_p0p2fix.txt" os.system( - 'cp $RICHMIRRORALIGNMENTGANGAROOT/files/Rich1MirrCombinList_10m12c_p0p2fix.txt .' + "cp $RICHMIRRORALIGNMENTGANGAROOT/files/Rich1MirrCombinList_10m12c_p0p2fix.txt ." ) -#mirrCombinSubset = "10m12c_p0p2fix" # required for RICH1 -#mirrCombinSubset = "48m85c_p12p43fix" -#mirrCombinSubset = "48m85c_p12p43s08s31fix" -#mirrCombinSubset = "48m48c_p12p43s09s30fix" +# mirrCombinSubset = "10m12c_p0p2fix" # required for RICH1 +# mirrCombinSubset = "48m85c_p12p43fix" +# mirrCombinSubset = "48m85c_p12p43s08s31fix" +# mirrCombinSubset = "48m48c_p12p43s09s30fix" -#thisCase = "R1SelMd" # Rich1 -#thisCase = "R2SelEnhSurB" # Rich2 -#thisCase = "198fSurB" # Rich2 +# thisCase = "R1SelMd" # Rich1 +# thisCase = "R2SelEnhSurB" # Rich2 +# thisCase = "198fSurB" # Rich2 thisCase = "R1MU" # Rich1 dataVariant = "Collision11" groupSlices = 1 groupBins = 1 -#minAverageBinPop = 25 +# minAverageBinPop = 25 minAverageBinPop = 9 -deltaThetaWindow = 4.0 #4 -if (richDetector == 2): - deltaThetaWindow = 3.0 #2 +deltaThetaWindow = 4.0 # 4 +if richDetector == 2: + deltaThetaWindow = 3.0 # 2 coeffCalibrTilt = 0.3 useTruth = "" useOffsetsFromMC = "false" -#useOffsetsFromMC = "true" +# useOffsetsFromMC = "true" verOffsetsFromMC = "" -#verOffsetsFromMC = "100fSurBMC10" +# verOffsetsFromMC = "100fSurBMC10" usePremisaligned = "false" -combinFitVariant = 1 #"slices" -if (richDetector == 2): - combinFitVariant = 3 #"surfaceB" RICH2 +combinFitVariant = 1 # "slices" +if richDetector == 2: + combinFitVariant = 3 # "surfaceB" RICH2 startFromIteration = 0 @@ -167,8 +178,8 @@ magnifCoeffMode = 0 # 2: individual for each pair # evaluated on-fly for each iteration # depedent on sign of rotation -if (magnifCoeffMode == 0): - os.system('cp $RICHMIRRORALIGNMENTGANGAROOT/files/MagCoeffs/* .') +if magnifCoeffMode == 0: + os.system("cp $RICHMIRRORALIGNMENTGANGAROOT/files/MagCoeffs/* .") # 0: Minuit solutionMethod = 1 # 1: algebraic diff --git a/Rich/RichMirrorAlignmentGanga/job/settings/prior/RichMirrorAlignmentGanga_MC10_settings.py b/Rich/RichMirrorAlignmentGanga/job/settings/prior/RichMirrorAlignmentGanga_MC10_settings.py index 5ebc815d50faa9f8c3e8cc4db1e2ded2c3b58ef8..ebb6bc62d2c85f739e1b866332975caeba6b544c 100644 --- a/Rich/RichMirrorAlignmentGanga/job/settings/prior/RichMirrorAlignmentGanga_MC10_settings.py +++ b/Rich/RichMirrorAlignmentGanga/job/settings/prior/RichMirrorAlignmentGanga_MC10_settings.py @@ -17,20 +17,30 @@ userReleaseArea = os.getenv("User_release_area") home = "/afs/cern.ch/user/a/asolomin" setupProjectPanoptesVersion = "HEAD" setupProjectPanoptesOptions = "--nightly lhcb-prerelease" -#setupProjectPanoptesOptions = "--nightly lhcb-prerelease Wed" +# setupProjectPanoptesOptions = "--nightly lhcb-prerelease Wed" pathToScripts = "/afs/cern.ch/lhcb/software/releases/LBSCRIPTS/prod/InstallArea/scripts" p = Popen( - "set HOME = " + home + ";" + "source " + - pathToScripts + "/LbLogin.sh;" + - "set User_release_area = " + userReleaseArea + ";" + - "source `which SetupProject.sh` Panoptes " + - setupProjectPanoptesVersion + " " + setupProjectPanoptesOptions + ";" + - "rm -f env_var_settings.txt;" + - "echo $RICHMIRRORALIGNMENTGANGAROOT > env_var_settings.txt ", + "set HOME = " + + home + + ";" + + "source " + + pathToScripts + + "/LbLogin.sh;" + + "set User_release_area = " + + userReleaseArea + + ";" + + "source `which SetupProject.sh` Panoptes " + + setupProjectPanoptesVersion + + " " + + setupProjectPanoptesOptions + + ";" + + "rm -f env_var_settings.txt;" + + "echo $RICHMIRRORALIGNMENTGANGAROOT > env_var_settings.txt ", shell=True, - executable="/bin/bash") + executable="/bin/bash", +) sts = os.waitpid(p.pid, 0) env_var_settings_txt = open("env_var_settings.txt") @@ -41,51 +51,51 @@ scriptOfEverything = RICHMIRRORALIGNMENTGANGAROOT + "/job/RichMirrorAlignmentGan workDir = "/afs/cern.ch/user/a/asolomin/public/rich_align/workdir" -#dDDB_tag = "head-20100119" +# dDDB_tag = "head-20100119" dDDB_tag = "head-20100407" -#dDDB_tag = "head-20100906" +# dDDB_tag = "head-20100906" -#localCondDB_tag = "rich-20100113" +# localCondDB_tag = "rich-20100113" condDB_tag = "sim-20100412-vc-md100" -#condDB_tag = "sim-20100831-vc-md100" +# condDB_tag = "sim-20100831-vc-md100" -#setupProjectBrunelOpts = "--use-grid" +# setupProjectBrunelOpts = "--use-grid" setupProjectBrunelOpts = "" -#eventSelectorInputFile = RICHMIRRORALIGNMENTGANGAROOT+"/options/EventSelectorInput_R2Sel100f7TeV_MC10.py" +# eventSelectorInputFile = RICHMIRRORALIGNMENTGANGAROOT+"/options/EventSelectorInput_R2Sel100f7TeV_MC10.py" eventSelectorInputFile = "EventSelectorInput_R2Sel100f7TeV_MC10.py" -#brunelEvtMax = 10 -#brunelPrintFreq = 1 -#splitMaxFiles = 1 -#brunelEvtMax = 100 -#brunelPrintFreq = 10 -#splitMaxFiles = 6 +# brunelEvtMax = 10 +# brunelPrintFreq = 1 +# splitMaxFiles = 1 +# brunelEvtMax = 100 +# brunelPrintFreq = 10 +# splitMaxFiles = 6 brunelEvtMax = -1 brunelPrintFreq = 100 splitMaxFiles = 1000 -#splitFilesPerJob = 1 -#splitFilesPerJob = 4 +# splitFilesPerJob = 1 +# splitFilesPerJob = 4 splitFilesPerJob = 2 -#backEnd = "LSF_8nm" -#backEnd = "LSF_1nh" -#backEnd = "local" +# backEnd = "LSF_8nm" +# backEnd = "LSF_1nh" +# backEnd = "local" backEnd = "dirac" -#diracCPUTime = 1200 -#diracCPUTime = 2400 -#diracCPUTime = 9600 +# diracCPUTime = 1200 +# diracCPUTime = 2400 +# diracCPUTime = 9600 diracCPUTime = 19200 brunelInitialInputType = "DST" messageSvcOutputLevel = 3 -#mirrCombinSubset = "10m12c_p0p2fix" # required for RICH1 -#mirrCombinSubset = "48m85c_p12p43fix" -#mirrCombinSubset = "48m85c_p12p43s08s31fix" +# mirrCombinSubset = "10m12c_p0p2fix" # required for RICH1 +# mirrCombinSubset = "48m85c_p12p43fix" +# mirrCombinSubset = "48m85c_p12p43s08s31fix" mirrCombinSubset = "48m48c_p12p43s09s30fix" thisCase = "100fSurB" @@ -94,44 +104,44 @@ dataVariant = "MC10" groupSlices = 1 groupBins = 1 -#minAverageBinPop = 25 +# minAverageBinPop = 25 minAverageBinPop = 9 deltaThetaWindow = 4 -#deltaThetaWindow = 3 # mrad +# deltaThetaWindow = 3 # mrad coeffCalibrTilt = 0.3 -#useTruth = "MCTruP" +# useTruth = "MCTruP" useTruth = "" useOffsetsFromMC = "false" -#useOffsetsFromMC = "true" +# useOffsetsFromMC = "true" verOffsetsFromMC = "" -#verOffsetsFromMC = "100fSurBMC10" +# verOffsetsFromMC = "100fSurBMC10" usePremisaligned = "false" -#usePremisaligned = "true" +# usePremisaligned = "true" verPremisaligned = "" -#verPremisaligned = "Pre" # premisaligned but fixed mirrors are +# verPremisaligned = "Pre" # premisaligned but fixed mirrors are # zeros -#verPremisaligned = "Prf" # premisaligned and fixed mirrors' +# verPremisaligned = "Prf" # premisaligned and fixed mirrors' # tilts at iteration 0 are equal to # initial tilts -#verPremisaligned = "Pri" # premisaligned and all initial values +# verPremisaligned = "Pri" # premisaligned and all initial values # at iteration 0 are equal to initial # tilts -#combinFitVariant = "slices" +# combinFitVariant = "slices" combinFitVariant = "surfaceB" maximumNumberOfIterations = 1 -#maximumNumberOfIterations = 3 -#maximumNumberOfIterations = 5 +# maximumNumberOfIterations = 3 +# maximumNumberOfIterations = 5 startFromIteration = 0 -#startFromIteration = 1 +# startFromIteration = 1 richDetector = 2 # 1: RICH1, 2: RICH2 diff --git a/Rich/RichMirrorAlignmentGanga/job/settings/tests/Run1MDMSUpdate/RMAG_Collision12_settings_R2MD_IOV04.py b/Rich/RichMirrorAlignmentGanga/job/settings/tests/Run1MDMSUpdate/RMAG_Collision12_settings_R2MD_IOV04.py index b4581205604ef0aae503c00093dadebefe5f73a3..de2dee1ffcfb409e05649ea542325aad186f0ab6 100644 --- a/Rich/RichMirrorAlignmentGanga/job/settings/tests/Run1MDMSUpdate/RMAG_Collision12_settings_R2MD_IOV04.py +++ b/Rich/RichMirrorAlignmentGanga/job/settings/tests/Run1MDMSUpdate/RMAG_Collision12_settings_R2MD_IOV04.py @@ -14,21 +14,21 @@ import os from subprocess import * -#=============================================================================== +# =============================================================================== # defs -#=============================================================================== +# =============================================================================== # stdReporter returns stdout and stderr from Popen.communicate() def stdReporter(stdout, stderr): - print "The shell script gave some STANDARD OUTPUT:" - print stdout + print("The shell script gave some STANDARD OUTPUT:") + print(stdout) if stderr: - print "The shell script also gave some STANDARD ERROR:" - print stderr + print("The shell script also gave some STANDARD ERROR:") + print(stderr) else: - print "The shell script ran fine." + print("The shell script ran fine.") -#=============================================================================== +# =============================================================================== ######################################################## # Search "Important" to find things you had better check @@ -39,34 +39,36 @@ def stdReporter(stdout, stderr): ### Important: What is the backend backEnd = "dirac" -#backEnd = "online" +# backEnd = "online" ### Important: Set your home directory home = "/afs/cern.ch/user/p/pnaik" # point this to your home directory -if (backEnd.lower() == 'online'): +if backEnd.lower() == "online": home = "/home/pnaik" # point this to the online home ### Important: Choose Panoptes Version (HEAD is usually fine, for Offline Alignment) setupProjectPanoptesVersion = "HEAD" -if (backEnd.lower() == 'online'): +if backEnd.lower() == "online": setupProjectPanoptesVersion = "v5r2" # you want a fixed version online ### Important: Choose Panoptes Options -setupProjectPanoptesOptions = "--nightly lhcb-head Wed" # Safest to specify a day that you know is working -#setupProjectPanoptesOptions = "--nightly lhcb-head" # will fail if running the script overnight -#setupProjectPanoptesOptions = "--nightly lhcb-prerelease Sun" -#setupProjectPanoptesOptions = "--nightly lhcb-prerelease" -#setupProjectPanoptesOptions = "--dev-dir=/afs/cern.ch/user/p/pnaik/PANOPTES" -if (backEnd.lower() == 'online'): +setupProjectPanoptesOptions = ( + "--nightly lhcb-head Wed" # Safest to specify a day that you know is working +) +# setupProjectPanoptesOptions = "--nightly lhcb-head" # will fail if running the script overnight +# setupProjectPanoptesOptions = "--nightly lhcb-prerelease Sun" +# setupProjectPanoptesOptions = "--nightly lhcb-prerelease" +# setupProjectPanoptesOptions = "--dev-dir=/afs/cern.ch/user/p/pnaik/PANOPTES" +if backEnd.lower() == "online": setupProjectPanoptesOptions = "" ### Important: Define a working directory. If it does not exist, make it. workDir = "/afs/cern.ch/user/p/pnaik/RichAlignment/2012/R2MD_IOV04" # Point this to your working directory -if (backEnd.lower() == 'online'): +if backEnd.lower() == "online": workDir = "/home/pnaik/rich/2012/R2MD_IOV04" if not os.path.isdir(workDir): - print "*** DOES NOT EXIST: workDir = " + workDir - print "*** Making " + workDir + print("*** DOES NOT EXIST: workDir = " + workDir) + print("*** Making " + workDir) os.makedirs(workDir) ### Important: Get the database tags right @@ -74,20 +76,20 @@ dDDB_tag = "dddb-20150119-2" # condDB_tag = "cond-20150409-1" # With Run 1 MDMS Updates ### Important: Set the LHCb and Brunel version and Brunel extra options -LHCbVersion = '' -if (backEnd.lower() == 'online'): - LHCbVersion = 'v36r2' -brunelVersion = 'v47r5' +LHCbVersion = "" +if backEnd.lower() == "online": + LHCbVersion = "v36r2" +brunelVersion = "v47r5" setupProjectBrunelOpts = "" ### Important: Where is the data eventSelectorInputFile = "/afs/cern.ch/user/p/pnaik/RichAlignment/2012/data/MD_IOV04.py" # make sure this exists -if (backEnd.lower() == 'online'): +if backEnd.lower() == "online": eventSelectorInputFile = "/home/pnaik/rich/2012/data/MD_IOV04.py" # we will be using the data from the HLT ### Important: What is the input type of your data brunelInitialInputType = "RAW" -if (backEnd.lower() == 'online'): +if backEnd.lower() == "online": brunelInitialInputType = "RAW" ### Important: Which RICH? @@ -113,39 +115,45 @@ AddedDB = [""] ### This is standard, do not change userReleaseArea = os.getenv("User_release_area") pathToScripts = "/afs/cern.ch/lhcb/software/releases/LBSCRIPTS/prod/InstallArea/scripts" -if (backEnd.lower() == 'online'): +if backEnd.lower() == "online": pathToScripts = "/cvmfs/lhcb.cern.ch/lib/lhcb/LBSCRIPTS/prod/InstallArea/scripts" ### This gets the environment variables we will need automatically, based on the above p = Popen( - "export HOME=" + home + ";" + "source " + pathToScripts + "/LbLogin.sh;" + - "export User_release_area=" + userReleaseArea + ";" + "export HOME=" + + home + + ";" + + "source " + + pathToScripts + + "/LbLogin.sh;" + + "export User_release_area=" + + userReleaseArea + + ";" # +"export CMTPROJECTPATH=/afs/cern.ch/sw/lcg/external/xqilla/2.2.4/x86_64-slc5-gcc43-opt/lib:$CMTPROJECTPATH;" # probably obsolete - + "source `which SetupProject.sh` Panoptes " + setupProjectPanoptesVersion - + " " + setupProjectPanoptesOptions + ";" + - "rm -f env_var_settings_mirroralign.txt;" - + - "echo $RICHMIRRALIGNROOT > env_var_settings_mirroralign.txt; " # Line 1 - + - "echo $RICHMIRRCOMBINFITROOT >> env_var_settings_mirroralign.txt; " # Line 2 - + - "echo $RICHMIRRORALIGNMENTGANGAROOT >> env_var_settings_mirroralign.txt; " # Line 3 - + - "echo $SQLITEDBPATH >> env_var_settings_mirroralign.txt; " # Line 4 + + "source `which SetupProject.sh` Panoptes " + + setupProjectPanoptesVersion + + " " + + setupProjectPanoptesOptions + + ";" + + "rm -f env_var_settings_mirroralign.txt;" + + "echo $RICHMIRRALIGNROOT > env_var_settings_mirroralign.txt; " # Line 1 + + "echo $RICHMIRRCOMBINFITROOT >> env_var_settings_mirroralign.txt; " # Line 2 + + "echo $RICHMIRRORALIGNMENTGANGAROOT >> env_var_settings_mirroralign.txt; " # Line 3 + + "echo $SQLITEDBPATH >> env_var_settings_mirroralign.txt; " # Line 4 + "echo $SHELL", shell=True, executable="/bin/bash", stdout=PIPE, - stderr=PIPE) + stderr=PIPE, +) (stdout, stderr) = p.communicate() stdReporter(stdout, stderr) env_var_settings_mirroralign_txt = open("env_var_settings_mirroralign.txt") -RICHMIRRALIGNROOT = env_var_settings_mirroralign_txt.readline().strip( -) # Line 1 -RICHMIRRCOMBINFITROOT = env_var_settings_mirroralign_txt.readline().strip( -) # Line 2 -RICHMIRRORALIGNMENTGANGAROOT = env_var_settings_mirroralign_txt.readline( -).strip() # Line 3 +RICHMIRRALIGNROOT = env_var_settings_mirroralign_txt.readline().strip() # Line 1 +RICHMIRRCOMBINFITROOT = env_var_settings_mirroralign_txt.readline().strip() # Line 2 +RICHMIRRORALIGNMENTGANGAROOT = ( + env_var_settings_mirroralign_txt.readline().strip() +) # Line 3 SQLITEDBPATH = env_var_settings_mirroralign_txt.readline().strip() # Line 4 env_var_settings_mirroralign_txt.close() os.system("rm -f env_var_settings_mirroralign.txt") @@ -170,7 +178,7 @@ if not SQLITEDBPATH.endswith(os.path.sep): ### To run over all events, we set brunelEvtMax to -1 # PN - not sure if this is events per job or events per subjob... I *think* it is the latter -#brunelEvtMax = -1 +# brunelEvtMax = -1 brunelEvtMax = 20000 ### Standard @@ -186,27 +194,35 @@ messageSvcOutputLevel = "3" ### Automatic choice of mirrCombinSubset file mirrCombinSubset = "" -if (richDetector == 2): +if richDetector == 2: mirrCombinSubset = "Rich2CombAndMirrSubsets_96m94c_p12p43fix.txt" # not yet available in PANOPTES HEAD, so I don't try to read it using os.system on the next line - #os.system("cp "+RICHMIRRORALIGNMENTGANGAROOT+"files/Rich2CombAndMirrSubsets_96m94c_p12p43fix.txt .") - os.system("cp " + RICHMIRRALIGNROOT + - "Test/Rich2CombAndMirrSubsets_96m94c_p12p43fix.txt " + - workDir) # Requires RICHMIRRALIGNROOT to be defined -if (richDetector == 1): + # os.system("cp "+RICHMIRRORALIGNMENTGANGAROOT+"files/Rich2CombAndMirrSubsets_96m94c_p12p43fix.txt .") + os.system( + "cp " + + RICHMIRRALIGNROOT + + "Test/Rich2CombAndMirrSubsets_96m94c_p12p43fix.txt " + + workDir + ) # Requires RICHMIRRALIGNROOT to be defined +if richDetector == 1: mirrCombinSubset = "Rich1CombAndMirrSubsets_20m16c_p0p1p2p3fix.txt" - #os.system("cp "+RICHMIRRORALIGNMENTGANGAROOT+"files/Rich1CombAndMirrSubsets_20m16c_p0p1p2p3fix.txt .") - os.system("cp " + RICHMIRRALIGNROOT + - "Test/Rich1CombAndMirrSubsets_20m16c_p0p1p2p3fix.txt " + - workDir) # Requires RICHMIRRALIGNROOT to be defined + # os.system("cp "+RICHMIRRORALIGNMENTGANGAROOT+"files/Rich1CombAndMirrSubsets_20m16c_p0p1p2p3fix.txt .") + os.system( + "cp " + + RICHMIRRALIGNROOT + + "Test/Rich1CombAndMirrSubsets_20m16c_p0p1p2p3fix.txt " + + workDir + ) # Requires RICHMIRRALIGNROOT to be defined ### Standard RICH mirror Alignment parameters, do not touch unless you are an expert groupSlices = 1 groupBins = 1 -minAverageBinPop = 6 # 6 * 50 deltaTheta bins in one phi bin slice = 300 photons minimum per phi bin +minAverageBinPop = ( + 6 # 6 * 50 deltaTheta bins in one phi bin slice = 300 photons minimum per phi bin +) -deltaThetaWindow = 4.0 #4 -if (richDetector == 2): - deltaThetaWindow = 3.0 #2 +deltaThetaWindow = 4.0 # 4 +if richDetector == 2: + deltaThetaWindow = 3.0 # 2 coeffCalibrTilt = 0.3 @@ -217,24 +233,30 @@ verOffsetsFromMC = "" usePremisaligned = "false" -combinFitVariant = 1 #"slices" -if (richDetector == 2): - combinFitVariant = 3 #"surfaceB" RICH2 +combinFitVariant = 1 # "slices" +if richDetector == 2: + combinFitVariant = 3 # "surfaceB" RICH2 maximumNumberOfIterations = 10 ### Change these if something bad happens in an iteration, but it is recoverable (i.e. Ganga jobs failed) startFromIteration = 0 # which iteration do you want to start from? NEED TO CHECK/CONFIRM THIS WORKS FOR ANYTHING OTHER THAN 0 -skipFirstRecoJob = 0 # currently only for iteration 0, skip submitting Brunel jobs to grid -skipFirstMergeJob = 0 # currently only for iteration 0, skip the merging Brunel histograms +skipFirstRecoJob = ( + 0 # currently only for iteration 0, skip submitting Brunel jobs to grid +) +skipFirstMergeJob = ( + 0 # currently only for iteration 0, skip the merging Brunel histograms +) if skipFirstRecoJob == 0: if skipFirstMergeJob == 1: skipFirstMergeJob == 0 -#if you are not skipping brunel jobs, you do not want to skip the merging of the brunel jobs! -#if you want to merge the jobs from a previous run of the script you must provide the job numbers -previousJobNumbers = range(984, 993) +# if you are not skipping brunel jobs, you do not want to skip the merging of the brunel jobs! +# if you want to merge the jobs from a previous run of the script you must provide the job numbers +previousJobNumbers = list(range(984, 993)) -skipFirstCombinFit = 0 # currently only for iteration 0, skip the combinFit before mirrAlign +skipFirstCombinFit = ( + 0 # currently only for iteration 0, skip the combinFit before mirrAlign +) ### Standard RICH mirror Alignment parameters, do not touch unless you are an expert @@ -247,9 +269,10 @@ skipFirstCombinFit = 0 # currently only for iteration 0, skip the combinFit bef magnifCoeffMode = 2 # 2: individual for each pair # evaluated on-fly for each iteration # depedent on sign of rotation -if (magnifCoeffMode == 0): - os.system("cp " + RICHMIRRORALIGNMENTGANGAROOT + "/files/MagCoeffs/* " + - workDir) # Requires RICHMIRRORALIGNMENTGANGAROOT to be defined +if magnifCoeffMode == 0: + os.system( + "cp " + RICHMIRRORALIGNMENTGANGAROOT + "/files/MagCoeffs/* " + workDir + ) # Requires RICHMIRRORALIGNMENTGANGAROOT to be defined # 0: Minuit solutionMethod = 1 # 1: algebraic diff --git a/Rich/RichMirrorAlignmentGanga/job/tagger.py b/Rich/RichMirrorAlignmentGanga/job/tagger.py index 190e53de4da7e5de4df0c43baf167915f49d9015..b7ccace39f09a549de7cd9e0df83823d3c16c9d5 100644 --- a/Rich/RichMirrorAlignmentGanga/job/tagger.py +++ b/Rich/RichMirrorAlignmentGanga/job/tagger.py @@ -9,13 +9,14 @@ # or submit itself to any jurisdiction. # ############################################################################### import sys + from CondDBUI import CondDB CondDB_tag = sys.argv[1] -#print CondDB_tag +# print CondDB_tag this = sys.argv[2] -#print this +# print this thisDB = sys.argv[3] -#print thisDB +# print thisDB condDB = CondDB("sqlite_file:" + this + ".db/" + thisDB, readOnly=False) condDB.recursiveTag("/", CondDB_tag) diff --git a/Rich/RichMirrorAlignmentGanga/options/Brunel_Rich1AlignMoni_Collision10-DST.py b/Rich/RichMirrorAlignmentGanga/options/Brunel_Rich1AlignMoni_Collision10-DST.py index 2205fdc3d180751c8662fd393ce3d2cdc3fcbed3..370c4345275556d67ed0f71670fa16996c2c7b56 100644 --- a/Rich/RichMirrorAlignmentGanga/options/Brunel_Rich1AlignMoni_Collision10-DST.py +++ b/Rich/RichMirrorAlignmentGanga/options/Brunel_Rich1AlignMoni_Collision10-DST.py @@ -9,32 +9,38 @@ # or submit itself to any jurisdiction. # ############################################################################### from Brunel.Configuration import * + ############################################################################### from GaudiKernel.ProcessJobOptions import importOptions -#importOptions ("$APPCONFIGOPTS/Brunel/earlyData.py") # comment this to make it work! + +# importOptions ("$APPCONFIGOPTS/Brunel/earlyData.py") # comment this to make it work! importOptions("$APPCONFIGOPTS/Brunel/DataType-2010.py") -#importOptions("$APPCONFIGOPTS/UseOracle.py") -#importOptions("$APPCONFIGOPTS/DisableLFC.py") +# importOptions("$APPCONFIGOPTS/UseOracle.py") +# importOptions("$APPCONFIGOPTS/DisableLFC.py") ############################################################################### from Configurables import MessageSvc + MessageSvc().Format = "% F%30W%S%7W%R%T %0W%M" -#MessageSvc().OutputLevel = 7 +# MessageSvc().OutputLevel = 7 from Configurables import Brunel + Brunel().EvtMax = 10 Brunel().PrintFreq = 1 Brunel().OutputType = "None" # reconstruct RICH only Brunel().InitSequence = ["Brunel"] Brunel().RecoSequence = ["RICH"] -#Brunel().MCCheckSequence = ["RICH"] # only when WithTruth +# Brunel().MCCheckSequence = ["RICH"] # only when WithTruth Brunel().Histograms = "OfflineExpress" # propagates down to Alignment from Configurables import RecMoniConf + # RecMoniConf is defined in REC/REC_vXrY/RecSys/python/RecSys/Configuration.py RecMoniConf().MoniSequence = ["RICH"] ############################################################################## from Configurables import RichRecSysConf + rConf = RichRecSysConf("RichOfflineRec") # disable PID rConf.setProp("PidConfig", "None") @@ -48,14 +54,8 @@ rConf.photonConfig().SelectionMode = "Loose" rConf.Radiators = ["Rich1Gas"] # only Long tracks with P > 10GeV rConf.trackConfig().TrackCuts = { - "Forward": { - "Chi2Cut": [0, 5], - "PCut": [10.0, 9999999] - }, - "Match": { - "Chi2Cut": [0, 5], - "PCut": [10.0, 9999999] - } + "Forward": {"Chi2Cut": [0, 5], "PCut": [10.0, 9999999]}, + "Match": {"Chi2Cut": [0, 5], "PCut": [10.0, 9999999]}, } # Turn off trackless ring finding rConf.TracklessRingAlgs = [] @@ -63,6 +63,7 @@ rConf.TracklessRingAlgs = [] rConf.RefitTracks = True from Configurables import RichRecQCConf + # disable monitors that are enabled by default in "OfflineFull" mode, # except "AlignmentMonitoring" RichRecQCConf("OfflineRichMoni").removeMonitor("L1SizeMonitoring") @@ -76,7 +77,7 @@ RichRecQCConf("OfflineRichMoni").removeMonitor("TracklessRingAngles") RichRecQCConf("OfflineRichMoni").removeMonitor("TracklessRingPeakSearch") RichRecQCConf("OfflineRichMoni").removeMonitor("HPDImageShifts") RichRecQCConf("OfflineRichMoni").removeMonitor("DataDecodingErrors") -#RichRecQCConf("OfflineRichMoni").removeMonitor("AlignmentMonitoring" ) +# RichRecQCConf("OfflineRichMoni").removeMonitor("AlignmentMonitoring" ) RichRecQCConf("OfflineRichMoni").removeMonitor("HPDIFBMonitoring") RichRecQCConf("OfflineRichMoni").removeMonitor("RichPixelPositions") RichRecQCConf("OfflineRichMoni").removeMonitor("HPDHitPlots") @@ -98,26 +99,25 @@ RichRecQCConf("OfflineRichMoni").removeMonitor("RichRecoTiming") RichRecQCConf("OfflineRichMoni").setProp("NTupleProduce", False) from Configurables import RichAlignmentConf + # choose RICH you want -#RichAlignmentConf("OfflineRichMoni_RichAlignmentConf").setProp("Radiators", ["Rich1Gas"]) +# RichAlignmentConf("OfflineRichMoni_RichAlignmentConf").setProp("Radiators", ["Rich1Gas"]) RichAlignmentConf("OfflineRichMoni_RichAlignmentConf").setProp( - "Radiators", ["Rich1Gas"]) + "Radiators", ["Rich1Gas"] +) # activate long list of segment combination histos to be prebooked for RICH2 # this may propagate from the Brunel Cofiguration, though -#RichAlignmentConf("OfflineRichMoni_RichAlignmentConf").setProp("Histograms", "OfflineExpress") +# RichAlignmentConf("OfflineRichMoni_RichAlignmentConf").setProp("Histograms", "OfflineExpress") ############################################################################## from Configurables import DstConf + # enable DST unpacking: needed to get tracks ApplicationMgr().ExtSvc += ["DataOnDemandSvc"] DstConf().EnableUnpack = ["Reconstruction"] ############################################################################## -from Configurables import LHCbApp # db tags -#LHCbApp().DDDBtag = "head-20100407" -#LHCbApp().CondDBtag = "head-20100408" +# LHCbApp().DDDBtag = "head-20100407" +# LHCbApp().CondDBtag = "head-20100408" ############################################################################## -from Configurables import CondDB -from Configurables import CondDBAccessSvc - -from Configurables import CondDB, CondDBAccessSvc +from Configurables import CondDB, CondDBAccessSvc, LHCbApp diff --git a/Rich/RichMirrorAlignmentGanga/options/Brunel_Rich1AlignMoni_Collision11-RAW.py b/Rich/RichMirrorAlignmentGanga/options/Brunel_Rich1AlignMoni_Collision11-RAW.py index ef02663145b61d44a1cb1e2b604d5e56ff1ef063..088674b62d79880f2f9d543081ccfc30206b729b 100644 --- a/Rich/RichMirrorAlignmentGanga/options/Brunel_Rich1AlignMoni_Collision11-RAW.py +++ b/Rich/RichMirrorAlignmentGanga/options/Brunel_Rich1AlignMoni_Collision11-RAW.py @@ -9,48 +9,52 @@ # or submit itself to any jurisdiction. # ############################################################################### from Brunel.Configuration import * + ############################################################################### from GaudiKernel.ProcessJobOptions import importOptions -#importOptions ("$APPCONFIGOPTS/Brunel/earlyData.py") + +# importOptions ("$APPCONFIGOPTS/Brunel/earlyData.py") importOptions("$APPCONFIGOPTS/Brunel/DataType-2012.py") -#importOptions("$APPCONFIGOPTS/UseOracle.py") -#importOptions("$APPCONFIGOPTS/DisableLFC.py") +# importOptions("$APPCONFIGOPTS/UseOracle.py") +# importOptions("$APPCONFIGOPTS/DisableLFC.py") ############################################################################### from Configurables import MessageSvc + MessageSvc().Format = "% F%30W%S%7W%R%T %0W%M" -#MessageSvc().OutputLevel = 7 +# MessageSvc().OutputLevel = 7 from Configurables import Brunel + Brunel().EvtMax = 1000 Brunel().PrintFreq = 10 Brunel().OutputType = "None" -#--Again the Database problem... -#from Configurables import CondDB, LHCbApp -#CondDB(UseOracle = True) -#LHCbApp().DDDBtag ="head-20110302" -#LHCbApp().CondDBtag="head-20110318" +# --Again the Database problem... +# from Configurables import CondDB, LHCbApp +# CondDB(UseOracle = True) +# LHCbApp().DDDBtag ="head-20110302" +# LHCbApp().CondDBtag="head-20110318" # reconstruct RICH only -#Brunel ().InitSequence = ["Brunel"] -Brunel().RecoSequence = [ - "Decoding", "VELO", "TT", "IT", "OT", "Tr", "Vertex", "RICH" -] +# Brunel ().InitSequence = ["Brunel"] +Brunel().RecoSequence = ["Decoding", "VELO", "TT", "IT", "OT", "Tr", "Vertex", "RICH"] -#Brunel ().RecoSequence = ["RICH"] -#Brunel().MCCheckSequence = ["RICH"] # only when WithTruth +# Brunel ().RecoSequence = ["RICH"] +# Brunel().MCCheckSequence = ["RICH"] # only when WithTruth Brunel().Histograms = "Expert" # propagates down to Alignment -#Brunel ().Histograms = "None" +# Brunel ().Histograms = "None" Brunel().DataType = "2012" -#from Configurables import EventClockSvc -#EventClockSvc( InitialTime = 1341100800000000000 ) # 1st July 2012 +# from Configurables import EventClockSvc +# EventClockSvc( InitialTime = 1341100800000000000 ) # 1st July 2012 from Configurables import RecMoniConf + # RecMoniConf is defined in REC/REC_vXrY/RecSys/python/RecSys/Configuration.py RecMoniConf().MoniSequence = ["RICH"] ############################################################################## from Configurables import RichRecSysConf + rConf = RichRecSysConf("RichOfflineRec") # disable PID rConf.setProp("PidConfig", "None") @@ -60,7 +64,8 @@ minP = 10 # in GeV # Tweak the tracking to only run the Forward tracking, and to apply # the min track momentum cut during the track finding. -from Configurables import TrackSys, PatForward, PatForwardTool +from Configurables import PatForward, PatForwardTool, TrackSys + TrackSys().setProp("TrackPatRecAlgorithms", ["FastVelo", "Forward"]) PatForward("PatForward").addTool(PatForwardTool) PatForward("PatForward").PatForwardTool.MinMomentum = minP * 1000 # in MeV @@ -74,19 +79,14 @@ rConf.photonConfig().SelectionMode = "Loose" rConf.Radiators = ["Rich1Gas", "Rich2Gas"] # only Long tracks with P > 10GeV rConf.trackConfig().TrackCuts = { - "Forward": { - "Chi2Cut": [0, 5], - "PCut": [minP, 9999999] - }, - "Match": { - "Chi2Cut": [0, 5], - "PCut": [minP, 9999999] - } + "Forward": {"Chi2Cut": [0, 5], "PCut": [minP, 9999999]}, + "Match": {"Chi2Cut": [0, 5], "PCut": [minP, 9999999]}, } # Turn off trackless ring finding rConf.TracklessRingAlgs = [] from Configurables import RichRecQCConf + # disable monitors that are enabled by default in "OfflineFull" mode, # except "AlignmentMonitoring" RichRecQCConf("OfflineRichMoni").removeMonitor("L1SizeMonitoring") @@ -100,7 +100,7 @@ RichRecQCConf("OfflineRichMoni").removeMonitor("TracklessRingAngles") RichRecQCConf("OfflineRichMoni").removeMonitor("TracklessRingPeakSearch") RichRecQCConf("OfflineRichMoni").removeMonitor("HPDImageShifts") RichRecQCConf("OfflineRichMoni").removeMonitor("DataDecodingErrors") -#RichRecQCConf ("OfflineRichMoni").removeMonitor("AlignmentMonitoring" ) +# RichRecQCConf ("OfflineRichMoni").removeMonitor("AlignmentMonitoring" ) RichRecQCConf("OfflineRichMoni").removeMonitor("HPDIFBMonitoring") RichRecQCConf("OfflineRichMoni").removeMonitor("RichPixelPositions") RichRecQCConf("OfflineRichMoni").removeMonitor("HPDHitPlots") @@ -119,39 +119,43 @@ RichRecQCConf("OfflineRichMoni").removeMonitor("RichDataObjectChecks") RichRecQCConf("OfflineRichMoni").removeMonitor("RichRecoTiming") # disable producing NTuple -#RichRecQCConf ("OfflineRichMoni").setProp("NTupleProduce", False ) +# RichRecQCConf ("OfflineRichMoni").setProp("NTupleProduce", False ) from Configurables import RichAlignmentConf + # choose RICH you want -#RichAlignmentConf("OfflineRichMoni_RichAlignmentConf").setProp("Radiators", ["Rich1Gas"]) +# RichAlignmentConf("OfflineRichMoni_RichAlignmentConf").setProp("Radiators", ["Rich1Gas"]) RichAlign = RichAlignmentConf("OfflineRichMoni_RichAlignmentConf") RichAlign.Radiators = ["Rich1Gas", "Rich2Gas"] RichAlign.HPDList = [[0], [0], [0]] RichAlign.Histograms = "Expert" -#RichAlign.VetoedHPDs = [100309] +# RichAlign.VetoedHPDs = [100309] RichAlign.NTupleProduce = False RichAlign.R1NTupleProduce = False # activate long list of segment combination histos to be prebooked for RICH2 # this may propagate from the Brunel Cofiguration, though -#RichAlignmentConf("OfflineRichMoni_RichAlignmentConf").setProp("Histograms", "OfflineExpress") +# RichAlignmentConf("OfflineRichMoni_RichAlignmentConf").setProp("Histograms", "OfflineExpress") ############################################################################## -#from Configurables import DstConf +# from Configurables import DstConf ## enable DST unpacking: needed to get tracks -#ApplicationMgr ().ExtSvc += ["DataOnDemandSvc"] -#DstConf ().EnableUnpack = True +# ApplicationMgr ().ExtSvc += ["DataOnDemandSvc"] +# DstConf ().EnableUnpack = True ############################################################################## -from Configurables import LHCbApp # db tags -#LHCbApp().DDDBtag = "head-20100407" -#LHCbApp().CondDBtag = "head-20100408" +# LHCbApp().DDDBtag = "head-20100407" +# LHCbApp().CondDBtag = "head-20100408" ############################################################################## -from Configurables import CondDB -from Configurables import CondDBAccessSvc -from Configurables import ApplicationMgr -from Configurables import HistogramPersistencySvc -#OutputStream("DstWriter").Output = "DATAFILE='Alignment.dst' TYP='POOL_ROOTTREE' OPT='REC'" +from Configurables import ( + ApplicationMgr, + CondDB, + CondDBAccessSvc, + HistogramPersistencySvc, + LHCbApp, +) + +# OutputStream("DstWriter").Output = "DATAFILE='Alignment.dst' TYP='POOL_ROOTTREE' OPT='REC'" NTupleSvc().Output = [ "RICHTUPLE1 DATAFILE='Ntuple_2012-Collisions.root' TYP='ROOT' OPT='NEW'" ] diff --git a/Rich/RichMirrorAlignmentGanga/options/Brunel_Rich1AlignMoni_Collision12-DST.py b/Rich/RichMirrorAlignmentGanga/options/Brunel_Rich1AlignMoni_Collision12-DST.py index 43966e47b9f6cf567a5bd553a86cb4a624d4d90f..8440e55441c0d881d2833528c7275497d38163e9 100644 --- a/Rich/RichMirrorAlignmentGanga/options/Brunel_Rich1AlignMoni_Collision12-DST.py +++ b/Rich/RichMirrorAlignmentGanga/options/Brunel_Rich1AlignMoni_Collision12-DST.py @@ -9,41 +9,43 @@ # or submit itself to any jurisdiction. # ############################################################################### from Brunel.Configuration import * + ############################################################################### from GaudiKernel.ProcessJobOptions import importOptions -#importOptions ("$APPCONFIGOPTS/Brunel/earlyData.py") + +# importOptions ("$APPCONFIGOPTS/Brunel/earlyData.py") importOptions("$APPCONFIGOPTS/Brunel/DataType-2012.py") -#importOptions("$APPCONFIGOPTS/UseOracle.py") -#importOptions("$APPCONFIGOPTS/DisableLFC.py") +# importOptions("$APPCONFIGOPTS/UseOracle.py") +# importOptions("$APPCONFIGOPTS/DisableLFC.py") ############################################################################### from Configurables import MessageSvc + MessageSvc().Format = "% F%30W%S%7W%R%T %0W%M" -#MessageSvc().OutputLevel = 7 +# MessageSvc().OutputLevel = 7 from Configurables import Brunel + Brunel().EvtMax = 1000 Brunel().PrintFreq = 10 Brunel().OutputType = "None" -#--Again the Database problem... -#from Configurables import CondDB, LHCbApp -#CondDB(UseOracle = True) -#LHCbApp().DDDBtag ="head-20110302" -#LHCbApp().CondDBtag="head-20110318" +# --Again the Database problem... +# from Configurables import CondDB, LHCbApp +# CondDB(UseOracle = True) +# LHCbApp().DDDBtag ="head-20110302" +# LHCbApp().CondDBtag="head-20110318" # reconstruct RICH only -#Brunel ().InitSequence = ["Brunel"] -Brunel().RecoSequence = [ - "Decoding", "VELO", "TT", "IT", "OT", "Tr", "Vertex", "RICH" -] +# Brunel ().InitSequence = ["Brunel"] +Brunel().RecoSequence = ["Decoding", "VELO", "TT", "IT", "OT", "Tr", "Vertex", "RICH"] -#Brunel ().RecoSequence = ["RICH"] -#Brunel().MCCheckSequence = ["RICH"] # only when WithTruth +# Brunel ().RecoSequence = ["RICH"] +# Brunel().MCCheckSequence = ["RICH"] # only when WithTruth Brunel().Histograms = "Expert" # propagates down to Alignment -#Brunel ().Histograms = "None" +# Brunel ().Histograms = "None" Brunel().DataType = "2012" -#DST +# DST Brunel().WithMC = False # with MC truth automatically invokes Simulation Brunel().InputType = "DST" Brunel().Persistency = "ROOT" @@ -52,10 +54,12 @@ Brunel().InitSequence = ["Brunel"] Brunel().RecoSequence = ["RICH"] from Configurables import RecMoniConf + # RecMoniConf is defined in REC/REC_vXrY/RecSys/python/RecSys/Configuration.py RecMoniConf().MoniSequence = ["RICH"] ############################################################################## from Configurables import RichRecSysConf + rConf = RichRecSysConf("RichOfflineRec") # disable PID rConf.setProp("PidConfig", "None") @@ -66,7 +70,8 @@ minP = 20 # in GeV # DST - PN - Not sure what effect this will have for DST, if any... but leaving it in # Tweak the tracking to only run the Forward tracking, and to apply # the min track momentum cut during the track finding. -from Configurables import TrackSys, PatForward, PatForwardTool +from Configurables import PatForward, PatForwardTool, TrackSys + TrackSys().setProp("TrackPatRecAlgorithms", ["FastVelo", "Forward"]) PatForward("PatForward").addTool(PatForwardTool) PatForward("PatForward").PatForwardTool.MinMomentum = minP * 1000 # in MeV @@ -92,14 +97,8 @@ rConf.photonConfig().SelectionMode = "Loose" rConf.Radiators = ["Rich1Gas"] # only Long tracks with P > 10GeV rConf.trackConfig().TrackCuts = { - "Forward": { - "Chi2Cut": [0, 5], - "PCut": [minP, 9999999] - }, - "Match": { - "Chi2Cut": [0, 5], - "PCut": [minP, 9999999] - } + "Forward": {"Chi2Cut": [0, 5], "PCut": [minP, 9999999]}, + "Match": {"Chi2Cut": [0, 5], "PCut": [minP, 9999999]}, } # Turn off trackless ring finding rConf.TracklessRingAlgs = [] @@ -108,6 +107,7 @@ rConf.TracklessRingAlgs = [] rConf.RefitTracks = True from Configurables import RichRecQCConf + # disable monitors that are enabled by default in "OfflineFull" mode, # except "AlignmentMonitoring" RichRecQCConf("OfflineRichMoni").removeMonitor("L1SizeMonitoring") @@ -121,7 +121,7 @@ RichRecQCConf("OfflineRichMoni").removeMonitor("TracklessRingAngles") RichRecQCConf("OfflineRichMoni").removeMonitor("TracklessRingPeakSearch") RichRecQCConf("OfflineRichMoni").removeMonitor("HPDImageShifts") RichRecQCConf("OfflineRichMoni").removeMonitor("DataDecodingErrors") -#RichRecQCConf ("OfflineRichMoni").removeMonitor("AlignmentMonitoring" ) +# RichRecQCConf ("OfflineRichMoni").removeMonitor("AlignmentMonitoring" ) RichRecQCConf("OfflineRichMoni").removeMonitor("HPDIFBMonitoring") RichRecQCConf("OfflineRichMoni").removeMonitor("RichPixelPositions") RichRecQCConf("OfflineRichMoni").removeMonitor("HPDHitPlots") @@ -140,41 +140,46 @@ RichRecQCConf("OfflineRichMoni").removeMonitor("RichDataObjectChecks") RichRecQCConf("OfflineRichMoni").removeMonitor("RichRecoTiming") # disable producing NTuple (PN- this was on in the older DST options, but I think we don't need it) -#RichRecQCConf ("OfflineRichMoni").setProp("NTupleProduce", False ) +# RichRecQCConf ("OfflineRichMoni").setProp("NTupleProduce", False ) from Configurables import RichAlignmentConf + # choose RICH you want -#RichAlignmentConf("OfflineRichMoni_RichAlignmentConf").setProp("Radiators", ["Rich1Gas"]) +# RichAlignmentConf("OfflineRichMoni_RichAlignmentConf").setProp("Radiators", ["Rich1Gas"]) RichAlign = RichAlignmentConf("OfflineRichMoni_RichAlignmentConf") RichAlign.Radiators = ["Rich1Gas"] RichAlign.HPDList = [[0], [0], [0]] RichAlign.Histograms = "Expert" -#RichAlign.VetoedHPDs = [100309] +# RichAlign.VetoedHPDs = [100309] RichAlign.NTupleProduce = False RichAlign.R1NTupleProduce = False # activate long list of segment combination histos to be prebooked for RICH2 # this may propagate from the Brunel Cofiguration, though -#RichAlignmentConf("OfflineRichMoni_RichAlignmentConf").setProp("Histograms", "OfflineExpress") +# RichAlignmentConf("OfflineRichMoni_RichAlignmentConf").setProp("Histograms", "OfflineExpress") ############################################################################## # DST from Configurables import DstConf + # enable DST unpacking: needed to get tracks ApplicationMgr().ExtSvc += ["DataOnDemandSvc"] DstConf().EnableUnpack = True ############################################################################## -from Configurables import LHCbApp # db tags -#LHCbApp().DDDBtag = "head-20100407" -#LHCbApp().CondDBtag = "head-20100408" +# LHCbApp().DDDBtag = "head-20100407" +# LHCbApp().CondDBtag = "head-20100408" ############################################################################## -from Configurables import CondDB -from Configurables import CondDBAccessSvc -#DST - PN - these were commented out in the DST options. I don't see the harm in leaving them in -from Configurables import ApplicationMgr -from Configurables import HistogramPersistencySvc -#OutputStream("DstWriter").Output = "DATAFILE='Alignment.dst' TYP='POOL_ROOTTREE' OPT='REC'" +# DST - PN - these were commented out in the DST options. I don't see the harm in leaving them in +from Configurables import ( + ApplicationMgr, + CondDB, + CondDBAccessSvc, + HistogramPersistencySvc, + LHCbApp, +) + +# OutputStream("DstWriter").Output = "DATAFILE='Alignment.dst' TYP='POOL_ROOTTREE' OPT='REC'" NTupleSvc().Output = [ "RICHTUPLE1 DATAFILE='Ntuple_2012-Collisions.root' TYP='ROOT' OPT='NEW'" ] diff --git a/Rich/RichMirrorAlignmentGanga/options/Brunel_Rich1AlignMoni_Collision12-RAW.py b/Rich/RichMirrorAlignmentGanga/options/Brunel_Rich1AlignMoni_Collision12-RAW.py index be83b121d2b9bfca00963538e216b3d51516f28a..bdb3a53e783492aa757bc73af74a9b176ce5fc0d 100644 --- a/Rich/RichMirrorAlignmentGanga/options/Brunel_Rich1AlignMoni_Collision12-RAW.py +++ b/Rich/RichMirrorAlignmentGanga/options/Brunel_Rich1AlignMoni_Collision12-RAW.py @@ -9,45 +9,49 @@ # or submit itself to any jurisdiction. # ############################################################################### from Brunel.Configuration import * + ############################################################################### from GaudiKernel.ProcessJobOptions import importOptions -#importOptions ("$APPCONFIGOPTS/Brunel/earlyData.py") + +# importOptions ("$APPCONFIGOPTS/Brunel/earlyData.py") importOptions("$APPCONFIGOPTS/Brunel/DataType-2012.py") -#importOptions("$APPCONFIGOPTS/UseOracle.py") -#importOptions("$APPCONFIGOPTS/DisableLFC.py") +# importOptions("$APPCONFIGOPTS/UseOracle.py") +# importOptions("$APPCONFIGOPTS/DisableLFC.py") ############################################################################### from Configurables import MessageSvc + MessageSvc().Format = "% F%30W%S%7W%R%T %0W%M" -#MessageSvc().OutputLevel = 7 +# MessageSvc().OutputLevel = 7 from Configurables import Brunel + Brunel().EvtMax = 1000 Brunel().PrintFreq = 10 Brunel().OutputType = "None" -#--Again the Database problem... -#from Configurables import CondDB, LHCbApp -#CondDB(UseOracle = True) -#LHCbApp().DDDBtag ="head-20110302" -#LHCbApp().CondDBtag="head-20110318" +# --Again the Database problem... +# from Configurables import CondDB, LHCbApp +# CondDB(UseOracle = True) +# LHCbApp().DDDBtag ="head-20110302" +# LHCbApp().CondDBtag="head-20110318" # reconstruct RICH only -#Brunel ().InitSequence = ["Brunel"] -Brunel().RecoSequence = [ - "Decoding", "VELO", "TT", "IT", "OT", "Tr", "Vertex", "RICH" -] +# Brunel ().InitSequence = ["Brunel"] +Brunel().RecoSequence = ["Decoding", "VELO", "TT", "IT", "OT", "Tr", "Vertex", "RICH"] -#Brunel ().RecoSequence = ["RICH"] -#Brunel().MCCheckSequence = ["RICH"] # only when WithTruth +# Brunel ().RecoSequence = ["RICH"] +# Brunel().MCCheckSequence = ["RICH"] # only when WithTruth Brunel().Histograms = "Expert" # propagates down to Alignment -#Brunel ().Histograms = "None" +# Brunel ().Histograms = "None" Brunel().DataType = "2012" from Configurables import RecMoniConf + # RecMoniConf is defined in REC/REC_vXrY/RecSys/python/RecSys/Configuration.py RecMoniConf().MoniSequence = ["RICH"] ############################################################################## from Configurables import RichRecSysConf + rConf = RichRecSysConf("RichOfflineRec") # disable PID rConf.setProp("PidConfig", "None") @@ -57,7 +61,8 @@ minP = 20 # in GeV # Tweak the tracking to only run the Forward tracking, and to apply # the min track momentum cut during the track finding. -from Configurables import TrackSys, PatForward, PatForwardTool +from Configurables import PatForward, PatForwardTool, TrackSys + TrackSys().setProp("TrackPatRecAlgorithms", ["FastVelo", "Forward"]) PatForward("PatForward").addTool(PatForwardTool) PatForward("PatForward").PatForwardTool.MinMomentum = minP * 1000 # in MeV @@ -71,19 +76,14 @@ rConf.photonConfig().SelectionMode = "Loose" rConf.Radiators = ["Rich1Gas"] # only Long tracks with P > 10GeV rConf.trackConfig().TrackCuts = { - "Forward": { - "Chi2Cut": [0, 5], - "PCut": [minP, 9999999] - }, - "Match": { - "Chi2Cut": [0, 5], - "PCut": [minP, 9999999] - } + "Forward": {"Chi2Cut": [0, 5], "PCut": [minP, 9999999]}, + "Match": {"Chi2Cut": [0, 5], "PCut": [minP, 9999999]}, } # Turn off trackless ring finding rConf.TracklessRingAlgs = [] from Configurables import RichRecQCConf + # disable monitors that are enabled by default in "OfflineFull" mode, # except "AlignmentMonitoring" RichRecQCConf("OfflineRichMoni").removeMonitor("L1SizeMonitoring") @@ -97,7 +97,7 @@ RichRecQCConf("OfflineRichMoni").removeMonitor("TracklessRingAngles") RichRecQCConf("OfflineRichMoni").removeMonitor("TracklessRingPeakSearch") RichRecQCConf("OfflineRichMoni").removeMonitor("HPDImageShifts") RichRecQCConf("OfflineRichMoni").removeMonitor("DataDecodingErrors") -#RichRecQCConf ("OfflineRichMoni").removeMonitor("AlignmentMonitoring" ) +# RichRecQCConf ("OfflineRichMoni").removeMonitor("AlignmentMonitoring" ) RichRecQCConf("OfflineRichMoni").removeMonitor("HPDIFBMonitoring") RichRecQCConf("OfflineRichMoni").removeMonitor("RichPixelPositions") RichRecQCConf("OfflineRichMoni").removeMonitor("HPDHitPlots") @@ -116,39 +116,43 @@ RichRecQCConf("OfflineRichMoni").removeMonitor("RichDataObjectChecks") RichRecQCConf("OfflineRichMoni").removeMonitor("RichRecoTiming") # disable producing NTuple -#RichRecQCConf ("OfflineRichMoni").setProp("NTupleProduce", False ) +# RichRecQCConf ("OfflineRichMoni").setProp("NTupleProduce", False ) from Configurables import RichAlignmentConf + # choose RICH you want -#RichAlignmentConf("OfflineRichMoni_RichAlignmentConf").setProp("Radiators", ["Rich1Gas"]) +# RichAlignmentConf("OfflineRichMoni_RichAlignmentConf").setProp("Radiators", ["Rich1Gas"]) RichAlign = RichAlignmentConf("OfflineRichMoni_RichAlignmentConf") RichAlign.Radiators = ["Rich1Gas"] RichAlign.HPDList = [[0], [0], [0]] RichAlign.Histograms = "Expert" -#RichAlign.VetoedHPDs = [100309] +# RichAlign.VetoedHPDs = [100309] RichAlign.NTupleProduce = False RichAlign.R1NTupleProduce = False # activate long list of segment combination histos to be prebooked for RICH2 # this may propagate from the Brunel Cofiguration, though -#RichAlignmentConf("OfflineRichMoni_RichAlignmentConf").setProp("Histograms", "OfflineExpress") +# RichAlignmentConf("OfflineRichMoni_RichAlignmentConf").setProp("Histograms", "OfflineExpress") ############################################################################## -#from Configurables import DstConf +# from Configurables import DstConf ## enable DST unpacking: needed to get tracks -#ApplicationMgr ().ExtSvc += ["DataOnDemandSvc"] -#DstConf ().EnableUnpack = True +# ApplicationMgr ().ExtSvc += ["DataOnDemandSvc"] +# DstConf ().EnableUnpack = True ############################################################################## -from Configurables import LHCbApp # db tags -#LHCbApp().DDDBtag = "head-20100407" -#LHCbApp().CondDBtag = "head-20100408" +# LHCbApp().DDDBtag = "head-20100407" +# LHCbApp().CondDBtag = "head-20100408" ############################################################################## -from Configurables import CondDB -from Configurables import CondDBAccessSvc -from Configurables import ApplicationMgr -from Configurables import HistogramPersistencySvc -#OutputStream("DstWriter").Output = "DATAFILE='Alignment.dst' TYP='POOL_ROOTTREE' OPT='REC'" +from Configurables import ( + ApplicationMgr, + CondDB, + CondDBAccessSvc, + HistogramPersistencySvc, + LHCbApp, +) + +# OutputStream("DstWriter").Output = "DATAFILE='Alignment.dst' TYP='POOL_ROOTTREE' OPT='REC'" NTupleSvc().Output = [ "RICHTUPLE1 DATAFILE='Ntuple_2012-Collisions.root' TYP='ROOT' OPT='NEW'" ] diff --git a/Rich/RichMirrorAlignmentGanga/options/Brunel_Rich1AlignMoni_Collision15-RAW.py b/Rich/RichMirrorAlignmentGanga/options/Brunel_Rich1AlignMoni_Collision15-RAW.py index bbb6cd31ca14401f5f6c59dcb8d2d231d4e82946..c708599e3877ca8dffb78d327a1b025567c87fc9 100644 --- a/Rich/RichMirrorAlignmentGanga/options/Brunel_Rich1AlignMoni_Collision15-RAW.py +++ b/Rich/RichMirrorAlignmentGanga/options/Brunel_Rich1AlignMoni_Collision15-RAW.py @@ -9,43 +9,49 @@ # or submit itself to any jurisdiction. # ############################################################################### from Brunel.Configuration import * + ############################################################################### from GaudiKernel.ProcessJobOptions import importOptions -#importOptions ("$APPCONFIGOPTS/Brunel/earlyData.py") + +# importOptions ("$APPCONFIGOPTS/Brunel/earlyData.py") importOptions("$APPCONFIGOPTS/Brunel/DataType-2015.py") -#importOptions("$APPCONFIGOPTS/UseOracle.py") -#importOptions("$APPCONFIGOPTS/DisableLFC.py") +# importOptions("$APPCONFIGOPTS/UseOracle.py") +# importOptions("$APPCONFIGOPTS/DisableLFC.py") ############################################################################### from Configurables import MessageSvc + MessageSvc().Format = "% F%30W%S%7W%R%T %0W%M" -#MessageSvc().OutputLevel = 7 +# MessageSvc().OutputLevel = 7 from Configurables import Brunel + Brunel().EvtMax = 1000 Brunel().PrintFreq = 10 Brunel().OutputType = "None" -#--Again the Database problem... -#from Configurables import CondDB, LHCbApp -#CondDB(UseOracle = True) -#LHCbApp().DDDBtag ="head-20110302" -#LHCbApp().CondDBtag="head-20110318" +# --Again the Database problem... +# from Configurables import CondDB, LHCbApp +# CondDB(UseOracle = True) +# LHCbApp().DDDBtag ="head-20110302" +# LHCbApp().CondDBtag="head-20110318" # reconstruct RICH only -#Brunel().InitSequence = ["Brunel"] +# Brunel().InitSequence = ["Brunel"] -#Brunel().RecoSequence = ["RICH"] ### RECO SEQUENCES NOW DEFINED BELOW! -#Brunel().MCCheckSequence = ["RICH"] # only when WithTruth +# Brunel().RecoSequence = ["RICH"] ### RECO SEQUENCES NOW DEFINED BELOW! +# Brunel().MCCheckSequence = ["RICH"] # only when WithTruth Brunel().Histograms = "Expert" # propagates down to Alignment -#Brunel().Histograms = "None" +# Brunel().Histograms = "None" Brunel().DataType = "2015" Brunel().VetoHltErrorEvents = False from Configurables import RecMoniConf + # RecMoniConf is defined in REC/REC_vXrY/RecSys/python/RecSys/Configuration.py RecMoniConf().MoniSequence = ["RICH"] ############################################################################## from Configurables import RichRecSysConf + rConf = RichRecSysConf("RichOfflineRec") # disable PID rConf.setProp("PidConfig", "None") @@ -57,31 +63,39 @@ minP = 20 # in GeV # the min track momentum cut during the track finding. # Brunel v47r9 Brunel().RecoSequence = [ - "Decoding", "VELO", "TT", "IT", "OT", "TrHLT1", "Vertex", "TrHLT2", "RICH" + "Decoding", + "VELO", + "TT", + "IT", + "OT", + "TrHLT1", + "Vertex", + "TrHLT2", + "RICH", ] -from Configurables import TrackSys, PatForward, PatForwardTool -TrackSys().setProp("TrackPatRecAlgorithms", - ["FastVelo", "VeloTT", "ForwardHLT1", "ForwardHLT2"]) +from Configurables import PatForward, PatForwardTool, TrackSys + +TrackSys().setProp( + "TrackPatRecAlgorithms", ["FastVelo", "VeloTT", "ForwardHLT1", "ForwardHLT2"] +) from Gaudi.Configuration import appendPostConfigAction def changeP(): PatForward("PatForwardHLT1").addTool(PatForwardTool) - PatForward( - "PatForwardHLT1").PatForwardTool.MinMomentum = minP * 1000 # in MeV + PatForward("PatForwardHLT1").PatForwardTool.MinMomentum = minP * 1000 # in MeV PatForward("PatForwardHLT2").addTool(PatForwardTool) - PatForward( - "PatForwardHLT2").PatForwardTool.MinMomentum = minP * 1000 # in MeV + PatForward("PatForwardHLT2").PatForwardTool.MinMomentum = minP * 1000 # in MeV appendPostConfigAction(changeP) # Brunel v47r5 -#Brunel().RecoSequence = ["Decoding","VELO","TT","IT","OT","Tr","RICH"] -#from Configurables import TrackSys, PatForward, PatForwardTool -#TrackSys().setProp( "TrackPatRecAlgorithms", ["FastVelo","Forward"] ) -#PatForward("PatForward").addTool(PatForwardTool) -#PatForward("PatForward").PatForwardTool.MinMomentum = minP * 1000 # in MeV +# Brunel().RecoSequence = ["Decoding","VELO","TT","IT","OT","Tr","RICH"] +# from Configurables import TrackSys, PatForward, PatForwardTool +# TrackSys().setProp( "TrackPatRecAlgorithms", ["FastVelo","Forward"] ) +# PatForward("PatForward").addTool(PatForwardTool) +# PatForward("PatForward").PatForwardTool.MinMomentum = minP * 1000 # in MeV # 2015-04-28 For future reference, these next lines can make *cuts* on Eta and Phi ranges # We are *not using these now* but may do so in the future, if we choose to emulate @@ -104,19 +118,14 @@ rConf.photonConfig().SelectionMode = "Loose" rConf.Radiators = ["Rich1Gas"] # only Long tracks with P > 10GeV rConf.trackConfig().TrackCuts = { - "Forward": { - "Chi2Cut": [0, 5], - "PCut": [minP, 9999999] - }, - "Match": { - "Chi2Cut": [0, 5], - "PCut": [minP, 9999999] - } + "Forward": {"Chi2Cut": [0, 5], "PCut": [minP, 9999999]}, + "Match": {"Chi2Cut": [0, 5], "PCut": [minP, 9999999]}, } # Turn off trackless ring finding rConf.TracklessRingAlgs = [] from Configurables import RichRecQCConf + # disable monitors that are enabled by default in "OfflineFull" mode, # except "AlignmentMonitoring" RichRecQCConf("OfflineRichMoni").removeMonitor("L1SizeMonitoring") @@ -130,7 +139,7 @@ RichRecQCConf("OfflineRichMoni").removeMonitor("TracklessRingAngles") RichRecQCConf("OfflineRichMoni").removeMonitor("TracklessRingPeakSearch") RichRecQCConf("OfflineRichMoni").removeMonitor("HPDImageShifts") RichRecQCConf("OfflineRichMoni").removeMonitor("DataDecodingErrors") -#RichRecQCConf ("OfflineRichMoni").removeMonitor("AlignmentMonitoring" ) +# RichRecQCConf ("OfflineRichMoni").removeMonitor("AlignmentMonitoring" ) RichRecQCConf("OfflineRichMoni").removeMonitor("HPDIFBMonitoring") RichRecQCConf("OfflineRichMoni").removeMonitor("RichPixelPositions") RichRecQCConf("OfflineRichMoni").removeMonitor("HPDHitPlots") @@ -149,39 +158,43 @@ RichRecQCConf("OfflineRichMoni").removeMonitor("RichDataObjectChecks") RichRecQCConf("OfflineRichMoni").removeMonitor("RichRecoTiming") # disable producing NTuple -#RichRecQCConf ("OfflineRichMoni").setProp("NTupleProduce", False ) +# RichRecQCConf ("OfflineRichMoni").setProp("NTupleProduce", False ) from Configurables import RichAlignmentConf + # choose RICH you want -#RichAlignmentConf("OfflineRichMoni_RichAlignmentConf").setProp("Radiators", ["Rich1Gas"]) +# RichAlignmentConf("OfflineRichMoni_RichAlignmentConf").setProp("Radiators", ["Rich1Gas"]) RichAlign = RichAlignmentConf("OfflineRichMoni_RichAlignmentConf") RichAlign.Radiators = ["Rich1Gas"] RichAlign.HPDList = [[0], [0], [0]] RichAlign.Histograms = "Expert" -#RichAlign.VetoedHPDs = [100309] +# RichAlign.VetoedHPDs = [100309] RichAlign.NTupleProduce = False RichAlign.R1NTupleProduce = False # activate long list of segment combination histos to be prebooked for RICH2 # this may propagate from the Brunel Cofiguration, though -#RichAlignmentConf("OfflineRichMoni_RichAlignmentConf").setProp("Histograms", "OfflineExpress") +# RichAlignmentConf("OfflineRichMoni_RichAlignmentConf").setProp("Histograms", "OfflineExpress") ############################################################################## -#from Configurables import DstConf +# from Configurables import DstConf ## enable DST unpacking: needed to get tracks -#ApplicationMgr ().ExtSvc += ["DataOnDemandSvc"] -#DstConf ().EnableUnpack = True +# ApplicationMgr ().ExtSvc += ["DataOnDemandSvc"] +# DstConf ().EnableUnpack = True ############################################################################## -from Configurables import LHCbApp # db tags -#LHCbApp().DDDBtag = "head-20100407" -#LHCbApp().CondDBtag = "head-20100408" +# LHCbApp().DDDBtag = "head-20100407" +# LHCbApp().CondDBtag = "head-20100408" ############################################################################## -from Configurables import CondDB -from Configurables import CondDBAccessSvc -from Configurables import ApplicationMgr -from Configurables import HistogramPersistencySvc -#OutputStream("DstWriter").Output = "DATAFILE='Alignment.dst' TYP='POOL_ROOTTREE' OPT='REC'" +from Configurables import ( + ApplicationMgr, + CondDB, + CondDBAccessSvc, + HistogramPersistencySvc, + LHCbApp, +) + +# OutputStream("DstWriter").Output = "DATAFILE='Alignment.dst' TYP='POOL_ROOTTREE' OPT='REC'" NTupleSvc().Output = [ "RICHTUPLE1 DATAFILE='Ntuple_2015-Collisions.root' TYP='ROOT' OPT='NEW'" ] diff --git a/Rich/RichMirrorAlignmentGanga/options/Brunel_Rich2AlignMoni_Collision10-DST.py b/Rich/RichMirrorAlignmentGanga/options/Brunel_Rich2AlignMoni_Collision10-DST.py index 2ec9dd65ade765425ff426df35515f08f454c2dc..760dad8b09c9e791e0c5f3af6e2bb429b1bb076d 100644 --- a/Rich/RichMirrorAlignmentGanga/options/Brunel_Rich2AlignMoni_Collision10-DST.py +++ b/Rich/RichMirrorAlignmentGanga/options/Brunel_Rich2AlignMoni_Collision10-DST.py @@ -9,32 +9,38 @@ # or submit itself to any jurisdiction. # ############################################################################### from Brunel.Configuration import * + ############################################################################### from GaudiKernel.ProcessJobOptions import importOptions -#importOptions ("$APPCONFIGOPTS/Brunel/earlyData.py") # comment this to make it work! + +# importOptions ("$APPCONFIGOPTS/Brunel/earlyData.py") # comment this to make it work! importOptions("$APPCONFIGOPTS/Brunel/DataType-2010.py") -#importOptions("$APPCONFIGOPTS/UseOracle.py") -#importOptions("$APPCONFIGOPTS/DisableLFC.py") +# importOptions("$APPCONFIGOPTS/UseOracle.py") +# importOptions("$APPCONFIGOPTS/DisableLFC.py") ############################################################################### from Configurables import MessageSvc + MessageSvc().Format = "% F%30W%S%7W%R%T %0W%M" -#MessageSvc().OutputLevel = 7 +# MessageSvc().OutputLevel = 7 from Configurables import Brunel + Brunel().EvtMax = 10 Brunel().PrintFreq = 1 Brunel().OutputType = "None" # reconstruct RICH only Brunel().InitSequence = ["Brunel"] Brunel().RecoSequence = ["RICH"] -#Brunel().MCCheckSequence = ["RICH"] # only when WithTruth +# Brunel().MCCheckSequence = ["RICH"] # only when WithTruth Brunel().Histograms = "OfflineExpress" # propagates down to Alignment from Configurables import RecMoniConf + # RecMoniConf is defined in REC/REC_vXrY/RecSys/python/RecSys/Configuration.py RecMoniConf().MoniSequence = ["RICH"] ############################################################################## from Configurables import RichRecSysConf + rConf = RichRecSysConf("RichOfflineRec") # disable PID rConf.setProp("PidConfig", "None") @@ -48,14 +54,8 @@ rConf.photonConfig().SelectionMode = "Loose" rConf.Radiators = ["Rich2Gas"] # only Long tracks with P > 10GeV rConf.trackConfig().TrackCuts = { - "Forward": { - "Chi2Cut": [0, 5], - "PCut": [10.0, 9999999] - }, - "Match": { - "Chi2Cut": [0, 5], - "PCut": [10.0, 9999999] - } + "Forward": {"Chi2Cut": [0, 5], "PCut": [10.0, 9999999]}, + "Match": {"Chi2Cut": [0, 5], "PCut": [10.0, 9999999]}, } # Turn off trackless ring finding rConf.TracklessRingAlgs = [] @@ -63,6 +63,7 @@ rConf.TracklessRingAlgs = [] rConf.RefitTracks = True from Configurables import RichRecQCConf + # disable monitors that are enabled by default in "OfflineFull" mode, # except "AlignmentMonitoring" RichRecQCConf("OfflineRichMoni").removeMonitor("L1SizeMonitoring") @@ -76,7 +77,7 @@ RichRecQCConf("OfflineRichMoni").removeMonitor("TracklessRingAngles") RichRecQCConf("OfflineRichMoni").removeMonitor("TracklessRingPeakSearch") RichRecQCConf("OfflineRichMoni").removeMonitor("HPDImageShifts") RichRecQCConf("OfflineRichMoni").removeMonitor("DataDecodingErrors") -#RichRecQCConf("OfflineRichMoni").removeMonitor("AlignmentMonitoring" ) +# RichRecQCConf("OfflineRichMoni").removeMonitor("AlignmentMonitoring" ) RichRecQCConf("OfflineRichMoni").removeMonitor("HPDIFBMonitoring") RichRecQCConf("OfflineRichMoni").removeMonitor("RichPixelPositions") RichRecQCConf("OfflineRichMoni").removeMonitor("HPDHitPlots") @@ -98,26 +99,25 @@ RichRecQCConf("OfflineRichMoni").removeMonitor("RichRecoTiming") RichRecQCConf("OfflineRichMoni").setProp("NTupleProduce", False) from Configurables import RichAlignmentConf + # choose RICH you want -#RichAlignmentConf("OfflineRichMoni_RichAlignmentConf").setProp("Radiators", ["Rich1Gas"]) +# RichAlignmentConf("OfflineRichMoni_RichAlignmentConf").setProp("Radiators", ["Rich1Gas"]) RichAlignmentConf("OfflineRichMoni_RichAlignmentConf").setProp( - "Radiators", ["Rich2Gas"]) + "Radiators", ["Rich2Gas"] +) # activate long list of segment combination histos to be prebooked for RICH2 # this may propagate from the Brunel Cofiguration, though -#RichAlignmentConf("OfflineRichMoni_RichAlignmentConf").setProp("Histograms", "OfflineExpress") +# RichAlignmentConf("OfflineRichMoni_RichAlignmentConf").setProp("Histograms", "OfflineExpress") ############################################################################## from Configurables import DstConf + # enable DST unpacking: needed to get tracks ApplicationMgr().ExtSvc += ["DataOnDemandSvc"] DstConf().EnableUnpack = ["Reconstruction"] ############################################################################## -from Configurables import LHCbApp # db tags -#LHCbApp().DDDBtag = "head-20100407" -#LHCbApp().CondDBtag = "head-20100408" +# LHCbApp().DDDBtag = "head-20100407" +# LHCbApp().CondDBtag = "head-20100408" ############################################################################## -from Configurables import CondDB -from Configurables import CondDBAccessSvc - -from Configurables import CondDB, CondDBAccessSvc +from Configurables import CondDB, CondDBAccessSvc, LHCbApp diff --git a/Rich/RichMirrorAlignmentGanga/options/Brunel_Rich2AlignMoni_Collision11-RAW.py b/Rich/RichMirrorAlignmentGanga/options/Brunel_Rich2AlignMoni_Collision11-RAW.py index 593b4d1c776d671d3a54ff6b8f9d07ed87958ab5..c2e727b1921adfa90dacc2b866fb3b90106f1216 100644 --- a/Rich/RichMirrorAlignmentGanga/options/Brunel_Rich2AlignMoni_Collision11-RAW.py +++ b/Rich/RichMirrorAlignmentGanga/options/Brunel_Rich2AlignMoni_Collision11-RAW.py @@ -9,48 +9,52 @@ # or submit itself to any jurisdiction. # ############################################################################### from Brunel.Configuration import * + ############################################################################### from GaudiKernel.ProcessJobOptions import importOptions -#importOptions ("$APPCONFIGOPTS/Brunel/earlyData.py") + +# importOptions ("$APPCONFIGOPTS/Brunel/earlyData.py") importOptions("$APPCONFIGOPTS/Brunel/DataType-2012.py") -#importOptions("$APPCONFIGOPTS/UseOracle.py") -#importOptions("$APPCONFIGOPTS/DisableLFC.py") +# importOptions("$APPCONFIGOPTS/UseOracle.py") +# importOptions("$APPCONFIGOPTS/DisableLFC.py") ############################################################################### from Configurables import MessageSvc + MessageSvc().Format = "% F%30W%S%7W%R%T %0W%M" -#MessageSvc().OutputLevel = 7 +# MessageSvc().OutputLevel = 7 from Configurables import Brunel + Brunel().EvtMax = 1000 Brunel().PrintFreq = 10 Brunel().OutputType = "None" -#--Again the Database problem... -#from Configurables import CondDB, LHCbApp -#CondDB(UseOracle = True) -#LHCbApp().DDDBtag ="head-20110302" -#LHCbApp().CondDBtag="head-20110318" +# --Again the Database problem... +# from Configurables import CondDB, LHCbApp +# CondDB(UseOracle = True) +# LHCbApp().DDDBtag ="head-20110302" +# LHCbApp().CondDBtag="head-20110318" # reconstruct RICH only -#Brunel ().InitSequence = ["Brunel"] -Brunel().RecoSequence = [ - "Decoding", "VELO", "TT", "IT", "OT", "Tr", "Vertex", "RICH" -] +# Brunel ().InitSequence = ["Brunel"] +Brunel().RecoSequence = ["Decoding", "VELO", "TT", "IT", "OT", "Tr", "Vertex", "RICH"] -#Brunel ().RecoSequence = ["RICH"] -#Brunel().MCCheckSequence = ["RICH"] # only when WithTruth +# Brunel ().RecoSequence = ["RICH"] +# Brunel().MCCheckSequence = ["RICH"] # only when WithTruth Brunel().Histograms = "Expert" # propagates down to Alignment -#Brunel ().Histograms = "None" +# Brunel ().Histograms = "None" Brunel().DataType = "2012" -#from Configurables import EventClockSvc -#EventClockSvc( InitialTime = 1341100800000000000 ) # 1st July 2012 +# from Configurables import EventClockSvc +# EventClockSvc( InitialTime = 1341100800000000000 ) # 1st July 2012 from Configurables import RecMoniConf + # RecMoniConf is defined in REC/REC_vXrY/RecSys/python/RecSys/Configuration.py RecMoniConf().MoniSequence = ["RICH"] ############################################################################## from Configurables import RichRecSysConf + rConf = RichRecSysConf("RichOfflineRec") # disable PID rConf.setProp("PidConfig", "None") @@ -60,7 +64,8 @@ minP = 40 # in GeV # Tweak the tracking to only run the Forward tracking, and to apply # the min track momentum cut during the track finding. -from Configurables import TrackSys, PatForward, PatForwardTool +from Configurables import PatForward, PatForwardTool, TrackSys + TrackSys().setProp("TrackPatRecAlgorithms", ["FastVelo", "Forward"]) PatForward("PatForward").addTool(PatForwardTool) PatForward("PatForward").PatForwardTool.MinMomentum = minP * 1000 # in MeV @@ -74,19 +79,14 @@ rConf.photonConfig().SelectionMode = "Loose" rConf.Radiators = ["Rich2Gas"] # only Long tracks with P > 10GeV rConf.trackConfig().TrackCuts = { - "Forward": { - "Chi2Cut": [0, 5], - "PCut": [minP, 9999999] - }, - "Match": { - "Chi2Cut": [0, 5], - "PCut": [minP, 9999999] - } + "Forward": {"Chi2Cut": [0, 5], "PCut": [minP, 9999999]}, + "Match": {"Chi2Cut": [0, 5], "PCut": [minP, 9999999]}, } # Turn off trackless ring finding rConf.TracklessRingAlgs = [] from Configurables import RichRecQCConf + # disable monitors that are enabled by default in "OfflineFull" mode, # except "AlignmentMonitoring" RichRecQCConf("OfflineRichMoni").removeMonitor("L1SizeMonitoring") @@ -100,7 +100,7 @@ RichRecQCConf("OfflineRichMoni").removeMonitor("TracklessRingAngles") RichRecQCConf("OfflineRichMoni").removeMonitor("TracklessRingPeakSearch") RichRecQCConf("OfflineRichMoni").removeMonitor("HPDImageShifts") RichRecQCConf("OfflineRichMoni").removeMonitor("DataDecodingErrors") -#RichRecQCConf ("OfflineRichMoni").removeMonitor("AlignmentMonitoring" ) +# RichRecQCConf ("OfflineRichMoni").removeMonitor("AlignmentMonitoring" ) RichRecQCConf("OfflineRichMoni").removeMonitor("HPDIFBMonitoring") RichRecQCConf("OfflineRichMoni").removeMonitor("RichPixelPositions") RichRecQCConf("OfflineRichMoni").removeMonitor("HPDHitPlots") @@ -119,39 +119,43 @@ RichRecQCConf("OfflineRichMoni").removeMonitor("RichDataObjectChecks") RichRecQCConf("OfflineRichMoni").removeMonitor("RichRecoTiming") # disable producing NTuple -#RichRecQCConf ("OfflineRichMoni").setProp("NTupleProduce", False ) +# RichRecQCConf ("OfflineRichMoni").setProp("NTupleProduce", False ) from Configurables import RichAlignmentConf + # choose RICH you want -#RichAlignmentConf("OfflineRichMoni_RichAlignmentConf").setProp("Radiators", ["Rich1Gas"]) +# RichAlignmentConf("OfflineRichMoni_RichAlignmentConf").setProp("Radiators", ["Rich1Gas"]) RichAlign = RichAlignmentConf("OfflineRichMoni_RichAlignmentConf") RichAlign.Radiators = ["Rich2Gas"] RichAlign.HPDList = [[0], [0], [0]] RichAlign.Histograms = "Expert" -#RichAlign.VetoedHPDs = [100309] +# RichAlign.VetoedHPDs = [100309] RichAlign.NTupleProduce = False RichAlign.R1NTupleProduce = False # activate long list of segment combination histos to be prebooked for RICH2 # this may propagate from the Brunel Cofiguration, though -#RichAlignmentConf("OfflineRichMoni_RichAlignmentConf").setProp("Histograms", "OfflineExpress") +# RichAlignmentConf("OfflineRichMoni_RichAlignmentConf").setProp("Histograms", "OfflineExpress") ############################################################################## -#from Configurables import DstConf +# from Configurables import DstConf ## enable DST unpacking: needed to get tracks -#ApplicationMgr ().ExtSvc += ["DataOnDemandSvc"] -#DstConf ().EnableUnpack = True +# ApplicationMgr ().ExtSvc += ["DataOnDemandSvc"] +# DstConf ().EnableUnpack = True ############################################################################## -from Configurables import LHCbApp # db tags -#LHCbApp().DDDBtag = "head-20100407" -#LHCbApp().CondDBtag = "head-20100408" +# LHCbApp().DDDBtag = "head-20100407" +# LHCbApp().CondDBtag = "head-20100408" ############################################################################## -from Configurables import CondDB -from Configurables import CondDBAccessSvc -from Configurables import ApplicationMgr -from Configurables import HistogramPersistencySvc -#OutputStream("DstWriter").Output = "DATAFILE='Alignment.dst' TYP='POOL_ROOTTREE' OPT='REC'" +from Configurables import ( + ApplicationMgr, + CondDB, + CondDBAccessSvc, + HistogramPersistencySvc, + LHCbApp, +) + +# OutputStream("DstWriter").Output = "DATAFILE='Alignment.dst' TYP='POOL_ROOTTREE' OPT='REC'" NTupleSvc().Output = [ "RICHTUPLE1 DATAFILE='Ntuple_2012-Collisions.root' TYP='ROOT' OPT='NEW'" ] diff --git a/Rich/RichMirrorAlignmentGanga/options/Brunel_Rich2AlignMoni_Collision12-DST.py b/Rich/RichMirrorAlignmentGanga/options/Brunel_Rich2AlignMoni_Collision12-DST.py index 94264890da76360c212ae13a616c18cf4bb6e782..95369d9067d61002358c091713b6fcaf166290bc 100644 --- a/Rich/RichMirrorAlignmentGanga/options/Brunel_Rich2AlignMoni_Collision12-DST.py +++ b/Rich/RichMirrorAlignmentGanga/options/Brunel_Rich2AlignMoni_Collision12-DST.py @@ -9,41 +9,43 @@ # or submit itself to any jurisdiction. # ############################################################################### from Brunel.Configuration import * + ############################################################################### from GaudiKernel.ProcessJobOptions import importOptions -#importOptions ("$APPCONFIGOPTS/Brunel/earlyData.py") + +# importOptions ("$APPCONFIGOPTS/Brunel/earlyData.py") importOptions("$APPCONFIGOPTS/Brunel/DataType-2012.py") -#importOptions("$APPCONFIGOPTS/UseOracle.py") -#importOptions("$APPCONFIGOPTS/DisableLFC.py") +# importOptions("$APPCONFIGOPTS/UseOracle.py") +# importOptions("$APPCONFIGOPTS/DisableLFC.py") ############################################################################### from Configurables import MessageSvc + MessageSvc().Format = "% F%30W%S%7W%R%T %0W%M" -#MessageSvc().OutputLevel = 7 +# MessageSvc().OutputLevel = 7 from Configurables import Brunel + Brunel().EvtMax = 1000 Brunel().PrintFreq = 10 Brunel().OutputType = "None" -#--Again the Database problem... -#from Configurables import CondDB, LHCbApp -#CondDB(UseOracle = True) -#LHCbApp().DDDBtag ="head-20110302" -#LHCbApp().CondDBtag="head-20110318" +# --Again the Database problem... +# from Configurables import CondDB, LHCbApp +# CondDB(UseOracle = True) +# LHCbApp().DDDBtag ="head-20110302" +# LHCbApp().CondDBtag="head-20110318" # reconstruct RICH only -#Brunel ().InitSequence = ["Brunel"] -Brunel().RecoSequence = [ - "Decoding", "VELO", "TT", "IT", "OT", "Tr", "Vertex", "RICH" -] +# Brunel ().InitSequence = ["Brunel"] +Brunel().RecoSequence = ["Decoding", "VELO", "TT", "IT", "OT", "Tr", "Vertex", "RICH"] -#Brunel ().RecoSequence = ["RICH"] -#Brunel().MCCheckSequence = ["RICH"] # only when WithTruth +# Brunel ().RecoSequence = ["RICH"] +# Brunel().MCCheckSequence = ["RICH"] # only when WithTruth Brunel().Histograms = "Expert" # propagates down to Alignment -#Brunel ().Histograms = "None" +# Brunel ().Histograms = "None" Brunel().DataType = "2012" -#DST +# DST Brunel().WithMC = False # with MC truth automatically invokes Simulation Brunel().InputType = "DST" Brunel().Persistency = "ROOT" @@ -52,10 +54,12 @@ Brunel().InitSequence = ["Brunel"] Brunel().RecoSequence = ["RICH"] from Configurables import RecMoniConf + # RecMoniConf is defined in REC/REC_vXrY/RecSys/python/RecSys/Configuration.py RecMoniConf().MoniSequence = ["RICH"] ############################################################################## from Configurables import RichRecSysConf + rConf = RichRecSysConf("RichOfflineRec") # disable PID rConf.setProp("PidConfig", "None") @@ -66,7 +70,8 @@ minP = 40 # in GeV # DST - PN - Not sure what effect this will have for DST, if any... but leaving it in # Tweak the tracking to only run the Forward tracking, and to apply # the min track momentum cut during the track finding. -from Configurables import TrackSys, PatForward, PatForwardTool +from Configurables import PatForward, PatForwardTool, TrackSys + TrackSys().setProp("TrackPatRecAlgorithms", ["FastVelo", "Forward"]) PatForward("PatForward").addTool(PatForwardTool) PatForward("PatForward").PatForwardTool.MinMomentum = minP * 1000 # in MeV @@ -92,14 +97,8 @@ rConf.photonConfig().SelectionMode = "Loose" rConf.Radiators = ["Rich2Gas"] # only Long tracks with P > 10GeV rConf.trackConfig().TrackCuts = { - "Forward": { - "Chi2Cut": [0, 5], - "PCut": [minP, 9999999] - }, - "Match": { - "Chi2Cut": [0, 5], - "PCut": [minP, 9999999] - } + "Forward": {"Chi2Cut": [0, 5], "PCut": [minP, 9999999]}, + "Match": {"Chi2Cut": [0, 5], "PCut": [minP, 9999999]}, } # Turn off trackless ring finding rConf.TracklessRingAlgs = [] @@ -108,6 +107,7 @@ rConf.TracklessRingAlgs = [] rConf.RefitTracks = True from Configurables import RichRecQCConf + # disable monitors that are enabled by default in "OfflineFull" mode, # except "AlignmentMonitoring" RichRecQCConf("OfflineRichMoni").removeMonitor("L1SizeMonitoring") @@ -121,7 +121,7 @@ RichRecQCConf("OfflineRichMoni").removeMonitor("TracklessRingAngles") RichRecQCConf("OfflineRichMoni").removeMonitor("TracklessRingPeakSearch") RichRecQCConf("OfflineRichMoni").removeMonitor("HPDImageShifts") RichRecQCConf("OfflineRichMoni").removeMonitor("DataDecodingErrors") -#RichRecQCConf ("OfflineRichMoni").removeMonitor("AlignmentMonitoring" ) +# RichRecQCConf ("OfflineRichMoni").removeMonitor("AlignmentMonitoring" ) RichRecQCConf("OfflineRichMoni").removeMonitor("HPDIFBMonitoring") RichRecQCConf("OfflineRichMoni").removeMonitor("RichPixelPositions") RichRecQCConf("OfflineRichMoni").removeMonitor("HPDHitPlots") @@ -140,42 +140,47 @@ RichRecQCConf("OfflineRichMoni").removeMonitor("RichDataObjectChecks") RichRecQCConf("OfflineRichMoni").removeMonitor("RichRecoTiming") # disable producing NTuple (PN- this was on in the older DST options, but I think we don't need it) -#RichRecQCConf ("OfflineRichMoni").setProp("NTupleProduce", False ) +# RichRecQCConf ("OfflineRichMoni").setProp("NTupleProduce", False ) -#DST: PN: OK, for some reason these are commented out in the old DST options. I leave it in. I don't see the harm, yet +# DST: PN: OK, for some reason these are commented out in the old DST options. I leave it in. I don't see the harm, yet from Configurables import RichAlignmentConf + # choose RICH you want -#RichAlignmentConf("OfflineRichMoni_RichAlignmentConf").setProp("Radiators", ["Rich1Gas"]) +# RichAlignmentConf("OfflineRichMoni_RichAlignmentConf").setProp("Radiators", ["Rich1Gas"]) RichAlign = RichAlignmentConf("OfflineRichMoni_RichAlignmentConf") RichAlign.Radiators = ["Rich2Gas"] RichAlign.HPDList = [[0], [0], [0]] RichAlign.Histograms = "Expert" -#RichAlign.VetoedHPDs = [100309] +# RichAlign.VetoedHPDs = [100309] RichAlign.NTupleProduce = False RichAlign.R1NTupleProduce = False # activate long list of segment combination histos to be prebooked for RICH2 # this may propagate from the Brunel Cofiguration, though -#RichAlignmentConf("OfflineRichMoni_RichAlignmentConf").setProp("Histograms", "OfflineExpress") +# RichAlignmentConf("OfflineRichMoni_RichAlignmentConf").setProp("Histograms", "OfflineExpress") ############################################################################## # DST from Configurables import DstConf + # enable DST unpacking: needed to get tracks ApplicationMgr().ExtSvc += ["DataOnDemandSvc"] DstConf().EnableUnpack = True ############################################################################## -from Configurables import LHCbApp # db tags -#LHCbApp().DDDBtag = "head-20100407" -#LHCbApp().CondDBtag = "head-20100408" +# LHCbApp().DDDBtag = "head-20100407" +# LHCbApp().CondDBtag = "head-20100408" ############################################################################## -from Configurables import CondDB -from Configurables import CondDBAccessSvc -#DST - PN - these were commented out in the DST options. I don't see the harm in leaving them in -from Configurables import ApplicationMgr -from Configurables import HistogramPersistencySvc -#OutputStream("DstWriter").Output = "DATAFILE='Alignment.dst' TYP='POOL_ROOTTREE' OPT='REC'" +# DST - PN - these were commented out in the DST options. I don't see the harm in leaving them in +from Configurables import ( + ApplicationMgr, + CondDB, + CondDBAccessSvc, + HistogramPersistencySvc, + LHCbApp, +) + +# OutputStream("DstWriter").Output = "DATAFILE='Alignment.dst' TYP='POOL_ROOTTREE' OPT='REC'" NTupleSvc().Output = [ "RICHTUPLE1 DATAFILE='Ntuple_2012-Collisions.root' TYP='ROOT' OPT='NEW'" ] diff --git a/Rich/RichMirrorAlignmentGanga/options/Brunel_Rich2AlignMoni_Collision12-RAW.py b/Rich/RichMirrorAlignmentGanga/options/Brunel_Rich2AlignMoni_Collision12-RAW.py index 39ef9a0cd21baea9740bcd241b9522a0057cca69..b1e54d176d55869999e6270e3382dbcb16435d5f 100644 --- a/Rich/RichMirrorAlignmentGanga/options/Brunel_Rich2AlignMoni_Collision12-RAW.py +++ b/Rich/RichMirrorAlignmentGanga/options/Brunel_Rich2AlignMoni_Collision12-RAW.py @@ -9,45 +9,49 @@ # or submit itself to any jurisdiction. # ############################################################################### from Brunel.Configuration import * + ############################################################################### from GaudiKernel.ProcessJobOptions import importOptions -#importOptions ("$APPCONFIGOPTS/Brunel/earlyData.py") + +# importOptions ("$APPCONFIGOPTS/Brunel/earlyData.py") importOptions("$APPCONFIGOPTS/Brunel/DataType-2012.py") -#importOptions("$APPCONFIGOPTS/UseOracle.py") -#importOptions("$APPCONFIGOPTS/DisableLFC.py") +# importOptions("$APPCONFIGOPTS/UseOracle.py") +# importOptions("$APPCONFIGOPTS/DisableLFC.py") ############################################################################### from Configurables import MessageSvc + MessageSvc().Format = "% F%30W%S%7W%R%T %0W%M" -#MessageSvc().OutputLevel = 7 +# MessageSvc().OutputLevel = 7 from Configurables import Brunel + Brunel().EvtMax = 1000 Brunel().PrintFreq = 10 Brunel().OutputType = "None" -#--Again the Database problem... -#from Configurables import CondDB, LHCbApp -#CondDB(UseOracle = True) -#LHCbApp().DDDBtag ="head-20110302" -#LHCbApp().CondDBtag="head-20110318" +# --Again the Database problem... +# from Configurables import CondDB, LHCbApp +# CondDB(UseOracle = True) +# LHCbApp().DDDBtag ="head-20110302" +# LHCbApp().CondDBtag="head-20110318" # reconstruct RICH only -#Brunel ().InitSequence = ["Brunel"] -Brunel().RecoSequence = [ - "Decoding", "VELO", "TT", "IT", "OT", "Tr", "Vertex", "RICH" -] +# Brunel ().InitSequence = ["Brunel"] +Brunel().RecoSequence = ["Decoding", "VELO", "TT", "IT", "OT", "Tr", "Vertex", "RICH"] -#Brunel ().RecoSequence = ["RICH"] -#Brunel().MCCheckSequence = ["RICH"] # only when WithTruth +# Brunel ().RecoSequence = ["RICH"] +# Brunel().MCCheckSequence = ["RICH"] # only when WithTruth Brunel().Histograms = "Expert" # propagates down to Alignment -#Brunel ().Histograms = "None" +# Brunel ().Histograms = "None" Brunel().DataType = "2012" from Configurables import RecMoniConf + # RecMoniConf is defined in REC/REC_vXrY/RecSys/python/RecSys/Configuration.py RecMoniConf().MoniSequence = ["RICH"] ############################################################################## from Configurables import RichRecSysConf + rConf = RichRecSysConf("RichOfflineRec") # disable PID rConf.setProp("PidConfig", "None") @@ -57,7 +61,8 @@ minP = 40 # in GeV # Tweak the tracking to only run the Forward tracking, and to apply # the min track momentum cut during the track finding. -from Configurables import TrackSys, PatForward, PatForwardTool +from Configurables import PatForward, PatForwardTool, TrackSys + TrackSys().setProp("TrackPatRecAlgorithms", ["FastVelo", "Forward"]) PatForward("PatForward").addTool(PatForwardTool) PatForward("PatForward").PatForwardTool.MinMomentum = minP * 1000 # in MeV @@ -83,19 +88,14 @@ rConf.photonConfig().SelectionMode = "Loose" rConf.Radiators = ["Rich2Gas"] # only Long tracks with P > 10GeV rConf.trackConfig().TrackCuts = { - "Forward": { - "Chi2Cut": [0, 5], - "PCut": [minP, 9999999] - }, - "Match": { - "Chi2Cut": [0, 5], - "PCut": [minP, 9999999] - } + "Forward": {"Chi2Cut": [0, 5], "PCut": [minP, 9999999]}, + "Match": {"Chi2Cut": [0, 5], "PCut": [minP, 9999999]}, } # Turn off trackless ring finding rConf.TracklessRingAlgs = [] from Configurables import RichRecQCConf + # disable monitors that are enabled by default in "OfflineFull" mode, # except "AlignmentMonitoring" RichRecQCConf("OfflineRichMoni").removeMonitor("L1SizeMonitoring") @@ -109,7 +109,7 @@ RichRecQCConf("OfflineRichMoni").removeMonitor("TracklessRingAngles") RichRecQCConf("OfflineRichMoni").removeMonitor("TracklessRingPeakSearch") RichRecQCConf("OfflineRichMoni").removeMonitor("HPDImageShifts") RichRecQCConf("OfflineRichMoni").removeMonitor("DataDecodingErrors") -#RichRecQCConf ("OfflineRichMoni").removeMonitor("AlignmentMonitoring" ) +# RichRecQCConf ("OfflineRichMoni").removeMonitor("AlignmentMonitoring" ) RichRecQCConf("OfflineRichMoni").removeMonitor("HPDIFBMonitoring") RichRecQCConf("OfflineRichMoni").removeMonitor("RichPixelPositions") RichRecQCConf("OfflineRichMoni").removeMonitor("HPDHitPlots") @@ -128,39 +128,43 @@ RichRecQCConf("OfflineRichMoni").removeMonitor("RichDataObjectChecks") RichRecQCConf("OfflineRichMoni").removeMonitor("RichRecoTiming") # disable producing NTuple -#RichRecQCConf ("OfflineRichMoni").setProp("NTupleProduce", False ) +# RichRecQCConf ("OfflineRichMoni").setProp("NTupleProduce", False ) from Configurables import RichAlignmentConf + # choose RICH you want -#RichAlignmentConf("OfflineRichMoni_RichAlignmentConf").setProp("Radiators", ["Rich1Gas"]) +# RichAlignmentConf("OfflineRichMoni_RichAlignmentConf").setProp("Radiators", ["Rich1Gas"]) RichAlign = RichAlignmentConf("OfflineRichMoni_RichAlignmentConf") RichAlign.Radiators = ["Rich2Gas"] RichAlign.HPDList = [[0], [0], [0]] RichAlign.Histograms = "Expert" -#RichAlign.VetoedHPDs = [100309] +# RichAlign.VetoedHPDs = [100309] RichAlign.NTupleProduce = False RichAlign.R1NTupleProduce = False # activate long list of segment combination histos to be prebooked for RICH2 # this may propagate from the Brunel Cofiguration, though -#RichAlignmentConf("OfflineRichMoni_RichAlignmentConf").setProp("Histograms", "OfflineExpress") +# RichAlignmentConf("OfflineRichMoni_RichAlignmentConf").setProp("Histograms", "OfflineExpress") ############################################################################## -#from Configurables import DstConf +# from Configurables import DstConf ## enable DST unpacking: needed to get tracks -#ApplicationMgr ().ExtSvc += ["DataOnDemandSvc"] -#DstConf ().EnableUnpack = True +# ApplicationMgr ().ExtSvc += ["DataOnDemandSvc"] +# DstConf ().EnableUnpack = True ############################################################################## -from Configurables import LHCbApp # db tags -#LHCbApp().DDDBtag = "head-20100407" -#LHCbApp().CondDBtag = "head-20100408" +# LHCbApp().DDDBtag = "head-20100407" +# LHCbApp().CondDBtag = "head-20100408" ############################################################################## -from Configurables import CondDB -from Configurables import CondDBAccessSvc -from Configurables import ApplicationMgr -from Configurables import HistogramPersistencySvc -#OutputStream("DstWriter").Output = "DATAFILE='Alignment.dst' TYP='POOL_ROOTTREE' OPT='REC'" +from Configurables import ( + ApplicationMgr, + CondDB, + CondDBAccessSvc, + HistogramPersistencySvc, + LHCbApp, +) + +# OutputStream("DstWriter").Output = "DATAFILE='Alignment.dst' TYP='POOL_ROOTTREE' OPT='REC'" NTupleSvc().Output = [ "RICHTUPLE1 DATAFILE='Ntuple_2012-Collisions.root' TYP='ROOT' OPT='NEW'" ] diff --git a/Rich/RichMirrorAlignmentGanga/options/Brunel_Rich2AlignMoni_Collision15-RAW.py b/Rich/RichMirrorAlignmentGanga/options/Brunel_Rich2AlignMoni_Collision15-RAW.py index dd15845d302090d857fe5d02182cefb54f91034d..b11712e76aaa7d489cec539c57a133814d01c636 100644 --- a/Rich/RichMirrorAlignmentGanga/options/Brunel_Rich2AlignMoni_Collision15-RAW.py +++ b/Rich/RichMirrorAlignmentGanga/options/Brunel_Rich2AlignMoni_Collision15-RAW.py @@ -9,43 +9,49 @@ # or submit itself to any jurisdiction. # ############################################################################### from Brunel.Configuration import * + ############################################################################### from GaudiKernel.ProcessJobOptions import importOptions -#importOptions ("$APPCONFIGOPTS/Brunel/earlyData.py") + +# importOptions ("$APPCONFIGOPTS/Brunel/earlyData.py") importOptions("$APPCONFIGOPTS/Brunel/DataType-2015.py") -#importOptions("$APPCONFIGOPTS/UseOracle.py") -#importOptions("$APPCONFIGOPTS/DisableLFC.py") +# importOptions("$APPCONFIGOPTS/UseOracle.py") +# importOptions("$APPCONFIGOPTS/DisableLFC.py") ############################################################################### from Configurables import MessageSvc + MessageSvc().Format = "% F%30W%S%7W%R%T %0W%M" -#MessageSvc().OutputLevel = 7 +# MessageSvc().OutputLevel = 7 from Configurables import Brunel + Brunel().EvtMax = 1000 Brunel().PrintFreq = 10 Brunel().OutputType = "None" -#--Again the Database problem... -#from Configurables import CondDB, LHCbApp -#CondDB(UseOracle = True) -#LHCbApp().DDDBtag ="head-20110302" -#LHCbApp().CondDBtag="head-20110318" +# --Again the Database problem... +# from Configurables import CondDB, LHCbApp +# CondDB(UseOracle = True) +# LHCbApp().DDDBtag ="head-20110302" +# LHCbApp().CondDBtag="head-20110318" # reconstruct RICH only -#Brunel().InitSequence = ["Brunel"] +# Brunel().InitSequence = ["Brunel"] -#Brunel().RecoSequence = ["RICH"] ### RECO SEQUENCES NOW DEFINED BELOW! -#Brunel().MCCheckSequence = ["RICH"] # only when WithTruth +# Brunel().RecoSequence = ["RICH"] ### RECO SEQUENCES NOW DEFINED BELOW! +# Brunel().MCCheckSequence = ["RICH"] # only when WithTruth Brunel().Histograms = "Expert" # propagates down to Alignment -#Brunel().Histograms = "None" +# Brunel().Histograms = "None" Brunel().DataType = "2015" Brunel().VetoHltErrorEvents = False from Configurables import RecMoniConf + # RecMoniConf is defined in REC/REC_vXrY/RecSys/python/RecSys/Configuration.py RecMoniConf().MoniSequence = ["RICH"] ############################################################################## from Configurables import RichRecSysConf + rConf = RichRecSysConf("RichOfflineRec") # disable PID rConf.setProp("PidConfig", "None") @@ -57,31 +63,39 @@ minP = 40 # in GeV # the min track momentum cut during the track finding. # Brunel v47r9 Brunel().RecoSequence = [ - "Decoding", "VELO", "TT", "IT", "OT", "TrHLT1", "Vertex", "TrHLT2", "RICH" + "Decoding", + "VELO", + "TT", + "IT", + "OT", + "TrHLT1", + "Vertex", + "TrHLT2", + "RICH", ] -from Configurables import TrackSys, PatForward, PatForwardTool -TrackSys().setProp("TrackPatRecAlgorithms", - ["FastVelo", "VeloTT", "ForwardHLT1", "ForwardHLT2"]) +from Configurables import PatForward, PatForwardTool, TrackSys + +TrackSys().setProp( + "TrackPatRecAlgorithms", ["FastVelo", "VeloTT", "ForwardHLT1", "ForwardHLT2"] +) from Gaudi.Configuration import appendPostConfigAction def changeP(): PatForward("PatForwardHLT1").addTool(PatForwardTool) - PatForward( - "PatForwardHLT1").PatForwardTool.MinMomentum = minP * 1000 # in MeV + PatForward("PatForwardHLT1").PatForwardTool.MinMomentum = minP * 1000 # in MeV PatForward("PatForwardHLT2").addTool(PatForwardTool) - PatForward( - "PatForwardHLT2").PatForwardTool.MinMomentum = minP * 1000 # in MeV + PatForward("PatForwardHLT2").PatForwardTool.MinMomentum = minP * 1000 # in MeV appendPostConfigAction(changeP) # Brunel v47r5 -#Brunel().RecoSequence = ["Decoding","VELO","TT","IT","OT","Tr","RICH"] -#from Configurables import TrackSys, PatForward, PatForwardTool -#TrackSys().setProp( "TrackPatRecAlgorithms", ["FastVelo","Forward"] ) -#PatForward("PatForward").addTool(PatForwardTool) -#PatForward("PatForward").PatForwardTool.MinMomentum = minP * 1000 # in MeV +# Brunel().RecoSequence = ["Decoding","VELO","TT","IT","OT","Tr","RICH"] +# from Configurables import TrackSys, PatForward, PatForwardTool +# TrackSys().setProp( "TrackPatRecAlgorithms", ["FastVelo","Forward"] ) +# PatForward("PatForward").addTool(PatForwardTool) +# PatForward("PatForward").PatForwardTool.MinMomentum = minP * 1000 # in MeV # 2015-04-28 For future reference, these next lines can make *cuts* on Eta and Phi ranges # We are *not using these now* but may do so in the future, if we choose to emulate @@ -104,19 +118,14 @@ rConf.photonConfig().SelectionMode = "Loose" rConf.Radiators = ["Rich2Gas"] # only Long tracks with P > 10GeV rConf.trackConfig().TrackCuts = { - "Forward": { - "Chi2Cut": [0, 5], - "PCut": [minP, 9999999] - }, - "Match": { - "Chi2Cut": [0, 5], - "PCut": [minP, 9999999] - } + "Forward": {"Chi2Cut": [0, 5], "PCut": [minP, 9999999]}, + "Match": {"Chi2Cut": [0, 5], "PCut": [minP, 9999999]}, } # Turn off trackless ring finding rConf.TracklessRingAlgs = [] from Configurables import RichRecQCConf + # disable monitors that are enabled by default in "OfflineFull" mode, # except "AlignmentMonitoring" RichRecQCConf("OfflineRichMoni").removeMonitor("L1SizeMonitoring") @@ -130,7 +139,7 @@ RichRecQCConf("OfflineRichMoni").removeMonitor("TracklessRingAngles") RichRecQCConf("OfflineRichMoni").removeMonitor("TracklessRingPeakSearch") RichRecQCConf("OfflineRichMoni").removeMonitor("HPDImageShifts") RichRecQCConf("OfflineRichMoni").removeMonitor("DataDecodingErrors") -#RichRecQCConf ("OfflineRichMoni").removeMonitor("AlignmentMonitoring" ) +# RichRecQCConf ("OfflineRichMoni").removeMonitor("AlignmentMonitoring" ) RichRecQCConf("OfflineRichMoni").removeMonitor("HPDIFBMonitoring") RichRecQCConf("OfflineRichMoni").removeMonitor("RichPixelPositions") RichRecQCConf("OfflineRichMoni").removeMonitor("HPDHitPlots") @@ -149,39 +158,43 @@ RichRecQCConf("OfflineRichMoni").removeMonitor("RichDataObjectChecks") RichRecQCConf("OfflineRichMoni").removeMonitor("RichRecoTiming") # disable producing NTuple -#RichRecQCConf ("OfflineRichMoni").setProp("NTupleProduce", False ) +# RichRecQCConf ("OfflineRichMoni").setProp("NTupleProduce", False ) from Configurables import RichAlignmentConf + # choose RICH you want -#RichAlignmentConf("OfflineRichMoni_RichAlignmentConf").setProp("Radiators", ["Rich1Gas"]) +# RichAlignmentConf("OfflineRichMoni_RichAlignmentConf").setProp("Radiators", ["Rich1Gas"]) RichAlign = RichAlignmentConf("OfflineRichMoni_RichAlignmentConf") RichAlign.Radiators = ["Rich2Gas"] RichAlign.HPDList = [[0], [0], [0]] RichAlign.Histograms = "Expert" -#RichAlign.VetoedHPDs = [100309] +# RichAlign.VetoedHPDs = [100309] RichAlign.NTupleProduce = False RichAlign.R1NTupleProduce = False # activate long list of segment combination histos to be prebooked for RICH2 # this may propagate from the Brunel Cofiguration, though -#RichAlignmentConf("OfflineRichMoni_RichAlignmentConf").setProp("Histograms", "OfflineExpress") +# RichAlignmentConf("OfflineRichMoni_RichAlignmentConf").setProp("Histograms", "OfflineExpress") ############################################################################## -#from Configurables import DstConf +# from Configurables import DstConf ## enable DST unpacking: needed to get tracks -#ApplicationMgr ().ExtSvc += ["DataOnDemandSvc"] -#DstConf ().EnableUnpack = True +# ApplicationMgr ().ExtSvc += ["DataOnDemandSvc"] +# DstConf ().EnableUnpack = True ############################################################################## -from Configurables import LHCbApp # db tags -#LHCbApp().DDDBtag = "head-20100407" -#LHCbApp().CondDBtag = "head-20100408" +# LHCbApp().DDDBtag = "head-20100407" +# LHCbApp().CondDBtag = "head-20100408" ############################################################################## -from Configurables import CondDB -from Configurables import CondDBAccessSvc -from Configurables import ApplicationMgr -from Configurables import HistogramPersistencySvc -#OutputStream("DstWriter").Output = "DATAFILE='Alignment.dst' TYP='POOL_ROOTTREE' OPT='REC'" +from Configurables import ( + ApplicationMgr, + CondDB, + CondDBAccessSvc, + HistogramPersistencySvc, + LHCbApp, +) + +# OutputStream("DstWriter").Output = "DATAFILE='Alignment.dst' TYP='POOL_ROOTTREE' OPT='REC'" NTupleSvc().Output = [ "RICHTUPLE1 DATAFILE='Ntuple_2015-Collisions.root' TYP='ROOT' OPT='NEW'" ] diff --git a/Rich/RichMirrorAlignmentGanga/options/older/Brunel_RichAlignMoni_Collision10-DST.py b/Rich/RichMirrorAlignmentGanga/options/older/Brunel_RichAlignMoni_Collision10-DST.py index 36f3929c561fe283c1d4ea2fa1fb70024e4d76b5..34e92e775c11e71c2c489a4a4ddd555ff31b53d3 100644 --- a/Rich/RichMirrorAlignmentGanga/options/older/Brunel_RichAlignMoni_Collision10-DST.py +++ b/Rich/RichMirrorAlignmentGanga/options/older/Brunel_RichAlignMoni_Collision10-DST.py @@ -9,32 +9,38 @@ # or submit itself to any jurisdiction. # ############################################################################### from Brunel.Configuration import * + ############################################################################### from GaudiKernel.ProcessJobOptions import importOptions -#importOptions ("$APPCONFIGOPTS/Brunel/earlyData.py") # comment this to make it work! + +# importOptions ("$APPCONFIGOPTS/Brunel/earlyData.py") # comment this to make it work! importOptions("$APPCONFIGOPTS/Brunel/DataType-2010.py") -#importOptions("$APPCONFIGOPTS/UseOracle.py") -#importOptions("$APPCONFIGOPTS/DisableLFC.py") +# importOptions("$APPCONFIGOPTS/UseOracle.py") +# importOptions("$APPCONFIGOPTS/DisableLFC.py") ############################################################################### from Configurables import MessageSvc + MessageSvc().Format = "% F%30W%S%7W%R%T %0W%M" -#MessageSvc().OutputLevel = 7 +# MessageSvc().OutputLevel = 7 from Configurables import Brunel + Brunel().EvtMax = 10 Brunel().PrintFreq = 1 Brunel().OutputType = "None" # reconstruct RICH only Brunel().InitSequence = ["Brunel"] Brunel().RecoSequence = ["RICH"] -#Brunel().MCCheckSequence = ["RICH"] # only when WithTruth +# Brunel().MCCheckSequence = ["RICH"] # only when WithTruth Brunel().Histograms = "OfflineExpress" # propagates down to Alignment from Configurables import RecMoniConf + # RecMoniConf is defined in REC/REC_vXrY/RecSys/python/RecSys/Configuration.py RecMoniConf().MoniSequence = ["RICH"] ############################################################################## from Configurables import RichRecSysConf + rConf = RichRecSysConf("RichOfflineRec") # disable PID rConf.setProp("PidConfig", "None") @@ -48,14 +54,8 @@ rConf.photonConfig().SelectionMode = "Loose" rConf.Radiators = ["Rich1Gas", "Rich2Gas"] # only Long tracks with P > 10GeV rConf.trackConfig().TrackCuts = { - "Forward": { - "Chi2Cut": [0, 5], - "PCut": [10.0, 9999999] - }, - "Match": { - "Chi2Cut": [0, 5], - "PCut": [10.0, 9999999] - } + "Forward": {"Chi2Cut": [0, 5], "PCut": [10.0, 9999999]}, + "Match": {"Chi2Cut": [0, 5], "PCut": [10.0, 9999999]}, } # Turn off trackless ring finding rConf.TracklessRingAlgs = [] @@ -63,6 +63,7 @@ rConf.TracklessRingAlgs = [] rConf.RefitTracks = True from Configurables import RichRecQCConf + # disable monitors that are enabled by default in "OfflineFull" mode, # except "AlignmentMonitoring" RichRecQCConf("OfflineRichMoni").removeMonitor("L1SizeMonitoring") @@ -76,7 +77,7 @@ RichRecQCConf("OfflineRichMoni").removeMonitor("TracklessRingAngles") RichRecQCConf("OfflineRichMoni").removeMonitor("TracklessRingPeakSearch") RichRecQCConf("OfflineRichMoni").removeMonitor("HPDImageShifts") RichRecQCConf("OfflineRichMoni").removeMonitor("DataDecodingErrors") -#RichRecQCConf("OfflineRichMoni").removeMonitor("AlignmentMonitoring" ) +# RichRecQCConf("OfflineRichMoni").removeMonitor("AlignmentMonitoring" ) RichRecQCConf("OfflineRichMoni").removeMonitor("HPDIFBMonitoring") RichRecQCConf("OfflineRichMoni").removeMonitor("RichPixelPositions") RichRecQCConf("OfflineRichMoni").removeMonitor("HPDHitPlots") @@ -98,26 +99,25 @@ RichRecQCConf("OfflineRichMoni").removeMonitor("RichRecoTiming") RichRecQCConf("OfflineRichMoni").setProp("NTupleProduce", False) from Configurables import RichAlignmentConf + # choose RICH you want -#RichAlignmentConf("OfflineRichMoni_RichAlignmentConf").setProp("Radiators", ["Rich1Gas"]) +# RichAlignmentConf("OfflineRichMoni_RichAlignmentConf").setProp("Radiators", ["Rich1Gas"]) RichAlignmentConf("OfflineRichMoni_RichAlignmentConf").setProp( - "Radiators", ["Rich1Gas", "Rich2Gas"]) + "Radiators", ["Rich1Gas", "Rich2Gas"] +) # activate long list of segment combination histos to be prebooked for RICH2 # this may propagate from the Brunel Cofiguration, though -#RichAlignmentConf("OfflineRichMoni_RichAlignmentConf").setProp("Histograms", "OfflineExpress") +# RichAlignmentConf("OfflineRichMoni_RichAlignmentConf").setProp("Histograms", "OfflineExpress") ############################################################################## from Configurables import DstConf + # enable DST unpacking: needed to get tracks ApplicationMgr().ExtSvc += ["DataOnDemandSvc"] DstConf().EnableUnpack = ["Reconstruction"] ############################################################################## -from Configurables import LHCbApp # db tags -#LHCbApp().DDDBtag = "head-20100407" -#LHCbApp().CondDBtag = "head-20100408" +# LHCbApp().DDDBtag = "head-20100407" +# LHCbApp().CondDBtag = "head-20100408" ############################################################################## -from Configurables import CondDB -from Configurables import CondDBAccessSvc - -from Configurables import CondDB, CondDBAccessSvc +from Configurables import CondDB, CondDBAccessSvc, LHCbApp diff --git a/Rich/RichMirrorAlignmentGanga/options/older/Brunel_RichAlignMoni_Collision11-DST.py b/Rich/RichMirrorAlignmentGanga/options/older/Brunel_RichAlignMoni_Collision11-DST.py index b014d75ea01f32cdc2a984a2602c11df4a0a0290..b2c3e7ecf0c97c62b66709e4d83462bfcd8fe031 100644 --- a/Rich/RichMirrorAlignmentGanga/options/older/Brunel_RichAlignMoni_Collision11-DST.py +++ b/Rich/RichMirrorAlignmentGanga/options/older/Brunel_RichAlignMoni_Collision11-DST.py @@ -9,22 +9,26 @@ # or submit itself to any jurisdiction. # ############################################################################### from Brunel.Configuration import * + ############################################################################### from GaudiKernel.ProcessJobOptions import importOptions + importOptions("$APPCONFIGOPTS/Brunel/DataType-2011.py") -#importOptions("$APPCONFIGOPTS/Brunel/MC09-NoTruth.py") -#importOptions ("$APPCONFIGOPTS/Brunel/MC09-WithTruth.py") -#importOptions("$APPCONFIGOPTS/DisableLFC.py") -#importOptions("$APPCONFIGOPTS/Brunel/MC09-WithTruth.py") +# importOptions("$APPCONFIGOPTS/Brunel/MC09-NoTruth.py") +# importOptions ("$APPCONFIGOPTS/Brunel/MC09-WithTruth.py") +# importOptions("$APPCONFIGOPTS/DisableLFC.py") +# importOptions("$APPCONFIGOPTS/Brunel/MC09-WithTruth.py") ############################################################################### from Configurables import MessageSvc + MessageSvc().Format = "% F%30W%S%7W%R%T %0W%M" -#MessageSvc().OutputLevel = 7 +# MessageSvc().OutputLevel = 7 from Configurables import Brunel -#Brunel().DataType = "MC09" -#Brunel().Simulation = True # taken care in MC09-NoTruth.py / MC09-WithTruth.py + +# Brunel().DataType = "MC09" +# Brunel().Simulation = True # taken care in MC09-NoTruth.py / MC09-WithTruth.py Brunel().WithMC = False # with MC truth automatically invokes Simulation Brunel().InputType = "DST" Brunel().EvtMax = 20 @@ -35,16 +39,18 @@ Brunel().Persistency = "ROOT" # reconstruct RICH only Brunel().InitSequence = ["Brunel"] Brunel().RecoSequence = ["RICH"] -#Brunel ().MCCheckSequence = ["RICH"] # only when WithTruth +# Brunel ().MCCheckSequence = ["RICH"] # only when WithTruth Brunel().Histograms = "OfflineExpress" # propagates down to Alignment from Configurables import RecMoniConf + # RecMoniConf is defined in REC/REC_vXrY/RecSys/python/RecSys/Configuration.py RecMoniConf().MoniSequence = ["RICH"] ############################################################################## -#IODataManager().AgeLimit = 3; +# IODataManager().AgeLimit = 3; ############################################################################## from Configurables import RichRecSysConf + rConf = RichRecSysConf("RichOfflineRec") # disable PID rConf.setProp("PidConfig", "None") @@ -54,14 +60,8 @@ rConf.photonConfig().SelectionMode = "Loose" rConf.Radiators = ["Rich1Gas", "Rich2Gas"] # only Long tracks with P > 10GeV rConf.trackConfig().TrackCuts = { - "Forward": { - "Chi2Cut": [0, 5], - "PCut": [10.0, 9999999] - }, - "Match": { - "Chi2Cut": [0, 5], - "PCut": [10.0, 9999999] - } + "Forward": {"Chi2Cut": [0, 5], "PCut": [10.0, 9999999]}, + "Match": {"Chi2Cut": [0, 5], "PCut": [10.0, 9999999]}, } # Turn off trackless ring finding rConf.TracklessRingAlgs = [] @@ -69,6 +69,7 @@ rConf.TracklessRingAlgs = [] rConf.RefitTracks = True from Configurables import RichRecQCConf + # disable monitors that are enabled by default in "OfflineFull" mode # except "AlignmentMonitoring" RichRecQCConf("OfflineRichMoni").removeMonitor("L1SizeMonitoring") @@ -80,7 +81,7 @@ RichRecQCConf("OfflineRichMoni").removeMonitor("TrackMonitoring") RichRecQCConf("OfflineRichMoni").removeMonitor("PhotonMonitoring") RichRecQCConf("OfflineRichMoni").removeMonitor("TracklessRingAngles") RichRecQCConf("OfflineRichMoni").removeMonitor("TracklessRingPeakSearch") -#RichRecQCConf("OfflineRichMoni").removeMonitor("AlignmentMonitoring" ) +# RichRecQCConf("OfflineRichMoni").removeMonitor("AlignmentMonitoring" ) RichRecQCConf("OfflineRichMoni").removeMonitor("HPDIFBMonitoring") RichRecQCConf("OfflineRichMoni").removeMonitor("RichPixelPositions") RichRecQCConf("OfflineRichMoni").removeMonitor("HPDHitPlots") @@ -101,51 +102,47 @@ RichRecQCConf("OfflineRichMoni").removeMonitor("RichRecoTiming") # disable producing NTuple RichRecQCConf("OfflineRichMoni").setProp("NTupleProduce", False) -from Configurables import RichAlignmentConf # choose RICH you want -#RichAlignmentConf("OfflineRichMoni_RichAlignmentConf").setProp("Radiators", ["Rich1Gas"]) -#RichAlignmentConf ("OfflineRichMoni_RichAlignmentConf").setProp("Radiators", ["Rich1Gas", "Rich2Gas"]) +# RichAlignmentConf("OfflineRichMoni_RichAlignmentConf").setProp("Radiators", ["Rich1Gas"]) +# RichAlignmentConf ("OfflineRichMoni_RichAlignmentConf").setProp("Radiators", ["Rich1Gas", "Rich2Gas"]) # -#from Configurables import ( Rich__Rec__MC__AlignmentMonitor ) -#RichAlignMoniR1 = Rich__Rec__MC__AlignmentMonitor("RichAlignMoniR1Gas") -#trselname = "TrackSelector" -#RichAlignMoniR1.addTool( RichAlignmentConf ("OfflineRichMoni_RichAlignmentConf").richTools().trackSelector(trselname), name=trselname ) -#RichRecQCConf ("OfflineRichMoni").createMonitor(Rich__Rec__MC__AlignmentMonitor,"RichAlignMoniR1Gas",trackType=None,tkCuts="Tight" ) +# from Configurables import ( Rich__Rec__MC__AlignmentMonitor ) +# RichAlignMoniR1 = Rich__Rec__MC__AlignmentMonitor("RichAlignMoniR1Gas") +# trselname = "TrackSelector" +# RichAlignMoniR1.addTool( RichAlignmentConf ("OfflineRichMoni_RichAlignmentConf").richTools().trackSelector(trselname), name=trselname ) +# RichRecQCConf ("OfflineRichMoni").createMonitor(Rich__Rec__MC__AlignmentMonitor,"RichAlignMoniR1Gas",trackType=None,tkCuts="Tight" ) # -#RichAlignMoniR2 = Rich__Rec__MC__AlignmentMonitor("RichAlignMoniR2Gas") -#trselname = "TrackSelector" -#RichAlignMoniR2.addTool( RichAlignmentConf ("OfflineRichMoni_RichAlignmentConf").richTools().trackSelector(trselname), name=trselname ) -#RichRecQCConf ("OfflineRichMoni").createMonitor(Rich__Rec__MC__AlignmentMonitor,"RichAlignMoniR2Gas",trackType=None,tkCuts="Tight" ) +# RichAlignMoniR2 = Rich__Rec__MC__AlignmentMonitor("RichAlignMoniR2Gas") +# trselname = "TrackSelector" +# RichAlignMoniR2.addTool( RichAlignmentConf ("OfflineRichMoni_RichAlignmentConf").richTools().trackSelector(trselname), name=trselname ) +# RichRecQCConf ("OfflineRichMoni").createMonitor(Rich__Rec__MC__AlignmentMonitor,"RichAlignMoniR2Gas",trackType=None,tkCuts="Tight" ) ##RichRecQCConf ("OfflineRichMoni").createMonitor(RichAlignmentConf,"OfflineRichMoni_RichAlignmentConf",trackType=None,tkCuts="Tight" ) - # activate long list of segment combination histos to be prebooked for RICH2 # but this propagates from the Brunel Cofiguration -#RichAlignmentConf().setProp("Histograms", "OfflineExpress") - +# RichAlignmentConf().setProp("Histograms", "OfflineExpress") # activate filling histograms that utilize knowledge from MC Truth # but this propagates from the Brunel Cofiguration -#RichAlignmentConf().setProp("WithMC", True ) +# RichAlignmentConf().setProp("WithMC", True ) ############################################################################## -from Configurables import DstConf +from Configurables import DstConf, RichAlignmentConf + # enable DST unpacking: needed to get tracks ApplicationMgr().ExtSvc += ["DataOnDemandSvc"] DstConf().EnableUnpack = ["Reconstruction"] ############################################################################## -from Configurables import LHCbApp # db tags -#LHCbApp().DDDBtag = "MC09-20090602" -#LHCbApp().CondDBtag = "MC09-20090402-vc-md100" +# LHCbApp().DDDBtag = "MC09-20090602" +# LHCbApp().CondDBtag = "MC09-20090402-vc-md100" ############################################################################## -from Configurables import CondDB -from Configurables import CondDBAccessSvc +from Configurables import CondDB, CondDBAccessSvc, LHCbApp # -#Brunel().DDDBtag = 'head-20111102' -#Brunel().CondDBtag = 'head-20111111' +# Brunel().DDDBtag = 'head-20111102' +# Brunel().CondDBtag = 'head-20111111' ##Brunel().EvtMax = """+brunelEvtMax+""" ##Brunel().PrintFreq = """+brunelPrintFreq+""" -#RichAlignmentConf ("OfflineRichMoni_RichAlignmentConf").setProp("Radiators", ['Rich1Gas']) -#MessageSvc().OutputLevel = 3 -#RichAlignmentConf("OfflineRichMoni_RichAlignmentConf").setProp("DeltaThetaRange", [ 0.04,0.007, 0.004 ]) -#HistogramPersistencySvc().setProp('OutputFile', 'RichRecQCHistos_rich1_.root') +# RichAlignmentConf ("OfflineRichMoni_RichAlignmentConf").setProp("Radiators", ['Rich1Gas']) +# MessageSvc().OutputLevel = 3 +# RichAlignmentConf("OfflineRichMoni_RichAlignmentConf").setProp("DeltaThetaRange", [ 0.04,0.007, 0.004 ]) +# HistogramPersistencySvc().setProp('OutputFile', 'RichRecQCHistos_rich1_.root') # -#CondDB().addLayer( CondDBAccessSvc('Rich1AlignMirr', ConnectionString = 'sqlite_file:Mirrors_10m12c_p0p2fix_Gs1Gb1Mp9Wi7FvsurfaceBCm0Ct0.3Sm1_R1SelMdCollision11.db/LHCBCOND', DefaultTAG = 'head-20111111') ) +# CondDB().addLayer( CondDBAccessSvc('Rich1AlignMirr', ConnectionString = 'sqlite_file:Mirrors_10m12c_p0p2fix_Gs1Gb1Mp9Wi7FvsurfaceBCm0Ct0.3Sm1_R1SelMdCollision11.db/LHCBCOND', DefaultTAG = 'head-20111111') ) diff --git a/Rich/RichMirrorAlignmentGanga/options/older/Brunel_RichAlignMoni_Collision11-RAW.py b/Rich/RichMirrorAlignmentGanga/options/older/Brunel_RichAlignMoni_Collision11-RAW.py index ef02663145b61d44a1cb1e2b604d5e56ff1ef063..088674b62d79880f2f9d543081ccfc30206b729b 100644 --- a/Rich/RichMirrorAlignmentGanga/options/older/Brunel_RichAlignMoni_Collision11-RAW.py +++ b/Rich/RichMirrorAlignmentGanga/options/older/Brunel_RichAlignMoni_Collision11-RAW.py @@ -9,48 +9,52 @@ # or submit itself to any jurisdiction. # ############################################################################### from Brunel.Configuration import * + ############################################################################### from GaudiKernel.ProcessJobOptions import importOptions -#importOptions ("$APPCONFIGOPTS/Brunel/earlyData.py") + +# importOptions ("$APPCONFIGOPTS/Brunel/earlyData.py") importOptions("$APPCONFIGOPTS/Brunel/DataType-2012.py") -#importOptions("$APPCONFIGOPTS/UseOracle.py") -#importOptions("$APPCONFIGOPTS/DisableLFC.py") +# importOptions("$APPCONFIGOPTS/UseOracle.py") +# importOptions("$APPCONFIGOPTS/DisableLFC.py") ############################################################################### from Configurables import MessageSvc + MessageSvc().Format = "% F%30W%S%7W%R%T %0W%M" -#MessageSvc().OutputLevel = 7 +# MessageSvc().OutputLevel = 7 from Configurables import Brunel + Brunel().EvtMax = 1000 Brunel().PrintFreq = 10 Brunel().OutputType = "None" -#--Again the Database problem... -#from Configurables import CondDB, LHCbApp -#CondDB(UseOracle = True) -#LHCbApp().DDDBtag ="head-20110302" -#LHCbApp().CondDBtag="head-20110318" +# --Again the Database problem... +# from Configurables import CondDB, LHCbApp +# CondDB(UseOracle = True) +# LHCbApp().DDDBtag ="head-20110302" +# LHCbApp().CondDBtag="head-20110318" # reconstruct RICH only -#Brunel ().InitSequence = ["Brunel"] -Brunel().RecoSequence = [ - "Decoding", "VELO", "TT", "IT", "OT", "Tr", "Vertex", "RICH" -] +# Brunel ().InitSequence = ["Brunel"] +Brunel().RecoSequence = ["Decoding", "VELO", "TT", "IT", "OT", "Tr", "Vertex", "RICH"] -#Brunel ().RecoSequence = ["RICH"] -#Brunel().MCCheckSequence = ["RICH"] # only when WithTruth +# Brunel ().RecoSequence = ["RICH"] +# Brunel().MCCheckSequence = ["RICH"] # only when WithTruth Brunel().Histograms = "Expert" # propagates down to Alignment -#Brunel ().Histograms = "None" +# Brunel ().Histograms = "None" Brunel().DataType = "2012" -#from Configurables import EventClockSvc -#EventClockSvc( InitialTime = 1341100800000000000 ) # 1st July 2012 +# from Configurables import EventClockSvc +# EventClockSvc( InitialTime = 1341100800000000000 ) # 1st July 2012 from Configurables import RecMoniConf + # RecMoniConf is defined in REC/REC_vXrY/RecSys/python/RecSys/Configuration.py RecMoniConf().MoniSequence = ["RICH"] ############################################################################## from Configurables import RichRecSysConf + rConf = RichRecSysConf("RichOfflineRec") # disable PID rConf.setProp("PidConfig", "None") @@ -60,7 +64,8 @@ minP = 10 # in GeV # Tweak the tracking to only run the Forward tracking, and to apply # the min track momentum cut during the track finding. -from Configurables import TrackSys, PatForward, PatForwardTool +from Configurables import PatForward, PatForwardTool, TrackSys + TrackSys().setProp("TrackPatRecAlgorithms", ["FastVelo", "Forward"]) PatForward("PatForward").addTool(PatForwardTool) PatForward("PatForward").PatForwardTool.MinMomentum = minP * 1000 # in MeV @@ -74,19 +79,14 @@ rConf.photonConfig().SelectionMode = "Loose" rConf.Radiators = ["Rich1Gas", "Rich2Gas"] # only Long tracks with P > 10GeV rConf.trackConfig().TrackCuts = { - "Forward": { - "Chi2Cut": [0, 5], - "PCut": [minP, 9999999] - }, - "Match": { - "Chi2Cut": [0, 5], - "PCut": [minP, 9999999] - } + "Forward": {"Chi2Cut": [0, 5], "PCut": [minP, 9999999]}, + "Match": {"Chi2Cut": [0, 5], "PCut": [minP, 9999999]}, } # Turn off trackless ring finding rConf.TracklessRingAlgs = [] from Configurables import RichRecQCConf + # disable monitors that are enabled by default in "OfflineFull" mode, # except "AlignmentMonitoring" RichRecQCConf("OfflineRichMoni").removeMonitor("L1SizeMonitoring") @@ -100,7 +100,7 @@ RichRecQCConf("OfflineRichMoni").removeMonitor("TracklessRingAngles") RichRecQCConf("OfflineRichMoni").removeMonitor("TracklessRingPeakSearch") RichRecQCConf("OfflineRichMoni").removeMonitor("HPDImageShifts") RichRecQCConf("OfflineRichMoni").removeMonitor("DataDecodingErrors") -#RichRecQCConf ("OfflineRichMoni").removeMonitor("AlignmentMonitoring" ) +# RichRecQCConf ("OfflineRichMoni").removeMonitor("AlignmentMonitoring" ) RichRecQCConf("OfflineRichMoni").removeMonitor("HPDIFBMonitoring") RichRecQCConf("OfflineRichMoni").removeMonitor("RichPixelPositions") RichRecQCConf("OfflineRichMoni").removeMonitor("HPDHitPlots") @@ -119,39 +119,43 @@ RichRecQCConf("OfflineRichMoni").removeMonitor("RichDataObjectChecks") RichRecQCConf("OfflineRichMoni").removeMonitor("RichRecoTiming") # disable producing NTuple -#RichRecQCConf ("OfflineRichMoni").setProp("NTupleProduce", False ) +# RichRecQCConf ("OfflineRichMoni").setProp("NTupleProduce", False ) from Configurables import RichAlignmentConf + # choose RICH you want -#RichAlignmentConf("OfflineRichMoni_RichAlignmentConf").setProp("Radiators", ["Rich1Gas"]) +# RichAlignmentConf("OfflineRichMoni_RichAlignmentConf").setProp("Radiators", ["Rich1Gas"]) RichAlign = RichAlignmentConf("OfflineRichMoni_RichAlignmentConf") RichAlign.Radiators = ["Rich1Gas", "Rich2Gas"] RichAlign.HPDList = [[0], [0], [0]] RichAlign.Histograms = "Expert" -#RichAlign.VetoedHPDs = [100309] +# RichAlign.VetoedHPDs = [100309] RichAlign.NTupleProduce = False RichAlign.R1NTupleProduce = False # activate long list of segment combination histos to be prebooked for RICH2 # this may propagate from the Brunel Cofiguration, though -#RichAlignmentConf("OfflineRichMoni_RichAlignmentConf").setProp("Histograms", "OfflineExpress") +# RichAlignmentConf("OfflineRichMoni_RichAlignmentConf").setProp("Histograms", "OfflineExpress") ############################################################################## -#from Configurables import DstConf +# from Configurables import DstConf ## enable DST unpacking: needed to get tracks -#ApplicationMgr ().ExtSvc += ["DataOnDemandSvc"] -#DstConf ().EnableUnpack = True +# ApplicationMgr ().ExtSvc += ["DataOnDemandSvc"] +# DstConf ().EnableUnpack = True ############################################################################## -from Configurables import LHCbApp # db tags -#LHCbApp().DDDBtag = "head-20100407" -#LHCbApp().CondDBtag = "head-20100408" +# LHCbApp().DDDBtag = "head-20100407" +# LHCbApp().CondDBtag = "head-20100408" ############################################################################## -from Configurables import CondDB -from Configurables import CondDBAccessSvc -from Configurables import ApplicationMgr -from Configurables import HistogramPersistencySvc -#OutputStream("DstWriter").Output = "DATAFILE='Alignment.dst' TYP='POOL_ROOTTREE' OPT='REC'" +from Configurables import ( + ApplicationMgr, + CondDB, + CondDBAccessSvc, + HistogramPersistencySvc, + LHCbApp, +) + +# OutputStream("DstWriter").Output = "DATAFILE='Alignment.dst' TYP='POOL_ROOTTREE' OPT='REC'" NTupleSvc().Output = [ "RICHTUPLE1 DATAFILE='Ntuple_2012-Collisions.root' TYP='ROOT' OPT='NEW'" ] diff --git a/Rich/RichMirrorAlignmentGanga/options/older/Brunel_RichAlignMoni_Collision12-RAW.py b/Rich/RichMirrorAlignmentGanga/options/older/Brunel_RichAlignMoni_Collision12-RAW.py index de449e629c95e107d182f8639f19b2925ce4a802..afd3bb64a295d8428d2420dbb12d28e78dfbeeff 100644 --- a/Rich/RichMirrorAlignmentGanga/options/older/Brunel_RichAlignMoni_Collision12-RAW.py +++ b/Rich/RichMirrorAlignmentGanga/options/older/Brunel_RichAlignMoni_Collision12-RAW.py @@ -9,45 +9,49 @@ # or submit itself to any jurisdiction. # ############################################################################### from Brunel.Configuration import * + ############################################################################### from GaudiKernel.ProcessJobOptions import importOptions -#importOptions ("$APPCONFIGOPTS/Brunel/earlyData.py") + +# importOptions ("$APPCONFIGOPTS/Brunel/earlyData.py") importOptions("$APPCONFIGOPTS/Brunel/DataType-2012.py") -#importOptions("$APPCONFIGOPTS/UseOracle.py") -#importOptions("$APPCONFIGOPTS/DisableLFC.py") +# importOptions("$APPCONFIGOPTS/UseOracle.py") +# importOptions("$APPCONFIGOPTS/DisableLFC.py") ############################################################################### from Configurables import MessageSvc + MessageSvc().Format = "% F%30W%S%7W%R%T %0W%M" -#MessageSvc().OutputLevel = 7 +# MessageSvc().OutputLevel = 7 from Configurables import Brunel + Brunel().EvtMax = 1000 Brunel().PrintFreq = 10 Brunel().OutputType = "None" -#--Again the Database problem... -#from Configurables import CondDB, LHCbApp -#CondDB(UseOracle = True) -#LHCbApp().DDDBtag ="head-20110302" -#LHCbApp().CondDBtag="head-20110318" +# --Again the Database problem... +# from Configurables import CondDB, LHCbApp +# CondDB(UseOracle = True) +# LHCbApp().DDDBtag ="head-20110302" +# LHCbApp().CondDBtag="head-20110318" # reconstruct RICH only -#Brunel ().InitSequence = ["Brunel"] -Brunel().RecoSequence = [ - "Decoding", "VELO", "TT", "IT", "OT", "Tr", "Vertex", "RICH" -] +# Brunel ().InitSequence = ["Brunel"] +Brunel().RecoSequence = ["Decoding", "VELO", "TT", "IT", "OT", "Tr", "Vertex", "RICH"] -#Brunel ().RecoSequence = ["RICH"] -#Brunel().MCCheckSequence = ["RICH"] # only when WithTruth +# Brunel ().RecoSequence = ["RICH"] +# Brunel().MCCheckSequence = ["RICH"] # only when WithTruth Brunel().Histograms = "Expert" # propagates down to Alignment -#Brunel ().Histograms = "None" +# Brunel ().Histograms = "None" Brunel().DataType = "2012" from Configurables import RecMoniConf + # RecMoniConf is defined in REC/REC_vXrY/RecSys/python/RecSys/Configuration.py RecMoniConf().MoniSequence = ["RICH"] ############################################################################## from Configurables import RichRecSysConf + rConf = RichRecSysConf("RichOfflineRec") # disable PID rConf.setProp("PidConfig", "None") @@ -57,7 +61,8 @@ minP = 10 # in GeV # Tweak the tracking to only run the Forward tracking, and to apply # the min track momentum cut during the track finding. -from Configurables import TrackSys, PatForward, PatForwardTool +from Configurables import PatForward, PatForwardTool, TrackSys + TrackSys().setProp("TrackPatRecAlgorithms", ["FastVelo", "Forward"]) PatForward("PatForward").addTool(PatForwardTool) PatForward("PatForward").PatForwardTool.MinMomentum = minP * 1000 # in MeV @@ -71,19 +76,14 @@ rConf.photonConfig().SelectionMode = "Loose" rConf.Radiators = ["Rich1Gas", "Rich2Gas"] # only Long tracks with P > 10GeV rConf.trackConfig().TrackCuts = { - "Forward": { - "Chi2Cut": [0, 5], - "PCut": [minP, 9999999] - }, - "Match": { - "Chi2Cut": [0, 5], - "PCut": [minP, 9999999] - } + "Forward": {"Chi2Cut": [0, 5], "PCut": [minP, 9999999]}, + "Match": {"Chi2Cut": [0, 5], "PCut": [minP, 9999999]}, } # Turn off trackless ring finding rConf.TracklessRingAlgs = [] from Configurables import RichRecQCConf + # disable monitors that are enabled by default in "OfflineFull" mode, # except "AlignmentMonitoring" RichRecQCConf("OfflineRichMoni").removeMonitor("L1SizeMonitoring") @@ -97,7 +97,7 @@ RichRecQCConf("OfflineRichMoni").removeMonitor("TracklessRingAngles") RichRecQCConf("OfflineRichMoni").removeMonitor("TracklessRingPeakSearch") RichRecQCConf("OfflineRichMoni").removeMonitor("HPDImageShifts") RichRecQCConf("OfflineRichMoni").removeMonitor("DataDecodingErrors") -#RichRecQCConf ("OfflineRichMoni").removeMonitor("AlignmentMonitoring" ) +# RichRecQCConf ("OfflineRichMoni").removeMonitor("AlignmentMonitoring" ) RichRecQCConf("OfflineRichMoni").removeMonitor("HPDIFBMonitoring") RichRecQCConf("OfflineRichMoni").removeMonitor("RichPixelPositions") RichRecQCConf("OfflineRichMoni").removeMonitor("HPDHitPlots") @@ -116,39 +116,43 @@ RichRecQCConf("OfflineRichMoni").removeMonitor("RichDataObjectChecks") RichRecQCConf("OfflineRichMoni").removeMonitor("RichRecoTiming") # disable producing NTuple -#RichRecQCConf ("OfflineRichMoni").setProp("NTupleProduce", False ) +# RichRecQCConf ("OfflineRichMoni").setProp("NTupleProduce", False ) from Configurables import RichAlignmentConf + # choose RICH you want -#RichAlignmentConf("OfflineRichMoni_RichAlignmentConf").setProp("Radiators", ["Rich1Gas"]) +# RichAlignmentConf("OfflineRichMoni_RichAlignmentConf").setProp("Radiators", ["Rich1Gas"]) RichAlign = RichAlignmentConf("OfflineRichMoni_RichAlignmentConf") RichAlign.Radiators = ["Rich1Gas", "Rich2Gas"] RichAlign.HPDList = [[0], [0], [0]] RichAlign.Histograms = "Expert" -#RichAlign.VetoedHPDs = [100309] +# RichAlign.VetoedHPDs = [100309] RichAlign.NTupleProduce = False RichAlign.R1NTupleProduce = False # activate long list of segment combination histos to be prebooked for RICH2 # this may propagate from the Brunel Cofiguration, though -#RichAlignmentConf("OfflineRichMoni_RichAlignmentConf").setProp("Histograms", "OfflineExpress") +# RichAlignmentConf("OfflineRichMoni_RichAlignmentConf").setProp("Histograms", "OfflineExpress") ############################################################################## -#from Configurables import DstConf +# from Configurables import DstConf ## enable DST unpacking: needed to get tracks -#ApplicationMgr ().ExtSvc += ["DataOnDemandSvc"] -#DstConf ().EnableUnpack = True +# ApplicationMgr ().ExtSvc += ["DataOnDemandSvc"] +# DstConf ().EnableUnpack = True ############################################################################## -from Configurables import LHCbApp # db tags -#LHCbApp().DDDBtag = "head-20100407" -#LHCbApp().CondDBtag = "head-20100408" +# LHCbApp().DDDBtag = "head-20100407" +# LHCbApp().CondDBtag = "head-20100408" ############################################################################## -from Configurables import CondDB -from Configurables import CondDBAccessSvc -from Configurables import ApplicationMgr -from Configurables import HistogramPersistencySvc -#OutputStream("DstWriter").Output = "DATAFILE='Alignment.dst' TYP='POOL_ROOTTREE' OPT='REC'" +from Configurables import ( + ApplicationMgr, + CondDB, + CondDBAccessSvc, + HistogramPersistencySvc, + LHCbApp, +) + +# OutputStream("DstWriter").Output = "DATAFILE='Alignment.dst' TYP='POOL_ROOTTREE' OPT='REC'" NTupleSvc().Output = [ "RICHTUPLE1 DATAFILE='Ntuple_2012-Collisions.root' TYP='ROOT' OPT='NEW'" ] diff --git a/Rich/RichMirrorAlignmentGanga/options/older/Brunel_RichAlignMoni_MC10-DST.py b/Rich/RichMirrorAlignmentGanga/options/older/Brunel_RichAlignMoni_MC10-DST.py index ebb90ab1adb7153c906366ff347a8d2ae48ae4dd..39e5e19316f02743483fc7e54cf84f96d284df1c 100644 --- a/Rich/RichMirrorAlignmentGanga/options/older/Brunel_RichAlignMoni_MC10-DST.py +++ b/Rich/RichMirrorAlignmentGanga/options/older/Brunel_RichAlignMoni_MC10-DST.py @@ -9,21 +9,25 @@ # or submit itself to any jurisdiction. # ############################################################################### from Brunel.Configuration import * + ############################################################################### from GaudiKernel.ProcessJobOptions import importOptions -#importOptions("$APPCONFIGOPTS/Brunel/MC09-NoTruth.py") -#importOptions ("$APPCONFIGOPTS/Brunel/MC09-WithTruth.py") -#importOptions("$APPCONFIGOPTS/DisableLFC.py") + +# importOptions("$APPCONFIGOPTS/Brunel/MC09-NoTruth.py") +# importOptions ("$APPCONFIGOPTS/Brunel/MC09-WithTruth.py") +# importOptions("$APPCONFIGOPTS/DisableLFC.py") importOptions("$APPCONFIGOPTS/Brunel/MC09-WithTruth.py") ############################################################################### from Configurables import MessageSvc + MessageSvc().Format = "% F%30W%S%7W%R%T %0W%M" -#MessageSvc().OutputLevel = 7 +# MessageSvc().OutputLevel = 7 from Configurables import Brunel -#Brunel().DataType = "MC09" -#Brunel().Simulation = True # taken care in MC09-NoTruth.py / MC09-WithTruth.py + +# Brunel().DataType = "MC09" +# Brunel().Simulation = True # taken care in MC09-NoTruth.py / MC09-WithTruth.py Brunel().WithMC = True # with MC truth automatically invokes Simulation Brunel().InputType = "DST" Brunel().EvtMax = 10 @@ -36,12 +40,14 @@ Brunel().MCCheckSequence = ["RICH"] # only when WithTruth Brunel().Histograms = "OfflineExpress" # propagates down to Alignment from Configurables import RecMoniConf + # RecMoniConf is defined in REC/REC_vXrY/RecSys/python/RecSys/Configuration.py RecMoniConf().MoniSequence = ["RICH"] ############################################################################## -#IODataManager().AgeLimit = 3; +# IODataManager().AgeLimit = 3; ############################################################################## from Configurables import RichRecSysConf + rConf = RichRecSysConf("RichOfflineRec") # disable PID rConf.setProp("PidConfig", "None") @@ -51,19 +57,14 @@ rConf.photonConfig().SelectionMode = "Wide" rConf.Radiators = ["Rich1Gas", "Rich2Gas"] # only Long tracks with P > 10GeV rConf.trackConfig().TrackCuts = { - "Forward": { - "Chi2Cut": [0, 5], - "PCut": [10.0, 9999999] - }, - "Match": { - "Chi2Cut": [0, 5], - "PCut": [10.0, 9999999] - } + "Forward": {"Chi2Cut": [0, 5], "PCut": [10.0, 9999999]}, + "Match": {"Chi2Cut": [0, 5], "PCut": [10.0, 9999999]}, } # Turn off trackless ring finding rConf.TracklessRingAlgs = [] from Configurables import RichRecQCConf + # disable monitors that are enabled by default in "OfflineFull" mode # except "AlignmentMonitoring" RichRecQCConf("OfflineRichMoni").removeMonitor("L1SizeMonitoring") @@ -75,7 +76,7 @@ RichRecQCConf("OfflineRichMoni").removeMonitor("TrackMonitoring") RichRecQCConf("OfflineRichMoni").removeMonitor("PhotonMonitoring") RichRecQCConf("OfflineRichMoni").removeMonitor("TracklessRingAngles") RichRecQCConf("OfflineRichMoni").removeMonitor("TracklessRingPeakSearch") -#RichRecQCConf("OfflineRichMoni").removeMonitor("AlignmentMonitoring" ) +# RichRecQCConf("OfflineRichMoni").removeMonitor("AlignmentMonitoring" ) RichRecQCConf("OfflineRichMoni").removeMonitor("HPDIFBMonitoring") RichRecQCConf("OfflineRichMoni").removeMonitor("RichPixelPositions") RichRecQCConf("OfflineRichMoni").removeMonitor("HPDHitPlots") @@ -97,40 +98,41 @@ RichRecQCConf("OfflineRichMoni").removeMonitor("RichRecoTiming") RichRecQCConf("OfflineRichMoni").setProp("NTupleProduce", False) from Configurables import RichAlignmentConf + # choose RICH you want -#RichAlignmentConf("OfflineRichMoni_RichAlignmentConf").setProp("Radiators", ["Rich1Gas"]) +# RichAlignmentConf("OfflineRichMoni_RichAlignmentConf").setProp("Radiators", ["Rich1Gas"]) RichAlignmentConf("OfflineRichMoni_RichAlignmentConf").setProp( - "Radiators", ["Rich1Gas", "Rich2Gas"]) + "Radiators", ["Rich1Gas", "Rich2Gas"] +) # -#from Configurables import ( Rich__Rec__MC__AlignmentMonitor ) -#RichAlignMoniR1 = Rich__Rec__MC__AlignmentMonitor("RichAlignMoniR1Gas") -#trselname = "TrackSelector" -#RichAlignMoniR1.addTool( RichAlignmentConf ("OfflineRichMoni_RichAlignmentConf").richTools().trackSelector(trselname), name=trselname ) -#RichRecQCConf ("OfflineRichMoni").createMonitor(Rich__Rec__MC__AlignmentMonitor,"RichAlignMoniR1Gas",trackType=None,tkCuts="Tight" ) +# from Configurables import ( Rich__Rec__MC__AlignmentMonitor ) +# RichAlignMoniR1 = Rich__Rec__MC__AlignmentMonitor("RichAlignMoniR1Gas") +# trselname = "TrackSelector" +# RichAlignMoniR1.addTool( RichAlignmentConf ("OfflineRichMoni_RichAlignmentConf").richTools().trackSelector(trselname), name=trselname ) +# RichRecQCConf ("OfflineRichMoni").createMonitor(Rich__Rec__MC__AlignmentMonitor,"RichAlignMoniR1Gas",trackType=None,tkCuts="Tight" ) # -#RichAlignMoniR2 = Rich__Rec__MC__AlignmentMonitor("RichAlignMoniR2Gas") -#trselname = "TrackSelector" -#RichAlignMoniR2.addTool( RichAlignmentConf ("OfflineRichMoni_RichAlignmentConf").richTools().trackSelector(trselname), name=trselname ) -#RichRecQCConf ("OfflineRichMoni").createMonitor(Rich__Rec__MC__AlignmentMonitor,"RichAlignMoniR2Gas",trackType=None,tkCuts="Tight" ) +# RichAlignMoniR2 = Rich__Rec__MC__AlignmentMonitor("RichAlignMoniR2Gas") +# trselname = "TrackSelector" +# RichAlignMoniR2.addTool( RichAlignmentConf ("OfflineRichMoni_RichAlignmentConf").richTools().trackSelector(trselname), name=trselname ) +# RichRecQCConf ("OfflineRichMoni").createMonitor(Rich__Rec__MC__AlignmentMonitor,"RichAlignMoniR2Gas",trackType=None,tkCuts="Tight" ) ##RichRecQCConf ("OfflineRichMoni").createMonitor(RichAlignmentConf,"OfflineRichMoni_RichAlignmentConf",trackType=None,tkCuts="Tight" ) # activate long list of segment combination histos to be prebooked for RICH2 # but this propagates from the Brunel Cofiguration -#RichAlignmentConf().setProp("Histograms", "OfflineExpress") +# RichAlignmentConf().setProp("Histograms", "OfflineExpress") # activate filling histograms that utilize knowledge from MC Truth # but this propagates from the Brunel Cofiguration -#RichAlignmentConf().setProp("WithMC", True ) +# RichAlignmentConf().setProp("WithMC", True ) ############################################################################## from Configurables import DstConf + # enable DST unpacking: needed to get tracks ApplicationMgr().ExtSvc += ["DataOnDemandSvc"] DstConf().EnableUnpack = ["Reconstruction"] ############################################################################## -from Configurables import LHCbApp # db tags -#LHCbApp().DDDBtag = "MC09-20090602" -#LHCbApp().CondDBtag = "MC09-20090402-vc-md100" +# LHCbApp().DDDBtag = "MC09-20090602" +# LHCbApp().CondDBtag = "MC09-20090402-vc-md100" ############################################################################## -from Configurables import CondDB -from Configurables import CondDBAccessSvc +from Configurables import CondDB, CondDBAccessSvc, LHCbApp diff --git a/Rich/RichMirrorAlignmentGanga/scripts/XMLcompare.py b/Rich/RichMirrorAlignmentGanga/scripts/XMLcompare.py index 06154eaf3fa2e5a56806f69f15ac118aaff1aeb5..287e417e838cb132a04a434e5e4dd81d7925d9e8 100644 --- a/Rich/RichMirrorAlignmentGanga/scripts/XMLcompare.py +++ b/Rich/RichMirrorAlignmentGanga/scripts/XMLcompare.py @@ -8,53 +8,54 @@ # granted to it by virtue of its status as an Intergovernmental Organization # # or submit itself to any jurisdiction. # ############################################################################### -import os, re, argparse +import argparse +import os +import re + parser = argparse.ArgumentParser( - description= - 'Compares two XML files or a single diff between XML files. Usage is "python XMLcompare.py <before.xml> <after.xml>" OR "python XMLcompare.py <diff_between_two_xmls.txt>". Designed only to compare Y and Z tilts for all alignment parameters in the XML file. Does not tell you the name of each parameter, only draws attention to those that differ by more than 0.1 mrad. Tilts are ROUNDED not truncated.' + description='Compares two XML files or a single diff between XML files. Usage is "python XMLcompare.py <before.xml> <after.xml>" OR "python XMLcompare.py <diff_between_two_xmls.txt>". Designed only to compare Y and Z tilts for all alignment parameters in the XML file. Does not tell you the name of each parameter, only draws attention to those that differ by more than 0.1 mrad. Tilts are ROUNDED not truncated.' ) parser.add_argument( - 'files', - metavar='FILE', + "files", + metavar="FILE", type=str, - nargs='+', - help='the file with the diff OR the two files you want to diff') + nargs="+", + help="the file with the diff OR the two files you want to diff", +) parser.add_argument( - '-w', + "-w", action="store", default=0.1, dest="warningPrecision", type=float, - help= - 'the precision of differences at which warnings are provided, default is 0.1' + help="the precision of differences at which warnings are provided, default is 0.1", ) parser.add_argument( - '-p', + "-p", action="store", default=2, dest="displayPrecision", type=int, - help= - 'the number of digits after the decimal point printed for output numbers, default is 2' + help="the number of digits after the decimal point printed for output numbers, default is 2", ) args = parser.parse_args() warningPrecision = args.warningPrecision displayPrecision = str(args.displayPrecision) -#Actually, the parser will tell you that you didn't provide enough arguments, so we don't need this next bit +# Actually, the parser will tell you that you didn't provide enough arguments, so we don't need this next bit # if (len(args.files)==0): # print "I need files." # raise SystemExit("I need files.") -if (len(args.files) == 1): +if len(args.files) == 1: file = args.files[0] - print "pre-diffed input file: " + file -if (len(args.files) == 2): + print("pre-diffed input file: " + file) +if len(args.files) == 2: file = args.files[0] file2 = args.files[1] tempfile = "temp_XMLcompare.txt" - print "first XML file to diff: " + file - print "second XML file to diff: " + file2 + print("first XML file to diff: " + file) + print("second XML file to diff: " + file2) os.system("diff " + file + " " + file2 + " > " + tempfile) file = tempfile @@ -71,7 +72,7 @@ with open(file, "r") as myfile: data = re.sub(r"([a-z]+)", r"\n \1", data2) -#print data +# print data # use http://www.myezapp.com/apps/dev/regexp/show.ws to translate pattern = re.compile(r"[^-\d]*([\-]{0,1}\d+\.\d+)[^-\d]*") @@ -89,11 +90,21 @@ sets = [] i = 0 end = len(results) while i < end - 1: - sets.append((results[i + 0], results[i + 1], results[i + 2], - results[i + 3], results[i + 4], results[i + 5])) + sets.append( + ( + results[i + 0], + results[i + 1], + results[i + 2], + results[i + 3], + results[i + 4], + results[i + 5], + ) + ) i += 6 -print " Y and Z tilt differences for all parameters. Note that numbers are ROUNDED not truncated. " +print( + " Y and Z tilt differences for all parameters. Note that numbers are ROUNDED not truncated. " +) for t in sets: # print t a = float(t[4]) - float(t[1]) # Y @@ -104,13 +115,19 @@ for t in sets: str1 += " " str2 += " " if abs(a) > warningPrecision: - str1str = ", warning: this Y tilt difference is %7." + displayPrecision + "f mrad" + str1str = ( + ", warning: this Y tilt difference is %7." + displayPrecision + "f mrad" + ) str1 = str1str % a if abs(b) > warningPrecision: - str2str = ", warning: this Z tilt difference is %7." + displayPrecision + "f mrad" + str2str = ( + ", warning: this Z tilt difference is %7." + displayPrecision + "f mrad" + ) str2 = str2str % b - printString = " %7." + displayPrecision + "f , %s, %7." + displayPrecision + "f , %s " - print printString % (a, str1, b, str2) + printString = ( + " %7." + displayPrecision + "f , %s, %7." + displayPrecision + "f , %s " + ) + print(printString % (a, str1, b, str2)) -if (len(args.files) == 2): +if len(args.files) == 2: os.system("rm -rf " + tempfile) diff --git a/Rich/RichMirrorAlignmentGanga/scripts/getDataSet.py b/Rich/RichMirrorAlignmentGanga/scripts/getDataSet.py index 1afb3f23ea3b893c7b87f1d97ffd771b7c78afc8..8cdeb733a6c857d6020a516b280c02d2e976d94d 100644 --- a/Rich/RichMirrorAlignmentGanga/scripts/getDataSet.py +++ b/Rich/RichMirrorAlignmentGanga/scripts/getDataSet.py @@ -17,9 +17,9 @@ import sys # Obtains an integer from user def GetLastRun(): Lastrun = 0 - lastrun = raw_input("Enter last run to use, zero for default (9999999): ") + lastrun = input("Enter last run to use, zero for default (9999999): ") - if lastrun == '': + if lastrun == "": Lastrun = 0 else: Lastrun = int(lastrun) @@ -31,9 +31,9 @@ def GetLastRun(): # Obtains an integer from user def GetFirstRun(): Firstrun = 0 - firstrun = raw_input("Enter first run to use, zero for default (0): ") + firstrun = input("Enter first run to use, zero for default (0): ") - if firstrun == '': + if firstrun == "": Firstrun = 0 else: Firstrun = int(firstrun) @@ -51,11 +51,11 @@ def WriteFile(ouputFile, files, firstRun, Lastrun, scale): lines.append("IOHelper().inputFiles([\n") for file in files: i = i + 1 - if not (i % scale): #Take only every 'scale'th file + if not (i % scale): # Take only every 'scale'th file filename = file.name - k = filename.split('/') - run = int(k[8]) #Get RunNumber - if (run < Lastrun) and (run > firstRun): #Upper limit on RunNumber + k = filename.split("/") + run = int(k[8]) # Get RunNumber + if (run < Lastrun) and (run > firstRun): # Upper limit on RunNumber lines.append(" 'LFN:" + filename + "',\n") test = lines[-1].replace(",\n", "") del lines[-1] @@ -66,7 +66,7 @@ def WriteFile(ouputFile, files, firstRun, Lastrun, scale): for line in lines: f.write(line) - print "File", outputFile, "written" + print("File", outputFile, "written") f.close() @@ -74,46 +74,49 @@ def WriteFile(ouputFile, files, firstRun, Lastrun, scale): gridProxy.renew() -Data = str(raw_input("Enter year to align, 2011 or 2012?: ")) -if (Data != "2011" and Data != "2012"): - print Data, "You must enter either 2011 or 2012" +Data = str(input("Enter year to align, 2011 or 2012?: ")) +if Data != "2011" and Data != "2012": + print(Data, "You must enter either 2011 or 2012") sys.exit() -Mag = raw_input("Enter polarity to align, MagUp or MagDown?: ") -if (Mag != "MagUp" and Mag != "MagDown"): - print "You must enter either MagUp or MagDown" +Mag = input("Enter polarity to align, MagUp or MagDown?: ") +if Mag != "MagUp" and Mag != "MagDown": + print("You must enter either MagUp or MagDown") sys.exit() DataPath = "" -if (Data == "2011"): - DataPath = "/LHCb/Collision11/Beam3500GeV-VeloClosed-" + Mag + "/Real Data/91000000/RAW" -if (Data == "2012"): - DataPath = "/LHCb/Collision12/Beam4000GeV-VeloClosed-" + Mag + "/Real Data/91000000/RAW" +if Data == "2011": + DataPath = ( + "/LHCb/Collision11/Beam3500GeV-VeloClosed-" + Mag + "/Real Data/91000000/RAW" + ) +if Data == "2012": + DataPath = ( + "/LHCb/Collision12/Beam4000GeV-VeloClosed-" + Mag + "/Real Data/91000000/RAW" + ) FirstRun = GetFirstRun() Lastrun = GetLastRun() -outputFile = raw_input("OutputFile Name: ") +outputFile = input("OutputFile Name: ") if outputFile == "": outputFile = "LFN-Test.py" # We will only write every 'scale'th file # If scale is 1 then we will write every file scale = int( - raw_input( - "Enter Scale Factor (must enter an integer greater than or equal to 1): " - )) + input("Enter Scale Factor (must enter an integer greater than or equal to 1): ") +) bkq = BKQuery(path=DataPath, type="Path", dqflag="All") # 2011 path = "/LHCb/Collision12/Beam4000GeV-VeloClosed-MagUp/Real Data/91000000/RAW" # FULL path = "/LHCb/Collision12/Beam4000GeV-VeloClosed-MagDown/Real Data/90000000/RAW", # EXPRESS path = "/LHCb/Collision12/Beam4000GeV-VeloClosed-MagDown/Real Data/91000000/RAW", -print "Be patient, I'm getting the complete list of data files." +print("Be patient, I'm getting the complete list of data files.") ds = bkq.getDataset() -print "BKQuery().getDataset().files()" +print("BKQuery().getDataset().files()") files = ds.files -print "Got the files. Now writing the data LFNs to " + outputFile +print("Got the files. Now writing the data LFNs to " + outputFile) WriteFile(outputFile, files, FirstRun, Lastrun, scale) diff --git a/Rich/RichMirrorAlignmentOnline/doc/OldRichMirrorAlignment.txt b/Rich/RichMirrorAlignmentOnline/doc/OldRichMirrorAlignment.txt index 37efd67e69964ee3e92af63289c4708df9173564..995c31e1559e12d1febb6fd46748579cb1421ec3 100644 --- a/Rich/RichMirrorAlignmentOnline/doc/OldRichMirrorAlignment.txt +++ b/Rich/RichMirrorAlignmentOnline/doc/OldRichMirrorAlignment.txt @@ -1875,4 +1875,3 @@ else: print("Now exiting the mirror alignment driver python script.") print strftime("%Y-%m-%d %H:%M:%S", gmtime()) print "-------------------" - diff --git a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/MirrorAlignment/data_255358.py b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/MirrorAlignment/data_255358.py index 7e4dbb651e3f543e0d9b2fc5128fd3b9bfb0e76a..f18a44f0af350a36f7815f795714776c98f0356e 100644 --- a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/MirrorAlignment/data_255358.py +++ b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/MirrorAlignment/data_255358.py @@ -11,6 +11,7 @@ import os import re from datetime import datetime + from PyConf.application import ApplicationOptions filename_expr = re.compile( @@ -31,12 +32,8 @@ def sort_names(f): m = filename_expr.match(f) if m is None: return m - funs = [ - int, lambda t: int(datetime.strptime(t, "%Y%m%d-%H%M%S").timestamp()), - int - ] - return tuple( - fun(m.group(k)) for fun, k in zip(funs, ("run", "time", "rest"))) + funs = [int, lambda t: int(datetime.strptime(t, "%Y%m%d-%H%M%S").timestamp()), int] + return tuple(fun(m.group(k)) for fun, k in zip(funs, ("run", "time", "rest"))) files = [os.path.join(base_dir, f) for f in os.listdir(base_dir)] diff --git a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/MirrorAlignment/data_256292_HltR2.py b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/MirrorAlignment/data_256292_HltR2.py index 8f039ef6ae38f6985aacfd1465c87d5cdea58e2d..102c4368a5f98dc75194c2536b4d3cee3098f2cb 100644 --- a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/MirrorAlignment/data_256292_HltR2.py +++ b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/MirrorAlignment/data_256292_HltR2.py @@ -11,6 +11,7 @@ import os import re from datetime import datetime + from PyConf.application import ApplicationOptions filename_expr = re.compile(r"Run_0000256292_R2(?:[0-9]|[a-z]|[A-Z])+mdf") @@ -29,17 +30,13 @@ def sort_names(f): m = filename_expr.match(f) if m is None: return m - funs = [ - int, lambda t: int(datetime.strptime(t, "%Y%m%d-%H%M%S").timestamp()), - int - ] - return tuple( - fun(m.group(k)) for fun, k in zip(funs, ("run", "time", "rest"))) + funs = [int, lambda t: int(datetime.strptime(t, "%Y%m%d-%H%M%S").timestamp()), int] + return tuple(fun(m.group(k)) for fun, k in zip(funs, ("run", "time", "rest"))) files = [os.path.join(base_dir, f) for f in os.listdir(base_dir)] -#files = sorted(files, key=sort_names) +# files = sorted(files, key=sort_names) options.input_files = files -#options.input_files = files[:5] +# options.input_files = files[:5] print(options.input_files) diff --git a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/MirrorAlignment/data_online.py b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/MirrorAlignment/data_online.py index 278bff601a7493f9e85f17b14e880d7142036426..4694eea2aec6fa2b1407d4af9f2e7b70d3fa59fd 100644 --- a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/MirrorAlignment/data_online.py +++ b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/MirrorAlignment/data_online.py @@ -8,16 +8,18 @@ # granted to it by virtue of its status as an Intergovernmental Organization # # or submit itself to any jurisdiction. # ############################################################################### +import getpass import os -import sys import re +import sys from datetime import datetime -from PyConf.application import ApplicationOptions -import getpass +from pathlib import Path + from MooreOnlineConf.utils import ( # may need to check for online user in offline scenario, let's see - alignment_options, distribute_files, + alignment_options, + distribute_files, ) -from pathlib import Path +from PyConf.application import ApplicationOptions filename_expr = re.compile( r"Run_(?P<run>\d{10})_HLT(?P<node>\d{5})_(?P<time>(?:\d{8})-(?:\d{6}))-(?P<rest>\d{3})\.mdf" @@ -33,7 +35,7 @@ options.input_type = "MDF" base_dir = "/calib/align/LHCb/Rich/0000256292/" -#base_dir = "/calib/align/LHCb/Rich/0000261947/" +# base_dir = "/calib/align/LHCb/Rich/0000261947/" def sort_names(f): @@ -41,12 +43,8 @@ def sort_names(f): m = filename_expr.match(f) if m is None: return m - funs = [ - int, lambda t: int(datetime.strptime(t, "%Y%m%d-%H%M%S").timestamp()), - int - ] - return tuple( - fun(m.group(k)) for fun, k in zip(funs, ("run", "time", "rest"))) + funs = [int, lambda t: int(datetime.strptime(t, "%Y%m%d-%H%M%S").timestamp()), int] + return tuple(fun(m.group(k)) for fun, k in zip(funs, ("run", "time", "rest"))) absolutely_all_files = True @@ -56,35 +54,38 @@ divide_2022_2023 = 259566 if absolutely_all_files and exclude_2022 is False and exclude_2023 is False: import glob + base_dir = "/calib/align/LHCb/Rich/*/" dirs = glob.glob(base_dir, recursive=True) files = [] for dir_i in dirs: - files += glob.glob(dir_i + '*') + files += glob.glob(dir_i + "*") elif absolutely_all_files and exclude_2022 is True and exclude_2023 is False: import glob import re + base_dir = "/calib/align/LHCb/Rich/0000*/" dirs = glob.glob(base_dir, recursive=True) files = [] for dir_i in dirs: # PN - Extract the number from the directory string using regular expressions - WILL NOT WORK IF RUN NUMBERS BECOME 7 DIGITS - num = int(re.search(r'/0000(\d{6})/', dir_i).group(1)) + num = int(re.search(r"/0000(\d{6})/", dir_i).group(1)) # Check if the number is greater than or equal to 259 if num >= divide_2022_2023: - files += glob.glob(dir_i + '*') + files += glob.glob(dir_i + "*") elif absolutely_all_files and exclude_2022 is False and exclude_2023 is True: import glob import re + base_dir = "/calib/align/LHCb/Rich/0000*/" dirs = glob.glob(base_dir, recursive=True) files = [] for dir_i in dirs: # PN - Extract the number from the directory string using regular expressions - WILL NOT WORK IF RUN NUMBERS BECOME 7 DIGITS - num = int(re.search(r'/0000(\d{6})/', dir_i).group(1)) + num = int(re.search(r"/0000(\d{6})/", dir_i).group(1)) # Check if the number is greater than or equal to 259 if num < divide_2022_2023: - files += glob.glob(dir_i + '*') + files += glob.glob(dir_i + "*") elif absolutely_all_files and exclude_2022 is True and exclude_2023 is True: print("You just excluded everything") else: @@ -96,8 +97,8 @@ else: # print(file_size) # quit() -#files = files[:1000] -#files = files[:25] +# files = files[:1000] +# files = files[:25] # # files = sorted(files, key=sort_names) @@ -108,6 +109,7 @@ options.input_files = files if "online" in getpass.getuser(): import OnlineEnvBase as OnlineEnv + online_options = alignment_options(OnlineEnv) if OnlineEnv.PartitionName != "TESTALIGNMENT": # usually the case print("not on TESTALIGNMENT partition") @@ -115,10 +117,9 @@ if "online" in getpass.getuser(): print(f"online_options.runs {online_options.runs}") sys.stdout.flush() INPUT_DATA_PATH = Path("/calib/align/LHCb/Rich/") - #INPUT_DATA_PATH = Path(f"/calib/align/LHCb/Rich{whichRich}/") + # INPUT_DATA_PATH = Path(f"/calib/align/LHCb/Rich{whichRich}/") files = [ - sorted((INPUT_DATA_PATH / run).iterdir()) - for run in online_options.runs + sorted((INPUT_DATA_PATH / run).iterdir()) for run in online_options.runs ] else: # if on testbench PN: this may now crash the testbench if user is online; there may be also another problem as this is not files_per_run as I think is expected by distribute_files print("on TESTALIGNMENT partition") @@ -126,22 +127,20 @@ if "online" in getpass.getuser(): files = [sorted(INPUT_DATA_PATH.iterdir())] print(f"files {files}") sys.stdout.flush() - print(f'{sum(len(sublist) for sublist in files)} .mdf files...') + print(f"{sum(len(sublist) for sublist in files)} .mdf files...") sys.stdout.flush() file_size = 0 for file in [item for sublist in files for item in sublist]: file_size += os.path.getsize(file) - print('file_size', file_size) + print("file_size", file_size) sys.stdout.flush() print(f"online_options.nodes {online_options.nodes}") sys.stdout.flush() def distribute_files_alt(nodes, files): total_files = sum(files, []) # Flatten the files into a single list - n_files_per_node = len(total_files) // len( - nodes) # Number of files per node - extra_files = len(total_files) % len( - nodes) # Remaining files to distribute + n_files_per_node = len(total_files) // len(nodes) # Number of files per node + extra_files = len(total_files) % len(nodes) # Remaining files to distribute files_per_node = [] start_index = 0 @@ -157,7 +156,7 @@ if "online" in getpass.getuser(): return dict(zip(nodes, files_per_node)) - #files_per_node = distribute_files(online_options.nodes, files) + # files_per_node = distribute_files(online_options.nodes, files) files_per_node = distribute_files_alt(online_options.nodes, files) print(f"files_per_node {files_per_node}") sys.stdout.flush() @@ -170,8 +169,7 @@ if "online" in getpass.getuser(): # When testing we run multiple instances on the same node # TODO this should probably be done based on the partition name # and also "nodes" should be renamed to workers everywhere. - print("Trying multiple instances on same node" - ) # may not work for mirrAlign + print("Trying multiple instances on same node") # may not work for mirrAlign worker_id = utgid input_files = files_per_node[worker_id] @@ -181,10 +179,10 @@ if "online" in getpass.getuser(): sys.stdout.flush() options.input_files = input_files -print(f'{len(options.input_files)} .mdf files...') +print(f"{len(options.input_files)} .mdf files...") sys.stdout.flush() file_size = 0 for file in options.input_files: file_size += os.path.getsize(file) -print('file_size', file_size) +print("file_size", file_size) sys.stdout.flush() diff --git a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/MirrorAlignment/fit_hist.py b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/MirrorAlignment/fit_hist.py index 8f295fbe944b0ee62d6cc46ca5b9539cf33b9117..43c53a2208038212d4e6f60c17715e57b55a9e38 100644 --- a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/MirrorAlignment/fit_hist.py +++ b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/MirrorAlignment/fit_hist.py @@ -8,29 +8,43 @@ # granted to it by virtue of its status as an Intergovernmental Organization # # or submit itself to any jurisdiction. # ############################################################################### +import argparse import os import re import sys -import sys, numpy -from ROOT import TH1D, TCanvas, TFile, TF1, gStyle, TGraph, TMultiGraph, TLine, TH2D, TExec -import argparse +import numpy +from ROOT import ( + TF1, + TH1D, + TH2D, + TCanvas, + TExec, + TFile, + TGraph, + TLine, + TMultiGraph, + gStyle, +) class AlignMonitor: - def __init__(self, whichRich, file_nm - # _alignConf, - # _maxIt, - ): - ''' + def __init__( + self, + whichRich, + file_nm, + # _alignConf, + # _maxIt, + ): + """ self.alignConf = _alignConf self.nameStr = self.alignConf.getProp('nameStr') self.whichRich = self.alignConf.getProp('Rich') self.displayMode = self.alignConf.getProp('displayMode') self.warningFactor = self.alignConf.getProp('warningFactor') self.maxIt = _maxIt # the maximum labeled number of the iterations that we are looping through - ''' - self.workdir = './' + """ + self.workdir = "./" self.whichRich = whichRich self.maxIt = 0 self.prename = file_nm @@ -40,33 +54,41 @@ class AlignMonitor: self.maxpri = 3 self.binToPriMirr = [[2, 3], [0, 1]] self.maxsec = 15 - self.binToSecMirr = [[10, 11, 14, 15], [8, 9, 12, 13], [2, 3, 6, 7], - [0, 1, 4, 5]] + self.binToSecMirr = [ + [10, 11, 14, 15], + [8, 9, 12, 13], + [2, 3, 6, 7], + [0, 1, 4, 5], + ] self.fitMin = -0.005 self.fitMax = 0.005 - #self.fitMin = -0.01 - #self.fitMax = 0.01 + # self.fitMin = -0.01 + # self.fitMax = 0.01 # if RICH2, use RICH2 settings - if (self.whichRich == 2): + if self.whichRich == 2: self.maxpri = 55 - self.binToPriMirr = [[3, 2, 1, 0, 31, 30, 29, 28], - [7, 6, 5, 4, 35, 34, 33, 32], - [11, 10, 9, 8, 39, 38, 37, 36], - [15, 14, 13, 12, 43, 42, 41, 40], - [19, 18, 17, 16, 47, 46, 45, 44], - [23, 22, 21, 20, 51, 50, 49, 48], - [27, 26, 25, 24, 55, 54, 53, 52]] + self.binToPriMirr = [ + [3, 2, 1, 0, 31, 30, 29, 28], + [7, 6, 5, 4, 35, 34, 33, 32], + [11, 10, 9, 8, 39, 38, 37, 36], + [15, 14, 13, 12, 43, 42, 41, 40], + [19, 18, 17, 16, 47, 46, 45, 44], + [23, 22, 21, 20, 51, 50, 49, 48], + [27, 26, 25, 24, 55, 54, 53, 52], + ] self.maxsec = 39 - self.binToSecMirr = [[3, 2, 1, 0, 23, 22, 21, 20], - [7, 6, 5, 4, 27, 26, 25, 24], - [11, 10, 9, 8, 31, 30, 29, 28], - [15, 14, 13, 12, 35, 34, 33, 32], - [19, 18, 17, 16, 39, 38, 37, 36]] + self.binToSecMirr = [ + [3, 2, 1, 0, 23, 22, 21, 20], + [7, 6, 5, 4, 27, 26, 25, 24], + [11, 10, 9, 8, 31, 30, 29, 28], + [15, 14, 13, 12, 35, 34, 33, 32], + [19, 18, 17, 16, 39, 38, 37, 36], + ] # Original fit range self.fitMin = -0.0039 self.fitMax = 0.0035 - #self.fitMin = -0.002 - #self.fitMax = 0.002 + # self.fitMin = -0.002 + # self.fitMax = 0.002 self.isInsane = False self.finalCKres = None self.finalCKresErr = None @@ -74,24 +96,22 @@ class AlignMonitor: def performMonitoring(self): import os + gStyle.SetOptFit(1111) gStyle.SetOptStat(000000000) # File for the RICH piquet AND for the RICH mirror alignment experts - expertFile = self.workdir + 'Rich' + str( - self.whichRich) + '_AlignSummary.pdf' + expertFile = self.workdir + "Rich" + str(self.whichRich) + "_AlignSummary.pdf" # File for the Alignment piquet ("duplicating" what goes to the Presenter for the Data Manager [except CK angle res stuff]) - monitorFile = self.workdir + 'Rich' + str( - self.whichRich) + '_AlignMonitor.pdf' + monitorFile = self.workdir + "Rich" + str(self.whichRich) + "_AlignMonitor.pdf" # File with for testing purposes - testingFile = self.workdir + 'Rich' + str( - self.whichRich) + '_AlignTesting.pdf' + testingFile = self.workdir + "Rich" + str(self.whichRich) + "_AlignTesting.pdf" # Data Manager can only get histograms sent via self.monSvc - theCanvas = TCanvas('theCanvas', 'MirrAlign') + theCanvas = TCanvas("theCanvas", "MirrAlign") theCanvas.Divide(2, 2, 0.001, 0.001) - theCanvas2 = TCanvas('theCanvas2', 'MirrAlignTest') + theCanvas2 = TCanvas("theCanvas2", "MirrAlignTest") theCanvas2.Divide(2, 2, 0.001, 0.001) theCanvas2.Clear() @@ -128,57 +148,79 @@ class AlignMonitor: # define resHistoTrend resHistoTrend = TH1D( - 'resHistoTrend', 'RICH' + str(self.whichRich) + - ' Cherenkov angle resolution (mrad) per It. ', self.maxIt + 1, - -0.5, self.maxIt + 0.5) + "resHistoTrend", + "RICH" + + str(self.whichRich) + + " Cherenkov angle resolution (mrad) per It. ", + self.maxIt + 1, + -0.5, + self.maxIt + 0.5, + ) for j in reversed(range(0, self.maxIt + 1)): filename[j] = self.prename if os.path.exists(filename[j]): - thisFile[j] = TFile(filename[j], 'read') + thisFile[j] = TFile(filename[j], "read") if self.cuts: - hist[j] = (thisFile[j].Get( - f'RICH/RiCKResLongTight/Rich{self.whichRich}Gas/ckResAll' - )).Clone() + hist[j] = ( + thisFile[j].Get( + f"RICH/RiCKResLongTight/Rich{self.whichRich}Gas/ckResAll" + ) + ).Clone() else: - hist[j] = (thisFile[j].Get( - f'RICH/RiCKResLong/Rich{self.whichRich}Gas/ckResAll') - ).Clone() + hist[j] = ( + thisFile[j].Get( + f"RICH/RiCKResLong/Rich{self.whichRich}Gas/ckResAll" + ) + ).Clone() if (j == 0) and (j == self.maxIt): - hist[j].SetName('resHisto0') - hist[j].SetName('resHistoN') - elif (j == self.maxIt): - hist[j].SetName('resHistoN') - elif (j == 0): - hist[j].SetName('resHisto0') - if (j != 0): - hist[j].SetName('resHisto' + str(j)) + hist[j].SetName("resHisto0") + hist[j].SetName("resHistoN") + elif j == self.maxIt: + hist[j].SetName("resHistoN") + elif j == 0: + hist[j].SetName("resHisto0") + if j != 0: + hist[j].SetName("resHisto" + str(j)) fitRes[j] = self.fitCherenkovAngle(hist[j]) resHistograms[j] = fitRes[j][0] resHistoTrend.SetBinContent(j + 1, fitRes[j][1] * 1000) resHistoTrend.SetBinError(j + 1, fitRes[j][2] * 1000) - print("_i" + str(j) + " CK angle resolution: " + - str(fitRes[j][1] * 1000) + " mrad.") - print("_i" + str(j) + " CK angle resolution err: " + - str(fitRes[j][2] * 1000) + " mrad.") + print( + "_i" + + str(j) + + " CK angle resolution: " + + str(fitRes[j][1] * 1000) + + " mrad." + ) + print( + "_i" + + str(j) + + " CK angle resolution err: " + + str(fitRes[j][2] * 1000) + + " mrad." + ) if j == self.maxIt: self.finalCKres = fitRes[j][1] * 1000 self.finalCKresErr = fitRes[j][2] * 1000 - title[j] = 'RICH' + str( - self.whichRich) + ' Cherenkov angle resolution It. ' + str( - j) + title[j] = ( + "RICH" + + str(self.whichRich) + + " Cherenkov angle resolution It. " + + str(j) + ) resHistograms[j].SetTitle(title[j]) - resHistograms[j].SetXTitle('#Delta#theta_{Cherenkov} (rad)') - resHistograms[j].SetYTitle('Entries') + resHistograms[j].SetXTitle("#Delta#theta_{Cherenkov} (rad)") + resHistograms[j].SetYTitle("Entries") histFunc[j] = resHistograms[j].GetFunction( - "Rich" + str(self.whichRich) + "fFitF3") - polbkg[j] = TF1("polBKG" + str(j), "pol3(0)", self.fitMin, - self.fitMax) + "Rich" + str(self.whichRich) + "fFitF3" + ) + polbkg[j] = TF1("polBKG" + str(j), "pol3(0)", self.fitMin, self.fitMax) polbkg[j].SetParameter(0, histFunc[j].GetParameter(3)) polbkg[j].SetParameter(1, histFunc[j].GetParameter(4)) polbkg[j].SetParameter(2, histFunc[j].GetParameter(5)) @@ -198,15 +240,14 @@ class AlignMonitor: resHistograms[j].Draw() polbkg[j].Draw("SAME") - #theCanvas.Print(monitorFile) + # theCanvas.Print(monitorFile) sys.stdout.flush() # Make resHistoTrend iteration trend plot resHistoTrend.SetMarkerStyle(8) - resHistoTrend.SetXTitle('iteration number') - resHistoTrend.SetYTitle( - '#splitline{Cherenkov angle resolution (mrad)}{}') + resHistoTrend.SetXTitle("iteration number") + resHistoTrend.SetYTitle("#splitline{Cherenkov angle resolution (mrad)}{}") theCanvas2.Clear() theCanvas.Clear() @@ -214,12 +255,12 @@ class AlignMonitor: sys.stdout.flush() def fitCherenkovAngle(self, hist): - richStr = 'Rich' + str(self.whichRich) + richStr = "Rich" + str(self.whichRich) m_maxErrorForOK = 1e-3 xPeak = hist.GetBinCenter(hist.GetMaximumBin()) delta = 0 - if (richStr == 'Rich1'): + if richStr == "Rich1": delta = 0.0025 else: delta = 0.00105 @@ -231,7 +272,7 @@ class AlignMonitor: preFitF = TF1(preFitFName, "gaus", fitMin, fitMax) preFitF.SetParameter(1, 0) - if (richStr == 'Rich1'): + if richStr == "Rich1": preFitF.SetParameter(2, 0.0015) else: preFitF.SetParameter(2, 0.0007) @@ -255,7 +296,7 @@ class AlignMonitor: fFitF.SetParName(1, "Gaus Mean") fFitF.SetParName(2, "Gaus Sigma") nParamsToSet = 3 - if (nPol > 1): + if nPol > 1: nParamsToSet = 3 + nPol for p in range(0, nParamsToSet): @@ -268,17 +309,19 @@ class AlignMonitor: bestFitF = fFitF bestNPol = nPol else: - if (nPol == nPolFull): + if nPol == nPolFull: hist.Fit(fFitF, "RFSE0QM") fitOK = True if nPol > 1: break - print([ - fFitF.GetParameter(3), - fFitF.GetParameter(4), - fFitF.GetParameter(5), - fFitF.GetParameter(6) - ]) + print( + [ + fFitF.GetParameter(3), + fFitF.GetParameter(4), + fFitF.GetParameter(5), + fFitF.GetParameter(6), + ] + ) fitRes = [hist, fFitF.GetParameter(2), fFitF.GetParError(2)] return fitRes @@ -293,15 +336,14 @@ def monitor(whichRich, file_nm): # can minimise using monitor() as function to minimise if returns finalCKres and has arg inputs -if __name__ == '__main__': +if __name__ == "__main__": parser = argparse.ArgumentParser( - description="Fits histogram to obtain Rich CK angle resolution") + description="Fits histogram to obtain Rich CK angle resolution" + ) parser.add_argument( - 'whichRich', - choices=[1, 2], - type=int, - help='Which Rich detector to use') - parser.add_argument('file_nm', help='Name of root file to use') + "whichRich", choices=[1, 2], type=int, help="Which Rich detector to use" + ) + parser.add_argument("file_nm", help="Name of root file to use") args = parser.parse_args() whichRich = args.whichRich file_nm = args.file_nm diff --git a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/MirrorAlignment/go_rich1.py b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/MirrorAlignment/go_rich1.py index da77f6cc0988a349f80e9bcc08c550c89181d630..4452c043e4cedc778970f0b9d9f0ba5a8181c5d5 100644 --- a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/MirrorAlignment/go_rich1.py +++ b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/MirrorAlignment/go_rich1.py @@ -11,12 +11,12 @@ import hlt2_reco_rich_noUT_panoptes_dd4hep_both print(__name__) -''' +""" if __name__ == 'builtins': my_class_instance = hlt2_reco_rich_noUT_panoptes_dd4hep_both(whichRich=1) print(my_class_instance) my_class_instance.run() -''' +""" my_class_instance = hlt2_reco_rich_noUT_panoptes_dd4hep_both(whichRich=1) print(my_class_instance) diff --git a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/MirrorAlignment/go_rich2.py b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/MirrorAlignment/go_rich2.py index 7a2c2077171e0b1d504390e9a4fd69b17493afcf..f559652bab41a8509cdac3873d7dc283010726f4 100644 --- a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/MirrorAlignment/go_rich2.py +++ b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/MirrorAlignment/go_rich2.py @@ -11,12 +11,12 @@ import hlt2_reco_rich_noUT_panoptes_dd4hep_both print(__name__) -''' +""" if __name__ == 'builtins': my_class_instance = hlt2_reco_rich_noUT_panoptes_dd4hep_both(whichRich=2) print(my_class_instance) my_class_instance.run() -''' +""" my_class_instance = hlt2_reco_rich_noUT_panoptes_dd4hep_both(whichRich=2) print(my_class_instance) diff --git a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/MirrorAlignment/hlt2_reco_rich1_noUT_panoptes_dd4hep_both.py b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/MirrorAlignment/hlt2_reco_rich1_noUT_panoptes_dd4hep_both.py index 8f721171f792a9befe51872f8c84d5ba7fb4c0f8..25b1f623500a2ad13f6cab046f76dd5bc85fdd1c 100644 --- a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/MirrorAlignment/hlt2_reco_rich1_noUT_panoptes_dd4hep_both.py +++ b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/MirrorAlignment/hlt2_reco_rich1_noUT_panoptes_dd4hep_both.py @@ -8,18 +8,20 @@ # granted to it by virtue of its status as an Intergovernmental Organization # # or submit itself to any jurisdiction. # ############################################################################### -import glob import csv -import math import datetime -from ruamel.yaml import YAML -import sys -import os, re +import getpass +import glob +import math +import os +import re import shutil +import sys import time from time import gmtime, strftime + from PyMirrAlignOnline.Communicator import * -import getpass +from ruamel.yaml import YAML print(f"RichAnalyzer __name__ = {__name__}") @@ -29,7 +31,7 @@ class hlt2_reco_rich_noUT_panoptes_dd4hep_both: self.whichRich = self.Rich() def Rich( - self + self, ): # RichAnalyzer must be running in the workDir for this to be correct def check_directory(): cwd = os.getcwd() @@ -49,29 +51,30 @@ class hlt2_reco_rich_noUT_panoptes_dd4hep_both: def run(self): # main code whichRich = self.whichRich - rich = f'rich{whichRich}' - radiator = f'Rich{whichRich}Gas' + rich = f"rich{whichRich}" + radiator = f"Rich{whichRich}Gas" if whichRich == 1: from Configurables import Rich1MirrAlignOnConf - #from Configuration import Rich1MirrAlignOnConf + + # from Configuration import Rich1MirrAlignOnConf alignConf = Rich1MirrAlignOnConf() elif whichRich == 2: from Configurables import Rich2MirrAlignOnConf - #from Configuration import Rich2MirrAlignOnConf + + # from Configuration import Rich2MirrAlignOnConf alignConf = Rich2MirrAlignOnConf() alignConf.__apply_configuration__() - EvtMax = alignConf.getProp('EvtMax') # this isn't currently used - workdir = alignConf.getProp('WorkDir') - useHltDecisions = alignConf.getProp('useHltDecisions') - dataVariant = alignConf.getProp('dataVariant') + EvtMax = alignConf.getProp("EvtMax") # this isn't currently used + workdir = alignConf.getProp("WorkDir") + useHltDecisions = alignConf.getProp("useHltDecisions") + dataVariant = alignConf.getProp("dataVariant") runAnalyzer = "UNKNOWN" while runAnalyzer != "YES": yaml = YAML() - while not os.path.exists( - f"{workdir}rich{whichRich}_runAnalyzer.yml"): + while not os.path.exists(f"{workdir}rich{whichRich}_runAnalyzer.yml"): time.sleep(4) with open(f"{workdir}rich{whichRich}_runAnalyzer.yml") as finp: runAnalyzer = yaml.load(finp) @@ -110,81 +113,114 @@ class hlt2_reco_rich_noUT_panoptes_dd4hep_both: # Since we are doing this by hand, specify the iteration number in stdin if count == 2 and arguments[1] in [ - '0', '1', '2', '3', '4', '5', '6', '7', '8' + "0", + "1", + "2", + "3", + "4", + "5", + "6", + "7", + "8", ]: n_it = int(arguments[1]) if count == 1 and arguments[0] in [ - '0', '1', '2', '3', '4', '5', '6', '7', '8' + "0", + "1", + "2", + "3", + "4", + "5", + "6", + "7", + "8", ]: n_it = int(arguments[0]) # possible tiltname can be given via stdin if count == 2 and arguments[0] in [ - "priYn", "priYp", "priZn", "priZp", "secYn", "secYp", - "secZn", "secZp" + "priYn", + "priYp", + "priZn", + "priZp", + "secYn", + "secYp", + "secZn", + "secZp", ]: tiltName = arguments[0] # For Rich1 - #tiltName = "" # uses 'alignment2022' - #tiltName = "priYn" # uses '2022_12_06_Rich1_priYn', a branch of 'alignment2022' - #tiltName = "priYp" # uses '2022_12_06_Rich1 - #tiltName = "priZn" # uses '2022_12_06_Rich1 - #tiltName = "priZp" # uses '2022_12_06_Rich1 - #tiltName = "secYn" # uses '2022_12_06_Rich1 - #tiltName = "secYp" # uses '2022_12_06_Rich1 - #tiltName = "secZn" # uses '2022_12_06_Rich1 - #tiltName = "secZp" # uses '2022_12_06_Rich1 + # tiltName = "" # uses 'alignment2022' + # tiltName = "priYn" # uses '2022_12_06_Rich1_priYn', a branch of 'alignment2022' + # tiltName = "priYp" # uses '2022_12_06_Rich1 + # tiltName = "priZn" # uses '2022_12_06_Rich1 + # tiltName = "priZp" # uses '2022_12_06_Rich1 + # tiltName = "secYn" # uses '2022_12_06_Rich1 + # tiltName = "secYp" # uses '2022_12_06_Rich1 + # tiltName = "secZn" # uses '2022_12_06_Rich1 + # tiltName = "secZp" # uses '2022_12_06_Rich1 # For Rich2 - #tiltName = "" # uses '2022_12_08_Rich2_2018' - #tiltName = "priYn" # uses '2022_??_??_Rich2_priYn', a branch of '2022_12_08_Rich2_2018' - #tiltName = "priYp" # uses '2022_??_??_Rich2 - #tiltName = "priZn" # uses '2022_??_??_Rich2 - #tiltName = "priZp" # uses '2022_??_??_Rich2 - #tiltName = "secYn" # uses '2022_??_??_Rich2 - #tiltName = "secYp" # uses '2022_??_??_Rich2 - #tiltName = "secZn" # uses '2022_??_??_Rich2 - #tiltName = "secZp" # uses '2022_??_??_Rich2 + # tiltName = "" # uses '2022_12_08_Rich2_2018' + # tiltName = "priYn" # uses '2022_??_??_Rich2_priYn', a branch of '2022_12_08_Rich2_2018' + # tiltName = "priYp" # uses '2022_??_??_Rich2 + # tiltName = "priZn" # uses '2022_??_??_Rich2 + # tiltName = "priZp" # uses '2022_??_??_Rich2 + # tiltName = "secYn" # uses '2022_??_??_Rich2 + # tiltName = "secYp" # uses '2022_??_??_Rich2 + # tiltName = "secZn" # uses '2022_??_??_Rich2 + # tiltName = "secZp" # uses '2022_??_??_Rich2 print(f"INFO: Iteration: {n_it}") print(f"INFO: Tilt Name: {tiltName}") if tiltName not in [ - "", "priYn", "priYp", "priZn", "priZp", "secYn", "secYp", - "secZn", "secZp" + "", + "priYn", + "priYp", + "priZn", + "priZp", + "secYn", + "secYp", + "secZn", + "secZp", ]: print(f"ERROR: This is not a valid tiltName") sys.stdout.flush() - from GaudiKernel.SystemOfUnits import (GeV, MeV, mm, mrad) + from GaudiKernel.SystemOfUnits import GeV, MeV, mm, mrad from Moore import ( options, run_reconstruction, ) - + from Panoptes.alignment import ( + standalone_rich_online_align_reco, + standalone_rich_panel_align_reco, + ) + from PyConf.Algorithms import ( + PrForwardTrackingVelo, + PrHybridSeeding, + PrMatchNN, + VeloRetinaClusterTrackingSIMD, + VPRetinaFullClusterDecoder, + ) + from RecoConf.legacy_rec_hlt1_tracking import ( + make_PatPV3DFuture_pvs, + make_reco_pvs, + make_velo_full_clusters, + make_VeloClusterTrackingSIMD, + ) from RecoConf.rich_data_monitoring import ( - default_rich_monitoring_options, alignment_rich_monitoring_options, + default_rich_monitoring_options, ) - - from PyConf.Algorithms import (PrForwardTrackingVelo, - VPRetinaFullClusterDecoder) - from PyConf.Algorithms import PrMatchNN, PrHybridSeeding - from PyConf.Algorithms import VeloRetinaClusterTrackingSIMD - from RecoConf.legacy_rec_hlt1_tracking import ( - make_VeloClusterTrackingSIMD, make_reco_pvs, - make_PatPV3DFuture_pvs, make_velo_full_clusters) - from RecoConf.rich_reconstruction import default_rich_reco_options - from Panoptes.alignment import ( - standalone_rich_online_align_reco, - standalone_rich_panel_align_reco, - ) """Options for running over data with FT raw bank version 6.""" from RecoConf.decoders import ( - default_ft_decoding_version, ) + default_ft_decoding_version, + ) options.scheduler_legacy_mode = False - #options.use_iosvc = False + # options.use_iosvc = False options.n_threads = 20 # 1 print(f"Using HLT decisions: {useHltDecisions}") @@ -198,8 +234,9 @@ class hlt2_reco_rich_noUT_panoptes_dd4hep_both: options.input_type = "MDF" else: options.set_input_and_conds_from_testfiledb( - 'upgrade_Sept2022_minbias_0fb_md_xdigi') - options.input_type = 'ROOT' + "upgrade_Sept2022_minbias_0fb_md_xdigi" + ) + options.input_type = "ROOT" useDD4Hep = True @@ -220,38 +257,49 @@ class hlt2_reco_rich_noUT_panoptes_dd4hep_both: from Configurables import DDDBConf if "Collision23" in dataVariant: - dd4hep = DD4hepSvc(DetectorList=[ - "/world", "Magnet", "VP", "FT", "Rich1", "Rich2" - ]) + dd4hep = DD4hepSvc( + DetectorList=["/world", "Magnet", "VP", "FT", "Rich1", "Rich2"] + ) elif "Collision22" in dataVariant: - dd4hep = DD4hepSvc(DetectorList=[ - "/world", "Magnet", "UT", "VP", "FT", "Rich1", "Rich2" - ]) + dd4hep = DD4hepSvc( + DetectorList=[ + "/world", + "Magnet", + "UT", + "VP", + "FT", + "Rich1", + "Rich2", + ] + ) dd4hep.OutputLevel = 1 richFilesDir = alignConf.getProp( - 'richFiles') # '/group/rich/AlignmentFiles/' + "richFiles" + ) # '/group/rich/AlignmentFiles/' if useCondDBPath: if "Collision23" in dataVariant: - conddb_path = f'{richFilesDir}lhcb-conditions-database_master_CloneForRich' + conddb_path = ( + f"{richFilesDir}lhcb-conditions-database_master_CloneForRich" + ) elif "Collision22" in dataVariant: - conddb_path = f'{richFilesDir}lhcb-conditions-database_alignment2022_SingleNodeIterator' + conddb_path = f"{richFilesDir}lhcb-conditions-database_alignment2022_SingleNodeIterator" dd4hep.ConditionsLocation = f"file://{conddb_path}" else: - dd4hep.ConditionsLocation = 'git:/cvmfs/lhcb.cern.ch/lib/lhcb/git-conddb/lhcb-conditions-database.git' + dd4hep.ConditionsLocation = "git:/cvmfs/lhcb.cern.ch/lib/lhcb/git-conddb/lhcb-conditions-database.git" if useRealData: - options.conddb_tag = 'master' # used for real data - options.dddb_tag = 'run3/trunk' - DDDBConf().GeometryVersion = 'run3/trunk' # used for real data + options.conddb_tag = "master" # used for real data + options.dddb_tag = "run3/trunk" + DDDBConf().GeometryVersion = "run3/trunk" # used for real data # Which branch? dd4hep.UseConditionsOverlay = True if useCondDBPath: if "Collision23" in dataVariant: - dd4hep.ConditionsVersion = 'master' + dd4hep.ConditionsVersion = "master" elif "Collision22" in dataVariant: - dd4hep.ConditionsVersion = 'alignment2022' + dd4hep.ConditionsVersion = "alignment2022" # PN - Here we only want to replace the # latest Mirrors YAML in the git clone DB @@ -261,14 +309,14 @@ class hlt2_reco_rich_noUT_panoptes_dd4hep_both: # We don't really need this part, unless we later choose to # get the latest DB from the git clone DB # (we currently get it from the online DB, I think) - #from subprocess import * - #cmd = "cd " + conddb_path + " ; git checkout . ; cd - " - #p = Popen( + # from subprocess import * + # cmd = "cd " + conddb_path + " ; git checkout . ; cd - " + # p = Popen( # cmd, # shell=True, # executable="/bin/bash") - #p.communicate() - #sys.stdout.flush() + # p.communicate() + # sys.stdout.flush() re_version = re.compile(r"^([0-9]+)$") @@ -284,7 +332,8 @@ class hlt2_reco_rich_noUT_panoptes_dd4hep_both: os.listdir( f"{conddb_path}/Conditions/Rich{whichRich}/Alignment/Mirrors.yml/" ), - key=get_version) + key=get_version, + ) toFile = f"{conddb_path}/Conditions/Rich{whichRich}/Alignment/Mirrors.yml/{latestName}" print(f"INFO: Copying {fromFile} to {toFile}") shutil.copyfile(fromFile, toFile) @@ -292,30 +341,41 @@ class hlt2_reco_rich_noUT_panoptes_dd4hep_both: else: if whichRich == 1: - if (tiltName == "" and n_it == 0): - dd4hep.ConditionsVersion = f'alignment2022' - elif (n_it >= 1): - dd4hep.ConditionsVersion = f'2022_12_06_Rich{whichRich}_i{n_it}_new' + if tiltName == "" and n_it == 0: + dd4hep.ConditionsVersion = f"alignment2022" + elif n_it >= 1: + dd4hep.ConditionsVersion = ( + f"2022_12_06_Rich{whichRich}_i{n_it}_new" + ) else: - dd4hep.ConditionsVersion = f'2022_12_06_Rich{whichRich}_{tiltName}' + dd4hep.ConditionsVersion = ( + f"2022_12_06_Rich{whichRich}_{tiltName}" + ) else: - if (tiltName == "" and n_it == 0): - dd4hep.ConditionsVersion = f'2022_12_08_Rich{whichRich}_2018' - elif (n_it >= 1): - dd4hep.ConditionsVersion = f'2022_12_08_Rich{whichRich}_i{n_it}_new' + if tiltName == "" and n_it == 0: + dd4hep.ConditionsVersion = ( + f"2022_12_08_Rich{whichRich}_2018" + ) + elif n_it >= 1: + dd4hep.ConditionsVersion = ( + f"2022_12_08_Rich{whichRich}_i{n_it}_new" + ) else: - dd4hep.ConditionsVersion = f'2022_12_08_Rich{whichRich}_{tiltName}' + dd4hep.ConditionsVersion = ( + f"2022_12_08_Rich{whichRich}_{tiltName}" + ) else: - options.conddb_tag = 'jonrob/all-pmts-active' # used for DetDesc MC samples with DD4Hep - DDDBConf( - ).GeometryVersion = 'before-rich1-geom-update-26052022' # used for DetDesc MC samples with DD4Hep + options.conddb_tag = ( + "jonrob/all-pmts-active" # used for DetDesc MC samples with DD4Hep + ) + DDDBConf().GeometryVersion = "before-rich1-geom-update-26052022" # used for DetDesc MC samples with DD4Hep else: - options.conddb_tag = 'upgrade/sim-20220612-vc-md100-RICHcustomFTv6' + options.conddb_tag = "upgrade/sim-20220612-vc-md100-RICHcustomFTv6" options.simulation = True - param_list = ['p0_x', 'p1_x', 'p0_y', 'p1_y', 'p0_z', 'p1_z'] + param_list = ["p0_x", "p1_x", "p0_y", "p1_y", "p0_z", "p1_z"] param_dict = dict.fromkeys(param_list) # Only edit bad_align to play with alignment parameters @@ -347,7 +407,7 @@ class hlt2_reco_rich_noUT_panoptes_dd4hep_both: align_opts = {} # Reco opts - wider_bkg = {"PhotonSelection": 'None'} + wider_bkg = {"PhotonSelection": "None"} default_reco_opts.update(wider_bkg) panel_select = {"ActivatePanel": (True, True)} default_reco_opts.update(panel_select) @@ -368,7 +428,7 @@ class hlt2_reco_rich_noUT_panoptes_dd4hep_both: # Check if "_" is found before "k_" if underscore_index != -1: # Extract the substring between the last "_" and "k_" - num_str = current_variant[underscore_index + 1:k_index] + num_str = current_variant[underscore_index + 1 : k_index] try: if "O" in num_str: # this is O not 0 options.evt_max = EvtMax @@ -390,9 +450,7 @@ class hlt2_reco_rich_noUT_panoptes_dd4hep_both: f"INFO: evt_max is extracted as {options.evt_max} events from current_variant." ) except ValueError: - print( - "ERROR: Unable to convert extracted substring to integer." - ) + print("ERROR: Unable to convert extracted substring to integer.") else: print("ERROR: '_' not found before 'k_'.") else: @@ -410,8 +468,7 @@ class hlt2_reco_rich_noUT_panoptes_dd4hep_both: # Check if "_" is found after "minp" if underscore_index != -1: # Extract the substring between "minp" and "_" - num_str = current_variant[minp_index + - len("minp"):underscore_index] + num_str = current_variant[minp_index + len("minp") : underscore_index] try: # Convert the extracted substring to a float (double) minP = float(num_str) @@ -419,9 +476,7 @@ class hlt2_reco_rich_noUT_panoptes_dd4hep_both: f"INFO: Extracted track momentum cut as {minP} GeV from current_variant." ) except ValueError: - print( - "ERROR: Unable to convert extracted substring to float." - ) + print("ERROR: Unable to convert extracted substring to float.") else: print("ERROR: Underscore not found after minp.") else: @@ -441,29 +496,30 @@ class hlt2_reco_rich_noUT_panoptes_dd4hep_both: } } default_moni_opts.update(tighter_minp) - wider_histo = {'CKResHistoRange': (0.025, 0.005, 0.004)} + wider_histo = {"CKResHistoRange": (0.025, 0.005, 0.004)} default_moni_opts.update(wider_histo) - useUT = {'UseUT': False} + useUT = {"UseUT": False} default_moni_opts.update(useUT) PrForwardTrackingVelo.global_bind( MinQuality=0.0, DeltaQuality=0.0, MinTotalHits=9, - MaxChi2PerDoF=50., - MaxChi2XProjection=60., - MaxChi2PerDoFFinal=28., - MaxChi2Stereo=16., - MaxChi2StereoAdd=16., + MaxChi2PerDoF=50.0, + MaxChi2XProjection=60.0, + MaxChi2PerDoFFinal=28.0, + MaxChi2Stereo=16.0, + MaxChi2StereoAdd=16.0, ) make_VeloClusterTrackingSIMD.global_bind( - algorithm=VeloRetinaClusterTrackingSIMD) + algorithm=VeloRetinaClusterTrackingSIMD + ) make_velo_full_clusters.global_bind( - make_full_cluster=VPRetinaFullClusterDecoder) - make_reco_pvs.global_bind( - make_pvs_from_velo_tracks=make_PatPV3DFuture_pvs) - ''' + make_full_cluster=VPRetinaFullClusterDecoder + ) + make_reco_pvs.global_bind(make_pvs_from_velo_tracks=make_PatPV3DFuture_pvs) + """ # Possible mirror align tasks are: mirror_align_tasks = [ 'Produce', # fill the production set of histograms @@ -474,7 +530,7 @@ class hlt2_reco_rich_noUT_panoptes_dd4hep_both: #'Calibrate', # check filling all RICH2 mirror combinations with elimination when filled # 'Explore', # explore influence of RICH1 coordinate systems on distribution shapes ] - ''' + """ # Define the regular expression pattern to match the desired substring pattern = r"_(O|\d+)k_([^_]+)" @@ -484,29 +540,27 @@ class hlt2_reco_rich_noUT_panoptes_dd4hep_both: if match: # Extract the number and subsequent substring from the match object - #number = match.group(1) + # number = match.group(1) substr = match.group(2) # Split the subsequent substring by "_" and store in a list mirror_align_tasks = substr.split("_") - #print("Number:", number) + # print("Number:", number) print( f"INFO: mirror_align_tasks = {mirror_align_tasks} extracted from current_variant." ) else: - print( - "ERROR: mirror_align_tasks pattern not found in current_variant." - ) + print("ERROR: mirror_align_tasks pattern not found in current_variant.") sys.stdout.flush() - ''' + """ if 'md' in options.conddb_tag: mp = 'md' elif 'mu' in options.conddb_tag: mp = 'mu' else: mp = 'Collision22' - + n_kevts = f"{math.trunc(options.evt_max / 1000)}k" addinfo = f'_minp{math.trunc(minP)}_subset_' + mp + "_" + n_kevts @@ -517,7 +571,7 @@ class hlt2_reco_rich_noUT_panoptes_dd4hep_both: tasks = '' for task in mirror_align_tasks: tasks += f"_{task}" - + # create timestamp # now = datetime.datetime.now() # dt = now.isoformat(timespec='minutes') # Anatoly's old timestamp @@ -526,95 +580,97 @@ class hlt2_reco_rich_noUT_panoptes_dd4hep_both: yaml = YAML() with open(f"./rich{whichRich}_session_timestamp.yml") as inp: ts = yaml.load(inp) - + # form the current variant name current_variant = f"{ts}_rich{whichRich}{addinfo}{tasks}" - ''' + """ - if 'subset' in current_variant: + if "subset" in current_variant: if whichRich == 1: central_mirr_combs = { "PrebookHistos": [ - ('p00', 's03'), - ('p01', 's06'), - ('p02', 's12'), - ('p03', 's09'), + ("p00", "s03"), + ("p01", "s06"), + ("p02", "s12"), + ("p03", "s09"), ], } else: central_mirr_combs = { "PrebookHistos": [ - ('p17', 's13'), - ('p47', 's35'), - ('p17', 's09'), - ('p47', 's31'), - ('p16', 's12'), - ('p46', 's34'), - ('p16', 's08'), - ('p46', 's30'), - ('p13', 's10'), - ('p43', 's31'), - ('p13', 's09'), - ('p43', 's30'), - ('p12', 's09'), - ('p42', 's30'), - ('p12', 's08'), - ('p42', 's29'), - ('p09', 's09'), - ('p39', 's31'), - ('p09', 's05'), - ('p39', 's27'), - ('p08', 's08'), - ('p38', 's30'), - ('p08', 's04'), - ('p38', 's26'), + ("p17", "s13"), + ("p47", "s35"), + ("p17", "s09"), + ("p47", "s31"), + ("p16", "s12"), + ("p46", "s34"), + ("p16", "s08"), + ("p46", "s30"), + ("p13", "s10"), + ("p43", "s31"), + ("p13", "s09"), + ("p43", "s30"), + ("p12", "s09"), + ("p42", "s30"), + ("p12", "s08"), + ("p42", "s29"), + ("p09", "s09"), + ("p39", "s31"), + ("p09", "s05"), + ("p39", "s27"), + ("p08", "s08"), + ("p38", "s30"), + ("p08", "s04"), + ("p38", "s26"), ], } align_opts.update(central_mirr_combs) align_opts.update({"MinP4Align": minP * GeV}) - #if 'theta2' in current_variant: + # if 'theta2' in current_variant: # align_opts.update({"DeltaThetaRange": 0.002}) - align_opts.update({"PoorestPopulation": 279.}) + align_opts.update({"PoorestPopulation": 279.0}) - if (tiltName == ""): + if tiltName == "": connectStr = "" else: connectStr = "_" # save output file with histograms if UseDD4Hep: - #options.histo_file = f'rich{whichRich}_opt_dd4hep.root' - options.histo_file = f"{workdir}{current_variant}_histos{connectStr}{tiltName}_i{n_it}.root" + # options.histo_file = f'rich{whichRich}_opt_dd4hep.root' + options.histo_file = ( + f"{workdir}{current_variant}_histos{connectStr}{tiltName}_i{n_it}.root" + ) else: - options.histo_file = f'rich{whichRich}_opt.root' + options.histo_file = f"rich{whichRich}_opt.root" # prepare part of the overridden options in use # to be recorded into a YAML file align_opts_dump = alignment_rich_monitoring_options( - radiator=radiator, init_override_opts=align_opts) + radiator=radiator, init_override_opts=align_opts + ) # add overridden default_rich_monitoring_options # to the part of the options in use to be recorded into the YAML file align_opts_dump.update( - default_rich_monitoring_options( - init_override_opts=default_moni_opts)) + default_rich_monitoring_options(init_override_opts=default_moni_opts) + ) # retrieve the timestamp - ts = re.findall(r'[\d]{4}-[\d]{2}-[\d]{2}T[\d]{2}-[\d]{2}', - current_variant)[0] + ts = re.findall(r"[\d]{4}-[\d]{2}-[\d]{2}T[\d]{2}-[\d]{2}", current_variant)[0] # prepare options in use to be recorded into the YAML file opts_dump = {} opts_dump[ts] = {} - opts_dump[ts]['reco_opts'] = align_opts_dump + opts_dump[ts]["reco_opts"] = align_opts_dump # append YAML file with the part of the options in use - with open(f"{workdir}{rich}_reco_opts.yml", 'a') as out: + with open(f"{workdir}{rich}_reco_opts.yml", "a") as out: yaml.dump(opts_dump, out) - ''' + """ # To get the JSON right (old) from AllenCore.configuration_options import is_allen_standalone is_allen_standalone.global_bind(standalone=True) @@ -622,8 +678,8 @@ class hlt2_reco_rich_noUT_panoptes_dd4hep_both: import hlt1_pp_no_gec_no_ut #import hlt1_pp_forward_then_matching_no_ut_no_gec #import passthrough - ''' - ''' + """ + """ # To get the JSON right from PyConf.Algorithms import LHCb__UnpackRawEvent, HltDecReportsDecoder, HltSelReportsDecoder #, ApplicationMgr #from PyConf.application import configured_ann_svc @@ -646,37 +702,45 @@ class hlt2_reco_rich_noUT_panoptes_dd4hep_both: #app = ApplicationMgr( # TopAlg=[unpacker, decDec, selDec], # ExtSvc=[configured_ann_svc(name='HltANNSvc')]) - ''' + """ # by default, no additional filtering of the events event_filter = [] # Prepare filter - lines = (['Hlt1RICH1AlignmentDecision'] - if whichRich == 1 else ['Hlt1RICH2AlignmentDecision']) + lines = ( + ["Hlt1RICH1AlignmentDecision"] + if whichRich == 1 + else ["Hlt1RICH2AlignmentDecision"] + ) from PyConf.application import ( default_raw_banks, default_raw_event, ) + options.input_raw_format = 0.5 - default_raw_event.global_bind( - raw_event_format=options.input_raw_format) + default_raw_event.global_bind(raw_event_format=options.input_raw_format) + import Functors from PyConf.Algorithms import ( - VoidFilter, HltDecReportsDecoder as PyConf_Algorithms_HltDecReportsDecoder, ) - import Functors + from PyConf.Algorithms import ( + VoidFilter, + ) + hlt1_dec_reports = PyConf_Algorithms_HltDecReportsDecoder( - SourceID='Hlt1', RawBanks=default_raw_banks("HltDecReports")) + SourceID="Hlt1", RawBanks=default_raw_banks("HltDecReports") + ) hlt1_filter = VoidFilter( - name='Streaming_filter', + name="Streaming_filter", OutputLevel=1, Cut=Functors.DECREPORTS_FILTER( - Lines=lines, - DecReports=hlt1_dec_reports.OutputHltDecReportsLocation)) + Lines=lines, DecReports=hlt1_dec_reports.OutputHltDecReportsLocation + ), + ) # when particular decision of HLT1 line about RICH1 or RICH2 is wanted if useHltDecisions: @@ -702,17 +766,23 @@ class hlt2_reco_rich_noUT_panoptes_dd4hep_both: print(f"options.histo_file {options.histo_file}") sys.stdout.flush() - with standalone_rich_online_align_reco.bind(RichGas=radiator, MirrorAlignTasks = mirror_align_tasks,\ - EventFilter=event_filter, \ - noUT=True), \ - alignment_rich_monitoring_options.bind(radiator=radiator, \ - init_override_opts=align_opts), \ - default_ft_decoding_version.bind(value=6), \ - default_rich_reco_options.bind(init_override_opts=default_reco_opts), \ - default_rich_monitoring_options.bind(init_override_opts=default_moni_opts): + with ( + standalone_rich_online_align_reco.bind( + RichGas=radiator, + MirrorAlignTasks=mirror_align_tasks, + EventFilter=event_filter, + noUT=True, + ), + alignment_rich_monitoring_options.bind( + radiator=radiator, init_override_opts=align_opts + ), + default_ft_decoding_version.bind(value=6), + default_rich_reco_options.bind(init_override_opts=default_reco_opts), + default_rich_monitoring_options.bind(init_override_opts=default_moni_opts), + ): run_reconstruction(options, standalone_rich_online_align_reco) -if __name__ == 'builtins': +if __name__ == "builtins": RichAnalyzer_instance = hlt2_reco_rich_noUT_panoptes_dd4hep_both() RichAnalyzer_instance.run() diff --git a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/MirrorAlignment/hlt2_reco_rich2_noUT_panoptes_dd4hep_both.py b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/MirrorAlignment/hlt2_reco_rich2_noUT_panoptes_dd4hep_both.py index 8855fad6abb029a9b69a88c49cf836aff91d0feb..773b52a6184931df917da12b63f1ee99939880fd 100644 --- a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/MirrorAlignment/hlt2_reco_rich2_noUT_panoptes_dd4hep_both.py +++ b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/MirrorAlignment/hlt2_reco_rich2_noUT_panoptes_dd4hep_both.py @@ -8,18 +8,20 @@ # granted to it by virtue of its status as an Intergovernmental Organization # # or submit itself to any jurisdiction. # ############################################################################### -import glob import csv -import math import datetime -from ruamel.yaml import YAML -import sys -import os, re +import getpass +import glob +import math +import os +import re import shutil +import sys import time from time import gmtime, strftime + from PyMirrAlignOnline.Communicator import * -import getpass +from ruamel.yaml import YAML print(f"RichAnalyzer __name__ = {__name__}") @@ -29,7 +31,7 @@ class hlt2_reco_rich_noUT_panoptes_dd4hep_both: self.whichRich = self.Rich() def Rich( - self + self, ): # RichAnalyzer must be running in the workDir for this to be correct def check_directory(): cwd = os.getcwd() @@ -49,29 +51,30 @@ class hlt2_reco_rich_noUT_panoptes_dd4hep_both: def run(self): # main code whichRich = self.whichRich - rich = f'rich{whichRich}' - radiator = f'Rich{whichRich}Gas' + rich = f"rich{whichRich}" + radiator = f"Rich{whichRich}Gas" if whichRich == 1: from Configurables import Rich1MirrAlignOnConf - #from Configuration import Rich1MirrAlignOnConf + + # from Configuration import Rich1MirrAlignOnConf alignConf = Rich1MirrAlignOnConf() elif whichRich == 2: from Configurables import Rich2MirrAlignOnConf - #from Configuration import Rich2MirrAlignOnConf + + # from Configuration import Rich2MirrAlignOnConf alignConf = Rich2MirrAlignOnConf() alignConf.__apply_configuration__() - EvtMax = alignConf.getProp('EvtMax') # this isn't currently used - workdir = alignConf.getProp('WorkDir') - useHltDecisions = alignConf.getProp('useHltDecisions') - dataVariant = alignConf.getProp('dataVariant') + EvtMax = alignConf.getProp("EvtMax") # this isn't currently used + workdir = alignConf.getProp("WorkDir") + useHltDecisions = alignConf.getProp("useHltDecisions") + dataVariant = alignConf.getProp("dataVariant") runAnalyzer = "UNKNOWN" while runAnalyzer != "YES": yaml = YAML() - while not os.path.exists( - f"{workdir}rich{whichRich}_runAnalyzer.yml"): + while not os.path.exists(f"{workdir}rich{whichRich}_runAnalyzer.yml"): time.sleep(4) with open(f"{workdir}rich{whichRich}_runAnalyzer.yml") as finp: runAnalyzer = yaml.load(finp) @@ -110,81 +113,114 @@ class hlt2_reco_rich_noUT_panoptes_dd4hep_both: # Since we are doing this by hand, specify the iteration number in stdin if count == 2 and arguments[1] in [ - '0', '1', '2', '3', '4', '5', '6', '7', '8' + "0", + "1", + "2", + "3", + "4", + "5", + "6", + "7", + "8", ]: n_it = int(arguments[1]) if count == 1 and arguments[0] in [ - '0', '1', '2', '3', '4', '5', '6', '7', '8' + "0", + "1", + "2", + "3", + "4", + "5", + "6", + "7", + "8", ]: n_it = int(arguments[0]) # possible tiltname can be given via stdin if count == 2 and arguments[0] in [ - "priYn", "priYp", "priZn", "priZp", "secYn", "secYp", - "secZn", "secZp" + "priYn", + "priYp", + "priZn", + "priZp", + "secYn", + "secYp", + "secZn", + "secZp", ]: tiltName = arguments[0] # For Rich1 - #tiltName = "" # uses 'alignment2022' - #tiltName = "priYn" # uses '2022_12_06_Rich1_priYn', a branch of 'alignment2022' - #tiltName = "priYp" # uses '2022_12_06_Rich1 - #tiltName = "priZn" # uses '2022_12_06_Rich1 - #tiltName = "priZp" # uses '2022_12_06_Rich1 - #tiltName = "secYn" # uses '2022_12_06_Rich1 - #tiltName = "secYp" # uses '2022_12_06_Rich1 - #tiltName = "secZn" # uses '2022_12_06_Rich1 - #tiltName = "secZp" # uses '2022_12_06_Rich1 + # tiltName = "" # uses 'alignment2022' + # tiltName = "priYn" # uses '2022_12_06_Rich1_priYn', a branch of 'alignment2022' + # tiltName = "priYp" # uses '2022_12_06_Rich1 + # tiltName = "priZn" # uses '2022_12_06_Rich1 + # tiltName = "priZp" # uses '2022_12_06_Rich1 + # tiltName = "secYn" # uses '2022_12_06_Rich1 + # tiltName = "secYp" # uses '2022_12_06_Rich1 + # tiltName = "secZn" # uses '2022_12_06_Rich1 + # tiltName = "secZp" # uses '2022_12_06_Rich1 # For Rich2 - #tiltName = "" # uses '2022_12_08_Rich2_2018' - #tiltName = "priYn" # uses '2022_??_??_Rich2_priYn', a branch of '2022_12_08_Rich2_2018' - #tiltName = "priYp" # uses '2022_??_??_Rich2 - #tiltName = "priZn" # uses '2022_??_??_Rich2 - #tiltName = "priZp" # uses '2022_??_??_Rich2 - #tiltName = "secYn" # uses '2022_??_??_Rich2 - #tiltName = "secYp" # uses '2022_??_??_Rich2 - #tiltName = "secZn" # uses '2022_??_??_Rich2 - #tiltName = "secZp" # uses '2022_??_??_Rich2 + # tiltName = "" # uses '2022_12_08_Rich2_2018' + # tiltName = "priYn" # uses '2022_??_??_Rich2_priYn', a branch of '2022_12_08_Rich2_2018' + # tiltName = "priYp" # uses '2022_??_??_Rich2 + # tiltName = "priZn" # uses '2022_??_??_Rich2 + # tiltName = "priZp" # uses '2022_??_??_Rich2 + # tiltName = "secYn" # uses '2022_??_??_Rich2 + # tiltName = "secYp" # uses '2022_??_??_Rich2 + # tiltName = "secZn" # uses '2022_??_??_Rich2 + # tiltName = "secZp" # uses '2022_??_??_Rich2 print(f"INFO: Iteration: {n_it}") print(f"INFO: Tilt Name: {tiltName}") if tiltName not in [ - "", "priYn", "priYp", "priZn", "priZp", "secYn", "secYp", - "secZn", "secZp" + "", + "priYn", + "priYp", + "priZn", + "priZp", + "secYn", + "secYp", + "secZn", + "secZp", ]: print(f"ERROR: This is not a valid tiltName") sys.stdout.flush() - from GaudiKernel.SystemOfUnits import (GeV, MeV, mm, mrad) + from GaudiKernel.SystemOfUnits import GeV, MeV, mm, mrad from Moore import ( options, run_reconstruction, ) - + from Panoptes.alignment import ( + standalone_rich_online_align_reco, + standalone_rich_panel_align_reco, + ) + from PyConf.Algorithms import ( + PrForwardTrackingVelo, + PrHybridSeeding, + PrMatchNN, + VeloRetinaClusterTrackingSIMD, + VPRetinaFullClusterDecoder, + ) + from RecoConf.legacy_rec_hlt1_tracking import ( + make_PatPV3DFuture_pvs, + make_reco_pvs, + make_velo_full_clusters, + make_VeloClusterTrackingSIMD, + ) from RecoConf.rich_data_monitoring import ( - default_rich_monitoring_options, alignment_rich_monitoring_options, + default_rich_monitoring_options, ) - - from PyConf.Algorithms import (PrForwardTrackingVelo, - VPRetinaFullClusterDecoder) - from PyConf.Algorithms import PrMatchNN, PrHybridSeeding - from PyConf.Algorithms import VeloRetinaClusterTrackingSIMD - from RecoConf.legacy_rec_hlt1_tracking import ( - make_VeloClusterTrackingSIMD, make_reco_pvs, - make_PatPV3DFuture_pvs, make_velo_full_clusters) - from RecoConf.rich_reconstruction import default_rich_reco_options - from Panoptes.alignment import ( - standalone_rich_online_align_reco, - standalone_rich_panel_align_reco, - ) """Options for running over data with FT raw bank version 6.""" from RecoConf.decoders import ( - default_ft_decoding_version, ) + default_ft_decoding_version, + ) options.scheduler_legacy_mode = False - #options.use_iosvc = False + # options.use_iosvc = False options.n_threads = 20 # 1 print(f"Using HLT decisions: {useHltDecisions}") @@ -198,8 +234,9 @@ class hlt2_reco_rich_noUT_panoptes_dd4hep_both: options.input_type = "MDF" else: options.set_input_and_conds_from_testfiledb( - 'upgrade_Sept2022_minbias_0fb_md_xdigi') - options.input_type = 'ROOT' + "upgrade_Sept2022_minbias_0fb_md_xdigi" + ) + options.input_type = "ROOT" useDD4Hep = True @@ -220,38 +257,49 @@ class hlt2_reco_rich_noUT_panoptes_dd4hep_both: from Configurables import DDDBConf if "Collision23" in dataVariant: - dd4hep = DD4hepSvc(DetectorList=[ - "/world", "Magnet", "VP", "FT", "Rich1", "Rich2" - ]) + dd4hep = DD4hepSvc( + DetectorList=["/world", "Magnet", "VP", "FT", "Rich1", "Rich2"] + ) elif "Collision22" in dataVariant: - dd4hep = DD4hepSvc(DetectorList=[ - "/world", "Magnet", "UT", "VP", "FT", "Rich1", "Rich2" - ]) + dd4hep = DD4hepSvc( + DetectorList=[ + "/world", + "Magnet", + "UT", + "VP", + "FT", + "Rich1", + "Rich2", + ] + ) dd4hep.OutputLevel = 1 richFilesDir = alignConf.getProp( - 'richFiles') # '/group/rich/AlignmentFiles/' + "richFiles" + ) # '/group/rich/AlignmentFiles/' if useCondDBPath: if "Collision23" in dataVariant: - conddb_path = f'{richFilesDir}lhcb-conditions-database_master_CloneForRich' + conddb_path = ( + f"{richFilesDir}lhcb-conditions-database_master_CloneForRich" + ) elif "Collision22" in dataVariant: - conddb_path = f'{richFilesDir}lhcb-conditions-database_alignment2022_SingleNodeIterator' + conddb_path = f"{richFilesDir}lhcb-conditions-database_alignment2022_SingleNodeIterator" dd4hep.ConditionsLocation = f"file://{conddb_path}" else: - dd4hep.ConditionsLocation = 'git:/cvmfs/lhcb.cern.ch/lib/lhcb/git-conddb/lhcb-conditions-database.git' + dd4hep.ConditionsLocation = "git:/cvmfs/lhcb.cern.ch/lib/lhcb/git-conddb/lhcb-conditions-database.git" if useRealData: - options.conddb_tag = 'master' # used for real data - options.dddb_tag = 'run3/trunk' - DDDBConf().GeometryVersion = 'run3/trunk' # used for real data + options.conddb_tag = "master" # used for real data + options.dddb_tag = "run3/trunk" + DDDBConf().GeometryVersion = "run3/trunk" # used for real data # Which branch? dd4hep.UseConditionsOverlay = True if useCondDBPath: if "Collision23" in dataVariant: - dd4hep.ConditionsVersion = 'master' + dd4hep.ConditionsVersion = "master" elif "Collision22" in dataVariant: - dd4hep.ConditionsVersion = 'alignment2022' + dd4hep.ConditionsVersion = "alignment2022" # PN - Here we only want to replace the # latest Mirrors YAML in the git clone DB @@ -261,14 +309,14 @@ class hlt2_reco_rich_noUT_panoptes_dd4hep_both: # We don't really need this part, unless we later choose to # get the latest DB from the git clone DB # (we currently get it from the online DB, I think) - #from subprocess import * - #cmd = "cd " + conddb_path + " ; git checkout . ; cd - " - #p = Popen( + # from subprocess import * + # cmd = "cd " + conddb_path + " ; git checkout . ; cd - " + # p = Popen( # cmd, # shell=True, # executable="/bin/bash") - #p.communicate() - #sys.stdout.flush() + # p.communicate() + # sys.stdout.flush() re_version = re.compile(r"^([0-9]+)$") @@ -284,7 +332,8 @@ class hlt2_reco_rich_noUT_panoptes_dd4hep_both: os.listdir( f"{conddb_path}/Conditions/Rich{whichRich}/Alignment/Mirrors.yml/" ), - key=get_version) + key=get_version, + ) toFile = f"{conddb_path}/Conditions/Rich{whichRich}/Alignment/Mirrors.yml/{latestName}" print(f"INFO: Copying {fromFile} to {toFile}") shutil.copyfile(fromFile, toFile) @@ -292,30 +341,41 @@ class hlt2_reco_rich_noUT_panoptes_dd4hep_both: else: if whichRich == 1: - if (tiltName == "" and n_it == 0): - dd4hep.ConditionsVersion = f'alignment2022' - elif (n_it >= 1): - dd4hep.ConditionsVersion = f'2022_12_06_Rich{whichRich}_i{n_it}_new' + if tiltName == "" and n_it == 0: + dd4hep.ConditionsVersion = f"alignment2022" + elif n_it >= 1: + dd4hep.ConditionsVersion = ( + f"2022_12_06_Rich{whichRich}_i{n_it}_new" + ) else: - dd4hep.ConditionsVersion = f'2022_12_06_Rich{whichRich}_{tiltName}' + dd4hep.ConditionsVersion = ( + f"2022_12_06_Rich{whichRich}_{tiltName}" + ) else: - if (tiltName == "" and n_it == 0): - dd4hep.ConditionsVersion = f'2022_12_08_Rich{whichRich}_2018' - elif (n_it >= 1): - dd4hep.ConditionsVersion = f'2022_12_08_Rich{whichRich}_i{n_it}_new' + if tiltName == "" and n_it == 0: + dd4hep.ConditionsVersion = ( + f"2022_12_08_Rich{whichRich}_2018" + ) + elif n_it >= 1: + dd4hep.ConditionsVersion = ( + f"2022_12_08_Rich{whichRich}_i{n_it}_new" + ) else: - dd4hep.ConditionsVersion = f'2022_12_08_Rich{whichRich}_{tiltName}' + dd4hep.ConditionsVersion = ( + f"2022_12_08_Rich{whichRich}_{tiltName}" + ) else: - options.conddb_tag = 'jonrob/all-pmts-active' # used for DetDesc MC samples with DD4Hep - DDDBConf( - ).GeometryVersion = 'before-rich1-geom-update-26052022' # used for DetDesc MC samples with DD4Hep + options.conddb_tag = ( + "jonrob/all-pmts-active" # used for DetDesc MC samples with DD4Hep + ) + DDDBConf().GeometryVersion = "before-rich1-geom-update-26052022" # used for DetDesc MC samples with DD4Hep else: - options.conddb_tag = 'upgrade/sim-20220612-vc-md100-RICHcustomFTv6' + options.conddb_tag = "upgrade/sim-20220612-vc-md100-RICHcustomFTv6" options.simulation = True - param_list = ['p0_x', 'p1_x', 'p0_y', 'p1_y', 'p0_z', 'p1_z'] + param_list = ["p0_x", "p1_x", "p0_y", "p1_y", "p0_z", "p1_z"] param_dict = dict.fromkeys(param_list) # Only edit bad_align to play with alignment parameters @@ -347,7 +407,7 @@ class hlt2_reco_rich_noUT_panoptes_dd4hep_both: align_opts = {} # Reco opts - wider_bkg = {"PhotonSelection": 'None'} + wider_bkg = {"PhotonSelection": "None"} default_reco_opts.update(wider_bkg) panel_select = {"ActivatePanel": (True, True)} default_reco_opts.update(panel_select) @@ -368,7 +428,7 @@ class hlt2_reco_rich_noUT_panoptes_dd4hep_both: # Check if "_" is found before "k_" if underscore_index != -1: # Extract the substring between the last "_" and "k_" - num_str = current_variant[underscore_index + 1:k_index] + num_str = current_variant[underscore_index + 1 : k_index] try: if "O" in num_str: # this is O not 0 options.evt_max = EvtMax @@ -390,9 +450,7 @@ class hlt2_reco_rich_noUT_panoptes_dd4hep_both: f"INFO: evt_max is extracted as {options.evt_max} events from current_variant." ) except ValueError: - print( - "ERROR: Unable to convert extracted substring to integer." - ) + print("ERROR: Unable to convert extracted substring to integer.") else: print("ERROR: '_' not found before 'k_'.") else: @@ -410,8 +468,7 @@ class hlt2_reco_rich_noUT_panoptes_dd4hep_both: # Check if "_" is found after "minp" if underscore_index != -1: # Extract the substring between "minp" and "_" - num_str = current_variant[minp_index + - len("minp"):underscore_index] + num_str = current_variant[minp_index + len("minp") : underscore_index] try: # Convert the extracted substring to a float (double) minP = float(num_str) @@ -419,9 +476,7 @@ class hlt2_reco_rich_noUT_panoptes_dd4hep_both: f"INFO: Extracted track momentum cut as {minP} GeV from current_variant." ) except ValueError: - print( - "ERROR: Unable to convert extracted substring to float." - ) + print("ERROR: Unable to convert extracted substring to float.") else: print("ERROR: Underscore not found after minp.") else: @@ -441,29 +496,30 @@ class hlt2_reco_rich_noUT_panoptes_dd4hep_both: } } default_moni_opts.update(tighter_minp) - wider_histo = {'CKResHistoRange': (0.025, 0.005, 0.004)} + wider_histo = {"CKResHistoRange": (0.025, 0.005, 0.004)} default_moni_opts.update(wider_histo) - useUT = {'UseUT': False} + useUT = {"UseUT": False} default_moni_opts.update(useUT) PrForwardTrackingVelo.global_bind( MinQuality=0.0, DeltaQuality=0.0, MinTotalHits=9, - MaxChi2PerDoF=50., - MaxChi2XProjection=60., - MaxChi2PerDoFFinal=28., - MaxChi2Stereo=16., - MaxChi2StereoAdd=16., + MaxChi2PerDoF=50.0, + MaxChi2XProjection=60.0, + MaxChi2PerDoFFinal=28.0, + MaxChi2Stereo=16.0, + MaxChi2StereoAdd=16.0, ) make_VeloClusterTrackingSIMD.global_bind( - algorithm=VeloRetinaClusterTrackingSIMD) + algorithm=VeloRetinaClusterTrackingSIMD + ) make_velo_full_clusters.global_bind( - make_full_cluster=VPRetinaFullClusterDecoder) - make_reco_pvs.global_bind( - make_pvs_from_velo_tracks=make_PatPV3DFuture_pvs) - ''' + make_full_cluster=VPRetinaFullClusterDecoder + ) + make_reco_pvs.global_bind(make_pvs_from_velo_tracks=make_PatPV3DFuture_pvs) + """ # Possible mirror align tasks are: mirror_align_tasks = [ 'Produce', # fill the production set of histograms @@ -474,7 +530,7 @@ class hlt2_reco_rich_noUT_panoptes_dd4hep_both: #'Calibrate', # check filling all RICH2 mirror combinations with elimination when filled # 'Explore', # explore influence of RICH1 coordinate systems on distribution shapes ] - ''' + """ # Define the regular expression pattern to match the desired substring pattern = r"_(O|\d+)k_([^_]+)" @@ -484,29 +540,27 @@ class hlt2_reco_rich_noUT_panoptes_dd4hep_both: if match: # Extract the number and subsequent substring from the match object - #number = match.group(1) + # number = match.group(1) substr = match.group(2) # Split the subsequent substring by "_" and store in a list mirror_align_tasks = substr.split("_") - #print("Number:", number) + # print("Number:", number) print( f"INFO: mirror_align_tasks = {mirror_align_tasks} extracted from current_variant." ) else: - print( - "ERROR: mirror_align_tasks pattern not found in current_variant." - ) + print("ERROR: mirror_align_tasks pattern not found in current_variant.") sys.stdout.flush() - ''' + """ if 'md' in options.conddb_tag: mp = 'md' elif 'mu' in options.conddb_tag: mp = 'mu' else: mp = 'Collision22' - + n_kevts = f"{math.trunc(options.evt_max / 1000)}k" addinfo = f'_minp{math.trunc(minP)}_subset_' + mp + "_" + n_kevts @@ -517,7 +571,7 @@ class hlt2_reco_rich_noUT_panoptes_dd4hep_both: tasks = '' for task in mirror_align_tasks: tasks += f"_{task}" - + # create timestamp # now = datetime.datetime.now() # dt = now.isoformat(timespec='minutes') # Anatoly's old timestamp @@ -526,95 +580,97 @@ class hlt2_reco_rich_noUT_panoptes_dd4hep_both: yaml = YAML() with open(f"./rich{whichRich}_session_timestamp.yml") as inp: ts = yaml.load(inp) - + # form the current variant name current_variant = f"{ts}_rich{whichRich}{addinfo}{tasks}" - ''' + """ - if 'subset' in current_variant: + if "subset" in current_variant: if whichRich == 1: central_mirr_combs = { "PrebookHistos": [ - ('p00', 's03'), - ('p01', 's06'), - ('p02', 's12'), - ('p03', 's09'), + ("p00", "s03"), + ("p01", "s06"), + ("p02", "s12"), + ("p03", "s09"), ], } else: central_mirr_combs = { "PrebookHistos": [ - ('p17', 's13'), - ('p47', 's35'), - ('p17', 's09'), - ('p47', 's31'), - ('p16', 's12'), - ('p46', 's34'), - ('p16', 's08'), - ('p46', 's30'), - ('p13', 's10'), - ('p43', 's31'), - ('p13', 's09'), - ('p43', 's30'), - ('p12', 's09'), - ('p42', 's30'), - ('p12', 's08'), - ('p42', 's29'), - ('p09', 's09'), - ('p39', 's31'), - ('p09', 's05'), - ('p39', 's27'), - ('p08', 's08'), - ('p38', 's30'), - ('p08', 's04'), - ('p38', 's26'), + ("p17", "s13"), + ("p47", "s35"), + ("p17", "s09"), + ("p47", "s31"), + ("p16", "s12"), + ("p46", "s34"), + ("p16", "s08"), + ("p46", "s30"), + ("p13", "s10"), + ("p43", "s31"), + ("p13", "s09"), + ("p43", "s30"), + ("p12", "s09"), + ("p42", "s30"), + ("p12", "s08"), + ("p42", "s29"), + ("p09", "s09"), + ("p39", "s31"), + ("p09", "s05"), + ("p39", "s27"), + ("p08", "s08"), + ("p38", "s30"), + ("p08", "s04"), + ("p38", "s26"), ], } align_opts.update(central_mirr_combs) align_opts.update({"MinP4Align": minP * GeV}) - #if 'theta2' in current_variant: + # if 'theta2' in current_variant: # align_opts.update({"DeltaThetaRange": 0.002}) - align_opts.update({"PoorestPopulation": 279.}) + align_opts.update({"PoorestPopulation": 279.0}) - if (tiltName == ""): + if tiltName == "": connectStr = "" else: connectStr = "_" # save output file with histograms if UseDD4Hep: - #options.histo_file = f'rich{whichRich}_opt_dd4hep.root' - options.histo_file = f"{workdir}{current_variant}_histos{connectStr}{tiltName}_i{n_it}.root" + # options.histo_file = f'rich{whichRich}_opt_dd4hep.root' + options.histo_file = ( + f"{workdir}{current_variant}_histos{connectStr}{tiltName}_i{n_it}.root" + ) else: - options.histo_file = f'rich{whichRich}_opt.root' + options.histo_file = f"rich{whichRich}_opt.root" # prepare part of the overridden options in use # to be recorded into a YAML file align_opts_dump = alignment_rich_monitoring_options( - radiator=radiator, init_override_opts=align_opts) + radiator=radiator, init_override_opts=align_opts + ) # add overridden default_rich_monitoring_options # to the part of the options in use to be recorded into the YAML file align_opts_dump.update( - default_rich_monitoring_options( - init_override_opts=default_moni_opts)) + default_rich_monitoring_options(init_override_opts=default_moni_opts) + ) # retrieve the timestamp - ts = re.findall(r'[\d]{4}-[\d]{2}-[\d]{2}T[\d]{2}-[\d]{2}', - current_variant)[0] + ts = re.findall(r"[\d]{4}-[\d]{2}-[\d]{2}T[\d]{2}-[\d]{2}", current_variant)[0] # prepare options in use to be recorded into the YAML file opts_dump = {} opts_dump[ts] = {} - opts_dump[ts]['reco_opts'] = align_opts_dump + opts_dump[ts]["reco_opts"] = align_opts_dump # append YAML file with the part of the options in use - with open(f"{workdir}{rich}_reco_opts.yml", 'a') as out: + with open(f"{workdir}{rich}_reco_opts.yml", "a") as out: yaml.dump(opts_dump, out) - ''' + """ # To get the JSON right (old) from AllenCore.configuration_options import is_allen_standalone is_allen_standalone.global_bind(standalone=True) @@ -622,8 +678,8 @@ class hlt2_reco_rich_noUT_panoptes_dd4hep_both: import hlt1_pp_no_gec_no_ut #import hlt1_pp_forward_then_matching_no_ut_no_gec #import passthrough - ''' - ''' + """ + """ # To get the JSON right from PyConf.Algorithms import LHCb__UnpackRawEvent, HltDecReportsDecoder, HltSelReportsDecoder #, ApplicationMgr #from PyConf.application import configured_ann_svc @@ -646,37 +702,45 @@ class hlt2_reco_rich_noUT_panoptes_dd4hep_both: #app = ApplicationMgr( # TopAlg=[unpacker, decDec, selDec], # ExtSvc=[configured_ann_svc(name='HltANNSvc')]) - ''' + """ # by default, no additional filtering of the events event_filter = [] # Prepare filter - lines = (['Hlt1RICH1AlignmentDecision'] - if whichRich == 1 else ['Hlt1RICH2AlignmentDecision']) + lines = ( + ["Hlt1RICH1AlignmentDecision"] + if whichRich == 1 + else ["Hlt1RICH2AlignmentDecision"] + ) from PyConf.application import ( default_raw_banks, default_raw_event, ) + options.input_raw_format = 0.5 - default_raw_event.global_bind( - raw_event_format=options.input_raw_format) + default_raw_event.global_bind(raw_event_format=options.input_raw_format) + import Functors from PyConf.Algorithms import ( - VoidFilter, HltDecReportsDecoder as PyConf_Algorithms_HltDecReportsDecoder, ) - import Functors + from PyConf.Algorithms import ( + VoidFilter, + ) + hlt1_dec_reports = PyConf_Algorithms_HltDecReportsDecoder( - SourceID='Hlt1', RawBanks=default_raw_banks("HltDecReports")) + SourceID="Hlt1", RawBanks=default_raw_banks("HltDecReports") + ) hlt1_filter = VoidFilter( - name='Streaming_filter', + name="Streaming_filter", OutputLevel=1, Cut=Functors.DECREPORTS_FILTER( - Lines=lines, - DecReports=hlt1_dec_reports.OutputHltDecReportsLocation)) + Lines=lines, DecReports=hlt1_dec_reports.OutputHltDecReportsLocation + ), + ) # when particular decision of HLT1 line about RICH1 or RICH2 is wanted if useHltDecisions: @@ -702,17 +766,23 @@ class hlt2_reco_rich_noUT_panoptes_dd4hep_both: print(f"options.histo_file {options.histo_file}") sys.stdout.flush() - with standalone_rich_online_align_reco.bind(RichGas=radiator, MirrorAlignTasks = mirror_align_tasks,\ - EventFilter=event_filter, \ - noUT=True), \ - alignment_rich_monitoring_options.bind(radiator=radiator, \ - init_override_opts=align_opts), \ - default_ft_decoding_version.bind(value=6), \ - default_rich_reco_options.bind(init_override_opts=default_reco_opts), \ - default_rich_monitoring_options.bind(init_override_opts=default_moni_opts): + with ( + standalone_rich_online_align_reco.bind( + RichGas=radiator, + MirrorAlignTasks=mirror_align_tasks, + EventFilter=event_filter, + noUT=True, + ), + alignment_rich_monitoring_options.bind( + radiator=radiator, init_override_opts=align_opts + ), + default_ft_decoding_version.bind(value=6), + default_rich_reco_options.bind(init_override_opts=default_reco_opts), + default_rich_monitoring_options.bind(init_override_opts=default_moni_opts), + ): run_reconstruction(options, standalone_rich_online_align_reco) -if __name__ == 'builtins': +if __name__ == "builtins": RichAnalyzer_instance = hlt2_reco_rich_noUT_panoptes_dd4hep_both() RichAnalyzer_instance.run() diff --git a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/MirrorAlignment/rich1_session_timestamp.py b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/MirrorAlignment/rich1_session_timestamp.py index 9359428d3f767aad9d542eb4173660c0ed73ffaf..1c522f43ec092599c69b8d0b1ddda6f79d9dd0ab 100644 --- a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/MirrorAlignment/rich1_session_timestamp.py +++ b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/MirrorAlignment/rich1_session_timestamp.py @@ -9,10 +9,12 @@ # or submit itself to any jurisdiction. # ############################################################################### from datetime import datetime + from ruamel.yaml import YAML + yaml = YAML() -dt = datetime.now().isoformat(timespec='minutes') +dt = datetime.now().isoformat(timespec="minutes") dt = dt.replace(":", "-") # Anatoly's new timestamp -with open('rich1_session_timestamp.yml', 'w') as fout: +with open("rich1_session_timestamp.yml", "w") as fout: yaml.dump(dt, fout) diff --git a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/MirrorAlignment/rich2_session_timestamp.py b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/MirrorAlignment/rich2_session_timestamp.py index ea401434479beeae42f8789361b8371ee5fa54b8..1310f24b2eda2e98a40a54a37e1afc5c7207656f 100644 --- a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/MirrorAlignment/rich2_session_timestamp.py +++ b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/MirrorAlignment/rich2_session_timestamp.py @@ -9,10 +9,12 @@ # or submit itself to any jurisdiction. # ############################################################################### from datetime import datetime + from ruamel.yaml import YAML + yaml = YAML() -dt = datetime.now().isoformat(timespec='minutes') +dt = datetime.now().isoformat(timespec="minutes") dt = dt.replace(":", "-") # Anatoly's new timestamp -with open('rich2_session_timestamp.yml', 'w') as fout: +with open("rich2_session_timestamp.yml", "w") as fout: yaml.dump(dt, fout) diff --git a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/MirrorAlignment/run_RICH1.sh b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/MirrorAlignment/run_RICH1.sh index d26f84e818784e678409bd577ef06729a64446d7..231e59ecf368b12c2bc18e418a60027c1cfa1ae8 100644 --- a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/MirrorAlignment/run_RICH1.sh +++ b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/MirrorAlignment/run_RICH1.sh @@ -8,7 +8,7 @@ # granted to it by virtue of its status as an Intergovernmental Organization # # or submit itself to any jurisdiction. # ############################################################################### -# Uncomment this to change the timestamp (you do not want to do this when the timestamp YAML has been provided, +# Uncomment this to change the timestamp (you do not want to do this when the timestamp YAML has been provided, # and you are working on the same mirror alignment procedure [whole set of iterations]): # ## initialize (once per an entire alignment) diff --git a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/MirrorAlignment/run_RICH2.sh b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/MirrorAlignment/run_RICH2.sh index e2cb23999ccae75d2318a20d2e5c34369ff813b0..4af1682bd7f972442f7af9a03a06f4a4ad207298 100644 --- a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/MirrorAlignment/run_RICH2.sh +++ b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/MirrorAlignment/run_RICH2.sh @@ -13,7 +13,7 @@ # Check hlt2_reco_rich2_noUT_panoptes_dd4hep-both.py file to make sure you will be using the right branch of the conditions database for each iteration! -# First iteration (i0) - +# First iteration (i0) - #../stack/Panoptes/run gaudirun.py data_255358.py hlt2_reco_rich2_noUT_panoptes_dd4hep-both.py | tee logR2_i0.txt # Montioring example for i0 (optional) @@ -31,4 +31,3 @@ # (i4) #echo -n 4 | ../stack/Panoptes/run gaudirun.py data_255358.py hlt2_reco_rich2_noUT_panoptes_dd4hep-both.py | tee logR2_i4.txt - diff --git a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/README.md b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/README.md index 3a7e1ab1c12c2db1868c8b427a0e5bad635dbfca..4fcc67cc516c50884ae8a7e4a6244b6a6e65b126 100644 --- a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/README.md +++ b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/README.md @@ -10,7 +10,7 @@ To perform a standalone Rich reconstruction run, for example: ./stack_moore/Moore/run gaudirun.py hlt2_reco_rich1.py ``` -To fit the output, run `fit_hist.py` in the same folder as the histograms, like: +To fit the output, run `fit_hist.py` in the same folder as the histograms, like: ``` python fit_hist.py whichRich file_nm diff --git a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/alignment_conditions/RIch2/v3.yml b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/alignment_conditions/RIch2/v3.yml index 053a7f23aa4216d802a2e040e904765b1f636968..42dba0b9a2b25b3f0e2b5472ad3444549b37c5f6 100644 --- a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/alignment_conditions/RIch2/v3.yml +++ b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/alignment_conditions/RIch2/v3.yml @@ -15,4 +15,4 @@ PDPanel0: !alignment rotation: [0.0 * mrad, 0.0 * mrad, 0.0 * mrad] PDPanel1: !alignment position: [9.25 * mm, 3.0 * mm, 0.0 * mm] - rotation: [0.0 * mrad, 0.0 * mrad, 0.0 * mrad] \ No newline at end of file + rotation: [0.0 * mrad, 0.0 * mrad, 0.0 * mrad] diff --git a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/alignment_conditions/Rich1/v1.yml b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/alignment_conditions/Rich1/v1.yml index 50209e8231ae8d56c062da5f4c3c1e17b144d1fa..5ecd3f67853befd24cebce32450ec957a5bd143e 100644 --- a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/alignment_conditions/Rich1/v1.yml +++ b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/alignment_conditions/Rich1/v1.yml @@ -10,8 +10,8 @@ ############################################################################### PDPanel0: !alignment - position: [0.0 * mm, -6.0 * mm, 0.0 * mm] - rotation: [0.0 * mrad, 0.0 * mrad, 0.0 * mrad] + position: [0.0 * mm, -6.0 * mm, 0.0 * mm] + rotation: [0.0 * mrad, 0.0 * mrad, 0.0 * mrad] PDPanel1: !alignment - position: [-4.5 * mm, 9.0 * mm, 0.0 * mm] + position: [-4.5 * mm, 9.0 * mm, 0.0 * mm] rotation: [0.0 * mrad, 0.0 * mrad, 0.0 * mrad] diff --git a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/data_255358.py b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/data_255358.py index 3108001d4fc60779d507fdda0badfdea8a9313c5..2f12c9c8fd8957e352a56d13049be8e47b52f7c3 100644 --- a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/data_255358.py +++ b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/data_255358.py @@ -11,6 +11,7 @@ import os import re from datetime import datetime + from PyConf.application import ApplicationOptions filename_expr = re.compile( @@ -30,12 +31,8 @@ def sort_names(f): m = filename_expr.match(f) if m is None: return m - funs = [ - int, lambda t: int(datetime.strptime(t, "%Y%m%d-%H%M%S").timestamp()), - int - ] - return tuple( - fun(m.group(k)) for fun, k in zip(funs, ("run", "time", "rest"))) + funs = [int, lambda t: int(datetime.strptime(t, "%Y%m%d-%H%M%S").timestamp()), int] + return tuple(fun(m.group(k)) for fun, k in zip(funs, ("run", "time", "rest"))) files = [os.path.join(base_dir, f) for f in os.listdir(base_dir)] diff --git a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/fit_hist.py b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/fit_hist.py index 9fb8bb48fe7b7c214c8e0a26897fdfec0032748b..e6d38f40d51a383e92603835fcf4b23d6be77913 100644 --- a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/fit_hist.py +++ b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/fit_hist.py @@ -8,32 +8,45 @@ # granted to it by virtue of its status as an Intergovernmental Organization # # or submit itself to any jurisdiction. # ############################################################################### +import argparse import os import re import sys -import sys, numpy +import numpy import ROOT -from ROOT import TH1D, TCanvas, TFile, TF1, gStyle, TGraph, TMultiGraph, TLine, TH2D, TExec -import argparse - from GaudiPython import gbl +from ROOT import ( + TF1, + TH1D, + TH2D, + TCanvas, + TExec, + TFile, + TGraph, + TLine, + TMultiGraph, + gStyle, +) class AlignMonitor: - def __init__(self, whichRich, file_nm - # _alignConf, - # _maxIt, - ): - ''' + def __init__( + self, + whichRich, + file_nm, + # _alignConf, + # _maxIt, + ): + """ self.alignConf = _alignConf self.nameStr = self.alignConf.getProp('nameStr') self.whichRich = self.alignConf.getProp('Rich') self.displayMode = self.alignConf.getProp('displayMode') self.warningFactor = self.alignConf.getProp('warningFactor') self.maxIt = _maxIt # the maximum labeled number of the iterations that we are looping through - ''' - self.workdir = './' + """ + self.workdir = "./" self.whichRich = whichRich self.maxIt = 0 self.prename = file_nm @@ -43,33 +56,41 @@ class AlignMonitor: self.maxpri = 3 self.binToPriMirr = [[2, 3], [0, 1]] self.maxsec = 15 - self.binToSecMirr = [[10, 11, 14, 15], [8, 9, 12, 13], [2, 3, 6, 7], - [0, 1, 4, 5]] + self.binToSecMirr = [ + [10, 11, 14, 15], + [8, 9, 12, 13], + [2, 3, 6, 7], + [0, 1, 4, 5], + ] self.fitMin = -0.0055 self.fitMax = 0.0055 - #self.fitMin = -0.01 - #self.fitMax = 0.01 + # self.fitMin = -0.01 + # self.fitMax = 0.01 # if RICH2, use RICH2 settings - if (self.whichRich == 2): + if self.whichRich == 2: self.maxpri = 55 - self.binToPriMirr = [[3, 2, 1, 0, 31, 30, 29, 28], - [7, 6, 5, 4, 35, 34, 33, 32], - [11, 10, 9, 8, 39, 38, 37, 36], - [15, 14, 13, 12, 43, 42, 41, 40], - [19, 18, 17, 16, 47, 46, 45, 44], - [23, 22, 21, 20, 51, 50, 49, 48], - [27, 26, 25, 24, 55, 54, 53, 52]] + self.binToPriMirr = [ + [3, 2, 1, 0, 31, 30, 29, 28], + [7, 6, 5, 4, 35, 34, 33, 32], + [11, 10, 9, 8, 39, 38, 37, 36], + [15, 14, 13, 12, 43, 42, 41, 40], + [19, 18, 17, 16, 47, 46, 45, 44], + [23, 22, 21, 20, 51, 50, 49, 48], + [27, 26, 25, 24, 55, 54, 53, 52], + ] self.maxsec = 39 - self.binToSecMirr = [[3, 2, 1, 0, 23, 22, 21, 20], - [7, 6, 5, 4, 27, 26, 25, 24], - [11, 10, 9, 8, 31, 30, 29, 28], - [15, 14, 13, 12, 35, 34, 33, 32], - [19, 18, 17, 16, 39, 38, 37, 36]] + self.binToSecMirr = [ + [3, 2, 1, 0, 23, 22, 21, 20], + [7, 6, 5, 4, 27, 26, 25, 24], + [11, 10, 9, 8, 31, 30, 29, 28], + [15, 14, 13, 12, 35, 34, 33, 32], + [19, 18, 17, 16, 39, 38, 37, 36], + ] # Original fit range self.fitMin = -0.0055 self.fitMax = 0.0055 - #self.fitMin = -0.002 - #self.fitMax = 0.002 + # self.fitMin = -0.002 + # self.fitMax = 0.002 self.isInsane = False self.finalCKres = None self.finalCKresErr = None @@ -77,6 +98,7 @@ class AlignMonitor: def performMonitoring(self): import os + if not plot_nice: gStyle.SetOptFit(1111) gStyle.SetOptStat(000000000) @@ -84,25 +106,34 @@ class AlignMonitor: if hist_path == "": pdf_suff = "" else: - pdf_suff = "_" + hist_path.split("/")[-4] + "_" + hist_path.split( - "/")[-3] + "_" + hist_path.split( - "/")[-2] + "_" + hist_path.split("/")[-1] + pdf_suff = ( + "_" + + hist_path.split("/")[-4] + + "_" + + hist_path.split("/")[-3] + + "_" + + hist_path.split("/")[-2] + + "_" + + hist_path.split("/")[-1] + ) # including figures doesn't work for .pdfs file_ext = "png" if plot_nice else "pdf" # File for the RICH piquet AND for the RICH mirror alignment experts - expertFile = f'{self.workdir}Rich{self.whichRich}_AlignSummary{pdf_suff}.{file_ext}' + expertFile = ( + f"{self.workdir}Rich{self.whichRich}_AlignSummary{pdf_suff}.{file_ext}" + ) # File for the Alignment piquet ("duplicating" what goes to the Presenter for the Data Manager [except CK angle res stuff]) - monitorFile = f'{self.workdir}Rich{self.whichRich}_AlignMonitor{pdf_suff}.pdf' + monitorFile = f"{self.workdir}Rich{self.whichRich}_AlignMonitor{pdf_suff}.pdf" # File with for testing purposes - testingFile = f'{self.workdir}Rich{self.whichRich}_AlignTesting{pdf_suff}.pdf' + testingFile = f"{self.workdir}Rich{self.whichRich}_AlignTesting{pdf_suff}.pdf" # Data Manager can only get histograms sent via self.monSvc - theCanvas = TCanvas('theCanvas', 'MirrAlign') + theCanvas = TCanvas("theCanvas", "MirrAlign") theCanvas.Divide(2, 2, 0.001, 0.001) - theCanvas2 = TCanvas('theCanvas2', 'MirrAlignTest') + theCanvas2 = TCanvas("theCanvas2", "MirrAlignTest") theCanvas2.Divide(2, 2, 0.001, 0.001) theCanvas2.Clear() @@ -140,35 +171,44 @@ class AlignMonitor: # define resHistoTrend resHistoTrend = TH1D( - 'resHistoTrend', 'RICH' + str(self.whichRich) + - ' Cherenkov angle resolution (mrad) per It. ', self.maxIt + 1, - -0.5, self.maxIt + 0.5) + "resHistoTrend", + "RICH" + + str(self.whichRich) + + " Cherenkov angle resolution (mrad) per It. ", + self.maxIt + 1, + -0.5, + self.maxIt + 0.5, + ) for j in reversed(range(0, self.maxIt + 1)): filename[j] = self.prename if os.path.exists(filename[j]): - thisFile[j] = TFile(filename[j], 'read') + thisFile[j] = TFile(filename[j], "read") if hist_path == "": if self.cuts: - hist[j] = (thisFile[j].Get( - f'RICH/RiCKResLongTight/Rich{self.whichRich}Gas/ckResAll' - )).Clone() + hist[j] = ( + thisFile[j].Get( + f"RICH/RiCKResLongTight/Rich{self.whichRich}Gas/ckResAll" + ) + ).Clone() else: - hist[j] = (thisFile[j].Get( - f'RICH/RiCKResLong/Rich{self.whichRich}Gas/ckResAll' - )).Clone() + hist[j] = ( + thisFile[j].Get( + f"RICH/RiCKResLong/Rich{self.whichRich}Gas/ckResAll" + ) + ).Clone() else: - hist[j] = (thisFile[j].Get(f'{hist_path}')).Clone() + hist[j] = (thisFile[j].Get(f"{hist_path}")).Clone() if (j == 0) and (j == self.maxIt): - hist[j].SetName('resHisto0') - hist[j].SetName('resHistoN') - elif (j == self.maxIt): - hist[j].SetName('resHistoN') - elif (j == 0): - hist[j].SetName('resHisto0') - if (j != 0): - hist[j].SetName('resHisto' + str(j)) + hist[j].SetName("resHisto0") + hist[j].SetName("resHistoN") + elif j == self.maxIt: + hist[j].SetName("resHistoN") + elif j == 0: + hist[j].SetName("resHisto0") + if j != 0: + hist[j].SetName("resHisto" + str(j)) # perform the fit and extract fit models fitRes[j], resHistograms[j] = self.fitCherenkovAngle(hist[j]) @@ -181,21 +221,30 @@ class AlignMonitor: resHistoTrend.SetBinContent(j + 1, ckres) resHistoTrend.SetBinError(j + 1, ckres_error) - print("_i" + str(j) + " CK angle resolution: " + - str(ckres) + " mrad.") - print("_i" + str(j) + " CK angle resolution err: " + - str(ckres_error) + " mrad.") + print( + "_i" + str(j) + " CK angle resolution: " + str(ckres) + " mrad." + ) + print( + "_i" + + str(j) + + " CK angle resolution err: " + + str(ckres_error) + + " mrad." + ) if j == self.maxIt: self.finalCKres = ckres self.finalCKresErr = ckres_error - title[j] = 'RICH' + str( - self.whichRich) + ' Cherenkov angle resolution It. ' + str( - j) + title[j] = ( + "RICH" + + str(self.whichRich) + + " Cherenkov angle resolution It. " + + str(j) + ) resHistograms[j].SetTitle(title[j]) - resHistograms[j].SetXTitle(r'#Delta#theta_{Cherenkov} (rad)') - resHistograms[j].SetYTitle('Entries') + resHistograms[j].SetXTitle(r"#Delta#theta_{Cherenkov} (rad)") + resHistograms[j].SetYTitle("Entries") histFunc[j].SetLineColor(2) polbkg[j].SetLineColor(4) @@ -215,8 +264,8 @@ class AlignMonitor: # set y axis label to refer to the bin width resHistograms[j].GetYaxis().SetTitle( - "Entries/{:.4f} rad".format( - resHistograms[j].GetBinWidth(1))) + "Entries/{:.4f} rad".format(resHistograms[j].GetBinWidth(1)) + ) theCanvas2.cd() if plot_nice: @@ -227,10 +276,10 @@ class AlignMonitor: polbkg[j].Draw("SAME") if plot_nice: - # this increases dpi of pngs - theCanvas2.SetCanvasSize(theCanvas2.GetWw() * 6, - theCanvas2.GetWh() * 6) + theCanvas2.SetCanvasSize( + theCanvas2.GetWw() * 6, theCanvas2.GetWh() * 6 + ) # for whatever reason things get cut off on the right theCanvas2.SetRightMargin(0.1) @@ -246,23 +295,34 @@ class AlignMonitor: text_res1.SetNDC(True) text_res1.SetTextSize(0.023) text_res1.DrawLatex( - 0.16, 0.88, r'#sigma[#Delta#theta_{Cherenkov}] = ' + - f'({self.finalCKres:.3f}' + r' #pm ' + - f'{self.finalCKresErr:.3f})' + r' #times 10^{-3}' + - r' rad') + 0.16, + 0.88, + r"#sigma[#Delta#theta_{Cherenkov}] = " + + f"({self.finalCKres:.3f}" + + r" #pm " + + f"{self.finalCKresErr:.3f})" + + r" #times 10^{-3}" + + r" rad", + ) text_res2 = ROOT.TLatex() text_res2.SetNDC(True) text_res2.SetTextSize(0.023) if whichRich == 1: text_res2.DrawLatex( - 0.16, 0.85, - r'(#sigma[#Delta#theta_{Cherenkov}](Run 2) = ' + - r'(1.640 #pm 0.003) #times 10^{-3} ' + r' rad)') + 0.16, + 0.85, + r"(#sigma[#Delta#theta_{Cherenkov}](Run 2) = " + + r"(1.640 #pm 0.003) #times 10^{-3} " + + r" rad)", + ) else: text_res2.DrawLatex( - 0.16, 0.85, - r'(#sigma[#Delta#theta_{Cherenkov}](Run 2) = ' + - r'(0.650 #pm 0.001) #times 10^{-3} ' + r' rad)') + 0.16, + 0.85, + r"(#sigma[#Delta#theta_{Cherenkov}](Run 2) = " + + r"(0.650 #pm 0.001) #times 10^{-3} " + + r" rad)", + ) # Create the TPad with the calculated position and size pad = ROOT.TPad("pad", "pad", 0.63, 0.6, 0.85, 0.85) @@ -283,15 +343,14 @@ class AlignMonitor: resHistograms[j].Draw("E1") polbkg[j].Draw("SAME") - #theCanvas.Print(monitorFile) + # theCanvas.Print(monitorFile) sys.stdout.flush() # Make resHistoTrend iteration trend plot resHistoTrend.SetMarkerStyle(8) - resHistoTrend.SetXTitle('iteration number') - resHistoTrend.SetYTitle( - '#splitline{Cherenkov angle resolution (mrad)}{}') + resHistoTrend.SetXTitle("iteration number") + resHistoTrend.SetYTitle("#splitline{Cherenkov angle resolution (mrad)}{}") theCanvas2.Clear() theCanvas.Clear() @@ -299,14 +358,12 @@ class AlignMonitor: sys.stdout.flush() def fitCherenkovAngle(self, hist): - # get Chris Jones's C++ fitter fitter = gbl.Rich.Rec.CKResolutionFitter() # set signal (AsymNormal) and background (FreeNPol) models fitter.params().RichFitTypes[whichRich - 1].clear() - fitter.params().RichFitTypes[whichRich - - 1].push_back("AsymNormal:FreeNPol") + fitter.params().RichFitTypes[whichRich - 1].push_back("AsymNormal:FreeNPol") # change fit ranges fitter.params().RichFitMin[0] = self.fitMin @@ -327,6 +384,7 @@ def monitor(whichRich, file_nm): if write_results: import csv + f = open(f"./ckres_results_R{whichRich}.csv", "a+") writer = csv.writer(f) writer.writerow([finalCKres, finalCKresErr, extra_info]) @@ -337,29 +395,28 @@ def monitor(whichRich, file_nm): # can minimise using monitor() as function to minimise if returns finalCKres and has arg inputs -if __name__ == '__main__': +if __name__ == "__main__": parser = argparse.ArgumentParser( - description="Fits histogram to obtain Rich CK angle resolution") - parser.add_argument( - 'whichRich', - choices=[1, 2], - type=int, - help='Which Rich detector to use') - parser.add_argument('file_nm', help='Name of root file to use') + description="Fits histogram to obtain Rich CK angle resolution" + ) parser.add_argument( - '--hist_path', default="", help='Histogram path in root file') + "whichRich", choices=[1, 2], type=int, help="Which Rich detector to use" + ) + parser.add_argument("file_nm", help="Name of root file to use") + parser.add_argument("--hist_path", default="", help="Histogram path in root file") parser.add_argument( - '--write_results', - action='store_true', - help='Write results to textfile') + "--write_results", action="store_true", help="Write results to textfile" + ) parser.add_argument( - '--extra_info', - help='Any extra text to be written to the text file (e.g. run number)') + "--extra_info", + help="Any extra text to be written to the text file (e.g. run number)", + ) parser.add_argument( - '--plot_nice', + "--plot_nice", default=False, - action='store_true', - help='Plot the histogram nicely, using lhcbstyle') + action="store_true", + help="Plot the histogram nicely, using lhcbstyle", + ) args = parser.parse_args() whichRich = args.whichRich file_nm = args.file_nm diff --git a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/get_column_plots.sh b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/get_column_plots.sh index 7e8cce9a9997636bfa5a60b764547660f5626966..5151bcf2d120995fbfce443602df50d9c5dc11ce 100644 --- a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/get_column_plots.sh +++ b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/get_column_plots.sh @@ -57,7 +57,7 @@ fi if [ "$whichRich" -eq 2 ]; then for pmt in R H; do - + if [ "$whichRich" -eq 2 ] && [ "$whichPanel" -eq 0 ]; then histo_path="RICH/RiCKResLongTight/Rich2Gas/ASide-left/ckResAllPerPanel${pmt}TypePD" elif [ "$whichRich" -eq 2 ] && [ "$whichPanel" -eq 1 ]; then @@ -68,7 +68,7 @@ if [ "$whichRich" -eq 2 ]; then python fit_hist.py "$whichRich" "$whichPanel" rich"${whichRich}"_opt_dd4hep_p"$whichPanel".root --hist_path "$histo_path" - done + done fi # create folder structure and move pdf files over @@ -102,4 +102,4 @@ if [ "${whichRich}" = 2 ] && [ "${whichPanel}" = 0 ]; then fi if [ "${whichRich}" = 2 ] && [ "${whichPanel}" = 1 ]; then mv Rich${whichRich}*.pdf "${runNum_dir}/${subdirs[3]}" -fi \ No newline at end of file +fi diff --git a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/hlt2_reco_rich_noUT_dd4hep.py b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/hlt2_reco_rich_noUT_dd4hep.py index 4eeddc38f0c5e5e661a4fd35673d812cb3c9a20f..ba6927bb0669db5bba979cc390961abd7b41c650 100644 --- a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/hlt2_reco_rich_noUT_dd4hep.py +++ b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/hlt2_reco_rich_noUT_dd4hep.py @@ -8,50 +8,54 @@ # granted to it by virtue of its status as an Intergovernmental Organization # # or submit itself to any jurisdiction. # ############################################################################### -import glob import csv +import glob import math -import sys import random +import sys -from GaudiKernel.SystemOfUnits import (GeV, MeV, mm, mrad) +from GaudiKernel.SystemOfUnits import GeV, MeV, mm, mrad from Moore import ( options, run_reconstruction, ) - +from Panoptes.alignment import ( + standalone_rich_online_align_reco, + standalone_rich_panel_align_reco, +) from PyConf.Algorithms import ( - PrForwardTrackingVelo, VPRetinaFullClusterDecoder, - VeloRetinaClusterTrackingSIMD, PrMatchNN, PrHybridSeeding) - + PrForwardTrackingVelo, + PrHybridSeeding, + PrMatchNN, + VeloRetinaClusterTrackingSIMD, + VPRetinaFullClusterDecoder, +) from RecoConf.legacy_rec_hlt1_tracking import ( - make_VeloClusterTrackingSIMD, make_reco_pvs, make_PatPV3DFuture_pvs, - make_velo_full_clusters) - + make_PatPV3DFuture_pvs, + make_reco_pvs, + make_velo_full_clusters, + make_VeloClusterTrackingSIMD, +) from RecoConf.rich_data_monitoring import ( - default_rich_monitoring_options, alignment_rich_monitoring_options, + default_rich_monitoring_options, ) - from RecoConf.rich_reconstruction import default_rich_reco_options -from Panoptes.alignment import ( - standalone_rich_online_align_reco, - standalone_rich_panel_align_reco, -) - # from Configurables import ( # UpdateManagerSvc # ) """Options for running over data with FT raw bank version 6.""" from RecoConf.decoders import ( - default_ft_decoding_version, ) + default_ft_decoding_version, +) # load options from YAML file from ruamel.yaml import YAML + yaml = YAML() -with open('surveys/survey_opts.yml') as opts_yml_file: +with open("surveys/survey_opts.yml") as opts_yml_file: yml_opts = yaml.load(opts_yml_file) whichRich = yml_opts["whichRich"] @@ -72,15 +76,15 @@ options.scheduler_legacy_mode = False options.use_iosvc = True if useRealData is not True: - options.set_input_and_conds_from_testfiledb( - 'upgrade_Sept2022_minbias_0fb_md_xdigi') - options.input_type = 'ROOT' + options.set_input_and_conds_from_testfiledb("upgrade_Sept2022_minbias_0fb_md_xdigi") + options.input_type = "ROOT" else: if useHltDecisions: exec( open( "/home/jreich/stack_dd4hep_v3/Panoptes/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/data_online.py" - ).read()) + ).read() + ) else: # exec(open("/home/jreich/stack_dd4hep_v3/Panoptes/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/MirrorAlignment/data_online.py").read()) @@ -105,11 +109,9 @@ else: base_dir_files = f"/calib/align/LHCb/Rich{whichRich}" - def obtain_files_from_many_runs(base_dir_files, - start_run, - end_run, - num_files_to_select=30, - seed_value=100): + def obtain_files_from_many_runs( + base_dir_files, start_run, end_run, num_files_to_select=30, seed_value=100 + ): files = [] for folder_number in range(start_run, end_run + 1): @@ -118,15 +120,14 @@ else: # Check if the folder exists if os.path.exists(folder_path) and os.path.isdir(folder_path): - # List all files in the folder files_in_folder = os.listdir(folder_path) # Select random files from the folder random.seed(seed_value) random_files = random.sample( - files_in_folder, - min(num_files_to_select, len(files_in_folder))) + files_in_folder, min(num_files_to_select, len(files_in_folder)) + ) # Print the selected files for file_name in random_files: @@ -135,7 +136,8 @@ else: return files options.input_files = obtain_files_from_many_runs( - base_dir_files, 290015, 290052) + base_dir_files, 290015, 290052 + ) options.simulation = False options.input_type = "MDF" @@ -152,28 +154,28 @@ if UseDD4Hep: from Configurables import DDDBConf # dd4hep = DD4hepSvc(DetectorList=["/world", "Magnet", "UT", "VP", "FT", "Rich1", "Rich2"]) - dd4hep = DD4hepSvc( - DetectorList=["/world", "Magnet", "VP", "FT", "Rich1", "Rich2"]) + dd4hep = DD4hepSvc(DetectorList=["/world", "Magnet", "VP", "FT", "Rich1", "Rich2"]) dd4hep.OutputLevel = 1 if useRealData: - options.conddb_tag = 'master' # used for real data + options.conddb_tag = "master" # used for real data - options.dddb_tag = 'run3/trunk' + options.dddb_tag = "run3/trunk" # needed for when reconstruction changed to SuperPixels (change was at run 289434) - DDDBConf().GeometryVersion = 'run3/2024.Q1.2-v00.00' - options.geometry_version = 'run3/2024.Q1.2-v00.00' + DDDBConf().GeometryVersion = "run3/2024.Q1.2-v00.00" + options.geometry_version = "run3/2024.Q1.2-v00.00" # latest scifi and velo alignments dd4hep.UseConditionsOverlay = False - dd4hep.ConditionsVersion = 'master' + dd4hep.ConditionsVersion = "master" options.simulation = False else: - options.conddb_tag = 'jonrob/all-pmts-active' # used for DetDesc MC samples with DD4Hep - DDDBConf( - ).GeometryVersion = 'run3/before-rich1-geom-update-26052022' # used for DetDesc MC samples with DD4Hep + options.conddb_tag = ( + "jonrob/all-pmts-active" # used for DetDesc MC samples with DD4Hep + ) + DDDBConf().GeometryVersion = "run3/before-rich1-geom-update-26052022" # used for DetDesc MC samples with DD4Hep if manual_update: conddb_path = yml_opts["conddb_path"] @@ -184,16 +186,18 @@ if UseDD4Hep: f"Error: Trying to manually update conditions. No local clone of condDB found in {conddb_path}." ) else: - dd4hep.ConditionsLocation = 'git:/cvmfs/lhcb.cern.ch/lib/lhcb/git-conddb/lhcb-conditions-database.git' + dd4hep.ConditionsLocation = ( + "git:/cvmfs/lhcb.cern.ch/lib/lhcb/git-conddb/lhcb-conditions-database.git" + ) else: - options.conddb_tag = 'upgrade/sim-20220612-vc-md100-RICHcustomFTv6' + options.conddb_tag = "upgrade/sim-20220612-vc-md100-RICHcustomFTv6" options.simulation = True -rich = f'rich{whichRich}' -radiator = f'Rich{whichRich}Gas' +rich = f"rich{whichRich}" +radiator = f"Rich{whichRich}Gas" -param_list = ['p0_x', 'p1_x', 'p0_y', 'p1_y', 'p0_z', 'p1_z'] +param_list = ["p0_x", "p1_x", "p0_y", "p1_y", "p0_z", "p1_z"] param_dict = dict.fromkeys(param_list) trans_perf_param_dict = dict.fromkeys(param_list) @@ -211,7 +215,7 @@ perf_align = [ yml_opts[f"R{whichRich}"]["P0"]["perf_trans"]["y"], yml_opts[f"R{whichRich}"]["P1"]["perf_trans"]["y"], yml_opts[f"R{whichRich}"]["P0"]["perf_trans"]["z"], - yml_opts[f"R{whichRich}"]["P1"]["perf_trans"]["z"] + yml_opts[f"R{whichRich}"]["P1"]["perf_trans"]["z"], ] for val, param in zip(perf_align, param_dict.keys()): @@ -275,17 +279,17 @@ default_reco_opts.update(panel_select) # Monitoring opts if whichRich == 1: - minP = 30. + minP = 30.0 tighter_minp = { "TightTrackSelection": { "MinP": minP * GeV, "MinPt": 0.5 * GeV, - "MaxChi2": 2., + "MaxChi2": 2.0, "MaxGhostProb": 0.1, } } if whichRich == 2: - minP = 60. + minP = 60.0 tighter_minp = { "TightTrackSelection": { "MinP": minP * GeV, @@ -297,29 +301,30 @@ if whichRich == 2: default_moni_opts.update(tighter_minp) # wider_histo = {'CKResHistoRange': (0.025, 0.005, 0.004)} -wider_histo = {'CKResHistoRange': (0.025, 0.0055, 0.0055)} +wider_histo = {"CKResHistoRange": (0.025, 0.0055, 0.0055)} default_moni_opts.update(wider_histo) -useUT = {'UseUT': False} +useUT = {"UseUT": False} default_moni_opts.update(useUT) nkevts = str(math.trunc(options.evt_max / 1000)) # save output file with histograms if UseDD4Hep: - options.histo_file = f'rich{whichRich}_opt_dd4hep_p{whichPanel}_testttt.root' + options.histo_file = f"rich{whichRich}_opt_dd4hep_p{whichPanel}_testttt.root" else: - options.histo_file = f'rich{whichRich}_opt_p{whichPanel}.root' + options.histo_file = f"rich{whichRich}_opt_p{whichPanel}.root" PrForwardTrackingVelo.global_bind( MinQuality=0.0, DeltaQuality=0.0, MinTotalHits=9, - MaxChi2PerDoF=50., - MaxChi2XProjection=60., - MaxChi2PerDoFFinal=28., - MaxChi2Stereo=16., - MaxChi2StereoAdd=16., - MinP=minP * GeV) + MaxChi2PerDoF=50.0, + MaxChi2XProjection=60.0, + MaxChi2PerDoFFinal=28.0, + MaxChi2Stereo=16.0, + MaxChi2StereoAdd=16.0, + MinP=minP * GeV, +) PrMatchNN.global_bind(MinP=minP * GeV) PrHybridSeeding.global_bind(MinP=minP * GeV) @@ -330,30 +335,37 @@ PrHybridSeeding.global_bind(MinP=minP * GeV) # make_full_cluster=VPRetinaFullClusterDecoder) make_reco_pvs.global_bind(make_pvs_from_velo_tracks=make_PatPV3DFuture_pvs) -from Configurables import LHCb__UnpackRawEvent, HltDecReportsDecoder, HltSelReportsDecoder, ApplicationMgr +from Configurables import ( + ApplicationMgr, + HltDecReportsDecoder, + HltSelReportsDecoder, + LHCb__UnpackRawEvent, +) from PyConf.application import configured_ann_svc + unpacker = LHCb__UnpackRawEvent( "UnpackRawEvent", OutputLevel=2, - RawBankLocations=[ - "DAQ/RawBanks/HltDecReports", "DAQ/RawBanks/HltSelReports" - ], - BankTypes=["HltDecReports", "HltSelReports"]) + RawBankLocations=["DAQ/RawBanks/HltDecReports", "DAQ/RawBanks/HltSelReports"], + BankTypes=["HltDecReports", "HltSelReports"], +) decDec = HltDecReportsDecoder( "HltDecReportsDecoder/Hlt1DecReportsDecoder", SourceID="Hlt1", - RawBanks=unpacker.RawBankLocations[0]) + RawBanks=unpacker.RawBankLocations[0], +) selDec = HltSelReportsDecoder( "HltSelReportsDecoder/Hlt1SelReportsDecoder", SourceID="Hlt1", DecReports=unpacker.RawBankLocations[0], - RawBanks=unpacker.RawBankLocations[1]) + RawBanks=unpacker.RawBankLocations[1], +) app = ApplicationMgr( - TopAlg=[unpacker, decDec, selDec], - ExtSvc=[configured_ann_svc(name='HltANNSvc')]) + TopAlg=[unpacker, decDec, selDec], ExtSvc=[configured_ann_svc(name="HltANNSvc")] +) # by default, no additional filtering of the events event_filter = [] @@ -361,29 +373,34 @@ event_filter = [] # Prepare filter import Functors from PyConf.Algorithms import ( - VoidFilter, HltDecReportsDecoder as PyConf_Algorithms_HltDecReportsDecoder, ) +from PyConf.Algorithms import ( + VoidFilter, +) from PyConf.application import ( default_raw_banks, default_raw_event, ) -lines = (['Hlt1RICH1AlignmentDecision'] - if whichRich == 1 else ['Hlt1RICH2AlignmentDecision']) +lines = ( + ["Hlt1RICH1AlignmentDecision"] if whichRich == 1 else ["Hlt1RICH2AlignmentDecision"] +) with default_raw_event.bind(raw_event_format=0.5): hlt1_dec_reports = PyConf_Algorithms_HltDecReportsDecoder( - RawBanks=default_raw_banks("HltDecReports"), SourceID='Hlt1') + RawBanks=default_raw_banks("HltDecReports"), SourceID="Hlt1" + ) hlt1_filter = VoidFilter( - name='Streaming_filter', + name="Streaming_filter", Cut=Functors.DECREPORTS_FILTER( - Lines=lines, - DecReports=hlt1_dec_reports.OutputHltDecReportsLocation)) + Lines=lines, DecReports=hlt1_dec_reports.OutputHltDecReportsLocation + ), + ) # when particular decision of HLT1 line about RICH1 or RICH2 is wanted -#if 'subset' not in current_variant: +# if 'subset' not in current_variant: if useHltDecisions: # prepare filter for selecting events # chosen for alignment of mirrors of particular RICH @@ -402,13 +419,15 @@ if useHltDecisions: sys.stdout.flush() - -with standalone_rich_panel_align_reco.bind(RichGas=radiator,\ - EventFilter=event_filter if useHltDecisions else [],\ - noUT=True), \ - alignment_rich_monitoring_options.bind(radiator=radiator, \ - init_override_opts=align_opts), \ - default_ft_decoding_version.bind(value=6), \ - default_rich_reco_options.bind(init_override_opts=default_reco_opts), \ - default_rich_monitoring_options.bind(init_override_opts=default_moni_opts): +with ( + standalone_rich_panel_align_reco.bind( + RichGas=radiator, EventFilter=event_filter if useHltDecisions else [], noUT=True + ), + alignment_rich_monitoring_options.bind( + radiator=radiator, init_override_opts=align_opts + ), + default_ft_decoding_version.bind(value=6), + default_rich_reco_options.bind(init_override_opts=default_reco_opts), + default_rich_monitoring_options.bind(init_override_opts=default_moni_opts), +): run_reconstruction(options, standalone_rich_panel_align_reco) diff --git a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/old_scripts/hlt2_reco_rich1_moore.py b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/old_scripts/hlt2_reco_rich1_moore.py index 60f63fceef0a29cb8c8e5281eed166baae77f4f9..e9f3b6a1b66a1ebf8bdaf6cd92f9f46a7ac7cf2a 100644 --- a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/old_scripts/hlt2_reco_rich1_moore.py +++ b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/old_scripts/hlt2_reco_rich1_moore.py @@ -8,70 +8,77 @@ # granted to it by virtue of its status as an Intergovernmental Organization # # or submit itself to any jurisdiction. # ############################################################################### -import glob import csv +import glob import math -#from Panoptes.alignment import ( -# standalone_rich_mirror_align_reco, ) +from Configurables import CondDB, UpdateManagerSvc +# from Panoptes.alignment import ( +# standalone_rich_mirror_align_reco, ) from GaudiKernel.SystemOfUnits import ( - GeV, ) + GeV, +) from Moore import ( options, run_reconstruction, ) +from PyConf.tonic import configurable from RecoConf.rich_add_reconstruction_monitoring_checking import ( - add_hlt2_rich, ) + add_hlt2_rich, +) from RecoConf.rich_data_monitoring import ( - default_rich_monitoring_options, alignment_rich_monitoring_options, + default_rich_monitoring_options, ) - from RecoConf.rich_reconstruction import default_rich_reco_options - from RecoConf.standalone import ( - standalone_hlt2_reco, ) -from PyConf.tonic import configurable -from Configurables import (CondDB, UpdateManagerSvc) + standalone_hlt2_reco, +) + """Options for running over data with FT raw bank version 6.""" from RecoConf.decoders import ( - default_ft_decoding_version, ) - + default_ft_decoding_version, +) from RecoConf.hlt2_tracking import ( - make_hlt2_tracks_without_UT, ) + make_hlt2_tracks_without_UT, +) options.n_threads = 10 options.evt_max = 10000 -options.input_files = sorted([ - 'mdf:root://eoslhcb.cern.ch/%s' % f for f in glob.glob( - r'/eos/lhcb/grid/prod/lhcb/MC/Upgrade/MDF/00146082/000*/00146082_*') -]) -options.input_type = 'MDF' -options.dddb_tag = 'upgrade/bmalecki-rich-alignmentParameters' -options.conddb_tag = 'upgrade/bmalecki-rich-alignmentParameters' +options.input_files = sorted( + [ + "mdf:root://eoslhcb.cern.ch/%s" % f + for f in glob.glob( + r"/eos/lhcb/grid/prod/lhcb/MC/Upgrade/MDF/00146082/000*/00146082_*" + ) + ] +) +options.input_type = "MDF" +options.dddb_tag = "upgrade/bmalecki-rich-alignmentParameters" +options.conddb_tag = "upgrade/bmalecki-rich-alignmentParameters" -rich = 'rich1' +rich = "rich1" radiator = "Rich1Gas" track_types = [ - 'Long', + "Long", #'Upstream', #'Downstream', ] # Import alignment parameters from csv file and apply -param_list = ['p0_x', 'p1_x', 'p0_y', 'p1_y', 'p0_z', 'p1_z'] +param_list = ["p0_x", "p1_x", "p0_y", "p1_y", "p0_z", "p1_z"] param_dict = dict.fromkeys(param_list) -#file_name = '/afs/cern.ch/work/j/jamey/public/rich_align/rich_align_upgrade/optimisation/rich2_params.csv' -#f = open(file_name, 'r') -#reader = csv.reader(f) +# file_name = '/afs/cern.ch/work/j/jamey/public/rich_align/rich_align_upgrade/optimisation/rich2_params.csv' +# f = open(file_name, 'r') +# reader = csv.reader(f) for row, param in zip([0.0, 0.0, -30.15, 30.15, 0.0, 0.0], param_dict.keys()): param_dict[param] = float(row) -#f.close() +# f.close() UpdateManagerSvc().ConditionsOverride += [ f"Conditions/Alignment/Rich1/PDPanel0_Align := double_v dPosXYZ = {param_dict['p0_x']} {param_dict['p0_y']} {param_dict['p0_z']};", @@ -82,7 +89,7 @@ default_opts = {} default_reco_opts = {} # Reco opts -wider_bkg = {"PhotonSelection": 'None'} +wider_bkg = {"PhotonSelection": "None"} default_reco_opts.update(wider_bkg) panel_select = {"ActivatePanel": (True, False)} default_reco_opts.update(panel_select) @@ -90,19 +97,19 @@ default_reco_opts.update(panel_select) # Monitoring opts tighter_minp = { "TightTrackSelection": { - "MinP": 30. * GeV, + "MinP": 30.0 * GeV, "MinPt": 0.5 * GeV, - "MaxChi2": 2., + "MaxChi2": 2.0, "MaxGhostProb": 0.1, } } default_opts.update(tighter_minp) -wider_histo = {'CKResHistoRange': (0.025, 0.008, 0.004)} +wider_histo = {"CKResHistoRange": (0.025, 0.008, 0.004)} default_opts.update(wider_histo) align_tasks = [ - 'Produce', # fill the production set of histograms - 'Monitor', # add various checking histograms + "Produce", # fill the production set of histograms + "Monitor", # add various checking histograms #'Map', # add counters for creation of the HLT1 pre-selection line "map" #'Optimize', # add counters for optimization of the RICH2 mirror combinations subset #'Select', # check filling the rest of RICH2 mirror combinations along with 8 poorest @@ -115,18 +122,25 @@ task = align_tasks[0] nkevts = str(math.trunc(options.evt_max / 1000)) # save output file with histograms -options.histo_file = 'rich1_2.root' +options.histo_file = "rich1_2.root" moni_set = "PhotonCherenkovAngles" -#standalone_rich_mirror_align_reco.bind(RichGas="Rich1Gas", align_tasks=align_tasks, noUT=True), \ +# standalone_rich_mirror_align_reco.bind(RichGas="Rich1Gas", align_tasks=align_tasks, noUT=True), \ -with add_hlt2_rich.bind( +with ( + add_hlt2_rich.bind( do_data_monitoring_rich=True, moni_set=moni_set, radiator=radiator, align_tasks=align_tasks, - track_types=track_types), \ - default_ft_decoding_version.bind(value=6), \ - default_rich_reco_options.bind(default_rich_reco_opts_level2_modify=default_reco_opts), \ - default_rich_monitoring_options.bind(default_rich_moni_opts_level2_modify=default_opts): + track_types=track_types, + ), + default_ft_decoding_version.bind(value=6), + default_rich_reco_options.bind( + default_rich_reco_opts_level2_modify=default_reco_opts + ), + default_rich_monitoring_options.bind( + default_rich_moni_opts_level2_modify=default_opts + ), +): run_reconstruction(options, standalone_hlt2_reco) diff --git a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/old_scripts/hlt2_reco_rich1_noUT_moore.py b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/old_scripts/hlt2_reco_rich1_noUT_moore.py index afbaf10c2660c2e7c82a76af0806a90ae2e2224c..3633e390b68ff2bcfbee3b15a140cb99681d183e 100644 --- a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/old_scripts/hlt2_reco_rich1_noUT_moore.py +++ b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/old_scripts/hlt2_reco_rich1_noUT_moore.py @@ -8,51 +8,59 @@ # granted to it by virtue of its status as an Intergovernmental Organization # # or submit itself to any jurisdiction. # ############################################################################### -import glob import csv +import glob import math +from Configurables import UpdateManagerSvc from GaudiKernel.SystemOfUnits import ( - GeV, ) + GeV, +) from Moore import ( options, run_reconstruction, ) from RecoConf.rich_add_reconstruction_monitoring_checking import ( - add_hlt2_rich, ) + add_hlt2_rich, +) from RecoConf.rich_data_monitoring import ( - default_rich_monitoring_options, ) - + default_rich_monitoring_options, +) from RecoConf.rich_reconstruction import default_rich_reco_options - from RecoConf.standalone import ( - standalone_hlt2_light_reco_without_UT, ) -from Configurables import (UpdateManagerSvc) + standalone_hlt2_light_reco_without_UT, +) + """Options for running over data with FT raw bank version 6.""" from RecoConf.decoders import ( - default_ft_decoding_version, ) + default_ft_decoding_version, +) options.n_threads = 6 options.evt_max = 10000 -options.input_files = sorted([ - 'mdf:root://eoslhcb.cern.ch/%s' % f for f in glob.glob( - r'/eos/lhcb/grid/prod/lhcb/MC/Upgrade/MDF/00146082/000*/00146082_*') -]) -options.input_type = 'MDF' -options.dddb_tag = 'upgrade/dddb-20220612' -options.conddb_tag = 'upgrade/sim-20220612-vc-md100-RICHcustomFTv6' +options.input_files = sorted( + [ + "mdf:root://eoslhcb.cern.ch/%s" % f + for f in glob.glob( + r"/eos/lhcb/grid/prod/lhcb/MC/Upgrade/MDF/00146082/000*/00146082_*" + ) + ] +) +options.input_type = "MDF" +options.dddb_tag = "upgrade/dddb-20220612" +options.conddb_tag = "upgrade/sim-20220612-vc-md100-RICHcustomFTv6" -rich = 'rich1' +rich = "rich1" radiator = "Rich1Gas" track_types = [ - 'Long', + "Long", #'Upstream', #'Downstream', ] -param_list = ['p0_x', 'p1_x', 'p0_y', 'p1_y', 'p0_z', 'p1_z'] +param_list = ["p0_x", "p1_x", "p0_y", "p1_y", "p0_z", "p1_z"] param_dict = dict.fromkeys(param_list) # Only edit bad_align to play with alignment parameters @@ -71,7 +79,7 @@ default_level2_opts = {} default_reco_opts = {} # Reco opts -wider_bkg = {"PhotonSelection": 'None'} +wider_bkg = {"PhotonSelection": "None"} default_reco_opts.update(wider_bkg) panel_select = {"ActivatePanel": (True, False)} default_reco_opts.update(panel_select) @@ -79,19 +87,19 @@ default_reco_opts.update(panel_select) # Monitoring opts tighter_minp = { "TightTrackSelection": { - "MinP": 30. * GeV, + "MinP": 30.0 * GeV, "MinPt": 0.5 * GeV, - "MaxChi2": 2., + "MaxChi2": 2.0, "MaxGhostProb": 0.1, } } default_opts.update(tighter_minp) -wider_histo = {'CKResHistoRange': (0.025, 0.008, 0.004)} +wider_histo = {"CKResHistoRange": (0.025, 0.008, 0.004)} default_level2_opts.update(wider_histo) align_tasks = [ - 'Produce', # fill the production set of histograms - 'Monitor', # add various checking histograms + "Produce", # fill the production set of histograms + "Monitor", # add various checking histograms #'Map', # add counters for creation of the HLT1 pre-selection line "map" #'Optimize', # add counters for optimization of the RICH2 mirror combinations subset #'Select', # check filling the rest of RICH2 mirror combinations along with 8 poorest @@ -104,20 +112,26 @@ task = align_tasks[0] nkevts = str(math.trunc(options.evt_max / 1000)) # save output file with histograms -options.histo_file = 'rich1_opt.root' +options.histo_file = "rich1_opt.root" moni_set = "PhotonCherenkovAngles" standalone_hlt2_light_reco_without_UT -with add_hlt2_rich.bind( +with ( + add_hlt2_rich.bind( do_data_monitoring_rich=True, moni_set=moni_set, radiator=radiator, mirror_align_tasks=align_tasks, - track_types=track_types), \ - default_ft_decoding_version.bind(value=6), \ - default_rich_reco_options.bind(default_rich_reco_opts_modify=default_reco_opts), \ - default_rich_monitoring_options.bind(default_rich_moni_opts_modify=default_opts,default_rich_moni_opts_modify_level2=default_level2_opts), \ - standalone_hlt2_light_reco_without_UT.bind(skip_Muon=True): + track_types=track_types, + ), + default_ft_decoding_version.bind(value=6), + default_rich_reco_options.bind(default_rich_reco_opts_modify=default_reco_opts), + default_rich_monitoring_options.bind( + default_rich_moni_opts_modify=default_opts, + default_rich_moni_opts_modify_level2=default_level2_opts, + ), + standalone_hlt2_light_reco_without_UT.bind(skip_Muon=True), +): run_reconstruction(options, standalone_hlt2_light_reco_without_UT) diff --git a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/old_scripts/hlt2_reco_rich1_noUT_panoptes.py b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/old_scripts/hlt2_reco_rich1_noUT_panoptes.py index 67913862833f871d4b6246a5c9155aff40919ba2..63edfa17d98104a82ce0329fb1403a3798ff52da 100644 --- a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/old_scripts/hlt2_reco_rich1_noUT_panoptes.py +++ b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/old_scripts/hlt2_reco_rich1_noUT_panoptes.py @@ -8,45 +8,49 @@ # granted to it by virtue of its status as an Intergovernmental Organization # # or submit itself to any jurisdiction. # ############################################################################### -import glob import csv +import glob import math +from Configurables import UpdateManagerSvc from GaudiKernel.SystemOfUnits import ( - GeV, ) + GeV, +) from Moore import ( options, run_reconstruction, ) - +from Panoptes.alignment import standalone_rich_panel_align_reco from RecoConf.rich_data_monitoring import ( - default_rich_monitoring_options, ) - + default_rich_monitoring_options, +) from RecoConf.rich_reconstruction import default_rich_reco_options -from Panoptes.alignment import (standalone_rich_panel_align_reco) - -from Configurables import (UpdateManagerSvc) """Options for running over data with FT raw bank version 6.""" from RecoConf.decoders import ( - default_ft_decoding_version, ) + default_ft_decoding_version, +) options.n_threads = 10 options.evt_max = 10000 -options.input_type = 'MDF' -options.dddb_tag = 'upgrade/dddb-20220612' -options.conddb_tag = 'upgrade/sim-20220612-vc-md100-RICHcustomFTv6' -options.input_files = sorted([ - 'mdf:root://eoslhcb.cern.ch/%s' % f for f in glob.glob( - r'/eos/lhcb/grid/prod/lhcb/MC/Upgrade/MDF/00146082/000*/00146082_*') -]) +options.input_type = "MDF" +options.dddb_tag = "upgrade/dddb-20220612" +options.conddb_tag = "upgrade/sim-20220612-vc-md100-RICHcustomFTv6" +options.input_files = sorted( + [ + "mdf:root://eoslhcb.cern.ch/%s" % f + for f in glob.glob( + r"/eos/lhcb/grid/prod/lhcb/MC/Upgrade/MDF/00146082/000*/00146082_*" + ) + ] +) whichPanel = 0 # options: 0, 1, "both" -rich = 'rich1' +rich = "rich1" radiator = "Rich1Gas" -param_list = ['p0_x', 'p1_x', 'p0_y', 'p1_y', 'p0_z', 'p1_z'] +param_list = ["p0_x", "p1_x", "p0_y", "p1_y", "p0_z", "p1_z"] rot_perf_param_dict = dict.fromkeys(param_list) trans_perf_param_dict = dict.fromkeys(param_list) @@ -69,11 +73,12 @@ else: cond_update_list = [] for panel_num in panel_nums: - pre_cond_str = f'Conditions/Alignment/Rich1/PDPanel{panel_num}_Align := ' - optimum_trans_cond_str = f'double_v dPosXYZ = {trans_perf_param_dict["p" + str(panel_num)+ "_x"]} {trans_perf_param_dict["p" + str(panel_num)+ "_y"]} {trans_perf_param_dict["p" + str(panel_num)+ "_z"]}; ' - optimum_rot_cond_str = f'double_v dRotXYZ = {rot_perf_param_dict["p" + str(panel_num)+ "_x"]} {rot_perf_param_dict["p" + str(panel_num)+ "_y"]} {rot_perf_param_dict["p" + str(panel_num)+ "_z"]};' - cond_update_list.append(pre_cond_str + optimum_trans_cond_str + - optimum_rot_cond_str) + pre_cond_str = f"Conditions/Alignment/Rich1/PDPanel{panel_num}_Align := " + optimum_trans_cond_str = f"double_v dPosXYZ = {trans_perf_param_dict['p' + str(panel_num) + '_x']} {trans_perf_param_dict['p' + str(panel_num) + '_y']} {trans_perf_param_dict['p' + str(panel_num) + '_z']}; " + optimum_rot_cond_str = f"double_v dRotXYZ = {rot_perf_param_dict['p' + str(panel_num) + '_x']} {rot_perf_param_dict['p' + str(panel_num) + '_y']} {rot_perf_param_dict['p' + str(panel_num) + '_z']};" + cond_update_list.append( + pre_cond_str + optimum_trans_cond_str + optimum_rot_cond_str + ) UpdateManagerSvc().ConditionsOverride = cond_update_list @@ -97,20 +102,20 @@ default_reco_opts.update(panel_select) # Monitoring opts tighter_minp = { "TightTrackSelection": { - "MinP": 30. * GeV, + "MinP": 30.0 * GeV, "MinPt": 0.5 * GeV, - "MaxChi2": 2., + "MaxChi2": 2.0, "MaxGhostProb": 0.1, } } default_opts.update(tighter_minp) -wider_histo = {'CKResHistoRange': (0.025, 0.008, 0.004)} +wider_histo = {"CKResHistoRange": (0.025, 0.008, 0.004)} default_level2_opts.update(wider_histo) align_tasks = [ - 'Produce', # fill the production set of histograms - 'Monitor', # add various checking histograms + "Produce", # fill the production set of histograms + "Monitor", # add various checking histograms #'Map', # add counters for creation of the HLT1 pre-selection line "map" #'Optimize', # add counters for optimization of the RICH2 mirror combinations subset #'Select', # check filling the rest of RICH2 mirror combinations along with 8 poorest @@ -121,12 +126,16 @@ align_tasks = [ nkevts = str(math.trunc(options.evt_max / 1000)) # save output file with histograms -options.histo_file = 'rich1_opt.root' - - -with standalone_rich_panel_align_reco.bind(RichGas=radiator, \ - noUT=True), \ - default_ft_decoding_version.bind(value=6), \ - default_rich_reco_options.bind(default_rich_reco_opts_modify=default_reco_opts), \ - default_rich_monitoring_options.bind(default_rich_moni_opts_modify=default_opts,default_rich_moni_opts_modify_level2=default_level2_opts): +options.histo_file = "rich1_opt.root" + + +with ( + standalone_rich_panel_align_reco.bind(RichGas=radiator, noUT=True), + default_ft_decoding_version.bind(value=6), + default_rich_reco_options.bind(default_rich_reco_opts_modify=default_reco_opts), + default_rich_monitoring_options.bind( + default_rich_moni_opts_modify=default_opts, + default_rich_moni_opts_modify_level2=default_level2_opts, + ), +): run_reconstruction(options, standalone_rich_panel_align_reco) diff --git a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/old_scripts/hlt2_reco_rich2_moore.py b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/old_scripts/hlt2_reco_rich2_moore.py index 2889265c9baeaa45defcef6a267416737c446750..312bcad285cee8c63242578069999286024d2172 100644 --- a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/old_scripts/hlt2_reco_rich2_moore.py +++ b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/old_scripts/hlt2_reco_rich2_moore.py @@ -8,65 +8,72 @@ # granted to it by virtue of its status as an Intergovernmental Organization # # or submit itself to any jurisdiction. # ############################################################################### -import glob import csv +import glob import math +from Configurables import CondDB, UpdateManagerSvc from GaudiKernel.SystemOfUnits import ( - GeV, ) + GeV, +) from Moore import ( options, run_reconstruction, ) +from PyConf.tonic import configurable from RecoConf.rich_add_reconstruction_monitoring_checking import ( - add_hlt2_rich, ) + add_hlt2_rich, +) from RecoConf.rich_data_monitoring import ( - default_rich_monitoring_options, alignment_rich_monitoring_options, + default_rich_monitoring_options, ) - from RecoConf.rich_reconstruction import default_rich_reco_options - from RecoConf.standalone import ( - standalone_hlt2_reco, ) -from PyConf.tonic import configurable -from Configurables import (CondDB, UpdateManagerSvc) + standalone_hlt2_reco, +) + """Options for running over data with FT raw bank version 6.""" from RecoConf.decoders import ( - default_ft_decoding_version, ) + default_ft_decoding_version, +) options.n_threads = 10 options.evt_max = 10000 -options.input_files = sorted([ - 'mdf:root://eoslhcb.cern.ch/%s' % f for f in glob.glob( - r'/eos/lhcb/grid/prod/lhcb/MC/Upgrade/MDF/00146082/000*/00146082_*') -]) -options.input_type = 'MDF' -options.dddb_tag = 'upgrade/bmalecki-rich-alignmentParameters' -options.conddb_tag = 'upgrade/bmalecki-rich-alignmentParameters' +options.input_files = sorted( + [ + "mdf:root://eoslhcb.cern.ch/%s" % f + for f in glob.glob( + r"/eos/lhcb/grid/prod/lhcb/MC/Upgrade/MDF/00146082/000*/00146082_*" + ) + ] +) +options.input_type = "MDF" +options.dddb_tag = "upgrade/bmalecki-rich-alignmentParameters" +options.conddb_tag = "upgrade/bmalecki-rich-alignmentParameters" -rich = 'rich2' +rich = "rich2" radiator = "Rich2Gas" track_types = [ - 'Long', + "Long", #'Upstream', #'Downstream', ] # Import alignment parameters from csv file and apply -param_list = ['p0_x', 'p1_x', 'p0_y', 'p1_y', 'p0_z', 'p1_z'] +param_list = ["p0_x", "p1_x", "p0_y", "p1_y", "p0_z", "p1_z"] param_dict = dict.fromkeys(param_list) -#file_name = '/afs/cern.ch/work/j/jamey/public/rich_align/rich_align_upgrade/optimisation/rich2_params.csv' -#f = open(file_name, 'r') -#reader = csv.reader(f) +# file_name = '/afs/cern.ch/work/j/jamey/public/rich_align/rich_align_upgrade/optimisation/rich2_params.csv' +# f = open(file_name, 'r') +# reader = csv.reader(f) perf_align = [-1.32, 1.41, -4.74, -3.92, 4.79, 2.57] bad_align = [-0.32, 2.41, -2.74, -5.92, 4.79, 2.57] for row, param in zip(perf_align, param_dict.keys()): param_dict[param] = row -#f.close() +# f.close() UpdateManagerSvc().ConditionsOverride += [ f"Conditions/Alignment/Rich2/PDPanel0_Align := double_v dPosXYZ = {param_dict['p0_x']} {param_dict['p0_y']} {param_dict['p0_z']};", @@ -80,20 +87,20 @@ wider_bkg = {"PhotonSelection": "None"} default_reco_opts.update(wider_bkg) tighter_minp = { "TightTrackSelection": { - "MinP": 60. * GeV, + "MinP": 60.0 * GeV, "MinPt": 0.5 * GeV, - "MaxChi2": 2., + "MaxChi2": 2.0, "MaxGhostProb": 0.1, } } default_opts.update(tighter_minp) -wider_histo = {'CKResHistoRange': (0.025, 0.008, 0.012)} +wider_histo = {"CKResHistoRange": (0.025, 0.008, 0.012)} default_opts.update(wider_histo) align_tasks = [ - 'Produce', # fill the production set of histograms - 'Monitor', # add various checking histograms + "Produce", # fill the production set of histograms + "Monitor", # add various checking histograms #'Map', # add counters for creation of the HLT1 pre-selection line "map" #'Optimize', # add counters for optimization of the RICH2 mirror combinations subset #'Select', # check filling the rest of RICH2 mirror combinations along with 8 poorest @@ -106,17 +113,24 @@ task = align_tasks[0] nkevts = str(math.trunc(options.evt_max / 1000)) # save output file with histograms -options.histo_file = 'rich2_withhisto.root' +options.histo_file = "rich2_withhisto.root" moni_set = "PhotonCherenkovAngles" -with add_hlt2_rich.bind( +with ( + add_hlt2_rich.bind( do_data_monitoring_rich=True, moni_set=moni_set, radiator=radiator, align_tasks=align_tasks, - track_types=track_types), \ - default_ft_decoding_version.bind(value=6), \ - default_rich_reco_options.bind(default_rich_reco_opts_level2_modify=default_reco_opts), \ - default_rich_monitoring_options.bind(default_rich_moni_opts_level2_modify=default_opts): + track_types=track_types, + ), + default_ft_decoding_version.bind(value=6), + default_rich_reco_options.bind( + default_rich_reco_opts_level2_modify=default_reco_opts + ), + default_rich_monitoring_options.bind( + default_rich_moni_opts_level2_modify=default_opts + ), +): run_reconstruction(options, standalone_hlt2_reco) diff --git a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/old_scripts/hlt2_reco_rich2_noUT_moore.py b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/old_scripts/hlt2_reco_rich2_noUT_moore.py index e568ebc9a56b9b49ac94c4deb03be372efe8a58e..b8fe8e911776dd9d8cdeb860884ff10fdec4ae8e 100644 --- a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/old_scripts/hlt2_reco_rich2_noUT_moore.py +++ b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/old_scripts/hlt2_reco_rich2_noUT_moore.py @@ -8,56 +8,63 @@ # granted to it by virtue of its status as an Intergovernmental Organization # # or submit itself to any jurisdiction. # ############################################################################### -import glob import csv +import glob import math +from Configurables import UpdateManagerSvc from GaudiKernel.SystemOfUnits import ( - GeV, ) + GeV, +) from Moore import ( options, run_reconstruction, ) from RecoConf.rich_add_reconstruction_monitoring_checking import ( - add_hlt2_rich, ) + add_hlt2_rich, +) from RecoConf.rich_data_monitoring import ( - default_rich_monitoring_options, ) - + default_rich_monitoring_options, +) from RecoConf.rich_reconstruction import default_rich_reco_options - from RecoConf.standalone import ( - standalone_hlt2_light_reco_without_UT, ) + standalone_hlt2_light_reco_without_UT, +) -from Configurables import (UpdateManagerSvc) """Options for running over data with FT raw bank version 6.""" from RecoConf.decoders import ( - default_ft_decoding_version, ) + default_ft_decoding_version, +) options.n_threads = 6 options.evt_max = 10000 -options.input_files = sorted([ - 'mdf:root://eoslhcb.cern.ch/%s' % f for f in glob.glob( - r'/eos/lhcb/grid/prod/lhcb/MC/Upgrade/MDF/00146082/000*/00146082_*') -]) -options.input_type = 'MDF' +options.input_files = sorted( + [ + "mdf:root://eoslhcb.cern.ch/%s" % f + for f in glob.glob( + r"/eos/lhcb/grid/prod/lhcb/MC/Upgrade/MDF/00146082/000*/00146082_*" + ) + ] +) +options.input_type = "MDF" # options.dddb_tag = 'dddb-20220612' # options.conddb_tag = 'sim-20220612-vc-md100' -options.dddb_tag = 'upgrade/dddb-20220612' -options.conddb_tag = 'upgrade/sim-20220612-vc-md100-RICHcustomFTv6' +options.dddb_tag = "upgrade/dddb-20220612" +options.conddb_tag = "upgrade/sim-20220612-vc-md100-RICHcustomFTv6" -rich = 'rich2' +rich = "rich2" radiator = "Rich2Gas" track_types = [ - 'Long', + "Long", #'Upstream', #'Downstream', ] # Only edit bad_align to play with alignment parameters -param_list = ['p0_x', 'p1_x', 'p0_y', 'p1_y', 'p0_z', 'p1_z'] +param_list = ["p0_x", "p1_x", "p0_y", "p1_y", "p0_z", "p1_z"] param_dict = dict.fromkeys(param_list) perf_align = [-1.32, 1.41, -4.74, -3.92, 4.79, 2.57] bad_align = [-0.32, 2.41, -2.74, -5.92, 4.79, 2.57] @@ -82,20 +89,20 @@ default_reco_opts.update(panel_select) # Monitoring opts tighter_minp = { "TightTrackSelection": { - "MinP": 60. * GeV, + "MinP": 60.0 * GeV, "MinPt": 0.5 * GeV, - "MaxChi2": 2., + "MaxChi2": 2.0, "MaxGhostProb": 0.1, } } default_opts.update(tighter_minp) -wider_histo = {'CKResHistoRange': (0.025, 0.008, 0.012)} +wider_histo = {"CKResHistoRange": (0.025, 0.008, 0.012)} default_level2_opts.update(wider_histo) align_tasks = [ - 'Produce', # fill the production set of histograms - 'Monitor', # add various checking histograms + "Produce", # fill the production set of histograms + "Monitor", # add various checking histograms #'Map', # add counters for creation of the HLT1 pre-selection line "map" #'Optimize', # add counters for optimization of the RICH2 mirror combinations subset #'Select', # check filling the rest of RICH2 mirror combinations along with 8 poorest @@ -108,20 +115,26 @@ task = align_tasks[0] nkevts = str(math.trunc(options.evt_max / 1000)) # save output file with histograms -options.histo_file = 'rich2_opt.root' +options.histo_file = "rich2_opt.root" moni_set = "PhotonCherenkovAngles" -with add_hlt2_rich.bind( +with ( + add_hlt2_rich.bind( do_data_monitoring_rich=True, moni_set=moni_set, radiator=radiator, mirror_align_tasks=align_tasks, - track_types=track_types), \ - default_ft_decoding_version.bind(value=6), \ - default_rich_reco_options.bind(default_rich_reco_opts_modify=default_reco_opts), \ - default_rich_monitoring_options.bind(default_rich_moni_opts_modify=default_opts,default_rich_moni_opts_modify_level2=default_level2_opts), \ - standalone_hlt2_light_reco_without_UT.bind(skip_Muon=True): + track_types=track_types, + ), + default_ft_decoding_version.bind(value=6), + default_rich_reco_options.bind(default_rich_reco_opts_modify=default_reco_opts), + default_rich_monitoring_options.bind( + default_rich_moni_opts_modify=default_opts, + default_rich_moni_opts_modify_level2=default_level2_opts, + ), + standalone_hlt2_light_reco_without_UT.bind(skip_Muon=True), +): run_reconstruction(options, standalone_hlt2_light_reco_without_UT) # old -> make_hlt2_tracks_without_UT.bind(use_pr_kf=True, light_reco=True, fast_reco=True), \ diff --git a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/old_scripts/hlt2_reco_rich2_noUT_panoptes.py b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/old_scripts/hlt2_reco_rich2_noUT_panoptes.py index bde8c17b0a5211095de6529afbeecdd39df64c1f..08be19f787fca39ca150202c322f2e488c8ed209 100644 --- a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/old_scripts/hlt2_reco_rich2_noUT_panoptes.py +++ b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/old_scripts/hlt2_reco_rich2_noUT_panoptes.py @@ -8,45 +8,49 @@ # granted to it by virtue of its status as an Intergovernmental Organization # # or submit itself to any jurisdiction. # ############################################################################### -import glob import csv +import glob import math +from Configurables import UpdateManagerSvc from GaudiKernel.SystemOfUnits import ( - GeV, ) + GeV, +) from Moore import ( options, run_reconstruction, ) - +from Panoptes.alignment import standalone_rich_panel_align_reco from RecoConf.rich_data_monitoring import ( - default_rich_monitoring_options, ) - + default_rich_monitoring_options, +) from RecoConf.rich_reconstruction import default_rich_reco_options -from Panoptes.alignment import (standalone_rich_panel_align_reco) - -from Configurables import (UpdateManagerSvc) """Options for running over data with FT raw bank version 6.""" from RecoConf.decoders import ( - default_ft_decoding_version, ) + default_ft_decoding_version, +) options.n_threads = 10 options.evt_max = 10000 -options.input_type = 'MDF' -options.dddb_tag = 'upgrade/dddb-20220612' -options.conddb_tag = 'upgrade/sim-20220612-vc-md100-RICHcustomFTv6' -options.input_files = sorted([ - 'mdf:root://eoslhcb.cern.ch/%s' % f for f in glob.glob( - r'/eos/lhcb/grid/prod/lhcb/MC/Upgrade/MDF/00146082/000*/00146082_*') -]) +options.input_type = "MDF" +options.dddb_tag = "upgrade/dddb-20220612" +options.conddb_tag = "upgrade/sim-20220612-vc-md100-RICHcustomFTv6" +options.input_files = sorted( + [ + "mdf:root://eoslhcb.cern.ch/%s" % f + for f in glob.glob( + r"/eos/lhcb/grid/prod/lhcb/MC/Upgrade/MDF/00146082/000*/00146082_*" + ) + ] +) whichPanel = 0 # options: 0, 1, "both" -rich = 'rich2' +rich = "rich2" radiator = "Rich2Gas" -param_list = ['p0_x', 'p1_x', 'p0_y', 'p1_y', 'p0_z', 'p1_z'] +param_list = ["p0_x", "p1_x", "p0_y", "p1_y", "p0_z", "p1_z"] rot_perf_param_dict = dict.fromkeys(param_list) trans_perf_param_dict = dict.fromkeys(param_list) @@ -69,11 +73,12 @@ else: cond_update_list = [] for panel_num in panel_nums: - pre_cond_str = f'Conditions/Alignment/Rich2/PDPanel{panel_num}_Align := ' - optimum_trans_cond_str = f'double_v dPosXYZ = {trans_perf_param_dict["p" + str(panel_num)+ "_x"]} {trans_perf_param_dict["p" + str(panel_num)+ "_y"]} {trans_perf_param_dict["p" + str(panel_num)+ "_z"]}; ' - optimum_rot_cond_str = f'double_v dRotXYZ = {rot_perf_param_dict["p" + str(panel_num)+ "_x"]} {rot_perf_param_dict["p" + str(panel_num)+ "_y"]} {rot_perf_param_dict["p" + str(panel_num)+ "_z"]};' - cond_update_list.append(pre_cond_str + optimum_trans_cond_str + - optimum_rot_cond_str) + pre_cond_str = f"Conditions/Alignment/Rich2/PDPanel{panel_num}_Align := " + optimum_trans_cond_str = f"double_v dPosXYZ = {trans_perf_param_dict['p' + str(panel_num) + '_x']} {trans_perf_param_dict['p' + str(panel_num) + '_y']} {trans_perf_param_dict['p' + str(panel_num) + '_z']}; " + optimum_rot_cond_str = f"double_v dRotXYZ = {rot_perf_param_dict['p' + str(panel_num) + '_x']} {rot_perf_param_dict['p' + str(panel_num) + '_y']} {rot_perf_param_dict['p' + str(panel_num) + '_z']};" + cond_update_list.append( + pre_cond_str + optimum_trans_cond_str + optimum_rot_cond_str + ) UpdateManagerSvc().ConditionsOverride = cond_update_list @@ -97,20 +102,20 @@ default_reco_opts.update(panel_select) # Monitoring opts tighter_minp = { "TightTrackSelection": { - "MinP": 60. * GeV, + "MinP": 60.0 * GeV, "MinPt": 0.5 * GeV, - "MaxChi2": 2., + "MaxChi2": 2.0, "MaxGhostProb": 0.1, } } default_opts.update(tighter_minp) -wider_histo = {'CKResHistoRange': (0.025, 0.008, 0.012)} +wider_histo = {"CKResHistoRange": (0.025, 0.008, 0.012)} default_level2_opts.update(wider_histo) align_tasks = [ - 'Produce', # fill the production set of histograms - 'Monitor', # add various checking histograms + "Produce", # fill the production set of histograms + "Monitor", # add various checking histograms #'Map', # add counters for creation of the HLT1 pre-selection line "map" #'Optimize', # add counters for optimization of the RICH2 mirror combinations subset #'Select', # check filling the rest of RICH2 mirror combinations along with 8 poorest @@ -121,12 +126,16 @@ align_tasks = [ nkevts = str(math.trunc(options.evt_max / 1000)) # save output file with histograms -options.histo_file = 'rich2_opt.root' - - -with standalone_rich_panel_align_reco.bind(RichGas=radiator, \ - noUT=True), \ - default_ft_decoding_version.bind(value=6), \ - default_rich_reco_options.bind(default_rich_reco_opts_modify=default_reco_opts), \ - default_rich_monitoring_options.bind(default_rich_moni_opts_modify=default_opts,default_rich_moni_opts_modify_level2=default_level2_opts): +options.histo_file = "rich2_opt.root" + + +with ( + standalone_rich_panel_align_reco.bind(RichGas=radiator, noUT=True), + default_ft_decoding_version.bind(value=6), + default_rich_reco_options.bind(default_rich_reco_opts_modify=default_reco_opts), + default_rich_monitoring_options.bind( + default_rich_moni_opts_modify=default_opts, + default_rich_moni_opts_modify_level2=default_level2_opts, + ), +): run_reconstruction(options, standalone_rich_panel_align_reco) diff --git a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/hlt2_reco_rich1_noUT_survey_dd4hep_p0.py b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/hlt2_reco_rich1_noUT_survey_dd4hep_p0.py index 7fae84c073ede3aa59b9f9965a5d292ea0e02dc9..ea91bb0e5fb93c7998f49347bda0dea644f7ab5d 100644 --- a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/hlt2_reco_rich1_noUT_survey_dd4hep_p0.py +++ b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/hlt2_reco_rich1_noUT_survey_dd4hep_p0.py @@ -8,48 +8,47 @@ # granted to it by virtue of its status as an Intergovernmental Organization # # or submit itself to any jurisdiction. # ############################################################################### -import glob import csv +import glob import math -from GaudiKernel.SystemOfUnits import (GeV, MeV, mm, mrad) +from GaudiKernel.SystemOfUnits import GeV, MeV, mm, mrad from Moore import ( options, run_reconstruction, ) - -from RecoConf.rich_data_monitoring import ( - default_rich_monitoring_options, ) - -from PyConf.Algorithms import (VeloRetinaClusterTrackingSIMD, - PrForwardTrackingVelo, - VPRetinaFullClusterDecoder) +from Panoptes.alignment import ( + standalone_rich_online_align_reco, + standalone_rich_panel_align_reco, +) +from PyConf.Algorithms import ( + PrForwardTrackingVelo, + VeloRetinaClusterTrackingSIMD, + VPRetinaFullClusterDecoder, +) from RecoConf.legacy_rec_hlt1_tracking import ( - make_VeloClusterTrackingSIMD, make_reco_pvs, make_PatPV3DFuture_pvs, - make_velo_full_clusters) - + make_PatPV3DFuture_pvs, + make_reco_pvs, + make_velo_full_clusters, + make_VeloClusterTrackingSIMD, +) from RecoConf.rich_data_monitoring import ( - default_rich_monitoring_options, alignment_rich_monitoring_options, + default_rich_monitoring_options, ) - from RecoConf.rich_reconstruction import default_rich_reco_options -from Panoptes.alignment import ( - standalone_rich_online_align_reco, - standalone_rich_panel_align_reco, -) - # from Configurables import ( # UpdateManagerSvc # ) """Options for running over data with FT raw bank version 6.""" from RecoConf.decoders import ( - default_ft_decoding_version, ) + default_ft_decoding_version, +) whichRich = 1 whichPanel = 0 -survey_type = 'translation' +survey_type = "translation" manual_update = True @@ -62,14 +61,14 @@ options.n_threads = 1 options.scheduler_legacy_mode = False if useRealData is not True: - options.set_input_and_conds_from_testfiledb( - 'upgrade_Sept2022_minbias_0fb_md_xdigi') - options.input_type = 'ROOT' + options.set_input_and_conds_from_testfiledb("upgrade_Sept2022_minbias_0fb_md_xdigi") + options.input_type = "ROOT" else: exec( open( "/eos/user/j/jreich/stack_dd4hep_december/Panoptes/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/data_255358.py" - ).read()) + ).read() + ) options.simulation = False options.input_type = "MDF" @@ -86,44 +85,48 @@ if UseDD4Hep: from Configurables import DDDBConf dd4hep = DD4hepSvc( - DetectorList=["/world", "Magnet", "UT", "VP", "FT", "Rich1", "Rich2"]) + DetectorList=["/world", "Magnet", "UT", "VP", "FT", "Rich1", "Rich2"] + ) dd4hep.OutputLevel = 1 if useRealData: - options.conddb_tag = 'master' # used for real data - options.dddb_tag = 'run3/trunk' - DDDBConf().GeometryVersion = 'run3/trunk' # used for real data + options.conddb_tag = "master" # used for real data + options.dddb_tag = "run3/trunk" + DDDBConf().GeometryVersion = "run3/trunk" # used for real data # latest scifi and velo alignments dd4hep.UseConditionsOverlay = True - dd4hep.ConditionsVersion = 'alignment2022' + dd4hep.ConditionsVersion = "alignment2022" options.simulation = False else: - options.conddb_tag = 'jonrob/all-pmts-active' # used for DetDesc MC samples with DD4Hep - DDDBConf( - ).GeometryVersion = 'run3/before-rich1-geom-update-26052022' # used for DetDesc MC samples with DD4Hep + options.conddb_tag = ( + "jonrob/all-pmts-active" # used for DetDesc MC samples with DD4Hep + ) + DDDBConf().GeometryVersion = "run3/before-rich1-geom-update-26052022" # used for DetDesc MC samples with DD4Hep if manual_update: - conddb_path = '/eos/user/j/jreich/stack_dd4hep_december/Panoptes/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/lhcb-conditions-database' + conddb_path = "/eos/user/j/jreich/stack_dd4hep_december/Panoptes/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/lhcb-conditions-database" dd4hep.ConditionsLocation = "file://" + conddb_path else: - dd4hep.ConditionsLocation = 'git:/cvmfs/lhcb.cern.ch/lib/lhcb/git-conddb/lhcb-conditions-database.git' + dd4hep.ConditionsLocation = ( + "git:/cvmfs/lhcb.cern.ch/lib/lhcb/git-conddb/lhcb-conditions-database.git" + ) else: - options.conddb_tag = 'upgrade/sim-20220612-vc-md100-RICHcustomFTv6' + options.conddb_tag = "upgrade/sim-20220612-vc-md100-RICHcustomFTv6" options.simulation = True -rich = f'rich{whichRich}' -radiator = f'Rich{whichRich}Gas' +rich = f"rich{whichRich}" +radiator = f"Rich{whichRich}Gas" -param_list = ['p0_x', 'p1_x', 'p0_y', 'p1_y', 'p0_z', 'p1_z'] +param_list = ["p0_x", "p1_x", "p0_y", "p1_y", "p0_z", "p1_z"] param_dict = dict.fromkeys(param_list) trans_perf_param_dict = dict.fromkeys(param_list) # Change file name if running elsewhere -file_name = f'rich{whichRich}_{survey_type}_params_p{whichPanel}.csv' -f = open(file_name, 'r') +file_name = f"rich{whichRich}_{survey_type}_params_p{whichPanel}.csv" +f = open(file_name, "r") reader = csv.reader(f) for row, param in zip(reader, param_dict.keys()): param_dict[param] = float(row[0]) @@ -144,39 +147,37 @@ else: # update the conditons if UseDD4Hep: - # dd4hep.DumpConditions = True if manual_update: # "_" here so argparse can interpret it (gets replaced by a space later) - pos_condition = f'position:_[{param_dict["p" + str(whichPanel)+ "_x"]}_*_mm,_{param_dict["p" + str(whichPanel)+ "_y"]}_*_mm,_{param_dict["p" + str(whichPanel)+ "_z"]}_*_mm]' - rot_condition = 'rotation:_[0.0_*_mrad,_0.0_*_mrad,_0.0_*_mrad]' + pos_condition = f"position:_[{param_dict['p' + str(whichPanel) + '_x']}_*_mm,_{param_dict['p' + str(whichPanel) + '_y']}_*_mm,_{param_dict['p' + str(whichPanel) + '_z']}_*_mm]" + rot_condition = "rotation:_[0.0_*_mrad,_0.0_*_mrad,_0.0_*_mrad]" import os + os.system( - f'python manual_cond_update.py --whichRich 1 --whichPanel {whichPanel} --conddb_path {conddb_path}/ --pos_condition {pos_condition} --rot_condition {rot_condition} ' + f"python manual_cond_update.py --whichRich 1 --whichPanel {whichPanel} --conddb_path {conddb_path}/ --pos_condition {pos_condition} --rot_condition {rot_condition} " ) else: condval = "!alignment {position: [0.0 * mm, 0.0 * mm, 0.0 * mm] , rotation: [0.0 * mrad, 0.0 * mrad, 0.0 * mrad]}" - dd4hep.ConditionsOverride.update({ - "/world/BeforeMagnetRegion/Rich1/Rich1PmtPanel1:Panel": - condval - - # "/world/BeforeMagnetRegion/Rich1:Rich1System": - # condval - }) + dd4hep.ConditionsOverride.update( + { + "/world/BeforeMagnetRegion/Rich1/Rich1PmtPanel1:Panel": condval + # "/world/BeforeMagnetRegion/Rich1:Rich1System": + # condval + } + ) else: - cond_update_list = [] for panel_num in panel_nums: - pre_cond_str = f'Conditions/Alignment/Rich1/PDPanel{panel_num}_Align := ' - optimum_trans_cond_str = f'double_v dPosXYZ = {trans_perf_param_dict["p" + str(panel_num)+ "_x"]} {trans_perf_param_dict["p" + str(panel_num)+ "_y"]} {trans_perf_param_dict["p" + str(panel_num)+ "_z"]}; ' + pre_cond_str = f"Conditions/Alignment/Rich1/PDPanel{panel_num}_Align := " + optimum_trans_cond_str = f"double_v dPosXYZ = {trans_perf_param_dict['p' + str(panel_num) + '_x']} {trans_perf_param_dict['p' + str(panel_num) + '_y']} {trans_perf_param_dict['p' + str(panel_num) + '_z']}; " - update_cond = f'double_v {param_key} = {param_dict["p" + str(panel_num)+ "_x"]} {param_dict["p" + str(panel_num)+ "_y"]} {param_dict["p" + str(panel_num)+ "_z"]};' - cond_update_list.append(pre_cond_str + optimum_trans_cond_str + - update_cond) + update_cond = f"double_v {param_key} = {param_dict['p' + str(panel_num) + '_x']} {param_dict['p' + str(panel_num) + '_y']} {param_dict['p' + str(panel_num) + '_z']};" + cond_update_list.append(pre_cond_str + optimum_trans_cond_str + update_cond) UpdateManagerSvc().ConditionsOverride = cond_update_list @@ -200,16 +201,16 @@ default_reco_opts.update(panel_select) if whichRich == 1: tighter_minp = { "TightTrackSelection": { - "MinP": 30. * GeV, + "MinP": 30.0 * GeV, "MinPt": 0.5 * GeV, - "MaxChi2": 2., + "MaxChi2": 2.0, "MaxGhostProb": 0.1, } } if whichRich == 2: tighter_minp = { "TightTrackSelection": { - "MinP": 60. * GeV, + "MinP": 60.0 * GeV, "MinPt": 0.5 * GeV, "MaxChi2": 2.0, "MaxGhostProb": 0.1, @@ -217,14 +218,14 @@ if whichRich == 2: } default_moni_opts.update(tighter_minp) -wider_histo = {'CKResHistoRange': (0.025, 0.005, 0.004)} +wider_histo = {"CKResHistoRange": (0.025, 0.005, 0.004)} default_moni_opts.update(wider_histo) -useUT = {'UseUT': False} +useUT = {"UseUT": False} default_moni_opts.update(useUT) align_tasks = [ - 'Produce', # fill the production set of histograms - 'Monitor', # add various checking histograms + "Produce", # fill the production set of histograms + "Monitor", # add various checking histograms #'Map', # add counters for creation of the HLT1 pre-selection line "map" #'Optimize', # add counters for optimization of the RICH2 mirror combinations subset #'Select', # check filling the rest of RICH2 mirror combinations along with 8 poorest @@ -236,35 +237,36 @@ nkevts = str(math.trunc(options.evt_max / 1000)) # save output file with histograms if UseDD4Hep: - options.histo_file = f'rich{whichRich}_opt_dd4hep_p{whichPanel}.root' + options.histo_file = f"rich{whichRich}_opt_dd4hep_p{whichPanel}.root" else: - options.histo_file = f'rich{whichRich}_opt_p{whichPanel}.root' + options.histo_file = f"rich{whichRich}_opt_p{whichPanel}.root" PrForwardTrackingVelo.global_bind( MinQuality=0.0, DeltaQuality=0.0, - DecisionLDA=-99., + DecisionLDA=-99.0, MinTotalHits=9, - MaxChi2PerDoF=50., - MaxChi2XProjection=60., - MaxChi2PerDoFFinal=28., - MaxChi2Stereo=16., - MaxChi2StereoAdd=16., + MaxChi2PerDoF=50.0, + MaxChi2XProjection=60.0, + MaxChi2PerDoFFinal=28.0, + MaxChi2Stereo=16.0, + MaxChi2StereoAdd=16.0, ) -make_VeloClusterTrackingSIMD.global_bind( - algorithm=VeloRetinaClusterTrackingSIMD) -make_velo_full_clusters.global_bind( - make_full_cluster=VPRetinaFullClusterDecoder) +make_VeloClusterTrackingSIMD.global_bind(algorithm=VeloRetinaClusterTrackingSIMD) +make_velo_full_clusters.global_bind(make_full_cluster=VPRetinaFullClusterDecoder) make_reco_pvs.global_bind(make_pvs_from_velo_tracks=make_PatPV3DFuture_pvs) - -with standalone_rich_online_align_reco.bind(RichGas=radiator, MirrorAlignTasks = align_tasks,\ - noUT=True), \ - alignment_rich_monitoring_options.bind(radiator=radiator, \ - init_override_opts=align_opts), \ - default_ft_decoding_version.bind(value=6), \ - default_rich_reco_options.bind(init_override_opts=default_reco_opts), \ - default_rich_monitoring_options.bind(init_override_opts=default_moni_opts): +with ( + standalone_rich_online_align_reco.bind( + RichGas=radiator, MirrorAlignTasks=align_tasks, noUT=True + ), + alignment_rich_monitoring_options.bind( + radiator=radiator, init_override_opts=align_opts + ), + default_ft_decoding_version.bind(value=6), + default_rich_reco_options.bind(init_override_opts=default_reco_opts), + default_rich_monitoring_options.bind(init_override_opts=default_moni_opts), +): run_reconstruction(options, standalone_rich_online_align_reco) diff --git a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/hlt2_reco_rich1_noUT_survey_dd4hep_p1.py b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/hlt2_reco_rich1_noUT_survey_dd4hep_p1.py index 72a986c4390d3d12209aec09b1329a46a865563e..7fd1c9bf7f5c64f3b5ee004d25cc141be05bad27 100644 --- a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/hlt2_reco_rich1_noUT_survey_dd4hep_p1.py +++ b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/hlt2_reco_rich1_noUT_survey_dd4hep_p1.py @@ -8,48 +8,47 @@ # granted to it by virtue of its status as an Intergovernmental Organization # # or submit itself to any jurisdiction. # ############################################################################### -import glob import csv +import glob import math -from GaudiKernel.SystemOfUnits import (GeV, MeV, mm, mrad) +from GaudiKernel.SystemOfUnits import GeV, MeV, mm, mrad from Moore import ( options, run_reconstruction, ) - -from RecoConf.rich_data_monitoring import ( - default_rich_monitoring_options, ) - -from PyConf.Algorithms import (VeloRetinaClusterTrackingSIMD, - PrForwardTrackingVelo, - VPRetinaFullClusterDecoder) +from Panoptes.alignment import ( + standalone_rich_online_align_reco, + standalone_rich_panel_align_reco, +) +from PyConf.Algorithms import ( + PrForwardTrackingVelo, + VeloRetinaClusterTrackingSIMD, + VPRetinaFullClusterDecoder, +) from RecoConf.legacy_rec_hlt1_tracking import ( - make_VeloClusterTrackingSIMD, make_reco_pvs, make_PatPV3DFuture_pvs, - make_velo_full_clusters) - + make_PatPV3DFuture_pvs, + make_reco_pvs, + make_velo_full_clusters, + make_VeloClusterTrackingSIMD, +) from RecoConf.rich_data_monitoring import ( - default_rich_monitoring_options, alignment_rich_monitoring_options, + default_rich_monitoring_options, ) - from RecoConf.rich_reconstruction import default_rich_reco_options -from Panoptes.alignment import ( - standalone_rich_online_align_reco, - standalone_rich_panel_align_reco, -) - # from Configurables import ( # UpdateManagerSvc # ) """Options for running over data with FT raw bank version 6.""" from RecoConf.decoders import ( - default_ft_decoding_version, ) + default_ft_decoding_version, +) whichRich = 1 whichPanel = 1 -survey_type = 'translation' +survey_type = "translation" manual_update = True @@ -62,14 +61,14 @@ options.n_threads = 1 options.scheduler_legacy_mode = False if useRealData is not True: - options.set_input_and_conds_from_testfiledb( - 'upgrade_Sept2022_minbias_0fb_md_xdigi') - options.input_type = 'ROOT' + options.set_input_and_conds_from_testfiledb("upgrade_Sept2022_minbias_0fb_md_xdigi") + options.input_type = "ROOT" else: exec( open( "/eos/user/j/jreich/stack_dd4hep_december/Panoptes/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/data_255358.py" - ).read()) + ).read() + ) options.simulation = False options.input_type = "MDF" @@ -86,44 +85,48 @@ if UseDD4Hep: from Configurables import DDDBConf dd4hep = DD4hepSvc( - DetectorList=["/world", "Magnet", "UT", "VP", "FT", "Rich1", "Rich2"]) + DetectorList=["/world", "Magnet", "UT", "VP", "FT", "Rich1", "Rich2"] + ) dd4hep.OutputLevel = 1 if useRealData: - options.conddb_tag = 'master' # used for real data - options.dddb_tag = 'run3/trunk' - DDDBConf().GeometryVersion = 'run3/trunk' # used for real data + options.conddb_tag = "master" # used for real data + options.dddb_tag = "run3/trunk" + DDDBConf().GeometryVersion = "run3/trunk" # used for real data # latest scifi and velo alignments dd4hep.UseConditionsOverlay = True - dd4hep.ConditionsVersion = 'alignment2022' + dd4hep.ConditionsVersion = "alignment2022" options.simulation = False else: - options.conddb_tag = 'jonrob/all-pmts-active' # used for DetDesc MC samples with DD4Hep - DDDBConf( - ).GeometryVersion = 'run3/before-rich1-geom-update-26052022' # used for DetDesc MC samples with DD4Hep + options.conddb_tag = ( + "jonrob/all-pmts-active" # used for DetDesc MC samples with DD4Hep + ) + DDDBConf().GeometryVersion = "run3/before-rich1-geom-update-26052022" # used for DetDesc MC samples with DD4Hep if manual_update: - conddb_path = '/eos/user/j/jreich/stack_dd4hep_december/Panoptes/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/lhcb-conditions-database' + conddb_path = "/eos/user/j/jreich/stack_dd4hep_december/Panoptes/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/lhcb-conditions-database" dd4hep.ConditionsLocation = "file://" + conddb_path else: - dd4hep.ConditionsLocation = 'git:/cvmfs/lhcb.cern.ch/lib/lhcb/git-conddb/lhcb-conditions-database.git' + dd4hep.ConditionsLocation = ( + "git:/cvmfs/lhcb.cern.ch/lib/lhcb/git-conddb/lhcb-conditions-database.git" + ) else: - options.conddb_tag = 'upgrade/sim-20220612-vc-md100-RICHcustomFTv6' + options.conddb_tag = "upgrade/sim-20220612-vc-md100-RICHcustomFTv6" options.simulation = True -rich = f'rich{whichRich}' -radiator = f'Rich{whichRich}Gas' +rich = f"rich{whichRich}" +radiator = f"Rich{whichRich}Gas" -param_list = ['p0_x', 'p1_x', 'p0_y', 'p1_y', 'p0_z', 'p1_z'] +param_list = ["p0_x", "p1_x", "p0_y", "p1_y", "p0_z", "p1_z"] param_dict = dict.fromkeys(param_list) trans_perf_param_dict = dict.fromkeys(param_list) # Change file name if running elsewhere -file_name = f'rich{whichRich}_{survey_type}_params_p{whichPanel}.csv' -f = open(file_name, 'r') +file_name = f"rich{whichRich}_{survey_type}_params_p{whichPanel}.csv" +f = open(file_name, "r") reader = csv.reader(f) for row, param in zip(reader, param_dict.keys()): param_dict[param] = float(row[0]) @@ -144,39 +147,37 @@ else: # update the conditons if UseDD4Hep: - # dd4hep.DumpConditions = True if manual_update: # "_" here so argparse can interpret it (gets replaced by a space later) - pos_condition = f'position:_[{param_dict["p" + str(whichPanel)+ "_x"]}_*_mm,_{param_dict["p" + str(whichPanel)+ "_y"]}_*_mm,_{param_dict["p" + str(whichPanel)+ "_z"]}_*_mm]' - rot_condition = 'rotation:_[0.0_*_mrad,_0.0_*_mrad,_0.0_*_mrad]' + pos_condition = f"position:_[{param_dict['p' + str(whichPanel) + '_x']}_*_mm,_{param_dict['p' + str(whichPanel) + '_y']}_*_mm,_{param_dict['p' + str(whichPanel) + '_z']}_*_mm]" + rot_condition = "rotation:_[0.0_*_mrad,_0.0_*_mrad,_0.0_*_mrad]" import os + os.system( - f'python manual_cond_update.py --whichRich 1 --whichPanel {whichPanel} --conddb_path {conddb_path}/ --pos_condition {pos_condition} --rot_condition {rot_condition} ' + f"python manual_cond_update.py --whichRich 1 --whichPanel {whichPanel} --conddb_path {conddb_path}/ --pos_condition {pos_condition} --rot_condition {rot_condition} " ) else: condval = "!alignment {position: [0.0 * mm, 0.0 * mm, 0.0 * mm] , rotation: [0.0 * mrad, 0.0 * mrad, 0.0 * mrad]}" - dd4hep.ConditionsOverride.update({ - "/world/BeforeMagnetRegion/Rich1/Rich1PmtPanel1:Panel": - condval - - # "/world/BeforeMagnetRegion/Rich1:Rich1System": - # condval - }) + dd4hep.ConditionsOverride.update( + { + "/world/BeforeMagnetRegion/Rich1/Rich1PmtPanel1:Panel": condval + # "/world/BeforeMagnetRegion/Rich1:Rich1System": + # condval + } + ) else: - cond_update_list = [] for panel_num in panel_nums: - pre_cond_str = f'Conditions/Alignment/Rich1/PDPanel{panel_num}_Align := ' - optimum_trans_cond_str = f'double_v dPosXYZ = {trans_perf_param_dict["p" + str(panel_num)+ "_x"]} {trans_perf_param_dict["p" + str(panel_num)+ "_y"]} {trans_perf_param_dict["p" + str(panel_num)+ "_z"]}; ' + pre_cond_str = f"Conditions/Alignment/Rich1/PDPanel{panel_num}_Align := " + optimum_trans_cond_str = f"double_v dPosXYZ = {trans_perf_param_dict['p' + str(panel_num) + '_x']} {trans_perf_param_dict['p' + str(panel_num) + '_y']} {trans_perf_param_dict['p' + str(panel_num) + '_z']}; " - update_cond = f'double_v {param_key} = {param_dict["p" + str(panel_num)+ "_x"]} {param_dict["p" + str(panel_num)+ "_y"]} {param_dict["p" + str(panel_num)+ "_z"]};' - cond_update_list.append(pre_cond_str + optimum_trans_cond_str + - update_cond) + update_cond = f"double_v {param_key} = {param_dict['p' + str(panel_num) + '_x']} {param_dict['p' + str(panel_num) + '_y']} {param_dict['p' + str(panel_num) + '_z']};" + cond_update_list.append(pre_cond_str + optimum_trans_cond_str + update_cond) UpdateManagerSvc().ConditionsOverride = cond_update_list @@ -200,16 +201,16 @@ default_reco_opts.update(panel_select) if whichRich == 1: tighter_minp = { "TightTrackSelection": { - "MinP": 30. * GeV, + "MinP": 30.0 * GeV, "MinPt": 0.5 * GeV, - "MaxChi2": 2., + "MaxChi2": 2.0, "MaxGhostProb": 0.1, } } if whichRich == 2: tighter_minp = { "TightTrackSelection": { - "MinP": 60. * GeV, + "MinP": 60.0 * GeV, "MinPt": 0.5 * GeV, "MaxChi2": 2.0, "MaxGhostProb": 0.1, @@ -217,14 +218,14 @@ if whichRich == 2: } default_moni_opts.update(tighter_minp) -wider_histo = {'CKResHistoRange': (0.025, 0.005, 0.004)} +wider_histo = {"CKResHistoRange": (0.025, 0.005, 0.004)} default_moni_opts.update(wider_histo) -useUT = {'UseUT': False} +useUT = {"UseUT": False} default_moni_opts.update(useUT) align_tasks = [ - 'Produce', # fill the production set of histograms - 'Monitor', # add various checking histograms + "Produce", # fill the production set of histograms + "Monitor", # add various checking histograms #'Map', # add counters for creation of the HLT1 pre-selection line "map" #'Optimize', # add counters for optimization of the RICH2 mirror combinations subset #'Select', # check filling the rest of RICH2 mirror combinations along with 8 poorest @@ -236,35 +237,36 @@ nkevts = str(math.trunc(options.evt_max / 1000)) # save output file with histograms if UseDD4Hep: - options.histo_file = f'rich{whichRich}_opt_dd4hep_p{whichPanel}.root' + options.histo_file = f"rich{whichRich}_opt_dd4hep_p{whichPanel}.root" else: - options.histo_file = f'rich{whichRich}_opt_p{whichPanel}.root' + options.histo_file = f"rich{whichRich}_opt_p{whichPanel}.root" PrForwardTrackingVelo.global_bind( MinQuality=0.0, DeltaQuality=0.0, - DecisionLDA=-99., + DecisionLDA=-99.0, MinTotalHits=9, - MaxChi2PerDoF=50., - MaxChi2XProjection=60., - MaxChi2PerDoFFinal=28., - MaxChi2Stereo=16., - MaxChi2StereoAdd=16., + MaxChi2PerDoF=50.0, + MaxChi2XProjection=60.0, + MaxChi2PerDoFFinal=28.0, + MaxChi2Stereo=16.0, + MaxChi2StereoAdd=16.0, ) -make_VeloClusterTrackingSIMD.global_bind( - algorithm=VeloRetinaClusterTrackingSIMD) -make_velo_full_clusters.global_bind( - make_full_cluster=VPRetinaFullClusterDecoder) +make_VeloClusterTrackingSIMD.global_bind(algorithm=VeloRetinaClusterTrackingSIMD) +make_velo_full_clusters.global_bind(make_full_cluster=VPRetinaFullClusterDecoder) make_reco_pvs.global_bind(make_pvs_from_velo_tracks=make_PatPV3DFuture_pvs) - -with standalone_rich_online_align_reco.bind(RichGas=radiator, MirrorAlignTasks = align_tasks,\ - noUT=True), \ - alignment_rich_monitoring_options.bind(radiator=radiator, \ - init_override_opts=align_opts), \ - default_ft_decoding_version.bind(value=6), \ - default_rich_reco_options.bind(init_override_opts=default_reco_opts), \ - default_rich_monitoring_options.bind(init_override_opts=default_moni_opts): +with ( + standalone_rich_online_align_reco.bind( + RichGas=radiator, MirrorAlignTasks=align_tasks, noUT=True + ), + alignment_rich_monitoring_options.bind( + radiator=radiator, init_override_opts=align_opts + ), + default_ft_decoding_version.bind(value=6), + default_rich_reco_options.bind(init_override_opts=default_reco_opts), + default_rich_monitoring_options.bind(init_override_opts=default_moni_opts), +): run_reconstruction(options, standalone_rich_online_align_reco) diff --git a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/hlt2_reco_rich2_noUT_survey_dd4hep_p0.py b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/hlt2_reco_rich2_noUT_survey_dd4hep_p0.py index a1038e9e9ad2d2eb342927e996bde352fbb19e75..76e46e159cb8052ae21d0cc7b38b56e67869d4ec 100644 --- a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/hlt2_reco_rich2_noUT_survey_dd4hep_p0.py +++ b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/hlt2_reco_rich2_noUT_survey_dd4hep_p0.py @@ -8,48 +8,47 @@ # granted to it by virtue of its status as an Intergovernmental Organization # # or submit itself to any jurisdiction. # ############################################################################### -import glob import csv +import glob import math -from GaudiKernel.SystemOfUnits import (GeV, MeV, mm, mrad) +from GaudiKernel.SystemOfUnits import GeV, MeV, mm, mrad from Moore import ( options, run_reconstruction, ) - -from RecoConf.rich_data_monitoring import ( - default_rich_monitoring_options, ) - -from PyConf.Algorithms import (VeloRetinaClusterTrackingSIMD, - PrForwardTrackingVelo, - VPRetinaFullClusterDecoder) +from Panoptes.alignment import ( + standalone_rich_online_align_reco, + standalone_rich_panel_align_reco, +) +from PyConf.Algorithms import ( + PrForwardTrackingVelo, + VeloRetinaClusterTrackingSIMD, + VPRetinaFullClusterDecoder, +) from RecoConf.legacy_rec_hlt1_tracking import ( - make_VeloClusterTrackingSIMD, make_reco_pvs, make_PatPV3DFuture_pvs, - make_velo_full_clusters) - + make_PatPV3DFuture_pvs, + make_reco_pvs, + make_velo_full_clusters, + make_VeloClusterTrackingSIMD, +) from RecoConf.rich_data_monitoring import ( - default_rich_monitoring_options, alignment_rich_monitoring_options, + default_rich_monitoring_options, ) - from RecoConf.rich_reconstruction import default_rich_reco_options -from Panoptes.alignment import ( - standalone_rich_online_align_reco, - standalone_rich_panel_align_reco, -) - # from Configurables import ( # UpdateManagerSvc # ) """Options for running over data with FT raw bank version 6.""" from RecoConf.decoders import ( - default_ft_decoding_version, ) + default_ft_decoding_version, +) whichRich = 2 whichPanel = 0 -survey_type = 'translation' +survey_type = "translation" manual_update = True @@ -62,14 +61,14 @@ options.n_threads = 1 options.scheduler_legacy_mode = False if useRealData is not True: - options.set_input_and_conds_from_testfiledb( - 'upgrade_Sept2022_minbias_0fb_md_xdigi') - options.input_type = 'ROOT' + options.set_input_and_conds_from_testfiledb("upgrade_Sept2022_minbias_0fb_md_xdigi") + options.input_type = "ROOT" else: exec( open( "/eos/user/j/jreich/stack_dd4hep_december/Panoptes/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/data_255358.py" - ).read()) + ).read() + ) options.simulation = False options.input_type = "MDF" @@ -86,44 +85,48 @@ if UseDD4Hep: from Configurables import DDDBConf dd4hep = DD4hepSvc( - DetectorList=["/world", "Magnet", "UT", "VP", "FT", "Rich1", "Rich2"]) + DetectorList=["/world", "Magnet", "UT", "VP", "FT", "Rich1", "Rich2"] + ) dd4hep.OutputLevel = 1 if useRealData: - options.conddb_tag = 'master' # used for real data - options.dddb_tag = 'run3/trunk' - DDDBConf().GeometryVersion = 'run3/trunk' # used for real data + options.conddb_tag = "master" # used for real data + options.dddb_tag = "run3/trunk" + DDDBConf().GeometryVersion = "run3/trunk" # used for real data # latest scifi and velo alignments dd4hep.UseConditionsOverlay = True - dd4hep.ConditionsVersion = 'alignment2022' + dd4hep.ConditionsVersion = "alignment2022" options.simulation = False else: - options.conddb_tag = 'jonrob/all-pmts-active' # used for DetDesc MC samples with DD4Hep - DDDBConf( - ).GeometryVersion = 'run3/before-rich1-geom-update-26052022' # used for DetDesc MC samples with DD4Hep + options.conddb_tag = ( + "jonrob/all-pmts-active" # used for DetDesc MC samples with DD4Hep + ) + DDDBConf().GeometryVersion = "run3/before-rich1-geom-update-26052022" # used for DetDesc MC samples with DD4Hep if manual_update: - conddb_path = '/eos/user/j/jreich/stack_dd4hep_december/Panoptes/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/lhcb-conditions-database' + conddb_path = "/eos/user/j/jreich/stack_dd4hep_december/Panoptes/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/lhcb-conditions-database" dd4hep.ConditionsLocation = "file://" + conddb_path else: - dd4hep.ConditionsLocation = 'git:/cvmfs/lhcb.cern.ch/lib/lhcb/git-conddb/lhcb-conditions-database.git' + dd4hep.ConditionsLocation = ( + "git:/cvmfs/lhcb.cern.ch/lib/lhcb/git-conddb/lhcb-conditions-database.git" + ) else: - options.conddb_tag = 'upgrade/sim-20220612-vc-md100-RICHcustomFTv6' + options.conddb_tag = "upgrade/sim-20220612-vc-md100-RICHcustomFTv6" options.simulation = True -rich = f'rich{whichRich}' -radiator = f'Rich{whichRich}Gas' +rich = f"rich{whichRich}" +radiator = f"Rich{whichRich}Gas" -param_list = ['p0_x', 'p1_x', 'p0_y', 'p1_y', 'p0_z', 'p1_z'] +param_list = ["p0_x", "p1_x", "p0_y", "p1_y", "p0_z", "p1_z"] param_dict = dict.fromkeys(param_list) trans_perf_param_dict = dict.fromkeys(param_list) # Change file name if running elsewhere -file_name = f'rich{whichRich}_{survey_type}_params_p{whichPanel}.csv' -f = open(file_name, 'r') +file_name = f"rich{whichRich}_{survey_type}_params_p{whichPanel}.csv" +f = open(file_name, "r") reader = csv.reader(f) for row, param in zip(reader, param_dict.keys()): param_dict[param] = float(row[0]) @@ -144,39 +147,37 @@ else: # update the conditons if UseDD4Hep: - # dd4hep.DumpConditions = True if manual_update: # "_" here so argparse can interpret it (gets replaced by a space later) - pos_condition = f'position:_[{param_dict["p" + str(whichPanel)+ "_x"]}_*_mm,_{param_dict["p" + str(whichPanel)+ "_y"]}_*_mm,_{param_dict["p" + str(whichPanel)+ "_z"]}_*_mm]' - rot_condition = 'rotation:_[0.0_*_mrad,_0.0_*_mrad,_0.0_*_mrad]' + pos_condition = f"position:_[{param_dict['p' + str(whichPanel) + '_x']}_*_mm,_{param_dict['p' + str(whichPanel) + '_y']}_*_mm,_{param_dict['p' + str(whichPanel) + '_z']}_*_mm]" + rot_condition = "rotation:_[0.0_*_mrad,_0.0_*_mrad,_0.0_*_mrad]" import os + os.system( - f'python manual_cond_update.py --whichRich 1 --whichPanel {whichPanel} --conddb_path {conddb_path}/ --pos_condition {pos_condition} --rot_condition {rot_condition} ' + f"python manual_cond_update.py --whichRich 1 --whichPanel {whichPanel} --conddb_path {conddb_path}/ --pos_condition {pos_condition} --rot_condition {rot_condition} " ) else: condval = "!alignment {position: [0.0 * mm, 0.0 * mm, 0.0 * mm] , rotation: [0.0 * mrad, 0.0 * mrad, 0.0 * mrad]}" - dd4hep.ConditionsOverride.update({ - "/world/BeforeMagnetRegion/Rich1/Rich1PmtPanel1:Panel": - condval - - # "/world/BeforeMagnetRegion/Rich1:Rich1System": - # condval - }) + dd4hep.ConditionsOverride.update( + { + "/world/BeforeMagnetRegion/Rich1/Rich1PmtPanel1:Panel": condval + # "/world/BeforeMagnetRegion/Rich1:Rich1System": + # condval + } + ) else: - cond_update_list = [] for panel_num in panel_nums: - pre_cond_str = f'Conditions/Alignment/Rich1/PDPanel{panel_num}_Align := ' - optimum_trans_cond_str = f'double_v dPosXYZ = {trans_perf_param_dict["p" + str(panel_num)+ "_x"]} {trans_perf_param_dict["p" + str(panel_num)+ "_y"]} {trans_perf_param_dict["p" + str(panel_num)+ "_z"]}; ' + pre_cond_str = f"Conditions/Alignment/Rich1/PDPanel{panel_num}_Align := " + optimum_trans_cond_str = f"double_v dPosXYZ = {trans_perf_param_dict['p' + str(panel_num) + '_x']} {trans_perf_param_dict['p' + str(panel_num) + '_y']} {trans_perf_param_dict['p' + str(panel_num) + '_z']}; " - update_cond = f'double_v {param_key} = {param_dict["p" + str(panel_num)+ "_x"]} {param_dict["p" + str(panel_num)+ "_y"]} {param_dict["p" + str(panel_num)+ "_z"]};' - cond_update_list.append(pre_cond_str + optimum_trans_cond_str + - update_cond) + update_cond = f"double_v {param_key} = {param_dict['p' + str(panel_num) + '_x']} {param_dict['p' + str(panel_num) + '_y']} {param_dict['p' + str(panel_num) + '_z']};" + cond_update_list.append(pre_cond_str + optimum_trans_cond_str + update_cond) UpdateManagerSvc().ConditionsOverride = cond_update_list @@ -200,16 +201,16 @@ default_reco_opts.update(panel_select) if whichRich == 1: tighter_minp = { "TightTrackSelection": { - "MinP": 30. * GeV, + "MinP": 30.0 * GeV, "MinPt": 0.5 * GeV, - "MaxChi2": 2., + "MaxChi2": 2.0, "MaxGhostProb": 0.1, } } if whichRich == 2: tighter_minp = { "TightTrackSelection": { - "MinP": 60. * GeV, + "MinP": 60.0 * GeV, "MinPt": 0.5 * GeV, "MaxChi2": 2.0, "MaxGhostProb": 0.1, @@ -217,14 +218,14 @@ if whichRich == 2: } default_moni_opts.update(tighter_minp) -wider_histo = {'CKResHistoRange': (0.025, 0.005, 0.004)} +wider_histo = {"CKResHistoRange": (0.025, 0.005, 0.004)} default_moni_opts.update(wider_histo) -useUT = {'UseUT': False} +useUT = {"UseUT": False} default_moni_opts.update(useUT) align_tasks = [ - 'Produce', # fill the production set of histograms - 'Monitor', # add various checking histograms + "Produce", # fill the production set of histograms + "Monitor", # add various checking histograms #'Map', # add counters for creation of the HLT1 pre-selection line "map" #'Optimize', # add counters for optimization of the RICH2 mirror combinations subset #'Select', # check filling the rest of RICH2 mirror combinations along with 8 poorest @@ -236,35 +237,36 @@ nkevts = str(math.trunc(options.evt_max / 1000)) # save output file with histograms if UseDD4Hep: - options.histo_file = f'rich{whichRich}_opt_dd4hep_p{whichPanel}.root' + options.histo_file = f"rich{whichRich}_opt_dd4hep_p{whichPanel}.root" else: - options.histo_file = f'rich{whichRich}_opt_p{whichPanel}.root' + options.histo_file = f"rich{whichRich}_opt_p{whichPanel}.root" PrForwardTrackingVelo.global_bind( MinQuality=0.0, DeltaQuality=0.0, - DecisionLDA=-99., + DecisionLDA=-99.0, MinTotalHits=9, - MaxChi2PerDoF=50., - MaxChi2XProjection=60., - MaxChi2PerDoFFinal=28., - MaxChi2Stereo=16., - MaxChi2StereoAdd=16., + MaxChi2PerDoF=50.0, + MaxChi2XProjection=60.0, + MaxChi2PerDoFFinal=28.0, + MaxChi2Stereo=16.0, + MaxChi2StereoAdd=16.0, ) -make_VeloClusterTrackingSIMD.global_bind( - algorithm=VeloRetinaClusterTrackingSIMD) -make_velo_full_clusters.global_bind( - make_full_cluster=VPRetinaFullClusterDecoder) +make_VeloClusterTrackingSIMD.global_bind(algorithm=VeloRetinaClusterTrackingSIMD) +make_velo_full_clusters.global_bind(make_full_cluster=VPRetinaFullClusterDecoder) make_reco_pvs.global_bind(make_pvs_from_velo_tracks=make_PatPV3DFuture_pvs) - -with standalone_rich_online_align_reco.bind(RichGas=radiator, MirrorAlignTasks = align_tasks,\ - noUT=True), \ - alignment_rich_monitoring_options.bind(radiator=radiator, \ - init_override_opts=align_opts), \ - default_ft_decoding_version.bind(value=6), \ - default_rich_reco_options.bind(init_override_opts=default_reco_opts), \ - default_rich_monitoring_options.bind(init_override_opts=default_moni_opts): +with ( + standalone_rich_online_align_reco.bind( + RichGas=radiator, MirrorAlignTasks=align_tasks, noUT=True + ), + alignment_rich_monitoring_options.bind( + radiator=radiator, init_override_opts=align_opts + ), + default_ft_decoding_version.bind(value=6), + default_rich_reco_options.bind(init_override_opts=default_reco_opts), + default_rich_monitoring_options.bind(init_override_opts=default_moni_opts), +): run_reconstruction(options, standalone_rich_online_align_reco) diff --git a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/hlt2_reco_rich2_noUT_survey_dd4hep_p1.py b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/hlt2_reco_rich2_noUT_survey_dd4hep_p1.py index da73b5ecf4df48bd1992b3d2a4c8442d8fe597b4..dde811440146bce3758113c620efff2bfb8ba0c7 100644 --- a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/hlt2_reco_rich2_noUT_survey_dd4hep_p1.py +++ b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/hlt2_reco_rich2_noUT_survey_dd4hep_p1.py @@ -8,48 +8,47 @@ # granted to it by virtue of its status as an Intergovernmental Organization # # or submit itself to any jurisdiction. # ############################################################################### -import glob import csv +import glob import math -from GaudiKernel.SystemOfUnits import (GeV, MeV, mm, mrad) +from GaudiKernel.SystemOfUnits import GeV, MeV, mm, mrad from Moore import ( options, run_reconstruction, ) - -from RecoConf.rich_data_monitoring import ( - default_rich_monitoring_options, ) - -from PyConf.Algorithms import (VeloRetinaClusterTrackingSIMD, - PrForwardTrackingVelo, - VPRetinaFullClusterDecoder) +from Panoptes.alignment import ( + standalone_rich_online_align_reco, + standalone_rich_panel_align_reco, +) +from PyConf.Algorithms import ( + PrForwardTrackingVelo, + VeloRetinaClusterTrackingSIMD, + VPRetinaFullClusterDecoder, +) from RecoConf.legacy_rec_hlt1_tracking import ( - make_VeloClusterTrackingSIMD, make_reco_pvs, make_PatPV3DFuture_pvs, - make_velo_full_clusters) - + make_PatPV3DFuture_pvs, + make_reco_pvs, + make_velo_full_clusters, + make_VeloClusterTrackingSIMD, +) from RecoConf.rich_data_monitoring import ( - default_rich_monitoring_options, alignment_rich_monitoring_options, + default_rich_monitoring_options, ) - from RecoConf.rich_reconstruction import default_rich_reco_options -from Panoptes.alignment import ( - standalone_rich_online_align_reco, - standalone_rich_panel_align_reco, -) - # from Configurables import ( # UpdateManagerSvc # ) """Options for running over data with FT raw bank version 6.""" from RecoConf.decoders import ( - default_ft_decoding_version, ) + default_ft_decoding_version, +) whichRich = 2 whichPanel = 1 -survey_type = 'translation' +survey_type = "translation" manual_update = True @@ -62,14 +61,14 @@ options.n_threads = 1 options.scheduler_legacy_mode = False if useRealData is not True: - options.set_input_and_conds_from_testfiledb( - 'upgrade_Sept2022_minbias_0fb_md_xdigi') - options.input_type = 'ROOT' + options.set_input_and_conds_from_testfiledb("upgrade_Sept2022_minbias_0fb_md_xdigi") + options.input_type = "ROOT" else: exec( open( "/eos/user/j/jreich/stack_dd4hep_december/Panoptes/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/data_255358.py" - ).read()) + ).read() + ) options.simulation = False options.input_type = "MDF" @@ -86,44 +85,48 @@ if UseDD4Hep: from Configurables import DDDBConf dd4hep = DD4hepSvc( - DetectorList=["/world", "Magnet", "UT", "VP", "FT", "Rich1", "Rich2"]) + DetectorList=["/world", "Magnet", "UT", "VP", "FT", "Rich1", "Rich2"] + ) dd4hep.OutputLevel = 1 if useRealData: - options.conddb_tag = 'master' # used for real data - options.dddb_tag = 'run3/trunk' - DDDBConf().GeometryVersion = 'run3/trunk' # used for real data + options.conddb_tag = "master" # used for real data + options.dddb_tag = "run3/trunk" + DDDBConf().GeometryVersion = "run3/trunk" # used for real data # latest scifi and velo alignments dd4hep.UseConditionsOverlay = True - dd4hep.ConditionsVersion = 'alignment2022' + dd4hep.ConditionsVersion = "alignment2022" options.simulation = False else: - options.conddb_tag = 'jonrob/all-pmts-active' # used for DetDesc MC samples with DD4Hep - DDDBConf( - ).GeometryVersion = 'run3/before-rich1-geom-update-26052022' # used for DetDesc MC samples with DD4Hep + options.conddb_tag = ( + "jonrob/all-pmts-active" # used for DetDesc MC samples with DD4Hep + ) + DDDBConf().GeometryVersion = "run3/before-rich1-geom-update-26052022" # used for DetDesc MC samples with DD4Hep if manual_update: - conddb_path = '/eos/user/j/jreich/stack_dd4hep_december/Panoptes/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/lhcb-conditions-database' + conddb_path = "/eos/user/j/jreich/stack_dd4hep_december/Panoptes/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/lhcb-conditions-database" dd4hep.ConditionsLocation = "file://" + conddb_path else: - dd4hep.ConditionsLocation = 'git:/cvmfs/lhcb.cern.ch/lib/lhcb/git-conddb/lhcb-conditions-database.git' + dd4hep.ConditionsLocation = ( + "git:/cvmfs/lhcb.cern.ch/lib/lhcb/git-conddb/lhcb-conditions-database.git" + ) else: - options.conddb_tag = 'upgrade/sim-20220612-vc-md100-RICHcustomFTv6' + options.conddb_tag = "upgrade/sim-20220612-vc-md100-RICHcustomFTv6" options.simulation = True -rich = f'rich{whichRich}' -radiator = f'Rich{whichRich}Gas' +rich = f"rich{whichRich}" +radiator = f"Rich{whichRich}Gas" -param_list = ['p0_x', 'p1_x', 'p0_y', 'p1_y', 'p0_z', 'p1_z'] +param_list = ["p0_x", "p1_x", "p0_y", "p1_y", "p0_z", "p1_z"] param_dict = dict.fromkeys(param_list) trans_perf_param_dict = dict.fromkeys(param_list) # Change file name if running elsewhere -file_name = f'rich{whichRich}_{survey_type}_params_p{whichPanel}.csv' -f = open(file_name, 'r') +file_name = f"rich{whichRich}_{survey_type}_params_p{whichPanel}.csv" +f = open(file_name, "r") reader = csv.reader(f) for row, param in zip(reader, param_dict.keys()): param_dict[param] = float(row[0]) @@ -144,39 +147,37 @@ else: # update the conditons if UseDD4Hep: - # dd4hep.DumpConditions = True if manual_update: # "_" here so argparse can interpret it (gets replaced by a space later) - pos_condition = f'position:_[{param_dict["p" + str(whichPanel)+ "_x"]}_*_mm,_{param_dict["p" + str(whichPanel)+ "_y"]}_*_mm,_{param_dict["p" + str(whichPanel)+ "_z"]}_*_mm]' - rot_condition = 'rotation:_[0.0_*_mrad,_0.0_*_mrad,_0.0_*_mrad]' + pos_condition = f"position:_[{param_dict['p' + str(whichPanel) + '_x']}_*_mm,_{param_dict['p' + str(whichPanel) + '_y']}_*_mm,_{param_dict['p' + str(whichPanel) + '_z']}_*_mm]" + rot_condition = "rotation:_[0.0_*_mrad,_0.0_*_mrad,_0.0_*_mrad]" import os + os.system( - f'python manual_cond_update.py --whichRich 1 --whichPanel {whichPanel} --conddb_path {conddb_path}/ --pos_condition {pos_condition} --rot_condition {rot_condition} ' + f"python manual_cond_update.py --whichRich 1 --whichPanel {whichPanel} --conddb_path {conddb_path}/ --pos_condition {pos_condition} --rot_condition {rot_condition} " ) else: condval = "!alignment {position: [0.0 * mm, 0.0 * mm, 0.0 * mm] , rotation: [0.0 * mrad, 0.0 * mrad, 0.0 * mrad]}" - dd4hep.ConditionsOverride.update({ - "/world/BeforeMagnetRegion/Rich1/Rich1PmtPanel1:Panel": - condval - - # "/world/BeforeMagnetRegion/Rich1:Rich1System": - # condval - }) + dd4hep.ConditionsOverride.update( + { + "/world/BeforeMagnetRegion/Rich1/Rich1PmtPanel1:Panel": condval + # "/world/BeforeMagnetRegion/Rich1:Rich1System": + # condval + } + ) else: - cond_update_list = [] for panel_num in panel_nums: - pre_cond_str = f'Conditions/Alignment/Rich1/PDPanel{panel_num}_Align := ' - optimum_trans_cond_str = f'double_v dPosXYZ = {trans_perf_param_dict["p" + str(panel_num)+ "_x"]} {trans_perf_param_dict["p" + str(panel_num)+ "_y"]} {trans_perf_param_dict["p" + str(panel_num)+ "_z"]}; ' + pre_cond_str = f"Conditions/Alignment/Rich1/PDPanel{panel_num}_Align := " + optimum_trans_cond_str = f"double_v dPosXYZ = {trans_perf_param_dict['p' + str(panel_num) + '_x']} {trans_perf_param_dict['p' + str(panel_num) + '_y']} {trans_perf_param_dict['p' + str(panel_num) + '_z']}; " - update_cond = f'double_v {param_key} = {param_dict["p" + str(panel_num)+ "_x"]} {param_dict["p" + str(panel_num)+ "_y"]} {param_dict["p" + str(panel_num)+ "_z"]};' - cond_update_list.append(pre_cond_str + optimum_trans_cond_str + - update_cond) + update_cond = f"double_v {param_key} = {param_dict['p' + str(panel_num) + '_x']} {param_dict['p' + str(panel_num) + '_y']} {param_dict['p' + str(panel_num) + '_z']};" + cond_update_list.append(pre_cond_str + optimum_trans_cond_str + update_cond) UpdateManagerSvc().ConditionsOverride = cond_update_list @@ -200,16 +201,16 @@ default_reco_opts.update(panel_select) if whichRich == 1: tighter_minp = { "TightTrackSelection": { - "MinP": 30. * GeV, + "MinP": 30.0 * GeV, "MinPt": 0.5 * GeV, - "MaxChi2": 2., + "MaxChi2": 2.0, "MaxGhostProb": 0.1, } } if whichRich == 2: tighter_minp = { "TightTrackSelection": { - "MinP": 60. * GeV, + "MinP": 60.0 * GeV, "MinPt": 0.5 * GeV, "MaxChi2": 2.0, "MaxGhostProb": 0.1, @@ -217,14 +218,14 @@ if whichRich == 2: } default_moni_opts.update(tighter_minp) -wider_histo = {'CKResHistoRange': (0.025, 0.005, 0.004)} +wider_histo = {"CKResHistoRange": (0.025, 0.005, 0.004)} default_moni_opts.update(wider_histo) -useUT = {'UseUT': False} +useUT = {"UseUT": False} default_moni_opts.update(useUT) align_tasks = [ - 'Produce', # fill the production set of histograms - 'Monitor', # add various checking histograms + "Produce", # fill the production set of histograms + "Monitor", # add various checking histograms #'Map', # add counters for creation of the HLT1 pre-selection line "map" #'Optimize', # add counters for optimization of the RICH2 mirror combinations subset #'Select', # check filling the rest of RICH2 mirror combinations along with 8 poorest @@ -236,35 +237,36 @@ nkevts = str(math.trunc(options.evt_max / 1000)) # save output file with histograms if UseDD4Hep: - options.histo_file = f'rich{whichRich}_opt_dd4hep_p{whichPanel}.root' + options.histo_file = f"rich{whichRich}_opt_dd4hep_p{whichPanel}.root" else: - options.histo_file = f'rich{whichRich}_opt_p{whichPanel}.root' + options.histo_file = f"rich{whichRich}_opt_p{whichPanel}.root" PrForwardTrackingVelo.global_bind( MinQuality=0.0, DeltaQuality=0.0, - DecisionLDA=-99., + DecisionLDA=-99.0, MinTotalHits=9, - MaxChi2PerDoF=50., - MaxChi2XProjection=60., - MaxChi2PerDoFFinal=28., - MaxChi2Stereo=16., - MaxChi2StereoAdd=16., + MaxChi2PerDoF=50.0, + MaxChi2XProjection=60.0, + MaxChi2PerDoFFinal=28.0, + MaxChi2Stereo=16.0, + MaxChi2StereoAdd=16.0, ) -make_VeloClusterTrackingSIMD.global_bind( - algorithm=VeloRetinaClusterTrackingSIMD) -make_velo_full_clusters.global_bind( - make_full_cluster=VPRetinaFullClusterDecoder) +make_VeloClusterTrackingSIMD.global_bind(algorithm=VeloRetinaClusterTrackingSIMD) +make_velo_full_clusters.global_bind(make_full_cluster=VPRetinaFullClusterDecoder) make_reco_pvs.global_bind(make_pvs_from_velo_tracks=make_PatPV3DFuture_pvs) - -with standalone_rich_online_align_reco.bind(RichGas=radiator, MirrorAlignTasks = align_tasks,\ - noUT=True), \ - alignment_rich_monitoring_options.bind(radiator=radiator, \ - init_override_opts=align_opts), \ - default_ft_decoding_version.bind(value=6), \ - default_rich_reco_options.bind(init_override_opts=default_reco_opts), \ - default_rich_monitoring_options.bind(init_override_opts=default_moni_opts): +with ( + standalone_rich_online_align_reco.bind( + RichGas=radiator, MirrorAlignTasks=align_tasks, noUT=True + ), + alignment_rich_monitoring_options.bind( + radiator=radiator, init_override_opts=align_opts + ), + default_ft_decoding_version.bind(value=6), + default_rich_reco_options.bind(init_override_opts=default_reco_opts), + default_rich_monitoring_options.bind(init_override_opts=default_moni_opts), +): run_reconstruction(options, standalone_rich_online_align_reco) diff --git a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/hlt2_reco_rich2_noUT_survey_dd4hep_survey.py b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/hlt2_reco_rich2_noUT_survey_dd4hep_survey.py index efd4ba014abb77170186fec9e7e5d4dd415b161b..314c5a701334ac53f3509a2d00511fc38f81943f 100644 --- a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/hlt2_reco_rich2_noUT_survey_dd4hep_survey.py +++ b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/hlt2_reco_rich2_noUT_survey_dd4hep_survey.py @@ -8,51 +8,55 @@ # granted to it by virtue of its status as an Intergovernmental Organization # # or submit itself to any jurisdiction. # ############################################################################### -import glob import csv +import glob import math -import sys import random import shutil +import sys -from GaudiKernel.SystemOfUnits import (GeV, MeV, mm, mrad) +from GaudiKernel.SystemOfUnits import GeV, MeV, mm, mrad from Moore import ( options, run_reconstruction, ) - -from PyConf.Algorithms import (PrForwardTrackingVelo, - VPRetinaFullClusterDecoder) -from PyConf.Algorithms import VeloRetinaClusterTrackingSIMD -from PyConf.Algorithms import PrMatchNN, PrHybridSeeding +from Panoptes.alignment import ( + standalone_rich_online_align_reco, + standalone_rich_panel_align_reco, +) +from PyConf.Algorithms import ( + PrForwardTrackingVelo, + PrHybridSeeding, + PrMatchNN, + VeloRetinaClusterTrackingSIMD, + VPRetinaFullClusterDecoder, +) from RecoConf.legacy_rec_hlt1_tracking import ( - make_VeloClusterTrackingSIMD, make_reco_pvs, make_PatPV3DFuture_pvs, - make_velo_full_clusters) - + make_PatPV3DFuture_pvs, + make_reco_pvs, + make_velo_full_clusters, + make_VeloClusterTrackingSIMD, +) from RecoConf.rich_data_monitoring import ( - default_rich_monitoring_options, alignment_rich_monitoring_options, + default_rich_monitoring_options, ) - from RecoConf.rich_reconstruction import default_rich_reco_options -from Panoptes.alignment import ( - standalone_rich_online_align_reco, - standalone_rich_panel_align_reco, -) - # from Configurables import ( # UpdateManagerSvc # ) """Options for running over data with FT raw bank version 6.""" from RecoConf.decoders import ( - default_ft_decoding_version, ) + default_ft_decoding_version, +) # load options from YAML file from ruamel.yaml import YAML + yaml = YAML() -with open('survey_opts.yml') as opts_yml_file: +with open("survey_opts.yml") as opts_yml_file: yml_opts = yaml.load(opts_yml_file) whichRich = yml_opts["whichRich"] @@ -73,15 +77,15 @@ options.scheduler_legacy_mode = False options.use_iosvc = True if useRealData is not True: - options.set_input_and_conds_from_testfiledb( - 'upgrade_Sept2022_minbias_0fb_md_xdigi') - options.input_type = 'ROOT' + options.set_input_and_conds_from_testfiledb("upgrade_Sept2022_minbias_0fb_md_xdigi") + options.input_type = "ROOT" else: if useHltDecisions: exec( open( "/home/jreich/stack_dd4hep_v3/Panoptes/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/MirrorAlignment/data_online.py" - ).read()) + ).read() + ) else: # exec(open("/home/jreich/stack_dd4hep_v3/Panoptes/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/MirrorAlignment/data_online.py").read()) @@ -101,11 +105,12 @@ else: base_dir_files = f"/calib/align/LHCb/Rich{whichRich}" def obtain_files_from_many_runs( - base_dir_files, - start_run, - end_run, - num_files_to_select=2, # this is per run number - seed_value=100): + base_dir_files, + start_run, + end_run, + num_files_to_select=2, # this is per run number + seed_value=100, + ): files = [] for folder_number in range(start_run, end_run + 1): @@ -114,15 +119,14 @@ else: # Check if the folder exists if os.path.exists(folder_path) and os.path.isdir(folder_path): - # List all files in the folder files_in_folder = os.listdir(folder_path) # Select random files from the folder random.seed(seed_value) random_files = random.sample( - files_in_folder, - min(num_files_to_select, len(files_in_folder))) + files_in_folder, min(num_files_to_select, len(files_in_folder)) + ) # Print the selected files for file_name in random_files: @@ -131,7 +135,8 @@ else: return files options.input_files = obtain_files_from_many_runs( - base_dir_files, 299618, 299683) + base_dir_files, 299618, 299683 + ) # base_dir_files, 298656, 300124) # base_dir = "/calib/align/LHCb/Rich/0000255353/" @@ -155,36 +160,40 @@ if UseDD4Hep: useUT_bool = True if useUT_bool: - dd4hep = DD4hepSvc(DetectorList=[ - "/world", "Magnet", "UT", "VP", "FT", "Rich1", "Rich2" - ]) + dd4hep = DD4hepSvc( + DetectorList=["/world", "Magnet", "UT", "VP", "FT", "Rich1", "Rich2"] + ) noUT_bool = False else: dd4hep = DD4hepSvc( - DetectorList=["/world", "Magnet", "VP", "FT", "Rich1", "Rich2"]) + DetectorList=["/world", "Magnet", "VP", "FT", "Rich1", "Rich2"] + ) noUT_bool = True dd4hep.OutputLevel = 1 if useRealData: - options.conddb_tag = 'master' # used for real data - options.dddb_tag = 'run3/trunk' + options.conddb_tag = "master" # used for real data + options.dddb_tag = "run3/trunk" # DDDBConf().GeometryVersion = 'run3/trunk' # used for real data # latest scifi and velo alignments dd4hep.UseConditionsOverlay = True - dd4hep.ConditionsVersion = 'master' + dd4hep.ConditionsVersion = "master" # needed for when reconstruction changed to SuperPixels (change was at run 289434) - DDDBConf().GeometryVersion = 'run3/2024.Q1.2-v00.00' - options.geometry_version = 'run3/2024.Q1.2-v00.00' + DDDBConf().GeometryVersion = "run3/2024.Q1.2-v00.00" + options.geometry_version = "run3/2024.Q1.2-v00.00" else: - options.conddb_tag = 'jonrob/all-pmts-active' # used for DetDesc MC samples with DD4Hep - DDDBConf( - ).GeometryVersion = 'before-rich1-geom-update-26052022' # used for DetDesc MC samples with DD4Hep + options.conddb_tag = ( + "jonrob/all-pmts-active" # used for DetDesc MC samples with DD4Hep + ) + DDDBConf().GeometryVersion = "before-rich1-geom-update-26052022" # used for DetDesc MC samples with DD4Hep if manual_update: - dd4hep.ConditionsVersion = 'master' - dd4hep.ConditionsLocation = 'git:/cvmfs/lhcb.cern.ch/lib/lhcb/git-conddb/lhcb-conditions-database.git' + dd4hep.ConditionsVersion = "master" + dd4hep.ConditionsLocation = ( + "git:/cvmfs/lhcb.cern.ch/lib/lhcb/git-conddb/lhcb-conditions-database.git" + ) # if manual_update: # conddb_path = yml_opts["conddb_path"] @@ -198,19 +207,19 @@ if UseDD4Hep: # dd4hep.ConditionsLocation = 'git:/cvmfs/lhcb.cern.ch/lib/lhcb/git-conddb/lhcb-conditions-database.git' else: - options.conddb_tag = 'upgrade/sim-20220612-vc-md100-RICHcustomFTv6' + options.conddb_tag = "upgrade/sim-20220612-vc-md100-RICHcustomFTv6" options.simulation = True -rich = f'rich{whichRich}' -radiator = f'Rich{whichRich}Gas' +rich = f"rich{whichRich}" +radiator = f"Rich{whichRich}Gas" -param_list = ['p0_x', 'p1_x', 'p0_y', 'p1_y', 'p0_z', 'p1_z'] +param_list = ["p0_x", "p1_x", "p0_y", "p1_y", "p0_z", "p1_z"] param_dict = dict.fromkeys(param_list) trans_perf_param_dict = dict.fromkeys(param_list) # Change file name if running elsewhere -file_name = f'rich{whichRich}_{survey_type}_params_p{whichPanel}.csv' -f = open(file_name, 'r') +file_name = f"rich{whichRich}_{survey_type}_params_p{whichPanel}.csv" +f = open(file_name, "r") reader = csv.reader(f) for row, param in zip(reader, param_dict.keys()): param_dict[param] = float(row[0]) @@ -224,7 +233,7 @@ perf_align = [ yml_opts[f"R{whichRich}"]["P0"]["perf_trans"]["y"], yml_opts[f"R{whichRich}"]["P1"]["perf_trans"]["y"], yml_opts[f"R{whichRich}"]["P0"]["perf_trans"]["z"], - yml_opts[f"R{whichRich}"]["P1"]["perf_trans"]["z"] + yml_opts[f"R{whichRich}"]["P1"]["perf_trans"]["z"], ] for val, param in zip(perf_align, param_dict.keys()): @@ -242,64 +251,64 @@ if UseDD4Hep: # dd4hep.DumpConditions = True if manual_update: - fromFile = f"./this_iter_conditions_R{whichRich}P{whichPanel}.yml" f = open(fromFile, "w") # create yml file for conditions overlay for p in [0, 1]: - - if survey_type == 'translation': + if survey_type == "translation": f.write(f"PDPanel{p}: !alignment\n") if p == int( - whichPanel + whichPanel ): # update conditions for panel you want to survey f.write( - f" position: [{param_dict['p' + str(p)+ '_x']} * mm, {param_dict['p' + str(p)+ '_y']} * mm, {param_dict['p' + str(p)+ '_z']} * mm]\n" +\ - f" rotation: [0.0 * mrad, 0.0 * mrad, 0.0 * mrad]" - ) + f" position: [{param_dict['p' + str(p) + '_x']} * mm, {param_dict['p' + str(p) + '_y']} * mm, {param_dict['p' + str(p) + '_z']} * mm]\n" + + f" rotation: [0.0 * mrad, 0.0 * mrad, 0.0 * mrad]" + ) else: # take optimimum alignment for panel you arent surveying f.write( - f" position: [{trans_perf_param_dict['p' + str(p)+ '_x']} * mm, {trans_perf_param_dict['p' + str(p)+ '_y']} * mm, {trans_perf_param_dict['p' + str(p)+ '_z']} * mm]\n" +\ - f" rotation: [0.0 * mrad, 0.0 * mrad, 0.0 * mrad]" - ) - elif survey_type == 'rotation': + f" position: [{trans_perf_param_dict['p' + str(p) + '_x']} * mm, {trans_perf_param_dict['p' + str(p) + '_y']} * mm, {trans_perf_param_dict['p' + str(p) + '_z']} * mm]\n" + + f" rotation: [0.0 * mrad, 0.0 * mrad, 0.0 * mrad]" + ) + elif survey_type == "rotation": f.write(f"PDPanel{p}: !alignment\n") if p == int( - whichPanel + whichPanel ): # update conditions for panel you want to survey f.write( - f" position: [{trans_perf_param_dict['p' + str(p)+ '_x']} * mm, {trans_perf_param_dict['p' + str(p)+ '_y']} * mm, {trans_perf_param_dict['p' + str(p)+ '_z']} * mm]\n" +\ - f" rotation: [{param_dict['p' + str(p)+ '_x']} * mrad, {param_dict['p' + str(p)+ '_y']} * mrad, {param_dict['p' + str(p)+ '_z']} * mrad]" - ) + f" position: [{trans_perf_param_dict['p' + str(p) + '_x']} * mm, {trans_perf_param_dict['p' + str(p) + '_y']} * mm, {trans_perf_param_dict['p' + str(p) + '_z']} * mm]\n" + + f" rotation: [{param_dict['p' + str(p) + '_x']} * mrad, {param_dict['p' + str(p) + '_y']} * mrad, {param_dict['p' + str(p) + '_z']} * mrad]" + ) else: # take optimimum alignment for panel you arent surveying f.write( - f" position: [{trans_perf_param_dict['p' + str(p)+ '_x']} * mm, {trans_perf_param_dict['p' + str(p)+ '_y']} * mm, {trans_perf_param_dict['p' + str(p)+ '_z']} * mm]\n" +\ - f" rotation: [0.0 * mrad, 0.0 * mrad, 0.0 * mrad]" - ) + f" position: [{trans_perf_param_dict['p' + str(p) + '_x']} * mm, {trans_perf_param_dict['p' + str(p) + '_y']} * mm, {trans_perf_param_dict['p' + str(p) + '_z']} * mm]\n" + + f" rotation: [0.0 * mrad, 0.0 * mrad, 0.0 * mrad]" + ) - if p == 0: # yaml file doesnt get read properly if there is a newline at the end + if ( + p == 0 + ): # yaml file doesnt get read properly if there is a newline at the end f.write("\n") f.close() dd4hep.UseConditionsOverlay = True - dd4hep.ConditionsOverlayInitPath = '/group/rich/sw/alignment/ConditionsOverlayForPanels/' + dd4hep.ConditionsOverlayInitPath = ( + "/group/rich/sw/alignment/ConditionsOverlayForPanels/" + ) toFile = f"/group/rich/sw/alignment/ConditionsOverlayForPanels/Conditions/Rich{whichRich}/Alignment/PDPanels.yml" shutil.copyfile(fromFile, toFile) else: - cond_update_list = [] for panel_num in panel_nums: - pre_cond_str = f'Conditions/Alignment/Rich1/PDPanel{panel_num}_Align := ' - optimum_trans_cond_str = f'double_v dPosXYZ = {trans_perf_param_dict["p" + str(panel_num)+ "_x"]} {trans_perf_param_dict["p" + str(panel_num)+ "_y"]} {trans_perf_param_dict["p" + str(panel_num)+ "_z"]}; ' + pre_cond_str = f"Conditions/Alignment/Rich1/PDPanel{panel_num}_Align := " + optimum_trans_cond_str = f"double_v dPosXYZ = {trans_perf_param_dict['p' + str(panel_num) + '_x']} {trans_perf_param_dict['p' + str(panel_num) + '_y']} {trans_perf_param_dict['p' + str(panel_num) + '_z']}; " - update_cond = f'double_v {param_key} = {param_dict["p" + str(panel_num)+ "_x"]} {param_dict["p" + str(panel_num)+ "_y"]} {param_dict["p" + str(panel_num)+ "_z"]};' - cond_update_list.append(pre_cond_str + optimum_trans_cond_str + - update_cond) + update_cond = f"double_v {param_key} = {param_dict['p' + str(panel_num) + '_x']} {param_dict['p' + str(panel_num) + '_y']} {param_dict['p' + str(panel_num) + '_z']};" + cond_update_list.append(pre_cond_str + optimum_trans_cond_str + update_cond) UpdateManagerSvc().ConditionsOverride = cond_update_list @@ -315,9 +324,7 @@ else: # dd4hep.UseConditionsOverlay = True # dd4hep.ConditionsOverlayInitPath = '/group/online/alignment/prelim_align_2024/07_01_Run3Map_withUT_0207' condval = "!alignment{ position: [0 * mm, 0 * mm, 0 * mm], rotation: [-0.000511080865103135 * rad, -0.00021828767680766154 * rad, -0.000866016317444813 * rad]}" -dd4hep.ConditionsOverride = { - "/world/BeforeMagnetRegion/VP:alignment_delta": condval -} +dd4hep.ConditionsOverride = {"/world/BeforeMagnetRegion/VP:alignment_delta": condval} # ####### 4th July 2024 overlay default_moni_opts = {} @@ -338,17 +345,17 @@ default_reco_opts.update(panel_select) # Monitoring opts if whichRich == 1: - minP = 30. + minP = 30.0 tighter_minp = { "TightTrackSelection": { "MinP": minP * GeV, "MinPt": 0.5 * GeV, - "MaxChi2": 2., + "MaxChi2": 2.0, "MaxGhostProb": 0.1, } } if whichRich == 2: - minP = 60. + minP = 60.0 tighter_minp = { "TightTrackSelection": { "MinP": minP * GeV, @@ -360,64 +367,70 @@ if whichRich == 2: default_moni_opts.update(tighter_minp) # wider_histo = {'CKResHistoRange': (0.025, 0.005, 0.004)} -wider_histo = {'CKResHistoRange': (0.025, 0.0055, 0.0055)} +wider_histo = {"CKResHistoRange": (0.025, 0.0055, 0.0055)} default_moni_opts.update(wider_histo) -useUT = {'UseUT': useUT_bool} +useUT = {"UseUT": useUT_bool} default_moni_opts.update(useUT) nkevts = str(math.trunc(options.evt_max / 1000)) # save output file with histograms if UseDD4Hep: - options.histo_file = f'rich{whichRich}_opt_dd4hep_p{whichPanel}.root' + options.histo_file = f"rich{whichRich}_opt_dd4hep_p{whichPanel}.root" else: - options.histo_file = f'rich{whichRich}_opt_p{whichPanel}.root' + options.histo_file = f"rich{whichRich}_opt_p{whichPanel}.root" PrForwardTrackingVelo.global_bind( MinQuality=0.0, DeltaQuality=0.0, MinTotalHits=9, - MaxChi2PerDoF=50., - MaxChi2XProjection=60., - MaxChi2PerDoFFinal=28., - MaxChi2Stereo=16., - MaxChi2StereoAdd=16., - MinP=minP * GeV) + MaxChi2PerDoF=50.0, + MaxChi2XProjection=60.0, + MaxChi2PerDoFFinal=28.0, + MaxChi2Stereo=16.0, + MaxChi2StereoAdd=16.0, + MinP=minP * GeV, +) PrMatchNN.global_bind(MinP=minP * GeV) PrHybridSeeding.global_bind(MinP=minP * GeV) # commented out when reconstruction changed to SuperPixels (change was at run 289434) -make_VeloClusterTrackingSIMD.global_bind( - algorithm=VeloRetinaClusterTrackingSIMD) -make_velo_full_clusters.global_bind( - make_full_cluster=VPRetinaFullClusterDecoder) +make_VeloClusterTrackingSIMD.global_bind(algorithm=VeloRetinaClusterTrackingSIMD) +make_velo_full_clusters.global_bind(make_full_cluster=VPRetinaFullClusterDecoder) make_reco_pvs.global_bind(make_pvs_from_velo_tracks=make_PatPV3DFuture_pvs) -from Configurables import LHCb__UnpackRawEvent, HltDecReportsDecoder, HltSelReportsDecoder, ApplicationMgr +from Configurables import ( + ApplicationMgr, + HltDecReportsDecoder, + HltSelReportsDecoder, + LHCb__UnpackRawEvent, +) from PyConf.application import configured_ann_svc + unpacker = LHCb__UnpackRawEvent( "UnpackRawEvent", OutputLevel=2, - RawBankLocations=[ - "DAQ/RawBanks/HltDecReports", "DAQ/RawBanks/HltSelReports" - ], - BankTypes=["HltDecReports", "HltSelReports"]) + RawBankLocations=["DAQ/RawBanks/HltDecReports", "DAQ/RawBanks/HltSelReports"], + BankTypes=["HltDecReports", "HltSelReports"], +) decDec = HltDecReportsDecoder( "HltDecReportsDecoder/Hlt1DecReportsDecoder", SourceID="Hlt1", - RawBanks=unpacker.RawBankLocations[0]) + RawBanks=unpacker.RawBankLocations[0], +) selDec = HltSelReportsDecoder( "HltSelReportsDecoder/Hlt1SelReportsDecoder", SourceID="Hlt1", DecReports=unpacker.RawBankLocations[0], - RawBanks=unpacker.RawBankLocations[1]) + RawBanks=unpacker.RawBankLocations[1], +) app = ApplicationMgr( - TopAlg=[unpacker, decDec, selDec], - ExtSvc=[configured_ann_svc(name='HltANNSvc')]) + TopAlg=[unpacker, decDec, selDec], ExtSvc=[configured_ann_svc(name="HltANNSvc")] +) # by default, no additional filtering of the events event_filter = [] @@ -425,29 +438,34 @@ event_filter = [] # Prepare filter import Functors from PyConf.Algorithms import ( - VoidFilter, HltDecReportsDecoder as PyConf_Algorithms_HltDecReportsDecoder, ) +from PyConf.Algorithms import ( + VoidFilter, +) from PyConf.application import ( default_raw_banks, default_raw_event, ) -lines = (['Hlt1RICH1AlignmentDecision'] - if whichRich == 1 else ['Hlt1RICH2AlignmentDecision']) +lines = ( + ["Hlt1RICH1AlignmentDecision"] if whichRich == 1 else ["Hlt1RICH2AlignmentDecision"] +) with default_raw_event.bind(raw_event_format=0.5): hlt1_dec_reports = PyConf_Algorithms_HltDecReportsDecoder( - RawBanks=default_raw_banks("HltDecReports"), SourceID='Hlt1') + RawBanks=default_raw_banks("HltDecReports"), SourceID="Hlt1" + ) hlt1_filter = VoidFilter( - name='Streaming_filter', + name="Streaming_filter", Cut=Functors.DECREPORTS_FILTER( - Lines=lines, - DecReports=hlt1_dec_reports.OutputHltDecReportsLocation)) + Lines=lines, DecReports=hlt1_dec_reports.OutputHltDecReportsLocation + ), + ) # when particular decision of HLT1 line about RICH1 or RICH2 is wanted -#if 'subset' not in current_variant: +# if 'subset' not in current_variant: if useHltDecisions: # prepare filter for selecting events # chosen for alignment of mirrors of particular RICH @@ -466,13 +484,17 @@ if useHltDecisions: sys.stdout.flush() - -with standalone_rich_panel_align_reco.bind(RichGas=radiator,\ - EventFilter=event_filter if useHltDecisions else [],\ - noUT=noUT_bool), \ - alignment_rich_monitoring_options.bind(radiator=radiator, \ - init_override_opts=align_opts), \ - default_ft_decoding_version.bind(value=6), \ - default_rich_reco_options.bind(init_override_opts=default_reco_opts), \ - default_rich_monitoring_options.bind(init_override_opts=default_moni_opts): +with ( + standalone_rich_panel_align_reco.bind( + RichGas=radiator, + EventFilter=event_filter if useHltDecisions else [], + noUT=noUT_bool, + ), + alignment_rich_monitoring_options.bind( + radiator=radiator, init_override_opts=align_opts + ), + default_ft_decoding_version.bind(value=6), + default_rich_reco_options.bind(init_override_opts=default_reco_opts), + default_rich_monitoring_options.bind(init_override_opts=default_moni_opts), +): run_reconstruction(options, standalone_rich_panel_align_reco) diff --git a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/manual_cond_update.py b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/manual_cond_update.py index a930c17a5876f72fc4e1b090b7cc9462f77a3fe7..0ef85b0531e742562cb32e246bf8fb764e6a1634 100755 --- a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/manual_cond_update.py +++ b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/manual_cond_update.py @@ -14,29 +14,28 @@ parser = argparse.ArgumentParser() parser.add_argument( "--whichRich", - default='both', + default="both", type=str, - help="Set to both for both. Set to 1 for RICH1. Set to 2 for RICH2)") + help="Set to both for both. Set to 1 for RICH1. Set to 2 for RICH2)", +) parser.add_argument( "--whichPanel", - default='both', + default="both", type=str, - help="Set to both for both. Set to 0 for Panel0. Set to 1 for Panel1)") + help="Set to both for both. Set to 0 for Panel0. Set to 1 for Panel1)", +) parser.add_argument( "--conddb_path", - default='', + default="", type=str, - help="Directory of local copy of conditions database") + help="Directory of local copy of conditions database", +) parser.add_argument( - "--pos_condition", - default='', - type=str, - help="Position condition to update") + "--pos_condition", default="", type=str, help="Position condition to update" +) parser.add_argument( - "--rot_condition", - default='', - type=str, - help="Rotation condition to update") + "--rot_condition", default="", type=str, help="Rotation condition to update" +) args = parser.parse_args() @@ -47,7 +46,7 @@ pos_condition = (args.pos_condition).replace("_", " ") rot_condition = (args.rot_condition).replace("_", " ") # filename = f'{conddb_path}Conditions/Rich{whichRich}/Alignment/PDPanels.yml/255000' -filename = f'{conddb_path}Conditions/Rich{whichRich}/Alignment/PDPanels.yml/0' +filename = f"{conddb_path}Conditions/Rich{whichRich}/Alignment/PDPanels.yml/0" new_file = "" @@ -55,10 +54,9 @@ import threading lock = threading.Lock() lock.acquire() -with open(filename, 'r') as f: +with open(filename, "r") as f: panel_num = None for line in f: - newline = line if "Panel0" in line: diff --git a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/old_scripts/hlt2_reco_rich1_noUT_moore_survey.py b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/old_scripts/hlt2_reco_rich1_noUT_moore_survey.py index 76551e7f433630488c290230303a75b891c1a8b4..d0c491c5b3baee201934507ed3ff84dc22a25eca 100644 --- a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/old_scripts/hlt2_reco_rich1_noUT_moore_survey.py +++ b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/old_scripts/hlt2_reco_rich1_noUT_moore_survey.py @@ -8,62 +8,69 @@ # granted to it by virtue of its status as an Intergovernmental Organization # # or submit itself to any jurisdiction. # ############################################################################### -import glob import csv +import glob import math +from Configurables import CondDB, UpdateManagerSvc from GaudiKernel.SystemOfUnits import ( - GeV, ) + GeV, +) from Moore import ( options, run_reconstruction, ) +from PyConf.tonic import configurable from RecoConf.rich_add_reconstruction_monitoring_checking import ( - add_hlt2_rich, ) + add_hlt2_rich, +) from RecoConf.rich_data_monitoring import ( - default_rich_monitoring_options, alignment_rich_monitoring_options, + default_rich_monitoring_options, ) - from RecoConf.rich_reconstruction import default_rich_reco_options - from RecoConf.standalone import ( - standalone_hlt2_light_reco_without_UT, ) -from PyConf.tonic import configurable -from Configurables import (CondDB, UpdateManagerSvc) + standalone_hlt2_light_reco_without_UT, +) + """Options for running over data with FT raw bank version 6.""" from RecoConf.decoders import ( - default_ft_decoding_version, ) - + default_ft_decoding_version, +) from RecoConf.hlt2_tracking import ( - make_hlt2_tracks_without_UT, ) + make_hlt2_tracks_without_UT, +) options.n_threads = 5 options.evt_max = 10000 -options.input_files = sorted([ - 'mdf:root://eoslhcb.cern.ch/%s' % f for f in glob.glob( - r'/eos/lhcb/grid/prod/lhcb/MC/Upgrade/MDF/00146082/000*/00146082_*') -]) -options.input_type = 'MDF' -options.dddb_tag = 'upgrade/dddb-20220612' -options.conddb_tag = 'upgrade/sim-20220612-vc-md100-RICHcustomFTv6' +options.input_files = sorted( + [ + "mdf:root://eoslhcb.cern.ch/%s" % f + for f in glob.glob( + r"/eos/lhcb/grid/prod/lhcb/MC/Upgrade/MDF/00146082/000*/00146082_*" + ) + ] +) +options.input_type = "MDF" +options.dddb_tag = "upgrade/dddb-20220612" +options.conddb_tag = "upgrade/sim-20220612-vc-md100-RICHcustomFTv6" -rich = 'rich1' +rich = "rich1" radiator = "Rich1Gas" track_types = [ - 'Long', + "Long", #'Upstream', #'Downstream', ] -param_list = ['p0_x', 'p1_x', 'p0_y', 'p1_y', 'p0_z', 'p1_z'] +param_list = ["p0_x", "p1_x", "p0_y", "p1_y", "p0_z", "p1_z"] param_dict = dict.fromkeys(param_list) # Change file name if running elsewhere -file_name = '/afs/cern.ch/work/j/jreich/stack/Panoptes/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/rich1_params.csv' -f = open(file_name, 'r') +file_name = "/afs/cern.ch/work/j/jreich/stack/Panoptes/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/rich1_params.csv" +f = open(file_name, "r") reader = csv.reader(f) for row, param in zip(reader, param_dict.keys()): param_dict[param] = float(row[0]) @@ -79,7 +86,7 @@ default_level2_opts = {} default_reco_opts = {} # Reco opts -wider_bkg = {"PhotonSelection": 'None'} +wider_bkg = {"PhotonSelection": "None"} default_reco_opts.update(wider_bkg) panel_select = {"ActivatePanel": (True, True)} default_reco_opts.update(panel_select) @@ -87,19 +94,19 @@ default_reco_opts.update(panel_select) # Monitoring opts tighter_minp = { "TightTrackSelection": { - "MinP": 30. * GeV, + "MinP": 30.0 * GeV, "MinPt": 0.5 * GeV, - "MaxChi2": 2., + "MaxChi2": 2.0, "MaxGhostProb": 0.1, } } default_opts.update(tighter_minp) -wider_histo = {'CKResHistoRange': (0.025, 0.008, 0.004)} +wider_histo = {"CKResHistoRange": (0.025, 0.008, 0.004)} default_level2_opts.update(wider_histo) align_tasks = [ - 'Produce', # fill the production set of histograms - 'Monitor', # add various checking histograms + "Produce", # fill the production set of histograms + "Monitor", # add various checking histograms #'Map', # add counters for creation of the HLT1 pre-selection line "map" #'Optimize', # add counters for optimization of the RICH2 mirror combinations subset #'Select', # check filling the rest of RICH2 mirror combinations along with 8 poorest @@ -112,17 +119,23 @@ task = align_tasks[0] nkevts = str(math.trunc(options.evt_max / 1000)) # save output file with histograms -options.histo_file = 'rich1_opt.root' +options.histo_file = "rich1_opt.root" moni_set = "PhotonCherenkovAngles" -with add_hlt2_rich.bind( +with ( + add_hlt2_rich.bind( do_data_monitoring_rich=True, moni_set=moni_set, radiator=radiator, mirror_align_tasks=align_tasks, - track_types=track_types), \ - default_ft_decoding_version.bind(value=6), \ - default_rich_reco_options.bind(default_rich_reco_opts_modify=default_reco_opts), \ - default_rich_monitoring_options.bind(default_rich_moni_opts_modify=default_opts,default_rich_moni_opts_modify_level2=default_level2_opts): + track_types=track_types, + ), + default_ft_decoding_version.bind(value=6), + default_rich_reco_options.bind(default_rich_reco_opts_modify=default_reco_opts), + default_rich_monitoring_options.bind( + default_rich_moni_opts_modify=default_opts, + default_rich_moni_opts_modify_level2=default_level2_opts, + ), +): run_reconstruction(options, standalone_hlt2_light_reco_without_UT) diff --git a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/old_scripts/hlt2_reco_rich1_noUT_panoptes_survey.py b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/old_scripts/hlt2_reco_rich1_noUT_panoptes_survey.py index edbb78c36dbf098a87f758ffc5f050c071b6deb5..16f1ce86eda5d644d28834c4fbaf87a12adb7af7 100644 --- a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/old_scripts/hlt2_reco_rich1_noUT_panoptes_survey.py +++ b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/old_scripts/hlt2_reco_rich1_noUT_panoptes_survey.py @@ -8,46 +8,50 @@ # granted to it by virtue of its status as an Intergovernmental Organization # # or submit itself to any jurisdiction. # ############################################################################### -import glob import csv +import glob import math +from Configurables import UpdateManagerSvc from GaudiKernel.SystemOfUnits import ( - GeV, ) + GeV, +) from Moore import ( options, run_reconstruction, ) - +from Panoptes.alignment import standalone_rich_panel_align_reco from RecoConf.rich_data_monitoring import ( - default_rich_monitoring_options, ) - + default_rich_monitoring_options, +) from RecoConf.rich_reconstruction import default_rich_reco_options -from Panoptes.alignment import (standalone_rich_panel_align_reco) - -from Configurables import (UpdateManagerSvc) """Options for running over data with FT raw bank version 6.""" from RecoConf.decoders import ( - default_ft_decoding_version, ) + default_ft_decoding_version, +) options.n_threads = 10 options.evt_max = 10000 -options.input_type = 'MDF' -options.dddb_tag = 'upgrade/dddb-20220612' -options.conddb_tag = 'upgrade/sim-20220612-vc-md100-RICHcustomFTv6' -options.input_files = sorted([ - 'mdf:root://eoslhcb.cern.ch/%s' % f for f in glob.glob( - r'/eos/lhcb/grid/prod/lhcb/MC/Upgrade/MDF/00146082/000*/00146082_*') -]) +options.input_type = "MDF" +options.dddb_tag = "upgrade/dddb-20220612" +options.conddb_tag = "upgrade/sim-20220612-vc-md100-RICHcustomFTv6" +options.input_files = sorted( + [ + "mdf:root://eoslhcb.cern.ch/%s" % f + for f in glob.glob( + r"/eos/lhcb/grid/prod/lhcb/MC/Upgrade/MDF/00146082/000*/00146082_*" + ) + ] +) survey_type = "translation" # options: translation, rotation whichPanel = 1 # options: 0, 1, "both" -rich = 'rich1' +rich = "rich1" radiator = "Rich1Gas" -param_list = ['p0_x', 'p1_x', 'p0_y', 'p1_y', 'p0_z', 'p1_z'] +param_list = ["p0_x", "p1_x", "p0_y", "p1_y", "p0_z", "p1_z"] param_dict = dict.fromkeys(param_list) trans_perf_param_dict = dict.fromkeys(param_list) @@ -59,8 +63,8 @@ elif survey_type == "rotation": conversion_factor = 0.001 # in rad (need to convert to mrad) # Change file name if running elsewhere -file_name = f'/afs/cern.ch/work/j/jreich/stack/Panoptes/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/rich1_{survey_type}_params.csv' -f = open(file_name, 'r') +file_name = f"/afs/cern.ch/work/j/jreich/stack/Panoptes/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/rich1_{survey_type}_params.csv" +f = open(file_name, "r") reader = csv.reader(f) for row, param in zip(reader, param_dict.keys()): param_dict[param] = float(row[0]) * conversion_factor @@ -81,12 +85,11 @@ else: cond_update_list = [] for panel_num in panel_nums: - pre_cond_str = f'Conditions/Alignment/Rich1/PDPanel{panel_num}_Align := ' - optimum_trans_cond_str = f'double_v dPosXYZ = {trans_perf_param_dict["p" + str(panel_num)+ "_x"]} {trans_perf_param_dict["p" + str(panel_num)+ "_y"]} {trans_perf_param_dict["p" + str(panel_num)+ "_z"]}; ' + pre_cond_str = f"Conditions/Alignment/Rich1/PDPanel{panel_num}_Align := " + optimum_trans_cond_str = f"double_v dPosXYZ = {trans_perf_param_dict['p' + str(panel_num) + '_x']} {trans_perf_param_dict['p' + str(panel_num) + '_y']} {trans_perf_param_dict['p' + str(panel_num) + '_z']}; " - update_cond = f'double_v {param_key} = {param_dict["p" + str(panel_num)+ "_x"]} {param_dict["p" + str(panel_num)+ "_y"]} {param_dict["p" + str(panel_num)+ "_z"]};' - cond_update_list.append(pre_cond_str + optimum_trans_cond_str + - update_cond) + update_cond = f"double_v {param_key} = {param_dict['p' + str(panel_num) + '_x']} {param_dict['p' + str(panel_num) + '_y']} {param_dict['p' + str(panel_num) + '_z']};" + cond_update_list.append(pre_cond_str + optimum_trans_cond_str + update_cond) UpdateManagerSvc().ConditionsOverride = cond_update_list @@ -110,20 +113,20 @@ default_reco_opts.update(panel_select) # Monitoring opts tighter_minp = { "TightTrackSelection": { - "MinP": 30. * GeV, + "MinP": 30.0 * GeV, "MinPt": 0.5 * GeV, - "MaxChi2": 2., + "MaxChi2": 2.0, "MaxGhostProb": 0.1, } } default_opts.update(tighter_minp) -wider_histo = {'CKResHistoRange': (0.025, 0.008, 0.004)} +wider_histo = {"CKResHistoRange": (0.025, 0.008, 0.004)} default_level2_opts.update(wider_histo) align_tasks = [ - 'Produce', # fill the production set of histograms - 'Monitor', # add various checking histograms + "Produce", # fill the production set of histograms + "Monitor", # add various checking histograms #'Map', # add counters for creation of the HLT1 pre-selection line "map" #'Optimize', # add counters for optimization of the RICH2 mirror combinations subset #'Select', # check filling the rest of RICH2 mirror combinations along with 8 poorest @@ -134,12 +137,16 @@ align_tasks = [ nkevts = str(math.trunc(options.evt_max / 1000)) # save output file with histograms -options.histo_file = 'rich1_opt.root' - - -with standalone_rich_panel_align_reco.bind(RichGas=radiator, \ - noUT=True), \ - default_ft_decoding_version.bind(value=6), \ - default_rich_reco_options.bind(default_rich_reco_opts_modify=default_reco_opts), \ - default_rich_monitoring_options.bind(default_rich_moni_opts_modify=default_opts,default_rich_moni_opts_modify_level2=default_level2_opts): +options.histo_file = "rich1_opt.root" + + +with ( + standalone_rich_panel_align_reco.bind(RichGas=radiator, noUT=True), + default_ft_decoding_version.bind(value=6), + default_rich_reco_options.bind(default_rich_reco_opts_modify=default_reco_opts), + default_rich_monitoring_options.bind( + default_rich_moni_opts_modify=default_opts, + default_rich_moni_opts_modify_level2=default_level2_opts, + ), +): run_reconstruction(options, standalone_rich_panel_align_reco) diff --git a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/old_scripts/hlt2_reco_rich1_opt.py b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/old_scripts/hlt2_reco_rich1_opt.py index dacee3e0c7803ccff2a7e084ceb36ea99960ea02..3043179907739f3fe43b136f2b85694cba698525 100644 --- a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/old_scripts/hlt2_reco_rich1_opt.py +++ b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/old_scripts/hlt2_reco_rich1_opt.py @@ -8,63 +8,70 @@ # granted to it by virtue of its status as an Intergovernmental Organization # # or submit itself to any jurisdiction. # ############################################################################### -import glob import csv +import glob import math +from Configurables import CondDB, UpdateManagerSvc from GaudiKernel.SystemOfUnits import ( - GeV, ) + GeV, +) from Moore import ( options, run_reconstruction, ) +from PyConf.tonic import configurable from RecoConf.rich_add_reconstruction_monitoring_checking import ( - add_hlt2_rich, ) + add_hlt2_rich, +) from RecoConf.rich_data_monitoring import ( - default_rich_monitoring_options, alignment_rich_monitoring_options, + default_rich_monitoring_options, ) - from RecoConf.rich_reconstruction import default_rich_reco_options - from RecoConf.standalone import ( - standalone_hlt2_light_reco_without_UT, ) -from PyConf.tonic import configurable -from Configurables import (CondDB, UpdateManagerSvc) + standalone_hlt2_light_reco_without_UT, +) + """Options for running over data with FT raw bank version 6.""" from RecoConf.decoders import ( - default_ft_decoding_version, ) - + default_ft_decoding_version, +) from RecoConf.hlt2_tracking import ( - make_hlt2_tracks_without_UT, ) + make_hlt2_tracks_without_UT, +) options.n_threads = 10 options.evt_max = 10000 -options.input_files = sorted([ - 'mdf:root://eoslhcb.cern.ch/%s' % f for f in glob.glob( - r'/eos/lhcb/grid/prod/lhcb/MC/Upgrade/MDF/00146082/000*/00146082_*') -]) -options.input_type = 'MDF' -options.dddb_tag = 'upgrade/bmalecki-rich-alignmentParameters' -options.conddb_tag = 'upgrade/bmalecki-rich-alignmentParameters' +options.input_files = sorted( + [ + "mdf:root://eoslhcb.cern.ch/%s" % f + for f in glob.glob( + r"/eos/lhcb/grid/prod/lhcb/MC/Upgrade/MDF/00146082/000*/00146082_*" + ) + ] +) +options.input_type = "MDF" +options.dddb_tag = "upgrade/bmalecki-rich-alignmentParameters" +options.conddb_tag = "upgrade/bmalecki-rich-alignmentParameters" -rich = 'rich1' +rich = "rich1" radiator = "Rich1Gas" track_types = [ - 'Long', + "Long", #'Upstream', #'Downstream', ] # Import alignment parameters from csv file and apply -param_list = ['p0_x', 'p1_x', 'p0_y', 'p1_y', 'p0_z', 'p1_z'] +param_list = ["p0_x", "p1_x", "p0_y", "p1_y", "p0_z", "p1_z"] param_dict = dict.fromkeys(param_list) # Change file name if running elsewhere -file_name = '/afs/cern.ch/work/j/jamey/public/rich_align/rich_align_upgrade/optimisation/rich1_params.csv' -f = open(file_name, 'r') +file_name = "/afs/cern.ch/work/j/jamey/public/rich_align/rich_align_upgrade/optimisation/rich1_params.csv" +f = open(file_name, "r") reader = csv.reader(f) for row, param in zip(reader, param_dict.keys()): param_dict[param] = float(row[0]) @@ -79,7 +86,7 @@ default_opts = {} default_reco_opts = {} # Reco opts -wider_bkg = {"PhotonSelection": 'None'} +wider_bkg = {"PhotonSelection": "None"} default_reco_opts.update(wider_bkg) panel_select = {"ActivatePanel": (True, True)} default_reco_opts.update(panel_select) @@ -87,19 +94,19 @@ default_reco_opts.update(panel_select) # Monitoring opts tighter_minp = { "TightTrackSelection": { - "MinP": 30. * GeV, + "MinP": 30.0 * GeV, "MinPt": 0.5 * GeV, - "MaxChi2": 2., + "MaxChi2": 2.0, "MaxGhostProb": 0.1, } } default_opts.update(tighter_minp) -wider_histo = {'CKResHistoRange': (0.025, 0.008, 0.004)} +wider_histo = {"CKResHistoRange": (0.025, 0.008, 0.004)} default_opts.update(wider_histo) align_tasks = [ - 'Produce', # fill the production set of histograms - 'Monitor', # add various checking histograms + "Produce", # fill the production set of histograms + "Monitor", # add various checking histograms #'Map', # add counters for creation of the HLT1 pre-selection line "map" #'Optimize', # add counters for optimization of the RICH2 mirror combinations subset #'Select', # check filling the rest of RICH2 mirror combinations along with 8 poorest @@ -112,18 +119,25 @@ task = align_tasks[0] nkevts = str(math.trunc(options.evt_max / 1000)) # save output file with histograms -options.histo_file = 'rich1_opt.root' +options.histo_file = "rich1_opt.root" moni_set = "PhotonCherenkovAngles" -with add_hlt2_rich.bind( +with ( + add_hlt2_rich.bind( do_data_monitoring_rich=True, moni_set=moni_set, radiator=radiator, align_tasks=align_tasks, - track_types=track_types), \ - default_ft_decoding_version.bind(value=6), \ - make_hlt2_tracks_without_UT.bind(use_pr_kf=True, light_reco=True, fast_reco=True), \ - default_rich_reco_options.bind(default_rich_reco_opts_level2_modify=default_reco_opts), \ - default_rich_monitoring_options.bind(default_rich_moni_opts_level2_modify=default_opts): + track_types=track_types, + ), + default_ft_decoding_version.bind(value=6), + make_hlt2_tracks_without_UT.bind(use_pr_kf=True, light_reco=True, fast_reco=True), + default_rich_reco_options.bind( + default_rich_reco_opts_level2_modify=default_reco_opts + ), + default_rich_monitoring_options.bind( + default_rich_moni_opts_level2_modify=default_opts + ), +): run_reconstruction(options, standalone_hlt2_light_reco_without_UT) diff --git a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/old_scripts/hlt2_reco_rich2_noUT_moore_survey.py b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/old_scripts/hlt2_reco_rich2_noUT_moore_survey.py index c3e7a0a5cc37a26507c3f905449578cc9a12a514..a923373d0ef379d4d24d7353edd1fba6604f82ac 100644 --- a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/old_scripts/hlt2_reco_rich2_noUT_moore_survey.py +++ b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/old_scripts/hlt2_reco_rich2_noUT_moore_survey.py @@ -8,65 +8,71 @@ # granted to it by virtue of its status as an Intergovernmental Organization # # or submit itself to any jurisdiction. # ############################################################################### -import glob import csv +import glob import math +from Configurables import CondDB, UpdateManagerSvc from GaudiKernel.SystemOfUnits import ( - GeV, ) + GeV, +) from Moore import ( options, run_reconstruction, ) +from PyConf.tonic import configurable from RecoConf.rich_add_reconstruction_monitoring_checking import ( - add_hlt2_rich, ) + add_hlt2_rich, +) from RecoConf.rich_data_monitoring import ( - default_rich_monitoring_options, alignment_rich_monitoring_options, + default_rich_monitoring_options, ) - from RecoConf.rich_reconstruction import default_rich_reco_options - from RecoConf.standalone import ( - standalone_hlt2_light_reco_without_UT, ) -from PyConf.tonic import configurable -from Configurables import (CondDB, UpdateManagerSvc) + standalone_hlt2_light_reco_without_UT, +) + """Options for running over data with FT raw bank version 6.""" from RecoConf.decoders import ( - default_ft_decoding_version, ) - -from RecoConf.hlt2_tracking import (make_hlt2_tracks_without_UT) + default_ft_decoding_version, +) +from RecoConf.hlt2_tracking import make_hlt2_tracks_without_UT options.n_threads = 5 options.evt_max = 10000 -options.input_files = sorted([ - 'mdf:root://eoslhcb.cern.ch/%s' % f for f in glob.glob( - r'/eos/lhcb/grid/prod/lhcb/MC/Upgrade/MDF/00146082/000*/00146082_*') -]) -options.input_type = 'MDF' +options.input_files = sorted( + [ + "mdf:root://eoslhcb.cern.ch/%s" % f + for f in glob.glob( + r"/eos/lhcb/grid/prod/lhcb/MC/Upgrade/MDF/00146082/000*/00146082_*" + ) + ] +) +options.input_type = "MDF" # options.dddb_tag = 'dddb-20220612' # options.conddb_tag = 'sim-20220612-vc-md100' -options.dddb_tag = 'upgrade/dddb-20220612' -options.conddb_tag = 'upgrade/sim-20220612-vc-md100-RICHcustomFTv6' +options.dddb_tag = "upgrade/dddb-20220612" +options.conddb_tag = "upgrade/sim-20220612-vc-md100-RICHcustomFTv6" -rich = 'rich2' +rich = "rich2" radiator = "Rich2Gas" track_types = [ - 'Long', + "Long", #'Upstream', #'Downstream', ] # Only edit bad_align to play with alignment parameters -param_list = ['p0_x', 'p1_x', 'p0_y', 'p1_y', 'p0_z', 'p1_z'] +param_list = ["p0_x", "p1_x", "p0_y", "p1_y", "p0_z", "p1_z"] param_dict = dict.fromkeys(param_list) # Change file name if running elsewhere -file_name = '/afs/cern.ch/work/j/jreich/stack/Panoptes/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/rich2_params.csv' -f = open(file_name, 'r') +file_name = "/afs/cern.ch/work/j/jreich/stack/Panoptes/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/rich2_params.csv" +f = open(file_name, "r") reader = csv.reader(f) for row, param in zip(reader, param_dict.keys()): param_dict[param] = float(row[0]) @@ -90,20 +96,20 @@ default_reco_opts.update(panel_select) # Monitoring opts tighter_minp = { "TightTrackSelection": { - "MinP": 60. * GeV, + "MinP": 60.0 * GeV, "MinPt": 0.5 * GeV, - "MaxChi2": 2., + "MaxChi2": 2.0, "MaxGhostProb": 0.1, } } default_opts.update(tighter_minp) -wider_histo = {'CKResHistoRange': (0.025, 0.008, 0.012)} +wider_histo = {"CKResHistoRange": (0.025, 0.008, 0.012)} default_level2_opts.update(wider_histo) align_tasks = [ - 'Produce', # fill the production set of histograms - 'Monitor', # add various checking histograms + "Produce", # fill the production set of histograms + "Monitor", # add various checking histograms #'Map', # add counters for creation of the HLT1 pre-selection line "map" #'Optimize', # add counters for optimization of the RICH2 mirror combinations subset #'Select', # check filling the rest of RICH2 mirror combinations along with 8 poorest @@ -116,19 +122,25 @@ task = align_tasks[0] nkevts = str(math.trunc(options.evt_max / 1000)) # save output file with histograms -options.histo_file = 'rich2_opt.root' +options.histo_file = "rich2_opt.root" moni_set = "PhotonCherenkovAngles" -with add_hlt2_rich.bind( +with ( + add_hlt2_rich.bind( do_data_monitoring_rich=True, moni_set=moni_set, radiator=radiator, mirror_align_tasks=align_tasks, - track_types=track_types), \ - default_ft_decoding_version.bind(value=6), \ - default_rich_reco_options.bind(default_rich_reco_opts_modify=default_reco_opts), \ - default_rich_monitoring_options.bind(default_rich_moni_opts_modify=default_opts,default_rich_moni_opts_modify_level2=default_level2_opts): + track_types=track_types, + ), + default_ft_decoding_version.bind(value=6), + default_rich_reco_options.bind(default_rich_reco_opts_modify=default_reco_opts), + default_rich_monitoring_options.bind( + default_rich_moni_opts_modify=default_opts, + default_rich_moni_opts_modify_level2=default_level2_opts, + ), +): run_reconstruction(options, standalone_hlt2_light_reco_without_UT) # old -> make_hlt2_tracks_without_UT.bind(use_pr_kf=True, light_reco=True, fast_reco=True), \ diff --git a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/old_scripts/hlt2_reco_rich2_noUT_panoptes_survey.py b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/old_scripts/hlt2_reco_rich2_noUT_panoptes_survey.py index e1793b8a2249ac1c5836e76f2408d856ea063f13..94dc35fabb71dde0d7a823940a292a0481cca99d 100644 --- a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/old_scripts/hlt2_reco_rich2_noUT_panoptes_survey.py +++ b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/old_scripts/hlt2_reco_rich2_noUT_panoptes_survey.py @@ -8,46 +8,50 @@ # granted to it by virtue of its status as an Intergovernmental Organization # # or submit itself to any jurisdiction. # ############################################################################### -import glob import csv +import glob import math +from Configurables import UpdateManagerSvc from GaudiKernel.SystemOfUnits import ( - GeV, ) + GeV, +) from Moore import ( options, run_reconstruction, ) - +from Panoptes.alignment import standalone_rich_panel_align_reco from RecoConf.rich_data_monitoring import ( - default_rich_monitoring_options, ) - + default_rich_monitoring_options, +) from RecoConf.rich_reconstruction import default_rich_reco_options -from Panoptes.alignment import (standalone_rich_panel_align_reco) - -from Configurables import (UpdateManagerSvc) """Options for running over data with FT raw bank version 6.""" from RecoConf.decoders import ( - default_ft_decoding_version, ) + default_ft_decoding_version, +) options.n_threads = 10 options.evt_max = 10000 -options.input_type = 'MDF' -options.dddb_tag = 'upgrade/dddb-20220612' -options.conddb_tag = 'upgrade/sim-20220612-vc-md100-RICHcustomFTv6' -options.input_files = sorted([ - 'mdf:root://eoslhcb.cern.ch/%s' % f for f in glob.glob( - r'/eos/lhcb/grid/prod/lhcb/MC/Upgrade/MDF/00146082/000*/00146082_*') -]) +options.input_type = "MDF" +options.dddb_tag = "upgrade/dddb-20220612" +options.conddb_tag = "upgrade/sim-20220612-vc-md100-RICHcustomFTv6" +options.input_files = sorted( + [ + "mdf:root://eoslhcb.cern.ch/%s" % f + for f in glob.glob( + r"/eos/lhcb/grid/prod/lhcb/MC/Upgrade/MDF/00146082/000*/00146082_*" + ) + ] +) survey_type = "translation" # options: translation, rotation whichPanel = 0 # options: 0, 1, "both" -rich = 'rich2' +rich = "rich2" radiator = "Rich2Gas" -param_list = ['p0_x', 'p1_x', 'p0_y', 'p1_y', 'p0_z', 'p1_z'] +param_list = ["p0_x", "p1_x", "p0_y", "p1_y", "p0_z", "p1_z"] param_dict = dict.fromkeys(param_list) trans_perf_param_dict = dict.fromkeys(param_list) @@ -59,8 +63,8 @@ elif survey_type == "rotation": conversion_factor = 0.001 # in rad (need to convert to mrad) # Change file name if running elsewhere -file_name = f'/afs/cern.ch/work/j/jreich/stack/Panoptes/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/rich2_{survey_type}_params.csv' -f = open(file_name, 'r') +file_name = f"/afs/cern.ch/work/j/jreich/stack/Panoptes/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/rich2_{survey_type}_params.csv" +f = open(file_name, "r") reader = csv.reader(f) for row, param in zip(reader, param_dict.keys()): param_dict[param] = float(row[0]) * conversion_factor @@ -81,12 +85,11 @@ else: cond_update_list = [] for panel_num in panel_nums: - pre_cond_str = f'Conditions/Alignment/Rich2/PDPanel{panel_num}_Align := ' - optimum_trans_cond_str = f'double_v dPosXYZ = {trans_perf_param_dict["p" + str(panel_num)+ "_x"]} {trans_perf_param_dict["p" + str(panel_num)+ "_y"]} {trans_perf_param_dict["p" + str(panel_num)+ "_z"]}; ' + pre_cond_str = f"Conditions/Alignment/Rich2/PDPanel{panel_num}_Align := " + optimum_trans_cond_str = f"double_v dPosXYZ = {trans_perf_param_dict['p' + str(panel_num) + '_x']} {trans_perf_param_dict['p' + str(panel_num) + '_y']} {trans_perf_param_dict['p' + str(panel_num) + '_z']}; " - update_cond = f'double_v {param_key} = {param_dict["p" + str(panel_num)+ "_x"]} {param_dict["p" + str(panel_num)+ "_y"]} {param_dict["p" + str(panel_num)+ "_z"]};' - cond_update_list.append(pre_cond_str + optimum_trans_cond_str + - update_cond) + update_cond = f"double_v {param_key} = {param_dict['p' + str(panel_num) + '_x']} {param_dict['p' + str(panel_num) + '_y']} {param_dict['p' + str(panel_num) + '_z']};" + cond_update_list.append(pre_cond_str + optimum_trans_cond_str + update_cond) UpdateManagerSvc().ConditionsOverride = cond_update_list @@ -110,20 +113,20 @@ default_reco_opts.update(panel_select) # Monitoring opts tighter_minp = { "TightTrackSelection": { - "MinP": 60. * GeV, + "MinP": 60.0 * GeV, "MinPt": 0.5 * GeV, - "MaxChi2": 2., + "MaxChi2": 2.0, "MaxGhostProb": 0.1, } } default_opts.update(tighter_minp) -wider_histo = {'CKResHistoRange': (0.025, 0.008, 0.012)} +wider_histo = {"CKResHistoRange": (0.025, 0.008, 0.012)} default_level2_opts.update(wider_histo) align_tasks = [ - 'Produce', # fill the production set of histograms - 'Monitor', # add various checking histograms + "Produce", # fill the production set of histograms + "Monitor", # add various checking histograms #'Map', # add counters for creation of the HLT1 pre-selection line "map" #'Optimize', # add counters for optimization of the RICH2 mirror combinations subset #'Select', # check filling the rest of RICH2 mirror combinations along with 8 poorest @@ -134,12 +137,16 @@ align_tasks = [ nkevts = str(math.trunc(options.evt_max / 1000)) # save output file with histograms -options.histo_file = 'rich2_opt.root' - - -with standalone_rich_panel_align_reco.bind(RichGas=radiator, \ - noUT=True), \ - default_ft_decoding_version.bind(value=6), \ - default_rich_reco_options.bind(default_rich_reco_opts_modify=default_reco_opts), \ - default_rich_monitoring_options.bind(default_rich_moni_opts_modify=default_opts,default_rich_moni_opts_modify_level2=default_level2_opts): +options.histo_file = "rich2_opt.root" + + +with ( + standalone_rich_panel_align_reco.bind(RichGas=radiator, noUT=True), + default_ft_decoding_version.bind(value=6), + default_rich_reco_options.bind(default_rich_reco_opts_modify=default_reco_opts), + default_rich_monitoring_options.bind( + default_rich_moni_opts_modify=default_opts, + default_rich_moni_opts_modify_level2=default_level2_opts, + ), +): run_reconstruction(options, standalone_rich_panel_align_reco) diff --git a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/old_scripts/hlt2_reco_rich2_opt.py b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/old_scripts/hlt2_reco_rich2_opt.py index d463575fbc4958eb24e2edb16892183ef465a9e6..85e4ca19f905ec726d56bd762bb8eef2b019f072 100644 --- a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/old_scripts/hlt2_reco_rich2_opt.py +++ b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/old_scripts/hlt2_reco_rich2_opt.py @@ -8,63 +8,70 @@ # granted to it by virtue of its status as an Intergovernmental Organization # # or submit itself to any jurisdiction. # ############################################################################### -import glob import csv +import glob import math +from Configurables import CondDB, UpdateManagerSvc from GaudiKernel.SystemOfUnits import ( - GeV, ) + GeV, +) from Moore import ( options, run_reconstruction, ) +from PyConf.tonic import configurable from RecoConf.rich_add_reconstruction_monitoring_checking import ( - add_hlt2_rich, ) + add_hlt2_rich, +) from RecoConf.rich_data_monitoring import ( - default_rich_monitoring_options, alignment_rich_monitoring_options, + default_rich_monitoring_options, ) - from RecoConf.rich_reconstruction import default_rich_reco_options - from RecoConf.standalone import ( - standalone_hlt2_light_reco_without_UT, ) -from PyConf.tonic import configurable -from Configurables import (CondDB, UpdateManagerSvc) + standalone_hlt2_light_reco_without_UT, +) + """Options for running over data with FT raw bank version 6.""" from RecoConf.decoders import ( - default_ft_decoding_version, ) - + default_ft_decoding_version, +) from RecoConf.hlt2_tracking import ( - make_hlt2_tracks_without_UT, ) + make_hlt2_tracks_without_UT, +) options.n_threads = 10 options.evt_max = 10000 -options.input_files = sorted([ - 'mdf:root://eoslhcb.cern.ch/%s' % f for f in glob.glob( - r'/eos/lhcb/grid/prod/lhcb/MC/Upgrade/MDF/00146082/000*/00146082_*') -]) -options.input_type = 'MDF' -options.dddb_tag = 'upgrade/bmalecki-rich-alignmentParameters' -options.conddb_tag = 'upgrade/bmalecki-rich-alignmentParameters' +options.input_files = sorted( + [ + "mdf:root://eoslhcb.cern.ch/%s" % f + for f in glob.glob( + r"/eos/lhcb/grid/prod/lhcb/MC/Upgrade/MDF/00146082/000*/00146082_*" + ) + ] +) +options.input_type = "MDF" +options.dddb_tag = "upgrade/bmalecki-rich-alignmentParameters" +options.conddb_tag = "upgrade/bmalecki-rich-alignmentParameters" -rich = 'rich2' +rich = "rich2" radiator = "Rich2Gas" track_types = [ - 'Long', + "Long", #'Upstream', #'Downstream', ] # Import alignment parameters from csv file and apply -param_list = ['p0_x', 'p1_x', 'p0_y', 'p1_y', 'p0_z', 'p1_z'] +param_list = ["p0_x", "p1_x", "p0_y", "p1_y", "p0_z", "p1_z"] param_dict = dict.fromkeys(param_list) # Change file name if running elsewhere -file_name = '/afs/cern.ch/work/j/jamey/public/rich_align/rich_align_upgrade/optimisation/rich2_params.csv' -f = open(file_name, 'r') +file_name = "/afs/cern.ch/work/j/jamey/public/rich_align/rich_align_upgrade/optimisation/rich2_params.csv" +f = open(file_name, "r") reader = csv.reader(f) for row, param in zip(reader, param_dict.keys()): param_dict[param] = float(row[0]) @@ -87,20 +94,20 @@ default_reco_opts.update(panel_select) # Monitoring opts tighter_minp = { "TightTrackSelection": { - "MinP": 60. * GeV, + "MinP": 60.0 * GeV, "MinPt": 0.5 * GeV, - "MaxChi2": 2., + "MaxChi2": 2.0, "MaxGhostProb": 0.1, } } default_opts.update(tighter_minp) -wider_histo = {'CKResHistoRange': (0.025, 0.008, 0.012)} +wider_histo = {"CKResHistoRange": (0.025, 0.008, 0.012)} default_opts.update(wider_histo) align_tasks = [ - 'Produce', # fill the production set of histograms - 'Monitor', # add various checking histograms + "Produce", # fill the production set of histograms + "Monitor", # add various checking histograms #'Map', # add counters for creation of the HLT1 pre-selection line "map" #'Optimize', # add counters for optimization of the RICH2 mirror combinations subset #'Select', # check filling the rest of RICH2 mirror combinations along with 8 poorest @@ -113,18 +120,25 @@ task = align_tasks[0] nkevts = str(math.trunc(options.evt_max / 1000)) # save output file with histograms -options.histo_file = 'rich2_opt.root' +options.histo_file = "rich2_opt.root" moni_set = "PhotonCherenkovAngles" -with add_hlt2_rich.bind( +with ( + add_hlt2_rich.bind( do_data_monitoring_rich=True, moni_set=moni_set, radiator=radiator, align_tasks=align_tasks, - track_types=track_types), \ - default_ft_decoding_version.bind(value=6), \ - make_hlt2_tracks_without_UT.bind(use_pr_kf=True, light_reco=True, fast_reco=True), \ - default_rich_reco_options.bind(default_rich_reco_opts_level2_modify=default_reco_opts), \ - default_rich_monitoring_options.bind(default_rich_moni_opts_level2_modify=default_opts): + track_types=track_types, + ), + default_ft_decoding_version.bind(value=6), + make_hlt2_tracks_without_UT.bind(use_pr_kf=True, light_reco=True, fast_reco=True), + default_rich_reco_options.bind( + default_rich_reco_opts_level2_modify=default_reco_opts + ), + default_rich_monitoring_options.bind( + default_rich_moni_opts_level2_modify=default_opts + ), +): run_reconstruction(options, standalone_hlt2_light_reco_without_UT) diff --git a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/optimise_RICH.py b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/optimise_RICH.py index 6d3120e9b91f1553f5faf7b557685a51552ef374..243b085576a7ae63ee22d58d84f8fd50711ca1d3 100644 --- a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/optimise_RICH.py +++ b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/optimise_RICH.py @@ -8,70 +8,91 @@ # granted to it by virtue of its status as an Intergovernmental Organization # # or submit itself to any jurisdiction. # ############################################################################### +import argparse +import csv +import json import os +import random import re -import sys import subprocess -import csv -import argparse -import random - import sys -import numpy as np -from ROOT import gROOT, TH1D, TCanvas, TFile, TF1, gStyle, TGraph, TMultiGraph, TLine, TH2D, TExec -from scipy.optimize import minimize -import json +import numpy as np from GaudiPython import gbl +from ROOT import ( + TF1, + TH1D, + TH2D, + TCanvas, + TExec, + TFile, + TGraph, + TLine, + TMultiGraph, + gROOT, + gStyle, +) +from scipy.optimize import minimize # Set batch mode so histograms aren't printed -#sys.argv.append('-b') +# sys.argv.append('-b') gROOT.SetBatch(True) class AlignMonitor: - def __init__(self, whichRich, floated - # _alignConf, - # _maxIt, - ): - ''' + def __init__( + self, + whichRich, + floated, + # _alignConf, + # _maxIt, + ): + """ self.alignConf = _alignConf self.nameStr = self.alignConf.getProp('nameStr') self.whichRich = self.alignConf.getProp('Rich') self.displayMode = self.alignConf.getProp('displayMode') self.warningFactor = self.alignConf.getProp('warningFactor') self.maxIt = _maxIt # the maximum labeled number of the iterations that we are looping through - ''' - self.workdir = './' + """ + self.workdir = "./" self.whichRich = whichRich self.maxIt = 0 - self.floated_str = '_'.join(str(round(f, 2)) for f in floated) - self.prename = f'{prepath}/rich{self.whichRich}_opt_dd4hep_p{whichPanel}.root' + self.floated_str = "_".join(str(round(f, 2)) for f in floated) + self.prename = f"{prepath}/rich{self.whichRich}_opt_dd4hep_p{whichPanel}.root" # RICH1 settings self.maxpri = 3 self.binToPriMirr = [[2, 3], [0, 1]] self.maxsec = 15 - self.binToSecMirr = [[10, 11, 14, 15], [8, 9, 12, 13], [2, 3, 6, 7], - [0, 1, 4, 5]] + self.binToSecMirr = [ + [10, 11, 14, 15], + [8, 9, 12, 13], + [2, 3, 6, 7], + [0, 1, 4, 5], + ] self.fitMin = -0.0055 self.fitMax = 0.0055 # if RICH2, use RICH2 settings - if (self.whichRich == 2): + if self.whichRich == 2: self.maxpri = 55 - self.binToPriMirr = [[3, 2, 1, 0, 31, 30, 29, 28], - [7, 6, 5, 4, 35, 34, 33, 32], - [11, 10, 9, 8, 39, 38, 37, 36], - [15, 14, 13, 12, 43, 42, 41, 40], - [19, 18, 17, 16, 47, 46, 45, 44], - [23, 22, 21, 20, 51, 50, 49, 48], - [27, 26, 25, 24, 55, 54, 53, 52]] + self.binToPriMirr = [ + [3, 2, 1, 0, 31, 30, 29, 28], + [7, 6, 5, 4, 35, 34, 33, 32], + [11, 10, 9, 8, 39, 38, 37, 36], + [15, 14, 13, 12, 43, 42, 41, 40], + [19, 18, 17, 16, 47, 46, 45, 44], + [23, 22, 21, 20, 51, 50, 49, 48], + [27, 26, 25, 24, 55, 54, 53, 52], + ] self.maxsec = 39 - self.binToSecMirr = [[3, 2, 1, 0, 23, 22, 21, 20], - [7, 6, 5, 4, 27, 26, 25, 24], - [11, 10, 9, 8, 31, 30, 29, 28], - [15, 14, 13, 12, 35, 34, 33, 32], - [19, 18, 17, 16, 39, 38, 37, 36]] + self.binToSecMirr = [ + [3, 2, 1, 0, 23, 22, 21, 20], + [7, 6, 5, 4, 27, 26, 25, 24], + [11, 10, 9, 8, 31, 30, 29, 28], + [15, 14, 13, 12, 35, 34, 33, 32], + [19, 18, 17, 16, 39, 38, 37, 36], + ] # Original fit range self.fitMin = -0.0055 self.fitMax = 0.0055 @@ -84,6 +105,7 @@ class AlignMonitor: def performMonitoring(self, p, hist_path=""): import os + gStyle.SetOptFit(1111) gStyle.SetOptStat(000000000) @@ -94,22 +116,25 @@ class AlignMonitor: # File for the RICH piquet AND for the RICH mirror alignment experts if num_chunks != 0: - expertFile = f'Rich{self.whichRich}_{survey_type}_{p}_({self.floated_str})_{pdf_suff}.pdf' + expertFile = f"Rich{self.whichRich}_{survey_type}_{p}_({self.floated_str})_{pdf_suff}.pdf" else: if os.path.isdir(self.workdir + "plots") is not True: os.mkdir(self.workdir + "plots") - expertFile = self.workdir + f'plots/Rich{self.whichRich}_{survey_type}_{p}_({self.floated_str})_{pdf_suff}.pdf' + expertFile = ( + self.workdir + + f"plots/Rich{self.whichRich}_{survey_type}_{p}_({self.floated_str})_{pdf_suff}.pdf" + ) # File for the Alignment piquet ("duplicating" what goes to the Presenter for the Data Manager [except CK angle res stuff]) - monitorFile = self.workdir + f'Rich{self.whichRich}_AlignMonitor.pdf' + monitorFile = self.workdir + f"Rich{self.whichRich}_AlignMonitor.pdf" # File with for testing purposes - testingFile = self.workdir + f'Rich{self.whichRich}_AlignTesting.pdf' + testingFile = self.workdir + f"Rich{self.whichRich}_AlignTesting.pdf" # Data Manager can only get histograms sent via self.monSvc - theCanvas = TCanvas('theCanvas', 'MirrAlign') + theCanvas = TCanvas("theCanvas", "MirrAlign") theCanvas.Divide(2, 2, 0.001, 0.001) - theCanvas2 = TCanvas('theCanvas2', 'MirrAlignTest') + theCanvas2 = TCanvas("theCanvas2", "MirrAlignTest") theCanvas2.Divide(2, 2, 0.001, 0.001) theCanvas2.Clear() @@ -146,31 +171,38 @@ class AlignMonitor: # define resHistoTrend resHistoTrend = TH1D( - 'resHistoTrend', 'RICH' + str(self.whichRich) + - ' Cherenkov angle resolution (mrad) per It. ', self.maxIt + 1, - -0.5, self.maxIt + 0.5) + "resHistoTrend", + "RICH" + + str(self.whichRich) + + " Cherenkov angle resolution (mrad) per It. ", + self.maxIt + 1, + -0.5, + self.maxIt + 0.5, + ) for j in reversed(range(0, self.maxIt + 1)): filename[j] = self.prename if os.path.exists(filename[j]): - thisFile[j] = TFile(filename[j], 'read') + thisFile[j] = TFile(filename[j], "read") if hist_path == "": - hist[j] = (thisFile[j].Get( - f'RICH/RiCKResLongTight/Rich{self.whichRich}Gas/ckResAll' - )).Clone() + hist[j] = ( + thisFile[j].Get( + f"RICH/RiCKResLongTight/Rich{self.whichRich}Gas/ckResAll" + ) + ).Clone() else: - hist[j] = (thisFile[j].Get(f'{hist_path}')).Clone() + hist[j] = (thisFile[j].Get(f"{hist_path}")).Clone() if (j == 0) and (j == self.maxIt): - hist[j].SetName('resHisto0') - hist[j].SetName('resHistoN') - elif (j == self.maxIt): - hist[j].SetName('resHistoN') - elif (j == 0): - hist[j].SetName('resHisto0') - if (j != 0): - hist[j].SetName('resHisto' + str(j)) + hist[j].SetName("resHisto0") + hist[j].SetName("resHistoN") + elif j == self.maxIt: + hist[j].SetName("resHistoN") + elif j == 0: + hist[j].SetName("resHisto0") + if j != 0: + hist[j].SetName("resHisto" + str(j)) # perform the fit and extract fit models fitRes[j], resHistograms[j] = self.fitCherenkovAngle(hist[j]) @@ -193,12 +225,15 @@ class AlignMonitor: resHistoTrend.SetBinContent(j + 1, 100) resHistoTrend.SetBinError(j + 1, 100) - title[j] = 'RICH' + str( - self.whichRich - ) + ' Cherenkov angle resolution It. ' + str(j) + title[j] = ( + "RICH" + + str(self.whichRich) + + " Cherenkov angle resolution It. " + + str(j) + ) hist[j].SetTitle(title[j]) - hist[j].SetXTitle('#Delta#theta_{Cherenkov} (rad)') - hist[j].SetYTitle('Entries') + hist[j].SetXTitle("#Delta#theta_{Cherenkov} (rad)") + hist[j].SetYTitle("Entries") gStyle.SetStatW(0.11) @@ -213,9 +248,10 @@ class AlignMonitor: # Make resHistoTrend iteration trend plot resHistoTrend.SetMarkerStyle(8) - resHistoTrend.SetXTitle('iteration number') + resHistoTrend.SetXTitle("iteration number") resHistoTrend.SetYTitle( - '#splitline{Cherenkov angle resolution (mrad)}{}') + "#splitline{Cherenkov angle resolution (mrad)}{}" + ) theCanvas2.Clear() theCanvas.Clear() @@ -232,24 +268,38 @@ class AlignMonitor: resHistoTrend.SetBinContent(j + 1, ckres) resHistoTrend.SetBinError(j + 1, ckres_error) - print("_i" + str(j) + " CK angle resolution: " + - str(ckres) + " mrad.") - print("_i" + str(j) + " CK angle resolution err: " + - str(ckres_error) + " mrad.") - print("_i" + str(j) + " CK angle gaussian mean: " + - str(gaussianmean) + " mrad.") + print( + "_i" + str(j) + " CK angle resolution: " + str(ckres) + " mrad." + ) + print( + "_i" + + str(j) + + " CK angle resolution err: " + + str(ckres_error) + + " mrad." + ) + print( + "_i" + + str(j) + + " CK angle gaussian mean: " + + str(gaussianmean) + + " mrad." + ) if j == self.maxIt: self.finalCKres = ckres self.finalCKresErr = ckres_error self.finalCKgaussianmean = gaussianmean - title[j] = 'RICH' + str( - self.whichRich) + ' Cherenkov angle resolution It. ' + str( - j) + title[j] = ( + "RICH" + + str(self.whichRich) + + " Cherenkov angle resolution It. " + + str(j) + ) resHistograms[j].SetTitle(title[j]) - resHistograms[j].SetXTitle('#Delta#theta_{Cherenkov} (rad)') - resHistograms[j].SetYTitle('Entries') + resHistograms[j].SetXTitle("#Delta#theta_{Cherenkov} (rad)") + resHistograms[j].SetYTitle("Entries") histFunc[j].SetLineColor(2) polbkg[j].SetLineColor(4) @@ -273,15 +323,14 @@ class AlignMonitor: else: print("WARNING: " + filename[j] + ": does not exist") - #theCanvas.Print(monitorFile) + # theCanvas.Print(monitorFile) # sys.stdout.flush() # Make resHistoTrend iteration trend plot resHistoTrend.SetMarkerStyle(8) - resHistoTrend.SetXTitle('iteration number') - resHistoTrend.SetYTitle( - '#splitline{Cherenkov angle resolution (mrad)}{}') + resHistoTrend.SetXTitle("iteration number") + resHistoTrend.SetYTitle("#splitline{Cherenkov angle resolution (mrad)}{}") theCanvas2.Clear() theCanvas.Clear() @@ -291,14 +340,12 @@ class AlignMonitor: sys.stdout.flush() def fitCherenkovAngle(self, hist): - # get Chris Jones's C++ fitter fitter = gbl.Rich.Rec.CKResolutionFitter() # set signal (AsymNormal) and background (FreeNPol) models fitter.params().RichFitTypes[whichRich - 1].clear() - fitter.params().RichFitTypes[whichRich - - 1].push_back("AsymNormal:FreeNPol") + fitter.params().RichFitTypes[whichRich - 1].push_back("AsymNormal:FreeNPol") # change fit ranges fitter.params().RichFitMin[0] = self.fitMin @@ -312,21 +359,19 @@ class AlignMonitor: def write_to_csv(x): - with open(f'rich{whichRich}_{survey_type}_params_p{whichPanel}.csv', - 'w') as f: + with open(f"rich{whichRich}_{survey_type}_params_p{whichPanel}.csv", "w") as f: wtr = csv.writer(f) for axis in x.keys(): wtr.writerow([x[axis]]) def check_if_already_run(x, csv_name): - conditions = [] for axis in x.keys(): if x[axis] is not None: - conditions.append(f'{axis}{x[axis]}') + conditions.append(f"{axis}{x[axis]}") - conds_to_write = ':'.join(str(d) for d in conditions) + conds_to_write = ":".join(str(d) for d in conditions) # extract conditions from current iteration pattern = r"(?:x|y|z)(-?\d+\.\d+)" match1 = re.findall(pattern, conds_to_write) @@ -341,14 +386,11 @@ def check_if_already_run(x, csv_name): return True - if (os.path.exists( - f'ck_vs_param_R{whichRich}_{survey_type}_{csv_name}.csv')): + if os.path.exists(f"ck_vs_param_R{whichRich}_{survey_type}_{csv_name}.csv"): reconstruction_already_run = False - with open(f'ck_vs_param_R{whichRich}_{survey_type}_{csv_name}.csv', - 'r') as f: - reader = csv.reader(f, delimiter=',') + with open(f"ck_vs_param_R{whichRich}_{survey_type}_{csv_name}.csv", "r") as f: + reader = csv.reader(f, delimiter=",") for row in reader: - # extract conditions for row in results file match2 = re.findall(pattern, row[1]) match2 = [float(cond) for cond in match2] @@ -356,30 +398,23 @@ def check_if_already_run(x, csv_name): reconstruction_already_run = is_close_to_match(match1, match2) if reconstruction_already_run: - print( - "INFO: Reconstruction has already completed. Skipping..." - ) + print("INFO: Reconstruction has already completed. Skipping...") return reconstruction_already_run return reconstruction_already_run else: print( - f'ck_vs_param_R{whichRich}_{survey_type}_{csv_name}.csv , does not exist. This must be the 1st time you have run this configuration.' + f"ck_vs_param_R{whichRich}_{survey_type}_{csv_name}.csv , does not exist. This must be the 1st time you have run this configuration." ) return def check_for_reco_issues(finalCKres, finalCKresErr, csv_name): - issue_present = False - if (os.path.exists( - f'ck_vs_param_R{whichRich}_{survey_type}_{csv_name}.csv')): - - with open(f'ck_vs_param_R{whichRich}_{survey_type}_{csv_name}.csv', - 'r') as f: - reader = csv.reader(f, delimiter=',') + if os.path.exists(f"ck_vs_param_R{whichRich}_{survey_type}_{csv_name}.csv"): + with open(f"ck_vs_param_R{whichRich}_{survey_type}_{csv_name}.csv", "r") as f: + reader = csv.reader(f, delimiter=",") for row in reader: - if float(finalCKresErr) == 0.0: issue_present = True print( @@ -393,67 +428,71 @@ def check_for_reco_issues(finalCKres, finalCKresErr, csv_name): def write_plotting(ck, x, ckerr, ck_gaussian_mean, csv_name, col_num): - conditions = [] for axis in x.keys(): if x[axis] is not None: - conditions.append(f'{axis}{x[axis]}') + conditions.append(f"{axis}{x[axis]}") - conds_to_write = ':'.join(str(d) for d in conditions) + conds_to_write = ":".join(str(d) for d in conditions) - with open(f'ck_vs_param_R{whichRich}_{survey_type}_{csv_name}.csv', - 'a') as f: + with open(f"ck_vs_param_R{whichRich}_{survey_type}_{csv_name}.csv", "a") as f: writer = csv.writer(f) if "all" in col_num: writer.writerow([ck, conds_to_write, ckerr, ck_gaussian_mean]) else: - writer.writerow( - [ck, conds_to_write, ckerr, ck_gaussian_mean, col_num]) + writer.writerow([ck, conds_to_write, ckerr, ck_gaussian_mean, col_num]) def monitor(x, panel): - ''' + """ Function to be minimised x - tuple of alignment parameters as: (panel0_x, panel1_x, panel0_y, panel1_y, panel0_z, panel1_z) panel - str of panel to shift, choose from '0x', '1x', '0y', '1y' returns resolution (need to minimise) - ''' + """ start_time = time.time() # create starting dict of 0.0 for each condition - param_list = ['p0_x', 'p1_x', 'p0_y', 'p1_y', 'p0_z', 'p1_z'] + param_list = ["p0_x", "p1_x", "p0_y", "p1_y", "p0_z", "p1_z"] param_dict = dict.fromkeys(param_list) for p_axis in param_dict.keys(): param_dict[p_axis] = 0.0 # set optimum alignment conditions if survey_type == "translation": - param_dict[f'p{whichPanel}_x'] = yml_opts[f"R{whichRich}"][ - f"P{whichPanel}"]["perf_trans"]["x"] - param_dict[f'p{whichPanel}_y'] = yml_opts[f"R{whichRich}"][ - f"P{whichPanel}"]["perf_trans"]["y"] - param_dict[f'p{whichPanel}_z'] = yml_opts[f"R{whichRich}"][ - f"P{whichPanel}"]["perf_trans"]["z"] + param_dict[f"p{whichPanel}_x"] = yml_opts[f"R{whichRich}"][f"P{whichPanel}"][ + "perf_trans" + ]["x"] + param_dict[f"p{whichPanel}_y"] = yml_opts[f"R{whichRich}"][f"P{whichPanel}"][ + "perf_trans" + ]["y"] + param_dict[f"p{whichPanel}_z"] = yml_opts[f"R{whichRich}"][f"P{whichPanel}"][ + "perf_trans" + ]["z"] elif survey_type == "rotation": - param_dict[f'p{whichPanel}_x'] = yml_opts[f"R{whichRich}"][ - f"P{whichPanel}"]["perf_rot"]["x"] - param_dict[f'p{whichPanel}_y'] = yml_opts[f"R{whichRich}"][ - f"P{whichPanel}"]["perf_rot"]["y"] - param_dict[f'p{whichPanel}_z'] = yml_opts[f"R{whichRich}"][ - f"P{whichPanel}"]["perf_rot"]["z"] + param_dict[f"p{whichPanel}_x"] = yml_opts[f"R{whichRich}"][f"P{whichPanel}"][ + "perf_rot" + ]["x"] + param_dict[f"p{whichPanel}_y"] = yml_opts[f"R{whichRich}"][f"P{whichPanel}"][ + "perf_rot" + ]["y"] + param_dict[f"p{whichPanel}_z"] = yml_opts[f"R{whichRich}"][f"P{whichPanel}"][ + "perf_rot" + ]["z"] for axis in ["x", "y", "z"]: if x[axis] is not None: # we want to update this condition - param_dict[f'p{whichPanel}_{axis}'] = x[axis] + param_dict[f"p{whichPanel}_{axis}"] = x[axis] print(x) write_to_csv(param_dict) check_if_already_run_res = check_if_already_run( - param_dict, f'panel{panel}{axis_name}') + param_dict, f"panel{panel}{axis_name}" + ) if check_if_already_run_res: return @@ -461,24 +500,25 @@ def monitor(x, panel): alignMonitor = AlignMonitor( whichRich=whichRich, floated=[ - param_dict[f'p{whichPanel}_x'], param_dict[f'p{whichPanel}_y'], - param_dict[f'p{whichPanel}_z'] - ]) + param_dict[f"p{whichPanel}_x"], + param_dict[f"p{whichPanel}_y"], + param_dict[f"p{whichPanel}_z"], + ], + ) alignMonitor.performMonitoring(panel, hist_path) finalCKres = alignMonitor.finalCKres finalCKresErr = alignMonitor.finalCKresErr finalCKgaussianmean = alignMonitor.finalCKgaussianmean check_for_reco_issues_res = check_for_reco_issues( - finalCKres, finalCKresErr, f'panel{panel}{axis_name}') + finalCKres, finalCKresErr, f"panel{panel}{axis_name}" + ) return check_for_reco_issues_res, finalCKres, finalCKresErr, finalCKgaussianmean check_for_reco_issues_res = True while check_for_reco_issues_res: - # Wait for the file to be released, with a timeout of 100 seconds try: - wait_for_file( - "hlt2_reco_rich2_noUT_survey_dd4hep_survey.py", timeout=100) + wait_for_file("hlt2_reco_rich2_noUT_survey_dd4hep_survey.py", timeout=100) print("INFO: File is free. Proceed with running the file.") # Your code to run the file goes here except TimeoutError: @@ -486,8 +526,10 @@ def monitor(x, panel): quit() print("INFO: Running Reconstruction...") - reco_run_str = f"{stack_path}/Panoptes/run gaudirun.py {stack_path}/" +\ - f"Panoptes/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/" + reco_run_str = ( + f"{stack_path}/Panoptes/run gaudirun.py {stack_path}/" + + f"Panoptes/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/" + ) if verbose: reco_run_str += f"hlt2_reco_rich2_noUT_survey_dd4hep_survey.py | tee steeringR{whichRich}_p{whichPanel}_log.log" else: @@ -501,38 +543,49 @@ def monitor(x, panel): if columns: for col_num in column_nums: print(f"Column: {col_num}/{column_nums[-1]}") - check_for_reco_issues_res, \ - finalCKres, finalCKresErr, \ - finalCKgaussianmean = perform_one_fit_pipeline(hist_path = f"{hist_path_prefix}{col_num}" ) + ( + check_for_reco_issues_res, + finalCKres, + finalCKresErr, + finalCKgaussianmean, + ) = perform_one_fit_pipeline(hist_path=f"{hist_path_prefix}{col_num}") results_dict[f"{col_num}"] = { "finalCKres": finalCKres, "finalCKresErr": finalCKresErr, - "finalCKgaussianmean": finalCKgaussianmean + "finalCKgaussianmean": finalCKgaussianmean, } else: - check_for_reco_issues_res, finalCKres, finalCKresErr, finalCKgaussianmean = perform_one_fit_pipeline( - ) + ( + check_for_reco_issues_res, + finalCKres, + finalCKresErr, + finalCKgaussianmean, + ) = perform_one_fit_pipeline() results_dict["all_cols"] = { "finalCKres": finalCKres, "finalCKresErr": finalCKresErr, - "finalCKgaussianmean": finalCKgaussianmean + "finalCKgaussianmean": finalCKgaussianmean, } # sys.stdout.flush() # os.remove(f'rich{whichRich}_opt_dd4hep_p{whichPanel}.root') # os.remove(f'rich{whichRich}_opt_dd4hep_p{whichPanel}_new.root') - os.remove(f'rich{whichRich}_{survey_type}_params_p{whichPanel}.csv') + os.remove(f"rich{whichRich}_{survey_type}_params_p{whichPanel}.csv") for col_num in results_dict.keys(): - write_plotting(results_dict[col_num]["finalCKres"], param_dict, - results_dict[col_num]["finalCKresErr"], - results_dict[col_num]["finalCKgaussianmean"], - f'panel{panel}{axis_name}', col_num) + write_plotting( + results_dict[col_num]["finalCKres"], + param_dict, + results_dict[col_num]["finalCKresErr"], + results_dict[col_num]["finalCKgaussianmean"], + f"panel{panel}{axis_name}", + col_num, + ) diff_time = time.time() - start_time - print(f'INFO: Time taken for this iteration: {round(diff_time)} seconds') + print(f"INFO: Time taken for this iteration: {round(diff_time)} seconds") return finalCKres @@ -548,10 +601,12 @@ class minimizer: self.init_conds = {"x": None, "y": None, "z": None} for axis in self.axes: - self.conds_update[axis] = init_dict[f'R{whichRich}'][ - f'{self.p}{axis}'][f'{survey_type}'] - self.init_conds[axis] = init_dict[f'R{whichRich}'][ - f'{self.p}{axis}'][f'{survey_type}'] + self.conds_update[axis] = init_dict[f"R{whichRich}"][f"{self.p}{axis}"][ + f"{survey_type}" + ] + self.init_conds[axis] = init_dict[f"R{whichRich}"][f"{self.p}{axis}"][ + f"{survey_type}" + ] if not twoD_scan: # for 1D scans pass @@ -561,19 +616,15 @@ class minimizer: self.num_iter["y"] = self.iter_num if whichRich == 1 and whichPanel == 0: - self.manual_points = {"x": [], "y": []} if whichRich == 1 and whichPanel == 1: - self.manual_points = {"x": [], "y": []} if whichRich == 2 and whichPanel == 0: - self.manual_points = {"x": [], "y": []} if whichRich == 2 and whichPanel == 1: - self.manual_points = {"x": [], "y": []} def perform_scans(self): @@ -584,29 +635,25 @@ class minimizer: else: if run_manual_points: for i in range(0, len(self.manual_points["x"])): - self.conds_update[self. - axes[0]] = self.manual_points["x"][i] - self.conds_update[self. - axes[1]] = self.manual_points["y"][i] + self.conds_update[self.axes[0]] = self.manual_points["x"][i] + self.conds_update[self.axes[1]] = self.manual_points["y"][i] res = monitor(self.conds_update, self.p) else: - total_iter = (self.num_iter["x"] + 1) * ( - self.num_iter["y"] + 1) + total_iter = (self.num_iter["x"] + 1) * (self.num_iter["y"] + 1) iter_counter = 0 for i_x in range(self.num_iter["x"] + 1): if i_x != 0: self.conds_update[self.axes[0]] += self.step_size - self.conds_update[self.axes[1]] = self.init_conds[self. - axes[1]] + self.conds_update[self.axes[1]] = self.init_conds[self.axes[1]] for i_y in range(self.num_iter["y"] + 1): if i_y != 0: self.conds_update[self.axes[1]] += self.step_size print( - f"INFO: {iter_counter}/{total_iter} ({round(iter_counter/total_iter*100.0)}%) complete. " + f"INFO: {iter_counter}/{total_iter} ({round(iter_counter / total_iter * 100.0)}%) complete. " ) res = monitor(self.conds_update, self.p) iter_counter += 1 @@ -617,18 +664,20 @@ class minimizer: results_list = [] ckres_list = [] with open( - f'ck_vs_param_R{whichRich}_{survey_type}_panel{whichPanel}{axis_name}.csv', - 'r') as f: + f"ck_vs_param_R{whichRich}_{survey_type}_panel{whichPanel}{axis_name}.csv", + "r", + ) as f: for line in f: stripped_line = line.strip() results_list.append(stripped_line) # store all info - parts = stripped_line.split(',') + parts = stripped_line.split(",") ckres_list.append(float(parts[0])) # check if we have reached threshold for i in range(0, len(ckres_list)): - if ((ckres_list[i] < 0.4 and whichRich == 1) - or (ckres_list[i] < 0.2 and whichRich == 2)): + if (ckres_list[i] < 0.4 and whichRich == 1) or ( + ckres_list[i] < 0.2 and whichRich == 2 + ): ckres_list[i] = 100 min_ckres = min(ckres_list) @@ -641,7 +690,8 @@ class minimizer: # extract conditions for the iteration with min ckres min_ckres_index = ckres_list.index(min_ckres) min_ckres_conds = results_list[min_ckres_index].split(",")[ - 1] # looks like p0_x1.9:p1_x0.0:p0_y-5.8:p1_y0.0:p0_z0.0 + 1 + ] # looks like p0_x1.9:p1_x0.0:p0_y-5.8:p1_y0.0:p0_z0.0 min_ckres_conds_splitted = min_ckres_conds.split(":") if whichPanel == 0: new_x_start = float(min_ckres_conds_splitted[0].split("x")[1]) @@ -653,12 +703,13 @@ class minimizer: new_z_start = float(min_ckres_conds_splitted[5].split("z")[1]) # check if new minimum is the same and the previous - if ((self.init_conds["x"] == new_x_start - self.offset) - and (self.init_conds["y"] == new_y_start - self.offset) - and (self.init_conds["z"] == new_z_start - self.offset)): - + if ( + (self.init_conds["x"] == new_x_start - self.offset) + and (self.init_conds["y"] == new_y_start - self.offset) + and (self.init_conds["z"] == new_z_start - self.offset) + ): # reduce the step size - self.step_size = 0.5 * self.step_size #(in mm) + self.step_size = 0.5 * self.step_size # (in mm) self.offset = int(self.iter_num / 2) * self.step_size print( f"INFO: Minimum hasn't moved, decreasing step size. (new step size = {self.step_size})" @@ -680,14 +731,12 @@ class minimizer: return False def align_panels(self): - self.perform_scans() n_scans = 1 if stop_on_threshold: - while not self.check_if_reached_threshold( - ): # have not reached threshold + while not self.check_if_reached_threshold(): # have not reached threshold print(f"INFO: Starting scan number {n_scans}.") self.perform_scans() n_scans += 1 @@ -700,7 +749,6 @@ class minimizer: def get_chunk_list(x0): - iter_list = [x0] update_x0 = x0[0] # obtain list of conditions to iterate over @@ -720,7 +768,7 @@ import time def is_file_locked(file_path): try: - file_descriptor = open(file_path, 'r') + file_descriptor = open(file_path, "r") fcntl.flock(file_descriptor, fcntl.LOCK_EX | fcntl.LOCK_NB) fcntl.flock(file_descriptor, fcntl.LOCK_UN) file_descriptor.close() @@ -734,66 +782,61 @@ def wait_for_file(file_path, interval=1, timeout=None): while is_file_locked(file_path): if timeout and (time.time() - start_time) >= timeout: - raise TimeoutError( - f"Timeout waiting for file {file_path} to be released.") + raise TimeoutError(f"Timeout waiting for file {file_path} to be released.") time.sleep(interval) -if __name__ == '__main__': +if __name__ == "__main__": parser = argparse.ArgumentParser( - description="Run optimisation on RICH panel alignment") + description="Run optimisation on RICH panel alignment" + ) parser.add_argument( - '--whichRich', - type=int, - choices=[1, 2], - help='Which RICH panel to optimise') + "--whichRich", type=int, choices=[1, 2], help="Which RICH panel to optimise" + ) parser.add_argument( - '--whichPanel', + "--whichPanel", type=str, - choices=['both', '0', '1'], - help='Which Panel panel to use') + choices=["both", "0", "1"], + help="Which Panel panel to use", + ) parser.add_argument( - '--survey_type', + "--survey_type", type=str, - help='Which tests to run', - choices=["translation", "rotation"]) + help="Which tests to run", + choices=["translation", "rotation"], + ) parser.add_argument( - '--twoD_scan', - type=str, - help='Perform 2D or 1D scans', - default='False') + "--twoD_scan", type=str, help="Perform 2D or 1D scans", default="False" + ) parser.add_argument( - '--columns', - default='False', - type=str, - help='Perform scans of columns') + "--columns", default="False", type=str, help="Perform scans of columns" + ) parser.add_argument( - '--axis_name', + "--axis_name", type=str, default="", - help='Which axis to translate along or rotate about', - choices=["x", "y", "z", ""]) + help="Which axis to translate along or rotate about", + choices=["x", "y", "z", ""], + ) parser.add_argument( - '--verbose', - default='False', - type=str, - help='Show output of reconstruction') + "--verbose", default="False", type=str, help="Show output of reconstruction" + ) parser.add_argument( - '--stop_on_threshold', - default='False', + "--stop_on_threshold", + default="False", type=str, - help='Stop iterating when you hit the ckres threshold') + help="Stop iterating when you hit the ckres threshold", + ) # arguments for batch submission parser.add_argument( - '--num_chunks', + "--num_chunks", type=int, default=0, - help= - 'Number of chunks to split up survey into (each chunk runs on a separate node)' + help="Number of chunks to split up survey into (each chunk runs on a separate node)", ) - parser.add_argument('--chunk_number', type=int, help='Chunk identifier') + parser.add_argument("--chunk_number", type=int, help="Chunk identifier") args = parser.parse_args() whichRich = int(args.whichRich) @@ -811,10 +854,11 @@ if __name__ == '__main__': ### write argparse options to YAML file ### from ruamel.yaml import YAML + yaml = YAML() # read - with open('survey_opts.yml') as opts_yml_file: + with open("survey_opts.yml") as opts_yml_file: yml_opts = yaml.load(opts_yml_file) # update @@ -823,11 +867,11 @@ if __name__ == '__main__': yml_opts["survey_type"] = survey_type # write - with open('survey_opts.yml', 'w') as opts_yml_file: + with open("survey_opts.yml", "w") as opts_yml_file: yaml.dump(yml_opts, opts_yml_file) stack_path = yml_opts["stack_path"] - prepath = f'{stack_path}/Panoptes/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys' + prepath = f"{stack_path}/Panoptes/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys" threshold = yml_opts[f"RICH{whichRich}_p{whichPanel}_CKres_threshold"] max_iter = yml_opts["max_iter"] @@ -835,15 +879,14 @@ if __name__ == '__main__': run_manual_points = False if survey_type == "translation": - if columns: iter_num = 8 # step_size = 0.5 #(in mm) - step_size = 0.25 #(in mm) + step_size = 0.25 # (in mm) offset = int(iter_num / 2) * step_size else: iter_num = 2 - step_size = 0.8 #(in mm) + step_size = 0.8 # (in mm) offset = int(iter_num / 2) * step_size elif survey_type == "rotation": @@ -856,64 +899,56 @@ if __name__ == '__main__': init_dict = { "R1": { "0x": { - "translation": - yml_opts["R1"]["P0"]["perf_trans"]["x"] - offset, - "rotation": -1.0 + "translation": yml_opts["R1"]["P0"]["perf_trans"]["x"] - offset, + "rotation": -1.0, }, "0y": { - "translation": - yml_opts["R1"]["P0"]["perf_trans"]["y"] - offset, - "rotation": -1.0 + "translation": yml_opts["R1"]["P0"]["perf_trans"]["y"] - offset, + "rotation": -1.0, }, "0z": { "translation": yml_opts["R1"]["P0"]["perf_trans"]["z"], - "rotation": -1.0 + "rotation": -1.0, }, "1x": { - "translation": - yml_opts["R1"]["P1"]["perf_trans"]["x"] - offset, - "rotation": -1.0 + "translation": yml_opts["R1"]["P1"]["perf_trans"]["x"] - offset, + "rotation": -1.0, }, "1y": { - "translation": - yml_opts["R1"]["P1"]["perf_trans"]["y"] - offset, - "rotation": -1.0 + "translation": yml_opts["R1"]["P1"]["perf_trans"]["y"] - offset, + "rotation": -1.0, }, "1z": { "translation": yml_opts["R1"]["P1"]["perf_trans"]["z"], - "rotation": -1.0 + "rotation": -1.0, }, }, "R2": { "0x": { - "translation": - yml_opts["R2"]["P0"]["perf_trans"]["x"] - offset, - "rotation": -25.0 + "translation": yml_opts["R2"]["P0"]["perf_trans"]["x"] - offset, + "rotation": -25.0, }, "0y": { - "translation": - yml_opts["R2"]["P0"]["perf_trans"]["y"] - offset, - "rotation": -25.0 + "translation": yml_opts["R2"]["P0"]["perf_trans"]["y"] - offset, + "rotation": -25.0, }, "0z": { "translation": yml_opts["R2"]["P0"]["perf_trans"]["z"], - "rotation": -25.0 + "rotation": -25.0, }, "1x": { - "translation": - yml_opts["R2"]["P1"]["perf_trans"]["x"] - offset, - "rotation": -25.0 + "translation": yml_opts["R2"]["P1"]["perf_trans"]["x"] - offset, + "rotation": -25.0, }, "1y": { - "translation": - yml_opts["R2"]["P1"]["perf_trans"]["y"] - offset, - "rotation": -25.0 + "translation": yml_opts["R2"]["P1"]["perf_trans"]["y"] - offset, + "rotation": -25.0, }, "1z": { "translation": yml_opts["R2"]["P1"]["perf_trans"]["z"], - "rotation": -25.0 + "rotation": -25.0, }, - } + }, } ### change these to alter starting positions of scan (centre of scan) @@ -935,19 +970,22 @@ if __name__ == '__main__': hist_path_prefix = "RICH/RiCKResLongTight/Rich1Gas/bottom/cols/ckResAllCol" column_nums = [i for i in range(0, 11)] if whichRich == 2 and whichPanel == 0: - hist_path_prefix = "RICH/RiCKResLongTight/Rich2Gas/ASide-left/cols/ckResAllCol" + hist_path_prefix = ( + "RICH/RiCKResLongTight/Rich2Gas/ASide-left/cols/ckResAllCol" + ) column_nums = [i for i in range(1, 13)] if whichRich == 2 and whichPanel == 1: - hist_path_prefix = "RICH/RiCKResLongTight/Rich2Gas/CSide-right/cols/ckResAllCol" + hist_path_prefix = ( + "RICH/RiCKResLongTight/Rich2Gas/CSide-right/cols/ckResAllCol" + ) column_nums = [i for i in range(1, 13)] if num_chunks != 0: - minimizer(f'{whichPanel}{axis}') + minimizer(f"{whichPanel}{axis}") else: if twoD_scan: - panel_aligner = minimizer(f'{whichPanel}xy', iter_num, step_size) + panel_aligner = minimizer(f"{whichPanel}xy", iter_num, step_size) else: - panel_aligner = minimizer(f'{whichPanel}{axis_name}', iter_num, - step_size) + panel_aligner = minimizer(f"{whichPanel}{axis_name}", iter_num, step_size) panel_aligner.align_panels() diff --git a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/plot_alignment_diffs.py b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/plot_alignment_diffs.py index 6669104e3c941bc15ee2c1641a681b05c3abb266..6955fd63702b4237d7aebe48a04708bdee58c427 100644 --- a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/plot_alignment_diffs.py +++ b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/plot_alignment_diffs.py @@ -8,21 +8,21 @@ # granted to it by virtue of its status as an Intergovernmental Organization # # or submit itself to any jurisdiction. # ############################################################################### +import argparse +import csv import os +import random import re -import sys import subprocess -import csv -import argparse -import random - import sys -import numpy as np + import matplotlib.pyplot as plt +import numpy as np from ruamel.yaml import YAML + yaml = YAML() -n_aligments = 4 #number of alignments +n_aligments = 4 # number of alignments n_aligments_list = list(range(1, n_aligments + 1)) alignments_dir = "/home/jreich/stack_dd4hep_v3/Panoptes/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/alignment_conditions" @@ -32,51 +32,55 @@ results_dict = {f"v{alignment_num}": {} for alignment_num in n_aligments_list} for whichRich in [1, 2]: for whichPanel in [0, 1]: for alignment_num in n_aligments_list: - # read yaml file - with open(f"{alignments_dir}/Rich{whichRich}/v{alignment_num}.yml" - ) as yml_file: + with open( + f"{alignments_dir}/Rich{whichRich}/v{alignment_num}.yml" + ) as yml_file: alignment_yml = yaml.load(yml_file) - results_dict[f"v{alignment_num}"][ - f"R{whichRich}P{whichPanel}"] = { - "px": - float(alignment_yml[f"PDPanel{whichPanel}"]["position"] - [0].split(" ")[0]), - "py": - float(alignment_yml[f"PDPanel{whichPanel}"]["position"] - [1].split(" ")[0]), - "pz": - float(alignment_yml[f"PDPanel{whichPanel}"]["position"] - [2].split(" ")[0]) - } + results_dict[f"v{alignment_num}"][f"R{whichRich}P{whichPanel}"] = { + "px": float( + alignment_yml[f"PDPanel{whichPanel}"]["position"][0].split(" ")[ + 0 + ] + ), + "py": float( + alignment_yml[f"PDPanel{whichPanel}"]["position"][1].split(" ")[ + 0 + ] + ), + "pz": float( + alignment_yml[f"PDPanel{whichPanel}"]["position"][2].split(" ")[ + 0 + ] + ), + } ### plot for whichRich in [1, 2]: - panel_names = ["top", "bottom" - ] if whichRich == 1 else ["ASide-left", "CSide-right"] + panel_names = ["top", "bottom"] if whichRich == 1 else ["ASide-left", "CSide-right"] for whichPanel in [0, 1]: - fig = plt.figure() # obtain each position for each alignment version in a list (e.g posx = [v1res,v2res,v3res,v4res]) xpos, ypos, zpos = [], [], [] xtick_labels = [] for alignment_num in n_aligments_list: - xpos.append(results_dict[f"v{alignment_num}"] - [f"R{whichRich}P{whichPanel}"]["px"]) - ypos.append(results_dict[f"v{alignment_num}"] - [f"R{whichRich}P{whichPanel}"]["py"]) - zpos.append(results_dict[f"v{alignment_num}"] - [f"R{whichRich}P{whichPanel}"]["pz"]) + xpos.append( + results_dict[f"v{alignment_num}"][f"R{whichRich}P{whichPanel}"]["px"] + ) + ypos.append( + results_dict[f"v{alignment_num}"][f"R{whichRich}P{whichPanel}"]["py"] + ) + zpos.append( + results_dict[f"v{alignment_num}"][f"R{whichRich}P{whichPanel}"]["pz"] + ) xtick_labels.append(f"v{alignment_num}") plt.scatter(range(len(xpos)), xpos, label="x", marker="s", color="red") - plt.scatter( - range(len(ypos)), ypos, label="y", marker="o", color="blue") - plt.scatter( - range(len(zpos)), zpos, label="z", marker="*", color="orange") + plt.scatter(range(len(ypos)), ypos, label="y", marker="o", color="blue") + plt.scatter(range(len(zpos)), zpos, label="z", marker="*", color="orange") plt.xticks(range(len(xtick_labels)), xtick_labels) diff --git a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/plot_cktheta.py b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/plot_cktheta.py index ab2654ff9caba77bbd7cbbb6a7b95cc51d646d9d..6a8b0c94d7960d191c983970b04051bc7a54f987 100644 --- a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/plot_cktheta.py +++ b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/plot_cktheta.py @@ -8,46 +8,49 @@ # granted to it by virtue of its status as an Intergovernmental Organization # # or submit itself to any jurisdiction. # ############################################################################### -import csv -import numpy as np -from matplotlib.backends.backend_pdf import PdfPages import argparse +import csv import json -from scipy.interpolate import griddata -import matplotlib.pyplot as plt +import matplotlib as mpl import matplotlib.colors as colors +import matplotlib.pyplot as plt +import numpy as np from matplotlib import cm +from matplotlib.backends.backend_pdf import PdfPages +from scipy.interpolate import griddata -import matplotlib as mpl -mpl.rcParams['savefig.dpi'] = 300 # Set the DPI to 300 +mpl.rcParams["savefig.dpi"] = 300 # Set the DPI to 300 parser = argparse.ArgumentParser() parser.add_argument( "--whichRich", - default='both', + default="both", type=str, - help="Set to both for both. Set to 1 for RICH1. Set to 2 for RICH2)") + help="Set to both for both. Set to 1 for RICH1. Set to 2 for RICH2)", +) parser.add_argument( "--whichPanel", - default='both', + default="both", type=str, - help="Set to both for both. Set to 0 for Panel0. Set to 1 for Panel1)") + help="Set to both for both. Set to 0 for Panel0. Set to 1 for Panel1)", +) parser.add_argument( "--survey_type", default="translation", choices=["translation", "rotation"], type=str, - help="Choose which survey study to plot") + help="Choose which survey study to plot", +) +parser.add_argument("--zoom", default="False", type=str, help="Set to True to zoom in") parser.add_argument( - "--zoom", default='False', type=str, help="Set to True to zoom in") + "--columns", default="False", type=str, help="Perform scans of columns" +) parser.add_argument( - '--columns', default='False', type=str, help='Perform scans of columns') -parser.add_argument( - '--twoD_scan', type=str, help='Perform 2D or 1D scans', default='False') -parser.add_argument( - "--csv_path", default="", help="path to csv file with results") + "--twoD_scan", type=str, help="Perform 2D or 1D scans", default="False" +) +parser.add_argument("--csv_path", default="", help="path to csv file with results") # parser.add_argument('--axis_name', type=str, default = "", help='Which axis to translate along or rotate about', choices = ["x", "y", "z", ""]) args = parser.parse_args() @@ -62,62 +65,45 @@ csv_path = args.csv_path ### load options from YAML from ruamel.yaml import YAML + yaml = YAML() # read -with open('survey_opts.yml') as opts_yml_file: +with open("survey_opts.yml") as opts_yml_file: yml_opts = yaml.load(opts_yml_file) perf_align = { - 'p0_x': yml_opts[f"R{whichRich}"]["P0"]["perf_trans"]["x"], - 'p1_x': yml_opts[f"R{whichRich}"]["P1"]["perf_trans"]["x"], - 'p0_y': yml_opts[f"R{whichRich}"]["P0"]["perf_trans"]["y"], - 'p1_y': yml_opts[f"R{whichRich}"]["P1"]["perf_trans"]["y"], - 'p0_z': yml_opts[f"R{whichRich}"]["P0"]["perf_trans"]["z"], - 'p1_z': yml_opts[f"R{whichRich}"]["P1"]["perf_trans"]["z"] + "p0_x": yml_opts[f"R{whichRich}"]["P0"]["perf_trans"]["x"], + "p1_x": yml_opts[f"R{whichRich}"]["P1"]["perf_trans"]["x"], + "p0_y": yml_opts[f"R{whichRich}"]["P0"]["perf_trans"]["y"], + "p1_y": yml_opts[f"R{whichRich}"]["P1"]["perf_trans"]["y"], + "p0_z": yml_opts[f"R{whichRich}"]["P0"]["perf_trans"]["z"], + "p1_z": yml_opts[f"R{whichRich}"]["P1"]["perf_trans"]["z"], } if ".csv" not in csv_path: stack_path = yml_opts["stack_path"] - prepath = f'{stack_path}/Panoptes/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys' - path_to_csvs = f'{prepath}/survey_results/{survey_type}/panel_{whichPanel}' + prepath = f"{stack_path}/Panoptes/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys" + path_to_csvs = f"{prepath}/survey_results/{survey_type}/panel_{whichPanel}" path_to_csvs = prepath # temp for now else: path_to_csvs = csv_path if survey_type == "translation": opt_pos = { - "R1": { - "x": [0.0, 0.0], - "y": [0.0, 0.0], - "z": [0.0, 0.0] - }, - "R2": { - "x": [0.0, 0.0], - "y": [0.0, 0.0], - "z": [0.0, 0.0] - } + "R1": {"x": [0.0, 0.0], "y": [0.0, 0.0], "z": [0.0, 0.0]}, + "R2": {"x": [0.0, 0.0], "y": [0.0, 0.0], "z": [0.0, 0.0]}, } if survey_type == "rotation": opt_pos = { - "R1": { - "x": [0.0, 0.0], - "y": [0.0, 0.0], - "z": [0.0, 0.0] - }, - "R2": { - "x": [0.0, 0.0], - "y": [0.0, 0.0], - "z": [0.0, 0.0] - } + "R1": {"x": [0.0, 0.0], "y": [0.0, 0.0], "z": [0.0, 0.0]}, + "R2": {"x": [0.0, 0.0], "y": [0.0, 0.0], "z": [0.0, 0.0]}, } -panel_names = ["top", "bottom" - ] if whichRich == 1 else ["ASide-left", "CSide-right"] +panel_names = ["top", "bottom"] if whichRich == 1 else ["ASide-left", "CSide-right"] def get_csv(rich, p_axis, path_to_csvs): - res_dict = {} # obtain axes and panel number split_p_axis = list(map(str, p_axis)) @@ -127,9 +113,11 @@ def get_csv(rich, p_axis, path_to_csvs): file_name = path_to_csvs else: if twoD_scan: - file_name = f'{path_to_csvs}/ck_vs_param_R{rich}_{survey_type}_panel{whichPanel}.csv' + file_name = f"{path_to_csvs}/ck_vs_param_R{rich}_{survey_type}_panel{whichPanel}.csv" else: - file_name = f'{path_to_csvs}/ck_vs_param_R{rich}_{survey_type}_panel{p_axis}.csv' + file_name = ( + f"{path_to_csvs}/ck_vs_param_R{rich}_{survey_type}_panel{p_axis}.csv" + ) import threading @@ -138,15 +126,15 @@ def get_csv(rich, p_axis, path_to_csvs): try: print(f"Reading file: \n {file_name}") - with open(file_name, 'r') as f: + with open(file_name, "r") as f: reader = csv.reader(f) plotting_vars = list(reader) except: print(f"File: {file_name} not found.") print("Setting Ckres to linspace of zeros") - res_dict[f'ckRes'] = np.zeros(30) - res_dict[f'ckRes_err'] = np.zeros(30) - res_dict[f'{survey_type}_{axes[0]}'] = np.zeros(30) + res_dict[f"ckRes"] = np.zeros(30) + res_dict[f"ckRes_err"] = np.zeros(30) + res_dict[f"{survey_type}_{axes[0]}"] = np.zeros(30) return res_dict lock.release() @@ -158,32 +146,30 @@ def get_csv(rich, p_axis, path_to_csvs): ck_gauss_mean_str = p_array[:, 3] if columns: col_num_str = p_array[:, 4] - res_dict[f'col_num'] = np.array(col_num_str, dtype=int) + res_dict[f"col_num"] = np.array(col_num_str, dtype=int) - res_dict[f'ckRes'] = np.array(ckRes_str, dtype=np.float32) - res_dict[f'ckRes_err'] = np.array(ckRes_err_str, dtype=np.float32) - res_dict[f'ck_gauss_mean'] = np.array(ck_gauss_mean_str, dtype=np.float32) + res_dict[f"ckRes"] = np.array(ckRes_str, dtype=np.float32) + res_dict[f"ckRes_err"] = np.array(ckRes_err_str, dtype=np.float32) + res_dict[f"ck_gauss_mean"] = np.array(ck_gauss_mean_str, dtype=np.float32) # TODO change this when I change the _ when writing results for axis in axes: - res_dict[f'{survey_type}_{axis}'] = [] + res_dict[f"{survey_type}_{axis}"] = [] for cond in conds_str: - cond_dict = { "p0_x": None, "p1_x": None, "p0_y": None, "p1_y": None, "p0_z": None, - "p1_z": None + "p1_z": None, } cond_split_str = cond.split(":") # store respective conditions from string - cond_dict["p0_x"] = cond_split_str[0].replace("p0_x", - "") # e.g p0_x-1.5 + cond_dict["p0_x"] = cond_split_str[0].replace("p0_x", "") # e.g p0_x-1.5 cond_dict["p1_x"] = cond_split_str[1].replace("p1_x", "") cond_dict["p0_y"] = cond_split_str[2].replace("p0_y", "") cond_dict["p1_y"] = cond_split_str[3].replace("p1_y", "") @@ -191,8 +177,7 @@ def get_csv(rich, p_axis, path_to_csvs): cond_dict["p1_z"] = cond_split_str[5].replace("p1_z", "") for axis in axes: - res_dict[f'{survey_type}_{axis}'].append( - float(cond_dict[f'p{p}_{axis}'])) + res_dict[f"{survey_type}_{axis}"].append(float(cond_dict[f"p{p}_{axis}"])) return res_dict @@ -200,9 +185,13 @@ def get_csv(rich, p_axis, path_to_csvs): if twoD_scan: def plot_2d_scan(res_dict, extra_text=""): - x, y, z, ck_gauss_mean, ck_res_err = res_dict[ - f'{survey_type}_x'], res_dict[f'{survey_type}_y'], res_dict[ - f'ckRes'], res_dict[f'ck_gauss_mean'], res_dict[f'ckRes_err'] + x, y, z, ck_gauss_mean, ck_res_err = ( + res_dict[f"{survey_type}_x"], + res_dict[f"{survey_type}_y"], + res_dict[f"ckRes"], + res_dict[f"ck_gauss_mean"], + res_dict[f"ckRes_err"], + ) gauss_mean_thres, default_value = 1, 2.5 print( @@ -210,17 +199,17 @@ if twoD_scan: ) x, y, z = [], [], [] bad_fit_counter = 0 - for i in range(0, len(res_dict[f'{survey_type}_y'])): - x.append(res_dict[f'{survey_type}_x'][i]) - y.append(res_dict[f'{survey_type}_y'][i]) - if (abs(res_dict[f'ck_gauss_mean'][i]) > gauss_mean_thres): + for i in range(0, len(res_dict[f"{survey_type}_y"])): + x.append(res_dict[f"{survey_type}_x"][i]) + y.append(res_dict[f"{survey_type}_y"][i]) + if abs(res_dict[f"ck_gauss_mean"][i]) > gauss_mean_thres: z.append(default_value) bad_fit_counter += 1 else: - z.append(res_dict['ckRes'][i]) + z.append(res_dict["ckRes"][i]) print( - f"Number of CKres fits with gaussian mean > {gauss_mean_thres}: {bad_fit_counter} ({bad_fit_counter/len(res_dict[f'{survey_type}_y'])*100} %)." + f"Number of CKres fits with gaussian mean > {gauss_mean_thres}: {bad_fit_counter} ({bad_fit_counter / len(res_dict[f'{survey_type}_y']) * 100} %)." ) if columns: @@ -238,10 +227,9 @@ if twoD_scan: xi = np.linspace(np.min(x), np.max(x), 1000) yi = np.linspace(np.min(y), np.max(y), 1000) - zi = griddata((x, y), z, (xi[None, :], yi[:, None]), method='linear') + zi = griddata((x, y), z, (xi[None, :], yi[:, None]), method="linear") - center_val = z[int( - 0.35 * len(z))] # center_val is at 35% of the colour bar + center_val = z[int(0.35 * len(z))] # center_val is at 35% of the colour bar if whichRich == 1 and whichPanel == 0: # center_val = 1.185 n_levels = 50 @@ -281,18 +269,24 @@ if twoD_scan: yi, zi, norm=norm, - # vmin = 0.0, vmax =2, - cmap='viridis', - levels=n_levels) + cmap="viridis", + levels=n_levels, + ) cbar = fig.colorbar(pcm) - cbar.set_label(r'$\sigma[\Delta\theta_{{\mathrm{{Cherenkov}}}}]$') + cbar.set_label(r"$\sigma[\Delta\theta_{{\mathrm{{Cherenkov}}}}]$") # add tick where current alignment lies ticks = cbar.get_ticks().tolist() # Get the default ticks as a list - alignment_index = next((i for i, (a, b) in enumerate(zip(x, y)) - if a == perf_align[f"p{whichPanel}_x"] - and b == perf_align[f"p{whichPanel}_y"]), None) + alignment_index = next( + ( + i + for i, (a, b) in enumerate(zip(x, y)) + if a == perf_align[f"p{whichPanel}_x"] + and b == perf_align[f"p{whichPanel}_y"] + ), + None, + ) if alignment_index is None: alignment_index = 0 @@ -307,57 +301,60 @@ if twoD_scan: # Find the "Current Alignment" tick label and set its color to red for label in cbar.ax.get_yticklabels(): if label.get_text() == "{:.3f}".format(z[alignment_index]): - label.set_color('r') + label.set_color("r") break # obtain minima and write ckres_min_index = np.where(z == min(z))[0][0] ckres_pot_improv = abs(z[alignment_index] - z[ckres_min_index]) - bbox_props = dict( - boxstyle='round,pad=0.3', fc='white', ec='gray', lw=1) + bbox_props = dict(boxstyle="round,pad=0.3", fc="white", ec="gray", lw=1) ax.text( 0.8, 0.97, - rf'Potential Improvement in $\sigma[\Delta\theta_{{\mathrm{{Cherenkov}}}}]$ = {"{:.4f}".format(ckres_pot_improv)} ({"{:.2f}".format(ckres_pot_improv/z[alignment_index]*100.0)}%)', + rf"Potential Improvement in $\sigma[\Delta\theta_{{\mathrm{{Cherenkov}}}}]$ = {'{:.4f}'.format(ckres_pot_improv)} ({'{:.2f}'.format(ckres_pot_improv / z[alignment_index] * 100.0)}%)", transform=fig.transFigure, - ha='right', - va='top', + ha="right", + va="top", fontsize=8, - bbox=bbox_props) + bbox=bbox_props, + ) if zoom: - ax.set_xlim(perf_align[f"p{whichPanel}_x"] - 3, - perf_align[f"p{whichPanel}_x"] + 3) - ax.set_ylim(perf_align[f"p{whichPanel}_y"] - 3, - perf_align[f"p{whichPanel}_y"] + 3) + ax.set_xlim( + perf_align[f"p{whichPanel}_x"] - 3, perf_align[f"p{whichPanel}_x"] + 3 + ) + ax.set_ylim( + perf_align[f"p{whichPanel}_y"] - 3, perf_align[f"p{whichPanel}_y"] + 3 + ) # ax.set_ylim(0.0,-10.5) # ax.set_xlim(-6,6) - ax.scatter(x, y, c='k', edgecolor="w", s=3) + ax.scatter(x, y, c="k", edgecolor="w", s=3) ax.scatter( perf_align[f"p{whichPanel}_x"], perf_align[f"p{whichPanel}_y"], - marker='*', + marker="*", s=40, c="red", - label="Current alignment") + label="Current alignment", + ) ax.scatter( x[ckres_min_index], y[ckres_min_index], - marker='*', + marker="*", s=40, c="m", - label="Update") + label="Update", + ) ax.legend() ax.set_xlabel("x (mm)") ax.set_ylabel("y (mm)") - ax.set_title( - f'RICH {whichRich} {panel_names[whichPanel]} {extra_text}') + ax.set_title(f"RICH {whichRich} {panel_names[whichPanel]} {extra_text}") fig.savefig( - f'CKRes_2DScan_R{whichRich}_{panel_names[whichPanel]}_{extra_text}_zoom_{zoom}.png' + f"CKRes_2DScan_R{whichRich}_{panel_names[whichPanel]}_{extra_text}_zoom_{zoom}.png" ) # print minima @@ -366,9 +363,8 @@ if twoD_scan: ) print(f"x: {x[ckres_min_index]} mm, y: {y[ckres_min_index]} mm") - res_dict = get_csv(whichRich, f'{whichPanel}xy', path_to_csvs) + res_dict = get_csv(whichRich, f"{whichPanel}xy", path_to_csvs) if columns: - # extract per column results if whichRich == 1: column_nums = [i for i in range(0, 11)] @@ -397,86 +393,79 @@ if twoD_scan: else: pdf = PdfPages( - f'RICH_paneltests_RICH-{whichRich}_panel-{whichPanel}_surveyType-{survey_type}_zoom-{zoom}.pdf' + f"RICH_paneltests_RICH-{whichRich}_panel-{whichPanel}_surveyType-{survey_type}_zoom-{zoom}.pdf" ) - x_res_dict = get_csv(whichRich, f'{whichPanel}x', path_to_csvs) - y_res_dict = get_csv(whichRich, f'{whichPanel}y', path_to_csvs) - z_res_dict = get_csv(whichRich, f'{whichPanel}z', path_to_csvs) + x_res_dict = get_csv(whichRich, f"{whichPanel}x", path_to_csvs) + y_res_dict = get_csv(whichRich, f"{whichPanel}y", path_to_csvs) + z_res_dict = get_csv(whichRich, f"{whichPanel}z", path_to_csvs) ncols = 1 nrows = 3 fig, ax = plt.subplots(figsize=(16, 16), nrows=nrows, ncols=ncols) -kwargs = {'fmt': '.', 'color': 'black'} +kwargs = {"fmt": ".", "color": "black"} axes_dict = { - "R1": { - "x": [None, None], - "y": [None, None], - "z": [None, None] - }, - "R2": { - "x": [None, None], - "y": [None, None], - "z": [None, None] - } + "R1": {"x": [None, None], "y": [None, None], "z": [None, None]}, + "R2": {"x": [None, None], "y": [None, None], "z": [None, None]}, } ax[0].errorbar( - x_res_dict[f'{survey_type}_x'], - x_res_dict[f'ckRes'], - yerr=x_res_dict[f'ckRes_err'], - label=f'Panel {whichPanel} x {survey_type}, RICH{whichRich}', - **kwargs) + x_res_dict[f"{survey_type}_x"], + x_res_dict[f"ckRes"], + yerr=x_res_dict[f"ckRes_err"], + label=f"Panel {whichPanel} x {survey_type}, RICH{whichRich}", + **kwargs, +) ax[1].errorbar( - y_res_dict[f'{survey_type}_y'], - y_res_dict[f'ckRes'], - yerr=y_res_dict[f'ckRes_err'], - label=f'Panel {whichPanel} y {survey_type}, RICH{whichRich}', - **kwargs) + y_res_dict[f"{survey_type}_y"], + y_res_dict[f"ckRes"], + yerr=y_res_dict[f"ckRes_err"], + label=f"Panel {whichPanel} y {survey_type}, RICH{whichRich}", + **kwargs, +) ax[2].errorbar( - z_res_dict[f'{survey_type}_z'], - z_res_dict[f'ckRes'], - yerr=z_res_dict[f'ckRes_err'], - label=f'Panel {whichPanel} z {survey_type}, RICH{whichRich}', - **kwargs) -axes_dict[f'R{whichRich}']["x"][whichPanel] = ax[0] -axes_dict[f'R{whichRich}']["y"][whichPanel] = ax[1] -axes_dict[f'R{whichRich}']["z"][whichPanel] = ax[2] + z_res_dict[f"{survey_type}_z"], + z_res_dict[f"ckRes"], + yerr=z_res_dict[f"ckRes_err"], + label=f"Panel {whichPanel} z {survey_type}, RICH{whichRich}", + **kwargs, +) +axes_dict[f"R{whichRich}"]["x"][whichPanel] = ax[0] +axes_dict[f"R{whichRich}"]["y"][whichPanel] = ax[1] +axes_dict[f"R{whichRich}"]["z"][whichPanel] = ax[2] subplot_counter = 0 subplot_threshold = 3 -for direction in axes_dict[f'R{whichRich}'].keys(): - +for direction in axes_dict[f"R{whichRich}"].keys(): for panel_num in [0, 1]: - - axs = axes_dict[f'R{whichRich}'][direction][panel_num] + axs = axes_dict[f"R{whichRich}"][direction][panel_num] if axs is None: plt.close() continue axs.legend(fontsize=22) - opt_pos_axs = opt_pos[f'R{whichRich}'][direction][panel_num] - axs.axvline(x=opt_pos_axs, ls='--', c='r') + opt_pos_axs = opt_pos[f"R{whichRich}"][direction][panel_num] + axs.axvline(x=opt_pos_axs, ls="--", c="r") if zoom: - if (whichRich == 1 and panel_num == 0): + if whichRich == 1 and panel_num == 0: axs.set_ylim(1, 1.2) - if ("z" in direction): + if "z" in direction: axs.set_ylim(0.8, 1.8) - if (whichRich == 1 and panel_num == 1): + if whichRich == 1 and panel_num == 1: axs.set_ylim(1.05, 1.25) - if ("z" in direction): + if "z" in direction: axs.set_ylim(0.8, 1.8) - if (whichRich == 2 and panel_num == 0): + if whichRich == 2 and panel_num == 0: axs.set_ylim(0.6, 0.7) - if ("z" in direction): + if "z" in direction: axs.set_ylim(0.5, 0.9) - if (whichRich == 2 and panel_num == 1): + if whichRich == 2 and panel_num == 1: axs.set_ylim(0.5, 0.66) - if ("z" in direction): + if "z" in direction: axs.set_ylim(0.5, 0.9) # if whichRich == 1: @@ -485,10 +474,10 @@ for direction in axes_dict[f'R{whichRich}'].keys(): # axs.set_ylim(0.4,0.9) if survey_type == "translation": - axs.set_xlabel('Panel alignment shift / mm', fontsize=20) + axs.set_xlabel("Panel alignment shift / mm", fontsize=20) if survey_type == "rotation": - axs.set_xlabel('Panel alignment rotation / mrad', fontsize=20) - axs.set_ylabel(r'$\theta_{C}$ resolution / mrad', fontsize=20) + axs.set_xlabel("Panel alignment rotation / mrad", fontsize=20) + axs.set_ylabel(r"$\theta_{C}$ resolution / mrad", fontsize=20) subplot_counter += 1 if subplot_counter == subplot_threshold: diff --git a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/survey_results/translation/panel_0/ck_vs_param_R1_translation_panel0z.csv b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/survey_results/translation/panel_0/ck_vs_param_R1_translation_panel0z.csv index e13334e7061b0bd96d385ef3d6059332ddba9aa9..c35b355c579a610d28ce93832f41bd4fb7bf4dc2 100644 --- a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/survey_results/translation/panel_0/ck_vs_param_R1_translation_panel0z.csv +++ b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/survey_results/translation/panel_0/ck_vs_param_R1_translation_panel0z.csv @@ -59,4 +59,3 @@ 0.8931342477006953,7.0,0.01142586098143703 0.892138521413545,7.25,0.011354917705202708 0.8936547549767824,7.5,0.011461073885705542 - diff --git a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/survey_results/translation/panel_both/ck_vs_param_R1_translation_panel0z.csv b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/survey_results/translation/panel_both/ck_vs_param_R1_translation_panel0z.csv index e13334e7061b0bd96d385ef3d6059332ddba9aa9..c35b355c579a610d28ce93832f41bd4fb7bf4dc2 100644 --- a/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/survey_results/translation/panel_both/ck_vs_param_R1_translation_panel0z.csv +++ b/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/PanelAlignment/surveys/survey_results/translation/panel_both/ck_vs_param_R1_translation_panel0z.csv @@ -59,4 +59,3 @@ 0.8931342477006953,7.0,0.01142586098143703 0.892138521413545,7.25,0.011354917705202708 0.8936547549767824,7.5,0.011461073885705542 - diff --git a/Rich/RichMirrorAlignmentOnline/files/XML_YAML_config/README.md b/Rich/RichMirrorAlignmentOnline/files/XML_YAML_config/README.md index ca0d9d27557787b33cc82d4b1c3ec2544b6f6e23..d42c50f2cdf62802fe03c16a133e2374ba69cf0e 100644 --- a/Rich/RichMirrorAlignmentOnline/files/XML_YAML_config/README.md +++ b/Rich/RichMirrorAlignmentOnline/files/XML_YAML_config/README.md @@ -2,8 +2,8 @@ ## Introduction The XML YAML conversions tool allows for quick conversions between XML and YAML. -This tool will take any XML or YAML file and output the data in the same location -with the same filename, but the opposite file type. +This tool will take any XML or YAML file and output the data in the same location +with the same filename, but the opposite file type. The conversion tool supports additional features: * A blocklist of items that should not be included in the output file @@ -12,8 +12,8 @@ The conversion tool supports additional features: * A custom yaml parser that allows the converter to parse custom yaml tags -**WARNING:** Do not parse or convert YAML files from untrusted sources. The -parser used in this tool has the ability to construct arbitrary python objects +**WARNING:** Do not parse or convert YAML files from untrusted sources. The +parser used in this tool has the ability to construct arbitrary python objects which may be harmful. ## REQUIREMENTS The tool requires a working version of Python 3 with additional modules: @@ -26,12 +26,12 @@ can be configured through the text files in "Configuration_files". ### Conversion Tool Conversion is a python object that handles all file conversions between XML and -YAML. The object is initiated as a class instance and can then be used to make -any necessary conversions. A XML <-> YAML conversions are run by calling -"conv_XML" and "conv_YAML" respectively and passing the relevant file path (see +YAML. The object is initiated as a class instance and can then be used to make +any necessary conversions. A XML <-> YAML conversions are run by calling +"conv_XML" and "conv_YAML" respectively and passing the relevant file path (see examples below). -**Note:** Conversion requires the user to add the absolute path to the directory +**Note:** Conversion requires the user to add the absolute path to the directory "Configuration_files" on line 5 in "convert_XML_YAML.py" prior to any use. #### Examples @@ -50,14 +50,14 @@ To convert a YAML file to XML the absolute file path is passed to conv_YAML: conversions_variable.conv_YAML(r"absolute_path_to_file_dir/filename.yml") ### Blocklist -The blocklist is a list of illegal node names that will be blocked when -converting. It is configured through the file "blocklist_config.txt" which -contains a list of names to ignore. Each new line in the document denotes a new -illegal node name, node beginning, node ending or node wildcard. Illegal node names are denoted -by typing in the full node name. Illegal node beginnings are denoted by typing in -the beginning followed by a "-". Illegal node endings are denoted by typing in -the ending and adding a "-" to the front of it. Illegal node wildcards are denoted by typing in a "*" -followed by the wildcard (if the node contains the wildcard string, the node will be removed). ```blisted_write_file``` can be set to ```True``` or ```False``` to write blocklisted conditions to file when converting from xml->yaml (to be added back when converting back to xml). ```reAdd_blocklisted_conditions``` can be set to ```True``` or ```False``` to re-add xml conditions which were removed when converting from xml->yaml (created with ```blisted_write_file = True```). +The blocklist is a list of illegal node names that will be blocked when +converting. It is configured through the file "blocklist_config.txt" which +contains a list of names to ignore. Each new line in the document denotes a new +illegal node name, node beginning, node ending or node wildcard. Illegal node names are denoted +by typing in the full node name. Illegal node beginnings are denoted by typing in +the beginning followed by a "-". Illegal node endings are denoted by typing in +the ending and adding a "-" to the front of it. Illegal node wildcards are denoted by typing in a "*" +followed by the wildcard (if the node contains the wildcard string, the node will be removed). ```blisted_write_file``` can be set to ```True``` or ```False``` to write blocklisted conditions to file when converting from xml->yaml (to be added back when converting back to xml). ```reAdd_blocklisted_conditions``` can be set to ```True``` or ```False``` to re-add xml conditions which were removed when converting from xml->yaml (created with ```blisted_write_file = True```). @@ -74,20 +74,20 @@ node name because it is used to define beginnings and endings (wildcards). * "*and" will block "and" and "hand" but not "And" ### Parameter and Unit conversions -The param_conversion_config.txt file contains translations for parameter names -and units between XML and YAML. Each line is defines a set containing the -parameter name in XML followed by a ":", then the base unit of that parameter in -XML followed by a ":", then the corresponding parameter in YAML followed by a -":", and finally the base unit of that parameter in YAML followed by a ":". +The param_conversion_config.txt file contains translations for parameter names +and units between XML and YAML. Each line is defines a set containing the +parameter name in XML followed by a ":", then the base unit of that parameter in +XML followed by a ":", then the corresponding parameter in YAML followed by a +":", and finally the base unit of that parameter in YAML followed by a ":". Everything after the 4th ":" on that line is ignored. -**Note:** If the values in the XML file have specified units when converting XML +**Note:** If the values in the XML file have specified units when converting XML -> YAML then this will be used instead of the XML base unit. ### Numerical Unit Conversions The unit_conversions_config.txt file contains the numerical conversions between -units. Each line contains the a unit symbol followed by a ":" then the dimensions -of the unit in base SI units followed by a ":" then the value of the unit -relative to its base unit followed by a ":". Everything after the 3rd ":" is +units. Each line contains the a unit symbol followed by a ":" then the dimensions +of the unit in base SI units followed by a ":" then the value of the unit +relative to its base unit followed by a ":". Everything after the 3rd ":" is ignored. **Note:** all unit names and SI unit names are case sensitive and whitespace is @@ -97,17 +97,16 @@ make sure that compatible units have IDENTICAL base units. * "mrad:rad:0.001:" a milliradian has its base in radians and is 0.001 radians * "rad:rad:1.0:" a radian has its base in radians and is 1.0 radians * "N:kg\*m\*s^2:1.0:" a newton has its base in kg*m*s^2 and is 1.0 kg*m*s^2 - * Note: "kg\*m\*s^2" will be interpreted differently from "kg m s^2" and + * Note: "kg\*m\*s^2" will be interpreted differently from "kg m s^2" and "kg\*m\*s\*s" as compatible base units must be identical. ### Custom YAML parser and tags The custom_tags.txt file contains a list of custom tags used in the YAML files where each line contains a single custom tag. -**Note:** The YAML parser will only work if all custom tags are added. +**Note:** The YAML parser will only work if all custom tags are added. ### Tacking on (or off) extra lines of text The ```tack_on_off``` function in ```objects.py``` prepends or appends (or removes) text to the start or end of the file. These lines are manually added in yaml_tack_on_Rich_X.txt or xml_tack_on_Rich_X.txt (where X = 1 or 2), stored in the Configuration folder (defined in ```config_path```). Setting ```tack_on == True``` tacks on the lines and setting ```tack_on == False``` removes the lines. - + * Everything below ```'---top'``` (and above ```'---bottom'```) will be prepended to the top of the file (or removed, if ```tack_on == False```). * Everything below ```'---bottom'``` will be appended to the bottom of the file (or removed, if ```tack_on == False```). - diff --git a/Rich/RichMirrorAlignmentOnline/files/XML_YAML_config/yaml_parser_config.txt b/Rich/RichMirrorAlignmentOnline/files/XML_YAML_config/yaml_parser_config.txt index 7e18bc5e7e912c78a2dc06d87b84bd3b3ecf89fa..7acfbdb8abbe08f1bc70bf28f8118d116cba94e8 100644 --- a/Rich/RichMirrorAlignmentOnline/files/XML_YAML_config/yaml_parser_config.txt +++ b/Rich/RichMirrorAlignmentOnline/files/XML_YAML_config/yaml_parser_config.txt @@ -1 +1 @@ -!alignment \ No newline at end of file +!alignment diff --git a/Rich/RichMirrorAlignmentOnline/files/ZeroDB/Rich2_Zeroed.xml b/Rich/RichMirrorAlignmentOnline/files/ZeroDB/Rich2_Zeroed.xml index 69a6f237091720d8c2a89b0e864a845968be1e29..8487874a7924501e78e5bf1c6faa0330ffd053cd 100644 --- a/Rich/RichMirrorAlignmentOnline/files/ZeroDB/Rich2_Zeroed.xml +++ b/Rich/RichMirrorAlignmentOnline/files/ZeroDB/Rich2_Zeroed.xml @@ -619,4 +619,3 @@ <paramVector name="dRotXYZ" type="double">0.0*mrad 0.0*mrad 0.0*mrad</paramVector> <paramVector name="pivotXYZ" type="double">84409*mm 0.0*mm 0.0*mm</paramVector> </condition> - diff --git a/Rich/RichMirrorAlignmentOnline/files/ZeroDB/Rich2_v45_converted_lastMagDown2018.yml b/Rich/RichMirrorAlignmentOnline/files/ZeroDB/Rich2_v45_converted_lastMagDown2018.yml index 9773a49fcc6fba92867a4da18877f4e596585894..50cb56c7b6dca2932b31a850417997083cc6f3b2 100644 --- a/Rich/RichMirrorAlignmentOnline/files/ZeroDB/Rich2_v45_converted_lastMagDown2018.yml +++ b/Rich/RichMirrorAlignmentOnline/files/ZeroDB/Rich2_v45_converted_lastMagDown2018.yml @@ -412,4 +412,3 @@ R2M2Seg39: !alignment pivot: [84409.0 * mm, 0.0 * mm, 0.0 * mm] position: [0.0 * mm, 0.0 * mm, 0.0 * mm] rotation: [0.0 * mrad, 0.03803 * mrad, -0.49929 * mrad] - diff --git a/Rich/RichMirrorAlignmentOnline/files/ZeroDB/Rich2_v48_converted_lastMagUp2018.yml b/Rich/RichMirrorAlignmentOnline/files/ZeroDB/Rich2_v48_converted_lastMagUp2018.yml index 1d06fc69632689c71864ef98eac1213b8f839a58..6a72cf1990e73e4bbf43665bc68f28143dec9163 100644 --- a/Rich/RichMirrorAlignmentOnline/files/ZeroDB/Rich2_v48_converted_lastMagUp2018.yml +++ b/Rich/RichMirrorAlignmentOnline/files/ZeroDB/Rich2_v48_converted_lastMagUp2018.yml @@ -412,4 +412,3 @@ R2M2Seg39: !alignment pivot: [84409.0 * mm, 0.0 * mm, 0.0 * mm] position: [0.0 * mm, 0.0 * mm, 0.0 * mm] rotation: [0.0 * mrad, 0.00855 * mrad, -0.54814 * mrad] - diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py index 01781b370e7dba3150b51f0d209a00f4a1f7071a..61eb43a16e700cbf2c574b17c772396cf70abbe0 100644 --- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py +++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py @@ -11,55 +11,78 @@ __authors__ = "Jake Reich, Claire Prouve, Paras Naik" __copyright__ = "University of Bristol, June 2023" -import sys, numpy -from ROOT import TH1D, TCanvas, TFile, TF1, gStyle, TGraph, TMultiGraph, TLine, TH2D, TExec -from ruamel.yaml import YAML import getpass +import sys + +import numpy from GaudiPython import gbl +from ROOT import ( + TF1, + TH1D, + TH2D, + TCanvas, + TExec, + TFile, + TGraph, + TLine, + TMultiGraph, + gStyle, +) +from ruamel.yaml import YAML class AlignMonitor: def __init__(self, _alignConf, _maxIt, flat=False): self.alignConf = _alignConf - self.nameStr = self.alignConf.getProp('nameStr') - self.whichRich = self.alignConf.getProp('Rich') - self.workdir = self.alignConf.getProp('WorkDir') + self.nameStr = self.alignConf.getProp("nameStr") + self.whichRich = self.alignConf.getProp("Rich") + self.workdir = self.alignConf.getProp("WorkDir") self.HistoDir = self.alignConf.getProp( - 'HistoDir' + "HistoDir" ) # PN: This will point to the directory to where we send the ROOT file with histograms for Monet self.runNumber = self.alignConf.getProp( - 'runNumber') # earliest run in fill (identifies the monet plots) - self.warningFactor = self.alignConf.getProp('warningFactor') + "runNumber" + ) # earliest run in fill (identifies the monet plots) + self.warningFactor = self.alignConf.getProp("warningFactor") self.maxIt = _maxIt # the maximum labeled number of the iterations that we are looping through yaml = YAML() - with open(self.workdir + '/' + 'rich' + str(self.whichRich) + - '_variant.yml') as finp: + with open( + self.workdir + "/" + "rich" + str(self.whichRich) + "_variant.yml" + ) as finp: variant = yaml.load(finp) self.prename = variant + "_histos_" # RICH1 settings self.maxpri = 3 self.binToPriMirr = [[2, 3], [0, 1]] self.maxsec = 15 - self.binToSecMirr = [[10, 11, 14, 15], [8, 9, 12, 13], [2, 3, 6, 7], - [0, 1, 4, 5]] + self.binToSecMirr = [ + [10, 11, 14, 15], + [8, 9, 12, 13], + [2, 3, 6, 7], + [0, 1, 4, 5], + ] self.fitMin = -0.007 self.fitMax = 0.007 # if RICH2, use RICH2 settings - if (self.whichRich == 2): + if self.whichRich == 2: self.maxpri = 55 - self.binToPriMirr = [[3, 2, 1, 0, 31, 30, 29, 28], - [7, 6, 5, 4, 35, 34, 33, 32], - [11, 10, 9, 8, 39, 38, 37, 36], - [15, 14, 13, 12, 43, 42, 41, 40], - [19, 18, 17, 16, 47, 46, 45, 44], - [23, 22, 21, 20, 51, 50, 49, 48], - [27, 26, 25, 24, 55, 54, 53, 52]] + self.binToPriMirr = [ + [3, 2, 1, 0, 31, 30, 29, 28], + [7, 6, 5, 4, 35, 34, 33, 32], + [11, 10, 9, 8, 39, 38, 37, 36], + [15, 14, 13, 12, 43, 42, 41, 40], + [19, 18, 17, 16, 47, 46, 45, 44], + [23, 22, 21, 20, 51, 50, 49, 48], + [27, 26, 25, 24, 55, 54, 53, 52], + ] self.maxsec = 39 - self.binToSecMirr = [[3, 2, 1, 0, 23, 22, 21, 20], - [7, 6, 5, 4, 27, 26, 25, 24], - [11, 10, 9, 8, 31, 30, 29, 28], - [15, 14, 13, 12, 35, 34, 33, 32], - [19, 18, 17, 16, 39, 38, 37, 36]] + self.binToSecMirr = [ + [3, 2, 1, 0, 23, 22, 21, 20], + [7, 6, 5, 4, 27, 26, 25, 24], + [11, 10, 9, 8, 31, 30, 29, 28], + [15, 14, 13, 12, 35, 34, 33, 32], + [19, 18, 17, 16, 39, 38, 37, 36], + ] self.fitMin = -0.0039 self.fitMax = 0.0035 self.flat = flat @@ -89,103 +112,199 @@ class AlignMonitor: def performMonitoring(self, compareFILE, forcedUpdate_ChMagPol): import os + gStyle.SetOptFit(1111) gStyle.SetOptStat(000000000) # File for the RICH piquet AND for the RICH mirror alignment experts - expertFile = self.workdir + 'Rich' + str( - self.whichRich) + '_AlignSummary.pdf' + expertFile = self.workdir + "Rich" + str(self.whichRich) + "_AlignSummary.pdf" # File for the Alignment piquet ("duplicating" what goes to the Presenter for the Data Manager [except CK angle res stuff]) - monitorFile = self.workdir + 'Rich' + str( - self.whichRich) + '_AlignMonitor.pdf' + monitorFile = self.workdir + "Rich" + str(self.whichRich) + "_AlignMonitor.pdf" if self.flat is False: # obtain file to store histograms for Monet - monetFile = self.HistoDir + "RichAlignMon-run" + str( - self.runNumber) + ".root" + monetFile = ( + self.HistoDir + "RichAlignMon-run" + str(self.runNumber) + ".root" + ) monetRootFile = TFile(monetFile, "UPDATE") - theCanvas = TCanvas('theCanvas', 'MirrAlign') + theCanvas = TCanvas("theCanvas", "MirrAlign") theCanvas.Divide(2, 2, 0.001, 0.001) - theCanvas2 = TCanvas('theCanvas2', 'MirrAlignTest') + theCanvas2 = TCanvas("theCanvas2", "MirrAlignTest") theCanvas2.Divide(2, 2, 0.001, 0.001) ######### Start of 2D histos section # heatHistos - from PyMirrAlignOnline.tiltObj import tiltObj # PN: this should also work offline if running in a Panoptes environment + from PyMirrAlignOnline.tiltObj import ( + tiltObj, # PN: this should also work offline if running in a Panoptes environment + ) + mirrtilts = [] for n_it in range(0, self.maxIt + 1): mirrtilts.append(tiltObj(self.alignConf)) - #iterationFILE = self.workdir + 'Rich' + str( + # iterationFILE = self.workdir + 'Rich' + str( # self.whichRich) + 'CondDBUpdate_' + self.nameStr + '_i' + str( # n_it + 1) yaml = YAML() - with open(self.workdir + '/' + 'rich' + str(self.whichRich) + - '_variant.yml') as finp: + with open( + self.workdir + "/" + "rich" + str(self.whichRich) + "_variant.yml" + ) as finp: variant = yaml.load(finp) iterationFILE = self.workdir + variant + "_conds_i" + str(n_it + 1) - #compare YAML to YAML, or XML to XML, depending on the format of compareFILE - if '.yml' in compareFILE: - iterationFILE += '.yml' + # compare YAML to YAML, or XML to XML, depending on the format of compareFILE + if ".yml" in compareFILE: + iterationFILE += ".yml" # fills mirrtilts with the exact change in mirror compensation from compareFILE to iterationFILE mirrtilts[n_it].setChangeYAML([compareFILE, iterationFILE]) else: - iterationFILE += '.xml' + iterationFILE += ".xml" # fills mirrtilts with the exact change in mirror compensation from compareFILE to iterationFILE mirrtilts[n_it].setChange([compareFILE, iterationFILE]) - if (self.whichRich == 1): + if self.whichRich == 1: heatHistoPriY = TH2D( - 'heatHistoPriY', 'RICH' + str(self.whichRich) + - ' Primary mirrors local Y rotation (mrad)', 2, -1, 1, 2, -1, 1) + "heatHistoPriY", + "RICH" + + str(self.whichRich) + + " Primary mirrors local Y rotation (mrad)", + 2, + -1, + 1, + 2, + -1, + 1, + ) heatHistoPriZ = TH2D( - 'heatHistoPriZ', 'RICH' + str(self.whichRich) + - ' Primary mirrors local Z rotation (mrad)', 2, -1, 1, 2, -1, 1) + "heatHistoPriZ", + "RICH" + + str(self.whichRich) + + " Primary mirrors local Z rotation (mrad)", + 2, + -1, + 1, + 2, + -1, + 1, + ) heatHistoSecY = TH2D( - 'heatHistoSecY', 'RICH' + str(self.whichRich) + - ' Secondary mirrors local Y rotation (mrad)', 4, -1, 1, 4, -1, - 1) + "heatHistoSecY", + "RICH" + + str(self.whichRich) + + " Secondary mirrors local Y rotation (mrad)", + 4, + -1, + 1, + 4, + -1, + 1, + ) heatHistoSecZ = TH2D( - 'heatHistoSecZ', 'RICH' + str(self.whichRich) + - ' Secondary mirrors local Z rotation (mrad)', 4, -1, 1, 4, -1, - 1) + "heatHistoSecZ", + "RICH" + + str(self.whichRich) + + " Secondary mirrors local Z rotation (mrad)", + 4, + -1, + 1, + 4, + -1, + 1, + ) numbersHistoPri = TH2D( - 'numbersHistoPri', - 'RICH' + str(self.whichRich) + ' Primary mirror numbers', 2, - -1, 1, 2, -1, 1) + "numbersHistoPri", + "RICH" + str(self.whichRich) + " Primary mirror numbers", + 2, + -1, + 1, + 2, + -1, + 1, + ) numbersHistoSec = TH2D( - 'numbersHistoSec', - 'RICH' + str(self.whichRich) + ' Secondary mirror numbers', 4, - -1, 1, 4, -1, 1) + "numbersHistoSec", + "RICH" + str(self.whichRich) + " Secondary mirror numbers", + 4, + -1, + 1, + 4, + -1, + 1, + ) - if (self.whichRich == 2): + if self.whichRich == 2: heatHistoPriY = TH2D( - 'heatHistoPriY', 'RICH' + str(self.whichRich) + - ' Primary mirrors local Y rotation (mrad)', 8, -1, 1, 7, -1, 1) + "heatHistoPriY", + "RICH" + + str(self.whichRich) + + " Primary mirrors local Y rotation (mrad)", + 8, + -1, + 1, + 7, + -1, + 1, + ) heatHistoPriZ = TH2D( - 'heatHistoPriZ', 'RICH' + str(self.whichRich) + - ' Primary mirrors local Z rotation (mrad)', 8, -1, 1, 7, -1, 1) + "heatHistoPriZ", + "RICH" + + str(self.whichRich) + + " Primary mirrors local Z rotation (mrad)", + 8, + -1, + 1, + 7, + -1, + 1, + ) heatHistoSecY = TH2D( - 'heatHistoSecY', 'RICH' + str(self.whichRich) + - ' Secondary mirrors local Y rotation (mrad)', 8, -1, 1, 5, -1, - 1) + "heatHistoSecY", + "RICH" + + str(self.whichRich) + + " Secondary mirrors local Y rotation (mrad)", + 8, + -1, + 1, + 5, + -1, + 1, + ) heatHistoSecZ = TH2D( - 'heatHistoSecZ', 'RICH' + str(self.whichRich) + - ' Secondary mirrors local Z rotation (mrad)', 8, -1, 1, 5, -1, - 1) + "heatHistoSecZ", + "RICH" + + str(self.whichRich) + + " Secondary mirrors local Z rotation (mrad)", + 8, + -1, + 1, + 5, + -1, + 1, + ) numbersHistoPri = TH2D( - 'numbersHistoPri', - 'RICH' + str(self.whichRich) + ' Primary mirror numbers', 8, - -1, 1, 7, -1, 1) + "numbersHistoPri", + "RICH" + str(self.whichRich) + " Primary mirror numbers", + 8, + -1, + 1, + 7, + -1, + 1, + ) numbersHistoSec = TH2D( - 'numbersHistoSec', - 'RICH' + str(self.whichRich) + ' Secondary mirror numbers', 8, - -1, 1, 5, -1, 1) + "numbersHistoSec", + "RICH" + str(self.whichRich) + " Secondary mirror numbers", + 8, + -1, + 1, + 5, + -1, + 1, + ) - xTitle = 'relative global X position (not to scale)' - yTitle = 'relative global Y position (not to scale)' + xTitle = "relative global X position (not to scale)" + yTitle = "relative global Y position (not to scale)" heatHistoPriY.SetXTitle(xTitle) heatHistoPriY.SetYTitle(yTitle) heatHistoSecY.SetXTitle(xTitle) @@ -199,7 +318,8 @@ class AlignMonitor: numbersHistoSec.SetXTitle(xTitle) numbersHistoSec.SetYTitle(yTitle) - self.origMarkerSize = heatHistoPriY.GetMarkerSize( + self.origMarkerSize = ( + heatHistoPriY.GetMarkerSize() ) # default MarkerSize should be same for all histos # Flexible Range Color scheme before 2017 June 19 @@ -216,20 +336,84 @@ class AlignMonitor: # 600 = kBlue # 602 = kBlue + 2 self.colorsLow = [ - 602, 602, 602, 602, 602, 602, 602, 602, 602, 602, 602, 602, 602, - 602, 602, 602, 602, 602 + 602, + 602, + 602, + 602, + 602, + 602, + 602, + 602, + 602, + 602, + 602, + 602, + 602, + 602, + 602, + 602, + 602, + 602, ] self.colorsLow += [ - 602, 602, 602, 602, 602, 602, 602, 602, 602, 602, 602, 602, 602, - 602, 600, 857, 867, 416 + 602, + 602, + 602, + 602, + 602, + 602, + 602, + 602, + 602, + 602, + 602, + 602, + 602, + 602, + 600, + 857, + 867, + 416, ] self.colorsHigh = [ - 416, 400, 797, 632, 634, 634, 634, 634, 634, 634, 634, 634, 634, - 634, 634, 634, 634, 634 + 416, + 400, + 797, + 632, + 634, + 634, + 634, + 634, + 634, + 634, + 634, + 634, + 634, + 634, + 634, + 634, + 634, + 634, ] self.colorsHigh += [ - 634, 634, 634, 634, 634, 634, 634, 634, 634, 634, 634, 634, 634, - 634, 634, 634, 634, 634 + 634, + 634, + 634, + 634, + 634, + 634, + 634, + 634, + 634, + 634, + 634, + 634, + 634, + 634, + 634, + 634, + 634, + 634, ] colorsListFlex = self.colorsLow + self.colorsHigh @@ -240,10 +424,10 @@ class AlignMonitor: # RichMirrCombinFit and/or RichMirrAlign, then print them to a file and # pick them up in RichMirrAlign and/or RichMirrorAlignmentOnline (via setProp). # For now, we just use the stopTolerances from the Configuration in all cases. - self.sTPY = float(self.alignConf.getProp('stopTolerancePriY')) - self.sTPZ = float(self.alignConf.getProp('stopTolerancePriZ')) - self.sTSY = float(self.alignConf.getProp('stopToleranceSecY')) - self.sTSZ = float(self.alignConf.getProp('stopToleranceSecZ')) + self.sTPY = float(self.alignConf.getProp("stopTolerancePriY")) + self.sTPZ = float(self.alignConf.getProp("stopTolerancePriZ")) + self.sTSY = float(self.alignConf.getProp("stopToleranceSecY")) + self.sTSZ = float(self.alignConf.getProp("stopToleranceSecZ")) biggestTilt = [None] * (self.maxIt + 1) for n_it in reversed(range(0, self.maxIt + 1)): @@ -255,31 +439,47 @@ class AlignMonitor: colsPri = len(self.binToPriMirr[0]) for row in range(rowsPri): for col in range(colsPri): - #truncated, not rounded + # truncated, not rounded heatHistoPriY.SetBinContent( - col + 1, row + 1, - mirrtilts[n_it].priYtrunc[self.binToPriMirr[row][col]]) + col + 1, + row + 1, + mirrtilts[n_it].priYtrunc[self.binToPriMirr[row][col]], + ) heatHistoPriZ.SetBinContent( - col + 1, row + 1, - mirrtilts[n_it].priZtrunc[self.binToPriMirr[row][col]]) + col + 1, + row + 1, + mirrtilts[n_it].priZtrunc[self.binToPriMirr[row][col]], + ) numbersHistoPri.SetBinContent( - col + 1, row + 1, self.binToPriMirr[row][col] - if self.binToPriMirr[row][col] != 0 else 0.0000001) + col + 1, + row + 1, + self.binToPriMirr[row][col] + if self.binToPriMirr[row][col] != 0 + else 0.0000001, + ) rowsSec = len(self.binToSecMirr) colsSec = len(self.binToSecMirr[0]) for row in range(rowsSec): for col in range(colsSec): - #truncated, not rounded + # truncated, not rounded heatHistoSecY.SetBinContent( - col + 1, row + 1, - mirrtilts[n_it].secYtrunc[self.binToSecMirr[row][col]]) + col + 1, + row + 1, + mirrtilts[n_it].secYtrunc[self.binToSecMirr[row][col]], + ) heatHistoSecZ.SetBinContent( - col + 1, row + 1, - mirrtilts[n_it].secZtrunc[self.binToSecMirr[row][col]]) + col + 1, + row + 1, + mirrtilts[n_it].secZtrunc[self.binToSecMirr[row][col]], + ) numbersHistoSec.SetBinContent( - col + 1, row + 1, self.binToSecMirr[row][col] - if self.binToSecMirr[row][col] != 0 else 0.0000001) + col + 1, + row + 1, + self.binToSecMirr[row][col] + if self.binToSecMirr[row][col] != 0 + else 0.0000001, + ) # Get the absolute value of the maximum tilt in any plot, # this lets us set the scales only as relevant, @@ -291,42 +491,44 @@ class AlignMonitor: if not forcedUpdate_ChMagPol: crazy = self.warningFactor else: - #PN: Note to self... we may want to de-hardcode expandCrazyFactor. + # PN: Note to self... we may want to de-hardcode expandCrazyFactor. expandCrazyFactor = 2 # The choice of expandCrazyFactor is completely arbitrary, and should be re-evaluated later. crazy = expandCrazyFactor * self.warningFactor - if biggestTilt[n_it][0] >= crazy * self.sTPY or biggestTilt[ - n_it][1] >= crazy * self.sTPZ or biggestTilt[n_it][ - 2] >= crazy * self.sTSY or biggestTilt[n_it][ - 3] >= crazy * self.sTSZ: + if ( + biggestTilt[n_it][0] >= crazy * self.sTPY + or biggestTilt[n_it][1] >= crazy * self.sTPZ + or biggestTilt[n_it][2] >= crazy * self.sTSY + or biggestTilt[n_it][3] >= crazy * self.sTSZ + ): self.isInsane = True # Flexible range plotting style for self.nFlex in reversed(range(0, 35)): - if biggestTilt[n_it][ - 0] >= self.nFlex * self.sTPY or biggestTilt[n_it][ - 1] >= self.nFlex * self.sTPZ or biggestTilt[n_it][ - 2] >= self.nFlex * self.sTSY or biggestTilt[ - n_it][3] >= self.nFlex * self.sTSZ: + if ( + biggestTilt[n_it][0] >= self.nFlex * self.sTPY + or biggestTilt[n_it][1] >= self.nFlex * self.sTPZ + or biggestTilt[n_it][2] >= self.nFlex * self.sTSY + or biggestTilt[n_it][3] >= self.nFlex * self.sTSZ + ): break # max: heatHistoPriY.GetZaxis().SetRangeUser(-36*self.sTPY, 36*self.sTPY) heatHistoPriY.GetZaxis().SetRangeUser( - (self.nFlex + 2) * (0 - self.sTPY), - (self.nFlex + 2) * (self.sTPY)) + (self.nFlex + 2) * (0 - self.sTPY), (self.nFlex + 2) * (self.sTPY) + ) heatHistoPriZ.GetZaxis().SetRangeUser( - (self.nFlex + 2) * (0 - self.sTPZ), - (self.nFlex + 2) * (self.sTPZ)) + (self.nFlex + 2) * (0 - self.sTPZ), (self.nFlex + 2) * (self.sTPZ) + ) heatHistoSecY.GetZaxis().SetRangeUser( - (self.nFlex + 2) * (0 - self.sTSY), - (self.nFlex + 2) * (self.sTSY)) + (self.nFlex + 2) * (0 - self.sTSY), (self.nFlex + 2) * (self.sTSY) + ) heatHistoSecZ.GetZaxis().SetRangeUser( - (self.nFlex + 2) * (0 - self.sTSZ), - (self.nFlex + 2) * (self.sTSZ)) + (self.nFlex + 2) * (0 - self.sTSZ), (self.nFlex + 2) * (self.sTSZ) + ) colorsLowClone = list(self.colorsLow) colorsLowClone.reverse() - colorsLowSubset = list(colorsLowClone[0:self.nFlex + 2]) + colorsLowSubset = list(colorsLowClone[0 : self.nFlex + 2]) colorsLowSubset.reverse() - colorsListFlex = list(colorsLowSubset + - self.colorsHigh[0:self.nFlex + 2]) + colorsListFlex = list(colorsLowSubset + self.colorsHigh[0 : self.nFlex + 2]) levelsPY = [] levelsPZ = [] levelsSY = [] @@ -339,19 +541,20 @@ class AlignMonitor: levelsSZ += [i * self.sTSZ] gStyle.SetPalette( len(list(colorsListFlex)), - numpy.array(list(colorsListFlex), dtype='intc')) + numpy.array(list(colorsListFlex), dtype="intc"), + ) heatHistoPriY.SetContour( - len(list(levelsPY)), - numpy.array(list(levelsPY), dtype='float64')) + len(list(levelsPY)), numpy.array(list(levelsPY), dtype="float64") + ) heatHistoPriZ.SetContour( - len(list(levelsPZ)), - numpy.array(list(levelsPZ), dtype='float64')) + len(list(levelsPZ)), numpy.array(list(levelsPZ), dtype="float64") + ) heatHistoSecY.SetContour( - len(list(levelsSY)), - numpy.array(list(levelsSY), dtype='float64')) + len(list(levelsSY)), numpy.array(list(levelsSY), dtype="float64") + ) heatHistoSecZ.SetContour( - len(list(levelsSZ)), - numpy.array(list(levelsSZ), dtype='float64')) + len(list(levelsSZ)), numpy.array(list(levelsSZ), dtype="float64") + ) heatHistoPriY.SetMarkerSize(1.8 * self.origMarkerSize) heatHistoPriZ.SetMarkerSize(1.8 * self.origMarkerSize) heatHistoSecY.SetMarkerSize(1.8 * self.origMarkerSize) @@ -365,35 +568,38 @@ class AlignMonitor: numbersHistoPri.SetBarOffset(0.175) numbersHistoSec.SetBarOffset(0.175) heatHistoPriY.SetTitle( - '#splitline{RICH' + str(self.whichRich) + - ' Primary mirrors local Y rotation (mrad) after It. ' + - str(n_it) + - '}{Values truncated, not rounded. Mirror number displayed smaller.}' + "#splitline{RICH" + + str(self.whichRich) + + " Primary mirrors local Y rotation (mrad) after It. " + + str(n_it) + + "}{Values truncated, not rounded. Mirror number displayed smaller.}" ) heatHistoPriZ.SetTitle( - '#splitline{RICH' + str(self.whichRich) + - ' Primary mirrors local Z rotation (mrad) after It. ' + - str(n_it) + - '}{Values truncated, not rounded. Mirror number displayed smaller.}' + "#splitline{RICH" + + str(self.whichRich) + + " Primary mirrors local Z rotation (mrad) after It. " + + str(n_it) + + "}{Values truncated, not rounded. Mirror number displayed smaller.}" ) heatHistoSecY.SetTitle( - '#splitline{RICH' + str(self.whichRich) + - ' Secondary mirrors local Y rotation (mrad) after It. ' + - str(n_it) + - '}{Values truncated, not rounded. Mirror number displayed smaller.}' + "#splitline{RICH" + + str(self.whichRich) + + " Secondary mirrors local Y rotation (mrad) after It. " + + str(n_it) + + "}{Values truncated, not rounded. Mirror number displayed smaller.}" ) heatHistoSecZ.SetTitle( - '#splitline{RICH' + str(self.whichRich) + - ' Secondary mirrors local Z rotation (mrad) after It. ' + - str(n_it) + - '}{Values truncated, not rounded. Mirror number displayed smaller.}' + "#splitline{RICH" + + str(self.whichRich) + + " Secondary mirrors local Z rotation (mrad) after It. " + + str(n_it) + + "}{Values truncated, not rounded. Mirror number displayed smaller.}" ) # we need TExec in order to have multiple text formats drawn on the same TPad execStyle1 = TExec( - "execStyle1", - "gStyle->SetPaintTextFormat(\"4.2f\");") # formerly 5.3f - execStyle2 = TExec("execStyle2", - "gStyle->SetPaintTextFormat(\"2.0f\");") + "execStyle1", 'gStyle->SetPaintTextFormat("4.2f");' + ) # formerly 5.3f + execStyle2 = TExec("execStyle2", 'gStyle->SetPaintTextFormat("2.0f");') theCanvas.cd(1) heatHistoPriY.Draw("COLZ") @@ -425,55 +631,68 @@ class AlignMonitor: execStyle2.Draw() numbersHistoSec.Draw("TEXT SAME") - theCanvas.Print(expertFile + '(') + theCanvas.Print(expertFile + "(") ############# # Compensations-divided-by-tolerances Histograms # sets priYdiv, etc... otherwise these will be empty mirrtilts[n_it].setDiv( - tolerances=[self.sTPY, self.sTPZ, self.sTSY, self.sTSZ]) + tolerances=[self.sTPY, self.sTPZ, self.sTSY, self.sTSZ] + ) rowsPri = len(self.binToPriMirr) colsPri = len(self.binToPriMirr[0]) for row in range(rowsPri): for col in range(colsPri): - #truncated, not rounded + # truncated, not rounded heatHistoPriY.SetBinContent( - col + 1, row + 1, - mirrtilts[n_it].priYdiv[self.binToPriMirr[row][col]]) + col + 1, + row + 1, + mirrtilts[n_it].priYdiv[self.binToPriMirr[row][col]], + ) heatHistoPriZ.SetBinContent( - col + 1, row + 1, - mirrtilts[n_it].priZdiv[self.binToPriMirr[row][col]]) + col + 1, + row + 1, + mirrtilts[n_it].priZdiv[self.binToPriMirr[row][col]], + ) rowsSec = len(self.binToSecMirr) colsSec = len(self.binToSecMirr[0]) for row in range(rowsSec): for col in range(colsSec): - #truncated, not rounded + # truncated, not rounded heatHistoSecY.SetBinContent( - col + 1, row + 1, - mirrtilts[n_it].secYdiv[self.binToSecMirr[row][col]]) + col + 1, + row + 1, + mirrtilts[n_it].secYdiv[self.binToSecMirr[row][col]], + ) heatHistoSecZ.SetBinContent( - col + 1, row + 1, - mirrtilts[n_it].secZdiv[self.binToSecMirr[row][col]]) + col + 1, + row + 1, + mirrtilts[n_it].secZdiv[self.binToSecMirr[row][col]], + ) # Flexible range plotting style # self.nFlex should be unchanged from previous determination. # max: heatHistoPriY.GetZaxis().SetRangeUser(-36*1, 36*1) - heatHistoPriY.GetZaxis().SetRangeUser((self.nFlex + 2) * (0 - 1), - (self.nFlex + 2) * (1)) - heatHistoPriZ.GetZaxis().SetRangeUser((self.nFlex + 2) * (0 - 1), - (self.nFlex + 2) * (1)) - heatHistoSecY.GetZaxis().SetRangeUser((self.nFlex + 2) * (0 - 1), - (self.nFlex + 2) * (1)) - heatHistoSecZ.GetZaxis().SetRangeUser((self.nFlex + 2) * (0 - 1), - (self.nFlex + 2) * (1)) + heatHistoPriY.GetZaxis().SetRangeUser( + (self.nFlex + 2) * (0 - 1), (self.nFlex + 2) * (1) + ) + heatHistoPriZ.GetZaxis().SetRangeUser( + (self.nFlex + 2) * (0 - 1), (self.nFlex + 2) * (1) + ) + heatHistoSecY.GetZaxis().SetRangeUser( + (self.nFlex + 2) * (0 - 1), (self.nFlex + 2) * (1) + ) + heatHistoSecZ.GetZaxis().SetRangeUser( + (self.nFlex + 2) * (0 - 1), (self.nFlex + 2) * (1) + ) levelsPY = [] levelsPZ = [] levelsSY = [] levelsSZ = [] - #max: for i in range(-(36),(36)+1): + # max: for i in range(-(36),(36)+1): for i in range(-(self.nFlex + 2), (self.nFlex + 2) + 1): levelsPY += [i * 1] levelsPZ += [i * 1] @@ -481,19 +700,20 @@ class AlignMonitor: levelsSZ += [i * 1] gStyle.SetPalette( len(list(colorsListFlex)), - numpy.array(list(colorsListFlex), dtype='intc')) + numpy.array(list(colorsListFlex), dtype="intc"), + ) heatHistoPriY.SetContour( - len(list(levelsPY)), - numpy.array(list(levelsPY), dtype='float64')) + len(list(levelsPY)), numpy.array(list(levelsPY), dtype="float64") + ) heatHistoPriZ.SetContour( - len(list(levelsPZ)), - numpy.array(list(levelsPZ), dtype='float64')) + len(list(levelsPZ)), numpy.array(list(levelsPZ), dtype="float64") + ) heatHistoSecY.SetContour( - len(list(levelsSY)), - numpy.array(list(levelsSY), dtype='float64')) + len(list(levelsSY)), numpy.array(list(levelsSY), dtype="float64") + ) heatHistoSecZ.SetContour( - len(list(levelsSZ)), - numpy.array(list(levelsSZ), dtype='float64')) + len(list(levelsSZ)), numpy.array(list(levelsSZ), dtype="float64") + ) heatHistoPriY.SetMarkerSize(1.8 * self.origMarkerSize) heatHistoPriZ.SetMarkerSize(1.8 * self.origMarkerSize) heatHistoSecY.SetMarkerSize(1.8 * self.origMarkerSize) @@ -507,31 +727,35 @@ class AlignMonitor: numbersHistoPri.SetBarOffset(0.175) numbersHistoSec.SetBarOffset(0.175) heatHistoPriY.SetTitle( - '#splitline{RICH' + str(self.whichRich) + - ' Primary mirrors local Y rotation divided by tolerance, after It. ' - + str(n_it) + - '}{Values truncated, not rounded. Mirror number displayed smaller.}' + "#splitline{RICH" + + str(self.whichRich) + + " Primary mirrors local Y rotation divided by tolerance, after It. " + + str(n_it) + + "}{Values truncated, not rounded. Mirror number displayed smaller.}" ) heatHistoPriZ.SetTitle( - '#splitline{RICH' + str(self.whichRich) + - ' Primary mirrors local Z rotation divided by tolerance, after It. ' - + str(n_it) + - '}{Values truncated, not rounded. Mirror number displayed smaller.}' + "#splitline{RICH" + + str(self.whichRich) + + " Primary mirrors local Z rotation divided by tolerance, after It. " + + str(n_it) + + "}{Values truncated, not rounded. Mirror number displayed smaller.}" ) heatHistoSecY.SetTitle( - '#splitline{RICH' + str(self.whichRich) + - ' Secondary mirrors local Y rotation divided by tolerance, after It. ' - + str(n_it) + - '}{Values truncated, not rounded. Mirror number displayed smaller.}' + "#splitline{RICH" + + str(self.whichRich) + + " Secondary mirrors local Y rotation divided by tolerance, after It. " + + str(n_it) + + "}{Values truncated, not rounded. Mirror number displayed smaller.}" ) heatHistoSecZ.SetTitle( - '#splitline{RICH' + str(self.whichRich) + - ' Secondary mirrors local Z rotation divided by tolerance, after It. ' - + str(n_it) + - '}{Values truncated, not rounded. Mirror number displayed smaller.}' + "#splitline{RICH" + + str(self.whichRich) + + " Secondary mirrors local Z rotation divided by tolerance, after It. " + + str(n_it) + + "}{Values truncated, not rounded. Mirror number displayed smaller.}" ) - gStyle.SetPaintTextFormat('2.0f') + gStyle.SetPaintTextFormat("2.0f") theCanvas.cd(1) heatHistoPriY.Draw("COLZ") heatHistoPriY.Draw("TEXT SAME") @@ -550,19 +774,21 @@ class AlignMonitor: numbersHistoSec.Draw("TEXT SAME") if n_it == self.maxIt: - theCanvas.Print(monitorFile) if self.flat is False: - monetRootFile.WriteTObject( - heatHistoPriY, f"RICH{self.whichRich}_heatHistoPriY") + heatHistoPriY, f"RICH{self.whichRich}_heatHistoPriY" + ) monetRootFile.WriteTObject( - heatHistoPriZ, f"RICH{self.whichRich}_heatHistoPriZ") + heatHistoPriZ, f"RICH{self.whichRich}_heatHistoPriZ" + ) monetRootFile.WriteTObject( - heatHistoSecY, f"RICH{self.whichRich}_heatHistoSecY") + heatHistoSecY, f"RICH{self.whichRich}_heatHistoSecY" + ) monetRootFile.WriteTObject( - heatHistoSecZ, f"RICH{self.whichRich}_heatHistoSecZ") + heatHistoSecZ, f"RICH{self.whichRich}_heatHistoSecZ" + ) # Commented out stuff below is for the Run 2 Monet setup """ @@ -611,10 +837,9 @@ class AlignMonitor: sys.stdout.flush() + ############# -############# - -# End of 2D histos section ############# + # End of 2D histos section ############# theCanvas2.Clear() theCanvas.Clear() @@ -654,96 +879,79 @@ class AlignMonitor: "histFunc": [None] * (self.maxIt + 1), "hist": [None] * (self.maxIt + 1), "fitRes": [None] * (self.maxIt + 1), - "resHistoTrend": - TH1D( - 'resHistoTrend', 'RICH' + str(self.whichRich) + - ' Cherenkov angle resolution (mrad) per It. ', self.maxIt + 1, - -0.5, self.maxIt + 0.5) + "resHistoTrend": TH1D( + "resHistoTrend", + "RICH" + + str(self.whichRich) + + " Cherenkov angle resolution (mrad) per It. ", + self.maxIt + 1, + -0.5, + self.maxIt + 0.5, + ), } import copy + histos = { # all PMTs in RICH1 are small (R-type) "RICH1": { - "columns": { - "top": {}, - "bottom": {} - }, + "columns": {"top": {}, "bottom": {}}, "allCkres": copy.deepcopy(default_column_histo_dict), - "dThetavsPhi": { - "top": None, - "bottom": None - } + "dThetavsPhi": {"top": None, "bottom": None}, }, "RICH2": { - "columns": { - "ASide-left": {}, - "CSide-right": {} - }, - "columns_Rtype": { - "ASide-left": {}, - "CSide-right": {} - }, - "columns_Htype": { - "ASide-left": {}, - "CSide-right": {} - }, + "columns": {"ASide-left": {}, "CSide-right": {}}, + "columns_Rtype": {"ASide-left": {}, "CSide-right": {}}, + "columns_Htype": {"ASide-left": {}, "CSide-right": {}}, "Rtype": copy.deepcopy(default_column_histo_dict), "Htype": copy.deepcopy(default_column_histo_dict), "allCkres": copy.deepcopy(default_column_histo_dict), - "dThetavsPhi": { - "ASide-left": None, - "CSide-right": None - } - } + "dThetavsPhi": {"ASide-left": None, "CSide-right": None}, + }, } # define arrays with column numbers for each RICH column_nums = { "RICH1": [i for i in range(0, 11)], - "RICH2": [i for i in range(1, 13)] + "RICH2": [i for i in range(1, 13)], } # define panels names - panel_names = ["top", "bottom"] if self.whichRich == 1 else [ - "ASide-left", "CSide-right" - ] + panel_names = ( + ["top", "bottom"] if self.whichRich == 1 else ["ASide-left", "CSide-right"] + ) # create histos for each column for column_num in column_nums[f"RICH{self.whichRich}"]: for panel_name in panel_names: histos[f"RICH{self.whichRich}"]["columns"][panel_name][ - f"col{column_num}"] = copy.deepcopy( - default_column_histo_dict) + f"col{column_num}" + ] = copy.deepcopy(default_column_histo_dict) if self.whichRich == 2: - histos[f"RICH{self.whichRich}"]["columns_Rtype"][ - panel_name][f"col{column_num}"] = copy.deepcopy( - default_column_histo_dict) - histos[f"RICH{self.whichRich}"]["columns_Htype"][ - panel_name][f"col{column_num}"] = copy.deepcopy( - default_column_histo_dict) + histos[f"RICH{self.whichRich}"]["columns_Rtype"][panel_name][ + f"col{column_num}" + ] = copy.deepcopy(default_column_histo_dict) + histos[f"RICH{self.whichRich}"]["columns_Htype"][panel_name][ + f"col{column_num}" + ] = copy.deepcopy(default_column_histo_dict) # define placeholder_histogram placeholder_histogram = TH1D("placeholder", "placeholder", 100, 0, 1) placeholder_histogram.SetStats(0) for j in reversed(range(0, self.maxIt + 1)): - filename[j] = self.workdir + '/' + self.prename + 'i' + str( - j) + '.root' + filename[j] = self.workdir + "/" + self.prename + "i" + str(j) + ".root" if os.path.exists(filename[j]): - thisFile[j] = TFile(filename[j], 'read') + thisFile[j] = TFile(filename[j], "read") def plot_ckres(hist_path, hist_dict, j): - try: - hist_dict["hist"][j] = ( - thisFile[j].Get(hist_path).Clone()) + hist_dict["hist"][j] = thisFile[j].Get(hist_path).Clone() except: print( f"INFO: {hist_path} not produced in {filename[j]} . Skipping..." ) return None - title[j] = hist_dict["hist"][j].GetTitle() + " It. " + str( - j) + title[j] = hist_dict["hist"][j].GetTitle() + " It. " + str(j) # check if enough entries to perform fit integral_threshold = 1100.0 @@ -754,12 +962,16 @@ class AlignMonitor: "INFO: Not enough entries in the histogram to perform the fit." ) hist_dict["hist"][j].SetTitle( - title[j] + "(NOT ENOUGH ENTRIES TO FIT)") + title[j] + "(NOT ENOUGH ENTRIES TO FIT)" + ) return hist_dict["hist"][j] - if f"RICH/RiCKResLongTight/Rich{self.whichRich}Gas/ckResAll" == hist_path: + if ( + f"RICH/RiCKResLongTight/Rich{self.whichRich}Gas/ckResAll" + == hist_path + ): if (j == 0) and (j == self.maxIt): - hist_dict["hist"][j].SetName('resHisto0') + hist_dict["hist"][j].SetName("resHisto0") # Commented out stuff below is for the Run 2 Monet setup """ @@ -769,7 +981,7 @@ class AlignMonitor: print("INFO: resHisto0 sent to Monitoring.") """ - hist_dict["hist"][j].SetName('resHistoN') + hist_dict["hist"][j].SetName("resHistoN") # Commented out stuff below is for the Run 2 Monet setup """ @@ -779,69 +991,92 @@ class AlignMonitor: print("INFO: resHistoN sent to Monitoring.") """ - elif (j == self.maxIt): - hist_dict["hist"][j].SetName('resHistoN') + elif j == self.maxIt: + hist_dict["hist"][j].SetName("resHistoN") # Commented out stuff below is for the Run 2 Monet setup - """ + """ if self.flat is False: self.monSvc.publishHistogram( self.monitoring_folder, hist_dict["hist"][j].Clone(), add=False) print("INFO: resHistoN sent to Monitoring.") """ - elif (j == 0): - hist_dict["hist"][j].SetName('resHisto0') + elif j == 0: + hist_dict["hist"][j].SetName("resHisto0") # Commented out stuff below is for the Run 2 Monet setup - """ + """ if self.flat is False: self.monSvc.publishHistogram( self.monitoring_folder, hist_dict["hist"][j].Clone(), add=False) print("INFO: resHisto0 sent to Monitoring.") """ - if (j != 0): - hist_dict["hist"][j].SetName('resHisto' + str(j)) + if j != 0: + hist_dict["hist"][j].SetName("resHisto" + str(j)) - hist_dict["fitRes"][j], hist_dict["resHistograms"][ - j] = self.fitCherenkovAngle(hist_dict["hist"][j]) + hist_dict["fitRes"][j], hist_dict["resHistograms"][j] = ( + self.fitCherenkovAngle(hist_dict["hist"][j]) + ) - hist_dict["histFunc"][j] = hist_dict["fitRes"][ - j].overallFitFunc + hist_dict["histFunc"][j] = hist_dict["fitRes"][j].overallFitFunc hist_dict["polbkg"][j] = hist_dict["fitRes"][j].bkgFitFunc ckres = hist_dict["histFunc"][j].GetParameter(2) * 1000 - ckres_error = hist_dict["histFunc"][j].GetParError( - 2) * 1000 + ckres_error = hist_dict["histFunc"][j].GetParError(2) * 1000 hist_dict["resHistoTrend"].SetBinContent(j + 1, ckres) hist_dict["resHistoTrend"].SetBinError(j + 1, ckres_error) - if f"RICH/RiCKResLongTight/Rich{self.whichRich}Gas/ckResAll" == hist_path: + if ( + f"RICH/RiCKResLongTight/Rich{self.whichRich}Gas/ckResAll" + == hist_path + ): print("INFO: " + title[j] + ":") - print("INFO: _i" + str(j) + - " CK angle resolution: " + str(ckres) + - " mrad.") - print("INFO: _i" + str(j) + - " CK angle resolution err: " + str(ckres_error) + - " mrad.") + print( + "INFO: _i" + + str(j) + + " CK angle resolution: " + + str(ckres) + + " mrad." + ) + print( + "INFO: _i" + + str(j) + + " CK angle resolution err: " + + str(ckres_error) + + " mrad." + ) else: print("INFO: subselection " + title[j] + ":") - print("INFO: subselection _i" + str(j) + - " CK angle resolution: " + str(ckres) + - " mrad.") - print("INFO: subselection _i" + str(j) + - " CK angle resolution err: " + str(ckres_error) + - " mrad.") - - if j == self.maxIt and f"RICH/RiCKResLongTight/Rich{self.whichRich}Gas/ckResAll" == hist_path: + print( + "INFO: subselection _i" + + str(j) + + " CK angle resolution: " + + str(ckres) + + " mrad." + ) + print( + "INFO: subselection _i" + + str(j) + + " CK angle resolution err: " + + str(ckres_error) + + " mrad." + ) + + if ( + j == self.maxIt + and f"RICH/RiCKResLongTight/Rich{self.whichRich}Gas/ckResAll" + == hist_path + ): self.finalCKres = ckres self.finalCKresErr = ckres_error hist_dict["resHistograms"][j].SetTitle(title[j]) hist_dict["resHistograms"][j].SetXTitle( - r'#Delta#theta_{Cherenkov} (rad)') - hist_dict["resHistograms"][j].SetYTitle('Entries') + r"#Delta#theta_{Cherenkov} (rad)" + ) + hist_dict["resHistograms"][j].SetYTitle("Entries") hist_dict["histFunc"][j].SetLineColor(2) hist_dict["polbkg"][j].SetLineColor(4) @@ -863,33 +1098,42 @@ class AlignMonitor: try: res = plot_ckres( hist_path, - histos[f"RICH{self.whichRich}"] - [hist_dict_name][panel_name] - [f"col{column_num}"], j) + histos[f"RICH{self.whichRich}"][hist_dict_name][ + panel_name + ][f"col{column_num}"], + j, + ) print(res) except: res = None # store histogram without fit if res is not None: - histos[f"RICH{self.whichRich}"][ - hist_dict_name][panel_name][ - f"col{column_num}"][ - "resHistograms"][j] = res + histos[f"RICH{self.whichRich}"][hist_dict_name][ + panel_name + ][f"col{column_num}"]["resHistograms"][j] = res elif "Rtype" in hist_dict_name: hist_path = f"RICH/RiCKResLongTight/Rich{self.whichRich}Gas/ckResAllRTypePD" res = plot_ckres( hist_path, - histos[f"RICH{self.whichRich}"][hist_dict_name], j) + histos[f"RICH{self.whichRich}"][hist_dict_name], + j, + ) elif "Htype" in hist_dict_name: hist_path = f"RICH/RiCKResLongTight/Rich{self.whichRich}Gas/ckResAllHTypePD" res = plot_ckres( hist_path, - histos[f"RICH{self.whichRich}"][hist_dict_name], j) + histos[f"RICH{self.whichRich}"][hist_dict_name], + j, + ) elif "allCkres" in hist_dict_name: # allCkres - hist_path = f"RICH/RiCKResLongTight/Rich{self.whichRich}Gas/ckResAll" + hist_path = ( + f"RICH/RiCKResLongTight/Rich{self.whichRich}Gas/ckResAll" + ) res = plot_ckres( hist_path, - histos[f"RICH{self.whichRich}"][hist_dict_name], j) + histos[f"RICH{self.whichRich}"][hist_dict_name], + j, + ) elif "dThetavsPhi" in hist_dict_name: # define primary and secondary mirrors mirr_combs = { @@ -897,69 +1141,80 @@ class AlignMonitor: "top": { "pri": ["00", "01"], "sec": [ - "00", "01", "02", "03", "04", "05", - "06", "07" - ] + "00", + "01", + "02", + "03", + "04", + "05", + "06", + "07", + ], }, "bottom": { "pri": ["02", "03"], "sec": [ - "08", "09", "10", "11", "12", "13", - "14", "15" - ] - } + "08", + "09", + "10", + "11", + "12", + "13", + "14", + "15", + ], + }, }, "RICH2": { "ASide-left": { - "pri": [ - "{:02d}".format(num) - for num in range(28) - ], - "sec": [ - "{:02d}".format(num) - for num in range(20) - ] + "pri": ["{:02d}".format(num) for num in range(28)], + "sec": ["{:02d}".format(num) for num in range(20)], }, "CSide-right": { "pri": [ - "{:02d}".format(num) - for num in range(28, 56) + "{:02d}".format(num) for num in range(28, 56) ], "sec": [ - "{:02d}".format(num) - for num in range(20, 40) - ] - } - } + "{:02d}".format(num) for num in range(20, 40) + ], + }, + }, } # combine mirror comb histos for each panel - for panel in mirr_combs[f"RICH{self.whichRich}"].keys( - ): - histos[f"RICH{self.whichRich}"]["dThetavsPhi"][ - panel] = TH2D( - fr'#Delta#theta vs #phi (R{self.whichRich} {panel}, it {j})', - fr'#Delta#theta vs #phi (R{self.whichRich} {panel}, it {j})', - 60, 0, 6.283185307179586, 50, + for panel in mirr_combs[f"RICH{self.whichRich}"].keys(): + histos[f"RICH{self.whichRich}"]["dThetavsPhi"][panel] = ( + TH2D( + rf"#Delta#theta vs #phi (R{self.whichRich} {panel}, it {j})", + rf"#Delta#theta vs #phi (R{self.whichRich} {panel}, it {j})", + 60, + 0, + 6.283185307179586, + 50, -0.012000000104308128 - if self.whichRich == 1 else - -0.004000000189989805, - 0.012000000104308128 if self.whichRich == 1 - else 0.004000000189989805) - - for pri in mirr_combs[f"RICH{self.whichRich}"][ - panel]["pri"]: - for sec in mirr_combs[f"RICH{self.whichRich}"][ - panel]["sec"]: - + if self.whichRich == 1 + else -0.004000000189989805, + 0.012000000104308128 + if self.whichRich == 1 + else 0.004000000189989805, + ) + ) + + for pri in mirr_combs[f"RICH{self.whichRich}"][panel][ + "pri" + ]: + for sec in mirr_combs[f"RICH{self.whichRich}"][panel][ + "sec" + ]: # check if this pri and sec combination is correct hist_path = f"RICH/MirrorAlignLong/Rich{self.whichRich}Gas/dThetaPhiRecSaturTrR{self.whichRich}p{pri}s{sec}" try: mirr_comb_hist = ( - thisFile[j].Get(hist_path).Clone()) - histos[f"RICH{self.whichRich}"][ - "dThetavsPhi"][panel].Add( - mirr_comb_hist) + thisFile[j].Get(hist_path).Clone() + ) + histos[f"RICH{self.whichRich}"]["dThetavsPhi"][ + panel + ].Add(mirr_comb_hist) except: pass # this mirror combination doesn't exist in the root file @@ -967,27 +1222,31 @@ class AlignMonitor: theCanvas2.cd() gStyle.SetNumberContours(20) histos[f"RICH{self.whichRich}"]["dThetavsPhi"][ - panel].GetXaxis().SetTitle(fr'#phi (rad)') + panel + ].GetXaxis().SetTitle(rf"#phi (rad)") histos[f"RICH{self.whichRich}"]["dThetavsPhi"][ - panel].GetYaxis().SetTitle( - fr'#Delta#theta (mrad)') - histos[f"RICH{self.whichRich}"]["dThetavsPhi"][ - panel].Draw("COLZ") + panel + ].GetYaxis().SetTitle(rf"#Delta#theta (mrad)") + histos[f"RICH{self.whichRich}"]["dThetavsPhi"][panel].Draw( + "COLZ" + ) theCanvas2.Print(expertFile) ## write to Monet root file if self.flat is False: if j == 0: monetRootFile.WriteTObject( - histos[f"RICH{self.whichRich}"] - ["dThetavsPhi"][panel], - f"RICH{self.whichRich}_{hist_dict_name}_RICH{self.whichRich}_{panel}_It_{j}" + histos[f"RICH{self.whichRich}"]["dThetavsPhi"][ + panel + ], + f"RICH{self.whichRich}_{hist_dict_name}_RICH{self.whichRich}_{panel}_It_{j}", ) if j == self.maxIt: monetRootFile.WriteTObject( - histos[f"RICH{self.whichRich}"] - ["dThetavsPhi"][panel], - f"RICH{self.whichRich}_{hist_dict_name}_RICH{self.whichRich}_{panel}_It_final" + histos[f"RICH{self.whichRich}"]["dThetavsPhi"][ + panel + ], + f"RICH{self.whichRich}_{hist_dict_name}_RICH{self.whichRich}_{panel}_It_final", ) theCanvas2.Clear() @@ -997,48 +1256,56 @@ class AlignMonitor: theCanvas2.Divide(3, 4) for panel_name in panel_names: - column_counter = 0 if self.whichRich == 1 else 1 # RICH 2 has no 0th column, so we start it at 1st column + column_counter = ( + 0 if self.whichRich == 1 else 1 + ) # RICH 2 has no 0th column, so we start it at 1st column for irow in range(3): for icol in range(4): - - theCanvas2.cd(irow * 4 + icol + - 1) # go to current pad + theCanvas2.cd( + irow * 4 + icol + 1 + ) # go to current pad # deal with cases where no column for the corresponding TPad index - if column_counter >= len( - column_nums[f"RICH{self.whichRich}"] - ) and self.whichRich == 1: # RICH 1 has no 11th column + if ( + column_counter + >= len(column_nums[f"RICH{self.whichRich}"]) + and self.whichRich == 1 + ): # RICH 1 has no 11th column column_counter += 1 placeholder_histogram.Draw() continue try: - histos[f"RICH{self.whichRich}"][ - hist_dict_name][panel_name][ - f"col{column_counter}"][ - "resHistograms"][j].Draw() + histos[f"RICH{self.whichRich}"][hist_dict_name][ + panel_name + ][f"col{column_counter}"]["resHistograms"][ + j + ].Draw() except: pass # only show fit, if there were enough events to perform the fit try: - if histos[f"RICH{self.whichRich}"][ - hist_dict_name][panel_name][ - f"col{column_counter}"][ - "histFunc"][ - j] is not None: + if ( + histos[f"RICH{self.whichRich}"][ + hist_dict_name + ][panel_name][f"col{column_counter}"][ + "histFunc" + ][j] + is not None + ): try: histos[f"RICH{self.whichRich}"][ - hist_dict_name][panel_name][ - f"col{column_counter}"][ - "histFunc"][ - j].Draw("SAME") + hist_dict_name + ][panel_name][f"col{column_counter}"][ + "histFunc" + ][j].Draw("SAME") except: pass try: histos[f"RICH{self.whichRich}"][ - hist_dict_name][panel_name][ - f"col{column_counter}"][ - "polbkg"][j].Draw( - "SAME") + hist_dict_name + ][panel_name][f"col{column_counter}"][ + "polbkg" + ][j].Draw("SAME") except: pass except: @@ -1050,18 +1317,23 @@ class AlignMonitor: theCanvas2.Clear() - elif "resHistograms" in histos[f"RICH{self.whichRich}"][ - hist_dict_name].keys(): + elif ( + "resHistograms" + in histos[f"RICH{self.whichRich}"][hist_dict_name].keys() + ): theCanvas2.Divide(1, 1) # add to canvas theCanvas2.cd() histos[f"RICH{self.whichRich}"][hist_dict_name][ - "resHistograms"][j].Draw() - histos[f"RICH{self.whichRich}"][hist_dict_name][ - "histFunc"][j].Draw("SAME") - histos[f"RICH{self.whichRich}"][hist_dict_name][ - "polbkg"][j].Draw("SAME") + "resHistograms" + ][j].Draw() + histos[f"RICH{self.whichRich}"][hist_dict_name]["histFunc"][ + j + ].Draw("SAME") + histos[f"RICH{self.whichRich}"][hist_dict_name]["polbkg"][ + j + ].Draw("SAME") theCanvas2.Print(expertFile) theCanvas2.Clear() @@ -1069,15 +1341,17 @@ class AlignMonitor: if self.flat is False: if j == 0: monetRootFile.WriteTObject( - histos[f"RICH{self.whichRich}"] - [hist_dict_name]["resHistograms"][j], - f"RICH{self.whichRich}_{hist_dict_name}_It_{j}" + histos[f"RICH{self.whichRich}"][hist_dict_name][ + "resHistograms" + ][j], + f"RICH{self.whichRich}_{hist_dict_name}_It_{j}", ) if j == self.maxIt: monetRootFile.WriteTObject( - histos[f"RICH{self.whichRich}"] - [hist_dict_name]["resHistograms"][j], - f"RICH{self.whichRich}_{hist_dict_name}_It_final" + histos[f"RICH{self.whichRich}"][hist_dict_name][ + "resHistograms" + ][j], + f"RICH{self.whichRich}_{hist_dict_name}_It_final", ) ####### from fitCherenkovAngle_old ################# @@ -1129,56 +1403,64 @@ class AlignMonitor: if "columns" in hist_dict_name: for panel_name in panel_names: for column_num in column_nums[f"RICH{self.whichRich}"]: - trendTitle = histos[f"RICH{self.whichRich}"][ - hist_dict_name][panel_name][f"col{column_num}"][ - "resHistoTrend"].GetTitle() - histos[f"RICH{self.whichRich}"][hist_dict_name][ - panel_name][f"col{column_num}"][ - "resHistoTrend"].SetTitle( - f"{trendTitle}, {hist_dict_name} ({column_num}), {panel_name}" - ) - histos[f"RICH{self.whichRich}"][hist_dict_name][ - panel_name][f"col{column_num}"][ - "resHistoTrend"].SetMarkerStyle(8) - histos[f"RICH{self.whichRich}"][hist_dict_name][ - panel_name][f"col{column_num}"][ - "resHistoTrend"].SetXTitle('iteration number') - histos[f"RICH{self.whichRich}"][hist_dict_name][ - panel_name][f"col{column_num}"][ - "resHistoTrend"].SetYTitle( - '#splitline{Cherenkov angle resolution (mrad)}{}' - ) + trendTitle = histos[f"RICH{self.whichRich}"][hist_dict_name][ + panel_name + ][f"col{column_num}"]["resHistoTrend"].GetTitle() + histos[f"RICH{self.whichRich}"][hist_dict_name][panel_name][ + f"col{column_num}" + ]["resHistoTrend"].SetTitle( + f"{trendTitle}, {hist_dict_name} ({column_num}), {panel_name}" + ) + histos[f"RICH{self.whichRich}"][hist_dict_name][panel_name][ + f"col{column_num}" + ]["resHistoTrend"].SetMarkerStyle(8) + histos[f"RICH{self.whichRich}"][hist_dict_name][panel_name][ + f"col{column_num}" + ]["resHistoTrend"].SetXTitle("iteration number") + histos[f"RICH{self.whichRich}"][hist_dict_name][panel_name][ + f"col{column_num}" + ]["resHistoTrend"].SetYTitle( + "#splitline{Cherenkov angle resolution (mrad)}{}" + ) theCanvas.Clear() - histos[f"RICH{self.whichRich}"][hist_dict_name][ - panel_name][f"col{column_num}"][ - "resHistoTrend"].DrawCopy() + histos[f"RICH{self.whichRich}"][hist_dict_name][panel_name][ + f"col{column_num}" + ]["resHistoTrend"].DrawCopy() theCanvas.Print(expertFile) - elif "resHistoTrend" in histos[f"RICH{self.whichRich}"][ - hist_dict_name].keys(): + elif ( + "resHistoTrend" + in histos[f"RICH{self.whichRich}"][hist_dict_name].keys() + ): trendTitle = histos[f"RICH{self.whichRich}"][hist_dict_name][ - "resHistoTrend"].GetTitle() + "resHistoTrend" + ].GetTitle() histos[f"RICH{self.whichRich}"][hist_dict_name][ - "resHistoTrend"].SetTitle( - f"{trendTitle}, {hist_dict_name}") + "resHistoTrend" + ].SetTitle(f"{trendTitle}, {hist_dict_name}") histos[f"RICH{self.whichRich}"][hist_dict_name][ - "resHistoTrend"].SetMarkerStyle(8) + "resHistoTrend" + ].SetMarkerStyle(8) histos[f"RICH{self.whichRich}"][hist_dict_name][ - "resHistoTrend"].SetXTitle('iteration number') + "resHistoTrend" + ].SetXTitle("iteration number") histos[f"RICH{self.whichRich}"][hist_dict_name][ - "resHistoTrend"].SetYTitle( - '#splitline{Cherenkov angle resolution (mrad)}{}') + "resHistoTrend" + ].SetYTitle("#splitline{Cherenkov angle resolution (mrad)}{}") theCanvas.Clear() histos[f"RICH{self.whichRich}"][hist_dict_name][ - "resHistoTrend"].DrawCopy() + "resHistoTrend" + ].DrawCopy() if self.flat is False: monetRootFile.WriteTObject( - histos[f"RICH{self.whichRich}"][hist_dict_name] - ["resHistoTrend"], - f"RICH{self.whichRich}_{hist_dict_name}_resHistoTrend") + histos[f"RICH{self.whichRich}"][hist_dict_name][ + "resHistoTrend" + ], + f"RICH{self.whichRich}_{hist_dict_name}_resHistoTrend", + ) theCanvas.Print(expertFile) @@ -1205,9 +1487,9 @@ class AlignMonitor: minSecY = TLine(0, -self.sTSY, self.maxsec, -self.sTSY) maxSecZ = TLine(0, self.sTSZ, self.maxsec, self.sTSZ) minSecZ = TLine(0, -self.sTSZ, self.maxsec, -self.sTSZ) - maxPriY.SetLineColor(2) #red + maxPriY.SetLineColor(2) # red minPriY.SetLineColor(2) - maxPriZ.SetLineColor(4) #blue + maxPriZ.SetLineColor(4) # blue minPriZ.SetLineColor(4) maxSecY.SetLineColor(2) minSecY.SetLineColor(2) @@ -1235,17 +1517,20 @@ class AlignMonitor: tops = biggestTilt[self.maxIt][1] mgraphs[0].SetMinimum(-(tops + 0.01)) mgraphs[0].SetMaximum(tops + 0.01) - mgraphs[0].Draw('AP') + mgraphs[0].Draw("AP") maxPriY.Draw("SAME") minPriY.Draw("SAME") maxPriZ.Draw("SAME") minPriZ.Draw("SAME") mgraphs[0].SetTitle( - "RICH" + str(self.whichRich) + - " final primary mirror compensations w.r.t. to comparison DB") + "RICH" + + str(self.whichRich) + + " final primary mirror compensations w.r.t. to comparison DB" + ) mgraphs[0].GetXaxis().SetTitle("primary mirror number") mgraphs[0].GetYaxis().SetTitle( - "change in compensation (mrad) [{red, blue}: local {Y, Z}]") + "change in compensation (mrad) [{red, blue}: local {Y, Z}]" + ) theCanvas.Print(expertFile) @@ -1259,21 +1544,24 @@ class AlignMonitor: tops = biggestTilt[self.maxIt][3] mgraphs[1].SetMinimum(-(tops + 0.01)) mgraphs[1].SetMaximum(tops + 0.01) - mgraphs[1].Draw('AP') + mgraphs[1].Draw("AP") maxSecY.Draw("SAME") minSecY.Draw("SAME") maxSecZ.Draw("SAME") minSecZ.Draw("SAME") mgraphs[1].SetTitle( - "RICH" + str(self.whichRich) + - " final secondary mirror compensations w.r.t. to comparison DB") + "RICH" + + str(self.whichRich) + + " final secondary mirror compensations w.r.t. to comparison DB" + ) mgraphs[1].GetXaxis().SetTitle("secondary mirror number") mgraphs[1].GetYaxis().SetTitle( - "change in compensation (mrad) [{red, blue}: local {Y, Z}]") + "change in compensation (mrad) [{red, blue}: local {Y, Z}]" + ) - theCanvas.Print(expertFile + ')') + theCanvas.Print(expertFile + ")") for n_it in range(0, self.maxIt + 1): - #mirrtilts[self.maxIt].writeChange(self.maxIt + 1) # PN: This does not look right, let me try to fix: + # mirrtilts[self.maxIt].writeChange(self.maxIt + 1) # PN: This does not look right, let me try to fix: mirrtilts[n_it].writeChange(n_it + 1) mgraphs[0].Delete() mgraphs[1].Delete() @@ -1294,14 +1582,14 @@ class AlignMonitor: """ def fitCherenkovAngle(self, hist): - # get Chris Jones's C++ fitter fitter = gbl.Rich.Rec.CKResolutionFitter() # set signal (AsymNormal) and background (FreeNPol) models fitter.params().RichFitTypes[self.whichRich - 1].clear() - fitter.params().RichFitTypes[self.whichRich - - 1].push_back("AsymNormal:FreeNPol") + fitter.params().RichFitTypes[self.whichRich - 1].push_back( + "AsymNormal:FreeNPol" + ) # change fit ranges fitter.params().RichFitMin[0] = self.fitMin @@ -1314,12 +1602,12 @@ class AlignMonitor: return res, hist def fitCherenkovAngle_old(self, hist): - richStr = 'Rich' + str(self.whichRich) + richStr = "Rich" + str(self.whichRich) m_maxErrorForOK = 1e-3 xPeak = hist.GetBinCenter(hist.GetMaximumBin()) delta = 0 - if (richStr == 'Rich1'): + if richStr == "Rich1": delta = 0.0025 else: delta = 0.00105 @@ -1331,7 +1619,7 @@ class AlignMonitor: preFitF = TF1(preFitFName, "gaus", fitMin, fitMax) preFitF.SetParameter(1, 0) - if (richStr == 'Rich1'): + if richStr == "Rich1": preFitF.SetParameter(2, 0.0015) else: preFitF.SetParameter(2, 0.0007) @@ -1355,7 +1643,7 @@ class AlignMonitor: fFitF.SetParName(1, "Gaus Mean") fFitF.SetParName(2, "Gaus Sigma") nParamsToSet = 3 - if (nPol > 1): + if nPol > 1: nParamsToSet = 3 + nPol for p in range(0, nParamsToSet): @@ -1368,7 +1656,7 @@ class AlignMonitor: bestFitF = fFitF bestNPol = nPol else: - if (nPol == nPolFull): + if nPol == nPolFull: hist.Fit(fFitF, "RFSE0QM") fitOK = True if nPol > 1: diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Communicator.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Communicator.py index 4534368979d15f037e88724ce366696422af00da..d69bad123d4cb1f19e37eb9e4fe45a98916ed212 100644 --- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Communicator.py +++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Communicator.py @@ -8,9 +8,12 @@ # granted to it by virtue of its status as an Intergovernmental Organization # # or submit itself to any jurisdiction. # ############################################################################### -import os, sys +import os +import re import socket -import re, struct +import struct +import sys + import pydim @@ -27,37 +30,41 @@ class State(object): class Communicator(object): def __init__(self, utgid_suffix): self.__status = State.UNKNOWN - from multiprocessing import Pipe, Condition, Lock + from multiprocessing import Condition, Lock, Pipe + self.__master_end, self.__process_end = Pipe() self.__callback_lock = Lock() utgid = self.utgid(utgid_suffix) pydim.dis_add_cmnd(utgid, "C", self.__command_callback, 1) - self.__info_svc = pydim.dis_add_service(utgid + "/status", "C", - self.__status_callback, 0) + self.__info_svc = pydim.dis_add_service( + utgid + "/status", "C", self.__status_callback, 0 + ) if not self.__info_svc: - sys.stderr.write("An error occurred while registering the " + - utgid + "/status DB update DIM service\n") + sys.stderr.write( + "An error occurred while registering the " + + utgid + + "/status DB update DIM service\n" + ) sys.exit(1) pydim.dis_start_serving(utgid) - print("INFO: Started DIM service " + utgid + "/status with server " + - utgid) + print("INFO: Started DIM service " + utgid + "/status with server " + utgid) sys.stdout.flush() pydim.dis_update_service(self.__info_svc) def partition(self): - return os.environ.get('PARTITION', 'TEST') + return os.environ.get("PARTITION", "TEST") def hostname(self): import socket - return socket.gethostname().split('.')[0] + + return socket.gethostname().split(".")[0] def utgid(self, suffix): - utgid = os.environ.get('UTGID', '') + utgid = os.environ.get("UTGID", "") if utgid: return utgid else: - return '_'.join((self.partition(), self.hostname().upper(), - suffix)) + return "_".join((self.partition(), self.hostname().upper(), suffix)) def has_command(self, *args): if len(args) == 0: @@ -87,13 +94,13 @@ class Communicator(object): self.__process_end.close() def __command_callback(self, args, tag): - #print("Before) repr(args[0])") - #print(repr(args[0])) + # print("Before) repr(args[0])") + # print(repr(args[0])) self.__callback_lock.acquire() self.__put_command(args[0]) - #print("After) repr(args[0])") - #print(repr(args[0])) + # print("After) repr(args[0])") + # print(repr(args[0])) self.__callback_lock.release() def __status_callback(self, *args): - return (self.__status, ) + return (self.__status,) diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/HistoHelper.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/HistoHelper.py index 563777901346e702e3911b920d641f43eefa25cb..a5d9836a572eae69eb3e7d4c555ef792ee48de06 100644 --- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/HistoHelper.py +++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/HistoHelper.py @@ -11,29 +11,28 @@ __author__ = "Paras Naik, Claire Prouve" __copyright__ = "University of Bristol, June 2023" -import time -from time import sleep -from time import time -from time import gmtime, strftime -import pydim -import threading -import shutil +import glob import os +import shutil import sys -from ruamel.yaml import YAML +import threading +import time +from time import gmtime, sleep, strftime, time + +import pydim import ROOT -import glob +from ruamel.yaml import YAML class HistoCopier: def __init__(self, alignConf): - self.__tiltNames = alignConf.getProp('tiltNames') - self.__workdir = alignConf.getProp('WorkDir') - self.__whichRich = alignConf.getProp('Rich') + self.__tiltNames = alignConf.getProp("tiltNames") + self.__workdir = alignConf.getProp("WorkDir") + self.__whichRich = alignConf.getProp("Rich") self.__tiltNamesLength = len(self.__tiltNames) def resultName(self, n_it, m_it): - #print(f"n_it {n_it} m_it {m_it}") + # print(f"n_it {n_it} m_it {m_it}") if m_it % self.__tiltNamesLength == 0: connectStr = "" else: @@ -41,17 +40,17 @@ class HistoCopier: yaml = YAML() with open( - os.path.join(self.__workdir, - f'rich{self.__whichRich}_variant.yml')) as finp: + os.path.join(self.__workdir, f"rich{self.__whichRich}_variant.yml") + ) as finp: variant = yaml.load(finp) mergename = f"{self.__workdir}{variant}_histos{connectStr}{self.__tiltNames[m_it % self.__tiltNamesLength]}_i{n_it}.root" - #print(f"mergename {mergename}") + # print(f"mergename {mergename}") return mergename def getHistoFile(self, n_it, m_it): - #print(f"n_it {n_it} m_it {m_it}") + # print(f"n_it {n_it} m_it {m_it}") if m_it % self.__tiltNamesLength == 0: connectStr = "" else: @@ -59,8 +58,8 @@ class HistoCopier: yaml = YAML() with open( - os.path.join(self.__workdir, - f'rich{self.__whichRich}_variant.yml')) as finp: + os.path.join(self.__workdir, f"rich{self.__whichRich}_variant.yml") + ) as finp: variant = yaml.load(finp) # Specify the file pattern @@ -68,15 +67,15 @@ class HistoCopier: # Get the list of files matching the pattern file_list = glob.glob(file_pattern) - #print(f"file_list {file_list}") + # print(f"file_list {file_list}") # Specify the output file name resultName = self.resultName(n_it, m_it) - #self.waitForSaveSet(resultName, m_it) + # self.waitForSaveSet(resultName, m_it) ## Create an empty output file - #outputFile = ROOT.TFile(resultName, "RECREATE") - #outputFile.Close() + # outputFile = ROOT.TFile(resultName, "RECREATE") + # outputFile.Close() # Create a TFileMerger object merger = ROOT.TFileMerger() @@ -93,7 +92,7 @@ class HistoCopier: # Close the output file del merger - #merger.OutputFile("") + # merger.OutputFile("") # Print a summary of the merged file merged_file = ROOT.TFile(resultName, "READ") @@ -107,7 +106,7 @@ class HistoCopier: os.remove(file_name) -''' +""" class SaveSetRetriever_Run2: def __init__(self, part, tsk): self.name = part + "/" + tsk + "/SAVESETLOCATION" @@ -182,4 +181,4 @@ class HistoCopier_Run2: def getHistoFile(self, n_it, m_it): resultName = self.resultName(n_it, m_it) self.waitForSaveSet(resultName, m_it) -''' +""" diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py index 848226eadeca6a556d50b2acd68766062fb65a91..b0266abe81e7e45e4bd95034e7b39b96ea968037 100644 --- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py +++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py @@ -11,7 +11,7 @@ __authors__ = "Claire Prouve, Paras Naik" __copyright__ = "University of Bristol, July 2023" -#python -c "from PyMirrAlignOnline import Iterator; Iterator.run(1,True,True)" +# python -c "from PyMirrAlignOnline import Iterator; Iterator.run(1,True,True)" # if flat is False (same as 'if offline is False') # This is the Iterator (for testbench / Run Control) Online @@ -30,31 +30,30 @@ __copyright__ = "University of Bristol, July 2023" # NB: For each single iteration, you must manually put the root file for the current iteration in the right place! # Please propagate all generally useful changes to the main iterator part (flat = False) import distutils -import os +import getpass import glob +import math +import os import re import shutil +import subprocess import sys -import math -import time -from time import sleep -from time import time -from time import gmtime, strftime import threading -import subprocess +import time from distutils import dir_util -from ruamel.yaml import YAML -import getpass -import ROOT +from time import gmtime, sleep, strftime, time + # LHCb-specific imports import Configurables -from PyMirrAlignOnline.Communicator import * # gets the State and Communicator classes +import ROOT from MooreOnlineConf.utils import ( - alignment_options, ) - -print( - f"INFO: Iterator.py launched at {strftime('%Y-%m-%d %H:%M:%S', gmtime())} UTC" + alignment_options, ) +from ruamel.yaml import YAML + +from PyMirrAlignOnline.Communicator import * # gets the State and Communicator classes + +print(f"INFO: Iterator.py launched at {strftime('%Y-%m-%d %H:%M:%S', gmtime())} UTC") sys.stdout.flush() @@ -62,7 +61,6 @@ sys.stdout.flush() ##### Here is where the party starts! ######################################################################################################################## def run(whichRich, offline=False, runInlineReco=False): - flat = offline def get_file_name(file_path): @@ -84,9 +82,9 @@ def run(whichRich, offline=False, runInlineReco=False): launchTime = strftime("%Y-%m-%d %H:%M:%S", gmtime()) start_time_config = time() # when LHCbA config start time is really set - #print(f"INFO: The launch directory is: {os.getcwd()}") - #print(f'INFO: os.getenv("WORKING_DIR") = {os.getenv("WORKING_DIR")}') - launchDir = os.path.join(os.getcwd(), '') + # print(f"INFO: The launch directory is: {os.getcwd()}") + # print(f'INFO: os.getenv("WORKING_DIR") = {os.getenv("WORKING_DIR")}') + launchDir = os.path.join(os.getcwd(), "") ######################################################################################################################## ##### reading in the settings from the Configuration file @@ -95,11 +93,13 @@ def run(whichRich, offline=False, runInlineReco=False): sys.stdout.flush() if whichRich == 1: from Configurables import Rich1MirrAlignOnConf - #from Configuration import Rich1MirrAlignOnConf + + # from Configuration import Rich1MirrAlignOnConf alignConf = Rich1MirrAlignOnConf() elif whichRich == 2: from Configurables import Rich2MirrAlignOnConf - #from Configuration import Rich2MirrAlignOnConf + + # from Configuration import Rich2MirrAlignOnConf alignConf = Rich2MirrAlignOnConf() else: sys.stderr.write(f"A detector named RICH{whichRich} does not exist.\n") @@ -109,27 +109,34 @@ def run(whichRich, offline=False, runInlineReco=False): ### grab the stack directory as defined in Configuration.py stackDir = alignConf.getProp( - 'stackDir') # '/group/rich/sw/alignment/stack/' is default + "stackDir" + ) # '/group/rich/sw/alignment/stack/' is default ### Set up strings needed for logging of hlt02 (the node that the iterator is running on) richFilesDir = alignConf.getProp( - 'richFiles') # '/group/rich/AlignmentFiles/' is default + "richFiles" + ) # '/group/rich/AlignmentFiles/' is default - loggingDir = f'{richFilesDir}Logging/' - polarityDir = f'{richFilesDir}Polarity/' + loggingDir = f"{richFilesDir}Logging/" + polarityDir = f"{richFilesDir}Polarity/" lastAlignSuccess = f"{loggingDir}Rich{whichRich}_success.txt" currentHLT02log = f"{loggingDir}Rich{whichRich}_hlt02.log" currentHLT02logReduced = f"{loggingDir}Rich{whichRich}_hlt02reduced.log" previousHLT02log = f"{loggingDir}Rich{whichRich}_hlt02_previous.log" previousHLT02logReduced = f"{loggingDir}Rich{whichRich}_hlt02reduced_previous.log" - #cmdStart = 'exec /opt/FMC/bin/logViewer -l 2 -S -b &>' - #cmdStart = '/group/online/dataflow/scripts/log_viewer.sh -m hlt02 -b /ROLogBridge_HLT2 &>' - cmdStart = 'stdbuf -oL -eL /group/online/dataflow/scripts/log_viewer.sh -m hlt02 &>' + # cmdStart = 'exec /opt/FMC/bin/logViewer -l 2 -S -b &>' + # cmdStart = '/group/online/dataflow/scripts/log_viewer.sh -m hlt02 -b /ROLogBridge_HLT2 &>' + cmdStart = "stdbuf -oL -eL /group/online/dataflow/scripts/log_viewer.sh -m hlt02 &>" # list used to help remove lines from the hlt02 log in the hlt02reduced versions, removeExtraneous_patterns = [ - "LHCb2_HLT02_Hlt2Adder_0", "Hlt2SaverSvc", "MARK", "BusyPub", - "BusyMon", "JobOptionsSvc", "environtment" + "LHCb2_HLT02_Hlt2Adder_0", + "Hlt2SaverSvc", + "MARK", + "BusyPub", + "BusyMon", + "JobOptionsSvc", + "environtment", ] # environtment not a typo # PN: Not sure ANY of these patterns appear anymore in Run3 # However, we keep this feature in case there is pollution of our log files @@ -143,13 +150,17 @@ def run(whichRich, offline=False, runInlineReco=False): except: print("WARNING: failed copy(currentHLT02log, previousHLT02log)") if os.path.exists(previousHLT02log): - #os.system(f'grep -vE "{removeExtraneous}" {previousHLT02log} > {previousHLT02logReduced}') + # os.system(f'grep -vE "{removeExtraneous}" {previousHLT02log} > {previousHLT02logReduced}') try: - with open(previousHLT02log, "rb") as input_file, open( - previousHLT02logReduced, "wb") as output_file: + with ( + open(previousHLT02log, "rb") as input_file, + open(previousHLT02logReduced, "wb") as output_file, + ): for line in input_file: - if not any(pattern in line.decode() - for pattern in removeExtraneous_patterns): + if not any( + pattern in line.decode() + for pattern in removeExtraneous_patterns + ): output_file.write(line) except: print("WARNING: failed to produce previousHLT02logReduced") @@ -159,32 +170,33 @@ def run(whichRich, offline=False, runInlineReco=False): with open(lastAlignSuccess) as lastAlignSuccessFile: lastAlignSuccessLine = lastAlignSuccessFile.readline() else: - lastAlignSuccessLine = 'UNKNOWN\n' + lastAlignSuccessLine = "UNKNOWN\n" ### Now that we have the lastAlignSuccessLine, Reset lastAlignSuccessFile to default try: - lastAlignSuccessFile = open(lastAlignSuccess, 'w') - lastAlignSuccessFile.write( - 'NO\n') # python will convert \n to os.linesep + lastAlignSuccessFile = open(lastAlignSuccess, "w") + lastAlignSuccessFile.write("NO\n") # python will convert \n to os.linesep lastAlignSuccessFile.close() except: print("WARNING: failed open(lastAlignSuccess, 'w')") ## Start logging of hlt02 (the node that the iterator is running on) - if lastAlignSuccessLine == 'YES\n': + if lastAlignSuccessLine == "YES\n": logProcess = subprocess.Popen( f"{cmdStart} {currentHLT02log}", shell=True, executable="/bin/bash", stderr=subprocess.PIPE, - stdout=subprocess.PIPE) + stdout=subprocess.PIPE, + ) else: logProcess = subprocess.Popen( f"{cmdStart}> {currentHLT02log}", shell=True, executable="/bin/bash", stderr=subprocess.PIPE, - stdout=subprocess.PIPE) + stdout=subprocess.PIPE, + ) logProcess.stdout.close() logProcess.stderr.close() @@ -199,7 +211,7 @@ def run(whichRich, offline=False, runInlineReco=False): print("INFO: Configuration Applied") print("INFO: LHCbA config start time set.") print(f"INFO: The launch directory is: {os.getcwd()}") - if lastAlignSuccessLine == 'YES\n': + if lastAlignSuccessLine == "YES\n": print( f"INFO: The previous Rich{whichRich} alignment was able to copy hlt02.log, overwriting hlt02.log with this alignment's printouts." ) @@ -208,35 +220,30 @@ def run(whichRich, offline=False, runInlineReco=False): f"INFO: The previous Rich{whichRich} alignment was not able to copy hlt02.log, appending this alignment's printouts to hlt02.log." ) print(f"INFO: logging hlt02 in temporary file: {currentHLT02log}") - print( - f"INFO: backing up last hlt02 log in temporary file: {previousHLT02log}" - ) + print(f"INFO: backing up last hlt02 log in temporary file: {previousHLT02log}") print( f"INFO: storing reduced backup of last hlt02 log in temporary file: {previousHLT02logReduced}" ) ### make a backup of OnlineEnvBase.py (do it now, in case we need to study the configuration on a single node) - origOnlineEnvBase = '/group/online/dataflow/options/LHCbA/OnlineEnvBase.py' + origOnlineEnvBase = "/group/online/dataflow/options/LHCbA/OnlineEnvBase.py" saveOnlineEnvBase = f"{loggingDir}Rich{whichRich}_OnlineEnvBase.py" try: copy( origOnlineEnvBase, # changed from "LHCbA/HLT/OnlineEnvBase.py" where it was in Run 2 - saveOnlineEnvBase) # - print( - f"INFO: stored OnlineEnvBase.py in temporary file: {saveOnlineEnvBase}" - ) + saveOnlineEnvBase, + ) # + print(f"INFO: stored OnlineEnvBase.py in temporary file: {saveOnlineEnvBase}") except: print("WARNING: failed copy(origOnlineEnvBase, saveOnlineEnvBase)") sys.stdout.flush() ### make a backup of Configuration.py - origConfiguration = f'{stackDir}Panoptes/Rich/RichMirrorAlignmentOnline/python/RichMirrorAlignmentOnline/Configuration.py' + origConfiguration = f"{stackDir}Panoptes/Rich/RichMirrorAlignmentOnline/python/RichMirrorAlignmentOnline/Configuration.py" saveConfiguration = f"{loggingDir}Rich{whichRich}_Configuration.py" try: copy(origConfiguration, saveConfiguration) - print( - f"INFO: stored Configuration.py in temporary file: {saveConfiguration}" - ) + print(f"INFO: stored Configuration.py in temporary file: {saveConfiguration}") except: print(origConfiguration) print(saveConfiguration) @@ -244,43 +251,52 @@ def run(whichRich, offline=False, runInlineReco=False): sys.stdout.flush() from PyMirrAlignOnline.XMLFileHelper import XMLFileHelper + xmlHelper = None from PyMirrAlignOnline.YAMLFileHelper import YAMLFileHelper + ymlHelper = None from PyMirrAlignOnline.convert_XML_YAML import Conversion + conversionsHelper = None from PyMirrAlignOnline.RichAlignmentHelper import RichAlignmentHelper + alignHelper = None from PyMirrAlignOnline.SetupHelper import SetupHelper + setupHelper = None from PyMirrAlignOnline.UpdateHelper import UpdateHelper + updateHelper = None from PyMirrAlignOnline.HistoHelper import HistoCopier + histCopier = None - from PyMirrAlignOnline.convert_magnFactors_txt_YAML import convert_magnFactors_txt_YAML + from PyMirrAlignOnline.convert_magnFactors_txt_YAML import ( + convert_magnFactors_txt_YAML, + ) maxIters = int( - alignConf.getProp('maxIterations') + alignConf.getProp("maxIterations") ) # This is the maximum "_i" iteration number before the alignment gives up - workdir = alignConf.getProp('WorkDir') - tiltNames = alignConf.getProp('tiltNames') + workdir = alignConf.getProp("WorkDir") + tiltNames = alignConf.getProp("tiltNames") tiltNamesLength = len(tiltNames) - thisNameStr = alignConf.getProp('nameStr') - magnFactorsMode = alignConf.getProp('magnFactorsMode') - autoUpdate_initial = bool(alignConf.getProp('autoUpdate')) + thisNameStr = alignConf.getProp("nameStr") + magnFactorsMode = alignConf.getProp("magnFactorsMode") + autoUpdate_initial = bool(alignConf.getProp("autoUpdate")) print(f"INFO: Initial setting of autoUpdate = {autoUpdate_initial}") autoUpdateNoV = False # this can never be True if autoUpdate_initial is False autoUpdate = False if autoUpdate_initial: autoUpdate = True - autoUpdateNoV = bool(alignConf.getProp('autoUpdateNoV')) + autoUpdateNoV = bool(alignConf.getProp("autoUpdateNoV")) print(f"INFO: Initial setting of autoUpdateNoV = {autoUpdateNoV}") - testing = bool(alignConf.getProp('testing')) + testing = bool(alignConf.getProp("testing")) print(f"INFO: Initial setting of testing = {testing}") print( f"INFO: Initial setting of useReducedSubset = {alignConf.getProp('useReducedSubset')}" ) - YAMLio = bool(alignConf.getProp('YAMLio')) + YAMLio = bool(alignConf.getProp("YAMLio")) print(f"INFO: Initial setting of YAMLio = {YAMLio}") if YAMLio: print( @@ -290,11 +306,11 @@ def run(whichRich, offline=False, runInlineReco=False): print( "INFO: Expecting the (v-numbered) starting file to be XML. Convert to YAML for MirrCombinFit & MirrAlign. Output YAML." ) - useDD4hep = bool(alignConf.getProp('useDD4hep')) + useDD4hep = bool(alignConf.getProp("useDD4hep")) if useDD4hep: YAMLio = True # if using DD4hep we are expecting YAML print( - "INFO: Reconstructing with DD4hep. Forced YAMLio = True. Expect RICH calibrations to be in calib.yml (or Run3 equivalent)." # PN: Update this message when this check of calib.yml or Run3 equivalent is re-established + "INFO: Reconstructing with DD4hep. Forced YAMLio = True. Expect RICH calibrations to be in calib.yml (or Run3 equivalent)." # PN: Update this message when this check of calib.yml or Run3 equivalent is re-established ) else: print( @@ -335,6 +351,7 @@ def run(whichRich, offline=False, runInlineReco=False): if flat is False: # Get List of Runs from Online if "online" in getpass.getuser(): import OnlineEnvBase as Online # import OnlineEnv as Online + online_options = alignment_options(Online) runs = online_options.runs # runs = Online.DeferredRuns # PN - Extract the run number substring from the full string @@ -346,41 +363,44 @@ def run(whichRich, offline=False, runInlineReco=False): for run in runs: polarities.append(setupHelper.getPolarity(run)) fills.append(setupHelper.getFillNumber(run)) - #print(f"INFO: runs = {runs}") + # print(f"INFO: runs = {runs}") for i in range(0, len(runs), 14): - batch = runs[i:i + 14] + batch = runs[i : i + 14] if i == 0: print("INFO: runs:", batch) else: print(" ", batch) - #print(f"INFO: fills = {fills}") + # print(f"INFO: fills = {fills}") for i in range(0, len(fills), 14): - batch = fills[i:i + 14] + batch = fills[i : i + 14] if i == 0: print("INFO: fills:", batch) else: print(" ", batch) - polsStr = [str(item) for item in polarities - ] # str() gets rid of unicode flag preceding each string - #print(f"INFO: polarities = {polsStr}") + polsStr = [ + str(item) for item in polarities + ] # str() gets rid of unicode flag preceding each string + # print(f"INFO: polarities = {polsStr}") for i in range(0, len(polarities), 14): - batch = polarities[i:i + 14] + batch = polarities[i : i + 14] if i == 0: print("INFO: polarities:", batch) else: print(" ", batch) cancel = False - preSubject = '' - preText = '' - postSubject = '' - postText = '' + preSubject = "" + preText = "" + postSubject = "" + postText = "" polarityMiss = [] calibMissing = [] polarityDiff = [] - if flat is False: # Check RICH calibrations exist # PN: We have no idea how to do this yet for Run 3 + if ( + flat is False + ): # Check RICH calibrations exist # PN: We have no idea how to do this yet for Run 3 for i in range(0, len(runs)): ## PN: We have no idea what the calib locations are. In Run 2 we needed calibrations before we could place alignments. For now comment this part out. - ''' + """ calibLoc = f"/group/online/hlt/conditions/LHCb/NoYear/{int(math.floor(int(runs[i]) / 1000.0))}/{runs[i]}/rich{whichRich}" if useDD4hep: calibLoc = f"{calibLoc}calib.yml" # PN - eventually find out where this is for Run 3 @@ -389,14 +409,14 @@ def run(whichRich, offline=False, runInlineReco=False): if not os.path.exists(calibLoc): print(f"WARNING: Missing RICH calibration detected: {calibLoc}") calibMissing.append(runs[i]) - ''' + """ ## PN: For now, do not check that all data has the same known polarity. We will want to re-enable this during fully automated running. - ''' + """ if (polarities[i] == 'OFF') or (polarities[i] != polarities[0]): polarityDiff.append(runs[i]) if (polarities[i] is None): polarityMiss.append(runs[i]) - ''' + """ pass sys.stdout.flush() @@ -406,7 +426,7 @@ def run(whichRich, offline=False, runInlineReco=False): state = State.NOT_READY if flat is False: # Get the Communicator - com = Communicator('ALIGNITER') + com = Communicator("ALIGNITER") print("INFO: Communicator started.") if flat is False: # Set the state com.set_status(state) @@ -430,13 +450,23 @@ def run(whichRich, offline=False, runInlineReco=False): if not cancel: if flat is False: # Get Command command = com.get_command() - if "state" in command: # ignore strange "!state" command from Run Control + if ( + "state" in command + ): # ignore strange "!state" command from Run Control command = com.get_command() print(f"INFO: Iterator Receiving command: {command}") print("INFO: ----------------------------") acceptable_commands = [ - "configure", "start", "pause", "reset", "stop", "c", "s", "p", - "r", "t" + "configure", + "start", + "pause", + "reset", + "stop", + "c", + "s", + "p", + "r", + "t", ] if flat is False: pass @@ -477,11 +507,11 @@ def run(whichRich, offline=False, runInlineReco=False): if command == "t": command = "stop" else: - command = 'reset' + command = "reset" ######################################################################################################################## ##### this code will be executed when you click configure on the run-control ######################################################################################################################## - if command.startswith('configure') and state == State.NOT_READY: + if command.startswith("configure") and state == State.NOT_READY: print( f"INFO: CONFIGURE command received at {strftime('%Y-%m-%d %H:%M:%S', gmtime())} UTC" ) @@ -514,7 +544,9 @@ def run(whichRich, offline=False, runInlineReco=False): if polarityDiff and calibMissing: cancel = True - cancelSubject = f"TEST [{alignConf.getProp('dataVariant')}]: " if testing else "" + cancelSubject = ( + f"TEST [{alignConf.getProp('dataVariant')}]: " if testing else "" + ) cancelSubject += f"WARNING: RICH{whichRich} mirror alignment {setupHelper.directoryTime} started, but has been cancelled (polarityDiff and calibMissing)." cancelText = f"RICH{whichRich} mirror alignment {setupHelper.directoryTime} started, but has been cancelled. \n " cancelText += f"Data for these runs contain magnet OFF data *or* are of mixed polarity: {polarityDiff} \n " @@ -522,8 +554,10 @@ def run(whichRich, offline=False, runInlineReco=False): cancelText += f"List of all selected Runs: {runs} \n Fills: {fills} \n Polarities: {polsStr}" print("INFO: Sending email: polarityDiff and calibMissing") setupHelper.sendEmail( - cancelSubject, cancelText, - setupHelper.emails if not testing else setupHelper.experts) + cancelSubject, + cancelText, + setupHelper.emails if not testing else setupHelper.experts, + ) print("WARNING: Mirror alignment will be skipped.") print( f"WARNING: These runs contain magnet OFF data *or* data for these runs is of mixed polarity: {polarityDiff}" @@ -532,129 +566,158 @@ def run(whichRich, offline=False, runInlineReco=False): f"WARNING: These runs do not yet have RICH calibrations available: {calibMissing}" ) messageID = setupHelper.quickWriteInLogbook( - subject=cancelSubject, text=cancelText) + subject=cancelSubject, text=cancelText + ) # Mismatched polarity check elif polarityDiff: cancel = True - cancelSubject = f"TEST [{alignConf.getProp('dataVariant')}]: " if testing else '' + cancelSubject = ( + f"TEST [{alignConf.getProp('dataVariant')}]: " if testing else "" + ) cancelSubject += f"WARNING: RICH{whichRich} mirror alignment {setupHelper.directoryTime} started, but has been cancelled (polarityDiff)." cancelText = f"RICH{whichRich} mirror alignment {setupHelper.directoryTime} started, but has been cancelled. \n" cancelText += f"Data for these runs contain magnet OFF data *or* are of mixed polarity: {polarityDiff} \n \n" cancelText += f"List of all selected Runs: {runs} \n Fills: {fills} \n Polarities: {polsStr}" print("INFO: Sending email: polarityDiff") setupHelper.sendEmail( - cancelSubject, cancelText, - setupHelper.emails if not testing else setupHelper.experts) + cancelSubject, + cancelText, + setupHelper.emails if not testing else setupHelper.experts, + ) print("WARNING: Mirror alignment will be skipped.") print( f"WARNING: These runs contain magnet OFF data *or* data for these runs is of mixed polarity: {polarityDiff}" ) messageID = setupHelper.quickWriteInLogbook( - subject=cancelSubject, text=cancelText) + subject=cancelSubject, text=cancelText + ) # RICH calibrations availability check elif calibMissing: cancel = True - cancelSubject = f"TEST [{alignConf.getProp('dataVariant')}]: " if testing else '' + cancelSubject = ( + f"TEST [{alignConf.getProp('dataVariant')}]: " if testing else "" + ) cancelSubject += f"WARNING: RICH{whichRich} mirror alignment {setupHelper.directoryTime} started, but has been cancelled (calibMissing)." cancelText = f"RICH{whichRich} mirror alignment {setupHelper.directoryTime} started, but has been cancelled. \n " cancelText += f"Data for these runs do not yet have RICH calibrations available: {calibMissing} \n \n " cancelText += f"List of all selected Runs: {runs} \n Fills: {fills} \n Polarities: {polsStr}" print("INFO: Sending email: calibMissing") setupHelper.sendEmail( - cancelSubject, cancelText, - setupHelper.emails if not testing else setupHelper.experts) + cancelSubject, + cancelText, + setupHelper.emails if not testing else setupHelper.experts, + ) print("WARNING: Mirror alignment will be skipped.") print( f"WARNING: These runs do not yet have RICH calibrations available: {calibMissing}" ) messageID = setupHelper.quickWriteInLogbook( - subject=cancelSubject, text=cancelText) + subject=cancelSubject, text=cancelText + ) # Missing polarity info elif polarityMiss: - preSubject += f'WARNING: Some polarity information was missing, but ' - preText += f'Polarity information for these runs is currently not found: {polarityMiss} \n' + preSubject += f"WARNING: Some polarity information was missing, but " + preText += f"Polarity information for these runs is currently not found: {polarityMiss} \n" print( f"WARNING: Polarity information for these runs is currently not found: {polarityMiss}. This alignment will continue as normal." ) forcedUpdate_ChMagPol = False - ChMagPolSubject = '' - ChMagPolText = '' + ChMagPolSubject = "" + ChMagPolText = "" if flat is False: if "online" in getpass.getuser(): pass else: - polarities.append( - 'UP') # PN: fake a magnet polarity for testbench + polarities.append("UP") # PN: fake a magnet polarity for testbench else: polarities.append( - 'UP' + "UP" ) # PN: we must fake a magnet polarity for Iterator_flat if (not cancel) and (polarities[0] is not None): - oldPolarityFilename = f"{polarityDir}previousPolarity_RICH{whichRich}.txt" - newPolarityFilename = f"{polarityDir}currentPolarity_RICH{whichRich}.txt" - #os.system("quota -s") + oldPolarityFilename = ( + f"{polarityDir}previousPolarity_RICH{whichRich}.txt" + ) + newPolarityFilename = ( + f"{polarityDir}currentPolarity_RICH{whichRich}.txt" + ) + # os.system("quota -s") print(newPolarityFilename) try: - with open(newPolarityFilename, - 'w') as currentAlignPolarityFile: + with open(newPolarityFilename, "w") as currentAlignPolarityFile: currentAlignPolarityFile.write( - f"{polarities[0]}\n{runs}\n{fills}\n") + f"{polarities[0]}\n{runs}\n{fills}\n" + ) except: print("Got a Disk Quota Exceeded, continuing...") if os.path.exists(oldPolarityFilename): - with open(oldPolarityFilename, - 'r') as previousAlignPolarityFile: + with open(oldPolarityFilename, "r") as previousAlignPolarityFile: first_line = previousAlignPolarityFile.readline() - if (first_line != f"{polarities[0]}\n"): - ChMagPolEmailSubject = f"TEST [{alignConf.getProp('dataVariant')}]: " if testing else '' + if first_line != f"{polarities[0]}\n": + ChMagPolEmailSubject = ( + f"TEST [{alignConf.getProp('dataVariant')}]: " + if testing + else "" + ) ChMagPolEmailSubject += f"WARNING: MAGNET POLARITY CHANGE! RICH{whichRich} mirror alignment {setupHelper.directoryTime}." ChMagPolEmailText = f"WARNING: MAGNET POLARITY CHANGE from \n {first_line} to {polarities[0]} \n RICH{whichRich} mirror alignment {setupHelper.directoryTime}. \n Runs: {runs} \n Fills: {fills} \n Polarities: {polsStr} \n dataVariant: {alignConf.getProp('dataVariant')}" print("INFO: Sending email: Magnet Polarity Change") setupHelper.sendEmail( - ChMagPolEmailSubject, ChMagPolEmailText, - setupHelper.emails - if not testing else setupHelper.experts) + ChMagPolEmailSubject, + ChMagPolEmailText, + setupHelper.emails if not testing else setupHelper.experts, + ) forcedUpdate_ChMagPol = True - ChMagPolSubject += 'Magnet Polarity Changed; possibly forcing update.' - ChMagPolText += f'If this alignment converges and passes sanity checks, the alignment will be updated due to a change in magnet polarity (unless autoUpdate is/becomes False, or testing is True). If there are any problems with this alignment, please contact the Mirror Alignment expert! They should check previousPolarity_RICH in {polarityDir} to ensure the proper behavior on the next attempt!' - postSubject += f' {ChMagPolSubject}' - postText += f' \n {ChMagPolText}' + ChMagPolSubject += ( + "Magnet Polarity Changed; possibly forcing update." + ) + ChMagPolText += f"If this alignment converges and passes sanity checks, the alignment will be updated due to a change in magnet polarity (unless autoUpdate is/becomes False, or testing is True). If there are any problems with this alignment, please contact the Mirror Alignment expert! They should check previousPolarity_RICH in {polarityDir} to ensure the proper behavior on the next attempt!" + postSubject += f" {ChMagPolSubject}" + postText += f" \n {ChMagPolText}" print( "INFO: Magnet Polarity Changed; if this alignment converges under normal conditions, then the alignment will be updated." ) # PN: This next four-line section confuses me, why are we overwriting here? Should investigate whether this is correct or not. # Next two lines only get used at the end if things fail - ChMagPolSubject = ' WARNING: The magnet polarity changed!' - ChMagPolText = ' \n WARNING: The magnet polarity changed! Make sure that everything (e.g. previousPolarity_RICH) is in order for the next alignment!!!' + ChMagPolSubject = " WARNING: The magnet polarity changed!" + ChMagPolText = " \n WARNING: The magnet polarity changed! Make sure that everything (e.g. previousPolarity_RICH) is in order for the next alignment!!!" # OUTDATED: The expert should re-flip the magnet polarity for this Rich detector in {polarityDir} in order to have the proper behavior on the next attempt!!! sys.stdout.flush() - if (not cancel): - leadText = '' + if not cancel: + leadText = "" if testing: - leadText += f'TEST [{alignConf.getProp("dataVariant")}]: ' - totalSubject = f'{leadText}{preSubject}RICH{whichRich} alignment {setupHelper.directoryTime} has started.{postSubject}' - if alignConf.getProp("MajItStart") != 0 or alignConf.getProp( - "MinItStart") != 0: - totalSubject = f'{leadText}{preSubject}RICH{whichRich} alignment {setupHelper.directoryTime} has started from Iteration _i{alignConf.getProp("MajItStart")}, Minor Iteration {alignConf.getProp("MinItStart")}.{postSubject}' - totalText = f'{preText} RICH{whichRich} mirror alignment {setupHelper.directoryTime} has started. \n Runs: {runs} \n Fills: {fills} \n Polarities: {polsStr}{postText} \n dataVariant: {alignConf.getProp("dataVariant")}' - if alignConf.getProp("MajItStart") != 0 or alignConf.getProp( - "MinItStart") != 0: - totalText = f'{preText} RICH{whichRich} mirror alignment {setupHelper.directoryTime} has started from Iteration _i{alignConf.getProp("MajItStart")}, Minor Iteration {alignConf.getProp("MinItStart")}. \n Runs: {runs} \n Fills: {fills} \n Polarities: {polsStr}{postText} \n dataVariant: {alignConf.getProp("dataVariant")}' + leadText += f"TEST [{alignConf.getProp('dataVariant')}]: " + totalSubject = f"{leadText}{preSubject}RICH{whichRich} alignment {setupHelper.directoryTime} has started.{postSubject}" + if ( + alignConf.getProp("MajItStart") != 0 + or alignConf.getProp("MinItStart") != 0 + ): + totalSubject = f"{leadText}{preSubject}RICH{whichRich} alignment {setupHelper.directoryTime} has started from Iteration _i{alignConf.getProp('MajItStart')}, Minor Iteration {alignConf.getProp('MinItStart')}.{postSubject}" + totalText = f"{preText} RICH{whichRich} mirror alignment {setupHelper.directoryTime} has started. \n Runs: {runs} \n Fills: {fills} \n Polarities: {polsStr}{postText} \n dataVariant: {alignConf.getProp('dataVariant')}" + if ( + alignConf.getProp("MajItStart") != 0 + or alignConf.getProp("MinItStart") != 0 + ): + totalText = f"{preText} RICH{whichRich} mirror alignment {setupHelper.directoryTime} has started from Iteration _i{alignConf.getProp('MajItStart')}, Minor Iteration {alignConf.getProp('MinItStart')}. \n Runs: {runs} \n Fills: {fills} \n Polarities: {polsStr}{postText} \n dataVariant: {alignConf.getProp('dataVariant')}" setupHelper.sendEmail( - totalSubject, totalText, - setupHelper.emails if not testing else setupHelper.experts) + totalSubject, + totalText, + setupHelper.emails if not testing else setupHelper.experts, + ) postText += " \n \n If this alignment does not finish, and this is not a TEST alignment, please report this via the RICH ELOG. \n " - totalText = f'{preText} RICH{whichRich} mirror alignment {setupHelper.directoryTime} has started. \n Runs: {runs} \n Fills: {fills} \n Polarities: {polsStr}{postText} \n dataVariant: {alignConf.getProp("dataVariant")}' - if alignConf.getProp("MajItStart") != 0 or alignConf.getProp( - "MinItStart") != 0: - totalText = f'{preText} RICH{whichRich} mirror alignment {setupHelper.directoryTime} has started from Iteration _i{alignConf.getProp("MajItStart")}, Minor Iteration {alignConf.getProp("MinItStart")}. \n Runs: {runs} \n Fills: {fills} \n Polarities: {polsStr}{postText} \n dataVariant: {alignConf.getProp("dataVariant")}' + totalText = f"{preText} RICH{whichRich} mirror alignment {setupHelper.directoryTime} has started. \n Runs: {runs} \n Fills: {fills} \n Polarities: {polsStr}{postText} \n dataVariant: {alignConf.getProp('dataVariant')}" + if ( + alignConf.getProp("MajItStart") != 0 + or alignConf.getProp("MinItStart") != 0 + ): + totalText = f"{preText} RICH{whichRich} mirror alignment {setupHelper.directoryTime} has started from Iteration _i{alignConf.getProp('MajItStart')}, Minor Iteration {alignConf.getProp('MinItStart')}. \n Runs: {runs} \n Fills: {fills} \n Polarities: {polsStr}{postText} \n dataVariant: {alignConf.getProp('dataVariant')}" print( f"INFO: RICH{whichRich} mirror alignment {setupHelper.directoryTime} has started, dataVariant: {alignConf.getProp('dataVariant')}" ) sys.stdout.flush() messageID = setupHelper.quickWriteInLogbook( - subject=totalSubject, text=totalText) + subject=totalSubject, text=totalText + ) sys.stdout.flush() configureDone = True @@ -663,7 +726,7 @@ def run(whichRich, offline=False, runInlineReco=False): ######################################################################################################################## ##### setting up the alignment and starting the first minor iteration (this only for the very first iteration) ######################################################################################################################## - elif (command.startswith('start') and state == State.READY): + elif command.startswith("start") and state == State.READY: print( f"INFO: START command received at {strftime('%Y-%m-%d %H:%M:%S', gmtime())} UTC" ) @@ -680,8 +743,9 @@ def run(whichRich, offline=False, runInlineReco=False): try: elapsed_time_config except NameError: - elapsed_time_config = time( - ) - start_time_config # LHCbA configuration time + elapsed_time_config = ( + time() - start_time_config + ) # LHCbA configuration time else: elapsed_time_config = 0.0 # we were already configured if (n_it == 0) and (m_it == 0): @@ -693,16 +757,18 @@ def run(whichRich, offline=False, runInlineReco=False): ) # only accurate if LHCbA AutoPilot is ON elapsed_runtimes = { - 'elapsed_time_run': 0.0, - 'elapsed_times_RichMirrCombinFit': [], - 'elapsed_times_RichMirrAlign': [], - 'elapsed_times_RichMirrRunReco': [] + "elapsed_time_run": 0.0, + "elapsed_times_RichMirrCombinFit": [], + "elapsed_times_RichMirrAlign": [], + "elapsed_times_RichMirrRunReco": [], } start_time_run = time() print("INFO: Alignment start time set.") sys.stdout.flush() - if flat is False: ### write the file for the analyzers to know which iteration they are at - PN: This may no longer be needed or used? + if ( + flat is False + ): ### write the file for the analyzers to know which iteration they are at - PN: This may no longer be needed or used? f = open(alignConf.getProp("ItNrFile"), "w") f.write(str(m_it)) f.close() @@ -710,15 +776,11 @@ def run(whichRich, offline=False, runInlineReco=False): ### if you want to start the alignment from scratch (e.g. at the m_it = 0) if m_it == 0: - #clean up the working directory + # clean up the working directory if YAMLio: - print( - "INFO: Setting up the folders and getting the starting YAML" - ) + print("INFO: Setting up the folders and getting the starting YAML") else: - print( - "INFO: Setting up the folders and getting the starting XML" - ) + print("INFO: Setting up the folders and getting the starting XML") print(f"INFO: Removing everything in {workdir}") for f in os.listdir(workdir): if os.path.isdir(f"{workdir}/{f}"): @@ -735,27 +797,34 @@ def run(whichRich, offline=False, runInlineReco=False): combAndMirrSubsets) """ - #consistency workflow timestamp + # consistency workflow timestamp yaml = YAML() ts = setupHelper.dt - with open(f"{workdir}rich{whichRich}_session_timestamp.yml", - "w") as fout: + with open( + f"{workdir}rich{whichRich}_session_timestamp.yml", "w" + ) as fout: yaml.dump(ts, fout) - #construction of the consistency workflow variant - mp = alignConf.getProp('dataVariant') - useHltDecisions = alignConf.getProp('useHltDecisions') + # construction of the consistency workflow variant + mp = alignConf.getProp("dataVariant") + useHltDecisions = alignConf.getProp("useHltDecisions") # currently does not care if RICH1 or RICH2 - evt_max_for_offline_and_testbench = 25000 * 1000 # this sets a high max when running over a large data sample where we don't use HLT decisions + evt_max_for_offline_and_testbench = ( + 25000 * 1000 + ) # this sets a high max when running over a large data sample where we don't use HLT decisions - minP = alignConf.getProp('minP') + minP = alignConf.getProp("minP") SubsetStr = "" if setupHelper.usingReducedSubset is True: - evt_max_for_offline_and_testbench = 50 * 1000 # 2 * typical for aligning inner mirrors subset only, running on minbias + evt_max_for_offline_and_testbench = ( + 50 * 1000 + ) # 2 * typical for aligning inner mirrors subset only, running on minbias if whichRich == 2: - evt_max_for_offline_and_testbench = 400 * 1000 # 2 * typical for aligning inner mirrors subset only, running on minbias + evt_max_for_offline_and_testbench = ( + 400 * 1000 + ) # 2 * typical for aligning inner mirrors subset only, running on minbias SubsetStr = "_subset" n_kevts = f"{math.trunc(evt_max_for_offline_and_testbench / 1000)}k" # online we do not know this a priori @@ -774,7 +843,7 @@ def run(whichRich, offline=False, runInlineReco=False): # # PN - Guessing that the missing p in MapExlore is intentional mirror_align_tasks = [ - 'Produce', # fill the production set of histograms + "Produce", # fill the production set of histograms #'Monitor', # add various checking histograms #'MapExlore', # explore tracks and photons for the HLT1 pre-selection line "map" #'MapConstruct', # construct exploratory data structure for the HLT1 pre-selection line "map" @@ -788,16 +857,16 @@ def run(whichRich, offline=False, runInlineReco=False): #'SkipFilled', # check filling all RICH2 mirror combinations with skipping when filled ] # cumulative substring with all tasks chosen - tasks = '' + tasks = "" for task in mirror_align_tasks: - tasks += f'_{task}' + tasks += f"_{task}" # # form the current variant name - current_variant = f'{ts}_rich{whichRich}{addinfo}{tasks}' + current_variant = f"{ts}_rich{whichRich}{addinfo}{tasks}" ####################################################################### # record the current variant name into the YAML file - with open(f'{workdir}rich{whichRich}_variant.yml', 'w') as out: + with open(f"{workdir}rich{whichRich}_variant.yml", "w") as out: yaml.dump(current_variant, out) currentMirrorDBFilePre = f"{workdir}{current_variant}_conds_i{n_it}" @@ -806,15 +875,13 @@ def run(whichRich, offline=False, runInlineReco=False): f"{currentMirrorDBFilePre}.yml" ) ### get the starting-yml from the database if not useDD4hep: - conversionsHelper.conv_YAML( - f"{currentMirrorDBFilePre}.yml") + conversionsHelper.conv_YAML(f"{currentMirrorDBFilePre}.yml") else: xmlHelper.getStartXML( f"{currentMirrorDBFilePre}.xml" ) ### get the starting-xml from the database if not useDD4hep: - conversionsHelper.conv_XML( - f"{currentMirrorDBFilePre}.xml") + conversionsHelper.conv_XML(f"{currentMirrorDBFilePre}.xml") if not magnFactorsMode == 0: if useDD4hep: @@ -842,27 +909,28 @@ def run(whichRich, offline=False, runInlineReco=False): os.path.join(workdir, f), os.path.join( workdir, - f.replace(f[:f.find("_magnifs")], - current_variant))) + f.replace(f[: f.find("_magnifs")], current_variant), + ), + ) # YAMLify magnification factors [currently for records only] if not os.path.exists( - f"{workdir}rich{whichRich}_MirrMagnFactors_predefined.yml" + f"{workdir}rich{whichRich}_MirrMagnFactors_predefined.yml" ): convert_magnFactors_txt_YAML.to_yaml(workdir) ### if you want to start from some arbitrary minor iteration else: - #this method will keep all files needed when starting at m_it > 0 + # this method will keep all files needed when starting at m_it > 0 setupHelper.startMinIt(m_it) - #shutil.copyfile( # flat is True + # shutil.copyfile( # flat is True # "/group/rich/pnaik/input_Iterator_flat/Claire/rich2_variant.yml", # workdir + "rich2_variant.yml") # - #shutil.copyfile( + # shutil.copyfile( # "/group/rich/pnaik/input_Iterator_flat/Claire/2022-07-20T21-10_rich2_minp60_qnt20f60_rndmpresc_unknown0k_conds_i3.yml", # workdir + # "2022-07-20T21-10_rich2_minp60_qnt20f60_rndmpresc_unknown0k_conds_i3.yml" - #) # + # ) # # We have to reload the variant name here, since we may be starting from a non-"zeroth" iteration yaml = YAML() @@ -891,8 +959,7 @@ def run(whichRich, offline=False, runInlineReco=False): print(f"INFO: *************************** ") yaml = YAML() - with open(f"{workdir}rich{whichRich}_iter_number.yml", - 'w') as fout: + with open(f"{workdir}rich{whichRich}_iter_number.yml", "w") as fout: yaml.dump(n_it, fout) if m_it > 99: @@ -903,7 +970,7 @@ def run(whichRich, offline=False, runInlineReco=False): print(f"INFO: Minor iteration {m_it}**********") yaml = YAML() - with open(f"{workdir}rich{whichRich}_tilt_name.yml", 'w') as fout: + with open(f"{workdir}rich{whichRich}_tilt_name.yml", "w") as fout: yaml.dump(tiltNames[m_it % tiltNamesLength], fout) # Create analyzerOutDir @@ -914,21 +981,16 @@ def run(whichRich, offline=False, runInlineReco=False): try: os.chmod(analyzerOutDir, 0o775) except: - print( - f"WARNING: failed os.chmod({analyzerOutDir}, 0o775)" - ) + print(f"WARNING: failed os.chmod({analyzerOutDir}, 0o775)") print(f"INFO: Creating {analyzerOutDir}") except: print(f"WARNING: failed to make {analyzerOutDir}") - analyzerOutDir = os.path.join(analyzerOutDir, '') + analyzerOutDir = os.path.join(analyzerOutDir, "") yaml = YAML() - with open(f"{workdir}rich{whichRich}_runAnalyzer.yml", - 'w') as fout: + with open(f"{workdir}rich{whichRich}_runAnalyzer.yml", "w") as fout: yaml.dump("YES", fout) - print( - f"INFO: {workdir}rich{whichRich}_runAnalyzer.yml set to 'YES'" - ) + print(f"INFO: {workdir}rich{whichRich}_runAnalyzer.yml set to 'YES'") if flat and runInlineReco: start_time_RichMirrRunReco = time() @@ -940,12 +1002,12 @@ def run(whichRich, offline=False, runInlineReco=False): richAnalyzerOutFile = f"{analyzerOutDir}Rich{whichRich}AnalyzerOut{tiltNameRecoStr}_i{n_it}.txt" richAnalyzerStdOutFile = f"{analyzerOutDir}Rich{whichRich}AnalyzerStdOut{tiltNameRecoStr}_i{n_it}.txt" richAnalyzerStdErrFile = f"{analyzerOutDir}Rich{whichRich}AnalyzerStdErr{tiltNameRecoStr}_i{n_it}.txt" - myStdOut = open(richAnalyzerStdOutFile, 'w') - myStdErr = open(richAnalyzerStdErrFile, 'w') + myStdOut = open(richAnalyzerStdOutFile, "w") + myStdErr = open(richAnalyzerStdErrFile, "w") if m_it % tiltNamesLength != 0: tiltNameRecoStr = f" {tiltNames[m_it % tiltNamesLength]}" cmd = f"cd {workdir} ; {stackDir}Panoptes/run gaudirun.py {stackDir}Panoptes/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/MirrorAlignment/data_online.py {stackDir}Panoptes/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/MirrorAlignment/hlt2_reco_rich{whichRich}_noUT_panoptes_dd4hep_both.py > {richAnalyzerOutFile} ; cd -" - #cmd = f"cd {workdir} ; echo -n{tiltNameRecoStr} {n_it} | /group/rich/sw/alignment/stack/Panoptes/run gaudirun.py /group/rich/sw/alignment/stack/Panoptes/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/MirrorAlignment/data_online.py /group/rich/sw/alignment/stack/Panoptes/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/MirrorAlignment/hlt2_reco_rich{whichRich}_noUT_panoptes_dd4hep-both.py > {richAnalyzerOutFile} ; cd -" + # cmd = f"cd {workdir} ; echo -n{tiltNameRecoStr} {n_it} | /group/rich/sw/alignment/stack/Panoptes/run gaudirun.py /group/rich/sw/alignment/stack/Panoptes/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/MirrorAlignment/data_online.py /group/rich/sw/alignment/stack/Panoptes/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/MirrorAlignment/hlt2_reco_rich{whichRich}_noUT_panoptes_dd4hep-both.py > {richAnalyzerOutFile} ; cd -" print(f"INFO: Starting Inline Reconstruction. ") print(f"INFO: cmd = {cmd}") p4 = subprocess.Popen( @@ -953,7 +1015,8 @@ def run(whichRich, offline=False, runInlineReco=False): shell=True, executable="/bin/bash", stdout=myStdOut, - stderr=myStdErr) + stderr=myStdErr, + ) p4.communicate() print("INFO: Inline Reconstruction Complete. ") myStdOut.close() @@ -961,9 +1024,9 @@ def run(whichRich, offline=False, runInlineReco=False): sys.stdout.flush() hh, r = divmod(time() - start_time_RichMirrRunReco, 3600) mm, ss = divmod(r, 60) - elapsed_runtimes['elapsed_times_RichMirrRunReco'].append( - "{:0>2}:{:0>2}:{:05.2f}".format( - int(hh), int(mm), ss)) # RichMirrRunReco run time + elapsed_runtimes["elapsed_times_RichMirrRunReco"].append( + "{:0>2}:{:0>2}:{:05.2f}".format(int(hh), int(mm), ss) + ) # RichMirrRunReco run time # increase the minor iteration counter if magnFactorsMode == 0: @@ -979,7 +1042,7 @@ def run(whichRich, offline=False, runInlineReco=False): ######################################################################################################################## ##### here's the code for all the following iterations ######################################################################################################################## - elif (command.startswith('pause') and state == State.RUNNING): + elif command.startswith("pause") and state == State.RUNNING: print( f"INFO: PAUSE command received at {strftime('%Y-%m-%d %H:%M:%S', gmtime())} UTC" ) @@ -988,14 +1051,13 @@ def run(whichRich, offline=False, runInlineReco=False): com.set_status(state) yaml = YAML() - with open(f"{workdir}rich{whichRich}_runAnalyzer.yml", - 'w') as fout: + with open(f"{workdir}rich{whichRich}_runAnalyzer.yml", "w") as fout: yaml.dump("NO", fout) - print( - f"INFO: {workdir}rich{whichRich}_runAnalyzer.yml set to 'NO'" - ) + print(f"INFO: {workdir}rich{whichRich}_runAnalyzer.yml set to 'NO'") - if flat is False: # write new minor iteration number to file for the analyzers to read + if ( + flat is False + ): # write new minor iteration number to file for the analyzers to read f = open(alignConf.getProp("ItNrFile"), "w") f.write(str(m_it)) f.close() @@ -1024,12 +1086,9 @@ def run(whichRich, offline=False, runInlineReco=False): allDone = False # if the minor iterations for one major iteration have finished perform fits etc: - if (m_it % tiltNamesLength == 0): - print( - f"INFO: minor iterations for major iteration {n_it} finished" - ) - print( - f"INFO: now merge the rootfiles and perform alignment") + if m_it % tiltNamesLength == 0: + print(f"INFO: minor iterations for major iteration {n_it} finished") + print(f"INFO: now merge the rootfiles and perform alignment") if flat is False: pass @@ -1038,94 +1097,96 @@ def run(whichRich, offline=False, runInlineReco=False): else: # copy pre-made reconstruction files needed to run Iterator_flat if whichRich == 1: - input_Iterator_flat = "/group/rich/pnaik/input_Iterator_flat/Alex/" + input_Iterator_flat = ( + "/group/rich/pnaik/input_Iterator_flat/Alex/" + ) for x in [ - "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_conds_i0.yml", - "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_conds_i1.yml", - "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_conds_i2.yml", - "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_conds_i3.yml", - "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_conds_i4.yml", - "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_conds_i5.yml", - "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_conds_i6.yml", - "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_conds_i7.yml", - "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_conds_priYn_i0.yml", - "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_conds_priYp_i0.yml", - "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_conds_priZn_i0.yml", - "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_conds_priZp_i0.yml", - "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_conds_secYn_i0.yml", - "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_conds_secYp_i0.yml", - "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_conds_secZn_i0.yml", - "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_conds_secZp_i0.yml", - "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_histos_i0.root", - "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_histos_i1.root", - "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_histos_i2.root", - "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_histos_i3.root", - "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_histos_i4.root", - "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_histos_i5.root", - "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_histos_i6.root", - "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_histos_i7.root", - #"2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_histos_priYn_i0.root", - #"2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_histos_priYp_i0.root", - #"2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_histos_priZn_i0.root", - #"2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_histos_priZp_i0.root", - #"2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_histos_secYn_i0.root", - #"2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_histos_secYp_i0.root", - #"2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_histos_secZn_i0.root", - #"2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_histos_secZp_i0.root", - "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_magnifs_priYn_predefined.txt", - "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_magnifs_priYp_predefined.txt", - "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_magnifs_priZn_predefined.txt", - "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_magnifs_priZp_predefined.txt", - "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_magnifs_secYn_predefined.txt", - "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_magnifs_secYp_predefined.txt", - "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_magnifs_secZn_predefined.txt", - "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_magnifs_secZp_predefined.txt", - "rich1_fit_align_confs.yml", - #"rich2_iter_number.yml" , - "rich1_reco_opts.yml", - "rich1_session_timestamp.yml", - "rich1_variant.yml" + "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_conds_i0.yml", + "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_conds_i1.yml", + "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_conds_i2.yml", + "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_conds_i3.yml", + "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_conds_i4.yml", + "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_conds_i5.yml", + "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_conds_i6.yml", + "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_conds_i7.yml", + "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_conds_priYn_i0.yml", + "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_conds_priYp_i0.yml", + "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_conds_priZn_i0.yml", + "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_conds_priZp_i0.yml", + "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_conds_secYn_i0.yml", + "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_conds_secYp_i0.yml", + "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_conds_secZn_i0.yml", + "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_conds_secZp_i0.yml", + "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_histos_i0.root", + "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_histos_i1.root", + "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_histos_i2.root", + "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_histos_i3.root", + "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_histos_i4.root", + "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_histos_i5.root", + "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_histos_i6.root", + "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_histos_i7.root", + # "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_histos_priYn_i0.root", + # "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_histos_priYp_i0.root", + # "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_histos_priZn_i0.root", + # "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_histos_priZp_i0.root", + # "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_histos_secYn_i0.root", + # "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_histos_secYp_i0.root", + # "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_histos_secZn_i0.root", + # "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_histos_secZp_i0.root", + "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_magnifs_priYn_predefined.txt", + "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_magnifs_priYp_predefined.txt", + "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_magnifs_priZn_predefined.txt", + "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_magnifs_priZp_predefined.txt", + "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_magnifs_secYn_predefined.txt", + "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_magnifs_secYp_predefined.txt", + "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_magnifs_secZn_predefined.txt", + "2022-12-06T17-55_rich1_minp30_subset_Collision22_25k_Produce_magnifs_secZp_predefined.txt", + "rich1_fit_align_confs.yml", + # "rich2_iter_number.yml" , + "rich1_reco_opts.yml", + "rich1_session_timestamp.yml", + "rich1_variant.yml", ]: print( f"INFO: Copying {input_Iterator_flat + x} to {workdir + x}" ) - shutil.copyfile(input_Iterator_flat + x, - workdir + x) + shutil.copyfile(input_Iterator_flat + x, workdir + x) # if whichRich == 2: - input_Iterator_flat = "/group/rich/pnaik/input_Iterator_flat/Paras/" + input_Iterator_flat = ( + "/group/rich/pnaik/input_Iterator_flat/Paras/" + ) for x in [ - "2022-12-06T17-55_rich2_minp60_subset_Collision22_200k_Produce_conds_i0.yml", - "2022-12-06T17-55_rich2_minp60_subset_Collision22_200k_Produce_histos_i0.root", - "2022-12-06T17-55_rich2_minp60_subset_Collision22_200k_Produce_conds_i1.yml", - "2022-12-06T17-55_rich2_minp60_subset_Collision22_200k_Produce_histos_i1.root", - "2022-12-06T17-55_rich2_minp60_subset_Collision22_200k_Produce_conds_i2.yml", - "2022-12-06T17-55_rich2_minp60_subset_Collision22_200k_Produce_histos_i2.root", - "2022-12-06T17-55_rich2_minp60_subset_Collision22_200k_Produce_conds_i3.yml", - "2022-12-06T17-55_rich2_minp60_subset_Collision22_200k_Produce_histos_i3.root", - "2022-12-06T17-55_rich2_minp60_subset_Collision22_200k_Produce_conds_i4.yml", - "2022-12-06T17-55_rich2_minp60_subset_Collision22_200k_Produce_histos_i4.root", - "2022-12-06T17-55_rich2_minp60_subset_Collision22_200k_Produce_conds_i5.yml", - "2022-12-06T17-55_rich2_minp60_subset_Collision22_200k_Produce_histos_i5.root", - "2022-12-06T17-55_rich2_minp60_subset_Collision22_200k_Produce_magnifs_priYn_predefined.txt", - "2022-12-06T17-55_rich2_minp60_subset_Collision22_200k_Produce_magnifs_priYp_predefined.txt", - "2022-12-06T17-55_rich2_minp60_subset_Collision22_200k_Produce_magnifs_priZn_predefined.txt", - "2022-12-06T17-55_rich2_minp60_subset_Collision22_200k_Produce_magnifs_priZp_predefined.txt", - "2022-12-06T17-55_rich2_minp60_subset_Collision22_200k_Produce_magnifs_secYn_predefined.txt", - "2022-12-06T17-55_rich2_minp60_subset_Collision22_200k_Produce_magnifs_secYp_predefined.txt", - "2022-12-06T17-55_rich2_minp60_subset_Collision22_200k_Produce_magnifs_secZn_predefined.txt", - "2022-12-06T17-55_rich2_minp60_subset_Collision22_200k_Produce_magnifs_secZp_predefined.txt", - "rich2_fit_align_confs.yml", - #"rich2_iter_number.yml" , - "rich2_reco_opts.yml", - "rich2_session_timestamp.yml", - "rich2_variant.yml" + "2022-12-06T17-55_rich2_minp60_subset_Collision22_200k_Produce_conds_i0.yml", + "2022-12-06T17-55_rich2_minp60_subset_Collision22_200k_Produce_histos_i0.root", + "2022-12-06T17-55_rich2_minp60_subset_Collision22_200k_Produce_conds_i1.yml", + "2022-12-06T17-55_rich2_minp60_subset_Collision22_200k_Produce_histos_i1.root", + "2022-12-06T17-55_rich2_minp60_subset_Collision22_200k_Produce_conds_i2.yml", + "2022-12-06T17-55_rich2_minp60_subset_Collision22_200k_Produce_histos_i2.root", + "2022-12-06T17-55_rich2_minp60_subset_Collision22_200k_Produce_conds_i3.yml", + "2022-12-06T17-55_rich2_minp60_subset_Collision22_200k_Produce_histos_i3.root", + "2022-12-06T17-55_rich2_minp60_subset_Collision22_200k_Produce_conds_i4.yml", + "2022-12-06T17-55_rich2_minp60_subset_Collision22_200k_Produce_histos_i4.root", + "2022-12-06T17-55_rich2_minp60_subset_Collision22_200k_Produce_conds_i5.yml", + "2022-12-06T17-55_rich2_minp60_subset_Collision22_200k_Produce_histos_i5.root", + "2022-12-06T17-55_rich2_minp60_subset_Collision22_200k_Produce_magnifs_priYn_predefined.txt", + "2022-12-06T17-55_rich2_minp60_subset_Collision22_200k_Produce_magnifs_priYp_predefined.txt", + "2022-12-06T17-55_rich2_minp60_subset_Collision22_200k_Produce_magnifs_priZn_predefined.txt", + "2022-12-06T17-55_rich2_minp60_subset_Collision22_200k_Produce_magnifs_priZp_predefined.txt", + "2022-12-06T17-55_rich2_minp60_subset_Collision22_200k_Produce_magnifs_secYn_predefined.txt", + "2022-12-06T17-55_rich2_minp60_subset_Collision22_200k_Produce_magnifs_secYp_predefined.txt", + "2022-12-06T17-55_rich2_minp60_subset_Collision22_200k_Produce_magnifs_secZn_predefined.txt", + "2022-12-06T17-55_rich2_minp60_subset_Collision22_200k_Produce_magnifs_secZp_predefined.txt", + "rich2_fit_align_confs.yml", + # "rich2_iter_number.yml" , + "rich2_reco_opts.yml", + "rich2_session_timestamp.yml", + "rich2_variant.yml", ]: print( f"INFO: Copying {input_Iterator_flat + x} to {workdir + x}" ) - shutil.copyfile(input_Iterator_flat + x, - workdir + x) + shutil.copyfile(input_Iterator_flat + x, workdir + x) # ### run the mirror Alignment - In Run 3 we have to feed these YAML via the .conf files prepared by RichAlignmentHelper @@ -1134,21 +1195,20 @@ def run(whichRich, offline=False, runInlineReco=False): alignHelper.runMirrCombinFit(n_it) hh, r = divmod(time() - start_time_RichMirrCombinFit, 3600) mm, ss = divmod(r, 60) - elapsed_runtimes['elapsed_times_RichMirrCombinFit'].append( - "{:0>2}:{:0>2}:{:05.2f}".format( - int(hh), int(mm), ss)) # RichMirrCombinFit run time + elapsed_runtimes["elapsed_times_RichMirrCombinFit"].append( + "{:0>2}:{:0>2}:{:05.2f}".format(int(hh), int(mm), ss) + ) # RichMirrCombinFit run time - enoughBinsPopulated = alignHelper.checkEnoughBinsPopulated( - n_it) + enoughBinsPopulated = alignHelper.checkEnoughBinsPopulated(n_it) print(f"INFO: enoughBinsPopulated = {enoughBinsPopulated}") start_time_RichMirrAlign = time() alignHelper.runRichAlign(n_it) hh, r = divmod(time() - start_time_RichMirrAlign, 3600) mm, ss = divmod(r, 60) - elapsed_runtimes['elapsed_times_RichMirrAlign'].append( - "{:0>2}:{:0>2}:{:05.2f}".format( - int(hh), int(mm), ss)) # RichMirrAlign run time + elapsed_runtimes["elapsed_times_RichMirrAlign"].append( + "{:0>2}:{:0>2}:{:05.2f}".format(int(hh), int(mm), ss) + ) # RichMirrAlign run time ### pick up the new yml file from RichMirrAlign and format in in a way readable for the analyzers yaml = YAML() @@ -1188,7 +1248,7 @@ def run(whichRich, offline=False, runInlineReco=False): f"INFO: The alignment after Iteration {n_it} returns converged = {conv}" ) - if (conv or n_it >= maxIters): + if conv or n_it >= maxIters: allDone = True iterationsDone = True if conv and n_it >= maxIters: @@ -1204,8 +1264,9 @@ def run(whichRich, offline=False, runInlineReco=False): "INFO: *** The alignment has reached its maximum number of iterations and has not converged ***" ) - elapsed_runtimes['elapsed_time_run'] = time( - ) - start_time_run # Actual total iterating time + elapsed_runtimes["elapsed_time_run"] = ( + time() - start_time_run + ) # Actual total iterating time print( f"INFO: Elapsed time to run the Mirror Alignment set as {elapsed_runtimes['elapsed_time_run']} seconds." ) @@ -1215,18 +1276,19 @@ def run(whichRich, offline=False, runInlineReco=False): # this returns True if the monitoring sanity check failed. if YAMLio: ymlHelper.getCompareYAML( - compareDB) ### can be different from starting-yml + compareDB + ) ### can be different from starting-yml else: xmlHelper.getCompareXML( - compareDB) ### can be different from starting-xml - insane = setupHelper.monitor(n_it, compareDB, - forcedUpdate_ChMagPol) - #insane = False # If this needs to be faked + compareDB + ) ### can be different from starting-xml + insane = setupHelper.monitor(n_it, compareDB, forcedUpdate_ChMagPol) + # insane = False # If this needs to be faked print(f"INFO: alignMonitor.isInsane = {insane}") sys.stdout.flush() nEventsListList = setupHelper.getNEventsListList(n_it) - #nEventsListList = [[10000000], 10000000] # If this needs to be faked + # nEventsListList = [[10000000], 10000000] # If this needs to be faked print( f"INFO: Average number of events processed per iteration = {nEventsListList[1]}" ) @@ -1246,27 +1308,32 @@ def run(whichRich, offline=False, runInlineReco=False): print( "WARNING: Since the polarity changed as well, we force autoUpdateNoV to be True (HLT2 gets no version)." ) - sanitySubject += " Polarity changed so no version provided to HLT2." + sanitySubject += ( + " Polarity changed so no version provided to HLT2." + ) sanityText += "\n Since the polarity changed as well, no version was provided to HLT2. The mirror aligners should investigate." setupHelper.sendEmail( - f'autoUpdate disabled: Poor photon population in at least one of the RICH{whichRich} mirror combinations for RICH{whichRich} alignment {setupHelper.directoryTime}.{sanitySubject}', - f'RICH{whichRich} mirror alignment {setupHelper.directoryTime} autoUpdate changed from True to False.{sanityText}', + f"autoUpdate disabled: Poor photon population in at least one of the RICH{whichRich} mirror combinations for RICH{whichRich} alignment {setupHelper.directoryTime}.{sanitySubject}", + f"RICH{whichRich} mirror alignment {setupHelper.directoryTime} autoUpdate changed from True to False.{sanityText}", setupHelper.emails - if not testing else setupHelper.experts) + if not testing + else setupHelper.experts, + ) # This is not important enough to raise a WARNING to the Data Manager - alert = f'INFO: Rich{whichRich} mirror alignment could not make a decision due to poor photon population in at least one of the RICH mirror combinations.' + alert = f"INFO: Rich{whichRich} mirror alignment could not make a decision due to poor photon population in at least one of the RICH mirror combinations." else: print( f"WARNING: There is poor photon population in at least one of the RICH mirror combinations; autoUpdate was already False." ) setupHelper.sendEmail( - f'Poor photon population in at least one of the RICH{whichRich} mirror combinations, autoUpdate was already False.', - f'RICH{whichRich} mirror alignment {setupHelper.directoryTime} autoUpdate already False.', + f"Poor photon population in at least one of the RICH{whichRich} mirror combinations, autoUpdate was already False.", + f"RICH{whichRich} mirror alignment {setupHelper.directoryTime} autoUpdate already False.", setupHelper.emails - if not testing else setupHelper.experts) + if not testing + else setupHelper.experts, + ) - if nEventsListList[1] < int( - alignConf.getProp('requiredEvents')): + if nEventsListList[1] < int(alignConf.getProp("requiredEvents")): if autoUpdate_initial: autoUpdate = False print( @@ -1277,24 +1344,30 @@ def run(whichRich, offline=False, runInlineReco=False): print( "WARNING: Since the polarity changed as well, we force autoUpdateNoV to be True (HLT2 gets no version)." ) - sanitySubject += " Polarity changed so no version provided to HLT2." + sanitySubject += ( + " Polarity changed so no version provided to HLT2." + ) sanityText += f"\n Since the polarity changed as well, no version was provided to HLT2. The mirror aligners should investigate." setupHelper.sendEmail( - f'autoUpdate disabled: Lack of events processed for RICH{str(whichRich)} alignment {setupHelper.directoryTime}.{sanitySubject}', - f'RICH{str(whichRich)} mirror alignment {setupHelper.directoryTime} autoUpdate changed from True to False. \n Investigate HLT farm availability for the LHCbA partition. \n Average number of events processed per iteration: {str(nEventsListList[1])}{sanityText}', + f"autoUpdate disabled: Lack of events processed for RICH{str(whichRich)} alignment {setupHelper.directoryTime}.{sanitySubject}", + f"RICH{str(whichRich)} mirror alignment {setupHelper.directoryTime} autoUpdate changed from True to False. \n Investigate HLT farm availability for the LHCbA partition. \n Average number of events processed per iteration: {str(nEventsListList[1])}{sanityText}", setupHelper.emails - if not testing else setupHelper.experts) + if not testing + else setupHelper.experts, + ) # This is not important enough to raise a WARNING to the Data Manager - alert = f'INFO: Rich{str(whichRich)} mirror alignment could not make a decision due to lack of processed events. Investigate HLT farm availability for the LHCbA partition.' # There may have also been poor photon population. + alert = f"INFO: Rich{str(whichRich)} mirror alignment could not make a decision due to lack of processed events. Investigate HLT farm availability for the LHCbA partition." # There may have also been poor photon population. else: print( f"WARNING: We processed an average number of events per iteration of {nEventsListList[1]}, which is too low; autoUpdate was already False." ) setupHelper.sendEmail( - f'Lack of events processed for RICH{str(whichRich)} alignment {setupHelper.directoryTime}, autoUpdate was already False.', - f'RICH{str(whichRich)} mirror alignment {setupHelper.directoryTime} autoUpdate already False. \n Average number of events processed per iteration: {str(nEventsListList[1])}', + f"Lack of events processed for RICH{str(whichRich)} alignment {setupHelper.directoryTime}, autoUpdate was already False.", + f"RICH{str(whichRich)} mirror alignment {setupHelper.directoryTime} autoUpdate already False. \n Average number of events processed per iteration: {str(nEventsListList[1])}", setupHelper.emails - if not testing else setupHelper.experts) + if not testing + else setupHelper.experts, + ) if insane: if autoUpdate_initial: @@ -1307,43 +1380,55 @@ def run(whichRich, offline=False, runInlineReco=False): print( "WARNING: Since the polarity changed as well, we force autoUpdateNoV to be True (HLT2 gets no version)." ) - sanitySubject += " Polarity changed so no version provided to HLT2." + sanitySubject += ( + " Polarity changed so no version provided to HLT2." + ) sanityText += " Since the polarity changed as well, no version was provided to HLT2. The mirror aligners should investigate." setupHelper.sendEmail( - f'autoUpdate disabled: Tolerance sanity checks failed for RICH{str(whichRich)} alignment {setupHelper.directoryTime}.{sanitySubject}', - f'RICH{str(whichRich)} mirror alignment {setupHelper.directoryTime} autoUpdate changed from True to False. \n Tolerance sanity checks have failed for this alignment.{sanityText}', + f"autoUpdate disabled: Tolerance sanity checks failed for RICH{str(whichRich)} alignment {setupHelper.directoryTime}.{sanitySubject}", + f"RICH{str(whichRich)} mirror alignment {setupHelper.directoryTime} autoUpdate changed from True to False. \n Tolerance sanity checks have failed for this alignment.{sanityText}", setupHelper.emails - if not testing else setupHelper.experts) - alert = f'ERROR: Rich{str(whichRich)} mirror alignment converged but constants changes are unreasonably large; 8-21h (21h-8h): please call (email) the Alignment piquet.' # There may have also been a lack of processed events, or poor photon population. + if not testing + else setupHelper.experts, + ) + alert = f"ERROR: Rich{str(whichRich)} mirror alignment converged but constants changes are unreasonably large; 8-21h (21h-8h): please call (email) the Alignment piquet." # There may have also been a lack of processed events, or poor photon population. else: print( "WARNING: Tolerance sanity checks have failed; autoUpdate was already False." ) setupHelper.sendEmail( - f'Tolerance sanity checks failed for RICH{str(whichRich)} alignment {setupHelper.directoryTime}, autoUpdate was already False.', - f'RICH{str(whichRich)} mirror alignment {setupHelper.directoryTime} autoUpdate already False. \n Tolerance sanity checks have failed for this alignment.', + f"Tolerance sanity checks failed for RICH{str(whichRich)} alignment {setupHelper.directoryTime}, autoUpdate was already False.", + f"RICH{str(whichRich)} mirror alignment {setupHelper.directoryTime} autoUpdate already False. \n Tolerance sanity checks have failed for this alignment.", setupHelper.emails - if not testing else setupHelper.experts) + if not testing + else setupHelper.experts, + ) sys.stdout.flush() print( - f'ALEX {forcedUpdate_ChMagPol}, {updateHelper.updateDecision(n_it)}, {conv}' + f"ALEX {forcedUpdate_ChMagPol}, {updateHelper.updateDecision(n_it)}, {conv}" ) # if the alignment has converged AND there was no sanity problem AND we are not testing, overwrite the old polarity file with the new polarity file - if conv and not insane and not nEventsListList[1] < int( - alignConf.getProp( - 'requiredEvents')) and not testing: + if ( + conv + and not insane + and not nEventsListList[1] + < int(alignConf.getProp("requiredEvents")) + and not testing + ): try: copy( newPolarityFilename, # - oldPolarityFilename) # + oldPolarityFilename, + ) # except: print( f"WARNING: failed copy(newPolarityFilename,oldPolarityFilename)" ) - if (forcedUpdate_ChMagPol - or updateHelper.updateDecision(n_it)) and conv: + if ( + forcedUpdate_ChMagPol or updateHelper.updateDecision(n_it) + ) and conv: # if conv: # we now *always* use the newer YAML (XML) file [result of RichMirrAlign (result of RichMirrAlign, converted to XML)] when updating the mirror alignment, not the current YAML (XML) if YAMLio: @@ -1357,11 +1442,9 @@ def run(whichRich, offline=False, runInlineReco=False): else: vN_DB_str = f"v{int(latest_vN) + 1}" if YAMLio: - ymlHelper.finalYAML(vN_DB_str, - True) # current + 1 + ymlHelper.finalYAML(vN_DB_str, True) # current + 1 else: - xmlHelper.finalXML(vN_DB_str, - True) # current + 1 + xmlHelper.finalXML(vN_DB_str, True) # current + 1 if testing: setupHelper.finalize( # vN_DB_str, # @@ -1371,7 +1454,8 @@ def run(whichRich, offline=False, runInlineReco=False): elapsed_runtimes, # None, # nEventsListList, # - messageID) # + messageID, + ) # else: # If not testing, and autoUpdate is still on, it's a good alignment. setupHelper.finalize( # vN_DB_str, # @@ -1381,11 +1465,14 @@ def run(whichRich, offline=False, runInlineReco=False): elapsed_runtimes, # True, # nEventsListList, # - messageID) # - alert = f"INFO: Rich{whichRich} mirror alignment updated." + messageID, + ) # + alert = ( + f"INFO: Rich{whichRich} mirror alignment updated." + ) updateHelper.updateDB( - int(latest_vN) + 1, True, - alert) # current + 1 + int(latest_vN) + 1, True, alert + ) # current + 1 else: # autoUpdate was never True, or was True but now switched to False if testing: vN_DB_str = f"v{int(latest_vN) + 1}_testing_maybe_{setupHelper.directoryTime}" @@ -1393,10 +1480,12 @@ def run(whichRich, offline=False, runInlineReco=False): vN_DB_str = f"v{int(latest_vN) + 1}_maybe_{setupHelper.directoryTime}" if YAMLio: ymlHelper.finalYAML( - vN_DB_str, True) # (current + 1)_maybe + vN_DB_str, True + ) # (current + 1)_maybe else: - xmlHelper.finalXML(vN_DB_str, - True) # (current + 1)_maybe + xmlHelper.finalXML( + vN_DB_str, True + ) # (current + 1)_maybe setupHelper.finalize( vN_DB_str, # conv, # @@ -1405,15 +1494,15 @@ def run(whichRich, offline=False, runInlineReco=False): elapsed_runtimes, # None, # nEventsListList, # - messageID) # + messageID, + ) # if not testing: if not autoUpdateNoV: # provide the existing version ONLY if autoUpdate was always off, or autoUpdate was on but is now off *and* autoUpdateNoV remains False print( f"SENT UPDATE {testing} {autoUpdateNoV} SENT updateDB :{int(latest_vN)} False {alert}:" ) - updateHelper.updateDB( - int(latest_vN), False, alert) + updateHelper.updateDB(int(latest_vN), False, alert) else: print( f"{testing} {autoUpdateNoV} would have run updateDB {int(latest_vN)} {alert}" @@ -1422,10 +1511,10 @@ def run(whichRich, offline=False, runInlineReco=False): print( f"{testing} {autoUpdateNoV} would have run updateDB {int(latest_vN)} {alert}" ) - #updateHelper.stopUpdateDIM() + # updateHelper.stopUpdateDIM() else: - vN_DB_str = f'v{int(latest_vN)}' + vN_DB_str = f"v{int(latest_vN)}" setupHelper.finalize( vN_DB_str, conv, @@ -1438,14 +1527,13 @@ def run(whichRich, offline=False, runInlineReco=False): ) if not testing: if autoUpdate_initial and not conv: - alert = f'ERROR: Rich{whichRich} mirror alignment failed to converge; 8-21h (21h-8h): please call (email) the Alignment piquet.' # There may have also been a lack of processed events / sanity check failure. + alert = f"ERROR: Rich{whichRich} mirror alignment failed to converge; 8-21h (21h-8h): please call (email) the Alignment piquet." # There may have also been a lack of processed events / sanity check failure. updateHelper.updateDB( - int(latest_vN), False, alert) # current - #updateHelper.stopUpdateDIM() #PN: Better check if this is meant to be commented or not + int(latest_vN), False, alert + ) # current + # updateHelper.stopUpdateDIM() #PN: Better check if this is meant to be commented or not - print( - f"INFO: The Iterator state is about to be set to {state}." - ) + print(f"INFO: The Iterator state is about to be set to {state}.") state = State.READY # Final bits: save Configuration, OnlineEnvBase, and hlt02 logs @@ -1456,8 +1544,10 @@ def run(whichRich, offline=False, runInlineReco=False): if not cancel: try: - copy(origConfiguration, - f"{setupHelper.savedir}Configuration.py") + copy( + origConfiguration, + f"{setupHelper.savedir}Configuration.py", + ) print( f"INFO: Configuration.py stored in file: {setupHelper.savedir}Configuration.py" ) @@ -1465,23 +1555,25 @@ def run(whichRich, offline=False, runInlineReco=False): try: copy( origConfiguration, - f"{loggingDir}Rich{whichRich}_Configuration_{setupHelper.directoryTime}.py" + f"{loggingDir}Rich{whichRich}_Configuration_{setupHelper.directoryTime}.py", ) print( f"INFO: Configuration.py stored in file: {loggingDir}Rich{whichRich}_Configuration_{setupHelper.directoryTime}.py" ) except: - #print(f"WARNING: failed copy(origConfiguration, {loggingDir}Rich{whichRich}_Configuration_{setupHelper.directoryTime}.py)") + # print(f"WARNING: failed copy(origConfiguration, {loggingDir}Rich{whichRich}_Configuration_{setupHelper.directoryTime}.py)") copy( origConfiguration, - f"{launchDir}Rich{whichRich}_Configuration_{setupHelper.directoryTime}.py" + f"{launchDir}Rich{whichRich}_Configuration_{setupHelper.directoryTime}.py", ) print( f"INFO: Configuration.py stored in file: {launchDir}Rich{whichRich}_Configuration_{setupHelper.directoryTime}.py" ) try: - copy(origOnlineEnvBase, - f"{setupHelper.savedir}OnlineEnvBase.py") + copy( + origOnlineEnvBase, + f"{setupHelper.savedir}OnlineEnvBase.py", + ) print( f"INFO: OnlineEnvBase.py stored in file: {setupHelper.savedir}OnlineEnvBase.py" ) @@ -1489,16 +1581,16 @@ def run(whichRich, offline=False, runInlineReco=False): try: copy( origOnlineEnvBase, - f"{loggingDir}Rich{whichRich}_OnlineEnvBase_{setupHelper.directoryTime}.py" + f"{loggingDir}Rich{whichRich}_OnlineEnvBase_{setupHelper.directoryTime}.py", ) print( f"INFO: OnlineEnvBase.py stored in file: {loggingDir}Rich{whichRich}_OnlineEnvBase_{setupHelper.directoryTime}.py" ) except: - #print(f"WARNING: failed copy(origOnlineEnvBase, {loggingDir}Rich{whichRich}_OnlineEnvBase_{setupHelper.directoryTime}.py)") + # print(f"WARNING: failed copy(origOnlineEnvBase, {loggingDir}Rich{whichRich}_OnlineEnvBase_{setupHelper.directoryTime}.py)") opy( origOnlineEnvBase, - f"{launchDir}Rich{whichRich}_OnlineEnvBase_{setupHelper.directoryTime}.py" + f"{launchDir}Rich{whichRich}_OnlineEnvBase_{setupHelper.directoryTime}.py", ) print( f"INFO: OnlineEnvBase.py stored in file: {launchDir}Rich{whichRich}_OnlineEnvBase_{setupHelper.directoryTime}.py" @@ -1521,10 +1613,12 @@ def run(whichRich, offline=False, runInlineReco=False): ) else: setupHelper.sendEmail( - f'ERROR: RICH{whichRich} mirror alignment {setupHelper.directoryTime} did not complete normally.{ChMagPolSubject}', - f'ERROR: RICH{whichRich} mirror alignment {setupHelper.directoryTime} did not complete normally. \n No output directory was written. \n Log may be found on plus.cern.ch (via lbgw) in {richFilesDir}Logging/ with timestamp {setupHelper.directoryTime}.{ChMagPolText} \n Runs: {str(runs)} \n Fills: {str(fills)} \n Polarities: {str(polsStr)}{postText} \n dataVariant: {alignConf.getProp("dataVariant")}', + f"ERROR: RICH{whichRich} mirror alignment {setupHelper.directoryTime} did not complete normally.{ChMagPolSubject}", + f"ERROR: RICH{whichRich} mirror alignment {setupHelper.directoryTime} did not complete normally. \n No output directory was written. \n Log may be found on plus.cern.ch (via lbgw) in {richFilesDir}Logging/ with timestamp {setupHelper.directoryTime}.{ChMagPolText} \n Runs: {str(runs)} \n Fills: {str(fills)} \n Polarities: {str(polsStr)}{postText} \n dataVariant: {alignConf.getProp('dataVariant')}", setupHelper.emails - if not testing else setupHelper.experts) + if not testing + else setupHelper.experts, + ) print( f"ERROR: RICH{whichRich} mirror alignment {setupHelper.directoryTime} did not complete normally. No output directory was written." ) @@ -1540,22 +1634,25 @@ def run(whichRich, offline=False, runInlineReco=False): if os.path.exists(setupHelper.savedir): sys.stdout.flush() try: - copy(currentHLT02log, - f"{setupHelper.savedir}hlt02.log") + copy(currentHLT02log, f"{setupHelper.savedir}hlt02.log") print( f"INFO: stored hlt02 log in file: {setupHelper.savedir}hlt02.log" ) # remove what we currently believe are extraneous items - #os.system(f'grep -vE "{removeExtraneous}" {setupHelper.savedir}hlt02.log > {setupHelper.savedir}hlt02reduced.log') - with open( + # os.system(f'grep -vE "{removeExtraneous}" {setupHelper.savedir}hlt02.log > {setupHelper.savedir}hlt02reduced.log') + with ( + open( f"{setupHelper.savedir}hlt02.log", "rb" - ) as input_file, open( - f"{setupHelper.savedir}hlt02reduced.log", - "wb") as output_file: + ) as input_file, + open( + f"{setupHelper.savedir}hlt02reduced.log", "wb" + ) as output_file, + ): for line in input_file: - if not any(pattern in line.decode() - for pattern in - removeExtraneous_patterns): + if not any( + pattern in line.decode() + for pattern in removeExtraneous_patterns + ): output_file.write(line) print( f"INFO: stored reduced file: {setupHelper.savedir}hlt02reduced.log" @@ -1569,28 +1666,30 @@ def run(whichRich, offline=False, runInlineReco=False): f"INFO: stored hlt02 log in file: {launchDir}hlt02.log" ) # remove what we currently believe are extraneous items - #os.system(f'grep -vE "{removeExtraneous}" {launchDir}hlt02.log > {launchDir}hlt02reduced.log') - with open(f"{launchDir}hlt02.log", - "rb") as input_file, open( - f"{launchDir}hlt02reduced.log", - "wb") as output_file: + # os.system(f'grep -vE "{removeExtraneous}" {launchDir}hlt02.log > {launchDir}hlt02reduced.log') + with ( + open(f"{launchDir}hlt02.log", "rb") as input_file, + open( + f"{launchDir}hlt02reduced.log", "wb" + ) as output_file, + ): for line in input_file: - if not any(pattern in line.decode() - for pattern in - removeExtraneous_patterns): + if not any( + pattern in line.decode() + for pattern in removeExtraneous_patterns + ): output_file.write(line) print( f"INFO: stored reduced file: {launchDir}hlt02reduced.log" ) try: - lastAlignSuccessFile = open(lastAlignSuccess, 'w') + lastAlignSuccessFile = open(lastAlignSuccess, "w") lastAlignSuccessFile.write( - 'YES\n' + "YES\n" ) # python will convert \n to os.linesep lastAlignSuccessFile.close() except: - print( - f"WARNING: failed open(lastAlignSuccess, 'w')") + print(f"WARNING: failed open(lastAlignSuccess, 'w')") else: print( f"INFO: storing reduced file: {loggingDir}Rich{whichRich}_{setupHelper.directoryTime}_hlt02reduced.log" @@ -1599,23 +1698,28 @@ def run(whichRich, offline=False, runInlineReco=False): try: copy( currentHLT02log, - f"{loggingDir}Rich{whichRich}_{setupHelper.directoryTime}_hlt02.log" + f"{loggingDir}Rich{whichRich}_{setupHelper.directoryTime}_hlt02.log", ) print( f"INFO: stored hlt02 log in file: {loggingDir}Rich{whichRich}_{setupHelper.directoryTime}_hlt02.log" ) # remove what we currently believe are extraneous items - #os.system(f'grep -vE "{removeExtraneous}" {loggingDir}Rich{whichRich}_{setupHelper.directoryTime}_hlt02.log > {loggingDir}Rich{whichRich}_{setupHelper.directoryTime}_hlt02reduced.log') - with open( + # os.system(f'grep -vE "{removeExtraneous}" {loggingDir}Rich{whichRich}_{setupHelper.directoryTime}_hlt02.log > {loggingDir}Rich{whichRich}_{setupHelper.directoryTime}_hlt02reduced.log') + with ( + open( f"{loggingDir}Rich{whichRich}_{setupHelper.directoryTime}_hlt02.log", - "rb" - ) as input_file, open( + "rb", + ) as input_file, + open( f"{loggingDir}Rich{whichRich}_{setupHelper.directoryTime}_hlt02reduced.log", - "wb") as output_file: + "wb", + ) as output_file, + ): for line in input_file: - if not any(pattern in line.decode() - for pattern in - removeExtraneous_patterns): + if not any( + pattern in line.decode() + for pattern in removeExtraneous_patterns + ): output_file.write(line) except: print( @@ -1623,52 +1727,54 @@ def run(whichRich, offline=False, runInlineReco=False): ) copy( currentHLT02log, - f"{launchDir}Rich{whichRich}_{setupHelper.directoryTime}_hlt02.log" + f"{launchDir}Rich{whichRich}_{setupHelper.directoryTime}_hlt02.log", ) print( f"INFO: stored hlt02 log in file: {launchDir}Rich{whichRich}_{setupHelper.directoryTime}_hlt02.log" ) # remove what we currently believe are extraneous items - #os.system(f'grep -vE "{removeExtraneous}" {launchDir}Rich{whichRich}_{setupHelper.directoryTime}_hlt02.log > {launchDir}Rich{whichRich}_{setupHelper.directoryTime}_hlt02reduced.log') - with open( + # os.system(f'grep -vE "{removeExtraneous}" {launchDir}Rich{whichRich}_{setupHelper.directoryTime}_hlt02.log > {launchDir}Rich{whichRich}_{setupHelper.directoryTime}_hlt02reduced.log') + with ( + open( f"{launchDir}Rich{whichRich}_{setupHelper.directoryTime}_hlt02.log", - "rb" - ) as input_file, open( + "rb", + ) as input_file, + open( f"{launchDir}Rich{whichRich}_{setupHelper.directoryTime}_hlt02reduced.log", - "wb") as output_file: + "wb", + ) as output_file, + ): for line in input_file: - if not any(pattern in line.decode() - for pattern in - removeExtraneous_patterns): + if not any( + pattern in line.decode() + for pattern in removeExtraneous_patterns + ): output_file.write(line) if cancel: try: - lastAlignSuccessFile = open( - lastAlignSuccess, 'w') + lastAlignSuccessFile = open(lastAlignSuccess, "w") lastAlignSuccessFile.write( - 'YES\n' + "YES\n" ) # python will convert \n to os.linesep lastAlignSuccessFile.close() except: - print( - f"WARNING: failed open(lastAlignSuccess, 'w')" - ) + print(f"WARNING: failed open(lastAlignSuccess, 'w')") # For good measure, make a reduced log in the logging directory - #os.system(f'grep -vE "{removeExtraneous}" {currentHLT02log} > {currentHLT02logReduced}') + # os.system(f'grep -vE "{removeExtraneous}" {currentHLT02log} > {currentHLT02logReduced}') try: - with open(f"{currentHLT02log}", - "rb") as input_file, open( - f"{currentHLT02logReduced}", - "wb") as output_file: + with ( + open(f"{currentHLT02log}", "rb") as input_file, + open(f"{currentHLT02logReduced}", "wb") as output_file, + ): for line in input_file: - if not any(pattern in line.decode() for pattern - in removeExtraneous_patterns): + if not any( + pattern in line.decode() + for pattern in removeExtraneous_patterns + ): output_file.write(line) except: - print( - "WARNING: failed to produce currentHLT02logReduced" - ) + print("WARNING: failed to produce currentHLT02logReduced") print(f"INFO: Next expected command is reset (RESET)") @@ -1681,13 +1787,11 @@ def run(whichRich, offline=False, runInlineReco=False): print(f"INFO: *************************** ") yaml = YAML() - with open(f"{workdir}rich{whichRich}_iter_number.yml", - 'w') as fout: + with open(f"{workdir}rich{whichRich}_iter_number.yml", "w") as fout: yaml.dump(n_it, fout) yaml = YAML() - with open( - f"{workdir}/rich{whichRich}_variant.yml") as finp: + with open(f"{workdir}/rich{whichRich}_variant.yml") as finp: variant = yaml.load(finp) ### get the yml-file produced by the last fit and create the ones with the tilted mirrors (xml for DetDesc, yml for DD4hep) @@ -1698,13 +1802,15 @@ def run(whichRich, offline=False, runInlineReco=False): "INFO: magnFactorsMode is nonzero. Creating coeff_calibration_yml files." ) ymlHelper.create_coeff_calibration_yml_files( - f"{currentMirrorDBFilePre}.yml", n_it) + f"{currentMirrorDBFilePre}.yml", n_it + ) else: print( "INFO: magnFactorsMode is nonzero. Creating coeff_calibration_xml files." ) xmlHelper.create_coeff_calibration_xml_files( - f"{currentMirrorDBFilePre}.xml", n_it) + f"{currentMirrorDBFilePre}.xml", n_it + ) sys.stdout.flush() ### just start the next minor iteration if not converged yet @@ -1719,7 +1825,7 @@ def run(whichRich, offline=False, runInlineReco=False): yaml = YAML() with open(f"{workdir}/rich{whichRich}_variant.yml") as finp: variant = yaml.load(finp) - if (m_it % tiltNamesLength == 0): + if m_it % tiltNamesLength == 0: pickupDB = f"{workdir}{variant}_conds_i{n_it}" else: pickupDB = f"{workdir}{variant}_conds_{tiltNames[m_it % tiltNamesLength]}_i{n_it}" @@ -1730,13 +1836,11 @@ def run(whichRich, offline=False, runInlineReco=False): copy(pickupDB, currentDB) yaml = YAML() - with open(f"{workdir}rich{whichRich}_tilt_name.yml", - 'w') as fout: + with open(f"{workdir}rich{whichRich}_tilt_name.yml", "w") as fout: yaml.dump(tiltNames[m_it % tiltNamesLength], fout) yaml = YAML() - with open(f"{workdir}rich{whichRich}_runAnalyzer.yml", - 'w') as fout: + with open(f"{workdir}rich{whichRich}_runAnalyzer.yml", "w") as fout: yaml.dump("YES", fout) print( f"INFO: {workdir}rich{whichRich}_runAnalyzer.yml set to 'YES'" @@ -1752,12 +1856,12 @@ def run(whichRich, offline=False, runInlineReco=False): richAnalyzerOutFile = f"{analyzerOutDir}Rich{whichRich}AnalyzerOut{tiltNameRecoStr}_i{n_it}.txt" richAnalyzerStdOutFile = f"{analyzerOutDir}Rich{whichRich}AnalyzerStdOut{tiltNameRecoStr}_i{n_it}.txt" richAnalyzerStdErrFile = f"{analyzerOutDir}Rich{whichRich}AnalyzerStdErr{tiltNameRecoStr}_i{n_it}.txt" - myStdOut = open(richAnalyzerStdOutFile, 'w') - myStdErr = open(richAnalyzerStdErrFile, 'w') + myStdOut = open(richAnalyzerStdOutFile, "w") + myStdErr = open(richAnalyzerStdErrFile, "w") if m_it % tiltNamesLength != 0: tiltNameRecoStr = f" {tiltNames[m_it % tiltNamesLength]}" cmd = f"cd {workdir} ; {stackDir}Panoptes/run gaudirun.py {stackDir}Panoptes/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/MirrorAlignment/data_online.py {stackDir}Panoptes/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/MirrorAlignment/hlt2_reco_rich{whichRich}_noUT_panoptes_dd4hep_both.py > {richAnalyzerOutFile} ; cd - " - #cmd = f"cd {workdir} ; echo -n{tiltNameRecoStr} {n_it} | /group/rich/sw/alignment/stack/Panoptes/run gaudirun.py /group/rich/sw/alignment/stack/Panoptes/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/MirrorAlignment/data_online.py /group/rich/sw/alignment/stack/Panoptes/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/MirrorAlignment/hlt2_reco_rich{whichRich}_noUT_panoptes_dd4hep-both.py > {richAnalyzerOutFile} ; cd - " + # cmd = f"cd {workdir} ; echo -n{tiltNameRecoStr} {n_it} | /group/rich/sw/alignment/stack/Panoptes/run gaudirun.py /group/rich/sw/alignment/stack/Panoptes/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/MirrorAlignment/data_online.py /group/rich/sw/alignment/stack/Panoptes/Rich/RichMirrorAlignmentOnline/files/OfflineScripts/MirrorAlignment/hlt2_reco_rich{whichRich}_noUT_panoptes_dd4hep-both.py > {richAnalyzerOutFile} ; cd - " print("INFO: Starting Inline Reconstruction. ") print(f"INFO: cmd = {cmd}") p4 = subprocess.Popen( @@ -1765,7 +1869,8 @@ def run(whichRich, offline=False, runInlineReco=False): shell=True, executable="/bin/bash", stdout=myStdOut, - stderr=myStdErr) + stderr=myStdErr, + ) p4.communicate() print("INFO: Inline Reconstruction Complete. ") myStdOut.close() @@ -1773,9 +1878,9 @@ def run(whichRich, offline=False, runInlineReco=False): sys.stdout.flush() hh, r = divmod(time() - start_time_RichMirrRunReco, 3600) mm, ss = divmod(r, 60) - elapsed_runtimes['elapsed_times_RichMirrRunReco'].append( - "{:0>2}:{:0>2}:{:05.2f}".format( - int(hh), int(mm), ss)) # RichMirrRunReco run time + elapsed_runtimes["elapsed_times_RichMirrRunReco"].append( + "{:0>2}:{:0>2}:{:05.2f}".format(int(hh), int(mm), ss) + ) # RichMirrRunReco run time if magnFactorsMode == 0: m_it = m_it + tiltNamesLength @@ -1789,22 +1894,21 @@ def run(whichRich, offline=False, runInlineReco=False): sys.stdout.flush() sleep(2) - elif command.startswith('stop') and state in (State.RUNNING, - State.READY): - + elif command.startswith("stop") and state in (State.RUNNING, State.READY): print( f"INFO: STOP command received at {strftime('%Y-%m-%d %H:%M:%S', gmtime())} UTC" ) - elapsed_runtimes['elapsed_time_run'] = time( - ) - start_time_run # Actual iterating time + elapsed_runtimes["elapsed_time_run"] = ( + time() - start_time_run + ) # Actual iterating time print( f"INFO: Elapsed time to run the Mirror Alignment set as {elapsed_runtimes['elapsed_time_run']} seconds." ) nEventsListList = setupHelper.getNEventsListList(n_it) - #nEventsListList = [[10000000], 10000000] # If this needs to be faked + # nEventsListList = [[10000000], 10000000] # If this needs to be faked - vN_DB_str = f'v{int(latest_vN)}' + vN_DB_str = f"v{int(latest_vN)}" # PN: Note to self, or ask Claire [depending on when this was put in]: # Should we really be finalizing the alignment if a STOP occurs? setupHelper.finalize( @@ -1815,21 +1919,23 @@ def run(whichRich, offline=False, runInlineReco=False): elapsed_runtimes, # False, # nEventsListList, # - messageID) # + messageID, + ) # if not testing: alert = f"INFO: Rich{whichRich} mirror alignment received an unexpected STOP command." # There may have also been a lack of processed events / sanity check failure. if autoUpdate_initial: alert = f"ERROR: Rich{whichRich} mirror alignment received an unexpected STOP command; 8-21h (21h-8h): please call (email) the Alignment piquet." # There may have also been a lack of processed events / sanity check failure. updateHelper.updateDB(int(latest_vN), False, alert) # current - #updateHelper.stopUpdateDIM() + # updateHelper.stopUpdateDIM() setupHelper.sendEmail( f"STOP command received for RICH{whichRich} alignment {setupHelper.directoryTime}.", f"RICH{whichRich} mirror alignment {setupHelper.directoryTime} received an unexpected STOP command. \n Check for source of error, it may have involved a Traceback.", - setupHelper.emails if not testing else setupHelper.experts) + setupHelper.emails if not testing else setupHelper.experts, + ) state = State.READY sys.stdout.flush() - elif command.startswith('reset'): + elif command.startswith("reset"): print( f"INFO: RESET command received at {strftime('%Y-%m-%d %H:%M:%S', gmtime())} UTC" ) @@ -1840,7 +1946,7 @@ def run(whichRich, offline=False, runInlineReco=False): else: break - elif command.startswith('unload'): + elif command.startswith("unload"): print( f"INFO: UNLOAD command received at {strftime('%Y-%m-%d %H:%M:%S', gmtime())} UTC" ) @@ -1859,10 +1965,9 @@ def run(whichRich, offline=False, runInlineReco=False): com.set_status(state) print(f"INFO: Iterator state = {state}") - -######################################################################################################################## -##### This is where the party ends! (well, almost...) -######################################################################################################################## + ######################################################################################################################## + ##### This is where the party ends! (well, almost...) + ######################################################################################################################## print(f"INFO: Iterator state set to {state}.") print(f"INFO: End of run(whichRich = {whichRich}).") @@ -1892,5 +1997,6 @@ def run(whichRich, offline=False, runInlineReco=False): print("INFO: Claire says miezmiezmiez. Jake says whatwhatwhat.") sys.stdout.flush() -if __name__ == '__main__': + +if __name__ == "__main__": run() diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/LHCbStyle.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/LHCbStyle.py index dc1be29e890ea80c1d083ad59937b50178d1ce1c..de922c8d75d7b55beab2ecaaba0868cdfab1cb88 100644 --- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/LHCbStyle.py +++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/LHCbStyle.py @@ -21,14 +21,16 @@ # by $Author$ # ============================================================================= """LHCb Style for ROOT-plots""" -'''Based off of https://gitlab.cern.ch/lhcb/Analysis/blob/master/Analysis/Ostap/python/Ostap/LHCbStyle.py''' + +"""Based off of https://gitlab.cern.ch/lhcb/Analysis/blob/master/Analysis/Ostap/python/Ostap/LHCbStyle.py""" # ============================================================================= import ROOT + __all__ = ( - 'lhcbStyle', - 'lhcbLabel', - 'LHCbStyle', - 'lhcbLatex', + "lhcbStyle", + "lhcbLabel", + "LHCbStyle", + "lhcbLatex", ) ## font @@ -53,12 +55,14 @@ lhcbLatex.SetTextAlign(12) # ============================================================================= ## define LHCb style for plots -def LHCbStyle(name="LHCbStyle", - desc="Standard LHCb plots style", - lineWidth=lhcbWidth, - font=lhcbFont, - makeNew=False, - force=True): +def LHCbStyle( + name="LHCbStyle", + desc="Standard LHCb plots style", + lineWidth=lhcbWidth, + font=lhcbFont, + makeNew=False, + force=True, +): """ Define LHCb style for plots """ @@ -72,7 +76,7 @@ def LHCbStyle(name="LHCbStyle", nam = name i = 1 while obj: - nam = name + '_%d' % i + nam = name + "_%d" % i obj = ROOT.gROOT.FindObject(nam) i += 1 @@ -158,8 +162,7 @@ def LHCbStyle(name="LHCbStyle", ## lhcbStyle . SetOptFit(1011); // order is probability, Chi2, errors, parameters ## size of small lines at the end of error bars - style.SetEndErrorSize( - 0) # this value is 5 (not 0) in Vanya's version of this file + style.SetEndErrorSize(0) # this value is 5 (not 0) in Vanya's version of this file ## look of the statistics box: style.SetStatBorderSize(0) @@ -204,23 +207,30 @@ def printLHCb(LR="L", prelim="Final", text=""): //////////////////////////////////////////////////////////////////// """ - if not LR in ('L', 'R'): + if not LR in ("L", "R"): raise TypeError("Unknown LR-option: %s" % LR) global lhcbName - if 'R' == LR: - lhcbName = ROOT.TPaveText(0.70 - lhcbStyle.GetPadRightMargin(), - 0.75 - lhcbStyle.GetPadTopMargin(), - 0.95 - lhcbStyle.GetPadRightMargin(), - 0.85 - lhcbStyle.GetPadTopMargin(), "BRNDC") + if "R" == LR: + lhcbName = ROOT.TPaveText( + 0.70 - lhcbStyle.GetPadRightMargin(), + 0.75 - lhcbStyle.GetPadTopMargin(), + 0.95 - lhcbStyle.GetPadRightMargin(), + 0.85 - lhcbStyle.GetPadTopMargin(), + "BRNDC", + ) else: ## LR="L" - lhcbName = ROOT.TPaveText(lhcbStyle.GetPadLeftMargin() + 0.05, - 0.87 - lhcbStyle.GetPadTopMargin(), - lhcbStyle.GetPadLeftMargin() + 0.30, - 0.95 - lhcbStyle.GetPadTopMargin(), "BRNDC") - - if "Final" == prelim: lhcbName.AddText("LHCb") + lhcbName = ROOT.TPaveText( + lhcbStyle.GetPadLeftMargin() + 0.05, + 0.87 - lhcbStyle.GetPadTopMargin(), + lhcbStyle.GetPadLeftMargin() + 0.30, + 0.95 - lhcbStyle.GetPadTopMargin(), + "BRNDC", + ) + + if "Final" == prelim: + lhcbName.AddText("LHCb") elif "Prelim" == prelim: lhcbName.AddText("#splitline{LHCb}{#scale[1.0]{Preliminary}}") else: diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/RichAlignmentHelper.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/RichAlignmentHelper.py index 4a3571444e69184c6b2b83123adad248be4a14a9..27eeb7780cf19b8a08defa7101037ecf1b665508 100644 --- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/RichAlignmentHelper.py +++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/RichAlignmentHelper.py @@ -11,40 +11,39 @@ __authors__ = "Claire Prouve, Paras Naik" __copyright__ = "University of Bristol, November 2022" +import copy +import getpass import os -import sys import re import shutil -import time -from time import sleep -from time import time -from time import gmtime, strftime -import copy -from ruamel.yaml import YAML import subprocess +import sys +import time +from time import gmtime, sleep, strftime, time from typing import List + +from ruamel.yaml import YAML + from PyMirrAlignOnline.convert_magnFactors_txt_YAML import convert_magnFactors_txt_YAML -import getpass class RichAlignmentHelper: def __init__(self, configuration): self.alignConf = configuration - self.thisNameStr = self.alignConf.getProp('nameStr') - self.tiltNames = self.alignConf.getProp('tiltNames') - #self.magnifDir = os.path.join(self.alignConf.getProp('stackDir'),self.alignConf.getProp('magnifDir')) - self.workdir = self.alignConf.getProp('WorkDir') - self.whichRich = self.alignConf.getProp('Rich') - self.deltaThetaWindow = self.alignConf.getProp('deltaThetaWindow') - self.minAverageBinPop = self.alignConf.getProp('minAverageBinPop') - self.phiBinFactor = self.alignConf.getProp('phiBinFactor') - self.minFracPhiBinsPopulated = self.alignConf.getProp( - 'minFracPhiBinsPopulated') - self.combinFitMethod = self.alignConf.getProp('combinFitMethod') - self.coeffCalibTilt = self.alignConf.getProp('coeffCalibTilt') - self.magnFactorsMode = self.alignConf.getProp('magnFactorsMode') - self.solutionMethod = self.alignConf.getProp('solutionMethod') - self.fixSinusoidShift = self.alignConf.getProp('fixSinusoidShift') + self.thisNameStr = self.alignConf.getProp("nameStr") + self.tiltNames = self.alignConf.getProp("tiltNames") + # self.magnifDir = os.path.join(self.alignConf.getProp('stackDir'),self.alignConf.getProp('magnifDir')) + self.workdir = self.alignConf.getProp("WorkDir") + self.whichRich = self.alignConf.getProp("Rich") + self.deltaThetaWindow = self.alignConf.getProp("deltaThetaWindow") + self.minAverageBinPop = self.alignConf.getProp("minAverageBinPop") + self.phiBinFactor = self.alignConf.getProp("phiBinFactor") + self.minFracPhiBinsPopulated = self.alignConf.getProp("minFracPhiBinsPopulated") + self.combinFitMethod = self.alignConf.getProp("combinFitMethod") + self.coeffCalibTilt = self.alignConf.getProp("coeffCalibTilt") + self.magnFactorsMode = self.alignConf.getProp("magnFactorsMode") + self.solutionMethod = self.alignConf.getProp("solutionMethod") + self.fixSinusoidShift = self.alignConf.getProp("fixSinusoidShift") def runMirrCombinFit(self, n_it): ps = [] @@ -61,33 +60,36 @@ class RichAlignmentHelper: variant = yaml.load(finp) yaml = YAML() - with open(f"{self.workdir}rich{self.whichRich}_session_timestamp.yml" - ) as finp: + with open(f"{self.workdir}rich{self.whichRich}_session_timestamp.yml") as finp: dt = yaml.load(finp) for tiltName in _tiltNames: - if (tiltName == ""): + if tiltName == "": connectStr = "" else: connectStr = "_" - combinFitDir = f"{self.workdir}{variant}_histos{connectStr}{tiltName}_i{n_it}/" + combinFitDir = ( + f"{self.workdir}{variant}_histos{connectStr}{tiltName}_i{n_it}/" + ) if os.path.exists(combinFitDir): print(f"INFO: Removing {combinFitDir}") shutil.rmtree(combinFitDir) os.makedirs(combinFitDir) - #combinFitPlotDir = f"{combinFitDir}plots/" + # combinFitPlotDir = f"{combinFitDir}plots/" combinFitPlotDir = f"{self.workdir}plots/" # PN: All plots will now go into one directory, at top level in the workdir - #os.makedirs(combinFitPlotDir) + # os.makedirs(combinFitPlotDir) if not os.path.exists(combinFitPlotDir): os.makedirs(combinFitPlotDir) - combinResultsFile = f"{self.workdir}{variant}_fit_res{connectStr}{tiltName}_i{n_it}.txt" + combinResultsFile = ( + f"{self.workdir}{variant}_fit_res{connectStr}{tiltName}_i{n_it}.txt" + ) - #fitConfigFile = combinFitDir + "Rich" + str( + # fitConfigFile = combinFitDir + "Rich" + str( # self.whichRich - #) + "MirrCombinFit_" + self.thisNameStr + connectStr + tiltName + "_i" + str( + # ) + "MirrCombinFit_" + self.thisNameStr + connectStr + tiltName + "_i" + str( # n_it) + ".conf" """ histoFile = "RichRecQCHistos_rich" + str( @@ -135,106 +137,89 @@ class RichAlignmentHelper: conf_new = {} richFilesDir = self.alignConf.getProp( - 'richFiles') # '/group/rich/AlignmentFiles/' + "richFiles" + ) # '/group/rich/AlignmentFiles/' if not os.path.exists( - f"{self.workdir}/rich{self.whichRich}_fit_align_confs.yml" + f"{self.workdir}/rich{self.whichRich}_fit_align_confs.yml" ): print( f"INFO: Copying {richFilesDir}FitAlignConfs/rich{self.whichRich}_fit_align_confs.yml to {self.workdir}rich{self.whichRich}_fit_align_confs.yml" ) shutil.copy2( f"{richFilesDir}FitAlignConfs/rich{self.whichRich}_fit_align_confs.yml", - f"{self.workdir}rich{self.whichRich}_fit_align_confs.yml") - with open(f"{self.workdir}rich{self.whichRich}_fit_align_confs.yml" - ) as finp: + f"{self.workdir}rich{self.whichRich}_fit_align_confs.yml", + ) + with open( + f"{self.workdir}rich{self.whichRich}_fit_align_confs.yml" + ) as finp: conf = yaml.load(finp) last_timestamp = list(conf)[-1] copy_last_conf = copy.deepcopy(conf[last_timestamp]) conf_new[dt] = copy_last_conf - conf_new[dt]['fit_conf'].update({ - 'plotDir': - combinFitPlotDir, - 'workDir': - self.workdir, - 'fixSinusoidShift': - self.fixSinusoidShift, - 'sinusoidShift': - 0., - 'zeroGlobalFitMean': - False, - 'useGlobalFitMean': - False, - 'minAverageBinPop': - self.minAverageBinPop, - 'phiBinFactor': - self.phiBinFactor, - 'minFracPhiBinsPopulated': - self.minFracPhiBinsPopulated, - 'deltaThetaWindow': - self.deltaThetaWindow, - 'combinFitMethod': - self.combinFitMethod, - 'backgroundOrder': - 2, - 'plotOutputLevel': - 2, - 'warningFactor': - self.alignConf.getProp('warningFactor'), - 'stopToleranceMode': - self.alignConf.getProp( - 'stopToleranceMode'), # PN: same as for RichMirrAlign - 'stopTolerance': - 0.23, # PN: I have no idea what this is for - 'nominalResolutionSigma': - self.alignConf.getProp('nominalResolutionSigma'), - 'stopSigmaFraction': - self.alignConf.getProp( - 'stopSigmaFraction' - ), # PN: we used to only provide this to RichMirrAlign, now we provide it to RichMirrCombinFit? - this is currently 0 in the configuration! - }) - - conf_new[dt]['align_conf'].update({ - 'magnFactorsMode': - self.magnFactorsMode, - 'solutionMethod': - self.solutionMethod, - 'usePremisaligned': - False, - 'stopToleranceMode': - self.alignConf.getProp('stopToleranceMode'), - 'stopTolerancePriY': - self.alignConf.getProp('stopTolerancePriY'), - 'stopTolerancePriZ': - self.alignConf.getProp('stopTolerancePriZ'), - 'stopToleranceSecY': - self.alignConf.getProp('stopToleranceSecY'), - 'stopToleranceSecZ': - self.alignConf.getProp('stopToleranceSecZ'), - 'stopDecisionMode': - self.alignConf.getProp('stopDecisionMode'), - 'regularizationMode': - self.alignConf.getProp('regularizationMode'), - 'printMode': - 2, - }) - - #print(f"INFO: Last Timestamp: {last_timestamp}") - #print(f"INFO: Current Timestamp: {dt}") - - if dt != last_timestamp: # if same timestamp, then we are doing some sort of testing with external root and YAML configuration files OR the .yml was already written for this alignment (i.e. we are in subsequent iterations) + conf_new[dt]["fit_conf"].update( + { + "plotDir": combinFitPlotDir, + "workDir": self.workdir, + "fixSinusoidShift": self.fixSinusoidShift, + "sinusoidShift": 0.0, + "zeroGlobalFitMean": False, + "useGlobalFitMean": False, + "minAverageBinPop": self.minAverageBinPop, + "phiBinFactor": self.phiBinFactor, + "minFracPhiBinsPopulated": self.minFracPhiBinsPopulated, + "deltaThetaWindow": self.deltaThetaWindow, + "combinFitMethod": self.combinFitMethod, + "backgroundOrder": 2, + "plotOutputLevel": 2, + "warningFactor": self.alignConf.getProp("warningFactor"), + "stopToleranceMode": self.alignConf.getProp( + "stopToleranceMode" + ), # PN: same as for RichMirrAlign + "stopTolerance": 0.23, # PN: I have no idea what this is for + "nominalResolutionSigma": self.alignConf.getProp( + "nominalResolutionSigma" + ), + "stopSigmaFraction": self.alignConf.getProp( + "stopSigmaFraction" + ), # PN: we used to only provide this to RichMirrAlign, now we provide it to RichMirrCombinFit? - this is currently 0 in the configuration! + } + ) + + conf_new[dt]["align_conf"].update( + { + "magnFactorsMode": self.magnFactorsMode, + "solutionMethod": self.solutionMethod, + "usePremisaligned": False, + "stopToleranceMode": self.alignConf.getProp("stopToleranceMode"), + "stopTolerancePriY": self.alignConf.getProp("stopTolerancePriY"), + "stopTolerancePriZ": self.alignConf.getProp("stopTolerancePriZ"), + "stopToleranceSecY": self.alignConf.getProp("stopToleranceSecY"), + "stopToleranceSecZ": self.alignConf.getProp("stopToleranceSecZ"), + "stopDecisionMode": self.alignConf.getProp("stopDecisionMode"), + "regularizationMode": self.alignConf.getProp("regularizationMode"), + "printMode": 2, + } + ) + + # print(f"INFO: Last Timestamp: {last_timestamp}") + # print(f"INFO: Current Timestamp: {dt}") + + if ( + dt != last_timestamp + ): # if same timestamp, then we are doing some sort of testing with external root and YAML configuration files OR the .yml was already written for this alignment (i.e. we are in subsequent iterations) with open( - f"{self.workdir}/rich{self.whichRich}_fit_align_confs.yml", - 'a') as fout: - yaml.boolean_representation = ['false', 'true'] + f"{self.workdir}/rich{self.whichRich}_fit_align_confs.yml", "a" + ) as fout: + yaml.boolean_representation = ["false", "true"] yaml.dump(conf_new, fout) fitOutputFile = f"{combinFitDir}Rich{self.whichRich}MirrCombinFitOut_{self.thisNameStr}{connectStr}{tiltName}_i{n_it}.txt" fitStdOutFile = f"{combinFitDir}Rich{self.whichRich}MirrCombinFitStdOut_{self.thisNameStr}{connectStr}{tiltName}_i{n_it}.txt" fitStdErrFile = f"{combinFitDir}Rich{self.whichRich}MirrCombinFitStdErr_{self.thisNameStr}{connectStr}{tiltName}_i{n_it}.txt" - myStdOut = open(fitStdOutFile, 'w') - myStdErr = open(fitStdErrFile, 'w') + myStdOut = open(fitStdOutFile, "w") + myStdErr = open(fitStdErrFile, "w") cmd = f"cd {self.workdir} ; `which RichMirrCombinFit` rich{self.whichRich} {tiltName} > {fitOutputFile} ; cd -" print(f"INFO: Starting RichMirrCombinFit.") print(f"INFO: cmd = {cmd}") @@ -244,7 +229,8 @@ class RichAlignmentHelper: shell=True, executable="/bin/bash", stdout=myStdOut, - stderr=myStdErr) + stderr=myStdErr, + ) myStdOut.close() myStdErr.close() ps.append(p2) @@ -257,7 +243,8 @@ class RichAlignmentHelper: if all([x is not None for x in ps_status]): PopenTotal = 0 for l in ps_status: - if l is not None: PopenTotal += 1 + if l is not None: + PopenTotal += 1 print( f"INFO: {PopenTotal} of {tiltNamesLength} RichMirrCombinFit processes complete" ) @@ -268,7 +255,8 @@ class RichAlignmentHelper: else: PopenDone = 0 for l in ps_status: - if l is not None: PopenDone += 1 + if l is not None: + PopenDone += 1 if PopenDone > PopenCount: print( f"INFO: {PopenDone} of {tiltNamesLength} RichMirrCombinFit processes complete" @@ -290,16 +278,22 @@ class RichAlignmentHelper: variant = yaml.load(finp) for tiltNum, tiltName in enumerate(_tiltNames): - if (tiltName == ""): + if tiltName == "": connectStr = "" else: connectStr = "_" - combinFitDir = f"{self.workdir}{variant}_histos{connectStr}{tiltName}_i{n_it}/" + combinFitDir = ( + f"{self.workdir}{variant}_histos{connectStr}{tiltName}_i{n_it}/" + ) print(f"INFO: expected combinFitDir {combinFitDir}") - combinResultsFile = f"{self.workdir}{variant}_fit_res{connectStr}{tiltName}_i{n_it}.txt" + combinResultsFile = ( + f"{self.workdir}{variant}_fit_res{connectStr}{tiltName}_i{n_it}.txt" + ) print(f"INFO: expected combinResultsFile {combinResultsFile}") - magnificationOutputFile = f"{self.workdir}{variant}_magnifs{connectStr}{tiltName}_i{n_it}.txt" + magnificationOutputFile = ( + f"{self.workdir}{variant}_magnifs{connectStr}{tiltName}_i{n_it}.txt" + ) sys.stdout.flush() @@ -318,41 +312,40 @@ class RichAlignmentHelper: if tiltNum == 0: pNoTilt.append(newpars) - with open(magnificationOutputFile, 'w') as magfile: + with open(magnificationOutputFile, "w") as magfile: for i, sp in enumerate(p): tiltSign = 1.0 - #if tiltName.count('neg') > 0: - if tiltName.count('n') > 0: + # if tiltName.count('neg') > 0: + if tiltName.count("n") > 0: tiltSign = -1.0 mirrPair = sp[0] - Y = (sp[1] - pNoTilt[i][1]) / ( - self.coeffCalibTilt * tiltSign) - Z = (sp[3] - pNoTilt[i][3]) / ( - self.coeffCalibTilt * tiltSign) - magfile.write(mirrPair + " " + str(Y) + " " + str(Z) + - "\n") + Y = (sp[1] - pNoTilt[i][1]) / (self.coeffCalibTilt * tiltSign) + Z = (sp[3] - pNoTilt[i][3]) / (self.coeffCalibTilt * tiltSign) + magfile.write(mirrPair + " " + str(Y) + " " + str(Z) + "\n") if self.magnFactorsMode != 0: # YAMLify magnification factors [currently for records only] convert_magnFactors_txt_YAML.to_yaml(self.workdir, n_it) - #richMirrAlignConfFile = self.workdir + "Rich" + str( + # richMirrAlignConfFile = self.workdir + "Rich" + str( # self.whichRich) + "MirrAlign_i" + str(n_it) + ".conf" - richMirrAlignOutFile = f"{self.workdir}Rich{self.whichRich}MirrAlignOut_i{n_it}.txt" - #richMirrAlignNanOutFile = self.workdir + "Rich" + str( + richMirrAlignOutFile = ( + f"{self.workdir}Rich{self.whichRich}MirrAlignOut_i{n_it}.txt" + ) + # richMirrAlignNanOutFile = self.workdir + "Rich" + str( # self.whichRich) + "MirrAlignNanOut_i" + str(n_it) + ".txt" combinFitDir = f"{self.workdir}{variant}_histos_i{n_it}/" combinResultsFile = f"{self.workdir}{variant}_fit_res_i{n_it}.txt" # - #currentMirrorYAMLFile = self.workdir + "Rich" + str( + # currentMirrorYAMLFile = self.workdir + "Rich" + str( # self.whichRich) + "CondDBUpdate_" + self.thisNameStr + "_i" + str( # n_it) + ".yml" - #nextIterationYAMLFile = self.workdir + "Rich" + str( + # nextIterationYAMLFile = self.workdir + "Rich" + str( # self.whichRich) + "CondDBUpdate_" + self.thisNameStr + "_i" + str( # n_it + 1) + ".yml" - #zeroMirrorYAMLFile = self.workdir + "Rich" + str( + # zeroMirrorYAMLFile = self.workdir + "Rich" + str( # self.whichRich) + "CondDBUpdate_" + self.thisNameStr + "_i0.yml" """ if os.path.exists(richMirrAlignConfFile): @@ -394,20 +387,21 @@ class RichAlignmentHelper: f.close() """ - alignStdOutFile = f"{self.workdir}Rich{self.whichRich}MirrAlignStdOut_i{n_it}.txt" - alignStdErrFile = f"{self.workdir}Rich{self.whichRich}MirrAlignStdErr_i{n_it}.txt" - myStdOut = open(alignStdOutFile, 'w') - myStdErr = open(alignStdErrFile, 'w') + alignStdOutFile = ( + f"{self.workdir}Rich{self.whichRich}MirrAlignStdOut_i{n_it}.txt" + ) + alignStdErrFile = ( + f"{self.workdir}Rich{self.whichRich}MirrAlignStdErr_i{n_it}.txt" + ) + myStdOut = open(alignStdOutFile, "w") + myStdErr = open(alignStdErrFile, "w") cmd = f"cd {self.workdir} ; `which RichMirrAlign` rich{self.whichRich} > {richMirrAlignOutFile} ; cd - " print(f"INFO: Starting RichMirrAlign.") print(f"INFO: cmd = {cmd}") sys.stdout.flush() p3 = subprocess.Popen( - cmd, - shell=True, - executable="/bin/bash", - stdout=myStdOut, - stderr=myStdErr) + cmd, shell=True, executable="/bin/bash", stdout=myStdOut, stderr=myStdErr + ) p3.communicate() myStdOut.close() myStdErr.close() @@ -425,18 +419,18 @@ class RichAlignmentHelper: variant = yaml.load(finp) for tiltName in _tiltNames: - if (tiltName == ""): + if tiltName == "": connectStr = "" else: connectStr = "_" - combinFitDir = f"{self.workdir}{variant}_histos{connectStr}{tiltName}_i{n_it}/" + combinFitDir = ( + f"{self.workdir}{variant}_histos{connectStr}{tiltName}_i{n_it}/" + ) fitOutputFile = f"{combinFitDir}Rich{self.whichRich}MirrCombinFitOut_{self.thisNameStr}{connectStr}{tiltName}_i{n_it}.txt" fitNGEFile = f"{combinFitDir}Rich{self.whichRich}MirrCombinFitNGEOut_{self.thisNameStr}{connectStr}{tiltName}_i{n_it}.txt" - os.system( - f"cat {fitOutputFile} | grep ' not_good_enough ' > {fitNGEFile}" - ) + os.system(f"cat {fitOutputFile} | grep ' not_good_enough ' > {fitNGEFile}") if not os.path.exists(fitNGEFile): print("ERROR: no fitNGEFile.") @@ -445,7 +439,7 @@ class RichAlignmentHelper: with open(fitNGEFile) as f: num_lines = len(f.readlines()) - if (num_lines != 0): + if num_lines != 0: print( "WARNING: Not enough well populated phi-bins in all mirror combination histograms. Will perform all fits anyway." ) @@ -456,10 +450,12 @@ class RichAlignmentHelper: return True def hasConverged(self): - stop_or_continue_file = self.workdir + f"rich{self.whichRich}_stop_or_continue.txt" + stop_or_continue_file = ( + self.workdir + f"rich{self.whichRich}_stop_or_continue.txt" + ) if not os.path.exists(stop_or_continue_file): print(f"ERROR: no {stop_or_continue_file} file.") - #return False # PN - if there is no stop_or_continue_file, something is wrong, thus we want it to crash in the next step. + # return False # PN - if there is no stop_or_continue_file, something is wrong, thus we want it to crash in the next step. with open(stop_or_continue_file) as rich_stop_or_continue_txt: verdict = rich_stop_or_continue_txt.readline().strip().upper() @@ -485,23 +481,33 @@ class RichAlignmentHelper: tiltNamesLength = len(_tiltNames) yaml = YAML() - with open(self.workdir + '/' + 'rich' + str(self.whichRich) + - '_variant.yml') as finp: + with open( + self.workdir + "/" + "rich" + str(self.whichRich) + "_variant.yml" + ) as finp: variant = yaml.load(finp) yaml = YAML() - with open(self.workdir + '/' + 'rich' + str(self.whichRich) + - '_session_timestamp.yml') as finp: + with open( + self.workdir + "/" + "rich" + str(self.whichRich) + "_session_timestamp.yml" + ) as finp: dt = yaml.load(finp) for tiltName in _tiltNames: - if (tiltName == ""): + if tiltName == "": connectStr = "" else: connectStr = "_" - combinFitDir = self.workdir + variant + "_histos" \ - + connectStr + tiltName + "_i" + str(n_it) + "/" + combinFitDir = ( + self.workdir + + variant + + "_histos" + + connectStr + + tiltName + + "_i" + + str(n_it) + + "/" + ) combinFitPlotDir = combinFitDir + "plots/" if os.path.exists(combinFitDir): print(f"INFO: Removing {combinFitDir}") @@ -509,11 +515,19 @@ class RichAlignmentHelper: os.makedirs(combinFitDir) os.makedirs(combinFitPlotDir) - combinResultsFile = self.workdir + variant + "_fit_res" \ - + connectStr + tiltName + "_i" + str(n_it) + ".txt" - #fitConfigFile = combinFitDir + "Rich" + str( + combinResultsFile = ( + self.workdir + + variant + + "_fit_res" + + connectStr + + tiltName + + "_i" + + str(n_it) + + ".txt" + ) + # fitConfigFile = combinFitDir + "Rich" + str( # self.whichRich - #) + "MirrCombinFit_" + self.thisNameStr + connectStr + tiltName + "_i" + str( + # ) + "MirrCombinFit_" + self.thisNameStr + connectStr + tiltName + "_i" + str( # n_it) + ".conf" """ histoFile = "RichRecQCHistos_rich" + str( @@ -559,99 +573,160 @@ class RichAlignmentHelper: """ conf_new = {} - if not os.path.exists(self.workdir + '/' + 'rich' + str( - self.whichRich) + '_fit_align_confs.yml'): + if not os.path.exists( + self.workdir + + "/" + + "rich" + + str(self.whichRich) + + "_fit_align_confs.yml" + ): shutil.copy2( # '/group/rich/sw/alignment/stack/Panoptes/Rich/RichMirrorAlignmentOnline/files/workflow_configuration/rich' - '/group/rich/AlignmentFiles/FitAlignConfs/rich' + str( - self.whichRich) + '_fit_align_confs.yml', - self.workdir + '/' + 'rich' + str(self.whichRich) + - '_fit_align_confs.yml') - with open(self.workdir + '/' + 'rich' + str(self.whichRich) + - '_fit_align_confs.yml') as finp: + "/group/rich/AlignmentFiles/FitAlignConfs/rich" + + str(self.whichRich) + + "_fit_align_confs.yml", + self.workdir + + "/" + + "rich" + + str(self.whichRich) + + "_fit_align_confs.yml", + ) + with open( + self.workdir + + "/" + + "rich" + + str(self.whichRich) + + "_fit_align_confs.yml" + ) as finp: conf = yaml.load(finp) last_timestamp = list(conf)[-1] copy_last_conf = copy.deepcopy(conf[last_timestamp]) conf_new[dt] = copy_last_conf - conf_new[dt]['fit_conf'][ - 'plotDir'] = combinFitPlotDir # PN: Need to fix, all plots appear in _i0 directory - conf_new[dt]['fit_conf']['workDir'] = self.workdir - conf_new[dt]['fit_conf']['fixSinusoidShift'] = \ - self.fixSinusoidShift - conf_new[dt]['fit_conf']['sinusoidShift'] = 0. - conf_new[dt]['fit_conf']['zeroGlobalFitMean'] = False - conf_new[dt]['fit_conf']['useGlobalFitMean'] = False - conf_new[dt]['fit_conf']['minAverageBinPop'] = \ - self.minAverageBinPop - conf_new[dt]['fit_conf']['phiBinFactor'] = self.phiBinFactor - conf_new[dt]['fit_conf']['minFracPhiBinsPopulated'] = \ + conf_new[dt]["fit_conf"]["plotDir"] = ( + combinFitPlotDir # PN: Need to fix, all plots appear in _i0 directory + ) + conf_new[dt]["fit_conf"]["workDir"] = self.workdir + conf_new[dt]["fit_conf"]["fixSinusoidShift"] = self.fixSinusoidShift + conf_new[dt]["fit_conf"]["sinusoidShift"] = 0.0 + conf_new[dt]["fit_conf"]["zeroGlobalFitMean"] = False + conf_new[dt]["fit_conf"]["useGlobalFitMean"] = False + conf_new[dt]["fit_conf"]["minAverageBinPop"] = self.minAverageBinPop + conf_new[dt]["fit_conf"]["phiBinFactor"] = self.phiBinFactor + conf_new[dt]["fit_conf"]["minFracPhiBinsPopulated"] = ( self.minFracPhiBinsPopulated - conf_new[dt]['fit_conf']['deltaThetaWindow'] = \ - self.deltaThetaWindow - conf_new[dt]['fit_conf']['combinFitMethod'] = \ - self.combinFitMethod - conf_new[dt]['fit_conf']['backgroundOrder'] = 2 - conf_new[dt]['fit_conf']['plotOutputLevel'] = 2 - conf_new[dt]['fit_conf']['warningFactor'] = \ - self.alignConf.getProp('warningFactor') - conf_new[dt]['fit_conf']['stopToleranceMode'] = \ - self.alignConf.getProp( - 'stopToleranceMode') # PN: same as for RichMirrAlign - conf_new[dt]['fit_conf'][ - 'stopTolerance'] = 0.23 # PN: I have no idea what this is for - conf_new[dt]['fit_conf']['nominalResolutionSigma'] = \ - self.alignConf.getProp('nominalResolutionSigma') - conf_new[dt]['fit_conf']['stopSigmaFraction'] = \ - self.alignConf.getProp('stopSigmaFraction' + ) + conf_new[dt]["fit_conf"]["deltaThetaWindow"] = self.deltaThetaWindow + conf_new[dt]["fit_conf"]["combinFitMethod"] = self.combinFitMethod + conf_new[dt]["fit_conf"]["backgroundOrder"] = 2 + conf_new[dt]["fit_conf"]["plotOutputLevel"] = 2 + conf_new[dt]["fit_conf"]["warningFactor"] = self.alignConf.getProp( + "warningFactor" + ) + conf_new[dt]["fit_conf"]["stopToleranceMode"] = self.alignConf.getProp( + "stopToleranceMode" + ) # PN: same as for RichMirrAlign + conf_new[dt]["fit_conf"]["stopTolerance"] = ( + 0.23 # PN: I have no idea what this is for + ) + conf_new[dt]["fit_conf"]["nominalResolutionSigma"] = self.alignConf.getProp( + "nominalResolutionSigma" + ) + conf_new[dt]["fit_conf"]["stopSigmaFraction"] = self.alignConf.getProp( + "stopSigmaFraction" ) # PN: we used to only provide this to RichMirrAlign, now we provide it to RichMirrCombinFit? - this is currently 0 in the configuration! - conf_new[dt]['align_conf']['magnFactorsMode'] = \ - self.magnFactorsMode - conf_new[dt]['align_conf']['solutionMethod'] = \ - self.solutionMethod - conf_new[dt]['align_conf']['usePremisaligned'] = False - conf_new[dt]['align_conf']['stopToleranceMode'] = \ - self.alignConf.getProp('stopToleranceMode') - conf_new[dt]['align_conf']['stopTolerancePriY'] = \ - self.alignConf.getProp('stopTolerancePriY') - conf_new[dt]['align_conf']['stopTolerancePriZ'] = \ - self.alignConf.getProp('stopTolerancePriZ') - conf_new[dt]['align_conf']['stopToleranceSecY'] = \ - self.alignConf.getProp('stopToleranceSecY') - conf_new[dt]['align_conf']['stopToleranceSecZ'] = \ - self.alignConf.getProp('stopToleranceSecZ') - conf_new[dt]['align_conf']['stopDecisionMode'] = \ - self.alignConf.getProp('stopDecisionMode') - conf_new[dt]['align_conf']['regularizationMode'] = \ - self.alignConf.getProp('regularizationMode') - conf_new[dt]['align_conf']['printMode'] = 2 + conf_new[dt]["align_conf"]["magnFactorsMode"] = self.magnFactorsMode + conf_new[dt]["align_conf"]["solutionMethod"] = self.solutionMethod + conf_new[dt]["align_conf"]["usePremisaligned"] = False + conf_new[dt]["align_conf"]["stopToleranceMode"] = self.alignConf.getProp( + "stopToleranceMode" + ) + conf_new[dt]["align_conf"]["stopTolerancePriY"] = self.alignConf.getProp( + "stopTolerancePriY" + ) + conf_new[dt]["align_conf"]["stopTolerancePriZ"] = self.alignConf.getProp( + "stopTolerancePriZ" + ) + conf_new[dt]["align_conf"]["stopToleranceSecY"] = self.alignConf.getProp( + "stopToleranceSecY" + ) + conf_new[dt]["align_conf"]["stopToleranceSecZ"] = self.alignConf.getProp( + "stopToleranceSecZ" + ) + conf_new[dt]["align_conf"]["stopDecisionMode"] = self.alignConf.getProp( + "stopDecisionMode" + ) + conf_new[dt]["align_conf"]["regularizationMode"] = self.alignConf.getProp( + "regularizationMode" + ) + conf_new[dt]["align_conf"]["printMode"] = 2 print("INFO: Last Timestamp: ", last_timestamp) print("INFO: Current Timestamp: ", dt) - if dt != last_timestamp: # if same timestamp, then we are doing some sort of testing with external root and YAML configuration files + if ( + dt != last_timestamp + ): # if same timestamp, then we are doing some sort of testing with external root and YAML configuration files with open( - self.workdir + '/' + 'rich' + str(self.whichRich) + - '_fit_align_confs.yml', 'a') as fout: - yaml.boolean_representation = ['false', 'true'] + self.workdir + + "/" + + "rich" + + str(self.whichRich) + + "_fit_align_confs.yml", + "a", + ) as fout: + yaml.boolean_representation = ["false", "true"] yaml.dump(conf_new, fout) - fitOutputFile = combinFitDir + "Rich" + str( - self.whichRich - ) + "MirrCombinFitOut_" + self.thisNameStr + connectStr + tiltName + "_i" + str( - n_it) + ".txt" - fitStdOutFile = combinFitDir + "Rich" + str( - self.whichRich - ) + "MirrCombinFitStdOut_" + self.thisNameStr + connectStr + tiltName + "_i" + str( - n_it) + ".txt" - fitStdErrFile = combinFitDir + "Rich" + str( - self.whichRich - ) + "MirrCombinFitStdErr_" + self.thisNameStr + connectStr + tiltName + "_i" + str( - n_it) + ".txt" - myStdOut = open(fitStdOutFile, 'w') - myStdErr = open(fitStdErrFile, 'w') - cmd = "cd " + self.workdir + " ; `which RichMirrCombinFit` " + "rich" + str( - self.whichRich - ) + " " + tiltName + " > " + fitOutputFile + " ; cd - " + fitOutputFile = ( + combinFitDir + + "Rich" + + str(self.whichRich) + + "MirrCombinFitOut_" + + self.thisNameStr + + connectStr + + tiltName + + "_i" + + str(n_it) + + ".txt" + ) + fitStdOutFile = ( + combinFitDir + + "Rich" + + str(self.whichRich) + + "MirrCombinFitStdOut_" + + self.thisNameStr + + connectStr + + tiltName + + "_i" + + str(n_it) + + ".txt" + ) + fitStdErrFile = ( + combinFitDir + + "Rich" + + str(self.whichRich) + + "MirrCombinFitStdErr_" + + self.thisNameStr + + connectStr + + tiltName + + "_i" + + str(n_it) + + ".txt" + ) + myStdOut = open(fitStdOutFile, "w") + myStdErr = open(fitStdErrFile, "w") + cmd = ( + "cd " + + self.workdir + + " ; `which RichMirrCombinFit` " + + "rich" + + str(self.whichRich) + + " " + + tiltName + + " > " + + fitOutputFile + + " ; cd - " + ) print(f"INFO: Starting RichMirrCombinFit.") print(f"INFO: cmd = {cmd}") sys.stdout.flush() @@ -660,7 +735,8 @@ class RichAlignmentHelper: shell=True, executable="/bin/bash", stdout=myStdOut, - stderr=myStdErr) + stderr=myStdErr, + ) myStdOut.close() myStdErr.close() ps.append(p2) @@ -673,9 +749,12 @@ class RichAlignmentHelper: if all([x is not None for x in ps_status]): PopenTotal = 0 for l in ps_status: - if l is not None: PopenTotal += 1 - print("INFO: %d of %d RichMirrCombinFit processes complete" % - (PopenTotal, tiltNamesLength)) + if l is not None: + PopenTotal += 1 + print( + "INFO: %d of %d RichMirrCombinFit processes complete" + % (PopenTotal, tiltNamesLength) + ) print("INFO: ", strftime("%Y-%m-%d %H:%M:%S", gmtime())) print("INFO: -------------------") sys.stdout.flush() @@ -683,10 +762,13 @@ class RichAlignmentHelper: else: PopenDone = 0 for l in ps_status: - if l is not None: PopenDone += 1 + if l is not None: + PopenDone += 1 if PopenDone > PopenCount: - print("INFO: %d of %d RichMirrCombinFit processes complete" - % (PopenDone, tiltNamesLength)) + print( + "INFO: %d of %d RichMirrCombinFit processes complete" + % (PopenDone, tiltNamesLength) + ) print("INFO: ", strftime("%Y-%m-%d %H:%M:%S", gmtime())) print("INFO: -------------------") PopenCount = 0 + PopenDone @@ -700,24 +782,49 @@ class RichAlignmentHelper: _tiltNames = self.tiltNames yaml = YAML() - with open(self.workdir + '/' + 'rich' + str(self.whichRich) + - '_variant.yml') as finp: + with open( + self.workdir + "/" + "rich" + str(self.whichRich) + "_variant.yml" + ) as finp: variant = yaml.load(finp) for tiltNum, tiltName in enumerate(_tiltNames): - if (tiltName == ""): + if tiltName == "": connectStr = "" else: connectStr = "_" - combinFitDir = self.workdir + variant + "_histos" \ - + connectStr + tiltName + "_i" + str(n_it) + "/" + combinFitDir = ( + self.workdir + + variant + + "_histos" + + connectStr + + tiltName + + "_i" + + str(n_it) + + "/" + ) print("INFO: expected combinFitDir " + combinFitDir) - combinResultsFile = self.workdir + variant + "_fit_res" \ - + connectStr + tiltName + "_i" + str(n_it) + ".txt" + combinResultsFile = ( + self.workdir + + variant + + "_fit_res" + + connectStr + + tiltName + + "_i" + + str(n_it) + + ".txt" + ) print("INFO: expected combinResultsFile " + combinResultsFile) - magnificationOutputFile = self.workdir + variant + "_magnifs" + connectStr + tiltName + "_i" + str( - n_it) + ".txt" # + magnificationOutputFile = ( + self.workdir + + variant + + "_magnifs" + + connectStr + + tiltName + + "_i" + + str(n_it) + + ".txt" + ) # sys.stdout.flush() p = [] @@ -744,39 +851,42 @@ class RichAlignmentHelper: pNoTilt.append(newpars) line = fitfile.readline() - with open(magnificationOutputFile, 'w') as magfile: + with open(magnificationOutputFile, "w") as magfile: for i, sp in enumerate(p): tiltSign = 1.0 - #if tiltName.count('neg') > 0: - if tiltName.count('n') > 0: + # if tiltName.count('neg') > 0: + if tiltName.count("n") > 0: tiltSign = -1.0 mirrPair = sp[0] - Y = (sp[1] - pNoTilt[i][1]) / ( - self.coeffCalibTilt * tiltSign) - Z = (sp[3] - pNoTilt[i][3]) / ( - self.coeffCalibTilt * tiltSign) - magfile.write(mirrPair + " " + str(Y) + " " + str(Z) + - "\n") - - #richMirrAlignConfFile = self.workdir + "Rich" + str( + Y = (sp[1] - pNoTilt[i][1]) / (self.coeffCalibTilt * tiltSign) + Z = (sp[3] - pNoTilt[i][3]) / (self.coeffCalibTilt * tiltSign) + magfile.write(mirrPair + " " + str(Y) + " " + str(Z) + "\n") + + # richMirrAlignConfFile = self.workdir + "Rich" + str( # self.whichRich) + "MirrAlign_i" + str(n_it) + ".conf" - richMirrAlignOutFile = self.workdir + "Rich" + str( - self.whichRich) + "MirrAlignOut_i" + str(n_it) + ".txt" - #richMirrAlignNanOutFile = self.workdir + "Rich" + str( + richMirrAlignOutFile = ( + self.workdir + + "Rich" + + str(self.whichRich) + + "MirrAlignOut_i" + + str(n_it) + + ".txt" + ) + # richMirrAlignNanOutFile = self.workdir + "Rich" + str( # self.whichRich) + "MirrAlignNanOut_i" + str(n_it) + ".txt" - combinFitDir = self.workdir + variant + "_histos" \ - + "_i" + str(n_it) + "/" - combinResultsFile = self.workdir + variant + "_fit_res" \ - + "_i" + str(n_it) + ".txt" + combinFitDir = self.workdir + variant + "_histos" + "_i" + str(n_it) + "/" + combinResultsFile = ( + self.workdir + variant + "_fit_res" + "_i" + str(n_it) + ".txt" + ) # - #currentMirrorYAMLFile = self.workdir + "Rich" + str( + # currentMirrorYAMLFile = self.workdir + "Rich" + str( # self.whichRich) + "CondDBUpdate_" + self.thisNameStr + "_i" + str( # n_it) + ".yml" - #nextIterationYAMLFile = self.workdir + "Rich" + str( + # nextIterationYAMLFile = self.workdir + "Rich" + str( # self.whichRich) + "CondDBUpdate_" + self.thisNameStr + "_i" + str( # n_it + 1) + ".yml" - #zeroMirrorYAMLFile = self.workdir + "Rich" + str( + # zeroMirrorYAMLFile = self.workdir + "Rich" + str( # self.whichRich) + "CondDBUpdate_" + self.thisNameStr + "_i0.yml" """ if os.path.exists(richMirrAlignConfFile): @@ -818,23 +928,40 @@ class RichAlignmentHelper: f.close() """ - alignStdOutFile = self.workdir + "Rich" + str( - self.whichRich) + "MirrAlignStdOut_i" + str(n_it) + ".txt" - alignStdErrFile = self.workdir + "Rich" + str( - self.whichRich) + "MirrAlignStdErr_i" + str(n_it) + ".txt" - myStdOut = open(alignStdOutFile, 'w') - myStdErr = open(alignStdErrFile, 'w') - cmd = "cd " + self.workdir + " ; `which RichMirrAlign` " + "rich" + str( - self.whichRich) + " > " + richMirrAlignOutFile + " ; cd - " + alignStdOutFile = ( + self.workdir + + "Rich" + + str(self.whichRich) + + "MirrAlignStdOut_i" + + str(n_it) + + ".txt" + ) + alignStdErrFile = ( + self.workdir + + "Rich" + + str(self.whichRich) + + "MirrAlignStdErr_i" + + str(n_it) + + ".txt" + ) + myStdOut = open(alignStdOutFile, "w") + myStdErr = open(alignStdErrFile, "w") + cmd = ( + "cd " + + self.workdir + + " ; `which RichMirrAlign` " + + "rich" + + str(self.whichRich) + + " > " + + richMirrAlignOutFile + + " ; cd - " + ) print("INFO: Starting RichMirrAlign. ") print("INFO: cmd = " + cmd) sys.stdout.flush() p3 = Popen( - cmd, - shell=True, - executable="/bin/bash", - stdout=myStdOut, - stderr=myStdErr) + cmd, shell=True, executable="/bin/bash", stdout=myStdOut, stderr=myStdErr + ) p3.communicate() myStdOut.close() myStdErr.close() @@ -848,33 +975,59 @@ class RichAlignmentHelper: _tiltNames = self.tiltNames yaml = YAML() - with open(self.workdir + '/' + 'rich' + str(self.whichRich) + - '_variant.yml') as finp: + with open( + self.workdir + "/" + "rich" + str(self.whichRich) + "_variant.yml" + ) as finp: variant = yaml.load(finp) for tiltName in _tiltNames: - if (tiltName == ""): + if tiltName == "": connectStr = "" else: connectStr = "_" - combinFitDir = self.workdir + variant + "_histos" \ - + connectStr + tiltName + "_i" + str(n_it) + "/" - fitOutputFile = combinFitDir + "Rich" + str( - self.whichRich - ) + "MirrCombinFitOut_" + self.thisNameStr + connectStr + tiltName + "_i" + str( - n_it) + ".txt" - fitNGEFile = combinFitDir + "Rich" + str( - self.whichRich - ) + "MirrCombinFitNGEOut_" + self.thisNameStr + connectStr + tiltName + "_i" + str( - n_it) + ".txt" + combinFitDir = ( + self.workdir + + variant + + "_histos" + + connectStr + + tiltName + + "_i" + + str(n_it) + + "/" + ) + fitOutputFile = ( + combinFitDir + + "Rich" + + str(self.whichRich) + + "MirrCombinFitOut_" + + self.thisNameStr + + connectStr + + tiltName + + "_i" + + str(n_it) + + ".txt" + ) + fitNGEFile = ( + combinFitDir + + "Rich" + + str(self.whichRich) + + "MirrCombinFitNGEOut_" + + self.thisNameStr + + connectStr + + tiltName + + "_i" + + str(n_it) + + ".txt" + ) - os.system('cat ' + fitOutputFile + - ' | grep " not_good_enough " > ' + fitNGEFile) + os.system( + "cat " + fitOutputFile + ' | grep " not_good_enough " > ' + fitNGEFile + ) if not os.path.exists(fitNGEFile): print("ERROR: no fitNGEFile.") num_lines = sum(1 for line in open(fitNGEFile)) - if (num_lines != 0): + if num_lines != 0: print( "WARNING: Not enough well populated phi-bins in all mirror combination histograms. Will perform all fits anyway." ) @@ -884,19 +1037,20 @@ class RichAlignmentHelper: return True def old_hasConverged(self): - if not os.path.exists(self.workdir + "rich" + str(self.whichRich) + - "_stop_or_continue.txt"): - print("ERROR: no rich" + str(self.whichRich) + - "_stop_or_continue_txt file.") - rich_stop_or_continue_txt = open(self.workdir + "rich" + - str(self.whichRich) + - "_stop_or_continue.txt") + if not os.path.exists( + self.workdir + "rich" + str(self.whichRich) + "_stop_or_continue.txt" + ): + print( + "ERROR: no rich" + str(self.whichRich) + "_stop_or_continue_txt file." + ) + rich_stop_or_continue_txt = open( + self.workdir + "rich" + str(self.whichRich) + "_stop_or_continue.txt" + ) verdict = rich_stop_or_continue_txt.readline().strip().upper() rich_stop_or_continue_txt.close() print("INFO: Verdict: " + str(verdict)) sys.stdout.flush() - if (verdict == "STOP"): + if verdict == "STOP": return True - if (verdict != "STOP" and verdict != "STOP_NAN" - and verdict != "STOP_NGE"): + if verdict != "STOP" and verdict != "STOP_NAN" and verdict != "STOP_NGE": return False diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/RichAnalyzer.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/RichAnalyzer.py index 0027785d698376a21731bd586493edf389561e35..101262b48d5a699b92fe81e4b81004e0c6391545 100755 --- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/RichAnalyzer.py +++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/RichAnalyzer.py @@ -8,21 +8,25 @@ # granted to it by virtue of its status as an Intergovernmental Organization # # or submit itself to any jurisdiction. # ############################################################################### -import glob import csv -import math import datetime -from ruamel.yaml import YAML -import sys -import os, re +import getpass +import glob +import math +import os +import re import shutil +import sys import time from time import gmtime, strftime -from PyMirrAlignOnline.Communicator import * -import getpass -from MooreOnlineConf.utils import ( - alignment_options, ) + import OnlineEnvBase as OnlineEnv +from MooreOnlineConf.utils import ( + alignment_options, +) +from ruamel.yaml import YAML + +from PyMirrAlignOnline.Communicator import * print(f"RichAnalyzer __name__ = {__name__}") @@ -32,7 +36,7 @@ class hlt2_reco_rich_noUT_panoptes_dd4hep_both: self.whichRich = self.Rich() def Rich( - self + self, ): # RichAnalyzer must be running in the workDir for this to be correct def check_directory(): cwd = os.getcwd() @@ -52,29 +56,30 @@ class hlt2_reco_rich_noUT_panoptes_dd4hep_both: def run(self): # main code whichRich = self.whichRich - rich = f'rich{whichRich}' - radiator = f'Rich{whichRich}Gas' + rich = f"rich{whichRich}" + radiator = f"Rich{whichRich}Gas" if whichRich == 1: from Configurables import Rich1MirrAlignOnConf - #from Configuration import Rich1MirrAlignOnConf + + # from Configuration import Rich1MirrAlignOnConf alignConf = Rich1MirrAlignOnConf() elif whichRich == 2: from Configurables import Rich2MirrAlignOnConf - #from Configuration import Rich2MirrAlignOnConf + + # from Configuration import Rich2MirrAlignOnConf alignConf = Rich2MirrAlignOnConf() alignConf.__apply_configuration__() - EvtMax = alignConf.getProp('EvtMax') # this isn't currently used - workdir = alignConf.getProp('WorkDir') - useHltDecisions = alignConf.getProp('useHltDecisions') - dataVariant = alignConf.getProp('dataVariant') + EvtMax = alignConf.getProp("EvtMax") # this isn't currently used + workdir = alignConf.getProp("WorkDir") + useHltDecisions = alignConf.getProp("useHltDecisions") + dataVariant = alignConf.getProp("dataVariant") runAnalyzer = "UNKNOWN" while runAnalyzer != "YES": yaml = YAML() - while not os.path.exists( - f"{workdir}rich{whichRich}_runAnalyzer.yml"): + while not os.path.exists(f"{workdir}rich{whichRich}_runAnalyzer.yml"): time.sleep(4) with open(f"{workdir}rich{whichRich}_runAnalyzer.yml") as finp: runAnalyzer = yaml.load(finp) @@ -113,81 +118,114 @@ class hlt2_reco_rich_noUT_panoptes_dd4hep_both: # Since we are doing this by hand, specify the iteration number in stdin if count == 2 and arguments[1] in [ - '0', '1', '2', '3', '4', '5', '6', '7', '8' + "0", + "1", + "2", + "3", + "4", + "5", + "6", + "7", + "8", ]: n_it = int(arguments[1]) if count == 1 and arguments[0] in [ - '0', '1', '2', '3', '4', '5', '6', '7', '8' + "0", + "1", + "2", + "3", + "4", + "5", + "6", + "7", + "8", ]: n_it = int(arguments[0]) # possible tiltname can be given via stdin if count == 2 and arguments[0] in [ - "priYn", "priYp", "priZn", "priZp", "secYn", "secYp", - "secZn", "secZp" + "priYn", + "priYp", + "priZn", + "priZp", + "secYn", + "secYp", + "secZn", + "secZp", ]: tiltName = arguments[0] # For Rich1 - #tiltName = "" # uses 'alignment2022' - #tiltName = "priYn" # uses '2022_12_06_Rich1_priYn', a branch of 'alignment2022' - #tiltName = "priYp" # uses '2022_12_06_Rich1 - #tiltName = "priZn" # uses '2022_12_06_Rich1 - #tiltName = "priZp" # uses '2022_12_06_Rich1 - #tiltName = "secYn" # uses '2022_12_06_Rich1 - #tiltName = "secYp" # uses '2022_12_06_Rich1 - #tiltName = "secZn" # uses '2022_12_06_Rich1 - #tiltName = "secZp" # uses '2022_12_06_Rich1 + # tiltName = "" # uses 'alignment2022' + # tiltName = "priYn" # uses '2022_12_06_Rich1_priYn', a branch of 'alignment2022' + # tiltName = "priYp" # uses '2022_12_06_Rich1 + # tiltName = "priZn" # uses '2022_12_06_Rich1 + # tiltName = "priZp" # uses '2022_12_06_Rich1 + # tiltName = "secYn" # uses '2022_12_06_Rich1 + # tiltName = "secYp" # uses '2022_12_06_Rich1 + # tiltName = "secZn" # uses '2022_12_06_Rich1 + # tiltName = "secZp" # uses '2022_12_06_Rich1 # For Rich2 - #tiltName = "" # uses '2022_12_08_Rich2_2018' - #tiltName = "priYn" # uses '2022_??_??_Rich2_priYn', a branch of '2022_12_08_Rich2_2018' - #tiltName = "priYp" # uses '2022_??_??_Rich2 - #tiltName = "priZn" # uses '2022_??_??_Rich2 - #tiltName = "priZp" # uses '2022_??_??_Rich2 - #tiltName = "secYn" # uses '2022_??_??_Rich2 - #tiltName = "secYp" # uses '2022_??_??_Rich2 - #tiltName = "secZn" # uses '2022_??_??_Rich2 - #tiltName = "secZp" # uses '2022_??_??_Rich2 + # tiltName = "" # uses '2022_12_08_Rich2_2018' + # tiltName = "priYn" # uses '2022_??_??_Rich2_priYn', a branch of '2022_12_08_Rich2_2018' + # tiltName = "priYp" # uses '2022_??_??_Rich2 + # tiltName = "priZn" # uses '2022_??_??_Rich2 + # tiltName = "priZp" # uses '2022_??_??_Rich2 + # tiltName = "secYn" # uses '2022_??_??_Rich2 + # tiltName = "secYp" # uses '2022_??_??_Rich2 + # tiltName = "secZn" # uses '2022_??_??_Rich2 + # tiltName = "secZp" # uses '2022_??_??_Rich2 print(f"INFO: Iteration: {n_it}") print(f"INFO: Tilt Name: {tiltName}") if tiltName not in [ - "", "priYn", "priYp", "priZn", "priZp", "secYn", "secYp", - "secZn", "secZp" + "", + "priYn", + "priYp", + "priZn", + "priZp", + "secYn", + "secYp", + "secZn", + "secZp", ]: print(f"ERROR: This is not a valid tiltName") sys.stdout.flush() - from GaudiKernel.SystemOfUnits import (GeV, MeV, mm, mrad) + from GaudiKernel.SystemOfUnits import GeV, MeV, mm, mrad from Moore import ( options, run_reconstruction, ) - + from Panoptes.alignment import ( + standalone_rich_online_align_reco, + standalone_rich_panel_align_reco, + ) + from PyConf.Algorithms import ( + PrForwardTrackingVelo, + PrHybridSeeding, + PrMatchNN, + VeloRetinaClusterTrackingSIMD, + VPRetinaFullClusterDecoder, + ) + from RecoConf.legacy_rec_hlt1_tracking import ( + make_PatPV3DFuture_pvs, + make_reco_pvs, + make_velo_full_clusters, + make_VeloClusterTrackingSIMD, + ) from RecoConf.rich_data_monitoring import ( - default_rich_monitoring_options, alignment_rich_monitoring_options, + default_rich_monitoring_options, ) - - from PyConf.Algorithms import (PrForwardTrackingVelo, - VPRetinaFullClusterDecoder) - from PyConf.Algorithms import PrMatchNN, PrHybridSeeding - from PyConf.Algorithms import VeloRetinaClusterTrackingSIMD - from RecoConf.legacy_rec_hlt1_tracking import make_VeloClusterTrackingSIMD - from RecoConf.legacy_rec_hlt1_tracking import ( - make_reco_pvs, make_PatPV3DFuture_pvs, make_velo_full_clusters) - from RecoConf.rich_reconstruction import default_rich_reco_options - from Panoptes.alignment import ( - standalone_rich_online_align_reco, - standalone_rich_panel_align_reco, - ) """Options for running over data with FT raw bank version 6.""" from RecoConf.decoders import ( - default_ft_decoding_version, ) + default_ft_decoding_version, + ) options.scheduler_legacy_mode = False - #options.use_iosvc = False + # options.use_iosvc = False options.n_threads = 40 # 1 print(f"Using HLT decisions: {useHltDecisions}") @@ -201,8 +239,9 @@ class hlt2_reco_rich_noUT_panoptes_dd4hep_both: options.input_type = "MDF" else: options.set_input_and_conds_from_testfiledb( - 'upgrade_Sept2022_minbias_0fb_md_xdigi') - options.input_type = 'ROOT' + "upgrade_Sept2022_minbias_0fb_md_xdigi" + ) + options.input_type = "ROOT" useDD4Hep = True @@ -226,38 +265,61 @@ class hlt2_reco_rich_noUT_panoptes_dd4hep_both: if "Collision23" in dataVariant or "Collision24" in dataVariant: if useUT_bool: - dd4hep = DD4hepSvc(DetectorList=[ - "/world", "Magnet", "UT", "VP", "FT", "Rich1", "Rich2" - ]) + dd4hep = DD4hepSvc( + DetectorList=[ + "/world", + "Magnet", + "UT", + "VP", + "FT", + "Rich1", + "Rich2", + ] + ) noUT_bool = False else: - dd4hep = DD4hepSvc(DetectorList=[ - "/world", "Magnet", "VP", "FT", "Rich1", "Rich2" - ]) + dd4hep = DD4hepSvc( + DetectorList=["/world", "Magnet", "VP", "FT", "Rich1", "Rich2"] + ) noUT_bool = True elif "Collision22" in dataVariant: - dd4hep = DD4hepSvc(DetectorList=[ - "/world", "Magnet", "UT", "VP", "FT", "Rich1", "Rich2" - ]) + dd4hep = DD4hepSvc( + DetectorList=[ + "/world", + "Magnet", + "UT", + "VP", + "FT", + "Rich1", + "Rich2", + ] + ) dd4hep.OutputLevel = 1 richFilesDir = alignConf.getProp( - 'richFiles') # '/group/rich/AlignmentFiles/' + "richFiles" + ) # '/group/rich/AlignmentFiles/' if useCondDBPath: if "Collision23" in dataVariant: - conddb_path = f'{richFilesDir}lhcb-conditions-database_master_CloneForRich' + conddb_path = ( + f"{richFilesDir}lhcb-conditions-database_master_CloneForRich" + ) elif "Collision22" in dataVariant: # conddb_path = f'{richFilesDir}lhcb-conditions-database_alignment2022_SingleNodeIterator' # conddb_path = f'/group/rich/sw/alignment/lhcb-conditions-database' - #conddb_path = f'{richFilesDir}lhcb-conditions-database_Feb24' #use for sajan branch - conddb_path = '/group/rich/sw/alignment/lhcb-conditions-database' + # conddb_path = f'{richFilesDir}lhcb-conditions-database_Feb24' #use for sajan branch + conddb_path = "/group/rich/sw/alignment/lhcb-conditions-database" elif "Collision24" in dataVariant: - conddb_path = '/group/rich/sw/alignment/lhcb-conditions-database-new' + conddb_path = ( + "/group/rich/sw/alignment/lhcb-conditions-database-new" + ) # conddb_path = '/swdev/marshall/lhcb-conditions-database' if useConditionsOverlay: - conddb_path = '/group/online/hlt/conditions.run3/lhcb-conditions-database' + conddb_path = ( + "/group/online/hlt/conditions.run3/lhcb-conditions-database" + ) dd4hep.ConditionsLocation = f"file://{conddb_path}" else: pass @@ -272,7 +334,9 @@ class hlt2_reco_rich_noUT_panoptes_dd4hep_both: if "Collision23" in dataVariant: dd4hep.ConditionsVersion = OnlineEnv.CondDBTag elif "Collision22" in dataVariant: - dd4hep.ConditionsVersion = 'alignment2022' # need alignment2022 for 2022 data + dd4hep.ConditionsVersion = ( + "alignment2022" # need alignment2022 for 2022 data + ) elif "Collision24" in dataVariant: dd4hep.ConditionsVersion = OnlineEnv.CondDBTag @@ -285,14 +349,14 @@ class hlt2_reco_rich_noUT_panoptes_dd4hep_both: # We don't really need this part, unless we later choose to # get the latest DB from the git clone DB # (we currently get it from the online DB, I think) - #from subprocess import * - #cmd = "cd " + conddb_path + " ; git checkout . ; cd - " - #p = Popen( + # from subprocess import * + # cmd = "cd " + conddb_path + " ; git checkout . ; cd - " + # p = Popen( # cmd, # shell=True, # executable="/bin/bash") - #p.communicate() - #sys.stdout.flush() + # p.communicate() + # sys.stdout.flush() re_version = re.compile(r"^([0-9]+)$") @@ -303,11 +367,9 @@ class hlt2_reco_rich_noUT_panoptes_dd4hep_both: else: return int(r.group(0)) - def find_highest_version_below(directory_str, - lowestRunInData): + def find_highest_version_below(directory_str, lowestRunInData): versions = [ - get_version(file) - for file in os.listdir(directory_str) + get_version(file) for file in os.listdir(directory_str) ] versions_below_latest = [ v for v in versions if v <= lowestRunInData @@ -318,8 +380,7 @@ class hlt2_reco_rich_noUT_panoptes_dd4hep_both: fromFile = f"{workdir}" + f"CondDB_Rich{whichRich}.yml" directory = f"{conddb_path}/Conditions/Rich{whichRich}/Alignment/Mirrors.yml/" - latestName = max( - os.listdir(directory), key=get_version) # default + latestName = max(os.listdir(directory), key=get_version) # default # PN - this will be OK so long as the list of runs # - does not span across several mirror alignment versions # - already in the Mirrors.yml directory @@ -328,15 +389,15 @@ class hlt2_reco_rich_noUT_panoptes_dd4hep_both: # - and the next higher version # PN - FUTURE PROBLEM TO SOLVE... how can we re-run the alignment on data # - that spans existing alignments, should we ever want to (would we?) - if "online" in getpass.getuser( - ): # Get List of Runs from Online + if "online" in getpass.getuser(): # Get List of Runs from Online import OnlineEnvBase as Online # import OnlineEnv as Online + online_options = alignment_options(Online) runs = online_options.runs # runs = Online.DeferredRuns # PN - Extract the run number substring from the full string # - WILL NOT WORK IF RUN NUMBERS BECOME 7 DIGITS runs = [entry[-6:] for entry in runs] - #for i in range(0, len(runs), 14): + # for i in range(0, len(runs), 14): # batch = runs[i:i + 14] # if i == 0: # print("INFO: runs:", batch) @@ -345,30 +406,26 @@ class hlt2_reco_rich_noUT_panoptes_dd4hep_both: runs_int = list(map(int, runs)) runs_int.sort() for i in range(0, len(runs_int), 14): - batch = runs_int[i:i + 14] + batch = runs_int[i : i + 14] if i == 0: print("INFO: runs_int (sorted):", batch) else: print(" ", batch) lowestRun = runs_int[0] - print("INFO: Lowest run number being processed:", - lowestRun) - latestName = find_highest_version_below( - directory, lowestRun) + print("INFO: Lowest run number being processed:", lowestRun) + latestName = find_highest_version_below(directory, lowestRun) else: # PN - need to figure out what to do in testbench case, trying this for now input_files = options.input_files lowestRun = 9999999 for j in input_files: # PN - Extract the number from the file string using regular expressions # - WILL NOT WORK IF RUN NUMBERS BECOME 7 DIGITS - num = int(re.search(r'/0000(\d{6})/', j).group(1)) + num = int(re.search(r"/0000(\d{6})/", j).group(1)) # Check if the number is lower if num < lowestRun: lowestRun = num - print("INFO: Lowest run number being processed:", - lowestRun) - latestName = find_highest_version_below( - directory, lowestRun) + print("INFO: Lowest run number being processed:", lowestRun) + latestName = find_highest_version_below(directory, lowestRun) toFile = f"{conddb_path}/Conditions/Rich{whichRich}/Alignment/Mirrors.yml/{latestName}" @@ -377,13 +434,12 @@ class hlt2_reco_rich_noUT_panoptes_dd4hep_both: shutil.copyfile(fromFile, toFile) sys.stdout.flush() elif useConditionsOverlay: - doCondOverlay = False if n_it == 0: dd4hep.UseConditionsOverlay = False # only change conditions on it0 if there is a starting yaml defined - yamlCondUpdate = alignConf.getProp('startYAMLFile') + yamlCondUpdate = alignConf.getProp("startYAMLFile") if yamlCondUpdate != "": fromFile = yamlCondUpdate doCondOverlay = True @@ -394,7 +450,9 @@ class hlt2_reco_rich_noUT_panoptes_dd4hep_both: if doCondOverlay: dd4hep.UseConditionsOverlay = True - dd4hep.ConditionsOverlayInitPath = '/group/rich/sw/alignment/ConditionsOverlay' + dd4hep.ConditionsOverlayInitPath = ( + "/group/rich/sw/alignment/ConditionsOverlay" + ) toFile = f"/group/rich/sw/alignment/ConditionsOverlay/Conditions/Rich{whichRich}/Alignment/Mirrors.yml" @@ -404,9 +462,10 @@ class hlt2_reco_rich_noUT_panoptes_dd4hep_both: sys.stdout.flush() else: - options.conddb_tag = 'jonrob/all-pmts-active' # used for DetDesc MC samples with DD4Hep - DDDBConf( - ).GeometryVersion = 'before-rich1-geom-update-26052022' # used for DetDesc MC samples with DD4Hep + options.conddb_tag = ( + "jonrob/all-pmts-active" # used for DetDesc MC samples with DD4Hep + ) + DDDBConf().GeometryVersion = "before-rich1-geom-update-26052022" # used for DetDesc MC samples with DD4Hep # dd4hep.LimitedIOVPaths = [ # # Tel40 links condition @@ -443,10 +502,10 @@ class hlt2_reco_rich_noUT_panoptes_dd4hep_both: # ] else: - options.conddb_tag = 'upgrade/sim-20220612-vc-md100-RICHcustomFTv6' + options.conddb_tag = "upgrade/sim-20220612-vc-md100-RICHcustomFTv6" options.simulation = True - param_list = ['p0_x', 'p1_x', 'p0_y', 'p1_y', 'p0_z', 'p1_z'] + param_list = ["p0_x", "p1_x", "p0_y", "p1_y", "p0_z", "p1_z"] param_dict = dict.fromkeys(param_list) # Only edit bad_align to play with alignment parameters @@ -496,7 +555,7 @@ class hlt2_reco_rich_noUT_panoptes_dd4hep_both: align_opts = {} # Reco opts - wider_bkg = {"PhotonSelection": 'None'} + wider_bkg = {"PhotonSelection": "None"} default_reco_opts.update(wider_bkg) panel_select = {"ActivatePanel": (True, True)} default_reco_opts.update(panel_select) @@ -517,7 +576,7 @@ class hlt2_reco_rich_noUT_panoptes_dd4hep_both: # Check if "_" is found before "k_" if underscore_index != -1: # Extract the substring between the last "_" and "k_" - num_str = current_variant[underscore_index + 1:k_index] + num_str = current_variant[underscore_index + 1 : k_index] try: if "O" in num_str: # this is O not 0 options.evt_max = EvtMax @@ -539,9 +598,7 @@ class hlt2_reco_rich_noUT_panoptes_dd4hep_both: f"INFO: evt_max is extracted as {options.evt_max} events from current_variant." ) except ValueError: - print( - "ERROR: Unable to convert extracted substring to integer." - ) + print("ERROR: Unable to convert extracted substring to integer.") else: print("ERROR: '_' not found before 'k_'.") else: @@ -559,8 +616,7 @@ class hlt2_reco_rich_noUT_panoptes_dd4hep_both: # Check if "_" is found after "minp" if underscore_index != -1: # Extract the substring between "minp" and "_" - num_str = current_variant[minp_index + - len("minp"):underscore_index] + num_str = current_variant[minp_index + len("minp") : underscore_index] try: # Convert the extracted substring to a float (double) minP = float(num_str) @@ -568,9 +624,7 @@ class hlt2_reco_rich_noUT_panoptes_dd4hep_both: f"INFO: Extracted track momentum cut as {minP} GeV from current_variant." ) except ValueError: - print( - "ERROR: Unable to convert extracted substring to float." - ) + print("ERROR: Unable to convert extracted substring to float.") else: print("ERROR: Underscore not found after minp.") else: @@ -590,20 +644,20 @@ class hlt2_reco_rich_noUT_panoptes_dd4hep_both: } } default_moni_opts.update(tighter_minp) - wider_histo = {'CKResHistoRange': (0.025, 0.005, 0.004)} + wider_histo = {"CKResHistoRange": (0.025, 0.005, 0.004)} default_moni_opts.update(wider_histo) - useUT = {'UseUT': useUT_bool} + useUT = {"UseUT": useUT_bool} default_moni_opts.update(useUT) PrForwardTrackingVelo.global_bind( MinQuality=0.0, DeltaQuality=0.0, MinTotalHits=9, - MaxChi2PerDoF=50., - MaxChi2XProjection=60., - MaxChi2PerDoFFinal=28., - MaxChi2Stereo=16., - MaxChi2StereoAdd=16., + MaxChi2PerDoF=50.0, + MaxChi2XProjection=60.0, + MaxChi2PerDoFFinal=28.0, + MaxChi2Stereo=16.0, + MaxChi2StereoAdd=16.0, ) # use superpixels or not @@ -613,15 +667,16 @@ class hlt2_reco_rich_noUT_panoptes_dd4hep_both: if not "veloSP" in hltSettings: print("Configuring for Velo cluster F/W") make_VeloClusterTrackingSIMD.global_bind( - algorithm=VeloRetinaClusterTrackingSIMD) + algorithm=VeloRetinaClusterTrackingSIMD + ) make_velo_full_clusters.global_bind( - make_full_cluster=VPRetinaFullClusterDecoder) + make_full_cluster=VPRetinaFullClusterDecoder + ) else: print("Configuring for Velo SuperPixel F/W") - make_reco_pvs.global_bind( - make_pvs_from_velo_tracks=make_PatPV3DFuture_pvs) - ''' + make_reco_pvs.global_bind(make_pvs_from_velo_tracks=make_PatPV3DFuture_pvs) + """ # Possible mirror align tasks are: mirror_align_tasks = [ 'Produce', # fill the production set of histograms @@ -632,7 +687,7 @@ class hlt2_reco_rich_noUT_panoptes_dd4hep_both: #'Calibrate', # check filling all RICH2 mirror combinations with elimination when filled # 'Explore', # explore influence of RICH1 coordinate systems on distribution shapes ] - ''' + """ # Define the regular expression pattern to match the desired substring pattern = r"_(O|\d+)k_([^_]+)" @@ -642,29 +697,27 @@ class hlt2_reco_rich_noUT_panoptes_dd4hep_both: if match: # Extract the number and subsequent substring from the match object - #number = match.group(1) + # number = match.group(1) substr = match.group(2) # Split the subsequent substring by "_" and store in a list mirror_align_tasks = substr.split("_") - #print("Number:", number) + # print("Number:", number) print( f"INFO: mirror_align_tasks = {mirror_align_tasks} extracted from current_variant." ) else: - print( - "ERROR: mirror_align_tasks pattern not found in current_variant." - ) + print("ERROR: mirror_align_tasks pattern not found in current_variant.") sys.stdout.flush() - ''' + """ if 'md' in options.conddb_tag: mp = 'md' elif 'mu' in options.conddb_tag: mp = 'mu' else: mp = 'Collision22' - + n_kevts = f"{math.trunc(options.evt_max / 1000)}k" addinfo = f'_minp{math.trunc(minP)}_subset_' + mp + "_" + n_kevts @@ -675,7 +728,7 @@ class hlt2_reco_rich_noUT_panoptes_dd4hep_both: tasks = '' for task in mirror_align_tasks: tasks += f"_{task}" - + # create timestamp # now = datetime.datetime.now() # dt = now.isoformat(timespec='minutes') # Anatoly's old timestamp @@ -684,98 +737,100 @@ class hlt2_reco_rich_noUT_panoptes_dd4hep_both: yaml = YAML() with open(f"./rich{whichRich}_session_timestamp.yml") as inp: ts = yaml.load(inp) - + # form the current variant name current_variant = f"{ts}_rich{whichRich}{addinfo}{tasks}" - ''' + """ - if 'subset' in current_variant: + if "subset" in current_variant: if whichRich == 1: central_mirr_combs = { "PrebookHistos": [ - ('p00', 's03'), - ('p01', 's06'), - ('p02', 's12'), - ('p03', 's09'), + ("p00", "s03"), + ("p01", "s06"), + ("p02", "s12"), + ("p03", "s09"), ], } else: central_mirr_combs = { "PrebookHistos": [ - ('p17', 's13'), - ('p47', 's35'), - ('p17', 's09'), - ('p47', 's31'), - ('p16', 's12'), - ('p46', 's34'), - ('p16', 's08'), - ('p46', 's30'), - ('p13', 's10'), - ('p43', 's31'), - ('p13', 's09'), - ('p43', 's30'), - ('p12', 's09'), - ('p42', 's30'), - ('p12', 's08'), - ('p42', 's29'), - ('p09', 's09'), - ('p39', 's31'), - ('p09', 's05'), - ('p39', 's27'), - ('p08', 's08'), - ('p38', 's30'), - ('p08', 's04'), - ('p38', 's26'), + ("p17", "s13"), + ("p47", "s35"), + ("p17", "s09"), + ("p47", "s31"), + ("p16", "s12"), + ("p46", "s34"), + ("p16", "s08"), + ("p46", "s30"), + ("p13", "s10"), + ("p43", "s31"), + ("p13", "s09"), + ("p43", "s30"), + ("p12", "s09"), + ("p42", "s30"), + ("p12", "s08"), + ("p42", "s29"), + ("p09", "s09"), + ("p39", "s31"), + ("p09", "s05"), + ("p39", "s27"), + ("p08", "s08"), + ("p38", "s30"), + ("p08", "s04"), + ("p38", "s26"), ], } align_opts.update(central_mirr_combs) align_opts.update({"MinP4Align": minP * GeV}) - #if 'theta2' in current_variant: + # if 'theta2' in current_variant: # align_opts.update({"DeltaThetaRange": 0.002}) - deltatheta = alignConf.getProp("deltaThetaWindow") / 1000. + deltatheta = alignConf.getProp("deltaThetaWindow") / 1000.0 # if 'thetaN' in current_variant: align_opts.update({"DeltaThetaRange": deltatheta}) - align_opts.update({"PoorestPopulation": 279.}) + align_opts.update({"PoorestPopulation": 279.0}) - if (tiltName == ""): + if tiltName == "": connectStr = "" else: connectStr = "_" # save output file with histograms if UseDD4Hep: - #options.histo_file = f'rich{whichRich}_opt_dd4hep.root' - options.histo_file = f"{workdir}{current_variant}_histos{connectStr}{tiltName}_i{n_it}.root" + # options.histo_file = f'rich{whichRich}_opt_dd4hep.root' + options.histo_file = ( + f"{workdir}{current_variant}_histos{connectStr}{tiltName}_i{n_it}.root" + ) else: - options.histo_file = f'rich{whichRich}_opt.root' + options.histo_file = f"rich{whichRich}_opt.root" # prepare part of the overridden options in use # to be recorded into a YAML file align_opts_dump = alignment_rich_monitoring_options( - radiator=radiator, init_override_opts=align_opts) + radiator=radiator, init_override_opts=align_opts + ) # add overridden default_rich_monitoring_options # to the part of the options in use to be recorded into the YAML file align_opts_dump.update( - default_rich_monitoring_options( - init_override_opts=default_moni_opts)) + default_rich_monitoring_options(init_override_opts=default_moni_opts) + ) # retrieve the timestamp - ts = re.findall(r'[\d]{4}-[\d]{2}-[\d]{2}T[\d]{2}-[\d]{2}', - current_variant)[0] + ts = re.findall(r"[\d]{4}-[\d]{2}-[\d]{2}T[\d]{2}-[\d]{2}", current_variant)[0] # prepare options in use to be recorded into the YAML file opts_dump = {} opts_dump[ts] = {} - opts_dump[ts]['reco_opts'] = align_opts_dump + opts_dump[ts]["reco_opts"] = align_opts_dump # append YAML file with the part of the options in use - with open(f"{workdir}{rich}_reco_opts.yml", 'a') as out: + with open(f"{workdir}{rich}_reco_opts.yml", "a") as out: yaml.dump(opts_dump, out) - ''' + """ # To get the JSON right (old) from AllenCore.configuration_options import is_allen_standalone is_allen_standalone.global_bind(standalone=True) @@ -783,8 +838,8 @@ class hlt2_reco_rich_noUT_panoptes_dd4hep_both: import hlt1_pp_no_gec_no_ut #import hlt1_pp_forward_then_matching_no_ut_no_gec #import passthrough - ''' - ''' + """ + """ # To get the JSON right from PyConf.Algorithms import LHCb__UnpackRawEvent, HltDecReportsDecoder, HltSelReportsDecoder #, ApplicationMgr #from PyConf.application import configured_ann_svc @@ -807,37 +862,45 @@ class hlt2_reco_rich_noUT_panoptes_dd4hep_both: #app = ApplicationMgr( # TopAlg=[unpacker, decDec, selDec], # ExtSvc=[configured_ann_svc(name='HltANNSvc')]) - ''' + """ # by default, no additional filtering of the events event_filter = [] # Prepare filter - lines = (['Hlt1RICH1AlignmentDecision'] - if whichRich == 1 else ['Hlt1RICH2AlignmentDecision']) + lines = ( + ["Hlt1RICH1AlignmentDecision"] + if whichRich == 1 + else ["Hlt1RICH2AlignmentDecision"] + ) from PyConf.application import ( default_raw_banks, default_raw_event, ) + options.input_raw_format = 0.5 - default_raw_event.global_bind( - raw_event_format=options.input_raw_format) + default_raw_event.global_bind(raw_event_format=options.input_raw_format) + import Functors from PyConf.Algorithms import ( - VoidFilter, HltDecReportsDecoder as PyConf_Algorithms_HltDecReportsDecoder, ) - import Functors + from PyConf.Algorithms import ( + VoidFilter, + ) + hlt1_dec_reports = PyConf_Algorithms_HltDecReportsDecoder( - SourceID='Hlt1', RawBanks=default_raw_banks("HltDecReports")) + SourceID="Hlt1", RawBanks=default_raw_banks("HltDecReports") + ) hlt1_filter = VoidFilter( - name='Streaming_filter', + name="Streaming_filter", OutputLevel=1, Cut=Functors.DECREPORTS_FILTER( - Lines=lines, - DecReports=hlt1_dec_reports.OutputHltDecReportsLocation)) + Lines=lines, DecReports=hlt1_dec_reports.OutputHltDecReportsLocation + ), + ) # when particular decision of HLT1 line about RICH1 or RICH2 is wanted if useHltDecisions: @@ -863,17 +926,23 @@ class hlt2_reco_rich_noUT_panoptes_dd4hep_both: print(f"options.histo_file {options.histo_file}") sys.stdout.flush() - with standalone_rich_online_align_reco.bind(RichGas=radiator, MirrorAlignTasks = mirror_align_tasks,\ - EventFilter=event_filter, \ - noUT=noUT_bool), \ - alignment_rich_monitoring_options.bind(radiator=radiator, \ - init_override_opts=align_opts), \ - default_ft_decoding_version.bind(value=6), \ - default_rich_reco_options.bind(init_override_opts=default_reco_opts), \ - default_rich_monitoring_options.bind(init_override_opts=default_moni_opts): + with ( + standalone_rich_online_align_reco.bind( + RichGas=radiator, + MirrorAlignTasks=mirror_align_tasks, + EventFilter=event_filter, + noUT=noUT_bool, + ), + alignment_rich_monitoring_options.bind( + radiator=radiator, init_override_opts=align_opts + ), + default_ft_decoding_version.bind(value=6), + default_rich_reco_options.bind(init_override_opts=default_reco_opts), + default_rich_monitoring_options.bind(init_override_opts=default_moni_opts), + ): run_reconstruction(options, standalone_rich_online_align_reco) -if __name__ == 'builtins': +if __name__ == "builtins": RichAnalyzer_instance = hlt2_reco_rich_noUT_panoptes_dd4hep_both() RichAnalyzer_instance.run() diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/RichAnalyzerControl.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/RichAnalyzerControl.py index 752a49795724bafe3d814f78f01f580d60121c98..93baf0e9024af73f592ab091833a1a8e8751c4da 100644 --- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/RichAnalyzerControl.py +++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/RichAnalyzerControl.py @@ -8,17 +8,20 @@ # granted to it by virtue of its status as an Intergovernmental Organization # # or submit itself to any jurisdiction. # ############################################################################### -import math import datetime -from ruamel.yaml import YAML -import sys -import os, re +import getpass +import math +import os +import re import shutil -import time import subprocess +import sys +import time from time import gmtime, strftime + +from ruamel.yaml import YAML + from PyMirrAlignOnline.Communicator import * -import getpass print(f"INFO: RichAnalyzerControl __name__ = {__name__}") @@ -29,30 +32,30 @@ class RichAnalyzerControl: pass def go(self, whichRich=1): - self.whichRich = whichRich if self.whichRich == 1: from Configurables import Rich1MirrAlignOnConf - #from Configuration import Rich1MirrAlignOnConf + + # from Configuration import Rich1MirrAlignOnConf alignConf = Rich1MirrAlignOnConf() elif self.whichRich == 2: from Configurables import Rich2MirrAlignOnConf - #from Configuration import Rich2MirrAlignOnConf + + # from Configuration import Rich2MirrAlignOnConf alignConf = Rich2MirrAlignOnConf() alignConf.__apply_configuration__() - self.workdir = alignConf.getProp('WorkDir') + self.workdir = alignConf.getProp("WorkDir") # Online_bit state = State.NOT_READY - com = Communicator('ALIGNWRKR') + com = Communicator("ALIGNWRKR") print("INFO: Communicator started.") com.set_status(state) print(f"INFO: Analyzer state = {state}") yaml = YAML() - with open(f"{self.workdir}rich{self.whichRich}_runAnalyzer.yml", - 'w') as fout: + with open(f"{self.workdir}rich{self.whichRich}_runAnalyzer.yml", "w") as fout: yaml.dump("NO", fout) print( f"INFO: {self.workdir}rich{self.whichRich}_runAnalyzer.yml set to 'NO'" @@ -63,20 +66,20 @@ class RichAnalyzerControl: sys.stdout.flush() command = com.get_command() if "state" in command: # ignore strange "!state" command from Run Control - #print('"state" is in command') - #sys.stdout.flush() + # print('"state" is in command') + # sys.stdout.flush() command = com.get_command() - #print(command) - #sys.stdout.flush() + # print(command) + # sys.stdout.flush() print(f"INFO: Analyzer Receiving command: {command}") print("INFO: ----------------------------") - if command.startswith('configure') and state == State.NOT_READY: + if command.startswith("configure") and state == State.NOT_READY: print( f"INFO: CONFIGURE command received at {strftime('%Y-%m-%d %H:%M:%S', gmtime())} UTC" ) sys.stdout.flush() state = State.READY - elif (command.startswith('start') and state == State.READY): + elif command.startswith("start") and state == State.READY: print( f"INFO: START command received at {strftime('%Y-%m-%d %H:%M:%S', gmtime())} UTC" ) @@ -86,18 +89,18 @@ class RichAnalyzerControl: # elif (state == State.RUNNING): com.set_status(state) print(f"INFO: Analyzer state = {state}") - #print(f"INFO: PAUSE command received at {strftime('%Y-%m-%d %H:%M:%S', gmtime())} UTC") - #sys.stdout.flush() - #self.run() + # print(f"INFO: PAUSE command received at {strftime('%Y-%m-%d %H:%M:%S', gmtime())} UTC") + # sys.stdout.flush() + # self.run() runAnalyzer = "UNKNOWN" while runAnalyzer != "YES": yaml = YAML() while not os.path.exists( - f"{self.workdir}rich{self.whichRich}_runAnalyzer.yml" + f"{self.workdir}rich{self.whichRich}_runAnalyzer.yml" ): time.sleep(4) with open( - f"{self.workdir}rich{self.whichRich}_runAnalyzer.yml" + f"{self.workdir}rich{self.whichRich}_runAnalyzer.yml" ) as finp: runAnalyzer = yaml.load(finp) print( @@ -107,19 +110,20 @@ class RichAnalyzerControl: time.sleep(4) sys.stdout.flush() yaml = YAML() - with open(f"{self.workdir}rich{self.whichRich}_iter_number.yml" - ) as finp: + with open( + f"{self.workdir}rich{self.whichRich}_iter_number.yml" + ) as finp: n_it = yaml.load(finp) yaml = YAML() - with open(f"{self.workdir}rich{self.whichRich}_tilt_name.yml" - ) as finp: + with open(f"{self.workdir}rich{self.whichRich}_tilt_name.yml") as finp: tiltName = yaml.load(finp) - if (tiltName == ""): + if tiltName == "": connectStr = "" else: connectStr = "_" analyzerOutDir = os.path.join( - f"{self.workdir}Rich{self.whichRich}AnalyzerOutput", '') + f"{self.workdir}Rich{self.whichRich}AnalyzerOutput", "" + ) if "online" in getpass.getuser(): utgid = os.environ["UTGID"] try: @@ -133,10 +137,10 @@ class RichAnalyzerControl: richAnalyzerOutFile = f"{analyzerOutDir}Rich{self.whichRich}AnalyzerOut{connectStr}{tiltName}_i{n_it}.txt" analyzerStdOutFile = f"{analyzerOutDir}Rich{self.whichRich}AnalyzerStdOut{connectStr}{tiltName}_i{n_it}.txt" analyzerStdErrFile = f"{analyzerOutDir}Rich{self.whichRich}AnalyzerStdErr{connectStr}{tiltName}_i{n_it}.txt" - myStdOut = open(analyzerStdOutFile, 'w') - myStdErr = open(analyzerStdErrFile, 'w') + myStdOut = open(analyzerStdOutFile, "w") + myStdErr = open(analyzerStdErrFile, "w") - self.dataVariant = alignConf.getProp('dataVariant') + self.dataVariant = alignConf.getProp("dataVariant") if self.dataVariant == "Collision24": if self.whichRich == 1: which_data_online = "data_online_Rich1.py" @@ -154,7 +158,8 @@ class RichAnalyzerControl: shell=True, executable="/bin/bash", stdout=myStdOut, - stderr=myStdErr) + stderr=myStdErr, + ) p3.communicate() myStdOut.close() myStdErr.close() @@ -162,20 +167,20 @@ class RichAnalyzerControl: print("INFO: RichAnalyzer complete. ") sys.stdout.flush() state = State.PAUSED - elif command.startswith('stop') and state in (State.PAUSED): + elif command.startswith("stop") and state in (State.PAUSED): print( f"INFO: STOP command received at {strftime('%Y-%m-%d %H:%M:%S', gmtime())} UTC" ) sys.stdout.flush() state = State.READY - elif command.startswith('reset'): + elif command.startswith("reset"): print( f"INFO: RESET command received at {strftime('%Y-%m-%d %H:%M:%S', gmtime())} UTC" ) sys.stdout.flush() state = State.NOT_READY - #break - elif command.startswith('unload'): + # break + elif command.startswith("unload"): print( f"INFO: UNLOAD command received at {strftime('%Y-%m-%d %H:%M:%S', gmtime())} UTC" ) @@ -183,9 +188,7 @@ class RichAnalyzerControl: state = State.OFFLINE break else: - print( - f"ERROR: Analyzer: bad transition from {state} to {command}" - ) + print(f"ERROR: Analyzer: bad transition from {state} to {command}") sys.stdout.flush() state = State.ERROR break @@ -197,6 +200,6 @@ class RichAnalyzerControl: print(f"INFO: Analyzer state = {state}") -if __name__ == '__main__': +if __name__ == "__main__": RichAnalyzerControl_instance = RichAnalyzerControl() RichAnalyzerControl_instance.go(whichRich=1) diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/RichAnalyzer_Run3.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/RichAnalyzer_Run3.py index b269e94ac2418453ab968a519870aa5e191675c0..95ad800356147f78ba7cba5f039575f0e72794de 100644 --- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/RichAnalyzer_Run3.py +++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/RichAnalyzer_Run3.py @@ -14,13 +14,14 @@ # https://gitlab.cern.ch/lhcb/Online/-/blob/master/Online/FarmConfig/job/AlignVPHalvesModules.sh # https://gitlab.cern.ch/lhcb/Panoptes/-/blob/alex_branch/Rich/Panoptes/python/Panoptes/alignment.py -import glob import csv -import math import datetime -from ruamel.yaml import YAML -import sys +import glob +import math import re +import sys + +from ruamel.yaml import YAML ################# currently taking in n_it and tiltName from stdin --- this will need to change ################# @@ -41,56 +42,63 @@ count = len(arguments) # Since we are doing this by hand, specify the iteration number in stdin n_it = 0 -if count == 2 and arguments[1] in [ - '0', '1', '2', '3', '4', '5', '6', '7', '8' -]: +if count == 2 and arguments[1] in ["0", "1", "2", "3", "4", "5", "6", "7", "8"]: n_it = int(arguments[1]) -if count == 1 and arguments[0] in [ - '0', '1', '2', '3', '4', '5', '6', '7', '8' -]: +if count == 1 and arguments[0] in ["0", "1", "2", "3", "4", "5", "6", "7", "8"]: n_it = int(arguments[0]) print("Iteration: " + str(n_it)) # possible tiltname can be given via stdin tiltName = "" if count == 2 and arguments[0] in [ - "priYn", "priYp", "priZn", "priZp", "secYn", "secYp", "secZn", "secZp" + "priYn", + "priYp", + "priZn", + "priZp", + "secYn", + "secYp", + "secZn", + "secZp", ]: tiltName = arguments[0] print("Tilt Name: " + tiltName) ################# ############################################################################# ################# -from GaudiKernel.SystemOfUnits import (GeV, MeV, mm, mrad) +from GaudiKernel.SystemOfUnits import GeV, MeV, mm, mrad from Moore import ( options, run_reconstruction, ) - +from Panoptes.alignment import ( + standalone_rich_online_align_reco, +) +from PyConf.Algorithms import ( + PrForwardTrackingVelo, + VeloRetinaClusterTrackingSIMD, + VPRetinaFullClusterDecoder, +) +from RecoConf.legacy_rec_hlt1_tracking import ( + make_PatPV3DFuture_pvs, + make_reco_pvs, + make_velo_full_clusters, + make_VeloClusterTrackingSIMD, +) from RecoConf.rich_data_monitoring import ( - default_rich_monitoring_options, alignment_rich_monitoring_options, + default_rich_monitoring_options, ) - -from PyConf.Algorithms import (PrForwardTrackingVelo, - VPRetinaFullClusterDecoder) -from PyConf.Algorithms import VeloRetinaClusterTrackingSIMD -from RecoConf.legacy_rec_hlt1_tracking import ( - make_VeloClusterTrackingSIMD, make_reco_pvs, make_PatPV3DFuture_pvs, - make_velo_full_clusters) - from RecoConf.rich_reconstruction import default_rich_reco_options -from Panoptes.alignment import ( - standalone_rich_online_align_reco, ) """Options for running over data with FT raw bank version 6.""" from RecoConf.decoders import ( - default_ft_decoding_version, ) + default_ft_decoding_version, +) useRealData = True options.n_threads = 10 # Maybe something else will override this anyway? -#options.evt_max = 25000000 +# options.evt_max = 25000000 if useRealData is True: options.simulation = False options.input_type = "MDF" @@ -110,52 +118,56 @@ whichRich = 1 # PN - really we want this defined when we call the Analyzer, e.g # does this bit still work? if whichRich == 1: from Configurables import Rich1MirrAlignOnConf + alignConf = Rich1MirrAlignOnConf() elif whichRich == 2: from Configurables import Rich2MirrAlignOnConf + alignConf = Rich2MirrAlignOnConf() alignConf.__apply_configuration__() -#whichRich = alignConf.getProp('Rich') - not sure why we would ever do this +# whichRich = alignConf.getProp('Rich') - not sure why we would ever do this print("INFO: (RichAnalyzer.py) whichRich = ", whichRich) -workdir = alignConf.getProp('WorkDir') +workdir = alignConf.getProp("WorkDir") print("INFO: (RichAnalyzer.py) workdir = ", workdir) -whichData = alignConf.getProp( - 'dataVariant') # not sure if we will use this or not... +whichData = alignConf.getProp("dataVariant") # not sure if we will use this or not... print("INFO: (RichAnalyzer.py) whichData = ", whichData) -rich = 'rich' + str(whichRich) +rich = "rich" + str(whichRich) radiator = "Rich" + str(whichRich) + "Gas" if UseDD4Hep: from Configurables import DDDBConf dd4hep = DD4hepSvc( - DetectorList=["/world", "Magnet", "UT", "VP", "FT", "Rich1", "Rich2"]) - dd4hep.ConditionsLocation = 'git:/cvmfs/lhcb.cern.ch/lib/lhcb/git-conddb/lhcb-conditions-database.git' + DetectorList=["/world", "Magnet", "UT", "VP", "FT", "Rich1", "Rich2"] + ) + dd4hep.ConditionsLocation = ( + "git:/cvmfs/lhcb.cern.ch/lib/lhcb/git-conddb/lhcb-conditions-database.git" + ) dd4hep.OutputLevel = 1 if useRealData: - options.conddb_tag = 'master' # used for real data - options.dddb_tag = 'run3/trunk' - DDDBConf().GeometryVersion = 'run3/trunk' # used for real data + options.conddb_tag = "master" # used for real data + options.dddb_tag = "run3/trunk" + DDDBConf().GeometryVersion = "run3/trunk" # used for real data ## PN - eventually will want to do this all the Online way, for now comment out - #dd4hep.UseConditionsOverlay = True - #if (tiltName == "" and n_it == 0): + # dd4hep.UseConditionsOverlay = True + # if (tiltName == "" and n_it == 0): # dd4hep.ConditionsVersion = 'alignment2022' - #elif (n_it >= 1): + # elif (n_it >= 1): # dd4hep.ConditionsVersion = '2022_12_06_Rich'+str(whichRich)+'_i' + str(n_it) + "_new" - #else: + # else: # dd4hep.ConditionsVersion = '2022_12_06_Rich'+str(whichRich)+'_' + tiltName ##### Online Stuff (to be sorted) ##### -from PyConf.application import configure_input -#from Humboldt.utils import runAlignment +# from Humboldt.utils import runAlignment import OnlineEnvBase as OnlineEnv +from PyConf.application import configure_input -#TODO: get these from Online +# TODO: get these from Online runNumber = 9999 workerNumber = 0 runType = "RICH" + str(whichRich) @@ -163,9 +175,11 @@ if OnlineEnv.PartitionName == "TEST": histofile = "testRICHmonitoringhist.root" # for now we just use this / later match Anatoly's scheme else: from pathlib import Path - onlineprefix = '/group/online/dataflow/cmtuser/alignonlinetest' + + onlineprefix = "/group/online/dataflow/cmtuser/alignonlinetest" Path(f"{onlineprefix}/{runType}/{runNumber}/analyzerOutput_RICH/").mkdir( - parents=True, exist_ok=True) + parents=True, exist_ok=True + ) histofile = f"{onlineprefix}/{runType}/{runNumber}/analyzerOutput_RICH/{workerNumber}_testRICHmonitoringhist.root" ##### ########################### ##### @@ -179,7 +193,7 @@ default_reco_opts = {} align_opts = {} # Reco opts -wider_bkg = {"PhotonSelection": 'None'} +wider_bkg = {"PhotonSelection": "None"} default_reco_opts.update(wider_bkg) panel_select = {"ActivatePanel": (True, True)} default_reco_opts.update(panel_select) @@ -188,7 +202,7 @@ default_reco_opts.update(panel_select) if whichRich == 1: tighter_minp = { "TightTrackSelection": { - "MinP": 30. * GeV, + "MinP": 30.0 * GeV, "MinPt": 0.5 * GeV, "MaxChi2": 2.0, "MaxGhostProb": 0.1, @@ -197,38 +211,36 @@ if whichRich == 1: else: tighter_minp = { "TightTrackSelection": { - "MinP": 60. * GeV, + "MinP": 60.0 * GeV, "MinPt": 0.5 * GeV, "MaxChi2": 2.0, "MaxGhostProb": 0.1, } } default_moni_opts.update(tighter_minp) -wider_histo = {'CKResHistoRange': (0.025, 0.005, 0.004)} +wider_histo = {"CKResHistoRange": (0.025, 0.005, 0.004)} default_moni_opts.update(wider_histo) -useUT = {'UseUT': False} +useUT = {"UseUT": False} default_moni_opts.update(useUT) PrForwardTrackingVelo.global_bind( MinQuality=0.0, DeltaQuality=0.0, - DecisionLDA=-99., + DecisionLDA=-99.0, MinTotalHits=9, - MaxChi2PerDoF=50., - MaxChi2XProjection=60., - MaxChi2PerDoFFinal=28., - MaxChi2Stereo=16., - MaxChi2StereoAdd=16., + MaxChi2PerDoF=50.0, + MaxChi2XProjection=60.0, + MaxChi2PerDoFFinal=28.0, + MaxChi2Stereo=16.0, + MaxChi2StereoAdd=16.0, ) -make_VeloClusterTrackingSIMD.global_bind( - algorithm=VeloRetinaClusterTrackingSIMD) -make_velo_full_clusters.global_bind( - make_full_cluster=VPRetinaFullClusterDecoder) +make_VeloClusterTrackingSIMD.global_bind(algorithm=VeloRetinaClusterTrackingSIMD) +make_velo_full_clusters.global_bind(make_full_cluster=VPRetinaFullClusterDecoder) make_reco_pvs.global_bind(make_pvs_from_velo_tracks=make_PatPV3DFuture_pvs) mirror_align_tasks = [ - 'Produce', # fill the production set of histograms + "Produce", # fill the production set of histograms #'Monitor', # add various checking histograms #'Map', # add counters for creation of the HLT1 pre-selection line "map" #'Optimize', # add counters for optimization of the RICH2 mirror combinations subset @@ -237,132 +249,138 @@ mirror_align_tasks = [ # 'Explore', # explore influence of RICH1 coordinate systems on distribution shapes ] -if 'md' in options.conddb_tag: - mp = 'md' -elif 'mu' in options.conddb_tag: - mp = 'mu' +if "md" in options.conddb_tag: + mp = "md" +elif "mu" in options.conddb_tag: + mp = "mu" else: - mp = 'Collision22' # PN - should fix this later + mp = "Collision22" # PN - should fix this later # PN - I don't think we will know the number of events a priori -#n_kevts = str(math.trunc(options.evt_max / 1000)) + 'k' +# n_kevts = str(math.trunc(options.evt_max / 1000)) + 'k' if whichRich == 1: - addinfo = '_minp30_subset_' + mp #+ "_" + n_kevts - #addinfo = '_minp40_subset_' + mp #+ "_" + n_kevts + addinfo = "_minp30_subset_" + mp # + "_" + n_kevts + # addinfo = '_minp40_subset_' + mp #+ "_" + n_kevts else: - addinfo = '_minp60_subset_' + mp #+ "_" + n_kevts + addinfo = "_minp60_subset_" + mp # + "_" + n_kevts # cumulative substring with all tasks chosen -tasks = '' +tasks = "" for task in mirror_align_tasks: - tasks += '_' + task + tasks += "_" + task yaml = YAML() -with open( - workdir + '/' + rich + '_session_timestamp.yml' -) as inp: # file made in SetupHelper; need to provide to Analyzer via conf the directory of this file +with ( + open(workdir + "/" + rich + "_session_timestamp.yml") as inp +): # file made in SetupHelper; need to provide to Analyzer via conf the directory of this file ts = yaml.load(inp) # form the current variant name -current_variant = ts + '_' + 'rich' + str(whichRich) + addinfo + tasks +current_variant = ts + "_" + "rich" + str(whichRich) + addinfo + tasks -if 'subset' in current_variant: +if "subset" in current_variant: if whichRich == 1: central_mirr_combs = { "PrebookHistos": [ - ('p00', 's03'), - ('p01', 's06'), - ('p02', 's12'), - ('p03', 's09'), + ("p00", "s03"), + ("p01", "s06"), + ("p02", "s12"), + ("p03", "s09"), ], } align_opts.update(central_mirr_combs) else: central_mirr_combs = { "PrebookHistos": [ - ('p17', 's13'), - ('p47', 's35'), - ('p17', 's09'), - ('p47', 's31'), - ('p16', 's12'), - ('p46', 's34'), - ('p16', 's08'), - ('p46', 's30'), - ('p13', 's10'), - ('p43', 's31'), - ('p13', 's09'), - ('p43', 's30'), - ('p12', 's09'), - ('p42', 's30'), - ('p12', 's08'), - ('p42', 's29'), - ('p09', 's09'), - ('p39', 's31'), - ('p09', 's05'), - ('p39', 's27'), - ('p08', 's08'), - ('p38', 's30'), - ('p08', 's04'), - ('p38', 's26'), + ("p17", "s13"), + ("p47", "s35"), + ("p17", "s09"), + ("p47", "s31"), + ("p16", "s12"), + ("p46", "s34"), + ("p16", "s08"), + ("p46", "s30"), + ("p13", "s10"), + ("p43", "s31"), + ("p13", "s09"), + ("p43", "s30"), + ("p12", "s09"), + ("p42", "s30"), + ("p12", "s08"), + ("p42", "s29"), + ("p09", "s09"), + ("p39", "s31"), + ("p09", "s05"), + ("p39", "s27"), + ("p08", "s08"), + ("p38", "s30"), + ("p08", "s04"), + ("p38", "s26"), ], } align_opts.update(central_mirr_combs) -if 'minp40' in current_variant: - align_opts.update({"MinP4Align": 40. * GeV}) -elif 'minp30' in current_variant: - align_opts.update({"MinP4Align": 30. * GeV}) -elif 'minp60' in current_variant: - align_opts.update({"MinP4Align": 60. * GeV}) +if "minp40" in current_variant: + align_opts.update({"MinP4Align": 40.0 * GeV}) +elif "minp30" in current_variant: + align_opts.update({"MinP4Align": 30.0 * GeV}) +elif "minp60" in current_variant: + align_opts.update({"MinP4Align": 60.0 * GeV}) -if 'theta2' in current_variant: +if "theta2" in current_variant: align_opts.update({"DeltaThetaRange": 0.002}) # PN - no idea what this is for -align_opts.update({"PoorestPopulation": 279.}) +align_opts.update({"PoorestPopulation": 279.0}) -if (tiltName == ""): +if tiltName == "": connectStr = "" else: connectStr = "_" # save output file with histograms -#if UseDD4Hep: +# if UseDD4Hep: # options.histo_file = "./" + current_variant + "_histos" + connectStr + tiltName + "_i" + str(n_it) + ".root" # prepare part of the overridden options in use # to be recorded into a YAML file align_opts_dump = alignment_rich_monitoring_options( - radiator=radiator, init_override_opts=align_opts) + radiator=radiator, init_override_opts=align_opts +) # add overridden default_rich_monitoring_options # to the part of the options in use to be recorded into the YAML file align_opts_dump.update( - default_rich_monitoring_options(init_override_opts=default_moni_opts)) + default_rich_monitoring_options(init_override_opts=default_moni_opts) +) # retrieve the timestamp -ts = re.findall(r'[\d]{4}-[\d]{2}-[\d]{2}T[\d]{2}-[\d]{2}', current_variant)[0] +ts = re.findall(r"[\d]{4}-[\d]{2}-[\d]{2}T[\d]{2}-[\d]{2}", current_variant)[0] # prepare options in use to be recorded into the YAML file opts_dump = {} opts_dump[ts] = {} -opts_dump[ts]['reco_opts'] = align_opts_dump +opts_dump[ts]["reco_opts"] = align_opts_dump # append YAML file with the part of the options in use -with open(workdir + '/' + rich + '_reco_opts.yml', 'a') as out: +with open(workdir + "/" + rich + "_reco_opts.yml", "a") as out: yaml.dump(opts_dump, out) ## PN - incorporate this later? ## iteration number substring -#with open(workdir + '/' + rich +'_iter_number.yml') as inp: +# with open(workdir + '/' + rich +'_iter_number.yml') as inp: # iN = '_i'+str(yaml.load(inp)) -with standalone_rich_online_align_reco.bind(RichGas=radiator, MirrorAlignTasks = mirror_align_tasks,\ - noUT=True), \ - alignment_rich_monitoring_options.bind(radiator=radiator, \ - init_override_opts=align_opts), \ - default_ft_decoding_version.bind(value=6), \ - default_rich_reco_options.bind(init_override_opts=default_reco_opts), \ - default_rich_monitoring_options.bind(init_override_opts=default_moni_opts): +with ( + standalone_rich_online_align_reco.bind( + RichGas=radiator, MirrorAlignTasks=mirror_align_tasks, noUT=True + ), + alignment_rich_monitoring_options.bind( + radiator=radiator, init_override_opts=align_opts + ), + default_ft_decoding_version.bind(value=6), + default_rich_reco_options.bind(init_override_opts=default_reco_opts), + default_rich_monitoring_options.bind(init_override_opts=default_moni_opts), +): run_reconstruction(options, standalone_rich_online_align_reco) diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py index e7df424d665c2c4ff75dce0a83ef084de1c759fe..c76ffecb8d0a0ddd8490f13c5aa25bdc29c7b093 100644 --- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py +++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py @@ -11,90 +11,102 @@ __authors__ = "Claire Prouve, Paras Naik" __copyright__ = "University of Bristol, November 2022" +import datetime +import getpass +import glob +import math import os -import shutil import re -import math -import datetime -import time -from time import time -from time import gmtime, strftime -import subprocess, shlex -import sys -from ROOT import TH1, TFile, TTree -from ruamel.yaml import YAML +import shlex +import shutil import smtplib +import subprocess +import sys +import time from enum import Enum -import getpass +from time import gmtime, strftime, time + from MooreOnlineConf.utils import ( - alignment_options, ) -import glob + alignment_options, +) +from ROOT import TH1, TFile, TTree +from ruamel.yaml import YAML class SetupHelper: def __init__(self, _alignConf, flat=False): self.alignConf = _alignConf - #self.combAndMirrSubsets = self.alignConf.getProp('combAndMirrSubsets') - self.nameStr = self.alignConf.getProp('nameStr') - self.tiltNames = self.alignConf.getProp('tiltNames') + # self.combAndMirrSubsets = self.alignConf.getProp('combAndMirrSubsets') + self.nameStr = self.alignConf.getProp("nameStr") + self.tiltNames = self.alignConf.getProp("tiltNames") self.tiltNamesLength = len(self.tiltNames) - self.workdir = self.alignConf.getProp('WorkDir') - self.whichRich = self.alignConf.getProp('Rich') - self.YAMLio = self.alignConf.getProp('YAMLio') - self.useDD4hep = self.alignConf.getProp('useDD4hep') - self.autoUpdate = self.alignConf.getProp('autoUpdate') - self.autoUpdateNoV = self.alignConf.getProp('autoUpdateNoV') - self.magnFactorsMode = self.alignConf.getProp('magnFactorsMode') - self.minAverageBinPop = self.alignConf.getProp('minAverageBinPop') - self.phiBinFactor = self.alignConf.getProp('phiBinFactor') - self.minFracPhiBinsPopulated = self.alignConf.getProp( - 'minFracPhiBinsPopulated') - self.deltaThetaWindow = self.alignConf.getProp('deltaThetaWindow') - self.combinFitMethod = self.alignConf.getProp('combinFitMethod') - self.solutionMethod = self.alignConf.getProp('solutionMethod') - self.coeffCalibTilt = self.alignConf.getProp('coeffCalibTilt') + self.workdir = self.alignConf.getProp("WorkDir") + self.whichRich = self.alignConf.getProp("Rich") + self.YAMLio = self.alignConf.getProp("YAMLio") + self.useDD4hep = self.alignConf.getProp("useDD4hep") + self.autoUpdate = self.alignConf.getProp("autoUpdate") + self.autoUpdateNoV = self.alignConf.getProp("autoUpdateNoV") + self.magnFactorsMode = self.alignConf.getProp("magnFactorsMode") + self.minAverageBinPop = self.alignConf.getProp("minAverageBinPop") + self.phiBinFactor = self.alignConf.getProp("phiBinFactor") + self.minFracPhiBinsPopulated = self.alignConf.getProp("minFracPhiBinsPopulated") + self.deltaThetaWindow = self.alignConf.getProp("deltaThetaWindow") + self.combinFitMethod = self.alignConf.getProp("combinFitMethod") + self.solutionMethod = self.alignConf.getProp("solutionMethod") + self.coeffCalibTilt = self.alignConf.getProp("coeffCalibTilt") self.magnifDir = os.path.join( - self.alignConf.getProp('stackDir'), - self.alignConf.getProp('magnifDir')) + self.alignConf.getProp("stackDir"), self.alignConf.getProp("magnifDir") + ) self.XML_YAML_configDir = os.path.join( - self.alignConf.getProp('stackDir'), - self.alignConf.getProp('XML_YAML_configDir')) - self.testing = self.alignConf.getProp('testing') - self.fixSinusoidShift = self.alignConf.getProp('fixSinusoidShift') + self.alignConf.getProp("stackDir"), + self.alignConf.getProp("XML_YAML_configDir"), + ) + self.testing = self.alignConf.getProp("testing") + self.fixSinusoidShift = self.alignConf.getProp("fixSinusoidShift") # People who will get the emails during testing self.experts = [ - 'alex.marshall@cern.ch', 'jake.reich@cern.ch', - 'zahra.moghaddam@bristol.ac.uk', 'Anatoly.Solomin@bristol.ac.uk', - 'Paras.Naik@cern.ch' - ] #self.experts = ['Paras.Naik@cern.ch','samuel.maddrell-mander@cern.ch','matthew.george.chapman@cern.ch','claire.prouve@cern.ch'] + "alex.marshall@cern.ch", + "jake.reich@cern.ch", + "zahra.moghaddam@bristol.ac.uk", + "Anatoly.Solomin@bristol.ac.uk", + "Paras.Naik@cern.ch", + ] # self.experts = ['Paras.Naik@cern.ch','samuel.maddrell-mander@cern.ch','matthew.george.chapman@cern.ch','claire.prouve@cern.ch'] # People who will get the emails during automated/production running (in principle this is experts + anyone else and/or mailing list who wishes to be notified) self.emails = [ - 'alex.marshall@cern.ch', 'jake.reich@cern.ch', - 'zahra.moghaddam@bristol.ac.uk', 'Anatoly.Solomin@bristol.ac.uk', - 'Paras.Naik@cern.ch' - ] #self.emails = ['lhcb-rich-mirror-alignment-development@cern.ch','jonesc@hep.phy.cam.ac.uk','antonis.papanestis@stfc.ac.uk','m.mccann@imperial.ac.uk','silvia.gambetta@cern.ch'] + "alex.marshall@cern.ch", + "jake.reich@cern.ch", + "zahra.moghaddam@bristol.ac.uk", + "Anatoly.Solomin@bristol.ac.uk", + "Paras.Naik@cern.ch", + ] # self.emails = ['lhcb-rich-mirror-alignment-development@cern.ch','jonesc@hep.phy.cam.ac.uk','antonis.papanestis@stfc.ac.uk','m.mccann@imperial.ac.uk','silvia.gambetta@cern.ch'] # # Uncomment and adjust these lines should you be testing and don't want to spam people (though usually the experts don't mind) - #self.experts = ['whoever.you.are@cern.ch'] - #self.emails = ['whoever.you.are@cern.ch'] + # self.experts = ['whoever.you.are@cern.ch'] + # self.emails = ['whoever.you.are@cern.ch'] - self.developers = ['lhcb-rich-mirror-alignment-development@cern.ch'] + self.developers = ["lhcb-rich-mirror-alignment-development@cern.ch"] self.directoryTime = strftime("%Y%m%d_%H%M%S", gmtime()) print(f"INFO: self.directoryTime: {self.directoryTime}") self.now = datetime.datetime.now(datetime.timezone.utc) - self.dt = self.now.isoformat(timespec='minutes').replace( - "+00:00", "") # Anatoly's old timestamp + self.dt = self.now.isoformat(timespec="minutes").replace( + "+00:00", "" + ) # Anatoly's old timestamp self.dt = self.dt.replace(":", "-") # Anatoly's new timestamp print(f"INFO: self.dt: {self.dt}") self.savedir = os.path.join( - self.alignConf.getProp('SaveDir') + 'Rich' + str(self.whichRich) + - '/' + self.directoryTime, '') - self.dataVariant = self.alignConf.getProp('dataVariant') - self.trendDateRange = self.alignConf.getProp('trendDateRange') + self.alignConf.getProp("SaveDir") + + "Rich" + + str(self.whichRich) + + "/" + + self.directoryTime, + "", + ) + self.dataVariant = self.alignConf.getProp("dataVariant") + self.trendDateRange = self.alignConf.getProp("trendDateRange") self.finalCKres = None self.finalCKresErr = None self.flat = flat - self.usingReducedSubset = self.alignConf.getProp('useReducedSubset') + self.usingReducedSubset = self.alignConf.getProp("useReducedSubset") def setupMagnifFiles(self): print(f"INFO: Copying all files in {self.magnifDir} to {self.workdir}") @@ -106,7 +118,7 @@ class SetupHelper: def startMinIt(self, m_it): """Remove folders and files from a given directory based on certain criteria. - + Args: m_it (int): The iteration number. """ @@ -117,7 +129,8 @@ class SetupHelper: f"Rich{self.whichRich}MirrCombinFit_{self.nameStr}[\w\.]*_i{removeIt}" ) re_alignFiles = re.compile( - f"Rich{self.whichRich}MirrAlign[a-zA-z]*_i{removeIt}\.txt") + f"Rich{self.whichRich}MirrAlign[a-zA-z]*_i{removeIt}\.txt" + ) fitFolders = [x for x in files if re_fitFolders.match(x)] alignFiles = [x for x in files if re_alignFiles.match(x)] @@ -128,10 +141,13 @@ class SetupHelper: yaml = YAML() with open( - os.path.join(self.workdir, - f'rich{self.whichRich}_variant.yml')) as finp: + os.path.join(self.workdir, f"rich{self.whichRich}_variant.yml") + ) as finp: variant = yaml.load(finp) - rootFile = variant + f"_histos_{self.tiltNames[m_it % self.tiltNamesLength]}_i{removeIt}.root" + rootFile = ( + variant + + f"_histos_{self.tiltNames[m_it % self.tiltNamesLength]}_i{removeIt}.root" + ) # Remove fit folders, align files, and root file. files_to_remove = fitFolders + alignFiles + [rootFile] @@ -147,21 +163,24 @@ class SetupHelper: def monitor(self, n_it, compareFILE, forcedUpdate_ChMagPol): from PyMirrAlignOnline.AlignMonitor import AlignMonitor + alignMonitor = AlignMonitor(self.alignConf, n_it, self.flat) alignMonitor.performMonitoring(compareFILE, forcedUpdate_ChMagPol) self.finalCKres = alignMonitor.finalCKres self.finalCKresErr = alignMonitor.finalCKresErr return alignMonitor.isInsane - def finalize(self, - vN_DB_str, - conv, - n_it, - farm_config_time, - elapsed_runtimes, - DBUpdated, - nEventsListList, - edit=None): + def finalize( + self, + vN_DB_str, + conv, + n_it, + farm_config_time, + elapsed_runtimes, + DBUpdated, + nEventsListList, + edit=None, + ): nEventsList = nEventsListList[0] nEvents = nEventsListList[1] @@ -174,9 +193,17 @@ class SetupHelper: shutil.copyfile(fromFile, toFile) summaryFile = f"{self.workdir}summary.txt" - self.writeSummary(vN_DB_str, conv, n_it, farm_config_time, - elapsed_runtimes, summaryFile, DBUpdated, nEvents, - nEventsList) + self.writeSummary( + vN_DB_str, + conv, + n_it, + farm_config_time, + elapsed_runtimes, + summaryFile, + DBUpdated, + nEvents, + nEventsList, + ) if self.flat is False: if "online" in getpass.getuser(): @@ -184,28 +211,29 @@ class SetupHelper: else: print( "INFO: TESTBENCH: If your user name is not 'online' will not save in usual place (" - + self.savedir + - ") to avoid a potential permissions issue." + + self.savedir + + ") to avoid a potential permissions issue." ) # PN: Temporary print( "INFO: TESTBENCH: Instead will save in the testbench output directory." ) # PN: Temporary sys.stdout.flush() - #self.savedir = "/home/pnaik/SCRATCH_TESTBENCH" + '/' + self.directoryTime + '/' # PN: Temporary - self.savedir = "." + '/' + self.directoryTime + '/' # PN: Temporary + # self.savedir = "/home/pnaik/SCRATCH_TESTBENCH" + '/' + self.directoryTime + '/' # PN: Temporary + self.savedir = "." + "/" + self.directoryTime + "/" # PN: Temporary if not os.path.exists(self.savedir): os.makedirs(self.savedir) else: + print("INFO: You are running the Iterator in flat (not fully Online) mode.") print( - "INFO: You are running the Iterator in flat (not fully Online) mode." + "INFO: Will not save in usual place (" + + self.savedir + + ") to avoid a potential permissions issue." ) - print("INFO: Will not save in usual place (" + self.savedir + - ") to avoid a potential permissions issue.") print( "INFO: Instead will save in the directory you launched the Iterator from." ) sys.stdout.flush() - self.savedir = "./" + '/' + self.directoryTime + '/' + self.savedir = "./" + "/" + self.directoryTime + "/" if not os.path.exists(self.savedir): os.makedirs(self.savedir) print( @@ -235,72 +263,94 @@ class SetupHelper: # Create the trend plots automatically, now that the savedir is written import PyMirrAlignOnline.trendHelper as trendHelper - print("INFO: Now producing the trend plots for RICH" + - str(self.whichRich) + ".") + + print( + "INFO: Now producing the trend plots for RICH" + str(self.whichRich) + "." + ) sys.stdout.flush() # Files for the Alignment trend plots - trendFile_Fills_hollow = self.workdir + 'Rich' + str( - self.whichRich) + '_AlignTrend_Fills_hollow.pdf' - trendFile_Dates_hollow = self.workdir + 'Rich' + str( - self.whichRich) + '_AlignTrend_Dates_hollow.pdf' + trendFile_Fills_hollow = ( + self.workdir + "Rich" + str(self.whichRich) + "_AlignTrend_Fills_hollow.pdf" + ) + trendFile_Dates_hollow = ( + self.workdir + "Rich" + str(self.whichRich) + "_AlignTrend_Dates_hollow.pdf" + ) # set dates minDate = self.trendDateRange[ - 'minDate'] # 2017 data: 20170602 / Rich2: 20170605 - maxDate = self.trendDateRange['maxDate'] # 2017 data: 20171129 - #now = datetime.datetime.now() + "minDate" + ] # 2017 data: 20170602 / Rich2: 20170605 + maxDate = self.trendDateRange["maxDate"] # 2017 data: 20171129 + # now = datetime.datetime.now() if minDate is None: - minDate = int( - self.now.year) * 10000 + 1 * 100 + 1 # beginning of run year + minDate = int(self.now.year) * 10000 + 1 * 100 + 1 # beginning of run year if maxDate is None: - maxDate = int( - self.now.year) * 10000 + 12 * 100 + 31 # end of run year + maxDate = int(self.now.year) * 10000 + 12 * 100 + 31 # end of run year print( 'INFO: Now making the "hollow" trend plot with Fills on the x-axis, with minDate ' - + str(minDate) + ' and maxDate ' + str(maxDate)) - P_Fills_hollow = trendHelper.Plotter(self.whichRich, 'hollow', "Fills", - minDate, maxDate, - trendFile_Fills_hollow) + + str(minDate) + + " and maxDate " + + str(maxDate) + ) + P_Fills_hollow = trendHelper.Plotter( + self.whichRich, "hollow", "Fills", minDate, maxDate, trendFile_Fills_hollow + ) alignmentsExist = P_Fills_hollow.GetAlignments() if alignmentsExist: P_Fills_hollow.calculate_tilts() print( 'INFO: Now making the "hollow" trend plot with Dates on the x-axis, with minDate ' - + str(minDate) + ' and maxDate ' + str(maxDate)) - P_Dates_hollow = trendHelper.Plotter(self.whichRich, 'hollow', "Dates", - minDate, maxDate, - trendFile_Dates_hollow) + + str(minDate) + + " and maxDate " + + str(maxDate) + ) + P_Dates_hollow = trendHelper.Plotter( + self.whichRich, "hollow", "Dates", minDate, maxDate, trendFile_Dates_hollow + ) alignmentsExist = P_Dates_hollow.GetAlignments() if alignmentsExist: P_Dates_hollow.calculate_tilts() # Identify important file names - ChangeWRTDBFile = self.savedir + "/Rich" + str( - self.whichRich) + '_ChangeWRTDB_' + str(n_it + 1) + '.txt' - AlignSummaryFile = self.savedir + "/Rich" + str( - self. - whichRich) + '_AlignSummary.pdf' # For RICH piquet and experts - AlignMonitorFile = self.savedir + "/Rich" + str( - self.whichRich) + '_AlignMonitor.pdf' # For Monitoring - AlignTrendFile_Fills_hollow = self.savedir + "/Rich" + str( - self.whichRich - ) + '_AlignTrend_Fills_hollow.pdf' # Automatic alignment trend plot - AlignTrendFile_Dates_hollow = self.savedir + "/Rich" + str( - self.whichRich - ) + '_AlignTrend_Dates_hollow.pdf' # Automatic alignment trend plot - - AlignTestingFile = self.workdir + "/Rich" + str( - self.whichRich - ) + '_AlignTesting.pdf' # Not used just yet; May not exist + ChangeWRTDBFile = ( + self.savedir + + "/Rich" + + str(self.whichRich) + + "_ChangeWRTDB_" + + str(n_it + 1) + + ".txt" + ) + AlignSummaryFile = ( + self.savedir + "/Rich" + str(self.whichRich) + "_AlignSummary.pdf" + ) # For RICH piquet and experts + AlignMonitorFile = ( + self.savedir + "/Rich" + str(self.whichRich) + "_AlignMonitor.pdf" + ) # For Monitoring + AlignTrendFile_Fills_hollow = ( + self.savedir + + "/Rich" + + str(self.whichRich) + + "_AlignTrend_Fills_hollow.pdf" + ) # Automatic alignment trend plot + AlignTrendFile_Dates_hollow = ( + self.savedir + + "/Rich" + + str(self.whichRich) + + "_AlignTrend_Dates_hollow.pdf" + ) # Automatic alignment trend plot + + AlignTestingFile = ( + self.workdir + "/Rich" + str(self.whichRich) + "_AlignTesting.pdf" + ) # Not used just yet; May not exist # Copy the "hollow" trend file with Fills on the x-axis from the workdir to the savedir # This is the only one we send to the RICH ELOG - if os.path.exists(trendFile_Fills_hollow) and os.path.exists( - self.savedir): + if os.path.exists(trendFile_Fills_hollow) and os.path.exists(self.savedir): print( 'INFO: storing "hollow" alignment trend plot with Fills on the x-axis in file: ' - + AlignTrendFile_Fills_hollow) + + AlignTrendFile_Fills_hollow + ) try: copy(trendFile_Fills_hollow, AlignTrendFile_Fills_hollow) except: @@ -308,17 +358,22 @@ class SetupHelper: f"WARNING: failed copy(trendFile_Fills_hollow,AlignTrendFile_Fills_hollow)" ) else: - print("INFO: " + trendFile_Fills_hollow + " or " + self.savedir + - " does not exist.") + print( + "INFO: " + + trendFile_Fills_hollow + + " or " + + self.savedir + + " does not exist." + ) sys.stdout.flush() # Copy the "hollow" trend file with Dates on the x-axis from the workdir to the savedir # This is not sent to the RICH ELOG, but available for AlignmentView - if os.path.exists(trendFile_Dates_hollow) and os.path.exists( - self.savedir): + if os.path.exists(trendFile_Dates_hollow) and os.path.exists(self.savedir): print( 'INFO: storing "hollow" alignment trend plot with Dates on the x-axis in file: ' - + AlignTrendFile_Dates_hollow) + + AlignTrendFile_Dates_hollow + ) try: copy(trendFile_Dates_hollow, AlignTrendFile_Dates_hollow) except: @@ -326,33 +381,60 @@ class SetupHelper: f"WARNING: failed copy(trendFile_Dates_hollow,AlignTrendFile_Dates_hollow)" ) else: - print("INFO: " + trendFile_Dates_hollow + " or " + self.savedir + - " does not exist.") + print( + "INFO: " + + trendFile_Dates_hollow + + " or " + + self.savedir + + " does not exist." + ) sys.stdout.flush() # Write files and information to the RICH and Alignment Monitor ELOGs, and also send email - alignment_time = elapsed_runtimes['elapsed_time_run'] + alignment_time = elapsed_runtimes["elapsed_time_run"] self.writeInLogbook( - vN_DB_str, conv, n_it, farm_config_time, alignment_time, - summaryFile, ChangeWRTDBFile, AlignSummaryFile, AlignMonitorFile, - AlignTrendFile_Fills_hollow, DBUpdated, nEvents, edit) - - def writeInLogbook(self, vN_DB_str, conv, n_it, farm_config_time, - alignment_time, summaryFile, ChangeWRTDBFile, - AlignSummaryFile, AlignMonitorFile, - AlignTrendFile_Fills_hollow, DBUpdated, nEvents, edit): + vN_DB_str, + conv, + n_it, + farm_config_time, + alignment_time, + summaryFile, + ChangeWRTDBFile, + AlignSummaryFile, + AlignMonitorFile, + AlignTrendFile_Fills_hollow, + DBUpdated, + nEvents, + edit, + ) + + def writeInLogbook( + self, + vN_DB_str, + conv, + n_it, + farm_config_time, + alignment_time, + summaryFile, + ChangeWRTDBFile, + AlignSummaryFile, + AlignMonitorFile, + AlignTrendFile_Fills_hollow, + DBUpdated, + nEvents, + edit, + ): hh, r = divmod(farm_config_time, 3600) mm, ss = divmod(r, 60) - farm_config_time_str = "{:0>2}:{:0>2}:{:05.2f}".format( - int(hh), int(mm), ss) + farm_config_time_str = "{:0>2}:{:0>2}:{:05.2f}".format(int(hh), int(mm), ss) hh, r = divmod(alignment_time, 3600) mm, ss = divmod(r, 60) - alignment_time_str = "{:0>2}:{:0>2}:{:05.2f}".format( - int(hh), int(mm), ss) + alignment_time_str = "{:0>2}:{:0>2}:{:05.2f}".format(int(hh), int(mm), ss) if self.flat is False: if "online" in getpass.getuser(): import OnlineEnvBase as Online # import OnlineEnv as Online + online_options = alignment_options(Online) runs = online_options.runs # runs = Online.DeferredRuns # PN - Extract the run number substring from the full string - WILL NOT WORK IF RUN NUMBERS BECOME 7 DIGITS @@ -364,39 +446,41 @@ class SetupHelper: FillAlignment = 0 # RICH ELOG - host = 'logbook.lbdaq.cern.ch' #'lblogbook.cern.ch' + host = "logbook.lbdaq.cern.ch" #'lblogbook.cern.ch' port = 8080 - username = 'common Common\!' # used to be 'common Common\\!' but now works with only one escape - subject = '' - text = '' - instruction_file = 'https://twiki.cern.ch/twiki/bin/view/LHCb/LHCbRun3RichMirrAlignShiftInfo' - subjText = '' + username = "common Common\!" # used to be 'common Common\\!' but now works with only one escape + subject = "" + text = "" + instruction_file = ( + "https://twiki.cern.ch/twiki/bin/view/LHCb/LHCbRun3RichMirrAlignShiftInfo" + ) + subjText = "" if self.testing: - logbook = 'TestLogbook' - systemName = 'System' - activity = 'Test' - author = 'Generic Elog Account' + logbook = "TestLogbook" + systemName = "System" + activity = "Test" + author = "Generic Elog Account" else: - logbook = 'RICH' - systemName = 'System_19' # Change 19 if Alignment changes its order in the ELOG (ask the current RICH expert) - activity = 'Alignment' - author = 'MirrAlign Monitor' # Or any other name + logbook = "RICH" + systemName = "System_19" # Change 19 if Alignment changes its order in the ELOG (ask the current RICH expert) + activity = "Alignment" + author = "MirrAlign Monitor" # Or any other name if DBUpdated: - subjText = ' updated,' + subjText = " updated," elif self.testing and DBUpdated is None: - subjText = ' not updated due to testing = True,' # if testing is on, regardless of autoUpdate setting + subjText = " not updated due to testing = True," # if testing is on, regardless of autoUpdate setting elif DBUpdated is None: if self.autoUpdate is False: - subjText = ' not updated due to autoUpdate = False, needs MirrAlign expert decision,' # testing and autoUpdate were off to begin with + subjText = " not updated due to autoUpdate = False, needs MirrAlign expert decision," # testing and autoUpdate were off to begin with elif self.autoUpdateNoV: - subjText = ' not updated due to sanity check issue, needs MirrAlign expert decision,' # testing off, but autoUpdate was on at the start, then switched off + subjText = " not updated due to sanity check issue, needs MirrAlign expert decision," # testing off, but autoUpdate was on at the start, then switched off elif self.autoUpdateNoV is False: - subjText = ' not updated due to sanity check issue,' # existing version was provided + subjText = " not updated due to sanity check issue," # existing version was provided else: - subjText += '' + subjText += "" else: - subjText += '' + subjText += "" if self.testing: subject = f"TEST [{self.dataVariant}]: " @@ -425,7 +509,9 @@ class SetupHelper: if DBUpdated is None: text += f" There was a significant change from the alignment in the DB, or a change in magnet polarity. However, the final state of autoUpdate was set to False (even if the initial state of autoUpdate was True), or the alignment is in testing mode, so the DB was not updated. If the automatic update feature was disabled, a sanity check was not satisfied. Please notify a MirrAlign expert to investigate whether this alignment ({vN_DB_str}) should be installed." - if self.autoUpdate and self.autoUpdateNoV: # We should maybe provide more info here + if ( + self.autoUpdate and self.autoUpdateNoV + ): # We should maybe provide more info here text += " Please note: autoUpdate was initially True, and autoUpdateNoV was set to True. This means that an alignment version has NOT been provided to HLT2." elif DBUpdated: text += f" Due to a significant change from the alignment in the DB, or a change in magnet polarity, the DB was automatically updated to {vN_DB_str}." @@ -435,42 +521,43 @@ class SetupHelper: if not self.autoUpdate: text += " The initial state of autoUpdate was set to False in the configuration." - command = '' - #elog -h "logbook.lbdaq.cern.ch" -p 8080 -l "RICH" -u common Common\! -a "Author=MirrAlign Monitor" -a "System_19=Alignment" -a "Subject=TEST" "Testing the writing of logbook entries from the mirror alignment.\n RICH piquets should ignore all mirror alignments marked TEST in the subject heading.\n (Notes: common / System_19)" + command = "" + # elog -h "logbook.lbdaq.cern.ch" -p 8080 -l "RICH" -u common Common\! -a "Author=MirrAlign Monitor" -a "System_19=Alignment" -a "Subject=TEST" "Testing the writing of logbook entries from the mirror alignment.\n RICH piquets should ignore all mirror alignments marked TEST in the subject heading.\n (Notes: common / System_19)" command += f'/group/online/bin/elog -h "{host}" -p {port}' if edit: - command += f' -e {int(edit)}' + command += f" -e {int(edit)}" command += f' -l "{logbook}" -u {username} -a "Author={author}"' command += f' -a "{systemName}={activity}" -a "Subject={subject}" "{text}"' files = [ - summaryFile, ChangeWRTDBFile, AlignSummaryFile, - AlignTrendFile_Fills_hollow + summaryFile, + ChangeWRTDBFile, + AlignSummaryFile, + AlignTrendFile_Fills_hollow, ] for file in files: if os.path.exists(file): command += f' -f "{file}"' - #print(f'DEBUG: command = elog -h "logbook.lbdaq.cern.ch" -p 8080 -l "RICH" -u common Common\! -a "Author=MirrAlign Monitor" -a "System_19=Alignment" -a "Subject=TEST" "Testing the writing of logbook entries from the mirror alignment.\n RICH piquets should ignore all mirror alignments marked TEST in the subject heading.\n (Notes: common / System_19)"') + # print(f'DEBUG: command = elog -h "logbook.lbdaq.cern.ch" -p 8080 -l "RICH" -u common Common\! -a "Author=MirrAlign Monitor" -a "System_19=Alignment" -a "Subject=TEST" "Testing the writing of logbook entries from the mirror alignment.\n RICH piquets should ignore all mirror alignments marked TEST in the subject heading.\n (Notes: common / System_19)"') print(f"INFO: command = {command}") cmd = shlex.split(command) try: env = os.environ.copy() - library_path = os.environ['LD_LIBRARY_PATH'] - env['LD_LIBRARY_PATH'] = f'{library_path}:/opt/nvidia/nsight-compute/2022.4.0/host/target-linux-x64/CollectX/' - elogret = subprocess.check_output( - cmd, stderr=subprocess.STDOUT, env=env) + library_path = os.environ["LD_LIBRARY_PATH"] + env["LD_LIBRARY_PATH"] = ( + f"{library_path}:/opt/nvidia/nsight-compute/2022.4.0/host/target-linux-x64/CollectX/" + ) + elogret = subprocess.check_output(cmd, stderr=subprocess.STDOUT, env=env) messageID_match = re.search( - r'.*Message successfully transmitted, ID=(\d*)', - elogret.decode()) + r".*Message successfully transmitted, ID=(\d*)", elogret.decode() + ) if messageID_match: messageID = int(messageID_match.group(1)) else: - print( - "WARNING: Failed to extract message ID (main write to RICH ELOG)" - ) + print("WARNING: Failed to extract message ID (main write to RICH ELOG)") messageID = None except: messageID = None @@ -478,42 +565,51 @@ class SetupHelper: print(f"INFO: messageID = {messageID} (main write to RICH ELOG)") # Alignment ELOG - logbookAlignment = 'Alignment monitoring' # always - authorAlignment = 'monibot' # always - activityAlignment = 'Rich' + str(self.whichRich) + ' Mirrors' # always - TypeAlignment = 'Convergence' # always - #subjectAlignment = 'IGNORE-- ' - #textAlignment = 'Please Ignore: \n ' - subjectAlignment = '' - textAlignment = '' - StatusAlignment = 'Good' # or can be changed below to 'Unchecked' or 'Bad' (for now 'Bad' never happens) + logbookAlignment = "Alignment monitoring" # always + authorAlignment = "monibot" # always + activityAlignment = "Rich" + str(self.whichRich) + " Mirrors" # always + TypeAlignment = "Convergence" # always + # subjectAlignment = 'IGNORE-- ' + # textAlignment = 'Please Ignore: \n ' + subjectAlignment = "" + textAlignment = "" + StatusAlignment = "Good" # or can be changed below to 'Unchecked' or 'Bad' (for now 'Bad' never happens) if self.testing: - subjectAlignment += 'TEST [' + self.dataVariant + ']: ' - textAlignment += f'A test mirror alignment for Rich{self.whichRich} was performed for fill {FillAlignment} by a RICH mirror alignment expert. No action is necessary; ignore the following. \n' + subjectAlignment += "TEST [" + self.dataVariant + "]: " + textAlignment += f"A test mirror alignment for Rich{self.whichRich} was performed for fill {FillAlignment} by a RICH mirror alignment expert. No action is necessary; ignore the following. \n" if DBUpdated is None: - subjectAlignment += 'No alignment update-- Needs MirrAlign expert decision' - textAlignment += f'Rich{self.whichRich} mirror alignment for fill {FillAlignment} is requesting an update be made, but for some reason this was not done automatically. Please ask the Rich Mirror Alignment experts to investigate the draft alignment ({vN_DB_str}). Monitoring plots in the attachment; shifter\'s instructions can be found at: {instruction_file}' - StatusAlignment = 'Unchecked' + subjectAlignment += "No alignment update-- Needs MirrAlign expert decision" + textAlignment += f"Rich{self.whichRich} mirror alignment for fill {FillAlignment} is requesting an update be made, but for some reason this was not done automatically. Please ask the Rich Mirror Alignment experts to investigate the draft alignment ({vN_DB_str}). Monitoring plots in the attachment; shifter's instructions can be found at: {instruction_file}" + StatusAlignment = "Unchecked" elif DBUpdated: - subjectAlignment += 'Monitoring plots' - textAlignment += f'Updated Rich{self.whichRich} mirror alignment for fill {FillAlignment} ({vN_DB_str}), monitoring plots in the attachment; shifter\'s instructions can be found at: {instruction_file}' - StatusAlignment = 'Unchecked' + subjectAlignment += "Monitoring plots" + textAlignment += f"Updated Rich{self.whichRich} mirror alignment for fill {FillAlignment} ({vN_DB_str}), monitoring plots in the attachment; shifter's instructions can be found at: {instruction_file}" + StatusAlignment = "Unchecked" else: - subjectAlignment += 'No alignment update' - textAlignment += f'No Rich{self.whichRich} alignment update needed for fill {FillAlignment}. The DB alignment is still {vN_DB_str}.' + subjectAlignment += "No alignment update" + textAlignment += f"No Rich{self.whichRich} alignment update needed for fill {FillAlignment}. The DB alignment is still {vN_DB_str}." if self.testing: - StatusAlignment = 'Test' + StatusAlignment = "Test" # Construct the elog command command = '/group/online/bin/elog -h "{}" -p {} -l "{}" -u {} -a "Author={}" -a "System={}" -a "Subject={}" -a "Type={}" -a "Fill={}" -a "Status={}" "{}"'.format( - host, port, logbookAlignment, username, authorAlignment, - activityAlignment, subjectAlignment, TypeAlignment, FillAlignment, - StatusAlignment, textAlignment) + host, + port, + logbookAlignment, + username, + authorAlignment, + activityAlignment, + subjectAlignment, + TypeAlignment, + FillAlignment, + StatusAlignment, + textAlignment, + ) # Add the attachment file if applicable if DBUpdated or DBUpdated is None: @@ -522,26 +618,32 @@ class SetupHelper: cmd = shlex.split(command) if self.autoUpdate: # If we are not in autoUpdate mode, then we do not post to the Alignment Monitoring ELOG - FNULL = open(os.devnull, 'w') - subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT) #test + FNULL = open(os.devnull, "w") + subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT) # test # Email - subj2 = '' + subj2 = "" if self.testing: - subj2 += f'TEST [{self.dataVariant}]: ' + subj2 += f"TEST [{self.dataVariant}]: " text2 = f"The Mirror {activity} for RICH{self.whichRich}" if conv: text2 += f" ran for {alignment_time_str} and converged. " - subj2 += f'RICH{self.whichRich} alignment {self.directoryTime} converged: New ELOG entry' + subj2 += f"RICH{self.whichRich} alignment {self.directoryTime} converged: New ELOG entry" else: - text2 += f" ran for {alignment_time_str} and did not converge. Approximately " - subj2 += f'RICH{self.whichRich} alignment {self.directoryTime} incomplete: New ELOG entry' + text2 += ( + f" ran for {alignment_time_str} and did not converge. Approximately " + ) + subj2 += f"RICH{self.whichRich} alignment {self.directoryTime} incomplete: New ELOG entry" text2 += f"{nEvents} events per iteration were processed. {n_it + 1} iteration(s) occured. \n" - db_msg = '' + db_msg = "" if DBUpdated is None: - db_msg = "\n There was a significant change from the alignment in the DB, or a change in magnet polarity. However the automatic update feature is off or was disabled during the alignment (The final state of autoUpdate was set to False), so the DB was not updated. If the automatic update feature was disabled, there may not have been enough events processed, or a sanity check was not satisfied. A MirrAlign expert should investigate whether this draft alignment (" + vN_DB_str + ") should be installed. \n" # We should probably provide more info here + db_msg = ( + "\n There was a significant change from the alignment in the DB, or a change in magnet polarity. However the automatic update feature is off or was disabled during the alignment (The final state of autoUpdate was set to False), so the DB was not updated. If the automatic update feature was disabled, there may not have been enough events processed, or a sanity check was not satisfied. A MirrAlign expert should investigate whether this draft alignment (" + + vN_DB_str + + ") should be installed. \n" + ) # We should probably provide more info here elif DBUpdated: db_msg = f"\n Due to a significant change from the alignment in the DB, or a change in magnet polarity, the DB was automatically updated to {vN_DB_str}. \n" # We should probably provide more info here else: @@ -549,41 +651,55 @@ class SetupHelper: text2 += db_msg links = [ - 'https://lblogbook.cern.ch/RICH/?System=%5EAlignment%24&Subject={0}&mode=full' - .format(self.directoryTime), - 'https://lbrich.cern.ch/alignmentview.php', - 'https://lbrich.cern.ch/plot/index.html?rich=' + str( - self.whichRich) + '&source=mirror' + "https://lblogbook.cern.ch/RICH/?System=%5EAlignment%24&Subject={0}&mode=full".format( + self.directoryTime + ), + "https://lbrich.cern.ch/alignmentview.php", + "https://lbrich.cern.ch/plot/index.html?rich=" + + str(self.whichRich) + + "&source=mirror", ] text2 += "\n More information is available at the following links: \n\n " - text2 += '\n'.join(links) + text2 += "\n".join(links) - text2 += "\n\n Fill number of first run processed: " + str( - FillAlignment) + text2 += "\n\n Fill number of first run processed: " + str(FillAlignment) - auto_update_msg = '' if self.autoUpdate else " \n\n The initial state of autoUpdate was set to False in the configuration." + auto_update_msg = ( + "" + if self.autoUpdate + else " \n\n The initial state of autoUpdate was set to False in the configuration." + ) text2 += auto_update_msg - self.sendEmail(subj2, text2, - self.emails if not self.testing else self.experts) + self.sendEmail(subj2, text2, self.emails if not self.testing else self.experts) return messageID - def writeSummary(self, vN_DB_str, conv, n_it, farm_config_time, - elapsed_runtimes, summaryFile, DBUpdated, nEvents, - nEventsList): - farm_config_time_str = str( - datetime.timedelta(seconds=farm_config_time)) + def writeSummary( + self, + vN_DB_str, + conv, + n_it, + farm_config_time, + elapsed_runtimes, + summaryFile, + DBUpdated, + nEvents, + nEventsList, + ): + farm_config_time_str = str(datetime.timedelta(seconds=farm_config_time)) alignment_time_str = str( - datetime.timedelta(seconds=elapsed_runtimes['elapsed_time_run'])) + datetime.timedelta(seconds=elapsed_runtimes["elapsed_time_run"]) + ) MirrCombinFit_time_str = str( - elapsed_runtimes['elapsed_times_RichMirrCombinFit']) - MirrAlign_time_str = str( - elapsed_runtimes['elapsed_times_RichMirrAlign']) + elapsed_runtimes["elapsed_times_RichMirrCombinFit"] + ) + MirrAlign_time_str = str(elapsed_runtimes["elapsed_times_RichMirrAlign"]) if self.flat is False: if "online" in getpass.getuser(): import OnlineEnvBase as Online # import OnlineEnv as Online + online_options = alignment_options(Online) runs = online_options.runs # runs = Online.DeferredRuns # PN - Extract the run number substring from the full string - WILL NOT WORK IF RUN NUMBERS BECOME 7 DIGITS @@ -592,16 +708,19 @@ class SetupHelper: runs = [] # PN: for testbench else: runs = [] - runsString = ' '.join(str(run) for run in runs) - fillsString = ' '.join( - str(self.getFillNumber(run) - ) if self.getFillNumber(run) is not None else ' ???? ' - for run in runs) - polaritiesString = ' '.join({ - 'UP': ' UP', - 'DOWN': ' DOWN', - 'OFF': ' OFF' - }.get(self.getPolarity(run), ' ???? ') for run in runs) + runsString = " ".join(str(run) for run in runs) + fillsString = " ".join( + str(self.getFillNumber(run)) + if self.getFillNumber(run) is not None + else " ???? " + for run in runs + ) + polaritiesString = " ".join( + {"UP": " UP", "DOWN": " DOWN", "OFF": " OFF"}.get( + self.getPolarity(run), " ???? " + ) + for run in runs + ) finalCKres = math.ceil(self.finalCKres * 10000) / 10000 finalCKresErr = math.ceil(self.finalCKresErr * 10000) / 10000 @@ -609,66 +728,71 @@ class SetupHelper: print("INFO: LHCbA config time (readable): " + farm_config_time_str) # print("INFO: Note, the LHCbA config time may be inaccurate if the alignment is run manually with LHCbA AutoPilot OFF.") print("INFO: Alignment time (readable): " + alignment_time_str) - args = (f'richDetector = {self.whichRich}\n' - f'DB updated = {DBUpdated}\n') + args = ( + f"richDetector = {self.whichRich}\n" + f"DB updated = {DBUpdated}\n" + ) args += ( - f' (Alignment changed, but autoUpdate started as False or was disabled)\n' - if DBUpdated is None else f'') + f" (Alignment changed, but autoUpdate started as False or was disabled)\n" + if DBUpdated is None + else f"" + ) args += ( - f'resulting DB = {vN_DB_str}\n' - f'converged = {conv}\n' - f'Number of iterations = {n_it + 1}\n' - f'Final iteration label = _i{n_it}\n' - f'Number of events = {nEvents}\n' - f'runs = {runsString}\n' - f'fills = {fillsString}\n' - f'polarities = {polaritiesString}\n' - f'dataVariant = {self.dataVariant}\n' - f'savedir = {self.savedir}\n' - f'magnFactorsMode = {self.magnFactorsMode}\n' - f'magnifDir = {self.magnifDir}\n' - f'XML_YAML_configDir = {self.XML_YAML_configDir}\n' - #f'combAndMirrSubsets = {self.combAndMirrSubsets}\n' - f'LHCbA config time = {farm_config_time_str}\n' - f'Alignment time = {alignment_time_str}\n' - f'CK angle resolution = {finalCKres}\n' - f' error = {finalCKresErr}\n' - f'startXMLFile = {self.alignConf.getProp("startXMLFile")}\n' - f'compareXMLFile = {self.alignConf.getProp("compareXMLFile")}\n' - f'startYAMLFile = {self.alignConf.getProp("startYAMLFile")}\n' - f'compareYAMLFile = {self.alignConf.getProp("compareYAMLFile")}\n' - f'YAMLio = {self.YAMLio}\n' - f'useDD4Hep = {self.useDD4hep}\n' - f'\n' - f'autoUpdate (initial) = {self.autoUpdate}\n' - f'autoUpdateNoV = {self.autoUpdateNoV}\n' - f'testing = {self.testing}\n' - f'requiredEvents = {self.alignConf.getProp("requiredEvents")}\n' - f'minAverageBinPop = {self.minAverageBinPop}\n' - f'phiBinFactor = {self.phiBinFactor}\n' - f'minFracPhiBinsPopulated = {self.minFracPhiBinsPopulated}\n' - f'deltaThetaWindow = {self.deltaThetaWindow}\n' - f'combinFitMethod = {self.combinFitMethod}\n' - f'solutionMethod = {self.solutionMethod}\n' - f'coeffCalibTilt = {self.coeffCalibTilt}\n' - f'fixSinusoidShift = {self.fixSinusoidShift}\n' - f'maxIterations = {self.alignConf.getProp("maxIterations")}\n' - f'useHltDecisions = {self.alignConf.getProp("useHltDecisions")}\n' - f'usingReducedSubset = {self.usingReducedSubset}\n' - f'EvtMax = {self.alignConf.getProp("EvtMax")}\n' - f'regularizationMode = {self.alignConf.getProp("regularizationMode")}\n' - f'stopDecisionMode = {self.alignConf.getProp("stopDecisionMode")}\n' - f'stopToleranceMode = {self.alignConf.getProp("stopToleranceMode")}\n' - f'nominalResolutionSigma = {self.alignConf.getProp("nominalResolutionSigma")}\n' - f'stopSigmaFraction = {self.alignConf.getProp("stopSigmaFraction")}\n' - f'warningFactor = {self.alignConf.getProp("warningFactor")}\n' - f'stopTolerancePriY = {self.alignConf.getProp("stopTolerancePriY")}\n' - f'stopTolerancePriZ = {self.alignConf.getProp("stopTolerancePriZ")}\n' - f'stopToleranceSecY = {self.alignConf.getProp("stopToleranceSecY")}\n' - f'stopToleranceSecZ = {self.alignConf.getProp("stopToleranceSecZ")}\n' - f'nEventsList = {nEventsList}\n' - f'CombinFit times = {MirrCombinFit_time_str}\n' - f'MirrAlign times = {MirrAlign_time_str}\n') + f"resulting DB = {vN_DB_str}\n" + f"converged = {conv}\n" + f"Number of iterations = {n_it + 1}\n" + f"Final iteration label = _i{n_it}\n" + f"Number of events = {nEvents}\n" + f"runs = {runsString}\n" + f"fills = {fillsString}\n" + f"polarities = {polaritiesString}\n" + f"dataVariant = {self.dataVariant}\n" + f"savedir = {self.savedir}\n" + f"magnFactorsMode = {self.magnFactorsMode}\n" + f"magnifDir = {self.magnifDir}\n" + f"XML_YAML_configDir = {self.XML_YAML_configDir}\n" + # f'combAndMirrSubsets = {self.combAndMirrSubsets}\n' + f"LHCbA config time = {farm_config_time_str}\n" + f"Alignment time = {alignment_time_str}\n" + f"CK angle resolution = {finalCKres}\n" + f" error = {finalCKresErr}\n" + f"startXMLFile = {self.alignConf.getProp('startXMLFile')}\n" + f"compareXMLFile = {self.alignConf.getProp('compareXMLFile')}\n" + f"startYAMLFile = {self.alignConf.getProp('startYAMLFile')}\n" + f"compareYAMLFile = {self.alignConf.getProp('compareYAMLFile')}\n" + f"YAMLio = {self.YAMLio}\n" + f"useDD4Hep = {self.useDD4hep}\n" + f"\n" + f"autoUpdate (initial) = {self.autoUpdate}\n" + f"autoUpdateNoV = {self.autoUpdateNoV}\n" + f"testing = {self.testing}\n" + f"requiredEvents = {self.alignConf.getProp('requiredEvents')}\n" + f"minAverageBinPop = {self.minAverageBinPop}\n" + f"phiBinFactor = {self.phiBinFactor}\n" + f"minFracPhiBinsPopulated = {self.minFracPhiBinsPopulated}\n" + f"deltaThetaWindow = {self.deltaThetaWindow}\n" + f"combinFitMethod = {self.combinFitMethod}\n" + f"solutionMethod = {self.solutionMethod}\n" + f"coeffCalibTilt = {self.coeffCalibTilt}\n" + f"fixSinusoidShift = {self.fixSinusoidShift}\n" + f"maxIterations = {self.alignConf.getProp('maxIterations')}\n" + f"useHltDecisions = {self.alignConf.getProp('useHltDecisions')}\n" + f"usingReducedSubset = {self.usingReducedSubset}\n" + f"EvtMax = {self.alignConf.getProp('EvtMax')}\n" + f"regularizationMode = {self.alignConf.getProp('regularizationMode')}\n" + f"stopDecisionMode = {self.alignConf.getProp('stopDecisionMode')}\n" + f"stopToleranceMode = {self.alignConf.getProp('stopToleranceMode')}\n" + f"nominalResolutionSigma = {self.alignConf.getProp('nominalResolutionSigma')}\n" + f"stopSigmaFraction = {self.alignConf.getProp('stopSigmaFraction')}\n" + f"warningFactor = {self.alignConf.getProp('warningFactor')}\n" + f"stopTolerancePriY = {self.alignConf.getProp('stopTolerancePriY')}\n" + f"stopTolerancePriZ = {self.alignConf.getProp('stopTolerancePriZ')}\n" + f"stopToleranceSecY = {self.alignConf.getProp('stopToleranceSecY')}\n" + f"stopToleranceSecZ = {self.alignConf.getProp('stopToleranceSecZ')}\n" + f"nEventsList = {nEventsList}\n" + f"CombinFit times = {MirrCombinFit_time_str}\n" + f"MirrAlign times = {MirrAlign_time_str}\n" + ) # not provided yet (not sure if there is need): # MajItStart and MinItStart # WorkDir, ItNrFile, thisCase, tiltNames, and original SaveDir in configuration @@ -677,17 +801,20 @@ class SetupHelper: if os.path.exists(summaryFile): print(f"INFO: Removing existing {summaryFile}") os.remove(summaryFile) - with open(summaryFile, 'w') as f: + with open(summaryFile, "w") as f: print(f"INFO: Writing {summaryFile}") f.write(args) sys.stdout.flush() richFilesDir = self.alignConf.getProp( - 'richFiles') # '/group/rich/AlignmentFiles/' - CKresTrendFile = f"{richFilesDir}Logging/Rich" + str( - self.whichRich) + "_CKresTrend.txt" - UpdateTrendFile = f"{richFilesDir}Logging/Rich" + str( - self.whichRich) + "_UpdateTrend.txt" + "richFiles" + ) # '/group/rich/AlignmentFiles/' + CKresTrendFile = ( + f"{richFilesDir}Logging/Rich" + str(self.whichRich) + "_CKresTrend.txt" + ) + UpdateTrendFile = ( + f"{richFilesDir}Logging/Rich" + str(self.whichRich) + "_UpdateTrend.txt" + ) if self.flat is False: if "online" in getpass.getuser(): @@ -702,25 +829,32 @@ class SetupHelper: firstCollisionInfo = None if firstFill is not None: - firstFill_str = '' + str(firstFill) + '' + firstFill_str = "" + str(firstFill) + "" else: - firstFill_str = '????' + firstFill_str = "????" if firstFill is not None: firstPolarity = self.getPolarity(runs[0]) firstCollisionInfo = self.getCollisionInfo(runs[0]) - firstPolarity_str = ' UP' if firstPolarity == 'UP' else \ - 'DOWN' if firstPolarity == 'DOWN' else \ - ' OFF' if firstPolarity == 'OFF' else \ - '????' + firstPolarity_str = ( + " UP" + if firstPolarity == "UP" + else "DOWN" + if firstPolarity == "DOWN" + else " OFF" + if firstPolarity == "OFF" + else "????" + ) - firstCollisionInfo_str = '' + str( - firstCollisionInfo - ) + '' if firstCollisionInfo is not None else '????' + firstCollisionInfo_str = ( + "" + str(firstCollisionInfo) + "" + if firstCollisionInfo is not None + else "????" + ) else: - firstPolarity_str = '????' - firstCollisionInfo_str = '????' + firstPolarity_str = "????" + firstCollisionInfo_str = "????" if not self.testing: with open(CKresTrendFile, "a") as file: @@ -745,19 +879,21 @@ class SetupHelper: f"# TEST {firstFill_str}\t{self.directoryTime}\t{vN_DB_str}\t{firstPolarity_str}\t{firstCollisionInfo_str}\n" ) if "testing_maybe" in vN_DB_str: - maybeSubj = "A _testing_maybe version has been produced by the mirror alignment" + maybeSubj = ( + "A _testing_maybe version has been produced by the mirror alignment" + ) maybeText = f"A _testing_maybe version has been produced by the mirror alignment. \n If you choose to use this alignment for this fill(s), make sure as you address this to update the entry in {richFilesDir}Logging/Rich{self.whichRich}_UpdateTrend.txt, with the result (i.e. a proper vN). Also uncomment the '# TEST ' part of the relevant line in {richFilesDir}Logging/Rich{self.whichRich}_CKresTrend.txt please." self.sendEmail(maybeSubj, maybeText, self.experts) def sendEmail(self, subject, text, receiversList): - sender = 'lhcb-rich-mirror-alignment-development@cern.ch' - message = 'From: MirrAlign Monitor <{}>\n'.format(sender) - message += 'To: {}\n'.format(', '.join(receiversList)) - message += 'Subject: {}\n\n'.format(subject) - message += '{}\n\n'.format(text) + sender = "lhcb-rich-mirror-alignment-development@cern.ch" + message = "From: MirrAlign Monitor <{}>\n".format(sender) + message += "To: {}\n".format(", ".join(receiversList)) + message += "Subject: {}\n\n".format(subject) + message += "{}\n\n".format(text) try: - smtpObj = smtplib.SMTP('localhost') + smtpObj = smtplib.SMTP("localhost") smtpObj.sendmail(sender, receiversList, message) print("INFO: Successfully sent email") return True # PN: probably not needed, hopefully harmless @@ -776,9 +912,9 @@ class SetupHelper: if not run_info: return None # Check if fill ID is missing or invalid - if run_info['fillid'] is None or run_info['fillid'] == 0: + if run_info["fillid"] is None or run_info["fillid"] == 0: return None - fill_number = run_info['fillid'] + fill_number = run_info["fillid"] except: print(f"WARNING: getFillNumber() = None") # Error occurred when querying RunDB API @@ -803,10 +939,10 @@ class SetupHelper: # Engineered from https://gitlab.cern.ch/lhcb/Lovell/blob/master/VeloAnalysisFramework/python/veloview/utils/rundb.py def getPolarity(self, runNumber): """Get the polarity of a given run number from the LBRUNDB. - + Args: runNumber (int): The run number to query. - + Returns: Polarity or None: The polarity of the run, or None if the polarity could not be determined. @@ -814,7 +950,7 @@ class SetupHelper: run_info = self.queryRunDB(runNumber) if not run_info: return None - polarity = run_info.get('magnetState') + polarity = run_info.get("magnetState") if not polarity: # Polarity not included in JSON response return None # API returns UP for magnet up, DOWN for magnet down, OFF for off @@ -822,9 +958,11 @@ class SetupHelper: # Engineered from https://gitlab.cern.ch/lhcb/Lovell/blob/master/VeloAnalysisFramework/python/veloview/utils/rundb.py def queryRunDB(self, runNumber): - import json, urllib.request - RUNDB_API_URL = f'http://rundb-internal.lbdaq.cern.ch/api/run/{runNumber}/' # e.g. see http://lbrundb.cern.ch/api/run/185380/ for what's available - #RUNDB_API_URL = f'https://lbrundb.cern.ch/api/run/{runNumber}/' # e.g. see http://lbrundb.cern.ch/api/run/185380/ for what's available + import json + import urllib.request + + RUNDB_API_URL = f"http://rundb-internal.lbdaq.cern.ch/api/run/{runNumber}/" # e.g. see http://lbrundb.cern.ch/api/run/185380/ for what's available + # RUNDB_API_URL = f'https://lbrundb.cern.ch/api/run/{runNumber}/' # e.g. see http://lbrundb.cern.ch/api/run/185380/ for what's available request = urllib.request.urlopen(RUNDB_API_URL) # Make sure the request was OK, not e.g. 404 not found if request.getcode() != 200: @@ -833,9 +971,9 @@ class SetupHelper: ) return None try: - #print(f"DEBUG: request.getcode() is 200. Trying to query the LHCb RunDB.") - response_data = request.read().decode('utf-8') - #print(f"DEBUG: Response data: {response_data}") + # print(f"DEBUG: request.getcode() is 200. Trying to query the LHCb RunDB.") + response_data = request.read().decode("utf-8") + # print(f"DEBUG: Response data: {response_data}") run_json = json.loads(response_data) except ValueError as e: # Couldn't decode the response @@ -843,40 +981,42 @@ class SetupHelper: f"WARNING: Unsuccessfully querying LHCb RunDB. Couldn't decode the response: {str(e)}" ) return None - #print("INFO: Querying of the LHCb RunDB is Successful.") + # print("INFO: Querying of the LHCb RunDB is Successful.") return run_json def getNEventsListList(self, n_it): - #yaml = YAML() - #with open(f"{self.workdir}/rich{self.whichRich}_variant.yml") as finp: + # yaml = YAML() + # with open(f"{self.workdir}/rich{self.whichRich}_variant.yml") as finp: # current_variant = yaml.load(finp) - #file_prefix = f"{self.workdir}/{current_variant}_histos_i" + # file_prefix = f"{self.workdir}/{current_variant}_histos_i" file_prefix = f"{self.workdir}RichDataTuple_i" - #print(file_prefix) + # print(file_prefix) event_counts = [] for j in range(n_it + 1): useTextFile = True if useTextFile is True: # Define the pattern to match the files analyzerOutDir = os.path.join( - f"{self.workdir}Rich{self.whichRich}AnalyzerOutput", '') - file_pattern = f'{analyzerOutDir}Rich{self.whichRich}AnalyzerOut_i{j}*txt' + f"{self.workdir}Rich{self.whichRich}AnalyzerOutput", "" + ) + file_pattern = ( + f"{analyzerOutDir}Rich{self.whichRich}AnalyzerOut_i{j}*txt" + ) # Initialize a variable to store the sum total_sum = 0 # Iterate over the matching files for filename in glob.glob(file_pattern): - with open(filename, 'r') as file: + with open(filename, "r") as file: for line in file: - if 'createODIN/Decode_ODIN' in line and 'Sum=' in line: + if "createODIN/Decode_ODIN" in line and "Sum=" in line: # Extract the sum value from the line - sum_value = int( - line.split('Sum=')[1].split()[0]) + sum_value = int(line.split("Sum=")[1].split()[0]) total_sum += sum_value event_counts.append(total_sum) - ''' + """ else: filename = f"{file_prefix}{j}.root" #print(filename) @@ -894,7 +1034,7 @@ class SetupHelper: print("ERROR: RichDataTree is not a valid TTree object.") else: event_counts.append(0) - ''' + """ # Calculate the denominator of the average, based on the count of zero values appearing in the event_counts list denominator = n_it + 1 if event_counts.count(0) > 0: @@ -917,57 +1057,60 @@ class SetupHelper: return [event_counts, average_n_events] def quickWriteInLogbook( - self, - subject="", - text="", - edit=None, - instruction_file_url="https://twiki.cern.ch/twiki/bin/view/LHCb/LHCbRun3RichMirrAlignShiftInfo" + self, + subject="", + text="", + edit=None, + instruction_file_url="https://twiki.cern.ch/twiki/bin/view/LHCb/LHCbRun3RichMirrAlignShiftInfo", ): - host = 'logbook.lbdaq.cern.ch' + host = "logbook.lbdaq.cern.ch" port = 8080 - username = 'common Common\!' # used to be 'common Common\\!' but now works with only one escape + username = "common Common\!" # used to be 'common Common\\!' but now works with only one escape if self.testing: - logbook = 'TestLogbook' - systemName = 'System' - activity = 'Test' - author = 'Generic Elog Account' + logbook = "TestLogbook" + systemName = "System" + activity = "Test" + author = "Generic Elog Account" else: - logbook = 'RICH' - systemName = 'System_19' # Change 19 if Alignment changes its order in the ELOG (ask the current RICH expert) - activity = 'Alignment' - author = 'MirrAlign Monitor' # Or any other name + logbook = "RICH" + systemName = "System_19" # Change 19 if Alignment changes its order in the ELOG (ask the current RICH expert) + activity = "Alignment" + author = "MirrAlign Monitor" # Or any other name if instruction_file_url: text += f"\nShifter's instructions can be found at {instruction_file_url}." e_string = "" try: - e_string += ' -e ' + str(int(edit)) + e_string += " -e " + str(int(edit)) except: pass - #print(f"INFO: e_string failed") - - command = '' - command += (f'/group/online/bin/elog -h "{host}" -p {port}' - f'{e_string}' - f' -l "{logbook}" -u {username}' - f' -a "Author={author}"' - f' -a "{systemName}={activity}"' - f' -a "Subject={subject}"' - f' "{text}"') - #print(f'DEBUG: command = elog -h "logbook.lbdaq.cern.ch" -p 8080 -l "RICH" -u common Common\! -a "Author=MirrAlign Monitor" -a "System_19=Alignment" -a "Subject=TEST" "Testing the writing of logbook entries from the mirror alignment.\n RICH piquets should ignore all mirror alignments marked TEST in the subject heading.\n (Notes: common / System_19)"') - #print(f"DEBUG: command = {command}") + # print(f"INFO: e_string failed") + + command = "" + command += ( + f'/group/online/bin/elog -h "{host}" -p {port}' + f"{e_string}" + f' -l "{logbook}" -u {username}' + f' -a "Author={author}"' + f' -a "{systemName}={activity}"' + f' -a "Subject={subject}"' + f' "{text}"' + ) + # print(f'DEBUG: command = elog -h "logbook.lbdaq.cern.ch" -p 8080 -l "RICH" -u common Common\! -a "Author=MirrAlign Monitor" -a "System_19=Alignment" -a "Subject=TEST" "Testing the writing of logbook entries from the mirror alignment.\n RICH piquets should ignore all mirror alignments marked TEST in the subject heading.\n (Notes: common / System_19)"') + # print(f"DEBUG: command = {command}") cmd = shlex.split(command) try: env = os.environ.copy() - library_path = os.environ['LD_LIBRARY_PATH'] - env['LD_LIBRARY_PATH'] = f'{library_path}:/opt/nvidia/nsight-compute/2022.4.0/host/target-linux-x64/CollectX/' - elogret = subprocess.check_output( - cmd, stderr=subprocess.STDOUT, env=env) + library_path = os.environ["LD_LIBRARY_PATH"] + env["LD_LIBRARY_PATH"] = ( + f"{library_path}:/opt/nvidia/nsight-compute/2022.4.0/host/target-linux-x64/CollectX/" + ) + elogret = subprocess.check_output(cmd, stderr=subprocess.STDOUT, env=env) messageID_match = re.search( - r'.*Message successfully transmitted, ID=(\d*)', - elogret.decode()) + r".*Message successfully transmitted, ID=(\d*)", elogret.decode() + ) if messageID_match: messageID = int(messageID_match.group(1)) else: @@ -978,7 +1121,7 @@ class SetupHelper: except: messageID = None print(f"WARNING: Exception (quick write to RICH ELOG)") - ''' + """ # Alternative way p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=env) output = p.communicate()[0] @@ -988,7 +1131,7 @@ class SetupHelper: else: print("WARNING: Failed to extract message ID") messageID = None - ''' + """ print(f"INFO: messageID = {messageID} (quick write to RICH ELOG)") sys.stdout.flush() @@ -1000,25 +1143,39 @@ class SetupHelper: removeIt = (m_it - m_it % self.tiltNamesLength) / self.tiltNamesLength files = os.listdir(self.workdir) - re_fitFolders = re.compile(r"Rich" + str(self.whichRich) + - "MirrCombinFit_" + self.nameStr + - "[\w\.]*_i" + str(removeIt)) - re_alignFiles = re.compile(r"Rich" + str(self.whichRich) + - "MirrAlign[a-zA-z]*_i" + str(removeIt) + - "\.txt") + re_fitFolders = re.compile( + r"Rich" + + str(self.whichRich) + + "MirrCombinFit_" + + self.nameStr + + "[\w\.]*_i" + + str(removeIt) + ) + re_alignFiles = re.compile( + r"Rich" + + str(self.whichRich) + + "MirrAlign[a-zA-z]*_i" + + str(removeIt) + + "\.txt" + ) fitFolders = [x for x in files if re_fitFolders.match(x)] alignFiles = [x for x in files if re_alignFiles.match(x)] - if (m_it % self.tiltNamesLength == 0): + if m_it % self.tiltNamesLength == 0: connectStr = "" else: connectStr = "_" yaml = YAML() - with open(self.workdir + 'rich' + str(self.whichRich) + - '_variant.yml') as finp: + with open(self.workdir + "rich" + str(self.whichRich) + "_variant.yml") as finp: variant = yaml.load(finp) - rootFile = variant + "_histos_" + self.tiltNames[ - m_it % self.tiltNamesLength] + "_i" + str(removeIt) + ".root" # + rootFile = ( + variant + + "_histos_" + + self.tiltNames[m_it % self.tiltNamesLength] + + "_i" + + str(removeIt) + + ".root" + ) # for f in fitFolders: print("INFO: Removing " + self.workdir + f) @@ -1030,64 +1187,78 @@ class SetupHelper: print("INFO: Removing " + self.workdir + rootFile) os.remove(self.workdir + rootFile) - def old_writeInLogbook(self, - vN_DB_str, - conv, - n_it, - farm_config_time, - alignment_time, - summaryFile, - ChangeWRTDBFile, - AlignSummaryFile, - AlignMonitorFile, - AlignTrendFile_Fills_hollow, - DBUpdated, - nEvents, - edit, - flat=False): + def old_writeInLogbook( + self, + vN_DB_str, + conv, + n_it, + farm_config_time, + alignment_time, + summaryFile, + ChangeWRTDBFile, + AlignSummaryFile, + AlignMonitorFile, + AlignTrendFile_Fills_hollow, + DBUpdated, + nEvents, + edit, + flat=False, + ): hh, r = divmod(farm_config_time, 3600) mm, ss = divmod(r, 60) - farm_config_time_str = "{:0>2}:{:0>2}:{:05.2f}".format( - int(hh), int(mm), ss) + farm_config_time_str = "{:0>2}:{:0>2}:{:05.2f}".format(int(hh), int(mm), ss) hh, r = divmod(alignment_time, 3600) mm, ss = divmod(r, 60) - alignment_time_str = "{:0>2}:{:0>2}:{:05.2f}".format( - int(hh), int(mm), ss) + alignment_time_str = "{:0>2}:{:0>2}:{:05.2f}".format(int(hh), int(mm), ss) if flat is False: - #import OnlineEnv as Online - #FillAlignment = self.getFillNumber(Online.DeferredRuns[0]) + # import OnlineEnv as Online + # FillAlignment = self.getFillNumber(Online.DeferredRuns[0]) FillAlignment = 0 # PN: temporary pass else: FillAlignment = 0 # RICH ELOG - host = 'logbook.lbdaq.cern.ch' + host = "logbook.lbdaq.cern.ch" port = 8080 - username = 'common Common\\!' - logbook = 'RICH' - author = 'MirrAlign Monitor' # Or any other name - activity = 'Alignment' - subject = '' - text = '' - instruction_file = 'https://twiki.cern.ch/twiki/bin/view/LHCb/LHCbRun3RichMirrAlignShiftInfo' - subjText = '' + username = "common Common\\!" + logbook = "RICH" + author = "MirrAlign Monitor" # Or any other name + activity = "Alignment" + subject = "" + text = "" + instruction_file = ( + "https://twiki.cern.ch/twiki/bin/view/LHCb/LHCbRun3RichMirrAlignShiftInfo" + ) + subjText = "" if DBUpdated: - subjText += ' updated,' - elif self.testing and DBUpdated is None: # if testing is on, regardless of autoUpdate setting - subjText += ' not updated due to testing = True,' - elif DBUpdated is None and self.autoUpdate is False: # testing and autoUpdate were off to begin with - subjText += ' not updated due to autoUpdate = False, needs MirrAlign expert decision,' - elif DBUpdated is None and self.autoUpdateNoV is True: # testing off, but autoUpdate was on at the start, then switched off - subjText += ' not updated due to sanity check issue, needs MirrAlign expert decision,' - elif DBUpdated is None and self.autoUpdateNoV is False: # testing off, but autoUpdate was on at the start, then switched off - subjText += ' not updated due to sanity check issue,' # existing version was provided + subjText += " updated," + elif ( + self.testing and DBUpdated is None + ): # if testing is on, regardless of autoUpdate setting + subjText += " not updated due to testing = True," + elif ( + DBUpdated is None and self.autoUpdate is False + ): # testing and autoUpdate were off to begin with + subjText += " not updated due to autoUpdate = False, needs MirrAlign expert decision," + elif ( + DBUpdated is None and self.autoUpdateNoV is True + ): # testing off, but autoUpdate was on at the start, then switched off + subjText += " not updated due to sanity check issue, needs MirrAlign expert decision," + elif ( + DBUpdated is None and self.autoUpdateNoV is False + ): # testing off, but autoUpdate was on at the start, then switched off + subjText += " not updated due to sanity check issue," # existing version was provided else: - subjText += '' + subjText += "" if self.testing: - subject += 'TEST [' + self.dataVariant + ']: ' - text += 'TEST [' + self.dataVariant + ']: This is a test alignment being run by a mirror alignment expert; RICH piquets may ignore it. \n' + subject += "TEST [" + self.dataVariant + "]: " + text += ( + "TEST [" + + self.dataVariant + + "]: This is a test alignment being run by a mirror alignment expert; RICH piquets may ignore it. \n" + ) text += "The Mirror " text += str(activity) text += " for RICH" @@ -1098,18 +1269,28 @@ class SetupHelper: text += " (excluding an LHCbA configuration time of " text += farm_config_time_str text += ") and converged. " - subject += 'RICH' + str( - self.whichRich - ) + ' alignment ' + self.directoryTime + subjText + ' converged' + subject += ( + "RICH" + + str(self.whichRich) + + " alignment " + + self.directoryTime + + subjText + + " converged" + ) else: text += " ran for " text += alignment_time_str text += " (excluding an LHCbA configuration time of " text += farm_config_time_str text += ") and did not converge. " - subject += 'RICH' + str( - self.whichRich - ) + ' alignment ' + self.directoryTime + subjText + ' incomplete' + subject += ( + "RICH" + + str(self.whichRich) + + " alignment " + + self.directoryTime + + subjText + + " incomplete" + ) text += "We processed approximately " text += str(nEvents) text += " events per iteration from the RICH" @@ -1124,17 +1305,27 @@ class SetupHelper: text += self.directoryTime text += "." if DBUpdated is None: - text += " There was a significant change from the alignment in the DB, or a change in magnet polarity." \ - + "However, the final state of autoUpdate was set to False (even if the initial state of autoUpdate was True), " \ - + "or the alignment is in testing mode, so the DB was not updated. " \ - + "If the automatic update feature was disabled, a sanity check was not satisfied. " \ - + "Please notify a MirrAlign expert to investigate whether this alignment (" + vN_DB_str + ") should be installed." + text += ( + " There was a significant change from the alignment in the DB, or a change in magnet polarity." + + "However, the final state of autoUpdate was set to False (even if the initial state of autoUpdate was True), " + + "or the alignment is in testing mode, so the DB was not updated. " + + "If the automatic update feature was disabled, a sanity check was not satisfied. " + + "Please notify a MirrAlign expert to investigate whether this alignment (" + + vN_DB_str + + ") should be installed." + ) # We should maybe provide more info here if self.autoUpdate and self.autoUpdateNoV: - text += " Please note: autoUpdate was initially True, and autoUpdateNoV was set to True. " \ - + "This means that an alignment version has NOT been provided to HLT2." + text += ( + " Please note: autoUpdate was initially True, and autoUpdateNoV was set to True. " + + "This means that an alignment version has NOT been provided to HLT2." + ) elif DBUpdated: - text += " Due to a significant change from the alignment in the DB, or a change in magnet polarity, the DB was automatically updated to " + vN_DB_str + "." # We should probably provide more info here + text += ( + " Due to a significant change from the alignment in the DB, or a change in magnet polarity, the DB was automatically updated to " + + vN_DB_str + + "." + ) # We should probably provide more info here else: text += " The alignment in the DB is still " + vN_DB_str + "." if not self.autoUpdate: @@ -1144,7 +1335,7 @@ class SetupHelper: command += '" -p ' command += str(port) try: - command += ' -e ' + str(int(edit)) + command += " -e " + str(int(edit)) except: pass command += ' -l "' @@ -1153,7 +1344,7 @@ class SetupHelper: command += str(username) command += ' -a "Author=' command += str(author) - #command += '" -a "System=' + # command += '" -a "System=' command += '" -a "System_19=' # Change 19 if Alignment changes its order in the ELOG (ask the current RICH expert) command += str(activity) command += '" -a "Subject=' @@ -1174,54 +1365,73 @@ class SetupHelper: try: elogret = subprocess.check_output(cmd, stderr=subprocess.STDOUT) messageID = int( - re.search('.*Message successfully transmitted, ID=(\d*)', - elogret).groups()[0]) + re.search( + ".*Message successfully transmitted, ID=(\d*)", elogret + ).groups()[0] + ) print(f"INFO: messageID = {messageID}") except: messageID = None # Alignment ELOG - logbookAlignment = 'Alignment monitoring' # always - authorAlignment = 'monibot' # always - activityAlignment = 'Rich' + str(self.whichRich) + ' Mirrors' # always - TypeAlignment = 'Convergence' # always - #subjectAlignment = 'IGNORE-- ' - #textAlignment = 'Please Ignore: \n ' - subjectAlignment = '' - textAlignment = '' - StatusAlignment = 'Good' # or can be changed below to 'Unchecked' or 'Bad' (for now 'Bad' never happens) + logbookAlignment = "Alignment monitoring" # always + authorAlignment = "monibot" # always + activityAlignment = "Rich" + str(self.whichRich) + " Mirrors" # always + TypeAlignment = "Convergence" # always + # subjectAlignment = 'IGNORE-- ' + # textAlignment = 'Please Ignore: \n ' + subjectAlignment = "" + textAlignment = "" + StatusAlignment = "Good" # or can be changed below to 'Unchecked' or 'Bad' (for now 'Bad' never happens) if self.testing: - subjectAlignment += 'TEST [' + self.dataVariant + ']: ' - textAlignment += 'A test mirror alignment for Rich' + str( - self.whichRich - ) + ' was performed for fill ' + str( - FillAlignment - ) + " by a RICH mirror alignment expert. No action is necessary; ignore the following. \n " + subjectAlignment += "TEST [" + self.dataVariant + "]: " + textAlignment += ( + "A test mirror alignment for Rich" + + str(self.whichRich) + + " was performed for fill " + + str(FillAlignment) + + " by a RICH mirror alignment expert. No action is necessary; ignore the following. \n " + ) if DBUpdated is None: - subjectAlignment += 'No alignment update-- Needs MirrAlign expert decision' - textAlignment += 'Rich' + str( - self.whichRich - ) + ' mirror alignment for fill ' + str( - FillAlignment - ) + " is requesting an update be made, but for some reason this was not done automatically. Please ask the Rich Mirror Alignment experts to investigate the draft alignment (" + vN_DB_str + "). Monitoring plots in the attachment; shifter's instructions can be found at: " + instruction_file - StatusAlignment = 'Unchecked' + subjectAlignment += "No alignment update-- Needs MirrAlign expert decision" + textAlignment += ( + "Rich" + + str(self.whichRich) + + " mirror alignment for fill " + + str(FillAlignment) + + " is requesting an update be made, but for some reason this was not done automatically. Please ask the Rich Mirror Alignment experts to investigate the draft alignment (" + + vN_DB_str + + "). Monitoring plots in the attachment; shifter's instructions can be found at: " + + instruction_file + ) + StatusAlignment = "Unchecked" elif DBUpdated: - subjectAlignment += 'Monitoring plots' - textAlignment += 'Updated Rich' + str( - self.whichRich - ) + ' mirror alignment for fill ' + str( - FillAlignment - ) + " (" + vN_DB_str + "), monitoring plots in the attachment; shifter's instructions can be found at: " + instruction_file - StatusAlignment = 'Unchecked' + subjectAlignment += "Monitoring plots" + textAlignment += ( + "Updated Rich" + + str(self.whichRich) + + " mirror alignment for fill " + + str(FillAlignment) + + " (" + + vN_DB_str + + "), monitoring plots in the attachment; shifter's instructions can be found at: " + + instruction_file + ) + StatusAlignment = "Unchecked" else: - subjectAlignment += 'No alignment update' - textAlignment += 'No Rich' + str( - self.whichRich) + ' alignment update needed for fill ' + str( - FillAlignment - ) + '. The DB alignment is still ' + vN_DB_str + '.' + subjectAlignment += "No alignment update" + textAlignment += ( + "No Rich" + + str(self.whichRich) + + " alignment update needed for fill " + + str(FillAlignment) + + ". The DB alignment is still " + + vN_DB_str + + "." + ) if self.testing: - StatusAlignment = 'Test' + StatusAlignment = "Test" command = '/group/online/bin/elog -h "' command += str(host) @@ -1252,13 +1462,13 @@ class SetupHelper: command += ' -f "{0}"'.format(AlignMonitorFile) cmd = shlex.split(command) if self.autoUpdate: # If we are not in autoUpdate mode, then we do not post to the Alignment Monitoring ELOG - FNULL = open(os.devnull, 'w') + FNULL = open(os.devnull, "w") subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT) # Email - subj2 = '' + subj2 = "" if self.testing: - subj2 += 'TEST [' + self.dataVariant + ']: ' + subj2 += "TEST [" + self.dataVariant + "]: " text2 = "The Mirror " text2 += str(activity) text2 += " for RICH" @@ -1267,188 +1477,246 @@ class SetupHelper: text2 += " ran for " text2 += alignment_time_str text2 += " and converged. " - subj2 += 'RICH{0} alignment {1} converged: New ELOG entry'.format( - self.whichRich, self.directoryTime) + subj2 += "RICH{0} alignment {1} converged: New ELOG entry".format( + self.whichRich, self.directoryTime + ) else: text2 += " ran for " text2 += alignment_time_str text2 += " and did not converge. Approximately " - subj2 += 'RICH{0} alignment {1} incomplete: New ELOG entry'.format( - self.whichRich, self.directoryTime) + subj2 += "RICH{0} alignment {1} incomplete: New ELOG entry".format( + self.whichRich, self.directoryTime + ) text2 += str(nEvents) text2 += " events per iteration were processed. " text2 += str(n_it + 1) text2 += " iteration(s) occured. \n" if DBUpdated is None: - text2 += "\n There was a significant change from the alignment in the DB, or a change in magnet polarity. However the automatic update feature is off or was disabled during the alignment (The final state of autoUpdate was set to False), so the DB was not updated. If the automatic update feature was disabled, there may not have been enough events processed, or a sanity check was not satisfied. A MirrAlign expert should investigate whether this draft alignment (" + vN_DB_str + ") should be installed. \n" # We should probably provide more info here + text2 += ( + "\n There was a significant change from the alignment in the DB, or a change in magnet polarity. However the automatic update feature is off or was disabled during the alignment (The final state of autoUpdate was set to False), so the DB was not updated. If the automatic update feature was disabled, there may not have been enough events processed, or a sanity check was not satisfied. A MirrAlign expert should investigate whether this draft alignment (" + + vN_DB_str + + ") should be installed. \n" + ) # We should probably provide more info here elif DBUpdated: - text2 += "\n Due to a significant change from the alignment in the DB, or a change in magnet polarity, the DB was automatically updated to " + vN_DB_str + ". \n" # We should probably provide more info here + text2 += ( + "\n Due to a significant change from the alignment in the DB, or a change in magnet polarity, the DB was automatically updated to " + + vN_DB_str + + ". \n" + ) # We should probably provide more info here else: text2 += "\n The alignment in the DB is still " + vN_DB_str + "." text2 += "\n More information is available at the following links: \n\n " - text2 += 'https://lblogbook.cern.ch/RICH/?System=%5EAlignment%24&Subject={0}&mode=full'.format( - self.directoryTime) - text2 += '\n https://lbrich.cern.ch/alignmentview.php' - text2 += '\n https://lbrich.cern.ch/plot/index.html?rich=' + str( - self.whichRich) + '&source=mirror' + text2 += "https://lblogbook.cern.ch/RICH/?System=%5EAlignment%24&Subject={0}&mode=full".format( + self.directoryTime + ) + text2 += "\n https://lbrich.cern.ch/alignmentview.php" + text2 += ( + "\n https://lbrich.cern.ch/plot/index.html?rich=" + + str(self.whichRich) + + "&source=mirror" + ) - text2 += "\n\n Fill number of first run processed: " + str( - FillAlignment) + text2 += "\n\n Fill number of first run processed: " + str(FillAlignment) if not self.autoUpdate: text2 += " \n\n The initial state of autoUpdate was set to False in the configuration." - self.sendEmail(subj2, text2, - self.emails if not self.testing else self.experts) + self.sendEmail(subj2, text2, self.emails if not self.testing else self.experts) sys.stdout.flush() return messageID - def old_writeSummary(self, - vN_DB_str, - conv, - n_it, - farm_config_time, - elapsed_runtimes, - summaryFile, - DBUpdated, - nEvents, - nEventsList, - flat=False): + def old_writeSummary( + self, + vN_DB_str, + conv, + n_it, + farm_config_time, + elapsed_runtimes, + summaryFile, + DBUpdated, + nEvents, + nEventsList, + flat=False, + ): hh, r = divmod(farm_config_time, 3600) mm, ss = divmod(r, 60) - farm_config_time_str = "{:0>2}:{:0>2}:{:05.2f}".format( - int(hh), int(mm), ss) - hh, r = divmod(elapsed_runtimes['elapsed_time_run'], 3600) + farm_config_time_str = "{:0>2}:{:0>2}:{:05.2f}".format(int(hh), int(mm), ss) + hh, r = divmod(elapsed_runtimes["elapsed_time_run"], 3600) mm, ss = divmod(r, 60) - alignment_time_str = "{:0>2}:{:0>2}:{:05.2f}".format( - int(hh), int(mm), ss) + alignment_time_str = "{:0>2}:{:0>2}:{:05.2f}".format(int(hh), int(mm), ss) MirrCombinFit_time_str = str( - elapsed_runtimes['elapsed_times_RichMirrCombinFit']) - MirrAlign_time_str = str( - elapsed_runtimes['elapsed_times_RichMirrAlign']) + elapsed_runtimes["elapsed_times_RichMirrCombinFit"] + ) + MirrAlign_time_str = str(elapsed_runtimes["elapsed_times_RichMirrAlign"]) if flat is False: - #import OnlineEnv as Online - #runs = Online.DeferredRuns + # import OnlineEnv as Online + # runs = Online.DeferredRuns runs = [] # PN: Temporary pass else: runs = [] - runsString = '' - fillsString = '' - polaritiesString = '' + runsString = "" + fillsString = "" + polaritiesString = "" for i in range(0, len(runs)): - runsString += str(runs[i]) + ' ' + runsString += str(runs[i]) + " " fill = self.getFillNumber(runs[i]) if fill is not None: - fillsString += ' ' + str(fill) + ' ' + fillsString += " " + str(fill) + " " else: - fillsString += ' ???? ' + fillsString += " ???? " polarity = self.getPolarity(runs[i]) - if polarity == 'UP': - polaritiesString += ' UP ' - elif polarity == 'DOWN': - polaritiesString += ' DOWN ' - elif polarity == 'OFF': - polaritiesString += ' OFF ' - else: #something went wrong - polaritiesString += ' ???? ' + if polarity == "UP": + polaritiesString += " UP " + elif polarity == "DOWN": + polaritiesString += " DOWN " + elif polarity == "OFF": + polaritiesString += " OFF " + else: # something went wrong + polaritiesString += " ???? " if os.path.exists(summaryFile): print(f"INFO: Removing existing {summaryFile}") os.remove(summaryFile) - f = open(summaryFile, 'w') - args = '' - args += 'richDetector = ' + str(self.whichRich) + '\n' - args += 'DB updated = ' + str(DBUpdated) + '\n' + f = open(summaryFile, "w") + args = "" + args += "richDetector = " + str(self.whichRich) + "\n" + args += "DB updated = " + str(DBUpdated) + "\n" if DBUpdated is None: - args += ' (Alignment changed, but autoUpdate started as False or was disabled) \n' - args += 'resulting DB = ' + vN_DB_str + '\n' - args += 'converged = ' + str(conv) + '\n' - args += 'Number of iterations = ' + str(n_it + 1) + '\n' - args += 'Final iteration label = ' + '_i' + str(n_it) + '\n' - args += 'Number of events = ' + str(nEvents) + '\n' - args += 'runs = ' + runsString + '\n' - args += 'fills = ' + fillsString + '\n' - args += 'polarities = ' + polaritiesString + '\n' - args += 'dataVariant = ' + str(self.dataVariant) + '\n' - args += 'savedir = ' + self.savedir + '\n' - args += 'magnFactorsMode = ' + str(self.magnFactorsMode) + '\n' - args += 'magnifDir = ' + str(self.magnifDir) + '\n' - args += 'XML_YAML_configDir = ' + str( - self.XML_YAML_configDir) + '\n' - #args += 'combAndMirrSubsets = ' + str( + args += " (Alignment changed, but autoUpdate started as False or was disabled) \n" + args += "resulting DB = " + vN_DB_str + "\n" + args += "converged = " + str(conv) + "\n" + args += "Number of iterations = " + str(n_it + 1) + "\n" + args += "Final iteration label = " + "_i" + str(n_it) + "\n" + args += "Number of events = " + str(nEvents) + "\n" + args += "runs = " + runsString + "\n" + args += "fills = " + fillsString + "\n" + args += "polarities = " + polaritiesString + "\n" + args += "dataVariant = " + str(self.dataVariant) + "\n" + args += "savedir = " + self.savedir + "\n" + args += "magnFactorsMode = " + str(self.magnFactorsMode) + "\n" + args += "magnifDir = " + str(self.magnifDir) + "\n" + args += "XML_YAML_configDir = " + str(self.XML_YAML_configDir) + "\n" + # args += 'combAndMirrSubsets = ' + str( # self.combAndMirrSubsets) + '\n' print("INFO: LHCbA config time (readable): " + farm_config_time_str) # print("INFO: Note, the LHCbA config time may be inaccurate if the alignment is run manually with LHCbA AutoPilot OFF.") - args += 'LHCbA config time = ' + farm_config_time_str + '\n' + args += "LHCbA config time = " + farm_config_time_str + "\n" print("INFO: Alignment time (readable): " + alignment_time_str) - args += 'Alignment time = ' + alignment_time_str + '\n' + args += "Alignment time = " + alignment_time_str + "\n" finalCKres = math.ceil(self.finalCKres * 10000) / 10000 finalCKresErr = math.ceil(self.finalCKresErr * 10000) / 10000 - args += 'CK angle resolution = ' + str(finalCKres) + '\n' - args += ' error = ' + str(finalCKresErr) + '\n' - args += 'startXMLFile = ' + str( - self.alignConf.getProp('startXMLFile')) + '\n' - args += 'compareXMLFile = ' + str( - self.alignConf.getProp('compareXMLFile')) + '\n' - args += 'startYAMLFile = ' + str( - self.alignConf.getProp('startYAMLFile')) + '\n' - args += 'compareYAMLFile = ' + str( - self.alignConf.getProp('compareYAMLFile')) + '\n' - args += 'YAMLio = ' + str(self.YAMLio) + '\n' - args += 'useDD4Hep = ' + str(self.useDD4hep) + '\n' - args += '\n' - args += 'autoUpdate (initial) = ' + str(self.autoUpdate) + '\n' - args += 'autoUpdateNoV = ' + str(self.autoUpdateNoV) + '\n' - args += 'testing = ' + str(self.testing) + '\n' - args += 'requiredEvents = ' + str( - self.alignConf.getProp('requiredEvents')) + '\n' - args += 'minAverageBinPop = ' + str( - self.minAverageBinPop) + '\n' - args += 'phiBinFactor = ' + str(self.phiBinFactor) + '\n' - args += 'minFracPhiBinsPopulated = ' + str( - self.minFracPhiBinsPopulated) + '\n' - args += 'deltaThetaWindow = ' + str( - self.deltaThetaWindow) + '\n' - args += 'combinFitMethod = ' + str(self.combinFitMethod) + '\n' - args += 'solutionMethod = ' + str(self.solutionMethod) + '\n' - args += 'coeffCalibTilt = ' + str(self.coeffCalibTilt) + '\n' - args += 'fixSinusoidShift = ' + str( - self.fixSinusoidShift) + '\n' - args += 'maxIterations = ' + str( - self.alignConf.getProp('maxIterations')) + '\n' - args += 'useHltDecisions = ' + str( - self.alignConf.getProp('useHltDecisions')) + '\n' - args += 'usingReducedSubset = ' + str( - self.usingReducedSubset) + '\n' - args += 'EvtMax = ' + str( - self.alignConf.getProp('EvtMax')) + '\n' - args += 'regularizationMode = ' + str( - self.alignConf.getProp('regularizationMode')) + '\n' - args += 'stopDecisionMode = ' + str( - self.alignConf.getProp('stopDecisionMode')) + '\n' - args += 'stopToleranceMode = ' + str( - self.alignConf.getProp('stopToleranceMode')) + '\n' - args += 'nominalResolutionSigma = ' + str( - self.alignConf.getProp('nominalResolutionSigma')) + '\n' - args += 'stopSigmaFraction = ' + str( - self.alignConf.getProp('stopSigmaFraction')) + '\n' - args += 'warningFactor = ' + str( - self.alignConf.getProp('warningFactor')) + '\n' - args += 'stopTolerancePriY = ' + str( - self.alignConf.getProp('stopTolerancePriY')) + '\n' - args += 'stopTolerancePriZ = ' + str( - self.alignConf.getProp('stopTolerancePriZ')) + '\n' - args += 'stopToleranceSecY = ' + str( - self.alignConf.getProp('stopToleranceSecY')) + '\n' - args += 'stopToleranceSecZ = ' + str( - self.alignConf.getProp('stopToleranceSecZ')) + '\n' - args += 'nEventsList = ' + str(nEventsList) + '\n' - args += 'CombinFit times = ' + MirrCombinFit_time_str + '\n' - args += 'MirrAlign times = ' + MirrAlign_time_str + '\n' + args += "CK angle resolution = " + str(finalCKres) + "\n" + args += " error = " + str(finalCKresErr) + "\n" + args += ( + "startXMLFile = " + + str(self.alignConf.getProp("startXMLFile")) + + "\n" + ) + args += ( + "compareXMLFile = " + + str(self.alignConf.getProp("compareXMLFile")) + + "\n" + ) + args += ( + "startYAMLFile = " + + str(self.alignConf.getProp("startYAMLFile")) + + "\n" + ) + args += ( + "compareYAMLFile = " + + str(self.alignConf.getProp("compareYAMLFile")) + + "\n" + ) + args += "YAMLio = " + str(self.YAMLio) + "\n" + args += "useDD4Hep = " + str(self.useDD4hep) + "\n" + args += "\n" + args += "autoUpdate (initial) = " + str(self.autoUpdate) + "\n" + args += "autoUpdateNoV = " + str(self.autoUpdateNoV) + "\n" + args += "testing = " + str(self.testing) + "\n" + args += ( + "requiredEvents = " + + str(self.alignConf.getProp("requiredEvents")) + + "\n" + ) + args += "minAverageBinPop = " + str(self.minAverageBinPop) + "\n" + args += "phiBinFactor = " + str(self.phiBinFactor) + "\n" + args += "minFracPhiBinsPopulated = " + str(self.minFracPhiBinsPopulated) + "\n" + args += "deltaThetaWindow = " + str(self.deltaThetaWindow) + "\n" + args += "combinFitMethod = " + str(self.combinFitMethod) + "\n" + args += "solutionMethod = " + str(self.solutionMethod) + "\n" + args += "coeffCalibTilt = " + str(self.coeffCalibTilt) + "\n" + args += "fixSinusoidShift = " + str(self.fixSinusoidShift) + "\n" + args += ( + "maxIterations = " + + str(self.alignConf.getProp("maxIterations")) + + "\n" + ) + args += ( + "useHltDecisions = " + + str(self.alignConf.getProp("useHltDecisions")) + + "\n" + ) + args += "usingReducedSubset = " + str(self.usingReducedSubset) + "\n" + args += ( + "EvtMax = " + str(self.alignConf.getProp("EvtMax")) + "\n" + ) + args += ( + "regularizationMode = " + + str(self.alignConf.getProp("regularizationMode")) + + "\n" + ) + args += ( + "stopDecisionMode = " + + str(self.alignConf.getProp("stopDecisionMode")) + + "\n" + ) + args += ( + "stopToleranceMode = " + + str(self.alignConf.getProp("stopToleranceMode")) + + "\n" + ) + args += ( + "nominalResolutionSigma = " + + str(self.alignConf.getProp("nominalResolutionSigma")) + + "\n" + ) + args += ( + "stopSigmaFraction = " + + str(self.alignConf.getProp("stopSigmaFraction")) + + "\n" + ) + args += ( + "warningFactor = " + + str(self.alignConf.getProp("warningFactor")) + + "\n" + ) + args += ( + "stopTolerancePriY = " + + str(self.alignConf.getProp("stopTolerancePriY")) + + "\n" + ) + args += ( + "stopTolerancePriZ = " + + str(self.alignConf.getProp("stopTolerancePriZ")) + + "\n" + ) + args += ( + "stopToleranceSecY = " + + str(self.alignConf.getProp("stopToleranceSecY")) + + "\n" + ) + args += ( + "stopToleranceSecZ = " + + str(self.alignConf.getProp("stopToleranceSecZ")) + + "\n" + ) + args += "nEventsList = " + str(nEventsList) + "\n" + args += "CombinFit times = " + MirrCombinFit_time_str + "\n" + args += "MirrAlign times = " + MirrAlign_time_str + "\n" # not provided yet (not sure if there is need): # MajItStart and MinItStart # WorkDir, ItNrFile, thisCase, tiltNames, and original SaveDir in configuration @@ -1457,13 +1725,19 @@ class SetupHelper: f.close() sys.stdout.flush() - CKresTrendFile = "/group/rich/AlignmentFiles/Logging/Rich" + str( - self.whichRich) + "_CKresTrend.txt" - UpdateTrendFile = "/group/rich/AlignmentFiles/Logging/Rich" + str( - self.whichRich) + "_UpdateTrend.txt" + CKresTrendFile = ( + "/group/rich/AlignmentFiles/Logging/Rich" + + str(self.whichRich) + + "_CKresTrend.txt" + ) + UpdateTrendFile = ( + "/group/rich/AlignmentFiles/Logging/Rich" + + str(self.whichRich) + + "_UpdateTrend.txt" + ) if flat is False: - #firstFill = self.getFillNumber(runs[0]) + # firstFill = self.getFillNumber(runs[0]) firstFill = None # PN: temporary firstPolarity = None # PN: temporary firstCollisionInfo = None # PN: temporary @@ -1473,82 +1747,121 @@ class SetupHelper: firstPolarity = None firstCollisionInfo = None if firstFill is not None: - firstFill_str = '' + str(firstFill) + '' + firstFill_str = "" + str(firstFill) + "" else: - firstFill_str = '????' + firstFill_str = "????" if firstFill is not None: firstPolarity = self.getPolarity(runs[0]) - if firstPolarity == 'UP': - firstPolarity_str = ' UP' - elif firstPolarity == 'DOWN': - firstPolarity_str = 'DOWN' - elif firstPolarity == 'OFF': - firstPolarity_str = ' OFF' - else: #something went wrong - firstPolarity_str = '????' + if firstPolarity == "UP": + firstPolarity_str = " UP" + elif firstPolarity == "DOWN": + firstPolarity_str = "DOWN" + elif firstPolarity == "OFF": + firstPolarity_str = " OFF" + else: # something went wrong + firstPolarity_str = "????" if firstFill is not None: firstCollisionInfo = self.getCollisionInfo(runs[0]) if firstCollisionInfo is not None: - firstCollisionInfo_str = '' + str(firstCollisionInfo) + '' + firstCollisionInfo_str = "" + str(firstCollisionInfo) + "" else: - firstCollisionInfo_str = '????' + firstCollisionInfo_str = "????" if not self.testing: with open(CKresTrendFile, "a") as myfile: - myfile.write(firstFill_str + " " + - (self.directoryTime).replace("_", "T") + " " + - str(self.finalCKres / 1000) + " " + - str(self.finalCKresErr / 1000) + '\n') + myfile.write( + firstFill_str + + " " + + (self.directoryTime).replace("_", "T") + + " " + + str(self.finalCKres / 1000) + + " " + + str(self.finalCKresErr / 1000) + + "\n" + ) with open(UpdateTrendFile, "a") as myfile: - myfile.write(firstFill_str + "\t" + self.directoryTime + "\t" + - vN_DB_str + "\t" + firstPolarity_str + "\t" + - firstCollisionInfo_str + '\n') + myfile.write( + firstFill_str + + "\t" + + self.directoryTime + + "\t" + + vN_DB_str + + "\t" + + firstPolarity_str + + "\t" + + firstCollisionInfo_str + + "\n" + ) if "maybe" in vN_DB_str: maybeSubj = "A _maybe version has been produced by the mirror alignment" - maybeText = "A _maybe version has been produced by the mirror alignment. \n As you address this, also make sure to update the entry in /group/rich/AlignmentFiles/Logging/Rich" + str( - self.whichRich - ) + "_UpdateTrend.txt, with the result (i.e. a proper vN, or the existing vN). Also you may wish to comment out the relevant line in /group/rich/AlignmentFiles/Logging/Rich" + str( - self.whichRich - ) + "_CKresTrend.txt if you do not wish it to appear in the CK angle resolution trend plot; you could also copy the previous line's resolution, or just leave it if it is not a fluctuation." + maybeText = ( + "A _maybe version has been produced by the mirror alignment. \n As you address this, also make sure to update the entry in /group/rich/AlignmentFiles/Logging/Rich" + + str(self.whichRich) + + "_UpdateTrend.txt, with the result (i.e. a proper vN, or the existing vN). Also you may wish to comment out the relevant line in /group/rich/AlignmentFiles/Logging/Rich" + + str(self.whichRich) + + "_CKresTrend.txt if you do not wish it to appear in the CK angle resolution trend plot; you could also copy the previous line's resolution, or just leave it if it is not a fluctuation." + ) self.sendEmail(maybeSubj, maybeText, self.emails) else: with open(CKresTrendFile, "a") as myfile: - myfile.write("# TEST " + firstFill_str + " " + - (self.directoryTime).replace("_", "T") + " " + - str(self.finalCKres / 1000) + " " + - str(self.finalCKresErr / 1000) + '\n') + myfile.write( + "# TEST " + + firstFill_str + + " " + + (self.directoryTime).replace("_", "T") + + " " + + str(self.finalCKres / 1000) + + " " + + str(self.finalCKresErr / 1000) + + "\n" + ) with open(UpdateTrendFile, "a") as myfile: - myfile.write("# TEST " + firstFill_str + "\t" + - self.directoryTime + "\t" + vN_DB_str + "\t" + - firstPolarity_str + "\t" + - firstCollisionInfo_str + '\n') + myfile.write( + "# TEST " + + firstFill_str + + "\t" + + self.directoryTime + + "\t" + + vN_DB_str + + "\t" + + firstPolarity_str + + "\t" + + firstCollisionInfo_str + + "\n" + ) if "testing_maybe" in vN_DB_str: - maybeSubj = "A _testing_maybe version has been produced by the mirror alignment" - maybeText = "A _testing_maybe version has been produced by the mirror alignment. \n If you choose to use this alignment for this fill(s), make sure as you address this to update the entry in /group/rich/AlignmentFiles/Logging/Rich" + str( - self.whichRich - ) + "_UpdateTrend.txt, with the result (i.e. a proper vN). Also uncomment the '# TEST ' part of the relevant line in /group/rich/AlignmentFiles/Logging/Rich" + str( - self.whichRich) + "_CKresTrend.txt please." + maybeSubj = ( + "A _testing_maybe version has been produced by the mirror alignment" + ) + maybeText = ( + "A _testing_maybe version has been produced by the mirror alignment. \n If you choose to use this alignment for this fill(s), make sure as you address this to update the entry in /group/rich/AlignmentFiles/Logging/Rich" + + str(self.whichRich) + + "_UpdateTrend.txt, with the result (i.e. a proper vN). Also uncomment the '# TEST ' part of the relevant line in /group/rich/AlignmentFiles/Logging/Rich" + + str(self.whichRich) + + "_CKresTrend.txt please." + ) self.sendEmail(maybeSubj, maybeText, self.experts) def old_sendEmail(self, subject, text, receiversList): import smtplib - sender = 'lhcb-rich-mirror-alignment-development@cern.ch' - message = 'From: MirrAlign Monitor <' + + sender = "lhcb-rich-mirror-alignment-development@cern.ch" + message = "From: MirrAlign Monitor <" message += sender - message += '>\n' - message += 'To:' + message += ">\n" + message += "To:" for ie in receiversList: - message += ' <' + message += " <" message += ie - message += '>,' + message += ">," message = message[:-1] - message += '\n' - message += 'Subject: ' + message += "\n" + message += "Subject: " message += subject - message += '\n\n' - message += '\n{0}\n\n'.format(text) + message += "\n\n" + message += "\n{0}\n\n".format(text) try: - smtpObj = smtplib.SMTP('localhost') + smtpObj = smtplib.SMTP("localhost") smtpObj.sendmail(sender, receiversList, message) print("INFO: Successfully sent email") except smtplib.SMTPException: @@ -1560,7 +1873,7 @@ class SetupHelper: if not response: return None try: - fill = response['fillid'] + fill = response["fillid"] except KeyError: # Fill ID not included in JSON response return None @@ -1573,7 +1886,7 @@ class SetupHelper: if not response: return None try: - polarity = response['magnetState'] + polarity = response["magnetState"] except KeyError: # Polarity not included in JSON response return None @@ -1582,8 +1895,7 @@ class SetupHelper: def old_getNEventsListList(self, n_it): yaml = YAML() - with open(self.workdir + 'rich' + str(self.whichRich) + - '_variant.yml') as finp: + with open(self.workdir + "rich" + str(self.whichRich) + "_variant.yml") as finp: current_variant = yaml.load(finp) self.fileprename = self.workdir + current_variant + "_histos_i" nEventsList = [] @@ -1591,10 +1903,11 @@ class SetupHelper: thisFile = [] hist = [] for j in range(0, n_it + 1): - filename.append(self.fileprename + str(j) + '.root') - thisFile.append(TFile(filename[j], 'read')) - hist.append(thisFile[j].Get( - 'RICH/RichODIN/TriggerType')) # won't work on MC + filename.append(self.fileprename + str(j) + ".root") + thisFile.append(TFile(filename[j], "read")) + hist.append( + thisFile[j].Get("RICH/RichODIN/TriggerType") + ) # won't work on MC nEventsList.append(int(hist[j].GetEntries())) nEvents = int( round(float(sum(nEventsList)) / float(n_it + 1)) @@ -1602,13 +1915,15 @@ class SetupHelper: return [nEventsList, nEvents] def old_quickWriteInLogbook(self, subject, text, edit=None): - host = 'logbook.lbdaq.cern.ch' + host = "logbook.lbdaq.cern.ch" port = 8080 - username = 'common Common\\!' - logbook = 'RICH' - author = 'MirrAlign Monitor' # Or any other name - activity = 'Alignment' - instruction_file = 'https://twiki.cern.ch/twiki/bin/view/LHCb/LHCbRun3RichMirrAlignShiftInfo' + username = "common Common\\!" + logbook = "RICH" + author = "MirrAlign Monitor" # Or any other name + activity = "Alignment" + instruction_file = ( + "https://twiki.cern.ch/twiki/bin/view/LHCb/LHCbRun3RichMirrAlignShiftInfo" + ) text += " \n Shifter's instructions can be found at " text += str(instruction_file) @@ -1619,7 +1934,7 @@ class SetupHelper: command += '" -p ' command += str(port) try: - command += ' -e ' + str(int(edit)) + command += " -e " + str(int(edit)) except: pass command += ' -l "' @@ -1628,7 +1943,7 @@ class SetupHelper: command += str(username) command += ' -a "Author=' command += str(author) - #command += '" -a "System=' + # command += '" -a "System=' command += '" -a "System_19=' # Change 19 if Alignment changes its order in the ELOG (ask the current RICH expert) command += str(activity) command += '" -a "Subject=' @@ -1640,8 +1955,10 @@ class SetupHelper: try: elogret = subprocess.check_output(cmd, stderr=subprocess.STDOUT) messageID = int( - re.search('.*Message successfully transmitted, ID=(\d*)', - elogret).groups()[0]) + re.search( + ".*Message successfully transmitted, ID=(\d*)", elogret + ).groups()[0] + ) print(f"INFO: messageID = {messageID}") except: messageID = None diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/UpdateHelper.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/UpdateHelper.py index 2c6cedf299849eacc36ed61983b859d7e8eaee5e..11830a816c76382b42ea54f62434086194d248df 100644 --- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/UpdateHelper.py +++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/UpdateHelper.py @@ -11,18 +11,17 @@ __author__ = "Paras Naik" __copyright__ = "University of Bristol, May 2018" +import getpass import os -import shutil import re -import time -from time import time -from time import gmtime, strftime -from time import sleep -import pydim -import threading +import shutil import sys -import getpass +import threading +import time from pathlib import Path +from time import gmtime, sleep, strftime, time + +import pydim def load_opts(f, key_strip="OnlineEnv."): @@ -31,14 +30,15 @@ def load_opts(f, key_strip="OnlineEnv."): result = {} for line in f: line = line.strip() - if line.startswith("//"): continue + if line.startswith("//"): + continue m = re.match(r"^(?P<key>\S+)\s*=\s*(?P<value>.*)\s*;$", line) if not m: raise ValueError(f"cannot parse {line!r}") key = m.group("key") if not key.startswith(key_strip): raise ValueError(f"key {key!r} does not start with {key_strip!r}") - key = key[len(key_strip):] + key = key[len(key_strip) :] result[key] = parseOpt(m.group("value")) return result @@ -46,58 +46,79 @@ def load_opts(f, key_strip="OnlineEnv."): class UpdateHelper: def __init__(self, _alignConf): self.alignConf = _alignConf - self.nameStr = self.alignConf.getProp('nameStr') - self.tiltNames = self.alignConf.getProp('tiltNames') - self.workdir = self.alignConf.getProp('WorkDir') - self.whichRich = self.alignConf.getProp('Rich') - self.magnFactorsMode = self.alignConf.getProp('magnFactorsMode') - #self.magnifDir = os.path.join(self.alignConf.getProp('stackDir'),self.alignConf.getProp('magnifDir')) - if self.alignConf.getProp( - 'testing') or not self.alignConf.getProp('autoUpdate'): + self.nameStr = self.alignConf.getProp("nameStr") + self.tiltNames = self.alignConf.getProp("tiltNames") + self.workdir = self.alignConf.getProp("WorkDir") + self.whichRich = self.alignConf.getProp("Rich") + self.magnFactorsMode = self.alignConf.getProp("magnFactorsMode") + # self.magnifDir = os.path.join(self.alignConf.getProp('stackDir'),self.alignConf.getProp('magnifDir')) + if self.alignConf.getProp("testing") or not self.alignConf.getProp( + "autoUpdate" + ): # if testing, don't send DIM message to correct server, since clara will potentially expect an updated alignment in the online conddb - self.updateServiceName = f"/Publisher/Rich{self.whichRich}/Alignment/MirrorsTest" + self.updateServiceName = ( + f"/Publisher/Rich{self.whichRich}/Alignment/MirrorsTest" + ) else: - self.updateServiceName = f"/Publisher/Rich{self.whichRich}/Alignment/Mirrors" - #self.messageServiceName = "/Publisher/Rich"+str(self.whichRich)+"/MirrorAlignMessage" + self.updateServiceName = ( + f"/Publisher/Rich{self.whichRich}/Alignment/Mirrors" + ) + # self.messageServiceName = "/Publisher/Rich"+str(self.whichRich)+"/MirrorAlignMessage" self.messageServiceName = "/Publisher/AlignmentMessenger" self.format = "C" # "C" means a string self.updateString = "" self.messageString = "" self.serverName = "Rich" + str(self.whichRich) + "MirrorAlign_0" - #self.serverName = "LHCbA_HLT02_AligDrv_0" + # self.serverName = "LHCbA_HLT02_AligDrv_0" self.updateSvc = None self.messageSvc = None def startUpdateDIM(self): self.updateSvc = pydim.dis_add_service( - self.updateServiceName, self.format, self.updateStringTuple, 1) + self.updateServiceName, self.format, self.updateStringTuple, 1 + ) self.messageSvc = pydim.dis_add_service( - self.messageServiceName, self.format, self.messageStringTuple, 1) + self.messageServiceName, self.format, self.messageStringTuple, 1 + ) if not self.updateSvc: - sys.stderr.write("An error occurred while registering the " + - self.updateServiceName + - " DB update DIM service\n") + sys.stderr.write( + "An error occurred while registering the " + + self.updateServiceName + + " DB update DIM service\n" + ) sys.exit(1) if not self.messageSvc: - sys.stderr.write("An error occurred while registering the " + - self.messageServiceName + - " DB update-message DIM service\n") + sys.stderr.write( + "An error occurred while registering the " + + self.messageServiceName + + " DB update-message DIM service\n" + ) sys.exit(1) pydim.dis_start_serving(self.serverName) - print("INFO: Started DB update DIM service " + self.updateServiceName + - " with server " + self.serverName) + print( + "INFO: Started DB update DIM service " + + self.updateServiceName + + " with server " + + self.serverName + ) print( "INFO: Sending initialization DB update code (i.e. just a dummy empty string to start): ", - self.updateStringTuple('')) + self.updateStringTuple(""), + ) sys.stdout.flush() pydim.dis_update_service(self.updateSvc) - print("INFO: Started DB update-message DIM service " + - self.messageServiceName + " with server " + self.serverName) + print( + "INFO: Started DB update-message DIM service " + + self.messageServiceName + + " with server " + + self.serverName + ) print( "INFO: Sending initialization DB update-message code (i.e. just a dummy empty string to start): ", - self.messageStringTuple('')) + self.messageStringTuple(""), + ) sys.stdout.flush() pydim.dis_update_service(self.messageSvc) @@ -116,15 +137,16 @@ class UpdateHelper: # the callback function must return a tuple def updateStringTuple(self, tag): stringTuple = self.updateString - return (stringTuple, ) + return (stringTuple,) # the callback function must return a tuple def messageStringTuple(self, tag): stringTuple = self.messageString - return (stringTuple, ) + return (stringTuple,) def updateDB(self, N_DB, decision, message=""): import OnlineEnvBase as Online # import OnlineEnv as Online + # runs = Online.DeferredRuns with open(Path(Online.__file__).parent / "RunList.opts") as f: runs = sorted(load_opts(f)["DeferredRuns"]) @@ -136,30 +158,40 @@ class UpdateHelper: self.updateString = str(minRun) + " v" + str(N_DB) self.messageString = message if not self.updateSvc: - sys.stderr.write("The " + self.updateServiceName + - " DB update DIM service does not exist\n") + sys.stderr.write( + "The " + + self.updateServiceName + + " DB update DIM service does not exist\n" + ) sys.exit(1) if not self.messageSvc: - sys.stderr.write("The " + self.messageServiceName + - " DB update-message DIM service does not exist\n") + sys.stderr.write( + "The " + + self.messageServiceName + + " DB update-message DIM service does not exist\n" + ) sys.exit(1) if decision: - print( - "INFO: The decision is to trigger an automatic update of the DB. " - ) + print("INFO: The decision is to trigger an automatic update of the DB. ") else: print( "INFO: The decision is to not update the DB (the alignment was fine, or autoUpdate is False). " ) - print("INFO: Sending the following update code to the " + - self.updateServiceName + " DB update DIM service") - print("INFO: Sending final DB update code: ", - self.updateStringTuple('')) + print( + "INFO: Sending the following update code to the " + + self.updateServiceName + + " DB update DIM service" + ) + print("INFO: Sending final DB update code: ", self.updateStringTuple("")) pydim.dis_update_service(self.updateSvc) - print("INFO: Sending the following message code to the " + - self.messageServiceName + " DB update-message DIM service") - print("INFO: Sending final DB update-message code: ", - self.messageStringTuple('')) + print( + "INFO: Sending the following message code to the " + + self.messageServiceName + + " DB update-message DIM service" + ) + print( + "INFO: Sending final DB update-message code: ", self.messageStringTuple("") + ) pydim.dis_update_service(self.messageSvc) print( "INFO: We now wait 20 seconds for Online to pick up our DB update and DB update-message." diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/XMLFileHelper.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/XMLFileHelper.py index c651749fdb75e8ff9f99a5b360d2a2fde49bad4f..a79fced7f55651fd27001f84d70b604a79683b5c 100644 --- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/XMLFileHelper.py +++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/XMLFileHelper.py @@ -12,101 +12,123 @@ __authors__ = "Claire Prouve, Paras Naik" __copyright__ = "University of Bristol, May 2018" import distutils +import math import os import re import shutil import sys -import math -import time -from time import sleep -from time import time -from time import gmtime, strftime import threading -import Configurables -from subprocess import * +import time from distutils import dir_util +from subprocess import * +from time import gmtime, sleep, strftime, time + +import Configurables class XMLFileHelper: def __init__(self, configuration): self.alignConf = configuration - self.whichRich = self.alignConf.getProp('Rich') - self.base_dir = '/group/online/alignment/Rich' + str( - self.whichRich) + '/MirrorAlign/' + self.whichRich = self.alignConf.getProp("Rich") + self.base_dir = ( + "/group/online/alignment/Rich" + str(self.whichRich) + "/MirrorAlign/" + ) def create_coeff_calibration_xml_files(self, inputFile, n_it): print("INFO: start create coeff") - writedir = self.alignConf.getProp('WorkDir') - coeffCalibTilt = self.alignConf.getProp('coeffCalibTilt') - thisNameStr = self.alignConf.getProp('nameStr') + writedir = self.alignConf.getProp("WorkDir") + coeffCalibTilt = self.alignConf.getProp("coeffCalibTilt") + thisNameStr = self.alignConf.getProp("nameStr") - import fpformat from array import array + + import fpformat from lxml import etree - signName = dict({'-': 'neg', '+': 'pos'}) - signToShift = dict({'-': -coeffCalibTilt, '+': coeffCalibTilt}) - mirrTypeName = dict({'pri': 'Sph', 'sec': 'Sec'}) - totMirrNum = dict({'pri': 56, 'sec': 40}) + signName = dict({"-": "neg", "+": "pos"}) + signToShift = dict({"-": -coeffCalibTilt, "+": coeffCalibTilt}) + mirrTypeName = dict({"pri": "Sph", "sec": "Sec"}) + totMirrNum = dict({"pri": 56, "sec": 40}) if self.whichRich == 2: - totMirrNum = dict({'pri': 56, 'sec': 40}) + totMirrNum = dict({"pri": 56, "sec": 40}) if self.whichRich == 1: - totMirrNum = dict({'pri': 4, 'sec': 16}) + totMirrNum = dict({"pri": 4, "sec": 16}) - seqNum = dict({'Y': 1, 'Z': 2}) - rotRE = re.compile(r'[\-|\+]?[0-9]+\.?[0-9]*|[\-|\+]?\.[0-9]+') + seqNum = dict({"Y": 1, "Z": 2}) + rotRE = re.compile(r"[\-|\+]?[0-9]+\.?[0-9]*|[\-|\+]?\.[0-9]+") rotValues = [] - for mirrType in ['pri', 'sec']: - for axis in ['Y', 'Z']: - for sign in ['-', '+']: + for mirrType in ["pri", "sec"]: + for axis in ["Y", "Z"]: + for sign in ["-", "+"]: parser = etree.XMLParser(remove_blank_text=True) RichAlignmentConditions = etree.parse(inputFile, parser) for mirrNum in range(totMirrNum[mirrType]): - floatRotValues = array('f') - if (self.whichRich == 1): + floatRotValues = array("f") + if self.whichRich == 1: dRotXYZ = RichAlignmentConditions.xpath( - "//condition[@name='" + - mirrTypeName[mirrType] + "Mirror" + - str(mirrNum) + - "_Align']/paramVector[@name='dRotXYZ']") - if (self.whichRich == 2): + "//condition[@name='" + + mirrTypeName[mirrType] + + "Mirror" + + str(mirrNum) + + "_Align']/paramVector[@name='dRotXYZ']" + ) + if self.whichRich == 2: dRotXYZ = RichAlignmentConditions.xpath( - "//condition[@name='Rich" + - str(self.whichRich) + mirrTypeName[mirrType] + - "Mirror" + str(mirrNum) + - "_Align']/paramVector[@name='dRotXYZ']") + "//condition[@name='Rich" + + str(self.whichRich) + + mirrTypeName[mirrType] + + "Mirror" + + str(mirrNum) + + "_Align']/paramVector[@name='dRotXYZ']" + ) rotValues = rotRE.findall( - etree.tostring( - dRotXYZ[0], pretty_print=True, method="text")) + etree.tostring(dRotXYZ[0], pretty_print=True, method="text") + ) for i in range(3): floatRotValues.append(float(rotValues[i])) floatRotValues[seqNum[axis]] += signToShift[sign] - dRotXYZ[0].text = fpformat.fix( - floatRotValues[0], 5) + '*mrad ' + fpformat.fix( - floatRotValues[1], - 5) + '*mrad ' + fpformat.fix( - floatRotValues[2], 5) + '*mrad ' - if axis == 'Y': - signCombinName = signName[sign] + 'YzerZ' + dRotXYZ[0].text = ( + fpformat.fix(floatRotValues[0], 5) + + "*mrad " + + fpformat.fix(floatRotValues[1], 5) + + "*mrad " + + fpformat.fix(floatRotValues[2], 5) + + "*mrad " + ) + if axis == "Y": + signCombinName = signName[sign] + "YzerZ" else: - signCombinName = 'zerY' + signName[sign] + 'Z' + signCombinName = "zerY" + signName[sign] + "Z" newXML_File = open( - writedir + 'Rich' + str(self.whichRich) + - 'CondDBUpdate_' + thisNameStr + "_" + mirrType + - "_" + signCombinName + "_i" + str(n_it) + ".xml", - 'w') + writedir + + "Rich" + + str(self.whichRich) + + "CondDBUpdate_" + + thisNameStr + + "_" + + mirrType + + "_" + + signCombinName + + "_i" + + str(n_it) + + ".xml", + "w", + ) newXML_File.write( etree.tostring( RichAlignmentConditions, - encoding='iso-8859-1', + encoding="iso-8859-1", xml_declaration=True, pretty_print=True, - with_tail=False)) + with_tail=False, + ) + ) newXML_File.close() def getStartXMLOrigFileName(self): - import os, re + import os + import re re_version = re.compile(r"^v([0-9]+)\.xml$") @@ -123,65 +145,67 @@ class XMLFileHelper: def getStartXML(self, startxml): import os - latest = self.alignConf.getProp('startXMLFile') + latest = self.alignConf.getProp("startXMLFile") - if (latest == "") or (self.alignConf.getProp('testing') is not True): + if (latest == "") or (self.alignConf.getProp("testing") is not True): latest = self.getStartXMLOrigFileName() latest = os.path.join(self.base_dir, latest) print("INFO: This file was picked up as the starting xml: ", latest) - with open(startxml, 'w') as outfile: - outfile.write('<?xml version=\'1.0\' encoding=\'iso-8859-1\'?> \n') - outfile.write( - '<!DOCTYPE DDDB SYSTEM "conddb:/DTD/structure.dtd"> \n') - outfile.write('<DDDB> \n') + with open(startxml, "w") as outfile: + outfile.write("<?xml version='1.0' encoding='iso-8859-1'?> \n") + outfile.write('<!DOCTYPE DDDB SYSTEM "conddb:/DTD/structure.dtd"> \n') + outfile.write("<DDDB> \n") if not os.path.exists(latest): print("ERROR: no latest file.") with open(latest) as infile: for line in infile: outfile.write(line) - outfile.write('</DDDB> \n') + outfile.write("</DDDB> \n") def getCompareXML(self, compareXML): import os - compareXMLFile = self.alignConf.getProp('compareXMLFile') - if (compareXMLFile == ""): + compareXMLFile = self.alignConf.getProp("compareXMLFile") + if compareXMLFile == "": compareXMLFile = self.getStartXMLOrigFileName() compareXMLFile = os.path.join(self.base_dir, compareXMLFile) - print("INFO: This file was picked up as the compareXMLFile: ", - compareXMLFile) + print("INFO: This file was picked up as the compareXMLFile: ", compareXMLFile) - with open(compareXML, 'w') as outfile: - outfile.write('<?xml version=\'1.0\' encoding=\'iso-8859-1\'?> \n') - outfile.write( - '<!DOCTYPE DDDB SYSTEM "conddb:/DTD/structure.dtd"> \n') - outfile.write('<DDDB> \n') + with open(compareXML, "w") as outfile: + outfile.write("<?xml version='1.0' encoding='iso-8859-1'?> \n") + outfile.write('<!DOCTYPE DDDB SYSTEM "conddb:/DTD/structure.dtd"> \n') + outfile.write("<DDDB> \n") if not os.path.exists(compareXMLFile): print("ERROR: no compareXMLFile.") with open(compareXMLFile) as infile: for line in infile: outfile.write(line) - outfile.write('</DDDB> \n') + outfile.write("</DDDB> \n") def finalXML(self, vN_DB_str, Update): - workdir = self.alignConf.getProp('WorkDir') + workdir = self.alignConf.getProp("WorkDir") - finalXML = workdir + "CondDB_Update_Rich" + str( - self.whichRich) + ".xml" + finalXML = workdir + "CondDB_Update_Rich" + str(self.whichRich) + ".xml" tocopyXML = workdir + "CondDB_Rich" + str(self.whichRich) + ".xml" if not os.path.exists(tocopyXML): print("ERROR: no tocopyXML file.") - with open(tocopyXML, 'r') as infile: - with open(finalXML, 'w') as outfile: + with open(tocopyXML, "r") as infile: + with open(finalXML, "w") as outfile: for line in infile: - if "<?xml version=\'1.0\' encoding=\'iso-8859-1\'?>" not in line and '<!DOCTYPE DDDB SYSTEM "conddb:/DTD/structure.dtd">' not in line and '<DDDB>' not in line and '</DDDB>' not in line: + if ( + "<?xml version='1.0' encoding='iso-8859-1'?>" not in line + and '<!DOCTYPE DDDB SYSTEM "conddb:/DTD/structure.dtd">' + not in line + and "<DDDB>" not in line + and "</DDDB>" not in line + ): outfile.write(line) if Update: - latest = vN_DB_str + '.xml' + latest = vN_DB_str + ".xml" latest = os.path.join(self.base_dir, latest) shutil.copyfile(finalXML, latest) @@ -190,18 +214,16 @@ class XMLFileHelper: counter = 0 if not os.path.exists(newXMLfile): print("ERROR: no newXMLfile.") - with open(newXMLfile, 'r') as infile: - with open(temp, 'w') as outfile: + with open(newXMLfile, "r") as infile: + with open(temp, "w") as outfile: for line in infile: counter = counter + 1 if counter == 1: - outfile.write( - '<?xml version=\'1.0\' encoding=\'iso-8859-1\'?> \n' - ) + outfile.write("<?xml version='1.0' encoding='iso-8859-1'?> \n") outfile.write( '<!DOCTYPE DDDB SYSTEM "conddb:/DTD/structure.dtd"> \n' ) - outfile.write('<DDDB> \n') + outfile.write("<DDDB> \n") else: outfile.write(line) shutil.copyfile(temp, newXMLfile) diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/YAMLFileHelper.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/YAMLFileHelper.py index db54929c89bcdd7a1d001a1fdd9b22f7dcc24306..590fceda077f7aef6873e0dac6c4e5818a1c5548 100644 --- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/YAMLFileHelper.py +++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/YAMLFileHelper.py @@ -12,30 +12,31 @@ __authors__ = "Claire Prouve, Paras Naik, Vidar Marsh" __copyright__ = "University of Bristol, August 2021" import distutils +import getpass +import math import os import re import shutil import sys -import math -import time -from time import sleep -from time import time -from time import gmtime, strftime import threading -import Configurables -from subprocess import * +import time from distutils import dir_util -import getpass +from subprocess import * +from time import gmtime, sleep, strftime, time + +import Configurables class YAMLFileHelper: def __init__(self, configuration): self.alignConf = configuration - self.whichRich = self.alignConf.getProp('Rich') + self.whichRich = self.alignConf.getProp("Rich") richFilesDir = self.alignConf.getProp( - 'richFiles') # '/group/rich/AlignmentFiles/' - self.base_dir_for_testing_and_maybe = f'{richFilesDir}testingMaybe/Rich' + str( - self.whichRich) + '/Mirrors/' + "richFiles" + ) # '/group/rich/AlignmentFiles/' + self.base_dir_for_testing_and_maybe = ( + f"{richFilesDir}testingMaybe/Rich" + str(self.whichRich) + "/Mirrors/" + ) # PN: Until we are ready to use the real Run 3 Online CondDB location, # we use the testing/maybe basedir. @@ -45,8 +46,11 @@ class YAMLFileHelper: # This is the online base_dir, we should pick up the current alignment and drop any new alignment here # Note that any alignment dropped in .pool is there FOREVER (as it gets swept into the true CondDB quite often) # Do not drop an alignment there until you can guarantee it is better than the last alignment! - self.base_dir = '/group/online/hlt/conditions.run3/lhcb-conditions-database/Conditions/Rich' \ - + str(self.whichRich) + '/Alignment/Mirrors.yml/.pool/' + self.base_dir = ( + "/group/online/hlt/conditions.run3/lhcb-conditions-database/Conditions/Rich" + + str(self.whichRich) + + "/Alignment/Mirrors.yml/.pool/" + ) # self.base_dir = '/group/online/AligWork/tempAlignmentFiles/lhcb-conditions-database_Feb24/Conditions/Rich' + str(self.whichRich) + '/Alignment/starting_points/' @@ -54,28 +58,30 @@ class YAMLFileHelper: # Therefore we are OVERWRITING self.base_dir here. # If you put a new alignment into alignment2022 or similar branch of the new CondDB, # you must have ALSO placed it here as the latest vN for it to get picked up as the starting mirror alignment! - ''' + """ Comment this next line out ONLY when ready and wanting to automatically post v-numbers to .pool! Uncomment when you want v-number updates to post to the testing_and_maybe area for testing - ''' - self.base_dir = f'{richFilesDir}testingMaybe/Rich' \ - + str(self.whichRich) + '/Mirrors/' # use the same base_dir as for testing/maybe alignments + """ + self.base_dir = ( + f"{richFilesDir}testingMaybe/Rich" + str(self.whichRich) + "/Mirrors/" + ) # use the same base_dir as for testing/maybe alignments self.latest = None def create_coeff_calibration_yml_files(self, inputFile, n_it): print("INFO: start create coeff") - writedir = self.alignConf.getProp('WorkDir') - coeffCalibTilt = self.alignConf.getProp('coeffCalibTilt') - thisNameStr = self.alignConf.getProp('nameStr') + writedir = self.alignConf.getProp("WorkDir") + coeffCalibTilt = self.alignConf.getProp("coeffCalibTilt") + thisNameStr = self.alignConf.getProp("nameStr") import ruamel.yaml class Condition: - yaml_tag = u"!alignment" + yaml_tag = "!alignment" yaml = ruamel.yaml.YAML() - with open(writedir + '/' + 'rich' + str(self.whichRich) + - '_variant.yml') as finp: + with open( + writedir + "/" + "rich" + str(self.whichRich) + "_variant.yml" + ) as finp: variant = yaml.load(finp) yaml = ruamel.yaml.YAML() @@ -83,41 +89,40 @@ class YAMLFileHelper: sys.path.append(inputFile) with open(inputFile, "r") as f: RichAlignCon = yaml.load(f) - #signName = dict({'-': 'neg', '+': 'pos'}) - signName = dict({'-': 'n', '+': 'p'}) - signToShift = dict({'-': -coeffCalibTilt, '+': coeffCalibTilt}) - #mirrTypeName = dict({'pri': 'Sph', 'sec': 'Sec'}) - mirrTypeName = dict({'pri': '1', 'sec': '2'}) + # signName = dict({'-': 'neg', '+': 'pos'}) + signName = dict({"-": "n", "+": "p"}) + signToShift = dict({"-": -coeffCalibTilt, "+": coeffCalibTilt}) + # mirrTypeName = dict({'pri': 'Sph', 'sec': 'Sec'}) + mirrTypeName = dict({"pri": "1", "sec": "2"}) if self.whichRich == 2: - totMirrNum = dict({'pri': 56, 'sec': 40}) + totMirrNum = dict({"pri": 56, "sec": 40}) elif self.whichRich == 1: - totMirrNum = dict({'pri': 4, 'sec': 16}) + totMirrNum = dict({"pri": 4, "sec": 16}) else: - raise ValueError("RICH detector \"{}\" does not exist".format\ - (self.whichRich)) - seqNum = dict({'Y': 1, 'Z': 2}) - for mirrType in ['pri', 'sec']: - for axis in ['Y', 'Z']: - for sign in ['-', '+']: + raise ValueError('RICH detector "{}" does not exist'.format(self.whichRich)) + seqNum = dict({"Y": 1, "Z": 2}) + for mirrType in ["pri", "sec"]: + for axis in ["Y", "Z"]: + for sign in ["-", "+"]: with open(inputFile, "r") as f: RichAlignCon = yaml.load(f) for mirrNum in range(totMirrNum[mirrType]): - #if self.whichRich == 1: + # if self.whichRich == 1: # mirrName = "{}Mirror{}_Align".format\ # (mirrTypeName[mirrType], mirrNum) - #if self.whichRich == 2: + # if self.whichRich == 2: # mirrName = "Rich{}{}Mirror{}_Align".format\ # (self.whichRich, mirrTypeName[mirrType], \ # mirrNum) - mirrName = "R{}M{}Seg{}".format\ - (self.whichRich, mirrTypeName[mirrType], \ - mirrNum) + mirrName = "R{}M{}Seg{}".format( + self.whichRich, mirrTypeName[mirrType], mirrNum + ) # add 0, e.g. R1M1Seg5 -> R1M1Seg05 - if (len(mirrName) == 8): + if len(mirrName) == 8: mirrName = mirrName[:-1] + "0" + mirrName[-1:] dRotXYZ_unit = RichAlignCon[mirrName].rotation - #NOTE: dRotXYZ_unit it NOT an ordinary list but a + # NOTE: dRotXYZ_unit it NOT an ordinary list but a # ruamel.yaml object. This list must be re-inserted # into RichAlingCon after the values have been # updated to preserve the output file structure. @@ -136,30 +141,40 @@ class YAMLFileHelper: for i in range(len(dRotXYZ_new)): dRotXYZ_unit[i] = round(dRotXYZ_new[i], 5) if units[i] != None: - dRotXYZ_unit[i] = "{} * {}".format\ - (dRotXYZ_unit[i], units[i]) + dRotXYZ_unit[i] = "{} * {}".format( + dRotXYZ_unit[i], units[i] + ) # Note comment about dRotXYZ_unit RichAlignCon[mirrName].rotation = dRotXYZ_unit - if axis == 'Y': - #signCombinName = signName[sign] + 'YzerZ' - signCombinName = 'Y' + signName[sign] + if axis == "Y": + # signCombinName = signName[sign] + 'YzerZ' + signCombinName = "Y" + signName[sign] else: - #signCombinName = 'zerY' + signName[sign] + 'Z' - signCombinName = 'Z' + signName[sign] - #with open(writedir + 'Rich' + str(self.whichRich) \ + # signCombinName = 'zerY' + signName[sign] + 'Z' + signCombinName = "Z" + signName[sign] + # with open(writedir + 'Rich' + str(self.whichRich) \ # + 'CondDBUpdate_' + thisNameStr + "_" \ # + mirrType + "_" + signCombinName + "_i" \ # + str(n_it) + ".yml", 'w') as f: # yaml.dump(RichAlignCon, f) - with open(writedir + variant + "_conds_" + - mirrType + signCombinName + "_i" \ - + str(n_it) + ".yml", 'w') as f: + with open( + writedir + + variant + + "_conds_" + + mirrType + + signCombinName + + "_i" + + str(n_it) + + ".yml", + "w", + ) as f: yaml.dump(RichAlignCon, f) def getStartYAMLOrigFileName(self): - import os, re + import os + import re - #re_version = re.compile(r"^v([0-9]+)\.yml$") + # re_version = re.compile(r"^v([0-9]+)\.yml$") re_version = re.compile( r"^v([0-9]+)(?:\.yml)?$" ) # should match v123 and v123.yml but not v123_testing_maybe_20230505_171822.yml @@ -177,23 +192,21 @@ class YAMLFileHelper: def getStartYAML(self, startyml): import os - self.latest = self.alignConf.getProp('startYAMLFile') + self.latest = self.alignConf.getProp("startYAMLFile") - if (self.latest == "") or (self.alignConf.getProp('testing') is - not True): + if (self.latest == "") or (self.alignConf.getProp("testing") is not True): self.latest = self.getStartYAMLOrigFileName() # self.latest = "200000" # self.latest = "rich1sajanpivots_i3" self.latest = os.path.join(self.base_dir, self.latest) - print("INFO: This file was picked up as the starting yml:", - self.latest) + print("INFO: This file was picked up as the starting yml:", self.latest) - with open(startyml, 'w') as outfile: - #outfile.write('<?xml version=\'1.0\' encoding=\'iso-8859-1\'?> \n') - #outfile.write( + with open(startyml, "w") as outfile: + # outfile.write('<?xml version=\'1.0\' encoding=\'iso-8859-1\'?> \n') + # outfile.write( # '<!DOCTYPE DDDB SYSTEM "conddb:/DTD/structure.dtd"> \n') - #outfile.write('<DDDB> \n') + # outfile.write('<DDDB> \n') if not os.path.exists(self.latest): print("ERROR: no latest file.") with open(self.latest) as infile: @@ -204,16 +217,15 @@ class YAMLFileHelper: def getCompareYAML(self, compareYAML): import os - compareYAMLFile = self.alignConf.getProp('compareYAMLFile') + compareYAMLFile = self.alignConf.getProp("compareYAMLFile") - if (compareYAMLFile == ""): + if compareYAMLFile == "": compareYAMLFile = self.getStartYAMLOrigFileName() compareYAMLFile = os.path.join(self.base_dir, compareYAMLFile) - print("INFO: This file was picked up as the compareYAMLFile:", - compareYAMLFile) + print("INFO: This file was picked up as the compareYAMLFile:", compareYAMLFile) - with open(compareYAML, 'w') as outfile: + with open(compareYAML, "w") as outfile: # outfile.write('<?xml version=\'1.0\' encoding=\'iso-8859-1\'?> \n') # outfile.write( # '<!DOCTYPE DDDB SYSTEM "conddb:/DTD/structure.dtd"> \n') @@ -226,24 +238,30 @@ class YAMLFileHelper: # outfile.write('</DDDB> \n') def finalYAML(self, vN_DB_str, Update): - workdir = self.alignConf.getProp('WorkDir') + workdir = self.alignConf.getProp("WorkDir") - finalYAML = workdir + "CondDB_Update_Rich" + str( - self.whichRich) + ".yml" + finalYAML = workdir + "CondDB_Update_Rich" + str(self.whichRich) + ".yml" tocopyYAML = workdir + "CondDB_Rich" + str(self.whichRich) + ".yml" if not os.path.exists(tocopyYAML): print("ERROR: no tocopyYAML file.") - with open(tocopyYAML, 'r') as infile: - with open(finalYAML, 'w') as outfile: + with open(tocopyYAML, "r") as infile: + with open(finalYAML, "w") as outfile: for line in infile: - if "<?xml version=\'1.0\' encoding=\'iso-8859-1\'?>" not in line and '<!DOCTYPE DDDB SYSTEM "conddb:/DTD/structure.dtd">' not in line and '<DDDB>' not in line and '</DDDB>' not in line: + if ( + "<?xml version='1.0' encoding='iso-8859-1'?>" not in line + and '<!DOCTYPE DDDB SYSTEM "conddb:/DTD/structure.dtd">' + not in line + and "<DDDB>" not in line + and "</DDDB>" not in line + ): outfile.write(line) if Update: if "testing" in vN_DB_str or "maybe" in vN_DB_str: - self.latest = vN_DB_str + '.yml' - self.latest = os.path.join(self.base_dir_for_testing_and_maybe, - self.latest) + self.latest = vN_DB_str + ".yml" + self.latest = os.path.join( + self.base_dir_for_testing_and_maybe, self.latest + ) else: self.latest = vN_DB_str self.latest = os.path.join(self.base_dir, self.latest) @@ -255,11 +273,11 @@ class YAMLFileHelper: counter = 0 if not os.path.exists(newYAMLfile): print("ERROR: no newYAMLfile.") - with open(newYAMLfile, 'r') as infile: - with open(temp, 'w') as outfile: + with open(newYAMLfile, "r") as infile: + with open(temp, "w") as outfile: print("INFO: Reformatting " + newYAMLfile + " in " + temp) for line in infile: - ''' + """ counter = counter + 1 if counter == 1: # PN - I am not sure why it was done like this for XML; this would certainly require the first line to be blank # outfile.write( @@ -272,7 +290,7 @@ class YAMLFileHelper: pass else: outfile.write(line) - ''' + """ outfile.write(line) # Add a newline at the end of the YAML file. This is necessary to pass the lhcb-conditions-database formatting check (GitLab) outfile.write("\n") diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/__init__.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/__init__.py index 79924c63b1a9e5399b02560d12235d636daeef5c..b9699acd6294bd5f185e8d778030d849f19281f2 100644 --- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/__init__.py +++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/__init__.py @@ -9,9 +9,9 @@ # or submit itself to any jurisdiction. # ############################################################################### # Import required modules -import os import glob import inspect +import os # Get this module's source code directory module_file = inspect.getfile(inspect.currentframe()) @@ -20,12 +20,10 @@ module_dir = os.path.dirname(module_file) print(f"INFO: PyMirrAlignOnline package directory: {module_dir}") # Get the list of all .py file names in the package directory -files = glob.glob(os.path.join(module_dir, '*.py')) +files = glob.glob(os.path.join(module_dir, "*.py")) # Extract the module names from the file names -module_names = [ - os.path.basename(file)[:-3] for file in files if not "__init__" in file -] +module_names = [os.path.basename(file)[:-3] for file in files if not "__init__" in file] # Define the __all__ variable as the list of module names __all__ = module_names diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/convert_XML_YAML.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/convert_XML_YAML.py index 55c0a92c3ed28abb4895ce1a784c9e2d9b2c202e..3e54454421ebae2ade8641fd6753caeccdbf4218 100644 --- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/convert_XML_YAML.py +++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/convert_XML_YAML.py @@ -11,15 +11,17 @@ __authors__ = "Vidar Marsh, Jake Reich, Paras Naik" __copyright__ = "University of Bristol, May 2022" -from fileinput import filename -import sys -import os import argparse -from distutils.util import strtobool +import os import re -import yaml +import sys +from distutils.util import strtobool +from fileinput import filename + import numpy as np +import yaml from lxml import etree + import PyMirrAlignOnline.converter_objects as obj # set flags @@ -42,7 +44,8 @@ class Condition(yaml.YAMLObject): Configurable YAML object used format data before it is dumped to a YAML file. """ - yaml_tag = u"!alignment" + + yaml_tag = "!alignment" class Conversion: @@ -56,29 +59,28 @@ class Conversion: self.whichRich = whichRICH self.configPath = config_path self.blistedCondsPath = blisted_conds_path - if (self.alignConf != ""): - self.whichRich = self.alignConf.getProp('Rich') + if self.alignConf != "": + self.whichRich = self.alignConf.getProp("Rich") self.configPath = os.path.join( - self.alignConf.getProp('stackDir'), - self.alignConf.getProp('XML_YAML_configDir')) # + self.alignConf.getProp("stackDir"), + self.alignConf.getProp("XML_YAML_configDir"), + ) # self.blistedCondsPath = os.path.join( - self.alignConf.getProp('stackDir'), - self.alignConf.getProp('XML_YAML_configDir') - ) #self.alignConf.getProp('WorkDir') # PN - not sure yet if WorkDir is the best place + self.alignConf.getProp("stackDir"), + self.alignConf.getProp("XML_YAML_configDir"), + ) # self.alignConf.getProp('WorkDir') # PN - not sure yet if WorkDir is the best place # Add configuration files and xml_blocklisted_conditions folder to path. sys.path.append(self.configPath) sys.path.append(self.blistedCondsPath) - blist_path = os.path.sep.join((self.configPath, - "blocklist_config.txt")) + blist_path = os.path.sep.join((self.configPath, "blocklist_config.txt")) blist_path = r"{}".format(blist_path) - yaml_parser_path = os.path.sep.join((self.configPath, \ - "yaml_parser_config.txt")) + yaml_parser_path = os.path.sep.join((self.configPath, "yaml_parser_config.txt")) yaml_parser_path = r"{}".format(yaml_parser_path) - param_path = os.path.sep.join((self.configPath, \ - "param_conversion_config.txt")) + param_path = os.path.sep.join((self.configPath, "param_conversion_config.txt")) param_path = r"{}".format(param_path) - unit_conv_path = os.path.sep.join((self.configPath, \ - "unit_conversion_config.txt")) + unit_conv_path = os.path.sep.join( + (self.configPath, "unit_conversion_config.txt") + ) unit_conv_path = r"{}".format(unit_conv_path) # Create blocklist: Parse contentes of blocklist_config.txt list, use # to create blocklist object. @@ -87,7 +89,7 @@ class Conversion: # Configure yaml parser to accept custom tags. temp = obj.load_to_list(yaml_parser_path) for tag in temp: - yaml.add_constructor(u"{}".format(tag), obj.custom_constructor) + yaml.add_constructor("{}".format(tag), obj.custom_constructor) # Configure Conversions for name and unit translation between files: # name_xml(name in xml) -> name in yaml # unit_xml(name in xml) -> unit in xml @@ -104,8 +106,7 @@ class Conversion: temp = obj.load_to_list(unit_conv_path) for line in temp: elements = line.split(":") - self.conversions.unit_conv[elements[0]] = (elements[1], \ - float(elements[2])) + self.conversions.unit_conv[elements[0]] = (elements[1], float(elements[2])) def conv_XML(self, file_path): """ @@ -118,8 +119,7 @@ class Conversion: """ file_type = file_path[-4:] if file_type != ".xml": - raise TypeError("input file is \"{}\" not \".xml\"".format\ - (file_type)) + raise TypeError('input file is "{}" not ".xml"'.format(file_type)) # Generate output file name from input file name. file_dir, file_name = os.path.split(file_path) file_name = file_name[:-4] + "_converted.yml" @@ -128,10 +128,10 @@ class Conversion: os.remove(out_file_path) print("converting file: " + file_path + " ,(XML->YAML)...") # Generate blocklisted list file from input file name. - if (blisted_write_file == True): + if blisted_write_file == True: blisted_file_path = os.path.sep.join( - (self.blistedCondsPath, - file_name.split(".")[0] + "_blisted_nodes.txt")) + (self.blistedCondsPath, file_name.split(".")[0] + "_blisted_nodes.txt") + ) if os.path.exists(blisted_file_path): os.remove(blisted_file_path) @@ -162,7 +162,8 @@ class Conversion: # nodes to remove (save to .txt file to be added when converting back to xml) if self.blocklist.check(yml_node_name) == True: blisted_node = etree.tostring( - xml_node, pretty_print=True, encoding="unicode") + xml_node, pretty_print=True, encoding="unicode" + ) if reAdd_blocklisted_conditions: with open(blisted_file_path, "a+") as f: f.write(" " + blisted_node) @@ -173,16 +174,14 @@ class Conversion: for xml_subnode in xml_node.iter("paramVector"): xml_subnode_name = xml_subnode.get("name") - yml_subnode_name = self.conversions.get_name_yml\ - (xml_subnode_name) + yml_subnode_name = self.conversions.get_name_yml(xml_subnode_name) xml_data = xml_subnode.text.split() yml_data = [] for xml_datapoint in xml_data: try: xml_value, xml_unit = xml_datapoint.split("*") xml_value = float(xml_value) - yml_datapoint = "{} * {}".format(xml_value, \ - xml_unit) + yml_datapoint = "{} * {}".format(xml_value, xml_unit) except: xml_value = xml_datapoint sig_figs = obj.find_sigfigs(xml_value) @@ -191,21 +190,24 @@ class Conversion: # with np.format_float_positional if sig_figs == 0: sig_figs = 1 - yml_unit = self.conversions.get_unit_yml\ - (yml_subnode_name) - yml_value = self.conversions.convert_unit\ - (xml_value, xml_unit, yml_unit) - yml_value = np.format_float_positional(yml_value, \ - precision=sig_figs, fractional=False, trim="0") + yml_unit = self.conversions.get_unit_yml(yml_subnode_name) + yml_value = self.conversions.convert_unit( + xml_value, xml_unit, yml_unit + ) + yml_value = np.format_float_positional( + yml_value, + precision=sig_figs, + fractional=False, + trim="0", + ) yml_datapoint = float(yml_value) yml_data.append(yml_datapoint) yml_condition.__dict__[yml_subnode_name] = yml_data # apply new naming convention - if (applyNewNC == True): - + if applyNewNC == True: # prepend "R1" or "R2" - if (self.whichRich == 1): + if self.whichRich == 1: yml_node_name = "R1" + yml_node_name else: yml_node_name = "R2" + yml_node_name @@ -214,17 +216,16 @@ class Conversion: yml_node_name = re.sub("Sec", "M2", yml_node_name) yml_node_name = re.sub("Mirror", "Seg", yml_node_name) - yml_node_name = re.sub("_Align", "", - yml_node_name) # remove "_Align" yml_node_name = re.sub( - "Rich" + str(self.whichRich), "", - yml_node_name) # remove "Rich1" or "Rich2" + "_Align", "", yml_node_name + ) # remove "_Align" + yml_node_name = re.sub( + "Rich" + str(self.whichRich), "", yml_node_name + ) # remove "Rich1" or "Rich2" # add 0, e.g. R1M1Seg5 -> R1M1Seg05 - if (len(yml_node_name) == 8): - yml_node_name = yml_node_name[: - -1] + "0" + yml_node_name[ - -1:] + if len(yml_node_name) == 8: + yml_node_name = yml_node_name[:-1] + "0" + yml_node_name[-1:] yml_obj = {yml_node_name: yml_condition} @@ -234,9 +235,8 @@ class Conversion: f.write(yaml.dump(yml_obj, default_flow_style=None)) # tack on extra lines from yaml_tack_on_Rich_X.txt - if (type(tack_on) == bool): - obj.tack_on_off(out_file_path, tack_on, self.configPath, - self.whichRich) + if type(tack_on) == bool: + obj.tack_on_off(out_file_path, tack_on, self.configPath, self.whichRich) print("converted. output file: " + out_file_path) @@ -251,8 +251,7 @@ class Conversion: """ file_type = file_path[-4:] if file_type != ".yml": - raise TypeError("input file is \"{}\" not \".yml\"".format\ - (file_type)) + raise TypeError('input file is "{}" not ".yml"'.format(file_type)) # Generate output file name from input file name. file_dir, in_file_name = os.path.split(file_path) file_name = in_file_name[:-4] + "_converted.xml" @@ -267,19 +266,18 @@ class Conversion: ### convert back to old naming scheme ### nameChange_dict = {} for yml_node in yml_tree: - temp_name = yml_node temp_name = re.sub("M1", "Sph", temp_name) temp_name = re.sub("M2", "Sec", temp_name) temp_name = re.sub("Seg", "Mirror", temp_name) - if (temp_name[11] == "0"): - temp_name = temp_name[0:11:] + temp_name[11 + 1::] + if temp_name[11] == "0": + temp_name = temp_name[0:11:] + temp_name[11 + 1 : :] temp_name = re.sub("R1", "", temp_name) temp_name = re.sub("R2", "", temp_name) temp_name += "_Align" # re-append "_Align" - if (self.whichRich == 2): + if self.whichRich == 2: temp_name = "Rich2" + temp_name # re-prepend "Rich2" nameChange_dict[yml_node] = temp_name # store name change @@ -292,24 +290,20 @@ class Conversion: xml_tree = etree.ElementTree(xml_root) # Conversion for yml_node in yml_tree: - if self.blocklist.check(yml_node) == False: xml_node = etree.SubElement(xml_root, "condition") xml_node.set("classID", "6") xml_node.set("name", yml_node) for yml_subnode in yml_tree[yml_node]: - xml_subnode = etree.SubElement(xml_node, "paramVector") - xml_subnode_name = self.conversions.get_name_xml\ - (yml_subnode) + xml_subnode_name = self.conversions.get_name_xml(yml_subnode) xml_subnode.set("name", xml_subnode_name) xml_subnode.set("type", "double") # Counter is used to log the number of 0 entries xml_data = [] counter = 0 for yml_datapoint in yml_tree[yml_node][yml_subnode]: - try: yml_value, yml_unit = yml_datapoint.split("*") yml_unit = yml_unit.strip() @@ -320,56 +314,66 @@ class Conversion: sig_figs = obj.find_sigfigs(yml_value) yml_value = float(yml_value) if yml_unit == False: - xml_unit = self.conversions.get_unit_xml\ - (xml_subnode_name) - yml_unit = self.conversions.get_unit_yml\ - (yml_subnode) - yml_value = self.conversions.convert_unit\ - (yml_value, yml_unit, xml_unit) + xml_unit = self.conversions.get_unit_xml(xml_subnode_name) + yml_unit = self.conversions.get_unit_yml(yml_subnode) + yml_value = self.conversions.convert_unit( + yml_value, yml_unit, xml_unit + ) else: xml_unit = yml_unit - # Format text output + # Format text output if xml_unit == "mrad": - yml_value = np.format_float_positional(yml_value, \ - precision=5, fractional=True, trim="k", \ - min_digits=5) + yml_value = np.format_float_positional( + yml_value, + precision=5, + fractional=True, + trim="k", + min_digits=5, + ) if yml_value == "0.00000": counter += 1 elif sig_figs == 0: - yml_value = np.format_float_positional(yml_value, \ - precision=1, fractional=False, trim="-") + yml_value = np.format_float_positional( + yml_value, precision=1, fractional=False, trim="-" + ) else: - yml_value = np.format_float_positional(yml_value, \ - precision=sig_figs, fractional=False, trim="0") + yml_value = np.format_float_positional( + yml_value, + precision=sig_figs, + fractional=False, + trim="0", + ) xml_datapoint = "*".join((str(yml_value), xml_unit)) xml_data.append(xml_datapoint) if counter == 3: xml_datapoint = "*".join(("0", xml_unit)) text = "{0} {0} {0}".format(xml_datapoint) elif xml_unit == "mrad": - text = (xml_data[0].rjust(15) + xml_data[1].rjust(16) + - xml_data[2].rjust(16)) + text = ( + xml_data[0].rjust(15) + + xml_data[1].rjust(16) + + xml_data[2].rjust(16) + ) else: - text = "{} {} {}".format(xml_data[0], xml_data[1], \ - xml_data[2]) + text = "{} {} {}".format(xml_data[0], xml_data[1], xml_data[2]) xml_subnode.text = text # Write to file and remove root yml_node. - if (reAdd_blocklisted_conditions == True): + if reAdd_blocklisted_conditions == True: # read blocklisted list file from input file name. try: blisted_file_path = os.path.sep.join( - (self.blistedCondsPath, - in_file_name[:-4].split(".")[0] + "_blisted_nodes.txt")) + ( + self.blistedCondsPath, + in_file_name[:-4].split(".")[0] + "_blisted_nodes.txt", + ) + ) except: raise ImportError( "File with blocklisted conditions (when converting from xml to yaml) not found. \n" - + - "Have you run the xml->yaml converter at some point (to generate the corresponding blocklist file)?\n " - + - "Have you checked that self.blistedCondsPath is correct?.\n" - + - "Have you set blisted_write_file to False when converting from XML->YAML?" + + "Have you run the xml->yaml converter at some point (to generate the corresponding blocklist file)?\n " + + "Have you checked that self.blistedCondsPath is correct?.\n" + + "Have you set blisted_write_file to False when converting from XML->YAML?" ) with open(blisted_file_path, "r") as f: @@ -387,16 +391,13 @@ class Conversion: f.writelines(blisted_content) # tack on (or off) extra lines from yaml_tack_on_Rich_X.txt - if (type(tack_on) == bool): - obj.tack_on_off(out_file_path, tack_on, self.configPath, - self.whichRich) + if type(tack_on) == bool: + obj.tack_on_off(out_file_path, tack_on, self.configPath, self.whichRich) print("converted. output file: " + out_file_path) if __name__ == "__main__": - c = Conversion() c.conv_XML(r"/home/yq21049/Desktop/xml_yaml/Data/v40-R1_master.xml") - c.conv_YAML( - r"/home/yq21049/Desktop/xml_yaml/Data/v40-R1_master_converted.yml") + c.conv_YAML(r"/home/yq21049/Desktop/xml_yaml/Data/v40-R1_master_converted.yml") diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/convert_magnFactors_txt_YAML.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/convert_magnFactors_txt_YAML.py index ae91c8f404681b6429bcb9dcecf7808e0b721eb1..e1c1acb78e0dd0d2d214e119ac49e8bb10a5fc32 100644 --- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/convert_magnFactors_txt_YAML.py +++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/convert_magnFactors_txt_YAML.py @@ -1,20 +1,20 @@ ## Convert magnification factors to YAML ### Introduction -#This tool is created to convert a directory containing text files with magnetisation factors for either RICH1 or RICH2 to a yaml object. The yaml object will be written to the file _RichXMirrMagnFactors_ where _X_ refers to the specific RICH detector (1 or 2) and stored in the inputted directory. +# This tool is created to convert a directory containing text files with magnetisation factors for either RICH1 or RICH2 to a yaml object. The yaml object will be written to the file _RichXMirrMagnFactors_ where _X_ refers to the specific RICH detector (1 or 2) and stored in the inputted directory. ### Requirements -#The tool requires a working version of Python 3 with additional packages: -#* ruamel +# The tool requires a working version of Python 3 with additional packages: +# * ruamel ### CONFIGURATION AND USE -#To use the Conversion tool download mag_parse.py and note the location. Whenever the tool is required is a python script simply add the location to path and import the file. Initiate an instance of the MagConvert class (as shown below) and call the to_yaml method. Pass the absolute path to the directory containing magnification factors and the file _RichXMirrMagnFactors.yml_ will be added to the directory (_X_ refers to the detector number). +# To use the Conversion tool download mag_parse.py and note the location. Whenever the tool is required is a python script simply add the location to path and import the file. Initiate an instance of the MagConvert class (as shown below) and call the to_yaml method. Pass the absolute path to the directory containing magnification factors and the file _RichXMirrMagnFactors.yml_ will be added to the directory (_X_ refers to the detector number). # -#**Example:** Importing map_parse and converting the directory _magnification_ which contains magnification factors for RICH 1: +# **Example:** Importing map_parse and converting the directory _magnification_ which contains magnification factors for RICH 1: # # import mag_parse # # convert = MagConvert() # convert.to_yaml("<Path to magnification>/magnification") # -#This would result in the file _Rich1MirrMagnFactors.yml_ being added to _magnification_. +# This would result in the file _Rich1MirrMagnFactors.yml_ being added to _magnification_. ############################################################################### # (c) Copyright 2000-2021 CERN for the benefit of the LHCb Collaboration # @@ -29,9 +29,10 @@ __authors__ = "Vidar Marsh, Paras Naik" __copyright__ = "University of Bristol, August 2021" -import sys import os import re +import sys + import ruamel.yaml yaml = ruamel.yaml.YAML() @@ -63,16 +64,17 @@ class convert_magnFactors_txt_YAML: # detector. mag_num = 0 for filename in os.listdir(mag_dir_path): - if "magnifs" in filename and (f"_i{n_it}" in filename - or "_predefined" in filename) and ( - "pri" in filename - or "sec" in filename): + if ( + "magnifs" in filename + and (f"_i{n_it}" in filename or "_predefined" in filename) + and ("pri" in filename or "sec" in filename) + ): # Extract substring with "rich" in it - which_rich = re.search(r"_([^_]*rich[^_]*)_", - filename).group(1) + which_rich = re.search(r"_([^_]*rich[^_]*)_", filename).group(1) # Extract first three letters of substring with "pri" or "sec" in it - pri_sec_substring = re.search(r"_([^_]*(pri|sec)[^_]*)_", - filename).group(1) + pri_sec_substring = re.search( + r"_([^_]*(pri|sec)[^_]*)_", filename + ).group(1) rot_mirr = pri_sec_substring[:3] # Extract last two letters of substring with "pri" or "sec" in it rot_axis = pri_sec_substring[-2:] @@ -98,18 +100,8 @@ class convert_magnFactors_txt_YAML: if mag_num == 0: mag_map = { rich_detector: { - "pri": { - "Yn": {}, - "Yp": {}, - "Zn": {}, - "Zp": {} - }, - "sec": { - "Yn": {}, - "Yp": {}, - "Zn": {}, - "Zp": {} - } + "pri": {"Yn": {}, "Yp": {}, "Zn": {}, "Zp": {}}, + "sec": {"Yn": {}, "Yp": {}, "Zn": {}, "Zp": {}}, } } mag_num += 1 @@ -133,19 +125,21 @@ class convert_magnFactors_txt_YAML: except: mag_map[rich_detector][rot_mirr][rot_axis][pri_mirr] = {} try: - mag_map[rich_detector][rot_mirr][rot_axis][pri_mirr][ - sec_mirr] + mag_map[rich_detector][rot_mirr][rot_axis][pri_mirr][sec_mirr] except: - mag_map[rich_detector][rot_mirr][rot_axis][pri_mirr][ - sec_mirr] = None - mag_map[rich_detector][rot_mirr][rot_axis][pri_mirr][ - sec_mirr] = [float(y_rot), float(z_rot)] + mag_map[rich_detector][rot_mirr][rot_axis][pri_mirr][sec_mirr] = ( + None + ) + mag_map[rich_detector][rot_mirr][rot_axis][pri_mirr][sec_mirr] = [ + float(y_rot), + float(z_rot), + ] # Create YAML file newfile = rich_detector + f"_MirrMagnFactors_predefined.yml" if n_it < 99: newfile = rich_detector + f"_MirrMagnFactors_i{n_it}.yml" newfile_path = os.path.sep.join((mag_dir_path, newfile)) - #while os.path.isfile(newfile_path) == True: + # while os.path.isfile(newfile_path) == True: # to_newfile, newfile_name = os.path.split(newfile_path) # newfile_name = "new" + newfile_name # newfile_path = os.path.sep.join([to_newfile, newfile_name]) diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/converter_objects.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/converter_objects.py index bdeb35d823a4c88dd1876830b1d963f368f466de..d88fcb505997350f750b26b5a6874c03ca299d93 100644 --- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/converter_objects.py +++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/converter_objects.py @@ -37,23 +37,23 @@ def load_to_list(file): def tack_on_off(out_file_path, tack_on, config_path, whichRICH): """ - Adds extra lines to the start and end of the converted file. - These lines are manually added in yaml_tack_on_Rich_X.txt or xml_tack_on_Rich_X.txt (where X = 1 or 2), - stored in the Configuration folder (defined in 'config_path'). + Adds extra lines to the start and end of the converted file. + These lines are manually added in yaml_tack_on_Rich_X.txt or xml_tack_on_Rich_X.txt (where X = 1 or 2), + stored in the Configuration folder (defined in 'config_path'). - Everything below '---top' (and above '---bottom') will be prepended to the top of the file. - Everything below '---bottom' will be appended to the bottom of the file. + Everything below '---top' (and above '---bottom') will be prepended to the top of the file. + Everything below '---bottom' will be appended to the bottom of the file. - Args: - out_file_path: raw string, path to the output file we want to write to - """ + Args: + out_file_path: raw string, path to the output file we want to write to + """ top_text = "" bottom_text = "" # get correct tack_on file file_type = out_file_path[-4:] - if (tack_on == True): + if tack_on == True: if file_type == ".xml": file_type = "xml" elif file_type == ".yml": @@ -65,10 +65,11 @@ def tack_on_off(out_file_path, tack_on, config_path, whichRICH): file_type = "xml" parse_path = os.path.sep.join( - (config_path, file_type + "_tack_on_Rich_" + str(whichRICH) + ".txt")) + (config_path, file_type + "_tack_on_Rich_" + str(whichRICH) + ".txt") + ) parse_path = r"{}".format(parse_path) - if (tack_on == True): + if tack_on == True: print("adding lines from file: " + parse_path) else: print("removing lines from file: " + parse_path) @@ -77,29 +78,28 @@ def tack_on_off(out_file_path, tack_on, config_path, whichRICH): with open(parse_path, "r") as f: for line in f: l = line.strip() - if (l == "---top"): + if l == "---top": temp_where_var = "top" continue - if (l == "---bottom"): + if l == "---bottom": temp_where_var = "bottom" continue - if (temp_where_var == "top"): + if temp_where_var == "top": top_text += line - elif (temp_where_var == "bottom"): + elif temp_where_var == "bottom": bottom_text += line # write to output file with open(out_file_path, "r+") as f: content = f.read() - if (tack_on == False): + if tack_on == False: content = content.replace(top_text, "") content = content.replace(bottom_text, "") f.seek(0) f.write(content) else: - f.seek(0) f.write(top_text + "\n" + content + "\n" + bottom_text) @@ -152,7 +152,7 @@ class Conversions: If the parameter name defined for XML files does not exist then a KeyError will be returned """ - errtxt = "\"{}\" does not exist in YAML database".format(name_yml) + errtxt = '"{}" does not exist in YAML database'.format(name_yml) try: name_xml = self.name_yml[name_yml] return name_xml @@ -174,7 +174,7 @@ class Conversions: If the parameter name defined for YAML files does not exist then a KeyError will be returned """ - errtxt = "\"{}\" does not exist in XML database".format(name_xml) + errtxt = '"{}" does not exist in XML database'.format(name_xml) try: name_yml = self.name_xml[name_xml] return name_yml @@ -193,8 +193,7 @@ class Conversions: Returns: str, unit in XML associated with name_xml """ - errtxt = "no unit associated with \"{}\" in XML database".format( - name_xml) + errtxt = 'no unit associated with "{}" in XML database'.format(name_xml) try: return self.unit_xml[name_xml] except: @@ -212,8 +211,7 @@ class Conversions: Returns: str, unit in YAML associated with name_yml """ - errtxt = "no unit associated with \"{}\" in YAMLdatabase".format( - name_yml) + errtxt = 'no unit associated with "{}" in YAMLdatabase'.format(name_yml) try: return self.unit_yml[name_yml] except: @@ -232,8 +230,8 @@ class Conversions: "Value" in units of u_out """ # Error messages - err_void = "the unit \"{}\" does not exist in database" - err_incomp = "the units \"{}\" and \"{}\" are incompatible" + err_void = 'the unit "{}" does not exist in database' + err_incomp = 'the units "{}" and "{}" are incompatible' # Check units exist in unit_conv list if u_in not in self.unit_conv: raise ValueError(err_void.format(u_in)) @@ -241,10 +239,8 @@ class Conversions: raise ValueError(err_void.format(u_out)) else: if self.unit_conv[u_in][0] == self.unit_conv[u_out][0]: - # convert units of "value" - return value * self.unit_conv[u_in][1] / self.unit_conv[u_out][ - 1] + return value * self.unit_conv[u_in][1] / self.unit_conv[u_out][1] else: raise ValueError(err_incomp.format(u_in, u_out)) @@ -329,8 +325,7 @@ def find_sigfigs(number): tokens = number.split(".") whole_num = tokens[0].lstrip("0") if len(tokens) > 2: - raise ValueError( - "Invalid number {} only 1 decimal allowed".format(number)) + raise ValueError("Invalid number {} only 1 decimal allowed".format(number)) elif len(tokens) == 2: decimal_num = tokens[1].rstrip("0") return len(whole_num) + len(decimal_num) diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/data_online.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/data_online.py index abee36b91cf7ba2e850940f6d67b4dc872d2991c..79cd1e1028625e0b89768f0d214a52237d3535d5 100644 --- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/data_online.py +++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/data_online.py @@ -8,16 +8,18 @@ # granted to it by virtue of its status as an Intergovernmental Organization # # or submit itself to any jurisdiction. # ############################################################################### +import getpass import os -import sys import re +import sys from datetime import datetime -from PyConf.application import ApplicationOptions -import getpass +from pathlib import Path + from MooreOnlineConf.utils import ( # may need to check for online user in offline scenario, let's see - alignment_options, distribute_files, + alignment_options, + distribute_files, ) -from pathlib import Path +from PyConf.application import ApplicationOptions filename_expr = re.compile( r"Run_(?P<run>\d{10})_HLT(?P<node>\d{5})_(?P<time>(?:\d{8})-(?:\d{6}))-(?P<rest>\d{3})\.mdf" @@ -33,7 +35,7 @@ options.input_type = "MDF" base_dir = "/calib/align/LHCb/Rich/0000256292/" -#base_dir = "/calib/align/LHCb/Rich/0000261947/" +# base_dir = "/calib/align/LHCb/Rich/0000261947/" def sort_names(f): @@ -41,52 +43,55 @@ def sort_names(f): m = filename_expr.match(f) if m is None: return m - funs = [ - int, lambda t: int(datetime.strptime(t, "%Y%m%d-%H%M%S").timestamp()), - int - ] - return tuple( - fun(m.group(k)) for fun, k in zip(funs, ("run", "time", "rest"))) + funs = [int, lambda t: int(datetime.strptime(t, "%Y%m%d-%H%M%S").timestamp()), int] + return tuple(fun(m.group(k)) for fun, k in zip(funs, ("run", "time", "rest"))) TESTBENCH_single_run = True -absolutely_all_files = True # not really "absolutely all" if just 2023 data chosen, see below -exclude_2022 = False #True +absolutely_all_files = ( + True # not really "absolutely all" if just 2023 data chosen, see below +) +exclude_2022 = False # True exclude_2023 = False divide_2022_2023 = 259566 if absolutely_all_files and exclude_2022 is False and exclude_2023 is False: import glob + base_dir = "/calib/align/LHCb/Rich/*/" dirs = glob.glob(base_dir, recursive=True) files = [] for dir_i in dirs: - files += glob.glob(dir_i + '*') + files += glob.glob(dir_i + "*") elif absolutely_all_files and exclude_2022 is True and exclude_2023 is False: import glob import re + base_dir = "/calib/align/LHCb/Rich/0000*/" dirs = glob.glob(base_dir, recursive=True) files = [] for dir_i in dirs: # PN - Extract the number from the directory string using regular expressions - WILL NOT WORK IF RUN NUMBERS BECOME 7 DIGITS - num = int(re.search(r'/0000(\d{6})/', dir_i).group(1)) + num = int(re.search(r"/0000(\d{6})/", dir_i).group(1)) # Check if the number is greater than or equal to 259 - if num >= divide_2022_2023 and num > 265000: # hack to avoid too many data files - files += glob.glob(dir_i + '*') + if ( + num >= divide_2022_2023 and num > 265000 + ): # hack to avoid too many data files + files += glob.glob(dir_i + "*") elif absolutely_all_files and exclude_2022 is False and exclude_2023 is True: import glob import re + base_dir = "/calib/align/LHCb/Rich/0000*/" dirs = glob.glob(base_dir, recursive=True) files = [] for dir_i in dirs: # PN - Extract the number from the directory string using regular expressions - WILL NOT WORK IF RUN NUMBERS BECOME 7 DIGITS - num = int(re.search(r'/0000(\d{6})/', dir_i).group(1)) + num = int(re.search(r"/0000(\d{6})/", dir_i).group(1)) # Check if the number is greater than or equal to 259 if num < divide_2022_2023: - files += glob.glob(dir_i + '*') + files += glob.glob(dir_i + "*") elif absolutely_all_files and exclude_2022 is True and exclude_2023 is True: print("You just excluded everything") else: @@ -98,8 +103,8 @@ else: # print(file_size) # quit() -#files = files[:1000] -#files = files[:25] +# files = files[:1000] +# files = files[:25] # # files = sorted(files, key=sort_names) @@ -110,17 +115,21 @@ options.input_files = files if "online" in getpass.getuser(): import OnlineEnvBase as OnlineEnv + online_options = alignment_options(OnlineEnv) - if OnlineEnv.PartitionName != "TESTALIGNMENT": # usually the case for the Run Control + if ( + OnlineEnv.PartitionName != "TESTALIGNMENT" + ): # usually the case for the Run Control print("not on TESTALIGNMENT partition") sys.stdout.flush() print(f"online_options.runs {online_options.runs}") sys.stdout.flush() INPUT_DATA_PATH = Path("/calib/align/LHCb/Rich/") - #INPUT_DATA_PATH = Path(f"/calib/align/LHCb/Rich{whichRich}/") + # INPUT_DATA_PATH = Path(f"/calib/align/LHCb/Rich{whichRich}/") files = [ sorted((INPUT_DATA_PATH / run).iterdir()) - for run in online_options.runs if (INPUT_DATA_PATH / run).exists() + for run in online_options.runs + if (INPUT_DATA_PATH / run).exists() ] else: # testbench, but we never use it from the online account, so we should never get here print("on TESTALIGNMENT partition") @@ -128,22 +137,20 @@ if "online" in getpass.getuser(): files = [sorted(INPUT_DATA_PATH.iterdir())] print(f"files {files}") sys.stdout.flush() - print(f'{sum(len(sublist) for sublist in files)} .mdf files...') + print(f"{sum(len(sublist) for sublist in files)} .mdf files...") sys.stdout.flush() file_size = 0 for file in [item for sublist in files for item in sublist]: file_size += os.path.getsize(file) - print('file_size', file_size) + print("file_size", file_size) sys.stdout.flush() print(f"online_options.nodes {online_options.nodes}") sys.stdout.flush() def distribute_files_alt(nodes, files): total_files = sum(files, []) # Flatten the files into a single list - n_files_per_node = len(total_files) // len( - nodes) # Number of files per node - extra_files = len(total_files) % len( - nodes) # Remaining files to distribute + n_files_per_node = len(total_files) // len(nodes) # Number of files per node + extra_files = len(total_files) % len(nodes) # Remaining files to distribute files_per_node = [] start_index = 0 @@ -159,7 +166,7 @@ if "online" in getpass.getuser(): return dict(zip(nodes, files_per_node)) - #files_per_node = distribute_files(online_options.nodes, files) + # files_per_node = distribute_files(online_options.nodes, files) files_per_node = distribute_files_alt(online_options.nodes, files) print(f"files_per_node {files_per_node}") sys.stdout.flush() @@ -172,8 +179,7 @@ if "online" in getpass.getuser(): # When testing we run multiple instances on the same node # TODO this should probably be done based on the partition name # and also "nodes" should be renamed to workers everywhere. - print("Trying multiple instances on same node" - ) # may not work for mirrAlign + print("Trying multiple instances on same node") # may not work for mirrAlign worker_id = utgid input_files = files_per_node[worker_id] @@ -190,10 +196,10 @@ if TESTBENCH_single_run: x for x in options.input_files if f"{TESTBENCH_single_run_number}" in x ] -print(f'{len(options.input_files)} .mdf files...') +print(f"{len(options.input_files)} .mdf files...") sys.stdout.flush() file_size = 0 for file in options.input_files: file_size += os.path.getsize(file) -print('file_size', file_size) +print("file_size", file_size) sys.stdout.flush() diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/data_online_Rich1.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/data_online_Rich1.py index 214a2bc4a78b757cf5010a83c7095260fab3cd43..ab391eb02df6ae0730a8404be3d1b8c5cfe87e12 100644 --- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/data_online_Rich1.py +++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/data_online_Rich1.py @@ -8,19 +8,21 @@ # granted to it by virtue of its status as an Intergovernmental Organization # # or submit itself to any jurisdiction. # ############################################################################### +import getpass +import glob import os -import sys import re +import sys from datetime import datetime -from PyConf.application import ApplicationOptions -import getpass -from MooreOnlineConf.utils import ( # may need to check for online user in offline scenario, let's see - alignment_options, distribute_files, -) -from pathlib import Path -import glob from itertools import cycle +from pathlib import Path + import numpy as np +from MooreOnlineConf.utils import ( # may need to check for online user in offline scenario, let's see + alignment_options, + distribute_files, +) +from PyConf.application import ApplicationOptions filename_expr = re.compile( r"Run_(?P<run>\d{10})_HLT(?P<node>\d{5})_(?P<time>(?:\d{8})-(?:\d{6}))-(?P<rest>\d{3})\.mdf" @@ -42,27 +44,24 @@ def sort_names(f): m = filename_expr.match(f) if m is None: return m - funs = [ - int, lambda t: int(datetime.strptime(t, "%Y%m%d-%H%M%S").timestamp()), - int - ] - return tuple( - fun(m.group(k)) for fun, k in zip(funs, ("run", "time", "rest"))) + funs = [int, lambda t: int(datetime.strptime(t, "%Y%m%d-%H%M%S").timestamp()), int] + return tuple(fun(m.group(k)) for fun, k in zip(funs, ("run", "time", "rest"))) select_runs_TESTBENCH = True # use this option and lines near the bottom of this file to select runs in the testbench import glob + base_dir = "/calib/align/LHCb/Rich1/*/" dirs = glob.glob(base_dir, recursive=True) files = [] for dir_i in dirs: - files += glob.glob(dir_i + '*') + files += glob.glob(dir_i + "*") # Only select 2024 data files_24 = [] for file in files: - file_id = file.split('/')[-2] + file_id = file.split("/")[-2] if int(file_id[4:]) >= 287743: files_24.append(file) files = files_24 @@ -74,8 +73,11 @@ options.input_files = files if "online" in getpass.getuser(): import OnlineEnvBase as OnlineEnv + online_options = alignment_options(OnlineEnv) - if OnlineEnv.PartitionName != "TESTALIGNMENT": # usually the case for the Run Control + if ( + OnlineEnv.PartitionName != "TESTALIGNMENT" + ): # usually the case for the Run Control print("not on TESTALIGNMENT partition") sys.stdout.flush() print(f"online_options.runs {online_options.runs}") @@ -83,7 +85,8 @@ if "online" in getpass.getuser(): INPUT_DATA_PATH = Path(f"/calib/align/LHCb/Rich1/") files = [ sorted((INPUT_DATA_PATH / run).iterdir()) - for run in online_options.runs if (INPUT_DATA_PATH / run).exists() + for run in online_options.runs + if (INPUT_DATA_PATH / run).exists() ] else: # testbench, but we never use it from the online account, so we should never get here @@ -92,12 +95,12 @@ if "online" in getpass.getuser(): files = [sorted(INPUT_DATA_PATH.iterdir())] print(f"files {files}") sys.stdout.flush() - print(f'{sum(len(sublist) for sublist in files)} .mdf files...') + print(f"{sum(len(sublist) for sublist in files)} .mdf files...") sys.stdout.flush() file_size = 0 for file in [item for sublist in files for item in sublist]: file_size += os.path.getsize(file) - print('file_size', file_size) + print("file_size", file_size) sys.stdout.flush() print(f"online_options.nodes {online_options.nodes}") sys.stdout.flush() @@ -129,8 +132,7 @@ if "online" in getpass.getuser(): # When testing we run multiple instances on the same node # TODO this should probably be done based on the partition name # and also "nodes" should be renamed to workers everywhere. - print("Trying multiple instances on same node" - ) # may not work for mirrAlign + print("Trying multiple instances on same node") # may not work for mirrAlign worker_id = utgid input_files = files_per_node[worker_id] @@ -148,15 +150,16 @@ if select_runs_TESTBENCH and "online" not in getpass.getuser(): if not isinstance(select_run_numbers, list): select_run_numbers = [select_run_numbers] options.input_files = [ - x for x in options.input_files if any( - str(run_number) in x for run_number in select_run_numbers) + x + for x in options.input_files + if any(str(run_number) in x for run_number in select_run_numbers) ] -print(f'{len(options.input_files)} .mdf files...') +print(f"{len(options.input_files)} .mdf files...") sys.stdout.flush() file_size = 0 for file in options.input_files: file_size += os.path.getsize(file) -print('file_size/1024*1024:', file_size / (1024 * 1024), 'in MB') +print("file_size/1024*1024:", file_size / (1024 * 1024), "in MB") sys.stdout.flush() diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/data_online_Rich2.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/data_online_Rich2.py index a907be2070870bf20c4bff7a69420e5fe282fdf5..57505f40e52bd878c7f241ddab864ec7adb01ff9 100644 --- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/data_online_Rich2.py +++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/data_online_Rich2.py @@ -8,19 +8,21 @@ # granted to it by virtue of its status as an Intergovernmental Organization # # or submit itself to any jurisdiction. # ############################################################################### +import getpass +import glob import os -import sys import re +import sys from datetime import datetime -from PyConf.application import ApplicationOptions -import getpass -from MooreOnlineConf.utils import ( # may need to check for online user in offline scenario, let's see - alignment_options, distribute_files, -) -from pathlib import Path -import glob from itertools import cycle +from pathlib import Path + import numpy as np +from MooreOnlineConf.utils import ( # may need to check for online user in offline scenario, let's see + alignment_options, + distribute_files, +) +from PyConf.application import ApplicationOptions filename_expr = re.compile( r"Run_(?P<run>\d{10})_HLT(?P<node>\d{5})_(?P<time>(?:\d{8})-(?:\d{6}))-(?P<rest>\d{3})\.mdf" @@ -42,27 +44,24 @@ def sort_names(f): m = filename_expr.match(f) if m is None: return m - funs = [ - int, lambda t: int(datetime.strptime(t, "%Y%m%d-%H%M%S").timestamp()), - int - ] - return tuple( - fun(m.group(k)) for fun, k in zip(funs, ("run", "time", "rest"))) + funs = [int, lambda t: int(datetime.strptime(t, "%Y%m%d-%H%M%S").timestamp()), int] + return tuple(fun(m.group(k)) for fun, k in zip(funs, ("run", "time", "rest"))) select_runs_TESTBENCH = True # use this option and lines near the bottom of this file to select runs in the testbench import glob + base_dir = "/calib/align/LHCb/Rich2/*/" dirs = glob.glob(base_dir, recursive=True) files = [] for dir_i in dirs: - files += glob.glob(dir_i + '*') + files += glob.glob(dir_i + "*") # Only select 2024 data files_24 = [] for file in files: - file_id = file.split('/')[-2] + file_id = file.split("/")[-2] if int(file_id[4:]) >= 287743: files_24.append(file) files = files_24 @@ -74,8 +73,11 @@ options.input_files = files if "online" in getpass.getuser(): import OnlineEnvBase as OnlineEnv + online_options = alignment_options(OnlineEnv) - if OnlineEnv.PartitionName != "TESTALIGNMENT": # usually the case for the Run Control + if ( + OnlineEnv.PartitionName != "TESTALIGNMENT" + ): # usually the case for the Run Control print("not on TESTALIGNMENT partition") sys.stdout.flush() print(f"online_options.runs {online_options.runs}") @@ -83,7 +85,8 @@ if "online" in getpass.getuser(): INPUT_DATA_PATH = Path(f"/calib/align/LHCb/Rich2/") files = [ sorted((INPUT_DATA_PATH / run).iterdir()) - for run in online_options.runs if (INPUT_DATA_PATH / run).exists() + for run in online_options.runs + if (INPUT_DATA_PATH / run).exists() ] else: # testbench, but we never use it from the online account, so we should never get here @@ -92,12 +95,12 @@ if "online" in getpass.getuser(): files = [sorted(INPUT_DATA_PATH.iterdir())] print(f"files {files}") sys.stdout.flush() - print(f'{sum(len(sublist) for sublist in files)} .mdf files...') + print(f"{sum(len(sublist) for sublist in files)} .mdf files...") sys.stdout.flush() file_size = 0 for file in [item for sublist in files for item in sublist]: file_size += os.path.getsize(file) - print('file_size', file_size) + print("file_size", file_size) sys.stdout.flush() print(f"online_options.nodes {online_options.nodes}") sys.stdout.flush() @@ -129,8 +132,7 @@ if "online" in getpass.getuser(): # When testing we run multiple instances on the same node # TODO this should probably be done based on the partition name # and also "nodes" should be renamed to workers everywhere. - print("Trying multiple instances on same node" - ) # may not work for mirrAlign + print("Trying multiple instances on same node") # may not work for mirrAlign worker_id = utgid input_files = files_per_node[worker_id] @@ -145,15 +147,16 @@ if select_runs_TESTBENCH and "online" not in getpass.getuser(): if not isinstance(select_run_numbers, list): select_run_numbers = [select_run_numbers] options.input_files = [ - x for x in options.input_files if any( - str(run_number) in x for run_number in select_run_numbers) + x + for x in options.input_files + if any(str(run_number) in x for run_number in select_run_numbers) ] -print(f'{len(options.input_files)} .mdf files...') +print(f"{len(options.input_files)} .mdf files...") sys.stdout.flush() file_size = 0 for file in options.input_files: file_size += os.path.getsize(file) -print('file_size/1024*1024:', file_size / (1024 * 1024), 'in MB') +print("file_size/1024*1024:", file_size / (1024 * 1024), "in MB") sys.stdout.flush() diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/fileFinder.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/fileFinder.py index 2e8cfcff0d0a30c65228028fd32138c4b2fe0d62..578915cb73de516f630abcf43948e06dd0c966d1 100644 --- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/fileFinder.py +++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/fileFinder.py @@ -13,12 +13,14 @@ __copyright__ = "University of Bristol, May 2018" class fileFinder: - def __init__(self, - _whichRich, - _minDate=00000000, - _maxDate=99999999, - _alignments=[], - _exclude=[]): + def __init__( + self, + _whichRich, + _minDate=00000000, + _maxDate=99999999, + _alignments=[], + _exclude=[], + ): self.whichRich = _whichRich self.minDate = _minDate self.maxDate = _maxDate @@ -28,11 +30,21 @@ class fileFinder: def getRich1_20160524to20160824(self): print("INFO: getRich1_20160524to20160824") alignments = [ - '20160616_205455', '20160616_180427', '20160616_192744', - '20160616_182620', '20160616_191413', '20160616_170644', - '20160616_174432', '20160616_195828', '20160616_203146', - '20160616_185541', '20160617_162358', '20160824_151337', - '20160824_123152', '20160824_130005', '20160824_121406' + "20160616_205455", + "20160616_180427", + "20160616_192744", + "20160616_182620", + "20160616_191413", + "20160616_170644", + "20160616_174432", + "20160616_195828", + "20160616_203146", + "20160616_185541", + "20160617_162358", + "20160824_151337", + "20160824_123152", + "20160824_130005", + "20160824_121406", ] return alignments @@ -40,23 +52,29 @@ class fileFinder: fullFiles = {} import os import re - startdir = '/group/online/AligWork/MirrorAlignments/Rich' + str( - self.whichRich) + '/' + + startdir = ( + "/group/online/AligWork/MirrorAlignments/Rich" + str(self.whichRich) + "/" + ) aligndirs = os.listdir(startdir) newalignments = [] if len(self.alignments) <= 0: for a in aligndirs: - date = a.split('_') + date = a.split("_") if self.whichRich == 2: - if (int(date[0]) <= self.maxDate - and int(date[0]) >= self.minDate - and not (a in self.exclude)): + if ( + int(date[0]) <= self.maxDate + and int(date[0]) >= self.minDate + and not (a in self.exclude) + ): newalignments.append(a) elif self.whichRich == 1: - if (int(date[0]) >= self.minDate - and int(date[0]) <= self.maxDate - and not (a in self.exclude)): + if ( + int(date[0]) >= self.minDate + and int(date[0]) <= self.maxDate + and not (a in self.exclude) + ): newalignments.append(a) newalignments.sort() else: @@ -64,59 +82,61 @@ class fileFinder: self.alignments = [] if self.whichRich == 1: - if (self.minDate < 20160824 and self.maxDate > 20160524): + if self.minDate < 20160824 and self.maxDate > 20160524: talignments = self.getRich1_20160524to20160824() talignments.extend(newalignments) newalignments = talignments for i in range(0, len(newalignments)): a = newalignments[i] - alignfiles = os.listdir(startdir + '/' + a) + alignfiles = os.listdir(startdir + "/" + a) # let's see if there are XML files, YAML files, or if both prefer XML - re_xmlfiles = re.compile(r"Rich" + str(self.whichRich) + - "CondDBUpdate_[A-Za-z0-9._]*_i[0-9].xml") + re_xmlfiles = re.compile( + r"Rich" + str(self.whichRich) + "CondDBUpdate_[A-Za-z0-9._]*_i[0-9].xml" + ) xmlfiles = [x for x in alignfiles if re_xmlfiles.match(x)] - re_ymlfiles = re.compile(r"Rich" + str(self.whichRich) + - "CondDBUpdate_[A-Za-z0-9._]*_i[0-9].yml") + re_ymlfiles = re.compile( + r"Rich" + str(self.whichRich) + "CondDBUpdate_[A-Za-z0-9._]*_i[0-9].yml" + ) ymlfiles = [x for x in alignfiles if re_ymlfiles.match(x)] # check for XML - file0 = '' - fileN = '' + file0 = "" + fileN = "" maxit = 0 for xml in xmlfiles: - if xml.endswith('_i0.xml'): - file0 = startdir + '/' + a + '/' + xml + if xml.endswith("_i0.xml"): + file0 = startdir + "/" + a + "/" + xml else: - hasi = xml.split('_') - hasi = hasi[len(hasi) - 1].split('.') - hasi = hasi[0].replace('i', '') + hasi = xml.split("_") + hasi = hasi[len(hasi) - 1].split(".") + hasi = hasi[0].replace("i", "") it = int(float(hasi)) if it > maxit: maxit = it - fileN = startdir + '/' + a + '/' + xml + fileN = startdir + "/" + a + "/" + xml # check for YAML - file0_yml = '' - fileN_yml = '' + file0_yml = "" + fileN_yml = "" maxit_yml = 0 for yml in ymlfiles: - if yml.endswith('_i0.yml'): - file0_yml = startdir + '/' + a + '/' + yml + if yml.endswith("_i0.yml"): + file0_yml = startdir + "/" + a + "/" + yml else: - hasi_yml = yml.split('_') - hasi_yml = hasi_yml[len(hasi_yml) - 1].split('.') - hasi_yml = hasi_yml[0].replace('i', '') + hasi_yml = yml.split("_") + hasi_yml = hasi_yml[len(hasi_yml) - 1].split(".") + hasi_yml = hasi_yml[0].replace("i", "") it_yml = int(float(hasi_yml)) if it_yml > maxit_yml: maxit_yml = it_yml - fileN_yml = startdir + '/' + a + '/' + yml + fileN_yml = startdir + "/" + a + "/" + yml - if not (file0 == '' or fileN == ''): + if not (file0 == "" or fileN == ""): fullFiles[a] = [file0, fileN] self.alignments.append(a) - elif not (file0_yml == '' or fileN_yml == ''): + elif not (file0_yml == "" or fileN_yml == ""): fullFiles[a] = [file0_yml, fileN_yml] self.alignments.append(a) diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/tiltObj.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/tiltObj.py index ec40c77df02cadd514e8991b8205ceac65dcb9e8..d4ee28bfd47208a27187073652fcc140115018e7 100644 --- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/tiltObj.py +++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/tiltObj.py @@ -22,18 +22,19 @@ class tiltObj: if self.alignConf == 1 or self.alignConf == 2: self.whichRich = self.alignConf else: # two different types were compared with ==, which should always be false - self.whichRich = self.alignConf.getProp('Rich') + self.whichRich = self.alignConf.getProp("Rich") import re + if self.whichRich == 1: - #self.priRe = re.compile('SphMirror[0-3]_Align') - #self.secRe = re.compile('SecMirror([0-9]|1[0-5])_Align') - self.priRe = re.compile('R1M1Seg[0-9][0-9]') - self.secRe = re.compile('R1M2Seg[0-9][0-9]') + # self.priRe = re.compile('SphMirror[0-3]_Align') + # self.secRe = re.compile('SecMirror([0-9]|1[0-5])_Align') + self.priRe = re.compile("R1M1Seg[0-9][0-9]") + self.secRe = re.compile("R1M2Seg[0-9][0-9]") else: - #self.priRe = re.compile('Rich2SphMirror[0-9]*_Align') - #self.secRe = re.compile('Rich2SecMirror[0-9]*_Align') - self.priRe = re.compile('R2M1Seg[0-9][0-9]') - self.secRe = re.compile('R2M2Seg[0-9][0-9]') + # self.priRe = re.compile('Rich2SphMirror[0-9]*_Align') + # self.secRe = re.compile('Rich2SecMirror[0-9]*_Align') + self.priRe = re.compile("R2M1Seg[0-9][0-9]") + self.secRe = re.compile("R2M2Seg[0-9][0-9]") self.priY = {} self.priZ = {} @@ -50,10 +51,10 @@ class tiltObj: self.secYdiv = {} self.secZdiv = {} - if (self.whichRich == 1): + if self.whichRich == 1: self.maxpri = 3 self.maxsec = 15 - if (self.whichRich == 2): + if self.whichRich == 2: self.maxpri = 55 self.maxsec = 39 @@ -66,43 +67,53 @@ class tiltObj: def writeChange(self, n): import os + # this will only work if alignConf is actually alignConf and not a Rich number - filename = self.alignConf.getProp('WorkDir') + 'Rich' + str( - self.whichRich) + '_ChangeWRTDB_' + str(n) + '.txt' + filename = ( + self.alignConf.getProp("WorkDir") + + "Rich" + + str(self.whichRich) + + "_ChangeWRTDB_" + + str(n) + + ".txt" + ) if os.path.exists(filename): os.remove(filename) - f = open(filename, 'w') - args = 'Primary mirrors \n' + f = open(filename, "w") + args = "Primary mirrors \n" for i in range(0, self.maxpri + 1): - args += str(i) + ' ' + str(self.priY[i]) + ' ' + str( - self.priZ[i]) + '\n' - args += '\n' - args += 'Secondary mirrors \n' + args += ( + str(i) + " " + str(self.priY[i]) + " " + str(self.priZ[i]) + "\n" + ) + args += "\n" + args += "Secondary mirrors \n" for i in range(0, self.maxsec + 1): - args += str(i) + ' ' + str(self.secY[i]) + ' ' + str( - self.secZ[i]) + '\n' + args += ( + str(i) + " " + str(self.secY[i]) + " " + str(self.secZ[i]) + "\n" + ) f.write(args) f.close() def setChangeYAML(self, files): - import ruamel.yaml import re + import ruamel.yaml + class condition: - yaml_tag = u"!alignment" + yaml_tag = "!alignment" yaml = ruamel.yaml.YAML() yaml.register_class(condition) if self.whichRich == 1: - #self.priRe = re.compile('SphMirror[0-3]_Align') - #self.secRe = re.compile('SecMirror([0-9]|1[0-5])_Align') - self.priRe = re.compile('R1M1Seg[0-9][0-9]') - self.secRe = re.compile('R1M2Seg[0-9][0-9]') + # self.priRe = re.compile('SphMirror[0-3]_Align') + # self.secRe = re.compile('SecMirror([0-9]|1[0-5])_Align') + self.priRe = re.compile("R1M1Seg[0-9][0-9]") + self.secRe = re.compile("R1M2Seg[0-9][0-9]") else: - #self.priRe = re.compile('Rich2SphMirror[0-9]*_Align') - #self.secRe = re.compile('Rich2SecMirror[0-9]*_Align') - self.priRe = re.compile('R2M1Seg[0-9][0-9]') - self.secRe = re.compile('R2M2Seg[0-9][0-9]') + # self.priRe = re.compile('Rich2SphMirror[0-9]*_Align') + # self.secRe = re.compile('Rich2SecMirror[0-9]*_Align') + self.priRe = re.compile("R2M1Seg[0-9][0-9]") + self.secRe = re.compile("R2M2Seg[0-9][0-9]") tree = {} with open(files[0], "r") as f: tree[0] = yaml.load(f) @@ -129,7 +140,7 @@ class tiltObj: if self.priRe.match(mirrNum): rotation = tree[mirrNum].rotation[1:] mirrNum = mirrNum[4:] - #mirrNum = float(mirrNum.strip("SphMirror_Align")) + # mirrNum = float(mirrNum.strip("SphMirror_Align")) mirrNum = float(mirrNum.strip("Seg")) for i in range(len(rotation)): rotValue = rotation[i] @@ -143,7 +154,7 @@ class tiltObj: elif self.secRe.match(mirrNum): rotation = tree[mirrNum].rotation[1:] mirrNum = mirrNum[4:] - #mirrNum = float(mirrNum.strip("SecMirror_Align")) + # mirrNum = float(mirrNum.strip("SecMirror_Align")) mirrNum = float(mirrNum.strip("Seg")) for i in range(len(rotation)): rotValue = rotation[i] @@ -161,6 +172,7 @@ class tiltObj: print("INFO: compareXML ", files[0]) print("INFO: self.lastXMLFile ", files[1]) import sys + sys.stdout.flush() parser = etree.XMLParser(remove_blank_text=True) @@ -197,9 +209,9 @@ class tiltObj: graph_secZ.SetPoint(i, i, self.secZ[i]) graph_priY.SetMarkerStyle(8) - graph_priY.SetMarkerColor(2) #red + graph_priY.SetMarkerColor(2) # red graph_priZ.SetMarkerStyle(8) - graph_priZ.SetMarkerColor(4) #blue + graph_priZ.SetMarkerColor(4) # blue graph_secY.SetMarkerStyle(8) graph_secY.SetMarkerColor(2) graph_secZ.SetMarkerStyle(8) @@ -216,40 +228,38 @@ class tiltObj: def xmlToDict(self, tree): if self.whichRich == 1: - self.priRe = re.compile('SphMirror[0-3]_Align') - self.secRe = re.compile('SecMirror([0-9]|1[0-5])_Align') + self.priRe = re.compile("SphMirror[0-3]_Align") + self.secRe = re.compile("SecMirror([0-9]|1[0-5])_Align") else: - self.priRe = re.compile('Rich2SphMirror[0-9]*_Align') - self.secRe = re.compile('Rich2SecMirror[0-9]*_Align') + self.priRe = re.compile("Rich2SphMirror[0-9]*_Align") + self.secRe = re.compile("Rich2SecMirror[0-9]*_Align") priTiltY = {} priTiltZ = {} secTiltY = {} secTiltZ = {} root = tree.getroot() - for cond in root.findall('condition'): - if self.priRe.match(cond.attrib['name']): - for paramV in cond.findall('paramVector'): - if paramV.attrib['name'] == 'dRotXYZ': - dRotXYZ = paramV.text.strip('*mrad').split('*mrad') + for cond in root.findall("condition"): + if self.priRe.match(cond.attrib["name"]): + for paramV in cond.findall("paramVector"): + if paramV.attrib["name"] == "dRotXYZ": + dRotXYZ = paramV.text.strip("*mrad").split("*mrad") if self.whichRich == 2: - mirrNumber = cond.attrib['name'].replace( - 'Rich2', '') + mirrNumber = cond.attrib["name"].replace("Rich2", "") else: - mirrNumber = cond.attrib['name'] - mirrNumber = mirrNumber.strip('SphMirror_Align') + mirrNumber = cond.attrib["name"] + mirrNumber = mirrNumber.strip("SphMirror_Align") priTiltY[int(float(mirrNumber))] = float(dRotXYZ[1]) priTiltZ[int(float(mirrNumber))] = float(dRotXYZ[2]) - elif self.secRe.match(cond.attrib['name']): - for paramV in cond.findall('paramVector'): - if paramV.attrib['name'] == 'dRotXYZ': - dRotXYZ = paramV.text.strip('*mrad').split('*mrad') + elif self.secRe.match(cond.attrib["name"]): + for paramV in cond.findall("paramVector"): + if paramV.attrib["name"] == "dRotXYZ": + dRotXYZ = paramV.text.strip("*mrad").split("*mrad") if self.whichRich == 2: - mirrNumber = cond.attrib['name'].replace( - 'Rich2', '') + mirrNumber = cond.attrib["name"].replace("Rich2", "") else: - mirrNumber = cond.attrib['name'] - mirrNumber = mirrNumber.strip('SecMirror_Align') + mirrNumber = cond.attrib["name"] + mirrNumber = mirrNumber.strip("SecMirror_Align") secTiltY[int(float(mirrNumber))] = float(dRotXYZ[1]) secTiltZ[int(float(mirrNumber))] = float(dRotXYZ[2]) @@ -273,46 +283,52 @@ class tiltObj: # can only be done *after* a setChange(files) # truncated-not-rounded-version of the mirror compensations already stored in self.priY, self.priZ, etc... import math + if int(digits) < 0: import sys + sys.exit("ERROR: Non-sensical number of digits for setTrunc.") divisor = float(math.pow(10, int(digits))) for pY in self.priY.keys(): if not abs(self.priY[pY]) < math.pow(10, int(0 - digits)): - self.priYtrunc[pY] = math.floor( - self.priY[pY] * divisor - ) / divisor + 0.0000001 if self.priY[pY] >= 0. else math.ceil( - self.priY[pY] * divisor) / divisor - 0.0000001 + self.priYtrunc[pY] = ( + math.floor(self.priY[pY] * divisor) / divisor + 0.0000001 + if self.priY[pY] >= 0.0 + else math.ceil(self.priY[pY] * divisor) / divisor - 0.0000001 + ) elif self.priY[pY] >= 0: self.priYtrunc[pY] = 0.0000001 else: self.priYtrunc[pY] = -0.0000001 for pZ in self.priZ.keys(): if not abs(self.priZ[pZ]) < math.pow(10, int(0 - digits)): - self.priZtrunc[pZ] = math.floor( - self.priZ[pZ] * divisor - ) / divisor + 0.0000001 if self.priZ[pZ] >= 0. else math.ceil( - self.priZ[pZ] * divisor) / divisor - 0.0000001 + self.priZtrunc[pZ] = ( + math.floor(self.priZ[pZ] * divisor) / divisor + 0.0000001 + if self.priZ[pZ] >= 0.0 + else math.ceil(self.priZ[pZ] * divisor) / divisor - 0.0000001 + ) elif self.priZ[pZ] >= 0: self.priZtrunc[pZ] = 0.0000001 else: self.priZtrunc[pZ] = -0.0000001 for sY in self.secY.keys(): if not abs(self.secY[sY]) < math.pow(10, int(0 - digits)): - self.secYtrunc[sY] = math.floor( - self.secY[sY] * divisor - ) / divisor + 0.0000001 if self.secY[sY] >= 0. else math.ceil( - self.secY[sY] * divisor) / divisor - 0.0000001 + self.secYtrunc[sY] = ( + math.floor(self.secY[sY] * divisor) / divisor + 0.0000001 + if self.secY[sY] >= 0.0 + else math.ceil(self.secY[sY] * divisor) / divisor - 0.0000001 + ) elif self.secY[sY] >= 0: self.secYtrunc[sY] = 0.0000001 else: self.secYtrunc[sY] = -0.0000001 for sZ in self.secZ.keys(): if not abs(self.secZ[sZ]) < math.pow(10, int(0 - digits)): - self.secZtrunc[sZ] = math.floor( - self.secZ[sZ] * divisor - ) / divisor + 0.0000001 if self.secZ[sZ] >= 0. else math.ceil( - self.secZ[sZ] * divisor) / divisor - 0.0000001 + self.secZtrunc[sZ] = ( + math.floor(self.secZ[sZ] * divisor) / divisor + 0.0000001 + if self.secZ[sZ] >= 0.0 + else math.ceil(self.secZ[sZ] * divisor) / divisor - 0.0000001 + ) elif self.secZ[sZ] >= 0: self.secZtrunc[sZ] = 0.0000001 else: @@ -323,56 +339,62 @@ class tiltObj: # truncated-not-rounded-version of the mirror compensations, already stored in self.priY, self.priZ, etc..., divided by the tolerances # NOTE: If digits = 0, values within the tolerances will all show up as "-0" or "0" import math + if int(digits) < 0: import sys + sys.exit("ERROR: Non-sensical number of digits for setDiv.") divisor = float(math.pow(10, int(digits))) if tolerances is None: tolerances = [0.1, 0.1, 0.1, 0.1] for pY in self.priY.keys(): - if not abs(self.priY[pY] / tolerances[0]) < math.pow( - 10, int(0 - digits)): - self.priYdiv[pY] = math.floor( - self.priY[pY] / tolerances[0] * divisor - ) / divisor + 0.0000001 if self.priY[pY] >= 0. else math.ceil( - self.priY[pY] / tolerances[0] * - divisor) / divisor - 0.0000001 + if not abs(self.priY[pY] / tolerances[0]) < math.pow(10, int(0 - digits)): + self.priYdiv[pY] = ( + math.floor(self.priY[pY] / tolerances[0] * divisor) / divisor + + 0.0000001 + if self.priY[pY] >= 0.0 + else math.ceil(self.priY[pY] / tolerances[0] * divisor) / divisor + - 0.0000001 + ) elif self.priY[pY] >= 0: self.priYdiv[pY] = 0.0000001 else: self.priYdiv[pY] = -0.0000001 for pZ in self.priZ.keys(): - if not abs(self.priZ[pZ] / tolerances[1]) < math.pow( - 10, int(0 - digits)): - self.priZdiv[pZ] = math.floor( - self.priZ[pZ] / tolerances[1] * divisor - ) / divisor + 0.0000001 if self.priZ[pZ] >= 0. else math.ceil( - self.priZ[pZ] / tolerances[1] * - divisor) / divisor - 0.0000001 + if not abs(self.priZ[pZ] / tolerances[1]) < math.pow(10, int(0 - digits)): + self.priZdiv[pZ] = ( + math.floor(self.priZ[pZ] / tolerances[1] * divisor) / divisor + + 0.0000001 + if self.priZ[pZ] >= 0.0 + else math.ceil(self.priZ[pZ] / tolerances[1] * divisor) / divisor + - 0.0000001 + ) elif self.priZ[pZ] >= 0: self.priZdiv[pZ] = 0.0000001 else: self.priZdiv[pZ] = -0.0000001 for sY in self.secY.keys(): - if not abs(self.secY[sY] / tolerances[2]) < math.pow( - 10, int(0 - digits)): - self.secYdiv[sY] = math.floor( - self.secY[sY] / tolerances[2] * divisor - ) / divisor + 0.0000001 if self.secY[sY] >= 0. else math.ceil( - self.secY[sY] / tolerances[2] * - divisor) / divisor - 0.0000001 + if not abs(self.secY[sY] / tolerances[2]) < math.pow(10, int(0 - digits)): + self.secYdiv[sY] = ( + math.floor(self.secY[sY] / tolerances[2] * divisor) / divisor + + 0.0000001 + if self.secY[sY] >= 0.0 + else math.ceil(self.secY[sY] / tolerances[2] * divisor) / divisor + - 0.0000001 + ) elif self.secY[sY] >= 0: self.secYdiv[sY] = 0.0000001 else: self.secYdiv[sY] = -0.0000001 for sZ in self.secZ.keys(): - if not abs(self.secZ[sZ] / tolerances[3]) < math.pow( - 10, int(0 - digits)): - self.secZdiv[sZ] = math.floor( - self.secZ[sZ] / tolerances[3] * divisor - ) / divisor + 0.0000001 if self.secZ[sZ] >= 0. else math.ceil( - self.secZ[sZ] / tolerances[3] * - divisor) / divisor - 0.0000001 + if not abs(self.secZ[sZ] / tolerances[3]) < math.pow(10, int(0 - digits)): + self.secZdiv[sZ] = ( + math.floor(self.secZ[sZ] / tolerances[3] * divisor) / divisor + + 0.0000001 + if self.secZ[sZ] >= 0.0 + else math.ceil(self.secZ[sZ] / tolerances[3] * divisor) / divisor + - 0.0000001 + ) elif self.secZ[sZ] >= 0: self.secZdiv[sZ] = 0.0000001 else: diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/trendHelper.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/trendHelper.py index c0b2ced7ec68c01f684bae541c60754e56aff4e7..b78ecd07cfe0f13298753b11b6c649910ec5f2c4 100644 --- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/trendHelper.py +++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/trendHelper.py @@ -13,32 +13,42 @@ from __future__ import print_function __authors__ = "Sam Maddrell-Mander, Claire Prouve, Paras Naik" __copyright__ = "University of Bristol, May 2018" -from PyMirrAlignOnline.fileFinder import fileFinder -from PyMirrAlignOnline.tiltObj import tiltObj -from ROOT import TCanvas, TGraph, gStyle, TMultiGraph, TLine, TPaveText, TDatime -from PyMirrAlignOnline.LHCbStyle import LHCbStyle -from datetime import datetime -import time import copy import getpass +import time +from datetime import datetime + +from ROOT import TCanvas, TDatime, TGraph, TLine, TMultiGraph, TPaveText, gStyle + +from PyMirrAlignOnline.fileFinder import fileFinder +from PyMirrAlignOnline.LHCbStyle import LHCbStyle +from PyMirrAlignOnline.tiltObj import tiltObj -#class Plotter(object): +# class Plotter(object): class Plotter: - def __init__(self, - RICH=1, - plotType='default', - trendXaxis="Numbers", - startDate=None, - endDate=None, - fileName=""): + def __init__( + self, + RICH=1, + plotType="default", + trendXaxis="Numbers", + startDate=None, + endDate=None, + fileName="", + ): self.whichRich = RICH self.plot_type = plotType # 'default' or 'hollow' self.trend_Xaxis = trendXaxis # "Numbers", "Fills" or "Dates" if fileName == "": - self.file_name = "/home/pnaik/2018trendplots/Rich" + str( - self.whichRich) + "_allin1_" + str(self.plot_type) + "_" + str( - self.trend_Xaxis) + "_current.pdf" + self.file_name = ( + "/home/pnaik/2018trendplots/Rich" + + str(self.whichRich) + + "_allin1_" + + str(self.plot_type) + + "_" + + str(self.trend_Xaxis) + + "_current.pdf" + ) # "/home/smaddrel/Mirrors/Rich"+str(self.whichRich)+"_allin1_"+str(self.plot_type)+"_YYYYMMDD.pdf" else: self.file_name = fileName @@ -67,78 +77,83 @@ class Plotter: self.exceptionList = [] if self.whichRich == 1: self.exceptionList += [ - '20170606_150337', - '20170611_143511', - '20170611_192654', - '20170612_004007', - '20170621_114735', - '20170621_142043', - '20170621_151343', - '20170621_153621', - '20170621_183028', - '20170705_184436', - '20170706_093538', - '20170706_160847', - '20170708_130756', - '20170708_145416', + "20170606_150337", + "20170611_143511", + "20170611_192654", + "20170612_004007", + "20170621_114735", + "20170621_142043", + "20170621_151343", + "20170621_153621", + "20170621_183028", + "20170705_184436", + "20170706_093538", + "20170706_160847", + "20170708_130756", + "20170708_145416", # '20170714_095506', - '20170715_161843', - '20170716_164021', - '20170717_173507', - '20170717_174549', - '20170717_175536', - '20170717_210458', - '20170717_212834', - '20170720_140020', # found on 18 December 2017, see JIRA RICH-47 - '20170720_215756', # found on 18 December 2017, see JIRA RICH-47 - '20170808_121449', - '20170808_150718', - '20170808_151700', - '20170808_152604', - '20170808_153952', - '20170808_155511', - '20170810_083727', - '20170810_085136', - '20170810_090208', - '20170810_091600', - '20170810_092531', - '20170810_110324', - '20170810_113408', - '20170814_144647', - '20170814_150050', - '20170814_152611', - '20171019_174630' + "20170715_161843", + "20170716_164021", + "20170717_173507", + "20170717_174549", + "20170717_175536", + "20170717_210458", + "20170717_212834", + "20170720_140020", # found on 18 December 2017, see JIRA RICH-47 + "20170720_215756", # found on 18 December 2017, see JIRA RICH-47 + "20170808_121449", + "20170808_150718", + "20170808_151700", + "20170808_152604", + "20170808_153952", + "20170808_155511", + "20170810_083727", + "20170810_085136", + "20170810_090208", + "20170810_091600", + "20170810_092531", + "20170810_110324", + "20170810_113408", + "20170814_144647", + "20170814_150050", + "20170814_152611", + "20171019_174630", ] if self.whichRich == 2: self.exceptionList += [ - '20170606_102357', - '20170610_211541', - '20170611_170020', - '20170611_175943', - '20170611_190207', - '20170611_201742', - '20170613_083436', - '20170621_180226', - '20170627_105541', - '20170705_185414', - '20170706_100355', - '20170706_162516', - '20170708_140804', + "20170606_102357", + "20170610_211541", + "20170611_170020", + "20170611_175943", + "20170611_190207", + "20170611_201742", + "20170613_083436", + "20170621_180226", + "20170627_105541", + "20170705_185414", + "20170706_100355", + "20170706_162516", + "20170708_140804", #'20170714_100603', - '20170715_162726', - '20170716_165032', - '20170720_141548', # found on 18 December 2017, see JIRA RICH-47 - '20170810_115802', - '20170810_152825', - '20170810_154107', - '20170810_155418', - '20170814_153345', - '20170814_154437' + "20170715_162726", + "20170716_165032", + "20170720_141548", # found on 18 December 2017, see JIRA RICH-47 + "20170810_115802", + "20170810_152825", + "20170810_154107", + "20170810_155418", + "20170814_153345", + "20170814_154437", ] def GetAlignments(self): - findFiles = fileFinder(self.whichRich, self.minDate, self.maxDate, - self.alignmentList, self.exceptionList) + findFiles = fileFinder( + self.whichRich, + self.minDate, + self.maxDate, + self.alignmentList, + self.exceptionList, + ) self.files = findFiles.findFiles() self.alignments = findFiles.alignments @@ -152,7 +167,7 @@ class Plotter: # Also, reject alignments that don't show up in # *both* self.alignments and the _UpdateTrend.txt file self.GetChanges_DB_Polarity() - ''' + """ # OLD: Manually provide list of alignment numbers # where the DB was updated, and another list of when the polarity was flipped self.DB_changes = [] @@ -166,7 +181,7 @@ class Plotter: self.polarity_changes += [19,49,90,137,151,153] if self.whichRich == 2: self.polarity_changes += [19,48,91,138,152,154] - ''' + """ if not self.alignments: print( @@ -175,11 +190,13 @@ class Plotter: return False else: self.minDateString = datetime.strptime( - self.alignments[0][0:8], '%Y%m%d').strftime('%Y/%m/%d') + self.alignments[0][0:8], "%Y%m%d" + ).strftime("%Y/%m/%d") self.maxDateString = datetime.strptime( - self.alignments[-1][0:8], '%Y%m%d').strftime('%Y/%m/%d') - #self.minDateString = datetime.strptime(str(self.minDate), '%Y%m%d').strftime('%Y/%m/%d') - #self.maxDateString = datetime.strptime(str(self.maxDate), '%Y%m%d').strftime('%Y/%m/%d') + self.alignments[-1][0:8], "%Y%m%d" + ).strftime("%Y/%m/%d") + # self.minDateString = datetime.strptime(str(self.minDate), '%Y%m%d').strftime('%Y/%m/%d') + # self.maxDateString = datetime.strptime(str(self.maxDate), '%Y%m%d').strftime('%Y/%m/%d') self.dateString = self.minDateString + " - " + self.maxDateString return True @@ -191,25 +208,25 @@ class Plotter: sys.stdout.flush() if self.whichRich == 1: from Configurables import Rich1MirrAlignOnConf - #from Configuration import Rich1MirrAlignOnConf + + # from Configuration import Rich1MirrAlignOnConf alignConf = Rich1MirrAlignOnConf() elif self.whichRich == 2: from Configurables import Rich2MirrAlignOnConf - #from Configuration import Rich2MirrAlignOnConf + + # from Configuration import Rich2MirrAlignOnConf alignConf = Rich2MirrAlignOnConf() else: - sys.stderr.write( - f"A detector named RICH{self.whichRich} does not exist.\n") + sys.stderr.write(f"A detector named RICH{self.whichRich} does not exist.\n") sys.exit(1) alignConf.__apply_configuration__() - #print("INFO: Configuration Applied") + # print("INFO: Configuration Applied") sys.stdout.flush() - richFilesDir = alignConf.getProp( - 'richFiles') # '/group/rich/AlignmentFiles/' + richFilesDir = alignConf.getProp("richFiles") # '/group/rich/AlignmentFiles/' f = open( - f'{richFilesDir}Logging/Rich' + str( - self.whichRich) + '_UpdateTrend.txt', 'r' + f"{richFilesDir}Logging/Rich" + str(self.whichRich) + "_UpdateTrend.txt", + "r", ) # Elements: Fill_Number Alignment_Directory_Name Version Polarity Collision_Type # self.align_num = [] # not needed since it will be the same as the index of self.alignments, after the alignments in self.ignore are removed self.align_fill = [] @@ -223,8 +240,10 @@ class Plotter: print("INFO: Reading in alignments trend file.") for line in f.readlines(): elements = line.split() - if len(elements) == 0: continue # reject blank lines - if '#' in elements[0]: continue # reject commented lines + if len(elements) == 0: + continue # reject blank lines + if "#" in elements[0]: + continue # reject commented lines if elements[1] not in self.alignments: self.align_ignore.append(elements[1]) # print('We removed alignment',elements[1],'because it is not in self.alignments') @@ -234,20 +253,21 @@ class Plotter: self.align_name.append(elements[1]) self.align_version.append(int(elements[2][1:])) if (num == 0) or ( - (num > 0) and - (self.align_version[-1] != self.align_version[-2])): + (num > 0) and (self.align_version[-1] != self.align_version[-2]) + ): (self.DB_changes).append(num) self.align_polarity.append(elements[3]) - if (num > 0) and (self.align_polarity[-1] != - self.align_polarity[-2]): + if (num > 0) and (self.align_polarity[-1] != self.align_polarity[-2]): (self.polarity_changes).append(num) num += 1 - print("INFO: Note that we skip alignments in Rich" + - str(self.whichRich) + - "_UpdateTrend.txt that do not appear in self.alignments") - #print("INFO: Skipped alignments: ", self.align_ignore) + print( + "INFO: Note that we skip alignments in Rich" + + str(self.whichRich) + + "_UpdateTrend.txt that do not appear in self.alignments" + ) + # print("INFO: Skipped alignments: ", self.align_ignore) for i in range(0, len(self.align_ignore), 6): - batch = self.align_ignore[i:i + 6] + batch = self.align_ignore[i : i + 6] if i == 0: print("INFO: Skipped alignments:", batch) else: @@ -257,10 +277,14 @@ class Plotter: # Note that an alignment not present in both self.alignments and _UpdateTrend.txt # is thusly never counted. print( - 'INFO: Also, note that we removed entries from self.alignments that do not appear in Rich' - + str(self.whichRich) + '_UpdateTrend.txt') - print("INFO: Removed alignments: ", - self.list_difference(self.alignments, self.align_name)) + "INFO: Also, note that we removed entries from self.alignments that do not appear in Rich" + + str(self.whichRich) + + "_UpdateTrend.txt" + ) + print( + "INFO: Removed alignments: ", + self.list_difference(self.alignments, self.align_name), + ) sys.stdout.flush() self.alignments = self.align_name # We assign it here so that the difference can be printed in the previous line. self.fills = self.align_fill @@ -268,8 +292,7 @@ class Plotter: # print('Check the alignment numbers:') # for i, a in enumerate(self.alignments): # print(i, a) - print( - 'INFO: Finished reading in alignments trend file, and determined:') + print("INFO: Finished reading in alignments trend file, and determined:") print("INFO: self.DB_changes =", self.DB_changes) print("INFO: self.polarity_changes =", self.polarity_changes) sys.stdout.flush() @@ -283,10 +306,10 @@ class Plotter: return [x for x in a if x not in b] def calculate_tilts(self): - if (self.whichRich == 1): + if self.whichRich == 1: self.maxpri = 3 self.maxsec = 15 - if (self.whichRich == 2): + if self.whichRich == 2: self.maxpri = 55 self.maxsec = 39 lhcbStyle = LHCbStyle() @@ -317,18 +340,20 @@ class Plotter: for i, alignment in enumerate(self.alignments): self.AlignmentSelector(i, self.plot_type) print(i, alignment, "is being compared to:", self.alignment_temp) - if '.yml' in self.files[self.alignment_temp][ - 1] and '.yml' in self.files[alignment][1]: # - self.tiltmaker.setChangeYAML([ - self.files[self.alignment_temp][1], - self.files[alignment][1] - ]) - elif '.xml' in self.files[self.alignment_temp][ - 1] and '.xml' in self.files[alignment][1]: # - self.tiltmaker.setChange([ - self.files[self.alignment_temp][1], - self.files[alignment][1] - ]) + if ( + ".yml" in self.files[self.alignment_temp][1] + and ".yml" in self.files[alignment][1] + ): # + self.tiltmaker.setChangeYAML( + [self.files[self.alignment_temp][1], self.files[alignment][1]] + ) + elif ( + ".xml" in self.files[self.alignment_temp][1] + and ".xml" in self.files[alignment][1] + ): # + self.tiltmaker.setChange( + [self.files[self.alignment_temp][1], self.files[alignment][1]] + ) else: print("ERROR: Trying to compare XML to YAML or vice versa") # self.tilts will be what it was for the previous "alignment in enumerate(self.alignments)" setChange @@ -338,12 +363,13 @@ class Plotter: hollow_markers = [24, 25, 26, 32] i_fill = int(self.fills[i]) dt = TDatime( - int(self.alignments[i][0:(0 + 4)]), - int(self.alignments[i][4:(4 + 2)]), - int(self.alignments[i][6:(6 + 2)]), - int(self.alignments[i][9:(9 + 2)]), - int(self.alignments[i][11:(11 + 2)]), - int(self.alignments[i][13:(13 + 2)])) + int(self.alignments[i][0 : (0 + 4)]), + int(self.alignments[i][4 : (4 + 2)]), + int(self.alignments[i][6 : (6 + 2)]), + int(self.alignments[i][9 : (9 + 2)]), + int(self.alignments[i][11 : (11 + 2)]), + int(self.alignments[i][13 : (13 + 2)]), + ) i_date = dt.Convert() # print(self.alignments[i], self.alignment_temp) for j in range(0, self.maxpri + 1): @@ -360,19 +386,25 @@ class Plotter: if i in self.DB_changes: if self.trend_Xaxis == "Fills": graphs_priY_flip[j].SetPoint( - self.DB_changes.index(i), i_fill, self.tilts[0][j]) + self.DB_changes.index(i), i_fill, self.tilts[0][j] + ) graphs_priZ_flip[j].SetPoint( - self.DB_changes.index(i), i_fill, self.tilts[1][j]) + self.DB_changes.index(i), i_fill, self.tilts[1][j] + ) elif self.trend_Xaxis == "Dates": graphs_priY_flip[j].SetPoint( - self.DB_changes.index(i), i_date, self.tilts[0][j]) + self.DB_changes.index(i), i_date, self.tilts[0][j] + ) graphs_priZ_flip[j].SetPoint( - self.DB_changes.index(i), i_date, self.tilts[1][j]) + self.DB_changes.index(i), i_date, self.tilts[1][j] + ) else: # self.trend_Xaxis == "Numbers" graphs_priY_flip[j].SetPoint( - self.DB_changes.index(i), i, self.tilts[0][j]) + self.DB_changes.index(i), i, self.tilts[0][j] + ) graphs_priZ_flip[j].SetPoint( - self.DB_changes.index(i), i, self.tilts[1][j]) + self.DB_changes.index(i), i, self.tilts[1][j] + ) for j in range(0, self.maxsec + 1): if self.trend_Xaxis == "Fills": graphs_secY[j].SetPoint(i, i_fill, self.tilts[2][j]) @@ -386,38 +418,46 @@ class Plotter: if i in self.DB_changes: if self.trend_Xaxis == "Fills": graphs_secY_flip[j].SetPoint( - self.DB_changes.index(i), i_fill, self.tilts[2][j]) + self.DB_changes.index(i), i_fill, self.tilts[2][j] + ) graphs_secZ_flip[j].SetPoint( - self.DB_changes.index(i), i_fill, self.tilts[3][j]) + self.DB_changes.index(i), i_fill, self.tilts[3][j] + ) elif self.trend_Xaxis == "Dates": graphs_secY_flip[j].SetPoint( - self.DB_changes.index(i), i_date, self.tilts[2][j]) + self.DB_changes.index(i), i_date, self.tilts[2][j] + ) graphs_secZ_flip[j].SetPoint( - self.DB_changes.index(i), i_date, self.tilts[3][j]) + self.DB_changes.index(i), i_date, self.tilts[3][j] + ) else: # self.trend_Xaxis == "Numbers" graphs_secY_flip[j].SetPoint( - self.DB_changes.index(i), i, self.tilts[2][j]) + self.DB_changes.index(i), i, self.tilts[2][j] + ) graphs_secZ_flip[j].SetPoint( - self.DB_changes.index(i), i, self.tilts[3][j]) + self.DB_changes.index(i), i, self.tilts[3][j] + ) n_minus_1 = len(self.alignments) - 1 i_fill_0 = int(self.fills[0]) dt_0 = TDatime( - int(self.alignments[0][0:(0 + 4)]), - int(self.alignments[0][4:(4 + 2)]), - int(self.alignments[0][6:(6 + 2)]), - int(self.alignments[0][9:(9 + 2)]), - int(self.alignments[0][11:(11 + 2)]), - int(self.alignments[0][13:(13 + 2)])) + int(self.alignments[0][0 : (0 + 4)]), + int(self.alignments[0][4 : (4 + 2)]), + int(self.alignments[0][6 : (6 + 2)]), + int(self.alignments[0][9 : (9 + 2)]), + int(self.alignments[0][11 : (11 + 2)]), + int(self.alignments[0][13 : (13 + 2)]), + ) i_date_0 = dt_0.Convert() i_fill_n_minus_1 = int(self.fills[n_minus_1]) dt_n_minus_1 = TDatime( - int(self.alignments[n_minus_1][0:(0 + 4)]), - int(self.alignments[n_minus_1][4:(4 + 2)]), - int(self.alignments[n_minus_1][6:(6 + 2)]), - int(self.alignments[n_minus_1][9:(9 + 2)]), - int(self.alignments[n_minus_1][11:(11 + 2)]), - int(self.alignments[n_minus_1][13:(13 + 2)])) + int(self.alignments[n_minus_1][0 : (0 + 4)]), + int(self.alignments[n_minus_1][4 : (4 + 2)]), + int(self.alignments[n_minus_1][6 : (6 + 2)]), + int(self.alignments[n_minus_1][9 : (9 + 2)]), + int(self.alignments[n_minus_1][11 : (11 + 2)]), + int(self.alignments[n_minus_1][13 : (13 + 2)]), + ) i_date_n_minus_1 = dt_n_minus_1.Convert() if self.trend_Xaxis == "Fills": x1 = i_fill_0 @@ -435,9 +475,9 @@ class Plotter: multisSecZ = TMultiGraph() markers_filled = [20, 21, 22, 23] hollow_markers = [24, 25, 26, 32] - if self.plot_type == 'default': + if self.plot_type == "default": markers = markers_filled - if self.plot_type == 'hollow': + if self.plot_type == "hollow": markers = hollow_markers if self.whichRich == 1: colour_valPri = 2 @@ -500,45 +540,45 @@ class Plotter: txt = TPaveText(0.20, 0.70, 0.45, 0.90, "NDC") if self.whichRich == 1: - txt.AddText('#scale[1.25]{LHCb RICH 1}') + txt.AddText("#scale[1.25]{LHCb RICH 1}") else: - txt.AddText('#scale[1.25]{LHCb RICH 2}') + txt.AddText("#scale[1.25]{LHCb RICH 2}") txt.SetFillStyle(1001) txt.SetBorderSize(0) txt.SetFillColor(0) - prim = TPaveText(0.72, 0.84, 0.86, 0.92, 'NDC') - prim.AddText('Primary Mirrors') + prim = TPaveText(0.72, 0.84, 0.86, 0.92, "NDC") + prim.AddText("Primary Mirrors") prim.SetFillColor(0) - seco = TPaveText(0.72, 0.82, 0.86, 0.90, 'NDC') - seco.AddText('Secondary Mirrors') + seco = TPaveText(0.72, 0.82, 0.86, 0.90, "NDC") + seco.AddText("Secondary Mirrors") seco.SetFillColor(0) - date = TPaveText(0.72, 0.22, 0.86, 0.30, 'NDC') - date.AddText( - self.dateString) # e.g. date.AddText( '2017/06/06 - 2017/11/26') + date = TPaveText(0.72, 0.22, 0.86, 0.30, "NDC") + date.AddText(self.dateString) # e.g. date.AddText( '2017/06/06 - 2017/11/26') date.SetFillColor(0) from ROOT import TLegend + leg = TLegend(0.72, 0.71, 0.86, 0.84) - leg2 = TPaveText(0.72, 0.72, 0.86, 0.82, 'NDC') + leg2 = TPaveText(0.72, 0.72, 0.86, 0.82, "NDC") if self.whichRich == 1: - leg.AddEntry(graphs_priY[0], "primary mirror 0", 'p') - leg.AddEntry(graphs_priY[1], "primary mirror 1", 'p') - leg.AddEntry(graphs_priY[2], "primary mirror 2", 'p') - leg.AddEntry(graphs_priY[3], "primary mirror 3", 'p') - leg2.AddText('Markers represent') - leg2.AddText('the 16 individual mirrors') + leg.AddEntry(graphs_priY[0], "primary mirror 0", "p") + leg.AddEntry(graphs_priY[1], "primary mirror 1", "p") + leg.AddEntry(graphs_priY[2], "primary mirror 2", "p") + leg.AddEntry(graphs_priY[3], "primary mirror 3", "p") + leg2.AddText("Markers represent") + leg2.AddText("the 16 individual mirrors") else: - leg = TPaveText(0.72, 0.72, 0.86, 0.82, 'NDC') - leg.AddText('Markers represent') - leg.AddText('the 56 individual mirrors') - leg2.AddText('Markers represent') - leg2.AddText('the 40 individual mirrors') + leg = TPaveText(0.72, 0.72, 0.86, 0.82, "NDC") + leg.AddText("Markers represent") + leg.AddText("the 56 individual mirrors") + leg2.AddText("Markers represent") + leg2.AddText("the 40 individual mirrors") leg.SetFillColor(0) leg.SetTextSize(0.04) leg.SetTextFont(132) leg2.SetFillColor(0) - leg2.SetTextSize(0.04) #0.03 + leg2.SetTextSize(0.04) # 0.03 leg2.SetTextFont(132) pri_upper = TLine(-0.5, 0.1, 14.5, 0.1) @@ -600,22 +640,24 @@ class Plotter: i_x = self.polarity_changes[x] i_fill_x = int(self.fills[i_x]) dt_x = TDatime( - int(self.alignments[i_x][0:(0 + 4)]), - int(self.alignments[i_x][4:(4 + 2)]), - int(self.alignments[i_x][6:(6 + 2)]), - int(self.alignments[i_x][9:(9 + 2)]), - int(self.alignments[i_x][11:(11 + 2)]), - int(self.alignments[i_x][13:(13 + 2)])) + int(self.alignments[i_x][0 : (0 + 4)]), + int(self.alignments[i_x][4 : (4 + 2)]), + int(self.alignments[i_x][6 : (6 + 2)]), + int(self.alignments[i_x][9 : (9 + 2)]), + int(self.alignments[i_x][11 : (11 + 2)]), + int(self.alignments[i_x][13 : (13 + 2)]), + ) i_date_x = dt_x.Convert() pre_i_x = i_x - 1 pre_i_fill_x = int(self.fills[pre_i_x]) pre_dt_x = TDatime( - int(self.alignments[pre_i_x][0:(0 + 4)]), - int(self.alignments[pre_i_x][4:(4 + 2)]), - int(self.alignments[pre_i_x][6:(6 + 2)]), - int(self.alignments[pre_i_x][9:(9 + 2)]), - int(self.alignments[pre_i_x][11:(11 + 2)]), - int(self.alignments[pre_i_x][13:(13 + 2)])) + int(self.alignments[pre_i_x][0 : (0 + 4)]), + int(self.alignments[pre_i_x][4 : (4 + 2)]), + int(self.alignments[pre_i_x][6 : (6 + 2)]), + int(self.alignments[pre_i_x][9 : (9 + 2)]), + int(self.alignments[pre_i_x][11 : (11 + 2)]), + int(self.alignments[pre_i_x][13 : (13 + 2)]), + ) pre_i_date_x = pre_dt_x.Convert() if self.trend_Xaxis == "Fills": x_flip = i_fill_x - (i_fill_x - pre_i_fill_x) / 2 @@ -623,40 +665,44 @@ class Plotter: x_flip = i_date_x - (i_date_x - pre_i_date_x) / 2 else: # self.trend_Xaxis == "Numbers" x_flip = i_x - 0.5 - flips_pY_17[x] = TLine(x_flip, -4 * pY_17, x_flip, - 4 * pY_17) # large vertical limits + flips_pY_17[x] = TLine( + x_flip, -4 * pY_17, x_flip, 4 * pY_17 + ) # large vertical limits flips_pY_17[x].SetLineStyle(7) - flips_pZ_17[x] = TLine(x_flip, -4 * pZ_17, x_flip, - 4 * pZ_17) # large vertical limits + flips_pZ_17[x] = TLine( + x_flip, -4 * pZ_17, x_flip, 4 * pZ_17 + ) # large vertical limits flips_pZ_17[x].SetLineStyle(7) - flips_sY_17[x] = TLine(x_flip, -4 * sY_17, x_flip, - 4 * sY_17) # large vertical limits + flips_sY_17[x] = TLine( + x_flip, -4 * sY_17, x_flip, 4 * sY_17 + ) # large vertical limits flips_sY_17[x].SetLineStyle(7) - flips_sZ_17[x] = TLine(x_flip, -4 * sZ_17, x_flip, - 4 * sZ_17) # large vertical limits + flips_sZ_17[x] = TLine( + x_flip, -4 * sZ_17, x_flip, 4 * sZ_17 + ) # large vertical limits flips_sZ_17[x].SetLineStyle(7) ## Magnet polarity switches for Primary [2016?, whichRich?] - #flip1 = TLine(5.5, -0.3, 5.5, 0.3) - #flip1.SetLineStyle(7) - #flip2 = TLine(10.5, -0.3, 10.5, 0.3) - #flip2.SetLineStyle(7) - #flip3 = TLine(19.5, -0.3, 19.5, 0.3) - #flip3.SetLineStyle(7) - #flip4 = TLine(26.5, -0.3, 26.5, 0.3) - #flip4.SetLineStyle(7) + # flip1 = TLine(5.5, -0.3, 5.5, 0.3) + # flip1.SetLineStyle(7) + # flip2 = TLine(10.5, -0.3, 10.5, 0.3) + # flip2.SetLineStyle(7) + # flip3 = TLine(19.5, -0.3, 19.5, 0.3) + # flip3.SetLineStyle(7) + # flip4 = TLine(26.5, -0.3, 26.5, 0.3) + # flip4.SetLineStyle(7) ## Magnet polarity switches for Secondary [2016?, whichRich?] - #flip1s = TLine(5.5, -0.65, 5.5, 0.65) - #flip1s.SetLineStyle(7) - #flip2s = TLine(10.5, -0.65, 10.5, 0.65) - #flip2s.SetLineStyle(7) - #flip3s = TLine(19.5, -0.65, 19.5, 0.65) - #flip3s.SetLineStyle(7) - #flip4s = TLine(26.5, -0.65, 26.5, 0.65) - #flip4s.SetLineStyle(7) - - cPlot = TCanvas('hasi', 'masi', 7500, 1500) + # flip1s = TLine(5.5, -0.65, 5.5, 0.65) + # flip1s.SetLineStyle(7) + # flip2s = TLine(10.5, -0.65, 10.5, 0.65) + # flip2s.SetLineStyle(7) + # flip3s = TLine(19.5, -0.65, 19.5, 0.65) + # flip3s.SetLineStyle(7) + # flip4s = TLine(26.5, -0.65, 26.5, 0.65) + # flip4s.SetLineStyle(7) + + cPlot = TCanvas("hasi", "masi", 7500, 1500) cPlot.SetLeftMargin(0.05) cPlot.SetRightMargin(0.05) cPlot.SaveAs(self.file_name + "[") @@ -668,7 +714,7 @@ class Plotter: else: # self.trend_Xaxis == "Numbers" title_Xaxis = "Alignment number [a.u.]" - multisPriY.Draw('AP') + multisPriY.Draw("AP") multisPriY.GetXaxis().SetTitle(title_Xaxis) if self.trend_Xaxis == "Dates": multisPriY.GetXaxis().SetTimeDisplay(1) @@ -678,25 +724,25 @@ class Plotter: multisPriY.GetYaxis().SetTitle("Local Y rotation [mrad]") multisPriY.GetYaxis().SetTitleOffset(0.30) for x in range(0, len(flips_pY_17)): - flips_pY_17[x].Draw('same') - pY_17_line1.Draw('same') - pY_17_line2.Draw('same') - txt.InsertText('#scale[0.75]{Preliminary}') - txt.Draw('same') - #prim.InsertText('Primary Mirror') - prim.Draw('same') - date.Draw('same') - leg.Draw('same') - middle.Draw('same') - #pri_upper.Draw('same') - #pri_lower.Draw('same') - #flip1.Draw('same') - #flip2.Draw('same') - #flip3.Draw('same') - #flip4.Draw('same') + flips_pY_17[x].Draw("same") + pY_17_line1.Draw("same") + pY_17_line2.Draw("same") + txt.InsertText("#scale[0.75]{Preliminary}") + txt.Draw("same") + # prim.InsertText('Primary Mirror') + prim.Draw("same") + date.Draw("same") + leg.Draw("same") + middle.Draw("same") + # pri_upper.Draw('same') + # pri_lower.Draw('same') + # flip1.Draw('same') + # flip2.Draw('same') + # flip3.Draw('same') + # flip4.Draw('same') cPlot.SaveAs(self.file_name) - multisPriZ.Draw('AP') + multisPriZ.Draw("AP") multisPriZ.GetXaxis().SetTitle(title_Xaxis) if self.trend_Xaxis == "Dates": multisPriZ.GetXaxis().SetTimeDisplay(1) @@ -706,23 +752,23 @@ class Plotter: multisPriZ.GetYaxis().SetTitle("Local Z rotation [mrad]") multisPriZ.GetYaxis().SetTitleOffset(0.30) for x in range(0, len(flips_pY_17)): - flips_pZ_17[x].Draw('same') - pZ_17_line1.Draw('same') - pZ_17_line2.Draw('same') - txt.Draw('same') - prim.Draw('same') - date.Draw('same') - leg.Draw('same') - #pri_upper.Draw('same') - #pri_lower.Draw('same') - #flip1.Draw('same') - #flip2.Draw('same') - #flip3.Draw('same') - #flip4.Draw('same') - middle.Draw('same') + flips_pZ_17[x].Draw("same") + pZ_17_line1.Draw("same") + pZ_17_line2.Draw("same") + txt.Draw("same") + prim.Draw("same") + date.Draw("same") + leg.Draw("same") + # pri_upper.Draw('same') + # pri_lower.Draw('same') + # flip1.Draw('same') + # flip2.Draw('same') + # flip3.Draw('same') + # flip4.Draw('same') + middle.Draw("same") cPlot.SaveAs(self.file_name) - multisSecY.Draw('AP') + multisSecY.Draw("AP") multisSecY.GetXaxis().SetTitle(title_Xaxis) if self.trend_Xaxis == "Dates": multisSecY.GetXaxis().SetTimeDisplay(1) @@ -732,24 +778,24 @@ class Plotter: multisSecY.GetYaxis().SetTitle("Local Y rotation [mrad]") multisSecY.GetYaxis().SetTitleOffset(0.30) for x in range(0, len(flips_sY_17)): - flips_sY_17[x].Draw('same') - sY_17_line1.Draw('same') - sY_17_line2.Draw('same') - txt.Draw('same') - leg2.Draw('same') - #leg2b.Draw('same') - date.Draw('same') - middle.Draw('same') - #sec_upper.Draw('same') - #sec_lower.Draw('same') - #flip1s.Draw('same') - #flip2s.Draw('same') - #flip3s.Draw('same') - #flip4s.Draw('same') - seco.Draw('same') + flips_sY_17[x].Draw("same") + sY_17_line1.Draw("same") + sY_17_line2.Draw("same") + txt.Draw("same") + leg2.Draw("same") + # leg2b.Draw('same') + date.Draw("same") + middle.Draw("same") + # sec_upper.Draw('same') + # sec_lower.Draw('same') + # flip1s.Draw('same') + # flip2s.Draw('same') + # flip3s.Draw('same') + # flip4s.Draw('same') + seco.Draw("same") cPlot.SaveAs(self.file_name) - multisSecZ.Draw('AP') + multisSecZ.Draw("AP") multisSecZ.GetXaxis().SetTitle(title_Xaxis) if self.trend_Xaxis == "Dates": multisSecZ.GetXaxis().SetTimeDisplay(1) @@ -759,39 +805,40 @@ class Plotter: multisSecZ.GetYaxis().SetTitle("Local Z rotation [mrad]") multisSecZ.GetYaxis().SetTitleOffset(0.30) for x in range(0, len(flips_sZ_17)): - flips_sZ_17[x].Draw('same') - sZ_17_line1.Draw('same') - sZ_17_line2.Draw('same') - txt.Draw('same') - leg2.Draw('same') - #leg2b.Draw('same') - date.Draw('same') - middle.Draw('same') - #sec_upper.Draw('same') - #sec_lower.Draw('same') - #flip1s.Draw('same') - #flip2s.Draw('same') - #flip3s.Draw('same') - #flip4s.Draw('same') - seco.Draw('same') + flips_sZ_17[x].Draw("same") + sZ_17_line1.Draw("same") + sZ_17_line2.Draw("same") + txt.Draw("same") + leg2.Draw("same") + # leg2b.Draw('same') + date.Draw("same") + middle.Draw("same") + # sec_upper.Draw('same') + # sec_lower.Draw('same') + # flip1s.Draw('same') + # flip2s.Draw('same') + # flip3s.Draw('same') + # flip4s.Draw('same') + seco.Draw("same") cPlot.SaveAs(self.file_name) cPlot.SaveAs(self.file_name + "]") pass - def AlignmentSelector(self, i, version='default'): + def AlignmentSelector(self, i, version="default"): self.DB_rangepoints = copy.deepcopy(self.DB_changes) self.DB_rangepoints += [999999] # just some ridiculously large number offset = 0 - if version == 'hollow': + if version == "hollow": offset += 1 if i == 0: self.alignment_temp = self.alignments[self.DB_changes[0]] else: for x in range(1, len(self.DB_changes)): if i >= (self.DB_rangepoints[x] + offset) and ( - i < self.DB_rangepoints[x + 1] + offset): + i < self.DB_rangepoints[x + 1] + offset + ): self.alignment_temp = self.alignments[self.DB_changes[x]] pass @@ -805,58 +852,58 @@ def main(): # for now run both in sequence print("INFO: Now making default plot for RICH1 with Numbers on x-axis") - P1 = Plotter(1, 'default', "Numbers", None, None, "") + P1 = Plotter(1, "default", "Numbers", None, None, "") P1.GetAlignments() P1.calculate_tilts() print("INFO: Now making default plot for RICH2 with Numbers on x-axis") - P2 = Plotter(2, 'default', "Numbers", None, None, "") + P2 = Plotter(2, "default", "Numbers", None, None, "") P2.GetAlignments() P2.calculate_tilts() print("INFO: Now making hollow plot for RICH1 with Numbers on x-axis") - P1_hollow = Plotter(1, 'hollow', "Numbers", None, None, "") + P1_hollow = Plotter(1, "hollow", "Numbers", None, None, "") P1_hollow.GetAlignments() P1_hollow.calculate_tilts() print("INFO: Now making hollow plot for RICH2 with Numbers on x-axis") - P2_hollow = Plotter(2, 'hollow', "Numbers", None, None, "") + P2_hollow = Plotter(2, "hollow", "Numbers", None, None, "") P2_hollow.GetAlignments() P2_hollow.calculate_tilts() print("INFO: Now making default plot for RICH1 with Fills on x-axis") - P1 = Plotter(1, 'default', "Fills", None, None, "") + P1 = Plotter(1, "default", "Fills", None, None, "") P1.GetAlignments() P1.calculate_tilts() print("INFO: Now making default plot for RICH2 with Fills on x-axis") - P2 = Plotter(2, 'default', "Fills", None, None, "") + P2 = Plotter(2, "default", "Fills", None, None, "") P2.GetAlignments() P2.calculate_tilts() print("INFO: Now making hollow plot for RICH1 with Fills on x-axis") - P1_hollow = Plotter(1, 'hollow', "Fills", None, None, "") + P1_hollow = Plotter(1, "hollow", "Fills", None, None, "") P1_hollow.GetAlignments() P1_hollow.calculate_tilts() print("INFO: Now making hollow plot for RICH2 with Fills on x-axis") - P2_hollow = Plotter(2, 'hollow', "Fills", None, None, "") + P2_hollow = Plotter(2, "hollow", "Fills", None, None, "") P2_hollow.GetAlignments() P2_hollow.calculate_tilts() print("INFO: Now making default plot for RICH1 with Dates on x-axis") - P1 = Plotter(1, 'default', "Dates", None, None, "") + P1 = Plotter(1, "default", "Dates", None, None, "") P1.GetAlignments() P1.calculate_tilts() print("INFO: Now making default plot for RICH2 with Dates on x-axis") - P2 = Plotter(2, 'default', "Dates", None, None, "") + P2 = Plotter(2, "default", "Dates", None, None, "") P2.GetAlignments() P2.calculate_tilts() print("INFO: Now making hollow plot for RICH1 with Dates on x-axis") - P1_hollow = Plotter(1, 'hollow', "Dates", None, None, "") + P1_hollow = Plotter(1, "hollow", "Dates", None, None, "") P1_hollow.GetAlignments() P1_hollow.calculate_tilts() print("INFO: Now making hollow plot for RICH2 with Dates on x-axis") - P2_hollow = Plotter(2, 'hollow', "Dates", None, None, "") + P2_hollow = Plotter(2, "hollow", "Dates", None, None, "") P2_hollow.GetAlignments() P2_hollow.calculate_tilts() pass -if __name__ == '__main__': +if __name__ == "__main__": main() diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/unbiased_fitter.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/unbiased_fitter.py index de86bd050f3bf9a095c53853968022f7b0fa73f7..bd9818cb5f7aca6f51073db70ce502e5bffdf01a 100644 --- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/unbiased_fitter.py +++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/unbiased_fitter.py @@ -9,33 +9,40 @@ # granted to it by virtue of its status as an Intergovernmental Organization # # or submit itself to any jurisdiction. # ############################################################################### +import argparse +import csv +import json import os +import random import re -import sys import subprocess -import csv -import argparse -import random - import sys -import numpy as np -from ROOT import gROOT, TH1D, TCanvas, TFile, TF1, gStyle, TGraph, TMultiGraph, TLine, TH2D, TExec -from scipy.optimize import minimize -import json +import numpy as np from GaudiPython import gbl +from ROOT import ( + TF1, + TH1D, + TH2D, + TCanvas, + TExec, + TFile, + TGraph, + TLine, + TMultiGraph, + gROOT, + gStyle, +) +from scipy.optimize import minimize # Set batch mode so histograms aren't printed -#sys.argv.append('-b') +# sys.argv.append('-b') gROOT.SetBatch(True) -parser = argparse.ArgumentParser( - description="Run optimisation on RICH panel alignment") +parser = argparse.ArgumentParser(description="Run optimisation on RICH panel alignment") parser.add_argument( - '--whichRich', - type=int, - choices=[1, 2], - help='Which RICH panel to optimise') + "--whichRich", type=int, choices=[1, 2], help="Which RICH panel to optimise" +) args = parser.parse_args() whichRich = int(args.whichRich) @@ -45,49 +52,58 @@ prepath = os.getcwd() class AlignMonitor: - def __init__(self, - whichRich, - fitrange=0.0055 - # _alignConf, - # _maxIt, - ): - ''' + def __init__( + self, + whichRich, + fitrange=0.0055, + # _alignConf, + # _maxIt, + ): + """ self.alignConf = _alignConf self.nameStr = self.alignConf.getProp('nameStr') self.whichRich = self.alignConf.getProp('Rich') self.displayMode = self.alignConf.getProp('displayMode') self.warningFactor = self.alignConf.getProp('warningFactor') self.maxIt = _maxIt # the maximum labeled number of the iterations that we are looping through - ''' - self.workdir = './' + """ + self.workdir = "./" self.whichRich = whichRich self.maxIt = 0 - self.prename = f'{prepath}/rich{whichRich}_opt_dd4hep_p{whichPanel}.root' + self.prename = f"{prepath}/rich{whichRich}_opt_dd4hep_p{whichPanel}.root" # RICH1 settings self.maxpri = 3 self.binToPriMirr = [[2, 3], [0, 1]] self.maxsec = 15 - self.binToSecMirr = [[10, 11, 14, 15], [8, 9, 12, 13], [2, 3, 6, 7], - [0, 1, 4, 5]] + self.binToSecMirr = [ + [10, 11, 14, 15], + [8, 9, 12, 13], + [2, 3, 6, 7], + [0, 1, 4, 5], + ] self.fitMin = -fitrange self.fitMax = fitrange # if RICH2, use RICH2 settings - if (self.whichRich == 2): + if self.whichRich == 2: self.maxpri = 55 - self.binToPriMirr = [[3, 2, 1, 0, 31, 30, 29, 28], - [7, 6, 5, 4, 35, 34, 33, 32], - [11, 10, 9, 8, 39, 38, 37, 36], - [15, 14, 13, 12, 43, 42, 41, 40], - [19, 18, 17, 16, 47, 46, 45, 44], - [23, 22, 21, 20, 51, 50, 49, 48], - [27, 26, 25, 24, 55, 54, 53, 52]] + self.binToPriMirr = [ + [3, 2, 1, 0, 31, 30, 29, 28], + [7, 6, 5, 4, 35, 34, 33, 32], + [11, 10, 9, 8, 39, 38, 37, 36], + [15, 14, 13, 12, 43, 42, 41, 40], + [19, 18, 17, 16, 47, 46, 45, 44], + [23, 22, 21, 20, 51, 50, 49, 48], + [27, 26, 25, 24, 55, 54, 53, 52], + ] self.maxsec = 39 - self.binToSecMirr = [[3, 2, 1, 0, 23, 22, 21, 20], - [7, 6, 5, 4, 27, 26, 25, 24], - [11, 10, 9, 8, 31, 30, 29, 28], - [15, 14, 13, 12, 35, 34, 33, 32], - [19, 18, 17, 16, 39, 38, 37, 36]] + self.binToSecMirr = [ + [3, 2, 1, 0, 23, 22, 21, 20], + [7, 6, 5, 4, 27, 26, 25, 24], + [11, 10, 9, 8, 31, 30, 29, 28], + [15, 14, 13, 12, 35, 34, 33, 32], + [19, 18, 17, 16, 39, 38, 37, 36], + ] # Original fit range self.fitMin = -fitrange self.fitMax = fitrange @@ -100,6 +116,7 @@ class AlignMonitor: def performMonitoring(self, p, hist_path=""): import os + gStyle.SetOptFit(1111) gStyle.SetOptStat(000000000) @@ -109,17 +126,17 @@ class AlignMonitor: pdf_suff = "_" + hist_path.split("/")[-1] # File for the RICH piquet AND for the RICH mirror alignment experts - expertFile = f'TESTING.pdf' + expertFile = f"TESTING.pdf" # File for the Alignment piquet ("duplicating" what goes to the Presenter for the Data Manager [except CK angle res stuff]) - monitorFile = self.workdir + f'Rich{self.whichRich}_AlignMonitor.pdf' + monitorFile = self.workdir + f"Rich{self.whichRich}_AlignMonitor.pdf" # File with for testing purposes - testingFile = self.workdir + f'Rich{self.whichRich}_AlignTesting.pdf' + testingFile = self.workdir + f"Rich{self.whichRich}_AlignTesting.pdf" # Data Manager can only get histograms sent via self.monSvc - theCanvas = TCanvas('theCanvas', 'MirrAlign') + theCanvas = TCanvas("theCanvas", "MirrAlign") theCanvas.Divide(2, 2, 0.001, 0.001) - theCanvas2 = TCanvas('theCanvas2', 'MirrAlignTest') + theCanvas2 = TCanvas("theCanvas2", "MirrAlignTest") theCanvas2.Divide(2, 2, 0.001, 0.001) theCanvas2.Clear() @@ -156,31 +173,38 @@ class AlignMonitor: # define resHistoTrend resHistoTrend = TH1D( - 'resHistoTrend', 'RICH' + str(self.whichRich) + - ' Cherenkov angle resolution (mrad) per It. ', self.maxIt + 1, - -0.5, self.maxIt + 0.5) + "resHistoTrend", + "RICH" + + str(self.whichRich) + + " Cherenkov angle resolution (mrad) per It. ", + self.maxIt + 1, + -0.5, + self.maxIt + 0.5, + ) for j in reversed(range(0, self.maxIt + 1)): filename[j] = self.prename if os.path.exists(filename[j]): - thisFile[j] = TFile(filename[j], 'read') + thisFile[j] = TFile(filename[j], "read") if hist_path == "": - hist[j] = (thisFile[j].Get( - f'RICH/RiCKResLongTight/Rich{self.whichRich}Gas/ckResAll' - )).Clone() + hist[j] = ( + thisFile[j].Get( + f"RICH/RiCKResLongTight/Rich{self.whichRich}Gas/ckResAll" + ) + ).Clone() else: - hist[j] = (thisFile[j].Get(f'{hist_path}')).Clone() + hist[j] = (thisFile[j].Get(f"{hist_path}")).Clone() if (j == 0) and (j == self.maxIt): - hist[j].SetName('resHisto0') - hist[j].SetName('resHistoN') - elif (j == self.maxIt): - hist[j].SetName('resHistoN') - elif (j == 0): - hist[j].SetName('resHisto0') - if (j != 0): - hist[j].SetName('resHisto' + str(j)) + hist[j].SetName("resHisto0") + hist[j].SetName("resHistoN") + elif j == self.maxIt: + hist[j].SetName("resHistoN") + elif j == 0: + hist[j].SetName("resHisto0") + if j != 0: + hist[j].SetName("resHisto" + str(j)) # perform the fit and extract fit models fitRes[j], resHistograms[j] = self.fitCherenkovAngle(hist[j]) @@ -203,12 +227,15 @@ class AlignMonitor: resHistoTrend.SetBinContent(j + 1, 100) resHistoTrend.SetBinError(j + 1, 100) - title[j] = 'RICH' + str( - self.whichRich - ) + ' Cherenkov angle resolution It. ' + str(j) + title[j] = ( + "RICH" + + str(self.whichRich) + + " Cherenkov angle resolution It. " + + str(j) + ) hist[j].SetTitle(title[j]) - hist[j].SetXTitle('#Delta#theta_{Cherenkov} (rad)') - hist[j].SetYTitle('Entries') + hist[j].SetXTitle("#Delta#theta_{Cherenkov} (rad)") + hist[j].SetYTitle("Entries") gStyle.SetStatW(0.11) @@ -223,9 +250,10 @@ class AlignMonitor: # Make resHistoTrend iteration trend plot resHistoTrend.SetMarkerStyle(8) - resHistoTrend.SetXTitle('iteration number') + resHistoTrend.SetXTitle("iteration number") resHistoTrend.SetYTitle( - '#splitline{Cherenkov angle resolution (mrad)}{}') + "#splitline{Cherenkov angle resolution (mrad)}{}" + ) theCanvas2.Clear() theCanvas.Clear() @@ -242,24 +270,38 @@ class AlignMonitor: resHistoTrend.SetBinContent(j + 1, ckres) resHistoTrend.SetBinError(j + 1, ckres_error) - print("_i" + str(j) + " CK angle resolution: " + - str(ckres) + " mrad.") - print("_i" + str(j) + " CK angle resolution err: " + - str(ckres_error) + " mrad.") - print("_i" + str(j) + " CK angle gaussian mean: " + - str(gaussianmean) + " mrad.") + print( + "_i" + str(j) + " CK angle resolution: " + str(ckres) + " mrad." + ) + print( + "_i" + + str(j) + + " CK angle resolution err: " + + str(ckres_error) + + " mrad." + ) + print( + "_i" + + str(j) + + " CK angle gaussian mean: " + + str(gaussianmean) + + " mrad." + ) if j == self.maxIt: self.finalCKres = ckres self.finalCKresErr = ckres_error self.finalCKgaussianmean = gaussianmean - title[j] = 'RICH' + str( - self.whichRich) + ' Cherenkov angle resolution It. ' + str( - j) + title[j] = ( + "RICH" + + str(self.whichRich) + + " Cherenkov angle resolution It. " + + str(j) + ) resHistograms[j].SetTitle(title[j]) - resHistograms[j].SetXTitle('#Delta#theta_{Cherenkov} (rad)') - resHistograms[j].SetYTitle('Entries') + resHistograms[j].SetXTitle("#Delta#theta_{Cherenkov} (rad)") + resHistograms[j].SetYTitle("Entries") histFunc[j].SetLineColor(2) polbkg[j].SetLineColor(4) @@ -283,15 +325,14 @@ class AlignMonitor: else: print("WARNING: " + filename[j] + ": does not exist") - #theCanvas.Print(monitorFile) + # theCanvas.Print(monitorFile) # sys.stdout.flush() # Make resHistoTrend iteration trend plot resHistoTrend.SetMarkerStyle(8) - resHistoTrend.SetXTitle('iteration number') - resHistoTrend.SetYTitle( - '#splitline{Cherenkov angle resolution (mrad)}{}') + resHistoTrend.SetXTitle("iteration number") + resHistoTrend.SetYTitle("#splitline{Cherenkov angle resolution (mrad)}{}") theCanvas2.Clear() theCanvas.Clear() @@ -301,14 +342,12 @@ class AlignMonitor: sys.stdout.flush() def fitCherenkovAngle(self, hist): - # get Chris Jones's C++ fitter fitter = gbl.Rich.Rec.CKResolutionFitter() # set signal (AsymNormal) and background (FreeNPol) models fitter.params().RichFitTypes[whichRich - 1].clear() - fitter.params().RichFitTypes[whichRich - - 1].push_back("AsymNormal:FreeNPol") + fitter.params().RichFitTypes[whichRich - 1].push_back("AsymNormal:FreeNPol") # change fit ranges fitter.params().RichFitMin[0] = self.fitMin @@ -322,16 +361,11 @@ class AlignMonitor: def check_for_reco_issues(finalCKres, finalCKresErr, csv_name): - issue_present = False - if (os.path.exists( - f'ck_vs_param_R{whichRich}_{survey_type}_{csv_name}.csv')): - - with open(f'ck_vs_param_R{whichRich}_{survey_type}_{csv_name}.csv', - 'r') as f: - reader = csv.reader(f, delimiter=',') + if os.path.exists(f"ck_vs_param_R{whichRich}_{survey_type}_{csv_name}.csv"): + with open(f"ck_vs_param_R{whichRich}_{survey_type}_{csv_name}.csv", "r") as f: + reader = csv.reader(f, delimiter=",") for row in reader: - if float(finalCKresErr) == 0.0: issue_present = True print( @@ -345,9 +379,8 @@ def check_for_reco_issues(finalCKres, finalCKresErr, csv_name): def perform_one_fit_pipeline(hist_path="", fitrange=0.0055): - panel = whichPanel - axis_name = 'x' + axis_name = "x" alignMonitor = AlignMonitor(whichRich=whichRich, fitrange=fitrange) alignMonitor.performMonitoring(panel, hist_path) @@ -361,9 +394,11 @@ def perform_one_fit_pipeline(hist_path="", fitrange=0.0055): # finalCKres, finalCKresErr, finalCKgaussianmean = perform_one_fit_pipeline(fitrange=0.0055) if whichRich == 1: finalCKres, finalCKresErr, finalCKgaussianmean = perform_one_fit_pipeline( - fitrange=0.0055) + fitrange=0.0055 + ) elif whichRich == 2: finalCKres, finalCKresErr, finalCKgaussianmean = perform_one_fit_pipeline( - fitrange=0.0035) + fitrange=0.0035 + ) print(finalCKres, finalCKresErr, finalCKgaussianmean) diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/unbiased_reconstruction.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/unbiased_reconstruction.py index 3f825e12834c1c2a15473c977575287d61ebd513..7d851f23ef2dfeab126a00e688858d8b801b33d1 100644 --- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/unbiased_reconstruction.py +++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/unbiased_reconstruction.py @@ -9,49 +9,54 @@ # granted to it by virtue of its status as an Intergovernmental Organization # # or submit itself to any jurisdiction. # ############################################################################### -import glob +import argparse import csv +import glob import math -import sys import random -import argparse +import sys -from GaudiKernel.SystemOfUnits import (GeV, MeV, mm, mrad) +from GaudiKernel.SystemOfUnits import GeV, MeV, mm, mrad from Moore import ( options, run_reconstruction, ) - -from PyConf.Algorithms import (PrForwardTrackingVelo, - VPRetinaFullClusterDecoder) -from PyConf.Algorithms import VeloRetinaClusterTrackingSIMD -from PyConf.Algorithms import PrMatchNN, PrHybridSeeding +from Panoptes.alignment import ( + standalone_rich_online_align_reco, + standalone_rich_panel_align_reco, +) +from PyConf.Algorithms import ( + PrForwardTrackingVelo, + PrHybridSeeding, + PrMatchNN, + VeloRetinaClusterTrackingSIMD, + VPRetinaFullClusterDecoder, +) from RecoConf.legacy_rec_hlt1_tracking import ( - make_VeloClusterTrackingSIMD, make_reco_pvs, make_PatPV3DFuture_pvs, - make_velo_full_clusters) - + make_PatPV3DFuture_pvs, + make_reco_pvs, + make_velo_full_clusters, + make_VeloClusterTrackingSIMD, +) from RecoConf.rich_data_monitoring import ( - default_rich_monitoring_options, alignment_rich_monitoring_options, + default_rich_monitoring_options, ) - from RecoConf.rich_reconstruction import default_rich_reco_options -from Panoptes.alignment import ( - standalone_rich_online_align_reco, - standalone_rich_panel_align_reco, -) """Options for running over data with FT raw bank version 6.""" from RecoConf.decoders import ( - default_ft_decoding_version, ) + default_ft_decoding_version, +) # load options from YAML file from ruamel.yaml import YAML + yaml = YAML() whichRich = 2 whichPanel = "both" -survey_type = 'TESTING' +survey_type = "TESTING" manual_update = True @@ -81,11 +86,12 @@ base_dir_files = f"/calib/align/LHCb/Rich{whichRich}" def obtain_files_from_many_runs( - base_dir_files, - start_run, - end_run, - num_files_to_select=2, # this is per run number - seed_value=100): + base_dir_files, + start_run, + end_run, + num_files_to_select=2, # this is per run number + seed_value=100, +): files = [] for folder_number in range(start_run, end_run + 1): @@ -94,15 +100,14 @@ def obtain_files_from_many_runs( # Check if the folder exists if os.path.exists(folder_path) and os.path.isdir(folder_path): - # List all files in the folder files_in_folder = os.listdir(folder_path) # Select random files from the folder random.seed(seed_value) random_files = random.sample( - files_in_folder, min(num_files_to_select, - len(files_in_folder))) + files_in_folder, min(num_files_to_select, len(files_in_folder)) + ) # Print the selected files for file_name in random_files: @@ -115,45 +120,45 @@ options.input_files = obtain_files_from_many_runs( # base_dir_files, 299618, 299683) base_dir_files, 298656, - 300124) + 300124, +) options.simulation = False options.input_type = "MDF" +from Configurables import DDDBConf from Configurables import LHCb__Det__LbDD4hep__DD4hepSvc as DD4hepSvc from DDDB.CheckDD4Hep import UseDD4Hep -from Configurables import DDDBConf - useUT_bool = True if useUT_bool: dd4hep = DD4hepSvc( - DetectorList=["/world", "Magnet", "UT", "VP", "FT", "Rich1", "Rich2"]) + DetectorList=["/world", "Magnet", "UT", "VP", "FT", "Rich1", "Rich2"] + ) noUT_bool = False else: - dd4hep = DD4hepSvc( - DetectorList=["/world", "Magnet", "VP", "FT", "Rich1", "Rich2"]) + dd4hep = DD4hepSvc(DetectorList=["/world", "Magnet", "VP", "FT", "Rich1", "Rich2"]) noUT_bool = True dd4hep.OutputLevel = 1 -options.conddb_tag = 'master' # used for real data -options.dddb_tag = 'run3/trunk' +options.conddb_tag = "master" # used for real data +options.dddb_tag = "run3/trunk" # latest scifi and velo alignments dd4hep.UseConditionsOverlay = True -dd4hep.ConditionsVersion = 'master' +dd4hep.ConditionsVersion = "master" # needed for when reconstruction changed to SuperPixels (change was at run 289434) -DDDBConf().GeometryVersion = 'run3/2024.Q1.2-v00.00' -options.geometry_version = 'run3/2024.Q1.2-v00.00' +DDDBConf().GeometryVersion = "run3/2024.Q1.2-v00.00" +options.geometry_version = "run3/2024.Q1.2-v00.00" conddb_path = "/swdev/marshall/lhcb-conditions-database/" dd4hep.ConditionsLocation = "file://" + conddb_path -rich = f'rich{whichRich}' -radiator = f'Rich{whichRich}Gas' +rich = f"rich{whichRich}" +radiator = f"Rich{whichRich}Gas" -param_list = ['p0_x', 'p1_x', 'p0_y', 'p1_y', 'p0_z', 'p1_z'] +param_list = ["p0_x", "p1_x", "p0_y", "p1_y", "p0_z", "p1_z"] param_dict = dict.fromkeys(param_list) trans_perf_param_dict = dict.fromkeys(param_list) @@ -166,11 +171,11 @@ trans_perf_param_dict = dict.fromkeys(param_list) # ####### 4th July 2024 overlay dd4hep.UseConditionsOverlay = True -dd4hep.ConditionsOverlayInitPath = '/group/online/alignment/prelim_align_2024/07_01_Run3Map_withUT_0207' +dd4hep.ConditionsOverlayInitPath = ( + "/group/online/alignment/prelim_align_2024/07_01_Run3Map_withUT_0207" +) condval = "!alignment{ position: [0 * mm, 0 * mm, 0 * mm], rotation: [-0.0005157705398491993 * rad, 7.011816237252315e-05 * rad, -0.00042666842206765687 * rad]}" -dd4hep.ConditionsOverride = { - "/world/BeforeMagnetRegion/VP:alignment_delta": condval -} +dd4hep.ConditionsOverride = {"/world/BeforeMagnetRegion/VP:alignment_delta": condval} # ####### 4th July 2024 overlay panel_nums = [] @@ -198,17 +203,17 @@ default_reco_opts.update(panel_select) # Monitoring opts if whichRich == 1: - minP = 10. + minP = 10.0 tighter_minp = { "TightTrackSelection": { "MinP": minP * GeV, "MinPt": 0.5 * GeV, - "MaxChi2": 2., + "MaxChi2": 2.0, "MaxGhostProb": 0.1, } } if whichRich == 2: - minP = 20. + minP = 20.0 tighter_minp = { "TightTrackSelection": { "MinP": minP * GeV, @@ -221,64 +226,70 @@ if whichRich == 2: default_moni_opts.update(tighter_minp) # wider_histo = {'CKResHistoRange': (0.025, 0.005, 0.004)} -wider_histo = {'CKResHistoRange': (0.025, 0.0055, 0.0055)} +wider_histo = {"CKResHistoRange": (0.025, 0.0055, 0.0055)} default_moni_opts.update(wider_histo) -useUT = {'UseUT': useUT_bool} +useUT = {"UseUT": useUT_bool} default_moni_opts.update(useUT) nkevts = str(math.trunc(options.evt_max / 1000)) # save output file with histograms if UseDD4Hep: - options.histo_file = f'rich{whichRich}_opt_dd4hep_p{whichPanel}.root' + options.histo_file = f"rich{whichRich}_opt_dd4hep_p{whichPanel}.root" else: - options.histo_file = f'rich{whichRich}_opt_p{whichPanel}.root' + options.histo_file = f"rich{whichRich}_opt_p{whichPanel}.root" PrForwardTrackingVelo.global_bind( MinQuality=0.0, DeltaQuality=0.0, MinTotalHits=9, - MaxChi2PerDoF=50., - MaxChi2XProjection=60., - MaxChi2PerDoFFinal=28., - MaxChi2Stereo=16., - MaxChi2StereoAdd=16., - MinP=minP * GeV) + MaxChi2PerDoF=50.0, + MaxChi2XProjection=60.0, + MaxChi2PerDoFFinal=28.0, + MaxChi2Stereo=16.0, + MaxChi2StereoAdd=16.0, + MinP=minP * GeV, +) PrMatchNN.global_bind(MinP=minP * GeV) PrHybridSeeding.global_bind(MinP=minP * GeV) # commented out when reconstruction changed to SuperPixels (change was at run 289434) -make_VeloClusterTrackingSIMD.global_bind( - algorithm=VeloRetinaClusterTrackingSIMD) -make_velo_full_clusters.global_bind( - make_full_cluster=VPRetinaFullClusterDecoder) +make_VeloClusterTrackingSIMD.global_bind(algorithm=VeloRetinaClusterTrackingSIMD) +make_velo_full_clusters.global_bind(make_full_cluster=VPRetinaFullClusterDecoder) make_reco_pvs.global_bind(make_pvs_from_velo_tracks=make_PatPV3DFuture_pvs) -from Configurables import LHCb__UnpackRawEvent, HltDecReportsDecoder, HltSelReportsDecoder, ApplicationMgr +from Configurables import ( + ApplicationMgr, + HltDecReportsDecoder, + HltSelReportsDecoder, + LHCb__UnpackRawEvent, +) from PyConf.application import configured_ann_svc + unpacker = LHCb__UnpackRawEvent( "UnpackRawEvent", OutputLevel=2, - RawBankLocations=[ - "DAQ/RawBanks/HltDecReports", "DAQ/RawBanks/HltSelReports" - ], - BankTypes=["HltDecReports", "HltSelReports"]) + RawBankLocations=["DAQ/RawBanks/HltDecReports", "DAQ/RawBanks/HltSelReports"], + BankTypes=["HltDecReports", "HltSelReports"], +) decDec = HltDecReportsDecoder( "HltDecReportsDecoder/Hlt1DecReportsDecoder", SourceID="Hlt1", - RawBanks=unpacker.RawBankLocations[0]) + RawBanks=unpacker.RawBankLocations[0], +) selDec = HltSelReportsDecoder( "HltSelReportsDecoder/Hlt1SelReportsDecoder", SourceID="Hlt1", DecReports=unpacker.RawBankLocations[0], - RawBanks=unpacker.RawBankLocations[1]) + RawBanks=unpacker.RawBankLocations[1], +) app = ApplicationMgr( - TopAlg=[unpacker, decDec, selDec], - ExtSvc=[configured_ann_svc(name='HltANNSvc')]) + TopAlg=[unpacker, decDec, selDec], ExtSvc=[configured_ann_svc(name="HltANNSvc")] +) # by default, no additional filtering of the events event_filter = [] @@ -286,29 +297,34 @@ event_filter = [] # Prepare filter import Functors from PyConf.Algorithms import ( - VoidFilter, HltDecReportsDecoder as PyConf_Algorithms_HltDecReportsDecoder, ) +from PyConf.Algorithms import ( + VoidFilter, +) from PyConf.application import ( default_raw_banks, default_raw_event, ) -lines = (['Hlt1RICH1AlignmentDecision'] - if whichRich == 1 else ['Hlt1RICH2AlignmentDecision']) +lines = ( + ["Hlt1RICH1AlignmentDecision"] if whichRich == 1 else ["Hlt1RICH2AlignmentDecision"] +) with default_raw_event.bind(raw_event_format=0.5): hlt1_dec_reports = PyConf_Algorithms_HltDecReportsDecoder( - RawBanks=default_raw_banks("HltDecReports"), SourceID='Hlt1') + RawBanks=default_raw_banks("HltDecReports"), SourceID="Hlt1" + ) hlt1_filter = VoidFilter( - name='Streaming_filter', + name="Streaming_filter", Cut=Functors.DECREPORTS_FILTER( - Lines=lines, - DecReports=hlt1_dec_reports.OutputHltDecReportsLocation)) + Lines=lines, DecReports=hlt1_dec_reports.OutputHltDecReportsLocation + ), + ) # when particular decision of HLT1 line about RICH1 or RICH2 is wanted -#if 'subset' not in current_variant: +# if 'subset' not in current_variant: if useHltDecisions: # prepare filter for selecting events # chosen for alignment of mirrors of particular RICH @@ -327,12 +343,17 @@ if useHltDecisions: sys.stdout.flush() -with standalone_rich_panel_align_reco.bind(RichGas=radiator,\ - EventFilter=event_filter if useHltDecisions else [],\ - noUT=noUT_bool), \ - alignment_rich_monitoring_options.bind(radiator=radiator, \ - init_override_opts=align_opts), \ - default_ft_decoding_version.bind(value=6), \ - default_rich_reco_options.bind(init_override_opts=default_reco_opts), \ - default_rich_monitoring_options.bind(init_override_opts=default_moni_opts): +with ( + standalone_rich_panel_align_reco.bind( + RichGas=radiator, + EventFilter=event_filter if useHltDecisions else [], + noUT=noUT_bool, + ), + alignment_rich_monitoring_options.bind( + radiator=radiator, init_override_opts=align_opts + ), + default_ft_decoding_version.bind(value=6), + default_rich_reco_options.bind(init_override_opts=default_reco_opts), + default_rich_monitoring_options.bind(init_override_opts=default_moni_opts), +): run_reconstruction(options, standalone_rich_panel_align_reco) diff --git a/Rich/RichMirrorAlignmentOnline/python/RichMirrorAlignmentOnline/Configuration.py b/Rich/RichMirrorAlignmentOnline/python/RichMirrorAlignmentOnline/Configuration.py index a295469be93cc93aa81a8c4d88d93968a48586ec..f00cc43ac5c9265fdb52d083729c78f48151cbf6 100644 --- a/Rich/RichMirrorAlignmentOnline/python/RichMirrorAlignmentOnline/Configuration.py +++ b/Rich/RichMirrorAlignmentOnline/python/RichMirrorAlignmentOnline/Configuration.py @@ -32,260 +32,155 @@ __copyright__ = "University of Bristol, June 2023" ### Some details on regularizationMode are listed at the end of this file import os -from Gaudi.Configuration import * + import GaudiKernel.ProcessJobOptions -from Configurables import (LHCbConfigurableUser) +from Configurables import LHCbConfigurableUser +from Gaudi.Configuration import * class Rich1MirrAlignOnConf(LHCbConfigurableUser): __used_configurables__ = [] __slots__ = { #### Do not change this!!! Just DON'T! - "Rich": - 1, + "Rich": 1, #### Directory where we write the ROOT file that Monet picks up for the monitoring - "HistoDir": - "", + "HistoDir": "", #### Only change these if you want to pick up from where you left off in iterations, experts only "MajItStart": # will be automatically forced to be the integer part of dividing MinItStart by the length of tiltNames, if magnFactorModes != 0 0, # 2, "MinItStart": # will be automatically forced to be MajItStart multiplied by the length of tiltNames, if magnFactorModes = 0 0, # 18 ### Better not change these, only for very very VERY good reasons - "dataVariant": - "Collision24", - "useHltDecisions": - False, - "useReducedSubset": - False, - "stackDir": - "/group/rich/sw/alignment/stack/", - "magnFactorsMode": - 0, # 0, + "dataVariant": "Collision24", + "useHltDecisions": False, + "useReducedSubset": False, + "stackDir": "/group/rich/sw/alignment/stack/", + "magnFactorsMode": 0, # 0, "magnifDir": # relative to stackDir (i.e. remove /group/rich/sw/alignment/stack/) - #"Panoptes/Rich/RichMirrorAlignmentOnline/files/MagnifFactors/Rich1/2024-03-13T11-26/", # use for sajans detector branch + # "Panoptes/Rich/RichMirrorAlignmentOnline/files/MagnifFactors/Rich1/2024-03-13T11-26/", # use for sajans detector branch "Panoptes/Rich/RichMirrorAlignmentOnline/files/MagnifFactors/Rich1/20230514_202521/", - "richFiles": - "/group/online/AligWork/tempAlignmentFiles", # "/group/rich/AlignmentFiles/", - "maxIterations": - 8, #8, - "testing": - True, #False, - "WorkDir": - "/group/online/AligWork/Rich1/", + "richFiles": "/group/online/AligWork/tempAlignmentFiles", # "/group/rich/AlignmentFiles/", + "maxIterations": 8, # 8, + "testing": True, # False, + "WorkDir": "/group/online/AligWork/Rich1/", # "/home/marshall/Bristol_RICH/testbench/Rich1/", # If running in the testbench this path must be changed - "SaveDir": - "/group/online/AligWork/MirrorAlignments/", + "SaveDir": "/group/online/AligWork/MirrorAlignments/", # "/home/marshall/Bristol_RICH/testbench/MirrorAlignments/", # If running in the testbench this path must be changed - "ItNrFile": - "/group/online/dataflow/options/LHCbA/Rich1_Alignment_Reference_File.txt", - "thisCase": - "online", + "ItNrFile": "/group/online/dataflow/options/LHCbA/Rich1_Alignment_Reference_File.txt", + "thisCase": "online", "tiltNames": [ - #"", "pri_negYzerZ", "pri_posYzerZ", "pri_zerYnegZ", "pri_zerYposZ", - #"sec_negYzerZ", "sec_posYzerZ", "sec_zerYnegZ", "sec_zerYposZ" - '', - 'priYn', - 'priYp', - 'priZn', - 'priZp', - 'secYn', - 'secYp', - 'secZn', - 'secZp' - ] - , - #"combAndMirrSubsets": - #"/group/rich/sw/alignment/stack/Panoptes/Rich/RichMirrorAlignmentOnline/files/CombAndMirrSubsets/Rich1CombAndMirrSubsets.txt", + # "", "pri_negYzerZ", "pri_posYzerZ", "pri_zerYnegZ", "pri_zerYposZ", + # "sec_negYzerZ", "sec_posYzerZ", "sec_zerYnegZ", "sec_zerYposZ" + "", + "priYn", + "priYp", + "priZn", + "priZp", + "secYn", + "secYp", + "secZn", + "secZp", + ], + # "combAndMirrSubsets": + # "/group/rich/sw/alignment/stack/Panoptes/Rich/RichMirrorAlignmentOnline/files/CombAndMirrSubsets/Rich1CombAndMirrSubsets.txt", ### May be changed if you know what you are doing, explanations below - "startXMLFile": - "" # "/group/rich/sw/alignment/stack/Panoptes/Rich/RichMirrorAlignmentOnline/files/ZeroDB/Rich1_Zeroed.xml" # if testing is not True OR this is blank, it automatically uses the DB XML file - , - "compareXMLFile": - "" # "/group/rich/sw/alignment/stack/Panoptes/Rich/RichMirrorAlignmentOnline/files/ZeroDB/Rich1_Zeroed.xml" # if this is blank, it automatically uses the DB XML file - , - "startYAMLFile": - "" + "startXMLFile": "", # "/group/rich/sw/alignment/stack/Panoptes/Rich/RichMirrorAlignmentOnline/files/ZeroDB/Rich1_Zeroed.xml" # if testing is not True OR this is blank, it automatically uses the DB XML file + "compareXMLFile": "", # "/group/rich/sw/alignment/stack/Panoptes/Rich/RichMirrorAlignmentOnline/files/ZeroDB/Rich1_Zeroed.xml" # if this is blank, it automatically uses the DB XML file + "startYAMLFile": "", # "/group/rich/sw/alignment/lhcb-conditions-database-new/Conditions/Rich1/Alignment/Mirrors.yml/.pool/v10" # if testing is not True OR this is blank, it automatically uses the DB XML file # "/group/rich/sw/alignment/yaml_files/starting_points/v4_altered.yml" # if testing is not True OR this is blank, it automatically uses the DB XML file - , - "compareYAMLFile": - "" + "compareYAMLFile": "", # "/group/rich/sw/alignment/lhcb-conditions-database-new/Conditions/Rich1/Alignment/Mirrors.yml/.pool/v10" # if this is blank, it automatically uses the DB YAML file # "/group/rich/sw/alignment/yaml_files/starting_points/v4_altered.yml" # if this is blank, it automatically uses the DB YAML file - , - "YAMLio": - True, - "useDD4hep": - True, - "minP": - 30., - "coeffCalibTilt": - 0.7, - "minAverageBinPop": - 6., - "phiBinFactor": - 3, - "minFracPhiBinsPopulated": - 0.8, - "deltaThetaWindow": - 12., - "combinFitMethod": - 5, + "YAMLio": True, + "useDD4hep": True, + "minP": 30.0, + "coeffCalibTilt": 0.7, + "minAverageBinPop": 6.0, + "phiBinFactor": 3, + "minFracPhiBinsPopulated": 0.8, + "deltaThetaWindow": 12.0, + "combinFitMethod": 5, "XML_YAML_configDir": # relative to stackDir "Panoptes/Rich/RichMirrorAlignmentOnline/files/XML_YAML_config/", - "solutionMethod": - 0, - "regularizationMode": - 0, - "stopDecisionMode": - 1, - "stopToleranceMode": - 1, - "nominalResolutionSigma": - 1.11 # Run 3: best so far - , - "stopSigmaFraction": - 0, + "solutionMethod": 0, + "regularizationMode": 0, + "stopDecisionMode": 1, + "stopToleranceMode": 1, + "nominalResolutionSigma": 1.11, # Run 3: best so far + "stopSigmaFraction": 0, "requiredEvents": # 1180000 # Run 2: ~70% of 1684783 - 1180000 - , - "autoUpdate": - False, #True, - "autoUpdateNoV": - False, #True, - "trendDateRange": { - 'minDate': None, - 'maxDate': None - } + 1180000, + "autoUpdate": False, # True, + "autoUpdateNoV": False, # True, + "trendDateRange": {"minDate": None, "maxDate": None}, # 2017 tolerances: [0.027, 0.030, 0.455, 0.370], adjusted to [0.03, 0.03, 0.46, 0.37] - , - "stopTolerancePriY": - 0.015, - "stopTolerancePriZ": - 0.015, - "stopToleranceSecY": - 0.23, - "stopToleranceSecZ": - 0.185, - "warningFactor": - 3, - "EvtMax": - -1, - "fixSinusoidShift": - True, - "nameStr": - "", - "runNumber": - "" + "stopTolerancePriY": 0.015, + "stopTolerancePriZ": 0.015, + "stopToleranceSecY": 0.23, + "stopToleranceSecZ": 0.185, + "warningFactor": 3, + "EvtMax": -1, + "fixSinusoidShift": True, + "nameStr": "", + "runNumber": "", } _propertyDocDct = { - "MajItStart": - """ Start the alignment at this major iteration. Please make sure this is consitent with MinItStart. """, - "MinItStart": - """ Start the alignment at this minor iteration. Please make sure this is consitent with MajItStart. """, - "Rich": - """ Rich1 or Rich2. """, - "HistoDir": - """ Directory where we write the ROOT file that Monet picks up for the monitoring. """, - "WorkDir": - """ Directory in which all the output will be written. """, - "SaveDir": - """ Directory in which all output files of the alignment are saved after it has finished """, - "ItNrFile": - """ File which contains only the number of the current iteration written by the iterator, to be read by the analyzers """, - "thisCase": - """ Right now this is used only for the naming convention. """, - "tiltNames": - """ Combination of tilts for the calculation and usage of the magnification factors. This is needed even when using predefined magnification factors!!! """, - #"combAndMirrSubsets": - #""" File that lists the subset of combinations of primary and secondary mirror segments chosen for alignment monitoring, and all mirror segments under alignment monitoring """, - "startXMLFile": - """ ONLY IF testing = True, this is the XML file with the mirror tilts that we start with for the alignment; if it is blank or testing is not True, it uses the latest v-numbered xml (which is what should be currently in the DB) """, - "compareXMLFile": - """ XML file with mirror tilts, for comparison of mirror tilts before and after alignment; if it is blank, it uses the latest v-numbered xml (which is what should be currently in the DB) """, - "startYAMLFile": - """ ONLY IF testing = True, this is the YAML file with the mirror tilts that we start with for the alignment; if it is blank or testing is not True, it uses the latest v-numbered yml (which is what should be currently in the DB) """, - "compareYAMLFile": - """ YAML file with mirror tilts, for comparison of mirror tilts before and after alignment; if it is blank, it uses the latest v-numbered yml (which is what should be currently in the DB) """, - "YAMLio": - """ If True, then startYAMLFile and compareYAMLFile are considered instead of startXMLFile and compareXMLFile, the input is expected to be YAML, the output will be YAML, and it is assumed that the latest v-numbered file is yml and not xml """, - "useDD4hep": - """ If True, then use DD4hep (YAML-based) for reconstruction instead of DetDesc (XML-based). Also YAMLio will be set to True within the Iterator. """, - "useHltDecisions": - """ If True, then only process events with a RICH HLT line trigger decision (for the particular RICH being aligned) """, - "useReducedSubset": - """ If True, then use a reduced subset of mirror combinations allowing only for the alignment of inner mirrors """, - "minP": - """ minimum momentum cut for the tracks that we wish to reconstruct (in GeV) """, - "coeffCalibTilt": - """ Mirror-tilts applied for the calculation of the magnification coefficients. """, - "minAverageBinPop": - """ Demanded minimal entries per bin in x-y-bin; atm 6: for 20 phi-bins, 4.8: for 25 phi-bins. """, - "phiBinFactor": - """ Factor by which the number of phi-bins is reduced. The histograms should now come with 60 phi bins, factor 3 reduced this to 20 bin in the fit.""", - "minFracPhiBinsPopulated": - """ Fraction of the phi-bins that should be sufficiently populated, based on the current minAverageBinPop setting. Ideally this is 0.8, but sometimes we lower it if the mirror alignment still seems OK with a lower fraction, though we really should adjust the HLT line instead.""", - "deltaThetaWindow": - """ dTheta-range in the histograms; 4.0 for Rich1 and 3.0 for Rich2. """, - "combinFitMethod": - """ Method for fitting the 2D histograms; 1: first fit the slices of dTheta with a Gaussian and then fit to phi using only the mean of the Gaussian, 3: fit a 2D function, 5: same as 3 but with unifyWidths """, - "stackDir": - """ directory that contains the compiled code stack """, - "magnFactorsMode": - """ Method for calculating the magnification coefficents; 0: magnefication coeff. pre-determined, 1: individual for all mirror pairs, determined in the 0-th iteration and not updated any further, 2: individual for all mirrorpairs, determined on-the-fly on the data. """, - "magnifDir": - """ directory that contains the pre-determined magnification coeff., files in this folder have to be named Rich[1,2]_MirrMagn _[tiltName]_predefined.txt """, - "richFiles": - """ directory (usually in /group/rich/) that contains the Logging, Polarity, testingMaybe, and rolling CKtrend and Update files """, - "XML_YAML_configDir": - """ directory that contains the configuration files for the XML-YAML converter """, - "solutionMethod": - """ Solution method for calculating the mirror tilts after the individual fits; 0: Minuit, 1: Algebraic """, - "regularizationMode": - """ regularization mode (0/10/1/11): regularization terms magnified (weighted) with: 0(def)-> major & minor per-mirror MFs; 10-> only averaged per-kind major MFs; 1 (and 11, respectively)-> all weights = 1. """, - "stopDecisionMode": - """ decision mode: default 0: use sqrt of the final regularization term, divided by the number of mirrors, 1: for each solution component use its own tolerance""", - "stopToleranceMode": - """ tolerance mode: default 0: calculate the stopTolerances from nominal sigma, average magn factors and stopSigmaFraction, 1 use stopTolerances given below""", - "nominalResolutionSigma": - """ RICH-dependent nominal Cherenkov angle resolution (in mrad)""", - "stopSigmaFraction": - """ tolerance for total tilt of mirror pair in terms of the fraction of the nominal Cherenkov angle resolution """, - "maxIterations": - """ The number of iterations the mirror alignment will run, before giving up """, - "requiredEvents": - """ If this many events are not procesed by the farm, on average, we do run the alignment but we will never update it. """, - "autoUpdate": - """ If True, then the fully automated updating system is activated. If False, our DB update service is still active but returns the starting alignment version. """, - "autoUpdateNoV": - """ Only looked at if autoUpdate is True. Then, if autoUpdateNoV is False, nothing changes. If autoUpdateNoV is True, then rather than sending the existing alignment version if autoUpdate is disabled *and* there is a _maybe_ alignment, we will send no version through the DB update service. HLT2 will have to wait for us to assign one. """, - "testing": - """ If True, then we are running a test alignment; we also disable our DB update service completely. """, - "trendDateRange": - """ Set the date range for the automatic trend plots. Format is YYYYMMDD. Additionally, a minDate(maxDate) of None defaults to the first(last) day of the current year (see AlignMonitor.py).""", - "stopTolerancePriY": - """ RICH-dependent tolerance for primary mirrors rotation around Y correction in mrad to stop the alignment """, - "stopTolerancePriZ": - """ RICH-dependent tolerance for primary mirrors rotation around Z correction in mrad to stop the alignment """, - "stopToleranceSecY": - """ RICH-dependent tolerance for secondary mirrors rotation around Y correction in mrad to stop the alignment """, - "stopToleranceSecZ": - """ RICH-dependent tolerance for secondary mirrors rotation around Z correction in mrad to stop the alignment """, - "warningFactor": - """ alerts the alignment if any of the mirrors have shifted more than warningFactor times a particular mirror rotation stopTolerance """, - "EvtMax": - """ maximal number of events processed by Moore PER NODE (hlt farm has ~1500 nodes), -1 = infinite """, - "dataVariant": - """ Helps us decide which Moore options to use (see RichAnalyzer.py); also used for the naming convention. """, - "fixSinusoidShift": - """ True : fix at sinusoidShift; False : it is not fixed """, - "nameStr": - """ Right now this is used only for the naming convention, but will be set when initiating the Configuration. """, - "runNumber": - """ Defined as the earliest run in the fill """ + "MajItStart": """ Start the alignment at this major iteration. Please make sure this is consitent with MinItStart. """, + "MinItStart": """ Start the alignment at this minor iteration. Please make sure this is consitent with MajItStart. """, + "Rich": """ Rich1 or Rich2. """, + "HistoDir": """ Directory where we write the ROOT file that Monet picks up for the monitoring. """, + "WorkDir": """ Directory in which all the output will be written. """, + "SaveDir": """ Directory in which all output files of the alignment are saved after it has finished """, + "ItNrFile": """ File which contains only the number of the current iteration written by the iterator, to be read by the analyzers """, + "thisCase": """ Right now this is used only for the naming convention. """, + "tiltNames": """ Combination of tilts for the calculation and usage of the magnification factors. This is needed even when using predefined magnification factors!!! """, + # "combAndMirrSubsets": + # """ File that lists the subset of combinations of primary and secondary mirror segments chosen for alignment monitoring, and all mirror segments under alignment monitoring """, + "startXMLFile": """ ONLY IF testing = True, this is the XML file with the mirror tilts that we start with for the alignment; if it is blank or testing is not True, it uses the latest v-numbered xml (which is what should be currently in the DB) """, + "compareXMLFile": """ XML file with mirror tilts, for comparison of mirror tilts before and after alignment; if it is blank, it uses the latest v-numbered xml (which is what should be currently in the DB) """, + "startYAMLFile": """ ONLY IF testing = True, this is the YAML file with the mirror tilts that we start with for the alignment; if it is blank or testing is not True, it uses the latest v-numbered yml (which is what should be currently in the DB) """, + "compareYAMLFile": """ YAML file with mirror tilts, for comparison of mirror tilts before and after alignment; if it is blank, it uses the latest v-numbered yml (which is what should be currently in the DB) """, + "YAMLio": """ If True, then startYAMLFile and compareYAMLFile are considered instead of startXMLFile and compareXMLFile, the input is expected to be YAML, the output will be YAML, and it is assumed that the latest v-numbered file is yml and not xml """, + "useDD4hep": """ If True, then use DD4hep (YAML-based) for reconstruction instead of DetDesc (XML-based). Also YAMLio will be set to True within the Iterator. """, + "useHltDecisions": """ If True, then only process events with a RICH HLT line trigger decision (for the particular RICH being aligned) """, + "useReducedSubset": """ If True, then use a reduced subset of mirror combinations allowing only for the alignment of inner mirrors """, + "minP": """ minimum momentum cut for the tracks that we wish to reconstruct (in GeV) """, + "coeffCalibTilt": """ Mirror-tilts applied for the calculation of the magnification coefficients. """, + "minAverageBinPop": """ Demanded minimal entries per bin in x-y-bin; atm 6: for 20 phi-bins, 4.8: for 25 phi-bins. """, + "phiBinFactor": """ Factor by which the number of phi-bins is reduced. The histograms should now come with 60 phi bins, factor 3 reduced this to 20 bin in the fit.""", + "minFracPhiBinsPopulated": """ Fraction of the phi-bins that should be sufficiently populated, based on the current minAverageBinPop setting. Ideally this is 0.8, but sometimes we lower it if the mirror alignment still seems OK with a lower fraction, though we really should adjust the HLT line instead.""", + "deltaThetaWindow": """ dTheta-range in the histograms; 4.0 for Rich1 and 3.0 for Rich2. """, + "combinFitMethod": """ Method for fitting the 2D histograms; 1: first fit the slices of dTheta with a Gaussian and then fit to phi using only the mean of the Gaussian, 3: fit a 2D function, 5: same as 3 but with unifyWidths """, + "stackDir": """ directory that contains the compiled code stack """, + "magnFactorsMode": """ Method for calculating the magnification coefficents; 0: magnefication coeff. pre-determined, 1: individual for all mirror pairs, determined in the 0-th iteration and not updated any further, 2: individual for all mirrorpairs, determined on-the-fly on the data. """, + "magnifDir": """ directory that contains the pre-determined magnification coeff., files in this folder have to be named Rich[1,2]_MirrMagn _[tiltName]_predefined.txt """, + "richFiles": """ directory (usually in /group/rich/) that contains the Logging, Polarity, testingMaybe, and rolling CKtrend and Update files """, + "XML_YAML_configDir": """ directory that contains the configuration files for the XML-YAML converter """, + "solutionMethod": """ Solution method for calculating the mirror tilts after the individual fits; 0: Minuit, 1: Algebraic """, + "regularizationMode": """ regularization mode (0/10/1/11): regularization terms magnified (weighted) with: 0(def)-> major & minor per-mirror MFs; 10-> only averaged per-kind major MFs; 1 (and 11, respectively)-> all weights = 1. """, + "stopDecisionMode": """ decision mode: default 0: use sqrt of the final regularization term, divided by the number of mirrors, 1: for each solution component use its own tolerance""", + "stopToleranceMode": """ tolerance mode: default 0: calculate the stopTolerances from nominal sigma, average magn factors and stopSigmaFraction, 1 use stopTolerances given below""", + "nominalResolutionSigma": """ RICH-dependent nominal Cherenkov angle resolution (in mrad)""", + "stopSigmaFraction": """ tolerance for total tilt of mirror pair in terms of the fraction of the nominal Cherenkov angle resolution """, + "maxIterations": """ The number of iterations the mirror alignment will run, before giving up """, + "requiredEvents": """ If this many events are not procesed by the farm, on average, we do run the alignment but we will never update it. """, + "autoUpdate": """ If True, then the fully automated updating system is activated. If False, our DB update service is still active but returns the starting alignment version. """, + "autoUpdateNoV": """ Only looked at if autoUpdate is True. Then, if autoUpdateNoV is False, nothing changes. If autoUpdateNoV is True, then rather than sending the existing alignment version if autoUpdate is disabled *and* there is a _maybe_ alignment, we will send no version through the DB update service. HLT2 will have to wait for us to assign one. """, + "testing": """ If True, then we are running a test alignment; we also disable our DB update service completely. """, + "trendDateRange": """ Set the date range for the automatic trend plots. Format is YYYYMMDD. Additionally, a minDate(maxDate) of None defaults to the first(last) day of the current year (see AlignMonitor.py).""", + "stopTolerancePriY": """ RICH-dependent tolerance for primary mirrors rotation around Y correction in mrad to stop the alignment """, + "stopTolerancePriZ": """ RICH-dependent tolerance for primary mirrors rotation around Z correction in mrad to stop the alignment """, + "stopToleranceSecY": """ RICH-dependent tolerance for secondary mirrors rotation around Y correction in mrad to stop the alignment """, + "stopToleranceSecZ": """ RICH-dependent tolerance for secondary mirrors rotation around Z correction in mrad to stop the alignment """, + "warningFactor": """ alerts the alignment if any of the mirrors have shifted more than warningFactor times a particular mirror rotation stopTolerance """, + "EvtMax": """ maximal number of events processed by Moore PER NODE (hlt farm has ~1500 nodes), -1 = infinite """, + "dataVariant": """ Helps us decide which Moore options to use (see RichAnalyzer.py); also used for the naming convention. """, + "fixSinusoidShift": """ True : fix at sinusoidShift; False : it is not fixed """, + "nameStr": """ Right now this is used only for the naming convention, but will be set when initiating the Configuration. """, + "runNumber": """ Defined as the earliest run in the fill """, } def setNameStr(self): @@ -294,7 +189,9 @@ class Rich1MirrAlignOnConf(LHCbConfigurableUser): thisTuning += f"Fm{self.getProp('combinFitMethod')}" thisTuning += f"Mm{self.getProp('magnFactorsMode')}" thisTuning += f"Sm{self.getProp('solutionMethod')}" - thisNameStr = f"{thisTuning}_{self.getProp('thisCase')}_{self.getProp('dataVariant')}" + thisNameStr = ( + f"{thisTuning}_{self.getProp('thisCase')}_{self.getProp('dataVariant')}" + ) self.setProp("nameStr", thisNameStr) #### Dont mess with this filename!!! @@ -303,9 +200,11 @@ class Rich1MirrAlignOnConf(LHCbConfigurableUser): # take earliest run in fill as the runNumber (for Monet's structure) runs = [] # can remove this when everything works for Run 3 import getpass + if "online" in getpass.getuser(): import OnlineEnvBase as Online # import OnlineEnv as Online from MooreOnlineConf.utils import alignment_options + online_options = alignment_options(Online) runs = online_options.runs # runs = Online.DeferredRuns # PN - Extract the run number substring from the full string - WILL NOT WORK IF RUN NUMBERS BECOME 7 DIGITS @@ -315,30 +214,32 @@ class Rich1MirrAlignOnConf(LHCbConfigurableUser): else: runNumber = "000000" # placeholder run number - first_dir = runNumber[:2] + '0' * (len(runNumber) - 2 - ) # returns 250000 for 256112 - second_dir = runNumber[:3] + '0' * (len(runNumber) - 3 - ) # returns 256000 for 256112 + first_dir = runNumber[:2] + "0" * ( + len(runNumber) - 2 + ) # returns 250000 for 256112 + second_dir = runNumber[:3] + "0" * ( + len(runNumber) - 3 + ) # returns 256000 for 256112 histodir = f"/hist/Savesets/ByRun/RichAlignMon/{first_dir}/{second_dir}/" os.makedirs( - histodir, - exist_ok=True) # create subdirectory path if it doesnt exist + histodir, exist_ok=True + ) # create subdirectory path if it doesnt exist self.setProp("HistoDir", histodir) self.setProp("runNumber", runNumber) def checkStartIt(self): if not self.getProp("magnFactorsMode") == 0: integerDivides = self.getProp("MinItStart") // len( - self.getProp("tiltNames")) + self.getProp("tiltNames") + ) if integerDivides != self.getProp("MajItStart"): print( "WARNING: Major Iteration did not match minor iteration. Major iteration is being set to match minor iteration." ) self.setProp("MajItStart", integerDivides) - if (self.getProp("magnFactorsMode") == 0 - and self.getProp("magnifDir") == ""): + if self.getProp("magnFactorsMode") == 0 and self.getProp("magnifDir") == "": self.setProp( - "magnifDir", '/group/rich/AlignmentFiles/MagnifFactors/Rich1/' + "magnifDir", "/group/rich/AlignmentFiles/MagnifFactors/Rich1/" ) # PN - This whole thing needs to be changed for Run 3, but indeed good to have a default directory for MagFactors print( "WARNING: Mode for calculating magnification coefficients was chosen to be 0 but no directory with pre-determined coefficients provided. Directory set to default." @@ -349,21 +250,23 @@ class Rich1MirrAlignOnConf(LHCbConfigurableUser): ) self.setProp( "MinItStart", - self.getProp("MajItStart") * len(self.getProp("tiltNames"))) + self.getProp("MajItStart") * len(self.getProp("tiltNames")), + ) def __apply_configuration__(self): self.setHistoDir() self.setNameStr() self.checkStartIt() # Next 3 lines add the trailing slash in key directory names - self.setProp('WorkDir', os.path.join(self.getProp('WorkDir'), '')) - self.setProp('SaveDir', os.path.join(self.getProp('SaveDir'), '')) - self.setProp('stackDir', os.path.join(self.getProp('stackDir'), '')) - self.setProp('magnifDir', os.path.join(self.getProp('magnifDir'), '')) - self.setProp('richFiles', os.path.join(self.getProp('richFiles'), '')) - self.setProp('XML_YAML_configDir', - os.path.join(self.getProp('XML_YAML_configDir'), '')) - self.setProp('HistoDir', os.path.join(self.getProp('HistoDir'), '')) + self.setProp("WorkDir", os.path.join(self.getProp("WorkDir"), "")) + self.setProp("SaveDir", os.path.join(self.getProp("SaveDir"), "")) + self.setProp("stackDir", os.path.join(self.getProp("stackDir"), "")) + self.setProp("magnifDir", os.path.join(self.getProp("magnifDir"), "")) + self.setProp("richFiles", os.path.join(self.getProp("richFiles"), "")) + self.setProp( + "XML_YAML_configDir", os.path.join(self.getProp("XML_YAML_configDir"), "") + ) + self.setProp("HistoDir", os.path.join(self.getProp("HistoDir"), "")) print("INFO: Rich1MirrAlignOnConf applied") @@ -371,252 +274,144 @@ class Rich2MirrAlignOnConf(LHCbConfigurableUser): __used_configurables__ = [] __slots__ = { #### Do not ever change this!!! Just DON'T! - "Rich": - 2, + "Rich": 2, #### Directory where we write the ROOT file that Monet picks up for the monitoring - "HistoDir": - "", + "HistoDir": "", #### Only change these if you want to pick up from where you left off in iterations, experts only "MajItStart": # will be automatically forced to be the integer part of dividing MinItStart by the length of tiltNames, if magnFactorModes != 0 - 0, #4, + 0, # 4, "MinItStart": # will be automatically forced to be MajItStart multiplied by the length of tiltNames, if magnFactorModes = 0 - 0, #36 + 0, # 36 ### Better not change these, only for very very VERY good reasons - "dataVariant": - "Collision24", - "useHltDecisions": - False, - "useReducedSubset": - False, - "stackDir": - "/group/rich/sw/alignment/stack/", - "magnFactorsMode": - 0, - "richFiles": - "/group/online/AligWork/tempAlignmentFiles", # "/group/rich/AlignmentFiles/", + "dataVariant": "Collision24", + "useHltDecisions": False, + "useReducedSubset": False, + "stackDir": "/group/rich/sw/alignment/stack/", + "magnFactorsMode": 0, + "richFiles": "/group/online/AligWork/tempAlignmentFiles", # "/group/rich/AlignmentFiles/", "magnifDir": # relative to stackDir (i.e. remove /group/rich/sw/alignment/stack/) "Panoptes/Rich/RichMirrorAlignmentOnline/files/MagnifFactors/Rich2/2024-03-22T14-48/", - "maxIterations": - 8, #8, - "testing": - True, #False, - "WorkDir": - "/group/online/AligWork/Rich2/", - #"/home/marshall/Bristol_RICH/testbench/Rich2/", # If running in the testbench this path must be changed - "SaveDir": - "/group/online/AligWork/MirrorAlignments/", - #"/home/marshall/Bristol_RICH/testbench/MirrorAlignments/", # If running in the testbench this path must be changed - "ItNrFile": - "/group/online/dataflow/options/LHCbA/Rich2_Alignment_Reference_File.txt", - "thisCase": - "online", + "maxIterations": 8, # 8, + "testing": True, # False, + "WorkDir": "/group/online/AligWork/Rich2/", + # "/home/marshall/Bristol_RICH/testbench/Rich2/", # If running in the testbench this path must be changed + "SaveDir": "/group/online/AligWork/MirrorAlignments/", + # "/home/marshall/Bristol_RICH/testbench/MirrorAlignments/", # If running in the testbench this path must be changed + "ItNrFile": "/group/online/dataflow/options/LHCbA/Rich2_Alignment_Reference_File.txt", + "thisCase": "online", "tiltNames": [ - #"", "pri_negYzerZ", "pri_posYzerZ", "pri_zerYnegZ", "pri_zerYposZ", - #"sec_negYzerZ", "sec_posYzerZ", "sec_zerYnegZ", "sec_zerYposZ" - '', - 'priYn', - 'priYp', - 'priZn', - 'priZp', - 'secYn', - 'secYp', - 'secZn', - 'secZp' - ] - , - #"combAndMirrSubsets": - #"/group/rich/sw/alignment/stack/Panoptes/Rich/RichMirrorAlignmentOnline/files/CombAndMirrSubsets/Rich2CombAndMirrSubsets.txt", + # "", "pri_negYzerZ", "pri_posYzerZ", "pri_zerYnegZ", "pri_zerYposZ", + # "sec_negYzerZ", "sec_posYzerZ", "sec_zerYnegZ", "sec_zerYposZ" + "", + "priYn", + "priYp", + "priZn", + "priZp", + "secYn", + "secYp", + "secZn", + "secZp", + ], + # "combAndMirrSubsets": + # "/group/rich/sw/alignment/stack/Panoptes/Rich/RichMirrorAlignmentOnline/files/CombAndMirrSubsets/Rich2CombAndMirrSubsets.txt", ### May be changed if you know what you are doing - "startXMLFile": - "" # "/group/rich/sw/alignment/stack/Panoptes/Rich/RichMirrorAlignmentOnline/files/ZeroDB/Rich2_Zeroed.xml" # if testing is not True OR this is blank, it automatically uses the DB XML file - , - "compareXMLFile": - "" # if this is blank, it automatically uses the DB XML file - , - "startYAMLFile": - "" + "startXMLFile": "", # "/group/rich/sw/alignment/stack/Panoptes/Rich/RichMirrorAlignmentOnline/files/ZeroDB/Rich2_Zeroed.xml" # if testing is not True OR this is blank, it automatically uses the DB XML file + "compareXMLFile": "", # if this is blank, it automatically uses the DB XML file + "startYAMLFile": "", # "/group/rich/sw/alignment/lhcb-conditions-database-new/Conditions/Rich2/Alignment/Mirrors.yml/.pool/v9" # if testing is not True OR this is blank, it automatically uses the DB XML file # "" # if testing is not True OR this is blank, it automatically uses the DB YAML file # "/group/rich/sw/alignment/yaml_files/starting_points/RICH2_2024_preliminary_updated.yml" # if testing is not True OR this is blank, it automatically uses the DB YAML file - , - "compareYAMLFile": - "" + "compareYAMLFile": "", # "/group/rich/sw/alignment/lhcb-conditions-database-new/Conditions/Rich2/Alignment/Mirrors.yml/.pool/v9" # if testing is not True OR this is blank, it automatically uses the DB XML file # "" # if this is blank, it automatically uses the DB YAML file # "/group/rich/sw/alignment/yaml_files/starting_points/RICH2_2024_preliminary_updated.yml" # if this is blank, it automatically uses the DB YAML file - , - "YAMLio": - True, - "useDD4hep": - True, - "minP": - 60., - "coeffCalibTilt": - 0.3, - "minAverageBinPop": - 6., - "phiBinFactor": - 3, - "minFracPhiBinsPopulated": - 0.7 # adjusted from 0.8 due to inefficiencies in our existing choice of HLT line prescales - , - "deltaThetaWindow": - 4., - "combinFitMethod": - 5, + "YAMLio": True, + "useDD4hep": True, + "minP": 60.0, + "coeffCalibTilt": 0.3, + "minAverageBinPop": 6.0, + "phiBinFactor": 3, + "minFracPhiBinsPopulated": 0.7, # adjusted from 0.8 due to inefficiencies in our existing choice of HLT line prescales + "deltaThetaWindow": 4.0, + "combinFitMethod": 5, "XML_YAML_configDir": # relative to stackDir "Panoptes/Rich/RichMirrorAlignmentOnline/files/XML_YAML_config/", - "solutionMethod": - 0, - "regularizationMode": - 0, - "stopDecisionMode": - 1, - "stopToleranceMode": - 1, - "nominalResolutionSigma": - 0.625 # Run 3: best so far - , - "stopSigmaFraction": - 0, - "requiredEvents": - 942500 # Run 2: ~70% of 1346563 - , - "autoUpdate": - False, #True, - "autoUpdateNoV": - False, #True, - "trendDateRange": { - 'minDate': None, - 'maxDate': None - } + "solutionMethod": 0, + "regularizationMode": 0, + "stopDecisionMode": 1, + "stopToleranceMode": 1, + "nominalResolutionSigma": 0.625, # Run 3: best so far + "stopSigmaFraction": 0, + "requiredEvents": 942500, # Run 2: ~70% of 1346563 + "autoUpdate": False, # True, + "autoUpdateNoV": False, # True, + "trendDateRange": {"minDate": None, "maxDate": None}, # 2017 tolerances: [0.032, 0.030, 0.043, 0.057], adjusted to [0.03, 0.03, 0.05, 0.06] - , - "stopTolerancePriY": - 0.03, - "stopTolerancePriZ": - 0.03, - "stopToleranceSecY": - 0.05, - "stopToleranceSecZ": - 0.06, - "warningFactor": - 3, - "EvtMax": - -1, - "fixSinusoidShift": - True, - "nameStr": - "", - "runNumber": - "" + "stopTolerancePriY": 0.03, + "stopTolerancePriZ": 0.03, + "stopToleranceSecY": 0.05, + "stopToleranceSecZ": 0.06, + "warningFactor": 3, + "EvtMax": -1, + "fixSinusoidShift": True, + "nameStr": "", + "runNumber": "", } _propertyDocDct = { - "MajItStart": - """ Start the alignment at this major iteration. Please make sure this is consitent with MinItStart. """, - "MinItStart": - """ Start the alignment at this minor iteration. Please make sure this is consitent with MajItStart. """, - "Rich": - """ Rich1 or Rich2. """, - "HistoDir": - """ Directory where we write the ROOT file that Monet picks up for the monitoring. """, - "WorkDir": - """ Directory in which all the output will be written. """, - "SaveDir": - """ Directory in which all output files of the alignment are saved after it has finished """, - "ItNrFile": - """ File which contains only the number of the current iteration written by the iterator, to be read by the analyzers """, - "thisCase": - """ Right now this is used only for the naming convention. """, - "tiltNames": - """ Combination of tilts for the calculation and usage of the magnification factors. This is needed even when using predefined magnification factors!!! """, - #"combAndMirrSubsets": - #""" File that lists the subset of combinations of primary and secondary mirror segments chosen for alignment monitoring, and all mirror segments under alignment monitoring """, - "startXMLFile": - """ ONLY IF testing = True, this is the XML file with the mirror tilts that we start with for the alignment; if it is blank or testing is not True, it uses the latest v-numbered xml (which is what should be currently in the DB) """, - "compareXMLFile": - """ XML file with mirror tilts, for comparison of mirror tilts before and after alignment; if it is blank, it uses the latest v-numbered xml (which is what should be currently in the DB) """, - "startYAMLFile": - """ ONLY IF testing = True, this is the YAML file with the mirror tilts that we start with for the alignment; if it is blank or testing is not True, it uses the latest v-numbered yml (which is what should be currently in the DB) """, - "compareYAMLFile": - """ YAML file with mirror tilts, for comparison of mirror tilts before and after alignment; if it is blank, it uses the latest v-numbered yml (which is what should be currently in the DB) """, - "YAMLio": - """ If True, then startYAMLFile and compareYAMLFile are considered instead of startXMLFile and compareXMLFile, the input is expected to be YAML, the output will be YAML, and it is assumed that the latest v-numbered file is yml and not xml """, - "useDD4hep": - """ If True, then use DD4hep (YAML-based) for reconstruction instead of DetDesc (XML-based). Also YAMLio will be set to True within the Iterator. """, - "useHltDecisions": - """ If True, then only process events with a RICH HLT line trigger decision (for the particular RICH being aligned) """, - "useReducedSubset": - """ If True, then use a reduced subset of mirror combinations allowing only for the alignment of inner mirrors """, - "minP": - """ minimum momentum cut for the tracks that we wish to reconstruct (in GeV) """, - "coeffCalibTilt": - """ Mirror-tilts applied for the calculation of the magnification coefficients. """, - "minAverageBinPop": - """ Demanded minimal entries per bin in x-y-bin; atm 6: for 20 phi-bins, 4.8: for 25 phi-bins. """, - "phiBinFactor": - """ Factor by which the number of phi-bins is reduced. The histograms should now come with 60 phi bins, factor 3 reduced this to 20 bin in the fit.""", - "minFracPhiBinsPopulated": - """ Fraction of the phi-bins that should be sufficiently populated, based on the current minAverageBinPop setting. Ideally this is 0.8, but sometimes we lower it if the mirror alignment still seems OK with a lower fraction, though we really should adjust the HLT line instead.""", - "deltaThetaWindow": - """ dTheta-range in the histograms; 4.0 for Rich1 and 3.0 for Rich2. """, - "combinFitMethod": - """ Method for fitting the 2D histograms; 1: first fit the slices of dTheta with a Gaussian and then fit to phi using only the mean of the Gaussian, 3: fit a 2D function, 5: Same as 3 but with unifyWidths """, - "stackDir": - """ directory that contains the compiled code stack """, - "magnFactorsMode": - """ Method for calculating the magnification coefficents; 0: magnefication coeff. pre-determined, 1: individual for all mirror pairs, determined in the 0-th iteration and not updated any further, 2: individual for all mirrorpairs, determined on-the-fly on the data. """, - "magnifDir": - """ directory that contains the pre-determined magnification coeff., files in this folder have to be named Rich[1,2]_MirrMagn _[tiltName]_predefined.txt """, - "richFiles": - """ directory (usually in /group/rich/) that contains the Logging, Polarity, testingMaybe, and rolling CKtrend and Update files """, - "XML_YAML_configDir": - """ directory that contains the configuration files for the XML-YAML converter """, - "solutionMethod": - """ Solution method for calculating the mirror tilts after the individual fits; 0: Minuit, 1: Algebraic """, - "regularizationMode": - """ regularization mode (0/10/1/11): regularization terms magnified (weighted) with: 0(def)-> major & minor per-mirror MFs; 10-> only averaged per-kind major MFs; 1 (and 11, respectively)-> all weights = 1. """, - "stopDecisionMode": - """ decision mode: default 0: use sqrt of the final regularization term, divided by the number of mirrors, 1: for each solution component use its own tolerance""", - "stopToleranceMode": - """ tolerance mode: default 0: calculate the stopTolerances from nominal sigma, average magn factors and stopSigmaFraction, 1 use stopTolerances given below""", - "nominalResolutionSigma": - """ RICH-dependent nominal Cherenkov angle resolution (in mrad)""", - "stopSigmaFraction": - """ tolerance for total tilt of mirror pair in terms of the fraction of the nominal Cherenkov angle resolution """, - "maxIterations": - """ The number of iterations the mirror alignment will run, before giving up """, - "requiredEvents": - """ If this many events are not procesed by the farm, on average, we do run the alignment but we will never update it. """, - "autoUpdate": - """ If True, then the fully automated updating system is activated. If False, our DB update service is still active but returns the starting alignment version. """, - "autoUpdateNoV": - """ Only looked at if autoUpdate is True. Then, if autoUpdateNoV is False, nothing changes. If autoUpdateNoV is True, then rather than sending the existing alignment version if autoUpdate is disabled *and* there is a _maybe_ alignment, we will send no version through the DB update service. HLT2 will have to wait for us to assign one. """, - "testing": - """ If True, then we are running a test alignment; we also disable our DB update service completely. """, - "trendDateRange": - """ Set the date range for the automatic trend plots. Format is YYYYMMDD. Additionally, a minDate(maxDate) of None defaults to the first(last) day of the current year (see AlignMonitor.py).""", - "stopTolerancePriY": - """ RICH-dependent tolerance for primary mirrors rotation around Y correction in mrad to stop the alignment """, - "stopTolerancePriZ": - """ RICH-dependent tolerance for primary mirrors rotation around Z correction in mrad to stop the alignment """, - "stopToleranceSecY": - """ RICH-dependent tolerance for secondary mirrors rotation around Y correction in mrad to stop the alignment """, - "stopToleranceSecZ": - """ RICH-dependent tolerance for secondary mirrors rotation around Z correction in mrad to stop the alignment """, - "warningFactor": - """ alerts the alignment if any of the mirrors have shifted more than warningFactor times a particular mirror rotation stopTolerance """, - "EvtMax": - """ maximal number of events processed by Moore PER NODE (hlt farm has ~1500 nodes), -1 = infinite """, - "dataVariant": - """ Helps us decide which Moore options to use (see RichAnalyzer.py); also used for the naming convention. """, - "fixSinusoidShift": - """ True : fix at sinusoidShift; False : it is not fixed """, - "nameStr": - """ Right now this is used only for the naming convention, but will be set when initiating the Configuration. """, - "runNumber": - """ Defined as the earliest run in the fill """ + "MajItStart": """ Start the alignment at this major iteration. Please make sure this is consitent with MinItStart. """, + "MinItStart": """ Start the alignment at this minor iteration. Please make sure this is consitent with MajItStart. """, + "Rich": """ Rich1 or Rich2. """, + "HistoDir": """ Directory where we write the ROOT file that Monet picks up for the monitoring. """, + "WorkDir": """ Directory in which all the output will be written. """, + "SaveDir": """ Directory in which all output files of the alignment are saved after it has finished """, + "ItNrFile": """ File which contains only the number of the current iteration written by the iterator, to be read by the analyzers """, + "thisCase": """ Right now this is used only for the naming convention. """, + "tiltNames": """ Combination of tilts for the calculation and usage of the magnification factors. This is needed even when using predefined magnification factors!!! """, + # "combAndMirrSubsets": + # """ File that lists the subset of combinations of primary and secondary mirror segments chosen for alignment monitoring, and all mirror segments under alignment monitoring """, + "startXMLFile": """ ONLY IF testing = True, this is the XML file with the mirror tilts that we start with for the alignment; if it is blank or testing is not True, it uses the latest v-numbered xml (which is what should be currently in the DB) """, + "compareXMLFile": """ XML file with mirror tilts, for comparison of mirror tilts before and after alignment; if it is blank, it uses the latest v-numbered xml (which is what should be currently in the DB) """, + "startYAMLFile": """ ONLY IF testing = True, this is the YAML file with the mirror tilts that we start with for the alignment; if it is blank or testing is not True, it uses the latest v-numbered yml (which is what should be currently in the DB) """, + "compareYAMLFile": """ YAML file with mirror tilts, for comparison of mirror tilts before and after alignment; if it is blank, it uses the latest v-numbered yml (which is what should be currently in the DB) """, + "YAMLio": """ If True, then startYAMLFile and compareYAMLFile are considered instead of startXMLFile and compareXMLFile, the input is expected to be YAML, the output will be YAML, and it is assumed that the latest v-numbered file is yml and not xml """, + "useDD4hep": """ If True, then use DD4hep (YAML-based) for reconstruction instead of DetDesc (XML-based). Also YAMLio will be set to True within the Iterator. """, + "useHltDecisions": """ If True, then only process events with a RICH HLT line trigger decision (for the particular RICH being aligned) """, + "useReducedSubset": """ If True, then use a reduced subset of mirror combinations allowing only for the alignment of inner mirrors """, + "minP": """ minimum momentum cut for the tracks that we wish to reconstruct (in GeV) """, + "coeffCalibTilt": """ Mirror-tilts applied for the calculation of the magnification coefficients. """, + "minAverageBinPop": """ Demanded minimal entries per bin in x-y-bin; atm 6: for 20 phi-bins, 4.8: for 25 phi-bins. """, + "phiBinFactor": """ Factor by which the number of phi-bins is reduced. The histograms should now come with 60 phi bins, factor 3 reduced this to 20 bin in the fit.""", + "minFracPhiBinsPopulated": """ Fraction of the phi-bins that should be sufficiently populated, based on the current minAverageBinPop setting. Ideally this is 0.8, but sometimes we lower it if the mirror alignment still seems OK with a lower fraction, though we really should adjust the HLT line instead.""", + "deltaThetaWindow": """ dTheta-range in the histograms; 4.0 for Rich1 and 3.0 for Rich2. """, + "combinFitMethod": """ Method for fitting the 2D histograms; 1: first fit the slices of dTheta with a Gaussian and then fit to phi using only the mean of the Gaussian, 3: fit a 2D function, 5: Same as 3 but with unifyWidths """, + "stackDir": """ directory that contains the compiled code stack """, + "magnFactorsMode": """ Method for calculating the magnification coefficents; 0: magnefication coeff. pre-determined, 1: individual for all mirror pairs, determined in the 0-th iteration and not updated any further, 2: individual for all mirrorpairs, determined on-the-fly on the data. """, + "magnifDir": """ directory that contains the pre-determined magnification coeff., files in this folder have to be named Rich[1,2]_MirrMagn _[tiltName]_predefined.txt """, + "richFiles": """ directory (usually in /group/rich/) that contains the Logging, Polarity, testingMaybe, and rolling CKtrend and Update files """, + "XML_YAML_configDir": """ directory that contains the configuration files for the XML-YAML converter """, + "solutionMethod": """ Solution method for calculating the mirror tilts after the individual fits; 0: Minuit, 1: Algebraic """, + "regularizationMode": """ regularization mode (0/10/1/11): regularization terms magnified (weighted) with: 0(def)-> major & minor per-mirror MFs; 10-> only averaged per-kind major MFs; 1 (and 11, respectively)-> all weights = 1. """, + "stopDecisionMode": """ decision mode: default 0: use sqrt of the final regularization term, divided by the number of mirrors, 1: for each solution component use its own tolerance""", + "stopToleranceMode": """ tolerance mode: default 0: calculate the stopTolerances from nominal sigma, average magn factors and stopSigmaFraction, 1 use stopTolerances given below""", + "nominalResolutionSigma": """ RICH-dependent nominal Cherenkov angle resolution (in mrad)""", + "stopSigmaFraction": """ tolerance for total tilt of mirror pair in terms of the fraction of the nominal Cherenkov angle resolution """, + "maxIterations": """ The number of iterations the mirror alignment will run, before giving up """, + "requiredEvents": """ If this many events are not procesed by the farm, on average, we do run the alignment but we will never update it. """, + "autoUpdate": """ If True, then the fully automated updating system is activated. If False, our DB update service is still active but returns the starting alignment version. """, + "autoUpdateNoV": """ Only looked at if autoUpdate is True. Then, if autoUpdateNoV is False, nothing changes. If autoUpdateNoV is True, then rather than sending the existing alignment version if autoUpdate is disabled *and* there is a _maybe_ alignment, we will send no version through the DB update service. HLT2 will have to wait for us to assign one. """, + "testing": """ If True, then we are running a test alignment; we also disable our DB update service completely. """, + "trendDateRange": """ Set the date range for the automatic trend plots. Format is YYYYMMDD. Additionally, a minDate(maxDate) of None defaults to the first(last) day of the current year (see AlignMonitor.py).""", + "stopTolerancePriY": """ RICH-dependent tolerance for primary mirrors rotation around Y correction in mrad to stop the alignment """, + "stopTolerancePriZ": """ RICH-dependent tolerance for primary mirrors rotation around Z correction in mrad to stop the alignment """, + "stopToleranceSecY": """ RICH-dependent tolerance for secondary mirrors rotation around Y correction in mrad to stop the alignment """, + "stopToleranceSecZ": """ RICH-dependent tolerance for secondary mirrors rotation around Z correction in mrad to stop the alignment """, + "warningFactor": """ alerts the alignment if any of the mirrors have shifted more than warningFactor times a particular mirror rotation stopTolerance """, + "EvtMax": """ maximal number of events processed by Moore PER NODE (hlt farm has ~1500 nodes), -1 = infinite """, + "dataVariant": """ Helps us decide which Moore options to use (see RichAnalyzer.py); also used for the naming convention. """, + "fixSinusoidShift": """ True : fix at sinusoidShift; False : it is not fixed """, + "nameStr": """ Right now this is used only for the naming convention, but will be set when initiating the Configuration. """, + "runNumber": """ Defined as the earliest run in the fill """, } def setNameStr(self): @@ -625,7 +420,9 @@ class Rich2MirrAlignOnConf(LHCbConfigurableUser): thisTuning += f"Fm{self.getProp('combinFitMethod')}" thisTuning += f"Mm{self.getProp('magnFactorsMode')}" thisTuning += f"Sm{self.getProp('solutionMethod')}" - thisNameStr = f"{thisTuning}_{self.getProp('thisCase')}_{self.getProp('dataVariant')}" + thisNameStr = ( + f"{thisTuning}_{self.getProp('thisCase')}_{self.getProp('dataVariant')}" + ) self.setProp("nameStr", thisNameStr) #### Dont mess with this filename!!! @@ -634,9 +431,11 @@ class Rich2MirrAlignOnConf(LHCbConfigurableUser): # take earliest run in fill as the runNumber (for Monet's structure) runs = [] # can remove this when everything works for Run 3 import getpass + if "online" in getpass.getuser(): import OnlineEnvBase as Online # import OnlineEnv as Online from MooreOnlineConf.utils import alignment_options + online_options = alignment_options(Online) runs = online_options.runs # runs = Online.DeferredRuns # PN - Extract the run number substring from the full string - WILL NOT WORK IF RUN NUMBERS BECOME 7 DIGITS @@ -646,30 +445,32 @@ class Rich2MirrAlignOnConf(LHCbConfigurableUser): else: runNumber = "000000" # placeholder run number - first_dir = runNumber[:2] + '0' * (len(runNumber) - 2 - ) # returns 250000 for 256112 - second_dir = runNumber[:3] + '0' * (len(runNumber) - 3 - ) # returns 256000 for 256112 + first_dir = runNumber[:2] + "0" * ( + len(runNumber) - 2 + ) # returns 250000 for 256112 + second_dir = runNumber[:3] + "0" * ( + len(runNumber) - 3 + ) # returns 256000 for 256112 histodir = f"/hist/Savesets/ByRun/RichAlignMon/{first_dir}/{second_dir}/" os.makedirs( - histodir, - exist_ok=True) # create subdirectory path if it doesnt exist + histodir, exist_ok=True + ) # create subdirectory path if it doesnt exist self.setProp("HistoDir", histodir) self.setProp("runNumber", runNumber) def checkStartIt(self): if not self.getProp("magnFactorsMode") == 0: integerDivides = self.getProp("MinItStart") // len( - self.getProp("tiltNames")) + self.getProp("tiltNames") + ) if integerDivides != self.getProp("MajItStart"): print( "WARNING: Major Iteration did not match minor iteration. Major iteration is being set to match minor iteration." ) self.setProp("MajItStart", integerDivides) - if (self.getProp("magnFactorsMode") == 0 - and self.getProp("magnifDir") == ""): + if self.getProp("magnFactorsMode") == 0 and self.getProp("magnifDir") == "": self.setProp( - "magnifDir", '/group/rich/AlignmentFiles/MagnifFactors/Rich2/' + "magnifDir", "/group/rich/AlignmentFiles/MagnifFactors/Rich2/" ) # PN - This whole thing needs to be changed for Run 3, but indeed good to have a default directory for MagFactors print( "WARNING: Mode for calculating magnification coefficients was chosen to be 0 but no directory with pre-determined coefficients provided. Directory set to default." @@ -680,25 +481,27 @@ class Rich2MirrAlignOnConf(LHCbConfigurableUser): ) self.setProp( "MinItStart", - self.getProp("MajItStart") * len(self.getProp("tiltNames"))) + self.getProp("MajItStart") * len(self.getProp("tiltNames")), + ) def __apply_configuration__(self): self.setHistoDir() self.setNameStr() self.checkStartIt() # Next 3 lines add the trailing slash in key directory names - self.setProp('WorkDir', os.path.join(self.getProp('WorkDir'), '')) - self.setProp('SaveDir', os.path.join(self.getProp('SaveDir'), '')) - self.setProp('stackDir', os.path.join(self.getProp('stackDir'), '')) - self.setProp('magnifDir', os.path.join(self.getProp('magnifDir'), '')) - self.setProp('richFiles', os.path.join(self.getProp('richFiles'), '')) - self.setProp('XML_YAML_configDir', - os.path.join(self.getProp('XML_YAML_configDir'), '')) - self.setProp('HistoDir', os.path.join(self.getProp('HistoDir'), '')) + self.setProp("WorkDir", os.path.join(self.getProp("WorkDir"), "")) + self.setProp("SaveDir", os.path.join(self.getProp("SaveDir"), "")) + self.setProp("stackDir", os.path.join(self.getProp("stackDir"), "")) + self.setProp("magnifDir", os.path.join(self.getProp("magnifDir"), "")) + self.setProp("richFiles", os.path.join(self.getProp("richFiles"), "")) + self.setProp( + "XML_YAML_configDir", os.path.join(self.getProp("XML_YAML_configDir"), "") + ) + self.setProp("HistoDir", os.path.join(self.getProp("HistoDir"), "")) print("INFO: Rich2MirrAlignOnConf applied") -#=============================================================================== +# =============================================================================== # regularizationMode has changed from 1 (used in 2016) to 0 (used in 2017). # Looking back at the functional we minimize: # https://indico.cern.ch/event/477524/contributions/2174895/attachments/1276535/1894128/richmirralign_update_2016-05-20_rich_sw.pdf @@ -714,4 +517,4 @@ class Rich2MirrAlignOnConf(LHCbConfigurableUser): # In light of this, the RICH1 tolerances for 2017 should be set to: [0.027, 0.030, 0.455, 0.370] mrad # What we decided for RICH2 from 2016 study: [0.065, 0.055, 0.045, 0.035] mrad # In light of this, the RICH2 tolerances for 2017 should be set to: [0.032, 0.030, 0.043, 0.057] mrad -#=============================================================================== +# =============================================================================== diff --git a/Rich/RichMirrorAlignmentOnline/python/RichMirrorAlignmentOnline/SavedConfigurations/2016_Configurations/2016_AutomaticDecisionConfig.txt b/Rich/RichMirrorAlignmentOnline/python/RichMirrorAlignmentOnline/SavedConfigurations/2016_Configurations/2016_AutomaticDecisionConfig.txt index 041be815e9f314031352e169a643422718ea1786..4b77bf9c41395f130d2a23c22018d40527b3abf2 100644 --- a/Rich/RichMirrorAlignmentOnline/python/RichMirrorAlignmentOnline/SavedConfigurations/2016_Configurations/2016_AutomaticDecisionConfig.txt +++ b/Rich/RichMirrorAlignmentOnline/python/RichMirrorAlignmentOnline/SavedConfigurations/2016_Configurations/2016_AutomaticDecisionConfig.txt @@ -312,4 +312,3 @@ class Rich2MirrAlignOnConf(LHCbConfigurableUser): # What we decided for RICH2 from 2016 study: [0.065, 0.055, 0.045, 0.035] mrad # In light of this, the RICH2 tolerances for 2017 should be set to: [0.032, 0.030, 0.043, 0.057] mrad #=============================================================================== - diff --git a/Rich/RichMirrorAlignmentOnline/python/RichMirrorAlignmentOnline/SavedConfigurations/2016_Configurations/2016_PreAutomaticDecisionConfig.txt b/Rich/RichMirrorAlignmentOnline/python/RichMirrorAlignmentOnline/SavedConfigurations/2016_Configurations/2016_PreAutomaticDecisionConfig.txt index fcd2f05abc265520498c12f6165f8101a2641b7d..1b147eeb84f3b5b6e48fa893f05ee3deff84688c 100644 --- a/Rich/RichMirrorAlignmentOnline/python/RichMirrorAlignmentOnline/SavedConfigurations/2016_Configurations/2016_PreAutomaticDecisionConfig.txt +++ b/Rich/RichMirrorAlignmentOnline/python/RichMirrorAlignmentOnline/SavedConfigurations/2016_Configurations/2016_PreAutomaticDecisionConfig.txt @@ -311,4 +311,3 @@ class Rich2MirrAlignOnConf(LHCbConfigurableUser): # What we decided for RICH2 from 2016 study: [0.065, 0.055, 0.045, 0.035] mrad # In light of this, the RICH2 tolerances for 2017 should be set to: [0.032, 0.030, 0.043, 0.057] mrad #=============================================================================== - diff --git a/Rich/RichMirrorAlignmentOnline/python/RichMirrorAlignmentOnline/SavedConfigurations/2018_Configurations/Configuration.py b/Rich/RichMirrorAlignmentOnline/python/RichMirrorAlignmentOnline/SavedConfigurations/2018_Configurations/Configuration.py index 747e49d891204bb07dfd99e19b05d46c615de2ea..f5ca9dda7a5e202e55f3b891d7c9dbf2706b3e0c 100644 --- a/Rich/RichMirrorAlignmentOnline/python/RichMirrorAlignmentOnline/SavedConfigurations/2018_Configurations/Configuration.py +++ b/Rich/RichMirrorAlignmentOnline/python/RichMirrorAlignmentOnline/SavedConfigurations/2018_Configurations/Configuration.py @@ -32,223 +32,148 @@ __copyright__ = "University of Bristol, May 2018" ### Some details on regularizationMode are listed at the end of this file import os -from Gaudi.Configuration import * + import GaudiKernel.ProcessJobOptions -from Configurables import (LHCbConfigurableUser) +from Configurables import LHCbConfigurableUser +from Gaudi.Configuration import * class Rich1MirrAlignOnConf(LHCbConfigurableUser): __used_configurables__ = [] __slots__ = { #### Do not change these!!! Just DON'T! - "Rich": - 1, - "HistoDir": - "" + "Rich": 1, + "HistoDir": "", #### Only change these if you want to pick up from where you left off in iterations, experts only (we don't use this much anymore) - , - "MajItStart": - 0, - "MinItStart": - 0 + "MajItStart": 0, + "MinItStart": 0, ### Better not change these, only for very very VERY good reasons - , - "WorkDir": - "/group/online/AligWork/Rich1/", - "SaveDir": - "/group/online/AligWork/MirrorAlignments/", - "ItNrFile": - "/group/online/dataflow/options/LHCbA/Rich1_Alignment_Reference_File.txt", - "thisCase": - "online", + "WorkDir": "/group/online/AligWork/Rich1/", + "SaveDir": "/group/online/AligWork/MirrorAlignments/", + "ItNrFile": "/group/online/dataflow/options/LHCbA/Rich1_Alignment_Reference_File.txt", + "thisCase": "online", "tiltNames": [ - "", "pri_negYzerZ", "pri_posYzerZ", "pri_zerYnegZ", "pri_zerYposZ", - "sec_negYzerZ", "sec_posYzerZ", "sec_zerYnegZ", "sec_zerYposZ" - ] + "", + "pri_negYzerZ", + "pri_posYzerZ", + "pri_zerYnegZ", + "pri_zerYposZ", + "sec_negYzerZ", + "sec_posYzerZ", + "sec_zerYnegZ", + "sec_zerYposZ", + ], ### May be changed if you know what you are doing, explanations below - , - "combAndMirrSubsets": - "/group/rich/sw/cmtuser/AlignmentRelease/Rich/RichMirrorAlignmentOnline/files/Rich1CombAndMirrSubsets.txt", - "startXMLFile": - "" # "/group/rich/AlignmentFiles/databaseAlignments/Rich1/Rich1_Zeroed.xml" # if testing is not True OR this is blank, it automatically uses the DB XML file - , - "compareXMLFile": - "" # if this is blank, it automatically uses the DB XML file - , - "coeffCalibTilt": - 0.7, - "minAverageBinPop": - 6, - "phiBinFactor": - 3, - "minFracPhiBinsPopulated": - 0.8, - "deltaThetaWindow": - 8.0, - "combinFitMethod": - 5, - "magnFactorsMode": - 0, - "magnifDir": - "/group/rich/sw/cmtuser/AlignmentRelease/Rich/RichMirrorAlignmentOnline/files/MagnifFactors/Rich1/20180424_164201/" + "combAndMirrSubsets": "/group/rich/sw/cmtuser/AlignmentRelease/Rich/RichMirrorAlignmentOnline/files/Rich1CombAndMirrSubsets.txt", + "startXMLFile": "", # "/group/rich/AlignmentFiles/databaseAlignments/Rich1/Rich1_Zeroed.xml" # if testing is not True OR this is blank, it automatically uses the DB XML file + "compareXMLFile": "", # if this is blank, it automatically uses the DB XML file + "coeffCalibTilt": 0.7, + "minAverageBinPop": 6, + "phiBinFactor": 3, + "minFracPhiBinsPopulated": 0.8, + "deltaThetaWindow": 8.0, + "combinFitMethod": 5, + "magnFactorsMode": 0, + "magnifDir": "/group/rich/sw/cmtuser/AlignmentRelease/Rich/RichMirrorAlignmentOnline/files/MagnifFactors/Rich1/20180424_164201/", # ,"magnifDir" : "/group/rich/AlignmentFiles/MagnifFactors/Rich1/20180424_164201/" - , - "solutionMethod": - 0, - "regularizationMode": - 0, - "stopToleranceMode": - 1, - "nominalResolutionSigma": - 1.66 # by eye, looking at mirror resolutions between fills 6130 and 6280 (e.g. post- best MDCS corrections for 2017) + "solutionMethod": 0, + "regularizationMode": 0, + "stopToleranceMode": 1, + "nominalResolutionSigma": 1.66, # by eye, looking at mirror resolutions between fills 6130 and 6280 (e.g. post- best MDCS corrections for 2017) # ,"nominalResolutionSigma" : 1.639 # from https://lblogbook.cern.ch/RICH/13677 - , - "stopSigmaFraction": - 0, - "maxIterations": - 8, - "requiredEvents": - 1180000 # ~70% of 1684783 - , - "autoUpdate": - True, - "autoUpdateNoV": - False, - "testing": - False, - "trendDateRange": { - 'minDate': None, - 'maxDate': None - } + "stopSigmaFraction": 0, + "maxIterations": 8, + "requiredEvents": 1180000, # ~70% of 1684783 + "autoUpdate": True, + "autoUpdateNoV": False, + "testing": False, + "trendDateRange": {"minDate": None, "maxDate": None}, # 2017 tolerances: [0.027, 0.030, 0.455, 0.370], adjusted to [0.03, 0.03, 0.46, 0.37] - , - "stopTolerancePriY": - 0.03, - "stopTolerancePriZ": - 0.03, - "stopToleranceSecY": - 0.46, - "stopToleranceSecZ": - 0.37, - "warningFactor": - 3, - "EvtMax": - -1, - "dataVariant": - "Collision18", - "fixSinusoidShift": - 1, - "nameStr": - "", - "displayMode": - 1, - "xmlMDCS": - "" # "/group/rich/AlignmentFiles/MDCS/Conditions/Rich1/Environment/HPD.xml" + "stopTolerancePriY": 0.03, + "stopTolerancePriZ": 0.03, + "stopToleranceSecY": 0.46, + "stopToleranceSecZ": 0.37, + "warningFactor": 3, + "EvtMax": -1, + "dataVariant": "Collision18", + "fixSinusoidShift": 1, + "nameStr": "", + "displayMode": 1, + "xmlMDCS": "", # "/group/rich/AlignmentFiles/MDCS/Conditions/Rich1/Environment/HPD.xml" } _propertyDocDct = { - "MajItStart": - """ Start the alignment at this major iteration. Please make sure this is consitent with MinItStart. """, - "MinItStart": - """ Start the alignment at this minor iteration. Please make sure this is consitent with MajItStart. """, - "Rich": - """ Rich1 or Rich2. """, - "HistoDir": - """ Directory where the savesets are being written to. """, - "WorkDir": - """ Directory in which all the output will be written. """, - "SaveDir": - """ Directory in which all output files of the alignment are saved after it has finished """, - "ItNrFile": - """ File which contains only the number of the current iteration written by the iterator, to be read by the analyzers """, - "thisCase": - """ Right now this is used only for the naming convention. """, - "tiltNames": - """ Combination of tilts for the calculation and usage of the magnification factors. This is needed even when using predefined magnification factors!!! """, - "combAndMirrSubsets": - """ File that lists the subset of combinations of primary and secondary mirror segments chosen for alignment monitoring, and all mirror segments under alignment monitoring """, - "startXMLFile": - """ ONLY IF testing = True, this is the XML file with the mirror tilts that we start with for the alignment; if it is blank or testing is not True, it uses the latest v-numbered xml (which is what should be currently in the DB) """, - "compareXMLFile": - """ XML file with mirror tilts, for comparison of mirror tilts before and after alignment; if it is blank, it uses the latest v-numbered xml (which is what should be currently in the DB) """, - "coeffCalibTilt": - """ Mirror-tilts applied for the calculation of the magnification coefficients. """, - "minAverageBinPop": - """ Demanded minimal entries per bin in x-y-bin; atm 6: for 20 phi-bins, 4.8: for 25 phi-bins. """, - "phiBinFactor": - """ Factor by which the number of phi-bins is reduced. The histograms should now come with 60 phi bins, factor 3 reduced this to 20 bin in the fit.""", - "minFracPhiBinsPopulated": - """ Fraction of the phi-bins that should be sufficiently populated, based on the current minAverageBinPop setting. Ideally this is 0.8, but sometimes we lower it if the mirror alignment still seems OK with a lower fraction, though we really should adjust the HLT line instead.""", - "deltaThetaWindow": - """ dTheta-range in the histograms; 4.0 for Rich1 and 3.0 for Rich2. """, - "combinFitMethod": - """ Method for fitting the 2D histograms; 1: first fit the slices of dTheta with a Gaussian and then fit to phi using only the mean of the Gaussian, 3: fit a 2D function, 5: same as 3 but with unifyWidths """, - "magnFactorsMode": - """ Method for calculating the magnification coefficents; 0: magnefication coeff. pre-determined, 1: individual for all mirror pairs, determined in the 0-th iteration and not updated any further, 2: individual for all mirrorpairs, determined on-the-fly on the data. """, - "magnifDir": - """ directory that contains the pre-determined magnification coeff., files in this folder have to be named Rich[1,2]_MirrMagn _[tiltName]_predefined.txt """, - "solutionMethod": - """ Solution method for calculating the mirror tilts after the individual fits; 0: Minuit, 1: Algebraic """, - "regularizationMode": - """ regularization mode (0/10/1/11): regularization terms magnified (weighted) with: 0(def)-> major & minor per-mirror MFs; 10-> only averaged per-kind major MFs; 1 (and 11, respectively)-> all weights = 1. """, - "stopToleranceMode": - """ tolerance mode: default 0: calculate the stopTolerances from nominal sigma, average magn factors and stopSigmaFraction, 1 use stopTolerances given below""", - "nominalResolutionSigma": - """ RICH-dependent nominal Cherenkov angle resolution (in mrad)""", - "stopSigmaFraction": - """ tolerance for total tilt of mirror pair in terms of the fraction of the nominal Cherenkov angle resolution """, - "maxIterations": - """ The number of iterations the mirror alignment will run, before giving up """, - "requiredEvents": - """ If this many events are not procesed by the farm, on average, we do run the alignment but we will never update it. """, - "autoUpdate": - """ If True, then the fully automated updating system is activated. If False, our DB update service is still active but returns the starting alignment version. """, - "autoUpdateNoV": - """ Only looked at if autoUpdate is True. Then, if autoUpdateNoV is False, nothing changes. If autoUpdateNoV is True, then rather than sending the existing alignment version if autoUpdate is disabled *and* there is a _maybe_ alignment, we will send no version through the DB update service. HLT2 will have to wait for us to assign one. """, - "testing": - """ If True, then we are running a test alignment; we also disable our DB update service completely. """, - "trendDateRange": - """ Set the date range for the automatic trend plots. Format is YYYYMMDD. Additionally, a minDate(maxDate) of None defaults to the first(last) day of the current year (see AlignMonitor.py).""", - "stopTolerancePriY": - """ RICH-dependent tolerance for primary mirrors rotation around Y correction in mrad to stop the alignment """, - "stopTolerancePriZ": - """ RICH-dependent tolerance for primary mirrors rotation around Z correction in mrad to stop the alignment """, - "stopToleranceSecY": - """ RICH-dependent tolerance for secondary mirrors rotation around Y correction in mrad to stop the alignment """, - "stopToleranceSecZ": - """ RICH-dependent tolerance for secondary mirrors rotation around Z correction in mrad to stop the alignment """, - "warningFactor": - """ alerts the alignment if any of the mirrors have shifted more than warningFactor times a particular mirror rotation stopTolerance """, - "EvtMax": - """ maximal number of events processed by brunel PER NODE (hlt farm has ~1500 nodes), -1 = infinite """, - "dataVariant": - """ Helps us decide which Brunel options to use (see RichAnalyzer.py); also used for the naming convention. """, - "fixSinusoidShift": - """ 1 : fix at sinusoidShift; 0 : it is not fixed """, - "nameStr": - """ Right now this is used only for the naming convention, but will be set when initiating the Configuration. """, - "displayMode": - """ 1 : Current TH2D display style (auto-scaling Z-axis, granular colors, using same colors for > 4*threshold); 0: Anatoly's development TH2D display style (similar, but with printed mirror number also, and fixed scale)""", - "xmlMDCS": - """ Location of MDCS conditions XML file, for override if needed. Not used if blank. """ + "MajItStart": """ Start the alignment at this major iteration. Please make sure this is consitent with MinItStart. """, + "MinItStart": """ Start the alignment at this minor iteration. Please make sure this is consitent with MajItStart. """, + "Rich": """ Rich1 or Rich2. """, + "HistoDir": """ Directory where the savesets are being written to. """, + "WorkDir": """ Directory in which all the output will be written. """, + "SaveDir": """ Directory in which all output files of the alignment are saved after it has finished """, + "ItNrFile": """ File which contains only the number of the current iteration written by the iterator, to be read by the analyzers """, + "thisCase": """ Right now this is used only for the naming convention. """, + "tiltNames": """ Combination of tilts for the calculation and usage of the magnification factors. This is needed even when using predefined magnification factors!!! """, + "combAndMirrSubsets": """ File that lists the subset of combinations of primary and secondary mirror segments chosen for alignment monitoring, and all mirror segments under alignment monitoring """, + "startXMLFile": """ ONLY IF testing = True, this is the XML file with the mirror tilts that we start with for the alignment; if it is blank or testing is not True, it uses the latest v-numbered xml (which is what should be currently in the DB) """, + "compareXMLFile": """ XML file with mirror tilts, for comparison of mirror tilts before and after alignment; if it is blank, it uses the latest v-numbered xml (which is what should be currently in the DB) """, + "coeffCalibTilt": """ Mirror-tilts applied for the calculation of the magnification coefficients. """, + "minAverageBinPop": """ Demanded minimal entries per bin in x-y-bin; atm 6: for 20 phi-bins, 4.8: for 25 phi-bins. """, + "phiBinFactor": """ Factor by which the number of phi-bins is reduced. The histograms should now come with 60 phi bins, factor 3 reduced this to 20 bin in the fit.""", + "minFracPhiBinsPopulated": """ Fraction of the phi-bins that should be sufficiently populated, based on the current minAverageBinPop setting. Ideally this is 0.8, but sometimes we lower it if the mirror alignment still seems OK with a lower fraction, though we really should adjust the HLT line instead.""", + "deltaThetaWindow": """ dTheta-range in the histograms; 4.0 for Rich1 and 3.0 for Rich2. """, + "combinFitMethod": """ Method for fitting the 2D histograms; 1: first fit the slices of dTheta with a Gaussian and then fit to phi using only the mean of the Gaussian, 3: fit a 2D function, 5: same as 3 but with unifyWidths """, + "magnFactorsMode": """ Method for calculating the magnification coefficents; 0: magnefication coeff. pre-determined, 1: individual for all mirror pairs, determined in the 0-th iteration and not updated any further, 2: individual for all mirrorpairs, determined on-the-fly on the data. """, + "magnifDir": """ directory that contains the pre-determined magnification coeff., files in this folder have to be named Rich[1,2]_MirrMagn _[tiltName]_predefined.txt """, + "solutionMethod": """ Solution method for calculating the mirror tilts after the individual fits; 0: Minuit, 1: Algebraic """, + "regularizationMode": """ regularization mode (0/10/1/11): regularization terms magnified (weighted) with: 0(def)-> major & minor per-mirror MFs; 10-> only averaged per-kind major MFs; 1 (and 11, respectively)-> all weights = 1. """, + "stopToleranceMode": """ tolerance mode: default 0: calculate the stopTolerances from nominal sigma, average magn factors and stopSigmaFraction, 1 use stopTolerances given below""", + "nominalResolutionSigma": """ RICH-dependent nominal Cherenkov angle resolution (in mrad)""", + "stopSigmaFraction": """ tolerance for total tilt of mirror pair in terms of the fraction of the nominal Cherenkov angle resolution """, + "maxIterations": """ The number of iterations the mirror alignment will run, before giving up """, + "requiredEvents": """ If this many events are not procesed by the farm, on average, we do run the alignment but we will never update it. """, + "autoUpdate": """ If True, then the fully automated updating system is activated. If False, our DB update service is still active but returns the starting alignment version. """, + "autoUpdateNoV": """ Only looked at if autoUpdate is True. Then, if autoUpdateNoV is False, nothing changes. If autoUpdateNoV is True, then rather than sending the existing alignment version if autoUpdate is disabled *and* there is a _maybe_ alignment, we will send no version through the DB update service. HLT2 will have to wait for us to assign one. """, + "testing": """ If True, then we are running a test alignment; we also disable our DB update service completely. """, + "trendDateRange": """ Set the date range for the automatic trend plots. Format is YYYYMMDD. Additionally, a minDate(maxDate) of None defaults to the first(last) day of the current year (see AlignMonitor.py).""", + "stopTolerancePriY": """ RICH-dependent tolerance for primary mirrors rotation around Y correction in mrad to stop the alignment """, + "stopTolerancePriZ": """ RICH-dependent tolerance for primary mirrors rotation around Z correction in mrad to stop the alignment """, + "stopToleranceSecY": """ RICH-dependent tolerance for secondary mirrors rotation around Y correction in mrad to stop the alignment """, + "stopToleranceSecZ": """ RICH-dependent tolerance for secondary mirrors rotation around Z correction in mrad to stop the alignment """, + "warningFactor": """ alerts the alignment if any of the mirrors have shifted more than warningFactor times a particular mirror rotation stopTolerance """, + "EvtMax": """ maximal number of events processed by brunel PER NODE (hlt farm has ~1500 nodes), -1 = infinite """, + "dataVariant": """ Helps us decide which Brunel options to use (see RichAnalyzer.py); also used for the naming convention. """, + "fixSinusoidShift": """ 1 : fix at sinusoidShift; 0 : it is not fixed """, + "nameStr": """ Right now this is used only for the naming convention, but will be set when initiating the Configuration. """, + "displayMode": """ 1 : Current TH2D display style (auto-scaling Z-axis, granular colors, using same colors for > 4*threshold); 0: Anatoly's development TH2D display style (similar, but with printed mirror number also, and fixed scale)""", + "xmlMDCS": """ Location of MDCS conditions XML file, for override if needed. Not used if blank. """, } def setNameStr(self): - thisTuning = "Mp" + str(self.getProp('minAverageBinPop')) - thisTuning += "Wi" + str(self.getProp('deltaThetaWindow')) - thisTuning += "Fm" + str(self.getProp('combinFitMethod')) - thisTuning += "Mm" + str(self.getProp('magnFactorsMode')) - thisTuning += "Sm" + str(self.getProp('solutionMethod')) - thisNameStr = thisTuning + "_" + str( - self.getProp('thisCase')) + "_" + str(self.getProp('dataVariant')) + thisTuning = "Mp" + str(self.getProp("minAverageBinPop")) + thisTuning += "Wi" + str(self.getProp("deltaThetaWindow")) + thisTuning += "Fm" + str(self.getProp("combinFitMethod")) + thisTuning += "Mm" + str(self.getProp("magnFactorsMode")) + thisTuning += "Sm" + str(self.getProp("solutionMethod")) + thisNameStr = ( + thisTuning + + "_" + + str(self.getProp("thisCase")) + + "_" + + str(self.getProp("dataVariant")) + ) self.setProp("nameStr", thisNameStr) ### Dont mess with this filename!!! def setHistoDir(self): import time + year = time.strftime("%Y") - histodir = "/hist/Savesets/" + str(year) + "/LHCbA/AligWrk_Rich" + str( - self.getProp("Rich")) + "/" + histodir = ( + "/hist/Savesets/" + + str(year) + + "/LHCbA/AligWrk_Rich" + + str(self.getProp("Rich")) + + "/" + ) self.setProp("HistoDir", histodir) def checkStartIt(self): @@ -256,19 +181,24 @@ class Rich1MirrAlignOnConf(LHCbConfigurableUser): if self.getProp("MinItStart") < 9: if not self.getProp("MajItStart") == 0: self.setProp("MajItStart", 0) - print "Warning: Major Iteration did not match minor itertion. Major iteration was set to match minor iteration." + print( + "Warning: Major Iteration did not match minor itertion. Major iteration was set to match minor iteration." + ) else: - majstartit = (self.getProp("MinItStart") - ( - self.getProp("MinItStart") % self.getProp("MajItStart")) - ) / self.getProp("MajItStart") + majstartit = ( + self.getProp("MinItStart") + - (self.getProp("MinItStart") % self.getProp("MajItStart")) + ) / self.getProp("MajItStart") if not self.getProp("MajItStart") == majstartit: - self.setProp('MajItStart', majstartit) - print "Warning: Major Iteration did not match minor itertion. Major iteration was set to match minor iteration." - if (self.getProp("magnFactorsMode") == 0 - and self.getProp("magnifDir") == ""): - self.setProp("magnifDir", - '/group/rich/AlignmentFiles/MagnifFactors/Rich1/') - print "Warning: Mode for calculating magnification coefficients was chosen to be 0 but no directory with pre-determined coefficients provided. Directory set to default." + self.setProp("MajItStart", majstartit) + print( + "Warning: Major Iteration did not match minor itertion. Major iteration was set to match minor iteration." + ) + if self.getProp("magnFactorsMode") == 0 and self.getProp("magnifDir") == "": + self.setProp("magnifDir", "/group/rich/AlignmentFiles/MagnifFactors/Rich1/") + print( + "Warning: Mode for calculating magnification coefficients was chosen to be 0 but no directory with pre-determined coefficients provided. Directory set to default." + ) if self.getProp("magnFactorsMode") == 0: self.setProp("MinItStart", self.getProp("MajItStart") * 9) @@ -277,10 +207,10 @@ class Rich1MirrAlignOnConf(LHCbConfigurableUser): self.setNameStr() self.checkStartIt() # Next 3 lines add the trailing slash in key directory names - self.setProp('WorkDir', os.path.join(self.getProp('WorkDir'), '')) - self.setProp('SaveDir', os.path.join(self.getProp('SaveDir'), '')) - self.setProp('magnifDir', os.path.join(self.getProp('magnifDir'), '')) - print "INFO: Rich1MirrAlignOnConf applied" + self.setProp("WorkDir", os.path.join(self.getProp("WorkDir"), "")) + self.setProp("SaveDir", os.path.join(self.getProp("SaveDir"), "")) + self.setProp("magnifDir", os.path.join(self.getProp("magnifDir"), "")) + print("INFO: Rich1MirrAlignOnConf applied") class Rich2MirrAlignOnConf(LHCbConfigurableUser): @@ -288,214 +218,137 @@ class Rich2MirrAlignOnConf(LHCbConfigurableUser): __slots__ = { #### Do not ever change these!!! Just DONT! - "Rich": - 2, - "HistoDir": - "" + "Rich": 2, + "HistoDir": "", #### Only change these if you want to pick up from where you left off in iterations, experts only (we don't use this much anymore) - , - "MajItStart": - 0, - "MinItStart": - 0 + "MajItStart": 0, + "MinItStart": 0, ### Better not change these, only for very very VERY good reasons - , - "WorkDir": - "/group/online/AligWork/Rich2/", - "SaveDir": - "/group/online/AligWork/MirrorAlignments/", - "ItNrFile": - "/group/online/dataflow/options/LHCbA/Rich2_Alignment_Reference_File.txt", - "thisCase": - "online", + "WorkDir": "/group/online/AligWork/Rich2/", + "SaveDir": "/group/online/AligWork/MirrorAlignments/", + "ItNrFile": "/group/online/dataflow/options/LHCbA/Rich2_Alignment_Reference_File.txt", + "thisCase": "online", "tiltNames": [ - "", "pri_negYzerZ", "pri_posYzerZ", "pri_zerYnegZ", "pri_zerYposZ", - "sec_negYzerZ", "sec_posYzerZ", "sec_zerYnegZ", "sec_zerYposZ" - ] + "", + "pri_negYzerZ", + "pri_posYzerZ", + "pri_zerYnegZ", + "pri_zerYposZ", + "sec_negYzerZ", + "sec_posYzerZ", + "sec_zerYnegZ", + "sec_zerYposZ", + ], ### May be changed if you know what you are doing - , - "combAndMirrSubsets": - "/group/rich/sw/cmtuser/AlignmentRelease/Rich/RichMirrorAlignmentOnline/files/Rich2CombAndMirrSubsets.txt", - "startXMLFile": - "" # "/group/rich/AlignmentFiles/databaseAlignments/Rich2/Rich2_Zeroed.xml" # if testing is not True OR this is blank, it automatically uses the DB XML file - , - "compareXMLFile": - "" # if this is blank, it automatically uses the DB XML file - , - "coeffCalibTilt": - 0.3, - "minAverageBinPop": - 6, - "phiBinFactor": - 3, - "minFracPhiBinsPopulated": - 0.7 # adjusted from 0.8 due to inefficiencies in our existing choice of HLT line prescales - , - "deltaThetaWindow": - 4.0, - "combinFitMethod": - 5, - "magnFactorsMode": - 0, - "magnifDir": - "/group/rich/sw/cmtuser/AlignmentRelease/Rich/RichMirrorAlignmentOnline/files/MagnifFactors/Rich2/20180424_145140/" + "combAndMirrSubsets": "/group/rich/sw/cmtuser/AlignmentRelease/Rich/RichMirrorAlignmentOnline/files/Rich2CombAndMirrSubsets.txt", + "startXMLFile": "", # "/group/rich/AlignmentFiles/databaseAlignments/Rich2/Rich2_Zeroed.xml" # if testing is not True OR this is blank, it automatically uses the DB XML file + "compareXMLFile": "", # if this is blank, it automatically uses the DB XML file + "coeffCalibTilt": 0.3, + "minAverageBinPop": 6, + "phiBinFactor": 3, + "minFracPhiBinsPopulated": 0.7, # adjusted from 0.8 due to inefficiencies in our existing choice of HLT line prescales + "deltaThetaWindow": 4.0, + "combinFitMethod": 5, + "magnFactorsMode": 0, + "magnifDir": "/group/rich/sw/cmtuser/AlignmentRelease/Rich/RichMirrorAlignmentOnline/files/MagnifFactors/Rich2/20180424_145140/", # ,"magnifDir" : "/group/rich/AlignmentFiles/MagnifFactors/Rich2/20180424_145140/" - , - "solutionMethod": - 0, - "regularizationMode": - 0, - "stopToleranceMode": - 1, - "nominalResolutionSigma": - 0.656 # from https://lblogbook.cern.ch/RICH/13678 (and still seems reasonable throughout 2017) - , - "stopSigmaFraction": - 0, - "maxIterations": - 8, - "requiredEvents": - 942500 # ~70% of 1346563 - , - "autoUpdate": - True, - "autoUpdateNoV": - False, - "testing": - False, - "trendDateRange": { - 'minDate': None, - 'maxDate': None - } + "solutionMethod": 0, + "regularizationMode": 0, + "stopToleranceMode": 1, + "nominalResolutionSigma": 0.656, # from https://lblogbook.cern.ch/RICH/13678 (and still seems reasonable throughout 2017) + "stopSigmaFraction": 0, + "maxIterations": 8, + "requiredEvents": 942500, # ~70% of 1346563 + "autoUpdate": True, + "autoUpdateNoV": False, + "testing": False, + "trendDateRange": {"minDate": None, "maxDate": None}, # 2017 tolerances: [0.032, 0.030, 0.043, 0.057], adjusted to [0.03, 0.03, 0.05, 0.06] - , - "stopTolerancePriY": - 0.03, - "stopTolerancePriZ": - 0.03, - "stopToleranceSecY": - 0.05, - "stopToleranceSecZ": - 0.06, - "warningFactor": - 3, - "EvtMax": - -1, - "dataVariant": - "Collision18", - "fixSinusoidShift": - 1, - "nameStr": - "", - "displayMode": - 1, - "xmlMDCS": - "" # "/group/rich/AlignmentFiles/MDCS/Conditions/Rich1/Environment/HPD.xml" # 'Rich1' is not a typo! + "stopTolerancePriY": 0.03, + "stopTolerancePriZ": 0.03, + "stopToleranceSecY": 0.05, + "stopToleranceSecZ": 0.06, + "warningFactor": 3, + "EvtMax": -1, + "dataVariant": "Collision18", + "fixSinusoidShift": 1, + "nameStr": "", + "displayMode": 1, + "xmlMDCS": "", # "/group/rich/AlignmentFiles/MDCS/Conditions/Rich1/Environment/HPD.xml" # 'Rich1' is not a typo! } _propertyDocDct = { - "MajItStart": - """ Start the alignment at this major iteration. Please make sure this is consitent with MinItStart. """, - "MinItStart": - """ Start the alignment at this minor iteration. Please make sure this is consitent with MajItStart. """, - "Rich": - """ Rich1 or Rich2. """, - "HistoDir": - """ Directory where the savesets are being written to. """, - "WorkDir": - """ Directory in which all the output will be written. """, - "SaveDir": - """ Directory in which all output files of the alignment are saved after it has finished """, - "ItNrFile": - """ File which contains only the number of the current iteration written by the iterator, to be read by the analyzers """, - "thisCase": - """ Right now this is used only for the naming convention. """, - "tiltNames": - """ Combination of tilts for the calculation and usage of the magnification factors. This is needed even when using predefined magnification factors!!! """, - "combAndMirrSubsets": - """ File that lists the subset of combinations of primary and secondary mirror segments chosen for alignment monitoring, and all mirror segments under alignment monitoring """, - "startXMLFile": - """ ONLY IF testing = True, this is the XML file with the mirror tilts that we start with for the alignment; if it is blank or testing is not True, it uses the latest v-numbered xml (which is what should be currently in the DB) """, - "compareXMLFile": - """ XML file with mirror tilts, for comparison of mirror tilts before and after alignment; if it is blank, it uses the latest v-numbered xml (which is what should be currently in the DB) """, - "coeffCalibTilt": - """ Mirror-tilts applied for the calculation of the magnification coefficients. """, - "minAverageBinPop": - """ Demanded minimal entries per bin in x-y-bin; atm 6: for 20 phi-bins, 4.8: for 25 phi-bins. """, - "phiBinFactor": - """ Factor by which the number of phi-bins is reduced. The histograms should now come with 60 phi bins, factor 3 reduced this to 20 bin in the fit.""", - "minFracPhiBinsPopulated": - """ Fraction of the phi-bins that should be sufficiently populated, based on the current minAverageBinPop setting. Ideally this is 0.8, but sometimes we lower it if the mirror alignment still seems OK with a lower fraction, though we really should adjust the HLT line instead.""", - "deltaThetaWindow": - """ dTheta-range in the histograms; 4.0 for Rich1 and 3.0 for Rich2. """, - "combinFitMethod": - """ Method for fitting the 2D histograms; 1: first fit the slices of dTheta with a Gaussian and then fit to phi using only the mean of the Gaussian, 3: fit a 2D function, 5: Same as 3 but with unifyWidths """, - "magnFactorsMode": - """ Method for calculating the magnification coefficents; 0: magnefication coeff. pre-determined, 1: individual for all mirror pairs, determined in the 0-th iteration and not updated any further, 2: individual for all mirrorpairs, determined on-the-fly on the data. """, - "magnifDir": - """ directory that contains the pre-determined magnification coeff., files in this folder have to be named Rich[1,2]_MirrMagn _[tiltName]_predefined.txt """, - "solutionMethod": - """ Solution method for calculating the mirror tilts after the individual fits; 0: Minuit, 1: Algebraic """, - "regularizationMode": - """ regularization mode (0/10/1/11): regularization terms magnified (weighted) with: 0(def)-> major & minor per-mirror MFs; 10-> only averaged per-kind major MFs; 1 (and 11, respectively)-> all weights = 1. """, - "stopToleranceMode": - """ tolerance mode: default 0: calculate the stopTolerances from nominal sigma, average magn factors and stopSigmaFraction, 1 use stopTolerances given below""", - "nominalResolutionSigma": - """ RICH-dependent nominal Cherenkov angle resolution (in mrad)""", - "stopSigmaFraction": - """ tolerance for total tilt of mirror pair in terms of the fraction of the nominal Cherenkov angle resolution """, - "maxIterations": - """ The number of iterations the mirror alignment will run, before giving up """, - "requiredEvents": - """ If this many events are not procesed by the farm, on average, we do run the alignment but we will never update it. """, - "autoUpdate": - """ If True, then the fully automated updating system is activated. If False, our DB update service is still active but returns the starting alignment version. """, - "autoUpdateNoV": - """ Only looked at if autoUpdate is True. Then, if autoUpdateNoV is False, nothing changes. If autoUpdateNoV is True, then rather than sending the existing alignment version if autoUpdate is disabled *and* there is a _maybe_ alignment, we will send no version through the DB update service. HLT2 will have to wait for us to assign one. """, - "testing": - """ If True, then we are running a test alignment; we also disable our DB update service completely. """, - "trendDateRange": - """ Set the date range for the automatic trend plots. Format is YYYYMMDD. Additionally, a minDate(maxDate) of None defaults to the first(last) day of the current year (see AlignMonitor.py).""", - "stopTolerancePriY": - """ RICH-dependent tolerance for primary mirrors rotation around Y correction in mrad to stop the alignment """, - "stopTolerancePriZ": - """ RICH-dependent tolerance for primary mirrors rotation around Z correction in mrad to stop the alignment """, - "stopToleranceSecY": - """ RICH-dependent tolerance for secondary mirrors rotation around Y correction in mrad to stop the alignment """, - "stopToleranceSecZ": - """ RICH-dependent tolerance for secondary mirrors rotation around Z correction in mrad to stop the alignment """, - "warningFactor": - """ alerts the alignment if any of the mirrors have shifted more than warningFactor times a particular mirror rotation stopTolerance """, - "EvtMax": - """ maximal number of events processed by brunel PER NODE (hlt farm has ~1500 nodes), -1 = infinite """, - "dataVariant": - """ Helps us decide which Brunel options to use (see RichAnalyzer.py); also used for the naming convention. """, - "fixSinusoidShift": - """ 1 : fix at sinusoidShift; 0 : it is not fixed """, - "nameStr": - """ Right now this is used only for the naming convention, but will be set when initiating the Configuration. """, - "displayMode": - """ 1 : Current TH2D display style (auto-scaling Z-axis, granular colors, using same colors for > 4*threshold); 0: Anatoly's development TH2D display style (similar, but with printed mirror number also, and fixed scale)""", - "xmlMDCS": - """ Location of MDCS conditions XML file, for override if needed. Not used if blank. """ + "MajItStart": """ Start the alignment at this major iteration. Please make sure this is consitent with MinItStart. """, + "MinItStart": """ Start the alignment at this minor iteration. Please make sure this is consitent with MajItStart. """, + "Rich": """ Rich1 or Rich2. """, + "HistoDir": """ Directory where the savesets are being written to. """, + "WorkDir": """ Directory in which all the output will be written. """, + "SaveDir": """ Directory in which all output files of the alignment are saved after it has finished """, + "ItNrFile": """ File which contains only the number of the current iteration written by the iterator, to be read by the analyzers """, + "thisCase": """ Right now this is used only for the naming convention. """, + "tiltNames": """ Combination of tilts for the calculation and usage of the magnification factors. This is needed even when using predefined magnification factors!!! """, + "combAndMirrSubsets": """ File that lists the subset of combinations of primary and secondary mirror segments chosen for alignment monitoring, and all mirror segments under alignment monitoring """, + "startXMLFile": """ ONLY IF testing = True, this is the XML file with the mirror tilts that we start with for the alignment; if it is blank or testing is not True, it uses the latest v-numbered xml (which is what should be currently in the DB) """, + "compareXMLFile": """ XML file with mirror tilts, for comparison of mirror tilts before and after alignment; if it is blank, it uses the latest v-numbered xml (which is what should be currently in the DB) """, + "coeffCalibTilt": """ Mirror-tilts applied for the calculation of the magnification coefficients. """, + "minAverageBinPop": """ Demanded minimal entries per bin in x-y-bin; atm 6: for 20 phi-bins, 4.8: for 25 phi-bins. """, + "phiBinFactor": """ Factor by which the number of phi-bins is reduced. The histograms should now come with 60 phi bins, factor 3 reduced this to 20 bin in the fit.""", + "minFracPhiBinsPopulated": """ Fraction of the phi-bins that should be sufficiently populated, based on the current minAverageBinPop setting. Ideally this is 0.8, but sometimes we lower it if the mirror alignment still seems OK with a lower fraction, though we really should adjust the HLT line instead.""", + "deltaThetaWindow": """ dTheta-range in the histograms; 4.0 for Rich1 and 3.0 for Rich2. """, + "combinFitMethod": """ Method for fitting the 2D histograms; 1: first fit the slices of dTheta with a Gaussian and then fit to phi using only the mean of the Gaussian, 3: fit a 2D function, 5: Same as 3 but with unifyWidths """, + "magnFactorsMode": """ Method for calculating the magnification coefficents; 0: magnefication coeff. pre-determined, 1: individual for all mirror pairs, determined in the 0-th iteration and not updated any further, 2: individual for all mirrorpairs, determined on-the-fly on the data. """, + "magnifDir": """ directory that contains the pre-determined magnification coeff., files in this folder have to be named Rich[1,2]_MirrMagn _[tiltName]_predefined.txt """, + "solutionMethod": """ Solution method for calculating the mirror tilts after the individual fits; 0: Minuit, 1: Algebraic """, + "regularizationMode": """ regularization mode (0/10/1/11): regularization terms magnified (weighted) with: 0(def)-> major & minor per-mirror MFs; 10-> only averaged per-kind major MFs; 1 (and 11, respectively)-> all weights = 1. """, + "stopToleranceMode": """ tolerance mode: default 0: calculate the stopTolerances from nominal sigma, average magn factors and stopSigmaFraction, 1 use stopTolerances given below""", + "nominalResolutionSigma": """ RICH-dependent nominal Cherenkov angle resolution (in mrad)""", + "stopSigmaFraction": """ tolerance for total tilt of mirror pair in terms of the fraction of the nominal Cherenkov angle resolution """, + "maxIterations": """ The number of iterations the mirror alignment will run, before giving up """, + "requiredEvents": """ If this many events are not procesed by the farm, on average, we do run the alignment but we will never update it. """, + "autoUpdate": """ If True, then the fully automated updating system is activated. If False, our DB update service is still active but returns the starting alignment version. """, + "autoUpdateNoV": """ Only looked at if autoUpdate is True. Then, if autoUpdateNoV is False, nothing changes. If autoUpdateNoV is True, then rather than sending the existing alignment version if autoUpdate is disabled *and* there is a _maybe_ alignment, we will send no version through the DB update service. HLT2 will have to wait for us to assign one. """, + "testing": """ If True, then we are running a test alignment; we also disable our DB update service completely. """, + "trendDateRange": """ Set the date range for the automatic trend plots. Format is YYYYMMDD. Additionally, a minDate(maxDate) of None defaults to the first(last) day of the current year (see AlignMonitor.py).""", + "stopTolerancePriY": """ RICH-dependent tolerance for primary mirrors rotation around Y correction in mrad to stop the alignment """, + "stopTolerancePriZ": """ RICH-dependent tolerance for primary mirrors rotation around Z correction in mrad to stop the alignment """, + "stopToleranceSecY": """ RICH-dependent tolerance for secondary mirrors rotation around Y correction in mrad to stop the alignment """, + "stopToleranceSecZ": """ RICH-dependent tolerance for secondary mirrors rotation around Z correction in mrad to stop the alignment """, + "warningFactor": """ alerts the alignment if any of the mirrors have shifted more than warningFactor times a particular mirror rotation stopTolerance """, + "EvtMax": """ maximal number of events processed by brunel PER NODE (hlt farm has ~1500 nodes), -1 = infinite """, + "dataVariant": """ Helps us decide which Brunel options to use (see RichAnalyzer.py); also used for the naming convention. """, + "fixSinusoidShift": """ 1 : fix at sinusoidShift; 0 : it is not fixed """, + "nameStr": """ Right now this is used only for the naming convention, but will be set when initiating the Configuration. """, + "displayMode": """ 1 : Current TH2D display style (auto-scaling Z-axis, granular colors, using same colors for > 4*threshold); 0: Anatoly's development TH2D display style (similar, but with printed mirror number also, and fixed scale)""", + "xmlMDCS": """ Location of MDCS conditions XML file, for override if needed. Not used if blank. """, } ### Dont mess with this filename!!! def setHistoDir(self): import time + year = time.strftime("%Y") - histodir = "/hist/Savesets/" + str(year) + "/LHCbA/AligWrk_Rich" + str( - self.getProp("Rich")) + "/" + histodir = ( + "/hist/Savesets/" + + str(year) + + "/LHCbA/AligWrk_Rich" + + str(self.getProp("Rich")) + + "/" + ) self.setProp("HistoDir", histodir) def setNameStr(self): - thisTuning = "Mp" + str(self.getProp('minAverageBinPop')) - thisTuning += "Wi" + str(self.getProp('deltaThetaWindow')) - thisTuning += "Fm" + str(self.getProp('combinFitMethod')) - thisTuning += "Mm" + str(self.getProp('magnFactorsMode')) - thisTuning += "Sm" + str(self.getProp('solutionMethod')) - thisNameStr = thisTuning + "_" + str( - self.getProp('thisCase')) + "_" + str(self.getProp('dataVariant')) + thisTuning = "Mp" + str(self.getProp("minAverageBinPop")) + thisTuning += "Wi" + str(self.getProp("deltaThetaWindow")) + thisTuning += "Fm" + str(self.getProp("combinFitMethod")) + thisTuning += "Mm" + str(self.getProp("magnFactorsMode")) + thisTuning += "Sm" + str(self.getProp("solutionMethod")) + thisNameStr = ( + thisTuning + + "_" + + str(self.getProp("thisCase")) + + "_" + + str(self.getProp("dataVariant")) + ) self.setProp("nameStr", thisNameStr) def checkStartIt(self): @@ -503,19 +356,24 @@ class Rich2MirrAlignOnConf(LHCbConfigurableUser): if self.getProp("MinItStart") < 9: if not self.getProp("MajItStart") == 0: self.setProp("MajItStart", 0) - print "Warning: Major Iteration did not match minor itertion. Major iteration was set to match minor iteration." + print( + "Warning: Major Iteration did not match minor itertion. Major iteration was set to match minor iteration." + ) else: - majstartit = (self.getProp("MinItStart") - ( - self.getProp("MinItStart") % self.getProp("MajItStart")) - ) / self.getProp("MajItStart") + majstartit = ( + self.getProp("MinItStart") + - (self.getProp("MinItStart") % self.getProp("MajItStart")) + ) / self.getProp("MajItStart") if not self.getProp("MajItStart") == majstartit: - self.setProp('MajItStart', majstartit) - print "Warning: Major Iteration did not match minor itertion. Major iteration was set to match minor iteration." - if (self.getProp("magnFactorsMode") == 0 - and self.getProp("magnifDir") == ""): - self.setProp("magnifDir", - '/group/rich/AlignmentFiles/MagnifFactors/Rich2/') - print "Warning: Mode for calculating magnification coefficients was chosen to be 0 but no directory with pre-determined coefficients provided. Directory set to default." + self.setProp("MajItStart", majstartit) + print( + "Warning: Major Iteration did not match minor itertion. Major iteration was set to match minor iteration." + ) + if self.getProp("magnFactorsMode") == 0 and self.getProp("magnifDir") == "": + self.setProp("magnifDir", "/group/rich/AlignmentFiles/MagnifFactors/Rich2/") + print( + "Warning: Mode for calculating magnification coefficients was chosen to be 0 but no directory with pre-determined coefficients provided. Directory set to default." + ) if self.getProp("magnFactorsMode") == 0: self.setProp("MinItStart", self.getProp("MajItStart") * 9) @@ -524,13 +382,13 @@ class Rich2MirrAlignOnConf(LHCbConfigurableUser): self.setNameStr() self.checkStartIt() # Next 3 lines add the trailing slash in key directory names - self.setProp('WorkDir', os.path.join(self.getProp('WorkDir'), '')) - self.setProp('SaveDir', os.path.join(self.getProp('SaveDir'), '')) - self.setProp('magnifDir', os.path.join(self.getProp('magnifDir'), '')) - print "INFO: Rich2MirrAlignOnConf applied" + self.setProp("WorkDir", os.path.join(self.getProp("WorkDir"), "")) + self.setProp("SaveDir", os.path.join(self.getProp("SaveDir"), "")) + self.setProp("magnifDir", os.path.join(self.getProp("magnifDir"), "")) + print("INFO: Rich2MirrAlignOnConf applied") -#=============================================================================== +# =============================================================================== # regularizationMode has changed from 1 (used in 2016) to 0 (used in 2017). # Looking back at the functional we minimize: # https://indico.cern.ch/event/477524/contributions/2174895/attachments/1276535/1894128/richmirralign_update_2016-05-20_rich_sw.pdf @@ -546,4 +404,4 @@ class Rich2MirrAlignOnConf(LHCbConfigurableUser): # In light of this, the RICH1 tolerances for 2017 should be set to: [0.027, 0.030, 0.455, 0.370] mrad # What we decided for RICH2 from 2016 study: [0.065, 0.055, 0.045, 0.035] mrad # In light of this, the RICH2 tolerances for 2017 should be set to: [0.032, 0.030, 0.043, 0.057] mrad -#=============================================================================== +# =============================================================================== diff --git a/Rich/RichMirrorAlignmentOnline/python/RichMirrorAlignmentOnline/SavedConfigurations/2018_Configurations/Configuration_2018_runOn2017.py b/Rich/RichMirrorAlignmentOnline/python/RichMirrorAlignmentOnline/SavedConfigurations/2018_Configurations/Configuration_2018_runOn2017.py index 628be5fc919a8bbb58bbb3d5d6758aace8196aac..40ed6cf96cfee3882a7df08d0a2ebc61f8324b40 100644 --- a/Rich/RichMirrorAlignmentOnline/python/RichMirrorAlignmentOnline/SavedConfigurations/2018_Configurations/Configuration_2018_runOn2017.py +++ b/Rich/RichMirrorAlignmentOnline/python/RichMirrorAlignmentOnline/SavedConfigurations/2018_Configurations/Configuration_2018_runOn2017.py @@ -30,221 +30,147 @@ __authors__ = "Claire Prouve <Claire.Prouve@cern.ch>, Paras Naik <Paras.Naik@cer ### Some details on regularizationMode are listed at the end of this file import os -from Gaudi.Configuration import * + import GaudiKernel.ProcessJobOptions -from Configurables import (LHCbConfigurableUser) +from Configurables import LHCbConfigurableUser +from Gaudi.Configuration import * class Rich1MirrAlignOnConf(LHCbConfigurableUser): __used_configurables__ = [] __slots__ = { #### Do not change these!!! Just DON'T! - "Rich": - 1, - "HistoDir": - "" + "Rich": 1, + "HistoDir": "", #### Only change these if you want to pick up from where you left off in iterations, experts only - , - "MajItStart": - 0, - "MinItStart": - 0 + "MajItStart": 0, + "MinItStart": 0, ### Better not change these, only for very very VERY good reasons - , - "WorkDir": - "/group/online/AligWork/Rich1/", - "SaveDir": - "/group/online/AligWork/MirrorAlignments/", - "ItNrFile": - "/group/online/dataflow/options/LHCbA/Rich1_Alignment_Reference_File.txt", - "thisCase": - "online", + "WorkDir": "/group/online/AligWork/Rich1/", + "SaveDir": "/group/online/AligWork/MirrorAlignments/", + "ItNrFile": "/group/online/dataflow/options/LHCbA/Rich1_Alignment_Reference_File.txt", + "thisCase": "online", "tiltNames": [ - "", "pri_negYzerZ", "pri_posYzerZ", "pri_zerYnegZ", "pri_zerYposZ", - "sec_negYzerZ", "sec_posYzerZ", "sec_zerYnegZ", "sec_zerYposZ" - ] + "", + "pri_negYzerZ", + "pri_posYzerZ", + "pri_zerYnegZ", + "pri_zerYposZ", + "sec_negYzerZ", + "sec_posYzerZ", + "sec_zerYnegZ", + "sec_zerYposZ", + ], ### May be changed if you know what you are doing, explanations below - , - "combAndMirrSubsets": - "/group/rich/sw/cmtuser/AlignmentRelease/Rich/RichMirrorAlignmentOnline/files/Rich1CombAndMirrSubsets.txt", - "startXMLFile": - "" # "/group/rich/AlignmentFiles/databaseAlignments/Rich1/Rich1_Zeroed.xml" # if testing is not True OR this is blank, it automatically uses the DB XML file - , - "compareXMLFile": - "" # if this is blank, it automatically uses the DB XML file - , - "coeffCalibTilt": - 0.7, - "minAverageBinPop": - 6, - "phiBinFactor": - 3, - "minFracPhiBinsPopulated": - 0.8, - "deltaThetaWindow": - 8.0, - "combinFitMethod": - 5, - "magnFactorsMode": - 0, - "magnifDir": - "/group/rich/AlignmentFiles/MagnifFactors/Rich1/20170612_004007/", - "solutionMethod": - 0, - "regularizationMode": - 0, - "stopToleranceMode": - 1, - "nominalResolutionSigma": - 1.66 # by eye, looking at mirror resolutions between fills 6130 and 6280 (e.g. post- best MDCS corrections for 2017) + "combAndMirrSubsets": "/group/rich/sw/cmtuser/AlignmentRelease/Rich/RichMirrorAlignmentOnline/files/Rich1CombAndMirrSubsets.txt", + "startXMLFile": "", # "/group/rich/AlignmentFiles/databaseAlignments/Rich1/Rich1_Zeroed.xml" # if testing is not True OR this is blank, it automatically uses the DB XML file + "compareXMLFile": "", # if this is blank, it automatically uses the DB XML file + "coeffCalibTilt": 0.7, + "minAverageBinPop": 6, + "phiBinFactor": 3, + "minFracPhiBinsPopulated": 0.8, + "deltaThetaWindow": 8.0, + "combinFitMethod": 5, + "magnFactorsMode": 0, + "magnifDir": "/group/rich/AlignmentFiles/MagnifFactors/Rich1/20170612_004007/", + "solutionMethod": 0, + "regularizationMode": 0, + "stopToleranceMode": 1, + "nominalResolutionSigma": 1.66, # by eye, looking at mirror resolutions between fills 6130 and 6280 (e.g. post- best MDCS corrections for 2017) # ,"nominalResolutionSigma" : 1.639 # from https://lblogbook.cern.ch/RICH/13677 - , - "stopSigmaFraction": - 0, - "maxIterations": - 8, - "requiredEvents": - 1180000 # ~70% of 1684783 - , - "autoUpdate": - True, - "autoUpdateNoV": - False, - "testing": - True, - "trendDateRange": { - 'minDate': 20170602, - 'maxDate': 20171129 - } + "stopSigmaFraction": 0, + "maxIterations": 8, + "requiredEvents": 1180000, # ~70% of 1684783 + "autoUpdate": True, + "autoUpdateNoV": False, + "testing": True, + "trendDateRange": {"minDate": 20170602, "maxDate": 20171129}, # 2017 tolerances: [0.027, 0.030, 0.455, 0.370], adjusted to [0.03, 0.03, 0.46, 0.37] - , - "stopTolerancePriY": - 0.03, - "stopTolerancePriZ": - 0.03, - "stopToleranceSecY": - 0.46, - "stopToleranceSecZ": - 0.37, - "warningFactor": - 3, - "EvtMax": - -1, - "dataVariant": - "Collision17", - "fixSinusoidShift": - 1, - "nameStr": - "", - "displayMode": - 1, - "xmlMDCS": - "" # "/group/rich/AlignmentFiles/MDCS/Conditions/Rich1/Environment/HPD.xml" + "stopTolerancePriY": 0.03, + "stopTolerancePriZ": 0.03, + "stopToleranceSecY": 0.46, + "stopToleranceSecZ": 0.37, + "warningFactor": 3, + "EvtMax": -1, + "dataVariant": "Collision17", + "fixSinusoidShift": 1, + "nameStr": "", + "displayMode": 1, + "xmlMDCS": "", # "/group/rich/AlignmentFiles/MDCS/Conditions/Rich1/Environment/HPD.xml" } _propertyDocDct = { - "MajItStart": - """ Start the alignment at this major iteration. Please make sure this is consitent with MinItStart. """, - "MinItStart": - """ Start the alignment at this minor iteration. Please make sure this is consitent with MajItStart. """, - "Rich": - """ Rich1 or Rich2. """, - "HistoDir": - """ Directory where the savesets are being written to. """, - "WorkDir": - """ Directory in which all the output will be written. """, - "SaveDir": - """ Directory in which all output files of the alignment are saved after it has finished """, - "ItNrFile": - """ File which contains only the number of the current iteration written by the iterator, to be read by the analyzers """, - "thisCase": - """ Right now this is used only for the naming convention. """, - "tiltNames": - """ Combination of tilts for the calculation and usage of the magnification factors. This is needed even when using predefined magnification factors!!! """, - "combAndMirrSubsets": - """ File that lists the subset of combinations of primary and secondary mirror segments chosen for alignment monitoring, and all mirror segments under alignment monitoring """, - "startXMLFile": - """ ONLY IF testing = True, this is the XML file with the mirror tilts that we start with for the alignment; if it is blank or testing is not True, it uses the latest v-numbered xml (which is what should be currently in the DB) """, - "compareXMLFile": - """ XML file with mirror tilts, for comparison of mirror tilts before and after alignment; if it is blank, it uses the latest v-numbered xml (which is what should be currently in the DB) """, - "coeffCalibTilt": - """ Mirror-tilts applied for the calculation of the magnification coefficients. """, - "minAverageBinPop": - """ Demanded minimal entries per bin in x-y-bin; atm 6: for 20 phi-bins, 4.8: for 25 phi-bins. """, - "phiBinFactor": - """ Factor by which the number of phi-bins is reduced. The histograms should now come with 60 phi bins, factor 3 reduced this to 20 bin in the fit.""", - "minFracPhiBinsPopulated": - """ Fraction of the phi-bins that should be sufficiently populated, based on the current minAverageBinPop setting. Ideally this is 0.8, but sometimes we lower it if the mirror alignment still seems OK with a lower fraction, though we really should adjust the HLT line instead.""", - "deltaThetaWindow": - """ dTheta-range in the histograms; 4.0 for Rich1 and 3.0 for Rich2. """, - "combinFitMethod": - """ Method for fitting the 2D histograms; 1: first fit the slices of dTheta with a Gaussian and then fit to phi using only the mean of the Gaussian, 3: fit a 2D function, 5: same as 3 but with unifyWidths """, - "magnFactorsMode": - """ Method for calculating the magnification coefficents; 0: magnefication coeff. pre-determined, 1: individual for all mirror pairs, determined in the 0-th iteration and not updated any further, 2: individual for all mirrorpairs, determined on-the-fly on the data. """, - "magnifDir": - """ directory that contains the pre-determined magnification coeff., files in this folder have to be named Rich[1,2]_MirrMagn _[tiltName]_predefined.txt """, - "solutionMethod": - """ Solution method for calculating the mirror tilts after the individual fits; 0: Minuit, 1: Algebraic """, - "regularizationMode": - """ regularization mode (0/10/1/11): regularization terms magnified (weighted) with: 0(def)-> major & minor per-mirror MFs; 10-> only averaged per-kind major MFs; 1 (and 11, respectively)-> all weights = 1. """, - "stopToleranceMode": - """ tolerance mode: default 0: calculate the stopTolerances from nominal sigma, average magn factors and stopSigmaFraction, 1 use stopTolerances given below""", - "nominalResolutionSigma": - """ RICH-dependent nominal Cherenkov angle resolution (in mrad)""", - "stopSigmaFraction": - """ tolerance for total tilt of mirror pair in terms of the fraction of the nominal Cherenkov angle resolution """, - "maxIterations": - """ The number of iterations the mirror alignment will run, before giving up """, - "requiredEvents": - """ If this many events are not procesed by the farm, on average, we do run the alignment but we will never update it. """, - "autoUpdate": - """ If True, then the fully automated updating system is activated. If False, our DB update service is still active but returns the starting alignment version. """, - "autoUpdateNoV": - """ Only looked at if autoUpdate is True. Then, if autoUpdateNoV is False, nothing changes. If autoUpdateNoV is True, then rather than sending the existing alignment version if autoUpdate is disabled *and* there is a _maybe_ alignment, we will send no version through the DB update service. HLT2 will have to wait for us to assign one. """, - "testing": - """ If True, then we are running a test alignment; we also disable our DB update service completely. """, - "trendDateRange": - """ Set the date range for the automatic trend plots. Format is YYYYMMDD. Additionally, a minDate(maxDate) of None defaults to the first(last) day of the current year.""", - "stopTolerancePriY": - """ RICH-dependent tolerance for primary mirrors rotation around Y correction in mrad to stop the alignment """, - "stopTolerancePriZ": - """ RICH-dependent tolerance for primary mirrors rotation around Z correction in mrad to stop the alignment """, - "stopToleranceSecY": - """ RICH-dependent tolerance for secondary mirrors rotation around Y correction in mrad to stop the alignment """, - "stopToleranceSecZ": - """ RICH-dependent tolerance for secondary mirrors rotation around Z correction in mrad to stop the alignment """, - "warningFactor": - """ alerts the alignment if any of the mirrors have shifted more than warningFactor times a particular mirror rotation stopTolerance """, - "EvtMax": - """ maximal number of events processed by brunel PER NODE (hlt farm has ~1500 nodes), -1 = infinite """, - "dataVariant": - """ Helps us decide which Brunel options to use; also used for the naming convention. """, - "fixSinusoidShift": - """ 1 : fix at sinusoidShift; 0 : it is not fixed """, - "nameStr": - """ Right now this is used only for the naming convention, but will be set when initiating the Configuration. """, - "displayMode": - """ 1 : Current TH2D display style (auto-scaling Z-axis, granular colors, using same colors for > 4*threshold); 0: Anatoly's development TH2D display style (similar, but with printed mirror number also, and fixed scale)""", - "xmlMDCS": - """ Location of MDCS conditions XML file, for override if needed. Not used if blank. """ + "MajItStart": """ Start the alignment at this major iteration. Please make sure this is consitent with MinItStart. """, + "MinItStart": """ Start the alignment at this minor iteration. Please make sure this is consitent with MajItStart. """, + "Rich": """ Rich1 or Rich2. """, + "HistoDir": """ Directory where the savesets are being written to. """, + "WorkDir": """ Directory in which all the output will be written. """, + "SaveDir": """ Directory in which all output files of the alignment are saved after it has finished """, + "ItNrFile": """ File which contains only the number of the current iteration written by the iterator, to be read by the analyzers """, + "thisCase": """ Right now this is used only for the naming convention. """, + "tiltNames": """ Combination of tilts for the calculation and usage of the magnification factors. This is needed even when using predefined magnification factors!!! """, + "combAndMirrSubsets": """ File that lists the subset of combinations of primary and secondary mirror segments chosen for alignment monitoring, and all mirror segments under alignment monitoring """, + "startXMLFile": """ ONLY IF testing = True, this is the XML file with the mirror tilts that we start with for the alignment; if it is blank or testing is not True, it uses the latest v-numbered xml (which is what should be currently in the DB) """, + "compareXMLFile": """ XML file with mirror tilts, for comparison of mirror tilts before and after alignment; if it is blank, it uses the latest v-numbered xml (which is what should be currently in the DB) """, + "coeffCalibTilt": """ Mirror-tilts applied for the calculation of the magnification coefficients. """, + "minAverageBinPop": """ Demanded minimal entries per bin in x-y-bin; atm 6: for 20 phi-bins, 4.8: for 25 phi-bins. """, + "phiBinFactor": """ Factor by which the number of phi-bins is reduced. The histograms should now come with 60 phi bins, factor 3 reduced this to 20 bin in the fit.""", + "minFracPhiBinsPopulated": """ Fraction of the phi-bins that should be sufficiently populated, based on the current minAverageBinPop setting. Ideally this is 0.8, but sometimes we lower it if the mirror alignment still seems OK with a lower fraction, though we really should adjust the HLT line instead.""", + "deltaThetaWindow": """ dTheta-range in the histograms; 4.0 for Rich1 and 3.0 for Rich2. """, + "combinFitMethod": """ Method for fitting the 2D histograms; 1: first fit the slices of dTheta with a Gaussian and then fit to phi using only the mean of the Gaussian, 3: fit a 2D function, 5: same as 3 but with unifyWidths """, + "magnFactorsMode": """ Method for calculating the magnification coefficents; 0: magnefication coeff. pre-determined, 1: individual for all mirror pairs, determined in the 0-th iteration and not updated any further, 2: individual for all mirrorpairs, determined on-the-fly on the data. """, + "magnifDir": """ directory that contains the pre-determined magnification coeff., files in this folder have to be named Rich[1,2]_MirrMagn _[tiltName]_predefined.txt """, + "solutionMethod": """ Solution method for calculating the mirror tilts after the individual fits; 0: Minuit, 1: Algebraic """, + "regularizationMode": """ regularization mode (0/10/1/11): regularization terms magnified (weighted) with: 0(def)-> major & minor per-mirror MFs; 10-> only averaged per-kind major MFs; 1 (and 11, respectively)-> all weights = 1. """, + "stopToleranceMode": """ tolerance mode: default 0: calculate the stopTolerances from nominal sigma, average magn factors and stopSigmaFraction, 1 use stopTolerances given below""", + "nominalResolutionSigma": """ RICH-dependent nominal Cherenkov angle resolution (in mrad)""", + "stopSigmaFraction": """ tolerance for total tilt of mirror pair in terms of the fraction of the nominal Cherenkov angle resolution """, + "maxIterations": """ The number of iterations the mirror alignment will run, before giving up """, + "requiredEvents": """ If this many events are not procesed by the farm, on average, we do run the alignment but we will never update it. """, + "autoUpdate": """ If True, then the fully automated updating system is activated. If False, our DB update service is still active but returns the starting alignment version. """, + "autoUpdateNoV": """ Only looked at if autoUpdate is True. Then, if autoUpdateNoV is False, nothing changes. If autoUpdateNoV is True, then rather than sending the existing alignment version if autoUpdate is disabled *and* there is a _maybe_ alignment, we will send no version through the DB update service. HLT2 will have to wait for us to assign one. """, + "testing": """ If True, then we are running a test alignment; we also disable our DB update service completely. """, + "trendDateRange": """ Set the date range for the automatic trend plots. Format is YYYYMMDD. Additionally, a minDate(maxDate) of None defaults to the first(last) day of the current year.""", + "stopTolerancePriY": """ RICH-dependent tolerance for primary mirrors rotation around Y correction in mrad to stop the alignment """, + "stopTolerancePriZ": """ RICH-dependent tolerance for primary mirrors rotation around Z correction in mrad to stop the alignment """, + "stopToleranceSecY": """ RICH-dependent tolerance for secondary mirrors rotation around Y correction in mrad to stop the alignment """, + "stopToleranceSecZ": """ RICH-dependent tolerance for secondary mirrors rotation around Z correction in mrad to stop the alignment """, + "warningFactor": """ alerts the alignment if any of the mirrors have shifted more than warningFactor times a particular mirror rotation stopTolerance """, + "EvtMax": """ maximal number of events processed by brunel PER NODE (hlt farm has ~1500 nodes), -1 = infinite """, + "dataVariant": """ Helps us decide which Brunel options to use; also used for the naming convention. """, + "fixSinusoidShift": """ 1 : fix at sinusoidShift; 0 : it is not fixed """, + "nameStr": """ Right now this is used only for the naming convention, but will be set when initiating the Configuration. """, + "displayMode": """ 1 : Current TH2D display style (auto-scaling Z-axis, granular colors, using same colors for > 4*threshold); 0: Anatoly's development TH2D display style (similar, but with printed mirror number also, and fixed scale)""", + "xmlMDCS": """ Location of MDCS conditions XML file, for override if needed. Not used if blank. """, } def setNameStr(self): - thisTuning = "Mp" + str(self.getProp('minAverageBinPop')) - thisTuning += "Wi" + str(self.getProp('deltaThetaWindow')) - thisTuning += "Fm" + str(self.getProp('combinFitMethod')) - thisTuning += "Mm" + str(self.getProp('magnFactorsMode')) - thisTuning += "Sm" + str(self.getProp('solutionMethod')) - thisNameStr = thisTuning + "_" + str( - self.getProp('thisCase')) + "_" + str(self.getProp('dataVariant')) + thisTuning = "Mp" + str(self.getProp("minAverageBinPop")) + thisTuning += "Wi" + str(self.getProp("deltaThetaWindow")) + thisTuning += "Fm" + str(self.getProp("combinFitMethod")) + thisTuning += "Mm" + str(self.getProp("magnFactorsMode")) + thisTuning += "Sm" + str(self.getProp("solutionMethod")) + thisNameStr = ( + thisTuning + + "_" + + str(self.getProp("thisCase")) + + "_" + + str(self.getProp("dataVariant")) + ) self.setProp("nameStr", thisNameStr) ### Dont mess with this filename!!! def setHistoDir(self): import time + year = time.strftime("%Y") - histodir = "/hist/Savesets/" + str(year) + "/LHCbA/AligWrk_Rich" + str( - self.getProp("Rich")) + "/" + histodir = ( + "/hist/Savesets/" + + str(year) + + "/LHCbA/AligWrk_Rich" + + str(self.getProp("Rich")) + + "/" + ) self.setProp("HistoDir", histodir) def checkStartIt(self): @@ -252,19 +178,24 @@ class Rich1MirrAlignOnConf(LHCbConfigurableUser): if self.getProp("MinItStart") < 9: if not self.getProp("MajItStart") == 0: self.setProp("MajItStart", 0) - print "Warning: Major Iteration did not match minor itertion. Major iteration was set to match minor iteration." + print( + "Warning: Major Iteration did not match minor itertion. Major iteration was set to match minor iteration." + ) else: - majstartit = (self.getProp("MinItStart") - ( - self.getProp("MinItStart") % self.getProp("MajItStart")) - ) / self.getProp("MajItStart") + majstartit = ( + self.getProp("MinItStart") + - (self.getProp("MinItStart") % self.getProp("MajItStart")) + ) / self.getProp("MajItStart") if not self.getProp("MajItStart") == majstartit: - self.setProp('MajItStart', majstartit) - print "Warning: Major Iteration did not match minor itertion. Major iteration was set to match minor iteration." - if (self.getProp("magnFactorsMode") == 0 - and self.getProp("magnifDir") == ""): - self.setProp("magnifDir", - '/group/rich/AlignmentFiles/MagnifFactors/Rich1/') - print "Warning: Mode for calculating magnification coefficients was chosen to be 0 but no directory with pre-determined coefficients provided. Directory set to default." + self.setProp("MajItStart", majstartit) + print( + "Warning: Major Iteration did not match minor itertion. Major iteration was set to match minor iteration." + ) + if self.getProp("magnFactorsMode") == 0 and self.getProp("magnifDir") == "": + self.setProp("magnifDir", "/group/rich/AlignmentFiles/MagnifFactors/Rich1/") + print( + "Warning: Mode for calculating magnification coefficients was chosen to be 0 but no directory with pre-determined coefficients provided. Directory set to default." + ) if self.getProp("magnFactorsMode") == 0: self.setProp("MinItStart", self.getProp("MajItStart") * 9) @@ -273,10 +204,10 @@ class Rich1MirrAlignOnConf(LHCbConfigurableUser): self.setNameStr() self.checkStartIt() # Next 3 lines add the trailing slash in key directory names - self.setProp('WorkDir', os.path.join(self.getProp('WorkDir'), '')) - self.setProp('SaveDir', os.path.join(self.getProp('SaveDir'), '')) - self.setProp('magnifDir', os.path.join(self.getProp('magnifDir'), '')) - print "INFO: Rich1MirrAlignOnConf applied" + self.setProp("WorkDir", os.path.join(self.getProp("WorkDir"), "")) + self.setProp("SaveDir", os.path.join(self.getProp("SaveDir"), "")) + self.setProp("magnifDir", os.path.join(self.getProp("magnifDir"), "")) + print("INFO: Rich1MirrAlignOnConf applied") class Rich2MirrAlignOnConf(LHCbConfigurableUser): @@ -284,212 +215,136 @@ class Rich2MirrAlignOnConf(LHCbConfigurableUser): __slots__ = { #### Do not ever change these!!! Just DONT! - "Rich": - 2, - "HistoDir": - "" + "Rich": 2, + "HistoDir": "", #### Only change these if you want to pick up from where you left off in iterations, experts only - , - "MajItStart": - 0, - "MinItStart": - 0 + "MajItStart": 0, + "MinItStart": 0, ### Better not change these, only for very very VERY good reasons - , - "WorkDir": - "/group/online/AligWork/Rich2/", - "SaveDir": - "/group/online/AligWork/MirrorAlignments/", - "ItNrFile": - "/group/online/dataflow/options/LHCbA/Rich2_Alignment_Reference_File.txt", - "thisCase": - "online", + "WorkDir": "/group/online/AligWork/Rich2/", + "SaveDir": "/group/online/AligWork/MirrorAlignments/", + "ItNrFile": "/group/online/dataflow/options/LHCbA/Rich2_Alignment_Reference_File.txt", + "thisCase": "online", "tiltNames": [ - "", "pri_negYzerZ", "pri_posYzerZ", "pri_zerYnegZ", "pri_zerYposZ", - "sec_negYzerZ", "sec_posYzerZ", "sec_zerYnegZ", "sec_zerYposZ" - ] + "", + "pri_negYzerZ", + "pri_posYzerZ", + "pri_zerYnegZ", + "pri_zerYposZ", + "sec_negYzerZ", + "sec_posYzerZ", + "sec_zerYnegZ", + "sec_zerYposZ", + ], ### May be changed if you know what you are doing - , - "combAndMirrSubsets": - "/group/rich/sw/cmtuser/AlignmentRelease/Rich/RichMirrorAlignmentOnline/files/Rich2CombAndMirrSubsets.txt", - "startXMLFile": - "" # "/group/rich/AlignmentFiles/databaseAlignments/Rich2/Rich2_Zeroed.xml" # if testing is not True OR this is blank, it automatically uses the DB XML file - , - "compareXMLFile": - "" # if this is blank, it automatically uses the DB XML file - , - "coeffCalibTilt": - 0.3, - "minAverageBinPop": - 6, - "phiBinFactor": - 3, - "minFracPhiBinsPopulated": - 0.7 # adjusted from 0.8 due to inefficiencies in our existing choice of HLT line prescales - , - "deltaThetaWindow": - 4.0, - "combinFitMethod": - 5, - "magnFactorsMode": - 0, - "magnifDir": - "/group/rich/AlignmentFiles/MagnifFactors/Rich2/20170613_083436/", - "solutionMethod": - 0, - "regularizationMode": - 0, - "stopToleranceMode": - 1, - "nominalResolutionSigma": - 0.656 # from https://lblogbook.cern.ch/RICH/13678 (and still seems reasonable throughout 2017) - , - "stopSigmaFraction": - 0, - "maxIterations": - 8, - "requiredEvents": - 942500 # ~70% of 1346563 - , - "autoUpdate": - True, - "autoUpdateNoV": - False, - "testing": - True, - "trendDateRange": { - 'minDate': 20170605, - 'maxDate': 20171129 - } + "combAndMirrSubsets": "/group/rich/sw/cmtuser/AlignmentRelease/Rich/RichMirrorAlignmentOnline/files/Rich2CombAndMirrSubsets.txt", + "startXMLFile": "", # "/group/rich/AlignmentFiles/databaseAlignments/Rich2/Rich2_Zeroed.xml" # if testing is not True OR this is blank, it automatically uses the DB XML file + "compareXMLFile": "", # if this is blank, it automatically uses the DB XML file + "coeffCalibTilt": 0.3, + "minAverageBinPop": 6, + "phiBinFactor": 3, + "minFracPhiBinsPopulated": 0.7, # adjusted from 0.8 due to inefficiencies in our existing choice of HLT line prescales + "deltaThetaWindow": 4.0, + "combinFitMethod": 5, + "magnFactorsMode": 0, + "magnifDir": "/group/rich/AlignmentFiles/MagnifFactors/Rich2/20170613_083436/", + "solutionMethod": 0, + "regularizationMode": 0, + "stopToleranceMode": 1, + "nominalResolutionSigma": 0.656, # from https://lblogbook.cern.ch/RICH/13678 (and still seems reasonable throughout 2017) + "stopSigmaFraction": 0, + "maxIterations": 8, + "requiredEvents": 942500, # ~70% of 1346563 + "autoUpdate": True, + "autoUpdateNoV": False, + "testing": True, + "trendDateRange": {"minDate": 20170605, "maxDate": 20171129}, # 2017 tolerances: [0.032, 0.030, 0.043, 0.057], adjusted to [0.03, 0.03, 0.05, 0.06] - , - "stopTolerancePriY": - 0.03, - "stopTolerancePriZ": - 0.03, - "stopToleranceSecY": - 0.05, - "stopToleranceSecZ": - 0.06, - "warningFactor": - 3, - "EvtMax": - -1, - "dataVariant": - "Collision17", - "fixSinusoidShift": - 1, - "nameStr": - "", - "displayMode": - 1, - "xmlMDCS": - "" # "/group/rich/AlignmentFiles/MDCS/Conditions/Rich1/Environment/HPD.xml" # 'Rich1' is not a typo! + "stopTolerancePriY": 0.03, + "stopTolerancePriZ": 0.03, + "stopToleranceSecY": 0.05, + "stopToleranceSecZ": 0.06, + "warningFactor": 3, + "EvtMax": -1, + "dataVariant": "Collision17", + "fixSinusoidShift": 1, + "nameStr": "", + "displayMode": 1, + "xmlMDCS": "", # "/group/rich/AlignmentFiles/MDCS/Conditions/Rich1/Environment/HPD.xml" # 'Rich1' is not a typo! } _propertyDocDct = { - "MajItStart": - """ Start the alignment at this major iteration. Please make sure this is consitent with MinItStart. """, - "MinItStart": - """ Start the alignment at this minor iteration. Please make sure this is consitent with MajItStart. """, - "Rich": - """ Rich1 or Rich2. """, - "HistoDir": - """ Directory where the savesets are being written to. """, - "WorkDir": - """ Directory in which all the output will be written. """, - "SaveDir": - """ Directory in which all output files of the alignment are saved after it has finished """, - "ItNrFile": - """ File which contains only the number of the current iteration written by the iterator, to be read by the analyzers """, - "thisCase": - """ Right now this is used only for the naming convention. """, - "tiltNames": - """ Combination of tilts for the calculation and usage of the magnification factors. This is needed even when using predefined magnification factors!!! """, - "combAndMirrSubsets": - """ File that lists the subset of combinations of primary and secondary mirror segments chosen for alignment monitoring, and all mirror segments under alignment monitoring """, - "startXMLFile": - """ ONLY IF testing = True, this is the XML file with the mirror tilts that we start with for the alignment; if it is blank or testing is not True, it uses the latest v-numbered xml (which is what should be currently in the DB) """, - "compareXMLFile": - """ XML file with mirror tilts, for comparison of mirror tilts before and after alignment; if it is blank, it uses the latest v-numbered xml (which is what should be currently in the DB) """, - "coeffCalibTilt": - """ Mirror-tilts applied for the calculation of the magnification coefficients. """, - "minAverageBinPop": - """ Demanded minimal entries per bin in x-y-bin; atm 6: for 20 phi-bins, 4.8: for 25 phi-bins. """, - "phiBinFactor": - """ Factor by which the number of phi-bins is reduced. The histograms should now come with 60 phi bins, factor 3 reduced this to 20 bin in the fit.""", - "minFracPhiBinsPopulated": - """ Fraction of the phi-bins that should be sufficiently populated, based on the current minAverageBinPop setting. Ideally this is 0.8, but sometimes we lower it if the mirror alignment still seems OK with a lower fraction, though we really should adjust the HLT line instead.""", - "deltaThetaWindow": - """ dTheta-range in the histograms; 4.0 for Rich1 and 3.0 for Rich2. """, - "combinFitMethod": - """ Method for fitting the 2D histograms; 1: first fit the slices of dTheta with a Gaussian and then fit to phi using only the mean of the Gaussian, 3: fit a 2D function, 5: Same as 3 but with unifyWidths """, - "magnFactorsMode": - """ Method for calculating the magnification coefficents; 0: magnefication coeff. pre-determined, 1: individual for all mirror pairs, determined in the 0-th iteration and not updated any further, 2: individual for all mirrorpairs, determined on-the-fly on the data. """, - "magnifDir": - """ directory that contains the pre-determined magnification coeff., files in this folder have to be named Rich[1,2]_MirrMagn _[tiltName]_predefined.txt """, - "solutionMethod": - """ Solution method for calculating the mirror tilts after the individual fits; 0: Minuit, 1: Algebraic """, - "regularizationMode": - """ regularization mode (0/10/1/11): regularization terms magnified (weighted) with: 0(def)-> major & minor per-mirror MFs; 10-> only averaged per-kind major MFs; 1 (and 11, respectively)-> all weights = 1. """, - "stopToleranceMode": - """ tolerance mode: default 0: calculate the stopTolerances from nominal sigma, average magn factors and stopSigmaFraction, 1 use stopTolerances given below""", - "nominalResolutionSigma": - """ RICH-dependent nominal Cherenkov angle resolution (in mrad)""", - "stopSigmaFraction": - """ tolerance for total tilt of mirror pair in terms of the fraction of the nominal Cherenkov angle resolution """, - "maxIterations": - """ The number of iterations the mirror alignment will run, before giving up """, - "requiredEvents": - """ If this many events are not procesed by the farm, on average, we do run the alignment but we will never update it. """, - "autoUpdate": - """ If True, then the fully automated updating system is activated. If False, our DB update service is still active but returns the starting alignment version. """, - "autoUpdateNoV": - """ Only looked at if autoUpdate is True. Then, if autoUpdateNoV is False, nothing changes. If autoUpdateNoV is True, then rather than sending the existing alignment version if autoUpdate is disabled *and* there is a _maybe_ alignment, we will send no version through the DB update service. HLT2 will have to wait for us to assign one. """, - "testing": - """ If True, then we are running a test alignment; we also disable our DB update service completely. """, - "trendDateRange": - """ Set the date range for the automatic trend plots. Format is YYYYMMDD. Additionally, a minDate(maxDate) of None defaults to the first(last) day of the current year.""", - "stopTolerancePriY": - """ RICH-dependent tolerance for primary mirrors rotation around Y correction in mrad to stop the alignment """, - "stopTolerancePriZ": - """ RICH-dependent tolerance for primary mirrors rotation around Z correction in mrad to stop the alignment """, - "stopToleranceSecY": - """ RICH-dependent tolerance for secondary mirrors rotation around Y correction in mrad to stop the alignment """, - "stopToleranceSecZ": - """ RICH-dependent tolerance for secondary mirrors rotation around Z correction in mrad to stop the alignment """, - "warningFactor": - """ alerts the alignment if any of the mirrors have shifted more than warningFactor times a particular mirror rotation stopTolerance """, - "EvtMax": - """ maximal number of events processed by brunel PER NODE (hlt farm has ~1500 nodes), -1 = infinite """, - "dataVariant": - """ Helps us decide which Brunel options to use; also used for the naming convention. """, - "fixSinusoidShift": - """ 1 : fix at sinusoidShift; 0 : it is not fixed """, - "nameStr": - """ Right now this is used only for the naming convention, but will be set when initiating the Configuration. """, - "displayMode": - """ 1 : Current TH2D display style (auto-scaling Z-axis, granular colors, using same colors for > 4*threshold); 0: Anatoly's development TH2D display style (similar, but with printed mirror number also, and fixed scale)""", - "xmlMDCS": - """ Location of MDCS conditions XML file, for override if needed. Not used if blank. """ + "MajItStart": """ Start the alignment at this major iteration. Please make sure this is consitent with MinItStart. """, + "MinItStart": """ Start the alignment at this minor iteration. Please make sure this is consitent with MajItStart. """, + "Rich": """ Rich1 or Rich2. """, + "HistoDir": """ Directory where the savesets are being written to. """, + "WorkDir": """ Directory in which all the output will be written. """, + "SaveDir": """ Directory in which all output files of the alignment are saved after it has finished """, + "ItNrFile": """ File which contains only the number of the current iteration written by the iterator, to be read by the analyzers """, + "thisCase": """ Right now this is used only for the naming convention. """, + "tiltNames": """ Combination of tilts for the calculation and usage of the magnification factors. This is needed even when using predefined magnification factors!!! """, + "combAndMirrSubsets": """ File that lists the subset of combinations of primary and secondary mirror segments chosen for alignment monitoring, and all mirror segments under alignment monitoring """, + "startXMLFile": """ ONLY IF testing = True, this is the XML file with the mirror tilts that we start with for the alignment; if it is blank or testing is not True, it uses the latest v-numbered xml (which is what should be currently in the DB) """, + "compareXMLFile": """ XML file with mirror tilts, for comparison of mirror tilts before and after alignment; if it is blank, it uses the latest v-numbered xml (which is what should be currently in the DB) """, + "coeffCalibTilt": """ Mirror-tilts applied for the calculation of the magnification coefficients. """, + "minAverageBinPop": """ Demanded minimal entries per bin in x-y-bin; atm 6: for 20 phi-bins, 4.8: for 25 phi-bins. """, + "phiBinFactor": """ Factor by which the number of phi-bins is reduced. The histograms should now come with 60 phi bins, factor 3 reduced this to 20 bin in the fit.""", + "minFracPhiBinsPopulated": """ Fraction of the phi-bins that should be sufficiently populated, based on the current minAverageBinPop setting. Ideally this is 0.8, but sometimes we lower it if the mirror alignment still seems OK with a lower fraction, though we really should adjust the HLT line instead.""", + "deltaThetaWindow": """ dTheta-range in the histograms; 4.0 for Rich1 and 3.0 for Rich2. """, + "combinFitMethod": """ Method for fitting the 2D histograms; 1: first fit the slices of dTheta with a Gaussian and then fit to phi using only the mean of the Gaussian, 3: fit a 2D function, 5: Same as 3 but with unifyWidths """, + "magnFactorsMode": """ Method for calculating the magnification coefficents; 0: magnefication coeff. pre-determined, 1: individual for all mirror pairs, determined in the 0-th iteration and not updated any further, 2: individual for all mirrorpairs, determined on-the-fly on the data. """, + "magnifDir": """ directory that contains the pre-determined magnification coeff., files in this folder have to be named Rich[1,2]_MirrMagn _[tiltName]_predefined.txt """, + "solutionMethod": """ Solution method for calculating the mirror tilts after the individual fits; 0: Minuit, 1: Algebraic """, + "regularizationMode": """ regularization mode (0/10/1/11): regularization terms magnified (weighted) with: 0(def)-> major & minor per-mirror MFs; 10-> only averaged per-kind major MFs; 1 (and 11, respectively)-> all weights = 1. """, + "stopToleranceMode": """ tolerance mode: default 0: calculate the stopTolerances from nominal sigma, average magn factors and stopSigmaFraction, 1 use stopTolerances given below""", + "nominalResolutionSigma": """ RICH-dependent nominal Cherenkov angle resolution (in mrad)""", + "stopSigmaFraction": """ tolerance for total tilt of mirror pair in terms of the fraction of the nominal Cherenkov angle resolution """, + "maxIterations": """ The number of iterations the mirror alignment will run, before giving up """, + "requiredEvents": """ If this many events are not procesed by the farm, on average, we do run the alignment but we will never update it. """, + "autoUpdate": """ If True, then the fully automated updating system is activated. If False, our DB update service is still active but returns the starting alignment version. """, + "autoUpdateNoV": """ Only looked at if autoUpdate is True. Then, if autoUpdateNoV is False, nothing changes. If autoUpdateNoV is True, then rather than sending the existing alignment version if autoUpdate is disabled *and* there is a _maybe_ alignment, we will send no version through the DB update service. HLT2 will have to wait for us to assign one. """, + "testing": """ If True, then we are running a test alignment; we also disable our DB update service completely. """, + "trendDateRange": """ Set the date range for the automatic trend plots. Format is YYYYMMDD. Additionally, a minDate(maxDate) of None defaults to the first(last) day of the current year.""", + "stopTolerancePriY": """ RICH-dependent tolerance for primary mirrors rotation around Y correction in mrad to stop the alignment """, + "stopTolerancePriZ": """ RICH-dependent tolerance for primary mirrors rotation around Z correction in mrad to stop the alignment """, + "stopToleranceSecY": """ RICH-dependent tolerance for secondary mirrors rotation around Y correction in mrad to stop the alignment """, + "stopToleranceSecZ": """ RICH-dependent tolerance for secondary mirrors rotation around Z correction in mrad to stop the alignment """, + "warningFactor": """ alerts the alignment if any of the mirrors have shifted more than warningFactor times a particular mirror rotation stopTolerance """, + "EvtMax": """ maximal number of events processed by brunel PER NODE (hlt farm has ~1500 nodes), -1 = infinite """, + "dataVariant": """ Helps us decide which Brunel options to use; also used for the naming convention. """, + "fixSinusoidShift": """ 1 : fix at sinusoidShift; 0 : it is not fixed """, + "nameStr": """ Right now this is used only for the naming convention, but will be set when initiating the Configuration. """, + "displayMode": """ 1 : Current TH2D display style (auto-scaling Z-axis, granular colors, using same colors for > 4*threshold); 0: Anatoly's development TH2D display style (similar, but with printed mirror number also, and fixed scale)""", + "xmlMDCS": """ Location of MDCS conditions XML file, for override if needed. Not used if blank. """, } ### Dont mess with this filename!!! def setHistoDir(self): import time + year = time.strftime("%Y") - histodir = "/hist/Savesets/" + str(year) + "/LHCbA/AligWrk_Rich" + str( - self.getProp("Rich")) + "/" + histodir = ( + "/hist/Savesets/" + + str(year) + + "/LHCbA/AligWrk_Rich" + + str(self.getProp("Rich")) + + "/" + ) self.setProp("HistoDir", histodir) def setNameStr(self): - thisTuning = "Mp" + str(self.getProp('minAverageBinPop')) - thisTuning += "Wi" + str(self.getProp('deltaThetaWindow')) - thisTuning += "Fm" + str(self.getProp('combinFitMethod')) - thisTuning += "Mm" + str(self.getProp('magnFactorsMode')) - thisTuning += "Sm" + str(self.getProp('solutionMethod')) - thisNameStr = thisTuning + "_" + str( - self.getProp('thisCase')) + "_" + str(self.getProp('dataVariant')) + thisTuning = "Mp" + str(self.getProp("minAverageBinPop")) + thisTuning += "Wi" + str(self.getProp("deltaThetaWindow")) + thisTuning += "Fm" + str(self.getProp("combinFitMethod")) + thisTuning += "Mm" + str(self.getProp("magnFactorsMode")) + thisTuning += "Sm" + str(self.getProp("solutionMethod")) + thisNameStr = ( + thisTuning + + "_" + + str(self.getProp("thisCase")) + + "_" + + str(self.getProp("dataVariant")) + ) self.setProp("nameStr", thisNameStr) def checkStartIt(self): @@ -497,19 +352,24 @@ class Rich2MirrAlignOnConf(LHCbConfigurableUser): if self.getProp("MinItStart") < 9: if not self.getProp("MajItStart") == 0: self.setProp("MajItStart", 0) - print "Warning: Major Iteration did not match minor itertion. Major iteration was set to match minor iteration." + print( + "Warning: Major Iteration did not match minor itertion. Major iteration was set to match minor iteration." + ) else: - majstartit = (self.getProp("MinItStart") - ( - self.getProp("MinItStart") % self.getProp("MajItStart")) - ) / self.getProp("MajItStart") + majstartit = ( + self.getProp("MinItStart") + - (self.getProp("MinItStart") % self.getProp("MajItStart")) + ) / self.getProp("MajItStart") if not self.getProp("MajItStart") == majstartit: - self.setProp('MajItStart', majstartit) - print "Warning: Major Iteration did not match minor itertion. Major iteration was set to match minor iteration." - if (self.getProp("magnFactorsMode") == 0 - and self.getProp("magnifDir") == ""): - self.setProp("magnifDir", - '/group/rich/AlignmentFiles/MagnifFactors/Rich2/') - print "Warning: Mode for calculating magnification coefficients was chosen to be 0 but no directory with pre-determined coefficients provided. Directory set to default." + self.setProp("MajItStart", majstartit) + print( + "Warning: Major Iteration did not match minor itertion. Major iteration was set to match minor iteration." + ) + if self.getProp("magnFactorsMode") == 0 and self.getProp("magnifDir") == "": + self.setProp("magnifDir", "/group/rich/AlignmentFiles/MagnifFactors/Rich2/") + print( + "Warning: Mode for calculating magnification coefficients was chosen to be 0 but no directory with pre-determined coefficients provided. Directory set to default." + ) if self.getProp("magnFactorsMode") == 0: self.setProp("MinItStart", self.getProp("MajItStart") * 9) @@ -518,13 +378,13 @@ class Rich2MirrAlignOnConf(LHCbConfigurableUser): self.setNameStr() self.checkStartIt() # Next 3 lines add the trailing slash in key directory names - self.setProp('WorkDir', os.path.join(self.getProp('WorkDir'), '')) - self.setProp('SaveDir', os.path.join(self.getProp('SaveDir'), '')) - self.setProp('magnifDir', os.path.join(self.getProp('magnifDir'), '')) - print "INFO: Rich2MirrAlignOnConf applied" + self.setProp("WorkDir", os.path.join(self.getProp("WorkDir"), "")) + self.setProp("SaveDir", os.path.join(self.getProp("SaveDir"), "")) + self.setProp("magnifDir", os.path.join(self.getProp("magnifDir"), "")) + print("INFO: Rich2MirrAlignOnConf applied") -#=============================================================================== +# =============================================================================== # regularizationMode has changed from 1 (used in 2016) to 0 (used in 2017). # Looking back at the functional we minimize: # https://indico.cern.ch/event/477524/contributions/2174895/attachments/1276535/1894128/richmirralign_update_2016-05-20_rich_sw.pdf @@ -540,4 +400,4 @@ class Rich2MirrAlignOnConf(LHCbConfigurableUser): # In light of this, the RICH1 tolerances for 2017 should be set to: [0.027, 0.030, 0.455, 0.370] mrad # What we decided for RICH2 from 2016 study: [0.065, 0.055, 0.045, 0.035] mrad # In light of this, the RICH2 tolerances for 2017 should be set to: [0.032, 0.030, 0.043, 0.057] mrad -#=============================================================================== +# =============================================================================== diff --git a/Rich/RichMirrorAlignmentOnline/python/RichMirrorAlignmentOnline/SavedConfigurations/2018_Configurations/Configuration_FinalPit.py b/Rich/RichMirrorAlignmentOnline/python/RichMirrorAlignmentOnline/SavedConfigurations/2018_Configurations/Configuration_FinalPit.py index 7629e37fd00dadc660f0d40a1a15eb9eb9dcba34..d5a9a6ae00abae9fb1c6731038cdd60e7fb7c699 100644 --- a/Rich/RichMirrorAlignmentOnline/python/RichMirrorAlignmentOnline/SavedConfigurations/2018_Configurations/Configuration_FinalPit.py +++ b/Rich/RichMirrorAlignmentOnline/python/RichMirrorAlignmentOnline/SavedConfigurations/2018_Configurations/Configuration_FinalPit.py @@ -32,223 +32,148 @@ __copyright__ = "University of Bristol, May 2018" ### Some details on regularizationMode are listed at the end of this file import os -from Gaudi.Configuration import * + import GaudiKernel.ProcessJobOptions -from Configurables import (LHCbConfigurableUser) +from Configurables import LHCbConfigurableUser +from Gaudi.Configuration import * class Rich1MirrAlignOnConf(LHCbConfigurableUser): __used_configurables__ = [] __slots__ = { #### Do not change these!!! Just DON'T! - "Rich": - 1, - "HistoDir": - "" + "Rich": 1, + "HistoDir": "", #### Only change these if you want to pick up from where you left off in iterations, experts only (we don't use this much anymore) - , - "MajItStart": - 0, - "MinItStart": - 0 + "MajItStart": 0, + "MinItStart": 0, ### Better not change these, only for very very VERY good reasons - , - "WorkDir": - "/group/online/AligWork/Rich1/", - "SaveDir": - "/group/online/AligWork/MirrorAlignments/", - "ItNrFile": - "/group/online/dataflow/options/LHCbA/Rich1_Alignment_Reference_File.txt", - "thisCase": - "online", + "WorkDir": "/group/online/AligWork/Rich1/", + "SaveDir": "/group/online/AligWork/MirrorAlignments/", + "ItNrFile": "/group/online/dataflow/options/LHCbA/Rich1_Alignment_Reference_File.txt", + "thisCase": "online", "tiltNames": [ - "", "pri_negYzerZ", "pri_posYzerZ", "pri_zerYnegZ", "pri_zerYposZ", - "sec_negYzerZ", "sec_posYzerZ", "sec_zerYnegZ", "sec_zerYposZ" - ] + "", + "pri_negYzerZ", + "pri_posYzerZ", + "pri_zerYnegZ", + "pri_zerYposZ", + "sec_negYzerZ", + "sec_posYzerZ", + "sec_zerYnegZ", + "sec_zerYposZ", + ], ### May be changed if you know what you are doing, explanations below - , - "combAndMirrSubsets": - "/group/rich/sw/cmtuser/AlignmentRelease/Rich/RichMirrorAlignmentOnline/files/Rich1CombAndMirrSubsets.txt", - "startXMLFile": - "/group/rich/sw/cmtuser/AlignmentOnlineDev_v12r1/Rich/RichMirrorAlignmentOnline/files/Rich1_Zeroed.xml" # if testing is not True OR this is blank, it automatically uses the DB XML file - , - "compareXMLFile": - "" # if this is blank, it automatically uses the DB XML file - , - "coeffCalibTilt": - 0.7, - "minAverageBinPop": - 6, - "phiBinFactor": - 3, - "minFracPhiBinsPopulated": - 0.8, - "deltaThetaWindow": - 8.0, - "combinFitMethod": - 5, - "magnFactorsMode": - 0, - "magnifDir": - "/group/rich/sw/cmtuser/AlignmentRelease/Rich/RichMirrorAlignmentOnline/files/MagnifFactors/Rich1/20180424_164201/" + "combAndMirrSubsets": "/group/rich/sw/cmtuser/AlignmentRelease/Rich/RichMirrorAlignmentOnline/files/Rich1CombAndMirrSubsets.txt", + "startXMLFile": "/group/rich/sw/cmtuser/AlignmentOnlineDev_v12r1/Rich/RichMirrorAlignmentOnline/files/Rich1_Zeroed.xml", # if testing is not True OR this is blank, it automatically uses the DB XML file + "compareXMLFile": "", # if this is blank, it automatically uses the DB XML file + "coeffCalibTilt": 0.7, + "minAverageBinPop": 6, + "phiBinFactor": 3, + "minFracPhiBinsPopulated": 0.8, + "deltaThetaWindow": 8.0, + "combinFitMethod": 5, + "magnFactorsMode": 0, + "magnifDir": "/group/rich/sw/cmtuser/AlignmentRelease/Rich/RichMirrorAlignmentOnline/files/MagnifFactors/Rich1/20180424_164201/", # ,"magnifDir" : "/group/rich/AlignmentFiles/MagnifFactors/Rich1/20180424_164201/" - , - "solutionMethod": - 0, - "regularizationMode": - 0, - "stopToleranceMode": - 1, - "nominalResolutionSigma": - 1.66 # by eye, looking at mirror resolutions between fills 6130 and 6280 (e.g. post- best MDCS corrections for 2017) + "solutionMethod": 0, + "regularizationMode": 0, + "stopToleranceMode": 1, + "nominalResolutionSigma": 1.66, # by eye, looking at mirror resolutions between fills 6130 and 6280 (e.g. post- best MDCS corrections for 2017) # ,"nominalResolutionSigma" : 1.639 # from https://lblogbook.cern.ch/RICH/13677 - , - "stopSigmaFraction": - 0, - "maxIterations": - 8, - "requiredEvents": - 1180000 # ~70% of 1684783 - , - "autoUpdate": - True, - "autoUpdateNoV": - False, - "testing": - True, - "trendDateRange": { - 'minDate': None, - 'maxDate': None - } + "stopSigmaFraction": 0, + "maxIterations": 8, + "requiredEvents": 1180000, # ~70% of 1684783 + "autoUpdate": True, + "autoUpdateNoV": False, + "testing": True, + "trendDateRange": {"minDate": None, "maxDate": None}, # 2017 tolerances: [0.027, 0.030, 0.455, 0.370], adjusted to [0.03, 0.03, 0.46, 0.37] - , - "stopTolerancePriY": - 0.03, - "stopTolerancePriZ": - 0.03, - "stopToleranceSecY": - 0.46, - "stopToleranceSecZ": - 0.37, - "warningFactor": - 3, - "EvtMax": - -1, - "dataVariant": - "Collision18", - "fixSinusoidShift": - 1, - "nameStr": - "", - "displayMode": - 1, - "xmlMDCS": - "" # "/group/rich/AlignmentFiles/MDCS/Conditions/Rich1/Environment/HPD.xml" + "stopTolerancePriY": 0.03, + "stopTolerancePriZ": 0.03, + "stopToleranceSecY": 0.46, + "stopToleranceSecZ": 0.37, + "warningFactor": 3, + "EvtMax": -1, + "dataVariant": "Collision18", + "fixSinusoidShift": 1, + "nameStr": "", + "displayMode": 1, + "xmlMDCS": "", # "/group/rich/AlignmentFiles/MDCS/Conditions/Rich1/Environment/HPD.xml" } _propertyDocDct = { - "MajItStart": - """ Start the alignment at this major iteration. Please make sure this is consitent with MinItStart. """, - "MinItStart": - """ Start the alignment at this minor iteration. Please make sure this is consitent with MajItStart. """, - "Rich": - """ Rich1 or Rich2. """, - "HistoDir": - """ Directory where the savesets are being written to. """, - "WorkDir": - """ Directory in which all the output will be written. """, - "SaveDir": - """ Directory in which all output files of the alignment are saved after it has finished """, - "ItNrFile": - """ File which contains only the number of the current iteration written by the iterator, to be read by the analyzers """, - "thisCase": - """ Right now this is used only for the naming convention. """, - "tiltNames": - """ Combination of tilts for the calculation and usage of the magnification factors. This is needed even when using predefined magnification factors!!! """, - "combAndMirrSubsets": - """ File that lists the subset of combinations of primary and secondary mirror segments chosen for alignment monitoring, and all mirror segments under alignment monitoring """, - "startXMLFile": - """ ONLY IF testing = True, this is the XML file with the mirror tilts that we start with for the alignment; if it is blank or testing is not True, it uses the latest v-numbered xml (which is what should be currently in the DB) """, - "compareXMLFile": - """ XML file with mirror tilts, for comparison of mirror tilts before and after alignment; if it is blank, it uses the latest v-numbered xml (which is what should be currently in the DB) """, - "coeffCalibTilt": - """ Mirror-tilts applied for the calculation of the magnification coefficients. """, - "minAverageBinPop": - """ Demanded minimal entries per bin in x-y-bin; atm 6: for 20 phi-bins, 4.8: for 25 phi-bins. """, - "phiBinFactor": - """ Factor by which the number of phi-bins is reduced. The histograms should now come with 60 phi bins, factor 3 reduced this to 20 bin in the fit.""", - "minFracPhiBinsPopulated": - """ Fraction of the phi-bins that should be sufficiently populated, based on the current minAverageBinPop setting. Ideally this is 0.8, but sometimes we lower it if the mirror alignment still seems OK with a lower fraction, though we really should adjust the HLT line instead.""", - "deltaThetaWindow": - """ dTheta-range in the histograms; 4.0 for Rich1 and 3.0 for Rich2. """, - "combinFitMethod": - """ Method for fitting the 2D histograms; 1: first fit the slices of dTheta with a Gaussian and then fit to phi using only the mean of the Gaussian, 3: fit a 2D function, 5: same as 3 but with unifyWidths """, - "magnFactorsMode": - """ Method for calculating the magnification coefficents; 0: magnefication coeff. pre-determined, 1: individual for all mirror pairs, determined in the 0-th iteration and not updated any further, 2: individual for all mirrorpairs, determined on-the-fly on the data. """, - "magnifDir": - """ directory that contains the pre-determined magnification coeff., files in this folder have to be named Rich[1,2]_MirrMagn _[tiltName]_predefined.txt """, - "solutionMethod": - """ Solution method for calculating the mirror tilts after the individual fits; 0: Minuit, 1: Algebraic """, - "regularizationMode": - """ regularization mode (0/10/1/11): regularization terms magnified (weighted) with: 0(def)-> major & minor per-mirror MFs; 10-> only averaged per-kind major MFs; 1 (and 11, respectively)-> all weights = 1. """, - "stopToleranceMode": - """ tolerance mode: default 0: calculate the stopTolerances from nominal sigma, average magn factors and stopSigmaFraction, 1 use stopTolerances given below""", - "nominalResolutionSigma": - """ RICH-dependent nominal Cherenkov angle resolution (in mrad)""", - "stopSigmaFraction": - """ tolerance for total tilt of mirror pair in terms of the fraction of the nominal Cherenkov angle resolution """, - "maxIterations": - """ The number of iterations the mirror alignment will run, before giving up """, - "requiredEvents": - """ If this many events are not procesed by the farm, on average, we do run the alignment but we will never update it. """, - "autoUpdate": - """ If True, then the fully automated updating system is activated. If False, our DB update service is still active but returns the starting alignment version. """, - "autoUpdateNoV": - """ Only looked at if autoUpdate is True. Then, if autoUpdateNoV is False, nothing changes. If autoUpdateNoV is True, then rather than sending the existing alignment version if autoUpdate is disabled *and* there is a _maybe_ alignment, we will send no version through the DB update service. HLT2 will have to wait for us to assign one. """, - "testing": - """ If True, then we are running a test alignment; we also disable our DB update service completely. """, - "trendDateRange": - """ Set the date range for the automatic trend plots. Format is YYYYMMDD. Additionally, a minDate(maxDate) of None defaults to the first(last) day of the current year (see AlignMonitor.py).""", - "stopTolerancePriY": - """ RICH-dependent tolerance for primary mirrors rotation around Y correction in mrad to stop the alignment """, - "stopTolerancePriZ": - """ RICH-dependent tolerance for primary mirrors rotation around Z correction in mrad to stop the alignment """, - "stopToleranceSecY": - """ RICH-dependent tolerance for secondary mirrors rotation around Y correction in mrad to stop the alignment """, - "stopToleranceSecZ": - """ RICH-dependent tolerance for secondary mirrors rotation around Z correction in mrad to stop the alignment """, - "warningFactor": - """ alerts the alignment if any of the mirrors have shifted more than warningFactor times a particular mirror rotation stopTolerance """, - "EvtMax": - """ maximal number of events processed by brunel PER NODE (hlt farm has ~1500 nodes), -1 = infinite """, - "dataVariant": - """ Helps us decide which Brunel options to use (see RichAnalyzer.py); also used for the naming convention. """, - "fixSinusoidShift": - """ 1 : fix at sinusoidShift; 0 : it is not fixed """, - "nameStr": - """ Right now this is used only for the naming convention, but will be set when initiating the Configuration. """, - "displayMode": - """ 1 : Current TH2D display style (auto-scaling Z-axis, granular colors, using same colors for > 4*threshold); 0: Anatoly's development TH2D display style (similar, but with printed mirror number also, and fixed scale)""", - "xmlMDCS": - """ Location of MDCS conditions XML file, for override if needed. Not used if blank. """ + "MajItStart": """ Start the alignment at this major iteration. Please make sure this is consitent with MinItStart. """, + "MinItStart": """ Start the alignment at this minor iteration. Please make sure this is consitent with MajItStart. """, + "Rich": """ Rich1 or Rich2. """, + "HistoDir": """ Directory where the savesets are being written to. """, + "WorkDir": """ Directory in which all the output will be written. """, + "SaveDir": """ Directory in which all output files of the alignment are saved after it has finished """, + "ItNrFile": """ File which contains only the number of the current iteration written by the iterator, to be read by the analyzers """, + "thisCase": """ Right now this is used only for the naming convention. """, + "tiltNames": """ Combination of tilts for the calculation and usage of the magnification factors. This is needed even when using predefined magnification factors!!! """, + "combAndMirrSubsets": """ File that lists the subset of combinations of primary and secondary mirror segments chosen for alignment monitoring, and all mirror segments under alignment monitoring """, + "startXMLFile": """ ONLY IF testing = True, this is the XML file with the mirror tilts that we start with for the alignment; if it is blank or testing is not True, it uses the latest v-numbered xml (which is what should be currently in the DB) """, + "compareXMLFile": """ XML file with mirror tilts, for comparison of mirror tilts before and after alignment; if it is blank, it uses the latest v-numbered xml (which is what should be currently in the DB) """, + "coeffCalibTilt": """ Mirror-tilts applied for the calculation of the magnification coefficients. """, + "minAverageBinPop": """ Demanded minimal entries per bin in x-y-bin; atm 6: for 20 phi-bins, 4.8: for 25 phi-bins. """, + "phiBinFactor": """ Factor by which the number of phi-bins is reduced. The histograms should now come with 60 phi bins, factor 3 reduced this to 20 bin in the fit.""", + "minFracPhiBinsPopulated": """ Fraction of the phi-bins that should be sufficiently populated, based on the current minAverageBinPop setting. Ideally this is 0.8, but sometimes we lower it if the mirror alignment still seems OK with a lower fraction, though we really should adjust the HLT line instead.""", + "deltaThetaWindow": """ dTheta-range in the histograms; 4.0 for Rich1 and 3.0 for Rich2. """, + "combinFitMethod": """ Method for fitting the 2D histograms; 1: first fit the slices of dTheta with a Gaussian and then fit to phi using only the mean of the Gaussian, 3: fit a 2D function, 5: same as 3 but with unifyWidths """, + "magnFactorsMode": """ Method for calculating the magnification coefficents; 0: magnefication coeff. pre-determined, 1: individual for all mirror pairs, determined in the 0-th iteration and not updated any further, 2: individual for all mirrorpairs, determined on-the-fly on the data. """, + "magnifDir": """ directory that contains the pre-determined magnification coeff., files in this folder have to be named Rich[1,2]_MirrMagn _[tiltName]_predefined.txt """, + "solutionMethod": """ Solution method for calculating the mirror tilts after the individual fits; 0: Minuit, 1: Algebraic """, + "regularizationMode": """ regularization mode (0/10/1/11): regularization terms magnified (weighted) with: 0(def)-> major & minor per-mirror MFs; 10-> only averaged per-kind major MFs; 1 (and 11, respectively)-> all weights = 1. """, + "stopToleranceMode": """ tolerance mode: default 0: calculate the stopTolerances from nominal sigma, average magn factors and stopSigmaFraction, 1 use stopTolerances given below""", + "nominalResolutionSigma": """ RICH-dependent nominal Cherenkov angle resolution (in mrad)""", + "stopSigmaFraction": """ tolerance for total tilt of mirror pair in terms of the fraction of the nominal Cherenkov angle resolution """, + "maxIterations": """ The number of iterations the mirror alignment will run, before giving up """, + "requiredEvents": """ If this many events are not procesed by the farm, on average, we do run the alignment but we will never update it. """, + "autoUpdate": """ If True, then the fully automated updating system is activated. If False, our DB update service is still active but returns the starting alignment version. """, + "autoUpdateNoV": """ Only looked at if autoUpdate is True. Then, if autoUpdateNoV is False, nothing changes. If autoUpdateNoV is True, then rather than sending the existing alignment version if autoUpdate is disabled *and* there is a _maybe_ alignment, we will send no version through the DB update service. HLT2 will have to wait for us to assign one. """, + "testing": """ If True, then we are running a test alignment; we also disable our DB update service completely. """, + "trendDateRange": """ Set the date range for the automatic trend plots. Format is YYYYMMDD. Additionally, a minDate(maxDate) of None defaults to the first(last) day of the current year (see AlignMonitor.py).""", + "stopTolerancePriY": """ RICH-dependent tolerance for primary mirrors rotation around Y correction in mrad to stop the alignment """, + "stopTolerancePriZ": """ RICH-dependent tolerance for primary mirrors rotation around Z correction in mrad to stop the alignment """, + "stopToleranceSecY": """ RICH-dependent tolerance for secondary mirrors rotation around Y correction in mrad to stop the alignment """, + "stopToleranceSecZ": """ RICH-dependent tolerance for secondary mirrors rotation around Z correction in mrad to stop the alignment """, + "warningFactor": """ alerts the alignment if any of the mirrors have shifted more than warningFactor times a particular mirror rotation stopTolerance """, + "EvtMax": """ maximal number of events processed by brunel PER NODE (hlt farm has ~1500 nodes), -1 = infinite """, + "dataVariant": """ Helps us decide which Brunel options to use (see RichAnalyzer.py); also used for the naming convention. """, + "fixSinusoidShift": """ 1 : fix at sinusoidShift; 0 : it is not fixed """, + "nameStr": """ Right now this is used only for the naming convention, but will be set when initiating the Configuration. """, + "displayMode": """ 1 : Current TH2D display style (auto-scaling Z-axis, granular colors, using same colors for > 4*threshold); 0: Anatoly's development TH2D display style (similar, but with printed mirror number also, and fixed scale)""", + "xmlMDCS": """ Location of MDCS conditions XML file, for override if needed. Not used if blank. """, } def setNameStr(self): - thisTuning = "Mp" + str(self.getProp('minAverageBinPop')) - thisTuning += "Wi" + str(self.getProp('deltaThetaWindow')) - thisTuning += "Fm" + str(self.getProp('combinFitMethod')) - thisTuning += "Mm" + str(self.getProp('magnFactorsMode')) - thisTuning += "Sm" + str(self.getProp('solutionMethod')) - thisNameStr = thisTuning + "_" + str( - self.getProp('thisCase')) + "_" + str(self.getProp('dataVariant')) + thisTuning = "Mp" + str(self.getProp("minAverageBinPop")) + thisTuning += "Wi" + str(self.getProp("deltaThetaWindow")) + thisTuning += "Fm" + str(self.getProp("combinFitMethod")) + thisTuning += "Mm" + str(self.getProp("magnFactorsMode")) + thisTuning += "Sm" + str(self.getProp("solutionMethod")) + thisNameStr = ( + thisTuning + + "_" + + str(self.getProp("thisCase")) + + "_" + + str(self.getProp("dataVariant")) + ) self.setProp("nameStr", thisNameStr) ### Dont mess with this filename!!! def setHistoDir(self): import time + year = time.strftime("%Y") - histodir = "/hist/Savesets/" + str(year) + "/LHCbA/AligWrk_Rich" + str( - self.getProp("Rich")) + "/" + histodir = ( + "/hist/Savesets/" + + str(year) + + "/LHCbA/AligWrk_Rich" + + str(self.getProp("Rich")) + + "/" + ) self.setProp("HistoDir", histodir) def checkStartIt(self): @@ -256,19 +181,24 @@ class Rich1MirrAlignOnConf(LHCbConfigurableUser): if self.getProp("MinItStart") < 9: if not self.getProp("MajItStart") == 0: self.setProp("MajItStart", 0) - print "Warning: Major Iteration did not match minor itertion. Major iteration was set to match minor iteration." + print( + "Warning: Major Iteration did not match minor itertion. Major iteration was set to match minor iteration." + ) else: - majstartit = (self.getProp("MinItStart") - ( - self.getProp("MinItStart") % self.getProp("MajItStart")) - ) / self.getProp("MajItStart") + majstartit = ( + self.getProp("MinItStart") + - (self.getProp("MinItStart") % self.getProp("MajItStart")) + ) / self.getProp("MajItStart") if not self.getProp("MajItStart") == majstartit: - self.setProp('MajItStart', majstartit) - print "Warning: Major Iteration did not match minor itertion. Major iteration was set to match minor iteration." - if (self.getProp("magnFactorsMode") == 0 - and self.getProp("magnifDir") == ""): - self.setProp("magnifDir", - '/group/rich/AlignmentFiles/MagnifFactors/Rich1/') - print "Warning: Mode for calculating magnification coefficients was chosen to be 0 but no directory with pre-determined coefficients provided. Directory set to default." + self.setProp("MajItStart", majstartit) + print( + "Warning: Major Iteration did not match minor itertion. Major iteration was set to match minor iteration." + ) + if self.getProp("magnFactorsMode") == 0 and self.getProp("magnifDir") == "": + self.setProp("magnifDir", "/group/rich/AlignmentFiles/MagnifFactors/Rich1/") + print( + "Warning: Mode for calculating magnification coefficients was chosen to be 0 but no directory with pre-determined coefficients provided. Directory set to default." + ) if self.getProp("magnFactorsMode") == 0: self.setProp("MinItStart", self.getProp("MajItStart") * 9) @@ -277,10 +207,10 @@ class Rich1MirrAlignOnConf(LHCbConfigurableUser): self.setNameStr() self.checkStartIt() # Next 3 lines add the trailing slash in key directory names - self.setProp('WorkDir', os.path.join(self.getProp('WorkDir'), '')) - self.setProp('SaveDir', os.path.join(self.getProp('SaveDir'), '')) - self.setProp('magnifDir', os.path.join(self.getProp('magnifDir'), '')) - print "INFO: Rich1MirrAlignOnConf applied" + self.setProp("WorkDir", os.path.join(self.getProp("WorkDir"), "")) + self.setProp("SaveDir", os.path.join(self.getProp("SaveDir"), "")) + self.setProp("magnifDir", os.path.join(self.getProp("magnifDir"), "")) + print("INFO: Rich1MirrAlignOnConf applied") class Rich2MirrAlignOnConf(LHCbConfigurableUser): @@ -288,214 +218,137 @@ class Rich2MirrAlignOnConf(LHCbConfigurableUser): __slots__ = { #### Do not ever change these!!! Just DONT! - "Rich": - 2, - "HistoDir": - "" + "Rich": 2, + "HistoDir": "", #### Only change these if you want to pick up from where you left off in iterations, experts only (we don't use this much anymore) - , - "MajItStart": - 0, - "MinItStart": - 0 + "MajItStart": 0, + "MinItStart": 0, ### Better not change these, only for very very VERY good reasons - , - "WorkDir": - "/group/online/AligWork/Rich2/", - "SaveDir": - "/group/online/AligWork/MirrorAlignments/", - "ItNrFile": - "/group/online/dataflow/options/LHCbA/Rich2_Alignment_Reference_File.txt", - "thisCase": - "online", + "WorkDir": "/group/online/AligWork/Rich2/", + "SaveDir": "/group/online/AligWork/MirrorAlignments/", + "ItNrFile": "/group/online/dataflow/options/LHCbA/Rich2_Alignment_Reference_File.txt", + "thisCase": "online", "tiltNames": [ - "", "pri_negYzerZ", "pri_posYzerZ", "pri_zerYnegZ", "pri_zerYposZ", - "sec_negYzerZ", "sec_posYzerZ", "sec_zerYnegZ", "sec_zerYposZ" - ] + "", + "pri_negYzerZ", + "pri_posYzerZ", + "pri_zerYnegZ", + "pri_zerYposZ", + "sec_negYzerZ", + "sec_posYzerZ", + "sec_zerYnegZ", + "sec_zerYposZ", + ], ### May be changed if you know what you are doing - , - "combAndMirrSubsets": - "/group/rich/sw/cmtuser/AlignmentRelease/Rich/RichMirrorAlignmentOnline/files/Rich2CombAndMirrSubsets.txt", - "startXMLFile": - "/group/online/alignment/Rich2/MirrorAlign/v45.xml" # "/group/rich/AlignmentFiles/databaseAlignments/Rich2/Rich2_Zeroed.xml" # if testing is not True OR this is blank, it automatically uses the DB XML file - , - "compareXMLFile": - "" # if this is blank, it automatically uses the DB XML file - , - "coeffCalibTilt": - 0.3, - "minAverageBinPop": - 6, - "phiBinFactor": - 3, - "minFracPhiBinsPopulated": - 0.7 # adjusted from 0.8 due to inefficiencies in our existing choice of HLT line prescales - , - "deltaThetaWindow": - 4.0, - "combinFitMethod": - 5, - "magnFactorsMode": - 0, - "magnifDir": - "/group/rich/sw/cmtuser/AlignmentRelease/Rich/RichMirrorAlignmentOnline/files/MagnifFactors/Rich2/20180424_145140/" + "combAndMirrSubsets": "/group/rich/sw/cmtuser/AlignmentRelease/Rich/RichMirrorAlignmentOnline/files/Rich2CombAndMirrSubsets.txt", + "startXMLFile": "/group/online/alignment/Rich2/MirrorAlign/v45.xml", # "/group/rich/AlignmentFiles/databaseAlignments/Rich2/Rich2_Zeroed.xml" # if testing is not True OR this is blank, it automatically uses the DB XML file + "compareXMLFile": "", # if this is blank, it automatically uses the DB XML file + "coeffCalibTilt": 0.3, + "minAverageBinPop": 6, + "phiBinFactor": 3, + "minFracPhiBinsPopulated": 0.7, # adjusted from 0.8 due to inefficiencies in our existing choice of HLT line prescales + "deltaThetaWindow": 4.0, + "combinFitMethod": 5, + "magnFactorsMode": 0, + "magnifDir": "/group/rich/sw/cmtuser/AlignmentRelease/Rich/RichMirrorAlignmentOnline/files/MagnifFactors/Rich2/20180424_145140/", # ,"magnifDir" : "/group/rich/AlignmentFiles/MagnifFactors/Rich2/20180424_145140/" - , - "solutionMethod": - 0, - "regularizationMode": - 0, - "stopToleranceMode": - 1, - "nominalResolutionSigma": - 0.656 # from https://lblogbook.cern.ch/RICH/13678 (and still seems reasonable throughout 2017) - , - "stopSigmaFraction": - 0, - "maxIterations": - 8, - "requiredEvents": - 942500 # ~70% of 1346563 - , - "autoUpdate": - True, - "autoUpdateNoV": - False, - "testing": - True, - "trendDateRange": { - 'minDate': None, - 'maxDate': None - } + "solutionMethod": 0, + "regularizationMode": 0, + "stopToleranceMode": 1, + "nominalResolutionSigma": 0.656, # from https://lblogbook.cern.ch/RICH/13678 (and still seems reasonable throughout 2017) + "stopSigmaFraction": 0, + "maxIterations": 8, + "requiredEvents": 942500, # ~70% of 1346563 + "autoUpdate": True, + "autoUpdateNoV": False, + "testing": True, + "trendDateRange": {"minDate": None, "maxDate": None}, # 2017 tolerances: [0.032, 0.030, 0.043, 0.057], adjusted to [0.03, 0.03, 0.05, 0.06] - , - "stopTolerancePriY": - 0.03, - "stopTolerancePriZ": - 0.03, - "stopToleranceSecY": - 0.05, - "stopToleranceSecZ": - 0.06, - "warningFactor": - 3, - "EvtMax": - -1, - "dataVariant": - "Collision18", - "fixSinusoidShift": - 1, - "nameStr": - "", - "displayMode": - 1, - "xmlMDCS": - "" # "/group/rich/AlignmentFiles/MDCS/Conditions/Rich1/Environment/HPD.xml" # 'Rich1' is not a typo! + "stopTolerancePriY": 0.03, + "stopTolerancePriZ": 0.03, + "stopToleranceSecY": 0.05, + "stopToleranceSecZ": 0.06, + "warningFactor": 3, + "EvtMax": -1, + "dataVariant": "Collision18", + "fixSinusoidShift": 1, + "nameStr": "", + "displayMode": 1, + "xmlMDCS": "", # "/group/rich/AlignmentFiles/MDCS/Conditions/Rich1/Environment/HPD.xml" # 'Rich1' is not a typo! } _propertyDocDct = { - "MajItStart": - """ Start the alignment at this major iteration. Please make sure this is consitent with MinItStart. """, - "MinItStart": - """ Start the alignment at this minor iteration. Please make sure this is consitent with MajItStart. """, - "Rich": - """ Rich1 or Rich2. """, - "HistoDir": - """ Directory where the savesets are being written to. """, - "WorkDir": - """ Directory in which all the output will be written. """, - "SaveDir": - """ Directory in which all output files of the alignment are saved after it has finished """, - "ItNrFile": - """ File which contains only the number of the current iteration written by the iterator, to be read by the analyzers """, - "thisCase": - """ Right now this is used only for the naming convention. """, - "tiltNames": - """ Combination of tilts for the calculation and usage of the magnification factors. This is needed even when using predefined magnification factors!!! """, - "combAndMirrSubsets": - """ File that lists the subset of combinations of primary and secondary mirror segments chosen for alignment monitoring, and all mirror segments under alignment monitoring """, - "startXMLFile": - """ ONLY IF testing = True, this is the XML file with the mirror tilts that we start with for the alignment; if it is blank or testing is not True, it uses the latest v-numbered xml (which is what should be currently in the DB) """, - "compareXMLFile": - """ XML file with mirror tilts, for comparison of mirror tilts before and after alignment; if it is blank, it uses the latest v-numbered xml (which is what should be currently in the DB) """, - "coeffCalibTilt": - """ Mirror-tilts applied for the calculation of the magnification coefficients. """, - "minAverageBinPop": - """ Demanded minimal entries per bin in x-y-bin; atm 6: for 20 phi-bins, 4.8: for 25 phi-bins. """, - "phiBinFactor": - """ Factor by which the number of phi-bins is reduced. The histograms should now come with 60 phi bins, factor 3 reduced this to 20 bin in the fit.""", - "minFracPhiBinsPopulated": - """ Fraction of the phi-bins that should be sufficiently populated, based on the current minAverageBinPop setting. Ideally this is 0.8, but sometimes we lower it if the mirror alignment still seems OK with a lower fraction, though we really should adjust the HLT line instead.""", - "deltaThetaWindow": - """ dTheta-range in the histograms; 4.0 for Rich1 and 3.0 for Rich2. """, - "combinFitMethod": - """ Method for fitting the 2D histograms; 1: first fit the slices of dTheta with a Gaussian and then fit to phi using only the mean of the Gaussian, 3: fit a 2D function, 5: Same as 3 but with unifyWidths """, - "magnFactorsMode": - """ Method for calculating the magnification coefficents; 0: magnefication coeff. pre-determined, 1: individual for all mirror pairs, determined in the 0-th iteration and not updated any further, 2: individual for all mirrorpairs, determined on-the-fly on the data. """, - "magnifDir": - """ directory that contains the pre-determined magnification coeff., files in this folder have to be named Rich[1,2]_MirrMagn _[tiltName]_predefined.txt """, - "solutionMethod": - """ Solution method for calculating the mirror tilts after the individual fits; 0: Minuit, 1: Algebraic """, - "regularizationMode": - """ regularization mode (0/10/1/11): regularization terms magnified (weighted) with: 0(def)-> major & minor per-mirror MFs; 10-> only averaged per-kind major MFs; 1 (and 11, respectively)-> all weights = 1. """, - "stopToleranceMode": - """ tolerance mode: default 0: calculate the stopTolerances from nominal sigma, average magn factors and stopSigmaFraction, 1 use stopTolerances given below""", - "nominalResolutionSigma": - """ RICH-dependent nominal Cherenkov angle resolution (in mrad)""", - "stopSigmaFraction": - """ tolerance for total tilt of mirror pair in terms of the fraction of the nominal Cherenkov angle resolution """, - "maxIterations": - """ The number of iterations the mirror alignment will run, before giving up """, - "requiredEvents": - """ If this many events are not procesed by the farm, on average, we do run the alignment but we will never update it. """, - "autoUpdate": - """ If True, then the fully automated updating system is activated. If False, our DB update service is still active but returns the starting alignment version. """, - "autoUpdateNoV": - """ Only looked at if autoUpdate is True. Then, if autoUpdateNoV is False, nothing changes. If autoUpdateNoV is True, then rather than sending the existing alignment version if autoUpdate is disabled *and* there is a _maybe_ alignment, we will send no version through the DB update service. HLT2 will have to wait for us to assign one. """, - "testing": - """ If True, then we are running a test alignment; we also disable our DB update service completely. """, - "trendDateRange": - """ Set the date range for the automatic trend plots. Format is YYYYMMDD. Additionally, a minDate(maxDate) of None defaults to the first(last) day of the current year (see AlignMonitor.py).""", - "stopTolerancePriY": - """ RICH-dependent tolerance for primary mirrors rotation around Y correction in mrad to stop the alignment """, - "stopTolerancePriZ": - """ RICH-dependent tolerance for primary mirrors rotation around Z correction in mrad to stop the alignment """, - "stopToleranceSecY": - """ RICH-dependent tolerance for secondary mirrors rotation around Y correction in mrad to stop the alignment """, - "stopToleranceSecZ": - """ RICH-dependent tolerance for secondary mirrors rotation around Z correction in mrad to stop the alignment """, - "warningFactor": - """ alerts the alignment if any of the mirrors have shifted more than warningFactor times a particular mirror rotation stopTolerance """, - "EvtMax": - """ maximal number of events processed by brunel PER NODE (hlt farm has ~1500 nodes), -1 = infinite """, - "dataVariant": - """ Helps us decide which Brunel options to use (see RichAnalyzer.py); also used for the naming convention. """, - "fixSinusoidShift": - """ 1 : fix at sinusoidShift; 0 : it is not fixed """, - "nameStr": - """ Right now this is used only for the naming convention, but will be set when initiating the Configuration. """, - "displayMode": - """ 1 : Current TH2D display style (auto-scaling Z-axis, granular colors, using same colors for > 4*threshold); 0: Anatoly's development TH2D display style (similar, but with printed mirror number also, and fixed scale)""", - "xmlMDCS": - """ Location of MDCS conditions XML file, for override if needed. Not used if blank. """ + "MajItStart": """ Start the alignment at this major iteration. Please make sure this is consitent with MinItStart. """, + "MinItStart": """ Start the alignment at this minor iteration. Please make sure this is consitent with MajItStart. """, + "Rich": """ Rich1 or Rich2. """, + "HistoDir": """ Directory where the savesets are being written to. """, + "WorkDir": """ Directory in which all the output will be written. """, + "SaveDir": """ Directory in which all output files of the alignment are saved after it has finished """, + "ItNrFile": """ File which contains only the number of the current iteration written by the iterator, to be read by the analyzers """, + "thisCase": """ Right now this is used only for the naming convention. """, + "tiltNames": """ Combination of tilts for the calculation and usage of the magnification factors. This is needed even when using predefined magnification factors!!! """, + "combAndMirrSubsets": """ File that lists the subset of combinations of primary and secondary mirror segments chosen for alignment monitoring, and all mirror segments under alignment monitoring """, + "startXMLFile": """ ONLY IF testing = True, this is the XML file with the mirror tilts that we start with for the alignment; if it is blank or testing is not True, it uses the latest v-numbered xml (which is what should be currently in the DB) """, + "compareXMLFile": """ XML file with mirror tilts, for comparison of mirror tilts before and after alignment; if it is blank, it uses the latest v-numbered xml (which is what should be currently in the DB) """, + "coeffCalibTilt": """ Mirror-tilts applied for the calculation of the magnification coefficients. """, + "minAverageBinPop": """ Demanded minimal entries per bin in x-y-bin; atm 6: for 20 phi-bins, 4.8: for 25 phi-bins. """, + "phiBinFactor": """ Factor by which the number of phi-bins is reduced. The histograms should now come with 60 phi bins, factor 3 reduced this to 20 bin in the fit.""", + "minFracPhiBinsPopulated": """ Fraction of the phi-bins that should be sufficiently populated, based on the current minAverageBinPop setting. Ideally this is 0.8, but sometimes we lower it if the mirror alignment still seems OK with a lower fraction, though we really should adjust the HLT line instead.""", + "deltaThetaWindow": """ dTheta-range in the histograms; 4.0 for Rich1 and 3.0 for Rich2. """, + "combinFitMethod": """ Method for fitting the 2D histograms; 1: first fit the slices of dTheta with a Gaussian and then fit to phi using only the mean of the Gaussian, 3: fit a 2D function, 5: Same as 3 but with unifyWidths """, + "magnFactorsMode": """ Method for calculating the magnification coefficents; 0: magnefication coeff. pre-determined, 1: individual for all mirror pairs, determined in the 0-th iteration and not updated any further, 2: individual for all mirrorpairs, determined on-the-fly on the data. """, + "magnifDir": """ directory that contains the pre-determined magnification coeff., files in this folder have to be named Rich[1,2]_MirrMagn _[tiltName]_predefined.txt """, + "solutionMethod": """ Solution method for calculating the mirror tilts after the individual fits; 0: Minuit, 1: Algebraic """, + "regularizationMode": """ regularization mode (0/10/1/11): regularization terms magnified (weighted) with: 0(def)-> major & minor per-mirror MFs; 10-> only averaged per-kind major MFs; 1 (and 11, respectively)-> all weights = 1. """, + "stopToleranceMode": """ tolerance mode: default 0: calculate the stopTolerances from nominal sigma, average magn factors and stopSigmaFraction, 1 use stopTolerances given below""", + "nominalResolutionSigma": """ RICH-dependent nominal Cherenkov angle resolution (in mrad)""", + "stopSigmaFraction": """ tolerance for total tilt of mirror pair in terms of the fraction of the nominal Cherenkov angle resolution """, + "maxIterations": """ The number of iterations the mirror alignment will run, before giving up """, + "requiredEvents": """ If this many events are not procesed by the farm, on average, we do run the alignment but we will never update it. """, + "autoUpdate": """ If True, then the fully automated updating system is activated. If False, our DB update service is still active but returns the starting alignment version. """, + "autoUpdateNoV": """ Only looked at if autoUpdate is True. Then, if autoUpdateNoV is False, nothing changes. If autoUpdateNoV is True, then rather than sending the existing alignment version if autoUpdate is disabled *and* there is a _maybe_ alignment, we will send no version through the DB update service. HLT2 will have to wait for us to assign one. """, + "testing": """ If True, then we are running a test alignment; we also disable our DB update service completely. """, + "trendDateRange": """ Set the date range for the automatic trend plots. Format is YYYYMMDD. Additionally, a minDate(maxDate) of None defaults to the first(last) day of the current year (see AlignMonitor.py).""", + "stopTolerancePriY": """ RICH-dependent tolerance for primary mirrors rotation around Y correction in mrad to stop the alignment """, + "stopTolerancePriZ": """ RICH-dependent tolerance for primary mirrors rotation around Z correction in mrad to stop the alignment """, + "stopToleranceSecY": """ RICH-dependent tolerance for secondary mirrors rotation around Y correction in mrad to stop the alignment """, + "stopToleranceSecZ": """ RICH-dependent tolerance for secondary mirrors rotation around Z correction in mrad to stop the alignment """, + "warningFactor": """ alerts the alignment if any of the mirrors have shifted more than warningFactor times a particular mirror rotation stopTolerance """, + "EvtMax": """ maximal number of events processed by brunel PER NODE (hlt farm has ~1500 nodes), -1 = infinite """, + "dataVariant": """ Helps us decide which Brunel options to use (see RichAnalyzer.py); also used for the naming convention. """, + "fixSinusoidShift": """ 1 : fix at sinusoidShift; 0 : it is not fixed """, + "nameStr": """ Right now this is used only for the naming convention, but will be set when initiating the Configuration. """, + "displayMode": """ 1 : Current TH2D display style (auto-scaling Z-axis, granular colors, using same colors for > 4*threshold); 0: Anatoly's development TH2D display style (similar, but with printed mirror number also, and fixed scale)""", + "xmlMDCS": """ Location of MDCS conditions XML file, for override if needed. Not used if blank. """, } ### Dont mess with this filename!!! def setHistoDir(self): import time + year = time.strftime("%Y") - histodir = "/hist/Savesets/" + str(year) + "/LHCbA/AligWrk_Rich" + str( - self.getProp("Rich")) + "/" + histodir = ( + "/hist/Savesets/" + + str(year) + + "/LHCbA/AligWrk_Rich" + + str(self.getProp("Rich")) + + "/" + ) self.setProp("HistoDir", histodir) def setNameStr(self): - thisTuning = "Mp" + str(self.getProp('minAverageBinPop')) - thisTuning += "Wi" + str(self.getProp('deltaThetaWindow')) - thisTuning += "Fm" + str(self.getProp('combinFitMethod')) - thisTuning += "Mm" + str(self.getProp('magnFactorsMode')) - thisTuning += "Sm" + str(self.getProp('solutionMethod')) - thisNameStr = thisTuning + "_" + str( - self.getProp('thisCase')) + "_" + str(self.getProp('dataVariant')) + thisTuning = "Mp" + str(self.getProp("minAverageBinPop")) + thisTuning += "Wi" + str(self.getProp("deltaThetaWindow")) + thisTuning += "Fm" + str(self.getProp("combinFitMethod")) + thisTuning += "Mm" + str(self.getProp("magnFactorsMode")) + thisTuning += "Sm" + str(self.getProp("solutionMethod")) + thisNameStr = ( + thisTuning + + "_" + + str(self.getProp("thisCase")) + + "_" + + str(self.getProp("dataVariant")) + ) self.setProp("nameStr", thisNameStr) def checkStartIt(self): @@ -503,19 +356,24 @@ class Rich2MirrAlignOnConf(LHCbConfigurableUser): if self.getProp("MinItStart") < 9: if not self.getProp("MajItStart") == 0: self.setProp("MajItStart", 0) - print "Warning: Major Iteration did not match minor itertion. Major iteration was set to match minor iteration." + print( + "Warning: Major Iteration did not match minor itertion. Major iteration was set to match minor iteration." + ) else: - majstartit = (self.getProp("MinItStart") - ( - self.getProp("MinItStart") % self.getProp("MajItStart")) - ) / self.getProp("MajItStart") + majstartit = ( + self.getProp("MinItStart") + - (self.getProp("MinItStart") % self.getProp("MajItStart")) + ) / self.getProp("MajItStart") if not self.getProp("MajItStart") == majstartit: - self.setProp('MajItStart', majstartit) - print "Warning: Major Iteration did not match minor itertion. Major iteration was set to match minor iteration." - if (self.getProp("magnFactorsMode") == 0 - and self.getProp("magnifDir") == ""): - self.setProp("magnifDir", - '/group/rich/AlignmentFiles/MagnifFactors/Rich2/') - print "Warning: Mode for calculating magnification coefficients was chosen to be 0 but no directory with pre-determined coefficients provided. Directory set to default." + self.setProp("MajItStart", majstartit) + print( + "Warning: Major Iteration did not match minor itertion. Major iteration was set to match minor iteration." + ) + if self.getProp("magnFactorsMode") == 0 and self.getProp("magnifDir") == "": + self.setProp("magnifDir", "/group/rich/AlignmentFiles/MagnifFactors/Rich2/") + print( + "Warning: Mode for calculating magnification coefficients was chosen to be 0 but no directory with pre-determined coefficients provided. Directory set to default." + ) if self.getProp("magnFactorsMode") == 0: self.setProp("MinItStart", self.getProp("MajItStart") * 9) @@ -524,13 +382,13 @@ class Rich2MirrAlignOnConf(LHCbConfigurableUser): self.setNameStr() self.checkStartIt() # Next 3 lines add the trailing slash in key directory names - self.setProp('WorkDir', os.path.join(self.getProp('WorkDir'), '')) - self.setProp('SaveDir', os.path.join(self.getProp('SaveDir'), '')) - self.setProp('magnifDir', os.path.join(self.getProp('magnifDir'), '')) - print "INFO: Rich2MirrAlignOnConf applied" + self.setProp("WorkDir", os.path.join(self.getProp("WorkDir"), "")) + self.setProp("SaveDir", os.path.join(self.getProp("SaveDir"), "")) + self.setProp("magnifDir", os.path.join(self.getProp("magnifDir"), "")) + print("INFO: Rich2MirrAlignOnConf applied") -#=============================================================================== +# =============================================================================== # regularizationMode has changed from 1 (used in 2016) to 0 (used in 2017). # Looking back at the functional we minimize: # https://indico.cern.ch/event/477524/contributions/2174895/attachments/1276535/1894128/richmirralign_update_2016-05-20_rich_sw.pdf @@ -546,4 +404,4 @@ class Rich2MirrAlignOnConf(LHCbConfigurableUser): # In light of this, the RICH1 tolerances for 2017 should be set to: [0.027, 0.030, 0.455, 0.370] mrad # What we decided for RICH2 from 2016 study: [0.065, 0.055, 0.045, 0.035] mrad # In light of this, the RICH2 tolerances for 2017 should be set to: [0.032, 0.030, 0.043, 0.057] mrad -#=============================================================================== +# =============================================================================== diff --git a/Rich/RichMirrorAlignmentOnline/python/RichMirrorAlignmentOnline/SavedConfigurations/README.txt b/Rich/RichMirrorAlignmentOnline/python/RichMirrorAlignmentOnline/SavedConfigurations/README.txt index 3291eefffe4ddb7089415542319e9a9bd7bb18d3..030377efade789a3ef1bd8efd9c808383f51c5c6 100644 --- a/Rich/RichMirrorAlignmentOnline/python/RichMirrorAlignmentOnline/SavedConfigurations/README.txt +++ b/Rich/RichMirrorAlignmentOnline/python/RichMirrorAlignmentOnline/SavedConfigurations/README.txt @@ -60,4 +60,3 @@ Removed Configurations: and ONLY for RICH1: coeffCalibTilt changed from default to 0.8 magnifCoeffMode changed from default to 2 (recalculate magnification factors in each iteration) - diff --git a/Rich/RichMirrorAlignmentOnline/python/RichMirrorAlignmentOnline/__init__.py b/Rich/RichMirrorAlignmentOnline/python/RichMirrorAlignmentOnline/__init__.py index d6634e42c7d5a238c439b004162e7fed2fe8337d..8b2e4ce683e7b62ac7c470db076115bd18edb141 100644 --- a/Rich/RichMirrorAlignmentOnline/python/RichMirrorAlignmentOnline/__init__.py +++ b/Rich/RichMirrorAlignmentOnline/python/RichMirrorAlignmentOnline/__init__.py @@ -9,9 +9,9 @@ # or submit itself to any jurisdiction. # ############################################################################### # Import required modules -import os import glob import inspect +import os # Get this module's source code directory module_file = inspect.getfile(inspect.currentframe()) @@ -20,12 +20,10 @@ module_dir = os.path.dirname(module_file) print(f"INFO: RichMirrorAlignmentOnline package directory: {module_dir}") # Get the list of all .py file names in the package directory -files = glob.glob(os.path.join(module_dir, '*.py')) +files = glob.glob(os.path.join(module_dir, "*.py")) # Extract the module names from the file names -module_names = [ - os.path.basename(file)[:-3] for file in files if not "__init__" in file -] +module_names = [os.path.basename(file)[:-3] for file in files if not "__init__" in file] # Define the __all__ variable as the list of module names __all__ = module_names diff --git a/Rich/RichMirrorAlignmentOnline/src/MirrPauseHandler.cpp b/Rich/RichMirrorAlignmentOnline/src/MirrPauseHandler.cpp index 1974d0b72ee0d72d52c91af564973cd7b00c0c99..262592cd6072d0211dfaef0185cfcb49775e8708 100644 --- a/Rich/RichMirrorAlignmentOnline/src/MirrPauseHandler.cpp +++ b/Rich/RichMirrorAlignmentOnline/src/MirrPauseHandler.cpp @@ -111,7 +111,7 @@ StatusCode MirrPauseHandler::execute() { auto b = m_rawEvt->banks( i ); if ( b.size() > 0 ) { for ( auto itB = b.begin(); itB != b.end(); itB++ ) { - m_currentRun = LHCb::ODIN{( *itB )->range<std::uint32_t>()}.runNumber(); + m_currentRun = LHCb::ODIN{ ( *itB )->range<std::uint32_t>() }.runNumber(); } } } diff --git a/Rich/RichOnlineCalib/options/RichOnlineCalib-Offline.py b/Rich/RichOnlineCalib/options/RichOnlineCalib-Offline.py index c2bd424aa274a308975c40738c6e5b9083f794a7..2e4ea4b8064fbb84aabf73380a1c0ff8dd899a18 100644 --- a/Rich/RichOnlineCalib/options/RichOnlineCalib-Offline.py +++ b/Rich/RichOnlineCalib/options/RichOnlineCalib-Offline.py @@ -15,22 +15,21 @@ gaudirun.py RichOnlineCalib-Offline.py """ from Configurables import GaudiSequencer + RichOnCalibSeq = GaudiSequencer("RichOnCalibSeq") # -from Configurables import OMARichRefIndex, OMARichHPDImage +from Configurables import OMARichHPDImage, OMARichRefIndex RefIndexAlg = OMARichRefIndex("RefIndexAlg") HPDImageAlg = OMARichHPDImage("HPDImageAlg") -#myFiles1 = ["/afs/cern.ch/user/j/jhe/gangadir/workspace/jhe/LocalXML/308/output/RefInCalib-RichCKCalib_pA_BR-v43r2p6_Run-135576.root"] +# myFiles1 = ["/afs/cern.ch/user/j/jhe/gangadir/workspace/jhe/LocalXML/308/output/RefInCalib-RichCKCalib_pA_BR-v43r2p6_Run-135576.root"] myFiles0 = [ "/afs/cern.ch/user/j/jhe/scratch0/Rich/Brunel-135576-20130120T161302-EOR.root" ] -myFiles1 = [ - "/afs/cern.ch/user/j/jhe/scratch0/Rich/Brunel-135576-Offline-EOR.root" -] +myFiles1 = ["/afs/cern.ch/user/j/jhe/scratch0/Rich/Brunel-135576-Offline-EOR.root"] RefIndexAlg.InputFiles = myFiles1 RefIndexAlg.xmlFilePath = "/tmp/jhe/" @@ -39,7 +38,7 @@ HPDImageAlg.InputFiles = myFiles1 HPDImageAlg.xmlFilePath = "/tmp/jhe/" RichOnCalibSeq.Members += [ - #RefIndexAlg, + # RefIndexAlg, HPDImageAlg ] @@ -52,8 +51,10 @@ RefIndexAlg.OutputLevel = 2 HPDImageAlg.OutputLevel = 2 from Configurables import ApplicationMgr + ApplicationMgr().TopAlg += [RichOnCalibSeq] from Configurables import LHCbApp + LHCbApp().DDDBtag = "head-20120413" LHCbApp().CondDBtag = "cond-20120730" diff --git a/Rich/RichOnlineCalib/options/RichOnlineCalib.py b/Rich/RichOnlineCalib/options/RichOnlineCalib.py index 5e594cec4e18a967b35eea82230e0b7596fb76e0..d82e356855461b202bd9e67891c2578b2c22bde2 100644 --- a/Rich/RichOnlineCalib/options/RichOnlineCalib.py +++ b/Rich/RichOnlineCalib/options/RichOnlineCalib.py @@ -9,10 +9,11 @@ # or submit itself to any jurisdiction. # ############################################################################### from Configurables import GaudiSequencer + RichOnCalibSeq = GaudiSequencer("RichOnCalibSeq") # -from Configurables import OMARichRefIndex, OMARichHPDImage +from Configurables import OMARichHPDImage, OMARichRefIndex RefIndexAlg = OMARichRefIndex("RefIndexAlg") HPDImageAlg = OMARichHPDImage("HPDImageAlg") @@ -33,6 +34,7 @@ RefIndexAlg.OutputLevel = 3 HPDImageAlg.OutputLevel = 3 from Configurables import ApplicationMgr + ApplicationMgr().TopAlg += [RichOnCalibSeq] ApplicationMgr().EvtSel = "NONE" @@ -40,5 +42,6 @@ ApplicationMgr().ExtSvc += ["MonitorSvc"] ApplicationMgr().Runable = "LHCb::OnlineRunable/Runable" from Configurables import LHCbApp + LHCbApp().DDDBtag = "head-20120413" LHCbApp().CondDBtag = "cond-20120730" diff --git a/Rich/RichOnlineCalib/src/RichCalibUtils.cpp b/Rich/RichOnlineCalib/src/RichCalibUtils.cpp index bfaacbad4ff20bf6e5f25094fe729815e8f80093..42014374522fddbdd756fea4fe405e05a5e26f50 100644 --- a/Rich/RichOnlineCalib/src/RichCalibUtils.cpp +++ b/Rich/RichOnlineCalib/src/RichCalibUtils.cpp @@ -34,7 +34,7 @@ StatusCode CalibAlg::initialize() { // Partition const char* partition = getenv( "PARTITION" ); if ( partition ) { - const std::string part{partition}; + const std::string part{ partition }; calib_message( MSG::INFO, "Environment variable PARTITION = '", part, "'" ); m_okToPublish = m_okToPublish.value() && ( part != "RICH" && part != "RICH1" && part != "RICH2" && part != "FEST" ); diff --git a/Rich/RichOnlineCalib/src/RichCalibUtils.h b/Rich/RichOnlineCalib/src/RichCalibUtils.h index 33c54b028f72f9dd7a0c198ab801749085a3ee15..2e8d5598b02111069e471197597e237342cead9c 100644 --- a/Rich/RichOnlineCalib/src/RichCalibUtils.h +++ b/Rich/RichOnlineCalib/src/RichCalibUtils.h @@ -62,7 +62,7 @@ namespace Rich::Calib::Utils { enum Quadrant : std::uint16_t { Q0 = 0, Q1, Q2, Q3 }; - inline auto quadrants() { return std::array{Quadrant::Q0, Quadrant::Q1, Quadrant::Q2, Quadrant::Q3}; } + inline auto quadrants() { return std::array{ Quadrant::Q0, Quadrant::Q1, Quadrant::Q2, Quadrant::Q3 }; } template <typename T> using QuadArray = Rich::Future::Hist::Array<T, 4, Quadrant>; @@ -85,8 +85,8 @@ namespace Rich::Calib::Utils { /// Type for value+-error template <typename TYPE> struct ValueWithError { - TYPE value{1}; - TYPE error{0}; + TYPE value{ 1 }; + TYPE error{ 0 }; friend inline std::ostream& operator<<( std::ostream& os, const ValueWithError& ve ) { os << "[ " << boost::format( "%10.5e" ) % ve.value; @@ -96,8 +96,8 @@ namespace Rich::Calib::Utils { }; struct RunStats { - unsigned long long used{0}; ///< #Events used for calibration - unsigned long long late{0}; ///< #Events that arrived late + unsigned long long used{ 0 }; ///< #Events used for calibration + unsigned long long late{ 0 }; ///< #Events that arrived late }; /// Base class for calibration algorithms @@ -113,31 +113,31 @@ namespace Rich::Calib::Utils { protected: // data - std::string m_taskType{"UNDEFINED"}; + std::string m_taskType{ "UNDEFINED" }; /// Current TCanvas for printing mutable std::unique_ptr<TCanvas> m_canvas; /// Run number for last processed run - mutable unsigned int m_runNumber{0}; + mutable unsigned int m_runNumber{ 0 }; /// PDF file for each run mutable std::map<unsigned int, std::string> m_pdfFile; /// The time the last calibration was run - mutable time_t m_timeLastCalib{0}; + mutable time_t m_timeLastCalib{ 0 }; /// The time the current ongoing calibration started - mutable time_t m_timeCurrentCalibStart{0}; + mutable time_t m_timeCurrentCalibStart{ 0 }; /// Total overall number of events seen - mutable unsigned long long m_nEvts{0}; + mutable unsigned long long m_nEvts{ 0 }; /// Number of events seen since last calibration was run... - mutable unsigned long long m_nEventsSinceCalib{0}; + mutable unsigned long long m_nEventsSinceCalib{ 0 }; /// Total number of events in current run - mutable unsigned long long m_nEventsThisRun{0}; + mutable unsigned long long m_nEventsThisRun{ 0 }; /** List of all previously calibrated runs for the current process * with the number of events used for that calibration */ @@ -150,54 +150,54 @@ namespace Rich::Calib::Utils { // properties /// minimum beta value for tracks - Gaudi::Property<DetectorArray<float>> m_minBeta{this, "MinBeta", {0.9999f, 0.9999f}}; + Gaudi::Property<DetectorArray<float>> m_minBeta{ this, "MinBeta", { 0.9999f, 0.9999f } }; /// maximum beta value for tracks - Gaudi::Property<DetectorArray<float>> m_maxBeta{this, "MaxBeta", {999.99f, 999.99f}}; + Gaudi::Property<DetectorArray<float>> m_maxBeta{ this, "MaxBeta", { 999.99f, 999.99f } }; /// Overall Min monentum cut Gaudi::Property<DetectorArray<double>> m_minP{ - this, "MinP", {0.0 * Gaudi::Units::GeV, 0.0 * Gaudi::Units::GeV}, "Minimum momentum (GeV/c)"}; + this, "MinP", { 0.0 * Gaudi::Units::GeV, 0.0 * Gaudi::Units::GeV }, "Minimum momentum (GeV/c)" }; /// Overall Max monentum cut Gaudi::Property<DetectorArray<double>> m_maxP{ - this, "MaxP", {9e9 * Gaudi::Units::GeV, 9e9 * Gaudi::Units::GeV}, "Maximum momentum (GeV/c)"}; + this, "MaxP", { 9e9 * Gaudi::Units::GeV, 9e9 * Gaudi::Units::GeV }, "Maximum momentum (GeV/c)" }; /// Histogram ranges for CK resolution plots - Gaudi::Property<DetectorArray<float>> m_ckResRange{this, "CKResHistoRange", {0.0055f, 0.0035f}}; + Gaudi::Property<DetectorArray<float>> m_ckResRange{ this, "CKResHistoRange", { 0.0055f, 0.0035f } }; /// Min theta limit for histos for each rad - Gaudi::Property<DetectorArray<float>> m_ckThetaMin{this, "ChThetaRecHistoLimitMin", {0.040f, 0.020f}}; + Gaudi::Property<DetectorArray<float>> m_ckThetaMin{ this, "ChThetaRecHistoLimitMin", { 0.040f, 0.020f } }; /// Max theta limit for histos for each rad - Gaudi::Property<DetectorArray<float>> m_ckThetaMax{this, "ChThetaRecHistoLimitMax", {0.065f, 0.035f}}; + Gaudi::Property<DetectorArray<float>> m_ckThetaMax{ this, "ChThetaRecHistoLimitMax", { 0.065f, 0.035f } }; /// Is it is OK to publish calibrations - Gaudi::Property<bool> m_okToPublish{this, "OKToPublish", true}; + Gaudi::Property<bool> m_okToPublish{ this, "OKToPublish", true }; /// Task log file name - Gaudi::Property<std::string> m_loggerFile{this, "LoggerFile", "Task.log"}; + Gaudi::Property<std::string> m_loggerFile{ this, "LoggerFile", "Task.log" }; /// Summary file path - Gaudi::Property<std::string> m_summaryPath{this, "summaryPath", "/group/online/alignment"}; + Gaudi::Property<std::string> m_summaryPath{ this, "summaryPath", "/group/online/alignment" }; /// Min entries for a fit - Gaudi::Property<unsigned int> m_minEntries{this, "minEntries", 100000}; + Gaudi::Property<unsigned int> m_minEntries{ this, "minEntries", 100000 }; /// Flag to turn on/off the saving of summary PDF files - Gaudi::Property<bool> m_createPDFsummary{this, "CreatePDFSummary", true}; + Gaudi::Property<bool> m_createPDFsummary{ this, "CreatePDFSummary", true }; /// Max run number history - Gaudi::Property<unsigned int> m_runNumHistSize{this, "RunNumHistSize", 100}; + Gaudi::Property<unsigned int> m_runNumHistSize{ this, "RunNumHistSize", 100 }; /// Detailed run-by-run debugging histos - Gaudi::Property<bool> m_enableRunByRunHists{this, "RunByRunHists", false}; + Gaudi::Property<bool> m_enableRunByRunHists{ this, "RunByRunHists", false }; // Log file from run by run summary - Gaudi::Property<std::string> m_runByrunLog{this, "RunByRunSummary", "RunByRunSummary.txt"}; + Gaudi::Property<std::string> m_runByrunLog{ this, "RunByRunSummary", "RunByRunSummary.txt" }; /// The radiators to calibration - Gaudi::Property<std::vector<std::string>> m_rads{this, "RichRads", {"Rich1Gas", "Rich2Gas"}}; + Gaudi::Property<std::vector<std::string>> m_rads{ this, "RichRads", { "Rich1Gas", "Rich2Gas" } }; protected: /// End of calibration reset @@ -248,7 +248,7 @@ namespace Rich::Calib::Utils { inline auto getDateTimeString( const char* fmt = "%Y%m%d:%H%M%S" ) const { const std::time_t t = std::time( nullptr ); char mbstr[100]; - return std::string{std::strftime( mbstr, sizeof( mbstr ), fmt, std::localtime( &t ) ) ? mbstr : ""}; + return std::string{ std::strftime( mbstr, sizeof( mbstr ), fmt, std::localtime( &t ) ) ? mbstr : "" }; } /// Get year/month/day as a string @@ -397,7 +397,7 @@ namespace Rich::Calib::Utils { assert( !hists.empty() ); if ( !hists.empty() ) { // Always fill the last histogram added to the container - ++hists.back()[{std::forward<Args>( args )...}]; + ++hists.back()[{ std::forward<Args>( args )... }]; } } }; diff --git a/Rich/RichOnlineCalib/src/RichPhotonCounting.cpp b/Rich/RichOnlineCalib/src/RichPhotonCounting.cpp index 0778df9885bc62f6dec0f9beb08f2704ba19600a..2000be661968f58c61ab027cfca244f94b0ba239 100644 --- a/Rich/RichOnlineCalib/src/RichPhotonCounting.cpp +++ b/Rich/RichOnlineCalib/src/RichPhotonCounting.cpp @@ -71,13 +71,13 @@ namespace Rich::Future::Rec::Counting { /// Standard constructor PhotonCounting( const std::string& name, ISvcLocator* pSvcLocator ) : Consumer( name, pSvcLocator, - {KeyValue{"ODINLocation", LHCb::ODINLocation::Default}, - KeyValue{"TracksLocation", LHCb::TrackLocation::Default}, - KeyValue{"SummaryTracksLocation", Summary::TESLocations::Tracks}, - KeyValue{"PhotonToParentsLocation", Relations::PhotonToParentsLocation::Default}, - KeyValue{"TrackSegmentsLocation", LHCb::RichTrackSegmentLocation::Default}, - KeyValue{"CherenkovAnglesLocation", CherenkovAnglesLocation::Signal}, - KeyValue{"CherenkovPhotonLocation", SIMDCherenkovPhotonLocation::Default}} ) { + { KeyValue{ "ODINLocation", LHCb::ODINLocation::Default }, + KeyValue{ "TracksLocation", LHCb::TrackLocation::Default }, + KeyValue{ "SummaryTracksLocation", Summary::TESLocations::Tracks }, + KeyValue{ "PhotonToParentsLocation", Relations::PhotonToParentsLocation::Default }, + KeyValue{ "TrackSegmentsLocation", LHCb::RichTrackSegmentLocation::Default }, + KeyValue{ "CherenkovAnglesLocation", CherenkovAnglesLocation::Signal }, + KeyValue{ "CherenkovPhotonLocation", SIMDCherenkovPhotonLocation::Default } } ) { setProperty( "NBins1DHistos", 150 ).ignore(); setProperty( "NBins2DHistos", 100 ).ignore(); m_taskType = "PhotonCounting"; @@ -185,7 +185,7 @@ namespace Rich::Future::Rec::Counting { setLabels( h_ckPhotonYield[rich] ); ok &= ( h_ckPhotonYield[rich].get() != nullptr ); } // active rad loop - return StatusCode{ok}; + return StatusCode{ ok }; } private: @@ -290,56 +290,59 @@ namespace Rich::Future::Rec::Counting { // properties /// The histogram ID to use - Gaudi::Property<std::string> m_ResPlot{this, "ResPlot", "ckResAll"}; + Gaudi::Property<std::string> m_ResPlot{ this, "ResPlot", "ckResAll" }; /// Allow counting during stop() - Gaudi::Property<bool> m_allowStopCounting{this, "AllowCountingAtStop", true}; + Gaudi::Property<bool> m_allowStopCounting{ this, "AllowCountingAtStop", true }; /// Min VP nHits cut - Gaudi::Property<DetectorArray<double>> m_minvphits{this, "MinVPHits", {8.0, 8.0}, "Minimum VP nHits"}; + Gaudi::Property<DetectorArray<double>> m_minvphits{ this, "MinVPHits", { 8.0, 8.0 }, "Minimum VP nHits" }; /// Background model - Gaudi::Property<bool> m_enableQuadraticBckModel{this, "QuadraticBckModel", true}; + Gaudi::Property<bool> m_enableQuadraticBckModel{ this, "QuadraticBckModel", true }; private: // cached data // Define the region boundary - const DetectorArray<double> m_bkgWindow1Low = {-0.008, -0.0035}; - const DetectorArray<double> m_bkgWindow1High = {-0.003, -0.002}; - const DetectorArray<double> m_bkgWindow2Low = {0.0035, 0.002}; - const DetectorArray<double> m_bkgWindow2High = {0.008, 0.0035}; + const DetectorArray<double> m_bkgWindow1Low = { -0.008, -0.0035 }; + const DetectorArray<double> m_bkgWindow1High = { -0.003, -0.002 }; + const DetectorArray<double> m_bkgWindow2Low = { 0.0035, 0.002 }; + const DetectorArray<double> m_bkgWindow2High = { 0.008, 0.0035 }; // Define the region boundary - quadratic - const DetectorArray<double> m_bkgQuad1Low = {-0.008, -0.0035}; - const DetectorArray<double> m_bkgQuad1Mid = {-0.005, -0.0025}; - const DetectorArray<double> m_bkgQuad1High = {-0.003, -0.002}; - const DetectorArray<double> m_bkgQuad2Low = {0.0035, 0.002}; - const DetectorArray<double> m_bkgQuad2High = {0.008, 0.0035}; + const DetectorArray<double> m_bkgQuad1Low = { -0.008, -0.0035 }; + const DetectorArray<double> m_bkgQuad1Mid = { -0.005, -0.0025 }; + const DetectorArray<double> m_bkgQuad1High = { -0.003, -0.002 }; + const DetectorArray<double> m_bkgQuad2Low = { 0.0035, 0.002 }; + const DetectorArray<double> m_bkgQuad2High = { 0.008, 0.0035 }; /// Lock for main event processing mutable std::mutex m_mutex; // CK theta histograms for photon counting - Hist::DetArray<std::unique_ptr<TH1D>> h_ckPhotonYield = {{}}; + Hist::DetArray<std::unique_ptr<TH1D>> h_ckPhotonYield = { {} }; // Current active run-by-run histograms - mutable Hist::DetArray<RunByRunHists<Hist::H1D<>>> h_ckThetaRec_run = {{}}; - mutable Hist::DetArray<RunByRunHists<Hist::H1D<>>> h_ckThetaExp_run = {{}}; - mutable Hist::DetArray<RunByRunHists<Hist::H1D<>>> h_ckThetaRes_run = {{}}; - mutable Hist::DetArray<RunByRunHists<Hist::H1D<>>> h_tkPtot_run = {{}}; - mutable Hist::DetArray<QuadArray<RunByRunHists<Hist::H1D<>>>> h_ckThetaRes_quadrants_run = {{{}}}; - mutable Hist::DetArray<RunByRunHists<Hist::H2D<>>> h_tkEntryXY_run = {{}}; - mutable Hist::DetArray<RunByRunHists<Hist::H1D<>>> h_ckPhotonSig_run = {{}}; - mutable Hist::DetArray<QuadArray<RunByRunHists<Hist::H1D<>>>> h_ckPhotonSig_quadrants_run = {{{}}}; - mutable Hist::DetArray<RunByRunHists<Hist::H1D<unsigned int>>> h_ckPhotonSigNoSub_run = {{}}; - mutable Hist::DetArray<QuadArray<RunByRunHists<Hist::H1D<unsigned int>>>> h_ckPhotonSigNoSub_quadrants_run = {{{}}}; - mutable Hist::DetArray<RunByRunHists<Hist::H1D<unsigned int>>> h_ckPhotonBckLow_run = {{}}; - mutable Hist::DetArray<QuadArray<RunByRunHists<Hist::H1D<unsigned int>>>> h_ckPhotonBckLow_quadrants_run = {{{}}}; - mutable Hist::DetArray<RunByRunHists<Hist::H1D<unsigned int>>> h_ckPhotonBckHigh_run = {{}}; - mutable Hist::DetArray<QuadArray<RunByRunHists<Hist::H1D<unsigned int>>>> h_ckPhotonBckHigh_quadrants_run = {{{}}}; - mutable Hist::DetArray<RunByRunHists<Hist::H2D<>>> h_tkSegMomVSPhotonYield_run = {{}}; - mutable Hist::DetArray<RunByRunHists<Hist::H2D<>>> h_tkpathLengthVSPhotonYield_run = {{}}; + mutable Hist::DetArray<RunByRunHists<Hist::H1D<>>> h_ckThetaRec_run = { {} }; + mutable Hist::DetArray<RunByRunHists<Hist::H1D<>>> h_ckThetaExp_run = { {} }; + mutable Hist::DetArray<RunByRunHists<Hist::H1D<>>> h_ckThetaRes_run = { {} }; + mutable Hist::DetArray<RunByRunHists<Hist::H1D<>>> h_tkPtot_run = { {} }; + mutable Hist::DetArray<QuadArray<RunByRunHists<Hist::H1D<>>>> h_ckThetaRes_quadrants_run = { { {} } }; + mutable Hist::DetArray<RunByRunHists<Hist::H2D<>>> h_tkEntryXY_run = { {} }; + mutable Hist::DetArray<RunByRunHists<Hist::H1D<>>> h_ckPhotonSig_run = { {} }; + mutable Hist::DetArray<QuadArray<RunByRunHists<Hist::H1D<>>>> h_ckPhotonSig_quadrants_run = { { {} } }; + mutable Hist::DetArray<RunByRunHists<Hist::H1D<unsigned int>>> h_ckPhotonSigNoSub_run = { {} }; + mutable Hist::DetArray<QuadArray<RunByRunHists<Hist::H1D<unsigned int>>>> h_ckPhotonSigNoSub_quadrants_run = { + { {} } }; + mutable Hist::DetArray<RunByRunHists<Hist::H1D<unsigned int>>> h_ckPhotonBckLow_run = { {} }; + mutable Hist::DetArray<QuadArray<RunByRunHists<Hist::H1D<unsigned int>>>> h_ckPhotonBckLow_quadrants_run = { + { {} } }; + mutable Hist::DetArray<RunByRunHists<Hist::H1D<unsigned int>>> h_ckPhotonBckHigh_run = { {} }; + mutable Hist::DetArray<QuadArray<RunByRunHists<Hist::H1D<unsigned int>>>> h_ckPhotonBckHigh_quadrants_run = { + { {} } }; + mutable Hist::DetArray<RunByRunHists<Hist::H2D<>>> h_tkSegMomVSPhotonYield_run = { {} }; + mutable Hist::DetArray<RunByRunHists<Hist::H2D<>>> h_tkpathLengthVSPhotonYield_run = { {} }; }; } // namespace Rich::Future::Rec::Counting @@ -357,7 +360,7 @@ void PhotonCounting::operator()( const LHCb::ODIN& odin, const SIMDCherenkovPhoton::Vector& photons ) const { // Only one thread can be running from this point on - std::scoped_lock lock{m_mutex}; + std::scoped_lock lock{ m_mutex }; // First event printout if ( 0 == m_nEvts ) { @@ -415,15 +418,15 @@ void PhotonCounting::operator()( const LHCb::ODIN& odin, // Photon level parameters // background subtraction estimation regions - DetectorArray<unsigned int> bkgNLinB1 = {0, 0}; - DetectorArray<unsigned int> bkgNLinB2 = {0, 0}; - DetectorArray<unsigned int> bkgNLinSig = {0, 0}; + DetectorArray<unsigned int> bkgNLinB1 = { 0, 0 }; + DetectorArray<unsigned int> bkgNLinB2 = { 0, 0 }; + DetectorArray<unsigned int> bkgNLinSig = { 0, 0 }; // background subtraction estimation regions - quadratic - DetectorArray<double> bkgNQuadB1 = {0, 0}; - DetectorArray<double> bkgNQuadB2 = {0, 0}; - DetectorArray<double> bkgNQuadB3 = {0, 0}; - DetectorArray<double> bkgNQuadSig = {0, 0}; - DetectorArray<bool> valid_entry = {false, false}; + DetectorArray<double> bkgNQuadB1 = { 0, 0 }; + DetectorArray<double> bkgNQuadB2 = { 0, 0 }; + DetectorArray<double> bkgNQuadB3 = { 0, 0 }; + DetectorArray<double> bkgNQuadSig = { 0, 0 }; + DetectorArray<bool> valid_entry = { false, false }; // loop over photons for this track for ( const auto photIn : sumTk.photonIndices() ) { @@ -492,7 +495,7 @@ void PhotonCounting::operator()( const LHCb::ODIN& odin, const auto seg_x = seg.entryPoint().x(); const auto seg_y = seg.entryPoint().y(); const auto q = ( seg_x > 0 ? ( seg_y > 0 ? Quadrant::Q0 : Quadrant::Q2 ) // - : ( seg_y > 0 ? Quadrant::Q1 : Quadrant::Q3 ) ); + : ( seg_y > 0 ? Quadrant::Q1 : Quadrant::Q3 ) ); fillRunByRunHist( h_tkEntryXY_run[rich], seg_x, seg_y ); // Loop over scalar entries in SIMD photon for ( std::size_t i = 0; i < SIMDCherenkovPhoton::SIMDFP::Size; ++i ) { @@ -669,8 +672,8 @@ void PhotonCounting::runPhotonCounting( const std::string& type ) const { // Get the result if ( radPhotonYieldHist->GetEntries() > 0 ) { - const PhotonYield yield{radPhotonYieldHist->GetMean(), - radPhotonYieldHist->GetRMS() / std::sqrt( radPhotonYieldHist->GetEntries() )}; + const PhotonYield yield{ radPhotonYieldHist->GetMean(), + radPhotonYieldHist->GetRMS() / std::sqrt( radPhotonYieldHist->GetEntries() ) }; // info message for logging calib_message( MSG::INFO, rad, " photon yield for Run ", runNumber(), " = ", yield ); // If enabled write to photon yield summary diff --git a/Rich/RichOnlineCalib/src/RichRefIndexCalib.cpp b/Rich/RichOnlineCalib/src/RichRefIndexCalib.cpp index 52ab6e393a682f95df61797d9e76b61a342e52c3..6c3af6c8fc0b77b008a5d5e0e97f7d090e62e27f 100644 --- a/Rich/RichOnlineCalib/src/RichRefIndexCalib.cpp +++ b/Rich/RichOnlineCalib/src/RichRefIndexCalib.cpp @@ -84,14 +84,14 @@ namespace Rich::Future::Rec::Calib { /// Standard constructor RefIndexCalib( const std::string& name, ISvcLocator* pSvcLocator ) : Consumer( name, pSvcLocator, - {KeyValue{"ODINLocation", LHCb::ODINLocation::Default}, - KeyValue{"TracksLocation", LHCb::TrackLocation::Default}, - KeyValue{"SummaryTracksLocation", Summary::TESLocations::Tracks}, - KeyValue{"PhotonToParentsLocation", Relations::PhotonToParentsLocation::Default}, - KeyValue{"TrackSegmentsLocation", LHCb::RichTrackSegmentLocation::Default}, - KeyValue{"CherenkovAnglesLocation", CherenkovAnglesLocation::Signal}, - KeyValue{"CherenkovPhotonLocation", SIMDCherenkovPhotonLocation::Default}, - KeyValue{"ScaleFactorsCache", DeRichLocations::derivedCondition( name + "-DataCache" )}} ) { + { KeyValue{ "ODINLocation", LHCb::ODINLocation::Default }, + KeyValue{ "TracksLocation", LHCb::TrackLocation::Default }, + KeyValue{ "SummaryTracksLocation", Summary::TESLocations::Tracks }, + KeyValue{ "PhotonToParentsLocation", Relations::PhotonToParentsLocation::Default }, + KeyValue{ "TrackSegmentsLocation", LHCb::RichTrackSegmentLocation::Default }, + KeyValue{ "CherenkovAnglesLocation", CherenkovAnglesLocation::Signal }, + KeyValue{ "CherenkovPhotonLocation", SIMDCherenkovPhotonLocation::Default }, + KeyValue{ "ScaleFactorsCache", DeRichLocations::derivedCondition( name + "-DataCache" ) } } ) { declareProperty( "nPolFull", m_ckFitter.params().RichNPol ); declareProperty( "StartNPol", m_ckFitter.params().RichStartPol ); @@ -131,13 +131,13 @@ namespace Rich::Future::Rec::Calib { Detector::Rich1::addConditionDerivation( this ); Detector::Rich2::addConditionDerivation( this ); addConditionDerivation( - {Detector::Rich1::DefaultConditionKey, // - Detector::Rich2::DefaultConditionKey}, // + { Detector::Rich1::DefaultConditionKey, // + Detector::Rich2::DefaultConditionKey }, // inputLocation<ScaleFactorsCache>(), // [parent = this]( const Detector::Rich1& r1, // const Detector::Rich2& r2 ) { - const ScaleFactorsCache scaleFs{ScaleFactor{r1.radiator().currentRefIndexScaleFactor(), 0.0}, - ScaleFactor{r2.radiator().currentRefIndexScaleFactor(), 0.0}}; + const ScaleFactorsCache scaleFs{ ScaleFactor{ r1.radiator().currentRefIndexScaleFactor(), 0.0 }, + ScaleFactor{ r2.radiator().currentRefIndexScaleFactor(), 0.0 } }; parent->calib_message( MSG::DEBUG, "Current Scalefactors : R1Gas=", scaleFs[Rich::Rich1], " R2Gas=", scaleFs[Rich::Rich2] ); return scaleFs; @@ -294,7 +294,7 @@ namespace Rich::Future::Rec::Calib { } } // active rad loop if ( !m_enableRunByRunHists ) { initExtraHists(); } - return StatusCode{ok}; + return StatusCode{ ok }; } private: @@ -378,83 +378,83 @@ namespace Rich::Future::Rec::Calib { // properties /// Minimum number of events for a calibration - Gaudi::Property<unsigned long long> m_minEventsForCalib{this, "MinEventsForCalib", 100}; + Gaudi::Property<unsigned long long> m_minEventsForCalib{ this, "MinEventsForCalib", 100 }; /// Time interval to send periodic calibration updates - Gaudi::Property<int> m_minTimeBetweenCalibs{this, "MinTimeBetweenCalibs", 16 * 60}; // 16 mins + Gaudi::Property<int> m_minTimeBetweenCalibs{ this, "MinTimeBetweenCalibs", 16 * 60 }; // 16 mins /// Time interval for failed fit retries - Gaudi::Property<int> m_failedFitRetryPeriod{this, "FailedFitRetryPeriod", 20}; // 20 secs + Gaudi::Property<int> m_failedFitRetryPeriod{ this, "FailedFitRetryPeriod", 20 }; // 20 secs /// Max number of failed fit retries - Gaudi::Property<unsigned int> m_maxfailedFitRetries{this, "MaxFailedFitRetries", 10}; + Gaudi::Property<unsigned int> m_maxfailedFitRetries{ this, "MaxFailedFitRetries", 10 }; /// RICH1 task name - Gaudi::Property<std::string> m_Rich1TaskName{this, "Rich1TaskName", "Rich1/Environment/Gas"}; + Gaudi::Property<std::string> m_Rich1TaskName{ this, "Rich1TaskName", "Rich1/Environment/Gas" }; /// RICH2 task name - Gaudi::Property<std::string> m_Rich2TaskName{this, "Rich2TaskName", "Rich2/Environment/Gas"}; + Gaudi::Property<std::string> m_Rich2TaskName{ this, "Rich2TaskName", "Rich2/Environment/Gas" }; /// RICH1 name for n-1 scale factor DIM service - Gaudi::Property<std::string> m_Rich1ScaleTaskName{this, "Rich1ScaleTaskName", "Rich1RefIndex"}; + Gaudi::Property<std::string> m_Rich1ScaleTaskName{ this, "Rich1ScaleTaskName", "Rich1RefIndex" }; /// RICH2 name for n-1 scale factor DIM service - Gaudi::Property<std::string> m_Rich2ScaleTaskName{this, "Rich2ScaleTaskName", "Rich2RefIndex"}; + Gaudi::Property<std::string> m_Rich2ScaleTaskName{ this, "Rich2ScaleTaskName", "Rich2RefIndex" }; /// Flag to turn on the creation of a Preliminary calibration for each run - Gaudi::Property<bool> m_createPrelimCalib{this, "CreatePreliminaryCalibration", true}; + Gaudi::Property<bool> m_createPrelimCalib{ this, "CreatePreliminaryCalibration", true }; /// The ROOT file directory to use for the calibration (the Gaudi Monitor) - Gaudi::Property<std::string> m_HistBase{this, "HistBase", "RICH/RiCKResLongTight/"}; + Gaudi::Property<std::string> m_HistBase{ this, "HistBase", "RICH/RiCKResLongTight/" }; /// The histogram ID to use - Gaudi::Property<std::string> m_ResPlot{this, "ResPlot", "ckResAll"}; + Gaudi::Property<std::string> m_ResPlot{ this, "ResPlot", "ckResAll" }; /// CK Resolution fitter - Rich::Rec::CKResolutionFitter m_ckFitter{this}; + Rich::Rec::CKResolutionFitter m_ckFitter{ this }; /// slope from the shift - Gaudi::Property<std::array<double, 2>> m_RefIndexSlope{this, "RefIndexSlope", {38.1, 65.25}}; + Gaudi::Property<std::array<double, 2>> m_RefIndexSlope{ this, "RefIndexSlope", { 38.1, 65.25 } }; /// Precision for YML file parameters - Gaudi::Property<unsigned int> m_Precision{this, "Precision", 8}; + Gaudi::Property<unsigned int> m_Precision{ this, "Precision", 8 }; /// LHCB DB to write to path - Gaudi::Property<std::string> m_conditionsDbPath{this, "conditionsDbPath", "/group/online/hlt/conditions.run3"}; + Gaudi::Property<std::string> m_conditionsDbPath{ this, "conditionsDbPath", "/group/online/hlt/conditions.run3" }; /// Create direct run conditions - Gaudi::Property<bool> m_makeDBRunFile{this, "MakeDBRunFile", false}; + Gaudi::Property<bool> m_makeDBRunFile{ this, "MakeDBRunFile", false }; /// log file to list all previous YML versions - Gaudi::Property<std::string> m_ymlVersionLog{this, "ymlVersionLog", "version.txt"}; + Gaudi::Property<std::string> m_ymlVersionLog{ this, "ymlVersionLog", "version.txt" }; /// log file for previous scale factors - Gaudi::Property<std::string> m_RefIndexSFLog{this, "RefIndexSFLog", "refIndexSF.txt"}; + Gaudi::Property<std::string> m_RefIndexSFLog{ this, "RefIndexSFLog", "refIndexSF.txt" }; /// DIM Summary file name - Gaudi::Property<std::string> m_dimSummaryFile{this, "DIMSummaryFile", "DIMUpdateSummary.txt"}; + Gaudi::Property<std::string> m_dimSummaryFile{ this, "DIMSummaryFile", "DIMUpdateSummary.txt" }; /// Flag to turn on/off publishing to DIM - Gaudi::Property<bool> m_disableDIMpublish{this, "DisableDIMPublish", false}; + Gaudi::Property<bool> m_disableDIMpublish{ this, "DisableDIMPublish", false }; /// maximum cached calibrations to allow in a row - Gaudi::Property<unsigned int> m_maxCachedCalibs{this, "MaxCachedCalibsInARow", 5}; + Gaudi::Property<unsigned int> m_maxCachedCalibs{ this, "MaxCachedCalibsInARow", 5 }; /// Use a running average for the scale factors ? - Gaudi::Property<bool> m_useRunningAv{this, "UseRunningAverage", true}; + Gaudi::Property<bool> m_useRunningAv{ this, "UseRunningAverage", true }; /// Allow calibrations during stop() - Gaudi::Property<bool> m_allowStopCalib{this, "AllowCalibAtStop", true}; + Gaudi::Property<bool> m_allowStopCalib{ this, "AllowCalibAtStop", true }; /// Min CK res for good fit - Gaudi::Property<DetectorArray<double>> m_minCKTRes{this, "MinCKThetaRes", {0.0005, 0.0002}}; + Gaudi::Property<DetectorArray<double>> m_minCKTRes{ this, "MinCKThetaRes", { 0.0005, 0.0002 } }; /// Max CK res for good fit - Gaudi::Property<DetectorArray<double>> m_maxCKTRes{this, "MaxCKThetaRes", {0.0020, 0.0010}}; + Gaudi::Property<DetectorArray<double>> m_maxCKTRes{ this, "MaxCKThetaRes", { 0.0020, 0.0010 } }; /// Max tolerance on fitted mean value - Gaudi::Property<DetectorArray<double>> m_maxCKTMean{this, "MaxCKThetaMean", {0.001, 0.0006}}; + Gaudi::Property<DetectorArray<double>> m_maxCKTMean{ this, "MaxCKThetaMean", { 0.001, 0.0006 } }; /// Override for run number (e.g. for testing to merge runs) - Gaudi::Property<unsigned int> m_forcedRunNumber{this, "ForcedRunNumber", 0}; + Gaudi::Property<unsigned int> m_forcedRunNumber{ this, "ForcedRunNumber", 0 }; private: // cached datax @@ -463,30 +463,30 @@ namespace Rich::Future::Rec::Calib { mutable std::mutex m_mutex; // CK theta histograms for calibration fits - Hist::DetArray<std::unique_ptr<TH1D>> h_ckResAll = {{}}; - Hist::DetArray<QuadArray<std::unique_ptr<TH1D>>> h_ckResAllQuads = {{{}}}; + Hist::DetArray<std::unique_ptr<TH1D>> h_ckResAll = { {} }; + Hist::DetArray<QuadArray<std::unique_ptr<TH1D>>> h_ckResAllQuads = { { {} } }; // Monitoring histos - mutable Hist::DetArray<RunByRunHists<Hist::H1D<>>> h_ckThetaRec_run = {{}}; - mutable Hist::DetArray<RunByRunHists<Hist::H1D<>>> h_ckThetaExp_run = {{}}; - mutable Hist::DetArray<RunByRunHists<Hist::H1D<>>> h_ckThetaRes_run = {{}}; - mutable Hist::DetArray<QuadArray<RunByRunHists<Hist::H1D<>>>> h_ckThetaRes_quads_run = {{{}}}; - mutable Hist::DetArray<RunByRunHists<Hist::H2D<>>> h_tkEntryXY_run = {{}}; + mutable Hist::DetArray<RunByRunHists<Hist::H1D<>>> h_ckThetaRec_run = { {} }; + mutable Hist::DetArray<RunByRunHists<Hist::H1D<>>> h_ckThetaExp_run = { {} }; + mutable Hist::DetArray<RunByRunHists<Hist::H1D<>>> h_ckThetaRes_run = { {} }; + mutable Hist::DetArray<QuadArray<RunByRunHists<Hist::H1D<>>>> h_ckThetaRes_quads_run = { { {} } }; + mutable Hist::DetArray<RunByRunHists<Hist::H2D<>>> h_tkEntryXY_run = { {} }; /// Publishing service IPublishSvc* m_pPublishSvc = nullptr; /// String to publish for new calibrations for RICH1 - mutable std::string m_Rich1PubString{""}; + mutable std::string m_Rich1PubString{ "" }; /// String to publish for new calibrations for RICH2 - mutable std::string m_Rich2PubString{""}; + mutable std::string m_Rich2PubString{ "" }; /// The RICH1 scale factor value to publish - mutable double m_Rich1RefIndex{1.0}; + mutable double m_Rich1RefIndex{ 1.0 }; /// The RICH2 scale factor value to publish - mutable double m_Rich2RefIndex{1.0}; + mutable double m_Rich2RefIndex{ 1.0 }; /** Keep a count of the number of calibrations in a row, per radiator, * for which a cached value from a previous run is used */ @@ -499,7 +499,7 @@ namespace Rich::Future::Rec::Calib { mutable ScaleFactorsCache m_scaleFs; /// Current failed fit count - mutable DetectorArray<unsigned int> m_failedFitCount{{0, 0}}; + mutable DetectorArray<unsigned int> m_failedFitCount{ { 0, 0 } }; private: /// Fit Result object @@ -554,7 +554,7 @@ namespace Rich::Future::Rec::Calib { const auto newScale = m_scaleFs[iR].value * scaleFcorrection; const auto scaleFcorrection_err = ( shift_err * m_RefIndexSlope[iR] ); const auto newScale_err = m_scaleFs[iR].value * scaleFcorrection_err; - ScaleFactor scale{newScale, newScale_err}; + ScaleFactor scale{ newScale, newScale_err }; // apply a running average ? if ( m_useRunningAv.value() ) { @@ -647,9 +647,10 @@ namespace Rich::Future::Rec::Calib { /// Radiator name to task name inline auto radToTaskName( const std::string& rad ) const noexcept { - const std::string task = ( "Rich1Gas" == rad ? "Rich1/Calib" : // - "Rich2Gas" == rad ? "Rich2/Calib" : // - "" ); + const std::string task = ( "Rich1Gas" == rad ? "Rich1/Calib" : // + "Rich2Gas" == rad ? "Rich2/Calib" + : // + "" ); if ( task.empty() ) { calib_message( MSG::WARNING, "Unknown radiator '", rad, "'" ); } return task; } @@ -671,7 +672,7 @@ void RefIndexCalib::operator()( const LHCb::ODIN& odin, const ScaleFactorsCache& scaleFactors ) const { // Only one thread can be running from this point on - std::scoped_lock lock{m_mutex}; + std::scoped_lock lock{ m_mutex }; // First event printout if ( 0 == m_nEvts ) { @@ -793,7 +794,7 @@ void RefIndexCalib::operator()( const LHCb::ODIN& odin, const auto seg_x = seg.entryPoint().x(); const auto seg_y = seg.entryPoint().y(); const auto q = ( seg_x > 0 ? ( seg_y > 0 ? Quadrant::Q0 : Quadrant::Q2 ) // - : ( seg_y > 0 ? Quadrant::Q1 : Quadrant::Q3 ) ); + : ( seg_y > 0 ? Quadrant::Q1 : Quadrant::Q3 ) ); fillRunByRunHist( h_tkEntryXY_run[rich], seg_x, seg_y ); // Loop over scalar entries in SIMD photon @@ -923,7 +924,7 @@ void RefIndexCalib::runCalibration( const std::string& type ) const { hasNewScaleF = true; } else { ++m_cachedCalibCount[rad]; // Count cached calibrations - scale = ScaleFactor{getLastRefIndexSF( rad ).first, 0.0}; + scale = ScaleFactor{ getLastRefIndexSF( rad ).first, 0.0 }; calib_message( MSG::WARNING, "Fit FAILED. Using scale from previous run ", scale ); // increment failed fit count for this radiator ++m_failedFitCount[iRich]; @@ -936,7 +937,7 @@ void RefIndexCalib::runCalibration( const std::string& type ) const { } else { // not enough statistics, take the one from previous run ++m_cachedCalibCount[rad]; // Count cached calibrations - scale = ScaleFactor{getLastRefIndexSF( rad ).first, 0.0}; + scale = ScaleFactor{ getLastRefIndexSF( rad ).first, 0.0 }; calib_message( MSG::INFO, "Not enough statistics for ", rad, " -> Using scale from previous run ", scale ); } @@ -1000,7 +1001,7 @@ void RefIndexCalib::runCalibration( const std::string& type ) const { std::pair<double, std::time_t> RefIndexCalib::getLastRefIndexSF( const std::string& rad ) const { - std::pair<double, std::time_t> scale_time{0, 0}; + std::pair<double, std::time_t> scale_time{ 0, 0 }; auto& scale = scale_time.first; auto& write_time = scale_time.second; unsigned int run = 0; diff --git a/Rich/RichOnlineMonitors/src/RichBXTypeMonitor.cpp b/Rich/RichOnlineMonitors/src/RichBXTypeMonitor.cpp index 869f9ff4f76228e4dfe195b060a8b58675fb3cb3..5132d9e6151db9562b68e12226179eaf7a50db16 100644 --- a/Rich/RichOnlineMonitors/src/RichBXTypeMonitor.cpp +++ b/Rich/RichOnlineMonitors/src/RichBXTypeMonitor.cpp @@ -51,28 +51,28 @@ namespace Rich::Future::Mon { BXTypeMonitors( const std::string& name, ISvcLocator* pSvcLocator ) : Consumer( name, pSvcLocator, // input data - {KeyValue{"ODINLocation", LHCb::ODINLocation::Default}, - KeyValue{"DecodedDataLocation", DAQ::DecodedDataLocation::Default}} ) {} + { KeyValue{ "ODINLocation", LHCb::ODINLocation::Default }, + KeyValue{ "DecodedDataLocation", DAQ::DecodedDataLocation::Default } } ) {} private: // histograms /// Pixel based hit map - mutable Hist::DetArray<Hist::H2D<>> h_pixelMapBeamCrossing = {{}}; - mutable Hist::DetArray<Hist::H2D<>> h_pixelMap2BeamCrossing = {{}}; - mutable Hist::DetArray<Hist::H2D<>> h_pixelMapBeamGas = {{}}; - mutable Hist::DetArray<Hist::H2D<>> h_pixelMap2BeamGas = {{}}; - mutable Hist::DetArray<Hist::H2D<>> h_pixelMapEmptyEmpty = {{}}; - mutable Hist::DetArray<Hist::H2D<>> h_pixelMap2EmptyEmpty = {{}}; + mutable Hist::DetArray<Hist::H2D<>> h_pixelMapBeamCrossing = { {} }; + mutable Hist::DetArray<Hist::H2D<>> h_pixelMap2BeamCrossing = { {} }; + mutable Hist::DetArray<Hist::H2D<>> h_pixelMapBeamGas = { {} }; + mutable Hist::DetArray<Hist::H2D<>> h_pixelMap2BeamGas = { {} }; + mutable Hist::DetArray<Hist::H2D<>> h_pixelMapEmptyEmpty = { {} }; + mutable Hist::DetArray<Hist::H2D<>> h_pixelMap2EmptyEmpty = { {} }; // nHits - mutable Hist::DetArray<Hist::H1D<>> h_nHitsBXIDBeamCrossing = {{}}; - mutable Hist::DetArray<Hist::PanelArray<Hist::H1D<>>> h_nHitsBXIDBeamCrossing_side = {{}}; - mutable Hist::DetArray<Hist::H1D<>> h_nHitsBXIDBeamGas = {{}}; - mutable Hist::DetArray<Hist::H1D<>> h_nHitsBXIDEmptyEmpty = {{}}; + mutable Hist::DetArray<Hist::H1D<>> h_nHitsBXIDBeamCrossing = { {} }; + mutable Hist::DetArray<Hist::PanelArray<Hist::H1D<>>> h_nHitsBXIDBeamCrossing_side = { {} }; + mutable Hist::DetArray<Hist::H1D<>> h_nHitsBXIDBeamGas = { {} }; + mutable Hist::DetArray<Hist::H1D<>> h_nHitsBXIDEmptyEmpty = { {} }; // MaPmts hits (for occupancy) - mutable Hist::DetArray<Hist::WH1D<>> h_Occupancy_bb = {{}}; - mutable Hist::DetArray<Hist::WH1D<>> h_Occupancy_ee = {{}}; - mutable Hist::DetArray<Hist::WH1D<>> h_Occupancy_ebbe = {{}}; + mutable Hist::DetArray<Hist::WH1D<>> h_Occupancy_bb = { {} }; + mutable Hist::DetArray<Hist::WH1D<>> h_Occupancy_ee = { {} }; + mutable Hist::DetArray<Hist::WH1D<>> h_Occupancy_ebbe = { {} }; private: static constexpr float weight_PMThit = 1.0 / 64.0; @@ -164,7 +164,7 @@ namespace Rich::Future::Mon { "nHitsBXIDBeamCrossing_side" ); } } - return StatusCode{ok}; + return StatusCode{ ok }; } public: @@ -233,16 +233,16 @@ namespace Rich::Future::Mon { for ( int i = 0; i < 2; ++i ) { for ( int j = 0; j < 2; ++j ) { if ( odin.bunchCrossingType() == LHCb::ODINImplementation::v7::ODIN::BXTypes::BeamCrossing ) { - ++hb_pixelMapBeamCrossing[rich][{iGlobalX + i, iGlobalY + j}]; - ++hb_pixelMap2BeamCrossing[rich][{iGlobalX2 + i, iGlobalY + j}]; + ++hb_pixelMapBeamCrossing[rich][{ iGlobalX + i, iGlobalY + j }]; + ++hb_pixelMap2BeamCrossing[rich][{ iGlobalX2 + i, iGlobalY + j }]; } else if ( odin.bunchCrossingType() == LHCb::ODINImplementation::v7::ODIN::BXTypes::Beam1 || odin.bunchCrossingType() == LHCb::ODINImplementation::v7::ODIN::BXTypes::Beam2 ) { - ++hb_pixelMapBeamGas[rich][{iGlobalX + i, iGlobalY + j}]; - ++hb_pixelMap2BeamGas[rich][{iGlobalX2 + i, iGlobalY + j}]; + ++hb_pixelMapBeamGas[rich][{ iGlobalX + i, iGlobalY + j }]; + ++hb_pixelMap2BeamGas[rich][{ iGlobalX2 + i, iGlobalY + j }]; } else if ( odin.bunchCrossingType() == LHCb::ODINImplementation::v7::ODIN::BXTypes::NoBeam ) { - ++hb_pixelMapEmptyEmpty[rich][{iGlobalX + i, iGlobalY + j}]; - ++hb_pixelMap2EmptyEmpty[rich][{iGlobalX2 + i, iGlobalY + j}]; + ++hb_pixelMapEmptyEmpty[rich][{ iGlobalX + i, iGlobalY + j }]; + ++hb_pixelMap2EmptyEmpty[rich][{ iGlobalX2 + i, iGlobalY + j }]; } } } @@ -255,16 +255,16 @@ namespace Rich::Future::Mon { auto convertX = []( const auto x ) { return ( -1 * ( x + 3 - 89 - 21 ) ) + 89 + 21; }; auto convertY = []( const auto y ) { return -( y + 1 ); }; if ( odin.bunchCrossingType() == LHCb::ODINImplementation::v7::ODIN::BXTypes::BeamCrossing ) { - ++hb_pixelMapBeamCrossing[rich][{convertY( iGlobalY ), convertX( iGlobalX )}]; - ++hb_pixelMap2BeamCrossing[rich][{convertY( iGlobalY ), convertX( iGlobalX2 )}]; + ++hb_pixelMapBeamCrossing[rich][{ convertY( iGlobalY ), convertX( iGlobalX ) }]; + ++hb_pixelMap2BeamCrossing[rich][{ convertY( iGlobalY ), convertX( iGlobalX2 ) }]; } else if ( odin.bunchCrossingType() == LHCb::ODINImplementation::v7::ODIN::BXTypes::Beam1 || odin.bunchCrossingType() == LHCb::ODINImplementation::v7::ODIN::BXTypes::Beam2 ) { - ++hb_pixelMapBeamGas[rich][{convertY( iGlobalY ), convertX( iGlobalX )}]; - ++hb_pixelMap2BeamGas[rich][{convertY( iGlobalY ), convertX( iGlobalX2 )}]; + ++hb_pixelMapBeamGas[rich][{ convertY( iGlobalY ), convertX( iGlobalX ) }]; + ++hb_pixelMap2BeamGas[rich][{ convertY( iGlobalY ), convertX( iGlobalX2 ) }]; } else if ( odin.bunchCrossingType() == LHCb::ODINImplementation::v7::ODIN::BXTypes::NoBeam ) { - ++hb_pixelMapEmptyEmpty[rich][{convertY( iGlobalY ), convertX( iGlobalX )}]; - ++hb_pixelMap2EmptyEmpty[rich][{convertY( iGlobalY ), convertX( iGlobalX2 )}]; + ++hb_pixelMapEmptyEmpty[rich][{ convertY( iGlobalY ), convertX( iGlobalX ) }]; + ++hb_pixelMap2EmptyEmpty[rich][{ convertY( iGlobalY ), convertX( iGlobalX2 ) }]; } } else { @@ -274,31 +274,31 @@ namespace Rich::Future::Mon { auto convertX = []( const auto x ) { return x + 3; }; auto convertY = []( const auto y ) { return y + 1; }; if ( odin.bunchCrossingType() == LHCb::ODINImplementation::v7::ODIN::BXTypes::BeamCrossing ) { - ++hb_pixelMapBeamCrossing[rich][{convertY( iGlobalY ), convertX( iGlobalX )}]; - ++hb_pixelMap2BeamCrossing[rich][{convertY( iGlobalY ), convertX( iGlobalX2 )}]; + ++hb_pixelMapBeamCrossing[rich][{ convertY( iGlobalY ), convertX( iGlobalX ) }]; + ++hb_pixelMap2BeamCrossing[rich][{ convertY( iGlobalY ), convertX( iGlobalX2 ) }]; } else if ( odin.bunchCrossingType() == LHCb::ODINImplementation::v7::ODIN::BXTypes::Beam1 || odin.bunchCrossingType() == LHCb::ODINImplementation::v7::ODIN::BXTypes::Beam2 ) { - ++hb_pixelMapBeamGas[rich][{convertY( iGlobalY ), convertX( iGlobalX )}]; - ++hb_pixelMap2BeamGas[rich][{convertY( iGlobalY ), convertX( iGlobalX2 )}]; + ++hb_pixelMapBeamGas[rich][{ convertY( iGlobalY ), convertX( iGlobalX ) }]; + ++hb_pixelMap2BeamGas[rich][{ convertY( iGlobalY ), convertX( iGlobalX2 ) }]; } else if ( odin.bunchCrossingType() == LHCb::ODINImplementation::v7::ODIN::BXTypes::NoBeam ) { - ++hb_pixelMapEmptyEmpty[rich][{convertY( iGlobalY ), convertX( iGlobalX )}]; - ++hb_pixelMap2EmptyEmpty[rich][{convertY( iGlobalY ), convertX( iGlobalX2 )}]; + ++hb_pixelMapEmptyEmpty[rich][{ convertY( iGlobalY ), convertX( iGlobalX ) }]; + ++hb_pixelMap2EmptyEmpty[rich][{ convertY( iGlobalY ), convertX( iGlobalX2 ) }]; } } } else { auto convertX = []( const auto x ) { return x + 1; }; auto convertY = []( const auto y ) { return y; }; if ( odin.bunchCrossingType() == LHCb::ODINImplementation::v7::ODIN::BXTypes::BeamCrossing ) { - ++hb_pixelMapBeamCrossing[rich][{convertX( iGlobalX ), convertY( iGlobalY )}]; - ++hb_pixelMap2BeamCrossing[rich][{convertX( iGlobalX2 ), convertY( iGlobalY )}]; + ++hb_pixelMapBeamCrossing[rich][{ convertX( iGlobalX ), convertY( iGlobalY ) }]; + ++hb_pixelMap2BeamCrossing[rich][{ convertX( iGlobalX2 ), convertY( iGlobalY ) }]; } else if ( odin.bunchCrossingType() == LHCb::ODINImplementation::v7::ODIN::BXTypes::Beam1 || odin.bunchCrossingType() == LHCb::ODINImplementation::v7::ODIN::BXTypes::Beam2 ) { - ++hb_pixelMapBeamGas[rich][{convertX( iGlobalX ), convertY( iGlobalY )}]; - ++hb_pixelMap2BeamGas[rich][{convertX( iGlobalX2 ), convertY( iGlobalY )}]; + ++hb_pixelMapBeamGas[rich][{ convertX( iGlobalX ), convertY( iGlobalY ) }]; + ++hb_pixelMap2BeamGas[rich][{ convertX( iGlobalX2 ), convertY( iGlobalY ) }]; } else if ( odin.bunchCrossingType() == LHCb::ODINImplementation::v7::ODIN::BXTypes::NoBeam ) { - ++hb_pixelMapEmptyEmpty[rich][{convertX( iGlobalX ), convertY( iGlobalY )}]; - ++hb_pixelMap2EmptyEmpty[rich][{convertX( iGlobalX2 ), convertY( iGlobalY )}]; + ++hb_pixelMapEmptyEmpty[rich][{ convertX( iGlobalX ), convertY( iGlobalY ) }]; + ++hb_pixelMap2EmptyEmpty[rich][{ convertX( iGlobalX2 ), convertY( iGlobalY ) }]; } } } diff --git a/Rich/RichOnlineMonitors/src/RichBankSizesMonitor.cpp b/Rich/RichOnlineMonitors/src/RichBankSizesMonitor.cpp index f808c45649bfa88b168f563231f60719b4c0e7a0..943e09b1faa243d12b21fb4c780f2fdb32046a6e 100644 --- a/Rich/RichOnlineMonitors/src/RichBankSizesMonitor.cpp +++ b/Rich/RichOnlineMonitors/src/RichBankSizesMonitor.cpp @@ -49,7 +49,7 @@ namespace Rich::Future::Mon { BankSizes( const std::string& name, ISvcLocator* pSvcLocator ) : Consumer( name, pSvcLocator, // input data - {KeyValue{"RawBanks", "DAQ/RawBanks/Rich"}} ) { + { KeyValue{ "RawBanks", "DAQ/RawBanks/Rich" } } ) { setProperty( "NBins2DHistos", 500 ).ignore(); } @@ -60,10 +60,10 @@ namespace Rich::Future::Mon { private: /// Bank size vs sourceID histogram - mutable Hist::DetArray<Hist::PanelArray<Hist::H2D<>>> h_BankSizes = {{}}; + mutable Hist::DetArray<Hist::PanelArray<Hist::H2D<>>> h_BankSizes = { {} }; /// Invalid SourceID - mutable ErrorCounter m_invalidSourceID{this, "Invalid Tel40 SourceID"}; + mutable ErrorCounter m_invalidSourceID{ this, "Invalid Tel40 SourceID" }; protected: /// Pre-Book all histograms @@ -93,7 +93,7 @@ namespace Rich::Future::Mon { } } - return StatusCode{ok}; + return StatusCode{ ok }; } public: @@ -115,7 +115,7 @@ namespace Rich::Future::Mon { const std::size_t bankSize = bank->size(); const auto rich = tel40ID.rich(); const auto side = tel40ID.side(); - ++hb_BankSizes[rich][side][{source_id, bankSize}]; + ++hb_BankSizes[rich][side][{ source_id, bankSize }]; } } } diff --git a/Rich/RichOnlineMonitors/src/RichDataTuple.cpp b/Rich/RichOnlineMonitors/src/RichDataTuple.cpp index 925981a38b197141d6bb0fe30932e21162388a8d..b794e53121f0f1a7af0ba5e1384fe54e1ff3b816 100644 --- a/Rich/RichOnlineMonitors/src/RichDataTuple.cpp +++ b/Rich/RichOnlineMonitors/src/RichDataTuple.cpp @@ -81,12 +81,12 @@ namespace Rich::Future::Mon { DataTuple( const std::string& name, ISvcLocator* pSvcLocator ) : Consumer( name, pSvcLocator, // input data - {KeyValue{"ODINLocation", LHCb::ODINLocation::Default}, - KeyValue{"DecodedDataLocation", DAQ::DecodedDataLocation::Default}, - // input conditions data - KeyValue{"RichSmartIDs", Rich::Utils::RichSmartIDs::DefaultConditionKey}, - KeyValue{"Tel40CableMapping", DAQ::Tel40CableMapping::DefaultConditionKey + "-" + name}, - KeyValue{"PDMDBEncodeMapping", DAQ::PDMDBEncodeMapping::DefaultConditionKey + "-" + name}} ) {} + { KeyValue{ "ODINLocation", LHCb::ODINLocation::Default }, + KeyValue{ "DecodedDataLocation", DAQ::DecodedDataLocation::Default }, + // input conditions data + KeyValue{ "RichSmartIDs", Rich::Utils::RichSmartIDs::DefaultConditionKey }, + KeyValue{ "Tel40CableMapping", DAQ::Tel40CableMapping::DefaultConditionKey + "-" + name }, + KeyValue{ "PDMDBEncodeMapping", DAQ::PDMDBEncodeMapping::DefaultConditionKey + "-" + name } } ) {} /// Initialize StatusCode initialize() override { @@ -171,8 +171,8 @@ namespace Rich::Future::Mon { mutable std::mutex m_updateLock; // Tuple data - mutable std::uint32_t m_nHits{0}; - mutable Rich::DetectorArray<std::uint32_t> m_nHitsRich{{}}; + mutable std::uint32_t m_nHits{ 0 }; + mutable Rich::DetectorArray<std::uint32_t> m_nHitsRich{ {} }; mutable std::vector<std::uint16_t> m_rich; mutable std::vector<std::uint16_t> m_side; mutable std::vector<std::uint16_t> m_col; @@ -191,22 +191,22 @@ namespace Rich::Future::Mon { mutable std::vector<float> m_spaceGloY; mutable std::vector<float> m_spaceGloZ; mutable std::vector<std::uint32_t> m_tell40bit; - mutable unsigned long long m_evID{0}; - mutable unsigned int m_stepID{0}; - mutable unsigned int m_thDAC_ID{0}; - mutable unsigned int m_nBunch{0}; - mutable unsigned int m_slotID{0}; - mutable unsigned int m_taeWindow{0}; - mutable unsigned int m_taeCentral{0}; - mutable unsigned int m_taeFirst{0}; - unsigned int m_start_scan{0}; - unsigned int m_stop_scan{0}; - mutable unsigned int m_eventType{0}; - mutable unsigned int m_triggerType{0}; - mutable unsigned int m_bxidType{0}; - - Gaudi::Property<std::string> m_path{this, "OutputPath", "/hist/RICHMon/"}; - Gaudi::Property<unsigned int> m_number{this, "RunNumber", 0}; + mutable unsigned long long m_evID{ 0 }; + mutable unsigned int m_stepID{ 0 }; + mutable unsigned int m_thDAC_ID{ 0 }; + mutable unsigned int m_nBunch{ 0 }; + mutable unsigned int m_slotID{ 0 }; + mutable unsigned int m_taeWindow{ 0 }; + mutable unsigned int m_taeCentral{ 0 }; + mutable unsigned int m_taeFirst{ 0 }; + unsigned int m_start_scan{ 0 }; + unsigned int m_stop_scan{ 0 }; + mutable unsigned int m_eventType{ 0 }; + mutable unsigned int m_triggerType{ 0 }; + mutable unsigned int m_bxidType{ 0 }; + + Gaudi::Property<std::string> m_path{ this, "OutputPath", "/hist/RICHMon/" }; + Gaudi::Property<unsigned int> m_number{ this, "RunNumber", 0 }; public: /// Functional operator @@ -220,7 +220,7 @@ namespace Rich::Future::Mon { std::lock_guard lock( m_updateLock ); m_nHits = 0; - m_nHitsRich = {0, 0}; + m_nHitsRich = { 0, 0 }; m_rich.clear(); m_side.clear(); m_col.clear(); diff --git a/Rich/RichOnlineMonitors/src/RichHitMapsMonitor.cpp b/Rich/RichOnlineMonitors/src/RichHitMapsMonitor.cpp index a2f0e072750d6a7700061e54235dd18b05e1f936..41195a4777922c6fc3ee92927a6a25d8c10df17c 100644 --- a/Rich/RichOnlineMonitors/src/RichHitMapsMonitor.cpp +++ b/Rich/RichOnlineMonitors/src/RichHitMapsMonitor.cpp @@ -65,12 +65,12 @@ namespace Rich::Future::Mon { HitMaps( const std::string& name, ISvcLocator* pSvcLocator ) : Consumer( name, pSvcLocator, // input data - {KeyValue{"ODINLocation", LHCb::ODINLocation::Default}, - KeyValue{"DecodedDataLocation", DAQ::DecodedDataLocation::Default}, - // input conditions data - KeyValue{"RichSmartIDs", Rich::Utils::RichSmartIDs::DefaultConditionKey}, - KeyValue{"Tel40CableMapping", DAQ::Tel40CableMapping::DefaultConditionKey + "-" + name}, - KeyValue{"PDMDBEncodeMapping", DAQ::PDMDBEncodeMapping::DefaultConditionKey + "-" + name}} ) { + { KeyValue{ "ODINLocation", LHCb::ODINLocation::Default }, + KeyValue{ "DecodedDataLocation", DAQ::DecodedDataLocation::Default }, + // input conditions data + KeyValue{ "RichSmartIDs", Rich::Utils::RichSmartIDs::DefaultConditionKey }, + KeyValue{ "Tel40CableMapping", DAQ::Tel40CableMapping::DefaultConditionKey + "-" + name }, + KeyValue{ "PDMDBEncodeMapping", DAQ::PDMDBEncodeMapping::DefaultConditionKey + "-" + name } } ) { // setProperty( "HistoPrint", true ).ignore(); setProperty( "NBins2DHistos", 500 ).ignore(); } @@ -103,39 +103,39 @@ namespace Rich::Future::Mon { using PMTPlots = Hist::DetArray<PMTPlotsPerPanel>; /// Hit map for RICH, local coordinates - mutable Hist::DetArray<Hist::H2D<>> h_hitMaps = {{}}; + mutable Hist::DetArray<Hist::H2D<>> h_hitMaps = { {} }; /// Pixel based hit map - mutable Hist::DetArray<Hist::H2D<>> h_pixelMap = {{}}; - mutable Hist::DetArray<Hist::H2D<>> h_pixelMap2 = {{}}; + mutable Hist::DetArray<Hist::H2D<>> h_pixelMap = { {} }; + mutable Hist::DetArray<Hist::H2D<>> h_pixelMap2 = { {} }; /// Occupancy vs slotID - mutable Hist::DetArray<Hist::H2D<>> h_NHitsVsSlotID = {{}}; + mutable Hist::DetArray<Hist::H2D<>> h_NHitsVsSlotID = { {} }; /// Occupancy vs bunchID - mutable Hist::DetArray<Hist::H2D<>> h_NHitsVsBunchID = {{}}; + mutable Hist::DetArray<Hist::H2D<>> h_NHitsVsBunchID = { {} }; /// slotID vs tell40 bit - mutable Hist::DetArray<Hist::H2D<>> h_SlotIDVsBitID = {{}}; + mutable Hist::DetArray<Hist::H2D<>> h_SlotIDVsBitID = { {} }; /// bunchID vs tell40 link (i.e. 100 bits) - mutable Hist::DetArray<Hist::H2D<>> h_BunchIDVsBitID = {{}}; + mutable Hist::DetArray<Hist::H2D<>> h_BunchIDVsBitID = { {} }; /// Individual maps for each PMT mutable std::unique_ptr<PMTPlots> h_pixelMapsCol; /// Individual hits for each PMT mutable std::unique_ptr<PMTPlots> h_pixelCol; /// nHits - mutable Hist::DetArray<Hist::H1D<>> h_nHits = {{}}; - mutable Hist::DetArray<Hist::PanelArray<Hist::H1D<>>> h_nHits_side = {{}}; + mutable Hist::DetArray<Hist::H1D<>> h_nHits = { {} }; + mutable Hist::DetArray<Hist::PanelArray<Hist::H1D<>>> h_nHits_side = { {} }; private: - unsigned int m_start_scan{0}; - unsigned int m_stop_scan{0}; + unsigned int m_start_scan{ 0 }; + unsigned int m_stop_scan{ 0 }; private: // properties /// Fill individual PMT plots - Gaudi::Property<bool> m_fillVerbosePMTPlots{this, "VerbosePlots", false, "Create verbose PMT specific hit maps"}; + Gaudi::Property<bool> m_fillVerbosePMTPlots{ this, "VerbosePlots", false, "Create verbose PMT specific hit maps" }; /// Fill spatial coordiate plots - Gaudi::Property<bool> m_fillSpacePlots{this, "SpatialPlots", false, "Create spatial hit maps"}; + Gaudi::Property<bool> m_fillSpacePlots{ this, "SpatialPlots", false, "Create spatial hit maps" }; /// Fill individual PMT plots - Gaudi::Property<bool> m_enableOfflinePlots{this, "OfflinePlots", false, "Enable (large) offline plots"}; + Gaudi::Property<bool> m_enableOfflinePlots{ this, "OfflinePlots", false, "Enable (large) offline plots" }; protected: /// Pre-Book all histograms @@ -248,7 +248,7 @@ namespace Rich::Future::Mon { } } - return StatusCode{ok}; + return StatusCode{ ok }; } private: @@ -352,13 +352,13 @@ namespace Rich::Future::Mon { 1e5 * static_cast<int>( id.panel() ) + 100 * ( 24 * ( tel40Data.sourceID.data() & 0x3F ) + tel40Data.connector.data() ) + anodeData.bit.data(); - ++hb_SlotIDVsBitID[rich][{bitID, slotID}]; - ++hb_BunchIDVsBitID[rich][{bitID, bunchID}]; + ++hb_SlotIDVsBitID[rich][{ bitID, slotID }]; + ++hb_BunchIDVsBitID[rich][{ bitID, bunchID }]; } if ( m_fillVerbosePMTPlots ) { - ++( getPMTHitsPlot( id )[{thDAC_ID, id.anodeIndex()}] ); - ++( getPMTPlot( id )[{id.ecLocalPMTFrameX(), id.ecLocalPMTFrameY()}] ); + ++( getPMTHitsPlot( id )[{ thDAC_ID, id.anodeIndex() }] ); + ++( getPMTPlot( id )[{ id.ecLocalPMTFrameX(), id.ecLocalPMTFrameY() }] ); } const auto iGlobalX = id.ecGlobalPMTFrameX() - id.panel() * 220; @@ -368,8 +368,8 @@ namespace Rich::Future::Mon { // For large H type PMTs fill a group of 4 corresponding to the effective smaller pixels for ( int i = 0; i < 2; ++i ) { for ( int j = 0; j < 2; ++j ) { - ++hb_pixelMap[rich][{iGlobalX + i, iGlobalY + j}]; - ++hb_pixelMap2[rich][{iGlobalX2 + i, iGlobalY + j}]; + ++hb_pixelMap[rich][{ iGlobalX + i, iGlobalY + j }]; + ++hb_pixelMap2[rich][{ iGlobalX2 + i, iGlobalY + j }]; } } } else { @@ -378,19 +378,19 @@ namespace Rich::Future::Mon { if ( 0 == side ) { auto convertX = []( const auto x ) { return ( -1 * ( x + 3 - 89 - 21 ) ) + 89 + 21; }; auto convertY = []( const auto y ) { return -( y + 1 ); }; - ++hb_pixelMap[rich][{convertY( iGlobalY ), convertX( iGlobalX )}]; - ++hb_pixelMap2[rich][{convertY( iGlobalY ), convertX( iGlobalX2 )}]; + ++hb_pixelMap[rich][{ convertY( iGlobalY ), convertX( iGlobalX ) }]; + ++hb_pixelMap2[rich][{ convertY( iGlobalY ), convertX( iGlobalX2 ) }]; } else { auto convertX = []( const auto x ) { return x + 3; }; auto convertY = []( const auto y ) { return y + 1; }; - ++hb_pixelMap[rich][{convertY( iGlobalY ), convertX( iGlobalX )}]; - ++hb_pixelMap2[rich][{convertY( iGlobalY ), convertX( iGlobalX2 )}]; + ++hb_pixelMap[rich][{ convertY( iGlobalY ), convertX( iGlobalX ) }]; + ++hb_pixelMap2[rich][{ convertY( iGlobalY ), convertX( iGlobalX2 ) }]; } } else { auto convertX = []( const auto x ) { return x + 1; }; auto convertY = []( const auto y ) { return y; }; - ++hb_pixelMap[rich][{convertX( iGlobalX ), convertY( iGlobalY )}]; - ++hb_pixelMap2[rich][{convertX( iGlobalX2 ), convertY( iGlobalY )}]; + ++hb_pixelMap[rich][{ convertX( iGlobalX ), convertY( iGlobalY ) }]; + ++hb_pixelMap2[rich][{ convertX( iGlobalX2 ), convertY( iGlobalY ) }]; } } @@ -401,7 +401,7 @@ namespace Rich::Future::Mon { // info() << "gPos " << gPos << endmsg; const auto lPos = smartIDsHelper.globalToPDPanel( gPos ); // info() << "lPos " << lPos << endmsg; - ++hb_hitMaps[rich][{lPos.x(), lPos.y()}]; + ++hb_hitMaps[rich][{ lPos.x(), lPos.y() }]; } } // hit loop @@ -414,8 +414,8 @@ namespace Rich::Future::Mon { } // modules if ( m_fillVerbosePMTPlots ) { ++h_nHits_side[rich][side][nHitsSide]; } } // panels - ++h_NHitsVsSlotID[rich][{slotID, nHits}]; - ++h_NHitsVsBunchID[rich][{bunchID, nHits}]; + ++h_NHitsVsSlotID[rich][{ slotID, nHits }]; + ++h_NHitsVsBunchID[rich][{ bunchID, nHits }]; // if ( m_enableOfflinePlots ) { ++h_NHitsVsBunchID[rich][{ bunchID, nHits }]; } ++h_nHits[rich][nHits]; } // RICHes diff --git a/Rich/RichOnlineMonitors/src/RichTAEMonitor.cpp b/Rich/RichOnlineMonitors/src/RichTAEMonitor.cpp index c34337eea2820394b7c1e6cb2e5c37f8be0910dc..42f4a59ad545621ef3c16b713d411e4e82816f23 100644 --- a/Rich/RichOnlineMonitors/src/RichTAEMonitor.cpp +++ b/Rich/RichOnlineMonitors/src/RichTAEMonitor.cpp @@ -67,7 +67,7 @@ namespace Rich::Future::Mon { : MergingConsumer<ODINVector, DecodedDataVector>( name, pSvcLocator, // input data - {KeyValues{"ODINsLocation", {}}, KeyValues{"DecodedDatasLocation", {}}} ) { + { KeyValues{ "ODINsLocation", {} }, KeyValues{ "DecodedDatasLocation", {} } } ) { // setProperty( "HistoPrint", true ).ignore(); setProperty( "NBins2DHistos", 500 ).ignore(); } @@ -82,26 +82,26 @@ namespace Rich::Future::Mon { } private: - LHCb::TAE::Handler m_taeHandler{this}; + LHCb::TAE::Handler m_taeHandler{ this }; // histograms /// Occupancy vs taeID - mutable Hist::DetArray<Hist::H2D<>> h_NHitsVsTaeID = {{}}; + mutable Hist::DetArray<Hist::H2D<>> h_NHitsVsTaeID = { {} }; /// taeID vs tell40 link (i.e. 100 bits) - mutable Hist::DetArray<Hist::H2D<>> h_TaeIDVsBitID = {{}}; + mutable Hist::DetArray<Hist::H2D<>> h_TaeIDVsBitID = { {} }; - ConditionAccessor<DAQ::Tel40CableMapping> m_tel40CableMapping{this, DAQ::Tel40CableMapping::DefaultConditionKey + - "-" + name()}; - ConditionAccessor<DAQ::PDMDBEncodeMapping> m_pdmdbEncodeMapping{this, DAQ::PDMDBEncodeMapping::DefaultConditionKey + - "-" + name()}; + ConditionAccessor<DAQ::Tel40CableMapping> m_tel40CableMapping{ this, DAQ::Tel40CableMapping::DefaultConditionKey + + "-" + name() }; + ConditionAccessor<DAQ::PDMDBEncodeMapping> m_pdmdbEncodeMapping{ + this, DAQ::PDMDBEncodeMapping::DefaultConditionKey + "-" + name() }; protected: /// Pre-Book all histograms StatusCode prebookHistograms() override { bool ok = true; - const BinLabels TAEaxisLabels = {"Prev4", "Prev3", "Prev2", "Prev1", "Central", - "Next1", "Next2", "Next3", "Next4"}; + const BinLabels TAEaxisLabels = { "Prev4", "Prev3", "Prev2", "Prev1", "Central", + "Next1", "Next2", "Next3", "Next4" }; // Loop over RICHes for ( const auto rich : Rich::detectors() ) { @@ -119,7 +119,7 @@ namespace Rich::Future::Mon { BinLabels(), TAEaxisLabels ); } - return StatusCode{ok}; + return StatusCode{ ok }; } public: @@ -176,7 +176,7 @@ namespace Rich::Future::Mon { 1e5 * static_cast<int>( id.panel() ) + 100 * ( 24 * ( tel40Data.sourceID.data() & 0x3F ) + tel40Data.connector.data() ) + anodeData.bit.data(), - offset}]; + offset }]; } } // hit loop @@ -188,7 +188,7 @@ namespace Rich::Future::Mon { } // modules } // panels if ( ( offset == 0 || odin.bunchCrossingType() == LHCb::ODIN::BXTypes::NoBeam ) && ( nHits > 0 ) ) { - ++hb_NHitsVsTaeID[rich][{offset, nHits}]; + ++hb_NHitsVsTaeID[rich][{ offset, nHits }]; } } // RICHes }