test
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  virtual ~PATPhotonSlimmer() { }
32 
33  virtual void produce(edm::Event & iEvent, const edm::EventSetup & iSetup) override;
34  virtual void beginLuminosityBlock(const edm::LuminosityBlock&, const edm::EventSetup&) override final;
35 
36  private:
37  const edm::EDGetTokenT<edm::View<pat::Photon> > src_;
38 
40 
41  const edm::EDGetTokenT<edm::ValueMap<std::vector<reco::PFCandidateRef> > > reco2pf_;
42  const edm::EDGetTokenT<edm::Association<pat::PackedCandidateCollection> > pf2pc_;
43  const edm::EDGetTokenT<pat::PackedCandidateCollection> pc_;
48  std::unique_ptr<pat::ObjectModifier<pat::Photon> > photonModifier_;
49  };
50 
51 } // namespace
52 
54  src_(consumes<edm::View<pat::Photon> >(iConfig.getParameter<edm::InputTag>("src"))),
55  dropSuperClusters_(iConfig.getParameter<std::string>("dropSuperCluster")),
56  dropBasicClusters_(iConfig.getParameter<std::string>("dropBasicClusters")),
57  dropPreshowerClusters_(iConfig.getParameter<std::string>("dropPreshowerClusters")),
58  dropSeedCluster_(iConfig.getParameter<std::string>("dropSeedCluster")),
59  dropRecHits_(iConfig.getParameter<std::string>("dropRecHits")),
60  reco2pf_(mayConsume<edm::ValueMap<std::vector<reco::PFCandidateRef> > >(iConfig.getParameter<edm::InputTag>("recoToPFMap"))),
61  pf2pc_(mayConsume<edm::Association<pat::PackedCandidateCollection>>(iConfig.getParameter<edm::InputTag>("packedPFCandidates"))),
62  pc_(mayConsume<pat::PackedCandidateCollection>(iConfig.getParameter<edm::InputTag>("packedPFCandidates"))),
63  linkToPackedPF_(iConfig.getParameter<bool>("linkToPackedPFCandidates")),
64  saveNonZSClusterShapes_(iConfig.getParameter<std::string>("saveNonZSClusterShapes")),
65  reducedBarrelRecHitCollectionToken_(consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("reducedBarrelRecHitCollection"))),
66  reducedEndcapRecHitCollectionToken_(consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("reducedEndcapRecHitCollection"))),
67  modifyPhoton_(iConfig.getParameter<bool>("modifyPhotons"))
68 {
70  if( modifyPhoton_ ) {
71  const edm::ParameterSet& mod_config = iConfig.getParameter<edm::ParameterSet>("modifierConfig");
72  photonModifier_.reset(new pat::ObjectModifier<pat::Photon>(mod_config) );
73  photonModifier_->setConsumes(sumes);
74  } else {
75  photonModifier_.reset(nullptr);
76  }
77 
78  mayConsume<EcalRecHitCollection>(edm::InputTag("reducedEcalRecHitsEB"));
79  mayConsume<EcalRecHitCollection>(edm::InputTag("reducedEcalRecHitsEE"));
80 
81  produces<std::vector<pat::Photon> >();
82 }
83 
84 void
86 }
87 
88 void
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  }
105 
106  auto out = std::make_unique<std::vector<pat::Photon>>();
107  out->reserve(src->size());
108 
109  if( modifyPhoton_ ) { photonModifier_->setEvent(iEvent); }
110  if( modifyPhoton_ ) photonModifier_->setEventContent(iSetup);
111 
112 
113  std::vector<unsigned int> keys;
114  for (View<pat::Photon>::const_iterator it = src->begin(), ed = src->end(); it != ed; ++it) {
115  out->push_back(*it);
116  pat::Photon & photon = out->back();
117 
118  if( modifyPhoton_ ) { photonModifier_->modify(photon); }
119 
120  if (dropSuperClusters_(photon)) { photon.superCluster_.clear(); photon.embeddedSuperCluster_ = false; }
121  if (dropBasicClusters_(photon)) { photon.basicClusters_.clear(); }
122  if (dropPreshowerClusters_(photon)) { photon.preshowerClusters_.clear(); }
123  if (dropSeedCluster_(photon)) { photon.seedCluster_.clear(); photon.embeddedSeedCluster_ = false; }
124  if (dropRecHits_(photon)) { photon.recHits_ = EcalRecHitCollection(); photon.embeddedRecHits_ = false; }
125 
126  if (linkToPackedPF_) {
127  //std::cout << " PAT photon in " << src.id() << " comes from " << photon.refToOrig_.id() << ", " << photon.refToOrig_.key() << std::endl;
128  keys.clear();
129  for(auto const& pf: (*reco2pf)[photon.refToOrig_]) {
130  if( pf2pc->contains(pf.id()) ) {
131  keys.push_back( (*pf2pc)[pf].key());
132  }
133  }
135  keys.begin(), keys.end());
136  //std::cout << "Photon with pt " << photon.pt() << " associated to " << photon.associatedPackedFCandidateIndices_.size() << " PF Candidates\n";
137  //if there's just one PF Cand then it's me, otherwise I have no univoque parent so my ref will be null
138  if (keys.size() == 1) {
139  photon.refToOrig_ = photon.sourceCandidatePtr(0);
140  } else {
141  photon.refToOrig_ = reco::CandidatePtr(pc.id());
142  }
143  }
144  if (saveNonZSClusterShapes_(photon)) {
145  std::vector<float> vCov = lazyToolsNoZS.localCovariances(*( photon.superCluster()->seed()));
146  float r9 = lazyToolsNoZS.e3x3( *( photon.superCluster()->seed())) / photon.superCluster()->rawEnergy() ;
147  float sigmaIetaIeta = ( !edm::isNotFinite(vCov[0]) ) ? sqrt(vCov[0]) : 0;
148  float sigmaIetaIphi = vCov[1];
149  float sigmaIphiIphi = ( !edm::isNotFinite(vCov[2]) ) ? sqrt(vCov[2]) : 0;
150  float e15o55 = lazyToolsNoZS.e1x5( *( photon.superCluster()->seed()) ) / lazyToolsNoZS.e5x5( *( photon.superCluster()->seed()) );
151  photon.addUserFloat("sigmaIetaIeta_NoZS", sigmaIetaIeta);
152  photon.addUserFloat("sigmaIetaIphi_NoZS", sigmaIetaIphi);
153  photon.addUserFloat("sigmaIphiIphi_NoZS", sigmaIphiIphi);
154  photon.addUserFloat("r9_NoZS", r9);
155  photon.addUserFloat("e1x5_over_e5x5_NoZS", e15o55);
156  }
157 
158  }
159 
160  iEvent.put(std::move(out));
161 }
162 
164 using namespace pat;
T getParameter(std::string const &) const
Analysis-level Photon class.
Definition: Photon.h:47
reco::SuperClusterRef superCluster() const
override the superCluster method from CaloJet, to access the internal storage of the supercluster ...
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
float e5x5(const reco::BasicCluster &cluster)
virtual void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
const edm::EDGetTokenT< EcalRecHitCollection > reducedBarrelRecHitCollectionToken_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
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:322
const StringCutObjectSelector< pat::Photon > dropSuperClusters_
std::vector< reco::SuperCluster > superCluster_
Definition: Photon.h:343
void addUserFloat(const std::string &label, float data, const bool overwrite=false)
Set user-defined float.
Definition: PATObject.h:813
std::vector< reco::CaloCluster > preshowerClusters_
Place to store electron&#39;s preshower clusters internally.
Definition: Photon.h:349
float e3x3(const reco::BasicCluster &cluster)
const StringCutObjectSelector< pat::Photon > saveNonZSClusterShapes_
std::vector< reco::CaloCluster > seedCluster_
Place to store electron&#39;s seed cluster internally.
Definition: Photon.h:353
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
int iEvent
Definition: GenABIO.cc:230
slimmer of PAT Taus
bool isNotFinite(T x)
Definition: isFinite.h:10
reco::CandidatePtr sourceCandidatePtr(size_type i) const
get the source candidate pointer with index i
const edm::EDGetTokenT< edm::Association< pat::PackedCandidateCollection > > pf2pc_
const edm::EDGetTokenT< edm::ValueMap< std::vector< reco::PFCandidateRef > > > reco2pf_
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
T sqrt(T t)
Definition: SSEVec.h:18
def move
Definition: eostools.py:510
edm::Ref< PFCandidateCollection > PFCandidateRef
persistent reference to a PFCandidate
const edm::EDGetTokenT< edm::View< pat::Photon > > src_
string key
FastSim: produces sample of signal events, overlayed with premixed minbias events.
bool embeddedSuperCluster_
Definition: Photon.h:342
virtual void beginLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &) overridefinal
EcalRecHitCollection recHits_
Place to store electron&#39;s RecHits internally (5x5 around seed+ all RecHits)
Definition: Photon.h:357
bool embeddedRecHits_
True if RecHits stored internally.
Definition: Photon.h:355
edm::Ptr< Candidate > CandidatePtr
persistent reference to an object in a collection of Candidate objects
Definition: CandidateFwd.h:25
std::vector< float > localCovariances(const reco::BasicCluster &cluster, float w0=4.7)
string const
Definition: compareJSON.py:14
PATPhotonSlimmer(const edm::ParameterSet &iConfig)
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81
float e1x5(const reco::BasicCluster &cluster)
bool embeddedSeedCluster_
True if seed cluster is stored internally.
Definition: Photon.h:351
const StringCutObjectSelector< pat::Photon > dropSeedCluster_
const StringCutObjectSelector< pat::Photon > dropRecHits_
std::unique_ptr< pat::ObjectModifier< pat::Photon > > photonModifier_
EDGetTokenT< ProductType > mayConsume(edm::InputTag const &tag)
const edm::EDGetTokenT< EcalRecHitCollection > reducedEndcapRecHitCollectionToken_
edm::Ptr< reco::Candidate > refToOrig_
Definition: PATObject.h:421
const StringCutObjectSelector< pat::Photon > dropBasicClusters_
const StringCutObjectSelector< pat::Photon > dropPreshowerClusters_
std::vector< reco::CaloCluster > basicClusters_
Place to store electron&#39;s basic clusters internally.
Definition: Photon.h:347
edm::SortedCollection< EcalRecHit > EcalRecHitCollection
const edm::EDGetTokenT< pat::PackedCandidateCollection > pc_