ATLAS Offline Software
CreateMisalignmentITk.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 #Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
4 
9 
10 from AthenaConfiguration.AllConfigFlags import initConfigFlags
11 from AthenaConfiguration.MainServicesConfig import MainServicesCfg
12 from InDetAlignGenAlgs.InDetAlignAlgsConfig import CreateITkMisalignAlgCfg
13 from AthenaConfiguration.DetectorConfigFlags import setupDetectorFlags
14 from InDetAlignGenTools.InDetAlignGenToolsConfig import ITkAlignDBTool
15 import sys
16 from AthenaConfiguration.ComponentFactory import CompFactory
17 
18 def blockFolder(ca,folder):
19  "Block use of specified conditions DB folder so data can be read from elsewhere"
20  from IOVDbSvc.IOVDbSvcConfig import IOVDbSvcCfg
21  ca.merge(IOVDbSvcCfg(flags))
22  iovdbsvc=ca.getService("IOVDbSvc")
23  # check existing list of folders and remove it if found
24  for i in range(0,len(iovdbsvc.Folders)):
25  if (iovdbsvc.Folders[i].find(folder)>=0):
26  del iovdbsvc.Folders[i]
27  break
28  condInputLoader=ca.getCondAlgo("CondInputLoader")
29  for i in range(0, len(condInputLoader.Load)):
30  if (folder in condInputLoader.Load[i][-1] ):
31  del condInputLoader.Load[i]
32  break
33 
34 
35 def getFlags(**kwargs):
36  flags=initConfigFlags()
37 
38  flags.Input.isMC = True
39 
40  flags.Input.Files = []
41 
42  from AthenaConfiguration.TestDefaults import defaultGeometryTags,defaultConditionsTags
43  flags.GeoModel.AtlasVersion = defaultGeometryTags.RUN4
44  flags.GeoModel.Align.Dynamic = False
45 
46  flags.ITk.Geometry.AllLocal = False
47  detectors = [
48  "ITkPixel",
49  "ITkStrip",
50  "Bpipe"
51  ]
52  setupDetectorFlags(flags, custom_list=detectors, toggle_geometry=True)
53  flags.TrackingGeometry.MaterialSource = "Input"
54 
55 
56  #Define the output database file name and add it to the flags
57  if 'MisalignMode' not in kwargs.keys():
58  MisalignMode = 11 # Radial
59  else:
60  MisalignMode=int(kwargs.get('MisalignMode',11))
61  databaseFilename = 'MisalignmentSet%s.db' % (MisalignMode)
62  flags.IOVDb.DBConnection="sqlite://;schema=%s;dbname=OFLCOND" % (databaseFilename)
63  flags.IOVDb.GlobalTag = defaultConditionsTags.RUN4_MC
64 
65  # This should run serially for the moment.
66  flags.Concurrency.NumThreads = 1
67  flags.Concurrency.NumConcurrentEvents = 1
68  flags.lock()
69 
70  return flags
71 
72 def CreateMis(flags,name="CreateITkMisalignAlg",**kwargs):
73  #
74  #--------------------------------------------------------------
75  # Geometry section
76  #--------------------------------------------------------------
77  misalignmentOnTopOfExistingSet = False
78  readDBPoolFile = False
79 
80  createFreshDB = not(readDBPoolFile or misalignmentOnTopOfExistingSet)
81 
82  MisalignMode = kwargs.pop('MisalignMode',11)
83 
84  shiftInMicrons = 100
85 
86  if MisalignMode in [11, 12, 31]:
87  shiftInMicrons = 500
88  outFiles = 'MisalignmentSet%s' % (MisalignMode)
89  misalignModeMap = {0:'no Misalignment',
90  1: 'misalignment by 6 parameters',
91  2: 'random misalignment',
92  3: 'IBL-stave temperature dependent bowing',
93  11: 'R deltaR (radial expansion)', 12: 'Phi deltaR (ellipse)',13: 'Z deltaR (funnel)',
94  21: 'R deltaPhi (curl)', 22: 'Phi deltaPhi (clamshell) ',23:'Z deltaPhi (twist)',
95  31: 'R deltaZ (telescope)',32:'Phi deltaZ (skew)',33:'Z deltaZ (z-expansion)'}
96 
97 
98  acc=MainServicesCfg(flags)
99  print ("\n CreateMisalignAlg: Creation of misalignment mode %s: %s \n" % (int(MisalignMode),misalignModeMap.get(int(MisalignMode),'unknown')))
100  kwargs.setdefault("ASCIIFilenameBase",outFiles)
101  kwargs.setdefault("SQLiteTag",'MisalignmentMode_'+str(misalignModeMap.get(int(MisalignMode),'unknown')))
102  kwargs.setdefault("MisalignMode",int(MisalignMode))
103  kwargs.setdefault("MaxShift",shiftInMicrons)
104  kwargs.setdefault("CreateFreshDB",createFreshDB)
105  #Create and configure the AlignDB tool
106  outputAlignFolder="/Indet/AlignITk" #The folder name to which the created misaligments should be written
107  inputAlignFolder="/Indet/Align" #The folder name from which initial misalignments should be read
108 
109  writeDBPoolFile=True #Activate or deactivate writing to outFiles + '.pool.root'
110  kargsTool={}
111  kargsTool.setdefault("SCTTwoSide",True)
112  kargsTool.setdefault("DBRoot",outputAlignFolder)
113  kargsTool.setdefault("DBKey",outputAlignFolder)
114  kargsTool.setdefault("forceUserDBConfig",True)
115  if writeDBPoolFile:
116  print("Writing DB Pool File")
117  InDetCondStream=CompFactory.AthenaOutputStreamTool("CondStream_write",OutputFile = outFiles+'.pool.root')
118  InDetCondStream.PoolContainerPrefix="<type>"
119  InDetCondStream.TopLevelContainerName=""
120  InDetCondStream.SubLevelBranchName="<key>"
121  kargsTool.setdefault("CondStream",InDetCondStream)
122  dbTool = acc.popToolsAndMerge(ITkAlignDBTool(flags,**kargsTool))
123 
124  kwargs.setdefault("IDAlignDBTool",dbTool)
125 
126  cfg=CreateITkMisalignAlgCfg(flags,name=name,SetITkPixelAlignable=True,SetITkStripAlignable=True,setAlignmentFolderName=inputAlignFolder,**kwargs)
127 
128  acc.merge(cfg)
129  if writeDBPoolFile:
130  print("To be writen DB pool File")
131 
132  return acc
133 
134 if __name__ == "__main__":
135  if(len(sys.argv[1:])):
136  kwargs=dict(arg.split('=') for arg in sys.argv[1:])
137  print(kwargs)
138  else:
139  kwargs={}
140  print("no args")
141  #Get the basic configuration flags
142  flags=getFlags(**kwargs)
143  flags.dump()
144  #Add the tools and the algorithm to the accumulator
145  acc=CreateMis(flags,**kwargs)
146  acc.printConfig()
147 
148  #run
149  sc=acc.run(10)
150  if sc.isFailure():
151  print("Failed to run the Misalignment Algorithm")
152  sys.exit(-1)
CreateMisalignmentITk.CreateMis
def CreateMis(flags, name="CreateITkMisalignAlg", **kwargs)
Definition: CreateMisalignmentITk.py:72
InDetAlignGenToolsConfig.ITkAlignDBTool
def ITkAlignDBTool(flags, name="ITkAlignDBTool", setAlignmentFolderName="/Indet/AlignITk", **kwargs)
Definition: InDetAlignGenToolsConfig.py:6
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
CreateMisalignmentITk.getFlags
def getFlags(**kwargs)
Definition: CreateMisalignmentITk.py:35
InDetAlignAlgsConfig.CreateITkMisalignAlgCfg
def CreateITkMisalignAlgCfg(flags, name="CreateITkMisalignAlg", SetITkPixelAlignable=False, SetITkStripAlignable=False, setAlignmentFolderName="/Indet/AlignITk", **kwargs)
Definition: InDetAlignAlgsConfig.py:6
python.MainServicesConfig.MainServicesCfg
def MainServicesCfg(flags, LoopMgr='AthenaEventLoopMgr')
Definition: MainServicesConfig.py:260
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
python.IOVDbSvcConfig.IOVDbSvcCfg
def IOVDbSvcCfg(flags, **kwargs)
Definition: IOVDbSvcConfig.py:19
CreateMisalignmentITk.blockFolder
def blockFolder(ca, folder)
Definition: CreateMisalignmentITk.py:18
python.DetectorConfigFlags.setupDetectorFlags
def setupDetectorFlags(flags, custom_list=None, use_metadata=False, toggle_geometry=False, validate_only=False, keep_beampipe=False)
Definition: DetectorConfigFlags.py:289
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
if
if(febId1==febId2)
Definition: LArRodBlockPhysicsV0.cxx:567
str
Definition: BTagTrackIpAccessor.cxx:11
dbg::print
void print(std::FILE *stream, std::format_string< Args... > fmt, Args &&... args)
Definition: SGImplSvc.cxx:70