CMS 3D CMS Logo

L1GTNTupleProducer.cc
Go to the documentation of this file.
7 
10 #include "TTree.h"
11 
13 
14 #include <memory>
15 #include <vector>
16 #include <unordered_map>
17 #include <map>
18 
19 using namespace l1t;
20 
22 public:
23  explicit L1GTNTupleProducer(const edm::ParameterSet&);
24 
25  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
26 
27 private:
28  //void beginJob(void) override;
29  void analyze(const edm::Event&, const edm::EventSetup&) override;
30  //void endJob() override;
31 
32 private:
33  void fillData(const l1t::P2GTCandidateCollection& collection, const std::string& instanceName);
34 
36  const unsigned maxNTuples_;
37 
41 
45 
51 
53  TTree* tree_;
54 
55  std::unordered_map<std::string, std::vector<int>> data_;
56 };
57 
58 static const std::map<std::string, std::vector<std::string>> NTUPLE_VARIABLES = {
59  {"GTTPromptJet", {"Pt", "Eta", "Phi"}},
60  {"GTTDisplacedJet", {"Pt", "Eta", "Phi"}},
61  {"GTTPrimaryVertex", {"Z0"}},
62  {"GMTSaPromptMuon", {"Pt", "Eta", "Phi", "Z0"}},
63  {"GMTSaDisplacedMuon", {"Pt", "Eta", "Phi", "Z0"}},
64  {"GMTTkMuon", {"Pt", "Eta", "Phi", "Z0"}},
65  {"CL2Jet", {"Pt", "Eta", "Phi", "Z0"}},
66  {"CL2Photon", {"Pt", "Eta", "Phi"}},
67  {"CL2Electron", {"Pt", "Eta", "Phi", "Z0"}},
68  {"CL2EtSum", {"Pt", "Phi", "ScaSumPt"}},
69  {"CL2HtSum", {"Pt", "Phi", "ScaSumPt"}}};
70 
72  : producerName_(config.getParameter<std::string>("producerName")),
73  maxNTuples_(config.getParameter<unsigned>("maxNTuples")),
74  gttPromptJetToken_(consumes<P2GTCandidateCollection>(edm::InputTag(producerName_, "GTTPromptJets"))),
75  gttDisplacedJetToken_(consumes<P2GTCandidateCollection>(edm::InputTag(producerName_, "GTTDisplacedJets"))),
76  gttPrimaryVertexToken_(consumes<P2GTCandidateCollection>(edm::InputTag(producerName_, "GTTPrimaryVert"))),
77  gmtSaPromptMuonToken_(consumes<P2GTCandidateCollection>(edm::InputTag(producerName_, "GMTSaPromptMuons"))),
78  gmtSaDisplacedMuonToken_(consumes<P2GTCandidateCollection>(edm::InputTag(producerName_, "GMTSaDisplacedMuons"))),
79  gmtTkMuonToken_(consumes<P2GTCandidateCollection>(edm::InputTag(producerName_, "GMTTkMuons"))),
80  cl2JetToken_(consumes<P2GTCandidateCollection>(edm::InputTag(producerName_, "CL2Jets"))),
81  cl2PhotonToken_(consumes<P2GTCandidateCollection>(edm::InputTag(producerName_, "CL2Photons"))),
82  cl2ElectronToken_(consumes<P2GTCandidateCollection>(edm::InputTag(producerName_, "CL2Electrons"))),
83  cl2EtSumToken_(consumes<P2GTCandidateCollection>(edm::InputTag(producerName_, "CL2EtSum"))),
84  cl2HtSumToken_(consumes<P2GTCandidateCollection>(edm::InputTag(producerName_, "CL2HtSum"))),
85  tree_(fs_->make<TTree>("L1PhaseIITree", "L1PhaseIITree")) {
86  for (const auto& [collec, variables] : NTUPLE_VARIABLES) {
87  for (const std::string& var : variables) {
88  std::string name = collec + var;
89  tree_->Branch(name.c_str(), &data_[name], 8000, 1);
90  }
91  }
92 }
93 
96  desc.add<std::string>("producerName");
97  desc.add<unsigned>("maxNTuples");
98 
99  descriptions.addDefault(desc);
100 }
101 
103  for (const P2GTCandidate& object : collection) {
104  for (const std::string& var : NTUPLE_VARIABLES.at(instanceName)) {
105  std::string name = instanceName + var;
106  if (var == "Pt")
107  data_.at(name).push_back(object.hwPT());
108  else if (var == "Eta")
109  data_.at(name).push_back(object.hwEta());
110  else if (var == "Phi")
111  data_.at(name).push_back(object.hwPhi());
112  else if (var == "Z0")
113  data_.at(name).push_back(object.hwZ0());
114  else if (var == "D0")
115  data_.at(name).push_back(object.hwD0());
116  else if (var == "ScaSumPt")
117  data_.at(name).push_back(object.hwSca_sum());
118  }
119  }
120 }
121 
123  const l1t::P2GTCandidateCollection& gttPromptJets = event.get(gttPromptJetToken_);
124  fillData(gttPromptJets, "GTTPromptJet");
125 
126  const l1t::P2GTCandidateCollection& gttDisplacedJets = event.get(gttDisplacedJetToken_);
127  fillData(gttDisplacedJets, "GTTDisplacedJet");
128 
129  const l1t::P2GTCandidateCollection& gttPrimaryVertices = event.get(gttPrimaryVertexToken_);
130  fillData(gttPrimaryVertices, "GTTPrimaryVertex");
131 
132  const l1t::P2GTCandidateCollection& gmtSaPromptMuons = event.get(gmtSaPromptMuonToken_);
133  fillData(gmtSaPromptMuons, "GMTSaPromptMuon");
134 
135  const l1t::P2GTCandidateCollection& gmtSaDisplacedMuons = event.get(gmtSaDisplacedMuonToken_);
136  fillData(gmtSaDisplacedMuons, "GMTSaDisplacedMuon");
137 
138  const l1t::P2GTCandidateCollection& gmtTkMuons = event.get(gmtTkMuonToken_);
139  fillData(gmtTkMuons, "GMTTkMuon");
140 
141  const l1t::P2GTCandidateCollection& cl2Jets = event.get(cl2JetToken_);
142  fillData(cl2Jets, "CL2Jet");
143 
144  const l1t::P2GTCandidateCollection& cl2Photons = event.get(cl2PhotonToken_);
145  fillData(cl2Photons, "CL2Photon");
146 
147  const l1t::P2GTCandidateCollection& cl2Electrons = event.get(cl2ElectronToken_);
148  fillData(cl2Electrons, "CL2Electron");
149 
150  const l1t::P2GTCandidateCollection& cl2EtSum = event.get(cl2EtSumToken_);
151  fillData(cl2EtSum, "CL2EtSum");
152 
153  const l1t::P2GTCandidateCollection& cl2HtSum = event.get(cl2HtSumToken_);
154  fillData(cl2HtSum, "CL2HtSum");
155 
156  tree_->Fill();
157 
158  for (auto& [key, vector] : data_) {
159  vector.clear();
160  }
161 }
162 
std::vector< P2GTCandidate > P2GTCandidateCollection
Definition: P2GTCandidate.h:16
const edm::EDGetTokenT< P2GTCandidateCollection > gttPromptJetToken_
S make(const edm::ParameterSet &cfg)
delete x;
Definition: CaloConfig.h:22
Definition: config.py:1
void analyze(const edm::Event &, const edm::EventSetup &) override
example_stream void analyze(const edm::Event &, const edm::EventSetup &) override
const edm::EDGetTokenT< P2GTCandidateCollection > cl2ElectronToken_
const edm::EDGetTokenT< P2GTCandidateCollection > cl2HtSumToken_
void addDefault(ParameterSetDescription const &psetDescription)
const edm::Service< TFileService > fs_
const edm::EDGetTokenT< P2GTCandidateCollection > gmtSaDisplacedMuonToken_
const edm::EDGetTokenT< P2GTCandidateCollection > gttPrimaryVertexToken_
const std::string producerName_
void fillData(const l1t::P2GTCandidateCollection &collection, const std::string &instanceName)
key
prepare the HTCondor submission files and eventually submit them
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const edm::EDGetTokenT< P2GTCandidateCollection > cl2PhotonToken_
const edm::EDGetTokenT< P2GTCandidateCollection > gttDisplacedJetToken_
std::unordered_map< std::string, std::vector< int > > data_
const edm::EDGetTokenT< P2GTCandidateCollection > cl2EtSumToken_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
const unsigned maxNTuples_
const edm::EDGetTokenT< P2GTCandidateCollection > gmtSaPromptMuonToken_
static const std::map< std::string, std::vector< std::string > > NTUPLE_VARIABLES
L1GTNTupleProducer(const edm::ParameterSet &)
HLT enums.
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
const edm::EDGetTokenT< P2GTCandidateCollection > cl2JetToken_
const edm::EDGetTokenT< P2GTCandidateCollection > gmtTkMuonToken_
Definition: event.py:1