ATLAS Offline Software
EFTrackingSmearingConfig.py
Go to the documentation of this file.
1 
2 #Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 from AthenaConfiguration.ComponentFactory import CompFactory
4 from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
5 from AthenaCommon.Logging import logging
6 _log = logging.getLogger(__name__)
7 
8 def EFTrackingSmearingCfg(flags, name = "EFTrackingSmearingAlg", **kwargs):
9  # set common parameters
10  histSvc = CompFactory.THistSvc(Output=[name +" DATAFILE='"+name+ ".root' OPT='RECREATE'"])
11 
12  result = ComponentAccumulator()
13  result.addService(histSvc)
14 
15  alg = CompFactory.EFTrackingSmearingAlg(
16  name = name,
17  RootStreamName = name,
18  RootDirName = "/EFTSmearing/",
19  **kwargs
20  )
21 
22  sf_str=str(kwargs['SmearingScaleFactor']).replace(".","p")
23  if kwargs['SmearTruthParticle']:
24  alg.OutputTruthParticleContainer = "TruthParticle_smeared_SF"+sf_str
25  else:
26  alg.OutputTrackParticleContainer = "InDetTrackParticles_smeared_SF"+sf_str
27 
28  result.addEventAlgo(alg)
29  return result
30 
31 
32 
33 
34 if __name__ == "__main__":
35 
36  from AthenaConfiguration.TestDefaults import defaultTestFiles
37  from AthenaConfiguration.AllConfigFlags import initConfigFlags
38  from AthenaCommon.Constants import INFO, DEBUG
39  flags = initConfigFlags()
40  flags.Input.Files = defaultTestFiles.AOD_RUN3_MC
41  flags.Input.isMC=True
42  flags.Exec.MaxEvents = 5
43  flags.lock()
44 
45  # create basic infrastructure
46  from AthenaConfiguration.MainServicesConfig import MainServicesCfg
47  acc = MainServicesCfg(flags)
48  acc.getService("MessageSvc").debugLimit = 100000
49 
50  from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
51  acc.merge(PoolReadCfg(flags))
52 
53  # needed to access the decorators for the truth particles
54  from InDetPhysValMonitoring.InDetPhysValDecorationConfig import AddDecoratorCfg
55  acc.merge(AddDecoratorCfg(flags))
56 
57  TestsmearFactor = 2
58  TestEfficiencyFactor=1
59  # example to smear the track particles
60  smearerTrack = EFTrackingSmearingCfg(
61  flags,
62  name = "testTrack",
63  InputTrackParticleContainer = "InDetTrackParticles",
64  OutputTracksPtCutGeV = 1,
65  SmearingScaleFactor = TestsmearFactor,
66  SmearedTrackEfficiency = TestEfficiencyFactor,
67  ParameterizedTrackEfficiency = False,
68  SmearTruthParticle = False,
69  EnableMonitoring = True,
70  OutputLevel = INFO)
71  acc.merge(smearerTrack)
72 
73 
74  # example to smear the truth particles
75  smearerTruth = EFTrackingSmearingCfg(
76  flags,
77  name = "testTruth",
78  InputTruthParticleContainer = "TruthParticles",
79  OutputTracksPtCutGeV = 1,
80  SmearingScaleFactor = TestsmearFactor,
81  SmearedTrackEfficiency = TestEfficiencyFactor,
82  ParameterizedTrackEfficiency = False,
83  SmearTruthParticle = True,
84  ParameterizedTrackEfficiency_LRT = True,
85  SmearedTrackEfficiency_d0low_LRT = .001,
86  SmearedTrackEfficiency_d0high_LRT = 400.,
87  EnableMonitoring = True,
88  OutputLevel = DEBUG)
89  acc.merge(smearerTruth)
90 
91 
92  # validation of the smeared tracks and truth particles
93  validationAlg = CompFactory.EFTrackingSmearMonAlg(
94  name = "EFTrakingSmearMonAlg",
95  OutputLevel = INFO,
96  InputTrackParticleContainer = "InDetTrackParticles",
97  InputTruthParticleContainer = "TruthParticles",
98  SmearedTrackParticleContainer = "InDetTrackParticles_smeared_SF"+str(TestsmearFactor),
99  SmearedTruthParticleContainer = "TruthParticle_smeared_SF"+str(TestsmearFactor),)
100  acc.addEventAlgo(validationAlg)
101 
102  acc.wasMerged()
103 
104  # below is validation
105  acc.printConfig(withDetails=True, summariseProps=True)
106 
107 
108  # run the job
109  status = acc.run()
110 
111 
112  # report the execution status (0 ok, else error)
113  import sys
114  sys.exit(not status.isSuccess())
115 
replace
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition: hcg.cxx:307
python.JetAnalysisCommon.ComponentAccumulator
ComponentAccumulator
Definition: JetAnalysisCommon.py:302
EFTrackingSmearingConfig.EFTrackingSmearingCfg
def EFTrackingSmearingCfg(flags, name="EFTrackingSmearingAlg", **kwargs)
Definition: EFTrackingSmearingConfig.py:8
InDetPhysValDecorationConfig.AddDecoratorCfg
def AddDecoratorCfg(flags, **kwargs)
Definition: InDetPhysValDecorationConfig.py:153
python.MainServicesConfig.MainServicesCfg
def MainServicesCfg(flags, LoopMgr='AthenaEventLoopMgr')
Definition: MainServicesConfig.py:260
Constants
some useful constants -------------------------------------------------—
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
str
Definition: BTagTrackIpAccessor.cxx:11
python.PoolReadConfig.PoolReadCfg
def PoolReadCfg(flags)
Definition: PoolReadConfig.py:69