Skip to content

Commit

Permalink
Merge pull request #27114 from cms-sw/code-format-analysis-reconstruc…
Browse files Browse the repository at this point in the history
…tion-4ecc02

Running code-format for analysis-reconstruction
  • Loading branch information
cmsbuild committed Jun 6, 2019
2 parents 0391fd1 + a7d7e58 commit 8255d66
Show file tree
Hide file tree
Showing 93 changed files with 3,472 additions and 3,622 deletions.
Expand Up @@ -22,41 +22,46 @@
namespace pf2pat {

struct ElectronIDPFCandidateSelectorDefinition : public PFCandidateSelectorDefinition {

ElectronIDPFCandidateSelectorDefinition ( const edm::ParameterSet & cfg, edm::ConsumesCollector && iC ) :
electronsToken_( iC.consumes<reco::GsfElectronCollection>( cfg.getParameter< edm::InputTag >( "recoGsfElectrons" ) ) ),
electronIdToken_( iC.consumes<edm::ValueMap<float> >( cfg.getParameter< edm::InputTag >( "electronIdMap" ) ) )
{
if (cfg.exists("bitsToCheck")) {
isBitMap_ = true;
mask_ = 0;
if (cfg.existsAs<std::vector<std::string> >("bitsToCheck")) {
std::vector<std::string> strbits = cfg.getParameter<std::vector<std::string> >("bitsToCheck");
for (std::vector<std::string>::const_iterator istrbit = strbits.begin(), estrbit = strbits.end();
istrbit != estrbit; ++istrbit) {
if (*istrbit == "id" ) { mask_ |= 1; }
else if (*istrbit == "iso") { mask_ |= 2; }
else if (*istrbit == "conv") { mask_ |= 4; }
else if (*istrbit == "ip") { mask_ |= 8; }
else throw cms::Exception("Configuration") << "ElectronIDPFCandidateSelector: " <<
"bitsToCheck allowed string values are only id(0), iso(1), conv(2), ip(3).\n" <<
"Otherwise, use uint32_t bitmask).\n";
}
} else if (cfg.existsAs<uint32_t>("bitsToCheck")) {
mask_ = cfg.getParameter<uint32_t>("bitsToCheck");
} else {
throw cms::Exception("Configuration") << "ElectronIDPFCandidateSelector: " <<
"bitsToCheck must be either a vector of strings, or a uint32 bitmask.\n";
}
ElectronIDPFCandidateSelectorDefinition(const edm::ParameterSet& cfg, edm::ConsumesCollector&& iC)
: electronsToken_(
iC.consumes<reco::GsfElectronCollection>(cfg.getParameter<edm::InputTag>("recoGsfElectrons"))),
electronIdToken_(iC.consumes<edm::ValueMap<float> >(cfg.getParameter<edm::InputTag>("electronIdMap"))) {
if (cfg.exists("bitsToCheck")) {
isBitMap_ = true;
mask_ = 0;
if (cfg.existsAs<std::vector<std::string> >("bitsToCheck")) {
std::vector<std::string> strbits = cfg.getParameter<std::vector<std::string> >("bitsToCheck");
for (std::vector<std::string>::const_iterator istrbit = strbits.begin(), estrbit = strbits.end();
istrbit != estrbit;
++istrbit) {
if (*istrbit == "id") {
mask_ |= 1;
} else if (*istrbit == "iso") {
mask_ |= 2;
} else if (*istrbit == "conv") {
mask_ |= 4;
} else if (*istrbit == "ip") {
mask_ |= 8;
} else
throw cms::Exception("Configuration")
<< "ElectronIDPFCandidateSelector: "
<< "bitsToCheck allowed string values are only id(0), iso(1), conv(2), ip(3).\n"
<< "Otherwise, use uint32_t bitmask).\n";
}
} else if (cfg.existsAs<uint32_t>("bitsToCheck")) {
mask_ = cfg.getParameter<uint32_t>("bitsToCheck");
} else {
isBitMap_ = false;
value_ = cfg.getParameter<double>("electronIdCut");
throw cms::Exception("Configuration")
<< "ElectronIDPFCandidateSelector: "
<< "bitsToCheck must be either a vector of strings, or a uint32 bitmask.\n";
}
} else {
isBitMap_ = false;
value_ = cfg.getParameter<double>("electronIdCut");
}
}

void select( const HandleToCollection & hc,
const edm::Event & e,
const edm::EventSetup& s) {
void select(const HandleToCollection& hc, const edm::Event& e, const edm::EventSetup& s) {
selected_.clear();

edm::Handle<reco::GsfElectronCollection> electrons;
Expand All @@ -65,56 +70,61 @@ namespace pf2pat {
edm::Handle<edm::ValueMap<float> > electronId;
e.getByToken(electronIdToken_, electronId);

unsigned key=0;
for( collection::const_iterator pfc = hc->begin();
pfc != hc->end(); ++pfc, ++key) {

unsigned key = 0;
for (collection::const_iterator pfc = hc->begin(); pfc != hc->end(); ++pfc, ++key) {
// Get GsfTrack for matching with reco::GsfElectron objects
reco::GsfTrackRef PfTk = pfc->gsfTrackRef();

// skip ones without GsfTrack: they won't be matched anyway
if (PfTk.isNull()) continue;
if (PfTk.isNull())
continue;

int match = -1;
// try first the non-ambiguous tracks
for (reco::GsfElectronCollection::const_iterator it = electrons->begin(), ed = electrons->end(); it != ed; ++it) {
if (it->gsfTrack() == PfTk) { match = it - electrons->begin(); break; }
for (reco::GsfElectronCollection::const_iterator it = electrons->begin(), ed = electrons->end(); it != ed;
++it) {
if (it->gsfTrack() == PfTk) {
match = it - electrons->begin();
break;
}
}
// then the ambiguous ones
if (match == -1) {
for (reco::GsfElectronCollection::const_iterator it = electrons->begin(), ed = electrons->end(); it != ed; ++it) {
if (std::count(it->ambiguousGsfTracksBegin(), it->ambiguousGsfTracksEnd(), PfTk) > 0) {
match = it - electrons->begin(); break;
}
for (reco::GsfElectronCollection::const_iterator it = electrons->begin(), ed = electrons->end(); it != ed;
++it) {
if (std::count(it->ambiguousGsfTracksBegin(), it->ambiguousGsfTracksEnd(), PfTk) > 0) {
match = it - electrons->begin();
break;
}
}
}
// if found, make a GsfElectronRef and read electron id
if (match != -1) {
reco::GsfElectronRef ref(electrons,match);
float eleId = (*electronId)[ref];
bool pass = false;
if (isBitMap_) {
uint32_t thisval = eleId;
pass = ((thisval & mask_) == mask_);
} else {
pass = (eleId > value_);
}
if (pass) {
selected_.push_back( reco::PFCandidate(*pfc) );
reco::PFCandidatePtr ptrToMother( hc, key );
selected_.back().setSourceCandidatePtr( ptrToMother );
}
reco::GsfElectronRef ref(electrons, match);
float eleId = (*electronId)[ref];
bool pass = false;
if (isBitMap_) {
uint32_t thisval = eleId;
pass = ((thisval & mask_) == mask_);
} else {
pass = (eleId > value_);
}
if (pass) {
selected_.push_back(reco::PFCandidate(*pfc));
reco::PFCandidatePtr ptrToMother(hc, key);
selected_.back().setSourceCandidatePtr(ptrToMother);
}
}
}
}

private:
edm::EDGetTokenT<reco::GsfElectronCollection> electronsToken_;
edm::EDGetTokenT<edm::ValueMap<float> > electronIdToken_;
bool isBitMap_;
uint32_t mask_;
double value_;
private:
edm::EDGetTokenT<reco::GsfElectronCollection> electronsToken_;
edm::EDGetTokenT<edm::ValueMap<float> > electronIdToken_;
bool isBitMap_;
uint32_t mask_;
double value_;
};
}
} // namespace pf2pat

#endif
31 changes: 13 additions & 18 deletions CommonTools/ParticleFlow/interface/EventHypothesis.h
@@ -1,42 +1,37 @@
#ifndef __CommonTools_ParticleFlow_interface_EventHypothesis__
#define __CommonTools_ParticleFlow_interface_EventHypothesis__


#include "FWCore/ParameterSet/interface/ParameterSet.h"

#include <map>
#include <string>


namespace pf2pat {

class EventHypothesis {

class EventHypothesis {
public:
/// the name of the parameter set is given to the event hypothesis
/// the parameter set must contain a vstring named "sequence"
/// and at least a parameter set named after each string in the
/// sequence.
EventHypothesis( const edm::ParameterSet& ps);

/// and at least a parameter set named after each string in the
/// sequence.
EventHypothesis(const edm::ParameterSet& ps);

private:
// need a base class for all algorithms/producers
typedef std::string Producer;
typedef std::map< std::string, Producer > Producers;
typedef std::vector< std::string > Sequence;
typedef std::map<std::string, Producer> Producers;
typedef std::vector<std::string> Sequence;

/// unique name
std::string name_;
std::string name_;

/// map of producers, indexed by producer name
Producers producers_;
Producers producers_;

/// sequence of producers
Sequence sequence_;

/// sequence of producers
Sequence sequence_;
};

}
} // namespace pf2pat

#endif
Expand Up @@ -20,31 +20,25 @@
namespace pf2pat {

struct GenericPFCandidateSelectorDefinition : public PFCandidateSelectorDefinition {
GenericPFCandidateSelectorDefinition(const edm::ParameterSet& cfg, edm::ConsumesCollector&& iC)
: selector_(cfg.getParameter<std::string>("cut")) {}

GenericPFCandidateSelectorDefinition ( const edm::ParameterSet & cfg, edm::ConsumesCollector && iC ) :
selector_( cfg.getParameter< std::string >( "cut" ) ) { }

void select( const HandleToCollection & hc,
const edm::Event & e,
const edm::EventSetup& s) {
void select(const HandleToCollection& hc, const edm::Event& e, const edm::EventSetup& s) {
selected_.clear();

unsigned key=0;
for( collection::const_iterator pfc = hc->begin();
pfc != hc->end(); ++pfc, ++key) {

if( selector_(*pfc) ) {
selected_.push_back( reco::PFCandidate(*pfc) );
reco::PFCandidatePtr ptrToMother( hc, key );
selected_.back().setSourceCandidatePtr( ptrToMother );

}
unsigned key = 0;
for (collection::const_iterator pfc = hc->begin(); pfc != hc->end(); ++pfc, ++key) {
if (selector_(*pfc)) {
selected_.push_back(reco::PFCandidate(*pfc));
reco::PFCandidatePtr ptrToMother(hc, key);
selected_.back().setSourceCandidatePtr(ptrToMother);
}
}
}

private:
private:
StringCutObjectSelector<reco::PFCandidate> selector_;
};
}
} // namespace pf2pat

#endif
31 changes: 12 additions & 19 deletions CommonTools/ParticleFlow/interface/GenericPFJetSelectorDefinition.h
@@ -1,7 +1,6 @@
#ifndef CommonTools_ParticleFlow_GenericPFJetSelectorDefinition
#define CommonTools_ParticleFlow_GenericPFJetSelectorDefinition


#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/ConsumesCollector.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
Expand All @@ -13,31 +12,25 @@
namespace pf2pat {

struct GenericPFJetSelectorDefinition : public PFJetSelectorDefinition {
GenericPFJetSelectorDefinition(const edm::ParameterSet& cfg, edm::ConsumesCollector&& iC)
: selector_(cfg.getParameter<std::string>("cut")) {}

GenericPFJetSelectorDefinition ( const edm::ParameterSet & cfg, edm::ConsumesCollector && iC ) :
selector_( cfg.getParameter< std::string >( "cut" ) ) { }

void select( const HandleToCollection & hc,
const edm::Event & e,
const edm::EventSetup& s) {
void select(const HandleToCollection& hc, const edm::Event& e, const edm::EventSetup& s) {
selected_.clear();

unsigned key=0;
for( collection::const_iterator pfc = hc->begin();
pfc != hc->end(); ++pfc, ++key) {

if( selector_(*pfc) ) {
selected_.push_back( reco::PFJet(*pfc) );
reco::CandidatePtr ptrToMother( hc, key );
selected_.back().setSourceCandidatePtr( ptrToMother );

}
unsigned key = 0;
for (collection::const_iterator pfc = hc->begin(); pfc != hc->end(); ++pfc, ++key) {
if (selector_(*pfc)) {
selected_.push_back(reco::PFJet(*pfc));
reco::CandidatePtr ptrToMother(hc, key);
selected_.back().setSourceCandidatePtr(ptrToMother);
}
}
}

private:
private:
StringCutObjectSelector<reco::PFJet> selector_;
};
}
} // namespace pf2pat

#endif

0 comments on commit 8255d66

Please sign in to comment.