babymaker  e95a6a9342d4604277fe7cc6149b6b5b24447d89
bmaker_full.hh
Go to the documentation of this file.
1 // Creates baby tree with basic branches
2 
3 #ifndef H_BMAKER_FULL
4 #define H_BMAKER_FULL
5 
6 // System include files
7 #include <memory>
8 #include <vector>
9 #include <ctime>
11 
12 // FW include files
13 #include "FWCore/Framework/interface/Frameworkfwd.h"
14 #include "FWCore/Framework/interface/EDAnalyzer.h"
15 #include "FWCore/Framework/interface/Event.h"
16 #include "FWCore/ParameterSet/interface/ParameterSet.h"
17 
18 // FW physics include files
19 #include "DataFormats/PatCandidates/interface/Muon.h"
20 #include "DataFormats/PatCandidates/interface/Electron.h"
21 #include "DataFormats/PatCandidates/interface/Photon.h"
22 #include "DataFormats/PatCandidates/interface/MET.h"
23 #include "DataFormats/PatCandidates/interface/Jet.h"
24 #include "DataFormats/JetReco/interface/GenJet.h"
25 #include "DataFormats/PatCandidates/interface/Conversion.h"
26 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
27 #include "DataFormats/VertexReco/interface/Vertex.h"
28 #include "DataFormats/Common/interface/TriggerResults.h"
29 #include "DataFormats/PatCandidates/interface/PackedTriggerPrescales.h"
30 #include "DataFormats/PatCandidates/interface/TriggerObjectStandAlone.h"
31 #include "DataFormats/PatCandidates/interface/PackedCandidate.h"
32 #include "SimDataFormats/PileupSummaryInfo/interface/PileupSummaryInfo.h"
33 #include "SimDataFormats/GeneratorProducts/interface/LHEEventProduct.h"
34 #include "SimDataFormats/GeneratorProducts/interface/GenEventInfoProduct.h"
35 #include "SimDataFormats/GeneratorProducts/interface/GenLumiInfoHeader.h"
36 
37 // User include files
46 /* DAK8
47 #include "NNKit/FatJetNN/interface/FatJetNN.h"
48 #include "NNKit/FatJetNN/interface/FatJetNNDecorrelator.h"
49 #include "NNKit/FatJetNN/interface/FatJetNNHelper.h"
50 using namespace deepntuples;
51 */
52 
53 // ROOT include files
54 #include "TTree.h"
55 #include "TString.h"
56 
57 typedef float& (baby_base::*baby_float)();
58 typedef std::vector<float>& (baby_base::*baby_vfloat)();
59 typedef std::vector<bool>& (baby_base::*baby_vbool)();
60 
61 // Class declaration
62 class bmaker_full : public edm::EDAnalyzer {
63 public:
64  explicit bmaker_full(const edm::ParameterSet&);
65  ~bmaker_full();
66 
67  TFile *outfile;
69  bool isData;
70  time_t startTime;
71 
72  //object classes
79 
80  // Functions that do the branch writing
81  void writeMET(edm::Handle<pat::METCollection> mets, edm::Handle<pat::METCollection> mets_nohf, edm::Handle<pat::METCollection> mets_puppi);
82  std::vector<reco::Candidate::LorentzVector> writeJets(edm::Handle<pat::JetCollection> alljets,
83  std::vector<unsigned> &all_baby_jets_idx,
84  edm::Handle<edm::View <reco::GenJet> > genjets,
85  vCands &sig_leps, vCands &veto_leps,
86  vCands &photons, vCands &tks,
87  std::vector<std::vector<LVector> > &sysjets,
88  std::vector<double> &jetsMuonEnergyFrac);
89  void writeBTagWeights(edm::Handle<pat::JetCollection> alljets,
90  std::vector<reco::Candidate::LorentzVector> &all_baby_jets,
91  std::vector<unsigned> &all_baby_jet_idx);
92  void writeHiggVars(std::vector<LVector> &baby_jets_p4, std::vector<float> &baby_jets_csv,
93  std::vector<bool> &baby_jets_h1, std::vector<bool> &baby_jets_h2,
94  std::vector<bool> &baby_jets_islep, int &baby_nbl, int &baby_nbm, int &baby_nbt,
95  float &baby_hig_am, float &baby_hig_dm, float &baby_hig_drmax,
96  int &baby_hig_bin, float &baby_mct, bool isSystemtatic = false);
97  void writeBBVars(std::vector<reco::Candidate::LorentzVector> &all_baby_jets, vCands &sig_leps);
98 
99  void writeFatJets();
100 /* DAK8
101  void writeAk8Jets(edm::Handle<edm::View<pat::Jet>> &ak8jets);
102 */
103  vCands writeMuons(edm::Handle<pat::MuonCollection> muons,
104  edm::Handle<pat::PackedCandidateCollection> pfcands,
105  edm::Handle<reco::VertexCollection> vtx,
106  vCands &veto_mus, vCands &all_mus, double rhoEventCentral);
107  vCands writeElectrons(edm::Handle<pat::ElectronCollection> electrons,
108  edm::Handle<pat::PackedCandidateCollection> pfcands,
109  edm::Handle<reco::VertexCollection> vtx,
110  vCands &veto_els, vCands &all_els, double rhoEventCentral);
111  void writeDiLep(vCands &sig_mus, vCands &sig_els, vCands &veto_mus, vCands &veto_els);
112  void setDiLepMass(vCands leptons, baby_float ll_m, baby_float ll_pt1, baby_float ll_pt2, baby_float ll_pt,
113  baby_float ll_eta, baby_float ll_phi, baby_vfloat l_pt, baby_vbool l_inz,
114  baby_float ll_w);
115  void setElMuMass(vCands leptons1, vCands leptons2, baby_float ll_m, baby_float ll_pt1, baby_float ll_pt2,
116  baby_float ll_pt, baby_float ll_eta, baby_float ll_phi,
117  baby_float ll_w);
118  void writeLeptons(vCands &leptons);
119  void writeTks(edm::Handle<pat::PackedCandidateCollection> pfcands,edm::Handle<reco::VertexCollection> vtx, double rhoEventCentral);
120  vCands writePhotons(edm::Handle<pat::PhotonCollection> allphotons,
121  edm::Handle<std::vector<pat::Electron> > &electrons,
122  edm::Handle<reco::ConversionCollection> &conversions,
123  edm::Handle<reco::BeamSpot> &beamspot, double rho);
124 
125  bool writeTriggers(const edm::TriggerNames &names,
126  edm::Handle<edm::TriggerResults> triggerBits,
127  edm::Handle<pat::PackedTriggerPrescales> triggerPrescales);
128  void writeHLTObjects(const edm::TriggerNames &names,
129  edm::Handle<pat::TriggerObjectStandAloneCollection> triggerObjects,
130  vCands &all_mus, vCands &all_els, vCands &photons, const edm::Event&);
131  void writeFilters(const edm::TriggerNames &fnames,
132  edm::Handle<edm::TriggerResults> filterBits,
133  edm::Handle<reco::VertexCollection> vtx,
134  std::vector<double> jetsMuonEnergyFrac);
135  void writeVertices(edm::Handle<reco::VertexCollection> vtx,
136  edm::Handle<std::vector< PileupSummaryInfo > > pu_info);
137  void writeGenInfo(edm::Handle<LHEEventProduct> lhe_info);
138  void writeIFSR(edm::Handle<reco::GenParticleCollection> genParticles,
139  std::vector<reco::Candidate::LorentzVector> &jets);
140  void writeMC(edm::Handle<reco::GenParticleCollection> genParticles, vCands &all_mus, vCands &all_els, vCands &photons);
141 
142  void reportTime(const edm::Event& iEvent);
143 
144  // functions for calculating rebalanced MET
145  void rebalancedMET(double& MET, double& METPhi);
146  double calculateRescalingFactor(unsigned int jetIdx);
147  double calculateRebalancedMET(unsigned int jetIdx, double mu, double& METPhi);
148 
149  // for filling additional event weights
150  void writeWeights(const vCands &sig_leps, edm::Handle<GenEventInfoProduct> &gen_event_info,
151  edm::Handle<LHEEventProduct> &lhe_info);
152 
153  std::vector<TString> trig_name;
154 
155  // Input parameters
156  TString outname;
157  std::vector<std::string> inputfiles;
158  TString jsonfile;
159  TString condor_subtime;
160  TString jec_label;
161  std::string btag_label_BC;
162  std::string btag_label_UDSG;
163  edm::InputTag met_label;
164  edm::InputTag met_nohf_label;
165  edm::InputTag jets_label;
166  unsigned int nevents_sample;
167  unsigned int nevents;
169  float xsec;
170 
172  bool isFastSim;
174  bool debug;
175 
176  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
177 
178 private:
179  int mprod_;
180  int mlsp_;
181 
182  // Tokens
183  edm::EDGetTokenT<edm::TriggerResults> tok_trigResults_hlt_;
184  edm::EDGetTokenT<pat::PackedTriggerPrescales> tok_patTrig_;
185  edm::EDGetTokenT<reco::VertexCollection> tok_primVertex_;
186  edm::EDGetTokenT<std::vector< PileupSummaryInfo > > tok_addPileup_;
187  edm::EDGetTokenT<std::vector< PileupSummaryInfo > > tok_slimAddPileup_;
188  edm::EDGetTokenT<pat::PackedCandidateCollection> tok_packPFCands_;
189  edm::EDGetTokenT<double> tok_rhoFastJet_centralNeutral_;
190  edm::EDGetTokenT<pat::MuonCollection> tok_muons_;
191  edm::EDGetTokenT<pat::ElectronCollection> tok_electrons_;
192  edm::EDGetTokenT<double> tok_rhoFastJet_all_;
193  edm::EDGetTokenT<reco::BeamSpot> tok_offBeamSpot_;
194  edm::EDGetTokenT<pat::PhotonCollection> tok_photons_;
195  edm::EDGetTokenT<std::vector<reco::Conversion> > tok_reducedEgamma_conver_;
196  edm::EDGetTokenT<pat::JetCollection> tok_jets_;
197  edm::EDGetTokenT<edm::View<reco::GenJet> > tok_genJets_;
198  edm::EDGetTokenT<pat::METCollection> tok_met_;
199  edm::EDGetTokenT<pat::METCollection> tok_met_noHF_;
200  edm::EDGetTokenT<pat::METCollection> tok_met_Puppi_;
201  edm::EDGetTokenT<bool> tok_HBHENoiseFilter_;
202  edm::EDGetTokenT<bool> tok_HBHEIsoNoiseFilter_;
203  edm::EDGetTokenT<edm::TriggerResults> tok_trigResults_reco_;
204  edm::EDGetTokenT<edm::TriggerResults> tok_trigResults_pat_;
205  edm::EDGetTokenT<pat::TriggerObjectStandAloneCollection> tok_selectedPatTrig_;
206  edm::EDGetTokenT<reco::GenParticleCollection> tok_pruneGenPart_;
207  edm::EDGetTokenT<LHEEventProduct> tok_extLHEProducer_;
208  edm::EDGetTokenT<LHEEventProduct> tok_source_;
209  edm::EDGetTokenT<GenEventInfoProduct> tok_generator_;
210  edm::EDGetTokenT<bool> tok_badChCandFilter_;
211  edm::EDGetTokenT<bool> tok_badPFMuonFilter_;
212  edm::EDGetTokenT<GenLumiInfoHeader> tok_genlumiheader_;
213 
214 /* DAK8
215  edm::EDGetTokenT<edm::View<pat::Jet>> tok_deepJetToken_;
216  std::unique_ptr<FatJetNN> fatjetNN_;
217  std::unique_ptr<FatJetNN> decorrNN_;
218  double deepJetR;
219 */
220 
221  virtual void beginJob() override;
222  virtual void analyze(const edm::Event&, const edm::EventSetup&) override;
223  virtual void endJob() override;
224 
225 
226  // virtual void beginRun(edm::Run const&, edm::EventSetup const&) override;
227  // virtual void endRun(edm::Run const&, edm::EventSetup const&) override;
228  virtual void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
229  //virtual void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
230 
231  // ----------member data ---------------------------
232 };
233 
234 #endif
edm::InputTag met_nohf_label
Definition: bmaker_full.hh:164
TString outname
Definition: bmaker_full.hh:156
edm::EDGetTokenT< pat::TriggerObjectStandAloneCollection > tok_selectedPatTrig_
Definition: bmaker_full.hh:205
bool addBTagWeights
Definition: bmaker_full.hh:171
edm::EDGetTokenT< pat::METCollection > tok_met_
Definition: bmaker_full.hh:198
time_t startTime
Definition: bmaker_full.hh:70
edm::InputTag met_label
Definition: bmaker_full.hh:163
void writeWeights(const vCands &sig_leps, edm::Handle< GenEventInfoProduct > &gen_event_info, edm::Handle< LHEEventProduct > &lhe_info)
bool writeTriggers(const edm::TriggerNames &names, edm::Handle< edm::TriggerResults > triggerBits, edm::Handle< pat::PackedTriggerPrescales > triggerPrescales)
void writeHLTObjects(const edm::TriggerNames &names, edm::Handle< pat::TriggerObjectStandAloneCollection > triggerObjects, vCands &all_mus, vCands &all_els, vCands &photons, const edm::Event &)
edm::EDGetTokenT< std::vector< PileupSummaryInfo > > tok_slimAddPileup_
Definition: bmaker_full.hh:187
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)
edm::EDGetTokenT< pat::JetCollection > tok_jets_
Definition: bmaker_full.hh:196
edm::EDGetTokenT< pat::PackedCandidateCollection > tok_packPFCands_
Definition: bmaker_full.hh:188
bmaker_full(const edm::ParameterSet &)
virtual void beginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) override
edm::EDGetTokenT< pat::METCollection > tok_met_noHF_
Definition: bmaker_full.hh:199
edm::InputTag jets_label
Definition: bmaker_full.hh:165
std::vector< const reco::Candidate * > vCands
Definition: utilities.hh:15
edm::EDGetTokenT< pat::METCollection > tok_met_Puppi_
Definition: bmaker_full.hh:200
weight_tools * weightTool
Definition: bmaker_full.hh:78
edm::EDGetTokenT< bool > tok_badChCandFilter_
Definition: bmaker_full.hh:210
edm::EDGetTokenT< GenEventInfoProduct > tok_generator_
Definition: bmaker_full.hh:209
edm::EDGetTokenT< pat::PackedTriggerPrescales > tok_patTrig_
Definition: bmaker_full.hh:184
lepton_tools * lepTool
Definition: bmaker_full.hh:73
std::string btag_label_BC
Definition: bmaker_full.hh:161
virtual void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: bmaker_full.cc:41
edm::EDGetTokenT< edm::TriggerResults > tok_trigResults_pat_
Definition: bmaker_full.hh:204
edm::EDGetTokenT< double > tok_rhoFastJet_centralNeutral_
Definition: bmaker_full.hh:189
baby_full baby
Definition: bmaker_full.hh:68
edm::EDGetTokenT< GenLumiInfoHeader > tok_genlumiheader_
Definition: bmaker_full.hh:212
void writeDiLep(vCands &sig_mus, vCands &sig_els, vCands &veto_mus, vCands &veto_els)
void writeMET(edm::Handle< pat::METCollection > mets, edm::Handle< pat::METCollection > mets_nohf, edm::Handle< pat::METCollection > mets_puppi)
Definition: bmaker_full.cc:369
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)
edm::EDGetTokenT< edm::TriggerResults > tok_trigResults_hlt_
Definition: bmaker_full.hh:183
void rebalancedMET(double &MET, double &METPhi)
TString jec_label
Definition: bmaker_full.hh:160
edm::EDGetTokenT< pat::PhotonCollection > tok_photons_
Definition: bmaker_full.hh:194
edm::EDGetTokenT< pat::MuonCollection > tok_muons_
Definition: bmaker_full.hh:190
edm::EDGetTokenT< std::vector< PileupSummaryInfo > > tok_addPileup_
Definition: bmaker_full.hh:186
void reportTime(const edm::Event &iEvent)
edm::EDGetTokenT< edm::View< reco::GenJet > > tok_genJets_
Definition: bmaker_full.hh:197
edm::EDGetTokenT< reco::GenParticleCollection > tok_pruneGenPart_
Definition: bmaker_full.hh:206
float &(baby_base::* baby_float)()
Definition: bmaker_full.hh:57
bool doMetRebalancing
Definition: bmaker_full.hh:168
edm::EDGetTokenT< bool > tok_HBHENoiseFilter_
Definition: bmaker_full.hh:201
TString condor_subtime
Definition: bmaker_full.hh:159
void writeVertices(edm::Handle< reco::VertexCollection > vtx, edm::Handle< std::vector< PileupSummaryInfo > > pu_info)
unsigned int nevents
Definition: bmaker_full.hh:167
void writeTks(edm::Handle< pat::PackedCandidateCollection > pfcands, edm::Handle< reco::VertexCollection > vtx, double rhoEventCentral)
void writeBBVars(std::vector< reco::Candidate::LorentzVector > &all_baby_jets, vCands &sig_leps)
Definition: bmaker_full.cc:863
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
mc_tools * mcTool
Definition: bmaker_full.hh:77
bool doSystematics
Definition: bmaker_full.hh:173
edm::EDGetTokenT< LHEEventProduct > tok_extLHEProducer_
Definition: bmaker_full.hh:207
edm::EDGetTokenT< std::vector< reco::Conversion > > tok_reducedEgamma_conver_
Definition: bmaker_full.hh:195
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)
std::vector< bool > &(baby_base::* baby_vbool)()
Definition: bmaker_full.hh:59
edm::EDGetTokenT< reco::BeamSpot > tok_offBeamSpot_
Definition: bmaker_full.hh:193
edm::EDGetTokenT< edm::TriggerResults > tok_trigResults_reco_
Definition: bmaker_full.hh:203
void writeIFSR(edm::Handle< reco::GenParticleCollection > genParticles, std::vector< reco::Candidate::LorentzVector > &jets)
void writeBTagWeights(edm::Handle< pat::JetCollection > alljets, std::vector< reco::Candidate::LorentzVector > &all_baby_jets, std::vector< unsigned > &all_baby_jet_idx)
Definition: bmaker_full.cc:603
void writeGenInfo(edm::Handle< LHEEventProduct > lhe_info)
virtual void endJob() override
edm::EDGetTokenT< pat::ElectronCollection > tok_electrons_
Definition: bmaker_full.hh:191
edm::EDGetTokenT< bool > tok_HBHEIsoNoiseFilter_
Definition: bmaker_full.hh:202
edm::EDGetTokenT< reco::VertexCollection > tok_primVertex_
Definition: bmaker_full.hh:185
unsigned int nevents_sample
Definition: bmaker_full.hh:166
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)
event_tools * eventTool
Definition: bmaker_full.hh:76
void writeFatJets()
Definition: bmaker_full.cc:889
edm::EDGetTokenT< bool > tok_badPFMuonFilter_
Definition: bmaker_full.hh:211
TFile * outfile
Definition: bmaker_full.hh:67
TString jsonfile
Definition: bmaker_full.hh:158
std::vector< TString > trig_name
Definition: bmaker_full.hh:153
photon_tools * photonTool
Definition: bmaker_full.hh:75
virtual void beginJob() override
void writeHiggVars(std::vector< LVector > &baby_jets_p4, std::vector< float > &baby_jets_csv, std::vector< bool > &baby_jets_h1, std::vector< bool > &baby_jets_h2, std::vector< bool > &baby_jets_islep, int &baby_nbl, int &baby_nbm, int &baby_nbt, float &baby_hig_am, float &baby_hig_dm, float &baby_hig_drmax, int &baby_hig_bin, float &baby_mct, bool isSystemtatic=false)
Definition: bmaker_full.cc:757
std::vector< float > &(baby_base::* baby_vfloat)()
Definition: bmaker_full.hh:58
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)
Definition: bmaker_full.cc:982
std::vector< reco::Candidate::LorentzVector > writeJets(edm::Handle< pat::JetCollection > alljets, std::vector< unsigned > &all_baby_jets_idx, edm::Handle< edm::View< reco::GenJet > > genjets, vCands &sig_leps, vCands &veto_leps, vCands &photons, vCands &tks, std::vector< std::vector< LVector > > &sysjets, std::vector< double > &jetsMuonEnergyFrac)
Definition: bmaker_full.cc:402
void writeLeptons(vCands &leptons)
void writeMC(edm::Handle< reco::GenParticleCollection > genParticles, vCands &all_mus, vCands &all_els, vCands &photons)
void writeFilters(const edm::TriggerNames &fnames, edm::Handle< edm::TriggerResults > filterBits, edm::Handle< reco::VertexCollection > vtx, std::vector< double > jetsMuonEnergyFrac)
double calculateRebalancedMET(unsigned int jetIdx, double mu, double &METPhi)
jet_met_tools * jetTool
Definition: bmaker_full.hh:74
edm::EDGetTokenT< LHEEventProduct > tok_source_
Definition: bmaker_full.hh:208
edm::EDGetTokenT< double > tok_rhoFastJet_all_
Definition: bmaker_full.hh:192
std::vector< std::string > inputfiles
Definition: bmaker_full.hh:157
std::string btag_label_UDSG
Definition: bmaker_full.hh:162
double calculateRescalingFactor(unsigned int jetIdx)