CMS 3D CMS Logo

Phase2L1TGMTSAMuonProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: L1Trigger/Phase2L1GMT
4 // Class: Phase2L1TGMTSAMuonProducer
5 //
13 //
14 // Original Author: Zhenbin Wu
15 // Created: Fri, 30 Apr 2021 19:10:59 GMT
16 //
17 //
18 
19 #ifndef PHASE2GMT_SAMUONPRODUCER
20 #define PHASE2GMT_SAMUONPRODUCER
21 
22 // system include files
23 #include <memory>
24 #include <sstream>
25 
26 // user include files
29 
32 
35 
39 
42 //
43 // class declaration
44 //
45 using namespace Phase2L1GMT;
46 using namespace l1t;
47 
49 public:
51  ~Phase2L1TGMTSAMuonProducer() override = default;
52 
53  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
54 
55 private:
56  void beginStream(edm::StreamID) override;
57  void produce(edm::Event&, const edm::EventSetup&) override;
58  void endStream() override;
59 
60  l1t::SAMuon Convertl1tMuon(const l1t::Muon& mu, const int bx_);
61 
62  // ----------member data ---------------------------
64  unsigned int Nprompt;
65  unsigned int Ndisplaced;
66 };
67 
69  : muonToken_(consumes<l1t::MuonBxCollection>(iConfig.getParameter<edm::InputTag>("muonToken"))),
70  Nprompt(iConfig.getParameter<uint>("Nprompt")),
71  Ndisplaced(iConfig.getParameter<uint>("Ndisplaced")) {
72  produces<std::vector<l1t::SAMuon> >("promptSAMuons").setBranchAlias("prompt");
73  produces<std::vector<l1t::SAMuon> >("displacedSAMuons").setBranchAlias("displaced");
74 }
75 
76 //
77 // member functions
78 //
79 
80 // ------------ method called to produce the data ------------
82  using namespace edm;
84  iEvent.getByToken(muonToken_, muon);
85 
86  // Output
87  std::vector<SAMuon> prompt;
88  std::vector<SAMuon> displaced;
89 
90  for (int bx = muon->getFirstBX(); bx <= muon->getLastBX(); ++bx) {
91  //TODO: We are expecting to send all BX. Using bx0 for now
92  if (bx != 0) {
93  continue;
94  }
95 
96  for (uint i = 0; i < muon->size(bx); ++i) {
97  const l1t::Muon& mu = muon->at(bx, i);
98 
99  //TODO: Still looking for a way to get displaced muon
100  if (abs(mu.hwDXY()) > 0)
101  displaced.push_back(Convertl1tMuon(mu, bx));
102  else
103  prompt.push_back(Convertl1tMuon(mu, bx));
104  }
105 
106  // Sort by hwPt
107  std::sort(prompt.begin(), prompt.end(), std::greater<>());
108  std::sort(displaced.begin(), displaced.end(), std::greater<>());
109 
110  // Store into output, allow up to 18 prompt + 18 displayed
111  if (prompt.size() > Nprompt) {
112  prompt.resize(Nprompt);
113  }
114  if (displaced.size() > Ndisplaced) {
115  displaced.resize(Ndisplaced);
116  }
117  }
118 
119  std::unique_ptr<std::vector<l1t::SAMuon> > prompt_ptr = std::make_unique<std::vector<l1t::SAMuon> >(prompt);
120  std::unique_ptr<std::vector<l1t::SAMuon> > displaced_ptr = std::make_unique<std::vector<l1t::SAMuon> >(displaced);
121  iEvent.put(std::move(prompt_ptr), "promptSAMuons");
122  iEvent.put(std::move(displaced_ptr), "displacedSAMuons");
123 }
124 
125 // === FUNCTION ============================================================
126 // Name: Phase2L1TGMTSAMuonProducer::Convertl1tMuon
127 // Description:
128 // ===========================================================================
130  ap_uint<BITSSAQUALITY> qual = mu.hwQual();
131  int charge = mu.charge() > 0 ? 0 : 1;
132 
133  ap_uint<BITSPT> pt = round(mu.pt() / LSBpt);
134  ap_int<BITSPHI> phi = round(mu.phi() / LSBphi);
135  ap_int<BITSETA> eta = round(mu.eta() / LSBeta);
136  // FIXME: Below are not well defined in phase1 GMT
137  // Using the version from Correlator for now
138  ap_int<BITSSAZ0> z0 = 0; // No tracks info in Phase 1
139  // Use 2 bits with LSB = 30cm for BMTF and 25cm for EMTF currently, but subjet to change
140  ap_int<BITSSAD0> d0 = mu.hwDXY();
141 
142  int bstart = 0;
143  wordtype word(0);
144  bstart = wordconcat<wordtype>(word, bstart, pt > 0, 1);
145  bstart = wordconcat<wordtype>(word, bstart, pt, BITSGTPT);
146  bstart = wordconcat<wordtype>(word, bstart, phi, BITSGTPHI);
147  bstart = wordconcat<wordtype>(word, bstart, eta, BITSGTETA);
148  bstart = wordconcat<wordtype>(word, bstart, z0, BITSSAZ0);
149  bstart = wordconcat<wordtype>(word, bstart, d0, BITSSAD0);
150  bstart = wordconcat<wordtype>(word, bstart, charge, 1);
151  bstart = wordconcat<wordtype>(word, bstart, qual, BITSSAQUALITY);
152 
153  SAMuon samuon(mu, charge, pt.to_uint(), eta.to_int(), phi.to_int(), z0.to_int(), d0.to_int(), qual.to_uint());
154  samuon.setWord(word);
155  return samuon;
156 } // ----- end of function Phase2L1TGMTSAMuonProducer::Convertl1tMuon -----
157 
158 // ------------ method called once each stream before processing any runs, lumis or events ------------
160  // please remove this method if not needed
161 }
162 
163 // ------------ method called once each stream after processing all runs, lumis and events ------------
165  // please remove this method if not needed
166 }
167 
168 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
171  desc.add<edm::InputTag>("muonToken", edm::InputTag("simGmtStage2Digis"));
172  desc.add<unsigned int>("Nprompt", 12);
173  desc.add<unsigned int>("Ndisplaced", 12);
174  descriptions.add("standaloneMuons", desc);
175 }
176 
177 //define this as a plug-in
179 #endif
const float LSBphi
Definition: Constants.h:81
edm::EDGetTokenT< BXVector< l1t::Muon > > muonToken_
const int BITSSAQUALITY
Definition: Constants.h:57
const int BITSGTETA
Definition: Constants.h:62
const int BITSSAD0
Definition: Constants.h:56
const int BITSGTPHI
Definition: Constants.h:61
void setWord(uint64_t word)
Definition: SAMuon.h:43
delete x;
Definition: CaloConfig.h:22
ap_uint< 64 > wordtype
Definition: Constants.h:88
void beginStream(edm::StreamID) override
uint64_t word
const float LSBpt
Definition: Constants.h:80
int iEvent
Definition: GenABIO.cc:224
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Nprompt
Definition: gmt_cfi.py:81
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void produce(edm::Event &, const edm::EventSetup &) override
const int BITSGTPT
Definition: Constants.h:60
Definition: Muon.h:21
const float LSBeta
Definition: Constants.h:82
Ndisplaced
Definition: gmt_cfi.py:82
static constexpr float d0
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
HLT enums.
l1t::SAMuon Convertl1tMuon(const l1t::Muon &mu, const int bx_)
Phase2L1TGMTSAMuonProducer(const edm::ParameterSet &)
def move(src, dest)
Definition: eostools.py:511
const int BITSSAZ0
Definition: Constants.h:55