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"));
65  reducedEBRecHitCollectionToken_ = consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("reducedEBRecHitCollection"));
66  reducedEERecHitCollectionToken_ = consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("reducedEERecHitCollection"));
67  method_ = iConfig.getParameter<std::string>("method");
68  std::vector<std::string> fpMvaWeightFiles = iConfig.getParameter<std::vector<std::string> >("mvaWeightFile");
69  Trig_ = iConfig.getParameter<bool>("Trig");
70  NoIP_ = iConfig.getParameter<bool>("NoIP");
71 
72  produces<edm::ValueMap<float> >("");
73 
75 
77  if(Trig_ && !NoIP_){type_ = EGammaMvaEleEstimator::kTrig;}
78 
79  if(Trig_ && NoIP_){type_ = EGammaMvaEleEstimator::kTrigNoIP;}
80 
81  if(!Trig_){type_ = EGammaMvaEleEstimator::kNonTrig;}
82 
83  bool manualCat_ = true;
84 
85  std::string path_mvaWeightFileEleID;
86  for(unsigned ifile=0 ; ifile < fpMvaWeightFiles.size() ; ++ifile) {
87  path_mvaWeightFileEleID = edm::FileInPath ( fpMvaWeightFiles[ifile].c_str() ).fullPath();
88  mvaWeightFiles_.push_back(path_mvaWeightFileEleID);
89  }
90 
91  mvaID_->initialize(method_, type_, manualCat_, mvaWeightFiles_);
92 
93 }
94 
95 
97 {
98 
99  // do anything here that needs to be done at desctruction time
100  // (e.g. close files, deallocate resources etc.)
101 
102 }
103 
104 
105 //
106 // member functions
107 //
108 
109 // ------------ method called on each new Event ------------
111 
112  std::unique_ptr<edm::ValueMap<float> > out(new edm::ValueMap<float>() );
113 
115  iEvent.getByToken(vertexToken_, vertexCollection);
116 
118  const reco::Vertex *pv = &dummy;
119  if ( !vertexCollection->empty()) {
120  pv = &*vertexCollection->begin();
121  } else { // create a dummy PV
123  e(0, 0) = 0.0015 * 0.0015;
124  e(1, 1) = 0.0015 * 0.0015;
125  e(2, 2) = 15. * 15.;
126  reco::Vertex::Point p(0, 0, 0);
127  dummy = reco::Vertex(p, e, 0, 0, 0);
128  }
129 
131 
133  iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder", builder);
134  TransientTrackBuilder thebuilder = *(builder.product());
135 
137  iEvent.getByToken(electronToken_,egCollection);
138  const reco::GsfElectronCollection egCandidates = (*egCollection.product());
139 
140  _Rho=0;
141  edm::Handle<double> rhoPtr;
142  iEvent.getByToken(eventrhoToken_,rhoPtr);
143  _Rho=*rhoPtr;
144 
145  std::vector<float> values;
146  values.reserve(egCollection->size());
147 
148  for ( reco::GsfElectronCollection::const_iterator egIter = egCandidates.begin(); egIter != egCandidates.end(); ++egIter) {
149 
150  double mvaVal = -999999;
151  if(!NoIP_){
152  mvaVal = mvaID_->mvaValue( *egIter, *pv,thebuilder,lazyTools, verbose_);
153  }
154  if(NoIP_){
155  mvaVal = mvaID_->mvaValue( *egIter, *pv, _Rho,/*thebuilder,*/lazyTools, verbose_);
156  }
157 
158  values.push_back( mvaVal );
159  }
160 
162  filler.insert(egCollection, values.begin(), values.end() );
163  filler.fill();
164 
165  iEvent.put(std::move(out));
166 
167  return true;
168 }
169 
170 //define this as a plug-in
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
edm::EDGetTokenT< double > eventrhoToken_
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:136
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:519
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
edm::EDGetTokenT< EcalRecHitCollection > reducedEBRecHitCollectionToken_
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:53
math::Error< dimension >::type Error
covariance error matrix (3x3)
Definition: Vertex.h:43
edm::EDGetTokenT< EcalRecHitCollection > reducedEERecHitCollectionToken_
std::vector< GsfElectron > GsfElectronCollection
collection of GsfElectron objects
bool filter(edm::Event &, const edm::EventSetup &) override
int iEvent
Definition: GenABIO.cc:230
def pv(vc)
Definition: MetAnalyzer.py:6
math::XYZPoint Point
point in the space
Definition: Vertex.h:39
edm::EDGetTokenT< reco::VertexCollection > vertexToken_
Double_t mvaValue(const reco::GsfElectron &ele, const reco::Vertex &vertex, const TransientTrackBuilder &transientTrackBuilder, EcalClusterLazyTools myEcalCluster, bool printDebug=kFALSE)
std::vector< std::string > mvaWeightFiles_
ElectronIdMVAProducer(const edm::ParameterSet &)
T const * product() const
Definition: Handle.h:81
edm::EDGetTokenT< reco::GsfElectronCollection > electronToken_
const T & get() const
Definition: EventSetup.h:58
std::string fullPath() const
Definition: FileInPath.cc:197
T const * product() const
Definition: ESHandle.h:86
def move(src, dest)
Definition: eostools.py:510
EGammaMvaEleEstimator * mvaID_