ATLAS Offline Software
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"
27 #include "AtlasHepMC/GenParticle.h"
28 #include "AtlasHepMC/GenVertex.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 //____________________________________________________________________
49 public:
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)) {
63  }
64  }
65 
66  std::map<SimBarCode::ExtBarCode,int> extBarCode2pdg;
67  bool cut_fromIROnly = false;
68  bool cut_excludeBarcodeZero = false;
69  bool cut_excludeNeutrals = false;
70 
71  bool displayAscObjs = false;
72  void updateVisibleAssociatedObjects() const;
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 //____________________________________________________________________
106 {
107  delete m_d;
108 }
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;
130  messageVerbose("Associated objects shown flag changed to " + str(b));
132 }
133 
134 //____________________________________________________________________
135 template <class collT>
136 void TrackCollHandle_SimulationTracks::Imp::addHitCollections(std::map<SimBarCode,SimHitList> & hitLists)
137 {
139 
140  theclass->message("Entered addHitCollections " + QString(typeid(collT).name()));
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 //____________________________________________________________________
180 bool 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.");
184  addHitCollections<SimulationHitCollection>(hitLists);
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:
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);
201  possiblyUpdateGUI();
202  }
203 
204  //Sort hitLists:
205  for (it = hitLists.begin(); it!=itE; ++it) {
206  sort(it->second.begin(),it->second.end());
207  possiblyUpdateGUI();
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.:
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 {
282  return;
284  if (b)
286  else
288 }
289 
290 //____________________________________________________________________
292 {
293  if (m_d->cut_excludeNeutrals==b)
294  return;
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()))) {
315  handle->setAscObjsVisible(displayAscObjs);
316  }
317  theclass->largeChangesEnd();
318 }
319 
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
TrackCollHandle_SimulationTracks::Imp::updateVisibleAssociatedObjects
void updateVisibleAssociatedObjects() const
Definition: TrackCollHandle_SimulationTracks.cxx:307
TrackCollHandle_SimulationTracks::Imp
Definition: TrackCollHandle_SimulationTracks.cxx:48
SimBarCode::isNonUniqueSecondary
bool isNonUniqueSecondary() const
TrackCollHandleBase
Definition: TrackCollHandleBase.h:49
TrackCollHandle_SimulationTracks::setCutExcludeNeutrals
void setCutExcludeNeutrals(bool)
Definition: TrackCollHandle_SimulationTracks.cxx:291
GenEvent.h
SimHitHandleBase::simBarCode
SimBarCode simBarCode() const
Definition: SimHitHandleBase.h:48
TrackSystemController.h
TrackHandleBase::charge
double charge() const
Definition: TrackHandleBase.cxx:1508
TrackCollHandle_SimulationTracks::cut
virtual bool cut(TrackHandleBase *)
Definition: TrackCollHandle_SimulationTracks.cxx:266
TrackCollHandle_SimulationTracks::setShowAscObjs
void setShowAscObjs(bool)
Definition: TrackCollHandle_SimulationTracks.cxx:125
VP1Msg.h
VP1HelperClassBase::messageVerbose
void messageVerbose(const QString &) const
Definition: VP1HelperClassBase.cxx:78
GenVertex.h
fillPileUpNoiseLumi.connect
string connect
Definition: fillPileUpNoiseLumi.py:70
CSV_InDetExporter.new
new
Definition: CSV_InDetExporter.py:145
AtlasHitsVector
Definition: AtlasHitsVector.h:33
TrackCollHandle_SimulationTracks::Imp::loadHitLists
bool loadHitLists(std::map< SimBarCode, SimHitList > &hitLists)
Definition: TrackCollHandle_SimulationTracks.cxx:180
skel.it
it
Definition: skel.GENtoEVGEN.py:396
VP1ParticleData.h
SimHitHandle_ForwardHit.h
TrackCollHandle_SimulationTracks::Imp::addHitCollections
void addHitCollections(std::map< SimBarCode, SimHitList > &hitLists)
Definition: TrackCollHandle_SimulationTracks.cxx:136
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:158
TrackCollHandleBase::recheckCutStatusOfAllNotVisibleHandles
void recheckCutStatusOfAllNotVisibleHandles()
Definition: TrackCollHandleBase.cxx:407
SimBarCode::extBarCode
ExtBarCode extBarCode() const
Definition: SimBarCode.h:43
SimHitList
std::vector< std::pair< double, SimHitHandleBase * > > SimHitList
Definition: SimHitHandleBase.h:76
SimBarCode::pdgCode
int pdgCode() const
VP1String::str
static QString str(const QString &s)
Definition: VP1String.h:49
GenParticle.h
mapkey::sys
@ sys
Definition: TElectronEfficiencyCorrectionTool.cxx:42
TrackCollHandle_SimulationTracks::m_d
Imp * m_d
Definition: TrackCollHandle_SimulationTracks.h:53
TrackHandle_SimulationTrack::setAscObjsVisible
void setAscObjsVisible(bool)
Definition: TrackHandle_SimulationTrack.cxx:207
TrackCollHandle_SimulationTracks::Imp::cut_excludeBarcodeZero
bool cut_excludeBarcodeZero
Definition: TrackCollHandle_SimulationTracks.cxx:68
TruthTest.itE
itE
Definition: TruthTest.py:25
TrackCollHandle_SimulationTracks::Imp::updateGUICounter
int updateGUICounter
Definition: TrackCollHandle_SimulationTracks.cxx:59
SimBarCode
Definition: SimBarCode.h:22
SimulationHit
Definition: SimulationHit.h:11
TrackCollHandle_SimulationTracks::Imp::possiblyUpdateGUI
void possiblyUpdateGUI()
Definition: TrackCollHandle_SimulationTracks.cxx:60
TrackCollHandle_SimulationTracks::TrackCollHandle_SimulationTracks
TrackCollHandle_SimulationTracks(TrackSysCommonData *, const QString &name)
Definition: TrackCollHandle_SimulationTracks.cxx:91
VP1SGContentsHelper::getKeys
QStringList getKeys() const
Definition: VP1SGContentsHelper.h:55
TrackSystemController::cutTruthExcludeNeutrals
bool cutTruthExcludeNeutrals() const
Definition: TrackSystemController.cxx:1868
TrackHandle_SimulationTrack::hasBarCodeZero
bool hasBarCodeZero() const
Definition: TrackHandle_SimulationTrack.cxx:182
TrackCollHandleBase::cut
virtual bool cut(TrackHandleBase *)
Definition: TrackCollHandleBase.cxx:316
VP1HelperClassBase::setHelperClassName
void setHelperClassName(const QString &n)
Definition: VP1HelperClassBase.h:59
IVP1System
Definition: IVP1System.h:36
SimBarCode.h
TrackSysCommonData
Definition: TrackSysCommonData.h:50
McEventCollection.h
SimBarCode::unknownPDG
static const int unknownPDG
Definition: SimBarCode.h:25
VP1ParticleData::particleCharge
static double particleCharge(const int &pdgcode, bool &ok)
Definition: VP1ParticleData.cxx:103
TrackCollHandle_SimulationTracks::Imp::createHitHandle
static SimHitHandleBase * createHitHandle(const SimulationHit &h)
Definition: TrackCollHandle_SimulationTracks.cxx:57
SimHitHandleBase::cacheMomentum
void cacheMomentum()
Definition: SimHitHandleBase.h:58
SimHitHandleBase::hitTime
virtual double hitTime() const =0
SimHitHandle_ForwardHit
Definition: SimHitHandle_ForwardHit.h:23
TrackCollHandle_SimulationTracks::Imp::maxPdgCode
static const int maxPdgCode
Definition: TrackCollHandle_SimulationTracks.cxx:74
VP1SGAccessHelper::retrieve
bool retrieve(const T *&, const QString &key) const
TrackCollHandle_SimulationTracks::Imp::displayAscObjs
bool displayAscObjs
Definition: TrackCollHandle_SimulationTracks.cxx:71
VP1HelperClassBase::systemBase
IVP1System * systemBase() const
Definition: VP1HelperClassBase.h:50
TrackCollHandle_SimulationTracks::load
virtual bool load()
Definition: TrackCollHandle_SimulationTracks.cxx:214
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
SimHitHandleBase::setPDG
void setPDG(int)
Definition: SimHitHandleBase.h:87
TrackCollHandleBase::addTrackHandle
void addTrackHandle(TrackHandleBase *)
Definition: TrackCollHandleBase.cxx:515
TrackSystemController
Definition: TrackSystemController.h:49
TrackRecordCollection.h
charge
double charge(const T &p)
Definition: AtlasPID.h:756
SimHitHandleBase.h
TrackCollHandle_SimulationTracks::Imp::theclass
TrackCollHandle_SimulationTracks * theclass
Definition: TrackCollHandle_SimulationTracks.cxx:51
VP1SGContentsHelper
Definition: VP1SGContentsHelper.h:26
TrackCollHandle_SimulationTracks::setupSettingsFromControllerSpecific
virtual void setupSettingsFromControllerSpecific(TrackSystemController *)
Definition: TrackCollHandle_SimulationTracks.cxx:111
SimHitHandleBase::actualPDGCodeFromSimHit
virtual int actualPDGCodeFromSimHit() const
Definition: SimHitHandleBase.h:61
TrackCollHandle_SimulationTracks::Imp::extBarCode2pdg
std::map< SimBarCode::ExtBarCode, int > extBarCode2pdg
Definition: TrackCollHandle_SimulationTracks.cxx:66
TrackSystemController::cutExcludeBarcodeZero
bool cutExcludeBarcodeZero() const
Definition: TrackSystemController.cxx:1862
TrackCollHandle_SimulationTracks::Imp::cut_fromIROnly
bool cut_fromIROnly
Definition: TrackCollHandle_SimulationTracks.cxx:67
SimulationHitCollection.h
TrackHandle_SimulationTrack
Definition: TrackHandle_SimulationTrack.h:26
h
IVP1System::updateGUI
void updateGUI()
Definition: IVP1System.cxx:262
TrackCollHandle_SimulationTracks::setCutExcludeBarcodeZero
void setCutExcludeBarcodeZero(bool)
Definition: TrackCollHandle_SimulationTracks.cxx:279
SimHitHandleBase
Definition: SimHitHandleBase.h:32
TrackCollHandle_SimulationTracks
Definition: TrackCollHandle_SimulationTracks.h:25
calibdata.cd
cd
Definition: calibdata.py:51
TrackCollHandle_SimulationTracks::fixPDGCode
void fixPDGCode(SimHitHandleBase *) const
Definition: TrackCollHandle_SimulationTracks.cxx:244
VP1HelperClassBase::message
void message(const QString &) const
Definition: VP1HelperClassBase.cxx:49
TrackSystemController::showTruthAscObjs
bool showTruthAscObjs() const
Definition: TrackSystemController.cxx:1758
TrackHandleBase::hasCharge
bool hasCharge() const
Definition: TrackHandleBase.h:99
VP1JobConfigInfo.h
TrackCollHandleBase::recheckCutStatusOfAllVisibleHandles
void recheckCutStatusOfAllVisibleHandles()
Definition: TrackCollHandleBase.cxx:386
VP1Msg::verbose
static bool verbose()
Definition: VP1Msg.h:31
VP1SGAccessHelper
Definition: VP1SGAccessHelper.h:25
TrackCollHandle_SimulationTracks::availableCollections
static QStringList availableCollections(IVP1System *)
Definition: TrackCollHandle_SimulationTracks.cxx:80
TrackHandleBase
Definition: TrackHandleBase.h:56
SimulationHit.h
TrackCollHandle_SimulationTracks.h
TrackCollHandle_SimulationTracks::Imp::cut_excludeNeutrals
bool cut_excludeNeutrals
Definition: TrackCollHandle_SimulationTracks.cxx:69
VP1SGAccessHelper.h
IVP1System.h
TrackCollHandle_SimulationTracks::~TrackCollHandle_SimulationTracks
virtual ~TrackCollHandle_SimulationTracks()
Definition: TrackCollHandle_SimulationTracks.cxx:105
VP1SGContentsHelper.h
TrackType
Definition: TrackTypes.h:10
TrackCollHandleBase::name
const QString & name() const
Definition: TrackCollHandleBase.cxx:310
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
TrackHandle_SimulationTrack.h
SimBarCode::ExtBarCode
std::pair< int, HepMcParticleLink::index_type > ExtBarCode
Definition: SimBarCode.h:42