![]() |
![]() |
#include <PhysicsTools/PatAlgos/interface/PATPhotonProducer.h>
Public Member Functions | |
PATPhotonProducer (const edm::ParameterSet &iConfig) | |
virtual void | produce (edm::Event &iEvent, const edm::EventSetup &iSetup) |
~PATPhotonProducer () | |
Private Attributes | |
bool | addEfficiencies_ |
bool | addGenMatch_ |
bool | addPhotonID_ |
bool | addTrigMatch_ |
pat::helper::EfficiencyLoader | efficiencyLoader_ |
bool | embedGenMatch_ |
bool | embedSuperCluster_ |
GreaterByEt< Photon > | eTComparator_ |
std::vector< edm::InputTag > | genMatchSrc_ |
std::vector< std::pair < pat::IsolationKeys, edm::InputTag > > | isoDepositLabels_ |
pat::helper::MultiIsolator | isolator_ |
pat::helper::MultiIsolator::IsolationValuePairs | isolatorTmpStorage_ |
edm::InputTag | photonIDSrc_ |
edm::InputTag | photonSrc_ |
std::vector< edm::InputTag > | trigMatchSrc_ |
pat::PATUserDataHelper < pat::Photon > | userDataHelper_ |
bool | useUserData_ |
The PATPhotonProducer produces the analysis-level pat::Photon starting from a collection of objects of PhotonType.
Definition at line 37 of file PATPhotonProducer.h.
PATPhotonProducer::PATPhotonProducer | ( | const edm::ParameterSet & | iConfig | ) | [explicit] |
Definition at line 16 of file PATPhotonProducer.cc.
References addEfficiencies_, addGenMatch_, addPhotonID_, addTrigMatch_, pat::ECalIso, efficiencyLoader_, embedGenMatch_, embedSuperCluster_, edm::ParameterSet::exists(), edm::ParameterSet::existsAs(), genMatchSrc_, edm::ParameterSet::getParameter(), pat::HCalIso, isoDepositLabels_, it, getDQMSummary::key, photonIDSrc_, photonSrc_, pat::TrackerIso, trigMatchSrc_, pat::UserBaseIso, and useUserData_.
00016 : 00017 isolator_(iConfig.exists("isolation") ? iConfig.getParameter<edm::ParameterSet>("isolation") : edm::ParameterSet(), false) , 00018 userDataHelper_ ( iConfig.getParameter<edm::ParameterSet>("userData") ) 00019 { 00020 // initialize the configurables 00021 photonSrc_ = iConfig.getParameter<edm::InputTag>("photonSource"); 00022 embedSuperCluster_ = iConfig.getParameter<bool> ("embedSuperCluster"); 00023 00024 // photon ID configurables 00025 addPhotonID_ = iConfig.getParameter<bool> ("addPhotonID"); 00026 photonIDSrc_ = iConfig.getParameter<edm::InputTag>("photonIDSource"); 00027 00028 // MC matching configurables 00029 addGenMatch_ = iConfig.getParameter<bool> ( "addGenMatch" ); 00030 if (addGenMatch_) { 00031 embedGenMatch_ = iConfig.getParameter<bool> ( "embedGenMatch" ); 00032 if (iConfig.existsAs<edm::InputTag>("genParticleMatch")) { 00033 genMatchSrc_.push_back(iConfig.getParameter<edm::InputTag>( "genParticleMatch" )); 00034 } else { 00035 genMatchSrc_ = iConfig.getParameter<std::vector<edm::InputTag> >( "genParticleMatch" ); 00036 } 00037 } 00038 00039 // trigger matching configurables 00040 addTrigMatch_ = iConfig.getParameter<bool> ( "addTrigMatch" ); 00041 trigMatchSrc_ = iConfig.getParameter<std::vector<edm::InputTag> >( "trigPrimMatch" ); 00042 00043 // Efficiency configurables 00044 addEfficiencies_ = iConfig.getParameter<bool>("addEfficiencies"); 00045 if (addEfficiencies_) { 00046 efficiencyLoader_ = pat::helper::EfficiencyLoader(iConfig.getParameter<edm::ParameterSet>("efficiencies")); 00047 } 00048 00049 // Check to see if the user wants to add user data 00050 useUserData_ = false; 00051 if ( iConfig.exists("userData") ) { 00052 useUserData_ = true; 00053 } 00054 00055 00056 // produces vector of photons 00057 produces<std::vector<Photon> >(); 00058 00059 if (iConfig.exists("isoDeposits")) { 00060 edm::ParameterSet depconf = iConfig.getParameter<edm::ParameterSet>("isoDeposits"); 00061 if (depconf.exists("tracker")) isoDepositLabels_.push_back(std::make_pair(TrackerIso, depconf.getParameter<edm::InputTag>("tracker"))); 00062 if (depconf.exists("ecal")) isoDepositLabels_.push_back(std::make_pair(ECalIso, depconf.getParameter<edm::InputTag>("ecal"))); 00063 if (depconf.exists("hcal")) isoDepositLabels_.push_back(std::make_pair(HCalIso, depconf.getParameter<edm::InputTag>("hcal"))); 00064 if (depconf.exists("user")) { 00065 std::vector<edm::InputTag> userdeps = depconf.getParameter<std::vector<edm::InputTag> >("user"); 00066 std::vector<edm::InputTag>::const_iterator it = userdeps.begin(), ed = userdeps.end(); 00067 int key = UserBaseIso; 00068 for ( ; it != ed; ++it, ++key) { 00069 isoDepositLabels_.push_back(std::make_pair(IsolationKeys(key), *it)); 00070 } 00071 } 00072 } 00073 }
PATPhotonProducer::~PATPhotonProducer | ( | ) |
void PATPhotonProducer::produce | ( | edm::Event & | iEvent, | |
const edm::EventSetup & | iSetup | |||
) | [virtual] |
Implements edm::EDProducer.
Definition at line 78 of file PATPhotonProducer.cc.
References pat::PATUserDataHelper< ObjectType >::add(), addGenMatch_, pat::PATObject< ObjectType >::addGenParticleRef(), addPhotonID_, pat::PATObject< ObjectType >::addTriggerMatch(), addTrigMatch_, pat::helper::MultiIsolator::beginEvent(), edm::RefToBase< T >::castTo(), efficiencyLoader_, embedGenMatch_, pat::PATObject< ObjectType >::embedGenParticle(), pat::Photon::embedSuperCluster(), embedSuperCluster_, pat::helper::MultiIsolator::enabled(), pat::helper::EfficiencyLoader::enabled(), pat::helper::MultiIsolator::endEvent(), eTComparator_, pat::helper::MultiIsolator::fill(), first, genMatchSrc_, edm::Event::getByLabel(), i, edm::Ref< C, T, F >::isAvailable(), edm::Ref< C, T, F >::isNonnull(), edm::Ref< C, T, F >::isNull(), isoDepositLabels_, isolator_, isolatorTmpStorage_, it, j, n, pat::helper::EfficiencyLoader::newEvent(), photonIDSrc_, photons_cfi::photons, photonSrc_, edm::Event::put(), edm::second(), pat::helper::EfficiencyLoader::setEfficiencies(), pat::Photon::setIsoDeposit(), pat::Photon::setIsolation(), pat::Photon::setPhotonID(), python::multivaluedict::sort(), trigMatchSrc_, userDataHelper_, and useUserData_.
00078 { 00079 00080 // Get the vector of Photon's from the event 00081 edm::Handle<edm::View<PhotonType> > photons; 00082 iEvent.getByLabel(photonSrc_, photons); 00083 00084 // prepare the MC matching 00085 std::vector<edm::Handle<edm::Association<reco::GenParticleCollection> > > genMatches(genMatchSrc_.size()); 00086 if (addGenMatch_) { 00087 for (size_t j = 0, nd = genMatchSrc_.size(); j < nd; ++j) { 00088 iEvent.getByLabel(genMatchSrc_[j], genMatches[j]); 00089 } 00090 } 00091 00092 // prepare the PhotonID 00093 edm::Handle<reco::PhotonIDAssociationCollection > photonID; 00094 if (addPhotonID_) { 00095 iEvent.getByLabel(photonIDSrc_, photonID); 00096 } 00097 00098 if (isolator_.enabled()) isolator_.beginEvent(iEvent,iSetup); 00099 00100 if (efficiencyLoader_.enabled()) efficiencyLoader_.newEvent(iEvent); 00101 00102 std::vector<edm::Handle<edm::ValueMap<IsoDeposit> > > deposits(isoDepositLabels_.size()); 00103 for (size_t j = 0, nd = deposits.size(); j < nd; ++j) { 00104 iEvent.getByLabel(isoDepositLabels_[j].second, deposits[j]); 00105 } 00106 00107 // loop over photons 00108 std::vector<Photon> * PATPhotons = new std::vector<Photon>(); 00109 for (edm::View<PhotonType>::const_iterator itPhoton = photons->begin(); itPhoton != photons->end(); itPhoton++) { 00110 // construct the Photon from the ref -> save ref to original object 00111 unsigned int idx = itPhoton - photons->begin(); 00112 edm::RefToBase<PhotonType> photonRef = photons->refAt(idx); 00113 edm::Ptr<PhotonType> photonPtr = photons->ptrAt(idx); 00114 Photon aPhoton(photonRef); 00115 if (embedSuperCluster_) aPhoton.embedSuperCluster(); 00116 00117 // store the match to the generated final state muons 00118 if (addGenMatch_) { 00119 for(size_t i = 0, n = genMatches.size(); i < n; ++i) { 00120 reco::GenParticleRef genPhoton = (*genMatches[i])[photonRef]; 00121 aPhoton.addGenParticleRef(genPhoton); 00122 } 00123 if (embedGenMatch_) aPhoton.embedGenParticle(); 00124 } 00125 00126 // matches to trigger primitives 00127 if ( addTrigMatch_ ) { 00128 for ( size_t i = 0; i < trigMatchSrc_.size(); ++i ) { 00129 edm::Handle<edm::Association<TriggerPrimitiveCollection> > trigMatch; 00130 iEvent.getByLabel(trigMatchSrc_[i], trigMatch); 00131 TriggerPrimitiveRef trigPrim = (*trigMatch)[photonRef]; 00132 if ( trigPrim.isNonnull() && trigPrim.isAvailable() ) { 00133 aPhoton.addTriggerMatch(*trigPrim); 00134 } 00135 } 00136 } 00137 00138 // PhotonID 00139 if (addPhotonID_) { 00140 reco::PhotonRef recoPhotonRef = photonRef.castTo<reco::PhotonRef>(); 00141 if (recoPhotonRef.isNull()) throw cms::Exception("Bad Input") << "You can't read PhotonIDAssociation from something that's not a PhotonCollection"; 00142 aPhoton.setPhotonID( *( (*photonID)[recoPhotonRef] ) ); 00143 } 00144 00145 if (efficiencyLoader_.enabled()) { 00146 efficiencyLoader_.setEfficiencies( aPhoton, photonRef ); 00147 } 00148 00149 // here comes the extra functionality 00150 if (isolator_.enabled()) { 00151 isolator_.fill(*photons, idx, isolatorTmpStorage_); 00152 typedef pat::helper::MultiIsolator::IsolationValuePairs IsolationValuePairs; 00153 // better to loop backwards, so the vector is resized less times 00154 for (IsolationValuePairs::const_reverse_iterator it = isolatorTmpStorage_.rbegin(), ed = isolatorTmpStorage_.rend(); it != ed; ++it) { 00155 aPhoton.setIsolation(it->first, it->second); 00156 } 00157 } 00158 00159 for (size_t j = 0, nd = deposits.size(); j < nd; ++j) { 00160 aPhoton.setIsoDeposit(isoDepositLabels_[j].first, (*deposits[j])[photonRef]); 00161 } 00162 00163 00164 if ( useUserData_ ) { 00165 userDataHelper_.add( aPhoton, iEvent, iSetup ); 00166 } 00167 00168 00169 // add the Photon to the vector of Photons 00170 PATPhotons->push_back(aPhoton); 00171 } 00172 00173 // sort Photons in ET 00174 std::sort(PATPhotons->begin(), PATPhotons->end(), eTComparator_); 00175 00176 // put genEvt object in Event 00177 std::auto_ptr<std::vector<Photon> > myPhotons(PATPhotons); 00178 iEvent.put(myPhotons); 00179 if (isolator_.enabled()) isolator_.endEvent(); 00180 00181 }
bool pat::PATPhotonProducer::addEfficiencies_ [private] |
bool pat::PATPhotonProducer::addGenMatch_ [private] |
Definition at line 52 of file PATPhotonProducer.h.
Referenced by PATPhotonProducer(), and produce().
bool pat::PATPhotonProducer::addPhotonID_ [private] |
Definition at line 59 of file PATPhotonProducer.h.
Referenced by PATPhotonProducer(), and produce().
bool pat::PATPhotonProducer::addTrigMatch_ [private] |
Definition at line 56 of file PATPhotonProducer.h.
Referenced by PATPhotonProducer(), and produce().
Definition at line 70 of file PATPhotonProducer.h.
Referenced by PATPhotonProducer(), and produce().
bool pat::PATPhotonProducer::embedGenMatch_ [private] |
Definition at line 53 of file PATPhotonProducer.h.
Referenced by PATPhotonProducer(), and produce().
Definition at line 50 of file PATPhotonProducer.h.
Referenced by PATPhotonProducer(), and produce().
std::vector<edm::InputTag> pat::PATPhotonProducer::genMatchSrc_ [private] |
Definition at line 54 of file PATPhotonProducer.h.
Referenced by PATPhotonProducer(), and produce().
std::vector<std::pair<pat::IsolationKeys,edm::InputTag> > pat::PATPhotonProducer::isoDepositLabels_ [private] |
Definition at line 67 of file PATPhotonProducer.h.
Referenced by PATPhotonProducer(), and produce().
Definition at line 60 of file PATPhotonProducer.h.
Referenced by PATPhotonProducer(), and produce().
Definition at line 49 of file PATPhotonProducer.h.
Referenced by PATPhotonProducer(), and produce().
std::vector<edm::InputTag> pat::PATPhotonProducer::trigMatchSrc_ [private] |
Definition at line 57 of file PATPhotonProducer.h.
Referenced by PATPhotonProducer(), and produce().
bool pat::PATPhotonProducer::useUserData_ [private] |
Definition at line 72 of file PATPhotonProducer.h.
Referenced by PATPhotonProducer(), and produce().