Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RecoParticleFlow/PFProducer - some cleanup and modernization #26519

Merged
merged 5 commits into from Apr 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
83 changes: 16 additions & 67 deletions RecoParticleFlow/PFProducer/interface/KDTreeLinkerTools.h
Expand Up @@ -7,89 +7,38 @@
#include <map>
#include <set>

typedef std::set<reco::PFBlockElement*> BlockEltSet;
typedef std::set<const reco::PFRecHit*> RecHitSet;

typedef std::map<const reco::PFRecHit*, BlockEltSet> RecHit2BlockEltMap;
typedef std::map<reco::PFBlockElement*, BlockEltSet> BlockElt2BlockEltMap;
using BlockEltSet = std::set<reco::PFBlockElement *>;
using RecHitSet = std::set<const reco::PFRecHit *>;

using RecHit2BlockEltMap = std::map<const reco::PFRecHit *, BlockEltSet>;
using BlockElt2BlockEltMap = std::map<reco::PFBlockElement *, BlockEltSet>;

// Box structure used to define 2D field.
// It's used in KDTree building step to divide the detector
// space (ECAL, HCAL...) and in searching step to create a bounding
// box around the demanded point (Track collision point, PS projection...).
struct KDTreeBox
{
double dim1min, dim1max;
double dim2min, dim2max;

public:

KDTreeBox(double d1min, double d1max,
double d2min, double d2max)
: dim1min (d1min), dim1max(d1max)
, dim2min (d2min), dim2max(d2max)
{}

KDTreeBox()
: dim1min (0), dim1max(0)
, dim2min (0), dim2max(0)
{}
struct KDTreeBox {
double dim1min = 0.0;
double dim1max = 0.0;
double dim2min = 0.0;
double dim2max = 0.0;
};


// Data stored in each KDTree node.
// The dim1/dim2 fields are usually the duplication of some PFRecHit values
// (eta/phi or x/y). But in some situations, phi field is shifted by +-2.Pi
struct KDTreeNodeInfo
{
const reco::PFRecHit *ptr;
struct KDTreeNodeInfo {
const reco::PFRecHit *ptr = nullptr;
double dim1;
double dim2;

public:
KDTreeNodeInfo()
: ptr(nullptr)
{}

KDTreeNodeInfo(const reco::PFRecHit *rhptr,
double d1,
double d2)
: ptr(rhptr), dim1(d1), dim2(d2)
{}
};


// KDTree node.
struct KDTreeNode
{
// Data
KDTreeNodeInfo rh;

// Right/left sons.
KDTreeNode *left, *right;

// Region bounding box.
KDTreeBox region;

public:
KDTreeNode()
: left(nullptr), right(nullptr)
{}

void setAttributs(const KDTreeBox& regionBox,
const KDTreeNodeInfo& rhinfo)
{
rh = rhinfo;
region = regionBox;
}

void setAttributs(const KDTreeBox& regionBox)
{
region = regionBox;
}
struct KDTreeNode {
KDTreeNodeInfo rh; // data
KDTreeNode *left = nullptr; // left son
KDTreeNode *right = nullptr; // right son
KDTreeBox region; // Region bounding box
};



#endif
25 changes: 11 additions & 14 deletions RecoParticleFlow/PFProducer/interface/PFAlgo.h
Expand Up @@ -27,10 +27,13 @@
#include "DataFormats/TrackReco/interface/TrackFwd.h"
#include "DataFormats/VertexReco/interface/VertexFwd.h"
#include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h"
#include "DataFormats/Common/interface/ValueMap.h"

#include "RecoParticleFlow/PFProducer/interface/PFCandConnector.h"
#include "RecoParticleFlow/PFProducer/interface/PFMuonAlgo.h"
#include "RecoParticleFlow/PFProducer/interface/PFEGammaFilters.h"
#include "DataFormats/Common/interface/ValueMap.h"
#include "RecoParticleFlow/PFProducer/interface/PFElectronAlgo.h"
#include "RecoParticleFlow/PFProducer/interface/PFPhotonAlgo.h"

/// \brief Particle Flow Algorithm
/*!
Expand All @@ -42,25 +45,19 @@
class PFEnergyCalibration;
class PFSCEnergyCalibration;
class PFEnergyCalibrationHF;
class PFElectronAlgo;
class PFPhotonAlgo;
class PFMuonAlgo;

class PFAlgo {

public:

/// constructor
PFAlgo();

/// destructor
~PFAlgo();
PFAlgo(bool debug);

void setHOTag(bool ho) { useHO_ = ho;}
void setAlgo( int algo ) {algo_ = algo;}
void setPFMuonAlgo(PFMuonAlgo* algo) {pfmu_ =algo;}
void setMuonHandle(const edm::Handle<reco::MuonCollection>&);
void setDebug( bool debug ) {debug_ = debug; connector_.setDebug(debug_); }

void setParameters(double nSigmaECAL,
double nSigmaHCAL,
Expand Down Expand Up @@ -207,9 +204,9 @@ class PFAlgo {
return std::move(pfCleanedCandidates_);
}

/// \return unique_ptr to the collection of candidates (transfers ownership)
std::unique_ptr< reco::PFCandidateCollection> transferCandidates() {
return connector_.connect(pfCandidates_);
/// \return the collection of candidates
reco::PFCandidateCollection transferCandidates() {
return connector_.connect(*pfCandidates_);
}

/// return the pointer to the calibration function
Expand Down Expand Up @@ -312,7 +309,7 @@ class PFAlgo {

bool useHO_;
int algo_;
bool debug_;
const bool debug_;

/// Variables for PFElectrons
std::string mvaWeightFileEleID_;
Expand All @@ -331,8 +328,8 @@ class PFAlgo {
double sumPtTrackIsoForEgammaSC_endcap_;
double coneTrackIsoForEgammaSC_;
unsigned int nTrackIsoForEgammaSC_;
PFElectronAlgo *pfele_;
PFPhotonAlgo *pfpho_;
std::unique_ptr<PFElectronAlgo> pfele_;
std::unique_ptr<PFPhotonAlgo> pfpho_;
PFMuonAlgo *pfmu_;


Expand Down
79 changes: 11 additions & 68 deletions RecoParticleFlow/PFProducer/interface/PFBlockAlgo.h
@@ -1,68 +1,20 @@
#ifndef RecoParticleFlow_PFProducer_PFBlockAlgo_h
#define RecoParticleFlow_PFProducer_PFBlockAlgo_h

#include <set>
#include <vector>
#include <iostream>

// #include "FWCore/Framework/interface/Handle.h"
#include "DataFormats/Common/interface/Handle.h"
// #include "FWCore/Framework/interface/OrphanHandle.h"
#include "DataFormats/Common/interface/OrphanHandle.h"


#include "DataFormats/ParticleFlowReco/interface/PFClusterFwd.h"
#include "DataFormats/ParticleFlowReco/interface/PFRecTrackFwd.h"
#include "DataFormats/ParticleFlowReco/interface/PFCluster.h"
#include "DataFormats/ParticleFlowReco/interface/PFRecTrack.h"
#include "DataFormats/ParticleFlowReco/interface/PFDisplacedTrackerVertex.h" // gouzevitch
#include "DataFormats/ParticleFlowReco/interface/PFConversionFwd.h"
#include "DataFormats/ParticleFlowReco/interface/PFConversion.h"
#include "DataFormats/ParticleFlowReco/interface/PFV0Fwd.h"
#include "DataFormats/ParticleFlowReco/interface/PFV0.h"
#include "DataFormats/ParticleFlowReco/interface/GsfPFRecTrack.h"
#include "DataFormats/ParticleFlowReco/interface/GsfPFRecTrackFwd.h"
#include "DataFormats/ParticleFlowReco/interface/PFBrem.h"
#include "DataFormats/ParticleFlowReco/interface/PFTrajectoryPoint.h"

#include "DataFormats/ParticleFlowReco/interface/PFBlockElement.h"
#include "DataFormats/ParticleFlowReco/interface/PFBlock.h"
#include "DataFormats/ParticleFlowReco/interface/PFBlockElement.h"
#include "DataFormats/ParticleFlowReco/interface/PFBlockFwd.h"

// Glowinski & Gouzevitch
#include "DataFormats/ParticleFlowReco/interface/PFRecHit.h"
#include "RecoParticleFlow/PFProducer/interface/KDTreeLinkerBase.h"
// !Glowinski & Gouzevitch

// #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"

#include "RecoParticleFlow/PFProducer/interface/PFMuonAlgo.h"
#include "RecoParticleFlow/PFProducer/interface/PhotonSelectorAlgo.h"
#include "RecoParticleFlow/PFProducer/interface/PFBlockElementSCEqual.h"
#include "RecoParticleFlow/PFClusterTools/interface/PFResolutionMap.h"

#include "DataFormats/MuonReco/interface/MuonFwd.h"
#include "DataFormats/MuonReco/interface/Muon.h"
#include "DataFormats/EgammaReco/interface/SuperClusterFwd.h"
#include "DataFormats/EgammaReco/interface/SuperCluster.h"
#include "DataFormats/GsfTrackReco/interface/GsfTrackFwd.h"
#include "DataFormats/GsfTrackReco/interface/GsfTrack.h"
#include "DataFormats/EgammaReco/interface/ElectronSeedFwd.h"
#include "DataFormats/EgammaReco/interface/ElectronSeed.h"
#include "DataFormats/EgammaCandidates/interface/PhotonFwd.h"
#include "DataFormats/EgammaCandidates/interface/Photon.h"
#include "DataFormats/ParticleFlowReco/interface/PFBlockElementSuperCluster.h"

#include "RecoParticleFlow/PFClusterTools/interface/ClusterClusterMapping.h"

#include "RecoParticleFlow/PFProducer/interface/PFBlockLink.h"

#include "RecoParticleFlow/PFProducer/interface/BlockElementLinkerBase.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Framework/interface/ConsumesCollector.h"
#include "RecoParticleFlow/PFProducer/interface/BlockElementImporterBase.h"
#include "RecoParticleFlow/PFProducer/interface/BlockElementLinkerBase.h"
#include "RecoParticleFlow/PFProducer/interface/KDTreeLinkerBase.h"
#include "DataFormats/Common/interface/OwnVector.h"

#include <map>
#include <memory>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

namespace std {
template<>
Expand All @@ -73,13 +25,6 @@ namespace std {
return arg.first ^ (arg.second << 1);
}
};
template<>
struct equal_to<std::pair<unsigned int,unsigned int> > {
typedef std::pair<unsigned int,unsigned int> arg_type;
bool operator()(const arg_type& arg1, const arg_type& arg2) const {
return ( (arg1.first == arg2.first) & (arg1.second == arg2.second) );
}
};
}

/// \brief Particle Flow Algorithm
Expand Down Expand Up @@ -129,17 +74,15 @@ class PFBlockAlgo {
/// compute missing links in the blocks
/// (the recursive procedure does not build all links)
void packLinks(reco::PFBlock& block,
const std::unordered_map<std::pair<unsigned int,unsigned int>,PFBlockLink>& links) const;
const std::unordered_map<std::pair<unsigned int,unsigned int>,double>& links) const;

/// Avoid to check links when not useful
inline bool linkPrefilter(const reco::PFBlockElement* last,
const reco::PFBlockElement* next) const;

/// check whether 2 elements are linked. Returns distance and linktype
/// check whether 2 elements are linked. Returns distance
inline void link( const reco::PFBlockElement* el1,
const reco::PFBlockElement* el2,
PFBlockLink::Type& linktype,
reco::PFBlock::LinkTest& linktest,
double& dist) const;

// the test elements will be transferred to the blocks
Expand Down
4 changes: 0 additions & 4 deletions RecoParticleFlow/PFProducer/interface/PFBlockElementSCEqual.h
Expand Up @@ -3,12 +3,10 @@

#include "DataFormats/ParticleFlowReco/interface/PFBlockElementSuperCluster.h"
#include "DataFormats/ParticleFlowReco/interface/PFBlockElement.h"
//#include "DataFormats/EgammaReco/interface/SuperClusterFwd.h"

class PFBlockElementSCEqual {
public:
PFBlockElementSCEqual(reco::SuperClusterRef scRef):ref_(scRef) {;}
~PFBlockElementSCEqual(){;}
inline bool operator() (const std::unique_ptr<reco::PFBlockElement>& el) {
return (el->type()==reco::PFBlockElement::SC && (static_cast<const reco::PFBlockElementSuperCluster*>(el.get()))->superClusterRef()==ref_);
}
Expand All @@ -20,5 +18,3 @@ class PFBlockElementSCEqual {
};

#endif