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_;
40 
41  double _Rho;
43  std::vector<std::string> mvaWeightFiles_;
44  bool Trig_;
45  bool NoIP_;
46 
48 };
49 
50 //
51 // constants, enums and typedefs
52 //
53 
54 //
55 // static data member definitions
56 //
57 
58 //
59 // constructors and destructor
60 //
62  : ecalClusterToolsESGetTokens_{consumesCollector()} {
63  verbose_ = iConfig.getUntrackedParameter<bool>("verbose", false);
64  vertexToken_ = consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("vertexTag"));
65  electronToken_ = consumes<reco::GsfElectronCollection>(iConfig.getParameter<edm::InputTag>("electronTag"));
66  eventrhoToken_ = consumes<double>(edm::InputTag("kt6PFJets", "rho"));
67  reducedEBRecHitCollectionToken_ =
68  consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("reducedEBRecHitCollection"));
69  reducedEERecHitCollectionToken_ =
70  consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("reducedEERecHitCollection"));
71  method_ = iConfig.getParameter<std::string>("method");
72  std::vector<std::string> fpMvaWeightFiles = iConfig.getParameter<std::vector<std::string> >("mvaWeightFile");
73  Trig_ = iConfig.getParameter<bool>("Trig");
74  NoIP_ = iConfig.getParameter<bool>("NoIP");
75 
76  produces<edm::ValueMap<float> >("");
77 
78  mvaID_ = new EGammaMvaEleEstimator();
79 
81  if (Trig_ && !NoIP_) {
83  }
84 
85  if (Trig_ && NoIP_) {
87  }
88 
89  if (!Trig_) {
91  }
92 
93  bool manualCat_ = true;
94 
95  std::string path_mvaWeightFileEleID;
96  for (unsigned ifile = 0; ifile < fpMvaWeightFiles.size(); ++ifile) {
97  path_mvaWeightFileEleID = edm::FileInPath(fpMvaWeightFiles[ifile].c_str()).fullPath();
98  mvaWeightFiles_.push_back(path_mvaWeightFileEleID);
99  }
100 
101  mvaID_->initialize(method_, type_, manualCat_, mvaWeightFiles_);
102 }
103 
105  // do anything here that needs to be done at desctruction time
106  // (e.g. close files, deallocate resources etc.)
107 }
108 
109 //
110 // member functions
111 //
112 
113 // ------------ method called on each new Event ------------
115  std::unique_ptr<edm::ValueMap<float> > out(new edm::ValueMap<float>());
116 
118  iEvent.getByToken(vertexToken_, vertexCollection);
119 
121  const reco::Vertex* pv = &dummy;
122  if (!vertexCollection->empty()) {
123  pv = &*vertexCollection->begin();
124  } else { // create a dummy PV
126  e(0, 0) = 0.0015 * 0.0015;
127  e(1, 1) = 0.0015 * 0.0015;
128  e(2, 2) = 15. * 15.;
129  reco::Vertex::Point p(0, 0, 0);
130  dummy = reco::Vertex(p, e, 0, 0, 0);
131  }
132 
133  EcalClusterLazyTools lazyTools(iEvent,
137 
139  iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder", builder);
140  TransientTrackBuilder thebuilder = *(builder.product());
141 
143  iEvent.getByToken(electronToken_, egCollection);
144  const reco::GsfElectronCollection egCandidates = (*egCollection.product());
145 
146  _Rho = 0;
147  edm::Handle<double> rhoPtr;
148  iEvent.getByToken(eventrhoToken_, rhoPtr);
149  _Rho = *rhoPtr;
150 
151  std::vector<float> values;
152  values.reserve(egCollection->size());
153 
154  for (reco::GsfElectronCollection::const_iterator egIter = egCandidates.begin(); egIter != egCandidates.end();
155  ++egIter) {
156  double mvaVal = -999999;
157  if (!NoIP_) {
158  mvaVal = mvaID_->mvaValue(*egIter, *pv, thebuilder, lazyTools, verbose_);
159  }
160  if (NoIP_) {
161  mvaVal = mvaID_->mvaValue(*egIter, *pv, _Rho, /*thebuilder,*/ lazyTools, verbose_);
162  }
163 
164  values.push_back(mvaVal);
165  }
166 
168  filler.insert(egCollection, values.begin(), values.end());
169  filler.fill();
170 
171  iEvent.put(std::move(out));
172 
173  return true;
174 }
175 
176 //define this as a plug-in
EGammaMvaEleEstimator
Definition: EGammaMvaEleEstimator.h:38
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
ElectronIdMVAProducer::NoIP_
bool NoIP_
Definition: ElectronIdMVAProducer.cc:45
EDFilter.h
edm::EDConsumerBase::consumesCollector
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
Definition: EDConsumerBase.cc:46
ElectronIdMVAProducer::Trig_
bool Trig_
Definition: ElectronIdMVAProducer.cc:44
reco::GsfElectronCollection
std::vector< GsfElectron > GsfElectronCollection
collection of GsfElectron objects
Definition: GsfElectronFwd.h:14
edm::Handle< reco::VertexCollection >
EGammaMvaEleEstimator::MVAType
MVAType
Definition: EGammaMvaEleEstimator.h:43
ElectronIdMVAProducer::method_
std::string method_
Definition: ElectronIdMVAProducer.cc:42
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:114
MakerMacros.h
ElectronIdMVAProducer::eventrhoToken_
edm::EDGetTokenT< double > eventrhoToken_
Definition: ElectronIdMVAProducer.cc:36
edm::EventSetup::get
T get() const
Definition: EventSetup.h:80
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
ElectronIdMVAProducer::ecalClusterToolsESGetTokens_
const EcalClusterLazyTools::ESGetTokens ecalClusterToolsESGetTokens_
Definition: ElectronIdMVAProducer.cc:39
edm::ESHandle< TransientTrackBuilder >
EcalClusterLazyToolsBase::ESGetTokens
Definition: EcalClusterLazyTools.h:53
GsfElectron.h
EcalClusterLazyTools
EGammaMvaEleEstimator.h
ElectronIdMVAProducer::_Rho
double _Rho
Definition: ElectronIdMVAProducer.cc:41
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
Vertex.h
GsfElectronFwd.h
edm::ParameterSet
Definition: ParameterSet.h:47
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:38
edm::EventSetup
Definition: EventSetup.h:57
TransientTrackRecord.h
get
#define get
EcalClusterLazyToolsBase::ESGetTokens::get
ESData get(edm::EventSetup const &eventSetup) const
Definition: EcalClusterLazyTools.h:62
EGammaMvaEleEstimator::kNonTrig
Definition: EGammaMvaEleEstimator.h:46
VertexFwd.h
EGammaMvaEleEstimator::mvaValue
Double_t mvaValue(const reco::GsfElectron &ele, const reco::Vertex &vertex, const TransientTrackBuilder &transientTrackBuilder, EcalClusterLazyTools const &myEcalCluster, bool printDebug=kFALSE)
Definition: EGammaMvaEleEstimator.cc:954
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:47
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:104
ElectronIdMVAProducer::ElectronIdMVAProducer
ElectronIdMVAProducer(const edm::ParameterSet &)
Definition: ElectronIdMVAProducer.cc:61
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:43
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37