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 edm::ProductID tauProductID = taus.id();
00075
00076
00077 std::auto_ptr<TauDiscriminator> output(new TauDiscriminator(TauRefProd(taus)));
00078
00079 size_t nTaus = taus->size();
00080
00081
00082 size_t nPrediscriminants = prediscriminants_.size();
00083 for( size_t iDisc = 0; iDisc < nPrediscriminants; ++iDisc )
00084 {
00085 prediscriminants_[iDisc].fill(event);
00086
00087
00088
00089 edm::ProductID discKeyId =
00090 prediscriminants_[iDisc].handle->keyProduct().id();
00091 if (tauProductID != discKeyId) {
00092 throw cms::Exception("MisconfiguredPrediscriminant")
00093 << "The tau collection with input tag " << TauProducer_
00094 << " has product ID: " << tauProductID
00095 << " but the pre-discriminator with input tag "
00096 << prediscriminants_[iDisc].label
00097 << " is keyed with product ID: " << discKeyId << std::endl;
00098 }
00099 }
00100
00101
00102 for( size_t iTau = 0; iTau < nTaus; ++iTau )
00103 {
00104
00105 TauRef tauRef(taus, iTau);
00106
00107 bool passesPrediscriminants = true;
00108
00109 for( size_t iDisc = 0; iDisc < nPrediscriminants; ++iDisc )
00110 {
00111
00112 double discResult = (*prediscriminants_[iDisc].handle)[tauRef];
00113 uint8_t thisPasses = ( discResult > prediscriminants_[iDisc].cut ) ? 1 : 0;
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131 if( thisPasses ^ andPrediscriminants_ )
00132 {
00133 passesPrediscriminants = ( andPrediscriminants_ ? 0 : 1 );
00134 break;
00135 }
00136 }
00137
00138 double result = prediscriminantFailValue_;
00139 if( passesPrediscriminants )
00140 {
00141
00142 result = discriminate(tauRef);
00143 }
00144
00145
00146 output->setValue(iTau, result);
00147 }
00148 event.put(output);
00149 }
00150
00151
00152 template<> std::string getProducerString<PFTau>() { return "PFTauProducer"; }
00153 template<> std::string getProducerString<CaloTau>() { return "CaloTauProducer"; }
00154
00155
00156 template class TauDiscriminationProducerBase<PFTau, PFTauDiscriminator>;
00157 template class TauDiscriminationProducerBase<CaloTau, CaloTauDiscriminator>;