CMS 3D CMS Logo

PATElectronSlimmer.cc
Go to the documentation of this file.
1 
8 
10 
23 
24 namespace pat {
25 
27  public:
28  explicit PATElectronSlimmer(const edm::ParameterSet & iConfig);
29  ~PATElectronSlimmer() override { }
30 
31  void produce(edm::Event & iEvent, const edm::EventSetup & iSetup) final;
33 
34  private:
36 
39 
43  const bool linkToPackedPF_;
46  const bool modifyElectron_;
47  std::unique_ptr<pat::ObjectModifier<pat::Electron> > electronModifier_;
48  };
49 
50 } // namespace
51 
53  src_(consumes<edm::View<pat::Electron> >(iConfig.getParameter<edm::InputTag>("src"))),
54  dropSuperClusters_(iConfig.getParameter<std::string>("dropSuperCluster")),
55  dropBasicClusters_(iConfig.getParameter<std::string>("dropBasicClusters")),
56  dropPFlowClusters_(iConfig.getParameter<std::string>("dropPFlowClusters")),
57  dropPreshowerClusters_(iConfig.getParameter<std::string>("dropPreshowerClusters")),
58  dropSeedCluster_(iConfig.getParameter<std::string>("dropSeedCluster")),
59  dropRecHits_(iConfig.getParameter<std::string>("dropRecHits")),
60  dropCorrections_(iConfig.getParameter<std::string>("dropCorrections")),
61  dropIsolations_(iConfig.getParameter<std::string>("dropIsolations")),
62  dropShapes_(iConfig.getParameter<std::string>("dropShapes")),
63  dropSaturation_(iConfig.getParameter<std::string>("dropSaturation")),
64  dropExtrapolations_(iConfig.getParameter<std::string>("dropExtrapolations")),
65  dropClassifications_(iConfig.getParameter<std::string>("dropClassifications")),
66  reco2pf_(mayConsume<edm::ValueMap<std::vector<reco::PFCandidateRef>>>(iConfig.getParameter<edm::InputTag>("recoToPFMap"))),
67  pf2pc_(mayConsume<edm::Association<pat::PackedCandidateCollection>>(iConfig.getParameter<edm::InputTag>("packedPFCandidates"))),
68  pc_(mayConsume<pat::PackedCandidateCollection>(iConfig.getParameter<edm::InputTag>("packedPFCandidates"))),
69  linkToPackedPF_(iConfig.getParameter<bool>("linkToPackedPFCandidates")),
70  saveNonZSClusterShapes_(iConfig.getParameter<std::string>("saveNonZSClusterShapes")),
71  reducedBarrelRecHitCollectionToken_(consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("reducedBarrelRecHitCollection"))),
72  reducedEndcapRecHitCollectionToken_(consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("reducedEndcapRecHitCollection"))),
73  modifyElectron_(iConfig.getParameter<bool>("modifyElectrons"))
74 {
75  if( modifyElectron_ ) {
76  const edm::ParameterSet& mod_config = iConfig.getParameter<edm::ParameterSet>("modifierConfig");
77  electronModifier_ = std::make_unique<pat::ObjectModifier<pat::Electron>>(mod_config, consumesCollector());
78  }
79 
80  mayConsume<EcalRecHitCollection>(edm::InputTag("reducedEcalRecHitsEB"));
81  mayConsume<EcalRecHitCollection>(edm::InputTag("reducedEcalRecHitsEE"));
82 
83  produces<std::vector<pat::Electron> >();
84 }
85 
86 void
88 }
89 
90 void
92  using namespace edm;
93  using namespace std;
94 
96  iEvent.getByToken(src_, src);
97 
101  if (linkToPackedPF_) {
102  iEvent.getByToken(reco2pf_, reco2pf);
103  iEvent.getByToken(pf2pc_, pf2pc);
104  iEvent.getByToken(pc_, pc);
105  }
107 
108  auto out = std::make_unique<std::vector<pat::Electron>>();
109  out->reserve(src->size());
110 
111  if( modifyElectron_ ) { electronModifier_->setEvent(iEvent); }
112  if( modifyElectron_ ) electronModifier_->setEventContent(iSetup);
113 
114  std::vector<unsigned int> keys;
115  for (View<pat::Electron>::const_iterator it = src->begin(), ed = src->end(); it != ed; ++it) {
116  out->push_back(*it);
117  pat::Electron & electron = out->back();
118 
119  if( modifyElectron_ ) { electronModifier_->modify(electron); }
120 
121  if (dropSuperClusters_(electron)) { electron.superCluster_.clear(); electron.embeddedSuperCluster_ = false; }
122  if (dropBasicClusters_(electron)) { electron.basicClusters_.clear(); }
123  if (dropSuperClusters_(electron) || dropPFlowClusters_(electron)) { electron.pflowSuperCluster_.clear(); electron.embeddedPflowSuperCluster_ = false; }
124  if (dropBasicClusters_(electron) || dropPFlowClusters_(electron)) { electron.pflowBasicClusters_.clear(); }
125  if (dropPreshowerClusters_(electron)) { electron.preshowerClusters_.clear(); }
126  if (dropPreshowerClusters_(electron) || dropPFlowClusters_(electron)) { electron.pflowPreshowerClusters_.clear(); }
127  if (dropSeedCluster_(electron)) { electron.seedCluster_.clear(); electron.embeddedSeedCluster_ = false; }
128  if (dropRecHits_(electron)) { electron.recHits_ = EcalRecHitCollection(); electron.embeddedRecHits_ = false; }
129  if (dropCorrections_(electron)) { electron.setCorrections(reco::GsfElectron::Corrections()); }
131  if (dropShapes_(electron)) { electron.setShowerShape(reco::GsfElectron::ShowerShape()); }
135  if (linkToPackedPF_) {
136  //std::cout << " PAT electron in " << src.id() << " comes from " << electron.refToOrig_.id() << ", " << electron.refToOrig_.key() << std::endl;
137  keys.clear();
138  for(auto const& pf: (*reco2pf)[electron.refToOrig_]) {
139  if( pf2pc->contains(pf.id()) ) {
140  keys.push_back( (*pf2pc)[pf].key());
141  }
142  }
144  keys.begin(), keys.end());
145  //std::cout << "Electron with pt " << electron.pt() << " associated to " << electron.associatedPackedFCandidateIndices_.size() << " PF Candidates\n";
146  //if there's just one PF Cand then it's me, otherwise I have no univoque parent so my ref will be null
147  if (keys.size() == 1) {
148  electron.refToOrig_ = electron.sourceCandidatePtr(0);
149  } else {
150  electron.refToOrig_ = reco::CandidatePtr(pc.id());
151  }
152  }
153  if (saveNonZSClusterShapes_(electron)) {
154  std::vector<float> vCov = lazyToolsNoZS.localCovariances(*( electron.superCluster()->seed()));
155  electron.full5x5_setSigmaIetaIphi(vCov[1]);
156  }
157  }
158 
159  iEvent.put(std::move(out));
160 }
161 
163 using namespace pat;
void setDr04Isolation(const IsolationVariables &dr04)
Definition: GsfElectron.h:577
T getParameter(std::string const &) const
const edm::EDGetTokenT< EcalRecHitCollection > reducedEndcapRecHitCollectionToken_
const StringCutObjectSelector< pat::Electron > dropRecHits_
const StringCutObjectSelector< pat::Electron > dropIsolations_
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
const edm::EDGetTokenT< edm::ValueMap< std::vector< reco::PFCandidateRef > > > reco2pf_
ProductID id() const
Definition: HandleBase.cc:15
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
const StringCutObjectSelector< pat::Electron > dropSuperClusters_
std::vector< pat::PackedCandidate > PackedCandidateCollection
void setSaturationInfo(const SaturationInfo &s)
Definition: GsfElectron.h:523
const StringCutObjectSelector< pat::Electron > dropCorrections_
void full5x5_setSigmaIetaIphi(float sigmaIetaIphi)
Definition: Electron.h:229
void setShowerShape(const ShowerShape &s)
Definition: GsfElectron.h:486
std::vector< reco::SuperCluster > superCluster_
Place to store electron&#39;s supercluster internally.
Definition: Electron.h:298
Slimmer of PAT Electrons.
reco::CandidatePtr sourceCandidatePtr(size_type i) const override
get the source candidate pointer with index i
const edm::EDGetTokenT< edm::Association< pat::PackedCandidateCollection > > pf2pc_
void setPfIsolationVariables(const PflowIsolationVariables &iso)
Definition: GsfElectron.h:696
void setDr03Isolation(const IsolationVariables &dr03)
Definition: GsfElectron.h:576
void beginLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &) final
std::vector< reco::CaloCluster > pflowBasicClusters_
Place to store electron&#39;s pflow basic clusters internally.
Definition: Electron.h:306
Definition: HeavyIon.h:7
const edm::EDGetTokenT< EcalRecHitCollection > reducedBarrelRecHitCollectionToken_
std::unique_ptr< pat::ObjectModifier< pat::Electron > > electronModifier_
std::vector< reco::CaloCluster > basicClusters_
Place to store electron&#39;s basic clusters internally.
Definition: Electron.h:302
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const StringCutObjectSelector< pat::Electron > dropBasicClusters_
std::vector< reco::CaloCluster > preshowerClusters_
Place to store electron&#39;s preshower clusters internally.
Definition: Electron.h:304
PATElectronSlimmer(const edm::ParameterSet &iConfig)
bool embeddedRecHits_
True if RecHits stored internally.
Definition: Electron.h:320
const StringCutObjectSelector< pat::Electron > dropPreshowerClusters_
const StringCutObjectSelector< pat::Electron > dropClassifications_
const StringCutObjectSelector< pat::Electron > dropShapes_
const StringCutObjectSelector< pat::Electron > dropExtrapolations_
bool embeddedSeedCluster_
True if seed cluster is stored internally.
Definition: Electron.h:316
const StringCutObjectSelector< pat::Electron > saveNonZSClusterShapes_
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) final
edm::Ref< PFCandidateCollection > PFCandidateRef
persistent reference to a PFCandidate
EcalRecHitCollection recHits_
Place to store electron&#39;s RecHits internally (5x5 around seed+ all RecHits)
Definition: Electron.h:322
const StringCutObjectSelector< pat::Electron > dropSeedCluster_
edm::Ptr< Candidate > CandidatePtr
persistent reference to an object in a collection of Candidate objects
Definition: CandidateFwd.h:25
const StringCutObjectSelector< pat::Electron > dropPFlowClusters_
void setClassification(Classification myclass)
Definition: GsfElectron.h:778
bool embeddedPflowSuperCluster_
True if electron&#39;s pflowsupercluster is stored internally.
Definition: Electron.h:296
Analysis-level electron class.
Definition: Electron.h:52
const StringCutObjectSelector< pat::Electron > dropSaturation_
bool embeddedSuperCluster_
True if electron&#39;s supercluster is stored internally.
Definition: Electron.h:294
fixed size matrix
void setTrackExtrapolations(const TrackExtrapolations &te)
Definition: GsfElectron.h:303
HLT enums.
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
std::vector< reco::CaloCluster > pflowPreshowerClusters_
Place to store electron&#39;s pflow preshower clusters internally.
Definition: Electron.h:308
void setCorrections(const Corrections &c)
Definition: GsfElectron.h:856
void setAssociatedPackedPFCandidates(const edm::RefProd< pat::PackedCandidateCollection > &refprod, T beginIndexItr, T endIndexItr)
References to PFCandidates linked to this object (e.g. for isolation vetos or masking before jet recl...
Definition: Electron.h:268
void setClassificationVariables(const ClassificationVariables &cv)
Definition: GsfElectron.h:777
const edm::EDGetTokenT< edm::View< pat::Electron > > src_
const edm::EDGetTokenT< pat::PackedCandidateCollection > pc_
std::vector< float > localCovariances(const reco::BasicCluster &cluster, float w0=4.7)
edm::Ptr< reco::Candidate > refToOrig_
Definition: PATObject.h:421
reco::SuperClusterRef superCluster() const override
override the reco::GsfElectron::superCluster method, to access the internal storage of the superclust...
def move(src, dest)
Definition: eostools.py:511
std::vector< reco::SuperCluster > pflowSuperCluster_
Place to store electron&#39;s pflow supercluster internally.
Definition: Electron.h:310
edm::SortedCollection< EcalRecHit > EcalRecHitCollection
std::vector< reco::CaloCluster > seedCluster_
Place to store electron&#39;s seed cluster internally.
Definition: Electron.h:318