ATLAS Offline Software
TruthSegmentCsvDumperAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
9 #include "GaudiKernel/SystemOfUnits.h"
10 
11 #include <fstream>
12 #include <TString.h>
13 
14 #include <unordered_map>
15 
16 namespace MuonR4{
17 TruthSegmentCsvDumperAlg::TruthSegmentCsvDumperAlg(const std::string& name, ISvcLocator* pSvcLocator):
18  AthAlgorithm{name, pSvcLocator} {}
20  ATH_CHECK(m_inSegmentKey.initialize());
21  ATH_CHECK(m_idHelperSvc.retrieve());
23  return StatusCode::SUCCESS;
24 }
25 
27  const EventContext & context = Gaudi::Hive::currentContext();
28  std::ofstream file{std::string(Form("event%09zu-",++m_event))+"MuonTruthSegment.csv"};
29  const std::string delim = ",";
30 
31  file<<"GlobalPositionCentroidX"<<delim<<"GlobalPositionCentroidY"<<delim<<"GlobalPositionCentroidZ"<<delim;
32  file<<"GlobalDirectionX"<<delim<<"GlobalDirectionY"<<delim<<"GlobalDirectionZ"<<delim;
33  file<<"Time"<<delim<<"TimeError"<<delim;
34  file<<"ChiSquared"<<delim<<"NumberDoF"<<delim;
35  file<<"PrecisionHits"<<delim<<"PhiLayers"<<delim<<"TrigEtaLayers"<<delim;
36  file<<"Sector"<<delim <<"Eta"<<delim<<"Chamber"<<delim<<"Technology"<<std::endl;
37 
39  if(!readTruthSegment.isValid()){
40  ATH_MSG_FATAL("Failed to retrieve truth segment container");
41  return StatusCode::FAILURE;
42  }
43 
44  ATH_CHECK(readTruthSegment.isPresent());
45  for (const xAOD::MuonSegment* segment : *readTruthSegment) {
46  // Segment information
47  float seg_x = segment->x();
48  float seg_y = segment->y();
49  float seg_z = segment->z();
50  float seg_px = segment->px();
51  float seg_py = segment->py();
52  float seg_pz = segment->pz();
53 
54  // time information
55  float seg_t0 = segment->t0();
56  float seg_t0error = segment->t0error();
57 
58  // Fit quality information
59  float seg_chiSquared = segment->chiSquared();
60  float seg_numberDoF = segment->numberDoF();
61 
62  // nHits
63  int seg_PrecisionHits = segment->nPrecisionHits();
64  int seg_PhiLayers = segment->nPhiLayers();
65  int seg_TrigEtaLayers = segment->nTrigEtaLayers();
66 
67  // Detector information
68  int seg_sector = segment->sector();
69  int seg_eta = segment->etaIndex();
70  Muon::MuonStationIndex::ChIndex seg_chamber = segment->chamberIndex();
71  Muon::MuonStationIndex::TechnologyIndex seg_tec = segment->technology();
72 
73  // verbose some information to check
74  ATH_MSG_VERBOSE("x: "<<seg_x<<" y: "<<seg_y<<" z: "<<seg_z);
75  ATH_MSG_VERBOSE("px: "<<seg_px<<" py: "<<seg_py<<" pz: "<<seg_pz);
76  ATH_MSG_VERBOSE("t0: "<<seg_t0<<" t0error: "<<seg_t0error);
77  ATH_MSG_VERBOSE("chiSquared: "<<seg_chiSquared<<" numberDoF: "<<seg_numberDoF);
78  ATH_MSG_VERBOSE("nPrecisionHits: "<<seg_PrecisionHits<<" nPhiLayers: "<<seg_PhiLayers<<" nTrigEtaLayers: "<<seg_TrigEtaLayers);
79  ATH_MSG_VERBOSE("sector: "<<seg_sector<<" eta: "<<seg_eta);
80  ATH_MSG_VERBOSE("chamber: "<<seg_chamber<<"technology: "<<seg_tec);
81 
82  // save the segment information to the csv file
83  file<<seg_x<<delim<<seg_y<<delim<<seg_z<<delim;
84  file<<seg_px<<delim<<seg_py<<delim<<seg_pz<<delim;
85  file<<seg_t0<<delim<<seg_t0error<<delim;
86  file<<seg_chiSquared<<delim<<seg_numberDoF<<delim;
87  file<<seg_PrecisionHits<<delim<<seg_PhiLayers<<delim<<seg_TrigEtaLayers<<delim;
88  file<<seg_sector<<delim<<seg_eta<<delim<<seg_chamber<<delim<<seg_tec<<std::endl;
89 
90  }
91  return StatusCode::SUCCESS;
92 }
93 
94 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
MuonR4::TruthSegmentCsvDumperAlg::m_r4DetMgr
const MuonGMR4::MuonDetectorManager * m_r4DetMgr
Definition: TruthSegmentCsvDumperAlg.h:29
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
MuonR4::TruthSegmentCsvDumperAlg::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Definition: TruthSegmentCsvDumperAlg.h:27
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
xAOD::MuonSegment_v1
Class describing a MuonSegment.
Definition: MuonSegment_v1.h:33
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
SpectrometerSector.h
AthCommonDataStore< AthCommonMsg< Algorithm > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
MuonR4::TruthSegmentCsvDumperAlg::execute
StatusCode execute() override
Definition: TruthSegmentCsvDumperAlg.cxx:26
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
file
TFile * file
Definition: tile_monitor.h:29
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
MuonR4::TruthSegmentCsvDumperAlg::m_inSegmentKey
SG::ReadHandleKey< xAOD::MuonSegmentContainer > m_inSegmentKey
Definition: TruthSegmentCsvDumperAlg.h:25
AthAlgorithm
Definition: AthAlgorithm.h:47
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
MuonR4::TruthSegmentCsvDumperAlg::m_event
size_t m_event
Definition: TruthSegmentCsvDumperAlg.h:30
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
MuonR4
This header ties the generic definitions in this package.
Definition: HoughEventData.h:16
TruthSegmentCsvDumperAlg.h
MuonR4::TruthSegmentCsvDumperAlg::TruthSegmentCsvDumperAlg
TruthSegmentCsvDumperAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TruthSegmentCsvDumperAlg.cxx:17
Muon::MuonStationIndex::ChIndex
ChIndex
enum to classify the different chamber layers in the muon spectrometer
Definition: MuonStationIndex.h:15
SG::VarHandleBase::isPresent
bool isPresent() const
Is the referenced object present in SG?
Definition: StoreGate/src/VarHandleBase.cxx:394
MuonReadoutElement.h
Muon::MuonStationIndex::TechnologyIndex
TechnologyIndex
enum to classify the different layers in the muon spectrometer
Definition: MuonStationIndex.h:54
MuonR4::TruthSegmentCsvDumperAlg::initialize
StatusCode initialize() override
Definition: TruthSegmentCsvDumperAlg.cxx:19
NSWL1::PadTriggerAdapter::segment
Muon::NSW_PadTriggerSegment segment(const NSWL1::PadTrigger &data)
Definition: PadTriggerAdapter.cxx:5