ATLAS Offline Software
TruthTrackRetriever.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "TruthTrackRetriever.h"
6 
7 #include "HepPDT/ParticleData.hh"
8 #include "HepPDT/ParticleDataTable.hh"
9 #include "GaudiKernel/SystemOfUnits.h"
11 
15 
16 namespace JiveXML {
17 
18 
25  TruthTrackRetriever::TruthTrackRetriever(const std::string& type,const std::string& name,const IInterface* parent):
26  base_class(type,name,parent),
27  m_typeName("STr")
28  {
29  declareProperty("StoreGateKey", m_McEvtCollName = "TruthEvent", "Name of the McEventCollection");
30  declareProperty("UnstableMinPtCut", m_MinPtCut = 100*Gaudi::Units::MeV, "Minimum pT for an unstable particle to get accepted");
31  declareProperty("UnstableMinRhoCut", m_MinRhoCut = 40*Gaudi::Units::mm, "Minium radius of the end-vertex for unstable particle to get accepted");
32 
33  }
34 
39  //Nothing to do here
40  return StatusCode::SUCCESS;
41  }
42 
47  StatusCode TruthTrackRetriever::retrieve(ToolHandle<IFormatTool> &FormatTool) {
48 
49  //be verbose
50  if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "Retrieving " << dataTypeName() << endmsg;
51 
52  //Retrieve the collection
53  const McEventCollection* McEvtColl = NULL;
54  if ( !evtStore()->contains<McEventCollection>( m_McEvtCollName )){
55  if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "Could not find McEventCollection " << m_McEvtCollName << endmsg;
56  return StatusCode::SUCCESS;
57  }
58  if( evtStore()->retrieve(McEvtColl, m_McEvtCollName).isFailure() ){
59  if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "Could not retrieve McEventCollection " << m_McEvtCollName << endmsg;
60  return StatusCode::SUCCESS;
61  }
62 
63  // Calculate the size
64  long NParticles=0;
65  McEventCollection::const_iterator McEvtCollItr = McEvtColl->begin();
66  for ( ; McEvtCollItr != McEvtColl->end(); ++McEvtCollItr)
67  NParticles += (*McEvtCollItr)->particles_size();
68 
69  //Show in verbose mode
70  if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "Total number of particles in McEventCollection \""
71  << m_McEvtCollName << "\" is " << NParticles << endmsg;
72 
73  //Reserve space for the output data
74  DataVect pt; pt.reserve(NParticles);
75  DataVect phi; phi.reserve(NParticles);
76  DataVect eta; eta.reserve(NParticles);
77  DataVect rhoVertex; rhoVertex.reserve(NParticles);
78  DataVect phiVertex; phiVertex.reserve(NParticles);
79  DataVect zVertex; zVertex.reserve(NParticles);
80  DataVect code; code.reserve(NParticles);
81  DataVect id; id.reserve(NParticles);
82  DataVect rhoEndVertex; rhoEndVertex.reserve(NParticles);
83  DataVect phiEndVertex; phiEndVertex.reserve(NParticles);
84  DataVect zEndVertex; zEndVertex.reserve(NParticles);
85 
86 
87  //Now loop events and retrieve
88  for ( McEvtCollItr = McEvtColl->begin(); McEvtCollItr != McEvtColl->end(); ++McEvtCollItr){
89 
90  //Loop over particles in the event
91 #ifdef HEPMC3
92  const auto &barcodes = (*McEvtCollItr)->attribute<HepMC::GenEventBarcodes> ("barcodes");
93  std::map<int,int> id_to_barcode_map;
94  if (barcodes) id_to_barcode_map = barcodes->id_to_barcode_map();
95 #endif
96  for (const auto& particle: *(*McEvtCollItr) ) {
97 
98  //Additional cuts for decaying particles
99  if ( particle->end_vertex() ) {
100  //Reject particles that fail the pt cut
101  if ( particle->momentum().perp() < m_MinPtCut) continue ;
102  //Reject particles that fail the minimum end-vertex cut
103  if (particle->end_vertex()->position().perp() < m_MinRhoCut ) continue ;
104  }
105 
106  //Get basic parameters (eta, phi, pt, ...)
107  pt.push_back(DataType(particle->momentum().perp()/Gaudi::Units::GeV));
108  float thePhi = particle->momentum().phi();
109  phi.push_back(DataType( (thePhi<0) ? thePhi+=2*M_PI : thePhi ));
110  eta.push_back(DataType( particle->momentum().pseudoRapidity() ));
111  code.push_back(DataType( particle->pdg_id() ));
112 #ifdef HEPMC3
113  id.push_back(DataType( id_to_barcode_map.at(particle->id() )));
114 #else
115  id.push_back(DataType( HepMC::barcode(*particle) ));
116 #endif
117 
118  // Get the vertex information
119  const auto& vertexprod = particle->production_vertex();
120  if (vertexprod) {
121  const auto& pos=vertexprod->position();
122  rhoVertex.push_back(DataType( std::sqrt(pos.x()*pos.x()+pos.y()*pos.y()+pos.z()*pos.z())*Gaudi::Units::mm/Gaudi::Units::cm ));
123  float vtxPhi = pos.phi();
124  phiVertex.push_back(DataType( (vtxPhi<0)? vtxPhi+=2*M_PI : vtxPhi ));
125  zVertex.push_back(DataType( pos.z()*Gaudi::Units::mm/Gaudi::Units::cm ));
126  } else {
127  rhoVertex.push_back(DataType( 0. ));
128  phiVertex.push_back(DataType( 0. ));
129  zVertex.push_back(DataType( 0. ));
130  }
131  //Do the same for the end vertex
132  const auto& vertexend = particle->end_vertex();
133  if ( vertexend ) {
134  const auto& pos=vertexend->position();
135  rhoEndVertex.push_back(DataType(std::sqrt(pos.x()*pos.x()+pos.y()*pos.y()+pos.z()*pos.z())*Gaudi::Units::mm/Gaudi::Units::cm));
136  float vtxPhi = pos.phi();
137  phiEndVertex.push_back(DataType( (vtxPhi<0)? vtxPhi+=2*M_PI : vtxPhi ));
138  zEndVertex.push_back(DataType(pos.z()*Gaudi::Units::mm/Gaudi::Units::cm));
139  } else {
140  rhoEndVertex.push_back(DataType( 0. ));
141  phiEndVertex.push_back(DataType( 0. ));
142  zEndVertex.push_back(DataType( 0. ));
143  }
144  }
145  }
146 
147  DataMap myDataMap;
148  myDataMap["pt"] = pt;
149  myDataMap["phi"] = phi;
150  myDataMap["eta"] = eta;
151  myDataMap["code"] = code;
152  myDataMap["id"] = id;
153  myDataMap["rhoVertex"] = rhoVertex;
154  myDataMap["phiVertex"] = phiVertex;
155  myDataMap["zVertex"] = zVertex;
156  myDataMap["rhoEndVertex"] = rhoEndVertex;
157  myDataMap["phiEndVertex"] = phiEndVertex;
158  myDataMap["zEndVertex"] = zEndVertex;
159 
160  //Be verbose
161  if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << dataTypeName() << ": "<< pt.size() << endmsg;
162 
163  //forward data to formating tool
164  return FormatTool->AddToEvent(dataTypeName(), m_McEvtCollName, &myDataMap);
165  }
166 }
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
Trk::ParticleSwitcher::particle
constexpr ParticleHypothesis particle[PARTICLEHYPOTHESES]
the array of masses
Definition: ParticleHypothesis.h:76
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:64
JiveXML::TruthTrackRetriever::m_McEvtCollName
std::string m_McEvtCollName
Storegate key for the McEventCollection (different between RDO/ESD and AOD)
Definition: TruthTrackRetriever.h:62
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:79
JiveXML::DataVect
std::vector< DataType > DataVect
Defines a map with a key and a vector of DataType objects e.g.
Definition: DataType.h:58
python.SystemOfUnits.MeV
int MeV
Definition: SystemOfUnits.py:154
DataType
OFFLINE_FRAGMENTS_NAMESPACE::PointerType DataType
Definition: RoIBResultByteStreamTool.cxx:25
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
JiveXML::TruthTrackRetriever::m_MinPtCut
double m_MinPtCut
Minimum pT for a particle to get accepted.
Definition: TruthTrackRetriever.h:64
cm
const double cm
Definition: Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/tools/FCAL_ChannelMap.cxx:25
TruthTrackRetriever.h
McEventCollection.h
python.Dumpers.barcodes
def barcodes(beg, end, sz)
Definition: Dumpers.py:2800
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
JiveXML::TruthTrackRetriever::dataTypeName
virtual std::string dataTypeName() const
Return the name of the data type.
Definition: TruthTrackRetriever.h:52
HepMC::barcode
int barcode(const T *p)
Definition: Barcode.h:16
test_pyathena.parent
parent
Definition: test_pyathena.py:15
McEventCollection
This defines the McEventCollection, which is really just an ObjectVector of McEvent objects.
Definition: McEventCollection.h:33
JiveXML::TruthTrackRetriever::TruthTrackRetriever
TruthTrackRetriever(const std::string &type, const std::string &name, const IInterface *parent)
Standard Constructor.
Definition: TruthTrackRetriever.cxx:25
JiveXML
This header is shared inbetween the C-style server thread and the C++ Athena ServerSvc.
Definition: BadLArRetriever.cxx:21
JiveXML::TruthTrackRetriever::initialize
StatusCode initialize()
Default AthAlgTool methods.
Definition: TruthTrackRetriever.cxx:38
TrackRecord.h
EventPrimitives.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
TrackRecordCollection.h
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
python.SystemOfUnits.mm
int mm
Definition: SystemOfUnits.py:83
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
DEBUG
#define DEBUG
Definition: page_access.h:11
JiveXML::TruthTrackRetriever::m_MinRhoCut
double m_MinRhoCut
Minium radius of the end-vertex for the particle to get accepted.
Definition: TruthTrackRetriever.h:66
declareProperty
#define declareProperty(n, p, h)
Definition: BaseFakeBkgTool.cxx:15
JiveXML::TruthTrackRetriever::retrieve
virtual StatusCode retrieve(ToolHandle< IFormatTool > &FormatTool)
Retrieve all the data.
Definition: TruthTrackRetriever.cxx:47
GeV
#define GeV
Definition: CaloTransverseBalanceVecMon.cxx:30
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.