ATLAS Offline Software
TruthMuonTrackRetriever.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 
7 #include "GaudiKernel/IPartPropSvc.h"
8 
12 #include "HepPDT/ParticleData.hh"
13 #include "HepPDT/ParticleDataTable.hh"
14 #include "CLHEP/Geometry/Point3D.h"
15 #include "CLHEP/Geometry/Vector3D.h"
16 #include "CLHEP/Units/SystemOfUnits.h"
18 
19 
20 namespace JiveXML {
21 
28  TruthMuonTrackRetriever::TruthMuonTrackRetriever(const std::string& type ,const std::string& name,const IInterface* parent):
29  base_class(type, name, parent),
30  m_typeName("SMTr") {
31  //Fill the list with the names of track record collections to try
32  m_TrackRecCollNames.push_back("MuonEntryLayer");
33  m_TrackRecCollNames.push_back("MuonEntryRecord");
34 
35  //Declare the properties
36  declareProperty("TrackRecCollNames",m_TrackRecCollNames,"List of track records collections to try in this order - only one is retrieved");
37 
38  }
39 
40 
45 
46  //Nothing to be done here
47  return StatusCode::SUCCESS;
48  }
49 
54  StatusCode TruthMuonTrackRetriever::retrieve(ToolHandle<IFormatTool> &FormatTool) {
55 
56  ATH_MSG_DEBUG( "Retrieving " << dataTypeName() );
57 
58  //Try to retrieve the track record collection
59  const TrackRecordCollection* TrackRecordColl = NULL ;
60  //Loop over all the collections and try a retrieve (more efficenct than
61  //contain-retrieve combination)
62  for (auto CollNameItr : m_TrackRecCollNames ) {
63  //be verbose
64  ATH_MSG_DEBUG( "Trying to retrieve " << CollNameItr );
65  //try to retrive
66  if ( !evtStore()->contains<TrackRecordCollection>( CollNameItr )){ continue; } // skip if not in SG
67  if (evtStore()->retrieve(TrackRecordColl, CollNameItr).isSuccess()) break ;
68  }
69 
70  //If we didnt' get any, return
71  if (TrackRecordColl == NULL ) {
72  ATH_MSG_WARNING( "Unable to retrieve any track collection from " << m_TrackRecCollNames );
73  return StatusCode::RECOVERABLE;
74  }
75 
76  //Reserve space for the output
77  DataVect pt; pt.reserve(TrackRecordColl->size());
78  DataVect phi; phi.reserve(TrackRecordColl->size());
79  DataVect eta; eta.reserve(TrackRecordColl->size());
80  DataVect rhoVertex; rhoVertex.reserve(TrackRecordColl->size());
81  DataVect phiVertex; phiVertex.reserve(TrackRecordColl->size());
82  DataVect zVertex; zVertex.reserve(TrackRecordColl->size());
83  DataVect code; code.reserve(TrackRecordColl->size());
84  DataVect id; id.reserve(TrackRecordColl->size());
85 
86  //Now loop over the collection and retrieve data
87  for (const auto & record : *TrackRecordColl ) {
88 
89  //Get the pdg code
90  int pdgCode = record.GetPDGCode();
91 
92  //Only accept muons
93  if (abs(pdgCode) != 13) {
94  ATH_MSG_DEBUG( "Reject non-muon track with PDG ID " << pdgCode );
95  continue;
96  }
97 
98  //Get vertex and momentum
99  HepGeom::Point3D<double> vertex = record.GetPosition();
100  HepGeom::Vector3D<double> momentum = record.GetMomentum();
101 
102  //And store output
103  pt.emplace_back( momentum.perp()/CLHEP::GeV );
104  phi.emplace_back( momentum.phi() < 0 ? momentum.phi() + 2*M_PI : momentum.phi() );
105  eta.emplace_back( momentum.pseudoRapidity() );
106  rhoVertex.emplace_back( vertex.perp()*CLHEP::mm/CLHEP::cm );
107  phiVertex.emplace_back( vertex.phi() < 0 ? vertex.phi() + 2*M_PI : vertex.phi() );
108  zVertex.emplace_back( vertex.z()*CLHEP::mm/CLHEP::cm );
109  code.emplace_back( pdgCode );
110  id.emplace_back( HepMC::barcode(record) ); // FIXME barcode-based
111  }
112 
113  //Finall add everything to the datamap
115  const auto nEntries = pt.size();
116  dataMap["pt"] = std::move(pt);
117  dataMap["phi"] = std::move(phi);
118  dataMap["eta"] = std::move(eta);
119  dataMap["rhoVertex"] = std::move(rhoVertex);
120  dataMap["phiVertex"] = std::move(phiVertex);
121  dataMap["zVertex"] = std::move(zVertex);
122  dataMap["code"] = std::move(code);
123  dataMap["id"] = std::move(id);
124 
125  //some summary
126  ATH_MSG_DEBUG( dataTypeName() << ": "<< nEntries );
127 
128  //forward data to formating tool
129  //return FormatTool->AddToEvent(dataTypeName(), (*CollNameItr), &dataMap);
132  std::string emptyStr="";
133  return FormatTool->AddToEvent(dataTypeName(), emptyStr, &dataMap);
134  }
135 }
JiveXML::TruthMuonTrackRetriever::dataTypeName
virtual std::string dataTypeName() const
Return the name of the data type.
Definition: TruthMuonTrackRetriever.h:49
GeV
#define GeV
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:17
JiveXML::TruthMuonTrackRetriever::initialize
StatusCode initialize()
Default AthAlgTool methods.
Definition: TruthMuonTrackRetriever.cxx:44
JiveXML::DataVect
std::vector< DataType > DataVect
Defines a map with a key and a vector of DataType objects e.g.
Definition: DataType.h:58
AtlasHitsVector
Definition: AtlasHitsVector.h:33
test_pyathena.pt
pt
Definition: test_pyathena.py:11
M_PI
#define M_PI
Definition: ActiveFraction.h:11
JiveXML::DataMap
std::map< std::string, DataVect > DataMap
Definition: DataType.h:59
GenParticle.h
JiveXML::TruthMuonTrackRetriever::TruthMuonTrackRetriever
TruthMuonTrackRetriever(const std::string &type, const std::string &name, const IInterface *parent)
Standard Constructor.
Definition: TruthMuonTrackRetriever.cxx:28
cm
const double cm
Definition: Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/tools/FCAL_ChannelMap.cxx:25
histSizes.code
code
Definition: histSizes.py:129
ParticleGun_EoverP_Config.momentum
momentum
Definition: ParticleGun_EoverP_Config.py:63
LArHistMerge_trf.dataMap
dataMap
Definition: LArHistMerge_trf.py:218
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
HepMC::barcode
int barcode(const T *p)
Definition: Barcode.h:16
test_pyathena.parent
parent
Definition: test_pyathena.py:15
JiveXML
This header is shared inbetween the C-style server thread and the C++ Athena ServerSvc.
Definition: BadLArRetriever.cxx:22
TrackRecord.h
id
SG::auxid_t id
Definition: Control/AthContainers/Root/debug.cxx:220
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
MagicNumbers.h
TrackRecordCollection.h
python.SystemOfUnits.mm
int mm
Definition: SystemOfUnits.py:83
JiveXML::TruthMuonTrackRetriever::m_TrackRecCollNames
std::vector< std::string > m_TrackRecCollNames
A list of StoreGate names to probe in this order for the muon record collecton.
Definition: TruthMuonTrackRetriever.h:59
Trk::vertex
@ vertex
Definition: MeasurementType.h:21
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
JiveXML::TruthMuonTrackRetriever::retrieve
virtual StatusCode retrieve(ToolHandle< IFormatTool > &FormatTool)
Retrieve all the data.
Definition: TruthMuonTrackRetriever.cxx:54
AtlasHitsVector::size
size_type size() const
Definition: AtlasHitsVector.h:143
TruthMuonTrackRetriever.h
dqBeamSpot.nEntries
int nEntries
Definition: dqBeamSpot.py:73