Go to the documentation of this file.00001 #include "RecoTauTag/RecoTau/interface/TauDiscriminationProducerBase.h"
00002
00003 using namespace reco;
00004
00005
00006 template<class TauType, class TauDiscriminator>
00007 TauDiscriminationProducerBase<TauType, TauDiscriminator>::TauDiscriminationProducerBase()
00008 {
00009 throw cms::Exception("TauDiscriminationProducerBase") << " -- default ctor called; derived classes must call " <<
00010 "TauDiscriminationProducerBase(const ParameterSet&)";
00011 }
00012
00013
00014 template<class TauType, class TauDiscriminator>
00015 TauDiscriminationProducerBase<TauType, TauDiscriminator>::TauDiscriminationProducerBase(const edm::ParameterSet& iConfig)
00016 {
00017
00018 TauProducer_ = iConfig.getParameter<edm::InputTag>(getProducerString<TauType>());
00019
00020
00021
00022 const edm::ParameterSet& prediscriminantConfig = iConfig.getParameter<edm::ParameterSet>("Prediscriminants");
00023
00024
00025 std::string pdBoolOperator = prediscriminantConfig.getParameter<std::string>("BooleanOperator");
00026
00027 transform(pdBoolOperator.begin(), pdBoolOperator.end(), pdBoolOperator.begin(), ::tolower);
00028
00029 if( pdBoolOperator == "and" )
00030 {
00031 andPrediscriminants_ = 0x1;
00032 }
00033 else if ( pdBoolOperator == "or" )
00034 {
00035 andPrediscriminants_ = 0x0;
00036 }
00037 else
00038 {
00039 throw cms::Exception("TauDiscriminationProducerBase") << "PrediscriminantBooleanOperator defined incorrectly, options are: AND,OR";
00040 }
00041
00042
00043 std::vector<std::string> prediscriminantsNames = prediscriminantConfig.getParameterNamesForType<edm::ParameterSet>();
00044
00045 for( std::vector<std::string>::const_iterator iDisc = prediscriminantsNames.begin();
00046 iDisc != prediscriminantsNames.end(); ++iDisc )
00047 {
00048 const edm::ParameterSet& iPredisc = prediscriminantConfig.getParameter<edm::ParameterSet>(*iDisc);
00049 const edm::InputTag& label = iPredisc.getParameter<edm::InputTag>("Producer");
00050 double cut = iPredisc.getParameter<double>("cut");
00051
00052 TauDiscInfo thisDiscriminator;
00053 thisDiscriminator.label = label;
00054 thisDiscriminator.cut = cut;
00055 prediscriminants_.push_back(thisDiscriminator);
00056 }
00057
00058 prediscriminantFailValue_ = 0.;
00059
00060
00061 produces<TauDiscriminator>();
00062 }
00063
00064 template<class TauType, class TauDiscriminator>
00065 void TauDiscriminationProducerBase<TauType, TauDiscriminator>::produce(edm::Event& event, const edm::EventSetup& eventSetup)
00066 {
00067
00068 beginEvent(event, eventSetup);
00069
00070
00071 edm::Handle<TauCollection> taus;
00072 event.getByLabel(TauProducer_, taus);
00073
00074
00075 std::auto_ptr<TauDiscriminator> output(new TauDiscriminator(TauRefProd(taus)));
00076
00077 size_t nTaus = taus->size();
00078
00079
00080 size_t nPrediscriminants = prediscriminants_.size();
00081 for( size_t iDisc = 0; iDisc < nPrediscriminants; ++iDisc )
00082 {
00083 prediscriminants_[iDisc].fill(event);
00084 }
00085
00086
00087 for( size_t iTau = 0; iTau < nTaus; ++iTau )
00088 {
00089
00090 TauRef tauRef(taus, iTau);
00091
00092 bool passesPrediscriminants = true;
00093
00094 for( size_t iDisc = 0; iDisc < nPrediscriminants; ++iDisc )
00095 {
00096
00097 double discResult = (*prediscriminants_[iDisc].handle)[tauRef];
00098 uint8_t thisPasses = ( discResult > prediscriminants_[iDisc].cut ) ? 1 : 0;
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116 if( thisPasses ^ andPrediscriminants_ )
00117 {
00118 passesPrediscriminants = ( andPrediscriminants_ ? 0 : 1 );
00119 break;
00120 }
00121 }
00122
00123 double result = prediscriminantFailValue_;
00124 if( passesPrediscriminants )
00125 {
00126
00127 result = discriminate(tauRef);
00128 }
00129
00130
00131 output->setValue(iTau, result);
00132 }
00133 event.put(output);
00134 }
00135
00136
00137 template<> std::string getProducerString<PFTau>() { return "PFTauProducer"; }
00138 template<> std::string getProducerString<CaloTau>() { return "CaloTauProducer"; }
00139
00140
00141 template class TauDiscriminationProducerBase<PFTau, PFTauDiscriminator>;
00142 template class TauDiscriminationProducerBase<CaloTau, CaloTauDiscriminator>;