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/Bootstrap.h"
8 //#include "GaudiKernel/ISvcLocator.h"
9 #include "GaudiKernel/IPartPropSvc.h"
10 
11 #include "AtlasHepMC/GenParticle.h"
14 #include "HepPDT/ParticleData.hh"
15 #include "HepPDT/ParticleDataTable.hh"
16 #include "CLHEP/Geometry/Point3D.h"
17 #include "CLHEP/Geometry/Vector3D.h"
18 #include "CLHEP/Units/SystemOfUnits.h"
20 
21 
22 namespace JiveXML {
23 
30  TruthMuonTrackRetriever::TruthMuonTrackRetriever(const std::string& type ,const std::string& name,const IInterface* parent):
31  base_class(type, name, parent),
32  m_typeName("SMTr") {
33  //Fill the list with the names of track record collections to try
34  m_TrackRecCollNames.push_back("MuonEntryLayer");
35  m_TrackRecCollNames.push_back("MuonEntryRecord");
36 
37  //Declare the properties
38  declareProperty("TrackRecCollNames",m_TrackRecCollNames,"List of track records collections to try in this order - only one is retrieved");
39 
40  }
41 
42 
47 
48  //Nothing to be done here
49  return StatusCode::SUCCESS;
50  }
51 
56  StatusCode TruthMuonTrackRetriever::retrieve(ToolHandle<IFormatTool> &FormatTool) {
57 
58  ATH_MSG_DEBUG( "Retrieving " << dataTypeName() );
59 
60  //Try to retrieve the track record collection
61  const TrackRecordCollection* TrackRecordColl = NULL ;
62  //Loop over all the collections and try a retrieve (more efficenct than
63  //contain-retrieve combination)
64  for (auto CollNameItr : m_TrackRecCollNames ) {
65  //be verbose
66  ATH_MSG_DEBUG( "Trying to retrieve " << CollNameItr );
67  //try to retrive
68  if ( !evtStore()->contains<TrackRecordCollection>( CollNameItr )){ continue; } // skip if not in SG
69  if (evtStore()->retrieve(TrackRecordColl, CollNameItr).isSuccess()) break ;
70  }
71 
72  //If we didnt' get any, return
73  if (TrackRecordColl == NULL ) {
74  ATH_MSG_WARNING( "Unable to retrieve any track collection from " << m_TrackRecCollNames );
75  return StatusCode::RECOVERABLE;
76  }
77 
78  //Reserve space for the output
79  DataVect pt; pt.reserve(TrackRecordColl->size());
80  DataVect phi; phi.reserve(TrackRecordColl->size());
81  DataVect eta; eta.reserve(TrackRecordColl->size());
82  DataVect rhoVertex; rhoVertex.reserve(TrackRecordColl->size());
83  DataVect phiVertex; phiVertex.reserve(TrackRecordColl->size());
84  DataVect zVertex; zVertex.reserve(TrackRecordColl->size());
85  DataVect code; code.reserve(TrackRecordColl->size());
86  DataVect id; id.reserve(TrackRecordColl->size());
87 
88  //Now loop over the collection and retrieve data
89  for (auto record : *TrackRecordColl ) {
90 
91  //Get the pdg code
92  int pdgCode = record.GetPDGCode();
93 
94  //Only accept muons
95  if (abs(pdgCode) != 13) {
96  ATH_MSG_DEBUG( "Reject non-muon track with PDG ID " << pdgCode );
97  continue;
98  }
99 
100  //Get vertex and momentum
101  HepGeom::Point3D<double> vertex = record.GetPosition();
102  HepGeom::Vector3D<double> momentum = record.GetMomentum();
103 
104  //And store output
105  pt.push_back(DataType( momentum.perp()/CLHEP::GeV ));
106  phi.push_back(DataType( momentum.phi() < 0 ? momentum.phi() + 2*M_PI : momentum.phi() ));
107  eta.push_back(DataType( momentum.pseudoRapidity() ));
108  rhoVertex.push_back(DataType( vertex.perp()*CLHEP::mm/CLHEP::cm ));
109  phiVertex.push_back(DataType( vertex.phi() < 0 ? vertex.phi() + 2*M_PI : vertex.phi() ));
110  zVertex.push_back(DataType( vertex.z()*CLHEP::mm/CLHEP::cm ));
111  code.push_back(DataType( pdgCode ));
112  id.push_back(DataType( HepMC::barcode(record) )); // FIXME barcode-based
113  }
114 
115  //Finall add everything to the datamap
117  dataMap["pt"] = pt;
118  dataMap["phi"] = phi;
119  dataMap["eta"] = eta;
120  dataMap["rhoVertex"] = rhoVertex;
121  dataMap["phiVertex"] = phiVertex;
122  dataMap["zVertex"] = zVertex;
123  dataMap["code"] = code;
124  dataMap["id"] = id;
125 
126  //some summary
127  ATH_MSG_DEBUG( dataTypeName() << ": "<< pt.size() );
128 
129  //forward data to formating tool
130  //return FormatTool->AddToEvent(dataTypeName(), (*CollNameItr), &dataMap);
133  std::string emptyStr="";
134  return FormatTool->AddToEvent(dataTypeName(), emptyStr, &dataMap);
135  }
136 }
JiveXML::TruthMuonTrackRetriever::dataTypeName
virtual std::string dataTypeName() const
Return the name of the data type.
Definition: TruthMuonTrackRetriever.h:49
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:64
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:79
JiveXML::TruthMuonTrackRetriever::initialize
StatusCode initialize()
Default AthAlgTool methods.
Definition: TruthMuonTrackRetriever.cxx:46
JiveXML::DataVect
std::vector< DataType > DataVect
Defines a map with a key and a vector of DataType objects e.g.
Definition: DataType.h:58
DataType
OFFLINE_FRAGMENTS_NAMESPACE::PointerType DataType
Definition: RoIBResultByteStreamTool.cxx:25
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:30
cm
const double cm
Definition: Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/tools/FCAL_ChannelMap.cxx:25
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:21
TrackRecord.h
pmontree.code
code
Definition: pmontree.py:443
id
SG::auxid_t id
Definition: Control/AthContainers/Root/debug.cxx:194
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
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:56
declareProperty
#define declareProperty(n, p, h)
Definition: BaseFakeBkgTool.cxx:15
AtlasHitsVector::size
size_type size() const
Definition: AtlasHitsVector.h:143
TruthMuonTrackRetriever.h
GeV
#define GeV
Definition: CaloTransverseBalanceVecMon.cxx:30