CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PATPhotonSlimmer.cc
Go to the documentation of this file.
1 
10 
13 
15 
17 
25 
26 namespace pat {
27 
29  public:
30  explicit PATPhotonSlimmer(const edm::ParameterSet& iConfig);
31  ~PATPhotonSlimmer() override {}
32 
33  void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override;
35 
36  private:
38 
41 
45  const bool linkToPackedPF_;
49  const bool modifyPhoton_;
50  std::unique_ptr<pat::ObjectModifier<pat::Photon>> photonModifier_;
51  };
52 
53 } // namespace pat
54 
56  : src_(consumes<edm::View<pat::Photon>>(iConfig.getParameter<edm::InputTag>("src"))),
57  dropSuperClusters_(iConfig.getParameter<std::string>("dropSuperCluster")),
58  dropBasicClusters_(iConfig.getParameter<std::string>("dropBasicClusters")),
59  dropPreshowerClusters_(iConfig.getParameter<std::string>("dropPreshowerClusters")),
60  dropSeedCluster_(iConfig.getParameter<std::string>("dropSeedCluster")),
61  dropRecHits_(iConfig.getParameter<std::string>("dropRecHits")),
62  dropSaturation_(iConfig.getParameter<std::string>("dropSaturation")),
63  dropRegressionData_(iConfig.getParameter<std::string>("dropRegressionData")),
64  reco2pf_(mayConsume<edm::ValueMap<std::vector<reco::PFCandidateRef>>>(
65  iConfig.getParameter<edm::InputTag>("recoToPFMap"))),
66  pf2pc_(mayConsume<edm::Association<pat::PackedCandidateCollection>>(
67  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")),
72  consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("reducedBarrelRecHitCollection"))),
74  consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("reducedEndcapRecHitCollection"))),
75  modifyPhoton_(iConfig.getParameter<bool>("modifyPhotons")) {
76  if (modifyPhoton_) {
77  const edm::ParameterSet& mod_config = iConfig.getParameter<edm::ParameterSet>("modifierConfig");
78  photonModifier_ = std::make_unique<pat::ObjectModifier<pat::Photon>>(mod_config, consumesCollector());
79  }
80 
81  mayConsume<EcalRecHitCollection>(edm::InputTag("reducedEcalRecHitsEB"));
82  mayConsume<EcalRecHitCollection>(edm::InputTag("reducedEcalRecHitsEE"));
83 
84  produces<std::vector<pat::Photon>>();
85 }
86 
88 
90  using namespace edm;
91  using namespace std;
92 
94  iEvent.getByToken(src_, src);
95 
99  if (linkToPackedPF_) {
100  iEvent.getByToken(reco2pf_, reco2pf);
101  iEvent.getByToken(pf2pc_, pf2pc);
102  iEvent.getByToken(pc_, pc);
103  }
104  noZS::EcalClusterLazyTools lazyToolsNoZS(
106 
107  auto out = std::make_unique<std::vector<pat::Photon>>();
108  out->reserve(src->size());
109 
110  if (modifyPhoton_) {
111  photonModifier_->setEvent(iEvent);
112  }
113  if (modifyPhoton_)
114  photonModifier_->setEventContent(iSetup);
115 
116  std::vector<unsigned int> keys;
117  for (View<pat::Photon>::const_iterator it = src->begin(), ed = src->end(); it != ed; ++it) {
118  out->push_back(*it);
119  pat::Photon& photon = out->back();
120 
121  if (modifyPhoton_) {
122  photonModifier_->modify(photon);
123  }
124 
125  if (dropSuperClusters_(photon)) {
126  photon.superCluster_.clear();
127  photon.embeddedSuperCluster_ = false;
128  }
129  if (dropBasicClusters_(photon)) {
130  photon.basicClusters_.clear();
131  }
132  if (dropPreshowerClusters_(photon)) {
133  photon.preshowerClusters_.clear();
134  }
135  if (dropSeedCluster_(photon)) {
136  photon.seedCluster_.clear();
137  photon.embeddedSeedCluster_ = false;
138  }
139  if (dropRecHits_(photon)) {
140  photon.recHits_ = EcalRecHitCollection();
141  photon.embeddedRecHits_ = false;
142  }
143  if (dropSaturation_(photon)) {
145  }
146  if (dropRegressionData_(photon)) {
147  photon.setEMax(0);
148  photon.setE2nd(0);
149  photon.setE3x3(0);
150  photon.setETop(0);
151  photon.setEBottom(0);
152  photon.setELeft(0);
153  photon.setERight(0);
154  photon.setSee(0);
155  photon.setSep(0);
156  photon.setSpp(0);
157  photon.setMaxDR(0);
158  photon.setMaxDRDPhi(0);
159  photon.setMaxDRDEta(0);
160  photon.setMaxDRRawEnergy(0);
161  photon.setSubClusRawE1(0);
162  photon.setSubClusRawE2(0);
163  photon.setSubClusRawE3(0);
164  photon.setSubClusDPhi1(0);
165  photon.setSubClusDPhi2(0);
166  photon.setSubClusDPhi3(0);
167  photon.setSubClusDEta1(0);
168  photon.setSubClusDEta2(0);
169  photon.setSubClusDEta3(0);
170  photon.setCryPhi(0);
171  photon.setCryEta(0);
172  photon.setIEta(0);
173  photon.setIPhi(0);
174  }
175 
176  if (linkToPackedPF_) {
177  //std::cout << " PAT photon in " << src.id() << " comes from " << photon.refToOrig_.id() << ", " << photon.refToOrig_.key() << std::endl;
178  keys.clear();
179  for (auto const& pf : (*reco2pf)[photon.refToOrig_]) {
180  if (pf2pc->contains(pf.id())) {
181  keys.push_back((*pf2pc)[pf].key());
182  }
183  }
185  edm::RefProd<pat::PackedCandidateCollection>(pc), keys.begin(), keys.end());
186  //std::cout << "Photon with pt " << photon.pt() << " associated to " << photon.associatedPackedFCandidateIndices_.size() << " PF Candidates\n";
187  //if there's just one PF Cand then it's me, otherwise I have no univoque parent so my ref will be null
188  if (keys.size() == 1) {
189  photon.refToOrig_ = photon.sourceCandidatePtr(0);
190  } else {
191  photon.refToOrig_ = reco::CandidatePtr(pc.id());
192  }
193  }
194  if (saveNonZSClusterShapes_(photon)) {
195  std::vector<float> vCov = lazyToolsNoZS.localCovariances(*(photon.superCluster()->seed()));
196  float r9 = lazyToolsNoZS.e3x3(*(photon.superCluster()->seed())) / photon.superCluster()->rawEnergy();
197  float sigmaIetaIeta = (!edm::isNotFinite(vCov[0])) ? sqrt(vCov[0]) : 0;
198  float sigmaIetaIphi = vCov[1];
199  float sigmaIphiIphi = (!edm::isNotFinite(vCov[2])) ? sqrt(vCov[2]) : 0;
200  float e15o55 =
201  lazyToolsNoZS.e1x5(*(photon.superCluster()->seed())) / lazyToolsNoZS.e5x5(*(photon.superCluster()->seed()));
202  photon.addUserFloat("sigmaIetaIeta_NoZS", sigmaIetaIeta);
203  photon.addUserFloat("sigmaIetaIphi_NoZS", sigmaIetaIphi);
204  photon.addUserFloat("sigmaIphiIphi_NoZS", sigmaIphiIphi);
205  photon.addUserFloat("r9_NoZS", r9);
206  photon.addUserFloat("e1x5_over_e5x5_NoZS", e15o55);
207  }
208  }
209 
210  iEvent.put(std::move(out));
211 }
212 
214 using namespace pat;
T getParameter(std::string const &) const
void setSpp(float s)
Definition: Photon.h:266
Analysis-level Photon class.
Definition: Photon.h:46
void setIEta(float i)
Definition: Photon.h:308
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
Definition: Photon.py:1
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
const edm::EDGetTokenT< EcalRecHitCollection > reducedBarrelRecHitCollectionToken_
void setSubClusDPhi3(float s)
Definition: Photon.h:291
ProductID id() const
Definition: HandleBase.cc:13
void setE2nd(float e)
Definition: Photon.h:251
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
void setSee(float s)
Definition: Photon.h:264
constexpr bool isNotFinite(T x)
Definition: isFinite.h:9
void setMaxDRRawEnergy(float m)
Definition: Photon.h:277
std::vector< pat::PackedCandidate > PackedCandidateCollection
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: Photon.h:317
void setSubClusDPhi2(float s)
Definition: Photon.h:289
void setSaturationInfo(const SaturationInfo &s)
Definition: Photon.h:268
const StringCutObjectSelector< pat::Photon > dropSuperClusters_
std::vector< reco::SuperCluster > superCluster_
Definition: Photon.h:335
void addUserFloat(const std::string &label, float data, const bool overwrite=false)
Set user-defined float.
Definition: PATObject.h:897
std::vector< reco::CaloCluster > preshowerClusters_
Place to store electron&#39;s preshower clusters internally.
Definition: Photon.h:341
void setIPhi(float i)
Definition: Photon.h:306
const StringCutObjectSelector< pat::Photon > saveNonZSClusterShapes_
reco::SuperClusterRef superCluster() const override
override the superCluster method from CaloJet, to access the internal storage of the supercluster ...
std::vector< reco::CaloCluster > seedCluster_
Place to store electron&#39;s seed cluster internally.
Definition: Photon.h:345
Definition: HeavyIon.h:7
void setELeft(float e)
Definition: Photon.h:259
float e1x5(const reco::BasicCluster &cluster)
int iEvent
Definition: GenABIO.cc:224
void setEMax(float e)
Definition: Photon.h:249
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
float e5x5(const reco::BasicCluster &cluster)
slimmer of PAT Taus
const edm::EDGetTokenT< edm::Association< pat::PackedCandidateCollection > > pf2pc_
void setERight(float e)
Definition: Photon.h:261
const edm::EDGetTokenT< edm::ValueMap< std::vector< reco::PFCandidateRef > > > reco2pf_
void setMaxDRDEta(float m)
Definition: Photon.h:275
T sqrt(T t)
Definition: SSEVec.h:19
void setETop(float e)
Definition: Photon.h:255
void setSubClusDPhi1(float s)
Definition: Photon.h:287
edm::Ref< PFCandidateCollection > PFCandidateRef
persistent reference to a PFCandidate
const edm::EDGetTokenT< edm::View< pat::Photon > > src_
void setSubClusDEta1(float s)
Definition: Photon.h:294
bool embeddedSuperCluster_
Definition: Photon.h:334
void setCryEta(float c)
Definition: Photon.h:303
const StringCutObjectSelector< pat::Photon > dropRegressionData_
EcalRecHitCollection recHits_
Place to store electron&#39;s RecHits internally (5x5 around seed+ all RecHits)
Definition: Photon.h:349
bool embeddedRecHits_
True if RecHits stored internally.
Definition: Photon.h:347
edm::Ptr< Candidate > CandidatePtr
persistent reference to an object in a collection of Candidate objects
Definition: CandidateFwd.h:25
void setCryPhi(float c)
Definition: Photon.h:301
void setSubClusDEta2(float s)
Definition: Photon.h:296
void setMaxDR(float m)
Definition: Photon.h:271
void setSubClusRawE2(float s)
Definition: Photon.h:282
float e3x3(const reco::BasicCluster &cluster)
PATPhotonSlimmer(const edm::ParameterSet &iConfig)
void beginLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &) final
void setEBottom(float e)
Definition: Photon.h:257
void setMaxDRDPhi(float m)
Definition: Photon.h:273
fixed size matrix
HLT enums.
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
void setSubClusDEta3(float s)
Definition: Photon.h:298
bool embeddedSeedCluster_
True if seed cluster is stored internally.
Definition: Photon.h:343
void setSubClusRawE1(float s)
Definition: Photon.h:280
const StringCutObjectSelector< pat::Photon > dropSeedCluster_
const StringCutObjectSelector< pat::Photon > dropRecHits_
std::unique_ptr< pat::ObjectModifier< pat::Photon > > photonModifier_
void setSubClusRawE3(float s)
Definition: Photon.h:284
reco::CandidatePtr sourceCandidatePtr(size_type i) const override
get the source candidate pointer with index i
const StringCutObjectSelector< pat::Photon > dropSaturation_
std::vector< float > localCovariances(const reco::BasicCluster &cluster, float w0=4.7)
const edm::EDGetTokenT< EcalRecHitCollection > reducedEndcapRecHitCollectionToken_
edm::Ptr< reco::Candidate > refToOrig_
Definition: PATObject.h:463
def move(src, dest)
Definition: eostools.py:511
const StringCutObjectSelector< pat::Photon > dropBasicClusters_
void setE3x3(float e)
Definition: Photon.h:253
const StringCutObjectSelector< pat::Photon > dropPreshowerClusters_
std::vector< reco::CaloCluster > basicClusters_
Place to store electron&#39;s basic clusters internally.
Definition: Photon.h:339
edm::SortedCollection< EcalRecHit > EcalRecHitCollection
void setSep(float s)
Definition: Photon.h:268
const edm::EDGetTokenT< pat::PackedCandidateCollection > pc_