36#include "GaudiKernel/IPartPropSvc.h"
43 const float FPGATrackSim_PT_TRUTHMIN = 400.;
44 const float FPGATrackSim_Z_TRUTHMIN = 2300.;
48 base_class(algname, name, ifc)
77 return StatusCode::SUCCESS;
82 return StatusCode::SUCCESS;
96 event_info.
setLB(eventInfo->lumiBlock());
97 event_info.
setBCID(eventInfo->bcid());
112 std::vector <FPGATrackSimCluster> clusters;
119 std::vector <FPGATrackSimTruthTrack> truth;
124 std::vector <FPGATrackSimOfflineTrack>
offline;
133 return StatusCode::SUCCESS;
140 ATH_MSG_DEBUG(
"read Offline tracks, size= " << offlineTracksHandle->size());
146 tmpOfflineTrack.
setQOverPt(trackParticle->pt() > 0 ? trackParticle->charge() / trackParticle->pt() : 0);
147 tmpOfflineTrack.
setEta(trackParticle->eta());
148 tmpOfflineTrack.
setPhi(trackParticle->phi());
149 tmpOfflineTrack.
setD0(trackParticle->d0());
150 tmpOfflineTrack.
setZ0(trackParticle->z0());
152 const Trk::TrackStates* trackStates = trackParticle->track()->trackStateOnSurfaces();
153 if (trackStates ==
nullptr) {
155 return StatusCode::FAILURE;
158 if (tsos ==
nullptr)
continue;
161 if (tsos->trackParameters() !=
nullptr &&
162 tsos->trackParameters()->associatedSurface().associatedDetectorElement() !=
nullptr &&
163 tsos->trackParameters()->associatedSurface().associatedDetectorElement()->identify() != 0
179 else if (
m_sctId->is_sct(hitId)) {
187 tmpOfflineHit.
setLocY(-99999.9);
189 tmpOfflineTrack.
addHit(tmpOfflineHit);
193 offline.push_back(tmpOfflineTrack);
197 return StatusCode::SUCCESS;
207 const EventContext& eventContext)
const
210 unsigned int hitIndex = 0u;
215 return StatusCode::SUCCESS;
223 unsigned int& hitIndex,
224 const EventContext& eventContext)
const {
232 if (pixel_rdoCollection ==
nullptr) {
continue; }
245 hitIndexMap[rdoId] = hitIndex;
250 hitIndexMap[tmpId] = hitIndex;
256 InDetSimDataCollection::const_iterator iter(pixelSDOHandle->find(rdoId));
257 if (nCells > 1 && iter == pixelSDOHandle->end()) {
259 for (
int ii = 0; ii < nCells && iter == pixelSDOHandle->end(); ++ii) {
264 if (iter != pixelSDOHandle->end()) { bestTruthLink =
getTruthInformation(iter, parentMask); }
277 int barrel_ec =
m_pixelId->barrel_ec(rdoId);
280 else if (barrel_ec == 2)
282 else if (barrel_ec == -2)
297 tmpSGhit.
setToT(pixelRawData->getToT());
306 tmpSGhit.
setBarcode(std::numeric_limits<HepMcParticleLink::barcode_type>::max());
307 tmpSGhit.
setUniqueID(std::numeric_limits<HepMcParticleLink::barcode_type>::max());
310 tmpSGhit.
setBarcodePt(
static_cast<unsigned long>(std::ceil(bestParent ? bestParent->momentum().perp() : 0.)));
321 eventHeader->
addHit(tmpSGhit);
325 return StatusCode::SUCCESS;
332 unsigned int& hitIndex,
333 const EventContext& eventContext)
const {
335 constexpr int MaxChannelinStripRow = 128;
341 if (SCT_Collection ==
nullptr) {
continue; }
343 std::map<int, bool> firedStrips;
344 std::map<int, const SCT_RDORawData*> firedStripsToRDO;
350 const Identifier rdoId = sctRawData->identify();
351 const int baseLineStrip{
m_sctId->strip(rdoId)};
352 for(
int i = 0; i < sctRawData->getGroupSize(); i++) {
353 firedStrips[baseLineStrip+ i] =
true;
354 firedStripsToRDO[baseLineStrip + i] = sctRawData;
360 std::map<int, int> stripEncodingForITK;
361 std::map<int, const SCT_RDORawData* > stripEncodingForITKToRDO;
362 for(
const auto& [stripID, fired]: firedStrips)
370 std::bitset<3> hitMap;
374 int currChipID = stripID / MaxChannelinStripRow;
376 int maxStripIDForCurrChip = (currChipID + 1) * MaxChannelinStripRow;
378 for(
int i = 0; i < 3; i++)
381 if((stripID + 1 + i) >= maxStripIDForCurrChip)
continue;
383 if(firedStrips.find(stripID + 1 + i) != firedStrips.end())
385 if(firedStrips.at(stripID + 1 + i))
388 firedStrips[stripID + 1 + i] =
false;
398 stripEncodingForITK[stripID] = (int)(hitMap.to_ulong());
399 stripEncodingForITKToRDO[stripID] = firedStripsToRDO[stripID];
403 for(
const auto& [stripID, fired]: firedStrips)
413 std::pair<Amg::Vector3D, Amg::Vector3D> endsOfStrip = sielement->
endsOfStrip(localPos);
415 hitIndexMap[rdoId] = hitIndex;
422 InDetSimDataCollection::const_iterator iter(stripSDOHandle->find(rdoId));
424 if (iter != stripSDOHandle->end()) { bestTruthLink =
getTruthInformation(iter, parentMask); }
436 int barrel_ec =
m_sctId->barrel_ec(rdoId);
439 else if (barrel_ec == 2)
441 else if (barrel_ec == -2)
461 tmpSGhit.
setBarcode(std::numeric_limits<HepMcParticleLink::barcode_type>::max());
462 tmpSGhit.
setUniqueID(std::numeric_limits<HepMcParticleLink::barcode_type>::max());
466 if(stripEncodingForITK.find(stripID) != stripEncodingForITK.end())
470 int chipID = stripID / MaxChannelinStripRow;
471 int ITkStripID = stripID % MaxChannelinStripRow;
477 int offset =
m_sctId->eta_module(rdoId) % 2;
478 if(
m_sctId->barrel_ec(rdoId) == 0) offset = (std::abs(
m_sctId->eta_module(rdoId)) - 1) % 2;
480 ITkStripID += offset * MaxChannelinStripRow;
488 tmpSGhit.
setBarcodePt(
static_cast<unsigned long>(std::ceil(bestParent ? bestParent->momentum().perp() : 0.)));
490 tmpSGhit.
setX(0.5 * (endsOfStrip.first.x() + endsOfStrip.second.x()));
491 tmpSGhit.
setY(0.5 * (endsOfStrip.first.y() + endsOfStrip.second.y()));
492 tmpSGhit.
setZ(0.5 * (endsOfStrip.first.z() + endsOfStrip.second.z()));
502 eventHeader->
addHit(tmpSGhit);
507 return StatusCode::SUCCESS;
513 unsigned int pixelClusterIndex = 0;
517 for (
const InDet::SiClusterCollection* pixelClusterCollection : *pixelClusterContainerHandle) {
518 if (pixelClusterCollection ==
nullptr) {
528 for (
const Identifier& rdoId : cluster->rdoList()) {
534 InDetSimDataCollection::const_iterator iter(pixelSDOHandle->find(rdoId));
536 if (nCells > 1 && iter == pixelSDOHandle->end()) {
538 for (
int ii = 0; ii < nCells && iter == pixelSDOHandle->end(); ++ii) {
546 pixelClusterIndexMap[theId] = pixelClusterIndex;
551 return StatusCode::SUCCESS;
564 for (
const InDet::SiClusterCollection* pixelClusterCollection : *pixelClusterContainerHandler) {
565 if (pixelClusterCollection ==
nullptr) {
569 const int size = pixelClusterCollection->size();
577 for (
const Identifier& rdoId : cluster->rdoList()) {
582 InDetSimDataCollection::const_iterator iter(pixelSDOHandle->find(rdoId));
584 if (nCells > 1 && iter == pixelSDOHandle->end()) {
586 for (
int ii = 0; ii < nCells && iter == pixelSDOHandle->end(); ++ii) {
591 if (iter != pixelSDOHandle->end()) { bestTruthLink =
getTruthInformation(iter, parentMask); }
607 clusterEquiv.
setX(globalPos.x());
608 clusterEquiv.
setY(globalPos.y());
609 clusterEquiv.
setZ(globalPos.z());
614 int barrel_ec =
m_pixelId->barrel_ec(theID);
617 else if (barrel_ec == 2)
619 else if (barrel_ec == -2)
630 clusterEquiv.
setPhiWidth(cluster->width().colRow()[1]);
631 clusterEquiv.
setEtaWidth(cluster->width().colRow()[0]);
639 clusterEquiv.
setEventIndex(std::numeric_limits<long>::max());
640 clusterEquiv.
setBarcode(std::numeric_limits<HepMcParticleLink::barcode_type>::max());
641 clusterEquiv.
setUniqueID(std::numeric_limits<HepMcParticleLink::barcode_type>::max());
644 clusterEquiv.
setBarcodePt(
static_cast<unsigned long>(std::ceil(bestParent ? bestParent->momentum().perp() : 0.)));
647 clusters.push_back(clusterOut);
659 if (SCT_Collection ==
nullptr) {
continue; }
661 const Identifier rdoId = sctRawData->identify();
672 InDetSimDataCollection::const_iterator iter(stripSDOHandle->find(rdoId));
674 if (iter != stripSDOHandle->end()) { bestTruthLink =
getTruthInformation(iter, parentMask); }
689 int barrel_ec =
m_sctId->barrel_ec(rdoId);
692 else if (barrel_ec == 2)
694 else if (barrel_ec == -2)
706 clusterEquiv.
setPhiWidth(sctRawData->getGroupSize());
714 clusterEquiv.
setEventIndex(std::numeric_limits<long>::max());
715 clusterEquiv.
setBarcode(std::numeric_limits<HepMcParticleLink::barcode_type>::max());
716 clusterEquiv.
setUniqueID(std::numeric_limits<HepMcParticleLink::barcode_type>::max());
719 clusterEquiv.
setBarcodePt(
static_cast<unsigned long>(std::ceil(bestParent ? bestParent->momentum().perp() : 0.)));
722 clusters.push_back(clusterOut);
727 return StatusCode::SUCCESS;
734 ATH_MSG_DEBUG(
"Dump truth tracks, size " << simTracksHandle->size());
737 for (
unsigned int ievt = 0; ievt < simTracksHandle->size(); ++ievt) {
740 HepGeom::Point3D<double> primaryVtx(0., 0., 0.);
745 primaryVtx.set(spv->position().x(),
747 spv->position().z());
748 ATH_MSG_DEBUG(
"using signal process vertex for eventIndex " << ievt <<
":"
749 << primaryVtx.x() <<
"\t" << primaryVtx.y() <<
"\t" << primaryVtx.z());
751 for (
const auto& particle: *genEvent) {
752 const int pdgcode = particle->pdg_id();
754 if (particle->production_vertex() ==
nullptr) {
758 if (std::abs(
charge) < 0.5) {
765 const Amg::Vector3D momentum(particle->momentum().px(), particle->momentum().py(), particle->momentum().pz());
766 const Amg::Vector3D position(particle->production_vertex()->position().x(), particle->production_vertex()->position().y(), particle->production_vertex()->position().z());
778 const double track_truth_d0 = tP ? tP->parameters()[
Trk::d0] : 999.;
779 const double track_truth_phi = tP ? tP->parameters()[
Trk::phi] : 999.;
780 const double track_truth_p = (tP && fabs(tP->parameters()[
Trk::qOverP]) > 1.e-8) ?
781 tP->charge() / tP->parameters()[
Trk::qOverP] : 10E7;
782 const double track_truth_x0 = tP ? tP->position().x() : 999.;
783 const double track_truth_y0 = tP ? tP->position().y() : 999.;
784 const double track_truth_z0 = tP ? tP->parameters()[
Trk::z0] : 999.;
785 const double track_truth_q = tP ? tP->charge() : 0.;
786 const double track_truth_sinphi = tP ? std::sin(tP->parameters()[
Trk::phi]) : -1.;
787 const double track_truth_cosphi = tP ? std::cos(tP->parameters()[
Trk::phi]) : -1.;
788 const double track_truth_sintheta = tP ? std::sin(tP->parameters()[
Trk::theta]) : -1.;
789 const double track_truth_costheta = tP ? std::cos(tP->parameters()[
Trk::theta]) : -1.;
790 double truth_d0corr = track_truth_d0 - (primaryVtx.y() * cos(track_truth_phi) - primaryVtx.x() * sin(track_truth_phi));
791 double truth_zvertex = 0.;
792 const HepGeom::Point3D<double> startVertex(particle->production_vertex()->position().x(), particle->production_vertex()->position().y(), particle->production_vertex()->position().z());
794 bool isPrimary =
true;
795 if (std::abs(truth_d0corr) > 2.) { isPrimary =
false; }
799 if (isPrimary && particle->production_vertex()) {
800 const HepGeom::Point3D<double> startVertex(particle->production_vertex()->position().x(), particle->production_vertex()->position().y(), particle->production_vertex()->position().z());
801 if (std::abs(startVertex.z() - truth_zvertex) > 100.) { isPrimary =
false; }
802 if (particle->end_vertex()) {
803 HepGeom::Point3D<double> endVertex(particle->end_vertex()->position().x(), particle->end_vertex()->position().y(), particle->end_vertex()->position().z());
804 if (endVertex.perp() < FPGATrackSim_PT_TRUTHMIN && std::abs(endVertex.z()) < FPGATrackSim_Z_TRUTHMIN) { isPrimary =
false; }
814 tmpSGTrack.
setVtxX(track_truth_x0);
815 tmpSGTrack.
setVtxY(track_truth_y0);
816 tmpSGTrack.
setVtxZ(track_truth_z0);
817 tmpSGTrack.
setD0(track_truth_d0);
818 tmpSGTrack.
setZ0(track_truth_z0);
819 tmpSGTrack.
setQ(track_truth_q);
820 tmpSGTrack.
setPX(track_truth_p * (track_truth_cosphi * track_truth_sintheta));
821 tmpSGTrack.
setPY(track_truth_p * (track_truth_sinphi * track_truth_sintheta));
822 tmpSGTrack.
setPZ(track_truth_p * track_truth_costheta);
824 tmpSGTrack.
setStatus(particle->status());
830 truth.push_back(tmpSGTrack);
835 return StatusCode::SUCCESS;
843 const std::vector<InDetSimData::Deposit>& deposits(sdo.
getdeposits());
844 float bestPt{-999.f};
849 if (!particleLink.
isValid()) {
continue; }
850 const float genEta = particleLink->momentum().pseudoRapidity();
851 const float genPt = particleLink->momentum().perp();
857 if (std::fabs(genEta) >
m_maxEta) {
continue; }
859 if (bestPt < genPt) {
861 bestTruthLink = &particleLink;
866 return bestTruthLink;
#define ATH_CHECK
Evaluate an expression and check for errors.
double charge(const T &p)
: FPGATrackSim-specific class to represent an hit in the detector.
ATLAS-specific HepMC functions.
size_t size() const
Number of registered mappings.
void setClusterEquiv(const FPGATrackSimHit &input)
void setaverageInteractionsPerCrossing(const int &val)
void setBCID(const int &val)
void setLB(const int &val)
void setRunNumber(const unsigned long &val)
void setlevel1TriggerType(const unsigned int &val)
void setactualInteractionsPerCrossing(const int &val)
void setEventNumber(const unsigned long &val)
void setextendedLevel1ID(const unsigned int &val)
void setPhiModule(unsigned v)
void setIdentifierHash(unsigned v)
void setEtaIndex(unsigned v)
void setEventIndex(long v)
void setPhiIndex(unsigned v)
void setStripChipIDForITk(int v)
long getEventIndex() const
void setHitType(HitType type)
float getBarcodePt() const
void setPhiCoord(float v)
void setIdentifier(unsigned int v)
void setBarcode(const HepMcParticleLink::barcode_type &v)
void setisValidForITkHit(bool v)
void setRdoIdentifier(Identifier::value_type v)
void setParentageMask(unsigned long v)
void setBarcodePt(float v)
HepMcParticleLink::barcode_type getBarcode() const
void setLayerDisk(unsigned v)
void setStripHitMapForITk(int v)
void setStripRowIDForITk(int v)
void setEtaCoord(float v)
void setTruth(const FPGATrackSimMultiTruth &v)
void setEtaWidth(unsigned v)
void setPhiWidth(unsigned v)
void setUniqueID(const HepMcParticleLink::barcode_type &v)
void setDetectorZone(DetectorZone detZone)
void setDetType(SiliconTech detType)
void maximize(const FPGATrackSimMultiTruth::Barcode &code, const FPGATrackSimMultiTruth::Weight &weight)
std::pair< unsigned long, unsigned long > Barcode
void setClusterID(int clus)
void setIsBarrel(bool is)
void setTrackNumber(int track)
void setQOverPt(double v)
void addHit(const FPGATrackSimOfflineHit &s)
void addOfflineCluster(const FPGATrackSimCluster &c) const
size_t nTruthTracks() const
size_t nOfflineClusters() const
void addOfflineTrack(const FPGATrackSimOfflineTrack &t) const
void addTruthTrack(const FPGATrackSimTruthTrack &t) const
size_t nOfflineTracks() const
void setUniqueID(const HepMcParticleLink::barcode_type &v)
void setBarcode(const HepMcParticleLink::barcode_type &v)
void setEventIndex(int v)
a link optimized in size for a GenParticle in a McEventCollection
int id() const
Return the id of the target particle.
bool isValid() const
Validity check.
HepMC::ConstGenParticlePtr cptr() const
Dereference.
index_type eventIndex() const
Return the event number of the referenced GenEvent.
int barcode() const
Return the barcode of the target particle.
value_type get_compact() const
Get the compact id.
value_type get_compact() const
Get the compact id.
Identifier32 get_identifier32() const
Get the 32-bit version Identifier, will be invalid if >32 bits needed.
virtual SiCellId connectedCell(const SiReadoutCellId &readoutId, int number) const =0
readout id -> id of connected diodes.
virtual SiLocalPosition localPositionOfCell(const SiCellId &cellId) const =0
readout or diode id -> position.
Identifier for the strip or pixel cell.
Base class for the detector design classes for Pixel and SCT.
Class to hold geometrical description of a silicon detector element.
virtual SiCellId cellIdFromIdentifier(const Identifier &identifier) const override final
SiCellId from Identifier.
virtual const SiDetectorDesign & design() const override final
access to the local description (inline):
std::pair< Amg::Vector3D, Amg::Vector3D > endsOfStrip(const Amg::Vector2D &position) const
Special method for SCT to retrieve the two ends of a "strip" Returned coordinates are in global frame...
virtual Identifier identifierFromCellId(const SiCellId &cellId) const override final
Identifier <-> SiCellId (ie strip number or pixel eta_index,phi_index) Identifier from SiCellId (ie s...
Class to represent a position in the natural frame of a silicon sensor, for Pixel and SCT For Pixel: ...
double xPhi() const
position along phi direction:
double xEta() const
position along eta direction:
Identifier for the strip or pixel readout cell.
SiCellId connectedCell(const SiCellId cellId, int number) const
Get the cell ids sharing the readout for this cell.
virtual IdentifierHash identifyHash() const override final
identifier hash (inline)
int numberOfConnectedCells(const SiCellId cellId) const
Test if readout cell has more than one diode associated with it.
HepGeom::Point3D< double > globalPosition(const HepGeom::Point3D< double > &localPos) const
transform a reconstruction local position into a global position (inline):
virtual Identifier identify() const override final
identifier of this detector element (inline)
Amg::Vector2D rawLocalPositionOfCell(const SiCellId &cellId) const
Returns position (center) of cell.
virtual Identifier identify() const override final
std::pair< HepMcParticleLink, float > Deposit
const std::vector< Deposit > & getdeposits() const
This class is the pure abstract base class for all fittable tracking measurements.
const LocalParameters & localParameters() const
Interface method to get the LocalParameters.
Class describing the Line to which the Perigee refers to.
Class to handle RIO On Tracks ROT) for InDet and Muons, it inherits from the common MeasurementBase.
Identifier identify() const
return the identifier -extends MeasurementBase
represents the track state (measurement, material, fit parameters and quality) at a surface.
@ Measurement
This is a measurement, and will at least contain a Trk::MeasurementBase.
Eigen::Matrix< double, 2, 1 > Vector2D
Eigen::Matrix< double, 3, 1 > Vector3D
ConstGenVertexPtr signal_process_vertex(const GenEvent *e)
HepMC3::ConstGenParticlePtr ConstGenParticlePtr
bool is_simulation_particle(const T &p)
Method to establish if a particle (or barcode) was created during the simulation (TODO update to be s...
HepMC3::ConstGenVertexPtr ConstGenVertexPtr
HepMC3::GenEvent GenEvent
bool isStable(const T &p)
Identify if the particle is stable, i.e. has not decayed.
double charge(const T &p)
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
DataVector< const Trk::TrackStateOnSurface > TrackStates
CurvilinearParametersT< TrackParametersDim, Charged, PlaneSurface > CurvilinearParameters
TrackParticle_v1 TrackParticle
Reference the current persistent version: