CMS 3D CMS Logo

L1ElectronRecoTreeProducer.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 //electrons
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 L1ElectronRecoTreeProducer : public edm::one::EDAnalyzer<edm::one::SharedResources> {
44 public:
46  ~L1ElectronRecoTreeProducer() 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 private:
59  // output file
61 
62  // tree
63  TTree* tree_;
64 
65  // EDM input tags
66  //edm::EDGetToken ElectronToken_;
67  // edm::EDGetToken<edm::View<reco::GsfElectron>> ElectronToken_;
73 
74  // debug stuff
76  unsigned int maxElectron_;
77 };
78 
80  maxElectron_ = iConfig.getParameter<unsigned int>("maxElectron");
81  //ElectronToken_ = mayConsume<edm::View<reco::GsfElectron> >(iConfig.getUntrackedParameter("ElectronToken",edm::InputTag("gedGsfElectrons")));
82  ElectronToken_ = consumes<reco::GsfElectronCollection>(
83  iConfig.getUntrackedParameter("ElectronToken", edm::InputTag("gedGsfElectrons")));
84 
85  /*RhoToken_ = consumes<double>(iConfig.getUntrackedParameter("RhoToken",edm::InputTag("fixedGridRhoFastjetAllCalo")));
86  vtxToken_ = mayConsume<reco::VertexCollection>(iConfig.getUntrackedParameter("vtxToken",edm::InputTag("offlinePrimaryVertices")));
87  conversionsToken_ = mayConsume< reco::ConversionCollection >(iConfig.getUntrackedParameter("conversionsToken",edm::InputTag("conversions")));
88  beamSpotToken_ = mayConsume< reco::BeamSpot>(iConfig.getUntrackedParameter("beamSpotToken",edm::InputTag("offlineBeamSpot")));*/
89 
90  ElectronVetoIdMapToken_ = consumes<edm::ValueMap<bool> >(iConfig.getUntrackedParameter(
91  "eleVetoIdMapToken", edm::InputTag("egmGsfElectronIDs:cutBasedElectronID-Spring15-25ns-V1-standalone-veto")));
92  ElectronLooseIdMapToken_ = consumes<edm::ValueMap<bool> >(iConfig.getUntrackedParameter(
93  "eleLooseIdMapToken", edm::InputTag("egmGsfElectronIDs:cutBasedElectronID-Spring15-25ns-V1-standalone-loose")));
94  ElectronMediumIdMapToken_ = consumes<edm::ValueMap<bool> >(iConfig.getUntrackedParameter(
95  "eleMediumIdMapToken", edm::InputTag("egmGsfElectronIDs:cutBasedElectronID-Spring15-25ns-V1-standalone-medium")));
96  ElectronTightIdMapToken_ = consumes<edm::ValueMap<bool> >(iConfig.getUntrackedParameter(
97  "eleTightIdMapToken", edm::InputTag("egmGsfElectronIDs:cutBasedElectronID-Spring15-25ns-V1-standalone-tight")));
98 
101 
102  usesResource(TFileService::kSharedResource);
103  tree_ = fs_->make<TTree>("ElectronRecoTree", "ElectronRecoTree");
104  tree_->Branch("Electron", "L1Analysis::L1AnalysisRecoElectronDataFormat", &electron_data, 32000, 3);
105 }
106 
108  // do anything here that needs to be done at desctruction time
109  // (e.g. close files, deallocate resources etc.)
110 }
111 
112 //
113 // member functions
114 //
115 
116 // ------------ method called to for each event ------------
118  electron->Reset();
119  //edm::Handle<edm::View<reco::GsfElectron> > recoElectrons;
120  //iEvent.getByToken(ElectronToken_, recoElectrons);
122  iEvent.getByToken(ElectronToken_, recoElectrons);
123 
124  std::vector<edm::Handle<edm::ValueMap<bool> > > eleVIDDecisionHandles(4);
125 
126  iEvent.getByToken(ElectronVetoIdMapToken_, eleVIDDecisionHandles[0]);
127  iEvent.getByToken(ElectronLooseIdMapToken_, eleVIDDecisionHandles[1]);
128  iEvent.getByToken(ElectronMediumIdMapToken_, eleVIDDecisionHandles[2]);
129  iEvent.getByToken(ElectronTightIdMapToken_, eleVIDDecisionHandles[3]);
130 
131  if (recoElectrons.isValid() && eleVIDDecisionHandles[0].isValid() && eleVIDDecisionHandles[1].isValid() &&
132  eleVIDDecisionHandles[2].isValid() && eleVIDDecisionHandles[3].isValid()) {
133  electron->SetElectron(iEvent, iSetup, recoElectrons, eleVIDDecisionHandles, maxElectron_);
134  } else {
135  if (!electronsMissing_) {
136  edm::LogWarning("MissingProduct") << "CaloJets not found. Branch will not be filled" << std::endl;
137  }
138  electronsMissing_ = true;
139  }
140 
141  tree_->Fill();
142 }
143 
144 // ------------ method called once each job just before starting event loop ------------
146 
147 // ------------ method called once each job just after ending the event loop ------------
149 
150 //define this as a plug-in
static const std::string kSharedResource
Definition: TFileService.h:76
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
L1ElectronRecoTreeProducer(const edm::ParameterSet &)
edm::Service< TFileService > fs_
edm::EDGetTokenT< reco::GsfElectronCollection > ElectronToken_
L1Analysis::L1AnalysisRecoElectron * electron
edm::EDGetTokenT< edm::ValueMap< bool > > ElectronMediumIdMapToken_
edm::EDGetTokenT< edm::ValueMap< bool > > ElectronLooseIdMapToken_
T getUntrackedParameter(std::string const &, T const &) const
int iEvent
Definition: GenABIO.cc:224
L1Analysis::L1AnalysisRecoElectronDataFormat * electron_data
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
L1AnalysisRecoElectronDataFormat * getData()
edm::EDGetTokenT< edm::ValueMap< bool > > ElectronTightIdMapToken_
edm::EDGetTokenT< edm::ValueMap< bool > > ElectronVetoIdMapToken_
bool isValid() const
Definition: HandleBase.h:70
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
void SetElectron(const edm::Event &event, const edm::EventSetup &setup, const edm::Handle< reco::GsfElectronCollection > electrons, const std::vector< edm::Handle< edm::ValueMap< bool > > > eleVIDDecisionHandles, const unsigned &maxElectron)
Log< level::Warning, false > LogWarning
void analyze(const edm::Event &, const edm::EventSetup &) override