CMS 3D CMS Logo

ElectronIdMVAProducer.cc
Go to the documentation of this file.
1 // system include files
2 #include <memory>
3 
4 // user include files
7 
10 
20 //
21 // class declaration
22 //
23 
25 public:
27  ~ElectronIdMVAProducer() override;
28 
29 private:
30  bool filter(edm::Event&, const edm::EventSetup&) override;
31 
32  // ----------member data ---------------------------
33  bool verbose_;
39 
40  double _Rho;
42  std::vector<std::string> mvaWeightFiles_;
43  bool Trig_;
44  bool NoIP_;
45 
47 };
48 
49 //
50 // constants, enums and typedefs
51 //
52 
53 //
54 // static data member definitions
55 //
56 
57 //
58 // constructors and destructor
59 //
61  verbose_ = iConfig.getUntrackedParameter<bool>("verbose", false);
62  vertexToken_ = consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("vertexTag"));
63  electronToken_ = consumes<reco::GsfElectronCollection>(iConfig.getParameter<edm::InputTag>("electronTag"));
64  eventrhoToken_ = consumes<double>(edm::InputTag("kt6PFJets", "rho"));
66  consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("reducedEBRecHitCollection"));
68  consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("reducedEERecHitCollection"));
69  method_ = iConfig.getParameter<std::string>("method");
70  std::vector<std::string> fpMvaWeightFiles = iConfig.getParameter<std::vector<std::string> >("mvaWeightFile");
71  Trig_ = iConfig.getParameter<bool>("Trig");
72  NoIP_ = iConfig.getParameter<bool>("NoIP");
73 
74  produces<edm::ValueMap<float> >("");
75 
77 
79  if (Trig_ && !NoIP_) {
81  }
82 
83  if (Trig_ && NoIP_) {
85  }
86 
87  if (!Trig_) {
89  }
90 
91  bool manualCat_ = true;
92 
93  std::string path_mvaWeightFileEleID;
94  for (unsigned ifile = 0; ifile < fpMvaWeightFiles.size(); ++ifile) {
95  path_mvaWeightFileEleID = edm::FileInPath(fpMvaWeightFiles[ifile].c_str()).fullPath();
96  mvaWeightFiles_.push_back(path_mvaWeightFileEleID);
97  }
98 
99  mvaID_->initialize(method_, type_, manualCat_, mvaWeightFiles_);
100 }
101 
103  // do anything here that needs to be done at desctruction time
104  // (e.g. close files, deallocate resources etc.)
105 }
106 
107 //
108 // member functions
109 //
110 
111 // ------------ method called on each new Event ------------
113  std::unique_ptr<edm::ValueMap<float> > out(new edm::ValueMap<float>());
114 
116  iEvent.getByToken(vertexToken_, vertexCollection);
117 
119  const reco::Vertex* pv = &dummy;
120  if (!vertexCollection->empty()) {
121  pv = &*vertexCollection->begin();
122  } else { // create a dummy PV
124  e(0, 0) = 0.0015 * 0.0015;
125  e(1, 1) = 0.0015 * 0.0015;
126  e(2, 2) = 15. * 15.;
127  reco::Vertex::Point p(0, 0, 0);
128  dummy = reco::Vertex(p, e, 0, 0, 0);
129  }
130 
132 
134  iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder", builder);
135  TransientTrackBuilder thebuilder = *(builder.product());
136 
138  iEvent.getByToken(electronToken_, egCollection);
139  const reco::GsfElectronCollection egCandidates = (*egCollection.product());
140 
141  _Rho = 0;
142  edm::Handle<double> rhoPtr;
143  iEvent.getByToken(eventrhoToken_, rhoPtr);
144  _Rho = *rhoPtr;
145 
146  std::vector<float> values;
147  values.reserve(egCollection->size());
148 
149  for (reco::GsfElectronCollection::const_iterator egIter = egCandidates.begin(); egIter != egCandidates.end();
150  ++egIter) {
151  double mvaVal = -999999;
152  if (!NoIP_) {
153  mvaVal = mvaID_->mvaValue(*egIter, *pv, thebuilder, lazyTools, verbose_);
154  }
155  if (NoIP_) {
156  mvaVal = mvaID_->mvaValue(*egIter, *pv, _Rho, /*thebuilder,*/ lazyTools, verbose_);
157  }
158 
159  values.push_back(mvaVal);
160  }
161 
163  filler.insert(egCollection, values.begin(), values.end());
164  filler.fill();
165 
166  iEvent.put(std::move(out));
167 
168  return true;
169 }
170 
171 //define this as a plug-in
EGammaMvaEleEstimator
Definition: EGammaMvaEleEstimator.h:38
edm::ESHandle::product
T const * product() const
Definition: ESHandle.h:86
EGammaMvaEleEstimator::mvaValue
Double_t mvaValue(const reco::GsfElectron &ele, const reco::Vertex &vertex, const TransientTrackBuilder &transientTrackBuilder, EcalClusterLazyTools myEcalCluster, bool printDebug=kFALSE)
Definition: EGammaMvaEleEstimator.cc:954
edm::Handle::product
T const * product() const
Definition: Handle.h:70
edm::EDGetTokenT< reco::VertexCollection >
reco::Vertex::Error
math::Error< dimension >::type Error
covariance error matrix (3x3)
Definition: Vertex.h:44
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
EGammaMvaEleEstimator::kTrig
Definition: EGammaMvaEleEstimator.h:44
EGammaMvaEleEstimator::kTrigNoIP
Definition: EGammaMvaEleEstimator.h:45
EGammaMvaEleEstimator::initialize
void initialize(std::string methodName, std::string weightsfile, EGammaMvaEleEstimator::MVAType type)
Definition: EGammaMvaEleEstimator.cc:42
ElectronIdMVAProducer::NoIP_
bool NoIP_
Definition: ElectronIdMVAProducer.cc:44
EDFilter.h
ElectronIdMVAProducer::Trig_
bool Trig_
Definition: ElectronIdMVAProducer.cc:43
reco::GsfElectronCollection
std::vector< GsfElectron > GsfElectronCollection
collection of GsfElectron objects
Definition: GsfElectronFwd.h:14
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
edm::Handle< reco::VertexCollection >
EGammaMvaEleEstimator::MVAType
MVAType
Definition: EGammaMvaEleEstimator.h:43
ElectronIdMVAProducer::method_
std::string method_
Definition: ElectronIdMVAProducer.cc:41
ElectronIdMVAProducer::reducedEERecHitCollectionToken_
edm::EDGetTokenT< EcalRecHitCollection > reducedEERecHitCollectionToken_
Definition: ElectronIdMVAProducer.cc:38
edm::FileInPath
Definition: FileInPath.h:64
ElectronIdMVAProducer::filter
bool filter(edm::Event &, const edm::EventSetup &) override
Definition: ElectronIdMVAProducer.cc:112
MakerMacros.h
ElectronIdMVAProducer::eventrhoToken_
edm::EDGetTokenT< double > eventrhoToken_
Definition: ElectronIdMVAProducer.cc:36
edm::EventSetup::get
T get() const
Definition: EventSetup.h:73
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
ElectronIdMVAProducer::verbose_
bool verbose_
Definition: ElectronIdMVAProducer.cc:33
contentValuesCheck.values
values
Definition: contentValuesCheck.py:38
compare_using_db.ifile
ifile
Definition: compare_using_db.py:251
TransientTrackRecord
Definition: TransientTrackRecord.h:11
edm::ESHandle< TransientTrackBuilder >
GsfElectron.h
EcalClusterLazyTools
EGammaMvaEleEstimator.h
ElectronIdMVAProducer::_Rho
double _Rho
Definition: ElectronIdMVAProducer.cc:40
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
Vertex.h
GsfElectronFwd.h
edm::ParameterSet
Definition: ParameterSet.h:36
Event.h
ElectronIdMVAProducer
Definition: ElectronIdMVAProducer.cc:24
trigObjTnPSource_cfi.filler
filler
Definition: trigObjTnPSource_cfi.py:21
MetAnalyzer.pv
def pv(vc)
Definition: MetAnalyzer.py:7
iEvent
int iEvent
Definition: GenABIO.cc:224
TransientTrackBuilder
Definition: TransientTrackBuilder.h:16
edm::EDFilter
Definition: EDFilter.h:39
edm::EventSetup
Definition: EventSetup.h:57
TransientTrackRecord.h
get
#define get
EGammaMvaEleEstimator::kNonTrig
Definition: EGammaMvaEleEstimator.h:46
VertexFwd.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
ElectronIdMVAProducer::reducedEBRecHitCollectionToken_
edm::EDGetTokenT< EcalRecHitCollection > reducedEBRecHitCollectionToken_
Definition: ElectronIdMVAProducer.cc:37
reco::Vertex::Point
math::XYZPoint Point
point in the space
Definition: Vertex.h:40
eostools.move
def move(src, dest)
Definition: eostools.py:511
IPTools.h
HltBtagValidation_cff.Vertex
Vertex
Definition: HltBtagValidation_cff.py:32
Frameworkfwd.h
ElectronIdMVAProducer::mvaID_
EGammaMvaEleEstimator * mvaID_
Definition: ElectronIdMVAProducer.cc:46
spclusmultinvestigator_cfi.vertexCollection
vertexCollection
Definition: spclusmultinvestigator_cfi.py:4
edm::ValueMap< float >
ElectronIdMVAProducer::electronToken_
edm::EDGetTokenT< reco::GsfElectronCollection > electronToken_
Definition: ElectronIdMVAProducer.cc:35
ElectronIdMVAProducer::vertexToken_
edm::EDGetTokenT< reco::VertexCollection > vertexToken_
Definition: ElectronIdMVAProducer.cc:34
Electron.h
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
ElectronIdMVAProducer::~ElectronIdMVAProducer
~ElectronIdMVAProducer() override
Definition: ElectronIdMVAProducer.cc:102
ElectronIdMVAProducer::ElectronIdMVAProducer
ElectronIdMVAProducer(const edm::ParameterSet &)
Definition: ElectronIdMVAProducer.cc:60
edm::helper::Filler
Definition: ValueMap.h:22
ParameterSet.h
dummy
Definition: DummySelector.h:38
edm::Event
Definition: Event.h:73
edm::InputTag
Definition: InputTag.h:15
reco::Vertex
Definition: Vertex.h:35
edm::FileInPath::fullPath
std::string fullPath() const
Definition: FileInPath.cc:163
ElectronIdMVAProducer::mvaWeightFiles_
std::vector< std::string > mvaWeightFiles_
Definition: ElectronIdMVAProducer.cc:42
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37