CMS 3D CMS Logo

L1TMicroGMTInputProducerFromGen.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: L1TMicroGMTInputProducerFromGen
4 // Class: L1TMicroGMTInputProducerFromGen
5 //
13 //
14 // Original Author: Joschka Philip Lingemann,40 3-B01,+41227671598,
15 // Created: Thu Oct 3 10:12:30 CEST 2013
16 // $Id$
17 //
18 //
19 
20 
21 // system include files
22 #include <memory>
23 #include <fstream>
24 
25 // user include files
28 
31 
35 
40 
42 
43 #include "TMath.h"
44 #include "TRandom3.h"
45 
46 //
47 // class declaration
48 //
49 using namespace l1t;
50 
52  public:
55 
56  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
57 
58  private:
59  void produce(edm::Event&, const edm::EventSetup&) override ;
60 
61  void beginRun(const edm::Run&, edm::EventSetup const&) override ;
62  void endRun(const edm::Run&, edm::EventSetup const&) override ;
63  void beginLuminosityBlock(const edm::LuminosityBlock&, edm::EventSetup const&) override ;
64  void endLuminosityBlock(const edm::LuminosityBlock&, edm::EventSetup const&) override ;
65 
66  static bool compareMuons(const RegionalMuonCand&, const RegionalMuonCand&);
67 
68  // ----------member data ---------------------------
70  int m_currEvt;
71  const static int m_maxMuons = 108;
72  TRandom3 m_rnd;
73 };
74 
75 //
76 // constants, enums and typedefs
77 //
78 
79 
80 //
81 // static data member definitions
82 //
83 
84 //
85 // constructors and destructor
86 //
88  m_currEvt(0), m_rnd(0)
89 {
90  //register your inputs:
91  genParticlesToken = consumes <reco::GenParticleCollection> (std::string("genParticles"));
92  //register your products
93  produces<RegionalMuonCandBxCollection>("BarrelTFMuons");
94  produces<RegionalMuonCandBxCollection>("OverlapTFMuons");
95  produces<RegionalMuonCandBxCollection>("ForwardTFMuons");
96  produces<MuonCaloSumBxCollection>("TriggerTowerSums");
97 }
98 
99 
101 {
102  // do anything here that needs to be done at desctruction time
103  // (e.g. close files, deallocate resources etc.)
104 }
105 
106 
107 //
108 // member functions
109 //
110 
111 bool
113 {
114  return mu1.processor() < mu2.processor();
115 }
116 
117 // ------------ method called to produce the data ------------
118 void
120 {
121  using namespace edm;
122 
123  std::unique_ptr<RegionalMuonCandBxCollection> barrelMuons (new RegionalMuonCandBxCollection());
124  std::unique_ptr<RegionalMuonCandBxCollection> overlapMuons (new RegionalMuonCandBxCollection());
125  std::unique_ptr<RegionalMuonCandBxCollection> endcapMuons (new RegionalMuonCandBxCollection());
126  std::unique_ptr<MuonCaloSumBxCollection> towerSums (new MuonCaloSumBxCollection());
127 
128  std::vector<RegionalMuonCand> bmMuons;
129  std::vector<RegionalMuonCand> omMuons;
130  std::vector<RegionalMuonCand> emMuons;
131 
132 
133  std::vector<int> muIndices;
135  // Make sure that you can get genParticles
136  if (iEvent.getByToken(genParticlesToken, genParticles)) {
137  int cntr = 0;
138  for (auto it = genParticles->cbegin(); it != genParticles->cend(); ++it) {
139  const reco::Candidate& mcParticle = *it;
140  if( abs(mcParticle.pdgId()) == 13 && mcParticle.status() == 1 ) muIndices.push_back(cntr);
141  cntr++;
142  }
143  }
144  else {
145  LogTrace("GlobalMuon") << " GenParticleCollection not found." << std::endl;
146  }
147 
149  MuonCaloSum tSum;
150  // alternative scale (using full phi bit-width): 163.4521265553765f;
151  const float phiToInt = 91.67324722093171f;
152  // alternative scale: 100.0f;
153  const float etaToInt = 90.9090909090f;
154  const int maxPt = (1 << 9)-1;
155  int muCntr = 0;
156 
157  double twoPi = TMath::Pi() * 2.;
158 
159  for (auto it = muIndices.begin(); it != muIndices.end(); ++it) {
160  // don't really care which muons are taken...
161  // guess there ain't 108 generated anyways
162  if (muCntr == m_maxMuons) break;
163  int gen_idx = *it;
164  const reco::Candidate& mcMuon = genParticles->at(gen_idx);
165  double eta = mcMuon.eta();
166  if (fabs(eta) > 2.45) continue; // out of acceptance
167  int hwPt = int(mcMuon.pt() * 2);
168  hwPt = (hwPt < maxPt ? hwPt : maxPt);
169  int hwEta = int(eta * etaToInt);
170  double phi = mcMuon.phi();
171  if (phi < 0) phi += twoPi; // add 2*pi
172  int hwPhi = (int(phi * phiToInt))%576;
173  int hwQual = 8;
174  int hwCharge = (mcMuon.charge() > 0) ? 0 : 1;
175  int hwChargeValid = 1;
176 
177  mu.setHwPt(hwPt);
178 
179 
180 
181  tftype tf(tftype::bmtf);
182  int globalWedgePhi = (hwPhi+24)%576; // this sets CMS phi = 0 to -15 deg
183  int localPhi = globalWedgePhi%48;
184  int processor = globalWedgePhi / 48 + 1;
185  int globalSectorPhi = (hwPhi-24); // this sets CMS phi = 0 to +15 deg
186  if (globalSectorPhi < 0) {
187  globalSectorPhi += 576;
188  }
189 
190 
191  if (fabs(eta) > 0.8) {
192  if (fabs(eta) < 1.2) {
193  tf = (eta > 0 ? tftype::omtf_pos : tftype::omtf_neg);
194  processor = globalSectorPhi / 96 + 1;
195  localPhi = globalSectorPhi%96;
196  } else {
197  tf = (eta > 0 ? tftype::emtf_pos : tftype::emtf_neg);
198  processor = globalSectorPhi / 96 + 1;
199  localPhi = globalSectorPhi%96;
200  }
201  }
202  mu.setHwPhi(localPhi);
203  mu.setTFIdentifiers(processor, tf);
204 
205  mu.setHwEta(hwEta);
206  mu.setHwSign(hwCharge);
207  mu.setHwSignValid(hwChargeValid);
208  mu.setHwQual(hwQual);
209 
210  if (fabs(eta) < 0.8 && bmMuons.size() < 36) {
211  bmMuons.push_back(mu);
212  muCntr++;
213  } else if (fabs(eta) < 1.2 && omMuons.size() < 36) {
214  omMuons.push_back(mu);
215  muCntr++;
216  } else if (emMuons.size() < 36) {
217  emMuons.push_back(mu);
218  muCntr++;
219  }
220  }
221 
222  std::sort(bmMuons.begin(), bmMuons.end(), L1TMicroGMTInputProducerFromGen::compareMuons);
223  std::sort(omMuons.begin(), omMuons.end(), L1TMicroGMTInputProducerFromGen::compareMuons);
224  std::sort(emMuons.begin(), emMuons.end(), L1TMicroGMTInputProducerFromGen::compareMuons);
225 
226  for (const auto& mu:bmMuons) {
227  barrelMuons->push_back(0, mu);
228  }
229 
230  for (const auto& mu:omMuons) {
231  overlapMuons->push_back(0, mu);
232  }
233 
234  for (const auto& mu:emMuons) {
235  endcapMuons->push_back(0, mu);
236  }
237 
238  for (int i = 0; i < 1008; ++i) {
239  // from where could I take the tower energies?
240  int energy = int(m_rnd.Gaus(12, 6));
241  if (energy < 0) energy = 0;
242  if (energy > 31) energy = 31;
243  MuonCaloSum sum(energy, i/28, i%28, i);
244  towerSums->push_back(0, sum);
245  }
246 
247  iEvent.put(std::move(barrelMuons), "BarrelTFMuons");
248  iEvent.put(std::move(overlapMuons), "OverlapTFMuons");
249  iEvent.put(std::move(endcapMuons), "ForwardTFMuons");
250  iEvent.put(std::move(towerSums), "TriggerTowerSums");
251  m_currEvt++;
252 
253 }
254 
255 // ------------ method called when starting to processes a run ------------
256 void
258 {
259 }
260 
261 // ------------ method called when ending the processing of a run ------------
262 void
264 {
265 }
266 
267 // ------------ method called when starting to processes a luminosity block ------------
268 void
270 {
271 }
272 
273 // ------------ method called when ending the processing of a luminosity block ------------
274 void
276 {
277 }
278 
279 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
280 void
282  //The following says we do not know what parameters are allowed so do no validation
283  // Please change this to state exactly what you do use, even if it is no parameters
285  desc.setUnknown();
286  descriptions.addDefault(desc);
287 }
288 
289 //define this as a plug-in
void endRun(const edm::Run &, edm::EventSetup const &) override
const double Pi
void setHwPhi(int bits)
Set compressed relative phi as transmitted by hardware LSB = 2*pi/576 (8 bits)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
BXVector< RegionalMuonCand > RegionalMuonCandBxCollection
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
BXVector< MuonCaloSum > MuonCaloSumBxCollection
Definition: MuonCaloSumFwd.h:7
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
delete x;
Definition: CaloConfig.h:22
virtual int status() const =0
status word
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void addDefault(ParameterSetDescription const &psetDescription)
void endLuminosityBlock(const edm::LuminosityBlock &, edm::EventSetup const &) override
void setTFIdentifiers(int processor, tftype trackFinder)
Set the processor ID, track-finder type. From these two, the link is set.
virtual int pdgId() const =0
PDG identifier.
L1TMicroGMTInputProducerFromGen(const edm::ParameterSet &)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
edm::EDGetTokenT< reco::GenParticleCollection > genParticlesToken
const int mu
Definition: Constants.h:22
#define LogTrace(id)
static bool compareMuons(const RegionalMuonCand &, const RegionalMuonCand &)
void setHwQual(int bits)
Set compressed quality code as transmitted by hardware (4 bits)
void beginLuminosityBlock(const edm::LuminosityBlock &, edm::EventSetup const &) override
void setHwPt(int bits)
Set compressed pT as transmitted by hardware LSB = 0.5 (9 bits)
void setHwEta(int bits)
Set compressed eta as transmitted by hardware LSB = 0.010875 (9 bits)
void beginRun(const edm::Run &, edm::EventSetup const &) override
const int processor() const
Get processor ID on which the candidate was found (0..5 for OMTF/EMTF; 0..11 for BMTF) ...
virtual double eta() const =0
momentum pseudorapidity
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
virtual double pt() const =0
transverse momentum
virtual int charge() const =0
electric charge
HLT enums.
void setHwSignValid(int bits)
Set whether charge measurement is valid (0 for high pT muons)
constexpr double twoPi()
Definition: Pi.h:32
virtual double phi() const =0
momentum azimuthal angle
def move(src, dest)
Definition: eostools.py:511
Definition: Run.h:45
void setHwSign(int bits)
Set charge sign bit (charge = (-1)^(sign))
void produce(edm::Event &, const edm::EventSetup &) override