From 2eab6cd9df099cbb8452d7d6ee3d117acba8d1ff Mon Sep 17 00:00:00 2001 From: Giovanni Marchiori Date: Wed, 29 Jan 2025 17:35:16 +0100 Subject: [PATCH] indentation --- .../components/TracksFromGenParticlesAlg.cpp | 354 +++++++++--------- 1 file changed, 177 insertions(+), 177 deletions(-) diff --git a/Tracking/components/TracksFromGenParticlesAlg.cpp b/Tracking/components/TracksFromGenParticlesAlg.cpp index 3e42317..10ce899 100644 --- a/Tracking/components/TracksFromGenParticlesAlg.cpp +++ b/Tracking/components/TracksFromGenParticlesAlg.cpp @@ -71,17 +71,17 @@ class TracksFromGenParticlesAlg : public Gaudi::Algorithm { /// Handle for the output links between reco and gen particles mutable DataHandle m_links{"TracksFromGenParticlesAlgAssociation", Gaudi::DataHandle::Writer, this}; - // the next two functions have been copied from k4GaudiPandora and DDMarlinPandora / DDPandoraPFANewProcessor - // ideally they could be put in a separate file named e.g. DDUtils.cc - double getFieldFromCompact(); - dd4hep::rec::LayeredCalorimeterData * getExtension(unsigned int includeFlag, unsigned int excludeFlag=0); + // the next two functions have been copied from k4GaudiPandora and DDMarlinPandora / DDPandoraPFANewProcessor + // ideally they could be put in a separate file named e.g. DDUtils.cc + double getFieldFromCompact(); + dd4hep::rec::LayeredCalorimeterData * getExtension(unsigned int includeFlag, unsigned int excludeFlag=0); }; double TracksFromGenParticlesAlg::getFieldFromCompact() { - dd4hep::Detector& mainDetector = dd4hep::Detector::getInstance(); - const double position[3]={0,0,0}; // position to calculate magnetic field at (the origin in this case) - double magneticFieldVector[3]={0,0,0}; // initialise object to hold magnetic field - mainDetector.field().magneticField(position,magneticFieldVector); // get the magnetic field vector from DD4hep + dd4hep::Detector& mainDetector = dd4hep::Detector::getInstance(); + const double position[3]={0,0,0}; // position to calculate magnetic field at (the origin in this case) + double magneticFieldVector[3]={0,0,0}; // initialise object to hold magnetic field + mainDetector.field().magneticField(position,magneticFieldVector); // get the magnetic field vector from DD4hep return magneticFieldVector[2]/dd4hep::tesla; // z component at (0,0,0) } @@ -93,8 +93,8 @@ dd4hep::rec::LayeredCalorimeterData * TracksFromGenParticlesAlg::getExtension(un const std::vector< dd4hep::DetElement>& theDetectors = dd4hep::DetectorSelector(mainDetector).detectors( includeFlag, excludeFlag ); debug() << " getExtension : includeFlag: " << dd4hep::DetType( includeFlag ) << " excludeFlag: " << dd4hep::DetType( excludeFlag ) - << " found : " << theDetectors.size() << " - first det: " << theDetectors.at(0).name() - << endmsg; + << " found : " << theDetectors.size() << " - first det: " << theDetectors.at(0).name() + << endmsg; if( theDetectors.size() != 1 ){ @@ -163,179 +163,179 @@ StatusCode TracksFromGenParticlesAlg::initialize() { } StatusCode TracksFromGenParticlesAlg::execute(const EventContext&) const { - // Get the input MC particle collection - const edm4hep::MCParticleCollection* genParticleColl = m_inputMCParticles.get(); - - // Create the output track collection and track gen<->reco links collection - auto outputTrackCollection = new edm4hep::TrackCollection(); - auto MCRecoTrackParticleAssociationCollection = new edm4hep::TrackMCParticleLinkCollection(); - - // loop over the gen particles, find charged ones, and create the corresponding reco particles - int iparticle = 0; - for (const auto& genParticle : *genParticleColl) { - debug() << endmsg; - debug() << "Gen. particle: " << genParticle << endmsg; - debug() <<" particle "< > trackHits; - for ( size_t ih=0; ih*> (m_inputSimTrackerHitCollectionHandles[ih]); - const edm4hep::SimTrackerHitCollection* coll = handle->get(); - for (const auto& hit : *coll) { - const edm4hep::MCParticle particle = hit.getParticle(); - std::array ahit{hit.x(), hit.y(), hit.z(), hit.getMomentum()[0], hit.getMomentum()[1], hit.getMomentum()[2], hit.getTime()}; - if(particle.getObjectID() == genParticle.getObjectID()) trackHits.push_back(ahit); - } + // Get the input MC particle collection + const edm4hep::MCParticleCollection* genParticleColl = m_inputMCParticles.get(); + + // Create the output track collection and track gen<->reco links collection + auto outputTrackCollection = new edm4hep::TrackCollection(); + auto MCRecoTrackParticleAssociationCollection = new edm4hep::TrackMCParticleLinkCollection(); + + // loop over the gen particles, find charged ones, and create the corresponding reco particles + int iparticle = 0; + for (const auto& genParticle : *genParticleColl) { + debug() << endmsg; + debug() << "Gen. particle: " << genParticle << endmsg; + debug() <<" particle "< > trackHits; + for ( size_t ih=0; ih*> (m_inputSimTrackerHitCollectionHandles[ih]); + const edm4hep::SimTrackerHitCollection* coll = handle->get(); + for (const auto& hit : *coll) { + const edm4hep::MCParticle particle = hit.getParticle(); + std::array ahit{hit.x(), hit.y(), hit.z(), hit.getMomentum()[0], hit.getMomentum()[1], hit.getMomentum()[2], hit.getTime()}; + if(particle.getObjectID() == genParticle.getObjectID()) trackHits.push_back(ahit); } - - if(!trackHits.empty()) - { - // particles with at least one SimTrackerHit - debug() << "Number of SimTrackerHits: " << trackHits.size() << endmsg; - - // sort the hits according to their time - std::sort(trackHits.begin(), trackHits.end(), [](const std::array a, const std::array b) { - return a[6]::max()); - const pandora::Helix helix(trackState_IP.phi, - trackState_IP.D0, - trackState_IP.Z0, - trackState_IP.omega, - trackState_IP.tanLambda, - m_Bz); - const pandora::CartesianVector& referencePoint(helix.GetReferencePoint()); - - pandora::CartesianVector bestECalProjection(0.f, 0.f, 0.f); - const int signPz((helix.GetMomentum().GetZ() > 0.f) ? 1 : -1); - (void)helix.GetPointInZ(static_cast(signPz) * m_eCalEndCapInnerZ, referencePoint, - bestECalProjection, minGenericTime); - - // Then project to barrel surface(s), and keep projection with lower arrival time - pandora::CartesianVector barrelProjection(0.f, 0.f, 0.f); - float genericTime(std::numeric_limits::max()); - const pandora::StatusCode statusCode(helix.GetPointOnCircle(m_eCalBarrelInnerR, referencePoint, barrelProjection, genericTime)); - if ((pandora::STATUS_CODE_SUCCESS == statusCode) && (genericTime < minGenericTime)) { - minGenericTime = genericTime; - bestECalProjection = barrelProjection; - } - - double posAtCalorimeter[] = {bestECalProjection.GetX(), bestECalProjection.GetY(), bestECalProjection.GetZ()}; - debug() << "Radius at calorimeter: " << std::sqrt(posAtCalorimeter[0]*posAtCalorimeter[0] + posAtCalorimeter[1]*posAtCalorimeter[1]) << endmsg; - double momAtCalorimeter[] = {0.,0.,0.}; - // get extrapolated momentum from the helix with ref point at last hit - helixAtLastHit.getExtrapolatedMomentum(posAtCalorimeter, momAtCalorimeter); - // produce new helix at calorimeter position - auto helixAtCalorimeter = HelixClass_double(); - helixAtCalorimeter.Initialize_VP(posAtCalorimeter, momAtCalorimeter, genParticle.getCharge(), m_Bz); - // fill the TrackState parameters - trackState_AtCalorimeter.location = edm4hep::TrackState::AtCalorimeter; - trackState_AtCalorimeter.D0 = helixAtCalorimeter.getD0(); - trackState_AtCalorimeter.phi = helixAtCalorimeter.getPhi0(); - trackState_AtCalorimeter.omega = helixAtCalorimeter.getOmega(); - trackState_AtCalorimeter.Z0 = helixAtCalorimeter.getZ0(); - trackState_AtCalorimeter.tanLambda = helixAtCalorimeter.getTanLambda(); - trackState_AtCalorimeter.referencePoint = edm4hep::Vector3f((float)posAtCalorimeter[0], - (float)posAtCalorimeter[1], - (float)posAtCalorimeter[2]); - // attach the TrackState to the track - trackFromGen.addToTrackStates(trackState_AtCalorimeter); - - outputTrackCollection->push_back(trackFromGen); - - // Building the association between tracks and genParticles - auto MCRecoTrackParticleAssociation = edm4hep::MutableTrackMCParticleLink(); - MCRecoTrackParticleAssociation.setFrom(trackFromGen); - MCRecoTrackParticleAssociation.setTo(genParticle); - MCRecoTrackParticleAssociationCollection->push_back(MCRecoTrackParticleAssociation); + } + + if(!trackHits.empty()) + { + // particles with at least one SimTrackerHit + debug() << "Number of SimTrackerHits: " << trackHits.size() << endmsg; + + // sort the hits according to their time + std::sort(trackHits.begin(), trackHits.end(), [](const std::array a, const std::array b) { + return a[6]::max()); + const pandora::Helix helix(trackState_IP.phi, + trackState_IP.D0, + trackState_IP.Z0, + trackState_IP.omega, + trackState_IP.tanLambda, + m_Bz); + const pandora::CartesianVector& referencePoint(helix.GetReferencePoint()); + + pandora::CartesianVector bestECalProjection(0.f, 0.f, 0.f); + const int signPz((helix.GetMomentum().GetZ() > 0.f) ? 1 : -1); + (void)helix.GetPointInZ(static_cast(signPz) * m_eCalEndCapInnerZ, referencePoint, + bestECalProjection, minGenericTime); + + // Then project to barrel surface(s), and keep projection with lower arrival time + pandora::CartesianVector barrelProjection(0.f, 0.f, 0.f); + float genericTime(std::numeric_limits::max()); + const pandora::StatusCode statusCode(helix.GetPointOnCircle(m_eCalBarrelInnerR, referencePoint, barrelProjection, genericTime)); + if ((pandora::STATUS_CODE_SUCCESS == statusCode) && (genericTime < minGenericTime)) { + minGenericTime = genericTime; + bestECalProjection = barrelProjection; } + + double posAtCalorimeter[] = {bestECalProjection.GetX(), bestECalProjection.GetY(), bestECalProjection.GetZ()}; + debug() << "Radius at calorimeter: " << std::sqrt(posAtCalorimeter[0]*posAtCalorimeter[0] + posAtCalorimeter[1]*posAtCalorimeter[1]) << endmsg; + double momAtCalorimeter[] = {0.,0.,0.}; + // get extrapolated momentum from the helix with ref point at last hit + helixAtLastHit.getExtrapolatedMomentum(posAtCalorimeter, momAtCalorimeter); + // produce new helix at calorimeter position + auto helixAtCalorimeter = HelixClass_double(); + helixAtCalorimeter.Initialize_VP(posAtCalorimeter, momAtCalorimeter, genParticle.getCharge(), m_Bz); + // fill the TrackState parameters + trackState_AtCalorimeter.location = edm4hep::TrackState::AtCalorimeter; + trackState_AtCalorimeter.D0 = helixAtCalorimeter.getD0(); + trackState_AtCalorimeter.phi = helixAtCalorimeter.getPhi0(); + trackState_AtCalorimeter.omega = helixAtCalorimeter.getOmega(); + trackState_AtCalorimeter.Z0 = helixAtCalorimeter.getZ0(); + trackState_AtCalorimeter.tanLambda = helixAtCalorimeter.getTanLambda(); + trackState_AtCalorimeter.referencePoint = edm4hep::Vector3f((float)posAtCalorimeter[0], + (float)posAtCalorimeter[1], + (float)posAtCalorimeter[2]); + // attach the TrackState to the track + trackFromGen.addToTrackStates(trackState_AtCalorimeter); + + outputTrackCollection->push_back(trackFromGen); + + // Building the association between tracks and genParticles + auto MCRecoTrackParticleAssociation = edm4hep::MutableTrackMCParticleLink(); + MCRecoTrackParticleAssociation.setFrom(trackFromGen); + MCRecoTrackParticleAssociation.setTo(genParticle); + MCRecoTrackParticleAssociationCollection->push_back(MCRecoTrackParticleAssociation); } + } - // push the outputTrackCollection to event store - m_tracks.put(outputTrackCollection); - m_links.put(MCRecoTrackParticleAssociationCollection); + // push the outputTrackCollection to event store + m_tracks.put(outputTrackCollection); + m_links.put(MCRecoTrackParticleAssociationCollection); - debug() << "Output tracks collection size: " << outputTrackCollection->size() << endmsg; + debug() << "Output tracks collection size: " << outputTrackCollection->size() << endmsg; - return StatusCode::SUCCESS; + return StatusCode::SUCCESS; } StatusCode TracksFromGenParticlesAlg::finalize() { return Gaudi::Algorithm::finalize(); }