CMS 3D CMS Logo

L1TMuonCaloSumProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: L1TMuonCaloSumProducer
4 // Class: L1TMuonCaloSumProducer
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 
38 
39 #include "TMath.h"
40 #include "TRandom3.h"
41 
42 //
43 // class declaration
44 //
45 using namespace l1t;
46 
48 public:
50 
51  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
52 
53 private:
54  void produce(edm::Event&, const edm::EventSetup&) override;
55 
58 };
59 
60 //
61 // constants, enums and typedefs
62 //
63 
64 //
65 // static data member definitions
66 //
67 
68 //
69 // constructors and destructor
70 //
72  //register your inputs:
73  m_caloLabel = iConfig.getParameter<edm::InputTag>("caloStage2Layer2Label");
74  m_caloTowerToken = consumes<CaloTowerBxCollection>(m_caloLabel);
75  //register your products
76  produces<MuonCaloSumBxCollection>("TriggerTowerSums");
77  produces<MuonCaloSumBxCollection>("TriggerTower2x2s");
78 }
79 
80 //
81 // member functions
82 //
83 
84 // ------------ method called to produce the data ------------
86  using namespace edm;
87  std::unique_ptr<MuonCaloSumBxCollection> towerSums(std::make_unique<MuonCaloSumBxCollection>());
88  std::unique_ptr<MuonCaloSumBxCollection> tower2x2s(std::make_unique<MuonCaloSumBxCollection>());
89 
91 
92  if (iEvent.getByToken(m_caloTowerToken, caloTowers)) {
93  int detamax = 4;
94  int dphimax = 4;
95 
96  const int iFirstBx = caloTowers->getFirstBX();
97  const int iLastBx = caloTowers->getLastBX();
98 
99  // set BX range for sums
100  towerSums->setBXRange(iFirstBx, iLastBx);
101  tower2x2s->setBXRange(iFirstBx, iLastBx);
102 
103  for (int bx = iFirstBx; bx <= iLastBx; ++bx) {
104  std::map<int, MuonCaloSum> sums;
105  std::map<int, MuonCaloSum> regs;
106 
107  for (auto it = caloTowers->begin(bx); it != caloTowers->end(bx); ++it) {
108  const CaloTower& twr = *it;
109  int hwEta = twr.hwEta();
110  if (std::abs(hwEta) > 27) {
111  continue;
112  }
113  int hwPt = twr.hwPt();
114  if (hwPt < 1) {
115  continue;
116  }
117  int hwPhi = twr.hwPhi();
118 
119  // calculating tower2x2s
120  int ieta2x2 = (hwEta + 27) / 2;
121  int iphi2x2 = hwPhi / 2;
122  int muon_idx = iphi2x2 * 28 + ieta2x2;
123  if (regs.count(muon_idx) == 0) {
124  regs[muon_idx] = MuonCaloSum(hwPt, iphi2x2, ieta2x2, muon_idx);
125  } else {
126  regs.at(muon_idx).setEtBits(regs.at(muon_idx).etBits() + hwPt);
127  }
128 
129  // std::cout << "iphi; phi " << hwPhi << "; " << phi << " .. ieta; eta" << hwEta << "; " << twr.eta() << std::endl;
130 
131  // calculating towerSums
132  int ietamax = hwEta + detamax + 1;
133  for (int ieta = hwEta - detamax; ieta < ietamax; ++ieta) {
134  if (std::abs(ieta) > 27) {
135  continue;
136  }
137  int ietamu = (ieta + 27) / 2;
138  int iphimax = hwPhi + dphimax + 1;
139  for (int iphi = hwPhi - dphimax; iphi < iphimax; ++iphi) {
140  int iphiwrapped = iphi;
141  if (iphiwrapped < 0) {
142  iphiwrapped += 72;
143  } else if (iphiwrapped > 71) {
144  iphiwrapped -= 72;
145  }
146  int iphimu = iphiwrapped / 2;
147  int idxmu = iphimu * 28 + ietamu;
148  if (sums.count(idxmu) == 0) {
149  sums[idxmu] = MuonCaloSum(hwPt, iphimu, ietamu, idxmu);
150  } else {
151  sums.at(idxmu).setEtBits(sums.at(idxmu).etBits() + hwPt);
152  }
153  }
154  }
155  }
156 
157  // fill towerSums output collection for this BX
158  for (auto it = sums.begin(); it != sums.end(); ++it) {
159  if (it->second.etBits() > 0) {
160  MuonCaloSum sum = MuonCaloSum(it->second);
161  // convert Et to correct scale:
162  if (sum.etBits() > 31) {
163  sum.setEtBits(31);
164  }
165  towerSums->push_back(bx, sum);
166  }
167  }
168  // fill tower2x2s output collection for this BX
169  for (auto it = regs.begin(); it != regs.end(); ++it) {
170  if (it->second.etBits() > 0) {
171  tower2x2s->push_back(bx, it->second);
172  }
173  }
174  }
175  } else {
176  LogWarning("GlobalMuon") << "CaloTowers not found. Producing empty collections." << std::endl;
177  }
178 
179  iEvent.put(std::move(towerSums), "TriggerTowerSums");
180  iEvent.put(std::move(tower2x2s), "TriggerTower2x2s");
181 }
182 
183 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
185  //The following says we do not know what parameters are allowed so do no validation
186  // Please change this to state exactly what you do use, even if it is no parameters
188  desc.setUnknown();
189  descriptions.addDefault(desc);
190 }
191 
192 //define this as a plug-in
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
edm::EDGetTokenT< CaloTowerBxCollection > m_caloTowerToken
const int etBits() const
Definition: MuonCaloSum.h:20
int hwPhi() const
Definition: L1Candidate.h:37
delete x;
Definition: CaloConfig.h:22
L1TMuonCaloSumProducer(const edm::ParameterSet &)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
int iEvent
Definition: GenABIO.cc:224
void addDefault(ParameterSetDescription const &psetDescription)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int hwEta() const
Definition: L1Candidate.h:36
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void produce(edm::Event &, const edm::EventSetup &) override
void setEtBits(int bits)
Definition: MuonCaloSum.h:15
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
int hwPt() const
Definition: L1Candidate.h:35
HLT enums.
Log< level::Warning, false > LogWarning
def move(src, dest)
Definition: eostools.py:511