ATLAS Offline Software
TrackHandle_TruthTrack.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 
7 // //
8 // Implementation of class TrackHandle_TruthTrack //
9 // //
10 // Author: Thomas H. Kittelmann (Thomas.Kittelmann@cern.ch) //
11 // Initial version: March 2008 //
12 // //
14 
17 #include "VP1Base/VP1Msg.h"
18 
19 #include "AtlasHepMC/GenVertex.h"
20 #include "CLHEP/Vector/LorentzVector.h"
21 #include "TrkTrack/Track.h"
25 #include "AtlasHepMC/GenParticle.h"
26 
27 //____________________________________________________________________
29 public:
31  const SimBarCode& sbc,const SimHitList& shl,HepMC::ConstGenParticlePtr p)
32  : theclass(tc),
33  simBarCode(sbc),
34  simHitList(shl),
35  genParticle(p),
36  ascObjVis(false),
37  ascObjs(nullptr),
38  trkTrack(nullptr) {}
43 
44  bool ascObjVis;
45  std::vector<AscObj_TruthPoint*> * ascObjs;
46  void ensureInitAscObjs();
48  void ensureInitTrkTracks();
49 
51  {
52  if (!p)
53  return nullptr;//Fixme: message!
54  HepMC::ConstGenVertexPtr v = p->production_vertex();
55  if (!v)
56  return nullptr;//Fixme: message!
57  Amg::Vector3D mom(p->momentum().px(),p->momentum().py(),p->momentum().pz());
58  double absmom(mom.mag());
59  if (absmom<=0)
60  return nullptr;//Fixme: message!
61  Amg::Vector3D pos(v->position().x(),v->position().y(),v->position().z());
62  return new Trk::Perigee(0.,0.,mom.phi(), mom.theta(), charge/absmom, pos);
63  }
64 
66  {
67  if (!p)
68  return nullptr;//Fixme: message!
69  HepMC::ConstGenVertexPtr v = p->end_vertex();
70  if (!v)
71  return nullptr;//Fixme: message!
72  Amg::Vector3D mom(p->momentum().px(),p->momentum().py(),p->momentum().pz());
73 // double absmom(mom.mag());
74 // if (absmom<=0)
75 // return 0;//Fixme: message!
76  Amg::Vector3D pos(v->position().x(),v->position().y(),v->position().z());
77 
78  Amg::Translation3D amgtranslation(pos.x(),pos.y(),pos.z());
79  Amg::Transform3D amgTransf(amgtranslation * Amg::RotationMatrix3D::Identity());
80 
81  return new Trk::AtaPlane(pos,mom,charge, *(new Trk::PlaneSurface(amgTransf)));
82  }
83 
85  {
86  return pars ? new Trk::TrackStateOnSurface(
87  nullptr,
88  std::unique_ptr<Trk::TrackParameters>(pars),
89  nullptr)
90  : nullptr;
91  }
93  {
94  if (!pars)
95  return;
97  if (tsos)
98  dv->push_back(tsos);
99  }
100 
101  void createTrack(Trk::TrackStates* trackStateOnSurfaces)
102  {
103  if (!trackStateOnSurfaces) {
104  VP1Msg::messageDebug("TrackHandle_TruthTrack WARNING: Could not create track due to null TSOS vector");
105  return;
106  }
107  if (trackStateOnSurfaces->empty()) {
108  VP1Msg::messageDebug("TrackHandle_TruthTrack WARNING: Could not create track due to empty TSOS vector");
109  delete trackStateOnSurfaces;
110  return;
111  }
112  if (trkTrack) {
113  VP1Msg::messageDebug("TrackHandle_TruthTrack ERROR: Already create trkTrack previously!");
114  delete trackStateOnSurfaces;
115  return;
116  }
117 
119  std::unique_ptr<Trk::TrackStates> sink(trackStateOnSurfaces);
120  trkTrack = new Trk::Track(ti,
121  std::move(sink),
122  nullptr /*fitquality*/);
123 
124  }
125 
126 };
127 
128 //____________________________________________________________________
130  const SimBarCode& simBarCode,
131  const SimHitList& simHitList,
133  : TrackHandleBase(ch), m_d(new Imp(this,simBarCode,simHitList,genPart))
134 {
135  if (VP1Msg::verbose()) {
136  //Check genparticle barcode is same as in simBarCode. (and event index in parent_event())
137  //Check that genparticle has production vertex.
138  //Check if genparticle has end vertex, that there are no sim hits.
139  //all pdg codes of simhits and genparticle should be identical.
140  //all simhits should have same barcode.
141  //hitTime should be rising in all simhits. NB: Remember to correct hit times with bunch crossing!!
142  //fixme!
143  }
144 }
145 
146 //____________________________________________________________________
148 {
149  //Fixme: delete simhitlist here?
150  setAscObjsVisible(false);
151  delete m_d->ascObjs;
152  delete m_d->trkTrack;
153  delete m_d;
154 }
155 
156 //____________________________________________________________________
158 {
159  if (trkTrack)
160  return;
161 
162  //The GenParticle part is used if it is available with a production
163  //vertex. The sim. hits are used if present and the genparticle does
164  //not have an end vertex:
165  bool useGenParticle = genParticle && genParticle->production_vertex();
166  bool decayedGenParticle = useGenParticle && genParticle->end_vertex();
167  bool useSimHits = !decayedGenParticle && !simHitList.empty();
168 
169  if (!useGenParticle&&!useSimHits) {
170  VP1Msg::message("TrackHandle_TruthTrack ERROR: Track has neither a genparticle or sim. hits!!");
171  return;
172  }
173 
174  if (!theclass->hasCharge()) {
175  VP1Msg::message("TrackHandle_TruthTrack ERROR: Could not determine particle charge (pdg="
176  +QString::number(theclass->pdgCode())+").");//Fixme: I guess we could show non-extrapolated version?
177  return;
178  }
179  const double charge = theclass->charge();
180 
181  Trk::TrackStates* trackStateOnSurfaces = new Trk::TrackStates;
182 
183  if (useGenParticle) {
185 
186  if (decayedGenParticle) {
188  createTrack(trackStateOnSurfaces);
189  return;
190  }
191  }
192 
193  if (useSimHits) {
194  //Add parameters from simhits (yes, if !useGenParticle, we get no perigee).
195  SimHitList::const_iterator it, itE(simHitList.end());
196  for ( it = simHitList.begin(); it != itE; ++it ) {
197  //Fixme: momentum() < 0 (i.e. not present);
198  //Fixme: Possibly add points for both posStart() and posEnd() (and use energy loss information to get different momenta?)
199  addPars(trackStateOnSurfaces,it->second->createTrackParameters());
200  }
201 
202  }
203 
204  createTrack(trackStateOnSurfaces);
205 }
206 
207 //____________________________________________________________________
209 {
210 
211  QStringList l;
212  l << "Truth track";
214  l << "Evt index = "+QString::number(m_d->simBarCode.evtIndex());
215  l << "BarCode = "+QString::number(m_d->simBarCode.barCode());
216  return l;
217 }
218 
219 //____________________________________________________________________
221 {
222 }
223 
224 
225 //____________________________________________________________________
227 {
229  return m_d->trkTrack;
230 }
231 
232 
233 //____________________________________________________________________
235 {
236  return m_d->simBarCode.pdgCode();
237 }
238 
239 //____________________________________________________________________
241 {
243 }
244 
245 //____________________________________________________________________
247 {
248  if (m_d->genParticle) {
249  return Amg::Vector3D(m_d->genParticle->momentum().px(),m_d->genParticle->momentum().py(),m_d->genParticle->momentum().pz());
250  }
251  SimHitList::const_iterator it, itE(m_d->simHitList.end());
252  for ( it = m_d->simHitList.begin(); it != itE; ++it ) {
253  if (it->second->momentum()>=0) {
254  return (it->second->momentum()) * (it->second->momentumDirection());
255  }
256  }
257  //Unknown:
258  return TrackHandleBase::momentum();
259 }
260 
261 //____________________________________________________________________
262 bool TrackHandle_TruthTrack::hasVertexAtIR(const double& rmaxsq, const double& zmax) const
263 {
264  if (!m_d->genParticle)
265  return false;
266  HepMC::ConstGenVertexPtr v = m_d->genParticle->production_vertex();
267  if (!v)
268  return false;
269 
270  double x(v->position().x()), y(v->position().y());
271  if (x*x+y*y>rmaxsq)
272  return false;
273  return fabs(v->position().z())<=zmax;
274 }
275 
276 //____________________________________________________________________
278 {
279  if (visible()&&m_d->ascObjVis&&!m_d->ascObjs)
281 }
282 
283 //____________________________________________________________________
285 {
286  if (m_d->ascObjVis==b)
287  return;
288  m_d->ascObjVis=b;
289 // const bool visnow = visible()&&m_d->ascObjVis;
290 // const bool visbefore = visible()&&!m_d->ascObjVis;
291 // if (visnow==visbefore)
292 // return;
293 // VP1Msg::messageVerbose("TrackHandle_TruthTrack::AscObjs visible state -> "+VP1Msg::str(b));
294 
295  if (!m_d->ascObjs) {
296  if (!b||!visible())
297  return;
299  }
300 
302  for (;it!=itE;++it)
303  (*it)->setVisible(b);
304 }
305 
306 //____________________________________________________________________
308 {
309  if (ascObjs)
310  return;
311  ascObjs = new std::vector<AscObj_TruthPoint*>;
312  HepMC::ConstGenVertexPtr vprod{nullptr};
313  HepMC::ConstGenVertexPtr vend{nullptr};
314  if (genParticle) {
315  vprod=genParticle->production_vertex();
316  vend=genParticle->end_vertex();
317  }
318  ascObjs->reserve((vprod?1:0)+(vend?1:simHitList.size()));
319  if (vprod)
320  ascObjs->push_back(new AscObj_TruthPoint(theclass,vprod,genParticle));
321 
322  if (vend) {
323  ascObjs->push_back(new AscObj_TruthPoint(theclass,vend,genParticle));
324  } else {
325  SimHitList::const_iterator it, itE(simHitList.end());
326  for ( it = simHitList.begin(); it != itE; ++it )
327  ascObjs->push_back(new AscObj_TruthPoint(theclass,it->second));
328  }
330  for (it=ascObjs->begin();it!=itE;++it)
331  theclass->registerAssocObject(*it);
332  for (it=ascObjs->begin();it!=itE;++it)
333  (*it)->setVisible(ascObjVis);
334 }
335 
336 //____________________________________________________________________
338 {
339  if (!m_d->simHitList.empty()) {
340  if (m_d->simHitList.at(0).second->hasCharge())
341  return m_d->simHitList.at(0).second->charge();
342  else
343  VP1Msg::messageVerbose("TrackHandle_TruthTrack::calculateCharge() WARNING: Simhit did not have charge!");
344  }
345 
347 }
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
make_hlt_rep.pars
pars
Definition: make_hlt_rep.py:90
TrackHandle_TruthTrack::Imp::simBarCode
SimBarCode simBarCode
Definition: TrackHandle_TruthTrack.cxx:40
SimBarCode::isNonUniqueSecondary
bool isNonUniqueSecondary() const
Trk::TrackInfo
Contains information about the 'fitter' of this track.
Definition: Tracking/TrkEvent/TrkTrack/TrkTrack/TrackInfo.h:32
TrackCollHandleBase
Definition: TrackCollHandleBase.h:49
TrackHandle_TruthTrack::clicked
virtual QStringList clicked() const
Called when user selects the node (stringlist is displayed in messagebox).
Definition: TrackHandle_TruthTrack.cxx:208
sendEI_SPB.ch
ch
Definition: sendEI_SPB.py:35
TrackHandle_TruthTrack::Imp::ensureInitAscObjs
void ensureInitAscObjs()
Definition: TrackHandle_TruthTrack.cxx:307
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
TrackHandle_TruthTrack::Imp::simHitList
SimHitList simHitList
Definition: TrackHandle_TruthTrack.cxx:41
TrackParameters.h
SimBarCode::barCode
int barCode() const
PlotCalibFromCool.dv
dv
Definition: PlotCalibFromCool.py:762
Trk::Track
The ATLAS Track class.
Definition: Tracking/TrkEvent/TrkTrack/TrkTrack/Track.h:73
TrackHandleBase::charge
double charge() const
Definition: TrackHandleBase.cxx:1491
VP1Msg.h
Trk::ParametersT
Dummy class used to allow special convertors to be called for surfaces owned by a detector element.
Definition: EMErrorDetail.h:25
GenVertex.h
TrackHandle_TruthTrack
Definition: TrackHandle_TruthTrack.h:28
TrackHandle_TruthTrack::hasBarCodeZero
bool hasBarCodeZero() const
Definition: TrackHandle_TruthTrack.cxx:240
xAOD::JetInput::Track
@ Track
Definition: JetContainerInfo.h:61
CSV_InDetExporter.new
new
Definition: CSV_InDetExporter.py:145
skel.it
it
Definition: skel.GENtoEVGEN.py:423
Trk::Perigee
ParametersT< 5, Charged, PerigeeSurface > Perigee
Definition: Tracking/TrkEvent/TrkParameters/TrkParameters/TrackParameters.h:29
TrackHandle_TruthTrack::Imp::Imp
Imp(TrackHandle_TruthTrack *tc, const SimBarCode &sbc, const SimHitList &shl, HepMC::ConstGenParticlePtr p)
Definition: TrackHandle_TruthTrack.cxx:30
TrackHandle_TruthTrack::Imp::ensureInitTrkTracks
void ensureInitTrkTracks()
Definition: TrackHandle_TruthTrack.cxx:157
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:158
TrackHandle_TruthTrack::Imp::theclass
TrackHandle_TruthTrack * theclass
Definition: TrackHandle_TruthTrack.cxx:39
SimHitList
std::vector< std::pair< double, SimHitHandleBase * > > SimHitList
Definition: SimHitHandleBase.h:76
TrackHandle_TruthTrack::Imp::createTrack
void createTrack(Trk::TrackStates *trackStateOnSurfaces)
Definition: TrackHandle_TruthTrack.cxx:101
SimBarCode::pdgCode
int pdgCode() const
x
#define x
GenParticle.h
TrackHandle_TruthTrack::Imp::createTrkParamFromDecayVertex
static Trk::TrackParameters * createTrkParamFromDecayVertex(HepMC::ConstGenParticlePtr p, const double &charge)
Definition: TrackHandle_TruthTrack.cxx:65
TruthTest.itE
itE
Definition: TruthTest.py:25
SimBarCode
Definition: SimBarCode.h:22
TrackHandle_TruthTrack::visibleStateChanged
void visibleStateChanged()
override if need to take action in this case.
Definition: TrackHandle_TruthTrack.cxx:277
Track.h
TrackHandle_TruthTrack::Imp::addPars
static void addPars(Trk::TrackStates *dv, Trk::TrackParameters *pars)
Definition: TrackHandle_TruthTrack.cxx:92
TrackHandle_TruthTrack::~TrackHandle_TruthTrack
virtual ~TrackHandle_TruthTrack()
Definition: TrackHandle_TruthTrack.cxx:147
TrackHandleBase::calculateCharge
virtual double calculateCharge() const
Definition: TrackHandleBase.cxx:1464
TrackHandle_TruthTrack::Imp
Definition: TrackHandle_TruthTrack.cxx:28
TrackHandle_TruthTrack::hasVertexAtIR
bool hasVertexAtIR(const double &rmaxsq, const double &zmax) const
Definition: TrackHandle_TruthTrack.cxx:262
ParticleGun_EoverP_Config.mom
mom
Definition: ParticleGun_EoverP_Config.py:63
AscObj_TruthPoint.h
Trk::TrackStates
DataVector< const Trk::TrackStateOnSurface > TrackStates
Definition: Tracking/TrkEvent/TrkTrack/TrkTrack/Track.h:30
TrackHandleBase::momentum
virtual Amg::Vector3D momentum() const
Definition: TrackHandleBase.h:83
TrackHandleBase::visible
bool visible() const
Definition: TrackHandleBase.h:67
TrackHandle_TruthTrack::Imp::ascObjs
std::vector< AscObj_TruthPoint * > * ascObjs
Definition: TrackHandle_TruthTrack.cxx:45
Amg::Transform3D
Eigen::Affine3d Transform3D
Definition: GeoPrimitives.h:46
PixelAthClusterMonAlgCfg.zmax
zmax
Definition: PixelAthClusterMonAlgCfg.py:176
TrackHandle_TruthTrack::Imp::genParticle
HepMC::ConstGenParticlePtr genParticle
Definition: TrackHandle_TruthTrack.cxx:42
Trk::ParametersBase
Definition: ParametersBase.h:55
TrackHandle_TruthTrack::Imp::createTrkPerigeeFromProdVertex
static Trk::Perigee * createTrkPerigeeFromProdVertex(HepMC::ConstGenParticlePtr p, const double &charge)
Definition: TrackHandle_TruthTrack.cxx:50
DataVector< const Trk::TrackStateOnSurface >
TrackHandleBase::extrapolationParticleHypothesis
virtual Trk::ParticleHypothesis extrapolationParticleHypothesis() const
Default implementation of this next method bases hypothesis on pdgCode() and charge():
Definition: TrackHandleBase.cxx:1517
TrackHandle_TruthTrack::setAscObjsVisible
void setAscObjsVisible(bool)
Definition: TrackHandle_TruthTrack.cxx:284
HepMC::ConstGenParticlePtr
const GenParticle * ConstGenParticlePtr
Definition: GenParticle.h:38
Trk::TrackStateOnSurface
represents the track state (measurement, material, fit parameters and quality) at a surface.
Definition: TrackStateOnSurface.h:71
python.selection.number
number
Definition: selection.py:20
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
TrackHandle_TruthTrack::TrackHandle_TruthTrack
TrackHandle_TruthTrack(TrackCollHandleBase *, const SimBarCode &, const SimHitList &, HepMC::ConstGenParticlePtr genPart=nullptr)
Definition: TrackHandle_TruthTrack.cxx:129
VP1Msg::messageVerbose
static void messageVerbose(const QString &)
Definition: VP1Msg.cxx:84
TrackHandle_TruthTrack::m_d
Imp * m_d
Definition: TrackHandle_TruthTrack.h:60
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
TrackHandle_TruthTrack::Imp::ascObjVis
bool ascObjVis
Definition: TrackHandle_TruthTrack.cxx:44
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
python.PyAthena.v
v
Definition: PyAthena.py:157
Trk::AtaPlane
ParametersT< 5, Charged, PlaneSurface > AtaPlane
Definition: Tracking/TrkEvent/TrkParameters/TrkParameters/TrackParameters.h:30
DataVector.h
An STL vector of pointers that by default owns its pointed-to elements.
TrackHandle_TruthTrack::pdgCode
virtual int pdgCode() const
0 means unknown
Definition: TrackHandle_TruthTrack.cxx:234
VP1Msg::messageDebug
static void messageDebug(const QString &)
Definition: VP1Msg.cxx:39
y
#define y
VP1Msg::message
static void message(const QString &, IVP1System *sys=0)
Definition: VP1Msg.cxx:30
Trk::PlaneSurface
Definition: PlaneSurface.h:64
PlaneSurface.h
Amg::Translation3D
Eigen::Translation< double, 3 > Translation3D
Definition: GeoPrimitives.h:44
TrackHandle_TruthTrack::calculateCharge
virtual double calculateCharge() const
Definition: TrackHandle_TruthTrack.cxx:337
TrackHandle_TruthTrack.h
AscObj_TruthPoint
Definition: AscObj_TruthPoint.h:27
TrackHandle_TruthTrack::momentum
virtual Amg::Vector3D momentum() const
Definition: TrackHandle_TruthTrack.cxx:246
TrackHandleBase::baseInfo
QStringList baseInfo() const
Definition: TrackHandleBase.cxx:1534
TrackHandleBase::hasCharge
bool hasCharge() const
Definition: TrackHandleBase.h:99
VP1Msg::verbose
static bool verbose()
Definition: VP1Msg.h:31
HepMC::ConstGenVertexPtr
const HepMC::GenVertex * ConstGenVertexPtr
Definition: GenVertex.h:60
TrackHandleBase
Definition: TrackHandleBase.h:56
TrackHandle_TruthTrack::ensureTouchedMuonChambersInitialised
void ensureTouchedMuonChambersInitialised() const
Definition: TrackHandle_TruthTrack.cxx:220
DataVector::empty
bool empty() const noexcept
Returns true if the collection is empty.
SimBarCode::evtIndex
HepMcParticleLink::index_type evtIndex() const
TrackHandle_TruthTrack::Imp::createTSOS
static Trk::TrackStateOnSurface * createTSOS(Trk::TrackParameters *pars)
Definition: TrackHandle_TruthTrack.cxx:84
TrackHandle_TruthTrack::provide_pathInfoTrkTrack
const Trk::Track * provide_pathInfoTrkTrack() const
Definition: TrackHandle_TruthTrack.cxx:226
TrackHandle_TruthTrack::Imp::trkTrack
const Trk::Track * trkTrack
Definition: TrackHandle_TruthTrack.cxx:47
Trk::TrackInfo::Unknown
@ Unknown
Track fitter not defined.
Definition: Tracking/TrkEvent/TrkTrack/TrkTrack/TrackInfo.h:41