babymaker  8522a50888c6c2e6eb3059ef64397a0b29afe7a5
bmaker_basic.hh
Go to the documentation of this file.
1 // Creates baby tree with basic branches
2 
3 #ifndef H_BMAKER_BASIC
4 #define H_BMAKER_BASIC
5 
6 // System include files
7 #include <memory>
8 #include <vector>
9 #include <ctime>
10 
11 // FW include files
12 #include "FWCore/Framework/interface/Frameworkfwd.h"
13 #include "FWCore/Framework/interface/EDAnalyzer.h"
14 #include "FWCore/Framework/interface/Event.h"
15 #include "FWCore/ParameterSet/interface/ParameterSet.h"
16 
17 // FW physics include files
18 #include "DataFormats/PatCandidates/interface/Muon.h"
19 #include "DataFormats/PatCandidates/interface/Electron.h"
20 #include "DataFormats/PatCandidates/interface/Photon.h"
21 #include "DataFormats/PatCandidates/interface/MET.h"
22 #include "DataFormats/PatCandidates/interface/Jet.h"
23 #include "DataFormats/JetReco/interface/GenJet.h"
24 #include "DataFormats/PatCandidates/interface/Conversion.h"
25 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
26 #include "DataFormats/VertexReco/interface/Vertex.h"
27 #include "DataFormats/Common/interface/TriggerResults.h"
28 #include "DataFormats/PatCandidates/interface/PackedTriggerPrescales.h"
29 #include "DataFormats/PatCandidates/interface/TriggerObjectStandAlone.h"
30 #include "DataFormats/PatCandidates/interface/PackedCandidate.h"
31 #include "SimDataFormats/PileupSummaryInfo/interface/PileupSummaryInfo.h"
32 #include "SimDataFormats/GeneratorProducts/interface/LHEEventProduct.h"
33 
34 // ROOT include files
35 #include "TTree.h"
36 #include "TString.h"
37 
38 // User include files
47 
48 typedef float& (baby_base::*baby_float)();
49 typedef std::vector<float>& (baby_base::*baby_vfloat)();
50 typedef std::vector<bool>& (baby_base::*baby_vbool)();
51 
52 // Class declaration
53 class bmaker_basic : public edm::EDAnalyzer {
54 public:
55  explicit bmaker_basic(const edm::ParameterSet&);
56  ~bmaker_basic();
57 
58  TFile *outfile;
60  bool isData;
61  time_t startTime;
62 
63  //object classes
70 
71  // Functions that do the branch writing
72  void writeMET(edm::Handle<pat::METCollection> mets, edm::Handle<pat::METCollection> mets_nohf);
73  void writeJets(edm::Handle<pat::JetCollection> alljets,
74  edm::Handle<edm::View <reco::GenJet> > genjets,
75  vCands &sig_leps, vCands &veto_leps,
76  vCands &photons, vCands &tks,
77  std::vector<LVector> &jets,
78  std::vector<std::vector<LVector> > &sysjets);
79  void writeFatJets(std::vector<LVector> &jets);
80  vCands writeMuons(edm::Handle<pat::MuonCollection> muons,
81  edm::Handle<pat::PackedCandidateCollection> pfcands,
82  edm::Handle<reco::VertexCollection> vtx,
83  vCands &veto_mus, vCands &all_mus, double rhoEventCentral);
84  vCands writeElectrons(edm::Handle<pat::ElectronCollection> electrons,
85  edm::Handle<pat::PackedCandidateCollection> pfcands,
86  edm::Handle<reco::VertexCollection> vtx,
87  vCands &veto_els, vCands &all_els, double rhoEventCentral);
88  void writeDiLep(vCands &sig_mus, vCands &sig_els, vCands &veto_mus, vCands &veto_els);
89  void setDiLepMass(vCands leptons, baby_float ll_m, baby_float ll_pt1, baby_float ll_pt2, baby_float ll_pt,
90  baby_float ll_eta, baby_float ll_phi, baby_vfloat l_pt, baby_vbool l_inz,
91  baby_float ll_w);
92  void setElMuMass(vCands leptons1, vCands leptons2, baby_float ll_m, baby_float ll_pt1, baby_float ll_pt2,
93  baby_float ll_pt, baby_float ll_eta, baby_float ll_phi,
94  baby_float ll_w);
95  void writeLeptons(vCands &leptons);
96 
97  vCands writePhotons(edm::Handle<pat::PhotonCollection> allphotons, edm::Handle<std::vector<pat::Electron> > &electrons,
98  edm::Handle<reco::ConversionCollection> &conversions, edm::Handle<reco::BeamSpot> &beamspot, double rho);
99 
100  bool writeTriggers(const edm::TriggerNames &names,
101  edm::Handle<edm::TriggerResults> triggerBits,
102  edm::Handle<pat::PackedTriggerPrescales> triggerPrescales);
103  void writeHLTObjects(const edm::TriggerNames &names,
104  edm::Handle<pat::TriggerObjectStandAloneCollection> triggerObjects,
105  vCands &all_mus, vCands &all_els, vCands &photons);
106  void writeFilters(const edm::TriggerNames &fnames,
107  edm::Handle<edm::TriggerResults> filterBits,
108  edm::Handle<reco::VertexCollection> vtx);
109  void writeVertices(edm::Handle<reco::VertexCollection> vtx,
110  edm::Handle<std::vector< PileupSummaryInfo > > pu_info);
111  void writeGenInfo(edm::Handle<LHEEventProduct> lhe_info);
112  void writeMC(edm::Handle<reco::GenParticleCollection> genParticles, vCands &all_mus, vCands &all_els, vCands &photons);
113 
114  void reportTime(const edm::Event& iEvent);
115 
116  // functions for calculating rebalanced MET
117  void rebalancedMET(double& MET, double& METPhi);
118  double calculateRescalingFactor(unsigned int jetIdx);
119  double calculateRebalancedMET(unsigned int jetIdx, double mu, double& METPhi);
120 
121  // for filling additional event weights
122  void writeWeights(const vCands &sig_leps, edm::Handle<GenEventInfoProduct> &gen_event_info,
123  edm::Handle<LHEEventProduct> &lhe_info);
124 
125  std::vector<TString> trig_name;
126 
127  // Input parameters
128  TString outname;
129  std::vector<std::string> inputfiles;
130  TString jsonfile;
131  TString condor_subtime;
132  TString jec_label;
133  std::string btag_label_BC;
134  std::string btag_label_UDSG;
135  edm::InputTag met_label;
136  edm::InputTag met_nohf_label;
137  edm::InputTag jets_label;
138  unsigned int nevents_sample;
139  unsigned int nevents;
141  float xsec;
142 
144  bool isFastSim;
146  bool debug;
147 
148  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
149 
150 private:
151  // Tokens
152  edm::EDGetTokenT<edm::TriggerResults> tok_trigResults_hlt_;
153  edm::EDGetTokenT<pat::PackedTriggerPrescales> tok_patTrig_;
154  edm::EDGetTokenT<reco::VertexCollection> tok_primVertex_;
155  edm::EDGetTokenT<std::vector< PileupSummaryInfo > > tok_addPileup_;
156  edm::EDGetTokenT<std::vector< PileupSummaryInfo > > tok_slimAddPileup_;
157  edm::EDGetTokenT<pat::PackedCandidateCollection> tok_packPFCands_;
158  edm::EDGetTokenT<double> tok_rhoFastJet_centralNeutral_;
159  edm::EDGetTokenT<pat::MuonCollection> tok_muons_;
160  edm::EDGetTokenT<pat::ElectronCollection> tok_electrons_;
161  edm::EDGetTokenT<double> tok_rhoFastJet_all_;
162  edm::EDGetTokenT<reco::BeamSpot> tok_offBeamSpot_;
163  edm::EDGetTokenT<pat::PhotonCollection> tok_photons_;
164  edm::EDGetTokenT<std::vector<reco::Conversion> > tok_reducedEgamma_conver_;
165  edm::EDGetTokenT<pat::JetCollection> tok_jets_;
166  edm::EDGetTokenT<edm::View<reco::GenJet> > tok_genJets_;
167  edm::EDGetTokenT<pat::METCollection> tok_met_;
168  edm::EDGetTokenT<pat::METCollection> tok_met_noHF_;
169  edm::EDGetTokenT<bool> tok_HBHENoiseFilter_;
170  edm::EDGetTokenT<bool> tok_HBHEIsoNoiseFilter_;
171  edm::EDGetTokenT<edm::TriggerResults> tok_trigResults_reco_;
172  edm::EDGetTokenT<edm::TriggerResults> tok_trigResults_pat_;
173  edm::EDGetTokenT<pat::TriggerObjectStandAloneCollection> tok_selectedPatTrig_;
174  edm::EDGetTokenT<reco::GenParticleCollection> tok_pruneGenPart_;
175  edm::EDGetTokenT<LHEEventProduct> tok_extLHEProducer_;
176  edm::EDGetTokenT<LHEEventProduct> tok_source_;
177  edm::EDGetTokenT<GenEventInfoProduct> tok_generator_;
178 
179  virtual void beginJob() override;
180  virtual void analyze(const edm::Event&, const edm::EventSetup&) override;
181  virtual void endJob() override;
182 
183 
184  // virtual void beginRun(edm::Run const&, edm::EventSetup const&) override;
185  // virtual void endRun(edm::Run const&, edm::EventSetup const&) override;
186  //virtual void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
187  //virtual void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
188 
189  // ----------member data ---------------------------
190 };
191 
192 #endif
virtual void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: bmaker_basic.cc:35
void writeFilters(const edm::TriggerNames &fnames, edm::Handle< edm::TriggerResults > filterBits, edm::Handle< reco::VertexCollection > vtx)
TString condor_subtime
double calculateRescalingFactor(unsigned int jetIdx)
TString jec_label
vCands writeElectrons(edm::Handle< pat::ElectronCollection > electrons, edm::Handle< pat::PackedCandidateCollection > pfcands, edm::Handle< reco::VertexCollection > vtx, vCands &veto_els, vCands &all_els, double rhoEventCentral)
void writeGenInfo(edm::Handle< LHEEventProduct > lhe_info)
std::vector< float > &(baby_base::* baby_vfloat)()
Definition: bmaker_basic.hh:49
edm::EDGetTokenT< pat::METCollection > tok_met_
vCands writePhotons(edm::Handle< pat::PhotonCollection > allphotons, edm::Handle< std::vector< pat::Electron > > &electrons, edm::Handle< reco::ConversionCollection > &conversions, edm::Handle< reco::BeamSpot > &beamspot, double rho)
edm::EDGetTokenT< reco::BeamSpot > tok_offBeamSpot_
void writeLeptons(vCands &leptons)
edm::EDGetTokenT< pat::PackedCandidateCollection > tok_packPFCands_
void setDiLepMass(vCands leptons, baby_float ll_m, baby_float ll_pt1, baby_float ll_pt2, baby_float ll_pt, baby_float ll_eta, baby_float ll_phi, baby_vfloat l_pt, baby_vbool l_inz, baby_float ll_w)
void writeHLTObjects(const edm::TriggerNames &names, edm::Handle< pat::TriggerObjectStandAloneCollection > triggerObjects, vCands &all_mus, vCands &all_els, vCands &photons)
void setElMuMass(vCands leptons1, vCands leptons2, baby_float ll_m, baby_float ll_pt1, baby_float ll_pt2, baby_float ll_pt, baby_float ll_eta, baby_float ll_phi, baby_float ll_w)
edm::EDGetTokenT< LHEEventProduct > tok_source_
std::vector< const reco::Candidate * > vCands
Definition: utilities.hh:14
edm::EDGetTokenT< bool > tok_HBHEIsoNoiseFilter_
std::string btag_label_BC
edm::EDGetTokenT< pat::MuonCollection > tok_muons_
void writeMET(edm::Handle< pat::METCollection > mets, edm::Handle< pat::METCollection > mets_nohf)
edm::EDGetTokenT< bool > tok_HBHENoiseFilter_
edm::EDGetTokenT< reco::GenParticleCollection > tok_pruneGenPart_
edm::EDGetTokenT< edm::TriggerResults > tok_trigResults_pat_
void writeVertices(edm::Handle< reco::VertexCollection > vtx, edm::Handle< std::vector< PileupSummaryInfo > > pu_info)
mc_tools * mcTool
Definition: bmaker_basic.hh:68
edm::EDGetTokenT< pat::JetCollection > tok_jets_
void reportTime(const edm::Event &iEvent)
baby_basic baby
Definition: bmaker_basic.hh:59
std::vector< bool > &(baby_base::* baby_vbool)()
Definition: bmaker_basic.hh:50
void writeDiLep(vCands &sig_mus, vCands &sig_els, vCands &veto_mus, vCands &veto_els)
event_tools * eventTool
Definition: bmaker_basic.hh:67
bmaker_basic(const edm::ParameterSet &)
edm::EDGetTokenT< std::vector< reco::Conversion > > tok_reducedEgamma_conver_
edm::EDGetTokenT< pat::ElectronCollection > tok_electrons_
bool doMetRebalancing
jet_met_tools * jetTool
Definition: bmaker_basic.hh:65
edm::EDGetTokenT< pat::PackedTriggerPrescales > tok_patTrig_
weight_tools * weightTool
Definition: bmaker_basic.hh:69
std::vector< TString > trig_name
unsigned int nevents
edm::EDGetTokenT< pat::TriggerObjectStandAloneCollection > tok_selectedPatTrig_
void rebalancedMET(double &MET, double &METPhi)
void writeMC(edm::Handle< reco::GenParticleCollection > genParticles, vCands &all_mus, vCands &all_els, vCands &photons)
void writeWeights(const vCands &sig_leps, edm::Handle< GenEventInfoProduct > &gen_event_info, edm::Handle< LHEEventProduct > &lhe_info)
edm::InputTag met_nohf_label
edm::EDGetTokenT< double > tok_rhoFastJet_all_
unsigned int nevents_sample
edm::EDGetTokenT< LHEEventProduct > tok_extLHEProducer_
edm::EDGetTokenT< edm::TriggerResults > tok_trigResults_hlt_
edm::EDGetTokenT< std::vector< PileupSummaryInfo > > tok_addPileup_
std::string btag_label_UDSG
lepton_tools * lepTool
Definition: bmaker_basic.hh:64
void writeJets(edm::Handle< pat::JetCollection > alljets, edm::Handle< edm::View< reco::GenJet > > genjets, vCands &sig_leps, vCands &veto_leps, vCands &photons, vCands &tks, std::vector< LVector > &jets, std::vector< std::vector< LVector > > &sysjets)
photon_tools * photonTool
Definition: bmaker_basic.hh:66
edm::EDGetTokenT< edm::TriggerResults > tok_trigResults_reco_
time_t startTime
Definition: bmaker_basic.hh:61
virtual void endJob() override
vCands writeMuons(edm::Handle< pat::MuonCollection > muons, edm::Handle< pat::PackedCandidateCollection > pfcands, edm::Handle< reco::VertexCollection > vtx, vCands &veto_mus, vCands &all_mus, double rhoEventCentral)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void writeFatJets(std::vector< LVector > &jets)
edm::EDGetTokenT< GenEventInfoProduct > tok_generator_
bool writeTriggers(const edm::TriggerNames &names, edm::Handle< edm::TriggerResults > triggerBits, edm::Handle< pat::PackedTriggerPrescales > triggerPrescales)
edm::EDGetTokenT< pat::PhotonCollection > tok_photons_
std::vector< std::string > inputfiles
edm::InputTag met_label
edm::EDGetTokenT< std::vector< PileupSummaryInfo > > tok_slimAddPileup_
edm::EDGetTokenT< edm::View< reco::GenJet > > tok_genJets_
virtual void beginJob() override
edm::EDGetTokenT< reco::VertexCollection > tok_primVertex_
edm::EDGetTokenT< pat::METCollection > tok_met_noHF_
float &(baby_base::* baby_float)()
Definition: bmaker_basic.hh:48
double calculateRebalancedMET(unsigned int jetIdx, double mu, double &METPhi)
TString jsonfile
edm::InputTag jets_label
edm::EDGetTokenT< double > tok_rhoFastJet_centralNeutral_
TString outname
TFile * outfile
Definition: bmaker_basic.hh:58