Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <boost/ptr_container/ptr_vector.hpp>
00019 #include <boost/foreach.hpp>
00020
00021 #include <algorithm>
00022 #include <functional>
00023
00024 #include "FWCore/Framework/interface/EDProducer.h"
00025 #include "FWCore/Framework/interface/EventSetup.h"
00026 #include "FWCore/Framework/interface/ESHandle.h"
00027 #include "FWCore/Framework/interface/Event.h"
00028 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00029
00030 #include "RecoTauTag/RecoTau/interface/RecoTauBuilderPlugins.h"
00031 #include "RecoTauTag/RecoTau/interface/RecoTauCommonUtilities.h"
00032
00033 #include "DataFormats/JetReco/interface/PFJetCollection.h"
00034 #include "DataFormats/TauReco/interface/JetPiZeroAssociation.h"
00035 #include "DataFormats/TauReco/interface/PFTau.h"
00036 #include "DataFormats/Candidate/interface/CandidateFwd.h"
00037
00038 #include "CommonTools/Utils/interface/StringCutObjectSelector.h"
00039
00040 class RecoTauProducer : public edm::EDProducer {
00041 public:
00042 typedef reco::tau::RecoTauBuilderPlugin Builder;
00043 typedef reco::tau::RecoTauModifierPlugin Modifier;
00044 typedef boost::ptr_vector<Builder> BuilderList;
00045 typedef boost::ptr_vector<Modifier> ModifierList;
00046
00047 explicit RecoTauProducer(const edm::ParameterSet& pset);
00048 ~RecoTauProducer() {}
00049 void produce(edm::Event& evt, const edm::EventSetup& es);
00050
00051 private:
00052 edm::InputTag jetSrc_;
00053 edm::InputTag piZeroSrc_;
00054 BuilderList builders_;
00055 ModifierList modifiers_;
00056
00057 std::auto_ptr<StringCutObjectSelector<reco::PFTau> > outputSelector_;
00058
00059
00060
00061 bool buildNullTaus_;
00062 };
00063
00064 RecoTauProducer::RecoTauProducer(const edm::ParameterSet& pset) {
00065 jetSrc_ = pset.getParameter<edm::InputTag>("jetSrc");
00066 piZeroSrc_ = pset.getParameter<edm::InputTag>("piZeroSrc");
00067
00068 typedef std::vector<edm::ParameterSet> VPSet;
00069
00070 const VPSet& builders = pset.getParameter<VPSet>("builders");
00071 for (VPSet::const_iterator builderPSet = builders.begin();
00072 builderPSet != builders.end(); ++builderPSet) {
00073
00074 const std::string& pluginType =
00075 builderPSet->getParameter<std::string>("plugin");
00076
00077 builders_.push_back(
00078 RecoTauBuilderPluginFactory::get()->create(pluginType, *builderPSet));
00079 }
00080
00081 const VPSet& modfiers = pset.getParameter<VPSet>("modifiers");
00082 for (VPSet::const_iterator modfierPSet = modfiers.begin();
00083 modfierPSet != modfiers.end(); ++modfierPSet) {
00084
00085 const std::string& pluginType =
00086 modfierPSet->getParameter<std::string>("plugin");
00087
00088 modifiers_.push_back(
00089 RecoTauModifierPluginFactory::get()->create(pluginType, *modfierPSet));
00090 }
00091
00092
00093 if (pset.exists("outputSelection")) {
00094 std::string selection = pset.getParameter<std::string>("outputSelection");
00095 if (selection != "") {
00096 outputSelector_.reset(
00097 new StringCutObjectSelector<reco::PFTau>(selection));
00098 }
00099 }
00100 buildNullTaus_ = pset.getParameter<bool>("buildNullTaus");
00101 produces<reco::PFTauCollection>();
00102 }
00103
00104 void RecoTauProducer::produce(edm::Event& evt, const edm::EventSetup& es) {
00105
00106 edm::Handle<reco::CandidateView> jetView;
00107 evt.getByLabel(jetSrc_, jetView);
00108
00109
00110 reco::PFJetRefVector jets =
00111 reco::tau::castView<reco::PFJetRefVector>(jetView);
00112
00113
00114 edm::Handle<reco::JetPiZeroAssociation> piZeroAssoc;
00115 evt.getByLabel(piZeroSrc_, piZeroAssoc);
00116
00117
00118 for (BuilderList::iterator builder = builders_.begin();
00119 builder != builders_.end(); ++builder) {
00120 builder->setup(evt, es);
00121 }
00122 for (ModifierList::iterator modifier = modifiers_.begin();
00123 modifier != modifiers_.end(); ++modifier) {
00124 modifier->setup(evt, es);
00125 }
00126
00127
00128 std::auto_ptr<reco::PFTauCollection> output(new reco::PFTauCollection());
00129
00130
00131 BOOST_FOREACH(reco::PFJetRef jetRef, jets) {
00132
00133 const std::vector<reco::RecoTauPiZero>& piZeros = (*piZeroAssoc)[jetRef];
00134
00135 unsigned int nTausBuilt = 0;
00136 for (BuilderList::const_iterator builder = builders_.begin();
00137 builder != builders_.end(); ++builder) {
00138
00139 reco::tau::RecoTauBuilderPlugin::output_type taus(
00140 (*builder)(jetRef, piZeros));
00141
00142
00143 output->reserve(output->size() + taus.size());
00144
00145 if (!outputSelector_.get()) {
00146 output->insert(output->end(), taus.begin(), taus.end());
00147 nTausBuilt += taus.size();
00148 } else {
00149
00150 BOOST_FOREACH(const reco::PFTau& tau, taus) {
00151 if ((*outputSelector_)(tau)) {
00152 nTausBuilt++;
00153 output->push_back(tau);
00154 }
00155 }
00156 }
00157 }
00158
00159
00160
00161 if (!nTausBuilt && buildNullTaus_) {
00162 reco::PFTau nullTau(std::numeric_limits<int>::quiet_NaN(), jetRef->p4());
00163 nullTau.setjetRef(jetRef);
00164 output->push_back(nullTau);
00165 }
00166 }
00167
00168
00169 for (reco::PFTauCollection::iterator tau = output->begin();
00170 tau != output->end(); ++tau) {
00171 for (ModifierList::const_iterator modifier = modifiers_.begin();
00172 modifier != modifiers_.end(); ++modifier) {
00173 (*modifier)(*tau);
00174 }
00175 }
00176 evt.put(output);
00177 }
00178
00179 #include "FWCore/Framework/interface/MakerMacros.h"
00180 DEFINE_FWK_MODULE(RecoTauProducer);