CMS 3D CMS Logo

Classes | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes

PhysicsTools::TrainProcessor Class Reference

#include <TrainProcessor.h>

Inheritance diagram for PhysicsTools::TrainProcessor:
PhysicsTools::Source PhysicsTools::ProcessRegistry< Base_t, CalibBase_t, Parent_t >::Factory

List of all members.

Classes

struct  Dummy
struct  Registry
struct  SigBkg

Public Types

typedef TrainerMonitoring::Module Monitoring
typedef
edmplugin::PluginFactory
< Dummy *()> 
PluginFactory

Public Member Functions

virtual void cleanup ()
virtual void configure (XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *config)
void doTrainBegin ()
void doTrainData (const std::vector< double > *values, bool target, double weight, bool train, bool test)
void doTrainEnd ()
virtual Calibration::VarProcessorgetCalibration () const
virtual Variable::Flags getDefaultFlags () const
const char * getId () const
virtual bool load ()
virtual void passFlags (const std::vector< Variable::Flags > &flags)
virtual void save ()
 TrainProcessor (const char *name, const AtomicId *id, MVATrainer *trainer)
virtual ~TrainProcessor ()

Protected Member Functions

bool exists (const std::string &name)
virtual void * requestObject (const std::string &name) const
virtual void testData (const std::vector< double > *values, bool target, double weight, bool trainedOn)
virtual void trainBegin ()
virtual void trainData (const std::vector< double > *values, bool target, double weight)
virtual void trainEnd ()

Protected Attributes

Monitoringmonitoring
std::string name
MVATrainertrainer

Private Attributes

std::vector< SigBkgmonHistos
MonitoringmonModule

Detailed Description

Definition at line 28 of file TrainProcessor.h.


Member Typedef Documentation

Definition at line 40 of file TrainProcessor.h.

typedef edmplugin::PluginFactory<Dummy*()> PhysicsTools::TrainProcessor::PluginFactory

Definition at line 70 of file TrainProcessor.h.


Constructor & Destructor Documentation

PhysicsTools::TrainProcessor::TrainProcessor ( const char *  name,
const AtomicId id,
MVATrainer trainer 
)

Definition at line 20 of file TrainProcessor.cc.

PhysicsTools::TrainProcessor::~TrainProcessor ( ) [virtual]

Definition at line 27 of file TrainProcessor.cc.

{
}

Member Function Documentation

virtual void PhysicsTools::TrainProcessor::cleanup ( void  ) [inline, virtual]

Definition at line 65 of file TrainProcessor.h.

Referenced by PhysicsTools::MVATrainer::~MVATrainer().

{}
virtual void PhysicsTools::TrainProcessor::configure ( XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *  config) [inline, virtual]

Definition at line 51 of file TrainProcessor.h.

{}
void PhysicsTools::TrainProcessor::doTrainBegin ( )

Definition at line 31 of file TrainProcessor.cc.

References PhysicsTools::TrainerMonitoring::Module::book(), PhysicsTools::MVATrainer::bookMonitor(), PhysicsTools::TrainProcessor::SigBkg::entries, PhysicsTools::SourceVariableSet::get(), PhysicsTools::Source::getInputs(), PhysicsTools::Variable::getName(), PhysicsTools::Source::getName(), PhysicsTools::SourceVariable::getSource(), PhysicsTools::TrainProcessor::SigBkg::histo, infinity, PhysicsTools::Source::inputs, PhysicsTools::TrainProcessor::SigBkg::max, PhysicsTools::TrainProcessor::SigBkg::min, monHistos, monitoring, monModule, name, PhysicsTools::TrainProcessor::SigBkg::overflow, PhysicsTools::TrainProcessor::SigBkg::sameBinning, LaserTracksInput_cfi::source, trainBegin(), trainer, and PhysicsTools::TrainProcessor::SigBkg::underflow.

{
        bool booked = false;
        unsigned int nBins = 50;

        if (!monitoring) {
                const char *source = getName();
                if (source) {
                        monitoring = trainer->bookMonitor(name + "_" + source);
                        monModule = trainer->bookMonitor(std::string("input_") +
                                                         source);
                } else {
                        monModule = trainer->bookMonitor("output");
                        nBins = 400;
                }

                booked = monModule != 0;
        }

        if (booked) {
                std::vector<SourceVariable*> inputs = getInputs().get();
                for(std::vector<SourceVariable*>::const_iterator iter =
                        inputs.begin(); iter != inputs.end(); ++iter) {

                        SourceVariable *var = *iter;
                        std::string name =
                                (const char*)var->getSource()->getName()
                                + std::string("_")
                                + (const char*)var->getName();

                        SigBkg pair;
                        pair.entries[0] = pair.entries[1] = 0;
                        pair.histo[0] = monModule->book<TH1F>(name + "_bkg",
                                (name + "_bkg").c_str(),
                                (name + " background").c_str(), nBins, 0, 0);
                        pair.histo[1] = monModule->book<TH1F>(name + "_sig",
                                (name + "_sig").c_str(),
                                (name + " signal").c_str(), nBins, 0, 0);
                        pair.underflow[0] = pair.underflow[1] = 0.0;
                        pair.overflow[0] = pair.overflow[1] = 0.0;

                        pair.sameBinning = true;        // use as default
                        if (monitoring) {
                                pair.min = -std::numeric_limits<double>::infinity();
                                pair.max = +std::numeric_limits<double>::infinity();
                        } else {
                                pair.min = -99999.0;
                                pair.max = +99999.0;
                        }

                        monHistos.push_back(pair);
                }
        }

        trainBegin();
}
void PhysicsTools::TrainProcessor::doTrainData ( const std::vector< double > *  values,
bool  target,
double  weight,
bool  train,
bool  test 
)

Definition at line 88 of file TrainProcessor.cc.

References min, monHistos, monModule, filterCSVwithJSON::target, testData(), trainData(), create_public_pileup_plots::vals, relativeConstraints::value, and CommonMethods::weight().

{
        if (monModule && test) {
                for(std::vector<SigBkg>::iterator iter = monHistos.begin();
                    iter != monHistos.end(); ++iter) {
                        const std::vector<double> &vals =
                                        values[iter - monHistos.begin()];
                        for(std::vector<double>::const_iterator value =
                                vals.begin(); value != vals.end(); ++value) {

                                iter->entries[target]++;

                                if (*value <= iter->min) {
                                        iter->underflow[target] += weight;
                                        continue;
                                } else if (*value >= iter->max) {
                                        iter->overflow[target] += weight;
                                        continue;
                                }

                                iter->histo[target]->Fill(*value, weight);

                                if (iter->sameBinning)
                                        iter->histo[!target]->Fill(*value, 0);
                        }
                }
        }

        if (train)
                trainData(values, target, weight);
        if (test)
                testData(values, target, weight, train);
}
void PhysicsTools::TrainProcessor::doTrainEnd ( )

Definition at line 124 of file TrainProcessor.cc.

References i, monHistos, monModule, and trainEnd().

{
        trainEnd();

        if (monModule) {
                for(std::vector<SigBkg>::const_iterator iter =
                        monHistos.begin(); iter != monHistos.end(); ++iter) {

                        for(unsigned int i = 0; i < 2; i++) {
                                Int_t oBin = iter->histo[i]->GetNbinsX() + 1;
                                iter->histo[i]->SetBinContent(0,
                                        iter->histo[i]->GetBinContent(0) +
                                        iter->underflow[i]);
                                iter->histo[i]->SetBinContent(oBin,
                                        iter->histo[i]->GetBinContent(oBin) +
                                        iter->overflow[i]);
                                iter->histo[i]->SetEntries(iter->entries[i]);
                        }
                }

                monModule = 0;
        }
}
bool PhysicsTools::TrainProcessor::exists ( const std::string &  name) [inline, protected]

Definition at line 83 of file TrainProcessor.h.

        { return boost::filesystem::exists(name.c_str()); }
virtual Calibration::VarProcessor* PhysicsTools::TrainProcessor::getCalibration ( ) const [inline, virtual]
virtual Variable::Flags PhysicsTools::TrainProcessor::getDefaultFlags ( ) const [inline, virtual]

Definition at line 47 of file TrainProcessor.h.

References PhysicsTools::Variable::FLAG_ALL.

        { return Variable::FLAG_ALL; }
const char* PhysicsTools::TrainProcessor::getId ( ) const [inline]

Definition at line 67 of file TrainProcessor.h.

References name.

{ return name.c_str(); }
virtual bool PhysicsTools::TrainProcessor::load ( ) [inline, virtual]

Definition at line 63 of file TrainProcessor.h.

{ return true; }
virtual void PhysicsTools::TrainProcessor::passFlags ( const std::vector< Variable::Flags > &  flags) [inline, virtual]

Definition at line 54 of file TrainProcessor.h.

{}
virtual void* PhysicsTools::TrainProcessor::requestObject ( const std::string &  name) const [inline, protected, virtual]

Definition at line 80 of file TrainProcessor.h.

        { return 0; }
virtual void PhysicsTools::TrainProcessor::save ( ) [inline, virtual]

Definition at line 64 of file TrainProcessor.h.

{}
virtual void PhysicsTools::TrainProcessor::testData ( const std::vector< double > *  values,
bool  target,
double  weight,
bool  trainedOn 
) [inline, protected, virtual]

Definition at line 76 of file TrainProcessor.h.

Referenced by doTrainData().

                                                                          {}
virtual void PhysicsTools::TrainProcessor::trainBegin ( ) [inline, protected, virtual]

Definition at line 73 of file TrainProcessor.h.

Referenced by doTrainBegin().

{}
virtual void PhysicsTools::TrainProcessor::trainData ( const std::vector< double > *  values,
bool  target,
double  weight 
) [inline, protected, virtual]

Definition at line 74 of file TrainProcessor.h.

Referenced by doTrainData().

                                                           {}
virtual void PhysicsTools::TrainProcessor::trainEnd ( ) [inline, protected, virtual]

Definition at line 78 of file TrainProcessor.h.

References PhysicsTools::Source::trained.

Referenced by doTrainEnd().

{ trained = true; }

Member Data Documentation

Definition at line 101 of file TrainProcessor.h.

Referenced by doTrainBegin(), doTrainData(), and doTrainEnd().

Definition at line 88 of file TrainProcessor.h.

Referenced by doTrainBegin().

Definition at line 102 of file TrainProcessor.h.

Referenced by doTrainBegin(), doTrainData(), and doTrainEnd().

std::string PhysicsTools::TrainProcessor::name [protected]

Reimplemented from PhysicsTools::Source.

Definition at line 86 of file TrainProcessor.h.

Referenced by doTrainBegin(), and getId().

Definition at line 87 of file TrainProcessor.h.

Referenced by doTrainBegin().