00001
00002
00003
00004
00005 #include "PhysicsTools/PatAlgos/plugins/PATGenericParticleProducer.h"
00006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00007 #include "DataFormats/Common/interface/View.h"
00008 #include <memory>
00009
00010 using namespace pat;
00011
00012 PATGenericParticleProducer::PATGenericParticleProducer(const edm::ParameterSet & iConfig) :
00013 isolator_(iConfig.exists("isolation") ? iConfig.getParameter<edm::ParameterSet>("isolation") : edm::ParameterSet(), false),
00014 userDataHelper_ ( iConfig.getParameter<edm::ParameterSet>("userData") )
00015 {
00016
00017 src_ = iConfig.getParameter<edm::InputTag>( "src" );
00018
00019
00020 embedTrack_ = iConfig.getParameter<bool>( "embedTrack" );
00021 embedGsfTrack_ = iConfig.getParameter<bool>( "embedGsfTrack" );
00022 embedStandalone_ = iConfig.getParameter<bool>( "embedStandAloneMuon" );
00023 embedCombined_ = iConfig.getParameter<bool>( "embedCombinedMuon" );
00024 embedSuperCluster_ = iConfig.getParameter<bool>( "embedSuperCluster" );
00025 embedTracks_ = iConfig.getParameter<bool>( "embedMultipleTracks" );
00026 embedCaloTower_ = iConfig.getParameter<bool>( "embedCaloTower" );
00027
00028
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
00040 addTrigMatch_ = iConfig.getParameter<bool>( "addTrigMatch" );
00041 trigPrimSrc_ = iConfig.getParameter<std::vector<edm::InputTag> >( "trigPrimMatch" );
00042
00043
00044 addQuality_ = iConfig.getParameter<bool>("addQuality");
00045 qualitySrc_ = iConfig.getParameter<edm::InputTag>("qualitySource");
00046
00047
00048 produces<std::vector<GenericParticle> >();
00049
00050 if (iConfig.exists("isoDeposits")) {
00051 edm::ParameterSet depconf = iConfig.getParameter<edm::ParameterSet>("isoDeposits");
00052 if (depconf.exists("tracker")) isoDepositLabels_.push_back(std::make_pair(TrackerIso, depconf.getParameter<edm::InputTag>("tracker")));
00053 if (depconf.exists("ecal")) isoDepositLabels_.push_back(std::make_pair(ECalIso, depconf.getParameter<edm::InputTag>("ecal")));
00054 if (depconf.exists("hcal")) isoDepositLabels_.push_back(std::make_pair(HCalIso, depconf.getParameter<edm::InputTag>("hcal")));
00055 if (depconf.exists("user")) {
00056 std::vector<edm::InputTag> userdeps = depconf.getParameter<std::vector<edm::InputTag> >("user");
00057 std::vector<edm::InputTag>::const_iterator it = userdeps.begin(), ed = userdeps.end();
00058 int key = UserBaseIso;
00059 for ( ; it != ed; ++it, ++key) {
00060 isoDepositLabels_.push_back(std::make_pair(IsolationKeys(key), *it));
00061 }
00062 }
00063 }
00064
00065
00066 addEfficiencies_ = iConfig.getParameter<bool>("addEfficiencies");
00067 if (addEfficiencies_) {
00068 efficiencyLoader_ = pat::helper::EfficiencyLoader(iConfig.getParameter<edm::ParameterSet>("efficiencies"));
00069 }
00070
00071 if (iConfig.exists("vertexing")) {
00072 vertexingHelper_ = pat::helper::VertexingHelper(iConfig.getParameter<edm::ParameterSet>("vertexing"));
00073 }
00074
00075
00076 useUserData_ = false;
00077 if ( iConfig.exists("userData") ) {
00078 useUserData_ = true;
00079 }
00080 }
00081
00082 PATGenericParticleProducer::~PATGenericParticleProducer() {
00083 }
00084
00085 void PATGenericParticleProducer::produce(edm::Event & iEvent, const edm::EventSetup & iSetup) {
00086
00087 edm::Handle<edm::View<reco::Candidate> > cands;
00088 iEvent.getByLabel(src_, cands);
00089
00090
00091 if (isolator_.enabled()) isolator_.beginEvent(iEvent,iSetup);
00092
00093 if (efficiencyLoader_.enabled()) efficiencyLoader_.newEvent(iEvent);
00094 if (vertexingHelper_.enabled()) vertexingHelper_.newEvent(iEvent,iSetup);
00095
00096
00097 std::vector<edm::Handle<edm::ValueMap<IsoDeposit> > > deposits(isoDepositLabels_.size());
00098 for (size_t j = 0, nd = deposits.size(); j < nd; ++j) {
00099 iEvent.getByLabel(isoDepositLabels_[j].second, deposits[j]);
00100 }
00101
00102
00103 std::vector<edm::Handle<edm::Association<reco::GenParticleCollection> > > genMatches(genMatchSrc_.size());
00104 if (addGenMatch_) {
00105 for (size_t j = 0, nd = genMatchSrc_.size(); j < nd; ++j) {
00106 iEvent.getByLabel(genMatchSrc_[j], genMatches[j]);
00107 }
00108 }
00109
00110
00111 edm::Handle<edm::ValueMap<float> > qualities;
00112 if (addQuality_) iEvent.getByLabel(qualitySrc_, qualities);
00113
00114
00115 std::vector<GenericParticle> * PATGenericParticles = new std::vector<GenericParticle>();
00116 for (edm::View<reco::Candidate>::const_iterator itGenericParticle = cands->begin(); itGenericParticle != cands->end(); itGenericParticle++) {
00117
00118 unsigned int idx = itGenericParticle - cands->begin();
00119 edm::RefToBase<reco::Candidate> candRef = cands->refAt(idx);
00120
00121 PATGenericParticles->push_back(GenericParticle(candRef));
00122 GenericParticle & aGenericParticle = PATGenericParticles->back();
00123
00124
00125 if (embedTrack_) aGenericParticle.embedTrack();
00126 if (embedGsfTrack_) aGenericParticle.embedGsfTrack();
00127 if (embedTracks_) aGenericParticle.embedTracks();
00128 if (embedStandalone_) aGenericParticle.embedStandalone();
00129 if (embedCombined_) aGenericParticle.embedCombined();
00130 if (embedSuperCluster_) aGenericParticle.embedSuperCluster();
00131 if (embedCaloTower_) aGenericParticle.embedCaloTower();
00132
00133
00134 if ( addTrigMatch_ ) {
00135 for ( size_t i = 0; i < trigPrimSrc_.size(); ++i ) {
00136 edm::Handle<edm::Association<TriggerPrimitiveCollection> > trigMatch;
00137 iEvent.getByLabel(trigPrimSrc_[i], trigMatch);
00138 TriggerPrimitiveRef trigPrim = (*trigMatch)[candRef];
00139 if ( trigPrim.isNonnull() && trigPrim.isAvailable() ) {
00140 aGenericParticle.addTriggerMatch(*trigPrim);
00141 }
00142 }
00143 }
00144
00145
00146 if (isolator_.enabled()) {
00147 isolator_.fill(*cands, idx, isolatorTmpStorage_);
00148 typedef pat::helper::MultiIsolator::IsolationValuePairs IsolationValuePairs;
00149
00150 for (IsolationValuePairs::const_reverse_iterator it = isolatorTmpStorage_.rbegin(), ed = isolatorTmpStorage_.rend(); it != ed; ++it) {
00151 aGenericParticle.setIsolation(it->first, it->second);
00152 }
00153 }
00154
00155
00156 for (size_t j = 0, nd = deposits.size(); j < nd; ++j) {
00157 aGenericParticle.setIsoDeposit(isoDepositLabels_[j].first, (*deposits[j])[candRef]);
00158 }
00159
00160
00161 if (addGenMatch_) {
00162 for(size_t i = 0, n = genMatches.size(); i < n; ++i) {
00163 reco::GenParticleRef genGenericParticle = (*genMatches[i])[candRef];
00164 aGenericParticle.addGenParticleRef(genGenericParticle);
00165 }
00166 if (embedGenMatch_) aGenericParticle.embedGenParticle();
00167 }
00168
00169 if (addQuality_) {
00170 aGenericParticle.setQuality( (*qualities)[candRef] );
00171 }
00172
00173 if (efficiencyLoader_.enabled()) {
00174 efficiencyLoader_.setEfficiencies( aGenericParticle, candRef );
00175 }
00176
00177 if (vertexingHelper_.enabled()) {
00178 aGenericParticle.setVertexAssociation( vertexingHelper_(candRef) );
00179 }
00180
00181 if ( useUserData_ ) {
00182 userDataHelper_.add( aGenericParticle, iEvent, iSetup );
00183 }
00184
00185
00186
00187
00188 }
00189
00190
00191 std::sort(PATGenericParticles->begin(), PATGenericParticles->end(), eTComparator_);
00192
00193
00194 std::auto_ptr<std::vector<GenericParticle> > myGenericParticles(PATGenericParticles);
00195 iEvent.put(myGenericParticles);
00196 if (isolator_.enabled()) isolator_.endEvent();
00197
00198 }
00199
00200 #include "FWCore/Framework/interface/MakerMacros.h"
00201
00202 DEFINE_FWK_MODULE(PATGenericParticleProducer);