CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PATElectronSlimmer.cc
Go to the documentation of this file.
1 
8 
9 
22 
23 namespace pat {
24 
26  public:
27  explicit PATElectronSlimmer(const edm::ParameterSet & iConfig);
28  virtual ~PATElectronSlimmer() { }
29 
30  virtual void produce(edm::Event & iEvent, const edm::EventSetup & iSetup);
31 
32  private:
34 
37 
44  };
45 
46 } // namespace
47 
49  src_(consumes<edm::View<pat::Electron> >(iConfig.getParameter<edm::InputTag>("src"))),
50  dropSuperClusters_(iConfig.getParameter<std::string>("dropSuperCluster")),
51  dropBasicClusters_(iConfig.getParameter<std::string>("dropBasicClusters")),
52  dropPFlowClusters_(iConfig.getParameter<std::string>("dropPFlowClusters")),
53  dropPreshowerClusters_(iConfig.getParameter<std::string>("dropPreshowerClusters")),
54  dropSeedCluster_(iConfig.getParameter<std::string>("dropSeedCluster")),
55  dropRecHits_(iConfig.getParameter<std::string>("dropRecHits")),
56  dropCorrections_(iConfig.getParameter<std::string>("dropCorrections")),
57  dropIsolations_(iConfig.getParameter<std::string>("dropIsolations")),
58  dropShapes_(iConfig.getParameter<std::string>("dropShapes")),
59  dropExtrapolations_(iConfig.getParameter<std::string>("dropExtrapolations")),
60  dropClassifications_(iConfig.getParameter<std::string>("dropClassifications")),
61  linkToPackedPF_(iConfig.getParameter<bool>("linkToPackedPFCandidates")),
62  saveNonZSClusterShapes_(iConfig.getParameter<std::string>("saveNonZSClusterShapes")),
63  reducedBarrelRecHitCollectionToken_(consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("reducedBarrelRecHitCollection"))),
64  reducedEndcapRecHitCollectionToken_(consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("reducedEndcapRecHitCollection")))
65 {
66  produces<std::vector<pat::Electron> >();
67  if (linkToPackedPF_) {
68  reco2pf_ = consumes<edm::ValueMap<std::vector<reco::PFCandidateRef>>>(iConfig.getParameter<edm::InputTag>("recoToPFMap"));
69  pf2pc_ = consumes<edm::Association<pat::PackedCandidateCollection>>(iConfig.getParameter<edm::InputTag>("packedPFCandidates"));
70  pc_ = consumes<pat::PackedCandidateCollection>(iConfig.getParameter<edm::InputTag>("packedPFCandidates"));
71  }
72  mayConsume<EcalRecHitCollection>(edm::InputTag("reducedEcalRecHitsEB"));
73  mayConsume<EcalRecHitCollection>(edm::InputTag("reducedEcalRecHitsEE"));
74 }
75 
76 void
78  using namespace edm;
79  using namespace std;
80 
82  iEvent.getByToken(src_, src);
83 
87  if (linkToPackedPF_) {
88  iEvent.getByToken(reco2pf_, reco2pf);
89  iEvent.getByToken(pf2pc_, pf2pc);
90  iEvent.getByToken(pc_, pc);
91  }
92  noZS::EcalClusterLazyTools lazyToolsNoZS(iEvent, iSetup, reducedBarrelRecHitCollectionToken_, reducedEndcapRecHitCollectionToken_);
93 
94  auto_ptr<vector<pat::Electron> > out(new vector<pat::Electron>());
95  out->reserve(src->size());
96 
97  std::vector<unsigned int> keys;
98  for (View<pat::Electron>::const_iterator it = src->begin(), ed = src->end(); it != ed; ++it) {
99  out->push_back(*it);
100  pat::Electron & electron = out->back();
101  if (dropSuperClusters_(electron)) { electron.superCluster_.clear(); electron.embeddedSuperCluster_ = false; }
102  if (dropBasicClusters_(electron)) { electron.basicClusters_.clear(); }
103  if (dropSuperClusters_(electron) || dropPFlowClusters_(electron)) { electron.pflowSuperCluster_.clear(); electron.embeddedPflowSuperCluster_ = false; }
104  if (dropBasicClusters_(electron) || dropPFlowClusters_(electron)) { electron.pflowBasicClusters_.clear(); }
105  if (dropPreshowerClusters_(electron)) { electron.preshowerClusters_.clear(); }
106  if (dropPreshowerClusters_(electron) || dropPFlowClusters_(electron)) { electron.pflowPreshowerClusters_.clear(); }
107  if (dropSeedCluster_(electron)) { electron.seedCluster_.clear(); electron.embeddedSeedCluster_ = false; }
108  if (dropRecHits_(electron)) { electron.recHits_ = EcalRecHitCollection(); electron.embeddedRecHits_ = false; }
109  if (dropCorrections_(electron)) { electron.setCorrections(reco::GsfElectron::Corrections()); }
111  if (dropShapes_(electron)) { electron.setShowerShape(reco::GsfElectron::ShowerShape()); }
112  if (dropExtrapolations_(electron)) { electron.setTrackExtrapolations(reco::GsfElectron::TrackExtrapolations()); }
114  if (linkToPackedPF_) {
115  //std::cout << " PAT electron in " << src.id() << " comes from " << electron.refToOrig_.id() << ", " << electron.refToOrig_.key() << std::endl;
116  keys.clear();
117  for(auto const& pf: (*reco2pf)[electron.refToOrig_]) {
118  if( pf2pc->contains(pf.id()) ) {
119  keys.push_back( (*pf2pc)[pf].key());
120  }
121  }
123  keys.begin(), keys.end());
124  //std::cout << "Electron with pt " << electron.pt() << " associated to " << electron.associatedPackedFCandidateIndices_.size() << " PF Candidates\n";
125  //if there's just one PF Cand then it's me, otherwise I have no univoque parent so my ref will be null
126  if (keys.size() == 1) {
127  electron.refToOrig_ = electron.sourceCandidatePtr(0);
128  } else {
129  electron.refToOrig_ = reco::CandidatePtr(pc.id());
130  }
131  }
132  if (saveNonZSClusterShapes_(electron)) {
133  std::vector<float> vCov = lazyToolsNoZS.localCovariances(*( electron.superCluster()->seed()));
134  electron.full5x5_setSigmaIetaIphi(vCov[1]);
135  }
136 
137  }
138 
139  iEvent.put(out);
140 }
141 
143 using namespace pat;
edm::EDGetTokenT< pat::PackedCandidateCollection > pc_
void setDr04Isolation(const IsolationVariables &dr04)
Definition: GsfElectron.h:500
T getParameter(std::string const &) const
StringCutObjectSelector< pat::Electron > dropPFlowClusters_
edm::EDGetTokenT< edm::Association< pat::PackedCandidateCollection > > pf2pc_
edm::EDGetTokenT< edm::View< pat::Electron > > src_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:449
edm::EDGetTokenT< EcalRecHitCollection > reducedEndcapRecHitCollectionToken_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
StringCutObjectSelector< pat::Electron > dropIsolations_
void full5x5_setSigmaIetaIphi(float sigmaIetaIphi)
Definition: Electron.h:211
void setShowerShape(const ShowerShape &s)
Definition: GsfElectron.h:434
std::vector< reco::SuperCluster > superCluster_
Place to store electron&#39;s supercluster internally.
Definition: Electron.h:280
Slimmer of PAT Electrons.
void setHcalPFClusterIso(float hcalPFClus)
Definition: Electron.h:161
StringCutObjectSelector< pat::Electron > dropBasicClusters_
void setPfIsolationVariables(const PflowIsolationVariables &iso)
Definition: GsfElectron.h:609
void setDr03Isolation(const IsolationVariables &dr03)
Definition: GsfElectron.h:499
std::vector< reco::CaloCluster > pflowBasicClusters_
Place to store electron&#39;s pflow basic clusters internally.
Definition: Electron.h:288
edm::EDGetTokenT< edm::ValueMap< std::vector< reco::PFCandidateRef > > > reco2pf_
std::vector< reco::CaloCluster > basicClusters_
Place to store electron&#39;s basic clusters internally.
Definition: Electron.h:284
StringCutObjectSelector< pat::Electron > dropExtrapolations_
reco::SuperClusterRef superCluster() const
override the reco::GsfElectron::superCluster method, to access the internal storage of the superclust...
edm::EDGetTokenT< EcalRecHitCollection > reducedBarrelRecHitCollectionToken_
int iEvent
Definition: GenABIO.cc:230
std::vector< reco::CaloCluster > preshowerClusters_
Place to store electron&#39;s preshower clusters internally.
Definition: Electron.h:286
PATElectronSlimmer(const edm::ParameterSet &iConfig)
bool embeddedRecHits_
True if RecHits stored internally.
Definition: Electron.h:302
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
bool embeddedSeedCluster_
True if seed cluster is stored internally.
Definition: Electron.h:298
StringCutObjectSelector< pat::Electron > dropShapes_
tuple out
Definition: dbtoconf.py:99
EcalRecHitCollection recHits_
Place to store electron&#39;s RecHits internally (5x5 around seed+ all RecHits)
Definition: Electron.h:304
StringCutObjectSelector< pat::Electron > dropSuperClusters_
StringCutObjectSelector< pat::Electron > dropSeedCluster_
StringCutObjectSelector< pat::Electron > dropRecHits_
edm::Ptr< Candidate > CandidatePtr
persistent reference to an object in a collection of Candidate objects
Definition: CandidateFwd.h:25
void setEcalPFClusterIso(float ecalPFClus)
Definition: Electron.h:160
void setClassification(Classification myclass)
Definition: GsfElectron.h:690
StringCutObjectSelector< pat::Electron > dropClassifications_
bool embeddedPflowSuperCluster_
True if electron&#39;s pflowsupercluster is stored internally.
Definition: Electron.h:278
std::vector< float > localCovariances(const reco::BasicCluster &cluster, float w0=4.7)
Analysis-level electron class.
Definition: Electron.h:52
StringCutObjectSelector< pat::Electron > dropCorrections_
bool embeddedSuperCluster_
True if electron&#39;s supercluster is stored internally.
Definition: Electron.h:276
StringCutObjectSelector< pat::Electron > dropPreshowerClusters_
void setTrackExtrapolations(const TrackExtrapolations &te)
Definition: GsfElectron.h:297
reco::CandidatePtr sourceCandidatePtr(size_type i) const
get the source candidate pointer with index i
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81
std::vector< reco::CaloCluster > pflowPreshowerClusters_
Place to store electron&#39;s pflow preshower clusters internally.
Definition: Electron.h:290
void setCorrections(const Corrections &c)
Definition: GsfElectron.h:767
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:250
void setClassificationVariables(const ClassificationVariables &cv)
Definition: GsfElectron.h:689
StringCutObjectSelector< pat::Electron > saveNonZSClusterShapes_
edm::Ptr< reco::Candidate > refToOrig_
Definition: PATObject.h:407
virtual void produce(edm::Event &iEvent, const edm::EventSetup &iSetup)
std::vector< reco::SuperCluster > pflowSuperCluster_
Place to store electron&#39;s pflow supercluster internally.
Definition: Electron.h:292
edm::SortedCollection< EcalRecHit > EcalRecHitCollection
std::vector< reco::CaloCluster > seedCluster_
Place to store electron&#39;s seed cluster internally.
Definition: Electron.h:300