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 
41 
45  const bool linkToPackedPF_;
49  const bool modifyElectron_;
50  std::unique_ptr<pat::ObjectModifier<pat::Electron>> electronModifier_;
51  };
52 
53 } // namespace pat
54 
56  : src_(consumes<edm::View<pat::Electron>>(iConfig.getParameter<edm::InputTag>("src"))),
57  dropSuperClusters_(iConfig.getParameter<std::string>("dropSuperCluster")),
58  dropBasicClusters_(iConfig.getParameter<std::string>("dropBasicClusters")),
59  dropPFlowClusters_(iConfig.getParameter<std::string>("dropPFlowClusters")),
60  dropPreshowerClusters_(iConfig.getParameter<std::string>("dropPreshowerClusters")),
61  dropSeedCluster_(iConfig.getParameter<std::string>("dropSeedCluster")),
62  dropRecHits_(iConfig.getParameter<std::string>("dropRecHits")),
63  dropCorrections_(iConfig.getParameter<std::string>("dropCorrections")),
64  dropIsolations_(iConfig.getParameter<std::string>("dropIsolations")),
65  dropShapes_(iConfig.getParameter<std::string>("dropShapes")),
66  dropSaturation_(iConfig.getParameter<std::string>("dropSaturation")),
67  dropExtrapolations_(iConfig.getParameter<std::string>("dropExtrapolations")),
68  dropClassifications_(iConfig.getParameter<std::string>("dropClassifications")),
69  reco2pf_(mayConsume<edm::ValueMap<std::vector<reco::PFCandidateRef>>>(
70  iConfig.getParameter<edm::InputTag>("recoToPFMap"))),
71  pf2pc_(mayConsume<edm::Association<pat::PackedCandidateCollection>>(
72  iConfig.getParameter<edm::InputTag>("packedPFCandidates"))),
73  pc_(mayConsume<pat::PackedCandidateCollection>(iConfig.getParameter<edm::InputTag>("packedPFCandidates"))),
74  linkToPackedPF_(iConfig.getParameter<bool>("linkToPackedPFCandidates")),
75  saveNonZSClusterShapes_(iConfig.getParameter<std::string>("saveNonZSClusterShapes")),
76  reducedBarrelRecHitCollectionToken_(
77  consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("reducedBarrelRecHitCollection"))),
78  reducedEndcapRecHitCollectionToken_(
79  consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("reducedEndcapRecHitCollection"))),
80  modifyElectron_(iConfig.getParameter<bool>("modifyElectrons")) {
81  if (modifyElectron_) {
82  const edm::ParameterSet& mod_config = iConfig.getParameter<edm::ParameterSet>("modifierConfig");
83  electronModifier_ = std::make_unique<pat::ObjectModifier<pat::Electron>>(mod_config, consumesCollector());
84  }
85 
86  mayConsume<EcalRecHitCollection>(edm::InputTag("reducedEcalRecHitsEB"));
87  mayConsume<EcalRecHitCollection>(edm::InputTag("reducedEcalRecHitsEE"));
88 
89  produces<std::vector<pat::Electron>>();
90 }
91 
93 
95  using namespace edm;
96  using namespace std;
97 
99  iEvent.getByToken(src_, src);
100 
104  if (linkToPackedPF_) {
105  iEvent.getByToken(reco2pf_, reco2pf);
106  iEvent.getByToken(pf2pc_, pf2pc);
107  iEvent.getByToken(pc_, pc);
108  }
109  noZS::EcalClusterLazyTools lazyToolsNoZS(
110  iEvent, iSetup, reducedBarrelRecHitCollectionToken_, reducedEndcapRecHitCollectionToken_);
111 
112  auto out = std::make_unique<std::vector<pat::Electron>>();
113  out->reserve(src->size());
114 
115  if (modifyElectron_) {
116  electronModifier_->setEvent(iEvent);
117  }
118  if (modifyElectron_)
119  electronModifier_->setEventContent(iSetup);
120 
121  std::vector<unsigned int> keys;
122  for (View<pat::Electron>::const_iterator it = src->begin(), ed = src->end(); it != ed; ++it) {
123  out->push_back(*it);
124  pat::Electron& electron = out->back();
125 
126  if (modifyElectron_) {
127  electronModifier_->modify(electron);
128  }
129 
130  if (dropSuperClusters_(electron)) {
131  electron.superCluster_.clear();
132  electron.embeddedSuperCluster_ = false;
133  }
134  if (dropBasicClusters_(electron)) {
135  electron.basicClusters_.clear();
136  }
137  if (dropSuperClusters_(electron) || dropPFlowClusters_(electron)) {
138  electron.pflowSuperCluster_.clear();
139  electron.embeddedPflowSuperCluster_ = false;
140  }
141  if (dropBasicClusters_(electron) || dropPFlowClusters_(electron)) {
142  electron.pflowBasicClusters_.clear();
143  }
144  if (dropPreshowerClusters_(electron)) {
145  electron.preshowerClusters_.clear();
146  }
147  if (dropPreshowerClusters_(electron) || dropPFlowClusters_(electron)) {
148  electron.pflowPreshowerClusters_.clear();
149  }
150  if (dropSeedCluster_(electron)) {
151  electron.seedCluster_.clear();
152  electron.embeddedSeedCluster_ = false;
153  }
154  if (dropRecHits_(electron)) {
155  electron.recHits_ = EcalRecHitCollection();
156  electron.embeddedRecHits_ = false;
157  }
158  if (dropCorrections_(electron)) {
159  electron.setCorrections(reco::GsfElectron::Corrections());
160  }
161  if (dropIsolations_(electron)) {
164  electron.setPfIsolationVariables(reco::GsfElectron::PflowIsolationVariables());
165  }
166  if (dropShapes_(electron)) {
167  electron.setShowerShape(reco::GsfElectron::ShowerShape());
168  }
169  if (dropSaturation_(electron)) {
170  electron.setSaturationInfo(reco::GsfElectron::SaturationInfo());
171  }
172  if (dropExtrapolations_(electron)) {
173  electron.setTrackExtrapolations(reco::GsfElectron::TrackExtrapolations());
174  }
175  if (dropClassifications_(electron)) {
176  electron.setClassificationVariables(reco::GsfElectron::ClassificationVariables());
177  electron.setClassification(reco::GsfElectron::Classification());
178  }
179  if (linkToPackedPF_) {
180  //std::cout << " PAT electron in " << src.id() << " comes from " << electron.refToOrig_.id() << ", " << electron.refToOrig_.key() << std::endl;
181  keys.clear();
182  for (auto const& pf : (*reco2pf)[electron.refToOrig_]) {
183  if (pf2pc->contains(pf.id())) {
184  keys.push_back((*pf2pc)[pf].key());
185  }
186  }
187  electron.setAssociatedPackedPFCandidates(
189  //std::cout << "Electron with pt " << electron.pt() << " associated to " << electron.associatedPackedFCandidateIndices_.size() << " PF Candidates\n";
190  //if there's just one PF Cand then it's me, otherwise I have no univoque parent so my ref will be null
191  if (keys.size() == 1) {
192  electron.refToOrig_ = electron.sourceCandidatePtr(0);
193  } else {
194  electron.refToOrig_ = reco::CandidatePtr(pc.id());
195  }
196  }
197  if (saveNonZSClusterShapes_(electron)) {
198  std::vector<float> vCov = lazyToolsNoZS.localCovariances(*(electron.superCluster()->seed()));
199  electron.full5x5_setSigmaIetaIphi(vCov[1]);
200  }
201  }
202 
203  iEvent.put(std::move(out));
204 }
205 
207 using namespace pat;
pat::PATElectronSlimmer::dropPFlowClusters_
const StringCutObjectSelector< pat::Electron > dropPFlowClusters_
Definition: PATElectronSlimmer.cc:37
edm::RefProd< pat::PackedCandidateCollection >
pat::PATElectronSlimmer::reco2pf_
const edm::EDGetTokenT< edm::ValueMap< std::vector< reco::PFCandidateRef > > > reco2pf_
Definition: PATElectronSlimmer.cc:42
pat::PATElectronSlimmer::beginLuminosityBlock
void beginLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &) final
Definition: PATElectronSlimmer.cc:92
ObjectModifier.h
EcalClusterLazyToolsT::localCovariances
std::vector< float > localCovariances(const reco::BasicCluster &cluster, float w0=4.7)
Definition: EcalClusterLazyTools.h:252
electrons_cff.bool
bool
Definition: electrons_cff.py:372
StringCutObjectSelector.h
sistrip::View
View
Definition: ConstantsForView.h:26
pat::PATElectronSlimmer::dropCorrections_
const StringCutObjectSelector< pat::Electron > dropCorrections_
Definition: PATElectronSlimmer.cc:39
PFCandidate.h
edm::LuminosityBlock
Definition: LuminosityBlock.h:50
edm::EDGetTokenT
Definition: EDGetToken.h:33
Electron
Definition: Electron.py:1
edm
HLT enums.
Definition: AlignableModifier.h:19
reco::GsfElectron::PflowIsolationVariables
Definition: GsfElectron.h:606
pat::PATElectronSlimmer::dropIsolations_
const StringCutObjectSelector< pat::Electron > dropIsolations_
Definition: PATElectronSlimmer.cc:39
pat::PATElectronSlimmer::~PATElectronSlimmer
~PATElectronSlimmer() override
Definition: PATElectronSlimmer.cc:29
EDProducer.h
edm::SortedCollection< EcalRecHit >
pat::PATElectronSlimmer::saveNonZSClusterShapes_
const StringCutObjectSelector< pat::Electron > saveNonZSClusterShapes_
Definition: PATElectronSlimmer.cc:46
pat::PATElectronSlimmer::pc_
const edm::EDGetTokenT< pat::PackedCandidateCollection > pc_
Definition: PATElectronSlimmer.cc:44
EcalClusterLazyTools.h
relativeConstraints.keys
keys
Definition: relativeConstraints.py:89
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
Association.h
edm::Handle
Definition: AssociativeIterator.h:50
pat::PATElectronSlimmer::modifyElectron_
const bool modifyElectron_
Definition: PATElectronSlimmer.cc:49
reco::GsfElectron::Classification
Classification
Definition: GsfElectron.h:724
MakerMacros.h
pat::PATElectronSlimmer::dropPreshowerClusters_
const StringCutObjectSelector< pat::Electron > dropPreshowerClusters_
Definition: PATElectronSlimmer.cc:37
pat::PATElectronSlimmer
Slimmer of PAT Electrons.
Definition: PATElectronSlimmer.cc:26
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
pat::PATElectronSlimmer::linkToPackedPF_
const bool linkToPackedPF_
Definition: PATElectronSlimmer.cc:45
l1t::PFCandidateRef
edm::Ref< l1t::PFCandidateCollection > PFCandidateRef
Definition: PFCandidate.h:58
pat::PATElectronSlimmer::src_
const edm::EDGetTokenT< edm::View< pat::Electron > > src_
Definition: PATElectronSlimmer.cc:35
reco::GsfElectron::ShowerShape
Definition: GsfElectron.h:366
pat::PATElectronSlimmer::produce
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) final
Definition: PATElectronSlimmer.cc:94
metsig::electron
Definition: SignAlgoResolutions.h:48
GsfElectron.h
reco::GsfElectron::IsolationVariables
Definition: GsfElectron.h:510
pat::PATElectronSlimmer::dropSuperClusters_
const StringCutObjectSelector< pat::Electron > dropSuperClusters_
Definition: PATElectronSlimmer.cc:37
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
EcalRecHitCollection
edm::SortedCollection< EcalRecHit > EcalRecHitCollection
Definition: EcalRecHitCollections.h:10
EcalClusterLazyToolsT
Definition: EcalClusterLazyTools.h:105
pat::PATElectronSlimmer::reducedEndcapRecHitCollectionToken_
const edm::EDGetTokenT< EcalRecHitCollection > reducedEndcapRecHitCollectionToken_
Definition: PATElectronSlimmer.cc:47
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
edm::ParameterSet
Definition: ParameterSet.h:36
TrackRefitter_38T_cff.src
src
Definition: TrackRefitter_38T_cff.py:24
Event.h
PackedCandidate.h
reco::GsfElectron::TrackExtrapolations
Definition: GsfElectron.h:260
iEvent
int iEvent
Definition: GenABIO.cc:224
pat::PATElectronSlimmer::dropSaturation_
const StringCutObjectSelector< pat::Electron > dropSaturation_
Definition: PATElectronSlimmer.cc:39
RefToPtr.h
edm::stream::EDProducer
Definition: EDProducer.h:38
pat::PATElectronSlimmer::reducedBarrelRecHitCollectionToken_
const edm::EDGetTokenT< EcalRecHitCollection > reducedBarrelRecHitCollectionToken_
Definition: PATElectronSlimmer.cc:47
edm::EventSetup
Definition: EventSetup.h:57
reco::GsfElectron::ClassificationVariables
Definition: GsfElectron.h:718
pat
Definition: HeavyIon.h:7
pat::PATElectronSlimmer::electronModifier_
std::unique_ptr< pat::ObjectModifier< pat::Electron > > electronModifier_
Definition: PATElectronSlimmer.cc:50
pat::PackedCandidateCollection
std::vector< pat::PackedCandidate > PackedCandidateCollection
Definition: PackedCandidate.h:1130
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
pat::PATElectronSlimmer::dropRecHits_
const StringCutObjectSelector< pat::Electron > dropRecHits_
Definition: PATElectronSlimmer.cc:37
pat::PATElectronSlimmer::dropBasicClusters_
const StringCutObjectSelector< pat::Electron > dropBasicClusters_
Definition: PATElectronSlimmer.cc:37
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
isFinite.h
Frameworkfwd.h
packedPFCandidateRefMixer_cfi.pf
pf
Definition: packedPFCandidateRefMixer_cfi.py:4
pat::PATElectronSlimmer::dropShapes_
const StringCutObjectSelector< pat::Electron > dropShapes_
Definition: PATElectronSlimmer.cc:39
pat::PATElectronSlimmer::dropExtrapolations_
const StringCutObjectSelector< pat::Electron > dropExtrapolations_
Definition: PATElectronSlimmer.cc:39
StringCutObjectSelector< pat::Electron >
Electron.h
edm::View::const_iterator
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
reco::CandidatePtr
edm::Ptr< Candidate > CandidatePtr
persistent reference to an object in a collection of Candidate objects
Definition: CandidateFwd.h:25
pat::Electron
Analysis-level electron class.
Definition: Electron.h:51
ParameterSet.h
edm::Event
Definition: Event.h:73
reco::GsfElectron::SaturationInfo
Definition: GsfElectron.h:490
pat::PATElectronSlimmer::PATElectronSlimmer
PATElectronSlimmer(const edm::ParameterSet &iConfig)
Definition: PATElectronSlimmer.cc:55
crabWrapper.key
key
Definition: crabWrapper.py:19
edm::HandleBase::id
ProductID id() const
Definition: HandleBase.cc:13
pat::PATElectronSlimmer::dropSeedCluster_
const StringCutObjectSelector< pat::Electron > dropSeedCluster_
Definition: PATElectronSlimmer.cc:37
edm::InputTag
Definition: InputTag.h:15
pat::PATElectronSlimmer::dropClassifications_
const StringCutObjectSelector< pat::Electron > dropClassifications_
Definition: PATElectronSlimmer.cc:39
reco::GsfElectron::Corrections
Definition: GsfElectron.h:771
PFCandidateFwd.h
pat::PATElectronSlimmer::pf2pc_
const edm::EDGetTokenT< edm::Association< pat::PackedCandidateCollection > > pf2pc_
Definition: PATElectronSlimmer.cc:43