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 //
2 // $Id: PATElectronSlimmer.cc,v 1.1 2011/03/24 18:45:45 mwlebour Exp $
3 //
4 
13 
14 
27 
28 namespace pat {
29 
31  public:
32  explicit PATElectronSlimmer(const edm::ParameterSet & iConfig);
33  virtual ~PATElectronSlimmer() { }
34 
35  virtual void produce(edm::Event & iEvent, const edm::EventSetup & iSetup);
36 
37  private:
39 
42 
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  dropExtrapolations_(iConfig.getParameter<std::string>("dropExtrapolations")),
64  dropClassifications_(iConfig.getParameter<std::string>("dropClassifications")),
65  linkToPackedPF_(iConfig.getParameter<bool>("linkToPackedPFCandidates")),
66  saveNonZSClusterShapes_(iConfig.getParameter<std::string>("saveNonZSClusterShapes"))
67 {
68  produces<std::vector<pat::Electron> >();
69  if (linkToPackedPF_) {
70  reco2pf_ = consumes<edm::ValueMap<std::vector<reco::PFCandidateRef>>>(iConfig.getParameter<edm::InputTag>("recoToPFMap"));
71  pf2pc_ = consumes<edm::Association<pat::PackedCandidateCollection>>(iConfig.getParameter<edm::InputTag>("packedPFCandidates"));
72  pc_ = consumes<pat::PackedCandidateCollection>(iConfig.getParameter<edm::InputTag>("packedPFCandidates"));
73  }
74  mayConsume<EcalRecHitCollection>(edm::InputTag("reducedEcalRecHitsEB"));
75  mayConsume<EcalRecHitCollection>(edm::InputTag("reducedEcalRecHitsEE"));
76 }
77 
78 void
80  using namespace edm;
81  using namespace std;
82 
84  iEvent.getByToken(src_, src);
85 
89  if (linkToPackedPF_) {
90  iEvent.getByToken(reco2pf_, reco2pf);
91  iEvent.getByToken(pf2pc_, pf2pc);
92  iEvent.getByToken(pc_, pc);
93  }
94  edm::InputTag reducedBarrelRecHitCollection("reducedEcalRecHitsEB");
95  edm::InputTag reducedEndcapRecHitCollection("reducedEcalRecHitsEE");
96  noZS::EcalClusterLazyTools lazyToolsNoZS(iEvent, iSetup, reducedBarrelRecHitCollection, reducedEndcapRecHitCollection);
97 
98  auto_ptr<vector<pat::Electron> > out(new vector<pat::Electron>());
99  out->reserve(src->size());
100 
101  for (View<pat::Electron>::const_iterator it = src->begin(), ed = src->end(); it != ed; ++it) {
102  out->push_back(*it);
103  pat::Electron & electron = out->back();
104  if (dropSuperClusters_(electron)) { electron.superCluster_.clear(); electron.embeddedSuperCluster_ = false; }
105  if (dropBasicClusters_(electron)) { electron.basicClusters_.clear(); }
106  if (dropSuperClusters_(electron) || dropPFlowClusters_(electron)) { electron.pflowSuperCluster_.clear(); electron.embeddedPflowSuperCluster_ = false; }
107  if (dropBasicClusters_(electron) || dropPFlowClusters_(electron)) { electron.pflowBasicClusters_.clear(); }
108  if (dropPreshowerClusters_(electron)) { electron.preshowerClusters_.clear(); }
109  if (dropPreshowerClusters_(electron) || dropPFlowClusters_(electron)) { electron.pflowPreshowerClusters_.clear(); }
110  if (dropSeedCluster_(electron)) { electron.seedCluster_.clear(); electron.embeddedSeedCluster_ = false; }
111  if (dropRecHits_(electron)) { electron.recHits_ = EcalRecHitCollection(); electron.embeddedRecHits_ = false; }
112  if (dropCorrections_(electron)) { electron.setCorrections(reco::GsfElectron::Corrections()); }
114  if (dropShapes_(electron)) { electron.setPfShowerShape(reco::GsfElectron::ShowerShape()); electron.setShowerShape(reco::GsfElectron::ShowerShape()); }
115  if (dropExtrapolations_(electron)) { electron.setTrackExtrapolations(reco::GsfElectron::TrackExtrapolations()); }
117  if (linkToPackedPF_) {
119  //std::cout << " PAT electron in " << src.id() << " comes from " << electron.refToOrig_.id() << ", " << electron.refToOrig_.key() << std::endl;
121  for (const reco::PFCandidateRef & pf : (*reco2pf)[electron.refToOrig_]) {
122  if (pf2pc->contains(pf.id())) {
123  origs.push_back((*pf2pc)[pf]);
124  } //else std::cerr << " Electron linked to a PFCand in " << pf.id() << " while we expect them in " << pf2pc->ids().front().first << "\n";
125  }
126  //std::cout << "Electron with pt " << electron.pt() << " associated to " << origs.size() << " PF Candidates\n";
127  electron.setAssociatedPackedPFCandidates(origs);
128  //if there's just one PF Cand then it's me, otherwise I have no univoque parent so my ref will be null
129  if (origs.size() == 1) {
130  electron.refToOrig_ = refToPtr(origs[0]);
131  } else {
132  electron.refToOrig_ = reco::CandidatePtr(pc.id());
133  }
134  }
135  if (saveNonZSClusterShapes_(electron)) {
137  const auto & seedCluster = *electron.superCluster()->seed();
138  std::vector<float> vCov = lazyToolsNoZS.localCovariances(seedCluster);
139  std::vector<float> Cov = lazyToolsNoZS.covariances(seedCluster);
140  ss.sigmaEtaEta = ( !edm::isNotFinite(Cov[0]) ) ? sqrt(Cov[0]) : 0;
141  ss.sigmaIetaIeta = ( !edm::isNotFinite(vCov[0]) ) ? sqrt(vCov[0]) : 0;
142  ss.sigmaIphiIphi = ( !edm::isNotFinite(vCov[2]) ) ? sqrt(vCov[2]) : 0;
143  float sigmaIetaIphi = vCov[1]; // this is missing in the struct
144  ss.r9 = lazyToolsNoZS.e3x3(seedCluster) / electron.superCluster()->rawEnergy() ;
145  ss.e1x5 = lazyToolsNoZS.e1x5(seedCluster);
146  ss.e2x5Max = lazyToolsNoZS.e2x5Max(seedCluster);
147  ss.e5x5 = lazyToolsNoZS.e5x5(seedCluster);
148  // hcal stuff is not filled
149  electron.full5x5_setShowerShape(ss);
150  electron.full5x5_setSigmaIetaIphi(sigmaIetaIphi);
151  }
152 
153  }
154 
155  iEvent.put(out);
156 }
157 
159 using namespace pat;
edm::EDGetTokenT< pat::PackedCandidateCollection > pc_
void setDr04Isolation(const IsolationVariables &dr04)
Definition: GsfElectron.h:466
T getParameter(std::string const &) const
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81
StringCutObjectSelector< pat::Electron > dropPFlowClusters_
float e5x5(const reco::BasicCluster &cluster)
Ptr< typename C::value_type > refToPtr(Ref< C, typename C::value_type, refhelper::FindUsingAdvance< C, typename C::value_type > > const &ref)
Definition: RefToPtr.h:18
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:434
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
reco::SuperClusterRef superCluster() const
override the reco::GsfElectron::superCluster method, to access the internal storage of the superclust...
Definition: Electron.cc:152
StringCutObjectSelector< pat::Electron > dropIsolations_
void setAssociatedPackedPFCandidates(const edm::RefVector< pat::PackedCandidateCollection > &refvector)
References to PFCandidates linked to this object (e.g. for isolation vetos or masking before jet recl...
Definition: Electron.cc:490
void full5x5_setSigmaIetaIphi(float sigmaIetaIphi)
Definition: Electron.h:254
void setShowerShape(const ShowerShape &s)
Definition: GsfElectron.h:402
std::vector< reco::SuperCluster > superCluster_
Place to store electron&#39;s supercluster internally.
Definition: Electron.h:283
Matcher of reconstructed objects to L1 Muons.
StringCutObjectSelector< pat::Electron > dropBasicClusters_
float e3x3(const reco::BasicCluster &cluster)
void setPfIsolationVariables(const PflowIsolationVariables &iso)
Definition: GsfElectron.h:576
void setDr03Isolation(const IsolationVariables &dr03)
Definition: GsfElectron.h:465
std::vector< reco::CaloCluster > pflowBasicClusters_
Place to store electron&#39;s pflow basic clusters internally.
Definition: Electron.h:291
edm::EDGetTokenT< edm::ValueMap< std::vector< reco::PFCandidateRef > > > reco2pf_
void full5x5_setShowerShape(const ShowerShape &s)
Definition: Electron.h:253
std::vector< reco::CaloCluster > basicClusters_
Place to store electron&#39;s basic clusters internally.
Definition: Electron.h:287
StringCutObjectSelector< pat::Electron > dropExtrapolations_
int iEvent
Definition: GenABIO.cc:243
std::vector< reco::CaloCluster > preshowerClusters_
Place to store electron&#39;s preshower clusters internally.
Definition: Electron.h:289
PATElectronSlimmer(const edm::ParameterSet &iConfig)
bool isNotFinite(T x)
Definition: isFinite.h:10
bool embeddedRecHits_
True if RecHits stored internally.
Definition: Electron.h:305
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
T sqrt(T t)
Definition: SSEVec.h:48
bool embeddedSeedCluster_
True if seed cluster is stored internally.
Definition: Electron.h:301
float e2x5Max(const reco::BasicCluster &cluster)
StringCutObjectSelector< pat::Electron > dropShapes_
void setPfShowerShape(const ShowerShape &shape)
Definition: GsfElectron.h:575
tuple out
Definition: dbtoconf.py:99
EcalRecHitCollection recHits_
Place to store electron&#39;s RecHits internally (5x5 around seed+ all RecHits)
Definition: Electron.h:307
void setPackedPFCandidateCollection(const edm::RefProd< pat::PackedCandidateCollection > &refprod)
References to PFCandidates (e.g. to recompute isolation)
Definition: Electron.cc:477
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
std::vector< float > covariances(const reco::BasicCluster &cluster, float w0=4.7)
void setClassification(Classification myclass)
Definition: GsfElectron.h:660
StringCutObjectSelector< pat::Electron > dropClassifications_
bool embeddedPflowSuperCluster_
True if electron&#39;s pflowsupercluster is stored internally.
Definition: Electron.h:281
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:279
StringCutObjectSelector< pat::Electron > dropPreshowerClusters_
void setTrackExtrapolations(const TrackExtrapolations &te)
Definition: GsfElectron.h:281
float e1x5(const reco::BasicCluster &cluster)
std::vector< reco::CaloCluster > pflowPreshowerClusters_
Place to store electron&#39;s pflow preshower clusters internally.
Definition: Electron.h:293
void push_back(value_type const &ref)
Add a Ref&lt;C, T&gt; to the RefVector.
Definition: RefVector.h:64
size_type size() const
Size of the RefVector.
Definition: RefVector.h:89
void setCorrections(const Corrections &c)
Definition: GsfElectron.h:737
void setClassificationVariables(const ClassificationVariables &cv)
Definition: GsfElectron.h:659
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:295
edm::SortedCollection< EcalRecHit > EcalRecHitCollection
std::vector< reco::CaloCluster > seedCluster_
Place to store electron&#39;s seed cluster internally.
Definition: Electron.h:303