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 
22 
23 namespace pat {
24 
26  public:
27  explicit PATPhotonSlimmer(const edm::ParameterSet & iConfig);
28  virtual ~PATPhotonSlimmer() { }
29 
30  virtual void produce(edm::Event & iEvent, const edm::EventSetup & iSetup);
31 
32  private:
34 
36 
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  reducedBarrelRecHitCollectionToken_(consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("reducedBarrelRecHitCollection"))),
57  reducedEndcapRecHitCollectionToken_(consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("reducedEndcapRecHitCollection")))
58 {
59  produces<std::vector<pat::Photon> >();
60  if (linkToPackedPF_) {
61  reco2pf_ = consumes<edm::ValueMap<std::vector<reco::PFCandidateRef>>>(iConfig.getParameter<edm::InputTag>("recoToPFMap"));
62  pf2pc_ = consumes<edm::Association<pat::PackedCandidateCollection>>(iConfig.getParameter<edm::InputTag>("packedPFCandidates"));
63  pc_ = consumes<pat::PackedCandidateCollection>(iConfig.getParameter<edm::InputTag>("packedPFCandidates"));
64  }
65  mayConsume<EcalRecHitCollection>(edm::InputTag("reducedEcalRecHitsEB"));
66  mayConsume<EcalRecHitCollection>(edm::InputTag("reducedEcalRecHitsEE"));
67 }
68 
69 void
71  using namespace edm;
72  using namespace std;
73 
75  iEvent.getByToken(src_, src);
76 
80  if (linkToPackedPF_) {
81  iEvent.getByToken(reco2pf_, reco2pf);
82  iEvent.getByToken(pf2pc_, pf2pc);
83  iEvent.getByToken(pc_, pc);
84  }
85  noZS::EcalClusterLazyTools lazyToolsNoZS(iEvent, iSetup, reducedBarrelRecHitCollectionToken_, reducedEndcapRecHitCollectionToken_);
86 
87  auto_ptr<vector<pat::Photon> > out(new vector<pat::Photon>());
88  out->reserve(src->size());
89 
90  std::vector<unsigned int> keys;
91  for (View<pat::Photon>::const_iterator it = src->begin(), ed = src->end(); it != ed; ++it) {
92  out->push_back(*it);
93  pat::Photon & photon = out->back();
94 
95  if (dropSuperClusters_(photon)) { photon.superCluster_.clear(); photon.embeddedSuperCluster_ = false; }
96  if (dropBasicClusters_(photon)) { photon.basicClusters_.clear(); }
97  if (dropPreshowerClusters_(photon)) { photon.preshowerClusters_.clear(); }
98  if (dropSeedCluster_(photon)) { photon.seedCluster_.clear(); photon.embeddedSeedCluster_ = false; }
99  if (dropRecHits_(photon)) { photon.recHits_ = EcalRecHitCollection(); photon.embeddedRecHits_ = false; }
100 
101  if (linkToPackedPF_) {
102  //std::cout << " PAT photon in " << src.id() << " comes from " << photon.refToOrig_.id() << ", " << photon.refToOrig_.key() << std::endl;
103  keys.clear();
104  for(auto const& pf: (*reco2pf)[photon.refToOrig_]) {
105  if( pf2pc->contains(pf.id()) ) {
106  keys.push_back( (*pf2pc)[pf].key());
107  }
108  }
110  keys.begin(), keys.end());
111  //std::cout << "Photon with pt " << photon.pt() << " associated to " << photon.associatedPackedFCandidateIndices_.size() << " PF Candidates\n";
112  //if there's just one PF Cand then it's me, otherwise I have no univoque parent so my ref will be null
113  if (keys.size() == 1) {
114  photon.refToOrig_ = photon.sourceCandidatePtr(0);
115  } else {
116  photon.refToOrig_ = reco::CandidatePtr(pc.id());
117  }
118  }
119  if (saveNonZSClusterShapes_(photon)) {
120  std::vector<float> vCov = lazyToolsNoZS.localCovariances(*( photon.superCluster()->seed()));
121  float r9 = lazyToolsNoZS.e3x3( *( photon.superCluster()->seed())) / photon.superCluster()->rawEnergy() ;
122  float sigmaIetaIeta = ( !edm::isNotFinite(vCov[0]) ) ? sqrt(vCov[0]) : 0;
123  float sigmaIetaIphi = vCov[1];
124  float sigmaIphiIphi = ( !edm::isNotFinite(vCov[2]) ) ? sqrt(vCov[2]) : 0;
125  float e15o55 = lazyToolsNoZS.e1x5( *( photon.superCluster()->seed()) ) / lazyToolsNoZS.e5x5( *( photon.superCluster()->seed()) );
126  photon.addUserFloat("sigmaIetaIeta_NoZS", sigmaIetaIeta);
127  photon.addUserFloat("sigmaIetaIphi_NoZS", sigmaIetaIphi);
128  photon.addUserFloat("sigmaIphiIphi_NoZS", sigmaIphiIphi);
129  photon.addUserFloat("r9_NoZS", r9);
130  photon.addUserFloat("e1x5_over_e5x5_NoZS", e15o55);
131  }
132  }
133 
134  iEvent.put(out);
135 }
136 
138 using namespace pat;
T getParameter(std::string const &) const
StringCutObjectSelector< pat::Photon > dropSeedCluster_
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 ...
float e5x5(const reco::BasicCluster &cluster)
StringCutObjectSelector< pat::Photon > dropPreshowerClusters_
edm::EDGetTokenT< edm::View< pat::Photon > > src_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:449
StringCutObjectSelector< pat::Photon > dropSuperClusters_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
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:308
std::vector< reco::SuperCluster > superCluster_
Definition: Photon.h:329
std::vector< reco::CaloCluster > preshowerClusters_
Place to store electron&#39;s preshower clusters internally.
Definition: Photon.h:335
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:339
StringCutObjectSelector< pat::Photon > dropRecHits_
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
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
void addUserFloat(const std::string &label, float data)
Set user-defined float.
Definition: PATObject.h:765
T sqrt(T t)
Definition: SSEVec.h:48
edm::EDGetTokenT< EcalRecHitCollection > reducedEndcapRecHitCollectionToken_
edm::EDGetTokenT< EcalRecHitCollection > reducedBarrelRecHitCollectionToken_
bool embeddedSuperCluster_
Definition: Photon.h:328
tuple out
Definition: dbtoconf.py:99
EcalRecHitCollection recHits_
Place to store electron&#39;s RecHits internally (5x5 around seed+ all RecHits)
Definition: Photon.h:343
bool embeddedRecHits_
True if RecHits stored internally.
Definition: Photon.h:341
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)
edm::EDGetTokenT< edm::Association< pat::PackedCandidateCollection > > pf2pc_
PATPhotonSlimmer(const edm::ParameterSet &iConfig)
edm::EDGetTokenT< pat::PackedCandidateCollection > pc_
StringCutObjectSelector< pat::Photon > saveNonZSClusterShapes_
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:337
virtual void produce(edm::Event &iEvent, const edm::EventSetup &iSetup)
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:333
edm::SortedCollection< EcalRecHit > EcalRecHitCollection