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_;
52  };
53 
54 } // namespace pat
55 
57  : src_(consumes<edm::View<pat::Photon>>(iConfig.getParameter<edm::InputTag>("src"))),
58  dropSuperClusters_(iConfig.getParameter<std::string>("dropSuperCluster")),
59  dropBasicClusters_(iConfig.getParameter<std::string>("dropBasicClusters")),
60  dropPreshowerClusters_(iConfig.getParameter<std::string>("dropPreshowerClusters")),
61  dropSeedCluster_(iConfig.getParameter<std::string>("dropSeedCluster")),
62  dropRecHits_(iConfig.getParameter<std::string>("dropRecHits")),
63  dropSaturation_(iConfig.getParameter<std::string>("dropSaturation")),
64  dropRegressionData_(iConfig.getParameter<std::string>("dropRegressionData")),
65  reco2pf_(mayConsume<edm::ValueMap<std::vector<reco::PFCandidateRef>>>(
66  iConfig.getParameter<edm::InputTag>("recoToPFMap"))),
67  pf2pc_(mayConsume<edm::Association<pat::PackedCandidateCollection>>(
68  iConfig.getParameter<edm::InputTag>("packedPFCandidates"))),
69  pc_(mayConsume<pat::PackedCandidateCollection>(iConfig.getParameter<edm::InputTag>("packedPFCandidates"))),
70  linkToPackedPF_(iConfig.getParameter<bool>("linkToPackedPFCandidates")),
71  saveNonZSClusterShapes_(iConfig.getParameter<std::string>("saveNonZSClusterShapes")),
72  reducedBarrelRecHitCollectionToken_(
73  consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("reducedBarrelRecHitCollection"))),
74  reducedEndcapRecHitCollectionToken_(
75  consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("reducedEndcapRecHitCollection"))),
76  modifyPhoton_(iConfig.getParameter<bool>("modifyPhotons")),
77  ecalClusterToolsESGetTokens_{consumesCollector()} {
78  if (modifyPhoton_) {
79  const edm::ParameterSet& mod_config = iConfig.getParameter<edm::ParameterSet>("modifierConfig");
80  photonModifier_ = std::make_unique<pat::ObjectModifier<pat::Photon>>(mod_config, consumesCollector());
81  }
82 
83  mayConsume<EcalRecHitCollection>(edm::InputTag("reducedEcalRecHitsEB"));
84  mayConsume<EcalRecHitCollection>(edm::InputTag("reducedEcalRecHitsEE"));
85 
86  produces<std::vector<pat::Photon>>();
87 }
88 
90 
92  using namespace edm;
93  using namespace std;
94 
96  iEvent.getByToken(src_, src);
97 
101  if (linkToPackedPF_) {
102  iEvent.getByToken(reco2pf_, reco2pf);
103  iEvent.getByToken(pf2pc_, pf2pc);
104  iEvent.getByToken(pc_, pc);
105  }
106  noZS::EcalClusterLazyTools lazyToolsNoZS(iEvent,
107  ecalClusterToolsESGetTokens_.get(iSetup),
108  reducedBarrelRecHitCollectionToken_,
109  reducedEndcapRecHitCollectionToken_);
110 
111  auto out = std::make_unique<std::vector<pat::Photon>>();
112  out->reserve(src->size());
113 
114  if (modifyPhoton_) {
115  photonModifier_->setEvent(iEvent);
116  }
117  if (modifyPhoton_)
118  photonModifier_->setEventContent(iSetup);
119 
120  std::vector<unsigned int> keys;
121  for (View<pat::Photon>::const_iterator it = src->begin(), ed = src->end(); it != ed; ++it) {
122  out->push_back(*it);
123  pat::Photon& photon = out->back();
124 
125  if (modifyPhoton_) {
126  photonModifier_->modify(photon);
127  }
128 
129  if (dropSuperClusters_(photon)) {
130  photon.superCluster_.clear();
131  photon.embeddedSuperCluster_ = false;
132  }
133  if (dropBasicClusters_(photon)) {
134  photon.basicClusters_.clear();
135  }
136  if (dropPreshowerClusters_(photon)) {
137  photon.preshowerClusters_.clear();
138  }
139  if (dropSeedCluster_(photon)) {
140  photon.seedCluster_.clear();
141  photon.embeddedSeedCluster_ = false;
142  }
143  if (dropRecHits_(photon)) {
144  photon.recHits_ = EcalRecHitCollection();
145  photon.embeddedRecHits_ = false;
146  }
147  if (dropSaturation_(photon)) {
148  photon.setSaturationInfo(reco::Photon::SaturationInfo());
149  }
150  if (dropRegressionData_(photon)) {
151  photon.setEMax(0);
152  photon.setE2nd(0);
153  photon.setE3x3(0);
154  photon.setETop(0);
155  photon.setEBottom(0);
156  photon.setELeft(0);
157  photon.setERight(0);
158  photon.setSee(0);
159  photon.setSep(0);
160  photon.setSpp(0);
161  photon.setMaxDR(0);
162  photon.setMaxDRDPhi(0);
163  photon.setMaxDRDEta(0);
164  photon.setMaxDRRawEnergy(0);
165  photon.setSubClusRawE1(0);
166  photon.setSubClusRawE2(0);
167  photon.setSubClusRawE3(0);
168  photon.setSubClusDPhi1(0);
169  photon.setSubClusDPhi2(0);
170  photon.setSubClusDPhi3(0);
171  photon.setSubClusDEta1(0);
172  photon.setSubClusDEta2(0);
173  photon.setSubClusDEta3(0);
174  photon.setCryPhi(0);
175  photon.setCryEta(0);
176  photon.setIEta(0);
177  photon.setIPhi(0);
178  }
179 
180  if (linkToPackedPF_) {
181  //std::cout << " PAT photon in " << src.id() << " comes from " << photon.refToOrig_.id() << ", " << photon.refToOrig_.key() << std::endl;
182  keys.clear();
183  for (auto const& pf : (*reco2pf)[photon.refToOrig_]) {
184  if (pf2pc->contains(pf.id())) {
185  keys.push_back((*pf2pc)[pf].key());
186  }
187  }
188  photon.setAssociatedPackedPFCandidates(
190  //std::cout << "Photon with pt " << photon.pt() << " associated to " << photon.associatedPackedFCandidateIndices_.size() << " PF Candidates\n";
191  //if there's just one PF Cand then it's me, otherwise I have no univoque parent so my ref will be null
192  if (keys.size() == 1) {
193  photon.refToOrig_ = photon.sourceCandidatePtr(0);
194  } else {
195  photon.refToOrig_ = reco::CandidatePtr(pc.id());
196  }
197  }
198  if (saveNonZSClusterShapes_(photon)) {
199  const auto& vCov = lazyToolsNoZS.localCovariances(*(photon.superCluster()->seed()));
200  float r9 = lazyToolsNoZS.e3x3(*(photon.superCluster()->seed())) / photon.superCluster()->rawEnergy();
201  float sigmaIetaIeta = (!edm::isNotFinite(vCov[0])) ? sqrt(vCov[0]) : 0;
202  float sigmaIetaIphi = vCov[1];
203  float sigmaIphiIphi = (!edm::isNotFinite(vCov[2])) ? sqrt(vCov[2]) : 0;
204  float e15o55 =
205  lazyToolsNoZS.e1x5(*(photon.superCluster()->seed())) / lazyToolsNoZS.e5x5(*(photon.superCluster()->seed()));
206  photon.addUserFloat("sigmaIetaIeta_NoZS", sigmaIetaIeta);
207  photon.addUserFloat("sigmaIetaIphi_NoZS", sigmaIetaIphi);
208  photon.addUserFloat("sigmaIphiIphi_NoZS", sigmaIphiIphi);
209  photon.addUserFloat("r9_NoZS", r9);
210  photon.addUserFloat("e1x5_over_e5x5_NoZS", e15o55);
211  }
212  }
213 
214  iEvent.put(std::move(out));
215 }
216 
218 using namespace pat;
edm::RefProd< pat::PackedCandidateCollection >
muons2muons_cfi.photon
photon
Definition: muons2muons_cfi.py:28
electrons_cff.r9
r9
Definition: electrons_cff.py:360
ObjectModifier.h
electrons_cff.bool
bool
Definition: electrons_cff.py:366
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
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
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89301
reco::Photon::SaturationInfo
Definition: Photon.h:299
EDProducer.h
edm::SortedCollection< EcalRecHit >
EcalClusterLazyTools.h
relativeConstraints.keys
keys
Definition: relativeConstraints.py:89
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:46
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
EcalClusterLazyToolsBase::ESGetTokens
Definition: EcalClusterLazyTools.h:55
pat::PATPhotonSlimmer::ecalClusterToolsESGetTokens_
const EcalClusterLazyTools::ESGetTokens ecalClusterToolsESGetTokens_
Definition: PATPhotonSlimmer.cc:51
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:137
edm::ParameterSet
Definition: ParameterSet.h:47
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:56
Photon
Definition: Photon.py:1
iEvent
int iEvent
Definition: GenABIO.cc:224
RefToPtr.h
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
edm::stream::EDProducer
Definition: EDProducer.h:36
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:89
edm::EventSetup
Definition: EventSetup.h:58
pat
Definition: HeavyIon.h:7
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
pat::PackedCandidateCollection
std::vector< pat::PackedCandidate > PackedCandidateCollection
Definition: PackedCandidate.h:1131
ValueMap.h
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 >
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
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:29
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:91