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 double r9 = lazyTools.
e3x3( *( itElectron->superCluster()->seed())) / itElectron->superCluster()->rawEnergy() ;
397 double sigmaIphiIphi;
398 double sigmaIetaIphi;
399 std::vector<float> vCov = lazyTools.
localCovariances(*( itElectron->superCluster()->seed()));
401 else sigmaIphiIphi = 0;
402 sigmaIetaIphi = vCov[1];
406 bool barrel = itElectron->isEB();
407 DetId seed = lazyTools.
getMaximum(*(itElectron->superCluster()->seed())).first;
414 std::vector<DetId> cellsIn5x5;
415 for ( ; itscl!= itsclE ; ++ itscl) {
420 cellsIn5x5.insert(cellsIn5x5.end(),cellsToAdd.begin(), cellsToAdd.end());
425 unsigned nCellsIn5x5 = cellsIn5x5.size() ;
427 for(
unsigned i=0;
i< nCellsIn5x5 ; ++
i ) {
428 std::vector<DetId>::const_iterator itcheck =
find(selectedCells.begin(), selectedCells.end(),cellsIn5x5[
i]);
429 if (itcheck == selectedCells.end())
430 selectedCells.push_back(cellsIn5x5[
i]);
435 std::vector< std::pair<DetId, float> >::const_iterator it=itElectron->superCluster()->hitsAndFractions().begin();
436 std::vector< std::pair<DetId, float> >::const_iterator itend=itElectron->superCluster()->hitsAndFractions().end();
437 for( ; it!=itend ; ++it) {
440 std::vector<DetId>::const_iterator itcheck =
find(selectedCells.begin(),selectedCells.end(),id);
441 if ( itcheck == selectedCells.end()) {
442 selectedCells.push_back(
id);
456 unsigned nSelectedCells = selectedCells.size();
457 for (
unsigned icell = 0 ; icell < nSelectedCells ; ++icell) {
459 if ( it != recHits->
end() ) {
463 selectedRecHits.
sort();
467 bool passconversionveto =
false;
473 passconversionveto = itElectron->gsfTrack()->trackerExpectedHitsInner().numberOfLostHits() < 1;
494 genMatches, deposits, isolationValues );
498 patElectrons->push_back(anElectron);
516 unsigned int idx = itElectron - electrons->begin();
524 if ( pfCandsPresent ) {
529 ie != pfElectrons->end(); ++ie, ++
index) {
532 if( trkRef == pfTrkRef ) {
540 else if( valMapPresent ) {
562 for (
size_t j = 0, nd = deposits.size();
j < nd; ++
j) {
569 ids[
i].second = (*idhandles[
i])[elecsRef];
595 primaryVertexIsValid,
600 ip3d = ip3dpv.second.value();
603 double corr_d0 = track->dxy( beamPoint );
604 anElectron.
setDB( corr_d0, -1.0 );
607 double d0_corr = result.second.value();
608 double d0_err = result.second.error();
609 anElectron.
setDB( d0_corr, d0_err );
615 double r9 = lazyTools.
e3x3( *( itElectron->superCluster()->seed())) / itElectron->superCluster()->rawEnergy() ;
616 double sigmaIphiIphi;
617 double sigmaIetaIphi;
618 std::vector<float> vCov = lazyTools.
localCovariances(*( itElectron->superCluster()->seed()));
620 else sigmaIphiIphi = 0;
621 sigmaIetaIphi = vCov[1];
625 bool barrel= itElectron->isEB();
627 DetId seed=lazyTools.
getMaximum(*(itElectron->superCluster()->seed())).first;
635 std::vector<DetId> cellsIn5x5;
636 for ( ; itscl!= itsclE ; ++ itscl) {
641 cellsIn5x5.insert(cellsIn5x5.end(),cellsToAdd.begin(), cellsToAdd.end());
645 unsigned nCellsIn5x5 = cellsIn5x5.size() ;
647 for(
unsigned i=0;
i< nCellsIn5x5 ; ++
i ) {
648 std::vector<DetId>::const_iterator itcheck =
find(selectedCells.begin(), selectedCells.end(),cellsIn5x5[
i]);
649 if (itcheck == selectedCells.end())
650 selectedCells.push_back(cellsIn5x5[
i]);
654 std::vector< std::pair<DetId, float> >::const_iterator it=itElectron->superCluster()->hitsAndFractions().begin();
655 std::vector< std::pair<DetId, float> >::const_iterator itend=itElectron->superCluster()->hitsAndFractions().end();
656 for( ; it!=itend ; ++it) {
659 std::vector<DetId>::const_iterator itcheck =
find(selectedCells.begin(),selectedCells.end(),id);
660 if ( itcheck == selectedCells.end()) {
661 selectedCells.push_back(
id);
675 unsigned nSelectedCells = selectedCells.size();
676 for (
unsigned icell = 0 ; icell < nSelectedCells ; ++icell) {
678 if ( it != recHits->
end() ) {
682 selectedRecHits.
sort();
686 bool passconversionveto =
false;
692 passconversionveto = itElectron->gsfTrack()->trackerExpectedHitsInner().numberOfLostHits() < 1;
698 genMatches, deposits, pfId, isolationValues, isolationValuesNoPFId);
699 patElectrons->push_back(anElectron);
707 std::auto_ptr<std::vector<Electron> > ptr(patElectrons);
755 for(
size_t i = 0,
n = genMatches.size();
i <
n; ++
i) {
776 for (
size_t j = 0, nd = deposits.size();
j < nd; ++
j) {
780 assert(!pfcandref.
isNull());
783 (*deposits[
j])[source]);
787 (*deposits[
j])[elecRef]);
790 for (
size_t j = 0;
j<isolationValues.size(); ++
j) {
794 (*isolationValues[
j])[source]);
803 for (
size_t j = 0;
j<isolationValuesNoPFId.size(); ++
j) {
841 for(
size_t i = 0,
n = genMatches.size();
i <
n; ++
i) {
857 for (
size_t j = 0, nd = deposits.size();
j < nd; ++
j) {
863 (*deposits[
j])[candPtrForGenMatch]);
865 else if (deposits[
j]->
contains(candPtrForIsolation.
id())) {
867 (*deposits[
j])[candPtrForIsolation]);
871 (*deposits[
j])[candPtrForIsolation->sourceCandidatePtr(0)]);
875 for (
size_t j = 0;
j<isolationValues.size(); ++
j) {
879 isolationValues[
j]->
contains(candPtrForGenMatch.
id())) {
881 (*isolationValues[
j])[candPtrForGenMatch]);
883 else if (isolationValues[
j]->
contains(candPtrForIsolation.
id())) {
885 (*isolationValues[
j])[candPtrForIsolation]);
889 (*isolationValues[
j])[candPtrForIsolation->sourceCandidatePtr(0)]);
899 iDesc.
setComment(
"PAT electron producer module");
906 iDesc.
add<
bool>(
"embedGsfElectronCore",
true)->setComment(
"embed external gsf electron core");
907 iDesc.
add<
bool>(
"embedGsfTrack",
true)->setComment(
"embed external gsf track");
908 iDesc.
add<
bool>(
"embedSuperCluster",
true)->setComment(
"embed external super cluster");
909 iDesc.
add<
bool>(
"embedPflowSuperCluster",
true)->setComment(
"embed external super cluster");
910 iDesc.
add<
bool>(
"embedSeedCluster",
true)->setComment(
"embed external seed cluster");
911 iDesc.
add<
bool>(
"embedBasicClusters",
true)->setComment(
"embed external basic clusters");
912 iDesc.
add<
bool>(
"embedPreshowerClusters",
true)->setComment(
"embed external preshower clusters");
913 iDesc.
add<
bool>(
"embedPflowBasicClusters",
true)->setComment(
"embed external pflow basic clusters");
914 iDesc.
add<
bool>(
"embedPflowPreshowerClusters",
true)->setComment(
"embed external pflow preshower clusters");
915 iDesc.
add<
bool>(
"embedTrack",
false)->setComment(
"embed external track");
916 iDesc.
add<
bool>(
"embedRecHits",
true)->setComment(
"embed external RecHits");
920 iDesc.
add<
bool>(
"useParticleFlow",
false)->setComment(
"whether to use particle flow or not");
921 iDesc.
add<
bool>(
"embedPFCandidate",
false)->setComment(
"embed external particle flow object");
924 iDesc.
add<
bool>(
"addGenMatch",
true)->setComment(
"add MC matching");
925 iDesc.
add<
bool>(
"embedGenMatch",
false)->setComment(
"embed MC matched MC information");
926 std::vector<edm::InputTag> emptySourceVector;
929 )->
setComment(
"input with MC match information");
932 iDesc.
add<
bool>(
"addElectronID",
true)->setComment(
"add electron ID variables");
937 )->
setComment(
"input with electron ID variables");
951 isoDepositsPSet.
addOptional<std::vector<edm::InputTag> >(
"user");
965 isolationValuesPSet.
addOptional<std::vector<edm::InputTag> >(
"user");
966 iDesc.
addOptional(
"isolationValues", isolationValuesPSet);
979 isolationValuesNoPFIdPSet.
addOptional<std::vector<edm::InputTag> >(
"user");
980 iDesc.
addOptional(
"isolationValuesNoPFId", isolationValuesNoPFIdPSet);
985 iDesc.
add(
"efficiencies", efficienciesPSet);
986 iDesc.
add<
bool>(
"addEfficiencies",
false);
994 iDesc.
add<
bool>(
"addElectronShapes",
true);
1000 iDesc.
add(
"userIsolation", isolationPSet);
1005 iDesc.
add<
bool>(
"embedHighLevelSelection",
true)->setComment(
"embed high level selection");
1009 )->
setComment(
"input with high level selection");
1011 )->
setComment(
"input with high level selection");
1013 )->
setComment(
"input with high level selection, use primary vertex (true) or beam line (false)");
1015 descriptions.
add(
"PATElectronProducer", iDesc);
1026 bool primaryVertexIsValid,
1028 bool beamspotIsValid
1034 std::pair<bool,Measurement1D>
result =
1040 double d0_corr = result.second.value();
1041 double d0_err = primaryVertexIsValid ? result.second.error() : -1.0;
1052 d0_corr = result.second.value();
1053 d0_err = primaryVertexIsValid ? result.second.error() : -1.0;
1068 d0_corr = result.second.value();
1069 d0_err = beamspotIsValid ? result.second.error() : -1.0;
1079 d0_corr = result.second.value();
1080 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.
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
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)
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 find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
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 setMvaVariables(double r9, double sigmaIphiIphi, double sigmaIetaIphi, double ip3d)
set missing mva input variables
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.
bool isNonnull() const
Checks for non-null.
void setComment(std::string const &value)
GreaterByPt< Electron > pTComparator_
pat::helper::MultiIsolator isolator_
std::vector< edm::Handle< edm::Association< reco::GenParticleCollection > > > GenAssociations
bool isNonnull() const
Checks for non-null.
void beginEvent(const edm::Event &event, const edm::EventSetup &eventSetup)
Produces pat::Electron's.
bool isNull() const
Checks for null.
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_
ProductID id() const
Accessor for product ID.
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?
int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
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
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
IsolationLabels isolationValueLabelsNoPFId_
T const * product() const
edm::EDGetTokenT< edm::ValueMap< reco::PFCandidatePtr > > pfCandidateMapToken_
std::vector< std::pair< pat::IsolationKeys, float > > IsolationValuePairs
iterator find(key_type k)
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_
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