CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
L1ElectronRecoTreeProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: L1Trigger/L1TNtuples
4 // Class: L1JetRecoTreeProducer
5 //
14 // system include files
15 #include <memory>
16 
17 // framework
26 
27 //electrons
29 
30 // ROOT output stuff
33 #include "TH1.h"
34 #include "TTree.h"
35 #include "TF1.h"
36 
37 //local data formats
39 
40 
41 //
42 // class declaration
43 //
44 
46 public:
49 
50 
51 private:
52  virtual void beginJob(void) ;
53  virtual void analyze(const edm::Event&, const edm::EventSetup&);
54  virtual void endJob();
55 
56 public:
58 
60 
61 private:
62 
63  // output file
65 
66  // tree
67  TTree * tree_;
68 
69  // EDM input tags
70  //edm::EDGetToken ElectronToken_;
71  // edm::EDGetToken<edm::View<reco::GsfElectron>> ElectronToken_;
77 
78  // debug stuff
80  unsigned int maxElectron_;
81 
82 };
83 
84 
85 
87  electronsMissing_(false)
88 {
89 
90  maxElectron_ = iConfig.getParameter<unsigned int>("maxElectron");
91  //ElectronToken_ = mayConsume<edm::View<reco::GsfElectron> >(iConfig.getUntrackedParameter("ElectronToken",edm::InputTag("gedGsfElectrons")));
92  ElectronToken_ = consumes<reco::GsfElectronCollection>(iConfig.getUntrackedParameter("ElectronToken",edm::InputTag("gedGsfElectrons")));
93 
94  /*RhoToken_ = consumes<double>(iConfig.getUntrackedParameter("RhoToken",edm::InputTag("fixedGridRhoFastjetAllCalo")));
95  vtxToken_ = mayConsume<reco::VertexCollection>(iConfig.getUntrackedParameter("vtxToken",edm::InputTag("offlinePrimaryVertices")));
96  conversionsToken_ = mayConsume< reco::ConversionCollection >(iConfig.getUntrackedParameter("conversionsToken",edm::InputTag("conversions")));
97  beamSpotToken_ = mayConsume< reco::BeamSpot>(iConfig.getUntrackedParameter("beamSpotToken",edm::InputTag("offlineBeamSpot")));*/
98 
99  ElectronVetoIdMapToken_ = consumes<edm::ValueMap<bool> >(iConfig.getUntrackedParameter("eleVetoIdMapToken",edm::InputTag("egmGsfElectronIDs:cutBasedElectronID-Spring15-25ns-V1-standalone-veto")));
100  ElectronLooseIdMapToken_ = consumes<edm::ValueMap<bool> >(iConfig.getUntrackedParameter("eleLooseIdMapToken",edm::InputTag("egmGsfElectronIDs:cutBasedElectronID-Spring15-25ns-V1-standalone-loose")));
101  ElectronMediumIdMapToken_ = consumes<edm::ValueMap<bool> >(iConfig.getUntrackedParameter("eleMediumIdMapToken",edm::InputTag("egmGsfElectronIDs:cutBasedElectronID-Spring15-25ns-V1-standalone-medium")));
102  ElectronTightIdMapToken_ = consumes<edm::ValueMap<bool> >(iConfig.getUntrackedParameter("eleTightIdMapToken",edm::InputTag("egmGsfElectronIDs:cutBasedElectronID-Spring15-25ns-V1-standalone-tight")));
103 
105  electron_data = electron->getData();
106 
107  tree_=fs_->make<TTree>("ElectronRecoTree", "ElectronRecoTree");
108  tree_->Branch("Electron", "L1Analysis::L1AnalysisRecoElectronDataFormat", &electron_data, 32000, 3);
109 
110 }
111 
112 
114 {
115 
116  // do anything here that needs to be done at desctruction time
117  // (e.g. close files, deallocate resources etc.)
118 
119 }
120 
121 
122 //
123 // member functions
124 //
125 
126 // ------------ method called to for each event ------------
128 {
129 
130  electron->Reset();
131  //edm::Handle<edm::View<reco::GsfElectron> > recoElectrons;
132  //iEvent.getByToken(ElectronToken_, recoElectrons);
134  iEvent.getByToken(ElectronToken_, recoElectrons);
135 
136  std::vector<edm::Handle<edm::ValueMap<bool> > > eleVIDDecisionHandles(4) ;
137 
138  iEvent.getByToken (ElectronVetoIdMapToken_ , eleVIDDecisionHandles[0]) ;
139  iEvent.getByToken (ElectronLooseIdMapToken_ , eleVIDDecisionHandles[1]) ;
140  iEvent.getByToken (ElectronMediumIdMapToken_ , eleVIDDecisionHandles[2]) ;
141  iEvent.getByToken (ElectronTightIdMapToken_ , eleVIDDecisionHandles[3]) ;
142 
143  if (recoElectrons.isValid() && eleVIDDecisionHandles[0].isValid() && eleVIDDecisionHandles[1].isValid() && eleVIDDecisionHandles[2].isValid() && eleVIDDecisionHandles[3].isValid() ) {
144  electron->SetElectron(iEvent, iSetup, recoElectrons, eleVIDDecisionHandles, maxElectron_);
145  }
146  else {
147  if (!electronsMissing_) {edm::LogWarning("MissingProduct") << "CaloJets not found. Branch will not be filled" << std::endl;}
148  electronsMissing_ = true;
149  }
150 
151  tree_->Fill();
152 
153 }
154 
155 // ------------ method called once each job just before starting event loop ------------
156 void
158 {
159 }
160 
161 // ------------ method called once each job just after ending the event loop ------------
162 void
164 }
165 
166 //define this as a plug-in
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
L1ElectronRecoTreeProducer(const edm::ParameterSet &)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
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:230
virtual void analyze(const edm::Event &, const edm::EventSetup &)
L1Analysis::L1AnalysisRecoElectronDataFormat * electron_data
bool isValid() const
Definition: HandleBase.h:75
edm::EDGetTokenT< edm::ValueMap< bool > > ElectronTightIdMapToken_
edm::EDGetTokenT< edm::ValueMap< bool > > ElectronVetoIdMapToken_
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)
volatile std::atomic< bool > shutdown_flag false