CMS 3D CMS Logo

L1PhotonRecoTreeProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: L1Trigger/L1TNtuples
4 // Class: L1JetRecoTreeProducer
5 //
13 // system include files
14 #include <memory>
15 
16 // framework
25 
26 // photons
28 
29 // ROOT output stuff
32 #include "TH1.h"
33 #include "TTree.h"
34 #include "TF1.h"
35 
36 //local data formats
38 
39 //
40 // class declaration
41 //
42 
43 class L1PhotonRecoTreeProducer : public edm::one::EDAnalyzer<edm::one::SharedResources> {
44 public:
46  ~L1PhotonRecoTreeProducer() override;
47 
48 private:
49  void beginJob(void) override;
50  void analyze(const edm::Event&, const edm::EventSetup&) override;
51  void endJob() override;
52 
53 public:
55 
57 
58  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
59 
60 private:
61  // output file
63 
64  // tree
65  TTree* tree_;
66 
67  // EDM input tags
68 
72 
73  // debug stuff
75  unsigned int maxPhoton_;
76 };
77 
79  maxPhoton_ = iConfig.getParameter<unsigned int>("maxPhoton");
80  PhotonToken_ =
81  consumes<reco::PhotonCollection>(iConfig.getUntrackedParameter("PhotonToken", edm::InputTag("photons")));
82 
83  PhotonWP80MapToken_ = consumes<edm::ValueMap<bool> >(
84  iConfig.getUntrackedParameter("phoWP80MapToken", edm::InputTag("egmPhotonIDs:mvaPhoID-RunIIIWinter22-v1-wp80")));
85  PhotonWP90MapToken_ = consumes<edm::ValueMap<bool> >(
86  iConfig.getUntrackedParameter("phoWP90MapToken", edm::InputTag("egmPhotonIDs:mvaPhoID-RunIIIWinter22-v1-wp90")));
87 
90 
91  usesResource(TFileService::kSharedResource);
92  tree_ = fs_->make<TTree>("PhotonRecoTree", "PhotonRecoTree");
93  tree_->Branch("Photon", "L1Analysis::L1AnalysisRecoPhotonDataFormat", &photon_data, 32000, 3);
94 }
95 
97  // do anything here that needs to be done at desctruction time
98  // (e.g. close files, deallocate resources etc.)
99 }
100 
101 //
102 // member functions
103 //
104 
105 // ------------ method called to for each event ------------
107  photon->Reset();
109  iEvent.getByToken(PhotonToken_, recoPhotons);
110 
111  std::vector<edm::Handle<edm::ValueMap<bool> > > phoVIDDecisionHandles(2);
112 
113  iEvent.getByToken(PhotonWP80MapToken_, phoVIDDecisionHandles[0]);
114  iEvent.getByToken(PhotonWP90MapToken_, phoVIDDecisionHandles[1]);
115 
116  if (recoPhotons.isValid() && phoVIDDecisionHandles[0].isValid() && phoVIDDecisionHandles[1].isValid()) {
117  photon->SetPhoton(iEvent, iSetup, recoPhotons, phoVIDDecisionHandles, maxPhoton_);
118  } else {
119  if (!photonsMissing_) {
120  edm::LogWarning("MissingProduct") << "Photons or photon ID not found. Branch will not be filled" << std::endl;
121  }
122  photonsMissing_ = true;
123  }
124 
125  tree_->Fill();
126 }
127 
128 // ------------ method called once each job just before starting event loop ------------
130 
131 // ------------ method called once each job just after ending the event loop ------------
133 
136  desc.add<unsigned int>("maxPhoton", 20);
137  descriptions.addWithDefaultLabel(desc);
138 }
139 
140 //define this as a plug-in
static const std::string kSharedResource
Definition: TFileService.h:76
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
void SetPhoton(const edm::Event &event, const edm::EventSetup &setup, const edm::Handle< reco::PhotonCollection > photons, const std::vector< edm::Handle< edm::ValueMap< bool > > > phoVIDDecisionHandles, const unsigned &maxPhoton)
edm::EDGetTokenT< reco::PhotonCollection > PhotonToken_
L1AnalysisRecoPhotonDataFormat * getData()
T getUntrackedParameter(std::string const &, T const &) const
edm::Service< TFileService > fs_
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::EDGetTokenT< edm::ValueMap< bool > > PhotonWP80MapToken_
L1Analysis::L1AnalysisRecoPhoton * photon
L1PhotonRecoTreeProducer(const edm::ParameterSet &)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
bool isValid() const
Definition: HandleBase.h:70
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
edm::EDGetTokenT< edm::ValueMap< bool > > PhotonWP90MapToken_
Log< level::Warning, false > LogWarning
L1Analysis::L1AnalysisRecoPhotonDataFormat * photon_data
void analyze(const edm::Event &, const edm::EventSetup &) override