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 
11 
14 
16 
23 
24 namespace pat {
25 
27  public:
28  explicit PATPhotonSlimmer(const edm::ParameterSet & iConfig);
29  virtual ~PATPhotonSlimmer() { }
30 
31  virtual void produce(edm::Event & iEvent, const edm::EventSetup & iSetup);
32 
33  private:
35 
37 
43  };
44 
45 } // namespace
46 
48  src_(consumes<edm::View<pat::Photon> >(iConfig.getParameter<edm::InputTag>("src"))),
49  dropSuperClusters_(iConfig.getParameter<std::string>("dropSuperCluster")),
50  dropBasicClusters_(iConfig.getParameter<std::string>("dropBasicClusters")),
51  dropPreshowerClusters_(iConfig.getParameter<std::string>("dropPreshowerClusters")),
52  dropSeedCluster_(iConfig.getParameter<std::string>("dropSeedCluster")),
53  dropRecHits_(iConfig.getParameter<std::string>("dropRecHits")),
54  linkToPackedPF_(iConfig.getParameter<bool>("linkToPackedPFCandidates")),
55  saveNonZSClusterShapes_(iConfig.getParameter<std::string>("saveNonZSClusterShapes"))
56 {
57  produces<std::vector<pat::Photon> >();
58  if (linkToPackedPF_) {
59  reco2pf_ = consumes<edm::ValueMap<std::vector<reco::PFCandidateRef>>>(iConfig.getParameter<edm::InputTag>("recoToPFMap"));
60  pf2pc_ = consumes<edm::Association<pat::PackedCandidateCollection>>(iConfig.getParameter<edm::InputTag>("packedPFCandidates"));
61  pc_ = consumes<pat::PackedCandidateCollection>(iConfig.getParameter<edm::InputTag>("packedPFCandidates"));
62  }
63  mayConsume<EcalRecHitCollection>(edm::InputTag("reducedEcalRecHitsEB"));
64  mayConsume<EcalRecHitCollection>(edm::InputTag("reducedEcalRecHitsEE"));
65 }
66 
67 void
69  using namespace edm;
70  using namespace std;
71 
73  iEvent.getByToken(src_, src);
74 
78  if (linkToPackedPF_) {
79  iEvent.getByToken(reco2pf_, reco2pf);
80  iEvent.getByToken(pf2pc_, pf2pc);
81  iEvent.getByToken(pc_, pc);
82  }
83  edm::InputTag reducedBarrelRecHitCollection("reducedEcalRecHitsEB");
84  edm::InputTag reducedEndcapRecHitCollection("reducedEcalRecHitsEE");
85  noZS::EcalClusterLazyTools lazyToolsNoZS(iEvent, iSetup, reducedBarrelRecHitCollection, reducedEndcapRecHitCollection);
86 
87  auto_ptr<vector<pat::Photon> > out(new vector<pat::Photon>());
88  out->reserve(src->size());
89 
90  for (View<pat::Photon>::const_iterator it = src->begin(), ed = src->end(); it != ed; ++it) {
91  out->push_back(*it);
92  pat::Photon & photon = out->back();
93 
94  if (dropSuperClusters_(photon)) { photon.superCluster_.clear(); photon.embeddedSuperCluster_ = false; }
95  if (dropBasicClusters_(photon)) { photon.basicClusters_.clear(); }
96  if (dropPreshowerClusters_(photon)) { photon.preshowerClusters_.clear(); }
97  if (dropSeedCluster_(photon)) { photon.seedCluster_.clear(); photon.embeddedSeedCluster_ = false; }
98  if (dropRecHits_(photon)) { photon.recHits_ = EcalRecHitCollection(); photon.embeddedRecHits_ = false; }
99 
100  if (linkToPackedPF_) {
102  //std::cout << " PAT photon in " << src.id() << " comes from " << photon.refToOrig_.id() << ", " << photon.refToOrig_.key() << std::endl;
104  for (const reco::PFCandidateRef & pf : (*reco2pf)[photon.refToOrig_]) {
105  if (pf2pc->contains(pf.id())) {
106  origs.push_back((*pf2pc)[pf]);
107  } //else std::cerr << " Photon linked to a PFCand in " << pf.id() << " while we expect them in " << pf2pc->ids().front().first << "\n";
108  }
109  //std::cout << "Photon with pt " << photon.pt() << " associated to " << origs.size() << " PF Candidates\n";
110  photon.setAssociatedPackedPFCandidates(origs);
111  //if there's just one PF Cand then it's me, otherwise I have no univoque parent so my ref will be null
112  if (origs.size() == 1) {
113  photon.refToOrig_ = refToPtr(origs[0]);
114  } else {
115  photon.refToOrig_ = reco::CandidatePtr(pc.id());
116  }
117  }
118  if (saveNonZSClusterShapes_(photon)) {
120  const auto & seedCluster = *photon.superCluster()->seed();
121  std::vector<float> vCov = lazyToolsNoZS.localCovariances(seedCluster);
122  std::vector<float> Cov = lazyToolsNoZS.covariances(seedCluster);
123  ss.sigmaEtaEta = ( !edm::isNotFinite(Cov[0]) ) ? sqrt(Cov[0]) : 0;
124  ss.sigmaIetaIeta = ( !edm::isNotFinite(vCov[0]) ) ? sqrt(vCov[0]) : 0;
125  //float sigmaIphiIphi = ( !edm::isNotFinite(vCov[2]) ) ? sqrt(vCov[2]) : 0;
126  //float sigmaIetaIphi = vCov[1]; // this is missing in the struct
127  ss.e1x5 = lazyToolsNoZS.e1x5(seedCluster);
128  ss.e2x5 = lazyToolsNoZS.e2x5Max(seedCluster);
129  ss.e3x3 = lazyToolsNoZS.e3x3(seedCluster);
130  ss.e5x5 = lazyToolsNoZS.e5x5(seedCluster);
131  ss.maxEnergyXtal = lazyToolsNoZS.eMax(seedCluster);
132  // hcal stuff is not filled
133  photon.full5x5_setShowerShape(ss);
134  //electron.full5x5_setSigmaIphiIphi(sigmaIphiIphi);
135  //electron.full5x5_setSigmaIetaIphi(sigmaIetaIphi);
136  }
137  }
138 
139  iEvent.put(out);
140 }
141 
143 using namespace pat;
void setAssociatedPackedPFCandidates(const edm::RefVector< pat::PackedCandidateCollection > &refvector)
References to PFCandidates linked to this object (e.g. for isolation vetos or masking before jet recl...
Definition: Photon.cc:318
T getParameter(std::string const &) const
StringCutObjectSelector< pat::Photon > dropSeedCluster_
Analysis-level Photon class.
Definition: Photon.h:47
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81
float e5x5(const reco::BasicCluster &cluster)
Ptr< typename C::value_type > refToPtr(Ref< C, typename C::value_type, refhelper::FindUsingAdvance< C, typename C::value_type > > const &ref)
Definition: RefToPtr.h:18
StringCutObjectSelector< pat::Photon > dropPreshowerClusters_
edm::EDGetTokenT< edm::View< pat::Photon > > src_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
StringCutObjectSelector< pat::Photon > dropSuperClusters_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void full5x5_setShowerShape(const ShowerShape &s)
Definition: Photon.h:321
std::vector< reco::SuperCluster > superCluster_
Definition: Photon.h:348
std::vector< reco::CaloCluster > preshowerClusters_
Place to store electron&#39;s preshower clusters internally.
Definition: Photon.h:354
float e3x3(const reco::BasicCluster &cluster)
edm::EDGetTokenT< edm::ValueMap< std::vector< reco::PFCandidateRef > > > reco2pf_
std::vector< reco::CaloCluster > seedCluster_
Place to store electron&#39;s seed cluster internally.
Definition: Photon.h:358
StringCutObjectSelector< pat::Photon > dropRecHits_
int iEvent
Definition: GenABIO.cc:243
slimmer of PAT Taus
bool isNotFinite(T x)
Definition: isFinite.h:10
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
T sqrt(T t)
Definition: SSEVec.h:48
float e2x5Max(const reco::BasicCluster &cluster)
bool embeddedSuperCluster_
Definition: Photon.h:347
tuple out
Definition: dbtoconf.py:99
EcalRecHitCollection recHits_
Place to store electron&#39;s RecHits internally (5x5 around seed+ all RecHits)
Definition: Photon.h:362
bool embeddedRecHits_
True if RecHits stored internally.
Definition: Photon.h:360
edm::Ptr< Candidate > CandidatePtr
persistent reference to an object in a collection of Candidate objects
Definition: CandidateFwd.h:25
std::vector< float > covariances(const reco::BasicCluster &cluster, float w0=4.7)
std::vector< float > localCovariances(const reco::BasicCluster &cluster, float w0=4.7)
reco::SuperClusterRef superCluster() const
override the superCluster method from CaloJet, to access the internal storage of the supercluster ...
Definition: Photon.cc:190
edm::EDGetTokenT< edm::Association< pat::PackedCandidateCollection > > pf2pc_
PATPhotonSlimmer(const edm::ParameterSet &iConfig)
float eMax(const reco::BasicCluster &cluster)
edm::EDGetTokenT< pat::PackedCandidateCollection > pc_
StringCutObjectSelector< pat::Photon > saveNonZSClusterShapes_
float e1x5(const reco::BasicCluster &cluster)
bool embeddedSeedCluster_
True if seed cluster is stored internally.
Definition: Photon.h:356
virtual void produce(edm::Event &iEvent, const edm::EventSetup &iSetup)
void push_back(value_type const &ref)
Add a Ref&lt;C, T&gt; to the RefVector.
Definition: RefVector.h:64
size_type size() const
Size of the RefVector.
Definition: RefVector.h:89
void setPackedPFCandidateCollection(const edm::RefProd< pat::PackedCandidateCollection > &refprod)
References to PFCandidates (e.g. to recompute isolation)
Definition: Photon.cc:305
StringCutObjectSelector< pat::Photon > dropBasicClusters_
edm::Ptr< reco::Candidate > refToOrig_
Definition: PATObject.h:407
std::vector< reco::CaloCluster > basicClusters_
Place to store electron&#39;s basic clusters internally.
Definition: Photon.h:352
edm::SortedCollection< EcalRecHit > EcalRecHitCollection