CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
PATElectronSlimmer.cc
Go to the documentation of this file.
1 
8 
10 
23 
24 namespace pat {
25 
27  public:
29  ~PATElectronSlimmer() override {}
30 
31  void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) final;
33 
34  private:
35  const edm::EDGetTokenT<edm::View<pat::Electron>> src_;
36 
41 
42  const edm::EDGetTokenT<edm::ValueMap<std::vector<reco::PFCandidateRef>>> reco2pf_;
43  const edm::EDGetTokenT<edm::Association<pat::PackedCandidateCollection>> pf2pc_;
44  const edm::EDGetTokenT<pat::PackedCandidateCollection> pc_;
52  };
53 
54 } // namespace pat
55 
57  : src_(consumes<edm::View<pat::Electron>>(iConfig.getParameter<edm::InputTag>("src"))),
58  dropSuperClusters_(iConfig.getParameter<std::string>("dropSuperCluster")),
59  dropBasicClusters_(iConfig.getParameter<std::string>("dropBasicClusters")),
60  dropPFlowClusters_(iConfig.getParameter<std::string>("dropPFlowClusters")),
61  dropPreshowerClusters_(iConfig.getParameter<std::string>("dropPreshowerClusters")),
62  dropSeedCluster_(iConfig.getParameter<std::string>("dropSeedCluster")),
63  dropRecHits_(iConfig.getParameter<std::string>("dropRecHits")),
64  dropCorrections_(iConfig.getParameter<std::string>("dropCorrections")),
65  dropIsolations_(iConfig.getParameter<std::string>("dropIsolations")),
66  dropShapes_(iConfig.getParameter<std::string>("dropShapes")),
67  dropSaturation_(iConfig.getParameter<std::string>("dropSaturation")),
68  dropExtrapolations_(iConfig.getParameter<std::string>("dropExtrapolations")),
69  dropClassifications_(iConfig.getParameter<std::string>("dropClassifications")),
70  reco2pf_(mayConsume<edm::ValueMap<std::vector<reco::PFCandidateRef>>>(
71  iConfig.getParameter<edm::InputTag>("recoToPFMap"))),
72  pf2pc_(mayConsume<edm::Association<pat::PackedCandidateCollection>>(
73  iConfig.getParameter<edm::InputTag>("packedPFCandidates"))),
74  pc_(mayConsume<pat::PackedCandidateCollection>(iConfig.getParameter<edm::InputTag>("packedPFCandidates"))),
75  linkToPackedPF_(iConfig.getParameter<bool>("linkToPackedPFCandidates")),
76  saveNonZSClusterShapes_(iConfig.getParameter<std::string>("saveNonZSClusterShapes")),
77  reducedBarrelRecHitCollectionToken_(
78  consumes(iConfig.getParameter<edm::InputTag>("reducedBarrelRecHitCollection"))),
79  reducedEndcapRecHitCollectionToken_(
80  consumes(iConfig.getParameter<edm::InputTag>("reducedEndcapRecHitCollection"))),
81  ecalClusterToolsESGetTokens_{consumesCollector()},
82  modifyElectron_(iConfig.getParameter<bool>("modifyElectrons")) {
83  if (modifyElectron_) {
84  const edm::ParameterSet& mod_config = iConfig.getParameter<edm::ParameterSet>("modifierConfig");
85  electronModifier_ = std::make_unique<pat::ObjectModifier<pat::Electron>>(mod_config, consumesCollector());
86  }
87 
88  mayConsume<EcalRecHitCollection>(edm::InputTag("reducedEcalRecHitsEB"));
89  mayConsume<EcalRecHitCollection>(edm::InputTag("reducedEcalRecHitsEE"));
90 
91  produces<std::vector<pat::Electron>>();
92 }
93 
95 
97  using namespace edm;
98  using namespace std;
99 
101  iEvent.getByToken(src_, src);
102 
106  if (linkToPackedPF_) {
107  iEvent.getByToken(reco2pf_, reco2pf);
108  iEvent.getByToken(pf2pc_, pf2pc);
109  iEvent.getByToken(pc_, pc);
110  }
111  noZS::EcalClusterLazyTools lazyToolsNoZS(iEvent,
115 
116  auto out = std::make_unique<std::vector<pat::Electron>>();
117  out->reserve(src->size());
118 
119  if (modifyElectron_) {
120  electronModifier_->setEvent(iEvent);
121  }
122  if (modifyElectron_)
123  electronModifier_->setEventContent(iSetup);
124 
125  std::vector<unsigned int> keys;
126  for (View<pat::Electron>::const_iterator it = src->begin(), ed = src->end(); it != ed; ++it) {
127  out->push_back(*it);
128  pat::Electron& electron = out->back();
129 
130  if (modifyElectron_) {
131  electronModifier_->modify(electron);
132  }
133 
134  if (dropSuperClusters_(electron)) {
135  electron.superCluster_.clear();
136  electron.embeddedSuperCluster_ = false;
137  }
138  if (dropBasicClusters_(electron)) {
139  electron.basicClusters_.clear();
140  }
141  if (dropSuperClusters_(electron) || dropPFlowClusters_(electron)) {
142  electron.pflowSuperCluster_.clear();
143  electron.embeddedPflowSuperCluster_ = false;
144  }
145  if (dropBasicClusters_(electron) || dropPFlowClusters_(electron)) {
146  electron.pflowBasicClusters_.clear();
147  }
148  if (dropPreshowerClusters_(electron)) {
149  electron.preshowerClusters_.clear();
150  }
151  if (dropPreshowerClusters_(electron) || dropPFlowClusters_(electron)) {
152  electron.pflowPreshowerClusters_.clear();
153  }
154  if (dropSeedCluster_(electron)) {
155  electron.seedCluster_.clear();
156  electron.embeddedSeedCluster_ = false;
157  }
158  if (dropRecHits_(electron)) {
159  electron.recHits_ = EcalRecHitCollection();
160  electron.embeddedRecHits_ = false;
161  }
162  if (dropCorrections_(electron)) {
164  }
165  if (dropIsolations_(electron)) {
169  }
170  if (dropShapes_(electron)) {
172  }
173  if (dropSaturation_(electron)) {
175  }
176  if (dropExtrapolations_(electron)) {
178  }
179  if (dropClassifications_(electron)) {
182  }
183  if (linkToPackedPF_) {
184  //std::cout << " PAT electron in " << src.id() << " comes from " << electron.refToOrig_.id() << ", " << electron.refToOrig_.key() << std::endl;
185  keys.clear();
186  for (auto const& pf : (*reco2pf)[electron.refToOrig_]) {
187  if (pf2pc->contains(pf.id())) {
188  keys.push_back((*pf2pc)[pf].key());
189  }
190  }
193  //std::cout << "Electron with pt " << electron.pt() << " associated to " << electron.associatedPackedFCandidateIndices_.size() << " PF Candidates\n";
194  //if there's just one PF Cand then it's me, otherwise I have no univoque parent so my ref will be null
195  if (keys.size() == 1) {
196  electron.refToOrig_ = electron.sourceCandidatePtr(0);
197  } else {
198  electron.refToOrig_ = reco::CandidatePtr(pc.id());
199  }
200  }
201  if (saveNonZSClusterShapes_(electron)) {
202  const auto& vCov = lazyToolsNoZS.localCovariances(*(electron.superCluster()->seed()));
203  electron.full5x5_setSigmaIetaIphi(vCov[1]);
204  }
205  }
206 
207  iEvent.put(std::move(out));
208 }
209 
211 using namespace pat;
void setDr04Isolation(const IsolationVariables &dr04)
Definition: GsfElectron.h:606
const edm::EDGetTokenT< EcalRecHitCollection > reducedEndcapRecHitCollectionToken_
const StringCutObjectSelector< pat::Electron > dropRecHits_
reco::CandidatePtr sourceCandidatePtr(size_type i) const override
get the source candidate pointer with index i
const StringCutObjectSelector< pat::Electron > dropIsolations_
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
const edm::EDGetTokenT< edm::ValueMap< std::vector< reco::PFCandidateRef > > > reco2pf_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const StringCutObjectSelector< pat::Electron > dropSuperClusters_
std::vector< pat::PackedCandidate > PackedCandidateCollection
void setSaturationInfo(const SaturationInfo &s)
Definition: GsfElectron.h:522
const StringCutObjectSelector< pat::Electron > dropCorrections_
void full5x5_setSigmaIetaIphi(float sigmaIetaIphi)
Definition: Electron.h:218
void setShowerShape(const ShowerShape &s)
Definition: GsfElectron.h:491
std::vector< reco::SuperCluster > superCluster_
Place to store electron&#39;s supercluster internally.
Definition: Electron.h:291
Slimmer of PAT Electrons.
reco::SuperClusterRef superCluster() const override
override the reco::GsfElectron::superCluster method, to access the internal storage of the superclust...
std::unique_ptr< T, impl::DeviceDeleter > unique_ptr
const edm::EDGetTokenT< edm::Association< pat::PackedCandidateCollection > > pf2pc_
void setPfIsolationVariables(const PflowIsolationVariables &iso)
Definition: GsfElectron.h:738
void setDr03Isolation(const IsolationVariables &dr03)
Definition: GsfElectron.h:605
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:299
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:295
int iEvent
Definition: GenABIO.cc:224
const StringCutObjectSelector< pat::Electron > dropBasicClusters_
std::vector< reco::CaloCluster > preshowerClusters_
Place to store electron&#39;s preshower clusters internally.
Definition: Electron.h:297
PATElectronSlimmer(const edm::ParameterSet &iConfig)
const EcalClusterLazyTools::ESGetTokens ecalClusterToolsESGetTokens_
bool embeddedRecHits_
True if RecHits stored internally.
Definition: Electron.h:313
const StringCutObjectSelector< pat::Electron > dropPreshowerClusters_
const StringCutObjectSelector< pat::Electron > dropClassifications_
const StringCutObjectSelector< pat::Electron > dropShapes_
const StringCutObjectSelector< pat::Electron > dropExtrapolations_
def move
Definition: eostools.py:511
bool embeddedSeedCluster_
True if seed cluster is stored internally.
Definition: Electron.h:309
const StringCutObjectSelector< pat::Electron > saveNonZSClusterShapes_
tuple key
prepare the HTCondor submission files and eventually submit them
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) final
EcalRecHitCollection recHits_
Place to store electron&#39;s RecHits internally (5x5 around seed+ all RecHits)
Definition: Electron.h:315
const StringCutObjectSelector< pat::Electron > dropSeedCluster_
ESData get(edm::EventSetup const &eventSetup) const
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:815
bool embeddedPflowSuperCluster_
True if electron&#39;s pflowsupercluster is stored internally.
Definition: Electron.h:289
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
Analysis-level electron class.
Definition: Electron.h:51
const StringCutObjectSelector< pat::Electron > dropSaturation_
bool embeddedSuperCluster_
True if electron&#39;s supercluster is stored internally.
Definition: Electron.h:287
void setTrackExtrapolations(const TrackExtrapolations &te)
Definition: GsfElectron.h:278
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:301
void setCorrections(const Corrections &c)
Definition: GsfElectron.h:892
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:263
void setClassificationVariables(const ClassificationVariables &cv)
Definition: GsfElectron.h:814
edm::Ref< l1t::PFCandidateCollection > PFCandidateRef
Definition: PFCandidate.h:58
const edm::EDGetTokenT< edm::View< pat::Electron > > src_
const edm::EDGetTokenT< pat::PackedCandidateCollection > pc_
edm::Ptr< reco::Candidate > refToOrig_
Definition: PATObject.h:458
std::vector< reco::SuperCluster > pflowSuperCluster_
Place to store electron&#39;s pflow supercluster internally.
Definition: Electron.h:303
edm::SortedCollection< EcalRecHit > EcalRecHitCollection
std::vector< reco::CaloCluster > seedCluster_
Place to store electron&#39;s seed cluster internally.
Definition: Electron.h:311