ATLAS Offline Software
runBeamSpotCalibration.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 
4 from glob import glob
5 
6 from AthenaConfiguration.AllConfigFlags import initConfigFlags
7 flags = initConfigFlags()
8 
9 import configMy
10 
11 #Job options
12 if 'outputlevel' not in configMy.jobConfig: configMy.jobConfig['outputlevel'] = 3
13 if 'maxEvents' not in configMy.jobConfig: configMy.jobConfig['maxEvents'] = -1
14 if 'skipEvents' not in configMy.jobConfig: configMy.jobConfig['skipEvents'] = 0
15 if 'MsgLimit' not in configMy.jobConfig: configMy.jobConfig['MsgLimit'] = 20
16 
17 if 'outputfileprefix' not in configMy.jobConfig: configMy.jobConfig['outputfileprefix'] = ''
18 if 'outputfile' not in configMy.jobConfig: configMy.jobConfig['outputfile'] = configMy.jobConfig['outputfileprefix']+'beamspot.db'
19 if 'histfile' not in configMy.jobConfig: configMy.jobConfig['histfile'] = configMy.jobConfig['outputfileprefix']+'nt.root'
20 if 'monfile' not in configMy.jobConfig: configMy.jobConfig['monfile'] = configMy.jobConfig['outputfileprefix']+'beamspotmonitoring.root'
21 if 'jobpostprocsteps' not in configMy.jobConfig: configMy.jobConfig['jobpostprocsteps'] = 'MergeNt PlotBeamSpot LinkResults AveBeamSpot DQBeamSpot'
22 if 'doMonitoring' not in configMy.jobConfig: configMy.jobConfig['doMonitoring'] = True
23 if 'VertexNtuple' not in configMy.jobConfig: configMy.jobConfig['VertexNtuple'] = True
24 if 'WriteAllVertices' not in configMy.jobConfig: configMy.jobConfig['WriteAllVertices'] = False
25 if 'VertexTreeName' not in configMy.jobConfig: configMy.jobConfig['VertexTreeName'] = 'Vertices'
26 
27 #Event selection options
28 if 'UseBCID' not in configMy.jobConfig: configMy.jobConfig['UseBCID'] = []
29 if 'UseFilledBCIDsOnly' not in configMy.jobConfig: configMy.jobConfig['UseFilledBCIDsOnly'] = True
30 
31 #Vertex Selection Options
32 if 'MinTracksPerVtx' not in configMy.jobConfig: configMy.jobConfig['MinTracksPerVtx'] = 5
33 if 'MaxTracksPerVtx' not in configMy.jobConfig: configMy.jobConfig['MaxTracksPerVtx'] = 1000000
34 if 'MinVtxNum' not in configMy.jobConfig: configMy.jobConfig['MinVtxNum'] = 100
35 if 'MaxVtxChi2' not in configMy.jobConfig: configMy.jobConfig['MaxVtxChi2'] = 10
36 if 'MaxTransverseErr' not in configMy.jobConfig: configMy.jobConfig['MaxTransverseErr'] = 1000000
37 if 'VertexTypes' not in configMy.jobConfig: configMy.jobConfig['VertexTypes'] = ['PriVtx']
38 if 'MinVtxProb' not in configMy.jobConfig: configMy.jobConfig['MinVtxProb'] = .001
39 if 'VertexContainer' not in configMy.jobConfig: configMy.jobConfig['VertexContainer'] = 'PrimaryVertices'
40 if 'MaxAbsCorrelXY' not in configMy.jobConfig: configMy.jobConfig['MaxAbsCorrelXY'] = 0.8
41 
42 #Options for sorting vertices into fits
43 if 'LumiRange' not in configMy.jobConfig: configMy.jobConfig['LumiRange'] = 0
44 if 'RunRange' not in configMy.jobConfig: configMy.jobConfig['RunRange'] = 0
45 
46 #if 'GroupFitsByBCID' not in configMy.jobConfig: configMy.jobConfig['GroupFitsByBCID'] = False
47 #if 'GroupFitsByPileup' not in configMy.jobConfig: configMy.jobConfig['GroupFitsByPileup'] = False
48 if 'GroupFitsBy' not in configMy.jobConfig: configMy.jobConfig['GroupFitsBy'] = 'none'
49 if 'EventRange' not in configMy.jobConfig: configMy.jobConfig['EventRange'] = 0
50 
51 #Fit Options
52 if 'InitialKFactor' not in configMy.jobConfig: configMy.jobConfig['InitialKFactor'] = 1.0
53 if 'ConstantKFactor' not in configMy.jobConfig: configMy.jobConfig['ConstantKFactor'] = False
54 
55 #Fit Options for official fit only
56 if 'MaxSigmaTr' not in configMy.jobConfig: configMy.jobConfig['MaxSigmaTr'] = 20.
57 if 'MaxSigmaVtx' not in configMy.jobConfig: configMy.jobConfig['MaxSigmaVtx'] = 2.0
58 if 'TruncatedRMS' not in configMy.jobConfig: configMy.jobConfig['TruncatedRMS'] = True
59 if 'SetInitialRMS' not in configMy.jobConfig: configMy.jobConfig['SetInitialRMS'] = False
60 if 'OutlierChi2Tr' not in configMy.jobConfig: configMy.jobConfig['OutlierChi2Tr'] = 20.
61 if 'BeamSpotToolList' not in configMy.jobConfig: configMy.jobConfig['BeamSpotToolList'] = ['InDetBeamSpotRooFit','InDetBeamSpotVertex']
62 if 'FixWidth' not in configMy.jobConfig: configMy.jobConfig['FixWidth'] = False
63 
64 #Fit Options for RooFit only
65 if 'RooFitMaxTransverseErr' not in configMy.jobConfig: configMy.jobConfig['RooFitMaxTransverseErr'] = 0.05
66 
67 #Job options for Monitoring algorithm
68 if 'MinTrackPt' not in configMy.jobConfig: configMy.jobConfig['MinTrackPt'] = 500.
69 if 'useBeamSpot' not in configMy.jobConfig:
70  # change to True as soon as I have PrimaryVertexMonitoring in as well
71  configMy.jobConfig['useBeamSpot'] = configMy.jobConfig.get('beamspottag','')!='' or configMy.jobConfig.get('beamspotfile','')!=''
72 
73 #Printout of job configuration
74 print("Job configuration: ")
75 for option in configMy.jobConfig:
76  print(" ",option,': ',configMy.jobConfig[option])
77 print(" ")
78 
79 flags.Exec.OutputLevel = configMy.jobConfig['outputlevel']
80 flags.Exec.SkipEvents = configMy.jobConfig['skipEvents']
81 flags.Exec.MaxEvents = configMy.jobConfig['maxEvents']
82 
83 flags.Input.Files = []
84 for path in configMy.jobConfig['inputfiles']:
85  print("path: ",path)
86  print("glob: ",glob(path))
87  flags.Input.Files += glob(path)
88 
89 
90 flags.Trigger.triggerConfig = "DB"
91 flags.DQ.enableLumiAccess = False
92 flags.Output.HISTFileName = configMy.jobConfig['monfile']
93 flags.Exec.EventPrintoutInterval = 10000
94 flags.fillFromArgs()
95 flags.lock()
96 
97 from AthenaConfiguration.MainServicesConfig import MainServicesCfg
98 acc = MainServicesCfg(flags)
99 from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
100 acc.merge(PoolReadCfg(flags))
101 acc.getService("MessageSvc").defaultLimit = configMy.jobConfig['MsgLimit']
102 
103 from InDetBeamSpotFinder.InDetBeamSpotFinderConfig import InDetBeamSpotFinderCfg
104 acc.merge(InDetBeamSpotFinderCfg(flags,configMy.jobConfig))
105 
106 from AthenaConfiguration.ComponentFactory import CompFactory
107 acc.addService(CompFactory.THistSvc(
108  Output = ["INDETBEAMSPOTFINDER DATAFILE='%s' OPT='RECREATE'" % configMy.jobConfig['histfile']]))
109 
110 if configMy.jobConfig['doMonitoring']:
111  from AthenaMonitoring import AthMonitorCfgHelper
112  helper = AthMonitorCfgHelper(flags, "BeamSpotMonitoring")
113  from InDetGlobalMonitoringRun3Test.InDetGlobalBeamSpotMonAlgCfg import (
114  InDetGlobalBeamSpotMonAlgCfg )
115  InDetGlobalBeamSpotMonAlgCfg(helper, acc, flags,configMy.jobConfig)
116  acc.merge(helper.result())
117 
118 acc.printConfig(withDetails=True)
119 
120 # Execute and finish
121 sc = acc.run()
122 
123 # Success should be 0
124 import sys
125 sys.exit(not sc.isSuccess())
InDetBeamSpotFinderConfig.InDetBeamSpotFinderCfg
def InDetBeamSpotFinderCfg(flags, jobConfig={}, name="InDetBeamSpotFinder", **kwargs)
Definition: InDetBeamSpotFinderConfig.py:36
InDetGlobalBeamSpotMonAlgCfg
Definition: InDetGlobalBeamSpotMonAlgCfg.py:1
python.MainServicesConfig.MainServicesCfg
def MainServicesCfg(flags, LoopMgr='AthenaEventLoopMgr')
Definition: MainServicesConfig.py:260
print
void print(char *figname, TCanvas *c1)
Definition: TRTCalib_StrawStatusPlots.cxx:25
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
python.PoolReadConfig.PoolReadCfg
def PoolReadCfg(flags)
Definition: PoolReadConfig.py:69