Pandora
Pandora source code navigator
Loading...
Searching...
No Matches
XmlFileReader.cc
Go to the documentation of this file.
1
9#include "Api/PandoraApi.h"
10
11#include "Objects/CaloHit.h"
12#include "Objects/Track.h"
13
15
16namespace pandora
17{
18
19XmlFileReader::XmlFileReader(const pandora::Pandora &pandora, const std::string &fileName) :
20 FileReader(pandora, fileName),
21 m_pContainerXmlNode(nullptr),
22 m_pCurrentXmlElement(nullptr),
23 m_isAtFileStart(true)
24{
26 m_pXmlDocument = new TiXmlDocument(fileName);
27
29 {
30 std::cout << "XmlFileReader - Invalid xml file." << std::endl;
31 delete m_pXmlDocument;
32 throw StatusCodeException(STATUS_CODE_FAILURE);
33 }
34}
35
36//------------------------------------------------------------------------------------------------------------------------------------------
37
42
43//------------------------------------------------------------------------------------------------------------------------------------------
44
46{
47 m_pCurrentXmlElement = nullptr;
49
51 return STATUS_CODE_FAILURE;
52
53 return STATUS_CODE_SUCCESS;
54}
55
56//------------------------------------------------------------------------------------------------------------------------------------------
57
59{
60 m_pCurrentXmlElement = nullptr;
61
63 {
66
67 m_isAtFileStart = false;
68 }
69 else
70 {
72 throw StatusCodeException(STATUS_CODE_NOT_FOUND);
73
75 }
76
77 return STATUS_CODE_SUCCESS;
78}
79
80//------------------------------------------------------------------------------------------------------------------------------------------
81
83{
84 const std::string containerId((nullptr != m_pContainerXmlNode) ? m_pContainerXmlNode->ValueStr() : "");
85
86 if (std::string("Event") == containerId)
87 {
88 return EVENT_CONTAINER;
89 }
90 else if (std::string("Geometry") == containerId)
91 {
92 return GEOMETRY_CONTAINER;
93 }
94 else
95 {
96 return UNKNOWN_CONTAINER;
97 }
98}
99
100//------------------------------------------------------------------------------------------------------------------------------------------
101
102StatusCode XmlFileReader::GoToGeometry(const unsigned int geometryNumber)
103{
104 int nGeometriesRead(0);
105 m_isAtFileStart = true;
106 m_pContainerXmlNode = nullptr;
107 m_pCurrentXmlElement = nullptr;
108
110 --nGeometriesRead;
111
112 while (nGeometriesRead < static_cast<int>(geometryNumber))
113 {
114 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->GoToNextGeometry());
115 ++nGeometriesRead;
116 }
117
118 return STATUS_CODE_SUCCESS;
119}
120
121//------------------------------------------------------------------------------------------------------------------------------------------
122
123StatusCode XmlFileReader::GoToEvent(const unsigned int eventNumber)
124{
125 int nEventsRead(0);
126 m_isAtFileStart = true;
127 m_pContainerXmlNode = nullptr;
128 m_pCurrentXmlElement = nullptr;
129
130 if (EVENT_CONTAINER != this->GetNextContainerId())
131 --nEventsRead;
132
133 while (nEventsRead < static_cast<int>(eventNumber))
134 {
135 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->GoToNextEvent());
136 ++nEventsRead;
137 }
138
139 return STATUS_CODE_SUCCESS;
140}
141
142//------------------------------------------------------------------------------------------------------------------------------------------
143
145{
147 {
148 TiXmlHandle localHandle(m_pContainerXmlNode);
149 m_pCurrentXmlElement = localHandle.FirstChild().Element();
150 }
151 else
152 {
154 }
155
157 {
158 this->GoToNextContainer();
159 return STATUS_CODE_NOT_FOUND;
160 }
161
162 const std::string componentName(m_pCurrentXmlElement->ValueStr());
163
164 if (std::string("SubDetector") == componentName)
165 {
166 return this->ReadSubDetector();
167 }
168 if (std::string("LArTPC") == componentName)
169 {
170 return this->ReadLArTPC();
171 }
172 if (std::string("LineGap") == componentName)
173 {
174 return this->ReadLineGap();
175 }
176 else if (std::string("BoxGap") == componentName)
177 {
178 return this->ReadBoxGap();
179 }
180 else if (std::string("ConcentricGap") == componentName)
181 {
182 return this->ReadConcentricGap();
183 }
184 else
185 {
186 return STATUS_CODE_FAILURE;
187 }
188}
189
190//------------------------------------------------------------------------------------------------------------------------------------------
191
193{
195 {
196 TiXmlHandle localHandle(m_pContainerXmlNode);
197 m_pCurrentXmlElement = localHandle.FirstChild().Element();
198 }
199 else
200 {
202 }
203
205 {
206 this->GoToNextContainer();
207 return STATUS_CODE_NOT_FOUND;
208 }
209
210 const std::string componentName(m_pCurrentXmlElement->ValueStr());
211
212 if (std::string("CaloHit") == componentName)
213 {
214 return this->ReadCaloHit();
215 }
216 else if (std::string("Track") == componentName)
217 {
218 return this->ReadTrack();
219 }
220 else if (std::string("MCParticle") == componentName)
221 {
222 return this->ReadMCParticle();
223 }
224 else if (std::string("Relationship") == componentName)
225 {
226 return this->ReadRelationship();
227 }
228 else
229 {
230 return STATUS_CODE_FAILURE;
231 }
232}
233
234//------------------------------------------------------------------------------------------------------------------------------------------
235
237{
239 return STATUS_CODE_FAILURE;
240
242
243 try
244 {
245 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, m_pSubDetectorFactory->Read(*pParameters, *this));
246
247 std::string subDetectorName;
248 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("SubDetectorName", subDetectorName));
249 unsigned int subDetectorTypeInput(0);
250 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("SubDetectorType", subDetectorTypeInput));
251 const SubDetectorType subDetectorType(static_cast<SubDetectorType>(subDetectorTypeInput));
252 float innerRCoordinate(0.f);
253 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("InnerRCoordinate", innerRCoordinate));
254 float innerZCoordinate(0.f);
255 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("InnerZCoordinate", innerZCoordinate));
256 float innerPhiCoordinate(0.f);
257 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("InnerPhiCoordinate", innerPhiCoordinate));
258 unsigned int innerSymmetryOrder(0);
259 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("InnerSymmetryOrder", innerSymmetryOrder));
260 float outerRCoordinate(0.f);
261 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("OuterRCoordinate", outerRCoordinate));
262 float outerZCoordinate(0.f);
263 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("OuterZCoordinate", outerZCoordinate));
264 float outerPhiCoordinate(0.f);
265 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("OuterPhiCoordinate", outerPhiCoordinate));
266 unsigned int outerSymmetryOrder(0);
267 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("OuterSymmetryOrder", outerSymmetryOrder));
268 bool isMirroredInZ(false);
269 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("IsMirroredInZ", isMirroredInZ));
270 unsigned int nLayers(0);
271 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("NLayers", nLayers));
272
273 pParameters->m_subDetectorName = subDetectorName;
274 pParameters->m_subDetectorType = subDetectorType;
275 pParameters->m_innerRCoordinate = innerRCoordinate;
276 pParameters->m_innerZCoordinate = innerZCoordinate;
277 pParameters->m_innerPhiCoordinate = innerPhiCoordinate;
278 pParameters->m_innerSymmetryOrder = innerSymmetryOrder;
279 pParameters->m_outerRCoordinate = outerRCoordinate;
280 pParameters->m_outerZCoordinate = outerZCoordinate;
281 pParameters->m_outerPhiCoordinate = outerPhiCoordinate;
282 pParameters->m_outerSymmetryOrder = outerSymmetryOrder;
283 pParameters->m_isMirroredInZ = isMirroredInZ;
284 pParameters->m_nLayers = nLayers;
285
286 if (nLayers > 0)
287 {
288 FloatVector closestDistanceToIp, nRadiationLengths, nInteractionLengths;
289 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("ClosestDistanceToIp", closestDistanceToIp));
290 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("NRadiationLengths", nRadiationLengths));
291 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("NInteractionLengths", nInteractionLengths));
292
293 if ((closestDistanceToIp.size() != nLayers) || (nRadiationLengths.size() != nLayers) || (nInteractionLengths.size() != nLayers))
294 throw StatusCodeException(STATUS_CODE_FAILURE);
295
296 for (unsigned int iLayer = 0; iLayer < nLayers; ++iLayer)
297 {
299 layerParameters.m_closestDistanceToIp = closestDistanceToIp[iLayer];
300 layerParameters.m_nRadiationLengths = nRadiationLengths[iLayer];
301 layerParameters.m_nInteractionLengths = nInteractionLengths[iLayer];
302 pParameters->m_layerParametersVector.push_back(layerParameters);
303 }
304 }
305
307 delete pParameters;
308 }
309 catch (StatusCodeException &statusCodeException)
310 {
311 delete pParameters;
312 return statusCodeException.GetStatusCode();
313 }
314
315 return STATUS_CODE_SUCCESS;
316}
317
318//------------------------------------------------------------------------------------------------------------------------------------------
319
321{
323 return STATUS_CODE_FAILURE;
324
326
327 try
328 {
329 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, m_pLArTPCFactory->Read(*pParameters, *this));
330
331 unsigned int larTPCVolumeId;
332 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("LArTPCVolumeId", larTPCVolumeId));
333 float centerX(0.f);
334 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("CenterX", centerX));
335 float centerY(0.f);
336 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("CenterY", centerY));
337 float centerZ(0.f);
338 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("CenterZ", centerZ));
339 float widthX(0.f);
340 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("WidthX", widthX));
341 float widthY(0.f);
342 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("WidthY", widthY));
343 float widthZ(0.f);
344 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("WidthZ", widthZ));
345 float wirePitchU(0.f);
346 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("WirePitchU", wirePitchU));
347 float wirePitchV(0.f);
348 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("WirePitchV", wirePitchV));
349 float wirePitchW(0.f);
350 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("WirePitchW", wirePitchW));
351 float wireAngleU(0.f);
352 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("WireAngleU", wireAngleU));
353 float wireAngleV(0.f);
354 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("WireAngleV", wireAngleV));
355 float wireAngleW(0.f);
356 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("WireAngleW", wireAngleW));
357 float sigmaUVW(0.f);
358 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("SigmaUVW", sigmaUVW));
359 bool isDriftInPositiveX(false);
360 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("IsDriftInPositiveX", isDriftInPositiveX));
361
362 pParameters->m_larTPCVolumeId = larTPCVolumeId;
363 pParameters->m_centerX = centerX;
364 pParameters->m_centerY = centerY;
365 pParameters->m_centerZ = centerZ;
366 pParameters->m_widthX = widthX;
367 pParameters->m_widthY = widthY;
368 pParameters->m_widthZ = widthZ;
369 pParameters->m_wirePitchU = wirePitchU;
370 pParameters->m_wirePitchV = wirePitchV;
371 pParameters->m_wirePitchW = wirePitchW;
372 pParameters->m_wireAngleU = wireAngleU;
373 pParameters->m_wireAngleV = wireAngleV;
374 pParameters->m_wireAngleW = wireAngleW;
375 pParameters->m_sigmaUVW = sigmaUVW;
376 pParameters->m_isDriftInPositiveX = isDriftInPositiveX;
377
379 delete pParameters;
380 }
381 catch (StatusCodeException &statusCodeException)
382 {
383 delete pParameters;
384 return statusCodeException.GetStatusCode();
385 }
386
387 return STATUS_CODE_SUCCESS;
388}
389
390//------------------------------------------------------------------------------------------------------------------------------------------
391
393{
395 return STATUS_CODE_FAILURE;
396
398
399 try
400 {
401 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, m_pLineGapFactory->Read(*pParameters, *this));
402
403 unsigned int lineGapTypeInput(0);
404 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("LineGapType", lineGapTypeInput));
405 const LineGapType lineGapType(static_cast<LineGapType>(lineGapTypeInput));
406 float lineStartX(0.f);
407 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("LineStartX", lineStartX));
408 float lineEndX(0.f);
409 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("LineEndX", lineEndX));
410 float lineStartZ(0.f);
411 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("LineStartZ", lineStartZ));
412 float lineEndZ(0.f);
413 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("LineEndZ", lineEndZ));
414
415 pParameters->m_lineGapType = lineGapType;
416 pParameters->m_lineStartX = lineStartX;
417 pParameters->m_lineEndX = lineEndX;
418 pParameters->m_lineStartZ = lineStartZ;
419 pParameters->m_lineEndZ = lineEndZ;
421 delete pParameters;
422 }
423 catch (StatusCodeException &statusCodeException)
424 {
425 delete pParameters;
426 return statusCodeException.GetStatusCode();
427 }
428
429 return STATUS_CODE_SUCCESS;
430}
431
432//------------------------------------------------------------------------------------------------------------------------------------------
433
435{
437 return STATUS_CODE_FAILURE;
438
440
441 try
442 {
443 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, m_pBoxGapFactory->Read(*pParameters, *this));
444
445 CartesianVector vertex(0.f, 0.f, 0.f);
446 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("Vertex", vertex));
447 CartesianVector side1(0.f, 0.f, 0.f);
448 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("Side1", side1));
449 CartesianVector side2(0.f, 0.f, 0.f);
450 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("Side2", side2));
451 CartesianVector side3(0.f, 0.f, 0.f);
452 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("Side3", side3));
453
454 pParameters->m_vertex = vertex;
455 pParameters->m_side1 = side1;
456 pParameters->m_side2 = side2;
457 pParameters->m_side3 = side3;
459 delete pParameters;
460 }
461 catch (StatusCodeException &statusCodeException)
462 {
463 delete pParameters;
464 return statusCodeException.GetStatusCode();
465 }
466
467 return STATUS_CODE_SUCCESS;
468}
469
470//------------------------------------------------------------------------------------------------------------------------------------------
471
473{
475 return STATUS_CODE_FAILURE;
476
478
479 try
480 {
481 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, m_pConcentricGapFactory->Read(*pParameters, *this));
482
483 float minZCoordinate(0.f);
484 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("MinZCoordinate", minZCoordinate));
485 float maxZCoordinate(0.f);
486 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("MaxZCoordinate", maxZCoordinate));
487 float innerRCoordinate(0.f);
488 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("InnerRCoordinate", innerRCoordinate));
489 float innerPhiCoordinate(0.f);
490 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("InnerPhiCoordinate", innerPhiCoordinate));
491 unsigned int innerSymmetryOrder(0);
492 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("InnerSymmetryOrder", innerSymmetryOrder));
493 float outerRCoordinate(0.f);
494 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("OuterRCoordinate", outerRCoordinate));
495 float outerPhiCoordinate(0.f);
496 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("OuterPhiCoordinate", outerPhiCoordinate));
497 unsigned int outerSymmetryOrder(0);
498 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("OuterSymmetryOrder", outerSymmetryOrder));
499
500 pParameters->m_minZCoordinate = minZCoordinate;
501 pParameters->m_maxZCoordinate = maxZCoordinate;
502 pParameters->m_innerRCoordinate = innerRCoordinate;
503 pParameters->m_innerPhiCoordinate = innerPhiCoordinate;
504 pParameters->m_innerSymmetryOrder = innerSymmetryOrder;
505 pParameters->m_outerRCoordinate = outerRCoordinate;
506 pParameters->m_outerPhiCoordinate = outerPhiCoordinate;
507 pParameters->m_outerSymmetryOrder = outerSymmetryOrder;
509 delete pParameters;
510 }
511 catch (StatusCodeException &statusCodeException)
512 {
513 delete pParameters;
514 return statusCodeException.GetStatusCode();
515 }
516
517 return STATUS_CODE_SUCCESS;
518}
519
520//------------------------------------------------------------------------------------------------------------------------------------------
521
523{
525 return STATUS_CODE_FAILURE;
526
527 PandoraApi::CaloHit::Parameters *pParameters = m_pCaloHitFactory->NewParameters();
528
529 try
530 {
531 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, m_pCaloHitFactory->Read(*pParameters, *this));
532
533 unsigned int cellGeometryInput(0);
534 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("CellGeometry", cellGeometryInput));
535 const CellGeometry cellGeometry(static_cast<CellGeometry>(cellGeometryInput));
536 CartesianVector positionVector(0.f, 0.f, 0.f);
537 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("PositionVector", positionVector));
538 CartesianVector expectedDirection(0.f, 0.f, 0.f);
539 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("ExpectedDirection", expectedDirection));
540 CartesianVector cellNormalVector(0.f, 0.f, 0.f);
541 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("CellNormalVector", cellNormalVector));
542 float cellThickness(0.f);
543 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("CellThickness", cellThickness));
544 float nCellRadiationLengths(0.f);
545 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("NCellRadiationLengths", nCellRadiationLengths));
546 float nCellInteractionLengths(0.f);
547 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("NCellInteractionLengths", nCellInteractionLengths));
548 float time(0.f);
549 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("Time", time));
550 float inputEnergy(0.f);
551 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("InputEnergy", inputEnergy));
552 float mipEquivalentEnergy(0.f);
553 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("MipEquivalentEnergy", mipEquivalentEnergy));
554 float electromagneticEnergy(0.f);
555 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("ElectromagneticEnergy", electromagneticEnergy));
556 float hadronicEnergy(0.f);
557 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("HadronicEnergy", hadronicEnergy));
558 bool isDigital(false);
559 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("IsDigital", isDigital));
560 unsigned int hitTypeInput(0);
561 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("HitType", hitTypeInput));
562 const HitType hitType(static_cast<HitType>(hitTypeInput));
563 unsigned int hitRegionInput(0);
564 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("HitRegion", hitRegionInput));
565 const HitRegion hitRegion(static_cast<HitRegion>(hitRegionInput));
566 unsigned int layer(0);
567 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("Layer", layer));
568 bool isInOuterSamplingLayer(false);
569 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("IsInOuterSamplingLayer", isInOuterSamplingLayer));
570 const void *pParentAddress(nullptr);
571 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("ParentCaloHitAddress", pParentAddress));
572 float cellSize0(0.f);
573 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("CellSize0", cellSize0));
574 float cellSize1(0.f);
575 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("CellSize1", cellSize1));
576
577 pParameters->m_positionVector = positionVector;
578 pParameters->m_expectedDirection = expectedDirection;
579 pParameters->m_cellNormalVector = cellNormalVector;
580 pParameters->m_cellGeometry = cellGeometry;
581 pParameters->m_cellSize0 = cellSize0;
582 pParameters->m_cellSize1 = cellSize1;
583 pParameters->m_cellThickness = cellThickness;
584 pParameters->m_nCellRadiationLengths = nCellRadiationLengths;
585 pParameters->m_nCellInteractionLengths = nCellInteractionLengths;
586 pParameters->m_time = time;
587 pParameters->m_inputEnergy = inputEnergy;
588 pParameters->m_mipEquivalentEnergy = mipEquivalentEnergy;
589 pParameters->m_electromagneticEnergy = electromagneticEnergy;
590 pParameters->m_hadronicEnergy = hadronicEnergy;
591 pParameters->m_isDigital = isDigital;
592 pParameters->m_hitType = hitType;
593 pParameters->m_hitRegion = hitRegion;
594 pParameters->m_layer = layer;
595 pParameters->m_isInOuterSamplingLayer = isInOuterSamplingLayer;
596 pParameters->m_pParentAddress = pParentAddress;
597 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraApi::CaloHit::Create(*m_pPandora, *pParameters, *m_pCaloHitFactory));
598 delete pParameters;
599 }
600 catch (StatusCodeException &statusCodeException)
601 {
602 delete pParameters;
603 return statusCodeException.GetStatusCode();
604 }
605
606 return STATUS_CODE_SUCCESS;
607}
608
609//------------------------------------------------------------------------------------------------------------------------------------------
610
612{
614 return STATUS_CODE_FAILURE;
615
616 PandoraApi::Track::Parameters *pParameters = m_pTrackFactory->NewParameters();
617
618 try
619 {
620 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, m_pTrackFactory->Read(*pParameters, *this));
621
622 float d0(0.f);
623 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("D0", d0));
624 float z0(0.f);
625 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("Z0", z0));
626 int particleId(0);
627 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("ParticleId", particleId));
628 int charge(0);
629 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("Charge", charge));
630 float mass(0.f);
631 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("Mass", mass));
632 CartesianVector momentumAtDca(0.f, 0.f, 0.f);
633 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("MomentumAtDca", momentumAtDca));
634 TrackState trackStateAtStart(0.f, 0.f, 0.f, 0.f, 0.f, 0.f);
635 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("TrackStateAtStart", trackStateAtStart));
636 TrackState trackStateAtEnd(0.f, 0.f, 0.f, 0.f, 0.f, 0.f);
637 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("TrackStateAtEnd", trackStateAtEnd));
638 TrackState trackStateAtCalorimeter(0.f, 0.f, 0.f, 0.f, 0.f, 0.f);
639 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("TrackStateAtCalorimeter", trackStateAtCalorimeter));
640 float timeAtCalorimeter(0.f);
641 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("TimeAtCalorimeter", timeAtCalorimeter));
642 bool reachesCalorimeter(false);
643 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("ReachesCalorimeter", reachesCalorimeter));
644 bool isProjectedToEndCap(false);
645 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("IsProjectedToEndCap", isProjectedToEndCap));
646 bool canFormPfo(false);
647 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("CanFormPfo", canFormPfo));
648 bool canFormClusterlessPfo(false);
649 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("CanFormClusterlessPfo", canFormClusterlessPfo));
650 const void *pParentAddress(nullptr);
651 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("ParentTrackAddress", pParentAddress));
652
653 pParameters->m_d0 = d0;
654 pParameters->m_z0 = z0;
655 pParameters->m_particleId = particleId;
656 pParameters->m_charge = charge;
657 pParameters->m_mass = mass;
658 pParameters->m_momentumAtDca = momentumAtDca;
659 pParameters->m_trackStateAtStart = trackStateAtStart;
660 pParameters->m_trackStateAtEnd = trackStateAtEnd;
661 pParameters->m_trackStateAtCalorimeter = trackStateAtCalorimeter;
662 pParameters->m_timeAtCalorimeter = timeAtCalorimeter;
663 pParameters->m_reachesCalorimeter = reachesCalorimeter;
664 pParameters->m_isProjectedToEndCap = isProjectedToEndCap;
665 pParameters->m_canFormPfo = canFormPfo;
666 pParameters->m_canFormClusterlessPfo = canFormClusterlessPfo;
667 pParameters->m_pParentAddress = pParentAddress;
668 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraApi::Track::Create(*m_pPandora, *pParameters, *m_pTrackFactory));
669 delete pParameters;
670 }
671 catch (StatusCodeException &statusCodeException)
672 {
673 delete pParameters;
674 return statusCodeException.GetStatusCode();
675 }
676
677 return STATUS_CODE_SUCCESS;
678}
679
680//------------------------------------------------------------------------------------------------------------------------------------------
681
683{
685 return STATUS_CODE_FAILURE;
686
687 PandoraApi::MCParticle::Parameters *pParameters = m_pMCParticleFactory->NewParameters();
688
689 try
690 {
691 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, m_pMCParticleFactory->Read(*pParameters, *this));
692
693 float energy(0.f);
694 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("Energy", energy));
695 CartesianVector momentum(0.f, 0.f, 0.f);
696 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("Momentum", momentum));
697 CartesianVector vertex(0.f, 0.f, 0.f);
698 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("Vertex", vertex));
699 CartesianVector endpoint(0.f, 0.f, 0.f);
700 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("Endpoint", endpoint));
701 int particleId(-std::numeric_limits<int>::max());
702 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("ParticleId", particleId));
703 unsigned int mcParticleTypeInput(0);
704 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("MCParticleType", mcParticleTypeInput));
705 const MCParticleType mcParticleType(static_cast<MCParticleType>(mcParticleTypeInput));
706 const void *pParentAddress(nullptr);
707 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("Uid", pParentAddress));
708
709 pParameters->m_energy = energy;
710 pParameters->m_momentum = momentum;
711 pParameters->m_vertex = vertex;
712 pParameters->m_endpoint = endpoint;
713 pParameters->m_particleId = particleId;
714 pParameters->m_mcParticleType = mcParticleType;
715 pParameters->m_pParentAddress = pParentAddress;
716 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraApi::MCParticle::Create(*m_pPandora, *pParameters, *m_pMCParticleFactory));
717 delete pParameters;
718 }
719 catch (StatusCodeException &statusCodeException)
720 {
721 delete pParameters;
722 return statusCodeException.GetStatusCode();
723 }
724
725 return STATUS_CODE_SUCCESS;
726}
727
728//------------------------------------------------------------------------------------------------------------------------------------------
729
731{
733 return STATUS_CODE_FAILURE;
734
735 unsigned int relationshipIdInput(0);
736 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("RelationshipId", relationshipIdInput));
737 const RelationshipId relationshipId(static_cast<RelationshipId>(relationshipIdInput));
738 const void *address1(nullptr);
739 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("Address1", address1));
740 const void *address2(nullptr);
741 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("Address2", address2));
742 float weight(1.f);
743 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable("Weight", weight));
744
745 switch (relationshipId)
746 {
748 return PandoraApi::SetCaloHitToMCParticleRelationship(*m_pPandora, address1, address2, weight);
750 return PandoraApi::SetTrackToMCParticleRelationship(*m_pPandora, address1, address2, weight);
752 return PandoraApi::SetMCParentDaughterRelationship(*m_pPandora, address1, address2);
756 return PandoraApi::SetTrackSiblingRelationship(*m_pPandora, address1, address2);
757 default:
758 return STATUS_CODE_FAILURE;
759 }
760
761 return STATUS_CODE_SUCCESS;
762}
763
764} // namespace pandora
Header file for the calo hit class.
Header file for the pandora api class.
#define PANDORA_THROW_RESULT_IF(StatusCode1, Operator, Command)
Definition StatusCodes.h:43
#define PANDORA_RETURN_RESULT_IF(StatusCode1, Operator, Command)
Definition StatusCodes.h:19
Header file for the track class.
Header file for the xml file reader class.
static pandora::StatusCode SetTrackToMCParticleRelationship(const pandora::Pandora &pandora, const void *const pTrackParentAddress, const void *const pMCParticleParentAddress, const float mcParticleWeight=1)
Set track to mc particle relationship.
Definition PandoraApi.cc:76
static pandora::StatusCode SetMCParentDaughterRelationship(const pandora::Pandora &pandora, const void *const pParentAddress, const void *const pDaughterAddress)
Set parent-daughter mc particle relationship.
Definition PandoraApi.cc:44
static pandora::StatusCode SetCaloHitToMCParticleRelationship(const pandora::Pandora &pandora, const void *const pCaloHitParentAddress, const void *const pMCParticleParentAddress, const float mcParticleWeight=1)
Set calo hit to mc particle relationship.
Definition PandoraApi.cc:68
static pandora::StatusCode SetTrackSiblingRelationship(const pandora::Pandora &pandora, const void *const pFirstSiblingAddress, const void *const pSecondSiblingAddress)
Set sibling track relationship.
Definition PandoraApi.cc:60
static pandora::StatusCode SetTrackParentDaughterRelationship(const pandora::Pandora &pandora, const void *const pParentAddress, const void *const pDaughterAddress)
Set parent-daughter track relationship.
Definition PandoraApi.cc:52
pandora::InputFloat m_closestDistanceToIp
Closest distance of the layer from the interaction point, units mm.
pandora::InputFloat m_nRadiationLengths
Absorber material in front of layer, units radiation lengths.
pandora::InputFloat m_nInteractionLengths
Absorber material in front of layer, units interaction lengths.
static pandora::StatusCode Create(const pandora::Pandora &pandora, const Parameters &parameters, const pandora::ObjectFactory< Parameters, Object > &factory=pandora::PandoraObjectFactory< Parameters, Object >())
Create a new object from a user factory.
CartesianVector class.
FileReader class.
Definition FileReader.h:29
StatusCode GoToNextGeometry()
Skip to next geometry container in the file.
Definition FileReader.cc:84
StatusCode GoToNextEvent()
Skip to next event container in the file.
Definition FileReader.cc:97
virtual Parameters * NewParameters() const =0
Create new parameters instance on the heap (memory-management to be controlled by user)
virtual StatusCode Read(Parameters &parameters, FileReader &fileReader) const =0
Read any additional (derived class only) object parameters from file using the specified file reader.
Pandora class.
Definition Pandora.h:40
ObjectFactory< object_creation::Geometry::BoxGap::Parameters, object_creation::Geometry::BoxGap::Object > * m_pBoxGapFactory
Address of the box gap factory.
Definition Persistency.h:84
ContainerId m_containerId
The type of container currently being written to file.
Definition Persistency.h:76
const Pandora *const m_pPandora
Address of pandora instance to be used alongside the file writer.
Definition Persistency.h:73
ObjectFactory< object_creation::MCParticle::Parameters, object_creation::MCParticle::Object > * m_pMCParticleFactory
Address of the mc particle factory.
Definition Persistency.h:80
ObjectFactory< object_creation::Geometry::LArTPC::Parameters, object_creation::Geometry::LArTPC::Object > * m_pLArTPCFactory
Address of the lar tpc factory.
Definition Persistency.h:82
ObjectFactory< object_creation::Track::Parameters, object_creation::Track::Object > * m_pTrackFactory
Address of the track factory.
Definition Persistency.h:79
ObjectFactory< object_creation::CaloHit::Parameters, object_creation::CaloHit::Object > * m_pCaloHitFactory
Address of the calo hit factory.
Definition Persistency.h:78
ObjectFactory< object_creation::Geometry::LineGap::Parameters, object_creation::Geometry::LineGap::Object > * m_pLineGapFactory
Address of the line gap factory.
Definition Persistency.h:83
ObjectFactory< object_creation::Geometry::ConcentricGap::Parameters, object_creation::Geometry::ConcentricGap::Object > * m_pConcentricGapFactory
Address of the concentric gap factory.
Definition Persistency.h:85
ObjectFactory< object_creation::Geometry::SubDetector::Parameters, object_creation::Geometry::SubDetector::Object > * m_pSubDetectorFactory
Address of the sub detector factory.
Definition Persistency.h:81
FileType m_fileType
The file type.
Definition Persistency.h:75
StatusCodeException class.
StatusCode GetStatusCode() const
Get status code.
bool LoadFile(TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
Definition tinyxml.cc:957
TiXmlHandle FirstChildElement() const
Return a handle to the first child element.
Definition tinyxml.cc:1659
TiXmlElement * Element() const
Definition tinyxml.h:1710
TiXmlHandle FirstChild() const
Return a handle to the first child node.
Definition tinyxml.cc:1635
const std::string & ValueStr() const
Definition tinyxml.h:501
const TiXmlElement * NextSiblingElement() const
Definition tinyxml.cc:485
const TiXmlNode * NextSibling(const std::string &_value) const
STL std::string form.
Definition tinyxml.h:633
TrackState class.
Definition TrackState.h:22
StatusCode ReadCaloHit()
Read a calo hit from the current position in the file, recreating the stored object.
StatusCode ReadNextGeometryComponent()
Read the next pandora geometry component from the current position in the file, recreating the stored...
StatusCode ReadRelationship()
Read a relationship from the current position in the file, recreating the stored relationship.
~XmlFileReader()
Destructor.
StatusCode ReadBoxGap()
Read a box gap from the current position in the file.
StatusCode GoToEvent(const unsigned int eventNumber)
Skip to a specified event number in the file.
StatusCode GoToGeometry(const unsigned int geometryNumber)
Skip to a specified geometry number in the file.
TiXmlNode * m_pContainerXmlNode
The document xml node.
StatusCode ReadLineGap()
Read a line gap from the current position in the file.
StatusCode ReadConcentricGap()
Read a concentric gap from the current position in the file.
XmlFileReader(const pandora::Pandora &pandora, const std::string &fileName)
Constructor.
StatusCode ReadVariable(const std::string &xmlKey, T &t)
Read a variable from the file.
StatusCode ReadNextEventComponent()
Read the next pandora event component from the current position in the file, recreating the stored co...
TiXmlDocument * m_pXmlDocument
The xml document.
StatusCode ReadLArTPC()
Read a lar tpc from the current position in the file.
StatusCode ReadMCParticle()
Read a mc particle from the current position in the file, recreating the stored object.
StatusCode GoToNextContainer()
Skip to next container in the file.
StatusCode ReadSubDetector()
Read a sub detector from the current position in the file.
bool m_isAtFileStart
Whether reader is at file start.
StatusCode ReadHeader()
Read the container header from the current position in the file, checking for properly written contai...
StatusCode ReadTrack()
Read a track from the current position in the file, recreating the stored object.
ContainerId GetNextContainerId()
Get the id of the next container in the file without changing the current position in the file.
TiXmlElement * m_pCurrentXmlElement
The current xml element.
HitType
Calorimeter hit type enum.
HitRegion
Calorimeter hit region enum.
RelationshipId
The relationship identification enum.
Definition PandoraIO.h:57
@ TRACK_TO_MC_RELATIONSHIP
Definition PandoraIO.h:59
@ CALO_HIT_TO_MC_RELATIONSHIP
Definition PandoraIO.h:58
@ TRACK_SIBLING_RELATIONSHIP
Definition PandoraIO.h:62
@ TRACK_PARENT_DAUGHTER_RELATIONSHIP
Definition PandoraIO.h:61
@ MC_PARENT_DAUGHTER_RELATIONSHIP
Definition PandoraIO.h:60
CellGeometry
Cell geometry enum.
ContainerId
The container identification enum.
Definition PandoraIO.h:24
@ EVENT_CONTAINER
Definition PandoraIO.h:25
@ UNKNOWN_CONTAINER
Definition PandoraIO.h:27
@ GEOMETRY_CONTAINER
Definition PandoraIO.h:26
std::vector< float > FloatVector
MCParticleType
MC particle type enum.
StatusCode
The StatusCode enum.
SubDetectorType
Subdetector type enum.
LineGapType
Line gap type.