ATLAS Offline Software
Loading...
Searching...
No Matches
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
20#include "CLHEP/Vector/LorentzVector.h"
21#include "TrkTrack/Track.h"
26
27//____________________________________________________________________
29public:
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
45 std::vector<AscObj_TruthPoint*> * ascObjs;
46 void ensureInitAscObjs();
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
118 Trk::TrackInfo ti(Trk::TrackInfo::Unknown,theclass->extrapolationParticleHypothesis());
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//____________________________________________________________________
223
224
225//____________________________________________________________________
227{
228 m_d->ensureInitTrkTracks();
229 return m_d->trkTrack;
230}
231
232
233//____________________________________________________________________
235{
236 return m_d->simBarCode.pdgCode();
237}
238
239//____________________________________________________________________
241{
242 return m_d->simBarCode.isNonUniqueSecondary();
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:
259}
260
261//____________________________________________________________________
262bool 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)
280 m_d->ensureInitAscObjs();
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;
298 m_d->ensureInitAscObjs();
299 }
300
301 std::vector<AscObj_TruthPoint*>::iterator it(m_d->ascObjs->begin()), itE(m_d->ascObjs->end());
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 }
329 std::vector<AscObj_TruthPoint*>::iterator it, itE(ascObjs->end());
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}
An STL vector of pointers that by default owns its pointed-to elements.
static Double_t tc
std::vector< std::pair< double, SimHitHandleBase * > > SimHitList
#define y
#define x
bool empty() const noexcept
Returns true if the collection is empty.
virtual double calculateCharge() const
friend class TrackCollHandleBase
TrackHandleBase(TrackCollHandleBase *)
QStringList baseInfo() const
double charge() const
virtual Amg::Vector3D momentum() const
bool visible() const
std::vector< AscObj_TruthPoint * > * ascObjs
static Trk::TrackStateOnSurface * createTSOS(Trk::TrackParameters *pars)
static Trk::Perigee * createTrkPerigeeFromProdVertex(HepMC::ConstGenParticlePtr p, const double &charge)
void createTrack(Trk::TrackStates *trackStateOnSurfaces)
static void addPars(Trk::TrackStates *dv, Trk::TrackParameters *pars)
TrackHandle_TruthTrack * theclass
static Trk::TrackParameters * createTrkParamFromDecayVertex(HepMC::ConstGenParticlePtr p, const double &charge)
Imp(TrackHandle_TruthTrack *tc, const SimBarCode &sbc, const SimHitList &shl, HepMC::ConstGenParticlePtr p)
HepMC::ConstGenParticlePtr genParticle
virtual int pdgCode() const
0 means unknown
void ensureTouchedMuonChambersInitialised() const
virtual double calculateCharge() const
TrackHandle_TruthTrack(TrackCollHandleBase *, const SimBarCode &, const SimHitList &, HepMC::ConstGenParticlePtr genPart=nullptr)
const Trk::Track * provide_pathInfoTrkTrack() const
virtual QStringList clicked() const
Called when user selects the node (stringlist is displayed in messagebox).
void visibleStateChanged()
override if need to take action in this case.
bool hasVertexAtIR(const double &rmaxsq, const double &zmax) const
virtual Amg::Vector3D momentum() const
Class for a planaer rectangular or trapezoidal surface in the ATLAS detector.
Contains information about the 'fitter' of this track.
represents the track state (measurement, material, fit parameters and quality) at a surface.
static void messageVerbose(const QString &)
Definition VP1Msg.cxx:84
static bool verbose()
Definition VP1Msg.h:31
static void messageDebug(const QString &)
Definition VP1Msg.cxx:39
static void message(const QString &, IVP1System *sys=0)
Definition VP1Msg.cxx:30
Eigen::Affine3d Transform3D
Eigen::Matrix< double, 3, 1 > Vector3D
Eigen::Translation< double, 3 > Translation3D
const GenParticle * ConstGenParticlePtr
Definition GenParticle.h:38
const HepMC::GenVertex * ConstGenVertexPtr
Definition GenVertex.h:60
DataVector< const Trk::TrackStateOnSurface > TrackStates
ParametersT< TrackParametersDim, Charged, PerigeeSurface > Perigee
ParametersBase< TrackParametersDim, Charged > TrackParameters
ParametersT< TrackParametersDim, Charged, PlaneSurface > AtaPlane