test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ElectronPATIdMVAProducer.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  virtual ~ElectronPATIdMVAProducer();
28 
29  private:
30  virtual void produce(edm::Event&, const edm::EventSetup&);
31 
32  // ----------member data ---------------------------
33  bool verbose_;
35  double _Rho;
38  std::vector<std::string> mvaWeightFiles_;
39 
40 
42 
43 };
44 
45 //
46 // constants, enums and typedefs
47 //
48 
49 //
50 // static data member definitions
51 //
52 
53 //
54 // constructors and destructor
55 //
57  verbose_ = iConfig.getUntrackedParameter<bool>("verbose", false);
58  electronToken_ = consumes<pat::ElectronCollection>(iConfig.getParameter<edm::InputTag>("electronTag"));
59  method_ = iConfig.getParameter<std::string>("method");
60  std::vector<std::string> fpMvaWeightFiles = iConfig.getParameter<std::vector<std::string> >("mvaWeightFile");
61  eventrhoToken_ = consumes<double>(iConfig.getParameter<edm::InputTag>("Rho"));
62 
63  produces<edm::ValueMap<float> >();
64 
66 
68 
69 
71 
72 
73 
74  bool manualCat_ = true;
75 
76  std::string path_mvaWeightFileEleID;
77  for(unsigned ifile=0 ; ifile < fpMvaWeightFiles.size() ; ++ifile) {
78  path_mvaWeightFileEleID = edm::FileInPath ( fpMvaWeightFiles[ifile].c_str() ).fullPath();
79  mvaWeightFiles_.push_back(path_mvaWeightFileEleID);
80  }
81 
82  mvaID_->initialize(method_, type_, manualCat_, mvaWeightFiles_);
83 
84 }
85 
86 
88 {
89 
90  // do anything here that needs to be done at desctruction time
91  // (e.g. close files, deallocate resources etc.)
92 
93 }
94 
95 
96 //
97 // member functions
98 //
99 
100 // ------------ method called on each new Event ------------
102 
103  std::unique_ptr<edm::ValueMap<float> > out(new edm::ValueMap<float>() );
104 
105 
106 
107 
108 
109 
110 
112  iEvent.getByToken(electronToken_,egCollection);
113  const pat::ElectronCollection egCandidates = (*egCollection.product());
114 
115  _Rho=0;
116  edm::Handle<double> rhoPtr;
117  //const edm::InputTag eventrhoToken_("kt6PFJets", "rho");
118  iEvent.getByToken(eventrhoToken_,rhoPtr);
119  _Rho=*rhoPtr;
120 
121  std::vector<float> values;
122  values.reserve(egCollection->size());
123 
124  for ( pat::ElectronCollection::const_iterator egIter = egCandidates.begin(); egIter != egCandidates.end(); ++egIter) {
125 
126  double mvaVal = -999999;
127 
128 
129 
130 
131  mvaVal = mvaID_->mvaValue( *egIter, _Rho, verbose_);
132 
133 
134  values.push_back( mvaVal );
135  }
136 
137  edm::ValueMap<float>::Filler filler(*out);
138  filler.insert(egCollection, values.begin(), values.end() );
139  filler.fill();
140 
141  iEvent.put(std::move(out));
142 
143 
144 }
145 
146 //define this as a plug-in
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:52
std::vector< std::string > mvaWeightFiles_
ElectronPATIdMVAProducer(const edm::ParameterSet &)
int iEvent
Definition: GenABIO.cc:230
virtual void produce(edm::Event &, const edm::EventSetup &)
std::vector< Electron > ElectronCollection
Definition: Electron.h:37
def move
Definition: eostools.py:510
Double_t mvaValue(const reco::GsfElectron &ele, const reco::Vertex &vertex, const TransientTrackBuilder &transientTrackBuilder, EcalClusterLazyTools myEcalCluster, bool printDebug=kFALSE)
edm::EDGetTokenT< pat::ElectronCollection > electronToken_
EGammaMvaEleEstimator * mvaID_
T const * product() const
Definition: Handle.h:81
edm::EDGetTokenT< double > eventrhoToken_
std::string fullPath() const
Definition: FileInPath.cc:184