3 from AthenaPython.PyAthenaComps
import Alg,StatusCode
8 from InDetMeasurementUtilities.CSV_DictFormats
import CSV_DictFormats
11 return f
"{outputDir}/{container}_event_{eventNumber}.csv"
15 Algorithm to load InDet tracks data from CSV files to xAOD collections
16 Conventions in files naming:
17 - the files should reside in one dir and alg needs to be pointed to it through indir property, the naming convention: container_event_XYZ.csv should be used
18 - files CSV format needs to be identical to the one used in export
19 - if a given file is missing the data is not loaded, just reporting in the log about it
20 - If need to modify this behavior, hey, go for it, it is python
23 Alg.__init__ (self, name)
29 if self.
indir is None:
30 self.msg.
error(
"Input directory not configured")
31 return StatusCode.Failure
32 if not os.path.exists(self.
indir):
33 self.msg.
error(
"Missing input directory %s", self.
indir)
34 return StatusCode.Failure
36 return StatusCode.Success
41 return StatusCode.Failure
43 return StatusCode.Success
46 ei = self.evtStore.
retrieve(
"xAOD::EventInfo",
"EventInfo")
47 return ei.eventNumber()
51 if not os.path.exists(inputFileName):
52 self.msg.warning(
"Missing file %s, this will result in missing collections in certain events which is not allowed by POOL &ROOT ", inputFileName)
53 return StatusCode.Recoverable
56 c = ROOT.xAOD.TrackParticleContainer()
57 aux = ROOT.xAOD.TrackParticleAuxContainer()
59 ROOT.SetOwnership (c,
False)
60 ROOT.SetOwnership (aux,
False)
63 with open(inputFileName,
"r")
as f:
64 reader = csv.DictReader(f)
65 for k
in reader.fieldnames:
66 if k
not in CSV_DictFormats[
"InDetTrackParticles"].
keys():
67 self.msg.
error(
"A key: %s found in data that does not seem to be known", k)
68 return StatusCode.Failure
71 tp = ROOT.xAOD.TrackParticle()
73 ROOT.SetOwnership (tp,
False)
74 covm = ROOT.xAOD.ParametersCovMatrix_t()
76 theta = 2.0 * math.atan( math.exp(-
float(data[
'eta'])))
77 tp.setDefiningParameters(
float(data[
'd0']),
float(data[
'z0']),
float(data[
'phi']),
79 float(data[
'charge']) * math.sin(theta)/
float(data[
'pt']))
80 tp.setDefiningParametersCovMatrix(covm)
84 return StatusCode.Failure
85 if not self.evtStore.record (aux, f
'{self.trackParticleName}Aux.',
False):
86 return StatusCode.Failure
88 return StatusCode.Success
92 from AthenaConfiguration.ComponentAccumulator
import ComponentAccumulator
93 from OutputStreamAthenaPool.OutputStreamConfig
import addToESD, addToAOD
100 algo.trackParticleName = trackParticleName
101 output = [f
'xAOD::TrackParticleContainer#{trackParticleName}', f
'xAOD::TrackParticleAuxContainer#{trackParticleName}Aux.']
102 algo.ExtraOutput = output[:1]
106 ca.addEventAlgo(algo)
110 if __name__ ==
'__main__':
111 from AthenaConfiguration.AllConfigFlags
import initConfigFlags
112 from AthenaConfiguration.MainServicesConfig
import MainServicesCfg
114 flags.addFlag(
'CSVInputDir',
'testdir')
115 flags.addFlag(
"TrackParticlesName",
'NewTP')
116 flags.Exec.MaxEvents=2
118 flags.Output.AODFileName=
"outAOD.pool.root"
123 from AthenaPoolCnvSvc.PoolReadConfig
import PoolReadCfg
126 acc.merge(
CSV_InDetImporterCfg(flags, indir=flags.CSVInputDir, trackParticleName=flags.TrackParticlesName))
128 acc.printConfig(withDetails=
True)
131 if status.isFailure():