CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes

ElectronIdMVAProducer Class Reference

Inheritance diagram for ElectronIdMVAProducer:
edm::EDFilter edm::ProducerBase edm::ProductRegistryHelper

List of all members.

Public Member Functions

 ElectronIdMVAProducer (const edm::ParameterSet &)
 ~ElectronIdMVAProducer ()

Private Member Functions

virtual bool filter (edm::Event &, const edm::EventSetup &)

Private Attributes

double _Rho
edm::InputTag electronTag_
string method_
EGammaMvaEleEstimatormvaID_
vector< string > mvaWeightFiles_
bool NoIP_
edm::InputTag reducedEBRecHitCollection_
edm::InputTag reducedEERecHitCollection_
bool Trig_
bool verbose_
edm::InputTag vertexTag_

Detailed Description

Definition at line 26 of file ElectronIdMVAProducer.cc.


Constructor & Destructor Documentation

ElectronIdMVAProducer::ElectronIdMVAProducer ( const edm::ParameterSet iConfig) [explicit]

Definition at line 62 of file ElectronIdMVAProducer.cc.

References edm::FileInPath::fullPath(), edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), compare_using_db::ifile, EGammaMvaEleEstimator::kNonTrig, EGammaMvaEleEstimator::kTrig, and EGammaMvaEleEstimator::kTrigNoIP.

                                                                           {
        verbose_ = iConfig.getUntrackedParameter<bool>("verbose", false);
        vertexTag_ = iConfig.getParameter<edm::InputTag>("vertexTag");
        electronTag_ = iConfig.getParameter<edm::InputTag>("electronTag");
        reducedEBRecHitCollection_ = iConfig.getParameter<edm::InputTag>("reducedEBRecHitCollection");
        reducedEERecHitCollection_ = iConfig.getParameter<edm::InputTag>("reducedEERecHitCollection");
        method_ = iConfig.getParameter<string>("method");
        std::vector<string> fpMvaWeightFiles = iConfig.getParameter<std::vector<std::string> >("mvaWeightFile");
        Trig_ = iConfig.getParameter<bool>("Trig");
        NoIP_ = iConfig.getParameter<bool>("NoIP");

        produces<edm::ValueMap<float> >("");

        mvaID_ = new EGammaMvaEleEstimator();
 
        EGammaMvaEleEstimator::MVAType type_;
        if(Trig_ && !NoIP_){type_ = EGammaMvaEleEstimator::kTrig;}
         
        if(Trig_ && NoIP_){type_ = EGammaMvaEleEstimator::kTrigNoIP;}
         
        if(!Trig_){type_ = EGammaMvaEleEstimator::kNonTrig;}

        bool manualCat_ = true;

        string path_mvaWeightFileEleID;
        for(unsigned ifile=0 ; ifile < fpMvaWeightFiles.size() ; ++ifile) {
          path_mvaWeightFileEleID = edm::FileInPath ( fpMvaWeightFiles[ifile].c_str() ).fullPath();
          mvaWeightFiles_.push_back(path_mvaWeightFileEleID);
        }
        
        mvaID_->initialize(method_, type_, manualCat_, mvaWeightFiles_);

}
ElectronIdMVAProducer::~ElectronIdMVAProducer ( )

Definition at line 97 of file ElectronIdMVAProducer.cc.

{
 
   // do anything here that needs to be done at desctruction time
   // (e.g. close files, deallocate resources etc.)

}

Member Function Documentation

bool ElectronIdMVAProducer::filter ( edm::Event iEvent,
const edm::EventSetup iSetup 
) [private, virtual]

Implements edm::EDFilter.

Definition at line 111 of file ElectronIdMVAProducer.cc.

References alignCSCRings::e, edm::helper::Filler< Map >::fill(), edm::EventSetup::get(), edm::Event::getByLabel(), edm::helper::Filler< Map >::insert(), dbtoconf::out, AlCaHLTBitMon_ParallelJobs::p, edm::Event::put(), makeHLTPrescaleTable::values, and GoodVertex_cfg::vertexCollection.

                                                                                {
        using namespace edm;

        std::auto_ptr<edm::ValueMap<float> > out(new edm::ValueMap<float>() );

        Handle<reco::VertexCollection>  vertexCollection;
        iEvent.getByLabel(vertexTag_, vertexCollection);

        Vertex dummy;
        const Vertex *pv = &dummy;
        if ( vertexCollection->size() != 0) {
          pv = &*vertexCollection->begin();
        } else { // create a dummy PV
          Vertex::Error e;
          e(0, 0) = 0.0015 * 0.0015;
          e(1, 1) = 0.0015 * 0.0015;
          e(2, 2) = 15. * 15.;
          Vertex::Point p(0, 0, 0);
          dummy = Vertex(p, e, 0, 0, 0);
        }

        EcalClusterLazyTools lazyTools(iEvent, iSetup, reducedEBRecHitCollection_, reducedEERecHitCollection_);

        edm::ESHandle<TransientTrackBuilder> builder;
        iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder", builder);
        TransientTrackBuilder thebuilder = *(builder.product());

        Handle<reco::GsfElectronCollection> egCollection;
        iEvent.getByLabel(electronTag_,egCollection);
        const reco::GsfElectronCollection egCandidates = (*egCollection.product());

        _Rho=0;
        edm::Handle<double> rhoPtr;
        const edm::InputTag eventrho("kt6PFJets", "rho");
        iEvent.getByLabel(eventrho,rhoPtr);
        _Rho=*rhoPtr;

        std::vector<float> values;
        values.reserve(egCollection->size());
   
        for ( reco::GsfElectronCollection::const_iterator egIter = egCandidates.begin(); egIter != egCandidates.end(); ++egIter) {

          double mvaVal = -999999;
          if(!NoIP_){
          mvaVal = mvaID_->mvaValue( *egIter, *pv,thebuilder,lazyTools, verbose_);
          }
          if(NoIP_){
            mvaVal = mvaID_->mvaValue( *egIter, *pv, _Rho,/*thebuilder,*/lazyTools, verbose_);
          }
          
          values.push_back( mvaVal ); 
        }

        edm::ValueMap<float>::Filler filler(*out);
        filler.insert(egCollection, values.begin(), values.end() );
        filler.fill();

        iEvent.put(out);

        return true;
}

Member Data Documentation

double ElectronIdMVAProducer::_Rho [private]

Definition at line 41 of file ElectronIdMVAProducer.cc.

Definition at line 37 of file ElectronIdMVAProducer.cc.

Definition at line 42 of file ElectronIdMVAProducer.cc.

Definition at line 47 of file ElectronIdMVAProducer.cc.

vector<string> ElectronIdMVAProducer::mvaWeightFiles_ [private]

Definition at line 43 of file ElectronIdMVAProducer.cc.

Definition at line 45 of file ElectronIdMVAProducer.cc.

Definition at line 38 of file ElectronIdMVAProducer.cc.

Definition at line 39 of file ElectronIdMVAProducer.cc.

Definition at line 44 of file ElectronIdMVAProducer.cc.

Definition at line 35 of file ElectronIdMVAProducer.cc.

Definition at line 36 of file ElectronIdMVAProducer.cc.