ATLAS Offline Software
Loading...
Searching...
No Matches
CSV_InDetImporter.CSV_InDetImporterAlg Class Reference
Inheritance diagram for CSV_InDetImporter.CSV_InDetImporterAlg:
Collaboration diagram for CSV_InDetImporter.CSV_InDetImporterAlg:

Public Member Functions

 __init__ (self, name)
 initialize (self)
 execute (self)
 getEventNumber (self)
 readTrackParticle (self)

Public Attributes

 indir = None
 trackParticleName = None

Detailed Description

Algorithm to load InDet tracks data from CSV files to xAOD collections
Conventions in files naming:
 - 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
 - files CSV format needs to be identical to the one used in export
 - if a given file is missing the data is not loaded, just reporting in the log about it
 - If need to modify this behavior, hey, go for it, it is python

Definition at line 13 of file CSV_InDetImporter.py.

Constructor & Destructor Documentation

◆ __init__()

CSV_InDetImporter.CSV_InDetImporterAlg.__init__ ( self,
name )

Definition at line 22 of file CSV_InDetImporter.py.

22 def __init__(self, name):
23 Alg.__init__ (self, name)
24 self.indir = None
25 self.trackParticleName = None
26 return
27

Member Function Documentation

◆ execute()

CSV_InDetImporter.CSV_InDetImporterAlg.execute ( self)

Definition at line 38 of file CSV_InDetImporter.py.

38 def execute(self):
39 if self.trackParticleName:
40 if not self.readTrackParticle():
41 return StatusCode.Failure
42
43 return StatusCode.Success
44

◆ getEventNumber()

CSV_InDetImporter.CSV_InDetImporterAlg.getEventNumber ( self)

Definition at line 45 of file CSV_InDetImporter.py.

45 def getEventNumber(self):
46 ei = self.evtStore.retrieve("xAOD::EventInfo", "EventInfo")
47 return ei.eventNumber()
48

◆ initialize()

CSV_InDetImporter.CSV_InDetImporterAlg.initialize ( self)

Definition at line 28 of file CSV_InDetImporter.py.

28 def initialize(self):
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
35
36 return StatusCode.Success
37
void initialize()

◆ readTrackParticle()

CSV_InDetImporter.CSV_InDetImporterAlg.readTrackParticle ( self)

Definition at line 49 of file CSV_InDetImporter.py.

49 def readTrackParticle(self):
50 inputFileName = getCSVFilename(self.indir, self.trackParticleName, self.getEventNumber())
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
54
55
56 c = ROOT.xAOD.TrackParticleContainer()
57 aux = ROOT.xAOD.TrackParticleAuxContainer()
58 c.setStore (aux)
59 ROOT.SetOwnership (c,False)
60 ROOT.SetOwnership (aux,False)
61
62 # data reading
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
69
70 for data in reader:
71 tp = ROOT.xAOD.TrackParticle()
72 c.push_back(tp)
73 ROOT.SetOwnership (tp, False)
74 covm = ROOT.xAOD.ParametersCovMatrix_t()
75 covm.setZero()
76 theta = 2.0 * math.atan( math.exp(-float(data['eta'])))
77 tp.setDefiningParameters(float(data['d0']), float(data['z0']), float(data['phi']),
78 theta,
79 float(data['charge']) * math.sin(theta)/float(data['pt']))
80 tp.setDefiningParametersCovMatrix(covm)
81 pass
82
83 if not self.evtStore.record (c, self.trackParticleName, False):
84 return StatusCode.Failure
85 if not self.evtStore.record (aux, f'{self.trackParticleName}Aux.', False):
86 return StatusCode.Failure
87
88 return StatusCode.Success
89
90

Member Data Documentation

◆ indir

CSV_InDetImporter.CSV_InDetImporterAlg.indir = None

Definition at line 24 of file CSV_InDetImporter.py.

◆ trackParticleName

CSV_InDetImporter.CSV_InDetImporterAlg.trackParticleName = None

Definition at line 25 of file CSV_InDetImporter.py.


The documentation for this class was generated from the following file: