CMS 3D CMS Logo

GEDPhotonCoreProducer.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <vector>
3 #include <memory>
11 // Framework
31 #include <Math/VectorUtil.h>
32 #include <vector>
33 #include "TLorentzVector.h"
34 #include "TMath.h"
35 
37  conf_(config)
38 
39 {
40 
41  // use onfiguration file to setup input/output collection names
43  consumes<reco::PFCandidateCollection>(conf_.getParameter<edm::InputTag>("pfEgammaCandidates"));
45  consumes<reco::ElectronSeedCollection>(conf_.getParameter<edm::InputTag>("pixelSeedProducer"));
46 
47  GEDPhotonCoreCollection_ = conf_.getParameter<std::string>("gedPhotonCoreCollection");
48 
49 
50 
51  // Register the product
52  produces<reco::PhotonCoreCollection>(GEDPhotonCoreCollection_);
53 
54 }
55 
57 
58 
59 
60 
61 void GEDPhotonCoreProducer::produce(edm::Event &theEvent, const edm::EventSetup& theEventSetup) {
62 
63 
64  using namespace edm;
65  // nEvt_++;
66 
67  reco::PhotonCoreCollection outputPhotonCoreCollection;
68  auto outputPhotonCoreCollection_p = std::make_unique<reco::PhotonCoreCollection>();
69 
70  // Get the PF refined cluster collection
71  Handle<reco::PFCandidateCollection> pfCandidateHandle;
72  theEvent.getByToken(pfEgammaCandidates_,pfCandidateHandle);
73  if (!pfCandidateHandle.isValid()) {
74  edm::LogError("GEDPhotonCoreProducer")
75  << "Error! Can't get the pfEgammaCandidates";
76  }
77 
78 
79  // Get ElectronPixelSeeds
80  validPixelSeeds_=true;
83  theEvent.getByToken(pixelSeedProducer_, pixelSeedHandle);
84  if (!pixelSeedHandle.isValid()) {
85  validPixelSeeds_=false;
86  }
87 
88 
89 
90  // std::cout << " GEDPhotonCoreProducer::produce input PFcandidate size " << pfCandidateHandle->size() << std::endl;
91 
92 
93  // Loop over PF candidates and get only photons
94  for(unsigned int lCand=0; lCand < pfCandidateHandle->size(); lCand++) {
95  reco::PFCandidateRef candRef (reco::PFCandidateRef(pfCandidateHandle,lCand));
96 
97  // Retrieve stuff from the pfPhoton
98  reco::PFCandidateEGammaExtraRef pfPhoRef = candRef->egammaExtraRef();
99  reco::SuperClusterRef refinedSC= pfPhoRef->superClusterRef();
100  reco::SuperClusterRef boxSC= pfPhoRef->superClusterPFECALRef();
101  const reco::ConversionRefVector & doubleLegConv = pfPhoRef->conversionRef();
102  const reco::ConversionRefVector & singleLegConv = pfPhoRef->singleLegConversionRef();
103  reco::CaloClusterPtr refinedSCPtr= edm::refToPtr(refinedSC);
104 
105  // std::cout << "newCandidate doubleLegConv="<<doubleLegConv.size()<< std::endl;
106  //std::cout << "newCandidate singleLegConv="<< pfPhoRef->singleLegConvTrackRef().size()<< std::endl;
107 
109  reco::PhotonCore newCandidate;
110  newCandidate.setPFlowPhoton(true);
111  newCandidate.setStandardPhoton(false);
112  newCandidate.setSuperCluster(refinedSC);
113  newCandidate.setParentSuperCluster(boxSC);
114  // fill conversion infos
115 
116 
117  for(unsigned int lConv=0; lConv < doubleLegConv.size(); lConv++) {
118  newCandidate.addConversion(doubleLegConv[lConv]);
119  }
120 
121  for(unsigned int lConv=0; lConv < singleLegConv.size(); lConv++) {
122  newCandidate.addOneLegConversion(singleLegConv[lConv]);
123  }
124 
125  // std::cout << "newCandidate pf refined SC energy="<< newCandidate.superCluster()->energy()<<std::endl;
126  //std::cout << "newCandidate pf SC energy="<< newCandidate.parentSuperCluster()->energy()<<std::endl;
127  //std::cout << "newCandidate nconv2leg="<<newCandidate.conversions().size()<< std::endl;
128 
129  if ( validPixelSeeds_) {
130  for( unsigned int icp = 0; icp < pixelSeedHandle->size(); icp++) {
131  reco::ElectronSeedRef cpRef(pixelSeedHandle,icp);
132  if ( boxSC.isNonnull() && boxSC.id() == cpRef->caloCluster().id() && boxSC.key() == cpRef->caloCluster().key() ) {
133  newCandidate.addElectronPixelSeed(cpRef);
134  }
135  }
136  }
137 
138  outputPhotonCoreCollection.push_back(newCandidate);
139  }
140 
141  // put the product in the event
142  // edm::LogInfo("GEDPhotonCoreProducer") << " Put in the event " << iSC << " Photon Candidates \n";
143  outputPhotonCoreCollection_p->assign(outputPhotonCoreCollection.begin(),outputPhotonCoreCollection.end());
144  theEvent.put(std::move(outputPhotonCoreCollection_p), GEDPhotonCoreCollection_);
145 
146 
147 
148 
149 }
T getParameter(std::string const &) const
void setSuperCluster(const reco::SuperClusterRef &r)
set reference to SuperCluster
Definition: PhotonCore.h:50
void addOneLegConversion(const reco::ConversionRef &r)
add single ConversionRef to the vector of Refs
Definition: PhotonCore.h:56
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
void addConversion(const reco::ConversionRef &r)
add single ConversionRef to the vector of Refs
Definition: PhotonCore.h:54
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:251
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
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
Definition: config.py:1
key_type key() const
Accessor for product key.
Definition: Ref.h:263
edm::EDGetTokenT< reco::ElectronSeedCollection > pixelSeedProducer_
ProductID id() const
Accessor for product ID.
Definition: Ref.h:257
void setParentSuperCluster(const reco::SuperClusterRef &r)
set reference to PFlow SuperCluster
Definition: PhotonCore.h:52
void setStandardPhoton(const bool prov)
Definition: PhotonCore.h:61
std::vector< ElectronSeed > ElectronSeedCollection
collection of ElectronSeed objects
bool isValid() const
Definition: HandleBase.h:74
void produce(edm::Event &evt, const edm::EventSetup &es) override
void setPFlowPhoton(const bool prov)
set the provenance
Definition: PhotonCore.h:60
std::vector< PhotonCore > PhotonCoreCollection
collectin of PhotonCore objects
Definition: PhotonCoreFwd.h:9
HLT enums.
GEDPhotonCoreProducer(const edm::ParameterSet &ps)
size_type size() const
Size of the RefVector.
Definition: RefVector.h:107
void addElectronPixelSeed(const reco::ElectronSeedRef &r)
set electron pixel seed ref
Definition: PhotonCore.h:58
edm::EDGetTokenT< reco::PFCandidateCollection > pfEgammaCandidates_
def move(src, dest)
Definition: eostools.py:511