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 
32  void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override;
33 
34  private:
36 
39 
43  const bool linkToPackedPF_;
47  const bool modifyPhoton_;
48  std::unique_ptr<pat::ObjectModifier<pat::Photon>> photonModifier_;
50  };
51 
52 } // namespace pat
53 
55  : src_(consumes<edm::View<pat::Photon>>(iConfig.getParameter<edm::InputTag>("src"))),
56  dropSuperClusters_(iConfig.getParameter<std::string>("dropSuperCluster")),
57  dropBasicClusters_(iConfig.getParameter<std::string>("dropBasicClusters")),
58  dropPreshowerClusters_(iConfig.getParameter<std::string>("dropPreshowerClusters")),
59  dropSeedCluster_(iConfig.getParameter<std::string>("dropSeedCluster")),
60  dropRecHits_(iConfig.getParameter<std::string>("dropRecHits")),
61  dropSaturation_(iConfig.getParameter<std::string>("dropSaturation")),
62  dropRegressionData_(iConfig.getParameter<std::string>("dropRegressionData")),
63  reco2pf_(mayConsume<edm::ValueMap<std::vector<reco::PFCandidateRef>>>(
64  iConfig.getParameter<edm::InputTag>("recoToPFMap"))),
65  pf2pc_(mayConsume<edm::Association<pat::PackedCandidateCollection>>(
66  iConfig.getParameter<edm::InputTag>("packedPFCandidates"))),
67  pc_(mayConsume<pat::PackedCandidateCollection>(iConfig.getParameter<edm::InputTag>("packedPFCandidates"))),
68  linkToPackedPF_(iConfig.getParameter<bool>("linkToPackedPFCandidates")),
69  saveNonZSClusterShapes_(iConfig.getParameter<std::string>("saveNonZSClusterShapes")),
70  reducedBarrelRecHitCollectionToken_(
71  consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("reducedBarrelRecHitCollection"))),
72  reducedEndcapRecHitCollectionToken_(
73  consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("reducedEndcapRecHitCollection"))),
74  modifyPhoton_(iConfig.getParameter<bool>("modifyPhotons")),
75  ecalClusterToolsESGetTokens_{consumesCollector()} {
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  using namespace edm;
89  using namespace std;
90 
92  iEvent.getByToken(src_, src);
93 
97  if (linkToPackedPF_) {
98  iEvent.getByToken(reco2pf_, reco2pf);
99  iEvent.getByToken(pf2pc_, pf2pc);
100  iEvent.getByToken(pc_, pc);
101  }
102  noZS::EcalClusterLazyTools lazyToolsNoZS(iEvent,
103  ecalClusterToolsESGetTokens_.get(iSetup),
104  reducedBarrelRecHitCollectionToken_,
105  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  const auto& 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;
Analysis-level Photon class.
Definition: Photon.h:46
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
Definition: Photon.py:1
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
ProductID id() const
Definition: HandleBase.cc:29
const edm::EDGetTokenT< EcalRecHitCollection > reducedBarrelRecHitCollectionToken_
constexpr bool isNotFinite(T x)
Definition: isFinite.h:9
std::vector< pat::PackedCandidate > PackedCandidateCollection
const StringCutObjectSelector< pat::Photon > dropSuperClusters_
const StringCutObjectSelector< pat::Photon > saveNonZSClusterShapes_
Definition: HeavyIon.h:7
int iEvent
Definition: GenABIO.cc:224
slimmer of PAT Taus
const EcalClusterLazyTools::ESGetTokens ecalClusterToolsESGetTokens_
const edm::EDGetTokenT< edm::Association< pat::PackedCandidateCollection > > pf2pc_
const edm::EDGetTokenT< edm::ValueMap< std::vector< reco::PFCandidateRef > > > reco2pf_
T sqrt(T t)
Definition: SSEVec.h:19
key
prepare the HTCondor submission files and eventually submit them
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const edm::EDGetTokenT< edm::View< pat::Photon > > src_
const StringCutObjectSelector< pat::Photon > dropRegressionData_
edm::Ptr< Candidate > CandidatePtr
persistent reference to an object in a collection of Candidate objects
Definition: CandidateFwd.h:25
PATPhotonSlimmer(const edm::ParameterSet &iConfig)
fixed size matrix
HLT enums.
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:88
const StringCutObjectSelector< pat::Photon > dropSeedCluster_
const StringCutObjectSelector< pat::Photon > dropRecHits_
std::unique_ptr< pat::ObjectModifier< pat::Photon > > photonModifier_
edm::Ref< l1t::PFCandidateCollection > PFCandidateRef
Definition: PFCandidate.h:87
const StringCutObjectSelector< pat::Photon > dropSaturation_
const edm::EDGetTokenT< EcalRecHitCollection > reducedEndcapRecHitCollectionToken_
def move(src, dest)
Definition: eostools.py:511
const StringCutObjectSelector< pat::Photon > dropBasicClusters_
const StringCutObjectSelector< pat::Photon > dropPreshowerClusters_
edm::SortedCollection< EcalRecHit > EcalRecHitCollection
const edm::EDGetTokenT< pat::PackedCandidateCollection > pc_