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 // system include files
21 #include <memory>
22 #include <fstream>
23 
24 // user include files
27 
30 
34 
39 
41 
42 #include "TMath.h"
43 #include "TRandom3.h"
44 
45 //
46 // class declaration
47 //
48 using namespace l1t;
49 
51 public:
53 
54  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
55 
56 private:
57  void produce(edm::Event&, const edm::EventSetup&) override;
58 
59  static bool compareMuons(const RegionalMuonCand&, const RegionalMuonCand&);
60 
61  // ----------member data ---------------------------
63  int m_currEvt;
64  const static int m_maxMuons = 108;
65  TRandom3 m_rnd;
66 };
67 
68 //
69 // constants, enums and typedefs
70 //
71 
72 //
73 // static data member definitions
74 //
75 
76 //
77 // constructors and destructor
78 //
80  : m_currEvt(0), m_rnd(0) {
81  //register your inputs:
82  genParticlesToken = consumes<reco::GenParticleCollection>(std::string("genParticles"));
83  //register your products
84  produces<RegionalMuonCandBxCollection>("BarrelTFMuons");
85  produces<RegionalMuonCandBxCollection>("OverlapTFMuons");
86  produces<RegionalMuonCandBxCollection>("ForwardTFMuons");
87  produces<MuonCaloSumBxCollection>("TriggerTowerSums");
88 }
89 
90 //
91 // member functions
92 //
93 
95  return mu1.processor() < mu2.processor();
96 }
97 
98 // ------------ method called to produce the data ------------
100  using namespace edm;
101 
102  std::unique_ptr<RegionalMuonCandBxCollection> barrelMuons(new RegionalMuonCandBxCollection());
103  std::unique_ptr<RegionalMuonCandBxCollection> overlapMuons(new RegionalMuonCandBxCollection());
104  std::unique_ptr<RegionalMuonCandBxCollection> endcapMuons(new RegionalMuonCandBxCollection());
105  std::unique_ptr<MuonCaloSumBxCollection> towerSums(new MuonCaloSumBxCollection());
106 
107  std::vector<RegionalMuonCand> bmMuons;
108  std::vector<RegionalMuonCand> omMuons;
109  std::vector<RegionalMuonCand> emMuons;
110 
111  std::vector<int> muIndices;
113  // Make sure that you can get genParticles
114  if (iEvent.getByToken(genParticlesToken, genParticles)) {
115  int cntr = 0;
116  for (auto it = genParticles->cbegin(); it != genParticles->cend(); ++it) {
117  const reco::Candidate& mcParticle = *it;
118  if (abs(mcParticle.pdgId()) == 13 && mcParticle.status() == 1)
119  muIndices.push_back(cntr);
120  cntr++;
121  }
122  } else {
123  LogTrace("GlobalMuon") << " GenParticleCollection not found." << std::endl;
124  }
125 
127  MuonCaloSum tSum;
128  // alternative scale (using full phi bit-width): 163.4521265553765f;
129  const float phiToInt = 91.67324722093171f;
130  // alternative scale: 100.0f;
131  const float etaToInt = 90.9090909090f;
132  const int maxPt = (1 << 9) - 1;
133  int muCntr = 0;
134 
135  double twoPi = TMath::Pi() * 2.;
136 
137  for (auto it = muIndices.begin(); it != muIndices.end(); ++it) {
138  // don't really care which muons are taken...
139  // guess there ain't 108 generated anyways
140  if (muCntr == m_maxMuons)
141  break;
142  int gen_idx = *it;
143  const reco::Candidate& mcMuon = genParticles->at(gen_idx);
144  double eta = mcMuon.eta();
145  if (fabs(eta) > 2.45)
146  continue; // out of acceptance
147  int hwPt = int(mcMuon.pt() * 2);
148  hwPt = (hwPt < maxPt ? hwPt : maxPt);
149  int hwEta = int(eta * etaToInt);
150  double phi = mcMuon.phi();
151  if (phi < 0)
152  phi += twoPi; // add 2*pi
153  int hwPhi = (int(phi * phiToInt)) % 576;
154  int hwQual = 8;
155  int hwCharge = (mcMuon.charge() > 0) ? 0 : 1;
156  int hwChargeValid = 1;
157 
158  mu.setHwPt(hwPt);
159 
160  tftype tf(tftype::bmtf);
161  int globalWedgePhi = (hwPhi + 24) % 576; // this sets CMS phi = 0 to -15 deg
162  int localPhi = globalWedgePhi % 48;
163  int processor = globalWedgePhi / 48 + 1;
164  int globalSectorPhi = (hwPhi - 24); // this sets CMS phi = 0 to +15 deg
165  if (globalSectorPhi < 0) {
166  globalSectorPhi += 576;
167  }
168 
169  if (fabs(eta) > 0.8) {
170  if (fabs(eta) < 1.2) {
171  tf = (eta > 0 ? tftype::omtf_pos : tftype::omtf_neg);
172  processor = globalSectorPhi / 96 + 1;
173  localPhi = globalSectorPhi % 96;
174  } else {
175  tf = (eta > 0 ? tftype::emtf_pos : tftype::emtf_neg);
176  processor = globalSectorPhi / 96 + 1;
177  localPhi = globalSectorPhi % 96;
178  }
179  }
180  mu.setHwPhi(localPhi);
181  mu.setTFIdentifiers(processor, tf);
182 
183  mu.setHwEta(hwEta);
184  mu.setHwSign(hwCharge);
185  mu.setHwSignValid(hwChargeValid);
186  mu.setHwQual(hwQual);
187 
188  if (fabs(eta) < 0.8 && bmMuons.size() < 36) {
189  bmMuons.push_back(mu);
190  muCntr++;
191  } else if (fabs(eta) < 1.2 && omMuons.size() < 36) {
192  omMuons.push_back(mu);
193  muCntr++;
194  } else if (emMuons.size() < 36) {
195  emMuons.push_back(mu);
196  muCntr++;
197  }
198  }
199 
200  std::sort(bmMuons.begin(), bmMuons.end(), L1TMicroGMTInputProducerFromGen::compareMuons);
201  std::sort(omMuons.begin(), omMuons.end(), L1TMicroGMTInputProducerFromGen::compareMuons);
202  std::sort(emMuons.begin(), emMuons.end(), L1TMicroGMTInputProducerFromGen::compareMuons);
203 
204  for (const auto& mu : bmMuons) {
205  barrelMuons->push_back(0, mu);
206  }
207 
208  for (const auto& mu : omMuons) {
209  overlapMuons->push_back(0, mu);
210  }
211 
212  for (const auto& mu : emMuons) {
213  endcapMuons->push_back(0, mu);
214  }
215 
216  for (int i = 0; i < 1008; ++i) {
217  // from where could I take the tower energies?
218  int energy = int(m_rnd.Gaus(12, 6));
219  if (energy < 0)
220  energy = 0;
221  if (energy > 31)
222  energy = 31;
223  MuonCaloSum sum(energy, i / 28, i % 28, i);
224  towerSums->push_back(0, sum);
225  }
226 
227  iEvent.put(std::move(barrelMuons), "BarrelTFMuons");
228  iEvent.put(std::move(overlapMuons), "OverlapTFMuons");
229  iEvent.put(std::move(endcapMuons), "ForwardTFMuons");
230  iEvent.put(std::move(towerSums), "TriggerTowerSums");
231  m_currEvt++;
232 }
233 
234 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
236  //The following says we do not know what parameters are allowed so do no validation
237  // Please change this to state exactly what you do use, even if it is no parameters
239  desc.setUnknown();
240  descriptions.addDefault(desc);
241 }
242 
243 //define this as a plug-in
const double Pi
BXVector< RegionalMuonCand > RegionalMuonCandBxCollection
virtual double pt() const =0
transverse momentum
BXVector< MuonCaloSum > MuonCaloSumBxCollection
Definition: MuonCaloSumFwd.h:7
virtual int status() const =0
status word
const int processor() const
Get processor ID on which the candidate was found (0..5 for OMTF/EMTF; 0..11 for BMTF) ...
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
delete x;
Definition: CaloConfig.h:22
#define LogTrace(id)
int iEvent
Definition: GenABIO.cc:224
void addDefault(ParameterSetDescription const &psetDescription)
L1TMicroGMTInputProducerFromGen(const edm::ParameterSet &)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
edm::EDGetTokenT< reco::GenParticleCollection > genParticlesToken
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
virtual int charge() const =0
electric charge
static bool compareMuons(const RegionalMuonCand &, const RegionalMuonCand &)
virtual int pdgId() const =0
PDG identifier.
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
maxPt
Definition: PV_cfg.py:224
HLT enums.
constexpr double twoPi()
Definition: Pi.h:32
def move(src, dest)
Definition: eostools.py:511
virtual double phi() const =0
momentum azimuthal angle
virtual double eta() const =0
momentum pseudorapidity
void produce(edm::Event &, const edm::EventSetup &) override