CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
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 
100  electron_data = electron->getData();
101 
102  tree_ = fs_->make<TTree>("ElectronRecoTree", "ElectronRecoTree");
103  tree_->Branch("Electron", "L1Analysis::L1AnalysisRecoElectronDataFormat", &electron_data, 32000, 3);
104 }
105 
107  // do anything here that needs to be done at desctruction time
108  // (e.g. close files, deallocate resources etc.)
109 }
110 
111 //
112 // member functions
113 //
114 
115 // ------------ method called to for each event ------------
117  electron->Reset();
118  //edm::Handle<edm::View<reco::GsfElectron> > recoElectrons;
119  //iEvent.getByToken(ElectronToken_, recoElectrons);
121  iEvent.getByToken(ElectronToken_, recoElectrons);
122 
123  std::vector<edm::Handle<edm::ValueMap<bool> > > eleVIDDecisionHandles(4);
124 
125  iEvent.getByToken(ElectronVetoIdMapToken_, eleVIDDecisionHandles[0]);
126  iEvent.getByToken(ElectronLooseIdMapToken_, eleVIDDecisionHandles[1]);
127  iEvent.getByToken(ElectronMediumIdMapToken_, eleVIDDecisionHandles[2]);
128  iEvent.getByToken(ElectronTightIdMapToken_, eleVIDDecisionHandles[3]);
129 
130  if (recoElectrons.isValid() && eleVIDDecisionHandles[0].isValid() && eleVIDDecisionHandles[1].isValid() &&
131  eleVIDDecisionHandles[2].isValid() && eleVIDDecisionHandles[3].isValid()) {
132  electron->SetElectron(iEvent, iSetup, recoElectrons, eleVIDDecisionHandles, maxElectron_);
133  } else {
134  if (!electronsMissing_) {
135  edm::LogWarning("MissingProduct") << "CaloJets not found. Branch will not be filled" << std::endl;
136  }
137  electronsMissing_ = true;
138  }
139 
140  tree_->Fill();
141 }
142 
143 // ------------ method called once each job just before starting event loop ------------
145 
146 // ------------ method called once each job just after ending the event loop ------------
148 
149 //define this as a plug-in
T getUntrackedParameter(std::string const &, T const &) const
L1ElectronRecoTreeProducer(const edm::ParameterSet &)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::Service< TFileService > fs_
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
edm::EDGetTokenT< reco::GsfElectronCollection > ElectronToken_
L1Analysis::L1AnalysisRecoElectron * electron
edm::EDGetTokenT< edm::ValueMap< bool > > ElectronMediumIdMapToken_
edm::EDGetTokenT< edm::ValueMap< bool > > ElectronLooseIdMapToken_
int iEvent
Definition: GenABIO.cc:224
L1Analysis::L1AnalysisRecoElectronDataFormat * electron_data
bool isValid() const
Definition: HandleBase.h:70
edm::EDGetTokenT< edm::ValueMap< bool > > ElectronTightIdMapToken_
edm::EDGetTokenT< edm::ValueMap< bool > > ElectronVetoIdMapToken_
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
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