Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include <boost/ptr_container/ptr_vector.hpp>
00016 #include <boost/ptr_container/ptr_list.hpp>
00017 #include <boost/foreach.hpp>
00018 #include <algorithm>
00019 #include <functional>
00020
00021 #include "FWCore/Framework/interface/EDProducer.h"
00022 #include "FWCore/Framework/interface/EventSetup.h"
00023 #include "FWCore/Framework/interface/ESHandle.h"
00024 #include "FWCore/Framework/interface/Event.h"
00025 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00026 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00027
00028 #include "RecoTauTag/RecoTau/interface/RecoTauPiZeroPlugins.h"
00029 #include "RecoTauTag/RecoTau/interface/RecoTauCleaningTools.h"
00030 #include "RecoTauTag/RecoTau/interface/RecoTauCommonUtilities.h"
00031
00032 #include "DataFormats/JetReco/interface/PFJetCollection.h"
00033 #include "DataFormats/TauReco/interface/JetPiZeroAssociation.h"
00034 #include "DataFormats/TauReco/interface/RecoTauPiZero.h"
00035 #include "DataFormats/Common/interface/Association.h"
00036
00037 #include "CommonTools/CandUtils/interface/AddFourMomenta.h"
00038 #include "CommonTools/Utils/interface/StringCutObjectSelector.h"
00039
00040 class RecoTauPiZeroProducer : public edm::EDProducer {
00041 public:
00042 typedef reco::tau::RecoTauPiZeroBuilderPlugin Builder;
00043 typedef reco::tau::RecoTauPiZeroQualityPlugin Ranker;
00044
00045 explicit RecoTauPiZeroProducer(const edm::ParameterSet& pset);
00046 ~RecoTauPiZeroProducer() {}
00047 void produce(edm::Event& evt, const edm::EventSetup& es);
00048 void print(const std::vector<reco::RecoTauPiZero>& piZeros,
00049 std::ostream& out);
00050
00051 private:
00052 typedef boost::ptr_vector<Builder> builderList;
00053 typedef boost::ptr_vector<Ranker> rankerList;
00054 typedef boost::ptr_vector<reco::RecoTauPiZero> PiZeroVector;
00055 typedef boost::ptr_list<reco::RecoTauPiZero> PiZeroList;
00056
00057 typedef reco::tau::RecoTauLexicographicalRanking<rankerList,
00058 reco::RecoTauPiZero> PiZeroPredicate;
00059
00060 edm::InputTag src_;
00061 builderList builders_;
00062 rankerList rankers_;
00063 std::auto_ptr<PiZeroPredicate> predicate_;
00064 double piZeroMass_;
00065
00066
00067 std::auto_ptr<StringCutObjectSelector<reco::RecoTauPiZero> >
00068 outputSelector_;
00069 };
00070
00071 RecoTauPiZeroProducer::RecoTauPiZeroProducer(const edm::ParameterSet& pset) {
00072 src_ = pset.getParameter<edm::InputTag>("jetSrc");
00073
00074 typedef std::vector<edm::ParameterSet> VPSet;
00075
00076 piZeroMass_ = pset.getParameter<double>("massHypothesis");
00077
00078
00079 const VPSet& builders = pset.getParameter<VPSet>("builders");
00080
00081 for (VPSet::const_iterator builderPSet = builders.begin();
00082 builderPSet != builders.end(); ++builderPSet) {
00083
00084 const std::string& pluginType =
00085 builderPSet->getParameter<std::string>("plugin");
00086
00087 builders_.push_back(RecoTauPiZeroBuilderPluginFactory::get()->create(
00088 pluginType, *builderPSet));
00089 }
00090
00091
00092 const VPSet& rankers = pset.getParameter<VPSet>("ranking");
00093 for (VPSet::const_iterator rankerPSet = rankers.begin();
00094 rankerPSet != rankers.end(); ++rankerPSet) {
00095 const std::string& pluginType =
00096 rankerPSet->getParameter<std::string>("plugin");
00097 rankers_.push_back(RecoTauPiZeroQualityPluginFactory::get()->create(
00098 pluginType, *rankerPSet));
00099 }
00100
00101
00102 predicate_ = std::auto_ptr<PiZeroPredicate>(new PiZeroPredicate(rankers_));
00103
00104
00105 if (pset.exists("outputSelection")) {
00106 std::string selection = pset.getParameter<std::string>("outputSelection");
00107 if (selection != "") {
00108 outputSelector_.reset(
00109 new StringCutObjectSelector<reco::RecoTauPiZero>(selection));
00110 }
00111 }
00112
00113 produces<reco::JetPiZeroAssociation>();
00114 }
00115
00116 void RecoTauPiZeroProducer::produce(edm::Event& evt,
00117 const edm::EventSetup& es) {
00118
00119 edm::Handle<reco::CandidateView> jetView;
00120 evt.getByLabel(src_, jetView);
00121
00122
00123 BOOST_FOREACH(Builder& builder, builders_) {
00124 builder.setup(evt, es);
00125 }
00126
00127
00128 reco::PFJetRefVector jetRefs =
00129 reco::tau::castView<reco::PFJetRefVector>(jetView);
00130
00131 std::auto_ptr<reco::JetPiZeroAssociation> association;
00132
00133 if (jetRefs.size()) {
00134 association.reset(
00135 new reco::JetPiZeroAssociation(reco::PFJetRefProd(jetRefs)));
00136 } else {
00137 association.reset(new reco::JetPiZeroAssociation);
00138 }
00139
00140
00141 BOOST_FOREACH(const reco::PFJetRef& jet, jetRefs) {
00142
00143 PiZeroList dirtyPiZeros;
00144
00145
00146 BOOST_FOREACH(const Builder& builder, builders_) {
00147 try {
00148 PiZeroVector result(builder(*jet));
00149 dirtyPiZeros.transfer(dirtyPiZeros.end(), result);
00150 } catch ( cms::Exception &exception) {
00151 edm::LogError("BuilderPluginException")
00152 << "Exception caught in builder plugin " << builder.name()
00153 << ", rethrowing" << std::endl;
00154 throw exception;
00155 }
00156 }
00157
00158 dirtyPiZeros.sort(*predicate_);
00159
00160
00161 std::vector<reco::RecoTauPiZero> cleanPiZeros;
00162 std::set<reco::CandidatePtr> photonsInCleanCollection;
00163 while (dirtyPiZeros.size()) {
00164
00165 std::auto_ptr<reco::RecoTauPiZero> toAdd(
00166 dirtyPiZeros.pop_front().release());
00167
00168 if (!(*outputSelector_)(*toAdd)) {
00169 continue;
00170 }
00171
00172 std::vector<reco::CandidatePtr> uniqueGammas;
00173 std::set_difference(toAdd->daughterPtrVector().begin(),
00174 toAdd->daughterPtrVector().end(),
00175 photonsInCleanCollection.begin(),
00176 photonsInCleanCollection.end(),
00177 std::back_inserter(uniqueGammas));
00178
00179
00180 if (!uniqueGammas.size()) {
00181 continue;
00182 } else if (uniqueGammas.size() == toAdd->daughterPtrVector().size()) {
00183
00184
00185 photonsInCleanCollection.insert(toAdd->daughterPtrVector().begin(),
00186 toAdd->daughterPtrVector().end());
00187 cleanPiZeros.push_back(*toAdd);
00188 } else {
00189
00190
00191 toAdd->clearDaughters();
00192
00193 BOOST_FOREACH(const reco::CandidatePtr& gamma, uniqueGammas) {
00194 toAdd->addDaughter(gamma);
00195 }
00196
00197 AddFourMomenta p4Builder_;
00198 p4Builder_.set(*toAdd);
00199
00200 PiZeroList::iterator insertionPoint = std::lower_bound(
00201 dirtyPiZeros.begin(), dirtyPiZeros.end(), *toAdd, *predicate_);
00202 dirtyPiZeros.insert(insertionPoint, toAdd);
00203 }
00204 }
00205
00206 if (piZeroMass_ >= 0) {
00207 std::for_each(
00208 cleanPiZeros.begin(), cleanPiZeros.end(),
00209 std::bind2nd(
00210 std::mem_fun_ref(&reco::RecoTauPiZero::setMass), piZeroMass_));
00211 }
00212
00213
00214 association->setValue(jet.key(), cleanPiZeros);
00215 }
00216 evt.put(association);
00217 }
00218
00219
00220 void RecoTauPiZeroProducer::print(
00221 const std::vector<reco::RecoTauPiZero>& piZeros, std::ostream& out) {
00222 const unsigned int width = 25;
00223 BOOST_FOREACH(const reco::RecoTauPiZero& piZero, piZeros) {
00224 out << piZero;
00225 out << "* Rankers:" << std::endl;
00226 for (rankerList::const_iterator ranker = rankers_.begin();
00227 ranker != rankers_.end(); ++ranker) {
00228 out << "* " << std::setiosflags(std::ios::left)
00229 << std::setw(width) << ranker->name()
00230 << " " << std::resetiosflags(std::ios::left)
00231 << std::setprecision(3) << (*ranker)(piZero);
00232 out << std::endl;
00233 }
00234 }
00235 }
00236
00237 #include "FWCore/Framework/interface/MakerMacros.h"
00238 DEFINE_FWK_MODULE(RecoTauPiZeroProducer);