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  qual_sa_t qual = mu.hwQual();
131  int charge = mu.charge() > 0 ? 0 : 1;
132 
133  pt_sa_t pt = round(mu.pt() / LSBpt);
134  phi_sa_t phi = round(mu.phi() / LSBphi);
135  eta_sa_t eta = round(mu.eta() / LSBeta);
136  // FIXME: Below are not well defined in phase1 GMT
137  // Using the version from Correlator for now
138  z0_sa_t 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  d0_sa_t 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, BITSSAQUAL);
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:92
edm::EDGetTokenT< BXVector< l1t::Muon > > muonToken_
const int BITSGTETA
Definition: Constants.h:62
ap_uint< BITSGTPT > pt_sa_t
Definition: Constants.h:113
const int BITSSAD0
Definition: Constants.h:56
const int BITSGTPHI
Definition: Constants.h:61
ap_uint< BITSSAQUAL > qual_sa_t
Definition: Constants.h:119
void setWord(uint64_t word)
Definition: SAMuon.h:53
const int BITSSAQUAL
Definition: Constants.h:57
delete x;
Definition: CaloConfig.h:22
ap_int< BITSSAD0 > d0_sa_t
Definition: Constants.h:117
ap_uint< 64 > wordtype
Definition: Constants.h:99
void beginStream(edm::StreamID) override
uint64_t word
const float LSBpt
Definition: Constants.h:91
int iEvent
Definition: GenABIO.cc:224
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
ap_int< BITSGTETA > eta_sa_t
Definition: Constants.h:115
Nprompt
Definition: gmt_cfi.py:92
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:93
Ndisplaced
Definition: gmt_cfi.py:93
static constexpr float d0
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
ap_int< BITSSAZ0 > z0_sa_t
Definition: Constants.h:116
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 &)
ap_int< BITSGTPHI > phi_sa_t
Definition: Constants.h:114
def move(src, dest)
Definition: eostools.py:511
const int BITSSAZ0
Definition: Constants.h:55