CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
PhotonMVANtuplizer Class Reference

#include <RecoEgamma/PhotonIdentification/plugins/PhotonMVANtuplizer.cc>

Inheritance diagram for PhotonMVANtuplizer:
edm::one::EDAnalyzer< edm::one::SharedResources > edm::one::EDAnalyzerBase edm::EDConsumerBase

Public Member Functions

 PhotonMVANtuplizer (const edm::ParameterSet &)
 
 ~PhotonMVANtuplizer () override
 
- Public Member Functions inherited from edm::one::EDAnalyzer< edm::one::SharedResources >
 EDAnalyzer ()=default
 
SerialTaskQueueglobalLuminosityBlocksQueue () final
 
SerialTaskQueueglobalRunsQueue () final
 
bool wantsGlobalLuminosityBlocks () const final
 
bool wantsGlobalRuns () const final
 
- Public Member Functions inherited from edm::one::EDAnalyzerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzerBase ()
 
ModuleDescription const & moduleDescription () const
 
bool wantsStreamLuminosityBlocks () const
 
bool wantsStreamRuns () const
 
 ~EDAnalyzerBase () override
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
virtual ~EDConsumerBase () noexcept(false)
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 
- Static Public Member Functions inherited from edm::one::EDAnalyzerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 

Private Member Functions

void analyze (const edm::Event &, const edm::EventSetup &) override
 
void beginJob () override
 
void endJob () override
 

Private Attributes

int genNpu_
 
const bool isMC_
 
const std::vector< std::string > mvaCatBranchNames_
 
std::vector< int > mvaCats_
 
const std::vector< std::string > mvaCatTags_
 
std::vector< edm::EDGetTokenT< edm::ValueMap< int > > > mvaCatTokens_
 
std::vector< int > mvaPasses_
 
std::vector< float > mvaValues_
 
const size_t nCats_
 
int nEvent_
 
int nLumi_
 
const size_t nPhoMaps_
 
int nRun_
 
const size_t nValMaps_
 
int nVars_
 
const std::vector< std::string > phoMapBranchNames_
 
const std::vector< std::string > phoMapTags_
 
std::vector< edm::EDGetTokenT< edm::ValueMap< bool > > > phoMapTokens_
 
MultiTokenT< std::vector< PileupSummaryInfo > > pileup_
 
const double ptThreshold_
 
MultiTokenT< edm::View< reco::Photon > > src_
 
TTree * tree_
 
const std::vector< std::string > valMapBranchNames_
 
const std::vector< std::string > valMapTags_
 
std::vector< edm::EDGetTokenT< edm::ValueMap< float > > > valMapTokens_
 
std::vector< float > vars_
 
MultiTokenT< std::vector< reco::Vertex > > vertices_
 
int vtxN_
 

Additional Inherited Members

- Public Types inherited from edm::one::EDAnalyzerBase
typedef EDAnalyzerBase ModuleType
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

Description: Ntuplizer to use for testing photon MVA IDs.

Implementation: [Notes on implementation]

Definition at line 56 of file PhotonMVANtuplizer.cc.

Constructor & Destructor Documentation

PhotonMVANtuplizer::PhotonMVANtuplizer ( const edm::ParameterSet iConfig)
explicit

Definition at line 130 of file PhotonMVANtuplizer.cc.

References edm::EDConsumerBase::consumes(), genNpu_, mps_fire::i, isMC_, gen::k, TFileService::kSharedResource, TFileService::make(), mvaCatBranchNames_, mvaCats_, mvaCatTags_, mvaCatTokens_, mvaPasses_, mvaValues_, nCats_, nEvent_, nLumi_, nPhoMaps_, nRun_, nValMaps_, nVars_, phoMapBranchNames_, phoMapTags_, phoMapTokens_, tree_, valMapBranchNames_, valMapTags_, valMapTokens_, vars_, and vtxN_.

131  : phoMapTags_ (iConfig.getUntrackedParameter<std::vector<std::string>>("phoMVAs"))
132  , phoMapBranchNames_ (iConfig.getUntrackedParameter<std::vector<std::string>>("phoMVALabels"))
133  , nPhoMaps_ (phoMapBranchNames_.size())
134  , valMapTags_ (iConfig.getUntrackedParameter<std::vector<std::string>>("phoMVAValMaps"))
135  , valMapBranchNames_ (iConfig.getUntrackedParameter<std::vector<std::string>>("phoMVAValMapLabels"))
136  , nValMaps_ (valMapBranchNames_.size())
137  , mvaCatTags_ (iConfig.getUntrackedParameter<std::vector<std::string>>("phoMVACats"))
138  , mvaCatBranchNames_ (iConfig.getUntrackedParameter<std::vector<std::string>>("phoMVACatLabels"))
139  , nCats_ (mvaCatBranchNames_.size())
140  , isMC_ (iConfig.getParameter<bool>("isMC"))
141  , ptThreshold_ (iConfig.getParameter<double>("ptThreshold"))
142  , src_ (consumesCollector(), iConfig, "src" , "srcMiniAOD")
143  , vertices_ (src_, consumesCollector(), iConfig, "vertices", "verticesMiniAOD")
144  , pileup_ (src_, consumesCollector(), iConfig, "pileup" , "pileupMiniAOD")
145 {
146  // phoMaps
147  for (size_t k = 0; k < nPhoMaps_; ++k) {
148 
150 
151  // Initialize vectors for holding ID decisions
152  mvaPasses_.push_back(0);
153  }
154 
155  // valMaps
156  for (size_t k = 0; k < nValMaps_; ++k) {
158 
159  // Initialize vectors for holding MVA values
160  mvaValues_.push_back(0.0);
161  }
162 
163  // categories
164  for (size_t k = 0; k < nCats_; ++k) {
166 
167  // Initialize vectors for holding MVA values
168  mvaCats_.push_back(0);
169  }
170 
171  // Book tree
172  usesResource(TFileService::kSharedResource);
174  tree_ = fs->make<TTree>("tree","tree");
175 
176  tree_->Branch("nEvent", &nEvent_);
177  tree_->Branch("nRun", &nRun_);
178  tree_->Branch("nLumi", &nLumi_);
179  if (isMC_) tree_->Branch("genNpu", &genNpu_);
180  tree_->Branch("vtxN", &vtxN_);
181 
182  // Has to be in two different loops
183  for (int i = 0; i < nVars_; ++i) {
184  vars_.push_back(0.0);
185  }
186 
187  // IDs
188  for (size_t k = 0; k < nValMaps_; ++k) {
189  tree_->Branch(valMapBranchNames_[k].c_str() , &mvaValues_[k]);
190  }
191 
192  for (size_t k = 0; k < nPhoMaps_; ++k) {
193  tree_->Branch(phoMapBranchNames_[k].c_str() , &mvaPasses_[k]);
194  }
195 
196  for (size_t k = 0; k < nCats_; ++k) {
197  tree_->Branch(mvaCatBranchNames_[k].c_str() , &mvaCats_[k]);
198  }
199 }
static const std::string kSharedResource
Definition: TFileService.h:76
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
MultiTokenT< std::vector< PileupSummaryInfo > > pileup_
MultiTokenT< edm::View< reco::Photon > > src_
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
const std::vector< std::string > valMapBranchNames_
std::vector< int > mvaCats_
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
const std::vector< std::string > phoMapTags_
std::vector< int > mvaPasses_
const std::vector< std::string > valMapTags_
std::vector< float > mvaValues_
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
std::vector< edm::EDGetTokenT< edm::ValueMap< int > > > mvaCatTokens_
MultiTokenT< std::vector< reco::Vertex > > vertices_
int k[5][pyjets_maxn]
std::vector< edm::EDGetTokenT< edm::ValueMap< bool > > > phoMapTokens_
const std::vector< std::string > mvaCatBranchNames_
std::vector< edm::EDGetTokenT< edm::ValueMap< float > > > valMapTokens_
const std::vector< std::string > phoMapBranchNames_
std::vector< float > vars_
const std::vector< std::string > mvaCatTags_
PhotonMVANtuplizer::~PhotonMVANtuplizer ( )
override

Definition at line 202 of file PhotonMVANtuplizer.cc.

203 {
204 
205  // do anything here that needs to be done at desctruction time
206  // (e.g. close files, deallocate resources etc.)
207 
208 }

Member Function Documentation

void PhotonMVANtuplizer::analyze ( const edm::Event iEvent,
const edm::EventSetup iSetup 
)
overrideprivate

Definition at line 217 of file PhotonMVANtuplizer.cc.

References edm::EventID::event(), genNpu_, edm::Event::getByToken(), MultiTokenT< T >::getValidHandle(), edm::EventBase::id(), createfilelist::int, isMC_, gen::k, edm::EventBase::luminosityBlock(), mvaCats_, mvaCatTokens_, mvaPasses_, mvaValues_, nCats_, nEvent_, nLumi_, nPhoMaps_, nRun_, nValMaps_, phoMapTokens_, ElectronMVANtuplizer_cfg::pileup, pileup_, ptThreshold_, muons2muons_cfi::pu, edm::EventID::run(), TrackRefitter_38T_cff::src, src_, tree_, valMapTokens_, MuonErrorMatrixValues_cff::values, electrons_cff::vertices, vertices_, and vtxN_.

218 {
219  // Fill global event info
220  nEvent_ = iEvent.id().event();
221  nRun_ = iEvent.id().run();
222  nLumi_ = iEvent.luminosityBlock();
223 
224  // Get Handles
225  auto src = src_.getValidHandle(iEvent);
226  auto vertices = vertices_.getValidHandle(iEvent);
227  auto pileup = pileup_.getValidHandle(iEvent);
228 
229  vtxN_ = vertices->size();
230 
231  // Fill with true number of pileup
232  if(isMC_) {
233  for(const auto& pu : *pileup)
234  {
235  int bx = pu.getBunchCrossing();
236  if(bx == 0)
237  {
238  genNpu_ = pu.getPU_NumInteractions();
239  break;
240  }
241  }
242  }
243 
244  // Get MVA decisions
246  for (size_t k = 0; k < nPhoMaps_; ++k) {
247  iEvent.getByToken(phoMapTokens_[k],decisions[k]);
248  }
249 
250  // Get MVA values
252  for (size_t k = 0; k < nValMaps_; ++k) {
253  iEvent.getByToken(valMapTokens_[k],values[k]);
254  }
255 
256  // Get MVA categories
258  for (size_t k = 0; k < nCats_; ++k) {
259  iEvent.getByToken(mvaCatTokens_[k],mvaCats[k]);
260  }
261 
262  int nPho = src->size();
263 
264  for(int iPho = 0; iPho < nPho; ++iPho) {
265 
266  const auto pho = src->ptrAt(iPho);
267 
268  if (pho->pt() < ptThreshold_) {
269  continue;
270  }
271 
272  //
273  // Look up and save the ID decisions
274  //
275  for (size_t k = 0; k < nPhoMaps_; ++k) {
276  mvaPasses_[k] = (int)(*decisions[k])[pho];
277  }
278 
279  for (size_t k = 0; k < nValMaps_; ++k) {
280  mvaValues_[k] = (*values[k])[pho];
281  }
282 
283  for (size_t k = 0; k < nCats_; ++k) {
284  mvaCats_[k] = (*mvaCats[k])[pho];
285  }
286 
287 
288  tree_->Fill();
289  }
290 
291 }
RunNumber_t run() const
Definition: EventID.h:39
EventNumber_t event() const
Definition: EventID.h:41
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
MultiTokenT< std::vector< PileupSummaryInfo > > pileup_
MultiTokenT< edm::View< reco::Photon > > src_
edm::LuminosityBlockNumber_t luminosityBlock() const
Definition: EventBase.h:63
std::vector< int > mvaCats_
std::vector< int > mvaPasses_
std::vector< float > mvaValues_
std::vector< edm::EDGetTokenT< edm::ValueMap< int > > > mvaCatTokens_
MultiTokenT< std::vector< reco::Vertex > > vertices_
int k[5][pyjets_maxn]
edm::Handle< T > getValidHandle(const edm::Event &iEvent)
Definition: MultiToken.h:83
std::vector< edm::EDGetTokenT< edm::ValueMap< bool > > > phoMapTokens_
edm::EventID id() const
Definition: EventBase.h:60
std::vector< edm::EDGetTokenT< edm::ValueMap< float > > > valMapTokens_
void PhotonMVANtuplizer::beginJob ( void  )
inlineoverrideprivatevirtual

Reimplemented from edm::one::EDAnalyzerBase.

Definition at line 69 of file PhotonMVANtuplizer.cc.

69 {};
void PhotonMVANtuplizer::endJob ( void  )
inlineoverrideprivatevirtual

Reimplemented from edm::one::EDAnalyzerBase.

Definition at line 71 of file PhotonMVANtuplizer.cc.

71 {};
void PhotonMVANtuplizer::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 295 of file PhotonMVANtuplizer.cc.

References edm::ParameterSetDescription::add(), edm::ConfigurationDescriptions::addDefault(), edm::ParameterSetDescription::addUntracked(), and DEFINE_FWK_MODULE.

295  {
296 
298  desc.add<edm::InputTag>("src");
299  desc.add<edm::InputTag>("vertices");
300  desc.add<edm::InputTag>("pileup");
301  desc.add<edm::InputTag>("srcMiniAOD");
302  desc.add<edm::InputTag>("verticesMiniAOD");
303  desc.add<edm::InputTag>("pileupMiniAOD");
304  desc.addUntracked<std::vector<std::string>>("phoMVAs");
305  desc.addUntracked<std::vector<std::string>>("phoMVALabels");
306  desc.addUntracked<std::vector<std::string>>("phoMVAValMaps");
307  desc.addUntracked<std::vector<std::string>>("phoMVAValMapLabels");
308  desc.addUntracked<std::vector<std::string>>("phoMVACats");
309  desc.addUntracked<std::vector<std::string>>("phoMVACatLabels");
310  desc.add<bool>("isMC");
311  desc.add<double>("ptThreshold", 5.0);
312  descriptions.addDefault(desc);
313 
314 }
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
void addDefault(ParameterSetDescription const &psetDescription)
ParameterDescriptionBase * add(U const &iLabel, T const &value)

Member Data Documentation

int PhotonMVANtuplizer::genNpu_
private

Definition at line 83 of file PhotonMVANtuplizer.cc.

Referenced by analyze(), and PhotonMVANtuplizer().

const bool PhotonMVANtuplizer::isMC_
private

Definition at line 109 of file PhotonMVANtuplizer.cc.

Referenced by analyze(), and PhotonMVANtuplizer().

const std::vector< std::string > PhotonMVANtuplizer::mvaCatBranchNames_
private

Definition at line 105 of file PhotonMVANtuplizer.cc.

Referenced by PhotonMVANtuplizer().

std::vector<int> PhotonMVANtuplizer::mvaCats_
private

Definition at line 89 of file PhotonMVANtuplizer.cc.

Referenced by analyze(), and PhotonMVANtuplizer().

const std::vector< std::string > PhotonMVANtuplizer::mvaCatTags_
private

Definition at line 103 of file PhotonMVANtuplizer.cc.

Referenced by PhotonMVANtuplizer().

std::vector< edm::EDGetTokenT<edm::ValueMap<int> > > PhotonMVANtuplizer::mvaCatTokens_
private

Definition at line 104 of file PhotonMVANtuplizer.cc.

Referenced by analyze(), and PhotonMVANtuplizer().

std::vector<int> PhotonMVANtuplizer::mvaPasses_
private

Definition at line 87 of file PhotonMVANtuplizer.cc.

Referenced by analyze(), and PhotonMVANtuplizer().

std::vector<float> PhotonMVANtuplizer::mvaValues_
private

Definition at line 88 of file PhotonMVANtuplizer.cc.

Referenced by analyze(), and PhotonMVANtuplizer().

const size_t PhotonMVANtuplizer::nCats_
private

Definition at line 106 of file PhotonMVANtuplizer.cc.

Referenced by analyze(), and PhotonMVANtuplizer().

int PhotonMVANtuplizer::nEvent_
private

Definition at line 82 of file PhotonMVANtuplizer.cc.

Referenced by analyze(), and PhotonMVANtuplizer().

int PhotonMVANtuplizer::nLumi_
private

Definition at line 82 of file PhotonMVANtuplizer.cc.

Referenced by analyze(), and PhotonMVANtuplizer().

const size_t PhotonMVANtuplizer::nPhoMaps_
private

Definition at line 95 of file PhotonMVANtuplizer.cc.

Referenced by analyze(), and PhotonMVANtuplizer().

int PhotonMVANtuplizer::nRun_
private

Definition at line 82 of file PhotonMVANtuplizer.cc.

Referenced by analyze(), and PhotonMVANtuplizer().

const size_t PhotonMVANtuplizer::nValMaps_
private

Definition at line 101 of file PhotonMVANtuplizer.cc.

Referenced by analyze(), and PhotonMVANtuplizer().

int PhotonMVANtuplizer::nVars_
private

Definition at line 79 of file PhotonMVANtuplizer.cc.

Referenced by PhotonMVANtuplizer().

const std::vector< std::string > PhotonMVANtuplizer::phoMapBranchNames_
private

Definition at line 94 of file PhotonMVANtuplizer.cc.

Referenced by PhotonMVANtuplizer().

const std::vector< std::string > PhotonMVANtuplizer::phoMapTags_
private

Definition at line 92 of file PhotonMVANtuplizer.cc.

Referenced by PhotonMVANtuplizer().

std::vector< edm::EDGetTokenT< edm::ValueMap<bool> > > PhotonMVANtuplizer::phoMapTokens_
private

Definition at line 93 of file PhotonMVANtuplizer.cc.

Referenced by analyze(), and PhotonMVANtuplizer().

MultiTokenT<std::vector<PileupSummaryInfo> > PhotonMVANtuplizer::pileup_
private

Definition at line 115 of file PhotonMVANtuplizer.cc.

Referenced by analyze().

const double PhotonMVANtuplizer::ptThreshold_
private

Definition at line 110 of file PhotonMVANtuplizer.cc.

Referenced by analyze().

MultiTokenT<edm::View<reco::Photon> > PhotonMVANtuplizer::src_
private

Definition at line 113 of file PhotonMVANtuplizer.cc.

Referenced by analyze().

TTree* PhotonMVANtuplizer::tree_
private

Definition at line 71 of file PhotonMVANtuplizer.cc.

Referenced by analyze(), and PhotonMVANtuplizer().

const std::vector< std::string > PhotonMVANtuplizer::valMapBranchNames_
private

Definition at line 100 of file PhotonMVANtuplizer.cc.

Referenced by PhotonMVANtuplizer().

const std::vector< std::string > PhotonMVANtuplizer::valMapTags_
private

Definition at line 98 of file PhotonMVANtuplizer.cc.

Referenced by PhotonMVANtuplizer().

std::vector< edm::EDGetTokenT<edm::ValueMap<float> > > PhotonMVANtuplizer::valMapTokens_
private

Definition at line 99 of file PhotonMVANtuplizer.cc.

Referenced by analyze(), and PhotonMVANtuplizer().

std::vector<float> PhotonMVANtuplizer::vars_
private

Definition at line 78 of file PhotonMVANtuplizer.cc.

Referenced by PhotonMVANtuplizer().

MultiTokenT<std::vector<reco::Vertex> > PhotonMVANtuplizer::vertices_
private

Definition at line 114 of file PhotonMVANtuplizer.cc.

Referenced by analyze().

int PhotonMVANtuplizer::vtxN_
private

Definition at line 84 of file PhotonMVANtuplizer.cc.

Referenced by analyze(), and PhotonMVANtuplizer().