38#include "GaudiKernel/IPartPropSvc.h"
46 const float FPGATrackSim_PT_TRUTHMIN = 400.;
47 const float FPGATrackSim_Z_TRUTHMIN = 2300.;
51 base_class(algname, name, ifc)
62 SmartIF<IPartPropSvc> partPropSvc{service(
"PartPropSvc")};
84 return StatusCode::SUCCESS;
89 return StatusCode::SUCCESS;
103 event_info.
setLB(eventInfo->lumiBlock());
104 event_info.
setBCID(eventInfo->bcid());
119 std::vector <FPGATrackSimCluster> clusters;
126 std::vector <FPGATrackSimTruthTrack> truth;
131 std::vector <FPGATrackSimOfflineTrack>
offline;
140 return StatusCode::SUCCESS;
147 ATH_MSG_DEBUG(
"read Offline tracks, size= " << offlineTracksHandle->size());
153 tmpOfflineTrack.
setQOverPt(trackParticle->pt() > 0 ? trackParticle->charge() / trackParticle->pt() : 0);
154 tmpOfflineTrack.
setEta(trackParticle->eta());
155 tmpOfflineTrack.
setPhi(trackParticle->phi());
156 tmpOfflineTrack.
setD0(trackParticle->d0());
157 tmpOfflineTrack.
setZ0(trackParticle->z0());
159 const Trk::TrackStates* trackStates = trackParticle->track()->trackStateOnSurfaces();
160 if (trackStates ==
nullptr) {
162 return StatusCode::FAILURE;
165 if (tsos ==
nullptr)
continue;
168 if (tsos->trackParameters() !=
nullptr &&
169 tsos->trackParameters()->associatedSurface().associatedDetectorElement() !=
nullptr &&
170 tsos->trackParameters()->associatedSurface().associatedDetectorElement()->identify() != 0
186 else if (
m_sctId->is_sct(hitId)) {
194 tmpOfflineHit.
setLocY(-99999.9);
196 tmpOfflineTrack.
addHit(tmpOfflineHit);
200 offline.push_back(tmpOfflineTrack);
204 return StatusCode::SUCCESS;
214 unsigned int hitIndex = 0u;
219 return StatusCode::SUCCESS;
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.)));
325 return StatusCode::SUCCESS;
331 constexpr int MaxChannelinStripRow = 128;
337 if (SCT_Collection ==
nullptr) {
continue; }
339 std::map<int, bool> firedStrips;
340 std::map<int, const SCT_RDORawData*> firedStripsToRDO;
346 const Identifier rdoId = sctRawData->identify();
347 const int baseLineStrip{
m_sctId->strip(rdoId)};
348 for(
int i = 0; i < sctRawData->getGroupSize(); i++) {
349 firedStrips[baseLineStrip+ i] =
true;
350 firedStripsToRDO[baseLineStrip + i] = sctRawData;
356 std::map<int, int> stripEncodingForITK;
357 std::map<int, const SCT_RDORawData* > stripEncodingForITKToRDO;
358 for(
const auto& [stripID, fired]: firedStrips)
366 std::bitset<3> hitMap;
370 int currChipID = stripID / MaxChannelinStripRow;
372 int maxStripIDForCurrChip = (currChipID + 1) * MaxChannelinStripRow;
374 for(
int i = 0; i < 3; i++)
377 if((stripID + 1 + i) >= maxStripIDForCurrChip)
continue;
379 if(firedStrips.find(stripID + 1 + i) != firedStrips.end())
381 if(firedStrips.at(stripID + 1 + i))
384 firedStrips[stripID + 1 + i] =
false;
394 stripEncodingForITK[stripID] = (int)(hitMap.to_ulong());
395 stripEncodingForITKToRDO[stripID] = firedStripsToRDO[stripID];
399 for(
const auto& [stripID, fired]: firedStrips)
409 std::pair<Amg::Vector3D, Amg::Vector3D> endsOfStrip = sielement->
endsOfStrip(localPos);
411 hitIndexMap[rdoId] = hitIndex;
418 InDetSimDataCollection::const_iterator iter(stripSDOHandle->find(rdoId));
420 if (iter != stripSDOHandle->end()) { bestTruthLink =
getTruthInformation(iter, parentMask); }
432 int barrel_ec =
m_sctId->barrel_ec(rdoId);
435 else if (barrel_ec == 2)
437 else if (barrel_ec == -2)
457 tmpSGhit.
setBarcode(std::numeric_limits<HepMcParticleLink::barcode_type>::max());
458 tmpSGhit.
setUniqueID(std::numeric_limits<HepMcParticleLink::barcode_type>::max());
462 if(stripEncodingForITK.find(stripID) != stripEncodingForITK.end())
466 int chipID = stripID / MaxChannelinStripRow;
467 int ITkStripID = stripID % MaxChannelinStripRow;
473 int offset =
m_sctId->eta_module(rdoId) % 2;
474 if(
m_sctId->barrel_ec(rdoId) == 0) offset = (std::abs(
m_sctId->eta_module(rdoId)) - 1) % 2;
476 ITkStripID += offset * MaxChannelinStripRow;
484 tmpSGhit.
setBarcodePt(
static_cast<unsigned long>(std::ceil(bestParent ? bestParent->momentum().perp() : 0.)));
486 tmpSGhit.
setX(0.5 * (endsOfStrip.first.x() + endsOfStrip.second.x()));
487 tmpSGhit.
setY(0.5 * (endsOfStrip.first.y() + endsOfStrip.second.y()));
488 tmpSGhit.
setZ(0.5 * (endsOfStrip.first.z() + endsOfStrip.second.z()));
503 return StatusCode::SUCCESS;
509 unsigned int pixelClusterIndex = 0;
513 for (
const InDet::SiClusterCollection* pixelClusterCollection : *pixelClusterContainerHandle) {
514 if (pixelClusterCollection ==
nullptr) {
524 for (
const Identifier& rdoId : cluster->rdoList()) {
530 InDetSimDataCollection::const_iterator iter(pixelSDOHandle->find(rdoId));
532 if (nCells > 1 && iter == pixelSDOHandle->end()) {
534 for (
int ii = 0; ii < nCells && iter == pixelSDOHandle->end(); ++ii) {
542 pixelClusterIndexMap[theId] = pixelClusterIndex;
547 return StatusCode::SUCCESS;
559 for (
const InDet::SiClusterCollection* pixelClusterCollection : *pixelClusterContainerHandler) {
560 if (pixelClusterCollection ==
nullptr) {
564 const int size = pixelClusterCollection->size();
565 ATH_MSG_DEBUG(
"PixelClusterCollection found with " << size <<
" clusters");
572 for (
const Identifier& rdoId : cluster->rdoList()) {
577 InDetSimDataCollection::const_iterator iter(pixelSDOHandle->find(rdoId));
579 if (nCells > 1 && iter == pixelSDOHandle->end()) {
581 for (
int ii = 0; ii < nCells && iter == pixelSDOHandle->end(); ++ii) {
586 if (iter != pixelSDOHandle->end()) { bestTruthLink =
getTruthInformation(iter, parentMask); }
602 clusterEquiv.
setX(globalPos.x());
603 clusterEquiv.
setY(globalPos.y());
604 clusterEquiv.
setZ(globalPos.z());
609 int barrel_ec =
m_pixelId->barrel_ec(theID);
612 else if (barrel_ec == 2)
614 else if (barrel_ec == -2)
625 clusterEquiv.
setPhiWidth(cluster->width().colRow()[1]);
626 clusterEquiv.
setEtaWidth(cluster->width().colRow()[0]);
634 clusterEquiv.
setEventIndex(std::numeric_limits<long>::max());
635 clusterEquiv.
setBarcode(std::numeric_limits<HepMcParticleLink::barcode_type>::max());
636 clusterEquiv.
setUniqueID(std::numeric_limits<HepMcParticleLink::barcode_type>::max());
639 clusterEquiv.
setBarcodePt(
static_cast<unsigned long>(std::ceil(bestParent ? bestParent->momentum().perp() : 0.)));
642 clusters.push_back(clusterOut);
654 if (SCT_Collection ==
nullptr) {
continue; }
656 const Identifier rdoId = sctRawData->identify();
667 InDetSimDataCollection::const_iterator iter(stripSDOHandle->find(rdoId));
669 if (iter != stripSDOHandle->end()) { bestTruthLink =
getTruthInformation(iter, parentMask); }
684 int barrel_ec =
m_sctId->barrel_ec(rdoId);
687 else if (barrel_ec == 2)
689 else if (barrel_ec == -2)
701 clusterEquiv.
setPhiWidth(sctRawData->getGroupSize());
709 clusterEquiv.
setEventIndex(std::numeric_limits<long>::max());
710 clusterEquiv.
setBarcode(std::numeric_limits<HepMcParticleLink::barcode_type>::max());
711 clusterEquiv.
setUniqueID(std::numeric_limits<HepMcParticleLink::barcode_type>::max());
714 clusterEquiv.
setBarcodePt(
static_cast<unsigned long>(std::ceil(bestParent ? bestParent->momentum().perp() : 0.)));
717 clusters.push_back(clusterOut);
722 return StatusCode::SUCCESS;
729 ATH_MSG_DEBUG(
"Dump truth tracks, size " << simTracksHandle->size());
732 for (
unsigned int ievt = 0; ievt < simTracksHandle->size(); ++ievt) {
733 const HepMC::GenEvent* genEvent = simTracksHandle->at(ievt);
735 HepGeom::Point3D<double> primaryVtx(0., 0., 0.);
740 primaryVtx.set(spv->position().x(),
742 spv->position().z());
743 ATH_MSG_DEBUG(
"using signal process vertex for eventIndex " << ievt <<
":"
744 << primaryVtx.x() <<
"\t" << primaryVtx.y() <<
"\t" << primaryVtx.z());
746 for (
const auto& particle: *genEvent) {
747 const int pdgcode = particle->pdg_id();
749 if (particle->production_vertex() ==
nullptr) {
757 float charge = pd->charge();
758 if (pdgcode < 0)
charge *= -1.;
759 if (std::abs(
charge) < 0.5) {
766 const Amg::Vector3D momentum(particle->momentum().px(), particle->momentum().py(), particle->momentum().pz());
767 const Amg::Vector3D position(particle->production_vertex()->position().x(), particle->production_vertex()->position().y(), particle->production_vertex()->position().z());
779 const double track_truth_d0 = tP ? tP->parameters()[
Trk::d0] : 999.;
780 const double track_truth_phi = tP ? tP->parameters()[
Trk::phi] : 999.;
781 const double track_truth_p = (tP && fabs(tP->parameters()[
Trk::qOverP]) > 1.e-8) ?
782 tP->charge() / tP->parameters()[
Trk::qOverP] : 10E7;
783 const double track_truth_x0 = tP ? tP->position().x() : 999.;
784 const double track_truth_y0 = tP ? tP->position().y() : 999.;
785 const double track_truth_z0 = tP ? tP->parameters()[
Trk::z0] : 999.;
786 const double track_truth_q = tP ? tP->charge() : 0.;
787 const double track_truth_sinphi = tP ? std::sin(tP->parameters()[
Trk::phi]) : -1.;
788 const double track_truth_cosphi = tP ? std::cos(tP->parameters()[
Trk::phi]) : -1.;
789 const double track_truth_sintheta = tP ? std::sin(tP->parameters()[
Trk::theta]) : -1.;
790 const double track_truth_costheta = tP ? std::cos(tP->parameters()[
Trk::theta]) : -1.;
791 double truth_d0corr = track_truth_d0 - (primaryVtx.y() * cos(track_truth_phi) - primaryVtx.x() * sin(track_truth_phi));
792 double truth_zvertex = 0.;
793 const HepGeom::Point3D<double> startVertex(particle->production_vertex()->position().x(), particle->production_vertex()->position().y(), particle->production_vertex()->position().z());
795 bool isPrimary =
true;
796 if (std::abs(truth_d0corr) > 2.) { isPrimary =
false; }
800 if (isPrimary && particle->production_vertex()) {
801 const HepGeom::Point3D<double> startVertex(particle->production_vertex()->position().x(), particle->production_vertex()->position().y(), particle->production_vertex()->position().z());
802 if (std::abs(startVertex.z() - truth_zvertex) > 100.) { isPrimary =
false; }
803 if (particle->end_vertex()) {
804 HepGeom::Point3D<double> endVertex(particle->end_vertex()->position().x(), particle->end_vertex()->position().y(), particle->end_vertex()->position().z());
805 if (endVertex.perp() < FPGATrackSim_PT_TRUTHMIN && std::abs(endVertex.z()) < FPGATrackSim_Z_TRUTHMIN) { isPrimary =
false; }
815 tmpSGTrack.
setVtxX(track_truth_x0);
816 tmpSGTrack.
setVtxY(track_truth_y0);
817 tmpSGTrack.
setVtxZ(track_truth_z0);
818 tmpSGTrack.
setD0(track_truth_d0);
819 tmpSGTrack.
setZ0(track_truth_z0);
820 tmpSGTrack.
setVtxZ(primaryVtx.z());
821 tmpSGTrack.
setQ(track_truth_q);
822 tmpSGTrack.
setPX(track_truth_p * (track_truth_cosphi * track_truth_sintheta));
823 tmpSGTrack.
setPY(track_truth_p * (track_truth_sinphi * track_truth_sintheta));
824 tmpSGTrack.
setPZ(track_truth_p * track_truth_costheta);
826 tmpSGTrack.
setStatus(particle->status());
832 truth.push_back(tmpSGTrack);
837 return StatusCode::SUCCESS;
845 const std::vector<InDetSimData::Deposit>& deposits(sdo.
getdeposits());
846 float bestPt{-999.f};
851 if (!particleLink.
isValid()) {
continue; }
852 const float genEta = particleLink->momentum().pseudoRapidity();
853 const float genPt = particleLink->momentum().perp();
859 if (std::fabs(genEta) >
m_maxEta) {
continue; }
861 if (bestPt < genPt) {
863 bestTruthLink = &particleLink;
872 return bestTruthLink;
#define ATH_CHECK
Evaluate an expression and check for errors.
double charge(const T &p)
defines an "iterator" over instances of a given type in StoreGateSvc
: FPGATrackSim-specific class to represent an hit in the detector.
ATLAS-specific HepMC functions.
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)
size_t nTruthTracks() const
void addTruthTrack(const FPGATrackSimTruthTrack &t)
void addOfflineTrack(const FPGATrackSimOfflineTrack &t)
size_t nOfflineClusters() 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
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...
const GenParticle * ConstGenParticlePtr
GenVertex * signal_process_vertex(const GenEvent *e)
const HepMC::GenVertex * ConstGenVertexPtr
bool isStable(const T &p)
Identify if the particle is stable, i.e. has not decayed.
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: