ATLAS Offline Software
Loading...
Searching...
No Matches
TrackHandle_SimulationTrack.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_SimulationTrack //
9// //
10// Author: Thomas H. Kittelmann (Thomas.Kittelmann@cern.ch) //
11// Initial version: March 2008 //
12// //
14
17#include "VP1Base/VP1Msg.h"
18
21#include "CLHEP/Vector/LorentzVector.h"
22#include "TrkTrack/Track.h"
26
27//____________________________________________________________________
29public:
31 const SimBarCode& sbc,const SimHitList& shl)
32 : theclass(tc),
33 simBarCode(sbc),
34 simHitList(shl),
35 ascObjVis(false),
36 ascObjs(nullptr),
37 trkTrack(nullptr) {}
41
43 std::vector<AscObj_TruthPoint*> * ascObjs;
44 void ensureInitAscObjs();
47
49 {
50 return pars ? new Trk::TrackStateOnSurface(
51 nullptr,
52 std::unique_ptr<Trk::TrackParameters>(pars),
53 nullptr)
54 : nullptr;
55 }
57 {
58 if (!pars)
59 return;
61 if (tsos)
62 dv->push_back(tsos);
63 }
64
65 void createTrack(Trk::TrackStates* trackStateOnSurfaces)
66 {
67 if (!trackStateOnSurfaces) {
68 VP1Msg::messageDebug("TrackHandle_SimulationTrack WARNING: Could not create track due to null TSOS vector");
69 return;
70 }
71 if (trackStateOnSurfaces->empty()) {
72 VP1Msg::messageDebug("TrackHandle_SimulationTrack WARNING: Could not create track due to empty TSOS vector");
73 delete trackStateOnSurfaces;
74 return;
75 }
76 if (trkTrack) {
77 VP1Msg::messageDebug("TrackHandle_SimulationTrack ERROR: Already create trkTrack previously!");
78 delete trackStateOnSurfaces;
79 return;
80 }
81
83 theclass->extrapolationParticleHypothesis());
84 /*track assumes ownership*/
85 std::unique_ptr<Trk::TrackStates> sink(trackStateOnSurfaces);
86 trkTrack = new Trk::Track(
87 ti,
88 std::move(sink),
89 nullptr /*fitquality*/);
90
91 // if (VP1Msg::verbose())
92 // VP1Msg::messageVerbose("TrackHandle_SimulationTrack created track
93 // with "
94 // +QString::number(trackStateOnSurfaces->size())+"
95 // parameters");
96 }
97
98};
99
100//____________________________________________________________________
102 const SimBarCode& simBarCode,
103 const SimHitList& simHitList )
104 : TrackHandleBase(ch), m_d(new Imp(this,simBarCode,simHitList))
105{
106 if (VP1Msg::verbose()) {
107 //Check genparticle barcode is same as in simBarCode. (and event index in parent_event())
108 //Check that genparticle has production vertex.
109 //Check if genparticle has end vertex, that there are no sim hits.
110 //all pdg codes of simhits and genparticle should be identical.
111 //all simhits should have same barcode.
112 //hitTime should be rising in all simhits. NB: Remember to correct hit times with bunch crossing!!
113 //fixme!
114 }
115}
116
117//____________________________________________________________________
119{
120 //Fixme: delete simhitlist here?
121 setAscObjsVisible(false);
122 delete m_d->ascObjs;
123 delete m_d->trkTrack;
124 delete m_d;
125}
126
127//____________________________________________________________________
129{
130 if (trkTrack)
131 return;
132
133 if (!theclass->hasCharge()) {
134 VP1Msg::message("TrackHandle_SimulationTrack ERROR: Could not determine particle charge (pdg="
135 +QString::number(theclass->pdgCode())+").");//Fixme: I guess we could show non-extrapolated version?
136 return;
137 }
138 //const double charge = theclass->charge(); unused
139
140 Trk::TrackStates* trackStateOnSurfaces = new Trk::TrackStates;
141
142
143 SimHitList::const_iterator it, itE(simHitList.end());
144 for ( it = simHitList.begin(); it != itE; ++it ) {
145 //Fixme: momentum() < 0 (i.e. not present);
146 //Fixme: Possibly add points for both posStart() and posEnd() (and use energy loss information to get different momenta?)
147 addPars(trackStateOnSurfaces,it->second->createTrackParameters());
148 }
149
150
151 createTrack(trackStateOnSurfaces);
152}
153
154//____________________________________________________________________
156{
157
158 QStringList l;
159 l << "Truth track";
161 l << "Evt index = "+QString::number(m_d->simBarCode.evtIndex());
162 l << "BarCode = "+QString::number(m_d->simBarCode.barCode());
163 return l;
164}
165
166
167//____________________________________________________________________
169{
170 m_d->ensureInitTrkTracks();
171 return m_d->trkTrack;
172}
173
174
175//____________________________________________________________________
177{
178 return m_d->simBarCode.pdgCode();
179}
180
181//____________________________________________________________________
183{
184 return m_d->simBarCode.isNonUniqueSecondary();
185}
186
187//____________________________________________________________________
189{
190 SimHitList::const_iterator it, itE(m_d->simHitList.end());
191 for ( it = m_d->simHitList.begin(); it != itE; ++it ) {
192 if (it->second->momentum()>=0)
193 return (it->second->momentum()) * (it->second->momentumDirection());
194 }
195 //Unknown:
197}
198
199//____________________________________________________________________
201{
202 if (visible()&&m_d->ascObjVis&&!m_d->ascObjs)
203 m_d->ensureInitAscObjs();
204}
205
206//____________________________________________________________________
208{
209 if (m_d->ascObjVis==b)
210 return;
211 m_d->ascObjVis=b;
212// const bool visnow = visible()&&m_d->ascObjVis;
213// const bool visbefore = visible()&&!m_d->ascObjVis;
214// if (visnow==visbefore)
215// return;
216// VP1Msg::messageVerbose("TrackHandle_SimulationTrack::AscObjs visible state -> "+VP1Msg::str(b));
217
218 if (!m_d->ascObjs) {
219 if (!b||!visible())
220 return;
221 m_d->ensureInitAscObjs();
222 }
223
224 std::vector<AscObj_TruthPoint*>::iterator it(m_d->ascObjs->begin()), itE(m_d->ascObjs->end());
225 for (;it!=itE;++it)
226 (*it)->setVisible(b);
227}
228
229//____________________________________________________________________
231{
232 if (ascObjs)
233 return;
234 ascObjs = new std::vector<AscObj_TruthPoint*>;
235 ascObjs->reserve(simHitList.size());
236{
237 SimHitList::const_iterator it, itE(simHitList.end());
238 for ( it = simHitList.begin(); it != itE; ++it )
239 ascObjs->push_back(new AscObj_TruthPoint(theclass,it->second));
240 }
241 {
242 std::vector<AscObj_TruthPoint*>::iterator it, itE(ascObjs->end());
243 for (it=ascObjs->begin();it!=itE;++it)
244 theclass->registerAssocObject(*it);
245 for (it=ascObjs->begin();it!=itE;++it)
246 (*it)->setVisible(ascObjVis);
247 }
248}
249
250//____________________________________________________________________
252{
253 if (!m_d->simHitList.empty()) {
254 if (m_d->simHitList.at(0).second->hasCharge())
255 return m_d->simHitList.at(0).second->charge();
256 else
257 VP1Msg::messageVerbose("TrackHandle_SimulationTrack::calculateCharge() WARNING: Simhit did not have charge!");
258 }
259
261}
An STL vector of pointers that by default owns its pointed-to elements.
static Double_t tc
std::vector< std::pair< double, SimHitHandleBase * > > SimHitList
bool empty() const noexcept
Returns true if the collection is empty.
virtual double calculateCharge() const
friend class TrackCollHandleBase
TrackHandleBase(TrackCollHandleBase *)
QStringList baseInfo() const
virtual Amg::Vector3D momentum() const
bool visible() const
static Trk::TrackStateOnSurface * createTSOS(Trk::TrackParameters *pars)
std::vector< AscObj_TruthPoint * > * ascObjs
Imp(TrackHandle_SimulationTrack *tc, const SimBarCode &sbc, const SimHitList &shl)
void createTrack(Trk::TrackStates *trackStateOnSurfaces)
static void addPars(Trk::TrackStates *dv, Trk::TrackParameters *pars)
void visibleStateChanged()
override if need to take action in this case.
virtual QStringList clicked() const
Called when user selects the node (stringlist is displayed in messagebox).
virtual Amg::Vector3D momentum() const
virtual int pdgCode() const
0 means unknown
const Trk::Track * provide_pathInfoTrkTrack() const
TrackHandle_SimulationTrack(TrackCollHandleBase *, const SimBarCode &simBarCode, const SimHitList &)
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::Matrix< double, 3, 1 > Vector3D
DataVector< const Trk::TrackStateOnSurface > TrackStates
ParametersBase< TrackParametersDim, Charged > TrackParameters