51 isolator_(iConfig.exists(
"userIsolation") ? iConfig.getParameter<edm::
ParameterSet>(
"userIsolation") : edm::
ParameterSet(), consumesCollector(),
false) ,
52 useUserData_(iConfig.exists(
"userData"))
90 addResolutions_ = iConfig.getParameter<
bool>(
"addResolutions" );
91 if (addResolutions_) {
95 addElecID_ = iConfig.getParameter<
bool>(
"addElectronID" );
99 elecIDSrcs_.push_back(NameTag(
"", iConfig.getParameter<
edm::InputTag>(
"electronIDSource")));
104 if (!elecIDSrcs_.empty()){
105 throw cms::Exception(
"Configuration") <<
"PATElectronProducer: you can't specify both 'electronIDSource' and 'electronIDSources'\n";
110 for (std::vector<std::string>::const_iterator it = names.begin(), ed = names.end(); it != ed; ++it) {
115 if (elecIDSrcs_.empty()){
117 "PATElectronProducer: id addElectronID is true, you must specify either:\n" <<
118 "\tInputTag electronIDSource = <someTag>\n" <<
"or\n" <<
119 "\tPSet electronIDSources = { \n" <<
120 "\t\tInputTag <someName> = <someTag> // as many as you want \n " <<
124 elecIDTokens_ =
edm::vector_transform(elecIDSrcs_, [
this](NameTag
const &
tag){
return mayConsume<edm::ValueMap<float> >(tag.second);});
147 readIsolationLabels(iConfig,
"isoDeposits", isoDepositLabels_, isoDepositTokens_);
149 readIsolationLabels(iConfig,
"isolationValues", isolationValueLabels_, isolationValueTokens_);
151 readIsolationLabels(iConfig,
"isolationValuesNoPFId", isolationValueLabelsNoPFId_, isolationValueNoPFIdTokens_);
153 addEfficiencies_ = iConfig.getParameter<
bool>(
"addEfficiencies");
154 if (addEfficiencies_) {
158 if ( useUserData_ ) {
162 embedHighLevelSelection_ = iConfig.getParameter<
bool>(
"embedHighLevelSelection");
163 beamLineToken_ = consumes<reco::BeamSpot>(iConfig.getParameter<
edm::InputTag>(
"beamLineSrc"));
164 if ( embedHighLevelSelection_ ) {
165 usePV_ = iConfig.getParameter<
bool>(
"usePV");
166 pvToken_ = consumes<std::vector<reco::Vertex> >(iConfig.getParameter<
edm::InputTag>(
"pvSrc"));
169 produces<std::vector<Electron> >();
173 PATElectronProducer::~PATElectronProducer()
195 edm::InputTag reducedEBRecHitCollection(
string(
"reducedEcalRecHitsEB"));
196 edm::InputTag reducedEERecHitCollection(
string(
"reducedEcalRecHitsEE"));
237 std::vector<edm::Handle<edm::ValueMap<float> > > idhandles;
238 std::vector<pat::Electron::IdPair> ids;
254 bool beamSpotIsValid =
false;
255 bool primaryVertexIsValid =
false;
271 if ( beamSpotHandle.
isValid() ){
272 beamSpot = *beamSpotHandle;
273 beamSpotIsValid =
true;
276 <<
"No beam spot available from EventSetup, not adding high level selection \n";
279 double x0 = beamSpot.
x0();
280 double y0 = beamSpot.
y0();
281 double z0 = beamSpot.
z0();
285 if ( pvHandle.
isValid() && !pvHandle->empty() ) {
286 primaryVertex = pvHandle->at(0);
287 primaryVertexIsValid =
true;
290 <<
"No primary vertex available from EventSetup, not adding high level selection \n";
295 std::vector<Electron> *
patElectrons =
new std::vector<Electron>();
303 i != pfElectrons->end(); ++
i, ++
index) {
312 bool MatchedToAmbiguousGsfTrack=
false;
314 unsigned int idx = itElectron - electrons->begin();
315 if (Matched || MatchedToAmbiguousGsfTrack)
continue;
319 if (itElectron->gsfTrack()==
i->gsfTrackRef()){
324 it!=itElectron->ambiguousGsfTracksEnd(); it++ ){
325 MatchedToAmbiguousGsfTrack |= (bool)(
i->gsfTrackRef()==(*it));
329 if (Matched || MatchedToAmbiguousGsfTrack){
363 primaryVertexIsValid,
368 ip3d = ip3dpv.second.value();
371 double corr_d0 = track->dxy( beamPoint );
372 anElectron.
setDB( corr_d0, -1.0 );
375 double d0_corr = result.second.value();
376 double d0_err = result.second.error();
377 anElectron.
setDB( d0_corr, d0_err );
387 ids[
i].second = (*idhandles[
i])[elecsRef];
390 ids.push_back(std::make_pair(
"pf_evspi",pfRef->mva_e_pi()));
391 ids.push_back(std::make_pair(
"pf_evsmu",pfRef->mva_e_mu()));
396 std::vector<float> vCov = lazyTools.localCovariances(*( itElectron->superCluster()->seed()));
399 std::vector<DetId> selectedCells;
400 bool barrel = itElectron->isEB();
403 for (
reco::CaloCluster_iterator clusIt = itElectron->superCluster()->clustersBegin(); clusIt!=itElectron->superCluster()->clustersEnd(); ++clusIt) {
405 DetId seed = lazyTools.getMaximum(**clusIt).first;
409 selectedCells.insert(selectedCells.end(), dets5x5.begin(), dets5x5.end());
412 for (
const std::pair<DetId, float> &
hit : (*clusIt)->hitsAndFractions()) {
413 selectedCells.push_back(
hit.first);
419 for (
reco::CaloCluster_iterator clusIt = itElectron->parentSuperCluster()->clustersBegin(); clusIt!=itElectron->parentSuperCluster()->clustersEnd(); ++clusIt) {
421 DetId seed = lazyTools.getMaximum(**clusIt).first;
425 selectedCells.insert(selectedCells.end(), dets5x5.begin(), dets5x5.end());
428 for (
const std::pair<DetId, float> &
hit : (*clusIt)->hitsAndFractions()) {
429 selectedCells.push_back(
hit.first);
435 std::sort(selectedCells.begin(),selectedCells.end());
436 std::unique(selectedCells.begin(),selectedCells.end());
450 unsigned nSelectedCells = selectedCells.
size();
451 for (
unsigned icell = 0 ; icell < nSelectedCells ; ++icell) {
453 if ( it != recHits->
end() ) {
457 selectedRecHits.
sort();
461 bool passconversionveto =
false;
488 genMatches, deposits, isolationValues );
492 patElectrons->push_back(anElectron);
510 unsigned int idx = itElectron - electrons->begin();
518 if ( pfCandsPresent ) {
523 ie != pfElectrons->end(); ++ie, ++
index) {
526 if( trkRef == pfTrkRef ) {
534 else if( valMapPresent ) {
556 for (
size_t j = 0, nd = deposits.size();
j < nd; ++
j) {
563 ids[
i].second = (*idhandles[
i])[elecsRef];
589 primaryVertexIsValid,
594 ip3d = ip3dpv.second.value();
597 double corr_d0 = track->dxy( beamPoint );
598 anElectron.
setDB( corr_d0, -1.0 );
601 double d0_corr = result.second.value();
602 double d0_err = result.second.error();
603 anElectron.
setDB( d0_corr, d0_err );
609 std::vector<float> vCov = lazyTools.localCovariances(*( itElectron->superCluster()->seed()));
612 std::vector<DetId> selectedCells;
613 bool barrel = itElectron->isEB();
616 for (
reco::CaloCluster_iterator clusIt = itElectron->superCluster()->clustersBegin(); clusIt!=itElectron->superCluster()->clustersEnd(); ++clusIt) {
618 DetId seed = lazyTools.getMaximum(**clusIt).first;
622 selectedCells.insert(selectedCells.end(), dets5x5.begin(), dets5x5.end());
625 for (
const std::pair<DetId, float> &
hit : (*clusIt)->hitsAndFractions()) {
626 selectedCells.push_back(
hit.first);
632 for (
reco::CaloCluster_iterator clusIt = itElectron->parentSuperCluster()->clustersBegin(); clusIt!=itElectron->parentSuperCluster()->clustersEnd(); ++clusIt) {
634 DetId seed = lazyTools.getMaximum(**clusIt).first;
638 selectedCells.insert(selectedCells.end(), dets5x5.begin(), dets5x5.end());
641 for (
const std::pair<DetId, float> &
hit : (*clusIt)->hitsAndFractions()) {
642 selectedCells.push_back(
hit.first);
648 std::sort(selectedCells.begin(),selectedCells.end());
649 std::unique(selectedCells.begin(),selectedCells.end());
662 unsigned nSelectedCells = selectedCells.
size();
663 for (
unsigned icell = 0 ; icell < nSelectedCells ; ++icell) {
665 if ( it != recHits->
end() ) {
669 selectedRecHits.
sort();
673 bool passconversionveto =
false;
685 genMatches, deposits, pfId, isolationValues, isolationValuesNoPFId);
686 patElectrons->push_back(anElectron);
694 std::auto_ptr<std::vector<Electron> > ptr(patElectrons);
742 for(
size_t i = 0,
n = genMatches.size();
i <
n; ++
i) {
763 for (
size_t j = 0, nd = deposits.size();
j < nd; ++
j) {
767 assert(!pfcandref.
isNull());
770 (*deposits[
j])[source]);
774 (*deposits[
j])[elecRef]);
777 for (
size_t j = 0;
j<isolationValues.size(); ++
j) {
781 (*isolationValues[
j])[source]);
790 for (
size_t j = 0;
j<isolationValuesNoPFId.size(); ++
j) {
828 for(
size_t i = 0,
n = genMatches.size();
i <
n; ++
i) {
844 for (
size_t j = 0, nd = deposits.size();
j < nd; ++
j) {
850 (*deposits[
j])[candPtrForGenMatch]);
852 else if (deposits[
j]->
contains(candPtrForIsolation.
id())) {
854 (*deposits[
j])[candPtrForIsolation]);
858 (*deposits[
j])[candPtrForIsolation->sourceCandidatePtr(0)]);
862 for (
size_t j = 0;
j<isolationValues.size(); ++
j) {
866 isolationValues[
j]->
contains(candPtrForGenMatch.
id())) {
868 (*isolationValues[
j])[candPtrForGenMatch]);
870 else if (isolationValues[
j]->
contains(candPtrForIsolation.
id())) {
872 (*isolationValues[
j])[candPtrForIsolation]);
876 (*isolationValues[
j])[candPtrForIsolation->sourceCandidatePtr(0)]);
886 iDesc.
setComment(
"PAT electron producer module");
893 iDesc.
add<
bool>(
"embedGsfElectronCore",
true)->setComment(
"embed external gsf electron core");
894 iDesc.
add<
bool>(
"embedGsfTrack",
true)->setComment(
"embed external gsf track");
895 iDesc.
add<
bool>(
"embedSuperCluster",
true)->setComment(
"embed external super cluster");
896 iDesc.
add<
bool>(
"embedPflowSuperCluster",
true)->setComment(
"embed external super cluster");
897 iDesc.
add<
bool>(
"embedSeedCluster",
true)->setComment(
"embed external seed cluster");
898 iDesc.
add<
bool>(
"embedBasicClusters",
true)->setComment(
"embed external basic clusters");
899 iDesc.
add<
bool>(
"embedPreshowerClusters",
true)->setComment(
"embed external preshower clusters");
900 iDesc.
add<
bool>(
"embedPflowBasicClusters",
true)->setComment(
"embed external pflow basic clusters");
901 iDesc.
add<
bool>(
"embedPflowPreshowerClusters",
true)->setComment(
"embed external pflow preshower clusters");
902 iDesc.
add<
bool>(
"embedTrack",
false)->setComment(
"embed external track");
903 iDesc.
add<
bool>(
"embedRecHits",
true)->setComment(
"embed external RecHits");
907 iDesc.
add<
bool>(
"useParticleFlow",
false)->setComment(
"whether to use particle flow or not");
908 iDesc.
add<
bool>(
"embedPFCandidate",
false)->setComment(
"embed external particle flow object");
911 iDesc.
add<
bool>(
"addGenMatch",
true)->setComment(
"add MC matching");
912 iDesc.
add<
bool>(
"embedGenMatch",
false)->setComment(
"embed MC matched MC information");
913 std::vector<edm::InputTag> emptySourceVector;
916 )->
setComment(
"input with MC match information");
919 iDesc.
add<
bool>(
"addElectronID",
true)->setComment(
"add electron ID variables");
924 )->
setComment(
"input with electron ID variables");
938 isoDepositsPSet.
addOptional<std::vector<edm::InputTag> >(
"user");
952 isolationValuesPSet.
addOptional<std::vector<edm::InputTag> >(
"user");
953 iDesc.
addOptional(
"isolationValues", isolationValuesPSet);
966 isolationValuesNoPFIdPSet.
addOptional<std::vector<edm::InputTag> >(
"user");
967 iDesc.
addOptional(
"isolationValuesNoPFId", isolationValuesNoPFIdPSet);
972 iDesc.
add(
"efficiencies", efficienciesPSet);
973 iDesc.
add<
bool>(
"addEfficiencies",
false);
981 iDesc.
add<
bool>(
"addElectronShapes",
true);
987 iDesc.
add(
"userIsolation", isolationPSet);
992 iDesc.
add<
bool>(
"embedHighLevelSelection",
true)->setComment(
"embed high level selection");
996 )->
setComment(
"input with high level selection");
998 )->
setComment(
"input with high level selection");
1000 )->
setComment(
"input with high level selection, use primary vertex (true) or beam line (false)");
1002 descriptions.
add(
"PATElectronProducer", iDesc);
1013 bool primaryVertexIsValid,
1015 bool beamspotIsValid
1021 std::pair<bool,Measurement1D>
result =
1027 double d0_corr = result.second.value();
1028 double d0_err = primaryVertexIsValid ? result.second.error() : -1.0;
1039 d0_corr = result.second.value();
1040 d0_err = primaryVertexIsValid ? result.second.error() : -1.0;
1055 d0_corr = result.second.value();
1056 d0_err = beamspotIsValid ? result.second.error() : -1.0;
1066 d0_corr = result.second.value();
1067 d0_err = beamspotIsValid ? result.second.error() : -1.0;
bool enabled() const
'true' if this there is at least one efficiency configured
T getParameter(std::string const &) const
bool embedGsfElectronCore_
void setComment(std::string const &value)
double z0() const
z coordinate
Assists in assimilating all pat::UserData into pat objects.
void setP4(P4Kind kind, const LorentzVector &p4, float p4Error, bool setCandidate)
void embedTrack()
method to store the electron's Track internally
void embedSeedCluster()
method to store the electron's seedcluster internally
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
bool isNonnull() const
Checks for non-null.
void setIsolation(IsolationKeys key, float value)
bool existsAs(std::string const ¶meterName, bool trackiness=true) const
checks if a parameter exists as a given type
void embedGsfElectronCore()
method to store the electron's core internally
bool contains(EventRange const &lh, EventID const &rh)
void setElectronIDs(const std::vector< IdPair > &ids)
Store multiple electron ID values, discarding existing ones. The first one in the list becomes the 'd...
void embedPflowBasicClusters()
method to store the electron's pflow basic clusters
static const HistoName names[]
Covariance3DMatrix covariance3D() const
return only 3D position covariance matrix
const LorentzVector & p4(P4Kind kind) const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
void embedSuperCluster()
method to store the electron's SuperCluster internally
void setAllowAnything()
allow any parameter label/value pairs
void embedPFCandidate()
embed the PFCandidate pointed to by pfCandidateRef_
#define DEFINE_FWK_MODULE(type)
void setDB(double dB, double edB, IpType type=None)
Set impact parameter of a certain type and its uncertainty.
IsolationLabels isoDepositLabels_
edm::EDGetTokenT< edm::View< reco::GsfElectron > > electronToken_
void embedHighLevel(pat::Electron &anElectron, reco::GsfTrackRef track, reco::TransientTrack &tt, reco::Vertex &primaryVertex, bool primaryVertexIsValid, reco::BeamSpot &beamspot, bool beamspotIsValid)
std::vector< EcalRecHit >::const_iterator const_iterator
void setPFCandidateRef(const reco::PFCandidateRef &ref)
add a reference to the source IsolatedPFCandidate
void fillElectron(Electron &aElectron, const ElectronBaseRef &electronRef, const reco::CandidateBaseRef &baseRef, const GenAssociations &genMatches, const IsoDepositMaps &deposits, const bool pfId, const IsolationValueMaps &isolationValues, const IsolationValueMaps &isolationValuesNoPFId) const
common electron filling, for both the standard and PF2PAT case
void push_back(T const &t)
ParameterDescriptionNode * addNode(ParameterDescriptionNode const &node)
void setPassConversionVeto(bool flag)
auto vector_transform(std::vector< InputType > const &input, Function predicate) -> std::vector< typename std::remove_cv< typename std::remove_reference< decltype(predicate(input.front()))>::type >::type >
PFCandidateCollection::const_iterator PFCandidateConstIterator
iterator
void setEcalDrivenMomentum(const Candidate::LorentzVector &mom)
void setResolutions(pat::PATObject< T > &obj) const
Sets the efficiencies for this object, using the reference to the original objects.
std::vector< edm::EDGetTokenT< edm::ValueMap< float > > > elecIDTokens_
void embedPreshowerClusters()
method to store the electron's preshower clusters
bool enabled() const
'true' if this there is at least one efficiency configured
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
void setIsoDeposit(IsolationKeys key, const IsoDeposit &dep)
Sets the IsoDeposit associated with some key; if it is already existent, it is overwritten.
static void fillDescription(edm::ParameterSetDescription &iDesc)
std::vector< std::string > getParameterNamesForType(bool trackiness=true) const
void embedBasicClusters()
method to store the electron's basic clusters
bool enabled() const
True if it has a non null configuration.
void setComment(std::string const &value)
GreaterByPt< Electron > pTComparator_
pat::helper::MultiIsolator isolator_
std::vector< edm::Handle< edm::Association< reco::GenParticleCollection > > > GenAssociations
void beginEvent(const edm::Event &event, const edm::EventSetup &eventSetup)
Produces pat::Electron's.
PATElectronProducer(const edm::ParameterSet &iConfig)
edm::EDGetTokenT< EcalRecHitCollection > reducedEndcapRecHitCollectionToken_
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
void embedRecHits(const EcalRecHitCollection *rechits)
method to store the RecHits internally - can be called from the PATElectronProducer ...
std::vector< edm::EDGetTokenT< edm::Association< reco::GenParticleCollection > > > genMatchTokens_
edm::InputTag reducedEndcapRecHitCollection_
std::vector< edm::EDGetTokenT< edm::ValueMap< IsoDeposit > > > isoDepositTokens_
edm::InputTag reducedBarrelRecHitCollection_
mva input variables
edm::EDGetTokenT< reco::ConversionCollection > hConversionsToken_
reco::PFCandidateRef pfCandidateRef() const
reference to the source PFCandidates; null if this has been built from a standard electron ...
math::XYZPoint Point
point in the space
std::vector< edm::Handle< edm::ValueMap< double > > > IsolationValueMaps
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool embedHighLevelSelection_
embed high level selection variables?
bool isNull() const
Checks for null.
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
virtual void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
void embedGsfTrack()
method to store the electron's GsfTrack internally
bool isNonnull() const
Checks for non-null.
const_iterator end() const
edm::EDGetTokenT< EcalRecHitCollection > reducedBarrelRecHitCollectionToken_
void fillElectron2(Electron &anElectron, const reco::CandidatePtr &candPtrForIsolation, const reco::CandidatePtr &candPtrForGenMatch, const reco::CandidatePtr &candPtrForLoader, const GenAssociations &genMatches, const IsoDepositMaps &deposits, const IsolationValueMaps &isolationValues) const
void addGenParticleRef(const reco::GenParticleRef &ref)
std::vector< edm::EDGetTokenT< edm::ValueMap< double > > > isolationValueNoPFIdTokens_
virtual std::vector< DetId > getWindow(const DetId &id, const int &northSouthSize, const int &eastWestSize) const
static void fillDescription(edm::ParameterSetDescription &iDesc)
Method for documentation and validation of PSet.
bool embedPflowSuperCluster_
pat::helper::EfficiencyLoader efficiencyLoader_
void setIsPF(bool hasPFCandidate)
bool embedPreshowerClusters_
tuple idx
DEBUGGING if hasattr(process,"trackMonIterativeTracking2012"): print "trackMonIterativeTracking2012 D...
pat::PATUserDataHelper< pat::Electron > userDataHelper_
void embedPflowSuperCluster()
method to store the electron's PflowSuperCluster internally
void setEfficiencies(pat::PATObject< T > &obj, const R &originalRef) const
Sets the efficiencies for this object, using the reference to the original objects.
bool useParticleFlow_
pflow specific
Analysis-level electron class.
const CaloTopology * ecalTopology_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
const CaloSubdetectorTopology * getSubdetectorTopology(const DetId &id) const
access the subdetector Topology for the given subdetector directly
ProductID id() const
Accessor for product ID.
IsolationLabels isolationValueLabelsNoPFId_
edm::EDGetTokenT< edm::ValueMap< reco::PFCandidatePtr > > pfCandidateMapToken_
std::vector< std::pair< pat::IsolationKeys, float > > IsolationValuePairs
iterator find(key_type k)
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
IsolationLabels isolationValueLabels_
double y0() const
y coordinate
pat::helper::KinResolutionsLoader resolutionLoader_
const Point & position() const
position
volatile std::atomic< bool > shutdown_flag false
bool embedPflowBasicClusters_
std::vector< edm::EDGetTokenT< edm::ValueMap< double > > > isolationValueTokens_
edm::EDGetTokenT< reco::BeamSpot > beamLineToken_
pat::helper::MultiIsolator::IsolationValuePairs isolatorTmpStorage_
void newEvent(const edm::Event &event, const edm::EventSetup &setup) const
To be called for each new event, reads in the EventSetup object.
edm::EDGetTokenT< reco::PFCandidateCollection > pfElecToken_
void setMvaVariables(double sigmaIetaIphi, double ip3d)
set missing mva input variables
static std::string const source
bool embedPflowPreshowerClusters_
void embedPflowPreshowerClusters()
method to store the electron's pflow preshower clusters
void newEvent(const edm::Event &event) const
To be called for each new event, reads in the ValueMaps for efficiencies.
edm::EDGetTokenT< std::vector< reco::Vertex > > pvToken_
Global3DVector GlobalVector
std::vector< NameTag > elecIDSrcs_
void fill(const edm::View< T > &coll, int idx, IsolationValuePairs &isolations) const
double x0() const
x coordinate
std::vector< edm::Handle< edm::ValueMap< IsoDeposit > > > IsoDepositMaps