CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MVATrainerLooperImpl.h
Go to the documentation of this file.
1 #ifndef PhysicsTools_MVATrainer_MVATrainerLooperImpl_h
2 #define PhysicsTools_MVATrainer_MVATrainerLooperImpl_h
3 
4 #include <string>
5 #include <memory>
6 
7 #include <boost/shared_ptr.hpp>
8 
12 
15 
16 namespace PhysicsTools {
17 
18 template<class Record_t>
20  public:
22  MVATrainerLooper(params)
23  {
24  setWhatProduced(this, "trainer");
25  addTrainer(new Trainer(params));
26  }
27 
28  virtual ~MVATrainerLooperImpl() {}
29 
30  boost::shared_ptr<Calibration::MVAComputer>
31  produce(const Record_t &record)
32  { return (*getTrainers().begin())->getCalibration(); }
33 };
34 
35 template<class Record_t>
37  public:
38  enum { kTrainer, kTrained };
39 
41  MVATrainerLooper(params)
42  {
43  setWhatProduced(this, edm::es::label("trainer", kTrainer)
44  ("trained", kTrained));
45 
46  std::vector<edm::ParameterSet> trainers =
47  params.getParameter<std::vector<edm::ParameterSet> >(
48  "trainers");
49 
50  for(std::vector<edm::ParameterSet>::const_iterator iter =
51  trainers.begin(); iter != trainers.end(); iter++)
52 
53  addTrainer(new Trainer(*iter));
54  }
55 
57 
61  produce(const Record_t &record)
62  {
63  boost::shared_ptr<MVATrainerContainer> trainerCalib(
64  new MVATrainerContainer());
65  TrainContainer trainedCalib;
66 
67  bool untrained = false;
69  getTrainers().begin();
70  iter != getTrainers().end(); iter++) {
71  Trainer *trainer = dynamic_cast<Trainer*>(*iter);
72  TrainObject calib = trainer->getCalibration();
73 
74  trainerCalib->addTrainer(trainer->calibrationRecord,
75  calib);
76  if (calib) {
77  untrained = true;
78  continue;
79  }
80 
81  if (!trainedCalib)
82  trainedCalib = TrainContainer(
84 
85  trainedCalib->add(trainer->calibrationRecord) =
86  *trainer->getTrainer()->getCalibration();
87  }
88 
89  if (untrained)
90  trainedCalib = TrainContainer(
92 
94  trainedESLabel(trainerCalib);
95 
96  return edm::es::products(trainedESLabel,
97  edm::es::l<kTrained>(trainedCalib));
98  }
99 
100  protected:
102  public:
103  Trainer(const edm::ParameterSet &params) :
104  MVATrainerLooper::Trainer(params),
105  calibrationRecord(params.getParameter<std::string>(
106  "calibrationRecord")) {}
107 
108  std::string calibrationRecord;
109  };
110 };
111 
112 } // namespace PhysicsTools
113 
114 #endif // PhysicsTools_MVATrainer_MVATrainerLooperImpl_h
T getParameter(std::string const &) const
Label label(const std::string &iString, int iIndex)
Definition: es_Label.h:89
void addTrainer(Trainer *trainer)
JetCorrectorParameters::Record record
Definition: classes.h:11
void setWhatProduced(T *iThis, const es::Label &iLabel=es::Label())
Definition: ESProducer.h:115
boost::shared_ptr< Calibration::MVAComputer > produce(const Record_t &record)
MVATrainerComputer * calib
Definition: MVATrainer.cc:64
ESProducts< T, S > products(const T &i1, const S &i2)
Definition: ESProducts.h:189
edm::ESProducts< edm::es::L< Calibration::MVAComputerContainer, kTrainer >, edm::es::L< Calibration::MVAComputerContainer, kTrained > > produce(const Record_t &record)
boost::shared_ptr< Calibration::MVAComputerContainer > TrainContainer
const TrainerContainer & getTrainers() const
const TrainObject getCalibration() const
boost::shared_ptr< Calibration::MVAComputer > TrainObject
Calibration::MVAComputer * getCalibration() const
Definition: MVATrainer.cc:1146
std::vector< Trainer * >::const_iterator const_iterator
#define begin
Definition: vmac.h:31
const MVATrainer * getTrainer() const
MVATrainerContainerLooperImpl(const edm::ParameterSet &params)
MVATrainerLooperImpl(const edm::ParameterSet &params)