5 '''@file RunTilePulseSim.py
6 @brief Script to run Tile pulse simulator
9 from AthenaConfiguration.ComponentFactory
import CompFactory
10 from TileConfiguration.TileConfigFlags
import TileRunType
14 """Return component accumulator with configured Tile digits from pulse algorithm
17 flags -- Athena configuration flags
19 OutputDigitsContainer -- Name of container with TileDigits to write
20 ImperfectionMean -- Mean value of pulse shape broadening
21 ImperfectionRMS -- RMS of pulse shape broadening
22 InTimeAmp -- Amplitude of in-time pulse
23 OutOfTimeAmp -- Amplitude of out-of-time pulse
24 InTimeOffset -- In-time pulse offset from nominal time
25 OutOfTimeOffset -- Out-of-time pulse offset from nominal time
26 UseGaussNoise -- Set to TRUE in order to create noise from double gaussian
27 GaussNoiseAmpOne -- Amplitude of first gaussian of double gaussian noise
28 GaussNoiseSigmaOne -- Standard deviation of first gaussian of double gaussian noise
29 GaussNoiseAmpTwo -- Amplitude of second gaussian of double gaussian noise
30 GaussNoiseSigmaTwo -- Standard deviation of second gaussian of double gaussian noise
31 UseInTimeAmpDist -- Set to TRUE in order to use a distribution for the in-time amplitude instead of a const.
32 UseOutOfTimeAmpDist -- Set to TRUE in order to use a distribution for the out-of-time amplitude instead of a const
33 InTimeAmpDistFileName -- Filename of file to use for amplitude distribution of in-time pulses
34 InTimeAmpDistHistogramName -- Name of the histogram to use for in-time amplitude distribution
35 InTimeAmpPulseProb -- Probability to add an in-time pulse
36 OutOfTimeAmpDistFileName -- Filename of file to use for amplitude distribution of out-of-time pulses
37 InTimeAmpPulseProb -- Probability to add an in-time pulse
38 PileUpFraction -- Probability that an out-of-time component will be added
39 GaussianC2CPhaseVariation -- RMS for the in-time pulse offset (channel-to-channel phase variation)
40 ChannelSpecificPedestal -- Set to TRUE in order to use a channel specific value for the pedestal
41 ChannelSpecificNoise -- Set to TRUE in order to add channel specific noise
42 OutOfTimeOffsetHistogramFile -- Filename of file containing histogram of pile-up timing distribution
43 OutOfTimeOffsetHistogramName -- Name of the histogram to use for pile-up timing distribution
44 AmpDistLowerLimit -- Set all bins lower than this to zero. Default = 135
45 PedestalValueHG -- Pedestal in HG if not taken from database
46 PedestalValueLG -- Pedestal in LG if not taken from database
47 SimulatePileUpWithPoiss -- Simulate pile-up overlaying signals from distribution
48 AvgMuForPileUpSimulation -- Average number of pp collisions for pile-up simulation with SimulatePileUpWithPoiss
49 PileUpAmpDistFileName -- Distribution to simulate pile-up with SimulatePileUpWithPoiss
50 RandomSeed -- Random seed for random number generator
51 SimulatePulseChain -- Simulate continuous output from readout cosidering HL-LHC paradigm
52 Bigain -- Save two gains in ntuple
53 NPulses -- The number of neighboring bunch crossings (before and after the in-time crossing) whose signals are accounted for when simulating the total contribution to a given bunch crossing
56 kwargs.setdefault(
'InTimeAmp', 1000)
57 kwargs.setdefault(
'InTimeAmpPulseProb', 1)
58 kwargs.setdefault(
'ImperfectionMean', 1)
59 kwargs.setdefault(
'ImperfectionRms', 0)
60 kwargs.setdefault(
'TilePhaseII',
False)
61 kwargs.setdefault(
'NSamples', 7)
62 kwargs.setdefault(
'Bigain',
False)
63 kwargs.setdefault(
'SimulatePulseChain',
False)
65 PhaseII = kwargs[
'TilePhaseII']
66 PulseChain = kwargs[
'SimulatePulseChain']
70 kwargs.setdefault(
'PedestalValueHG', 100)
71 kwargs.setdefault(
'PedestalValueLG', 100)
72 kwargs.setdefault(
'ChannelSpecificPedestal',
False)
73 kwargs.setdefault(
'UseGaussNoise',
True)
75 kwargs.setdefault(
'ChannelSpecificPedestal',
True)
76 kwargs.setdefault(
'ChannelSpecificNoise',
True)
78 kwargs.setdefault(
'PileUpFraction', 0)
79 kwargs.setdefault(
'AmpDistLowerLimit', 0)
80 kwargs.setdefault(
'SimulatePileUpWithPoiss',
False)
81 kwargs.setdefault(
'AvgMuForPileUpSimulation', 80)
83 from TileGeoModel.TileGMConfig
import TileGMCfg
86 from TileConditions.TileCablingSvcConfig
import TileCablingSvcCfg
89 from TileConditions.TileSampleNoiseConfig
import TileSampleNoiseCondAlgCfg
92 from RngComps.RngCompsConfig
import AthRNGSvcCfg
93 kwargs[
'RndmSvc'] = acc.getPrimaryAndMerge(
AthRNGSvcCfg(flags) )
96 nSamples = kwargs[
'NSamples']
if not PulseChain
else 1
97 ADCmax = 4095
if PhaseII
else 1023
98 ADCmaskValue = 4800
if PhaseII
else 2047
99 from TileConditions.TileInfoLoaderConfig
import TileInfoLoaderCfg
101 NSamples=nSamples, TrigSample=((nSamples-1)//2),
102 ADCmax=ADCmax, ADCmaskValue=ADCmaskValue) )
104 TileDigitsFromPulse = CompFactory.TileDigitsFromPulse
110 if __name__ ==
'__main__':
114 from AthenaCommon.Logging
import log
115 from AthenaCommon
import Constants
116 log.setLevel(Constants.INFO)
118 from AthenaConfiguration.AllConfigFlags
import initConfigFlags
121 parser = flags.getArgumentParser(description=
'Run Tile pulse simulator. \
122 One can use it without input file and default conditions will be used. \
123 Or one can use --run to specify run number from which conditions should be used \
124 (probably conditions and geometries tags should be changed also in this case). \
125 Or one can use --filesInput to specify input file with HITS to take conditions from. \
126 Example: athena --CA RunTilePulseSim.py --evtMax 10')
128 parser.add_argument(
'--preExec', help=
'Code to execute before locking configs')
129 parser.add_argument(
'--postExec', help=
'Code to execute after setup')
130 parser.add_argument(
'--printDetailedConfig', action=
'store_true', help=
'Print detailed Athena configuration')
131 parser.add_argument(
'--outputDirectory', default=
'.', help=
'Output directory for produced files')
132 parser.add_argument(
'--outputVersion', type=str, default=
'0', help=
'Version to be used in output file for ntuple')
133 parser.add_argument(
'--nsamples', type=int, default=7, help=
'Number of samples')
134 parser.add_argument(
'--phaseII', type=bool, default=
False, help=
'Use parameters of TilePhaseII')
135 parser.add_argument(
'--run', type=int, default=410000, help=
'Run number')
136 parser.add_argument(
'--save-true-amplitude', action=
'store_true', help=
'Save true Tile raw channel amplitude into h2000')
137 parser.add_argument(
'--pulseChain', type=bool, default=
False, help=
'Simulate continuous output of readout across bunch crossings')
138 parser.add_argument(
'--acr-db', action=
'store_true', help=
'Use auto correlation matrix from DB')
140 args, _ = parser.parse_known_args()
142 flags.Tile.RunType = TileRunType.PHY
146 flags.Tile.doOpt2 =
False
147 flags.Tile.doOptATLAS =
False
148 flags.Tile.OfcFromCOOL =
False
150 flags.Tile.doOpt2 =
True
151 flags.Tile.doOptATLAS =
True
152 if args.nsamples != 7:
153 flags.Tile.OfcFromCOOL =
False
155 flags.Input.isMC =
True
156 flags.Input.Files = []
157 flags.Exec.MaxEvents = 3
160 flags.fillFromArgs(parser=parser)
162 if not flags.Input.Files:
163 flags.Input.RunNumbers = [args.run]
164 flags.Input.ConditionsRunNumber = args.run
165 flags.Input.OverrideRunNumber =
True
167 from AthenaConfiguration.TestDefaults
import defaultConditionsTags, defaultGeometryTags
168 flags.GeoModel.AtlasVersion = defaultGeometryTags.RUN3
169 flags.IOVDb.GlobalTag = defaultConditionsTags.RUN3_MC
172 log.info(
'Executing preExec: %s', args.preExec)
178 runNumber = flags.Input.RunNumbers[0]
180 from AthenaConfiguration.MainServicesConfig
import MainServicesCfg
183 if flags.Input.Files:
184 from AthenaPoolCnvSvc.PoolReadConfig
import PoolReadCfg
188 cfg.merge(
TileDigitsFromPulseCfg(flags, NSamples=args.nsamples, TilePhaseII=args.phaseII, SimulatePulseChain=args.pulseChain) )
191 from TileRecUtils.TileRawChannelMakerConfig
import TileRawChannelMakerCfg
193 if not flags.Tile.OfcFromCOOL:
194 rawChannelBuilders = cfg.getEventAlgo(
'TileRChMaker').TileRawChannelBuilder
195 for rawChannelBuilder
in rawChannelBuilders:
196 if hasattr(rawChannelBuilder,
'TileCondToolOfc'):
197 rawChannelBuilder.TileCondToolOfc.nSamples = args.nsamples
199 rawChannelBuilder.TileCondToolOfc.OptFilterDeltaCorrelation =
not args.acr_db
202 ntupleFile = f
'{args.outputDirectory}/tile_{runNumber}_{args.outputVersion}.aan.root'
203 from TileRec.TileAANtupleConfig
import TileAANtupleCfg
208 TileDigitsContainerFlt=
'',
209 TileDigitsContainer=
'TileDigitsCnt',
210 CalibrateEnergy=
False,
213 outputFile=ntupleFile) )
216 cfg.getEventAlgo(
'TileNtuple').NSamples = 1
217 cfg.getEventAlgo(
'TileNtuple').TileRawChannelContainer =
'TrueAmp'
219 cfg.getEventAlgo(
'TileNtuple').NSamples = args.nsamples
220 cfg.getEventAlgo(
'TileNtuple').TileRawChannelContainer=
'TileRawChannelCnt'
221 cfg.getEventAlgo(
'TileNtuple').TileRawChannelContainerOpt=
'TileRawChannelOpt2'
223 if args.save_true_amplitude:
224 cfg.getEventAlgo(
'TileNtuple').TileRawChannelContainerFit =
'TrueAmp'
228 log.info(
'Executing postExec: %s', args.postExec)
231 cfg.printConfig(withDetails=args.printDetailedConfig,
232 summariseProps=args.printDetailedConfig,
233 printDefaults=args.printDetailedConfig)
235 if not args.config_only:
237 sys.exit(0
if sc.isSuccess()
else 1)