CP3-llbb Framework
FatJetsProducer.h
1 #ifndef FAT_JETS_PRODUCER
2 #define FAT_JETS_PRODUCER
3 
4 #include <cp3_llbb/Framework/interface/CandidatesProducer.h>
5 #include <cp3_llbb/Framework/interface/BTaggingScaleFactors.h>
6 
7 #include <DataFormats/PatCandidates/interface/Jet.h>
8 
9 class FatJetsProducer: public CandidatesProducer<pat::Jet>, public BTaggingScaleFactors {
10  public:
11  FatJetsProducer(const std::string& name, const ROOT::TreeGroup& tree, const edm::ParameterSet& config):
12  CandidatesProducer(name, tree, config), BTaggingScaleFactors(const_cast<ROOT::TreeGroup&>(tree))
13  {
14  BTaggingScaleFactors::create_branches(config);
15 
16  if (config.exists("btags")) {
17  const std::vector<std::string>& btags = config.getUntrackedParameter<std::vector<std::string>>("btags");
18 
19  // Create branches
20  for (const std::string& btag: btags) {
21  std::string branchName{btag};
22  std::replace(std::begin(branchName), std::end(branchName), ':', '_');
23  m_btag_discriminators.emplace(btag, &CandidatesProducer<pat::Jet>::tree[branchName].write<std::vector<float>>());
24  }
25  }
26 
27  if (config.exists("subjets_btags")) {
28  m_subjets_btag_discriminators = config.getUntrackedParameter<std::vector<std::string>>("subjets_btags");
29 
30  // Create branches
31  for (const std::string& btag: m_subjets_btag_discriminators) {
32  m_softdrop_btag_discriminators_branches.emplace(btag,
33  &CandidatesProducer<pat::Jet>::tree["softdrop_" + btag].write<std::vector<std::vector<float>>>());
34  m_softdrop_puppi_btag_discriminators_branches.emplace(btag,
35  &CandidatesProducer<pat::Jet>::tree["softdrop_puppi_" + btag].write<std::vector<std::vector<float>>>());
36  }
37  }
38  Njettinesstau1 = config.getUntrackedParameter<std::string>("Njettinesstau1", "NjettinessAK8:tau1");
39  Njettinesstau2 = config.getUntrackedParameter<std::string>("Njettinesstau2", "NjettinessAK8:tau2");
40  Njettinesstau3 = config.getUntrackedParameter<std::string>("Njettinesstau3", "NjettinessAK8:tau3");
41  SoftDropSubjets = config.getUntrackedParameter<std::string>("SoftDropSubjets", "SoftDrop");
42  SoftDropPuppiSubjets = config.getUntrackedParameter<std::string>("SoftDropPuppiSubjets", "SoftDropPuppi");
43  }
44 
45  virtual ~FatJetsProducer() {}
46 
47  virtual void doConsumes(const edm::ParameterSet& config, edm::ConsumesCollector&& collector) override {
48  m_jets_token = collector.consumes<std::vector<pat::Jet>>(config.getUntrackedParameter<edm::InputTag>("jets", edm::InputTag("slimmedJetsAK8")));
49  }
50 
51  virtual void produce(edm::Event& event, const edm::EventSetup& eventSetup) override;
52 
53  float getBTagDiscriminant(size_t index, const std::string& name) const {
54  return m_btag_discriminators.at(name)->at(index);
55  }
56 
57  float getSoftDropBTagDiscriminant(size_t index, size_t sj_index, const std::string& btag_name) const {
58  return m_softdrop_btag_discriminators_branches.at(btag_name)->at(index).at(sj_index);
59  }
60 
61  float getSoftDropPuppiBTagDiscriminant(size_t index, size_t sj_index, const std::string& btag_name) const {
62  return m_softdrop_puppi_btag_discriminators_branches.at(btag_name)->at(index).at(sj_index);
63  }
64 
65  float get_scale_factor(Algorithm algo, const std::string& wp, size_t index, Variation variation = Variation::Nominal);
66 
67  private:
68 
69  // Tokens
70  edm::EDGetTokenT<std::vector<pat::Jet>> m_jets_token;
71 
72  std::map<std::string, std::vector<float>*> m_btag_discriminators;
73 
74  std::vector<std::string> m_subjets_btag_discriminators;
75  std::map<std::string, std::vector<std::vector<float>>*> m_softdrop_btag_discriminators_branches;
76  std::map<std::string, std::vector<std::vector<float>>*> m_softdrop_puppi_btag_discriminators_branches;
77 
78  std::string Njettinesstau1;
79  std::string Njettinesstau2;
80  std::string Njettinesstau3;
81  std::string SoftDropSubjets;
82  std::string SoftDropPuppiSubjets;
83 
84  public:
85  // Tree members
86  std::vector<float>& area = tree["area"].write<std::vector<float>>();
87  std::vector<int8_t>& partonFlavor = tree["partonFlavor"].write<std::vector<int8_t>>();
88  std::vector<int8_t>& hadronFlavor = tree["hadronFlavor"].write<std::vector<int8_t>>();
89 
90  // Systematics flavor: 1 for heavy jets, 2 for light jets
91  std::vector<int8_t>& systFlavor = tree["systFlavor"].write<std::vector<int8_t>>();
92 
93  std::vector<float>& jecFactor = tree["jecFactor"].write<std::vector<float>>();
94 
95  BRANCH(passLooseID, std::vector<bool>);
96  BRANCH(passTightID, std::vector<bool>);
97  BRANCH(passTightLeptonVetoID, std::vector<bool>);
98 
99  BRANCH(tau1, std::vector<float>);
100  BRANCH(tau2, std::vector<float>);
101  BRANCH(tau3, std::vector<float>);
102 
103  BRANCH(puppi_p4, std::vector<LorentzVector>);
104  BRANCH(puppi_tau1, std::vector<float>);
105  BRANCH(puppi_tau2, std::vector<float>);
106  BRANCH(puppi_tau3, std::vector<float>);
107 
108  BRANCH(softdrop_mass, std::vector<float>);
109  BRANCH(pruned_mass, std::vector<float>);
110 
111  BRANCH(softdrop_subjets_p4, std::vector<std::vector<LorentzVector>>);
112  BRANCH(softdrop_puppi_subjets_p4, std::vector<std::vector<LorentzVector>>);
113 };
114 
115 #endif
Definition: BTaggingScaleFactors.h:36
Definition: CandidatesProducer.h:9
Definition: FatJetsProducer.h:9
virtual void doConsumes(const edm::ParameterSet &config, edm::ConsumesCollector &&collector) override
Hook for the CMSSW consumes interface.
Definition: FatJetsProducer.h:47
virtual void produce(edm::Event &event, const edm::EventSetup &eventSetup) override
Main method of the producer, called for each event.
Definition: FatJetsProducer.cc:5
ROOT::TreeGroup tree
Access point to output tree.
Definition: Producer.h:132