CMS 3D CMS Logo

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")),
71  reducedBarrelRecHitCollectionToken_(
72  consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("reducedBarrelRecHitCollection"))),
73  reducedEndcapRecHitCollectionToken_(
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(
105  iEvent, iSetup, reducedBarrelRecHitCollectionToken_, reducedEndcapRecHitCollectionToken_);
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)) {
144  photon.setSaturationInfo(reco::Photon::SaturationInfo());
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  }
184  photon.setAssociatedPackedPFCandidates(
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;
edm::RefProd< pat::PackedCandidateCollection >
muons2muons_cfi.photon
photon
Definition: muons2muons_cfi.py:28
electrons_cff.r9
r9
Definition: electrons_cff.py:366
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
pat::PATPhotonSlimmer::reducedEndcapRecHitCollectionToken_
const edm::EDGetTokenT< EcalRecHitCollection > reducedEndcapRecHitCollectionToken_
Definition: PATPhotonSlimmer.cc:47
pat::PATPhotonSlimmer::dropPreshowerClusters_
const StringCutObjectSelector< pat::Photon > dropPreshowerClusters_
Definition: PATPhotonSlimmer.cc:39
StringCutObjectSelector.h
EcalClusterLazyToolsT::e5x5
float e5x5(const reco::BasicCluster &cluster)
Definition: EcalClusterLazyTools.h:169
sistrip::View
View
Definition: ConstantsForView.h:26
edm::isNotFinite
constexpr bool isNotFinite(T x)
Definition: isFinite.h:9
PFCandidate.h
edm::LuminosityBlock
Definition: LuminosityBlock.h:50
edm::EDGetTokenT
Definition: EDGetToken.h:33
edm
HLT enums.
Definition: AlignableModifier.h:19
Photon.h
pat::Photon
Analysis-level Photon class.
Definition: Photon.h:46
pat::PATPhotonSlimmer::dropSuperClusters_
const StringCutObjectSelector< pat::Photon > dropSuperClusters_
Definition: PATPhotonSlimmer.cc:39
reco::Photon::SaturationInfo
Definition: Photon.h:258
EDProducer.h
edm::SortedCollection< EcalRecHit >
EcalClusterLazyTools.h
relativeConstraints.keys
keys
Definition: relativeConstraints.py:89
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
Association.h
pat::PATPhotonSlimmer::linkToPackedPF_
const bool linkToPackedPF_
Definition: PATPhotonSlimmer.cc:45
edm::Handle
Definition: AssociativeIterator.h:50
pat::PATPhotonSlimmer::modifyPhoton_
const bool modifyPhoton_
Definition: PATPhotonSlimmer.cc:49
pat::PATPhotonSlimmer::pf2pc_
const edm::EDGetTokenT< edm::Association< pat::PackedCandidateCollection > > pf2pc_
Definition: PATPhotonSlimmer.cc:43
MakerMacros.h
pat::PATPhotonSlimmer::saveNonZSClusterShapes_
const StringCutObjectSelector< pat::Photon > saveNonZSClusterShapes_
Definition: PATPhotonSlimmer.cc:46
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
l1t::PFCandidateRef
edm::Ref< l1t::PFCandidateCollection > PFCandidateRef
Definition: PFCandidate.h:58
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
pat::PATPhotonSlimmer::~PATPhotonSlimmer
~PATPhotonSlimmer() override
Definition: PATPhotonSlimmer.cc:31
EcalRecHitCollection
edm::SortedCollection< EcalRecHit > EcalRecHitCollection
Definition: EcalRecHitCollections.h:10
pat::PATPhotonSlimmer::dropRegressionData_
const StringCutObjectSelector< pat::Photon > dropRegressionData_
Definition: PATPhotonSlimmer.cc:39
pat::PATPhotonSlimmer::reco2pf_
const edm::EDGetTokenT< edm::ValueMap< std::vector< reco::PFCandidateRef > > > reco2pf_
Definition: PATPhotonSlimmer.cc:42
EcalClusterLazyToolsT
Definition: EcalClusterLazyTools.h:105
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
pat::PATPhotonSlimmer::PATPhotonSlimmer
PATPhotonSlimmer(const edm::ParameterSet &iConfig)
Definition: PATPhotonSlimmer.cc:55
Photon
Definition: Photon.py:1
EcalClusterLazyToolsT::e3x3
float e3x3(const reco::BasicCluster &cluster)
Definition: EcalClusterLazyTools.h:163
iEvent
int iEvent
Definition: GenABIO.cc:224
RefToPtr.h
edm::stream::EDProducer
Definition: EDProducer.h:38
pat::PATPhotonSlimmer::src_
const edm::EDGetTokenT< edm::View< pat::Photon > > src_
Definition: PATPhotonSlimmer.cc:37
pat::PATPhotonSlimmer::beginLuminosityBlock
void beginLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &) final
Definition: PATPhotonSlimmer.cc:87
edm::EventSetup
Definition: EventSetup.h:57
pat
Definition: HeavyIon.h:7
pat::PackedCandidateCollection
std::vector< pat::PackedCandidate > PackedCandidateCollection
Definition: PackedCandidate.h:1130
ValueMap.h
EcalClusterLazyToolsT::e1x5
float e1x5(const reco::BasicCluster &cluster)
Definition: EcalClusterLazyTools.h:151
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
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
StringCutObjectSelector< pat::Photon >
pat::PATPhotonSlimmer::dropSaturation_
const StringCutObjectSelector< pat::Photon > dropSaturation_
Definition: PATPhotonSlimmer.cc:39
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
pat::PATPhotonSlimmer::dropBasicClusters_
const StringCutObjectSelector< pat::Photon > dropBasicClusters_
Definition: PATPhotonSlimmer.cc:39
reco::CandidatePtr
edm::Ptr< Candidate > CandidatePtr
persistent reference to an object in a collection of Candidate objects
Definition: CandidateFwd.h:25
ParameterSet.h
pat::PATPhotonSlimmer::dropSeedCluster_
const StringCutObjectSelector< pat::Photon > dropSeedCluster_
Definition: PATPhotonSlimmer.cc:39
pat::PATPhotonSlimmer::pc_
const edm::EDGetTokenT< pat::PackedCandidateCollection > pc_
Definition: PATPhotonSlimmer.cc:44
edm::Event
Definition: Event.h:73
pat::PATPhotonSlimmer
slimmer of PAT Taus
Definition: PATPhotonSlimmer.cc:28
crabWrapper.key
key
Definition: crabWrapper.py:19
pat::PATPhotonSlimmer::photonModifier_
std::unique_ptr< pat::ObjectModifier< pat::Photon > > photonModifier_
Definition: PATPhotonSlimmer.cc:50
edm::HandleBase::id
ProductID id() const
Definition: HandleBase.cc:13
edm::InputTag
Definition: InputTag.h:15
pat::PATPhotonSlimmer::dropRecHits_
const StringCutObjectSelector< pat::Photon > dropRecHits_
Definition: PATPhotonSlimmer.cc:39
pat::PATPhotonSlimmer::reducedBarrelRecHitCollectionToken_
const edm::EDGetTokenT< EcalRecHitCollection > reducedBarrelRecHitCollectionToken_
Definition: PATPhotonSlimmer.cc:47
PFCandidateFwd.h
pat::PATPhotonSlimmer::produce
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
Definition: PATPhotonSlimmer.cc:89