ATLAS Offline Software
Loading...
Searching...
No Matches
TrackCollHandle_SimulationTracks.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 TrackCollHandle_SimulationTracks //
9// //
10// Author: Thomas H. Kittelmann (Thomas.Kittelmann@cern.ch) //
11// Initial version: March 2008 //
12// //
14
21#include "VP1Base/IVP1System.h"
22#include "VP1Base/VP1Msg.h"
25
26#include "AtlasHepMC/GenEvent.h"
30
32
35
38#include "CLHEP/Units/PhysicalConstants.h"
39
40#include "CLHEP/Vector/LorentzVector.h"
41
42#include <QStringList>
43#include <QTime>
44
45#include <iostream>
46
47//____________________________________________________________________
49public:
50
52 bool loadHitLists(std::map<SimBarCode,SimHitList> & hitLists);
53
54 template <class collT>
55 void addHitCollections(std::map<SimBarCode,SimHitList> & hitLists);
56
58
61 if (!((updateGUICounter++)%750)) {
62 theclass->systemBase()->updateGUI();
63 }
64 }
65
66 std::map<SimBarCode::ExtBarCode,int> extBarCode2pdg;
67 bool cut_fromIROnly = false;
69 bool cut_excludeNeutrals = false;
70
71 bool displayAscObjs = false;
73
74 static const int maxPdgCode = 1000000000;
75
76};
77
78
79//____________________________________________________________________
81{
82 QStringList l;
83 VP1SGContentsHelper sgcont(sys);
84
85 l << sgcont.getKeys<SimulationHitCollection>();
86
87 return l;
88}
89
90//____________________________________________________________________
92 const QString& name)
93 : TrackCollHandleBase(cd,name,TrackType::SimulationTrack), m_d(new Imp)
94{
95 setHelperClassName("TrackCollHandle_SimulationTracks");
96 m_d->theclass = this;
97 m_d->updateGUICounter = 0;
98 m_d->cut_fromIROnly = false;
99 m_d->cut_excludeBarcodeZero = false;
100 m_d->cut_excludeNeutrals = false;
101 m_d->displayAscObjs = false;
102}
103
104//____________________________________________________________________
109
110//____________________________________________________________________
112{
113
114 connect(controller,SIGNAL(cutExcludeBarcodeZeroChanged(bool)),this,SLOT(setCutExcludeBarcodeZero(bool)));
116
117 connect(controller,SIGNAL(cutTruthExcludeNeutralsChanged(bool)),this,SLOT(setCutExcludeNeutrals(bool)));
119
120 connect(controller,SIGNAL(showTruthAscObjsChanged(bool)),this,SLOT(setShowAscObjs(bool)));
121 setShowAscObjs(controller->showTruthAscObjs());
122}
123
124//____________________________________________________________________
126{
127 if (m_d->displayAscObjs==b)
128 return;
129 m_d->displayAscObjs=b;
130 messageVerbose("Associated objects shown flag changed to " + str(b));
131 m_d->updateVisibleAssociatedObjects();
132}
133
134//____________________________________________________________________
135template <class collT>
136void TrackCollHandle_SimulationTracks::Imp::addHitCollections(std::map<SimBarCode,SimHitList> & hitLists)
137{
138 std::map<SimBarCode,SimHitList>::iterator itHitList;
139
140 theclass->message("Entered addHitCollections " + QString(typeid(collT).name()));
141 VP1SGAccessHelper sgaccess(theclass->systemBase());
142
143 for (const QString& key : VP1SGContentsHelper(theclass->systemBase()).getKeys<collT>()) {
144 const collT * hitColl;
145 theclass->message("Try to retrieve "+QString(typeid(collT).name())+" collection with key = "+key);
146 if (!sgaccess.retrieve(hitColl, key)) {
147 theclass->message("Error: Could not retrieve "+QString(typeid(collT).name())+" collection with key = "+key);
148 continue;
149 }
150 theclass->messageVerbose("Retrieved hit collection of type "+QString(typeid(collT).name())+" with key = "+key);
151 typename collT::const_iterator it, itE(hitColl->end());
152 int itot(0), iadded(0);
153 for (it=hitColl->begin();it!=itE;++it) {
154 ++itot;
156 SimHitHandleBase * handle = createHitHandle(*it);
157 handle->cacheMomentum();
158 theclass->fixPDGCode(handle);
159 SimBarCode trackID = handle->simBarCode();
160 if (trackID.pdgCode()>maxPdgCode) {
161 continue;
162 }
163
164 itHitList = hitLists.find(trackID);
165 if ( itHitList == hitLists.end() ) {
166 SimHitList l;
167 l.push_back(std::pair<double,SimHitHandleBase*>(handle->hitTime(),handle));
168 hitLists[trackID] = l;
169 } else {
170 itHitList->second.emplace_back(handle->hitTime(),handle);
171 }
172 ++iadded;
173 }
174 theclass->messageVerbose(" => used "+str(iadded)+" of "+str(itot)+" hits");
175 }
176
177}
178
179//____________________________________________________________________
180bool TrackCollHandle_SimulationTracks::Imp::loadHitLists(std::map<SimBarCode,SimHitList> & hitLists)
181{
182 //Fixme: Return false if we do not find at least one collection
183 theclass->messageVerbose( "Searching " + str( hitLists.size() ) + " lists of sim. hits.");
185
186 if (VP1Msg::verbose())
187 theclass->messageVerbose( "Found " + str( hitLists.size() ) + " lists of sim. hits.");
188
189 //Time to assign all simhits with known pdg code a charge:
190 std::map<SimBarCode,SimHitList>::iterator it, itE(hitLists.end());
191 for (it = hitLists.begin(); it!=itE; ++it) {
192 if (it->first.unknownPdgCode())
193 continue;
194 bool ok;
195 double charge = VP1ParticleData::particleCharge(it->first.pdgCode(),ok);
196 if (!ok)
197 continue;
198 SimHitList::iterator itHit(it->second.begin()), itHitE(it->second.end());
199 for (;itHit!=itHitE;++itHit)
200 itHit->second->setCharge(charge);
202 }
203
204 //Sort hitLists:
205 for (it = hitLists.begin(); it!=itE; ++it) {
206 sort(it->second.begin(),it->second.end());
208 }
209 return true;
210}
211
212
213//____________________________________________________________________
215{
216
217 //get sim hits and track records:
218 std::map<SimBarCode,SimHitList> hitLists;
219 if (!m_d->loadHitLists(hitLists))
220 return false;
221 messageVerbose("TrackCollHandle_SimulationTracks "+name()
222 +": Found "+str(hitLists.size())+" truth particles from simhits");
223
224 //Finally we need to combine the info we thus found, and construct
225 //actual track handles:
226
227 std::map<SimBarCode,SimHitList>::iterator itHitList, itHitListEnd(hitLists.end()), itHitListTemp;
228
229 for (itHitList = hitLists.begin();itHitList!=itHitListEnd;++itHitList) {
230 if (itHitList->second.empty()) {
231 message("load WARNING: Ignoring empty hit list.");
232 continue;
233 }
234 addTrackHandle( new TrackHandle_SimulationTrack( this, itHitList->first, itHitList->second ) );
235 }
236
237 //Maybe we need to show measurements, etc.:
238 m_d->updateVisibleAssociatedObjects();
239
240 return true;
241}
242
243//____________________________________________________________________
245{
246 int pdgfromsimhit =handle->actualPDGCodeFromSimHit();
247 bool isNonUniqueSecondary = handle->simBarCode().isNonUniqueSecondary();
248 SimBarCode::ExtBarCode extBarCode = handle->simBarCode().extBarCode();
249
250 if (pdgfromsimhit!=SimBarCode::unknownPDG) {
251 handle->setPDG(handle->actualPDGCodeFromSimHit());
252 std::map<SimBarCode::ExtBarCode,int>::const_iterator it = m_d->extBarCode2pdg.find(extBarCode);
253 if ( !isNonUniqueSecondary && it==m_d->extBarCode2pdg.end())
254 m_d->extBarCode2pdg[extBarCode] = pdgfromsimhit;
255 return;
256 }
257 if (isNonUniqueSecondary)
258 return;
259 std::map<SimBarCode::ExtBarCode,int>::const_iterator it = m_d->extBarCode2pdg.find(extBarCode);
260 if (it!=m_d->extBarCode2pdg.end()) {
261 handle->setPDG(it->second);
262 }
263}
264
265//____________________________________________________________________
267{
268 if (!TrackCollHandleBase::cut(handle))
269 return false;
270
271 if (m_d->cut_excludeNeutrals && handle->hasCharge() && handle->charge()==0.0)
272 return false;
273
274 TrackHandle_SimulationTrack * truthhandle = static_cast<TrackHandle_SimulationTrack *>(handle);
275 return !(m_d->cut_excludeBarcodeZero && truthhandle->hasBarCodeZero());
276}
277
278//____________________________________________________________________
280{
281 if (m_d->cut_excludeBarcodeZero==b)
282 return;
283 m_d->cut_excludeBarcodeZero=b;
284 if (b)
286 else
288}
289
290//____________________________________________________________________
292{
293 if (m_d->cut_excludeNeutrals==b)
294 return;
295 m_d->cut_excludeNeutrals=b;
296 if (b)
298 else
300}
301
302
303//If has momentum - Check light-speed consistency given positions and time.
304//mom should be decreasing
305
306//____________________________________________________________________
308{
309
310 theclass->message("updateVisibleAssociatedObjects");//fixme
311 theclass->largeChangesBegin();
312 theclass->trackHandleIterationBegin();
314 while ((handle=static_cast<TrackHandle_SimulationTrack*>(theclass->getNextTrackHandle()))) {
316 }
317 theclass->largeChangesEnd();
318}
319
double charge(const T &p)
Definition AtlasPID.h:997
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
std::vector< std::pair< double, SimHitHandleBase * > > SimHitList
AtlasHitsVector< SimulationHit > SimulationHitCollection
Header file for AthHistogramAlgorithm.
std::pair< int, HepMcParticleLink::index_type > ExtBarCode
Definition SimBarCode.h:42
ExtBarCode extBarCode() const
Definition SimBarCode.h:43
static const int unknownPDG
Definition SimBarCode.h:25
bool isNonUniqueSecondary() const
int pdgCode() const
virtual double hitTime() const =0
virtual int actualPDGCodeFromSimHit() const
SimBarCode simBarCode() const
const QString & name() const
virtual bool cut(TrackHandleBase *)
void addTrackHandle(TrackHandleBase *)
TrackCollHandleBase(TrackSysCommonData *, const QString &name, TrackType::Type)
std::map< SimBarCode::ExtBarCode, int > extBarCode2pdg
bool loadHitLists(std::map< SimBarCode, SimHitList > &hitLists)
void addHitCollections(std::map< SimBarCode, SimHitList > &hitLists)
static SimHitHandleBase * createHitHandle(const SimulationHit &h)
TrackCollHandle_SimulationTracks(TrackSysCommonData *, const QString &name)
virtual void setupSettingsFromControllerSpecific(TrackSystemController *)
static QStringList availableCollections(IVP1System *)
double charge() const
bool hasCharge() const
void messageVerbose(const QString &) const
void message(const QString &) const
void setHelperClassName(const QString &n)
static bool verbose()
Definition VP1Msg.h:31
static double particleCharge(const int &pdgcode, bool &ok)
bool retrieve(const T *&, const QString &key) const
QStringList getKeys() const