CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/RecoTauTag/RecoTau/plugins/RecoTauBuilderConePlugin.cc

Go to the documentation of this file.
00001 /*
00002  * RecoTauBuilderConePlugin
00003  *
00004  * Build a PFTau using cones defined in DeltaR.
00005  *
00006  * Original Authors: Ludovic Houchu, Simone Gennai
00007  * Modifications: Evan K. Friis
00008  *
00009  * $Id $
00010  */
00011 
00012 #include <vector>
00013 #include <algorithm>
00014 
00015 #include "RecoTauTag/RecoTau/interface/RecoTauBuilderPlugins.h"
00016 #include "RecoTauTag/RecoTau/interface/RecoTauCommonUtilities.h"
00017 #include "RecoTauTag/RecoTau/interface/ConeTools.h"
00018 #include "RecoTauTag/RecoTau/interface/RecoTauConstructor.h"
00019 #include "RecoTauTag/RecoTau/interface/RecoTauQualityCuts.h"
00020 
00021 #include "DataFormats/TauReco/interface/PFTau.h"
00022 #include "DataFormats/TauReco/interface/RecoTauPiZero.h"
00023 #include "DataFormats/Math/interface/deltaR.h"
00024 
00025 #include "CommonTools/Utils/interface/StringObjectFunction.h"
00026 
00027 namespace reco { namespace tau {
00028 
00029 class RecoTauBuilderConePlugin : public RecoTauBuilderPlugin {
00030   public:
00031     explicit RecoTauBuilderConePlugin(const edm::ParameterSet& pset);
00032     ~RecoTauBuilderConePlugin() {}
00033     // Build a tau from a jet
00034     return_type operator()(const reco::PFJetRef& jet,
00035         const std::vector<RecoTauPiZero>& piZeros) const;
00036   private:
00037     RecoTauQualityCuts qcuts_;
00038     bool usePFLeptonsAsChargedHadrons_;
00039     double leadObjecPtThreshold_;
00040     /* String function to extract values from PFJets */
00041     typedef StringObjectFunction<reco::PFJet> JetFunc;
00042     // Cone defintions
00043     JetFunc matchingCone_;
00044     JetFunc signalConeChargedHadrons_;
00045     JetFunc isoConeChargedHadrons_;
00046     JetFunc signalConePiZeros_;
00047     JetFunc isoConePiZeros_;
00048     JetFunc signalConeNeutralHadrons_;
00049     JetFunc isoConeNeutralHadrons_;
00050 };
00051 
00052 // ctor - initialize all of our variables
00053 RecoTauBuilderConePlugin::RecoTauBuilderConePlugin(
00054     const edm::ParameterSet& pset):RecoTauBuilderPlugin(pset),
00055     qcuts_(pset.getParameter<edm::ParameterSet>("qualityCuts")),
00056     usePFLeptonsAsChargedHadrons_(pset.getParameter<bool>("usePFLeptons")),
00057     leadObjecPtThreshold_(pset.getParameter<double>("leadObjectPt")),
00058     matchingCone_(pset.getParameter<std::string>("matchingCone")),
00059     signalConeChargedHadrons_(pset.getParameter<std::string>(
00060             "signalConeChargedHadrons")),
00061     isoConeChargedHadrons_(
00062         pset.getParameter<std::string>("isoConeChargedHadrons")),
00063     signalConePiZeros_(
00064         pset.getParameter<std::string>("signalConePiZeros")),
00065     isoConePiZeros_(
00066         pset.getParameter<std::string>("isoConePiZeros")),
00067     signalConeNeutralHadrons_(
00068         pset.getParameter<std::string>("signalConeNeutralHadrons")),
00069     isoConeNeutralHadrons_(
00070         pset.getParameter<std::string>("isoConeNeutralHadrons"))
00071 {}
00072 
00073 RecoTauBuilderConePlugin::return_type RecoTauBuilderConePlugin::operator()(
00074     const reco::PFJetRef& jet,
00075     const std::vector<RecoTauPiZero>& piZeros) const {
00076   // Get access to our cone tools
00077   using namespace cone;
00078   // Define output.  We only produce one tau per jet for the cone algo.
00079   output_type output;
00080 
00081   // Our tau builder - the true indicates to automatically copy gamma candidates
00082   // from the pizeros.
00083   RecoTauConstructor tau(jet, getPFCands(), true);
00084   // Setup our quality cuts to use the current vertex (supplied by base class)
00085   qcuts_.setPV(primaryVertex());
00086 
00087   typedef std::vector<PFCandidatePtr> PFCandPtrs;
00088 
00089   // Get the PF Charged hadrons + quality cuts
00090   PFCandPtrs pfchs;
00091   if (!usePFLeptonsAsChargedHadrons_) {
00092     pfchs = qcuts_.filterRefs(pfCandidates(*jet, reco::PFCandidate::h));
00093   } else {
00094     // Check if we want to include electrons in muons in "charged hadron"
00095     // collection.  This is the preferred behavior, as the PF lepton selections
00096     // are very loose.
00097     pfchs = qcuts_.filterRefs(pfChargedCands(*jet));
00098   }
00099 
00100   // Get the PF gammas
00101   PFCandPtrs pfGammas = qcuts_.filterRefs(
00102       pfCandidates(*jet, reco::PFCandidate::gamma));
00103   // Neutral hadrons
00104   PFCandPtrs pfnhs = qcuts_.filterRefs(
00105       pfCandidates(*jet, reco::PFCandidate::h0));
00106 
00107   /***********************************************
00108    ******     Lead Candidate Finding    **********
00109    ***********************************************/
00110 
00111   // Define our matching cone and filters
00112   double matchingCone = matchingCone_(*jet);
00113   PFCandPtrDRFilter matchingConeFilter(jet->p4(), 0, matchingCone);
00114 
00115   // Find the maximum PFCharged hadron in the matching cone.  The call to
00116   // PFCandidates always a sorted list, so we can just take the first if it
00117   // if it exists.
00118   PFCandidatePtr leadPFCH;
00119   PFCandPtrs::iterator leadPFCH_iter =
00120       std::find_if(pfchs.begin(), pfchs.end(), matchingConeFilter);
00121 
00122   if (leadPFCH_iter != pfchs.end()) {
00123     leadPFCH = *leadPFCH_iter;
00124     // Set leading candidate
00125     tau.setleadPFChargedHadrCand(leadPFCH);
00126   } else {
00127     // If there is no leading charged candidate at all, return nothing - the
00128     // producer class that owns the plugin will build a null tau if desired.
00129     return output.release();
00130   }
00131 
00132   // Find the leading neutral candidate
00133   PFCandidatePtr leadPFGamma;
00134   PFCandPtrs::iterator leadPFGamma_iter =
00135       std::find_if(pfGammas.begin(), pfGammas.end(), matchingConeFilter);
00136 
00137   if (leadPFGamma_iter != pfGammas.end()) {
00138     leadPFGamma = *leadPFGamma_iter;
00139     // Set leading neutral candidate
00140     tau.setleadPFNeutralCand(leadPFGamma);
00141   }
00142 
00143   PFCandidatePtr leadPFCand;
00144   // Always use the leadPFCH if it is above our threshold
00145   if (leadPFCH.isNonnull() && leadPFCH->pt() > leadObjecPtThreshold_) {
00146     leadPFCand = leadPFCH;
00147   } else if (leadPFGamma.isNonnull() &&
00148              leadPFGamma->pt() > leadObjecPtThreshold_) {
00149     // Otherwise use the lead Gamma if it is above threshold
00150     leadPFCand = leadPFGamma;
00151   } else {
00152     // If both are too low PT, just take the charged one
00153     leadPFCand = leadPFCH;
00154   }
00155 
00156   tau.setleadPFCand(leadPFCand);
00157 
00158   // Our cone axis is defined about the lead charged hadron
00159   reco::Candidate::LorentzVector coneAxis = leadPFCH->p4();
00160 
00161   /***********************************************
00162    ******     Cone Construction         **********
00163    ***********************************************/
00164 
00165   // Define the signal and isolation cone sizes for this jet and build filters
00166   // to select elements in the given DeltaR regions
00167 
00168   PFCandPtrDRFilter signalConePFCHFilter(
00169       coneAxis, -0.1, signalConeChargedHadrons_(*jet));
00170   PFCandPtrDRFilter signalConePFNHFilter(
00171       coneAxis, -0.1, signalConeNeutralHadrons_(*jet));
00172   PiZeroDRFilter signalConePiZeroFilter(
00173       coneAxis, -0.1, signalConePiZeros_(*jet));
00174 
00175   PFCandPtrDRFilter isoConePFCHFilter(
00176       coneAxis, signalConeChargedHadrons_(*jet), isoConeChargedHadrons_(*jet));
00177   PFCandPtrDRFilter isoConePFNHFilter(
00178       coneAxis, signalConeNeutralHadrons_(*jet), isoConeNeutralHadrons_(*jet));
00179   PiZeroDRFilter isoConePiZeroFilter(
00180       coneAxis, signalConePiZeros_(*jet), isoConePiZeros_(*jet));
00181 
00182   // Build signal charged hadrons
00183   tau.addPFCands(RecoTauConstructor::kSignal,
00184                  RecoTauConstructor::kChargedHadron,
00185                  PFCandPtrDRFilterIter(signalConePFCHFilter, pfchs.begin(),
00186                                        pfchs.end()),
00187                  PFCandPtrDRFilterIter(signalConePFCHFilter, pfchs.end(),
00188                                        pfchs.end()));
00189 
00190   // Build signal neutral hadrons
00191   tau.addPFCands(RecoTauConstructor::kSignal,
00192                  RecoTauConstructor::kNeutralHadron,
00193                  PFCandPtrDRFilterIter(signalConePFNHFilter, pfnhs.begin(),
00194                                        pfnhs.end()),
00195                  PFCandPtrDRFilterIter(signalConePFNHFilter, pfnhs.end(),
00196                                        pfnhs.end()));
00197 
00198   // Build signal PiZeros
00199   tau.addPiZeros(RecoTauConstructor::kSignal,
00200                  PiZeroDRFilterIter(signalConePiZeroFilter,
00201                                     piZeros.begin(), piZeros.end()),
00202                  PiZeroDRFilterIter(signalConePiZeroFilter,
00203                                     piZeros.end(), piZeros.end()));
00204 
00205   // Build isolation charged hadrons
00206   tau.addPFCands(RecoTauConstructor::kIsolation,
00207                  RecoTauConstructor::kChargedHadron,
00208                  PFCandPtrDRFilterIter(isoConePFCHFilter, pfchs.begin(),
00209                                        pfchs.end()),
00210                  PFCandPtrDRFilterIter(isoConePFCHFilter, pfchs.end(),
00211                                        pfchs.end()));
00212 
00213   // Build isolation neutral hadrons
00214   tau.addPFCands(RecoTauConstructor::kIsolation,
00215                  RecoTauConstructor::kNeutralHadron,
00216                  PFCandPtrDRFilterIter(isoConePFNHFilter, pfnhs.begin(),
00217                                        pfnhs.end()),
00218                  PFCandPtrDRFilterIter(isoConePFNHFilter, pfnhs.end(),
00219                                        pfnhs.end()));
00220 
00221   // Build isolation PiZeros
00222   tau.addPiZeros(RecoTauConstructor::kIsolation,
00223                  PiZeroDRFilterIter(isoConePiZeroFilter, piZeros.begin(),
00224                                     piZeros.end()),
00225                  PiZeroDRFilterIter(isoConePiZeroFilter, piZeros.end(),
00226                                     piZeros.end()));
00227 
00228   // Put our built tau in the output - 'false' indicates don't build the
00229   // leading candidtes, we already did that explicitly above.
00230 
00231   output.push_back(tau.get(false));
00232   return output.release();
00233 }
00234 }}  // end namespace reco::tauk
00235 
00236 #include "FWCore/Framework/interface/MakerMacros.h"
00237 DEFINE_EDM_PLUGIN(RecoTauBuilderPluginFactory,
00238                   reco::tau::RecoTauBuilderConePlugin,
00239                   "RecoTauBuilderConePlugin");